effect-durable-agent 0.1.0-alpha.1 → 0.1.0-alpha.10

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 (183) hide show
  1. package/README.md +140 -136
  2. package/dist/{command-queues-CQ9cwRP7.d.ts → command-queues-CQi4Xc7u.d.ts} +109 -21
  3. package/dist/{commands-Ce1ec6kH.d.ts → commands-p8venTWs.d.ts} +10 -2
  4. package/dist/compaction-0k8zCJgB.js +473 -0
  5. package/dist/compaction-0k8zCJgB.js.map +1 -0
  6. package/dist/{compaction-YayFKo_1.d.ts → compaction-BhLSSXJ-.d.ts} +28 -7
  7. package/dist/context-projection-mCuvcO2W.d.ts +140 -0
  8. package/dist/{core-Hv3cFydL.d.ts → core-C-6xHzRx.d.ts} +6 -3
  9. package/dist/domain/command-queues.d.ts +1 -1
  10. package/dist/domain/command-queues.js +1 -1
  11. package/dist/domain/command-queues.js.map +1 -1
  12. package/dist/domain/context-projection.d.ts +2 -0
  13. package/dist/domain/context-projection.js +32 -0
  14. package/dist/domain/context-projection.js.map +1 -0
  15. package/dist/domain/message-transcript.d.ts +1 -1
  16. package/dist/domain/model-usage.d.ts +2 -0
  17. package/dist/domain/model-usage.js +59 -0
  18. package/dist/domain/model-usage.js.map +1 -0
  19. package/dist/domain/reduced-state-schema.d.ts +14 -18
  20. package/dist/domain/reduced-state-schema.js +7 -11
  21. package/dist/domain/reduced-state-schema.js.map +1 -1
  22. package/dist/domain/reduced-state.d.ts +3 -2
  23. package/dist/domain/reduced-state.js +3 -2
  24. package/dist/domain/run-scheduling.d.ts +2 -0
  25. package/dist/domain/run-scheduling.js +127 -0
  26. package/dist/domain/run-scheduling.js.map +1 -0
  27. package/dist/{durable-C3Rz7kg3.js → durable-BPHVFVvV.js} +74 -83
  28. package/dist/durable-BPHVFVvV.js.map +1 -0
  29. package/dist/{durable-DlScwmCy.d.ts → durable-DeLCAvbw.d.ts} +1256 -104
  30. package/dist/envelope-DkZyMIgp.d.ts +191 -0
  31. package/dist/envelope-DxQzo5rN.js +82 -0
  32. package/dist/envelope-DxQzo5rN.js.map +1 -0
  33. package/dist/{keep-alive-DYDsH6qN.d.ts → event-factory-KaeDSfeP.d.ts} +11 -31
  34. package/dist/{keep-alive-p8dIcSVy.js → event-factory-QuC_UvyP.js} +8 -10
  35. package/dist/event-factory-QuC_UvyP.js.map +1 -0
  36. package/dist/{events-Bb9-Cu-7.d.ts → events-LZFNoESe.d.ts} +2 -188
  37. package/dist/{id-generator-C2Q15uZM.d.ts → id-generator--x6itQZ2.d.ts} +3 -2
  38. package/dist/index.d.ts +7 -6
  39. package/dist/index.js +5 -4
  40. package/dist/keep-alive-Chl5SJxy.d.ts +29 -0
  41. package/dist/{message-transcript-BCHdHAe2.d.ts → message-transcript-6PEzaEGn.d.ts} +4 -4
  42. package/dist/model-resolver-BPPJAsuh.d.ts +18 -0
  43. package/dist/model-usage-CdBEkTwU.d.ts +55 -0
  44. package/dist/{prompt-projector-9_02lk5-.d.ts → prompt-projector-CNhqUsEr.d.ts} +15 -16
  45. package/dist/{reduced-state-C4nVVzz9.js → reduced-state-Bz68V2H8.js} +65 -32
  46. package/dist/reduced-state-Bz68V2H8.js.map +1 -0
  47. package/dist/{reducer-registry-C0svUa63.d.ts → reducer-registry-CCSzc4h8.d.ts} +16 -6
  48. package/dist/run-scheduler-DcS_okUH.d.ts +43 -0
  49. package/dist/run-scheduling-wakeup-CeHrvXie.d.ts +25 -0
  50. package/dist/{runtime-C56FQxiL.d.ts → runtime-WL_gKqxn.d.ts} +16 -7
  51. package/dist/services/compaction.d.ts +1 -1
  52. package/dist/services/compaction.js +1 -425
  53. package/dist/services/id-generator.d.ts +1 -1
  54. package/dist/services/id-generator.js +2 -1
  55. package/dist/services/id-generator.js.map +1 -1
  56. package/dist/services/keep-alive.d.ts +2 -0
  57. package/dist/services/keep-alive.js +13 -0
  58. package/dist/services/keep-alive.js.map +1 -0
  59. package/dist/services/model-resolver.d.ts +2 -0
  60. package/dist/services/model-resolver.js +17 -0
  61. package/dist/services/model-resolver.js.map +1 -0
  62. package/dist/services/prompt-projector.d.ts +2 -2
  63. package/dist/services/prompt-projector.js +20 -10
  64. package/dist/services/prompt-projector.js.map +1 -1
  65. package/dist/services/reducer-registry.d.ts +2 -2
  66. package/dist/services/reducer-registry.js +7 -3
  67. package/dist/services/reducer-registry.js.map +1 -1
  68. package/dist/services/run-scheduler.d.ts +3 -0
  69. package/dist/services/run-scheduler.js +25 -0
  70. package/dist/services/run-scheduler.js.map +1 -0
  71. package/dist/services/run-scheduling-wakeup.d.ts +2 -0
  72. package/dist/services/run-scheduling-wakeup.js +13 -0
  73. package/dist/services/run-scheduling-wakeup.js.map +1 -0
  74. package/dist/services/runtime-layer.d.ts +67 -0
  75. package/dist/services/runtime-layer.js +47 -0
  76. package/dist/services/runtime-layer.js.map +1 -0
  77. package/dist/services/runtime.d.ts +1 -1
  78. package/dist/services/runtime.js +21 -14
  79. package/dist/services/runtime.js.map +1 -1
  80. package/dist/services/session-event-observer.d.ts +2 -0
  81. package/dist/services/session-event-observer.js +13 -0
  82. package/dist/services/session-event-observer.js.map +1 -0
  83. package/dist/services/session-query.d.ts +2 -2
  84. package/dist/services/session-query.js +140 -1
  85. package/dist/services/session-query.js.map +1 -0
  86. package/dist/services/session-state.d.ts +2 -0
  87. package/dist/services/session-state.js +2 -0
  88. package/dist/services/session-store.d.ts +2 -2
  89. package/dist/services/session-store.js +182 -2
  90. package/dist/services/session-store.js.map +1 -0
  91. package/dist/services/sink-checkpoint-store.d.ts +2 -0
  92. package/dist/services/sink-checkpoint-store.js +49 -0
  93. package/dist/services/sink-checkpoint-store.js.map +1 -0
  94. package/dist/services/sink-registry.d.ts +1 -1
  95. package/dist/services/sink-registry.js +1 -1
  96. package/dist/services/span-names.d.ts +1 -1
  97. package/dist/services/span-names.js +3 -0
  98. package/dist/services/span-names.js.map +1 -1
  99. package/dist/services/tool-registry.d.ts +1 -1
  100. package/dist/services/tracing.d.ts +1 -1
  101. package/dist/services/tracing.js +23 -2
  102. package/dist/services/tracing.js.map +1 -1
  103. package/dist/session-event-observer-DaFMKKNc.d.ts +24 -0
  104. package/dist/session-query-DfW_4KC0.d.ts +47 -0
  105. package/dist/{session-query-DOc1KanA.js → session-state-BIZ2SYaP.js} +350 -183
  106. package/dist/session-state-BIZ2SYaP.js.map +1 -0
  107. package/dist/{session-query-DlRo5Ufc.d.ts → session-state-BeR2rZRR.d.ts} +144 -46
  108. package/dist/{session-store-D2Ore1QC.d.ts → session-store-J_Un45kW.d.ts} +7 -96
  109. package/dist/sink-checkpoint-store-C9hUxfH0.d.ts +40 -0
  110. package/dist/{sink-registry-CFC6xjsN.js → sink-registry-Bbqhtdnx.js} +27 -67
  111. package/dist/sink-registry-Bbqhtdnx.js.map +1 -0
  112. package/dist/{sink-registry-CIU0LD3m.d.ts → sink-registry-DuDkNXjZ.d.ts} +24 -49
  113. package/dist/testkit/layers.d.ts +24 -14
  114. package/dist/testkit/layers.js +18 -11
  115. package/dist/testkit/layers.js.map +1 -1
  116. package/dist/{tool-registry-CcnkAAQK.d.ts → tool-registry-BDmJe_Wr.d.ts} +4 -4
  117. package/dist/types/commands.d.ts +2 -2
  118. package/dist/types/commands.js +7 -2
  119. package/dist/types/commands.js.map +1 -1
  120. package/dist/types/core.d.ts +2 -2
  121. package/dist/types/core.js +4 -2
  122. package/dist/types/core.js.map +1 -1
  123. package/dist/types/events/durable.d.ts +2 -2
  124. package/dist/types/events/durable.js +2 -2
  125. package/dist/types/events.d.ts +4 -3
  126. package/dist/types/events.js +3 -2
  127. package/dist/types/events.js.map +1 -1
  128. package/dist/websocket.d.ts +2776 -0
  129. package/dist/websocket.js +498 -0
  130. package/dist/websocket.js.map +1 -0
  131. package/package.json +68 -43
  132. package/testing/offline-trace/README.md +2 -1
  133. package/CHANGELOG.md +0 -10
  134. package/CONTRIBUTING.md +0 -26
  135. package/SECURITY.md +0 -8
  136. package/dist/durable-C3Rz7kg3.js.map +0 -1
  137. package/dist/durable-object-runtime-B7jwBY2R.js +0 -1494
  138. package/dist/durable-object-runtime-B7jwBY2R.js.map +0 -1
  139. package/dist/durable-object-runtime-pWv0ohlz.d.ts +0 -257
  140. package/dist/durable-object-storage-Czy7IPrh.d.ts +0 -41
  141. package/dist/host/durable-object-runtime.d.ts +0 -2
  142. package/dist/host/durable-object-runtime.js +0 -2
  143. package/dist/host/durable-object-storage.d.ts +0 -2
  144. package/dist/host/durable-object-storage.js +0 -0
  145. package/dist/host/durable-object.d.ts +0 -83
  146. package/dist/host/durable-object.js +0 -191
  147. package/dist/host/durable-object.js.map +0 -1
  148. package/dist/host/websocket-wire.d.ts +0 -2
  149. package/dist/host/websocket-wire.js +0 -88
  150. package/dist/host/websocket-wire.js.map +0 -1
  151. package/dist/keep-alive-p8dIcSVy.js.map +0 -1
  152. package/dist/reduced-state-C4nVVzz9.js.map +0 -1
  153. package/dist/services/compaction.js.map +0 -1
  154. package/dist/session-query-DOc1KanA.js.map +0 -1
  155. package/dist/session-store-pYxQW9qh.js +0 -214
  156. package/dist/session-store-pYxQW9qh.js.map +0 -1
  157. package/dist/sink-registry-CFC6xjsN.js.map +0 -1
  158. package/dist/websocket-wire-DvOu_6BJ.d.ts +0 -16773
  159. package/docs/assets/architecture.svg +0 -106
  160. package/docs/assets/event-sequence.svg +0 -143
  161. package/docs/assets/gcp-trace.png +0 -0
  162. package/docs/message-steering.md +0 -831
  163. package/docs/releasing.md +0 -57
  164. package/docs/spec.md +0 -774
  165. package/docs/subagents.md +0 -725
  166. package/docs/testing.md +0 -64
  167. package/docs/ui-projection.md +0 -742
  168. package/docs/websocket-protocol.md +0 -613
  169. package/examples/001-no-tools/README.md +0 -65
  170. package/examples/001-no-tools/worker.ts +0 -79
  171. package/examples/002-slack-bridge/README.md +0 -134
  172. package/examples/002-slack-bridge/events.ts +0 -115
  173. package/examples/002-slack-bridge/reducer.ts +0 -216
  174. package/examples/002-slack-bridge/scenario.test.ts +0 -223
  175. package/examples/002-slack-bridge/sinks.ts +0 -109
  176. package/examples/002-slack-bridge/worker.ts +0 -140
  177. package/examples/003-sandbox-lifecycle/README.md +0 -78
  178. package/examples/003-sandbox-lifecycle/events.ts +0 -203
  179. package/examples/003-sandbox-lifecycle/reducer.ts +0 -305
  180. package/examples/003-sandbox-lifecycle/scenario.test.ts +0 -202
  181. package/examples/_shared/event-id.ts +0 -12
  182. package/examples/_shared/http.ts +0 -27
  183. package/examples/_shared/openai.ts +0 -33
@@ -1,26 +1,25 @@
1
- import { m as SequenceNumber } from "./core-Hv3cFydL.js";
2
- import { r as EDACommand } from "./commands-Ce1ec6kH.js";
3
- import { D as DurableEventEnvelope, F as ModelSelectionPayload, I as NonNegativeInt, L as PositionedEvent, O as EphemeralEventEnvelope } from "./events-Bb9-Cu-7.js";
4
- import { Dt as ToolCallCreatedEvent } from "./durable-DlScwmCy.js";
5
- import { a as EDASessionStore, o as EDASessionStoreError, t as CommittedDurableEvent } from "./session-store-D2Ore1QC.js";
6
- import { S as ReducedState } from "./command-queues-CQ9cwRP7.js";
7
- import { t as DurableTranscriptMessage } from "./message-transcript-BCHdHAe2.js";
8
- import { i as EDAReducerStateSnapshot, n as EDAReducerRegistry } from "./reducer-registry-C0svUa63.js";
9
- import { d as LiveEventBus, s as EDASinkRegistry } from "./sink-registry-CIU0LD3m.js";
10
- import { t as IdGenerator } from "./id-generator-C2Q15uZM.js";
11
- import { i as SessionContext, n as EventFactory, t as EDAKeepAlive } from "./keep-alive-DYDsH6qN.js";
12
- import { d as CompactionRunner } from "./compaction-YayFKo_1.js";
13
- import { n as EDAPromptProjector } from "./prompt-projector-9_02lk5-.js";
14
- import { r as EDAToolRegistry } from "./tool-registry-CcnkAAQK.js";
1
+ import { Q as RunGrantResult, S as ReducedState } from "./command-queues-CQi4Xc7u.js";
2
+ import { d as PositionedEvent, l as ModelSelectionPayload, n as EphemeralEventEnvelope, t as DurableEventEnvelope, u as NonNegativeInt } from "./envelope-DkZyMIgp.js";
3
+ import { i as GrantRunCommand, r as EDACommand } from "./commands-p8venTWs.js";
4
+ import { zt as ToolCallCreatedEvent } from "./durable-DeLCAvbw.js";
5
+ import { a as EDASessionStore, o as EDASessionStoreError, t as CommittedDurableEvent } from "./session-store-J_Un45kW.js";
6
+ import { t as ModelResolver } from "./model-resolver-BPPJAsuh.js";
7
+ import { t as IdGenerator } from "./id-generator--x6itQZ2.js";
8
+ import { r as SessionContext, t as EventFactory } from "./event-factory-KaeDSfeP.js";
9
+ import { t as EDAKeepAlive } from "./keep-alive-Chl5SJxy.js";
10
+ import { d as CompactionRunner } from "./compaction-BhLSSXJ-.js";
11
+ import { s as EDASinkRegistry, u as LiveEventBus } from "./sink-registry-DuDkNXjZ.js";
12
+ import { a as EDAReducerStateSnapshot, r as EDAReducerRegistry } from "./reducer-registry-CCSzc4h8.js";
13
+ import { r as EDAPromptProjector } from "./prompt-projector-CNhqUsEr.js";
14
+ import { t as RunScheduler } from "./run-scheduler-DcS_okUH.js";
15
+ import { t as RunSchedulingWakeup } from "./run-scheduling-wakeup-CeHrvXie.js";
16
+ import { r as EDAToolRegistry } from "./tool-registry-BDmJe_Wr.js";
15
17
  import * as Context from "effect/Context";
16
18
  import * as Effect from "effect/Effect";
17
19
  import * as Layer from "effect/Layer";
18
20
  import * as Schema from "effect/Schema";
19
- import * as Stream from "effect/Stream";
20
21
  import * as Prompt from "effect/unstable/ai/Prompt";
21
22
  import * as Cause from "effect/Cause";
22
- import * as Scope from "effect/Scope";
23
- import * as LanguageModel from "effect/unstable/ai/LanguageModel";
24
23
  import * as Response from "effect/unstable/ai/Response";
25
24
 
26
25
  //#region src/services/session-event-sink.d.ts
@@ -146,7 +145,7 @@ interface ToolExecutorShape {
146
145
  declare const ToolExecutor_base: Context.ServiceClass<ToolExecutor, "@effect-durable-agent/ToolExecutor", ToolExecutorShape>;
147
146
  /** Executes sealed framework-owned tool calls and commits tool lifecycle boundaries. */
148
147
  declare class ToolExecutor extends ToolExecutor_base {
149
- static readonly Live: Layer.Layer<ToolExecutor, never, IdGenerator | EventFactory | SessionContext | EDAToolRegistry>;
148
+ static readonly Live: Layer.Layer<ToolExecutor, never, EDAToolRegistry | SessionContext | EventFactory | IdGenerator>;
150
149
  }
151
150
  //#endregion
152
151
  //#region src/services/inference-runner.d.ts
@@ -294,7 +293,7 @@ interface InferenceRunnerShape {
294
293
  declare const InferenceRunner_base: Context.ServiceClass<InferenceRunner, "@effect-durable-agent/InferenceRunner", InferenceRunnerShape>;
295
294
  /** Owns provider inference streams and routes them into durable/live inference emissions. */
296
295
  declare class InferenceRunner extends InferenceRunner_base {
297
- static readonly Live: Layer.Layer<InferenceRunner, never, IdGenerator | LanguageModel.LanguageModel | EventFactory | EDAToolRegistry>;
296
+ static readonly Live: Layer.Layer<InferenceRunner, never, ModelResolver | EDAToolRegistry | EventFactory | IdGenerator>;
298
297
  }
299
298
  //#endregion
300
299
  //#region src/services/turn-runner.d.ts
@@ -547,7 +546,7 @@ interface TurnRunnerShape {
547
546
  declare const TurnRunner_base: Context.ServiceClass<TurnRunner, "@effect-durable-agent/TurnRunner", TurnRunnerShape>;
548
547
  /** Owns one turn: turn boundaries, inferences, tool handoff, and terminal turn events. */
549
548
  declare class TurnRunner extends TurnRunner_base {
550
- static readonly Live: Layer.Layer<TurnRunner, never, IdGenerator | EventFactory | InferenceRunner | ToolExecutor>;
549
+ static readonly Live: Layer.Layer<TurnRunner, never, EventFactory | IdGenerator | InferenceRunner | ToolExecutor>;
551
550
  }
552
551
  //#endregion
553
552
  //#region src/services/session-state.d.ts
@@ -567,6 +566,120 @@ declare const SessionRunInput: Schema.Struct<{
567
566
  readonly systemPrompt: Schema.optionalKey<Schema.NonEmptyString>;
568
567
  }>;
569
568
  type SessionRunInput = typeof SessionRunInput.Type;
569
+ /** Command outcome when the command's run completed and the command was completed. */
570
+ declare const SessionCommandCompleted: Schema.TaggedStruct<"SessionCommandCompleted", {
571
+ readonly committed: Schema.Struct<{
572
+ readonly position: Schema.Struct<{
573
+ readonly seq: Schema.brand<Schema.Int, "SequenceNumber">;
574
+ readonly subSeq: Schema.brand<Schema.Literal<0>, "SubSequenceNumber">;
575
+ }>;
576
+ readonly event: Schema.Struct<{
577
+ readonly durability: Schema.Literal<"durable">;
578
+ readonly namespace: Schema.NonEmptyString;
579
+ readonly type: Schema.NonEmptyString;
580
+ readonly schemaVersion: Schema.Int;
581
+ readonly eventId: Schema.brand<Schema.String, "EventId">;
582
+ readonly sessionId: Schema.brand<Schema.String, "SessionId">;
583
+ readonly correlationId: Schema.optionalKey<Schema.brand<Schema.String, "CorrelationId">>;
584
+ readonly createdAtMs: Schema.brand<Schema.Int, "UnixEpochMillis">;
585
+ readonly trace: Schema.withConstructorDefault<Schema.Struct<{
586
+ readonly span: Schema.Struct<{
587
+ readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
588
+ readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
589
+ readonly sampled: Schema.Boolean;
590
+ readonly tracestate: Schema.NullOr<Schema.String>;
591
+ }>;
592
+ readonly links: Schema.$Array<Schema.Struct<{
593
+ readonly context: Schema.Struct<{
594
+ readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
595
+ readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
596
+ readonly sampled: Schema.Boolean;
597
+ readonly tracestate: Schema.NullOr<Schema.String>;
598
+ }>;
599
+ readonly attributes: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean]>>;
600
+ }>>;
601
+ }>>;
602
+ readonly payload: Schema.Unknown;
603
+ }>;
604
+ }>;
605
+ }>;
606
+ type SessionCommandCompleted = typeof SessionCommandCompleted.Type;
607
+ /** Command outcome when the command's run failed and the command was failed. */
608
+ declare const SessionCommandFailed: Schema.TaggedStruct<"SessionCommandFailed", {
609
+ readonly committed: Schema.Struct<{
610
+ readonly position: Schema.Struct<{
611
+ readonly seq: Schema.brand<Schema.Int, "SequenceNumber">;
612
+ readonly subSeq: Schema.brand<Schema.Literal<0>, "SubSequenceNumber">;
613
+ }>;
614
+ readonly event: Schema.Struct<{
615
+ readonly durability: Schema.Literal<"durable">;
616
+ readonly namespace: Schema.NonEmptyString;
617
+ readonly type: Schema.NonEmptyString;
618
+ readonly schemaVersion: Schema.Int;
619
+ readonly eventId: Schema.brand<Schema.String, "EventId">;
620
+ readonly sessionId: Schema.brand<Schema.String, "SessionId">;
621
+ readonly correlationId: Schema.optionalKey<Schema.brand<Schema.String, "CorrelationId">>;
622
+ readonly createdAtMs: Schema.brand<Schema.Int, "UnixEpochMillis">;
623
+ readonly trace: Schema.withConstructorDefault<Schema.Struct<{
624
+ readonly span: Schema.Struct<{
625
+ readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
626
+ readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
627
+ readonly sampled: Schema.Boolean;
628
+ readonly tracestate: Schema.NullOr<Schema.String>;
629
+ }>;
630
+ readonly links: Schema.$Array<Schema.Struct<{
631
+ readonly context: Schema.Struct<{
632
+ readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
633
+ readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
634
+ readonly sampled: Schema.Boolean;
635
+ readonly tracestate: Schema.NullOr<Schema.String>;
636
+ }>;
637
+ readonly attributes: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean]>>;
638
+ }>>;
639
+ }>>;
640
+ readonly payload: Schema.Unknown;
641
+ }>;
642
+ }>;
643
+ }>;
644
+ type SessionCommandFailed = typeof SessionCommandFailed.Type;
645
+ /** Command outcome when command work was cancelled by stop, interrupt, or recovery. */
646
+ declare const SessionCommandCancelled: Schema.TaggedStruct<"SessionCommandCancelled", {
647
+ readonly committed: Schema.Struct<{
648
+ readonly position: Schema.Struct<{
649
+ readonly seq: Schema.brand<Schema.Int, "SequenceNumber">;
650
+ readonly subSeq: Schema.brand<Schema.Literal<0>, "SubSequenceNumber">;
651
+ }>;
652
+ readonly event: Schema.Struct<{
653
+ readonly durability: Schema.Literal<"durable">;
654
+ readonly namespace: Schema.NonEmptyString;
655
+ readonly type: Schema.NonEmptyString;
656
+ readonly schemaVersion: Schema.Int;
657
+ readonly eventId: Schema.brand<Schema.String, "EventId">;
658
+ readonly sessionId: Schema.brand<Schema.String, "SessionId">;
659
+ readonly correlationId: Schema.optionalKey<Schema.brand<Schema.String, "CorrelationId">>;
660
+ readonly createdAtMs: Schema.brand<Schema.Int, "UnixEpochMillis">;
661
+ readonly trace: Schema.withConstructorDefault<Schema.Struct<{
662
+ readonly span: Schema.Struct<{
663
+ readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
664
+ readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
665
+ readonly sampled: Schema.Boolean;
666
+ readonly tracestate: Schema.NullOr<Schema.String>;
667
+ }>;
668
+ readonly links: Schema.$Array<Schema.Struct<{
669
+ readonly context: Schema.Struct<{
670
+ readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
671
+ readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
672
+ readonly sampled: Schema.Boolean;
673
+ readonly tracestate: Schema.NullOr<Schema.String>;
674
+ }>;
675
+ readonly attributes: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean]>>;
676
+ }>>;
677
+ }>>;
678
+ readonly payload: Schema.Unknown;
679
+ }>;
680
+ }>;
681
+ }>;
682
+ type SessionCommandCancelled = typeof SessionCommandCancelled.Type;
570
683
  /** Terminal command-processing variants returned from one control action. */
571
684
  declare const SessionCommandOutcome: Schema.Union<readonly [Schema.TaggedStruct<"SessionCommandCompleted", {
572
685
  readonly committed: Schema.Struct<{
@@ -680,9 +793,12 @@ interface SessionCommandResult {
680
793
  readonly started: CommittedDurableEvent;
681
794
  readonly outcome: SessionCommandOutcome;
682
795
  }
796
+ /** Why a control drain stopped without starting more command work. */
797
+ declare const SessionNoRunnableReason: Schema.Literals<readonly ["active-command", "no-pending-command", "awaiting-run-authorization"]>;
798
+ type SessionNoRunnableReason = typeof SessionNoRunnableReason.Type;
683
799
  /** Session control result when no admitted command is runnable. */
684
800
  declare const SessionNoRunnableCommand: Schema.TaggedStruct<"SessionNoRunnableCommand", {
685
- readonly reason: Schema.Literals<readonly ["active-command", "no-pending-command"]>;
801
+ readonly reason: Schema.Literals<readonly ["active-command", "no-pending-command", "awaiting-run-authorization"]>;
686
802
  readonly active: Schema.optionalKey<Schema.TaggedStruct<"DispatchActiveCommand", {
687
803
  readonly commandId: Schema.brand<Schema.String, "CommandId">;
688
804
  readonly runId: Schema.optionalKey<Schema.brand<Schema.String, "RunId">>;
@@ -716,6 +832,10 @@ type SessionCommandAdmissionError = EDASessionStoreError | SessionCommandAdmissi
716
832
  type EDASubmittable = EDACommand | DurableEventEnvelope;
717
833
  /** Internal live-process authority for commands, durable writes, and scheduling. */
718
834
  interface SessionStateShape extends SessionEventSink {
835
+ /** Trusted permission entrypoint, serialized with control actions and revalidated before commit. */
836
+ readonly grantRun: (command: GrantRunCommand, input: SessionRunInput) => Effect.Effect<RunGrantResult, SessionStateError>;
837
+ /** Host alarm callback for strict, at-least-once delivery of the current persisted request. */
838
+ readonly retryRunSchedulingDelivery: () => Effect.Effect<void, EDASessionStoreError>;
719
839
  /** Commit session-initial context, such as app-owned system prompt, before command work starts. */
720
840
  readonly initialize: (input: SessionRunInput) => Effect.Effect<void, SessionCommandAdmissionError>;
721
841
  /** Submit commands and/or app durable events as one ordered durable batch. */
@@ -740,30 +860,8 @@ interface SessionStateShape extends SessionEventSink {
740
860
  declare const SessionState_base: Context.ServiceClass<SessionState, "@effect-durable-agent/SessionState", SessionStateShape>;
741
861
  /** Internal authoritative live state and root control loop for one session. */
742
862
  declare class SessionState extends SessionState_base {
743
- static readonly Live: Layer.Layer<SessionState, EDASessionStoreError, IdGenerator | EDAPromptProjector | LiveEventBus | EDASessionStore | CompactionRunner | EventFactory | EDAKeepAlive | EDAReducerRegistry | TurnRunner | SessionContext | EDASinkRegistry>;
744
- }
745
- //#endregion
746
- //#region src/services/session-query.d.ts
747
- /** Authoritative live snapshot for one EDA session plus its derived durable transcript. */
748
- interface EDASessionSnapshot {
749
- readonly state: ReducedState;
750
- readonly reducerStates: EDAReducerStateSnapshot;
751
- readonly messages: ReadonlyArray<DurableTranscriptMessage>;
752
- }
753
- /** Read-only query facade over authoritative live state and reconnect-safe event streams. */
754
- interface EDASessionQueryShape {
755
- /** Read the authoritative live state and derive its durable transcript. */
756
- readonly snapshot: () => Effect.Effect<EDASessionSnapshot, EDASessionStoreError>;
757
- /** Read durable user/assistant messages in committed sequence order from the live snapshot. */
758
- readonly messages: () => Effect.Effect<ReadonlyArray<DurableTranscriptMessage>, EDASessionStoreError>;
759
- /** Backfill durable events after `afterSeq`, then follow live durable/ephemeral events. */
760
- readonly eventsAfter: (afterSeq: SequenceNumber) => Effect.Effect<Stream.Stream<PositionedEvent, EDASessionStoreError>, EDASessionStoreError, Scope.Scope>;
761
- }
762
- declare const EDASessionQuery_base: Context.ServiceClass<EDASessionQuery, "@effect-durable-agent/EDASessionQuery", EDASessionQueryShape>;
763
- /** Read-only session query facade backed by authoritative SessionState plus durable backfill. */
764
- declare class EDASessionQuery extends EDASessionQuery_base {
765
- static readonly Live: Layer.Layer<EDASessionQuery, never, SessionState | LiveEventBus | EDASessionStore>;
863
+ static readonly Live: Layer.Layer<SessionState, EDASessionStoreError, RunSchedulingWakeup | RunScheduler | EDASessionStore | EDASinkRegistry | EDAReducerRegistry | LiveEventBus | EDAKeepAlive | SessionContext | EventFactory | IdGenerator | TurnRunner | CompactionRunner | EDAPromptProjector>;
766
864
  }
767
865
  //#endregion
768
- export { SessionCommandAdmissionError as a, InferenceRunner as c, EDASubmittable as i, InferenceRunnerStreamPart as l, EDASessionQueryShape as n, SessionState as o, EDASessionSnapshot as r, TurnRunner as s, EDASessionQuery as t, ToolExecutor as u };
769
- //# sourceMappingURL=session-query-DlRo5Ufc.d.ts.map
866
+ export { ToolExecutor as S, SessionStateShape as _, SessionCommandCompleted as a, InferenceRunner as b, SessionCommandResult as c, SessionForkedCommand as d, SessionNoRunnableCommand as f, SessionStateError as g, SessionState as h, SessionCommandCancelled as i, SessionDrainProcessed as l, SessionRunInput as m, SessionCommandAdmissionConflict as n, SessionCommandFailed as o, SessionNoRunnableReason as p, SessionCommandAdmissionError as r, SessionCommandOutcome as s, EDASubmittable as t, SessionDrainResult as u, SessionStateSnapshotData as v, InferenceRunnerStreamPart as x, TurnRunner as y };
867
+ //# sourceMappingURL=session-state-BeR2rZRR.d.ts.map
@@ -1,6 +1,7 @@
1
- import { _ as SummaryId, h as SessionId, m as SequenceNumber, n as CommandId } from "./core-Hv3cFydL.js";
2
- import { n as CommandIdempotencyKey } from "./commands-Ce1ec6kH.js";
3
- import { D as DurableEventEnvelope } from "./events-Bb9-Cu-7.js";
1
+ import { g as SessionId, h as SequenceNumber, n as CommandId, v as SummaryId } from "./core-C-6xHzRx.js";
2
+ import { t as DurableEventEnvelope } from "./envelope-DkZyMIgp.js";
3
+ import { n as CommandIdempotencyKey } from "./commands-p8venTWs.js";
4
+ import { r as CompactionSummaryArtifact } from "./context-projection-mCuvcO2W.js";
4
5
  import * as Context from "effect/Context";
5
6
  import * as Effect from "effect/Effect";
6
7
  import * as Layer from "effect/Layer";
@@ -8,89 +9,6 @@ import * as Schema from "effect/Schema";
8
9
  import * as Stream from "effect/Stream";
9
10
  import * as Cause from "effect/Cause";
10
11
 
11
- //#region src/domain/context-projection.d.ts
12
- /** Stable identifier for the compaction policy that selected a summary plan. */
13
- declare const CompactionPolicyId: Schema.brand<Schema.NonEmptyString, "CompactionPolicyId">;
14
- type CompactionPolicyId = typeof CompactionPolicyId.Type;
15
- /** Stable identifier for the executor that produced a summary artifact. */
16
- declare const CompactionExecutorId: Schema.brand<Schema.NonEmptyString, "CompactionExecutorId">;
17
- type CompactionExecutorId = typeof CompactionExecutorId.Type;
18
- /** Authoritative cumulative model-context summary written with `SummaryCreated`. */
19
- declare const CompactionSummaryArtifact: Schema.Struct<{
20
- readonly compactionId: Schema.brand<Schema.String, "CompactionId">;
21
- readonly summaryId: Schema.brand<Schema.String, "SummaryId">;
22
- readonly previousSummaryId: Schema.optionalKey<Schema.brand<Schema.String, "SummaryId">>;
23
- readonly sourceFromSeq: Schema.brand<Schema.Int, "SequenceNumber">;
24
- readonly sourceToSeq: Schema.brand<Schema.Int, "SequenceNumber">;
25
- readonly retainedFromContextSeq: Schema.brand<Schema.Int, "SequenceNumber">;
26
- readonly text: Schema.NonEmptyString;
27
- readonly promptMessage: Schema.Struct<{
28
- readonly role: Schema.Literal<"user">;
29
- readonly content: Schema.Union<readonly [Schema.decodeTo<Schema.NonEmptyArray<Schema.toType<Schema.Struct<{
30
- readonly type: Schema.Literal<"text">;
31
- readonly text: Schema.String;
32
- readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Part">>;
33
- readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
34
- }>>>, Schema.String, never, never>, Schema.$Array<Schema.Union<readonly [Schema.Struct<{
35
- readonly type: Schema.Literal<"text">;
36
- readonly text: Schema.String;
37
- readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Part">>;
38
- readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
39
- }>, Schema.Struct<{
40
- readonly type: Schema.Literal<"file">;
41
- readonly mediaType: Schema.String;
42
- readonly fileName: Schema.optional<Schema.String>;
43
- readonly data: Schema.Union<readonly [Schema.String, Schema.Uint8Array, Schema.URL]>;
44
- readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Part">>;
45
- readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
46
- }>]>>]>;
47
- readonly "~effect/ai/Prompt/Message": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Message">>;
48
- readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
49
- }>;
50
- readonly policyId: Schema.brand<Schema.NonEmptyString, "CompactionPolicyId">;
51
- readonly executorId: Schema.optionalKey<Schema.brand<Schema.NonEmptyString, "CompactionExecutorId">>;
52
- }>;
53
- type CompactionSummaryArtifact = typeof CompactionSummaryArtifact.Type;
54
- /** Current durable context cursor projected from framework reducer state and summary rows. */
55
- declare const ContextProjection: Schema.Struct<{
56
- readonly contextVersion: Schema.brand<Schema.Int, "ContextVersion">;
57
- readonly currentSummary: Schema.optionalKey<Schema.Struct<{
58
- readonly compactionId: Schema.brand<Schema.String, "CompactionId">;
59
- readonly summaryId: Schema.brand<Schema.String, "SummaryId">;
60
- readonly previousSummaryId: Schema.optionalKey<Schema.brand<Schema.String, "SummaryId">>;
61
- readonly sourceFromSeq: Schema.brand<Schema.Int, "SequenceNumber">;
62
- readonly sourceToSeq: Schema.brand<Schema.Int, "SequenceNumber">;
63
- readonly retainedFromContextSeq: Schema.brand<Schema.Int, "SequenceNumber">;
64
- readonly text: Schema.NonEmptyString;
65
- readonly promptMessage: Schema.Struct<{
66
- readonly role: Schema.Literal<"user">;
67
- readonly content: Schema.Union<readonly [Schema.decodeTo<Schema.NonEmptyArray<Schema.toType<Schema.Struct<{
68
- readonly type: Schema.Literal<"text">;
69
- readonly text: Schema.String;
70
- readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Part">>;
71
- readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
72
- }>>>, Schema.String, never, never>, Schema.$Array<Schema.Union<readonly [Schema.Struct<{
73
- readonly type: Schema.Literal<"text">;
74
- readonly text: Schema.String;
75
- readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Part">>;
76
- readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
77
- }>, Schema.Struct<{
78
- readonly type: Schema.Literal<"file">;
79
- readonly mediaType: Schema.String;
80
- readonly fileName: Schema.optional<Schema.String>;
81
- readonly data: Schema.Union<readonly [Schema.String, Schema.Uint8Array, Schema.URL]>;
82
- readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Part">>;
83
- readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
84
- }>]>>]>;
85
- readonly "~effect/ai/Prompt/Message": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Message">>;
86
- readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
87
- }>;
88
- readonly policyId: Schema.brand<Schema.NonEmptyString, "CompactionPolicyId">;
89
- readonly executorId: Schema.optionalKey<Schema.brand<Schema.NonEmptyString, "CompactionExecutorId">>;
90
- }>>;
91
- }>;
92
- type ContextProjection = typeof ContextProjection.Type;
93
- //#endregion
94
12
  //#region src/services/session-store.d.ts
95
13
  /** A durable event after the store has assigned its replay position. */
96
14
  declare const CommittedDurableEvent: Schema.Struct<{
@@ -135,19 +53,12 @@ declare const EDASessionStoreError_base: Schema.Class<EDASessionStoreError, Sche
135
53
  * Store-level failure surfaced by durable append, replay, and hydration APIs.
136
54
  *
137
55
  * The error intentionally stays storage-semantic rather than SQL-specific so
138
- * framework services can treat DO SQLite, in-memory tests, and future adapters
56
+ * framework services can treat SQL-backed hosts, in-memory tests, and future adapters
139
57
  * as the same durability boundary.
140
58
  */
141
59
  declare class EDASessionStoreError extends EDASessionStoreError_base {}
142
60
  /** True when a Cause contains an escaped durable-store failure. */
143
61
  declare const hasEDASessionStoreError: (cause: Cause.Cause<unknown>) => boolean;
144
- /**
145
- * Initial hard cap for one serialized JSON value stored in DO SQLite.
146
- *
147
- * Cloudflare's SQL row/string limit is 2MB; failing around 1.5MB leaves margin
148
- * for encoding overhead and makes the future blob/chunk decision explicit.
149
- */
150
- declare const durableObjectSerializedJsonHardCapBytes = 1500000;
151
62
  /**
152
63
  * One logical event to persist in the durable session log.
153
64
  *
@@ -291,5 +202,5 @@ declare class EDASessionStore extends EDASessionStore_base {
291
202
  static readonly InMemorySeeded: (sessionId: SessionId, events: ReadonlyArray<DurableEventEnvelope>) => Layer.Layer<EDASessionStore, never, never>;
292
203
  }
293
204
  //#endregion
294
- export { EDASessionStore as a, FindCommandAdmissionInput as c, hasEDASessionStoreError as d, CompactionExecutorId as f, EDAReducerCheckpoint as i, SaveReducerCheckpointInput as l, ContextProjection as m, DurableAppendBatch as n, EDASessionStoreError as o, CompactionPolicyId as p, DurableAppendEntry as r, EDASessionStoreShape as s, CommittedDurableEvent as t, durableObjectSerializedJsonHardCapBytes as u };
295
- //# sourceMappingURL=session-store-D2Ore1QC.d.ts.map
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-J_Un45kW.d.ts.map
@@ -0,0 +1,40 @@
1
+ import { h as SequenceNumber } from "./core-C-6xHzRx.js";
2
+ import { o as EDASessionStoreError } from "./session-store-J_Un45kW.js";
3
+ import * as Context from "effect/Context";
4
+ import * as Effect from "effect/Effect";
5
+ import * as Layer from "effect/Layer";
6
+ import * as Schema from "effect/Schema";
7
+
8
+ //#region src/services/sink-checkpoint-store.d.ts
9
+ /** Stable sink name used as the durable checkpoint key. */
10
+ declare const EDASinkName: Schema.brand<Schema.NonEmptyString, "EDASinkName">;
11
+ type EDASinkName = typeof EDASinkName.Type;
12
+ /** Persisted cursor and sink-owned payload for one registered sink. */
13
+ interface StoredSinkCheckpoint {
14
+ readonly afterSeq: SequenceNumber;
15
+ readonly payload: unknown | undefined;
16
+ }
17
+ /** Durable checkpoint persistence port for at-least-once sink runners. */
18
+ interface SinkCheckpointStoreShape {
19
+ /** Read the latest committed cursor and sink-owned payload. */
20
+ readonly load: (sinkName: EDASinkName) => Effect.Effect<StoredSinkCheckpoint, EDASessionStoreError>;
21
+ /** Save sink-owned state without advancing the durable cursor. */
22
+ readonly saveState: (sinkName: EDASinkName, payload: unknown) => Effect.Effect<void, EDASessionStoreError>;
23
+ /** Atomically commit the processed cursor together with current sink-owned state. */
24
+ readonly commit: (sinkName: EDASinkName, afterSeq: SequenceNumber, payload: unknown | undefined) => Effect.Effect<void, EDASessionStoreError>;
25
+ }
26
+ declare const SinkCheckpointStore_base: Context.ServiceClass<SinkCheckpointStore, "@effect-durable-agent/SinkCheckpointStore", SinkCheckpointStoreShape>;
27
+ /**
28
+ * Semantic checkpoint store for registered EDA sinks.
29
+ *
30
+ * Checkpoints are intentionally exposed as load/save/commit operations rather
31
+ * than SQL. Sink side effects happen outside event append transactions, and the
32
+ * cursor advances only after the sink finishes its own external work.
33
+ */
34
+ declare class SinkCheckpointStore extends SinkCheckpointStore_base {
35
+ /** In-memory checkpoint implementation for store/runtime tests. */
36
+ static readonly InMemory: Layer.Layer<SinkCheckpointStore, never, never>;
37
+ }
38
+ //#endregion
39
+ export { StoredSinkCheckpoint as i, SinkCheckpointStore as n, SinkCheckpointStoreShape as r, EDASinkName as t };
40
+ //# sourceMappingURL=sink-checkpoint-store-C9hUxfH0.d.ts.map
@@ -1,11 +1,14 @@
1
1
  import { SequenceNumber, durablePosition } from "./types/core.js";
2
- import { Jn as turnFailedEventType, Xn as turnStoppedEventType, Yn as turnStartedEventType, qn as turnCompletedEventType } from "./durable-C3Rz7kg3.js";
3
- import { f as reduceCommittedEvents, o as foldReducedState } from "./reduced-state-C4nVVzz9.js";
4
- import { a as EDASessionStoreError, i as EDASessionStore, t as CommittedDurableEvent } from "./session-store-pYxQW9qh.js";
2
+ import { dr as turnCompletedEventType, fr as turnFailedEventType, mr as turnStoppedEventType, pr as turnStartedEventType } from "./durable-BPHVFVvV.js";
3
+ import { f as reduceCommittedEvents, o as foldReducedState } from "./reduced-state-Bz68V2H8.js";
4
+ import { CommittedDurableEvent, EDASessionStore, EDASessionStoreError } from "./services/session-store.js";
5
5
  import { IdGenerator } from "./services/id-generator.js";
6
- import { n as EventFactory, r as SessionContext, t as EDAKeepAlive } from "./keep-alive-p8dIcSVy.js";
6
+ import { n as SessionContext, t as EventFactory } from "./event-factory-QuC_UvyP.js";
7
7
  import { annotateEdaSpan } from "./services/tracing.js";
8
+ import { EDAKeepAlive } from "./services/keep-alive.js";
9
+ import { SessionEventObserver } from "./services/session-event-observer.js";
8
10
  import { EDAReducerRegistry } from "./services/reducer-registry.js";
11
+ import { EDASinkName, SinkCheckpointStore } from "./services/sink-checkpoint-store.js";
9
12
  import * as Context from "effect/Context";
10
13
  import * as Effect from "effect/Effect";
11
14
  import * as Layer from "effect/Layer";
@@ -15,8 +18,6 @@ import * as Cause from "effect/Cause";
15
18
  import * as Ref from "effect/Ref";
16
19
  import * as Scope from "effect/Scope";
17
20
  import * as PubSub from "effect/PubSub";
18
- import * as Duration from "effect/Duration";
19
- import * as Schedule from "effect/Schedule";
20
21
  import * as SynchronizedRef from "effect/SynchronizedRef";
21
22
  //#region src/services/live-event-bus.ts
22
23
  /** Conservative raw-delta cap for one open turn's live-only reconnect replay. */
@@ -27,11 +28,17 @@ var LiveEventBus = class LiveEventBus extends Context.Service()("@effect-durable
27
28
  return makeLiveBus(yield* Effect.acquireRelease(PubSub.unbounded(), PubSub.shutdown), yield* Ref.make({
28
29
  events: [],
29
30
  overflowed: false
30
- }));
31
+ }), yield* SessionEventObserver);
31
32
  }));
33
+ /** Live bus for hosts that do not install an append-driven observer. */
34
+ static Noop = LiveEventBus.Live.pipe(Layer.provide(SessionEventObserver.Noop));
32
35
  };
33
- const makeLiveBus = (pubsub, activeTurnReplay) => ({
34
- publish: (event) => updateActiveTurnReplay(activeTurnReplay, event).pipe(Effect.andThen(PubSub.publish(pubsub, event))),
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
+ }),
35
42
  subscribeQueue: () => PubSub.subscribe(pubsub),
36
43
  subscribe: () => Effect.map(PubSub.subscribe(pubsub), (subscription) => Stream.fromEffectRepeat(PubSub.take(subscription))),
37
44
  activeTurnReplay: () => Ref.get(activeTurnReplay)
@@ -63,46 +70,6 @@ const nextActiveTurnReplay = (state, event) => {
63
70
  };
64
71
  };
65
72
  //#endregion
66
- //#region src/services/sink-checkpoint-store.ts
67
- /** Stable sink name used as the durable checkpoint key. */
68
- const EDASinkName = Schema.NonEmptyString.pipe(Schema.brand("EDASinkName"));
69
- /**
70
- * Semantic checkpoint store for registered EDA sinks.
71
- *
72
- * Checkpoints are intentionally exposed as load/save/commit operations rather
73
- * than SQL. Sink side effects happen outside event append transactions, and the
74
- * cursor advances only after the sink finishes its own external work.
75
- */
76
- var SinkCheckpointStore = class SinkCheckpointStore extends Context.Service()("@effect-durable-agent/SinkCheckpointStore") {
77
- /** In-memory checkpoint implementation for store/runtime tests. */
78
- static InMemory = Layer.effect(SinkCheckpointStore, Effect.gen(function* () {
79
- return makeInMemorySinkCheckpointStore(yield* Ref.make(/* @__PURE__ */ new Map()));
80
- }));
81
- };
82
- /** Build a ref-backed checkpoint map with the same public semantics as host adapters. */
83
- const makeInMemorySinkCheckpointStore = (checkpoints) => ({
84
- load: (sinkName) => Ref.get(checkpoints).pipe(Effect.map((map) => map.get(sinkName) ?? {
85
- afterSeq: SequenceNumber.make(0),
86
- payload: void 0
87
- })),
88
- saveState: (sinkName, payload) => Ref.update(checkpoints, (map) => {
89
- const next = new Map(map);
90
- next.set(sinkName, {
91
- afterSeq: map.get(sinkName)?.afterSeq ?? SequenceNumber.make(0),
92
- payload
93
- });
94
- return next;
95
- }),
96
- commit: (sinkName, afterSeq, payload) => Ref.update(checkpoints, (map) => {
97
- const next = new Map(map);
98
- next.set(sinkName, {
99
- afterSeq,
100
- payload
101
- });
102
- return next;
103
- })
104
- });
105
- //#endregion
106
73
  //#region src/services/sink-registry.ts
107
74
  /** Convenience constructor preserving a sink's literal name/type information. */
108
75
  const EDASink = { make: (sink) => sink };
@@ -117,9 +84,7 @@ var EDASinkRegistry = class EDASinkRegistry extends Context.Service()("@effect-d
117
84
  static Live = (sinks) => Layer.effect(EDASinkRegistry, makeSinkRegistry(sinks));
118
85
  };
119
86
  const defaultBatchSize = 100;
120
- const maxDurableSinkRetryDelay = Duration.seconds(5);
121
87
  const sinkCheckpointFormatVersion = 1;
122
- const durableSinkRetrySchedule = Schedule.exponential("100 millis").pipe(Schedule.jittered, Schedule.modifyDelay(({ duration }) => Effect.succeed(Duration.min(duration, maxDurableSinkRetryDelay))));
123
88
  const makeSinkRegistry = (sinks) => Effect.gen(function* () {
124
89
  const session = yield* SessionContext;
125
90
  const store = yield* EDASessionStore;
@@ -164,14 +129,16 @@ const makeSinkRegistry = (sinks) => Effect.gen(function* () {
164
129
  const eventsForSink = durable === void 0 ? [] : filterInterested(fresh, durable.interests);
165
130
  if (durable !== void 0 && eventsForSink.length > 0) yield* Effect.gen(function* () {
166
131
  const staged = [];
167
- yield* durable.process({
132
+ if ((yield* durable.process({
168
133
  allEvents: fresh,
169
134
  events: eventsForSink,
170
135
  stateAfter: nextReduced,
171
136
  reducerStates: nextReducerStates,
172
137
  throughSeq
173
- }, baseContext(staged, input.publishEphemeral, input.scope, checkpoint));
174
- if (staged.length > 0) {
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) {
175
142
  yield* annotateEdaSpan({ "eda.sink.staged_events": staged.length });
176
143
  yield* input.appendDurableBatch(staged);
177
144
  }
@@ -189,17 +156,14 @@ const makeSinkRegistry = (sinks) => Effect.gen(function* () {
189
156
  reducerStates: nextReducerStates
190
157
  });
191
158
  });
192
- const processDurableBatchWithRetry = (events) => keepAlive.withActiveWork(`sink:${sink.name}`, processDurableBatch(events).pipe(Effect.tapError((error) => Effect.logWarning("EDA sink durable projection failed; retrying", {
193
- error: formatSinkError(error),
194
- sink: sink.name
195
- })), Effect.retry(durableSinkRetrySchedule)));
159
+ const processDurableBatchWithKeepAlive = (events) => keepAlive.withActiveWork(`sink:${sink.name}`, processDurableBatch(events));
196
160
  const drainDurablesThrough = (targetHead) => Effect.gen(function* () {
197
161
  while (true) {
198
162
  const current = yield* Ref.get(state);
199
163
  if (current.cursor >= targetHead) return;
200
164
  const allEvents = yield* readCursorBatchThrough(store, current.cursor, targetHead, sink.durable?.batchSize);
201
165
  if (allEvents.length === 0) return;
202
- yield* processDurableBatchWithRetry(allEvents);
166
+ yield* processDurableBatchWithKeepAlive(allEvents);
203
167
  }
204
168
  });
205
169
  const processLiveDurable = (event) => Effect.gen(function* () {
@@ -215,7 +179,7 @@ const makeSinkRegistry = (sinks) => Effect.gen(function* () {
215
179
  });
216
180
  return;
217
181
  }
218
- yield* processDurableBatchWithRetry([committedDurableFromPositioned(event)]);
182
+ yield* processDurableBatchWithKeepAlive([committedDurableFromPositioned(event)]);
219
183
  });
220
184
  const processLiveEphemeral = (event) => Effect.gen(function* () {
221
185
  const before = yield* Ref.get(state);
@@ -232,7 +196,7 @@ const makeSinkRegistry = (sinks) => Effect.gen(function* () {
232
196
  const processLiveEvent = (event) => event.event.durability === "durable" ? processLiveDurable(event) : processLiveEphemeral(event);
233
197
  yield* Effect.gen(function* () {
234
198
  yield* drainDurablesThrough(input.initialHead);
235
- yield* Effect.forever(Effect.gen(function* () {
199
+ return yield* Effect.forever(Effect.gen(function* () {
236
200
  yield* processLiveEvent(yield* PubSub.take(live));
237
201
  }));
238
202
  }).pipe(Effect.catchCause((cause) => Effect.logError("EDA sink runner failed", {
@@ -302,11 +266,7 @@ const committedDurableFromPositioned = (event) => CommittedDurableEvent.make({
302
266
  });
303
267
  const filterInterested = (events, interests) => events.filter((event) => matchesInterest(event.event.type, interests));
304
268
  const matchesInterest = (type, interests) => interests === void 0 || interests.some((interest) => interest === type);
305
- const formatSinkError = (error) => {
306
- if (Cause.isUnknownError(error)) return `${error.message ?? error._tag}: ${formatSinkError(error.cause)}`;
307
- return error instanceof Error ? error.message : String(error);
308
- };
309
269
  //#endregion
310
- export { LiveEventBus as i, EDASinkRegistry as n, SinkCheckpointStore as r, EDASink as t };
270
+ export { EDASinkRegistry as n, LiveEventBus as r, EDASink as t };
311
271
 
312
- //# sourceMappingURL=sink-registry-CFC6xjsN.js.map
272
+ //# sourceMappingURL=sink-registry-Bbqhtdnx.js.map