715 lines
29 KiB
TypeScript
715 lines
29 KiB
TypeScript
"use client";
|
|
|
|
import { ProviderInstanceIcon } from "../chat/ProviderInstanceIcon";
|
|
|
|
import { Radio as RadioPrimitive } from "@base-ui/react/radio";
|
|
import { CheckIcon } from "lucide-react";
|
|
import { useMemo, useState } from "react";
|
|
import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
|
|
import {
|
|
type AcpRegistrySearchAgent,
|
|
AuthProvidersManageScope,
|
|
ProviderInstanceId,
|
|
ProviderDriverKind,
|
|
type EnvironmentId,
|
|
type ProviderInstanceConfig,
|
|
type ProviderInstanceEnvironmentVariable,
|
|
} from "@t3tools/contracts";
|
|
|
|
import {
|
|
useEnvironmentSettings,
|
|
usePersistEnvironmentProviderInstanceMutation,
|
|
} from "../../hooks/useSettings";
|
|
|
|
import { cn } from "../../lib/utils";
|
|
import { normalizeProviderAccentColor } from "../../providerInstances";
|
|
import { readEnvironmentScope, useEnvironmentScope } from "../../state/session";
|
|
import { Button } from "../ui/button";
|
|
import { ChatGptConnectionButton } from "./ChatGptConnectionButton";
|
|
import { Dialog } from "../ui/dialog";
|
|
import { Badge } from "../ui/badge";
|
|
import { Input } from "../ui/input";
|
|
import { RadioGroup } from "../ui/radio-group";
|
|
import { toastManager } from "../ui/toast";
|
|
import { providerClients } from "./providerDriverMeta";
|
|
import { ProviderAccentColorPicker } from "./ProviderAccentColorPicker";
|
|
import { SettingsGroup } from "./SettingsGroup";
|
|
import { SettingsRow } from "./settingsLayout";
|
|
import { ProviderSettingsForm, deriveProviderSettingsFields } from "./ProviderSettingsForm";
|
|
import { WizardPanel, WizardPopup, WizardHeader, WizardFooter } from "../ui/wizard";
|
|
import {
|
|
ADD_PROVIDER_WIZARD_STEPS,
|
|
ACP_REGISTRY_WIZARD_STEPS,
|
|
LOCAL_ACP_WIZARD_STEPS,
|
|
deriveAvailableInstanceId,
|
|
resolveAcpRegistryWizardNavigation,
|
|
resolveWizardNavigation,
|
|
updateProviderIdentityDraft,
|
|
type ProviderIdentityDraft,
|
|
type WizardNavigation,
|
|
} from "./AddProviderInstanceDialog.logic";
|
|
import { AddProviderInstanceWizardSteps } from "./AddProviderInstanceWizardSteps";
|
|
import { AcpRegistrySearchStep } from "./AcpRegistrySearchStep";
|
|
import { ProviderWizardAuthenticationStep } from "./ProviderWizardAuthenticationStep";
|
|
import { resolveOfficialAcpRegistryIconUrl } from "./AcpRegistryIcon";
|
|
import { AddManagedCodexAccountDialog } from "./CodexSetupSection";
|
|
import { ProviderEnvironmentSection } from "./ProviderInstanceCard";
|
|
|
|
/**
|
|
* Normalize a user-provided label into a slug suffix for the instance id.
|
|
* The full id is formed by prefixing the driver slug. For example, label "Work" on
|
|
* driver "codex" becomes `codex_work`. Output is trimmed to 48 chars so the
|
|
* final composed id stays under the 64-char slug cap enforced by
|
|
* `ProviderInstanceId` in `@t3tools/contracts`.
|
|
*/
|
|
function slugifyLabel(value: string): string {
|
|
return value
|
|
.trim()
|
|
.toLowerCase()
|
|
.replace(/[^a-z0-9]+/g, "_")
|
|
.replace(/^_+|_+$/g, "")
|
|
.slice(0, 48);
|
|
}
|
|
|
|
function deriveInstanceId(driver: ProviderDriverKind, label: string): string {
|
|
const slug = slugifyLabel(label);
|
|
return slug ? `${driver}_${slug}` : "";
|
|
}
|
|
|
|
const INSTANCE_ID_PATTERN = /^[a-zA-Z][a-zA-Z0-9_-]*$/;
|
|
const DEFAULT_DRIVER_KIND = ProviderDriverKind.make("codex");
|
|
const ACP_REGISTRY_DRIVER_KIND = ProviderDriverKind.make("acpRegistry");
|
|
const DEFAULT_DRIVER_OPTION = providerClients.definitions[0]!;
|
|
const EMPTY_CONFIG_DRAFT: Record<string, unknown> = {};
|
|
/**
|
|
* Validate an instance id against the same slug rules the server applies in
|
|
* `ProviderInstanceId` (see `packages/contracts/src/providerInstance.ts`).
|
|
* Returns a user-facing error string, or `null` if valid.
|
|
*/
|
|
function validateInstanceId(id: string, existing: ReadonlySet<string>): string | null {
|
|
if (id.length === 0) return "Instance ID is required.";
|
|
if (id.length > 64) return "Instance ID must be 64 characters or fewer.";
|
|
if (!INSTANCE_ID_PATTERN.test(id)) {
|
|
return "Instance ID must start with a letter and use only letters, digits, '-', or '_'.";
|
|
}
|
|
if (existing.has(id)) return `An instance named '${id}' already exists.`;
|
|
return null;
|
|
}
|
|
|
|
interface AddProviderInstanceDialogProps {
|
|
readonly open: boolean;
|
|
readonly environmentId: EnvironmentId;
|
|
readonly environmentLabel: string;
|
|
readonly onOpenChange: (open: boolean) => void;
|
|
readonly onCreated?: (instanceId: ProviderInstanceId) => void;
|
|
}
|
|
|
|
export function AddProviderInstanceDialog({
|
|
open,
|
|
environmentId,
|
|
environmentLabel,
|
|
onOpenChange,
|
|
onCreated,
|
|
}: AddProviderInstanceDialogProps) {
|
|
const settings = useEnvironmentSettings(environmentId);
|
|
const persistProviderInstance = usePersistEnvironmentProviderInstanceMutation(environmentId);
|
|
const canManageProviders = useEnvironmentScope(environmentId, AuthProvidersManageScope);
|
|
|
|
const [wizardStep, setWizardStep] = useState(0);
|
|
const [addingChatGptAccount, setAddingChatGptAccount] = useState(false);
|
|
const [driver, setDriver] = useState<ProviderDriverKind>(DEFAULT_DRIVER_KIND);
|
|
const [identityByDriver, setIdentityByDriver] = useState<Record<string, ProviderIdentityDraft>>(
|
|
{},
|
|
);
|
|
const [selectedAcp, setSelectedAcp] = useState<AcpRegistrySearchAgent | null>(null);
|
|
const [localEnvironment, setLocalEnvironment] = useState<
|
|
ReadonlyArray<ProviderInstanceEnvironmentVariable>
|
|
>([]);
|
|
const [isManualAcpConfiguration, setIsManualAcpConfiguration] = useState(false);
|
|
const [isRegistryLoading, setIsRegistryLoading] = useState(false);
|
|
const [isPreparingRegistryAgent, setIsPreparingRegistryAgent] = useState(false);
|
|
// Driver-specific config drafts keyed by driver so toggling between drivers
|
|
// during the same dialog session does not lose in-progress input.
|
|
const [configByDriver, setConfigByDriver] = useState<Record<string, Record<string, unknown>>>({});
|
|
// Errors are suppressed until the user has tried to submit once. After that
|
|
// they update live so fixing the problem clears the message in place.
|
|
const [hasAttemptedSubmit, setHasAttemptedSubmit] = useState(false);
|
|
const [isSaving, setIsSaving] = useState(false);
|
|
const [createdInstanceId, setCreatedInstanceId] = useState<ProviderInstanceId | null>(null);
|
|
|
|
// Codex and Claude run at their default slots before they are configured, so
|
|
// those ids stay reserved; other unconfigured default slots are free to take.
|
|
const existingIds = useMemo(
|
|
() => new Set(["codex", "claudeAgent", ...Object.keys(settings.providerInstances ?? {})]),
|
|
[settings.providerInstances],
|
|
);
|
|
|
|
const driverOption = providerClients.get(driver) ?? DEFAULT_DRIVER_OPTION;
|
|
const isAcpRegistry = driver === ACP_REGISTRY_DRIVER_KIND;
|
|
const defaultIdentity: ProviderIdentityDraft = {
|
|
label: driverOption.label,
|
|
accentColor: "",
|
|
instanceIdOverride: null,
|
|
};
|
|
const { label, accentColor, instanceIdOverride } = identityByDriver[driver] ?? defaultIdentity;
|
|
const instanceId =
|
|
instanceIdOverride ??
|
|
deriveAvailableInstanceId(
|
|
(candidateLabel) => {
|
|
if (!candidateLabel.trim() || candidateLabel === driverOption.label) {
|
|
return isAcpRegistry ? `${driver}_custom` : driver;
|
|
}
|
|
return deriveInstanceId(driver, candidateLabel);
|
|
},
|
|
label,
|
|
existingIds,
|
|
);
|
|
const driverSettingsFields = useMemo(
|
|
() => deriveProviderSettingsFields(driverOption),
|
|
[driverOption],
|
|
);
|
|
const instanceIdError = validateInstanceId(instanceId, existingIds);
|
|
const showInstanceIdError = hasAttemptedSubmit && instanceIdError !== null;
|
|
const identityStep = 1;
|
|
const previewLabel = label.trim() || `${driverOption.label} Workspace`;
|
|
|
|
const configDraft = configByDriver[driver] ?? EMPTY_CONFIG_DRAFT;
|
|
const isLocalAcp = isAcpRegistry && isManualAcpConfiguration && configDraft.source === "local";
|
|
const localCommandPath =
|
|
typeof configDraft.commandPath === "string" ? configDraft.commandPath.trim() : "";
|
|
const manualAgentId = typeof configDraft.agentId === "string" ? configDraft.agentId.trim() : "";
|
|
const acpSelectionError = isLocalAcp
|
|
? localCommandPath.length > 0
|
|
? null
|
|
: "Executable is required."
|
|
: selectedAcp !== null || (isManualAcpConfiguration && manualAgentId.length > 0)
|
|
? null
|
|
: "Select an ACP or configure one manually.";
|
|
const wizardStepSummaries = isAcpRegistry
|
|
? ([
|
|
isLocalAcp ? "Local ACP command" : (selectedAcp?.name ?? (manualAgentId || null)),
|
|
previewLabel,
|
|
null,
|
|
] as const)
|
|
: ([driverOption.label, previewLabel, null] as const);
|
|
const setConfigDraft = (config: Record<string, unknown> | undefined) => {
|
|
setConfigByDriver((existing) => {
|
|
const next = { ...existing };
|
|
if (config === undefined || Object.keys(config).length === 0) {
|
|
delete next[driver];
|
|
} else {
|
|
next[driver] = config;
|
|
}
|
|
return next;
|
|
});
|
|
};
|
|
const setIdentityDraft = (update: Partial<ProviderIdentityDraft>) => {
|
|
setIdentityByDriver((existing) => ({
|
|
...existing,
|
|
[driver]: { ...(existing[driver] ?? defaultIdentity), ...update },
|
|
}));
|
|
};
|
|
|
|
const applyWizardNavigation = (navigation: WizardNavigation) => {
|
|
if (isSaving || isPreparingRegistryAgent || createdInstanceId) return;
|
|
if (navigation.kind === "blocked") {
|
|
setHasAttemptedSubmit(true);
|
|
}
|
|
if (isAcpRegistry && !isLocalAcp && navigation.kind === "navigate" && navigation.step === 2) {
|
|
void handleSave();
|
|
return;
|
|
}
|
|
setWizardStep(navigation.step);
|
|
};
|
|
|
|
const navigateToStep = (requestedStep: number) => {
|
|
applyWizardNavigation(
|
|
isAcpRegistry
|
|
? isLocalAcp
|
|
? resolveWizardNavigation(wizardStep, requestedStep, LOCAL_ACP_WIZARD_STEPS.length, {
|
|
instanceIdError,
|
|
prerequisite: { step: 0, error: acpSelectionError },
|
|
})
|
|
: resolveAcpRegistryWizardNavigation(wizardStep, requestedStep, {
|
|
instanceIdError,
|
|
selectionError: acpSelectionError,
|
|
})
|
|
: resolveWizardNavigation(wizardStep, requestedStep, ADD_PROVIDER_WIZARD_STEPS.length, {
|
|
instanceIdError,
|
|
}),
|
|
);
|
|
};
|
|
|
|
const handleAcpPrepared = (agent: AcpRegistrySearchAgent) => {
|
|
setDriver(ACP_REGISTRY_DRIVER_KIND);
|
|
const nextLabel = agent.name;
|
|
const registryIconUrl = resolveOfficialAcpRegistryIconUrl(agent.icon);
|
|
const nextInstanceId = deriveAvailableInstanceId(
|
|
(candidateLabel) => deriveInstanceId(ACP_REGISTRY_DRIVER_KIND, candidateLabel),
|
|
nextLabel,
|
|
existingIds,
|
|
);
|
|
setSelectedAcp(agent);
|
|
setIsManualAcpConfiguration(false);
|
|
setIdentityByDriver((existing) =>
|
|
updateProviderIdentityDraft(existing, ACP_REGISTRY_DRIVER_KIND, {
|
|
label: nextLabel,
|
|
instanceIdOverride: nextInstanceId,
|
|
}),
|
|
);
|
|
setConfigByDriver((existing) => ({
|
|
...existing,
|
|
[ACP_REGISTRY_DRIVER_KIND]: {
|
|
agentId: agent.id,
|
|
distribution: "auto",
|
|
...(registryIconUrl ? { registryIconUrl } : {}),
|
|
},
|
|
}));
|
|
setHasAttemptedSubmit(false);
|
|
setWizardStep(1);
|
|
};
|
|
|
|
const handleManualAcpConfiguration = () => {
|
|
setDriver(ACP_REGISTRY_DRIVER_KIND);
|
|
setSelectedAcp(null);
|
|
setIsManualAcpConfiguration(true);
|
|
setConfigByDriver((existing) => {
|
|
const next = { ...existing };
|
|
delete next[ACP_REGISTRY_DRIVER_KIND];
|
|
return next;
|
|
});
|
|
setIdentityByDriver((existing) =>
|
|
updateProviderIdentityDraft(existing, ACP_REGISTRY_DRIVER_KIND, {
|
|
label: "",
|
|
instanceIdOverride: null,
|
|
}),
|
|
);
|
|
setHasAttemptedSubmit(false);
|
|
};
|
|
|
|
const handleLocalAcpConfiguration = () => {
|
|
setDriver(ACP_REGISTRY_DRIVER_KIND);
|
|
setSelectedAcp(null);
|
|
setIsManualAcpConfiguration(true);
|
|
setConfigByDriver((existing) => ({
|
|
...existing,
|
|
[ACP_REGISTRY_DRIVER_KIND]: { source: "local", commandArgs: [] },
|
|
}));
|
|
setIdentityByDriver((existing) =>
|
|
updateProviderIdentityDraft(existing, ACP_REGISTRY_DRIVER_KIND, {
|
|
label: "Local ACP",
|
|
instanceIdOverride: null,
|
|
}),
|
|
);
|
|
setLocalEnvironment([]);
|
|
setHasAttemptedSubmit(false);
|
|
};
|
|
|
|
const handleSave = async () => {
|
|
if (!readEnvironmentScope(environmentId, AuthProvidersManageScope)) return;
|
|
if (isSaving || createdInstanceId) return;
|
|
setHasAttemptedSubmit(true);
|
|
if (instanceIdError !== null || (isAcpRegistry && acpSelectionError !== null)) return;
|
|
|
|
const config =
|
|
driver === "codex"
|
|
? { ...configByDriver[driver], setupMode: "existing" }
|
|
: (configByDriver[driver] ?? {});
|
|
const hasConfig = Object.keys(config).length > 0;
|
|
const normalizedAccentColor = normalizeProviderAccentColor(accentColor);
|
|
|
|
const nextInstance: ProviderInstanceConfig = {
|
|
driver,
|
|
enabled: true,
|
|
...(label.trim().length > 0 ? { displayName: label.trim() } : {}),
|
|
...(normalizedAccentColor ? { accentColor: normalizedAccentColor } : {}),
|
|
...(hasConfig ? { config } : {}),
|
|
...(isLocalAcp && localEnvironment.length > 0 ? { environment: localEnvironment } : {}),
|
|
};
|
|
// `ProviderInstanceId.make` revalidates the slug; we've already checked
|
|
// it via `validateInstanceId`, but going through the brand constructor
|
|
// keeps the type boundary honest and guards against any future drift in
|
|
// the slug rules.
|
|
const brandedId = ProviderInstanceId.make(instanceId);
|
|
setIsSaving(true);
|
|
const result = await persistProviderInstance({
|
|
operation: "create",
|
|
instanceId: brandedId,
|
|
instance: nextInstance,
|
|
});
|
|
if (result._tag === "Failure") {
|
|
const error = squashAtomCommandFailure(result);
|
|
setIsSaving(false);
|
|
toastManager.add({
|
|
type: "error",
|
|
title: "Could not add provider instance",
|
|
description: error instanceof Error ? error.message : "The settings update failed.",
|
|
});
|
|
return;
|
|
}
|
|
onCreated?.(brandedId);
|
|
if (isAcpRegistry && !isLocalAcp) {
|
|
setCreatedInstanceId(brandedId);
|
|
setIsSaving(false);
|
|
setWizardStep(2);
|
|
return;
|
|
}
|
|
toastManager.add({
|
|
type: "success",
|
|
title: "Provider instance added",
|
|
description: `${driverOption.label} instance '${instanceId}' was added.`,
|
|
});
|
|
onOpenChange(false);
|
|
};
|
|
|
|
if (addingChatGptAccount) {
|
|
return (
|
|
<AddManagedCodexAccountDialog
|
|
environmentId={environmentId}
|
|
onClose={() => onOpenChange(false)}
|
|
/>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
<WizardPopup size="wide">
|
|
<WizardHeader
|
|
title="Add provider"
|
|
description={<>Add an account or configure a provider on {environmentLabel}.</>}
|
|
>
|
|
{isAcpRegistry ? (
|
|
<AddProviderInstanceWizardSteps
|
|
currentStep={wizardStep}
|
|
summaries={wizardStepSummaries}
|
|
instanceIdError={instanceIdError}
|
|
steps={isLocalAcp ? LOCAL_ACP_WIZARD_STEPS : ACP_REGISTRY_WIZARD_STEPS}
|
|
disabled={isSaving || isPreparingRegistryAgent || createdInstanceId !== null}
|
|
identityStep={1}
|
|
prerequisite={{ step: 0, error: acpSelectionError }}
|
|
onNavigation={applyWizardNavigation}
|
|
/>
|
|
) : (
|
|
<AddProviderInstanceWizardSteps
|
|
currentStep={wizardStep}
|
|
summaries={wizardStepSummaries}
|
|
instanceIdError={instanceIdError}
|
|
disabled={isSaving || isPreparingRegistryAgent}
|
|
onNavigation={applyWizardNavigation}
|
|
/>
|
|
)}
|
|
</WizardHeader>
|
|
|
|
{createdInstanceId ? (
|
|
<ProviderWizardAuthenticationStep
|
|
environmentId={environmentId}
|
|
environmentLabel={environmentLabel}
|
|
instanceId={createdInstanceId}
|
|
onFinish={() => onOpenChange(false)}
|
|
/>
|
|
) : (
|
|
<>
|
|
<WizardPanel
|
|
className={cn(isAcpRegistry && wizardStep === identityStep && "min-h-72")}
|
|
holdHeight={wizardStep === 0 && !isManualAcpConfiguration && isRegistryLoading}
|
|
>
|
|
<div className={cn("grid gap-2", wizardStep !== 0 && "hidden")}>
|
|
<div id="add-instance-driver-label" className="text-sm font-medium text-foreground">
|
|
Provider
|
|
</div>
|
|
<RadioGroup
|
|
disabled={isPreparingRegistryAgent}
|
|
value={driver}
|
|
onValueChange={(value) => {
|
|
setDriver(ProviderDriverKind.make(value));
|
|
setIsManualAcpConfiguration(false);
|
|
setHasAttemptedSubmit(false);
|
|
}}
|
|
aria-labelledby="add-instance-driver-label"
|
|
className="grid grid-cols-1 sm:grid-cols-2"
|
|
>
|
|
{providerClients.definitions
|
|
.filter((option) => option.driverKind !== ACP_REGISTRY_DRIVER_KIND)
|
|
.map((option) => {
|
|
return (
|
|
<RadioPrimitive.Root
|
|
key={option.driverKind}
|
|
value={option.driverKind}
|
|
className="relative flex cursor-pointer items-center gap-3 rounded-lg bg-card px-3 py-3 text-left text-muted-foreground outline-none ring-1 ring-black/5 hover:bg-muted focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring data-checked:bg-primary/8 data-checked:text-foreground data-checked:ring-2 data-checked:ring-inset data-checked:ring-primary data-checked:hover:bg-primary/8 dark:bg-white/3 dark:ring-white/5 dark:hover:bg-white/5 dark:data-checked:bg-primary/15 dark:data-checked:ring-primary dark:data-checked:hover:bg-primary/15"
|
|
>
|
|
<ProviderInstanceIcon
|
|
driverKind={option.driverKind}
|
|
displayName={option.label}
|
|
iconClassName="size-4"
|
|
/>
|
|
<span className="min-w-0 flex-1 truncate text-sm font-medium text-foreground">
|
|
{option.label}
|
|
</span>
|
|
<RadioPrimitive.Indicator
|
|
className="grid size-5 shrink-0 place-items-center rounded-full bg-primary text-primary-foreground"
|
|
aria-hidden
|
|
>
|
|
<CheckIcon className="size-3.5 shrink-0" />
|
|
</RadioPrimitive.Indicator>
|
|
{option.badgeLabel ? (
|
|
<Badge variant="warning" size="sm">
|
|
{option.badgeLabel}
|
|
</Badge>
|
|
) : null}
|
|
</RadioPrimitive.Root>
|
|
);
|
|
})}
|
|
</RadioGroup>
|
|
</div>
|
|
|
|
{wizardStep === 0 ? (
|
|
<div className="space-y-4 pt-4">
|
|
<div className="flex items-center gap-3 text-xs text-muted-foreground">
|
|
<div aria-hidden className="flex-1 border-t border-border/70" />
|
|
<span>Or choose from ACP Registry</span>
|
|
<div aria-hidden className="flex-1 border-t border-border/70" />
|
|
</div>
|
|
{isAcpRegistry && isManualAcpConfiguration ? (
|
|
<div className="grid gap-4">
|
|
<div className="flex items-start justify-between gap-3">
|
|
<div>
|
|
<h3 className="text-sm font-medium text-foreground">
|
|
{isLocalAcp ? "Local ACP command" : "Enter manually"}
|
|
</h3>
|
|
<p className="mt-0.5 text-xs text-muted-foreground">
|
|
{isLocalAcp
|
|
? `Run an installed ACP executable on ${environmentLabel}.`
|
|
: "Enter an official registry ID and any local executable or auth override."}
|
|
</p>
|
|
</div>
|
|
<Button
|
|
onClick={() => {
|
|
setIsManualAcpConfiguration(false);
|
|
setHasAttemptedSubmit(false);
|
|
}}
|
|
size="xs"
|
|
variant="ghost"
|
|
>
|
|
Search registry
|
|
</Button>
|
|
</div>
|
|
<SettingsGroup variant="plain">
|
|
<ProviderSettingsForm
|
|
definition={driverOption}
|
|
value={configDraft}
|
|
idPrefix="add-provider-acpRegistry-manual"
|
|
variant="settings"
|
|
onChange={setConfigDraft}
|
|
/>
|
|
{isLocalAcp ? (
|
|
<ProviderEnvironmentSection
|
|
environment={localEnvironment}
|
|
onChange={setLocalEnvironment}
|
|
/>
|
|
) : null}
|
|
</SettingsGroup>
|
|
{isAcpRegistry && hasAttemptedSubmit && acpSelectionError ? (
|
|
<p className="text-2xs text-destructive">{acpSelectionError}</p>
|
|
) : null}
|
|
</div>
|
|
) : (
|
|
<>
|
|
<AcpRegistrySearchStep
|
|
environmentId={environmentId}
|
|
providerInstances={settings.providerInstances}
|
|
onPrepared={handleAcpPrepared}
|
|
onManualConfiguration={handleManualAcpConfiguration}
|
|
onLocalConfiguration={handleLocalAcpConfiguration}
|
|
onLoadingChange={setIsRegistryLoading}
|
|
onPreparingChange={setIsPreparingRegistryAgent}
|
|
/>
|
|
{isAcpRegistry && hasAttemptedSubmit && acpSelectionError ? (
|
|
<p className="mt-2 text-2xs text-destructive">{acpSelectionError}</p>
|
|
) : null}
|
|
</>
|
|
)}
|
|
</div>
|
|
) : null}
|
|
|
|
{isAcpRegistry && wizardStep === 1 && selectedAcp ? (
|
|
<div className="mb-4 flex items-start justify-between gap-3 border-b border-border/70 pb-3">
|
|
<div className="min-w-0">
|
|
<p className="truncate text-sm font-medium text-foreground">
|
|
{selectedAcp.name}
|
|
</p>
|
|
<p className="mt-0.5 text-xs text-muted-foreground">
|
|
v{selectedAcp.version} · {selectedAcp.distribution}
|
|
</p>
|
|
</div>
|
|
<div className="flex shrink-0 gap-2 text-2xs">
|
|
{selectedAcp.website ? (
|
|
<a
|
|
aria-label={`Open documentation for ${selectedAcp.name} (${selectedAcp.id})`}
|
|
className="text-muted-foreground hover:text-foreground"
|
|
href={selectedAcp.website}
|
|
rel="noreferrer"
|
|
target="_blank"
|
|
>
|
|
Docs
|
|
</a>
|
|
) : null}
|
|
{selectedAcp.repository ? (
|
|
<a
|
|
aria-label={`Open source for ${selectedAcp.name} (${selectedAcp.id})`}
|
|
className="text-muted-foreground hover:text-foreground"
|
|
href={selectedAcp.repository}
|
|
rel="noreferrer"
|
|
target="_blank"
|
|
>
|
|
Source
|
|
</a>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
) : null}
|
|
|
|
<SettingsGroup
|
|
variant="plain"
|
|
className={cn(wizardStep !== identityStep && "hidden")}
|
|
>
|
|
<SettingsRow
|
|
title={<label htmlFor="add-provider-label">Label</label>}
|
|
description={
|
|
<span id="add-provider-label-description">Shown in the provider list.</span>
|
|
}
|
|
control={
|
|
<Input
|
|
id="add-provider-label"
|
|
aria-describedby="add-provider-label-description"
|
|
size="sm"
|
|
className="w-full @min-[32rem]/settings-row:w-56"
|
|
placeholder="e.g. Work"
|
|
value={label}
|
|
onChange={(event) => setIdentityDraft({ label: event.target.value })}
|
|
/>
|
|
}
|
|
/>
|
|
<SettingsRow
|
|
title={<label htmlFor="add-provider-instance-id">Instance ID</label>}
|
|
description={
|
|
<span id="add-provider-instance-id-description">
|
|
Letters, digits, '-', or '_'.
|
|
</span>
|
|
}
|
|
status={
|
|
showInstanceIdError ? (
|
|
<span
|
|
id="add-provider-instance-id-error"
|
|
role="alert"
|
|
className="text-destructive"
|
|
>
|
|
{instanceIdError}
|
|
</span>
|
|
) : undefined
|
|
}
|
|
control={
|
|
<Input
|
|
id="add-provider-instance-id"
|
|
aria-describedby={
|
|
showInstanceIdError
|
|
? "add-provider-instance-id-description add-provider-instance-id-error"
|
|
: "add-provider-instance-id-description"
|
|
}
|
|
size="sm"
|
|
className="w-full @min-[32rem]/settings-row:w-56"
|
|
placeholder={`${driver}_work`}
|
|
value={instanceId}
|
|
onChange={(event) => {
|
|
setIdentityDraft({ instanceIdOverride: event.target.value });
|
|
}}
|
|
aria-invalid={showInstanceIdError}
|
|
/>
|
|
}
|
|
/>
|
|
<SettingsRow
|
|
title="Accent color"
|
|
description="Optional marker shown in the picker."
|
|
control={
|
|
<ProviderAccentColorPicker
|
|
displayName={label || driverOption.label}
|
|
value={accentColor || undefined}
|
|
onCommit={(value) => setIdentityDraft({ accentColor: value })}
|
|
layout="inline"
|
|
/>
|
|
}
|
|
/>
|
|
</SettingsGroup>
|
|
|
|
{!isAcpRegistry && driverSettingsFields.length > 0 ? (
|
|
<SettingsGroup variant="plain" className={cn(wizardStep !== 2 && "hidden")}>
|
|
<ProviderSettingsForm
|
|
definition={driverOption}
|
|
value={configDraft}
|
|
idPrefix={`add-provider-${driver}`}
|
|
variant="settings"
|
|
onChange={setConfigDraft}
|
|
/>
|
|
</SettingsGroup>
|
|
) : !isAcpRegistry && wizardStep === 2 ? (
|
|
<div className="grid gap-2">
|
|
<p className="text-sm text-muted-foreground">
|
|
This driver has no required configuration. You can add the instance now.
|
|
</p>
|
|
</div>
|
|
) : null}
|
|
</WizardPanel>
|
|
|
|
<WizardFooter>
|
|
<Button
|
|
variant={wizardStep === 0 ? "ghost-muted" : "outline"}
|
|
size="sm"
|
|
disabled={isSaving || isPreparingRegistryAgent}
|
|
onClick={() => {
|
|
if (wizardStep === 0) {
|
|
onOpenChange(false);
|
|
return;
|
|
}
|
|
setWizardStep((step) => Math.max(0, step - 1));
|
|
}}
|
|
>
|
|
{wizardStep === 0 ? "Cancel" : "Back"}
|
|
</Button>
|
|
{wizardStep === 0 && driver === "codex" ? (
|
|
<>
|
|
<Button variant="outline" size="sm" onClick={() => navigateToStep(1)}>
|
|
Configure manually
|
|
</Button>
|
|
<ChatGptConnectionButton
|
|
size="sm"
|
|
onClick={() => setAddingChatGptAccount(true)}
|
|
/>
|
|
</>
|
|
) : wizardStep < (isAcpRegistry ? 1 : 2) ? (
|
|
<Button
|
|
size="sm"
|
|
disabled={isPreparingRegistryAgent}
|
|
onClick={() => navigateToStep(wizardStep + 1)}
|
|
>
|
|
Next
|
|
</Button>
|
|
) : (
|
|
<Button
|
|
size="sm"
|
|
disabled={isSaving || !canManageProviders}
|
|
onClick={() => void handleSave()}
|
|
>
|
|
{isSaving
|
|
? "Adding..."
|
|
: isAcpRegistry && !isLocalAcp
|
|
? "Continue to sign-in"
|
|
: "Add instance"}
|
|
</Button>
|
|
)}
|
|
</WizardFooter>
|
|
</>
|
|
)}
|
|
</WizardPopup>
|
|
</Dialog>
|
|
);
|
|
}
|