billion-context 0.1.65-pr.366.215 → 0.1.65-pr.370.220

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -50005,8 +50005,7 @@ async function flushAllSessions() {
50005
50005
  function parseCompressInput(input, callId) {
50006
50006
  const { ranges, diagnostics } = parseCompressArgs(input, { callId });
50007
50007
  if (!diagnostics.ok && diagnostics.kind !== "ok") {
50008
- const category = diagnostics.kind === "missing-content" || diagnostics.kind === "empty-input" ? "empty-call" : diagnostics.kind === "malformed-json" || diagnostics.kind === "truncated" ? "stream-concat" : "validation";
50009
- log("warn", `[acp-compress-input] rejected: category=${category} kind=${diagnostics.kind} invalidItems=${diagnostics.invalidItems}${diagnostics.keys ? ` keys=[${diagnostics.keys.join(",")}]` : ""}${diagnostics.length !== void 0 ? ` len=${diagnostics.length}` : ""}${callId ? ` callId=${callId}` : ""}`);
50008
+ log("warn", `[acp-compress-input] rejected: kind=${diagnostics.kind} invalidItems=${diagnostics.invalidItems}${diagnostics.keys ? ` keys=[${diagnostics.keys.join(",")}]` : ""}${diagnostics.length !== void 0 ? ` len=${diagnostics.length}` : ""}`);
50010
50009
  }
50011
50010
  return ranges;
50012
50011
  }
@@ -50104,17 +50103,23 @@ function normalizeSseLineEndings(buf) {
50104
50103
  var PAIRED = /\x3cacp\s[^<>]{0,256}>([^<>]{0,64})<\/acp>/;
50105
50104
  var LONE_OPEN = /\x3cacp(?:\s[^<>]{0,256})?>/;
50106
50105
  var LONE_CLOSE = /<\/acp(?=[\s>])[^<>]{0,32}>/;
50107
- var PARTIAL_TAIL = /(\x3cacp\s[^<>]*|<\/?a?c?p?)$/;
50106
+ var PARTIAL_TAIL = /(\x3cacp\s[^<>]*|\x3c\/acp(?:\s[^<>]*)?|<\/?a?c?p?)$/;
50108
50107
  var TRUNC_OPEN = /\x3cacp\s[^<>]*$/;
50108
+ var TRUNC_CLOSE = /\x3c\/acp(?:\s[^<>]*)?$/;
50109
50109
  var CLOSE_TAG = "</acp";
50110
50110
  var HOLD_LIMIT = 128;
50111
50111
  var TAG_OPEN_CAP = 4096;
50112
50112
  var SWALLOW_CAP = 80;
50113
50113
  function stripAcpTags(text) {
50114
- return text.replace(new RegExp(PAIRED.source, "g"), "").replace(new RegExp(LONE_OPEN.source, "g"), "").replace(new RegExp(LONE_CLOSE.source, "g"), "").replace(new RegExp(TRUNC_OPEN.source), "");
50114
+ return text.replace(new RegExp(PAIRED.source, "g"), "").replace(new RegExp(LONE_OPEN.source, "g"), "").replace(new RegExp(LONE_CLOSE.source, "g"), "").replace(new RegExp(TRUNC_OPEN.source), "").replace(new RegExp(TRUNC_CLOSE.source), "");
50115
50115
  }
50116
+ var RENDER_TAG_DETECT = /\x3c\/?acp(?=[\s>])|\\u003c\/?acp(?=[\s>\\])/;
50116
50117
  function containsRenderTagText(s3) {
50117
- return /\x3c\/?acp(?=[\s>])/.test(s3) || /\\u003c\/?acp(?=[\s>\\])/.test(s3);
50118
+ return RENDER_TAG_DETECT.test(s3);
50119
+ }
50120
+ var TOOL_CALL_XML = /\x3c\/?(?:antml:)?(invoke|tool_calls|tool_call|parameter|parameters)\b[^<>]*\x3e|\\u003c\/?(?:antml:)?(invoke|tool_calls|tool_call|parameter|parameters)\b|\x3c\/?antml:[a-z_]+/i;
50121
+ function containsToolCallXmlFragment(s3) {
50122
+ return TOOL_CALL_XML.test(s3);
50118
50123
  }
50119
50124
  function createTagEchoFilter(onDrop) {
50120
50125
  let held = "";
@@ -50163,7 +50168,7 @@ function createTagEchoFilter(onDrop) {
50163
50168
  if (!m2) {
50164
50169
  const t = PARTIAL_TAIL.exec(buf);
50165
50170
  if (t) {
50166
- const definite = /^\x3cacp\s/.test(t[0]);
50171
+ const definite = /^\x3cacp\s/.test(t[0]) || /^\x3c\/acp/.test(t[0]);
50167
50172
  const cap = definite ? TAG_OPEN_CAP : HOLD_LIMIT;
50168
50173
  if (t[0].length <= cap) {
50169
50174
  held = t[0];
@@ -50210,6 +50215,11 @@ function createTagEchoFilter(onDrop) {
50210
50215
  drop(t[0]);
50211
50216
  return rest.slice(0, t.index);
50212
50217
  }
50218
+ const tc = new RegExp(TRUNC_CLOSE.source).exec(rest);
50219
+ if (tc) {
50220
+ drop(tc[0]);
50221
+ return rest.slice(0, tc.index);
50222
+ }
50213
50223
  return rest;
50214
50224
  },
50215
50225
  dropped() {
@@ -51074,6 +51084,23 @@ function isLoopThinking(m2) {
51074
51084
  function stripLoopThinking(messages) {
51075
51085
  return messages.filter((m2) => !isLoopThinking(m2));
51076
51086
  }
51087
+ function canonicalArgs(args) {
51088
+ try {
51089
+ return JSON.stringify(sortKeys(JSON.parse(args)));
51090
+ } catch {
51091
+ return args;
51092
+ }
51093
+ }
51094
+ function sortKeys(v2) {
51095
+ if (Array.isArray(v2)) return v2.map(sortKeys);
51096
+ if (v2 !== null && typeof v2 === "object") {
51097
+ const src = v2;
51098
+ const out = {};
51099
+ for (const k2 of Object.keys(src).sort()) out[k2] = sortKeys(src[k2]);
51100
+ return out;
51101
+ }
51102
+ return v2;
51103
+ }
51077
51104
  function executeProxyTool(toolName, args, ctx, callId) {
51078
51105
  if (toolName === "compress") {
51079
51106
  return applyRanges(parseCompressInput(args, callId), ctx);
@@ -51148,6 +51175,7 @@ async function* runCompressLoop(upstream, ctx, requestBody, requestOptions, adap
51148
51175
  let currentUpstream = upstream;
51149
51176
  const coreMessages = [...ctx.messages];
51150
51177
  let degradedRetried = false;
51178
+ const failedSignatures = /* @__PURE__ */ new Set();
51151
51179
  try {
51152
51180
  for (let round = 1; round <= MAX_LOOP_ROUNDS; round++) {
51153
51181
  if (signal?.aborted) break;
@@ -51338,6 +51366,19 @@ async function* runCompressLoop(upstream, ctx, requestBody, requestOptions, adap
51338
51366
  yield adapter.emitCompletion({ finishReason: "length", usage });
51339
51367
  return;
51340
51368
  }
51369
+ const failedMutating = proxyResults.filter(
51370
+ (pr2) => (pr2.name === "compress" || pr2.name === "decompress") && pr2.result.includes("FAILED")
51371
+ );
51372
+ if (reRequest && failedMutating.length > 0 && failedMutating.length === proxyResults.length) {
51373
+ const repeated = failedMutating.some((pr2) => failedSignatures.has(`${pr2.name}\0${canonicalArgs(pr2.arguments)}`));
51374
+ if (repeated) {
51375
+ ctx.log(`[acp-loop] round ${round}: model re-submitted an already-failed compress with identical arguments; stopping after ${round} round(s) instead of ${MAX_LOOP_ROUNDS}`);
51376
+ log("warn", `[acp-loop] repeated identical compress failure at round ${round}; breaking early (#156)`);
51377
+ yield adapter.emitCompletion({ finishReason: "length", usage });
51378
+ return;
51379
+ }
51380
+ }
51381
+ for (const pr2 of failedMutating) failedSignatures.add(`${pr2.name}\0${canonicalArgs(pr2.arguments)}`);
51341
51382
  ctx.log(`[acp-loop] round ${round}: proxy tool executed; re-requesting so the model sees the result`);
51342
51383
  if (signal?.aborted) break;
51343
51384
  const fetchUpstream = (body) => fetchWithRetry(
@@ -53215,14 +53256,14 @@ var MIN_TAIL_MATCH = 3;
53215
53256
  var MAX_STORED_ITEMS = 128;
53216
53257
  var MIN_FORK_PREFIX = 3;
53217
53258
  function stableStringify(value) {
53218
- return JSON.stringify(sortKeys(value));
53259
+ return JSON.stringify(sortKeys2(value));
53219
53260
  }
53220
- function sortKeys(value) {
53221
- if (Array.isArray(value)) return value.map(sortKeys);
53261
+ function sortKeys2(value) {
53262
+ if (Array.isArray(value)) return value.map(sortKeys2);
53222
53263
  if (value && typeof value === "object") {
53223
53264
  const record = value;
53224
53265
  const out = {};
53225
- for (const key of Object.keys(record).sort()) out[key] = sortKeys(record[key]);
53266
+ for (const key of Object.keys(record).sort()) out[key] = sortKeys2(record[key]);
53226
53267
  return out;
53227
53268
  }
53228
53269
  return value;
@@ -55421,6 +55462,28 @@ async function decodeRequestBody(contentEncoding, input, maxOutputBytes) {
55421
55462
  function bodyDumpEnabled() {
55422
55463
  return process.env.ACP_DUMP_BODY === "1";
55423
55464
  }
55465
+ var dumpFailCount = 0;
55466
+ var lastDumpFailLog = 0;
55467
+ function logDumpFailure(where, err2) {
55468
+ dumpFailCount++;
55469
+ const now = Date.now();
55470
+ if (dumpFailCount === 1 || now - lastDumpFailLog >= 6e4) {
55471
+ lastDumpFailLog = now;
55472
+ const msg = err2 instanceof Error ? err2.message : String(err2);
55473
+ log("warn", `[dump] ${where} failed (total ${dumpFailCount}x): ${msg}`);
55474
+ }
55475
+ }
55476
+ var unrecognizedPathCounts = /* @__PURE__ */ new Map();
55477
+ function logUnrecognizedPath(log2, url) {
55478
+ const key = maskUrlsInText(url.split("?")[0]);
55479
+ const n = (unrecognizedPathCounts.get(key) ?? 0) + 1;
55480
+ unrecognizedPathCounts.set(key, n);
55481
+ if (n <= 3) {
55482
+ log2("warn", `unrecognized path ${key} \u2014 not a known protocol (/chat/completions, /v1/messages, /responses, /responses/compact); forwarding unchanged`);
55483
+ } else if (n === 4) {
55484
+ log2("info", `unrecognized path ${key}: forwarding unchanged; further occurrences suppressed`);
55485
+ }
55486
+ }
55424
55487
  var BILI_HOP_HEADER = "x-bili-hop";
55425
55488
  function parseLauncherModelWindows(raw) {
55426
55489
  if (!raw) return {};
@@ -55868,7 +55931,8 @@ async function handle(req, res, opts, core, config, log2, instanceId) {
55868
55931
  ${hdrText}
55869
55932
 
55870
55933
  ${bodyBuffer.toString("utf8")}`);
55871
- } catch {
55934
+ } catch (err2) {
55935
+ logDumpFailure("INCOMING dump", err2);
55872
55936
  }
55873
55937
  }
55874
55938
  let reqConfig = config;
@@ -56073,7 +56137,7 @@ ${bodyBuffer.toString("utf8")}`);
56073
56137
  }
56074
56138
  if (!prepared) {
56075
56139
  if (protocol === null && !opts.passthrough) {
56076
- log2("warn", `unrecognized path ${maskUrlsInText(req.url ?? "")} \u2014 not a known protocol (/chat/completions, /v1/messages, /responses, /responses/compact); forwarding unchanged`);
56140
+ logUnrecognizedPath(log2, req.url ?? "");
56077
56141
  }
56078
56142
  await forward(req, res, opts, bodyBuffer, null, core, reqConfig, log2, route, instanceId, void 0);
56079
56143
  }
@@ -56698,7 +56762,8 @@ ${hdrText}
56698
56762
 
56699
56763
  ${bodyText}`);
56700
56764
  log2("info", `[debug] RAW request dump: ${reqPath}`);
56701
- } catch {
56765
+ } catch (err2) {
56766
+ logDumpFailure("REQ dump", err2);
56702
56767
  }
56703
56768
  }
56704
56769
  const dispatcher = proxyDispatcher(proxyUrl);
@@ -56746,7 +56811,8 @@ ${bodyText}`);
56746
56811
  ${hdrText}
56747
56812
  `);
56748
56813
  log2("info", `[debug] RAW response dump: ${resPath}`);
56749
- } catch {
56814
+ } catch (err2) {
56815
+ logDumpFailure("RES dump", err2);
56750
56816
  }
56751
56817
  }
56752
56818
  if (!upstream.ok) {
@@ -56882,12 +56948,16 @@ ${hdrText}
56882
56948
  systemPrompt,
56883
56949
  clientAbort.signal
56884
56950
  );
56951
+ let protocolFragmentWarned = false;
56885
56952
  for await (const chunk of loop) {
56886
56953
  if (res.destroyed || res.writableEnded) break;
56887
56954
  {
56888
56955
  const s3 = chunk.toString("utf8");
56889
56956
  if (s3.includes("<acp ") || s3.includes("</acp")) {
56890
56957
  log2("warn", `[${prepared.session.id}] tag echo: ${prepared.protocol} response stream contains <acp tag`);
56958
+ } else if (!protocolFragmentWarned && containsToolCallXmlFragment(s3)) {
56959
+ protocolFragmentWarned = true;
56960
+ log2("warn", `[${prepared.session.id}] tag echo: ${prepared.protocol} response stream contains tool-call XML fragment (possible tag echo; not stripped)`);
56891
56961
  }
56892
56962
  }
56893
56963
  res.write(chunk);
@@ -56995,7 +57065,7 @@ async function dumpStreamToFile(stream2, dir, name) {
56995
57065
  mkdirSync6(dir, { recursive: true });
56996
57066
  const ws2 = createWriteStream2(join4(dir, name));
56997
57067
  ws2.on("error", (e) => {
56998
- log("debug", `[dump] write stream error: ${e.message ?? e}`);
57068
+ logDumpFailure("SSE stream dump", e);
56999
57069
  });
57000
57070
  const reader = stream2.getReader();
57001
57071
  try {
@@ -57008,7 +57078,8 @@ async function dumpStreamToFile(stream2, dir, name) {
57008
57078
  reader.releaseLock();
57009
57079
  ws2.end();
57010
57080
  }
57011
- } catch {
57081
+ } catch (err2) {
57082
+ logDumpFailure("SSE stream dump", err2);
57012
57083
  }
57013
57084
  }
57014
57085
  function deriveTitle(messages) {