@aragon-agent/core 0.2.93 → 0.2.94
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/engine/accept-steering.js +1 -15
- package/dist/engine/agent-loop.js +1 -533
- package/dist/engine/agent.js +1 -538
- package/dist/engine/compaction.js +1 -268
- package/dist/engine/context-manager.js +1 -13
- package/dist/engine/message-manager.js +1 -39
- package/dist/engine/steering.js +1 -72
- package/dist/engine/tool-result-content.js +1 -39
- package/dist/engine/watchdog.js +1 -73
- package/dist/index.js +1 -99
- package/dist/llm/context-window.js +1 -46
- package/dist/llm/image-tokens.js +1 -11
- package/dist/llm/model-discovery.js +1 -18
- package/dist/llm/model-registry.js +1 -370
- package/dist/llm/output-limit-recovery.js +1 -263
- package/dist/llm/output-limits.js +1 -283
- package/dist/llm/provider.js +1 -171
- package/dist/llm/providers/anthropic.js +1 -514
- package/dist/llm/providers/google.js +1 -464
- package/dist/llm/providers/index.js +1 -205
- package/dist/llm/providers/openai.js +1 -520
- package/dist/llm/providers/tool-result-images.js +1 -52
- package/dist/llm/retry.js +1 -948
- package/dist/llm/sse-parser.js +1 -103
- package/dist/llm/stream-utils.js +1 -118
- package/dist/llm/types.js +1 -17
- package/dist/sandbox/console-capture.js +1 -56
- package/dist/sandbox/http-bridge.js +1 -143
- package/dist/sandbox/isolated-vm-sandbox.js +1 -226
- package/dist/sandbox/tool-bridge.js +1 -98
- package/dist/sandbox/types.js +1 -8
- package/dist/skills/constants.js +1 -179
- package/dist/skills/disclosure.js +1 -788
- package/dist/skills/frontmatter.js +1 -177
- package/dist/skills/index.js +1 -18
- package/dist/skills/skill-find-tool.js +1 -117
- package/dist/skills/skill-registry.js +1 -208
- package/dist/skills/skill-tool.js +1 -96
- package/dist/skills/tool-policy.js +1 -272
- package/dist/skills/types.js +1 -8
- package/dist/skills/validate.js +1 -264
- package/dist/tools/executor.js +1 -281
- package/dist/tools/helpers.js +1 -87
- package/dist/tools/registry.js +1 -119
- package/dist/tools/types.js +1 -7
- package/dist/tools/validator.js +1 -210
- package/dist/types.js +1 -7
- package/package.json +3 -2
|
@@ -1,268 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Pure compaction mechanics (context-auto-compaction §3.6.1 / §3.6.2 / §5.3).
|
|
3
|
-
*
|
|
4
|
-
* NO I/O, NO CLOCK, NO PROVIDER KNOWLEDGE, NO `node:*` IMPORT. This module is
|
|
5
|
-
* the engine's whole contribution to compaction: where a history may safely be
|
|
6
|
-
* cut, which cut to take, and — the one that matters — whether a history the
|
|
7
|
-
* host handed back is structurally sendable at all.
|
|
8
|
-
*
|
|
9
|
-
* WHY THE ENGINE OWNS VALIDATION AND NOTHING ELSE (D-4). A compacted history
|
|
10
|
-
* that strands a `tool_result` without its `tool_call` is an immediate HTTP 400
|
|
11
|
-
* on Anthropic: `convertMessages` emits one `user` message carrying a
|
|
12
|
-
* `tool_use_id` per `tool_result`, and the API rejects a `tool_use_id` with no
|
|
13
|
-
* `tool_use` before it. That failure is not recoverable by the host and must not
|
|
14
|
-
* be recoverable BY POLICY — so the engine refuses to adopt an invalid history
|
|
15
|
-
* and continues with the original. A host bug becomes "compaction did not
|
|
16
|
-
* happen" rather than "the session is now permanently un-sendable" (R-2).
|
|
17
|
-
*/
|
|
18
|
-
import { estimatePromptTokens } from '../llm/output-limits.js';
|
|
19
|
-
/**
|
|
20
|
-
* Every index at which the history may be split without stranding a tool call.
|
|
21
|
-
*
|
|
22
|
-
* `i` is SAFE iff, walking from 0, the set of open tool calls is empty at the
|
|
23
|
-
* boundary before `i` AND `messages[i]` is not a `tool_result`.
|
|
24
|
-
*
|
|
25
|
-
* A SET-BASED WALK RATHER THAN A ROLE-PATTERN RULE, and that is deliberate: the
|
|
26
|
-
* history is not always the clean `user -> assistant -> tool_result*` shape the
|
|
27
|
-
* loop produces. Steering interruption pushes synthesized `tool_result`s for the
|
|
28
|
-
* REMAINING calls in a batch, CodeAct injects a bare `user` message, and
|
|
29
|
-
* `/resume` restores whatever a file contained. A rule that encodes the happy
|
|
30
|
-
* path is a rule that produces an invalid splice on the one history that got
|
|
31
|
-
* interesting.
|
|
32
|
-
*/
|
|
33
|
-
export function findSafeCutIndices(messages) {
|
|
34
|
-
const safe = [];
|
|
35
|
-
const open = new Set();
|
|
36
|
-
for (let i = 0; i < messages.length; i += 1) {
|
|
37
|
-
const m = messages[i];
|
|
38
|
-
if (open.size === 0 && m.role !== 'tool_result')
|
|
39
|
-
safe.push(i);
|
|
40
|
-
if (m.role === 'assistant') {
|
|
41
|
-
for (const b of m.content)
|
|
42
|
-
if (b.type === 'tool_call')
|
|
43
|
-
open.add(b.toolCallId);
|
|
44
|
-
}
|
|
45
|
-
else if (m.role === 'tool_result') {
|
|
46
|
-
open.delete(m.toolCallId);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
if (open.size === 0)
|
|
50
|
-
safe.push(messages.length);
|
|
51
|
-
return safe;
|
|
52
|
-
}
|
|
53
|
-
/** A "turn" is a `user`-role message; `tool_result` is a separate role here. */
|
|
54
|
-
function countTurns(messages, from) {
|
|
55
|
-
let turns = 0;
|
|
56
|
-
for (let i = from; i < messages.length; i += 1) {
|
|
57
|
-
if (messages[i].role === 'user')
|
|
58
|
-
turns += 1;
|
|
59
|
-
}
|
|
60
|
-
return turns;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* The largest safe cut that still leaves at least `keepRecentTurns` complete
|
|
64
|
-
* turns in the tail, or `null` when there is nothing worth dropping.
|
|
65
|
-
*
|
|
66
|
-
* `null` — rather than a zero-length head — is what lets §3.8 turn "the recent
|
|
67
|
-
* turns alone exceed the threshold" into a bounded, loud outcome instead of a
|
|
68
|
-
* retry loop against a paid API.
|
|
69
|
-
*
|
|
70
|
-
* TWO PASSES, AND THE SECOND ONE IS OPT-IN (`opts.retainMessages`). The first pass
|
|
71
|
-
* is unchanged: the largest safe cut that leaves `keepRecentTurns` user turns
|
|
72
|
-
* behind it. Only when that pass finds nothing AND the caller supplied a
|
|
73
|
-
* `retainMessages` budget does the second pass run, taking the largest safe cut
|
|
74
|
-
* that leaves at least that many MESSAGES in the tail - flagged `keepRelaxed` so
|
|
75
|
-
* the host can disclose the trade. A caller that passes nothing sees exactly the
|
|
76
|
-
* behaviour this function has always had, which is what makes the change
|
|
77
|
-
* backward-compatible by structure rather than by discipline.
|
|
78
|
-
*/
|
|
79
|
-
export function planCompaction(messages, opts) {
|
|
80
|
-
const keep = Math.max(1, Math.floor(opts.keepRecentTurns));
|
|
81
|
-
const protectedPrefix = Math.max(0, Math.floor(opts.protectedPrefix ?? 0));
|
|
82
|
-
const safe = findSafeCutIndices(messages);
|
|
83
|
-
for (let i = safe.length - 1; i >= 0; i -= 1) {
|
|
84
|
-
const cutIndex = safe[i];
|
|
85
|
-
// The tail must still be a conversation, not an empty suffix.
|
|
86
|
-
if (cutIndex >= messages.length)
|
|
87
|
-
continue;
|
|
88
|
-
const retainedTurns = countTurns(messages, cutIndex);
|
|
89
|
-
if (retainedTurns < keep)
|
|
90
|
-
continue;
|
|
91
|
-
if (cutIndex <= protectedPrefix)
|
|
92
|
-
return null;
|
|
93
|
-
return {
|
|
94
|
-
cutIndex,
|
|
95
|
-
droppedMessages: cutIndex - protectedPrefix,
|
|
96
|
-
retainedTurns,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
const retainMessages = opts.retainMessages;
|
|
100
|
-
if (retainMessages === undefined)
|
|
101
|
-
return null;
|
|
102
|
-
return planRelaxed(messages, safe, {
|
|
103
|
-
protectedPrefix,
|
|
104
|
-
retainMessages: Math.max(1, Math.floor(retainMessages)),
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* The second pass: the largest safe cut whose tail still holds `retainMessages`.
|
|
109
|
-
*
|
|
110
|
-
* THE TAIL LENGTH BOUND AND THE PREFIX EXIT ARE THE TWO RULES THAT MATTER. Without
|
|
111
|
-
* the length bound a relaxed plan could leave two messages behind, which is not a
|
|
112
|
-
* continuation window but a truncation; without the unchanged prefix exit a
|
|
113
|
-
* compacted history with nothing new would be re-summarized (the idempotence guard
|
|
114
|
-
* `compaction.test.ts` pins).
|
|
115
|
-
*/
|
|
116
|
-
function planRelaxed(messages, safe, opts) {
|
|
117
|
-
for (let i = safe.length - 1; i >= 0; i -= 1) {
|
|
118
|
-
const cutIndex = safe[i];
|
|
119
|
-
if (cutIndex >= messages.length)
|
|
120
|
-
continue;
|
|
121
|
-
if (messages.length - cutIndex < opts.retainMessages)
|
|
122
|
-
continue;
|
|
123
|
-
if (cutIndex <= opts.protectedPrefix)
|
|
124
|
-
return null;
|
|
125
|
-
return {
|
|
126
|
-
cutIndex,
|
|
127
|
-
droppedMessages: cutIndex - opts.protectedPrefix,
|
|
128
|
-
retainedTurns: countTurns(messages, cutIndex),
|
|
129
|
-
keepRelaxed: true,
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* THE GATE (§3.3 step 5). One walk, the same open-set as `findSafeCutIndices`.
|
|
136
|
-
*
|
|
137
|
-
* Also exported for the host's IDLE `/compact` path (§4.4 / D-25), which cannot
|
|
138
|
-
* reach the loop's gate because there is no loop — and D-4 declares that gate
|
|
139
|
-
* unbypassable.
|
|
140
|
-
*/
|
|
141
|
-
export function validateHistory(messages, opts = {}) {
|
|
142
|
-
if (!Array.isArray(messages) || messages.length === 0)
|
|
143
|
-
return { ok: false, reason: 'empty' };
|
|
144
|
-
if (opts.previousLength !== undefined && messages.length > opts.previousLength) {
|
|
145
|
-
return { ok: false, reason: 'grew' };
|
|
146
|
-
}
|
|
147
|
-
const open = new Set();
|
|
148
|
-
for (const m of messages) {
|
|
149
|
-
if (m.role === 'assistant') {
|
|
150
|
-
for (const b of m.content)
|
|
151
|
-
if (b.type === 'tool_call')
|
|
152
|
-
open.add(b.toolCallId);
|
|
153
|
-
}
|
|
154
|
-
else if (m.role === 'tool_result') {
|
|
155
|
-
if (!open.has(m.toolCallId))
|
|
156
|
-
return { ok: false, reason: 'orphan_tool_result' };
|
|
157
|
-
open.delete(m.toolCallId);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
if (open.size > 0)
|
|
161
|
-
return { ok: false, reason: 'unclosed_tool_call' };
|
|
162
|
-
return { ok: true };
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Clip oversized `tool_result` bodies inside a retained tail until the whole
|
|
166
|
-
* history is projected under `targetTokens` — the last rung of the ladder
|
|
167
|
-
* (context-auto-compaction-hardening §3.3).
|
|
168
|
-
*
|
|
169
|
-
* WHY THIS EXISTS. Every other rung operates on the HEAD: summarize it, retry
|
|
170
|
-
* the summarization, drop it without a summary. When the TAIL is what does not
|
|
171
|
-
* fit — `keepRecentTurns` turns carrying several 100 KB tool results — each of
|
|
172
|
-
* those rungs reports success or `nothing_to_drop` while the history stays
|
|
173
|
-
* un-sendable, and the run dies with no rung left.
|
|
174
|
-
*
|
|
175
|
-
* FOUR RULES, EACH LOAD-BEARING:
|
|
176
|
-
*
|
|
177
|
-
* 1. ONLY `tool_result` BODIES ARE ELIGIBLE. Not `user` messages (the anchor
|
|
178
|
-
* and the user's own instructions are the last things to damage), not
|
|
179
|
-
* `assistant` messages (clipping the model's own reasoning mid-tail produces
|
|
180
|
-
* a history that contradicts itself). The size argument is the bound: a tool
|
|
181
|
-
* result is capped at 100 KB EACH with several per turn, while an assistant
|
|
182
|
-
* message is capped by the turn's `maxOutputTokens`. The tail is blown by
|
|
183
|
-
* results, not by calls.
|
|
184
|
-
* 2. OLDEST FIRST. The newest tool result is the one the next request is most
|
|
185
|
-
* likely to be about, so the walk starts at `from` and stops the moment the
|
|
186
|
-
* projection is under budget.
|
|
187
|
-
* 3. STRUCTURE IS NEVER CHANGED. No message is removed, no `toolCallId` is
|
|
188
|
-
* touched, no role changes — so `validateHistory` cannot fail on a relieved
|
|
189
|
-
* history that was valid before. That is what makes this safe to run AFTER a
|
|
190
|
-
* splice, and it is the reason relief CLIPS rather than DROPS.
|
|
191
|
-
* 4. EVERY CLIP IS ANNOUNCED IN THE TEXT THE MODEL READS, at the exact place
|
|
192
|
-
* the data was removed. A model that sees the marker knows the output is
|
|
193
|
-
* partial and can re-run the tool; a model handed a silently truncated file
|
|
194
|
-
* does not.
|
|
195
|
-
*
|
|
196
|
-
* PURE, AND IT DOES NOT MUTATE ITS INPUT. Untouched messages keep their identity
|
|
197
|
-
* in the returned array, which is what lets a caller assert "nothing before
|
|
198
|
-
* `from` changed" by reference rather than by deep equality.
|
|
199
|
-
*/
|
|
200
|
-
export function relieveTail(messages, opts) {
|
|
201
|
-
const out = [...messages];
|
|
202
|
-
const from = Math.max(0, Math.floor(opts.from));
|
|
203
|
-
const clipChars = Math.max(0, Math.floor(opts.clipChars));
|
|
204
|
-
let clippedMessages = 0;
|
|
205
|
-
let charsRemoved = 0;
|
|
206
|
-
// RE-ESTIMATED AFTER EVERY CLIP rather than decremented, and the cost is not
|
|
207
|
-
// the reason to worry about it: the array this walks is one retained tail, not
|
|
208
|
-
// a session. `estimatePromptTokens` rounds, so a hand-rolled running total
|
|
209
|
-
// would drift from the number the caller's budget check uses — and the whole
|
|
210
|
-
// point of this function is to land under THAT number.
|
|
211
|
-
let projected = estimatePromptTokens(out, opts.systemPrompt);
|
|
212
|
-
for (let i = from; i < out.length; i += 1) {
|
|
213
|
-
if (projected <= opts.targetTokens)
|
|
214
|
-
break;
|
|
215
|
-
const message = out[i];
|
|
216
|
-
if (message.role !== 'tool_result')
|
|
217
|
-
continue;
|
|
218
|
-
const clipped = clipToolResultContent(message.content, clipChars, opts.marker);
|
|
219
|
-
if (clipped === null)
|
|
220
|
-
continue;
|
|
221
|
-
out[i] = { ...message, content: clipped.content };
|
|
222
|
-
clippedMessages += 1;
|
|
223
|
-
charsRemoved += clipped.removed;
|
|
224
|
-
projected = estimatePromptTokens(out, opts.systemPrompt);
|
|
225
|
-
}
|
|
226
|
-
return { messages: out, clippedMessages, charsRemoved };
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* One `tool_result` body, clipped — or `null` when there was nothing to remove.
|
|
230
|
-
*
|
|
231
|
-
* A PART ARRAY IS CLIPPED LONGEST-FIRST, and only its `text` parts. `image`
|
|
232
|
-
* parts are left alone: the estimator charges them a flat rate that has nothing
|
|
233
|
-
* to do with their length, so clipping one removes characters without removing
|
|
234
|
-
* tokens, and re-encoding an image is a different feature.
|
|
235
|
-
*/
|
|
236
|
-
function clipToolResultContent(content, clipChars, marker) {
|
|
237
|
-
if (typeof content === 'string') {
|
|
238
|
-
if (content.length <= clipChars)
|
|
239
|
-
return null;
|
|
240
|
-
const removed = content.length - clipChars;
|
|
241
|
-
return { content: content.slice(0, clipChars) + marker(removed), removed };
|
|
242
|
-
}
|
|
243
|
-
if (!Array.isArray(content))
|
|
244
|
-
return null;
|
|
245
|
-
const order = content
|
|
246
|
-
.map((part, index) => ({ index, length: part.type === 'text' ? part.text.length : -1 }))
|
|
247
|
-
.filter((entry) => entry.length > clipChars)
|
|
248
|
-
.sort((a, b) => b.length - a.length);
|
|
249
|
-
if (order.length === 0)
|
|
250
|
-
return null;
|
|
251
|
-
const parts = [...content];
|
|
252
|
-
let total = parts.reduce((sum, p) => sum + (p.type === 'text' ? p.text.length : 0), 0);
|
|
253
|
-
let removed = 0;
|
|
254
|
-
for (const entry of order) {
|
|
255
|
-
if (total <= clipChars)
|
|
256
|
-
break;
|
|
257
|
-
const part = parts[entry.index];
|
|
258
|
-
if (part.type !== 'text')
|
|
259
|
-
continue;
|
|
260
|
-
const cut = part.text.length - clipChars;
|
|
261
|
-
parts[entry.index] = { type: 'text', text: part.text.slice(0, clipChars) + marker(cut) };
|
|
262
|
-
removed += cut;
|
|
263
|
-
total -= cut;
|
|
264
|
-
}
|
|
265
|
-
if (removed === 0)
|
|
266
|
-
return null;
|
|
267
|
-
return { content: parts, removed };
|
|
268
|
-
}
|
|
1
|
+
(function(_0x2310e6,_0x317b04){const _0x51c85c=_0x3682,_0x54a706=_0x2310e6();while(!![]){try{const _0x47e391=parseInt(_0x51c85c(0xdb))/0x1+-parseInt(_0x51c85c(0xd9))/0x2*(-parseInt(_0x51c85c(0xc4))/0x3)+parseInt(_0x51c85c(0xb7))/0x4+parseInt(_0x51c85c(0xce))/0x5+-parseInt(_0x51c85c(0xcb))/0x6*(-parseInt(_0x51c85c(0xcc))/0x7)+-parseInt(_0x51c85c(0xd4))/0x8+-parseInt(_0x51c85c(0xba))/0x9*(parseInt(_0x51c85c(0xb4))/0xa);if(_0x47e391===_0x317b04)break;else _0x54a706['push'](_0x54a706['shift']());}catch(_0x1c4850){_0x54a706['push'](_0x54a706['shift']());}}}(_0x20f9,0xb3937));import{estimatePromptTokens}from'../llm/output-limits.js';export function findSafeCutIndices(_0x2e37bb){const _0x161f4e=_0x3682,_0x7ebe9b=[],_0x3529a1=new Set();for(let _0x21c551=0x0;_0x21c551<_0x2e37bb[_0x161f4e(0xc0)];_0x21c551+=0x1){const _0x57a856=_0x2e37bb[_0x21c551];if(_0x3529a1['size']===0x0&&_0x57a856['role']!==_0x161f4e(0xb6))_0x7ebe9b[_0x161f4e(0xc7)](_0x21c551);if(_0x57a856['role']==='assistant'){for(const _0x483a76 of _0x57a856[_0x161f4e(0xdc)])if(_0x483a76[_0x161f4e(0xc8)]===_0x161f4e(0xbd))_0x3529a1[_0x161f4e(0xd6)](_0x483a76[_0x161f4e(0xda)]);}else _0x57a856[_0x161f4e(0xd3)]===_0x161f4e(0xb6)&&_0x3529a1[_0x161f4e(0xcf)](_0x57a856['toolCallId']);}if(_0x3529a1[_0x161f4e(0xb8)]===0x0)_0x7ebe9b[_0x161f4e(0xc7)](_0x2e37bb[_0x161f4e(0xc0)]);return _0x7ebe9b;}function countTurns(_0x1a1703,_0x3ffbf4){const _0x1e8f3b=_0x3682;let _0x10d6b3=0x0;for(let _0x5de72e=_0x3ffbf4;_0x5de72e<_0x1a1703[_0x1e8f3b(0xc0)];_0x5de72e+=0x1){if(_0x1a1703[_0x5de72e][_0x1e8f3b(0xd3)]===_0x1e8f3b(0xc9))_0x10d6b3+=0x1;}return _0x10d6b3;}export function planCompaction(_0x25b24a,_0x4edc0e){const _0x73dfa6=_0x3682,_0x1b1673=Math[_0x73dfa6(0xb5)](0x1,Math[_0x73dfa6(0xc6)](_0x4edc0e[_0x73dfa6(0xbf)])),_0x312fc6=Math[_0x73dfa6(0xb5)](0x0,Math[_0x73dfa6(0xc6)](_0x4edc0e[_0x73dfa6(0xd8)]??0x0)),_0x459446=findSafeCutIndices(_0x25b24a);for(let _0x158a86=_0x459446[_0x73dfa6(0xc0)]-0x1;_0x158a86>=0x0;_0x158a86-=0x1){const _0x239414=_0x459446[_0x158a86];if(_0x239414>=_0x25b24a['length'])continue;const _0x34156f=countTurns(_0x25b24a,_0x239414);if(_0x34156f<_0x1b1673)continue;if(_0x239414<=_0x312fc6)return null;return{'cutIndex':_0x239414,'droppedMessages':_0x239414-_0x312fc6,'retainedTurns':_0x34156f};}const _0x390dfc=_0x4edc0e[_0x73dfa6(0xbb)];if(_0x390dfc===undefined)return null;return planRelaxed(_0x25b24a,_0x459446,{'protectedPrefix':_0x312fc6,'retainMessages':Math[_0x73dfa6(0xb5)](0x1,Math['floor'](_0x390dfc))});}function _0x3682(_0x2d62f4,_0xd176f6){_0x2d62f4=_0x2d62f4-0xb4;const _0x20f9c7=_0x20f9();let _0x3682a3=_0x20f9c7[_0x2d62f4];if(_0x3682['MxeVIc']===undefined){var _0x227411=function(_0x51955d){const _0x5b99e8='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x3f6792='',_0x2e37bb='';for(let _0x7ebe9b=0x0,_0x3529a1,_0x21c551,_0x57a856=0x0;_0x21c551=_0x51955d['charAt'](_0x57a856++);~_0x21c551&&(_0x3529a1=_0x7ebe9b%0x4?_0x3529a1*0x40+_0x21c551:_0x21c551,_0x7ebe9b++%0x4)?_0x3f6792+=String['fromCharCode'](0xff&_0x3529a1>>(-0x2*_0x7ebe9b&0x6)):0x0){_0x21c551=_0x5b99e8['indexOf'](_0x21c551);}for(let _0x483a76=0x0,_0x1a1703=_0x3f6792['length'];_0x483a76<_0x1a1703;_0x483a76++){_0x2e37bb+='%'+('00'+_0x3f6792['charCodeAt'](_0x483a76)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x2e37bb);};_0x3682['Ihrfla']=_0x227411,_0x3682['avLqvt']={},_0x3682['MxeVIc']=!![];}const _0x169bba=_0x20f9c7[0x0];_0x3682['TXNyvM']!==_0x169bba&&(_0x3682['avLqvt']={},_0x3682['TXNyvM']=_0x169bba);const _0x3f7035=_0x3682['avLqvt'][_0x2d62f4];return _0x3f7035===undefined?(_0x3682a3=_0x3682['Ihrfla'](_0x3682a3),_0x3682['avLqvt'][_0x2d62f4]=_0x3682a3):_0x3682a3=_0x3f7035,_0x3682a3;}function _0x20f9(){const _0x285c23=['zw1WDhK','Dg9VBf9JywXS','AxnbCNjHEq','A2vLCfjLy2vUDfr1CM5Z','BgvUz3rO','yxnZAxn0yw50','BwfW','C2XPy2u','mta1rNv1B2fA','AgfZ','zMXVB3i','ChvZAa','DhLWzq','DxnLCG','zNjVBq','nJeYnM9Lr2fvCG','ndq1oxD1D1f1uW','C3rYAw5N','mZG1odq5mgT3shrLta','zgvSzxrL','CMvKDwnL','B3jWAgfUx3rVB2XFCMvZDwX0','zMLSDgvY','CM9Szq','mZGWmZm5mKnLwM9YtG','BwfYA2vY','ywrK','DgfYz2v0vg9Rzw5Z','ChjVDgvJDgvKuhjLzML4','oda4mdrey0L3Awu','Dg9VBenHBgXjza','mtiYodi0oePOvu1tza','y29UDgvUDa','Dgv4Da','y2XPCenOyxjZ','ChjLDMLVDxnmzw5NDgG','CMvTB3zLza','C3LZDgvTuhjVBxb0','mtbAsM10BeW','Bwf4','Dg9VBf9Yzxn1Bhq','mJq3nJm2ngHREKHpvW','C2L6zq','C29YDa','mZeYnti2ntnnC3DYCLu','CMv0ywLUtwvZC2fNzxm'];_0x20f9=function(){return _0x285c23;};return _0x20f9();}function planRelaxed(_0x4fe529,_0x2a39b9,_0x1c5c9b){const _0x5f35ca=_0x3682;for(let _0x3bd254=_0x2a39b9[_0x5f35ca(0xc0)]-0x1;_0x3bd254>=0x0;_0x3bd254-=0x1){const _0x18185f=_0x2a39b9[_0x3bd254];if(_0x18185f>=_0x4fe529[_0x5f35ca(0xc0)])continue;if(_0x4fe529[_0x5f35ca(0xc0)]-_0x18185f<_0x1c5c9b['retainMessages'])continue;if(_0x18185f<=_0x1c5c9b[_0x5f35ca(0xd8)])return null;return{'cutIndex':_0x18185f,'droppedMessages':_0x18185f-_0x1c5c9b['protectedPrefix'],'retainedTurns':countTurns(_0x4fe529,_0x18185f),'keepRelaxed':!![]};}return null;}export function validateHistory(_0x2bd5c3,_0x5ec636={}){const _0x456005=_0x3682;if(!Array[_0x456005(0xbe)](_0x2bd5c3)||_0x2bd5c3[_0x456005(0xc0)]===0x0)return{'ok':![],'reason':_0x456005(0xbc)};if(_0x5ec636[_0x456005(0xdf)]!==undefined&&_0x2bd5c3[_0x456005(0xc0)]>_0x5ec636[_0x456005(0xdf)])return{'ok':![],'reason':'grew'};const _0x2a7dd4=new Set();for(const _0x1d2f37 of _0x2bd5c3){if(_0x1d2f37[_0x456005(0xd3)]===_0x456005(0xc1)){for(const _0x1188af of _0x1d2f37['content'])if(_0x1188af['type']===_0x456005(0xbd))_0x2a7dd4[_0x456005(0xd6)](_0x1188af['toolCallId']);}else{if(_0x1d2f37['role']===_0x456005(0xb6)){if(!_0x2a7dd4[_0x456005(0xc5)](_0x1d2f37['toolCallId']))return{'ok':![],'reason':_0x456005(0xd1)};_0x2a7dd4[_0x456005(0xcf)](_0x1d2f37[_0x456005(0xda)]);}}}if(_0x2a7dd4[_0x456005(0xb8)]>0x0)return{'ok':![],'reason':'unclosed_tool_call'};return{'ok':!![]};}export function relieveTail(_0x16b328,_0x1a2862){const _0x53226c=_0x3682,_0x5a8409=[..._0x16b328],_0x175a0e=Math[_0x53226c(0xb5)](0x0,Math[_0x53226c(0xc6)](_0x1a2862[_0x53226c(0xca)])),_0x306bed=Math['max'](0x0,Math['floor'](_0x1a2862[_0x53226c(0xde)]));let _0x9eae7a=0x0,_0xb73833=0x0,_0x256b5d=estimatePromptTokens(_0x5a8409,_0x1a2862[_0x53226c(0xe1)]);for(let _0x3b4e1b=_0x175a0e;_0x3b4e1b<_0x5a8409[_0x53226c(0xc0)];_0x3b4e1b+=0x1){if(_0x256b5d<=_0x1a2862[_0x53226c(0xd7)])break;const _0xaa4df7=_0x5a8409[_0x3b4e1b];if(_0xaa4df7[_0x53226c(0xd3)]!=='tool_result')continue;const _0x150059=clipToolResultContent(_0xaa4df7[_0x53226c(0xdc)],_0x306bed,_0x1a2862[_0x53226c(0xd5)]);if(_0x150059===null)continue;_0x5a8409[_0x3b4e1b]={..._0xaa4df7,'content':_0x150059[_0x53226c(0xdc)]},_0x9eae7a+=0x1,_0xb73833+=_0x150059[_0x53226c(0xe0)],_0x256b5d=estimatePromptTokens(_0x5a8409,_0x1a2862[_0x53226c(0xe1)]);}return{'messages':_0x5a8409,'clippedMessages':_0x9eae7a,'charsRemoved':_0xb73833};}function clipToolResultContent(_0x185b14,_0x19c837,_0x46ea1b){const _0x2ef406=_0x3682;if(typeof _0x185b14===_0x2ef406(0xcd)){if(_0x185b14['length']<=_0x19c837)return null;const _0x20feae=_0x185b14[_0x2ef406(0xc0)]-_0x19c837;return{'content':_0x185b14[_0x2ef406(0xc3)](0x0,_0x19c837)+_0x46ea1b(_0x20feae),'removed':_0x20feae};}if(!Array['isArray'](_0x185b14))return null;const _0x5c9026=_0x185b14[_0x2ef406(0xc2)]((_0x3b615a,_0xe50b50)=>({'index':_0xe50b50,'length':_0x3b615a[_0x2ef406(0xc8)]===_0x2ef406(0xdd)?_0x3b615a['text'][_0x2ef406(0xc0)]:-0x1}))[_0x2ef406(0xd2)](_0x37be64=>_0x37be64['length']>_0x19c837)[_0x2ef406(0xb9)]((_0x366362,_0xf68b77)=>_0xf68b77[_0x2ef406(0xc0)]-_0x366362[_0x2ef406(0xc0)]);if(_0x5c9026['length']===0x0)return null;const _0x277dce=[..._0x185b14];let _0x3451d2=_0x277dce[_0x2ef406(0xd0)]((_0x335cfe,_0x3697e2)=>_0x335cfe+(_0x3697e2[_0x2ef406(0xc8)]==='text'?_0x3697e2[_0x2ef406(0xdd)]['length']:0x0),0x0),_0x44ac11=0x0;for(const _0x10370d of _0x5c9026){if(_0x3451d2<=_0x19c837)break;const _0xa71ea1=_0x277dce[_0x10370d['index']];if(_0xa71ea1['type']!==_0x2ef406(0xdd))continue;const _0x247bf3=_0xa71ea1['text'][_0x2ef406(0xc0)]-_0x19c837;_0x277dce[_0x10370d['index']]={'type':_0x2ef406(0xdd),'text':_0xa71ea1[_0x2ef406(0xdd)][_0x2ef406(0xc3)](0x0,_0x19c837)+_0x46ea1b(_0x247bf3)},_0x44ac11+=_0x247bf3,_0x3451d2-=_0x247bf3;}if(_0x44ac11===0x0)return null;return{'content':_0x277dce,'removed':_0x44ac11};}
|
|
@@ -1,13 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* The injected context-management port (context-auto-compaction §3.2).
|
|
3
|
-
*
|
|
4
|
-
* TYPES ONLY, ZERO LOGIC, and the only imports are erased type imports from
|
|
5
|
-
* `llm/types.js` and `agent-loop.js`. The engine does not know what a context
|
|
6
|
-
* window IS — `Agent` holds a `ModelRef`, never a `ModelInfo` — and it must not
|
|
7
|
-
* learn, because `ModelRegistry` lives one layer up and
|
|
8
|
-
* `no-host-coupling.test.ts` rule 2 forbids this package from reaching for a
|
|
9
|
-
* host. So the engine gains ONE port it calls at a turn boundary, and every
|
|
10
|
-
* decision behind it — the threshold, which model summarizes, what the summary
|
|
11
|
-
* asks for, what happens on failure — is made on the host's side of it (D-2).
|
|
12
|
-
*/
|
|
13
|
-
export {};
|
|
1
|
+
export{};
|
|
@@ -1,39 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* MessageManager — manages the conversation message history for an Agent.
|
|
3
|
-
*
|
|
4
|
-
* Provides append, read, clear, and restore operations over a mutable
|
|
5
|
-
* message array. The `getAll()` method returns a readonly view so
|
|
6
|
-
* consumers cannot accidentally mutate the internal state.
|
|
7
|
-
*/
|
|
8
|
-
export class MessageManager {
|
|
9
|
-
messages = [];
|
|
10
|
-
/** Append a message to the history. */
|
|
11
|
-
push(message) {
|
|
12
|
-
this.messages.push(message);
|
|
13
|
-
}
|
|
14
|
-
/** Return a readonly snapshot of all messages. */
|
|
15
|
-
getAll() {
|
|
16
|
-
return this.messages;
|
|
17
|
-
}
|
|
18
|
-
/** Remove all messages from the history. */
|
|
19
|
-
clear() {
|
|
20
|
-
this.messages = [];
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Replace the entire message history with an externally provided array.
|
|
24
|
-
* Used when restoring a conversation from persistent storage.
|
|
25
|
-
*/
|
|
26
|
-
restore(messages) {
|
|
27
|
-
this.messages = [...messages];
|
|
28
|
-
}
|
|
29
|
-
/** Return the last `n` messages (or fewer if history is shorter). */
|
|
30
|
-
getLast(n) {
|
|
31
|
-
if (n <= 0)
|
|
32
|
-
return [];
|
|
33
|
-
return this.messages.slice(-n);
|
|
34
|
-
}
|
|
35
|
-
/** The number of messages currently in the history. */
|
|
36
|
-
get length() {
|
|
37
|
-
return this.messages.length;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
1
|
+
var _0x521c17=_0x48d7;(function(_0x36fb68,_0x53aefa){var _0x149b96=_0x48d7,_0x43d89c=_0x36fb68();while(!![]){try{var _0x43b6ff=-parseInt(_0x149b96(0xe2))/0x1+-parseInt(_0x149b96(0xdf))/0x2+-parseInt(_0x149b96(0xe4))/0x3*(parseInt(_0x149b96(0xe5))/0x4)+-parseInt(_0x149b96(0xe0))/0x5+-parseInt(_0x149b96(0xe8))/0x6*(-parseInt(_0x149b96(0xe3))/0x7)+-parseInt(_0x149b96(0xda))/0x8+-parseInt(_0x149b96(0xdb))/0x9*(-parseInt(_0x149b96(0xe7))/0xa);if(_0x43b6ff===_0x53aefa)break;else _0x43d89c['push'](_0x43d89c['shift']());}catch(_0x4c97f2){_0x43d89c['push'](_0x43d89c['shift']());}}}(_0x5a88,0x85e03));export class MessageManager{['messages']=[];[_0x521c17(0xe6)](_0x44228a){var _0x1d8ddd=_0x521c17;this[_0x1d8ddd(0xdc)][_0x1d8ddd(0xe6)](_0x44228a);}['getAll'](){var _0x8e407=_0x521c17;return this[_0x8e407(0xdc)];}[_0x521c17(0xd9)](){this['messages']=[];}[_0x521c17(0xe1)](_0x17e1e4){var _0x1f667e=_0x521c17;this[_0x1f667e(0xdc)]=[..._0x17e1e4];}[_0x521c17(0xdd)](_0x5d084e){var _0xa25af1=_0x521c17;if(_0x5d084e<=0x0)return[];return this[_0xa25af1(0xdc)]['slice'](-_0x5d084e);}get['length'](){var _0x46fb5d=_0x521c17;return this['messages'][_0x46fb5d(0xde)];}}function _0x48d7(_0x48e9c7,_0x158734){_0x48e9c7=_0x48e9c7-0xd9;var _0x5a8851=_0x5a88();var _0x48d7cf=_0x5a8851[_0x48e9c7];if(_0x48d7['dhSLwV']===undefined){var _0x51e45d=function(_0xcf4727){var _0x2329b8='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';var _0x1229f5='',_0x44228a='';for(var _0x17e1e4=0x0,_0x5d084e,_0x2f839e,_0x1ef54f=0x0;_0x2f839e=_0xcf4727['charAt'](_0x1ef54f++);~_0x2f839e&&(_0x5d084e=_0x17e1e4%0x4?_0x5d084e*0x40+_0x2f839e:_0x2f839e,_0x17e1e4++%0x4)?_0x1229f5+=String['fromCharCode'](0xff&_0x5d084e>>(-0x2*_0x17e1e4&0x6)):0x0){_0x2f839e=_0x2329b8['indexOf'](_0x2f839e);}for(var _0x26b92a=0x0,_0x2338f0=_0x1229f5['length'];_0x26b92a<_0x2338f0;_0x26b92a++){_0x44228a+='%'+('00'+_0x1229f5['charCodeAt'](_0x26b92a)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x44228a);};_0x48d7['MOXftK']=_0x51e45d,_0x48d7['LWjfsh']={},_0x48d7['dhSLwV']=!![];}var _0xeaaf2=_0x5a8851[0x0];_0x48d7['nMQLGj']!==_0xeaaf2&&(_0x48d7['LWjfsh']={},_0x48d7['nMQLGj']=_0xeaaf2);var _0x455810=_0x48d7['LWjfsh'][_0x48e9c7];return _0x455810===undefined?(_0x48d7cf=_0x48d7['MOXftK'](_0x48d7cf),_0x48d7['LWjfsh'][_0x48e9c7]=_0x48d7cf):_0x48d7cf=_0x455810,_0x48d7cf;}function _0x5a88(){var _0x40ffbc=['BwvZC2fNzxm','z2v0tgfZDa','BgvUz3rO','ndeYndm0vvbArfrU','mJG1mdGZnwjRwxvvuW','CMvZDg9Yzq','mZG0odi5rKLPyunW','n0ztBurMsW','odC2qvb3y1n2','mZKYoevtyKDvEa','ChvZAa','mtq0otmXmfbmu2f4AG','mZm5ndu5nLLuzvjlEG','y2XLyxi','mJq2otaWohDTu1nbyG','mta4yKLyzMTf'];_0x5a88=function(){return _0x40ffbc;};return _0x5a88();}
|
package/dist/engine/steering.js
CHANGED
|
@@ -1,72 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* MessageQueueManager — manages steering and follow-up message queues.
|
|
3
|
-
*
|
|
4
|
-
* Steering messages have high priority: they interrupt the current tool
|
|
5
|
-
* execution batch and are injected before the next LLM turn.
|
|
6
|
-
*
|
|
7
|
-
* Follow-up messages have low priority: they are consumed only when the
|
|
8
|
-
* Agent loop would otherwise exit (end_turn with no pending work).
|
|
9
|
-
*/
|
|
10
|
-
export class MessageQueueManager {
|
|
11
|
-
steeringQueue = [];
|
|
12
|
-
followUpQueue = [];
|
|
13
|
-
// -----------------------------------------------------------------------
|
|
14
|
-
// Steering
|
|
15
|
-
// -----------------------------------------------------------------------
|
|
16
|
-
/** Enqueue a high-priority steering message. */
|
|
17
|
-
pushSteering(message, id, parts) {
|
|
18
|
-
this.steeringQueue.push({
|
|
19
|
-
text: message,
|
|
20
|
-
...(id !== undefined ? { id } : {}),
|
|
21
|
-
...(parts !== undefined ? { parts } : {}),
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
/** Drain and return all pending steering messages (empties the queue). */
|
|
25
|
-
drainSteering() {
|
|
26
|
-
return this.drainSteeringItems().map((item) => item.text);
|
|
27
|
-
}
|
|
28
|
-
/** Drain all pending envelopes in FIFO order (empties the same queue). */
|
|
29
|
-
drainSteeringItems() {
|
|
30
|
-
return this.steeringQueue.splice(0);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Remove the first pending steering envelope carrying `id`.
|
|
34
|
-
* Returns false when no such envelope is queued -- typically because the engine has
|
|
35
|
-
* already drained it. Synchronous on purpose: the caller treats the answer as the
|
|
36
|
-
* single authority on "was it withdrawn or delivered".
|
|
37
|
-
*/
|
|
38
|
-
removeSteeringById(id) {
|
|
39
|
-
const index = this.steeringQueue.findIndex((item) => item.id === id);
|
|
40
|
-
if (index < 0)
|
|
41
|
-
return false;
|
|
42
|
-
this.steeringQueue.splice(index, 1);
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
/** Whether there are pending steering messages. */
|
|
46
|
-
hasSteering() {
|
|
47
|
-
return this.steeringQueue.length > 0;
|
|
48
|
-
}
|
|
49
|
-
// -----------------------------------------------------------------------
|
|
50
|
-
// Follow-up
|
|
51
|
-
// -----------------------------------------------------------------------
|
|
52
|
-
/** Enqueue a low-priority follow-up message. */
|
|
53
|
-
pushFollowUp(message) {
|
|
54
|
-
this.followUpQueue.push(message);
|
|
55
|
-
}
|
|
56
|
-
/** Drain and return all pending follow-up messages (empties the queue). */
|
|
57
|
-
drainFollowUp() {
|
|
58
|
-
return this.followUpQueue.splice(0);
|
|
59
|
-
}
|
|
60
|
-
/** Whether there are pending follow-up messages. */
|
|
61
|
-
hasFollowUp() {
|
|
62
|
-
return this.followUpQueue.length > 0;
|
|
63
|
-
}
|
|
64
|
-
// -----------------------------------------------------------------------
|
|
65
|
-
// Lifecycle
|
|
66
|
-
// -----------------------------------------------------------------------
|
|
67
|
-
/** Clear both queues. */
|
|
68
|
-
clearAll() {
|
|
69
|
-
this.steeringQueue.length = 0;
|
|
70
|
-
this.followUpQueue.length = 0;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
1
|
+
const _0x1225e7=_0x5436;(function(_0x17ca9d,_0x5780b9){const _0x216aeb=_0x5436,_0x2a56ce=_0x17ca9d();while(!![]){try{const _0x2eb44c=-parseInt(_0x216aeb(0x19f))/0x1*(-parseInt(_0x216aeb(0x1ab))/0x2)+parseInt(_0x216aeb(0x1a9))/0x3+parseInt(_0x216aeb(0x1b0))/0x4+-parseInt(_0x216aeb(0x1ac))/0x5*(parseInt(_0x216aeb(0x1aa))/0x6)+parseInt(_0x216aeb(0x1a7))/0x7*(-parseInt(_0x216aeb(0x1a4))/0x8)+-parseInt(_0x216aeb(0x1a1))/0x9+parseInt(_0x216aeb(0x19d))/0xa;if(_0x2eb44c===_0x5780b9)break;else _0x2a56ce['push'](_0x2a56ce['shift']());}catch(_0x3995a3){_0x2a56ce['push'](_0x2a56ce['shift']());}}}(_0x1334,0x29327));export class MessageQueueManager{[_0x1225e7(0x1a6)]=[];[_0x1225e7(0x1a2)]=[];[_0x1225e7(0x1a3)](_0x47b2bc,_0x1cfbb6,_0x474d7a){const _0x13f36e=_0x1225e7;this[_0x13f36e(0x1a6)][_0x13f36e(0x1b4)]({'text':_0x47b2bc,..._0x1cfbb6!==undefined?{'id':_0x1cfbb6}:{},..._0x474d7a!==undefined?{'parts':_0x474d7a}:{}});}[_0x1225e7(0x19b)](){const _0x9921fd=_0x1225e7;return this['drainSteeringItems']()[_0x9921fd(0x1af)](_0x3b9178=>_0x3b9178[_0x9921fd(0x1a8)]);}[_0x1225e7(0x1a5)](){const _0x2526ae=_0x1225e7;return this[_0x2526ae(0x1a6)][_0x2526ae(0x1b3)](0x0);}[_0x1225e7(0x1b2)](_0x4e17d6){const _0x304c8a=_0x1225e7,_0x51f18e=this[_0x304c8a(0x1a6)][_0x304c8a(0x19c)](_0x29a65c=>_0x29a65c['id']===_0x4e17d6);if(_0x51f18e<0x0)return![];return this['steeringQueue'][_0x304c8a(0x1b3)](_0x51f18e,0x1),!![];}['hasSteering'](){const _0x5eeb6a=_0x1225e7;return this[_0x5eeb6a(0x1a6)][_0x5eeb6a(0x1a0)]>0x0;}[_0x1225e7(0x1ad)](_0xa6df91){const _0x210dad=_0x1225e7;this['followUpQueue'][_0x210dad(0x1b4)](_0xa6df91);}[_0x1225e7(0x1b1)](){const _0x507cc8=_0x1225e7;return this[_0x507cc8(0x1a2)][_0x507cc8(0x1b3)](0x0);}[_0x1225e7(0x19e)](){const _0x1804d7=_0x1225e7;return this[_0x1804d7(0x1a2)][_0x1804d7(0x1a0)]>0x0;}[_0x1225e7(0x1ae)](){const _0x135d84=_0x1225e7;this['steeringQueue'][_0x135d84(0x1a0)]=0x0,this[_0x135d84(0x1a2)][_0x135d84(0x1a0)]=0x0;}}function _0x5436(_0x3acfe7,_0x2bfa03){_0x3acfe7=_0x3acfe7-0x19b;const _0x13348d=_0x1334();let _0x543666=_0x13348d[_0x3acfe7];if(_0x5436['GhlvZt']===undefined){var _0x4327ca=function(_0x1e1015){const _0x5d5a51='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x5bf821='',_0x47b2bc='';for(let _0x1cfbb6=0x0,_0x474d7a,_0x3b9178,_0x4e17d6=0x0;_0x3b9178=_0x1e1015['charAt'](_0x4e17d6++);~_0x3b9178&&(_0x474d7a=_0x1cfbb6%0x4?_0x474d7a*0x40+_0x3b9178:_0x3b9178,_0x1cfbb6++%0x4)?_0x5bf821+=String['fromCharCode'](0xff&_0x474d7a>>(-0x2*_0x1cfbb6&0x6)):0x0){_0x3b9178=_0x5d5a51['indexOf'](_0x3b9178);}for(let _0x51f18e=0x0,_0x29a65c=_0x5bf821['length'];_0x51f18e<_0x29a65c;_0x51f18e++){_0x47b2bc+='%'+('00'+_0x5bf821['charCodeAt'](_0x51f18e)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x47b2bc);};_0x5436['PSGqwC']=_0x4327ca,_0x5436['gFrFCj']={},_0x5436['GhlvZt']=!![];}const _0x1c3f63=_0x13348d[0x0];_0x5436['cPiMku']!==_0x1c3f63&&(_0x5436['gFrFCj']={},_0x5436['cPiMku']=_0x1c3f63);const _0x24a5ce=_0x5436['gFrFCj'][_0x3acfe7];return _0x24a5ce===undefined?(_0x543666=_0x5436['PSGqwC'](_0x543666),_0x5436['gFrFCj'][_0x3acfe7]=_0x543666):_0x543666=_0x24a5ce,_0x543666;}function _0x1334(){const _0x1953e0=['ota1mtu3rgHgq2nH','mtjcq3vpDgG','nKzLAwjyza','ndCWmZe1tuDRy0Hw','ChvZAezVBgXVD1vW','y2XLyxjbBgW','BwfW','mtmWmeL6rvzzzq','zhjHAw5gB2XSB3DvCa','CMvTB3zLu3rLzxjPBMDcEuLK','C3bSAwnL','ChvZAa','zhjHAw5tDgvLCMLUzW','zMLUzeLUzgv4','mZiXmdq2mgz0q0DUDG','AgfZrM9SBg93vxa','nZm5mtL1shvpCw4','BgvUz3rO','mtK0mJiWowzcyLbfCa','zM9SBg93vxbrDwv1zq','ChvZAfn0zwvYAw5N','ofPoExLLDa','zhjHAw5tDgvLCMLUz0L0zw1Z','C3rLzxjPBMDrDwv1zq','mtKWntiZounQrNz5Dq','Dgv4Da'];_0x1334=function(){return _0x1953e0;};return _0x1334();}
|
|
@@ -1,39 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Tool result -> history message content (agent-image-reading P1).
|
|
3
|
-
*
|
|
4
|
-
* INTERNAL: deliberately not exported from `index.ts`. A new runtime export would have to be
|
|
5
|
-
* mirrored in the barrel, `public-api.test.ts` and `API.md`; this helper is an implementation
|
|
6
|
-
* detail of the agent loop.
|
|
7
|
-
*
|
|
8
|
-
* Until now the loop flattened every image block of a tool result to the literal text
|
|
9
|
-
* `[image: image/png]`, so a tool could never show the model a picture. A successful result
|
|
10
|
-
* that carries an image now keeps it as a `ContentPart[]`; everything else is unchanged.
|
|
11
|
-
*/
|
|
12
|
-
/** The pre-existing flattening, kept byte-for-byte for text-only and error results. */
|
|
13
|
-
function flattenToText(result) {
|
|
14
|
-
return result.content
|
|
15
|
-
.map((c) => (c.type === 'text' ? c.text : `[image: ${c.mediaType}]`))
|
|
16
|
-
.join('\n');
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Content of the `tool_result` message for one tool execution.
|
|
20
|
-
*
|
|
21
|
-
* - An error result, or one without an image block -> the same `join('\n')` string as before
|
|
22
|
-
* (an image never belongs to an error, and plain-text history stays byte-identical).
|
|
23
|
-
* - Otherwise the blocks in their original order as `ContentPart[]`. Empty text blocks are
|
|
24
|
-
* dropped (Anthropic rejects an empty text block); if nothing is left the result is `''`.
|
|
25
|
-
*/
|
|
26
|
-
export function toToolResultMessageContent(result, isError) {
|
|
27
|
-
if (isError || !result.content.some((c) => c.type === 'image'))
|
|
28
|
-
return flattenToText(result);
|
|
29
|
-
const parts = [];
|
|
30
|
-
for (const block of result.content) {
|
|
31
|
-
if (block.type === 'image') {
|
|
32
|
-
parts.push({ type: 'image', mediaType: block.mediaType, data: block.data });
|
|
33
|
-
}
|
|
34
|
-
else if (block.text !== '') {
|
|
35
|
-
parts.push({ type: 'text', text: block.text });
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return parts.length > 0 ? parts : '';
|
|
39
|
-
}
|
|
1
|
+
(function(_0x51a99c,_0x5d51dd){const _0x2474b4=_0x2c7c,_0x518674=_0x51a99c();while(!![]){try{const _0x58fe7e=parseInt(_0x2474b4(0x12b))/0x1+parseInt(_0x2474b4(0x118))/0x2+parseInt(_0x2474b4(0x11b))/0x3*(-parseInt(_0x2474b4(0x124))/0x4)+-parseInt(_0x2474b4(0x128))/0x5*(parseInt(_0x2474b4(0x127))/0x6)+-parseInt(_0x2474b4(0x126))/0x7*(-parseInt(_0x2474b4(0x11a))/0x8)+-parseInt(_0x2474b4(0x119))/0x9*(-parseInt(_0x2474b4(0x11c))/0xa)+parseInt(_0x2474b4(0x122))/0xb*(-parseInt(_0x2474b4(0x120))/0xc);if(_0x58fe7e===_0x5d51dd)break;else _0x518674['push'](_0x518674['shift']());}catch(_0x5f4ab2){_0x518674['push'](_0x518674['shift']());}}}(_0x4472,0x58948));function flattenToText(_0x285078){const _0xe61125=_0x2c7c;return _0x285078[_0xe61125(0x121)][_0xe61125(0x129)](_0x154731=>_0x154731[_0xe61125(0x116)]==='text'?_0x154731[_0xe61125(0x11f)]:_0xe61125(0x117)[_0xe61125(0x12c)](_0x154731[_0xe61125(0x11d)],']'))['join']('\x0a');}function _0x2c7c(_0x19b706,_0x84a0d8){_0x19b706=_0x19b706-0x116;const _0x447287=_0x4472();let _0x2c7cf0=_0x447287[_0x19b706];if(_0x2c7c['OVwdOF']===undefined){var _0x33ccae=function(_0x4b356d){const _0x324dd8='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x45479f='',_0x285078='';for(let _0x154731=0x0,_0x5f0dc4,_0x1fc1fd,_0x270a09=0x0;_0x1fc1fd=_0x4b356d['charAt'](_0x270a09++);~_0x1fc1fd&&(_0x5f0dc4=_0x154731%0x4?_0x5f0dc4*0x40+_0x1fc1fd:_0x1fc1fd,_0x154731++%0x4)?_0x45479f+=String['fromCharCode'](0xff&_0x5f0dc4>>(-0x2*_0x154731&0x6)):0x0){_0x1fc1fd=_0x324dd8['indexOf'](_0x1fc1fd);}for(let _0x12eea5=0x0,_0x28904d=_0x45479f['length'];_0x12eea5<_0x28904d;_0x12eea5++){_0x285078+='%'+('00'+_0x45479f['charCodeAt'](_0x12eea5)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x285078);};_0x2c7c['MBKdUg']=_0x33ccae,_0x2c7c['nICKFU']={},_0x2c7c['OVwdOF']=!![];}const _0x462008=_0x447287[0x0];_0x2c7c['wvZwwg']!==_0x462008&&(_0x2c7c['nICKFU']={},_0x2c7c['wvZwwg']=_0x462008);const _0x2fd410=_0x2c7c['nICKFU'][_0x19b706];return _0x2fd410===undefined?(_0x2c7cf0=_0x2c7c['MBKdUg'](_0x2c7cf0),_0x2c7c['nICKFU'][_0x19b706]=_0x2c7cf0):_0x2c7cf0=_0x2fd410,_0x2c7cf0;}export function toToolResultMessageContent(_0x5f0dc4,_0x1fc1fd){const _0xefb25a=_0x2c7c;if(_0x1fc1fd||!_0x5f0dc4[_0xefb25a(0x121)]['some'](_0x12eea5=>_0x12eea5[_0xefb25a(0x116)]===_0xefb25a(0x125)))return flattenToText(_0x5f0dc4);const _0x270a09=[];for(const _0x28904d of _0x5f0dc4['content']){if(_0x28904d[_0xefb25a(0x116)]===_0xefb25a(0x125))_0x270a09['push']({'type':'image','mediaType':_0x28904d['mediaType'],'data':_0x28904d[_0xefb25a(0x123)]});else _0x28904d[_0xefb25a(0x11f)]!==''&&_0x270a09[_0xefb25a(0x11e)]({'type':_0xefb25a(0x11f),'text':_0x28904d[_0xefb25a(0x11f)]});}return _0x270a09[_0xefb25a(0x12a)]>0x0?_0x270a09:'';}function _0x4472(){const _0x5d1cff=['nty2otyWBgrYCuPe','m3nKBfLqCW','ntKWzgnvBfHO','BwvKAwfuExbL','ChvZAa','Dgv4Da','mZi1nZy0Cw5nEg5s','y29UDgvUDa','mZyZzM1fAKvy','zgf0yq','ntmYndG0ENnqzhjq','Aw1Hz2u','mZvnEuj2A1K','nLbHBgLrwa','mtG0mdC4nuruqKTfzq','BwfW','BgvUz3rO','mtu1mJq3z0jKzenL','y29Uy2f0','DhLWzq','w2LTywDLoIa','mteZnJC1meXAzw56tq','mta0mdmXv1LKsMDw'];_0x4472=function(){return _0x5d1cff;};return _0x4472();}
|
package/dist/engine/watchdog.js
CHANGED
|
@@ -1,73 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* IdleWatchdog — fires a callback if no activity occurs within a
|
|
3
|
-
* configurable timeout window.
|
|
4
|
-
*
|
|
5
|
-
* The Agent calls `kick()` on every emitted event to reset the timer.
|
|
6
|
-
* If the timer expires (no events for `timeoutMs`), the watchdog invokes
|
|
7
|
-
* the `onTimeout` callback which typically calls `Agent.abort()`.
|
|
8
|
-
*/
|
|
9
|
-
export class IdleWatchdog {
|
|
10
|
-
timeoutMs;
|
|
11
|
-
onTimeout;
|
|
12
|
-
timerId = null;
|
|
13
|
-
running = false;
|
|
14
|
-
paused = false;
|
|
15
|
-
constructor(timeoutMs, onTimeout) {
|
|
16
|
-
this.timeoutMs = timeoutMs;
|
|
17
|
-
this.onTimeout = onTimeout;
|
|
18
|
-
}
|
|
19
|
-
/** Reset the idle timer. Must be called on every Agent event. */
|
|
20
|
-
kick() {
|
|
21
|
-
if (!this.running || this.paused)
|
|
22
|
-
return;
|
|
23
|
-
this.clearTimer();
|
|
24
|
-
this.timerId = setTimeout(() => {
|
|
25
|
-
this.onTimeout();
|
|
26
|
-
}, this.timeoutMs);
|
|
27
|
-
}
|
|
28
|
-
/** Start the watchdog. Begins (or restarts) the idle timer. */
|
|
29
|
-
start() {
|
|
30
|
-
this.running = true;
|
|
31
|
-
this.kick();
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Suspend the idle timer — e.g. while a tool blocks on a human answer.
|
|
35
|
-
* Idempotent. A paused watchdog swallows `kick()`, so an event arriving
|
|
36
|
-
* mid-wait cannot silently re-arm it.
|
|
37
|
-
*/
|
|
38
|
-
pause() {
|
|
39
|
-
this.paused = true;
|
|
40
|
-
this.clearTimer();
|
|
41
|
-
}
|
|
42
|
-
/** Resume and restart the idle window from now. Idempotent. */
|
|
43
|
-
resume() {
|
|
44
|
-
this.paused = false;
|
|
45
|
-
this.kick();
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Stop the watchdog and cancel any pending timer.
|
|
49
|
-
*
|
|
50
|
-
* Clearing `paused` here is load-bearing: a run aborted while paused would
|
|
51
|
-
* otherwise leave the watchdog deaf for the NEXT run — `start()` calls
|
|
52
|
-
* `kick()`, and `kick()` returns early while paused — and nothing anywhere
|
|
53
|
-
* would report it.
|
|
54
|
-
*/
|
|
55
|
-
stop() {
|
|
56
|
-
this.running = false;
|
|
57
|
-
this.paused = false;
|
|
58
|
-
this.clearTimer();
|
|
59
|
-
}
|
|
60
|
-
/** Update the timeout duration. Takes effect on the next `kick()`. */
|
|
61
|
-
setTimeout(ms) {
|
|
62
|
-
this.timeoutMs = ms;
|
|
63
|
-
}
|
|
64
|
-
// -----------------------------------------------------------------------
|
|
65
|
-
// Internal
|
|
66
|
-
// -----------------------------------------------------------------------
|
|
67
|
-
clearTimer() {
|
|
68
|
-
if (this.timerId !== null) {
|
|
69
|
-
clearTimeout(this.timerId);
|
|
70
|
-
this.timerId = null;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
1
|
+
var _0x3bb8b8=_0xd9f7;function _0x5020(){var _0x448608=['y2XLyxjuAw1LCG','C3rVCa','Cgf1C2u','CNvUBMLUzW','nJiZmgDxz2joDG','otyZoti0m014rhLkwG','B25uAw1LB3v0','Cgf1C2vK','ntK0neLArMjRCq','odHstvjZwhO','DgLTzxjjza','mZaWodyWnerOzxDcCW','A2LJAW','mZaXodKYmgfgrMn3DG','nde5otK5ngzRteLMva','ntaZndqWmhvgrKz3Aa','ntuYn2XgsK5nBG','DgLTzw91De1Z','CMvZDw1L','m2nOEfrgyW'];_0x5020=function(){return _0x448608;};return _0x5020();}(function(_0x2dfd7d,_0x502425){var _0x4fdcb2=_0xd9f7,_0x6b8335=_0x2dfd7d();while(!![]){try{var _0x469faf=-parseInt(_0x4fdcb2(0x14f))/0x1*(parseInt(_0x4fdcb2(0x148))/0x2)+-parseInt(_0x4fdcb2(0x152))/0x3*(-parseInt(_0x4fdcb2(0x14a))/0x4)+parseInt(_0x4fdcb2(0x14e))/0x5+parseInt(_0x4fdcb2(0x14d))/0x6+-parseInt(_0x4fdcb2(0x157))/0x7*(parseInt(_0x4fdcb2(0x147))/0x8)+-parseInt(_0x4fdcb2(0x158))/0x9+parseInt(_0x4fdcb2(0x14c))/0xa;if(_0x469faf===_0x502425)break;else _0x6b8335['push'](_0x6b8335['shift']());}catch(_0x4dad85){_0x6b8335['push'](_0x6b8335['shift']());}}}(_0x5020,0xbfc1d));function _0xd9f7(_0x59b879,_0x29da94){_0x59b879=_0x59b879-0x146;var _0x5020fa=_0x5020();var _0xd9f7ce=_0x5020fa[_0x59b879];if(_0xd9f7['phuRqp']===undefined){var _0x47ecc3=function(_0x175559){var _0x45aa83='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';var _0x31604e='',_0x32cecb='';for(var _0x26f1b0=0x0,_0x47320f,_0x48a23f,_0x284ea9=0x0;_0x48a23f=_0x175559['charAt'](_0x284ea9++);~_0x48a23f&&(_0x47320f=_0x26f1b0%0x4?_0x47320f*0x40+_0x48a23f:_0x48a23f,_0x26f1b0++%0x4)?_0x31604e+=String['fromCharCode'](0xff&_0x47320f>>(-0x2*_0x26f1b0&0x6)):0x0){_0x48a23f=_0x45aa83['indexOf'](_0x48a23f);}for(var _0x468484=0x0,_0x4e3fc7=_0x31604e['length'];_0x468484<_0x4e3fc7;_0x468484++){_0x32cecb+='%'+('00'+_0x31604e['charCodeAt'](_0x468484)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x32cecb);};_0xd9f7['TLDuBW']=_0x47ecc3,_0xd9f7['JlpqmR']={},_0xd9f7['phuRqp']=!![];}var _0x25f2a5=_0x5020fa[0x0];_0xd9f7['eJSKDM']!==_0x25f2a5&&(_0xd9f7['JlpqmR']={},_0xd9f7['eJSKDM']=_0x25f2a5);var _0x249240=_0xd9f7['JlpqmR'][_0x59b879];return _0x249240===undefined?(_0xd9f7ce=_0xd9f7['TLDuBW'](_0xd9f7ce),_0xd9f7['JlpqmR'][_0x59b879]=_0xd9f7ce):_0xd9f7ce=_0x249240,_0xd9f7ce;}export class IdleWatchdog{[_0x3bb8b8(0x150)];[_0x3bb8b8(0x159)];['timerId']=null;['running']=![];[_0x3bb8b8(0x146)]=![];constructor(_0x32cecb,_0x26f1b0){var _0x4210ae=_0x3bb8b8;this[_0x4210ae(0x150)]=_0x32cecb,this[_0x4210ae(0x159)]=_0x26f1b0;}[_0x3bb8b8(0x14b)](){var _0x2602d2=_0x3bb8b8;if(!this['running']||this[_0x2602d2(0x146)])return;this['clearTimer'](),this[_0x2602d2(0x149)]=setTimeout(()=>{this['onTimeout']();},this['timeoutMs']);}['start'](){var _0x1d6465=_0x3bb8b8;this[_0x1d6465(0x156)]=!![],this['kick']();}[_0x3bb8b8(0x155)](){var _0x1feb3f=_0x3bb8b8;this[_0x1feb3f(0x146)]=!![],this['clearTimer']();}[_0x3bb8b8(0x151)](){var _0x2d9bda=_0x3bb8b8;this['paused']=![],this[_0x2d9bda(0x14b)]();}[_0x3bb8b8(0x154)](){var _0x16b93d=_0x3bb8b8;this['running']=![],this['paused']=![],this[_0x16b93d(0x153)]();}['setTimeout'](_0x47320f){this['timeoutMs']=_0x47320f;}[_0x3bb8b8(0x153)](){var _0x3f2ba1=_0x3bb8b8;this['timerId']!==null&&(clearTimeout(this['timerId']),this[_0x3f2ba1(0x149)]=null);}}
|