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