fix(cliproxy): add NaN/Infinity and empty string validation

- Add Number.isFinite() check to reject NaN/Infinity budgets
- Add explicit empty string handling before level validation
This commit is contained in:
kaitranntt
2026-01-08 15:48:39 -05:00
parent 3bd3e379fe
commit 5f8d23c60b
+18
View File
@@ -105,6 +105,15 @@ export function validateThinking(
): ThinkingValidationResult {
const thinking = getModelThinkingSupport(provider, modelId);
// Handle empty string explicitly
if (typeof value === 'string' && value.trim() === '') {
return {
valid: false,
value: 'off',
warning: 'Empty thinking value not allowed. Using "off".',
};
}
// Handle off/none/disabled values
if (typeof value === 'string') {
const normalizedValue = value.toLowerCase().trim();
@@ -198,6 +207,15 @@ function validateBudgetThinking(
budget = value;
}
// Reject NaN/Infinity budgets
if (!Number.isFinite(budget)) {
return {
valid: false,
value: min || THINKING_BUDGET_DEFAULT_MIN,
warning: `Budget must be a finite number. Using minimum ${min || THINKING_BUDGET_DEFAULT_MIN}.`,
};
}
// Reject negative budgets
if (budget < THINKING_BUDGET_MIN) {
return {