Update Roo Code types

This commit is contained in:
cte 2025-03-27 03:08:09 -07:00
parent 02fc724fce
commit 203b0cfee0
2 changed files with 513 additions and 42 deletions

View file

@ -1,12 +1,12 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { z } from "zod"
import { Equals, Keys, AssertEqual } from "./utils.js"
/**
* ProviderName
*/
const providerNames = [
export const providerNames = [
"anthropic",
"glama",
"openrouter",
@ -26,7 +26,9 @@ const providerNames = [
"fake-ai",
] as const
export type ProviderName = (typeof providerNames)[number]
export const providerNamesSchema = z.enum(providerNames)
export type ProviderName = z.infer<typeof providerNamesSchema>
/**
* ToolGroup
@ -34,7 +36,9 @@ export type ProviderName = (typeof providerNames)[number]
export const toolGroups = ["read", "edit", "browser", "command", "mcp", "modes"] as const
export type ToolGroup = (typeof toolGroups)[number]
export const toolGroupsSchema = z.enum(toolGroups)
export type ToolGroup = z.infer<typeof toolGroupsSchema>
/**
* CheckpointStorage
@ -42,13 +46,18 @@ export type ToolGroup = (typeof toolGroups)[number]
export const checkpointStorages = ["task", "workspace"] as const
export type CheckpointStorage = (typeof checkpointStorages)[number]
export const checkpointStoragesSchema = z.enum(checkpointStorages)
export type CheckpointStorage = z.infer<typeof checkpointStoragesSchema>
export const isCheckpointStorage = (value: string): value is CheckpointStorage =>
checkpointStorages.includes(value as CheckpointStorage)
/**
* Language
*/
const languages = [
export const languages = [
"ca",
"de",
"en",
@ -66,7 +75,11 @@ const languages = [
"zh-TW",
] as const
export type Language = (typeof languages)[number]
export const languagesSchema = z.enum(languages)
export type Language = z.infer<typeof languagesSchema>
export const isLanguage = (value: string): value is Language => languages.includes(value as Language)
/**
* TelemetrySetting
@ -74,13 +87,15 @@ export type Language = (typeof languages)[number]
export const telemetrySettings = ["unset", "enabled", "disabled"] as const
export type TelemetrySetting = (typeof telemetrySettings)[number]
export const telemetrySettingsSchema = z.enum(telemetrySettings)
export type TelemetrySetting = z.infer<typeof telemetrySettingsSchema>
/**
* ModelInfo
*/
const modelInfoSchema = z.object({
export const modelInfoSchema = z.object({
maxTokens: z.number().optional(),
contextWindow: z.number(),
supportsImages: z.boolean().optional(),
@ -101,10 +116,10 @@ export type ModelInfo = z.infer<typeof modelInfoSchema>
* ApiConfigMeta
*/
const apiConfigMetaSchema = z.object({
export const apiConfigMetaSchema = z.object({
id: z.string(),
name: z.string(),
apiProvider: z.enum(providerNames).optional(),
apiProvider: providerNamesSchema.optional(),
})
export type ApiConfigMeta = z.infer<typeof apiConfigMetaSchema>
@ -113,7 +128,7 @@ export type ApiConfigMeta = z.infer<typeof apiConfigMetaSchema>
* HistoryItem
*/
const historyItemSchema = z.object({
export const historyItemSchema = z.object({
id: z.string(),
number: z.number(),
ts: z.number(),
@ -128,22 +143,22 @@ const historyItemSchema = z.object({
export type HistoryItem = z.infer<typeof historyItemSchema>
/**
* GroupOptions
*/
export const groupOptionsSchema = z.object({
fileRegex: z.string().optional(),
description: z.string().optional(),
})
export type GroupOptions = z.infer<typeof groupOptionsSchema>
/**
* GroupEntry
*/
const groupEntrySchema = z.union([
z.enum(toolGroups),
z
.tuple([
z.enum(toolGroups),
z.object({
fileRegex: z.string().optional(),
description: z.string().optional(),
}),
])
.readonly(),
])
export const groupEntrySchema = z.union([toolGroupsSchema, z.tuple([toolGroupsSchema, groupOptionsSchema])])
export type GroupEntry = z.infer<typeof groupEntrySchema>
@ -151,21 +166,64 @@ export type GroupEntry = z.infer<typeof groupEntrySchema>
* ModeConfig
*/
const modeConfigSchema = z.object({
export const modeConfigSchema = z.object({
slug: z.string(),
name: z.string(),
roleDefinition: z.string(),
customInstructions: z.string().optional(),
groups: z.array(groupEntrySchema).readonly(),
groups: z.array(groupEntrySchema),
source: z.enum(["global", "project"]).optional(),
})
export type ModeConfig = z.infer<typeof modeConfigSchema>
/**
* PromptComponent
*/
export const promptComponentSchema = z.object({
roleDefinition: z.string().optional(),
customInstructions: z.string().optional(),
})
export type PromptComponent = z.infer<typeof promptComponentSchema>
/**
* CustomModePrompts
*/
export const customModePromptsSchema = z.record(z.string(), promptComponentSchema.optional())
export type CustomModePrompts = z.infer<typeof customModePromptsSchema>
/**
* CustomSupportPrompts
*/
export const customSupportPromptsSchema = z.record(z.string(), z.string().optional())
export type CustomSupportPrompts = z.infer<typeof customSupportPromptsSchema>
/**
* ExperimentId
*/
export const experimentIds = [
"experimentalDiffStrategy",
"search_and_replace",
"insert_content",
"powerSteering",
"multi_search_and_replace",
] as const
export const experimentIdsSchema = z.enum(experimentIds)
export type ExperimentId = z.infer<typeof experimentIdsSchema>
/**
* Experiments
*/
const experimentsSchema = z.object({
experimentalDiffStrategy: z.boolean(),
search_and_replace: z.boolean(),
@ -176,6 +234,187 @@ const experimentsSchema = z.object({
export type Experiments = z.infer<typeof experimentsSchema>
// eslint-disable-next-line @typescript-eslint/no-unused-vars
type _AssertExperiments = AssertEqual<Equals<ExperimentId, Keys<Experiments>>>
/**
* ProviderSettings
*/
export const providerSettingsSchema = z.object({
apiProvider: providerNamesSchema.optional(),
// Anthropic
apiModelId: z.string().optional(),
apiKey: z.string().optional(),
anthropicBaseUrl: z.string().optional(),
// Glama
glamaModelId: z.string().optional(),
glamaModelInfo: modelInfoSchema.optional(),
glamaApiKey: z.string().optional(),
// OpenRouter
openRouterApiKey: z.string().optional(),
openRouterModelId: z.string().optional(),
openRouterModelInfo: modelInfoSchema.optional(),
openRouterBaseUrl: z.string().optional(),
openRouterSpecificProvider: z.string().optional(),
openRouterUseMiddleOutTransform: z.boolean().optional(),
// AWS Bedrock
awsAccessKey: z.string().optional(),
awsSecretKey: z.string().optional(),
awsSessionToken: z.string().optional(),
awsRegion: z.string().optional(),
awsUseCrossRegionInference: z.boolean().optional(),
awsUsePromptCache: z.boolean().optional(),
awspromptCacheId: z.string().optional(),
awsProfile: z.string().optional(),
awsUseProfile: z.boolean().optional(),
awsCustomArn: z.string().optional(),
// Google Vertex
vertexKeyFile: z.string().optional(),
vertexJsonCredentials: z.string().optional(),
vertexProjectId: z.string().optional(),
vertexRegion: z.string().optional(),
// OpenAI
openAiBaseUrl: z.string().optional(),
openAiApiKey: z.string().optional(),
openAiR1FormatEnabled: z.boolean().optional(),
openAiModelId: z.string().optional(),
openAiCustomModelInfo: modelInfoSchema.optional(),
openAiUseAzure: z.boolean().optional(),
azureApiVersion: z.string().optional(),
openAiStreamingEnabled: z.boolean().optional(),
// Ollama
ollamaModelId: z.string().optional(),
ollamaBaseUrl: z.string().optional(),
// VS Code LM
vsCodeLmModelSelector: z
.object({
vendor: z.string().optional(),
family: z.string().optional(),
version: z.string().optional(),
id: z.string().optional(),
})
.optional(),
// LM Studio
lmStudioModelId: z.string().optional(),
lmStudioBaseUrl: z.string().optional(),
lmStudioDraftModelId: z.string().optional(),
lmStudioSpeculativeDecodingEnabled: z.boolean().optional(),
// Gemini
geminiApiKey: z.string().optional(),
googleGeminiBaseUrl: z.string().optional(),
// OpenAI Native
openAiNativeApiKey: z.string().optional(),
// Mistral
mistralApiKey: z.string().optional(),
mistralCodestralUrl: z.string().optional(),
// DeepSeek
deepSeekBaseUrl: z.string().optional(),
deepSeekApiKey: z.string().optional(),
// Unbound
unboundApiKey: z.string().optional(),
unboundModelId: z.string().optional(),
unboundModelInfo: modelInfoSchema.optional(),
// Requesty
requestyApiKey: z.string().optional(),
requestyModelId: z.string().optional(),
requestyModelInfo: modelInfoSchema.optional(),
// Claude 3.7 Sonnet Thinking
modelTemperature: z.number().nullish(),
modelMaxTokens: z.number().optional(),
modelMaxThinkingTokens: z.number().optional(),
// Generic
includeMaxTokens: z.boolean().optional(),
// Fake AI
fakeAi: z.unknown().optional(),
})
export type ProviderSettings = z.infer<typeof providerSettingsSchema>
type ProviderSettingsRecord = Record<Keys<ProviderSettings>, undefined>
const providerSettingsRecord: ProviderSettingsRecord = {
apiProvider: undefined,
// Anthropic
apiModelId: undefined,
apiKey: undefined,
anthropicBaseUrl: undefined,
// Glama
glamaModelId: undefined,
glamaModelInfo: undefined,
glamaApiKey: undefined,
// OpenRouter
openRouterApiKey: undefined,
openRouterModelId: undefined,
openRouterModelInfo: undefined,
openRouterBaseUrl: undefined,
openRouterSpecificProvider: undefined,
openRouterUseMiddleOutTransform: undefined,
// AWS Bedrock
awsAccessKey: undefined,
awsSecretKey: undefined,
awsSessionToken: undefined,
awsRegion: undefined,
awsUseCrossRegionInference: undefined,
awsUsePromptCache: undefined,
awspromptCacheId: undefined,
awsProfile: undefined,
awsUseProfile: undefined,
awsCustomArn: undefined,
// Google Vertex
vertexKeyFile: undefined,
vertexJsonCredentials: undefined,
vertexProjectId: undefined,
vertexRegion: undefined,
// OpenAI
openAiBaseUrl: undefined,
openAiApiKey: undefined,
openAiR1FormatEnabled: undefined,
openAiModelId: undefined,
openAiCustomModelInfo: undefined,
openAiUseAzure: undefined,
azureApiVersion: undefined,
openAiStreamingEnabled: undefined,
// Ollama
ollamaModelId: undefined,
ollamaBaseUrl: undefined,
// VS Code LM
vsCodeLmModelSelector: undefined,
lmStudioModelId: undefined,
lmStudioBaseUrl: undefined,
lmStudioDraftModelId: undefined,
lmStudioSpeculativeDecodingEnabled: undefined,
// Gemini
geminiApiKey: undefined,
googleGeminiBaseUrl: undefined,
// OpenAI Native
openAiNativeApiKey: undefined,
// Mistral
mistralApiKey: undefined,
mistralCodestralUrl: undefined,
// DeepSeek
deepSeekBaseUrl: undefined,
deepSeekApiKey: undefined,
// Unbound
unboundApiKey: undefined,
unboundModelId: undefined,
unboundModelInfo: undefined,
// Requesty
requestyApiKey: undefined,
requestyModelId: undefined,
requestyModelInfo: undefined,
// Claude 3.7 Sonnet Thinking
modelTemperature: undefined,
modelMaxTokens: undefined,
modelMaxThinkingTokens: undefined,
// Generic
includeMaxTokens: undefined,
// Fake AI
fakeAi: undefined,
}
export const PROVIDER_SETTINGS_KEYS = Object.keys(providerSettingsRecord) as Keys<ProviderSettings>[]
/**
* GlobalSettings
*/
@ -211,7 +450,7 @@ export const globalSettingsSchema = z.object({
remoteBrowserHost: z.string().optional(),
enableCheckpoints: z.boolean().optional(),
checkpointStorage: z.enum(checkpointStorages).optional(),
checkpointStorage: checkpointStoragesSchema.optional(),
ttsEnabled: z.boolean().optional(),
ttsSpeed: z.number().optional(),
@ -231,9 +470,9 @@ export const globalSettingsSchema = z.object({
fuzzyMatchThreshold: z.number().optional(),
experiments: experimentsSchema.optional(),
language: z.enum(languages).optional(),
language: languagesSchema.optional(),
telemetrySetting: z.enum(telemetrySettings).optional(),
telemetrySetting: telemetrySettingsSchema.optional(),
mcpEnabled: z.boolean().optional(),
enableMcpServerCreation: z.boolean().optional(),
@ -241,19 +480,244 @@ export const globalSettingsSchema = z.object({
mode: z.string().optional(),
modeApiConfigs: z.record(z.string(), z.string()).optional(),
customModes: z.array(modeConfigSchema).optional(),
customModePrompts: z
.record(
z.string(),
z
.object({
roleDefinition: z.string().optional(),
customInstructions: z.string().optional(),
})
.optional(),
)
.optional(),
customSupportPrompts: z.record(z.string(), z.string().optional()).optional(),
customModePrompts: customModePromptsSchema.optional(),
customSupportPrompts: customSupportPromptsSchema.optional(),
enhancementApiConfigId: z.string().optional(),
})
export type GlobalSettings = z.infer<typeof globalSettingsSchema>
type GlobalSettingsRecord = Record<Keys<GlobalSettings>, undefined>
const globalSettingsRecord: GlobalSettingsRecord = {
currentApiConfigName: undefined,
listApiConfigMeta: undefined,
pinnedApiConfigs: undefined,
lastShownAnnouncementId: undefined,
customInstructions: undefined,
taskHistory: undefined,
autoApprovalEnabled: undefined,
alwaysAllowReadOnly: undefined,
alwaysAllowReadOnlyOutsideWorkspace: undefined,
alwaysAllowWrite: undefined,
alwaysAllowWriteOutsideWorkspace: undefined,
writeDelayMs: undefined,
alwaysAllowBrowser: undefined,
alwaysApproveResubmit: undefined,
requestDelaySeconds: undefined,
alwaysAllowMcp: undefined,
alwaysAllowModeSwitch: undefined,
alwaysAllowSubtasks: undefined,
alwaysAllowExecute: undefined,
allowedCommands: undefined,
browserToolEnabled: undefined,
browserViewportSize: undefined,
screenshotQuality: undefined,
remoteBrowserEnabled: undefined,
remoteBrowserHost: undefined,
enableCheckpoints: undefined,
checkpointStorage: undefined,
ttsEnabled: undefined,
ttsSpeed: undefined,
soundEnabled: undefined,
soundVolume: undefined,
maxOpenTabsContext: undefined,
maxWorkspaceFiles: undefined,
showRooIgnoredFiles: undefined,
maxReadFileLine: undefined,
terminalOutputLineLimit: undefined,
terminalShellIntegrationTimeout: undefined,
rateLimitSeconds: undefined,
diffEnabled: undefined,
fuzzyMatchThreshold: undefined,
experiments: undefined,
language: undefined,
telemetrySetting: undefined,
mcpEnabled: undefined,
enableMcpServerCreation: undefined,
mode: undefined,
modeApiConfigs: undefined,
customModes: undefined,
customModePrompts: undefined,
customSupportPrompts: undefined,
enhancementApiConfigId: undefined,
}
export const GLOBAL_SETTINGS_KEYS = Object.keys(globalSettingsRecord) as Keys<GlobalSettings>[]
/**
* RooCodeSettings
*/
export type RooCodeSettings = GlobalSettings & ProviderSettings
/**
* SecretState
*/
export type SecretState = Pick<
ProviderSettings,
| "apiKey"
| "glamaApiKey"
| "openRouterApiKey"
| "awsAccessKey"
| "awsSecretKey"
| "awsSessionToken"
| "openAiApiKey"
| "geminiApiKey"
| "openAiNativeApiKey"
| "deepSeekApiKey"
| "mistralApiKey"
| "unboundApiKey"
| "requestyApiKey"
>
type SecretStateRecord = Record<Keys<SecretState>, undefined>
const secretStateRecord: SecretStateRecord = {
apiKey: undefined,
glamaApiKey: undefined,
openRouterApiKey: undefined,
awsAccessKey: undefined,
awsSecretKey: undefined,
awsSessionToken: undefined,
openAiApiKey: undefined,
geminiApiKey: undefined,
openAiNativeApiKey: undefined,
deepSeekApiKey: undefined,
mistralApiKey: undefined,
unboundApiKey: undefined,
requestyApiKey: undefined,
}
export const SECRET_STATE_KEYS = Object.keys(secretStateRecord) as Keys<SecretState>[]
export const isSecretStateKey = (key: string): key is Keys<SecretState> =>
SECRET_STATE_KEYS.includes(key as Keys<SecretState>)
/**
* GlobalState
*/
export type GlobalState = Omit<RooCodeSettings, Keys<SecretState>>
export const GLOBAL_STATE_KEYS = [...GLOBAL_SETTINGS_KEYS, ...PROVIDER_SETTINGS_KEYS].filter(
(key: Keys<RooCodeSettings>) => !SECRET_STATE_KEYS.includes(key as Keys<SecretState>),
) as Keys<GlobalState>[]
export const isGlobalStateKey = (key: string): key is Keys<GlobalState> =>
GLOBAL_STATE_KEYS.includes(key as Keys<GlobalState>)
/**
* ClineAsk
*/
export const clineAsks = [
"followup",
"command",
"command_output",
"completion_result",
"tool",
"api_req_failed",
"resume_task",
"resume_completed_task",
"mistake_limit_reached",
"browser_action_launch",
"use_mcp_server",
"finishTask",
] as const
export const clineAskSchema = z.enum(clineAsks)
export type ClineAsk = z.infer<typeof clineAskSchema>
// ClineSay
export const clineSays = [
"task",
"error",
"api_req_started",
"api_req_finished",
"api_req_retried",
"api_req_retry_delayed",
"api_req_deleted",
"text",
"reasoning",
"completion_result",
"user_feedback",
"user_feedback_diff",
"command_output",
"tool",
"shell_integration_warning",
"browser_action",
"browser_action_result",
"command",
"mcp_server_request_started",
"mcp_server_response",
"new_task_started",
"new_task",
"checkpoint_saved",
"rooignore_error",
] as const
export const clineSaySchema = z.enum(clineSays)
export type ClineSay = z.infer<typeof clineSaySchema>
/**
* ToolProgressStatus
*/
export const toolProgressStatusSchema = z.object({
icon: z.string().optional(),
text: z.string().optional(),
})
export type ToolProgressStatus = z.infer<typeof toolProgressStatusSchema>
/**
* ClineMessage
*/
export const clineMessageSchema = z.object({
ts: z.number(),
type: z.union([z.literal("ask"), z.literal("say")]),
ask: clineAskSchema.optional(),
say: clineSaySchema.optional(),
text: z.string().optional(),
images: z.array(z.string()).optional(),
partial: z.boolean().optional(),
reasoning: z.string().optional(),
conversationHistoryIndex: z.number().optional(),
checkpoint: z.record(z.string(), z.unknown()).optional(),
progressStatus: toolProgressStatusSchema.optional(),
})
export type ClineMessage = z.infer<typeof clineMessageSchema>
/**
* TokenUsage
*/
export const tokenUsageSchema = z.object({
totalTokensIn: z.number(),
totalTokensOut: z.number(),
totalCacheWrites: z.number().optional(),
totalCacheReads: z.number().optional(),
totalCost: z.number(),
contextTokens: z.number(),
})
export type TokenUsage = z.infer<typeof tokenUsageSchema>

View file

@ -0,0 +1,7 @@
export type Keys<T> = keyof T
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