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

client.ts

78 lines2.7 KB

1import type { ProviderDriverKind } from "@t3tools/contracts";
2import type * as Schema from "effect/Schema";
3​
4export type ProviderSettingsSchema = {
5 readonly fields: Readonly<Record<string, Schema.Top>>;
6} & Schema.Top;
7​
8export interface ProviderEnvironmentField {
9 readonly name: string;
10 readonly label: string;
11 readonly description?: string;
12 readonly placeholder?: string;
13 readonly sensitive?: boolean;
15​
16export 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 }>;
26​
27export 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 }>;
34​
35export 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>;
50​
51export function defineProviderClient<const Definition extends ProviderClientDefinition>(
52 definition: Definition,
53): Definition {
54 return definition;
56​
57export interface ProviderClientRegistry {
58 readonly definitions: ReadonlyArray<ProviderClientDefinition>;
59 readonly get: (
60 driverKind: ProviderDriverKind | undefined,
61 ) => ProviderClientDefinition | undefined;
63​
64export 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 };