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