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

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 (77) hide show
  1. package/README.md +19 -18
  2. package/dist/{command-queues-CV7O-51r.d.ts → command-queues-Dwdf41mq.d.ts} +2 -2
  3. package/dist/{compaction-zbvLREI8.d.ts → compaction-DpHOf-g7.d.ts} +5 -5
  4. package/dist/{context-projection-n6Rdup0N.d.ts → context-projection-B4DWOZgi.d.ts} +3 -3
  5. package/dist/domain/command-queues.d.ts +1 -1
  6. package/dist/domain/context-projection.d.ts +1 -1
  7. package/dist/domain/message-transcript.d.ts +1 -1
  8. package/dist/domain/reduced-state.d.ts +1 -1
  9. package/dist/host/websocket-protocol.d.ts +26 -3
  10. package/dist/host/websocket-protocol.js +16 -4
  11. package/dist/host/websocket-protocol.js.map +1 -1
  12. package/dist/host/websocket-wire.d.ts +2 -2
  13. package/dist/host/websocket-wire.js +19 -2
  14. package/dist/host/websocket-wire.js.map +1 -1
  15. package/dist/index.d.ts +1 -1
  16. package/dist/{message-transcript-DiOPBY3l.d.ts → message-transcript-CFn_D3MH.d.ts} +3 -3
  17. package/dist/{prompt-projector-C1IbkHr0.d.ts → prompt-projector-C2meuNrV.d.ts} +4 -4
  18. package/dist/{reducer-registry-CjSJBPKo.d.ts → reducer-registry-K9FqZq5-.d.ts} +2 -2
  19. package/dist/{runtime-DOgmAKsO.d.ts → runtime-5NEJngu3.d.ts} +10 -5
  20. package/dist/services/compaction.d.ts +1 -1
  21. package/dist/services/prompt-projector.d.ts +1 -1
  22. package/dist/services/reducer-registry.d.ts +1 -1
  23. package/dist/services/runtime-layer.d.ts +9 -9
  24. package/dist/services/runtime-layer.js +2 -2
  25. package/dist/services/runtime.d.ts +1 -1
  26. package/dist/services/runtime.js +6 -2
  27. package/dist/services/runtime.js.map +1 -1
  28. package/dist/services/session-query.d.ts +2 -2
  29. package/dist/services/session-query.js +20 -3
  30. package/dist/services/session-query.js.map +1 -1
  31. package/dist/services/session-state.d.ts +1 -1
  32. package/dist/services/session-state.js +1 -1
  33. package/dist/services/session-store.d.ts +1 -1
  34. package/dist/services/session-store.js +1 -1
  35. package/dist/services/sink-checkpoint-store.d.ts +1 -1
  36. package/dist/services/sink-registry.d.ts +1 -1
  37. package/dist/services/sink-registry.js +1 -1
  38. package/dist/services/span-names.d.ts +1 -1
  39. package/dist/services/span-names.js +1 -0
  40. package/dist/services/span-names.js.map +1 -1
  41. package/dist/services/tool-registry.d.ts +1 -1
  42. package/dist/services/websocket-delivery.d.ts +90 -0
  43. package/dist/services/websocket-delivery.js +221 -0
  44. package/dist/services/websocket-delivery.js.map +1 -0
  45. package/dist/{session-query-C-C4m1eq.d.ts → session-query-5oyZRaQL.d.ts} +16 -9
  46. package/dist/{session-state-CjOSvWbe.d.ts → session-state-CI1xeT6f.d.ts} +11 -11
  47. package/dist/{session-state-SStf0KUo.js → session-state-D7dqko7r.js} +3 -3
  48. package/dist/{session-state-SStf0KUo.js.map → session-state-D7dqko7r.js.map} +1 -1
  49. package/dist/{session-store-DZZUffUy.d.ts → session-store-BLg6UvZa.d.ts} +2 -2
  50. package/dist/{sink-checkpoint-store-BZmQFTRE.d.ts → sink-checkpoint-store-B9WNvDtY.d.ts} +2 -2
  51. package/dist/{sink-registry-D13eUO_c.js → sink-registry-BbmoI9uv.js} +17 -24
  52. package/dist/sink-registry-BbmoI9uv.js.map +1 -0
  53. package/dist/{sink-registry-Cf79ICdW.d.ts → sink-registry-CO3YPS1p.d.ts} +26 -14
  54. package/dist/testkit/layers.d.ts +10 -10
  55. package/dist/testkit/layers.js +3 -3
  56. package/dist/{tool-registry-B7Wona6N.d.ts → tool-registry-B8H1P6Pu.d.ts} +2 -2
  57. package/dist/{websocket-wire-QD2SquQE.d.ts → websocket-wire-DPxwY4G5.d.ts} +39 -10
  58. package/package.json +11 -23
  59. package/testing/offline-trace/README.md +2 -1
  60. package/CHANGELOG.md +0 -34
  61. package/CONTRIBUTING.md +0 -26
  62. package/SECURITY.md +0 -7
  63. package/dist/services/websocket-subscriber.d.ts +0 -54
  64. package/dist/services/websocket-subscriber.js +0 -190
  65. package/dist/services/websocket-subscriber.js.map +0 -1
  66. package/dist/sink-registry-D13eUO_c.js.map +0 -1
  67. package/docs/assets/architecture.svg +0 -216
  68. package/docs/assets/event-sequence.svg +0 -133
  69. package/docs/assets/gcp-trace.png +0 -0
  70. package/docs/assets/hero.svg +0 -33
  71. package/docs/message-steering.md +0 -831
  72. package/docs/releasing.md +0 -114
  73. package/docs/spec.md +0 -777
  74. package/docs/subagents.md +0 -725
  75. package/docs/testing.md +0 -64
  76. package/docs/ui-projection.md +0 -742
  77. package/docs/websocket-protocol.md +0 -639
@@ -1,7 +1,7 @@
1
1
  import { _ as SummaryId, h as SessionId, m as SequenceNumber, n as CommandId } from "./core-CYT6DBaS.js";
2
2
  import { n as CommandIdempotencyKey } from "./commands-Ce1ec6kH.js";
3
3
  import { D as DurableEventEnvelope } from "./events-Bb9-Cu-7.js";
4
- import { r as CompactionSummaryArtifact } from "./context-projection-n6Rdup0N.js";
4
+ import { r as CompactionSummaryArtifact } from "./context-projection-B4DWOZgi.js";
5
5
  import * as Context from "effect/Context";
6
6
  import * as Effect from "effect/Effect";
7
7
  import * as Layer from "effect/Layer";
@@ -203,4 +203,4 @@ declare class EDASessionStore extends EDASessionStore_base {
203
203
  }
204
204
  //#endregion
205
205
  export { EDASessionStore as a, FindCommandAdmissionInput as c, EDAReducerCheckpoint as i, SaveReducerCheckpointInput as l, DurableAppendBatch as n, EDASessionStoreError as o, DurableAppendEntry as r, EDASessionStoreShape as s, CommittedDurableEvent as t, hasEDASessionStoreError as u };
206
- //# sourceMappingURL=session-store-DZZUffUy.d.ts.map
206
+ //# sourceMappingURL=session-store-BLg6UvZa.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { m as SequenceNumber } from "./core-CYT6DBaS.js";
2
- import { o as EDASessionStoreError } from "./session-store-DZZUffUy.js";
2
+ import { o as EDASessionStoreError } from "./session-store-BLg6UvZa.js";
3
3
  import * as Context from "effect/Context";
4
4
  import * as Effect from "effect/Effect";
5
5
  import * as Layer from "effect/Layer";
@@ -37,4 +37,4 @@ declare class SinkCheckpointStore extends SinkCheckpointStore_base {
37
37
  }
38
38
  //#endregion
39
39
  export { StoredSinkCheckpoint as i, SinkCheckpointStore as n, SinkCheckpointStoreShape as r, EDASinkName as t };
40
- //# sourceMappingURL=sink-checkpoint-store-BZmQFTRE.d.ts.map
40
+ //# sourceMappingURL=sink-checkpoint-store-B9WNvDtY.d.ts.map
@@ -13,12 +13,10 @@ import * as Effect from "effect/Effect";
13
13
  import * as Layer from "effect/Layer";
14
14
  import * as Schema from "effect/Schema";
15
15
  import * as Stream from "effect/Stream";
16
- import * as Cause from "effect/Cause";
16
+ import * as PubSub from "effect/PubSub";
17
17
  import * as Ref from "effect/Ref";
18
+ import * as Cause from "effect/Cause";
18
19
  import * as Scope from "effect/Scope";
19
- import * as PubSub from "effect/PubSub";
20
- import * as Duration from "effect/Duration";
21
- import * as Schedule from "effect/Schedule";
22
20
  import * as SynchronizedRef from "effect/SynchronizedRef";
23
21
  //#region src/services/live-event-bus.ts
24
22
  /** Conservative raw-delta cap for one open turn's live-only reconnect replay. */
@@ -29,15 +27,17 @@ var LiveEventBus = class LiveEventBus extends Context.Service()("@effect-durable
29
27
  return makeLiveBus(yield* Effect.acquireRelease(PubSub.unbounded(), PubSub.shutdown), yield* Ref.make({
30
28
  events: [],
31
29
  overflowed: false
32
- }));
30
+ }), yield* Ref.make([]));
33
31
  }));
34
32
  };
35
- const makeLiveBus = (pubsub, activeTurnReplay) => ({
36
- publish: (event) => updateActiveTurnReplay(activeTurnReplay, event).pipe(Effect.andThen(PubSub.publish(pubsub, event))),
33
+ const makeLiveBus = (pubsub, activeTurnReplay, listeners) => ({
34
+ publish: (event) => updateActiveTurnReplay(activeTurnReplay, event).pipe(Effect.andThen(notifyDeliveryListeners(listeners, event)), Effect.andThen(PubSub.publish(pubsub, event))),
37
35
  subscribeQueue: () => PubSub.subscribe(pubsub),
38
36
  subscribe: () => Effect.map(PubSub.subscribe(pubsub), (subscription) => Stream.fromEffectRepeat(PubSub.take(subscription))),
39
- activeTurnReplay: () => Ref.get(activeTurnReplay)
37
+ activeTurnReplay: () => Ref.get(activeTurnReplay),
38
+ registerDeliveryListener: (listener) => Ref.update(listeners, (current) => [...current, listener])
40
39
  });
40
+ const notifyDeliveryListeners = (listeners, event) => Ref.get(listeners).pipe(Effect.flatMap((current) => Effect.forEach(current, (listener) => listener(event).pipe(Effect.catchCause((cause) => Effect.logWarning("EDA live delivery listener defected", cause))), { discard: true })));
41
41
  const updateActiveTurnReplay = (ref, event) => Ref.update(ref, (state) => nextActiveTurnReplay(state, event));
42
42
  const nextActiveTurnReplay = (state, event) => {
43
43
  if (event.event.type === turnStartedEventType) return {
@@ -79,9 +79,7 @@ var EDASinkRegistry = class EDASinkRegistry extends Context.Service()("@effect-d
79
79
  static Live = (sinks) => Layer.effect(EDASinkRegistry, makeSinkRegistry(sinks));
80
80
  };
81
81
  const defaultBatchSize = 100;
82
- const maxDurableSinkRetryDelay = Duration.seconds(5);
83
82
  const sinkCheckpointFormatVersion = 1;
84
- const durableSinkRetrySchedule = Schedule.exponential("100 millis").pipe(Schedule.jittered, Schedule.modifyDelay(({ duration }) => Effect.succeed(Duration.min(duration, maxDurableSinkRetryDelay))));
85
83
  const makeSinkRegistry = (sinks) => Effect.gen(function* () {
86
84
  const session = yield* SessionContext;
87
85
  const store = yield* EDASessionStore;
@@ -126,14 +124,16 @@ const makeSinkRegistry = (sinks) => Effect.gen(function* () {
126
124
  const eventsForSink = durable === void 0 ? [] : filterInterested(fresh, durable.interests);
127
125
  if (durable !== void 0 && eventsForSink.length > 0) yield* Effect.gen(function* () {
128
126
  const staged = [];
129
- yield* durable.process({
127
+ if ((yield* durable.process({
130
128
  allEvents: fresh,
131
129
  events: eventsForSink,
132
130
  stateAfter: nextReduced,
133
131
  reducerStates: nextReducerStates,
134
132
  throughSeq
135
- }, baseContext(staged, input.publishEphemeral, input.scope, checkpoint));
136
- if (staged.length > 0) {
133
+ }, 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", {
134
+ cause: Cause.pretty(cause),
135
+ sink: sink.name
136
+ }).pipe(Effect.as(false))))) && staged.length > 0) {
137
137
  yield* annotateEdaSpan({ "eda.sink.staged_events": staged.length });
138
138
  yield* input.appendDurableBatch(staged);
139
139
  }
@@ -151,17 +151,14 @@ const makeSinkRegistry = (sinks) => Effect.gen(function* () {
151
151
  reducerStates: nextReducerStates
152
152
  });
153
153
  });
154
- const processDurableBatchWithRetry = (events) => keepAlive.withActiveWork(`sink:${sink.name}`, processDurableBatch(events).pipe(Effect.tapError((error) => Effect.logWarning("EDA sink durable projection failed; retrying", {
155
- error: formatSinkError(error),
156
- sink: sink.name
157
- })), Effect.retry(durableSinkRetrySchedule)));
154
+ const processDurableBatchWithKeepAlive = (events) => keepAlive.withActiveWork(`sink:${sink.name}`, processDurableBatch(events));
158
155
  const drainDurablesThrough = (targetHead) => Effect.gen(function* () {
159
156
  while (true) {
160
157
  const current = yield* Ref.get(state);
161
158
  if (current.cursor >= targetHead) return;
162
159
  const allEvents = yield* readCursorBatchThrough(store, current.cursor, targetHead, sink.durable?.batchSize);
163
160
  if (allEvents.length === 0) return;
164
- yield* processDurableBatchWithRetry(allEvents);
161
+ yield* processDurableBatchWithKeepAlive(allEvents);
165
162
  }
166
163
  });
167
164
  const processLiveDurable = (event) => Effect.gen(function* () {
@@ -177,7 +174,7 @@ const makeSinkRegistry = (sinks) => Effect.gen(function* () {
177
174
  });
178
175
  return;
179
176
  }
180
- yield* processDurableBatchWithRetry([committedDurableFromPositioned(event)]);
177
+ yield* processDurableBatchWithKeepAlive([committedDurableFromPositioned(event)]);
181
178
  });
182
179
  const processLiveEphemeral = (event) => Effect.gen(function* () {
183
180
  const before = yield* Ref.get(state);
@@ -264,11 +261,7 @@ const committedDurableFromPositioned = (event) => CommittedDurableEvent.make({
264
261
  });
265
262
  const filterInterested = (events, interests) => events.filter((event) => matchesInterest(event.event.type, interests));
266
263
  const matchesInterest = (type, interests) => interests === void 0 || interests.some((interest) => interest === type);
267
- const formatSinkError = (error) => {
268
- if (Cause.isUnknownError(error)) return `${error.message ?? error._tag}: ${formatSinkError(error.cause)}`;
269
- return error instanceof Error ? error.message : String(error);
270
- };
271
264
  //#endregion
272
265
  export { EDASinkRegistry as n, LiveEventBus as r, EDASink as t };
273
266
 
274
- //# sourceMappingURL=sink-registry-D13eUO_c.js.map
267
+ //# sourceMappingURL=sink-registry-BbmoI9uv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sink-registry-BbmoI9uv.js","names":[],"sources":["../src/services/live-event-bus.ts","../src/services/sink-registry.ts"],"sourcesContent":["import * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as PubSub from \"effect/PubSub\";\nimport * as Ref from \"effect/Ref\";\nimport type * as Scope from \"effect/Scope\";\nimport * as Stream from \"effect/Stream\";\n\nimport { TurnId } from \"../types/core\";\nimport {\n PositionedEvent,\n turnCompletedEventType,\n turnFailedEventType,\n turnStartedEventType,\n turnStoppedEventType,\n} from \"../types/events\";\n\n/** Conservative raw-delta cap for one open turn's live-only reconnect replay. */\nexport const activeTurnEphemeralReplayCapacity = 4_096;\n\n/** Live-only replay buffer for the currently open turn. */\nexport interface ActiveTurnEphemeralReplay {\n readonly turnId?: TurnId;\n readonly events: ReadonlyArray<PositionedEvent>;\n readonly overflowed: boolean;\n}\n\n/**\n * Push-delivery listener invoked inline as each event is published.\n *\n * Listeners let hibernation-capable hosts fan events out to accepted\n * WebSockets during the already-active turn instead of parking a resident\n * subscriber fiber on the pub/sub. Listeners must not fail; defects are\n * logged and never interrupt the publishing turn.\n */\nexport type LiveDeliveryListener = (event: PositionedEvent) => Effect.Effect<void>;\n\n/** In-memory live fanout plus active-turn replay source for reconnect streams. */\nexport interface LiveEventBusShape {\n readonly publish: (event: PositionedEvent) => Effect.Effect<boolean>;\n readonly subscribe: () => Effect.Effect<Stream.Stream<PositionedEvent>, never, Scope.Scope>;\n readonly subscribeQueue: () => Effect.Effect<\n PubSub.Subscription<PositionedEvent>,\n never,\n Scope.Scope\n >;\n /** Snapshot raw live-only events retained for the currently open turn. */\n readonly activeTurnReplay: () => Effect.Effect<ActiveTurnEphemeralReplay>;\n /** Register one push-delivery listener invoked inline on every published event. */\n readonly registerDeliveryListener: (listener: LiveDeliveryListener) => Effect.Effect<void>;\n}\n\n/** Unbounded in-memory fanout plus bounded active-turn ephemeral replay. */\nexport class LiveEventBus extends Context.Service<LiveEventBus, LiveEventBusShape>()(\n \"@effect-durable-agent/LiveEventBus\",\n) {\n static readonly Live = Layer.effect(\n LiveEventBus,\n Effect.gen(function* () {\n const pubsub = yield* Effect.acquireRelease(\n PubSub.unbounded<PositionedEvent>(),\n PubSub.shutdown,\n );\n const activeTurnReplay = yield* Ref.make<ActiveTurnEphemeralReplay>({\n events: [],\n overflowed: false,\n });\n const listeners = yield* Ref.make<ReadonlyArray<LiveDeliveryListener>>([]);\n return makeLiveBus(pubsub, activeTurnReplay, listeners);\n }),\n );\n}\n\nconst makeLiveBus = (\n pubsub: PubSub.PubSub<PositionedEvent>,\n activeTurnReplay: Ref.Ref<ActiveTurnEphemeralReplay>,\n listeners: Ref.Ref<ReadonlyArray<LiveDeliveryListener>>,\n): LiveEventBusShape => ({\n publish: (event) =>\n updateActiveTurnReplay(activeTurnReplay, event).pipe(\n Effect.andThen(notifyDeliveryListeners(listeners, event)),\n Effect.andThen(PubSub.publish(pubsub, event)),\n ),\n subscribeQueue: () => PubSub.subscribe(pubsub),\n subscribe: () =>\n Effect.map(PubSub.subscribe(pubsub), (subscription) =>\n Stream.fromEffectRepeat(PubSub.take(subscription)),\n ),\n activeTurnReplay: () => Ref.get(activeTurnReplay),\n registerDeliveryListener: (listener) =>\n Ref.update(listeners, (current) => [...current, listener]),\n});\n\nconst notifyDeliveryListeners = (\n listeners: Ref.Ref<ReadonlyArray<LiveDeliveryListener>>,\n event: PositionedEvent,\n): Effect.Effect<void> =>\n Ref.get(listeners).pipe(\n Effect.flatMap((current) =>\n Effect.forEach(\n current,\n (listener) =>\n listener(event).pipe(\n Effect.catchCause((cause) =>\n Effect.logWarning(\"EDA live delivery listener defected\", cause),\n ),\n ),\n { discard: true },\n ),\n ),\n );\n\nconst updateActiveTurnReplay = (\n ref: Ref.Ref<ActiveTurnEphemeralReplay>,\n event: PositionedEvent,\n): Effect.Effect<void> => Ref.update(ref, (state) => nextActiveTurnReplay(state, event));\n\nconst nextActiveTurnReplay = (\n state: ActiveTurnEphemeralReplay,\n event: PositionedEvent,\n): ActiveTurnEphemeralReplay => {\n if (event.event.type === turnStartedEventType) {\n return {\n turnId: (event.event.payload as { readonly turnId: TurnId }).turnId,\n events: [],\n overflowed: false,\n };\n }\n\n if (\n event.event.type === turnCompletedEventType ||\n event.event.type === turnFailedEventType ||\n event.event.type === turnStoppedEventType\n ) {\n const turnId = (event.event.payload as { readonly turnId?: TurnId }).turnId;\n return turnId === undefined || state.turnId === undefined || turnId === state.turnId\n ? { events: [], overflowed: false }\n : state;\n }\n\n if (event.event.durability !== \"ephemeral\" || state.turnId === undefined) {\n return state;\n }\n\n const events = [...state.events, event];\n if (events.length <= activeTurnEphemeralReplayCapacity) {\n return { ...state, events };\n }\n return {\n ...state,\n events: events.slice(events.length - activeTurnEphemeralReplayCapacity),\n overflowed: true,\n };\n};\n","import * as Cause from \"effect/Cause\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport * as PubSub from \"effect/PubSub\";\nimport * as Ref from \"effect/Ref\";\nimport * as Schema from \"effect/Schema\";\nimport * as Scope from \"effect/Scope\";\nimport * as Stream from \"effect/Stream\";\nimport * as SynchronizedRef from \"effect/SynchronizedRef\";\n\nimport {\n foldReducedState,\n reduceCommittedEvents,\n type ReducedState,\n} from \"../domain/reduced-state\";\nimport { EDAReducerRegistry, type EDAReducerStateSnapshot } from \"./reducer-registry\";\nimport { EventId, SessionId, SequenceNumber, durablePosition } from \"../types/core\";\nimport type {\n DurableEventEnvelope,\n EphemeralEventEnvelope,\n EventType,\n PositionedEvent,\n} from \"../types/events\";\nimport type { EDASessionStoreShape } from \"./session-store\";\nimport { CommittedDurableEvent, EDASessionStore, EDASessionStoreError } from \"./session-store\";\nimport { EventFactory } from \"./event-factory\";\nimport type { EventFactoryShape } from \"./event-factory\";\nimport { IdGenerator } from \"./id-generator\";\nimport { EDAKeepAlive } from \"./keep-alive\";\nimport { LiveEventBus } from \"./live-event-bus\";\nimport { SessionContext } from \"./session-context\";\nimport {\n EDASinkName,\n SinkCheckpointStore,\n type SinkCheckpointStoreShape,\n type StoredSinkCheckpoint,\n} from \"./sink-checkpoint-store\";\nimport { annotateEdaSpan } from \"./tracing\";\n\n/** Cursor-window input delivered to one durable sink drain. */\nexport interface EDASinkDurableBatch {\n /** All durable events replayed for this cursor window, including uninterested events. */\n readonly allEvents: ReadonlyArray<CommittedDurableEvent>;\n /** Events matching the sink's durable interests. */\n readonly events: ReadonlyArray<CommittedDurableEvent>;\n /** Authoritative reduced state folded exactly through `throughSeq`. */\n readonly stateAfter: ReducedState;\n /** App-specific durable reducer states folded exactly through `throughSeq`. */\n readonly reducerStates: EDAReducerStateSnapshot;\n /** Durable sequence through which the sink may advance after success. */\n readonly throughSeq: SequenceNumber;\n}\n\n/** Typed, sink-owned durable state stored independently from cursor advancement. */\nexport interface EDASinkCheckpoint {\n /** Decode current durable state, or return `initial` for a new or legacy cursor row. */\n readonly get: <State>(\n schema: Schema.Codec<State, unknown, never, never>,\n initial: State,\n ) => Effect.Effect<State, EDASessionStoreError>;\n /** Validate, encode, and durably save state without advancing the sink cursor. */\n readonly save: <State>(\n schema: Schema.Codec<State, unknown, never, never>,\n state: State,\n ) => Effect.Effect<void, EDASessionStoreError>;\n}\n\n/** Capabilities exposed to sink processors without granting raw store or bus access. */\nexport interface EDASinkContext {\n readonly sessionId: SessionId;\n /** Sink-owned checkpoint state, serialized with cursor commits and background writes. */\n readonly checkpoint: EDASinkCheckpoint;\n /** Build a framework durable event if the sink needs to emit one. */\n readonly events: EventFactoryShape;\n /** Mint an app durable event id for staged custom events. */\n readonly makeEventId: () => Effect.Effect<EventId>;\n /** Publish a best-effort live-only event. */\n readonly emitEphemeral: (\n event: EphemeralEventEnvelope,\n ) => Effect.Effect<PositionedEvent, EDASessionStoreError>;\n /** Stage durable events; the runner commits them after the sink succeeds. */\n readonly stageDurable: (event: DurableEventEnvelope) => Effect.Effect<void>;\n /** Fork background sink work into the session scope. */\n readonly forkScoped: (effect: Effect.Effect<unknown, unknown>) => Effect.Effect<void>;\n}\n\n/** Durable sink definition backed by a checkpoint and an app-owned delivery policy. */\nexport interface EDADurableSinkDefinition {\n readonly interests?: ReadonlyArray<EventType | string>;\n readonly batchSize?: number;\n readonly process: (batch: EDASinkDurableBatch, ctx: EDASinkContext) => Effect.Effect<void, never>;\n}\n\n/** Best-effort live-only sink definition. */\nexport interface EDAEphemeralSinkDefinition {\n readonly interests?: ReadonlyArray<EventType | string>;\n readonly process: (event: PositionedEvent, ctx: EDASinkContext) => Effect.Effect<void, never>;\n}\n\n/**\n * Named app integration hook with optional durable and ephemeral filters.\n *\n * Every sink runs on one serialized position-ordered lane. Sinks own retry and\n * terminal failure handling, so callbacks must have an infallible typed error\n * channel. An unexpected defect is logged and skipped before the durable checkpoint\n * advances. Ephemeral callbacks are best-effort and are only processed after the\n * durable prefix at their anchor sequence has been projected.\n */\nexport interface EDASink {\n readonly name: string;\n readonly durable?: EDADurableSinkDefinition;\n readonly ephemeral?: EDAEphemeralSinkDefinition;\n}\n\n/** Convenience constructor preserving a sink's literal name/type information. */\nexport const EDASink = {\n make: <const Sink extends EDASink>(sink: Sink): Sink => sink,\n};\n\n/** Session-owned capabilities needed to start all registered sink runners. */\nexport interface EDASinkRunnerStartInput {\n readonly appendDurableBatch: (\n events: ReadonlyArray<DurableEventEnvelope>,\n ) => Effect.Effect<ReadonlyArray<CommittedDurableEvent>, EDASessionStoreError>;\n readonly initialHead: SequenceNumber;\n readonly publishEphemeral: (\n event: EphemeralEventEnvelope,\n ) => Effect.Effect<PositionedEvent, EDASessionStoreError>;\n readonly scope: Scope.Scope;\n}\n\n/** Registry service coordinating durable checkpoints and live sink delivery. */\nexport interface EDASinkRegistryShape {\n readonly sinks: ReadonlyArray<EDASink>;\n /** Start long-lived sink runners. Safe to call once during session-state acquisition. */\n readonly startSinkRunners: (\n input: EDASinkRunnerStartInput,\n ) => Effect.Effect<void, EDASessionStoreError>;\n /** Coalesced non-blocking nudge that the durable log head advanced. */\n readonly notifyDurableHeadAdvanced: (head: SequenceNumber) => Effect.Effect<void>;\n /** Best-effort non-blocking delivery to ephemeral sink workers. */\n readonly publishEphemeralToSinks: (\n event: PositionedEvent,\n publishEphemeral: (\n event: EphemeralEventEnvelope,\n ) => Effect.Effect<PositionedEvent, EDASessionStoreError>,\n ) => Effect.Effect<void>;\n}\n\n/** Registry and runner for app-provided EDA sinks. */\nexport class EDASinkRegistry extends Context.Service<EDASinkRegistry, EDASinkRegistryShape>()(\n \"@effect-durable-agent/EDASinkRegistry\",\n) {\n static readonly Empty = Layer.succeed(EDASinkRegistry, {\n sinks: [],\n startSinkRunners: () => Effect.void,\n notifyDurableHeadAdvanced: () => Effect.void,\n publishEphemeralToSinks: () => Effect.void,\n } satisfies EDASinkRegistryShape);\n\n static readonly Live = (sinks: ReadonlyArray<EDASink>) =>\n Layer.effect(EDASinkRegistry, makeSinkRegistry(sinks));\n}\n\nconst defaultBatchSize = 100;\nconst sinkCheckpointFormatVersion = 1;\n\ninterface DurableRunnerState {\n readonly cursor: SequenceNumber;\n readonly reduced: ReducedState;\n readonly reducerStates: EDAReducerStateSnapshot;\n}\n\ninterface SerializedSinkState {\n readonly formatVersion: typeof sinkCheckpointFormatVersion;\n readonly state: unknown;\n readonly updatedAtMs: number;\n}\n\nconst makeSinkRegistry = (sinks: ReadonlyArray<EDASink>) =>\n Effect.gen(function* () {\n const session = yield* SessionContext;\n const store = yield* EDASessionStore;\n const liveBus = yield* LiveEventBus;\n const checkpointStore = yield* SinkCheckpointStore;\n const eventFactory = yield* EventFactory;\n const ids = yield* IdGenerator;\n const reducerRegistry = yield* EDAReducerRegistry;\n const keepAlive = yield* EDAKeepAlive;\n const started = yield* Ref.make(false);\n\n const baseContext = (\n staged: Array<DurableEventEnvelope>,\n publishEphemeral: (\n event: EphemeralEventEnvelope,\n ) => Effect.Effect<PositionedEvent, EDASessionStoreError>,\n scope: Scope.Scope,\n checkpoint: EDASinkCheckpoint,\n ): EDASinkContext => ({\n sessionId: session.sessionId,\n checkpoint,\n events: eventFactory,\n makeEventId: ids.makeEventId,\n emitEphemeral: publishEphemeral,\n stageDurable: (event) => Effect.sync(() => staged.push(event)),\n forkScoped: (effect) => effect.pipe(Effect.forkIn(scope), Effect.asVoid),\n });\n\n const makeSinkRunner = (sink: EDASink, input: EDASinkRunnerStartInput) =>\n Effect.gen(function* () {\n const sinkName = EDASinkName.make(sink.name);\n const storedCheckpoint = yield* checkpointStore.load(sinkName);\n const checkpointRef = yield* SynchronizedRef.make(storedCheckpoint);\n const checkpoint = makeSinkCheckpoint(checkpointStore, sinkName, checkpointRef);\n const cursor = storedCheckpoint.afterSeq;\n const prefix = yield* readDurablePrefixThrough(store, cursor);\n const state = yield* Ref.make<DurableRunnerState>({\n cursor,\n reduced: reduceCommittedEvents(prefix),\n reducerStates: reducerRegistry.reduce(reducerRegistry.initial, prefix),\n });\n const live = yield* liveBus.subscribeQueue().pipe(Scope.provide(input.scope));\n\n const processDurableBatch = Effect.fnUntraced(function* (\n allEvents: ReadonlyArray<CommittedDurableEvent>,\n ) {\n if (allEvents.length === 0) {\n return;\n }\n\n const current = yield* Ref.get(state);\n const fresh = allEvents.filter((entry) => entry.position.seq > current.cursor);\n if (fresh.length === 0) {\n return;\n }\n\n const durable = sink.durable;\n const throughSeq = fresh.at(-1)!.position.seq;\n const nextReduced = foldReducedState(current.reduced, fresh);\n const nextReducerStates = reducerRegistry.reduce(current.reducerStates, fresh);\n const eventsForSink =\n durable === undefined ? [] : filterInterested(fresh, durable.interests);\n\n if (durable !== undefined && eventsForSink.length > 0) {\n yield* Effect.gen(function* () {\n const staged: Array<DurableEventEnvelope> = [];\n const completed = yield* durable\n .process(\n {\n allEvents: fresh,\n events: eventsForSink,\n stateAfter: nextReduced,\n reducerStates: nextReducerStates,\n throughSeq,\n },\n baseContext(staged, input.publishEphemeral, input.scope, checkpoint),\n )\n .pipe(\n Effect.as(true),\n Effect.catchCause((cause) =>\n Cause.hasInterruptsOnly(cause)\n ? Effect.failCause(cause)\n : Effect.logError(\"EDA durable sink violated its infallible contract\", {\n cause: Cause.pretty(cause),\n sink: sink.name,\n }).pipe(Effect.as(false)),\n ),\n );\n if (completed && staged.length > 0) {\n yield* annotateEdaSpan({ \"eda.sink.staged_events\": staged.length });\n yield* input.appendDurableBatch(staged);\n }\n }).pipe(\n Effect.withSpan(\"agent.sink.drain\", {\n attributes: {\n \"eda.sink.name\": sink.name,\n \"eda.sink.cursor.before\": current.cursor,\n \"eda.sink.events.read\": fresh.length,\n \"eda.sink.events.interested\": eventsForSink.length,\n \"eda.sink.cursor.after\": throughSeq,\n },\n }),\n );\n }\n\n yield* commitSinkCheckpoint(checkpointStore, sinkName, checkpointRef, throughSeq);\n yield* Ref.set(state, {\n cursor: throughSeq,\n reduced: nextReduced,\n reducerStates: nextReducerStates,\n });\n });\n\n const processDurableBatchWithKeepAlive = (events: ReadonlyArray<CommittedDurableEvent>) =>\n keepAlive.withActiveWork(`sink:${sink.name}`, processDurableBatch(events));\n\n const drainDurablesThrough = (targetHead: SequenceNumber) =>\n Effect.gen(function* () {\n while (true) {\n const current = yield* Ref.get(state);\n if (current.cursor >= targetHead) {\n return;\n }\n const allEvents = yield* readCursorBatchThrough(\n store,\n current.cursor,\n targetHead,\n sink.durable?.batchSize,\n );\n if (allEvents.length === 0) {\n return;\n }\n yield* processDurableBatchWithKeepAlive(allEvents);\n }\n });\n\n const processLiveDurable = (event: PositionedEvent) =>\n Effect.gen(function* () {\n const current = yield* Ref.get(state);\n if (event.position.seq <= current.cursor) {\n return;\n }\n if (event.position.seq > current.cursor + 1) {\n yield* drainDurablesThrough(SequenceNumber.make(event.position.seq - 1));\n }\n const afterCatchup = yield* Ref.get(state);\n if (event.position.seq > afterCatchup.cursor + 1) {\n yield* Effect.logWarning(\"EDA sink runner could not catch up before live durable\", {\n cursor: afterCatchup.cursor,\n eventSeq: event.position.seq,\n sink: sink.name,\n });\n return;\n }\n yield* processDurableBatchWithKeepAlive([committedDurableFromPositioned(event)]);\n });\n\n const processLiveEphemeral = (event: PositionedEvent) =>\n Effect.gen(function* () {\n const before = yield* Ref.get(state);\n if (event.position.seq < before.cursor) {\n return;\n }\n if (event.position.seq > before.cursor) {\n yield* drainDurablesThrough(event.position.seq);\n }\n const after = yield* Ref.get(state);\n if (event.position.seq !== after.cursor) {\n return;\n }\n if (\n sink.ephemeral === undefined ||\n !matchesInterest(event.event.type, sink.ephemeral.interests)\n ) {\n return;\n }\n yield* sink.ephemeral\n .process(event, baseContext([], input.publishEphemeral, input.scope, checkpoint))\n .pipe(\n Effect.catchCause((cause) =>\n Effect.logError(\"EDA sink ephemeral projection failed\", {\n cause: String(cause),\n sink: sink.name,\n }),\n ),\n );\n });\n\n const processLiveEvent = (event: PositionedEvent) =>\n event.event.durability === \"durable\"\n ? processLiveDurable(event)\n : processLiveEphemeral(event);\n\n const runLoop = Effect.gen(function* () {\n yield* drainDurablesThrough(input.initialHead);\n return yield* Effect.forever(\n Effect.gen(function* () {\n const event = yield* PubSub.take(live);\n yield* processLiveEvent(event);\n }),\n );\n }).pipe(\n Effect.catchCause((cause) =>\n Effect.logError(\"EDA sink runner failed\", {\n cause: Cause.pretty(cause),\n sink: sink.name,\n }),\n ),\n );\n\n yield* runLoop.pipe(Effect.forkIn(input.scope));\n });\n\n return {\n sinks,\n startSinkRunners: Effect.fnUntraced(function* (input: EDASinkRunnerStartInput) {\n const wasStarted = yield* Ref.getAndSet(started, true);\n if (wasStarted) {\n return;\n }\n yield* Effect.forEach(sinks, (sink) => makeSinkRunner(sink, input), {\n discard: true,\n concurrency: \"unbounded\",\n });\n }),\n notifyDurableHeadAdvanced: () => Effect.void,\n publishEphemeralToSinks: () => Effect.void,\n } satisfies EDASinkRegistryShape;\n });\n\nconst readDurablePrefixThrough = (store: EDASessionStoreShape, throughSeq: SequenceNumber) => {\n if (throughSeq <= SequenceNumber.make(0)) {\n return Effect.succeed([]);\n }\n return store.eventsAfter(SequenceNumber.make(0)).pipe(\n Stream.takeWhile((event) => event.position.seq <= throughSeq),\n Stream.runCollect,\n Effect.map((events) => Array.from(events)),\n );\n};\n\nconst makeSinkCheckpoint = (\n store: SinkCheckpointStoreShape,\n sinkName: EDASinkName,\n checkpointRef: SynchronizedRef.SynchronizedRef<StoredSinkCheckpoint>,\n): EDASinkCheckpoint => ({\n get: (schema, initial) =>\n SynchronizedRef.get(checkpointRef).pipe(\n Effect.flatMap((checkpoint) => {\n const serialized = serializedSinkState(checkpoint.payload);\n return serialized === undefined\n ? Effect.succeed(initial)\n : decodeSinkState(schema, serialized.state);\n }),\n ),\n save: (schema, state) =>\n encodeSinkState(schema, state).pipe(\n Effect.flatMap((encoded) => {\n const payload: SerializedSinkState = {\n formatVersion: sinkCheckpointFormatVersion,\n state: encoded,\n updatedAtMs: Date.now(),\n };\n return SynchronizedRef.modifyEffect(checkpointRef, (checkpoint) =>\n store.saveState(sinkName, payload).pipe(\n Effect.as([\n undefined,\n {\n afterSeq: checkpoint.afterSeq,\n payload,\n },\n ] as const),\n ),\n );\n }),\n ),\n});\n\nconst commitSinkCheckpoint = (\n store: SinkCheckpointStoreShape,\n sinkName: EDASinkName,\n checkpointRef: SynchronizedRef.SynchronizedRef<StoredSinkCheckpoint>,\n afterSeq: SequenceNumber,\n): Effect.Effect<void, EDASessionStoreError> =>\n SynchronizedRef.modifyEffect(checkpointRef, (checkpoint) =>\n store.commit(sinkName, afterSeq, checkpoint.payload).pipe(\n Effect.as([\n undefined,\n {\n afterSeq,\n payload: checkpoint.payload,\n },\n ] as const),\n ),\n );\n\nconst serializedSinkState = (payload: unknown): SerializedSinkState | undefined => {\n if (\n typeof payload !== \"object\" ||\n payload === null ||\n !(\"formatVersion\" in payload) ||\n payload.formatVersion !== sinkCheckpointFormatVersion ||\n !(\"state\" in payload) ||\n !(\"updatedAtMs\" in payload) ||\n typeof payload.updatedAtMs !== \"number\"\n ) {\n return undefined;\n }\n return {\n formatVersion: sinkCheckpointFormatVersion,\n state: payload.state,\n updatedAtMs: payload.updatedAtMs,\n };\n};\n\nconst decodeSinkState = <State>(\n schema: Schema.Codec<State, unknown, never, never>,\n encoded: unknown,\n): Effect.Effect<State, EDASessionStoreError> =>\n Effect.try({\n try: () => Schema.decodeUnknownSync(schema)(encoded),\n catch: (cause) => sinkCheckpointCodecError(\"decoding\", cause),\n });\n\nconst encodeSinkState = <State>(\n schema: Schema.Codec<State, unknown, never, never>,\n state: State,\n): Effect.Effect<unknown, EDASessionStoreError> =>\n Effect.try({\n try: () => Schema.encodeUnknownSync(schema)(state),\n catch: (cause) => sinkCheckpointCodecError(\"encoding\", cause),\n });\n\nconst sinkCheckpointCodecError = (operation: string, cause: unknown) =>\n new EDASessionStoreError({\n message:\n cause instanceof Error\n ? `${operation} sink checkpoint: ${cause.message}`\n : `${operation} sink checkpoint: ${String(cause)}`,\n });\n\nconst readCursorBatchThrough = (\n store: EDASessionStoreShape,\n afterSeq: SequenceNumber,\n throughSeq: SequenceNumber,\n batchSize = defaultBatchSize,\n) =>\n store.eventsAfter(afterSeq).pipe(\n Stream.takeWhile((event) => event.position.seq <= throughSeq),\n Stream.take(batchSize),\n Stream.runCollect,\n Effect.map((events) => Array.from(events)),\n );\n\nconst committedDurableFromPositioned = (event: PositionedEvent): CommittedDurableEvent =>\n CommittedDurableEvent.make({\n event: event.event as DurableEventEnvelope,\n position: durablePosition(event.position.seq),\n });\n\nconst filterInterested = (\n events: ReadonlyArray<CommittedDurableEvent>,\n interests: ReadonlyArray<EventType | string> | undefined,\n): ReadonlyArray<CommittedDurableEvent> =>\n events.filter((event) => matchesInterest(event.event.type, interests));\n\nconst matchesInterest = (\n type: EventType | string,\n interests: ReadonlyArray<EventType | string> | undefined,\n): boolean => interests === undefined || interests.some((interest) => interest === type);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAkBA,MAAa,oCAAoC;;AAmCjD,IAAa,eAAb,MAAa,qBAAqB,QAAQ,QAAyC,EACjF,oCACF,EAAE;CACA,OAAgB,OAAO,MAAM,OAC3B,cACA,OAAO,IAAI,aAAa;EAUtB,OAAO,YAAY,OATG,OAAO,eAC3B,OAAO,UAA2B,GAClC,OAAO,QACT,GAM2B,OALK,IAAI,KAAgC;GAClE,QAAQ,CAAC;GACT,YAAY;EACd,CAAC,GAE4C,OADpB,IAAI,KAA0C,CAAC,CAAC,CACnB;CACxD,CAAC,CACH;AACF;AAEA,MAAM,eACJ,QACA,kBACA,eACuB;CACvB,UAAU,UACR,uBAAuB,kBAAkB,KAAK,EAAE,KAC9C,OAAO,QAAQ,wBAAwB,WAAW,KAAK,CAAC,GACxD,OAAO,QAAQ,OAAO,QAAQ,QAAQ,KAAK,CAAC,CAC9C;CACF,sBAAsB,OAAO,UAAU,MAAM;CAC7C,iBACE,OAAO,IAAI,OAAO,UAAU,MAAM,IAAI,iBACpC,OAAO,iBAAiB,OAAO,KAAK,YAAY,CAAC,CACnD;CACF,wBAAwB,IAAI,IAAI,gBAAgB;CAChD,2BAA2B,aACzB,IAAI,OAAO,YAAY,YAAY,CAAC,GAAG,SAAS,QAAQ,CAAC;AAC7D;AAEA,MAAM,2BACJ,WACA,UAEA,IAAI,I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BAAkB,MAAM,EAAE,KAAK;CACjD,QAAQ,UAAU,yBAAyB,YAAY,KAAK;AAC9D,CAAC;AAEH,MAAM,4BAA4B,WAAmB,UACnD,IAAI,qBAAqB,EACvB,SACE,iBAAiB,QACb,GAAG,UAAU,oBAAoB,MAAM,YACvC,GAAG,UAAU,oBAAoB,OAAO,KAAK,IACrD,CAAC;AAEH,MAAM,0BACJ,OACA,UACA,YACA,YAAY,qBAEZ,MAAM,YAAY,QAAQ,EAAE,KAC1B,OAAO,WAAW,UAAU,MAAM,SAAS,OAAO,UAAU,GAC5D,OAAO,KAAK,SAAS,GACrB,OAAO,YACP,OAAO,KAAK,WAAW,MAAM,KAAK,MAAM,CAAC,CAC3C;AAEF,MAAM,kCAAkC,UACtC,sBAAsB,KAAK;CACzB,OAAO,MAAM;CACb,UAAU,gBAAgB,MAAM,SAAS,GAAG;AAC9C,CAAC;AAEH,MAAM,oBACJ,QACA,cAEA,OAAO,QAAQ,UAAU,gBAAgB,MAAM,MAAM,MAAM,SAAS,CAAC;AAEvE,MAAM,mBACJ,MACA,cACY,cAAc,KAAA,KAAa,UAAU,MAAM,aAAa,aAAa,IAAI"}
@@ -1,19 +1,19 @@
1
1
  import { c as EventId, h as SessionId, m as SequenceNumber, y as TurnId } from "./core-CYT6DBaS.js";
2
2
  import { D as DurableEventEnvelope, L as PositionedEvent, M as EventType, O as EphemeralEventEnvelope } from "./events-Bb9-Cu-7.js";
3
- import { a as EDASessionStore, o as EDASessionStoreError, t as CommittedDurableEvent } from "./session-store-DZZUffUy.js";
4
- import { S as ReducedState } from "./command-queues-CV7O-51r.js";
3
+ import { a as EDASessionStore, o as EDASessionStoreError, t as CommittedDurableEvent } from "./session-store-BLg6UvZa.js";
4
+ import { S as ReducedState } from "./command-queues-Dwdf41mq.js";
5
5
  import { t as IdGenerator } from "./id-generator-Ckl8_XWW.js";
6
6
  import { n as EventFactoryShape, r as SessionContext, t as EventFactory } from "./event-factory-CLJcyymV.js";
7
7
  import { t as EDAKeepAlive } from "./keep-alive-Chl5SJxy.js";
8
- import { i as EDAReducerStateSnapshot, n as EDAReducerRegistry } from "./reducer-registry-CjSJBPKo.js";
9
- import { n as SinkCheckpointStore } from "./sink-checkpoint-store-BZmQFTRE.js";
8
+ import { i as EDAReducerStateSnapshot, n as EDAReducerRegistry } from "./reducer-registry-K9FqZq5-.js";
9
+ import { n as SinkCheckpointStore } from "./sink-checkpoint-store-B9WNvDtY.js";
10
10
  import * as Context from "effect/Context";
11
11
  import * as Effect from "effect/Effect";
12
12
  import * as Layer from "effect/Layer";
13
13
  import * as Schema from "effect/Schema";
14
14
  import * as Stream from "effect/Stream";
15
- import * as Scope from "effect/Scope";
16
15
  import * as PubSub from "effect/PubSub";
16
+ import * as Scope from "effect/Scope";
17
17
 
18
18
  //#region src/services/live-event-bus.d.ts
19
19
  /** Live-only replay buffer for the currently open turn. */
@@ -22,6 +22,15 @@ interface ActiveTurnEphemeralReplay {
22
22
  readonly events: ReadonlyArray<PositionedEvent>;
23
23
  readonly overflowed: boolean;
24
24
  }
25
+ /**
26
+ * Push-delivery listener invoked inline as each event is published.
27
+ *
28
+ * Listeners let hibernation-capable hosts fan events out to accepted
29
+ * WebSockets during the already-active turn instead of parking a resident
30
+ * subscriber fiber on the pub/sub. Listeners must not fail; defects are
31
+ * logged and never interrupt the publishing turn.
32
+ */
33
+ type LiveDeliveryListener = (event: PositionedEvent) => Effect.Effect<void>;
25
34
  /** In-memory live fanout plus active-turn replay source for reconnect streams. */
26
35
  interface LiveEventBusShape {
27
36
  readonly publish: (event: PositionedEvent) => Effect.Effect<boolean>;
@@ -29,6 +38,8 @@ interface LiveEventBusShape {
29
38
  readonly subscribeQueue: () => Effect.Effect<PubSub.Subscription<PositionedEvent>, never, Scope.Scope>;
30
39
  /** Snapshot raw live-only events retained for the currently open turn. */
31
40
  readonly activeTurnReplay: () => Effect.Effect<ActiveTurnEphemeralReplay>;
41
+ /** Register one push-delivery listener invoked inline on every published event. */
42
+ readonly registerDeliveryListener: (listener: LiveDeliveryListener) => Effect.Effect<void>;
32
43
  }
33
44
  declare const LiveEventBus_base: Context.ServiceClass<LiveEventBus, "@effect-durable-agent/LiveEventBus", LiveEventBusShape>;
34
45
  /** Unbounded in-memory fanout plus bounded active-turn ephemeral replay. */
@@ -73,24 +84,25 @@ interface EDASinkContext {
73
84
  /** Fork background sink work into the session scope. */
74
85
  readonly forkScoped: (effect: Effect.Effect<unknown, unknown>) => Effect.Effect<void>;
75
86
  }
76
- /** At-least-once sink definition backed by a durable checkpoint. */
87
+ /** Durable sink definition backed by a checkpoint and an app-owned delivery policy. */
77
88
  interface EDADurableSinkDefinition {
78
89
  readonly interests?: ReadonlyArray<EventType | string>;
79
90
  readonly batchSize?: number;
80
- readonly process: (batch: EDASinkDurableBatch, ctx: EDASinkContext) => Effect.Effect<void, unknown>;
91
+ readonly process: (batch: EDASinkDurableBatch, ctx: EDASinkContext) => Effect.Effect<void, never>;
81
92
  }
82
93
  /** Best-effort live-only sink definition. */
83
94
  interface EDAEphemeralSinkDefinition {
84
95
  readonly interests?: ReadonlyArray<EventType | string>;
85
- readonly process: (event: PositionedEvent, ctx: EDASinkContext) => Effect.Effect<void, unknown>;
96
+ readonly process: (event: PositionedEvent, ctx: EDASinkContext) => Effect.Effect<void, never>;
86
97
  }
87
98
  /**
88
99
  * Named app integration hook with optional durable and ephemeral filters.
89
100
  *
90
- * Every sink runs on one serialized position-ordered lane. Durable callbacks are
91
- * retried before the sink checkpoint advances; ephemeral callbacks are best-effort
92
- * and are only processed after the durable prefix at their anchor sequence has
93
- * been projected.
101
+ * Every sink runs on one serialized position-ordered lane. Sinks own retry and
102
+ * terminal failure handling, so callbacks must have an infallible typed error
103
+ * channel. An unexpected defect is logged and skipped before the durable checkpoint
104
+ * advances. Ephemeral callbacks are best-effort and are only processed after the
105
+ * durable prefix at their anchor sequence has been projected.
94
106
  */
95
107
  interface EDASink {
96
108
  readonly name: string;
@@ -125,5 +137,5 @@ declare class EDASinkRegistry extends EDASinkRegistry_base {
125
137
  static readonly Live: (sinks: ReadonlyArray<EDASink>) => Layer.Layer<EDASinkRegistry, never, EDASessionStore | LiveEventBus | EDAKeepAlive | IdGenerator | EventFactory | SessionContext | EDAReducerRegistry | SinkCheckpointStore>;
126
138
  }
127
139
  //#endregion
128
- export { EDASinkContext as a, EDASinkRegistryShape as c, EDASinkCheckpoint as i, EDASinkRunnerStartInput as l, EDAEphemeralSinkDefinition as n, EDASinkDurableBatch as o, EDASink as r, EDASinkRegistry as s, EDADurableSinkDefinition as t, LiveEventBus as u };
129
- //# sourceMappingURL=sink-registry-Cf79ICdW.d.ts.map
140
+ export { EDASinkContext as a, EDASinkRegistryShape as c, LiveEventBusShape as d, EDASinkCheckpoint as i, EDASinkRunnerStartInput as l, EDAEphemeralSinkDefinition as n, EDASinkDurableBatch as o, EDASink as r, EDASinkRegistry as s, EDADurableSinkDefinition as t, LiveEventBus as u };
141
+ //# sourceMappingURL=sink-registry-CO3YPS1p.d.ts.map
@@ -1,17 +1,17 @@
1
1
  import { h as SessionId } from "../core-CYT6DBaS.js";
2
2
  import { D as DurableEventEnvelope } from "../events-Bb9-Cu-7.js";
3
- import { a as EDASessionStore, o as EDASessionStoreError, s as EDASessionStoreShape } from "../session-store-DZZUffUy.js";
3
+ import { a as EDASessionStore, o as EDASessionStoreError, s as EDASessionStoreShape } from "../session-store-BLg6UvZa.js";
4
+ import { r as EDASink, s as EDASinkRegistry, u as LiveEventBus } from "../sink-registry-CO3YPS1p.js";
4
5
  import { t as IdGenerator } from "../id-generator-Ckl8_XWW.js";
5
6
  import { r as SessionContext, t as EventFactory } from "../event-factory-CLJcyymV.js";
6
7
  import { t as EDAKeepAlive } from "../keep-alive-Chl5SJxy.js";
7
- import { c as CompactionPolicy, d as CompactionRunner, r as CompactionExecutor } from "../compaction-zbvLREI8.js";
8
- import { r as EDASink, s as EDASinkRegistry, u as LiveEventBus } from "../sink-registry-Cf79ICdW.js";
9
- import { n as EDAReducerRegistry, t as EDAReducer } from "../reducer-registry-CjSJBPKo.js";
10
- import { r as EDAPromptProjector } from "../prompt-projector-C1IbkHr0.js";
11
- import { n as SinkCheckpointStore } from "../sink-checkpoint-store-BZmQFTRE.js";
12
- import { S as ToolExecutor, b as InferenceRunner, h as SessionState, x as InferenceRunnerStreamPart, y as TurnRunner } from "../session-state-CjOSvWbe.js";
13
- import { a as ToolParamsSchema, r as EDAToolRegistry, t as EDAModelToolkit } from "../tool-registry-B7Wona6N.js";
14
- import { t as EDASessionQuery } from "../session-query-C-C4m1eq.js";
8
+ import { c as CompactionPolicy, d as CompactionRunner, r as CompactionExecutor } from "../compaction-DpHOf-g7.js";
9
+ import { n as EDAReducerRegistry, t as EDAReducer } from "../reducer-registry-K9FqZq5-.js";
10
+ import { r as EDAPromptProjector } from "../prompt-projector-C2meuNrV.js";
11
+ import { n as SinkCheckpointStore } from "../sink-checkpoint-store-B9WNvDtY.js";
12
+ import { S as ToolExecutor, b as InferenceRunner, h as SessionState, x as InferenceRunnerStreamPart, y as TurnRunner } from "../session-state-CI1xeT6f.js";
13
+ import { a as ToolParamsSchema, r as EDAToolRegistry, t as EDAModelToolkit } from "../tool-registry-B8H1P6Pu.js";
14
+ import { n as EDASessionQuery } from "../session-query-5oyZRaQL.js";
15
15
  import * as Layer from "effect/Layer";
16
16
  import * as Stream from "effect/Stream";
17
17
  import * as Prompt from "effect/unstable/ai/Prompt";
@@ -98,7 +98,7 @@ interface EdaTestLayerOptions {
98
98
  * EDA service plus the fixed Clock. Layer constants are shared by reference,
99
99
  * so all services see the same store, bus, and ID counter.
100
100
  */
101
- declare const makeEdaTestLayer: (options: EdaTestLayerOptions) => Layer.Layer<LanguageModel.LanguageModel | SessionState | EDASessionStore | LiveEventBus | EDAKeepAlive | IdGenerator | EventFactory | TurnRunner | CompactionRunner | EDAPromptProjector | SessionContext | EDAReducerRegistry | EDASinkRegistry | SinkCheckpointStore | CompactionPolicy | CompactionExecutor | InferenceRunner | ToolExecutor | EDAToolRegistry | EDASessionQuery, EDASessionStoreError, never>;
101
+ declare const makeEdaTestLayer: (options: EdaTestLayerOptions) => Layer.Layer<EDAToolRegistry | LanguageModel.LanguageModel | SessionState | EDASessionStore | LiveEventBus | EDAKeepAlive | IdGenerator | EventFactory | TurnRunner | CompactionRunner | EDAPromptProjector | SessionContext | EDAReducerRegistry | EDASinkRegistry | SinkCheckpointStore | CompactionPolicy | CompactionExecutor | InferenceRunner | ToolExecutor | EDASessionQuery, EDASessionStoreError, never>;
102
102
  //#endregion
103
103
  export { EdaTestLayerOptions, FixedClock, TestLanguageModelOptions, TestModelParts, makeEdaTestLayer, makeFixedClock, makeLanguageModelLayer, testNowMs };
104
104
  //# sourceMappingURL=layers.d.ts.map
@@ -1,11 +1,11 @@
1
1
  import { yr as UnixEpochMillis } from "../durable-DsV9PxZC.js";
2
- import { d as TurnRunner, f as InferenceRunner, p as ToolExecutor, u as SessionState } from "../session-state-SStf0KUo.js";
2
+ import { n as EDASinkRegistry, r as LiveEventBus } from "../sink-registry-BbmoI9uv.js";
3
+ import { d as TurnRunner, f as InferenceRunner, p as ToolExecutor, u as SessionState } from "../session-state-D7dqko7r.js";
3
4
  import { EDASessionStore } from "../services/session-store.js";
4
5
  import { IdGenerator } from "../services/id-generator.js";
5
6
  import { n as SessionContext, t as EventFactory } from "../event-factory-tcpLgdMN.js";
6
7
  import { EDAKeepAlive } from "../services/keep-alive.js";
7
8
  import { CompactionExecutor, CompactionPolicy, CompactionRunner } from "../services/compaction.js";
8
- import { n as EDASinkRegistry, r as LiveEventBus } from "../sink-registry-D13eUO_c.js";
9
9
  import { EDAPromptProjector } from "../services/prompt-projector.js";
10
10
  import { EDAReducerRegistry } from "../services/reducer-registry.js";
11
11
  import { SinkCheckpointStore } from "../services/sink-checkpoint-store.js";
@@ -14,8 +14,8 @@ import { EDASessionQuery } from "../services/session-query.js";
14
14
  import * as Effect from "effect/Effect";
15
15
  import * as Layer from "effect/Layer";
16
16
  import * as Stream from "effect/Stream";
17
- import * as Clock from "effect/Clock";
18
17
  import * as Ref from "effect/Ref";
18
+ import * as Clock from "effect/Clock";
19
19
  import * as LanguageModel from "effect/unstable/ai/LanguageModel";
20
20
  import * as Response from "effect/unstable/ai/Response";
21
21
  //#region src/testkit/layers.ts
@@ -1,6 +1,6 @@
1
1
  import { c as EventId, h as SessionId, v as ToolCallId } from "./core-CYT6DBaS.js";
2
2
  import { D as DurableEventEnvelope, V as ToolName } from "./events-Bb9-Cu-7.js";
3
- import { o as EDASessionStoreError, t as CommittedDurableEvent } from "./session-store-DZZUffUy.js";
3
+ import { o as EDASessionStoreError, t as CommittedDurableEvent } from "./session-store-BLg6UvZa.js";
4
4
  import * as Context from "effect/Context";
5
5
  import * as Effect from "effect/Effect";
6
6
  import * as Layer from "effect/Layer";
@@ -48,4 +48,4 @@ declare class EDAToolRegistry extends EDAToolRegistry_base {
48
48
  }
49
49
  //#endregion
50
50
  export { ToolParamsSchema as a, EDAToolRegistryShape as i, EDAToolExecutionContext as n, makeEDAToolkit as o, EDAToolRegistry as r, EDAModelToolkit as t };
51
- //# sourceMappingURL=tool-registry-B7Wona6N.d.ts.map
51
+ //# sourceMappingURL=tool-registry-B8H1P6Pu.d.ts.map
@@ -7,25 +7,46 @@ import * as Schema from "effect/Schema";
7
7
  declare const EDA_WEB_SOCKET_WIRE_PROTOCOL_VERSION: 1;
8
8
  /** Flow-control policy announced by the server in the hello frame. */
9
9
  declare const EDAWebSocketWireFlowControl: Schema.Struct<{
10
- readonly ackTimeoutMs: Schema.Int;
10
+ readonly ackTimeoutMs: Schema.Int; /** Deprecated: servers no longer send heartbeat frames. Kept so deployed clients can decode hello. */
11
11
  readonly heartbeatIntervalMs: Schema.Int;
12
12
  readonly maxFrameBytes: Schema.Int;
13
13
  readonly maxFrameEvents: Schema.Int;
14
- readonly maxInFlightFrames: Schema.Int;
14
+ readonly maxInFlightFrames: Schema.Int; /** Suggested client-originated ping cadence; absent on servers that still send heartbeats. */
15
+ readonly pingIntervalMs: Schema.optionalKey<Schema.Int>;
15
16
  readonly subscriberBufferCapacityEvents: Schema.Int;
16
17
  }>;
17
18
  type EDAWebSocketWireFlowControl = typeof EDAWebSocketWireFlowControl.Type;
19
+ /**
20
+ * Canonical client liveness ping message.
21
+ *
22
+ * The exact string matters: hibernation-capable hosts register it with
23
+ * WebSocket auto-response so the runtime answers without waking the object.
24
+ */
25
+ declare const EDA_WEB_SOCKET_PING_MESSAGE = "{\"_tag\":\"ping\"}";
26
+ /** Canonical server pong message paired with {@link EDA_WEB_SOCKET_PING_MESSAGE}. */
27
+ declare const EDA_WEB_SOCKET_PONG_MESSAGE = "{\"_tag\":\"pong\"}";
28
+ /** Client liveness ping; hosts answer with a pong and never ACK-track it. */
29
+ declare const EDAWebSocketWirePingFrame: Schema.Struct<{
30
+ readonly _tag: Schema.Literal<"ping">;
31
+ }>;
32
+ type EDAWebSocketWirePingFrame = typeof EDAWebSocketWirePingFrame.Type;
33
+ /** Server liveness pong; clients may ignore it and must not ACK it. */
34
+ declare const EDAWebSocketWirePongFrame: Schema.Struct<{
35
+ readonly _tag: Schema.Literal<"pong">;
36
+ }>;
37
+ type EDAWebSocketWirePongFrame = typeof EDAWebSocketWirePongFrame.Type;
18
38
  declare const EDAWebSocketWireHelloFrame: Schema.Struct<{
19
39
  readonly _tag: Schema.Literal<"hello">;
20
40
  readonly protocolVersion: Schema.Literal<1>;
21
41
  readonly subscriberId: Schema.NonEmptyString;
22
42
  readonly resumeSeq: Schema.Int;
23
43
  readonly flowControl: Schema.Struct<{
24
- readonly ackTimeoutMs: Schema.Int;
44
+ readonly ackTimeoutMs: Schema.Int; /** Deprecated: servers no longer send heartbeat frames. Kept so deployed clients can decode hello. */
25
45
  readonly heartbeatIntervalMs: Schema.Int;
26
46
  readonly maxFrameBytes: Schema.Int;
27
47
  readonly maxFrameEvents: Schema.Int;
28
- readonly maxInFlightFrames: Schema.Int;
48
+ readonly maxInFlightFrames: Schema.Int; /** Suggested client-originated ping cadence; absent on servers that still send heartbeats. */
49
+ readonly pingIntervalMs: Schema.optionalKey<Schema.Int>;
29
50
  readonly subscriberBufferCapacityEvents: Schema.Int;
30
51
  }>;
31
52
  }>;
@@ -57,6 +78,8 @@ declare const EDAWebSocketWireClientFrame: Schema.Union<readonly [Schema.Struct<
57
78
  readonly _tag: Schema.Literal<"ack">;
58
79
  readonly frameId: Schema.Int;
59
80
  readonly durableThroughSeq: Schema.Int;
81
+ }>, Schema.Struct<{
82
+ readonly _tag: Schema.Literal<"ping">;
60
83
  }>]>;
61
84
  type EDAWebSocketWireClientFrame = typeof EDAWebSocketWireClientFrame.Type;
62
85
  /** Exhaustive decision table for a concrete WebSocket event union. */
@@ -2005,11 +2028,12 @@ declare const makeEDAWebSocketDomainSchemas: <EventSchema extends Schema.Codec<E
2005
2028
  readonly subscriberId: Schema.NonEmptyString;
2006
2029
  readonly resumeSeq: Schema.Int;
2007
2030
  readonly flowControl: Schema.Struct<{
2008
- readonly ackTimeoutMs: Schema.Int;
2031
+ readonly ackTimeoutMs: Schema.Int; /** Deprecated: servers no longer send heartbeat frames. Kept so deployed clients can decode hello. */
2009
2032
  readonly heartbeatIntervalMs: Schema.Int;
2010
2033
  readonly maxFrameBytes: Schema.Int;
2011
2034
  readonly maxFrameEvents: Schema.Int;
2012
- readonly maxInFlightFrames: Schema.Int;
2035
+ readonly maxInFlightFrames: Schema.Int; /** Suggested client-originated ping cadence; absent on servers that still send heartbeats. */
2036
+ readonly pingIntervalMs: Schema.optionalKey<Schema.Int>;
2013
2037
  readonly subscriberBufferCapacityEvents: Schema.Int;
2014
2038
  }>;
2015
2039
  }>, Schema.Struct<{
@@ -2027,6 +2051,8 @@ declare const makeEDAWebSocketDomainSchemas: <EventSchema extends Schema.Codec<E
2027
2051
  readonly _tag: Schema.Literal<"heartbeat">;
2028
2052
  readonly serverTimeMs: Schema.Int;
2029
2053
  readonly durableThroughSeq: Schema.Int;
2054
+ }>, Schema.Struct<{
2055
+ readonly _tag: Schema.Literal<"pong">;
2030
2056
  }>, Schema.Struct<{
2031
2057
  readonly _tag: Schema.Literal<"lagged">;
2032
2058
  readonly resumeSeq: Schema.Int;
@@ -2145,11 +2171,12 @@ declare const EDAWebSocketHostDomain: {
2145
2171
  readonly subscriberId: Schema.NonEmptyString;
2146
2172
  readonly resumeSeq: Schema.Int;
2147
2173
  readonly flowControl: Schema.Struct<{
2148
- readonly ackTimeoutMs: Schema.Int;
2174
+ readonly ackTimeoutMs: Schema.Int; /** Deprecated: servers no longer send heartbeat frames. Kept so deployed clients can decode hello. */
2149
2175
  readonly heartbeatIntervalMs: Schema.Int;
2150
2176
  readonly maxFrameBytes: Schema.Int;
2151
2177
  readonly maxFrameEvents: Schema.Int;
2152
- readonly maxInFlightFrames: Schema.Int;
2178
+ readonly maxInFlightFrames: Schema.Int; /** Suggested client-originated ping cadence; absent on servers that still send heartbeats. */
2179
+ readonly pingIntervalMs: Schema.optionalKey<Schema.Int>;
2153
2180
  readonly subscriberBufferCapacityEvents: Schema.Int;
2154
2181
  }>;
2155
2182
  }>, Schema.Struct<{
@@ -2194,6 +2221,8 @@ declare const EDAWebSocketHostDomain: {
2194
2221
  readonly _tag: Schema.Literal<"heartbeat">;
2195
2222
  readonly serverTimeMs: Schema.Int;
2196
2223
  readonly durableThroughSeq: Schema.Int;
2224
+ }>, Schema.Struct<{
2225
+ readonly _tag: Schema.Literal<"pong">;
2197
2226
  }>, Schema.Struct<{
2198
2227
  readonly _tag: Schema.Literal<"lagged">;
2199
2228
  readonly resumeSeq: Schema.Int;
@@ -2240,5 +2269,5 @@ declare const makeEDAWebSocketWireProtocol: <AppEventSchema extends Schema.Codec
2240
2269
  readonly appEvents: AppEventSchema;
2241
2270
  }) => EDAWebSocketWireProtocol<Schema.Union<readonly [typeof EDAFrameworkWebSocketEvent, AppEventSchema]>>;
2242
2271
  //#endregion
2243
- export { EDAWebSocketWireAckFrame as a, EDAWebSocketWireFlowControl as c, EDAWebSocketWireLaggedFrame as d, EDAWebSocketWireProtocol as f, makeEDAWebSocketWireProtocol as h, EDAWebSocketServerFrameInput as i, EDAWebSocketWireHeartbeatFrame as l, edaFrameworkWebSocketWireProtocol as m, EDAWebSocketEventConsumerPolicy as n, EDAWebSocketWireClientFrame as o, EDA_WEB_SOCKET_WIRE_PROTOCOL_VERSION as p, EDAWebSocketServerFrameEncoder as r, EDAWebSocketWireErrorFrame as s, EDAFrameworkWebSocketEvent as t, EDAWebSocketWireHelloFrame as u };
2244
- //# sourceMappingURL=websocket-wire-QD2SquQE.d.ts.map
2272
+ export { EDA_WEB_SOCKET_WIRE_PROTOCOL_VERSION as _, EDAWebSocketWireAckFrame as a, EDAWebSocketWireFlowControl as c, EDAWebSocketWireLaggedFrame as d, EDAWebSocketWirePingFrame as f, EDA_WEB_SOCKET_PONG_MESSAGE as g, EDA_WEB_SOCKET_PING_MESSAGE as h, EDAWebSocketServerFrameInput as i, EDAWebSocketWireHeartbeatFrame as l, EDAWebSocketWireProtocol as m, EDAWebSocketEventConsumerPolicy as n, EDAWebSocketWireClientFrame as o, EDAWebSocketWirePongFrame as p, EDAWebSocketServerFrameEncoder as r, EDAWebSocketWireErrorFrame as s, EDAFrameworkWebSocketEvent as t, EDAWebSocketWireHelloFrame as u, edaFrameworkWebSocketWireProtocol as v, makeEDAWebSocketWireProtocol as y };
2273
+ //# sourceMappingURL=websocket-wire-DPxwY4G5.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "effect-durable-agent",
3
- "version": "0.1.0-alpha.4",
3
+ "version": "0.1.0-alpha.5",
4
4
  "description": "A host-independent, event-sourced durable state-management and execution layer for agentic applications.",
5
5
  "keywords": [
6
6
  "agents",
@@ -14,7 +14,8 @@
14
14
  },
15
15
  "repository": {
16
16
  "type": "git",
17
- "url": "git+https://github.com/advait/effect-durable-agent.git"
17
+ "url": "git+https://github.com/advait/effect-durable-agent.git",
18
+ "directory": "packages/effect-durable-agent"
18
19
  },
19
20
  "license": "MIT",
20
21
  "author": "Advait Shinde",
@@ -23,11 +24,7 @@
23
24
  "main": "./dist/index.js",
24
25
  "types": "./dist/index.d.ts",
25
26
  "files": [
26
- "CHANGELOG.md",
27
- "CONTRIBUTING.md",
28
- "SECURITY.md",
29
27
  "dist",
30
- "docs",
31
28
  "testing/offline-trace/README.md",
32
29
  "tooling/oxlint/index.mjs",
33
30
  "tooling/oxlint/rules/*.mjs"
@@ -121,9 +118,9 @@
121
118
  "types": "./dist/services/tracing.d.ts",
122
119
  "import": "./dist/services/tracing.js"
123
120
  },
124
- "./services/websocket-subscriber": {
125
- "types": "./dist/services/websocket-subscriber.d.ts",
126
- "import": "./dist/services/websocket-subscriber.js"
121
+ "./services/websocket-delivery": {
122
+ "types": "./dist/services/websocket-delivery.d.ts",
123
+ "import": "./dist/services/websocket-delivery.js"
127
124
  },
128
125
  "./domain/context-projection": {
129
126
  "types": "./dist/domain/context-projection.d.ts",
@@ -182,20 +179,11 @@
182
179
  "wrangler": "^4.114.0"
183
180
  },
184
181
  "scripts": {
185
- "build": "pnpm run build:core && pnpm --filter effect-durable-agent-cloudflare run build && pnpm --filter effect-durable-agent-celld run build",
186
- "build:core": "vp pack",
187
- "check": "pnpm run lint && pnpm run typecheck && pnpm --filter effect-durable-agent-cloudflare run check && pnpm --filter effect-durable-agent-celld run check",
188
- "ci": "pnpm run build && pnpm run check && pnpm run test && pnpm run release:versions && pnpm run package:check",
189
- "lint": "vp fmt --check && vp lint --deny-warnings",
190
- "lint:fix": "vp fmt && vp lint --fix",
191
- "package:check": "node scripts/check-package.mjs",
192
- "publish:workspace": "node scripts/publish-workspace.mjs",
193
- "publish:workspace:dry-run": "node scripts/publish-workspace.mjs --dry-run",
194
- "release:versions": "node scripts/check-workspace-versions.mjs",
195
- "release:check": "pnpm run ci",
196
- "test": "pnpm run test:core && pnpm --filter effect-durable-agent-cloudflare run test && pnpm --filter effect-durable-agent-celld run test && pnpm run test:integration",
197
- "test:core": "vp test run --passWithNoTests src testing/offline-trace",
198
- "test:integration": "pnpm run build && vp test run testing/host-conformance/hosts.integration.test.ts",
182
+ "build": "vp pack",
183
+ "check": "pnpm run lint && pnpm run typecheck",
184
+ "lint": "vp fmt --check src testing tooling package.json tsconfig.json vite.config.ts && vp lint --deny-warnings src testing vite.config.ts",
185
+ "lint:fix": "vp fmt src testing tooling package.json tsconfig.json vite.config.ts && vp lint --fix src testing vite.config.ts",
186
+ "test": "vp test run --passWithNoTests src testing/offline-trace",
199
187
  "typecheck": "tsc -p tsconfig.json --noEmit"
200
188
  }
201
189
  }
@@ -7,7 +7,8 @@ remains self-contained.
7
7
  ## Run a real OpenAI trace
8
8
 
9
9
  ```bash
10
- OPENAI_API_KEY=... pnpm exec tsx testing/offline-trace/node/run.ts \
10
+ OPENAI_API_KEY=... pnpm --filter effect-durable-agent exec tsx \
11
+ testing/offline-trace/node/run.ts \
11
12
  --scenario no-tools \
12
13
  --out .eda-traces/no-tools-001
13
14
  ```
package/CHANGELOG.md DELETED
@@ -1,34 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to Effect Durable Agent will be documented in this file.
4
-
5
- ## Unreleased
6
-
7
- ## 0.1.0-alpha.4
8
-
9
- - Let applications project instruction and data messages from current reducer state into each model prompt
10
- - Build prompts only after turn input selection is committed into durable reducer state
11
- - Split the host-neutral runtime, Cloudflare Durable Objects host, and celld host into lockstep packages
12
- - Add shared real-runtime conformance tests for workerd and celld, including RPC, persistence,
13
- hard-restart recovery, durable idempotency, WebSocket resume/ACK, and warm/cold session recreation
14
- - Encode Effect Schema values explicitly at Durable Object RPC boundaries
15
-
16
- ## 0.1.0-alpha.3
17
-
18
- - Publish the state-projected prompt context and WebSocket schema changes from the unpublished `0.1.0-alpha.2` package
19
- - Pin prerelease publication to the npm `alpha` dist-tag
20
-
21
- ## 0.1.0-alpha.2
22
-
23
- - Let applications project instruction and data messages from current reducer state into each model prompt
24
- - Build prompts only after turn input selection is committed into durable reducer state
25
- - Separate WebSocket protocol schemas into explicit domain and wire surfaces
26
- - Add a typed domain-frame encoder, a host adapter for app-event narrowing, and transformation
27
- round-trip coverage
28
-
29
- ## 0.1.0-alpha.1
30
-
31
- - Publish the first public prerelease as `effect-durable-agent`
32
- - Ship compiled ESM and TypeScript declarations for every supported subpath
33
- - Add isolated package-consumer validation for Cloudflare Workers
34
- - Add MIT licensing and trusted-publishing release automation