billion-context-pi 0.1.62-pr.349.142 → 0.1.62
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 +6 -25
- package/dist/index.js.map +1 -1
- package/dist/reasoning-drop.d.ts +6 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3982,22 +3982,6 @@ function hasCompressCall(content) {
|
|
|
3982
3982
|
return b2?.type === "toolCall" && b2.name === "compress";
|
|
3983
3983
|
});
|
|
3984
3984
|
}
|
|
3985
|
-
function compressCallIds(content) {
|
|
3986
|
-
if (!Array.isArray(content)) return [];
|
|
3987
|
-
return content.filter((p) => {
|
|
3988
|
-
const b2 = p;
|
|
3989
|
-
return b2?.type === "toolCall" && b2.name === "compress";
|
|
3990
|
-
}).map((p) => p.id).filter((id) => typeof id === "string");
|
|
3991
|
-
}
|
|
3992
|
-
function resultIndexByCallId(messages) {
|
|
3993
|
-
const map = /* @__PURE__ */ new Map();
|
|
3994
|
-
for (let i = 0; i < messages.length; i++) {
|
|
3995
|
-
const msg = messages[i];
|
|
3996
|
-
if (msg?.role !== "toolResult" || typeof msg.toolCallId !== "string") continue;
|
|
3997
|
-
if (!map.has(msg.toolCallId)) map.set(msg.toolCallId, i);
|
|
3998
|
-
}
|
|
3999
|
-
return map;
|
|
4000
|
-
}
|
|
4001
3985
|
function reasoningLength(content) {
|
|
4002
3986
|
if (!Array.isArray(content)) return 0;
|
|
4003
3987
|
return content.reduce((n, p) => isThinking(p) ? n + p.thinking.length : n, 0);
|
|
@@ -4006,20 +3990,17 @@ function dropCompressReasoning(messages, cfg) {
|
|
|
4006
3990
|
const { drop, threshold } = resolveReasoningDrop(cfg);
|
|
4007
3991
|
if (!drop || messages.length === 0) return messages;
|
|
4008
3992
|
try {
|
|
4009
|
-
|
|
4010
|
-
|
|
3993
|
+
let lastUser = -1;
|
|
3994
|
+
for (let i = 0; i < messages.length; i++) {
|
|
3995
|
+
if (messages[i].role === "user") lastUser = i;
|
|
3996
|
+
}
|
|
3997
|
+
if (lastUser < 0) return messages;
|
|
4011
3998
|
let changed = false;
|
|
4012
3999
|
const out = messages.slice();
|
|
4013
|
-
for (let i = 0; i
|
|
4000
|
+
for (let i = 0; i < lastUser; i++) {
|
|
4014
4001
|
const msg = messages[i];
|
|
4015
4002
|
if (msg.role !== "assistant" || !Array.isArray(msg.content)) continue;
|
|
4016
4003
|
if (!hasCompressCall(msg.content)) continue;
|
|
4017
|
-
const ids = compressCallIds(msg.content);
|
|
4018
|
-
const closed = ids.length > 0 && ids.every((id) => {
|
|
4019
|
-
const ri = resultAt.get(id);
|
|
4020
|
-
return ri !== void 0 && ri > i && ri < last;
|
|
4021
|
-
});
|
|
4022
|
-
if (!closed) continue;
|
|
4023
4004
|
if (reasoningLength(msg.content) <= threshold) continue;
|
|
4024
4005
|
out[i] = {
|
|
4025
4006
|
...msg,
|