Skip to content

Commit ba44e63

Browse files
committed
Avoid type system duplication
1 parent 15e3d6f commit ba44e63

File tree

3 files changed

+6
-226
lines changed

3 files changed

+6
-226
lines changed

packages/types/src/global-settings.ts

Lines changed: 5 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { z } from "zod"
22

3-
import { type Keys, keysOf } from "./type-fu.js"
3+
import { type Keys } from "./type-fu.js"
44
import {
55
type ProviderSettings,
66
PROVIDER_SETTINGS_KEYS,
@@ -106,89 +106,7 @@ export const globalSettingsSchema = z.object({
106106

107107
export type GlobalSettings = z.infer<typeof globalSettingsSchema>
108108

109-
export const GLOBAL_SETTINGS_KEYS = keysOf<GlobalSettings>()([
110-
"currentApiConfigName",
111-
"listApiConfigMeta",
112-
"pinnedApiConfigs",
113-
114-
"lastShownAnnouncementId",
115-
"customInstructions",
116-
"taskHistory",
117-
118-
"condensingApiConfigId",
119-
"customCondensingPrompt",
120-
121-
"autoApprovalEnabled",
122-
"alwaysAllowReadOnly",
123-
"alwaysAllowReadOnlyOutsideWorkspace",
124-
"alwaysAllowWrite",
125-
"alwaysAllowWriteOutsideWorkspace",
126-
"writeDelayMs",
127-
"alwaysAllowBrowser",
128-
"alwaysApproveResubmit",
129-
"requestDelaySeconds",
130-
"alwaysAllowMcp",
131-
"alwaysAllowModeSwitch",
132-
"alwaysAllowSubtasks",
133-
"alwaysAllowExecute",
134-
"allowedCommands",
135-
"allowedMaxRequests",
136-
"autoCondenseContext",
137-
"autoCondenseContextPercent",
138-
"maxConcurrentFileReads",
139-
140-
"browserToolEnabled",
141-
"browserViewportSize",
142-
"screenshotQuality",
143-
"remoteBrowserEnabled",
144-
"remoteBrowserHost",
145-
146-
"enableCheckpoints",
147-
148-
"ttsEnabled",
149-
"ttsSpeed",
150-
"soundEnabled",
151-
"soundVolume",
152-
153-
"maxOpenTabsContext",
154-
"maxWorkspaceFiles",
155-
"showRooIgnoredFiles",
156-
"maxReadFileLine",
157-
158-
"terminalOutputLineLimit",
159-
"terminalShellIntegrationTimeout",
160-
"terminalShellIntegrationDisabled",
161-
"terminalCommandDelay",
162-
"terminalPowershellCounter",
163-
"terminalZshClearEolMark",
164-
"terminalZshOhMy",
165-
"terminalZshP10k",
166-
"terminalZdotdir",
167-
"terminalCompressProgressBar",
168-
169-
"rateLimitSeconds",
170-
"diffEnabled",
171-
"fuzzyMatchThreshold",
172-
"experiments",
173-
174-
"codebaseIndexModels",
175-
"codebaseIndexConfig",
176-
177-
"language",
178-
179-
"telemetrySetting",
180-
"mcpEnabled",
181-
"enableMcpServerCreation",
182-
183-
"mode",
184-
"modeApiConfigs",
185-
"customModes",
186-
"customModePrompts",
187-
"customSupportPrompts",
188-
"enhancementApiConfigId",
189-
"cachedChromeHostUrl",
190-
"historyPreviewCollapsed",
191-
])
109+
export const GLOBAL_SETTINGS_KEYS = globalSettingsSchema.keyof().options
192110

193111
/**
194112
* RooCodeSettings
@@ -201,32 +119,7 @@ export type RooCodeSettings = GlobalSettings & ProviderSettings
201119
/**
202120
* SecretState
203121
*/
204-
205-
export type SecretState = Pick<
206-
ProviderSettings,
207-
| "apiKey"
208-
| "glamaApiKey"
209-
| "openRouterApiKey"
210-
| "awsAccessKey"
211-
| "awsSecretKey"
212-
| "awsSessionToken"
213-
| "openAiApiKey"
214-
| "geminiApiKey"
215-
| "openAiNativeApiKey"
216-
| "deepSeekApiKey"
217-
| "mistralApiKey"
218-
| "unboundApiKey"
219-
| "requestyApiKey"
220-
| "xaiApiKey"
221-
| "groqApiKey"
222-
| "chutesApiKey"
223-
| "litellmApiKey"
224-
| "codeIndexOpenAiKey"
225-
| "codeIndexQdrantApiKey"
226-
| "codebaseIndexOpenAiCompatibleApiKey"
227-
>
228-
229-
export const SECRET_STATE_KEYS = keysOf<SecretState>()([
122+
export const SECRET_STATE_KEYS = [
230123
"apiKey",
231124
"glamaApiKey",
232125
"openRouterApiKey",
@@ -247,7 +140,8 @@ export const SECRET_STATE_KEYS = keysOf<SecretState>()([
247140
"codeIndexOpenAiKey",
248141
"codeIndexQdrantApiKey",
249142
"codebaseIndexOpenAiCompatibleApiKey",
250-
])
143+
] as const satisfies readonly (keyof ProviderSettings)[]
144+
export type SecretState = Pick<ProviderSettings, (typeof SECRET_STATE_KEYS)[number]>
251145

252146
export const isSecretStateKey = (key: string): key is Keys<SecretState> =>
253147
SECRET_STATE_KEYS.includes(key as Keys<SecretState>)

packages/types/src/provider-settings.ts

Lines changed: 1 addition & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { z } from "zod"
22

3-
import { keysOf } from "./type-fu.js"
43
import { reasoningEffortsSchema, modelInfoSchema } from "./model.js"
54
import { codebaseIndexProviderSchema } from "./codebase-index.js"
65

@@ -259,110 +258,7 @@ export const providerSettingsSchema = z.object({
259258
})
260259

261260
export type ProviderSettings = z.infer<typeof providerSettingsSchema>
262-
263-
export const PROVIDER_SETTINGS_KEYS = keysOf<ProviderSettings>()([
264-
"apiProvider",
265-
// Anthropic
266-
"apiModelId",
267-
"apiKey",
268-
"anthropicBaseUrl",
269-
"anthropicUseAuthToken",
270-
// Glama
271-
"glamaModelId",
272-
"glamaApiKey",
273-
// OpenRouter
274-
"openRouterApiKey",
275-
"openRouterModelId",
276-
"openRouterBaseUrl",
277-
"openRouterSpecificProvider",
278-
"openRouterUseMiddleOutTransform",
279-
// Amazon Bedrock
280-
"awsAccessKey",
281-
"awsSecretKey",
282-
"awsSessionToken",
283-
"awsRegion",
284-
"awsUseCrossRegionInference",
285-
"awsUsePromptCache",
286-
"awsProfile",
287-
"awsUseProfile",
288-
"awsCustomArn",
289-
"awsModelContextWindow",
290-
"awsBedrockEndpointEnabled",
291-
"awsBedrockEndpoint",
292-
// Google Vertex
293-
"vertexKeyFile",
294-
"vertexJsonCredentials",
295-
"vertexProjectId",
296-
"vertexRegion",
297-
// OpenAI
298-
"openAiBaseUrl",
299-
"openAiApiKey",
300-
"openAiLegacyFormat",
301-
"openAiR1FormatEnabled",
302-
"openAiModelId",
303-
"openAiCustomModelInfo",
304-
"openAiUseAzure",
305-
"azureApiVersion",
306-
"openAiStreamingEnabled",
307-
"openAiHostHeader", // Keep temporarily for backward compatibility during migration.
308-
"openAiHeaders",
309-
// Ollama
310-
"ollamaModelId",
311-
"ollamaBaseUrl",
312-
// VS Code LM
313-
"vsCodeLmModelSelector",
314-
"lmStudioModelId",
315-
"lmStudioBaseUrl",
316-
"lmStudioDraftModelId",
317-
"lmStudioSpeculativeDecodingEnabled",
318-
// Gemini
319-
"geminiApiKey",
320-
"googleGeminiBaseUrl",
321-
// OpenAI Native
322-
"openAiNativeApiKey",
323-
"openAiNativeBaseUrl",
324-
// Mistral
325-
"mistralApiKey",
326-
"mistralCodestralUrl",
327-
// DeepSeek
328-
"deepSeekBaseUrl",
329-
"deepSeekApiKey",
330-
// Unbound
331-
"unboundApiKey",
332-
"unboundModelId",
333-
// Requesty
334-
"requestyApiKey",
335-
"requestyModelId",
336-
// Code Index
337-
"codeIndexOpenAiKey",
338-
"codeIndexQdrantApiKey",
339-
"codebaseIndexOpenAiCompatibleBaseUrl",
340-
"codebaseIndexOpenAiCompatibleApiKey",
341-
"codebaseIndexOpenAiCompatibleModelDimension",
342-
// Reasoning
343-
"enableReasoningEffort",
344-
"reasoningEffort",
345-
"modelMaxTokens",
346-
"modelMaxThinkingTokens",
347-
// Generic
348-
"includeMaxTokens",
349-
"diffEnabled",
350-
"fuzzyMatchThreshold",
351-
"modelTemperature",
352-
"rateLimitSeconds",
353-
// Fake AI
354-
"fakeAi",
355-
// X.AI (Grok)
356-
"xaiApiKey",
357-
// Groq
358-
"groqApiKey",
359-
// Chutes AI
360-
"chutesApiKey",
361-
// LiteLLM
362-
"litellmBaseUrl",
363-
"litellmApiKey",
364-
"litellmModelId",
365-
])
261+
export const PROVIDER_SETTINGS_KEYS = providerSettingsSchema.keyof().options
366262

367263
export const MODEL_ID_KEYS: Partial<keyof ProviderSettings>[] = [
368264
"apiModelId",

packages/types/src/type-fu.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,3 @@ export type Values<T> = T[keyof T]
99
export type Equals<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false
1010

1111
export type AssertEqual<T extends true> = T
12-
13-
/**
14-
* Creates a type-safe keys array that enforces ALL keys from type T are present.
15-
* Returns a compile-time error if any keys are missing or extra keys are provided.
16-
*/
17-
export function keysOf<T>() {
18-
return <const U extends readonly (keyof T)[]>(
19-
keys: keyof T extends U[number] ? (U[number] extends keyof T ? U : never) : never,
20-
): U => keys
21-
}

0 commit comments

Comments
 (0)