billion-context 0.1.101-pr.690.515 → 0.1.101
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 +17 -181
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -43467,7 +43467,7 @@ var require_lib = __commonJS({
|
|
|
43467
43467
|
}
|
|
43468
43468
|
});
|
|
43469
43469
|
|
|
43470
|
-
// node_modules/acp-kernel/dist/chunk-
|
|
43470
|
+
// node_modules/acp-kernel/dist/chunk-JGNVAFFE.js
|
|
43471
43471
|
import { createRequire } from "module";
|
|
43472
43472
|
var require2 = createRequire(import.meta.url);
|
|
43473
43473
|
function defaultCountTokens(text) {
|
|
@@ -43476,12 +43476,6 @@ function defaultCountTokens(text) {
|
|
|
43476
43476
|
const cjkCount = cjk?.length ?? 0;
|
|
43477
43477
|
return cjkCount + Math.ceil((text.length - cjkCount) / 4);
|
|
43478
43478
|
}
|
|
43479
|
-
function thinkingTokenValue(thinking) {
|
|
43480
|
-
return typeof thinking === "number" && Number.isFinite(thinking) && thinking > 0 ? thinking : 0;
|
|
43481
|
-
}
|
|
43482
|
-
function countMessageTokens(message, countTokens = defaultCountTokens) {
|
|
43483
|
-
return countTokens(message.text ?? "") + thinkingTokenValue(message.thinkingTokens);
|
|
43484
|
-
}
|
|
43485
43479
|
function estimateTokensFast(text) {
|
|
43486
43480
|
if (!text) return 0;
|
|
43487
43481
|
return Math.ceil(text.length / 4);
|
|
@@ -45289,8 +45283,7 @@ function renderMessage(message, map, countTokens, strategy, snapshot = null) {
|
|
|
45289
45283
|
"^" + escapeRegex(TAG_OPEN) + "[^>]*" + GT + escapeRegex(ref) + escapeRegex(TAG_CLOSE) + "\\n?"
|
|
45290
45284
|
);
|
|
45291
45285
|
const cleanText = (message.text || "").replace(ownTagRe, "");
|
|
45292
|
-
const
|
|
45293
|
-
const tokens = textTokens + thinkingTokenValue(message.thinkingTokens);
|
|
45286
|
+
const tokens = snapshot ? snapshot[ref] ?? (snapshot[ref] = countTokens(cleanText)) : countTokens(cleanText);
|
|
45294
45287
|
const type = classifyType(message);
|
|
45295
45288
|
const prefix = acpTag(ref, tokens, type) + "\n";
|
|
45296
45289
|
if (!cleanText) return { ...message, text: prefix };
|
|
@@ -45369,12 +45362,8 @@ function adjustBoundariesForReasoningPairs(startIndex, endIndex, messages) {
|
|
|
45369
45362
|
j2++;
|
|
45370
45363
|
}
|
|
45371
45364
|
const companion = messages[j2 + 1];
|
|
45372
|
-
if (companion !== void 0 && companion.role === "assistant" && (companion.contentType === "text" || companion.contentType === "tool-call")) {
|
|
45373
|
-
|
|
45374
|
-
while (e + 1 < messages.length && messages[e + 1].role === "assistant" && (messages[e + 1].contentType === "text" || messages[e + 1].contentType === "tool-call")) {
|
|
45375
|
-
e++;
|
|
45376
|
-
}
|
|
45377
|
-
if (e > newEndIndex) newEndIndex = e;
|
|
45365
|
+
if (companion !== void 0 && companion.role === "assistant" && (companion.contentType === "text" || companion.contentType === "tool-call") && j2 + 1 > newEndIndex) {
|
|
45366
|
+
newEndIndex = j2 + 1;
|
|
45378
45367
|
}
|
|
45379
45368
|
}
|
|
45380
45369
|
if (msg.role === "assistant" && (msg.contentType === "text" || msg.contentType === "tool-call")) {
|
|
@@ -45390,64 +45379,6 @@ function adjustBoundariesForReasoningPairs(startIndex, endIndex, messages) {
|
|
|
45390
45379
|
}
|
|
45391
45380
|
return { startIndex: newStartIndex, endIndex: newEndIndex };
|
|
45392
45381
|
}
|
|
45393
|
-
function isAssistantAct(msg) {
|
|
45394
|
-
return msg.role === "assistant" && (msg.contentType === "text" || msg.contentType === "tool-call");
|
|
45395
|
-
}
|
|
45396
|
-
function computeTurnGroups(messages) {
|
|
45397
|
-
const resultIdByCallId = /* @__PURE__ */ new Map();
|
|
45398
|
-
for (const msg of messages) {
|
|
45399
|
-
if (msg.contentType === "tool-result" && typeof msg.toolCallId === "string" && msg.id) {
|
|
45400
|
-
if (!resultIdByCallId.has(msg.toolCallId))
|
|
45401
|
-
resultIdByCallId.set(msg.toolCallId, msg.id);
|
|
45402
|
-
}
|
|
45403
|
-
}
|
|
45404
|
-
const grouped = /* @__PURE__ */ new Set();
|
|
45405
|
-
const groups = [];
|
|
45406
|
-
for (let i = 0; i < messages.length; i++) {
|
|
45407
|
-
const msg = messages[i];
|
|
45408
|
-
if (!msg.id || grouped.has(msg.id)) continue;
|
|
45409
|
-
if (!(msg.contentType === "reasoning" || isAssistantAct(msg))) continue;
|
|
45410
|
-
let reasoningStart = i;
|
|
45411
|
-
if (msg.contentType === "reasoning") {
|
|
45412
|
-
while (reasoningStart > 0 && messages[reasoningStart - 1].contentType === "reasoning") {
|
|
45413
|
-
reasoningStart--;
|
|
45414
|
-
}
|
|
45415
|
-
} else {
|
|
45416
|
-
let s3 = i;
|
|
45417
|
-
while (s3 > 0 && isAssistantAct(messages[s3 - 1])) s3--;
|
|
45418
|
-
reasoningStart = s3;
|
|
45419
|
-
while (reasoningStart > 0 && messages[reasoningStart - 1].contentType === "reasoning") {
|
|
45420
|
-
reasoningStart--;
|
|
45421
|
-
}
|
|
45422
|
-
}
|
|
45423
|
-
const burstStart = (() => {
|
|
45424
|
-
let s3 = reasoningStart;
|
|
45425
|
-
while (s3 < messages.length && messages[s3].contentType === "reasoning")
|
|
45426
|
-
s3++;
|
|
45427
|
-
return s3;
|
|
45428
|
-
})();
|
|
45429
|
-
if (burstStart >= messages.length || !isAssistantAct(messages[burstStart])) {
|
|
45430
|
-
continue;
|
|
45431
|
-
}
|
|
45432
|
-
let burstEnd = burstStart;
|
|
45433
|
-
while (burstEnd + 1 < messages.length && isAssistantAct(messages[burstEnd + 1])) {
|
|
45434
|
-
burstEnd++;
|
|
45435
|
-
}
|
|
45436
|
-
const members = /* @__PURE__ */ new Set();
|
|
45437
|
-
for (let k2 = reasoningStart; k2 <= burstEnd; k2++) {
|
|
45438
|
-
const m2 = messages[k2];
|
|
45439
|
-
if (!m2.id) continue;
|
|
45440
|
-
members.add(m2.id);
|
|
45441
|
-
if (m2.role === "assistant" && m2.contentType === "tool-call" && typeof m2.toolCallId === "string") {
|
|
45442
|
-
const rid = resultIdByCallId.get(m2.toolCallId);
|
|
45443
|
-
if (rid) members.add(rid);
|
|
45444
|
-
}
|
|
45445
|
-
}
|
|
45446
|
-
for (const id of members) grouped.add(id);
|
|
45447
|
-
groups.push([...members]);
|
|
45448
|
-
}
|
|
45449
|
-
return groups;
|
|
45450
|
-
}
|
|
45451
45382
|
function estimateTextTokens(text) {
|
|
45452
45383
|
return Math.ceil(text.length / 4);
|
|
45453
45384
|
}
|
|
@@ -45471,7 +45402,7 @@ function computeProtectedRefs(messages, state, config, countTokens = estimateTex
|
|
|
45471
45402
|
if (isNeverPreserveRecent(msg)) continue;
|
|
45472
45403
|
const ref = state.messageRefs.byRaw[msg.id];
|
|
45473
45404
|
if (!ref || ref === "BLOCKED") continue;
|
|
45474
|
-
visible.push({ ref, tokens:
|
|
45405
|
+
visible.push({ ref, tokens: countTokens(msg.text ?? "") });
|
|
45475
45406
|
}
|
|
45476
45407
|
if (preserveN > 0) {
|
|
45477
45408
|
for (const m2 of visible.slice(-preserveN)) {
|
|
@@ -45514,7 +45445,7 @@ function buildCompressibleRanges(messages, state, config, protectedZoneRefs, cou
|
|
|
45514
45445
|
protectedMsgs.push({
|
|
45515
45446
|
ref,
|
|
45516
45447
|
gapBefore: skipSinceProtected,
|
|
45517
|
-
tokens:
|
|
45448
|
+
tokens: countTokens(msg.text ?? ""),
|
|
45518
45449
|
tools: msg.toolName ? [msg.toolName] : []
|
|
45519
45450
|
});
|
|
45520
45451
|
skipSinceProtected = false;
|
|
@@ -45529,7 +45460,7 @@ function buildCompressibleRanges(messages, state, config, protectedZoneRefs, cou
|
|
|
45529
45460
|
compressibleMsgs.push({
|
|
45530
45461
|
ref,
|
|
45531
45462
|
gapBefore: skipSinceCompressible,
|
|
45532
|
-
tokens:
|
|
45463
|
+
tokens: countTokens(msg.text ?? ""),
|
|
45533
45464
|
chars: (msg.text ?? "").length,
|
|
45534
45465
|
isTool: isToolMessage(msg),
|
|
45535
45466
|
isUser: msg.role === "user"
|
|
@@ -46162,42 +46093,6 @@ function applySingleRange(input) {
|
|
|
46162
46093
|
)} from compression range (recent/last-user zone).`
|
|
46163
46094
|
);
|
|
46164
46095
|
}
|
|
46165
|
-
{
|
|
46166
|
-
const reasoningIds = /* @__PURE__ */ new Set();
|
|
46167
|
-
const callIds = /* @__PURE__ */ new Set();
|
|
46168
|
-
for (const m2 of input.messages) {
|
|
46169
|
-
if (!m2.id) continue;
|
|
46170
|
-
if (m2.contentType === "reasoning") reasoningIds.add(m2.id);
|
|
46171
|
-
if (m2.role === "assistant" && m2.contentType === "tool-call") callIds.add(m2.id);
|
|
46172
|
-
}
|
|
46173
|
-
const withdrawIds = /* @__PURE__ */ new Set();
|
|
46174
|
-
let splitTurnCount = 0;
|
|
46175
|
-
for (const group of computeTurnGroups(input.messages)) {
|
|
46176
|
-
const foldHasReasoning = group.some(
|
|
46177
|
-
(id) => effectiveMessageIds.has(id) && reasoningIds.has(id)
|
|
46178
|
-
);
|
|
46179
|
-
if (!foldHasReasoning) continue;
|
|
46180
|
-
const keptHasCall = group.some(
|
|
46181
|
-
(id) => !effectiveMessageIds.has(id) && callIds.has(id)
|
|
46182
|
-
);
|
|
46183
|
-
if (!keptHasCall) continue;
|
|
46184
|
-
splitTurnCount++;
|
|
46185
|
-
for (const id of group) withdrawIds.add(id);
|
|
46186
|
-
}
|
|
46187
|
-
if (withdrawIds.size > 0) {
|
|
46188
|
-
for (const id of withdrawIds) effectiveMessageIds.delete(id);
|
|
46189
|
-
const beforeWithdraw = filteredIds.length;
|
|
46190
|
-
filteredIds = filteredIds.filter((id) => !withdrawIds.has(id));
|
|
46191
|
-
if (filteredIds.length === 0 && consumedBlockIds.length === 0) {
|
|
46192
|
-
throw new Error(
|
|
46193
|
-
`Range would split ${splitTurnCount} turn(s) at the protected-zone boundary: a visible tool-call must keep its reasoning run (strict-echo providers reject a rebuilt request that lost it). Shrink the range to end before the turn starts, or wait until the whole turn ages out of the protected zone.`
|
|
46194
|
-
);
|
|
46195
|
-
}
|
|
46196
|
-
warnings.push(
|
|
46197
|
-
`Withdrawn ${beforeWithdraw - filteredIds.length} message(s) from compression range to keep ${splitTurnCount} turn(s) intact (visible tool-call would lose its reasoning run).`
|
|
46198
|
-
);
|
|
46199
|
-
}
|
|
46200
|
-
}
|
|
46201
46096
|
if (!isBlockBoundary && filteredIds.length === 0 && consumedBlockIds.length > 0) {
|
|
46202
46097
|
const first = consumedBlockIds[0];
|
|
46203
46098
|
const last = consumedBlockIds[consumedBlockIds.length - 1];
|
|
@@ -46211,7 +46106,7 @@ function applySingleRange(input) {
|
|
|
46211
46106
|
let compressedTokens = 0;
|
|
46212
46107
|
for (const id of filteredIds) {
|
|
46213
46108
|
const message = input.messages.find((entry) => entry.id === id);
|
|
46214
|
-
compressedTokens +=
|
|
46109
|
+
compressedTokens += input.countTokens(message?.text ?? "");
|
|
46215
46110
|
}
|
|
46216
46111
|
for (const consumedId of consumedBlockIds) {
|
|
46217
46112
|
const consumed = blockById(input.state, consumedId);
|
|
@@ -46541,7 +46436,7 @@ function computeContextBreakdown(messages, total, growth, countTokens) {
|
|
|
46541
46436
|
const count = countTokens ?? ((t) => Math.ceil(t.length / 4));
|
|
46542
46437
|
let system = 0, tool = 0, summaries = 0, code = 0, text = 0;
|
|
46543
46438
|
for (const msg of messages) {
|
|
46544
|
-
const tokens =
|
|
46439
|
+
const tokens = count(msg.text ?? "");
|
|
46545
46440
|
if (msg.text?.startsWith("[Compressed conversation section]")) {
|
|
46546
46441
|
summaries += tokens;
|
|
46547
46442
|
} else if (msg.contentType === "tool-call" || msg.contentType === "tool-result") {
|
|
@@ -46727,7 +46622,7 @@ function collectVisible(messages, state, countTokens) {
|
|
|
46727
46622
|
if (coveredIds.has(message.id)) return;
|
|
46728
46623
|
const ref = refForRaw(state.messageRefs, message.id);
|
|
46729
46624
|
if (!ref) return;
|
|
46730
|
-
const tokens =
|
|
46625
|
+
const tokens = countTokens(message.text ?? "");
|
|
46731
46626
|
const tool = isToolMessage(message) ? message.toolName ?? (message.toolCallId ? toolCallNames.get(message.toolCallId) : void 0) ?? "tool" : "text";
|
|
46732
46627
|
if (tokens > 0) visible.push({ ref, tokens, tool, index });
|
|
46733
46628
|
});
|
|
@@ -53826,11 +53721,6 @@ async function* runCompressLoop(upstream, ctx, requestBody, requestOptions, adap
|
|
|
53826
53721
|
}
|
|
53827
53722
|
} catch (e) {
|
|
53828
53723
|
if (!(e instanceof UpstreamHttpError)) throw e;
|
|
53829
|
-
if (e.status === 400 && /reasoning_content/i.test(e.body) && ctx.session.metadata.strictReasoningEcho !== true) {
|
|
53830
|
-
ctx.session.metadata.strictReasoningEcho = true;
|
|
53831
|
-
ctx.log(`[acp-loop] 400 mentions reasoning_content \u2014 learned strict reasoning echo for this session; #651 reasoning-drop disabled (#684)`);
|
|
53832
|
-
log("warn", `[acp-loop] learned strictReasoningEcho (session ${ctx.session.id}); reasoning-drop disabled (#684)`);
|
|
53833
|
-
}
|
|
53834
53724
|
const suffix = e.attempts > 1 ? ` after ${e.attempts} attempt(s)` : "";
|
|
53835
53725
|
ctx.log(`[acp-proxy: compress loop upstream error ${e.status}${suffix}: ${e.body.slice(0, 200)}]`);
|
|
53836
53726
|
log("error", `[acp-loop] upstream error ${e.status}${suffix}: ${e.body.slice(0, 200)}`);
|
|
@@ -59646,7 +59536,7 @@ ${bodyBuffer.toString("utf8")}`);
|
|
|
59646
59536
|
log2("info", `[debug] strip-images: dropped ${stripped.removed} historical image part(s), kept last ${keepRecent} (session=${session.id})`);
|
|
59647
59537
|
}
|
|
59648
59538
|
const work = stripped.body;
|
|
59649
|
-
return countTokens ? prepareCountTokens(work, core, reqConfig, log2, session) : protocol === "anthropic" ? prepareAnthropic(work, req, opts, core, reqConfig, reqPrompts, log2, session, pluginMode,
|
|
59539
|
+
return countTokens ? prepareCountTokens(work, core, reqConfig, log2, session) : protocol === "anthropic" ? prepareAnthropic(work, req, opts, core, reqConfig, reqPrompts, log2, session, pluginMode, reasoningCfg) : protocol === "openai" ? prepareOpenai(work, req, opts, core, reqConfig, reqPrompts, log2, session, pluginMode, nativeWindow, reasoningCfg) : responsesCompact ? prepareResponsesCompact(stripped.removed > 0 ? Buffer.from(JSON.stringify(work)) : bodyBuffer, work, session, req, core, reqConfig, log2) : prepareResponses(work, req, opts, core, reqConfig, reqPrompts, log2, session, responsesIdentity, pluginMode, upstreamOrigin, nativeWindow, reasoningCfg);
|
|
59650
59540
|
};
|
|
59651
59541
|
const isCodexCompactTrigger = protocol === "responses" && !responsesCompact && isCodexClient(req.headers) && hasCompactionTrigger(parsed.input);
|
|
59652
59542
|
if (isCodexCompactTrigger) {
|
|
@@ -59734,64 +59624,13 @@ ${bodyBuffer.toString("utf8")}`);
|
|
|
59734
59624
|
}
|
|
59735
59625
|
}
|
|
59736
59626
|
var ACP_TAG_MARK = "<acp ";
|
|
59737
|
-
function withReasoningDrop(msgs, reasoning, log2, sessionId
|
|
59738
|
-
if (strictEcho) return msgs;
|
|
59627
|
+
function withReasoningDrop(msgs, reasoning, log2, sessionId) {
|
|
59739
59628
|
const out = dropCompressReasoning(msgs, reasoning);
|
|
59740
59629
|
if (out.length !== msgs.length) {
|
|
59741
59630
|
log2("info", `[${sessionId}] compress-reasoning: dropped ${msgs.length - out.length} reasoning message(s) from closed compress turns (#651)`);
|
|
59742
59631
|
}
|
|
59743
59632
|
return out;
|
|
59744
59633
|
}
|
|
59745
|
-
function isStrictReasoningEcho(session, upstreamOrigin) {
|
|
59746
|
-
if (session.metadata.strictReasoningEcho === true) return true;
|
|
59747
|
-
return upstreamOrigin !== void 0 && /deepseek/i.test(upstreamOrigin);
|
|
59748
|
-
}
|
|
59749
|
-
function warnReasoningPairs(wireMessages, log2, sessionId) {
|
|
59750
|
-
let withRc = 0;
|
|
59751
|
-
let split = 0;
|
|
59752
|
-
for (const m2 of wireMessages) {
|
|
59753
|
-
const msg = m2;
|
|
59754
|
-
if (msg?.role !== "assistant") continue;
|
|
59755
|
-
const hasRc = typeof msg.reasoning_content === "string" && msg.reasoning_content.length > 0;
|
|
59756
|
-
if (hasRc) withRc++;
|
|
59757
|
-
else if (Array.isArray(msg.tool_calls) && msg.tool_calls.length > 0) split++;
|
|
59758
|
-
}
|
|
59759
|
-
if (withRc > 0 && split > 0) {
|
|
59760
|
-
log2("warn", `[${sessionId}] reasoning-pair-violated: ${split} assistant tool-call message(s) lack reasoning_content while ${withRc} carry it \u2014 strict-echo upstreams (DeepSeek thinking mode) will reject the request (#684)`);
|
|
59761
|
-
}
|
|
59762
|
-
}
|
|
59763
|
-
function warnAnthropicThinkingPairs(wireMessages, log2, sessionId) {
|
|
59764
|
-
let withThinking = 0;
|
|
59765
|
-
let split = 0;
|
|
59766
|
-
for (const m2 of wireMessages) {
|
|
59767
|
-
const msg = m2;
|
|
59768
|
-
if (msg?.role !== "assistant" || !Array.isArray(msg.content)) continue;
|
|
59769
|
-
const hasThinking = msg.content.some((b2) => b2?.type === "thinking");
|
|
59770
|
-
if (hasThinking) withThinking++;
|
|
59771
|
-
else if (msg.content.some((b2) => b2?.type === "tool_use")) split++;
|
|
59772
|
-
}
|
|
59773
|
-
if (withThinking > 0 && split > 0) {
|
|
59774
|
-
log2("warn", `[${sessionId}] thinking-pair-violated: ${split} assistant tool_use message(s) lack a thinking block while ${withThinking} carry one \u2014 extended-thinking tool use requires preserved thinking (#684)`);
|
|
59775
|
-
}
|
|
59776
|
-
}
|
|
59777
|
-
function warnResponsesReasoningPairs(input, log2, sessionId) {
|
|
59778
|
-
let withReasoning = 0;
|
|
59779
|
-
let split = 0;
|
|
59780
|
-
let prevWasReasoning = false;
|
|
59781
|
-
for (const item of input) {
|
|
59782
|
-
const it2 = item;
|
|
59783
|
-
if (it2?.type === "reasoning") {
|
|
59784
|
-
withReasoning++;
|
|
59785
|
-
prevWasReasoning = true;
|
|
59786
|
-
continue;
|
|
59787
|
-
}
|
|
59788
|
-
if (it2?.type === "function_call" && !prevWasReasoning) split++;
|
|
59789
|
-
prevWasReasoning = false;
|
|
59790
|
-
}
|
|
59791
|
-
if (withReasoning > 0 && split > 0) {
|
|
59792
|
-
log2("warn", `[${sessionId}] reasoning-pair-violated: ${split} function_call item(s) lack a preceding reasoning item while ${withReasoning} exist \u2014 strict-echo upstreams will reject the request (#684)`);
|
|
59793
|
-
}
|
|
59794
|
-
}
|
|
59795
59634
|
function stripKernelSummaries(messages, state) {
|
|
59796
59635
|
const carried = /* @__PURE__ */ new Set();
|
|
59797
59636
|
for (const b2 of state.blocks) {
|
|
@@ -59895,13 +59734,13 @@ function effectiveTokenCount(session, msgs) {
|
|
|
59895
59734
|
if (!session.metadata.anonymousPrefixAffinity) return 0;
|
|
59896
59735
|
return estimateCoreMessagesUpper(msgs);
|
|
59897
59736
|
}
|
|
59898
|
-
function prepareAnthropic(parsed, req, opts, core, config, prompts, log2, session, pluginMode,
|
|
59737
|
+
function prepareAnthropic(parsed, req, opts, core, config, prompts, log2, session, pluginMode, reasoning) {
|
|
59899
59738
|
const sessionId = session.id;
|
|
59900
59739
|
const stream2 = parsed.stream === true;
|
|
59901
59740
|
++session.stats.requests;
|
|
59902
59741
|
session.hostCreditTokens = 0;
|
|
59903
59742
|
const injectTools = opts.compress.injectTool && !pluginMode;
|
|
59904
|
-
const stripReasoning = (msgs) => withReasoningDrop(msgs, reasoning, log2, sessionId
|
|
59743
|
+
const stripReasoning = (msgs) => withReasoningDrop(msgs, reasoning, log2, sessionId);
|
|
59905
59744
|
if (isAutoModeClassifier(parsed)) {
|
|
59906
59745
|
log2("info", `[${sessionId}] auto-mode classifier passthrough (skipping compress injection)`);
|
|
59907
59746
|
return { body: JSON.stringify(parsed), session, processedMessages: [], originalMessages: [], anthropicSystem: parsed.system, protocol: "anthropic", stream: stream2, compressInjected: false, pluginMode, nudge: void 0, prompts };
|
|
@@ -59964,7 +59803,6 @@ function prepareAnthropic(parsed, req, opts, core, config, prompts, log2, sessio
|
|
|
59964
59803
|
snapshotMessages(session, originalMessages);
|
|
59965
59804
|
markDirty(session);
|
|
59966
59805
|
const rebuilt = { ...parsed, messages: rebuiltMessages, system: systemOut, tools: toolsOut };
|
|
59967
|
-
warnAnthropicThinkingPairs(rebuiltMessages, log2, sessionId);
|
|
59968
59806
|
delete rebuilt.prompt_cache_key;
|
|
59969
59807
|
armHostUsageCredit(session, originalMessages, processedMessages, req.headers, opts.hostUsageCredit, log2);
|
|
59970
59808
|
return { body: JSON.stringify(rebuilt), session, processedMessages, originalMessages, anthropicSystem: parsed.system, protocol: "anthropic", stream: stream2, compressInjected: injectTools, pluginMode, nudge, prompts, renderTags: "text-only" };
|
|
@@ -60022,13 +59860,13 @@ function clampOutgoingOutput(rebuilt, field, ctx, sessionId, log2) {
|
|
|
60022
59860
|
log2("info", `[${sessionId}] output budget clamped ${raw} -> ${capped} (input~${inputEstimate}, window=${ctx.nativeWindow}); prevents input+output overflow (#453)`);
|
|
60023
59861
|
}
|
|
60024
59862
|
}
|
|
60025
|
-
function prepareOpenai(parsed, req, opts, core, config, prompts, log2, session, pluginMode,
|
|
59863
|
+
function prepareOpenai(parsed, req, opts, core, config, prompts, log2, session, pluginMode, nativeWindow, reasoning) {
|
|
60026
59864
|
const sessionId = session.id;
|
|
60027
59865
|
const stream2 = parsed.stream === true;
|
|
60028
59866
|
++session.stats.requests;
|
|
60029
59867
|
session.hostCreditTokens = 0;
|
|
60030
59868
|
let openaiSystemText = "";
|
|
60031
|
-
const stripReasoning = (msgs) => withReasoningDrop(msgs, reasoning, log2, sessionId
|
|
59869
|
+
const stripReasoning = (msgs) => withReasoningDrop(msgs, reasoning, log2, sessionId);
|
|
60032
59870
|
let openaiOutboundSystem;
|
|
60033
59871
|
let processedMessages = [];
|
|
60034
59872
|
let originalMessages = [];
|
|
@@ -60093,7 +59931,6 @@ function prepareOpenai(parsed, req, opts, core, config, prompts, log2, session,
|
|
|
60093
59931
|
processedMessages = [];
|
|
60094
59932
|
}
|
|
60095
59933
|
const rebuilt = { ...parsed, messages: rebuiltMessages, tools: toolsOut };
|
|
60096
|
-
warnReasoningPairs(rebuiltMessages, log2, sessionId);
|
|
60097
59934
|
clampOutgoingOutput(rebuilt, typeof parsed.max_completion_tokens === "number" ? "max_completion_tokens" : "max_tokens", { systemText: openaiSystemText, tools: toolsOut, processedMessages, lastInputTokens: session.stats.lastInputTokens, nativeWindow, imageTokens: imageTokensInParsedBody("openai", rebuilt) }, sessionId, log2);
|
|
60098
59935
|
delete rebuilt.prompt_cache_retention;
|
|
60099
59936
|
if (stream2 && rebuilt.stream_options === void 0) {
|
|
@@ -60112,7 +59949,7 @@ function prepareResponses(parsed, req, opts, core, config, prompts, log2, sessio
|
|
|
60112
59949
|
const stream2 = parsed.stream === true;
|
|
60113
59950
|
++session.stats.requests;
|
|
60114
59951
|
session.hostCreditTokens = 0;
|
|
60115
|
-
const stripReasoning = (msgs) => withReasoningDrop(msgs, reasoning, log2, sessionId
|
|
59952
|
+
const stripReasoning = (msgs) => withReasoningDrop(msgs, reasoning, log2, sessionId);
|
|
60116
59953
|
if (reconcileNativeCompactionBoundary(session)) {
|
|
60117
59954
|
log2("info", `[${sessionId}] reconciled ACP state after native Responses compact boundary`);
|
|
60118
59955
|
}
|
|
@@ -60230,7 +60067,6 @@ function prepareResponses(parsed, req, opts, core, config, prompts, log2, sessio
|
|
|
60230
60067
|
log2("info", `[${sessionId}] codex compact intercepted (trigger); forged SSE with ${summaries.length} block summary(s), upstream not contacted`);
|
|
60231
60068
|
}
|
|
60232
60069
|
const rebuilt = { ...parsed, input: rebuiltInput, tools: toolsOut };
|
|
60233
|
-
warnResponsesReasoningPairs(Array.isArray(rebuiltInput) ? rebuiltInput : [], log2, sessionId);
|
|
60234
60070
|
if (!isCompactionTrigger) {
|
|
60235
60071
|
clampOutgoingOutput(rebuilt, "max_output_tokens", { systemText: (responsesProjection?.systemParts ?? []).join("\n"), tools: toolsOut, processedMessages, lastInputTokens: session.stats.lastInputTokens, nativeWindow, imageTokens: imageTokensInParsedBody("responses", rebuilt) }, sessionId, log2);
|
|
60236
60072
|
}
|