mirror of
https://github.com/tiennm99/ccs.git
synced 2026-08-24 12:26:07 +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
|
* Example: "flash" → gemini provider with gemini-2.5-flash model
|
||||||
*/
|
*/
|
||||||
export interface CLIProxyVariantConfig {
|
export interface CLIProxyVariantConfig {
|
||||||
/** CLIProxy provider to use (gemini, codex, agy, qwen) */
|
/** CLIProxy provider to use */
|
||||||
provider: 'gemini' | 'codex' | 'agy' | 'qwen';
|
provider: 'gemini' | 'codex' | 'agy' | 'qwen' | 'iflow' | 'kiro' | 'ghcp';
|
||||||
/** Path to settings.json with custom model configuration */
|
/** Path to settings.json with custom model configuration (optional) */
|
||||||
settings: string;
|
settings?: string;
|
||||||
/** Account identifier for multi-account support (optional, defaults to 'default') */
|
/** Account identifier for multi-account support (optional, defaults to 'default') */
|
||||||
account?: string;
|
account?: string;
|
||||||
/** Unique port for variant isolation (8318-8417) */
|
/** Unique port for variant isolation (8318-8417) */
|
||||||
|
|||||||
@@ -121,9 +121,8 @@ export function loadConfigSafe(): Config {
|
|||||||
cliproxy = {};
|
cliproxy = {};
|
||||||
for (const [name, variant] of Object.entries(unifiedConfig.cliproxy.variants)) {
|
for (const [name, variant] of Object.entries(unifiedConfig.cliproxy.variants)) {
|
||||||
cliproxy[name] = {
|
cliproxy[name] = {
|
||||||
// Cast provider - unified has more providers than legacy type
|
provider: variant.provider,
|
||||||
provider: variant.provider as 'gemini' | 'codex' | 'agy' | 'qwen',
|
settings: variant.settings,
|
||||||
settings: variant.settings || '',
|
|
||||||
account: variant.account,
|
account: variant.account,
|
||||||
port: variant.port,
|
port: variant.port,
|
||||||
};
|
};
|
||||||
@@ -145,7 +144,13 @@ export function loadConfigSafe(): Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const raw = fs.readFileSync(configPath, 'utf8');
|
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)) {
|
if (!isConfig(parsed)) {
|
||||||
throw new Error(`Invalid config format: ${configPath}`);
|
throw new Error(`Invalid config format: ${configPath}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user