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

AddProviderInstanceDialog.tsx

698 lines28.2 KB

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