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

providerDriverMeta.ts

82 lines2.6 KB

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