billion-context 0.1.58 → 0.1.59-pr.295.153

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
@@ -49830,15 +49830,17 @@ function normalizeSseLineEndings(buf) {
49830
49830
  }
49831
49831
 
49832
49832
  // src/loop/tag-echo-filter.ts
49833
- var PAIRED = /\x3cacp\s[^<>]*>([^<>]{0,64})<\/acp>/;
49834
- var LONE = /<\/?acp(?=[\s>])[^<>]*>/;
49833
+ var PAIRED = /\x3cacp\s[^<>]{0,256}>([^<>]{0,64})<\/acp>/;
49834
+ var LONE_OPEN = /\x3cacp(?:\s[^<>]{0,256})?>/;
49835
+ var LONE_CLOSE = /<\/acp(?=[\s>])[^<>]{0,32}>/;
49835
49836
  var PARTIAL_TAIL = /(\x3cacp\s[^<>]*|<\/?a?c?p?)$/;
49836
- var TRUNCATED_TAG = /\x3cacp\s[^<>]*tokens\s*=\s*"[^<>"]*"[^<>]*$/;
49837
+ var TRUNC_OPEN = /\x3cacp\s[^<>]*$/;
49837
49838
  var CLOSE_TAG = "</acp";
49838
49839
  var HOLD_LIMIT = 128;
49840
+ var TAG_OPEN_CAP = 4096;
49839
49841
  var SWALLOW_CAP = 80;
49840
49842
  function stripAcpTags(text) {
49841
- return text.replace(new RegExp(PAIRED.source, "g"), "").replace(new RegExp(LONE.source, "g"), "").replace(new RegExp(TRUNCATED_TAG.source), "");
49843
+ 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), "");
49842
49844
  }
49843
49845
  function containsRenderTagText(s3) {
49844
49846
  return /\x3c\/?acp(?=[\s>])/.test(s3) || /\\u003c\/?acp(?=[\s>\\])/.test(s3);
@@ -49881,15 +49883,26 @@ function createTagEchoFilter(onDrop) {
49881
49883
  return out;
49882
49884
  }
49883
49885
  const p2 = PAIRED.exec(buf);
49884
- const l = LONE.exec(buf);
49885
- let m2;
49886
- if (p2 && l) m2 = p2.index <= l.index ? p2 : l;
49887
- else m2 = p2 ?? l;
49886
+ const o = LONE_OPEN.exec(buf);
49887
+ const c = LONE_CLOSE.exec(buf);
49888
+ let m2 = null;
49889
+ for (const cand of [p2, o, c]) {
49890
+ if (cand && (m2 === null || cand.index < m2.index)) m2 = cand;
49891
+ }
49888
49892
  if (!m2) {
49889
49893
  const t = PARTIAL_TAIL.exec(buf);
49890
- if (t && t[0].length <= HOLD_LIMIT) {
49891
- held = t[0];
49892
- out += buf.slice(0, buf.length - t[0].length);
49894
+ if (t) {
49895
+ const definite = /^\x3cacp\s/.test(t[0]);
49896
+ const cap = definite ? TAG_OPEN_CAP : HOLD_LIMIT;
49897
+ if (t[0].length <= cap) {
49898
+ held = t[0];
49899
+ out += buf.slice(0, buf.length - t[0].length);
49900
+ } else if (definite) {
49901
+ drop(t[0]);
49902
+ out += buf.slice(0, buf.length - t[0].length);
49903
+ } else {
49904
+ out += buf;
49905
+ }
49893
49906
  } else {
49894
49907
  out += buf;
49895
49908
  }
@@ -49898,8 +49911,7 @@ function createTagEchoFilter(onDrop) {
49898
49911
  drop(m2[0]);
49899
49912
  out += buf.slice(0, m2.index);
49900
49913
  buf = buf.slice(m2.index + m2[0].length);
49901
- const wasPaired = m2 === p2;
49902
- if (!wasPaired && /^\x3cacp\s/.test(m2[0])) {
49914
+ if (m2 === o && /^\x3cacp\s/.test(m2[0])) {
49903
49915
  swallowUntilClose = true;
49904
49916
  swallowed = "";
49905
49917
  }
@@ -49913,14 +49925,19 @@ function createTagEchoFilter(onDrop) {
49913
49925
  return process2(chunk);
49914
49926
  },
49915
49927
  flush() {
49916
- let rest = swallowed + held;
49928
+ const rest = swallowed + held;
49929
+ const wasSwallowing = swallowUntilClose;
49917
49930
  swallowed = "";
49918
49931
  held = "";
49919
49932
  swallowUntilClose = false;
49920
- const t = new RegExp(TRUNCATED_TAG.source).exec(rest);
49933
+ if (wasSwallowing) {
49934
+ if (rest.length > 0) drop(rest);
49935
+ return "";
49936
+ }
49937
+ const t = new RegExp(TRUNC_OPEN.source).exec(rest);
49921
49938
  if (t) {
49922
49939
  drop(t[0]);
49923
- rest = rest.slice(0, t.index);
49940
+ return rest.slice(0, t.index);
49924
49941
  }
49925
49942
  return rest;
49926
49943
  },
@@ -50953,11 +50970,13 @@ function usageTotals(protocol, usage) {
50953
50970
  }
50954
50971
  var CONTEXT_OVERFLOW_PATTERNS = [
50955
50972
  /context_length_exceeded/i,
50973
+ /context_window_exceeded/i,
50956
50974
  /context length exceeded/i,
50957
50975
  /maximum context length/i,
50958
50976
  /max context length/i,
50959
50977
  /maximum context size/i,
50960
50978
  /exceeds the context window/i,
50979
+ /out of room in the model/i,
50961
50980
  /exceeded model token limit/i,
50962
50981
  /prompt is too long/i,
50963
50982
  /prompt_too_long/i,
@@ -55865,7 +55884,16 @@ ${hdrText}
55865
55884
  s3.metadata.learnedContextLimits = learnedMap;
55866
55885
  log2("warn", `[${s3.id}] upstream context overflow \u2014 learned real window ${info.window} for ${reqModel ?? "(unknown model)"} (was ${prev ?? "unset"}); arming emergency shrink`);
55867
55886
  } else {
55868
- log2("warn", `[${s3.id}] upstream context overflow (window not parseable): ${info.message}`);
55887
+ const payloadEstimate = estimateCoreMessages(prepared.processedMessages);
55888
+ const prev = (reqModel ? learnedMap[reqModel] : void 0) ?? s3.metadata.learnedContextLimit;
55889
+ if (payloadEstimate >= 1e3 && (prev === void 0 || payloadEstimate < prev)) {
55890
+ if (reqModel) learnedMap[reqModel] = payloadEstimate;
55891
+ else s3.metadata.learnedContextLimit = payloadEstimate;
55892
+ s3.metadata.learnedContextLimits = learnedMap;
55893
+ log2("warn", `[${s3.id}] upstream context overflow (window not parseable) \u2014 learned conservative window ${payloadEstimate} for ${reqModel ?? "(unknown model)"} from rejected payload size (was ${prev ?? "unset"}); arming emergency shrink`);
55894
+ } else {
55895
+ log2("warn", `[${s3.id}] upstream context overflow (window not parseable): ${info.message}`);
55896
+ }
55869
55897
  }
55870
55898
  const floor = info.window ?? (reqModel ? learnedMap[reqModel] : void 0) ?? s3.metadata.learnedContextLimit ?? s3.metadata.effectiveContextLimit ?? 0;
55871
55899
  if (floor > 0) s3.stats.lastInputTokens = Math.max(s3.stats.lastInputTokens, floor);