Open History to see the last commit
1import { Spinner } from "~/components/ui/spinner";
2
3import {
4 AlertTriangleIcon,
5 CheckIcon,
6 ArrowUpCircleIcon,
7 CopyIcon,
8 DownloadIcon,
9 ExternalLinkIcon,
10 LayersIcon,
11 PlusIcon,
12 Trash2Icon,
13 XIcon,
14} from "lucide-react";
15import { Lock as LockGlyph, LockOpen } from "lucide";
16import * as Arr from "effect/Array";
17import * as Result from "effect/Result";
18import { Fragment, useState, type ReactElement, type ReactNode } from "react";
19import {
20 isProviderDriverKind,
21 resolveProviderInstanceEnabled,
22 type ProviderInstanceConfig,
23 type ProviderInstanceEnvironmentVariable,
24 type ProviderInstanceId,
25 type AcpRegistryUrlAuthAction,
26 type EnvironmentId,
27 type ProjectId,
28 type ProviderDriverKind,
29 type SecretReference,
30 type ServerProvider,
31 type ServerProviderModel,
32} from "@t3tools/contracts";
33
34import {
35 type CustomModelDefinition,
36 readCustomModelEntries,
37 toCustomModelSetting,
38} from "@t3tools/shared/model";
39import { cn } from "../../lib/utils";
40import { useCopyToClipboard } from "../../hooks/useCopyToClipboard";
41import { useStableCallback } from "../../hooks/useStableCallback";
42import { normalizeProviderAccentColor } from "../../providerInstances";
43import { Badge } from "../ui/badge";
44import { Button } from "../ui/button";
45import { MorphIcon } from "~/components/MorphIcon";
46import { DraftInput } from "../ui/draft-input";
47import { SecretSourceInput, type SecretSource } from "./SecretSourceInput";
48import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
49import { Switch } from "../ui/switch";
50import { ManagedControl, ManagedNotice } from "../ManagedPolicy";
51import { managedInstanceLocks, useManagedPolicy } from "../../state/managedPolicy";
52import { disallowedProviderMessage, isManagedDriverAllowed } from "@t3tools/contracts";
53import { stackedThreadToast, toastManager } from "../ui/toast";
54import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
55import type {
56 ProviderClientDefinition,
57 ProviderEnvironmentField,
58} from "@t3tools/provider-core/client";
59import {
60 deriveProviderSettingsFields,
61 ProviderSettingsForm,
62 reconcileRowsDraft,
63 seedRowsDraft,
64} from "./ProviderSettingsForm";
65import { ProviderModelsSection } from "./ProviderModelsSection";
66import { ProviderInstanceIcon } from "../chat/ProviderInstanceIcon";
67import { ProviderAccentColorPicker } from "./ProviderAccentColorPicker";
68import { RedactedSensitiveText } from "./RedactedSensitiveText";
69import { SettingResetButton, SettingsRow, SettingsSection } from "./settingsLayout";
70import { AcpSessionManagementSection } from "./AcpSessionManagementSection";
71import { FoldedSettingsSection } from "./FoldedSettingsSection";
72import { readCodexSetupMode } from "./CodexSetupSection.logic";
73import {
74 getProviderVersionAdvisoryPresentation,
75 PROVIDER_STATUS_STYLES,
76 getProviderStatusKey,
77 getProviderSummary,
78 getProviderVersionLabel,
79} from "./providerStatus";
80
81const ENVIRONMENT_VARIABLE_NAME_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
82
83function ProviderStatusDiagnostic({
84 detail,
85 children,
86}: {
87 detail: string | null;
88 children: ReactElement;
89}) {
90 if (!detail) return children;
91 return (
92 <Tooltip>
93 <TooltipTrigger render={children} />
94 <TooltipPopup side="top">{detail}</TooltipPopup>
95 </Tooltip>
96 );
97}
98
99let environmentVariableDraftId = 0;
100const nextEnvironmentVariableDraftId = () => `provider-env-${environmentVariableDraftId++}`;
101
102type EnvironmentDraftRow = {
103 readonly id: string;
104 readonly name: string;
105 readonly value: ProviderInstanceEnvironmentVariable["value"];
106 readonly sensitive: boolean;
107 readonly valueRedacted?: boolean;
108};
109
110function makeEnvironmentDraftRow(
111 variable: ProviderInstanceEnvironmentVariable,
112 index: number,
113): EnvironmentDraftRow {
114 return {
115 id: `${index}:${variable.name}`,
116 name: variable.name,
117 value: variable.value,
118 sensitive: variable.sensitive,
119 ...(variable.valueRedacted !== undefined ? { valueRedacted: variable.valueRedacted } : {}),
120 };
121}
122
123const toEnvironmentDraftRows = (environment: ReadonlyArray<ProviderInstanceEnvironmentVariable>) =>
124 environment.map(makeEnvironmentDraftRow);
125
126function environmentValuesEqual(
127 left: ProviderInstanceEnvironmentVariable["value"],
128 right: ProviderInstanceEnvironmentVariable["value"],
129): boolean {
130 if (typeof left === "string" || typeof right === "string") return left === right;
131 return left.provider === right.provider && left.reference === right.reference;
132}
133
134function providerEnvironmentsEqual(
135 left: ReadonlyArray<ProviderInstanceEnvironmentVariable>,
136 right: ReadonlyArray<ProviderInstanceEnvironmentVariable>,
137): boolean {
138 return (
139 left.length === right.length &&
140 left.every((variable, index) => {
141 const other = right[index];
142 return (
143 other !== undefined &&
144 variable.name === other.name &&
145 environmentValuesEqual(variable.value, other.value) &&
146 variable.sensitive === other.sensitive &&
147 variable.valueRedacted === other.valueRedacted
148 );
149 })
150 );
151}
152
153function readConfigString(config: unknown, key: string): string | null {
154 if (config === null || typeof config !== "object") return null;
155 const value = (config as Record<string, unknown>)[key];
156 return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
157}
158
159/** Preserve explicit empty arrays/objects; clearing a custom list differs from selecting driver defaults. */
160function nextConfigBlobWithValue(
161 config: unknown,
162 key: string,
163 value: unknown,
164): Record<string, unknown> {
165 const base: Record<string, unknown> =
166 config !== null && typeof config === "object" ? { ...(config as Record<string, unknown>) } : {};
167 base[key] = value;
168 return base;
169}
170
171export function deriveProviderModelsForDisplay(input: {
172 readonly liveModels: ReadonlyArray<ServerProviderModel> | undefined;
173 readonly customModels: ReadonlyArray<CustomModelDefinition>;
174}): ReadonlyArray<ServerProviderModel> {
175 const liveCustomModelsBySlug = new Map(
176 Arr.filterMap(input.liveModels ?? [], (model) =>
177 model.isCustom ? Result.succeed([model.slug, model] as const) : Result.failVoid,
178 ),
179 );
180 const serverModels = input.liveModels?.filter((model) => !model.isCustom) ?? [];
181 const serverSlugs = new Set(serverModels.map((model) => model.slug));
182 const customModels = input.customModels.flatMap((entry) =>
183 serverSlugs.has(entry.slug)
184 ? []
185 : [
186 {
187 slug: entry.slug,
188 name: entry.name,
189 isCustom: true,
190 capabilities:
191 entry.capabilities ?? liveCustomModelsBySlug.get(entry.slug)?.capabilities ?? null,
192 },
193 ],
194 );
195 return [...serverModels, ...customModels];
196}
197
198function ProviderAuthEmail(props: { readonly email: string | undefined }) {
199 const email = props.email?.trim();
200 if (!email) return null;
201
202 return (
203 <RedactedSensitiveText
204 value={email}
205 ariaLabel="Toggle account email visibility"
206 revealTooltip="Click to reveal email"
207 hideTooltip="Click to hide email"
208 className="max-w-full truncate"
209 />
210 );
211}
212
213function readProviderEnvironmentVariable(
214 environment: ReadonlyArray<ProviderInstanceEnvironmentVariable> | undefined,
215 name: string,
216): ProviderInstanceEnvironmentVariable | undefined {
217 return environment?.find((variable) => variable.name === name);
218}
219
220function providerEnvironmentWithoutNames(
221 environment: ReadonlyArray<ProviderInstanceEnvironmentVariable> | undefined,
222 names: ReadonlySet<string>,
223): ReadonlyArray<ProviderInstanceEnvironmentVariable> {
224 return (environment ?? []).filter((variable) => !names.has(variable.name));
225}
226
227export function nextProviderEnvironmentWithFieldValue(
228 environment: ReadonlyArray<ProviderInstanceEnvironmentVariable> | undefined,
229 field: ProviderEnvironmentField,
230 value: string,
231): ReadonlyArray<ProviderInstanceEnvironmentVariable> {
232 const trimmed = value.trim();
233 const next: ProviderInstanceEnvironmentVariable[] = [];
234 let found = false;
235
236 for (const variable of environment ?? []) {
237 if (variable.name !== field.name) {
238 next.push(variable);
239 continue;
240 }
241 found = true;
242 if (trimmed.length > 0) {
243 next.push({
244 name: variable.name,
245 value: trimmed,
246 sensitive: field.sensitive ?? true,
247 });
248 }
249 }
250
251 if (!found && trimmed.length > 0) {
252 next.push({
253 name: field.name,
254 value: trimmed,
255 sensitive: field.sensitive ?? true,
256 });
257 }
258
259 return next;
260}
261
262export function nextProviderEnvironmentWithFieldSecret(
263 environment: ReadonlyArray<ProviderInstanceEnvironmentVariable> | undefined,
264 field: ProviderEnvironmentField,
265 secret: SecretReference | undefined,
266): ReadonlyArray<ProviderInstanceEnvironmentVariable> {
267 const others = providerEnvironmentWithoutNames(environment, new Set([field.name]));
268 return secret === undefined
269 ? others
270 : [...others, { name: field.name, value: secret, sensitive: true }];
271}
272
273function ProviderEnvironmentFieldRow(props: {
274 readonly field: ProviderEnvironmentField;
275 readonly variable: ProviderInstanceEnvironmentVariable | undefined;
276 readonly idPrefix: string;
277 readonly onCommit: (field: ProviderEnvironmentField, value: string) => void;
278 readonly onSecretChange: (
279 field: ProviderEnvironmentField,
280 secret: SecretReference | undefined,
281 ) => void;
282 readonly onRemove: (field: ProviderEnvironmentField) => void;
283 readonly managedReason?: string | undefined;
284 readonly secretSources: ReadonlyArray<SecretSource>;
285}) {
286 const inputId = `${props.idPrefix}-environment-${props.field.name}`;
287 const value = props.variable?.valueRedacted ? "" : (props.variable?.value ?? "");
288
289 return (
290 <SettingsRow
291 title={<label htmlFor={inputId}>{props.field.label}</label>}
292 description={props.field.description}
293 managed={props.managedReason}
294 control={
295 <div className="flex w-full min-w-0 items-center gap-2 @min-[32rem]/settings-row:w-56">
296 {props.field.sensitive === false ? (
297 <DraftInput
298 id={inputId}
299 size="sm"
300 className="min-w-0 flex-1"
301 autoComplete="off"
302 value={typeof value === "string" ? value : ""}
303 onCommit={(next) => props.onCommit(props.field, next)}
304 placeholder={props.field.placeholder}
305 spellCheck={false}
306 />
307 ) : (
308 <SecretSourceInput
309 id={inputId}
310 size="sm"
311 className="min-w-0 flex-1"
312 value={value}
313 onCommit={(next) => props.onCommit(props.field, next)}
314 placeholder={props.field.placeholder}
315 configured={props.variable?.valueRedacted === true}
316 spellCheck={false}
317 aria-label={props.field.label}
318 sources={props.secretSources}
319 onSecretChange={(secret) => props.onSecretChange(props.field, secret)}
320 />
321 )}
322 {props.variable ? (
323 <Button
324 type="button"
325 size="icon-sm"
326 variant="ghost-destructive"
327 onClick={() => props.onRemove(props.field)}
328 aria-label={`Clear ${props.field.label}`}
329 >
330 <XIcon className="size-3.5" />
331 </Button>
332 ) : null}
333 </div>
334 }
335 />
336 );
337}
338
339export function ProviderEnvironmentSection(props: {
340 readonly environment: ReadonlyArray<ProviderInstanceEnvironmentVariable>;
341 readonly onChange: (environment: ReadonlyArray<ProviderInstanceEnvironmentVariable>) => void;
342 /** Variables an administrator's policy pins: listed by name, never editable or removable. */
343 readonly managed?: { readonly names: ReadonlySet<string>; readonly reason: string } | undefined;
344 readonly secretSources?: ReadonlyArray<SecretSource>;
345}) {
346 const [storedDraft, setDraft] = useState(() =>
347 seedRowsDraft(props.environment, toEnvironmentDraftRows),
348 );
349 const draft = reconcileRowsDraft(
350 storedDraft,
351 props.environment,
352 providerEnvironmentsEqual,
353 toEnvironmentDraftRows,
354 );
355 if (draft !== storedDraft) setDraft(draft);
356 const rows = draft.rows;
357 const setRows = (nextRows: ReadonlyArray<EnvironmentDraftRow>) =>
358 setDraft({ ...draft, rows: nextRows });
359
360 const publishRows = (nextRows: ReadonlyArray<EnvironmentDraftRow>) => {
361 const published: ProviderInstanceEnvironmentVariable[] = [];
362 for (const row of nextRows) {
363 const name = row.name.trim();
364 if (!ENVIRONMENT_VARIABLE_NAME_PATTERN.test(name)) {
365 if (
366 name.length > 0 ||
367 row.value !== "" ||
368 row.sensitive !== true ||
369 row.valueRedacted !== undefined
370 ) {
371 return;
372 }
373 continue;
374 }
375 const { id: _id, ...rest } = row;
376 published.push({ ...rest, name });
377 }
378 setDraft({ rows: nextRows, seen: draft.seen, lastPublished: published });
379 props.onChange(published);
380 };
381
382 const updateVariable = (id: string, patch: Partial<Omit<EnvironmentDraftRow, "id">>) => {
383 // A row named like a pinned variable renders as the policy's, with no way to edit or remove it.
384 if (patch.name !== undefined && props.managed?.names.has(patch.name)) return;
385 const nextRows = rows.map((row) =>
386 row.id === id
387 ? {
388 ...row,
389 ...patch,
390 ...(patch.value !== undefined ? { valueRedacted: false } : {}),
391 }
392 : row,
393 );
394 setRows(nextRows);
395 publishRows(nextRows);
396 };
397
398 const setVariableSecret = (id: string, secret: SecretReference | undefined) => {
399 const nextRows = rows.map((row) => {
400 if (row.id !== id) return row;
401 const { valueRedacted: _valueRedacted, ...rest } = row;
402 return { ...rest, value: secret ?? "" };
403 });
404 setRows(nextRows);
405 publishRows(nextRows);
406 };
407
408 const removeVariable = (id: string) => {
409 const nextRows = rows.filter((row) => row.id !== id);
410 setRows(nextRows);
411 publishRows(nextRows);
412 };
413
414 const addVariable = () =>
415 setRows([
416 ...rows,
417 {
418 id: nextEnvironmentVariableDraftId(),
419 name: "",
420 value: "",
421 sensitive: true,
422 },
423 ]);
424
425 return (
426 <SettingsRow
427 title="Variables"
428 description="API keys, base URLs, and other per-instance CLI settings."
429 control={
430 <Button type="button" size="sm" variant="outline" onClick={addVariable}>
431 <PlusIcon className="size-3" />
432 Add variable
433 </Button>
434 }
435 >
436 {rows.length > 0 ? (
437 <div className="mt-3 min-w-0 space-y-2 pb-2">
438 {rows.map((variable, index) => {
439 if (props.managed?.names.has(variable.name)) {
440 return (
441 <div key={variable.id} className="flex min-w-0 flex-wrap items-center gap-1.5">
442 <code className="min-w-0 truncate text-xs sm:w-44 sm:shrink-0">
443 {variable.name}
444 </code>
445 <span className="text-xs text-muted-foreground">{props.managed.reason}</span>
446 </div>
447 );
448 }
449 const nameInput = (
450 <DraftInput
451 size="sm"
452 font="mono"
453 className="min-w-0 flex-1"
454 value={variable.name}
455 onCommit={(name) => updateVariable(variable.id, { name: name.trim() })}
456 disabled={variable.valueRedacted === true}
457 placeholder="VARIABLE_NAME"
458 spellCheck={false}
459 aria-label={`Environment variable name ${index + 1}`}
460 />
461 );
462 const removeButton = (
463 <Button
464 type="button"
465 size="icon-micro"
466 variant="ghost-destructive"
467 onClick={() => removeVariable(variable.id)}
468 aria-label={`Remove environment variable ${variable.name || index + 1}`}
469 >
470 <XIcon className="size-3" />
471 </Button>
472 );
473 const sensitiveToggle =
474 typeof variable.value === "string" ? (
475 <Tooltip>
476 <TooltipTrigger
477 render={
478 <Button
479 type="button"
480 size="icon-micro"
481 variant="ghost-muted"
482 disabled={variable.valueRedacted === true}
483 onClick={() => {
484 const sensitive = !variable.sensitive;
485 updateVariable(variable.id, {
486 sensitive,
487 ...(sensitive && variable.valueRedacted === undefined
488 ? {}
489 : { valueRedacted: sensitive ? variable.valueRedacted : false }),
490 });
491 }}
492 aria-pressed={variable.sensitive}
493 aria-label={`Mark environment variable ${variable.name || index + 1} as sensitive`}
494 >
495 <MorphIcon
496 className="size-3"
497 icon={variable.sensitive ? LockGlyph : LockOpen}
498 />
499 </Button>
500 }
501 />
502 <TooltipPopup side="top">
503 {variable.sensitive ? "Sensitive, stored separately" : "Plain text"}
504 </TooltipPopup>
505 </Tooltip>
506 ) : null;
507 const layout = (source: ReactNode, value: ReactNode) => (
508 <div className="flex min-w-0 flex-col gap-1.5 rounded-lg border p-2">
509 <div className="flex min-w-0 items-center gap-1.5">
510 {nameInput}
511 {source}
512 {removeButton}
513 </div>
514 <div className="flex min-w-0 items-start gap-1.5">
515 {value}
516 {sensitiveToggle}
517 </div>
518 </div>
519 );
520 return (
521 <Fragment key={variable.id}>
522 {variable.sensitive ? (
523 <SecretSourceInput
524 size="sm"
525 font="mono"
526 className="min-w-0 flex-1"
527 value={variable.valueRedacted ? "" : variable.value}
528 onCommit={(value) => updateVariable(variable.id, { value })}
529 placeholder="value"
530 configured={variable.valueRedacted === true}
531 spellCheck={false}
532 aria-label={`Environment variable value ${index + 1}`}
533 sources={props.secretSources ?? []}
534 onSecretChange={(secret) => setVariableSecret(variable.id, secret)}
535 >
536 {(parts) => layout(parts.source, parts.value)}
537 </SecretSourceInput>
538 ) : (
539 layout(
540 null,
541 <DraftInput
542 size="sm"
543 font="mono"
544 className="min-w-0 flex-1"
545 value={
546 variable.valueRedacted || typeof variable.value !== "string"
547 ? ""
548 : variable.value
549 }
550 onCommit={(value) => updateVariable(variable.id, { value })}
551 autoComplete="off"
552 placeholder="value"
553 spellCheck={false}
554 aria-label={`Environment variable value ${index + 1}`}
555 />,
556 )
557 )}
558 </Fragment>
559 );
560 })}
561 <p className="text-xs text-muted-foreground">
562 Sensitive values are stored separately and never returned to the app.
563 {rows.some((row) => row.valueRedacted === true)
564 ? " Enter a new value to rename a saved one or make it plain text."
565 : null}
566 </p>
567 </div>
568 ) : null}
569 </SettingsRow>
570 );
571}
572
573function ProjectOverrideInheritance({
574 projectEnabled,
575 deviceEnabled,
576}: {
577 readonly projectEnabled: boolean;
578 readonly deviceEnabled: boolean;
579}) {
580 const layers = [
581 { key: "project", label: "Project", enabled: projectEnabled, effective: true },
582 { key: "device", label: "Device", enabled: deviceEnabled, effective: false },
583 ];
584 return (
585 <Popover>
586 <Tooltip>
587 <TooltipTrigger
588 render={
589 <PopoverTrigger
590 render={
591 <Button
592 size="icon-micro"
593 variant="ghost-muted"
594 aria-label="Overridden for this project. Show where this value comes from"
595 />
596 }
597 />
598 }
599 >
600 <LayersIcon className="size-3 text-primary" />
601 </TooltipTrigger>
602 <TooltipPopup side="top">Overridden for this project</TooltipPopup>
603 </Tooltip>
604 <PopoverPopup align="end" width="md" padding="none">
605 <ol role="list" className="px-3 py-2.5 text-sm">
606 {layers.map((layer) => (
607 <li
608 key={layer.key}
609 className={cn(
610 "grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 rounded-md px-2 py-1",
611 layer.effective && "bg-foreground/[0.06]",
612 )}
613 >
614 <span
615 className={cn(
616 "min-w-0 truncate",
617 layer.effective ? "font-medium text-foreground" : "text-muted-foreground",
618 )}
619 >
620 {layer.label}
621 </span>
622 <span
623 className={cn(
624 "flex items-center gap-1.5",
625 layer.effective ? "text-foreground" : "text-muted-foreground",
626 )}
627 >
628 {layer.enabled ? "On" : "Off"}
629 {layer.effective ? (
630 <CheckIcon aria-hidden className="size-3.5 shrink-0 text-primary" />
631 ) : (
632 <span aria-hidden className="size-3.5 shrink-0" />
633 )}
634 </span>
635 </li>
636 ))}
637 </ol>
638 </PopoverPopup>
639 </Popover>
640 );
641}
642
643interface ProjectOverrideControl {
644 readonly value: boolean | undefined;
645 readonly effectiveEnabled: boolean;
646 readonly onChange: (next: boolean) => void;
647 readonly onReset: () => void;
648}
649
650interface ProviderInstanceCardProps {
651 readonly instanceId: ProviderInstanceId;
652 readonly instance: ProviderInstanceConfig;
653 readonly driverOption: ProviderClientDefinition | undefined;
654 readonly liveProvider: ServerProvider | undefined;
655 readonly mode: "list" | "editor";
656 readonly selected?: boolean | undefined;
657 readonly onSelect?: (() => void) | undefined;
658 readonly readOnly?: boolean | undefined;
659 readonly canWriteSettings?: boolean;
660 readonly onUpdate: (nextInstance: ProviderInstanceConfig) => void;
661 readonly onDelete?: (() => void) | undefined;
662 readonly headerAction?: ReactNode | undefined;
663 readonly setup?: ReactNode;
664 readonly runtime?: ReactNode;
665 readonly hiddenModels: ReadonlyArray<string>;
666 readonly favoriteModels: ReadonlyArray<string>;
667 readonly modelOrder: ReadonlyArray<string>;
668 readonly onHiddenModelsChange: (
669 next: ReadonlyArray<string>,
670 affectedModels: ReadonlyArray<string>,
671 ) => void;
672 readonly onFavoriteModelsChange: (next: ReadonlyArray<string>) => void;
673 readonly onToggleFavorite: (model: string) => void;
674 readonly onModelOrderChange: (next: ReadonlyArray<string>) => void;
675 readonly onRunUpdate?: (() => void) | undefined;
676 readonly onInstallRecommended?: (() => void) | undefined;
677 readonly isUpdating?: boolean | undefined;
678 readonly onAcceptUrlAuth?: ((action: AcpRegistryUrlAuthAction) => void) | undefined;
679 readonly environmentId?: EnvironmentId | undefined;
680 readonly secretSources?: ReadonlyArray<SecretSource>;
681 readonly projectOverride?: ProjectOverrideControl | undefined;
682 readonly acpProjects?:
683 | ReadonlyArray<{
684 readonly id: ProjectId;
685 readonly title: string;
686 readonly workspaceRoot: string;
687 }>
688 | undefined;
689}
690
691const EMPTY_ACP_PROJECTS: NonNullable<ProviderInstanceCardProps["acpProjects"]> = [];
692const NO_SECRET_SOURCES: ReadonlyArray<SecretSource> = [];
693const NO_CUSTOM_MODELS: ReadonlyArray<CustomModelDefinition> = [];
694
695/** Unknown drivers stay read-only to preserve fork config. projectOverride switches affect only the
696 * project, not instance.enabled. */
697export function ProviderInstanceCard({
698 instanceId,
699 instance,
700 driverOption,
701 liveProvider,
702 mode,
703 selected = false,
704 onSelect,
705 readOnly = false,
706 canWriteSettings = true,
707 onUpdate,
708 onDelete,
709 headerAction,
710 setup,
711 runtime,
712 hiddenModels,
713 favoriteModels,
714 modelOrder,
715 onHiddenModelsChange,
716 onFavoriteModelsChange,
717 onToggleFavorite,
718 onModelOrderChange,
719 onRunUpdate,
720 onInstallRecommended,
721 isUpdating = false,
722 onAcceptUrlAuth,
723 environmentId,
724 acpProjects = EMPTY_ACP_PROJECTS,
725 secretSources = NO_SECRET_SOURCES,
726 projectOverride,
727}: ProviderInstanceCardProps) {
728 const enabled = projectOverride?.effectiveEnabled ?? resolveProviderInstanceEnabled(instance);
729 const effectiveProvider = liveProvider && { ...liveProvider, enabled };
730 const compatibility = enabled ? liveProvider?.compatibilityAdvisory : undefined;
731 const statusKey = enabled ? getProviderStatusKey(effectiveProvider) : "disabled";
732 const statusStyle = PROVIDER_STATUS_STYLES[statusKey];
733 const summary = enabled
734 ? getProviderSummary(effectiveProvider)
735 : { headline: "Disabled", detail: null };
736 const authEmail = liveProvider?.auth.email?.trim();
737 const isAuthenticated = enabled && liveProvider?.auth.status === "authenticated";
738 const authLabel =
739 enabled && liveProvider?.auth.status === "authenticated"
740 ? (liveProvider.auth.label ?? liveProvider.auth.type ?? null)
741 : null;
742 const versionLabel = getProviderVersionLabel(liveProvider?.version);
743 const versionAdvisory = getProviderVersionAdvisoryPresentation(
744 liveProvider?.versionAdvisory,
745 liveProvider?.compatibilityAdvisory,
746 enabled,
747 );
748 const updateCommand = versionAdvisory?.updateCommand ?? null;
749 const updateState = liveProvider?.updateState;
750 const updateProgress = isUpdating
751 ? ((updateState?.status === "queued" || updateState?.status === "running"
752 ? updateState.message
753 : null) ?? "Starting update")
754 : null;
755 const updateProblem =
756 !isUpdating && (updateState?.status === "failed" || updateState?.status === "unchanged")
757 ? updateState.message
758 : null;
759 const hasCompatibilityWarning =
760 compatibility !== undefined &&
761 compatibility.status !== "supported" &&
762 compatibility.status !== "unknown";
763 const VersionAdvisoryIcon = hasCompatibilityWarning ? AlertTriangleIcon : ArrowUpCircleIcon;
764 const onRunVersionAction = readOnly
765 ? undefined
766 : versionAdvisory?.targetVersion
767 ? onInstallRecommended
768 : onRunUpdate;
769 const urlAuthAction = liveProvider?.auth.action;
770 const displayName =
771 instance.displayName?.trim() || driverOption?.label || String(instance.driver);
772 const accentColor = normalizeProviderAccentColor(instance.accentColor);
773 const managedPolicy = useManagedPolicy(environmentId);
774 const instanceLocks = managedInstanceLocks(managedPolicy, instance.driver);
775 const managedDriverReason = isManagedDriverAllowed(managedPolicy, instance.driver)
776 ? undefined
777 : disallowedProviderMessage(
778 managedPolicy?.organization,
779 driverOption?.label ?? String(instance.driver),
780 );
781 const { copyToClipboard } = useCopyToClipboard<{ providerName: string }>({
782 onCopy: ({ providerName }) => {
783 toastManager.add({
784 type: "success",
785 title: `${providerName} update command copied`,
786 description: "Run it in a terminal when you are ready to update.",
787 });
788 },
789 onError: (error, { providerName }) => {
790 toastManager.add(
791 stackedThreadToast({
792 type: "error",
793 title: `Could not copy ${providerName} update command`,
794 description: error.message,
795 }),
796 );
797 },
798 });
799
800 const driverKind: ProviderDriverKind | null = isProviderDriverKind(instance.driver)
801 ? instance.driver
802 : null;
803 const storedCustomModels =
804 instance.config !== null && typeof instance.config === "object"
805 ? (instance.config as Record<string, unknown>).customModels
806 : undefined;
807 const customModels =
808 instance.driver === "antigravity"
809 ? NO_CUSTOM_MODELS
810 : readCustomModelEntries(storedCustomModels);
811 const modelsForDisplay = deriveProviderModelsForDisplay({
812 liveModels: liveProvider?.models,
813 customModels,
814 });
815 const updateDisplayName = (value: string) => {
816 const trimmed = value.trim();
817 const { displayName: _omit, ...rest } = instance;
818 onUpdate(
819 trimmed.length > 0
820 ? ({ ...rest, displayName: trimmed } as ProviderInstanceConfig)
821 : (rest as ProviderInstanceConfig),
822 );
823 };
824
825 const updateEnabled = (value: boolean) => {
826 if (projectOverride) {
827 projectOverride.onChange(value);
828 return;
829 }
830 onUpdate({ ...instance, enabled: value });
831 };
832
833 const updateAccentColor = (value: string) => {
834 const normalized = normalizeProviderAccentColor(value);
835 const { accentColor: _omit, ...rest } = instance;
836 onUpdate(
837 normalized
838 ? ({ ...rest, accentColor: normalized } as ProviderInstanceConfig)
839 : (rest as ProviderInstanceConfig),
840 );
841 };
842
843 const updateConfig = (nextConfig: Record<string, unknown> | undefined) => {
844 const { config: _omit, ...rest } = instance;
845 onUpdate(
846 nextConfig !== undefined
847 ? ({ ...rest, config: nextConfig } as ProviderInstanceConfig)
848 : (rest as ProviderInstanceConfig),
849 );
850 };
851
852 const updateCustomModels = useStableCallback((next: ReadonlyArray<CustomModelDefinition>) => {
853 const nextConfig = nextConfigBlobWithValue(
854 instance.config,
855 "customModels",
856 next.map(toCustomModelSetting),
857 );
858 const { config: _omit, ...rest } = instance;
859 onUpdate({ ...rest, config: nextConfig } as ProviderInstanceConfig);
860 });
861
862 const updateEnvironment = (environment: ReadonlyArray<ProviderInstanceEnvironmentVariable>) => {
863 const cleaned = environment.filter((variable) => variable.name.trim().length > 0);
864 const { environment: _omit, ...rest } = instance;
865 onUpdate(
866 cleaned.length > 0
867 ? ({ ...rest, environment: cleaned } as ProviderInstanceConfig)
868 : (rest as ProviderInstanceConfig),
869 );
870 };
871 const environmentFields = driverOption?.environmentFields ?? [];
872 const environmentFieldNames = new Set(environmentFields.map((field) => field.name));
873 const genericEnvironment = providerEnvironmentWithoutNames(
874 instance.environment,
875 environmentFieldNames,
876 );
877 const updateGenericEnvironment = (
878 environment: ReadonlyArray<ProviderInstanceEnvironmentVariable>,
879 ) => {
880 const dedicatedEnvironment = (instance.environment ?? []).filter((variable) =>
881 environmentFieldNames.has(variable.name),
882 );
883 updateEnvironment([...dedicatedEnvironment, ...environment]);
884 };
885 const updateEnvironmentField = (field: ProviderEnvironmentField, value: string) => {
886 updateEnvironment(nextProviderEnvironmentWithFieldValue(instance.environment, field, value));
887 };
888 const updateEnvironmentFieldSecret = (
889 field: ProviderEnvironmentField,
890 secret: SecretReference | undefined,
891 ) => {
892 updateEnvironment(nextProviderEnvironmentWithFieldSecret(instance.environment, field, secret));
893 };
894 const removeEnvironmentField = (field: ProviderEnvironmentField) => {
895 updateEnvironment(providerEnvironmentWithoutNames(instance.environment, new Set([field.name])));
896 };
897
898 const titleIconNode = (
899 <ProviderInstanceIcon
900 driverKind={driverKind ?? instance.driver}
901 displayName={displayName}
902 accentColor={accentColor}
903 acpRegistryAgentId={
904 readConfigString(instance.config, "source") === "local"
905 ? undefined
906 : (readConfigString(instance.config, "agentId") ?? undefined)
907 }
908 acpRegistryIconUrl={
909 readConfigString(instance.config, "source") === "local"
910 ? undefined
911 : (readConfigString(instance.config, "registryIconUrl") ?? undefined)
912 }
913 showBadge={Boolean(accentColor)}
914 className="size-5"
915 iconClassName="size-4 text-foreground/80"
916 badgeClassName="right-[-0.125rem] bottom-[-0.125rem] h-3 min-w-3 px-0.5 text-5xs"
917 />
918 );
919
920 const titleTailNode = headerAction ? (
921 <span className="inline-flex h-5 w-5 shrink-0 items-center justify-center">{headerAction}</span>
922 ) : null;
923
924 const versionCodeNode = versionLabel ? (
925 <code className="text-xs text-muted-foreground">{versionLabel}</code>
926 ) : null;
927
928 const statusDotNode =
929 statusKey === "warning" || statusKey === "error" ? (
930 <span className={cn("size-1.5 shrink-0 rounded-full", statusStyle.dot)} aria-hidden />
931 ) : null;
932 const needsAttention = statusKey === "warning" || statusKey === "error";
933 const statusDiagnostic = hasCompatibilityWarning && needsAttention ? summary.detail : null;
934 const inlineStatusDetail = hasCompatibilityWarning
935 ? compatibility?.status === "broken"
936 ? "Incompatible"
937 : compatibility?.status === "unsupported"
938 ? "Unsupported"
939 : "Limited support"
940 : summary.detail;
941 const editorStatusNode =
942 isAuthenticated && authEmail ? (
943 <>
944 {needsAttention ? statusDotNode : null}
945 <span>Authenticated as</span>
946 <ProviderAuthEmail email={authEmail} />
947 {authLabel ? <span>· {authLabel}</span> : null}
948 {inlineStatusDetail ? (
949 <span className="min-w-0 [overflow-wrap:anywhere]">· {inlineStatusDetail}</span>
950 ) : null}
951 </>
952 ) : (
953 <>
954 {statusDotNode}
955 <span>{summary.headline}</span>
956 {inlineStatusDetail ? (
957 <span className="min-w-0 [overflow-wrap:anywhere]">· {inlineStatusDetail}</span>
958 ) : null}
959 </>
960 );
961 const versionAdvisoryNode = versionAdvisory ? (
962 <Popover>
963 <Tooltip>
964 <TooltipTrigger
965 render={
966 <PopoverTrigger
967 render={
968 <Button
969 type="button"
970 size={mode === "list" ? "icon-micro" : "icon-xs"}
971 variant="ghost-muted"
972 className={mode === "list" ? "pointer-events-auto relative shrink-0" : undefined}
973 aria-label={`${updateProgress ? "Updating" : versionAdvisory.title}, view details`}
974 >
975 {updateProgress ? (
976 <Spinner tone="muted" {...(mode === "list" ? { size: "sm" as const } : {})} />
977 ) : (
978 <VersionAdvisoryIcon
979 className={cn(
980 mode === "list" && "size-3.5",
981 hasCompatibilityWarning && "text-warning",
982 )}
983 />
984 )}
985 </Button>
986 }
987 />
988 }
989 />
990 <TooltipPopup side="top">
991 {updateProgress ? "Updating" : versionAdvisory.title}
992 </TooltipPopup>
993 </Tooltip>
994 <PopoverPopup side="bottom" align="end" width="md" aria-label={versionAdvisory.title}>
995 <div className="grid min-w-0 gap-3">
996 <div className="grid gap-0.5">
997 <p className="text-sm font-semibold leading-tight text-foreground">
998 {versionAdvisory.title}
999 </p>
1000 <p
1001 className={cn(
1002 "text-xs leading-snug [overflow-wrap:anywhere]",
1003 versionAdvisory.emphasis === "strong" ? "text-warning" : "text-muted-foreground",
1004 )}
1005 >
1006 {versionAdvisory.detail}
1007 </p>
1008 </div>
1009 {onRunVersionAction ? (
1010 <Button
1011 type="button"
1012 size="xs"
1013 variant="outline"
1014 className="w-full"
1015 disabled={isUpdating}
1016 onClick={onRunVersionAction}
1017 >
1018 {isUpdating ? <Spinner /> : <DownloadIcon />}
1019 {isUpdating
1020 ? "Updating"
1021 : versionAdvisory.targetVersion
1022 ? `Install ${getProviderVersionLabel(versionAdvisory.targetVersion)}`
1023 : "Update now"}
1024 </Button>
1025 ) : null}
1026 {updateProgress || updateProblem ? (
1027 <p
1028 aria-live="polite"
1029 className={cn(
1030 "text-xs leading-snug [overflow-wrap:anywhere]",
1031 updateProblem ? "text-warning" : "text-muted-foreground",
1032 )}
1033 >
1034 {updateProgress ?? updateProblem}
1035 </p>
1036 ) : null}
1037 {onRunVersionAction && updateCommand ? (
1038 <div className="flex items-center gap-2 text-3xs font-medium uppercase tracking-wider text-muted-foreground">
1039 <span aria-hidden className="h-px flex-1 bg-border" />
1040 or, update manually using
1041 <span aria-hidden className="h-px flex-1 bg-border" />
1042 </div>
1043 ) : null}
1044 {updateCommand ? (
1045 <div className="flex min-w-0 items-center gap-1 rounded-md border border-border/70 bg-muted/40 py-0.5 pr-0.5 pl-2">
1046 <code className="min-w-0 flex-1 truncate font-mono text-2xs text-foreground">
1047 {updateCommand}
1048 </code>
1049 <Tooltip>
1050 <TooltipTrigger
1051 render={
1052 <Button
1053 type="button"
1054 size="icon-xs"
1055 variant="ghost-muted"
1056 className="shrink-0"
1057 onClick={() => copyToClipboard(updateCommand, { providerName: displayName })}
1058 aria-label="Copy update command"
1059 >
1060 <CopyIcon className="size-3" />
1061 </Button>
1062 }
1063 />
1064 <TooltipPopup side="top">Copy command</TooltipPopup>
1065 </Tooltip>
1066 </div>
1067 ) : null}
1068 </div>
1069 </PopoverPopup>
1070 </Popover>
1071 ) : null;
1072
1073 if (mode === "list") {
1074 return (
1075 <div
1076 data-slot="settings-row"
1077 className={cn(
1078 "group flex min-h-18 items-center gap-3 px-3 py-3 transition-colors sm:px-4",
1079 selected ? "bg-foreground/[0.06]" : "hover:bg-muted/25",
1080 )}
1081 >
1082 <div
1083 className={cn(
1084 "pointer-events-none relative flex min-w-0 flex-1 items-start gap-3 rounded-md text-left transition-opacity",
1085 !enabled && !selected && "opacity-60 group-hover:opacity-100",
1086 )}
1087 >
1088 <button
1089 type="button"
1090 className="pointer-events-auto absolute inset-0 cursor-pointer rounded-md outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
1091 onClick={onSelect}
1092 aria-label={`Select ${displayName}`}
1093 aria-pressed={selected}
1094 />
1095 {titleIconNode}
1096 <span className="min-w-0 flex-1">
1097 <span className="flex min-w-0 items-center gap-2">
1098 <span className="truncate text-sm font-medium text-foreground">{displayName}</span>
1099 {versionLabel ? (
1100 <code className="max-w-24 shrink-0 truncate text-xs text-muted-foreground">
1101 {versionLabel}
1102 </code>
1103 ) : null}
1104 {versionAdvisoryNode}
1105 </span>
1106 <span className="mt-0.5 flex items-start gap-1.5 text-xs leading-normal text-muted-foreground/80">
1107 {statusDotNode && !updateProgress ? (
1108 <span className="flex h-[1.45em] shrink-0 items-center">{statusDotNode}</span>
1109 ) : null}
1110 <ProviderStatusDiagnostic detail={statusDiagnostic}>
1111 <span
1112 tabIndex={statusDiagnostic ? 0 : undefined}
1113 aria-live="polite"
1114 className="pointer-events-auto line-clamp-2 [overflow-wrap:anywhere]"
1115 >
1116 {updateProgress ? (
1117 `Updating · ${updateProgress}`
1118 ) : (
1119 <>
1120 {summary.headline}
1121 {needsAttention && inlineStatusDetail ? ` · ${inlineStatusDetail}` : null}
1122 </>
1123 )}
1124 </span>
1125 </ProviderStatusDiagnostic>
1126 </span>
1127 </span>
1128 </div>
1129 <span className="flex h-5 shrink-0 items-center gap-1">
1130 {projectOverride?.value !== undefined ? (
1131 <span className="flex items-center">
1132 <ProjectOverrideInheritance
1133 projectEnabled={projectOverride.value}
1134 deviceEnabled={resolveProviderInstanceEnabled(instance)}
1135 />
1136 <SettingResetButton
1137 label={`${displayName} enablement`}
1138 tooltip="Reset to the device setting"
1139 disabled={readOnly || !canWriteSettings}
1140 onClick={projectOverride.onReset}
1141 />
1142 </span>
1143 ) : null}
1144 {/* The policy refuses switching it on; switching it off stays the user's call. */}
1145 <ManagedControl reason={enabled ? undefined : managedDriverReason}>
1146 <Switch
1147 checked={enabled}
1148 disabled={readOnly || (projectOverride !== undefined && !canWriteSettings)}
1149 onCheckedChange={(checked) => updateEnabled(Boolean(checked))}
1150 aria-label={`Enable ${displayName}`}
1151 />
1152 </ManagedControl>
1153 </span>
1154 </div>
1155 );
1156 }
1157
1158 const editorHeaderAction = (
1159 <div className="flex shrink-0 items-center gap-1.5">
1160 {driverOption?.badgeLabel ? (
1161 <Badge variant="warning" size="sm" className="shrink-0">
1162 {driverOption.badgeLabel}
1163 </Badge>
1164 ) : null}
1165 {versionCodeNode}
1166 {versionAdvisoryNode}
1167 <span
1168 inert={readOnly}
1169 aria-disabled={readOnly || undefined}
1170 // Empty, it would still add a flex gap and pull the version off the column edge.
1171 className={cn("inline-flex items-center gap-1 empty:hidden", readOnly && "opacity-50")}
1172 >
1173 {titleTailNode}
1174 {onDelete ? (
1175 <Button
1176 type="button"
1177 size="icon-xs"
1178 variant="ghost-destructive"
1179 disabled={readOnly}
1180 onClick={onDelete}
1181 aria-label={`Delete instance ${instanceId}`}
1182 >
1183 <Trash2Icon />
1184 </Button>
1185 ) : null}
1186 </span>
1187 </div>
1188 );
1189
1190 // Provider status gets its own row instead of hanging under the name field.
1191 const statusContent = (
1192 <>
1193 <ProviderStatusDiagnostic detail={statusDiagnostic}>
1194 <div
1195 tabIndex={statusDiagnostic ? 0 : undefined}
1196 className="flex min-w-0 flex-wrap items-baseline gap-x-1.5"
1197 >
1198 {editorStatusNode}
1199 </div>
1200 </ProviderStatusDiagnostic>
1201 {urlAuthAction && onAcceptUrlAuth ? (
1202 <div className="grid max-w-xl gap-1.5 pt-1 text-xs">
1203 <p>{urlAuthAction.message}</p>
1204 <code className="break-all text-2xs">{urlAuthAction.url}</code>
1205 <Button
1206 render={
1207 <a
1208 href={urlAuthAction.url}
1209 target="_blank"
1210 rel="noopener noreferrer"
1211 onClick={() => onAcceptUrlAuth(urlAuthAction)}
1212 />
1213 }
1214 size="xs"
1215 variant="outline"
1216 className="w-fit"
1217 disabled={readOnly}
1218 >
1219 <ExternalLinkIcon />
1220 Continue authentication
1221 </Button>
1222 </div>
1223 ) : null}
1224 </>
1225 );
1226
1227 const runtimeFields = driverOption ? (
1228 <ProviderSettingsForm
1229 definition={driverOption}
1230 value={instance.config}
1231 idPrefix={`provider-instance-${instanceId}`}
1232 variant="settings"
1233 onChange={updateConfig}
1234 managed={instanceLocks && { keys: instanceLocks.configKeys, reason: instanceLocks.reason }}
1235 environmentId={environmentId}
1236 />
1237 ) : (
1238 <SettingsRow
1239 title="Driver"
1240 description={
1241 <span>
1242 This instance uses <code className="text-foreground">{String(instance.driver)}</code>,
1243 which is not available in this build. Its configuration is preserved.
1244 </span>
1245 }
1246 />
1247 );
1248
1249 return (
1250 <>
1251 <SettingsSection title={displayName} icon={titleIconNode} headerAction={editorHeaderAction}>
1252 <SettingsRow title="Status" status={statusContent} />
1253 <SettingsRow
1254 title="Display name"
1255 control={
1256 <div
1257 inert={readOnly}
1258 aria-disabled={readOnly || undefined}
1259 className={cn(
1260 "flex w-full min-w-0 items-center justify-end gap-2 @min-[32rem]/settings-row:w-auto",
1261 readOnly && "opacity-50 select-none",
1262 )}
1263 >
1264 <ProviderAccentColorPicker
1265 layout="inline"
1266 displayName={displayName}
1267 value={accentColor}
1268 onCommit={updateAccentColor}
1269 />
1270 <DraftInput
1271 id={`provider-instance-${instanceId}-display-name`}
1272 size="sm"
1273 className="min-w-0 flex-1 @min-[32rem]/settings-row:w-56"
1274 value={instance.displayName ?? ""}
1275 onCommit={updateDisplayName}
1276 placeholder={driverOption?.label ?? "Instance label"}
1277 spellCheck={false}
1278 />
1279 </div>
1280 }
1281 />
1282 </SettingsSection>
1283
1284 {setup || environmentFields.length > 0 ? (
1285 <SettingsSection title="Setup">
1286 {setup}
1287 {environmentFields.length > 0 ? (
1288 <div
1289 inert={readOnly}
1290 aria-disabled={readOnly || undefined}
1291 className={readOnly ? "opacity-50 select-none" : undefined}
1292 >
1293 {environmentFields.map((field) => (
1294 <ProviderEnvironmentFieldRow
1295 key={field.name}
1296 field={field}
1297 variable={readProviderEnvironmentVariable(instance.environment, field.name)}
1298 idPrefix={`provider-instance-${instanceId}`}
1299 onCommit={updateEnvironmentField}
1300 onSecretChange={updateEnvironmentFieldSecret}
1301 onRemove={removeEnvironmentField}
1302 managedReason={
1303 instanceLocks?.wholeEnvironment ||
1304 instanceLocks?.environmentNames.has(field.name)
1305 ? instanceLocks.reason
1306 : undefined
1307 }
1308 secretSources={secretSources}
1309 />
1310 ))}
1311 </div>
1312 ) : null}
1313 </SettingsSection>
1314 ) : null}
1315
1316 {instance.driver === "codex" && readCodexSetupMode(instance.config) === "managed" ? (
1317 <div
1318 inert={readOnly}
1319 aria-disabled={readOnly || undefined}
1320 className={readOnly ? "opacity-50 select-none" : undefined}
1321 >
1322 <FoldedSettingsSection
1323 key={instanceId}
1324 id={`provider-instance-${instanceId}-runtime`}
1325 title="Runtime"
1326 headerPlacement="outside"
1327 >
1328 {runtime ?? runtimeFields}
1329 </FoldedSettingsSection>
1330 </div>
1331 ) : !driverOption || deriveProviderSettingsFields(driverOption).length > 0 ? (
1332 <SettingsSection
1333 title="Runtime"
1334 inert={readOnly}
1335 aria-disabled={readOnly || undefined}
1336 className={readOnly ? "opacity-50 select-none" : undefined}
1337 >
1338 {runtimeFields}
1339 </SettingsSection>
1340 ) : null}
1341
1342 <SettingsSection
1343 title="Environment"
1344 inert={readOnly || instanceLocks?.wholeEnvironment}
1345 aria-disabled={readOnly || instanceLocks?.wholeEnvironment || undefined}
1346 className={readOnly ? "opacity-50 select-none" : undefined}
1347 >
1348 {instanceLocks?.wholeEnvironment ? (
1349 <ManagedNotice>{instanceLocks.reason}</ManagedNotice>
1350 ) : null}
1351 <div className={instanceLocks?.wholeEnvironment ? "opacity-50" : undefined}>
1352 <ProviderEnvironmentSection
1353 environment={genericEnvironment}
1354 onChange={updateGenericEnvironment}
1355 secretSources={secretSources}
1356 managed={
1357 instanceLocks && {
1358 names: instanceLocks.environmentNames,
1359 reason: instanceLocks.reason,
1360 }
1361 }
1362 />
1363 </div>
1364 </SettingsSection>
1365 {environmentId !== undefined && liveProvider?.driver === "acpRegistry" ? (
1366 <AcpSessionManagementSection
1367 environmentId={environmentId}
1368 instanceId={instanceId}
1369 provider={liveProvider}
1370 projects={acpProjects}
1371 readOnly={readOnly}
1372 />
1373 ) : null}
1374
1375 {driverOption !== undefined ? (
1376 <SettingsSection title="Models">
1377 <div className="px-3 py-3 sm:px-4">
1378 <p className="mb-3 text-xs text-muted-foreground">
1379 Model preferences and custom models are saved on the selected environment and shared
1380 across connected devices.
1381 </p>
1382 <ProviderModelsSection
1383 canManageCustomModels={!readOnly}
1384 canWritePreferences={canWriteSettings}
1385 instanceId={instanceId}
1386 driverKind={driverKind}
1387 models={modelsForDisplay}
1388 customModels={customModels}
1389 hiddenModels={hiddenModels}
1390 favoriteModels={favoriteModels}
1391 modelOrder={modelOrder}
1392 onChange={updateCustomModels}
1393 onHiddenModelsChange={onHiddenModelsChange}
1394 onFavoriteModelsChange={onFavoriteModelsChange}
1395 onToggleFavorite={onToggleFavorite}
1396 onModelOrderChange={onModelOrderChange}
1397 />
1398 </div>
1399 </SettingsSection>
1400 ) : null}
1401 </>
1402 );
1403}