effect-durable-agent 0.1.0-alpha.10 → 0.1.0-alpha.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{command-queues-CQi4Xc7u.d.ts → command-queues-B45Xa1Dl.d.ts} +2 -2
- package/dist/{compaction-BhLSSXJ-.d.ts → compaction-CLCDOR1t.d.ts} +6 -6
- package/dist/{context-projection-mCuvcO2W.d.ts → context-projection-CCoN8m9W.d.ts} +2 -2
- package/dist/domain/command-queues.d.ts +1 -1
- package/dist/domain/context-projection.d.ts +1 -1
- package/dist/domain/message-transcript.d.ts +1 -1
- package/dist/domain/reduced-state.d.ts +1 -1
- package/dist/domain/run-scheduling.d.ts +1 -1
- package/dist/{event-factory-KaeDSfeP.d.ts → event-factory-EL4szNWm.d.ts} +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/{message-transcript-6PEzaEGn.d.ts → message-transcript-Dr6Rk-re.d.ts} +3 -3
- package/dist/{prompt-projector-CNhqUsEr.d.ts → prompt-projector-CGo1TGyZ.d.ts} +4 -4
- package/dist/{reducer-registry-CCSzc4h8.d.ts → reducer-registry-DqljrD58.d.ts} +4 -2
- package/dist/{run-scheduler-DcS_okUH.d.ts → run-scheduler-DvHWwWBJ.d.ts} +2 -2
- package/dist/{run-scheduling-wakeup-CeHrvXie.d.ts → run-scheduling-wakeup-CGgJ7RNe.d.ts} +2 -2
- package/dist/{runtime-WL_gKqxn.d.ts → runtime-j93ZOBnG.d.ts} +5 -5
- package/dist/services/compaction.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.map +1 -1
- package/dist/services/run-scheduler.d.ts +2 -2
- package/dist/services/run-scheduling-wakeup.d.ts +1 -1
- package/dist/services/runtime-layer.d.ts +11 -11
- package/dist/services/runtime-layer.js +2 -2
- package/dist/services/runtime.d.ts +1 -1
- package/dist/services/runtime.js +1 -1
- package/dist/services/session-query.d.ts +1 -1
- package/dist/services/session-query.js +2 -2
- package/dist/services/session-state.d.ts +1 -1
- package/dist/services/session-state.js +1 -1
- package/dist/services/session-store.d.ts +1 -1
- package/dist/services/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-query-DfW_4KC0.d.ts → session-query-DYuJXhMQ.d.ts} +8 -8
- package/dist/{session-state-BeR2rZRR.d.ts → session-state-13z-3YaF.d.ts} +14 -14
- package/dist/{session-state-BIZ2SYaP.js → session-state-xXXyniwU.js} +6 -6
- package/dist/{session-state-BIZ2SYaP.js.map → session-state-xXXyniwU.js.map} +1 -1
- package/dist/{session-store-J_Un45kW.d.ts → session-store-BIr-xfJ7.d.ts} +2 -2
- package/dist/{sink-checkpoint-store-C9hUxfH0.d.ts → sink-checkpoint-store-Cr9_GmOw.d.ts} +2 -2
- package/dist/{sink-registry-DuDkNXjZ.d.ts → sink-registry-C2t3DI_g.d.ts} +12 -8
- package/dist/{sink-registry-Bbqhtdnx.js → sink-registry-CUIrrkXU.js} +27 -23
- package/dist/sink-registry-CUIrrkXU.js.map +1 -0
- package/dist/testkit/layers.d.ts +13 -13
- package/dist/testkit/layers.js +2 -2
- package/dist/{tool-registry-BDmJe_Wr.d.ts → tool-registry-Dhs2KmYK.d.ts} +2 -2
- package/package.json +1 -1
- package/dist/sink-registry-Bbqhtdnx.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { g as SessionId, h as SequenceNumber, n as CommandId, v as SummaryId } from "./core-C-6xHzRx.js";
|
|
2
2
|
import { t as DurableEventEnvelope } from "./envelope-DkZyMIgp.js";
|
|
3
3
|
import { n as CommandIdempotencyKey } from "./commands-p8venTWs.js";
|
|
4
|
-
import { r as CompactionSummaryArtifact } from "./context-projection-
|
|
4
|
+
import { r as CompactionSummaryArtifact } from "./context-projection-CCoN8m9W.js";
|
|
5
5
|
import * as Context from "effect/Context";
|
|
6
6
|
import * as Effect from "effect/Effect";
|
|
7
7
|
import * as Layer from "effect/Layer";
|
|
@@ -203,4 +203,4 @@ declare class EDASessionStore extends EDASessionStore_base {
|
|
|
203
203
|
}
|
|
204
204
|
//#endregion
|
|
205
205
|
export { EDASessionStore as a, FindCommandAdmissionInput as c, EDAReducerCheckpoint as i, SaveReducerCheckpointInput as l, DurableAppendBatch as n, EDASessionStoreError as o, DurableAppendEntry as r, EDASessionStoreShape as s, CommittedDurableEvent as t, hasEDASessionStoreError as u };
|
|
206
|
-
//# sourceMappingURL=session-store-
|
|
206
|
+
//# sourceMappingURL=session-store-BIr-xfJ7.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { h as SequenceNumber } from "./core-C-6xHzRx.js";
|
|
2
|
-
import { o as EDASessionStoreError } from "./session-store-
|
|
2
|
+
import { o as EDASessionStoreError } from "./session-store-BIr-xfJ7.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";
|
|
@@ -37,4 +37,4 @@ declare class SinkCheckpointStore extends SinkCheckpointStore_base {
|
|
|
37
37
|
}
|
|
38
38
|
//#endregion
|
|
39
39
|
export { StoredSinkCheckpoint as i, SinkCheckpointStore as n, SinkCheckpointStoreShape as r, EDASinkName as t };
|
|
40
|
-
//# sourceMappingURL=sink-checkpoint-store-
|
|
40
|
+
//# sourceMappingURL=sink-checkpoint-store-Cr9_GmOw.d.ts.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { b as TurnId, c as EventId, g as SessionId, h as SequenceNumber } from "./core-C-6xHzRx.js";
|
|
2
|
-
import { S as ReducedState } from "./command-queues-
|
|
2
|
+
import { S as ReducedState } from "./command-queues-B45Xa1Dl.js";
|
|
3
3
|
import { d as PositionedEvent, n as EphemeralEventEnvelope, o as EventType, t as DurableEventEnvelope } from "./envelope-DkZyMIgp.js";
|
|
4
|
-
import { a as EDASessionStore, o as EDASessionStoreError, t as CommittedDurableEvent } from "./session-store-
|
|
4
|
+
import { a as EDASessionStore, o as EDASessionStoreError, t as CommittedDurableEvent } from "./session-store-BIr-xfJ7.js";
|
|
5
5
|
import { t as IdGenerator } from "./id-generator--x6itQZ2.js";
|
|
6
|
-
import { n as EventFactoryShape, r as SessionContext, t as EventFactory } from "./event-factory-
|
|
6
|
+
import { n as EventFactoryShape, r as SessionContext, t as EventFactory } from "./event-factory-EL4szNWm.js";
|
|
7
7
|
import { t as EDAKeepAlive } from "./keep-alive-Chl5SJxy.js";
|
|
8
8
|
import { t as SessionEventObserver } from "./session-event-observer-DaFMKKNc.js";
|
|
9
|
-
import { a as EDAReducerStateSnapshot, r as EDAReducerRegistry } from "./reducer-registry-
|
|
10
|
-
import { n as SinkCheckpointStore } from "./sink-checkpoint-store-
|
|
9
|
+
import { a as EDAReducerStateSnapshot, r as EDAReducerRegistry } from "./reducer-registry-DqljrD58.js";
|
|
10
|
+
import { n as SinkCheckpointStore } from "./sink-checkpoint-store-Cr9_GmOw.js";
|
|
11
11
|
import * as Context from "effect/Context";
|
|
12
12
|
import * as Effect from "effect/Effect";
|
|
13
13
|
import * as Layer from "effect/Layer";
|
|
@@ -108,7 +108,11 @@ declare const EDASink: {
|
|
|
108
108
|
/** Session-owned capabilities needed to start all registered sink runners. */
|
|
109
109
|
interface EDASinkRunnerStartInput {
|
|
110
110
|
readonly appendDurableBatch: (events: ReadonlyArray<DurableEventEnvelope>) => Effect.Effect<ReadonlyArray<CommittedDurableEvent>, EDASessionStoreError>;
|
|
111
|
-
|
|
111
|
+
/** Immutable framework and app projections at one common durable head. */
|
|
112
|
+
readonly initialProjection: {
|
|
113
|
+
readonly reduced: ReducedState;
|
|
114
|
+
readonly reducerStates: EDAReducerStateSnapshot;
|
|
115
|
+
};
|
|
112
116
|
readonly publishEphemeral: (event: EphemeralEventEnvelope) => Effect.Effect<PositionedEvent, EDASessionStoreError>;
|
|
113
117
|
readonly scope: Scope.Scope;
|
|
114
118
|
}
|
|
@@ -126,8 +130,8 @@ declare const EDASinkRegistry_base: Context.ServiceClass<EDASinkRegistry, "@effe
|
|
|
126
130
|
/** Registry and runner for app-provided EDA sinks. */
|
|
127
131
|
declare class EDASinkRegistry extends EDASinkRegistry_base {
|
|
128
132
|
static readonly Empty: Layer.Layer<EDASinkRegistry, never, never>;
|
|
129
|
-
static readonly Live: (sinks: ReadonlyArray<EDASink>) => Layer.Layer<EDASinkRegistry, never,
|
|
133
|
+
static readonly Live: (sinks: ReadonlyArray<EDASink>) => Layer.Layer<EDASinkRegistry, never, SinkCheckpointStore | EDASessionStore | LiveEventBus | EDAReducerRegistry | EventFactory | IdGenerator | EDAKeepAlive | SessionContext>;
|
|
130
134
|
}
|
|
131
135
|
//#endregion
|
|
132
136
|
export { EDASinkContext as a, EDASinkRegistryShape as c, EDASinkCheckpoint as i, EDASinkRunnerStartInput as l, EDAEphemeralSinkDefinition as n, EDASinkDurableBatch as o, EDASink as r, EDASinkRegistry as s, EDADurableSinkDefinition as t, LiveEventBus as u };
|
|
133
|
-
//# sourceMappingURL=sink-registry-
|
|
137
|
+
//# sourceMappingURL=sink-registry-C2t3DI_g.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SequenceNumber, durablePosition } from "./types/core.js";
|
|
2
2
|
import { dr as turnCompletedEventType, fr as turnFailedEventType, mr as turnStoppedEventType, pr as turnStartedEventType } from "./durable-BPHVFVvV.js";
|
|
3
|
-
import {
|
|
3
|
+
import { l as initialReducedState, o as foldReducedState } from "./reduced-state-Bz68V2H8.js";
|
|
4
4
|
import { CommittedDurableEvent, EDASessionStore, EDASessionStoreError } from "./services/session-store.js";
|
|
5
5
|
import { IdGenerator } from "./services/id-generator.js";
|
|
6
6
|
import { n as SessionContext, t as EventFactory } from "./event-factory-QuC_UvyP.js";
|
|
@@ -104,19 +104,29 @@ const makeSinkRegistry = (sinks) => Effect.gen(function* () {
|
|
|
104
104
|
stageDurable: (event) => Effect.sync(() => staged.push(event)),
|
|
105
105
|
forkScoped: (effect) => effect.pipe(Effect.forkIn(scope), Effect.asVoid)
|
|
106
106
|
});
|
|
107
|
-
const makeSinkRunner = (sink,
|
|
107
|
+
const makeSinkRunner = Effect.fnUntraced(function* (sink, { initialProjection, appendDurableBatch, publishEphemeral, scope }) {
|
|
108
|
+
const initialHead = initialProjection.reduced.lastSeq;
|
|
108
109
|
const sinkName = EDASinkName.make(sink.name);
|
|
109
110
|
const storedCheckpoint = yield* checkpointStore.load(sinkName);
|
|
110
111
|
const checkpointRef = yield* SynchronizedRef.make(storedCheckpoint);
|
|
111
112
|
const checkpoint = makeSinkCheckpoint(checkpointStore, sinkName, checkpointRef);
|
|
112
113
|
const cursor = storedCheckpoint.afterSeq;
|
|
113
|
-
const
|
|
114
|
-
const state = yield* Ref.make({
|
|
114
|
+
const initial = {
|
|
115
115
|
cursor,
|
|
116
|
-
reduced:
|
|
117
|
-
reducerStates: reducerRegistry.
|
|
118
|
-
}
|
|
119
|
-
const
|
|
116
|
+
reduced: initialReducedState,
|
|
117
|
+
reducerStates: reducerRegistry.initial
|
|
118
|
+
};
|
|
119
|
+
const hydrated = cursor === initialHead ? {
|
|
120
|
+
cursor,
|
|
121
|
+
reduced: initialProjection.reduced,
|
|
122
|
+
reducerStates: initialProjection.reducerStates
|
|
123
|
+
} : cursor <= SequenceNumber.make(0) ? initial : yield* store.eventsAfter(SequenceNumber.make(0)).pipe(Stream.takeWhile((event) => event.position.seq <= cursor), Stream.chunks, Stream.runFold(() => initial, (current, page) => ({
|
|
124
|
+
cursor,
|
|
125
|
+
reduced: foldReducedState(current.reduced, page),
|
|
126
|
+
reducerStates: reducerRegistry.reduce(current.reducerStates, page)
|
|
127
|
+
})));
|
|
128
|
+
const state = yield* Ref.make(hydrated);
|
|
129
|
+
const live = yield* liveBus.subscribeQueue().pipe(Scope.provide(scope));
|
|
120
130
|
const processDurableBatch = Effect.fnUntraced(function* (allEvents) {
|
|
121
131
|
if (allEvents.length === 0) return;
|
|
122
132
|
const current = yield* Ref.get(state);
|
|
@@ -135,12 +145,12 @@ const makeSinkRegistry = (sinks) => Effect.gen(function* () {
|
|
|
135
145
|
stateAfter: nextReduced,
|
|
136
146
|
reducerStates: nextReducerStates,
|
|
137
147
|
throughSeq
|
|
138
|
-
}, baseContext(staged,
|
|
148
|
+
}, baseContext(staged, publishEphemeral, scope, checkpoint)).pipe(Effect.as(true), Effect.catchCause((cause) => Cause.hasInterruptsOnly(cause) ? Effect.failCause(cause) : Effect.logError("EDA durable sink violated its infallible contract", {
|
|
139
149
|
cause: Cause.pretty(cause),
|
|
140
150
|
sink: sink.name
|
|
141
151
|
}).pipe(Effect.as(false))))) && staged.length > 0) {
|
|
142
152
|
yield* annotateEdaSpan({ "eda.sink.staged_events": staged.length });
|
|
143
|
-
yield*
|
|
153
|
+
yield* appendDurableBatch(staged);
|
|
144
154
|
}
|
|
145
155
|
}).pipe(Effect.withSpan("agent.sink.drain", { attributes: {
|
|
146
156
|
"eda.sink.name": sink.name,
|
|
@@ -188,39 +198,33 @@ const makeSinkRegistry = (sinks) => Effect.gen(function* () {
|
|
|
188
198
|
const after = yield* Ref.get(state);
|
|
189
199
|
if (event.position.seq !== after.cursor) return;
|
|
190
200
|
if (sink.ephemeral === void 0 || !matchesInterest(event.event.type, sink.ephemeral.interests)) return;
|
|
191
|
-
yield* sink.ephemeral.process(event, baseContext([],
|
|
201
|
+
yield* sink.ephemeral.process(event, baseContext([], publishEphemeral, scope, checkpoint)).pipe(Effect.catchCause((cause) => Effect.logError("EDA sink ephemeral projection failed", {
|
|
192
202
|
cause: String(cause),
|
|
193
203
|
sink: sink.name
|
|
194
204
|
})));
|
|
195
205
|
});
|
|
196
206
|
const processLiveEvent = (event) => event.event.durability === "durable" ? processLiveDurable(event) : processLiveEphemeral(event);
|
|
197
|
-
|
|
198
|
-
yield* drainDurablesThrough(
|
|
207
|
+
return Effect.gen(function* () {
|
|
208
|
+
yield* drainDurablesThrough(initialHead);
|
|
199
209
|
return yield* Effect.forever(Effect.gen(function* () {
|
|
200
210
|
yield* processLiveEvent(yield* PubSub.take(live));
|
|
201
211
|
}));
|
|
202
212
|
}).pipe(Effect.catchCause((cause) => Effect.logError("EDA sink runner failed", {
|
|
203
213
|
cause: Cause.pretty(cause),
|
|
204
214
|
sink: sink.name
|
|
205
|
-
})))
|
|
215
|
+
})));
|
|
206
216
|
});
|
|
207
217
|
return {
|
|
208
218
|
sinks,
|
|
209
219
|
startSinkRunners: Effect.fnUntraced(function* (input) {
|
|
210
220
|
if (yield* Ref.getAndSet(started, true)) return;
|
|
211
|
-
yield* Effect.forEach(sinks, (sink) => makeSinkRunner(sink, input), {
|
|
212
|
-
|
|
213
|
-
concurrency: "unbounded"
|
|
214
|
-
});
|
|
221
|
+
const runners = yield* Effect.forEach(sinks, (sink) => makeSinkRunner(sink, input), { concurrency: 1 });
|
|
222
|
+
yield* Effect.forEach(runners, (runner) => runner.pipe(Effect.forkIn(input.scope)), { discard: true });
|
|
215
223
|
}),
|
|
216
224
|
notifyDurableHeadAdvanced: () => Effect.void,
|
|
217
225
|
publishEphemeralToSinks: () => Effect.void
|
|
218
226
|
};
|
|
219
227
|
});
|
|
220
|
-
const readDurablePrefixThrough = (store, throughSeq) => {
|
|
221
|
-
if (throughSeq <= SequenceNumber.make(0)) return Effect.succeed([]);
|
|
222
|
-
return store.eventsAfter(SequenceNumber.make(0)).pipe(Stream.takeWhile((event) => event.position.seq <= throughSeq), Stream.runCollect, Effect.map((events) => Array.from(events)));
|
|
223
|
-
};
|
|
224
228
|
const makeSinkCheckpoint = (store, sinkName, checkpointRef) => ({
|
|
225
229
|
get: (schema, initial) => SynchronizedRef.get(checkpointRef).pipe(Effect.flatMap((checkpoint) => {
|
|
226
230
|
const serialized = serializedSinkState(checkpoint.payload);
|
|
@@ -269,4 +273,4 @@ const matchesInterest = (type, interests) => interests === void 0 || interests.s
|
|
|
269
273
|
//#endregion
|
|
270
274
|
export { EDASinkRegistry as n, LiveEventBus as r, EDASink as t };
|
|
271
275
|
|
|
272
|
-
//# sourceMappingURL=sink-registry-
|
|
276
|
+
//# sourceMappingURL=sink-registry-CUIrrkXU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sink-registry-CUIrrkXU.js","names":[],"sources":["../src/services/live-event-bus.ts","../src/services/sink-registry.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 * as Ref from \"effect/Ref\";\nimport type * as Scope from \"effect/Scope\";\nimport * as Stream from \"effect/Stream\";\n\nimport { TurnId } from \"../types/core\";\nimport {\n PositionedEvent,\n turnCompletedEventType,\n turnFailedEventType,\n turnStartedEventType,\n turnStoppedEventType,\n} from \"../types/events\";\nimport { SessionEventObserver, type SessionEventObserverShape } from \"./session-event-observer\";\n\n/** Conservative raw-delta cap for one open turn's live-only reconnect replay. */\nexport const activeTurnEphemeralReplayCapacity = 4_096;\n\n/** Live-only replay buffer for the currently open turn. */\nexport interface ActiveTurnEphemeralReplay {\n readonly turnId?: TurnId;\n readonly events: ReadonlyArray<PositionedEvent>;\n readonly overflowed: boolean;\n}\n\n/** In-memory live fanout plus active-turn replay source for reconnect streams. */\nexport interface LiveEventBusShape {\n readonly publish: (event: PositionedEvent) => Effect.Effect<boolean>;\n readonly subscribe: () => Effect.Effect<Stream.Stream<PositionedEvent>, never, Scope.Scope>;\n readonly subscribeQueue: () => Effect.Effect<\n PubSub.Subscription<PositionedEvent>,\n never,\n Scope.Scope\n >;\n /** Snapshot raw live-only events retained for the currently open turn. */\n readonly activeTurnReplay: () => Effect.Effect<ActiveTurnEphemeralReplay>;\n}\n\n/** Unbounded in-memory fanout plus bounded active-turn ephemeral replay. */\nexport class LiveEventBus extends Context.Service<LiveEventBus, LiveEventBusShape>()(\n \"@effect-durable-agent/LiveEventBus\",\n) {\n static readonly Live = Layer.effect(\n LiveEventBus,\n Effect.gen(function* () {\n const pubsub = yield* Effect.acquireRelease(\n PubSub.unbounded<PositionedEvent>(),\n PubSub.shutdown,\n );\n const activeTurnReplay = yield* Ref.make<ActiveTurnEphemeralReplay>({\n events: [],\n overflowed: false,\n });\n const observer = yield* SessionEventObserver;\n return makeLiveBus(pubsub, activeTurnReplay, observer);\n }),\n );\n\n /** Live bus for hosts that do not install an append-driven observer. */\n static readonly Noop = LiveEventBus.Live.pipe(Layer.provide(SessionEventObserver.Noop));\n}\n\nconst makeLiveBus = (\n pubsub: PubSub.PubSub<PositionedEvent>,\n activeTurnReplay: Ref.Ref<ActiveTurnEphemeralReplay>,\n observer: SessionEventObserverShape,\n): LiveEventBusShape => ({\n publish: (event) =>\n Effect.gen(function* () {\n yield* updateActiveTurnReplay(activeTurnReplay, event);\n yield* observer.onEvent(event);\n return yield* PubSub.publish(pubsub, event);\n }),\n subscribeQueue: () => PubSub.subscribe(pubsub),\n subscribe: () =>\n Effect.map(PubSub.subscribe(pubsub), (subscription) =>\n Stream.fromEffectRepeat(PubSub.take(subscription)),\n ),\n activeTurnReplay: () => Ref.get(activeTurnReplay),\n});\n\nconst updateActiveTurnReplay = (\n ref: Ref.Ref<ActiveTurnEphemeralReplay>,\n event: PositionedEvent,\n): Effect.Effect<void> => Ref.update(ref, (state) => nextActiveTurnReplay(state, event));\n\nconst nextActiveTurnReplay = (\n state: ActiveTurnEphemeralReplay,\n event: PositionedEvent,\n): ActiveTurnEphemeralReplay => {\n if (event.event.type === turnStartedEventType) {\n return {\n turnId: (event.event.payload as { readonly turnId: TurnId }).turnId,\n events: [],\n overflowed: false,\n };\n }\n\n if (\n event.event.type === turnCompletedEventType ||\n event.event.type === turnFailedEventType ||\n event.event.type === turnStoppedEventType\n ) {\n const turnId = (event.event.payload as { readonly turnId?: TurnId }).turnId;\n return turnId === undefined || state.turnId === undefined || turnId === state.turnId\n ? { events: [], overflowed: false }\n : state;\n }\n\n if (event.event.durability !== \"ephemeral\" || state.turnId === undefined) {\n return state;\n }\n\n const events = [...state.events, event];\n if (events.length <= activeTurnEphemeralReplayCapacity) {\n return { ...state, events };\n }\n return {\n ...state,\n events: events.slice(events.length - activeTurnEphemeralReplayCapacity),\n overflowed: true,\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 PubSub from \"effect/PubSub\";\nimport * as Ref from \"effect/Ref\";\nimport * as Schema from \"effect/Schema\";\nimport * as Scope from \"effect/Scope\";\nimport * as Stream from \"effect/Stream\";\nimport * as SynchronizedRef from \"effect/SynchronizedRef\";\n\nimport { foldReducedState, initialReducedState, type ReducedState } from \"../domain/reduced-state\";\nimport { EDAReducerRegistry, type EDAReducerStateSnapshot } from \"./reducer-registry\";\nimport { EventId, SessionId, SequenceNumber, durablePosition } from \"../types/core\";\nimport type {\n DurableEventEnvelope,\n EphemeralEventEnvelope,\n EventType,\n PositionedEvent,\n} from \"../types/events\";\nimport type { EDASessionStoreShape } from \"./session-store\";\nimport { CommittedDurableEvent, EDASessionStore, EDASessionStoreError } from \"./session-store\";\nimport { EventFactory } from \"./event-factory\";\nimport type { EventFactoryShape } from \"./event-factory\";\nimport { IdGenerator } from \"./id-generator\";\nimport { EDAKeepAlive } from \"./keep-alive\";\nimport { LiveEventBus } from \"./live-event-bus\";\nimport { SessionContext } from \"./session-context\";\nimport {\n EDASinkName,\n SinkCheckpointStore,\n type SinkCheckpointStoreShape,\n type StoredSinkCheckpoint,\n} from \"./sink-checkpoint-store\";\nimport { annotateEdaSpan } from \"./tracing\";\n\n/** Cursor-window input delivered to one durable sink drain. */\nexport interface EDASinkDurableBatch {\n /** All durable events replayed for this cursor window, including uninterested events. */\n readonly allEvents: ReadonlyArray<CommittedDurableEvent>;\n /** Events matching the sink's durable interests. */\n readonly events: ReadonlyArray<CommittedDurableEvent>;\n /** Authoritative reduced state folded exactly through `throughSeq`. */\n readonly stateAfter: ReducedState;\n /** App-specific durable reducer states folded exactly through `throughSeq`. */\n readonly reducerStates: EDAReducerStateSnapshot;\n /** Durable sequence through which the sink may advance after success. */\n readonly throughSeq: SequenceNumber;\n}\n\n/** Typed, sink-owned durable state stored independently from cursor advancement. */\nexport interface EDASinkCheckpoint {\n /** Decode current durable state, or return `initial` for a new or legacy cursor row. */\n readonly get: <State>(\n schema: Schema.Codec<State, unknown, never, never>,\n initial: State,\n ) => Effect.Effect<State, EDASessionStoreError>;\n /** Validate, encode, and durably save state without advancing the sink cursor. */\n readonly save: <State>(\n schema: Schema.Codec<State, unknown, never, never>,\n state: State,\n ) => Effect.Effect<void, EDASessionStoreError>;\n}\n\n/** Capabilities exposed to sink processors without granting raw store or bus access. */\nexport interface EDASinkContext {\n readonly sessionId: SessionId;\n /** Sink-owned checkpoint state, serialized with cursor commits and background writes. */\n readonly checkpoint: EDASinkCheckpoint;\n /** Build a framework durable event if the sink needs to emit one. */\n readonly events: EventFactoryShape;\n /** Mint an app durable event id for staged custom events. */\n readonly makeEventId: () => Effect.Effect<EventId>;\n /** Publish a best-effort live-only event. */\n readonly emitEphemeral: (\n event: EphemeralEventEnvelope,\n ) => Effect.Effect<PositionedEvent, EDASessionStoreError>;\n /** Stage durable events; the runner commits them after the sink succeeds. */\n readonly stageDurable: (event: DurableEventEnvelope) => Effect.Effect<void>;\n /** Fork background sink work into the session scope. */\n readonly forkScoped: (effect: Effect.Effect<unknown, unknown>) => Effect.Effect<void>;\n}\n\n/** Durable sink definition backed by a checkpoint and an app-owned delivery policy. */\nexport interface EDADurableSinkDefinition {\n readonly interests?: ReadonlyArray<EventType | string>;\n readonly batchSize?: number;\n readonly process: (batch: EDASinkDurableBatch, ctx: EDASinkContext) => Effect.Effect<void, never>;\n}\n\n/** Best-effort live-only sink definition. */\nexport interface EDAEphemeralSinkDefinition {\n readonly interests?: ReadonlyArray<EventType | string>;\n readonly process: (event: PositionedEvent, ctx: EDASinkContext) => Effect.Effect<void, never>;\n}\n\n/**\n * Named app integration hook with optional durable and ephemeral filters.\n *\n * Every sink runs on one serialized position-ordered lane. Sinks own retry and\n * terminal failure handling, so callbacks must have an infallible typed error\n * channel. An unexpected defect is logged and skipped before the durable checkpoint\n * advances. Ephemeral callbacks are best-effort and are only processed after the\n * durable prefix at their anchor sequence has been projected.\n */\nexport interface EDASink {\n readonly name: string;\n readonly durable?: EDADurableSinkDefinition;\n readonly ephemeral?: EDAEphemeralSinkDefinition;\n}\n\n/** Convenience constructor preserving a sink's literal name/type information. */\nexport const EDASink = {\n make: <const Sink extends EDASink>(sink: Sink): Sink => sink,\n};\n\n/** Session-owned capabilities needed to start all registered sink runners. */\nexport interface EDASinkRunnerStartInput {\n readonly appendDurableBatch: (\n events: ReadonlyArray<DurableEventEnvelope>,\n ) => Effect.Effect<ReadonlyArray<CommittedDurableEvent>, EDASessionStoreError>;\n /** Immutable framework and app projections at one common durable head. */\n readonly initialProjection: {\n readonly reduced: ReducedState;\n readonly reducerStates: EDAReducerStateSnapshot;\n };\n readonly publishEphemeral: (\n event: EphemeralEventEnvelope,\n ) => Effect.Effect<PositionedEvent, EDASessionStoreError>;\n readonly scope: Scope.Scope;\n}\n\n/** Registry service coordinating durable checkpoints and live sink delivery. */\nexport interface EDASinkRegistryShape {\n readonly sinks: ReadonlyArray<EDASink>;\n /** Start long-lived sink runners. Safe to call once during session-state acquisition. */\n readonly startSinkRunners: (\n input: EDASinkRunnerStartInput,\n ) => Effect.Effect<void, EDASessionStoreError>;\n /** Coalesced non-blocking nudge that the durable log head advanced. */\n readonly notifyDurableHeadAdvanced: (head: SequenceNumber) => Effect.Effect<void>;\n /** Best-effort non-blocking delivery to ephemeral sink workers. */\n readonly publishEphemeralToSinks: (\n event: PositionedEvent,\n publishEphemeral: (\n event: EphemeralEventEnvelope,\n ) => Effect.Effect<PositionedEvent, EDASessionStoreError>,\n ) => Effect.Effect<void>;\n}\n\n/** Registry and runner for app-provided EDA sinks. */\nexport class EDASinkRegistry extends Context.Service<EDASinkRegistry, EDASinkRegistryShape>()(\n \"@effect-durable-agent/EDASinkRegistry\",\n) {\n static readonly Empty = Layer.succeed(EDASinkRegistry, {\n sinks: [],\n startSinkRunners: () => Effect.void,\n notifyDurableHeadAdvanced: () => Effect.void,\n publishEphemeralToSinks: () => Effect.void,\n } satisfies EDASinkRegistryShape);\n\n static readonly Live = (sinks: ReadonlyArray<EDASink>) =>\n Layer.effect(EDASinkRegistry, makeSinkRegistry(sinks));\n}\n\nconst defaultBatchSize = 100;\nconst sinkCheckpointFormatVersion = 1;\n\ninterface DurableRunnerState {\n readonly cursor: SequenceNumber;\n readonly reduced: ReducedState;\n readonly reducerStates: EDAReducerStateSnapshot;\n}\n\ninterface SerializedSinkState {\n readonly formatVersion: typeof sinkCheckpointFormatVersion;\n readonly state: unknown;\n readonly updatedAtMs: number;\n}\n\nconst makeSinkRegistry = (sinks: ReadonlyArray<EDASink>) =>\n Effect.gen(function* () {\n const session = yield* SessionContext;\n const store = yield* EDASessionStore;\n const liveBus = yield* LiveEventBus;\n const checkpointStore = yield* SinkCheckpointStore;\n const eventFactory = yield* EventFactory;\n const ids = yield* IdGenerator;\n const reducerRegistry = yield* EDAReducerRegistry;\n const keepAlive = yield* EDAKeepAlive;\n const started = yield* Ref.make(false);\n\n const baseContext = (\n staged: Array<DurableEventEnvelope>,\n publishEphemeral: (\n event: EphemeralEventEnvelope,\n ) => Effect.Effect<PositionedEvent, EDASessionStoreError>,\n scope: Scope.Scope,\n checkpoint: EDASinkCheckpoint,\n ): EDASinkContext => ({\n sessionId: session.sessionId,\n checkpoint,\n events: eventFactory,\n makeEventId: ids.makeEventId,\n emitEphemeral: publishEphemeral,\n stageDurable: (event) => Effect.sync(() => staged.push(event)),\n forkScoped: (effect) => effect.pipe(Effect.forkIn(scope), Effect.asVoid),\n });\n\n const makeSinkRunner = Effect.fnUntraced(function* (\n sink: EDASink,\n { initialProjection, appendDurableBatch, publishEphemeral, scope }: EDASinkRunnerStartInput,\n ) {\n // Long-lived fibers capture the head and capabilities, not the initial projection.\n const initialHead = initialProjection.reduced.lastSeq;\n const sinkName = EDASinkName.make(sink.name);\n const storedCheckpoint = yield* checkpointStore.load(sinkName);\n const checkpointRef = yield* SynchronizedRef.make(storedCheckpoint);\n const checkpoint = makeSinkCheckpoint(checkpointStore, sinkName, checkpointRef);\n const cursor = storedCheckpoint.afterSeq;\n const initial: DurableRunnerState = {\n cursor,\n reduced: initialReducedState,\n reducerStates: reducerRegistry.initial,\n };\n // Share the immutable session projection only at exactly the sink's cursor.\n // Lagging sinks must reconstruct their earlier state, never observe future state.\n const hydrated =\n cursor === initialHead\n ? {\n cursor,\n reduced: initialProjection.reduced,\n reducerStates: initialProjection.reducerStates,\n }\n : cursor <= SequenceNumber.make(0)\n ? initial\n : yield* store.eventsAfter(SequenceNumber.make(0)).pipe(\n Stream.takeWhile((event) => event.position.seq <= cursor),\n Stream.chunks,\n Stream.runFold(\n () => initial,\n (current, page): DurableRunnerState => ({\n cursor,\n reduced: foldReducedState(current.reduced, page),\n reducerStates: reducerRegistry.reduce(current.reducerStates, page),\n }),\n ),\n );\n const state = yield* Ref.make(hydrated);\n const live = yield* liveBus.subscribeQueue().pipe(Scope.provide(scope));\n\n const processDurableBatch = Effect.fnUntraced(function* (\n allEvents: ReadonlyArray<CommittedDurableEvent>,\n ) {\n if (allEvents.length === 0) {\n return;\n }\n\n const current = yield* Ref.get(state);\n const fresh = allEvents.filter((entry) => entry.position.seq > current.cursor);\n if (fresh.length === 0) {\n return;\n }\n\n const durable = sink.durable;\n const throughSeq = fresh.at(-1)!.position.seq;\n const nextReduced = foldReducedState(current.reduced, fresh);\n const nextReducerStates = reducerRegistry.reduce(current.reducerStates, fresh);\n const eventsForSink =\n durable === undefined ? [] : filterInterested(fresh, durable.interests);\n\n if (durable !== undefined && eventsForSink.length > 0) {\n yield* Effect.gen(function* () {\n const staged: Array<DurableEventEnvelope> = [];\n const completed = yield* durable\n .process(\n {\n allEvents: fresh,\n events: eventsForSink,\n stateAfter: nextReduced,\n reducerStates: nextReducerStates,\n throughSeq,\n },\n baseContext(staged, publishEphemeral, scope, checkpoint),\n )\n .pipe(\n Effect.as(true),\n Effect.catchCause((cause) =>\n Cause.hasInterruptsOnly(cause)\n ? Effect.failCause(cause)\n : Effect.logError(\"EDA durable sink violated its infallible contract\", {\n cause: Cause.pretty(cause),\n sink: sink.name,\n }).pipe(Effect.as(false)),\n ),\n );\n if (completed && staged.length > 0) {\n yield* annotateEdaSpan({ \"eda.sink.staged_events\": staged.length });\n yield* appendDurableBatch(staged);\n }\n }).pipe(\n Effect.withSpan(\"agent.sink.drain\", {\n attributes: {\n \"eda.sink.name\": sink.name,\n \"eda.sink.cursor.before\": current.cursor,\n \"eda.sink.events.read\": fresh.length,\n \"eda.sink.events.interested\": eventsForSink.length,\n \"eda.sink.cursor.after\": throughSeq,\n },\n }),\n );\n }\n\n yield* commitSinkCheckpoint(checkpointStore, sinkName, checkpointRef, throughSeq);\n yield* Ref.set(state, {\n cursor: throughSeq,\n reduced: nextReduced,\n reducerStates: nextReducerStates,\n });\n });\n\n const processDurableBatchWithKeepAlive = (events: ReadonlyArray<CommittedDurableEvent>) =>\n keepAlive.withActiveWork(`sink:${sink.name}`, processDurableBatch(events));\n\n const drainDurablesThrough = (targetHead: SequenceNumber) =>\n Effect.gen(function* () {\n while (true) {\n const current = yield* Ref.get(state);\n if (current.cursor >= targetHead) {\n return;\n }\n const allEvents = yield* readCursorBatchThrough(\n store,\n current.cursor,\n targetHead,\n sink.durable?.batchSize,\n );\n if (allEvents.length === 0) {\n return;\n }\n yield* processDurableBatchWithKeepAlive(allEvents);\n }\n });\n\n const processLiveDurable = (event: PositionedEvent) =>\n Effect.gen(function* () {\n const current = yield* Ref.get(state);\n if (event.position.seq <= current.cursor) {\n return;\n }\n if (event.position.seq > current.cursor + 1) {\n yield* drainDurablesThrough(SequenceNumber.make(event.position.seq - 1));\n }\n const afterCatchup = yield* Ref.get(state);\n if (event.position.seq > afterCatchup.cursor + 1) {\n yield* Effect.logWarning(\"EDA sink runner could not catch up before live durable\", {\n cursor: afterCatchup.cursor,\n eventSeq: event.position.seq,\n sink: sink.name,\n });\n return;\n }\n yield* processDurableBatchWithKeepAlive([committedDurableFromPositioned(event)]);\n });\n\n const processLiveEphemeral = (event: PositionedEvent) =>\n Effect.gen(function* () {\n const before = yield* Ref.get(state);\n if (event.position.seq < before.cursor) {\n return;\n }\n if (event.position.seq > before.cursor) {\n yield* drainDurablesThrough(event.position.seq);\n }\n const after = yield* Ref.get(state);\n if (event.position.seq !== after.cursor) {\n return;\n }\n if (\n sink.ephemeral === undefined ||\n !matchesInterest(event.event.type, sink.ephemeral.interests)\n ) {\n return;\n }\n yield* sink.ephemeral\n .process(event, baseContext([], publishEphemeral, scope, checkpoint))\n .pipe(\n Effect.catchCause((cause) =>\n Effect.logError(\"EDA sink ephemeral projection failed\", {\n cause: String(cause),\n sink: sink.name,\n }),\n ),\n );\n });\n\n const processLiveEvent = (event: PositionedEvent) =>\n event.event.durability === \"durable\"\n ? processLiveDurable(event)\n : processLiveEphemeral(event);\n\n const runLoop = Effect.gen(function* () {\n yield* drainDurablesThrough(initialHead);\n return yield* Effect.forever(\n Effect.gen(function* () {\n const event = yield* PubSub.take(live);\n yield* processLiveEvent(event);\n }),\n );\n }).pipe(\n Effect.catchCause((cause) =>\n Effect.logError(\"EDA sink runner failed\", {\n cause: Cause.pretty(cause),\n sink: sink.name,\n }),\n ),\n );\n\n return runLoop;\n });\n\n return {\n sinks,\n startSinkRunners: Effect.fnUntraced(function* (input: EDASinkRunnerStartInput) {\n const wasStarted = yield* Ref.getAndSet(started, true);\n if (wasStarted) {\n return;\n }\n const runners = yield* Effect.forEach(sinks, (sink) => makeSinkRunner(sink, input), {\n concurrency: 1,\n });\n // Catch-up can append events. Subscribe every sink before starting any delivery fiber.\n yield* Effect.forEach(runners, (runner) => runner.pipe(Effect.forkIn(input.scope)), {\n discard: true,\n });\n }),\n notifyDurableHeadAdvanced: () => Effect.void,\n publishEphemeralToSinks: () => Effect.void,\n } satisfies EDASinkRegistryShape;\n });\n\nconst makeSinkCheckpoint = (\n store: SinkCheckpointStoreShape,\n sinkName: EDASinkName,\n checkpointRef: SynchronizedRef.SynchronizedRef<StoredSinkCheckpoint>,\n): EDASinkCheckpoint => ({\n get: (schema, initial) =>\n SynchronizedRef.get(checkpointRef).pipe(\n Effect.flatMap((checkpoint) => {\n const serialized = serializedSinkState(checkpoint.payload);\n return serialized === undefined\n ? Effect.succeed(initial)\n : decodeSinkState(schema, serialized.state);\n }),\n ),\n save: (schema, state) =>\n encodeSinkState(schema, state).pipe(\n Effect.flatMap((encoded) => {\n const payload: SerializedSinkState = {\n formatVersion: sinkCheckpointFormatVersion,\n state: encoded,\n updatedAtMs: Date.now(),\n };\n return SynchronizedRef.modifyEffect(checkpointRef, (checkpoint) =>\n store.saveState(sinkName, payload).pipe(\n Effect.as([\n undefined,\n {\n afterSeq: checkpoint.afterSeq,\n payload,\n },\n ] as const),\n ),\n );\n }),\n ),\n});\n\nconst commitSinkCheckpoint = (\n store: SinkCheckpointStoreShape,\n sinkName: EDASinkName,\n checkpointRef: SynchronizedRef.SynchronizedRef<StoredSinkCheckpoint>,\n afterSeq: SequenceNumber,\n): Effect.Effect<void, EDASessionStoreError> =>\n SynchronizedRef.modifyEffect(checkpointRef, (checkpoint) =>\n store.commit(sinkName, afterSeq, checkpoint.payload).pipe(\n Effect.as([\n undefined,\n {\n afterSeq,\n payload: checkpoint.payload,\n },\n ] as const),\n ),\n );\n\nconst serializedSinkState = (payload: unknown): SerializedSinkState | undefined => {\n if (\n typeof payload !== \"object\" ||\n payload === null ||\n !(\"formatVersion\" in payload) ||\n payload.formatVersion !== sinkCheckpointFormatVersion ||\n !(\"state\" in payload) ||\n !(\"updatedAtMs\" in payload) ||\n typeof payload.updatedAtMs !== \"number\"\n ) {\n return undefined;\n }\n return {\n formatVersion: sinkCheckpointFormatVersion,\n state: payload.state,\n updatedAtMs: payload.updatedAtMs,\n };\n};\n\nconst decodeSinkState = <State>(\n schema: Schema.Codec<State, unknown, never, never>,\n encoded: unknown,\n): Effect.Effect<State, EDASessionStoreError> =>\n Effect.try({\n try: () => Schema.decodeUnknownSync(schema)(encoded),\n catch: (cause) => sinkCheckpointCodecError(\"decoding\", cause),\n });\n\nconst encodeSinkState = <State>(\n schema: Schema.Codec<State, unknown, never, never>,\n state: State,\n): Effect.Effect<unknown, EDASessionStoreError> =>\n Effect.try({\n try: () => Schema.encodeUnknownSync(schema)(state),\n catch: (cause) => sinkCheckpointCodecError(\"encoding\", cause),\n });\n\nconst sinkCheckpointCodecError = (operation: string, cause: unknown) =>\n new EDASessionStoreError({\n message:\n cause instanceof Error\n ? `${operation} sink checkpoint: ${cause.message}`\n : `${operation} sink checkpoint: ${String(cause)}`,\n });\n\nconst readCursorBatchThrough = (\n store: EDASessionStoreShape,\n afterSeq: SequenceNumber,\n throughSeq: SequenceNumber,\n batchSize = defaultBatchSize,\n) =>\n store.eventsAfter(afterSeq).pipe(\n Stream.takeWhile((event) => event.position.seq <= throughSeq),\n Stream.take(batchSize),\n Stream.runCollect,\n Effect.map((events) => Array.from(events)),\n );\n\nconst committedDurableFromPositioned = (event: PositionedEvent): CommittedDurableEvent =>\n CommittedDurableEvent.make({\n event: event.event as DurableEventEnvelope,\n position: durablePosition(event.position.seq),\n });\n\nconst filterInterested = (\n events: ReadonlyArray<CommittedDurableEvent>,\n interests: ReadonlyArray<EventType | string> | undefined,\n): ReadonlyArray<CommittedDurableEvent> =>\n events.filter((event) => matchesInterest(event.event.type, interests));\n\nconst matchesInterest = (\n type: EventType | string,\n interests: ReadonlyArray<EventType | string> | undefined,\n): boolean => interests === undefined || interests.some((interest) => interest === type);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAmBA,MAAa,oCAAoC;;AAuBjD,IAAa,eAAb,MAAa,qBAAqB,QAAQ,QAAyC,EACjF,oCACF,EAAE;CACA,OAAgB,OAAO,MAAM,OAC3B,cACA,OAAO,I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,KAAa,UAAU,MAAM,aAAa,aAAa,IAAI"}
|
package/dist/testkit/layers.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { g as SessionId } from "../core-C-6xHzRx.js";
|
|
2
2
|
import { t as DurableEventEnvelope } from "../envelope-DkZyMIgp.js";
|
|
3
|
-
import { a as EDASessionStore, o as EDASessionStoreError, s as EDASessionStoreShape } from "../session-store-
|
|
3
|
+
import { a as EDASessionStore, o as EDASessionStoreError, s as EDASessionStoreShape } from "../session-store-BIr-xfJ7.js";
|
|
4
4
|
import { t as ModelResolver } from "../model-resolver-BPPJAsuh.js";
|
|
5
5
|
import { t as IdGenerator } from "../id-generator--x6itQZ2.js";
|
|
6
|
-
import { r as SessionContext, t as EventFactory } from "../event-factory-
|
|
6
|
+
import { r as SessionContext, t as EventFactory } from "../event-factory-EL4szNWm.js";
|
|
7
7
|
import { t as EDAKeepAlive } from "../keep-alive-Chl5SJxy.js";
|
|
8
|
-
import { c as CompactionPolicy, d as CompactionRunner, r as CompactionExecutor } from "../compaction-
|
|
9
|
-
import { r as EDASink, s as EDASinkRegistry, u as LiveEventBus } from "../sink-registry-
|
|
10
|
-
import { r as EDAReducerRegistry, t as EDAReducer } from "../reducer-registry-
|
|
11
|
-
import { r as EDAPromptProjector } from "../prompt-projector-
|
|
12
|
-
import { n as SinkCheckpointStore } from "../sink-checkpoint-store-
|
|
13
|
-
import { t as RunScheduler } from "../run-scheduler-
|
|
14
|
-
import { t as RunSchedulingWakeup } from "../run-scheduling-wakeup-
|
|
15
|
-
import { S as ToolExecutor, b as InferenceRunner, h as SessionState, x as InferenceRunnerStreamPart, y as TurnRunner } from "../session-state-
|
|
16
|
-
import { a as ToolParamsSchema, r as EDAToolRegistry, t as EDAModelToolkit } from "../tool-registry-
|
|
17
|
-
import { n as EDASessionQuery } from "../session-query-
|
|
8
|
+
import { c as CompactionPolicy, d as CompactionRunner, r as CompactionExecutor } from "../compaction-CLCDOR1t.js";
|
|
9
|
+
import { r as EDASink, s as EDASinkRegistry, u as LiveEventBus } from "../sink-registry-C2t3DI_g.js";
|
|
10
|
+
import { r as EDAReducerRegistry, t as EDAReducer } from "../reducer-registry-DqljrD58.js";
|
|
11
|
+
import { r as EDAPromptProjector } from "../prompt-projector-CGo1TGyZ.js";
|
|
12
|
+
import { n as SinkCheckpointStore } from "../sink-checkpoint-store-Cr9_GmOw.js";
|
|
13
|
+
import { t as RunScheduler } from "../run-scheduler-DvHWwWBJ.js";
|
|
14
|
+
import { t as RunSchedulingWakeup } from "../run-scheduling-wakeup-CGgJ7RNe.js";
|
|
15
|
+
import { S as ToolExecutor, b as InferenceRunner, h as SessionState, x as InferenceRunnerStreamPart, y as TurnRunner } from "../session-state-13z-3YaF.js";
|
|
16
|
+
import { a as ToolParamsSchema, r as EDAToolRegistry, t as EDAModelToolkit } from "../tool-registry-Dhs2KmYK.js";
|
|
17
|
+
import { n as EDASessionQuery } from "../session-query-DYuJXhMQ.js";
|
|
18
18
|
import * as Layer from "effect/Layer";
|
|
19
19
|
import * as LanguageModel from "effect/unstable/ai/LanguageModel";
|
|
20
20
|
import * as Stream from "effect/Stream";
|
|
@@ -105,7 +105,7 @@ interface EdaTestLayerOptions {
|
|
|
105
105
|
* EDA service plus the fixed Clock. Layer constants are shared by reference,
|
|
106
106
|
* so all services see the same store, bus, and ID counter.
|
|
107
107
|
*/
|
|
108
|
-
declare const makeEdaTestLayer: (options: EdaTestLayerOptions) => Layer.Layer<ModelResolver | RunSchedulingWakeup |
|
|
108
|
+
declare const makeEdaTestLayer: (options: EdaTestLayerOptions) => Layer.Layer<RunScheduler | ModelResolver | RunSchedulingWakeup | SinkCheckpointStore | EDASessionQuery | SessionState | EDASessionStore | LiveEventBus | EDAReducerRegistry | CompactionPolicy | CompactionExecutor | CompactionRunner | EventFactory | IdGenerator | EDAKeepAlive | TurnRunner | EDAPromptProjector | SessionContext | EDASinkRegistry | InferenceRunner | ToolExecutor | EDAToolRegistry, EDASessionStoreError, never>;
|
|
109
109
|
//#endregion
|
|
110
110
|
export { EdaTestLayerOptions, FixedClock, TestLanguageModelOptions, TestModelParts, makeEdaTestLayer, makeFixedClock, makeLanguageModelLayer, testNowMs };
|
|
111
111
|
//# sourceMappingURL=layers.d.ts.map
|
package/dist/testkit/layers.js
CHANGED
|
@@ -2,13 +2,13 @@ import { RunSchedulingWakeup } from "../services/run-scheduling-wakeup.js";
|
|
|
2
2
|
import { RunScheduler } from "../services/run-scheduler.js";
|
|
3
3
|
import { ModelResolver } from "../services/model-resolver.js";
|
|
4
4
|
import { h as UnixEpochMillis } from "../envelope-DxQzo5rN.js";
|
|
5
|
-
import { d as TurnRunner, f as InferenceRunner, p as ToolExecutor, u as SessionState } from "../session-state-
|
|
5
|
+
import { d as TurnRunner, f as InferenceRunner, p as ToolExecutor, u as SessionState } from "../session-state-xXXyniwU.js";
|
|
6
6
|
import { EDASessionStore } from "../services/session-store.js";
|
|
7
7
|
import { a as CompactionPolicy, n as CompactionExecutor, o as CompactionRunner } from "../compaction-0k8zCJgB.js";
|
|
8
8
|
import { IdGenerator } from "../services/id-generator.js";
|
|
9
9
|
import { n as SessionContext, t as EventFactory } from "../event-factory-QuC_UvyP.js";
|
|
10
10
|
import { EDAKeepAlive } from "../services/keep-alive.js";
|
|
11
|
-
import { n as EDASinkRegistry, r as LiveEventBus } from "../sink-registry-
|
|
11
|
+
import { n as EDASinkRegistry, r as LiveEventBus } from "../sink-registry-CUIrrkXU.js";
|
|
12
12
|
import { EDAPromptProjector } from "../services/prompt-projector.js";
|
|
13
13
|
import { EDAReducerRegistry } from "../services/reducer-registry.js";
|
|
14
14
|
import { SinkCheckpointStore } from "../services/sink-checkpoint-store.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { c as EventId, g as SessionId, y as ToolCallId } from "./core-C-6xHzRx.js";
|
|
2
2
|
import { h as ToolName, t as DurableEventEnvelope } from "./envelope-DkZyMIgp.js";
|
|
3
|
-
import { o as EDASessionStoreError, t as CommittedDurableEvent } from "./session-store-
|
|
3
|
+
import { o as EDASessionStoreError, t as CommittedDurableEvent } from "./session-store-BIr-xfJ7.js";
|
|
4
4
|
import * as Context from "effect/Context";
|
|
5
5
|
import * as Effect from "effect/Effect";
|
|
6
6
|
import * as Layer from "effect/Layer";
|
|
@@ -48,4 +48,4 @@ declare class EDAToolRegistry extends EDAToolRegistry_base {
|
|
|
48
48
|
}
|
|
49
49
|
//#endregion
|
|
50
50
|
export { ToolParamsSchema as a, EDAToolRegistryShape as i, EDAToolExecutionContext as n, makeEDAToolkit as o, EDAToolRegistry as r, EDAModelToolkit as t };
|
|
51
|
-
//# sourceMappingURL=tool-registry-
|
|
51
|
+
//# sourceMappingURL=tool-registry-Dhs2KmYK.d.ts.map
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sink-registry-Bbqhtdnx.js","names":[],"sources":["../src/services/live-event-bus.ts","../src/services/sink-registry.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 * as Ref from \"effect/Ref\";\nimport type * as Scope from \"effect/Scope\";\nimport * as Stream from \"effect/Stream\";\n\nimport { TurnId } from \"../types/core\";\nimport {\n PositionedEvent,\n turnCompletedEventType,\n turnFailedEventType,\n turnStartedEventType,\n turnStoppedEventType,\n} from \"../types/events\";\nimport { SessionEventObserver, type SessionEventObserverShape } from \"./session-event-observer\";\n\n/** Conservative raw-delta cap for one open turn's live-only reconnect replay. */\nexport const activeTurnEphemeralReplayCapacity = 4_096;\n\n/** Live-only replay buffer for the currently open turn. */\nexport interface ActiveTurnEphemeralReplay {\n readonly turnId?: TurnId;\n readonly events: ReadonlyArray<PositionedEvent>;\n readonly overflowed: boolean;\n}\n\n/** In-memory live fanout plus active-turn replay source for reconnect streams. */\nexport interface LiveEventBusShape {\n readonly publish: (event: PositionedEvent) => Effect.Effect<boolean>;\n readonly subscribe: () => Effect.Effect<Stream.Stream<PositionedEvent>, never, Scope.Scope>;\n readonly subscribeQueue: () => Effect.Effect<\n PubSub.Subscription<PositionedEvent>,\n never,\n Scope.Scope\n >;\n /** Snapshot raw live-only events retained for the currently open turn. */\n readonly activeTurnReplay: () => Effect.Effect<ActiveTurnEphemeralReplay>;\n}\n\n/** Unbounded in-memory fanout plus bounded active-turn ephemeral replay. */\nexport class LiveEventBus extends Context.Service<LiveEventBus, LiveEventBusShape>()(\n \"@effect-durable-agent/LiveEventBus\",\n) {\n static readonly Live = Layer.effect(\n LiveEventBus,\n Effect.gen(function* () {\n const pubsub = yield* Effect.acquireRelease(\n PubSub.unbounded<PositionedEvent>(),\n PubSub.shutdown,\n );\n const activeTurnReplay = yield* Ref.make<ActiveTurnEphemeralReplay>({\n events: [],\n overflowed: false,\n });\n const observer = yield* SessionEventObserver;\n return makeLiveBus(pubsub, activeTurnReplay, observer);\n }),\n );\n\n /** Live bus for hosts that do not install an append-driven observer. */\n static readonly Noop = LiveEventBus.Live.pipe(Layer.provide(SessionEventObserver.Noop));\n}\n\nconst makeLiveBus = (\n pubsub: PubSub.PubSub<PositionedEvent>,\n activeTurnReplay: Ref.Ref<ActiveTurnEphemeralReplay>,\n observer: SessionEventObserverShape,\n): LiveEventBusShape => ({\n publish: (event) =>\n Effect.gen(function* () {\n yield* updateActiveTurnReplay(activeTurnReplay, event);\n yield* observer.onEvent(event);\n return yield* PubSub.publish(pubsub, event);\n }),\n subscribeQueue: () => PubSub.subscribe(pubsub),\n subscribe: () =>\n Effect.map(PubSub.subscribe(pubsub), (subscription) =>\n Stream.fromEffectRepeat(PubSub.take(subscription)),\n ),\n activeTurnReplay: () => Ref.get(activeTurnReplay),\n});\n\nconst updateActiveTurnReplay = (\n ref: Ref.Ref<ActiveTurnEphemeralReplay>,\n event: PositionedEvent,\n): Effect.Effect<void> => Ref.update(ref, (state) => nextActiveTurnReplay(state, event));\n\nconst nextActiveTurnReplay = (\n state: ActiveTurnEphemeralReplay,\n event: PositionedEvent,\n): ActiveTurnEphemeralReplay => {\n if (event.event.type === turnStartedEventType) {\n return {\n turnId: (event.event.payload as { readonly turnId: TurnId }).turnId,\n events: [],\n overflowed: false,\n };\n }\n\n if (\n event.event.type === turnCompletedEventType ||\n event.event.type === turnFailedEventType ||\n event.event.type === turnStoppedEventType\n ) {\n const turnId = (event.event.payload as { readonly turnId?: TurnId }).turnId;\n return turnId === undefined || state.turnId === undefined || turnId === state.turnId\n ? { events: [], overflowed: false }\n : state;\n }\n\n if (event.event.durability !== \"ephemeral\" || state.turnId === undefined) {\n return state;\n }\n\n const events = [...state.events, event];\n if (events.length <= activeTurnEphemeralReplayCapacity) {\n return { ...state, events };\n }\n return {\n ...state,\n events: events.slice(events.length - activeTurnEphemeralReplayCapacity),\n overflowed: true,\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 PubSub from \"effect/PubSub\";\nimport * as Ref from \"effect/Ref\";\nimport * as Schema from \"effect/Schema\";\nimport * as Scope from \"effect/Scope\";\nimport * as Stream from \"effect/Stream\";\nimport * as SynchronizedRef from \"effect/SynchronizedRef\";\n\nimport {\n foldReducedState,\n reduceCommittedEvents,\n type ReducedState,\n} from \"../domain/reduced-state\";\nimport { EDAReducerRegistry, type EDAReducerStateSnapshot } from \"./reducer-registry\";\nimport { EventId, SessionId, SequenceNumber, durablePosition } from \"../types/core\";\nimport type {\n DurableEventEnvelope,\n EphemeralEventEnvelope,\n EventType,\n PositionedEvent,\n} from \"../types/events\";\nimport type { EDASessionStoreShape } from \"./session-store\";\nimport { CommittedDurableEvent, EDASessionStore, EDASessionStoreError } from \"./session-store\";\nimport { EventFactory } from \"./event-factory\";\nimport type { EventFactoryShape } from \"./event-factory\";\nimport { IdGenerator } from \"./id-generator\";\nimport { EDAKeepAlive } from \"./keep-alive\";\nimport { LiveEventBus } from \"./live-event-bus\";\nimport { SessionContext } from \"./session-context\";\nimport {\n EDASinkName,\n SinkCheckpointStore,\n type SinkCheckpointStoreShape,\n type StoredSinkCheckpoint,\n} from \"./sink-checkpoint-store\";\nimport { annotateEdaSpan } from \"./tracing\";\n\n/** Cursor-window input delivered to one durable sink drain. */\nexport interface EDASinkDurableBatch {\n /** All durable events replayed for this cursor window, including uninterested events. */\n readonly allEvents: ReadonlyArray<CommittedDurableEvent>;\n /** Events matching the sink's durable interests. */\n readonly events: ReadonlyArray<CommittedDurableEvent>;\n /** Authoritative reduced state folded exactly through `throughSeq`. */\n readonly stateAfter: ReducedState;\n /** App-specific durable reducer states folded exactly through `throughSeq`. */\n readonly reducerStates: EDAReducerStateSnapshot;\n /** Durable sequence through which the sink may advance after success. */\n readonly throughSeq: SequenceNumber;\n}\n\n/** Typed, sink-owned durable state stored independently from cursor advancement. */\nexport interface EDASinkCheckpoint {\n /** Decode current durable state, or return `initial` for a new or legacy cursor row. */\n readonly get: <State>(\n schema: Schema.Codec<State, unknown, never, never>,\n initial: State,\n ) => Effect.Effect<State, EDASessionStoreError>;\n /** Validate, encode, and durably save state without advancing the sink cursor. */\n readonly save: <State>(\n schema: Schema.Codec<State, unknown, never, never>,\n state: State,\n ) => Effect.Effect<void, EDASessionStoreError>;\n}\n\n/** Capabilities exposed to sink processors without granting raw store or bus access. */\nexport interface EDASinkContext {\n readonly sessionId: SessionId;\n /** Sink-owned checkpoint state, serialized with cursor commits and background writes. */\n readonly checkpoint: EDASinkCheckpoint;\n /** Build a framework durable event if the sink needs to emit one. */\n readonly events: EventFactoryShape;\n /** Mint an app durable event id for staged custom events. */\n readonly makeEventId: () => Effect.Effect<EventId>;\n /** Publish a best-effort live-only event. */\n readonly emitEphemeral: (\n event: EphemeralEventEnvelope,\n ) => Effect.Effect<PositionedEvent, EDASessionStoreError>;\n /** Stage durable events; the runner commits them after the sink succeeds. */\n readonly stageDurable: (event: DurableEventEnvelope) => Effect.Effect<void>;\n /** Fork background sink work into the session scope. */\n readonly forkScoped: (effect: Effect.Effect<unknown, unknown>) => Effect.Effect<void>;\n}\n\n/** Durable sink definition backed by a checkpoint and an app-owned delivery policy. */\nexport interface EDADurableSinkDefinition {\n readonly interests?: ReadonlyArray<EventType | string>;\n readonly batchSize?: number;\n readonly process: (batch: EDASinkDurableBatch, ctx: EDASinkContext) => Effect.Effect<void, never>;\n}\n\n/** Best-effort live-only sink definition. */\nexport interface EDAEphemeralSinkDefinition {\n readonly interests?: ReadonlyArray<EventType | string>;\n readonly process: (event: PositionedEvent, ctx: EDASinkContext) => Effect.Effect<void, never>;\n}\n\n/**\n * Named app integration hook with optional durable and ephemeral filters.\n *\n * Every sink runs on one serialized position-ordered lane. Sinks own retry and\n * terminal failure handling, so callbacks must have an infallible typed error\n * channel. An unexpected defect is logged and skipped before the durable checkpoint\n * advances. Ephemeral callbacks are best-effort and are only processed after the\n * durable prefix at their anchor sequence has been projected.\n */\nexport interface EDASink {\n readonly name: string;\n readonly durable?: EDADurableSinkDefinition;\n readonly ephemeral?: EDAEphemeralSinkDefinition;\n}\n\n/** Convenience constructor preserving a sink's literal name/type information. */\nexport const EDASink = {\n make: <const Sink extends EDASink>(sink: Sink): Sink => sink,\n};\n\n/** Session-owned capabilities needed to start all registered sink runners. */\nexport interface EDASinkRunnerStartInput {\n readonly appendDurableBatch: (\n events: ReadonlyArray<DurableEventEnvelope>,\n ) => Effect.Effect<ReadonlyArray<CommittedDurableEvent>, EDASessionStoreError>;\n readonly initialHead: SequenceNumber;\n readonly publishEphemeral: (\n event: EphemeralEventEnvelope,\n ) => Effect.Effect<PositionedEvent, EDASessionStoreError>;\n readonly scope: Scope.Scope;\n}\n\n/** Registry service coordinating durable checkpoints and live sink delivery. */\nexport interface EDASinkRegistryShape {\n readonly sinks: ReadonlyArray<EDASink>;\n /** Start long-lived sink runners. Safe to call once during session-state acquisition. */\n readonly startSinkRunners: (\n input: EDASinkRunnerStartInput,\n ) => Effect.Effect<void, EDASessionStoreError>;\n /** Coalesced non-blocking nudge that the durable log head advanced. */\n readonly notifyDurableHeadAdvanced: (head: SequenceNumber) => Effect.Effect<void>;\n /** Best-effort non-blocking delivery to ephemeral sink workers. */\n readonly publishEphemeralToSinks: (\n event: PositionedEvent,\n publishEphemeral: (\n event: EphemeralEventEnvelope,\n ) => Effect.Effect<PositionedEvent, EDASessionStoreError>,\n ) => Effect.Effect<void>;\n}\n\n/** Registry and runner for app-provided EDA sinks. */\nexport class EDASinkRegistry extends Context.Service<EDASinkRegistry, EDASinkRegistryShape>()(\n \"@effect-durable-agent/EDASinkRegistry\",\n) {\n static readonly Empty = Layer.succeed(EDASinkRegistry, {\n sinks: [],\n startSinkRunners: () => Effect.void,\n notifyDurableHeadAdvanced: () => Effect.void,\n publishEphemeralToSinks: () => Effect.void,\n } satisfies EDASinkRegistryShape);\n\n static readonly Live = (sinks: ReadonlyArray<EDASink>) =>\n Layer.effect(EDASinkRegistry, makeSinkRegistry(sinks));\n}\n\nconst defaultBatchSize = 100;\nconst sinkCheckpointFormatVersion = 1;\n\ninterface DurableRunnerState {\n readonly cursor: SequenceNumber;\n readonly reduced: ReducedState;\n readonly reducerStates: EDAReducerStateSnapshot;\n}\n\ninterface SerializedSinkState {\n readonly formatVersion: typeof sinkCheckpointFormatVersion;\n readonly state: unknown;\n readonly updatedAtMs: number;\n}\n\nconst makeSinkRegistry = (sinks: ReadonlyArray<EDASink>) =>\n Effect.gen(function* () {\n const session = yield* SessionContext;\n const store = yield* EDASessionStore;\n const liveBus = yield* LiveEventBus;\n const checkpointStore = yield* SinkCheckpointStore;\n const eventFactory = yield* EventFactory;\n const ids = yield* IdGenerator;\n const reducerRegistry = yield* EDAReducerRegistry;\n const keepAlive = yield* EDAKeepAlive;\n const started = yield* Ref.make(false);\n\n const baseContext = (\n staged: Array<DurableEventEnvelope>,\n publishEphemeral: (\n event: EphemeralEventEnvelope,\n ) => Effect.Effect<PositionedEvent, EDASessionStoreError>,\n scope: Scope.Scope,\n checkpoint: EDASinkCheckpoint,\n ): EDASinkContext => ({\n sessionId: session.sessionId,\n checkpoint,\n events: eventFactory,\n makeEventId: ids.makeEventId,\n emitEphemeral: publishEphemeral,\n stageDurable: (event) => Effect.sync(() => staged.push(event)),\n forkScoped: (effect) => effect.pipe(Effect.forkIn(scope), Effect.asVoid),\n });\n\n const makeSinkRunner = (sink: EDASink, input: EDASinkRunnerStartInput) =>\n Effect.gen(function* () {\n const sinkName = EDASinkName.make(sink.name);\n const storedCheckpoint = yield* checkpointStore.load(sinkName);\n const checkpointRef = yield* SynchronizedRef.make(storedCheckpoint);\n const checkpoint = makeSinkCheckpoint(checkpointStore, sinkName, checkpointRef);\n const cursor = storedCheckpoint.afterSeq;\n const prefix = yield* readDurablePrefixThrough(store, cursor);\n const state = yield* Ref.make<DurableRunnerState>({\n cursor,\n reduced: reduceCommittedEvents(prefix),\n reducerStates: reducerRegistry.reduce(reducerRegistry.initial, prefix),\n });\n const live = yield* liveBus.subscribeQueue().pipe(Scope.provide(input.scope));\n\n const processDurableBatch = Effect.fnUntraced(function* (\n allEvents: ReadonlyArray<CommittedDurableEvent>,\n ) {\n if (allEvents.length === 0) {\n return;\n }\n\n const current = yield* Ref.get(state);\n const fresh = allEvents.filter((entry) => entry.position.seq > current.cursor);\n if (fresh.length === 0) {\n return;\n }\n\n const durable = sink.durable;\n const throughSeq = fresh.at(-1)!.position.seq;\n const nextReduced = foldReducedState(current.reduced, fresh);\n const nextReducerStates = reducerRegistry.reduce(current.reducerStates, fresh);\n const eventsForSink =\n durable === undefined ? [] : filterInterested(fresh, durable.interests);\n\n if (durable !== undefined && eventsForSink.length > 0) {\n yield* Effect.gen(function* () {\n const staged: Array<DurableEventEnvelope> = [];\n const completed = yield* durable\n .process(\n {\n allEvents: fresh,\n events: eventsForSink,\n stateAfter: nextReduced,\n reducerStates: nextReducerStates,\n throughSeq,\n },\n baseContext(staged, input.publishEphemeral, input.scope, checkpoint),\n )\n .pipe(\n Effect.as(true),\n Effect.catchCause((cause) =>\n Cause.hasInterruptsOnly(cause)\n ? Effect.failCause(cause)\n : Effect.logError(\"EDA durable sink violated its infallible contract\", {\n cause: Cause.pretty(cause),\n sink: sink.name,\n }).pipe(Effect.as(false)),\n ),\n );\n if (completed && staged.length > 0) {\n yield* annotateEdaSpan({ \"eda.sink.staged_events\": staged.length });\n yield* input.appendDurableBatch(staged);\n }\n }).pipe(\n Effect.withSpan(\"agent.sink.drain\", {\n attributes: {\n \"eda.sink.name\": sink.name,\n \"eda.sink.cursor.before\": current.cursor,\n \"eda.sink.events.read\": fresh.length,\n \"eda.sink.events.interested\": eventsForSink.length,\n \"eda.sink.cursor.after\": throughSeq,\n },\n }),\n );\n }\n\n yield* commitSinkCheckpoint(checkpointStore, sinkName, checkpointRef, throughSeq);\n yield* Ref.set(state, {\n cursor: throughSeq,\n reduced: nextReduced,\n reducerStates: nextReducerStates,\n });\n });\n\n const processDurableBatchWithKeepAlive = (events: ReadonlyArray<CommittedDurableEvent>) =>\n keepAlive.withActiveWork(`sink:${sink.name}`, processDurableBatch(events));\n\n const drainDurablesThrough = (targetHead: SequenceNumber) =>\n Effect.gen(function* () {\n while (true) {\n const current = yield* Ref.get(state);\n if (current.cursor >= targetHead) {\n return;\n }\n const allEvents = yield* readCursorBatchThrough(\n store,\n current.cursor,\n targetHead,\n sink.durable?.batchSize,\n );\n if (allEvents.length === 0) {\n return;\n }\n yield* processDurableBatchWithKeepAlive(allEvents);\n }\n });\n\n const processLiveDurable = (event: PositionedEvent) =>\n Effect.gen(function* () {\n const current = yield* Ref.get(state);\n if (event.position.seq <= current.cursor) {\n return;\n }\n if (event.position.seq > current.cursor + 1) {\n yield* drainDurablesThrough(SequenceNumber.make(event.position.seq - 1));\n }\n const afterCatchup = yield* Ref.get(state);\n if (event.position.seq > afterCatchup.cursor + 1) {\n yield* Effect.logWarning(\"EDA sink runner could not catch up before live durable\", {\n cursor: afterCatchup.cursor,\n eventSeq: event.position.seq,\n sink: sink.name,\n });\n return;\n }\n yield* processDurableBatchWithKeepAlive([committedDurableFromPositioned(event)]);\n });\n\n const processLiveEphemeral = (event: PositionedEvent) =>\n Effect.gen(function* () {\n const before = yield* Ref.get(state);\n if (event.position.seq < before.cursor) {\n return;\n }\n if (event.position.seq > before.cursor) {\n yield* drainDurablesThrough(event.position.seq);\n }\n const after = yield* Ref.get(state);\n if (event.position.seq !== after.cursor) {\n return;\n }\n if (\n sink.ephemeral === undefined ||\n !matchesInterest(event.event.type, sink.ephemeral.interests)\n ) {\n return;\n }\n yield* sink.ephemeral\n .process(event, baseContext([], input.publishEphemeral, input.scope, checkpoint))\n .pipe(\n Effect.catchCause((cause) =>\n Effect.logError(\"EDA sink ephemeral projection failed\", {\n cause: String(cause),\n sink: sink.name,\n }),\n ),\n );\n });\n\n const processLiveEvent = (event: PositionedEvent) =>\n event.event.durability === \"durable\"\n ? processLiveDurable(event)\n : processLiveEphemeral(event);\n\n const runLoop = Effect.gen(function* () {\n yield* drainDurablesThrough(input.initialHead);\n return yield* Effect.forever(\n Effect.gen(function* () {\n const event = yield* PubSub.take(live);\n yield* processLiveEvent(event);\n }),\n );\n }).pipe(\n Effect.catchCause((cause) =>\n Effect.logError(\"EDA sink runner failed\", {\n cause: Cause.pretty(cause),\n sink: sink.name,\n }),\n ),\n );\n\n yield* runLoop.pipe(Effect.forkIn(input.scope));\n });\n\n return {\n sinks,\n startSinkRunners: Effect.fnUntraced(function* (input: EDASinkRunnerStartInput) {\n const wasStarted = yield* Ref.getAndSet(started, true);\n if (wasStarted) {\n return;\n }\n yield* Effect.forEach(sinks, (sink) => makeSinkRunner(sink, input), {\n discard: true,\n concurrency: \"unbounded\",\n });\n }),\n notifyDurableHeadAdvanced: () => Effect.void,\n publishEphemeralToSinks: () => Effect.void,\n } satisfies EDASinkRegistryShape;\n });\n\nconst readDurablePrefixThrough = (store: EDASessionStoreShape, throughSeq: SequenceNumber) => {\n if (throughSeq <= SequenceNumber.make(0)) {\n return Effect.succeed([]);\n }\n return store.eventsAfter(SequenceNumber.make(0)).pipe(\n Stream.takeWhile((event) => event.position.seq <= throughSeq),\n Stream.runCollect,\n Effect.map((events) => Array.from(events)),\n );\n};\n\nconst makeSinkCheckpoint = (\n store: SinkCheckpointStoreShape,\n sinkName: EDASinkName,\n checkpointRef: SynchronizedRef.SynchronizedRef<StoredSinkCheckpoint>,\n): EDASinkCheckpoint => ({\n get: (schema, initial) =>\n SynchronizedRef.get(checkpointRef).pipe(\n Effect.flatMap((checkpoint) => {\n const serialized = serializedSinkState(checkpoint.payload);\n return serialized === undefined\n ? Effect.succeed(initial)\n : decodeSinkState(schema, serialized.state);\n }),\n ),\n save: (schema, state) =>\n encodeSinkState(schema, state).pipe(\n Effect.flatMap((encoded) => {\n const payload: SerializedSinkState = {\n formatVersion: sinkCheckpointFormatVersion,\n state: encoded,\n updatedAtMs: Date.now(),\n };\n return SynchronizedRef.modifyEffect(checkpointRef, (checkpoint) =>\n store.saveState(sinkName, payload).pipe(\n Effect.as([\n undefined,\n {\n afterSeq: checkpoint.afterSeq,\n payload,\n },\n ] as const),\n ),\n );\n }),\n ),\n});\n\nconst commitSinkCheckpoint = (\n store: SinkCheckpointStoreShape,\n sinkName: EDASinkName,\n checkpointRef: SynchronizedRef.SynchronizedRef<StoredSinkCheckpoint>,\n afterSeq: SequenceNumber,\n): Effect.Effect<void, EDASessionStoreError> =>\n SynchronizedRef.modifyEffect(checkpointRef, (checkpoint) =>\n store.commit(sinkName, afterSeq, checkpoint.payload).pipe(\n Effect.as([\n undefined,\n {\n afterSeq,\n payload: checkpoint.payload,\n },\n ] as const),\n ),\n );\n\nconst serializedSinkState = (payload: unknown): SerializedSinkState | undefined => {\n if (\n typeof payload !== \"object\" ||\n payload === null ||\n !(\"formatVersion\" in payload) ||\n payload.formatVersion !== sinkCheckpointFormatVersion ||\n !(\"state\" in payload) ||\n !(\"updatedAtMs\" in payload) ||\n typeof payload.updatedAtMs !== \"number\"\n ) {\n return undefined;\n }\n return {\n formatVersion: sinkCheckpointFormatVersion,\n state: payload.state,\n updatedAtMs: payload.updatedAtMs,\n };\n};\n\nconst decodeSinkState = <State>(\n schema: Schema.Codec<State, unknown, never, never>,\n encoded: unknown,\n): Effect.Effect<State, EDASessionStoreError> =>\n Effect.try({\n try: () => Schema.decodeUnknownSync(schema)(encoded),\n catch: (cause) => sinkCheckpointCodecError(\"decoding\", cause),\n });\n\nconst encodeSinkState = <State>(\n schema: Schema.Codec<State, unknown, never, never>,\n state: State,\n): Effect.Effect<unknown, EDASessionStoreError> =>\n Effect.try({\n try: () => Schema.encodeUnknownSync(schema)(state),\n catch: (cause) => sinkCheckpointCodecError(\"encoding\", cause),\n });\n\nconst sinkCheckpointCodecError = (operation: string, cause: unknown) =>\n new EDASessionStoreError({\n message:\n cause instanceof Error\n ? `${operation} sink checkpoint: ${cause.message}`\n : `${operation} sink checkpoint: ${String(cause)}`,\n });\n\nconst readCursorBatchThrough = (\n store: EDASessionStoreShape,\n afterSeq: SequenceNumber,\n throughSeq: SequenceNumber,\n batchSize = defaultBatchSize,\n) =>\n store.eventsAfter(afterSeq).pipe(\n Stream.takeWhile((event) => event.position.seq <= throughSeq),\n Stream.take(batchSize),\n Stream.runCollect,\n Effect.map((events) => Array.from(events)),\n );\n\nconst committedDurableFromPositioned = (event: PositionedEvent): CommittedDurableEvent =>\n CommittedDurableEvent.make({\n event: event.event as DurableEventEnvelope,\n position: durablePosition(event.position.seq),\n });\n\nconst filterInterested = (\n events: ReadonlyArray<CommittedDurableEvent>,\n interests: ReadonlyArray<EventType | string> | undefined,\n): ReadonlyArray<CommittedDurableEvent> =>\n events.filter((event) => matchesInterest(event.event.type, interests));\n\nconst matchesInterest = (\n type: EventType | string,\n interests: ReadonlyArray<EventType | string> | undefined,\n): boolean => interests === undefined || interests.some((interest) => interest === type);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAmBA,MAAa,oCAAoC;;AAuBjD,IAAa,eAAb,MAAa,qBAAqB,QAAQ,QAAyC,EACjF,oCACF,EAAE;CACA,OAAgB,OAAO,MAAM,OAC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