fix(compress): accept JSON-string content in parseCompressInput - #176
Conversation
Non-strict-tool providers (e.g. vLLM openai-completions, supportsStrictTools:false) stringify nested array arguments, so the model may send compress.content as a JSON string instead of an array. Previously Array.isArray(obj.content) was false and toRange(obj) returned null, so the call silently parsed 0 ranges and compression never ran. parseCompressInput now JSON.parse's a string content before the array check (invalid JSON -> warn + 0 ranges, no crash), mirroring the fix in billion-context-pi PR #164 (normalizeRanges in src/compress-tool.ts). Adds a regression test for the JSON-string form.
|
LGTM — verified against all five call sites ( One non-blocking note: if |
背景
非严格工具 provider(vLLM openai-completions,
supportsStrictTools:false)会把嵌套数组参数字符串化:模型调用compress时传的content是 JSON 字符串而非数组。此前
parseCompressInput里Array.isArray(obj.content)为 false → 走toRange(obj)(顶层无 startId/endId/summary)→ null → 静默解析出 0 个 range,压缩从不执行(只有一条 warn 日志,无任何报错)。改动
src/compress-tool.ts的parseCompressInput在数组判断前,若content是字符串则先JSON.parse(非法 JSON → warn + 0 ranges,不崩溃)。与 billion-context-pi PR #164(normalizeRanges)对称。tests/basic.test.ts增加 JSON 字符串形式的回归测试。验证
npm run typecheck(tsc --noEmit --project tsconfig.build.json):cleannpm test:464 pass / 0 fail不合并,等 review。