effect-durable-agent 0.1.0-alpha.3 → 0.1.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +28 -27
  3. package/dist/{command-queues-CQ9cwRP7.d.ts → command-queues-CV7O-51r.d.ts} +7 -6
  4. package/dist/{compaction-1LSZR944.d.ts → compaction-zbvLREI8.d.ts} +8 -6
  5. package/dist/context-projection-n6Rdup0N.d.ts +140 -0
  6. package/dist/{core-Hv3cFydL.d.ts → core-CYT6DBaS.d.ts} +2 -2
  7. package/dist/domain/command-queues.d.ts +1 -1
  8. package/dist/domain/context-projection.d.ts +2 -0
  9. package/dist/domain/context-projection.js +32 -0
  10. package/dist/domain/context-projection.js.map +1 -0
  11. package/dist/domain/message-transcript.d.ts +1 -1
  12. package/dist/domain/reduced-state-schema.d.ts +2 -0
  13. package/dist/domain/reduced-state-schema.js +2 -1
  14. package/dist/domain/reduced-state-schema.js.map +1 -1
  15. package/dist/domain/reduced-state.d.ts +1 -1
  16. package/dist/domain/reduced-state.js +1 -1
  17. package/dist/{durable-DlScwmCy.d.ts → durable-B7M6TD_0.d.ts} +341 -2
  18. package/dist/{durable-C3Rz7kg3.js → durable-DsV9PxZC.js} +13 -2
  19. package/dist/durable-DsV9PxZC.js.map +1 -0
  20. package/dist/{keep-alive-DYDsH6qN.d.ts → event-factory-CLJcyymV.d.ts} +5 -29
  21. package/dist/{keep-alive-p8dIcSVy.js → event-factory-tcpLgdMN.js} +3 -10
  22. package/dist/event-factory-tcpLgdMN.js.map +1 -0
  23. package/dist/host/websocket-protocol.d.ts +229 -0
  24. package/dist/host/websocket-protocol.js +99 -0
  25. package/dist/host/websocket-protocol.js.map +1 -0
  26. package/dist/host/websocket-wire.d.ts +1 -1
  27. package/dist/host/websocket-wire.js +2 -2
  28. package/dist/host/websocket-wire.js.map +1 -1
  29. package/dist/{id-generator-C2Q15uZM.d.ts → id-generator-Ckl8_XWW.d.ts} +2 -2
  30. package/dist/index.d.ts +4 -4
  31. package/dist/index.js +2 -2
  32. package/dist/keep-alive-Chl5SJxy.d.ts +29 -0
  33. package/dist/{message-transcript-BCHdHAe2.d.ts → message-transcript-DiOPBY3l.d.ts} +3 -3
  34. package/dist/{prompt-projector-DimXJPOJ.d.ts → prompt-projector-C1IbkHr0.d.ts} +5 -5
  35. package/dist/{reduced-state-C4nVVzz9.js → reduced-state-TMi7ISla.js} +20 -4
  36. package/dist/reduced-state-TMi7ISla.js.map +1 -0
  37. package/dist/{reducer-registry-C0svUa63.d.ts → reducer-registry-CjSJBPKo.d.ts} +2 -2
  38. package/dist/{runtime-DcdPOEuE.d.ts → runtime-DOgmAKsO.d.ts} +7 -6
  39. package/dist/services/compaction.d.ts +1 -1
  40. package/dist/services/compaction.js +4 -3
  41. package/dist/services/compaction.js.map +1 -1
  42. package/dist/services/id-generator.d.ts +1 -1
  43. package/dist/services/keep-alive.d.ts +2 -0
  44. package/dist/services/keep-alive.js +13 -0
  45. package/dist/services/keep-alive.js.map +1 -0
  46. package/dist/services/prompt-projector.d.ts +1 -1
  47. package/dist/services/reducer-registry.d.ts +1 -1
  48. package/dist/services/runtime-layer.d.ts +58 -0
  49. package/dist/services/runtime-layer.js +42 -0
  50. package/dist/services/runtime-layer.js.map +1 -0
  51. package/dist/services/runtime.d.ts +1 -1
  52. package/dist/services/runtime.js +4 -3
  53. package/dist/services/runtime.js.map +1 -1
  54. package/dist/services/session-query.d.ts +1 -1
  55. package/dist/services/session-query.js +76 -1
  56. package/dist/services/session-query.js.map +1 -0
  57. package/dist/services/session-state.d.ts +2 -0
  58. package/dist/services/session-state.js +2 -0
  59. package/dist/services/session-store.d.ts +2 -2
  60. package/dist/services/session-store.js +181 -2
  61. package/dist/services/session-store.js.map +1 -0
  62. package/dist/services/sink-checkpoint-store.d.ts +2 -0
  63. package/dist/services/sink-checkpoint-store.js +49 -0
  64. package/dist/services/sink-checkpoint-store.js.map +1 -0
  65. package/dist/services/sink-registry.d.ts +1 -1
  66. package/dist/services/sink-registry.js +1 -1
  67. package/dist/services/tool-registry.d.ts +1 -1
  68. package/dist/services/websocket-subscriber.d.ts +54 -0
  69. package/dist/services/websocket-subscriber.js +190 -0
  70. package/dist/services/websocket-subscriber.js.map +1 -0
  71. package/dist/session-query-C-C4m1eq.d.ts +38 -0
  72. package/dist/{session-query-hxfujxUH.d.ts → session-state-CjOSvWbe.d.ts} +134 -42
  73. package/dist/{session-query-Cbf-e0rG.js → session-state-SStf0KUo.js} +18 -77
  74. package/dist/session-state-SStf0KUo.js.map +1 -0
  75. package/dist/{session-store-D2Ore1QC.d.ts → session-store-DZZUffUy.d.ts} +5 -94
  76. package/dist/sink-checkpoint-store-BZmQFTRE.d.ts +40 -0
  77. package/dist/{sink-registry-BziFpxoE.d.ts → sink-registry-Cf79ICdW.d.ts} +11 -40
  78. package/dist/{sink-registry-CFC6xjsN.js → sink-registry-D13eUO_c.js} +9 -47
  79. package/dist/sink-registry-D13eUO_c.js.map +1 -0
  80. package/dist/testkit/layers.d.ts +14 -11
  81. package/dist/testkit/layers.js +8 -5
  82. package/dist/testkit/layers.js.map +1 -1
  83. package/dist/{tool-registry-CcnkAAQK.d.ts → tool-registry-B7Wona6N.d.ts} +3 -3
  84. package/dist/types/core.d.ts +1 -1
  85. package/dist/types/core.js +1 -1
  86. package/dist/types/core.js.map +1 -1
  87. package/dist/types/events/durable.d.ts +2 -2
  88. package/dist/types/events/durable.js +2 -2
  89. package/dist/types/events.d.ts +2 -2
  90. package/dist/types/events.js +2 -2
  91. package/dist/{websocket-wire-D3tLrhe2.d.ts → websocket-wire-QD2SquQE.d.ts} +74 -2
  92. package/docs/message-steering.md +1 -1
  93. package/docs/releasing.md +42 -24
  94. package/docs/spec.md +11 -11
  95. package/docs/websocket-protocol.md +4 -4
  96. package/package.json +55 -35
  97. package/dist/durable-C3Rz7kg3.js.map +0 -1
  98. package/dist/durable-object-runtime-CiMKxGs6.d.ts +0 -257
  99. package/dist/durable-object-runtime-wKiqaAt2.js +0 -1494
  100. package/dist/durable-object-runtime-wKiqaAt2.js.map +0 -1
  101. package/dist/durable-object-storage-Czy7IPrh.d.ts +0 -41
  102. package/dist/host/durable-object-runtime.d.ts +0 -2
  103. package/dist/host/durable-object-runtime.js +0 -2
  104. package/dist/host/durable-object-storage.d.ts +0 -2
  105. package/dist/host/durable-object-storage.js +0 -0
  106. package/dist/host/durable-object.d.ts +0 -83
  107. package/dist/host/durable-object.js +0 -191
  108. package/dist/host/durable-object.js.map +0 -1
  109. package/dist/keep-alive-p8dIcSVy.js.map +0 -1
  110. package/dist/reduced-state-C4nVVzz9.js.map +0 -1
  111. package/dist/session-query-Cbf-e0rG.js.map +0 -1
  112. package/dist/session-store-pYxQW9qh.js +0 -214
  113. package/dist/session-store-pYxQW9qh.js.map +0 -1
  114. package/dist/sink-registry-CFC6xjsN.js.map +0 -1
  115. package/examples/001-no-tools/README.md +0 -65
  116. package/examples/001-no-tools/worker.ts +0 -79
  117. package/examples/002-slack-bridge/README.md +0 -134
  118. package/examples/002-slack-bridge/events.ts +0 -115
  119. package/examples/002-slack-bridge/reducer.ts +0 -216
  120. package/examples/002-slack-bridge/scenario.test.ts +0 -223
  121. package/examples/002-slack-bridge/sinks.ts +0 -109
  122. package/examples/002-slack-bridge/worker.ts +0 -140
  123. package/examples/003-sandbox-lifecycle/README.md +0 -78
  124. package/examples/003-sandbox-lifecycle/events.ts +0 -203
  125. package/examples/003-sandbox-lifecycle/reducer.ts +0 -305
  126. package/examples/003-sandbox-lifecycle/scenario.test.ts +0 -202
  127. package/examples/_shared/event-id.ts +0 -12
  128. package/examples/_shared/http.ts +0 -27
  129. package/examples/_shared/openai.ts +0 -33
@@ -1,25 +1,22 @@
1
- import { m as SequenceNumber } from "./core-Hv3cFydL.js";
2
1
  import { r as EDACommand } from "./commands-Ce1ec6kH.js";
3
2
  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-BziFpxoE.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-1LSZR944.js";
13
- import { r as EDAPromptProjector } from "./prompt-projector-DimXJPOJ.js";
14
- import { r as EDAToolRegistry } from "./tool-registry-CcnkAAQK.js";
3
+ import { kt as ToolCallCreatedEvent } from "./durable-B7M6TD_0.js";
4
+ import { a as EDASessionStore, o as EDASessionStoreError, t as CommittedDurableEvent } from "./session-store-DZZUffUy.js";
5
+ import { S as ReducedState } from "./command-queues-CV7O-51r.js";
6
+ import { t as IdGenerator } from "./id-generator-Ckl8_XWW.js";
7
+ import { r as SessionContext, t as EventFactory } from "./event-factory-CLJcyymV.js";
8
+ import { t as EDAKeepAlive } from "./keep-alive-Chl5SJxy.js";
9
+ import { d as CompactionRunner } from "./compaction-zbvLREI8.js";
10
+ import { s as EDASinkRegistry, u as LiveEventBus } from "./sink-registry-Cf79ICdW.js";
11
+ import { i as EDAReducerStateSnapshot, n as EDAReducerRegistry } from "./reducer-registry-CjSJBPKo.js";
12
+ import { r as EDAPromptProjector } from "./prompt-projector-C1IbkHr0.js";
13
+ import { r as EDAToolRegistry } from "./tool-registry-B7Wona6N.js";
15
14
  import * as Context from "effect/Context";
16
15
  import * as Effect from "effect/Effect";
17
16
  import * as Layer from "effect/Layer";
18
17
  import * as Schema from "effect/Schema";
19
- import * as Stream from "effect/Stream";
20
18
  import * as Prompt from "effect/unstable/ai/Prompt";
21
19
  import * as Cause from "effect/Cause";
22
- import * as Scope from "effect/Scope";
23
20
  import * as LanguageModel from "effect/unstable/ai/LanguageModel";
24
21
  import * as Response from "effect/unstable/ai/Response";
25
22
 
@@ -146,7 +143,7 @@ interface ToolExecutorShape {
146
143
  declare const ToolExecutor_base: Context.ServiceClass<ToolExecutor, "@effect-durable-agent/ToolExecutor", ToolExecutorShape>;
147
144
  /** Executes sealed framework-owned tool calls and commits tool lifecycle boundaries. */
148
145
  declare class ToolExecutor extends ToolExecutor_base {
149
- static readonly Live: Layer.Layer<ToolExecutor, never, EventFactory | IdGenerator | SessionContext | EDAToolRegistry>;
146
+ static readonly Live: Layer.Layer<ToolExecutor, never, IdGenerator | EventFactory | SessionContext | EDAToolRegistry>;
150
147
  }
151
148
  //#endregion
152
149
  //#region src/services/inference-runner.d.ts
@@ -294,7 +291,7 @@ interface InferenceRunnerShape {
294
291
  declare const InferenceRunner_base: Context.ServiceClass<InferenceRunner, "@effect-durable-agent/InferenceRunner", InferenceRunnerShape>;
295
292
  /** Owns provider inference streams and routes them into durable/live inference emissions. */
296
293
  declare class InferenceRunner extends InferenceRunner_base {
297
- static readonly Live: Layer.Layer<InferenceRunner, never, LanguageModel.LanguageModel | EventFactory | IdGenerator | EDAToolRegistry>;
294
+ static readonly Live: Layer.Layer<InferenceRunner, never, IdGenerator | EventFactory | EDAToolRegistry | LanguageModel.LanguageModel>;
298
295
  }
299
296
  //#endregion
300
297
  //#region src/services/turn-runner.d.ts
@@ -547,7 +544,7 @@ interface TurnRunnerShape {
547
544
  declare const TurnRunner_base: Context.ServiceClass<TurnRunner, "@effect-durable-agent/TurnRunner", TurnRunnerShape>;
548
545
  /** Owns one turn: turn boundaries, inferences, tool handoff, and terminal turn events. */
549
546
  declare class TurnRunner extends TurnRunner_base {
550
- static readonly Live: Layer.Layer<TurnRunner, never, EventFactory | IdGenerator | InferenceRunner | ToolExecutor>;
547
+ static readonly Live: Layer.Layer<TurnRunner, never, IdGenerator | EventFactory | InferenceRunner | ToolExecutor>;
551
548
  }
552
549
  //#endregion
553
550
  //#region src/services/session-state.d.ts
@@ -567,6 +564,120 @@ declare const SessionRunInput: Schema.Struct<{
567
564
  readonly systemPrompt: Schema.optionalKey<Schema.NonEmptyString>;
568
565
  }>;
569
566
  type SessionRunInput = typeof SessionRunInput.Type;
567
+ /** Command outcome when the command's run completed and the command was completed. */
568
+ declare const SessionCommandCompleted: Schema.TaggedStruct<"SessionCommandCompleted", {
569
+ readonly committed: Schema.Struct<{
570
+ readonly position: Schema.Struct<{
571
+ readonly seq: Schema.brand<Schema.Int, "SequenceNumber">;
572
+ readonly subSeq: Schema.brand<Schema.Literal<0>, "SubSequenceNumber">;
573
+ }>;
574
+ readonly event: Schema.Struct<{
575
+ readonly durability: Schema.Literal<"durable">;
576
+ readonly namespace: Schema.NonEmptyString;
577
+ readonly type: Schema.NonEmptyString;
578
+ readonly schemaVersion: Schema.Int;
579
+ readonly eventId: Schema.brand<Schema.String, "EventId">;
580
+ readonly sessionId: Schema.brand<Schema.String, "SessionId">;
581
+ readonly correlationId: Schema.optionalKey<Schema.brand<Schema.String, "CorrelationId">>;
582
+ readonly createdAtMs: Schema.brand<Schema.Int, "UnixEpochMillis">;
583
+ readonly trace: Schema.withConstructorDefault<Schema.Struct<{
584
+ readonly span: Schema.Struct<{
585
+ readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
586
+ readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
587
+ readonly sampled: Schema.Boolean;
588
+ readonly tracestate: Schema.NullOr<Schema.String>;
589
+ }>;
590
+ readonly links: Schema.$Array<Schema.Struct<{
591
+ readonly context: Schema.Struct<{
592
+ readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
593
+ readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
594
+ readonly sampled: Schema.Boolean;
595
+ readonly tracestate: Schema.NullOr<Schema.String>;
596
+ }>;
597
+ readonly attributes: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean]>>;
598
+ }>>;
599
+ }>>;
600
+ readonly payload: Schema.Unknown;
601
+ }>;
602
+ }>;
603
+ }>;
604
+ type SessionCommandCompleted = typeof SessionCommandCompleted.Type;
605
+ /** Command outcome when the command's run failed and the command was failed. */
606
+ declare const SessionCommandFailed: Schema.TaggedStruct<"SessionCommandFailed", {
607
+ readonly committed: Schema.Struct<{
608
+ readonly position: Schema.Struct<{
609
+ readonly seq: Schema.brand<Schema.Int, "SequenceNumber">;
610
+ readonly subSeq: Schema.brand<Schema.Literal<0>, "SubSequenceNumber">;
611
+ }>;
612
+ readonly event: Schema.Struct<{
613
+ readonly durability: Schema.Literal<"durable">;
614
+ readonly namespace: Schema.NonEmptyString;
615
+ readonly type: Schema.NonEmptyString;
616
+ readonly schemaVersion: Schema.Int;
617
+ readonly eventId: Schema.brand<Schema.String, "EventId">;
618
+ readonly sessionId: Schema.brand<Schema.String, "SessionId">;
619
+ readonly correlationId: Schema.optionalKey<Schema.brand<Schema.String, "CorrelationId">>;
620
+ readonly createdAtMs: Schema.brand<Schema.Int, "UnixEpochMillis">;
621
+ readonly trace: Schema.withConstructorDefault<Schema.Struct<{
622
+ readonly span: Schema.Struct<{
623
+ readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
624
+ readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
625
+ readonly sampled: Schema.Boolean;
626
+ readonly tracestate: Schema.NullOr<Schema.String>;
627
+ }>;
628
+ readonly links: Schema.$Array<Schema.Struct<{
629
+ readonly context: Schema.Struct<{
630
+ readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
631
+ readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
632
+ readonly sampled: Schema.Boolean;
633
+ readonly tracestate: Schema.NullOr<Schema.String>;
634
+ }>;
635
+ readonly attributes: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean]>>;
636
+ }>>;
637
+ }>>;
638
+ readonly payload: Schema.Unknown;
639
+ }>;
640
+ }>;
641
+ }>;
642
+ type SessionCommandFailed = typeof SessionCommandFailed.Type;
643
+ /** Command outcome when command work was cancelled by stop, interrupt, or recovery. */
644
+ declare const SessionCommandCancelled: Schema.TaggedStruct<"SessionCommandCancelled", {
645
+ readonly committed: Schema.Struct<{
646
+ readonly position: Schema.Struct<{
647
+ readonly seq: Schema.brand<Schema.Int, "SequenceNumber">;
648
+ readonly subSeq: Schema.brand<Schema.Literal<0>, "SubSequenceNumber">;
649
+ }>;
650
+ readonly event: Schema.Struct<{
651
+ readonly durability: Schema.Literal<"durable">;
652
+ readonly namespace: Schema.NonEmptyString;
653
+ readonly type: Schema.NonEmptyString;
654
+ readonly schemaVersion: Schema.Int;
655
+ readonly eventId: Schema.brand<Schema.String, "EventId">;
656
+ readonly sessionId: Schema.brand<Schema.String, "SessionId">;
657
+ readonly correlationId: Schema.optionalKey<Schema.brand<Schema.String, "CorrelationId">>;
658
+ readonly createdAtMs: Schema.brand<Schema.Int, "UnixEpochMillis">;
659
+ readonly trace: Schema.withConstructorDefault<Schema.Struct<{
660
+ readonly span: Schema.Struct<{
661
+ readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
662
+ readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
663
+ readonly sampled: Schema.Boolean;
664
+ readonly tracestate: Schema.NullOr<Schema.String>;
665
+ }>;
666
+ readonly links: Schema.$Array<Schema.Struct<{
667
+ readonly context: Schema.Struct<{
668
+ readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
669
+ readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
670
+ readonly sampled: Schema.Boolean;
671
+ readonly tracestate: Schema.NullOr<Schema.String>;
672
+ }>;
673
+ readonly attributes: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean]>>;
674
+ }>>;
675
+ }>>;
676
+ readonly payload: Schema.Unknown;
677
+ }>;
678
+ }>;
679
+ }>;
680
+ type SessionCommandCancelled = typeof SessionCommandCancelled.Type;
570
681
  /** Terminal command-processing variants returned from one control action. */
571
682
  declare const SessionCommandOutcome: Schema.Union<readonly [Schema.TaggedStruct<"SessionCommandCompleted", {
572
683
  readonly committed: Schema.Struct<{
@@ -680,6 +791,9 @@ interface SessionCommandResult {
680
791
  readonly started: CommittedDurableEvent;
681
792
  readonly outcome: SessionCommandOutcome;
682
793
  }
794
+ /** Why a control drain stopped without starting more command work. */
795
+ declare const SessionNoRunnableReason: Schema.Literals<readonly ["active-command", "no-pending-command"]>;
796
+ type SessionNoRunnableReason = typeof SessionNoRunnableReason.Type;
683
797
  /** Session control result when no admitted command is runnable. */
684
798
  declare const SessionNoRunnableCommand: Schema.TaggedStruct<"SessionNoRunnableCommand", {
685
799
  readonly reason: Schema.Literals<readonly ["active-command", "no-pending-command"]>;
@@ -740,30 +854,8 @@ interface SessionStateShape extends SessionEventSink {
740
854
  declare const SessionState_base: Context.ServiceClass<SessionState, "@effect-durable-agent/SessionState", SessionStateShape>;
741
855
  /** Internal authoritative live state and root control loop for one session. */
742
856
  declare class SessionState extends SessionState_base {
743
- static readonly Live: Layer.Layer<SessionState, EDASessionStoreError, CompactionRunner | EventFactory | IdGenerator | EDAKeepAlive | EDASinkRegistry | EDASessionStore | EDAReducerRegistry | LiveEventBus | SessionContext | EDAPromptProjector | TurnRunner>;
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, EDASessionStore | LiveEventBus | SessionState>;
857
+ static readonly Live: Layer.Layer<SessionState, EDASessionStoreError, EDAPromptProjector | EDASessionStore | LiveEventBus | EDAKeepAlive | IdGenerator | EventFactory | TurnRunner | CompactionRunner | SessionContext | EDAReducerRegistry | EDASinkRegistry>;
766
858
  }
767
859
  //#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-hxfujxUH.d.ts.map
860
+ 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 };
861
+ //# sourceMappingURL=session-state-CjOSvWbe.d.ts.map
@@ -1,15 +1,16 @@
1
1
  import { CommandId, InferenceId, MessageId, Position, RunId, SequenceNumber, SubSequenceNumber, TurnId } from "./types/core.js";
2
2
  import { CancelPendingMessageCommand, PromotePendingMessageCommand, ResumePendingMessagesCommand, StopTurnCommand, SubmitMessageCommand } from "./types/commands.js";
3
3
  import { makeEDARunTrace } from "./types/tracing.js";
4
- import { Dn as inferenceFailedEventType, En as inferenceCompletedEventType, Gn as toolCallRejectedEventType, Jn as turnFailedEventType, Un as toolCallCreatedEventType, _r as UsagePayload, cr as FailurePayload, dr as PositionedEvent, fr as ProviderPartId, hr as ToolName, lr as ModelSelectionPayload, mr as SystemPromptText, pn as commandAdmittedEventType, ur as NonNegativeInt } from "./durable-C3Rz7kg3.js";
5
- import { a as encodeReducedStateCheckpoint, h as assertNeverError, i as decodeReducedStateCheckpoint, l as initialReducedState, m as assertNever, n as activeTurnIdentityForCommand, o as foldReducedState, p as reducedStateCheckpointEventSeqs, r as classifyRecoverableWork, s as frameworkReducedStateReducerName } from "./reduced-state-C4nVVzz9.js";
6
- import { a as EDASessionStoreError, c as hasEDASessionStoreError, f as ContextProjection, i as EDASessionStore, p as emptyContextProjection, t as CommittedDurableEvent } from "./session-store-pYxQW9qh.js";
7
- import { durableMessageTranscript } from "./domain/message-transcript.js";
4
+ import { An as inferenceFailedEventType, Jn as toolCallRejectedEventType, Kn as toolCallCreatedEventType, Zn as turnFailedEventType, _r as SystemPromptText, br as UsagePayload, dr as FailurePayload, fr as ModelSelectionPayload, gn as commandAdmittedEventType, hr as ProviderPartId, kn as inferenceCompletedEventType, mr as PositionedEvent, pr as NonNegativeInt, vr as ToolName } from "./durable-DsV9PxZC.js";
5
+ import { a as encodeReducedStateCheckpoint, h as assertNeverError, i as decodeReducedStateCheckpoint, l as initialReducedState, m as assertNever, n as activeTurnIdentityForCommand, o as foldReducedState, p as reducedStateCheckpointEventSeqs, r as classifyRecoverableWork, s as frameworkReducedStateReducerName } from "./reduced-state-TMi7ISla.js";
6
+ import { ContextProjection, emptyContextProjection } from "./domain/context-projection.js";
7
+ import { CommittedDurableEvent, EDASessionStore, EDASessionStoreError, hasEDASessionStoreError } from "./services/session-store.js";
8
8
  import { IdGenerator } from "./services/id-generator.js";
9
- import { n as EventFactory, r as SessionContext, t as EDAKeepAlive } from "./keep-alive-p8dIcSVy.js";
9
+ import { n as SessionContext, t as EventFactory } from "./event-factory-tcpLgdMN.js";
10
10
  import { annotateEdaSpan, committedBatchAttributes, edaTraceContextFromSpan, eventBatchAttributes, toEdaExternalSpan, usageAttributes } from "./services/tracing.js";
11
+ import { EDAKeepAlive } from "./services/keep-alive.js";
11
12
  import { CompactionRunner } from "./services/compaction.js";
12
- import { i as LiveEventBus, n as EDASinkRegistry } from "./sink-registry-CFC6xjsN.js";
13
+ import { n as EDASinkRegistry, r as LiveEventBus } from "./sink-registry-D13eUO_c.js";
13
14
  import { EDAPromptProjector, buildEDAPrompt } from "./services/prompt-projector.js";
14
15
  import { EDAReducerRegistry, decodeReducerState, encodeReducerState, reducerSchemaVersion } from "./services/reducer-registry.js";
15
16
  import { EDAToolRegistry } from "./services/tool-registry.js";
@@ -29,7 +30,6 @@ import * as Scope from "effect/Scope";
29
30
  import * as Semaphore from "effect/Semaphore";
30
31
  import * as LanguageModel from "effect/unstable/ai/LanguageModel";
31
32
  import * as Option from "effect/Option";
32
- import * as PubSub from "effect/PubSub";
33
33
  import * as Response from "effect/unstable/ai/Response";
34
34
  //#region src/domain/dispatch-policy.ts
35
35
  /** Durable/runtime evidence for active work blocking new queued commands. */
@@ -1431,7 +1431,10 @@ const requireInferenceFailed = (committed) => {
1431
1431
  const failed = committed.find(isInferenceFailed);
1432
1432
  return failed === void 0 ? Effect.die(/* @__PURE__ */ new Error("InferenceRunFailed did not include InferenceFailed")) : Effect.succeed(failed);
1433
1433
  };
1434
- Schema.Struct({
1434
+ //#endregion
1435
+ //#region src/services/session-state.ts
1436
+ /** Input for one session control pass or long-lived control process. */
1437
+ const SessionRunInput = Schema.Struct({
1435
1438
  modelSelection: ModelSelectionPayload,
1436
1439
  maxToolCallsPerRun: Schema.optionalKey(NonNegativeInt),
1437
1440
  systemPrompt: Schema.optionalKey(SystemPromptText)
@@ -1442,7 +1445,8 @@ const SessionCommandCompleted = Schema.TaggedStruct("SessionCommandCompleted", {
1442
1445
  const SessionCommandFailed = Schema.TaggedStruct("SessionCommandFailed", { committed: CommittedDurableEvent });
1443
1446
  /** Command outcome when command work was cancelled by stop, interrupt, or recovery. */
1444
1447
  const SessionCommandCancelled = Schema.TaggedStruct("SessionCommandCancelled", { committed: CommittedDurableEvent });
1445
- Schema.Union([
1448
+ /** Terminal command-processing variants returned from one control action. */
1449
+ const SessionCommandOutcome = Schema.Union([
1446
1450
  SessionCommandCompleted,
1447
1451
  SessionCommandFailed,
1448
1452
  SessionCommandCancelled
@@ -1553,7 +1557,7 @@ const makeLiveSessionState = Effect.gen(function* () {
1553
1557
  }));
1554
1558
  const buildReducerCheckpointSnapshot = (snapshot) => [{
1555
1559
  name: frameworkReducedStateReducerName,
1556
- schemaVersion: 4,
1560
+ schemaVersion: 5,
1557
1561
  throughSeq: snapshot.reduced.lastSeq,
1558
1562
  payload: encodeReducedStateCheckpoint(snapshot.reduced),
1559
1563
  updatedAtMs: snapshot.updatedAtMs
@@ -2735,8 +2739,8 @@ const hydrateReducedStateCheckpoint = (store, checkpoint) => Effect.gen(function
2735
2739
  });
2736
2740
  const hydrateFrameworkReducedState = (store) => Effect.gen(function* () {
2737
2741
  const checkpoint = yield* store.loadReducerCheckpoint(frameworkReducedStateReducerName);
2738
- const checkpointState = checkpoint === void 0 || checkpoint.schemaVersion !== 4 ? initialReducedState : yield* hydrateReducedStateCheckpoint(store, checkpoint);
2739
- const checkpointSeq = checkpoint === void 0 || checkpoint.schemaVersion !== 4 ? SequenceNumber.make(0) : checkpoint.throughSeq;
2742
+ const checkpointState = checkpoint === void 0 || checkpoint.schemaVersion !== 5 ? initialReducedState : yield* hydrateReducedStateCheckpoint(store, checkpoint);
2743
+ const checkpointSeq = checkpoint === void 0 || checkpoint.schemaVersion !== 5 ? SequenceNumber.make(0) : checkpoint.throughSeq;
2740
2744
  return {
2741
2745
  state: foldReducedState(checkpointState, yield* store.eventsAfter(checkpointSeq).pipe(Stream.runCollect, Effect.map((events) => Array.from(events)))),
2742
2746
  checkpointSeq
@@ -2818,69 +2822,6 @@ const requireTurnFailed = (committed) => isTurnFailed(committed) ? Effect.succee
2818
2822
  const isTurnFailed = (committed) => committed.event.type === turnFailedEventType;
2819
2823
  const isSessionNoRunnableCommand = (result) => "_tag" in result && result._tag === "SessionNoRunnableCommand";
2820
2824
  //#endregion
2821
- //#region src/services/session-query.ts
2822
- /** Read-only session query facade backed by authoritative SessionState plus durable backfill. */
2823
- var EDASessionQuery = class EDASessionQuery extends Context.Service()("@effect-durable-agent/EDASessionQuery") {
2824
- static Live = Layer.effect(EDASessionQuery, Effect.gen(function* () {
2825
- const store = yield* EDASessionStore;
2826
- const liveBus = yield* LiveEventBus;
2827
- const sessionState = yield* SessionState;
2828
- const snapshot = Effect.gen(function* () {
2829
- const data = yield* sessionState.snapshotData();
2830
- return {
2831
- state: data.reduced,
2832
- reducerStates: data.reducerStates,
2833
- messages: durableMessageTranscript(data.reduced)
2834
- };
2835
- });
2836
- return {
2837
- snapshot: () => snapshot,
2838
- messages: () => snapshot.pipe(Effect.map((snapshot) => snapshot.messages)),
2839
- eventsAfter: (afterSeq) => Effect.gen(function* () {
2840
- const live = yield* liveBus.subscribeQueue();
2841
- const replayHead = (yield* sessionState.snapshot()).lastSeq;
2842
- const replay = yield* store.eventsAfter(afterSeq).pipe(Stream.filter((entry) => entry.position.seq <= replayHead), Stream.map((entry) => PositionedEvent.make({
2843
- position: entry.position,
2844
- event: entry.event
2845
- })), Stream.runCollect, Effect.map((events) => Array.from(events)));
2846
- const activeTurnReplay = yield* liveBus.activeTurnReplay();
2847
- const pendingLive = (yield* PubSub.takeUpTo(live, Number.POSITIVE_INFINITY)).filter((event) => shouldEmitLiveEvent(event, replayHead));
2848
- const reconnectPrefix = Array.from(uniquePositionedEvents([
2849
- ...replay,
2850
- ...activeTurnReplay.events,
2851
- ...pendingLive
2852
- ])).sort(comparePositionedEvents);
2853
- yield* annotateEdaSpan({
2854
- "eda.seq.after": afterSeq,
2855
- "eda.seq.head": replayHead,
2856
- "eda.replay.events": replay.length,
2857
- "eda.live.active_turn_events": activeTurnReplay.events.length,
2858
- "eda.live.active_turn_overflowed": activeTurnReplay.overflowed,
2859
- "eda.live.buffered_events": pendingLive.length
2860
- });
2861
- const follow = Stream.fromEffectRepeat(PubSub.take(live)).pipe(Stream.filter((event) => shouldEmitLiveEvent(event, replayHead)));
2862
- return Stream.fromIterable(reconnectPrefix).pipe(Stream.concat(follow));
2863
- }).pipe(Effect.withSpan("agent.events.follow", { attributes: { "eda.seq.after": afterSeq } }))
2864
- };
2865
- }));
2866
- };
2867
- const shouldEmitLiveEvent = (event, replayHead) => event.event.durability === "ephemeral" || event.position.seq > replayHead;
2868
- const comparePositionedEvents = (left, right) => {
2869
- const seq = left.position.seq - right.position.seq;
2870
- return seq === 0 ? left.position.subSeq - right.position.subSeq : seq;
2871
- };
2872
- const uniquePositionedEvents = (events) => {
2873
- const seen = /* @__PURE__ */ new Set();
2874
- const output = [];
2875
- for (const event of events) {
2876
- const key = `${event.position.seq}:${event.position.subSeq}:${event.event.eventId}`;
2877
- if (seen.has(key)) continue;
2878
- seen.add(key);
2879
- output.push(event);
2880
- }
2881
- return output;
2882
- };
2883
- //#endregion
2884
- export { ToolExecutor as a, InferenceRunner as i, SessionState as n, TurnRunner as r, EDASessionQuery as t };
2825
+ export { SessionCommandOutcome as a, SessionNoRunnableReason as c, TurnRunner as d, InferenceRunner as f, SessionCommandFailed as i, SessionRunInput as l, SessionCommandCancelled as n, SessionForkedCommand as o, ToolExecutor as p, SessionCommandCompleted as r, SessionNoRunnableCommand as s, SessionCommandAdmissionConflict as t, SessionState as u };
2885
2826
 
2886
- //# sourceMappingURL=session-query-Cbf-e0rG.js.map
2827
+ //# sourceMappingURL=session-state-SStf0KUo.js.map