| 1 | import { z } from "zod"; |
| 2 | |
| 3 | export const clientCertificateOptionsSchema = z.object({ |
| 4 | cert: z.string(), |
| 5 | key: z.string(), |
| 6 | passphrase: z.string().optional(), |
| 7 | }); |
| 8 | export type ClientCertificateOptions = z.infer< |
| 9 | typeof clientCertificateOptionsSchema |
| 10 | >; |
| 11 | |
| 12 | export const requestOptionsSchema = z.object({ |
| 13 | timeout: z.number().optional(), |
| 14 | verifySsl: z.boolean().optional(), |
| 15 | caBundlePath: z.union([z.string(), z.array(z.string())]).optional(), |
| 16 | proxy: z.string().optional(), |
| 17 | headers: z.record(z.string()).optional(), |
| 18 | extraBodyProperties: z.record(z.any()).optional(), |
| 19 | noProxy: z.array(z.string()).optional(), |
| 20 | clientCertificate: clientCertificateOptionsSchema.optional(), |
| 21 | }); |
| 22 | export type RequestOptions = z.infer<typeof requestOptionsSchema>; |
| 23 | export const modelRolesSchema = z.enum([ |
| 24 | "chat", |
| 25 | "autocomplete", |
| 26 | "embed", |
| 27 | "rerank", |
| 28 | "edit", |
| 29 | "apply", |
| 30 | "summarize", |
| 31 | ]); |
| 32 | export type ModelRole = z.infer<typeof modelRolesSchema>; |
| 33 | |
| 34 | // TODO consider just using array of strings for model capabilities |
| 35 | // To allow more dynamic string parsing |
| 36 | export const modelCapabilitySchema = z.union([ |
| 37 | z.literal("tool_use"), |
| 38 | z.literal("image_input"), |
| 39 | z.literal("next_edit"), |
| 40 | z.string(), // Needed for forwards compatibility, see https://github.com/continuedev/continue/pull/7676 |
| 41 | ]); |
| 42 | |
| 43 | // not ideal but lose type suggestions if use z.infer because of the string fallback |
| 44 | export type ModelCapability = "tool_use" | "image_input" | "next_edit"; |
| 45 | |
| 46 | export const completionOptionsSchema = z.object({ |
| 47 | contextLength: z.number().optional(), |
| 48 | maxTokens: z.number().optional(), |
| 49 | temperature: z.number().optional(), |
| 50 | topP: z.number().optional(), |
| 51 | topK: z.number().optional(), |
| 52 | minP: z.number().optional(), |
| 53 | presencePenalty: z.number().optional(), |
| 54 | frequencyPenalty: z.number().optional(), |
| 55 | stop: z.array(z.string()).optional(), |
| 56 | n: z.number().optional(), |
| 57 | reasoning: z.boolean().optional(), |
| 58 | reasoningBudgetTokens: z.number().optional(), |
| 59 | promptCaching: z.boolean().optional(), |
| 60 | stream: z.boolean().optional(), |
| 61 | }); |
| 62 | export type CompletionOptions = z.infer<typeof completionOptionsSchema>; |
| 63 | |
| 64 | export const embeddingTasksSchema = z.union([ |
| 65 | z.literal("chunk"), |
| 66 | z.literal("query"), |
| 67 | ]); |
| 68 | export type EmbeddingTasks = z.infer<typeof embeddingTasksSchema>; |
| 69 | |
| 70 | export const embeddingPrefixesSchema = z.record( |
| 71 | embeddingTasksSchema, |
| 72 | z.string(), |
| 73 | ); |
| 74 | export type EmbeddingPrefixes = z.infer<typeof embeddingPrefixesSchema>; |
| 75 | |
| 76 | export const cacheBehaviorSchema = z.object({ |
| 77 | cacheSystemMessage: z.boolean().optional(), |
| 78 | cacheConversation: z.boolean().optional(), |
| 79 | }); |
| 80 | export type CacheBehavior = z.infer<typeof cacheBehaviorSchema>; |
| 81 | |
| 82 | export const embedOptionsSchema = z.object({ |
| 83 | maxChunkSize: z.number().optional(), |
| 84 | maxBatchSize: z.number().optional(), |
| 85 | embeddingPrefixes: embeddingPrefixesSchema.optional(), |
| 86 | }); |
| 87 | export type EmbedOptions = z.infer<typeof embedOptionsSchema>; |
| 88 | |
| 89 | export const chatOptionsSchema = z.object({ |
| 90 | baseSystemMessage: z.string().optional(), |
| 91 | baseAgentSystemMessage: z.string().optional(), |
| 92 | basePlanSystemMessage: z.string().optional(), |
| 93 | }); |
| 94 | export type ChatOptions = z.infer<typeof chatOptionsSchema>; |
| 95 | |
| 96 | const templateSchema = z.enum([ |
| 97 | "llama2", |
| 98 | "alpaca", |
| 99 | "zephyr", |
| 100 | "phi2", |
| 101 | "phind", |
| 102 | "anthropic", |
| 103 | "chatml", |
| 104 | "none", |
| 105 | "openchat", |
| 106 | "deepseek", |
| 107 | "xwin-coder", |
| 108 | "neural-chat", |
| 109 | "codellama-70b", |
| 110 | "llava", |
| 111 | "gemma", |
| 112 | "granite", |
| 113 | "llama3", |
| 114 | "codestral", |
| 115 | ]); |
| 116 | |
| 117 | export const autocompleteOptionsSchema = z.object({ |
| 118 | disable: z.boolean().optional(), |
| 119 | maxPromptTokens: z.number().optional(), |
| 120 | debounceDelay: z.number().optional(), |
| 121 | modelTimeout: z.number().optional(), |
| 122 | maxSuffixPercentage: z.number().optional(), |
| 123 | prefixPercentage: z.number().optional(), |
| 124 | transform: z.boolean().optional(), |
| 125 | template: z.string().optional(), |
| 126 | onlyMyCode: z.boolean().optional(), |
| 127 | useCache: z.boolean().optional(), |
| 128 | useImports: z.boolean().optional(), |
| 129 | useRecentlyEdited: z.boolean().optional(), |
| 130 | useRecentlyOpened: z.boolean().optional(), |
| 131 | // Experimental options: true = enabled, false = disabled, number = enabled w priority |
| 132 | experimental_includeClipboard: z.boolean().optional(), |
| 133 | experimental_includeRecentlyVisitedRanges: z.boolean().optional(), |
| 134 | experimental_includeRecentlyEditedRanges: z.boolean().optional(), |
| 135 | experimental_includeDiff: z.boolean().optional(), |
| 136 | experimental_enableStaticContextualization: z.boolean().optional(), |
| 137 | }); |
| 138 | |
| 139 | /** Prompt templates use Handlebars syntax */ |
| 140 | const promptTemplatesSchema = z.object({ |
| 141 | apply: z.string().optional(), |
| 142 | chat: templateSchema.optional(), |
| 143 | edit: z.string().optional(), |
| 144 | autocomplete: z.string().optional(), |
| 145 | }); |
| 146 | export type PromptTemplates = z.infer<typeof promptTemplatesSchema>; |
| 147 | |
| 148 | const baseModelFields = { |
| 149 | name: z.string(), |
| 150 | model: z.string(), |
| 151 | apiKey: z.string().optional(), |
| 152 | apiBase: z.string().optional(), |
| 153 | maxStopWords: z.number().optional(), |
| 154 | roles: modelRolesSchema.array().optional(), |
| 155 | capabilities: modelCapabilitySchema.array().optional(), |
| 156 | defaultCompletionOptions: completionOptionsSchema.optional(), |
| 157 | cacheBehavior: cacheBehaviorSchema.optional(), |
| 158 | requestOptions: requestOptionsSchema.optional(), |
| 159 | embedOptions: embedOptionsSchema.optional(), |
| 160 | chatOptions: chatOptionsSchema.optional(), |
| 161 | promptTemplates: promptTemplatesSchema.optional(), |
| 162 | useLegacyCompletionsEndpoint: z.boolean().optional(), |
| 163 | env: z |
| 164 | .record(z.string(), z.union([z.string(), z.boolean(), z.number()])) |
| 165 | .optional(), |
| 166 | autocompleteOptions: autocompleteOptionsSchema.optional(), |
| 167 | }; |
| 168 | |
| 169 | export const modelSchema = z.union([ |
| 170 | z.object({ |
| 171 | ...baseModelFields, |
| 172 | provider: z.literal("continue-proxy"), |
| 173 | apiKeyLocation: z.string().optional(), |
| 174 | envSecretLocations: z.record(z.string(), z.string()).optional(), |
| 175 | orgScopeId: z.string().nullable(), |
| 176 | onPremProxyUrl: z.string().nullable(), |
| 177 | }), |
| 178 | z.object({ |
| 179 | ...baseModelFields, |
| 180 | provider: z.string().refine((val) => val !== "continue-proxy"), |
| 181 | sourceFile: z.string().optional(), |
| 182 | }), |
| 183 | ]); |
| 184 | |
| 185 | export const partialModelSchema = z.union([ |
| 186 | z |
| 187 | .object({ |
| 188 | ...baseModelFields, |
| 189 | provider: z.literal("continue-proxy"), |
| 190 | apiKeyLocation: z.string().optional(), |
| 191 | envSecretLocations: z.record(z.string(), z.string()).optional(), |
| 192 | }) |
| 193 | .partial(), |
| 194 | z |
| 195 | .object({ |
| 196 | ...baseModelFields, |
| 197 | provider: z.string().refine((val) => val !== "continue-proxy"), |
| 198 | }) |
| 199 | .partial(), |
| 200 | ]); |
| 201 | |
| 202 | export type ModelConfig = z.infer<typeof modelSchema>; |