@tanstack/ai 0.41.0 → 0.43.0
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/README.md +15 -1
- package/dist/esm/activities/chat/adapter.js +23 -16
- package/dist/esm/activities/chat/adapter.js.map +1 -1
- package/dist/esm/activities/chat/agent-loop-strategies.d.ts +10 -4
- package/dist/esm/activities/chat/agent-loop-strategies.js +75 -17
- package/dist/esm/activities/chat/agent-loop-strategies.js.map +1 -1
- package/dist/esm/activities/chat/cancel.d.ts +40 -0
- package/dist/esm/activities/chat/cancel.js +54 -0
- package/dist/esm/activities/chat/cancel.js.map +1 -0
- package/dist/esm/activities/chat/index.d.ts +28 -16
- package/dist/esm/activities/chat/index.js +2100 -1744
- package/dist/esm/activities/chat/index.js.map +1 -1
- package/dist/esm/activities/chat/mcp/manager.d.ts +2 -2
- package/dist/esm/activities/chat/mcp/manager.js +90 -77
- package/dist/esm/activities/chat/mcp/manager.js.map +1 -1
- package/dist/esm/activities/chat/mcp/types.d.ts +2 -2
- package/dist/esm/activities/chat/messages.js +397 -346
- package/dist/esm/activities/chat/messages.js.map +1 -1
- package/dist/esm/activities/chat/middleware/builder.js +17 -15
- package/dist/esm/activities/chat/middleware/builder.js.map +1 -1
- package/dist/esm/activities/chat/middleware/capabilities.js +78 -43
- package/dist/esm/activities/chat/middleware/capabilities.js.map +1 -1
- package/dist/esm/activities/chat/middleware/compose.d.ts +94 -1
- package/dist/esm/activities/chat/middleware/compose.js +623 -531
- package/dist/esm/activities/chat/middleware/compose.js.map +1 -1
- package/dist/esm/activities/chat/middleware/define.js +12 -5
- package/dist/esm/activities/chat/middleware/define.js.map +1 -1
- package/dist/esm/activities/chat/middleware/index.d.ts +5 -1
- package/dist/esm/activities/chat/middleware/locks.d.ts +50 -0
- package/dist/esm/activities/chat/middleware/locks.js +71 -0
- package/dist/esm/activities/chat/middleware/locks.js.map +1 -0
- package/dist/esm/activities/chat/middleware/pending-turn.d.ts +15 -0
- package/dist/esm/activities/chat/middleware/pending-turn.js +35 -0
- package/dist/esm/activities/chat/middleware/pending-turn.js.map +1 -0
- package/dist/esm/activities/chat/middleware/run-disconnect.d.ts +23 -0
- package/dist/esm/activities/chat/middleware/run-disconnect.js +42 -0
- package/dist/esm/activities/chat/middleware/run-disconnect.js.map +1 -0
- package/dist/esm/activities/chat/middleware/run-store.d.ts +283 -0
- package/dist/esm/activities/chat/middleware/run-store.js +176 -0
- package/dist/esm/activities/chat/middleware/run-store.js.map +1 -0
- package/dist/esm/activities/chat/middleware/sandbox-runtime.js +14 -8
- package/dist/esm/activities/chat/middleware/sandbox-runtime.js.map +1 -1
- package/dist/esm/activities/chat/middleware/tool-cache-middleware.js +79 -70
- package/dist/esm/activities/chat/middleware/tool-cache-middleware.js.map +1 -1
- package/dist/esm/activities/chat/middleware/types.d.ts +59 -2
- package/dist/esm/activities/chat/middleware/validate.js +23 -28
- package/dist/esm/activities/chat/middleware/validate.js.map +1 -1
- package/dist/esm/activities/chat/stream/json-parser.js +39 -25
- package/dist/esm/activities/chat/stream/json-parser.js.map +1 -1
- package/dist/esm/activities/chat/stream/message-updaters.js +275 -234
- package/dist/esm/activities/chat/stream/message-updaters.js.map +1 -1
- package/dist/esm/activities/chat/stream/processor.d.ts +24 -4
- package/dist/esm/activities/chat/stream/processor.js +1341 -1542
- package/dist/esm/activities/chat/stream/processor.js.map +1 -1
- package/dist/esm/activities/chat/stream/strategies.js +69 -53
- package/dist/esm/activities/chat/stream/strategies.js.map +1 -1
- package/dist/esm/activities/chat/tools/approval-schema.d.ts +19 -0
- package/dist/esm/activities/chat/tools/approval-schema.js +117 -0
- package/dist/esm/activities/chat/tools/approval-schema.js.map +1 -0
- package/dist/esm/activities/chat/tools/lazy-tool-manager.js +164 -191
- package/dist/esm/activities/chat/tools/lazy-tool-manager.js.map +1 -1
- package/dist/esm/activities/chat/tools/lazy-tools.js +24 -12
- package/dist/esm/activities/chat/tools/lazy-tools.js.map +1 -1
- package/dist/esm/activities/chat/tools/schema-converter.js +293 -146
- package/dist/esm/activities/chat/tools/schema-converter.js.map +1 -1
- package/dist/esm/activities/chat/tools/tool-calls.d.ts +18 -2
- package/dist/esm/activities/chat/tools/tool-calls.js +522 -531
- package/dist/esm/activities/chat/tools/tool-calls.js.map +1 -1
- package/dist/esm/activities/chat/tools/tool-definition.d.ts +75 -16
- package/dist/esm/activities/chat/tools/tool-definition.js +95 -23
- package/dist/esm/activities/chat/tools/tool-definition.js.map +1 -1
- package/dist/esm/activities/error-payload.js +85 -47
- package/dist/esm/activities/error-payload.js.map +1 -1
- package/dist/esm/activities/generateAudio/adapter.js +22 -15
- package/dist/esm/activities/generateAudio/adapter.js.map +1 -1
- package/dist/esm/activities/generateAudio/index.d.ts +4 -0
- package/dist/esm/activities/generateAudio/index.js +141 -105
- package/dist/esm/activities/generateAudio/index.js.map +1 -1
- package/dist/esm/activities/generateImage/adapter.js +22 -15
- package/dist/esm/activities/generateImage/adapter.js.map +1 -1
- package/dist/esm/activities/generateImage/index.d.ts +4 -0
- package/dist/esm/activities/generateImage/index.js +155 -111
- package/dist/esm/activities/generateImage/index.js.map +1 -1
- package/dist/esm/activities/generateSpeech/adapter.js +22 -15
- package/dist/esm/activities/generateSpeech/adapter.js.map +1 -1
- package/dist/esm/activities/generateSpeech/index.d.ts +4 -0
- package/dist/esm/activities/generateSpeech/index.js +159 -110
- package/dist/esm/activities/generateSpeech/index.js.map +1 -1
- package/dist/esm/activities/generateTranscription/adapter.js +22 -15
- package/dist/esm/activities/generateTranscription/adapter.js.map +1 -1
- package/dist/esm/activities/generateTranscription/index.d.ts +4 -0
- package/dist/esm/activities/generateTranscription/index.js +159 -100
- package/dist/esm/activities/generateTranscription/index.js.map +1 -1
- package/dist/esm/activities/generateVideo/adapter.js +36 -29
- package/dist/esm/activities/generateVideo/adapter.js.map +1 -1
- package/dist/esm/activities/generateVideo/index.d.ts +143 -19
- package/dist/esm/activities/generateVideo/index.js +456 -279
- package/dist/esm/activities/generateVideo/index.js.map +1 -1
- package/dist/esm/activities/generateVideo/snap.js +60 -48
- package/dist/esm/activities/generateVideo/snap.js.map +1 -1
- package/dist/esm/activities/index.js +8 -34
- package/dist/esm/activities/middleware/index.d.ts +1 -1
- package/dist/esm/activities/middleware/run.d.ts +10 -0
- package/dist/esm/activities/middleware/run.js +53 -29
- package/dist/esm/activities/middleware/run.js.map +1 -1
- package/dist/esm/activities/middleware/types.d.ts +44 -6
- package/dist/esm/activities/stream-generation-result.d.ts +4 -1
- package/dist/esm/activities/stream-generation-result.js +79 -44
- package/dist/esm/activities/stream-generation-result.js.map +1 -1
- package/dist/esm/activities/summarize/adapter.js +22 -15
- package/dist/esm/activities/summarize/adapter.js.map +1 -1
- package/dist/esm/activities/summarize/chat-stream-summarize.js +252 -202
- package/dist/esm/activities/summarize/chat-stream-summarize.js.map +1 -1
- package/dist/esm/activities/summarize/index.d.ts +27 -0
- package/dist/esm/activities/summarize/index.js +268 -102
- package/dist/esm/activities/summarize/index.js.map +1 -1
- package/dist/esm/adapter-internals.d.ts +2 -1
- package/dist/esm/adapter-internals.js +4 -11
- package/dist/esm/client.d.ts +25 -3
- package/dist/esm/client.js +131 -64
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/custom-events.d.ts +76 -0
- package/dist/esm/custom-events.js +37 -0
- package/dist/esm/custom-events.js.map +1 -0
- package/dist/esm/delivery-detach.d.ts +50 -0
- package/dist/esm/delivery-detach.js +71 -0
- package/dist/esm/delivery-detach.js.map +1 -0
- package/dist/esm/delivery-disconnect.d.ts +62 -0
- package/dist/esm/delivery-disconnect.js +81 -0
- package/dist/esm/delivery-disconnect.js.map +1 -0
- package/dist/esm/extend-adapter.js +19 -17
- package/dist/esm/extend-adapter.js.map +1 -1
- package/dist/esm/index.d.ts +23 -5
- package/dist/esm/index.js +30 -97
- package/dist/esm/interrupt-resume.d.ts +71 -0
- package/dist/esm/interrupt-resume.js +438 -0
- package/dist/esm/interrupt-resume.js.map +1 -0
- package/dist/esm/interrupt-serialization.d.ts +12 -0
- package/dist/esm/interrupt-serialization.js +178 -0
- package/dist/esm/interrupt-serialization.js.map +1 -0
- package/dist/esm/interrupts.d.ts +84 -0
- package/dist/esm/interrupts.js +31 -0
- package/dist/esm/interrupts.js.map +1 -0
- package/dist/esm/locks.d.ts +10 -0
- package/dist/esm/locks.js +2 -0
- package/dist/esm/logger/console-logger.js +101 -78
- package/dist/esm/logger/console-logger.js.map +1 -1
- package/dist/esm/logger/internal-logger.js +104 -89
- package/dist/esm/logger/internal-logger.js.map +1 -1
- package/dist/esm/logger/resolve.js +54 -49
- package/dist/esm/logger/resolve.js.map +1 -1
- package/dist/esm/logger/types.d.ts +1 -1
- package/dist/esm/middlewares/content-guard.js +142 -148
- package/dist/esm/middlewares/content-guard.js.map +1 -1
- package/dist/esm/middlewares/index.js +2 -6
- package/dist/esm/middlewares/otel.js +598 -732
- package/dist/esm/middlewares/otel.js.map +1 -1
- package/dist/esm/middlewares/usage-attributes.js +47 -40
- package/dist/esm/middlewares/usage-attributes.js.map +1 -1
- package/dist/esm/realtime/event-emitter.js +24 -25
- package/dist/esm/realtime/event-emitter.js.map +1 -1
- package/dist/esm/realtime/index.d.ts +5 -9
- package/dist/esm/realtime/index.js +29 -6
- package/dist/esm/realtime/index.js.map +1 -1
- package/dist/esm/scope.d.ts +47 -0
- package/dist/esm/stream-durability.d.ts +171 -0
- package/dist/esm/stream-durability.js +295 -0
- package/dist/esm/stream-durability.js.map +1 -0
- package/dist/esm/stream-to-response.d.ts +178 -13
- package/dist/esm/stream-to-response.js +663 -115
- package/dist/esm/stream-to-response.js.map +1 -1
- package/dist/esm/strip-to-spec-middleware.js +30 -16
- package/dist/esm/strip-to-spec-middleware.js.map +1 -1
- package/dist/esm/system-prompts.js +27 -21
- package/dist/esm/system-prompts.js.map +1 -1
- package/dist/esm/tool-registry.js +72 -45
- package/dist/esm/tool-registry.js.map +1 -1
- package/dist/esm/tools/provider-tool.js +14 -5
- package/dist/esm/tools/provider-tool.js.map +1 -1
- package/dist/esm/types.d.ts +332 -21
- package/dist/esm/types.js +2 -0
- package/dist/esm/utilities/ag-ui-wire.js +79 -93
- package/dist/esm/utilities/ag-ui-wire.js.map +1 -1
- package/dist/esm/utilities/chat-params.d.ts +26 -4
- package/dist/esm/utilities/chat-params.js +218 -92
- package/dist/esm/utilities/chat-params.js.map +1 -1
- package/dist/esm/utilities/errors.js +28 -18
- package/dist/esm/utilities/errors.js.map +1 -1
- package/dist/esm/utilities/media-prompt.js +46 -41
- package/dist/esm/utilities/media-prompt.js.map +1 -1
- package/dist/esm/utilities/numbers.js +13 -10
- package/dist/esm/utilities/numbers.js.map +1 -1
- package/dist/esm/utilities/provider-executed.js +20 -11
- package/dist/esm/utilities/provider-executed.js.map +1 -1
- package/dist/esm/utilities/sampling-keys.js +31 -19
- package/dist/esm/utilities/sampling-keys.js.map +1 -1
- package/dist/esm/utilities/tool-result.js +42 -30
- package/dist/esm/utilities/tool-result.js.map +1 -1
- package/dist/esm/utilities/usage.js +27 -9
- package/dist/esm/utilities/usage.js.map +1 -1
- package/dist/esm/utils.js +26 -18
- package/dist/esm/utils.js.map +1 -1
- package/package.json +10 -6
- package/skills/ai-core/SKILL.md +69 -18
- package/skills/ai-core/adapter-configuration/SKILL.md +44 -21
- package/skills/ai-core/adapter-configuration/references/anthropic-adapter.md +1 -3
- package/skills/ai-core/adapter-configuration/references/byteplus-adapter.md +148 -0
- package/skills/ai-core/adapter-configuration/references/gemini-adapter.md +2 -6
- package/skills/ai-core/adapter-configuration/references/groq-adapter.md +2 -6
- package/skills/ai-core/adapter-configuration/references/openai-adapter.md +1 -3
- package/skills/ai-core/ag-ui-protocol/SKILL.md +1 -1
- package/skills/ai-core/chat-experience/SKILL.md +156 -11
- package/skills/ai-core/client-persistence/SKILL.md +277 -0
- package/skills/ai-core/custom-backend-integration/SKILL.md +1 -1
- package/skills/ai-core/debug-logging/SKILL.md +1 -1
- package/skills/ai-core/locks/SKILL.md +143 -0
- package/skills/ai-core/media-generation/SKILL.md +144 -12
- package/skills/ai-core/middleware/SKILL.md +258 -33
- package/skills/ai-core/structured-outputs/SKILL.md +1 -1
- package/skills/ai-core/tool-calling/SKILL.md +54 -59
- package/src/activities/chat/agent-loop-strategies.ts +10 -4
- package/src/activities/chat/cancel.ts +81 -0
- package/src/activities/chat/index.ts +1152 -153
- package/src/activities/chat/mcp/manager.ts +4 -4
- package/src/activities/chat/mcp/types.ts +2 -2
- package/src/activities/chat/messages.ts +5 -3
- package/src/activities/chat/middleware/builder.ts +1 -1
- package/src/activities/chat/middleware/compose.ts +186 -9
- package/src/activities/chat/middleware/index.ts +26 -0
- package/src/activities/chat/middleware/locks.ts +102 -0
- package/src/activities/chat/middleware/pending-turn.ts +47 -0
- package/src/activities/chat/middleware/run-disconnect.ts +62 -0
- package/src/activities/chat/middleware/run-store.ts +412 -0
- package/src/activities/chat/middleware/types.ts +62 -1
- package/src/activities/chat/stream/processor.ts +189 -5
- package/src/activities/chat/tools/approval-schema.ts +205 -0
- package/src/activities/chat/tools/tool-calls.ts +106 -13
- package/src/activities/chat/tools/tool-definition.ts +210 -39
- package/src/activities/generateAudio/index.ts +20 -3
- package/src/activities/generateImage/index.ts +20 -3
- package/src/activities/generateSpeech/index.ts +25 -3
- package/src/activities/generateTranscription/index.ts +26 -3
- package/src/activities/generateVideo/index.ts +345 -82
- package/src/activities/middleware/index.ts +2 -0
- package/src/activities/middleware/run.ts +31 -0
- package/src/activities/middleware/types.ts +49 -5
- package/src/activities/stream-generation-result.ts +30 -2
- package/src/activities/summarize/chat-stream-summarize.ts +5 -0
- package/src/activities/summarize/index.ts +200 -10
- package/src/adapter-internals.ts +10 -1
- package/src/client.ts +244 -0
- package/src/custom-events.ts +107 -0
- package/src/delivery-detach.ts +72 -0
- package/src/delivery-disconnect.ts +84 -0
- package/src/index.ts +138 -0
- package/src/interrupt-resume.ts +824 -0
- package/src/interrupt-serialization.ts +183 -0
- package/src/interrupts.ts +146 -0
- package/src/locks.ts +17 -0
- package/src/logger/types.ts +1 -1
- package/src/middlewares/otel.ts +1 -0
- package/src/realtime/index.ts +5 -9
- package/src/scope.ts +47 -0
- package/src/stream-durability.ts +598 -0
- package/src/stream-to-response.ts +1051 -95
- package/src/strip-to-spec-middleware.ts +3 -3
- package/src/types.ts +416 -24
- package/src/utilities/chat-params.ts +245 -55
- package/dist/esm/activities/index.js.map +0 -1
- package/dist/esm/adapter-internals.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/middlewares/index.js.map +0 -1
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
//#region src/interrupt-serialization.ts
|
|
2
|
+
var SHA256_K = new Uint32Array([
|
|
3
|
+
1116352408,
|
|
4
|
+
1899447441,
|
|
5
|
+
3049323471,
|
|
6
|
+
3921009573,
|
|
7
|
+
961987163,
|
|
8
|
+
1508970993,
|
|
9
|
+
2453635748,
|
|
10
|
+
2870763221,
|
|
11
|
+
3624381080,
|
|
12
|
+
310598401,
|
|
13
|
+
607225278,
|
|
14
|
+
1426881987,
|
|
15
|
+
1925078388,
|
|
16
|
+
2162078206,
|
|
17
|
+
2614888103,
|
|
18
|
+
3248222580,
|
|
19
|
+
3835390401,
|
|
20
|
+
4022224774,
|
|
21
|
+
264347078,
|
|
22
|
+
604807628,
|
|
23
|
+
770255983,
|
|
24
|
+
1249150122,
|
|
25
|
+
1555081692,
|
|
26
|
+
1996064986,
|
|
27
|
+
2554220882,
|
|
28
|
+
2821834349,
|
|
29
|
+
2952996808,
|
|
30
|
+
3210313671,
|
|
31
|
+
3336571891,
|
|
32
|
+
3584528711,
|
|
33
|
+
113926993,
|
|
34
|
+
338241895,
|
|
35
|
+
666307205,
|
|
36
|
+
773529912,
|
|
37
|
+
1294757372,
|
|
38
|
+
1396182291,
|
|
39
|
+
1695183700,
|
|
40
|
+
1986661051,
|
|
41
|
+
2177026350,
|
|
42
|
+
2456956037,
|
|
43
|
+
2730485921,
|
|
44
|
+
2820302411,
|
|
45
|
+
3259730800,
|
|
46
|
+
3345764771,
|
|
47
|
+
3516065817,
|
|
48
|
+
3600352804,
|
|
49
|
+
4094571909,
|
|
50
|
+
275423344,
|
|
51
|
+
430227734,
|
|
52
|
+
506948616,
|
|
53
|
+
659060556,
|
|
54
|
+
883997877,
|
|
55
|
+
958139571,
|
|
56
|
+
1322822218,
|
|
57
|
+
1537002063,
|
|
58
|
+
1747873779,
|
|
59
|
+
1955562222,
|
|
60
|
+
2024104815,
|
|
61
|
+
2227730452,
|
|
62
|
+
2361852424,
|
|
63
|
+
2428436474,
|
|
64
|
+
2756734187,
|
|
65
|
+
3204031479,
|
|
66
|
+
3329325298
|
|
67
|
+
]);
|
|
68
|
+
function rotr(x, n) {
|
|
69
|
+
return x >>> n | x << 32 - n;
|
|
70
|
+
}
|
|
71
|
+
function sha256Hex(input) {
|
|
72
|
+
const msg = new TextEncoder().encode(input);
|
|
73
|
+
const bitLen = msg.length * 8;
|
|
74
|
+
const withOne = msg.length + 1;
|
|
75
|
+
const total = withOne + (56 - withOne % 64 + 64) % 64 + 8;
|
|
76
|
+
const bytes = new Uint8Array(total);
|
|
77
|
+
bytes.set(msg);
|
|
78
|
+
bytes[msg.length] = 128;
|
|
79
|
+
const view = new DataView(bytes.buffer);
|
|
80
|
+
view.setUint32(total - 8, Math.floor(bitLen / 4294967296));
|
|
81
|
+
view.setUint32(total - 4, bitLen >>> 0);
|
|
82
|
+
let h0 = 1779033703;
|
|
83
|
+
let h1 = 3144134277;
|
|
84
|
+
let h2 = 1013904242;
|
|
85
|
+
let h3 = 2773480762;
|
|
86
|
+
let h4 = 1359893119;
|
|
87
|
+
let h5 = 2600822924;
|
|
88
|
+
let h6 = 528734635;
|
|
89
|
+
let h7 = 1541459225;
|
|
90
|
+
const w = /* @__PURE__ */ new Uint32Array(64);
|
|
91
|
+
for (let offset = 0; offset < total; offset += 64) {
|
|
92
|
+
for (let i = 0; i < 16; i++) w[i] = view.getUint32(offset + i * 4);
|
|
93
|
+
for (let i = 16; i < 64; i++) {
|
|
94
|
+
const x15 = w[i - 15] ?? 0;
|
|
95
|
+
const x2 = w[i - 2] ?? 0;
|
|
96
|
+
const s0 = rotr(x15, 7) ^ rotr(x15, 18) ^ x15 >>> 3;
|
|
97
|
+
const s1 = rotr(x2, 17) ^ rotr(x2, 19) ^ x2 >>> 10;
|
|
98
|
+
w[i] = (w[i - 16] ?? 0) + s0 + (w[i - 7] ?? 0) + s1 >>> 0;
|
|
99
|
+
}
|
|
100
|
+
let a = h0;
|
|
101
|
+
let b = h1;
|
|
102
|
+
let c = h2;
|
|
103
|
+
let d = h3;
|
|
104
|
+
let e = h4;
|
|
105
|
+
let f = h5;
|
|
106
|
+
let g = h6;
|
|
107
|
+
let hh = h7;
|
|
108
|
+
for (let i = 0; i < 64; i++) {
|
|
109
|
+
const bigS1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
|
|
110
|
+
const ch = e & f ^ ~e & g;
|
|
111
|
+
const t1 = hh + bigS1 + ch + (SHA256_K[i] ?? 0) + (w[i] ?? 0) >>> 0;
|
|
112
|
+
const t2 = (rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22)) + (a & b ^ a & c ^ b & c) >>> 0;
|
|
113
|
+
hh = g;
|
|
114
|
+
g = f;
|
|
115
|
+
f = e;
|
|
116
|
+
e = d + t1 >>> 0;
|
|
117
|
+
d = c;
|
|
118
|
+
c = b;
|
|
119
|
+
b = a;
|
|
120
|
+
a = t1 + t2 >>> 0;
|
|
121
|
+
}
|
|
122
|
+
h0 = h0 + a >>> 0;
|
|
123
|
+
h1 = h1 + b >>> 0;
|
|
124
|
+
h2 = h2 + c >>> 0;
|
|
125
|
+
h3 = h3 + d >>> 0;
|
|
126
|
+
h4 = h4 + e >>> 0;
|
|
127
|
+
h5 = h5 + f >>> 0;
|
|
128
|
+
h6 = h6 + g >>> 0;
|
|
129
|
+
h7 = h7 + hh >>> 0;
|
|
130
|
+
}
|
|
131
|
+
const hex = (n) => (n >>> 0).toString(16).padStart(8, "0");
|
|
132
|
+
return hex(h0) + hex(h1) + hex(h2) + hex(h3) + hex(h4) + hex(h5) + hex(h6) + hex(h7);
|
|
133
|
+
}
|
|
134
|
+
/** The built-in default: SHA-256, prefixed so the algorithm is self-describing. */
|
|
135
|
+
function defaultInterruptHash(canonicalJson) {
|
|
136
|
+
return `sha256:${sha256Hex(canonicalJson)}`;
|
|
137
|
+
}
|
|
138
|
+
function canonical(value, active) {
|
|
139
|
+
if (value === null) return "null";
|
|
140
|
+
if (typeof value === "string" || typeof value === "boolean") return JSON.stringify(value);
|
|
141
|
+
if (typeof value === "number" && Number.isFinite(value)) return JSON.stringify(value);
|
|
142
|
+
if (typeof value !== "object") throw new TypeError("Interrupt values must be JSON-compatible.");
|
|
143
|
+
if (active.has(value)) throw new TypeError("Interrupt values must not cycle.");
|
|
144
|
+
if (!Array.isArray(value) && Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) throw new TypeError("Interrupt values must use plain JSON objects.");
|
|
145
|
+
active.add(value);
|
|
146
|
+
let encoded;
|
|
147
|
+
if (Array.isArray(value)) {
|
|
148
|
+
const items = [];
|
|
149
|
+
for (let index = 0; index < value.length; index++) items.push(canonical(value[index], active));
|
|
150
|
+
encoded = `[${items.join(",")}]`;
|
|
151
|
+
} else {
|
|
152
|
+
const record = value;
|
|
153
|
+
encoded = `{${Object.keys(record).sort().map((key) => `${JSON.stringify(key)}:${canonical(record[key], active)}`).join(",")}}`;
|
|
154
|
+
}
|
|
155
|
+
active.delete(value);
|
|
156
|
+
return encoded;
|
|
157
|
+
}
|
|
158
|
+
function canonicalInterruptJson(value) {
|
|
159
|
+
return canonical(value, /* @__PURE__ */ new WeakSet());
|
|
160
|
+
}
|
|
161
|
+
function digestInterruptJson(canonicalJson, hash = defaultInterruptHash) {
|
|
162
|
+
if (typeof canonicalJson !== "string") throw new TypeError("Interrupt digests require canonical JSON text.");
|
|
163
|
+
return hash(canonicalJson);
|
|
164
|
+
}
|
|
165
|
+
function freezeTree(value) {
|
|
166
|
+
if (value === null || typeof value !== "object" || Object.isFrozen(value)) return;
|
|
167
|
+
Object.values(value).forEach(freezeTree);
|
|
168
|
+
Object.freeze(value);
|
|
169
|
+
}
|
|
170
|
+
function cloneAndDeepFreezeJson(value) {
|
|
171
|
+
const clone = JSON.parse(canonicalInterruptJson(value));
|
|
172
|
+
freezeTree(clone);
|
|
173
|
+
return clone;
|
|
174
|
+
}
|
|
175
|
+
//#endregion
|
|
176
|
+
export { canonicalInterruptJson, cloneAndDeepFreezeJson, defaultInterruptHash, digestInterruptJson };
|
|
177
|
+
|
|
178
|
+
//# sourceMappingURL=interrupt-serialization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interrupt-serialization.js","names":[],"sources":["../../src/interrupt-serialization.ts"],"sourcesContent":["// Dependency-free SHA-256 (FIPS 180-4). Sync and isomorphic (Node + browser)\n// so interrupt hashing needs no crypto library. Users can replace the whole\n// algorithm through the `interrupts.hash` option; this is only the default.\n// ponytail: bundled ~60-line hash, swap via interrupts.hash if you need more.\nconst SHA256_K = new Uint32Array([\n 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,\n 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,\n 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,\n 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,\n 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,\n 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,\n 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,\n 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,\n 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,\n 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,\n 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,\n])\n\nfunction rotr(x: number, n: number): number {\n return (x >>> n) | (x << (32 - n))\n}\n\nfunction sha256Hex(input: string): string {\n const msg = new TextEncoder().encode(input)\n\n const bitLen = msg.length * 8\n const withOne = msg.length + 1\n const total = withOne + ((56 - (withOne % 64) + 64) % 64) + 8\n const bytes = new Uint8Array(total)\n bytes.set(msg)\n bytes[msg.length] = 0x80\n const view = new DataView(bytes.buffer)\n view.setUint32(total - 8, Math.floor(bitLen / 0x100000000))\n view.setUint32(total - 4, bitLen >>> 0)\n\n let h0 = 0x6a09e667\n let h1 = 0xbb67ae85\n let h2 = 0x3c6ef372\n let h3 = 0xa54ff53a\n let h4 = 0x510e527f\n let h5 = 0x9b05688c\n let h6 = 0x1f83d9ab\n let h7 = 0x5be0cd19\n\n const w = new Uint32Array(64)\n for (let offset = 0; offset < total; offset += 64) {\n for (let i = 0; i < 16; i++) w[i] = view.getUint32(offset + i * 4)\n for (let i = 16; i < 64; i++) {\n const x15 = w[i - 15] ?? 0\n const x2 = w[i - 2] ?? 0\n const s0 = rotr(x15, 7) ^ rotr(x15, 18) ^ (x15 >>> 3)\n const s1 = rotr(x2, 17) ^ rotr(x2, 19) ^ (x2 >>> 10)\n w[i] = ((w[i - 16] ?? 0) + s0 + (w[i - 7] ?? 0) + s1) >>> 0\n }\n\n let a = h0\n let b = h1\n let c = h2\n let d = h3\n let e = h4\n let f = h5\n let g = h6\n let hh = h7\n for (let i = 0; i < 64; i++) {\n const bigS1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25)\n const ch = (e & f) ^ (~e & g)\n const t1 = (hh + bigS1 + ch + (SHA256_K[i] ?? 0) + (w[i] ?? 0)) >>> 0\n const bigS0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22)\n const maj = (a & b) ^ (a & c) ^ (b & c)\n const t2 = (bigS0 + maj) >>> 0\n hh = g\n g = f\n f = e\n e = (d + t1) >>> 0\n d = c\n c = b\n b = a\n a = (t1 + t2) >>> 0\n }\n h0 = (h0 + a) >>> 0\n h1 = (h1 + b) >>> 0\n h2 = (h2 + c) >>> 0\n h3 = (h3 + d) >>> 0\n h4 = (h4 + e) >>> 0\n h5 = (h5 + f) >>> 0\n h6 = (h6 + g) >>> 0\n h7 = (h7 + hh) >>> 0\n }\n\n const hex = (n: number): string => (n >>> 0).toString(16).padStart(8, '0')\n return (\n hex(h0) +\n hex(h1) +\n hex(h2) +\n hex(h3) +\n hex(h4) +\n hex(h5) +\n hex(h6) +\n hex(h7)\n )\n}\n\n/**\n * A hash function for interrupt bindings and resolution fingerprints. Receives\n * canonical JSON text and returns an opaque string. Must be deterministic; the\n * server compares hashes it computed against the ones in a binding, so the same\n * function has to run wherever a given binding is produced and checked.\n */\nexport type InterruptHash = (canonicalJson: string) => string\n\n/** The built-in default: SHA-256, prefixed so the algorithm is self-describing. */\nexport function defaultInterruptHash(canonicalJson: string): string {\n return `sha256:${sha256Hex(canonicalJson)}`\n}\n\nfunction canonical(value: unknown, active: WeakSet<object>): string {\n if (value === null) return 'null'\n if (typeof value === 'string' || typeof value === 'boolean') {\n return JSON.stringify(value)\n }\n if (typeof value === 'number' && Number.isFinite(value)) {\n return JSON.stringify(value)\n }\n if (typeof value !== 'object') {\n throw new TypeError('Interrupt values must be JSON-compatible.')\n }\n if (active.has(value)) {\n throw new TypeError('Interrupt values must not cycle.')\n }\n if (\n !Array.isArray(value) &&\n Object.getPrototypeOf(value) !== Object.prototype &&\n Object.getPrototypeOf(value) !== null\n ) {\n throw new TypeError('Interrupt values must use plain JSON objects.')\n }\n\n active.add(value)\n let encoded: string\n if (Array.isArray(value)) {\n const items: Array<string> = []\n for (let index = 0; index < value.length; index++) {\n items.push(canonical(value[index], active))\n }\n encoded = `[${items.join(',')}]`\n } else {\n const record = value as Record<string, unknown>\n encoded = `{${Object.keys(record)\n .sort()\n .map((key) => `${JSON.stringify(key)}:${canonical(record[key], active)}`)\n .join(',')}}`\n }\n active.delete(value)\n return encoded\n}\n\nexport function canonicalInterruptJson(value: unknown): string {\n return canonical(value, new WeakSet<object>())\n}\n\nexport function digestInterruptJson(\n canonicalJson: string,\n hash: InterruptHash = defaultInterruptHash,\n): string {\n if (typeof canonicalJson !== 'string') {\n throw new TypeError('Interrupt digests require canonical JSON text.')\n }\n return hash(canonicalJson)\n}\n\nfunction freezeTree(value: unknown): void {\n if (value === null || typeof value !== 'object' || Object.isFrozen(value)) {\n return\n }\n Object.values(value).forEach(freezeTree)\n Object.freeze(value)\n}\n\nexport function cloneAndDeepFreezeJson<T>(value: T): T {\n const clone: T = JSON.parse(canonicalInterruptJson(value))\n freezeTree(clone)\n return clone\n}\n"],"mappings":";AAIA,IAAM,WAAW,IAAI,YAAY;CAC/B;CAAY;CAAY;CAAY;CAAY;CAAY;CAC5D;CAAY;CAAY;CAAY;CAAY;CAAY;CAC5D;CAAY;CAAY;CAAY;CAAY;CAAY;CAC5D;CAAY;CAAY;CAAY;CAAY;CAAY;CAC5D;CAAY;CAAY;CAAY;CAAY;CAAY;CAC5D;CAAY;CAAY;CAAY;CAAY;CAAY;CAC5D;CAAY;CAAY;CAAY;CAAY;CAAY;CAC5D;CAAY;CAAY;CAAY;CAAY;CAAY;CAC5D;CAAY;CAAY;CAAY;CAAY;CAAY;CAC5D;CAAY;CAAY;CAAY;CAAY;CAAY;CAC5D;CAAY;CAAY;CAAY;AACtC,CAAC;AAED,SAAS,KAAK,GAAW,GAAmB;CAC1C,OAAQ,MAAM,IAAM,KAAM,KAAK;AACjC;AAEA,SAAS,UAAU,OAAuB;CACxC,MAAM,MAAM,IAAI,YAAY,CAAC,CAAC,OAAO,KAAK;CAE1C,MAAM,SAAS,IAAI,SAAS;CAC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
+
threadId: string;
|
|
4
|
+
interruptedRunId: string;
|
|
5
|
+
generation: number;
|
|
6
|
+
submissionId?: string;
|
|
7
|
+
continuationRunId?: string;
|
|
8
|
+
}
|
|
9
|
+
export type ItemInterruptErrorCode = 'invalid-payload' | 'invalid-edited-args' | 'invalid-tool-output' | 'invalid-response-schema' | 'unknown-interrupt' | 'expired' | 'stale' | 'conflict' | 'legacy-unsupported';
|
|
10
|
+
export type BatchInterruptErrorCode = 'incomplete-batch' | 'item-validation-failed' | 'unsupported-bulk-operation' | 'async-resolver' | 'inactive-transaction' | 'mixed-provenance' | 'transport' | 'server' | 'protocol' | 'invalid-response-schema' | 'expired' | 'stale' | 'conflict' | 'legacy-submit-failed';
|
|
11
|
+
export interface ItemInterruptError extends InterruptCorrelation {
|
|
12
|
+
scope: 'item';
|
|
13
|
+
interruptId: string;
|
|
14
|
+
code: ItemInterruptErrorCode;
|
|
15
|
+
message: string;
|
|
16
|
+
path?: ReadonlyArray<string | number>;
|
|
17
|
+
source: 'client' | 'server';
|
|
18
|
+
retryable: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface BatchInterruptError extends InterruptCorrelation {
|
|
21
|
+
scope: 'batch';
|
|
22
|
+
code: BatchInterruptErrorCode;
|
|
23
|
+
message: string;
|
|
24
|
+
source: 'client' | 'server' | 'transport';
|
|
25
|
+
retryable: boolean;
|
|
26
|
+
interruptIds: ReadonlyArray<string>;
|
|
27
|
+
}
|
|
28
|
+
export type InterruptSubmissionError = ItemInterruptError | BatchInterruptError;
|
|
29
|
+
/**
|
|
30
|
+
* Wire version of {@link InterruptBinding}.
|
|
31
|
+
*
|
|
32
|
+
* The binding is the only part of an AG-UI `Interrupt` that this package
|
|
33
|
+
* claims — it rides in `metadata` under
|
|
34
|
+
* {@link INTERRUPT_BINDING_METADATA_KEY} and tells the resume path how to
|
|
35
|
+
* correlate an answer back to a paused run. Producers stamp `v`; readers
|
|
36
|
+
* reject any version they don't understand rather than duck-typing the fields.
|
|
37
|
+
*
|
|
38
|
+
* That matters because an AG-UI `Interrupt` is a shared envelope. Another
|
|
39
|
+
* producer — a workflow engine projecting a durable approval, a third-party
|
|
40
|
+
* agent — can legitimately put its own binding in the same envelope. Versioning
|
|
41
|
+
* makes "not mine" a clean rejection instead of a partial match that resumes
|
|
42
|
+
* against the wrong owner.
|
|
43
|
+
*/
|
|
44
|
+
export declare const INTERRUPT_BINDING_VERSION: 1;
|
|
45
|
+
interface InterruptBindingBase {
|
|
46
|
+
/** @see INTERRUPT_BINDING_VERSION */
|
|
47
|
+
v: typeof INTERRUPT_BINDING_VERSION;
|
|
48
|
+
interruptId: string;
|
|
49
|
+
interruptedRunId: string;
|
|
50
|
+
generation: number;
|
|
51
|
+
responseSchemaHash: string;
|
|
52
|
+
expiresAt?: string;
|
|
53
|
+
}
|
|
54
|
+
export type InterruptBinding = (InterruptBindingBase & {
|
|
55
|
+
kind: 'tool-approval';
|
|
56
|
+
toolName: string;
|
|
57
|
+
toolCallId: string;
|
|
58
|
+
originalArgs: unknown;
|
|
59
|
+
inputSchemaHash: string;
|
|
60
|
+
approvalSchemaHash: string;
|
|
61
|
+
}) | (InterruptBindingBase & {
|
|
62
|
+
kind: 'client-tool-execution';
|
|
63
|
+
toolName: string;
|
|
64
|
+
toolCallId: string;
|
|
65
|
+
outputSchemaHash: string;
|
|
66
|
+
}) | (InterruptBindingBase & {
|
|
67
|
+
kind: 'generic';
|
|
68
|
+
});
|
|
69
|
+
export type UnopenedInterruptBinding = InterruptBinding extends infer TBinding ? TBinding extends InterruptBinding ? Omit<TBinding, 'interruptedRunId' | 'generation'> : never : never;
|
|
70
|
+
export type ToolApprovalResolution = boolean | {
|
|
71
|
+
approved: true;
|
|
72
|
+
editedArgs?: unknown;
|
|
73
|
+
payload?: unknown;
|
|
74
|
+
} | {
|
|
75
|
+
approved: false;
|
|
76
|
+
payload?: unknown;
|
|
77
|
+
editedArgs?: never;
|
|
78
|
+
};
|
|
79
|
+
export declare function canonicalizeInterruptResolutions(resolutions: ReadonlyArray<RunAgentResumeItem>): {
|
|
80
|
+
resolutions: ReadonlyArray<RunAgentResumeItem>;
|
|
81
|
+
canonicalResolutions: string;
|
|
82
|
+
fingerprint: string;
|
|
83
|
+
};
|
|
84
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { canonicalInterruptJson, cloneAndDeepFreezeJson, digestInterruptJson } from "./interrupt-serialization.js";
|
|
2
|
+
//#region src/interrupts.ts
|
|
3
|
+
/**
|
|
4
|
+
* Wire version of {@link InterruptBinding}.
|
|
5
|
+
*
|
|
6
|
+
* The binding is the only part of an AG-UI `Interrupt` that this package
|
|
7
|
+
* claims — it rides in `metadata` under
|
|
8
|
+
* {@link INTERRUPT_BINDING_METADATA_KEY} and tells the resume path how to
|
|
9
|
+
* correlate an answer back to a paused run. Producers stamp `v`; readers
|
|
10
|
+
* reject any version they don't understand rather than duck-typing the fields.
|
|
11
|
+
*
|
|
12
|
+
* That matters because an AG-UI `Interrupt` is a shared envelope. Another
|
|
13
|
+
* producer — a workflow engine projecting a durable approval, a third-party
|
|
14
|
+
* agent — can legitimately put its own binding in the same envelope. Versioning
|
|
15
|
+
* makes "not mine" a clean rejection instead of a partial match that resumes
|
|
16
|
+
* against the wrong owner.
|
|
17
|
+
*/
|
|
18
|
+
var INTERRUPT_BINDING_VERSION = 1;
|
|
19
|
+
function canonicalizeInterruptResolutions(resolutions) {
|
|
20
|
+
const frozen = cloneAndDeepFreezeJson([...resolutions].sort((left, right) => left.interruptId.localeCompare(right.interruptId)));
|
|
21
|
+
const canonicalResolutions = canonicalInterruptJson(frozen);
|
|
22
|
+
return Object.freeze({
|
|
23
|
+
resolutions: frozen,
|
|
24
|
+
canonicalResolutions,
|
|
25
|
+
fingerprint: digestInterruptJson(canonicalResolutions)
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { INTERRUPT_BINDING_VERSION, canonicalizeInterruptResolutions };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=interrupts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interrupts.js","names":[],"sources":["../../src/interrupts.ts"],"sourcesContent":["import {\n canonicalInterruptJson,\n cloneAndDeepFreezeJson,\n digestInterruptJson,\n} from './interrupt-serialization'\nimport type { RunAgentResumeItem } from './types'\n\nexport interface InterruptCorrelation {\n threadId: string\n interruptedRunId: string\n generation: number\n submissionId?: string\n continuationRunId?: string\n}\n\nexport type ItemInterruptErrorCode =\n | 'invalid-payload'\n | 'invalid-edited-args'\n | 'invalid-tool-output'\n | 'invalid-response-schema'\n | 'unknown-interrupt'\n | 'expired'\n | 'stale'\n | 'conflict'\n | 'legacy-unsupported'\n\nexport type BatchInterruptErrorCode =\n | 'incomplete-batch'\n | 'item-validation-failed'\n | 'unsupported-bulk-operation'\n | 'async-resolver'\n | 'inactive-transaction'\n | 'mixed-provenance'\n | 'transport'\n | 'server'\n | 'protocol'\n | 'invalid-response-schema'\n | 'expired'\n | 'stale'\n | 'conflict'\n | 'legacy-submit-failed'\n\nexport interface ItemInterruptError extends InterruptCorrelation {\n scope: 'item'\n interruptId: string\n code: ItemInterruptErrorCode\n message: string\n path?: ReadonlyArray<string | number>\n source: 'client' | 'server'\n retryable: boolean\n}\n\nexport interface BatchInterruptError extends InterruptCorrelation {\n scope: 'batch'\n code: BatchInterruptErrorCode\n message: string\n source: 'client' | 'server' | 'transport'\n retryable: boolean\n interruptIds: ReadonlyArray<string>\n}\n\nexport type InterruptSubmissionError = ItemInterruptError | BatchInterruptError\n\n/**\n * Wire version of {@link InterruptBinding}.\n *\n * The binding is the only part of an AG-UI `Interrupt` that this package\n * claims — it rides in `metadata` under\n * {@link INTERRUPT_BINDING_METADATA_KEY} and tells the resume path how to\n * correlate an answer back to a paused run. Producers stamp `v`; readers\n * reject any version they don't understand rather than duck-typing the fields.\n *\n * That matters because an AG-UI `Interrupt` is a shared envelope. Another\n * producer — a workflow engine projecting a durable approval, a third-party\n * agent — can legitimately put its own binding in the same envelope. Versioning\n * makes \"not mine\" a clean rejection instead of a partial match that resumes\n * against the wrong owner.\n */\nexport const INTERRUPT_BINDING_VERSION = 1 as const\n\ninterface InterruptBindingBase {\n /** @see INTERRUPT_BINDING_VERSION */\n v: typeof INTERRUPT_BINDING_VERSION\n interruptId: string\n interruptedRunId: string\n generation: number\n responseSchemaHash: string\n expiresAt?: string\n}\n\nexport type InterruptBinding =\n | (InterruptBindingBase & {\n kind: 'tool-approval'\n toolName: string\n toolCallId: string\n originalArgs: unknown\n inputSchemaHash: string\n approvalSchemaHash: string\n })\n | (InterruptBindingBase & {\n kind: 'client-tool-execution'\n toolName: string\n toolCallId: string\n outputSchemaHash: string\n })\n | (InterruptBindingBase & {\n kind: 'generic'\n })\n\nexport type UnopenedInterruptBinding = InterruptBinding extends infer TBinding\n ? TBinding extends InterruptBinding\n ? Omit<TBinding, 'interruptedRunId' | 'generation'>\n : never\n : never\n\nexport type ToolApprovalResolution =\n | boolean\n | {\n approved: true\n editedArgs?: unknown\n payload?: unknown\n }\n | {\n approved: false\n payload?: unknown\n editedArgs?: never\n }\n\nexport function canonicalizeInterruptResolutions(\n resolutions: ReadonlyArray<RunAgentResumeItem>,\n): {\n resolutions: ReadonlyArray<RunAgentResumeItem>\n canonicalResolutions: string\n fingerprint: string\n} {\n const sorted = [...resolutions].sort((left, right) =>\n left.interruptId.localeCompare(right.interruptId),\n )\n const frozen = cloneAndDeepFreezeJson(sorted)\n const canonicalResolutions = canonicalInterruptJson(frozen)\n return Object.freeze({\n resolutions: frozen,\n canonicalResolutions,\n fingerprint: digestInterruptJson(canonicalResolutions),\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA8EA,IAAa,4BAA4B;AAkDzC,SAAgB,iCACd,aAKA;CAIA,MAAM,SAAS,uBAHA,CAAC,GAAG,WAAW,CAAC,CAAC,MAAM,MAAM,UAC1C,KAAK,YAAY,cAAc,MAAM,WAAW,CAEZ,CAAM;CAC5C,MAAM,uBAAuB,uBAAuB,MAAM;CAC1D,OAAO,OAAO,OAAO;EACnB,aAAa;EACb;EACA,aAAa,oBAAoB,oBAAoB;CACvD,CAAC;AACH"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Distributed-mutex primitive — coordination, not state persistence.
|
|
3
|
+
*
|
|
4
|
+
* Its own subpath (`@tanstack/ai/locks`) so it stays out of the main barrel and
|
|
5
|
+
* consumers opt in explicitly. Provide a store with `withLocks`; downstream
|
|
6
|
+
* middleware (e.g. `@tanstack/ai-sandbox`'s `ensure`) reads it via `getLocks` /
|
|
7
|
+
* `LocksCapability`. Import from here, not from `@tanstack/ai-persistence`.
|
|
8
|
+
*/
|
|
9
|
+
export { LocksCapability, getLocks, provideLocks, InMemoryLockStore, withLocks, defineLock, } from './activities/chat/middleware/index.js';
|
|
10
|
+
export type { LockStore } from './activities/chat/middleware/index.js';
|
|
@@ -1,83 +1,106 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/logger/console-logger.ts
|
|
2
|
+
/**
|
|
3
|
+
* `util.inspect` options used with `console.dir` on Node so deeply nested
|
|
4
|
+
* structures (e.g. provider chunk payloads with `usage`, `output`,
|
|
5
|
+
* `reasoning`, `tools`) render in full instead of truncating to
|
|
6
|
+
* `[Object]` / `[Array]`.
|
|
7
|
+
*/
|
|
8
|
+
var DIR_OPTIONS = {
|
|
9
|
+
depth: null,
|
|
10
|
+
colors: true
|
|
11
|
+
};
|
|
2
12
|
function resolveMetaStrategy() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
typeof process.versions?.node === "string") {
|
|
9
|
-
return "dir";
|
|
10
|
-
}
|
|
11
|
-
return "arg";
|
|
13
|
+
try {
|
|
14
|
+
if (globalThis.navigator?.userAgent === "Cloudflare-Workers") return "json";
|
|
15
|
+
} catch {}
|
|
16
|
+
if (typeof process !== "undefined" && typeof process.versions?.node === "string") return "dir";
|
|
17
|
+
return "arg";
|
|
12
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* `JSON.stringify` hardened for debug payloads: circular references collapse
|
|
21
|
+
* to `"[Circular]"`, `Error` instances expand to `name`/`message`/`stack`
|
|
22
|
+
* (they would otherwise stringify to `{}`), and `bigint` values become
|
|
23
|
+
* strings (they would otherwise throw). Never throws — falls back to
|
|
24
|
+
* `String(value)` and, if even that coercion throws, a placeholder.
|
|
25
|
+
*/
|
|
13
26
|
function stringifyMetaSafely(value) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
try {
|
|
37
|
-
return String(value);
|
|
38
|
-
} catch {
|
|
39
|
-
return "[Unserializable meta]";
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
class ConsoleLogger {
|
|
44
|
-
/** Log a debug-level message; forwards to `console.debug`. */
|
|
45
|
-
debug(message, meta) {
|
|
46
|
-
this.emit("debug", message, meta);
|
|
47
|
-
}
|
|
48
|
-
/** Log an info-level message; forwards to `console.info`. */
|
|
49
|
-
info(message, meta) {
|
|
50
|
-
this.emit("info", message, meta);
|
|
51
|
-
}
|
|
52
|
-
/** Log a warning-level message; forwards to `console.warn`. */
|
|
53
|
-
warn(message, meta) {
|
|
54
|
-
this.emit("warn", message, meta);
|
|
55
|
-
}
|
|
56
|
-
/** Log an error-level message; forwards to `console.error`. */
|
|
57
|
-
error(message, meta) {
|
|
58
|
-
this.emit("error", message, meta);
|
|
59
|
-
}
|
|
60
|
-
emit(level, message, meta) {
|
|
61
|
-
if (meta === void 0) {
|
|
62
|
-
console[level](message);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
switch (resolveMetaStrategy()) {
|
|
66
|
-
case "dir":
|
|
67
|
-
console[level](message);
|
|
68
|
-
console.dir(meta, DIR_OPTIONS);
|
|
69
|
-
break;
|
|
70
|
-
case "json":
|
|
71
|
-
console[level](`${message}
|
|
72
|
-
${stringifyMetaSafely(meta)}`);
|
|
73
|
-
break;
|
|
74
|
-
case "arg":
|
|
75
|
-
console[level](message, meta);
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
27
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
28
|
+
try {
|
|
29
|
+
return JSON.stringify(value, (_key, entry) => {
|
|
30
|
+
if (typeof entry === "bigint") return entry.toString();
|
|
31
|
+
if (entry instanceof Error) return {
|
|
32
|
+
name: entry.name,
|
|
33
|
+
message: entry.message,
|
|
34
|
+
stack: entry.stack
|
|
35
|
+
};
|
|
36
|
+
if (typeof entry === "object" && entry !== null) {
|
|
37
|
+
if (seen.has(entry)) return "[Circular]";
|
|
38
|
+
seen.add(entry);
|
|
39
|
+
}
|
|
40
|
+
return entry;
|
|
41
|
+
}, 2);
|
|
42
|
+
} catch {
|
|
43
|
+
try {
|
|
44
|
+
return String(value);
|
|
45
|
+
} catch {
|
|
46
|
+
return "[Unserializable meta]";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
79
49
|
}
|
|
80
|
-
|
|
81
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Default `Logger` implementation that routes each level to the matching
|
|
52
|
+
* `console` method:
|
|
53
|
+
*
|
|
54
|
+
* - `debug` → `console.debug`
|
|
55
|
+
* - `info` → `console.info`
|
|
56
|
+
* - `warn` → `console.warn`
|
|
57
|
+
* - `error` → `console.error`
|
|
58
|
+
*
|
|
59
|
+
* When a `meta` object is supplied it is rendered with the strategy that
|
|
60
|
+
* actually surfaces it on the current runtime (see {@link MetaStrategy}):
|
|
61
|
+
* depth-unlimited `console.dir` on Node, circular-safe JSON on Cloudflare
|
|
62
|
+
* Workers, and an extra console argument everywhere else.
|
|
63
|
+
*
|
|
64
|
+
* This is the logger used when `debug` is enabled on any activity and no
|
|
65
|
+
* custom `logger` is supplied via `debug: { logger }`.
|
|
66
|
+
*/
|
|
67
|
+
var ConsoleLogger = class {
|
|
68
|
+
/** Log a debug-level message; forwards to `console.debug`. */
|
|
69
|
+
debug(message, meta) {
|
|
70
|
+
this.emit("debug", message, meta);
|
|
71
|
+
}
|
|
72
|
+
/** Log an info-level message; forwards to `console.info`. */
|
|
73
|
+
info(message, meta) {
|
|
74
|
+
this.emit("info", message, meta);
|
|
75
|
+
}
|
|
76
|
+
/** Log a warning-level message; forwards to `console.warn`. */
|
|
77
|
+
warn(message, meta) {
|
|
78
|
+
this.emit("warn", message, meta);
|
|
79
|
+
}
|
|
80
|
+
/** Log an error-level message; forwards to `console.error`. */
|
|
81
|
+
error(message, meta) {
|
|
82
|
+
this.emit("error", message, meta);
|
|
83
|
+
}
|
|
84
|
+
emit(level, message, meta) {
|
|
85
|
+
if (meta === void 0) {
|
|
86
|
+
console[level](message);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
switch (resolveMetaStrategy()) {
|
|
90
|
+
case "dir":
|
|
91
|
+
console[level](message);
|
|
92
|
+
console.dir(meta, DIR_OPTIONS);
|
|
93
|
+
break;
|
|
94
|
+
case "json":
|
|
95
|
+
console[level](`${message}\n${stringifyMetaSafely(meta)}`);
|
|
96
|
+
break;
|
|
97
|
+
case "arg":
|
|
98
|
+
console[level](message, meta);
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
82
102
|
};
|
|
83
|
-
//#
|
|
103
|
+
//#endregion
|
|
104
|
+
export { ConsoleLogger };
|
|
105
|
+
|
|
106
|
+
//# sourceMappingURL=console-logger.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console-logger.js","sources":["../../../src/logger/console-logger.ts"],"sourcesContent":["import type { Logger } from './types'\n\n/**\n * `util.inspect` options used with `console.dir` on Node so deeply nested\n * structures (e.g. provider chunk payloads with `usage`, `output`,\n * `reasoning`, `tools`) render in full instead of truncating to\n * `[Object]` / `[Array]`.\n */\nconst DIR_OPTIONS = { depth: null, colors: true } as const\n\n/**\n * How `meta` should be rendered on the current runtime:\n *\n * - `dir` — Node. `console.dir(meta, { depth: null, colors: true })` gives a\n * depth-unlimited, colored inspect dump.\n * - `json` — Cloudflare Workers / workerd. workerd never forwards\n * `console.dir` output to the terminal (with or without options), and its\n * own inspect of extra console arguments truncates nested objects, so the\n * payload is appended as circular-safe pretty-printed JSON instead.\n * - `arg` — everything else (browsers, Deno, Bun). `meta` is passed as an\n * extra console argument: devtools keep collapsible object trees and the\n * runtime's inspect handles circular references natively.\n */\ntype MetaStrategy = 'dir' | 'json' | 'arg'\n\nfunction resolveMetaStrategy(): MetaStrategy {\n // workerd must be detected before the Node check: under the `nodejs_compat`\n // flag it emulates `process.versions.node`, but still drops `console.dir`.\n try {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- navigator is missing on Node < 21 despite the DOM lib typing it as always present\n if (globalThis.navigator?.userAgent === 'Cloudflare-Workers') return 'json'\n } catch {\n // A locked-down runtime with a throwing `userAgent` getter is not workerd;\n // fall through to the remaining checks rather than crash the log call.\n }\n if (\n typeof process !== 'undefined' &&\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- a partial process global (bundler shims) may lack versions\n typeof process.versions?.node === 'string'\n ) {\n return 'dir'\n }\n return 'arg'\n}\n\n/**\n * `JSON.stringify` hardened for debug payloads: circular references collapse\n * to `\"[Circular]\"`, `Error` instances expand to `name`/`message`/`stack`\n * (they would otherwise stringify to `{}`), and `bigint` values become\n * strings (they would otherwise throw). Never throws — falls back to\n * `String(value)` and, if even that coercion throws, a placeholder.\n */\nfunction stringifyMetaSafely(value: unknown): string {\n const seen = new WeakSet<object>()\n try {\n return JSON.stringify(\n value,\n (_key, entry: unknown) => {\n if (typeof entry === 'bigint') return entry.toString()\n if (entry instanceof Error) {\n return {\n name: entry.name,\n message: entry.message,\n stack: entry.stack,\n }\n }\n if (typeof entry === 'object' && entry !== null) {\n if (seen.has(entry)) return '[Circular]'\n seen.add(entry)\n }\n return entry\n },\n 2,\n )\n } catch {\n try {\n return String(value)\n } catch {\n return '[Unserializable meta]'\n }\n }\n}\n\n/**\n * Default `Logger` implementation that routes each level to the matching\n * `console` method:\n *\n * - `debug` → `console.debug`\n * - `info` → `console.info`\n * - `warn` → `console.warn`\n * - `error` → `console.error`\n *\n * When a `meta` object is supplied it is rendered with the strategy that\n * actually surfaces it on the current runtime (see {@link MetaStrategy}):\n * depth-unlimited `console.dir` on Node, circular-safe JSON on Cloudflare\n * Workers, and an extra console argument everywhere else.\n *\n * This is the logger used when `debug` is enabled on any activity and no\n * custom `logger` is supplied via `debug: { logger }`.\n */\nexport class ConsoleLogger implements Logger {\n /** Log a debug-level message; forwards to `console.debug`. */\n debug(message: string, meta?: Record<string, unknown>): void {\n this.emit('debug', message, meta)\n }\n\n /** Log an info-level message; forwards to `console.info`. */\n info(message: string, meta?: Record<string, unknown>): void {\n this.emit('info', message, meta)\n }\n\n /** Log a warning-level message; forwards to `console.warn`. */\n warn(message: string, meta?: Record<string, unknown>): void {\n this.emit('warn', message, meta)\n }\n\n /** Log an error-level message; forwards to `console.error`. */\n error(message: string, meta?: Record<string, unknown>): void {\n this.emit('error', message, meta)\n }\n\n private emit(\n level: 'debug' | 'info' | 'warn' | 'error',\n message: string,\n meta?: Record<string, unknown>,\n ): void {\n if (meta === undefined) {\n console[level](message)\n return\n }\n switch (resolveMetaStrategy()) {\n case 'dir':\n console[level](message)\n console.dir(meta, DIR_OPTIONS)\n break\n case 'json':\n console[level](`${message}\\n${stringifyMetaSafely(meta)}`)\n break\n case 'arg':\n console[level](message, meta)\n break\n }\n }\n}\n"],"
|
|
1
|
+
{"version":3,"file":"console-logger.js","names":[],"sources":["../../../src/logger/console-logger.ts"],"sourcesContent":["import type { Logger } from './types'\n\n/**\n * `util.inspect` options used with `console.dir` on Node so deeply nested\n * structures (e.g. provider chunk payloads with `usage`, `output`,\n * `reasoning`, `tools`) render in full instead of truncating to\n * `[Object]` / `[Array]`.\n */\nconst DIR_OPTIONS = { depth: null, colors: true } as const\n\n/**\n * How `meta` should be rendered on the current runtime:\n *\n * - `dir` — Node. `console.dir(meta, { depth: null, colors: true })` gives a\n * depth-unlimited, colored inspect dump.\n * - `json` — Cloudflare Workers / workerd. workerd never forwards\n * `console.dir` output to the terminal (with or without options), and its\n * own inspect of extra console arguments truncates nested objects, so the\n * payload is appended as circular-safe pretty-printed JSON instead.\n * - `arg` — everything else (browsers, Deno, Bun). `meta` is passed as an\n * extra console argument: devtools keep collapsible object trees and the\n * runtime's inspect handles circular references natively.\n */\ntype MetaStrategy = 'dir' | 'json' | 'arg'\n\nfunction resolveMetaStrategy(): MetaStrategy {\n // workerd must be detected before the Node check: under the `nodejs_compat`\n // flag it emulates `process.versions.node`, but still drops `console.dir`.\n try {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- navigator is missing on Node < 21 despite the DOM lib typing it as always present\n if (globalThis.navigator?.userAgent === 'Cloudflare-Workers') return 'json'\n } catch {\n // A locked-down runtime with a throwing `userAgent` getter is not workerd;\n // fall through to the remaining checks rather than crash the log call.\n }\n if (\n typeof process !== 'undefined' &&\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- a partial process global (bundler shims) may lack versions\n typeof process.versions?.node === 'string'\n ) {\n return 'dir'\n }\n return 'arg'\n}\n\n/**\n * `JSON.stringify` hardened for debug payloads: circular references collapse\n * to `\"[Circular]\"`, `Error` instances expand to `name`/`message`/`stack`\n * (they would otherwise stringify to `{}`), and `bigint` values become\n * strings (they would otherwise throw). Never throws — falls back to\n * `String(value)` and, if even that coercion throws, a placeholder.\n */\nfunction stringifyMetaSafely(value: unknown): string {\n const seen = new WeakSet<object>()\n try {\n return JSON.stringify(\n value,\n (_key, entry: unknown) => {\n if (typeof entry === 'bigint') return entry.toString()\n if (entry instanceof Error) {\n return {\n name: entry.name,\n message: entry.message,\n stack: entry.stack,\n }\n }\n if (typeof entry === 'object' && entry !== null) {\n if (seen.has(entry)) return '[Circular]'\n seen.add(entry)\n }\n return entry\n },\n 2,\n )\n } catch {\n try {\n return String(value)\n } catch {\n return '[Unserializable meta]'\n }\n }\n}\n\n/**\n * Default `Logger` implementation that routes each level to the matching\n * `console` method:\n *\n * - `debug` → `console.debug`\n * - `info` → `console.info`\n * - `warn` → `console.warn`\n * - `error` → `console.error`\n *\n * When a `meta` object is supplied it is rendered with the strategy that\n * actually surfaces it on the current runtime (see {@link MetaStrategy}):\n * depth-unlimited `console.dir` on Node, circular-safe JSON on Cloudflare\n * Workers, and an extra console argument everywhere else.\n *\n * This is the logger used when `debug` is enabled on any activity and no\n * custom `logger` is supplied via `debug: { logger }`.\n */\nexport class ConsoleLogger implements Logger {\n /** Log a debug-level message; forwards to `console.debug`. */\n debug(message: string, meta?: Record<string, unknown>): void {\n this.emit('debug', message, meta)\n }\n\n /** Log an info-level message; forwards to `console.info`. */\n info(message: string, meta?: Record<string, unknown>): void {\n this.emit('info', message, meta)\n }\n\n /** Log a warning-level message; forwards to `console.warn`. */\n warn(message: string, meta?: Record<string, unknown>): void {\n this.emit('warn', message, meta)\n }\n\n /** Log an error-level message; forwards to `console.error`. */\n error(message: string, meta?: Record<string, unknown>): void {\n this.emit('error', message, meta)\n }\n\n private emit(\n level: 'debug' | 'info' | 'warn' | 'error',\n message: string,\n meta?: Record<string, unknown>,\n ): void {\n if (meta === undefined) {\n console[level](message)\n return\n }\n switch (resolveMetaStrategy()) {\n case 'dir':\n console[level](message)\n console.dir(meta, DIR_OPTIONS)\n break\n case 'json':\n console[level](`${message}\\n${stringifyMetaSafely(meta)}`)\n break\n case 'arg':\n console[level](message, meta)\n break\n }\n }\n}\n"],"mappings":";;;;;;;AAQA,IAAM,cAAc;CAAE,OAAO;CAAM,QAAQ;AAAK;AAiBhD,SAAS,sBAAoC;CAG3C,I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