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

ProviderInstanceCard.tsx

725 lines27.0 KB

1"use client";
2​
3import { ChevronDownIcon, PlusIcon, Trash2Icon, XIcon } from "lucide-react";
4import { useEffect, useState, type ReactNode } from "react";
5import {
6 isProviderDriverKind,
7 type ProviderInstanceConfig,
8 type ProviderInstanceEnvironmentVariable,
9 type ProviderInstanceId,
10 type ProviderDriverKind,
11 type ServerProvider,
12 type ServerProviderModel,
13} from "@t3tools/contracts";
14​
15import { cn } from "../../lib/utils";
16import { normalizeProviderAccentColor } from "../../providerInstances";
17import { Badge } from "../ui/badge";
18import { Button } from "../ui/button";
19import { Collapsible, CollapsibleContent } from "../ui/collapsible";
20import { DraftInput } from "../ui/draft-input";
21import { Switch } from "../ui/switch";
22import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
23import type { DriverOption } from "./providerDriverMeta";
24import { ProviderSettingsForm } from "./ProviderSettingsForm";
25import { ProviderModelsSection } from "./ProviderModelsSection";
26import { ProviderInstanceIcon } from "../chat/ProviderInstanceIcon";
27import { RedactedSensitiveText } from "./RedactedSensitiveText";
28import {
29 PROVIDER_STATUS_STYLES,
30 getProviderSummary,
31 getProviderVersionLabel,
32 type ProviderStatusKey,
33} from "./providerStatus";
34​
35const PROVIDER_ACCENT_SWATCHES = [
36 "#2563eb",
37 "#16a34a",
38 "#ea580c",
39 "#dc2626",
40 "#7c3aed",
41 "#0891b2",
42] as const;
43​
44const ENVIRONMENT_VARIABLE_NAME_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
45​
46let environmentVariableDraftId = 0;
47const nextEnvironmentVariableDraftId = () => `provider-env-${environmentVariableDraftId++}`;
48​
49type EnvironmentDraftRow = {
50 readonly id: string;
51 readonly name: string;
52 readonly value: string;
53 readonly sensitive: boolean;
54 readonly valueRedacted?: boolean;
55};
56​
57function makeEnvironmentDraftRow(
58 variable: ProviderInstanceEnvironmentVariable,
59 index: number,
60): EnvironmentDraftRow {
61 return {
62 id: `${index}:${variable.name}`,
63 name: variable.name,
64 value: variable.value,
65 sensitive: variable.sensitive,
66 ...(variable.valueRedacted !== undefined ? { valueRedacted: variable.valueRedacted } : {}),
67 };
69​
70/**
71 * Read a string[] at `key` from the opaque config blob, filtering out
72 * non-string entries. Used for `customModels`, which is always typed as
73 * `string[]` by the concrete driver schemas but arrives here as
74 * `Schema.Unknown`.
75 */
76function readConfigStringArray(config: unknown, key: string): ReadonlyArray<string> {
77 if (config === null || typeof config !== "object") return [];
78 const value = (config as Record<string, unknown>)[key];
79 if (!Array.isArray(value)) return [];
80 return value.filter((entry): entry is string => typeof entry === "string");
82​
83/**
84 * Set `key` to an arbitrary value on the opaque config blob. Unlike
85 * provider settings field updates, does not drop empty-looking values — the
86 * caller is responsible for deciding whether an empty array / empty
87 * object should be stored explicitly (e.g. `customModels: []` is a
88 * meaningful "user cleared their custom list" state distinct from
89 * "driver default").
90 */
91function nextConfigBlobWithValue(
92 config: unknown,
93 key: string,
94 value: unknown,
95): Record<string, unknown> {
96 const base: Record<string, unknown> =
97 config !== null && typeof config === "object" ? { ...(config as Record<string, unknown>) } : {};
98 base[key] = value;
99 return base;
101​
102export function deriveProviderModelsForDisplay(input: {
103 readonly liveModels: ReadonlyArray<ServerProviderModel> | undefined;
104 readonly customModels: ReadonlyArray<string>;
105}): ReadonlyArray<ServerProviderModel> {
106 const liveCustomModelsBySlug = new Map(
107 (input.liveModels ?? [])
108 .filter((model) => model.isCustom)
109 .map((model) => [model.slug, model] as const),
110 );
111 const serverModels = input.liveModels?.filter((model) => !model.isCustom) ?? [];
112 const customModels = input.customModels.map(
113 (slug) =>
114 liveCustomModelsBySlug.get(slug) ?? {
115 slug,
116 name: slug,
117 isCustom: true,
118 capabilities: null,
119 },
120 );
121 return [...serverModels, ...customModels];
123​
124function ProviderAuthEmail(props: {
125 readonly email: string | undefined;
126 readonly prefix?: string;
127 readonly separator?: boolean;
128}) {
129 const trimmed = props.email?.trim();
130 if (!trimmed) return null;
131​
132 return (
133 <span className="inline-flex min-w-0 items-center gap-1.5">
134 {props.separator ? <span aria-hidden>·</span> : null}
135 {props.prefix ? <span className="text-muted-foreground/80">{props.prefix}</span> : null}
136 <RedactedSensitiveText
137 value={trimmed}
138 ariaLabel="Toggle account email visibility"
139 revealTooltip="Click to reveal email"
140 hideTooltip="Click to hide email"
141 />
142 </span>
143 );
145​
146function ProviderAccentColorPicker(props: {
147 readonly displayName: string;
148 readonly value: string | undefined;
149 readonly onCommit: (value: string) => void;
150}) {
151 const [draft, setDraft] = useState(props.value ?? "");
152 const [isEditing, setIsEditing] = useState(false);
153 const draftColor = normalizeProviderAccentColor(draft);
154​
155 useEffect(() => {
156 if (isEditing) return;
157 setDraft(props.value ?? "");
158 }, [isEditing, props.value]);
159​
160 const commitDraft = () => {
161 setIsEditing(false);
162 props.onCommit(draftColor ?? "");
163 };
164​
165 const commitSwatch = (swatch: string) => {
166 setIsEditing(false);
167 setDraft(swatch);
168 props.onCommit(swatch);
169 };
170​
171 return (
172 <div className="grid gap-2">
173 <span className="text-xs font-medium text-foreground">Accent color</span>
174 <div className="flex min-w-0 flex-wrap items-center gap-2">
175 <input
176 type="color"
177 value={draftColor ?? PROVIDER_ACCENT_SWATCHES[0]}
178 onFocus={() => setIsEditing(true)}
179 onInput={(event) => {
180 setIsEditing(true);
181 setDraft(event.currentTarget.value);
182 }}
183 onChange={(event) => {
184 setIsEditing(true);
185 setDraft(event.currentTarget.value);
186 }}
187 onBlur={commitDraft}
188 aria-label={`Accent color for ${props.displayName}`}
189 className="h-8 w-10 cursor-pointer rounded border border-input bg-background p-0.5"
190 />
191 <div className="flex flex-wrap gap-1.5">
192 {PROVIDER_ACCENT_SWATCHES.map((swatch) => {
193 const selected = draftColor?.toLowerCase() === swatch;
194 return (
195 <button
196 key={swatch}
197 type="button"
198 className={cn(
199 "size-6 cursor-pointer rounded-full border transition",
200 selected
201 ? "border-foreground ring-2 ring-ring ring-offset-1 ring-offset-background"
202 : "border-black/10 hover:scale-105 dark:border-white/20",
203 )}
204 style={{ backgroundColor: swatch }}
205 onClick={() => commitSwatch(swatch)}
206 aria-label={`Use ${swatch} accent`}
207 />
208 );
209 })}
210 </div>
211 {draftColor ? (
212 <Button
213 type="button"
214 size="sm"
215 variant="ghost"
216 className="h-7 px-2 text-xs text-muted-foreground"
217 onClick={() => {
218 setIsEditing(false);
219 setDraft("");
220 props.onCommit("");
221 }}
222 >
223 Clear
224 </Button>
225 ) : null}
226 </div>
227 <span className="text-xs text-muted-foreground">
228 Used to distinguish this instance in picker rails and model lists.
229 </span>
230 </div>
231 );
233​
234function ProviderEnvironmentSection(props: {
235 readonly environment: ReadonlyArray<ProviderInstanceEnvironmentVariable>;
236 readonly onChange: (environment: ReadonlyArray<ProviderInstanceEnvironmentVariable>) => void;
237}) {
238 const [rows, setRows] = useState<ReadonlyArray<EnvironmentDraftRow>>(() =>
239 props.environment.map(makeEnvironmentDraftRow),
240 );
241​
242 useEffect(() => {
243 setRows(props.environment.map(makeEnvironmentDraftRow));
244 }, [props.environment]);
245​
246 const publishRows = (nextRows: ReadonlyArray<EnvironmentDraftRow>) => {
247 const published: ProviderInstanceEnvironmentVariable[] = [];
248 for (const row of nextRows) {
249 const name = row.name.trim();
250 if (!ENVIRONMENT_VARIABLE_NAME_PATTERN.test(name)) {
251 if (
252 name.length > 0 ||
253 row.value.length > 0 ||
254 row.sensitive !== true ||
255 row.valueRedacted !== undefined
256 ) {
257 return;
258 }
259 continue;
260 }
261 const { id: _id, ...rest } = row;
262 published.push({ ...rest, name });
263 }
264 props.onChange(published);
265 };
266​
267 const updateVariable = (id: string, patch: Partial<Omit<EnvironmentDraftRow, "id">>) => {
268 const nextRows = rows.map((row) =>
269 row.id === id
270 ? {
271 ...row,
272 ...patch,
273 ...(patch.value !== undefined ? { valueRedacted: false } : {}),
274 }
275 : row,
276 );
277 setRows(nextRows);
278 publishRows(nextRows);
279 };
280​
281 const removeVariable = (id: string) => {
282 const nextRows = rows.filter((row) => row.id !== id);
283 setRows(nextRows);
284 publishRows(nextRows);
285 };
286​
287 return (
288 <div className="grid gap-2">
289 <div className="flex items-center justify-between gap-3">
290 <span className="text-xs font-medium text-foreground">Environment variables</span>
291 <Button
292 type="button"
293 size="sm"
294 variant="outline"
295 className="h-7 gap-1.5 px-2 text-xs"
296 onClick={() =>
297 setRows([
298 ...rows,
299 {
300 id: nextEnvironmentVariableDraftId(),
301 name: "",
302 value: "",
303 sensitive: true,
304 },
305 ])
306 }
307 >
308 <PlusIcon className="size-3" />
309 Add
310 </Button>
311 </div>
312 {rows.length === 0 ? (
313 <p className="text-xs text-muted-foreground">
314 Add variables to pass API keys, base URLs, or other per-instance CLI settings.
315 </p>
316 ) : (
317 <div className="grid gap-2">
318 {rows.map((variable, index) => (
319 <div
320 key={variable.id}
321 className="grid gap-2 rounded-md border border-border/70 bg-muted/20 p-2 sm:grid-cols-[minmax(0,1fr)_minmax(0,1.4fr)_auto_auto] sm:items-center"
322 >
323 <DraftInput
324 value={variable.name}
325 onCommit={(name) => updateVariable(variable.id, { name: name.trim() })}
326 placeholder="VARIABLE_NAME"
327 spellCheck={false}
328 aria-label={`Environment variable name ${index + 1}`}
329 />
330 <DraftInput
331 value={variable.valueRedacted ? "" : variable.value}
332 onCommit={(value) => updateVariable(variable.id, { value })}
333 type={variable.sensitive ? "password" : undefined}
334 autoComplete="off"
335 placeholder={
336 variable.valueRedacted ? "Stored secret - enter a new value to replace" : "Value"
337 }
338 spellCheck={false}
339 aria-label={`Environment variable value ${index + 1}`}
340 />
341 <label className="inline-flex h-8 items-center gap-2 text-xs text-muted-foreground">
342 <input
343 type="checkbox"
344 className="size-3.5"
345 checked={variable.sensitive}
346 onChange={(event) => {
347 const sensitive = event.currentTarget.checked;
348 updateVariable(variable.id, {
349 sensitive,
350 ...(sensitive && variable.valueRedacted === undefined
351 ? {}
352 : { valueRedacted: sensitive ? variable.valueRedacted : false }),
353 });
354 }}
355 />
356 Sensitive
357 </label>
358 <Button
359 type="button"
360 size="icon-sm"
361 variant="ghost"
362 className="size-8 justify-self-start text-muted-foreground hover:text-destructive sm:justify-self-end"
363 onClick={() => removeVariable(variable.id)}
364 aria-label={`Remove environment variable ${variable.name || index + 1}`}
365 >
366 <XIcon className="size-3.5" />
367 </Button>
368 </div>
369 ))}
370 </div>
371 )}
372 <span className="text-xs text-muted-foreground">
373 Sensitive values are stored separately and are not returned to the app after saving.
374 </span>
375 </div>
376 );
378​
379interface ProviderInstanceCardProps {
380 readonly instanceId: ProviderInstanceId;
381 readonly instance: ProviderInstanceConfig;
382 readonly driverOption: DriverOption | undefined;
383 readonly liveProvider: ServerProvider | undefined;
384 readonly isExpanded: boolean;
385 readonly onExpandedChange: (open: boolean) => void;
386 readonly onUpdate: (nextInstance: ProviderInstanceConfig) => void;
387 /**
388 * Pass `undefined` to hide the delete button entirely. Built-in default
389 * instance slots use `undefined` — they can't be deleted without losing
390 * the slot, and their "reset to defaults" affordance lives on an outer
391 * reset button instead. Explicit `| undefined` in the type accommodates
392 * `exactOptionalPropertyTypes: true`, where an absent key and
393 * `{ onDelete: undefined }` are treated as distinct shapes.
394 */
395 readonly onDelete?: (() => void) | undefined;
396 /**
397 * Optional outer reset button rendered next to the driver icon. Built-in
398 * default slots supply a reset-to-factory control here; custom instances
399 * omit it.
400 */
401 readonly headerAction?: ReactNode | undefined;
402 readonly hiddenModels: ReadonlyArray<string>;
403 readonly favoriteModels: ReadonlyArray<string>;
404 readonly modelOrder: ReadonlyArray<string>;
405 readonly onHiddenModelsChange: (next: ReadonlyArray<string>) => void;
406 readonly onFavoriteModelsChange: (next: ReadonlyArray<string>) => void;
407 readonly onModelOrderChange: (next: ReadonlyArray<string>) => void;
409​
410/**
411 * A single configured provider-instance row in the Providers settings
412 * section. Used for every row — both the built-in default instance for a
413 * driver (rendered with `onDelete` omitted) and user-authored custom
414 * instances (`onDelete` supplied). The only UI difference between the two
415 * is whether the trash button is visible; every other field (display
416 * name, config fields, models) behaves identically.
417 *
418 * Behavior notes:
419 * - `liveProvider` is matched by the caller via `instanceId`; when no
420 * match is available (e.g. the server hasn't probed yet, or the
421 * driver is not shipped by the current build) the card still renders
422 * with a neutral "checking" summary.
423 * - Unknown drivers (`driverOption === undefined`) get a read-only
424 * notice instead of editable fields, so fork instances round-trip
425 * without accidentally destroying their config.
426 * - The enabled Switch writes to the envelope's `instance.enabled`
427 * field; the server's registry consults this at `entry.enabled ?? true`
428 * before materializing the instance, and the probe also checks its
429 * driver-specific `config.enabled`. We treat the envelope flag as the
430 * single source of truth from the UI — built-in cards used to write
431 * the inner flag, but on the promotion-to-instance path every edit
432 * flows through the envelope.
433 */
434export function ProviderInstanceCard({
435 instanceId,
436 instance,
437 driverOption,
438 liveProvider,
439 isExpanded,
440 onExpandedChange,
441 onUpdate,
442 onDelete,
443 headerAction,
444 hiddenModels,
445 favoriteModels,
446 modelOrder,
447 onHiddenModelsChange,
448 onFavoriteModelsChange,
449 onModelOrderChange,
450}: ProviderInstanceCardProps) {
451 const enabled = instance.enabled ?? true;
452 // The server-reported status wins when present; otherwise fall back to
453 // "disabled"/"warning" based on the local `enabled` flag so the dot
454 // reflects the persisted intent even before the first probe completes.
455 const statusKey: ProviderStatusKey =
456 (liveProvider?.status as ProviderStatusKey | undefined) ?? (enabled ? "warning" : "disabled");
457 const statusStyle = PROVIDER_STATUS_STYLES[statusKey];
458 const rawSummary = getProviderSummary(liveProvider);
459 const authEmail = liveProvider?.auth.email;
460 const hasAuthenticatedEmail =
461 liveProvider?.auth.status === "authenticated" && Boolean(authEmail?.trim());
462 const authenticatedDetail = hasAuthenticatedEmail
463 ? (liveProvider?.auth.label ?? liveProvider?.auth.type ?? null)
464 : null;
465 const summary = rawSummary;
466 const versionLabel = getProviderVersionLabel(liveProvider?.version);
467 const FallbackIconComponent = driverOption?.icon;
468 const displayName =
469 instance.displayName?.trim() || driverOption?.label || String(instance.driver);
470 const accentColor = normalizeProviderAccentColor(instance.accentColor);
471​
472 // Narrow `instance.driver` for callers that key on the closed
473 // `ProviderDriverKind` union (e.g. `normalizeModelSlug`'s alias table). Custom
474 // fork drivers pass through as `null` and those callers fall back to
475 // verbatim behaviour.
476 const driverKind: ProviderDriverKind | null = isProviderDriverKind(instance.driver)
477 ? instance.driver
478 : null;
479​
480 const customModels = readConfigStringArray(instance.config, "customModels");
481 // Server-returned models may lag behind settings writes. Treat probe
482 // models as the source for built-ins only; custom rows come directly
483 // from the current instance config so add/remove reflects immediately.
484 const modelsForDisplay = deriveProviderModelsForDisplay({
485 liveModels: liveProvider?.models,
486 customModels,
487 });
488​
489 const updateDisplayName = (value: string) => {
490 const trimmed = value.trim();
491 const { displayName: _omit, ...rest } = instance;
492 onUpdate(
493 trimmed.length > 0
494 ? ({ ...rest, displayName: trimmed } as ProviderInstanceConfig)
495 : (rest as ProviderInstanceConfig),
496 );
497 };
498​
499 const updateEnabled = (value: boolean) => {
500 onUpdate({ ...instance, enabled: value });
501 };
502​
503 const updateAccentColor = (value: string) => {
504 const normalized = normalizeProviderAccentColor(value);
505 const { accentColor: _omit, ...rest } = instance;
506 onUpdate(
507 normalized
508 ? ({ ...rest, accentColor: normalized } as ProviderInstanceConfig)
509 : (rest as ProviderInstanceConfig),
510 );
511 };
512​
513 const updateConfig = (nextConfig: Record<string, unknown> | undefined) => {
514 const { config: _omit, ...rest } = instance;
515 onUpdate(
516 nextConfig !== undefined
517 ? ({ ...rest, config: nextConfig } as ProviderInstanceConfig)
518 : (rest as ProviderInstanceConfig),
519 );
520 };
521​
522 const updateCustomModels = (next: ReadonlyArray<string>) => {
523 const nextConfig = nextConfigBlobWithValue(instance.config, "customModels", [...next]);
524 const { config: _omit, ...rest } = instance;
525 onUpdate({ ...rest, config: nextConfig } as ProviderInstanceConfig);
526 };
527​
528 const updateEnvironment = (environment: ReadonlyArray<ProviderInstanceEnvironmentVariable>) => {
529 const cleaned = environment.filter((variable) => variable.name.trim().length > 0);
530 const { environment: _omit, ...rest } = instance;
531 onUpdate(
532 cleaned.length > 0
533 ? ({ ...rest, environment: cleaned } as ProviderInstanceConfig)
534 : (rest as ProviderInstanceConfig),
535 );
536 };
537​
538 return (
539 <div className="border-t border-border first:border-t-0">
540 <div className="px-4 py-4 sm:px-5">
541 <div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
542 <div className="min-w-0 flex-1 space-y-1">
543 <div className="flex min-h-5 items-center gap-1.5">
544 {driverKind ? (
545 <ProviderInstanceIcon
546 driverKind={driverKind}
547 displayName={displayName}
548 accentColor={accentColor}
549 showBadge={Boolean(accentColor)}
550 statusDotClassName={statusStyle.dot}
551 className="size-5"
552 iconClassName="size-4 text-foreground/80"
553 badgeClassName="right-[-0.125rem] bottom-[-0.125rem] h-3 min-w-3 text-[7px]"
554 />
555 ) : FallbackIconComponent ? (
556 <span className="relative inline-flex size-5 shrink-0 items-center justify-center">
557 <FallbackIconComponent className="size-4 text-foreground/80" aria-hidden />
558 <span
559 className={cn(
560 "pointer-events-none absolute -left-0.5 -top-0.5 size-2 rounded-full ring-2 ring-background",
561 statusStyle.dot,
562 )}
563 aria-hidden
564 />
565 </span>
566 ) : (
567 <span className={cn("size-2 shrink-0 rounded-full", statusStyle.dot)} />
568 )}
569 <h3 className="truncate text-sm font-medium text-foreground">{displayName}</h3>
570 {String(instanceId) !== String(instance.driver) ? (
571 // Hide the id chip on a default slot whose id === the
572 // driver slug — it's redundant with the driver icon +
573 // label. Custom instances (and any instance the user has
574 // since renamed) keep the chip so their slug stays
575 // visible for copy/paste + disambiguation.
576 <code className="truncate rounded bg-muted/60 px-1 py-0.5 text-[10px] text-muted-foreground">
577 {instanceId}
578 </code>
579 ) : null}
580 {driverOption?.badgeLabel ? (
581 <Badge variant="warning" size="sm" className="shrink-0">
582 {driverOption.badgeLabel}
583 </Badge>
584 ) : null}
585 {versionLabel ? (
586 <code className="text-xs text-muted-foreground">{versionLabel}</code>
587 ) : null}
588 {headerAction ? (
589 <span className="inline-flex h-5 w-5 shrink-0 items-center justify-center">
590 {headerAction}
591 </span>
592 ) : null}
593 {onDelete ? (
594 <span className="inline-flex h-5 w-5 shrink-0 items-center justify-center">
595 <Tooltip>
596 <TooltipTrigger
597 render={
598 <Button
599 size="icon-xs"
600 variant="ghost"
601 className="size-5 rounded-sm p-0 text-muted-foreground hover:text-destructive"
602 onClick={onDelete}
603 aria-label={`Delete provider instance ${instanceId}`}
604 >
605 <Trash2Icon className="size-3" />
606 </Button>
607 }
608 />
609 <TooltipPopup side="top">Delete instance</TooltipPopup>
610 </Tooltip>
611 </span>
612 ) : null}
613 </div>
614 <p className="flex min-w-0 flex-wrap items-center gap-x-1 text-xs text-muted-foreground">
615 {hasAuthenticatedEmail ? (
616 <>
617 <span>Authenticated as</span>
618 <ProviderAuthEmail email={authEmail} />
619 {authenticatedDetail ? <span>· {authenticatedDetail}</span> : null}
620 </>
621 ) : (
622 <>
623 <span>{summary.headline}</span>
624 <ProviderAuthEmail email={authEmail} separator prefix="Email" />
625 </>
626 )}
627 {summary.detail ? <span>- {summary.detail}</span> : null}
628 </p>
629 </div>
630 <div className="flex w-full shrink-0 items-center gap-2 sm:w-auto sm:justify-end">
631 <Button
632 size="sm"
633 variant="ghost"
634 className="h-7 px-2 text-xs text-muted-foreground hover:text-foreground"
635 onClick={() => onExpandedChange(!isExpanded)}
636 aria-label={`Toggle ${displayName} details`}
637 >
638 <ChevronDownIcon
639 className={cn("size-3.5 transition-transform", isExpanded && "rotate-180")}
640 />
641 </Button>
642 <Switch
643 checked={enabled}
644 onCheckedChange={(checked) => updateEnabled(Boolean(checked))}
645 aria-label={`Enable ${displayName}`}
646 />
647 </div>
648 </div>
649 </div>
650​
651 <Collapsible open={isExpanded} onOpenChange={onExpandedChange}>
652 <CollapsibleContent>
653 <div className="space-y-0">
654 <div className="border-t border-border/60 px-4 py-3 sm:px-5">
655 <label htmlFor={`provider-instance-${instanceId}-display-name`} className="block">
656 <span className="text-xs font-medium text-foreground">Display name</span>
657 <DraftInput
658 id={`provider-instance-${instanceId}-display-name`}
659 className="mt-1.5"
660 value={instance.displayName ?? ""}
661 onCommit={updateDisplayName}
662 placeholder={driverOption?.label ?? "Instance label"}
663 spellCheck={false}
664 />
665 <span className="mt-1 block text-xs text-muted-foreground">
666 Optional label shown in the provider list.
667 </span>
668 </label>
669 </div>
670​
671 <div className="border-t border-border/60 px-4 py-3 sm:px-5">
672 <ProviderAccentColorPicker
673 displayName={displayName}
674 value={accentColor}
675 onCommit={updateAccentColor}
676 />
677 </div>
678​
679 <div className="border-t border-border/60 px-4 py-3 sm:px-5">
680 <ProviderEnvironmentSection
681 environment={instance.environment ?? []}
682 onChange={updateEnvironment}
683 />
684 </div>
685​
686 {driverOption ? (
687 <ProviderSettingsForm
688 definition={driverOption}
689 value={instance.config}
690 idPrefix={`provider-instance-${instanceId}`}
691 variant="card"
692 onChange={updateConfig}
693 />
694 ) : null}
695​
696 {driverOption !== undefined ? (
697 <ProviderModelsSection
698 instanceId={instanceId}
699 driverKind={driverKind}
700 models={modelsForDisplay}
701 customModels={customModels}
702 hiddenModels={hiddenModels}
703 favoriteModels={favoriteModels}
704 modelOrder={modelOrder}
705 onChange={updateCustomModels}
706 onHiddenModelsChange={onHiddenModelsChange}
707 onFavoriteModelsChange={onFavoriteModelsChange}
708 onModelOrderChange={onModelOrderChange}
709 />
710 ) : (
711 <div className="border-t border-border/60 px-4 py-3 sm:px-5">
712 <p className="text-xs text-muted-foreground">
713 This instance uses a driver (
714 <code className="text-foreground">{String(instance.driver)}</code>) that is not
715 shipped with the current build. Configuration values are preserved but cannot be
716 edited from this surface.
717 </p>
718 </div>
719 )}
720 </div>
721 </CollapsibleContent>
722 </Collapsible>
723 </div>
724 );