effect-durable-agent 0.1.0-alpha.20 → 0.1.0-alpha.22

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.
Files changed (72) hide show
  1. package/README.md +2 -2
  2. package/dist/assert-never-CoyUpoRB.js +18 -0
  3. package/dist/assert-never-CoyUpoRB.js.map +1 -0
  4. package/dist/{compaction-GD1cTPTZ.js → compaction-ajHZ5l7f.js} +58 -6
  5. package/dist/compaction-ajHZ5l7f.js.map +1 -0
  6. package/dist/domain/command-queues.d.ts +1 -1
  7. package/dist/domain/message-transcript.d.ts +2 -2
  8. package/dist/domain/message-transcript.js +9 -1
  9. package/dist/domain/message-transcript.js.map +1 -1
  10. package/dist/domain/reduced-state.d.ts +1 -1
  11. package/dist/domain/reduced-state.js +927 -2
  12. package/dist/domain/reduced-state.js.map +1 -0
  13. package/dist/domain/run-scheduling.d.ts +1 -1
  14. package/dist/index.d.ts +1 -1
  15. package/dist/{model-resolver-BfM5YA6A.d.ts → model-resolver-DUms5p6X.d.ts} +7 -1
  16. package/dist/{reduced-state-4FSWDdgT.d.ts → reduced-state-PJdig48e.d.ts} +5087 -5025
  17. package/dist/{reducer-registry-BIhncOHH.d.ts → reducer-registry-BAbhZs6d.d.ts} +2 -2
  18. package/dist/{run-scheduling-wakeup-BH2pHE0U.d.ts → run-scheduling-wakeup-QLK87OqG.d.ts} +2 -2
  19. package/dist/services/compaction.d.ts +2 -2
  20. package/dist/services/compaction.js +2 -2
  21. package/dist/services/model-call.d.ts +15 -0
  22. package/dist/services/model-call.js +15 -0
  23. package/dist/services/model-call.js.map +1 -0
  24. package/dist/services/model-resolver.d.ts +1 -1
  25. package/dist/services/model-resolver.js.map +1 -1
  26. package/dist/services/prompt-projector.d.ts +2 -2
  27. package/dist/services/prompt-projector.js +48 -4
  28. package/dist/services/prompt-projector.js.map +1 -1
  29. package/dist/services/reducer-registry.d.ts +1 -1
  30. package/dist/services/reducer-registry.js +1 -1
  31. package/dist/services/run-scheduler.d.ts +1 -1
  32. package/dist/services/run-scheduling-wakeup.d.ts +1 -1
  33. package/dist/services/runtime-layer.d.ts +7 -7
  34. package/dist/services/runtime-layer.js +9 -9
  35. package/dist/services/runtime-layer.js.map +1 -1
  36. package/dist/services/runtime.d.ts +1 -1
  37. package/dist/services/runtime.js +1 -1
  38. package/dist/services/session-query.d.ts +1 -1
  39. package/dist/services/session-query.js +2 -2
  40. package/dist/services/session-state.d.ts +1 -1
  41. package/dist/services/session-state.js +1 -1
  42. package/dist/services/session-store.d.ts +2 -2
  43. package/dist/services/session-store.js +1 -251
  44. package/dist/services/sink-checkpoint-store.d.ts +1 -1
  45. package/dist/services/sink-registry.d.ts +1 -1
  46. package/dist/services/sink-registry.js +1 -1
  47. package/dist/services/tool-registry.d.ts +1 -1
  48. package/dist/{session-state-BAzdzqV4.js → session-state-StlO5B2N.js} +51 -21
  49. package/dist/session-state-StlO5B2N.js.map +1 -0
  50. package/dist/session-store-ByDjS03N.d.ts +3184 -0
  51. package/dist/session-store-DcJjs4Fd.js +413 -0
  52. package/dist/session-store-DcJjs4Fd.js.map +1 -0
  53. package/dist/{sink-checkpoint-store-C-SY0cG2.d.ts → sink-checkpoint-store-BHb8YRTw.d.ts} +2 -2
  54. package/dist/{sink-registry-BnWfMABI.js → sink-registry-DEneTH8u.js} +4 -4
  55. package/dist/{sink-registry-BnWfMABI.js.map → sink-registry-DEneTH8u.js.map} +1 -1
  56. package/dist/testkit/layers.d.ts +7 -7
  57. package/dist/testkit/layers.js +9 -9
  58. package/dist/testkit/layers.js.map +1 -1
  59. package/dist/{tool-registry-wPsHagF_.d.ts → tool-registry-CxZ0iuYb.d.ts} +2 -2
  60. package/dist/transcript.d.ts +137 -0
  61. package/dist/transcript.js +178 -0
  62. package/dist/transcript.js.map +1 -0
  63. package/dist/websocket.d.ts +1 -1
  64. package/dist/window-read-B8aF_hDq.js +2173 -0
  65. package/dist/window-read-B8aF_hDq.js.map +1 -0
  66. package/package.json +9 -1
  67. package/dist/compaction-GD1cTPTZ.js.map +0 -1
  68. package/dist/reduced-state-Vuud6LCM.js +0 -942
  69. package/dist/reduced-state-Vuud6LCM.js.map +0 -1
  70. package/dist/services/session-store.js.map +0 -1
  71. package/dist/session-state-BAzdzqV4.js.map +0 -1
  72. package/dist/session-store-BpitF4Wg.d.ts +0 -191
@@ -0,0 +1,178 @@
1
+ import { SequenceNumber } from "./types/core.js";
2
+ import { u as NonNegativeInt } from "./envelope-BCzKUq_z.js";
3
+ import { $ as TranscriptRecordId, A as SessionContextRecordId, B as TranscriptCursor, C as transcriptSemanticRevision, D as ImportAssistantRecordId, E as DecorationBufferRecordId, F as TranscriptBody, G as TranscriptDecorations, H as TranscriptDecorationBufferRecord, I as TranscriptBodySource, J as TranscriptOrder, K as TranscriptFieldPath, L as TranscriptBufferedDecoration, M as TranscriptAssistantLifecycle, N as TranscriptAssistantPart, O as InferenceAssistantRecordId, P as TranscriptAssistantRecord, Q as TranscriptRecordFromEnvelope, R as TranscriptClassification, S as computeTranscriptVersion, T as CompactionRecordId, U as TranscriptDecorationEntryKey, V as TranscriptDecoration, W as TranscriptDecorationKey, X as TranscriptRecord, Y as TranscriptPosition, Z as TranscriptRecordEnvelope, _ as TranscriptUserFallback, _t as transcriptRecordId, a as TranscriptCursorMismatch, at as TranscriptToolLifecycle, b as transcriptMappingBounds, c as TranscriptProjectionError, ct as TranscriptUserRecord, d as TranscriptListEntryKey, dt as UserRecordId, et as TranscriptRecordViewFromEnvelope, f as TranscriptMappedEvent, ft as isPendingTranscriptUserRecord, g as TranscriptMappings, gt as transcriptRecordEnvelopeFormat, h as TranscriptMappingTarget, ht as transcriptDecorationBufferLimit, i as EDATranscriptStore, it as TranscriptSessionContextRecord, j as ToolRecordId, k as RunGroupRecordId, l as TranscriptDefinition, lt as TranscriptUserState, m as TranscriptMappingOperation, mt as runGroupStatus, n as readTranscriptWindowFrom, nt as TranscriptRunMember, o as planTranscriptBatch, ot as TranscriptToolRecord, p as TranscriptMapping, pt as isTopLevelTranscriptRecord, q as TranscriptLogIncarnation, r as transcriptReadiness, rt as TranscriptRunOutcome, s as TranscriptAliasNamespace, st as TranscriptUnknownRecord, t as buildingTranscriptWindow, tt as TranscriptRunGroupRecord, u as TranscriptDefinitionError, ut as TranscriptVersion, v as emptyTranscriptMappings, vt as transcriptStoredInlineBodyLimit, w as AssistantRecordId, x as canonicalJson, y as makeTranscriptDefinition, z as TranscriptCompactionRecord } from "./window-read-B8aF_hDq.js";
4
+ import * as Schema from "effect/Schema";
5
+ import * as SchemaGetter from "effect/SchemaGetter";
6
+ //#region src/transcript/window.ts
7
+ const PositiveInt = Schema.Int.check(Schema.isGreaterThanOrEqualTo(1));
8
+ const orderKeyOfCursor = (cursor) => ({
9
+ anchorSeq: cursor.anchorSeq,
10
+ ordinal: cursor.ordinal,
11
+ recordId: cursor.recordId
12
+ });
13
+ /**
14
+ * Which slice of history to read.
15
+ *
16
+ * `Latest` serves first paint (SSR, CLIs); `Page` walks either direction from a cursor;
17
+ * `Range` re-reads exactly the span a client retains, inclusive of both ends, at one new cut.
18
+ */
19
+ const TranscriptWindowSelector = Schema.Union([
20
+ Schema.TaggedStruct("Latest", { count: PositiveInt }),
21
+ Schema.TaggedStruct("Page", {
22
+ direction: Schema.Literals(["before", "after"]),
23
+ cursor: TranscriptCursor,
24
+ count: PositiveInt
25
+ }),
26
+ Schema.TaggedStruct("Range", {
27
+ from: TranscriptCursor,
28
+ to: TranscriptCursor
29
+ }).check(Schema.makeFilter((range) => range.from.incarnation === range.to.incarnation && range.from.version === range.to.version || "a range is scoped to one incarnation and version"), Schema.makeFilter((range) => TranscriptOrder(orderKeyOfCursor(range.from), orderKeyOfCursor(range.to)) <= 0 || "a range starts at or before its end"))
30
+ ]);
31
+ /**
32
+ * Bounds on one window. `maxRecords` caps top-level records (a selector's `count` is further
33
+ * capped by it); `maxBytes` caps the whole response, dependencies included; bodies above
34
+ * `maxInlineBodyBytes` are sent as references.
35
+ */
36
+ const TranscriptWindowLimits = Schema.Struct({
37
+ maxRecords: PositiveInt,
38
+ maxBytes: PositiveInt,
39
+ maxInlineBodyBytes: NonNegativeInt
40
+ });
41
+ /** Default bounds: the first window holds 100 top-level records (design decision 4). */
42
+ const defaultTranscriptWindowLimits = {
43
+ maxRecords: 100,
44
+ maxBytes: 1048576,
45
+ maxInlineBodyBytes: 16384
46
+ };
47
+ /**
48
+ * Whether the window is the current interpretation of the log, and if not, why its cut is
49
+ * behind.
50
+ *
51
+ * Every state other than `Ready` is a degraded read and obeys one rule: the response contains
52
+ * nothing newer than `throughSeq` — no newer pending users, session context or live content.
53
+ */
54
+ const KnownReadiness = Schema.TaggedUnion({
55
+ /** The active version is healthy and projected through the log head at read time. */
56
+ Ready: {},
57
+ /** The active version failed while projecting `failedAtSeq`; this is its last good cut. */
58
+ Degraded: {
59
+ failedAtSeq: SequenceNumber,
60
+ error: Schema.String
61
+ },
62
+ /**
63
+ * The active version is no longer carried by this release; history is being rebuilt under
64
+ * the current definition, and clients receive one replacement when it activates.
65
+ */
66
+ UpdatingHistory: {},
67
+ /** No version is servable yet; the window is empty. */
68
+ Building: {},
69
+ /**
70
+ * A stored row of the served version cannot be decoded by this release. Nothing is served
71
+ * until a rebuild finishes, rather than a wrong view; the window is empty.
72
+ */
73
+ Unreadable: { error: Schema.String },
74
+ /** A readiness this reader does not know; treated as degraded. */
75
+ Unknown: { readinessType: Schema.String }
76
+ });
77
+ const knownReadinessTags = /* @__PURE__ */ new Set([
78
+ "Ready",
79
+ "Degraded",
80
+ "UpdatingHistory",
81
+ "Building",
82
+ "Unreadable",
83
+ "Unknown"
84
+ ]);
85
+ const UnrecognizedReadiness = Schema.Struct({ _tag: Schema.String.check(Schema.makeFilter((tag) => !knownReadinessTags.has(tag) || "a known readiness must decode as that readiness")) }).pipe(Schema.decodeTo(Schema.toType(KnownReadiness.cases.Unknown), {
86
+ decode: SchemaGetter.transform((readiness) => ({
87
+ _tag: "Unknown",
88
+ readinessType: readiness._tag
89
+ })),
90
+ encode: SchemaGetter.transform((readiness) => ({ _tag: readiness.readinessType }))
91
+ }));
92
+ /**
93
+ * Whether the window is the current interpretation of the log. A readiness this reader does not
94
+ * know decodes as `Unknown` and is treated as degraded: it carries no live content. A malformed
95
+ * readiness with a known tag is a decode failure.
96
+ */
97
+ const TranscriptReadiness = Schema.Union([KnownReadiness, UnrecognizedReadiness]);
98
+ /**
99
+ * Accumulated parts of the inference streaming now, captured at the same publication boundary as
100
+ * the window. Owned by the live runtime; storage-level reads never include it.
101
+ */
102
+ const TranscriptActiveContent = Schema.Struct({
103
+ assistantId: InferenceAssistantRecordId,
104
+ parts: Schema.Array(TranscriptAssistantPart)
105
+ });
106
+ const recordUpdatedSeq = (record) => record.updatedSeq;
107
+ const recordPosition = (record) => "position" in record ? record.position : void 0;
108
+ /** Positioned history, which is served only as a top-level record and never as a dependency. */
109
+ const isHistoryRecord = (record) => record.kind === "unknown" ? record.position !== void 0 : isTopLevelTranscriptRecord(record);
110
+ /**
111
+ * One complete, consistent read of a transcript version.
112
+ *
113
+ * `records` are top-level records in transcript order; `dependencies` are the tools and run
114
+ * groups they reference, the session context, and every pending user record. Every record is
115
+ * projected through `throughSeq` and none is newer, which is what makes a cut complete. A client
116
+ * replaces, never merges, what a window covers.
117
+ */
118
+ const TranscriptWindow = Schema.Struct({
119
+ incarnation: TranscriptLogIncarnation,
120
+ version: TranscriptVersion,
121
+ throughSeq: SequenceNumber,
122
+ records: Schema.Array(TranscriptRecordViewFromEnvelope),
123
+ dependencies: Schema.Array(TranscriptRecordViewFromEnvelope),
124
+ activeContent: Schema.optionalKey(Schema.Array(TranscriptActiveContent)),
125
+ hasOlder: Schema.Boolean,
126
+ hasNewer: Schema.Boolean,
127
+ readiness: TranscriptReadiness
128
+ }).check(Schema.makeFilter((window) => [...window.records, ...window.dependencies].every((record) => recordUpdatedSeq(record) <= window.throughSeq) || "every record must be projected through throughSeq and none may be newer"), Schema.makeFilter((window) => window.readiness._tag === "Ready" || window.activeContent === void 0 || "a degraded read never attaches live content"), Schema.makeFilter((window) => window.readiness._tag !== "Degraded" || window.readiness.failedAtSeq > window.throughSeq || "a degraded cut ends before the seq that failed"), Schema.makeFilter((window) => [...window.records, ...window.dependencies].every((record) => record.kind !== "decorationBuffer" && (record.kind !== "unknown" || record.originalKind !== "decorationBuffer")) || "decoration buffers are never served"), Schema.makeFilter((window) => {
129
+ const ids = [...window.records, ...window.dependencies].map((record) => record.id);
130
+ return new Set(ids).size === ids.length || "a record is served at most once";
131
+ }), Schema.makeFilter((window) => window.records.every((record, index) => {
132
+ const position = recordPosition(record);
133
+ if (position === void 0 || !isHistoryRecord(record)) return false;
134
+ const previous = index === 0 ? void 0 : window.records[index - 1];
135
+ const previousPosition = previous === void 0 ? void 0 : recordPosition(previous);
136
+ return previous === void 0 || previousPosition === void 0 || TranscriptOrder({
137
+ ...previousPosition,
138
+ recordId: previous.id
139
+ }, {
140
+ ...position,
141
+ recordId: record.id
142
+ }) < 0;
143
+ }) || "records are positioned history records in transcript order"), Schema.makeFilter((window) => window.dependencies.every((record) => !isHistoryRecord(record)) || "dependencies never contain history records"), Schema.makeFilter((window) => window.dependencies.every((record) => record.kind !== "user" || isPendingTranscriptUserRecord(record)) || "the only user dependencies are pending users; cancelled users are never served"), Schema.makeFilter((window) => window.readiness._tag !== "Building" && window.readiness._tag !== "Unreadable" || window.records.length === 0 && window.dependencies.length === 0 && !window.hasOlder && !window.hasNewer || "a building or unreadable window is empty"));
144
+ /** Paging cursor for one top-level record of a window. */
145
+ const transcriptCursorOf = (window, record) => {
146
+ const position = "position" in record ? record.position : void 0;
147
+ return position === void 0 ? void 0 : {
148
+ incarnation: window.incarnation,
149
+ version: window.version,
150
+ anchorSeq: position.anchorSeq,
151
+ ordinal: position.ordinal,
152
+ recordId: record.id
153
+ };
154
+ };
155
+ /** Health of one stored transcript version. A failed version is frozen at its last good cursor. */
156
+ const TranscriptVersionStatus = Schema.TaggedUnion({
157
+ Ok: {},
158
+ Failed: {
159
+ failedAtSeq: SequenceNumber,
160
+ error: Schema.String
161
+ }
162
+ });
163
+ /**
164
+ * Per-version maintenance state, one per version present in a session's storage.
165
+ *
166
+ * `cursor` is the last fully projected seq, committed together with that version's rows. At most
167
+ * one version is `active` (served) and at most one is `building` (catching up from the log).
168
+ */
169
+ const TranscriptVersionMeta = Schema.Struct({
170
+ version: TranscriptVersion,
171
+ role: Schema.Literals(["active", "building"]),
172
+ cursor: SequenceNumber,
173
+ status: TranscriptVersionStatus
174
+ }).check(Schema.makeFilter((meta) => meta.status._tag !== "Failed" || meta.status.failedAtSeq > meta.cursor || "a failed version is frozen before the seq that failed"));
175
+ //#endregion
176
+ export { AssistantRecordId, CompactionRecordId, DecorationBufferRecordId, EDATranscriptStore, ImportAssistantRecordId, InferenceAssistantRecordId, RunGroupRecordId, SessionContextRecordId, ToolRecordId, TranscriptActiveContent, TranscriptAliasNamespace, TranscriptAssistantLifecycle, TranscriptAssistantPart, TranscriptAssistantRecord, TranscriptBody, TranscriptBodySource, TranscriptBufferedDecoration, TranscriptClassification, TranscriptCompactionRecord, TranscriptCursor, TranscriptCursorMismatch, TranscriptDecoration, TranscriptDecorationBufferRecord, TranscriptDecorationEntryKey, TranscriptDecorationKey, TranscriptDecorations, TranscriptDefinition, TranscriptDefinitionError, TranscriptFieldPath, TranscriptListEntryKey, TranscriptLogIncarnation, TranscriptMappedEvent, TranscriptMapping, TranscriptMappingOperation, TranscriptMappingTarget, TranscriptMappings, TranscriptOrder, TranscriptPosition, TranscriptProjectionError, TranscriptReadiness, TranscriptRecord, TranscriptRecordEnvelope, TranscriptRecordFromEnvelope, TranscriptRecordId, TranscriptRecordViewFromEnvelope, TranscriptRunGroupRecord, TranscriptRunMember, TranscriptRunOutcome, TranscriptSessionContextRecord, TranscriptToolLifecycle, TranscriptToolRecord, TranscriptUnknownRecord, TranscriptUserFallback, TranscriptUserRecord, TranscriptUserState, TranscriptVersion, TranscriptVersionMeta, TranscriptVersionStatus, TranscriptWindow, TranscriptWindowLimits, TranscriptWindowSelector, UserRecordId, buildingTranscriptWindow, canonicalJson, computeTranscriptVersion, defaultTranscriptWindowLimits, emptyTranscriptMappings, isPendingTranscriptUserRecord, isTopLevelTranscriptRecord, makeTranscriptDefinition, planTranscriptBatch, readTranscriptWindowFrom, runGroupStatus, transcriptCursorOf, transcriptDecorationBufferLimit, transcriptMappingBounds, transcriptReadiness, transcriptRecordEnvelopeFormat, transcriptRecordId, transcriptSemanticRevision, transcriptStoredInlineBodyLimit };
177
+
178
+ //# sourceMappingURL=transcript.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcript.js","names":[],"sources":["../src/transcript/window.ts"],"sourcesContent":["import * as Schema from \"effect/Schema\";\nimport * as SchemaGetter from \"effect/SchemaGetter\";\n\nimport { SequenceNumber } from \"../types/core\";\nimport { NonNegativeInt } from \"../types/events/envelope\";\nimport {\n InferenceAssistantRecordId,\n TranscriptAssistantPart,\n TranscriptCursor,\n TranscriptLogIncarnation,\n TranscriptOrder,\n TranscriptRecordViewFromEnvelope,\n isPendingTranscriptUserRecord,\n isTopLevelTranscriptRecord,\n TranscriptVersion,\n type TranscriptOrderKey,\n type TranscriptRecordView,\n} from \"./records\";\n\nconst PositiveInt = Schema.Int.check(Schema.isGreaterThanOrEqualTo(1));\n\nconst orderKeyOfCursor = (cursor: TranscriptCursor): TranscriptOrderKey => ({\n anchorSeq: cursor.anchorSeq,\n ordinal: cursor.ordinal,\n recordId: cursor.recordId,\n});\n\n/**\n * Which slice of history to read.\n *\n * `Latest` serves first paint (SSR, CLIs); `Page` walks either direction from a cursor;\n * `Range` re-reads exactly the span a client retains, inclusive of both ends, at one new cut.\n */\nexport const TranscriptWindowSelector = Schema.Union([\n Schema.TaggedStruct(\"Latest\", { count: PositiveInt }),\n Schema.TaggedStruct(\"Page\", {\n direction: Schema.Literals([\"before\", \"after\"]),\n cursor: TranscriptCursor,\n count: PositiveInt,\n }),\n Schema.TaggedStruct(\"Range\", { from: TranscriptCursor, to: TranscriptCursor }).check(\n Schema.makeFilter(\n (range) =>\n (range.from.incarnation === range.to.incarnation &&\n range.from.version === range.to.version) ||\n \"a range is scoped to one incarnation and version\",\n ),\n Schema.makeFilter(\n (range) =>\n TranscriptOrder(orderKeyOfCursor(range.from), orderKeyOfCursor(range.to)) <= 0 ||\n \"a range starts at or before its end\",\n ),\n ),\n]);\nexport type TranscriptWindowSelector = typeof TranscriptWindowSelector.Type;\n\n/**\n * Bounds on one window. `maxRecords` caps top-level records (a selector's `count` is further\n * capped by it); `maxBytes` caps the whole response, dependencies included; bodies above\n * `maxInlineBodyBytes` are sent as references.\n */\nexport const TranscriptWindowLimits = Schema.Struct({\n maxRecords: PositiveInt,\n maxBytes: PositiveInt,\n maxInlineBodyBytes: NonNegativeInt,\n});\nexport type TranscriptWindowLimits = typeof TranscriptWindowLimits.Type;\n\n/** Default bounds: the first window holds 100 top-level records (design decision 4). */\nexport const defaultTranscriptWindowLimits: TranscriptWindowLimits = {\n maxRecords: 100,\n maxBytes: 1_048_576,\n maxInlineBodyBytes: 16_384,\n};\n\n/**\n * Whether the window is the current interpretation of the log, and if not, why its cut is\n * behind.\n *\n * Every state other than `Ready` is a degraded read and obeys one rule: the response contains\n * nothing newer than `throughSeq` — no newer pending users, session context or live content.\n */\nconst KnownReadiness = Schema.TaggedUnion({\n /** The active version is healthy and projected through the log head at read time. */\n Ready: {},\n /** The active version failed while projecting `failedAtSeq`; this is its last good cut. */\n Degraded: { failedAtSeq: SequenceNumber, error: Schema.String },\n /**\n * The active version is no longer carried by this release; history is being rebuilt under\n * the current definition, and clients receive one replacement when it activates.\n */\n UpdatingHistory: {},\n /** No version is servable yet; the window is empty. */\n Building: {},\n /**\n * A stored row of the served version cannot be decoded by this release. Nothing is served\n * until a rebuild finishes, rather than a wrong view; the window is empty.\n */\n Unreadable: { error: Schema.String },\n /** A readiness this reader does not know; treated as degraded. */\n Unknown: { readinessType: Schema.String },\n});\n\nconst knownReadinessTags: ReadonlySet<string> = new Set([\n \"Ready\",\n \"Degraded\",\n \"UpdatingHistory\",\n \"Building\",\n \"Unreadable\",\n \"Unknown\",\n]);\n\nconst UnrecognizedReadiness = Schema.Struct({\n _tag: Schema.String.check(\n Schema.makeFilter(\n (tag) => !knownReadinessTags.has(tag) || \"a known readiness must decode as that readiness\",\n ),\n ),\n}).pipe(\n Schema.decodeTo(Schema.toType(KnownReadiness.cases.Unknown), {\n decode: SchemaGetter.transform((readiness) => ({\n _tag: \"Unknown\" as const,\n readinessType: readiness._tag,\n })),\n encode: SchemaGetter.transform((readiness) => ({ _tag: readiness.readinessType })),\n }),\n);\n\n/**\n * Whether the window is the current interpretation of the log. A readiness this reader does not\n * know decodes as `Unknown` and is treated as degraded: it carries no live content. A malformed\n * readiness with a known tag is a decode failure.\n */\nexport const TranscriptReadiness = Schema.Union([KnownReadiness, UnrecognizedReadiness]);\nexport type TranscriptReadiness = typeof TranscriptReadiness.Type;\n\n/**\n * Accumulated parts of the inference streaming now, captured at the same publication boundary as\n * the window. Owned by the live runtime; storage-level reads never include it.\n */\nexport const TranscriptActiveContent = Schema.Struct({\n assistantId: InferenceAssistantRecordId,\n parts: Schema.Array(TranscriptAssistantPart),\n});\nexport type TranscriptActiveContent = typeof TranscriptActiveContent.Type;\n\nconst recordUpdatedSeq = (record: TranscriptRecordView): number => record.updatedSeq;\n\nconst recordPosition = (record: TranscriptRecordView) =>\n \"position\" in record ? record.position : undefined;\n\n/** Positioned history, which is served only as a top-level record and never as a dependency. */\nconst isHistoryRecord = (record: TranscriptRecordView): boolean =>\n record.kind === \"unknown\" ? record.position !== undefined : isTopLevelTranscriptRecord(record);\n\n/**\n * One complete, consistent read of a transcript version.\n *\n * `records` are top-level records in transcript order; `dependencies` are the tools and run\n * groups they reference, the session context, and every pending user record. Every record is\n * projected through `throughSeq` and none is newer, which is what makes a cut complete. A client\n * replaces, never merges, what a window covers.\n */\nexport const TranscriptWindow = Schema.Struct({\n incarnation: TranscriptLogIncarnation,\n version: TranscriptVersion,\n throughSeq: SequenceNumber,\n records: Schema.Array(TranscriptRecordViewFromEnvelope),\n dependencies: Schema.Array(TranscriptRecordViewFromEnvelope),\n activeContent: Schema.optionalKey(Schema.Array(TranscriptActiveContent)),\n hasOlder: Schema.Boolean,\n hasNewer: Schema.Boolean,\n readiness: TranscriptReadiness,\n}).check(\n Schema.makeFilter(\n (window) =>\n [...window.records, ...window.dependencies].every(\n (record) => recordUpdatedSeq(record) <= window.throughSeq,\n ) || \"every record must be projected through throughSeq and none may be newer\",\n ),\n Schema.makeFilter(\n (window) =>\n window.readiness._tag === \"Ready\" ||\n window.activeContent === undefined ||\n \"a degraded read never attaches live content\",\n ),\n Schema.makeFilter(\n (window) =>\n window.readiness._tag !== \"Degraded\" ||\n window.readiness.failedAtSeq > window.throughSeq ||\n \"a degraded cut ends before the seq that failed\",\n ),\n Schema.makeFilter(\n (window) =>\n [...window.records, ...window.dependencies].every(\n (record) =>\n record.kind !== \"decorationBuffer\" &&\n (record.kind !== \"unknown\" || record.originalKind !== \"decorationBuffer\"),\n ) || \"decoration buffers are never served\",\n ),\n Schema.makeFilter((window) => {\n const ids = [...window.records, ...window.dependencies].map((record) => record.id);\n return new Set(ids).size === ids.length || \"a record is served at most once\";\n }),\n Schema.makeFilter(\n (window) =>\n window.records.every((record, index) => {\n const position = recordPosition(record);\n if (position === undefined || !isHistoryRecord(record)) return false;\n const previous = index === 0 ? undefined : window.records[index - 1];\n const previousPosition = previous === undefined ? undefined : recordPosition(previous);\n return (\n previous === undefined ||\n previousPosition === undefined ||\n TranscriptOrder(\n { ...previousPosition, recordId: previous.id },\n { ...position, recordId: record.id },\n ) < 0\n );\n }) || \"records are positioned history records in transcript order\",\n ),\n Schema.makeFilter(\n (window) =>\n window.dependencies.every((record) => !isHistoryRecord(record)) ||\n \"dependencies never contain history records\",\n ),\n Schema.makeFilter(\n (window) =>\n window.dependencies.every(\n (record) => record.kind !== \"user\" || isPendingTranscriptUserRecord(record),\n ) || \"the only user dependencies are pending users; cancelled users are never served\",\n ),\n Schema.makeFilter(\n (window) =>\n (window.readiness._tag !== \"Building\" && window.readiness._tag !== \"Unreadable\") ||\n (window.records.length === 0 &&\n window.dependencies.length === 0 &&\n !window.hasOlder &&\n !window.hasNewer) ||\n \"a building or unreadable window is empty\",\n ),\n);\nexport type TranscriptWindow = typeof TranscriptWindow.Type;\n\n/** Paging cursor for one top-level record of a window. */\nexport const transcriptCursorOf = (\n window: Pick<TranscriptWindow, \"incarnation\" | \"version\">,\n record: TranscriptRecordView,\n): TranscriptCursor | undefined => {\n const position = \"position\" in record ? record.position : undefined;\n return position === undefined\n ? undefined\n : {\n incarnation: window.incarnation,\n version: window.version,\n anchorSeq: position.anchorSeq,\n ordinal: position.ordinal,\n recordId: record.id,\n };\n};\n\n/** Health of one stored transcript version. A failed version is frozen at its last good cursor. */\nexport const TranscriptVersionStatus = Schema.TaggedUnion({\n Ok: {},\n Failed: { failedAtSeq: SequenceNumber, error: Schema.String },\n});\nexport type TranscriptVersionStatus = typeof TranscriptVersionStatus.Type;\n\n/**\n * Per-version maintenance state, one per version present in a session's storage.\n *\n * `cursor` is the last fully projected seq, committed together with that version's rows. At most\n * one version is `active` (served) and at most one is `building` (catching up from the log).\n */\nexport const TranscriptVersionMeta = Schema.Struct({\n version: TranscriptVersion,\n role: Schema.Literals([\"active\", \"building\"]),\n cursor: SequenceNumber,\n status: TranscriptVersionStatus,\n}).check(\n Schema.makeFilter(\n (meta) =>\n meta.status._tag !== \"Failed\" ||\n meta.status.failedAtSeq > meta.cursor ||\n \"a failed version is frozen before the seq that failed\",\n ),\n);\nexport type TranscriptVersionMeta = typeof TranscriptVersionMeta.Type;\n"],"mappings":";;;;;;AAmBA,MAAM,cAAc,OAAO,IAAI,MAAM,OAAO,uBAAuB,CAAC,CAAC;AAErE,MAAM,oBAAoB,YAAkD;CAC1E,WAAW,OAAO;CAClB,SAAS,OAAO;CAChB,UAAU,OAAO;AACnB;;;;;;;AAQA,MAAa,2BAA2B,OAAO,MAAM;CACnD,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AO;CACjD,SAAS;CACT,MAAM,OAAO,SAAS,CAAC,UAAU,UAAU,CAAC;CAC5C,QAAQ;CACR,QAAQ;AACV,CAAC,CAAC,CAAC,MACD,OAAO,YACJ,SACC,KAAK,OAAO,SAAS,YACrB,KAAK,OAAO,cAAc,KAAK,UAC/B,uDACJ,CACF"}
@@ -2,7 +2,7 @@ import { c as StopTurnCommand, l as SubmitMessageCommand, o as PromotePendingMes
2
2
  import { h as SequenceNumber } from "./core-BcimKMIv.js";
3
3
  import { f as PositionedEvent, i as EventEnvelope } from "./envelope-Che6KatU.js";
4
4
  import "./events-BWuvzVml.js";
5
- import "./reduced-state-4FSWDdgT.js";
5
+ import "./reduced-state-PJdig48e.js";
6
6
  import * as Effect from "effect/Effect";
7
7
  import * as Schema from "effect/Schema";
8
8
  //#region src/websocket/protocol.d.ts