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

AddProviderInstanceDialog.tsx

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