effect-durable-agent 0.1.0-alpha.21 → 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.
- package/README.md +2 -2
- package/dist/assert-never-CoyUpoRB.js +18 -0
- package/dist/assert-never-CoyUpoRB.js.map +1 -0
- 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/reduced-state.js +927 -2
- package/dist/domain/reduced-state.js.map +1 -0
- package/dist/domain/run-scheduling.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/{reduced-state-BGd_yCBT.d.ts → reduced-state-PJdig48e.d.ts} +4171 -4171
- package/dist/{reducer-registry-BIhncOHH.d.ts → reducer-registry-BAbhZs6d.d.ts} +2 -2
- package/dist/{run-scheduling-wakeup-BH2pHE0U.d.ts → run-scheduling-wakeup-QLK87OqG.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 +2 -2
- package/dist/services/session-store.js +1 -251
- 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-C_1XxhvE.js → session-state-StlO5B2N.js} +5 -4
- package/dist/{session-state-C_1XxhvE.js.map → session-state-StlO5B2N.js.map} +1 -1
- package/dist/session-store-ByDjS03N.d.ts +3184 -0
- package/dist/session-store-DcJjs4Fd.js +413 -0
- package/dist/session-store-DcJjs4Fd.js.map +1 -0
- package/dist/{sink-checkpoint-store-C-SY0cG2.d.ts → sink-checkpoint-store-BHb8YRTw.d.ts} +2 -2
- package/dist/{sink-registry-CjK5MC90.js → sink-registry-DEneTH8u.js} +3 -3
- package/dist/{sink-registry-CjK5MC90.js.map → sink-registry-DEneTH8u.js.map} +1 -1
- package/dist/testkit/layers.d.ts +6 -6
- package/dist/testkit/layers.js +3 -3
- package/dist/{tool-registry-wPsHagF_.d.ts → tool-registry-CxZ0iuYb.d.ts} +2 -2
- package/dist/transcript.d.ts +137 -0
- package/dist/transcript.js +178 -0
- package/dist/transcript.js.map +1 -0
- package/dist/websocket.d.ts +1 -1
- package/dist/window-read-B8aF_hDq.js +2173 -0
- package/dist/window-read-B8aF_hDq.js.map +1 -0
- package/package.json +5 -1
- package/dist/reduced-state-Vuud6LCM.js +0 -942
- package/dist/reduced-state-Vuud6LCM.js.map +0 -1
- package/dist/services/session-store.js.map +0 -1
- package/dist/session-store-BpitF4Wg.d.ts +0 -191
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
import { CommandId, DurablePosition, SequenceNumber, durablePosition } from "./types/core.js";
|
|
2
|
+
import { t as DurableEventEnvelope } from "./envelope-BCzKUq_z.js";
|
|
3
|
+
import { H as DecodedDurableEvent, Nn as commandAdmittedEventType, Un as contextRebasedEventType, Wn as decodeDurableEventSync, kr as decodeRetainingExcess, mr as summaryCreatedEventType, qn as durableEventEnvelope } from "./durable-CD__3ztN.js";
|
|
4
|
+
import { CompactionSummaryArtifact } from "./domain/context-projection.js";
|
|
5
|
+
import { J as TranscriptOrder, ft as isPendingTranscriptUserRecord, i as EDATranscriptStore, n as readTranscriptWindowFrom, o as planTranscriptBatch, pt as isTopLevelTranscriptRecord, q as TranscriptLogIncarnation, t as buildingTranscriptWindow, v as emptyTranscriptMappings, y as makeTranscriptDefinition } from "./window-read-B8aF_hDq.js";
|
|
6
|
+
import * as Context from "effect/Context";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
import * as Layer from "effect/Layer";
|
|
9
|
+
import * as Schema from "effect/Schema";
|
|
10
|
+
import * as Stream from "effect/Stream";
|
|
11
|
+
import * as Cause from "effect/Cause";
|
|
12
|
+
import * as Ref from "effect/Ref";
|
|
13
|
+
import * as Result from "effect/Result";
|
|
14
|
+
import * as SchemaGetter from "effect/SchemaGetter";
|
|
15
|
+
//#region src/transcript/in-memory.ts
|
|
16
|
+
const aliasKey = (namespace, key) => `${namespace}\u0000${key}`;
|
|
17
|
+
/** The carried definition for a stored version, if this release still carries it. */
|
|
18
|
+
const carriedTranscriptDefinition = (config, version) => config.current.version === version ? config.current : config.previous?.version === version ? config.previous : void 0;
|
|
19
|
+
/** An empty version before any event is projected. */
|
|
20
|
+
const emptyTranscriptVersion = (version, role) => ({
|
|
21
|
+
meta: {
|
|
22
|
+
version,
|
|
23
|
+
role,
|
|
24
|
+
cursor: SequenceNumber.make(0),
|
|
25
|
+
status: { _tag: "Ok" }
|
|
26
|
+
},
|
|
27
|
+
records: /* @__PURE__ */ new Map(),
|
|
28
|
+
aliases: /* @__PURE__ */ new Map(),
|
|
29
|
+
ordinals: /* @__PURE__ */ new Map()
|
|
30
|
+
});
|
|
31
|
+
const lookupOf = (version) => ({
|
|
32
|
+
cursor: version.meta.cursor,
|
|
33
|
+
record: (id) => version.records.get(id),
|
|
34
|
+
alias: (namespace, key) => version.aliases.get(aliasKey(namespace, key)),
|
|
35
|
+
nextOrdinal: (anchorSeq) => version.ordinals.get(anchorSeq) ?? 0
|
|
36
|
+
});
|
|
37
|
+
const applyPlan = (version, plan) => {
|
|
38
|
+
const records = new Map(version.records);
|
|
39
|
+
const aliases = new Map(version.aliases);
|
|
40
|
+
const ordinals = new Map(version.ordinals);
|
|
41
|
+
for (const record of plan.records) {
|
|
42
|
+
records.set(record.id, record);
|
|
43
|
+
if ("position" in record && record.position !== void 0) {
|
|
44
|
+
const { anchorSeq, ordinal } = record.position;
|
|
45
|
+
ordinals.set(anchorSeq, Math.max(ordinals.get(anchorSeq) ?? 0, ordinal + 1));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
for (const alias of plan.aliases) {
|
|
49
|
+
const key = aliasKey(alias.namespace, alias.key);
|
|
50
|
+
if (!aliases.has(key)) aliases.set(key, alias.recordId);
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
meta: {
|
|
54
|
+
...version.meta,
|
|
55
|
+
cursor: plan.throughSeq
|
|
56
|
+
},
|
|
57
|
+
records,
|
|
58
|
+
aliases,
|
|
59
|
+
ordinals
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Project committed events into one version, or freeze it.
|
|
64
|
+
*
|
|
65
|
+
* A projection failure marks only this version failed at its unchanged cursor and leaves its
|
|
66
|
+
* rows exactly as they were, so it remains a consistent last-good cut.
|
|
67
|
+
*/
|
|
68
|
+
const advanceTranscriptVersion = (version, definition, committed) => {
|
|
69
|
+
const fresh = committed.filter((entry) => entry.position.seq > version.meta.cursor);
|
|
70
|
+
const first = fresh[0];
|
|
71
|
+
if (first === void 0 || version.meta.status._tag === "Failed") return version;
|
|
72
|
+
try {
|
|
73
|
+
return applyPlan(version, planTranscriptBatch(lookupOf(version), fresh, definition));
|
|
74
|
+
} catch (error) {
|
|
75
|
+
return {
|
|
76
|
+
...version,
|
|
77
|
+
meta: {
|
|
78
|
+
...version.meta,
|
|
79
|
+
status: {
|
|
80
|
+
_tag: "Failed",
|
|
81
|
+
failedAtSeq: first.position.seq,
|
|
82
|
+
error: error instanceof Error ? error.message : String(error)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
/** Maintain every carried, healthy version for a committed append; others stay frozen. */
|
|
89
|
+
const maintainTranscripts = (state, committed) => ({
|
|
90
|
+
...state,
|
|
91
|
+
versions: state.versions.map((version) => {
|
|
92
|
+
const definition = carriedTranscriptDefinition(state.config, version.meta.version);
|
|
93
|
+
return definition === void 0 ? version : advanceTranscriptVersion(version, definition, committed);
|
|
94
|
+
})
|
|
95
|
+
});
|
|
96
|
+
/**
|
|
97
|
+
* Converge a session to the current definition, as the adapter's builder does in slices.
|
|
98
|
+
*
|
|
99
|
+
* A building version that is not `current` is discarded. If the active version is not `current`,
|
|
100
|
+
* `current` is built from the log (never from old rows) and, once it reaches the head, becomes
|
|
101
|
+
* active and the old version is deleted. A failed build leaves the active version serving; only a
|
|
102
|
+
* new definition repairs it. A brand-new log simply initializes `current`.
|
|
103
|
+
*/
|
|
104
|
+
const convergeTranscripts = (state, log) => {
|
|
105
|
+
const current = state.config.current;
|
|
106
|
+
const versions = state.versions.filter((version) => version.meta.role === "active" || version.meta.version === current.version);
|
|
107
|
+
if (versions.find((version) => version.meta.role === "active")?.meta.version === current.version) return {
|
|
108
|
+
...state,
|
|
109
|
+
versions
|
|
110
|
+
};
|
|
111
|
+
const building = versions.find((version) => version.meta.role === "building") ?? emptyTranscriptVersion(current.version, "building");
|
|
112
|
+
const built = advanceTranscriptVersion(building, current, log);
|
|
113
|
+
if (built.meta.status._tag === "Failed") return {
|
|
114
|
+
...state,
|
|
115
|
+
versions: [...versions.filter((version) => version !== building), built]
|
|
116
|
+
};
|
|
117
|
+
return {
|
|
118
|
+
...state,
|
|
119
|
+
versions: [{
|
|
120
|
+
...built,
|
|
121
|
+
meta: {
|
|
122
|
+
...built.meta,
|
|
123
|
+
role: "active"
|
|
124
|
+
}
|
|
125
|
+
}]
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
/** Initial transcript state for a store whose log already holds `log`. */
|
|
129
|
+
const initialTranscriptState = (incarnation, config, log) => convergeTranscripts({
|
|
130
|
+
incarnation,
|
|
131
|
+
config,
|
|
132
|
+
versions: []
|
|
133
|
+
}, log);
|
|
134
|
+
const topLevelOrder = (record) => ({
|
|
135
|
+
anchorSeq: record.position?.anchorSeq ?? 0,
|
|
136
|
+
ordinal: record.position?.ordinal ?? 0,
|
|
137
|
+
recordId: record.id
|
|
138
|
+
});
|
|
139
|
+
/** Window reads over the active version, or undefined while nothing is servable. */
|
|
140
|
+
const inMemoryTranscriptWindowSource = (state) => {
|
|
141
|
+
const active = state.versions.find((version) => version.meta.role === "active");
|
|
142
|
+
if (active === void 0) return void 0;
|
|
143
|
+
const records = Array.from(active.records.values());
|
|
144
|
+
const ordered = records.filter(isTopLevelTranscriptRecord).sort((left, right) => TranscriptOrder(topLevelOrder(left), topLevelOrder(right)));
|
|
145
|
+
const compare = (record, key) => TranscriptOrder(topLevelOrder(record), key);
|
|
146
|
+
return {
|
|
147
|
+
incarnation: state.incarnation,
|
|
148
|
+
meta: active.meta,
|
|
149
|
+
carried: carriedTranscriptDefinition(state.config, active.meta.version) !== void 0,
|
|
150
|
+
topLevelBefore: (key, limit, inclusive) => ordered.filter((record) => key === void 0 || (inclusive ? compare(record, key) <= 0 : compare(record, key) < 0)).reverse().slice(0, limit),
|
|
151
|
+
topLevelAfter: (key, limit, inclusive) => ordered.filter((record) => key === void 0 || (inclusive ? compare(record, key) >= 0 : compare(record, key) > 0)).slice(0, limit),
|
|
152
|
+
record: (id) => active.records.get(id),
|
|
153
|
+
alias: (namespace, key) => active.aliases.get(aliasKey(namespace, key)),
|
|
154
|
+
toolsOf: (assistantId) => records.flatMap((record) => record.kind === "tool" && record.assistantId === assistantId ? [record] : []),
|
|
155
|
+
pendingUsers: () => records.filter(isPendingTranscriptUserRecord)
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region src/services/session-store.ts
|
|
160
|
+
/** A durable event after the store has assigned its replay position. */
|
|
161
|
+
const CommittedDurableEvent = Schema.Struct({
|
|
162
|
+
position: DurablePosition,
|
|
163
|
+
event: DurableEventEnvelope.pipe(Schema.decodeTo(Schema.declare(Schema.is(DecodedDurableEvent)), {
|
|
164
|
+
decode: SchemaGetter.transform(decodeDurableEventSync),
|
|
165
|
+
encode: SchemaGetter.transform(durableEventEnvelope)
|
|
166
|
+
}))
|
|
167
|
+
});
|
|
168
|
+
/**
|
|
169
|
+
* Store-level failure surfaced by durable append, replay, and hydration APIs.
|
|
170
|
+
*
|
|
171
|
+
* The error intentionally stays storage-semantic rather than SQL-specific so
|
|
172
|
+
* framework services can treat SQL-backed hosts, in-memory tests, and future adapters
|
|
173
|
+
* as the same durability boundary.
|
|
174
|
+
*/
|
|
175
|
+
var EDASessionStoreError = class extends Schema.TaggedError()("EDASessionStoreError", { message: Schema.String }) {};
|
|
176
|
+
/** True when a Cause contains an escaped durable-store failure. */
|
|
177
|
+
const hasEDASessionStoreError = (cause) => cause.reasons.some((reason) => Cause.isFailReason(reason) && reason.error instanceof EDASessionStoreError);
|
|
178
|
+
/**
|
|
179
|
+
* One logical event to persist in the durable session log.
|
|
180
|
+
*
|
|
181
|
+
* Store adapters may split large logical payload fields into sidecar rows after
|
|
182
|
+
* the event insert assigns `seq`, but callers still provide one fat event.
|
|
183
|
+
*/
|
|
184
|
+
const DurableAppendEntry = Schema.Struct({ event: DurableEventEnvelope });
|
|
185
|
+
/**
|
|
186
|
+
* Ordered durable append intent. Adapters assign positions in entry order.
|
|
187
|
+
*
|
|
188
|
+
* This is the single write shape exposed to framework services. It avoids raw
|
|
189
|
+
* SQL and public transaction callbacks while still expressing the full atomic
|
|
190
|
+
* transition EDA needs for events, normalized bodies, and metadata.
|
|
191
|
+
*/
|
|
192
|
+
const DurableAppendBatch = Schema.Struct({ entries: Schema.Array(DurableAppendEntry) });
|
|
193
|
+
/** Indexed command-admission lookup used for idempotent ingress. */
|
|
194
|
+
const FindCommandAdmissionInput = Schema.Struct({
|
|
195
|
+
commandId: Schema.optionalKey(CommandId),
|
|
196
|
+
idempotencyKey: Schema.optionalKey(Schema.String)
|
|
197
|
+
});
|
|
198
|
+
/**
|
|
199
|
+
* SQL-agnostic durable storage port for one EDA session.
|
|
200
|
+
*
|
|
201
|
+
* Framework services depend on this semantic port rather than raw SQL. Host
|
|
202
|
+
* adapters own physical tables and synchronous transaction mechanics; callers
|
|
203
|
+
* only express durable append/replay/lookup intent.
|
|
204
|
+
*/
|
|
205
|
+
var EDASessionStore = class extends Context.Service()("@effect-durable-agent/EDASessionStore") {
|
|
206
|
+
/**
|
|
207
|
+
* Deterministic in-memory implementation used by runtime and recovery tests.
|
|
208
|
+
*
|
|
209
|
+
* It also provides `EDATranscriptStore`, maintaining the transcript inside the same append
|
|
210
|
+
* critical section. Without `options.transcript` it maintains the definition with no host
|
|
211
|
+
* mappings.
|
|
212
|
+
*/
|
|
213
|
+
static InMemory = (sessionId, options) => inMemoryStoreLayer(sessionId, () => [], options);
|
|
214
|
+
/** In-memory store seeded with a durable prefix; its transcript is built from that prefix. */
|
|
215
|
+
static InMemorySeeded = (sessionId, events, options) => inMemoryStoreLayer(sessionId, () => seedCommittedEvents(sessionId, events), options);
|
|
216
|
+
};
|
|
217
|
+
const inMemoryStoreLayer = (sessionId, seed, options) => Layer.effectContext(Effect.gen(function* () {
|
|
218
|
+
const committed = seed();
|
|
219
|
+
const config = options?.transcript ?? { current: yield* makeTranscriptDefinition(emptyTranscriptMappings).pipe(Effect.orDie) };
|
|
220
|
+
const data = yield* Ref.make({
|
|
221
|
+
committed,
|
|
222
|
+
summaries: summariesFromCommittedEvents(committed),
|
|
223
|
+
reducerCheckpoints: /* @__PURE__ */ new Map(),
|
|
224
|
+
transcript: initialTranscriptState(TranscriptLogIncarnation.make(`memory:${sessionId}`), config, committed)
|
|
225
|
+
});
|
|
226
|
+
return Context.make(EDASessionStore, makeInMemoryStore(sessionId, data)).pipe(Context.add(EDATranscriptStore, makeInMemoryTranscriptStore(data)));
|
|
227
|
+
}));
|
|
228
|
+
const seedCommittedEvents = (sessionId, events) => {
|
|
229
|
+
const seen = /* @__PURE__ */ new Set();
|
|
230
|
+
return events.map((event, index) => {
|
|
231
|
+
if (event.sessionId !== sessionId) throw new Error(`EDASessionStore.InMemorySeeded is scoped to session ${sessionId}; received ${event.sessionId}`);
|
|
232
|
+
if (seen.has(event.eventId)) throw new Error(`Duplicate seed eventId ${event.eventId}`);
|
|
233
|
+
seen.add(event.eventId);
|
|
234
|
+
return {
|
|
235
|
+
position: durablePosition(SequenceNumber.make(index + 1)),
|
|
236
|
+
event: decodeDurableEventSync(DurableEventEnvelope.make(event))
|
|
237
|
+
};
|
|
238
|
+
});
|
|
239
|
+
};
|
|
240
|
+
const summariesFromCommittedEvents = (events) => {
|
|
241
|
+
const summaries = /* @__PURE__ */ new Map();
|
|
242
|
+
for (const { event } of events) {
|
|
243
|
+
if (event.type !== summaryCreatedEventType) continue;
|
|
244
|
+
const payload = event.payload;
|
|
245
|
+
if (payload.summary !== void 0) {
|
|
246
|
+
const summary = Schema.decodeUnknownSync(CompactionSummaryArtifact)(payload.summary);
|
|
247
|
+
summaries.set(summary.summaryId, summary);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return summaries;
|
|
251
|
+
};
|
|
252
|
+
/**
|
|
253
|
+
* Build an in-memory store with one `Ref.modify` append critical section.
|
|
254
|
+
*
|
|
255
|
+
* The fake models the semantic atomicity of the production adapter without
|
|
256
|
+
* exposing SQL, so runtime tests exercise the same store contract.
|
|
257
|
+
*/
|
|
258
|
+
const makeInMemoryStore = (sessionId, data) => {
|
|
259
|
+
const ensureSession = (event) => Effect.gen(function* () {
|
|
260
|
+
if (event.sessionId === sessionId) return;
|
|
261
|
+
return yield* new EDASessionStoreError({ message: `EDASessionStore.InMemory is scoped to session ${sessionId}; received ${event.sessionId}` });
|
|
262
|
+
});
|
|
263
|
+
const append = (batch) => Effect.gen(function* () {
|
|
264
|
+
for (const entry of batch.entries) yield* ensureSession(entry.event);
|
|
265
|
+
return yield* Ref.modify(data, (current) => {
|
|
266
|
+
const nextEntries = [...current.committed];
|
|
267
|
+
const nextSummaries = new Map(current.summaries);
|
|
268
|
+
const committedEvents = [];
|
|
269
|
+
const appended = [];
|
|
270
|
+
for (const entry of batch.entries) {
|
|
271
|
+
const { event } = entry;
|
|
272
|
+
const existing = nextEntries.find((entry) => entry.event.eventId === event.eventId);
|
|
273
|
+
if (existing !== void 0) {
|
|
274
|
+
committedEvents.push(existing);
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
const committed = {
|
|
278
|
+
position: durablePosition(SequenceNumber.make(nextEntries.length + 1)),
|
|
279
|
+
event: decodeDurableEventSync(DurableEventEnvelope.make(event))
|
|
280
|
+
};
|
|
281
|
+
nextEntries.push(committed);
|
|
282
|
+
committedEvents.push(committed);
|
|
283
|
+
appended.push(committed);
|
|
284
|
+
if (committed.event.type === summaryCreatedEventType) {
|
|
285
|
+
const payload = committed.event.payload;
|
|
286
|
+
if (payload.summary === void 0) throw new Error("SummaryCreated requires summary payload");
|
|
287
|
+
const summary = Schema.decodeUnknownSync(CompactionSummaryArtifact)(payload.summary);
|
|
288
|
+
if (payload.summaryId !== void 0 && summary.summaryId !== payload.summaryId) throw new Error("SummaryCreated summaryId does not match summary payload");
|
|
289
|
+
nextSummaries.set(summary.summaryId, summary);
|
|
290
|
+
}
|
|
291
|
+
if (committed.event.type === contextRebasedEventType) {
|
|
292
|
+
const payload = committed.event.payload;
|
|
293
|
+
if (payload.summaryId === void 0 || !nextSummaries.has(payload.summaryId)) throw new Error(`ContextRebased references unknown summaryId ${String(payload.summaryId)}`);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return [committedEvents, {
|
|
297
|
+
committed: nextEntries,
|
|
298
|
+
summaries: nextSummaries,
|
|
299
|
+
reducerCheckpoints: current.reducerCheckpoints,
|
|
300
|
+
transcript: appended.length === 0 ? current.transcript : maintainTranscripts(current.transcript, appended)
|
|
301
|
+
}];
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
return {
|
|
305
|
+
append,
|
|
306
|
+
eventsAfter: (afterSeq) => Stream.fromIterableEffect(Ref.get(data).pipe(Effect.map(({ committed }) => committed.filter((entry) => entry.position.seq > afterSeq)))),
|
|
307
|
+
loadCommittedEventsBySeq: (seqs) => Ref.get(data).pipe(Effect.map(({ committed }) => {
|
|
308
|
+
const requested = new Set(seqs.map((seq) => Number(seq)));
|
|
309
|
+
return committed.filter((entry) => requested.has(Number(entry.position.seq)));
|
|
310
|
+
})),
|
|
311
|
+
findCommandAdmission: (input) => Ref.get(data).pipe(Effect.map(({ committed }) => committed.find((entry) => commandAdmissionMatches(entry, input)))),
|
|
312
|
+
loadSummaryArtifact: (summaryId) => Ref.get(data).pipe(Effect.map(({ summaries }) => summaries.get(summaryId))),
|
|
313
|
+
loadReducerCheckpoint: (name) => Ref.get(data).pipe(Effect.map(({ reducerCheckpoints }) => reducerCheckpoints.get(name))),
|
|
314
|
+
saveReducerCheckpoint: (checkpoint) => Ref.update(data, (current) => ({
|
|
315
|
+
...current,
|
|
316
|
+
reducerCheckpoints: new Map(current.reducerCheckpoints).set(checkpoint.name, checkpoint)
|
|
317
|
+
})),
|
|
318
|
+
saveReducerCheckpoints: (checkpoints) => Ref.update(data, (current) => {
|
|
319
|
+
const reducerCheckpoints = new Map(current.reducerCheckpoints);
|
|
320
|
+
for (const checkpoint of checkpoints) reducerCheckpoints.set(checkpoint.name, checkpoint);
|
|
321
|
+
return {
|
|
322
|
+
...current,
|
|
323
|
+
reducerCheckpoints
|
|
324
|
+
};
|
|
325
|
+
})
|
|
326
|
+
};
|
|
327
|
+
};
|
|
328
|
+
/** Transcript reads over the in-memory store's active version, at one `Ref` snapshot. */
|
|
329
|
+
const makeInMemoryTranscriptStore = (data) => ({
|
|
330
|
+
readTranscriptWindow: (selector, limits) => Effect.gen(function* () {
|
|
331
|
+
const { transcript } = yield* Ref.get(data);
|
|
332
|
+
const source = inMemoryTranscriptWindowSource(transcript);
|
|
333
|
+
if (source === void 0) return buildingTranscriptWindow(transcript.incarnation, transcript.config.current.version);
|
|
334
|
+
const window = readTranscriptWindowFrom(source, selector, limits);
|
|
335
|
+
return Result.isSuccess(window) ? window.success : yield* window.failure;
|
|
336
|
+
}),
|
|
337
|
+
readTranscriptMeta: Ref.get(data).pipe(Effect.map(({ transcript }) => transcript.versions.map((version) => version.meta)))
|
|
338
|
+
});
|
|
339
|
+
const commandAdmissionMatches = (entry, input) => {
|
|
340
|
+
if (entry.event.type !== commandAdmittedEventType) return false;
|
|
341
|
+
const admitted = entry.event.payload.command;
|
|
342
|
+
if (admitted === void 0) return false;
|
|
343
|
+
if (input.idempotencyKey !== void 0 && admitted.idempotencyKey === input.idempotencyKey) return true;
|
|
344
|
+
return input.commandId !== void 0 && admitted.commandId === input.commandId;
|
|
345
|
+
};
|
|
346
|
+
const eventNamespaces = (ast) => {
|
|
347
|
+
if (ast._tag === "Union") return ast.types.flatMap(eventNamespaces);
|
|
348
|
+
if (ast._tag === "Objects") {
|
|
349
|
+
const namespace = ast.propertySignatures.find((field) => field.name === "namespace")?.type;
|
|
350
|
+
if (namespace?._tag === "Literal" && typeof namespace.literal === "string") return [namespace.literal];
|
|
351
|
+
}
|
|
352
|
+
throw new Error("App event schemas must be a union of structs with literal namespaces");
|
|
353
|
+
};
|
|
354
|
+
/** Attach the app decoder to every event-returning store operation without changing storage bytes. */
|
|
355
|
+
const registerAppEvents = (store, schema) => {
|
|
356
|
+
const namespaces = new Set(eventNamespaces(schema.ast));
|
|
357
|
+
const decode = decodeRetainingExcess(schema);
|
|
358
|
+
const envelopeKey = (event) => JSON.stringify(Schema.encodeSync(DurableEventEnvelope)(event));
|
|
359
|
+
const decodeEntry = (entry, prepared) => {
|
|
360
|
+
if (entry.event.namespace !== "__foreign" || !namespaces.has(entry.event.envelope.namespace)) return entry;
|
|
361
|
+
return {
|
|
362
|
+
...entry,
|
|
363
|
+
event: {
|
|
364
|
+
...entry.event,
|
|
365
|
+
decoded: prepared?.get(envelopeKey(entry.event.envelope)) ?? decode(entry.event.envelope)
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
};
|
|
369
|
+
const decodeEntryEffect = (entry) => Effect.try({
|
|
370
|
+
try: () => decodeEntry(entry),
|
|
371
|
+
catch: (cause) => new EDASessionStoreError({ message: `Registered app event decode failed: ${String(cause)}` })
|
|
372
|
+
});
|
|
373
|
+
const decodeEntries = (entries) => Effect.forEach(entries, decodeEntryEffect);
|
|
374
|
+
return {
|
|
375
|
+
...store,
|
|
376
|
+
append: (batch) => Effect.gen(function* () {
|
|
377
|
+
const prepared = yield* Effect.try({
|
|
378
|
+
try: () => {
|
|
379
|
+
const decoded = /* @__PURE__ */ new Map();
|
|
380
|
+
for (const { event } of batch.entries) {
|
|
381
|
+
if (!namespaces.has(event.namespace)) continue;
|
|
382
|
+
const key = envelopeKey(event);
|
|
383
|
+
if (!decoded.has(key)) decoded.set(key, decode(event));
|
|
384
|
+
}
|
|
385
|
+
return decoded;
|
|
386
|
+
},
|
|
387
|
+
catch: (cause) => new EDASessionStoreError({ message: `Registered app event decode failed: ${String(cause)}` })
|
|
388
|
+
});
|
|
389
|
+
const committed = yield* store.append(batch);
|
|
390
|
+
return yield* Effect.forEach(committed, (entry) => Effect.try({
|
|
391
|
+
try: () => decodeEntry(entry, prepared),
|
|
392
|
+
catch: (cause) => new EDASessionStoreError({ message: `Registered app event decode failed: ${String(cause)}` })
|
|
393
|
+
}));
|
|
394
|
+
}),
|
|
395
|
+
eventsAfter: (seq) => store.eventsAfter(seq).pipe(Stream.mapEffect(decodeEntryEffect)),
|
|
396
|
+
loadCommittedEventsBySeq: (seqs) => store.loadCommittedEventsBySeq(seqs).pipe(Effect.flatMap(decodeEntries)),
|
|
397
|
+
findCommandAdmission: (input) => store.findCommandAdmission(input).pipe(Effect.flatMap((entry) => entry === void 0 ? Effect.succeed(void 0) : decodeEntryEffect(entry)))
|
|
398
|
+
};
|
|
399
|
+
};
|
|
400
|
+
/** Narrow an already decoded fact from one schema, without decoding its payload again. */
|
|
401
|
+
const selectCommittedEvent = (schema, entry) => {
|
|
402
|
+
const event = entry.event.namespace === "__foreign" ? entry.event.decoded ?? entry.event.envelope : entry.event;
|
|
403
|
+
return Schema.is(schema)(event) ? {
|
|
404
|
+
position: entry.position,
|
|
405
|
+
event
|
|
406
|
+
} : void 0;
|
|
407
|
+
};
|
|
408
|
+
/** Typed journal read available to tools and application services without private SQL access. */
|
|
409
|
+
const queryCommittedEvents = (store, schema, options = {}) => store.eventsAfter(options.afterSeq ?? SequenceNumber.make(0)).pipe(Stream.map((entry) => selectCommittedEvent(schema, entry)), Stream.filter((entry) => entry !== void 0), Stream.take(options.limit ?? Number.MAX_SAFE_INTEGER), Stream.runCollect);
|
|
410
|
+
//#endregion
|
|
411
|
+
export { EDASessionStoreError as a, queryCommittedEvents as c, EDASessionStore as i, registerAppEvents as l, DurableAppendBatch as n, FindCommandAdmissionInput as o, DurableAppendEntry as r, hasEDASessionStoreError as s, CommittedDurableEvent as t, selectCommittedEvent as u };
|
|
412
|
+
|
|
413
|
+
//# sourceMappingURL=session-store-DcJjs4Fd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-store-DcJjs4Fd.js","names":[],"sources":["../src/transcript/in-memory.ts","../src/services/session-store.ts"],"sourcesContent":["import type { CommittedDurableEvent } from \"../services/session-store\";\nimport { SequenceNumber } from \"../types/core\";\nimport { planTranscriptBatch } from \"./interpreter\";\nimport type { TranscriptDefinition } from \"./mapping\";\nimport type { TranscriptAliasNamespace, TranscriptChangePlan, TranscriptLookup } from \"./plan\";\nimport {\n TranscriptOrder,\n isPendingTranscriptUserRecord,\n isTopLevelTranscriptRecord,\n type TranscriptLogIncarnation,\n type TranscriptOrderKey,\n type TranscriptRecord,\n type TranscriptRecordId,\n type TranscriptTopLevelRecord,\n type TranscriptVersion,\n} from \"./records\";\nimport type { TranscriptMaintenanceConfig } from \"./store\";\nimport type { TranscriptVersionMeta } from \"./window\";\nimport type { TranscriptWindowSource } from \"./window-read\";\n\n/**\n * The in-memory store's transcript state: the semantic model of the adapter's tables\n * (`transcript_records`, `transcript_aliases`, `transcript_meta`), kept inside the store's\n * `Ref.modify` critical section so maintenance commits atomically with the appended events.\n */\nexport interface InMemoryTranscriptVersion {\n readonly meta: TranscriptVersionMeta;\n readonly records: ReadonlyMap<TranscriptRecordId, TranscriptRecord>;\n readonly aliases: ReadonlyMap<string, TranscriptRecordId>;\n readonly ordinals: ReadonlyMap<number, number>;\n}\n\nexport interface InMemoryTranscriptState {\n readonly incarnation: TranscriptLogIncarnation;\n readonly config: TranscriptMaintenanceConfig;\n readonly versions: ReadonlyArray<InMemoryTranscriptVersion>;\n}\n\nconst aliasKey = (namespace: TranscriptAliasNamespace, key: string) => `${namespace}\\u0000${key}`;\n\n/** The carried definition for a stored version, if this release still carries it. */\nexport const carriedTranscriptDefinition = (\n config: TranscriptMaintenanceConfig,\n version: TranscriptVersion,\n): TranscriptDefinition | undefined =>\n config.current.version === version\n ? config.current\n : config.previous?.version === version\n ? config.previous\n : undefined;\n\n/** An empty version before any event is projected. */\nexport const emptyTranscriptVersion = (\n version: TranscriptVersion,\n role: TranscriptVersionMeta[\"role\"],\n): InMemoryTranscriptVersion => ({\n meta: { version, role, cursor: SequenceNumber.make(0), status: { _tag: \"Ok\" } },\n records: new Map(),\n aliases: new Map(),\n ordinals: new Map(),\n});\n\nconst lookupOf = (version: InMemoryTranscriptVersion): TranscriptLookup => ({\n cursor: version.meta.cursor,\n record: (id) => version.records.get(id),\n alias: (namespace, key) => version.aliases.get(aliasKey(namespace, key)),\n nextOrdinal: (anchorSeq) => version.ordinals.get(anchorSeq) ?? 0,\n});\n\nconst applyPlan = (\n version: InMemoryTranscriptVersion,\n plan: TranscriptChangePlan,\n): InMemoryTranscriptVersion => {\n const records = new Map(version.records);\n const aliases = new Map(version.aliases);\n const ordinals = new Map(version.ordinals);\n for (const record of plan.records) {\n records.set(record.id, record);\n if (\"position\" in record && record.position !== undefined) {\n const { anchorSeq, ordinal } = record.position;\n ordinals.set(anchorSeq, Math.max(ordinals.get(anchorSeq) ?? 0, ordinal + 1));\n }\n }\n for (const alias of plan.aliases) {\n const key = aliasKey(alias.namespace, alias.key);\n if (!aliases.has(key)) aliases.set(key, alias.recordId);\n }\n return { meta: { ...version.meta, cursor: plan.throughSeq }, records, aliases, ordinals };\n};\n\n/**\n * Project committed events into one version, or freeze it.\n *\n * A projection failure marks only this version failed at its unchanged cursor and leaves its\n * rows exactly as they were, so it remains a consistent last-good cut.\n */\nexport const advanceTranscriptVersion = (\n version: InMemoryTranscriptVersion,\n definition: TranscriptDefinition,\n committed: ReadonlyArray<CommittedDurableEvent>,\n): InMemoryTranscriptVersion => {\n const fresh = committed.filter((entry) => entry.position.seq > version.meta.cursor);\n const first = fresh[0];\n if (first === undefined || version.meta.status._tag === \"Failed\") return version;\n try {\n return applyPlan(version, planTranscriptBatch(lookupOf(version), fresh, definition));\n } catch (error) {\n return {\n ...version,\n meta: {\n ...version.meta,\n status: {\n _tag: \"Failed\",\n failedAtSeq: first.position.seq,\n error: error instanceof Error ? error.message : String(error),\n },\n },\n };\n }\n};\n\n/** Maintain every carried, healthy version for a committed append; others stay frozen. */\nexport const maintainTranscripts = (\n state: InMemoryTranscriptState,\n committed: ReadonlyArray<CommittedDurableEvent>,\n): InMemoryTranscriptState => ({\n ...state,\n versions: state.versions.map((version) => {\n const definition = carriedTranscriptDefinition(state.config, version.meta.version);\n return definition === undefined\n ? version\n : advanceTranscriptVersion(version, definition, committed);\n }),\n});\n\n/**\n * Converge a session to the current definition, as the adapter's builder does in slices.\n *\n * A building version that is not `current` is discarded. If the active version is not `current`,\n * `current` is built from the log (never from old rows) and, once it reaches the head, becomes\n * active and the old version is deleted. A failed build leaves the active version serving; only a\n * new definition repairs it. A brand-new log simply initializes `current`.\n */\nexport const convergeTranscripts = (\n state: InMemoryTranscriptState,\n log: ReadonlyArray<CommittedDurableEvent>,\n): InMemoryTranscriptState => {\n const current = state.config.current;\n const versions = state.versions.filter(\n (version) => version.meta.role === \"active\" || version.meta.version === current.version,\n );\n const active = versions.find((version) => version.meta.role === \"active\");\n if (active?.meta.version === current.version) return { ...state, versions };\n\n const building =\n versions.find((version) => version.meta.role === \"building\") ??\n emptyTranscriptVersion(current.version, \"building\");\n const built = advanceTranscriptVersion(building, current, log);\n if (built.meta.status._tag === \"Failed\") {\n return { ...state, versions: [...versions.filter((version) => version !== building), built] };\n }\n return { ...state, versions: [{ ...built, meta: { ...built.meta, role: \"active\" } }] };\n};\n\n/** Initial transcript state for a store whose log already holds `log`. */\nexport const initialTranscriptState = (\n incarnation: TranscriptLogIncarnation,\n config: TranscriptMaintenanceConfig,\n log: ReadonlyArray<CommittedDurableEvent>,\n): InMemoryTranscriptState => convergeTranscripts({ incarnation, config, versions: [] }, log);\n\nconst topLevelOrder = (record: TranscriptTopLevelRecord): TranscriptOrderKey => ({\n anchorSeq: record.position?.anchorSeq ?? 0,\n ordinal: record.position?.ordinal ?? 0,\n recordId: record.id,\n});\n\n/** Window reads over the active version, or undefined while nothing is servable. */\nexport const inMemoryTranscriptWindowSource = (\n state: InMemoryTranscriptState,\n): TranscriptWindowSource | undefined => {\n const active = state.versions.find((version) => version.meta.role === \"active\");\n if (active === undefined) return undefined;\n const records = Array.from(active.records.values());\n const ordered = records\n .filter(isTopLevelTranscriptRecord)\n .sort((left, right) => TranscriptOrder(topLevelOrder(left), topLevelOrder(right)));\n const compare = (record: TranscriptTopLevelRecord, key: TranscriptOrderKey) =>\n TranscriptOrder(topLevelOrder(record), key);\n return {\n incarnation: state.incarnation,\n meta: active.meta,\n carried: carriedTranscriptDefinition(state.config, active.meta.version) !== undefined,\n topLevelBefore: (key, limit, inclusive) =>\n ordered\n .filter(\n (record) =>\n key === undefined || (inclusive ? compare(record, key) <= 0 : compare(record, key) < 0),\n )\n .reverse()\n .slice(0, limit),\n topLevelAfter: (key, limit, inclusive) =>\n ordered\n .filter(\n (record) =>\n key === undefined || (inclusive ? compare(record, key) >= 0 : compare(record, key) > 0),\n )\n .slice(0, limit),\n record: (id) => active.records.get(id),\n alias: (namespace, key) => active.aliases.get(aliasKey(namespace, key)),\n toolsOf: (assistantId) =>\n records.flatMap((record) =>\n record.kind === \"tool\" && record.assistantId === assistantId ? [record] : [],\n ),\n pendingUsers: () => records.filter(isPendingTranscriptUserRecord),\n };\n};\n","import * as Cause from \"effect/Cause\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as Ref from \"effect/Ref\";\nimport * as Result from \"effect/Result\";\nimport * as Schema from \"effect/Schema\";\nimport * as SchemaGetter from \"effect/SchemaGetter\";\nimport type * as SchemaAST from \"effect/SchemaAST\";\nimport * as Stream from \"effect/Stream\";\n\nimport {\n DecodedDurableEvent,\n decodeDurableEventSync,\n durableEventEnvelope,\n} from \"../types/events/durable\";\n\nimport { type CommandIdempotencyKey } from \"../types/commands\";\nimport { CompactionSummaryArtifact } from \"../domain/context-projection\";\nimport {\n CommandId,\n DurablePosition,\n SequenceNumber,\n SessionId,\n SummaryId,\n durablePosition,\n} from \"../types/core\";\nimport {\n DurableEventEnvelope,\n commandAdmittedEventType,\n contextRebasedEventType,\n summaryCreatedEventType,\n} from \"../types/events\";\nimport { decodeRetainingExcess } from \"../types/events/internal\";\nimport {\n initialTranscriptState,\n inMemoryTranscriptWindowSource,\n maintainTranscripts,\n type InMemoryTranscriptState,\n} from \"../transcript/in-memory\";\nimport { emptyTranscriptMappings, makeTranscriptDefinition } from \"../transcript/mapping\";\nimport { TranscriptLogIncarnation } from \"../transcript/records\";\nimport {\n EDATranscriptStore,\n type EDATranscriptStoreShape,\n type TranscriptMaintenanceConfig,\n} from \"../transcript/store\";\nimport { buildingTranscriptWindow, readTranscriptWindowFrom } from \"../transcript/window-read\";\n\nexport type CommittedDurableEvent<E = DecodedDurableEvent> = {\n readonly position: typeof DurablePosition.Type;\n readonly event: E;\n};\n\n/** A durable event after the store has assigned its replay position. */\nexport const CommittedDurableEvent: Schema.Codec<\n CommittedDurableEvent,\n {\n readonly position: typeof DurablePosition.Encoded;\n readonly event: typeof DurableEventEnvelope.Encoded;\n },\n never,\n never\n> = Schema.Struct({\n position: DurablePosition,\n event: DurableEventEnvelope.pipe(\n Schema.decodeTo(Schema.declare<DecodedDurableEvent>(Schema.is(DecodedDurableEvent)), {\n decode: SchemaGetter.transform(decodeDurableEventSync),\n encode: SchemaGetter.transform(durableEventEnvelope),\n }),\n ),\n});\n/**\n * Store-level failure surfaced by durable append, replay, and hydration APIs.\n *\n * The error intentionally stays storage-semantic rather than SQL-specific so\n * framework services can treat SQL-backed hosts, in-memory tests, and future adapters\n * as the same durability boundary.\n */\nexport class EDASessionStoreError extends Schema.TaggedError<EDASessionStoreError>()(\n \"EDASessionStoreError\",\n {\n message: Schema.String,\n },\n) {}\n\n/** True when a Cause contains an escaped durable-store failure. */\nexport const hasEDASessionStoreError = (cause: Cause.Cause<unknown>): boolean =>\n cause.reasons.some(\n (reason) => Cause.isFailReason(reason) && reason.error instanceof EDASessionStoreError,\n );\n\n/**\n * One logical event to persist in the durable session log.\n *\n * Store adapters may split large logical payload fields into sidecar rows after\n * the event insert assigns `seq`, but callers still provide one fat event.\n */\nexport const DurableAppendEntry = Schema.Struct({\n event: DurableEventEnvelope,\n});\nexport type DurableAppendEntry = typeof DurableAppendEntry.Type;\n\n/**\n * Ordered durable append intent. Adapters assign positions in entry order.\n *\n * This is the single write shape exposed to framework services. It avoids raw\n * SQL and public transaction callbacks while still expressing the full atomic\n * transition EDA needs for events, normalized bodies, and metadata.\n */\nexport const DurableAppendBatch = Schema.Struct({\n entries: Schema.Array(DurableAppendEntry),\n});\nexport type DurableAppendBatch = typeof DurableAppendBatch.Type;\n\n/** Durable reducer checkpoint row used to hydrate framework and app projections cheaply. */\nexport interface EDAReducerCheckpoint {\n readonly name: string;\n readonly schemaVersion: number;\n readonly throughSeq: SequenceNumber;\n readonly payload: unknown;\n readonly updatedAtMs: number;\n}\n\n/** Input for writing one durable reducer checkpoint. */\nexport interface SaveReducerCheckpointInput {\n readonly name: string;\n readonly schemaVersion: number;\n readonly throughSeq: SequenceNumber;\n readonly payload: unknown;\n readonly updatedAtMs: number;\n}\n\n/** Indexed command-admission lookup used for idempotent ingress. */\nexport const FindCommandAdmissionInput = Schema.Struct({\n commandId: Schema.optionalKey(CommandId),\n idempotencyKey: Schema.optionalKey(Schema.String),\n});\n/** Typed command-admission lookup accepted by the semantic store port. */\nexport interface FindCommandAdmissionInput {\n readonly commandId?: CommandId;\n readonly idempotencyKey?: CommandIdempotencyKey;\n}\n\n/** Semantic durable store contract for one EDA session. */\nexport interface EDASessionStoreShape {\n /**\n * Append durable logical events atomically, preserving input order.\n *\n * Implementations must be idempotent by `eventId`: duplicates return the\n * original committed position and do not advance the durable head. Live publish\n * remains outside the store and is owned by `SessionState` after this succeeds.\n */\n readonly append: (\n batch: DurableAppendBatch,\n ) => Effect.Effect<ReadonlyArray<CommittedDurableEvent>, EDASessionStoreError>;\n /** Replay committed durable events with `seq > afterSeq`. */\n readonly eventsAfter: (\n afterSeq: SequenceNumber,\n ) => Stream.Stream<CommittedDurableEvent, EDASessionStoreError>;\n /** Load committed durable events by exact sequence number for checkpoint pointer hydration. */\n readonly loadCommittedEventsBySeq: (\n seqs: ReadonlyArray<SequenceNumber>,\n ) => Effect.Effect<ReadonlyArray<CommittedDurableEvent>, EDASessionStoreError>;\n /** Lookup an admitted command without replaying the full journal. */\n readonly findCommandAdmission: (\n input: FindCommandAdmissionInput,\n ) => Effect.Effect<CommittedDurableEvent | undefined, EDASessionStoreError>;\n /** Load one compacted summary artifact body by id, if it has been saved. */\n readonly loadSummaryArtifact: (\n summaryId: SummaryId,\n ) => Effect.Effect<CompactionSummaryArtifact | undefined, EDASessionStoreError>;\n /** Load one framework or app reducer checkpoint, if it has been saved. */\n readonly loadReducerCheckpoint: (\n name: string,\n ) => Effect.Effect<EDAReducerCheckpoint | undefined, EDASessionStoreError>;\n /** Persist one framework or app reducer checkpoint as a derived cache. */\n readonly saveReducerCheckpoint: (\n checkpoint: SaveReducerCheckpointInput,\n ) => Effect.Effect<void, EDASessionStoreError>;\n /** Persist a reducer checkpoint snapshot atomically across framework and app reducers. */\n readonly saveReducerCheckpoints: (\n checkpoints: ReadonlyArray<SaveReducerCheckpointInput>,\n ) => Effect.Effect<void, EDASessionStoreError>;\n}\n\n/**\n * SQL-agnostic durable storage port for one EDA session.\n *\n * Framework services depend on this semantic port rather than raw SQL. Host\n * adapters own physical tables and synchronous transaction mechanics; callers\n * only express durable append/replay/lookup intent.\n */\nexport class EDASessionStore extends Context.Service<EDASessionStore, EDASessionStoreShape>()(\n \"@effect-durable-agent/EDASessionStore\",\n) {\n /**\n * Deterministic in-memory implementation used by runtime and recovery tests.\n *\n * It also provides `EDATranscriptStore`, maintaining the transcript inside the same append\n * critical section. Without `options.transcript` it maintains the definition with no host\n * mappings.\n */\n static readonly InMemory = (sessionId: SessionId, options?: InMemoryStoreOptions) =>\n inMemoryStoreLayer(sessionId, () => [], options);\n\n /** In-memory store seeded with a durable prefix; its transcript is built from that prefix. */\n static readonly InMemorySeeded = (\n sessionId: SessionId,\n events: ReadonlyArray<DurableEventEnvelope>,\n options?: InMemoryStoreOptions,\n ) => inMemoryStoreLayer(sessionId, () => seedCommittedEvents(sessionId, events), options);\n}\n\n/** Construction options for the in-memory store. */\nexport interface InMemoryStoreOptions {\n /** Transcript definitions to maintain; defaults to the definition with no host mappings. */\n readonly transcript?: TranscriptMaintenanceConfig;\n}\n\nconst inMemoryStoreLayer = (\n sessionId: SessionId,\n seed: () => ReadonlyArray<CommittedDurableEvent>,\n options: InMemoryStoreOptions | undefined,\n) =>\n Layer.effectContext(\n Effect.gen(function* () {\n const committed = seed();\n const config = options?.transcript ?? {\n current: yield* makeTranscriptDefinition(emptyTranscriptMappings).pipe(Effect.orDie),\n };\n const data = yield* Ref.make<InMemoryStoreData>({\n committed,\n summaries: summariesFromCommittedEvents(committed),\n reducerCheckpoints: new Map(),\n transcript: initialTranscriptState(\n TranscriptLogIncarnation.make(`memory:${sessionId}`),\n config,\n committed,\n ),\n });\n return Context.make(EDASessionStore, makeInMemoryStore(sessionId, data)).pipe(\n Context.add(EDATranscriptStore, makeInMemoryTranscriptStore(data)),\n );\n }),\n );\n\ninterface InMemoryStoreData {\n readonly committed: ReadonlyArray<CommittedDurableEvent>;\n readonly summaries: ReadonlyMap<SummaryId, CompactionSummaryArtifact>;\n readonly reducerCheckpoints: ReadonlyMap<string, EDAReducerCheckpoint>;\n readonly transcript: InMemoryTranscriptState;\n}\n\nconst seedCommittedEvents = (\n sessionId: SessionId,\n events: ReadonlyArray<DurableEventEnvelope>,\n): ReadonlyArray<CommittedDurableEvent> => {\n const seen = new Set<string>();\n return events.map((event, index) => {\n if (event.sessionId !== sessionId) {\n throw new Error(\n `EDASessionStore.InMemorySeeded is scoped to session ${sessionId}; received ${event.sessionId}`,\n );\n }\n if (seen.has(event.eventId)) {\n throw new Error(`Duplicate seed eventId ${event.eventId}`);\n }\n seen.add(event.eventId);\n return {\n position: durablePosition(SequenceNumber.make(index + 1)),\n event: decodeDurableEventSync(DurableEventEnvelope.make(event)),\n };\n });\n};\n\nconst summariesFromCommittedEvents = (\n events: ReadonlyArray<CommittedDurableEvent>,\n): ReadonlyMap<SummaryId, CompactionSummaryArtifact> => {\n const summaries = new Map<SummaryId, CompactionSummaryArtifact>();\n for (const { event } of events) {\n if (event.type !== summaryCreatedEventType) {\n continue;\n }\n const payload = event.payload;\n if (payload.summary !== undefined) {\n const summary = Schema.decodeUnknownSync(CompactionSummaryArtifact)(payload.summary);\n summaries.set(summary.summaryId, summary);\n }\n }\n return summaries;\n};\n\n/**\n * Build an in-memory store with one `Ref.modify` append critical section.\n *\n * The fake models the semantic atomicity of the production adapter without\n * exposing SQL, so runtime tests exercise the same store contract.\n */\nconst makeInMemoryStore = (\n sessionId: SessionId,\n data: Ref.Ref<InMemoryStoreData>,\n): EDASessionStoreShape => {\n const ensureSession = (event: DurableEventEnvelope): Effect.Effect<void, EDASessionStoreError> =>\n Effect.gen(function* () {\n if (event.sessionId === sessionId) {\n return;\n }\n return yield* new EDASessionStoreError({\n message: `EDASessionStore.InMemory is scoped to session ${sessionId}; received ${event.sessionId}`,\n });\n });\n\n const append = (batch: DurableAppendBatch) =>\n Effect.gen(function* () {\n for (const entry of batch.entries) {\n yield* ensureSession(entry.event);\n }\n\n return yield* Ref.modify(data, (current) => {\n const nextEntries: Array<CommittedDurableEvent> = [...current.committed];\n const nextSummaries = new Map(current.summaries);\n const committedEvents: Array<CommittedDurableEvent> = [];\n const appended: Array<CommittedDurableEvent> = [];\n\n for (const entry of batch.entries) {\n const { event } = entry;\n const existing = nextEntries.find((entry) => entry.event.eventId === event.eventId);\n if (existing !== undefined) {\n committedEvents.push(existing);\n continue;\n }\n\n const committed: CommittedDurableEvent = {\n position: durablePosition(SequenceNumber.make(nextEntries.length + 1)),\n event: decodeDurableEventSync(DurableEventEnvelope.make(event)),\n };\n nextEntries.push(committed);\n committedEvents.push(committed);\n appended.push(committed);\n\n if (committed.event.type === summaryCreatedEventType) {\n const payload = committed.event.payload;\n if (payload.summary === undefined) {\n throw new Error(\"SummaryCreated requires summary payload\");\n }\n const summary = Schema.decodeUnknownSync(CompactionSummaryArtifact)(payload.summary);\n if (payload.summaryId !== undefined && summary.summaryId !== payload.summaryId) {\n throw new Error(\"SummaryCreated summaryId does not match summary payload\");\n }\n nextSummaries.set(summary.summaryId, summary);\n }\n\n if (committed.event.type === contextRebasedEventType) {\n const payload = committed.event.payload;\n if (payload.summaryId === undefined || !nextSummaries.has(payload.summaryId)) {\n throw new Error(\n `ContextRebased references unknown summaryId ${String(payload.summaryId)}`,\n );\n }\n }\n }\n\n return [\n committedEvents,\n {\n committed: nextEntries,\n summaries: nextSummaries,\n reducerCheckpoints: current.reducerCheckpoints,\n // Projection staging commits with the events; a projection failure freezes only\n // the failed version and never fails the append.\n transcript:\n appended.length === 0\n ? current.transcript\n : maintainTranscripts(current.transcript, appended),\n },\n ];\n });\n });\n\n return {\n append,\n eventsAfter: (afterSeq) =>\n Stream.fromIterableEffect(\n Ref.get(data).pipe(\n Effect.map(({ committed }) => committed.filter((entry) => entry.position.seq > afterSeq)),\n ),\n ),\n loadCommittedEventsBySeq: (seqs) =>\n Ref.get(data).pipe(\n Effect.map(({ committed }) => {\n const requested = new Set(seqs.map((seq) => Number(seq)));\n return committed.filter((entry) => requested.has(Number(entry.position.seq)));\n }),\n ),\n findCommandAdmission: (input) =>\n Ref.get(data).pipe(\n Effect.map(({ committed }) =>\n committed.find((entry) => commandAdmissionMatches(entry, input)),\n ),\n ),\n loadSummaryArtifact: (summaryId) =>\n Ref.get(data).pipe(Effect.map(({ summaries }) => summaries.get(summaryId))),\n loadReducerCheckpoint: (name) =>\n Ref.get(data).pipe(Effect.map(({ reducerCheckpoints }) => reducerCheckpoints.get(name))),\n saveReducerCheckpoint: (checkpoint) =>\n Ref.update(data, (current) => ({\n ...current,\n reducerCheckpoints: new Map(current.reducerCheckpoints).set(checkpoint.name, checkpoint),\n })),\n saveReducerCheckpoints: (checkpoints) =>\n Ref.update(data, (current) => {\n const reducerCheckpoints = new Map(current.reducerCheckpoints);\n for (const checkpoint of checkpoints) {\n reducerCheckpoints.set(checkpoint.name, checkpoint);\n }\n return { ...current, reducerCheckpoints };\n }),\n };\n};\n\n/** Transcript reads over the in-memory store's active version, at one `Ref` snapshot. */\nconst makeInMemoryTranscriptStore = (\n data: Ref.Ref<InMemoryStoreData>,\n): EDATranscriptStoreShape => ({\n readTranscriptWindow: (selector, limits) =>\n Effect.gen(function* () {\n const { transcript } = yield* Ref.get(data);\n const source = inMemoryTranscriptWindowSource(transcript);\n if (source === undefined) {\n return buildingTranscriptWindow(transcript.incarnation, transcript.config.current.version);\n }\n const window = readTranscriptWindowFrom(source, selector, limits);\n return Result.isSuccess(window) ? window.success : yield* window.failure;\n }),\n readTranscriptMeta: Ref.get(data).pipe(\n Effect.map(({ transcript }) => transcript.versions.map((version) => version.meta)),\n ),\n});\n\nconst commandAdmissionMatches = (\n entry: CommittedDurableEvent,\n input: FindCommandAdmissionInput,\n): boolean => {\n if (entry.event.type !== commandAdmittedEventType) {\n return false;\n }\n const admitted = entry.event.payload.command;\n if (admitted === undefined) {\n return false;\n }\n if (input.idempotencyKey !== undefined && admitted.idempotencyKey === input.idempotencyKey) {\n return true;\n }\n return input.commandId !== undefined && admitted.commandId === input.commandId;\n};\n\n/** App schemas are registered once; known namespaces fail at the store boundary when malformed. */\nexport type EDAAppEvents = Schema.Codec<DurableEventEnvelope, unknown, never, never>;\n\nconst eventNamespaces = (ast: SchemaAST.AST): ReadonlyArray<string> => {\n if (ast._tag === \"Union\") return ast.types.flatMap(eventNamespaces);\n if (ast._tag === \"Objects\") {\n const namespace = ast.propertySignatures.find((field) => field.name === \"namespace\")?.type;\n if (namespace?._tag === \"Literal\" && typeof namespace.literal === \"string\")\n return [namespace.literal];\n }\n throw new Error(\"App event schemas must be a union of structs with literal namespaces\");\n};\n\n/** Attach the app decoder to every event-returning store operation without changing storage bytes. */\nexport const registerAppEvents = (\n store: EDASessionStoreShape,\n schema: EDAAppEvents,\n): EDASessionStoreShape => {\n const namespaces = new Set(eventNamespaces(schema.ast));\n const decode = decodeRetainingExcess(schema);\n const envelopeKey = (event: DurableEventEnvelope): string =>\n JSON.stringify(Schema.encodeSync(DurableEventEnvelope)(event));\n const decodeEntry = (\n entry: CommittedDurableEvent,\n prepared?: ReadonlyMap<string, DurableEventEnvelope>,\n ): CommittedDurableEvent => {\n if (entry.event.namespace !== \"__foreign\" || !namespaces.has(entry.event.envelope.namespace))\n return entry;\n return {\n ...entry,\n event: {\n ...entry.event,\n decoded: prepared?.get(envelopeKey(entry.event.envelope)) ?? decode(entry.event.envelope),\n },\n };\n };\n const decodeEntryEffect = (entry: CommittedDurableEvent) =>\n Effect.try({\n try: () => decodeEntry(entry),\n catch: (cause) =>\n new EDASessionStoreError({\n message: `Registered app event decode failed: ${String(cause)}`,\n }),\n });\n const decodeEntries = (entries: ReadonlyArray<CommittedDurableEvent>) =>\n Effect.forEach(entries, decodeEntryEffect);\n return {\n ...store,\n append: (batch) =>\n Effect.gen(function* () {\n // Idempotent append can return different retained bytes for the same event id.\n // Reuse a prepared decode only when the complete persisted envelope matches.\n const prepared = yield* Effect.try({\n try: () => {\n const decoded = new Map<string, DurableEventEnvelope>();\n for (const { event } of batch.entries) {\n if (!namespaces.has(event.namespace)) continue;\n const key = envelopeKey(event);\n if (!decoded.has(key)) {\n decoded.set(key, decode(event));\n }\n }\n return decoded;\n },\n catch: (cause) =>\n new EDASessionStoreError({\n message: `Registered app event decode failed: ${String(cause)}`,\n }),\n });\n const committed = yield* store.append(batch);\n return yield* Effect.forEach(committed, (entry) =>\n Effect.try({\n try: () => decodeEntry(entry, prepared),\n catch: (cause) =>\n new EDASessionStoreError({\n message: `Registered app event decode failed: ${String(cause)}`,\n }),\n }),\n );\n }),\n eventsAfter: (seq) => store.eventsAfter(seq).pipe(Stream.mapEffect(decodeEntryEffect)),\n loadCommittedEventsBySeq: (seqs) =>\n store.loadCommittedEventsBySeq(seqs).pipe(Effect.flatMap(decodeEntries)),\n findCommandAdmission: (input) =>\n store\n .findCommandAdmission(input)\n .pipe(\n Effect.flatMap((entry) =>\n entry === undefined ? Effect.succeed(undefined) : decodeEntryEffect(entry),\n ),\n ),\n };\n};\n\n/** Narrow an already decoded fact from one schema, without decoding its payload again. */\nexport const selectCommittedEvent = <E extends DurableEventEnvelope>(\n schema: Schema.Codec<E, unknown, never, never>,\n entry: CommittedDurableEvent,\n): CommittedDurableEvent<E> | undefined => {\n const event =\n entry.event.namespace === \"__foreign\"\n ? (entry.event.decoded ?? entry.event.envelope)\n : entry.event;\n return Schema.is(schema)(event) ? { position: entry.position, event } : undefined;\n};\n\n/** Typed journal read available to tools and application services without private SQL access. */\nexport const queryCommittedEvents = <E extends DurableEventEnvelope>(\n store: EDASessionStoreShape,\n schema: Schema.Codec<E, unknown, never, never>,\n options: { readonly afterSeq?: SequenceNumber; readonly limit?: number } = {},\n): Effect.Effect<ReadonlyArray<CommittedDurableEvent<E>>, EDASessionStoreError> =>\n store.eventsAfter(options.afterSeq ?? SequenceNumber.make(0)).pipe(\n Stream.map((entry) => selectCommittedEvent(schema, entry)),\n Stream.filter((entry): entry is CommittedDurableEvent<E> => entry !== undefined),\n Stream.take(options.limit ?? Number.MAX_SAFE_INTEGER),\n Stream.runCollect,\n );\n"],"mappings":";;;;;;;;;;;;;;;AAsCA,MAAM,YAAY,WAAqC,QAAgB,GAAG,UAAU,QAAQ;;AAG5F,MAAa,+BACX,QACA,YAEA,OAAO,QAAQ,YAAY,UACvB,OAAO,UACP,OAAO,UAAU,YAAY,UAC3B,OAAO,WACP,KAAA;;AAGR,MAAa,0BACX,SACA,UAC+B;CAC/B,MAAM;EAAE;EAAS;EAAM,QAAQ,eAAe,KAAK,CAAC;EAAG,QAAQ,EAAE,MAAM,KAAK;CAAE;CAC9E,yBAAS,IAAI,IAAI;CACjB,yBAAS,IAAI,IAAI;CACjB,0BAAU,IAAI,IAAI;AACpB;AAEA,MAAM,YAAY,aAA0D;CAC1E,QAAQ,QAAQ,KAAK;CACrB,SAAS,OAAO,QAAQ,QAAQ,IAAI,EAAE;CACtC,QAAQ,WAAW,QAAQ,QAAQ,QAAQ,IAAI,SAAS,WAAW,GAAG,CAAC;CACvE,cAAc,cAAc,QAAQ,SAAS,IAAI,SAAS,KAAK;AACjE;AAEA,MAAM,aACJ,SACA,SAC8B;CAC9B,MAAM,UAAU,IAAI,IAAI,QAAQ,OAAO;CACvC,MAAM,UAAU,IAAI,IAAI,QAAQ,OAAO;CACvC,MAAM,WAAW,IAAI,IAAI,QAAQ,QAAQ;CACzC,KAAK,MAAM,UAAU,KAAK,SAAS;EACjC,QAAQ,IAAI,OAAO,IAAI,MAAM;EAC7B,IAAI,cAAc,UAAU,OAAO,aAAa,KAAA,GAAW;GACzD,MAAM,EAAE,WAAW,YAAY,OAAO;GACtC,SAAS,IAAI,WAAW,KAAK,IAAI,SAAS,IAAI,SAAS,KAAK,GAAG,UA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AAqB,QAAQ,KAAK,CAAC,GACzD,OAAO,QAAQ,UAA6C,UAAU,KAAA,CAAS,GAC/E,OAAO,KAAK,QAAQ,SAAS,OAAO,gBAAgB,GACpD,OAAO,UACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { h as SequenceNumber } from "./core-BcimKMIv.js";
|
|
2
|
-
import { s as EDASessionStoreError } from "./session-store-
|
|
2
|
+
import { s as EDASessionStoreError } from "./session-store-ByDjS03N.js";
|
|
3
3
|
import * as Context from "effect/Context";
|
|
4
4
|
import * as Effect from "effect/Effect";
|
|
5
5
|
import * as Layer from "effect/Layer";
|
|
@@ -36,4 +36,4 @@ declare class SinkCheckpointStore extends SinkCheckpointStore_base {
|
|
|
36
36
|
}
|
|
37
37
|
//#endregion
|
|
38
38
|
export { StoredSinkCheckpoint as i, SinkCheckpointStore as n, SinkCheckpointStoreShape as r, EDASinkName as t };
|
|
39
|
-
//# sourceMappingURL=sink-checkpoint-store-
|
|
39
|
+
//# sourceMappingURL=sink-checkpoint-store-BHb8YRTw.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SequenceNumber } from "./types/core.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { foldReducedState, initialReducedState } from "./domain/reduced-state.js";
|
|
3
|
+
import { a as EDASessionStoreError, i as EDASessionStore, u as selectCommittedEvent } from "./session-store-DcJjs4Fd.js";
|
|
4
4
|
import { n as SessionContext, t as EventFactory } from "./event-factory-VAci3NJb.js";
|
|
5
5
|
import { IdGenerator } from "./services/id-generator.js";
|
|
6
6
|
import { annotateEdaSpan } from "./services/tracing.js";
|
|
@@ -342,4 +342,4 @@ const matchesInterest = (event, interests) => interests === void 0 || interests
|
|
|
342
342
|
//#endregion
|
|
343
343
|
export { EDASinkRegistry as n, EDASink as t };
|
|
344
344
|
|
|
345
|
-
//# sourceMappingURL=sink-registry-
|
|
345
|
+
//# sourceMappingURL=sink-registry-DEneTH8u.js.map
|