effect-durable-agent 0.1.0-alpha.3 → 0.1.0-alpha.30
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 +43 -41
- package/dist/assert-never-CoyUpoRB.js +18 -0
- package/dist/assert-never-CoyUpoRB.js.map +1 -0
- package/dist/{commands-Ce1ec6kH.d.ts → commands-3OD-p8dD.d.ts} +16 -9
- package/dist/compaction-63iEDHHl.js +523 -0
- package/dist/compaction-63iEDHHl.js.map +1 -0
- package/dist/context-projection-D_uRtK3r.d.ts +139 -0
- package/dist/{core-Hv3cFydL.d.ts → core-BcimKMIv.d.ts} +6 -4
- package/dist/delivery-2ZILvoRD.js +507 -0
- package/dist/delivery-2ZILvoRD.js.map +1 -0
- package/dist/{websocket-wire-D3tLrhe2.d.ts → delivery-RjM1_NAE.d.ts} +1019 -200
- package/dist/domain/command-queues.d.ts +81 -2
- package/dist/domain/command-queues.js +1 -1
- package/dist/domain/command-queues.js.map +1 -1
- package/dist/domain/context-projection.d.ts +2 -0
- package/dist/domain/context-projection.js +32 -0
- package/dist/domain/context-projection.js.map +1 -0
- package/dist/domain/message-transcript.d.ts +36 -2
- package/dist/domain/message-transcript.js +10 -2
- package/dist/domain/message-transcript.js.map +1 -1
- package/dist/domain/model-usage.d.ts +2 -0
- package/dist/domain/model-usage.js +59 -0
- package/dist/domain/model-usage.js.map +1 -0
- package/dist/domain/reduced-state-schema.d.ts +3 -996
- package/dist/domain/reduced-state-schema.js +121 -12
- package/dist/domain/reduced-state-schema.js.map +1 -1
- package/dist/domain/reduced-state.d.ts +3 -2
- package/dist/domain/reduced-state.js +937 -2
- package/dist/domain/reduced-state.js.map +1 -0
- package/dist/domain/run-scheduling.d.ts +2 -0
- package/dist/domain/run-scheduling.js +127 -0
- package/dist/domain/run-scheduling.js.map +1 -0
- package/dist/{durable-DlScwmCy.d.ts → durable-Cqv5ZRFA.d.ts} +8505 -2497
- package/dist/{durable-C3Rz7kg3.js → durable-D13w1Qr3.js} +253 -91
- package/dist/durable-D13w1Qr3.js.map +1 -0
- package/dist/envelope-BCzKUq_z.js +91 -0
- package/dist/envelope-BCzKUq_z.js.map +1 -0
- package/dist/envelope-Che6KatU.d.ts +254 -0
- package/dist/{keep-alive-p8dIcSVy.js → event-factory-_vF1bIJ7.js} +8 -10
- package/dist/event-factory-_vF1bIJ7.js.map +1 -0
- package/dist/{events-Bb9-Cu-7.d.ts → events-Dg0o5wWs.d.ts} +140 -324
- package/dist/{id-generator-C2Q15uZM.d.ts → id-generator-BKGoKjt-.d.ts} +3 -3
- package/dist/in-memory-CeODnZhE.js +150 -0
- package/dist/in-memory-CeODnZhE.js.map +1 -0
- package/dist/index.d.ts +8 -7
- package/dist/index.js +6 -5
- package/dist/interpreter-DKGJ1sSx.js +1452 -0
- package/dist/interpreter-DKGJ1sSx.js.map +1 -0
- package/dist/keep-alive-_zFCUvt3.d.ts +28 -0
- package/dist/model-resolver-D0vcDZsU.d.ts +24 -0
- package/dist/model-usage-0GeHwaaU.d.ts +54 -0
- package/dist/records--54mZEBx.js +675 -0
- package/dist/records--54mZEBx.js.map +1 -0
- package/dist/reduced-state-DU2ECOUp.d.ts +47821 -0
- package/dist/reduced-state-schema-B2t3cobf.d.ts +2187 -0
- package/dist/{reducer-registry-C0svUa63.d.ts → reducer-registry-JLU1yptN.d.ts} +24 -8
- package/dist/run-scheduling-wakeup-D_bGdicf.d.ts +24 -0
- package/dist/services/compaction.d.ts +2 -2
- package/dist/services/compaction.js +2 -426
- package/dist/services/id-generator.d.ts +1 -1
- package/dist/services/id-generator.js +4 -2
- package/dist/services/id-generator.js.map +1 -1
- package/dist/services/keep-alive.d.ts +2 -0
- package/dist/services/keep-alive.js +13 -0
- package/dist/services/keep-alive.js.map +1 -0
- package/dist/services/model-call.d.ts +15 -0
- package/dist/services/model-call.js +15 -0
- package/dist/services/model-call.js.map +1 -0
- package/dist/services/model-resolver.d.ts +2 -0
- package/dist/services/model-resolver.js +17 -0
- package/dist/services/model-resolver.js.map +1 -0
- package/dist/services/prompt-projector.d.ts +2 -2
- package/dist/services/prompt-projector.js +49 -5
- package/dist/services/prompt-projector.js.map +1 -1
- package/dist/services/reducer-registry.d.ts +2 -2
- package/dist/services/reducer-registry.js +21 -4
- package/dist/services/reducer-registry.js.map +1 -1
- package/dist/services/run-scheduler.d.ts +2 -0
- package/dist/services/run-scheduler.js +25 -0
- package/dist/services/run-scheduler.js.map +1 -0
- package/dist/services/run-scheduling-wakeup.d.ts +2 -0
- package/dist/services/run-scheduling-wakeup.js +13 -0
- package/dist/services/run-scheduling-wakeup.js.map +1 -0
- package/dist/services/runtime-layer.d.ts +48 -0
- package/dist/services/runtime-layer.js +51 -0
- package/dist/services/runtime-layer.js.map +1 -0
- package/dist/services/runtime.d.ts +1 -1
- package/dist/services/runtime.js +34 -20
- package/dist/services/runtime.js.map +1 -1
- package/dist/services/session-event-observer.d.ts +2 -0
- package/dist/services/session-event-observer.js +13 -0
- package/dist/services/session-event-observer.js.map +1 -0
- package/dist/services/session-query.d.ts +2 -2
- package/dist/services/session-query.js +141 -2
- package/dist/services/session-query.js.map +1 -0
- package/dist/services/session-state.d.ts +2 -0
- package/dist/services/session-state.js +2 -0
- package/dist/services/session-store.d.ts +2 -2
- package/dist/services/session-store.js +272 -2
- package/dist/services/session-store.js.map +1 -0
- package/dist/services/sink-checkpoint-store.d.ts +2 -0
- package/dist/services/sink-checkpoint-store.js +50 -0
- package/dist/services/sink-checkpoint-store.js.map +1 -0
- package/dist/services/sink-registry.d.ts +2 -2
- package/dist/services/sink-registry.js +1 -1
- package/dist/services/span-names.d.ts +1 -1
- package/dist/services/span-names.js +7 -1
- package/dist/services/span-names.js.map +1 -1
- package/dist/services/tool-registry.d.ts +2 -2
- package/dist/services/tool-registry.js +12 -3
- package/dist/services/tool-registry.js.map +1 -1
- package/dist/services/tracing.d.ts +3 -3
- package/dist/services/tracing.js +25 -4
- package/dist/services/tracing.js.map +1 -1
- package/dist/session-event-observer-HvrRckbC.d.ts +24 -0
- package/dist/{session-query-Cbf-e0rG.js → session-state-BQYsuBqi.js} +693 -251
- package/dist/session-state-BQYsuBqi.js.map +1 -0
- package/dist/session-store-CQxg9U82.d.ts +3302 -0
- package/dist/sink-checkpoint-store-DWGifxp0.d.ts +39 -0
- package/dist/sink-registry-DskRcyOS.js +345 -0
- package/dist/sink-registry-DskRcyOS.js.map +1 -0
- package/dist/subscription-DmO3BcdT.js +505 -0
- package/dist/subscription-DmO3BcdT.js.map +1 -0
- package/dist/subscription-rC35dAWn.d.ts +958 -0
- package/dist/testkit/layers.d.ts +34 -19
- package/dist/testkit/layers.js +30 -16
- package/dist/testkit/layers.js.map +1 -1
- package/dist/testkit/transcript.d.ts +226 -0
- package/dist/testkit/transcript.js +1475 -0
- package/dist/testkit/transcript.js.map +1 -0
- package/dist/{tool-registry-CcnkAAQK.d.ts → tool-registry-BzlMhwzj.d.ts} +44 -8
- package/dist/{tracing-BXHAkxkx.d.ts → tracing-BwjbF285.d.ts} +1 -2
- package/dist/transcript.d.ts +101 -0
- package/dist/transcript.js +107 -0
- package/dist/transcript.js.map +1 -0
- package/dist/types/commands.d.ts +2 -2
- package/dist/types/commands.js +8 -3
- package/dist/types/commands.js.map +1 -1
- package/dist/types/core.d.ts +2 -2
- package/dist/types/core.js +4 -2
- package/dist/types/core.js.map +1 -1
- package/dist/types/events/durable.d.ts +2 -2
- package/dist/types/events/durable.js +2 -2
- package/dist/types/events.d.ts +5 -4
- package/dist/types/events.js +3 -2
- package/dist/types/events.js.map +1 -1
- package/dist/types/tracing.d.ts +1 -1
- package/dist/types/tracing.js.map +1 -1
- package/dist/websocket/events.d.ts +2 -0
- package/dist/websocket/events.js +2 -0
- package/dist/websocket.d.ts +2201 -0
- package/dist/websocket.js +684 -0
- package/dist/websocket.js.map +1 -0
- package/dist/window-read-CBZEJ84M.d.ts +113 -0
- package/dist/window-read-DPFAA1hM.js +264 -0
- package/dist/window-read-DPFAA1hM.js.map +1 -0
- package/package.json +87 -46
- package/testing/offline-trace/README.md +2 -1
- package/CHANGELOG.md +0 -25
- package/CONTRIBUTING.md +0 -26
- package/SECURITY.md +0 -7
- package/dist/command-queues-CQ9cwRP7.d.ts +0 -468
- package/dist/compaction-1LSZR944.d.ts +0 -144
- package/dist/durable-C3Rz7kg3.js.map +0 -1
- package/dist/durable-object-runtime-CiMKxGs6.d.ts +0 -257
- package/dist/durable-object-runtime-wKiqaAt2.js +0 -1494
- package/dist/durable-object-runtime-wKiqaAt2.js.map +0 -1
- package/dist/durable-object-storage-Czy7IPrh.d.ts +0 -41
- package/dist/host/durable-object-runtime.d.ts +0 -2
- package/dist/host/durable-object-runtime.js +0 -2
- package/dist/host/durable-object-storage.d.ts +0 -2
- package/dist/host/durable-object-storage.js +0 -0
- package/dist/host/durable-object.d.ts +0 -83
- package/dist/host/durable-object.js +0 -191
- package/dist/host/durable-object.js.map +0 -1
- package/dist/host/websocket-wire.d.ts +0 -2
- package/dist/host/websocket-wire.js +0 -105
- package/dist/host/websocket-wire.js.map +0 -1
- package/dist/index-BVVgDSdq.d.ts +0 -1
- package/dist/keep-alive-DYDsH6qN.d.ts +0 -111
- package/dist/keep-alive-p8dIcSVy.js.map +0 -1
- package/dist/message-transcript-BCHdHAe2.d.ts +0 -32
- package/dist/prompt-projector-DimXJPOJ.d.ts +0 -39
- package/dist/reduced-state-C4nVVzz9.js +0 -910
- package/dist/reduced-state-C4nVVzz9.js.map +0 -1
- package/dist/runtime-DcdPOEuE.d.ts +0 -60
- package/dist/services/compaction.js.map +0 -1
- package/dist/session-query-Cbf-e0rG.js.map +0 -1
- package/dist/session-query-hxfujxUH.d.ts +0 -769
- package/dist/session-store-D2Ore1QC.d.ts +0 -295
- package/dist/session-store-pYxQW9qh.js +0 -214
- package/dist/session-store-pYxQW9qh.js.map +0 -1
- package/dist/sink-registry-BziFpxoE.d.ts +0 -158
- package/dist/sink-registry-CFC6xjsN.js +0 -312
- package/dist/sink-registry-CFC6xjsN.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 -96
- 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/examples/001-no-tools/README.md +0 -65
- package/examples/001-no-tools/worker.ts +0 -79
- package/examples/002-slack-bridge/README.md +0 -134
- package/examples/002-slack-bridge/events.ts +0 -115
- package/examples/002-slack-bridge/reducer.ts +0 -216
- package/examples/002-slack-bridge/scenario.test.ts +0 -223
- package/examples/002-slack-bridge/sinks.ts +0 -109
- package/examples/002-slack-bridge/worker.ts +0 -140
- package/examples/003-sandbox-lifecycle/README.md +0 -78
- package/examples/003-sandbox-lifecycle/events.ts +0 -203
- package/examples/003-sandbox-lifecycle/reducer.ts +0 -305
- package/examples/003-sandbox-lifecycle/scenario.test.ts +0 -202
- package/examples/_shared/event-id.ts +0 -12
- package/examples/_shared/http.ts +0 -27
- package/examples/_shared/openai.ts +0 -33
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
//#region src/domain/context-projection.d.ts
|
|
3
|
+
/** Stable identifier for the compaction policy that selected a summary plan. */
|
|
4
|
+
declare const CompactionPolicyId: Schema.brand<Schema.NonEmptyString, "CompactionPolicyId">;
|
|
5
|
+
type CompactionPolicyId = typeof CompactionPolicyId.Type;
|
|
6
|
+
/** Stable identifier for the executor that produced a summary artifact. */
|
|
7
|
+
declare const CompactionExecutorId: Schema.brand<Schema.NonEmptyString, "CompactionExecutorId">;
|
|
8
|
+
type CompactionExecutorId = typeof CompactionExecutorId.Type;
|
|
9
|
+
/** Authoritative cumulative model-context summary written with `SummaryCreated`. */
|
|
10
|
+
declare const CompactionSummaryArtifact: Schema.Struct<{
|
|
11
|
+
readonly compactionId: Schema.brand<Schema.String, "CompactionId">;
|
|
12
|
+
readonly summaryId: Schema.brand<Schema.String, "SummaryId">;
|
|
13
|
+
readonly previousSummaryId: Schema.optionalKey<Schema.brand<Schema.String, "SummaryId">>;
|
|
14
|
+
readonly sourceFromSeq: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
15
|
+
readonly sourceToSeq: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
16
|
+
readonly retainedFromContextSeq: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
17
|
+
readonly text: Schema.NonEmptyString;
|
|
18
|
+
readonly promptMessage: Schema.Struct<{
|
|
19
|
+
readonly role: Schema.Literal<"user">;
|
|
20
|
+
readonly content: Schema.Union<readonly [Schema.decodeTo<Schema.NonEmptyArray<Schema.toType<Schema.Struct<{
|
|
21
|
+
readonly type: Schema.Literal<"text">;
|
|
22
|
+
readonly text: Schema.String;
|
|
23
|
+
readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Part">>;
|
|
24
|
+
readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
|
|
25
|
+
}>>>, Schema.String, never, never>, Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
26
|
+
readonly type: Schema.Literal<"text">;
|
|
27
|
+
readonly text: Schema.String;
|
|
28
|
+
readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Part">>;
|
|
29
|
+
readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
|
|
30
|
+
}>, Schema.Struct<{
|
|
31
|
+
readonly type: Schema.Literal<"file">;
|
|
32
|
+
readonly mediaType: Schema.String;
|
|
33
|
+
readonly fileName: Schema.optional<Schema.String>;
|
|
34
|
+
readonly data: Schema.Union<readonly [Schema.String, Schema.Uint8Array, Schema.URL]>;
|
|
35
|
+
readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Part">>;
|
|
36
|
+
readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
|
|
37
|
+
}>]>>]>;
|
|
38
|
+
readonly "~effect/ai/Prompt/Message": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Message">>;
|
|
39
|
+
readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
|
|
40
|
+
}>;
|
|
41
|
+
readonly policyId: Schema.brand<Schema.NonEmptyString, "CompactionPolicyId">;
|
|
42
|
+
readonly executorId: Schema.optionalKey<Schema.brand<Schema.NonEmptyString, "CompactionExecutorId">>;
|
|
43
|
+
}>;
|
|
44
|
+
type CompactionSummaryArtifact = typeof CompactionSummaryArtifact.Type;
|
|
45
|
+
/** Current durable context cursor projected from framework reducer state and summary rows. */
|
|
46
|
+
declare const ContextProjection: Schema.Struct<{
|
|
47
|
+
readonly contextVersion: Schema.brand<Schema.Int, "ContextVersion">;
|
|
48
|
+
readonly currentSummary: Schema.optionalKey<Schema.Struct<{
|
|
49
|
+
readonly compactionId: Schema.brand<Schema.String, "CompactionId">;
|
|
50
|
+
readonly summaryId: Schema.brand<Schema.String, "SummaryId">;
|
|
51
|
+
readonly previousSummaryId: Schema.optionalKey<Schema.brand<Schema.String, "SummaryId">>;
|
|
52
|
+
readonly sourceFromSeq: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
53
|
+
readonly sourceToSeq: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
54
|
+
readonly retainedFromContextSeq: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
55
|
+
readonly text: Schema.NonEmptyString;
|
|
56
|
+
readonly promptMessage: Schema.Struct<{
|
|
57
|
+
readonly role: Schema.Literal<"user">;
|
|
58
|
+
readonly content: Schema.Union<readonly [Schema.decodeTo<Schema.NonEmptyArray<Schema.toType<Schema.Struct<{
|
|
59
|
+
readonly type: Schema.Literal<"text">;
|
|
60
|
+
readonly text: Schema.String;
|
|
61
|
+
readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Part">>;
|
|
62
|
+
readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
|
|
63
|
+
}>>>, Schema.String, never, never>, Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
64
|
+
readonly type: Schema.Literal<"text">;
|
|
65
|
+
readonly text: Schema.String;
|
|
66
|
+
readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Part">>;
|
|
67
|
+
readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
|
|
68
|
+
}>, Schema.Struct<{
|
|
69
|
+
readonly type: Schema.Literal<"file">;
|
|
70
|
+
readonly mediaType: Schema.String;
|
|
71
|
+
readonly fileName: Schema.optional<Schema.String>;
|
|
72
|
+
readonly data: Schema.Union<readonly [Schema.String, Schema.Uint8Array, Schema.URL]>;
|
|
73
|
+
readonly "~effect/ai/Prompt/Part": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Part">>;
|
|
74
|
+
readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
|
|
75
|
+
}>]>>]>;
|
|
76
|
+
readonly "~effect/ai/Prompt/Message": Schema.withDecodingDefaultKey<Schema.Literal<"~effect/ai/Prompt/Message">>;
|
|
77
|
+
readonly options: Schema.withDecodingDefault<Schema.$Record<Schema.String, Schema.NullOr<Schema.Codec<Schema.Json>>>>;
|
|
78
|
+
}>;
|
|
79
|
+
readonly policyId: Schema.brand<Schema.NonEmptyString, "CompactionPolicyId">;
|
|
80
|
+
readonly executorId: Schema.optionalKey<Schema.brand<Schema.NonEmptyString, "CompactionExecutorId">>;
|
|
81
|
+
}>>;
|
|
82
|
+
}>;
|
|
83
|
+
type ContextProjection = typeof ContextProjection.Type;
|
|
84
|
+
/** Genesis context before any compaction has rebased prompt history. */
|
|
85
|
+
declare const emptyContextProjection: {
|
|
86
|
+
readonly contextVersion: number & import("effect/Brand").Brand<"ContextVersion">;
|
|
87
|
+
readonly currentSummary?: {
|
|
88
|
+
readonly compactionId: string & import("effect/Brand").Brand<"CompactionId">;
|
|
89
|
+
readonly summaryId: string & import("effect/Brand").Brand<"SummaryId">;
|
|
90
|
+
readonly previousSummaryId?: (string & import("effect/Brand").Brand<"SummaryId">) | undefined;
|
|
91
|
+
readonly sourceFromSeq: number & import("effect/Brand").Brand<"SequenceNumber">;
|
|
92
|
+
readonly sourceToSeq: number & import("effect/Brand").Brand<"SequenceNumber">;
|
|
93
|
+
readonly retainedFromContextSeq: number & import("effect/Brand").Brand<"SequenceNumber">;
|
|
94
|
+
readonly text: string;
|
|
95
|
+
readonly promptMessage: {
|
|
96
|
+
readonly role: "user";
|
|
97
|
+
readonly content: readonly ({
|
|
98
|
+
readonly type: "text";
|
|
99
|
+
readonly text: string;
|
|
100
|
+
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
|
|
101
|
+
readonly options: {
|
|
102
|
+
readonly [x: string]: Schema.Json;
|
|
103
|
+
};
|
|
104
|
+
} | {
|
|
105
|
+
readonly type: "file";
|
|
106
|
+
readonly mediaType: string;
|
|
107
|
+
readonly fileName?: string | undefined;
|
|
108
|
+
readonly data: string | URL | Uint8Array<ArrayBufferLike>;
|
|
109
|
+
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
|
|
110
|
+
readonly options: {
|
|
111
|
+
readonly [x: string]: Schema.Json;
|
|
112
|
+
};
|
|
113
|
+
})[] | readonly [{
|
|
114
|
+
readonly type: "text";
|
|
115
|
+
readonly text: string;
|
|
116
|
+
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
|
|
117
|
+
readonly options: {
|
|
118
|
+
readonly [x: string]: Schema.Json;
|
|
119
|
+
};
|
|
120
|
+
}, ...{
|
|
121
|
+
readonly type: "text";
|
|
122
|
+
readonly text: string;
|
|
123
|
+
readonly "~effect/ai/Prompt/Part": "~effect/ai/Prompt/Part";
|
|
124
|
+
readonly options: {
|
|
125
|
+
readonly [x: string]: Schema.Json;
|
|
126
|
+
};
|
|
127
|
+
}[]];
|
|
128
|
+
readonly "~effect/ai/Prompt/Message": "~effect/ai/Prompt/Message";
|
|
129
|
+
readonly options: {
|
|
130
|
+
readonly [x: string]: Schema.Json;
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
readonly policyId: string & import("effect/Brand").Brand<"CompactionPolicyId">;
|
|
134
|
+
readonly executorId?: (string & import("effect/Brand").Brand<"CompactionExecutorId">) | undefined;
|
|
135
|
+
} | undefined;
|
|
136
|
+
};
|
|
137
|
+
//#endregion
|
|
138
|
+
export { emptyContextProjection as a, ContextProjection as i, CompactionPolicyId as n, CompactionSummaryArtifact as r, CompactionExecutorId as t };
|
|
139
|
+
//# sourceMappingURL=context-projection-D_uRtK3r.d.ts.map
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import * as Schema from "effect/Schema";
|
|
2
2
|
import * as Order from "effect/Order";
|
|
3
|
-
|
|
4
3
|
//#region src/types/core.d.ts
|
|
5
|
-
/** Durable conversation identity; one
|
|
4
|
+
/** Durable conversation identity; one host isolation unit stores one session.
|
|
6
5
|
*
|
|
7
6
|
* New EDA sessions are minted as UUIDv7. Migrated sessions may retain UUIDv4
|
|
8
7
|
* identities, so runtime identity accepts any RFC UUID without changing app
|
|
@@ -19,6 +18,9 @@ type CommandId = typeof CommandId.Type;
|
|
|
19
18
|
/** Processing lifecycle identity triggered by one or more commands. */
|
|
20
19
|
declare const RunId: Schema.brand<Schema.String, "RunId">;
|
|
21
20
|
type RunId = typeof RunId.Type;
|
|
21
|
+
/** Stable deduplication identity for one durable request to authorize a new run. */
|
|
22
|
+
declare const RunRequestId: Schema.brand<Schema.String, "RunRequestId">;
|
|
23
|
+
type RunRequestId = typeof RunRequestId.Type;
|
|
22
24
|
/** One LLM invocation within a run. */
|
|
23
25
|
declare const TurnId: Schema.brand<Schema.String, "TurnId">;
|
|
24
26
|
type TurnId = typeof TurnId.Type;
|
|
@@ -77,5 +79,5 @@ declare const comparePosition: Order.Order<{
|
|
|
77
79
|
readonly subSeq: number & import("effect/Brand").Brand<"SubSequenceNumber">;
|
|
78
80
|
}>;
|
|
79
81
|
//#endregion
|
|
80
|
-
export {
|
|
81
|
-
//# sourceMappingURL=core-
|
|
82
|
+
export { durablePosition as S, SubSequenceNumber as _, CorrelationId as a, TurnId as b, EventId as c, Position as d, PositionOrder as f, SessionId as g, SequenceNumber as h, ContextVersion as i, InferenceId as l, RunRequestId as m, CommandId as n, DurablePosition as o, RunId as p, CompactionId as r, DurableSubSequenceNumber as s, BaseStateId as t, MessageId as u, SummaryId as v, comparePosition as x, ToolCallId as y };
|
|
83
|
+
//# sourceMappingURL=core-BcimKMIv.d.ts.map
|
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
import { Position, SequenceNumber } from "./types/core.js";
|
|
2
|
+
import { d as PositionedEvent, g as UnixEpochMillis, i as EventEnvelope } from "./envelope-BCzKUq_z.js";
|
|
3
|
+
import { U as EDADurableEvent } from "./durable-D13w1Qr3.js";
|
|
4
|
+
import { EDAEphemeralEvent } from "./types/events.js";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Schema from "effect/Schema";
|
|
7
|
+
//#region src/websocket/protocol.ts
|
|
8
|
+
const PositiveInt = Schema.Int.check(Schema.isGreaterThan(0));
|
|
9
|
+
const NonNegativeInt = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));
|
|
10
|
+
/** Current EDA live-event WebSocket wire protocol version. */
|
|
11
|
+
const EDA_WEB_SOCKET_WIRE_PROTOCOL_VERSION = 1;
|
|
12
|
+
/** Flow-control policy announced by the server in the hello frame. */
|
|
13
|
+
const EDAWebSocketWireFlowControl = Schema.Struct({
|
|
14
|
+
ackTimeoutMs: PositiveInt,
|
|
15
|
+
/** Deprecated: servers no longer send heartbeat frames. Kept so deployed clients can decode hello. */
|
|
16
|
+
heartbeatIntervalMs: PositiveInt,
|
|
17
|
+
maxFrameBytes: PositiveInt,
|
|
18
|
+
maxFrameEvents: PositiveInt,
|
|
19
|
+
maxInFlightFrames: PositiveInt,
|
|
20
|
+
/** Suggested client-originated ping cadence; absent on servers that still send heartbeats. */
|
|
21
|
+
pingIntervalMs: Schema.optionalKey(PositiveInt),
|
|
22
|
+
subscriberBufferCapacityEvents: PositiveInt
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* Canonical client liveness ping message.
|
|
26
|
+
*
|
|
27
|
+
* The exact string matters: hibernation-capable hosts register it with
|
|
28
|
+
* WebSocket auto-response so the runtime answers without waking the object.
|
|
29
|
+
*/
|
|
30
|
+
const EDA_WEB_SOCKET_PING_MESSAGE = "{\"_tag\":\"ping\"}";
|
|
31
|
+
/** Canonical server pong message paired with {@link EDA_WEB_SOCKET_PING_MESSAGE}. */
|
|
32
|
+
const EDA_WEB_SOCKET_PONG_MESSAGE = "{\"_tag\":\"pong\"}";
|
|
33
|
+
/** Client liveness ping; hosts answer with a pong and never ACK-track it. */
|
|
34
|
+
const EDAWebSocketWirePingFrame = Schema.Struct({ _tag: Schema.Literal("ping") });
|
|
35
|
+
/** Server liveness pong; clients may ignore it and must not ACK it. */
|
|
36
|
+
const EDAWebSocketWirePongFrame = Schema.Struct({ _tag: Schema.Literal("pong") });
|
|
37
|
+
const EDAWebSocketWireHelloFrame = Schema.Struct({
|
|
38
|
+
_tag: Schema.Literal("hello"),
|
|
39
|
+
protocolVersion: Schema.Literal(1),
|
|
40
|
+
subscriberId: Schema.NonEmptyString,
|
|
41
|
+
resumeSeq: NonNegativeInt,
|
|
42
|
+
flowControl: EDAWebSocketWireFlowControl
|
|
43
|
+
});
|
|
44
|
+
const EDAWebSocketWireHeartbeatFrame = Schema.Struct({
|
|
45
|
+
_tag: Schema.Literal("heartbeat"),
|
|
46
|
+
serverTimeMs: NonNegativeInt,
|
|
47
|
+
durableThroughSeq: NonNegativeInt
|
|
48
|
+
});
|
|
49
|
+
const EDAWebSocketWireLaggedFrame = Schema.Struct({
|
|
50
|
+
_tag: Schema.Literal("lagged"),
|
|
51
|
+
resumeSeq: NonNegativeInt,
|
|
52
|
+
reason: Schema.Literals(["buffer-overflow", "ack-timeout"])
|
|
53
|
+
});
|
|
54
|
+
const EDAWebSocketWireErrorFrame = Schema.Struct({
|
|
55
|
+
_tag: Schema.Literal("error"),
|
|
56
|
+
message: Schema.String
|
|
57
|
+
});
|
|
58
|
+
/**
|
|
59
|
+
* Client acknowledgement. `frameId` is the transport receipt: it cumulatively frees flow-control
|
|
60
|
+
* capacity. On a transcript socket `appliedUpdateSeq` is the client's applied cut, the last
|
|
61
|
+
* transcript update it applied completely, and `durableThroughSeq` is that update's
|
|
62
|
+
* `throughSeq`; both advance only on complete updates, never on a partial chunked transfer.
|
|
63
|
+
* Raw event sockets ignore `appliedUpdateSeq`.
|
|
64
|
+
*/
|
|
65
|
+
const EDAWebSocketWireAckFrame = Schema.Struct({
|
|
66
|
+
_tag: Schema.Literal("ack"),
|
|
67
|
+
frameId: PositiveInt,
|
|
68
|
+
durableThroughSeq: NonNegativeInt,
|
|
69
|
+
appliedUpdateSeq: Schema.optionalKey(NonNegativeInt)
|
|
70
|
+
});
|
|
71
|
+
const EDAWebSocketWireClientFrame = Schema.Union([EDAWebSocketWireAckFrame, EDAWebSocketWirePingFrame]);
|
|
72
|
+
/** Complete framework-owned event union present on every EDA WebSocket. */
|
|
73
|
+
const EDAFrameworkWebSocketEvent = Schema.Union([EDADurableEvent, EDAEphemeralEvent]);
|
|
74
|
+
const makeEDAWebSocketDomainSchemas = (event) => {
|
|
75
|
+
const positionedEvent = Schema.Struct({
|
|
76
|
+
position: Position,
|
|
77
|
+
event
|
|
78
|
+
});
|
|
79
|
+
const eventsFrame = Schema.Struct({
|
|
80
|
+
_tag: Schema.Literal("events"),
|
|
81
|
+
frameId: PositiveInt,
|
|
82
|
+
events: Schema.NonEmptyArray(positionedEvent),
|
|
83
|
+
durableThroughSeq: NonNegativeInt
|
|
84
|
+
});
|
|
85
|
+
return {
|
|
86
|
+
event,
|
|
87
|
+
positionedEvent,
|
|
88
|
+
eventsFrame,
|
|
89
|
+
serverFrame: Schema.Union([
|
|
90
|
+
EDAWebSocketWireHelloFrame,
|
|
91
|
+
eventsFrame,
|
|
92
|
+
EDAWebSocketWireHeartbeatFrame,
|
|
93
|
+
EDAWebSocketWirePongFrame,
|
|
94
|
+
EDAWebSocketWireLaggedFrame,
|
|
95
|
+
EDAWebSocketWireErrorFrame
|
|
96
|
+
])
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
makeEDAWebSocketDomainSchemas(EventEnvelope);
|
|
100
|
+
const makeEDAWebSocketWireProtocolFromEventSchema = (event) => {
|
|
101
|
+
const domain = makeEDAWebSocketDomainSchemas(event);
|
|
102
|
+
const encodeDomainServerFrame = Schema.encodeSync(domain.serverFrame);
|
|
103
|
+
const encodeUnknownDomainServerFrame = Schema.encodeUnknownSync(domain.serverFrame);
|
|
104
|
+
const encodeServerFrame = (frame) => JSON.stringify(encodeDomainServerFrame(frame));
|
|
105
|
+
return {
|
|
106
|
+
domain,
|
|
107
|
+
wire: {
|
|
108
|
+
event: Schema.toEncoded(domain.event),
|
|
109
|
+
positionedEvent: Schema.toEncoded(domain.positionedEvent),
|
|
110
|
+
eventsFrame: Schema.toEncoded(domain.eventsFrame),
|
|
111
|
+
serverFrame: Schema.toEncoded(domain.serverFrame),
|
|
112
|
+
clientFrame: EDAWebSocketWireClientFrame
|
|
113
|
+
},
|
|
114
|
+
encodeServerFrame,
|
|
115
|
+
host: { encodeServerFrame: (frame) => JSON.stringify(encodeUnknownDomainServerFrame(frame)) }
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
/** Strict framework-only protocol used when an app registers no custom events. */
|
|
119
|
+
const edaFrameworkWebSocketWireProtocol = makeEDAWebSocketWireProtocolFromEventSchema(EDAFrameworkWebSocketEvent);
|
|
120
|
+
/**
|
|
121
|
+
* Bind the generic EDA WebSocket transport to one app's custom event schema.
|
|
122
|
+
*
|
|
123
|
+
* Framework durable and ephemeral events are included automatically. Future EDA
|
|
124
|
+
* apps register only their custom events. Servers use the returned domain schemas
|
|
125
|
+
* and typed encoder; external consumers decode with the wire schemas. Pass the
|
|
126
|
+
* returned `host` adapter to the selected host package.
|
|
127
|
+
*/
|
|
128
|
+
const makeEDAWebSocketWireProtocol = (options) => makeEDAWebSocketWireProtocolFromEventSchema(Schema.Union([EDAFrameworkWebSocketEvent, options.appEvents]));
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region src/websocket/messages.ts
|
|
131
|
+
/** Current EDA live-event WebSocket protocol version. */
|
|
132
|
+
const EDA_WEB_SOCKET_PROTOCOL_VERSION = 1;
|
|
133
|
+
/** WebSocket close code used when a subscriber cannot keep up with live delivery. */
|
|
134
|
+
const EDA_WS_CLOSE_LAGGED = 4008;
|
|
135
|
+
/** WebSocket close code used for normal host-driven shutdown. */
|
|
136
|
+
const EDA_WS_CLOSE_GOING_AWAY = 1001;
|
|
137
|
+
/** WebSocket close code used for malformed client protocol messages. */
|
|
138
|
+
const EDA_WS_CLOSE_PROTOCOL_ERROR = 1002;
|
|
139
|
+
/** WebSocket close code used when the host cannot send a frame. */
|
|
140
|
+
const EDA_WS_CLOSE_SEND_FAILED = 1011;
|
|
141
|
+
/** WebSocket close code used for unsupported binary messages. */
|
|
142
|
+
const EDA_WS_CLOSE_UNSUPPORTED_DATA = 1003;
|
|
143
|
+
/** Live subscriber identity persisted in WebSocket attachments. */
|
|
144
|
+
const SubscriberId = Schema.NonEmptyString.pipe(Schema.brand("SubscriberId"));
|
|
145
|
+
/** Per-connection monotonically increasing server frame id. */
|
|
146
|
+
const FrameId = Schema.Int.check(Schema.isGreaterThanOrEqualTo(1)).pipe(Schema.brand("FrameId"));
|
|
147
|
+
/** Flow-control policy announced by the server in the hello frame. */
|
|
148
|
+
const EDAWebSocketFlowControl = EDAWebSocketWireFlowControl;
|
|
149
|
+
/** Default bounded policy sized for fast model deltas and large durable tool/message events. */
|
|
150
|
+
const defaultEDAWebSocketFlowControl = {
|
|
151
|
+
ackTimeoutMs: 3e4,
|
|
152
|
+
heartbeatIntervalMs: 1e4,
|
|
153
|
+
maxFrameBytes: 262144,
|
|
154
|
+
maxFrameEvents: 1,
|
|
155
|
+
maxInFlightFrames: 16,
|
|
156
|
+
pingIntervalMs: 3e4,
|
|
157
|
+
subscriberBufferCapacityEvents: 2048
|
|
158
|
+
};
|
|
159
|
+
/** First server frame; announces protocol and flow-control policy. */
|
|
160
|
+
const EDAWebSocketHelloFrame = Schema.Struct({
|
|
161
|
+
...EDAWebSocketWireHelloFrame.fields,
|
|
162
|
+
subscriberId: SubscriberId,
|
|
163
|
+
resumeSeq: SequenceNumber
|
|
164
|
+
});
|
|
165
|
+
/** Ordered positioned events delivered to the client. */
|
|
166
|
+
const EDAWebSocketEventsFrame = Schema.Struct({
|
|
167
|
+
_tag: Schema.Literal("events"),
|
|
168
|
+
frameId: FrameId,
|
|
169
|
+
events: Schema.NonEmptyArray(PositionedEvent),
|
|
170
|
+
durableThroughSeq: SequenceNumber
|
|
171
|
+
});
|
|
172
|
+
/**
|
|
173
|
+
* Deprecated idle server keepalive frame.
|
|
174
|
+
*
|
|
175
|
+
* Servers no longer send heartbeats; the schema remains so deployed clients
|
|
176
|
+
* keep decoding the server frame union. Liveness is client-originated via
|
|
177
|
+
* {@link EDAWebSocketPingFrame} and the host-level auto-response pong.
|
|
178
|
+
*/
|
|
179
|
+
const EDAWebSocketHeartbeatFrame = Schema.Struct({
|
|
180
|
+
...EDAWebSocketWireHeartbeatFrame.fields,
|
|
181
|
+
serverTimeMs: UnixEpochMillis,
|
|
182
|
+
durableThroughSeq: SequenceNumber
|
|
183
|
+
});
|
|
184
|
+
/** Client liveness ping; hosts answer with a pong and never ACK-track it. */
|
|
185
|
+
const EDAWebSocketPingFrame = EDAWebSocketWirePingFrame;
|
|
186
|
+
/** Server liveness pong; clients may ignore it and must not ACK it. */
|
|
187
|
+
const EDAWebSocketPongFrame = EDAWebSocketWirePongFrame;
|
|
188
|
+
/** Optional final frame sent before a lag-close. */
|
|
189
|
+
const EDAWebSocketLaggedFrame = Schema.Struct({
|
|
190
|
+
...EDAWebSocketWireLaggedFrame.fields,
|
|
191
|
+
resumeSeq: SequenceNumber
|
|
192
|
+
});
|
|
193
|
+
/** Optional final frame sent before a protocol/internal close. */
|
|
194
|
+
const EDAWebSocketErrorFrame = EDAWebSocketWireErrorFrame;
|
|
195
|
+
/** Server-to-client application frame union. */
|
|
196
|
+
const EDAWebSocketServerFrame = Schema.Union([
|
|
197
|
+
EDAWebSocketHelloFrame,
|
|
198
|
+
EDAWebSocketEventsFrame,
|
|
199
|
+
EDAWebSocketHeartbeatFrame,
|
|
200
|
+
EDAWebSocketPongFrame,
|
|
201
|
+
EDAWebSocketLaggedFrame,
|
|
202
|
+
EDAWebSocketErrorFrame
|
|
203
|
+
]);
|
|
204
|
+
/** Client acknowledgement after applying a server frame. */
|
|
205
|
+
const EDAWebSocketAckFrame = Schema.Struct({
|
|
206
|
+
...EDAWebSocketWireAckFrame.fields,
|
|
207
|
+
frameId: FrameId,
|
|
208
|
+
durableThroughSeq: SequenceNumber
|
|
209
|
+
});
|
|
210
|
+
/** Client-to-server application frame union. */
|
|
211
|
+
const EDAWebSocketClientFrame = Schema.Union([EDAWebSocketAckFrame, EDAWebSocketPingFrame]);
|
|
212
|
+
/** Serialize a server frame for a text WebSocket message. */
|
|
213
|
+
const encodeEDAWebSocketServerFrame = (frame, protocol) => (protocol ?? edaFrameworkWebSocketWireProtocol.host).encodeServerFrame(frame);
|
|
214
|
+
/** Decode an inbound text WebSocket message at the host boundary. */
|
|
215
|
+
const decodeEDAWebSocketClientMessage = (input) => Effect.try({
|
|
216
|
+
try: () => JSON.parse(input),
|
|
217
|
+
catch: (error) => error
|
|
218
|
+
}).pipe(Effect.flatMap((json) => Schema.decodeUnknownEffect(EDAWebSocketWireClientFrame)(json)), Effect.flatMap((frame) => Schema.decodeUnknownEffect(EDAWebSocketClientFrame)(frame)));
|
|
219
|
+
/** Short close reason that fits the WebSocket protocol reason limit. */
|
|
220
|
+
const laggedCloseReason = (seq) => `lag;seq=${seq}`;
|
|
221
|
+
//#endregion
|
|
222
|
+
//#region src/websocket/delivery.ts
|
|
223
|
+
/** Slow subscriber reasons that intentionally close only the lagging socket. */
|
|
224
|
+
const SubscriberLagReason = Schema.Literals(["buffer-overflow", "ack-timeout"]);
|
|
225
|
+
/** One sent-but-unacknowledged events frame. */
|
|
226
|
+
const EDAWebSocketInFlightFrame = Schema.Struct({
|
|
227
|
+
frameId: FrameId,
|
|
228
|
+
durableThroughSeq: SequenceNumber,
|
|
229
|
+
sentAtMs: Schema.Number
|
|
230
|
+
});
|
|
231
|
+
/** Compact consecutive host-suppressed receipts blocked by a visible ACK. */
|
|
232
|
+
const EDAWebSocketSuppressedRange = Schema.Struct({
|
|
233
|
+
fromFrameId: FrameId,
|
|
234
|
+
throughFrameId: FrameId,
|
|
235
|
+
durableThroughSeq: SequenceNumber
|
|
236
|
+
});
|
|
237
|
+
/** Complete delivery bookkeeping persisted in the WebSocket attachment. */
|
|
238
|
+
const EDAWebSocketDeliveryCheckpoint = Schema.Struct({
|
|
239
|
+
lastAckedSeq: SequenceNumber,
|
|
240
|
+
lastAckedFrameId: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
241
|
+
lastSentFrameId: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
242
|
+
nextFrameId: Schema.Int.check(Schema.isGreaterThanOrEqualTo(1)),
|
|
243
|
+
sentDurableThroughSeq: SequenceNumber,
|
|
244
|
+
inFlight: Schema.Array(EDAWebSocketInFlightFrame),
|
|
245
|
+
/** Host-projected receipts waiting behind an earlier client-visible ACK. */
|
|
246
|
+
suppressed: Schema.optionalKey(Schema.Array(EDAWebSocketSuppressedRange))
|
|
247
|
+
});
|
|
248
|
+
/** Build delivery state for a newly accepted connection. */
|
|
249
|
+
const makeWebSocketDeliveryState = (input) => ({
|
|
250
|
+
subscriberId: input.subscriberId,
|
|
251
|
+
policy: input.policy,
|
|
252
|
+
lastAckedSeq: input.resumeSeq,
|
|
253
|
+
lastAckedFrameId: 0,
|
|
254
|
+
lastSentFrameId: 0,
|
|
255
|
+
nextFrameId: 1,
|
|
256
|
+
sentDurableThroughSeq: input.resumeSeq,
|
|
257
|
+
inFlight: [],
|
|
258
|
+
suppressed: [],
|
|
259
|
+
pendingEphemeral: []
|
|
260
|
+
});
|
|
261
|
+
/** Rebuild exact ACK bookkeeping from a hibernating WebSocket attachment. */
|
|
262
|
+
const restoreWebSocketDeliveryState = (input) => ({
|
|
263
|
+
subscriberId: input.subscriberId,
|
|
264
|
+
policy: input.policy,
|
|
265
|
+
...input.checkpoint,
|
|
266
|
+
pendingEphemeral: [],
|
|
267
|
+
suppressed: input.checkpoint.suppressed ?? []
|
|
268
|
+
});
|
|
269
|
+
/** Project in-memory delivery state into the attachment-safe checkpoint. */
|
|
270
|
+
const checkpointWebSocketDeliveryState = (state) => ({
|
|
271
|
+
lastAckedSeq: state.lastAckedSeq,
|
|
272
|
+
lastAckedFrameId: state.lastAckedFrameId,
|
|
273
|
+
lastSentFrameId: state.lastSentFrameId,
|
|
274
|
+
nextFrameId: state.nextFrameId,
|
|
275
|
+
sentDurableThroughSeq: state.sentDurableThroughSeq,
|
|
276
|
+
inFlight: state.inFlight,
|
|
277
|
+
...state.suppressed.length === 0 ? {} : { suppressed: state.suppressed }
|
|
278
|
+
});
|
|
279
|
+
/** First frame for a freshly accepted connection. Restores never re-send hello. */
|
|
280
|
+
const deliveryHelloFrame = (state) => EDAWebSocketHelloFrame.make({
|
|
281
|
+
_tag: "hello",
|
|
282
|
+
protocolVersion: EDA_WEB_SOCKET_PROTOCOL_VERSION,
|
|
283
|
+
subscriberId: state.subscriberId,
|
|
284
|
+
resumeSeq: state.lastAckedSeq,
|
|
285
|
+
flowControl: state.policy
|
|
286
|
+
});
|
|
287
|
+
/** Deliver committed durable events read from the store. */
|
|
288
|
+
const onDurableEvents = (state, events, head, nowMs) => {
|
|
289
|
+
const stale = staleAckResult(state, nowMs);
|
|
290
|
+
if (stale !== void 0) return stale;
|
|
291
|
+
let next = state;
|
|
292
|
+
const frames = [];
|
|
293
|
+
let batch = [];
|
|
294
|
+
const flushBatch = () => {
|
|
295
|
+
if (batch.length === 0) return;
|
|
296
|
+
const sent = sendEventsFrame(next, batch, nowMs);
|
|
297
|
+
next = sent.state;
|
|
298
|
+
frames.push(sent.frame);
|
|
299
|
+
batch = [];
|
|
300
|
+
};
|
|
301
|
+
for (const event of events) {
|
|
302
|
+
if (event.event.durability === "durable" && event.position.seq <= next.sentDurableThroughSeq) continue;
|
|
303
|
+
if (batch.length === 0 && windowCapacity(next) <= 0) break;
|
|
304
|
+
batch.push(event);
|
|
305
|
+
if (batch.length >= next.policy.maxFrameEvents) flushBatch();
|
|
306
|
+
}
|
|
307
|
+
flushBatch();
|
|
308
|
+
return sentResult(next, frames, windowCapacity(next) > 0 && next.sentDurableThroughSeq < head ? next.sentDurableThroughSeq : void 0);
|
|
309
|
+
};
|
|
310
|
+
/** Deliver one live ephemeral event, buffering only while this isolate is active. */
|
|
311
|
+
const onEphemeralEvent = (state, event, nowMs) => {
|
|
312
|
+
const stale = staleAckResult(state, nowMs);
|
|
313
|
+
if (stale !== void 0) return stale;
|
|
314
|
+
if (windowCapacity(state) > 0 && state.pendingEphemeral.length === 0) {
|
|
315
|
+
const sent = sendEventsFrame(state, [event], nowMs);
|
|
316
|
+
return sentResult(sent.state, [sent.frame]);
|
|
317
|
+
}
|
|
318
|
+
const pendingEphemeral = [...state.pendingEphemeral, event];
|
|
319
|
+
if (pendingEphemeral.length > state.policy.subscriberBufferCapacityEvents) return laggedResult(state, "buffer-overflow");
|
|
320
|
+
return {
|
|
321
|
+
state: {
|
|
322
|
+
...state,
|
|
323
|
+
pendingEphemeral
|
|
324
|
+
},
|
|
325
|
+
actions: []
|
|
326
|
+
};
|
|
327
|
+
};
|
|
328
|
+
/** Apply one client ACK, reopen the window, and drain buffered ephemeral events. */
|
|
329
|
+
const onClientAck = (state, ack, nowMs) => {
|
|
330
|
+
const validated = applyAck(state, ack);
|
|
331
|
+
if (validated._tag === "close") return validated.result;
|
|
332
|
+
if (validated._tag === "ignore") return {
|
|
333
|
+
state,
|
|
334
|
+
actions: []
|
|
335
|
+
};
|
|
336
|
+
return reopenDeliveryWindow(validated.state, nowMs);
|
|
337
|
+
};
|
|
338
|
+
/**
|
|
339
|
+
* Apply one exact host-suppressed receipt without cumulatively ACKing any
|
|
340
|
+
* earlier client-visible frame.
|
|
341
|
+
*/
|
|
342
|
+
const onHostSuppressedFrame = (state, frame, nowMs) => {
|
|
343
|
+
const receipt = state.inFlight.find((candidate) => candidate.frameId === frame.frameId);
|
|
344
|
+
if (receipt === void 0 || receipt.durableThroughSeq !== frame.durableThroughSeq) return protocolClose(state, "Host suppressed an unknown frame receipt").result;
|
|
345
|
+
const next = advanceSuppressedReceipts({
|
|
346
|
+
...state,
|
|
347
|
+
inFlight: state.inFlight.filter((candidate) => candidate.frameId !== frame.frameId),
|
|
348
|
+
suppressed: insertSuppressedReceipt(state.suppressed, receipt)
|
|
349
|
+
});
|
|
350
|
+
return reopenDeliveryWindow(next, nowMs);
|
|
351
|
+
};
|
|
352
|
+
const reopenDeliveryWindow = (state, nowMs) => {
|
|
353
|
+
let next = state;
|
|
354
|
+
const frames = [];
|
|
355
|
+
while (next.pendingEphemeral.length > 0 && windowCapacity(next) > 0) {
|
|
356
|
+
const [head, ...rest] = next.pendingEphemeral;
|
|
357
|
+
if (head === void 0) break;
|
|
358
|
+
const sent = sendEventsFrame({
|
|
359
|
+
...next,
|
|
360
|
+
pendingEphemeral: rest
|
|
361
|
+
}, [head], nowMs);
|
|
362
|
+
next = sent.state;
|
|
363
|
+
frames.push(sent.frame);
|
|
364
|
+
}
|
|
365
|
+
const stale = staleAckResult(next, nowMs);
|
|
366
|
+
if (stale !== void 0) return stale;
|
|
367
|
+
return sentResult(next, frames, windowCapacity(next) > 0 && next.pendingEphemeral.length === 0 ? next.sentDurableThroughSeq : void 0, true);
|
|
368
|
+
};
|
|
369
|
+
const applyAck = (state, ack) => {
|
|
370
|
+
if (ack.frameId <= state.lastAckedFrameId) return ack.durableThroughSeq > state.lastAckedSeq ? protocolClose(state, "Duplicate ACK attempted to advance durable seq") : { _tag: "ignore" };
|
|
371
|
+
if (ack.frameId > state.lastSentFrameId) return protocolClose(state, "ACK referenced an unsent frame");
|
|
372
|
+
if (ack.durableThroughSeq < state.lastAckedSeq) return protocolClose(state, "ACK durable seq moved backwards");
|
|
373
|
+
const acknowledgedVisible = state.inFlight.filter((frame) => frame.frameId <= ack.frameId);
|
|
374
|
+
if (acknowledgedVisible.length === 0) return protocolClose(state, "ACK referenced no in-flight frames");
|
|
375
|
+
if (state.suppressed.some((range) => range.fromFrameId <= ack.frameId && ack.frameId <= range.throughFrameId)) return protocolClose(state, "ACK referenced a host-suppressed frame");
|
|
376
|
+
const acknowledgedSuppressed = state.suppressed.filter((range) => range.throughFrameId <= ack.frameId);
|
|
377
|
+
const acknowledged = [...acknowledgedVisible, ...acknowledgedSuppressed];
|
|
378
|
+
const allowedDurableSeq = SequenceNumber.make(acknowledged.reduce((max, receipt) => Math.max(max, receipt.durableThroughSeq), state.lastAckedSeq));
|
|
379
|
+
if (ack.durableThroughSeq > allowedDurableSeq) return protocolClose(state, "ACK durable seq exceeded sent frame boundary");
|
|
380
|
+
return {
|
|
381
|
+
_tag: "apply",
|
|
382
|
+
state: advanceSuppressedReceipts({
|
|
383
|
+
...state,
|
|
384
|
+
inFlight: state.inFlight.filter((frame) => frame.frameId > ack.frameId),
|
|
385
|
+
lastAckedFrameId: ack.frameId,
|
|
386
|
+
lastAckedSeq: ack.durableThroughSeq,
|
|
387
|
+
suppressed: state.suppressed.filter((range) => range.throughFrameId > ack.frameId)
|
|
388
|
+
})
|
|
389
|
+
};
|
|
390
|
+
};
|
|
391
|
+
const advanceSuppressedReceipts = (state) => {
|
|
392
|
+
let lastAckedFrameId = state.lastAckedFrameId;
|
|
393
|
+
let lastAckedSeq = state.lastAckedSeq;
|
|
394
|
+
let consumed = 0;
|
|
395
|
+
for (const range of state.suppressed) {
|
|
396
|
+
if (range.fromFrameId !== lastAckedFrameId + 1) break;
|
|
397
|
+
lastAckedFrameId = range.throughFrameId;
|
|
398
|
+
lastAckedSeq = SequenceNumber.make(Math.max(lastAckedSeq, range.durableThroughSeq));
|
|
399
|
+
consumed += 1;
|
|
400
|
+
}
|
|
401
|
+
return consumed === 0 ? state : {
|
|
402
|
+
...state,
|
|
403
|
+
lastAckedFrameId,
|
|
404
|
+
lastAckedSeq,
|
|
405
|
+
suppressed: state.suppressed.slice(consumed)
|
|
406
|
+
};
|
|
407
|
+
};
|
|
408
|
+
const insertSuppressedReceipt = (ranges, receipt) => {
|
|
409
|
+
const inserted = [...ranges, EDAWebSocketSuppressedRange.make({
|
|
410
|
+
fromFrameId: receipt.frameId,
|
|
411
|
+
throughFrameId: receipt.frameId,
|
|
412
|
+
durableThroughSeq: receipt.durableThroughSeq
|
|
413
|
+
})].sort((left, right) => left.fromFrameId - right.fromFrameId);
|
|
414
|
+
const compacted = [];
|
|
415
|
+
for (const range of inserted) {
|
|
416
|
+
const previous = compacted.at(-1);
|
|
417
|
+
if (previous === void 0 || range.fromFrameId > previous.throughFrameId + 1) {
|
|
418
|
+
compacted.push(range);
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
compacted[compacted.length - 1] = EDAWebSocketSuppressedRange.make({
|
|
422
|
+
fromFrameId: previous.fromFrameId,
|
|
423
|
+
throughFrameId: FrameId.make(Math.max(previous.throughFrameId, range.throughFrameId)),
|
|
424
|
+
durableThroughSeq: SequenceNumber.make(Math.max(previous.durableThroughSeq, range.durableThroughSeq))
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
return compacted;
|
|
428
|
+
};
|
|
429
|
+
const windowCapacity = (state) => state.policy.maxInFlightFrames - state.inFlight.length;
|
|
430
|
+
const sendEventsFrame = (state, events, nowMs) => {
|
|
431
|
+
const [first, ...rest] = events;
|
|
432
|
+
if (first === void 0) throw new Error("Cannot send an empty events frame");
|
|
433
|
+
const frameId = FrameId.make(state.nextFrameId);
|
|
434
|
+
const durableThroughSeq = SequenceNumber.make(events.reduce((max, event) => event.event.durability === "durable" ? Math.max(max, event.position.seq) : max, state.sentDurableThroughSeq));
|
|
435
|
+
const frame = EDAWebSocketEventsFrame.make({
|
|
436
|
+
_tag: "events",
|
|
437
|
+
frameId,
|
|
438
|
+
events: [first, ...rest],
|
|
439
|
+
durableThroughSeq
|
|
440
|
+
});
|
|
441
|
+
return {
|
|
442
|
+
state: {
|
|
443
|
+
...state,
|
|
444
|
+
inFlight: [...state.inFlight, {
|
|
445
|
+
frameId,
|
|
446
|
+
durableThroughSeq,
|
|
447
|
+
sentAtMs: nowMs
|
|
448
|
+
}],
|
|
449
|
+
lastSentFrameId: frameId,
|
|
450
|
+
nextFrameId: frameId + 1,
|
|
451
|
+
sentDurableThroughSeq: durableThroughSeq
|
|
452
|
+
},
|
|
453
|
+
frame
|
|
454
|
+
};
|
|
455
|
+
};
|
|
456
|
+
const sentResult = (state, frames, catchUpAfterSeq, stateChanged = frames.length > 0) => ({
|
|
457
|
+
state,
|
|
458
|
+
actions: [
|
|
459
|
+
...stateChanged ? [{ _tag: "Persist" }] : [],
|
|
460
|
+
...frames.length > 0 ? [{
|
|
461
|
+
_tag: "Send",
|
|
462
|
+
frames
|
|
463
|
+
}] : [],
|
|
464
|
+
...catchUpAfterSeq === void 0 ? [] : [{
|
|
465
|
+
_tag: "ReadEventPage",
|
|
466
|
+
afterSeq: catchUpAfterSeq
|
|
467
|
+
}]
|
|
468
|
+
]
|
|
469
|
+
});
|
|
470
|
+
/** Lazily enforce the ACK deadline: no resident timer, checked on each transition. */
|
|
471
|
+
const staleAckResult = (state, nowMs) => state.inFlight.some((frame) => frame.sentAtMs + state.policy.ackTimeoutMs <= nowMs) ? laggedResult(state, "ack-timeout") : void 0;
|
|
472
|
+
const laggedResult = (state, reason) => ({
|
|
473
|
+
state,
|
|
474
|
+
actions: [{
|
|
475
|
+
_tag: "Send",
|
|
476
|
+
frames: [EDAWebSocketLaggedFrame.make({
|
|
477
|
+
_tag: "lagged",
|
|
478
|
+
resumeSeq: state.lastAckedSeq,
|
|
479
|
+
reason
|
|
480
|
+
})]
|
|
481
|
+
}, {
|
|
482
|
+
_tag: "Close",
|
|
483
|
+
code: EDA_WS_CLOSE_LAGGED,
|
|
484
|
+
reason: laggedCloseReason(state.lastAckedSeq)
|
|
485
|
+
}]
|
|
486
|
+
});
|
|
487
|
+
const protocolClose = (state, message) => ({
|
|
488
|
+
_tag: "close",
|
|
489
|
+
result: {
|
|
490
|
+
state,
|
|
491
|
+
actions: [{
|
|
492
|
+
_tag: "Send",
|
|
493
|
+
frames: [EDAWebSocketErrorFrame.make({
|
|
494
|
+
_tag: "error",
|
|
495
|
+
message: message.slice(0, 120)
|
|
496
|
+
})]
|
|
497
|
+
}, {
|
|
498
|
+
_tag: "Close",
|
|
499
|
+
code: EDA_WS_CLOSE_PROTOCOL_ERROR,
|
|
500
|
+
reason: "protocol"
|
|
501
|
+
}]
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
//#endregion
|
|
505
|
+
export { FrameId as A, EDAWebSocketWireFlowControl as B, EDAWebSocketServerFrame as C, EDA_WS_CLOSE_PROTOCOL_ERROR as D, EDA_WS_CLOSE_LAGGED as E, laggedCloseReason as F, EDAWebSocketWirePongFrame as G, EDAWebSocketWireHelloFrame as H, EDAFrameworkWebSocketEvent as I, EDA_WEB_SOCKET_WIRE_PROTOCOL_VERSION as J, EDA_WEB_SOCKET_PING_MESSAGE as K, EDAWebSocketWireAckFrame as L, decodeEDAWebSocketClientMessage as M, defaultEDAWebSocketFlowControl as N, EDA_WS_CLOSE_SEND_FAILED as O, encodeEDAWebSocketServerFrame as P, EDAWebSocketWireClientFrame as R, EDAWebSocketPongFrame as S, EDA_WS_CLOSE_GOING_AWAY as T, EDAWebSocketWireLaggedFrame as U, EDAWebSocketWireHeartbeatFrame as V, EDAWebSocketWirePingFrame as W, makeEDAWebSocketWireProtocol as X, edaFrameworkWebSocketWireProtocol as Y, EDAWebSocketFlowControl as _, checkpointWebSocketDeliveryState as a, EDAWebSocketLaggedFrame as b, onClientAck as c, onHostSuppressedFrame as d, restoreWebSocketDeliveryState as f, EDAWebSocketEventsFrame as g, EDAWebSocketErrorFrame as h, SubscriberLagReason as i, SubscriberId as j, EDA_WS_CLOSE_UNSUPPORTED_DATA as k, onDurableEvents as l, EDAWebSocketClientFrame as m, EDAWebSocketInFlightFrame as n, deliveryHelloFrame as o, EDAWebSocketAckFrame as p, EDA_WEB_SOCKET_PONG_MESSAGE as q, EDAWebSocketSuppressedRange as r, makeWebSocketDeliveryState as s, EDAWebSocketDeliveryCheckpoint as t, onEphemeralEvent as u, EDAWebSocketHeartbeatFrame as v, EDA_WEB_SOCKET_PROTOCOL_VERSION as w, EDAWebSocketPingFrame as x, EDAWebSocketHelloFrame as y, EDAWebSocketWireErrorFrame as z };
|
|
506
|
+
|
|
507
|
+
//# sourceMappingURL=delivery-2ZILvoRD.js.map
|