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

ProviderInstanceCard.tsx

1,425 lines50.4 KB

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