billion-context 0.1.80 → 0.1.81-pr.507.330

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
@@ -49850,6 +49850,7 @@ var SessionStore = class {
49850
49850
  const byLabel = /* @__PURE__ */ new Map();
49851
49851
  let unlabeled = 0;
49852
49852
  for (const [id, envelope] of loaded) {
49853
+ if (id.startsWith("pfa-")) continue;
49853
49854
  const session = buildSession(envelope.payload);
49854
49855
  const label = session.meta.label;
49855
49856
  if (!label) {
@@ -58007,9 +58008,17 @@ async function preflightCompressIfNeeded(prepared, runPrepare, req, res, opts, c
58007
58008
  const session = prepared.session;
58008
58009
  const limit = config.modelContextLimit;
58009
58010
  const imageTokens = imageTokensInRawBody(prepared.protocol, prepared.body);
58010
- const payloadEstimate = estimateCoreMessages(prepared.processedMessages) + imageTokens;
58011
+ const textEstimate = estimateCoreMessages(prepared.processedMessages);
58012
+ const payloadEstimate = textEstimate + imageTokens;
58011
58013
  const tokenCount = Math.max(session.stats.lastInputTokens, payloadEstimate);
58012
58014
  if (limit <= 0 || !model || tokenCount < limit) return prepared;
58015
+ const learnedMap = session.metadata.learnedContextLimits;
58016
+ const learnedLimit = (model ? learnedMap?.[model] : void 0) ?? session.metadata.learnedContextLimit;
58017
+ const noOverflowEvidence = session.stats.lastInputTokens < limit && learnedLimit === void 0;
58018
+ if (imageTokens > 0 && textEstimate < limit && noOverflowEvidence) {
58019
+ log2("warn", `[${session.id}] image-dominated payload (~${textEstimate} text + ~${imageTokens} image tokens) exceeds window ${limit} by estimate only, no upstream overflow evidence \u2014 forwarding once so the upstream arbitrates billing (#496)`);
58020
+ return prepared;
58021
+ }
58013
58022
  const failFast = (status2, detail, retryable) => {
58014
58023
  const imageNote = imageTokens >= limit ? ` Images alone account for ~${imageTokens} tokens (\u2265 window ${limit}); compression cannot remove them \u2014 shrink or remove the images, or raise the window.` : "";
58015
58024
  const message = `context ~${tokenCount} tokens exceeds the model window ${limit} (model=${model}) and preflight compression could not bring it under: ${detail}.` + imageNote + ` The over-window payload was NOT forwarded.`;