Elffuss BraidHub

kikocis/continue public

e31fcddb0dec · 5.8 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("ollama"),
50 z.literal("cerebras"),
51 z.literal("kindo"),
52 z.literal("msty"),
53 z.literal("openrouter"),
54 z.literal("sambanova"),
55 z.literal("text-gen-webui"),
56 z.literal("vllm"),
57 z.literal("xAI"),
58 z.literal("scaleway"),
59 z.literal("ncompass"),
60 z.literal("relace"),
61 z.literal("huggingface-inference-api"),
62 ]),
63});
64export type OpenAIConfig = z.infer<typeof OpenAIConfigSchema>;
65
66export const MoonshotConfigSchema = OpenAIConfigSchema.extend({
67 provider: z.literal("moonshot"),
68});
69export type MoonshotConfig = z.infer<typeof MoonshotConfigSchema>;
70
71export const DeepseekConfigSchema = OpenAIConfigSchema.extend({
72 provider: z.literal("deepseek"),
73});
74export type DeepseekConfig = z.infer<typeof DeepseekConfigSchema>;
75
76export const BedrockConfigSchema = OpenAIConfigSchema.extend({
77 provider: z.literal("bedrock"),
78 // cacheBehavior: z.object({
79 // cacheSystemMessage: z.boolean().optional(),
80 // cacheConversation: z.boolean().optional(),
81 // }).optional(),
82 env: z.object({
83 region: z.string().optional(),
84 accessKeyId: z.string().optional(),
85 secretAccessKey: z.string().optional(),
86 profile: z.string().optional(),
87 }),
88});
89export type BedrockConfig = z.infer<typeof BedrockConfigSchema>;
90
91export const LlamastackConfigSchema = OpenAIConfigSchema.extend({
92 provider: z.literal("llamastack"),
93});
94export type LlamastackConfig = z.infer<typeof LlamastackConfigSchema>;
95
96export const ContinueProxyConfigSchema = BasePlusConfig.extend({
97 provider: z.literal("continue-proxy"),
98 env: z.object({
99 apiKeyLocation: z.string().optional(),
100 envSecretLocations: z.record(z.string(), z.string()).optional(),
101 orgScopeId: z.string().nullable(),
102 proxyUrl: z.string().optional(),
103 }),
104});
105export type ContinueProxyConfig = z.infer<typeof ContinueProxyConfigSchema>;
106
107export const MockConfigSchema = BasePlusConfig.extend({
108 provider: z.literal("mock"),
109});
110
111export type MockConfig = z.infer<typeof MockConfigSchema>;
112
113// Other APIs
114export const CohereConfigSchema = OpenAIConfigSchema.extend({
115 provider: z.literal("cohere"),
116});
117export type CohereConfig = z.infer<typeof CohereConfigSchema>;
118
119export const AzureConfigSchema = OpenAIConfigSchema.extend({
120 provider: z.literal("azure"),
121 env: z
122 .object({
123 apiVersion: z.string().optional(),
124 apiType: z
125 .union([
126 z.literal("azure-foundry"),
127 z.literal("azure-openai"),
128 z.literal("azure"), // Legacy
129 ])
130 .optional(),
131 deployment: z.string().optional(),
132 })
133 .optional(),
134});
135export type AzureConfig = z.infer<typeof AzureConfigSchema>;
136
137export const GeminiConfigSchema = OpenAIConfigSchema.extend({
138 provider: z.literal("gemini"),
139 apiKey: z.string(),
140});
141export type GeminiConfig = z.infer<typeof GeminiConfigSchema>;
142
143export const AnthropicConfigSchema = OpenAIConfigSchema.extend({
144 provider: z.literal("anthropic"),
145 apiKey: z.string(),
146});
147export type AnthropicConfig = z.infer<typeof AnthropicConfigSchema>;
148
149export const WatsonXConfigSchema = BasePlusConfig.extend({
150 provider: z.literal("watsonx"),
151 apiKey: z.string(),
152 env: z.object({
153 apiVersion: z.string().optional(),
154 projectId: z.string().optional(),
155 deploymentId: z.string().optional(),
156 }),
157});
158export type WatsonXConfig = z.infer<typeof WatsonXConfigSchema>;
159
160export const JinaConfigSchema = OpenAIConfigSchema.extend({
161 provider: z.literal("jina"),
162});
163export type JinaConfig = z.infer<typeof JinaConfigSchema>;
164
165export const InceptionConfigSchema = OpenAIConfigSchema.extend({
166 provider: z.literal("inception"),
167});
168export type InceptionConfig = z.infer<typeof InceptionConfigSchema>;
169
170export const VertexAIConfigSchema = BasePlusConfig.extend({
171 provider: z.literal("vertexai"),
172 env: z
173 .object({
174 region: z.string().optional(),
175 projectId: z.string().optional(),
176 keyFile: z.string().optional(),
177 keyJson: z.string().optional(),
178 })
179 .optional(),
180});
181export type VertexAIConfig = z.infer<typeof VertexAIConfigSchema>;
182
183// Discriminated union
184export const LLMConfigSchema = z.discriminatedUnion("provider", [
185 OpenAIConfigSchema,
186 BedrockConfigSchema,
187 MoonshotConfigSchema,
188 DeepseekConfigSchema,
189 CohereConfigSchema,
190 AzureConfigSchema,
191 GeminiConfigSchema,
192 AnthropicConfigSchema,
193 WatsonXConfigSchema,
194 JinaConfigSchema,
195 MockConfigSchema,
196 InceptionConfigSchema,
197 VertexAIConfigSchema,
198 LlamastackConfigSchema,
199 ContinueProxyConfigSchema,
200]);
201export type LLMConfig = z.infer<typeof LLMConfigSchema>;