effect-durable-agent 0.1.0-alpha.22 → 0.1.0-alpha.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/domain/command-queues.d.ts +1 -1
- package/dist/domain/message-transcript.d.ts +1 -1
- package/dist/domain/reduced-state.d.ts +1 -1
- package/dist/domain/run-scheduling.d.ts +1 -1
- package/dist/in-memory-D8qQXNc5.js +150 -0
- package/dist/in-memory-D8qQXNc5.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/{window-read-B8aF_hDq.js → interpreter-BYstFpr4.js} +82 -868
- package/dist/interpreter-BYstFpr4.js.map +1 -0
- package/dist/records-DWKEjuqb.js +675 -0
- package/dist/records-DWKEjuqb.js.map +1 -0
- package/dist/{reduced-state-PJdig48e.d.ts → reduced-state-B5WxKSM5.d.ts} +4206 -4206
- package/dist/{reducer-registry-BAbhZs6d.d.ts → reducer-registry-CPObI3cs.d.ts} +2 -2
- package/dist/{run-scheduling-wakeup-QLK87OqG.d.ts → run-scheduling-wakeup-B19JTeyq.d.ts} +2 -2
- package/dist/services/compaction.d.ts +1 -1
- package/dist/services/model-call.d.ts +1 -1
- package/dist/services/prompt-projector.d.ts +1 -1
- package/dist/services/reducer-registry.d.ts +1 -1
- package/dist/services/reducer-registry.js +1 -1
- package/dist/services/run-scheduler.d.ts +1 -1
- package/dist/services/run-scheduling-wakeup.d.ts +1 -1
- package/dist/services/runtime-layer.d.ts +6 -6
- package/dist/services/runtime-layer.js +3 -3
- package/dist/services/runtime.d.ts +1 -1
- package/dist/services/runtime.js +1 -1
- package/dist/services/session-query.d.ts +1 -1
- package/dist/services/session-query.js +2 -2
- package/dist/services/session-state.d.ts +1 -1
- package/dist/services/session-state.js +1 -1
- package/dist/services/session-store.d.ts +1 -1
- package/dist/services/session-store.js +271 -1
- package/dist/services/session-store.js.map +1 -0
- package/dist/services/sink-checkpoint-store.d.ts +1 -1
- package/dist/services/sink-registry.d.ts +1 -1
- package/dist/services/sink-registry.js +1 -1
- package/dist/services/tool-registry.d.ts +1 -1
- package/dist/{session-state-StlO5B2N.js → session-state-BW0l2aNk.js} +3 -3
- package/dist/{session-state-StlO5B2N.js.map → session-state-BW0l2aNk.js.map} +1 -1
- package/dist/{session-store-ByDjS03N.d.ts → session-store-CWYZ29CV.d.ts} +163 -45
- package/dist/{sink-checkpoint-store-BHb8YRTw.d.ts → sink-checkpoint-store-B8Ky5nfW.d.ts} +2 -2
- package/dist/{sink-registry-DEneTH8u.js → sink-registry-D0MetcNq.js} +2 -2
- package/dist/{sink-registry-DEneTH8u.js.map → sink-registry-D0MetcNq.js.map} +1 -1
- package/dist/subscription-DelB8L87.d.ts +958 -0
- package/dist/subscription-g5W0Ggqx.js +498 -0
- package/dist/subscription-g5W0Ggqx.js.map +1 -0
- package/dist/testkit/layers.d.ts +9 -6
- package/dist/testkit/layers.js +4 -4
- package/dist/testkit/layers.js.map +1 -1
- package/dist/testkit/transcript.d.ts +226 -0
- package/dist/testkit/transcript.js +1475 -0
- package/dist/testkit/transcript.js.map +1 -0
- package/dist/{tool-registry-CxZ0iuYb.d.ts → tool-registry-B_WE2ZwK.d.ts} +2 -2
- package/dist/transcript.d.ts +40 -99
- package/dist/transcript.js +99 -170
- package/dist/transcript.js.map +1 -1
- package/dist/websocket.d.ts +2209 -2
- package/dist/websocket.js +704 -18
- package/dist/websocket.js.map +1 -1
- package/dist/window-read-DBf1Iktt.d.ts +104 -0
- package/dist/window-read-U55aAeuz.js +184 -0
- package/dist/window-read-U55aAeuz.js.map +1 -0
- package/package.json +5 -1
- package/dist/session-store-DcJjs4Fd.js +0 -413
- package/dist/session-store-DcJjs4Fd.js.map +0 -1
- package/dist/window-read-B8aF_hDq.js.map +0 -1
|
@@ -1,673 +1,12 @@
|
|
|
1
|
-
import { CommandId
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { CommandIdempotencyKey
|
|
5
|
-
import { $n as pendingMessagesPausedEventType, An as baseStateCreatedEventType, Bn as compactionRequestedEventType, Cr as turnStartedEventType, Dn as assistantMessageCommittedEventType, Dr as userMessagePromotedEventType, Er as userMessageCommittedEventType, Fn as commandCompletedEventType, Hn as contextProjectedEventType, In as commandFailedEventType, Jn as inferenceCompletedEventType, Ln as commandStartedEventType, Mn as baseStateRequestedEventType, Nn as commandAdmittedEventType, On as assistantMessageImportedEventType, Or as userMessageSubmittedEventType, Pn as commandCancelledEventType, Qn as messageQueuePausedEventType, Rn as compactionCompletedEventType, Sr as turnFailedEventType, Tr as userMessageCancelledEventType, Un as contextRebasedEventType, Vn as compactionStartedEventType, Xn as inferenceStartedEventType, Yn as inferenceFailedEventType, Zn as interpretLegacyAttemptForReduction, _r as toolCallCreatedEventType, ar as runSchedulingGrantedEventType, br as toolCallStartedEventType, cr as runStartedEventType, dr as steeringMessageQueuedEventType, er as recoveryCompletedEventType, fr as stopTurnAppliedEventType, gr as toolCallCompletedEventType, hr as systemMessageCommittedEventType, ir as runSchedulingDeliveredEventType, jn as baseStateFailedEventType, kn as assistantPartialCommittedEventType, lr as sessionConfiguredEventType, mr as summaryCreatedEventType, nr as runFailedEventType, or as runSchedulingInvalidatedEventType, pr as stopTurnRequestedEventType, rr as runInterruptedEventType, sr as runSchedulingRequestedEventType,
|
|
1
|
+
import { CommandId } from "./types/core.js";
|
|
2
|
+
import { f as ProviderPartId, g as UnixEpochMillis, h as ToolName, l as ModelSelectionPayload, p as SchemaVersion, s as FailurePayload } from "./envelope-BCzKUq_z.js";
|
|
3
|
+
import { addModelUsage } from "./domain/model-usage.js";
|
|
4
|
+
import { CommandIdempotencyKey } from "./types/commands.js";
|
|
5
|
+
import { $n as pendingMessagesPausedEventType, An as baseStateCreatedEventType, Bn as compactionRequestedEventType, Cr as turnStartedEventType, Dn as assistantMessageCommittedEventType, Dr as userMessagePromotedEventType, Er as userMessageCommittedEventType, Fn as commandCompletedEventType, Hn as contextProjectedEventType, In as commandFailedEventType, Jn as inferenceCompletedEventType, Ln as commandStartedEventType, Mn as baseStateRequestedEventType, Nn as commandAdmittedEventType, On as assistantMessageImportedEventType, Or as userMessageSubmittedEventType, Pn as commandCancelledEventType, Qn as messageQueuePausedEventType, Rn as compactionCompletedEventType, Sr as turnFailedEventType, Tr as userMessageCancelledEventType, Un as contextRebasedEventType, Vn as compactionStartedEventType, Xn as inferenceStartedEventType, Yn as inferenceFailedEventType, Zn as interpretLegacyAttemptForReduction, _r as toolCallCreatedEventType, ar as runSchedulingGrantedEventType, br as toolCallStartedEventType, cr as runStartedEventType, dr as steeringMessageQueuedEventType, er as recoveryCompletedEventType, fr as stopTurnAppliedEventType, gr as toolCallCompletedEventType, hr as systemMessageCommittedEventType, ir as runSchedulingDeliveredEventType, jn as baseStateFailedEventType, kn as assistantPartialCommittedEventType, lr as sessionConfiguredEventType, mr as summaryCreatedEventType, nr as runFailedEventType, or as runSchedulingInvalidatedEventType, pr as stopTurnRequestedEventType, rr as runInterruptedEventType, sr as runSchedulingRequestedEventType, tr as runCompletedEventType, ur as steeringMessageCancelledEventType, vr as toolCallFailedEventType, wr as turnStoppedEventType, xr as turnCompletedEventType, yr as toolCallRejectedEventType, zn as compactionFailedEventType } from "./durable-CD__3ztN.js";
|
|
6
6
|
import { t as assertNever } from "./assert-never-CoyUpoRB.js";
|
|
7
|
-
import {
|
|
8
|
-
import * as Context from "effect/Context";
|
|
7
|
+
import { A as TranscriptRecordFromEnvelope, H as TranscriptVersion, K as runGroupStatus, O as TranscriptRecord, S as TranscriptDecorationKey, Y as transcriptRecordId, Z as sha256Hex, b as TranscriptDecorationEntryId, h as TranscriptClassification, w as TranscriptFieldPath } from "./records-DWKEjuqb.js";
|
|
9
8
|
import * as Effect from "effect/Effect";
|
|
10
9
|
import * as Schema from "effect/Schema";
|
|
11
|
-
import * as Order from "effect/Order";
|
|
12
|
-
import * as SchemaTransformation from "effect/SchemaTransformation";
|
|
13
|
-
import * as Result from "effect/Result";
|
|
14
|
-
import * as SchemaGetter from "effect/SchemaGetter";
|
|
15
|
-
//#region src/transcript/hash.ts
|
|
16
|
-
/**
|
|
17
|
-
* Synchronous hashing for transcript identities (versions and bounded record keys).
|
|
18
|
-
*/
|
|
19
|
-
const roundConstants = new Uint32Array([
|
|
20
|
-
1116352408,
|
|
21
|
-
1899447441,
|
|
22
|
-
3049323471,
|
|
23
|
-
3921009573,
|
|
24
|
-
961987163,
|
|
25
|
-
1508970993,
|
|
26
|
-
2453635748,
|
|
27
|
-
2870763221,
|
|
28
|
-
3624381080,
|
|
29
|
-
310598401,
|
|
30
|
-
607225278,
|
|
31
|
-
1426881987,
|
|
32
|
-
1925078388,
|
|
33
|
-
2162078206,
|
|
34
|
-
2614888103,
|
|
35
|
-
3248222580,
|
|
36
|
-
3835390401,
|
|
37
|
-
4022224774,
|
|
38
|
-
264347078,
|
|
39
|
-
604807628,
|
|
40
|
-
770255983,
|
|
41
|
-
1249150122,
|
|
42
|
-
1555081692,
|
|
43
|
-
1996064986,
|
|
44
|
-
2554220882,
|
|
45
|
-
2821834349,
|
|
46
|
-
2952996808,
|
|
47
|
-
3210313671,
|
|
48
|
-
3336571891,
|
|
49
|
-
3584528711,
|
|
50
|
-
113926993,
|
|
51
|
-
338241895,
|
|
52
|
-
666307205,
|
|
53
|
-
773529912,
|
|
54
|
-
1294757372,
|
|
55
|
-
1396182291,
|
|
56
|
-
1695183700,
|
|
57
|
-
1986661051,
|
|
58
|
-
2177026350,
|
|
59
|
-
2456956037,
|
|
60
|
-
2730485921,
|
|
61
|
-
2820302411,
|
|
62
|
-
3259730800,
|
|
63
|
-
3345764771,
|
|
64
|
-
3516065817,
|
|
65
|
-
3600352804,
|
|
66
|
-
4094571909,
|
|
67
|
-
275423344,
|
|
68
|
-
430227734,
|
|
69
|
-
506948616,
|
|
70
|
-
659060556,
|
|
71
|
-
883997877,
|
|
72
|
-
958139571,
|
|
73
|
-
1322822218,
|
|
74
|
-
1537002063,
|
|
75
|
-
1747873779,
|
|
76
|
-
1955562222,
|
|
77
|
-
2024104815,
|
|
78
|
-
2227730452,
|
|
79
|
-
2361852424,
|
|
80
|
-
2428436474,
|
|
81
|
-
2756734187,
|
|
82
|
-
3204031479,
|
|
83
|
-
3329325298
|
|
84
|
-
]);
|
|
85
|
-
const rotateRight = (value, bits) => value >>> bits | value << 32 - bits;
|
|
86
|
-
const at = (words, index) => words[index] ?? 0;
|
|
87
|
-
/** Lowercase hex SHA-256 of a string's UTF-8 bytes. */
|
|
88
|
-
const sha256Hex = (input) => {
|
|
89
|
-
const message = new TextEncoder().encode(input);
|
|
90
|
-
const bitLength = message.length * 8;
|
|
91
|
-
const paddedLength = Math.ceil((message.length + 9) / 64) * 64;
|
|
92
|
-
const padded = new Uint8Array(paddedLength);
|
|
93
|
-
padded.set(message);
|
|
94
|
-
padded[message.length] = 128;
|
|
95
|
-
const view = new DataView(padded.buffer);
|
|
96
|
-
view.setUint32(paddedLength - 8, Math.floor(bitLength / 4294967296));
|
|
97
|
-
view.setUint32(paddedLength - 4, bitLength >>> 0);
|
|
98
|
-
const hash = new Uint32Array([
|
|
99
|
-
1779033703,
|
|
100
|
-
3144134277,
|
|
101
|
-
1013904242,
|
|
102
|
-
2773480762,
|
|
103
|
-
1359893119,
|
|
104
|
-
2600822924,
|
|
105
|
-
528734635,
|
|
106
|
-
1541459225
|
|
107
|
-
]);
|
|
108
|
-
const schedule = /* @__PURE__ */ new Uint32Array(64);
|
|
109
|
-
for (let offset = 0; offset < paddedLength; offset += 64) {
|
|
110
|
-
for (let index = 0; index < 16; index += 1) schedule[index] = view.getUint32(offset + index * 4);
|
|
111
|
-
for (let index = 16; index < 64; index += 1) {
|
|
112
|
-
const w15 = at(schedule, index - 15);
|
|
113
|
-
const w2 = at(schedule, index - 2);
|
|
114
|
-
const s0 = rotateRight(w15, 7) ^ rotateRight(w15, 18) ^ w15 >>> 3;
|
|
115
|
-
const s1 = rotateRight(w2, 17) ^ rotateRight(w2, 19) ^ w2 >>> 10;
|
|
116
|
-
schedule[index] = at(schedule, index - 16) + s0 + at(schedule, index - 7) + s1;
|
|
117
|
-
}
|
|
118
|
-
const working = Uint32Array.from(hash);
|
|
119
|
-
for (let index = 0; index < 64; index += 1) {
|
|
120
|
-
const [a, b, c, d, e, f, g, h] = Array.from(working);
|
|
121
|
-
const s1 = rotateRight(e ?? 0, 6) ^ rotateRight(e ?? 0, 11) ^ rotateRight(e ?? 0, 25);
|
|
122
|
-
const choice = (e ?? 0) & (f ?? 0) ^ ~(e ?? 0) & (g ?? 0);
|
|
123
|
-
const t1 = (h ?? 0) + s1 + choice + at(roundConstants, index) + at(schedule, index);
|
|
124
|
-
const s0 = rotateRight(a ?? 0, 2) ^ rotateRight(a ?? 0, 13) ^ rotateRight(a ?? 0, 22);
|
|
125
|
-
const majority = (a ?? 0) & (b ?? 0) ^ (a ?? 0) & (c ?? 0) ^ (b ?? 0) & (c ?? 0);
|
|
126
|
-
working.set([
|
|
127
|
-
t1 + s0 + majority,
|
|
128
|
-
a ?? 0,
|
|
129
|
-
b ?? 0,
|
|
130
|
-
c ?? 0,
|
|
131
|
-
(d ?? 0) + t1,
|
|
132
|
-
e ?? 0,
|
|
133
|
-
f ?? 0,
|
|
134
|
-
g ?? 0
|
|
135
|
-
]);
|
|
136
|
-
}
|
|
137
|
-
for (let index = 0; index < 8; index += 1) hash[index] = at(hash, index) + at(working, index);
|
|
138
|
-
}
|
|
139
|
-
return Array.from(hash, (word) => word.toString(16).padStart(8, "0")).join("");
|
|
140
|
-
};
|
|
141
|
-
//#endregion
|
|
142
|
-
//#region src/transcript/records.ts
|
|
143
|
-
/** One logical user submission across every lifecycle state: `user:<commandId>`. */
|
|
144
|
-
const UserRecordId = Schema.TemplateLiteral(["user:", CommandId]);
|
|
145
|
-
/** One model inference's visible output: `assistant:<inferenceId>`. */
|
|
146
|
-
const InferenceAssistantRecordId = Schema.TemplateLiteral(["assistant:", InferenceId]);
|
|
147
|
-
/** Assistant context imported from another transport, keyed by its import event: `import:<eventId>`. */
|
|
148
|
-
const ImportAssistantRecordId = Schema.TemplateLiteral(["import:", EventId]);
|
|
149
|
-
/** Either assistant identity; both are top-level assistant records. */
|
|
150
|
-
const AssistantRecordId = Schema.Union([InferenceAssistantRecordId, ImportAssistantRecordId]);
|
|
151
|
-
/** The marker a context rebase leaves in history: `compaction:<compactionId>`. */
|
|
152
|
-
const CompactionRecordId = Schema.TemplateLiteral(["compaction:", CompactionId]);
|
|
153
|
-
/** A framework tool call, a dependency of its assistant: `tool:<toolCallId>`. */
|
|
154
|
-
const ToolRecordId = Schema.TemplateLiteral(["tool:", ToolCallId]);
|
|
155
|
-
/**
|
|
156
|
-
* A run plus every startup-recovery continuation of it: `run:<rootRunId>`.
|
|
157
|
-
*
|
|
158
|
-
* The id names the first run of the chain and never changes when a continuation joins.
|
|
159
|
-
*/
|
|
160
|
-
const RunGroupRecordId = Schema.TemplateLiteral(["run:", RunId]);
|
|
161
|
-
/** The session-context singleton. */
|
|
162
|
-
const SessionContextRecordId = Schema.Literal("session");
|
|
163
|
-
/**
|
|
164
|
-
* Internal holding record for decorations whose target user record does not exist yet.
|
|
165
|
-
*
|
|
166
|
-
* Hosts append decoration events before the command they describe (Gia submits
|
|
167
|
-
* `[author, attachments…, SubmitMessage]` in one batch), so the interpreter parks them under the
|
|
168
|
-
* association key and merges them when the user record is created. Never served by a window read.
|
|
169
|
-
*/
|
|
170
|
-
const DecorationBufferRecordId = Schema.TemplateLiteral([
|
|
171
|
-
"decorations:",
|
|
172
|
-
Schema.Literals(["command", "idempotencyKey"]),
|
|
173
|
-
":",
|
|
174
|
-
Schema.NonEmptyString.check(Schema.isMaxLength(512))
|
|
175
|
-
]);
|
|
176
|
-
/** Every transcript record identity this EDA release writes. */
|
|
177
|
-
const TranscriptRecordId = Schema.Union([
|
|
178
|
-
UserRecordId,
|
|
179
|
-
AssistantRecordId,
|
|
180
|
-
CompactionRecordId,
|
|
181
|
-
ToolRecordId,
|
|
182
|
-
RunGroupRecordId,
|
|
183
|
-
SessionContextRecordId,
|
|
184
|
-
DecorationBufferRecordId
|
|
185
|
-
]);
|
|
186
|
-
/** Constructors for record identities; the only place identities are spelled. */
|
|
187
|
-
const transcriptRecordId = {
|
|
188
|
-
user: (commandId) => `user:${commandId}`,
|
|
189
|
-
assistant: (inferenceId) => `assistant:${inferenceId}`,
|
|
190
|
-
import: (eventId) => `import:${eventId}`,
|
|
191
|
-
compaction: (compactionId) => `compaction:${compactionId}`,
|
|
192
|
-
tool: (toolCallId) => `tool:${toolCallId}`,
|
|
193
|
-
runGroup: (rootRunId) => `run:${rootRunId}`,
|
|
194
|
-
session: "session",
|
|
195
|
-
/**
|
|
196
|
-
* Keys longer than 256 characters (caller-owned idempotency keys) are hashed to stay bounded;
|
|
197
|
-
* keys starting with `#` are hashed too, so a literal key never collides with a hashed one.
|
|
198
|
-
*/
|
|
199
|
-
decorationBuffer: (association, key) => `decorations:${association}:${key.length > 0 && key.length <= 256 && !key.startsWith("#") ? key : `#sha256:${sha256Hex(key)}`}`
|
|
200
|
-
};
|
|
201
|
-
/**
|
|
202
|
-
* History position of a top-level record: the event that placed it and an ordinal among records
|
|
203
|
-
* placed by that same event. Assigned once and never moved.
|
|
204
|
-
*/
|
|
205
|
-
const TranscriptPosition = Schema.Struct({
|
|
206
|
-
anchorSeq: SequenceNumber,
|
|
207
|
-
ordinal: NonNegativeInt
|
|
208
|
-
});
|
|
209
|
-
/**
|
|
210
|
-
* Adapter-owned identity of one physical event log. A wiped log gets a new incarnation, which
|
|
211
|
-
* invalidates every cursor, chunk and body reference minted against the old one.
|
|
212
|
-
*/
|
|
213
|
-
const TranscriptLogIncarnation = Schema.NonEmptyString.pipe(Schema.brand("TranscriptLogIncarnation"));
|
|
214
|
-
/**
|
|
215
|
-
* Identity of one transcript interpretation: a hash of the EDA semantic revision and the host's
|
|
216
|
-
* canonical mapping data. Two sessions with equal versions interpret the same log identically.
|
|
217
|
-
*/
|
|
218
|
-
const TranscriptVersion = Schema.String.check(Schema.isPattern(/^[0-9a-f]{64}$/)).pipe(Schema.brand("TranscriptVersion"));
|
|
219
|
-
/**
|
|
220
|
-
* Paging cursor: a point in the total order `(anchorSeq, ordinal, recordId)`.
|
|
221
|
-
*
|
|
222
|
-
* A cursor is meaningful only for the incarnation and version that minted it; readers reject
|
|
223
|
-
* any other pairing rather than guess an equivalent point.
|
|
224
|
-
*/
|
|
225
|
-
const TranscriptCursor = Schema.Struct({
|
|
226
|
-
incarnation: TranscriptLogIncarnation,
|
|
227
|
-
version: TranscriptVersion,
|
|
228
|
-
anchorSeq: SequenceNumber,
|
|
229
|
-
ordinal: NonNegativeInt,
|
|
230
|
-
recordId: Schema.NonEmptyString
|
|
231
|
-
});
|
|
232
|
-
/** Total transcript order over top-level records. */
|
|
233
|
-
const TranscriptOrder = Order.Struct({
|
|
234
|
-
anchorSeq: Order.Number,
|
|
235
|
-
ordinal: Order.Number,
|
|
236
|
-
recordId: Order.String
|
|
237
|
-
});
|
|
238
|
-
/** A JSON path into an event payload; the empty path is the payload itself. */
|
|
239
|
-
const TranscriptFieldPath = Schema.Array(Schema.Union([Schema.String, NonNegativeInt]));
|
|
240
|
-
/** The immutable log location a body was read from. */
|
|
241
|
-
const TranscriptBodySource = Schema.Struct({
|
|
242
|
-
seq: SequenceNumber,
|
|
243
|
-
path: TranscriptFieldPath
|
|
244
|
-
});
|
|
245
|
-
/**
|
|
246
|
-
* Largest body a stored record holds inline, in canonical JSON bytes. Larger bodies are stored
|
|
247
|
-
* as references, which keeps every stored row far below a Durable Object's 2 MB value limit no
|
|
248
|
-
* matter how large an event payload is.
|
|
249
|
-
*/
|
|
250
|
-
const transcriptStoredInlineBodyLimit = 65536;
|
|
251
|
-
/**
|
|
252
|
-
* A potentially large body (tool parameters and results).
|
|
253
|
-
*
|
|
254
|
-
* Stored records hold a body inline up to `transcriptStoredInlineBodyLimit` and as a reference
|
|
255
|
-
* above it; a window read may also replace a smaller inline body with a reference. A reference
|
|
256
|
-
* points at the body's immutable source in the append-only log, so it stays resolvable after
|
|
257
|
-
* projection rows are rebuilt or deleted. The host authorizes reference resolution.
|
|
258
|
-
*/
|
|
259
|
-
const TranscriptBody = Schema.TaggedUnion({
|
|
260
|
-
Inline: {
|
|
261
|
-
value: Schema.Json,
|
|
262
|
-
source: TranscriptBodySource
|
|
263
|
-
},
|
|
264
|
-
Ref: {
|
|
265
|
-
source: TranscriptBodySource,
|
|
266
|
-
byteLength: NonNegativeInt
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
/** Host-defined decoration name, as written by a mapping operation. */
|
|
270
|
-
const TranscriptDecorationKey = Schema.String.check(Schema.isPattern(/^[A-Za-z][A-Za-z0-9_.-]{0,63}$/));
|
|
271
|
-
/** Key of one decoration list entry: an entry id or a host-assigned ordinal. */
|
|
272
|
-
const TranscriptDecorationEntryKey = Schema.Union([Schema.String.check(Schema.isMaxLength(256)), NonNegativeInt]);
|
|
273
|
-
/**
|
|
274
|
-
* A host decoration value: a JSON scalar/object, or a keyed list whose entries are replaced by id
|
|
275
|
-
* or ordinal. EDA treats the JSON as opaque; only the host gives it meaning.
|
|
276
|
-
*/
|
|
277
|
-
const TranscriptDecoration = Schema.TaggedUnion({
|
|
278
|
-
Value: { value: Schema.Json },
|
|
279
|
-
List: { entries: Schema.Array(Schema.Struct({
|
|
280
|
-
key: TranscriptDecorationEntryKey,
|
|
281
|
-
value: Schema.Json
|
|
282
|
-
})) }
|
|
283
|
-
});
|
|
284
|
-
/** Decorations of one record, keyed by host decoration name. */
|
|
285
|
-
const TranscriptDecorations = Schema.Record(TranscriptDecorationKey, TranscriptDecoration);
|
|
286
|
-
/** Host classification of a user record, such as an authenticated subagent notice. */
|
|
287
|
-
const TranscriptClassification = TranscriptDecorationKey;
|
|
288
|
-
const LifecycleTimingFields = {
|
|
289
|
-
startedAtMs: Schema.optionalKey(UnixEpochMillis),
|
|
290
|
-
terminalAtMs: Schema.optionalKey(UnixEpochMillis),
|
|
291
|
-
durationMs: Schema.optionalKey(NonNegativeInt)
|
|
292
|
-
};
|
|
293
|
-
/**
|
|
294
|
-
* Where a user submission is in its lifecycle.
|
|
295
|
-
*
|
|
296
|
-
* Only `Consumed` records are rendered in history. `Pending`, `Paused`, `Promoted` and `Steering`
|
|
297
|
-
* are waiting to be read by the agent and are served as dependencies. `Cancelled` records stay
|
|
298
|
-
* stored so their aliases resolve but are never rendered.
|
|
299
|
-
*/
|
|
300
|
-
const TranscriptUserState = Schema.TaggedUnion({
|
|
301
|
-
/** Admitted and queued for a later run. */
|
|
302
|
-
Pending: {},
|
|
303
|
-
/** Queued, but held because the user interrupted the run that would have read it. */
|
|
304
|
-
Paused: { byCommandId: CommandId },
|
|
305
|
-
/** Moved from the queue to steer the active run. */
|
|
306
|
-
Promoted: {},
|
|
307
|
-
/** Waiting to steer the active run. */
|
|
308
|
-
Steering: {},
|
|
309
|
-
/** Read by the agent; the record's position is the consumption point. */
|
|
310
|
-
Consumed: {
|
|
311
|
-
turnId: Schema.optionalKey(TurnId),
|
|
312
|
-
runId: Schema.optionalKey(RunId)
|
|
313
|
-
},
|
|
314
|
-
/** Withdrawn before the agent read it, or withdrawn from the model context. */
|
|
315
|
-
Cancelled: {
|
|
316
|
-
reason: Schema.String,
|
|
317
|
-
byCommandId: Schema.optionalKey(CommandId)
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
const UserBodyFields = {
|
|
321
|
-
commandId: CommandId,
|
|
322
|
-
/** Every message id that has carried this submission; a replacement id joins as an alias. */
|
|
323
|
-
messageIds: Schema.Array(MessageId),
|
|
324
|
-
idempotencyKey: Schema.optionalKey(CommandIdempotencyKey),
|
|
325
|
-
disposition: Schema.optionalKey(SubmitMessageDisposition),
|
|
326
|
-
/**
|
|
327
|
-
* JSON projection of the content: file bytes become data URLs, URLs become strings. Content is
|
|
328
|
-
* inline; file data belongs in host attachments rather than message content.
|
|
329
|
-
*/
|
|
330
|
-
content: JsonUserMessageContent,
|
|
331
|
-
state: TranscriptUserState,
|
|
332
|
-
/** Present when the submission arrived as steering for a specific run. */
|
|
333
|
-
steering: Schema.optionalKey(Schema.Struct({ runId: RunId })),
|
|
334
|
-
classification: Schema.optionalKey(TranscriptClassification),
|
|
335
|
-
decorations: TranscriptDecorations,
|
|
336
|
-
/** The first event that named this submission; pending users are served in this order. */
|
|
337
|
-
submittedSeq: SequenceNumber,
|
|
338
|
-
submittedAtMs: UnixEpochMillis,
|
|
339
|
-
/** Present exactly when `position` is: the record was consumed at some point. */
|
|
340
|
-
consumedAtMs: Schema.optionalKey(UnixEpochMillis)
|
|
341
|
-
};
|
|
342
|
-
/** Lifecycle of one assistant record. Imports are `Completed` from the start. */
|
|
343
|
-
const TranscriptAssistantLifecycle = Schema.TaggedUnion({
|
|
344
|
-
Streaming: {},
|
|
345
|
-
Completed: {
|
|
346
|
-
finishReason: Schema.optionalKey(Schema.String),
|
|
347
|
-
usage: Schema.optionalKey(UsagePayload)
|
|
348
|
-
},
|
|
349
|
-
Failed: { error: FailurePayload }
|
|
350
|
-
});
|
|
351
|
-
/**
|
|
352
|
-
* One ordered part of assistant output. Tool calls are references; their bodies live on the tool
|
|
353
|
-
* dependency. Part types this release does not render are kept as `Unknown` so ordering survives.
|
|
354
|
-
*/
|
|
355
|
-
const KnownAssistantPart = Schema.TaggedUnion({
|
|
356
|
-
Text: { text: Schema.String },
|
|
357
|
-
Reasoning: { text: Schema.String },
|
|
358
|
-
ToolCall: {
|
|
359
|
-
providerPartId: ProviderPartId,
|
|
360
|
-
toolName: ToolName,
|
|
361
|
-
providerExecuted: Schema.Boolean,
|
|
362
|
-
/** The framework tool record, once the call has been sealed into one. */
|
|
363
|
-
toolId: Schema.optionalKey(ToolRecordId)
|
|
364
|
-
},
|
|
365
|
-
/** Result of a provider-executed tool, which has no framework tool record. */
|
|
366
|
-
ToolResult: {
|
|
367
|
-
providerPartId: ProviderPartId,
|
|
368
|
-
toolName: ToolName,
|
|
369
|
-
isFailure: Schema.Boolean,
|
|
370
|
-
result: TranscriptBody
|
|
371
|
-
},
|
|
372
|
-
Unknown: { partType: Schema.String }
|
|
373
|
-
});
|
|
374
|
-
/** A part whose tag or shape this reader does not know keeps its place as `Unknown`. */
|
|
375
|
-
const knownAssistantPartTags = /* @__PURE__ */ new Set([
|
|
376
|
-
"Text",
|
|
377
|
-
"Reasoning",
|
|
378
|
-
"ToolCall",
|
|
379
|
-
"ToolResult",
|
|
380
|
-
"Unknown"
|
|
381
|
-
]);
|
|
382
|
-
const UnrecognizedAssistantPart = Schema.Struct({ _tag: Schema.String.check(Schema.makeFilter((tag) => !knownAssistantPartTags.has(tag) || "a known part tag must decode as that part")) }).pipe(Schema.decodeTo(Schema.toType(KnownAssistantPart.cases.Unknown), {
|
|
383
|
-
decode: SchemaGetter.transform((part) => ({
|
|
384
|
-
_tag: "Unknown",
|
|
385
|
-
partType: part._tag
|
|
386
|
-
})),
|
|
387
|
-
encode: SchemaGetter.transform((part) => ({ _tag: part.partType }))
|
|
388
|
-
}));
|
|
389
|
-
/**
|
|
390
|
-
* One ordered part of assistant output. A part tag this reader does not know decodes as
|
|
391
|
-
* `Unknown`, keeping its place; a malformed part with a known tag is a decode failure.
|
|
392
|
-
*/
|
|
393
|
-
const TranscriptAssistantPart = Schema.Union([KnownAssistantPart, UnrecognizedAssistantPart]);
|
|
394
|
-
const AssistantBodyFields = {
|
|
395
|
-
source: Schema.Literals(["inference", "import"]),
|
|
396
|
-
inferenceId: InferenceId,
|
|
397
|
-
runId: RunId,
|
|
398
|
-
turnId: TurnId,
|
|
399
|
-
/** Run group of the producing run; absent for imports and for runs the log never started. */
|
|
400
|
-
runGroupId: Schema.optionalKey(RunGroupRecordId),
|
|
401
|
-
messageId: Schema.optionalKey(MessageId),
|
|
402
|
-
lifecycle: TranscriptAssistantLifecycle,
|
|
403
|
-
parts: Schema.Array(TranscriptAssistantPart),
|
|
404
|
-
/** Present when the visible parts were preserved from an interrupted or failed inference. */
|
|
405
|
-
partial: Schema.optionalKey(Schema.Struct({ reason: Schema.String })),
|
|
406
|
-
...LifecycleTimingFields
|
|
407
|
-
};
|
|
408
|
-
const CompactionBodyFields = {
|
|
409
|
-
compactionId: CompactionId,
|
|
410
|
-
/** Reference to the summary artifact; the transcript never copies summary text. */
|
|
411
|
-
summaryId: SummaryId,
|
|
412
|
-
contextVersion: ContextVersion,
|
|
413
|
-
retainedFromContextSeq: SequenceNumber,
|
|
414
|
-
createdAtMs: UnixEpochMillis,
|
|
415
|
-
/** Set by the first `CompactionCompleted`; later completions add no token usage. */
|
|
416
|
-
completedAtMs: Schema.optionalKey(UnixEpochMillis)
|
|
417
|
-
};
|
|
418
|
-
/** Lifecycle of one framework tool call. The last terminal event wins. */
|
|
419
|
-
const TranscriptToolLifecycle = Schema.TaggedUnion({
|
|
420
|
-
Created: {},
|
|
421
|
-
Running: {},
|
|
422
|
-
Completed: { result: TranscriptBody },
|
|
423
|
-
Failed: { error: FailurePayload },
|
|
424
|
-
/** The call was not executable; terminal from creation. */
|
|
425
|
-
Rejected: {
|
|
426
|
-
reason: ToolCallRejectionReason,
|
|
427
|
-
message: Schema.String,
|
|
428
|
-
modelFeedback: Schema.String
|
|
429
|
-
}
|
|
430
|
-
});
|
|
431
|
-
const ToolBodyFields = {
|
|
432
|
-
toolCallId: ToolCallId,
|
|
433
|
-
assistantId: InferenceAssistantRecordId,
|
|
434
|
-
providerPartId: ProviderPartId,
|
|
435
|
-
toolName: ToolName,
|
|
436
|
-
providerExecuted: Schema.Boolean,
|
|
437
|
-
/** Absent for a rejected call: a rejection records only the model-facing feedback. */
|
|
438
|
-
params: Schema.optionalKey(TranscriptBody),
|
|
439
|
-
lifecycle: TranscriptToolLifecycle,
|
|
440
|
-
createdAtMs: UnixEpochMillis,
|
|
441
|
-
...LifecycleTimingFields
|
|
442
|
-
};
|
|
443
|
-
/** Outcome of one run inside a run group. */
|
|
444
|
-
const TranscriptRunOutcome = Schema.TaggedUnion({
|
|
445
|
-
Running: {},
|
|
446
|
-
Completed: {},
|
|
447
|
-
Failed: { error: FailurePayload },
|
|
448
|
-
/** Stopped by the user or by a runtime restart; a continuation may follow. */
|
|
449
|
-
Interrupted: { reason: Schema.String }
|
|
450
|
-
});
|
|
451
|
-
/** One run in a run group, in start order. */
|
|
452
|
-
const TranscriptRunMember = Schema.Struct({
|
|
453
|
-
runId: RunId,
|
|
454
|
-
commandIds: Schema.Array(CommandId),
|
|
455
|
-
modelSelection: ModelSelectionPayload,
|
|
456
|
-
outcome: TranscriptRunOutcome,
|
|
457
|
-
/** The interrupted run this one continues, as recorded by startup recovery. */
|
|
458
|
-
continuationOf: Schema.optionalKey(RunId),
|
|
459
|
-
...LifecycleTimingFields
|
|
460
|
-
});
|
|
461
|
-
const RunGroupBodyFields = {
|
|
462
|
-
rootRunId: RunId,
|
|
463
|
-
/** Every run of the chain in start order; the last member's outcome is the group's status. */
|
|
464
|
-
runs: Schema.NonEmptyArray(TranscriptRunMember)
|
|
465
|
-
};
|
|
466
|
-
const SessionContextBodyFields = {
|
|
467
|
-
/** The run currently executing, if any. */
|
|
468
|
-
activeRunId: Schema.optionalKey(RunId),
|
|
469
|
-
/** The compaction currently in progress, if any. */
|
|
470
|
-
activeCompactionId: Schema.optionalKey(CompactionId),
|
|
471
|
-
/** Session execution policy: the first configured or started model, as the runtime reads it. */
|
|
472
|
-
modelSelection: Schema.optionalKey(ModelSelectionPayload),
|
|
473
|
-
/** Model of the most recently started run. */
|
|
474
|
-
lastRunModelSelection: Schema.optionalKey(ModelSelectionPayload),
|
|
475
|
-
tokenUsage: TokenConsumptionState,
|
|
476
|
-
decorations: TranscriptDecorations
|
|
477
|
-
};
|
|
478
|
-
/** One decoration operation parked until its target exists, in arrival order. */
|
|
479
|
-
const TranscriptBufferedDecoration = Schema.Struct({
|
|
480
|
-
seq: SequenceNumber,
|
|
481
|
-
mapping: TranscriptDecorationKey,
|
|
482
|
-
/** Operation index within the mapping. */
|
|
483
|
-
operation: NonNegativeInt,
|
|
484
|
-
value: Schema.Json,
|
|
485
|
-
entryKey: Schema.optionalKey(TranscriptDecorationEntryKey)
|
|
486
|
-
});
|
|
487
|
-
/**
|
|
488
|
-
* Operations one decoration buffer keeps. Later operations for the same key are dropped, as are
|
|
489
|
-
* operations beyond the mapping bounds' decoration byte budget.
|
|
490
|
-
*/
|
|
491
|
-
const transcriptDecorationBufferLimit = 32;
|
|
492
|
-
const DecorationBufferBodyFields = { operations: Schema.Array(TranscriptBufferedDecoration).check(Schema.isMaxLength(32)) };
|
|
493
|
-
const commonFields = (kind, id) => ({
|
|
494
|
-
kind: Schema.tag(kind),
|
|
495
|
-
id,
|
|
496
|
-
/** The last event that contributed to this record. */
|
|
497
|
-
updatedSeq: SequenceNumber
|
|
498
|
-
});
|
|
499
|
-
/**
|
|
500
|
-
* User submission, top-level once consumed; waiting states are dependencies.
|
|
501
|
-
*
|
|
502
|
-
* A position is assigned once, when the agent first reads the submission, so a consumed record
|
|
503
|
-
* always has one and a waiting record never does. A cancelled record keeps the position it was
|
|
504
|
-
* consumed at, if any, and is never rendered.
|
|
505
|
-
*/
|
|
506
|
-
const TranscriptUserRecord = Schema.Struct({
|
|
507
|
-
...commonFields("user", UserRecordId),
|
|
508
|
-
position: Schema.optionalKey(TranscriptPosition),
|
|
509
|
-
...UserBodyFields
|
|
510
|
-
}).check(Schema.makeFilter((user) => user.position === void 0 === (user.consumedAtMs === void 0) || "position and consumedAtMs are assigned together"), Schema.makeFilter((user) => user.id === `user:${user.commandId}` || "a user record id names its command"), Schema.makeFilter((user) => {
|
|
511
|
-
switch (user.state._tag) {
|
|
512
|
-
case "Consumed": return user.position !== void 0 || "a consumed user record has a position";
|
|
513
|
-
case "Cancelled": return true;
|
|
514
|
-
default: return user.position === void 0 || "a waiting user record has no position";
|
|
515
|
-
}
|
|
516
|
-
}));
|
|
517
|
-
/** Assistant output of one inference or one import; top-level. */
|
|
518
|
-
const TranscriptAssistantRecord = Schema.Struct({
|
|
519
|
-
...commonFields("assistant", AssistantRecordId),
|
|
520
|
-
position: TranscriptPosition,
|
|
521
|
-
...AssistantBodyFields
|
|
522
|
-
}).check(Schema.makeFilter((assistant) => (assistant.source === "import" ? assistant.id.startsWith("import:") : assistant.id === `assistant:${assistant.inferenceId}`) || "an assistant record id matches its source and inference"));
|
|
523
|
-
/** Compaction marker; top-level. */
|
|
524
|
-
const TranscriptCompactionRecord = Schema.Struct({
|
|
525
|
-
...commonFields("compaction", CompactionRecordId),
|
|
526
|
-
position: TranscriptPosition,
|
|
527
|
-
...CompactionBodyFields
|
|
528
|
-
}).check(Schema.makeFilter((compaction) => compaction.id === `compaction:${compaction.compactionId}` || "a compaction record id names its compaction"));
|
|
529
|
-
/** Framework tool call; a dependency of its assistant record. */
|
|
530
|
-
const TranscriptToolRecord = Schema.Struct({
|
|
531
|
-
...commonFields("tool", ToolRecordId),
|
|
532
|
-
...ToolBodyFields
|
|
533
|
-
}).check(Schema.makeFilter((tool) => tool.id === `tool:${tool.toolCallId}` || "a tool record id names its tool call"));
|
|
534
|
-
/** Run and its recovery continuations; a dependency of the records it produced. */
|
|
535
|
-
const TranscriptRunGroupRecord = Schema.Struct({
|
|
536
|
-
...commonFields("runGroup", RunGroupRecordId),
|
|
537
|
-
...RunGroupBodyFields
|
|
538
|
-
}).check(Schema.makeFilter((group) => group.id === `run:${group.rootRunId}` && group.runs[0].runId === group.rootRunId || "a run group is named by, and starts with, its root run"));
|
|
539
|
-
/** A run group's status: the outcome of its latest run. */
|
|
540
|
-
const runGroupStatus = (group) => (group.runs[group.runs.length - 1] ?? group.runs[0]).outcome;
|
|
541
|
-
/** Session activity, model selection and token totals; a singleton dependency. */
|
|
542
|
-
const TranscriptSessionContextRecord = Schema.Struct({
|
|
543
|
-
...commonFields("sessionContext", SessionContextRecordId),
|
|
544
|
-
...SessionContextBodyFields
|
|
545
|
-
});
|
|
546
|
-
/** Internal decoration holding record; stored, never served. */
|
|
547
|
-
const TranscriptDecorationBufferRecord = Schema.Struct({
|
|
548
|
-
...commonFields("decorationBuffer", DecorationBufferRecordId),
|
|
549
|
-
...DecorationBufferBodyFields
|
|
550
|
-
});
|
|
551
|
-
/** Every record kind this EDA release stores. */
|
|
552
|
-
const TranscriptRecord = Schema.Union([
|
|
553
|
-
TranscriptUserRecord,
|
|
554
|
-
TranscriptAssistantRecord,
|
|
555
|
-
TranscriptCompactionRecord,
|
|
556
|
-
TranscriptToolRecord,
|
|
557
|
-
TranscriptRunGroupRecord,
|
|
558
|
-
TranscriptSessionContextRecord,
|
|
559
|
-
TranscriptDecorationBufferRecord
|
|
560
|
-
]);
|
|
561
|
-
/**
|
|
562
|
-
* A record this reader cannot interpret: a newer kind, or a body written by a newer EDA.
|
|
563
|
-
*
|
|
564
|
-
* It keeps the identity, position and revision so a client can hold its place and render a safe
|
|
565
|
-
* placeholder. Storage readers do not produce it: an undecodable stored row makes a read
|
|
566
|
-
* unavailable instead of wrong.
|
|
567
|
-
*/
|
|
568
|
-
const TranscriptUnknownRecord = Schema.Struct({
|
|
569
|
-
kind: Schema.tag("unknown"),
|
|
570
|
-
originalKind: Schema.NonEmptyString,
|
|
571
|
-
/** The envelope format it arrived in, kept so it re-encodes exactly as it was read. */
|
|
572
|
-
format: Schema.Int.check(Schema.isGreaterThanOrEqualTo(1)),
|
|
573
|
-
/** The uninterpreted body, kept so a relaying reader forwards it unchanged. */
|
|
574
|
-
body: Schema.Record(Schema.String, Schema.Unknown),
|
|
575
|
-
id: Schema.NonEmptyString,
|
|
576
|
-
updatedSeq: SequenceNumber,
|
|
577
|
-
position: Schema.optionalKey(TranscriptPosition)
|
|
578
|
-
});
|
|
579
|
-
/** Top-level kinds count toward a window's record limit and carry a position. */
|
|
580
|
-
const isTopLevelTranscriptRecord = (record) => record.kind === "assistant" || record.kind === "compaction" || record.kind === "user" && record.state._tag === "Consumed" && record.position !== void 0;
|
|
581
|
-
/** A user record still waiting for the agent; served as a dependency, never twice. */
|
|
582
|
-
const isPendingTranscriptUserRecord = (record) => record.kind === "user" && (record.state._tag === "Pending" || record.state._tag === "Paused" || record.state._tag === "Promoted" || record.state._tag === "Steering");
|
|
583
|
-
/**
|
|
584
|
-
* Current stored-row envelope format. Readers accept every format up to this one.
|
|
585
|
-
*
|
|
586
|
-
* Bump it whenever a known kind gains a value an older reader of this format could not decode
|
|
587
|
-
* (a new lifecycle or state tag, a new required field). Older readers then show such rows as
|
|
588
|
-
* `unknown` records; without a bump, a strict older reader would reject the whole window.
|
|
589
|
-
*/
|
|
590
|
-
const transcriptRecordEnvelopeFormat = 1;
|
|
591
|
-
/**
|
|
592
|
-
* Backward-readable row and wire shape for one record.
|
|
593
|
-
*
|
|
594
|
-
* Identity, kind, revision and position sit outside the kind-specific `body` so any reader can
|
|
595
|
-
* place a record it cannot interpret.
|
|
596
|
-
*/
|
|
597
|
-
const TranscriptRecordEnvelope = Schema.Struct({
|
|
598
|
-
format: Schema.Int.check(Schema.isGreaterThanOrEqualTo(1)),
|
|
599
|
-
kind: Schema.NonEmptyString,
|
|
600
|
-
id: Schema.NonEmptyString,
|
|
601
|
-
updatedSeq: SequenceNumber,
|
|
602
|
-
position: Schema.optionalKey(TranscriptPosition),
|
|
603
|
-
body: Schema.Record(Schema.String, Schema.Unknown)
|
|
604
|
-
});
|
|
605
|
-
const envelopeToFlat = (envelope) => {
|
|
606
|
-
const { kind, id, updatedSeq, position, body } = envelope;
|
|
607
|
-
const { kind: _kind, id: _id, updatedSeq: _updatedSeq, position: _position, ...fields } = body;
|
|
608
|
-
return {
|
|
609
|
-
...fields,
|
|
610
|
-
kind,
|
|
611
|
-
id,
|
|
612
|
-
updatedSeq,
|
|
613
|
-
...position === void 0 ? {} : { position }
|
|
614
|
-
};
|
|
615
|
-
};
|
|
616
|
-
const flatToEnvelope = (record) => {
|
|
617
|
-
const { kind, id, updatedSeq, position, ...body } = record;
|
|
618
|
-
return Schema.decodeUnknownSync(TranscriptRecordEnvelope)({
|
|
619
|
-
format: 1,
|
|
620
|
-
kind,
|
|
621
|
-
id,
|
|
622
|
-
updatedSeq,
|
|
623
|
-
...position === void 0 ? {} : { position },
|
|
624
|
-
body
|
|
625
|
-
});
|
|
626
|
-
};
|
|
627
|
-
const FlatRecordFields = Schema.Record(Schema.String, Schema.Unknown);
|
|
628
|
-
/** A known record stored or sent as its envelope. Decoding fails for anything this reader cannot interpret. */
|
|
629
|
-
const TranscriptRecordFromEnvelope = TranscriptRecordEnvelope.check(Schema.makeFilter((envelope) => envelope.format <= 1 || `unsupported transcript record envelope format ${envelope.format}`)).pipe(Schema.decodeTo(FlatRecordFields, {
|
|
630
|
-
decode: SchemaGetter.transform(envelopeToFlat),
|
|
631
|
-
encode: SchemaGetter.transform(flatToEnvelope)
|
|
632
|
-
}), Schema.decodeTo(TranscriptRecord, SchemaTransformation.passthroughSupertype()));
|
|
633
|
-
const knownRecordKinds = /* @__PURE__ */ new Set([
|
|
634
|
-
"user",
|
|
635
|
-
"assistant",
|
|
636
|
-
"compaction",
|
|
637
|
-
"tool",
|
|
638
|
-
"runGroup",
|
|
639
|
-
"sessionContext",
|
|
640
|
-
"decorationBuffer"
|
|
641
|
-
]);
|
|
642
|
-
/**
|
|
643
|
-
* Only a kind this reader does not know, or a newer envelope format, becomes `unknown`; a
|
|
644
|
-
* malformed record of a known kind in a known format is a decode failure, never a placeholder.
|
|
645
|
-
*/
|
|
646
|
-
const TranscriptUnknownRecordFromEnvelope = TranscriptRecordEnvelope.check(Schema.makeFilter((envelope) => !knownRecordKinds.has(envelope.kind) || envelope.format > 1 || `a ${envelope.kind} record in format ${envelope.format} must decode as that kind`)).pipe(Schema.decodeTo(TranscriptUnknownRecord, {
|
|
647
|
-
decode: SchemaGetter.transform((envelope) => ({
|
|
648
|
-
kind: "unknown",
|
|
649
|
-
originalKind: envelope.kind,
|
|
650
|
-
format: envelope.format,
|
|
651
|
-
body: envelope.body,
|
|
652
|
-
id: envelope.id,
|
|
653
|
-
updatedSeq: envelope.updatedSeq,
|
|
654
|
-
...envelope.position === void 0 ? {} : { position: envelope.position }
|
|
655
|
-
})),
|
|
656
|
-
encode: SchemaGetter.transform((record) => Schema.decodeUnknownSync(TranscriptRecordEnvelope)({
|
|
657
|
-
format: record.format,
|
|
658
|
-
kind: record.originalKind,
|
|
659
|
-
id: record.id,
|
|
660
|
-
updatedSeq: record.updatedSeq,
|
|
661
|
-
...record.position === void 0 ? {} : { position: record.position },
|
|
662
|
-
body: record.body
|
|
663
|
-
}))
|
|
664
|
-
}));
|
|
665
|
-
/**
|
|
666
|
-
* Wire codec for one record: a known record when this reader can interpret it, otherwise an
|
|
667
|
-
* explicit unknown record that keeps its id and position.
|
|
668
|
-
*/
|
|
669
|
-
const TranscriptRecordViewFromEnvelope = Schema.Union([TranscriptRecordFromEnvelope, TranscriptUnknownRecordFromEnvelope]);
|
|
670
|
-
//#endregion
|
|
671
10
|
//#region src/transcript/version.ts
|
|
672
11
|
/**
|
|
673
12
|
* EDA's transcript semantic revision.
|
|
@@ -680,8 +19,11 @@ const TranscriptRecordViewFromEnvelope = Schema.Union([TranscriptRecordFromEnvel
|
|
|
680
19
|
*
|
|
681
20
|
* A CI fingerprint over a fixed scenario corpus (added with the interpreter) fails when
|
|
682
21
|
* interpretation output changes and this constant does not; re-record it together with the bump.
|
|
22
|
+
*
|
|
23
|
+
* History: 1 — the initial interpreter (0.1.0-alpha.22). 2 — submissions consumed by one turn are
|
|
24
|
+
* ordered by submission, as the prompt orders them, not by the turn's input list.
|
|
683
25
|
*/
|
|
684
|
-
const transcriptSemanticRevision =
|
|
26
|
+
const transcriptSemanticRevision = 2;
|
|
685
27
|
/**
|
|
686
28
|
* Deterministic JSON: object keys sorted by code unit, no whitespace. Only JSON values are
|
|
687
29
|
* accepted, so equal data always produces equal bytes.
|
|
@@ -754,7 +96,16 @@ const TranscriptListEntryKey = Schema.TaggedUnion({
|
|
|
754
96
|
/** A string id at this payload path (for example an attachment id). */
|
|
755
97
|
Id: { path: MappingPath },
|
|
756
98
|
/** A non-negative integer ordinal at this payload path; the list is kept in ordinal order. */
|
|
757
|
-
Ordinal: { path: MappingPath }
|
|
99
|
+
Ordinal: { path: MappingPath },
|
|
100
|
+
/**
|
|
101
|
+
* An id and an ordinal; the list is kept in ordinal order. A new entry replaces every entry with
|
|
102
|
+
* the same id **or** the same ordinal, so an input retried with new ids, or in a different
|
|
103
|
+
* order, never leaves a stale duplicate (attachments and references keyed by both).
|
|
104
|
+
*/
|
|
105
|
+
IdOrOrdinal: {
|
|
106
|
+
id: MappingPath,
|
|
107
|
+
ordinal: MappingPath
|
|
108
|
+
}
|
|
758
109
|
});
|
|
759
110
|
/** One declarative decoration operation. Every `from` path reads the authenticated event payload. */
|
|
760
111
|
const TranscriptMappingOperation = Schema.TaggedUnion({
|
|
@@ -768,7 +119,7 @@ const TranscriptMappingOperation = Schema.TaggedUnion({
|
|
|
768
119
|
from: MappingPath,
|
|
769
120
|
to: TranscriptDecorationKey
|
|
770
121
|
},
|
|
771
|
-
/** Insert or replace one entry of a decoration list, keyed by id or
|
|
122
|
+
/** Insert or replace one entry of a decoration list, keyed by id, ordinal, or either. */
|
|
772
123
|
ReplaceListEntry: {
|
|
773
124
|
from: MappingPath,
|
|
774
125
|
to: TranscriptDecorationKey,
|
|
@@ -875,7 +226,7 @@ var TranscriptDefinition = class TranscriptDefinition {
|
|
|
875
226
|
const mappings = yield* Schema.decodeUnknownEffect(TranscriptMappings)(input).pipe(Effect.mapError((error) => new TranscriptDefinitionError({ message: error.message })));
|
|
876
227
|
const problems = validationProblems(mappings);
|
|
877
228
|
if (problems.length > 0) return yield* new TranscriptDefinitionError({ message: problems.join("; ") });
|
|
878
|
-
return new TranscriptDefinition(computeTranscriptVersion(
|
|
229
|
+
return new TranscriptDefinition(computeTranscriptVersion(2, Schema.encodeSync(TranscriptMappings)(mappings)), 2, mappings);
|
|
879
230
|
});
|
|
880
231
|
};
|
|
881
232
|
/** Validate host mapping data and derive its transcript version; see `TranscriptDefinition.make`. */
|
|
@@ -984,21 +335,44 @@ const prepareOperation = (mapping, operation, index, payload) => {
|
|
|
984
335
|
}
|
|
985
336
|
case "ReplaceListEntry": {
|
|
986
337
|
const value = boundedJson(extract(payload, operation.from));
|
|
987
|
-
const
|
|
988
|
-
return value === void 0 ||
|
|
338
|
+
const entry = listEntryKey(operation.key, payload);
|
|
339
|
+
return value === void 0 || entry === void 0 ? [] : [{
|
|
989
340
|
mapping,
|
|
990
341
|
operation: index,
|
|
991
342
|
value,
|
|
992
|
-
entryKey
|
|
343
|
+
entryKey: entry.key,
|
|
344
|
+
...entry.id === void 0 ? {} : { entryId: entry.id }
|
|
993
345
|
}];
|
|
994
346
|
}
|
|
995
347
|
}
|
|
996
348
|
};
|
|
349
|
+
const entryIdAt = (payload, path) => {
|
|
350
|
+
const value = extract(payload, path);
|
|
351
|
+
return typeof value === "string" && Schema.is(TranscriptDecorationEntryId)(value) ? value : void 0;
|
|
352
|
+
};
|
|
353
|
+
const ordinalAt = (payload, path) => {
|
|
354
|
+
const value = extract(payload, path);
|
|
355
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : void 0;
|
|
356
|
+
};
|
|
357
|
+
/** The entry's list key, and its id when the list is keyed by id or ordinal. */
|
|
997
358
|
const listEntryKey = (key, payload) => {
|
|
998
|
-
const value = extract(payload, key.path);
|
|
999
359
|
switch (key._tag) {
|
|
1000
|
-
case "Id":
|
|
1001
|
-
|
|
360
|
+
case "Id": {
|
|
361
|
+
const id = entryIdAt(payload, key.path);
|
|
362
|
+
return id === void 0 ? void 0 : { key: id };
|
|
363
|
+
}
|
|
364
|
+
case "Ordinal": {
|
|
365
|
+
const ordinal = ordinalAt(payload, key.path);
|
|
366
|
+
return ordinal === void 0 ? void 0 : { key: ordinal };
|
|
367
|
+
}
|
|
368
|
+
case "IdOrOrdinal": {
|
|
369
|
+
const id = entryIdAt(payload, key.id);
|
|
370
|
+
const ordinal = ordinalAt(payload, key.ordinal);
|
|
371
|
+
return id === void 0 || ordinal === void 0 ? void 0 : {
|
|
372
|
+
key: ordinal,
|
|
373
|
+
id
|
|
374
|
+
};
|
|
375
|
+
}
|
|
1002
376
|
}
|
|
1003
377
|
};
|
|
1004
378
|
const park = (batch, seq, association, key, prepared) => {
|
|
@@ -1043,7 +417,7 @@ const replayBufferedDecorations = (batch, seq, user) => {
|
|
|
1043
417
|
...decorations,
|
|
1044
418
|
[fallback.to]: source
|
|
1045
419
|
};
|
|
1046
|
-
if (jsonBytes
|
|
420
|
+
if (jsonBytes(next) <= transcriptMappingBounds.maxDecorationBytes) decorations = next;
|
|
1047
421
|
}
|
|
1048
422
|
}
|
|
1049
423
|
return decorations === decorated.decorations ? decorated : {
|
|
@@ -1068,7 +442,7 @@ const withinBudget = (operations) => {
|
|
|
1068
442
|
const kept = [];
|
|
1069
443
|
let bytes = 2;
|
|
1070
444
|
for (const operation of operations.slice(0, 32)) {
|
|
1071
|
-
bytes += jsonBytes
|
|
445
|
+
bytes += jsonBytes(operation) + 1;
|
|
1072
446
|
if (bytes > transcriptMappingBounds.maxDecorationBytes) break;
|
|
1073
447
|
kept.push(operation);
|
|
1074
448
|
}
|
|
@@ -1077,9 +451,9 @@ const withinBudget = (operations) => {
|
|
|
1077
451
|
/** Apply one operation unless the record's decorations would exceed their byte budget. */
|
|
1078
452
|
const applyPrepared = (definition, target, prepared) => {
|
|
1079
453
|
const next = applyOperation(definition, target, prepared);
|
|
1080
|
-
return next === target || jsonBytes
|
|
454
|
+
return next === target || jsonBytes(next.decorations) <= transcriptMappingBounds.maxDecorationBytes ? next : target;
|
|
1081
455
|
};
|
|
1082
|
-
const jsonBytes
|
|
456
|
+
const jsonBytes = (value) => encoder.encode(canonicalJson(value)).length;
|
|
1083
457
|
const applyOperation = (definition, target, prepared) => {
|
|
1084
458
|
const operation = mappingIndex(definition).byName.get(prepared.mapping)?.operations[prepared.operation];
|
|
1085
459
|
if (operation === void 0) return target;
|
|
@@ -1098,7 +472,7 @@ const applyOperation = (definition, target, prepared) => {
|
|
|
1098
472
|
}) : target;
|
|
1099
473
|
case "ReplaceListEntry": {
|
|
1100
474
|
if (prepared.entryKey === void 0) return target;
|
|
1101
|
-
const list = replaceListEntry(target.decorations[operation.to], prepared.entryKey, prepared.value, operation.key._tag === "
|
|
475
|
+
const list = replaceListEntry(target.decorations[operation.to], prepared.entryKey, prepared.value, operation.key._tag !== "Id", operation.key._tag === "IdOrOrdinal" ? prepared.entryId : void 0);
|
|
1102
476
|
return list === void 0 ? target : withDecoration(target, operation.to, list);
|
|
1103
477
|
}
|
|
1104
478
|
}
|
|
@@ -1110,8 +484,20 @@ const withDecoration = (target, key, decoration) => ({
|
|
|
1110
484
|
[key]: decoration
|
|
1111
485
|
}
|
|
1112
486
|
});
|
|
1113
|
-
const replaceListEntry = (existing, key, value, ordered) => {
|
|
487
|
+
const replaceListEntry = (existing, key, value, ordered, id) => {
|
|
1114
488
|
const entries = existing?._tag === "List" ? existing.entries : [];
|
|
489
|
+
if (id !== void 0) {
|
|
490
|
+
const kept = entries.filter((entry) => entry.key !== key && entry.id !== id);
|
|
491
|
+
if (kept.length === entries.length && entries.length >= transcriptMappingBounds.maxListEntries) return;
|
|
492
|
+
return {
|
|
493
|
+
_tag: "List",
|
|
494
|
+
entries: [...kept, {
|
|
495
|
+
key,
|
|
496
|
+
value,
|
|
497
|
+
id
|
|
498
|
+
}].sort((left, right) => Number(left.key) - Number(right.key))
|
|
499
|
+
};
|
|
500
|
+
}
|
|
1115
501
|
const index = entries.findIndex((entry) => entry.key === key);
|
|
1116
502
|
if (index >= 0) return {
|
|
1117
503
|
_tag: "List",
|
|
@@ -1137,7 +523,7 @@ const extract = (value, path) => path.reduce((current, key) => {
|
|
|
1137
523
|
if (current === null || typeof current !== "object" || Array.isArray(current)) return;
|
|
1138
524
|
return Object.getOwnPropertyDescriptor(current, key)?.value;
|
|
1139
525
|
}, value);
|
|
1140
|
-
const encoder
|
|
526
|
+
const encoder = new TextEncoder();
|
|
1141
527
|
/**
|
|
1142
528
|
* A payload value as the JSON a persisted log holds (so a live projection and a rebuild agree),
|
|
1143
529
|
* within the value bound; otherwise nothing.
|
|
@@ -1148,7 +534,7 @@ const boundedJson = (value) => {
|
|
|
1148
534
|
const json = JSON.stringify(value);
|
|
1149
535
|
if (json === void 0) return void 0;
|
|
1150
536
|
const normalized = JSON.parse(json);
|
|
1151
|
-
return Schema.is(Schema.Json)(normalized) && encoder
|
|
537
|
+
return Schema.is(Schema.Json)(normalized) && encoder.encode(canonicalJson(normalized)).length <= transcriptMappingBounds.maxValueBytes ? normalized : void 0;
|
|
1152
538
|
} catch {
|
|
1153
539
|
return;
|
|
1154
540
|
}
|
|
@@ -1248,7 +634,7 @@ var TranscriptBatch = class {
|
|
|
1248
634
|
};
|
|
1249
635
|
const aliasKey = (namespace, key) => `${namespace}\u0000${key}`;
|
|
1250
636
|
const matchesRecordSchema = Schema.is(TranscriptRecord);
|
|
1251
|
-
const encodeRecord
|
|
637
|
+
const encodeRecord = Schema.encodeSync(TranscriptRecordFromEnvelope);
|
|
1252
638
|
const describeCause = (cause) => cause instanceof Error ? cause.message : String(cause);
|
|
1253
639
|
/**
|
|
1254
640
|
* Why a record could not be stored, if it could not: it must satisfy the stored-row schema,
|
|
@@ -1258,7 +644,7 @@ const describeCause = (cause) => cause instanceof Error ? cause.message : String
|
|
|
1258
644
|
const storageProblem = (record) => {
|
|
1259
645
|
let envelope;
|
|
1260
646
|
try {
|
|
1261
|
-
envelope = encodeRecord
|
|
647
|
+
envelope = encodeRecord(record);
|
|
1262
648
|
} catch (cause) {
|
|
1263
649
|
return `does not satisfy the transcript record schema: ${describeCause(cause)}`;
|
|
1264
650
|
}
|
|
@@ -1435,15 +821,18 @@ const interpretEvent = (batch, entry, seq) => {
|
|
|
1435
821
|
}
|
|
1436
822
|
case turnStartedEventType: {
|
|
1437
823
|
const { runId, turnId, inputMessageIds } = event.payload;
|
|
824
|
+
const consumed = /* @__PURE__ */ new Map();
|
|
1438
825
|
for (const messageId of inputMessageIds ?? []) {
|
|
1439
826
|
const user = userByMessage(batch, messageId);
|
|
1440
827
|
if (user === void 0 || user.state._tag === "Consumed") continue;
|
|
1441
828
|
if (user.state._tag === "Cancelled" && user.steering === void 0) continue;
|
|
1442
|
-
|
|
1443
|
-
runId,
|
|
1444
|
-
turnId
|
|
1445
|
-
}));
|
|
829
|
+
consumed.set(user.id, user);
|
|
1446
830
|
}
|
|
831
|
+
const ordered = [...consumed.values()].sort((left, right) => left.submittedSeq - right.submittedSeq || (left.id < right.id ? -1 : left.id > right.id ? 1 : 0));
|
|
832
|
+
for (const user of ordered) batch.put(consume(batch, user, seq, at, {
|
|
833
|
+
runId,
|
|
834
|
+
turnId
|
|
835
|
+
}));
|
|
1447
836
|
return;
|
|
1448
837
|
}
|
|
1449
838
|
case assistantMessageCommittedEventType:
|
|
@@ -1993,181 +1382,6 @@ const jsonFailure = (error) => {
|
|
|
1993
1382
|
};
|
|
1994
1383
|
const mapNonEmpty = (items, f) => [f(items[0]), ...items.slice(1).map(f)];
|
|
1995
1384
|
//#endregion
|
|
1996
|
-
|
|
1997
|
-
/** A cursor minted for another log incarnation or transcript version. The client takes `Latest`. */
|
|
1998
|
-
var TranscriptCursorMismatch = class extends Schema.TaggedError()("TranscriptCursorMismatch", { message: Schema.String }) {};
|
|
1999
|
-
/** Transcript read port, provided alongside `EDASessionStore` by stores that maintain transcripts. */
|
|
2000
|
-
var EDATranscriptStore = class extends Context.Service()("@effect-durable-agent/EDATranscriptStore") {};
|
|
2001
|
-
//#endregion
|
|
2002
|
-
//#region src/transcript/window-read.ts
|
|
2003
|
-
/** Readiness of a served version: why its cut may be behind the log. */
|
|
2004
|
-
const transcriptReadiness = (meta, carried) => {
|
|
2005
|
-
if (!carried) return { _tag: "UpdatingHistory" };
|
|
2006
|
-
switch (meta.status._tag) {
|
|
2007
|
-
case "Ok": return { _tag: "Ready" };
|
|
2008
|
-
case "Failed": return {
|
|
2009
|
-
_tag: "Degraded",
|
|
2010
|
-
failedAtSeq: meta.status.failedAtSeq,
|
|
2011
|
-
error: meta.status.error
|
|
2012
|
-
};
|
|
2013
|
-
}
|
|
2014
|
-
};
|
|
2015
|
-
/** The empty window served while no version is servable yet. */
|
|
2016
|
-
const buildingTranscriptWindow = (incarnation, version) => ({
|
|
2017
|
-
incarnation,
|
|
2018
|
-
version,
|
|
2019
|
-
throughSeq: SequenceNumber.make(0),
|
|
2020
|
-
records: [],
|
|
2021
|
-
dependencies: [],
|
|
2022
|
-
hasOlder: false,
|
|
2023
|
-
hasNewer: false,
|
|
2024
|
-
readiness: { _tag: "Building" }
|
|
2025
|
-
});
|
|
2026
|
-
const orderKey = (record) => ({
|
|
2027
|
-
anchorSeq: record.position?.anchorSeq ?? 0,
|
|
2028
|
-
ordinal: record.position?.ordinal ?? 0,
|
|
2029
|
-
recordId: record.id
|
|
2030
|
-
});
|
|
2031
|
-
const cursorKey = (cursor) => ({
|
|
2032
|
-
anchorSeq: cursor.anchorSeq,
|
|
2033
|
-
ordinal: cursor.ordinal,
|
|
2034
|
-
recordId: cursor.recordId
|
|
2035
|
-
});
|
|
2036
|
-
/**
|
|
2037
|
-
* Assemble one window from a source at a single cut.
|
|
2038
|
-
*
|
|
2039
|
-
* The response never contains anything newer than the served version's cursor: a frozen (failed
|
|
2040
|
-
* or no longer carried) version's rows, pending users and session context all stop at its last
|
|
2041
|
-
* good cut, which is the degraded-read rule. Bodies above the inline limit become references;
|
|
2042
|
-
* if the response still exceeds the byte budget, records are dropped from the far end of the
|
|
2043
|
-
* selection, keeping at least one so paging always progresses.
|
|
2044
|
-
*/
|
|
2045
|
-
const readTranscriptWindowFrom = (source, selector, limits) => {
|
|
2046
|
-
const version = source.meta.version;
|
|
2047
|
-
for (const cursor of selectorCursors(selector)) if (cursor.incarnation !== source.incarnation || cursor.version !== version) return Result.fail(new TranscriptCursorMismatch({ message: `cursor for ${cursor.incarnation}/${cursor.version} read against ${source.incarnation}/${version}` }));
|
|
2048
|
-
const selected = selectTopLevel(source, selector, limits.maxRecords);
|
|
2049
|
-
const keepNewest = selector._tag === "Latest" || selector._tag === "Page" && selector.direction === "before";
|
|
2050
|
-
let top = selected.map((record) => withBodyRefs(record, limits.maxInlineBodyBytes));
|
|
2051
|
-
let dependencies = collectDependencies(source, top, limits.maxInlineBodyBytes);
|
|
2052
|
-
while (top.length > 1 && windowBytes(top, dependencies) > limits.maxBytes) {
|
|
2053
|
-
top = keepNewest ? top.slice(1) : top.slice(0, -1);
|
|
2054
|
-
dependencies = collectDependencies(source, top, limits.maxInlineBodyBytes);
|
|
2055
|
-
}
|
|
2056
|
-
const first = top[0];
|
|
2057
|
-
const last = top[top.length - 1];
|
|
2058
|
-
const [hasOlder, hasNewer] = first === void 0 || last === void 0 ? emptySelectionNeighbours(source, selector) : [source.topLevelBefore(orderKey(first), 1, false).length > 0, source.topLevelAfter(orderKey(last), 1, false).length > 0];
|
|
2059
|
-
return Result.succeed({
|
|
2060
|
-
incarnation: source.incarnation,
|
|
2061
|
-
version,
|
|
2062
|
-
throughSeq: source.meta.cursor,
|
|
2063
|
-
records: top,
|
|
2064
|
-
dependencies,
|
|
2065
|
-
hasOlder,
|
|
2066
|
-
hasNewer,
|
|
2067
|
-
readiness: transcriptReadiness(source.meta, source.carried)
|
|
2068
|
-
});
|
|
2069
|
-
};
|
|
2070
|
-
const selectorCursors = (selector) => {
|
|
2071
|
-
switch (selector._tag) {
|
|
2072
|
-
case "Latest": return [];
|
|
2073
|
-
case "Page": return [selector.cursor];
|
|
2074
|
-
case "Range": return [selector.from, selector.to];
|
|
2075
|
-
}
|
|
2076
|
-
};
|
|
2077
|
-
const selectTopLevel = (source, selector, maxRecords) => {
|
|
2078
|
-
switch (selector._tag) {
|
|
2079
|
-
case "Latest": return [...source.topLevelBefore(void 0, Math.min(selector.count, maxRecords), false)].reverse();
|
|
2080
|
-
case "Page": {
|
|
2081
|
-
const count = Math.min(selector.count, maxRecords);
|
|
2082
|
-
return selector.direction === "before" ? [...source.topLevelBefore(cursorKey(selector.cursor), count, false)].reverse() : source.topLevelAfter(cursorKey(selector.cursor), count, false);
|
|
2083
|
-
}
|
|
2084
|
-
case "Range": {
|
|
2085
|
-
const to = cursorKey(selector.to);
|
|
2086
|
-
return source.topLevelAfter(cursorKey(selector.from), maxRecords, true).filter((record) => TranscriptOrder(orderKey(record), to) <= 0);
|
|
2087
|
-
}
|
|
2088
|
-
}
|
|
2089
|
-
};
|
|
2090
|
-
const emptySelectionNeighbours = (source, selector) => {
|
|
2091
|
-
switch (selector._tag) {
|
|
2092
|
-
case "Latest": return [false, false];
|
|
2093
|
-
case "Page": {
|
|
2094
|
-
const key = cursorKey(selector.cursor);
|
|
2095
|
-
return selector.direction === "before" ? [false, source.topLevelAfter(key, 1, true).length > 0] : [source.topLevelBefore(key, 1, true).length > 0, false];
|
|
2096
|
-
}
|
|
2097
|
-
case "Range": return [source.topLevelBefore(cursorKey(selector.from), 1, false).length > 0, source.topLevelAfter(cursorKey(selector.to), 1, false).length > 0];
|
|
2098
|
-
}
|
|
2099
|
-
};
|
|
2100
|
-
/** Session context, then each record's run group and tools in part order, then pending users. */
|
|
2101
|
-
const collectDependencies = (source, top, maxInlineBodyBytes) => {
|
|
2102
|
-
const dependencies = /* @__PURE__ */ new Map();
|
|
2103
|
-
const add = (record) => {
|
|
2104
|
-
if (record !== void 0 && !dependencies.has(record.id)) dependencies.set(record.id, withBodyRefs(record, maxInlineBodyBytes));
|
|
2105
|
-
};
|
|
2106
|
-
add(source.record(transcriptRecordId.session));
|
|
2107
|
-
for (const record of top) switch (record.kind) {
|
|
2108
|
-
case "assistant": {
|
|
2109
|
-
if (record.runGroupId !== void 0) add(source.record(record.runGroupId));
|
|
2110
|
-
const partOrder = new Map(record.parts.flatMap((part, index) => part._tag === "ToolCall" && part.toolId !== void 0 ? [[part.toolId, index]] : []));
|
|
2111
|
-
[...source.toolsOf(record.id)].sort((left, right) => (partOrder.get(left.id) ?? Number.MAX_SAFE_INTEGER) - (partOrder.get(right.id) ?? Number.MAX_SAFE_INTEGER) || (left.id < right.id ? -1 : left.id > right.id ? 1 : 0)).forEach(add);
|
|
2112
|
-
break;
|
|
2113
|
-
}
|
|
2114
|
-
case "user": {
|
|
2115
|
-
const runId = record.state._tag === "Consumed" ? record.state.runId : void 0;
|
|
2116
|
-
const groupId = (runId === void 0 ? void 0 : source.alias("runId", runId)) ?? source.alias("runCommand", record.commandId);
|
|
2117
|
-
if (groupId !== void 0) add(source.record(groupId));
|
|
2118
|
-
break;
|
|
2119
|
-
}
|
|
2120
|
-
}
|
|
2121
|
-
[...source.pendingUsers()].filter(isPendingTranscriptUserRecord).sort((left, right) => left.submittedSeq - right.submittedSeq || (left.id < right.id ? -1 : left.id > right.id ? 1 : 0)).forEach(add);
|
|
2122
|
-
return Array.from(dependencies.values());
|
|
2123
|
-
};
|
|
2124
|
-
const encoder = new TextEncoder();
|
|
2125
|
-
const encodeRecord = Schema.encodeSync(TranscriptRecordFromEnvelope);
|
|
2126
|
-
const jsonBytes = (value) => {
|
|
2127
|
-
const json = JSON.stringify(value);
|
|
2128
|
-
return json === void 0 ? 0 : encoder.encode(json).length;
|
|
2129
|
-
};
|
|
2130
|
-
const windowBytes = (top, dependencies) => [...top, ...dependencies].reduce((total, record) => total + jsonBytes(encodeRecord(record)), 0);
|
|
2131
|
-
const bodyRef = (body, maxInlineBodyBytes) => {
|
|
2132
|
-
if (body._tag === "Ref") return body;
|
|
2133
|
-
const byteLength = jsonBytes(body.value);
|
|
2134
|
-
return byteLength <= maxInlineBodyBytes ? body : {
|
|
2135
|
-
_tag: "Ref",
|
|
2136
|
-
source: body.source,
|
|
2137
|
-
byteLength: NonNegativeInt.make(byteLength)
|
|
2138
|
-
};
|
|
2139
|
-
};
|
|
2140
|
-
/** Replace inline bodies above the limit with references to their immutable log source. */
|
|
2141
|
-
const withBodyRefs = (record, maxInlineBodyBytes) => {
|
|
2142
|
-
switch (record.kind) {
|
|
2143
|
-
case "tool": {
|
|
2144
|
-
const tool = {
|
|
2145
|
-
...record,
|
|
2146
|
-
...record.params === void 0 ? {} : { params: bodyRef(record.params, maxInlineBodyBytes) },
|
|
2147
|
-
lifecycle: record.lifecycle._tag === "Completed" ? {
|
|
2148
|
-
_tag: "Completed",
|
|
2149
|
-
result: bodyRef(record.lifecycle.result, maxInlineBodyBytes)
|
|
2150
|
-
} : record.lifecycle
|
|
2151
|
-
};
|
|
2152
|
-
return {
|
|
2153
|
-
...record,
|
|
2154
|
-
...tool
|
|
2155
|
-
};
|
|
2156
|
-
}
|
|
2157
|
-
case "assistant": {
|
|
2158
|
-
const parts = record.parts.map((part) => part._tag === "ToolResult" ? {
|
|
2159
|
-
...part,
|
|
2160
|
-
result: bodyRef(part.result, maxInlineBodyBytes)
|
|
2161
|
-
} : part);
|
|
2162
|
-
return {
|
|
2163
|
-
...record,
|
|
2164
|
-
parts
|
|
2165
|
-
};
|
|
2166
|
-
}
|
|
2167
|
-
default: return record;
|
|
2168
|
-
}
|
|
2169
|
-
};
|
|
2170
|
-
//#endregion
|
|
2171
|
-
export { TranscriptRecordId as $, SessionContextRecordId as A, TranscriptCursor as B, transcriptSemanticRevision as C, ImportAssistantRecordId as D, DecorationBufferRecordId as E, TranscriptBody as F, TranscriptDecorations as G, TranscriptDecorationBufferRecord as H, TranscriptBodySource as I, TranscriptOrder as J, TranscriptFieldPath as K, TranscriptBufferedDecoration as L, TranscriptAssistantLifecycle as M, TranscriptAssistantPart as N, InferenceAssistantRecordId as O, TranscriptAssistantRecord as P, TranscriptRecordFromEnvelope as Q, TranscriptClassification as R, computeTranscriptVersion as S, CompactionRecordId as T, TranscriptDecorationEntryKey as U, TranscriptDecoration as V, TranscriptDecorationKey as W, TranscriptRecord as X, TranscriptPosition as Y, TranscriptRecordEnvelope as Z, TranscriptUserFallback as _, transcriptRecordId as _t, TranscriptCursorMismatch as a, TranscriptToolLifecycle as at, transcriptMappingBounds as b, TranscriptProjectionError as c, TranscriptUserRecord as ct, TranscriptListEntryKey as d, UserRecordId as dt, TranscriptRecordViewFromEnvelope as et, TranscriptMappedEvent as f, isPendingTranscriptUserRecord as ft, TranscriptMappings as g, transcriptRecordEnvelopeFormat as gt, TranscriptMappingTarget as h, transcriptDecorationBufferLimit as ht, EDATranscriptStore as i, TranscriptSessionContextRecord as it, ToolRecordId as j, RunGroupRecordId as k, TranscriptDefinition as l, TranscriptUserState as lt, TranscriptMappingOperation as m, runGroupStatus as mt, readTranscriptWindowFrom as n, TranscriptRunMember as nt, planTranscriptBatch as o, TranscriptToolRecord as ot, TranscriptMapping as p, isTopLevelTranscriptRecord as pt, TranscriptLogIncarnation as q, transcriptReadiness as r, TranscriptRunOutcome as rt, TranscriptAliasNamespace as s, TranscriptUnknownRecord as st, buildingTranscriptWindow as t, TranscriptRunGroupRecord as tt, TranscriptDefinitionError as u, TranscriptVersion as ut, emptyTranscriptMappings as v, transcriptStoredInlineBodyLimit as vt, AssistantRecordId as w, canonicalJson as x, makeTranscriptDefinition as y, TranscriptCompactionRecord as z };
|
|
1385
|
+
export { computeTranscriptVersion as _, TranscriptDefinitionError as a, TranscriptMapping as c, TranscriptMappings as d, TranscriptUserFallback as f, canonicalJson as g, transcriptMappingBounds as h, TranscriptDefinition as i, TranscriptMappingOperation as l, makeTranscriptDefinition as m, TranscriptAliasNamespace as n, TranscriptListEntryKey as o, emptyTranscriptMappings as p, TranscriptProjectionError as r, TranscriptMappedEvent as s, planTranscriptBatch as t, TranscriptMappingTarget as u, transcriptSemanticRevision as v };
|
|
2172
1386
|
|
|
2173
|
-
//# sourceMappingURL=
|
|
1387
|
+
//# sourceMappingURL=interpreter-BYstFpr4.js.map
|