mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 14:16:43 +00:00
fix(cliproxy): handle edge cases in thinking validation
- model-catalog: add null guard and trim for modelId lookup - thinking-validator: add 100 char length limit, accept "8192.0" format - cliproxy-executor: error on empty --thinking= value - use-thinking-config: handle HTML error pages, return cleanup fn
This commit is contained in:
@@ -337,6 +337,13 @@ export async function execClaudeWithCLIProxy(
|
||||
const thinkingEqArg = argsWithoutProxy.find((arg) => arg.startsWith('--thinking='));
|
||||
if (thinkingEqArg) {
|
||||
const val = thinkingEqArg.substring('--thinking='.length);
|
||||
// Handle empty value after equals (--thinking=)
|
||||
if (!val || val.trim() === '') {
|
||||
console.error(fail('--thinking requires a value'));
|
||||
console.error(' Examples: --thinking=low, --thinking=8192, --thinking=off');
|
||||
console.error(' Levels: minimal, low, medium, high, xhigh, auto');
|
||||
process.exit(1);
|
||||
}
|
||||
// Parse as number if numeric, otherwise keep as string (level name)
|
||||
const numVal = parseInt(val, 10);
|
||||
thinkingOverride = !isNaN(numVal) ? numVal : val;
|
||||
|
||||
@@ -188,8 +188,8 @@ export function getProviderCatalog(provider: CLIProxyProvider): ProviderCatalog
|
||||
*/
|
||||
export function findModel(provider: CLIProxyProvider, modelId: string): ModelEntry | undefined {
|
||||
const catalog = MODEL_CATALOG[provider];
|
||||
if (!catalog) return undefined;
|
||||
const normalizedId = modelId.toLowerCase();
|
||||
if (!catalog || !modelId) return undefined;
|
||||
const normalizedId = modelId.trim().toLowerCase();
|
||||
return catalog.models.find((m) => m.id.toLowerCase() === normalizedId);
|
||||
}
|
||||
|
||||
|
||||
@@ -139,6 +139,15 @@ export function validateThinking(
|
||||
): ThinkingValidationResult {
|
||||
const thinking = getModelThinkingSupport(provider, modelId);
|
||||
|
||||
// Handle string length limit to prevent performance issues
|
||||
if (typeof value === 'string' && value.length > 100) {
|
||||
return {
|
||||
valid: false,
|
||||
value: 'off',
|
||||
warning: 'Thinking value too long (max 100 chars). Using "off".',
|
||||
};
|
||||
}
|
||||
|
||||
// Handle empty string explicitly
|
||||
if (typeof value === 'string' && value.trim() === '') {
|
||||
return {
|
||||
@@ -221,7 +230,14 @@ function validateBudgetThinking(
|
||||
} else {
|
||||
// Strict number parsing: reject partial parses like "123abc"
|
||||
const parsed = Number(value);
|
||||
if (isNaN(parsed) || !Number.isFinite(parsed) || value.trim() !== String(parsed)) {
|
||||
const trimmed = value.trim();
|
||||
// Accept trailing .0 for whole numbers (e.g., "8192.0" → 8192)
|
||||
const isWholeWithDecimal = Number.isInteger(parsed) && trimmed === `${parsed}.0`;
|
||||
if (
|
||||
isNaN(parsed) ||
|
||||
!Number.isFinite(parsed) ||
|
||||
(trimmed !== String(parsed) && !isWholeWithDecimal)
|
||||
) {
|
||||
// Not a valid number, try to find closest level
|
||||
const closest = findClosestLevel(value, Object.keys(THINKING_LEVEL_BUDGETS));
|
||||
if (closest) {
|
||||
|
||||
Reference in New Issue
Block a user