billion-context 0.1.75-pr.335.313 → 0.1.75-pr.424.312

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
@@ -48328,33 +48328,64 @@ async function contextFromRegistry(model, host) {
48328
48328
  function peekRegistryContext(model, host) {
48329
48329
  return registryLookup(cache2, model, host);
48330
48330
  }
48331
+ var VARIANT_SUFFIXES = [
48332
+ "-interleaved-thinking",
48333
+ "-thinking",
48334
+ "-reasoning",
48335
+ "-extended",
48336
+ "-fast",
48337
+ "-high",
48338
+ "-medium",
48339
+ "-low"
48340
+ ];
48341
+ function modelVariants(name) {
48342
+ const variants = [name];
48343
+ let current = name;
48344
+ for (; ; ) {
48345
+ let stripped = false;
48346
+ for (const suffix of VARIANT_SUFFIXES) {
48347
+ if (current.length > suffix.length && current.endsWith(suffix)) {
48348
+ current = current.slice(0, -suffix.length);
48349
+ variants.push(current);
48350
+ stripped = true;
48351
+ break;
48352
+ }
48353
+ }
48354
+ if (!stripped) break;
48355
+ }
48356
+ return variants;
48357
+ }
48331
48358
  function registryLookup(reg, model, host) {
48332
48359
  if (!reg || !model) return void 0;
48333
48360
  const provider = host ? providerFromHost(host) : void 0;
48334
- const candidates = provider ? [`${provider}/${model}`, model] : [model];
48335
- for (const key of candidates) {
48336
- const entry = reg[key];
48337
- const ctx = entry?.limit?.context;
48338
- if (typeof ctx === "number" && ctx > 0) return ctx;
48339
- }
48340
- if (provider === void 0) {
48341
- const suffix = `/${model}`;
48342
- let max;
48343
- const distinct = /* @__PURE__ */ new Set();
48344
- const parts = [];
48345
- for (const key of Object.keys(reg)) {
48346
- if (!key.endsWith(suffix)) continue;
48347
- const ctx = reg[key].limit?.context;
48348
- if (typeof ctx !== "number" || ctx <= 0) continue;
48349
- if (max === void 0 || ctx > max) max = ctx;
48350
- distinct.add(ctx);
48351
- parts.push(`${key}=${ctx}`);
48352
- }
48353
- if (max !== void 0 && distinct.size > 1 && !warnedConflicts.has(model)) {
48354
- warnedConflicts.add(model);
48355
- log("warn", `[acp-registry] conflicting context windows for "${model}" (${parts.join(", ")}) \u2014 using max ${max}`);
48361
+ for (const name of modelVariants(model)) {
48362
+ const candidates = provider ? [`${provider}/${name}`, name] : [name];
48363
+ for (const key of candidates) {
48364
+ const entry = reg[key];
48365
+ const ctx = entry?.limit?.context;
48366
+ if (typeof ctx === "number" && ctx > 0) return ctx;
48367
+ }
48368
+ if (provider === void 0) {
48369
+ const suffix = `/${name}`;
48370
+ let max;
48371
+ const distinct = /* @__PURE__ */ new Set();
48372
+ const parts = [];
48373
+ for (const key of Object.keys(reg)) {
48374
+ if (!key.endsWith(suffix)) continue;
48375
+ const ctx = reg[key].limit?.context;
48376
+ if (typeof ctx !== "number" || ctx <= 0) continue;
48377
+ if (max === void 0 || ctx > max) max = ctx;
48378
+ distinct.add(ctx);
48379
+ parts.push(`${key}=${ctx}`);
48380
+ }
48381
+ if (max !== void 0) {
48382
+ if (distinct.size > 1 && !warnedConflicts.has(name)) {
48383
+ warnedConflicts.add(name);
48384
+ log("warn", `[acp-registry] conflicting context windows for "${name}" (${parts.join(", ")}) \u2014 using max ${max}`);
48385
+ }
48386
+ return max;
48387
+ }
48356
48388
  }
48357
- return max;
48358
48389
  }
48359
48390
  return void 0;
48360
48391
  }
@@ -48479,14 +48510,11 @@ ${summary}` }]
48479
48510
  }
48480
48511
  return { items, replaced, dropped };
48481
48512
  }
48482
- function codexCompactGatePre(session, effectiveLimit) {
48483
- if (effectiveLimit <= 0) return false;
48513
+ function codexCompactGate(session, effectiveLimit, transformOk) {
48514
+ if (!transformOk || effectiveLimit <= 0) return false;
48484
48515
  if (session.stats.lastInputTokens >= effectiveLimit * 0.9) return false;
48485
48516
  return session.state.blocks.some((b2) => b2.active);
48486
48517
  }
48487
- function codexCompactGate(session, effectiveLimit, transformOk) {
48488
- return transformOk && codexCompactGatePre(session, effectiveLimit);
48489
- }
48490
48518
  function buildTriggerForgeBody(summaryText, usage, stream2) {
48491
48519
  const compactionItem = {
48492
48520
  type: "compaction",
@@ -54403,7 +54431,7 @@ function handlePluginStatus(conversationId2, res, fallbackLatest = false) {
54403
54431
  if (entry) entry.lastSeen = Date.now();
54404
54432
  const limit = session.metadata.effectiveContextLimit;
54405
54433
  const mem = remembered.get(session.id);
54406
- const modelContextLimit = typeof limit === "number" && limit > 0 ? limit : 2e5;
54434
+ const modelContextLimit = typeof limit === "number" && limit > 0 ? limit : 0;
54407
54435
  let panel;
54408
54436
  try {
54409
54437
  panel = buildStatusPanel({
@@ -56395,6 +56423,9 @@ function logUnrecognizedPath(log2, url) {
56395
56423
  log2("info", `unrecognized path ${key}: forwarding unchanged; further occurrences suppressed`);
56396
56424
  }
56397
56425
  }
56426
+ function isModelDiscoveryPath(path17) {
56427
+ return path17.replace(/\/+$/, "").endsWith("/models");
56428
+ }
56398
56429
  var BILI_HOP_HEADER = "x-bili-hop";
56399
56430
  function parseLauncherModelWindows(raw) {
56400
56431
  if (!raw) return {};
@@ -56938,11 +56969,11 @@ ${bodyBuffer.toString("utf8")}`);
56938
56969
  const pluginWindow = pluginReportedContextWindow(req.headers);
56939
56970
  const launcherWindow = launcherContextWindow(model);
56940
56971
  const configuredWindow = resolveConfiguredContextLimit(opts.routes, embeddedUrl, model);
56941
- const peekWindow = host ? peekRegistryContext(model, host) : void 0;
56972
+ const peekWindow = peekRegistryContext(model, host);
56942
56973
  let native = betaWindow ?? pluginWindow ?? launcherWindow ?? configuredWindow ?? peekWindow ?? lookupContextLimit(model);
56943
56974
  const operatorWindowTuned = resolveCompress(opts.routes, embeddedUrl, model, opts.compress).modelContextLimit !== void 0;
56944
56975
  nativeFromFallback = !betaWindow && !pluginWindow && !launcherWindow && !peekWindow && !configuredWindow && !operatorWindowTuned;
56945
- if (!native && host) {
56976
+ if (!native) {
56946
56977
  native = await contextFromRegistry(model, host);
56947
56978
  if (native) nativeFromFallback = false;
56948
56979
  }
@@ -57042,7 +57073,6 @@ ${bodyBuffer.toString("utf8")}`);
57042
57073
  if (pluginAgent && !pluginConversation) pluginConversation = conversation;
57043
57074
  if (pluginAgent) {
57044
57075
  if (session.metadata.pluginAgent !== pluginAgent) session.metadata.pluginAgent = pluginAgent;
57045
- session.metadata.effectiveContextLimit = reqConfig.modelContextLimit;
57046
57076
  recordPluginSession(pluginConversation ?? conversation, session.id);
57047
57077
  }
57048
57078
  if (protocol === "responses" || protocol === "openai" || protocol === "anthropic") {
@@ -57060,6 +57090,22 @@ ${bodyBuffer.toString("utf8")}`);
57060
57090
  reqConfig = { ...reqConfig, modelContextLimit: learnedLimit };
57061
57091
  nativeFromFallback = false;
57062
57092
  log2("info", `[${session.id}] self-healed context window: ${resolved} \u2192 ${learnedLimit} (learned from an upstream overflow)`);
57093
+ } else if (nativeFromFallback && reqModel) {
57094
+ const prevInput = session.stats.lastInputTokens ?? 0;
57095
+ const prevWindow = session.metadata.lastTurnWindow;
57096
+ const resolved = reqConfig.modelContextLimit;
57097
+ if (prevWindow !== void 0 && prevInput > prevWindow && prevInput > resolved && prevInput >= 1e3) {
57098
+ const map = session.metadata.learnedContextLimits ?? {};
57099
+ const prev = map[reqModel];
57100
+ if (prev === void 0 || prevInput > prev) {
57101
+ map[reqModel] = prevInput;
57102
+ session.metadata.learnedContextLimits = map;
57103
+ markDirty(session);
57104
+ }
57105
+ reqConfig = { ...reqConfig, modelContextLimit: prevInput };
57106
+ nativeFromFallback = false;
57107
+ log2("info", `[${session.id}] self-healed context window upward: ${resolved} \u2192 ${prevInput} (a prior turn used ${prevInput} input tokens, exceeding the fallback window)`);
57108
+ }
57063
57109
  }
57064
57110
  const nativeWindow = reqConfig.modelContextLimit;
57065
57111
  if (shouldReserveOutputHeadroom(protocol)) {
@@ -57073,25 +57119,12 @@ ${bodyBuffer.toString("utf8")}`);
57073
57119
  }
57074
57120
  if (reserved !== reqConfig.modelContextLimit) reqConfig = { ...reqConfig, modelContextLimit: reserved };
57075
57121
  }
57122
+ session.metadata.effectiveContextLimit = reqConfig.modelContextLimit;
57123
+ session.metadata.lastTurnWindow = reqConfig.modelContextLimit;
57076
57124
  acquireInFlight(session);
57077
57125
  try {
57078
57126
  await withSessionLock(session, async () => {
57079
57127
  const runPrepare = () => countTokens ? prepareCountTokens(parsed, core, reqConfig, log2, session) : protocol === "anthropic" ? prepareAnthropic(parsed, req, opts, core, reqConfig, reqPrompts, log2, session, pluginMode) : protocol === "openai" ? prepareOpenai(parsed, req, opts, core, reqConfig, reqPrompts, log2, session, pluginMode, nativeWindow) : responsesCompact ? prepareResponsesCompact(bodyBuffer, parsed, session, req, core, reqConfig, log2) : prepareResponses(parsed, req, opts, core, reqConfig, reqPrompts, log2, session, responsesIdentity, pluginMode, upstreamOrigin, nativeWindow);
57080
- const isCodexCompactTrigger = protocol === "responses" && !responsesCompact && isCodexClient(req.headers) && hasCompactionTrigger(parsed.input);
57081
- if (isCodexCompactTrigger) {
57082
- const mode = codexCompactMode();
57083
- const gatePre = codexCompactGatePre(session, reqConfig.modelContextLimit);
57084
- if (mode === "intercept" && gatePre) prepared = runPrepare();
57085
- if (prepared?.codexForge) {
57086
- await forward(req, res, opts, prepared.body, prepared, core, reqConfig, log2, route, instanceId, affinity);
57087
- rememberPluginMessages(sessionId, prepared.processedMessages, prepared.originalMessages, prepared.nudge);
57088
- return;
57089
- }
57090
- const why = mode !== "intercept" ? "BILI_CODEX_COMPACT=pass" : !gatePre ? "gate preconditions not met" : "transform/forge failed";
57091
- log2("info", `[${session.id}] codex compaction_trigger request not intercepted (${why}) \u2014 forwarding verbatim (no preflight, no rebuild, no window clamp)`);
57092
- await forward(req, res, opts, bodyBuffer, null, core, reqConfig, log2, route, instanceId, affinity);
57093
- return;
57094
- }
57095
57128
  prepared = runPrepare();
57096
57129
  if (!countTokens && !responsesCompact) {
57097
57130
  const outcome = await preflightCompressIfNeeded(
@@ -57137,7 +57170,7 @@ ${bodyBuffer.toString("utf8")}`);
57137
57170
  }
57138
57171
  }
57139
57172
  if (!prepared) {
57140
- if (protocol === null && !opts.passthrough) {
57173
+ if (protocol === null && !opts.passthrough && !isModelDiscoveryPath(urlPath)) {
57141
57174
  logUnrecognizedPath(log2, req.url ?? "");
57142
57175
  }
57143
57176
  await forward(req, res, opts, bodyBuffer, null, core, reqConfig, log2, route, instanceId, void 0);
@@ -57537,7 +57570,7 @@ function prepareResponsesCompact(body, parsed, session, req, core, config, log2)
57537
57570
  compressInjected: false,
57538
57571
  resetAfterSuccess: true
57539
57572
  };
57540
- if (codexCompactMode() !== "intercept" || !isCodexClient(req.headers) || !Array.isArray(parsed.input) || !codexCompactGatePre(session, config.modelContextLimit)) {
57573
+ if (codexCompactMode() !== "intercept" || !isCodexClient(req.headers) || !Array.isArray(parsed.input)) {
57541
57574
  return base;
57542
57575
  }
57543
57576
  const prevState = session.state;