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

AddProviderInstanceDialog.tsx

746 lines29.9 KB

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