effect-durable-agent 0.1.0-alpha.8 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/README.md +5 -5
  2. package/dist/assert-never-CoyUpoRB.js +18 -0
  3. package/dist/assert-never-CoyUpoRB.js.map +1 -0
  4. package/dist/{commands-Ce1ec6kH.d.ts → commands-BUquEZVP.d.ts} +31 -12
  5. package/dist/{compaction-BgDr5VJy.js → compaction-63iEDHHl.js} +63 -13
  6. package/dist/compaction-63iEDHHl.js.map +1 -0
  7. package/dist/{context-projection-n6Rdup0N.d.ts → context-projection-Bezx3drD.d.ts} +16 -40
  8. package/dist/{core-CYT6DBaS.d.ts → core-BcimKMIv.d.ts} +5 -3
  9. package/dist/delivery-2ZILvoRD.js +507 -0
  10. package/dist/delivery-2ZILvoRD.js.map +1 -0
  11. package/dist/delivery-D3MxW4wg.d.ts +3026 -0
  12. package/dist/domain/command-queues.d.ts +81 -2
  13. package/dist/domain/command-queues.js +1 -1
  14. package/dist/domain/command-queues.js.map +1 -1
  15. package/dist/domain/context-projection.d.ts +1 -1
  16. package/dist/domain/context-projection.js +1 -1
  17. package/dist/domain/context-projection.js.map +1 -1
  18. package/dist/domain/message-transcript.d.ts +36 -2
  19. package/dist/domain/message-transcript.js +10 -2
  20. package/dist/domain/message-transcript.js.map +1 -1
  21. package/dist/domain/model-usage.d.ts +1 -1
  22. package/dist/domain/model-usage.js +1 -1
  23. package/dist/domain/reduced-state-schema.d.ts +3 -992
  24. package/dist/domain/reduced-state-schema.js +126 -7
  25. package/dist/domain/reduced-state-schema.js.map +1 -1
  26. package/dist/domain/reduced-state.d.ts +2 -2
  27. package/dist/domain/reduced-state.js +936 -2
  28. package/dist/domain/reduced-state.js.map +1 -0
  29. package/dist/domain/run-scheduling.d.ts +2 -0
  30. package/dist/domain/run-scheduling.js +127 -0
  31. package/dist/domain/run-scheduling.js.map +1 -0
  32. package/dist/{durable-br2C1bWK.d.ts → durable-168Womqp.d.ts} +8535 -2859
  33. package/dist/{durable-BGFvX7Mh.js → durable-D13w1Qr3.js} +229 -15
  34. package/dist/durable-D13w1Qr3.js.map +1 -0
  35. package/dist/{envelope-DxQzo5rN.js → envelope-BCzKUq_z.js} +12 -3
  36. package/dist/envelope-BCzKUq_z.js.map +1 -0
  37. package/dist/{envelope-DkZyMIgp.d.ts → envelope-Che6KatU.d.ts} +70 -7
  38. package/dist/{event-factory-DTFdy0Cb.js → event-factory-_vF1bIJ7.js} +7 -3
  39. package/dist/event-factory-_vF1bIJ7.js.map +1 -0
  40. package/dist/{events-LZFNoESe.d.ts → events-DwTARLMv.d.ts} +139 -137
  41. package/dist/{id-generator-Ckl8_XWW.d.ts → id-generator-BKGoKjt-.d.ts} +3 -3
  42. package/dist/in-memory-CeODnZhE.js +150 -0
  43. package/dist/in-memory-CeODnZhE.js.map +1 -0
  44. package/dist/index.d.ts +8 -8
  45. package/dist/index.js +6 -6
  46. package/dist/interpreter-DKGJ1sSx.js +1452 -0
  47. package/dist/interpreter-DKGJ1sSx.js.map +1 -0
  48. package/dist/{keep-alive-Chl5SJxy.d.ts → keep-alive-_zFCUvt3.d.ts} +1 -2
  49. package/dist/{model-resolver-BPPJAsuh.d.ts → model-resolver-DeBDK8XO.d.ts} +11 -5
  50. package/dist/{model-usage-CdBEkTwU.d.ts → model-usage-0GeHwaaU.d.ts} +2 -3
  51. package/dist/records--54mZEBx.js +675 -0
  52. package/dist/records--54mZEBx.js.map +1 -0
  53. package/dist/reduced-state-B1cvy8N_.d.ts +51110 -0
  54. package/dist/reduced-state-schema-B98exWxQ.d.ts +2338 -0
  55. package/dist/{reducer-registry-aFjz_ZLT.d.ts → reducer-registry-DhGVzHBV.d.ts} +12 -6
  56. package/dist/run-scheduling-wakeup-Mjic4tb_.d.ts +24 -0
  57. package/dist/services/compaction.d.ts +2 -2
  58. package/dist/services/compaction.js +2 -2
  59. package/dist/services/id-generator.d.ts +1 -1
  60. package/dist/services/id-generator.js +6 -12
  61. package/dist/services/id-generator.js.map +1 -1
  62. package/dist/services/keep-alive.d.ts +1 -1
  63. package/dist/services/keep-alive.js.map +1 -1
  64. package/dist/services/model-call.d.ts +15 -0
  65. package/dist/services/model-call.js +15 -0
  66. package/dist/services/model-call.js.map +1 -0
  67. package/dist/services/model-resolver.d.ts +1 -1
  68. package/dist/services/model-resolver.js +1 -1
  69. package/dist/services/model-resolver.js.map +1 -1
  70. package/dist/services/prompt-projector.d.ts +2 -2
  71. package/dist/services/prompt-projector.js +49 -5
  72. package/dist/services/prompt-projector.js.map +1 -1
  73. package/dist/services/reducer-registry.d.ts +1 -1
  74. package/dist/services/reducer-registry.js +19 -6
  75. package/dist/services/reducer-registry.js.map +1 -1
  76. package/dist/services/run-scheduler.d.ts +2 -0
  77. package/dist/services/run-scheduler.js +25 -0
  78. package/dist/services/run-scheduler.js.map +1 -0
  79. package/dist/services/run-scheduling-wakeup.d.ts +2 -0
  80. package/dist/services/run-scheduling-wakeup.js +13 -0
  81. package/dist/services/run-scheduling-wakeup.js.map +1 -0
  82. package/dist/services/runtime-layer.d.ts +18 -31
  83. package/dist/services/runtime-layer.js +19 -13
  84. package/dist/services/runtime-layer.js.map +1 -1
  85. package/dist/services/runtime.d.ts +1 -1
  86. package/dist/services/runtime.js +31 -20
  87. package/dist/services/runtime.js.map +1 -1
  88. package/dist/services/session-event-observer.d.ts +1 -1
  89. package/dist/services/session-event-observer.js.map +1 -1
  90. package/dist/services/session-query.d.ts +1 -1
  91. package/dist/services/session-query.js +57 -10
  92. package/dist/services/session-query.js.map +1 -1
  93. package/dist/services/session-state.d.ts +1 -1
  94. package/dist/services/session-state.js +1 -1
  95. package/dist/services/session-store.d.ts +2 -2
  96. package/dist/services/session-store.js +127 -37
  97. package/dist/services/session-store.js.map +1 -1
  98. package/dist/services/sink-checkpoint-store.d.ts +1 -1
  99. package/dist/services/sink-checkpoint-store.js +2 -1
  100. package/dist/services/sink-checkpoint-store.js.map +1 -1
  101. package/dist/services/sink-registry.d.ts +2 -2
  102. package/dist/services/sink-registry.js +1 -1
  103. package/dist/services/span-names.d.ts +1 -1
  104. package/dist/services/span-names.js +6 -1
  105. package/dist/services/span-names.js.map +1 -1
  106. package/dist/services/tool-registry.d.ts +2 -2
  107. package/dist/services/tool-registry.js +12 -3
  108. package/dist/services/tool-registry.js.map +1 -1
  109. package/dist/services/tracing.d.ts +3 -3
  110. package/dist/services/tracing.js +2 -2
  111. package/dist/services/tracing.js.map +1 -1
  112. package/dist/{session-event-observer-DaFMKKNc.d.ts → session-event-observer-DlP9ITB2.d.ts} +3 -3
  113. package/dist/{session-state-aIqe9CLa.js → session-state-BehvUVyq.js} +669 -160
  114. package/dist/session-state-BehvUVyq.js.map +1 -0
  115. package/dist/session-store-BL6sfrnn.d.ts +3326 -0
  116. package/dist/{sink-checkpoint-store-M7qIxoSH.d.ts → sink-checkpoint-store-DvuHwvx_.d.ts} +3 -4
  117. package/dist/sink-registry-DskRcyOS.js +345 -0
  118. package/dist/sink-registry-DskRcyOS.js.map +1 -0
  119. package/dist/subscription-DZNWFDTV.d.ts +966 -0
  120. package/dist/subscription-DmO3BcdT.js +505 -0
  121. package/dist/subscription-DmO3BcdT.js.map +1 -0
  122. package/dist/testkit/layers.d.ts +31 -22
  123. package/dist/testkit/layers.js +23 -14
  124. package/dist/testkit/layers.js.map +1 -1
  125. package/dist/testkit/transcript.d.ts +226 -0
  126. package/dist/testkit/transcript.js +1475 -0
  127. package/dist/testkit/transcript.js.map +1 -0
  128. package/dist/{tool-registry-BJaVNtw4.d.ts → tool-registry-CHHUU9BN.d.ts} +44 -8
  129. package/dist/{tracing-BXHAkxkx.d.ts → tracing-BwjbF285.d.ts} +1 -2
  130. package/dist/transcript.d.ts +101 -0
  131. package/dist/transcript.js +107 -0
  132. package/dist/transcript.js.map +1 -0
  133. package/dist/types/commands.d.ts +2 -2
  134. package/dist/types/commands.js +8 -3
  135. package/dist/types/commands.js.map +1 -1
  136. package/dist/types/core.d.ts +2 -2
  137. package/dist/types/core.js +3 -1
  138. package/dist/types/core.js.map +1 -1
  139. package/dist/types/events/durable.d.ts +2 -2
  140. package/dist/types/events/durable.js +2 -2
  141. package/dist/types/events.d.ts +5 -5
  142. package/dist/types/events.js +3 -3
  143. package/dist/types/tracing.d.ts +1 -1
  144. package/dist/types/tracing.js.map +1 -1
  145. package/dist/websocket/events.d.ts +2 -0
  146. package/dist/websocket/events.js +2 -0
  147. package/dist/websocket.d.ts +2123 -2552
  148. package/dist/websocket.js +628 -442
  149. package/dist/websocket.js.map +1 -1
  150. package/dist/window-read-Brov9VdQ.d.ts +113 -0
  151. package/dist/window-read-DPFAA1hM.js +264 -0
  152. package/dist/window-read-DPFAA1hM.js.map +1 -0
  153. package/package.json +42 -14
  154. package/dist/command-queues-DdDB_aYM.d.ts +0 -462
  155. package/dist/compaction-BEor3jKv.d.ts +0 -165
  156. package/dist/compaction-BgDr5VJy.js.map +0 -1
  157. package/dist/durable-BGFvX7Mh.js.map +0 -1
  158. package/dist/envelope-DxQzo5rN.js.map +0 -1
  159. package/dist/event-factory-DTFdy0Cb.js.map +0 -1
  160. package/dist/event-factory-pFzsPlDs.d.ts +0 -87
  161. package/dist/index-BVVgDSdq.d.ts +0 -1
  162. package/dist/message-transcript-DQNlzxle.d.ts +0 -32
  163. package/dist/prompt-projector-f4ElyXCE.d.ts +0 -39
  164. package/dist/reduced-state-DF0-6mbR.js +0 -921
  165. package/dist/reduced-state-DF0-6mbR.js.map +0 -1
  166. package/dist/runtime-DbTCb32-.d.ts +0 -63
  167. package/dist/session-query-l8xpJYp8.d.ts +0 -45
  168. package/dist/session-state-YHFzOGDf.d.ts +0 -861
  169. package/dist/session-state-aIqe9CLa.js.map +0 -1
  170. package/dist/session-store-Cpi_NwTR.d.ts +0 -206
  171. package/dist/sink-registry-NDgeyzO0.js +0 -272
  172. package/dist/sink-registry-NDgeyzO0.js.map +0 -1
  173. package/dist/sink-registry-T1wOUuzq.d.ts +0 -133
@@ -1,206 +0,0 @@
1
- import { t as DurableEventEnvelope } from "./envelope-DkZyMIgp.js";
2
- import { _ as SummaryId, h as SessionId, m as SequenceNumber, n as CommandId } from "./core-CYT6DBaS.js";
3
- import { n as CommandIdempotencyKey } from "./commands-Ce1ec6kH.js";
4
- import { r as CompactionSummaryArtifact } from "./context-projection-n6Rdup0N.js";
5
- import * as Context from "effect/Context";
6
- import * as Effect from "effect/Effect";
7
- import * as Layer from "effect/Layer";
8
- import * as Schema from "effect/Schema";
9
- import * as Stream from "effect/Stream";
10
- import * as Cause from "effect/Cause";
11
-
12
- //#region src/services/session-store.d.ts
13
- /** A durable event after the store has assigned its replay position. */
14
- declare const CommittedDurableEvent: Schema.Struct<{
15
- readonly position: Schema.Struct<{
16
- readonly seq: Schema.brand<Schema.Int, "SequenceNumber">;
17
- readonly subSeq: Schema.brand<Schema.Literal<0>, "SubSequenceNumber">;
18
- }>;
19
- readonly event: Schema.Struct<{
20
- readonly durability: Schema.Literal<"durable">;
21
- readonly namespace: Schema.NonEmptyString;
22
- readonly type: Schema.NonEmptyString;
23
- readonly schemaVersion: Schema.Int;
24
- readonly eventId: Schema.brand<Schema.String, "EventId">;
25
- readonly sessionId: Schema.brand<Schema.String, "SessionId">;
26
- readonly correlationId: Schema.optionalKey<Schema.brand<Schema.String, "CorrelationId">>;
27
- readonly createdAtMs: Schema.brand<Schema.Int, "UnixEpochMillis">;
28
- readonly trace: Schema.withConstructorDefault<Schema.Struct<{
29
- readonly span: Schema.Struct<{
30
- readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
31
- readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
32
- readonly sampled: Schema.Boolean;
33
- readonly tracestate: Schema.NullOr<Schema.String>;
34
- }>;
35
- readonly links: Schema.$Array<Schema.Struct<{
36
- readonly context: Schema.Struct<{
37
- readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
38
- readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
39
- readonly sampled: Schema.Boolean;
40
- readonly tracestate: Schema.NullOr<Schema.String>;
41
- }>;
42
- readonly attributes: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean]>>;
43
- }>>;
44
- }>>;
45
- readonly payload: Schema.Unknown;
46
- }>;
47
- }>;
48
- type CommittedDurableEvent = typeof CommittedDurableEvent.Type;
49
- declare const EDASessionStoreError_base: Schema.Class<EDASessionStoreError, Schema.TaggedStruct<"EDASessionStoreError", {
50
- readonly message: Schema.String;
51
- }>, Cause.YieldableError>;
52
- /**
53
- * Store-level failure surfaced by durable append, replay, and hydration APIs.
54
- *
55
- * The error intentionally stays storage-semantic rather than SQL-specific so
56
- * framework services can treat SQL-backed hosts, in-memory tests, and future adapters
57
- * as the same durability boundary.
58
- */
59
- declare class EDASessionStoreError extends EDASessionStoreError_base {}
60
- /** True when a Cause contains an escaped durable-store failure. */
61
- declare const hasEDASessionStoreError: (cause: Cause.Cause<unknown>) => boolean;
62
- /**
63
- * One logical event to persist in the durable session log.
64
- *
65
- * Store adapters may split large logical payload fields into sidecar rows after
66
- * the event insert assigns `seq`, but callers still provide one fat event.
67
- */
68
- declare const DurableAppendEntry: Schema.Struct<{
69
- readonly event: Schema.Struct<{
70
- readonly durability: Schema.Literal<"durable">;
71
- readonly namespace: Schema.NonEmptyString;
72
- readonly type: Schema.NonEmptyString;
73
- readonly schemaVersion: Schema.Int;
74
- readonly eventId: Schema.brand<Schema.String, "EventId">;
75
- readonly sessionId: Schema.brand<Schema.String, "SessionId">;
76
- readonly correlationId: Schema.optionalKey<Schema.brand<Schema.String, "CorrelationId">>;
77
- readonly createdAtMs: Schema.brand<Schema.Int, "UnixEpochMillis">;
78
- readonly trace: Schema.withConstructorDefault<Schema.Struct<{
79
- readonly span: Schema.Struct<{
80
- readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
81
- readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
82
- readonly sampled: Schema.Boolean;
83
- readonly tracestate: Schema.NullOr<Schema.String>;
84
- }>;
85
- readonly links: Schema.$Array<Schema.Struct<{
86
- readonly context: Schema.Struct<{
87
- readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
88
- readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
89
- readonly sampled: Schema.Boolean;
90
- readonly tracestate: Schema.NullOr<Schema.String>;
91
- }>;
92
- readonly attributes: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean]>>;
93
- }>>;
94
- }>>;
95
- readonly payload: Schema.Unknown;
96
- }>;
97
- }>;
98
- type DurableAppendEntry = typeof DurableAppendEntry.Type;
99
- /**
100
- * Ordered durable append intent. Adapters assign positions in entry order.
101
- *
102
- * This is the single write shape exposed to framework services. It avoids raw
103
- * SQL and public transaction callbacks while still expressing the full atomic
104
- * transition EDA needs for events, normalized bodies, and metadata.
105
- */
106
- declare const DurableAppendBatch: Schema.Struct<{
107
- readonly entries: Schema.$Array<Schema.Struct<{
108
- readonly event: Schema.Struct<{
109
- readonly durability: Schema.Literal<"durable">;
110
- readonly namespace: Schema.NonEmptyString;
111
- readonly type: Schema.NonEmptyString;
112
- readonly schemaVersion: Schema.Int;
113
- readonly eventId: Schema.brand<Schema.String, "EventId">;
114
- readonly sessionId: Schema.brand<Schema.String, "SessionId">;
115
- readonly correlationId: Schema.optionalKey<Schema.brand<Schema.String, "CorrelationId">>;
116
- readonly createdAtMs: Schema.brand<Schema.Int, "UnixEpochMillis">;
117
- readonly trace: Schema.withConstructorDefault<Schema.Struct<{
118
- readonly span: Schema.Struct<{
119
- readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
120
- readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
121
- readonly sampled: Schema.Boolean;
122
- readonly tracestate: Schema.NullOr<Schema.String>;
123
- }>;
124
- readonly links: Schema.$Array<Schema.Struct<{
125
- readonly context: Schema.Struct<{
126
- readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
127
- readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
128
- readonly sampled: Schema.Boolean;
129
- readonly tracestate: Schema.NullOr<Schema.String>;
130
- }>;
131
- readonly attributes: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean]>>;
132
- }>>;
133
- }>>;
134
- readonly payload: Schema.Unknown;
135
- }>;
136
- }>>;
137
- }>;
138
- type DurableAppendBatch = typeof DurableAppendBatch.Type;
139
- /** Durable reducer checkpoint row used to hydrate framework and app projections cheaply. */
140
- interface EDAReducerCheckpoint {
141
- readonly name: string;
142
- readonly schemaVersion: number;
143
- readonly throughSeq: SequenceNumber;
144
- readonly payload: unknown;
145
- readonly updatedAtMs: number;
146
- }
147
- /** Input for writing one durable reducer checkpoint. */
148
- interface SaveReducerCheckpointInput {
149
- readonly name: string;
150
- readonly schemaVersion: number;
151
- readonly throughSeq: SequenceNumber;
152
- readonly payload: unknown;
153
- readonly updatedAtMs: number;
154
- }
155
- /** Indexed command-admission lookup used for idempotent ingress. */
156
- declare const FindCommandAdmissionInput: Schema.Struct<{
157
- readonly commandId: Schema.optionalKey<Schema.brand<Schema.String, "CommandId">>;
158
- readonly idempotencyKey: Schema.optionalKey<Schema.String>;
159
- }>;
160
- /** Typed command-admission lookup accepted by the semantic store port. */
161
- interface FindCommandAdmissionInput {
162
- readonly commandId?: CommandId;
163
- readonly idempotencyKey?: CommandIdempotencyKey;
164
- }
165
- /** Semantic durable store contract for one EDA session. */
166
- interface EDASessionStoreShape {
167
- /**
168
- * Append durable logical events atomically, preserving input order.
169
- *
170
- * Implementations must be idempotent by `eventId`: duplicates return the
171
- * original committed position and do not advance the durable head. Live publish
172
- * remains outside the store and is owned by `SessionState` after this succeeds.
173
- */
174
- readonly append: (batch: DurableAppendBatch) => Effect.Effect<ReadonlyArray<CommittedDurableEvent>, EDASessionStoreError>;
175
- /** Replay committed durable events with `seq > afterSeq`. */
176
- readonly eventsAfter: (afterSeq: SequenceNumber) => Stream.Stream<CommittedDurableEvent, EDASessionStoreError>;
177
- /** Load committed durable events by exact sequence number for checkpoint pointer hydration. */
178
- readonly loadCommittedEventsBySeq: (seqs: ReadonlyArray<SequenceNumber>) => Effect.Effect<ReadonlyArray<CommittedDurableEvent>, EDASessionStoreError>;
179
- /** Lookup an admitted command without replaying the full journal. */
180
- readonly findCommandAdmission: (input: FindCommandAdmissionInput) => Effect.Effect<CommittedDurableEvent | undefined, EDASessionStoreError>;
181
- /** Load one compacted summary artifact body by id, if it has been saved. */
182
- readonly loadSummaryArtifact: (summaryId: SummaryId) => Effect.Effect<CompactionSummaryArtifact | undefined, EDASessionStoreError>;
183
- /** Load one framework or app reducer checkpoint, if it has been saved. */
184
- readonly loadReducerCheckpoint: (name: string) => Effect.Effect<EDAReducerCheckpoint | undefined, EDASessionStoreError>;
185
- /** Persist one framework or app reducer checkpoint as a derived cache. */
186
- readonly saveReducerCheckpoint: (checkpoint: SaveReducerCheckpointInput) => Effect.Effect<void, EDASessionStoreError>;
187
- /** Persist a reducer checkpoint snapshot atomically across framework and app reducers. */
188
- readonly saveReducerCheckpoints: (checkpoints: ReadonlyArray<SaveReducerCheckpointInput>) => Effect.Effect<void, EDASessionStoreError>;
189
- }
190
- declare const EDASessionStore_base: Context.ServiceClass<EDASessionStore, "@effect-durable-agent/EDASessionStore", EDASessionStoreShape>;
191
- /**
192
- * SQL-agnostic durable storage port for one EDA session.
193
- *
194
- * Framework services depend on this semantic port rather than raw SQL. Host
195
- * adapters own physical tables and synchronous transaction mechanics; callers
196
- * only express durable append/replay/lookup intent.
197
- */
198
- declare class EDASessionStore extends EDASessionStore_base {
199
- /** Deterministic in-memory implementation used by runtime and recovery tests. */
200
- static readonly InMemory: (sessionId: SessionId) => Layer.Layer<EDASessionStore, never, never>;
201
- /** In-memory store seeded with a durable prefix; intended for recovery tests. */
202
- static readonly InMemorySeeded: (sessionId: SessionId, events: ReadonlyArray<DurableEventEnvelope>) => Layer.Layer<EDASessionStore, never, never>;
203
- }
204
- //#endregion
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-Cpi_NwTR.d.ts.map
@@ -1,272 +0,0 @@
1
- import { SequenceNumber, durablePosition } from "./types/core.js";
2
- import { $n as turnFailedEventType, Qn as turnCompletedEventType, er as turnStartedEventType, tr as turnStoppedEventType } from "./durable-BGFvX7Mh.js";
3
- import { f as reduceCommittedEvents, o as foldReducedState } from "./reduced-state-DF0-6mbR.js";
4
- import { CommittedDurableEvent, EDASessionStore, EDASessionStoreError } from "./services/session-store.js";
5
- import { IdGenerator } from "./services/id-generator.js";
6
- import { n as SessionContext, t as EventFactory } from "./event-factory-DTFdy0Cb.js";
7
- import { annotateEdaSpan } from "./services/tracing.js";
8
- import { EDAKeepAlive } from "./services/keep-alive.js";
9
- import { SessionEventObserver } from "./services/session-event-observer.js";
10
- import { EDAReducerRegistry } from "./services/reducer-registry.js";
11
- import { EDASinkName, SinkCheckpointStore } from "./services/sink-checkpoint-store.js";
12
- import * as Context from "effect/Context";
13
- import * as Effect from "effect/Effect";
14
- import * as Layer from "effect/Layer";
15
- import * as Schema from "effect/Schema";
16
- import * as Stream from "effect/Stream";
17
- import * as Cause from "effect/Cause";
18
- import * as Ref from "effect/Ref";
19
- import * as Scope from "effect/Scope";
20
- import * as PubSub from "effect/PubSub";
21
- import * as SynchronizedRef from "effect/SynchronizedRef";
22
- //#region src/services/live-event-bus.ts
23
- /** Conservative raw-delta cap for one open turn's live-only reconnect replay. */
24
- const activeTurnEphemeralReplayCapacity = 4096;
25
- /** Unbounded in-memory fanout plus bounded active-turn ephemeral replay. */
26
- var LiveEventBus = class LiveEventBus extends Context.Service()("@effect-durable-agent/LiveEventBus") {
27
- static Live = Layer.effect(LiveEventBus, Effect.gen(function* () {
28
- return makeLiveBus(yield* Effect.acquireRelease(PubSub.unbounded(), PubSub.shutdown), yield* Ref.make({
29
- events: [],
30
- overflowed: false
31
- }), yield* SessionEventObserver);
32
- }));
33
- /** Live bus for hosts that do not install an append-driven observer. */
34
- static Noop = LiveEventBus.Live.pipe(Layer.provide(SessionEventObserver.Noop));
35
- };
36
- const makeLiveBus = (pubsub, activeTurnReplay, observer) => ({
37
- publish: (event) => Effect.gen(function* () {
38
- yield* updateActiveTurnReplay(activeTurnReplay, event);
39
- yield* observer.onEvent(event);
40
- return yield* PubSub.publish(pubsub, event);
41
- }),
42
- subscribeQueue: () => PubSub.subscribe(pubsub),
43
- subscribe: () => Effect.map(PubSub.subscribe(pubsub), (subscription) => Stream.fromEffectRepeat(PubSub.take(subscription))),
44
- activeTurnReplay: () => Ref.get(activeTurnReplay)
45
- });
46
- const updateActiveTurnReplay = (ref, event) => Ref.update(ref, (state) => nextActiveTurnReplay(state, event));
47
- const nextActiveTurnReplay = (state, event) => {
48
- if (event.event.type === turnStartedEventType) return {
49
- turnId: event.event.payload.turnId,
50
- events: [],
51
- overflowed: false
52
- };
53
- if (event.event.type === turnCompletedEventType || event.event.type === turnFailedEventType || event.event.type === turnStoppedEventType) {
54
- const turnId = event.event.payload.turnId;
55
- return turnId === void 0 || state.turnId === void 0 || turnId === state.turnId ? {
56
- events: [],
57
- overflowed: false
58
- } : state;
59
- }
60
- if (event.event.durability !== "ephemeral" || state.turnId === void 0) return state;
61
- const events = [...state.events, event];
62
- if (events.length <= 4096) return {
63
- ...state,
64
- events
65
- };
66
- return {
67
- ...state,
68
- events: events.slice(events.length - activeTurnEphemeralReplayCapacity),
69
- overflowed: true
70
- };
71
- };
72
- //#endregion
73
- //#region src/services/sink-registry.ts
74
- /** Convenience constructor preserving a sink's literal name/type information. */
75
- const EDASink = { make: (sink) => sink };
76
- /** Registry and runner for app-provided EDA sinks. */
77
- var EDASinkRegistry = class EDASinkRegistry extends Context.Service()("@effect-durable-agent/EDASinkRegistry") {
78
- static Empty = Layer.succeed(EDASinkRegistry, {
79
- sinks: [],
80
- startSinkRunners: () => Effect.void,
81
- notifyDurableHeadAdvanced: () => Effect.void,
82
- publishEphemeralToSinks: () => Effect.void
83
- });
84
- static Live = (sinks) => Layer.effect(EDASinkRegistry, makeSinkRegistry(sinks));
85
- };
86
- const defaultBatchSize = 100;
87
- const sinkCheckpointFormatVersion = 1;
88
- const makeSinkRegistry = (sinks) => Effect.gen(function* () {
89
- const session = yield* SessionContext;
90
- const store = yield* EDASessionStore;
91
- const liveBus = yield* LiveEventBus;
92
- const checkpointStore = yield* SinkCheckpointStore;
93
- const eventFactory = yield* EventFactory;
94
- const ids = yield* IdGenerator;
95
- const reducerRegistry = yield* EDAReducerRegistry;
96
- const keepAlive = yield* EDAKeepAlive;
97
- const started = yield* Ref.make(false);
98
- const baseContext = (staged, publishEphemeral, scope, checkpoint) => ({
99
- sessionId: session.sessionId,
100
- checkpoint,
101
- events: eventFactory,
102
- makeEventId: ids.makeEventId,
103
- emitEphemeral: publishEphemeral,
104
- stageDurable: (event) => Effect.sync(() => staged.push(event)),
105
- forkScoped: (effect) => effect.pipe(Effect.forkIn(scope), Effect.asVoid)
106
- });
107
- const makeSinkRunner = (sink, input) => Effect.gen(function* () {
108
- const sinkName = EDASinkName.make(sink.name);
109
- const storedCheckpoint = yield* checkpointStore.load(sinkName);
110
- const checkpointRef = yield* SynchronizedRef.make(storedCheckpoint);
111
- const checkpoint = makeSinkCheckpoint(checkpointStore, sinkName, checkpointRef);
112
- const cursor = storedCheckpoint.afterSeq;
113
- const prefix = yield* readDurablePrefixThrough(store, cursor);
114
- const state = yield* Ref.make({
115
- cursor,
116
- reduced: reduceCommittedEvents(prefix),
117
- reducerStates: reducerRegistry.reduce(reducerRegistry.initial, prefix)
118
- });
119
- const live = yield* liveBus.subscribeQueue().pipe(Scope.provide(input.scope));
120
- const processDurableBatch = Effect.fnUntraced(function* (allEvents) {
121
- if (allEvents.length === 0) return;
122
- const current = yield* Ref.get(state);
123
- const fresh = allEvents.filter((entry) => entry.position.seq > current.cursor);
124
- if (fresh.length === 0) return;
125
- const durable = sink.durable;
126
- const throughSeq = fresh.at(-1).position.seq;
127
- const nextReduced = foldReducedState(current.reduced, fresh);
128
- const nextReducerStates = reducerRegistry.reduce(current.reducerStates, fresh);
129
- const eventsForSink = durable === void 0 ? [] : filterInterested(fresh, durable.interests);
130
- if (durable !== void 0 && eventsForSink.length > 0) yield* Effect.gen(function* () {
131
- const staged = [];
132
- if ((yield* durable.process({
133
- allEvents: fresh,
134
- events: eventsForSink,
135
- stateAfter: nextReduced,
136
- reducerStates: nextReducerStates,
137
- throughSeq
138
- }, baseContext(staged, input.publishEphemeral, input.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
- cause: Cause.pretty(cause),
140
- sink: sink.name
141
- }).pipe(Effect.as(false))))) && staged.length > 0) {
142
- yield* annotateEdaSpan({ "eda.sink.staged_events": staged.length });
143
- yield* input.appendDurableBatch(staged);
144
- }
145
- }).pipe(Effect.withSpan("agent.sink.drain", { attributes: {
146
- "eda.sink.name": sink.name,
147
- "eda.sink.cursor.before": current.cursor,
148
- "eda.sink.events.read": fresh.length,
149
- "eda.sink.events.interested": eventsForSink.length,
150
- "eda.sink.cursor.after": throughSeq
151
- } }));
152
- yield* commitSinkCheckpoint(checkpointStore, sinkName, checkpointRef, throughSeq);
153
- yield* Ref.set(state, {
154
- cursor: throughSeq,
155
- reduced: nextReduced,
156
- reducerStates: nextReducerStates
157
- });
158
- });
159
- const processDurableBatchWithKeepAlive = (events) => keepAlive.withActiveWork(`sink:${sink.name}`, processDurableBatch(events));
160
- const drainDurablesThrough = (targetHead) => Effect.gen(function* () {
161
- while (true) {
162
- const current = yield* Ref.get(state);
163
- if (current.cursor >= targetHead) return;
164
- const allEvents = yield* readCursorBatchThrough(store, current.cursor, targetHead, sink.durable?.batchSize);
165
- if (allEvents.length === 0) return;
166
- yield* processDurableBatchWithKeepAlive(allEvents);
167
- }
168
- });
169
- const processLiveDurable = (event) => Effect.gen(function* () {
170
- const current = yield* Ref.get(state);
171
- if (event.position.seq <= current.cursor) return;
172
- if (event.position.seq > current.cursor + 1) yield* drainDurablesThrough(SequenceNumber.make(event.position.seq - 1));
173
- const afterCatchup = yield* Ref.get(state);
174
- if (event.position.seq > afterCatchup.cursor + 1) {
175
- yield* Effect.logWarning("EDA sink runner could not catch up before live durable", {
176
- cursor: afterCatchup.cursor,
177
- eventSeq: event.position.seq,
178
- sink: sink.name
179
- });
180
- return;
181
- }
182
- yield* processDurableBatchWithKeepAlive([committedDurableFromPositioned(event)]);
183
- });
184
- const processLiveEphemeral = (event) => Effect.gen(function* () {
185
- const before = yield* Ref.get(state);
186
- if (event.position.seq < before.cursor) return;
187
- if (event.position.seq > before.cursor) yield* drainDurablesThrough(event.position.seq);
188
- const after = yield* Ref.get(state);
189
- if (event.position.seq !== after.cursor) return;
190
- if (sink.ephemeral === void 0 || !matchesInterest(event.event.type, sink.ephemeral.interests)) return;
191
- yield* sink.ephemeral.process(event, baseContext([], input.publishEphemeral, input.scope, checkpoint)).pipe(Effect.catchCause((cause) => Effect.logError("EDA sink ephemeral projection failed", {
192
- cause: String(cause),
193
- sink: sink.name
194
- })));
195
- });
196
- const processLiveEvent = (event) => event.event.durability === "durable" ? processLiveDurable(event) : processLiveEphemeral(event);
197
- yield* Effect.gen(function* () {
198
- yield* drainDurablesThrough(input.initialHead);
199
- return yield* Effect.forever(Effect.gen(function* () {
200
- yield* processLiveEvent(yield* PubSub.take(live));
201
- }));
202
- }).pipe(Effect.catchCause((cause) => Effect.logError("EDA sink runner failed", {
203
- cause: Cause.pretty(cause),
204
- sink: sink.name
205
- }))).pipe(Effect.forkIn(input.scope));
206
- });
207
- return {
208
- sinks,
209
- startSinkRunners: Effect.fnUntraced(function* (input) {
210
- if (yield* Ref.getAndSet(started, true)) return;
211
- yield* Effect.forEach(sinks, (sink) => makeSinkRunner(sink, input), {
212
- discard: true,
213
- concurrency: "unbounded"
214
- });
215
- }),
216
- notifyDurableHeadAdvanced: () => Effect.void,
217
- publishEphemeralToSinks: () => Effect.void
218
- };
219
- });
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
- const makeSinkCheckpoint = (store, sinkName, checkpointRef) => ({
225
- get: (schema, initial) => SynchronizedRef.get(checkpointRef).pipe(Effect.flatMap((checkpoint) => {
226
- const serialized = serializedSinkState(checkpoint.payload);
227
- return serialized === void 0 ? Effect.succeed(initial) : decodeSinkState(schema, serialized.state);
228
- })),
229
- save: (schema, state) => encodeSinkState(schema, state).pipe(Effect.flatMap((encoded) => {
230
- const payload = {
231
- formatVersion: sinkCheckpointFormatVersion,
232
- state: encoded,
233
- updatedAtMs: Date.now()
234
- };
235
- return SynchronizedRef.modifyEffect(checkpointRef, (checkpoint) => store.saveState(sinkName, payload).pipe(Effect.as([void 0, {
236
- afterSeq: checkpoint.afterSeq,
237
- payload
238
- }])));
239
- }))
240
- });
241
- const commitSinkCheckpoint = (store, sinkName, checkpointRef, afterSeq) => SynchronizedRef.modifyEffect(checkpointRef, (checkpoint) => store.commit(sinkName, afterSeq, checkpoint.payload).pipe(Effect.as([void 0, {
242
- afterSeq,
243
- payload: checkpoint.payload
244
- }])));
245
- const serializedSinkState = (payload) => {
246
- if (typeof payload !== "object" || payload === null || !("formatVersion" in payload) || payload.formatVersion !== sinkCheckpointFormatVersion || !("state" in payload) || !("updatedAtMs" in payload) || typeof payload.updatedAtMs !== "number") return;
247
- return {
248
- formatVersion: sinkCheckpointFormatVersion,
249
- state: payload.state,
250
- updatedAtMs: payload.updatedAtMs
251
- };
252
- };
253
- const decodeSinkState = (schema, encoded) => Effect.try({
254
- try: () => Schema.decodeUnknownSync(schema)(encoded),
255
- catch: (cause) => sinkCheckpointCodecError("decoding", cause)
256
- });
257
- const encodeSinkState = (schema, state) => Effect.try({
258
- try: () => Schema.encodeUnknownSync(schema)(state),
259
- catch: (cause) => sinkCheckpointCodecError("encoding", cause)
260
- });
261
- const sinkCheckpointCodecError = (operation, cause) => new EDASessionStoreError({ message: cause instanceof Error ? `${operation} sink checkpoint: ${cause.message}` : `${operation} sink checkpoint: ${String(cause)}` });
262
- 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)));
263
- const committedDurableFromPositioned = (event) => CommittedDurableEvent.make({
264
- event: event.event,
265
- position: durablePosition(event.position.seq)
266
- });
267
- const filterInterested = (events, interests) => events.filter((event) => matchesInterest(event.event.type, interests));
268
- const matchesInterest = (type, interests) => interests === void 0 || interests.some((interest) => interest === type);
269
- //#endregion
270
- export { EDASinkRegistry as n, LiveEventBus as r, EDASink as t };
271
-
272
- //# sourceMappingURL=sink-registry-NDgeyzO0.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sink-registry-NDgeyzO0.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,OAC3B,cACA,OAAO,IAAI,aAAa;EAUtB,OAAO,YAAY,OATG,OAAO,eAC3B,OAAO,UAA2B,GAClC,OAAO,QACT,GAM2B,OALK,IAAI,KAAgC;GAClE,QAAQ,CAAC;GACT,YAAY;EACd,CAAC,GAE4C,OADrB,oBAC6B;CACvD,CAAC,CACH;;CAGA,OAAgB,OAAO,aAAa,KAAK,KAAK,MAAM,QAAQ,qBAAqB,IAAI,CAAC;AACxF;AAEA,MAAM,eACJ,QACA,kBACA,cACuB;CACvB,UAAU,UACR,OAAO,IAAI,aAAa;EACtB,OAAO,uBAAuB,kBAAkB,KAAK;EACrD,OAAO,SAAS,QAAQ,KAAK;EAC7B,OAAO,OAAO,OAAO,QAAQ,QAAQ,KAAK;CAC5C,CAAC;CACH,sBAAsB,OAAO,UAAU,MAAM;CAC7C,iBACE,OAAO,IAAI,OAAO,UAAU,MAAM,IAAI,iBACpC,OAAO,iBAAiB,OAAO,KAAK,YAAY,CAAC,CACnD;CACF,wBAAwB,IAAI,IAAI,gBAAgB;AAClD;AAEA,MAAM,0BACJ,KACA,UACwB,IAAI,OAAO,MAAM,UAAU,qBAAqB,OAAO,KAAK,CAAC;AAEvF,MAAM,wBACJ,OACA,UAC8B;CAC9B,IAAI,MAAM,MAAM,SAAS,sBACvB,OAAO;EACL,QAAS,MAAM,MAAM,QAAwC;EAC7D,QAAQ,CAAC;EACT,YAAY;CACd;CAGF,IACE,MAAM,MAAM,SAAS,0BACrB,MAAM,MAAM,SAAS,uBACrB,MAAM,MAAM,SAAS,sBACrB;EACA,MAAM,SAAU,MAAM,MAAM,QAAyC;EACrE,OAAO,WAAW,KAAA,KAA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