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

providerDriverMeta.ts

125 lines3.7 KB

1import {
2 AcpRegistrySettings,
3 ClaudeSettings,
4 CodexSettings,
5 CursorSettings,
6 GrokSettings,
7 OpenCodeSettings,
8 ProviderDriverKind,
9} from "@t3tools/contracts";
10import type * as Schema from "effect/Schema";
11import {
12 ACPRegistryIcon,
13 ClaudeAI,
14 CursorIcon,
15 GrokIcon,
16 type Icon,
17 OpenAI,
18 OpenCodeIcon,
19} from "../Icons";
20​
21type ProviderSettingsSchema = {
22 readonly fields: Readonly<Record<string, Schema.Top>>;
23} & Schema.Top;
24​
25/**
26 * Browser-safe provider definition. This is deliberately shaped like the
27 * future provider package client export: the core web app gets a schema with
28 * field annotations plus provider-level presentation metadata, then renders
29 * settings generically.
30 */
31export interface ProviderClientDefinition {
32 readonly value: ProviderDriverKind;
33 readonly label: string;
34 readonly icon: Icon;
35 readonly settingsSchema: ProviderSettingsSchema;
36 readonly environmentFields?: readonly ProviderEnvironmentFieldDefinition[];
37 /** Whether this driver has a built-in default instance backed by legacy settings. */
38 readonly hasDefaultInstance?: boolean;
39 /**
40 * Optional short label rendered as a `variant="warning"` badge next to
41 * the instance title. Used to flag drivers that still ship under an
42 * early-access or preview gate — the flag is a property of the driver
43 * kind (not a specific instance), so every instance of that driver —
44 * built-in default or custom — advertises the same marker.
45 */
46 readonly badgeLabel?: string;
48​
49export interface ProviderEnvironmentFieldDefinition {
50 readonly name: string;
51 readonly label: string;
52 readonly description?: string;
53 readonly placeholder?: string;
54 readonly sensitive?: boolean;
56​
57export const PROVIDER_CLIENT_DEFINITIONS: readonly ProviderClientDefinition[] = [
58 {
59 value: ProviderDriverKind.make("codex"),
60 label: "Codex",
61 icon: OpenAI,
62 settingsSchema: CodexSettings,
63 },
64 {
65 value: ProviderDriverKind.make("claudeAgent"),
66 label: "Claude",
67 icon: ClaudeAI,
68 settingsSchema: ClaudeSettings,
69 },
70 {
71 value: ProviderDriverKind.make("cursor"),
72 label: "Cursor",
73 icon: CursorIcon,
74 settingsSchema: CursorSettings,
75 environmentFields: [
76 {
77 name: "CURSOR_API_KEY",
78 label: "Cursor API key",
79 description: "Required by the Cursor Agent SDK.",
80 placeholder: "Paste API key",
81 sensitive: true,
82 },
83 ],
84 },
85 {
86 value: ProviderDriverKind.make("grok"),
87 label: "Grok",
88 icon: GrokIcon,
89 settingsSchema: GrokSettings,
90 },
91 {
92 value: ProviderDriverKind.make("acpRegistry"),
93 label: "ACP Registry",
94 icon: ACPRegistryIcon,
95 badgeLabel: "V2 Preview",
96 settingsSchema: AcpRegistrySettings,
97 hasDefaultInstance: false,
98 },
99 {
100 value: ProviderDriverKind.make("opencode"),
101 label: "OpenCode",
102 icon: OpenCodeIcon,
103 settingsSchema: OpenCodeSettings,
104 },
105];
106​
107export const PROVIDER_CLIENT_DEFINITION_BY_VALUE: Partial<
108 Record<ProviderDriverKind, ProviderClientDefinition>
109> = Object.fromEntries(
110 PROVIDER_CLIENT_DEFINITIONS.map((definition) => [definition.value, definition]),
111);
112​
113export const DRIVER_OPTIONS = PROVIDER_CLIENT_DEFINITIONS;
114export const DRIVER_OPTION_BY_VALUE = PROVIDER_CLIENT_DEFINITION_BY_VALUE;
115export type DriverOption = ProviderClientDefinition;
116​
117/**
118 * Look up the driver metadata for an instance's `driver` field. Accepts
119 * Returns `undefined` for fork / unknown drivers so callers can decide how
120 * to render them — typically by falling back to a generic card.
121 */
122export function getDriverOption(driver: ProviderDriverKind | undefined): DriverOption | undefined {
123 if (driver === undefined) return undefined;
124 return PROVIDER_CLIENT_DEFINITION_BY_VALUE[driver];