effect-durable-agent 0.1.0-alpha.1 → 0.1.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -1
- package/README.md +131 -128
- package/SECURITY.md +3 -4
- package/dist/{command-queues-CQ9cwRP7.d.ts → command-queues-CV7O-51r.d.ts} +7 -6
- package/dist/{compaction-YayFKo_1.d.ts → compaction-zbvLREI8.d.ts} +8 -6
- package/dist/context-projection-n6Rdup0N.d.ts +140 -0
- package/dist/{core-Hv3cFydL.d.ts → core-CYT6DBaS.d.ts} +2 -2
- package/dist/domain/command-queues.d.ts +1 -1
- package/dist/domain/context-projection.d.ts +2 -0
- package/dist/domain/context-projection.js +32 -0
- package/dist/domain/context-projection.js.map +1 -0
- package/dist/domain/message-transcript.d.ts +1 -1
- package/dist/domain/reduced-state-schema.d.ts +2 -0
- package/dist/domain/reduced-state-schema.js +2 -1
- package/dist/domain/reduced-state-schema.js.map +1 -1
- package/dist/domain/reduced-state.d.ts +1 -1
- package/dist/domain/reduced-state.js +1 -1
- package/dist/{durable-DlScwmCy.d.ts → durable-B7M6TD_0.d.ts} +341 -2
- package/dist/{durable-C3Rz7kg3.js → durable-DsV9PxZC.js} +13 -2
- package/dist/durable-DsV9PxZC.js.map +1 -0
- package/dist/{keep-alive-DYDsH6qN.d.ts → event-factory-CLJcyymV.d.ts} +5 -29
- package/dist/{keep-alive-p8dIcSVy.js → event-factory-tcpLgdMN.js} +3 -10
- package/dist/event-factory-tcpLgdMN.js.map +1 -0
- package/dist/host/websocket-protocol.d.ts +229 -0
- package/dist/host/websocket-protocol.js +99 -0
- package/dist/host/websocket-protocol.js.map +1 -0
- package/dist/host/websocket-wire.d.ts +2 -2
- package/dist/host/websocket-wire.js +37 -20
- package/dist/host/websocket-wire.js.map +1 -1
- package/dist/{id-generator-C2Q15uZM.d.ts → id-generator-Ckl8_XWW.d.ts} +2 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/keep-alive-Chl5SJxy.d.ts +29 -0
- package/dist/{message-transcript-BCHdHAe2.d.ts → message-transcript-DiOPBY3l.d.ts} +3 -3
- package/dist/{prompt-projector-9_02lk5-.d.ts → prompt-projector-C1IbkHr0.d.ts} +15 -16
- package/dist/{reduced-state-C4nVVzz9.js → reduced-state-TMi7ISla.js} +20 -4
- package/dist/reduced-state-TMi7ISla.js.map +1 -0
- package/dist/{reducer-registry-C0svUa63.d.ts → reducer-registry-CjSJBPKo.d.ts} +2 -2
- package/dist/{runtime-C56FQxiL.d.ts → runtime-DOgmAKsO.d.ts} +7 -6
- package/dist/services/compaction.d.ts +1 -1
- package/dist/services/compaction.js +4 -3
- package/dist/services/compaction.js.map +1 -1
- package/dist/services/id-generator.d.ts +1 -1
- package/dist/services/keep-alive.d.ts +2 -0
- package/dist/services/keep-alive.js +13 -0
- package/dist/services/keep-alive.js.map +1 -0
- package/dist/services/prompt-projector.d.ts +2 -2
- package/dist/services/prompt-projector.js +20 -10
- package/dist/services/prompt-projector.js.map +1 -1
- package/dist/services/reducer-registry.d.ts +1 -1
- package/dist/services/runtime-layer.d.ts +58 -0
- package/dist/services/runtime-layer.js +42 -0
- package/dist/services/runtime-layer.js.map +1 -0
- package/dist/services/runtime.d.ts +1 -1
- package/dist/services/runtime.js +4 -3
- package/dist/services/runtime.js.map +1 -1
- package/dist/services/session-query.d.ts +1 -1
- package/dist/services/session-query.js +76 -1
- package/dist/services/session-query.js.map +1 -0
- package/dist/services/session-state.d.ts +2 -0
- package/dist/services/session-state.js +2 -0
- package/dist/services/session-store.d.ts +2 -2
- package/dist/services/session-store.js +181 -2
- package/dist/services/session-store.js.map +1 -0
- package/dist/services/sink-checkpoint-store.d.ts +2 -0
- package/dist/services/sink-checkpoint-store.js +49 -0
- package/dist/services/sink-checkpoint-store.js.map +1 -0
- 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/services/websocket-subscriber.d.ts +54 -0
- package/dist/services/websocket-subscriber.js +190 -0
- package/dist/services/websocket-subscriber.js.map +1 -0
- package/dist/session-query-C-C4m1eq.d.ts +38 -0
- package/dist/{session-query-DlRo5Ufc.d.ts → session-state-CjOSvWbe.d.ts} +132 -40
- package/dist/{session-query-DOc1KanA.js → session-state-SStf0KUo.js} +43 -146
- package/dist/session-state-SStf0KUo.js.map +1 -0
- package/dist/{session-store-D2Ore1QC.d.ts → session-store-DZZUffUy.d.ts} +5 -94
- package/dist/sink-checkpoint-store-BZmQFTRE.d.ts +40 -0
- package/dist/{sink-registry-CIU0LD3m.d.ts → sink-registry-Cf79ICdW.d.ts} +11 -40
- package/dist/{sink-registry-CFC6xjsN.js → sink-registry-D13eUO_c.js} +9 -47
- package/dist/sink-registry-D13eUO_c.js.map +1 -0
- package/dist/testkit/layers.d.ts +14 -11
- package/dist/testkit/layers.js +8 -5
- package/dist/testkit/layers.js.map +1 -1
- package/dist/{tool-registry-CcnkAAQK.d.ts → tool-registry-B7Wona6N.d.ts} +3 -3
- package/dist/types/core.d.ts +1 -1
- package/dist/types/core.js +1 -1
- package/dist/types/core.js.map +1 -1
- package/dist/types/events/durable.d.ts +2 -2
- package/dist/types/events/durable.js +2 -2
- package/dist/types/events.d.ts +2 -2
- package/dist/types/events.js +2 -2
- package/dist/websocket-wire-QD2SquQE.d.ts +2244 -0
- package/docs/assets/architecture.svg +170 -60
- package/docs/assets/event-sequence.svg +68 -78
- package/docs/assets/hero.svg +33 -0
- package/docs/message-steering.md +1 -1
- package/docs/releasing.md +96 -39
- package/docs/spec.md +15 -12
- package/docs/websocket-protocol.md +35 -9
- package/package.json +55 -35
- package/dist/durable-C3Rz7kg3.js.map +0 -1
- package/dist/durable-object-runtime-B7jwBY2R.js +0 -1494
- package/dist/durable-object-runtime-B7jwBY2R.js.map +0 -1
- package/dist/durable-object-runtime-pWv0ohlz.d.ts +0 -257
- package/dist/durable-object-storage-Czy7IPrh.d.ts +0 -41
- package/dist/host/durable-object-runtime.d.ts +0 -2
- package/dist/host/durable-object-runtime.js +0 -2
- package/dist/host/durable-object-storage.d.ts +0 -2
- package/dist/host/durable-object-storage.js +0 -0
- package/dist/host/durable-object.d.ts +0 -83
- package/dist/host/durable-object.js +0 -191
- package/dist/host/durable-object.js.map +0 -1
- package/dist/keep-alive-p8dIcSVy.js.map +0 -1
- package/dist/reduced-state-C4nVVzz9.js.map +0 -1
- package/dist/session-query-DOc1KanA.js.map +0 -1
- package/dist/session-store-pYxQW9qh.js +0 -214
- package/dist/session-store-pYxQW9qh.js.map +0 -1
- package/dist/sink-registry-CFC6xjsN.js.map +0 -1
- package/dist/websocket-wire-DvOu_6BJ.d.ts +0 -16773
- package/examples/001-no-tools/README.md +0 -65
- package/examples/001-no-tools/worker.ts +0 -79
- package/examples/002-slack-bridge/README.md +0 -134
- package/examples/002-slack-bridge/events.ts +0 -115
- package/examples/002-slack-bridge/reducer.ts +0 -216
- package/examples/002-slack-bridge/scenario.test.ts +0 -223
- package/examples/002-slack-bridge/sinks.ts +0 -109
- package/examples/002-slack-bridge/worker.ts +0 -140
- package/examples/003-sandbox-lifecycle/README.md +0 -78
- package/examples/003-sandbox-lifecycle/events.ts +0 -203
- package/examples/003-sandbox-lifecycle/reducer.ts +0 -305
- package/examples/003-sandbox-lifecycle/scenario.test.ts +0 -202
- package/examples/_shared/event-id.ts +0 -12
- package/examples/_shared/http.ts +0 -27
- package/examples/_shared/openai.ts +0 -33
|
@@ -1,2 +1,77 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { mr as PositionedEvent } from "../durable-DsV9PxZC.js";
|
|
2
|
+
import { u as SessionState } from "../session-state-SStf0KUo.js";
|
|
3
|
+
import { EDASessionStore } from "./session-store.js";
|
|
4
|
+
import { durableMessageTranscript } from "../domain/message-transcript.js";
|
|
5
|
+
import { annotateEdaSpan } from "./tracing.js";
|
|
6
|
+
import { r as LiveEventBus } from "../sink-registry-D13eUO_c.js";
|
|
7
|
+
import * as Context from "effect/Context";
|
|
8
|
+
import * as Effect from "effect/Effect";
|
|
9
|
+
import * as Layer from "effect/Layer";
|
|
10
|
+
import * as Stream from "effect/Stream";
|
|
11
|
+
import * as PubSub from "effect/PubSub";
|
|
12
|
+
//#region src/services/session-query.ts
|
|
13
|
+
/** Read-only session query facade backed by authoritative SessionState plus durable backfill. */
|
|
14
|
+
var EDASessionQuery = class EDASessionQuery extends Context.Service()("@effect-durable-agent/EDASessionQuery") {
|
|
15
|
+
static Live = Layer.effect(EDASessionQuery, Effect.gen(function* () {
|
|
16
|
+
const store = yield* EDASessionStore;
|
|
17
|
+
const liveBus = yield* LiveEventBus;
|
|
18
|
+
const sessionState = yield* SessionState;
|
|
19
|
+
const snapshot = Effect.gen(function* () {
|
|
20
|
+
const data = yield* sessionState.snapshotData();
|
|
21
|
+
return {
|
|
22
|
+
state: data.reduced,
|
|
23
|
+
reducerStates: data.reducerStates,
|
|
24
|
+
messages: durableMessageTranscript(data.reduced)
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
snapshot: () => snapshot,
|
|
29
|
+
messages: () => snapshot.pipe(Effect.map((snapshot) => snapshot.messages)),
|
|
30
|
+
eventsAfter: (afterSeq) => Effect.gen(function* () {
|
|
31
|
+
const live = yield* liveBus.subscribeQueue();
|
|
32
|
+
const replayHead = (yield* sessionState.snapshot()).lastSeq;
|
|
33
|
+
const replay = yield* store.eventsAfter(afterSeq).pipe(Stream.filter((entry) => entry.position.seq <= replayHead), Stream.map((entry) => PositionedEvent.make({
|
|
34
|
+
position: entry.position,
|
|
35
|
+
event: entry.event
|
|
36
|
+
})), Stream.runCollect, Effect.map((events) => Array.from(events)));
|
|
37
|
+
const activeTurnReplay = yield* liveBus.activeTurnReplay();
|
|
38
|
+
const pendingLive = (yield* PubSub.takeUpTo(live, Number.POSITIVE_INFINITY)).filter((event) => shouldEmitLiveEvent(event, replayHead));
|
|
39
|
+
const reconnectPrefix = Array.from(uniquePositionedEvents([
|
|
40
|
+
...replay,
|
|
41
|
+
...activeTurnReplay.events,
|
|
42
|
+
...pendingLive
|
|
43
|
+
])).sort(comparePositionedEvents);
|
|
44
|
+
yield* annotateEdaSpan({
|
|
45
|
+
"eda.seq.after": afterSeq,
|
|
46
|
+
"eda.seq.head": replayHead,
|
|
47
|
+
"eda.replay.events": replay.length,
|
|
48
|
+
"eda.live.active_turn_events": activeTurnReplay.events.length,
|
|
49
|
+
"eda.live.active_turn_overflowed": activeTurnReplay.overflowed,
|
|
50
|
+
"eda.live.buffered_events": pendingLive.length
|
|
51
|
+
});
|
|
52
|
+
const follow = Stream.fromEffectRepeat(PubSub.take(live)).pipe(Stream.filter((event) => shouldEmitLiveEvent(event, replayHead)));
|
|
53
|
+
return Stream.fromIterable(reconnectPrefix).pipe(Stream.concat(follow));
|
|
54
|
+
}).pipe(Effect.withSpan("agent.events.follow", { attributes: { "eda.seq.after": afterSeq } }))
|
|
55
|
+
};
|
|
56
|
+
}));
|
|
57
|
+
};
|
|
58
|
+
const shouldEmitLiveEvent = (event, replayHead) => event.event.durability === "ephemeral" || event.position.seq > replayHead;
|
|
59
|
+
const comparePositionedEvents = (left, right) => {
|
|
60
|
+
const seq = left.position.seq - right.position.seq;
|
|
61
|
+
return seq === 0 ? left.position.subSeq - right.position.subSeq : seq;
|
|
62
|
+
};
|
|
63
|
+
const uniquePositionedEvents = (events) => {
|
|
64
|
+
const seen = /* @__PURE__ */ new Set();
|
|
65
|
+
const output = [];
|
|
66
|
+
for (const event of events) {
|
|
67
|
+
const key = `${event.position.seq}:${event.position.subSeq}:${event.event.eventId}`;
|
|
68
|
+
if (seen.has(key)) continue;
|
|
69
|
+
seen.add(key);
|
|
70
|
+
output.push(event);
|
|
71
|
+
}
|
|
72
|
+
return output;
|
|
73
|
+
};
|
|
74
|
+
//#endregion
|
|
2
75
|
export { EDASessionQuery };
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=session-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-query.js","names":[],"sources":["../../src/services/session-query.ts"],"sourcesContent":["import * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as PubSub from \"effect/PubSub\";\nimport type * as Scope from \"effect/Scope\";\nimport * as Stream from \"effect/Stream\";\n\nimport { durableMessageTranscript } from \"../domain/message-transcript\";\nimport type { DurableTranscriptMessage } from \"../domain/message-transcript\";\nimport type { ReducedState } from \"../domain/reduced-state\";\nimport type { EDAReducerStateSnapshot } from \"./reducer-registry\";\nimport { SequenceNumber } from \"../types/core\";\nimport { PositionedEvent } from \"../types/events\";\nimport { EDASessionStore, EDASessionStoreError } from \"./session-store\";\nimport { LiveEventBus } from \"./live-event-bus\";\nimport { SessionState } from \"./session-state\";\nimport { annotateEdaSpan } from \"./tracing\";\n\n/** Authoritative live snapshot for one EDA session plus its derived durable transcript. */\nexport interface EDASessionSnapshot {\n readonly state: ReducedState;\n readonly reducerStates: EDAReducerStateSnapshot;\n readonly messages: ReadonlyArray<DurableTranscriptMessage>;\n}\n\n/** Read-only query facade over authoritative live state and reconnect-safe event streams. */\nexport interface EDASessionQueryShape {\n /** Read the authoritative live state and derive its durable transcript. */\n readonly snapshot: () => Effect.Effect<EDASessionSnapshot, EDASessionStoreError>;\n /** Read durable user/assistant messages in committed sequence order from the live snapshot. */\n readonly messages: () => Effect.Effect<\n ReadonlyArray<DurableTranscriptMessage>,\n EDASessionStoreError\n >;\n /** Backfill durable events after `afterSeq`, then follow live durable/ephemeral events. */\n readonly eventsAfter: (\n afterSeq: SequenceNumber,\n ) => Effect.Effect<\n Stream.Stream<PositionedEvent, EDASessionStoreError>,\n EDASessionStoreError,\n Scope.Scope\n >;\n}\n\n/** Read-only session query facade backed by authoritative SessionState plus durable backfill. */\nexport class EDASessionQuery extends Context.Service<EDASessionQuery, EDASessionQueryShape>()(\n \"@effect-durable-agent/EDASessionQuery\",\n) {\n static readonly Live = Layer.effect(\n EDASessionQuery,\n Effect.gen(function* () {\n const store = yield* EDASessionStore;\n const liveBus = yield* LiveEventBus;\n const sessionState = yield* SessionState;\n\n const snapshot = Effect.gen(function* () {\n const data = yield* sessionState.snapshotData();\n return {\n state: data.reduced,\n reducerStates: data.reducerStates,\n messages: durableMessageTranscript(data.reduced),\n } satisfies EDASessionSnapshot;\n });\n\n return {\n snapshot: () => snapshot,\n messages: () => snapshot.pipe(Effect.map((snapshot) => snapshot.messages)),\n eventsAfter: (afterSeq: SequenceNumber) =>\n Effect.gen(function* () {\n const live = yield* liveBus.subscribeQueue();\n const replayHead = (yield* sessionState.snapshot()).lastSeq;\n // TODO(backpressure): this runCollect drains the store stream eagerly and buffers the\n // whole durable reconnect prefix, defeating host-level paged replay/backpressure for\n // slow clients. Stream this prefix into the live follow stream instead.\n const replay = yield* store.eventsAfter(afterSeq).pipe(\n Stream.filter((entry) => entry.position.seq <= replayHead),\n Stream.map((entry) =>\n PositionedEvent.make({ position: entry.position, event: entry.event }),\n ),\n Stream.runCollect,\n Effect.map((events) => Array.from(events)),\n );\n const activeTurnReplay = yield* liveBus.activeTurnReplay();\n const pendingLive = (yield* PubSub.takeUpTo(live, Number.POSITIVE_INFINITY)).filter(\n (event) => shouldEmitLiveEvent(event, replayHead),\n );\n const reconnectPrefix: ReadonlyArray<PositionedEvent> = Array.from(\n uniquePositionedEvents([...replay, ...activeTurnReplay.events, ...pendingLive]),\n ).sort(comparePositionedEvents);\n yield* annotateEdaSpan({\n \"eda.seq.after\": afterSeq,\n \"eda.seq.head\": replayHead,\n \"eda.replay.events\": replay.length,\n \"eda.live.active_turn_events\": activeTurnReplay.events.length,\n \"eda.live.active_turn_overflowed\": activeTurnReplay.overflowed,\n \"eda.live.buffered_events\": pendingLive.length,\n });\n const follow: Stream.Stream<PositionedEvent> = Stream.fromEffectRepeat(\n PubSub.take(live),\n ).pipe(Stream.filter((event) => shouldEmitLiveEvent(event, replayHead)));\n return Stream.fromIterable(reconnectPrefix).pipe(Stream.concat(follow));\n }).pipe(\n Effect.withSpan(\"agent.events.follow\", {\n attributes: { \"eda.seq.after\": afterSeq },\n }),\n ),\n };\n }),\n );\n}\n\nconst shouldEmitLiveEvent = (event: PositionedEvent, replayHead: SequenceNumber): boolean =>\n event.event.durability === \"ephemeral\" || event.position.seq > replayHead;\n\nconst comparePositionedEvents = (left: PositionedEvent, right: PositionedEvent): number => {\n const seq = left.position.seq - right.position.seq;\n return seq === 0 ? left.position.subSeq - right.position.subSeq : seq;\n};\n\nconst uniquePositionedEvents = (\n events: ReadonlyArray<PositionedEvent>,\n): ReadonlyArray<PositionedEvent> => {\n const seen = new Set<string>();\n const output: PositionedEvent[] = [];\n for (const event of events) {\n const key = `${event.position.seq}:${event.position.subSeq}:${event.event.eventId}`;\n if (seen.has(key)) {\n continue;\n }\n seen.add(key);\n output.push(event);\n }\n return output;\n};\n"],"mappings":";;;;;;;;;;;;;AA6CA,IAAa,kBAAb,MAAa,wBAAwB,QAAQ,QAA+C,EAC1F,uCACF,EAAE;CACA,OAAgB,OAAO,MAAM,OAC3B,iBACA,OAAO,IAAI,aAAa;EACtB,MAAM,QAAQ,OAAO;EACrB,MAAM,UAAU,OAAO;EACvB,MAAM,eAAe,OAAO;EAE5B,MAAM,WAAW,OAAO,IAAI,aAAa;GACvC,MAAM,OAAO,OAAO,aAAa,aAAa;GAC9C,OAAO;IACL,OAAO,KAAK;IACZ,eAAe,KAAK;IACpB,UAAU,yBAAyB,KAAK,OAAO;GACjD;EACF,CAAC;EAED,OAAO;GACL,gBAAgB;GAChB,gBAAgB,SAAS,KAAK,OAAO,KAAK,aAAa,SAAS,QAAQ,CAAC;GACzE,cAAc,aACZ,OAAO,IAAI,aAAa;IACtB,MAAM,OAAO,OAAO,QAAQ,eAAe;IAC3C,MAAM,cAAc,OAAO,aAAa,SAAS,GAAG;IAIpD,MAAM,SAAS,OAAO,MAAM,YAAY,QAAQ,EAAE,KAChD,OAAO,QAAQ,UAAU,MAAM,SAAS,OAAO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QAAQ;EAC1B,MAAM,MAAM,GAAG,MAAM,SAAS,IAAI,GAAG,MAAM,SAAS,OAAO,GAAG,MAAM,MAAM;EAC1E,IAAI,KAAK,IAAI,GAAG,GACd;EAEF,KAAK,IAAI,GAAG;EACZ,OAAO,KAAK,KAAK;CACnB;CACA,OAAO;AACT"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { _ as SessionStateShape, a as SessionCommandCompleted, c as SessionCommandResult, d as SessionForkedCommand, f as SessionNoRunnableCommand, g as SessionStateError, h as SessionState, i as SessionCommandCancelled, l as SessionDrainProcessed, m as SessionRunInput, n as SessionCommandAdmissionConflict, o as SessionCommandFailed, p as SessionNoRunnableReason, r as SessionCommandAdmissionError, s as SessionCommandOutcome, t as EDASubmittable, u as SessionDrainResult, v as SessionStateSnapshotData } from "../session-state-CjOSvWbe.js";
|
|
2
|
+
export { EDASubmittable, SessionCommandAdmissionConflict, SessionCommandAdmissionError, SessionCommandCancelled, SessionCommandCompleted, SessionCommandFailed, SessionCommandOutcome, SessionCommandResult, SessionDrainProcessed, SessionDrainResult, SessionForkedCommand, SessionNoRunnableCommand, SessionNoRunnableReason, SessionRunInput, SessionState, SessionStateError, SessionStateShape, SessionStateSnapshotData };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as SessionCommandOutcome, c as SessionNoRunnableReason, i as SessionCommandFailed, l as SessionRunInput, n as SessionCommandCancelled, o as SessionForkedCommand, r as SessionCommandCompleted, s as SessionNoRunnableCommand, t as SessionCommandAdmissionConflict, u as SessionState } from "../session-state-SStf0KUo.js";
|
|
2
|
+
export { SessionCommandAdmissionConflict, SessionCommandCancelled, SessionCommandCompleted, SessionCommandFailed, SessionCommandOutcome, SessionForkedCommand, SessionNoRunnableCommand, SessionNoRunnableReason, SessionRunInput, SessionState };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as EDASessionStore, c as FindCommandAdmissionInput,
|
|
2
|
-
export { CommittedDurableEvent, DurableAppendBatch, DurableAppendEntry, EDAReducerCheckpoint, EDASessionStore, EDASessionStoreError, EDASessionStoreShape, FindCommandAdmissionInput, SaveReducerCheckpointInput,
|
|
1
|
+
import { a as EDASessionStore, c as FindCommandAdmissionInput, i as EDAReducerCheckpoint, l as SaveReducerCheckpointInput, n as DurableAppendBatch, o as EDASessionStoreError, r as DurableAppendEntry, s as EDASessionStoreShape, t as CommittedDurableEvent, u as hasEDASessionStoreError } from "../session-store-DZZUffUy.js";
|
|
2
|
+
export { CommittedDurableEvent, DurableAppendBatch, DurableAppendEntry, EDAReducerCheckpoint, EDASessionStore, EDASessionStoreError, EDASessionStoreShape, FindCommandAdmissionInput, SaveReducerCheckpointInput, hasEDASessionStoreError };
|
|
@@ -1,2 +1,181 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { CommandId, DurablePosition, SequenceNumber, durablePosition } from "../types/core.js";
|
|
2
|
+
import { En as contextRebasedEventType, Un as summaryCreatedEventType, ar as DurableEventEnvelope, gn as commandAdmittedEventType } from "../durable-DsV9PxZC.js";
|
|
3
|
+
import { CompactionSummaryArtifact } from "../domain/context-projection.js";
|
|
4
|
+
import * as Context from "effect/Context";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Layer from "effect/Layer";
|
|
7
|
+
import * as Schema from "effect/Schema";
|
|
8
|
+
import * as Stream from "effect/Stream";
|
|
9
|
+
import * as Cause from "effect/Cause";
|
|
10
|
+
import * as Ref from "effect/Ref";
|
|
11
|
+
//#region src/services/session-store.ts
|
|
12
|
+
/** A durable event after the store has assigned its replay position. */
|
|
13
|
+
const CommittedDurableEvent = Schema.Struct({
|
|
14
|
+
position: DurablePosition,
|
|
15
|
+
event: DurableEventEnvelope
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* Store-level failure surfaced by durable append, replay, and hydration APIs.
|
|
19
|
+
*
|
|
20
|
+
* The error intentionally stays storage-semantic rather than SQL-specific so
|
|
21
|
+
* framework services can treat SQL-backed hosts, in-memory tests, and future adapters
|
|
22
|
+
* as the same durability boundary.
|
|
23
|
+
*/
|
|
24
|
+
var EDASessionStoreError = class extends Schema.TaggedErrorClass()("EDASessionStoreError", { message: Schema.String }) {};
|
|
25
|
+
/** True when a Cause contains an escaped durable-store failure. */
|
|
26
|
+
const hasEDASessionStoreError = (cause) => cause.reasons.some((reason) => Cause.isFailReason(reason) && reason.error instanceof EDASessionStoreError);
|
|
27
|
+
/**
|
|
28
|
+
* One logical event to persist in the durable session log.
|
|
29
|
+
*
|
|
30
|
+
* Store adapters may split large logical payload fields into sidecar rows after
|
|
31
|
+
* the event insert assigns `seq`, but callers still provide one fat event.
|
|
32
|
+
*/
|
|
33
|
+
const DurableAppendEntry = Schema.Struct({ event: DurableEventEnvelope });
|
|
34
|
+
/**
|
|
35
|
+
* Ordered durable append intent. Adapters assign positions in entry order.
|
|
36
|
+
*
|
|
37
|
+
* This is the single write shape exposed to framework services. It avoids raw
|
|
38
|
+
* SQL and public transaction callbacks while still expressing the full atomic
|
|
39
|
+
* transition EDA needs for events, normalized bodies, and metadata.
|
|
40
|
+
*/
|
|
41
|
+
const DurableAppendBatch = Schema.Struct({ entries: Schema.Array(DurableAppendEntry) });
|
|
42
|
+
/** Indexed command-admission lookup used for idempotent ingress. */
|
|
43
|
+
const FindCommandAdmissionInput = Schema.Struct({
|
|
44
|
+
commandId: Schema.optionalKey(CommandId),
|
|
45
|
+
idempotencyKey: Schema.optionalKey(Schema.String)
|
|
46
|
+
});
|
|
47
|
+
/**
|
|
48
|
+
* SQL-agnostic durable storage port for one EDA session.
|
|
49
|
+
*
|
|
50
|
+
* Framework services depend on this semantic port rather than raw SQL. Host
|
|
51
|
+
* adapters own physical tables and synchronous transaction mechanics; callers
|
|
52
|
+
* only express durable append/replay/lookup intent.
|
|
53
|
+
*/
|
|
54
|
+
var EDASessionStore = class EDASessionStore extends Context.Service()("@effect-durable-agent/EDASessionStore") {
|
|
55
|
+
/** Deterministic in-memory implementation used by runtime and recovery tests. */
|
|
56
|
+
static InMemory = (sessionId) => Layer.effect(EDASessionStore, Effect.gen(function* () {
|
|
57
|
+
return makeInMemoryStore(sessionId, yield* Ref.make(emptyInMemoryStoreData()));
|
|
58
|
+
}));
|
|
59
|
+
/** In-memory store seeded with a durable prefix; intended for recovery tests. */
|
|
60
|
+
static InMemorySeeded = (sessionId, events) => Layer.effect(EDASessionStore, Effect.gen(function* () {
|
|
61
|
+
const committed = seedCommittedEvents(sessionId, events);
|
|
62
|
+
return makeInMemoryStore(sessionId, yield* Ref.make({
|
|
63
|
+
...emptyInMemoryStoreData(),
|
|
64
|
+
committed,
|
|
65
|
+
summaries: summariesFromCommittedEvents(committed)
|
|
66
|
+
}));
|
|
67
|
+
}));
|
|
68
|
+
};
|
|
69
|
+
const emptyInMemoryStoreData = () => ({
|
|
70
|
+
committed: [],
|
|
71
|
+
summaries: /* @__PURE__ */ new Map(),
|
|
72
|
+
reducerCheckpoints: /* @__PURE__ */ new Map()
|
|
73
|
+
});
|
|
74
|
+
const seedCommittedEvents = (sessionId, events) => {
|
|
75
|
+
const seen = /* @__PURE__ */ new Set();
|
|
76
|
+
return events.map((event, index) => {
|
|
77
|
+
if (event.sessionId !== sessionId) throw new Error(`EDASessionStore.InMemorySeeded is scoped to session ${sessionId}; received ${event.sessionId}`);
|
|
78
|
+
if (seen.has(event.eventId)) throw new Error(`Duplicate seed eventId ${event.eventId}`);
|
|
79
|
+
seen.add(event.eventId);
|
|
80
|
+
return CommittedDurableEvent.make({
|
|
81
|
+
position: durablePosition(SequenceNumber.make(index + 1)),
|
|
82
|
+
event
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
const summariesFromCommittedEvents = (events) => {
|
|
87
|
+
const summaries = /* @__PURE__ */ new Map();
|
|
88
|
+
for (const { event } of events) {
|
|
89
|
+
if (event.type !== summaryCreatedEventType) continue;
|
|
90
|
+
const payload = event.payload;
|
|
91
|
+
if (payload.summary !== void 0) {
|
|
92
|
+
const summary = CompactionSummaryArtifact.make(payload.summary);
|
|
93
|
+
summaries.set(summary.summaryId, summary);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return summaries;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Build an in-memory store with one `Ref.modify` append critical section.
|
|
100
|
+
*
|
|
101
|
+
* The fake models the semantic atomicity of the production adapter without
|
|
102
|
+
* exposing SQL, so runtime tests exercise the same store contract.
|
|
103
|
+
*/
|
|
104
|
+
const makeInMemoryStore = (sessionId, data) => {
|
|
105
|
+
const ensureSession = (event) => Effect.gen(function* () {
|
|
106
|
+
if (event.sessionId === sessionId) return;
|
|
107
|
+
return yield* new EDASessionStoreError({ message: `EDASessionStore.InMemory is scoped to session ${sessionId}; received ${event.sessionId}` });
|
|
108
|
+
});
|
|
109
|
+
const append = (batch) => Effect.gen(function* () {
|
|
110
|
+
for (const entry of batch.entries) yield* ensureSession(entry.event);
|
|
111
|
+
return yield* Ref.modify(data, (current) => {
|
|
112
|
+
const nextEntries = [...current.committed];
|
|
113
|
+
const nextSummaries = new Map(current.summaries);
|
|
114
|
+
const committedEvents = [];
|
|
115
|
+
for (const entry of batch.entries) {
|
|
116
|
+
const { event } = entry;
|
|
117
|
+
const existing = nextEntries.find((entry) => entry.event.eventId === event.eventId);
|
|
118
|
+
if (existing !== void 0) {
|
|
119
|
+
committedEvents.push(existing);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const committed = CommittedDurableEvent.make({
|
|
123
|
+
position: durablePosition(SequenceNumber.make(nextEntries.length + 1)),
|
|
124
|
+
event
|
|
125
|
+
});
|
|
126
|
+
nextEntries.push(committed);
|
|
127
|
+
committedEvents.push(committed);
|
|
128
|
+
if (event.type === summaryCreatedEventType) {
|
|
129
|
+
const payload = event.payload;
|
|
130
|
+
if (payload.summary === void 0) throw new Error("SummaryCreated requires summary payload");
|
|
131
|
+
const summary = CompactionSummaryArtifact.make(payload.summary);
|
|
132
|
+
if (payload.summaryId !== void 0 && summary.summaryId !== payload.summaryId) throw new Error("SummaryCreated summaryId does not match summary payload");
|
|
133
|
+
nextSummaries.set(summary.summaryId, summary);
|
|
134
|
+
}
|
|
135
|
+
if (event.type === contextRebasedEventType) {
|
|
136
|
+
const payload = event.payload;
|
|
137
|
+
if (payload.summaryId === void 0 || !nextSummaries.has(payload.summaryId)) throw new Error(`ContextRebased references unknown summaryId ${String(payload.summaryId)}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return [committedEvents, {
|
|
141
|
+
committed: nextEntries,
|
|
142
|
+
summaries: nextSummaries,
|
|
143
|
+
reducerCheckpoints: current.reducerCheckpoints
|
|
144
|
+
}];
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
return {
|
|
148
|
+
append,
|
|
149
|
+
eventsAfter: (afterSeq) => Stream.fromIterableEffect(Ref.get(data).pipe(Effect.map(({ committed }) => committed.filter((entry) => entry.position.seq > afterSeq)))),
|
|
150
|
+
loadCommittedEventsBySeq: (seqs) => Ref.get(data).pipe(Effect.map(({ committed }) => {
|
|
151
|
+
const requested = new Set(seqs.map((seq) => Number(seq)));
|
|
152
|
+
return committed.filter((entry) => requested.has(Number(entry.position.seq)));
|
|
153
|
+
})),
|
|
154
|
+
findCommandAdmission: (input) => Ref.get(data).pipe(Effect.map(({ committed }) => committed.find((entry) => commandAdmissionMatches(entry, input)))),
|
|
155
|
+
loadSummaryArtifact: (summaryId) => Ref.get(data).pipe(Effect.map(({ summaries }) => summaries.get(summaryId))),
|
|
156
|
+
loadReducerCheckpoint: (name) => Ref.get(data).pipe(Effect.map(({ reducerCheckpoints }) => reducerCheckpoints.get(name))),
|
|
157
|
+
saveReducerCheckpoint: (checkpoint) => Ref.update(data, (current) => ({
|
|
158
|
+
...current,
|
|
159
|
+
reducerCheckpoints: new Map(current.reducerCheckpoints).set(checkpoint.name, checkpoint)
|
|
160
|
+
})),
|
|
161
|
+
saveReducerCheckpoints: (checkpoints) => Ref.update(data, (current) => {
|
|
162
|
+
const reducerCheckpoints = new Map(current.reducerCheckpoints);
|
|
163
|
+
for (const checkpoint of checkpoints) reducerCheckpoints.set(checkpoint.name, checkpoint);
|
|
164
|
+
return {
|
|
165
|
+
...current,
|
|
166
|
+
reducerCheckpoints
|
|
167
|
+
};
|
|
168
|
+
})
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
const commandAdmissionMatches = (entry, input) => {
|
|
172
|
+
if (entry.event.type !== commandAdmittedEventType) return false;
|
|
173
|
+
const admitted = entry.event.payload.command;
|
|
174
|
+
if (admitted === void 0) return false;
|
|
175
|
+
if (input.idempotencyKey !== void 0 && admitted.idempotencyKey === input.idempotencyKey) return true;
|
|
176
|
+
return input.commandId !== void 0 && admitted.commandId === input.commandId;
|
|
177
|
+
};
|
|
178
|
+
//#endregion
|
|
179
|
+
export { CommittedDurableEvent, DurableAppendBatch, DurableAppendEntry, EDASessionStore, EDASessionStoreError, FindCommandAdmissionInput, hasEDASessionStoreError };
|
|
180
|
+
|
|
181
|
+
//# sourceMappingURL=session-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-store.js","names":[],"sources":["../../src/services/session-store.ts"],"sourcesContent":["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 Schema from \"effect/Schema\";\nimport * as Stream from \"effect/Stream\";\n\nimport { type CommandIdempotencyKey, type EDACommand } 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\";\n\n/** A durable event after the store has assigned its replay position. */\nexport const CommittedDurableEvent = Schema.Struct({\n position: DurablePosition,\n event: DurableEventEnvelope,\n});\nexport type CommittedDurableEvent = typeof CommittedDurableEvent.Type;\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.TaggedErrorClass<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 /** Deterministic in-memory implementation used by runtime and recovery tests. */\n static readonly InMemory = (sessionId: SessionId) =>\n Layer.effect(\n EDASessionStore,\n Effect.gen(function* () {\n const data = yield* Ref.make<InMemoryStoreData>(emptyInMemoryStoreData());\n return makeInMemoryStore(sessionId, data);\n }),\n );\n\n /** In-memory store seeded with a durable prefix; intended for recovery tests. */\n static readonly InMemorySeeded = (\n sessionId: SessionId,\n events: ReadonlyArray<DurableEventEnvelope>,\n ) =>\n Layer.effect(\n EDASessionStore,\n Effect.gen(function* () {\n const committed = seedCommittedEvents(sessionId, events);\n const data = yield* Ref.make<InMemoryStoreData>({\n ...emptyInMemoryStoreData(),\n committed,\n summaries: summariesFromCommittedEvents(committed),\n });\n return makeInMemoryStore(sessionId, 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}\n\nconst emptyInMemoryStoreData = (): InMemoryStoreData => ({\n committed: [],\n summaries: new Map(),\n reducerCheckpoints: new Map(),\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 CommittedDurableEvent.make({\n position: durablePosition(SequenceNumber.make(index + 1)),\n 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 as { readonly summary?: unknown };\n if (payload.summary !== undefined) {\n const summary = CompactionSummaryArtifact.make(payload.summary as never);\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\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.make({\n position: durablePosition(SequenceNumber.make(nextEntries.length + 1)),\n event,\n });\n nextEntries.push(committed);\n committedEvents.push(committed);\n\n if (event.type === summaryCreatedEventType) {\n const payload = event.payload as {\n readonly summary?: unknown;\n readonly summaryId?: CompactionSummaryArtifact[\"summaryId\"];\n };\n if (payload.summary === undefined) {\n throw new Error(\"SummaryCreated requires summary payload\");\n }\n const summary = CompactionSummaryArtifact.make(payload.summary as never);\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 (event.type === contextRebasedEventType) {\n const payload = event.payload as { readonly summaryId?: SummaryId };\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 },\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\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 as { readonly command?: EDACommand }).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"],"mappings":";;;;;;;;;;;;AA0BA,MAAa,wBAAwB,OAAO,OAAO;CACjD,UAAU;CACV,OAAO;AACT,CAAC;;;;;;;;AAUD,IAAa,uBAAb,cAA0C,OAAO,iBAAuC,EACtF,wBACA,EACE,SAAS,OAAO,OAClB,CACF,EAAE,CAAC;;AAGH,MAAa,2BAA2B,UACtC,MAAM,QAAQ,MACX,WAAW,MAAM,aAAa,MAAM,KAAK,OAAO,iBAAiB,oBACpE;;;;;;;AAQF,MAAa,qBAAqB,OAAO,OAAO,EAC9C,OAAO,qBACT,CAAC;;;;;;;;AAUD,MAAa,qBAAqB,OAAO,OAAO,EAC9C,SAAS,OAAO,MAAM,kBAAkB,EAC1C,CAAC;;AAsBD,MAAa,4BAA4B,OAAO,OAAO;CACrD,WAAW,OAAO,YAAY,SAAS;CACvC,gBAAgB,OAAO,YAAY,OAAO,MAAM;AAClD,CAAC;;;;;;;;AAwDD,IAAa,kBAAb,MAAa,wBAAwB,QAAQ,QAA+C,EAC1F,uCACF,EAAE;;CAEA,OAAgB,YAAY,cAC1B,MAAM,OACJ,iBACA,OAAO,IAAI,aAAa;EAEtB,OAAO,kBAAkB,WAAW,OADhB,IAAI,KAAwB,uBAAuB,CAAC,CAChC;CAC1C,CAAC,CACH;;CAGF,OAAgB,kBACd,WACA,WAEA,MAAM,OACJ,iBACA,OAAO,IAAI,aAAa;EACtB,MAAM,YAAY,oBAAoB,WAAW,MAAM;EAMvD,OAAO,kBAAkB,WAAW,OALh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KAAA,KAAa,SAAS,cAAc,MAAM;AACvE"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { SequenceNumber } from "../types/core.js";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Layer from "effect/Layer";
|
|
5
|
+
import * as Schema from "effect/Schema";
|
|
6
|
+
import * as Ref from "effect/Ref";
|
|
7
|
+
//#region src/services/sink-checkpoint-store.ts
|
|
8
|
+
/** Stable sink name used as the durable checkpoint key. */
|
|
9
|
+
const EDASinkName = Schema.NonEmptyString.pipe(Schema.brand("EDASinkName"));
|
|
10
|
+
/**
|
|
11
|
+
* Semantic checkpoint store for registered EDA sinks.
|
|
12
|
+
*
|
|
13
|
+
* Checkpoints are intentionally exposed as load/save/commit operations rather
|
|
14
|
+
* than SQL. Sink side effects happen outside event append transactions, and the
|
|
15
|
+
* cursor advances only after the sink finishes its own external work.
|
|
16
|
+
*/
|
|
17
|
+
var SinkCheckpointStore = class SinkCheckpointStore extends Context.Service()("@effect-durable-agent/SinkCheckpointStore") {
|
|
18
|
+
/** In-memory checkpoint implementation for store/runtime tests. */
|
|
19
|
+
static InMemory = Layer.effect(SinkCheckpointStore, Effect.gen(function* () {
|
|
20
|
+
return makeInMemorySinkCheckpointStore(yield* Ref.make(/* @__PURE__ */ new Map()));
|
|
21
|
+
}));
|
|
22
|
+
};
|
|
23
|
+
/** Build a ref-backed checkpoint map with the same public semantics as host adapters. */
|
|
24
|
+
const makeInMemorySinkCheckpointStore = (checkpoints) => ({
|
|
25
|
+
load: (sinkName) => Ref.get(checkpoints).pipe(Effect.map((map) => map.get(sinkName) ?? {
|
|
26
|
+
afterSeq: SequenceNumber.make(0),
|
|
27
|
+
payload: void 0
|
|
28
|
+
})),
|
|
29
|
+
saveState: (sinkName, payload) => Ref.update(checkpoints, (map) => {
|
|
30
|
+
const next = new Map(map);
|
|
31
|
+
next.set(sinkName, {
|
|
32
|
+
afterSeq: map.get(sinkName)?.afterSeq ?? SequenceNumber.make(0),
|
|
33
|
+
payload
|
|
34
|
+
});
|
|
35
|
+
return next;
|
|
36
|
+
}),
|
|
37
|
+
commit: (sinkName, afterSeq, payload) => Ref.update(checkpoints, (map) => {
|
|
38
|
+
const next = new Map(map);
|
|
39
|
+
next.set(sinkName, {
|
|
40
|
+
afterSeq,
|
|
41
|
+
payload
|
|
42
|
+
});
|
|
43
|
+
return next;
|
|
44
|
+
})
|
|
45
|
+
});
|
|
46
|
+
//#endregion
|
|
47
|
+
export { EDASinkName, SinkCheckpointStore };
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=sink-checkpoint-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sink-checkpoint-store.js","names":[],"sources":["../../src/services/sink-checkpoint-store.ts"],"sourcesContent":["import * 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 Schema from \"effect/Schema\";\n\nimport { SequenceNumber } from \"../types/core\";\nimport { EDASessionStoreError } from \"./session-store\";\n\n/** Stable sink name used as the durable checkpoint key. */\nexport const EDASinkName = Schema.NonEmptyString.pipe(Schema.brand(\"EDASinkName\"));\nexport type EDASinkName = typeof EDASinkName.Type;\n\n/** Persisted cursor and sink-owned payload for one registered sink. */\nexport interface StoredSinkCheckpoint {\n readonly afterSeq: SequenceNumber;\n readonly payload: unknown | undefined;\n}\n\n/** Durable checkpoint persistence port for at-least-once sink runners. */\nexport interface SinkCheckpointStoreShape {\n /** Read the latest committed cursor and sink-owned payload. */\n readonly load: (\n sinkName: EDASinkName,\n ) => Effect.Effect<StoredSinkCheckpoint, EDASessionStoreError>;\n /** Save sink-owned state without advancing the durable cursor. */\n readonly saveState: (\n sinkName: EDASinkName,\n payload: unknown,\n ) => Effect.Effect<void, EDASessionStoreError>;\n /** Atomically commit the processed cursor together with current sink-owned state. */\n readonly commit: (\n sinkName: EDASinkName,\n afterSeq: SequenceNumber,\n payload: unknown | undefined,\n ) => Effect.Effect<void, EDASessionStoreError>;\n}\n\n/**\n * Semantic checkpoint store for registered EDA sinks.\n *\n * Checkpoints are intentionally exposed as load/save/commit operations rather\n * than SQL. Sink side effects happen outside event append transactions, and the\n * cursor advances only after the sink finishes its own external work.\n */\nexport class SinkCheckpointStore extends Context.Service<\n SinkCheckpointStore,\n SinkCheckpointStoreShape\n>()(\"@effect-durable-agent/SinkCheckpointStore\") {\n /** In-memory checkpoint implementation for store/runtime tests. */\n static readonly InMemory = Layer.effect(\n SinkCheckpointStore,\n Effect.gen(function* () {\n const checkpoints = yield* Ref.make<ReadonlyMap<EDASinkName, StoredSinkCheckpoint>>(\n new Map(),\n );\n return makeInMemorySinkCheckpointStore(checkpoints);\n }),\n );\n}\n\n/** Build a ref-backed checkpoint map with the same public semantics as host adapters. */\nconst makeInMemorySinkCheckpointStore = (\n checkpoints: Ref.Ref<ReadonlyMap<EDASinkName, StoredSinkCheckpoint>>,\n): SinkCheckpointStoreShape => ({\n load: (sinkName) =>\n Ref.get(checkpoints).pipe(\n Effect.map(\n (map) =>\n map.get(sinkName) ?? {\n afterSeq: SequenceNumber.make(0),\n payload: undefined,\n },\n ),\n ),\n saveState: (sinkName, payload) =>\n Ref.update(checkpoints, (map) => {\n const next = new Map(map);\n next.set(sinkName, {\n afterSeq: map.get(sinkName)?.afterSeq ?? SequenceNumber.make(0),\n payload,\n });\n return next;\n }),\n commit: (sinkName, afterSeq, payload) =>\n Ref.update(checkpoints, (map) => {\n const next = new Map(map);\n next.set(sinkName, { afterSeq, payload });\n return next;\n }),\n});\n"],"mappings":";;;;;;;;AAUA,MAAa,cAAc,OAAO,eAAe,KAAK,OAAO,MAAM,aAAa,CAAC;;;;;;;;AAmCjF,IAAa,sBAAb,MAAa,4BAA4B,QAAQ,QAG/C,EAAE,2CAA2C,EAAE;;CAE/C,OAAgB,WAAW,MAAM,OAC/B,qBACA,OAAO,IAAI,aAAa;EAItB,OAAO,gCAAgC,OAHZ,IAAI,qBAC7B,IAAI,IAAI,CACV,CACkD;CACpD,CAAC,CACH;AACF;;AAGA,MAAM,mCACJ,iBAC8B;CAC9B,OAAO,aACL,IAAI,IAAI,WAAW,EAAE,KACnB,OAAO,KACJ,QACC,IAAI,IAAI,QAAQ,KAAK;EACnB,UAAU,eAAe,KAAK,CAAC;EAC/B,SAAS,KAAA;CACX,CACJ,CACF;CACF,YAAY,UAAU,YACpB,IAAI,OAAO,cAAc,QAAQ;EAC/B,MAAM,OAAO,IAAI,IAAI,GAAG;EACxB,KAAK,IAAI,UAAU;GACjB,UAAU,IAAI,IAAI,QAAQ,GAAG,YAAY,eAAe,KAAK,CAAC;GAC9D;EACF,CAAC;EACD,OAAO;CACT,CAAC;CACH,SAAS,UAAU,UAAU,YAC3B,IAAI,OAAO,cAAc,QAAQ;EAC/B,MAAM,OAAO,IAAI,IAAI,GAAG;EACxB,KAAK,IAAI,UAAU;GAAE;GAAU;EAAQ,CAAC;EACxC,OAAO;CACT,CAAC;AACL"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as EDASinkContext, c as EDASinkRegistryShape, i as EDASinkCheckpoint, l as EDASinkRunnerStartInput, n as EDAEphemeralSinkDefinition, o as EDASinkDurableBatch, r as EDASink, s as EDASinkRegistry, t as EDADurableSinkDefinition } from "../sink-registry-
|
|
1
|
+
import { a as EDASinkContext, c as EDASinkRegistryShape, i as EDASinkCheckpoint, l as EDASinkRunnerStartInput, n as EDAEphemeralSinkDefinition, o as EDASinkDurableBatch, r as EDASink, s as EDASinkRegistry, t as EDADurableSinkDefinition } from "../sink-registry-Cf79ICdW.js";
|
|
2
2
|
export { EDADurableSinkDefinition, EDAEphemeralSinkDefinition, EDASink, EDASinkCheckpoint, EDASinkContext, EDASinkDurableBatch, EDASinkRegistry, EDASinkRegistryShape, EDASinkRunnerStartInput };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as EDASinkRegistry, t as EDASink } from "../sink-registry-
|
|
1
|
+
import { n as EDASinkRegistry, t as EDASink } from "../sink-registry-D13eUO_c.js";
|
|
2
2
|
export { EDASink, EDASinkRegistry };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as ToolParamsSchema, i as EDAToolRegistryShape, n as EDAToolExecutionContext, o as makeEDAToolkit, r as EDAToolRegistry, t as EDAModelToolkit } from "../tool-registry-
|
|
1
|
+
import { a as ToolParamsSchema, i as EDAToolRegistryShape, n as EDAToolExecutionContext, o as makeEDAToolkit, r as EDAToolRegistry, t as EDAModelToolkit } from "../tool-registry-B7Wona6N.js";
|
|
2
2
|
export { EDAModelToolkit, EDAToolExecutionContext, EDAToolRegistry, EDAToolRegistryShape, ToolParamsSchema, makeEDAToolkit };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { m as SequenceNumber } from "../core-CYT6DBaS.js";
|
|
2
|
+
import { o as EDASessionStoreError } from "../session-store-DZZUffUy.js";
|
|
3
|
+
import { r as EDARuntime } from "../runtime-DOgmAKsO.js";
|
|
4
|
+
import { EDAWebSocketClientFrame, EDAWebSocketFlowControl, EDAWebSocketServerFrame, SubscriberId } from "../host/websocket-protocol.js";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Schema from "effect/Schema";
|
|
7
|
+
import * as Queue from "effect/Queue";
|
|
8
|
+
import * as Scope from "effect/Scope";
|
|
9
|
+
import * as Deferred from "effect/Deferred";
|
|
10
|
+
|
|
11
|
+
//#region src/services/websocket-subscriber.d.ts
|
|
12
|
+
/** Slow subscriber reasons that intentionally close only the lagging socket. */
|
|
13
|
+
declare const SubscriberLagReason: Schema.Literals<readonly ["buffer-overflow", "ack-timeout"]>;
|
|
14
|
+
type SubscriberLagReason = typeof SubscriberLagReason.Type;
|
|
15
|
+
declare const SubscriberLagged_base: Schema.Class<SubscriberLagged, Schema.TaggedStruct<"SubscriberLagged", {
|
|
16
|
+
readonly subscriberId: Schema.brand<Schema.NonEmptyString, "SubscriberId">;
|
|
17
|
+
readonly lastAckedSeq: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
18
|
+
readonly reason: Schema.Literals<readonly ["buffer-overflow", "ack-timeout"]>;
|
|
19
|
+
}>, import("effect/Cause").YieldableError>;
|
|
20
|
+
/** The subscriber could not keep up with the bounded live-delivery policy. */
|
|
21
|
+
declare class SubscriberLagged extends SubscriberLagged_base {}
|
|
22
|
+
declare const SubscriberProtocolError_base: Schema.Class<SubscriberProtocolError, Schema.TaggedStruct<"SubscriberProtocolError", {
|
|
23
|
+
readonly subscriberId: Schema.brand<Schema.NonEmptyString, "SubscriberId">;
|
|
24
|
+
readonly message: Schema.String;
|
|
25
|
+
}>, import("effect/Cause").YieldableError>;
|
|
26
|
+
/** The client sent a malformed or impossible protocol frame. */
|
|
27
|
+
declare class SubscriberProtocolError extends SubscriberProtocolError_base {}
|
|
28
|
+
declare const SubscriberSendFailed_base: Schema.Class<SubscriberSendFailed, Schema.TaggedStruct<"SubscriberSendFailed", {
|
|
29
|
+
readonly subscriberId: Schema.brand<Schema.NonEmptyString, "SubscriberId">;
|
|
30
|
+
readonly cause: Schema.Defect;
|
|
31
|
+
}>, import("effect/Cause").YieldableError>;
|
|
32
|
+
/** The host WebSocket boundary failed while sending a frame. */
|
|
33
|
+
declare class SubscriberSendFailed extends SubscriberSendFailed_base {}
|
|
34
|
+
/** Expected error surface for one WebSocket subscriber workflow. */
|
|
35
|
+
type EDAWebSocketSubscriberError = SubscriberLagged | SubscriberProtocolError | SubscriberSendFailed | EDASessionStoreError;
|
|
36
|
+
/** Transport boundary implemented by a host WebSocket adapter or tests. */
|
|
37
|
+
interface EDAWebSocketSubscriberTransport {
|
|
38
|
+
readonly send: (frame: EDAWebSocketServerFrame) => Effect.Effect<void, SubscriberSendFailed>;
|
|
39
|
+
readonly incoming: Queue.Queue<EDAWebSocketClientFrame>;
|
|
40
|
+
readonly closed: Deferred.Deferred<void>;
|
|
41
|
+
readonly persistAck: (seq: SequenceNumber) => Effect.Effect<void>;
|
|
42
|
+
}
|
|
43
|
+
/** Configuration for one scoped ACK-window subscriber workflow. */
|
|
44
|
+
interface EDAWebSocketSubscriberInput {
|
|
45
|
+
readonly subscriberId: SubscriberId;
|
|
46
|
+
readonly resumeSeq: SequenceNumber;
|
|
47
|
+
readonly policy: EDAWebSocketFlowControl;
|
|
48
|
+
readonly transport: EDAWebSocketSubscriberTransport;
|
|
49
|
+
}
|
|
50
|
+
/** Run one scoped, ACK-gated live-event WebSocket subscriber. */
|
|
51
|
+
declare const runWebSocketSubscriber: (input: EDAWebSocketSubscriberInput) => Effect.Effect<void, EDAWebSocketSubscriberError, EDARuntime | Scope.Scope>;
|
|
52
|
+
//#endregion
|
|
53
|
+
export { EDAWebSocketSubscriberError, EDAWebSocketSubscriberInput, EDAWebSocketSubscriberTransport, SubscriberLagReason, SubscriberLagged, SubscriberProtocolError, SubscriberSendFailed, runWebSocketSubscriber };
|
|
54
|
+
//# sourceMappingURL=websocket-subscriber.d.ts.map
|