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

ProviderInstanceCard.tsx

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