♻️ Refactor: Avoid type system duplication (#4596)

This commit is contained in:
Eamon Nerbonne 2025-06-13 18:10:34 +02:00 • committed by GitHub
parent 8fb368dd6b
commit e535b55076
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 6 additions and 226 deletions

View file

@ -1,6 +1,6 @@
import { z } from "zod"
import { type Keys, keysOf } from "./type-fu.js"
import { type Keys } from "./type-fu.js"
import {
type ProviderSettings,
PROVIDER_SETTINGS_KEYS,
@ -106,89 +106,7 @@ export const globalSettingsSchema = z.object({
export type GlobalSettings = z.infer<typeof globalSettingsSchema>
export const GLOBAL_SETTINGS_KEYS = keysOf<GlobalSettings>()([
"currentApiConfigName",
"listApiConfigMeta",
"pinnedApiConfigs",
"lastShownAnnouncementId",
"customInstructions",
"taskHistory",
"condensingApiConfigId",
"customCondensingPrompt",
"autoApprovalEnabled",
"alwaysAllowReadOnly",
"alwaysAllowReadOnlyOutsideWorkspace",
"alwaysAllowWrite",
"alwaysAllowWriteOutsideWorkspace",
"writeDelayMs",
"alwaysAllowBrowser",
"alwaysApproveResubmit",
"requestDelaySeconds",
"alwaysAllowMcp",
"alwaysAllowModeSwitch",
"alwaysAllowSubtasks",
"alwaysAllowExecute",
"allowedCommands",
"allowedMaxRequests",
"autoCondenseContext",
"autoCondenseContextPercent",
"maxConcurrentFileReads",
"browserToolEnabled",
"browserViewportSize",
"screenshotQuality",
"remoteBrowserEnabled",
"remoteBrowserHost",
"enableCheckpoints",
"ttsEnabled",
"ttsSpeed",
"soundEnabled",
"soundVolume",
"maxOpenTabsContext",
"maxWorkspaceFiles",
"showRooIgnoredFiles",
"maxReadFileLine",
"terminalOutputLineLimit",
"terminalShellIntegrationTimeout",
"terminalShellIntegrationDisabled",
"terminalCommandDelay",
"terminalPowershellCounter",
"terminalZshClearEolMark",
"terminalZshOhMy",
"terminalZshP10k",
"terminalZdotdir",
"terminalCompressProgressBar",
"rateLimitSeconds",
"diffEnabled",
"fuzzyMatchThreshold",
"experiments",
"codebaseIndexModels",
"codebaseIndexConfig",
"language",
"telemetrySetting",
"mcpEnabled",
"enableMcpServerCreation",
"mode",
"modeApiConfigs",
"customModes",
"customModePrompts",
"customSupportPrompts",
"enhancementApiConfigId",
"cachedChromeHostUrl",
"historyPreviewCollapsed",
])
export const GLOBAL_SETTINGS_KEYS = globalSettingsSchema.keyof().options
/**
* RooCodeSettings
@ -201,32 +119,7 @@ export type RooCodeSettings = GlobalSettings & ProviderSettings
/**
* SecretState
*/
export type SecretState = Pick<
ProviderSettings,
| "apiKey"
| "glamaApiKey"
| "openRouterApiKey"
| "awsAccessKey"
| "awsSecretKey"
| "awsSessionToken"
| "openAiApiKey"
| "geminiApiKey"
| "openAiNativeApiKey"
| "deepSeekApiKey"
| "mistralApiKey"
| "unboundApiKey"
| "requestyApiKey"
| "xaiApiKey"
| "groqApiKey"
| "chutesApiKey"
| "litellmApiKey"
| "codeIndexOpenAiKey"
| "codeIndexQdrantApiKey"
| "codebaseIndexOpenAiCompatibleApiKey"
>
export const SECRET_STATE_KEYS = keysOf<SecretState>()([
export const SECRET_STATE_KEYS = [
"apiKey",
"glamaApiKey",
"openRouterApiKey",
@ -247,7 +140,8 @@ export const SECRET_STATE_KEYS = keysOf<SecretState>()([
"codeIndexOpenAiKey",
"codeIndexQdrantApiKey",
"codebaseIndexOpenAiCompatibleApiKey",
])
] as const satisfies readonly (keyof ProviderSettings)[]
export type SecretState = Pick<ProviderSettings, (typeof SECRET_STATE_KEYS)[number]>
export const isSecretStateKey = (key: string): key is Keys<SecretState> =>
SECRET_STATE_KEYS.includes(key as Keys<SecretState>)

View file

@ -1,6 +1,5 @@
import { z } from "zod"
import { keysOf } from "./type-fu.js"
import { reasoningEffortsSchema, modelInfoSchema } from "./model.js"
import { codebaseIndexProviderSchema } from "./codebase-index.js"
@ -259,110 +258,7 @@ export const providerSettingsSchema = z.object({
})
export type ProviderSettings = z.infer<typeof providerSettingsSchema>
export const PROVIDER_SETTINGS_KEYS = keysOf<ProviderSettings>()([
"apiProvider",
// Anthropic
"apiModelId",
"apiKey",
"anthropicBaseUrl",
"anthropicUseAuthToken",
// Glama
"glamaModelId",
"glamaApiKey",
// OpenRouter
"openRouterApiKey",
"openRouterModelId",
"openRouterBaseUrl",
"openRouterSpecificProvider",
"openRouterUseMiddleOutTransform",
// Amazon Bedrock
"awsAccessKey",
"awsSecretKey",
"awsSessionToken",
"awsRegion",
"awsUseCrossRegionInference",
"awsUsePromptCache",
"awsProfile",
"awsUseProfile",
"awsCustomArn",
"awsModelContextWindow",
"awsBedrockEndpointEnabled",
"awsBedrockEndpoint",
// Google Vertex
"vertexKeyFile",
"vertexJsonCredentials",
"vertexProjectId",
"vertexRegion",
// OpenAI
"openAiBaseUrl",
"openAiApiKey",
"openAiLegacyFormat",
"openAiR1FormatEnabled",
"openAiModelId",
"openAiCustomModelInfo",
"openAiUseAzure",
"azureApiVersion",
"openAiStreamingEnabled",
"openAiHostHeader", // Keep temporarily for backward compatibility during migration.
"openAiHeaders",
// Ollama
"ollamaModelId",
"ollamaBaseUrl",
// VS Code LM
"vsCodeLmModelSelector",
"lmStudioModelId",
"lmStudioBaseUrl",
"lmStudioDraftModelId",
"lmStudioSpeculativeDecodingEnabled",
// Gemini
"geminiApiKey",
"googleGeminiBaseUrl",
// OpenAI Native
"openAiNativeApiKey",
"openAiNativeBaseUrl",
// Mistral
"mistralApiKey",
"mistralCodestralUrl",
// DeepSeek
"deepSeekBaseUrl",
"deepSeekApiKey",
// Unbound
"unboundApiKey",
"unboundModelId",
// Requesty
"requestyApiKey",
"requestyModelId",
// Code Index
"codeIndexOpenAiKey",
"codeIndexQdrantApiKey",
"codebaseIndexOpenAiCompatibleBaseUrl",
"codebaseIndexOpenAiCompatibleApiKey",
"codebaseIndexOpenAiCompatibleModelDimension",
// Reasoning
"enableReasoningEffort",
"reasoningEffort",
"modelMaxTokens",
"modelMaxThinkingTokens",
// Generic
"includeMaxTokens",
"diffEnabled",
"fuzzyMatchThreshold",
"modelTemperature",
"rateLimitSeconds",
// Fake AI
"fakeAi",
// X.AI (Grok)
"xaiApiKey",
// Groq
"groqApiKey",
// Chutes AI
"chutesApiKey",
// LiteLLM
"litellmBaseUrl",
"litellmApiKey",
"litellmModelId",
])
export const PROVIDER_SETTINGS_KEYS = providerSettingsSchema.keyof().options
export const MODEL_ID_KEYS: Partial<keyof ProviderSettings>[] = [
"apiModelId",

View file

@ -9,13 +9,3 @@ export type Values<T> = T[keyof T]
export type Equals<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false
export type AssertEqual<T extends true> = T
/**
* Creates a type-safe keys array that enforces ALL keys from type T are present.
* Returns a compile-time error if any keys are missing or extra keys are provided.
*/
export function keysOf<T>() {
return <const U extends readonly (keyof T)[]>(
keys: keyof T extends U[number] ? (U[number] extends keyof T ? U : never) : never,
): U => keys
}