Skip to content

Commit cc102a0

Browse files
author
Julius Marminge
committed
Move provider setting labels into schema annotations
- Derive form labels and descriptions from contract annotations - Simplify provider metadata and reuse shared empty config draft - Cover annotated field metadata in settings form tests
1 parent 7db8ea1 commit cc102a0

5 files changed

Lines changed: 226 additions & 128 deletions

File tree

‎apps/web/src/components/settings/AddProviderInstanceDialog.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function deriveInstanceId(driver: ProviderDriverKind, label: string): string {
6262
const INSTANCE_ID_PATTERN = /^[a-zA-Z][a-zA-Z0-9_-]*$/;
6363
const DEFAULT_DRIVER_KIND = ProviderDriverKind.make("codex");
6464
const DEFAULT_DRIVER_OPTION = DRIVER_OPTIONS[0]!;
65+
const EMPTY_CONFIG_DRAFT: Record<string, unknown> = {};
6566
interface ComingSoonDriverOption {
6667
readonly value: ProviderDriverKind;
6768
readonly label: string;
@@ -165,7 +166,7 @@ export function AddProviderInstanceDialog({ open, onOpenChange }: AddProviderIns
165166
const wizardSteps = ["Driver", "Identity", "Config"] as const;
166167
const wizardStepSummaries = [driverOption.label, previewLabel, null] as const;
167168

168-
const configDraft = configByDriver[driver] ?? {};
169+
const configDraft = configByDriver[driver] ?? EMPTY_CONFIG_DRAFT;
169170
const setConfigDraft = useCallback(
170171
(config: Record<string, unknown> | undefined) => {
171172
setConfigByDriver((existing) => {

‎apps/web/src/components/settings/ProviderSettingsForm.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ describe("ProviderSettingsForm helpers", () => {
2020
]);
2121
});
2222

23+
it("sources labels and descriptions from schema annotations", () => {
24+
const opencode = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("opencode")];
25+
expect(opencode).toBeDefined();
26+
27+
const serverPassword = deriveProviderSettingsFields(opencode!).find(
28+
(field) => field.key === "serverPassword",
29+
);
30+
31+
expect(serverPassword).toMatchObject({
32+
label: "Server password",
33+
description: "Stored in plain text on disk.",
34+
control: "password",
35+
});
36+
});
37+
2338
it("preserves unknown config keys while omitting empty configurable fields", () => {
2439
const opencode = DRIVER_OPTION_BY_VALUE[ProviderDriverKind.make("opencode")];
2540
expect(opencode).toBeDefined();
Lines changed: 132 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use client";
22

33
import { useMemo, type ReactNode } from "react";
4+
import { Schema } from "effect";
45

56
import { cn } from "../../lib/utils";
67
import { DraftInput } from "../ui/draft-input";
@@ -33,6 +34,16 @@ function fieldControlFromUi(ui: ProviderSettingsFieldUi | undefined): ProviderSe
3334
return ui?.control ?? "text";
3435
}
3536

37+
function readFieldAnnotationString(
38+
fieldSchema: ProviderClientDefinition["settingsSchema"]["fields"][string],
39+
key: "title" | "description",
40+
): string | undefined {
41+
const annotations =
42+
Schema.resolveAnnotationsKey(fieldSchema) ?? Schema.resolveAnnotations(fieldSchema);
43+
const value = annotations?.[key];
44+
return typeof value === "string" ? value : undefined;
45+
}
46+
3647
export function deriveProviderSettingsFields(
3748
definition: ProviderClientDefinition,
3849
): ReadonlyArray<ProviderSettingsFieldModel> {
@@ -46,12 +57,19 @@ export function deriveProviderSettingsFields(
4657
return orderedKeys.flatMap((key) => {
4758
const ui = definition.settingsUi.fields?.[key];
4859
if (ui?.hidden) return [];
60+
const fieldSchema = definition.settingsSchema.fields[key]!;
61+
const annotatedTitle = readFieldAnnotationString(fieldSchema, "title");
62+
const annotatedDescription = readFieldAnnotationString(fieldSchema, "description");
4963
return [
5064
{
5165
key,
5266
control: fieldControlFromUi(ui),
53-
label: ui?.label ?? titleizeFieldKey(key),
54-
...(ui?.description !== undefined ? { description: ui.description } : {}),
67+
label: ui?.label ?? annotatedTitle ?? titleizeFieldKey(key),
68+
...(ui?.description !== undefined
69+
? { description: ui.description }
70+
: annotatedDescription !== undefined
71+
? { description: annotatedDescription }
72+
: {}),
5573
...(ui?.placeholder !== undefined ? { placeholder: ui.placeholder } : {}),
5674
clearWhenEmpty: ui?.clearWhenEmpty ?? "omit",
5775
} satisfies ProviderSettingsFieldModel,
@@ -111,6 +129,108 @@ function FieldFrame(props: {
111129
return <div className="grid gap-1.5">{props.children}</div>;
112130
}
113131

132+
interface ProviderSettingsFieldRowProps {
133+
readonly field: ProviderSettingsFieldModel;
134+
readonly value: unknown;
135+
readonly idPrefix: string;
136+
readonly variant: ProviderSettingsFormProps["variant"];
137+
readonly onChange: ProviderSettingsFormProps["onChange"];
138+
}
139+
140+
function ProviderSettingsFieldRow({
141+
field,
142+
value,
143+
idPrefix,
144+
variant,
145+
onChange,
146+
}: ProviderSettingsFieldRowProps) {
147+
const inputId = `${idPrefix}-${field.key}`;
148+
const descriptionClassName =
149+
variant === "card"
150+
? "mt-1 block text-xs text-muted-foreground"
151+
: "text-[11px] text-muted-foreground";
152+
const label = <span className="text-xs font-medium text-foreground">{field.label}</span>;
153+
const description = field.description ? (
154+
<span className={descriptionClassName}>{field.description}</span>
155+
) : null;
156+
157+
if (field.control === "switch") {
158+
return (
159+
<FieldFrame variant={variant}>
160+
<div className="flex items-center justify-between gap-3">
161+
<div className="min-w-0">
162+
{label}
163+
{description}
164+
</div>
165+
<Switch
166+
checked={readProviderConfigBoolean(value, field.key)}
167+
onCheckedChange={(checked) =>
168+
onChange(nextProviderConfigWithFieldValue(value, field, Boolean(checked)))
169+
}
170+
aria-label={field.label}
171+
/>
172+
</div>
173+
</FieldFrame>
174+
);
175+
}
176+
177+
if (field.control === "textarea") {
178+
return (
179+
<FieldFrame variant={variant}>
180+
<label htmlFor={inputId} className={cn(variant === "card" && "block")}>
181+
{label}
182+
<Textarea
183+
id={inputId}
184+
className={cn(variant === "card" && "mt-1.5")}
185+
value={readProviderConfigString(value, field.key)}
186+
onChange={(event) =>
187+
onChange(nextProviderConfigWithFieldValue(value, field, event.target.value))
188+
}
189+
placeholder={field.placeholder}
190+
spellCheck={false}
191+
/>
192+
{description}
193+
</label>
194+
</FieldFrame>
195+
);
196+
}
197+
198+
const type = field.control === "password" ? "password" : undefined;
199+
return (
200+
<FieldFrame variant={variant}>
201+
<label htmlFor={inputId} className={cn(variant === "card" && "block")}>
202+
{label}
203+
{variant === "card" ? (
204+
<DraftInput
205+
id={inputId}
206+
className="mt-1.5"
207+
type={type}
208+
autoComplete={field.control === "password" ? "off" : undefined}
209+
value={readProviderConfigString(value, field.key)}
210+
onCommit={(next) => onChange(nextProviderConfigWithFieldValue(value, field, next))}
211+
placeholder={field.placeholder}
212+
spellCheck={false}
213+
/>
214+
) : (
215+
<Input
216+
id={inputId}
217+
className="bg-background"
218+
type={type}
219+
autoComplete={field.control === "password" ? "off" : undefined}
220+
value={readProviderConfigString(value, field.key)}
221+
onChange={(event) =>
222+
onChange(nextProviderConfigWithFieldValue(value, field, event.target.value))
223+
}
224+
placeholder={field.placeholder}
225+
spellCheck={false}
226+
/>
227+
)}
228+
{description}
229+
</label>
230+
</FieldFrame>
231+
);
232+
}
233+
114234
export function ProviderSettingsForm({
115235
definition,
116236
value,
@@ -126,95 +246,16 @@ export function ProviderSettingsForm({
126246

127247
return (
128248
<>
129-
{fields.map((field) => {
130-
const inputId = `${idPrefix}-${field.key}`;
131-
const descriptionClassName =
132-
variant === "card"
133-
? "mt-1 block text-xs text-muted-foreground"
134-
: "text-[11px] text-muted-foreground";
135-
const label = <span className="text-xs font-medium text-foreground">{field.label}</span>;
136-
const description = field.description ? (
137-
<span className={descriptionClassName}>{field.description}</span>
138-
) : null;
139-
140-
if (field.control === "switch") {
141-
return (
142-
<FieldFrame key={field.key} variant={variant}>
143-
<div className="flex items-center justify-between gap-3">
144-
<div className="min-w-0">
145-
{label}
146-
{description}
147-
</div>
148-
<Switch
149-
checked={readProviderConfigBoolean(value, field.key)}
150-
onCheckedChange={(checked) =>
151-
onChange(nextProviderConfigWithFieldValue(value, field, Boolean(checked)))
152-
}
153-
aria-label={field.label}
154-
/>
155-
</div>
156-
</FieldFrame>
157-
);
158-
}
159-
160-
if (field.control === "textarea") {
161-
return (
162-
<FieldFrame key={field.key} variant={variant}>
163-
<label htmlFor={inputId} className={cn(variant === "card" && "block")}>
164-
{label}
165-
<Textarea
166-
id={inputId}
167-
className={cn(variant === "card" && "mt-1.5")}
168-
value={readProviderConfigString(value, field.key)}
169-
onChange={(event) =>
170-
onChange(nextProviderConfigWithFieldValue(value, field, event.target.value))
171-
}
172-
placeholder={field.placeholder}
173-
spellCheck={false}
174-
/>
175-
{description}
176-
</label>
177-
</FieldFrame>
178-
);
179-
}
180-
181-
const type = field.control === "password" ? "password" : undefined;
182-
return (
183-
<FieldFrame key={field.key} variant={variant}>
184-
<label htmlFor={inputId} className={cn(variant === "card" && "block")}>
185-
{label}
186-
{variant === "card" ? (
187-
<DraftInput
188-
id={inputId}
189-
className="mt-1.5"
190-
type={type}
191-
autoComplete={field.control === "password" ? "off" : undefined}
192-
value={readProviderConfigString(value, field.key)}
193-
onCommit={(next) =>
194-
onChange(nextProviderConfigWithFieldValue(value, field, next))
195-
}
196-
placeholder={field.placeholder}
197-
spellCheck={false}
198-
/>
199-
) : (
200-
<Input
201-
id={inputId}
202-
className="bg-background"
203-
type={type}
204-
autoComplete={field.control === "password" ? "off" : undefined}
205-
value={readProviderConfigString(value, field.key)}
206-
onChange={(event) =>
207-
onChange(nextProviderConfigWithFieldValue(value, field, event.target.value))
208-
}
209-
placeholder={field.placeholder}
210-
spellCheck={false}
211-
/>
212-
)}
213-
{description}
214-
</label>
215-
</FieldFrame>
216-
);
217-
})}
249+
{fields.map((field) => (
250+
<ProviderSettingsFieldRow
251+
key={field.key}
252+
field={field}
253+
value={value}
254+
idPrefix={idPrefix}
255+
variant={variant}
256+
onChange={onChange}
257+
/>
258+
))}
218259
</>
219260
);
220261
}

‎apps/web/src/components/settings/providerDriverMeta.ts‎

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import {
55
OpenCodeSettings,
66
ProviderDriverKind,
77
} from "@t3tools/contracts";
8+
import type { Schema } from "effect";
89
import { ClaudeAI, CursorIcon, type Icon, OpenAI, OpenCodeIcon } from "../Icons";
910

1011
type ProviderSettingsSchema = {
11-
readonly fields: Readonly<Record<string, unknown>>;
12+
readonly fields: Readonly<Record<string, Schema.Top>>;
1213
};
1314

1415
export type ProviderSettingsControl = "text" | "password" | "textarea" | "switch";
@@ -60,22 +61,15 @@ export const PROVIDER_CLIENT_DEFINITIONS: readonly ProviderClientDefinition[] =
6061
enabled: { hidden: true },
6162
customModels: { hidden: true },
6263
binaryPath: {
63-
label: "Binary path",
6464
placeholder: "codex",
65-
description: "Path to the Codex binary used by this instance.",
6665
clearWhenEmpty: "omit",
6766
},
6867
homePath: {
69-
label: "CODEX_HOME path",
7068
placeholder: "~/.codex",
71-
description: "Custom Codex home and config directory.",
7269
clearWhenEmpty: "omit",
7370
},
7471
shadowHomePath: {
75-
label: "Shadow home path",
7672
placeholder: "~/.codex-t3/personal",
77-
description:
78-
"Account-specific Codex home. Keeps auth.json separate while sharing state from CODEX_HOME.",
7973
clearWhenEmpty: "omit",
8074
},
8175
},
@@ -92,22 +86,15 @@ export const PROVIDER_CLIENT_DEFINITIONS: readonly ProviderClientDefinition[] =
9286
enabled: { hidden: true },
9387
customModels: { hidden: true },
9488
binaryPath: {
95-
label: "Binary path",
9689
placeholder: "claude",
97-
description: "Path to the Claude binary used by this instance.",
9890
clearWhenEmpty: "omit",
9991
},
10092
homePath: {
101-
label: "Claude HOME path",
10293
placeholder: "~",
103-
description:
104-
"Custom HOME used when running this Claude instance. Keeps .claude.json and .claude separate.",
10594
clearWhenEmpty: "omit",
10695
},
10796
launchArgs: {
108-
label: "Launch arguments",
10997
placeholder: "e.g. --chrome",
110-
description: "Additional CLI arguments passed on session start.",
11198
clearWhenEmpty: "omit",
11299
},
113100
},
@@ -125,15 +112,11 @@ export const PROVIDER_CLIENT_DEFINITIONS: readonly ProviderClientDefinition[] =
125112
enabled: { hidden: true },
126113
customModels: { hidden: true },
127114
binaryPath: {
128-
label: "Binary path",
129115
placeholder: "agent",
130-
description: "Path to the Cursor agent binary.",
131116
clearWhenEmpty: "omit",
132117
},
133118
apiEndpoint: {
134-
label: "API endpoint",
135119
placeholder: "https://...",
136-
description: "Override the Cursor API endpoint for this instance.",
137120
clearWhenEmpty: "omit",
138121
},
139122
},
@@ -150,22 +133,16 @@ export const PROVIDER_CLIENT_DEFINITIONS: readonly ProviderClientDefinition[] =
150133
enabled: { hidden: true },
151134
customModels: { hidden: true },
152135
binaryPath: {
153-
label: "Binary path",
154136
placeholder: "opencode",
155-
description: "Path to the OpenCode binary.",
156137
clearWhenEmpty: "omit",
157138
},
158139
serverUrl: {
159-
label: "Server URL",
160140
placeholder: "http://127.0.0.1:4096",
161-
description: "Leave blank to let T3 Code spawn the server when needed.",
162141
clearWhenEmpty: "omit",
163142
},
164143
serverPassword: {
165144
control: "password",
166-
label: "Server password",
167145
placeholder: "Optional",
168-
description: "Stored in plain text on disk.",
169146
clearWhenEmpty: "omit",
170147
},
171148
},

0 commit comments

Comments
 (0)