acp-kernel 0.0.69 → 0.0.70-pr.293.160
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/compress.d.ts.map +1 -1
- package/dist/index.js +62 -3
- package/dist/index.js.map +1 -1
- package/dist/wire/bili-message.d.ts +12 -4
- package/dist/wire/bili-message.d.ts.map +1 -1
- package/dist/wire/index.js +32 -12
- package/dist/wire/index.js.map +1 -1
- package/dist/wire/openai.d.ts.map +1 -1
- package/dist/wire/responses.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/compress.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compress.d.ts","sourceRoot":"","sources":["../src/compress.ts"],"names":[],"mappings":"AAIA,OAAO,EAAkC,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAgBhF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAUvD,OAAO,EAGL,KAAK,YAAY,EAElB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EACV,sBAAsB,EACtB,gBAAgB,EAChB,gBAAgB,EAEhB,MAAM,EAEN,WAAW,EAGX,iBAAiB,EAEjB,YAAY,EACb,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,KAAK;IACpB,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CACxC;AAED,MAAM,WAAW,eAAe;IAC9B,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,iBAAiB,CAAC;IACxD,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,sBAAsB,CAAC;IACvE,YAAY,IAAI,YAAY,EAAE,CAAC;IAC/B,UAAU,CACR,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,gBAAgB,GACtB,gBAAgB,GAAG,SAAS,CAAC;IAChC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,GAAG,gBAAgB,EAA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G,eAAe,CAyU7D;AA4iCD,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -165,9 +165,43 @@ function collectSummaryAnchors(state, indexById, summaryIndexById) {
|
|
|
165
165
|
anchors.sort((left, right) => left.insertAt - right.insertAt);
|
|
166
166
|
return anchors;
|
|
167
167
|
}
|
|
168
|
+
function pairSafeAnchorIndex(messages, index) {
|
|
169
|
+
let safe = index;
|
|
170
|
+
while (safe > 0 && safe < messages.length && messages[safe - 1].role === "assistant" && messages[safe].role === "assistant") {
|
|
171
|
+
safe--;
|
|
172
|
+
}
|
|
173
|
+
const resultIndexByCallId = /* @__PURE__ */ new Map();
|
|
174
|
+
messages.forEach((message, at) => {
|
|
175
|
+
if (message.contentType !== "tool-result") return;
|
|
176
|
+
if (typeof message.toolCallId !== "string") return;
|
|
177
|
+
if (!resultIndexByCallId.has(message.toolCallId)) {
|
|
178
|
+
resultIndexByCallId.set(message.toolCallId, at);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
for (let guard = 0; guard < messages.length; guard++) {
|
|
182
|
+
let moved = safe;
|
|
183
|
+
for (let at = 0; at < safe && at < messages.length; at++) {
|
|
184
|
+
const message = messages[at];
|
|
185
|
+
if (message.role !== "assistant") continue;
|
|
186
|
+
if (message.contentType !== "tool-call") continue;
|
|
187
|
+
if (typeof message.toolCallId !== "string") continue;
|
|
188
|
+
const resultIndex = resultIndexByCallId.get(message.toolCallId);
|
|
189
|
+
if (resultIndex !== void 0 && resultIndex >= safe && resultIndex + 1 > moved) {
|
|
190
|
+
moved = resultIndex + 1;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (moved === safe) break;
|
|
194
|
+
safe = moved;
|
|
195
|
+
}
|
|
196
|
+
return safe;
|
|
197
|
+
}
|
|
168
198
|
function rebuildMessages(messages, covered, firstUserIndex, anchors) {
|
|
199
|
+
const safeAnchors = anchors.map((anchor) => ({
|
|
200
|
+
...anchor,
|
|
201
|
+
insertAt: pairSafeAnchorIndex(messages, anchor.insertAt)
|
|
202
|
+
})).sort((left, right) => left.insertAt - right.insertAt);
|
|
169
203
|
const result = [];
|
|
170
|
-
const pending = [...
|
|
204
|
+
const pending = [...safeAnchors];
|
|
171
205
|
const anchoredSummaryIds = new Set(
|
|
172
206
|
anchors.map((anchor) => summaryMessageId(anchor.blockId))
|
|
173
207
|
);
|
|
@@ -2631,17 +2665,42 @@ function applySingleRange(input) {
|
|
|
2631
2665
|
splitTurnCount++;
|
|
2632
2666
|
for (const id of group) withdrawIds.add(id);
|
|
2633
2667
|
}
|
|
2668
|
+
const resultIdByCallId = /* @__PURE__ */ new Map();
|
|
2669
|
+
for (const m of input.messages) {
|
|
2670
|
+
if (!m.id || m.contentType !== "tool-result") continue;
|
|
2671
|
+
if (typeof m.toolCallId !== "string") continue;
|
|
2672
|
+
if (!resultIdByCallId.has(m.toolCallId)) {
|
|
2673
|
+
resultIdByCallId.set(m.toolCallId, m.id);
|
|
2674
|
+
}
|
|
2675
|
+
}
|
|
2676
|
+
let splitPairCount = 0;
|
|
2677
|
+
for (const m of input.messages) {
|
|
2678
|
+
if (!m.id || m.contentType !== "tool-call") continue;
|
|
2679
|
+
if (typeof m.toolCallId !== "string") continue;
|
|
2680
|
+
const resultId = resultIdByCallId.get(m.toolCallId);
|
|
2681
|
+
if (resultId === void 0) continue;
|
|
2682
|
+
if (effectiveMessageIds.has(m.id) === effectiveMessageIds.has(resultId)) {
|
|
2683
|
+
continue;
|
|
2684
|
+
}
|
|
2685
|
+
withdrawIds.add(m.id);
|
|
2686
|
+
withdrawIds.add(resultId);
|
|
2687
|
+
splitPairCount++;
|
|
2688
|
+
}
|
|
2634
2689
|
if (withdrawIds.size > 0) {
|
|
2635
2690
|
for (const id of withdrawIds) effectiveMessageIds.delete(id);
|
|
2636
2691
|
const beforeWithdraw = filteredIds.length;
|
|
2637
2692
|
filteredIds = filteredIds.filter((id) => !withdrawIds.has(id));
|
|
2693
|
+
const splitDesc = [
|
|
2694
|
+
splitTurnCount > 0 ? `${splitTurnCount} turn(s)` : null,
|
|
2695
|
+
splitPairCount > 0 ? `${splitPairCount} tool call/result pair(s)` : null
|
|
2696
|
+
].filter((part) => part !== null).join(" and ");
|
|
2638
2697
|
if (filteredIds.length === 0 && consumedBlockIds.length === 0) {
|
|
2639
2698
|
throw new Error(
|
|
2640
|
-
`Range would split ${
|
|
2699
|
+
`Range would split ${splitDesc} at the protected-zone boundary: a visible tool-call must keep its reasoning run and its results (strict providers reject a rebuilt request that lost either). Shrink the range to end before the turn starts, or wait until the whole turn ages out of the protected zone.`
|
|
2641
2700
|
);
|
|
2642
2701
|
}
|
|
2643
2702
|
warnings.push(
|
|
2644
|
-
`Withdrawn ${beforeWithdraw - filteredIds.length} message(s) from compression range to keep ${
|
|
2703
|
+
`Withdrawn ${beforeWithdraw - filteredIds.length} message(s) from compression range to keep ${splitDesc} intact (visible tool-call would lose its reasoning run or its results).`
|
|
2645
2704
|
);
|
|
2646
2705
|
}
|
|
2647
2706
|
}
|