fix(configStore): add type guard for CLI tool type validation

- Add isValidType type guard to ensure type safety
- Validate tool type against allowed values before assignment
- Fixes TypeScript compilation error in build
This commit is contained in:
catlog22
2026-03-08 21:43:43 +08:00
parent 334f82eaad
commit f3ae78f95e

View File

@@ -114,6 +114,10 @@ function extractCliToolsFromBackend(data: unknown): Record<string, CliToolConfig
return null;
}
const validTypes = ['builtin', 'cli-wrapper', 'api-endpoint'] as const;
const isValidType = (t: unknown): t is 'builtin' | 'cli-wrapper' | 'api-endpoint' =>
typeof t === 'string' && (validTypes as readonly string[]).includes(t);
const cliTools: Record<string, CliToolConfig> = {};
for (const [key, tool] of Object.entries(backendTools)) {
const typedTool = tool as Record<string, unknown>;
@@ -122,7 +126,7 @@ function extractCliToolsFromBackend(data: unknown): Record<string, CliToolConfig
primaryModel: typeof typedTool.primaryModel === 'string' ? typedTool.primaryModel : '',
secondaryModel: typeof typedTool.secondaryModel === 'string' ? typedTool.secondaryModel : '',
tags: Array.isArray(typedTool.tags) ? typedTool.tags.filter((tag): tag is string => typeof tag === 'string') : [],
type: typeof typedTool.type === 'string' ? typedTool.type : 'builtin',
type: isValidType(typedTool.type) ? typedTool.type : 'builtin',
envFile: typeof typedTool.envFile === 'string' ? typedTool.envFile : undefined,
settingsFile: typeof typedTool.settingsFile === 'string' ? typedTool.settingsFile : undefined,
availableModels: Array.isArray(typedTool.availableModels)