effect-durable-agent 0.1.0-alpha.1 → 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 (136) hide show
  1. package/CHANGELOG.md +25 -1
  2. package/README.md +131 -128
  3. package/SECURITY.md +3 -4
  4. package/dist/{command-queues-CQ9cwRP7.d.ts → command-queues-CV7O-51r.d.ts} +7 -6
  5. package/dist/{compaction-YayFKo_1.d.ts → compaction-zbvLREI8.d.ts} +8 -6
  6. package/dist/context-projection-n6Rdup0N.d.ts +140 -0
  7. package/dist/{core-Hv3cFydL.d.ts → core-CYT6DBaS.d.ts} +2 -2
  8. package/dist/domain/command-queues.d.ts +1 -1
  9. package/dist/domain/context-projection.d.ts +2 -0
  10. package/dist/domain/context-projection.js +32 -0
  11. package/dist/domain/context-projection.js.map +1 -0
  12. package/dist/domain/message-transcript.d.ts +1 -1
  13. package/dist/domain/reduced-state-schema.d.ts +2 -0
  14. package/dist/domain/reduced-state-schema.js +2 -1
  15. package/dist/domain/reduced-state-schema.js.map +1 -1
  16. package/dist/domain/reduced-state.d.ts +1 -1
  17. package/dist/domain/reduced-state.js +1 -1
  18. package/dist/{durable-DlScwmCy.d.ts → durable-B7M6TD_0.d.ts} +341 -2
  19. package/dist/{durable-C3Rz7kg3.js → durable-DsV9PxZC.js} +13 -2
  20. package/dist/durable-DsV9PxZC.js.map +1 -0
  21. package/dist/{keep-alive-DYDsH6qN.d.ts → event-factory-CLJcyymV.d.ts} +5 -29
  22. package/dist/{keep-alive-p8dIcSVy.js → event-factory-tcpLgdMN.js} +3 -10
  23. package/dist/event-factory-tcpLgdMN.js.map +1 -0
  24. package/dist/host/websocket-protocol.d.ts +229 -0
  25. package/dist/host/websocket-protocol.js +99 -0
  26. package/dist/host/websocket-protocol.js.map +1 -0
  27. package/dist/host/websocket-wire.d.ts +2 -2
  28. package/dist/host/websocket-wire.js +37 -20
  29. package/dist/host/websocket-wire.js.map +1 -1
  30. package/dist/{id-generator-C2Q15uZM.d.ts → id-generator-Ckl8_XWW.d.ts} +2 -2
  31. package/dist/index.d.ts +4 -4
  32. package/dist/index.js +2 -2
  33. package/dist/keep-alive-Chl5SJxy.d.ts +29 -0
  34. package/dist/{message-transcript-BCHdHAe2.d.ts → message-transcript-DiOPBY3l.d.ts} +3 -3
  35. package/dist/{prompt-projector-9_02lk5-.d.ts → prompt-projector-C1IbkHr0.d.ts} +15 -16
  36. package/dist/{reduced-state-C4nVVzz9.js → reduced-state-TMi7ISla.js} +20 -4
  37. package/dist/reduced-state-TMi7ISla.js.map +1 -0
  38. package/dist/{reducer-registry-C0svUa63.d.ts → reducer-registry-CjSJBPKo.d.ts} +2 -2
  39. package/dist/{runtime-C56FQxiL.d.ts → runtime-DOgmAKsO.d.ts} +7 -6
  40. package/dist/services/compaction.d.ts +1 -1
  41. package/dist/services/compaction.js +4 -3
  42. package/dist/services/compaction.js.map +1 -1
  43. package/dist/services/id-generator.d.ts +1 -1
  44. package/dist/services/keep-alive.d.ts +2 -0
  45. package/dist/services/keep-alive.js +13 -0
  46. package/dist/services/keep-alive.js.map +1 -0
  47. package/dist/services/prompt-projector.d.ts +2 -2
  48. package/dist/services/prompt-projector.js +20 -10
  49. package/dist/services/prompt-projector.js.map +1 -1
  50. package/dist/services/reducer-registry.d.ts +1 -1
  51. package/dist/services/runtime-layer.d.ts +58 -0
  52. package/dist/services/runtime-layer.js +42 -0
  53. package/dist/services/runtime-layer.js.map +1 -0
  54. package/dist/services/runtime.d.ts +1 -1
  55. package/dist/services/runtime.js +4 -3
  56. package/dist/services/runtime.js.map +1 -1
  57. package/dist/services/session-query.d.ts +1 -1
  58. package/dist/services/session-query.js +76 -1
  59. package/dist/services/session-query.js.map +1 -0
  60. package/dist/services/session-state.d.ts +2 -0
  61. package/dist/services/session-state.js +2 -0
  62. package/dist/services/session-store.d.ts +2 -2
  63. package/dist/services/session-store.js +181 -2
  64. package/dist/services/session-store.js.map +1 -0
  65. package/dist/services/sink-checkpoint-store.d.ts +2 -0
  66. package/dist/services/sink-checkpoint-store.js +49 -0
  67. package/dist/services/sink-checkpoint-store.js.map +1 -0
  68. package/dist/services/sink-registry.d.ts +1 -1
  69. package/dist/services/sink-registry.js +1 -1
  70. package/dist/services/tool-registry.d.ts +1 -1
  71. package/dist/services/websocket-subscriber.d.ts +54 -0
  72. package/dist/services/websocket-subscriber.js +190 -0
  73. package/dist/services/websocket-subscriber.js.map +1 -0
  74. package/dist/session-query-C-C4m1eq.d.ts +38 -0
  75. package/dist/{session-query-DlRo5Ufc.d.ts → session-state-CjOSvWbe.d.ts} +132 -40
  76. package/dist/{session-query-DOc1KanA.js → session-state-SStf0KUo.js} +43 -146
  77. package/dist/session-state-SStf0KUo.js.map +1 -0
  78. package/dist/{session-store-D2Ore1QC.d.ts → session-store-DZZUffUy.d.ts} +5 -94
  79. package/dist/sink-checkpoint-store-BZmQFTRE.d.ts +40 -0
  80. package/dist/{sink-registry-CIU0LD3m.d.ts → sink-registry-Cf79ICdW.d.ts} +11 -40
  81. package/dist/{sink-registry-CFC6xjsN.js → sink-registry-D13eUO_c.js} +9 -47
  82. package/dist/sink-registry-D13eUO_c.js.map +1 -0
  83. package/dist/testkit/layers.d.ts +14 -11
  84. package/dist/testkit/layers.js +8 -5
  85. package/dist/testkit/layers.js.map +1 -1
  86. package/dist/{tool-registry-CcnkAAQK.d.ts → tool-registry-B7Wona6N.d.ts} +3 -3
  87. package/dist/types/core.d.ts +1 -1
  88. package/dist/types/core.js +1 -1
  89. package/dist/types/core.js.map +1 -1
  90. package/dist/types/events/durable.d.ts +2 -2
  91. package/dist/types/events/durable.js +2 -2
  92. package/dist/types/events.d.ts +2 -2
  93. package/dist/types/events.js +2 -2
  94. package/dist/websocket-wire-QD2SquQE.d.ts +2244 -0
  95. package/docs/assets/architecture.svg +170 -60
  96. package/docs/assets/event-sequence.svg +68 -78
  97. package/docs/assets/hero.svg +33 -0
  98. package/docs/message-steering.md +1 -1
  99. package/docs/releasing.md +96 -39
  100. package/docs/spec.md +15 -12
  101. package/docs/websocket-protocol.md +35 -9
  102. package/package.json +55 -35
  103. package/dist/durable-C3Rz7kg3.js.map +0 -1
  104. package/dist/durable-object-runtime-B7jwBY2R.js +0 -1494
  105. package/dist/durable-object-runtime-B7jwBY2R.js.map +0 -1
  106. package/dist/durable-object-runtime-pWv0ohlz.d.ts +0 -257
  107. package/dist/durable-object-storage-Czy7IPrh.d.ts +0 -41
  108. package/dist/host/durable-object-runtime.d.ts +0 -2
  109. package/dist/host/durable-object-runtime.js +0 -2
  110. package/dist/host/durable-object-storage.d.ts +0 -2
  111. package/dist/host/durable-object-storage.js +0 -0
  112. package/dist/host/durable-object.d.ts +0 -83
  113. package/dist/host/durable-object.js +0 -191
  114. package/dist/host/durable-object.js.map +0 -1
  115. package/dist/keep-alive-p8dIcSVy.js.map +0 -1
  116. package/dist/reduced-state-C4nVVzz9.js.map +0 -1
  117. package/dist/session-query-DOc1KanA.js.map +0 -1
  118. package/dist/session-store-pYxQW9qh.js +0 -214
  119. package/dist/session-store-pYxQW9qh.js.map +0 -1
  120. package/dist/sink-registry-CFC6xjsN.js.map +0 -1
  121. package/dist/websocket-wire-DvOu_6BJ.d.ts +0 -16773
  122. package/examples/001-no-tools/README.md +0 -65
  123. package/examples/001-no-tools/worker.ts +0 -79
  124. package/examples/002-slack-bridge/README.md +0 -134
  125. package/examples/002-slack-bridge/events.ts +0 -115
  126. package/examples/002-slack-bridge/reducer.ts +0 -216
  127. package/examples/002-slack-bridge/scenario.test.ts +0 -223
  128. package/examples/002-slack-bridge/sinks.ts +0 -109
  129. package/examples/002-slack-bridge/worker.ts +0 -140
  130. package/examples/003-sandbox-lifecycle/README.md +0 -78
  131. package/examples/003-sandbox-lifecycle/events.ts +0 -203
  132. package/examples/003-sandbox-lifecycle/reducer.ts +0 -305
  133. package/examples/003-sandbox-lifecycle/scenario.test.ts +0 -202
  134. package/examples/_shared/event-id.ts +0 -12
  135. package/examples/_shared/http.ts +0 -27
  136. package/examples/_shared/openai.ts +0 -33
@@ -1,15 +1,16 @@
1
1
  import { CommandId, InferenceId, MessageId, Position, RunId, SequenceNumber, SubSequenceNumber, TurnId } from "./types/core.js";
2
- import { CancelPendingMessageCommand, PromotePendingMessageCommand, ResumePendingMessagesCommand, StopTurnCommand, SubmitMessageCommand, UserMessageContent } from "./types/commands.js";
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
@@ -1937,23 +1941,28 @@ const makeLiveSessionState = Effect.gen(function* () {
1937
1941
  });
1938
1942
  const closeRunTraceOnFailure = (trace, effect) => effect.pipe(Effect.onExit((exit) => Exit.isFailure(exit) ? Scope.close(trace.runScope, exit) : Effect.void));
1939
1943
  const startTurn = Effect.fn(function* (input) {
1940
- const inputMessageIds = input.promptInput.selectedUserMessages.map((message) => message.messageId);
1941
- const prompt = yield* buildEDAPrompt(promptProjector, input.promptInput);
1942
1944
  const turnId = yield* ids.makeTurnId();
1943
- const current = yield* currentReduced();
1945
+ const started = yield* appendDurable(yield* events.turnStarted({
1946
+ runId: input.runId,
1947
+ turnId,
1948
+ ...input.inputMessageIds.length === 0 ? {} : { inputMessageIds: input.inputMessageIds }
1949
+ }));
1950
+ const promptState = yield* currentData();
1951
+ const prompt = yield* buildEDAPrompt(promptProjector, {
1952
+ sessionId: sessionContext.sessionId,
1953
+ state: promptState.reduced,
1954
+ reducerStates: promptState.reducerStates,
1955
+ context: yield* contextProjectionFor(promptState.reduced)
1956
+ });
1957
+ const current = promptState.reduced;
1944
1958
  const remainingToolCalls = remainingToolCallsForRun(current, input.runId, input.maxToolCallsPerRun ?? defaultMaxToolCallsPerRun);
1945
1959
  const remainingToolRejectionCorrections = remainingToolRejectionCorrectionsForRun(current, input.runId, NonNegativeInt.make(maxToolRejectionCorrections));
1946
1960
  yield* annotateEdaSpan({
1947
1961
  "eda.command.id": input.commandId,
1948
1962
  "eda.run.id": input.runId,
1949
1963
  "eda.turn.id": turnId,
1950
- "eda.message.input_count": inputMessageIds.length
1964
+ "eda.message.input_count": input.inputMessageIds.length
1951
1965
  });
1952
- const started = yield* appendDurable(yield* events.turnStarted({
1953
- runId: input.runId,
1954
- turnId,
1955
- ...inputMessageIds.length === 0 ? {} : { inputMessageIds }
1956
- }));
1957
1966
  const turnScope = yield* Scope.fork(input.runScope, "sequential");
1958
1967
  const fiber = yield* keepAlive.withActiveWork(`turn:${turnId}`, turnRunner.runTurn({
1959
1968
  runId: input.runId,
@@ -2014,30 +2023,17 @@ const makeLiveSessionState = Effect.gen(function* () {
2014
2023
  modelSelection: input.modelSelection,
2015
2024
  trace: activeRunTrace.runTrace
2016
2025
  });
2017
- const startedEvents = yield* appendDurableBatch([
2018
- commandStarted,
2019
- ...userMessage === void 0 ? [] : [userMessage],
2020
- runStarted
2021
- ]);
2022
- const selectedUserContent = submittedMessage === void 0 ? submit.content : Schema.decodeUnknownSync(UserMessageContent)(submittedMessage.content);
2023
- const promptState = yield* currentData();
2024
2026
  return yield* startTurn({
2025
2027
  commandId,
2026
- commandStarted: startedEvents[0],
2028
+ commandStarted: (yield* appendDurableBatch([
2029
+ commandStarted,
2030
+ ...userMessage === void 0 ? [] : [userMessage],
2031
+ runStarted
2032
+ ]))[0],
2033
+ inputMessageIds: [messageId],
2027
2034
  runId,
2028
2035
  modelSelection: input.modelSelection,
2029
2036
  ...input.maxToolCallsPerRun === void 0 ? {} : { maxToolCallsPerRun: input.maxToolCallsPerRun },
2030
- promptInput: {
2031
- sessionId: sessionContext.sessionId,
2032
- state: promptState.reduced,
2033
- reducerStates: promptState.reducerStates,
2034
- context: yield* contextProjectionFor(promptState.reduced),
2035
- selectedUserMessages: [{
2036
- commandId,
2037
- content: selectedUserContent,
2038
- messageId
2039
- }]
2040
- },
2041
2037
  runScope: activeRunTrace.runScope,
2042
2038
  runSpan: activeRunTrace.runSpan
2043
2039
  });
@@ -2069,20 +2065,10 @@ const makeLiveSessionState = Effect.gen(function* () {
2069
2065
  return yield* startTurn({
2070
2066
  commandId: command.commandId,
2071
2067
  commandStarted: started[0],
2068
+ inputMessageIds: pending.map((message) => message.messageId),
2072
2069
  runId,
2073
2070
  modelSelection: input.modelSelection,
2074
2071
  ...input.maxToolCallsPerRun === void 0 ? {} : { maxToolCallsPerRun: input.maxToolCallsPerRun },
2075
- promptInput: {
2076
- sessionId: sessionContext.sessionId,
2077
- state: current.reduced,
2078
- reducerStates: current.reducerStates,
2079
- context: yield* contextProjectionFor(current.reduced),
2080
- selectedUserMessages: pending.map((message) => ({
2081
- commandId: message.commandId,
2082
- content: message.content,
2083
- messageId: message.messageId
2084
- }))
2085
- },
2086
2072
  runScope: activeRunTrace.runScope,
2087
2073
  runSpan: activeRunTrace.runSpan
2088
2074
  });
@@ -2302,20 +2288,10 @@ const makeLiveSessionState = Effect.gen(function* () {
2302
2288
  yield* startTurn({
2303
2289
  commandId: continuation.command.commandId,
2304
2290
  commandStarted,
2291
+ inputMessageIds: pendingInputs.map((message) => message.messageId),
2305
2292
  runId: continuation.runId,
2306
2293
  modelSelection: input.modelSelection,
2307
2294
  ...input.maxToolCallsPerRun === void 0 ? {} : { maxToolCallsPerRun: input.maxToolCallsPerRun },
2308
- promptInput: {
2309
- sessionId: sessionContext.sessionId,
2310
- state: promptState.reduced,
2311
- reducerStates: promptState.reducerStates,
2312
- context: yield* contextProjectionFor(promptState.reduced),
2313
- selectedUserMessages: pendingInputs.map((message) => ({
2314
- commandId: message.commandId,
2315
- content: message.content,
2316
- messageId: message.messageId
2317
- }))
2318
- },
2319
2295
  runScope: continuation.runScope,
2320
2296
  runSpan: continuation.runSpan
2321
2297
  });
@@ -2556,36 +2532,20 @@ const makeLiveSessionState = Effect.gen(function* () {
2556
2532
  case "ContinueWithSteering": return yield* startTurn({
2557
2533
  commandId: active.commandId,
2558
2534
  commandStarted: active.commandStarted,
2535
+ inputMessageIds: continuation.steerings.map((steering) => steering.messageId),
2559
2536
  runId: active.runId,
2560
2537
  modelSelection: active.modelSelection,
2561
2538
  ...active.maxToolCallsPerRun === void 0 ? {} : { maxToolCallsPerRun: active.maxToolCallsPerRun },
2562
- promptInput: {
2563
- sessionId: sessionContext.sessionId,
2564
- state: current,
2565
- reducerStates: (yield* currentData()).reducerStates,
2566
- context: yield* contextProjectionFor(current),
2567
- selectedUserMessages: continuation.steerings.map((steering) => ({
2568
- commandId: steering.commandId,
2569
- content: steering.content,
2570
- messageId: steering.messageId
2571
- }))
2572
- },
2573
2539
  runScope: active.runScope,
2574
2540
  runSpan: active.runSpan
2575
2541
  });
2576
2542
  case "ContinueWithToolFeedback": return yield* startTurn({
2577
2543
  commandId: active.commandId,
2578
2544
  commandStarted: active.commandStarted,
2545
+ inputMessageIds: [],
2579
2546
  runId: active.runId,
2580
2547
  modelSelection: active.modelSelection,
2581
2548
  ...active.maxToolCallsPerRun === void 0 ? {} : { maxToolCallsPerRun: active.maxToolCallsPerRun },
2582
- promptInput: {
2583
- sessionId: sessionContext.sessionId,
2584
- state: current,
2585
- reducerStates: (yield* currentData()).reducerStates,
2586
- context: yield* contextProjectionFor(current),
2587
- selectedUserMessages: []
2588
- },
2589
2549
  runScope: active.runScope,
2590
2550
  runSpan: active.runSpan
2591
2551
  });
@@ -2779,8 +2739,8 @@ const hydrateReducedStateCheckpoint = (store, checkpoint) => Effect.gen(function
2779
2739
  });
2780
2740
  const hydrateFrameworkReducedState = (store) => Effect.gen(function* () {
2781
2741
  const checkpoint = yield* store.loadReducerCheckpoint(frameworkReducedStateReducerName);
2782
- const checkpointState = checkpoint === void 0 || checkpoint.schemaVersion !== 4 ? initialReducedState : yield* hydrateReducedStateCheckpoint(store, checkpoint);
2783
- 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;
2784
2744
  return {
2785
2745
  state: foldReducedState(checkpointState, yield* store.eventsAfter(checkpointSeq).pipe(Stream.runCollect, Effect.map((events) => Array.from(events)))),
2786
2746
  checkpointSeq
@@ -2862,69 +2822,6 @@ const requireTurnFailed = (committed) => isTurnFailed(committed) ? Effect.succee
2862
2822
  const isTurnFailed = (committed) => committed.event.type === turnFailedEventType;
2863
2823
  const isSessionNoRunnableCommand = (result) => "_tag" in result && result._tag === "SessionNoRunnableCommand";
2864
2824
  //#endregion
2865
- //#region src/services/session-query.ts
2866
- /** Read-only session query facade backed by authoritative SessionState plus durable backfill. */
2867
- var EDASessionQuery = class EDASessionQuery extends Context.Service()("@effect-durable-agent/EDASessionQuery") {
2868
- static Live = Layer.effect(EDASessionQuery, Effect.gen(function* () {
2869
- const store = yield* EDASessionStore;
2870
- const liveBus = yield* LiveEventBus;
2871
- const sessionState = yield* SessionState;
2872
- const snapshot = Effect.gen(function* () {
2873
- const data = yield* sessionState.snapshotData();
2874
- return {
2875
- state: data.reduced,
2876
- reducerStates: data.reducerStates,
2877
- messages: durableMessageTranscript(data.reduced)
2878
- };
2879
- });
2880
- return {
2881
- snapshot: () => snapshot,
2882
- messages: () => snapshot.pipe(Effect.map((snapshot) => snapshot.messages)),
2883
- eventsAfter: (afterSeq) => Effect.gen(function* () {
2884
- const live = yield* liveBus.subscribeQueue();
2885
- const replayHead = (yield* sessionState.snapshot()).lastSeq;
2886
- const replay = yield* store.eventsAfter(afterSeq).pipe(Stream.filter((entry) => entry.position.seq <= replayHead), Stream.map((entry) => PositionedEvent.make({
2887
- position: entry.position,
2888
- event: entry.event
2889
- })), Stream.runCollect, Effect.map((events) => Array.from(events)));
2890
- const activeTurnReplay = yield* liveBus.activeTurnReplay();
2891
- const pendingLive = (yield* PubSub.takeUpTo(live, Number.POSITIVE_INFINITY)).filter((event) => shouldEmitLiveEvent(event, replayHead));
2892
- const reconnectPrefix = Array.from(uniquePositionedEvents([
2893
- ...replay,
2894
- ...activeTurnReplay.events,
2895
- ...pendingLive
2896
- ])).sort(comparePositionedEvents);
2897
- yield* annotateEdaSpan({
2898
- "eda.seq.after": afterSeq,
2899
- "eda.seq.head": replayHead,
2900
- "eda.replay.events": replay.length,
2901
- "eda.live.active_turn_events": activeTurnReplay.events.length,
2902
- "eda.live.active_turn_overflowed": activeTurnReplay.overflowed,
2903
- "eda.live.buffered_events": pendingLive.length
2904
- });
2905
- const follow = Stream.fromEffectRepeat(PubSub.take(live)).pipe(Stream.filter((event) => shouldEmitLiveEvent(event, replayHead)));
2906
- return Stream.fromIterable(reconnectPrefix).pipe(Stream.concat(follow));
2907
- }).pipe(Effect.withSpan("agent.events.follow", { attributes: { "eda.seq.after": afterSeq } }))
2908
- };
2909
- }));
2910
- };
2911
- const shouldEmitLiveEvent = (event, replayHead) => event.event.durability === "ephemeral" || event.position.seq > replayHead;
2912
- const comparePositionedEvents = (left, right) => {
2913
- const seq = left.position.seq - right.position.seq;
2914
- return seq === 0 ? left.position.subSeq - right.position.subSeq : seq;
2915
- };
2916
- const uniquePositionedEvents = (events) => {
2917
- const seen = /* @__PURE__ */ new Set();
2918
- const output = [];
2919
- for (const event of events) {
2920
- const key = `${event.position.seq}:${event.position.subSeq}:${event.event.eventId}`;
2921
- if (seen.has(key)) continue;
2922
- seen.add(key);
2923
- output.push(event);
2924
- }
2925
- return output;
2926
- };
2927
- //#endregion
2928
- 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 };
2929
2826
 
2930
- //# sourceMappingURL=session-query-DOc1KanA.js.map
2827
+ //# sourceMappingURL=session-state-SStf0KUo.js.map