Elffuss BraidHub

kikocis/continue public

a36aa2a5e5e6 · 4.2 KiBRawPermalink
1import * as z from "zod";
2
3export const ClientCertificateOptionsSchema = z.object({
4 cert: z.string(),
5 key: z.string(),
6 passphrase: z.string().optional(),
7});
8
9export const RequestOptionsSchema = z.object({
10 timeout: z.number().optional(),
11 verifySsl: z.boolean().optional(),
12 caBundlePath: z.union([z.string(), z.array(z.string())]).optional(),
13 proxy: z.string().optional(),
14 headers: z.record(z.string()).optional(),
15 extraBodyProperties: z.record(z.unknown()).optional(),
16 noProxy: z.array(z.string()).optional(),
17 clientCertificate: z.lazy(() => ClientCertificateOptionsSchema).optional(),
18});
19
20// Base config objects
21export const BaseConfig = z.object({
22 provider: z.string(),
23 requestOptions: RequestOptionsSchema.optional(),
24});
25
26export const BasePlusConfig = BaseConfig.extend({
27 apiBase: z.string().optional(),
28 apiKey: z.string().optional(),
29});
30
31// OpenAI and compatible
32export const OpenAIConfigSchema = BasePlusConfig.extend({
33 provider: z.union([
34 z.literal("openai"),
35 z.literal("mistral"),
36 z.literal("voyage"),
37 z.literal("deepinfra"),
38 z.literal("groq"),
39 z.literal("nvidia"),
40 z.literal("ovhcloud"),
41 z.literal("fireworks"),
42 z.literal("together"),
43 z.literal("novita"),
44 z.literal("nebius"),
45 z.literal("function-network"),
46 z.literal("llama.cpp"),
47 z.literal("llamafile"),
48 z.literal("lmstudio"),
49 z.literal("cerebras"),
50 z.literal("kindo"),
51 z.literal("msty"),
52 z.literal("openrouter"),
53 z.literal("sambanova"),
54 z.literal("text-gen-webui"),
55 z.literal("vllm"),
56 z.literal("x-ai"),
57 z.literal("scaleway"),
58 z.literal("ncompass"),
59 z.literal("relace"),
60 ]),
61});
62export type OpenAIConfig = z.infer<typeof OpenAIConfigSchema>;
63
64export const MoonshotConfigSchema = OpenAIConfigSchema.extend({
65 provider: z.literal("moonshot"),
66});
67export type MoonshotConfig = z.infer<typeof MoonshotConfigSchema>;
68
69export const DeepseekConfigSchema = OpenAIConfigSchema.extend({
70 provider: z.literal("deepseek"),
71});
72export type DeepseekConfig = z.infer<typeof DeepseekConfigSchema>;
73
74export const MockConfigSchema = BasePlusConfig.extend({
75 provider: z.literal("mock"),
76});
77export type MockConfig = z.infer<typeof MockConfigSchema>;
78
79// Other APIs
80export const CohereConfigSchema = OpenAIConfigSchema.extend({
81 provider: z.literal("cohere"),
82});
83export type CohereConfig = z.infer<typeof CohereConfigSchema>;
84
85export const AzureConfigSchema = OpenAIConfigSchema.extend({
86 provider: z.literal("azure"),
87 env: z
88 .object({
89 apiVersion: z.string().optional(),
90 apiType: z
91 .union([
92 z.literal("azure-foundry"),
93 z.literal("azure-openai"),
94 z.literal("azure"), // Legacy
95 ])
96 .optional(),
97 deployment: z.string().optional(),
98 })
99 .optional(),
100});
101export type AzureConfig = z.infer<typeof AzureConfigSchema>;
102
103export const GeminiConfigSchema = OpenAIConfigSchema.extend({
104 provider: z.literal("gemini"),
105 apiKey: z.string(),
106});
107export type GeminiConfig = z.infer<typeof GeminiConfigSchema>;
108
109export const AnthropicConfigSchema = OpenAIConfigSchema.extend({
110 provider: z.literal("anthropic"),
111 apiKey: z.string(),
112});
113export type AnthropicConfig = z.infer<typeof AnthropicConfigSchema>;
114
115export const WatsonXConfigSchema = BasePlusConfig.extend({
116 provider: z.literal("watsonx"),
117 apiKey: z.string(),
118 env: z.object({
119 apiVersion: z.string().optional(),
120 projectId: z.string().optional(),
121 deploymentId: z.string().optional(),
122 }),
123});
124export type WatsonXConfig = z.infer<typeof WatsonXConfigSchema>;
125
126export const JinaConfigSchema = OpenAIConfigSchema.extend({
127 provider: z.literal("jina"),
128});
129export type JinaConfig = z.infer<typeof JinaConfigSchema>;
130
131export const InceptionConfigSchema = OpenAIConfigSchema.extend({
132 provider: z.literal("inception"),
133});
134export type InceptionConfig = z.infer<typeof InceptionConfigSchema>;
135
136// Discriminated union
137export const LLMConfigSchema = z.discriminatedUnion("provider", [
138 OpenAIConfigSchema,
139 MoonshotConfigSchema,
140 DeepseekConfigSchema,
141 CohereConfigSchema,
142 AzureConfigSchema,
143 GeminiConfigSchema,
144 AnthropicConfigSchema,
145 WatsonXConfigSchema,
146 JinaConfigSchema,
147 MockConfigSchema,
148 InceptionConfigSchema,
149]);
150export type LLMConfig = z.infer<typeof LLMConfigSchema>;