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

ProviderInstanceCard.tsx

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