@animalabs/agent-framework 0.19.0 → 0.21.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 +29 -0
- package/dist/src/agent.d.ts +22 -0
- package/dist/src/agent.d.ts.map +1 -1
- package/dist/src/agent.js +128 -10
- package/dist/src/agent.js.map +1 -1
- package/dist/src/api/types.d.ts +1 -1
- package/dist/src/api/types.d.ts.map +1 -1
- package/dist/src/code-execution/py-runner.d.ts +10 -1
- package/dist/src/code-execution/py-runner.d.ts.map +1 -1
- package/dist/src/code-execution/py-runner.js +27 -2
- package/dist/src/code-execution/py-runner.js.map +1 -1
- package/dist/src/code-execution/tool-definition.d.ts +21 -0
- package/dist/src/code-execution/tool-definition.d.ts.map +1 -1
- package/dist/src/code-execution/tool-definition.js +34 -0
- package/dist/src/code-execution/tool-definition.js.map +1 -1
- package/dist/src/framework.d.ts +153 -2
- package/dist/src/framework.d.ts.map +1 -1
- package/dist/src/framework.js +1175 -76
- package/dist/src/framework.js.map +1 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcpl/capability-grant.d.ts +1 -1
- package/dist/src/mcpl/capability-grant.d.ts.map +1 -1
- package/dist/src/mcpl/capability-grant.js +49 -5
- package/dist/src/mcpl/capability-grant.js.map +1 -1
- package/dist/src/mcpl/channel-registry.d.ts +59 -2
- package/dist/src/mcpl/channel-registry.d.ts.map +1 -1
- package/dist/src/mcpl/channel-registry.js +106 -6
- package/dist/src/mcpl/channel-registry.js.map +1 -1
- package/dist/src/mcpl/conversation-router.d.ts +8 -6
- package/dist/src/mcpl/conversation-router.d.ts.map +1 -1
- package/dist/src/mcpl/conversation-router.js +12 -6
- package/dist/src/mcpl/conversation-router.js.map +1 -1
- package/dist/src/mcpl/index.d.ts +3 -0
- package/dist/src/mcpl/index.d.ts.map +1 -1
- package/dist/src/mcpl/index.js +3 -0
- package/dist/src/mcpl/index.js.map +1 -1
- package/dist/src/mcpl/push-coalescer.d.ts +318 -0
- package/dist/src/mcpl/push-coalescer.d.ts.map +1 -0
- package/dist/src/mcpl/push-coalescer.js +709 -0
- package/dist/src/mcpl/push-coalescer.js.map +1 -0
- package/dist/src/mcpl/push-handler.d.ts +7 -2
- package/dist/src/mcpl/push-handler.d.ts.map +1 -1
- package/dist/src/mcpl/push-handler.js +43 -4
- package/dist/src/mcpl/push-handler.js.map +1 -1
- package/dist/src/mcpl/references.d.ts.map +1 -1
- package/dist/src/mcpl/references.js +9 -4
- package/dist/src/mcpl/references.js.map +1 -1
- package/dist/src/mcpl/server-connection.d.ts +18 -0
- package/dist/src/mcpl/server-connection.d.ts.map +1 -1
- package/dist/src/mcpl/server-connection.js +44 -1
- package/dist/src/mcpl/server-connection.js.map +1 -1
- package/dist/src/mcpl/tool-classes.d.ts +71 -0
- package/dist/src/mcpl/tool-classes.d.ts.map +1 -0
- package/dist/src/mcpl/tool-classes.js +170 -0
- package/dist/src/mcpl/tool-classes.js.map +1 -0
- package/dist/src/mcpl/tool-glob.d.ts +16 -0
- package/dist/src/mcpl/tool-glob.d.ts.map +1 -0
- package/dist/src/mcpl/tool-glob.js +41 -0
- package/dist/src/mcpl/tool-glob.js.map +1 -0
- package/dist/src/mcpl/tool-lifecycle.d.ts +253 -0
- package/dist/src/mcpl/tool-lifecycle.d.ts.map +1 -0
- package/dist/src/mcpl/tool-lifecycle.js +607 -0
- package/dist/src/mcpl/tool-lifecycle.js.map +1 -0
- package/dist/src/mcpl/transport.d.ts +15 -0
- package/dist/src/mcpl/transport.d.ts.map +1 -1
- package/dist/src/mcpl/transport.js +65 -1
- package/dist/src/mcpl/transport.js.map +1 -1
- package/dist/src/mcpl/types.d.ts +68 -1
- package/dist/src/mcpl/types.d.ts.map +1 -1
- package/dist/src/mcpl/types.js +6 -0
- package/dist/src/mcpl/types.js.map +1 -1
- package/dist/src/modules/discord/index.js +1 -1
- package/dist/src/modules/discord/index.js.map +1 -1
- package/dist/src/modules/history/index.d.ts +85 -0
- package/dist/src/modules/history/index.d.ts.map +1 -1
- package/dist/src/modules/history/index.js +1019 -24
- package/dist/src/modules/history/index.js.map +1 -1
- package/dist/src/modules/history/semantic.d.ts +202 -0
- package/dist/src/modules/history/semantic.d.ts.map +1 -0
- package/dist/src/modules/history/semantic.js +418 -0
- package/dist/src/modules/history/semantic.js.map +1 -0
- package/dist/src/modules/index.d.ts +2 -1
- package/dist/src/modules/index.d.ts.map +1 -1
- package/dist/src/modules/index.js.map +1 -1
- package/dist/src/tool-result-guard.d.ts +82 -0
- package/dist/src/tool-result-guard.d.ts.map +1 -0
- package/dist/src/tool-result-guard.js +306 -0
- package/dist/src/tool-result-guard.js.map +1 -0
- package/dist/src/types/agent.d.ts +14 -0
- package/dist/src/types/agent.d.ts.map +1 -1
- package/dist/src/types/framework.d.ts +21 -0
- package/dist/src/types/framework.d.ts.map +1 -1
- package/dist/src/types/trace.d.ts +17 -0
- package/dist/src/types/trace.d.ts.map +1 -1
- package/dist/test/channel-registry-routing.test.js +59 -0
- package/dist/test/channel-registry-routing.test.js.map +1 -1
- package/dist/test/code-execution.test.js +139 -0
- package/dist/test/code-execution.test.js.map +1 -1
- package/dist/test/conversation-router.test.js +33 -19
- package/dist/test/conversation-router.test.js.map +1 -1
- package/dist/test/conversation-routing.test.js +89 -0
- package/dist/test/conversation-routing.test.js.map +1 -1
- package/dist/test/helpers/coalescing-fixture.d.ts +72 -0
- package/dist/test/helpers/coalescing-fixture.d.ts.map +1 -0
- package/dist/test/helpers/coalescing-fixture.js +145 -0
- package/dist/test/helpers/coalescing-fixture.js.map +1 -0
- package/dist/test/helpers/coalescing-kill-child.d.ts +2 -0
- package/dist/test/helpers/coalescing-kill-child.d.ts.map +1 -0
- package/dist/test/helpers/coalescing-kill-child.js +24 -0
- package/dist/test/helpers/coalescing-kill-child.js.map +1 -0
- package/dist/test/history-module-realstore.test.d.ts +2 -0
- package/dist/test/history-module-realstore.test.d.ts.map +1 -0
- package/dist/test/history-module-realstore.test.js +363 -0
- package/dist/test/history-module-realstore.test.js.map +1 -0
- package/dist/test/history-module-semantic.test.d.ts +2 -0
- package/dist/test/history-module-semantic.test.d.ts.map +1 -0
- package/dist/test/history-module-semantic.test.js +213 -0
- package/dist/test/history-module-semantic.test.js.map +1 -0
- package/dist/test/history-module-ux.test.d.ts +2 -0
- package/dist/test/history-module-ux.test.d.ts.map +1 -0
- package/dist/test/history-module-ux.test.js +304 -0
- package/dist/test/history-module-ux.test.js.map +1 -0
- package/dist/test/history-module.test.js +25 -1
- package/dist/test/history-module.test.js.map +1 -1
- package/dist/test/history-semantic-review-findings.test.d.ts +2 -0
- package/dist/test/history-semantic-review-findings.test.d.ts.map +1 -0
- package/dist/test/history-semantic-review-findings.test.js +338 -0
- package/dist/test/history-semantic-review-findings.test.js.map +1 -0
- package/dist/test/history-semantic-sync-converges.test.d.ts +2 -0
- package/dist/test/history-semantic-sync-converges.test.d.ts.map +1 -0
- package/dist/test/history-semantic-sync-converges.test.js +109 -0
- package/dist/test/history-semantic-sync-converges.test.js.map +1 -0
- package/dist/test/mcpl-capability-grant.test.js +3 -1
- package/dist/test/mcpl-capability-grant.test.js.map +1 -1
- package/dist/test/mcpl-child-env.test.d.ts +2 -0
- package/dist/test/mcpl-child-env.test.d.ts.map +1 -0
- package/dist/test/mcpl-child-env.test.js +158 -0
- package/dist/test/mcpl-child-env.test.js.map +1 -0
- package/dist/test/mcpl-coalescing.test.d.ts +2 -0
- package/dist/test/mcpl-coalescing.test.d.ts.map +1 -0
- package/dist/test/mcpl-coalescing.test.js +1050 -0
- package/dist/test/mcpl-coalescing.test.js.map +1 -0
- package/dist/test/mcpl-list-status.test.js +4 -0
- package/dist/test/mcpl-list-status.test.js.map +1 -1
- package/dist/test/mcpl-reference-fields.test.d.ts +2 -0
- package/dist/test/mcpl-reference-fields.test.d.ts.map +1 -0
- package/dist/test/mcpl-reference-fields.test.js +82 -0
- package/dist/test/mcpl-reference-fields.test.js.map +1 -0
- package/dist/test/mcpl-tool-class-listing.test.d.ts +2 -0
- package/dist/test/mcpl-tool-class-listing.test.d.ts.map +1 -0
- package/dist/test/mcpl-tool-class-listing.test.js +147 -0
- package/dist/test/mcpl-tool-class-listing.test.js.map +1 -0
- package/dist/test/mcpl-tool-classes.test.d.ts +7 -0
- package/dist/test/mcpl-tool-classes.test.d.ts.map +1 -0
- package/dist/test/mcpl-tool-classes.test.js +80 -0
- package/dist/test/mcpl-tool-classes.test.js.map +1 -0
- package/dist/test/mcpl-tool-lifecycle-e2e.test.d.ts +2 -0
- package/dist/test/mcpl-tool-lifecycle-e2e.test.d.ts.map +1 -0
- package/dist/test/mcpl-tool-lifecycle-e2e.test.js +237 -0
- package/dist/test/mcpl-tool-lifecycle-e2e.test.js.map +1 -0
- package/dist/test/mcpl-tool-lifecycle-emitter.test.d.ts +11 -0
- package/dist/test/mcpl-tool-lifecycle-emitter.test.d.ts.map +1 -0
- package/dist/test/mcpl-tool-lifecycle-emitter.test.js +307 -0
- package/dist/test/mcpl-tool-lifecycle-emitter.test.js.map +1 -0
- package/dist/test/mcpl-tool-lifecycle.test.d.ts +11 -0
- package/dist/test/mcpl-tool-lifecycle.test.d.ts.map +1 -0
- package/dist/test/mcpl-tool-lifecycle.test.js +270 -0
- package/dist/test/mcpl-tool-lifecycle.test.js.map +1 -0
- package/dist/test/silent-heartbeat.test.d.ts +2 -0
- package/dist/test/silent-heartbeat.test.d.ts.map +1 -0
- package/dist/test/silent-heartbeat.test.js +154 -0
- package/dist/test/silent-heartbeat.test.js.map +1 -0
- package/dist/test/tool-result-guard.test.d.ts +2 -0
- package/dist/test/tool-result-guard.test.d.ts.map +1 -0
- package/dist/test/tool-result-guard.test.js +1081 -0
- package/dist/test/tool-result-guard.test.js.map +1 -0
- package/dist/test/tools-observe-parser-conformance.test.d.ts +2 -0
- package/dist/test/tools-observe-parser-conformance.test.d.ts.map +1 -0
- package/dist/test/tools-observe-parser-conformance.test.js +129 -0
- package/dist/test/tools-observe-parser-conformance.test.js.map +1 -0
- package/dist/test/trunk-channel-routing.test.js +67 -0
- package/dist/test/trunk-channel-routing.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/agent.ts +128 -10
- package/src/api/types.ts +2 -0
- package/src/code-execution/py-runner.ts +34 -2
- package/src/code-execution/tool-definition.ts +46 -0
- package/src/framework.ts +1207 -80
- package/src/index.ts +13 -0
- package/src/mcpl/capability-grant.ts +54 -6
- package/src/mcpl/channel-registry.ts +115 -7
- package/src/mcpl/conversation-router.ts +12 -8
- package/src/mcpl/index.ts +29 -0
- package/src/mcpl/push-coalescer.ts +821 -0
- package/src/mcpl/push-handler.ts +40 -4
- package/src/mcpl/references.ts +11 -3
- package/src/mcpl/server-connection.ts +48 -2
- package/src/mcpl/tool-classes.ts +188 -0
- package/src/mcpl/tool-glob.ts +36 -0
- package/src/mcpl/tool-lifecycle.ts +745 -0
- package/src/mcpl/transport.ts +67 -1
- package/src/mcpl/types.ts +71 -1
- package/src/modules/discord/index.ts +1 -1
- package/src/modules/history/index.ts +1089 -24
- package/src/modules/history/semantic.ts +473 -0
- package/src/modules/index.ts +2 -1
- package/src/tool-result-guard.ts +318 -0
- package/src/types/agent.ts +15 -0
- package/src/types/framework.ts +23 -0
- package/src/types/trace.ts +17 -0
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semantic (embedding) search for HistoryModule, backed by a shared remote
|
|
3
|
+
* embed-service (one per fleet; the index lives server-side, keyed by a
|
|
4
|
+
* per-store namespace).
|
|
5
|
+
*
|
|
6
|
+
* Two pieces:
|
|
7
|
+
* - `SemanticIndexClient` — thin HTTP client for the service's index API
|
|
8
|
+
* (`/v1/index/{ns}/upsert|search|stats`).
|
|
9
|
+
* - `SemanticIndexer` — incremental sync from the resident's chronicle into
|
|
10
|
+
* that namespace. Messages are watermarked by TIMESTAMP (chronicle's native
|
|
11
|
+
* time index is the only cheap "what's new" query), with a re-scan overlap
|
|
12
|
+
* so a message stamped slightly out of order is still picked up; the
|
|
13
|
+
* service dedups by id + text hash, so re-sending is free. Summaries are
|
|
14
|
+
* watermarked by `createdMs` (a fresh L3 spans months of old timestamps —
|
|
15
|
+
* its creation time is the only monotonic signal).
|
|
16
|
+
*
|
|
17
|
+
* What gets embedded per message: text blocks verbatim, plus the string
|
|
18
|
+
* arguments of the agent's private-prose tools (think / journal / skip_reply
|
|
19
|
+
* / private_note) labelled `[think] …` — that is the resident's own diary and
|
|
20
|
+
* is exactly what "what did I think about X" should find. tool_result
|
|
21
|
+
* payloads, other tool arguments, thinking blocks and media are skipped.
|
|
22
|
+
*
|
|
23
|
+
* Failure posture: the service being down never breaks the module. Sync ticks
|
|
24
|
+
* log and back off; `semantic_search` returns a clean tool error.
|
|
25
|
+
*/
|
|
26
|
+
const PRIVATE_PROSE_TOOLS = new Set(['think', 'journal', 'skip_reply', 'private_note']);
|
|
27
|
+
export class SemanticIndexClient {
|
|
28
|
+
cfg;
|
|
29
|
+
base;
|
|
30
|
+
ns;
|
|
31
|
+
timeoutMs;
|
|
32
|
+
constructor(cfg) {
|
|
33
|
+
this.cfg = cfg;
|
|
34
|
+
this.base = cfg.url.replace(/\/+$/, '');
|
|
35
|
+
this.ns = encodeURIComponent(cfg.namespace);
|
|
36
|
+
this.timeoutMs = cfg.requestTimeoutMs ?? 30_000;
|
|
37
|
+
}
|
|
38
|
+
async call(method, path, body) {
|
|
39
|
+
const headers = { 'content-type': 'application/json' };
|
|
40
|
+
if (this.cfg.token)
|
|
41
|
+
headers.authorization = `Bearer ${this.cfg.token}`;
|
|
42
|
+
const ctrl = new AbortController();
|
|
43
|
+
const timer = setTimeout(() => ctrl.abort(), this.timeoutMs);
|
|
44
|
+
try {
|
|
45
|
+
const res = await fetch(`${this.base}${path}`, {
|
|
46
|
+
method, headers, body: body === undefined ? undefined : JSON.stringify(body), signal: ctrl.signal,
|
|
47
|
+
});
|
|
48
|
+
const text = await res.text();
|
|
49
|
+
let json;
|
|
50
|
+
try {
|
|
51
|
+
json = JSON.parse(text);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
json = undefined;
|
|
55
|
+
}
|
|
56
|
+
if (!res.ok) {
|
|
57
|
+
const msg = json?.error?.message ?? text.slice(0, 200);
|
|
58
|
+
throw new Error(`embed-service ${method} ${path} → ${res.status}: ${msg}`);
|
|
59
|
+
}
|
|
60
|
+
return json;
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
clearTimeout(timer);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** Stats for this namespace; `null` when the namespace does not exist yet. */
|
|
67
|
+
async stats() {
|
|
68
|
+
try {
|
|
69
|
+
return await this.call('GET', `/v1/index/${this.ns}/stats`);
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
if (e instanceof Error && /→ 404/.test(e.message))
|
|
73
|
+
return null;
|
|
74
|
+
throw e;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async upsert(items) {
|
|
78
|
+
return this.call('POST', `/v1/index/${this.ns}/upsert`, { items });
|
|
79
|
+
}
|
|
80
|
+
async delete(ids) {
|
|
81
|
+
return this.call('POST', `/v1/index/${this.ns}/delete`, { ids });
|
|
82
|
+
}
|
|
83
|
+
async search(req) {
|
|
84
|
+
return this.call('POST', `/v1/index/${this.ns}/search`, req);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** Text to embed for one message, or '' when there is nothing worth indexing. */
|
|
88
|
+
export function messageIndexText(msg, includePrivateTools = true) {
|
|
89
|
+
const parts = [];
|
|
90
|
+
for (const block of msg.content) {
|
|
91
|
+
if (block.type === 'text' && typeof block.text === 'string') {
|
|
92
|
+
parts.push(block.text);
|
|
93
|
+
}
|
|
94
|
+
else if (includePrivateTools && block.type === 'tool_use' && PRIVATE_PROSE_TOOLS.has(block.name)) {
|
|
95
|
+
const input = block.input ?? {};
|
|
96
|
+
for (const v of Object.values(input)) {
|
|
97
|
+
if (typeof v === 'string' && v.trim().length > 0)
|
|
98
|
+
parts.push(`[${block.name}] ${v}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return parts.join('\n').trim();
|
|
103
|
+
}
|
|
104
|
+
/** Same two metadata shapes HistoryModule's getChannelId reads: MCPL ingestion writes `metadata.channelId`, older paths `metadata.external.channelId`. */
|
|
105
|
+
function channelOf(msg) {
|
|
106
|
+
const md = msg.metadata;
|
|
107
|
+
if (typeof md?.channelId === 'string')
|
|
108
|
+
return md.channelId;
|
|
109
|
+
return typeof md?.external?.channelId === 'string' ? md.external.channelId : null;
|
|
110
|
+
}
|
|
111
|
+
function authorOf(msg) {
|
|
112
|
+
const md = msg.metadata;
|
|
113
|
+
const a = md?.external?.authorName ?? md?.authorName;
|
|
114
|
+
return typeof a === 'string' ? a : null;
|
|
115
|
+
}
|
|
116
|
+
export function messageToItem(msg, cfg) {
|
|
117
|
+
const text = messageIndexText(msg, cfg.includePrivateTools ?? true);
|
|
118
|
+
if (!text)
|
|
119
|
+
return null;
|
|
120
|
+
const tsMs = msg.timestamp.getTime();
|
|
121
|
+
return {
|
|
122
|
+
id: `msg:${String(msg.id)}`,
|
|
123
|
+
text: text.slice(0, cfg.maxChars ?? 32_000),
|
|
124
|
+
ts: tsMs / 1000,
|
|
125
|
+
channel: channelOf(msg),
|
|
126
|
+
kind: 'message',
|
|
127
|
+
cursor: tsMs,
|
|
128
|
+
meta: { participant: msg.participant, author: authorOf(msg), seq: msg.sequence },
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
export function summaryToItem(s, cfg) {
|
|
132
|
+
const text = s.content.trim();
|
|
133
|
+
if (!text)
|
|
134
|
+
return null;
|
|
135
|
+
return {
|
|
136
|
+
id: `sum:${s.id}`,
|
|
137
|
+
text: text.slice(0, cfg.maxChars ?? 32_000),
|
|
138
|
+
ts: s.startMs / 1000,
|
|
139
|
+
kind: 'summary',
|
|
140
|
+
level: s.level,
|
|
141
|
+
cursor: s.createdMs,
|
|
142
|
+
meta: { endTs: s.endMs / 1000, firstSequence: s.firstSequence, lastSequence: s.lastSequence, tokens: s.tokens, parentId: s.parentId ?? null },
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
export class SemanticIndexer {
|
|
146
|
+
cm;
|
|
147
|
+
client;
|
|
148
|
+
cfg;
|
|
149
|
+
log;
|
|
150
|
+
inFlight = null;
|
|
151
|
+
consecutiveFailures = 0;
|
|
152
|
+
backoffUntil = 0;
|
|
153
|
+
lastError = null;
|
|
154
|
+
lastSyncAt = null;
|
|
155
|
+
constructor(cm, client, cfg, log = () => { }) {
|
|
156
|
+
this.cm = cm;
|
|
157
|
+
this.client = client;
|
|
158
|
+
this.cfg = cfg;
|
|
159
|
+
this.log = log;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Edits and removals since the last successful sync. The time-cursor walk
|
|
163
|
+
* only revisits the overlap window, so an edit to an older message (its
|
|
164
|
+
* timestamp does not change) or a removal would otherwise never reach the
|
|
165
|
+
* index. The host persists the pending sets through `onPendingChange` /
|
|
166
|
+
* `restorePending` (HistoryModule keeps them in module state), so edits
|
|
167
|
+
* made during an embed-service outage survive a restart. Events that land
|
|
168
|
+
* while the module is detached are not replayed (removals are still hidden
|
|
169
|
+
* at search time by the current-branch check in HistoryModule).
|
|
170
|
+
*/
|
|
171
|
+
editedIds = new Set();
|
|
172
|
+
removedIds = new Set();
|
|
173
|
+
detach = null;
|
|
174
|
+
/** Set once the service answers 404 to /delete (a build without the route): removals are dropped from then on. */
|
|
175
|
+
deleteUnsupported = false;
|
|
176
|
+
/** Called whenever the pending edit/remove sets change. */
|
|
177
|
+
onPendingChange = null;
|
|
178
|
+
pendingSnapshot() { return { edited: [...this.editedIds], removed: [...this.removedIds] }; }
|
|
179
|
+
restorePending(p) {
|
|
180
|
+
for (const id of p?.removed ?? []) {
|
|
181
|
+
this.removedIds.add(id);
|
|
182
|
+
this.editedIds.delete(id);
|
|
183
|
+
}
|
|
184
|
+
for (const id of p?.edited ?? [])
|
|
185
|
+
if (!this.removedIds.has(id))
|
|
186
|
+
this.editedIds.add(id);
|
|
187
|
+
}
|
|
188
|
+
pendingChanged() { this.onPendingChange?.(this.pendingSnapshot()); }
|
|
189
|
+
/** Subscribe to message-store edits/removals. Idempotent. */
|
|
190
|
+
attach() {
|
|
191
|
+
if (this.detach)
|
|
192
|
+
return;
|
|
193
|
+
const on = this.cm.onMessage;
|
|
194
|
+
if (typeof on !== 'function') {
|
|
195
|
+
this.log('[history/semantic] context-manager has no onMessage: edits and removals will not reach the index');
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
this.detach = on.call(this.cm, (e) => {
|
|
199
|
+
if (e.type === 'edit') {
|
|
200
|
+
this.editedIds.add(String(e.messageId));
|
|
201
|
+
this.pendingChanged();
|
|
202
|
+
}
|
|
203
|
+
else if (e.type === 'remove') {
|
|
204
|
+
const id = String(e.messageId);
|
|
205
|
+
this.editedIds.delete(id);
|
|
206
|
+
if (!this.deleteUnsupported)
|
|
207
|
+
this.removedIds.add(id);
|
|
208
|
+
this.pendingChanged();
|
|
209
|
+
}
|
|
210
|
+
// removeRange carries only its endpoints; removed ids in it are hidden at search time instead.
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
dispose() { this.detach?.(); this.detach = null; }
|
|
214
|
+
get backingOff() { return Date.now() < this.backoffUntil; }
|
|
215
|
+
/**
|
|
216
|
+
* Push what the index is missing, up to `maxItems`. Coalesces: a call while
|
|
217
|
+
* a sync is already running returns that run's promise instead of racing it.
|
|
218
|
+
*/
|
|
219
|
+
catchUp(maxItems) {
|
|
220
|
+
if (this.inFlight)
|
|
221
|
+
return this.inFlight;
|
|
222
|
+
const run = this.runCatchUp(maxItems).finally(() => { this.inFlight = null; });
|
|
223
|
+
this.inFlight = run;
|
|
224
|
+
return run;
|
|
225
|
+
}
|
|
226
|
+
async runCatchUp(maxItems) {
|
|
227
|
+
const report = { pushed: 0, inserted: 0, updated: 0, unchanged: 0, more: false, messagesScanned: 0, summariesScanned: 0 };
|
|
228
|
+
if (this.backingOff) {
|
|
229
|
+
report.more = true;
|
|
230
|
+
return report;
|
|
231
|
+
}
|
|
232
|
+
const batchSize = Math.min(256, Math.max(1, this.cfg.syncBatch ?? 128));
|
|
233
|
+
try {
|
|
234
|
+
const stats = await this.client.stats();
|
|
235
|
+
const msgWm = stats?.by_kind.message?.max_cursor ?? null;
|
|
236
|
+
const sumWm = stats?.by_kind.summary?.max_cursor ?? null;
|
|
237
|
+
let budget = maxItems;
|
|
238
|
+
let pending = [];
|
|
239
|
+
const flush = async () => {
|
|
240
|
+
if (pending.length === 0)
|
|
241
|
+
return;
|
|
242
|
+
const r = await this.client.upsert(pending);
|
|
243
|
+
report.pushed += pending.length;
|
|
244
|
+
report.inserted += r.inserted;
|
|
245
|
+
report.updated += r.updated;
|
|
246
|
+
report.unchanged += r.unchanged;
|
|
247
|
+
pending = [];
|
|
248
|
+
};
|
|
249
|
+
// Edits and removals first: they never come back round in the time walk.
|
|
250
|
+
// This phase fails on its own: a failure re-queues its ids, is logged
|
|
251
|
+
// and reported via lastError, and the tick falls through to summaries
|
|
252
|
+
// and the time walk, so one bad delete/upsert cannot freeze indexing.
|
|
253
|
+
let phaseError = null;
|
|
254
|
+
if (this.removedIds.size > 0 || this.editedIds.size > 0) {
|
|
255
|
+
const removed = [...this.removedIds];
|
|
256
|
+
// Edits spend the budget like any other upsert, so a large queue left
|
|
257
|
+
// by an outage cannot make a search's bounded catch-up unbounded; the
|
|
258
|
+
// rest stay queued for the next pass.
|
|
259
|
+
// Only actionable edits (an upsert or a delete) spend it: one whose
|
|
260
|
+
// message left the branch is dropped for free.
|
|
261
|
+
this.removedIds.clear();
|
|
262
|
+
const edited = [];
|
|
263
|
+
const toDelete = removed.map((id) => `msg:${id}`);
|
|
264
|
+
const blanked = [];
|
|
265
|
+
const toUpsert = [];
|
|
266
|
+
for (const id of [...this.editedIds]) {
|
|
267
|
+
if (budget <= 0)
|
|
268
|
+
break;
|
|
269
|
+
this.editedIds.delete(id);
|
|
270
|
+
const m = this.cm.getMessage(id);
|
|
271
|
+
// Not on the current branch (e.g. /undo after the edit): drop it,
|
|
272
|
+
// never delete — /redo brings the message back and the time walk
|
|
273
|
+
// will not revisit it. Search-time branch checks hide it meanwhile.
|
|
274
|
+
if (!m)
|
|
275
|
+
continue;
|
|
276
|
+
edited.push(id);
|
|
277
|
+
budget--;
|
|
278
|
+
const item = messageToItem(m, this.cfg);
|
|
279
|
+
// On the branch but edited down to nothing indexable: delete.
|
|
280
|
+
if (item)
|
|
281
|
+
toUpsert.push(item);
|
|
282
|
+
else {
|
|
283
|
+
toDelete.push(`msg:${id}`);
|
|
284
|
+
blanked.push(id);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (this.editedIds.size > 0)
|
|
288
|
+
report.more = true;
|
|
289
|
+
if (toDelete.length > 0) {
|
|
290
|
+
try {
|
|
291
|
+
await this.client.delete(toDelete);
|
|
292
|
+
}
|
|
293
|
+
catch (e) {
|
|
294
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
295
|
+
if (/→ 404/.test(msg)) {
|
|
296
|
+
// A service build without /delete (or a namespace that does
|
|
297
|
+
// not exist). Drop the removals and blanked edits: search-time
|
|
298
|
+
// checks (on-branch, still indexable) keep them out of results.
|
|
299
|
+
this.deleteUnsupported = true;
|
|
300
|
+
this.log(`[history/semantic] /delete unsupported by the embed-service; dropping ${toDelete.length} removal(s): ${msg}`);
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
for (const id of removed)
|
|
304
|
+
this.removedIds.add(id);
|
|
305
|
+
for (const id of blanked)
|
|
306
|
+
if (!this.removedIds.has(id))
|
|
307
|
+
this.editedIds.add(id);
|
|
308
|
+
phaseError = msg;
|
|
309
|
+
this.log(`[history/semantic] delete failed, ${removed.length} removal(s) re-queued: ${msg}`);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
try {
|
|
314
|
+
for (let i = 0; i < toUpsert.length; i += batchSize) {
|
|
315
|
+
const chunk = toUpsert.slice(i, i + batchSize);
|
|
316
|
+
const r = await this.client.upsert(chunk);
|
|
317
|
+
report.pushed += chunk.length;
|
|
318
|
+
report.inserted += r.inserted;
|
|
319
|
+
report.updated += r.updated;
|
|
320
|
+
report.unchanged += r.unchanged;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
catch (e) {
|
|
324
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
325
|
+
for (const id of edited)
|
|
326
|
+
if (!this.removedIds.has(id))
|
|
327
|
+
this.editedIds.add(id);
|
|
328
|
+
phaseError = msg;
|
|
329
|
+
this.log(`[history/semantic] edit re-upsert failed, ${edited.length} edit(s) re-queued: ${msg}`);
|
|
330
|
+
}
|
|
331
|
+
this.pendingChanged();
|
|
332
|
+
}
|
|
333
|
+
// Summaries before messages: they are few, and a message backlog that
|
|
334
|
+
// exceeds every tick's budget must not keep new summaries out forever.
|
|
335
|
+
{
|
|
336
|
+
const all = this.cm.getSummariesInRange({ fromMs: 0, toMs: Number.MAX_SAFE_INTEGER });
|
|
337
|
+
report.summariesScanned = all.length;
|
|
338
|
+
// `>=`: summaries sharing the watermark's millisecond may be only
|
|
339
|
+
// partly indexed (a bounded pass can stop inside a tie). Re-sending
|
|
340
|
+
// them is a dedup no-op for the service and costs no budget.
|
|
341
|
+
const fresh = all.filter((s) => sumWm === null || s.createdMs >= sumWm).sort((a, b) => a.createdMs - b.createdMs);
|
|
342
|
+
for (const s of fresh) {
|
|
343
|
+
if (budget <= 0) {
|
|
344
|
+
report.more = true;
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
const item = summaryToItem(s, this.cfg);
|
|
348
|
+
if (!item)
|
|
349
|
+
continue;
|
|
350
|
+
pending.push(item);
|
|
351
|
+
if (sumWm === null || s.createdMs > sumWm)
|
|
352
|
+
budget--;
|
|
353
|
+
if (pending.length >= batchSize)
|
|
354
|
+
await flush();
|
|
355
|
+
}
|
|
356
|
+
await flush();
|
|
357
|
+
}
|
|
358
|
+
// Messages: walk forward from (watermark - overlap) via the time index.
|
|
359
|
+
// Sound because rows are stamped at append time (CM addMessage takes no
|
|
360
|
+
// timestamp). An importer that writes historical stamps into a live
|
|
361
|
+
// store, or a backward clock step past the overlap, lands behind the
|
|
362
|
+
// watermark and is never indexed.
|
|
363
|
+
let fromMs = msgWm === null ? undefined : Math.max(0, msgWm - (this.cfg.overlapMs ?? 600_000));
|
|
364
|
+
// Messages at exactly `fromMs` already seen this pass. The query bounds
|
|
365
|
+
// are inclusive, so the next page starts at the last page's final
|
|
366
|
+
// millisecond and skips the ones already walked with `offset` — a run
|
|
367
|
+
// of more than a page within one millisecond is walked, not jumped.
|
|
368
|
+
let offset = 0;
|
|
369
|
+
const pageSize = 256;
|
|
370
|
+
for (;;) {
|
|
371
|
+
if (budget <= 0) {
|
|
372
|
+
report.more = true;
|
|
373
|
+
break;
|
|
374
|
+
}
|
|
375
|
+
const page = this.cm.queryMessagesByTime({ fromMs, offset, limit: pageSize });
|
|
376
|
+
const msgs = page.messages;
|
|
377
|
+
report.messagesScanned += msgs.length;
|
|
378
|
+
for (const m of msgs) {
|
|
379
|
+
const item = messageToItem(m, this.cfg);
|
|
380
|
+
if (!item)
|
|
381
|
+
continue;
|
|
382
|
+
pending.push(item);
|
|
383
|
+
// Only NEW items spend the budget. The overlap re-walk behind the
|
|
384
|
+
// watermark is a dedup no-op for the service, and it must be one
|
|
385
|
+
// for the budget too: when the overlap window held more messages
|
|
386
|
+
// than a tick's budget, every tick spent it all re-sending the same
|
|
387
|
+
// indexed items and never reached the first new one — the index
|
|
388
|
+
// froze at the watermark while reporting merely `more: true`.
|
|
389
|
+
if (msgWm === null || item.cursor === undefined || item.cursor > msgWm)
|
|
390
|
+
budget--;
|
|
391
|
+
if (pending.length >= batchSize)
|
|
392
|
+
await flush();
|
|
393
|
+
}
|
|
394
|
+
if (msgs.length < pageSize)
|
|
395
|
+
break;
|
|
396
|
+
const lastMs = msgs[msgs.length - 1].timestamp.getTime();
|
|
397
|
+
const atLast = msgs.filter((m) => m.timestamp.getTime() === lastMs).length;
|
|
398
|
+
offset = lastMs === fromMs ? offset + atLast : atLast;
|
|
399
|
+
fromMs = lastMs;
|
|
400
|
+
}
|
|
401
|
+
await flush();
|
|
402
|
+
this.consecutiveFailures = 0;
|
|
403
|
+
this.lastError = phaseError;
|
|
404
|
+
this.lastSyncAt = Date.now();
|
|
405
|
+
return report;
|
|
406
|
+
}
|
|
407
|
+
catch (e) {
|
|
408
|
+
this.consecutiveFailures++;
|
|
409
|
+
const delay = Math.min(15 * 60_000, 5_000 * 2 ** Math.min(8, this.consecutiveFailures - 1));
|
|
410
|
+
this.backoffUntil = Date.now() + delay;
|
|
411
|
+
this.lastError = e instanceof Error ? e.message : String(e);
|
|
412
|
+
this.log(`[history/semantic] sync failed (${this.consecutiveFailures}×, retry in ${Math.round(delay / 1000)}s): ${this.lastError}`);
|
|
413
|
+
report.more = true;
|
|
414
|
+
return report;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
//# sourceMappingURL=semantic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semantic.js","sourceRoot":"","sources":["../../../../src/modules/history/semantic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAgFH,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,cAAc,CAAC,CAAC,CAAC;AAExF,MAAM,OAAO,mBAAmB;IAID;IAHZ,IAAI,CAAS;IACb,EAAE,CAAS;IACX,SAAS,CAAS;IACnC,YAA6B,GAAwB;QAAxB,QAAG,GAAH,GAAG,CAAqB;QACnD,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,MAA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AC,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACxF,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,mBAAmB,EAAE,CAAC;YAC3B,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,MAAM,EAAE,KAAK,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,mBAAmB,GAAG,CAAC,CAAC,CAAC,CAAC;YAC5F,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;YACvC,IAAI,CAAC,SAAS,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YAC5D,IAAI,CAAC,GAAG,CAAC,mCAAmC,IAAI,CAAC,mBAAmB,eAAe,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;YACpI,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC;YACnB,OAAO,MAAM,CAAC;QAChB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -5,7 +5,8 @@ export { ApiModule } from './api/index.js';
|
|
|
5
5
|
export type { ApiEvent } from './api/index.js';
|
|
6
6
|
export { HealthModule } from './health/index.js';
|
|
7
7
|
export type { HealthModuleConfig } from './health/index.js';
|
|
8
|
-
export { HistoryModule } from './history/index.js';
|
|
8
|
+
export { HistoryModule, type HistoryModuleOptions } from './history/index.js';
|
|
9
|
+
export type { SemanticIndexConfig } from './history/semantic.js';
|
|
9
10
|
export { WorkspaceModule, WorkspaceReadError } from './workspace/index.js';
|
|
10
11
|
export type { WorkspaceReadErrorCode, WorkspaceReadStage, WorkspaceDiskReadResult, ReadFileFromDiskOptions } from './workspace/index.js';
|
|
11
12
|
export type { WorkspaceConfig, MountConfig, MountState, WorkspaceModuleState, ReadInput, WriteInput, EditInput, DeleteInput, LsInput, GlobInput, GrepInput, StatusInput, MaterializeInput, SyncInput, } from './workspace/index.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,YAAY,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,YAAY,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC9E,YAAY,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAEjE,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC3E,YAAY,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AACzI,YAAY,EACV,eAAe,EACf,WAAW,EACX,UAAU,EACV,oBAAoB,EACpB,SAAS,EACT,UAAU,EACV,SAAS,EACT,WAAW,EACX,OAAO,EACP,SAAS,EACT,SAAS,EACT,WAAW,EACX,gBAAgB,EAChB,SAAS,GACV,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACpE,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,YAAY,EACV,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,EACjB,SAAS,IAAI,gBAAgB,EAC7B,WAAW,EACX,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,oBAAoB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,OAAO,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,OAAO,EAAE,aAAa,EAA6B,MAAM,oBAAoB,CAAC;AAG9E,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAmB3E,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { ContextManager, MessageId } from '@animalabs/context-manager';
|
|
2
|
+
import type { ContentBlock, NormalizedMessage, ToolResult } from '@animalabs/membrane';
|
|
3
|
+
import type { CompletedToolCall } from './types/index.js';
|
|
4
|
+
export declare const TOOL_RESULT_GUARD_NOTICE = "Tool result withheld by the guard. The tool has already executed.";
|
|
5
|
+
export declare const TOOL_RESULT_GUARD_AUDIT_STATE = "framework/tool-result-guard";
|
|
6
|
+
/**
|
|
7
|
+
* Admission of newly returned tool output to durable model-facing memory.
|
|
8
|
+
*
|
|
9
|
+
* Raw output is appended to a separate Chronicle audit slot BEFORE the
|
|
10
|
+
* placeholder enters the context manager. In particular, onNewMessage and
|
|
11
|
+
* speculative compression never see unaccepted output. Acceptance edits the
|
|
12
|
+
* placeholder through CM's versioned edit API; withholding only appends an
|
|
13
|
+
* audit event. Neither operation erases the original output or its blobs.
|
|
14
|
+
*/
|
|
15
|
+
export declare class ToolResultGuard {
|
|
16
|
+
private readonly agentName;
|
|
17
|
+
private readonly cm;
|
|
18
|
+
private readonly configured;
|
|
19
|
+
private pending;
|
|
20
|
+
private registered;
|
|
21
|
+
private override;
|
|
22
|
+
/** True until a recovery produces a clean response/new tool round. */
|
|
23
|
+
recovering: boolean;
|
|
24
|
+
constructor(agentName: string, cm: ContextManager, configured?: boolean);
|
|
25
|
+
get enabled(): boolean;
|
|
26
|
+
setOverride(value: boolean | undefined): void;
|
|
27
|
+
get settingOverride(): boolean | undefined;
|
|
28
|
+
get hasPending(): boolean;
|
|
29
|
+
/** True only once the pending batch's originals were actually put on the
|
|
30
|
+
* wire. Guard effects (retry suppression, refusal claim, prose buffering)
|
|
31
|
+
* are scoped to this state; a merely staged batch never claims a refusal. */
|
|
32
|
+
get hasSubmittedPending(): boolean;
|
|
33
|
+
/** Extra input tokens the pending batch costs on the wire beyond the
|
|
34
|
+
* placeholder the strategy selected against (chars/4 + flat per image,
|
|
35
|
+
* the same heuristic as the physical-window projection). Compilation
|
|
36
|
+
* reserves this so substituting originals cannot exceed the budget. */
|
|
37
|
+
get pendingWireReserveTokens(): number;
|
|
38
|
+
/** Ordered storage work, separate from batches awaiting a provider verdict.
|
|
39
|
+
* A failed acceptance edit retains both the payload and its compression
|
|
40
|
+
* hold here; it can never re-arm refusal handling or tool submission. */
|
|
41
|
+
private unrecorded;
|
|
42
|
+
/** Retry edits and audit writes before a new activation, audit write,
|
|
43
|
+
* maintenance pass, or shutdown. A failed operation stays at the head. */
|
|
44
|
+
flushUnrecorded(): void;
|
|
45
|
+
private append;
|
|
46
|
+
private write;
|
|
47
|
+
private archive;
|
|
48
|
+
storeResults(content: ContentBlock[], wireResults: ToolResult[], originals: CompletedToolCall[]): MessageId;
|
|
49
|
+
/** Results for a live continuation (provideToolResults). Marks the batch
|
|
50
|
+
* submitted and returns the originals only when the audit is durable;
|
|
51
|
+
* otherwise returns placeholder results and leaves it unsubmitted. */
|
|
52
|
+
submissionResults(results: ToolResult[]): ToolResult[];
|
|
53
|
+
/** The stream carrying this batch ended without a clean round (abort or
|
|
54
|
+
* exhausted errors). Settle conservatively — an interrupted submission
|
|
55
|
+
* does not establish acceptance — so a later turn neither resubmits the
|
|
56
|
+
* originals nor attributes its own refusal to this batch. */
|
|
57
|
+
abandon(reason: string): void;
|
|
58
|
+
/** A budget/error restart compiles placeholders; restore pending output
|
|
59
|
+
* only in this provider request, never in the strategy's view. */
|
|
60
|
+
prepareRequest(messages: NormalizedMessage[], recordSubmission?: boolean): NormalizedMessage[];
|
|
61
|
+
/** The turn ended (endTurn/skip_reply) before the batch was submitted:
|
|
62
|
+
* nothing was refused, so admit it exactly as an unguarded agent would.
|
|
63
|
+
* Leaving it pending would turn it into a permanent withheld notice on
|
|
64
|
+
* restart and disable ordinary refusal handling on the next turn. */
|
|
65
|
+
settleTurnEnded(): void;
|
|
66
|
+
/** A refusal arrived while the pending batch was never on the wire (the
|
|
67
|
+
* strategy omitted the exchange). The guard cannot have caused it: record
|
|
68
|
+
* the batch as withheld, clear it, and let ordinary refusal handling run.
|
|
69
|
+
* Returns true when it settled such a batch. */
|
|
70
|
+
settleUnsubmitted(category: string): boolean;
|
|
71
|
+
/** A clean physical response accepts precisely the last submitted batch. */
|
|
72
|
+
accept(): void;
|
|
73
|
+
/** At most one recovery per batch; no scanning/deleting older history. */
|
|
74
|
+
withhold(category: string): string[] | null;
|
|
75
|
+
/** Transfer ownership from provider admission to an ordered storage job.
|
|
76
|
+
* Failure retains the accepted payload and its hold until the edit succeeds.
|
|
77
|
+
* Withheld content is final already, so audit failures cannot keep it held. */
|
|
78
|
+
private settle;
|
|
79
|
+
private releaseOperationHold;
|
|
80
|
+
private releaseHold;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=tool-result-guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-result-guard.d.ts","sourceRoot":"","sources":["../../src/tool-result-guard.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACvF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAG1D,eAAO,MAAM,wBAAwB,sEAAsE,CAAC;AAC5G,eAAO,MAAM,6BAA6B,gCAAgC,CAAC;AAsB3E;;;;;;;;GAQG;AACH,qBAAa,eAAe;IAQxB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAT7B,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,QAAQ,CAAsB;IACtC,sEAAsE;IACtE,UAAU,UAAS;gBAGA,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,cAAc,EAClB,UAAU,UAAQ;IAGrC,IAAI,OAAO,IAAI,OAAO,CAA6C;IACnE,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI;IAC7C,IAAI,eAAe,IAAI,OAAO,GAAG,SAAS,CAA0B;IACpE,IAAI,UAAU,IAAI,OAAO,CAAuC;IA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