@deepstrike/wasm 0.2.12 → 0.2.14
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/providers/anthropic.js +22 -12
- package/dist/providers/base.js +10 -7
- package/dist/types.d.ts +3 -1
- package/package.json +2 -2
|
@@ -19,17 +19,26 @@ function buildAnthropicTools(tools, anchorCache) {
|
|
|
19
19
|
* Roll cache breakpoints across the conversation tail so the message-history
|
|
20
20
|
* prefix is written once and re-read on later turns (without this the cached
|
|
21
21
|
* prefix stops at the end of `system` and the whole tool-result history is
|
|
22
|
-
* re-billed at full input price every turn).
|
|
23
|
-
*
|
|
24
|
-
* a
|
|
22
|
+
* re-billed at full input price every turn).
|
|
23
|
+
*
|
|
24
|
+
* When `frozenPrefixLen` marks a distinct frozen prefix (the compaction
|
|
25
|
+
* boundary), pin the deep breakpoint there — it is byte-stable across turns,
|
|
26
|
+
* so `[0..frozen]` is re-read cheaply every turn; the tail breakpoint writes
|
|
27
|
+
* only the incremental `[frozen..tail]`. Otherwise fall back to the rolling
|
|
28
|
+
* pair: final message + nearest preceding user turn.
|
|
25
29
|
*/
|
|
26
|
-
function applyMessageCacheControl(msgs) {
|
|
30
|
+
function applyMessageCacheControl(msgs, frozenPrefixLen) {
|
|
27
31
|
if (!msgs.length)
|
|
28
32
|
return;
|
|
29
33
|
const targets = new Set([msgs.length - 1]);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
if (typeof frozenPrefixLen === "number" && frozenPrefixLen >= 1 && frozenPrefixLen < msgs.length) {
|
|
35
|
+
targets.add(frozenPrefixLen - 1);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
for (let i = msgs.length - 2; i >= 0 && targets.size < MESSAGE_CACHE_BREAKPOINTS; i--) {
|
|
39
|
+
if (msgs[i].role === "user")
|
|
40
|
+
targets.add(i);
|
|
41
|
+
}
|
|
33
42
|
}
|
|
34
43
|
for (const idx of targets)
|
|
35
44
|
markLastBlockCacheable(msgs[idx]);
|
|
@@ -110,14 +119,15 @@ export class AnthropicProvider {
|
|
|
110
119
|
}
|
|
111
120
|
const system = systemBlocks.length ? systemBlocks : (context.systemText || undefined);
|
|
112
121
|
const msgs = toAnthropicMessages(context, message => this.nativeAssistantBlocks.get(assistantReplayKey(message)));
|
|
113
|
-
applyMessageCacheControl(msgs);
|
|
122
|
+
applyMessageCacheControl(msgs, context.frozenPrefixLen);
|
|
114
123
|
// Append the volatile State turn AFTER the cache breakpoints (uncached tail);
|
|
115
124
|
// absent on un-rebuilt bindings, where the state is already inside `turns`.
|
|
125
|
+
// Render through toAnthropicMessages so assistant tool_use blocks are
|
|
126
|
+
// serialized correctly — raw content would silently drop toolCalls.
|
|
116
127
|
if (context.stateTurn) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
});
|
|
128
|
+
const stateCtx = { systemText: "", turns: [context.stateTurn] };
|
|
129
|
+
const stateMsgs = toAnthropicMessages(stateCtx, message => this.nativeAssistantBlocks.get(assistantReplayKey(message)));
|
|
130
|
+
msgs.push(...stateMsgs);
|
|
121
131
|
}
|
|
122
132
|
assertCacheBudget(system, tools.length);
|
|
123
133
|
const body = {
|
package/dist/providers/base.js
CHANGED
|
@@ -66,7 +66,16 @@ export function toAnthropicMessages(context, nativeReplay) {
|
|
|
66
66
|
const result = [];
|
|
67
67
|
for (const msg of context.turns) {
|
|
68
68
|
if (msg.role === "tool") {
|
|
69
|
-
|
|
69
|
+
const parts = (msg.contentParts ?? [])
|
|
70
|
+
.filter(p => p.type === "tool_result")
|
|
71
|
+
.map(p => ({ type: "tool_result", tool_use_id: p.callId, content: p.output, is_error: p.isError ?? false }));
|
|
72
|
+
if (parts.length) {
|
|
73
|
+
result.push({ role: "user", content: parts });
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
// Fallback for messages without structured contentParts
|
|
77
|
+
result.push({ role: "user", content: [{ type: "tool_result", tool_use_id: "", content: msg.content, is_error: false }] });
|
|
78
|
+
}
|
|
70
79
|
continue;
|
|
71
80
|
}
|
|
72
81
|
if (msg.role === "assistant" && msg.toolCalls?.length) {
|
|
@@ -92,12 +101,6 @@ export function toAnthropicMessages(context, nativeReplay) {
|
|
|
92
101
|
content: msg.contentParts?.length ? anthropicPartsContent(msg.contentParts) : msg.content,
|
|
93
102
|
});
|
|
94
103
|
}
|
|
95
|
-
if (context.systemVolatile && result.length > 0) {
|
|
96
|
-
const last = result[result.length - 1];
|
|
97
|
-
if (last.role === "user") {
|
|
98
|
-
last.content = `${String(last.content ?? "")}\n\n[SYSTEM REMINDER]\n${context.systemVolatile}`;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
104
|
return result;
|
|
102
105
|
}
|
|
103
106
|
/** Collect a non-streaming assistant Message from stream events. */
|
package/dist/types.d.ts
CHANGED
|
@@ -47,11 +47,13 @@ export interface RenderedContext {
|
|
|
47
47
|
systemText: string;
|
|
48
48
|
systemStable?: string;
|
|
49
49
|
systemKnowledge?: string;
|
|
50
|
-
systemVolatile?: string;
|
|
51
50
|
turns: Message[];
|
|
52
51
|
/** Volatile State turn (task_state + signals), rendered after the cacheable
|
|
53
52
|
* history. Absent on un-rebuilt bindings — then it's still inside turns[0]. */
|
|
54
53
|
stateTurn?: Message;
|
|
54
|
+
/** Message count of the frozen history prefix (compaction boundary). When set,
|
|
55
|
+
* Anthropic pins a deep cache breakpoint here instead of the rolling pair. */
|
|
56
|
+
frozenPrefixLen?: number;
|
|
55
57
|
}
|
|
56
58
|
export interface StreamEvent {
|
|
57
59
|
type: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepstrike/wasm",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.14",
|
|
4
4
|
"description": "DeepStrike WASM SDK — browser, Cloudflare Workers, Deno Deploy",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"test": "node --experimental-vm-modules node_modules/.bin/jest"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@deepstrike/wasm-kernel": "0.2.
|
|
18
|
+
"@deepstrike/wasm-kernel": "0.2.14"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@types/jest": "^30.0.0",
|