Open History to see the last commit
1import { useState, type ReactNode } from "react";
2import * as Option from "effect/Option";
3import * as Schema from "effect/Schema";
4import {
5 acceptsSecretReference,
6 isSecretReference,
7 isSecretSetting,
8 type EnvironmentId,
9 type ProviderSettingsFormAnnotation,
10 type ProviderSettingsFormControl,
11 type ProviderSettingsFormOption,
12 type ProviderSettingsFormSchemaAnnotation,
13 type SecretReference,
14} from "@t3tools/contracts";
15import { PlusIcon, XIcon } from "lucide-react";
16
17import { cn } from "../../lib/utils";
18import { Button } from "../ui/button";
19import { DraftInput } from "../ui/draft-input";
20import { Input } from "../ui/input";
21import { SecretInput } from "./SecretInput";
22import { SecretSourceInput, useSecretSources } from "./SecretSourceInput";
23import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select";
24import { Switch } from "../ui/switch";
25import { Textarea } from "../ui/textarea";
26import type { ProviderClientDefinition } from "@t3tools/provider-core/client";
27
28export type SettingsFormDefinition = Pick<ProviderClientDefinition, "settingsSchema"> & {
29 readonly driverKind?: ProviderClientDefinition["driverKind"];
30};
31import { SettingsRow } from "./settingsLayout";
32
33export interface ProviderSettingsFieldModel {
34 readonly key: string;
35 readonly control: ProviderSettingsFormControl;
36 readonly label: string;
37 readonly description?: string | undefined;
38 readonly placeholder?: string | undefined;
39 readonly clearWhenEmpty: "omit" | "persist";
40 /** Kept in the server's secret store: a saved value arrives as `SECRET_REDACTED` and never shows. */
41 readonly secret?: boolean | undefined;
42 /** Typed `SettingsSecretValue`: may name a secret provider reference instead of a value. */
43 readonly acceptsSecretReference?: boolean | undefined;
44 readonly defaultBooleanValue?: boolean | undefined;
45 /** Whether the field's schema decodes a typed string; one it rejects is never stored. */
46 readonly accepts?: ((value: string) => boolean) | undefined;
47
48 readonly options?: ReadonlyArray<ProviderSettingsFormOption> | undefined;
49}
50
51function titleizeFieldKey(key: string): string {
52 return key
53 .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
54 .replace(/[-_]+/g, " ")
55 .replace(/^./, (char) => char.toUpperCase());
56}
57
58function readFieldAnnotations(
59 fieldSchema: ProviderClientDefinition["settingsSchema"]["fields"][string],
60) {
61 return Schema.resolveAnnotationsKey(fieldSchema) ?? Schema.resolveAnnotations(fieldSchema);
62}
63
64function readFieldAnnotationString(
65 fieldSchema: ProviderClientDefinition["settingsSchema"]["fields"][string],
66 key: "title" | "description",
67): string | undefined {
68 const annotations = readFieldAnnotations(fieldSchema);
69 const value = annotations?.[key];
70 return typeof value === "string" ? value : undefined;
71}
72
73function readProviderSettingsFormAnnotation(
74 fieldSchema: ProviderClientDefinition["settingsSchema"]["fields"][string],
75): ProviderSettingsFormAnnotation {
76 const annotation = readFieldAnnotations(fieldSchema)?.providerSettingsForm;
77 return annotation ?? {};
78}
79
80function readProviderSettingsFormSchemaAnnotation(
81 definition: SettingsFormDefinition,
82): ProviderSettingsFormSchemaAnnotation {
83 return Schema.resolveAnnotations(definition.settingsSchema)?.providerSettingsFormSchema ?? {};
84}
85
86function readFieldBooleanDefault(
87 fieldSchema: ProviderClientDefinition["settingsSchema"]["fields"][string],
88): boolean | undefined {
89 const decodeDefault = Schema.decodeUnknownOption(fieldSchema as Schema.Decoder<unknown>);
90 const decoded = decodeDefault(undefined);
91 return Option.isSome(decoded) && typeof decoded.value === "boolean" ? decoded.value : undefined;
92}
93
94function fieldAcceptsString(
95 fieldSchema: ProviderClientDefinition["settingsSchema"]["fields"][string],
96): (value: string) => boolean {
97 const decode = Schema.decodeUnknownOption(fieldSchema as Schema.Decoder<unknown>);
98 return (value) => Option.isSome(decode(value));
99}
100
101export function deriveProviderSettingsFields(
102 definition: SettingsFormDefinition,
103 value?: unknown,
104): ReadonlyArray<ProviderSettingsFieldModel> {
105 const isLocalAcp =
106 definition.driverKind === "acpRegistry" &&
107 readProviderConfigString(value, "source") === "local";
108 const schemaAnnotation = readProviderSettingsFormSchemaAnnotation(definition);
109 const orderedKeys = new Map(
110 (schemaAnnotation.order ?? []).map((key, index) => [key, index] as const),
111 );
112 const orderFallbackOffset = orderedKeys.size;
113
114 return Object.keys(definition.settingsSchema.fields)
115 .map((key, index) => ({ key, index }))
116 .toSorted((left, right) => {
117 return (
118 (orderedKeys.get(left.key) ?? orderFallbackOffset + left.index) -
119 (orderedKeys.get(right.key) ?? orderFallbackOffset + right.index)
120 );
121 })
122 .flatMap(({ key }) => {
123 const fieldSchema = definition.settingsSchema.fields[key]!;
124 const formAnnotation = readProviderSettingsFormAnnotation(fieldSchema);
125 if (formAnnotation.hidden) return [];
126 if (isLocalAcp && key !== "source" && key !== "commandPath") return [];
127
128 const annotatedTitle = readFieldAnnotationString(fieldSchema, "title");
129 const annotatedDescription = readFieldAnnotationString(fieldSchema, "description");
130 return [
131 {
132 key,
133 control: formAnnotation.control ?? "text",
134 label:
135 isLocalAcp && key === "commandPath"
136 ? "Executable"
137 : (annotatedTitle ?? titleizeFieldKey(key)),
138 ...(isLocalAcp && key === "commandPath"
139 ? { description: "Executable name or path on this environment." }
140 : annotatedDescription !== undefined
141 ? { description: annotatedDescription }
142 : {}),
143 ...(isLocalAcp && key === "commandPath"
144 ? { placeholder: "e.g. dsh" }
145 : formAnnotation.placeholder !== undefined
146 ? { placeholder: formAnnotation.placeholder }
147 : {}),
148 clearWhenEmpty: formAnnotation.clearWhenEmpty ?? "omit",
149 ...(isSecretSetting(fieldSchema) ? { secret: true } : {}),
150 ...(acceptsSecretReference(fieldSchema) ? { acceptsSecretReference: true } : {}),
151 ...(formAnnotation.control === "switch"
152 ? { defaultBooleanValue: readFieldBooleanDefault(fieldSchema) }
153 : {}),
154 accepts: fieldAcceptsString(fieldSchema),
155 ...(formAnnotation.control === "select" && formAnnotation.options
156 ? { options: formAnnotation.options }
157 : {}),
158 } satisfies ProviderSettingsFieldModel,
159 ];
160 });
161}
162
163let commandArgumentDraftId = 0;
164/**
165 * Editable rows seeded from a configured value. `seen` is the value the rows
166 * were last reconciled against; `lastPublished` is what the rows last sent to
167 * the owner, so its echo does not reseed rows (and drop their ids) mid-edit.
168 */
169export interface RowsDraft<V, R> {
170 readonly rows: ReadonlyArray<R>;
171 readonly seen: V;
172 readonly lastPublished: V | undefined;
173}
174
175export function seedRowsDraft<V, R>(
176 value: V,
177 toRows: (value: V) => ReadonlyArray<R>,
178): RowsDraft<V, R> {
179 return { rows: toRows(value), seen: value, lastPublished: undefined };
180}
181
182/** Reseeds the rows when the configured value changes from outside this editor. */
183export function reconcileRowsDraft<V, R>(
184 draft: RowsDraft<V, R>,
185 incoming: V,
186 equal: (left: V, right: V) => boolean,
187 toRows: (value: V) => ReadonlyArray<R>,
188): RowsDraft<V, R> {
189 if (draft.seen === incoming || equal(draft.seen, incoming)) return draft;
190 const echo = draft.lastPublished !== undefined && equal(draft.lastPublished, incoming);
191 return { rows: echo ? draft.rows : toRows(incoming), seen: incoming, lastPublished: undefined };
192}
193
194const makeCommandArgumentDraftRow = (value: string) => ({
195 id: `provider-argument-${commandArgumentDraftId++}`,
196 value,
197});
198
199const toCommandArgumentRows = (args: ReadonlyArray<string>) =>
200 args.map(makeCommandArgumentDraftRow);
201
202function commandArgumentsEqual(left: ReadonlyArray<string>, right: ReadonlyArray<string>) {
203 return left.length === right.length && left.every((argument, index) => argument === right[index]);
204}
205
206function configuredCommandArgs(value: ProviderSettingsFormProps["value"]) {
207 const configured =
208 value !== null && typeof value === "object"
209 ? (value as Record<string, unknown>).commandArgs
210 : undefined;
211 return Array.isArray(configured)
212 ? configured.filter((argument): argument is string => typeof argument === "string")
213 : [];
214}
215
216function ProviderCommandArguments({
217 value,
218 onChange,
219 managedReason,
220}: Pick<ProviderSettingsFormProps, "value" | "onChange"> & {
221 readonly managedReason: string | undefined;
222}) {
223 const args = configuredCommandArgs(value);
224 const [storedDraft, setDraft] = useState(() => seedRowsDraft(args, toCommandArgumentRows));
225 const draft = reconcileRowsDraft(storedDraft, args, commandArgumentsEqual, toCommandArgumentRows);
226 if (draft !== storedDraft) setDraft(draft);
227 const rows = draft.rows;
228
229 const updateArguments = (nextRows: typeof rows) => {
230 const next = nextRows.map((row) => row.value);
231 setDraft({ rows: nextRows, seen: draft.seen, lastPublished: next });
232 const config =
233 value !== null && typeof value === "object" ? { ...(value as Record<string, unknown>) } : {};
234 onChange({ ...config, commandArgs: next });
235 };
236
237 return (
238 <SettingsRow
239 title="Arguments"
240 description="One literal argument per row, in launch order."
241 managed={managedReason}
242 control={
243 <Button
244 type="button"
245 size="sm"
246 variant="outline"
247 onClick={() => updateArguments([...rows, makeCommandArgumentDraftRow("")])}
248 >
249 <PlusIcon />
250 Add argument
251 </Button>
252 }
253 >
254 {rows.length > 0 ? (
255 <div className="mt-3 min-w-0 space-y-2 pb-2">
256 {rows.map((argument, index) =>
257 managedReason !== undefined ? (
258 <code key={argument.id} className="block min-w-0 truncate text-xs">
259 {argument.value}
260 </code>
261 ) : (
262 <div key={argument.id} className="flex min-w-0 items-center gap-1.5">
263 <DraftInput
264 size="sm"
265 font="mono"
266 value={argument.value}
267 onCommit={(next) =>
268 updateArguments(
269 rows.map((current) =>
270 current.id === argument.id ? { ...current, value: next } : current,
271 ),
272 )
273 }
274 aria-label={`Argument ${index + 1}`}
275 spellCheck={false}
276 />
277 <Button
278 type="button"
279 size="icon-micro"
280 variant="ghost-destructive"
281 onClick={() =>
282 updateArguments(rows.filter((current) => current.id !== argument.id))
283 }
284 aria-label={`Remove argument ${index + 1}`}
285 >
286 <XIcon />
287 </Button>
288 </div>
289 ),
290 )}
291 </div>
292 ) : null}
293 </SettingsRow>
294 );
295}
296
297function readProviderConfigString(config: unknown, key: string): string {
298 if (config === null || typeof config !== "object") return "";
299 const value = (config as Record<string, unknown>)[key];
300 return typeof value === "string" ? value : "";
301}
302
303function readProviderConfigBoolean(config: unknown, key: string, defaultValue = false): boolean {
304 if (config === null || typeof config !== "object") return defaultValue;
305 const value = (config as Record<string, unknown>)[key];
306 return typeof value === "boolean" ? value : defaultValue;
307}
308
309export function nextProviderConfigWithFieldValue(
310 config: unknown,
311 field: ProviderSettingsFieldModel,
312 value: string | boolean | SecretReference,
313): Record<string, unknown> | undefined {
314 const base: Record<string, unknown> =
315 config !== null && typeof config === "object" ? { ...(config as Record<string, unknown>) } : {};
316
317 if (typeof value === "object") {
318 base[field.key] = value;
319 return base;
320 }
321
322 if (typeof value === "boolean") {
323 const emptyBooleanValue = field.defaultBooleanValue ?? false;
324 if (field.clearWhenEmpty === "omit" && value === emptyBooleanValue) {
325 delete base[field.key];
326 } else {
327 base[field.key] = value;
328 }
329 return Object.keys(base).length > 0 ? base : undefined;
330 }
331
332 const trimmed = value.trim();
333 if (field.clearWhenEmpty === "omit" && trimmed.length === 0) {
334 delete base[field.key];
335 } else if (field.accepts?.(value) !== false) {
336 base[field.key] = value;
337 }
338 return Object.keys(base).length > 0 ? base : undefined;
339}
340
341interface ProviderSettingsFormProps {
342 readonly definition: SettingsFormDefinition;
343 readonly value: unknown;
344 readonly idPrefix: string;
345 readonly variant: "card" | "dialog" | "settings";
346 readonly onChange: (nextConfig: Record<string, unknown> | undefined) => void;
347 /** Config keys an administrator's policy pins, shown inert with the reason. */
348 readonly managed?: { readonly keys: ReadonlySet<string>; readonly reason: string } | undefined;
349 /** Where the secret providers offered for `SettingsSecretValue` fields are configured. */
350 readonly environmentId?: EnvironmentId | undefined;
351}
352
353function SecretSettingsControl({
354 field,
355 value,
356 inputId,
357 descriptionId,
358 environmentId,
359 onChange,
360}: {
361 readonly field: ProviderSettingsFieldModel;
362 readonly value: unknown;
363 readonly inputId: string;
364 readonly descriptionId: string | undefined;
365 readonly environmentId: EnvironmentId;
366 readonly onChange: ProviderSettingsFormProps["onChange"];
367}) {
368 const sources = useSecretSources(environmentId);
369 const saved =
370 value !== null && typeof value === "object"
371 ? (value as Record<string, unknown>)[field.key]
372 : undefined;
373 const reference = isSecretReference(saved) ? saved : undefined;
374 const configured = reference !== undefined || (typeof saved === "string" && saved.length > 0);
375 return (
376 <div className="flex w-full min-w-0 items-start gap-2 @min-[32rem]/settings-row:w-80">
377 <SecretSourceInput
378 id={inputId}
379 aria-describedby={descriptionId}
380 aria-label={field.label}
381 size="sm"
382 className="min-w-0 flex-1"
383 value={reference ?? ""}
384 configured={reference === undefined && configured}
385 sources={sources}
386 onCommit={(next) => onChange(nextProviderConfigWithFieldValue(value, field, next))}
387 onSecretChange={(secret) =>
388 onChange(nextProviderConfigWithFieldValue(value, field, secret ?? ""))
389 }
390 />
391 {configured ? (
392 <Button
393 type="button"
394 size="icon-sm"
395 variant="ghost-destructive"
396 onClick={() => onChange(nextProviderConfigWithFieldValue(value, field, ""))}
397 aria-label={`Clear ${field.label}`}
398 >
399 <XIcon className="size-3.5" />
400 </Button>
401 ) : null}
402 </div>
403 );
404}
405
406function ProviderSettingsSelect({
407 field,
408 value,
409 inputId,
410 size,
411 className,
412 onChange,
413}: {
414 readonly field: ProviderSettingsFieldModel;
415 readonly value: unknown;
416 readonly inputId: string;
417 readonly size: "sm" | "xs";
418 readonly className?: string | undefined;
419 readonly onChange: ProviderSettingsFormProps["onChange"];
420}) {
421 const options = field.options ?? [];
422 const fallback = options[0]?.value ?? "";
423 const current = readProviderConfigString(value, field.key) || fallback;
424 const label = options.find((option) => option.value === current)?.label ?? current;
425 return (
426 <Select
427 value={current}
428 onValueChange={(next) => {
429 if (typeof next !== "string") return;
430 onChange(nextProviderConfigWithFieldValue(value, field, next === fallback ? "" : next));
431 }}
432 >
433 <SelectTrigger id={inputId} size={size} className={className} aria-label={field.label}>
434 <SelectValue>{label}</SelectValue>
435 </SelectTrigger>
436 <SelectPopup align="start" alignItemWithTrigger={false}>
437 {options.map((option) => (
438 <SelectItem key={option.value} value={option.value}>
439 {option.label}
440 </SelectItem>
441 ))}
442 </SelectPopup>
443 </Select>
444 );
445}
446
447function ProviderSettingsTextInput({
448 field,
449 value,
450 inputId,
451 descriptionId,
452 onChange,
453}: {
454 readonly field: ProviderSettingsFieldModel;
455 readonly value: unknown;
456 readonly inputId: string;
457 readonly descriptionId: string | undefined;
458 readonly onChange: ProviderSettingsFormProps["onChange"];
459}) {
460 const [rejected, setRejected] = useState<string | null>(null);
461 return (
462 <div className="flex w-full min-w-0 flex-col gap-1 @min-[32rem]/settings-row:w-56">
463 <DraftInput
464 id={inputId}
465 aria-describedby={descriptionId}
466 size="sm"
467 className="w-full max-w-full"
468 type={field.control === "password" ? "password" : undefined}
469 autoComplete={field.control === "password" ? "off" : undefined}
470 value={rejected ?? readProviderConfigString(value, field.key)}
471 placeholder={field.placeholder}
472 onCommit={(next) => {
473 const clears = field.clearWhenEmpty === "omit" && next.trim().length === 0;
474 if (!clears && field.accepts?.(next) === false) {
475 setRejected(next);
476 return;
477 }
478 setRejected(null);
479 onChange(nextProviderConfigWithFieldValue(value, field, next));
480 }}
481 aria-invalid={rejected !== null || undefined}
482 spellCheck={false}
483 />
484 {rejected !== null ? (
485 <p className="text-2xs text-destructive">Enter a valid value. It was not saved.</p>
486 ) : null}
487 </div>
488 );
489}
490
491function FieldFrame(props: {
492 readonly variant: ProviderSettingsFormProps["variant"];
493 readonly children: ReactNode;
494}) {
495 if (props.variant === "card") {
496 return <div>{props.children}</div>;
497 }
498 return <div className="grid gap-1.5">{props.children}</div>;
499}
500
501interface ProviderSettingsFieldRowProps {
502 readonly field: ProviderSettingsFieldModel;
503 readonly value: unknown;
504 readonly idPrefix: string;
505 readonly variant: ProviderSettingsFormProps["variant"];
506 readonly onChange: ProviderSettingsFormProps["onChange"];
507 readonly managedReason?: string | undefined;
508 readonly environmentId: EnvironmentId | undefined;
509}
510
511function ProviderSettingsFieldRow({
512 field,
513 value,
514 idPrefix,
515 variant,
516 onChange,
517 managedReason,
518 environmentId,
519}: ProviderSettingsFieldRowProps) {
520 const inputId = `${idPrefix}-${field.key}`;
521 const descriptionClassName =
522 variant === "dialog"
523 ? "text-2xs text-muted-foreground"
524 : "mt-1 block text-xs text-muted-foreground";
525 const label = <span className="text-xs font-medium text-foreground">{field.label}</span>;
526 const description = field.description ? (
527 <span className={descriptionClassName}>{field.description}</span>
528 ) : null;
529
530 if (variant === "settings") {
531 const descriptionId = field.description ? `${inputId}-description` : undefined;
532 const secretConfigured =
533 field.secret === true && readProviderConfigString(value, field.key).length > 0;
534 const control =
535 field.control === "switch" ? (
536 <Switch
537 checked={readProviderConfigBoolean(value, field.key, field.defaultBooleanValue)}
538 onCheckedChange={(checked) =>
539 onChange(nextProviderConfigWithFieldValue(value, field, Boolean(checked)))
540 }
541 aria-label={field.label}
542 aria-describedby={descriptionId}
543 />
544 ) : field.control === "select" ? (
545 <ProviderSettingsSelect
546 field={field}
547 value={value}
548 inputId={inputId}
549 size="sm"
550 className="w-full max-w-full @min-[32rem]/settings-row:w-56"
551 onChange={onChange}
552 />
553 ) : field.control === "textarea" ? (
554 <Textarea
555 id={inputId}
556 aria-describedby={descriptionId}
557 className="w-full max-w-full @min-[32rem]/settings-row:w-[min(24rem,50cqw)]"
558 value={readProviderConfigString(value, field.key)}
559 onChange={(event) =>
560 onChange(nextProviderConfigWithFieldValue(value, field, event.target.value))
561 }
562 placeholder={field.placeholder}
563 spellCheck={false}
564 />
565 ) : field.acceptsSecretReference && environmentId !== undefined ? (
566 <SecretSettingsControl
567 field={field}
568 value={value}
569 inputId={inputId}
570 descriptionId={descriptionId}
571 environmentId={environmentId}
572 onChange={onChange}
573 />
574 ) : field.secret ? (
575 <div className="flex w-full min-w-0 items-center gap-2 @min-[32rem]/settings-row:w-56">
576 <SecretInput
577 id={inputId}
578 aria-describedby={descriptionId}
579 size="sm"
580 className="min-w-0 flex-1"
581 configured={secretConfigured}
582 value=""
583 onCommit={(next) => onChange(nextProviderConfigWithFieldValue(value, field, next))}
584 />
585 {secretConfigured ? (
586 <Button
587 type="button"
588 size="icon-sm"
589 variant="ghost-destructive"
590 onClick={() => onChange(nextProviderConfigWithFieldValue(value, field, ""))}
591 aria-label={`Clear ${field.label}`}
592 >
593 <XIcon className="size-3.5" />
594 </Button>
595 ) : null}
596 </div>
597 ) : (
598 <ProviderSettingsTextInput
599 field={field}
600 value={value}
601 inputId={inputId}
602 descriptionId={descriptionId}
603 onChange={onChange}
604 />
605 );
606
607 return (
608 <SettingsRow
609 title={
610 field.control === "switch" ? field.label : <label htmlFor={inputId}>{field.label}</label>
611 }
612 description={
613 field.description ? <span id={descriptionId}>{field.description}</span> : undefined
614 }
615 control={control}
616 managed={managedReason}
617 />
618 );
619 }
620
621 if (field.control === "switch") {
622 return (
623 <FieldFrame variant={variant}>
624 <div className="flex items-center justify-between gap-3">
625 <div className="min-w-0">
626 {label}
627 {description}
628 </div>
629 <Switch
630 checked={readProviderConfigBoolean(value, field.key, field.defaultBooleanValue)}
631 onCheckedChange={(checked) =>
632 onChange(nextProviderConfigWithFieldValue(value, field, Boolean(checked)))
633 }
634 aria-label={field.label}
635 />
636 </div>
637 </FieldFrame>
638 );
639 }
640
641 if (field.control === "select") {
642 return (
643 <FieldFrame variant={variant}>
644 <label htmlFor={inputId} className={cn(variant === "card" && "block")}>
645 {label}
646 <ProviderSettingsSelect
647 field={field}
648 value={value}
649 inputId={inputId}
650 size="sm"
651 className={cn("w-full", variant === "card" && "mt-1.5")}
652 onChange={onChange}
653 />
654 {description}
655 </label>
656 </FieldFrame>
657 );
658 }
659
660 if (field.control === "textarea") {
661 return (
662 <FieldFrame variant={variant}>
663 <label htmlFor={inputId} className={cn(variant === "card" && "block")}>
664 {label}
665 <Textarea
666 id={inputId}
667 className={cn(variant === "card" && "mt-1.5")}
668 value={readProviderConfigString(value, field.key)}
669 onChange={(event) =>
670 onChange(nextProviderConfigWithFieldValue(value, field, event.target.value))
671 }
672 placeholder={field.placeholder}
673 spellCheck={false}
674 />
675 {description}
676 </label>
677 </FieldFrame>
678 );
679 }
680
681 const type = field.control === "password" ? "password" : undefined;
682 const BufferedInput = field.secret ? SecretInput : DraftInput;
683 const ControlledInput = field.secret ? SecretInput : Input;
684 return (
685 <FieldFrame variant={variant}>
686 <label htmlFor={inputId} className={cn(variant === "card" && "block")}>
687 {label}
688 {variant === "card" ? (
689 <BufferedInput
690 id={inputId}
691 size="sm"
692 className="mt-1.5"
693 type={field.secret ? undefined : type}
694 autoComplete={!field.secret && field.control === "password" ? "off" : undefined}
695 value={readProviderConfigString(value, field.key)}
696 onCommit={(next) => onChange(nextProviderConfigWithFieldValue(value, field, next))}
697 placeholder={field.placeholder}
698 spellCheck={false}
699 />
700 ) : (
701 <ControlledInput
702 id={inputId}
703 type={field.secret ? undefined : type}
704 autoComplete={!field.secret && field.control === "password" ? "off" : undefined}
705 value={readProviderConfigString(value, field.key)}
706 onChange={(event) =>
707 onChange(nextProviderConfigWithFieldValue(value, field, event.target.value))
708 }
709 placeholder={field.placeholder}
710 spellCheck={false}
711 />
712 )}
713 {description}
714 </label>
715 </FieldFrame>
716 );
717}
718
719export function ProviderSettingsForm({
720 definition,
721 value,
722 idPrefix,
723 variant,
724 onChange,
725 managed,
726 environmentId,
727}: ProviderSettingsFormProps) {
728 const fields = deriveProviderSettingsFields(definition, value);
729 const isLocalAcp =
730 definition.driverKind === "acpRegistry" &&
731 readProviderConfigString(value, "source") === "local";
732
733 if (fields.length === 0) {
734 return null;
735 }
736
737 return (
738 <>
739 {fields.map((field) => (
740 <ProviderSettingsFieldRow
741 key={field.key}
742 field={field}
743 value={value}
744 idPrefix={idPrefix}
745 variant={variant}
746 onChange={onChange}
747 managedReason={managed?.keys.has(field.key) ? managed.reason : undefined}
748 environmentId={environmentId}
749 />
750 ))}
751 {isLocalAcp ? (
752 <ProviderCommandArguments
753 value={value}
754 onChange={onChange}
755 managedReason={managed?.keys.has("commandArgs") ? managed.reason : undefined}
756 />
757 ) : null}
758 </>
759 );
760}