@earendil-works/pi-durable 1.1.0 → 1.3.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/CHANGELOG.md +55 -0
- package/README.md +164 -11
- package/dist/codemode/codemode.d.ts +173 -0
- package/dist/codemode/codemode.d.ts.map +1 -0
- package/dist/codemode/codemode.js +886 -0
- package/dist/codemode/codemode.js.map +1 -0
- package/dist/codemode/describe.d.ts +38 -0
- package/dist/codemode/describe.d.ts.map +1 -0
- package/dist/codemode/describe.js +119 -0
- package/dist/codemode/describe.js.map +1 -0
- package/dist/codemode/index.d.ts +3 -0
- package/dist/codemode/index.d.ts.map +1 -0
- package/dist/codemode/index.js +3 -0
- package/dist/codemode/index.js.map +1 -0
- package/dist/codemode/models.d.ts +28 -0
- package/dist/codemode/models.d.ts.map +1 -0
- package/dist/codemode/models.js +231 -0
- package/dist/codemode/models.js.map +1 -0
- package/dist/codemode/output.d.ts +41 -0
- package/dist/codemode/output.d.ts.map +1 -0
- package/dist/codemode/output.js +167 -0
- package/dist/codemode/output.js.map +1 -0
- package/dist/env/index.d.ts +43 -0
- package/dist/env/index.d.ts.map +1 -1
- package/dist/env/index.js.map +1 -1
- package/dist/errors.d.ts +20 -3
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +34 -5
- package/dist/errors.js.map +1 -1
- package/dist/harness/agent.d.ts +5 -2
- package/dist/harness/agent.d.ts.map +1 -1
- package/dist/harness/agent.js +69 -25
- package/dist/harness/agent.js.map +1 -1
- package/dist/harness/compaction.d.ts +6 -1
- package/dist/harness/compaction.d.ts.map +1 -1
- package/dist/harness/compaction.js +10 -7
- package/dist/harness/compaction.js.map +1 -1
- package/dist/harness/context.d.ts +5 -0
- package/dist/harness/context.d.ts.map +1 -1
- package/dist/harness/context.js +46 -12
- package/dist/harness/context.js.map +1 -1
- package/dist/harness/events.d.ts +35 -15
- package/dist/harness/events.d.ts.map +1 -1
- package/dist/harness/events.js +77 -23
- package/dist/harness/events.js.map +1 -1
- package/dist/harness/generation.d.ts +2 -0
- package/dist/harness/generation.d.ts.map +1 -1
- package/dist/harness/generation.js +31 -8
- package/dist/harness/generation.js.map +1 -1
- package/dist/harness/harness.d.ts +7 -0
- package/dist/harness/harness.d.ts.map +1 -1
- package/dist/harness/harness.js +53 -26
- package/dist/harness/harness.js.map +1 -1
- package/dist/harness/inbox.d.ts +16 -4
- package/dist/harness/inbox.d.ts.map +1 -1
- package/dist/harness/inbox.js +26 -3
- package/dist/harness/inbox.js.map +1 -1
- package/dist/harness/live.d.ts +74 -17
- package/dist/harness/live.d.ts.map +1 -1
- package/dist/harness/live.js +66 -14
- package/dist/harness/live.js.map +1 -1
- package/dist/harness/scheduler.d.ts +18 -5
- package/dist/harness/scheduler.d.ts.map +1 -1
- package/dist/harness/scheduler.js +696 -163
- package/dist/harness/scheduler.js.map +1 -1
- package/dist/harness/submissions.d.ts +7 -4
- package/dist/harness/submissions.d.ts.map +1 -1
- package/dist/harness/submissions.js +32 -13
- package/dist/harness/submissions.js.map +1 -1
- package/dist/harness/task-graph.d.ts +1 -1
- package/dist/harness/task-graph.d.ts.map +1 -1
- package/dist/harness/task-graph.js +15 -10
- package/dist/harness/task-graph.js.map +1 -1
- package/dist/harness/tool.d.ts +45 -5
- package/dist/harness/tool.d.ts.map +1 -1
- package/dist/harness/tool.js +378 -63
- package/dist/harness/tool.js.map +1 -1
- package/dist/harness/types.d.ts +153 -13
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/harness/types.js.map +1 -1
- package/dist/harness/util.d.ts +6 -1
- package/dist/harness/util.d.ts.map +1 -1
- package/dist/harness/util.js +5 -2
- package/dist/harness/util.js.map +1 -1
- package/dist/harness/view.d.ts +6 -2
- package/dist/harness/view.d.ts.map +1 -1
- package/dist/harness/view.js +22 -12
- package/dist/harness/view.js.map +1 -1
- package/dist/images/cloudflare.d.ts +4 -0
- package/dist/images/cloudflare.d.ts.map +1 -0
- package/dist/images/cloudflare.js +9 -0
- package/dist/images/cloudflare.js.map +1 -0
- package/dist/images/exif.d.ts +3 -0
- package/dist/images/exif.d.ts.map +1 -0
- package/dist/images/exif.js +71 -0
- package/dist/images/exif.js.map +1 -0
- package/dist/images/index.d.ts +18 -0
- package/dist/images/index.d.ts.map +1 -0
- package/dist/images/index.js +125 -0
- package/dist/images/index.js.map +1 -0
- package/dist/images/node-worker.d.ts +17 -0
- package/dist/images/node-worker.d.ts.map +1 -0
- package/dist/images/node-worker.js +16 -0
- package/dist/images/node-worker.js.map +1 -0
- package/dist/images/node.d.ts +21 -0
- package/dist/images/node.d.ts.map +1 -0
- package/dist/images/node.js +121 -0
- package/dist/images/node.js.map +1 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/search.d.ts +13 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +85 -0
- package/dist/search.js.map +1 -0
- package/dist/session/observation.d.ts +10 -3
- package/dist/session/observation.d.ts.map +1 -1
- package/dist/session/observation.js +24 -34
- package/dist/session/observation.js.map +1 -1
- package/dist/session/session.d.ts +68 -5
- package/dist/session/session.d.ts.map +1 -1
- package/dist/session/session.js +461 -49
- package/dist/session/session.js.map +1 -1
- package/dist/session/transaction.d.ts.map +1 -1
- package/dist/session/transaction.js +1 -0
- package/dist/session/transaction.js.map +1 -1
- package/dist/storage/jsonl/storage.d.ts +4 -0
- package/dist/storage/jsonl/storage.d.ts.map +1 -1
- package/dist/storage/jsonl/storage.js +2 -1
- package/dist/storage/jsonl/storage.js.map +1 -1
- package/dist/storage/memory.d.ts.map +1 -1
- package/dist/storage/memory.js +8 -10
- package/dist/storage/memory.js.map +1 -1
- package/dist/storage/scan.d.ts.map +1 -1
- package/dist/storage/scan.js +5 -4
- package/dist/storage/scan.js.map +1 -1
- package/dist/storage/sqlite/cloudflare.d.ts +17 -5
- package/dist/storage/sqlite/cloudflare.d.ts.map +1 -1
- package/dist/storage/sqlite/cloudflare.js +57 -21
- package/dist/storage/sqlite/cloudflare.js.map +1 -1
- package/dist/storage/sqlite/index.d.ts +1 -1
- package/dist/storage/sqlite/index.d.ts.map +1 -1
- package/dist/storage/sqlite/index.js.map +1 -1
- package/dist/storage/sqlite/migrations.d.ts +5 -1
- package/dist/storage/sqlite/migrations.d.ts.map +1 -1
- package/dist/storage/sqlite/migrations.js +94 -84
- package/dist/storage/sqlite/migrations.js.map +1 -1
- package/dist/storage/sqlite/node.d.ts +6 -4
- package/dist/storage/sqlite/node.d.ts.map +1 -1
- package/dist/storage/sqlite/node.js +6 -2
- package/dist/storage/sqlite/node.js.map +1 -1
- package/dist/storage/sqlite/schema.d.ts +47 -0
- package/dist/storage/sqlite/schema.d.ts.map +1 -0
- package/dist/storage/sqlite/schema.js +57 -0
- package/dist/storage/sqlite/schema.js.map +1 -0
- package/dist/storage/sqlite/storage.d.ts +9 -1
- package/dist/storage/sqlite/storage.d.ts.map +1 -1
- package/dist/storage/sqlite/storage.js +56 -55
- package/dist/storage/sqlite/storage.js.map +1 -1
- package/dist/testing/env-conformance.d.ts.map +1 -1
- package/dist/testing/env-conformance.js +100 -0
- package/dist/testing/env-conformance.js.map +1 -1
- package/dist/testing/runner.d.ts +1 -1
- package/dist/testing/runner.d.ts.map +1 -1
- package/dist/testing/runner.js.map +1 -1
- package/dist/testing/storage-conformance.d.ts.map +1 -1
- package/dist/testing/storage-conformance.js +3 -2
- package/dist/testing/storage-conformance.js.map +1 -1
- package/dist/testing/types.d.ts +2 -0
- package/dist/testing/types.d.ts.map +1 -1
- package/dist/testing/types.js.map +1 -1
- package/dist/tool-search/index.d.ts +2 -0
- package/dist/tool-search/index.d.ts.map +1 -0
- package/dist/tool-search/index.js +2 -0
- package/dist/tool-search/index.js.map +1 -0
- package/dist/tool-search/tool-search.d.ts +23 -0
- package/dist/tool-search/tool-search.d.ts.map +1 -0
- package/dist/tool-search/tool-search.js +84 -0
- package/dist/tool-search/tool-search.js.map +1 -0
- package/dist/tools/bash.d.ts +10 -2
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/bash.js +27 -9
- package/dist/tools/bash.js.map +1 -1
- package/dist/tools/edit.js +1 -1
- package/dist/tools/edit.js.map +1 -1
- package/dist/tools/image-processor.d.ts +50 -0
- package/dist/tools/image-processor.d.ts.map +1 -0
- package/dist/tools/image-processor.js +20 -0
- package/dist/tools/image-processor.js.map +1 -0
- package/dist/tools/image.d.ts +8 -0
- package/dist/tools/image.d.ts.map +1 -1
- package/dist/tools/image.js +47 -0
- package/dist/tools/image.js.map +1 -1
- package/dist/tools/index.d.ts +25 -2
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +13 -5
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/read.d.ts +10 -2
- package/dist/tools/read.d.ts.map +1 -1
- package/dist/tools/read.js +88 -29
- package/dist/tools/read.js.map +1 -1
- package/dist/tools/write.js +1 -1
- package/dist/tools/write.js.map +1 -1
- package/dist/truncate.d.ts +3 -2
- package/dist/truncate.d.ts.map +1 -1
- package/dist/truncate.js +4 -34
- package/dist/truncate.js.map +1 -1
- package/dist/types.d.ts +59 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +43 -4
- package/dist/harness/output.d.ts +0 -69
- package/dist/harness/output.d.ts.map +0 -1
- package/dist/harness/output.js +0 -318
- package/dist/harness/output.js.map +0 -1
package/dist/harness/events.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CommittedWatch } from "../session/observation.js";
|
|
2
2
|
import { AgentDoc } from "./agent.js";
|
|
3
|
+
import { NestedCallDoc } from "./tool.js";
|
|
3
4
|
import { UsageDoc } from "./usage.js";
|
|
4
5
|
import { scanAll } from "./util.js";
|
|
5
6
|
import { conversationViews } from "./view.js";
|
|
@@ -19,7 +20,9 @@ function snapshotOf(view) {
|
|
|
19
20
|
...(live.run === undefined ? {} : { run: { inputs: live.run.inputs } }),
|
|
20
21
|
...(live.generation === undefined ? {} : { generation: live.generation }),
|
|
21
22
|
tools: live.tools ?? [],
|
|
23
|
+
nestedTools: live.nestedTools ?? [],
|
|
22
24
|
compactions: live.compactions ?? [],
|
|
25
|
+
...(live.compactionFailure === undefined ? {} : { compactionFailure: live.compactionFailure }),
|
|
23
26
|
inbox: queued(inbox),
|
|
24
27
|
agent: agent ?? AgentDoc.definition.initial(),
|
|
25
28
|
usage: usage ?? UsageDoc.definition.initial(),
|
|
@@ -33,9 +36,10 @@ function queued(inbox) {
|
|
|
33
36
|
* commits are captured atomically on the Session line; overflow replaces undelivered batches with one snapshot.
|
|
34
37
|
*/
|
|
35
38
|
export async function watchEvents(harness, conversationId, context) {
|
|
39
|
+
const views = conversationViews(harness);
|
|
36
40
|
let watch;
|
|
37
41
|
let snapshot;
|
|
38
|
-
await
|
|
42
|
+
await views.attach(conversationId, async (initial, release, storage) => {
|
|
39
43
|
// Generations whose held outcome already ended their turn, read on the line with the snapshot.
|
|
40
44
|
const query = { conversationId, kind: "pi.generation", status: "completing" };
|
|
41
45
|
const completing = await scanAll((cursor) => storage.scanTasks(query, 100, cursor, context));
|
|
@@ -43,7 +47,7 @@ export async function watchEvents(harness, conversationId, context) {
|
|
|
43
47
|
let current = initial;
|
|
44
48
|
snapshot = snapshotOf(initial);
|
|
45
49
|
// Batches are the watch's values; an overflow delivers a snapshot of the newest view instead.
|
|
46
|
-
watch = new CommittedWatch([], release, () => [snapshotOf(current)]);
|
|
50
|
+
watch = new CommittedWatch([], release, (error) => views.report(error), () => [snapshotOf(current)]);
|
|
47
51
|
return {
|
|
48
52
|
publication: (before, after, ops, publication, commitContext) => {
|
|
49
53
|
current = after;
|
|
@@ -51,7 +55,7 @@ export async function watchEvents(harness, conversationId, context) {
|
|
|
51
55
|
if (events.length > 0)
|
|
52
56
|
watch.advance(events, [], commitContext);
|
|
53
57
|
},
|
|
54
|
-
closeSession: () => watch.closeSession(),
|
|
58
|
+
closeSession: (failure) => watch.closeSession(failure),
|
|
55
59
|
};
|
|
56
60
|
}, context);
|
|
57
61
|
// Like a watch, the acquisition context governs the stream's lifetime.
|
|
@@ -81,7 +85,18 @@ function translate(conversationId, before, after, viewOps, publication, held) {
|
|
|
81
85
|
const entries = [];
|
|
82
86
|
const tasks = new Map();
|
|
83
87
|
const submissions = [];
|
|
88
|
+
// Nested results this commit stored, by nested task ID; read now, since the caller's documents may retire next.
|
|
89
|
+
const nestedResults = new Map();
|
|
84
90
|
for (const change of publication.changes) {
|
|
91
|
+
if (change.type === "document" &&
|
|
92
|
+
change.record.kind === NestedCallDoc.definition.kind &&
|
|
93
|
+
change.value !== null &&
|
|
94
|
+
change.conversationId === conversationId) {
|
|
95
|
+
const state = change.value;
|
|
96
|
+
if (state.taskId !== undefined && state.result !== undefined) {
|
|
97
|
+
nestedResults.set(state.taskId, state.result);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
85
100
|
if (change.type === "entry" && change.value.conversationId === conversationId)
|
|
86
101
|
entries.push(change.value);
|
|
87
102
|
if (change.type === "task" && change.value.conversationId === conversationId)
|
|
@@ -100,12 +115,18 @@ function translate(conversationId, before, after, viewOps, publication, held) {
|
|
|
100
115
|
// Progress: tool starts, the in-flight message, tool updates, retry and deferred state.
|
|
101
116
|
const slotsBefore = new Map((was.live.tools ?? []).map((slot) => [slot.callId, slot]));
|
|
102
117
|
const slots = now.live.tools ?? [];
|
|
103
|
-
|
|
104
|
-
|
|
118
|
+
const nestedBefore = new Map((was.live.nestedTools ?? []).map((slot) => [slot.taskId, slot]));
|
|
119
|
+
const nested = now.live.nestedTools ?? [];
|
|
120
|
+
for (const slot of [...slots, ...nested]) {
|
|
121
|
+
const previous = "parentCallId" in slot ? nestedBefore.get(slot.taskId) : slotsBefore.get(slot.callId);
|
|
122
|
+
if (slot.status !== "running" || previous?.status === "running")
|
|
105
123
|
continue;
|
|
124
|
+
// A nested slot carries the arguments the call runs with; a model-issued call's are in its intent checkpoint.
|
|
106
125
|
const checkpoint = slot.taskId === undefined ? undefined : tasks.get(slot.taskId)?.state.checkpoint;
|
|
107
|
-
const args =
|
|
108
|
-
|
|
126
|
+
const args = "parentCallId" in slot
|
|
127
|
+
? slot.arguments
|
|
128
|
+
: (checkpoint?.arguments ?? {});
|
|
129
|
+
events.push({ type: "tool_execution_start", ...callOf(slot), args });
|
|
109
130
|
}
|
|
110
131
|
const partialBefore = was.live.generation?.message;
|
|
111
132
|
const partial = now.live.generation?.message;
|
|
@@ -118,10 +139,19 @@ function translate(conversationId, before, after, viewOps, publication, held) {
|
|
|
118
139
|
const previous = slotsBefore.get(slot.callId);
|
|
119
140
|
if (slot.status !== "running" || previous?.status !== "running")
|
|
120
141
|
continue;
|
|
121
|
-
const update = toolUpdate(viewOps, index, slot, previous);
|
|
142
|
+
const update = toolUpdate(viewOps, ["tools", index], slot, previous);
|
|
143
|
+
if (update === undefined)
|
|
144
|
+
continue;
|
|
145
|
+
events.push({ type: "tool_execution_update", ...callOf(slot), ...update });
|
|
146
|
+
}
|
|
147
|
+
for (const [index, slot] of nested.entries()) {
|
|
148
|
+
const previous = nestedBefore.get(slot.taskId);
|
|
149
|
+
if (slot.status !== "running" || previous?.status !== "running")
|
|
150
|
+
continue;
|
|
151
|
+
const update = toolUpdate(viewOps, ["nestedTools", index], slot, previous);
|
|
122
152
|
if (update === undefined)
|
|
123
153
|
continue;
|
|
124
|
-
events.push({ type: "tool_execution_update",
|
|
154
|
+
events.push({ type: "tool_execution_update", ...callOf(slot), ...update });
|
|
125
155
|
}
|
|
126
156
|
const generation = now.live.generation;
|
|
127
157
|
const generationBefore = was.live.generation;
|
|
@@ -138,28 +168,41 @@ function translate(conversationId, before, after, viewOps, publication, held) {
|
|
|
138
168
|
// Tools that end in this commit: a slot that becomes done, one created done (a call not offered), or an unfinished
|
|
139
169
|
// one that vanishes because its run ended. A done slot that vanishes ended earlier.
|
|
140
170
|
const toolEnds = [];
|
|
141
|
-
const endTool = (
|
|
171
|
+
const endTool = (slot, entryId) => {
|
|
142
172
|
const entry = entries.find((candidate) => candidate.id === entryId);
|
|
143
|
-
toolEnds.push({
|
|
144
|
-
type: "tool_execution_end",
|
|
145
|
-
toolCallId: callId,
|
|
146
|
-
toolName: name,
|
|
147
|
-
...(entry === undefined ? {} : { entry }),
|
|
148
|
-
});
|
|
173
|
+
toolEnds.push({ type: "tool_execution_end", ...callOf(slot), ...(entry === undefined ? {} : { entry }) });
|
|
149
174
|
};
|
|
150
175
|
for (const previous of slotsBefore.values()) {
|
|
151
176
|
if (previous.status === "done")
|
|
152
177
|
continue;
|
|
153
178
|
const slot = slots.find((candidate) => candidate.callId === previous.callId);
|
|
154
179
|
if (slot?.status === "done")
|
|
155
|
-
endTool(
|
|
180
|
+
endTool(slot, slot.entry);
|
|
156
181
|
// A slot whose run ended in this commit may have had its result appended with it, as for unstarted calls.
|
|
157
182
|
else if (slot === undefined)
|
|
158
|
-
endTool(previous
|
|
183
|
+
endTool(previous, resultOf(entries, previous.callId)?.id);
|
|
159
184
|
}
|
|
160
185
|
for (const slot of slots) {
|
|
161
186
|
if (slot.status === "done" && !slotsBefore.has(slot.callId))
|
|
162
|
-
endTool(slot
|
|
187
|
+
endTool(slot, slot.entry);
|
|
188
|
+
}
|
|
189
|
+
// Nested calls that end in this commit, the same way, children before the calls that made them: the lists hold
|
|
190
|
+
// parents first, so walk them backwards.
|
|
191
|
+
const endNested = (slot) => {
|
|
192
|
+
const result = nestedResults.get(slot.taskId);
|
|
193
|
+
events.push({ type: "tool_execution_end", ...callOf(slot), ...(result === undefined ? {} : { result }) });
|
|
194
|
+
};
|
|
195
|
+
const nestedNow = new Map(nested.map((slot) => [slot.taskId, slot]));
|
|
196
|
+
for (const previous of [...nestedBefore.values()].reverse()) {
|
|
197
|
+
if (previous.status === "done")
|
|
198
|
+
continue;
|
|
199
|
+
const slot = nestedNow.get(previous.taskId);
|
|
200
|
+
if (slot?.status === "done" || slot === undefined)
|
|
201
|
+
endNested(slot ?? previous);
|
|
202
|
+
}
|
|
203
|
+
for (const slot of [...nested].reverse()) {
|
|
204
|
+
if (slot.status === "done" && !nestedBefore.has(slot.taskId))
|
|
205
|
+
endNested(slot);
|
|
163
206
|
}
|
|
164
207
|
// Entries in append order; a tool's end directly precedes its result's message, as in the coding agent.
|
|
165
208
|
let assistantAppended = false;
|
|
@@ -183,9 +226,11 @@ function translate(conversationId, before, after, viewOps, publication, held) {
|
|
|
183
226
|
// Compaction ends, task failures, then turn and run ends.
|
|
184
227
|
const compactionsBefore = was.live.compactions ?? [];
|
|
185
228
|
const compactions = now.live.compactions ?? [];
|
|
229
|
+
const failure = now.live.compactionFailure;
|
|
186
230
|
for (const { taskId, reason } of compactionsBefore) {
|
|
187
231
|
if (!compactions.some((status) => status.taskId === taskId)) {
|
|
188
|
-
|
|
232
|
+
const error = failure?.taskId === taskId ? failure.error : undefined;
|
|
233
|
+
events.push({ type: "compaction_end", taskId, reason, ...(error === undefined ? {} : { error }) });
|
|
189
234
|
}
|
|
190
235
|
}
|
|
191
236
|
// A generation's turn ends when its outcome is committed: at a `completing` hold or at terminal, whichever comes
|
|
@@ -283,9 +328,18 @@ function messageChanges(viewOps, message) {
|
|
|
283
328
|
}
|
|
284
329
|
return changes;
|
|
285
330
|
}
|
|
286
|
-
/**
|
|
287
|
-
function
|
|
288
|
-
|
|
331
|
+
/** The identifying fields of a slot's tool events. */
|
|
332
|
+
function callOf(slot) {
|
|
333
|
+
return {
|
|
334
|
+
toolCallId: slot.callId,
|
|
335
|
+
toolName: slot.name,
|
|
336
|
+
...(slot.taskId === undefined ? {} : { taskId: slot.taskId }),
|
|
337
|
+
...("parentCallId" in slot ? { parentToolCallId: slot.parentCallId, parentTaskId: slot.parentTaskId } : {}),
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
/** Output, details, and diagnostics changes of a running slot at `at` in `pi.live`, from the view operations on it. */
|
|
341
|
+
function toolUpdate(viewOps, at, slot, previous) {
|
|
342
|
+
const outputPath = ["docs", "pi.live", ...at, "output"];
|
|
289
343
|
let trimStart = 0;
|
|
290
344
|
let append = "";
|
|
291
345
|
let set = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/harness/events.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAY3D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC,OAAO,EAAE,QAAQ,EAAmB,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAyB,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAsFrE,SAAS,KAAK,CAAC,IAAsB;IACpC,OAAO;QACN,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAc;QAC/C,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,CAA2B;QACtD,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,CAA2B;QACtD,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,CAA2B;KACtD,CAAC;AACH,CAAC;AAED,SAAS,UAAU,CAAC,IAAsB;IACzC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;IAClD,OAAO;QACN,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,GAAG,CAAC,IAAI,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC;QACvE,GAAG,CAAC,IAAI,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,UAAyC,EAAE,CAAC;QACxG,KAAK,EAAE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CAAC;KAC7F,CAAC;IACF,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC;AAC9D,CAAC;AAED,SAAS,UAAU,CAAC,IAAU,EAAE,MAAoC;IACnE,OAAO,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,OAAO,CAAC,CAAC;AAClG,CAAC","sourcesContent":["import type { Context, JsonValue } from \"@earendil-works/chord\";\nimport type { Op, Path } from \"@earendil-works/chord/delta\";\nimport type { AssistantMessage, Message, Usage } from \"@earendil-works/pi-ai\";\nimport { CommittedWatch } from \"../session/observation.ts\";\nimport type {\n\tCommitChange,\n\tCommitPublication,\n\tConversationId,\n\tEntryRecord,\n\tJsonObject,\n\tSubmissionId,\n\tSubmissionRecord,\n\tTaskId,\n\tWatchEnd,\n} from \"../types.ts\";\nimport { AgentDoc } from \"./agent.ts\";\nimport type { InboxItem, InboxState } from \"./inbox.ts\";\nimport type { CompactionStatus, LiveState, ToolSlot } from \"./live.ts\";\nimport type { AgentState, CompactionReason, Harness, ToolDiagnostic } from \"./types.ts\";\nimport { UsageDoc, type UsageState } from \"./usage.ts\";\nimport { scanAll } from \"./util.ts\";\nimport { type ConversationView, conversationViews } from \"./view.ts\";\n\ntype Block = AssistantMessage[\"content\"][number];\ntype QueuedItem = { id: SubmissionId; mode: InboxItem[\"mode\"] };\n\n/** One change to the in-flight assistant message, relative to that message. */\nexport type MessageChange =\n\t| { type: \"text_start\" | \"thinking_start\" | \"toolcall_start\"; contentIndex: number; block: Block }\n\t| { type: \"text_delta\" | \"thinking_delta\"; contentIndex: number; delta: string }\n\t| { type: \"toolcall_delta\"; contentIndex: number; path: readonly (string | number)[]; delta: string }\n\t| { type: \"block\"; contentIndex: number; block: Block }\n\t| { type: \"message\"; message: AssistantMessage };\n\nexport type SnapshotEvent = {\n\ttype: \"snapshot\";\n\tentries: readonly EntryRecord[];\n\trun?: { inputs: readonly SubmissionId[] };\n\t/** Current generation attempt: its in-flight partial, retry backoff, or deferred poll. */\n\tgeneration?: {\n\t\tattempt: number;\n\t\tmessage?: AssistantMessage;\n\t\tretry?: { at: number; error: string };\n\t\tdeferred?: { pollAt: number };\n\t};\n\ttools: readonly ToolSlot[];\n\t/** `pi.live.compactions`: live compactions with their attempt and retry backoff. */\n\tcompactions: readonly CompactionStatus[];\n\tinbox: readonly QueuedItem[];\n\t/** `pi.agent`; `{}` when absent. */\n\tagent: AgentState;\n\tusage: UsageState;\n};\n\n/** Experimental agent event, shaped like the coding agent's session events (spec §9.4). */\nexport type AgentEvent =\n\t| SnapshotEvent\n\t| { type: \"run_start\"; inputs: readonly SubmissionId[] }\n\t| { type: \"run_end\"; inputs: readonly SubmissionId[] }\n\t| { type: \"turn_start\" }\n\t| { type: \"turn_end\" }\n\t| { type: \"message_start\"; message: Message }\n\t/** `usage` is the partial's current usage, as in the coding agent's JSON mode. */\n\t| { type: \"message_update\"; usage: Usage; changes: readonly MessageChange[] }\n\t| { type: \"message_end\"; entry: EntryRecord }\n\t| { type: \"tool_execution_start\"; toolCallId: string; toolName: string; args: JsonObject }\n\t| {\n\t\t\ttype: \"tool_execution_update\";\n\t\t\ttoolCallId: string;\n\t\t\ttoolName: string;\n\t\t\t/** A front trim and then an append of the retained window, or its replacement. */\n\t\t\toutput?: { trimStart?: number; append?: string } | { set: string };\n\t\t\tdetails?: JsonValue;\n\t\t\tdiagnostics?: readonly ToolDiagnostic[];\n\t }\n\t/** `entry` is absent when the tool task faulted or was orphaned. */\n\t| { type: \"tool_execution_end\"; toolCallId: string; toolName: string; entry?: EntryRecord }\n\t| { type: \"inbox_update\"; items: readonly QueuedItem[] }\n\t| { type: \"submission\"; record: SubmissionRecord }\n\t| { type: \"auto_retry_start\"; attempt: number; at: number; errorMessage: string }\n\t| { type: \"auto_retry_end\"; attempt: number }\n\t| { type: \"deferred_poll\"; pollAt: number }\n\t| { type: \"entry_appended\"; entry: EntryRecord }\n\t| { type: \"agent_changed\"; agent: AgentState }\n\t| { type: \"usage_changed\"; usage: UsageState }\n\t| { type: \"task_failed\"; taskId: TaskId; kind: string; message: string }\n\t| { type: \"compaction_start\"; taskId: TaskId; reason: CompactionReason; blocking: boolean }\n\t/** The task's receipt tells whether it produced a summary; the summary entry has its own events. */\n\t| { type: \"compaction_end\"; taskId: TaskId; reason: CompactionReason };\n\n/** Serialized stream of one conversation's event batches, one per commit. */\nexport interface AgentEventStream {\n\t/** The `snapshot` event at attachment. */\n\treadonly snapshot: SnapshotEvent;\n\tstart(listener: (events: readonly AgentEvent[], context: Context) => Promise<void>): void;\n\tstop(): Promise<WatchEnd>;\n\treadonly closed: Promise<WatchEnd>;\n}\n\n/** The typed parts of a view the events read. */\ntype Parts = {\n\tlive: LiveState;\n\tinbox: InboxState | undefined;\n\tagent: AgentState | undefined;\n\tusage: UsageState | undefined;\n};\n\nfunction parts(view: ConversationView): Parts {\n\treturn {\n\t\tlive: (view.docs[\"pi.live\"] ?? {}) as LiveState,\n\t\tinbox: view.docs[\"pi.inbox\"] as InboxState | undefined,\n\t\tagent: view.docs[\"pi.agent\"] as AgentState | undefined,\n\t\tusage: view.docs[\"pi.usage\"] as UsageState | undefined,\n\t};\n}\n\nfunction snapshotOf(view: ConversationView): SnapshotEvent {\n\tconst { live, inbox, agent, usage } = parts(view);\n\treturn {\n\t\ttype: \"snapshot\",\n\t\tentries: view.entries,\n\t\t...(live.run === undefined ? {} : { run: { inputs: live.run.inputs } }),\n\t\t...(live.generation === undefined ? {} : { generation: live.generation as SnapshotEvent[\"generation\"] }),\n\t\ttools: live.tools ?? [],\n\t\tcompactions: live.compactions ?? [],\n\t\tinbox: queued(inbox),\n\t\tagent: agent ?? AgentDoc.definition.initial(),\n\t\tusage: usage ?? UsageDoc.definition.initial(),\n\t};\n}\n\nfunction queued(inbox: InboxState | undefined): QueuedItem[] {\n\treturn (inbox?.items ?? []).map((item) => ({ id: item.id, mode: item.mode }));\n}\n\n/**\n * Experimental: attach to one conversation's agent events (spec §9.4). The snapshot and the registration for later\n * commits are captured atomically on the Session line; overflow replaces undelivered batches with one snapshot.\n */\nexport async function watchEvents(\n\tharness: Harness,\n\tconversationId: ConversationId,\n\tcontext: Context,\n): Promise<AgentEventStream> {\n\tlet watch!: CommittedWatch<readonly AgentEvent[]>;\n\tlet snapshot!: SnapshotEvent;\n\tawait conversationViews(harness).attach(\n\t\tconversationId,\n\t\tasync (initial, release, storage) => {\n\t\t\t// Generations whose held outcome already ended their turn, read on the line with the snapshot.\n\t\t\tconst query = { conversationId, kind: \"pi.generation\", status: \"completing\" } as const;\n\t\t\tconst completing = await scanAll((cursor) => storage.scanTasks(query, 100, cursor, context));\n\t\t\tconst held = new Set<TaskId>(completing.map((record) => record.id));\n\t\t\tlet current = initial;\n\t\t\tsnapshot = snapshotOf(initial);\n\t\t\t// Batches are the watch's values; an overflow delivers a snapshot of the newest view instead.\n\t\t\twatch = new CommittedWatch<readonly AgentEvent[]>([], release, () => [snapshotOf(current)]);\n\t\t\treturn {\n\t\t\t\tpublication: (before, after, ops, publication, commitContext) => {\n\t\t\t\t\tcurrent = after;\n\t\t\t\t\tconst events = translate(conversationId, before, after, ops, publication, held);\n\t\t\t\t\tif (events.length > 0) watch.advance(events, [], commitContext);\n\t\t\t\t},\n\t\t\t\tcloseSession: () => watch.closeSession(),\n\t\t\t};\n\t\t},\n\t\tcontext,\n\t);\n\t// Like a watch, the acquisition context governs the stream's lifetime.\n\tconst signal = context.abortSignal;\n\tif (signal?.aborted) {\n\t\twatch.cancel();\n\t\tthrow signal.reason;\n\t}\n\tif (signal !== undefined) watch.observeCancellation(signal);\n\treturn {\n\t\tsnapshot,\n\t\tstart: (listener) => watch.start((events, _ops, deliveryContext) => listener(events, deliveryContext)),\n\t\tstop: () => watch.stop(),\n\t\tclosed: watch.closed,\n\t};\n}\n\ntype TaskChange = Extract<CommitChange, { type: \"task\" }>;\n\n/** The tool result for `callId` among `entries`. */\nfunction resultOf(entries: readonly EntryRecord[], callId: string): EntryRecord | undefined {\n\treturn entries.find((entry) => {\n\t\tconst message = entry.model?.[0];\n\t\treturn message?.role === \"toolResult\" && message.toolCallId === callId;\n\t});\n}\n\n/** Every event one publication causes, in the order of spec §9.4. */\nfunction translate(\n\tconversationId: ConversationId,\n\tbefore: ConversationView,\n\tafter: ConversationView,\n\tviewOps: readonly Op[],\n\tpublication: CommitPublication,\n\theld: Set<TaskId>,\n): AgentEvent[] {\n\tconst entries: EntryRecord[] = [];\n\tconst tasks = new Map<TaskId, TaskChange[\"value\"]>();\n\tconst submissions: SubmissionRecord[] = [];\n\tfor (const change of publication.changes) {\n\t\tif (change.type === \"entry\" && change.value.conversationId === conversationId) entries.push(change.value);\n\t\tif (change.type === \"task\" && change.value.conversationId === conversationId)\n\t\t\ttasks.set(change.value.id, change.value);\n\t\tif (change.type === \"submission\" && change.value.conversationId === conversationId) {\n\t\t\tsubmissions.push(change.value);\n\t\t}\n\t}\n\tif (viewOps.length === 0 && entries.length === 0 && tasks.size === 0 && submissions.length === 0) return [];\n\t// Entries are appended in ID order; submission records are published in the order the commit first touched them.\n\tsubmissions.sort((a, b) => a.id - b.id);\n\tconst was = parts(before);\n\tconst now = parts(after);\n\tconst events: AgentEvent[] = [];\n\n\t// Progress: tool starts, the in-flight message, tool updates, retry and deferred state.\n\tconst slotsBefore = new Map((was.live.tools ?? []).map((slot) => [slot.callId, slot]));\n\tconst slots = now.live.tools ?? [];\n\tfor (const slot of slots) {\n\t\tif (slot.status !== \"running\" || slotsBefore.get(slot.callId)?.status === \"running\") continue;\n\t\tconst checkpoint = slot.taskId === undefined ? undefined : tasks.get(slot.taskId)?.state.checkpoint;\n\t\tconst args = (checkpoint as { arguments?: JsonObject } | undefined)?.arguments ?? {};\n\t\tevents.push({ type: \"tool_execution_start\", toolCallId: slot.callId, toolName: slot.name, args });\n\t}\n\tconst partialBefore = was.live.generation?.message as AssistantMessage | undefined;\n\tconst partial = now.live.generation?.message as AssistantMessage | undefined;\n\tif (partial !== undefined && partialBefore === undefined) events.push({ type: \"message_start\", message: partial });\n\telse if (partial !== undefined && partial !== partialBefore) {\n\t\tevents.push({ type: \"message_update\", usage: partial.usage, changes: messageChanges(viewOps, partial) });\n\t}\n\tfor (const [index, slot] of slots.entries()) {\n\t\tconst previous = slotsBefore.get(slot.callId);\n\t\tif (slot.status !== \"running\" || previous?.status !== \"running\") continue;\n\t\tconst update = toolUpdate(viewOps, index, slot, previous);\n\t\tif (update === undefined) continue;\n\t\tevents.push({ type: \"tool_execution_update\", toolCallId: slot.callId, toolName: slot.name, ...update });\n\t}\n\tconst generation = now.live.generation;\n\tconst generationBefore = was.live.generation;\n\tif (generation?.retry !== undefined && generationBefore?.retry === undefined) {\n\t\tconst { at, error } = generation.retry;\n\t\tevents.push({ type: \"auto_retry_start\", attempt: generation.attempt, at, errorMessage: error });\n\t}\n\tif (generationBefore?.retry !== undefined && generation?.retry === undefined) {\n\t\tevents.push({ type: \"auto_retry_end\", attempt: generationBefore.attempt });\n\t}\n\tif (generation?.deferred !== undefined && generation.deferred.pollAt !== generationBefore?.deferred?.pollAt) {\n\t\tevents.push({ type: \"deferred_poll\", pollAt: generation.deferred.pollAt });\n\t}\n\n\t// Tools that end in this commit: a slot that becomes done, one created done (a call not offered), or an unfinished\n\t// one that vanishes because its run ended. A done slot that vanishes ended earlier.\n\tconst toolEnds: Extract<AgentEvent, { type: \"tool_execution_end\" }>[] = [];\n\tconst endTool = (callId: string, name: string, entryId: number | undefined): void => {\n\t\tconst entry = entries.find((candidate) => candidate.id === entryId);\n\t\ttoolEnds.push({\n\t\t\ttype: \"tool_execution_end\",\n\t\t\ttoolCallId: callId,\n\t\t\ttoolName: name,\n\t\t\t...(entry === undefined ? {} : { entry }),\n\t\t});\n\t};\n\tfor (const previous of slotsBefore.values()) {\n\t\tif (previous.status === \"done\") continue;\n\t\tconst slot = slots.find((candidate) => candidate.callId === previous.callId);\n\t\tif (slot?.status === \"done\") endTool(previous.callId, previous.name, slot.entry);\n\t\t// A slot whose run ended in this commit may have had its result appended with it, as for unstarted calls.\n\t\telse if (slot === undefined) endTool(previous.callId, previous.name, resultOf(entries, previous.callId)?.id);\n\t}\n\tfor (const slot of slots) {\n\t\tif (slot.status === \"done\" && !slotsBefore.has(slot.callId)) endTool(slot.callId, slot.name, slot.entry);\n\t}\n\n\t// Entries in append order; a tool's end directly precedes its result's message, as in the coding agent.\n\tlet assistantAppended = false;\n\tfor (const entry of entries) {\n\t\tevents.push(...toolEnds.filter((end) => end.entry === entry));\n\t\tconst message = entry.model?.[0];\n\t\tif (message === undefined) {\n\t\t\tevents.push({ type: \"entry_appended\", entry });\n\t\t\tcontinue;\n\t\t}\n\t\t// A streamed answer already started with its first partial.\n\t\tconst streamed = message.role === \"assistant\" && partialBefore !== undefined && !assistantAppended;\n\t\tif (message.role === \"assistant\") assistantAppended = true;\n\t\tif (!streamed) events.push({ type: \"message_start\", message });\n\t\tevents.push({ type: \"message_end\", entry });\n\t}\n\t// Ends without a result entry: a faulted or orphaned tool, or one whose run ended.\n\tevents.push(...toolEnds.filter((end) => end.entry === undefined));\n\n\t// Compaction ends, task failures, then turn and run ends.\n\tconst compactionsBefore = was.live.compactions ?? [];\n\tconst compactions = now.live.compactions ?? [];\n\tfor (const { taskId, reason } of compactionsBefore) {\n\t\tif (!compactions.some((status) => status.taskId === taskId)) {\n\t\t\tevents.push({ type: \"compaction_end\", taskId, reason });\n\t\t}\n\t}\n\t// A generation's turn ends when its outcome is committed: at a `completing` hold or at terminal, whichever comes\n\t// first, so a successor created at the hold starts after it.\n\tlet turnEnded = false;\n\tfor (const task of tasks.values()) {\n\t\tconst status = task.state.status;\n\t\tif (task.kind === \"pi.generation\" && status === \"completing\" && !held.has(task.id)) {\n\t\t\theld.add(task.id);\n\t\t\tturnEnded = true;\n\t\t}\n\t\tif (status !== \"terminal\") continue;\n\t\tif (task.kind === \"pi.generation\" && !held.delete(task.id)) turnEnded = true;\n\t\tconst outcome = task.state.outcome;\n\t\tif (outcome.status === \"faulted\" || outcome.status === \"orphaned\") {\n\t\t\tconst message = outcome.status === \"faulted\" ? outcome.error.message : outcome.reason;\n\t\t\tevents.push({ type: \"task_failed\", taskId: task.id, kind: task.kind, message });\n\t\t}\n\t}\n\tif (turnEnded) events.push({ type: \"turn_end\" });\n\tconst run = now.live.run;\n\tconst runBefore = was.live.run;\n\tconst runChanged = run?.inputs[0] !== runBefore?.inputs[0];\n\tif (runBefore !== undefined && runChanged) events.push({ type: \"run_end\", inputs: runBefore.inputs });\n\n\t// Submissions, document state, then what began.\n\tfor (const record of submissions) events.push({ type: \"submission\", record });\n\tif (now.inbox !== was.inbox) events.push({ type: \"inbox_update\", items: queued(now.inbox) });\n\t// A retired document reads as its initial value, as in a snapshot.\n\tif (now.agent !== was.agent) {\n\t\tevents.push({ type: \"agent_changed\", agent: now.agent ?? AgentDoc.definition.initial() });\n\t}\n\tif (now.usage !== was.usage)\n\t\tevents.push({ type: \"usage_changed\", usage: now.usage ?? UsageDoc.definition.initial() });\n\tfor (const { taskId, reason, blocking } of compactions) {\n\t\tif (!compactionsBefore.some((status) => status.taskId === taskId)) {\n\t\t\tevents.push({ type: \"compaction_start\", taskId, reason, blocking });\n\t\t}\n\t}\n\tif (run !== undefined && runChanged) events.push({ type: \"run_start\", inputs: run.inputs });\n\tif (run !== undefined && run.taskId !== runBefore?.taskId && tasks.get(run.taskId)?.kind === \"pi.generation\") {\n\t\tevents.push({ type: \"turn_start\" });\n\t}\n\treturn events;\n}\n\nconst PARTIAL_PATH = [\"docs\", \"pi.live\", \"generation\", \"message\"];\n\n/** Translate the view operations on the in-flight message into message changes (spec §9.4). */\nfunction messageChanges(viewOps: readonly Op[], message: AssistantMessage): MessageChange[] {\n\tconst changes: MessageChange[] = [];\n\t// A block sent whole already holds every later change to it in this batch.\n\tconst whole = new Set<number>();\n\tfor (const op of viewOps) {\n\t\t// View operations never replace the root.\n\t\tconst path = op[1] as Path;\n\t\tif (!startsWith(path, PARTIAL_PATH)) {\n\t\t\t// The whole message or generation was replaced.\n\t\t\tif (startsWith(PARTIAL_PATH, path)) return [{ type: \"message\", message }];\n\t\t\tcontinue;\n\t\t}\n\t\tconst rest = path.slice(PARTIAL_PATH.length);\n\t\tif (rest[0] === \"usage\") continue;\n\t\tif (rest[0] !== \"content\") return [{ type: \"message\", message }];\n\t\tif (rest.length === 1) {\n\t\t\tif (op[0] !== \"p\" || op[3] !== 0) return [{ type: \"message\", message }];\n\t\t\tfor (const [offset, block] of (op[4] as unknown as Block[]).entries()) {\n\t\t\t\tconst type =\n\t\t\t\t\tblock.type === \"text\" ? \"text_start\" : block.type === \"thinking\" ? \"thinking_start\" : \"toolcall_start\";\n\t\t\t\tchanges.push({ type, contentIndex: op[2] + offset, block });\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tconst contentIndex = rest[1] as number;\n\t\tconst field = rest[2];\n\t\tif (whole.has(contentIndex)) continue;\n\t\tif (op[0] === \"a\" && rest.length === 3 && (field === \"text\" || field === \"thinking\")) {\n\t\t\tchanges.push({ type: field === \"text\" ? \"text_delta\" : \"thinking_delta\", contentIndex, delta: op[2] });\n\t\t} else if (op[0] === \"a\" && field === \"arguments\") {\n\t\t\tchanges.push({ type: \"toolcall_delta\", contentIndex, path: rest.slice(3), delta: op[2] });\n\t\t} else {\n\t\t\twhole.add(contentIndex);\n\t\t\tchanges.push({ type: \"block\", contentIndex, block: message.content[contentIndex]! });\n\t\t}\n\t}\n\treturn changes;\n}\n\n/** Output, details, and diagnostics changes of a running slot, from the view operations on it. */\nfunction toolUpdate(\n\tviewOps: readonly Op[],\n\tindex: number,\n\tslot: ToolSlot,\n\tprevious: ToolSlot,\n): Omit<Extract<AgentEvent, { type: \"tool_execution_update\" }>, \"type\" | \"toolCallId\" | \"toolName\"> | undefined {\n\tconst outputPath = [\"docs\", \"pi.live\", \"tools\", index, \"output\"];\n\tlet trimStart = 0;\n\tlet append = \"\";\n\tlet set = false;\n\tfor (const op of viewOps) {\n\t\tif (!startsWith(op[1] as Path, outputPath)) continue;\n\t\tif (op[0] === \"t\") trimStart += op[2];\n\t\telse if (op[0] === \"a\") append += op[2];\n\t\telse set = true;\n\t}\n\tlet output: { trimStart?: number; append?: string } | { set: string } | undefined;\n\tif (set || (slot.output !== previous.output && trimStart === 0 && append === \"\"))\n\t\toutput = { set: slot.output ?? \"\" };\n\telse if (trimStart > 0 || append !== \"\") {\n\t\toutput = { ...(trimStart > 0 ? { trimStart } : {}), ...(append === \"\" ? {} : { append }) };\n\t}\n\t// A safe replay clears a running slot's progress: removed details send `null`, removed diagnostics `[]`.\n\tconst update = {\n\t\t...(output === undefined ? {} : { output }),\n\t\t...(slot.details === previous.details ? {} : { details: slot.details ?? null }),\n\t\t...(slot.diagnostics === previous.diagnostics ? {} : { diagnostics: slot.diagnostics ?? [] }),\n\t};\n\treturn Object.keys(update).length === 0 ? undefined : update;\n}\n\nfunction startsWith(path: Path, prefix: readonly (string | number)[]): boolean {\n\treturn prefix.length <= path.length && prefix.every((segment, index) => path[index] === segment);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/harness/events.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAY3D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC,OAAO,EAAE,aAAa,EAAwB,MAAM,WAAW,CAAC;AAEhE,OAAO,EAAE,QAAQ,EAAmB,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAyB,iBAAiB,EAAE,MAAM,WAAW,CAAC;AA6GrE,SAAS,KAAK,CAAC,IAAsB;IACpC,OAAO;QACN,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAA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AC;QACzC,MAAM,GAAG,EAAE,GAAG,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;IAC5F,CAAC;IACD,yGAAyG;IACzG,MAAM,MAAM,GAAG;QACd,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC;QAC3C,GAAG,CAAC,IAAI,CAAC,OAAO,KAAK,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,IAAI,EAAE,CAAC;QAC/E,GAAG,CAAC,IAAI,CAAC,WAAW,KAAK,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,EAAE,EAAE,CAAC;KAC7F,CAAC;IACF,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC;AAC9D,CAAC;AAED,SAAS,UAAU,CAAC,IAAU,EAAE,MAAoC;IACnE,OAAO,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,OAAO,CAAC,CAAC;AAClG,CAAC","sourcesContent":["import type { Context, JsonValue } from \"@earendil-works/chord\";\nimport type { Op, Path } from \"@earendil-works/chord/delta\";\nimport type { AssistantMessage, Message, Usage } from \"@earendil-works/pi-ai\";\nimport { CommittedWatch } from \"../session/observation.ts\";\nimport type {\n\tCommitChange,\n\tCommitPublication,\n\tConversationId,\n\tEntryRecord,\n\tJsonObject,\n\tSubmissionId,\n\tSubmissionRecord,\n\tTaskId,\n\tWatchEnd,\n} from \"../types.ts\";\nimport { AgentDoc } from \"./agent.ts\";\nimport type { InboxItem, InboxState } from \"./inbox.ts\";\nimport type { CompactionFailure, CompactionStatus, LiveState, NestedToolSlot, ToolSlot } from \"./live.ts\";\nimport { NestedCallDoc, type NestedCallState } from \"./tool.ts\";\nimport type { AgentState, CompactionReason, Harness, NestedToolExecutionResult, ToolDiagnostic } from \"./types.ts\";\nimport { UsageDoc, type UsageState } from \"./usage.ts\";\nimport { scanAll } from \"./util.ts\";\nimport { type ConversationView, conversationViews } from \"./view.ts\";\n\ntype Block = AssistantMessage[\"content\"][number];\ntype QueuedItem = { id: SubmissionId; mode: InboxItem[\"mode\"] };\n\n/** One change to the in-flight assistant message, relative to that message. */\nexport type MessageChange =\n\t| { type: \"text_start\" | \"thinking_start\" | \"toolcall_start\"; contentIndex: number; block: Block }\n\t| { type: \"text_delta\" | \"thinking_delta\"; contentIndex: number; delta: string }\n\t| { type: \"toolcall_delta\"; contentIndex: number; path: readonly (string | number)[]; delta: string }\n\t| { type: \"block\"; contentIndex: number; block: Block }\n\t| { type: \"message\"; message: AssistantMessage };\n\nexport type SnapshotEvent = {\n\ttype: \"snapshot\";\n\tentries: readonly EntryRecord[];\n\trun?: { inputs: readonly SubmissionId[] };\n\t/** Current generation attempt: its in-flight partial, retry backoff, or deferred poll. */\n\tgeneration?: {\n\t\tattempt: number;\n\t\tmessage?: AssistantMessage;\n\t\tretry?: { at: number; error: string };\n\t\tdeferred?: { pollAt: number };\n\t};\n\ttools: readonly ToolSlot[];\n\t/** `pi.live.nestedTools`: nested calls of running tool calls. */\n\tnestedTools: readonly NestedToolSlot[];\n\t/** `pi.live.compactions`: live compactions with their attempt and retry backoff. */\n\tcompactions: readonly CompactionStatus[];\n\t/** `pi.live.compactionFailure`: the newest compaction failure since a compaction last produced a summary. */\n\tcompactionFailure?: CompactionFailure;\n\tinbox: readonly QueuedItem[];\n\t/** `pi.agent`; `{}` when absent. */\n\tagent: AgentState;\n\tusage: UsageState;\n};\n\n/** Experimental agent event, shaped like the coding agent's session events (spec §9.4). */\nexport type AgentEvent =\n\t| SnapshotEvent\n\t| { type: \"run_start\"; inputs: readonly SubmissionId[] }\n\t| { type: \"run_end\"; inputs: readonly SubmissionId[] }\n\t| { type: \"turn_start\" }\n\t| { type: \"turn_end\" }\n\t| { type: \"message_start\"; message: Message }\n\t/** `usage` is the partial's current usage, as in the coding agent's JSON mode. */\n\t| { type: \"message_update\"; usage: Usage; changes: readonly MessageChange[] }\n\t| { type: \"message_end\"; entry: EntryRecord }\n\t| ({ type: \"tool_execution_start\"; args: JsonObject } & ToolEventCall)\n\t| ({\n\t\t\ttype: \"tool_execution_update\";\n\t\t\t/** A front trim and then an append of the retained window, or its replacement. */\n\t\t\toutput?: { trimStart?: number; append?: string } | { set: string };\n\t\t\tdetails?: JsonValue;\n\t\t\tdiagnostics?: readonly ToolDiagnostic[];\n\t } & ToolEventCall)\n\t/**\n\t * A model-issued call ends with its result `entry`, a nested call with its `result`. Both are absent when the tool\n\t * task faulted or was orphaned, or when the call's slot left `pi.live` unfinished: its run ended, or its parent\n\t * settled first.\n\t */\n\t| ({ type: \"tool_execution_end\"; entry?: EntryRecord; result?: NestedToolExecutionResult } & ToolEventCall)\n\t| { type: \"inbox_update\"; items: readonly QueuedItem[] }\n\t| { type: \"submission\"; record: SubmissionRecord }\n\t| { type: \"auto_retry_start\"; attempt: number; at: number; errorMessage: string }\n\t| { type: \"auto_retry_end\"; attempt: number }\n\t| { type: \"deferred_poll\"; pollAt: number }\n\t| { type: \"entry_appended\"; entry: EntryRecord }\n\t| { type: \"agent_changed\"; agent: AgentState }\n\t| { type: \"usage_changed\"; usage: UsageState }\n\t| { type: \"task_failed\"; taskId: TaskId; kind: string; message: string }\n\t| { type: \"compaction_start\"; taskId: TaskId; reason: CompactionReason; blocking: boolean }\n\t/**\n\t * The task's receipt tells whether it produced a summary; the summary entry has its own events. `error` is set when\n\t * the compaction failed, faulted, or was orphaned, as in `pi.live.compactionFailure`.\n\t */\n\t| { type: \"compaction_end\"; taskId: TaskId; reason: CompactionReason; error?: string };\n\n/**\n * Which call a tool event is about. `toolCallId` is the call's ID in the transcript and in tool events: the provider's\n * ID for a model-issued call, `<parent call ID>/<key>` for a nested one. Match events by it; do not parse it. `taskId`\n * is the call's tool task, absent for a call that never got one (not offered, or not started in a sequential round).\n * A nested call also names the call that made it, by call ID and by tool task.\n */\nexport type ToolEventCall = {\n\ttoolCallId: string;\n\ttoolName: string;\n\ttaskId?: TaskId;\n\tparentToolCallId?: string;\n\tparentTaskId?: TaskId;\n};\n\n/** Serialized stream of one conversation's event batches, one per commit. */\nexport interface AgentEventStream {\n\t/** The `snapshot` event at attachment. */\n\treadonly snapshot: SnapshotEvent;\n\tstart(listener: (events: readonly AgentEvent[], context: Context) => Promise<void>): void;\n\tstop(): Promise<WatchEnd>;\n\treadonly closed: Promise<WatchEnd>;\n}\n\n/** The typed parts of a view the events read. */\ntype Parts = {\n\tlive: LiveState;\n\tinbox: InboxState | undefined;\n\tagent: AgentState | undefined;\n\tusage: UsageState | undefined;\n};\n\nfunction parts(view: ConversationView): Parts {\n\treturn {\n\t\tlive: (view.docs[\"pi.live\"] ?? {}) as LiveState,\n\t\tinbox: view.docs[\"pi.inbox\"] as InboxState | undefined,\n\t\tagent: view.docs[\"pi.agent\"] as AgentState | undefined,\n\t\tusage: view.docs[\"pi.usage\"] as UsageState | undefined,\n\t};\n}\n\nfunction snapshotOf(view: ConversationView): SnapshotEvent {\n\tconst { live, inbox, agent, usage } = parts(view);\n\treturn {\n\t\ttype: \"snapshot\",\n\t\tentries: view.entries,\n\t\t...(live.run === undefined ? {} : { run: { inputs: live.run.inputs } }),\n\t\t...(live.generation === undefined ? {} : { generation: live.generation as SnapshotEvent[\"generation\"] }),\n\t\ttools: live.tools ?? [],\n\t\tnestedTools: live.nestedTools ?? [],\n\t\tcompactions: live.compactions ?? [],\n\t\t...(live.compactionFailure === undefined ? {} : { compactionFailure: live.compactionFailure }),\n\t\tinbox: queued(inbox),\n\t\tagent: agent ?? AgentDoc.definition.initial(),\n\t\tusage: usage ?? UsageDoc.definition.initial(),\n\t};\n}\n\nfunction queued(inbox: InboxState | undefined): QueuedItem[] {\n\treturn (inbox?.items ?? []).map((item) => ({ id: item.id, mode: item.mode }));\n}\n\n/**\n * Experimental: attach to one conversation's agent events (spec §9.4). The snapshot and the registration for later\n * commits are captured atomically on the Session line; overflow replaces undelivered batches with one snapshot.\n */\nexport async function watchEvents(\n\tharness: Harness,\n\tconversationId: ConversationId,\n\tcontext: Context,\n): Promise<AgentEventStream> {\n\tconst views = conversationViews(harness);\n\tlet watch!: CommittedWatch<readonly AgentEvent[]>;\n\tlet snapshot!: SnapshotEvent;\n\tawait views.attach(\n\t\tconversationId,\n\t\tasync (initial, release, storage) => {\n\t\t\t// Generations whose held outcome already ended their turn, read on the line with the snapshot.\n\t\t\tconst query = { conversationId, kind: \"pi.generation\", status: \"completing\" } as const;\n\t\t\tconst completing = await scanAll((cursor) => storage.scanTasks(query, 100, cursor, context));\n\t\t\tconst held = new Set<TaskId>(completing.map((record) => record.id));\n\t\t\tlet current = initial;\n\t\t\tsnapshot = snapshotOf(initial);\n\t\t\t// Batches are the watch's values; an overflow delivers a snapshot of the newest view instead.\n\t\t\twatch = new CommittedWatch<readonly AgentEvent[]>(\n\t\t\t\t[],\n\t\t\t\trelease,\n\t\t\t\t(error) => views.report(error),\n\t\t\t\t() => [snapshotOf(current)],\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tpublication: (before, after, ops, publication, commitContext) => {\n\t\t\t\t\tcurrent = after;\n\t\t\t\t\tconst events = translate(conversationId, before, after, ops, publication, held);\n\t\t\t\t\tif (events.length > 0) watch.advance(events, [], commitContext);\n\t\t\t\t},\n\t\t\t\tcloseSession: (failure) => watch.closeSession(failure),\n\t\t\t};\n\t\t},\n\t\tcontext,\n\t);\n\t// Like a watch, the acquisition context governs the stream's lifetime.\n\tconst signal = context.abortSignal;\n\tif (signal?.aborted) {\n\t\twatch.cancel();\n\t\tthrow signal.reason;\n\t}\n\tif (signal !== undefined) watch.observeCancellation(signal);\n\treturn {\n\t\tsnapshot,\n\t\tstart: (listener) => watch.start((events, _ops, deliveryContext) => listener(events, deliveryContext)),\n\t\tstop: () => watch.stop(),\n\t\tclosed: watch.closed,\n\t};\n}\n\ntype TaskChange = Extract<CommitChange, { type: \"task\" }>;\n\n/** The tool result for `callId` among `entries`. */\nfunction resultOf(entries: readonly EntryRecord[], callId: string): EntryRecord | undefined {\n\treturn entries.find((entry) => {\n\t\tconst message = entry.model?.[0];\n\t\treturn message?.role === \"toolResult\" && message.toolCallId === callId;\n\t});\n}\n\n/** Every event one publication causes, in the order of spec §9.4. */\nfunction translate(\n\tconversationId: ConversationId,\n\tbefore: ConversationView,\n\tafter: ConversationView,\n\tviewOps: readonly Op[],\n\tpublication: CommitPublication,\n\theld: Set<TaskId>,\n): AgentEvent[] {\n\tconst entries: EntryRecord[] = [];\n\tconst tasks = new Map<TaskId, TaskChange[\"value\"]>();\n\tconst submissions: SubmissionRecord[] = [];\n\t// Nested results this commit stored, by nested task ID; read now, since the caller's documents may retire next.\n\tconst nestedResults = new Map<TaskId, NestedToolExecutionResult>();\n\tfor (const change of publication.changes) {\n\t\tif (\n\t\t\tchange.type === \"document\" &&\n\t\t\tchange.record.kind === NestedCallDoc.definition.kind &&\n\t\t\tchange.value !== null &&\n\t\t\tchange.conversationId === conversationId\n\t\t) {\n\t\t\tconst state = change.value as NestedCallState;\n\t\t\tif (state.taskId !== undefined && state.result !== undefined) {\n\t\t\t\tnestedResults.set(state.taskId, state.result as unknown as NestedToolExecutionResult);\n\t\t\t}\n\t\t}\n\t\tif (change.type === \"entry\" && change.value.conversationId === conversationId) entries.push(change.value);\n\t\tif (change.type === \"task\" && change.value.conversationId === conversationId)\n\t\t\ttasks.set(change.value.id, change.value);\n\t\tif (change.type === \"submission\" && change.value.conversationId === conversationId) {\n\t\t\tsubmissions.push(change.value);\n\t\t}\n\t}\n\tif (viewOps.length === 0 && entries.length === 0 && tasks.size === 0 && submissions.length === 0) return [];\n\t// Entries are appended in ID order; submission records are published in the order the commit first touched them.\n\tsubmissions.sort((a, b) => a.id - b.id);\n\tconst was = parts(before);\n\tconst now = parts(after);\n\tconst events: AgentEvent[] = [];\n\n\t// Progress: tool starts, the in-flight message, tool updates, retry and deferred state.\n\tconst slotsBefore = new Map((was.live.tools ?? []).map((slot) => [slot.callId, slot]));\n\tconst slots = now.live.tools ?? [];\n\tconst nestedBefore = new Map((was.live.nestedTools ?? []).map((slot) => [slot.taskId, slot]));\n\tconst nested = now.live.nestedTools ?? [];\n\tfor (const slot of [...slots, ...nested]) {\n\t\tconst previous = \"parentCallId\" in slot ? nestedBefore.get(slot.taskId) : slotsBefore.get(slot.callId);\n\t\tif (slot.status !== \"running\" || previous?.status === \"running\") continue;\n\t\t// A nested slot carries the arguments the call runs with; a model-issued call's are in its intent checkpoint.\n\t\tconst checkpoint = slot.taskId === undefined ? undefined : tasks.get(slot.taskId)?.state.checkpoint;\n\t\tconst args =\n\t\t\t\"parentCallId\" in slot\n\t\t\t\t? slot.arguments\n\t\t\t\t: ((checkpoint as { arguments?: JsonObject } | undefined)?.arguments ?? {});\n\t\tevents.push({ type: \"tool_execution_start\", ...callOf(slot), args });\n\t}\n\tconst partialBefore = was.live.generation?.message as AssistantMessage | undefined;\n\tconst partial = now.live.generation?.message as AssistantMessage | undefined;\n\tif (partial !== undefined && partialBefore === undefined) events.push({ type: \"message_start\", message: partial });\n\telse if (partial !== undefined && partial !== partialBefore) {\n\t\tevents.push({ type: \"message_update\", usage: partial.usage, changes: messageChanges(viewOps, partial) });\n\t}\n\tfor (const [index, slot] of slots.entries()) {\n\t\tconst previous = slotsBefore.get(slot.callId);\n\t\tif (slot.status !== \"running\" || previous?.status !== \"running\") continue;\n\t\tconst update = toolUpdate(viewOps, [\"tools\", index], slot, previous);\n\t\tif (update === undefined) continue;\n\t\tevents.push({ type: \"tool_execution_update\", ...callOf(slot), ...update });\n\t}\n\tfor (const [index, slot] of nested.entries()) {\n\t\tconst previous = nestedBefore.get(slot.taskId);\n\t\tif (slot.status !== \"running\" || previous?.status !== \"running\") continue;\n\t\tconst update = toolUpdate(viewOps, [\"nestedTools\", index], slot, previous);\n\t\tif (update === undefined) continue;\n\t\tevents.push({ type: \"tool_execution_update\", ...callOf(slot), ...update });\n\t}\n\tconst generation = now.live.generation;\n\tconst generationBefore = was.live.generation;\n\tif (generation?.retry !== undefined && generationBefore?.retry === undefined) {\n\t\tconst { at, error } = generation.retry;\n\t\tevents.push({ type: \"auto_retry_start\", attempt: generation.attempt, at, errorMessage: error });\n\t}\n\tif (generationBefore?.retry !== undefined && generation?.retry === undefined) {\n\t\tevents.push({ type: \"auto_retry_end\", attempt: generationBefore.attempt });\n\t}\n\tif (generation?.deferred !== undefined && generation.deferred.pollAt !== generationBefore?.deferred?.pollAt) {\n\t\tevents.push({ type: \"deferred_poll\", pollAt: generation.deferred.pollAt });\n\t}\n\n\t// Tools that end in this commit: a slot that becomes done, one created done (a call not offered), or an unfinished\n\t// one that vanishes because its run ended. A done slot that vanishes ended earlier.\n\tconst toolEnds: Extract<AgentEvent, { type: \"tool_execution_end\" }>[] = [];\n\tconst endTool = (slot: ToolSlot, entryId: number | undefined): void => {\n\t\tconst entry = entries.find((candidate) => candidate.id === entryId);\n\t\ttoolEnds.push({ type: \"tool_execution_end\", ...callOf(slot), ...(entry === undefined ? {} : { entry }) });\n\t};\n\tfor (const previous of slotsBefore.values()) {\n\t\tif (previous.status === \"done\") continue;\n\t\tconst slot = slots.find((candidate) => candidate.callId === previous.callId);\n\t\tif (slot?.status === \"done\") endTool(slot, slot.entry);\n\t\t// A slot whose run ended in this commit may have had its result appended with it, as for unstarted calls.\n\t\telse if (slot === undefined) endTool(previous, resultOf(entries, previous.callId)?.id);\n\t}\n\tfor (const slot of slots) {\n\t\tif (slot.status === \"done\" && !slotsBefore.has(slot.callId)) endTool(slot, slot.entry);\n\t}\n\t// Nested calls that end in this commit, the same way, children before the calls that made them: the lists hold\n\t// parents first, so walk them backwards.\n\tconst endNested = (slot: NestedToolSlot): void => {\n\t\tconst result = nestedResults.get(slot.taskId);\n\t\tevents.push({ type: \"tool_execution_end\", ...callOf(slot), ...(result === undefined ? {} : { result }) });\n\t};\n\tconst nestedNow = new Map(nested.map((slot) => [slot.taskId, slot]));\n\tfor (const previous of [...nestedBefore.values()].reverse()) {\n\t\tif (previous.status === \"done\") continue;\n\t\tconst slot = nestedNow.get(previous.taskId);\n\t\tif (slot?.status === \"done\" || slot === undefined) endNested(slot ?? previous);\n\t}\n\tfor (const slot of [...nested].reverse()) {\n\t\tif (slot.status === \"done\" && !nestedBefore.has(slot.taskId)) endNested(slot);\n\t}\n\n\t// Entries in append order; a tool's end directly precedes its result's message, as in the coding agent.\n\tlet assistantAppended = false;\n\tfor (const entry of entries) {\n\t\tevents.push(...toolEnds.filter((end) => end.entry === entry));\n\t\tconst message = entry.model?.[0];\n\t\tif (message === undefined) {\n\t\t\tevents.push({ type: \"entry_appended\", entry });\n\t\t\tcontinue;\n\t\t}\n\t\t// A streamed answer already started with its first partial.\n\t\tconst streamed = message.role === \"assistant\" && partialBefore !== undefined && !assistantAppended;\n\t\tif (message.role === \"assistant\") assistantAppended = true;\n\t\tif (!streamed) events.push({ type: \"message_start\", message });\n\t\tevents.push({ type: \"message_end\", entry });\n\t}\n\t// Ends without a result entry: a faulted or orphaned tool, or one whose run ended.\n\tevents.push(...toolEnds.filter((end) => end.entry === undefined));\n\n\t// Compaction ends, task failures, then turn and run ends.\n\tconst compactionsBefore = was.live.compactions ?? [];\n\tconst compactions = now.live.compactions ?? [];\n\tconst failure = now.live.compactionFailure;\n\tfor (const { taskId, reason } of compactionsBefore) {\n\t\tif (!compactions.some((status) => status.taskId === taskId)) {\n\t\t\tconst error = failure?.taskId === taskId ? failure.error : undefined;\n\t\t\tevents.push({ type: \"compaction_end\", taskId, reason, ...(error === undefined ? {} : { error }) });\n\t\t}\n\t}\n\t// A generation's turn ends when its outcome is committed: at a `completing` hold or at terminal, whichever comes\n\t// first, so a successor created at the hold starts after it.\n\tlet turnEnded = false;\n\tfor (const task of tasks.values()) {\n\t\tconst status = task.state.status;\n\t\tif (task.kind === \"pi.generation\" && status === \"completing\" && !held.has(task.id)) {\n\t\t\theld.add(task.id);\n\t\t\tturnEnded = true;\n\t\t}\n\t\tif (status !== \"terminal\") continue;\n\t\tif (task.kind === \"pi.generation\" && !held.delete(task.id)) turnEnded = true;\n\t\tconst outcome = task.state.outcome;\n\t\tif (outcome.status === \"faulted\" || outcome.status === \"orphaned\") {\n\t\t\tconst message = outcome.status === \"faulted\" ? outcome.error.message : outcome.reason;\n\t\t\tevents.push({ type: \"task_failed\", taskId: task.id, kind: task.kind, message });\n\t\t}\n\t}\n\tif (turnEnded) events.push({ type: \"turn_end\" });\n\tconst run = now.live.run;\n\tconst runBefore = was.live.run;\n\tconst runChanged = run?.inputs[0] !== runBefore?.inputs[0];\n\tif (runBefore !== undefined && runChanged) events.push({ type: \"run_end\", inputs: runBefore.inputs });\n\n\t// Submissions, document state, then what began.\n\tfor (const record of submissions) events.push({ type: \"submission\", record });\n\tif (now.inbox !== was.inbox) events.push({ type: \"inbox_update\", items: queued(now.inbox) });\n\t// A retired document reads as its initial value, as in a snapshot.\n\tif (now.agent !== was.agent) {\n\t\tevents.push({ type: \"agent_changed\", agent: now.agent ?? AgentDoc.definition.initial() });\n\t}\n\tif (now.usage !== was.usage)\n\t\tevents.push({ type: \"usage_changed\", usage: now.usage ?? UsageDoc.definition.initial() });\n\tfor (const { taskId, reason, blocking } of compactions) {\n\t\tif (!compactionsBefore.some((status) => status.taskId === taskId)) {\n\t\t\tevents.push({ type: \"compaction_start\", taskId, reason, blocking });\n\t\t}\n\t}\n\tif (run !== undefined && runChanged) events.push({ type: \"run_start\", inputs: run.inputs });\n\tif (run !== undefined && run.taskId !== runBefore?.taskId && tasks.get(run.taskId)?.kind === \"pi.generation\") {\n\t\tevents.push({ type: \"turn_start\" });\n\t}\n\treturn events;\n}\n\nconst PARTIAL_PATH = [\"docs\", \"pi.live\", \"generation\", \"message\"];\n\n/** Translate the view operations on the in-flight message into message changes (spec §9.4). */\nfunction messageChanges(viewOps: readonly Op[], message: AssistantMessage): MessageChange[] {\n\tconst changes: MessageChange[] = [];\n\t// A block sent whole already holds every later change to it in this batch.\n\tconst whole = new Set<number>();\n\tfor (const op of viewOps) {\n\t\t// View operations never replace the root.\n\t\tconst path = op[1] as Path;\n\t\tif (!startsWith(path, PARTIAL_PATH)) {\n\t\t\t// The whole message or generation was replaced.\n\t\t\tif (startsWith(PARTIAL_PATH, path)) return [{ type: \"message\", message }];\n\t\t\tcontinue;\n\t\t}\n\t\tconst rest = path.slice(PARTIAL_PATH.length);\n\t\tif (rest[0] === \"usage\") continue;\n\t\tif (rest[0] !== \"content\") return [{ type: \"message\", message }];\n\t\tif (rest.length === 1) {\n\t\t\tif (op[0] !== \"p\" || op[3] !== 0) return [{ type: \"message\", message }];\n\t\t\tfor (const [offset, block] of (op[4] as unknown as Block[]).entries()) {\n\t\t\t\tconst type =\n\t\t\t\t\tblock.type === \"text\" ? \"text_start\" : block.type === \"thinking\" ? \"thinking_start\" : \"toolcall_start\";\n\t\t\t\tchanges.push({ type, contentIndex: op[2] + offset, block });\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tconst contentIndex = rest[1] as number;\n\t\tconst field = rest[2];\n\t\tif (whole.has(contentIndex)) continue;\n\t\tif (op[0] === \"a\" && rest.length === 3 && (field === \"text\" || field === \"thinking\")) {\n\t\t\tchanges.push({ type: field === \"text\" ? \"text_delta\" : \"thinking_delta\", contentIndex, delta: op[2] });\n\t\t} else if (op[0] === \"a\" && field === \"arguments\") {\n\t\t\tchanges.push({ type: \"toolcall_delta\", contentIndex, path: rest.slice(3), delta: op[2] });\n\t\t} else {\n\t\t\twhole.add(contentIndex);\n\t\t\tchanges.push({ type: \"block\", contentIndex, block: message.content[contentIndex]! });\n\t\t}\n\t}\n\treturn changes;\n}\n\n/** The identifying fields of a slot's tool events. */\nfunction callOf(slot: ToolSlot | NestedToolSlot): ToolEventCall {\n\treturn {\n\t\ttoolCallId: slot.callId,\n\t\ttoolName: slot.name,\n\t\t...(slot.taskId === undefined ? {} : { taskId: slot.taskId }),\n\t\t...(\"parentCallId\" in slot ? { parentToolCallId: slot.parentCallId, parentTaskId: slot.parentTaskId } : {}),\n\t};\n}\n\n/** Output, details, and diagnostics changes of a running slot at `at` in `pi.live`, from the view operations on it. */\nfunction toolUpdate(\n\tviewOps: readonly Op[],\n\tat: readonly [\"tools\" | \"nestedTools\", number],\n\tslot: ToolSlot | NestedToolSlot,\n\tprevious: ToolSlot | NestedToolSlot,\n): Omit<Extract<AgentEvent, { type: \"tool_execution_update\" }>, \"type\" | keyof ToolEventCall> | undefined {\n\tconst outputPath = [\"docs\", \"pi.live\", ...at, \"output\"];\n\tlet trimStart = 0;\n\tlet append = \"\";\n\tlet set = false;\n\tfor (const op of viewOps) {\n\t\tif (!startsWith(op[1] as Path, outputPath)) continue;\n\t\tif (op[0] === \"t\") trimStart += op[2];\n\t\telse if (op[0] === \"a\") append += op[2];\n\t\telse set = true;\n\t}\n\tlet output: { trimStart?: number; append?: string } | { set: string } | undefined;\n\tif (set || (slot.output !== previous.output && trimStart === 0 && append === \"\"))\n\t\toutput = { set: slot.output ?? \"\" };\n\telse if (trimStart > 0 || append !== \"\") {\n\t\toutput = { ...(trimStart > 0 ? { trimStart } : {}), ...(append === \"\" ? {} : { append }) };\n\t}\n\t// A safe replay clears a running slot's progress: removed details send `null`, removed diagnostics `[]`.\n\tconst update = {\n\t\t...(output === undefined ? {} : { output }),\n\t\t...(slot.details === previous.details ? {} : { details: slot.details ?? null }),\n\t\t...(slot.diagnostics === previous.diagnostics ? {} : { diagnostics: slot.diagnostics ?? [] }),\n\t};\n\treturn Object.keys(update).length === 0 ? undefined : update;\n}\n\nfunction startsWith(path: Path, prefix: readonly (string | number)[]): boolean {\n\treturn prefix.length <= path.length && prefix.every((segment, index) => path[index] === segment);\n}\n"]}
|
|
@@ -12,6 +12,8 @@ export type GenerationCheckpoint = {
|
|
|
12
12
|
compacted?: TaskId<CompactionResult>;
|
|
13
13
|
/** Error text of the overflow that started `compacted`; checked once when `prepare` resumes. */
|
|
14
14
|
overflow?: string;
|
|
15
|
+
/** Set when the blocking threshold started `compacted`; its outcome is checked once when `prepare` resumes. */
|
|
16
|
+
threshold?: true;
|
|
15
17
|
} | {
|
|
16
18
|
phase: "request";
|
|
17
19
|
attempt: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generation.d.ts","sourceRoot":"","sources":["../../src/harness/generation.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,KAAK,EAAkB,MAAM,uBAAuB,CAAC;AAC3F,OAAO,KAAK,EAGX,cAAc,EAGd,kBAAkB,EAGlB,MAAM,uBAAuB,CAAC;AAO/B,OAAO,KAAK,EACX,cAAc,EACd,OAAO,EAEP,YAAY,EACZ,MAAM,
|
|
1
|
+
{"version":3,"file":"generation.d.ts","sourceRoot":"","sources":["../../src/harness/generation.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,KAAK,EAAkB,MAAM,uBAAuB,CAAC;AAC3F,OAAO,KAAK,EAGX,cAAc,EAGd,kBAAkB,EAGlB,MAAM,uBAAuB,CAAC;AAO/B,OAAO,KAAK,EACX,cAAc,EACd,OAAO,EAEP,YAAY,EACZ,MAAM,EAGN,EAAE,EAEF,MAAM,aAAa,CAAC;AAKrB,OAAO,EAAmB,KAAK,SAAS,EAAiB,MAAM,WAAW,CAAC;AAG3E,OAAO,EAA4C,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAC1F,OAAO,KAAK,EAEX,gBAAgB,EAEhB,yB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CAAC,EAAE,CAAC;IAChC,kEAAkE;IAClE,OAAO,EAAE,MAAM,EAAE,CAAC;CACjB,CAAC;AAEL,MAAM,MAAM,gBAAgB,GAAG;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAmBpD;;;GAGG;AACH,eAAO,MAAM,cAAc,sGAgLzB,CAAC;AAmFH;;;GAGG;AACH,wBAAsB,cAAc,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,EAAE,cAAc,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAKlH;AAuTD,gGAAgG;AAChG,wBAAsB,QAAQ,CAC7B,EAAE,EAAE,EAAE,EACN,cAAc,EAAE,cAAc,EAC9B,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,EACtB,MAAM,EAAE,YAAY,EAAE,GACpB,OAAO,CAAC,IAAI,CAAC,CAEf;AAOD,2EAA2E;AAC3E,wBAAgB,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAE/E"}
|
|
@@ -25,8 +25,9 @@ export const GenerationTask = defineTask({
|
|
|
25
25
|
phases: {
|
|
26
26
|
/**
|
|
27
27
|
* Render the system prompt and tool loadout and append the positional `pi.system` entries they need, then move to
|
|
28
|
-
* `request`. The agent and settings resolved here are fixed for this request. Only the Harness writes
|
|
29
|
-
* conversation, so the
|
|
28
|
+
* `request`. The agent and settings resolved here are fixed for this request. Only the Harness writes model
|
|
29
|
+
* context to a busy conversation, so the context read here is still current at the commit; display-only entries
|
|
30
|
+
* may land meanwhile.
|
|
30
31
|
*/
|
|
31
32
|
prepare: async (task, runtime, context) => {
|
|
32
33
|
const { conversationId } = runtime;
|
|
@@ -36,13 +37,21 @@ export const GenerationTask = defineTask({
|
|
|
36
37
|
const resolved = model === undefined ? undefined : runtime.models.getModel(model.provider, model.modelId);
|
|
37
38
|
if (model === undefined || resolved === undefined)
|
|
38
39
|
return failNoModel(runtime, model, context);
|
|
39
|
-
const { attempt, compacted, overflow } = task.state.checkpoint;
|
|
40
|
+
const { attempt, compacted, overflow, threshold: blocked } = task.state.checkpoint;
|
|
40
41
|
if (compacted !== undefined && overflow !== undefined) {
|
|
41
42
|
const [outcome] = await runtime.outcomes([compacted], context);
|
|
42
43
|
if (outcome?.status !== "completed" || outcome.result.entryId === undefined) {
|
|
43
44
|
return failModelError(runtime, overflow, context);
|
|
44
45
|
}
|
|
45
46
|
}
|
|
47
|
+
// A threshold compaction that found nothing to compact or was declined leaves a request that may still fit. One
|
|
48
|
+
// that failed left a context it judged too large: sending it would at best leave no room for the answer.
|
|
49
|
+
if (compacted !== undefined && blocked === true) {
|
|
50
|
+
const [outcome] = await runtime.outcomes([compacted], context);
|
|
51
|
+
if (outcome !== undefined && outcome.status !== "completed") {
|
|
52
|
+
return failModelError(runtime, compactionFailure(outcome), context);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
46
55
|
const view = await runtime.context(conversationId, context);
|
|
47
56
|
const shown = replaySections(view.messages);
|
|
48
57
|
const report = (error) => runtime.report(error);
|
|
@@ -65,7 +74,7 @@ export const GenerationTask = defineTask({
|
|
|
65
74
|
// Compact first and prepare again; the transcript is unchanged until the compaction appends.
|
|
66
75
|
await runtime.commit(async (tx) => {
|
|
67
76
|
const child = await createCompaction(tx, conversationId, { reason: "threshold" }, runtime.taskId);
|
|
68
|
-
const checkpoint = { phase: "prepare", attempt, compacted: child };
|
|
77
|
+
const checkpoint = { phase: "prepare", attempt, compacted: child, threshold: true };
|
|
69
78
|
return { status: "waiting", checkpoint, on: [child], policy: "allSettled" };
|
|
70
79
|
}, context);
|
|
71
80
|
return;
|
|
@@ -188,7 +197,7 @@ export const GenerationTask = defineTask({
|
|
|
188
197
|
await convertPartial(tx, live, conversationId);
|
|
189
198
|
for (const call of unstarted) {
|
|
190
199
|
const result = harnessError("aborted", `Tool ${call.name} was aborted`);
|
|
191
|
-
await appendToolResult(tx, conversationId, call, result, runtime.now());
|
|
200
|
+
await appendToolResult(tx, conversationId, call, result, { timestamp: runtime.now() });
|
|
192
201
|
}
|
|
193
202
|
endRun(tx, live, runtime.taskId, { status: "unanswered", reason: "aborted" });
|
|
194
203
|
return { status: "terminal", outcome: { status: "aborted" } };
|
|
@@ -203,7 +212,7 @@ async function readCalls(runtime, assistant, callIds, context) {
|
|
|
203
212
|
}
|
|
204
213
|
/** A tool task for call `callId`, owned by the generation. */
|
|
205
214
|
function createToolTask(tx, runtime, assistant, callId) {
|
|
206
|
-
return tx.createTask(ToolTask, { assistant, callId }, { ownership: { kind: "task", taskId: runtime.taskId } });
|
|
215
|
+
return tx.createTask(ToolTask, { kind: "model", assistant, callId }, { ownership: { kind: "task", taskId: runtime.taskId } });
|
|
207
216
|
}
|
|
208
217
|
/**
|
|
209
218
|
* Which threshold compaction preparation starts before its request (spec §8.3): `blocking` above
|
|
@@ -221,6 +230,18 @@ function thresholdCompaction(view, planned, contextWindow, policy) {
|
|
|
221
230
|
return undefined;
|
|
222
231
|
return over;
|
|
223
232
|
}
|
|
233
|
+
/** Error text for a generation whose blocking compaction ended without completing. */
|
|
234
|
+
function compactionFailure(outcome) {
|
|
235
|
+
switch (outcome.status) {
|
|
236
|
+
case "failed":
|
|
237
|
+
case "faulted":
|
|
238
|
+
return `Compaction failed: ${outcome.error.message}`;
|
|
239
|
+
case "orphaned":
|
|
240
|
+
return `Compaction failed: ${outcome.reason}`;
|
|
241
|
+
case "aborted":
|
|
242
|
+
return "Compaction was aborted";
|
|
243
|
+
}
|
|
244
|
+
}
|
|
224
245
|
/** Settle the run's inputs `unanswered` with `model_error` and fail with `text`. */
|
|
225
246
|
async function failModelError(runtime, text, context) {
|
|
226
247
|
await runtime.commit(async (tx) => {
|
|
@@ -444,7 +465,7 @@ async function startToolRound(runtime, request, message, calls, context) {
|
|
|
444
465
|
for (const call of calls) {
|
|
445
466
|
if (!offered.has(call.name)) {
|
|
446
467
|
const unavailable = harnessError("tool_unavailable", `Tool ${call.name} is not available`);
|
|
447
|
-
const result = await appendToolResult(tx, conversationId, call, unavailable, runtime.now());
|
|
468
|
+
const result = await appendToolResult(tx, conversationId, call, unavailable, { timestamp: runtime.now() });
|
|
448
469
|
slots.push({ callId: call.id, name: call.name, status: "done", entry: result.id });
|
|
449
470
|
continue;
|
|
450
471
|
}
|
|
@@ -473,7 +494,8 @@ async function finishToolRound(runtime, assistant, tools, context) {
|
|
|
473
494
|
const outcomes = await runtime.outcomes(tools, context);
|
|
474
495
|
tools.forEach((id, index) => {
|
|
475
496
|
const outcome = outcomes[index];
|
|
476
|
-
|
|
497
|
+
// Version 1 results have no kind; every result a generation's round reads is a model-issued call's.
|
|
498
|
+
controls.set(id, outcome.status === "completed" && outcome.result.kind !== "nested" ? outcome.result.control : undefined);
|
|
477
499
|
});
|
|
478
500
|
const slots = (await runtime.snapshot(LiveDoc, conversationId, context))?.tools ?? [];
|
|
479
501
|
const results = slots.flatMap((slot) => (slot.entry === undefined ? [] : [slot.entry]));
|
|
@@ -511,6 +533,7 @@ async function finishToolRound(runtime, assistant, tools, context) {
|
|
|
511
533
|
}
|
|
512
534
|
else {
|
|
513
535
|
delete live.tools;
|
|
536
|
+
delete live.nestedTools;
|
|
514
537
|
if (live.run?.taskId === runtime.taskId)
|
|
515
538
|
live.run.inputs.push(...users);
|
|
516
539
|
handOver(live, runtime.taskId, await createGeneration(tx, conversationId));
|