|
| 1 | +import { z } from "zod" |
| 2 | + |
| 3 | +import type { Keys } from "./type-fu.js" |
| 4 | +import { |
| 5 | + type ProviderSettings, |
| 6 | + PROVIDER_SETTINGS_KEYS, |
| 7 | + providerSettingsEntrySchema, |
| 8 | + providerSettingsSchema, |
| 9 | +} from "./provider-settings.js" |
| 10 | +import { historyItemSchema } from "./history.js" |
| 11 | +import { codebaseIndexModelsSchema, codebaseIndexConfigSchema } from "./codebase-index.js" |
| 12 | +import { experimentsSchema } from "./experiment.js" |
| 13 | +import { telemetrySettingsSchema } from "./telemetry.js" |
| 14 | +import { modeConfigSchema } from "./mode.js" |
| 15 | +import { customModePromptsSchema, customSupportPromptsSchema } from "./mode.js" |
| 16 | +import { languagesSchema } from "./vscode.js" |
| 17 | + |
| 18 | +/** |
| 19 | + * GlobalSettings |
| 20 | + */ |
| 21 | + |
| 22 | +export const globalSettingsSchema = z.object({ |
| 23 | + currentApiConfigName: z.string().optional(), |
| 24 | + listApiConfigMeta: z.array(providerSettingsEntrySchema).optional(), |
| 25 | + pinnedApiConfigs: z.record(z.string(), z.boolean()).optional(), |
| 26 | + |
| 27 | + lastShownAnnouncementId: z.string().optional(), |
| 28 | + customInstructions: z.string().optional(), |
| 29 | + taskHistory: z.array(historyItemSchema).optional(), |
| 30 | + |
| 31 | + condensingApiConfigId: z.string().optional(), |
| 32 | + customCondensingPrompt: z.string().optional(), |
| 33 | + |
| 34 | + autoApprovalEnabled: z.boolean().optional(), |
| 35 | + alwaysAllowReadOnly: z.boolean().optional(), |
| 36 | + alwaysAllowReadOnlyOutsideWorkspace: z.boolean().optional(), |
| 37 | + codebaseIndexModels: codebaseIndexModelsSchema.optional(), |
| 38 | + codebaseIndexConfig: codebaseIndexConfigSchema.optional(), |
| 39 | + alwaysAllowWrite: z.boolean().optional(), |
| 40 | + alwaysAllowWriteOutsideWorkspace: z.boolean().optional(), |
| 41 | + writeDelayMs: z.number().optional(), |
| 42 | + alwaysAllowBrowser: z.boolean().optional(), |
| 43 | + alwaysApproveResubmit: z.boolean().optional(), |
| 44 | + requestDelaySeconds: z.number().optional(), |
| 45 | + alwaysAllowMcp: z.boolean().optional(), |
| 46 | + alwaysAllowModeSwitch: z.boolean().optional(), |
| 47 | + alwaysAllowSubtasks: z.boolean().optional(), |
| 48 | + alwaysAllowExecute: z.boolean().optional(), |
| 49 | + allowedCommands: z.array(z.string()).optional(), |
| 50 | + allowedMaxRequests: z.number().nullish(), |
| 51 | + autoCondenseContextPercent: z.number().optional(), |
| 52 | + |
| 53 | + browserToolEnabled: z.boolean().optional(), |
| 54 | + browserViewportSize: z.string().optional(), |
| 55 | + screenshotQuality: z.number().optional(), |
| 56 | + remoteBrowserEnabled: z.boolean().optional(), |
| 57 | + remoteBrowserHost: z.string().optional(), |
| 58 | + cachedChromeHostUrl: z.string().optional(), |
| 59 | + |
| 60 | + enableCheckpoints: z.boolean().optional(), |
| 61 | + |
| 62 | + ttsEnabled: z.boolean().optional(), |
| 63 | + ttsSpeed: z.number().optional(), |
| 64 | + soundEnabled: z.boolean().optional(), |
| 65 | + soundVolume: z.number().optional(), |
| 66 | + |
| 67 | + maxOpenTabsContext: z.number().optional(), |
| 68 | + maxWorkspaceFiles: z.number().optional(), |
| 69 | + showRooIgnoredFiles: z.boolean().optional(), |
| 70 | + maxReadFileLine: z.number().optional(), |
| 71 | + |
| 72 | + terminalOutputLineLimit: z.number().optional(), |
| 73 | + terminalShellIntegrationTimeout: z.number().optional(), |
| 74 | + terminalShellIntegrationDisabled: z.boolean().optional(), |
| 75 | + terminalCommandDelay: z.number().optional(), |
| 76 | + terminalPowershellCounter: z.boolean().optional(), |
| 77 | + terminalZshClearEolMark: z.boolean().optional(), |
| 78 | + terminalZshOhMy: z.boolean().optional(), |
| 79 | + terminalZshP10k: z.boolean().optional(), |
| 80 | + terminalZdotdir: z.boolean().optional(), |
| 81 | + terminalCompressProgressBar: z.boolean().optional(), |
| 82 | + |
| 83 | + rateLimitSeconds: z.number().optional(), |
| 84 | + diffEnabled: z.boolean().optional(), |
| 85 | + fuzzyMatchThreshold: z.number().optional(), |
| 86 | + experiments: experimentsSchema.optional(), |
| 87 | + |
| 88 | + language: languagesSchema.optional(), |
| 89 | + |
| 90 | + telemetrySetting: telemetrySettingsSchema.optional(), |
| 91 | + |
| 92 | + mcpEnabled: z.boolean().optional(), |
| 93 | + enableMcpServerCreation: z.boolean().optional(), |
| 94 | + |
| 95 | + mode: z.string().optional(), |
| 96 | + modeApiConfigs: z.record(z.string(), z.string()).optional(), |
| 97 | + customModes: z.array(modeConfigSchema).optional(), |
| 98 | + customModePrompts: customModePromptsSchema.optional(), |
| 99 | + customSupportPrompts: customSupportPromptsSchema.optional(), |
| 100 | + enhancementApiConfigId: z.string().optional(), |
| 101 | + historyPreviewCollapsed: z.boolean().optional(), |
| 102 | +}) |
| 103 | + |
| 104 | +export type GlobalSettings = z.infer<typeof globalSettingsSchema> |
| 105 | + |
| 106 | +type GlobalSettingsRecord = Record<Keys<GlobalSettings>, undefined> |
| 107 | + |
| 108 | +const globalSettingsRecord: GlobalSettingsRecord = { |
| 109 | + codebaseIndexModels: undefined, |
| 110 | + codebaseIndexConfig: undefined, |
| 111 | + currentApiConfigName: undefined, |
| 112 | + listApiConfigMeta: undefined, |
| 113 | + pinnedApiConfigs: undefined, |
| 114 | + |
| 115 | + lastShownAnnouncementId: undefined, |
| 116 | + customInstructions: undefined, |
| 117 | + taskHistory: undefined, |
| 118 | + |
| 119 | + condensingApiConfigId: undefined, |
| 120 | + customCondensingPrompt: undefined, |
| 121 | + |
| 122 | + autoApprovalEnabled: undefined, |
| 123 | + alwaysAllowReadOnly: undefined, |
| 124 | + alwaysAllowReadOnlyOutsideWorkspace: undefined, |
| 125 | + alwaysAllowWrite: undefined, |
| 126 | + alwaysAllowWriteOutsideWorkspace: undefined, |
| 127 | + writeDelayMs: undefined, |
| 128 | + alwaysAllowBrowser: undefined, |
| 129 | + alwaysApproveResubmit: undefined, |
| 130 | + requestDelaySeconds: undefined, |
| 131 | + alwaysAllowMcp: undefined, |
| 132 | + alwaysAllowModeSwitch: undefined, |
| 133 | + alwaysAllowSubtasks: undefined, |
| 134 | + alwaysAllowExecute: undefined, |
| 135 | + allowedCommands: undefined, |
| 136 | + allowedMaxRequests: undefined, |
| 137 | + autoCondenseContextPercent: undefined, |
| 138 | + |
| 139 | + browserToolEnabled: undefined, |
| 140 | + browserViewportSize: undefined, |
| 141 | + screenshotQuality: undefined, |
| 142 | + remoteBrowserEnabled: undefined, |
| 143 | + remoteBrowserHost: undefined, |
| 144 | + |
| 145 | + enableCheckpoints: undefined, |
| 146 | + |
| 147 | + ttsEnabled: undefined, |
| 148 | + ttsSpeed: undefined, |
| 149 | + soundEnabled: undefined, |
| 150 | + soundVolume: undefined, |
| 151 | + |
| 152 | + maxOpenTabsContext: undefined, |
| 153 | + maxWorkspaceFiles: undefined, |
| 154 | + showRooIgnoredFiles: undefined, |
| 155 | + maxReadFileLine: undefined, |
| 156 | + |
| 157 | + terminalOutputLineLimit: undefined, |
| 158 | + terminalShellIntegrationTimeout: undefined, |
| 159 | + terminalShellIntegrationDisabled: undefined, |
| 160 | + terminalCommandDelay: undefined, |
| 161 | + terminalPowershellCounter: undefined, |
| 162 | + terminalZshClearEolMark: undefined, |
| 163 | + terminalZshOhMy: undefined, |
| 164 | + terminalZshP10k: undefined, |
| 165 | + terminalZdotdir: undefined, |
| 166 | + terminalCompressProgressBar: undefined, |
| 167 | + |
| 168 | + rateLimitSeconds: undefined, |
| 169 | + diffEnabled: undefined, |
| 170 | + fuzzyMatchThreshold: undefined, |
| 171 | + experiments: undefined, |
| 172 | + |
| 173 | + language: undefined, |
| 174 | + |
| 175 | + telemetrySetting: undefined, |
| 176 | + |
| 177 | + mcpEnabled: undefined, |
| 178 | + enableMcpServerCreation: undefined, |
| 179 | + |
| 180 | + mode: undefined, |
| 181 | + modeApiConfigs: undefined, |
| 182 | + customModes: undefined, |
| 183 | + customModePrompts: undefined, |
| 184 | + customSupportPrompts: undefined, |
| 185 | + enhancementApiConfigId: undefined, |
| 186 | + cachedChromeHostUrl: undefined, |
| 187 | + historyPreviewCollapsed: undefined, |
| 188 | +} |
| 189 | + |
| 190 | +export const GLOBAL_SETTINGS_KEYS = Object.keys(globalSettingsRecord) as Keys<GlobalSettings>[] |
| 191 | + |
| 192 | +/** |
| 193 | + * RooCodeSettings |
| 194 | + */ |
| 195 | + |
| 196 | +export const rooCodeSettingsSchema = providerSettingsSchema.merge(globalSettingsSchema) |
| 197 | + |
| 198 | +export type RooCodeSettings = GlobalSettings & ProviderSettings |
| 199 | + |
| 200 | +/** |
| 201 | + * SecretState |
| 202 | + */ |
| 203 | + |
| 204 | +export type SecretState = Pick< |
| 205 | + ProviderSettings, |
| 206 | + | "apiKey" |
| 207 | + | "glamaApiKey" |
| 208 | + | "openRouterApiKey" |
| 209 | + | "awsAccessKey" |
| 210 | + | "awsSecretKey" |
| 211 | + | "awsSessionToken" |
| 212 | + | "openAiApiKey" |
| 213 | + | "geminiApiKey" |
| 214 | + | "openAiNativeApiKey" |
| 215 | + | "deepSeekApiKey" |
| 216 | + | "mistralApiKey" |
| 217 | + | "unboundApiKey" |
| 218 | + | "requestyApiKey" |
| 219 | + | "xaiApiKey" |
| 220 | + | "groqApiKey" |
| 221 | + | "chutesApiKey" |
| 222 | + | "litellmApiKey" |
| 223 | + | "codeIndexOpenAiKey" |
| 224 | + | "codeIndexQdrantApiKey" |
| 225 | +> |
| 226 | + |
| 227 | +export type CodeIndexSecrets = "codeIndexOpenAiKey" | "codeIndexQdrantApiKey" |
| 228 | + |
| 229 | +type SecretStateRecord = Record<Keys<SecretState>, undefined> |
| 230 | + |
| 231 | +const secretStateRecord: SecretStateRecord = { |
| 232 | + apiKey: undefined, |
| 233 | + glamaApiKey: undefined, |
| 234 | + openRouterApiKey: undefined, |
| 235 | + awsAccessKey: undefined, |
| 236 | + awsSecretKey: undefined, |
| 237 | + awsSessionToken: undefined, |
| 238 | + openAiApiKey: undefined, |
| 239 | + geminiApiKey: undefined, |
| 240 | + openAiNativeApiKey: undefined, |
| 241 | + deepSeekApiKey: undefined, |
| 242 | + mistralApiKey: undefined, |
| 243 | + unboundApiKey: undefined, |
| 244 | + requestyApiKey: undefined, |
| 245 | + xaiApiKey: undefined, |
| 246 | + groqApiKey: undefined, |
| 247 | + chutesApiKey: undefined, |
| 248 | + litellmApiKey: undefined, |
| 249 | + codeIndexOpenAiKey: undefined, |
| 250 | + codeIndexQdrantApiKey: undefined, |
| 251 | +} |
| 252 | + |
| 253 | +export const SECRET_STATE_KEYS = Object.keys(secretStateRecord) as Keys<SecretState>[] |
| 254 | + |
| 255 | +export const isSecretStateKey = (key: string): key is Keys<SecretState> => |
| 256 | + SECRET_STATE_KEYS.includes(key as Keys<SecretState>) |
| 257 | + |
| 258 | +/** |
| 259 | + * GlobalState |
| 260 | + */ |
| 261 | + |
| 262 | +export type GlobalState = Omit<RooCodeSettings, Keys<SecretState>> |
| 263 | + |
| 264 | +export const GLOBAL_STATE_KEYS = [...GLOBAL_SETTINGS_KEYS, ...PROVIDER_SETTINGS_KEYS].filter( |
| 265 | + (key: Keys<RooCodeSettings>) => !SECRET_STATE_KEYS.includes(key as Keys<SecretState>), |
| 266 | +) as Keys<GlobalState>[] |
| 267 | + |
| 268 | +export const isGlobalStateKey = (key: string): key is Keys<GlobalState> => |
| 269 | + GLOBAL_STATE_KEYS.includes(key as Keys<GlobalState>) |
0 commit comments