The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type { ProviderDriverKind } from "@t3tools/contracts"; |
| 2 | import type * as Schema from "effect/Schema"; |
| 3 | |
| 4 | export type ProviderSettingsSchema = { |
| 5 | readonly fields: Readonly<Record<string, Schema.Top>>; |
| 6 | } & Schema.Top; |
| 7 | |
| 8 | export interface ProviderEnvironmentField { |
| 9 | readonly name: string; |
| 10 | readonly label: string; |
| 11 | readonly description?: string; |
| 12 | readonly placeholder?: string; |
| 13 | readonly sensitive?: boolean; |
| 14 | } |
| 15 | |
| 16 | export interface ProviderIcon { |
| 17 | readonly viewBox: string; |
| 18 | readonly fill: { readonly light: string; readonly dark: string }; |
| 19 | readonly paths: ReadonlyArray<{ |
| 20 | readonly d: string; |
| 21 | readonly fillRule?: "evenodd" | "nonzero"; |
| 22 | readonly fill?: { readonly light: string; readonly dark: string }; |
| 23 | readonly gradient?: ProviderIconGradient; |
| 24 | }>; |
| 25 | } |
| 26 | |
| 27 | export interface ProviderIconGradient { |
| 28 | readonly x1: number; |
| 29 | readonly y1: number; |
| 30 | readonly x2: number; |
| 31 | readonly y2: number; |
| 32 | readonly stops: ReadonlyArray<{ readonly offset: number; readonly color: string }>; |
| 33 | } |
| 34 | |
| 35 | export interface ProviderClientDefinition { |
| 36 | readonly driverKind: ProviderDriverKind; |
| 37 | readonly label: string; |
| 38 | readonly icon?: ProviderIcon; |
| 39 | /** Model-name family prefixes the provider's own icon already shows, e.g. "Claude ". */ |
| 40 | readonly modelFamilies?: ReadonlyArray<string>; |
| 41 | readonly settingsSchema: ProviderSettingsSchema; |
| 42 | readonly environmentFields?: ReadonlyArray<ProviderEnvironmentField>; |
| 43 | readonly hasDefaultInstance?: boolean; |
| 44 | readonly badgeLabel?: string; |
| 45 | /** `false` lists the provider under Add provider's "Show more" instead of up front. */ |
| 46 | readonly featured?: boolean; |
| 47 | /** ACP Registry entries for this same agent, left out of Add provider's Registry list. */ |
| 48 | readonly acpRegistryAgentIds?: ReadonlyArray<string>; |
| 49 | } |
| 50 | |
| 51 | export function defineProviderClient<const Definition extends ProviderClientDefinition>( |
| 52 | definition: Definition, |
| 53 | ): Definition { |
| 54 | return definition; |
| 55 | } |
| 56 | |
| 57 | export interface ProviderClientRegistry { |
| 58 | readonly definitions: ReadonlyArray<ProviderClientDefinition>; |
| 59 | readonly get: ( |
| 60 | driverKind: ProviderDriverKind | undefined, |
| 61 | ) => ProviderClientDefinition | undefined; |
| 62 | } |
| 63 | |
| 64 | export function makeProviderClientRegistry( |
| 65 | definitions: ReadonlyArray<ProviderClientDefinition>, |
| 66 | ): ProviderClientRegistry { |
| 67 | const byDriverKind = new Map<ProviderDriverKind, ProviderClientDefinition>(); |
| 68 | for (const definition of definitions) { |
| 69 | if (byDriverKind.has(definition.driverKind)) { |
| 70 | throw new Error(`Provider driver '${definition.driverKind}' is defined more than once.`); |
| 71 | } |
| 72 | byDriverKind.set(definition.driverKind, definition); |
| 73 | } |
| 74 | return { |
| 75 | definitions, |
| 76 | get: (driverKind) => (driverKind === undefined ? undefined : byDriverKind.get(driverKind)), |
| 77 | }; |
| 78 | } |