Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

AddProviderInstanceDialog.tsx

711 lines28.9 KB

1"use client";
2​
3import { ProviderInstanceIcon } from "../chat/ProviderInstanceIcon";
4​
5import { Radio as RadioPrimitive } from "@base-ui/react/radio";
6import { CheckIcon } from "lucide-react";
7import { useMemo, useState } from "react";
8import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
9import {
10 DEFAULT_UNIFIED_SETTINGS,
11 type AcpRegistrySearchAgent,
12 ProviderInstanceId,
13 ProviderDriverKind,
14 type EnvironmentId,
15 type ProviderInstanceConfig,
16 type ProviderInstanceEnvironmentVariable,
17} from "@t3tools/contracts";
18​
19import {
20 useEnvironmentSettings,
21 usePersistEnvironmentProviderInstanceMutation,
22} from "../../hooks/useSettings";
23import * as Equal from "effect/Equal";
24​
25import { cn } from "../../lib/utils";
26import { normalizeProviderAccentColor } from "../../providerInstances";
27import { Button } from "../ui/button";
28import { ChatGptConnectionButton } from "./ChatGptConnectionButton";
29import { Dialog } from "../ui/dialog";
30import { Badge } from "../ui/badge";
31import { Input } from "../ui/input";
32import { RadioGroup } from "../ui/radio-group";
33import { toastManager } from "../ui/toast";
34import { DRIVER_OPTION_BY_VALUE, DRIVER_OPTIONS } from "./providerDriverMeta";
35import { ProviderAccentColorPicker } from "./ProviderAccentColorPicker";
36import { SettingsGroup } from "./SettingsGroup";
37import { SettingsRow } from "./settingsLayout";
38import { ProviderSettingsForm, deriveProviderSettingsFields } from "./ProviderSettingsForm";
39import { WizardPanel, WizardPopup, WizardHeader, WizardFooter } from "../ui/wizard";
40import {
41 ADD_PROVIDER_WIZARD_STEPS,
42 ACP_REGISTRY_WIZARD_STEPS,
43 LOCAL_ACP_WIZARD_STEPS,
44 deriveAvailableInstanceId,
45 resolveAcpRegistryWizardNavigation,
46 resolveWizardNavigation,
47 updateProviderIdentityDraft,
48 type ProviderIdentityDraft,
49 type WizardNavigation,
50} from "./AddProviderInstanceDialog.logic";
51import { AddProviderInstanceWizardSteps } from "./AddProviderInstanceWizardSteps";
52import { AcpRegistrySearchStep } from "./AcpRegistrySearchStep";
53import { ProviderWizardAuthenticationStep } from "./ProviderWizardAuthenticationStep";
54import { resolveOfficialAcpRegistryIconUrl } from "./AcpRegistryIcon";
55import { AddManagedCodexAccountDialog } from "./CodexSetupSection";
56import { ProviderEnvironmentSection } from "./ProviderInstanceCard";
57​
58/**
59 * Normalize a user-provided label into a slug suffix for the instance id.
60 * The full id is formed by prefixing the driver slug. For example, label "Work" on
61 * driver "codex" becomes `codex_work`. Output is trimmed to 48 chars so the
62 * final composed id stays under the 64-char slug cap enforced by
63 * `ProviderInstanceId` in `@t3tools/contracts`.
64 */
65function slugifyLabel(value: string): string {
66 return value
67 .trim()
68 .toLowerCase()
69 .replace(/[^a-z0-9]+/g, "_")
70 .replace(/^_+|_+$/g, "")
71 .slice(0, 48);
73​
74function deriveInstanceId(driver: ProviderDriverKind, label: string): string {
75 const slug = slugifyLabel(label);
76 return slug ? `${driver}_${slug}` : "";
78​
79const INSTANCE_ID_PATTERN = /^[a-zA-Z][a-zA-Z0-9_-]*$/;
80const DEFAULT_DRIVER_KIND = ProviderDriverKind.make("codex");
81const ACP_REGISTRY_DRIVER_KIND = ProviderDriverKind.make("acpRegistry");
82const DEFAULT_DRIVER_OPTION = DRIVER_OPTIONS[0]!;
83const EMPTY_CONFIG_DRAFT: Record<string, unknown> = {};
84/**
85 * Validate an instance id against the same slug rules the server applies in
86 * `ProviderInstanceId` (see `packages/contracts/src/providerInstance.ts`).
87 * Returns a user-facing error string, or `null` if valid.
88 */
89function validateInstanceId(id: string, existing: ReadonlySet<string>): string | null {
90 if (id.length === 0) return "Instance ID is required.";
91 if (id.length > 64) return "Instance ID must be 64 characters or fewer.";
92 if (!INSTANCE_ID_PATTERN.test(id)) {
93 return "Instance ID must start with a letter and use only letters, digits, '-', or '_'.";
94 }
95 if (existing.has(id)) return `An instance named '${id}' already exists.`;
96 return null;
98​
99interface AddProviderInstanceDialogProps {
100 readonly open: boolean;
101 readonly environmentId: EnvironmentId;
102 readonly environmentLabel: string;
103 readonly onOpenChange: (open: boolean) => void;
104 readonly onCreated?: (instanceId: ProviderInstanceId) => void;
106​
107export function AddProviderInstanceDialog({
108 open,
109 environmentId,
110 environmentLabel,
111 onOpenChange,
112 onCreated,
113}: AddProviderInstanceDialogProps) {
114 const settings = useEnvironmentSettings(environmentId);
115 const persistProviderInstance = usePersistEnvironmentProviderInstanceMutation(environmentId);
116​
117 const [wizardStep, setWizardStep] = useState(0);
118 const [addingChatGptAccount, setAddingChatGptAccount] = useState(false);
119 const [driver, setDriver] = useState<ProviderDriverKind>(DEFAULT_DRIVER_KIND);
120 const [identityByDriver, setIdentityByDriver] = useState<Record<string, ProviderIdentityDraft>>(
121 {},
122 );
123 const [selectedAcp, setSelectedAcp] = useState<AcpRegistrySearchAgent | null>(null);
124 const [localEnvironment, setLocalEnvironment] = useState<
125 ReadonlyArray<ProviderInstanceEnvironmentVariable>
126 >([]);
127 const [isManualAcpConfiguration, setIsManualAcpConfiguration] = useState(false);
128 const [isRegistryLoading, setIsRegistryLoading] = useState(false);
129 const [isPreparingRegistryAgent, setIsPreparingRegistryAgent] = useState(false);
130 // Driver-specific config drafts keyed by driver so toggling between drivers
131 // during the same dialog session does not lose in-progress input.
132 const [configByDriver, setConfigByDriver] = useState<Record<string, Record<string, unknown>>>({});
133 // Errors are suppressed until the user has tried to submit once. After that
134 // they update live so fixing the problem clears the message in place.
135 const [hasAttemptedSubmit, setHasAttemptedSubmit] = useState(false);
136 const [isSaving, setIsSaving] = useState(false);
137 const [createdInstanceId, setCreatedInstanceId] = useState<ProviderInstanceId | null>(null);
138​
139 const existingIds = useMemo(() => {
140 const ids = new Set(["codex", "claudeAgent", ...Object.keys(settings.providerInstances ?? {})]);
141 const defaults = DEFAULT_UNIFIED_SETTINGS.providers as Record<string, unknown>;
142 // Reserve configured legacy slots too, so adding an account cannot replace them.
143 for (const [kind, config] of Object.entries(settings.providers ?? {})) {
144 if (!Equal.equals(config, defaults[kind])) ids.add(kind);
145 }
146 return ids;
147 }, [settings.providerInstances, settings.providers]);
148​
149 const driverOption = DRIVER_OPTION_BY_VALUE[driver] ?? DEFAULT_DRIVER_OPTION;
150 const isAcpRegistry = driver === ACP_REGISTRY_DRIVER_KIND;
151 const defaultIdentity: ProviderIdentityDraft = {
152 label: driverOption.label,
153 accentColor: "",
154 instanceIdOverride: null,
155 };
156 const { label, accentColor, instanceIdOverride } = identityByDriver[driver] ?? defaultIdentity;
157 const instanceId =
158 instanceIdOverride ??
159 deriveAvailableInstanceId(
160 (candidateLabel) => {
161 if (!candidateLabel.trim() || candidateLabel === driverOption.label) {
162 return isAcpRegistry ? `${driver}_custom` : driver;
163 }
164 return deriveInstanceId(driver, candidateLabel);
165 },
166 label,
167 existingIds,
168 );
169 const driverSettingsFields = useMemo(
170 () => deriveProviderSettingsFields(driverOption),
171 [driverOption],
172 );
173 const instanceIdError = validateInstanceId(instanceId, existingIds);
174 const showInstanceIdError = hasAttemptedSubmit && instanceIdError !== null;
175 const identityStep = 1;
176 const previewLabel = label.trim() || `${driverOption.label} Workspace`;
177​
178 const configDraft = configByDriver[driver] ?? EMPTY_CONFIG_DRAFT;
179 const isLocalAcp = isAcpRegistry && isManualAcpConfiguration && configDraft.source === "local";
180 const localCommandPath =
181 typeof configDraft.commandPath === "string" ? configDraft.commandPath.trim() : "";
182 const manualAgentId = typeof configDraft.agentId === "string" ? configDraft.agentId.trim() : "";
183 const acpSelectionError = isLocalAcp
184 ? localCommandPath.length > 0
185 ? null
186 : "Executable is required."
187 : selectedAcp !== null || (isManualAcpConfiguration && manualAgentId.length > 0)
188 ? null
189 : "Select an ACP or configure one manually.";
190 const wizardStepSummaries = isAcpRegistry
191 ? ([
192 isLocalAcp ? "Local ACP command" : (selectedAcp?.name ?? (manualAgentId || null)),
193 previewLabel,
194 null,
195 ] as const)
196 : ([driverOption.label, previewLabel, null] as const);
197 const setConfigDraft = (config: Record<string, unknown> | undefined) => {
198 setConfigByDriver((existing) => {
199 const next = { ...existing };
200 if (config === undefined || Object.keys(config).length === 0) {
201 delete next[driver];
202 } else {
203 next[driver] = config;
204 }
205 return next;
206 });
207 };
208 const setIdentityDraft = (update: Partial<ProviderIdentityDraft>) => {
209 setIdentityByDriver((existing) => ({
210 ...existing,
211 [driver]: { ...(existing[driver] ?? defaultIdentity), ...update },
212 }));
213 };
214​
215 const applyWizardNavigation = (navigation: WizardNavigation) => {
216 if (isSaving || isPreparingRegistryAgent || createdInstanceId) return;
217 if (navigation.kind === "blocked") {
218 setHasAttemptedSubmit(true);
219 }
220 if (isAcpRegistry && !isLocalAcp && navigation.kind === "navigate" && navigation.step === 2) {
221 void handleSave();
222 return;
223 }
224 setWizardStep(navigation.step);
225 };
226​
227 const navigateToStep = (requestedStep: number) => {
228 applyWizardNavigation(
229 isAcpRegistry
230 ? isLocalAcp
231 ? resolveWizardNavigation(wizardStep, requestedStep, LOCAL_ACP_WIZARD_STEPS.length, {
232 instanceIdError,
233 prerequisite: { step: 0, error: acpSelectionError },
234 })
235 : resolveAcpRegistryWizardNavigation(wizardStep, requestedStep, {
236 instanceIdError,
237 selectionError: acpSelectionError,
238 })
239 : resolveWizardNavigation(wizardStep, requestedStep, ADD_PROVIDER_WIZARD_STEPS.length, {
240 instanceIdError,
241 }),
242 );
243 };
244​
245 const handleAcpPrepared = (agent: AcpRegistrySearchAgent) => {
246 setDriver(ACP_REGISTRY_DRIVER_KIND);
247 const nextLabel = agent.name;
248 const registryIconUrl = resolveOfficialAcpRegistryIconUrl(agent.icon);
249 const nextInstanceId = deriveAvailableInstanceId(
250 (candidateLabel) => deriveInstanceId(ACP_REGISTRY_DRIVER_KIND, candidateLabel),
251 nextLabel,
252 existingIds,
253 );
254 setSelectedAcp(agent);
255 setIsManualAcpConfiguration(false);
256 setIdentityByDriver((existing) =>
257 updateProviderIdentityDraft(existing, ACP_REGISTRY_DRIVER_KIND, {
258 label: nextLabel,
259 instanceIdOverride: nextInstanceId,
260 }),
261 );
262 setConfigByDriver((existing) => ({
263 ...existing,
264 [ACP_REGISTRY_DRIVER_KIND]: {
265 agentId: agent.id,
266 distribution: "auto",
267 ...(registryIconUrl ? { registryIconUrl } : {}),
268 },
269 }));
270 setHasAttemptedSubmit(false);
271 setWizardStep(1);
272 };
273​
274 const handleManualAcpConfiguration = () => {
275 setDriver(ACP_REGISTRY_DRIVER_KIND);
276 setSelectedAcp(null);
277 setIsManualAcpConfiguration(true);
278 setConfigByDriver((existing) => {
279 const next = { ...existing };
280 delete next[ACP_REGISTRY_DRIVER_KIND];
281 return next;
282 });
283 setIdentityByDriver((existing) =>
284 updateProviderIdentityDraft(existing, ACP_REGISTRY_DRIVER_KIND, {
285 label: "",
286 instanceIdOverride: null,
287 }),
288 );
289 setHasAttemptedSubmit(false);
290 };
291​
292 const handleLocalAcpConfiguration = () => {
293 setDriver(ACP_REGISTRY_DRIVER_KIND);
294 setSelectedAcp(null);
295 setIsManualAcpConfiguration(true);
296 setConfigByDriver((existing) => ({
297 ...existing,
298 [ACP_REGISTRY_DRIVER_KIND]: { source: "local", commandArgs: [] },
299 }));
300 setIdentityByDriver((existing) =>
301 updateProviderIdentityDraft(existing, ACP_REGISTRY_DRIVER_KIND, {
302 label: "Local ACP",
303 instanceIdOverride: null,
304 }),
305 );
306 setLocalEnvironment([]);
307 setHasAttemptedSubmit(false);
308 };
309​
310 const handleSave = async () => {
311 if (isSaving || createdInstanceId) return;
312 setHasAttemptedSubmit(true);
313 if (instanceIdError !== null || (isAcpRegistry && acpSelectionError !== null)) return;
314​
315 const config =
316 driver === "codex"
317 ? { ...configByDriver[driver], setupMode: "existing" }
318 : (configByDriver[driver] ?? {});
319 const hasConfig = Object.keys(config).length > 0;
320 const normalizedAccentColor = normalizeProviderAccentColor(accentColor);
321​
322 const nextInstance: ProviderInstanceConfig = {
323 driver,
324 enabled: true,
325 ...(label.trim().length > 0 ? { displayName: label.trim() } : {}),
326 ...(normalizedAccentColor ? { accentColor: normalizedAccentColor } : {}),
327 ...(hasConfig ? { config } : {}),
328 ...(isLocalAcp && localEnvironment.length > 0 ? { environment: localEnvironment } : {}),
329 };
330 // `ProviderInstanceId.make` revalidates the slug; we've already checked
331 // it via `validateInstanceId`, but going through the brand constructor
332 // keeps the type boundary honest and guards against any future drift in
333 // the slug rules.
334 const brandedId = ProviderInstanceId.make(instanceId);
335 setIsSaving(true);
336 const result = await persistProviderInstance({
337 operation: "create",
338 instanceId: brandedId,
339 instance: nextInstance,
340 });
341 if (result._tag === "Failure") {
342 const error = squashAtomCommandFailure(result);
343 setIsSaving(false);
344 toastManager.add({
345 type: "error",
346 title: "Could not add provider instance",
347 description: error instanceof Error ? error.message : "The settings update failed.",
348 });
349 return;
350 }
351 onCreated?.(brandedId);
352 if (isAcpRegistry && !isLocalAcp) {
353 setCreatedInstanceId(brandedId);
354 setIsSaving(false);
355 setWizardStep(2);
356 return;
357 }
358 toastManager.add({
359 type: "success",
360 title: "Provider instance added",
361 description: `${driverOption.label} instance '${instanceId}' was added.`,
362 });
363 onOpenChange(false);
364 };
365​
366 if (addingChatGptAccount) {
367 return (
368 <AddManagedCodexAccountDialog
369 environmentId={environmentId}
370 onClose={() => onOpenChange(false)}
371 />
372 );
373 }
374​
375 return (
376 <Dialog open={open} onOpenChange={onOpenChange}>
377 <WizardPopup size="wide">
378 <WizardHeader
379 title="Add provider"
380 description={<>Add an account or configure a provider on {environmentLabel}.</>}
381 >
382 {isAcpRegistry ? (
383 <AddProviderInstanceWizardSteps
384 currentStep={wizardStep}
385 summaries={wizardStepSummaries}
386 instanceIdError={instanceIdError}
387 steps={isLocalAcp ? LOCAL_ACP_WIZARD_STEPS : ACP_REGISTRY_WIZARD_STEPS}
388 disabled={isSaving || isPreparingRegistryAgent || createdInstanceId !== null}
389 identityStep={1}
390 prerequisite={{ step: 0, error: acpSelectionError }}
391 onNavigation={applyWizardNavigation}
392 />
393 ) : (
394 <AddProviderInstanceWizardSteps
395 currentStep={wizardStep}
396 summaries={wizardStepSummaries}
397 instanceIdError={instanceIdError}
398 disabled={isSaving || isPreparingRegistryAgent}
399 onNavigation={applyWizardNavigation}
400 />
401 )}
402 </WizardHeader>
403​
404 {createdInstanceId ? (
405 <ProviderWizardAuthenticationStep
406 environmentId={environmentId}
407 environmentLabel={environmentLabel}
408 instanceId={createdInstanceId}
409 onFinish={() => onOpenChange(false)}
410 />
411 ) : (
412 <>
413 <WizardPanel
414 className={cn(isAcpRegistry && wizardStep === identityStep && "min-h-72")}
415 holdHeight={wizardStep === 0 && !isManualAcpConfiguration && isRegistryLoading}
416 >
417 <div className={cn("grid gap-2", wizardStep !== 0 && "hidden")}>
418 <div id="add-instance-driver-label" className="text-sm font-medium text-foreground">
419 Provider
420 </div>
421 <RadioGroup
422 disabled={isPreparingRegistryAgent}
423 value={driver}
424 onValueChange={(value) => {
425 setDriver(ProviderDriverKind.make(value));
426 setIsManualAcpConfiguration(false);
427 setHasAttemptedSubmit(false);
428 }}
429 aria-labelledby="add-instance-driver-label"
430 className="grid grid-cols-1 sm:grid-cols-2"
431 >
432 {DRIVER_OPTIONS.filter((option) => option.value !== ACP_REGISTRY_DRIVER_KIND).map(
433 (option) => {
434 return (
435 <RadioPrimitive.Root
436 key={option.value}
437 value={option.value}
438 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-ring data-checked:bg-primary/8 data-checked:text-foreground data-checked:ring-2 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"
439 >
440 <ProviderInstanceIcon
441 driverKind={option.value}
442 displayName={option.label}
443 iconClassName="size-4"
444 />
445 <span className="min-w-0 flex-1 truncate text-sm font-medium text-foreground">
446 {option.label}
447 </span>
448 <RadioPrimitive.Indicator
449 className="grid size-5 shrink-0 place-items-center rounded-full bg-primary text-primary-foreground"
450 aria-hidden
451 >
452 <CheckIcon className="size-3.5 shrink-0" />
453 </RadioPrimitive.Indicator>
454 {option.badgeLabel ? (
455 <Badge variant="warning" size="sm">
456 {option.badgeLabel}
457 </Badge>
458 ) : null}
459 </RadioPrimitive.Root>
460 );
461 },
462 )}
463 </RadioGroup>
464 </div>
465​
466 {wizardStep === 0 ? (
467 <div className="space-y-4 pt-4">
468 <div className="flex items-center gap-3 text-xs text-muted-foreground">
469 <div aria-hidden className="flex-1 border-t border-border/70" />
470 <span>Or choose from ACP Registry</span>
471 <div aria-hidden className="flex-1 border-t border-border/70" />
472 </div>
473 {isAcpRegistry && isManualAcpConfiguration ? (
474 <div className="grid gap-4">
475 <div className="flex items-start justify-between gap-3">
476 <div>
477 <h3 className="text-sm font-medium text-foreground">
478 {isLocalAcp ? "Local ACP command" : "Enter manually"}
479 </h3>
480 <p className="mt-0.5 text-xs text-muted-foreground">
481 {isLocalAcp
482 ? `Run an installed ACP executable on ${environmentLabel}.`
483 : "Enter an official registry ID and any local executable or auth override."}
484 </p>
485 </div>
486 <Button
487 onClick={() => {
488 setIsManualAcpConfiguration(false);
489 setHasAttemptedSubmit(false);
490 }}
491 size="xs"
492 variant="ghost"
493 >
494 Search registry
495 </Button>
496 </div>
497 <SettingsGroup variant="plain">
498 <ProviderSettingsForm
499 definition={driverOption}
500 value={configDraft}
501 idPrefix="add-provider-acpRegistry-manual"
502 variant="settings"
503 onChange={setConfigDraft}
504 />
505 {isLocalAcp ? (
506 <ProviderEnvironmentSection
507 environment={localEnvironment}
508 onChange={setLocalEnvironment}
509 />
510 ) : null}
511 </SettingsGroup>
512 {isAcpRegistry && hasAttemptedSubmit && acpSelectionError ? (
513 <p className="text-2xs text-destructive">{acpSelectionError}</p>
514 ) : null}
515 </div>
516 ) : (
517 <>
518 <AcpRegistrySearchStep
519 environmentId={environmentId}
520 providerInstances={settings.providerInstances}
521 onPrepared={handleAcpPrepared}
522 onManualConfiguration={handleManualAcpConfiguration}
523 onLocalConfiguration={handleLocalAcpConfiguration}
524 onLoadingChange={setIsRegistryLoading}
525 onPreparingChange={setIsPreparingRegistryAgent}
526 />
527 {isAcpRegistry && hasAttemptedSubmit && acpSelectionError ? (
528 <p className="mt-2 text-2xs text-destructive">{acpSelectionError}</p>
529 ) : null}
530 </>
531 )}
532 </div>
533 ) : null}
534​
535 {isAcpRegistry && wizardStep === 1 && selectedAcp ? (
536 <div className="mb-4 flex items-start justify-between gap-3 border-b border-border/70 pb-3">
537 <div className="min-w-0">
538 <p className="truncate text-sm font-medium text-foreground">
539 {selectedAcp.name}
540 </p>
541 <p className="mt-0.5 text-xs text-muted-foreground">
542 v{selectedAcp.version} · {selectedAcp.distribution}
543 </p>
544 </div>
545 <div className="flex shrink-0 gap-2 text-2xs">
546 {selectedAcp.website ? (
547 <a
548 aria-label={`Open documentation for ${selectedAcp.name} (${selectedAcp.id})`}
549 className="text-muted-foreground hover:text-foreground"
550 href={selectedAcp.website}
551 rel="noreferrer"
552 target="_blank"
553 >
554 Docs
555 </a>
556 ) : null}
557 {selectedAcp.repository ? (
558 <a
559 aria-label={`Open source for ${selectedAcp.name} (${selectedAcp.id})`}
560 className="text-muted-foreground hover:text-foreground"
561 href={selectedAcp.repository}
562 rel="noreferrer"
563 target="_blank"
564 >
565 Source
566 </a>
567 ) : null}
568 </div>
569 </div>
570 ) : null}
571​
572 <SettingsGroup
573 variant="plain"
574 className={cn(wizardStep !== identityStep && "hidden")}
575 >
576 <SettingsRow
577 title={<label htmlFor="add-provider-label">Label</label>}
578 description={
579 <span id="add-provider-label-description">Shown in the provider list.</span>
580 }
581 control={
582 <Input
583 id="add-provider-label"
584 aria-describedby="add-provider-label-description"
585 size="sm"
586 className="w-full @min-[32rem]/settings-row:w-56"
587 placeholder="e.g. Work"
588 value={label}
589 onChange={(event) => setIdentityDraft({ label: event.target.value })}
590 />
591 }
592 />
593 <SettingsRow
594 title={<label htmlFor="add-provider-instance-id">Instance ID</label>}
595 description={
596 <span id="add-provider-instance-id-description">
597 Letters, digits, '-', or '_'.
598 </span>
599 }
600 status={
601 showInstanceIdError ? (
602 <span
603 id="add-provider-instance-id-error"
604 role="alert"
605 className="text-destructive"
606 >
607 {instanceIdError}
608 </span>
609 ) : undefined
610 }
611 control={
612 <Input
613 id="add-provider-instance-id"
614 aria-describedby={
615 showInstanceIdError
616 ? "add-provider-instance-id-description add-provider-instance-id-error"
617 : "add-provider-instance-id-description"
618 }
619 size="sm"
620 className="w-full @min-[32rem]/settings-row:w-56"
621 placeholder={`${driver}_work`}
622 value={instanceId}
623 onChange={(event) => {
624 setIdentityDraft({ instanceIdOverride: event.target.value });
625 }}
626 aria-invalid={showInstanceIdError}
627 />
628 }
629 />
630 <SettingsRow
631 title="Accent color"
632 description="Optional marker shown in the picker."
633 control={
634 <ProviderAccentColorPicker
635 displayName={label || driverOption.label}
636 value={accentColor || undefined}
637 onCommit={(value) => setIdentityDraft({ accentColor: value })}
638 layout="inline"
639 />
640 }
641 />
642 </SettingsGroup>
643​
644 {!isAcpRegistry && driverSettingsFields.length > 0 ? (
645 <SettingsGroup variant="plain" className={cn(wizardStep !== 2 && "hidden")}>
646 <ProviderSettingsForm
647 definition={driverOption}
648 value={configDraft}
649 idPrefix={`add-provider-${driver}`}
650 variant="settings"
651 onChange={setConfigDraft}
652 />
653 </SettingsGroup>
654 ) : !isAcpRegistry && wizardStep === 2 ? (
655 <div className="grid gap-2">
656 <p className="text-sm text-muted-foreground">
657 This driver has no required configuration. You can add the instance now.
658 </p>
659 </div>
660 ) : null}
661 </WizardPanel>
662​
663 <WizardFooter>
664 <Button
665 variant={wizardStep === 0 ? "ghost-muted" : "outline"}
666 size="sm"
667 disabled={isSaving || isPreparingRegistryAgent}
668 onClick={() => {
669 if (wizardStep === 0) {
670 onOpenChange(false);
671 return;
672 }
673 setWizardStep((step) => Math.max(0, step - 1));
674 }}
675 >
676 {wizardStep === 0 ? "Cancel" : "Back"}
677 </Button>
678 {wizardStep === 0 && driver === "codex" ? (
679 <>
680 <Button variant="outline" size="sm" onClick={() => navigateToStep(1)}>
681 Configure manually
682 </Button>
683 <ChatGptConnectionButton
684 size="sm"
685 onClick={() => setAddingChatGptAccount(true)}
686 />
687 </>
688 ) : wizardStep < (isAcpRegistry ? 1 : 2) ? (
689 <Button
690 size="sm"
691 disabled={isPreparingRegistryAgent}
692 onClick={() => navigateToStep(wizardStep + 1)}
693 >
694 Next
695 </Button>
696 ) : (
697 <Button size="sm" disabled={isSaving} onClick={() => void handleSave()}>
698 {isSaving
699 ? "Adding..."
700 : isAcpRegistry && !isLocalAcp
701 ? "Continue to sign-in"
702 : "Add instance"}
703 </Button>
704 )}
705 </WizardFooter>
706 </>
707 )}
708 </WizardPopup>
709 </Dialog>
710 );