effect-durable-agent 0.1.0-alpha.9 → 0.2.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 +5 -5
- package/dist/assert-never-CoyUpoRB.js +18 -0
- package/dist/assert-never-CoyUpoRB.js.map +1 -0
- package/dist/{commands-Ce1ec6kH.d.ts → commands-BUquEZVP.d.ts} +31 -12
- package/dist/{compaction-BgDr5VJy.js → compaction-D7WJa899.js} +63 -13
- package/dist/compaction-D7WJa899.js.map +1 -0
- package/dist/{context-projection-n6Rdup0N.d.ts → context-projection-Bezx3drD.d.ts} +16 -40
- package/dist/{core-CYT6DBaS.d.ts → core-BcimKMIv.d.ts} +5 -3
- package/dist/delivery-B_LDTuIB.d.ts +3169 -0
- package/dist/delivery-BoF-NZbZ.js +507 -0
- package/dist/delivery-BoF-NZbZ.js.map +1 -0
- package/dist/domain/command-queues.d.ts +81 -2
- package/dist/domain/command-queues.js +1 -1
- package/dist/domain/command-queues.js.map +1 -1
- package/dist/domain/context-projection.d.ts +1 -1
- package/dist/domain/context-projection.js +1 -1
- package/dist/domain/context-projection.js.map +1 -1
- package/dist/domain/message-transcript.d.ts +36 -2
- package/dist/domain/message-transcript.js +10 -2
- package/dist/domain/message-transcript.js.map +1 -1
- package/dist/domain/model-usage.d.ts +1 -1
- package/dist/domain/model-usage.js +1 -1
- package/dist/domain/reduced-state-schema.d.ts +3 -992
- package/dist/domain/reduced-state-schema.js +126 -7
- package/dist/domain/reduced-state-schema.js.map +1 -1
- package/dist/domain/reduced-state.d.ts +2 -2
- package/dist/domain/reduced-state.js +937 -2
- package/dist/domain/reduced-state.js.map +1 -0
- package/dist/domain/run-scheduling.d.ts +2 -0
- package/dist/domain/run-scheduling.js +127 -0
- package/dist/domain/run-scheduling.js.map +1 -0
- package/dist/{durable-br2C1bWK.d.ts → durable-BXqwM70o.d.ts} +8983 -2800
- package/dist/{durable-BGFvX7Mh.js → durable-Da57Rcml.js} +243 -15
- package/dist/durable-Da57Rcml.js.map +1 -0
- package/dist/{envelope-DxQzo5rN.js → envelope-BSI_Xh-f.js} +31 -6
- package/dist/envelope-BSI_Xh-f.js.map +1 -0
- package/dist/{envelope-DkZyMIgp.d.ts → envelope-CJnPfbjC.d.ts} +121 -11
- package/dist/{event-factory-DTFdy0Cb.js → event-factory-BUoBwqAy.js} +7 -3
- package/dist/event-factory-BUoBwqAy.js.map +1 -0
- package/dist/{events-LZFNoESe.d.ts → events-AIIwZ6dS.d.ts} +139 -137
- package/dist/{id-generator-Ckl8_XWW.d.ts → id-generator-BKGoKjt-.d.ts} +3 -3
- package/dist/in-memory-E497WhtS.js +150 -0
- package/dist/in-memory-E497WhtS.js.map +1 -0
- package/dist/index.d.ts +8 -8
- package/dist/index.js +6 -6
- package/dist/interpreter-BwYN2PCC.js +1453 -0
- package/dist/interpreter-BwYN2PCC.js.map +1 -0
- package/dist/{keep-alive-Chl5SJxy.d.ts → keep-alive-_zFCUvt3.d.ts} +1 -2
- package/dist/{model-resolver-BPPJAsuh.d.ts → model-resolver-O8Kn27GH.d.ts} +11 -5
- package/dist/{model-usage-CdBEkTwU.d.ts → model-usage-mttrPN0j.d.ts} +2 -3
- package/dist/records-D0ZIAOzd.js +675 -0
- package/dist/records-D0ZIAOzd.js.map +1 -0
- package/dist/reduced-state-YbjpihEf.d.ts +52933 -0
- package/dist/reduced-state-schema-B9TYxkP9.d.ts +2338 -0
- package/dist/{reducer-registry-aFjz_ZLT.d.ts → reducer-registry-Bqn5B4JO.d.ts} +12 -6
- package/dist/run-scheduling-wakeup-DX2zRAxd.d.ts +24 -0
- package/dist/services/compaction.d.ts +2 -2
- package/dist/services/compaction.js +2 -2
- package/dist/services/decider.d.ts +2 -0
- package/dist/services/decider.js +97 -0
- package/dist/services/decider.js.map +1 -0
- package/dist/services/id-generator.d.ts +1 -1
- package/dist/services/id-generator.js +6 -12
- package/dist/services/id-generator.js.map +1 -1
- package/dist/services/keep-alive.d.ts +1 -1
- package/dist/services/keep-alive.js.map +1 -1
- package/dist/services/model-call.d.ts +15 -0
- package/dist/services/model-call.js +15 -0
- package/dist/services/model-call.js.map +1 -0
- package/dist/services/model-resolver.d.ts +1 -1
- package/dist/services/model-resolver.js +1 -1
- package/dist/services/model-resolver.js.map +1 -1
- package/dist/services/prompt-projector.d.ts +2 -2
- package/dist/services/prompt-projector.js +49 -5
- package/dist/services/prompt-projector.js.map +1 -1
- package/dist/services/reducer-registry.d.ts +1 -1
- package/dist/services/reducer-registry.js +19 -6
- package/dist/services/reducer-registry.js.map +1 -1
- package/dist/services/run-scheduler.d.ts +2 -2
- package/dist/services/run-scheduler.js +25 -2
- package/dist/services/run-scheduler.js.map +1 -0
- package/dist/services/run-scheduling-wakeup.d.ts +2 -0
- package/dist/services/run-scheduling-wakeup.js +13 -0
- package/dist/services/run-scheduling-wakeup.js.map +1 -0
- package/dist/services/runtime-layer.d.ts +21 -33
- package/dist/services/runtime-layer.js +24 -16
- package/dist/services/runtime-layer.js.map +1 -1
- package/dist/services/runtime.d.ts +1 -1
- package/dist/services/runtime.js +32 -20
- package/dist/services/runtime.js.map +1 -1
- package/dist/services/session-event-observer.d.ts +1 -1
- package/dist/services/session-event-observer.js.map +1 -1
- package/dist/services/session-query.d.ts +1 -1
- package/dist/services/session-query.js +57 -10
- package/dist/services/session-query.js.map +1 -1
- package/dist/services/session-state.d.ts +2 -2
- package/dist/services/session-state.js +2 -1
- package/dist/services/session-store.d.ts +2 -2
- package/dist/services/session-store.js +143 -38
- package/dist/services/session-store.js.map +1 -1
- package/dist/services/sink-checkpoint-store.d.ts +1 -1
- package/dist/services/sink-checkpoint-store.js +2 -1
- package/dist/services/sink-checkpoint-store.js.map +1 -1
- package/dist/services/sink-registry.d.ts +2 -2
- package/dist/services/sink-registry.js +1 -1
- package/dist/services/span-names.d.ts +1 -1
- package/dist/services/span-names.js +7 -1
- package/dist/services/span-names.js.map +1 -1
- package/dist/services/tool-registry.d.ts +2 -2
- package/dist/services/tool-registry.js +12 -3
- package/dist/services/tool-registry.js.map +1 -1
- package/dist/services/tracing.d.ts +3 -3
- package/dist/services/tracing.js +2 -2
- package/dist/services/tracing.js.map +1 -1
- package/dist/session-admission-WE8J_0z9.js +138 -0
- package/dist/session-admission-WE8J_0z9.js.map +1 -0
- package/dist/{session-event-observer-DaFMKKNc.d.ts → session-event-observer-BWQUJTcN.d.ts} +3 -3
- package/dist/{session-state-Bkc6u-Wr.js → session-state-D02LCVcC.js} +815 -170
- package/dist/session-state-D02LCVcC.js.map +1 -0
- package/dist/session-store-DaSHeg8Q.d.ts +3343 -0
- package/dist/{sink-checkpoint-store-M7qIxoSH.d.ts → sink-checkpoint-store-CUvIVvlZ.d.ts} +3 -4
- package/dist/sink-registry-AOjX5_A1.js +369 -0
- package/dist/sink-registry-AOjX5_A1.js.map +1 -0
- package/dist/subscription-BhwUmsl4.d.ts +966 -0
- package/dist/subscription-D7U4Tziv.js +505 -0
- package/dist/subscription-D7U4Tziv.js.map +1 -0
- package/dist/testkit/layers.d.ts +33 -23
- package/dist/testkit/layers.js +34 -19
- package/dist/testkit/layers.js.map +1 -1
- package/dist/testkit/transcript.d.ts +232 -0
- package/dist/testkit/transcript.js +1526 -0
- package/dist/testkit/transcript.js.map +1 -0
- package/dist/{tracing-BXHAkxkx.d.ts → tracing-BwjbF285.d.ts} +1 -2
- package/dist/transcript.d.ts +101 -0
- package/dist/transcript.js +107 -0
- package/dist/transcript.js.map +1 -0
- package/dist/types/commands.d.ts +2 -2
- package/dist/types/commands.js +8 -3
- package/dist/types/commands.js.map +1 -1
- package/dist/types/core.d.ts +2 -2
- package/dist/types/core.js +3 -1
- package/dist/types/core.js.map +1 -1
- package/dist/types/events/durable.d.ts +2 -2
- package/dist/types/events/durable.js +2 -2
- package/dist/types/events.d.ts +5 -5
- package/dist/types/events.js +3 -3
- package/dist/types/tracing.d.ts +1 -1
- package/dist/types/tracing.js.map +1 -1
- package/dist/websocket/events.d.ts +2 -0
- package/dist/websocket/events.js +2 -0
- package/dist/websocket.d.ts +2123 -2552
- package/dist/websocket.js +628 -442
- package/dist/websocket.js.map +1 -1
- package/dist/window-read-BELSkO-r.d.ts +113 -0
- package/dist/window-read-FJTCDaSq.js +264 -0
- package/dist/window-read-FJTCDaSq.js.map +1 -0
- package/package.json +41 -13
- package/dist/command-queues-DdDB_aYM.d.ts +0 -462
- package/dist/compaction-BgDr5VJy.js.map +0 -1
- package/dist/compaction-ch8z6G9x.d.ts +0 -165
- package/dist/durable-BGFvX7Mh.js.map +0 -1
- package/dist/envelope-DxQzo5rN.js.map +0 -1
- package/dist/event-factory-DTFdy0Cb.js.map +0 -1
- package/dist/event-factory-Di1jwQvm.d.ts +0 -87
- package/dist/index-BVVgDSdq.d.ts +0 -1
- package/dist/message-transcript-DQNlzxle.d.ts +0 -32
- package/dist/prompt-projector-f4ElyXCE.d.ts +0 -39
- package/dist/reduced-state-DF0-6mbR.js +0 -921
- package/dist/reduced-state-DF0-6mbR.js.map +0 -1
- package/dist/run-scheduler-CAt7dF6C.js +0 -21
- package/dist/run-scheduler-CAt7dF6C.js.map +0 -1
- package/dist/run-scheduler-xkhZyto5.d.ts +0 -44
- package/dist/runtime-DDSYP9jS.d.ts +0 -63
- package/dist/session-query-B72HY_0L.d.ts +0 -45
- package/dist/session-state-Bkc6u-Wr.js.map +0 -1
- package/dist/session-state-C9YLSAso.d.ts +0 -862
- package/dist/session-store-Cpi_NwTR.d.ts +0 -206
- package/dist/sink-registry-Bl-vQES6.d.ts +0 -133
- package/dist/sink-registry-NDgeyzO0.js +0 -272
- package/dist/sink-registry-NDgeyzO0.js.map +0 -1
- package/dist/tool-registry-BJaVNtw4.d.ts +0 -51
|
@@ -0,0 +1,1526 @@
|
|
|
1
|
+
import { SequenceNumber, SessionId, durablePosition } from "../types/core.js";
|
|
2
|
+
import { makeEDATraceContext } from "../types/tracing.js";
|
|
3
|
+
import { y as effectDurableAgentNamespace } from "../envelope-BSI_Xh-f.js";
|
|
4
|
+
import { qn as decodeDurableEventSync } from "../durable-Da57Rcml.js";
|
|
5
|
+
import { m as makeTranscriptDefinition, p as emptyTranscriptMappings } from "../interpreter-BwYN2PCC.js";
|
|
6
|
+
import { A as TranscriptRecordFromEnvelope } from "../records-D0ZIAOzd.js";
|
|
7
|
+
import { n as emptyTranscriptVersion, t as advanceTranscriptVersion } from "../in-memory-E497WhtS.js";
|
|
8
|
+
import * as Effect from "effect/Effect";
|
|
9
|
+
import * as Schema from "effect/Schema";
|
|
10
|
+
import * as Prompt from "effect/ai/Prompt";
|
|
11
|
+
//#region src/transcript/transcript-testkit.ts
|
|
12
|
+
/**
|
|
13
|
+
* Test-only builders for transcript interpretation: deterministic ids, a log writer that goes
|
|
14
|
+
* through the real durable decoders, and helpers that project and normalize logs.
|
|
15
|
+
*/
|
|
16
|
+
const traceContext = makeEDATraceContext({
|
|
17
|
+
traceId: "0123456789abcdef0123456789abcdef",
|
|
18
|
+
spanId: "0123456789abcdef"
|
|
19
|
+
});
|
|
20
|
+
/** The encoded trace every test event carries. */
|
|
21
|
+
const testEventTrace = {
|
|
22
|
+
span: traceContext,
|
|
23
|
+
links: []
|
|
24
|
+
};
|
|
25
|
+
const runTrace = {
|
|
26
|
+
root: traceContext,
|
|
27
|
+
links: []
|
|
28
|
+
};
|
|
29
|
+
/** Deterministic UUIDv7-shaped id; `space` keeps identities of different kinds apart. */
|
|
30
|
+
const testId = (space, slot) => `018f6bd5-2f2a-7${space.toString(16).padStart(3, "0")}-8${(slot >> 48).toString(16).padStart(3, "0")}-${(slot % 2 ** 48).toString(16).padStart(12, "0")}`;
|
|
31
|
+
const ids = {
|
|
32
|
+
command: (slot) => testId(257, slot),
|
|
33
|
+
message: (slot) => testId(258, slot),
|
|
34
|
+
run: (slot) => testId(259, slot),
|
|
35
|
+
turn: (slot) => testId(260, slot),
|
|
36
|
+
inference: (slot) => testId(261, slot),
|
|
37
|
+
tool: (slot) => testId(262, slot),
|
|
38
|
+
compaction: (slot) => testId(263, slot),
|
|
39
|
+
summary: (slot) => testId(264, slot),
|
|
40
|
+
event: (slot) => testId(265, slot)
|
|
41
|
+
};
|
|
42
|
+
const testSessionId = SessionId.make(testId(256, 1));
|
|
43
|
+
const testModel = {
|
|
44
|
+
provider: "test",
|
|
45
|
+
modelId: "model-a"
|
|
46
|
+
};
|
|
47
|
+
const summaryPromptMessage = (text) => Schema.encodeSync(Prompt.UserMessage)(Prompt.makeMessage("user", { content: [Prompt.textPart({ text })] }));
|
|
48
|
+
/**
|
|
49
|
+
* Append-only test log. Every event is built as a raw envelope and decoded through the store's
|
|
50
|
+
* durable decoder, so tests exercise the same shapes the interpreter receives in production.
|
|
51
|
+
*/
|
|
52
|
+
var TestLog = class {
|
|
53
|
+
events = [];
|
|
54
|
+
envelopes = [];
|
|
55
|
+
nextEvent = 1;
|
|
56
|
+
/** The raw envelopes, for seeding an in-memory store. */
|
|
57
|
+
get durableEnvelopes() {
|
|
58
|
+
return this.envelopes;
|
|
59
|
+
}
|
|
60
|
+
append(type, payload, namespace = effectDurableAgentNamespace, dedupeKey) {
|
|
61
|
+
const slot = this.nextEvent++;
|
|
62
|
+
const raw = {
|
|
63
|
+
...dedupeKey === void 0 ? {} : { dedupeKey },
|
|
64
|
+
namespace,
|
|
65
|
+
type,
|
|
66
|
+
schemaVersion: 1,
|
|
67
|
+
durability: "durable",
|
|
68
|
+
eventId: ids.event(slot),
|
|
69
|
+
sessionId: testSessionId,
|
|
70
|
+
createdAtMs: 176e10 + slot * 1e3,
|
|
71
|
+
trace: testEventTrace,
|
|
72
|
+
payload
|
|
73
|
+
};
|
|
74
|
+
const event = decodeDurableEventSync(raw);
|
|
75
|
+
const envelope = event.namespace === "__foreign" ? event.envelope : event;
|
|
76
|
+
this.envelopes.push(envelope);
|
|
77
|
+
this.events.push({
|
|
78
|
+
position: durablePosition(SequenceNumber.make(this.events.length + 1)),
|
|
79
|
+
event
|
|
80
|
+
});
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
appendForeign(namespace, type, payload) {
|
|
84
|
+
return this.append(type, payload, namespace);
|
|
85
|
+
}
|
|
86
|
+
configure() {
|
|
87
|
+
return this.append("SessionConfigured", { modelSelection: testModel });
|
|
88
|
+
}
|
|
89
|
+
/** A decider's acceptance marker, as `decide` commits it first in its batch. */
|
|
90
|
+
deciderAccepted(input) {
|
|
91
|
+
return this.append("DeciderAccepted", {
|
|
92
|
+
decider: input.decider,
|
|
93
|
+
idempotencyKey: input.key,
|
|
94
|
+
result: input.result
|
|
95
|
+
}, effectDurableAgentNamespace, `${input.decider}\n${input.key}`);
|
|
96
|
+
}
|
|
97
|
+
/** Command admission plus the submitted message, as session ingress writes them. */
|
|
98
|
+
submit(input) {
|
|
99
|
+
const disposition = input.disposition ?? "queue";
|
|
100
|
+
this.append("CommandAdmitted", { command: {
|
|
101
|
+
_tag: "SubmitMessage",
|
|
102
|
+
commandId: ids.command(input.command),
|
|
103
|
+
disposition,
|
|
104
|
+
content: input.text,
|
|
105
|
+
...input.idempotencyKey === void 0 ? {} : { idempotencyKey: input.idempotencyKey }
|
|
106
|
+
} });
|
|
107
|
+
return this.append("UserMessageSubmitted", {
|
|
108
|
+
commandId: ids.command(input.command),
|
|
109
|
+
messageId: ids.message(input.message),
|
|
110
|
+
disposition,
|
|
111
|
+
content: input.text
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/** A legacy or interrupt-path admission: the message is committed when the command starts. */
|
|
115
|
+
admitOnly(input) {
|
|
116
|
+
return this.append("CommandAdmitted", { command: {
|
|
117
|
+
_tag: "SubmitMessage",
|
|
118
|
+
commandId: ids.command(input.command),
|
|
119
|
+
disposition: "interrupt",
|
|
120
|
+
content: input.text,
|
|
121
|
+
...input.idempotencyKey === void 0 ? {} : { idempotencyKey: input.idempotencyKey }
|
|
122
|
+
} });
|
|
123
|
+
}
|
|
124
|
+
commitUser(input) {
|
|
125
|
+
return this.append("UserMessageCommitted", {
|
|
126
|
+
commandId: ids.command(input.command),
|
|
127
|
+
messageId: ids.message(input.message),
|
|
128
|
+
content: input.text
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
startRun(input) {
|
|
132
|
+
for (const command of input.commands) this.append("CommandStarted", { commandId: ids.command(command) });
|
|
133
|
+
return this.runStarted(input);
|
|
134
|
+
}
|
|
135
|
+
runStarted(input) {
|
|
136
|
+
return this.append("RunStarted", {
|
|
137
|
+
runId: ids.run(input.run),
|
|
138
|
+
commandIds: input.commands.map(ids.command),
|
|
139
|
+
modelSelection: testModel,
|
|
140
|
+
trace: runTrace
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
turn(input) {
|
|
144
|
+
return this.append("TurnStarted", {
|
|
145
|
+
runId: ids.run(input.run),
|
|
146
|
+
turnId: ids.turn(input.turn),
|
|
147
|
+
...input.inputs === void 0 ? {} : { inputMessageIds: input.inputs.map(ids.message) }
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
inferenceStarted(input) {
|
|
151
|
+
return this.append("InferenceStarted", {
|
|
152
|
+
runId: ids.run(input.run),
|
|
153
|
+
turnId: ids.turn(input.turn),
|
|
154
|
+
inferenceId: ids.inference(input.inference)
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
assistant(input) {
|
|
158
|
+
const promptParts = [
|
|
159
|
+
...input.reasoning === void 0 ? [] : [{
|
|
160
|
+
type: "reasoning",
|
|
161
|
+
text: input.reasoning
|
|
162
|
+
}],
|
|
163
|
+
...input.text === void 0 ? [] : [{
|
|
164
|
+
type: "text",
|
|
165
|
+
text: input.text
|
|
166
|
+
}],
|
|
167
|
+
...(input.toolCalls ?? []).map((call) => ({
|
|
168
|
+
type: "tool-call",
|
|
169
|
+
id: call.providerId,
|
|
170
|
+
name: call.name,
|
|
171
|
+
params: { q: call.name },
|
|
172
|
+
providerExecuted: false
|
|
173
|
+
}))
|
|
174
|
+
];
|
|
175
|
+
return this.append(input.partial === void 0 ? "AssistantMessageCommitted" : "AssistantPartialCommitted", {
|
|
176
|
+
messageId: ids.message(input.message),
|
|
177
|
+
runId: ids.run(input.run),
|
|
178
|
+
turnId: ids.turn(input.turn),
|
|
179
|
+
inferenceId: ids.inference(input.inference),
|
|
180
|
+
promptParts,
|
|
181
|
+
...input.partial === void 0 ? {} : { reason: input.partial }
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
importAssistant(input) {
|
|
185
|
+
return this.append("AssistantMessageImported", {
|
|
186
|
+
messageId: ids.message(input.message),
|
|
187
|
+
runId: ids.run(input.run),
|
|
188
|
+
turnId: ids.turn(input.turn),
|
|
189
|
+
inferenceId: ids.inference(input.inference),
|
|
190
|
+
promptParts: [{
|
|
191
|
+
type: "text",
|
|
192
|
+
text: input.text
|
|
193
|
+
}]
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
inferenceCompleted(input) {
|
|
197
|
+
return this.append("InferenceCompleted", {
|
|
198
|
+
runId: ids.run(input.run),
|
|
199
|
+
turnId: ids.turn(input.turn),
|
|
200
|
+
inferenceId: ids.inference(input.inference),
|
|
201
|
+
finishReason: "stop",
|
|
202
|
+
usage: {
|
|
203
|
+
inputTokens: 10,
|
|
204
|
+
outputTokens: input.outputTokens ?? 5
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
inferenceFailed(input) {
|
|
209
|
+
return this.append("InferenceFailed", {
|
|
210
|
+
runId: ids.run(input.run),
|
|
211
|
+
turnId: ids.turn(input.turn),
|
|
212
|
+
inferenceId: ids.inference(input.inference),
|
|
213
|
+
error: {
|
|
214
|
+
message: "inference failed",
|
|
215
|
+
...input.code === void 0 ? {} : { code: input.code }
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
toolCreated(input) {
|
|
220
|
+
return this.append("ToolCallCreated", {
|
|
221
|
+
runId: ids.run(input.run),
|
|
222
|
+
turnId: ids.turn(input.turn),
|
|
223
|
+
inferenceId: ids.inference(input.inference),
|
|
224
|
+
toolCallId: ids.tool(input.tool),
|
|
225
|
+
promptPart: {
|
|
226
|
+
type: "tool-call",
|
|
227
|
+
id: input.providerId,
|
|
228
|
+
name: input.name,
|
|
229
|
+
params: { q: input.name },
|
|
230
|
+
providerExecuted: false
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
toolRejected(input) {
|
|
235
|
+
return this.append("ToolCallRejected", {
|
|
236
|
+
runId: ids.run(input.run),
|
|
237
|
+
turnId: ids.turn(input.turn),
|
|
238
|
+
inferenceId: ids.inference(input.inference),
|
|
239
|
+
toolCallId: ids.tool(input.tool),
|
|
240
|
+
promptPart: {
|
|
241
|
+
type: "tool-result",
|
|
242
|
+
id: input.providerId,
|
|
243
|
+
name: input.name,
|
|
244
|
+
isFailure: true,
|
|
245
|
+
result: {
|
|
246
|
+
message: "unknown tool",
|
|
247
|
+
reason: "unknown-tool",
|
|
248
|
+
modelFeedback: "no such tool"
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
toolStarted(tool) {
|
|
254
|
+
return this.append("ToolCallStarted", { toolCallId: ids.tool(tool) });
|
|
255
|
+
}
|
|
256
|
+
toolCompleted(input) {
|
|
257
|
+
return this.append("ToolCallCompleted", {
|
|
258
|
+
toolCallId: ids.tool(input.tool),
|
|
259
|
+
promptPart: {
|
|
260
|
+
type: "tool-result",
|
|
261
|
+
id: input.providerId,
|
|
262
|
+
name: input.name,
|
|
263
|
+
isFailure: false,
|
|
264
|
+
result: input.result ?? { ok: true }
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
toolFailed(input) {
|
|
269
|
+
return this.append("ToolCallFailed", {
|
|
270
|
+
toolCallId: ids.tool(input.tool),
|
|
271
|
+
error: {
|
|
272
|
+
message: "tool cancelled",
|
|
273
|
+
code: "tool.cancelled"
|
|
274
|
+
},
|
|
275
|
+
promptPart: {
|
|
276
|
+
type: "tool-result",
|
|
277
|
+
id: input.providerId,
|
|
278
|
+
name: input.name,
|
|
279
|
+
isFailure: true,
|
|
280
|
+
result: { message: "tool cancelled" }
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
turnCompleted(input) {
|
|
285
|
+
return this.append("TurnCompleted", {
|
|
286
|
+
runId: ids.run(input.run),
|
|
287
|
+
turnId: ids.turn(input.turn)
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
runCompleted(run, commands = []) {
|
|
291
|
+
this.append("RunCompleted", { runId: ids.run(run) });
|
|
292
|
+
for (const command of commands) this.append("CommandCompleted", { commandId: ids.command(command) });
|
|
293
|
+
return this;
|
|
294
|
+
}
|
|
295
|
+
runInterrupted(run) {
|
|
296
|
+
return this.append("RunFailed", {
|
|
297
|
+
runId: ids.run(run),
|
|
298
|
+
error: {
|
|
299
|
+
message: "run interrupted: restart",
|
|
300
|
+
code: "run.interrupted"
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
steer(input) {
|
|
305
|
+
return this.append("SteeringMessageQueued", {
|
|
306
|
+
commandId: ids.command(input.command),
|
|
307
|
+
messageId: ids.message(input.message),
|
|
308
|
+
runId: ids.run(input.run),
|
|
309
|
+
content: input.text
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
compaction(input) {
|
|
313
|
+
const seq = this.events.length;
|
|
314
|
+
this.append("CompactionRequested", {
|
|
315
|
+
compactionId: ids.compaction(input.compaction),
|
|
316
|
+
sourceFromSeq: 1,
|
|
317
|
+
sourceToSeq: seq
|
|
318
|
+
});
|
|
319
|
+
this.append("CompactionStarted", { compactionId: ids.compaction(input.compaction) });
|
|
320
|
+
this.append("SummaryCreated", {
|
|
321
|
+
compactionId: ids.compaction(input.compaction),
|
|
322
|
+
summaryId: ids.summary(input.summary),
|
|
323
|
+
sourceFromSeq: 1,
|
|
324
|
+
sourceToSeq: seq,
|
|
325
|
+
summary: {
|
|
326
|
+
compactionId: ids.compaction(input.compaction),
|
|
327
|
+
summaryId: ids.summary(input.summary),
|
|
328
|
+
sourceFromSeq: 1,
|
|
329
|
+
sourceToSeq: seq,
|
|
330
|
+
retainedFromContextSeq: input.retainedFromContextSeq,
|
|
331
|
+
text: "summary",
|
|
332
|
+
promptMessage: summaryPromptMessage("summary"),
|
|
333
|
+
policyId: "test"
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
this.append("ContextRebased", {
|
|
337
|
+
compactionId: ids.compaction(input.compaction),
|
|
338
|
+
summaryId: ids.summary(input.summary),
|
|
339
|
+
contextVersion: input.contextVersion,
|
|
340
|
+
retainedFromContextSeq: input.retainedFromContextSeq
|
|
341
|
+
});
|
|
342
|
+
return this.append("CompactionCompleted", {
|
|
343
|
+
compactionId: ids.compaction(input.compaction),
|
|
344
|
+
modelSelection: testModel,
|
|
345
|
+
usage: {
|
|
346
|
+
inputTokens: 100,
|
|
347
|
+
outputTokens: 20
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
/** One complete assistant turn: start, content, optional tools run to completion, finish. */
|
|
352
|
+
assistantTurn(input) {
|
|
353
|
+
this.turn({
|
|
354
|
+
run: input.run,
|
|
355
|
+
turn: input.turn,
|
|
356
|
+
...input.inputs === void 0 ? {} : { inputs: input.inputs }
|
|
357
|
+
});
|
|
358
|
+
this.inferenceStarted(input);
|
|
359
|
+
const toolCalls = (input.tools ?? []).map((tool) => ({
|
|
360
|
+
tool,
|
|
361
|
+
providerId: `call_${tool}`,
|
|
362
|
+
name: `tool_${tool}`
|
|
363
|
+
}));
|
|
364
|
+
this.assistant({
|
|
365
|
+
...input,
|
|
366
|
+
toolCalls
|
|
367
|
+
});
|
|
368
|
+
for (const call of toolCalls) this.toolCreated({
|
|
369
|
+
...input,
|
|
370
|
+
...call
|
|
371
|
+
});
|
|
372
|
+
this.inferenceCompleted(input);
|
|
373
|
+
for (const call of toolCalls) {
|
|
374
|
+
this.toolStarted(call.tool);
|
|
375
|
+
this.toolCompleted(call);
|
|
376
|
+
}
|
|
377
|
+
return this.turnCompleted(input);
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
/** A definition, built synchronously for tests. */
|
|
381
|
+
const testDefinition = (mappings = emptyTranscriptMappings) => Effect.runSync(makeTranscriptDefinition(mappings));
|
|
382
|
+
/** Project a log split into the given batches, starting from an empty version. */
|
|
383
|
+
const projectBatches = (definition, batches) => batches.reduce((version, batch) => advanceTranscriptVersion(version, definition, batch), emptyTranscriptVersion(definition.version, "active"));
|
|
384
|
+
/**
|
|
385
|
+
* A semantic view of a projected version for equality: every record encoded through its stored
|
|
386
|
+
* envelope with `updatedSeq` normalized, every alias, and the cursor and status.
|
|
387
|
+
*/
|
|
388
|
+
const normalizedProjection = (version) => ({
|
|
389
|
+
meta: version.meta,
|
|
390
|
+
records: Array.from(version.records.values()).map((record) => ({
|
|
391
|
+
...Schema.encodeSync(TranscriptRecordFromEnvelope)(record),
|
|
392
|
+
updatedSeq: 0
|
|
393
|
+
})).sort((left, right) => left.id < right.id ? -1 : left.id > right.id ? 1 : 0),
|
|
394
|
+
aliases: Array.from(version.aliases.entries()).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0)
|
|
395
|
+
});
|
|
396
|
+
//#endregion
|
|
397
|
+
//#region src/transcript/transcript-scenarios.ts
|
|
398
|
+
/** Gia-shaped decorations used by the decoration scenarios. */
|
|
399
|
+
const giaLikeTestMappings = {
|
|
400
|
+
mappings: [
|
|
401
|
+
{
|
|
402
|
+
name: "author",
|
|
403
|
+
event: {
|
|
404
|
+
namespace: "gia-agent",
|
|
405
|
+
type: "GiaUserMessageAuthorCommitted",
|
|
406
|
+
schemaVersion: 1
|
|
407
|
+
},
|
|
408
|
+
target: {
|
|
409
|
+
_tag: "UserByIdempotencyKey",
|
|
410
|
+
path: ["relatedCommandIdempotencyKey"]
|
|
411
|
+
},
|
|
412
|
+
operations: [{
|
|
413
|
+
_tag: "FirstWins",
|
|
414
|
+
from: ["userEmail"],
|
|
415
|
+
to: "author"
|
|
416
|
+
}]
|
|
417
|
+
},
|
|
418
|
+
{
|
|
419
|
+
name: "lastAuthor",
|
|
420
|
+
event: {
|
|
421
|
+
namespace: "gia-agent",
|
|
422
|
+
type: "GiaUserMessageAuthorCommitted",
|
|
423
|
+
schemaVersion: 1
|
|
424
|
+
},
|
|
425
|
+
target: { _tag: "Session" },
|
|
426
|
+
operations: [{
|
|
427
|
+
_tag: "Copy",
|
|
428
|
+
from: ["userEmail"],
|
|
429
|
+
to: "lastAuthor"
|
|
430
|
+
}]
|
|
431
|
+
},
|
|
432
|
+
{
|
|
433
|
+
name: "owner",
|
|
434
|
+
event: {
|
|
435
|
+
namespace: "gia-agent",
|
|
436
|
+
type: "GiaSessionMetadataCommitted",
|
|
437
|
+
schemaVersion: 1
|
|
438
|
+
},
|
|
439
|
+
target: { _tag: "Session" },
|
|
440
|
+
operations: [{
|
|
441
|
+
_tag: "FirstWins",
|
|
442
|
+
from: ["ownerUserEmail"],
|
|
443
|
+
to: "owner"
|
|
444
|
+
}]
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
name: "attachments",
|
|
448
|
+
event: {
|
|
449
|
+
namespace: "gia-agent",
|
|
450
|
+
type: "GiaFileAttachmentCreated",
|
|
451
|
+
schemaVersion: 1
|
|
452
|
+
},
|
|
453
|
+
target: {
|
|
454
|
+
_tag: "UserByIdempotencyKey",
|
|
455
|
+
path: ["relatedCommandIdempotencyKey"]
|
|
456
|
+
},
|
|
457
|
+
operations: [{
|
|
458
|
+
_tag: "ReplaceListEntry",
|
|
459
|
+
from: [],
|
|
460
|
+
to: "attachments",
|
|
461
|
+
key: {
|
|
462
|
+
_tag: "Id",
|
|
463
|
+
path: ["attachmentId"]
|
|
464
|
+
}
|
|
465
|
+
}]
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
name: "references",
|
|
469
|
+
event: {
|
|
470
|
+
namespace: "gia-agent",
|
|
471
|
+
type: "GiaReferenceCreated",
|
|
472
|
+
schemaVersion: 1
|
|
473
|
+
},
|
|
474
|
+
target: {
|
|
475
|
+
_tag: "UserByIdempotencyKey",
|
|
476
|
+
path: ["relatedCommandIdempotencyKey"]
|
|
477
|
+
},
|
|
478
|
+
operations: [{
|
|
479
|
+
_tag: "ReplaceListEntry",
|
|
480
|
+
from: ["target"],
|
|
481
|
+
to: "references",
|
|
482
|
+
key: {
|
|
483
|
+
_tag: "Ordinal",
|
|
484
|
+
path: ["ordinal"]
|
|
485
|
+
}
|
|
486
|
+
}]
|
|
487
|
+
},
|
|
488
|
+
{
|
|
489
|
+
name: "subagentNotice",
|
|
490
|
+
event: {
|
|
491
|
+
namespace: "gia-agent",
|
|
492
|
+
type: "GiaSubagentNotificationCommitted",
|
|
493
|
+
schemaVersion: 1
|
|
494
|
+
},
|
|
495
|
+
target: {
|
|
496
|
+
_tag: "UserByCommandId",
|
|
497
|
+
path: ["notificationId"]
|
|
498
|
+
},
|
|
499
|
+
operations: [{
|
|
500
|
+
_tag: "Classify",
|
|
501
|
+
classification: "subagentNotice"
|
|
502
|
+
}, {
|
|
503
|
+
_tag: "FirstWins",
|
|
504
|
+
from: ["children"],
|
|
505
|
+
to: "subagentChildren"
|
|
506
|
+
}]
|
|
507
|
+
}
|
|
508
|
+
],
|
|
509
|
+
userFallbacks: [{
|
|
510
|
+
to: "author",
|
|
511
|
+
fromSession: "lastAuthor"
|
|
512
|
+
}, {
|
|
513
|
+
to: "author",
|
|
514
|
+
fromSession: "owner"
|
|
515
|
+
}]
|
|
516
|
+
};
|
|
517
|
+
const author = (key, email) => ({
|
|
518
|
+
relatedCommandIdempotencyKey: key,
|
|
519
|
+
userEmail: email
|
|
520
|
+
});
|
|
521
|
+
const queueRunTools = () => {
|
|
522
|
+
const log = new TestLog().configure();
|
|
523
|
+
log.submit({
|
|
524
|
+
command: 1,
|
|
525
|
+
message: 1,
|
|
526
|
+
text: "hi",
|
|
527
|
+
idempotencyKey: "web:1"
|
|
528
|
+
});
|
|
529
|
+
log.startRun({
|
|
530
|
+
run: 1,
|
|
531
|
+
commands: [1]
|
|
532
|
+
});
|
|
533
|
+
log.assistantTurn({
|
|
534
|
+
run: 1,
|
|
535
|
+
turn: 1,
|
|
536
|
+
inference: 1,
|
|
537
|
+
message: 101,
|
|
538
|
+
text: "calling",
|
|
539
|
+
inputs: [1],
|
|
540
|
+
tools: [1, 2]
|
|
541
|
+
});
|
|
542
|
+
log.assistantTurn({
|
|
543
|
+
run: 1,
|
|
544
|
+
turn: 2,
|
|
545
|
+
inference: 2,
|
|
546
|
+
message: 102,
|
|
547
|
+
text: "done"
|
|
548
|
+
});
|
|
549
|
+
return log.runCompleted(1, [1]);
|
|
550
|
+
};
|
|
551
|
+
const legacyCommitted = () => {
|
|
552
|
+
const log = new TestLog().configure();
|
|
553
|
+
log.admitOnly({
|
|
554
|
+
command: 1,
|
|
555
|
+
text: "interrupting"
|
|
556
|
+
});
|
|
557
|
+
log.append("CommandStarted", { commandId: ids.command(1) });
|
|
558
|
+
log.commitUser({
|
|
559
|
+
command: 1,
|
|
560
|
+
message: 1,
|
|
561
|
+
text: "interrupting"
|
|
562
|
+
});
|
|
563
|
+
log.runStarted({
|
|
564
|
+
run: 1,
|
|
565
|
+
commands: [1]
|
|
566
|
+
});
|
|
567
|
+
log.assistantTurn({
|
|
568
|
+
run: 1,
|
|
569
|
+
turn: 1,
|
|
570
|
+
inference: 1,
|
|
571
|
+
message: 101,
|
|
572
|
+
text: "ok",
|
|
573
|
+
inputs: [1]
|
|
574
|
+
});
|
|
575
|
+
log.commitUser({
|
|
576
|
+
command: 2,
|
|
577
|
+
message: 2,
|
|
578
|
+
text: "old"
|
|
579
|
+
});
|
|
580
|
+
return log.runCompleted(1, [1]);
|
|
581
|
+
};
|
|
582
|
+
const steering = () => {
|
|
583
|
+
const log = new TestLog().configure();
|
|
584
|
+
log.submit({
|
|
585
|
+
command: 1,
|
|
586
|
+
message: 1,
|
|
587
|
+
text: "start"
|
|
588
|
+
});
|
|
589
|
+
log.startRun({
|
|
590
|
+
run: 1,
|
|
591
|
+
commands: [1]
|
|
592
|
+
});
|
|
593
|
+
log.turn({
|
|
594
|
+
run: 1,
|
|
595
|
+
turn: 1,
|
|
596
|
+
inputs: [1]
|
|
597
|
+
});
|
|
598
|
+
log.inferenceStarted({
|
|
599
|
+
run: 1,
|
|
600
|
+
turn: 1,
|
|
601
|
+
inference: 1
|
|
602
|
+
});
|
|
603
|
+
log.submit({
|
|
604
|
+
command: 2,
|
|
605
|
+
message: 2,
|
|
606
|
+
text: "steer me",
|
|
607
|
+
disposition: "steer"
|
|
608
|
+
});
|
|
609
|
+
log.steer({
|
|
610
|
+
command: 3,
|
|
611
|
+
message: 3,
|
|
612
|
+
run: 1,
|
|
613
|
+
text: "also this"
|
|
614
|
+
});
|
|
615
|
+
log.steer({
|
|
616
|
+
command: 4,
|
|
617
|
+
message: 4,
|
|
618
|
+
run: 1,
|
|
619
|
+
text: "never mind"
|
|
620
|
+
});
|
|
621
|
+
log.append("SteeringMessageCancelled", {
|
|
622
|
+
messageId: ids.message(4),
|
|
623
|
+
runId: ids.run(1),
|
|
624
|
+
reason: "run ended"
|
|
625
|
+
});
|
|
626
|
+
log.assistant({
|
|
627
|
+
run: 1,
|
|
628
|
+
turn: 1,
|
|
629
|
+
inference: 1,
|
|
630
|
+
message: 101,
|
|
631
|
+
text: "first"
|
|
632
|
+
});
|
|
633
|
+
log.inferenceCompleted({
|
|
634
|
+
run: 1,
|
|
635
|
+
turn: 1,
|
|
636
|
+
inference: 1
|
|
637
|
+
});
|
|
638
|
+
log.turnCompleted({
|
|
639
|
+
run: 1,
|
|
640
|
+
turn: 1
|
|
641
|
+
});
|
|
642
|
+
log.assistantTurn({
|
|
643
|
+
run: 1,
|
|
644
|
+
turn: 2,
|
|
645
|
+
inference: 2,
|
|
646
|
+
message: 102,
|
|
647
|
+
text: "steered",
|
|
648
|
+
inputs: [2, 3]
|
|
649
|
+
});
|
|
650
|
+
return log.runCompleted(1, [1]);
|
|
651
|
+
};
|
|
652
|
+
const promotePauseCancel = () => {
|
|
653
|
+
const log = new TestLog().configure();
|
|
654
|
+
log.submit({
|
|
655
|
+
command: 1,
|
|
656
|
+
message: 1,
|
|
657
|
+
text: "first"
|
|
658
|
+
});
|
|
659
|
+
log.startRun({
|
|
660
|
+
run: 1,
|
|
661
|
+
commands: [1]
|
|
662
|
+
});
|
|
663
|
+
log.turn({
|
|
664
|
+
run: 1,
|
|
665
|
+
turn: 1,
|
|
666
|
+
inputs: [1]
|
|
667
|
+
});
|
|
668
|
+
log.submit({
|
|
669
|
+
command: 2,
|
|
670
|
+
message: 2,
|
|
671
|
+
text: "queued a"
|
|
672
|
+
});
|
|
673
|
+
log.submit({
|
|
674
|
+
command: 3,
|
|
675
|
+
message: 3,
|
|
676
|
+
text: "queued b"
|
|
677
|
+
});
|
|
678
|
+
log.submit({
|
|
679
|
+
command: 4,
|
|
680
|
+
message: 4,
|
|
681
|
+
text: "queued c"
|
|
682
|
+
});
|
|
683
|
+
log.submit({
|
|
684
|
+
command: 5,
|
|
685
|
+
message: 5,
|
|
686
|
+
text: "queued d"
|
|
687
|
+
});
|
|
688
|
+
log.append("UserMessagePromoted", {
|
|
689
|
+
commandId: ids.command(6),
|
|
690
|
+
messageId: ids.message(2),
|
|
691
|
+
from: "queue",
|
|
692
|
+
to: "steer"
|
|
693
|
+
});
|
|
694
|
+
log.append("PendingMessagesPaused", {
|
|
695
|
+
interruptionCommandId: ids.command(7),
|
|
696
|
+
runId: ids.run(1),
|
|
697
|
+
messageIds: [ids.message(3), ids.message(4)],
|
|
698
|
+
reason: "user-interrupted"
|
|
699
|
+
});
|
|
700
|
+
log.append("UserMessageCancelled", {
|
|
701
|
+
commandId: ids.command(8),
|
|
702
|
+
messageId: ids.message(4),
|
|
703
|
+
reason: "user-cancel"
|
|
704
|
+
});
|
|
705
|
+
log.append("UserMessageCancelled", {
|
|
706
|
+
commandId: ids.command(9),
|
|
707
|
+
messageId: ids.message(5),
|
|
708
|
+
reason: "edit"
|
|
709
|
+
});
|
|
710
|
+
log.append("CommandCancelled", {
|
|
711
|
+
commandId: ids.command(5),
|
|
712
|
+
reason: "edited"
|
|
713
|
+
});
|
|
714
|
+
log.admitOnly({
|
|
715
|
+
command: 10,
|
|
716
|
+
text: "admitted then cancelled"
|
|
717
|
+
});
|
|
718
|
+
log.append("CommandCancelled", {
|
|
719
|
+
commandId: ids.command(10),
|
|
720
|
+
reason: "stopped"
|
|
721
|
+
});
|
|
722
|
+
log.inferenceStarted({
|
|
723
|
+
run: 1,
|
|
724
|
+
turn: 1,
|
|
725
|
+
inference: 1
|
|
726
|
+
});
|
|
727
|
+
log.assistant({
|
|
728
|
+
run: 1,
|
|
729
|
+
turn: 1,
|
|
730
|
+
inference: 1,
|
|
731
|
+
message: 101,
|
|
732
|
+
text: "answer"
|
|
733
|
+
});
|
|
734
|
+
log.inferenceCompleted({
|
|
735
|
+
run: 1,
|
|
736
|
+
turn: 1,
|
|
737
|
+
inference: 1
|
|
738
|
+
});
|
|
739
|
+
log.turnCompleted({
|
|
740
|
+
run: 1,
|
|
741
|
+
turn: 1
|
|
742
|
+
});
|
|
743
|
+
log.assistantTurn({
|
|
744
|
+
run: 1,
|
|
745
|
+
turn: 2,
|
|
746
|
+
inference: 2,
|
|
747
|
+
message: 102,
|
|
748
|
+
text: "promoted",
|
|
749
|
+
inputs: [2]
|
|
750
|
+
});
|
|
751
|
+
return log.runCompleted(1, [1]);
|
|
752
|
+
};
|
|
753
|
+
const partialEmptyImport = () => {
|
|
754
|
+
const log = new TestLog().configure();
|
|
755
|
+
log.importAssistant({
|
|
756
|
+
run: 9,
|
|
757
|
+
turn: 9,
|
|
758
|
+
inference: 9,
|
|
759
|
+
message: 99,
|
|
760
|
+
text: "imported context"
|
|
761
|
+
});
|
|
762
|
+
log.submit({
|
|
763
|
+
command: 1,
|
|
764
|
+
message: 1,
|
|
765
|
+
text: "go"
|
|
766
|
+
});
|
|
767
|
+
log.startRun({
|
|
768
|
+
run: 1,
|
|
769
|
+
commands: [1]
|
|
770
|
+
});
|
|
771
|
+
log.turn({
|
|
772
|
+
run: 1,
|
|
773
|
+
turn: 1,
|
|
774
|
+
inputs: [1]
|
|
775
|
+
});
|
|
776
|
+
log.inferenceStarted({
|
|
777
|
+
run: 1,
|
|
778
|
+
turn: 1,
|
|
779
|
+
inference: 1
|
|
780
|
+
});
|
|
781
|
+
log.assistant({
|
|
782
|
+
run: 1,
|
|
783
|
+
turn: 1,
|
|
784
|
+
inference: 1,
|
|
785
|
+
message: 101,
|
|
786
|
+
text: "half",
|
|
787
|
+
reasoning: "hmm",
|
|
788
|
+
partial: "inference failed before completion"
|
|
789
|
+
});
|
|
790
|
+
log.inferenceFailed({
|
|
791
|
+
run: 1,
|
|
792
|
+
turn: 1,
|
|
793
|
+
inference: 1
|
|
794
|
+
});
|
|
795
|
+
log.inferenceStarted({
|
|
796
|
+
run: 1,
|
|
797
|
+
turn: 1,
|
|
798
|
+
inference: 2
|
|
799
|
+
});
|
|
800
|
+
log.inferenceCompleted({
|
|
801
|
+
run: 1,
|
|
802
|
+
turn: 1,
|
|
803
|
+
inference: 2,
|
|
804
|
+
outputTokens: 0
|
|
805
|
+
});
|
|
806
|
+
log.turnCompleted({
|
|
807
|
+
run: 1,
|
|
808
|
+
turn: 1
|
|
809
|
+
});
|
|
810
|
+
return log.runCompleted(1, [1]);
|
|
811
|
+
};
|
|
812
|
+
const rejectedAndRepeatedTerminals = () => {
|
|
813
|
+
const log = new TestLog().configure();
|
|
814
|
+
log.submit({
|
|
815
|
+
command: 1,
|
|
816
|
+
message: 1,
|
|
817
|
+
text: "tools"
|
|
818
|
+
});
|
|
819
|
+
log.startRun({
|
|
820
|
+
run: 1,
|
|
821
|
+
commands: [1]
|
|
822
|
+
});
|
|
823
|
+
log.turn({
|
|
824
|
+
run: 1,
|
|
825
|
+
turn: 1,
|
|
826
|
+
inputs: [1]
|
|
827
|
+
});
|
|
828
|
+
log.inferenceStarted({
|
|
829
|
+
run: 1,
|
|
830
|
+
turn: 1,
|
|
831
|
+
inference: 1
|
|
832
|
+
});
|
|
833
|
+
log.toolCreated({
|
|
834
|
+
run: 1,
|
|
835
|
+
turn: 1,
|
|
836
|
+
inference: 1,
|
|
837
|
+
tool: 1,
|
|
838
|
+
providerId: "call_1",
|
|
839
|
+
name: "search"
|
|
840
|
+
});
|
|
841
|
+
log.toolRejected({
|
|
842
|
+
run: 1,
|
|
843
|
+
turn: 1,
|
|
844
|
+
inference: 1,
|
|
845
|
+
tool: 2,
|
|
846
|
+
providerId: "call_2",
|
|
847
|
+
name: "nope"
|
|
848
|
+
});
|
|
849
|
+
log.assistant({
|
|
850
|
+
run: 1,
|
|
851
|
+
turn: 1,
|
|
852
|
+
inference: 1,
|
|
853
|
+
message: 101,
|
|
854
|
+
text: "using tools",
|
|
855
|
+
toolCalls: [{
|
|
856
|
+
providerId: "call_1",
|
|
857
|
+
name: "search"
|
|
858
|
+
}, {
|
|
859
|
+
providerId: "call_2",
|
|
860
|
+
name: "nope"
|
|
861
|
+
}]
|
|
862
|
+
});
|
|
863
|
+
log.inferenceCompleted({
|
|
864
|
+
run: 1,
|
|
865
|
+
turn: 1,
|
|
866
|
+
inference: 1
|
|
867
|
+
});
|
|
868
|
+
log.toolStarted(1);
|
|
869
|
+
log.toolCompleted({
|
|
870
|
+
tool: 1,
|
|
871
|
+
providerId: "call_1",
|
|
872
|
+
name: "search",
|
|
873
|
+
result: { hits: 3 }
|
|
874
|
+
});
|
|
875
|
+
log.toolFailed({
|
|
876
|
+
tool: 1,
|
|
877
|
+
providerId: "call_1",
|
|
878
|
+
name: "search"
|
|
879
|
+
});
|
|
880
|
+
log.turnCompleted({
|
|
881
|
+
run: 1,
|
|
882
|
+
turn: 1
|
|
883
|
+
});
|
|
884
|
+
return log.runCompleted(1, [1]);
|
|
885
|
+
};
|
|
886
|
+
const recovery = () => {
|
|
887
|
+
const log = new TestLog().configure();
|
|
888
|
+
log.submit({
|
|
889
|
+
command: 1,
|
|
890
|
+
message: 1,
|
|
891
|
+
text: "long task"
|
|
892
|
+
});
|
|
893
|
+
log.startRun({
|
|
894
|
+
run: 1,
|
|
895
|
+
commands: [1]
|
|
896
|
+
});
|
|
897
|
+
log.turn({
|
|
898
|
+
run: 1,
|
|
899
|
+
turn: 1,
|
|
900
|
+
inputs: [1]
|
|
901
|
+
});
|
|
902
|
+
log.inferenceStarted({
|
|
903
|
+
run: 1,
|
|
904
|
+
turn: 1,
|
|
905
|
+
inference: 1
|
|
906
|
+
});
|
|
907
|
+
log.assistant({
|
|
908
|
+
run: 1,
|
|
909
|
+
turn: 1,
|
|
910
|
+
inference: 1,
|
|
911
|
+
message: 101,
|
|
912
|
+
text: "working",
|
|
913
|
+
toolCalls: [{
|
|
914
|
+
providerId: "call_1",
|
|
915
|
+
name: "bash"
|
|
916
|
+
}]
|
|
917
|
+
});
|
|
918
|
+
log.toolCreated({
|
|
919
|
+
run: 1,
|
|
920
|
+
turn: 1,
|
|
921
|
+
inference: 1,
|
|
922
|
+
tool: 1,
|
|
923
|
+
providerId: "call_1",
|
|
924
|
+
name: "bash"
|
|
925
|
+
});
|
|
926
|
+
log.inferenceCompleted({
|
|
927
|
+
run: 1,
|
|
928
|
+
turn: 1,
|
|
929
|
+
inference: 1
|
|
930
|
+
});
|
|
931
|
+
log.toolStarted(1);
|
|
932
|
+
log.toolFailed({
|
|
933
|
+
tool: 1,
|
|
934
|
+
providerId: "call_1",
|
|
935
|
+
name: "bash"
|
|
936
|
+
});
|
|
937
|
+
log.append("TurnFailed", {
|
|
938
|
+
runId: ids.run(1),
|
|
939
|
+
turnId: ids.turn(1),
|
|
940
|
+
error: {
|
|
941
|
+
message: "turn interrupted",
|
|
942
|
+
code: "turn.interrupted"
|
|
943
|
+
}
|
|
944
|
+
});
|
|
945
|
+
log.runInterrupted(1);
|
|
946
|
+
log.runStarted({
|
|
947
|
+
run: 2,
|
|
948
|
+
commands: [1]
|
|
949
|
+
});
|
|
950
|
+
log.append("RecoveryCompleted", {
|
|
951
|
+
trigger: "runtime-restart",
|
|
952
|
+
continuation: {
|
|
953
|
+
commandId: ids.command(1),
|
|
954
|
+
interruptedRunId: ids.run(1),
|
|
955
|
+
replacementRunId: ids.run(2)
|
|
956
|
+
}
|
|
957
|
+
});
|
|
958
|
+
log.assistantTurn({
|
|
959
|
+
run: 2,
|
|
960
|
+
turn: 2,
|
|
961
|
+
inference: 2,
|
|
962
|
+
message: 102,
|
|
963
|
+
text: "resumed"
|
|
964
|
+
});
|
|
965
|
+
return log.runCompleted(2, [1]);
|
|
966
|
+
};
|
|
967
|
+
const midRunCompaction = () => {
|
|
968
|
+
const log = new TestLog().configure();
|
|
969
|
+
log.submit({
|
|
970
|
+
command: 1,
|
|
971
|
+
message: 1,
|
|
972
|
+
text: "first"
|
|
973
|
+
});
|
|
974
|
+
log.startRun({
|
|
975
|
+
run: 1,
|
|
976
|
+
commands: [1]
|
|
977
|
+
});
|
|
978
|
+
log.assistantTurn({
|
|
979
|
+
run: 1,
|
|
980
|
+
turn: 1,
|
|
981
|
+
inference: 1,
|
|
982
|
+
message: 101,
|
|
983
|
+
text: "one",
|
|
984
|
+
inputs: [1],
|
|
985
|
+
tools: [1]
|
|
986
|
+
});
|
|
987
|
+
log.runCompleted(1, [1]);
|
|
988
|
+
log.submit({
|
|
989
|
+
command: 2,
|
|
990
|
+
message: 2,
|
|
991
|
+
text: "second"
|
|
992
|
+
});
|
|
993
|
+
log.startRun({
|
|
994
|
+
run: 2,
|
|
995
|
+
commands: [2]
|
|
996
|
+
});
|
|
997
|
+
log.assistantTurn({
|
|
998
|
+
run: 2,
|
|
999
|
+
turn: 2,
|
|
1000
|
+
inference: 2,
|
|
1001
|
+
message: 102,
|
|
1002
|
+
text: "two",
|
|
1003
|
+
inputs: [2]
|
|
1004
|
+
});
|
|
1005
|
+
log.compaction({
|
|
1006
|
+
compaction: 1,
|
|
1007
|
+
summary: 1,
|
|
1008
|
+
retainedFromContextSeq: log.events.length,
|
|
1009
|
+
contextVersion: 1
|
|
1010
|
+
});
|
|
1011
|
+
log.assistantTurn({
|
|
1012
|
+
run: 2,
|
|
1013
|
+
turn: 3,
|
|
1014
|
+
inference: 3,
|
|
1015
|
+
message: 103,
|
|
1016
|
+
text: "three"
|
|
1017
|
+
});
|
|
1018
|
+
return log.runCompleted(2, [2]);
|
|
1019
|
+
};
|
|
1020
|
+
const replacementMessageId = () => {
|
|
1021
|
+
const log = new TestLog().configure();
|
|
1022
|
+
log.submit({
|
|
1023
|
+
command: 1,
|
|
1024
|
+
message: 1,
|
|
1025
|
+
text: "before"
|
|
1026
|
+
});
|
|
1027
|
+
log.startRun({
|
|
1028
|
+
run: 1,
|
|
1029
|
+
commands: [1]
|
|
1030
|
+
});
|
|
1031
|
+
log.assistantTurn({
|
|
1032
|
+
run: 1,
|
|
1033
|
+
turn: 1,
|
|
1034
|
+
inference: 1,
|
|
1035
|
+
message: 101,
|
|
1036
|
+
text: "busy",
|
|
1037
|
+
inputs: [1]
|
|
1038
|
+
});
|
|
1039
|
+
log.submit({
|
|
1040
|
+
command: 2,
|
|
1041
|
+
message: 2,
|
|
1042
|
+
text: "queued during run"
|
|
1043
|
+
});
|
|
1044
|
+
log.compaction({
|
|
1045
|
+
compaction: 1,
|
|
1046
|
+
summary: 1,
|
|
1047
|
+
retainedFromContextSeq: log.events.length + 1,
|
|
1048
|
+
contextVersion: 1
|
|
1049
|
+
});
|
|
1050
|
+
log.runCompleted(1, [1]);
|
|
1051
|
+
log.append("CommandStarted", { commandId: ids.command(2) });
|
|
1052
|
+
log.commitUser({
|
|
1053
|
+
command: 2,
|
|
1054
|
+
message: 22,
|
|
1055
|
+
text: "queued during run"
|
|
1056
|
+
});
|
|
1057
|
+
log.runStarted({
|
|
1058
|
+
run: 2,
|
|
1059
|
+
commands: [2]
|
|
1060
|
+
});
|
|
1061
|
+
log.assistantTurn({
|
|
1062
|
+
run: 2,
|
|
1063
|
+
turn: 2,
|
|
1064
|
+
inference: 2,
|
|
1065
|
+
message: 102,
|
|
1066
|
+
text: "answered",
|
|
1067
|
+
inputs: [22]
|
|
1068
|
+
});
|
|
1069
|
+
return log.runCompleted(2, [2]);
|
|
1070
|
+
};
|
|
1071
|
+
const decorations = () => {
|
|
1072
|
+
const log = new TestLog().configure();
|
|
1073
|
+
log.appendForeign("gia-agent", "GiaSessionMetadataCommitted", { ownerUserEmail: "owner@example.com" });
|
|
1074
|
+
log.appendForeign("gia-agent", "GiaUserMessageAuthorCommitted", author("web:1", "a@example.com"));
|
|
1075
|
+
log.appendForeign("gia-agent", "GiaFileAttachmentCreated", {
|
|
1076
|
+
attachmentId: "att-1",
|
|
1077
|
+
relatedCommandIdempotencyKey: "web:1",
|
|
1078
|
+
ordinal: 0,
|
|
1079
|
+
fileName: "a.txt"
|
|
1080
|
+
});
|
|
1081
|
+
log.appendForeign("gia-agent", "GiaReferenceCreated", {
|
|
1082
|
+
ordinal: 1,
|
|
1083
|
+
referenceId: "ref-2",
|
|
1084
|
+
relatedCommandIdempotencyKey: "web:1",
|
|
1085
|
+
target: {
|
|
1086
|
+
kind: "doc",
|
|
1087
|
+
id: "d2"
|
|
1088
|
+
}
|
|
1089
|
+
});
|
|
1090
|
+
log.appendForeign("gia-agent", "GiaReferenceCreated", {
|
|
1091
|
+
ordinal: 0,
|
|
1092
|
+
referenceId: "ref-1",
|
|
1093
|
+
relatedCommandIdempotencyKey: "web:1",
|
|
1094
|
+
target: {
|
|
1095
|
+
kind: "doc",
|
|
1096
|
+
id: "d1"
|
|
1097
|
+
}
|
|
1098
|
+
});
|
|
1099
|
+
log.submit({
|
|
1100
|
+
command: 1,
|
|
1101
|
+
message: 1,
|
|
1102
|
+
text: "with files",
|
|
1103
|
+
idempotencyKey: "web:1"
|
|
1104
|
+
});
|
|
1105
|
+
log.appendForeign("gia-agent", "GiaFileAttachmentCreated", {
|
|
1106
|
+
attachmentId: "att-1",
|
|
1107
|
+
relatedCommandIdempotencyKey: "web:1",
|
|
1108
|
+
ordinal: 0,
|
|
1109
|
+
fileName: "a-renamed.txt"
|
|
1110
|
+
});
|
|
1111
|
+
log.appendForeign("gia-agent", "GiaUserMessageAuthorCommitted", author("web:1", "b@example.com"));
|
|
1112
|
+
log.appendForeign("gia-agent", "GiaSubagentNotificationCommitted", {
|
|
1113
|
+
notificationId: ids.command(2),
|
|
1114
|
+
children: [{
|
|
1115
|
+
name: "child",
|
|
1116
|
+
sessionId: "s",
|
|
1117
|
+
state: "completed"
|
|
1118
|
+
}]
|
|
1119
|
+
});
|
|
1120
|
+
log.submit({
|
|
1121
|
+
command: 2,
|
|
1122
|
+
message: 2,
|
|
1123
|
+
text: "children done",
|
|
1124
|
+
idempotencyKey: `subagent:notify:${ids.command(2)}`
|
|
1125
|
+
});
|
|
1126
|
+
log.submit({
|
|
1127
|
+
command: 3,
|
|
1128
|
+
message: 3,
|
|
1129
|
+
text: "no author",
|
|
1130
|
+
idempotencyKey: "slack:3"
|
|
1131
|
+
});
|
|
1132
|
+
log.appendForeign("gia-agent", "GiaUserMessageAuthorCommitted", { relatedCommandIdempotencyKey: "slack:3" });
|
|
1133
|
+
log.appendForeign("gia-agent", "GiaFileAttachmentCreated", {
|
|
1134
|
+
relatedCommandIdempotencyKey: "slack:3",
|
|
1135
|
+
fileName: "no id"
|
|
1136
|
+
});
|
|
1137
|
+
log.appendForeign("gia-agent", "GiaUserMessageAuthorCommitted", {
|
|
1138
|
+
relatedCommandIdempotencyKey: 7,
|
|
1139
|
+
userEmail: "x"
|
|
1140
|
+
});
|
|
1141
|
+
log.appendForeign("other-app", "Whatever", { relatedCommandIdempotencyKey: "web:1" });
|
|
1142
|
+
log.appendForeign("gia-agent", "GiaUserMessageAuthorCommitted", author("never", "c@example.com"));
|
|
1143
|
+
log.startRun({
|
|
1144
|
+
run: 1,
|
|
1145
|
+
commands: [
|
|
1146
|
+
1,
|
|
1147
|
+
2,
|
|
1148
|
+
3
|
|
1149
|
+
]
|
|
1150
|
+
});
|
|
1151
|
+
log.assistantTurn({
|
|
1152
|
+
run: 1,
|
|
1153
|
+
turn: 1,
|
|
1154
|
+
inference: 1,
|
|
1155
|
+
message: 101,
|
|
1156
|
+
text: "ok",
|
|
1157
|
+
inputs: [
|
|
1158
|
+
1,
|
|
1159
|
+
2,
|
|
1160
|
+
3
|
|
1161
|
+
]
|
|
1162
|
+
});
|
|
1163
|
+
return log.runCompleted(1, [
|
|
1164
|
+
1,
|
|
1165
|
+
2,
|
|
1166
|
+
3
|
|
1167
|
+
]);
|
|
1168
|
+
};
|
|
1169
|
+
const ignoredEvents = () => {
|
|
1170
|
+
const log = new TestLog().configure();
|
|
1171
|
+
log.append("SystemMessageCommitted", {
|
|
1172
|
+
messageId: ids.message(90),
|
|
1173
|
+
content: "system prompt"
|
|
1174
|
+
});
|
|
1175
|
+
log.append("RunSchedulingRequested", {
|
|
1176
|
+
requestId: ids.event(900),
|
|
1177
|
+
work: {
|
|
1178
|
+
_tag: "Command",
|
|
1179
|
+
commandId: ids.command(1)
|
|
1180
|
+
}
|
|
1181
|
+
});
|
|
1182
|
+
log.append("RunSchedulingDelivered", { requestId: ids.event(900) });
|
|
1183
|
+
log.append("RunSchedulingGranted", {
|
|
1184
|
+
requestId: ids.event(900),
|
|
1185
|
+
runId: ids.run(1)
|
|
1186
|
+
});
|
|
1187
|
+
log.append("RunSchedulingInvalidated", {
|
|
1188
|
+
requestId: ids.event(901),
|
|
1189
|
+
reason: "stopped"
|
|
1190
|
+
});
|
|
1191
|
+
log.submit({
|
|
1192
|
+
command: 1,
|
|
1193
|
+
message: 1,
|
|
1194
|
+
text: "hello"
|
|
1195
|
+
});
|
|
1196
|
+
log.startRun({
|
|
1197
|
+
run: 1,
|
|
1198
|
+
commands: [1]
|
|
1199
|
+
});
|
|
1200
|
+
log.turn({
|
|
1201
|
+
run: 1,
|
|
1202
|
+
turn: 1,
|
|
1203
|
+
inputs: [1]
|
|
1204
|
+
});
|
|
1205
|
+
log.append("StopTurnRequested", {
|
|
1206
|
+
commandId: ids.command(2),
|
|
1207
|
+
runId: ids.run(1),
|
|
1208
|
+
turnId: ids.turn(1)
|
|
1209
|
+
});
|
|
1210
|
+
log.append("StopTurnApplied", {
|
|
1211
|
+
commandId: ids.command(2),
|
|
1212
|
+
runId: ids.run(1),
|
|
1213
|
+
turnId: ids.turn(1)
|
|
1214
|
+
});
|
|
1215
|
+
log.append("TurnStopped", {
|
|
1216
|
+
runId: ids.run(1),
|
|
1217
|
+
turnId: ids.turn(1),
|
|
1218
|
+
reason: "stop"
|
|
1219
|
+
});
|
|
1220
|
+
log.append("ContextProjected", {
|
|
1221
|
+
contextVersion: 0,
|
|
1222
|
+
throughSeq: log.events.length
|
|
1223
|
+
});
|
|
1224
|
+
log.append("BaseStateRequested", {
|
|
1225
|
+
baseStateId: ids.event(902),
|
|
1226
|
+
requestedThroughSeq: 1
|
|
1227
|
+
});
|
|
1228
|
+
log.append("BaseStateCreated", {
|
|
1229
|
+
baseStateId: ids.event(902),
|
|
1230
|
+
coversThroughSeq: 1
|
|
1231
|
+
});
|
|
1232
|
+
log.append("BaseStateFailed", {
|
|
1233
|
+
baseStateId: ids.event(903),
|
|
1234
|
+
error: { message: "x" }
|
|
1235
|
+
});
|
|
1236
|
+
log.append("CompactionRequested", {
|
|
1237
|
+
compactionId: ids.compaction(9),
|
|
1238
|
+
sourceFromSeq: 1,
|
|
1239
|
+
sourceToSeq: 2
|
|
1240
|
+
});
|
|
1241
|
+
log.append("CompactionStarted", { compactionId: ids.compaction(9) });
|
|
1242
|
+
log.append("CompactionFailed", {
|
|
1243
|
+
compactionId: ids.compaction(9),
|
|
1244
|
+
error: { message: "no" }
|
|
1245
|
+
});
|
|
1246
|
+
log.append("RunInterrupted", {
|
|
1247
|
+
runId: ids.run(1),
|
|
1248
|
+
reason: "legacy stop"
|
|
1249
|
+
});
|
|
1250
|
+
log.append("CommandFailed", {
|
|
1251
|
+
commandId: ids.command(1),
|
|
1252
|
+
error: { message: "x" }
|
|
1253
|
+
});
|
|
1254
|
+
return log;
|
|
1255
|
+
};
|
|
1256
|
+
const legacyAttempts = () => {
|
|
1257
|
+
const log = new TestLog().configure();
|
|
1258
|
+
log.submit({
|
|
1259
|
+
command: 1,
|
|
1260
|
+
message: 1,
|
|
1261
|
+
text: "legacy"
|
|
1262
|
+
});
|
|
1263
|
+
log.startRun({
|
|
1264
|
+
run: 1,
|
|
1265
|
+
commands: [1]
|
|
1266
|
+
});
|
|
1267
|
+
log.turn({
|
|
1268
|
+
run: 1,
|
|
1269
|
+
turn: 1,
|
|
1270
|
+
inputs: [1]
|
|
1271
|
+
});
|
|
1272
|
+
log.append("TurnAttemptStarted", {
|
|
1273
|
+
runId: ids.run(1),
|
|
1274
|
+
turnId: ids.turn(1),
|
|
1275
|
+
attemptId: ids.inference(1)
|
|
1276
|
+
});
|
|
1277
|
+
log.append("AssistantMessageCommitted", {
|
|
1278
|
+
messageId: ids.message(101),
|
|
1279
|
+
runId: ids.run(1),
|
|
1280
|
+
turnId: ids.turn(1),
|
|
1281
|
+
attemptId: ids.inference(1),
|
|
1282
|
+
promptParts: [{
|
|
1283
|
+
type: "text",
|
|
1284
|
+
text: "legacy answer"
|
|
1285
|
+
}, {
|
|
1286
|
+
type: "tool-call",
|
|
1287
|
+
id: "call_1",
|
|
1288
|
+
name: "search",
|
|
1289
|
+
params: {},
|
|
1290
|
+
providerExecuted: false
|
|
1291
|
+
}]
|
|
1292
|
+
});
|
|
1293
|
+
log.append("ToolCallCreated", {
|
|
1294
|
+
runId: ids.run(1),
|
|
1295
|
+
turnId: ids.turn(1),
|
|
1296
|
+
attemptId: ids.inference(1),
|
|
1297
|
+
toolCallId: ids.tool(1),
|
|
1298
|
+
promptPart: {
|
|
1299
|
+
type: "tool-call",
|
|
1300
|
+
id: "call_1",
|
|
1301
|
+
name: "search",
|
|
1302
|
+
params: {},
|
|
1303
|
+
providerExecuted: false
|
|
1304
|
+
}
|
|
1305
|
+
});
|
|
1306
|
+
log.append("TurnAttemptCompleted", {
|
|
1307
|
+
runId: ids.run(1),
|
|
1308
|
+
turnId: ids.turn(1),
|
|
1309
|
+
attemptId: ids.inference(1),
|
|
1310
|
+
usage: {
|
|
1311
|
+
inputTokens: 3,
|
|
1312
|
+
outputTokens: 4
|
|
1313
|
+
}
|
|
1314
|
+
});
|
|
1315
|
+
log.toolStarted(1);
|
|
1316
|
+
log.toolCompleted({
|
|
1317
|
+
tool: 1,
|
|
1318
|
+
providerId: "call_1",
|
|
1319
|
+
name: "search"
|
|
1320
|
+
});
|
|
1321
|
+
log.turnCompleted({
|
|
1322
|
+
run: 1,
|
|
1323
|
+
turn: 1
|
|
1324
|
+
});
|
|
1325
|
+
return log.runCompleted(1, [1]);
|
|
1326
|
+
};
|
|
1327
|
+
const failuresAndRepeatedCompletion = () => {
|
|
1328
|
+
const log = new TestLog().configure();
|
|
1329
|
+
log.admitOnly({
|
|
1330
|
+
command: 1,
|
|
1331
|
+
text: "stop and do this"
|
|
1332
|
+
});
|
|
1333
|
+
log.append("CommandStarted", { commandId: ids.command(1) });
|
|
1334
|
+
log.append("CommandFailed", {
|
|
1335
|
+
commandId: ids.command(1),
|
|
1336
|
+
error: { message: "start failed" }
|
|
1337
|
+
});
|
|
1338
|
+
log.submit({
|
|
1339
|
+
command: 2,
|
|
1340
|
+
message: 2,
|
|
1341
|
+
text: "next"
|
|
1342
|
+
});
|
|
1343
|
+
log.startRun({
|
|
1344
|
+
run: 1,
|
|
1345
|
+
commands: [2]
|
|
1346
|
+
});
|
|
1347
|
+
log.assistantTurn({
|
|
1348
|
+
run: 1,
|
|
1349
|
+
turn: 1,
|
|
1350
|
+
inference: 1,
|
|
1351
|
+
message: 101,
|
|
1352
|
+
text: "ok",
|
|
1353
|
+
inputs: [2]
|
|
1354
|
+
});
|
|
1355
|
+
log.compaction({
|
|
1356
|
+
compaction: 1,
|
|
1357
|
+
summary: 1,
|
|
1358
|
+
retainedFromContextSeq: log.events.length,
|
|
1359
|
+
contextVersion: 1
|
|
1360
|
+
});
|
|
1361
|
+
log.append("CompactionCompleted", {
|
|
1362
|
+
compactionId: ids.compaction(1),
|
|
1363
|
+
modelSelection: {
|
|
1364
|
+
provider: "test",
|
|
1365
|
+
modelId: "model-a"
|
|
1366
|
+
},
|
|
1367
|
+
usage: {
|
|
1368
|
+
inputTokens: 100,
|
|
1369
|
+
outputTokens: 20
|
|
1370
|
+
}
|
|
1371
|
+
});
|
|
1372
|
+
return log.runCompleted(1, [2]);
|
|
1373
|
+
};
|
|
1374
|
+
const oneTurnConsumesSeveral = () => {
|
|
1375
|
+
const log = new TestLog().configure();
|
|
1376
|
+
log.submit({
|
|
1377
|
+
command: 1,
|
|
1378
|
+
message: 1,
|
|
1379
|
+
text: "first"
|
|
1380
|
+
});
|
|
1381
|
+
log.submit({
|
|
1382
|
+
command: 2,
|
|
1383
|
+
message: 2,
|
|
1384
|
+
text: "queued"
|
|
1385
|
+
});
|
|
1386
|
+
log.startRun({
|
|
1387
|
+
run: 1,
|
|
1388
|
+
commands: [1]
|
|
1389
|
+
});
|
|
1390
|
+
log.steer({
|
|
1391
|
+
command: 3,
|
|
1392
|
+
message: 3,
|
|
1393
|
+
run: 1,
|
|
1394
|
+
text: "steering"
|
|
1395
|
+
});
|
|
1396
|
+
log.append("UserMessagePromoted", {
|
|
1397
|
+
commandId: ids.command(9),
|
|
1398
|
+
messageId: ids.message(2),
|
|
1399
|
+
from: "queue",
|
|
1400
|
+
to: "steer"
|
|
1401
|
+
});
|
|
1402
|
+
log.assistantTurn({
|
|
1403
|
+
run: 1,
|
|
1404
|
+
turn: 1,
|
|
1405
|
+
inference: 1,
|
|
1406
|
+
message: 101,
|
|
1407
|
+
text: "all three",
|
|
1408
|
+
inputs: [
|
|
1409
|
+
1,
|
|
1410
|
+
3,
|
|
1411
|
+
2
|
|
1412
|
+
]
|
|
1413
|
+
});
|
|
1414
|
+
return log.runCompleted(1, [1]);
|
|
1415
|
+
};
|
|
1416
|
+
const oneTurnConsumesSeveralSubmitted = () => {
|
|
1417
|
+
const log = new TestLog().configure();
|
|
1418
|
+
log.submit({
|
|
1419
|
+
command: 1,
|
|
1420
|
+
message: 1,
|
|
1421
|
+
text: "first"
|
|
1422
|
+
});
|
|
1423
|
+
log.submit({
|
|
1424
|
+
command: 2,
|
|
1425
|
+
message: 2,
|
|
1426
|
+
text: "queued"
|
|
1427
|
+
});
|
|
1428
|
+
log.startRun({
|
|
1429
|
+
run: 1,
|
|
1430
|
+
commands: [1]
|
|
1431
|
+
});
|
|
1432
|
+
log.submit({
|
|
1433
|
+
command: 3,
|
|
1434
|
+
message: 3,
|
|
1435
|
+
text: "steering",
|
|
1436
|
+
disposition: "steer"
|
|
1437
|
+
});
|
|
1438
|
+
log.append("UserMessagePromoted", {
|
|
1439
|
+
commandId: ids.command(9),
|
|
1440
|
+
messageId: ids.message(2),
|
|
1441
|
+
from: "queue",
|
|
1442
|
+
to: "steer"
|
|
1443
|
+
});
|
|
1444
|
+
log.assistantTurn({
|
|
1445
|
+
run: 1,
|
|
1446
|
+
turn: 1,
|
|
1447
|
+
inference: 1,
|
|
1448
|
+
message: 101,
|
|
1449
|
+
text: "all three",
|
|
1450
|
+
inputs: [
|
|
1451
|
+
1,
|
|
1452
|
+
3,
|
|
1453
|
+
2
|
|
1454
|
+
]
|
|
1455
|
+
});
|
|
1456
|
+
return log.runCompleted(1, [1]);
|
|
1457
|
+
};
|
|
1458
|
+
/** A decider's batch: its marker, an app fact and the admitted message, then a reply. */
|
|
1459
|
+
const deciderBatch = () => {
|
|
1460
|
+
const log = new TestLog().configure();
|
|
1461
|
+
log.deciderAccepted({
|
|
1462
|
+
decider: "docs.chat.PostMessage",
|
|
1463
|
+
key: "msg-1",
|
|
1464
|
+
result: { route: "ai" }
|
|
1465
|
+
});
|
|
1466
|
+
log.appendForeign("docs.chat", "MessageRouted", {
|
|
1467
|
+
route: "ai",
|
|
1468
|
+
idempotencyKey: "msg-1"
|
|
1469
|
+
});
|
|
1470
|
+
log.submit({
|
|
1471
|
+
command: 1,
|
|
1472
|
+
message: 1,
|
|
1473
|
+
text: "hello",
|
|
1474
|
+
idempotencyKey: "msg-1"
|
|
1475
|
+
});
|
|
1476
|
+
log.startRun({
|
|
1477
|
+
run: 1,
|
|
1478
|
+
commands: [1]
|
|
1479
|
+
});
|
|
1480
|
+
log.assistantTurn({
|
|
1481
|
+
run: 1,
|
|
1482
|
+
turn: 1,
|
|
1483
|
+
inference: 1,
|
|
1484
|
+
message: 101,
|
|
1485
|
+
text: "hi",
|
|
1486
|
+
inputs: [1]
|
|
1487
|
+
});
|
|
1488
|
+
log.deciderAccepted({
|
|
1489
|
+
decider: "docs.chat.PostMessage",
|
|
1490
|
+
key: "msg-2",
|
|
1491
|
+
result: { route: "human" }
|
|
1492
|
+
});
|
|
1493
|
+
log.appendForeign("docs.chat", "MessageRouted", {
|
|
1494
|
+
route: "human",
|
|
1495
|
+
idempotencyKey: "msg-2"
|
|
1496
|
+
});
|
|
1497
|
+
return log.runCompleted(1, [1]);
|
|
1498
|
+
};
|
|
1499
|
+
const scenario = (name, compacted, build) => ({
|
|
1500
|
+
name,
|
|
1501
|
+
compacted,
|
|
1502
|
+
events: build().events
|
|
1503
|
+
});
|
|
1504
|
+
/** Build the corpus. Logs are deterministic: ids, timestamps and traces are fixed. */
|
|
1505
|
+
const transcriptScenarios = () => [
|
|
1506
|
+
scenario("queue-run-tools", false, queueRunTools),
|
|
1507
|
+
scenario("legacy-committed-user", false, legacyCommitted),
|
|
1508
|
+
scenario("steering", false, steering),
|
|
1509
|
+
scenario("promote-pause-cancel", false, promotePauseCancel),
|
|
1510
|
+
scenario("partial-failure-empty-success-import", false, partialEmptyImport),
|
|
1511
|
+
scenario("rejected-tool-repeated-terminals", false, rejectedAndRepeatedTerminals),
|
|
1512
|
+
scenario("recovery-continuation", false, recovery),
|
|
1513
|
+
scenario("mid-run-compaction", true, midRunCompaction),
|
|
1514
|
+
scenario("replacement-message-id", true, replacementMessageId),
|
|
1515
|
+
scenario("host-decorations", false, decorations),
|
|
1516
|
+
scenario("events-without-transcript-meaning", false, ignoredEvents),
|
|
1517
|
+
scenario("legacy-attempts", false, legacyAttempts),
|
|
1518
|
+
scenario("failed-interrupt-repeated-compaction-completion", true, failuresAndRepeatedCompletion),
|
|
1519
|
+
scenario("one-turn-consumes-several", false, oneTurnConsumesSeveral),
|
|
1520
|
+
scenario("one-turn-consumes-several-submitted", false, oneTurnConsumesSeveralSubmitted),
|
|
1521
|
+
scenario("decider-marker", false, deciderBatch)
|
|
1522
|
+
];
|
|
1523
|
+
//#endregion
|
|
1524
|
+
export { TestLog, giaLikeTestMappings, ids, normalizedProjection, projectBatches, testDefinition, testId, testSessionId, transcriptScenarios };
|
|
1525
|
+
|
|
1526
|
+
//# sourceMappingURL=transcript.js.map
|