mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 06:16:37 +00:00
fix: improve type safety and error handling in config-manager
- Wrap JSON.parse in try-catch with clear error message for malformed JSON - Add iflow, kiro, ghcp providers to CLIProxyVariantConfig type - Make settings optional in CLIProxyVariantConfig (was required with empty string fallback) - Remove unsafe type cast in loadConfigSafe() Addresses additional edge cases from PR #215 code review.
This commit is contained in:
+4
-4
@@ -17,10 +17,10 @@ export interface ProfilesConfig {
|
||||
* Example: "flash" → gemini provider with gemini-2.5-flash model
|
||||
*/
|
||||
export interface CLIProxyVariantConfig {
|
||||
/** CLIProxy provider to use (gemini, codex, agy, qwen) */
|
||||
provider: 'gemini' | 'codex' | 'agy' | 'qwen';
|
||||
/** Path to settings.json with custom model configuration */
|
||||
settings: string;
|
||||
/** CLIProxy provider to use */
|
||||
provider: 'gemini' | 'codex' | 'agy' | 'qwen' | 'iflow' | 'kiro' | 'ghcp';
|
||||
/** Path to settings.json with custom model configuration (optional) */
|
||||
settings?: string;
|
||||
/** Account identifier for multi-account support (optional, defaults to 'default') */
|
||||
account?: string;
|
||||
/** Unique port for variant isolation (8318-8417) */
|
||||
|
||||
@@ -121,9 +121,8 @@ export function loadConfigSafe(): Config {
|
||||
cliproxy = {};
|
||||
for (const [name, variant] of Object.entries(unifiedConfig.cliproxy.variants)) {
|
||||
cliproxy[name] = {
|
||||
// Cast provider - unified has more providers than legacy type
|
||||
provider: variant.provider as 'gemini' | 'codex' | 'agy' | 'qwen',
|
||||
settings: variant.settings || '',
|
||||
provider: variant.provider,
|
||||
settings: variant.settings,
|
||||
account: variant.account,
|
||||
port: variant.port,
|
||||
};
|
||||
@@ -145,7 +144,13 @@ export function loadConfigSafe(): Config {
|
||||
}
|
||||
|
||||
const raw = fs.readFileSync(configPath, 'utf8');
|
||||
const parsed: unknown = JSON.parse(raw);
|
||||
|
||||
let parsed: unknown;
|
||||
try {
|
||||
parsed = JSON.parse(raw);
|
||||
} catch (e) {
|
||||
throw new Error(`Malformed JSON in config: ${configPath} - ${(e as Error).message}`);
|
||||
}
|
||||
|
||||
if (!isConfig(parsed)) {
|
||||
throw new Error(`Invalid config format: ${configPath}`);
|
||||
|
||||
Reference in New Issue
Block a user