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.
- package/README.md +19 -18
- package/dist/{command-queues-CV7O-51r.d.ts → command-queues-Dwdf41mq.d.ts} +2 -2
- package/dist/{compaction-zbvLREI8.d.ts → compaction-DpHOf-g7.d.ts} +5 -5
- package/dist/{context-projection-n6Rdup0N.d.ts → context-projection-B4DWOZgi.d.ts} +3 -3
- package/dist/domain/command-queues.d.ts +1 -1
- package/dist/domain/context-projection.d.ts +1 -1
- package/dist/domain/message-transcript.d.ts +1 -1
- package/dist/domain/reduced-state.d.ts +1 -1
- package/dist/host/websocket-protocol.d.ts +26 -3
- package/dist/host/websocket-protocol.js +16 -4
- package/dist/host/websocket-protocol.js.map +1 -1
- package/dist/host/websocket-wire.d.ts +2 -2
- package/dist/host/websocket-wire.js +19 -2
- package/dist/host/websocket-wire.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/{message-transcript-DiOPBY3l.d.ts → message-transcript-CFn_D3MH.d.ts} +3 -3
- package/dist/{prompt-projector-C1IbkHr0.d.ts → prompt-projector-C2meuNrV.d.ts} +4 -4
- package/dist/{reducer-registry-CjSJBPKo.d.ts → reducer-registry-K9FqZq5-.d.ts} +2 -2
- package/dist/{runtime-DOgmAKsO.d.ts → runtime-5NEJngu3.d.ts} +10 -5
- package/dist/services/compaction.d.ts +1 -1
- package/dist/services/prompt-projector.d.ts +1 -1
- package/dist/services/reducer-registry.d.ts +1 -1
- package/dist/services/runtime-layer.d.ts +9 -9
- package/dist/services/runtime-layer.js +2 -2
- package/dist/services/runtime.d.ts +1 -1
- package/dist/services/runtime.js +6 -2
- package/dist/services/runtime.js.map +1 -1
- package/dist/services/session-query.d.ts +2 -2
- package/dist/services/session-query.js +20 -3
- package/dist/services/session-query.js.map +1 -1
- package/dist/services/session-state.d.ts +1 -1
- package/dist/services/session-state.js +1 -1
- package/dist/services/session-store.d.ts +1 -1
- package/dist/services/session-store.js +1 -1
- package/dist/services/sink-checkpoint-store.d.ts +1 -1
- package/dist/services/sink-registry.d.ts +1 -1
- package/dist/services/sink-registry.js +1 -1
- package/dist/services/span-names.d.ts +1 -1
- package/dist/services/span-names.js +1 -0
- package/dist/services/span-names.js.map +1 -1
- package/dist/services/tool-registry.d.ts +1 -1
- package/dist/services/websocket-delivery.d.ts +90 -0
- package/dist/services/websocket-delivery.js +221 -0
- package/dist/services/websocket-delivery.js.map +1 -0
- package/dist/{session-query-C-C4m1eq.d.ts → session-query-5oyZRaQL.d.ts} +16 -9
- package/dist/{session-state-CjOSvWbe.d.ts → session-state-CI1xeT6f.d.ts} +11 -11
- package/dist/{session-state-SStf0KUo.js → session-state-D7dqko7r.js} +3 -3
- package/dist/{session-state-SStf0KUo.js.map → session-state-D7dqko7r.js.map} +1 -1
- package/dist/{session-store-DZZUffUy.d.ts → session-store-BLg6UvZa.d.ts} +2 -2
- package/dist/{sink-checkpoint-store-BZmQFTRE.d.ts → sink-checkpoint-store-B9WNvDtY.d.ts} +2 -2
- package/dist/{sink-registry-D13eUO_c.js → sink-registry-BbmoI9uv.js} +17 -24
- package/dist/sink-registry-BbmoI9uv.js.map +1 -0
- package/dist/{sink-registry-Cf79ICdW.d.ts → sink-registry-CO3YPS1p.d.ts} +26 -14
- package/dist/testkit/layers.d.ts +10 -10
- package/dist/testkit/layers.js +3 -3
- package/dist/{tool-registry-B7Wona6N.d.ts → tool-registry-B8H1P6Pu.d.ts} +2 -2
- package/dist/{websocket-wire-QD2SquQE.d.ts → websocket-wire-DPxwY4G5.d.ts} +39 -10
- package/package.json +11 -23
- package/testing/offline-trace/README.md +2 -1
- package/CHANGELOG.md +0 -34
- package/CONTRIBUTING.md +0 -26
- package/SECURITY.md +0 -7
- package/dist/services/websocket-subscriber.d.ts +0 -54
- package/dist/services/websocket-subscriber.js +0 -190
- package/dist/services/websocket-subscriber.js.map +0 -1
- package/dist/sink-registry-D13eUO_c.js.map +0 -1
- package/docs/assets/architecture.svg +0 -216
- package/docs/assets/event-sequence.svg +0 -133
- package/docs/assets/gcp-trace.png +0 -0
- package/docs/assets/hero.svg +0 -33
- package/docs/message-steering.md +0 -831
- package/docs/releasing.md +0 -114
- package/docs/spec.md +0 -777
- package/docs/subagents.md +0 -725
- package/docs/testing.md +0 -64
- package/docs/ui-projection.md +0 -742
- package/docs/websocket-protocol.md +0 -639
package/CONTRIBUTING.md
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# Contributing
|
|
2
|
-
|
|
3
|
-
Issues and pull requests for Effect Durable Agent live in
|
|
4
|
-
[`advait/effect-durable-agent`](https://github.com/advait/effect-durable-agent).
|
|
5
|
-
|
|
6
|
-
## Development
|
|
7
|
-
|
|
8
|
-
Install dependencies and run the full validation suite:
|
|
9
|
-
|
|
10
|
-
```bash
|
|
11
|
-
pnpm install --frozen-lockfile
|
|
12
|
-
pnpm run ci
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
Validate the distributable package, including an install into an isolated Cloudflare Worker:
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
pnpm run build
|
|
19
|
-
pnpm run package:check
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
Use `pnpm run lint:fix` for automated formatting and lint fixes. Add tests for behavior changes, keep
|
|
23
|
-
the public event and state model explicit, and preserve compatibility across all exported
|
|
24
|
-
subpaths.
|
|
25
|
-
|
|
26
|
-
See [the release guide](./docs/releasing.md) for maintainer-only publishing steps.
|
package/SECURITY.md
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
# Security
|
|
2
|
-
|
|
3
|
-
Please do not report security vulnerabilities in public issues.
|
|
4
|
-
|
|
5
|
-
Use [GitHub's private vulnerability reporting](https://github.com/advait/effect-durable-agent/security/advisories/new).
|
|
6
|
-
Include the affected package version, impact, reproduction steps, and any known mitigations.
|
|
7
|
-
Maintainers will acknowledge the report and coordinate disclosure through that private thread.
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { m as SequenceNumber } from "../core-CYT6DBaS.js";
|
|
2
|
-
import { o as EDASessionStoreError } from "../session-store-DZZUffUy.js";
|
|
3
|
-
import { r as EDARuntime } from "../runtime-DOgmAKsO.js";
|
|
4
|
-
import { EDAWebSocketClientFrame, EDAWebSocketFlowControl, EDAWebSocketServerFrame, SubscriberId } from "../host/websocket-protocol.js";
|
|
5
|
-
import * as Effect from "effect/Effect";
|
|
6
|
-
import * as Schema from "effect/Schema";
|
|
7
|
-
import * as Queue from "effect/Queue";
|
|
8
|
-
import * as Scope from "effect/Scope";
|
|
9
|
-
import * as Deferred from "effect/Deferred";
|
|
10
|
-
|
|
11
|
-
//#region src/services/websocket-subscriber.d.ts
|
|
12
|
-
/** Slow subscriber reasons that intentionally close only the lagging socket. */
|
|
13
|
-
declare const SubscriberLagReason: Schema.Literals<readonly ["buffer-overflow", "ack-timeout"]>;
|
|
14
|
-
type SubscriberLagReason = typeof SubscriberLagReason.Type;
|
|
15
|
-
declare const SubscriberLagged_base: Schema.Class<SubscriberLagged, Schema.TaggedStruct<"SubscriberLagged", {
|
|
16
|
-
readonly subscriberId: Schema.brand<Schema.NonEmptyString, "SubscriberId">;
|
|
17
|
-
readonly lastAckedSeq: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
18
|
-
readonly reason: Schema.Literals<readonly ["buffer-overflow", "ack-timeout"]>;
|
|
19
|
-
}>, import("effect/Cause").YieldableError>;
|
|
20
|
-
/** The subscriber could not keep up with the bounded live-delivery policy. */
|
|
21
|
-
declare class SubscriberLagged extends SubscriberLagged_base {}
|
|
22
|
-
declare const SubscriberProtocolError_base: Schema.Class<SubscriberProtocolError, Schema.TaggedStruct<"SubscriberProtocolError", {
|
|
23
|
-
readonly subscriberId: Schema.brand<Schema.NonEmptyString, "SubscriberId">;
|
|
24
|
-
readonly message: Schema.String;
|
|
25
|
-
}>, import("effect/Cause").YieldableError>;
|
|
26
|
-
/** The client sent a malformed or impossible protocol frame. */
|
|
27
|
-
declare class SubscriberProtocolError extends SubscriberProtocolError_base {}
|
|
28
|
-
declare const SubscriberSendFailed_base: Schema.Class<SubscriberSendFailed, Schema.TaggedStruct<"SubscriberSendFailed", {
|
|
29
|
-
readonly subscriberId: Schema.brand<Schema.NonEmptyString, "SubscriberId">;
|
|
30
|
-
readonly cause: Schema.Defect;
|
|
31
|
-
}>, import("effect/Cause").YieldableError>;
|
|
32
|
-
/** The host WebSocket boundary failed while sending a frame. */
|
|
33
|
-
declare class SubscriberSendFailed extends SubscriberSendFailed_base {}
|
|
34
|
-
/** Expected error surface for one WebSocket subscriber workflow. */
|
|
35
|
-
type EDAWebSocketSubscriberError = SubscriberLagged | SubscriberProtocolError | SubscriberSendFailed | EDASessionStoreError;
|
|
36
|
-
/** Transport boundary implemented by a host WebSocket adapter or tests. */
|
|
37
|
-
interface EDAWebSocketSubscriberTransport {
|
|
38
|
-
readonly send: (frame: EDAWebSocketServerFrame) => Effect.Effect<void, SubscriberSendFailed>;
|
|
39
|
-
readonly incoming: Queue.Queue<EDAWebSocketClientFrame>;
|
|
40
|
-
readonly closed: Deferred.Deferred<void>;
|
|
41
|
-
readonly persistAck: (seq: SequenceNumber) => Effect.Effect<void>;
|
|
42
|
-
}
|
|
43
|
-
/** Configuration for one scoped ACK-window subscriber workflow. */
|
|
44
|
-
interface EDAWebSocketSubscriberInput {
|
|
45
|
-
readonly subscriberId: SubscriberId;
|
|
46
|
-
readonly resumeSeq: SequenceNumber;
|
|
47
|
-
readonly policy: EDAWebSocketFlowControl;
|
|
48
|
-
readonly transport: EDAWebSocketSubscriberTransport;
|
|
49
|
-
}
|
|
50
|
-
/** Run one scoped, ACK-gated live-event WebSocket subscriber. */
|
|
51
|
-
declare const runWebSocketSubscriber: (input: EDAWebSocketSubscriberInput) => Effect.Effect<void, EDAWebSocketSubscriberError, EDARuntime | Scope.Scope>;
|
|
52
|
-
//#endregion
|
|
53
|
-
export { EDAWebSocketSubscriberError, EDAWebSocketSubscriberInput, EDAWebSocketSubscriberTransport, SubscriberLagReason, SubscriberLagged, SubscriberProtocolError, SubscriberSendFailed, runWebSocketSubscriber };
|
|
54
|
-
//# sourceMappingURL=websocket-subscriber.d.ts.map
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import { SequenceNumber } from "../types/core.js";
|
|
2
|
-
import { yr as UnixEpochMillis } from "../durable-DsV9PxZC.js";
|
|
3
|
-
import { EDARuntime } from "./runtime.js";
|
|
4
|
-
import { EDAWebSocketEventsFrame, EDAWebSocketHeartbeatFrame, EDAWebSocketHelloFrame, EDA_WEB_SOCKET_PROTOCOL_VERSION, FrameId, SubscriberId } from "../host/websocket-protocol.js";
|
|
5
|
-
import * as Effect from "effect/Effect";
|
|
6
|
-
import * as Schema from "effect/Schema";
|
|
7
|
-
import * as Stream from "effect/Stream";
|
|
8
|
-
import * as Clock from "effect/Clock";
|
|
9
|
-
import * as Queue from "effect/Queue";
|
|
10
|
-
import * as Ref from "effect/Ref";
|
|
11
|
-
import * as Deferred from "effect/Deferred";
|
|
12
|
-
//#region src/services/websocket-subscriber.ts
|
|
13
|
-
/** Slow subscriber reasons that intentionally close only the lagging socket. */
|
|
14
|
-
const SubscriberLagReason = Schema.Literals(["buffer-overflow", "ack-timeout"]);
|
|
15
|
-
/** The subscriber could not keep up with the bounded live-delivery policy. */
|
|
16
|
-
var SubscriberLagged = class extends Schema.TaggedErrorClass()("SubscriberLagged", {
|
|
17
|
-
subscriberId: SubscriberId,
|
|
18
|
-
lastAckedSeq: SequenceNumber,
|
|
19
|
-
reason: SubscriberLagReason
|
|
20
|
-
}) {};
|
|
21
|
-
/** The client sent a malformed or impossible protocol frame. */
|
|
22
|
-
var SubscriberProtocolError = class extends Schema.TaggedErrorClass()("SubscriberProtocolError", {
|
|
23
|
-
subscriberId: SubscriberId,
|
|
24
|
-
message: Schema.String
|
|
25
|
-
}) {};
|
|
26
|
-
/** The host WebSocket boundary failed while sending a frame. */
|
|
27
|
-
var SubscriberSendFailed = class extends Schema.TaggedErrorClass()("SubscriberSendFailed", {
|
|
28
|
-
subscriberId: SubscriberId,
|
|
29
|
-
cause: Schema.Defect()
|
|
30
|
-
}) {};
|
|
31
|
-
/** Run one scoped, ACK-gated live-event WebSocket subscriber. */
|
|
32
|
-
const runWebSocketSubscriber = (input) => Effect.gen(function* () {
|
|
33
|
-
const eda = yield* EDARuntime;
|
|
34
|
-
const outbound = yield* Queue.dropping(input.policy.subscriberBufferCapacityEvents);
|
|
35
|
-
const windowSignal = yield* Queue.sliding(1);
|
|
36
|
-
const timeoutFailure = yield* Deferred.make();
|
|
37
|
-
const lastAckedSeq = yield* Ref.make(input.resumeSeq);
|
|
38
|
-
const lastAckedFrameId = yield* Ref.make(0);
|
|
39
|
-
const lastSentFrameId = yield* Ref.make(0);
|
|
40
|
-
const lastSentDurableThroughSeq = yield* Ref.make(input.resumeSeq);
|
|
41
|
-
const nextFrameId = yield* Ref.make(FrameId.make(1));
|
|
42
|
-
const inFlight = yield* Ref.make([]);
|
|
43
|
-
yield* input.transport.send(EDAWebSocketHelloFrame.make({
|
|
44
|
-
_tag: "hello",
|
|
45
|
-
protocolVersion: EDA_WEB_SOCKET_PROTOCOL_VERSION,
|
|
46
|
-
subscriberId: input.subscriberId,
|
|
47
|
-
resumeSeq: input.resumeSeq,
|
|
48
|
-
flowControl: input.policy
|
|
49
|
-
}));
|
|
50
|
-
const pump = (yield* eda.eventsAfter(input.resumeSeq)).pipe(Stream.interruptWhen(Deferred.await(input.transport.closed)), Stream.runForEach((event) => Queue.offer(outbound, event).pipe(Effect.flatMap((accepted) => accepted ? Effect.void : Effect.gen(function* () {
|
|
51
|
-
const seq = yield* Ref.get(lastAckedSeq);
|
|
52
|
-
return yield* new SubscriberLagged({
|
|
53
|
-
subscriberId: input.subscriberId,
|
|
54
|
-
lastAckedSeq: seq,
|
|
55
|
-
reason: "buffer-overflow"
|
|
56
|
-
});
|
|
57
|
-
})))));
|
|
58
|
-
const sender = sendLoop({
|
|
59
|
-
inFlight,
|
|
60
|
-
input,
|
|
61
|
-
lastAckedSeq,
|
|
62
|
-
lastSentDurableThroughSeq,
|
|
63
|
-
lastSentFrameId,
|
|
64
|
-
nextFrameId,
|
|
65
|
-
outbound,
|
|
66
|
-
timeoutFailure,
|
|
67
|
-
windowSignal
|
|
68
|
-
});
|
|
69
|
-
const ackLoop = receiveAcks({
|
|
70
|
-
inFlight,
|
|
71
|
-
input,
|
|
72
|
-
lastAckedFrameId,
|
|
73
|
-
lastAckedSeq,
|
|
74
|
-
lastSentFrameId,
|
|
75
|
-
windowSignal
|
|
76
|
-
});
|
|
77
|
-
yield* Effect.raceFirst(Deferred.await(input.transport.closed), Effect.raceFirst(Deferred.await(timeoutFailure), Effect.raceFirst(pump, Effect.raceFirst(sender, ackLoop))));
|
|
78
|
-
});
|
|
79
|
-
const sendLoop = (input) => Effect.forever(Effect.gen(function* () {
|
|
80
|
-
yield* waitForWindow(input.inFlight, input.windowSignal, input.input.policy.maxInFlightFrames);
|
|
81
|
-
const next = yield* takeNextOutboundOrHeartbeat(input.outbound, input.input.policy.heartbeatIntervalMs);
|
|
82
|
-
if (next._tag === "heartbeat") {
|
|
83
|
-
yield* sendHeartbeat(input.input, input.lastSentDurableThroughSeq);
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
const event = next.event;
|
|
87
|
-
const frameId = yield* Ref.get(input.nextFrameId);
|
|
88
|
-
yield* Ref.set(input.nextFrameId, FrameId.make(frameId + 1));
|
|
89
|
-
const previousSentDurableSeq = yield* Ref.get(input.lastSentDurableThroughSeq);
|
|
90
|
-
const durableThroughSeq = durableThroughForFrame([event], previousSentDurableSeq);
|
|
91
|
-
const frame = EDAWebSocketEventsFrame.make({
|
|
92
|
-
_tag: "events",
|
|
93
|
-
frameId,
|
|
94
|
-
events: [event],
|
|
95
|
-
durableThroughSeq
|
|
96
|
-
});
|
|
97
|
-
const encodedBytes = encodedFrameBytes(frame);
|
|
98
|
-
if (encodedBytes > input.input.policy.maxFrameBytes) return yield* new SubscriberProtocolError({
|
|
99
|
-
subscriberId: input.input.subscriberId,
|
|
100
|
-
message: `Encoded WebSocket frame exceeded maxFrameBytes (${encodedBytes} > ${input.input.policy.maxFrameBytes})`
|
|
101
|
-
});
|
|
102
|
-
const sent = {
|
|
103
|
-
frameId,
|
|
104
|
-
durableThroughSeq,
|
|
105
|
-
sentAtMs: yield* Clock.currentTimeMillis
|
|
106
|
-
};
|
|
107
|
-
yield* Ref.update(input.inFlight, (frames) => [...frames, sent]);
|
|
108
|
-
yield* Ref.set(input.lastSentFrameId, frameId);
|
|
109
|
-
yield* Ref.set(input.lastSentDurableThroughSeq, durableThroughSeq);
|
|
110
|
-
yield* input.input.transport.send(frame);
|
|
111
|
-
yield* startAckTimeout(input.input, input.inFlight, input.lastAckedSeq, input.timeoutFailure, sent);
|
|
112
|
-
}));
|
|
113
|
-
const takeNextOutboundOrHeartbeat = (outbound, heartbeatIntervalMs) => Effect.raceFirst(Queue.take(outbound).pipe(Effect.map((event) => ({
|
|
114
|
-
_tag: "event",
|
|
115
|
-
event
|
|
116
|
-
}))), Effect.sleep(`${heartbeatIntervalMs} millis`).pipe(Effect.as({ _tag: "heartbeat" })));
|
|
117
|
-
const sendHeartbeat = (input, lastSentDurableThroughSeq) => Effect.gen(function* () {
|
|
118
|
-
const durableThroughSeq = yield* Ref.get(lastSentDurableThroughSeq);
|
|
119
|
-
const serverTimeMs = yield* Clock.currentTimeMillis;
|
|
120
|
-
yield* input.transport.send(EDAWebSocketHeartbeatFrame.make({
|
|
121
|
-
_tag: "heartbeat",
|
|
122
|
-
serverTimeMs: UnixEpochMillis.make(serverTimeMs),
|
|
123
|
-
durableThroughSeq
|
|
124
|
-
}));
|
|
125
|
-
});
|
|
126
|
-
const receiveAcks = (input) => Effect.forever(Effect.gen(function* () {
|
|
127
|
-
const frame = yield* Queue.take(input.input.transport.incoming);
|
|
128
|
-
if (frame._tag !== "ack") return yield* new SubscriberProtocolError({
|
|
129
|
-
subscriberId: input.input.subscriberId,
|
|
130
|
-
message: `Unsupported client frame ${frame._tag ?? "unknown"}`
|
|
131
|
-
});
|
|
132
|
-
yield* applyAck(input, frame);
|
|
133
|
-
}));
|
|
134
|
-
const applyAck = (input, ack) => Effect.gen(function* () {
|
|
135
|
-
const lastAckedFrame = yield* Ref.get(input.lastAckedFrameId);
|
|
136
|
-
const lastSentFrame = yield* Ref.get(input.lastSentFrameId);
|
|
137
|
-
const currentSeq = yield* Ref.get(input.lastAckedSeq);
|
|
138
|
-
if (ack.frameId <= lastAckedFrame) {
|
|
139
|
-
if (ack.durableThroughSeq > currentSeq) return yield* new SubscriberProtocolError({
|
|
140
|
-
subscriberId: input.input.subscriberId,
|
|
141
|
-
message: "Duplicate ACK attempted to advance durable seq"
|
|
142
|
-
});
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
if (ack.frameId > lastSentFrame) return yield* new SubscriberProtocolError({
|
|
146
|
-
subscriberId: input.input.subscriberId,
|
|
147
|
-
message: "ACK referenced an unsent frame"
|
|
148
|
-
});
|
|
149
|
-
if (ack.durableThroughSeq < currentSeq) return yield* new SubscriberProtocolError({
|
|
150
|
-
subscriberId: input.input.subscriberId,
|
|
151
|
-
message: "ACK durable seq moved backwards"
|
|
152
|
-
});
|
|
153
|
-
const acknowledged = (yield* Ref.get(input.inFlight)).filter((frame) => frame.frameId <= ack.frameId);
|
|
154
|
-
if (acknowledged.length === 0) return yield* new SubscriberProtocolError({
|
|
155
|
-
subscriberId: input.input.subscriberId,
|
|
156
|
-
message: "ACK referenced no in-flight frames"
|
|
157
|
-
});
|
|
158
|
-
const allowedDurableSeq = SequenceNumber.make(acknowledged.reduce((max, frame) => Math.max(max, frame.durableThroughSeq), currentSeq));
|
|
159
|
-
if (ack.durableThroughSeq > allowedDurableSeq) return yield* new SubscriberProtocolError({
|
|
160
|
-
subscriberId: input.input.subscriberId,
|
|
161
|
-
message: "ACK durable seq exceeded sent frame boundary"
|
|
162
|
-
});
|
|
163
|
-
yield* Ref.update(input.inFlight, (frames) => frames.filter((frame) => frame.frameId > ack.frameId));
|
|
164
|
-
yield* Ref.set(input.lastAckedFrameId, ack.frameId);
|
|
165
|
-
yield* Ref.set(input.lastAckedSeq, ack.durableThroughSeq);
|
|
166
|
-
yield* input.input.transport.persistAck(ack.durableThroughSeq);
|
|
167
|
-
yield* Queue.offer(input.windowSignal, void 0);
|
|
168
|
-
});
|
|
169
|
-
const waitForWindow = (inFlight, windowSignal, maxInFlightFrames) => Effect.gen(function* () {
|
|
170
|
-
while (true) {
|
|
171
|
-
if ((yield* Ref.get(inFlight)).length < maxInFlightFrames) return;
|
|
172
|
-
yield* Queue.take(windowSignal);
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
const startAckTimeout = (input, inFlight, lastAckedSeq, timeoutFailure, sent) => Effect.gen(function* () {
|
|
176
|
-
yield* Effect.sleep(`${input.policy.ackTimeoutMs} millis`);
|
|
177
|
-
if (!(yield* Ref.get(inFlight)).some((frame) => frame.frameId === sent.frameId)) return;
|
|
178
|
-
const seq = yield* Ref.get(lastAckedSeq);
|
|
179
|
-
yield* Deferred.fail(timeoutFailure, new SubscriberLagged({
|
|
180
|
-
subscriberId: input.subscriberId,
|
|
181
|
-
lastAckedSeq: seq,
|
|
182
|
-
reason: "ack-timeout"
|
|
183
|
-
}));
|
|
184
|
-
}).pipe(Effect.forkScoped, Effect.asVoid);
|
|
185
|
-
const durableThroughForFrame = (events, previousSentDurableSeq) => SequenceNumber.make(events.reduce((max, event) => event.event.durability === "durable" ? Math.max(max, event.position.seq) : max, previousSentDurableSeq));
|
|
186
|
-
const encodedFrameBytes = (frame) => new TextEncoder().encode(JSON.stringify(frame)).byteLength;
|
|
187
|
-
//#endregion
|
|
188
|
-
export { SubscriberLagReason, SubscriberLagged, SubscriberProtocolError, SubscriberSendFailed, runWebSocketSubscriber };
|
|
189
|
-
|
|
190
|
-
//# sourceMappingURL=websocket-subscriber.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"websocket-subscriber.js","names":[],"sources":["../../src/services/websocket-subscriber.ts"],"sourcesContent":["import * as Clock from \"effect/Clock\";\nimport * as Deferred from \"effect/Deferred\";\nimport * as Effect from \"effect/Effect\";\nimport * as Queue from \"effect/Queue\";\nimport * as Ref from \"effect/Ref\";\nimport * as Schema from \"effect/Schema\";\nimport type * as Scope from \"effect/Scope\";\nimport * as Stream from \"effect/Stream\";\n\nimport { EDARuntime } from \"./runtime\";\nimport { EDASessionStoreError } from \"./session-store\";\nimport { SequenceNumber } from \"../types/core\";\nimport { UnixEpochMillis, type PositionedEvent } from \"../types/events\";\nimport {\n EDA_WEB_SOCKET_PROTOCOL_VERSION,\n EDAWebSocketAckFrame,\n EDAWebSocketEventsFrame,\n EDAWebSocketFlowControl,\n EDAWebSocketHeartbeatFrame,\n EDAWebSocketHelloFrame,\n FrameId,\n SubscriberId,\n type EDAWebSocketClientFrame,\n type EDAWebSocketServerFrame,\n} from \"../host/websocket-protocol\";\n\n/** Slow subscriber reasons that intentionally close only the lagging socket. */\nexport const SubscriberLagReason = Schema.Literals([\"buffer-overflow\", \"ack-timeout\"]);\nexport type SubscriberLagReason = typeof SubscriberLagReason.Type;\n\n/** The subscriber could not keep up with the bounded live-delivery policy. */\nexport class SubscriberLagged extends Schema.TaggedErrorClass<SubscriberLagged>()(\n \"SubscriberLagged\",\n {\n subscriberId: SubscriberId,\n lastAckedSeq: SequenceNumber,\n reason: SubscriberLagReason,\n },\n) {}\n\n/** The client sent a malformed or impossible protocol frame. */\nexport class SubscriberProtocolError extends Schema.TaggedErrorClass<SubscriberProtocolError>()(\n \"SubscriberProtocolError\",\n {\n subscriberId: SubscriberId,\n message: Schema.String,\n },\n) {}\n\n/** The host WebSocket boundary failed while sending a frame. */\nexport class SubscriberSendFailed extends Schema.TaggedErrorClass<SubscriberSendFailed>()(\n \"SubscriberSendFailed\",\n {\n subscriberId: SubscriberId,\n cause: Schema.Defect(),\n },\n) {}\n\n/** Expected error surface for one WebSocket subscriber workflow. */\nexport type EDAWebSocketSubscriberError =\n | SubscriberLagged\n | SubscriberProtocolError\n | SubscriberSendFailed\n | EDASessionStoreError;\n\n/** Transport boundary implemented by a host WebSocket adapter or tests. */\nexport interface EDAWebSocketSubscriberTransport {\n readonly send: (frame: EDAWebSocketServerFrame) => Effect.Effect<void, SubscriberSendFailed>;\n readonly incoming: Queue.Queue<EDAWebSocketClientFrame>;\n readonly closed: Deferred.Deferred<void>;\n readonly persistAck: (seq: SequenceNumber) => Effect.Effect<void>;\n}\n\n/** Configuration for one scoped ACK-window subscriber workflow. */\nexport interface EDAWebSocketSubscriberInput {\n readonly subscriberId: SubscriberId;\n readonly resumeSeq: SequenceNumber;\n readonly policy: EDAWebSocketFlowControl;\n readonly transport: EDAWebSocketSubscriberTransport;\n}\n\ninterface SentFrame {\n readonly frameId: FrameId;\n readonly durableThroughSeq: SequenceNumber;\n readonly sentAtMs: number;\n}\n\n/** Run one scoped, ACK-gated live-event WebSocket subscriber. */\nexport const runWebSocketSubscriber = (\n input: EDAWebSocketSubscriberInput,\n): Effect.Effect<void, EDAWebSocketSubscriberError, EDARuntime | Scope.Scope> =>\n Effect.gen(function* () {\n const eda = yield* EDARuntime;\n const outbound = yield* Queue.dropping<PositionedEvent>(\n input.policy.subscriberBufferCapacityEvents,\n );\n const windowSignal = yield* Queue.sliding<void>(1);\n const timeoutFailure = yield* Deferred.make<never, SubscriberLagged>();\n const lastAckedSeq = yield* Ref.make(input.resumeSeq);\n const lastAckedFrameId = yield* Ref.make(0);\n const lastSentFrameId = yield* Ref.make(0);\n const lastSentDurableThroughSeq = yield* Ref.make(input.resumeSeq);\n const nextFrameId = yield* Ref.make(FrameId.make(1));\n const inFlight = yield* Ref.make<ReadonlyArray<SentFrame>>([]);\n\n yield* input.transport.send(\n EDAWebSocketHelloFrame.make({\n _tag: \"hello\",\n protocolVersion: EDA_WEB_SOCKET_PROTOCOL_VERSION,\n subscriberId: input.subscriberId,\n resumeSeq: input.resumeSeq,\n flowControl: input.policy,\n }),\n );\n\n const events = yield* eda.eventsAfter(input.resumeSeq);\n // TODO(backpressure): this pump drains the replay/live stream into an intermediate queue ahead\n // of the ACK window. That bounded queue protects memory, but it still breaks end-to-end\n // backpressure from slow WebSocket clients to host-level paged durable replay.\n const pump = events.pipe(\n Stream.interruptWhen(Deferred.await(input.transport.closed)),\n Stream.runForEach((event) =>\n Queue.offer(outbound, event).pipe(\n Effect.flatMap((accepted) =>\n accepted\n ? Effect.void\n : Effect.gen(function* () {\n const seq = yield* Ref.get(lastAckedSeq);\n return yield* new SubscriberLagged({\n subscriberId: input.subscriberId,\n lastAckedSeq: seq,\n reason: \"buffer-overflow\",\n });\n }),\n ),\n ),\n ),\n );\n\n const sender = sendLoop({\n inFlight,\n input,\n lastAckedSeq,\n lastSentDurableThroughSeq,\n lastSentFrameId,\n nextFrameId,\n outbound,\n timeoutFailure,\n windowSignal,\n });\n const ackLoop = receiveAcks({\n inFlight,\n input,\n lastAckedFrameId,\n lastAckedSeq,\n lastSentFrameId,\n windowSignal,\n });\n\n yield* Effect.raceFirst(\n Deferred.await(input.transport.closed),\n Effect.raceFirst(\n Deferred.await(timeoutFailure),\n Effect.raceFirst(pump, Effect.raceFirst(sender, ackLoop)),\n ),\n );\n });\n\nconst sendLoop = (input: {\n readonly inFlight: Ref.Ref<ReadonlyArray<SentFrame>>;\n readonly input: EDAWebSocketSubscriberInput;\n readonly lastAckedSeq: Ref.Ref<SequenceNumber>;\n readonly lastSentDurableThroughSeq: Ref.Ref<SequenceNumber>;\n readonly lastSentFrameId: Ref.Ref<number>;\n readonly nextFrameId: Ref.Ref<FrameId>;\n readonly outbound: Queue.Queue<PositionedEvent>;\n readonly timeoutFailure: Deferred.Deferred<never, SubscriberLagged>;\n readonly windowSignal: Queue.Queue<void>;\n}): Effect.Effect<\n void,\n SubscriberLagged | SubscriberProtocolError | SubscriberSendFailed,\n Scope.Scope\n> =>\n Effect.forever(\n Effect.gen(function* () {\n yield* waitForWindow(\n input.inFlight,\n input.windowSignal,\n input.input.policy.maxInFlightFrames,\n );\n const next = yield* takeNextOutboundOrHeartbeat(\n input.outbound,\n input.input.policy.heartbeatIntervalMs,\n );\n if (next._tag === \"heartbeat\") {\n yield* sendHeartbeat(input.input, input.lastSentDurableThroughSeq);\n return;\n }\n\n const event = next.event;\n const frameId = yield* Ref.get(input.nextFrameId);\n yield* Ref.set(input.nextFrameId, FrameId.make(frameId + 1));\n\n const previousSentDurableSeq = yield* Ref.get(input.lastSentDurableThroughSeq);\n const durableThroughSeq = durableThroughForFrame([event], previousSentDurableSeq);\n const frame = EDAWebSocketEventsFrame.make({\n _tag: \"events\",\n frameId,\n events: [event],\n durableThroughSeq,\n });\n const encodedBytes = encodedFrameBytes(frame);\n if (encodedBytes > input.input.policy.maxFrameBytes) {\n return yield* new SubscriberProtocolError({\n subscriberId: input.input.subscriberId,\n message: `Encoded WebSocket frame exceeded maxFrameBytes (${encodedBytes} > ${input.input.policy.maxFrameBytes})`,\n });\n }\n\n const sentAtMs = yield* Clock.currentTimeMillis;\n const sent = { frameId, durableThroughSeq, sentAtMs } satisfies SentFrame;\n // Mark the frame in-flight before the synchronous host send so an immediate\n // client ACK cannot race ahead of our bookkeeping.\n yield* Ref.update(input.inFlight, (frames) => [...frames, sent]);\n yield* Ref.set(input.lastSentFrameId, frameId);\n yield* Ref.set(input.lastSentDurableThroughSeq, durableThroughSeq);\n yield* input.input.transport.send(frame);\n yield* startAckTimeout(\n input.input,\n input.inFlight,\n input.lastAckedSeq,\n input.timeoutFailure,\n sent,\n );\n }),\n );\n\nconst takeNextOutboundOrHeartbeat = (\n outbound: Queue.Queue<PositionedEvent>,\n heartbeatIntervalMs: number,\n): Effect.Effect<\n { readonly _tag: \"event\"; readonly event: PositionedEvent } | { readonly _tag: \"heartbeat\" }\n> =>\n Effect.raceFirst(\n Queue.take(outbound).pipe(Effect.map((event) => ({ _tag: \"event\", event }) as const)),\n Effect.sleep(`${heartbeatIntervalMs} millis`).pipe(Effect.as({ _tag: \"heartbeat\" } as const)),\n );\n\nconst sendHeartbeat = (\n input: EDAWebSocketSubscriberInput,\n lastSentDurableThroughSeq: Ref.Ref<SequenceNumber>,\n): Effect.Effect<void, SubscriberSendFailed> =>\n Effect.gen(function* () {\n const durableThroughSeq = yield* Ref.get(lastSentDurableThroughSeq);\n const serverTimeMs = yield* Clock.currentTimeMillis;\n yield* input.transport.send(\n EDAWebSocketHeartbeatFrame.make({\n _tag: \"heartbeat\",\n serverTimeMs: UnixEpochMillis.make(serverTimeMs),\n durableThroughSeq,\n }),\n );\n });\n\nconst receiveAcks = (input: {\n readonly inFlight: Ref.Ref<ReadonlyArray<SentFrame>>;\n readonly input: EDAWebSocketSubscriberInput;\n readonly lastAckedFrameId: Ref.Ref<number>;\n readonly lastAckedSeq: Ref.Ref<SequenceNumber>;\n readonly lastSentFrameId: Ref.Ref<number>;\n readonly windowSignal: Queue.Queue<void>;\n}): Effect.Effect<void, SubscriberProtocolError> =>\n Effect.forever(\n Effect.gen(function* () {\n const frame = yield* Queue.take(input.input.transport.incoming);\n if (frame._tag !== \"ack\") {\n return yield* new SubscriberProtocolError({\n subscriberId: input.input.subscriberId,\n message: `Unsupported client frame ${\n (\n frame as {\n readonly _tag?: string;\n }\n )._tag ?? \"unknown\"\n }`,\n });\n }\n yield* applyAck(input, frame as EDAWebSocketAckFrame);\n }),\n );\n\nconst applyAck = (\n input: Parameters<typeof receiveAcks>[0],\n ack: EDAWebSocketAckFrame,\n): Effect.Effect<void, SubscriberProtocolError> =>\n Effect.gen(function* () {\n const lastAckedFrame = yield* Ref.get(input.lastAckedFrameId);\n const lastSentFrame = yield* Ref.get(input.lastSentFrameId);\n const currentSeq = yield* Ref.get(input.lastAckedSeq);\n\n if (ack.frameId <= lastAckedFrame) {\n if (ack.durableThroughSeq > currentSeq) {\n return yield* new SubscriberProtocolError({\n subscriberId: input.input.subscriberId,\n message: \"Duplicate ACK attempted to advance durable seq\",\n });\n }\n return;\n }\n\n if (ack.frameId > lastSentFrame) {\n return yield* new SubscriberProtocolError({\n subscriberId: input.input.subscriberId,\n message: \"ACK referenced an unsent frame\",\n });\n }\n\n if (ack.durableThroughSeq < currentSeq) {\n return yield* new SubscriberProtocolError({\n subscriberId: input.input.subscriberId,\n message: \"ACK durable seq moved backwards\",\n });\n }\n\n const frames = yield* Ref.get(input.inFlight);\n const acknowledged = frames.filter((frame) => frame.frameId <= ack.frameId);\n if (acknowledged.length === 0) {\n return yield* new SubscriberProtocolError({\n subscriberId: input.input.subscriberId,\n message: \"ACK referenced no in-flight frames\",\n });\n }\n const allowedDurableSeq = SequenceNumber.make(\n acknowledged.reduce<number>(\n (max, frame) => Math.max(max, frame.durableThroughSeq),\n currentSeq,\n ),\n );\n if (ack.durableThroughSeq > allowedDurableSeq) {\n return yield* new SubscriberProtocolError({\n subscriberId: input.input.subscriberId,\n message: \"ACK durable seq exceeded sent frame boundary\",\n });\n }\n\n yield* Ref.update(input.inFlight, (frames) =>\n frames.filter((frame) => frame.frameId > ack.frameId),\n );\n yield* Ref.set(input.lastAckedFrameId, ack.frameId);\n yield* Ref.set(input.lastAckedSeq, ack.durableThroughSeq);\n yield* input.input.transport.persistAck(ack.durableThroughSeq);\n yield* Queue.offer(input.windowSignal, undefined);\n });\n\nconst waitForWindow = (\n inFlight: Ref.Ref<ReadonlyArray<SentFrame>>,\n windowSignal: Queue.Queue<void>,\n maxInFlightFrames: number,\n): Effect.Effect<void> =>\n Effect.gen(function* () {\n while (true) {\n const frames = yield* Ref.get(inFlight);\n if (frames.length < maxInFlightFrames) {\n return;\n }\n yield* Queue.take(windowSignal);\n }\n });\n\nconst startAckTimeout = (\n input: EDAWebSocketSubscriberInput,\n inFlight: Ref.Ref<ReadonlyArray<SentFrame>>,\n lastAckedSeq: Ref.Ref<SequenceNumber>,\n timeoutFailure: Deferred.Deferred<never, SubscriberLagged>,\n sent: SentFrame,\n): Effect.Effect<void, never, Scope.Scope> =>\n Effect.gen(function* () {\n yield* Effect.sleep(`${input.policy.ackTimeoutMs} millis`);\n const stillInFlight = (yield* Ref.get(inFlight)).some(\n (frame) => frame.frameId === sent.frameId,\n );\n if (!stillInFlight) {\n return;\n }\n const seq = yield* Ref.get(lastAckedSeq);\n yield* Deferred.fail(\n timeoutFailure,\n new SubscriberLagged({\n subscriberId: input.subscriberId,\n lastAckedSeq: seq,\n reason: \"ack-timeout\",\n }),\n );\n }).pipe(Effect.forkScoped, Effect.asVoid);\n\nconst durableThroughForFrame = (\n events: ReadonlyArray<PositionedEvent>,\n previousSentDurableSeq: SequenceNumber,\n): SequenceNumber =>\n SequenceNumber.make(\n events.reduce<number>(\n (max, event) =>\n event.event.durability === \"durable\" ? Math.max(max, event.position.seq) : max,\n previousSentDurableSeq,\n ),\n );\n\nconst encodedFrameBytes = (frame: EDAWebSocketServerFrame): number =>\n new TextEncoder().encode(JSON.stringify(frame)).byteLength;\n"],"mappings":";;;;;;;;;;;;;AA2BA,MAAa,sBAAsB,OAAO,SAAS,CAAC,mBAAmB,aAAa,CAAC;;AAIrF,IAAa,mBAAb,cAAsC,OAAO,iBAAmC,EAC9E,oBACA;CACE,cAAc;CACd,cAAc;CACd,QAAQ;AACV,CACF,EAAE,CAAC;;AAGH,IAAa,0BAAb,cAA6C,OAAO,iBAA0C,EAC5F,2BACA;CACE,cAAc;CACd,SAAS,OAAO;AAClB,CACF,EAAE,CAAC;;AAGH,IAAa,uBAAb,cAA0C,OAAO,iBAAuC,EACtF,wBACA;CACE,cAAc;CACd,OAAO,OAAO,OAAO;AACvB,CACF,EAAE,CAAC;;AAgCH,MAAa,0BACX,UAEA,OAAO,IAAI,aAAa;CACtB,MAAM,MAAM,OAAO;CACnB,MAAM,WAAW,OAAO,MAAM,SAC5B,MAAM,OAAO,8BACf;CACA,MAAM,eAAe,OAAO,MAAM,QAAc,CAAC;CACjD,MAAM,iBAAiB,OAAO,SAAS,KAA8B;CACrE,MAAM,eAAe,OAAO,IAAI,KAAK,MAAM,SAAS;CACpD,MAA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K,UACJ,MAAM,MAAM,eAAe,YAAY,KAAK,IAAI,KAAK,MAAM,SAAS,GAAG,IAAI,KAC7E,sBACF,CACF;AAEF,MAAM,qBAAqB,UACzB,IAAI,YAAY,EAAE,OAAO,KAAK,UAAU,KAAK,CAAC,EAAE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sink-registry-D13eUO_c.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/** In-memory live fanout plus active-turn replay source for reconnect streams. */\nexport interface LiveEventBusShape {\n readonly publish: (event: PositionedEvent) => Effect.Effect<boolean>;\n readonly subscribe: () => Effect.Effect<Stream.Stream<PositionedEvent>, never, Scope.Scope>;\n readonly subscribeQueue: () => Effect.Effect<\n PubSub.Subscription<PositionedEvent>,\n never,\n Scope.Scope\n >;\n /** Snapshot raw live-only events retained for the currently open turn. */\n readonly activeTurnReplay: () => Effect.Effect<ActiveTurnEphemeralReplay>;\n}\n\n/** Unbounded in-memory fanout plus bounded active-turn ephemeral replay. */\nexport class LiveEventBus extends Context.Service<LiveEventBus, LiveEventBusShape>()(\n \"@effect-durable-agent/LiveEventBus\",\n) {\n static readonly Live = Layer.effect(\n LiveEventBus,\n Effect.gen(function* () {\n const pubsub = yield* Effect.acquireRelease(\n PubSub.unbounded<PositionedEvent>(),\n PubSub.shutdown,\n );\n const activeTurnReplay = yield* Ref.make<ActiveTurnEphemeralReplay>({\n events: [],\n overflowed: false,\n });\n return makeLiveBus(pubsub, activeTurnReplay);\n }),\n );\n}\n\nconst makeLiveBus = (\n pubsub: PubSub.PubSub<PositionedEvent>,\n activeTurnReplay: Ref.Ref<ActiveTurnEphemeralReplay>,\n): LiveEventBusShape => ({\n publish: (event) =>\n updateActiveTurnReplay(activeTurnReplay, event).pipe(\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});\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 Duration from \"effect/Duration\";\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 Schedule from \"effect/Schedule\";\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/** At-least-once sink definition backed by a durable checkpoint. */\nexport interface EDADurableSinkDefinition {\n readonly interests?: ReadonlyArray<EventType | string>;\n readonly batchSize?: number;\n readonly process: (\n batch: EDASinkDurableBatch,\n ctx: EDASinkContext,\n ) => Effect.Effect<void, unknown>;\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, unknown>;\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. Durable callbacks are\n * retried before the sink checkpoint advances; ephemeral callbacks are best-effort\n * and are only processed after the durable prefix at their anchor sequence has\n * 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 maxDurableSinkRetryDelay = Duration.seconds(5);\nconst sinkCheckpointFormatVersion = 1;\nconst durableSinkRetrySchedule = Schedule.exponential(\"100 millis\").pipe(\n Schedule.jittered,\n Schedule.modifyDelay(({ duration }) =>\n Effect.succeed(Duration.min(duration, maxDurableSinkRetryDelay)),\n ),\n);\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 yield* durable.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 if (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 processDurableBatchWithRetry = (events: ReadonlyArray<CommittedDurableEvent>) =>\n keepAlive.withActiveWork(\n `sink:${sink.name}`,\n processDurableBatch(events).pipe(\n Effect.tapError((error) =>\n Effect.logWarning(\"EDA sink durable projection failed; retrying\", {\n error: formatSinkError(error),\n sink: sink.name,\n }),\n ),\n Effect.retry(durableSinkRetrySchedule),\n ),\n );\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* processDurableBatchWithRetry(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* processDurableBatchWithRetry([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\nconst formatSinkError = (error: unknown): string => {\n if (Cause.isUnknownError(error)) {\n return `${error.message ?? error._tag}: ${formatSinkError(error.cause)}`;\n }\n return error instanceof Error ? error.message : String(error);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAkBA,MAAa,oCAAoC;;AAuBjD,IAAa,eAAb,MAAa,qBAAqB,QAAQ,QAAyC,EACjF,oCACF,EAAE;CACA,OAAgB,OAAO,MAAM,OAC3B,cACA,OAAO,IAAI,aAAa;EAStB,OAAO,YAAY,OARG,OAAO,eAC3B,OAAO,UAA2B,GAClC,OAAO,QACT,GAK2B,OAJK,IAAI,KAAgC;GAClE,QAAQ,CAAC;GACT,YAAY;EACd,CAAC,CAC0C;CAC7C,CAAC,CACH;AACF;AAEA,MAAM,eACJ,QACA,sBACuB;CACvB,UAAU,UACR,uBAAuB,kBAAkB,KAAK,EAAE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ria-labelledby="title description"
|
|
8
|
-
>
|
|
9
|
-
<title id="title">Effect Durable Agent framework components</title>
|
|
10
|
-
<desc id="description">
|
|
11
|
-
Commands and application events enter the EDA session runtime and are recorded in an ordered
|
|
12
|
-
durable event log. The log feeds three balanced lanes: a live event stream for reconnecting
|
|
13
|
-
clients, pure reducers that produce framework and application state, and durable sinks for
|
|
14
|
-
external systems. State feeds separate pure UI and language-model context projections.
|
|
15
|
-
</desc>
|
|
16
|
-
|
|
17
|
-
<defs>
|
|
18
|
-
<marker
|
|
19
|
-
id="arrow"
|
|
20
|
-
viewBox="0 0 10 10"
|
|
21
|
-
refX="8"
|
|
22
|
-
refY="5"
|
|
23
|
-
markerWidth="7"
|
|
24
|
-
markerHeight="7"
|
|
25
|
-
orient="auto"
|
|
26
|
-
>
|
|
27
|
-
<path d="M 0 0 L 10 5 L 0 10 z" fill="#4f5d75" />
|
|
28
|
-
</marker>
|
|
29
|
-
<marker
|
|
30
|
-
id="arrow-accent"
|
|
31
|
-
viewBox="0 0 10 10"
|
|
32
|
-
refX="8"
|
|
33
|
-
refY="5"
|
|
34
|
-
markerWidth="7"
|
|
35
|
-
markerHeight="7"
|
|
36
|
-
orient="auto"
|
|
37
|
-
>
|
|
38
|
-
<path d="M 0 0 L 10 5 L 0 10 z" fill="#9a674f" />
|
|
39
|
-
</marker>
|
|
40
|
-
<style>
|
|
41
|
-
.card-title {
|
|
42
|
-
fill: #2d3142;
|
|
43
|
-
font: 700 18px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
44
|
-
}
|
|
45
|
-
.card-copy {
|
|
46
|
-
fill: #4f5d75;
|
|
47
|
-
font: 500 13px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
48
|
-
}
|
|
49
|
-
.inverse-title {
|
|
50
|
-
fill: #ffffff;
|
|
51
|
-
font: 700 18px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
52
|
-
}
|
|
53
|
-
.inverse-copy {
|
|
54
|
-
fill: #e5e7eb;
|
|
55
|
-
font: 500 13px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
56
|
-
}
|
|
57
|
-
.node-input {
|
|
58
|
-
fill: #eceeef;
|
|
59
|
-
stroke: #bfc0c0;
|
|
60
|
-
}
|
|
61
|
-
.node-runtime {
|
|
62
|
-
fill: #2d3142;
|
|
63
|
-
stroke: #2d3142;
|
|
64
|
-
}
|
|
65
|
-
.node-focal {
|
|
66
|
-
fill: #f2ebe7;
|
|
67
|
-
stroke: #9a674f;
|
|
68
|
-
stroke-width: 1.5;
|
|
69
|
-
}
|
|
70
|
-
.node-primary {
|
|
71
|
-
fill: #ffffff;
|
|
72
|
-
stroke: #2d3142;
|
|
73
|
-
}
|
|
74
|
-
.node-secondary {
|
|
75
|
-
fill: #ffffff;
|
|
76
|
-
stroke: #bfc0c0;
|
|
77
|
-
}
|
|
78
|
-
.node-external {
|
|
79
|
-
fill: #f0f0f0;
|
|
80
|
-
stroke: #bfc0c0;
|
|
81
|
-
}
|
|
82
|
-
.step-number {
|
|
83
|
-
fill: #c8cacf;
|
|
84
|
-
font: 500 40px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
85
|
-
}
|
|
86
|
-
.arrow {
|
|
87
|
-
fill: none;
|
|
88
|
-
stroke: #4f5d75;
|
|
89
|
-
stroke-width: 2.5;
|
|
90
|
-
marker-end: url(#arrow);
|
|
91
|
-
}
|
|
92
|
-
.arrow-accent {
|
|
93
|
-
fill: none;
|
|
94
|
-
stroke: #9a674f;
|
|
95
|
-
stroke-width: 2.5;
|
|
96
|
-
marker-end: url(#arrow-accent);
|
|
97
|
-
}
|
|
98
|
-
</style>
|
|
99
|
-
</defs>
|
|
100
|
-
|
|
101
|
-
<rect width="1200" height="865" rx="18" fill="#f5f5f5" />
|
|
102
|
-
|
|
103
|
-
<rect class="node-input" x="360" y="20" width="480" height="65" rx="12" />
|
|
104
|
-
<text class="card-title" x="600" y="48" text-anchor="middle">
|
|
105
|
-
Commands + application events
|
|
106
|
-
</text>
|
|
107
|
-
<text class="card-copy" x="600" y="70" text-anchor="middle">User intent + product facts</text>
|
|
108
|
-
|
|
109
|
-
<path class="arrow" d="M 600 85 V 113" />
|
|
110
|
-
|
|
111
|
-
<rect class="node-runtime" x="360" y="115" width="480" height="70" rx="12" />
|
|
112
|
-
<text class="step-number" x="344" y="164" text-anchor="end">1</text>
|
|
113
|
-
<text class="inverse-title" x="600" y="145" text-anchor="middle">EDA session runtime</text>
|
|
114
|
-
<text class="inverse-copy" x="600" y="168" text-anchor="middle">
|
|
115
|
-
Effect workflows inside one Durable Object
|
|
116
|
-
</text>
|
|
117
|
-
|
|
118
|
-
<path class="arrow-accent" d="M 600 185 V 213" />
|
|
119
|
-
|
|
120
|
-
<rect class="node-focal" x="360" y="215" width="480" height="75" rx="12" />
|
|
121
|
-
<text class="step-number" x="344" y="268" text-anchor="end">2</text>
|
|
122
|
-
<text class="card-title" x="600" y="246" text-anchor="middle">
|
|
123
|
-
Ordered durable event log
|
|
124
|
-
</text>
|
|
125
|
-
<text class="card-copy" x="600" y="269" text-anchor="middle">
|
|
126
|
-
Framework + application events · Durable Object SQLite
|
|
127
|
-
</text>
|
|
128
|
-
|
|
129
|
-
<path class="arrow" d="M 480 290 V 317 Q 480 325 472 325 H 208 Q 200 325 200 333 V 348" />
|
|
130
|
-
<path class="arrow-accent" d="M 600 290 V 348" />
|
|
131
|
-
<path class="arrow" d="M 720 290 V 317 Q 720 325 728 325 H 992 Q 1000 325 1000 333 V 348" />
|
|
132
|
-
|
|
133
|
-
<rect class="node-secondary" x="60" y="350" width="280" height="100" rx="12" />
|
|
134
|
-
<text class="step-number" x="44" y="416" text-anchor="end">3</text>
|
|
135
|
-
<text class="card-title" x="200" y="389" text-anchor="middle">Live event stream</text>
|
|
136
|
-
<text class="card-copy" x="200" y="415" text-anchor="middle">
|
|
137
|
-
Committed events over WebSockets
|
|
138
|
-
</text>
|
|
139
|
-
<text class="card-copy" x="200" y="436" text-anchor="middle">
|
|
140
|
-
Ordered by event sequence
|
|
141
|
-
</text>
|
|
142
|
-
|
|
143
|
-
<rect class="node-primary" x="450" y="350" width="300" height="100" rx="12" />
|
|
144
|
-
<text class="step-number" x="434" y="416" text-anchor="end">4</text>
|
|
145
|
-
<text class="card-title" x="600" y="389" text-anchor="middle">Pure reducers</text>
|
|
146
|
-
<text class="card-copy" x="600" y="415" text-anchor="middle">
|
|
147
|
-
Framework reducers + application reducers
|
|
148
|
-
</text>
|
|
149
|
-
<text class="card-copy" x="600" y="436" text-anchor="middle">
|
|
150
|
-
Deterministic at every sequence
|
|
151
|
-
</text>
|
|
152
|
-
|
|
153
|
-
<rect class="node-secondary" x="860" y="350" width="280" height="100" rx="12" />
|
|
154
|
-
<text class="step-number" x="844" y="416" text-anchor="end">7</text>
|
|
155
|
-
<text class="card-title" x="1000" y="389" text-anchor="middle">Durable sinks</text>
|
|
156
|
-
<text class="card-copy" x="1000" y="415" text-anchor="middle">
|
|
157
|
-
Committed events · persisted cursors
|
|
158
|
-
</text>
|
|
159
|
-
<text class="card-copy" x="1000" y="436" text-anchor="middle">
|
|
160
|
-
At-least-once delivery · retry
|
|
161
|
-
</text>
|
|
162
|
-
|
|
163
|
-
<path class="arrow" d="M 200 450 V 508" />
|
|
164
|
-
<path class="arrow-accent" d="M 600 450 V 508" />
|
|
165
|
-
<path class="arrow" d="M 1000 450 V 508" />
|
|
166
|
-
|
|
167
|
-
<rect class="node-external" x="60" y="510" width="280" height="70" rx="12" />
|
|
168
|
-
<text class="card-title" x="200" y="539" text-anchor="middle">Reconnecting clients</text>
|
|
169
|
-
<text class="card-copy" x="200" y="562" text-anchor="middle">
|
|
170
|
-
Catch up, then continue live
|
|
171
|
-
</text>
|
|
172
|
-
|
|
173
|
-
<rect class="node-focal" x="450" y="510" width="300" height="100" rx="12" />
|
|
174
|
-
<text class="step-number" x="434" y="576" text-anchor="end">5</text>
|
|
175
|
-
<text class="card-title" x="600" y="549" text-anchor="middle">State</text>
|
|
176
|
-
<text class="card-copy" x="600" y="575" text-anchor="middle">
|
|
177
|
-
Framework state + application state
|
|
178
|
-
</text>
|
|
179
|
-
<text class="card-copy" x="600" y="596" text-anchor="middle">
|
|
180
|
-
Snapshot through sequence N
|
|
181
|
-
</text>
|
|
182
|
-
|
|
183
|
-
<rect class="node-external" x="860" y="510" width="280" height="55" rx="12" />
|
|
184
|
-
<text class="card-title" x="1000" y="544" text-anchor="middle">External systems</text>
|
|
185
|
-
|
|
186
|
-
<path class="arrow" d="M 550 610 V 627 Q 550 635 542 635 H 473 Q 465 635 465 643 V 658" />
|
|
187
|
-
<path class="arrow" d="M 650 610 V 627 Q 650 635 658 635 H 727 Q 735 635 735 643 V 658" />
|
|
188
|
-
|
|
189
|
-
<rect class="node-primary" x="340" y="660" width="250" height="110" rx="12" />
|
|
190
|
-
<text class="step-number" x="324" y="732" text-anchor="end">6</text>
|
|
191
|
-
<text class="card-title" x="465" y="698" text-anchor="middle">Pure UI projection</text>
|
|
192
|
-
<text class="card-copy" x="465" y="723" text-anchor="middle">
|
|
193
|
-
Renderable state for humans
|
|
194
|
-
</text>
|
|
195
|
-
<text class="card-copy" x="465" y="746" text-anchor="middle">
|
|
196
|
-
Full history · tools · product state
|
|
197
|
-
</text>
|
|
198
|
-
|
|
199
|
-
<rect class="node-primary" x="610" y="660" width="250" height="110" rx="12" />
|
|
200
|
-
<text class="card-title" x="735" y="698" text-anchor="middle">LLM context projection</text>
|
|
201
|
-
<text class="card-copy" x="735" y="723" text-anchor="middle">
|
|
202
|
-
Purpose-built state for the model
|
|
203
|
-
</text>
|
|
204
|
-
<text class="card-copy" x="735" y="746" text-anchor="middle">
|
|
205
|
-
Selected · compacted · model-ready
|
|
206
|
-
</text>
|
|
207
|
-
|
|
208
|
-
<path class="arrow" d="M 465 770 V 798" />
|
|
209
|
-
<path class="arrow" d="M 735 770 V 798" />
|
|
210
|
-
|
|
211
|
-
<rect class="node-external" x="340" y="800" width="250" height="45" rx="12" />
|
|
212
|
-
<text class="card-title" x="465" y="829" text-anchor="middle">User interfaces</text>
|
|
213
|
-
|
|
214
|
-
<rect class="node-external" x="610" y="800" width="250" height="45" rx="12" />
|
|
215
|
-
<text class="card-title" x="735" y="829" text-anchor="middle">Language model</text>
|
|
216
|
-
</svg>
|