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

ProviderInstanceCard.tsx

805 lines30.5 KB

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