From 19e52399fe4a9707dbf2878117d2db09cfa5d467 Mon Sep 17 00:00:00 2001 From: kaitranntt Date: Thu, 8 Jan 2026 15:49:10 -0500 Subject: [PATCH] fix(config): add null guard and document nested paren limitation - Add optional chaining for tier_defaults to prevent crash - Document nested parenthesis matching limitation --- src/cliproxy/config-generator.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cliproxy/config-generator.ts b/src/cliproxy/config-generator.ts index 5ef52cb1..a80e68f1 100644 --- a/src/cliproxy/config-generator.ts +++ b/src/cliproxy/config-generator.ts @@ -54,9 +54,13 @@ export function detectTierFromModel(modelName: string): ModelTier { * @param model - Base model name * @param thinkingValue - Level name (e.g., 'high') or numeric budget * @returns Model name with thinking suffix, e.g., "gemini-3-pro-preview(high)" + * + * @note Paren matching only handles one level. Nested parens like "model(foo)(8192)" + * will be treated as already having suffix and returned unchanged. */ export function applyThinkingSuffix(model: string, thinkingValue: string | number): string { // Don't apply if already has suffix + // NOTE: This only detects ANY paren pair, not proper nesting (e.g., "model(foo)(8192)" passes through) if (model.includes('(') && model.includes(')')) { return model; } @@ -77,8 +81,8 @@ export function getThinkingValueForTier( if (providerOverride) { return providerOverride; } - // Fall back to global tier default - return thinkingConfig.tier_defaults[tier]; + // Fall back to global tier default (with null guard) + return thinkingConfig.tier_defaults?.[tier] ?? 'medium'; } /**