billion-context 0.1.55-pr.252.106 → 0.1.55

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
@@ -49384,8 +49384,6 @@ function buildSession(parsed) {
49384
49384
  outputTokens: stats.outputTokens ?? parsed.outputTokens ?? 0,
49385
49385
  cacheSamples: stats.cacheSamples ?? parsed.cacheSamples ?? 0,
49386
49386
  lastInputTokens: stats.lastInputTokens ?? parsed.lastInputTokens ?? 0,
49387
- // In-memory only — a fresh process has no pending compress fold.
49388
- compressCreditTokens: 0,
49389
49387
  contextTokens: stats.contextTokens ?? parsed.contextTokens ?? 0
49390
49388
  },
49391
49389
  metadata: parsed.metadata ?? {},
@@ -49476,7 +49474,7 @@ function getSession(id, meta) {
49476
49474
  const session = {
49477
49475
  id,
49478
49476
  meta: { protocol: meta?.protocol, upstreamOrigin: meta?.upstreamOrigin, label: meta?.label },
49479
- stats: { requests: 0, tokensSaved: 0, inputTokens: 0, cachedTokens: 0, outputTokens: 0, cacheSamples: 0, lastInputTokens: 0, compressCreditTokens: 0, contextTokens: 0 },
49477
+ stats: { requests: 0, tokensSaved: 0, inputTokens: 0, cachedTokens: 0, outputTokens: 0, cacheSamples: 0, lastInputTokens: 0, contextTokens: 0 },
49480
49478
  metadata: {},
49481
49479
  state: createInitialState(),
49482
49480
  createdAt: Date.now(),
@@ -49878,8 +49876,6 @@ function applyRanges(ranges, ctx) {
49878
49876
  const warn = r.warnings.length > 0 ? ` ${r.warnings.join("; ")}` : "";
49879
49877
  const msg = `[Compressed ${detail} \u2192 ${r.blocksCreated} block(s), ~${r.tokensCompressed} tokens saved.${warn}]`;
49880
49878
  ctx.log(`[acp-proxy: ${msg}]`);
49881
- ctx.session.stats.compressCreditTokens = (ctx.session.stats.compressCreditTokens ?? 0) + r.tokensCompressed;
49882
- ctx.session.stats.lastInputTokens = Math.max(0, ctx.session.stats.lastInputTokens - r.tokensCompressed);
49883
49879
  return msg;
49884
49880
  } catch (err2) {
49885
49881
  ctx.log(`[acp-proxy: compress failed: ${String(err2)}]`);
@@ -50273,7 +50269,7 @@ function recordUsage(ctx, usage, round) {
50273
50269
  const includesCached = ctx.protocol === "openai" || ctx.protocol === "responses";
50274
50270
  const total = (typeof prompt === "number" ? prompt : 0) + (!includesCached && typeof cached === "number" ? cached : 0);
50275
50271
  if (total > 0) ctx.session.stats.inputTokens += total;
50276
- ctx.session.stats.lastInputTokens = Math.max(0, total - (ctx.session.stats.compressCreditTokens ?? 0));
50272
+ ctx.session.stats.lastInputTokens = total;
50277
50273
  if (typeof cached === "number") {
50278
50274
  ctx.session.stats.cachedTokens += cached;
50279
50275
  ctx.session.stats.cacheSamples += 1;
@@ -52621,7 +52617,7 @@ function applyUsageSample(session, sample, protocol) {
52621
52617
  if (sample.inputTokens !== void 0) {
52622
52618
  const total = sample.inputTokens + (!includesCached && sample.cachedTokens !== void 0 ? sample.cachedTokens : 0);
52623
52619
  session.stats.inputTokens += total;
52624
- session.stats.lastInputTokens = Math.max(0, total - (session.stats.compressCreditTokens ?? 0));
52620
+ session.stats.lastInputTokens = total;
52625
52621
  }
52626
52622
  if (sample.outputTokens !== void 0) session.stats.outputTokens += sample.outputTokens;
52627
52623
  }
@@ -52853,9 +52849,6 @@ import path9 from "path";
52853
52849
  import fs4 from "fs";
52854
52850
  import os from "os";
52855
52851
  import path8 from "path";
52856
- function toModelWindow(id, contextWindow) {
52857
- return typeof id === "string" && id.length > 0 && typeof contextWindow === "number" && Number.isFinite(contextWindow) && contextWindow > 0 ? { id, contextWindow: Math.floor(contextWindow) } : null;
52858
- }
52859
52852
  function nonEmpty2(s3) {
52860
52853
  return typeof s3 === "string" && s3.trim().length > 0;
52861
52854
  }
@@ -52928,8 +52921,6 @@ function parseCodexToml(text) {
52928
52921
  const result = { providers: {} };
52929
52922
  let table = "";
52930
52923
  let curProvider = null;
52931
- let codexModel;
52932
- let codexContextWindow;
52933
52924
  for (const rawLine of text.split(/\r?\n/)) {
52934
52925
  const line = rawLine.trim();
52935
52926
  if (!line || line.startsWith("#")) continue;
@@ -52942,24 +52933,17 @@ function parseCodexToml(text) {
52942
52933
  }
52943
52934
  continue;
52944
52935
  }
52945
- const strMatch = /^([A-Za-z0-9_.-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/.exec(line);
52946
- const numMatch = /^([A-Za-z0-9_.-]+)\s*=\s*([0-9]+)\b/.exec(line);
52947
- if (strMatch) {
52948
- const key = strMatch[1];
52949
- const val = strMatch[2] !== void 0 ? strMatch[2] : strMatch[3];
52950
- if (table === "") {
52951
- if (key === "model_provider") result.modelProvider = val;
52952
- else if (key === "openai_base_url") result.openaiBaseUrl = val;
52953
- else if (key === "model") codexModel = val;
52954
- } else if (curProvider && key === "base_url") {
52955
- result.providers[curProvider].baseUrl = val;
52956
- }
52957
- } else if (numMatch && table === "" && numMatch[1] === "model_context_window") {
52958
- codexContextWindow = Number(numMatch[2]);
52936
+ const m2 = /^([A-Za-z0-9_.-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/.exec(line);
52937
+ if (!m2) continue;
52938
+ const key = m2[1];
52939
+ const val = m2[2] !== void 0 ? m2[2] : m2[3];
52940
+ if (table === "") {
52941
+ if (key === "model_provider") result.modelProvider = val;
52942
+ else if (key === "openai_base_url") result.openaiBaseUrl = val;
52943
+ } else if (curProvider && key === "base_url") {
52944
+ result.providers[curProvider].baseUrl = val;
52959
52945
  }
52960
52946
  }
52961
- const win = toModelWindow(codexModel, codexContextWindow);
52962
- if (win) result.modelWindows = [win];
52963
52947
  return result;
52964
52948
  }
52965
52949
  function readCodexConfig(codexHome) {
@@ -52981,19 +52965,7 @@ function readPiConfig(piHome) {
52981
52965
  for (const [name, val] of Object.entries(rawProviders)) {
52982
52966
  if (val && typeof val === "object" && !Array.isArray(val)) {
52983
52967
  const baseUrl = val.baseUrl;
52984
- const models = val.models;
52985
- const windows = [];
52986
- if (Array.isArray(models)) {
52987
- for (const m2 of models) {
52988
- if (!m2 || typeof m2 !== "object") continue;
52989
- const win = toModelWindow(m2.id, m2.contextWindow);
52990
- if (win) windows.push(win);
52991
- }
52992
- }
52993
- providers[name] = {
52994
- ...typeof baseUrl === "string" ? { baseUrl } : {},
52995
- ...windows.length > 0 ? { models: windows } : {}
52996
- };
52968
+ providers[name] = typeof baseUrl === "string" ? { baseUrl } : {};
52997
52969
  }
52998
52970
  }
52999
52971
  }
@@ -53004,9 +52976,6 @@ function parseOmpYaml(text) {
53004
52976
  let providersIndent = -1;
53005
52977
  let providerIndent = -1;
53006
52978
  let currentProvider = null;
53007
- let modelsIndent = -1;
53008
- let dashIndent = -1;
53009
- let currentModelId;
53010
52979
  for (const rawLine of text.split(/\r?\n/)) {
53011
52980
  const trimmed = rawLine.trim();
53012
52981
  if (!trimmed || trimmed.startsWith("#")) continue;
@@ -53018,9 +52987,6 @@ function parseOmpYaml(text) {
53018
52987
  if (indent <= providersIndent) break;
53019
52988
  if (providerIndent === -1) providerIndent = indent;
53020
52989
  if (indent === providerIndent) {
53021
- modelsIndent = -1;
53022
- dashIndent = -1;
53023
- currentModelId = void 0;
53024
52990
  const m2 = /^([A-Za-z0-9_.-]+):/.exec(trimmed);
53025
52991
  if (m2) {
53026
52992
  currentProvider = m2[1];
@@ -53029,26 +52995,8 @@ function parseOmpYaml(text) {
53029
52995
  currentProvider = null;
53030
52996
  }
53031
52997
  } else if (indent > providerIndent && currentProvider) {
53032
- const idMatch = /^-\s+id:\s*(\S+)/.exec(trimmed);
53033
- if (modelsIndent >= 0 && indent > modelsIndent && idMatch) {
53034
- currentModelId = idMatch[1];
53035
- dashIndent = indent;
53036
- } else if (modelsIndent >= 0 && dashIndent >= 0 && indent > dashIndent && /^contextWindow:\s*([0-9]+)/.test(trimmed)) {
53037
- const n = Number(/^contextWindow:\s*([0-9]+)/.exec(trimmed)[1]);
53038
- const win = toModelWindow(currentModelId, n);
53039
- if (win) {
53040
- const prov = result.providers[currentProvider];
53041
- prov.models = [...prov.models ?? [], win];
53042
- }
53043
- currentModelId = void 0;
53044
- } else if (/^models:\s*(#.*)?$/.test(trimmed)) {
53045
- modelsIndent = indent;
53046
- dashIndent = -1;
53047
- currentModelId = void 0;
53048
- } else if (modelsIndent < 0 || indent <= modelsIndent) {
53049
- const m2 = /^baseUrl:\s*(\S+)/.exec(trimmed);
53050
- if (m2) result.providers[currentProvider].baseUrl = m2[1];
53051
- }
52998
+ const m2 = /^baseUrl:\s*(\S+)/.exec(trimmed);
52999
+ if (m2) result.providers[currentProvider].baseUrl = m2[1];
53052
53000
  }
53053
53001
  }
53054
53002
  return result;
@@ -53169,19 +53117,6 @@ function readOpencodeConfig(file) {
53169
53117
  const baseURL = opts.baseURL;
53170
53118
  if (typeof baseURL === "string") providers[name] = { baseURL };
53171
53119
  }
53172
- const modelsRoot = value.models;
53173
- if (modelsRoot && typeof modelsRoot === "object" && !Array.isArray(modelsRoot) && providers[name]) {
53174
- const windows = [];
53175
- for (const [modelId, mv] of Object.entries(modelsRoot)) {
53176
- if (!mv || typeof mv !== "object") continue;
53177
- const limit = mv.limit;
53178
- if (typeof limit === "number") {
53179
- const win = toModelWindow(modelId, limit);
53180
- if (win) windows.push(win);
53181
- }
53182
- }
53183
- if (windows.length > 0) providers[name].models = windows;
53184
- }
53185
53120
  }
53186
53121
  }
53187
53122
  }
@@ -53234,19 +53169,6 @@ function loadClientConfig(env, cwd) {
53234
53169
  config.dsh = readDshConfig(resolveDshHome(env));
53235
53170
  return config;
53236
53171
  }
53237
- function collectModelWindows(config) {
53238
- const out = {};
53239
- const add = (wins) => {
53240
- for (const w2 of wins ?? []) {
53241
- if (!out[w2.id] || w2.contextWindow > out[w2.id]) out[w2.id] = w2.contextWindow;
53242
- }
53243
- };
53244
- for (const p2 of Object.values(config.pi?.providers ?? {})) add(p2.models);
53245
- for (const p2 of Object.values(config.omp?.providers ?? {})) add(p2.models);
53246
- for (const p2 of Object.values(config.opencode?.providers ?? {})) add(p2.models);
53247
- add(config.codex?.modelWindows);
53248
- return out;
53249
- }
53250
53172
 
53251
53173
  // src/discover.ts
53252
53174
  var TTL_MS2 = 2e3;
@@ -54176,24 +54098,6 @@ async function decodeRequestBody(contentEncoding, input, maxOutputBytes) {
54176
54098
  }
54177
54099
 
54178
54100
  // src/server.ts
54179
- function parseLauncherModelWindows(raw) {
54180
- if (!raw) return {};
54181
- try {
54182
- const parsed = JSON.parse(raw);
54183
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
54184
- const out = {};
54185
- for (const [id, v2] of Object.entries(parsed)) {
54186
- if (typeof v2 === "number" && Number.isFinite(v2) && v2 > 0) out[id] = Math.floor(v2);
54187
- }
54188
- return out;
54189
- } catch {
54190
- return {};
54191
- }
54192
- }
54193
- var LAUNCHER_MODEL_WINDOWS = parseLauncherModelWindows(process.env.BILI_LAUNCHER_MODEL_WINDOWS);
54194
- function launcherContextWindow(model) {
54195
- return LAUNCHER_MODEL_WINDOWS[model];
54196
- }
54197
54101
  var UPSTREAM_HOP_HEADERS = /* @__PURE__ */ new Set([
54198
54102
  "host",
54199
54103
  "content-length",
@@ -54603,7 +54507,7 @@ ${bodyBuffer.toString("utf8")}`);
54603
54507
  return void 0;
54604
54508
  }
54605
54509
  })();
54606
- let native = pluginReportedContextWindow(req.headers) ?? launcherContextWindow(model) ?? (host ? peekRegistryContext(model, host) : void 0) ?? resolveContextLimit(opts.routes, embeddedUrl, model);
54510
+ let native = pluginReportedContextWindow(req.headers) ?? (host ? peekRegistryContext(model, host) : void 0) ?? resolveContextLimit(opts.routes, embeddedUrl, model);
54607
54511
  if (!native && host) {
54608
54512
  native = await contextFromRegistry(model, host);
54609
54513
  }
@@ -54744,7 +54648,6 @@ function prepareAnthropic(parsed, req, opts, core, config, prompts, log2, sessio
54744
54648
  const tokenCount = session.stats.lastInputTokens;
54745
54649
  const turn = core.processTurn({ messages: msgs, state: session.state, config, tokenCount, renderTags: "text-only" });
54746
54650
  session.state = turn.state;
54747
- session.stats.compressCreditTokens = 0;
54748
54651
  if (turn.nudge) turn.nudge.compressibleRanges = viableRanges(turn.nudge.compressibleRanges);
54749
54652
  nudge = turn.nudge;
54750
54653
  session.stats.contextTokens = tokenCount;
@@ -54800,7 +54703,6 @@ function prepareOpenai(parsed, req, opts, core, config, prompts, log2, session,
54800
54703
  const tokenCount = session.stats.lastInputTokens;
54801
54704
  const turn = core.processTurn({ messages: msgs, state: session.state, config, tokenCount, renderTags: "text-only" });
54802
54705
  session.state = turn.state;
54803
- session.stats.compressCreditTokens = 0;
54804
54706
  if (turn.nudge) turn.nudge.compressibleRanges = viableRanges(turn.nudge.compressibleRanges);
54805
54707
  nudge = turn.nudge;
54806
54708
  session.stats.contextTokens = tokenCount;
@@ -54869,7 +54771,6 @@ function prepareResponses(parsed, req, opts, core, config, prompts, log2, sessio
54869
54771
  const tokenCount = session.stats.lastInputTokens;
54870
54772
  const turn = core.processTurn({ messages: msgs, state: session.state, config, tokenCount, renderTags: process.env.ACP_RENDER_NONE ? "none" : "text-only" });
54871
54773
  session.state = turn.state;
54872
- session.stats.compressCreditTokens = 0;
54873
54774
  if (turn.nudge) turn.nudge.compressibleRanges = viableRanges(turn.nudge.compressibleRanges);
54874
54775
  nudge = turn.nudge;
54875
54776
  session.stats.contextTokens = tokenCount;
@@ -55334,10 +55235,7 @@ ${hdrText}
55334
55235
  const { total, cached } = usageTotals(prepared.protocol, u2);
55335
55236
  if (typeof total === "number") {
55336
55237
  prepared.session.stats.inputTokens += total;
55337
- prepared.session.stats.lastInputTokens = Math.max(
55338
- 0,
55339
- total - (prepared.session.stats.compressCreditTokens ?? 0)
55340
- );
55238
+ prepared.session.stats.lastInputTokens = total;
55341
55239
  if (typeof cached === "number") {
55342
55240
  prepared.session.stats.cachedTokens += cached;
55343
55241
  prepared.session.stats.cacheSamples += 1;
@@ -60083,8 +59981,7 @@ async function ensureProxyRunning(opts, deps = {}) {
60083
59981
  stdio: ["ignore", logFd, logFd],
60084
59982
  env: {
60085
59983
  ...stripInheritedProxy(process.env),
60086
- ...opts.mitmDomains && opts.mitmDomains.length ? { BILI_MITM_DOMAINS: opts.mitmDomains.join(",") } : {},
60087
- ...opts.modelWindows && Object.keys(opts.modelWindows).length > 0 ? { BILI_LAUNCHER_MODEL_WINDOWS: JSON.stringify(opts.modelWindows) } : {}
59984
+ ...opts.mitmDomains && opts.mitmDomains.length ? { BILI_MITM_DOMAINS: opts.mitmDomains.join(",") } : {}
60088
59985
  }
60089
59986
  }
60090
59987
  );
@@ -60186,7 +60083,7 @@ async function runLaunch(params, deps = {}) {
60186
60083
  const base = baseClientName(params.client);
60187
60084
  const routes = discoverRoutes(base, config);
60188
60085
  const domains = dedupeInOrder([...routes.httpsDomains, ...params.mitmDomains ?? []]);
60189
- const handle2 = await ensureProxyRunning({ host, port, passthrough, debug, mitmDomains: domains, modelWindows: collectModelWindows(config) }, deps);
60086
+ const handle2 = await ensureProxyRunning({ host, port, passthrough, debug, mitmDomains: domains }, deps);
60190
60087
  console.error(
60191
60088
  `bili: started proxy at ${handle2.origin} (MITM domains: ${domains.length ? domains.join(", ") : "defaults"})` + (routes.httpRewrites.length > 0 ? ` (HTTP /bili/ rewrites: ${routes.httpRewrites.length})` : "") + (routes.httpsRewrites.length > 0 ? ` (HTTPS cert rewrites: ${routes.httpsRewrites.length})` : "") + (params.client === "pi-test" ? " (no extensions)" : "")
60192
60089
  );
@@ -60326,7 +60223,7 @@ async function runTestPi(params, deps = {}) {
60326
60223
  ...discoverDomains("pi", config),
60327
60224
  ...params.mitmDomains ?? []
60328
60225
  ]);
60329
- const handle2 = await ensureProxyRunning({ host, port, passthrough, debug, mitmDomains: domains, modelWindows: collectModelWindows(config) }, deps);
60226
+ const handle2 = await ensureProxyRunning({ host, port, passthrough, debug, mitmDomains: domains }, deps);
60330
60227
  console.error(
60331
60228
  `bili: started proxy at ${handle2.origin} (MITM domains: ${domains.length ? domains.join(", ") : "defaults"})`
60332
60229
  );