Open History to see the last commit
1import {
2 ClaudeSettings,
3 CodexSettings,
4 CursorSettings,
5 GrokSettings,
6 OpenCodeSettings,
7 ProviderDriverKind,
8} from "@t3tools/contracts";
9import type * as Schema from "effect/Schema";
10import { ClaudeAI, CursorIcon, GrokIcon, type Icon, OpenAI, OpenCodeIcon } from "../Icons";
11
12type ProviderSettingsSchema = {
13 readonly fields: Readonly<Record<string, Schema.Top>>;
14} & Schema.Top;
15
16/**
17 * Browser-safe provider definition. This is deliberately shaped like the
18 * future provider package client export: the core web app gets a schema with
19 * field annotations plus provider-level presentation metadata, then renders
20 * settings generically.
21 */
22export interface ProviderClientDefinition {
23 readonly value: ProviderDriverKind;
24 readonly label: string;
25 readonly icon: Icon;
26 readonly settingsSchema: ProviderSettingsSchema;
27 /**
28 * Optional short label rendered as a `variant="warning"` badge next to
29 * the instance title. Used to flag drivers that still ship under an
30 * early-access or preview gate — the flag is a property of the driver
31 * kind (not a specific instance), so every instance of that driver —
32 * built-in default or custom — advertises the same marker.
33 */
34 readonly badgeLabel?: string;
35}
36
37export const PROVIDER_CLIENT_DEFINITIONS: readonly ProviderClientDefinition[] = [
38 {
39 value: ProviderDriverKind.make("codex"),
40 label: "Codex",
41 icon: OpenAI,
42 settingsSchema: CodexSettings,
43 },
44 {
45 value: ProviderDriverKind.make("claudeAgent"),
46 label: "Claude",
47 icon: ClaudeAI,
48 settingsSchema: ClaudeSettings,
49 },
50 {
51 value: ProviderDriverKind.make("cursor"),
52 label: "Cursor",
53 icon: CursorIcon,
54 badgeLabel: "Early Access",
55 settingsSchema: CursorSettings,
56 },
57 {
58 value: ProviderDriverKind.make("grok"),
59 label: "Grok",
60 icon: GrokIcon,
61 badgeLabel: "Early Access",
62 settingsSchema: GrokSettings,
63 },
64 {
65 value: ProviderDriverKind.make("opencode"),
66 label: "OpenCode",
67 icon: OpenCodeIcon,
68 settingsSchema: OpenCodeSettings,
69 },
70];
71
72export const PROVIDER_CLIENT_DEFINITION_BY_VALUE: Partial<
73 Record<ProviderDriverKind, ProviderClientDefinition>
74> = Object.fromEntries(
75 PROVIDER_CLIENT_DEFINITIONS.map((definition) => [definition.value, definition]),
76);
77
78export const DRIVER_OPTIONS = PROVIDER_CLIENT_DEFINITIONS;
79export const DRIVER_OPTION_BY_VALUE = PROVIDER_CLIENT_DEFINITION_BY_VALUE;
80export type DriverOption = ProviderClientDefinition;
81
82/**
83 * Look up the driver metadata for an instance's `driver` field. Accepts
84 * Returns `undefined` for fork / unknown drivers so callers can decide how
85 * to render them — typically by falling back to a generic card.
86 */
87export function getDriverOption(driver: ProviderDriverKind | undefined): DriverOption | undefined {
88 if (driver === undefined) return undefined;
89 return PROVIDER_CLIENT_DEFINITION_BY_VALUE[driver];
90}