billion-context 0.1.60-pr.306.164 → 0.1.60
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 +33 -141
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -47852,7 +47852,6 @@ function rejectLegacyRoute(key, value) {
|
|
|
47852
47852
|
// src/server.ts
|
|
47853
47853
|
import http from "http";
|
|
47854
47854
|
import fs6 from "fs";
|
|
47855
|
-
import { randomUUID as randomUUID2 } from "crypto";
|
|
47856
47855
|
|
|
47857
47856
|
// src/compress-settings.ts
|
|
47858
47857
|
function resolveContextLimitValue(raw, nativeLimit) {
|
|
@@ -50228,21 +50227,16 @@ TASK: The conversation segment below (messages ${startRef}\u2013${endRef}) must
|
|
|
50228
50227
|
clearTimer();
|
|
50229
50228
|
}
|
|
50230
50229
|
}
|
|
50231
|
-
var ABORTED_FAILURE = { kind: "aborted", detail: "the client disconnected during preflight compression" };
|
|
50232
50230
|
async function preflightCompress(deps, messages) {
|
|
50233
50231
|
const limit = deps.config.modelContextLimit;
|
|
50234
|
-
const result = { compressedRanges: 0, savedTokens: 0
|
|
50232
|
+
const result = { compressedRanges: 0, savedTokens: 0 };
|
|
50235
50233
|
if (limit <= 0) return result;
|
|
50236
50234
|
const budget = Math.max(MIN_CHUNK_TOKENS, Math.floor(limit * CHUNK_FRACTION));
|
|
50237
50235
|
const minChars = deps.config.compress.minCompressRange;
|
|
50238
50236
|
let currentTokens = deps.session.stats.lastInputTokens;
|
|
50239
50237
|
let startTokens = -1;
|
|
50240
|
-
let failure;
|
|
50241
50238
|
for (let round = 0; round < MAX_PREFLIGHT_ROUNDS; round++) {
|
|
50242
|
-
if (deps.signal?.aborted)
|
|
50243
|
-
failure = ABORTED_FAILURE;
|
|
50244
|
-
break;
|
|
50245
|
-
}
|
|
50239
|
+
if (deps.signal?.aborted) break;
|
|
50246
50240
|
const turn = deps.core.processTurn({
|
|
50247
50241
|
messages,
|
|
50248
50242
|
state: deps.session.state,
|
|
@@ -50252,29 +50246,19 @@ async function preflightCompress(deps, messages) {
|
|
|
50252
50246
|
});
|
|
50253
50247
|
deps.session.state = turn.state;
|
|
50254
50248
|
currentTokens = Math.max(deps.session.stats.lastInputTokens, estimateCoreMessages(turn.messages));
|
|
50255
|
-
result.payloadEstimate = estimateCoreMessages(turn.messages);
|
|
50256
50249
|
if (startTokens < 0) startTokens = currentTokens;
|
|
50257
50250
|
if (currentTokens < limit) break;
|
|
50258
50251
|
const ranges = viableRanges(turn.nudge?.compressibleRanges ?? []);
|
|
50259
|
-
if (ranges.length === 0)
|
|
50260
|
-
failure = { kind: "exhausted", detail: "no compressible ranges remain in the conversation" };
|
|
50261
|
-
break;
|
|
50262
|
-
}
|
|
50252
|
+
if (ranges.length === 0) break;
|
|
50263
50253
|
const range = [...ranges].sort((a, b2) => refNum2(a.startRef) - refNum2(b2.startRef))[0];
|
|
50264
50254
|
const { refToIdx } = refMaps(messages, deps.session.state);
|
|
50265
50255
|
const startIdx = refToIdx.get(range.startRef);
|
|
50266
50256
|
const endIdx = refToIdx.get(range.endRef);
|
|
50267
|
-
if (startIdx === void 0 || endIdx === void 0 || startIdx > endIdx)
|
|
50268
|
-
failure = { kind: "exhausted", detail: "the compressible range no longer resolves to payload messages" };
|
|
50269
|
-
break;
|
|
50270
|
-
}
|
|
50257
|
+
if (startIdx === void 0 || endIdx === void 0 || startIdx > endIdx) break;
|
|
50271
50258
|
let appliedThisRound = 0;
|
|
50272
50259
|
for (const [cs2, ce2] of splitChunks(messages, startIdx, endIdx, budget)) {
|
|
50273
50260
|
if (currentTokens < limit) break;
|
|
50274
|
-
if (deps.signal?.aborted)
|
|
50275
|
-
failure = ABORTED_FAILURE;
|
|
50276
|
-
break;
|
|
50277
|
-
}
|
|
50261
|
+
if (deps.signal?.aborted) break;
|
|
50278
50262
|
const maps = refMaps(messages, deps.session.state);
|
|
50279
50263
|
const startRef = maps.idxToRef.get(cs2);
|
|
50280
50264
|
const endRef = maps.idxToRef.get(ce2);
|
|
@@ -50287,17 +50271,8 @@ async function preflightCompress(deps, messages) {
|
|
|
50287
50271
|
summary = await summarizeRange(deps, content, startRef, endRef);
|
|
50288
50272
|
} catch (err2) {
|
|
50289
50273
|
if (err2 instanceof UpstreamHttpError) {
|
|
50290
|
-
failure = {
|
|
50291
|
-
kind: "upstream",
|
|
50292
|
-
status: err2.status,
|
|
50293
|
-
detail: err2.status === 429 ? `the summarization call was rate-limited by the upstream (HTTP 429)` : `the summarization call was rejected by the upstream (HTTP ${err2.status})`
|
|
50294
|
-
};
|
|
50295
50274
|
deps.log("warn", `[preflight] summarization failed: HTTP ${err2.status} ${err2.body.slice(0, 200)}`);
|
|
50296
|
-
} else if (deps.signal?.aborted) {
|
|
50297
|
-
failure = ABORTED_FAILURE;
|
|
50298
|
-
deps.log("warn", `[preflight] summarization aborted: client disconnected`);
|
|
50299
50275
|
} else {
|
|
50300
|
-
failure = { kind: "upstream", detail: `the summarization call failed: ${String(err2)}` };
|
|
50301
50276
|
deps.log("warn", `[preflight] summarization failed: ${String(err2)}`);
|
|
50302
50277
|
}
|
|
50303
50278
|
break;
|
|
@@ -50322,19 +50297,10 @@ async function preflightCompress(deps, messages) {
|
|
|
50322
50297
|
appliedThisRound += 1;
|
|
50323
50298
|
result.compressedRanges += 1;
|
|
50324
50299
|
}
|
|
50325
|
-
if (appliedThisRound === 0)
|
|
50326
|
-
if (!failure) {
|
|
50327
|
-
failure = { kind: "exhausted", detail: "no range could be compressed (chunks below minCompressRange or the summarization responses were unusable)" };
|
|
50328
|
-
}
|
|
50329
|
-
break;
|
|
50330
|
-
}
|
|
50331
|
-
}
|
|
50332
|
-
if (!failure && currentTokens >= limit) {
|
|
50333
|
-
failure = { kind: "exhausted", detail: `the compress budget was exhausted after ${MAX_PREFLIGHT_ROUNDS} rounds` };
|
|
50300
|
+
if (appliedThisRound === 0) break;
|
|
50334
50301
|
}
|
|
50335
50302
|
if (result.compressedRanges > 0) deps.session.stats.lastInputTokens = currentTokens;
|
|
50336
50303
|
result.savedTokens = Math.max(0, startTokens - currentTokens);
|
|
50337
|
-
if (currentTokens >= limit) result.failure = failure;
|
|
50338
50304
|
return result;
|
|
50339
50305
|
}
|
|
50340
50306
|
|
|
@@ -52180,15 +52146,8 @@ ${systemPrompt}` : systemPrompt;
|
|
|
52180
52146
|
} else if (type === "message_delta") {
|
|
52181
52147
|
const u2 = data.usage ?? {};
|
|
52182
52148
|
if (typeof u2.output_tokens === "number") roundOutput = u2.output_tokens;
|
|
52183
|
-
|
|
52184
|
-
|
|
52185
|
-
if (input !== void 0 && input > 0 && cached !== void 0) {
|
|
52186
|
-
roundInput = input;
|
|
52187
|
-
roundCached = cached;
|
|
52188
|
-
} else {
|
|
52189
|
-
if (input !== void 0 && input > 0) roundInput = input;
|
|
52190
|
-
if (cached !== void 0 && cached > 0) roundCached = cached;
|
|
52191
|
-
}
|
|
52149
|
+
if (typeof u2.input_tokens === "number" && u2.input_tokens > 0) roundInput = u2.input_tokens;
|
|
52150
|
+
if (typeof u2.cache_read_input_tokens === "number" && u2.cache_read_input_tokens > 0) roundCached = u2.cache_read_input_tokens;
|
|
52192
52151
|
const d = data.delta ?? {};
|
|
52193
52152
|
if (typeof d.stop_reason === "string") stopReason = d.stop_reason;
|
|
52194
52153
|
if (!usageYielded) {
|
|
@@ -54875,7 +54834,6 @@ async function decodeRequestBody(contentEncoding, input, maxOutputBytes) {
|
|
|
54875
54834
|
function bodyDumpEnabled() {
|
|
54876
54835
|
return process.env.ACP_DUMP_BODY === "1";
|
|
54877
54836
|
}
|
|
54878
|
-
var BILI_HOP_HEADER = "x-bili-hop";
|
|
54879
54837
|
function parseLauncherModelWindows(raw) {
|
|
54880
54838
|
if (!raw) return {};
|
|
54881
54839
|
try {
|
|
@@ -54894,21 +54852,6 @@ var LAUNCHER_MODEL_WINDOWS = parseLauncherModelWindows(process.env.BILI_LAUNCHER
|
|
|
54894
54852
|
function launcherContextWindow(model) {
|
|
54895
54853
|
return LAUNCHER_MODEL_WINDOWS[model];
|
|
54896
54854
|
}
|
|
54897
|
-
function anthropicBetaContextWindow(headers) {
|
|
54898
|
-
const raw = headers["anthropic-beta"];
|
|
54899
|
-
if (raw === void 0) return void 0;
|
|
54900
|
-
const list = Array.isArray(raw) ? raw.join(",") : raw;
|
|
54901
|
-
let best;
|
|
54902
|
-
for (const part of list.split(",")) {
|
|
54903
|
-
const m2 = /^context-(\d+)m\b/.exec(part.trim().toLowerCase());
|
|
54904
|
-
if (!m2) continue;
|
|
54905
|
-
const n = Number.parseInt(m2[1], 10);
|
|
54906
|
-
if (!Number.isFinite(n) || n <= 0) continue;
|
|
54907
|
-
const w2 = n * 1e6;
|
|
54908
|
-
if (best === void 0 || w2 > best) best = w2;
|
|
54909
|
-
}
|
|
54910
|
-
return best;
|
|
54911
|
-
}
|
|
54912
54855
|
function safeSessionId(id) {
|
|
54913
54856
|
return (id ?? "unknown").replace(/[^a-zA-Z0-9._-]/g, "_");
|
|
54914
54857
|
}
|
|
@@ -54986,7 +54929,6 @@ async function startServer(opts) {
|
|
|
54986
54929
|
const core = createCore();
|
|
54987
54930
|
const config = opts.kernelConfig;
|
|
54988
54931
|
const log2 = (level, msg) => logMsg(opts, level, msg);
|
|
54989
|
-
const instanceId = randomUUID2();
|
|
54990
54932
|
await initSessions();
|
|
54991
54933
|
loadConversations();
|
|
54992
54934
|
log2("info", `[persist] ${getStore().enabled ? "enabled" : "disabled"}`);
|
|
@@ -54996,7 +54938,7 @@ async function startServer(opts) {
|
|
|
54996
54938
|
void loadRegistry();
|
|
54997
54939
|
const server = http.createServer(async (req, res) => {
|
|
54998
54940
|
try {
|
|
54999
|
-
await handle(req, res, opts, core, config, log2
|
|
54941
|
+
await handle(req, res, opts, core, config, log2);
|
|
55000
54942
|
} catch (err2) {
|
|
55001
54943
|
const msg = String(err2);
|
|
55002
54944
|
log2("error", msg);
|
|
@@ -55121,7 +55063,7 @@ function adminTrustedHosts(bindHost, port) {
|
|
|
55121
55063
|
}
|
|
55122
55064
|
return set;
|
|
55123
55065
|
}
|
|
55124
|
-
async function handle(req, res, opts, core, config, log2
|
|
55066
|
+
async function handle(req, res, opts, core, config, log2) {
|
|
55125
55067
|
const isAdminPath = req.url === "/__bili/" || req.url?.startsWith("/__bili/") || req.url === "/__acp/" || req.url?.startsWith("/__acp/");
|
|
55126
55068
|
if (isAdminPath && !isLoopbackAddress(req.socket.remoteAddress)) {
|
|
55127
55069
|
res.writeHead(403, { "content-type": "application/json" });
|
|
@@ -55282,11 +55224,6 @@ async function handle(req, res, opts, core, config, log2, instanceId) {
|
|
|
55282
55224
|
res.end(JSON.stringify({ error: { type: "invalid_request", message: String(err2) } }));
|
|
55283
55225
|
return;
|
|
55284
55226
|
}
|
|
55285
|
-
const hopMarker = headerValue2(req, BILI_HOP_HEADER);
|
|
55286
|
-
if (hopMarker !== void 0) {
|
|
55287
|
-
const selfLoop = hopMarker === instanceId;
|
|
55288
|
-
log2("warn", selfLoop ? `[chain] inbound request carries THIS instance's ${BILI_HOP_HEADER} marker (${hopMarker}) \u2014 self-loop detected. Passing through without processing; check your upstream config (it may point back to this instance).` : `[chain] inbound request carries ${BILI_HOP_HEADER} from another bili instance (${hopMarker}) \u2014 bili\u2192bili chain detected. Passing through without processing to avoid double compression; keep only one bili instance in the chain.`);
|
|
55289
|
-
}
|
|
55290
55227
|
const countTokens = isCountTokensRequest(req.method ?? "GET", urlPath, bodyBuffer.length > 0);
|
|
55291
55228
|
let parsed = null;
|
|
55292
55229
|
if (protocol && bodyBuffer.length > 0) {
|
|
@@ -55334,14 +55271,13 @@ ${bodyBuffer.toString("utf8")}`);
|
|
|
55334
55271
|
return void 0;
|
|
55335
55272
|
}
|
|
55336
55273
|
})();
|
|
55337
|
-
const betaWindow = anthropicBetaContextWindow(req.headers);
|
|
55338
55274
|
const pluginWindow = pluginReportedContextWindow(req.headers);
|
|
55339
55275
|
const launcherWindow = launcherContextWindow(model);
|
|
55340
55276
|
const peekWindow = host ? peekRegistryContext(model, host) : void 0;
|
|
55341
55277
|
const configuredWindow = resolveConfiguredContextLimit(opts.routes, embeddedUrl, model);
|
|
55342
|
-
let native =
|
|
55278
|
+
let native = pluginWindow ?? launcherWindow ?? peekWindow ?? configuredWindow ?? lookupContextLimit(model);
|
|
55343
55279
|
const operatorWindowTuned = resolveCompress(opts.routes, embeddedUrl, model, opts.compress).modelContextLimit !== void 0;
|
|
55344
|
-
nativeFromFallback = !
|
|
55280
|
+
nativeFromFallback = !pluginWindow && !launcherWindow && !peekWindow && !configuredWindow && !operatorWindowTuned;
|
|
55345
55281
|
if (!native && host) {
|
|
55346
55282
|
native = await contextFromRegistry(model, host);
|
|
55347
55283
|
if (native) nativeFromFallback = false;
|
|
@@ -55351,7 +55287,7 @@ ${bodyBuffer.toString("utf8")}`);
|
|
|
55351
55287
|
}
|
|
55352
55288
|
}
|
|
55353
55289
|
let prepared = null;
|
|
55354
|
-
if (!opts.passthrough &&
|
|
55290
|
+
if (!opts.passthrough && protocol && parsed && typeof parsed === "object") {
|
|
55355
55291
|
const sessionHeader = headerValue2(req, opts.sessionHeader);
|
|
55356
55292
|
let pluginAgent = pluginAgentHeader(req.headers);
|
|
55357
55293
|
let pluginConversation = pluginConversationHeader(req.headers);
|
|
@@ -55459,7 +55395,7 @@ ${bodyBuffer.toString("utf8")}`);
|
|
|
55459
55395
|
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) : responsesCompact ? prepareResponsesCompact(bodyBuffer, parsed, session) : prepareResponses(parsed, req, opts, core, reqConfig, reqPrompts, log2, session, responsesIdentity, pluginMode, upstreamOrigin);
|
|
55460
55396
|
prepared = runPrepare();
|
|
55461
55397
|
if (!countTokens && !responsesCompact) {
|
|
55462
|
-
|
|
55398
|
+
prepared = await preflightCompressIfNeeded(
|
|
55463
55399
|
prepared,
|
|
55464
55400
|
runPrepare,
|
|
55465
55401
|
req,
|
|
@@ -55470,29 +55406,10 @@ ${bodyBuffer.toString("utf8")}`);
|
|
|
55470
55406
|
parsed.model,
|
|
55471
55407
|
route,
|
|
55472
55408
|
affinity,
|
|
55473
|
-
log2
|
|
55474
|
-
instanceId
|
|
55409
|
+
log2
|
|
55475
55410
|
);
|
|
55476
|
-
if (isPreflightFailFast(outcome)) {
|
|
55477
|
-
if (outcome.respond && !res.headersSent && !res.destroyed) {
|
|
55478
|
-
res.writeHead(outcome.status, {
|
|
55479
|
-
"content-type": "application/json",
|
|
55480
|
-
...outcome.status === 503 ? { "retry-after": "30" } : {}
|
|
55481
|
-
});
|
|
55482
|
-
res.end(JSON.stringify({
|
|
55483
|
-
error: {
|
|
55484
|
-
type: "server_error",
|
|
55485
|
-
code: "preflight_compress_failed",
|
|
55486
|
-
message: outcome.message,
|
|
55487
|
-
retryable: outcome.retryable
|
|
55488
|
-
}
|
|
55489
|
-
}));
|
|
55490
|
-
}
|
|
55491
|
-
return;
|
|
55492
|
-
}
|
|
55493
|
-
prepared = outcome;
|
|
55494
55411
|
}
|
|
55495
|
-
await forward(req, res, opts, prepared.body, prepared, core, reqConfig, log2, route,
|
|
55412
|
+
await forward(req, res, opts, prepared.body, prepared, core, reqConfig, log2, route, affinity);
|
|
55496
55413
|
if (prepared) {
|
|
55497
55414
|
rememberPluginMessages(sessionId, prepared.processedMessages, prepared.originalMessages, prepared.nudge);
|
|
55498
55415
|
}
|
|
@@ -55505,7 +55422,7 @@ ${bodyBuffer.toString("utf8")}`);
|
|
|
55505
55422
|
if (protocol === null && !opts.passthrough) {
|
|
55506
55423
|
log2("warn", `unrecognized path ${maskUrlsInText(req.url ?? "")} \u2014 not a known protocol (/chat/completions, /v1/messages, /responses, /responses/compact); forwarding unchanged`);
|
|
55507
55424
|
}
|
|
55508
|
-
await forward(req, res, opts, bodyBuffer, null, core, reqConfig, log2, route,
|
|
55425
|
+
await forward(req, res, opts, bodyBuffer, null, core, reqConfig, log2, route, void 0);
|
|
55509
55426
|
}
|
|
55510
55427
|
}
|
|
55511
55428
|
var ACP_TAG_MARK = "<acp ";
|
|
@@ -55866,7 +55783,7 @@ function injectResponsesTool(tools, toolsToAdd = ACP_TOOLS_RESPONSES) {
|
|
|
55866
55783
|
const additions = toolsToAdd.filter((t) => !present.has(t.name));
|
|
55867
55784
|
return [...tools, ...additions];
|
|
55868
55785
|
}
|
|
55869
|
-
function buildForwardTarget(req, opts, route, affinity
|
|
55786
|
+
function buildForwardTarget(req, opts, route, affinity) {
|
|
55870
55787
|
const reqUrl = req.url ?? "";
|
|
55871
55788
|
const isAbsoluteUrl = /^https?:\/\//i.test(reqUrl);
|
|
55872
55789
|
const rewritten = route ? route.rewrittenUrl : isAbsoluteUrl ? reqUrl : opts.upstream + reqUrl;
|
|
@@ -55878,7 +55795,6 @@ function buildForwardTarget(req, opts, route, affinity, hopMarker) {
|
|
|
55878
55795
|
if (UPSTREAM_HOP_HEADERS.has(lower) || reqConnNamed.has(lower) || v2 === void 0) continue;
|
|
55879
55796
|
headers[k2] = Array.isArray(v2) ? v2.join(", ") : v2;
|
|
55880
55797
|
}
|
|
55881
|
-
if (hopMarker !== void 0) headers[BILI_HOP_HEADER] = hopMarker;
|
|
55882
55798
|
headers["host"] = new URL(upstreamUrl).host;
|
|
55883
55799
|
const betaKey = Object.keys(headers).find((h) => h.toLowerCase() === "x-codex-beta-features");
|
|
55884
55800
|
if (betaKey) {
|
|
@@ -55892,29 +55808,14 @@ function buildForwardTarget(req, opts, route, affinity, hopMarker) {
|
|
|
55892
55808
|
const proxyUrl = resolveProxy(opts.routes, opts.proxy, route?.rewrittenUrl ?? upstreamUrl, opts.proxyFallback);
|
|
55893
55809
|
return { upstreamUrl, headers, proxyUrl };
|
|
55894
55810
|
}
|
|
55895
|
-
function
|
|
55896
|
-
return "failFast" in outcome;
|
|
55897
|
-
}
|
|
55898
|
-
async function preflightCompressIfNeeded(prepared, runPrepare, req, res, opts, core, config, model, route, affinity, log2, instanceId) {
|
|
55811
|
+
async function preflightCompressIfNeeded(prepared, runPrepare, req, res, opts, core, config, model, route, affinity, log2) {
|
|
55899
55812
|
const session = prepared.session;
|
|
55900
55813
|
const limit = config.modelContextLimit;
|
|
55901
|
-
const
|
|
55902
|
-
const tokenCount = Math.max(session.stats.lastInputTokens, payloadEstimate);
|
|
55814
|
+
const tokenCount = Math.max(session.stats.lastInputTokens, estimateCoreMessages(prepared.processedMessages));
|
|
55903
55815
|
if (limit <= 0 || !model || tokenCount < limit) return prepared;
|
|
55904
|
-
|
|
55905
|
-
const message = `context ~${tokenCount} tokens exceeds the model window ${limit} (model=${model}) and preflight compression could not bring it under: ${detail}. The over-window payload was NOT forwarded.`;
|
|
55906
|
-
log2("error", `[${session.id}] preflight fail-fast ${status2} (retryable=${retryable}): ${message}`);
|
|
55907
|
-
return { failFast: true, status: status2, message, retryable, respond: !res.writableEnded };
|
|
55908
|
-
};
|
|
55909
|
-
if ((prepared.nudge?.compressibleRanges ?? []).length === 0) {
|
|
55910
|
-
if (payloadEstimate < limit) {
|
|
55911
|
-
log2("warn", `[${session.id}] preflight trigger fired on a stale baseline (~${tokenCount}) but the payload fits (~${payloadEstimate}/${limit}); forwarding as-is`);
|
|
55912
|
-
return prepared;
|
|
55913
|
-
}
|
|
55914
|
-
return failFast(502, "no part of the conversation is compressible (nothing left to fold)", false);
|
|
55915
|
-
}
|
|
55816
|
+
if ((prepared.nudge?.compressibleRanges ?? []).length === 0) return prepared;
|
|
55916
55817
|
log2("warn", `[${session.id}] context ${tokenCount} tokens exceeds model window ${limit} (model=${model}); preflight compressing before forward`);
|
|
55917
|
-
const { upstreamUrl, headers, proxyUrl } = buildForwardTarget(req, opts, route, affinity
|
|
55818
|
+
const { upstreamUrl, headers, proxyUrl } = buildForwardTarget(req, opts, route, affinity);
|
|
55918
55819
|
const clientAbort = new AbortController();
|
|
55919
55820
|
res.on("close", () => {
|
|
55920
55821
|
if (!res.writableEnded) clientAbort.abort();
|
|
@@ -55936,26 +55837,17 @@ async function preflightCompressIfNeeded(prepared, runPrepare, req, res, opts, c
|
|
|
55936
55837
|
},
|
|
55937
55838
|
prepared.originalMessages
|
|
55938
55839
|
);
|
|
55939
|
-
if (result.
|
|
55940
|
-
|
|
55941
|
-
|
|
55942
|
-
|
|
55943
|
-
|
|
55944
|
-
return rebuilt;
|
|
55945
|
-
}
|
|
55946
|
-
log2("warn", `[${session.id}] preflight made no progress but the payload fits (~${result.payloadEstimate}/${limit}); forwarding as-is`);
|
|
55947
|
-
return prepared;
|
|
55840
|
+
if (result.compressedRanges > 0) {
|
|
55841
|
+
log2("info", `[${session.id}] preflight compressed ${result.compressedRanges} range(s), ~${result.savedTokens} tokens saved (${tokenCount} \u2192 ${session.stats.lastInputTokens}) in ${Date.now() - started}ms; rebuilding payload`);
|
|
55842
|
+
const rebuilt = runPrepare();
|
|
55843
|
+
session.stats.requests -= 1;
|
|
55844
|
+
return rebuilt;
|
|
55948
55845
|
}
|
|
55949
|
-
|
|
55950
|
-
|
|
55951
|
-
log2("warn", `[${session.id}] preflight aborted (${f2.detail}); not forwarding`);
|
|
55952
|
-
return { failFast: true, status: 0, message: f2.detail, retryable: false, respond: false };
|
|
55953
|
-
}
|
|
55954
|
-
const status = f2?.kind === "upstream" && f2.status === 429 ? 503 : 502;
|
|
55955
|
-
return failFast(status, f2?.detail ?? "unknown reason", status === 503);
|
|
55846
|
+
log2("warn", `[${session.id}] preflight could not compress enough (~${result.savedTokens} tokens saved); forwarding as-is`);
|
|
55847
|
+
return prepared;
|
|
55956
55848
|
}
|
|
55957
|
-
async function forward(req, res, opts, body, prepared, core, config, log2, route,
|
|
55958
|
-
const { upstreamUrl, headers, proxyUrl } = buildForwardTarget(req, opts, route, affinity
|
|
55849
|
+
async function forward(req, res, opts, body, prepared, core, config, log2, route, affinity) {
|
|
55850
|
+
const { upstreamUrl, headers, proxyUrl } = buildForwardTarget(req, opts, route, affinity);
|
|
55959
55851
|
log2("info", `forward ${req.method} \u2192 ${maskUrlForLog(upstreamUrl)}`);
|
|
55960
55852
|
if (process.env.ACP_DEBUG && prepared) {
|
|
55961
55853
|
const sid = prepared.session.id;
|
|
@@ -60295,7 +60187,7 @@ function pluginStatusAll() {
|
|
|
60295
60187
|
}
|
|
60296
60188
|
|
|
60297
60189
|
// src/launcher.ts
|
|
60298
|
-
import { randomUUID as
|
|
60190
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
60299
60191
|
import fs10 from "fs";
|
|
60300
60192
|
import net2 from "net";
|
|
60301
60193
|
import os5 from "os";
|
|
@@ -61275,7 +61167,7 @@ async function runLaunch(params, deps = {}) {
|
|
|
61275
61167
|
const dshAcpPatch = writeDshAcpPatch(dshHomeDir);
|
|
61276
61168
|
if (dshAcpPatch) clientArgs = dshArgsWithPatch(clientArgs, dshAcpPatch);
|
|
61277
61169
|
} else if (base === "codex") {
|
|
61278
|
-
const codexConversationId = injectMcp ?
|
|
61170
|
+
const codexConversationId = injectMcp ? randomUUID2() : void 0;
|
|
61279
61171
|
if (directUrl) {
|
|
61280
61172
|
env = { ...process.env, BILLION_CONTEXT_PROXY: origin };
|
|
61281
61173
|
if (codexConversationId) clientArgs = [...buildCodexMcpArgs(origin, codexConversationId), ...clientArgs];
|