effect-durable-agent 0.1.0-alpha.12 → 0.1.0-alpha.14
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-B45Xa1Dl.d.ts → command-queues-CSEl1yrH.d.ts} +2 -2
- package/dist/{compaction-CLCDOR1t.d.ts → compaction-DYAlYxx5.d.ts} +5 -5
- package/dist/{context-projection-CCoN8m9W.d.ts → context-projection-C43pyxn2.d.ts} +4 -4
- 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/index.d.ts +1 -1
- package/dist/{message-transcript-Dr6Rk-re.d.ts → message-transcript-CmCHC1Pg.d.ts} +3 -3
- package/dist/{prompt-projector-CGo1TGyZ.d.ts → prompt-projector-_Zxe7dlE.d.ts} +4 -4
- package/dist/{reducer-registry-DqljrD58.d.ts → reducer-registry-BgtK0NuX.d.ts} +2 -2
- package/dist/{run-scheduler-DvHWwWBJ.d.ts → run-scheduler-BBqZ0Ate.d.ts} +2 -2
- package/dist/{run-scheduling-wakeup-CGgJ7RNe.d.ts → run-scheduling-wakeup-DRYZztL6.d.ts} +2 -2
- package/dist/{runtime-j93ZOBnG.d.ts → runtime-CH6Ll_Rv.d.ts} +4 -4
- 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/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 +1 -2
- package/dist/services/session-query.js.map +1 -1
- 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/span-names.d.ts +1 -1
- package/dist/services/span-names.js +3 -0
- package/dist/services/span-names.js.map +1 -1
- package/dist/services/tool-registry.d.ts +1 -1
- package/dist/services/tracing.js +1 -1
- package/dist/services/tracing.js.map +1 -1
- package/dist/{session-query-DYuJXhMQ.d.ts → session-query-CMeJog1g.d.ts} +6 -7
- package/dist/{session-state-13z-3YaF.d.ts → session-state-D4g0kV_K.d.ts} +43 -15
- package/dist/{session-state-xXXyniwU.js → session-state-DtPwg_EP.js} +76 -11
- package/dist/session-state-DtPwg_EP.js.map +1 -0
- package/dist/{session-store-BIr-xfJ7.d.ts → session-store-DCs--1kc.d.ts} +2 -2
- package/dist/{sink-checkpoint-store-Cr9_GmOw.d.ts → sink-checkpoint-store-CasqHvDz.d.ts} +2 -2
- package/dist/{sink-registry-CUIrrkXU.js → sink-registry-B7cG7gxK.js} +153 -121
- package/dist/sink-registry-B7cG7gxK.js.map +1 -0
- package/dist/{sink-registry-C2t3DI_g.d.ts → sink-registry-CAtl5OWV.d.ts} +9 -35
- package/dist/testkit/layers.d.ts +12 -12
- package/dist/testkit/layers.js +2 -2
- package/dist/{tool-registry-Dhs2KmYK.d.ts → tool-registry-CHMtDCJ5.d.ts} +2 -2
- package/package.json +1 -1
- package/dist/session-state-xXXyniwU.js.map +0 -1
- package/dist/sink-registry-CUIrrkXU.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-C43pyxn2.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-DCs--1kc.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-DCs--1kc.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-CasqHvDz.d.ts.map
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { SequenceNumber
|
|
2
|
-
import { dr as turnCompletedEventType, fr as turnFailedEventType, mr as turnStoppedEventType, pr as turnStartedEventType } from "./durable-BPHVFVvV.js";
|
|
1
|
+
import { SequenceNumber } from "./types/core.js";
|
|
3
2
|
import { l as initialReducedState, o as foldReducedState } from "./reduced-state-Bz68V2H8.js";
|
|
4
|
-
import {
|
|
3
|
+
import { EDASessionStore, EDASessionStoreError } from "./services/session-store.js";
|
|
5
4
|
import { IdGenerator } from "./services/id-generator.js";
|
|
6
5
|
import { n as SessionContext, t as EventFactory } from "./event-factory-QuC_UvyP.js";
|
|
7
6
|
import { annotateEdaSpan } from "./services/tracing.js";
|
|
8
7
|
import { EDAKeepAlive } from "./services/keep-alive.js";
|
|
9
|
-
import { SessionEventObserver } from "./services/session-event-observer.js";
|
|
10
8
|
import { EDAReducerRegistry } from "./services/reducer-registry.js";
|
|
11
9
|
import { EDASinkName, SinkCheckpointStore } from "./services/sink-checkpoint-store.js";
|
|
12
10
|
import * as Context from "effect/Context";
|
|
@@ -15,60 +13,71 @@ import * as Layer from "effect/Layer";
|
|
|
15
13
|
import * as Schema from "effect/Schema";
|
|
16
14
|
import * as Stream from "effect/Stream";
|
|
17
15
|
import * as Cause from "effect/Cause";
|
|
16
|
+
import * as Queue from "effect/Queue";
|
|
18
17
|
import * as Ref from "effect/Ref";
|
|
19
18
|
import * as Scope from "effect/Scope";
|
|
20
|
-
import * as
|
|
19
|
+
import * as Semaphore from "effect/Semaphore";
|
|
21
20
|
import * as SynchronizedRef from "effect/SynchronizedRef";
|
|
22
|
-
//#region src/services/
|
|
23
|
-
/**
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
21
|
+
//#region src/services/sink-inbox.ts
|
|
22
|
+
/** Durable payloads stay in the log; only bounded best-effort ephemeral work is retained. */
|
|
23
|
+
const ephemeralCapacity = 128;
|
|
24
|
+
const ephemeralByteCapacity = 256 * 1024;
|
|
25
|
+
/** An ephemeral update could not be measured as a JSON wire value. */
|
|
26
|
+
var SinkEphemeralEncodingError = class extends Schema.TaggedErrorClass()("SinkEphemeralEncodingError", { cause: Schema.Defect() }) {};
|
|
27
|
+
/**
|
|
28
|
+
* Coalesces durable heads without losing ephemeral ordering barriers. Publication never
|
|
29
|
+
* waits for delivery. Overflow drops the newest ephemeral update, never durable work.
|
|
30
|
+
*/
|
|
31
|
+
const makeSinkInbox = Effect.fnUntraced(function* (initialHead) {
|
|
32
|
+
const wake = yield* Effect.acquireRelease(Queue.sliding(1), Queue.shutdown);
|
|
33
|
+
let head = initialHead;
|
|
34
|
+
const pending = [];
|
|
35
|
+
let pendingBytes = 0;
|
|
36
|
+
const notify = (throughSeq) => Effect.sync(() => {
|
|
37
|
+
head = SequenceNumber.make(Math.max(head, throughSeq));
|
|
38
|
+
Queue.offerUnsafe(wake, void 0);
|
|
39
|
+
});
|
|
40
|
+
const offerEphemeral = (event) => Effect.try({
|
|
41
|
+
try: () => {
|
|
42
|
+
const bytes = new TextEncoder().encode(JSON.stringify(event)).byteLength;
|
|
43
|
+
if (pending.length >= ephemeralCapacity || bytes > ephemeralByteCapacity - pendingBytes) return false;
|
|
44
|
+
pending.push({
|
|
45
|
+
event,
|
|
46
|
+
bytes
|
|
47
|
+
});
|
|
48
|
+
pendingBytes += bytes;
|
|
49
|
+
Queue.offerUnsafe(wake, void 0);
|
|
50
|
+
return true;
|
|
51
|
+
},
|
|
52
|
+
catch: (cause) => new SinkEphemeralEncodingError({ cause })
|
|
53
|
+
});
|
|
54
|
+
const poll = (cursor) => Effect.sync(() => {
|
|
55
|
+
while (pending.length > 0) {
|
|
56
|
+
const first = pending[0];
|
|
57
|
+
if (first === void 0) break;
|
|
58
|
+
if (first.event.position.seq > cursor) return {
|
|
59
|
+
_tag: "Durable",
|
|
60
|
+
throughSeq: first.event.position.seq
|
|
61
|
+
};
|
|
62
|
+
pending.shift();
|
|
63
|
+
pendingBytes -= first.bytes;
|
|
64
|
+
if (first.event.position.seq === cursor) return {
|
|
65
|
+
_tag: "Ephemeral",
|
|
66
|
+
event: first.event
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return cursor < head ? {
|
|
70
|
+
_tag: "Durable",
|
|
71
|
+
throughSeq: head
|
|
72
|
+
} : void 0;
|
|
73
|
+
});
|
|
66
74
|
return {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
75
|
+
notify,
|
|
76
|
+
offerEphemeral,
|
|
77
|
+
poll,
|
|
78
|
+
awaitWork: Queue.take(wake)
|
|
70
79
|
};
|
|
71
|
-
};
|
|
80
|
+
});
|
|
72
81
|
//#endregion
|
|
73
82
|
//#region src/services/sink-registry.ts
|
|
74
83
|
/** Convenience constructor preserving a sink's literal name/type information. */
|
|
@@ -88,13 +97,14 @@ const sinkCheckpointFormatVersion = 1;
|
|
|
88
97
|
const makeSinkRegistry = (sinks) => Effect.gen(function* () {
|
|
89
98
|
const session = yield* SessionContext;
|
|
90
99
|
const store = yield* EDASessionStore;
|
|
91
|
-
const liveBus = yield* LiveEventBus;
|
|
92
100
|
const checkpointStore = yield* SinkCheckpointStore;
|
|
93
101
|
const eventFactory = yield* EventFactory;
|
|
94
102
|
const ids = yield* IdGenerator;
|
|
95
103
|
const reducerRegistry = yield* EDAReducerRegistry;
|
|
96
104
|
const keepAlive = yield* EDAKeepAlive;
|
|
97
105
|
const started = yield* Ref.make(false);
|
|
106
|
+
const hydrationGate = yield* Semaphore.make(1);
|
|
107
|
+
const deliveries = [];
|
|
98
108
|
const baseContext = (staged, publishEphemeral, scope, checkpoint) => ({
|
|
99
109
|
sessionId: session.sessionId,
|
|
100
110
|
checkpoint,
|
|
@@ -111,29 +121,50 @@ const makeSinkRegistry = (sinks) => Effect.gen(function* () {
|
|
|
111
121
|
const checkpointRef = yield* SynchronizedRef.make(storedCheckpoint);
|
|
112
122
|
const checkpoint = makeSinkCheckpoint(checkpointStore, sinkName, checkpointRef);
|
|
113
123
|
const cursor = storedCheckpoint.afterSeq;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
reduced: initialReducedState,
|
|
117
|
-
reducerStates: reducerRegistry.initial
|
|
118
|
-
};
|
|
119
|
-
const hydrated = cursor === initialHead ? {
|
|
124
|
+
if (cursor > initialHead) return yield* new EDASessionStoreError({ message: `Sink ${sink.name} cursor exceeds session head` });
|
|
125
|
+
const state = yield* Ref.make(cursor === initialHead ? {
|
|
120
126
|
cursor,
|
|
121
127
|
reduced: initialProjection.reduced,
|
|
122
128
|
reducerStates: initialProjection.reducerStates
|
|
123
|
-
} : cursor
|
|
129
|
+
} : cursor === 0 ? {
|
|
124
130
|
cursor,
|
|
125
|
-
reduced:
|
|
126
|
-
reducerStates: reducerRegistry.
|
|
127
|
-
})
|
|
128
|
-
const
|
|
129
|
-
|
|
131
|
+
reduced: initialReducedState,
|
|
132
|
+
reducerStates: reducerRegistry.initial
|
|
133
|
+
} : void 0);
|
|
134
|
+
const inbox = yield* makeSinkInbox(initialHead).pipe(Scope.provide(scope));
|
|
135
|
+
deliveries.push({
|
|
136
|
+
sink,
|
|
137
|
+
inbox
|
|
138
|
+
});
|
|
139
|
+
const ensureProjection = Effect.fnUntraced(function* () {
|
|
140
|
+
const existing = yield* Ref.get(state);
|
|
141
|
+
if (existing !== void 0) return existing;
|
|
142
|
+
const hydrated = yield* store.eventsAfter(SequenceNumber.make(0)).pipe(Stream.takeWhile((event) => event.position.seq <= cursor), Stream.chunks, Stream.runFold(() => ({
|
|
143
|
+
cursor,
|
|
144
|
+
reduced: initialReducedState,
|
|
145
|
+
reducerStates: reducerRegistry.initial
|
|
146
|
+
}), (current, page) => ({
|
|
147
|
+
cursor,
|
|
148
|
+
reduced: foldReducedState(current.reduced, page),
|
|
149
|
+
reducerStates: reducerRegistry.reduce(current.reducerStates, page)
|
|
150
|
+
})), Effect.withSpan("agent.sink.hydrate", { attributes: {
|
|
151
|
+
"eda.sink.name": sink.name,
|
|
152
|
+
"eda.session.id": session.sessionId,
|
|
153
|
+
"eda.seq.through": cursor
|
|
154
|
+
} }), hydrationGate.withPermits(1));
|
|
155
|
+
if (hydrated.reduced.lastSeq !== cursor) return yield* new EDASessionStoreError({ message: `Sink ${sink.name} could not reconstruct its cursor` });
|
|
156
|
+
yield* Ref.set(state, hydrated);
|
|
157
|
+
return hydrated;
|
|
158
|
+
});
|
|
130
159
|
const processDurableBatch = Effect.fnUntraced(function* (allEvents) {
|
|
131
160
|
if (allEvents.length === 0) return;
|
|
132
|
-
const current = yield*
|
|
161
|
+
const current = yield* ensureProjection();
|
|
133
162
|
const fresh = allEvents.filter((entry) => entry.position.seq > current.cursor);
|
|
134
163
|
if (fresh.length === 0) return;
|
|
135
164
|
const durable = sink.durable;
|
|
136
|
-
const
|
|
165
|
+
const last = fresh.at(-1);
|
|
166
|
+
if (last === void 0) return;
|
|
167
|
+
const throughSeq = last.position.seq;
|
|
137
168
|
const nextReduced = foldReducedState(current.reduced, fresh);
|
|
138
169
|
const nextReducerStates = reducerRegistry.reduce(current.reducerStates, fresh);
|
|
139
170
|
const eventsForSink = durable === void 0 ? [] : filterInterested(fresh, durable.interests);
|
|
@@ -166,63 +197,68 @@ const makeSinkRegistry = (sinks) => Effect.gen(function* () {
|
|
|
166
197
|
reducerStates: nextReducerStates
|
|
167
198
|
});
|
|
168
199
|
});
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if (allEvents.length === 0) return;
|
|
176
|
-
yield* processDurableBatchWithKeepAlive(allEvents);
|
|
177
|
-
}
|
|
200
|
+
const drainDurablesThrough = Effect.fnUntraced(function* (targetHead) {
|
|
201
|
+
const current = yield* ensureProjection();
|
|
202
|
+
if (current.cursor >= targetHead) return;
|
|
203
|
+
const allEvents = yield* readCursorBatchThrough(store, current.cursor, targetHead, sink.durable?.batchSize);
|
|
204
|
+
if (allEvents.length === 0) return yield* new EDASessionStoreError({ message: `Sink ${sink.name} could not read its durable backlog` });
|
|
205
|
+
yield* processDurableBatch(allEvents);
|
|
178
206
|
});
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
if (event.position.seq > afterCatchup.cursor + 1) {
|
|
185
|
-
yield* Effect.logWarning("EDA sink runner could not catch up before live durable", {
|
|
186
|
-
cursor: afterCatchup.cursor,
|
|
187
|
-
eventSeq: event.position.seq,
|
|
188
|
-
sink: sink.name
|
|
189
|
-
});
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
yield* processDurableBatchWithKeepAlive([committedDurableFromPositioned(event)]);
|
|
193
|
-
});
|
|
194
|
-
const processLiveEphemeral = (event) => Effect.gen(function* () {
|
|
195
|
-
const before = yield* Ref.get(state);
|
|
196
|
-
if (event.position.seq < before.cursor) return;
|
|
197
|
-
if (event.position.seq > before.cursor) yield* drainDurablesThrough(event.position.seq);
|
|
198
|
-
const after = yield* Ref.get(state);
|
|
199
|
-
if (event.position.seq !== after.cursor) return;
|
|
200
|
-
if (sink.ephemeral === void 0 || !matchesInterest(event.event.type, sink.ephemeral.interests)) return;
|
|
201
|
-
yield* sink.ephemeral.process(event, baseContext([], publishEphemeral, scope, checkpoint)).pipe(Effect.catchCause((cause) => Effect.logError("EDA sink ephemeral projection failed", {
|
|
202
|
-
cause: String(cause),
|
|
207
|
+
const processEphemeral = Effect.fnUntraced(function* (event) {
|
|
208
|
+
if (sink.ephemeral === void 0) return;
|
|
209
|
+
yield* ensureProjection();
|
|
210
|
+
yield* sink.ephemeral.process(event, baseContext([], publishEphemeral, scope, checkpoint)).pipe(Effect.catchCause((cause) => Cause.hasInterruptsOnly(cause) ? Effect.failCause(cause) : Effect.logError("EDA sink ephemeral projection failed", {
|
|
211
|
+
cause: Cause.pretty(cause),
|
|
203
212
|
sink: sink.name
|
|
204
213
|
})));
|
|
205
214
|
});
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
215
|
+
return {
|
|
216
|
+
runLoop: Effect.forever(Effect.gen(function* () {
|
|
217
|
+
const current = yield* Ref.get(state);
|
|
218
|
+
const work = yield* inbox.poll(current?.cursor ?? cursor);
|
|
219
|
+
if (work === void 0) {
|
|
220
|
+
yield* inbox.awaitWork;
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
yield* keepAlive.withActiveWork(`sink:${sink.name}`, work._tag === "Durable" ? drainDurablesThrough(work.throughSeq) : processEphemeral(work.event));
|
|
224
|
+
yield* Effect.yieldNow;
|
|
225
|
+
})).pipe(Effect.catchCause((cause) => Cause.hasInterruptsOnly(cause) ? Effect.failCause(cause) : Effect.logError("EDA sink runner failed", {
|
|
226
|
+
cause: Cause.pretty(cause),
|
|
227
|
+
sink: sink.name
|
|
228
|
+
}))),
|
|
229
|
+
initialization: cursor === initialHead ? "reused" : cursor > 0 ? "deferred" : "empty"
|
|
230
|
+
};
|
|
216
231
|
});
|
|
217
232
|
return {
|
|
218
233
|
sinks,
|
|
219
234
|
startSinkRunners: Effect.fnUntraced(function* (input) {
|
|
220
235
|
if (yield* Ref.getAndSet(started, true)) return;
|
|
221
|
-
const runners = yield* Effect.
|
|
222
|
-
|
|
236
|
+
const runners = yield* Effect.gen(function* () {
|
|
237
|
+
const runners = yield* Effect.forEach(sinks, (sink) => makeSinkRunner(sink, input), { concurrency: 1 });
|
|
238
|
+
yield* Effect.annotateCurrentSpan({
|
|
239
|
+
"eda.sinks.reused": runners.filter((runner) => runner.initialization === "reused").length,
|
|
240
|
+
"eda.sinks.deferred": runners.filter((runner) => runner.initialization === "deferred").length,
|
|
241
|
+
"eda.sinks.empty": runners.filter((runner) => runner.initialization === "empty").length
|
|
242
|
+
});
|
|
243
|
+
return runners;
|
|
244
|
+
}).pipe(Effect.withSpan("agent.sinks.initialize", { attributes: {
|
|
245
|
+
sessionId: session.sessionId,
|
|
246
|
+
"eda.session.id": session.sessionId,
|
|
247
|
+
"eda.seq.head": input.initialProjection.reduced.lastSeq,
|
|
248
|
+
"eda.sinks.count": sinks.length
|
|
249
|
+
} }));
|
|
250
|
+
yield* Effect.forEach(runners, (runner) => runner.runLoop.pipe(Effect.forkIn(input.scope)), { discard: true });
|
|
223
251
|
}),
|
|
224
|
-
notifyDurableHeadAdvanced: () => Effect.
|
|
225
|
-
publishEphemeralToSinks: () => Effect.
|
|
252
|
+
notifyDurableHeadAdvanced: (head) => Effect.forEach(deliveries, ({ inbox }) => inbox.notify(head), { discard: true }),
|
|
253
|
+
publishEphemeralToSinks: (event) => Effect.forEach(deliveries, ({ sink, inbox }) => {
|
|
254
|
+
if (sink.ephemeral === void 0 || !matchesInterest(event.event.type, sink.ephemeral.interests)) return Effect.void;
|
|
255
|
+
return Effect.gen(function* () {
|
|
256
|
+
if (!(yield* inbox.offerEphemeral(event))) yield* Effect.logWarning("EDA sink ephemeral buffer full", { sink: sink.name });
|
|
257
|
+
}).pipe(Effect.catchTag("SinkEphemeralEncodingError", (error) => Effect.logWarning("EDA sink ephemeral serialization failed", {
|
|
258
|
+
cause: error.cause,
|
|
259
|
+
sink: sink.name
|
|
260
|
+
})));
|
|
261
|
+
}, { discard: true })
|
|
226
262
|
};
|
|
227
263
|
});
|
|
228
264
|
const makeSinkCheckpoint = (store, sinkName, checkpointRef) => ({
|
|
@@ -264,13 +300,9 @@ const encodeSinkState = (schema, state) => Effect.try({
|
|
|
264
300
|
});
|
|
265
301
|
const sinkCheckpointCodecError = (operation, cause) => new EDASessionStoreError({ message: cause instanceof Error ? `${operation} sink checkpoint: ${cause.message}` : `${operation} sink checkpoint: ${String(cause)}` });
|
|
266
302
|
const readCursorBatchThrough = (store, afterSeq, throughSeq, batchSize = defaultBatchSize) => store.eventsAfter(afterSeq).pipe(Stream.takeWhile((event) => event.position.seq <= throughSeq), Stream.take(batchSize), Stream.runCollect, Effect.map((events) => Array.from(events)));
|
|
267
|
-
const committedDurableFromPositioned = (event) => CommittedDurableEvent.make({
|
|
268
|
-
event: event.event,
|
|
269
|
-
position: durablePosition(event.position.seq)
|
|
270
|
-
});
|
|
271
303
|
const filterInterested = (events, interests) => events.filter((event) => matchesInterest(event.event.type, interests));
|
|
272
304
|
const matchesInterest = (type, interests) => interests === void 0 || interests.some((interest) => interest === type);
|
|
273
305
|
//#endregion
|
|
274
|
-
export { EDASinkRegistry as n,
|
|
306
|
+
export { EDASinkRegistry as n, EDASink as t };
|
|
275
307
|
|
|
276
|
-
//# sourceMappingURL=sink-registry-
|
|
308
|
+
//# sourceMappingURL=sink-registry-B7cG7gxK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sink-registry-B7cG7gxK.js","names":[],"sources":["../src/services/sink-inbox.ts","../src/services/sink-registry.ts"],"sourcesContent":["import * as Effect from \"effect/Effect\";\nimport * as Queue from \"effect/Queue\";\nimport * as Schema from \"effect/Schema\";\n\nimport { SequenceNumber } from \"../types/core\";\nimport type { PositionedEvent } from \"../types/events\";\n\n/** Durable payloads stay in the log; only bounded best-effort ephemeral work is retained. */\nconst ephemeralCapacity = 128;\nconst ephemeralByteCapacity = 256 * 1024;\n\n/** An ephemeral update could not be measured as a JSON wire value. */\nexport class SinkEphemeralEncodingError extends Schema.TaggedErrorClass<SinkEphemeralEncodingError>()(\n \"SinkEphemeralEncodingError\",\n { cause: Schema.Defect() },\n) {}\n\n/** One ordered step on a sink's serialized delivery lane. */\ntype SinkWork =\n | { readonly _tag: \"Durable\"; readonly throughSeq: SequenceNumber }\n | { readonly _tag: \"Ephemeral\"; readonly event: PositionedEvent };\n\n/**\n * Coalesces durable heads without losing ephemeral ordering barriers. Publication never\n * waits for delivery. Overflow drops the newest ephemeral update, never durable work.\n */\nexport const makeSinkInbox = Effect.fnUntraced(function* (initialHead: SequenceNumber) {\n const wake = yield* Effect.acquireRelease(Queue.sliding<void>(1), Queue.shutdown);\n let head = initialHead;\n const pending: Array<{ readonly event: PositionedEvent; readonly bytes: number }> = [];\n let pendingBytes = 0;\n\n const notify = (throughSeq: SequenceNumber) =>\n Effect.sync(() => {\n head = SequenceNumber.make(Math.max(head, throughSeq));\n Queue.offerUnsafe(wake, undefined);\n });\n\n const offerEphemeral = (event: PositionedEvent) =>\n Effect.try({\n try: () => {\n const bytes = new TextEncoder().encode(JSON.stringify(event)).byteLength;\n if (pending.length >= ephemeralCapacity || bytes > ephemeralByteCapacity - pendingBytes) {\n return false;\n }\n pending.push({ event, bytes });\n pendingBytes += bytes;\n Queue.offerUnsafe(wake, undefined);\n return true;\n },\n catch: (cause) => new SinkEphemeralEncodingError({ cause }),\n });\n\n const poll = (cursor: SequenceNumber): Effect.Effect<SinkWork | undefined> =>\n Effect.sync(() => {\n while (pending.length > 0) {\n const first = pending[0];\n if (first === undefined) break;\n if (first.event.position.seq > cursor) {\n return { _tag: \"Durable\", throughSeq: first.event.position.seq };\n }\n pending.shift();\n pendingBytes -= first.bytes;\n if (first.event.position.seq === cursor) {\n return { _tag: \"Ephemeral\", event: first.event };\n }\n }\n return cursor < head ? { _tag: \"Durable\", throughSeq: head } : undefined;\n });\n\n return { notify, offerEphemeral, poll, awaitWork: Queue.take(wake) };\n});\n","import * as Cause from \"effect/Cause\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as Ref from \"effect/Ref\";\nimport * as Schema from \"effect/Schema\";\nimport * as Scope from \"effect/Scope\";\nimport * as Semaphore from \"effect/Semaphore\";\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 } from \"../types/core\";\nimport type {\n DurableEventEnvelope,\n EphemeralEventEnvelope,\n EventType,\n PositionedEvent,\n} from \"../types/events\";\nimport type { EDASessionStoreShape } from \"./session-store\";\nimport { type 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 { makeSinkInbox } from \"./sink-inbox\";\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: (event: PositionedEvent) => 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 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 const hydrationGate = yield* Semaphore.make(1);\n const deliveries: Array<{\n readonly sink: EDASink;\n readonly inbox: Effect.Success<ReturnType<typeof makeSinkInbox>>;\n }> = [];\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 if (cursor > initialHead) {\n return yield* new EDASessionStoreError({\n message: `Sink ${sink.name} cursor exceeds session head`,\n });\n }\n // Keep only an exact projection seed; lagging workers reconstruct in their own scope.\n const state = yield* Ref.make<DurableRunnerState | undefined>(\n cursor === initialHead\n ? {\n cursor,\n reduced: initialProjection.reduced,\n reducerStates: initialProjection.reducerStates,\n }\n : cursor === 0\n ? { cursor, reduced: initialReducedState, reducerStates: reducerRegistry.initial }\n : undefined,\n );\n const inbox = yield* makeSinkInbox(initialHead).pipe(Scope.provide(scope));\n deliveries.push({ sink, inbox });\n const ensureProjection = Effect.fnUntraced(function* () {\n const existing = yield* Ref.get(state);\n if (existing !== undefined) return existing;\n const hydrated = yield* store.eventsAfter(SequenceNumber.make(0)).pipe(\n Stream.takeWhile((event) => event.position.seq <= cursor),\n Stream.chunks,\n Stream.runFold(\n (): DurableRunnerState => ({\n cursor,\n reduced: initialReducedState,\n reducerStates: reducerRegistry.initial,\n }),\n (current, page): DurableRunnerState => ({\n cursor,\n reduced: foldReducedState(current.reduced, page),\n reducerStates: reducerRegistry.reduce(current.reducerStates, page),\n }),\n ),\n Effect.withSpan(\"agent.sink.hydrate\", {\n attributes: {\n \"eda.sink.name\": sink.name,\n \"eda.session.id\": session.sessionId,\n \"eda.seq.through\": cursor,\n },\n }),\n hydrationGate.withPermits(1),\n );\n if (hydrated.reduced.lastSeq !== cursor) {\n return yield* new EDASessionStoreError({\n message: `Sink ${sink.name} could not reconstruct its cursor`,\n });\n }\n yield* Ref.set(state, hydrated);\n return hydrated;\n });\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* ensureProjection();\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 last = fresh.at(-1);\n if (last === undefined) return;\n const throughSeq = last.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 drainDurablesThrough = Effect.fnUntraced(function* (targetHead: SequenceNumber) {\n const current = yield* ensureProjection();\n if (current.cursor >= targetHead) return;\n const allEvents = yield* readCursorBatchThrough(\n store,\n current.cursor,\n targetHead,\n sink.durable?.batchSize,\n );\n if (allEvents.length === 0) {\n return yield* new EDASessionStoreError({\n message: `Sink ${sink.name} could not read its durable backlog`,\n });\n }\n yield* processDurableBatch(allEvents);\n });\n\n const processEphemeral = Effect.fnUntraced(function* (event: PositionedEvent) {\n if (sink.ephemeral === undefined) return;\n yield* ensureProjection();\n yield* sink.ephemeral\n .process(event, baseContext([], publishEphemeral, scope, checkpoint))\n .pipe(\n Effect.catchCause((cause) =>\n Cause.hasInterruptsOnly(cause)\n ? Effect.failCause(cause)\n : Effect.logError(\"EDA sink ephemeral projection failed\", {\n cause: Cause.pretty(cause),\n sink: sink.name,\n }),\n ),\n );\n });\n\n const runLoop = Effect.forever(\n Effect.gen(function* () {\n const current = yield* Ref.get(state);\n const work = yield* inbox.poll(current?.cursor ?? cursor);\n if (work === undefined) {\n yield* inbox.awaitWork;\n return;\n }\n yield* keepAlive.withActiveWork(\n `sink:${sink.name}`,\n work._tag === \"Durable\"\n ? drainDurablesThrough(work.throughSeq)\n : processEphemeral(work.event),\n );\n yield* Effect.yieldNow;\n }),\n ).pipe(\n Effect.catchCause((cause) =>\n Cause.hasInterruptsOnly(cause)\n ? Effect.failCause(cause)\n : Effect.logError(\"EDA sink runner failed\", {\n cause: Cause.pretty(cause),\n sink: sink.name,\n }),\n ),\n );\n\n return {\n runLoop,\n initialization: cursor === initialHead ? \"reused\" : cursor > 0 ? \"deferred\" : \"empty\",\n };\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.gen(function* () {\n const runners = yield* Effect.forEach(sinks, (sink) => makeSinkRunner(sink, input), {\n concurrency: 1,\n });\n yield* Effect.annotateCurrentSpan({\n \"eda.sinks.reused\": runners.filter((runner) => runner.initialization === \"reused\")\n .length,\n \"eda.sinks.deferred\": runners.filter((runner) => runner.initialization === \"deferred\")\n .length,\n \"eda.sinks.empty\": runners.filter((runner) => runner.initialization === \"empty\").length,\n });\n return runners;\n }).pipe(\n Effect.withSpan(\"agent.sinks.initialize\", {\n attributes: {\n sessionId: session.sessionId,\n \"eda.session.id\": session.sessionId,\n \"eda.seq.head\": input.initialProjection.reduced.lastSeq,\n \"eda.sinks.count\": sinks.length,\n },\n }),\n );\n // Catch-up can append events. Register every inbox before starting any delivery fiber.\n yield* Effect.forEach(\n runners,\n (runner) => runner.runLoop.pipe(Effect.forkIn(input.scope)),\n {\n discard: true,\n },\n );\n }),\n notifyDurableHeadAdvanced: (head) =>\n Effect.forEach(deliveries, ({ inbox }) => inbox.notify(head), { discard: true }),\n publishEphemeralToSinks: (event) =>\n Effect.forEach(\n deliveries,\n ({ sink, inbox }) => {\n if (\n sink.ephemeral === undefined ||\n !matchesInterest(event.event.type, sink.ephemeral.interests)\n )\n return Effect.void;\n return Effect.gen(function* () {\n const accepted = yield* inbox.offerEphemeral(event);\n if (!accepted) {\n yield* Effect.logWarning(\"EDA sink ephemeral buffer full\", { sink: sink.name });\n }\n }).pipe(\n Effect.catchTag(\"SinkEphemeralEncodingError\", (error) =>\n Effect.logWarning(\"EDA sink ephemeral serialization failed\", {\n cause: error.cause,\n sink: sink.name,\n }),\n ),\n );\n },\n { discard: true },\n ),\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 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":";;;;;;;;;;;;;;;;;;;;;;AAQA,MAAM,oBAAoB;AAC1B,MAAM,wBAAwB,MAAM;;AAGpC,IAAa,6BAAb,cAAgD,OAAO,iBAA6C,EAClG,8BACA,EAAE,OAAO,OAAO,OAAO,EAAE,CAC3B,EAAE,CAAC;;;;;AAWH,MAAa,gBAAgB,OAAO,WAAW,WAAW,aAA6B;CACrF,MAAM,OAAO,OAAO,OAAO,eAAe,MAAM,QAAc,CAAC,GAAG,MAAM,QAAQ;CAChF,IAAI,OAAO;CACX,MAAM,UAA8E,CAAC;CACrF,IAAI,eAAe;CAEnB,MAAM,UAAU,eACd,OAAO,WAAW;EAChB,OAAO,eAAe,KAAK,KAAK,IAAI,MAAM,UAAU,CAAC;EACrD,MAAM,YAAY,MAAM,KAAA,CAAS;CACnC,CAAC;CAEH,MAAM,kBAAkB,UACtB,OAAO,IAAI;EACT,WAAW;GACT,MAAM,QAAQ,IAAI,YAAY,EAAE,OAAO,KAAK,UAAU,KAAK,CAAC,EAAE;GAC9D,IAAI,QAAQ,UAAU,qBAAqB,QAAQ,wBAAwB,cACzE,OAAO;GAET,QAAQ,KAAK;IAAE;IAAO;GAAM,CAAC;GAC7B,gBAAgB;GAChB,MAAM,YAAY,MAAM,KAAA,CAAS;GACjC,OAAO;EACT;EACA,QAAQ,UAAU,IAAI,2BAA2B,EAAE,MAAM,CAAC;CAC5D,CAAC;CAEH,MAAM,QAAQ,WACZ,OAAO,WAAW;EAChB,OAAO,QAAQ,SAAS,GAAG;GACzB,MAAM,QAAQ,QAAQ;GACtB,IAAI,UAAU,KAAA,GAAW;GACzB,IAAI,MAAM,MAAM,SAAS,MAAM,QAC7B,OAAO;IAAE,MAAM;IAAW,YAAY,MAAM,MAAM,SAAS;GAAI;GAEjE,QAAQ,MAAM;GACd,gBAA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CACA,SAAS,WAAW;AACtB,CACF,CAAU,CACZ,CACF;AAEF,MAAM,uBAAuB,YAAsD;CACjF,IACE,OAAO,YAAY,YACnB,YAAY,QACZ,EAAE,mBAAmB,YACrB,QAAQ,kBAAkB,+BAC1B,EAAE,WAAW,YACb,EAAE,iBAAiB,YACnB,OAAO,QAAQ,gBAAgB,UAE/B;CAEF,OAAO;EACL,eAAe;EACf,OAAO,QAAQ;EACf,aAAa,QAAQ;CACvB;AACF;AAEA,MAAM,mBACJ,QACA,YAEA,OAAO,IAAI;CACT,WAAW,OAAO,kBAAkB,MAAM,EAAE,OAAO;CACnD,QAAQ,UAAU,yBAAyB,YAAY,KAAK;AAC9D,CAAC;AAEH,MAAM,mBACJ,QACA,UAEA,OAAO,IAAI;CACT,WAAW,OAAO,kBAAkB,MAAM,EAAE,KAAK;CACjD,QAAQ,UAAU,yBAAyB,YAAY,KAAK;AAC9D,CAAC;AAEH,MAAM,4BAA4B,WAAmB,UACnD,IAAI,qBAAqB,EACvB,SACE,iBAAiB,QACb,GAAG,UAAU,oBAAoB,MAAM,YACvC,GAAG,UAAU,oBAAoB,OAAO,KAAK,IACrD,CAAC;AAEH,MAAM,0BACJ,OACA,UACA,YACA,YAAY,qBAEZ,MAAM,YAAY,QAAQ,EAAE,KAC1B,OAAO,WAAW,UAAU,MAAM,SAAS,OAAO,UAAU,GAC5D,OAAO,KAAK,SAAS,GACrB,OAAO,YACP,OAAO,KAAK,WAAW,MAAM,KAAK,MAAM,CAAC,CAC3C;AAEF,MAAM,oBACJ,QACA,cAEA,OAAO,QAAQ,UAAU,gBAAgB,MAAM,MAAM,MAAM,SAAS,CAAC;AAEvE,MAAM,mBACJ,MACA,cACY,cAAc,KAAA,KAAa,UAAU,MAAM,aAAa,aAAa,IAAI"}
|
|
@@ -1,44 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { S as ReducedState } from "./command-queues-
|
|
1
|
+
import { c as EventId, g as SessionId, h as SequenceNumber } from "./core-C-6xHzRx.js";
|
|
2
|
+
import { S as ReducedState } from "./command-queues-CSEl1yrH.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-DCs--1kc.js";
|
|
5
5
|
import { t as IdGenerator } from "./id-generator--x6itQZ2.js";
|
|
6
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
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { n as SinkCheckpointStore } from "./sink-checkpoint-store-Cr9_GmOw.js";
|
|
8
|
+
import { a as EDAReducerStateSnapshot, r as EDAReducerRegistry } from "./reducer-registry-BgtK0NuX.js";
|
|
9
|
+
import { n as SinkCheckpointStore } from "./sink-checkpoint-store-CasqHvDz.js";
|
|
11
10
|
import * as Context from "effect/Context";
|
|
12
11
|
import * as Effect from "effect/Effect";
|
|
13
12
|
import * as Layer from "effect/Layer";
|
|
14
13
|
import * as Schema from "effect/Schema";
|
|
15
|
-
import * as Stream from "effect/Stream";
|
|
16
14
|
import * as Scope from "effect/Scope";
|
|
17
|
-
import * as PubSub from "effect/PubSub";
|
|
18
15
|
|
|
19
|
-
//#region src/services/live-event-bus.d.ts
|
|
20
|
-
/** Live-only replay buffer for the currently open turn. */
|
|
21
|
-
interface ActiveTurnEphemeralReplay {
|
|
22
|
-
readonly turnId?: TurnId;
|
|
23
|
-
readonly events: ReadonlyArray<PositionedEvent>;
|
|
24
|
-
readonly overflowed: boolean;
|
|
25
|
-
}
|
|
26
|
-
/** In-memory live fanout plus active-turn replay source for reconnect streams. */
|
|
27
|
-
interface LiveEventBusShape {
|
|
28
|
-
readonly publish: (event: PositionedEvent) => Effect.Effect<boolean>;
|
|
29
|
-
readonly subscribe: () => Effect.Effect<Stream.Stream<PositionedEvent>, never, Scope.Scope>;
|
|
30
|
-
readonly subscribeQueue: () => Effect.Effect<PubSub.Subscription<PositionedEvent>, never, Scope.Scope>;
|
|
31
|
-
/** Snapshot raw live-only events retained for the currently open turn. */
|
|
32
|
-
readonly activeTurnReplay: () => Effect.Effect<ActiveTurnEphemeralReplay>;
|
|
33
|
-
}
|
|
34
|
-
declare const LiveEventBus_base: Context.ServiceClass<LiveEventBus, "@effect-durable-agent/LiveEventBus", LiveEventBusShape>;
|
|
35
|
-
/** Unbounded in-memory fanout plus bounded active-turn ephemeral replay. */
|
|
36
|
-
declare class LiveEventBus extends LiveEventBus_base {
|
|
37
|
-
static readonly Live: Layer.Layer<LiveEventBus, never, SessionEventObserver>;
|
|
38
|
-
/** Live bus for hosts that do not install an append-driven observer. */
|
|
39
|
-
static readonly Noop: Layer.Layer<LiveEventBus, never, never>;
|
|
40
|
-
}
|
|
41
|
-
//#endregion
|
|
42
16
|
//#region src/services/sink-registry.d.ts
|
|
43
17
|
/** Cursor-window input delivered to one durable sink drain. */
|
|
44
18
|
interface EDASinkDurableBatch {
|
|
@@ -124,14 +98,14 @@ interface EDASinkRegistryShape {
|
|
|
124
98
|
/** Coalesced non-blocking nudge that the durable log head advanced. */
|
|
125
99
|
readonly notifyDurableHeadAdvanced: (head: SequenceNumber) => Effect.Effect<void>;
|
|
126
100
|
/** Best-effort non-blocking delivery to ephemeral sink workers. */
|
|
127
|
-
readonly publishEphemeralToSinks: (event: PositionedEvent
|
|
101
|
+
readonly publishEphemeralToSinks: (event: PositionedEvent) => Effect.Effect<void>;
|
|
128
102
|
}
|
|
129
103
|
declare const EDASinkRegistry_base: Context.ServiceClass<EDASinkRegistry, "@effect-durable-agent/EDASinkRegistry", EDASinkRegistryShape>;
|
|
130
104
|
/** Registry and runner for app-provided EDA sinks. */
|
|
131
105
|
declare class EDASinkRegistry extends EDASinkRegistry_base {
|
|
132
106
|
static readonly Empty: Layer.Layer<EDASinkRegistry, never, never>;
|
|
133
|
-
static readonly Live: (sinks: ReadonlyArray<EDASink>) => Layer.Layer<EDASinkRegistry, never,
|
|
107
|
+
static readonly Live: (sinks: ReadonlyArray<EDASink>) => Layer.Layer<EDASinkRegistry, never, EDASessionStore | IdGenerator | EDAKeepAlive | SinkCheckpointStore | EDAReducerRegistry | SessionContext | EventFactory>;
|
|
134
108
|
}
|
|
135
109
|
//#endregion
|
|
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
|
|
137
|
-
//# sourceMappingURL=sink-registry-
|
|
110
|
+
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 };
|
|
111
|
+
//# sourceMappingURL=sink-registry-CAtl5OWV.d.ts.map
|
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-DCs--1kc.js";
|
|
4
4
|
import { t as ModelResolver } from "../model-resolver-BPPJAsuh.js";
|
|
5
5
|
import { t as IdGenerator } from "../id-generator--x6itQZ2.js";
|
|
6
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 {
|
|
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 {
|
|
14
|
-
import { t as
|
|
15
|
-
import {
|
|
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-DYAlYxx5.js";
|
|
9
|
+
import { C as LiveEventBus, S as ToolExecutor, b as InferenceRunner, h as SessionState, x as InferenceRunnerStreamPart, y as TurnRunner } from "../session-state-D4g0kV_K.js";
|
|
10
|
+
import { r as EDAReducerRegistry, t as EDAReducer } from "../reducer-registry-BgtK0NuX.js";
|
|
11
|
+
import { r as EDAPromptProjector } from "../prompt-projector-_Zxe7dlE.js";
|
|
12
|
+
import { n as SinkCheckpointStore } from "../sink-checkpoint-store-CasqHvDz.js";
|
|
13
|
+
import { r as EDASink, s as EDASinkRegistry } from "../sink-registry-CAtl5OWV.js";
|
|
14
|
+
import { t as RunScheduler } from "../run-scheduler-BBqZ0Ate.js";
|
|
15
|
+
import { t as RunSchedulingWakeup } from "../run-scheduling-wakeup-DRYZztL6.js";
|
|
16
|
+
import { a as ToolParamsSchema, r as EDAToolRegistry, t as EDAModelToolkit } from "../tool-registry-CHMtDCJ5.js";
|
|
17
|
+
import { n as EDASessionQuery } from "../session-query-CMeJog1g.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<RunScheduler |
|
|
108
|
+
declare const makeEdaTestLayer: (options: EdaTestLayerOptions) => Layer.Layer<RunScheduler | EDASessionQuery | SessionState | EDASessionStore | LiveEventBus | RunSchedulingWakeup | ModelResolver | IdGenerator | EDAKeepAlive | EDAToolRegistry | SinkCheckpointStore | EDAReducerRegistry | CompactionExecutor | CompactionPolicy | EDAPromptProjector | EDASinkRegistry | SessionContext | EventFactory | CompactionRunner | TurnRunner | InferenceRunner | ToolExecutor, 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,15 +2,15 @@ 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, m as LiveEventBus, p as ToolExecutor, u as SessionState } from "../session-state-DtPwg_EP.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-CUIrrkXU.js";
|
|
12
11
|
import { EDAPromptProjector } from "../services/prompt-projector.js";
|
|
13
12
|
import { EDAReducerRegistry } from "../services/reducer-registry.js";
|
|
13
|
+
import { n as EDASinkRegistry } from "../sink-registry-B7cG7gxK.js";
|
|
14
14
|
import { SinkCheckpointStore } from "../services/sink-checkpoint-store.js";
|
|
15
15
|
import { EDAToolRegistry } from "../services/tool-registry.js";
|
|
16
16
|
import { EDASessionQuery } from "../services/session-query.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-DCs--1kc.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-CHMtDCJ5.d.ts.map
|