providers.ts
1 import { z } from 'zod' 2 3 export const ModelInfoSchema = z.object({ 4 modelId: z.string(), 5 nickname: z.string().optional(), 6 type: z.enum(['chat', 'embedding', 'rerank']).optional().default('chat'), 7 capabilities: z 8 .array(z.enum(['vision', 'reasoning', 'tool_use', 'web_search'])) 9 .optional(), 10 contextWindow: z.number().optional(), 11 maxOutput: z.number().optional(), 12 }) 13 export type ModelInfo = z.infer<typeof ModelInfoSchema> 14 15 export const ProviderUrlsSchema = z.object({ 16 website: z.string().optional(), 17 getApiKey: z.string().optional(), 18 docs: z.string().optional(), 19 models: z.string().optional(), 20 }) 21 22 export const ProviderTypeEnum = z.enum([ 23 'openai', 24 'openai-responses', 25 'anthropic', 26 'gemini', 27 'chatglm', 28 ]) 29 export type ProviderType = z.infer<typeof ProviderTypeEnum> 30 31 export interface CustomProvider { 32 id: string 33 name: string 34 type: ProviderType 35 isCustom: true 36 iconUrl?: string 37 urls?: z.infer<typeof ProviderUrlsSchema> 38 apiHost?: string 39 apiPath?: string 40 apiKey?: string 41 models?: ModelInfo[] 42 enabled?: boolean 43 } 44 45 export interface BuiltinProvider { 46 id: string 47 name: string 48 type: ProviderType 49 isCustom: false 50 description?: string 51 defaultApiHost?: string 52 defaultModels?: ModelInfo[] 53 } 54 55 export type Provider = CustomProvider | BuiltinProvider 56 57 export const CustomProviderSettingsSchema = z.object({ 58 apiHost: z.string().optional(), 59 apiPath: z.string().optional(), 60 apiKey: z.string().optional(), 61 useProxy: z.boolean().optional(), 62 models: z.array(ModelInfoSchema).optional(), 63 }) 64 export type CustomProviderSettings = z.infer< 65 typeof CustomProviderSettingsSchema 66 > 67 68 export interface ProviderWithSettings { 69 id: string 70 name: string 71 type: ProviderType 72 isCustom: boolean 73 iconUrl?: string 74 urls?: z.infer<typeof ProviderUrlsSchema> 75 apiHost?: string 76 apiPath?: string 77 apiKey?: string 78 models?: ModelInfo[] 79 enabled?: boolean 80 settings: CustomProviderSettings 81 available?: boolean 82 lastProbeAt?: string | null 83 }