effect-durable-agent 0.1.0-alpha.1 → 0.1.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -1
- package/README.md +131 -128
- package/SECURITY.md +3 -4
- package/dist/{command-queues-CQ9cwRP7.d.ts → command-queues-CV7O-51r.d.ts} +7 -6
- package/dist/{compaction-YayFKo_1.d.ts → compaction-zbvLREI8.d.ts} +8 -6
- package/dist/context-projection-n6Rdup0N.d.ts +140 -0
- package/dist/{core-Hv3cFydL.d.ts → core-CYT6DBaS.d.ts} +2 -2
- package/dist/domain/command-queues.d.ts +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 +1 -1
- package/dist/domain/reduced-state-schema.d.ts +2 -0
- package/dist/domain/reduced-state-schema.js +2 -1
- package/dist/domain/reduced-state-schema.js.map +1 -1
- package/dist/domain/reduced-state.d.ts +1 -1
- package/dist/domain/reduced-state.js +1 -1
- package/dist/{durable-DlScwmCy.d.ts → durable-B7M6TD_0.d.ts} +341 -2
- package/dist/{durable-C3Rz7kg3.js → durable-DsV9PxZC.js} +13 -2
- package/dist/durable-DsV9PxZC.js.map +1 -0
- package/dist/{keep-alive-DYDsH6qN.d.ts → event-factory-CLJcyymV.d.ts} +5 -29
- package/dist/{keep-alive-p8dIcSVy.js → event-factory-tcpLgdMN.js} +3 -10
- package/dist/event-factory-tcpLgdMN.js.map +1 -0
- package/dist/host/websocket-protocol.d.ts +229 -0
- package/dist/host/websocket-protocol.js +99 -0
- package/dist/host/websocket-protocol.js.map +1 -0
- package/dist/host/websocket-wire.d.ts +2 -2
- package/dist/host/websocket-wire.js +37 -20
- package/dist/host/websocket-wire.js.map +1 -1
- package/dist/{id-generator-C2Q15uZM.d.ts → id-generator-Ckl8_XWW.d.ts} +2 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/keep-alive-Chl5SJxy.d.ts +29 -0
- package/dist/{message-transcript-BCHdHAe2.d.ts → message-transcript-DiOPBY3l.d.ts} +3 -3
- package/dist/{prompt-projector-9_02lk5-.d.ts → prompt-projector-C1IbkHr0.d.ts} +15 -16
- package/dist/{reduced-state-C4nVVzz9.js → reduced-state-TMi7ISla.js} +20 -4
- package/dist/reduced-state-TMi7ISla.js.map +1 -0
- package/dist/{reducer-registry-C0svUa63.d.ts → reducer-registry-CjSJBPKo.d.ts} +2 -2
- package/dist/{runtime-C56FQxiL.d.ts → runtime-DOgmAKsO.d.ts} +7 -6
- package/dist/services/compaction.d.ts +1 -1
- package/dist/services/compaction.js +4 -3
- package/dist/services/compaction.js.map +1 -1
- package/dist/services/id-generator.d.ts +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/prompt-projector.d.ts +2 -2
- package/dist/services/prompt-projector.js +20 -10
- package/dist/services/prompt-projector.js.map +1 -1
- package/dist/services/reducer-registry.d.ts +1 -1
- package/dist/services/runtime-layer.d.ts +58 -0
- package/dist/services/runtime-layer.js +42 -0
- package/dist/services/runtime-layer.js.map +1 -0
- package/dist/services/runtime.d.ts +1 -1
- package/dist/services/runtime.js +4 -3
- package/dist/services/runtime.js.map +1 -1
- package/dist/services/session-query.d.ts +1 -1
- package/dist/services/session-query.js +76 -1
- 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 +181 -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 +49 -0
- package/dist/services/sink-checkpoint-store.js.map +1 -0
- package/dist/services/sink-registry.d.ts +1 -1
- package/dist/services/sink-registry.js +1 -1
- package/dist/services/tool-registry.d.ts +1 -1
- package/dist/services/websocket-subscriber.d.ts +54 -0
- package/dist/services/websocket-subscriber.js +190 -0
- package/dist/services/websocket-subscriber.js.map +1 -0
- package/dist/session-query-C-C4m1eq.d.ts +38 -0
- package/dist/{session-query-DlRo5Ufc.d.ts → session-state-CjOSvWbe.d.ts} +132 -40
- package/dist/{session-query-DOc1KanA.js → session-state-SStf0KUo.js} +43 -146
- package/dist/session-state-SStf0KUo.js.map +1 -0
- package/dist/{session-store-D2Ore1QC.d.ts → session-store-DZZUffUy.d.ts} +5 -94
- package/dist/sink-checkpoint-store-BZmQFTRE.d.ts +40 -0
- package/dist/{sink-registry-CIU0LD3m.d.ts → sink-registry-Cf79ICdW.d.ts} +11 -40
- package/dist/{sink-registry-CFC6xjsN.js → sink-registry-D13eUO_c.js} +9 -47
- package/dist/sink-registry-D13eUO_c.js.map +1 -0
- package/dist/testkit/layers.d.ts +14 -11
- package/dist/testkit/layers.js +8 -5
- package/dist/testkit/layers.js.map +1 -1
- package/dist/{tool-registry-CcnkAAQK.d.ts → tool-registry-B7Wona6N.d.ts} +3 -3
- package/dist/types/core.d.ts +1 -1
- package/dist/types/core.js +1 -1
- 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 +2 -2
- package/dist/types/events.js +2 -2
- package/dist/websocket-wire-QD2SquQE.d.ts +2244 -0
- package/docs/assets/architecture.svg +170 -60
- package/docs/assets/event-sequence.svg +68 -78
- package/docs/assets/hero.svg +33 -0
- package/docs/message-steering.md +1 -1
- package/docs/releasing.md +96 -39
- package/docs/spec.md +15 -12
- package/docs/websocket-protocol.md +35 -9
- package/package.json +55 -35
- package/dist/durable-C3Rz7kg3.js.map +0 -1
- package/dist/durable-object-runtime-B7jwBY2R.js +0 -1494
- package/dist/durable-object-runtime-B7jwBY2R.js.map +0 -1
- package/dist/durable-object-runtime-pWv0ohlz.d.ts +0 -257
- 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/keep-alive-p8dIcSVy.js.map +0 -1
- package/dist/reduced-state-C4nVVzz9.js.map +0 -1
- package/dist/session-query-DOc1KanA.js.map +0 -1
- package/dist/session-store-pYxQW9qh.js +0 -214
- package/dist/session-store-pYxQW9qh.js.map +0 -1
- package/dist/sink-registry-CFC6xjsN.js.map +0 -1
- package/dist/websocket-wire-DvOu_6BJ.d.ts +0 -16773
- 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
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { h as SessionId } from "./core-
|
|
1
|
+
import { h as SessionId } from "./core-CYT6DBaS.js";
|
|
2
2
|
import { d as ToolParamsDeltaEvent, f as ToolParamsDeltaPayload, g as ToolParamsStartPayload, h as ToolParamsStartEvent, i as ReasoningDeltaPayload, l as TextDeltaEvent, m as ToolParamsEndPayload, p as ToolParamsEndEvent, r as ReasoningDeltaEvent, u as TextDeltaPayload } from "./events-Bb9-Cu-7.js";
|
|
3
|
-
import { $ as
|
|
4
|
-
import { t as IdGenerator } from "./id-generator-
|
|
3
|
+
import { $ as PendingMessagesPausedEvent, $t as TurnStoppedPayload, A as CompactionFailedEvent, At as ToolCallCreatedPayload, B as ContextRebasedPayload, Bt as ToolCallStartedPayload, Ct as SummaryCreatedEvent, D as CommandStartedPayload, Dt as ToolCallCompletedEvent, E as CommandStartedEvent, Et as SystemMessageCommittedPayload, F as CompactionStartedPayload, Ft as ToolCallRejectedEvent, Gt as TurnCompletedEvent, It as ToolCallRejectedPayload, J as InferenceStartedEvent, Jt as TurnFailedEvent, K as InferenceFailedEvent, Kt as TurnCompletedPayload, M as CompactionRequestedEvent, Mt as ToolCallFailedEvent, N as CompactionRequestedPayload, Nt as ToolCallFailedPayload, O as CompactionCompletedEvent, Ot as ToolCallCompletedPayload, P as CompactionStartedEvent, Qt as TurnStoppedEvent, S as CommandCompletedPayload, St as StopTurnRequestedPayload, T as CommandFailedPayload, Tt as SystemMessageCommittedEvent, U as InferenceCompletedEvent, W as InferenceCompletedPayload, Xt as TurnStartedEvent, Y as InferenceStartedPayload, Yt as TurnFailedPayload, Zt as TurnStartedPayload, _ as CommandAdmittedEvent, _t as SteeringMessageQueuedPayload, at as RunCompletedEvent, b as CommandCancelledPayload, bt as StopTurnAppliedPayload, cn as UserMessageSubmittedEvent, ct as RunFailedEvent, dt as RunInterruptedPayload, et as PendingMessagesPausedPayload, ft as RunStartedEvent, gt as SteeringMessageQueuedEvent, ht as SteeringMessageCancelledPayload, in as UserMessageCommittedPayload, j as CompactionFailedPayload, k as CompactionCompletedPayload, kt as ToolCallCreatedEvent, ln as UserMessageSubmittedPayload, lt as RunFailedPayload, mt as SteeringMessageCancelledEvent, n as AssistantMessageCommittedPayload, nn as UserMessageCancelledPayload, nt as RecoveryCompletedPayload, o as AssistantPartialCommittedEvent, on as UserMessagePromotedEvent, ot as RunCompletedPayload, pt as RunStartedPayload, q as InferenceFailedPayload, rn as UserMessageCommittedEvent, s as AssistantPartialCommittedPayload, sn as UserMessagePromotedPayload, t as AssistantMessageCommittedEvent, tn as UserMessageCancelledEvent, tt as RecoveryCompletedEvent, ut as RunInterruptedEvent, v as CommandAdmittedPayload, w as CommandFailedEvent, wt as SummaryCreatedPayload, x as CommandCompletedEvent, xt as StopTurnRequestedEvent, y as CommandCancelledEvent, yt as StopTurnAppliedEvent, z as ContextRebasedEvent, zt as ToolCallStartedEvent } from "./durable-B7M6TD_0.js";
|
|
4
|
+
import { t as IdGenerator } from "./id-generator-Ckl8_XWW.js";
|
|
5
5
|
import * as Context from "effect/Context";
|
|
6
6
|
import * as Effect from "effect/Effect";
|
|
7
7
|
import * as Layer from "effect/Layer";
|
|
@@ -83,29 +83,5 @@ declare class EventFactory extends EventFactory_base {
|
|
|
83
83
|
static readonly Live: Layer.Layer<EventFactory, never, IdGenerator | SessionContext>;
|
|
84
84
|
}
|
|
85
85
|
//#endregion
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
interface EDAKeepAliveLease {
|
|
89
|
-
readonly release: () => Promise<void>;
|
|
90
|
-
}
|
|
91
|
-
/** Host-provided wrapper for keeping finite active work alive in Durable Objects. */
|
|
92
|
-
interface EDAKeepAliveShape {
|
|
93
|
-
/**
|
|
94
|
-
* Durable Objects may hibernate after request/alarm callbacks finish, but EDA
|
|
95
|
-
* continues work in Effect fibers after public ingress returns: model turns,
|
|
96
|
-
* recovery drains, and durable sink catch-up. Wrap those finite active work
|
|
97
|
-
* regions so the host can keep an alarm armed until the work either completes,
|
|
98
|
-
* parks durably, fails, or is interrupted. Long-lived fibers blocked on queues
|
|
99
|
-
* should not hold a lease.
|
|
100
|
-
*/
|
|
101
|
-
readonly withActiveWork: <A, E, R>(label: string, effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
|
102
|
-
}
|
|
103
|
-
declare const EDAKeepAlive_base: Context.ServiceClass<EDAKeepAlive, "@effect-durable-agent/EDAKeepAlive", EDAKeepAliveShape>;
|
|
104
|
-
/** Host keep-alive service for finite active EDA work roots. */
|
|
105
|
-
declare class EDAKeepAlive extends EDAKeepAlive_base {
|
|
106
|
-
static readonly Noop: Layer.Layer<EDAKeepAlive, never, never>;
|
|
107
|
-
static readonly FromAcquire: (acquire: (label: string) => Promise<EDAKeepAliveLease>) => Layer.Layer<EDAKeepAlive>;
|
|
108
|
-
}
|
|
109
|
-
//#endregion
|
|
110
|
-
export { SessionContext as i, EventFactory as n, EventFactoryShape as r, EDAKeepAlive as t };
|
|
111
|
-
//# sourceMappingURL=keep-alive-DYDsH6qN.d.ts.map
|
|
86
|
+
export { EventFactoryShape as n, SessionContext as r, EventFactory as t };
|
|
87
|
+
//# sourceMappingURL=event-factory-CLJcyymV.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as PendingMessagesPausedEvent, $n as turnStoppedEventType, A as CompactionFailedEvent, An as inferenceFailedEventType, Bn as steeringMessageQueuedEventType, Cn as compactionRequestedEventType, Cr as schemaV1, Ct as SummaryCreatedEvent, Dt as ToolCallCompletedEvent, E as CommandStartedEvent, En as contextRebasedEventType, Fn as runCompletedEventType, Ft as ToolCallRejectedEvent, Gn as toolCallCompletedEventType, Gt as TurnCompletedEvent, Hn as stopTurnRequestedEventType, In as runFailedEventType, J as InferenceStartedEvent, Jn as toolCallRejectedEventType, Jt as TurnFailedEvent, K as InferenceFailedEvent, Kn as toolCallCreatedEventType, Ln as runInterruptedEventType, M as CompactionRequestedEvent, Mt as ToolCallFailedEvent, Nn as pendingMessagesPausedEventType, O as CompactionCompletedEvent, P as CompactionStartedEvent, Pn as recoveryCompletedEventType, Qn as turnStartedEventType, Qt as TurnStoppedEvent, Rn as runStartedEventType, Sn as compactionFailedEventType, Tt as SystemMessageCommittedEvent, U as InferenceCompletedEvent, Un as summaryCreatedEventType, Vn as stopTurnAppliedEventType, Wn as systemMessageCommittedEventType, Xn as turnCompletedEventType, Xt as TurnStartedEvent, Yn as toolCallStartedEventType, Zn as turnFailedEventType, _ as CommandAdmittedEvent, _n as commandCancelledEventType, at as RunCompletedEvent, bn as commandStartedEventType, cn as UserMessageSubmittedEvent, ct as RunFailedEvent, er as userMessageCancelledEventType, fn as assistantPartialCommittedEventType, ft as RunStartedEvent, gn as commandAdmittedEventType, gt as SteeringMessageQueuedEvent, jn as inferenceStartedEventType, kn as inferenceCompletedEventType, kt as ToolCallCreatedEvent, mt as SteeringMessageCancelledEvent, nr as userMessagePromotedEventType, o as AssistantPartialCommittedEvent, on as UserMessagePromotedEvent, qn as toolCallFailedEventType, rn as UserMessageCommittedEvent, rr as userMessageSubmittedEventType, t as AssistantMessageCommittedEvent, tn as UserMessageCancelledEvent, tr as userMessageCommittedEventType, tt as RecoveryCompletedEvent, un as assistantMessageCommittedEventType, ut as RunInterruptedEvent, vn as commandCompletedEventType, w as CommandFailedEvent, wn as compactionStartedEventType, x as CommandCompletedEvent, xn as compactionCompletedEventType, xr as effectDurableAgentNamespace, xt as StopTurnRequestedEvent, y as CommandCancelledEvent, yn as commandFailedEventType, yr as UnixEpochMillis, yt as StopTurnAppliedEvent, z as ContextRebasedEvent, zn as steeringMessageCancelledEventType, zt as ToolCallStartedEvent } from "./durable-DsV9PxZC.js";
|
|
2
2
|
import { ReasoningDeltaEvent, TextDeltaEvent, ToolParamsDeltaEvent, ToolParamsEndEvent, ToolParamsStartEvent, reasoningDeltaEventType, textDeltaEventType, toolParamsDeltaEventType, toolParamsEndEventType, toolParamsStartEventType } from "./types/events.js";
|
|
3
3
|
import { IdGenerator } from "./services/id-generator.js";
|
|
4
4
|
import { currentOrRootEDAEventTrace } from "./services/tracing.js";
|
|
@@ -97,13 +97,6 @@ var EventFactory = class EventFactory extends Context.Service()("@effect-durable
|
|
|
97
97
|
}));
|
|
98
98
|
};
|
|
99
99
|
//#endregion
|
|
100
|
-
|
|
101
|
-
/** Host keep-alive service for finite active EDA work roots. */
|
|
102
|
-
var EDAKeepAlive = class EDAKeepAlive extends Context.Service()("@effect-durable-agent/EDAKeepAlive") {
|
|
103
|
-
static Noop = Layer.succeed(EDAKeepAlive, { withActiveWork: (_label, effect) => effect });
|
|
104
|
-
static FromAcquire = (acquire) => Layer.succeed(EDAKeepAlive, { withActiveWork: (label, effect) => Effect.acquireUseRelease(Effect.promise(() => acquire(label)), () => effect, (lease) => Effect.promise(() => lease.release())) });
|
|
105
|
-
};
|
|
106
|
-
//#endregion
|
|
107
|
-
export { EventFactory as n, SessionContext as r, EDAKeepAlive as t };
|
|
100
|
+
export { SessionContext as n, EventFactory as t };
|
|
108
101
|
|
|
109
|
-
//# sourceMappingURL=
|
|
102
|
+
//# sourceMappingURL=event-factory-tcpLgdMN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-factory-tcpLgdMN.js","names":[],"sources":["../src/services/session-context.ts","../src/services/event-factory.ts"],"sourcesContent":["import * as Context from \"effect/Context\";\nimport * as Layer from \"effect/Layer\";\n\nimport { SessionId } from \"../types/core\";\n\n/** Runtime-scoped session identity dependency. */\nexport interface SessionContextShape {\n /** The one session this runtime instance owns; fixed for the runtime lifetime. */\n readonly sessionId: SessionId;\n}\n\n/**\n * Identity of the session a runtime instance is bound to. One runtime = one\n * session, so services read the session here instead of threading `sessionId`\n * through every input struct.\n */\nexport class SessionContext extends Context.Service<SessionContext, SessionContextShape>()(\n \"@effect-durable-agent/SessionContext\",\n) {\n static readonly Live = (sessionId: SessionId) => Layer.succeed(SessionContext, { sessionId });\n}\n","import * as Clock from \"effect/Clock\";\nimport * as Context from \"effect/Context\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\n\nimport {\n CommandAdmittedEvent,\n CommandAdmittedPayload,\n CommandCancelledEvent,\n CommandCancelledPayload,\n CommandCompletedEvent,\n CommandCompletedPayload,\n CommandFailedEvent,\n CommandFailedPayload,\n CommandStartedEvent,\n CommandStartedPayload,\n CompactionCompletedEvent,\n CompactionCompletedPayload,\n CompactionFailedEvent,\n CompactionFailedPayload,\n CompactionRequestedEvent,\n CompactionRequestedPayload,\n CompactionStartedEvent,\n CompactionStartedPayload,\n ContextRebasedEvent,\n ContextRebasedPayload,\n AssistantMessageCommittedEvent,\n AssistantMessageCommittedPayload,\n AssistantPartialCommittedEvent,\n AssistantPartialCommittedPayload,\n EventType,\n InferenceCompletedEvent,\n InferenceCompletedPayload,\n InferenceFailedEvent,\n InferenceFailedPayload,\n InferenceStartedEvent,\n InferenceStartedPayload,\n SummaryCreatedEvent,\n SummaryCreatedPayload,\n SystemMessageCommittedEvent,\n SystemMessageCommittedPayload,\n ReasoningDeltaEvent,\n ReasoningDeltaPayload,\n RecoveryCompletedEvent,\n RecoveryCompletedPayload,\n RunCompletedEvent,\n RunCompletedPayload,\n RunFailedEvent,\n RunFailedPayload,\n RunInterruptedEvent,\n RunInterruptedPayload,\n RunStartedEvent,\n RunStartedPayload,\n StopTurnAppliedEvent,\n StopTurnAppliedPayload,\n StopTurnRequestedEvent,\n StopTurnRequestedPayload,\n SteeringMessageCancelledEvent,\n SteeringMessageCancelledPayload,\n SteeringMessageQueuedEvent,\n SteeringMessageQueuedPayload,\n TextDeltaEvent,\n TextDeltaPayload,\n ToolCallCompletedEvent,\n ToolCallCompletedPayload,\n ToolCallCreatedEvent,\n ToolCallCreatedPayload,\n ToolCallFailedEvent,\n ToolCallFailedPayload,\n ToolCallRejectedEvent,\n ToolCallRejectedPayload,\n ToolCallStartedEvent,\n ToolCallStartedPayload,\n ToolParamsDeltaEvent,\n ToolParamsDeltaPayload,\n ToolParamsEndEvent,\n ToolParamsEndPayload,\n ToolParamsStartEvent,\n ToolParamsStartPayload,\n TurnCompletedEvent,\n TurnCompletedPayload,\n TurnFailedEvent,\n TurnFailedPayload,\n TurnStartedEvent,\n TurnStartedPayload,\n TurnStoppedEvent,\n TurnStoppedPayload,\n UnixEpochMillis,\n UserMessageCommittedEvent,\n UserMessageCommittedPayload,\n UserMessageSubmittedEvent,\n UserMessageSubmittedPayload,\n UserMessagePromotedEvent,\n UserMessagePromotedPayload,\n UserMessageCancelledEvent,\n UserMessageCancelledPayload,\n PendingMessagesPausedEvent,\n PendingMessagesPausedPayload,\n commandAdmittedEventType,\n commandCancelledEventType,\n commandCompletedEventType,\n commandFailedEventType,\n commandStartedEventType,\n compactionCompletedEventType,\n compactionFailedEventType,\n compactionRequestedEventType,\n compactionStartedEventType,\n contextRebasedEventType,\n assistantMessageCommittedEventType,\n assistantPartialCommittedEventType,\n effectDurableAgentNamespace,\n inferenceCompletedEventType,\n inferenceFailedEventType,\n inferenceStartedEventType,\n reasoningDeltaEventType,\n recoveryCompletedEventType,\n runCompletedEventType,\n runFailedEventType,\n runInterruptedEventType,\n runStartedEventType,\n schemaV1,\n steeringMessageCancelledEventType,\n summaryCreatedEventType,\n systemMessageCommittedEventType,\n steeringMessageQueuedEventType,\n stopTurnAppliedEventType,\n stopTurnRequestedEventType,\n textDeltaEventType,\n toolCallCompletedEventType,\n toolCallCreatedEventType,\n toolCallFailedEventType,\n toolCallRejectedEventType,\n toolCallStartedEventType,\n toolParamsDeltaEventType,\n toolParamsEndEventType,\n toolParamsStartEventType,\n turnCompletedEventType,\n turnFailedEventType,\n turnStartedEventType,\n turnStoppedEventType,\n userMessageCommittedEventType,\n userMessageSubmittedEventType,\n userMessagePromotedEventType,\n userMessageCancelledEventType,\n pendingMessagesPausedEventType,\n} from \"../types/events\";\nimport { IdGenerator } from \"./id-generator\";\nimport { SessionContext } from \"./session-context\";\nimport { currentOrRootEDAEventTrace } from \"./tracing\";\n\n/** Central envelope factory that stamps session id, event id, and current clock time. */\nexport interface EventFactoryShape {\n // Durable lifecycle events.\n readonly commandAdmitted: (\n payload: CommandAdmittedPayload,\n ) => Effect.Effect<CommandAdmittedEvent>;\n readonly commandStarted: (payload: CommandStartedPayload) => Effect.Effect<CommandStartedEvent>;\n readonly commandCompleted: (\n payload: CommandCompletedPayload,\n ) => Effect.Effect<CommandCompletedEvent>;\n readonly commandFailed: (payload: CommandFailedPayload) => Effect.Effect<CommandFailedEvent>;\n readonly commandCancelled: (\n payload: CommandCancelledPayload,\n ) => Effect.Effect<CommandCancelledEvent>;\n readonly systemMessageCommitted: (\n payload: SystemMessageCommittedPayload,\n ) => Effect.Effect<SystemMessageCommittedEvent>;\n readonly userMessageCommitted: (\n payload: UserMessageCommittedPayload,\n ) => Effect.Effect<UserMessageCommittedEvent>;\n readonly userMessageSubmitted: (\n payload: UserMessageSubmittedPayload,\n ) => Effect.Effect<UserMessageSubmittedEvent>;\n readonly userMessagePromoted: (\n payload: UserMessagePromotedPayload,\n ) => Effect.Effect<UserMessagePromotedEvent>;\n readonly userMessageCancelled: (\n payload: UserMessageCancelledPayload,\n ) => Effect.Effect<UserMessageCancelledEvent>;\n readonly pendingMessagesPaused: (\n payload: PendingMessagesPausedPayload,\n ) => Effect.Effect<PendingMessagesPausedEvent>;\n readonly steeringMessageQueued: (\n payload: SteeringMessageQueuedPayload,\n ) => Effect.Effect<SteeringMessageQueuedEvent>;\n readonly steeringMessageCancelled: (\n payload: SteeringMessageCancelledPayload,\n ) => Effect.Effect<SteeringMessageCancelledEvent>;\n readonly assistantMessageCommitted: (\n payload: AssistantMessageCommittedPayload,\n ) => Effect.Effect<AssistantMessageCommittedEvent>;\n readonly assistantPartialCommitted: (\n payload: AssistantPartialCommittedPayload,\n ) => Effect.Effect<AssistantPartialCommittedEvent>;\n readonly runStarted: (payload: RunStartedPayload) => Effect.Effect<RunStartedEvent>;\n readonly runCompleted: (payload: RunCompletedPayload) => Effect.Effect<RunCompletedEvent>;\n readonly runFailed: (payload: RunFailedPayload) => Effect.Effect<RunFailedEvent>;\n readonly recoveryCompleted: (\n payload: RecoveryCompletedPayload,\n ) => Effect.Effect<RecoveryCompletedEvent>;\n /** @deprecated Emit `runFailed` with `error.code = \"run.interrupted\"`. Retained for legacy event construction only. */\n readonly runInterrupted: (payload: RunInterruptedPayload) => Effect.Effect<RunInterruptedEvent>;\n readonly turnStarted: (payload: TurnStartedPayload) => Effect.Effect<TurnStartedEvent>;\n readonly turnCompleted: (payload: TurnCompletedPayload) => Effect.Effect<TurnCompletedEvent>;\n readonly turnFailed: (payload: TurnFailedPayload) => Effect.Effect<TurnFailedEvent>;\n /** @deprecated Emit `turnFailed` with `error.code = \"turn.interrupted\"`. Retained for legacy event construction only. */\n readonly turnStopped: (payload: TurnStoppedPayload) => Effect.Effect<TurnStoppedEvent>;\n readonly inferenceStarted: (\n payload: InferenceStartedPayload,\n ) => Effect.Effect<InferenceStartedEvent>;\n readonly inferenceCompleted: (\n payload: InferenceCompletedPayload,\n ) => Effect.Effect<InferenceCompletedEvent>;\n readonly inferenceFailed: (\n payload: InferenceFailedPayload,\n ) => Effect.Effect<InferenceFailedEvent>;\n readonly toolCallCreated: (\n payload: ToolCallCreatedPayload,\n ) => Effect.Effect<ToolCallCreatedEvent>;\n readonly toolCallRejected: (\n payload: ToolCallRejectedPayload,\n ) => Effect.Effect<ToolCallRejectedEvent>;\n readonly toolCallStarted: (\n payload: ToolCallStartedPayload,\n ) => Effect.Effect<ToolCallStartedEvent>;\n readonly toolCallCompleted: (\n payload: ToolCallCompletedPayload,\n ) => Effect.Effect<ToolCallCompletedEvent>;\n readonly toolCallFailed: (payload: ToolCallFailedPayload) => Effect.Effect<ToolCallFailedEvent>;\n readonly stopTurnRequested: (\n payload: StopTurnRequestedPayload,\n ) => Effect.Effect<StopTurnRequestedEvent>;\n readonly stopTurnApplied: (\n payload: StopTurnAppliedPayload,\n ) => Effect.Effect<StopTurnAppliedEvent>;\n readonly compactionRequested: (\n payload: CompactionRequestedPayload,\n ) => Effect.Effect<CompactionRequestedEvent>;\n readonly compactionStarted: (\n payload: CompactionStartedPayload,\n ) => Effect.Effect<CompactionStartedEvent>;\n readonly summaryCreated: (payload: SummaryCreatedPayload) => Effect.Effect<SummaryCreatedEvent>;\n readonly contextRebased: (payload: ContextRebasedPayload) => Effect.Effect<ContextRebasedEvent>;\n readonly compactionCompleted: (\n payload: CompactionCompletedPayload,\n ) => Effect.Effect<CompactionCompletedEvent>;\n readonly compactionFailed: (\n payload: CompactionFailedPayload,\n ) => Effect.Effect<CompactionFailedEvent>;\n // Ephemeral live-only events.\n readonly textDelta: (payload: TextDeltaPayload) => Effect.Effect<TextDeltaEvent>;\n readonly reasoningDelta: (payload: ReasoningDeltaPayload) => Effect.Effect<ReasoningDeltaEvent>;\n readonly toolParamsStart: (\n payload: ToolParamsStartPayload,\n ) => Effect.Effect<ToolParamsStartEvent>;\n readonly toolParamsDelta: (\n payload: ToolParamsDeltaPayload,\n ) => Effect.Effect<ToolParamsDeltaEvent>;\n readonly toolParamsEnd: (payload: ToolParamsEndPayload) => Effect.Effect<ToolParamsEndEvent>;\n}\n\n/**\n * The one construction path for built-in event envelopes. It closes over the\n * session identity, mints `eventId`s, and stamps `createdAtMs` from the\n * ambient `Clock`, so lifecycle code provides only the payload.\n */\nexport class EventFactory extends Context.Service<EventFactory, EventFactoryShape>()(\n \"@effect-durable-agent/EventFactory\",\n) {\n static readonly Live = Layer.effect(\n EventFactory,\n Effect.gen(function* () {\n const { sessionId } = yield* SessionContext;\n const ids = yield* IdGenerator;\n\n const envelope = (durability: \"durable\" | \"ephemeral\") =>\n Effect.gen(function* () {\n const eventId = yield* ids.makeEventId();\n const nowMs = yield* Clock.currentTimeMillis;\n const trace = yield* currentOrRootEDAEventTrace;\n return {\n namespace: effectDurableAgentNamespace,\n schemaVersion: schemaV1,\n durability,\n eventId,\n sessionId,\n createdAtMs: UnixEpochMillis.make(nowMs),\n trace,\n };\n });\n\n const event =\n (durability: \"durable\" | \"ephemeral\") =>\n <Payload, Event>(schema: { readonly make: (input: never) => Event }, type: EventType) =>\n (payload: Payload): Effect.Effect<Event> =>\n Effect.map(envelope(durability), (fields) =>\n schema.make({ ...fields, type, payload } as never),\n );\n const durable = event(\"durable\");\n const ephemeral = event(\"ephemeral\");\n\n return {\n commandAdmitted: durable<CommandAdmittedPayload, CommandAdmittedEvent>(\n CommandAdmittedEvent,\n commandAdmittedEventType,\n ),\n commandStarted: durable<CommandStartedPayload, CommandStartedEvent>(\n CommandStartedEvent,\n commandStartedEventType,\n ),\n commandCompleted: durable<CommandCompletedPayload, CommandCompletedEvent>(\n CommandCompletedEvent,\n commandCompletedEventType,\n ),\n commandFailed: durable<CommandFailedPayload, CommandFailedEvent>(\n CommandFailedEvent,\n commandFailedEventType,\n ),\n commandCancelled: durable<CommandCancelledPayload, CommandCancelledEvent>(\n CommandCancelledEvent,\n commandCancelledEventType,\n ),\n systemMessageCommitted: durable<SystemMessageCommittedPayload, SystemMessageCommittedEvent>(\n SystemMessageCommittedEvent,\n systemMessageCommittedEventType,\n ),\n userMessageCommitted: durable<UserMessageCommittedPayload, UserMessageCommittedEvent>(\n UserMessageCommittedEvent,\n userMessageCommittedEventType,\n ),\n userMessageSubmitted: durable<UserMessageSubmittedPayload, UserMessageSubmittedEvent>(\n UserMessageSubmittedEvent,\n userMessageSubmittedEventType,\n ),\n userMessagePromoted: durable<UserMessagePromotedPayload, UserMessagePromotedEvent>(\n UserMessagePromotedEvent,\n userMessagePromotedEventType,\n ),\n userMessageCancelled: durable<UserMessageCancelledPayload, UserMessageCancelledEvent>(\n UserMessageCancelledEvent,\n userMessageCancelledEventType,\n ),\n pendingMessagesPaused: durable<PendingMessagesPausedPayload, PendingMessagesPausedEvent>(\n PendingMessagesPausedEvent,\n pendingMessagesPausedEventType,\n ),\n steeringMessageQueued: durable<SteeringMessageQueuedPayload, SteeringMessageQueuedEvent>(\n SteeringMessageQueuedEvent,\n steeringMessageQueuedEventType,\n ),\n steeringMessageCancelled: durable<\n SteeringMessageCancelledPayload,\n SteeringMessageCancelledEvent\n >(SteeringMessageCancelledEvent, steeringMessageCancelledEventType),\n assistantMessageCommitted: durable<\n AssistantMessageCommittedPayload,\n AssistantMessageCommittedEvent\n >(AssistantMessageCommittedEvent, assistantMessageCommittedEventType),\n assistantPartialCommitted: durable<\n AssistantPartialCommittedPayload,\n AssistantPartialCommittedEvent\n >(AssistantPartialCommittedEvent, assistantPartialCommittedEventType),\n runStarted: durable<RunStartedPayload, RunStartedEvent>(\n RunStartedEvent,\n runStartedEventType,\n ),\n runCompleted: durable<RunCompletedPayload, RunCompletedEvent>(\n RunCompletedEvent,\n runCompletedEventType,\n ),\n runFailed: durable<RunFailedPayload, RunFailedEvent>(RunFailedEvent, runFailedEventType),\n recoveryCompleted: durable<RecoveryCompletedPayload, RecoveryCompletedEvent>(\n RecoveryCompletedEvent,\n recoveryCompletedEventType,\n ),\n runInterrupted: durable<RunInterruptedPayload, RunInterruptedEvent>(\n RunInterruptedEvent,\n runInterruptedEventType,\n ),\n turnStarted: durable<TurnStartedPayload, TurnStartedEvent>(\n TurnStartedEvent,\n turnStartedEventType,\n ),\n turnCompleted: durable<TurnCompletedPayload, TurnCompletedEvent>(\n TurnCompletedEvent,\n turnCompletedEventType,\n ),\n turnFailed: durable<TurnFailedPayload, TurnFailedEvent>(\n TurnFailedEvent,\n turnFailedEventType,\n ),\n turnStopped: durable<TurnStoppedPayload, TurnStoppedEvent>(\n TurnStoppedEvent,\n turnStoppedEventType,\n ),\n inferenceStarted: durable<InferenceStartedPayload, InferenceStartedEvent>(\n InferenceStartedEvent,\n inferenceStartedEventType,\n ),\n inferenceCompleted: durable<InferenceCompletedPayload, InferenceCompletedEvent>(\n InferenceCompletedEvent,\n inferenceCompletedEventType,\n ),\n inferenceFailed: durable<InferenceFailedPayload, InferenceFailedEvent>(\n InferenceFailedEvent,\n inferenceFailedEventType,\n ),\n toolCallCreated: durable<ToolCallCreatedPayload, ToolCallCreatedEvent>(\n ToolCallCreatedEvent,\n toolCallCreatedEventType,\n ),\n toolCallRejected: durable<ToolCallRejectedPayload, ToolCallRejectedEvent>(\n ToolCallRejectedEvent,\n toolCallRejectedEventType,\n ),\n toolCallStarted: durable<ToolCallStartedPayload, ToolCallStartedEvent>(\n ToolCallStartedEvent,\n toolCallStartedEventType,\n ),\n toolCallCompleted: durable<ToolCallCompletedPayload, ToolCallCompletedEvent>(\n ToolCallCompletedEvent,\n toolCallCompletedEventType,\n ),\n toolCallFailed: durable<ToolCallFailedPayload, ToolCallFailedEvent>(\n ToolCallFailedEvent,\n toolCallFailedEventType,\n ),\n stopTurnRequested: durable<StopTurnRequestedPayload, StopTurnRequestedEvent>(\n StopTurnRequestedEvent,\n stopTurnRequestedEventType,\n ),\n stopTurnApplied: durable<StopTurnAppliedPayload, StopTurnAppliedEvent>(\n StopTurnAppliedEvent,\n stopTurnAppliedEventType,\n ),\n compactionRequested: durable<CompactionRequestedPayload, CompactionRequestedEvent>(\n CompactionRequestedEvent,\n compactionRequestedEventType,\n ),\n compactionStarted: durable<CompactionStartedPayload, CompactionStartedEvent>(\n CompactionStartedEvent,\n compactionStartedEventType,\n ),\n summaryCreated: durable<SummaryCreatedPayload, SummaryCreatedEvent>(\n SummaryCreatedEvent,\n summaryCreatedEventType,\n ),\n contextRebased: durable<ContextRebasedPayload, ContextRebasedEvent>(\n ContextRebasedEvent,\n contextRebasedEventType,\n ),\n compactionCompleted: durable<CompactionCompletedPayload, CompactionCompletedEvent>(\n CompactionCompletedEvent,\n compactionCompletedEventType,\n ),\n compactionFailed: durable<CompactionFailedPayload, CompactionFailedEvent>(\n CompactionFailedEvent,\n compactionFailedEventType,\n ),\n textDelta: ephemeral<TextDeltaPayload, TextDeltaEvent>(TextDeltaEvent, textDeltaEventType),\n reasoningDelta: ephemeral<ReasoningDeltaPayload, ReasoningDeltaEvent>(\n ReasoningDeltaEvent,\n reasoningDeltaEventType,\n ),\n toolParamsStart: ephemeral<ToolParamsStartPayload, ToolParamsStartEvent>(\n ToolParamsStartEvent,\n toolParamsStartEventType,\n ),\n toolParamsDelta: ephemeral<ToolParamsDeltaPayload, ToolParamsDeltaEvent>(\n ToolParamsDeltaEvent,\n toolParamsDeltaEventType,\n ),\n toolParamsEnd: ephemeral<ToolParamsEndPayload, ToolParamsEndEvent>(\n ToolParamsEndEvent,\n toolParamsEndEventType,\n ),\n };\n }),\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AAgBA,IAAa,iBAAb,MAAa,uBAAuB,QAAQ,QAA6C,EACvF,sCACF,EAAE;CACA,OAAgB,QAAQ,cAAyB,MAAM,QAAQ,gBAAgB,EAAE,UAAU,CAAC;AAC9F;;;;;;;;ACsPA,IAAa,eAAb,MAAa,qBAAqB,QAAQ,QAAyC,EACjF,oCACF,EAAE;CACA,OAAgB,OAAO,MAAM,OAC3B,cACA,OAAO,IAAI,aAAa;EACtB,MAAM,EAAE,cAAc,OAAO;EAC7B,MAAM,MAAM,OAAO;EAEnB,MAAM,YAAY,eAChB,OAAO,IAAI,aAAa;GACtB,MAAM,UAAU,OAAO,IAAI,YAAY;GACvC,MAAM,QAAQ,OAAO,MAAM;GAC3B,MAAM,QAAQ,OAAO;GACrB,OAAO;IACL,WAAW;IACX,eAAe;IACf;IACA;IACA;IACA,aAAa,gBAAgB,KAAK,KAAK;IACvC;GACF;EACF,CAAC;EAEH,MAAM,SACH,gBACgB,QAAoD,UACpE,YACC,OAAO,IAAI,SAAS,UAAU,IAAI,WAChC,OAAO,KAAK;GAAE,GAAG;GAAQ;GAAM;EAAQ,CAAU,CACnD;EACJ,MAAM,UAAU,MAAM,SAAS;EAC/B,MAAM,YAAY,MAAM,WAAW;EAEnC,OAAO;GACL,iBAAiB,QACf,sBACA,wBACF;GACA,gBAAgB,QACd,qBACA,uBACF;GACA,kBAAkB,QAChB,uBACA,yBACF;GACA,eAAe,QACb,oBACA,sBACF;GACA,kBAAkB,QAChB,uBACA,yBACF;GACA,wBAAwB,QACtB,6BACA,+BACF;GACA,sBAAsB,QACpB,2BACA,6BACF;GACA,sBAAsB,QACpB,2BACA,6BACF;GACA,qBAAqB,QACnB,0BACA,4BACF;GACA,sBAAsB,QACpB,2BACA,6BACF;GACA,uBAAuB,QACrB,4BACA,8BACF;GACA,uBAAuB,QACrB,4BACA,8BACF;GACA,0BAA0B,QAGxB,+BAA+B,iCAAiC;GAClE,2BAA2B,QAGzB,gCAAgC,kCAAkC;GACpE,2BAA2B,QAGzB,gCAAgC,kCAAkC;GACpE,YAAY,QACV,iBACA,mBACF;GACA,cAAc,QACZ,mBACA,qBACF;GACA,WAAW,QAA0C,gBAAgB,kBAAkB;GACvF,mBAAmB,QACjB,wBACA,0BACF;GACA,gBAAgB,QACd,qBACA,uBACF;GACA,aAAa,QACX,kBACA,oBACF;GACA,eAAe,QACb,oBACA,sBACF;GACA,YAAY,QACV,iBACA,mBACF;GACA,aAAa,QACX,kBACA,oBACF;GACA,kBAAkB,QAChB,uBACA,yBACF;GACA,oBAAoB,QAClB,yBACA,2BACF;GACA,iBAAiB,QACf,sBACA,wBACF;GACA,iBAAiB,QACf,sBACA,wBACF;GACA,kBAAkB,QAChB,uBACA,yBACF;GACA,iBAAiB,QACf,sBACA,wBACF;GACA,mBAAmB,QACjB,wBACA,0BACF;GACA,gBAAgB,QACd,qBACA,uBACF;GACA,mBAAmB,QACjB,wBACA,0BACF;GACA,iBAAiB,QACf,sBACA,wBACF;GACA,qBAAqB,QACnB,0BACA,4BACF;GACA,mBAAmB,QACjB,wBACA,0BACF;GACA,gBAAgB,QACd,qBACA,uBACF;GACA,gBAAgB,QACd,qBACA,uBACF;GACA,qBAAqB,QACnB,0BACA,4BACF;GACA,kBAAkB,QAChB,uBACA,yBACF;GACA,WAAW,UAA4C,gBAAgB,kBAAkB;GACzF,gBAAgB,UACd,qBACA,uBACF;GACA,iBAAiB,UACf,sBACA,wBACF;GACA,iBAAiB,UACf,sBACA,wBACF;GACA,eAAe,UACb,oBACA,sBACF;EACF;CACF,CAAC,CACH;AACF"}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { m as SequenceNumber } from "../core-CYT6DBaS.js";
|
|
2
|
+
import { r as EDAWebSocketServerFrameEncoder } from "../websocket-wire-QD2SquQE.js";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Schema from "effect/Schema";
|
|
5
|
+
|
|
6
|
+
//#region src/host/websocket-protocol.d.ts
|
|
7
|
+
/** Current EDA live-event WebSocket protocol version. */
|
|
8
|
+
declare const EDA_WEB_SOCKET_PROTOCOL_VERSION: 1;
|
|
9
|
+
/** WebSocket close code used when a subscriber cannot keep up with live delivery. */
|
|
10
|
+
declare const EDA_WS_CLOSE_LAGGED = 4008;
|
|
11
|
+
/** WebSocket close code used for normal host-driven shutdown. */
|
|
12
|
+
declare const EDA_WS_CLOSE_GOING_AWAY = 1001;
|
|
13
|
+
/** WebSocket close code used for malformed client protocol messages. */
|
|
14
|
+
declare const EDA_WS_CLOSE_PROTOCOL_ERROR = 1002;
|
|
15
|
+
/** WebSocket close code used when the host cannot send a frame. */
|
|
16
|
+
declare const EDA_WS_CLOSE_SEND_FAILED = 1011;
|
|
17
|
+
/** WebSocket close code used for unsupported binary messages. */
|
|
18
|
+
declare const EDA_WS_CLOSE_UNSUPPORTED_DATA = 1003;
|
|
19
|
+
/** Live subscriber identity persisted in WebSocket attachments. */
|
|
20
|
+
declare const SubscriberId: Schema.brand<Schema.NonEmptyString, "SubscriberId">;
|
|
21
|
+
type SubscriberId = typeof SubscriberId.Type;
|
|
22
|
+
/** Per-connection monotonically increasing server frame id. */
|
|
23
|
+
declare const FrameId: Schema.brand<Schema.Int, "FrameId">;
|
|
24
|
+
type FrameId = typeof FrameId.Type;
|
|
25
|
+
/** Flow-control policy announced by the server in the hello frame. */
|
|
26
|
+
declare const EDAWebSocketFlowControl: Schema.Struct<{
|
|
27
|
+
readonly ackTimeoutMs: Schema.Int;
|
|
28
|
+
readonly heartbeatIntervalMs: Schema.Int;
|
|
29
|
+
readonly maxFrameBytes: Schema.Int;
|
|
30
|
+
readonly maxFrameEvents: Schema.Int;
|
|
31
|
+
readonly maxInFlightFrames: Schema.Int;
|
|
32
|
+
readonly subscriberBufferCapacityEvents: Schema.Int;
|
|
33
|
+
}>;
|
|
34
|
+
type EDAWebSocketFlowControl = typeof EDAWebSocketFlowControl.Type;
|
|
35
|
+
/** Default bounded policy sized for fast model deltas and large durable tool/message events. */
|
|
36
|
+
declare const defaultEDAWebSocketFlowControl: EDAWebSocketFlowControl;
|
|
37
|
+
/** First server frame; announces protocol and flow-control policy. */
|
|
38
|
+
declare const EDAWebSocketHelloFrame: Schema.Struct<{
|
|
39
|
+
readonly subscriberId: Schema.brand<Schema.NonEmptyString, "SubscriberId">;
|
|
40
|
+
readonly resumeSeq: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
41
|
+
readonly _tag: Schema.Literal<"hello">;
|
|
42
|
+
readonly protocolVersion: Schema.Literal<1>;
|
|
43
|
+
readonly flowControl: Schema.Struct<{
|
|
44
|
+
readonly ackTimeoutMs: Schema.Int;
|
|
45
|
+
readonly heartbeatIntervalMs: Schema.Int;
|
|
46
|
+
readonly maxFrameBytes: Schema.Int;
|
|
47
|
+
readonly maxFrameEvents: Schema.Int;
|
|
48
|
+
readonly maxInFlightFrames: Schema.Int;
|
|
49
|
+
readonly subscriberBufferCapacityEvents: Schema.Int;
|
|
50
|
+
}>;
|
|
51
|
+
}>;
|
|
52
|
+
type EDAWebSocketHelloFrame = typeof EDAWebSocketHelloFrame.Type;
|
|
53
|
+
/** Ordered positioned events delivered to the client. */
|
|
54
|
+
declare const EDAWebSocketEventsFrame: Schema.Struct<{
|
|
55
|
+
readonly _tag: Schema.Literal<"events">;
|
|
56
|
+
readonly frameId: Schema.brand<Schema.Int, "FrameId">;
|
|
57
|
+
readonly events: Schema.NonEmptyArray<Schema.Struct<{
|
|
58
|
+
readonly position: Schema.Struct<{
|
|
59
|
+
readonly seq: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
60
|
+
readonly subSeq: Schema.brand<Schema.Int, "SubSequenceNumber">;
|
|
61
|
+
}>;
|
|
62
|
+
readonly event: Schema.Struct<{
|
|
63
|
+
readonly namespace: Schema.NonEmptyString;
|
|
64
|
+
readonly type: Schema.NonEmptyString;
|
|
65
|
+
readonly schemaVersion: Schema.Int;
|
|
66
|
+
readonly durability: Schema.Literals<readonly ["durable", "ephemeral"]>;
|
|
67
|
+
readonly eventId: Schema.brand<Schema.String, "EventId">;
|
|
68
|
+
readonly sessionId: Schema.brand<Schema.String, "SessionId">;
|
|
69
|
+
readonly correlationId: Schema.optionalKey<Schema.brand<Schema.String, "CorrelationId">>;
|
|
70
|
+
readonly createdAtMs: Schema.brand<Schema.Int, "UnixEpochMillis">;
|
|
71
|
+
readonly trace: Schema.withConstructorDefault<Schema.Struct<{
|
|
72
|
+
readonly span: Schema.Struct<{
|
|
73
|
+
readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
|
|
74
|
+
readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
|
|
75
|
+
readonly sampled: Schema.Boolean;
|
|
76
|
+
readonly tracestate: Schema.NullOr<Schema.String>;
|
|
77
|
+
}>;
|
|
78
|
+
readonly links: Schema.$Array<Schema.Struct<{
|
|
79
|
+
readonly context: Schema.Struct<{
|
|
80
|
+
readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
|
|
81
|
+
readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
|
|
82
|
+
readonly sampled: Schema.Boolean;
|
|
83
|
+
readonly tracestate: Schema.NullOr<Schema.String>;
|
|
84
|
+
}>;
|
|
85
|
+
readonly attributes: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean]>>;
|
|
86
|
+
}>>;
|
|
87
|
+
}>>;
|
|
88
|
+
readonly payload: Schema.Unknown;
|
|
89
|
+
}>;
|
|
90
|
+
}>>;
|
|
91
|
+
readonly durableThroughSeq: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
92
|
+
}>;
|
|
93
|
+
type EDAWebSocketEventsFrame = typeof EDAWebSocketEventsFrame.Type;
|
|
94
|
+
/** Idle server keepalive frame that clients may ignore and must not ACK. */
|
|
95
|
+
declare const EDAWebSocketHeartbeatFrame: Schema.Struct<{
|
|
96
|
+
readonly serverTimeMs: Schema.brand<Schema.Int, "UnixEpochMillis">;
|
|
97
|
+
readonly durableThroughSeq: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
98
|
+
readonly _tag: Schema.Literal<"heartbeat">;
|
|
99
|
+
}>;
|
|
100
|
+
type EDAWebSocketHeartbeatFrame = typeof EDAWebSocketHeartbeatFrame.Type;
|
|
101
|
+
/** Optional final frame sent before a lag-close. */
|
|
102
|
+
declare const EDAWebSocketLaggedFrame: Schema.Struct<{
|
|
103
|
+
readonly resumeSeq: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
104
|
+
readonly _tag: Schema.Literal<"lagged">;
|
|
105
|
+
readonly reason: Schema.Literals<readonly ["buffer-overflow", "ack-timeout"]>;
|
|
106
|
+
}>;
|
|
107
|
+
type EDAWebSocketLaggedFrame = typeof EDAWebSocketLaggedFrame.Type;
|
|
108
|
+
/** Optional final frame sent before a protocol/internal close. */
|
|
109
|
+
declare const EDAWebSocketErrorFrame: Schema.Struct<{
|
|
110
|
+
readonly _tag: Schema.Literal<"error">;
|
|
111
|
+
readonly message: Schema.String;
|
|
112
|
+
}>;
|
|
113
|
+
type EDAWebSocketErrorFrame = typeof EDAWebSocketErrorFrame.Type;
|
|
114
|
+
/** Server-to-client application frame union. */
|
|
115
|
+
declare const EDAWebSocketServerFrame: Schema.Union<readonly [Schema.Struct<{
|
|
116
|
+
readonly subscriberId: Schema.brand<Schema.NonEmptyString, "SubscriberId">;
|
|
117
|
+
readonly resumeSeq: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
118
|
+
readonly _tag: Schema.Literal<"hello">;
|
|
119
|
+
readonly protocolVersion: Schema.Literal<1>;
|
|
120
|
+
readonly flowControl: Schema.Struct<{
|
|
121
|
+
readonly ackTimeoutMs: Schema.Int;
|
|
122
|
+
readonly heartbeatIntervalMs: Schema.Int;
|
|
123
|
+
readonly maxFrameBytes: Schema.Int;
|
|
124
|
+
readonly maxFrameEvents: Schema.Int;
|
|
125
|
+
readonly maxInFlightFrames: Schema.Int;
|
|
126
|
+
readonly subscriberBufferCapacityEvents: Schema.Int;
|
|
127
|
+
}>;
|
|
128
|
+
}>, Schema.Struct<{
|
|
129
|
+
readonly _tag: Schema.Literal<"events">;
|
|
130
|
+
readonly frameId: Schema.brand<Schema.Int, "FrameId">;
|
|
131
|
+
readonly events: Schema.NonEmptyArray<Schema.Struct<{
|
|
132
|
+
readonly position: Schema.Struct<{
|
|
133
|
+
readonly seq: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
134
|
+
readonly subSeq: Schema.brand<Schema.Int, "SubSequenceNumber">;
|
|
135
|
+
}>;
|
|
136
|
+
readonly event: Schema.Struct<{
|
|
137
|
+
readonly namespace: Schema.NonEmptyString;
|
|
138
|
+
readonly type: Schema.NonEmptyString;
|
|
139
|
+
readonly schemaVersion: Schema.Int;
|
|
140
|
+
readonly durability: Schema.Literals<readonly ["durable", "ephemeral"]>;
|
|
141
|
+
readonly eventId: Schema.brand<Schema.String, "EventId">;
|
|
142
|
+
readonly sessionId: Schema.brand<Schema.String, "SessionId">;
|
|
143
|
+
readonly correlationId: Schema.optionalKey<Schema.brand<Schema.String, "CorrelationId">>;
|
|
144
|
+
readonly createdAtMs: Schema.brand<Schema.Int, "UnixEpochMillis">;
|
|
145
|
+
readonly trace: Schema.withConstructorDefault<Schema.Struct<{
|
|
146
|
+
readonly span: Schema.Struct<{
|
|
147
|
+
readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
|
|
148
|
+
readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
|
|
149
|
+
readonly sampled: Schema.Boolean;
|
|
150
|
+
readonly tracestate: Schema.NullOr<Schema.String>;
|
|
151
|
+
}>;
|
|
152
|
+
readonly links: Schema.$Array<Schema.Struct<{
|
|
153
|
+
readonly context: Schema.Struct<{
|
|
154
|
+
readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
|
|
155
|
+
readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
|
|
156
|
+
readonly sampled: Schema.Boolean;
|
|
157
|
+
readonly tracestate: Schema.NullOr<Schema.String>;
|
|
158
|
+
}>;
|
|
159
|
+
readonly attributes: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean]>>;
|
|
160
|
+
}>>;
|
|
161
|
+
}>>;
|
|
162
|
+
readonly payload: Schema.Unknown;
|
|
163
|
+
}>;
|
|
164
|
+
}>>;
|
|
165
|
+
readonly durableThroughSeq: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
166
|
+
}>, Schema.Struct<{
|
|
167
|
+
readonly serverTimeMs: Schema.brand<Schema.Int, "UnixEpochMillis">;
|
|
168
|
+
readonly durableThroughSeq: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
169
|
+
readonly _tag: Schema.Literal<"heartbeat">;
|
|
170
|
+
}>, Schema.Struct<{
|
|
171
|
+
readonly resumeSeq: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
172
|
+
readonly _tag: Schema.Literal<"lagged">;
|
|
173
|
+
readonly reason: Schema.Literals<readonly ["buffer-overflow", "ack-timeout"]>;
|
|
174
|
+
}>, Schema.Struct<{
|
|
175
|
+
readonly _tag: Schema.Literal<"error">;
|
|
176
|
+
readonly message: Schema.String;
|
|
177
|
+
}>]>;
|
|
178
|
+
type EDAWebSocketServerFrame = typeof EDAWebSocketServerFrame.Type;
|
|
179
|
+
/** Client acknowledgement after applying a server frame. */
|
|
180
|
+
declare const EDAWebSocketAckFrame: Schema.Struct<{
|
|
181
|
+
readonly frameId: Schema.brand<Schema.Int, "FrameId">;
|
|
182
|
+
readonly durableThroughSeq: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
183
|
+
readonly _tag: Schema.Literal<"ack">;
|
|
184
|
+
}>;
|
|
185
|
+
type EDAWebSocketAckFrame = typeof EDAWebSocketAckFrame.Type;
|
|
186
|
+
/** Client-to-server application frame union. */
|
|
187
|
+
declare const EDAWebSocketClientFrame: Schema.Union<readonly [Schema.Struct<{
|
|
188
|
+
readonly frameId: Schema.brand<Schema.Int, "FrameId">;
|
|
189
|
+
readonly durableThroughSeq: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
190
|
+
readonly _tag: Schema.Literal<"ack">;
|
|
191
|
+
}>]>;
|
|
192
|
+
type EDAWebSocketClientFrame = typeof EDAWebSocketClientFrame.Type;
|
|
193
|
+
/** Small attachment persisted by hibernation-capable WebSocket hosts. */
|
|
194
|
+
declare const EDAWebSocketAttachment: Schema.Struct<{
|
|
195
|
+
readonly kind: Schema.Literal<"eda-events-v1">;
|
|
196
|
+
readonly sessionId: Schema.brand<Schema.String, "SessionId">;
|
|
197
|
+
readonly subscriberId: Schema.brand<Schema.NonEmptyString, "SubscriberId">;
|
|
198
|
+
readonly lastAckedSeq: Schema.brand<Schema.Int, "SequenceNumber">;
|
|
199
|
+
readonly trace: Schema.Struct<{
|
|
200
|
+
readonly parent: Schema.NullOr<Schema.Struct<{
|
|
201
|
+
readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
|
|
202
|
+
readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
|
|
203
|
+
readonly sampled: Schema.Boolean;
|
|
204
|
+
readonly tracestate: Schema.NullOr<Schema.String>;
|
|
205
|
+
}>>;
|
|
206
|
+
readonly links: Schema.$Array<Schema.Struct<{
|
|
207
|
+
readonly context: Schema.Struct<{
|
|
208
|
+
readonly traceId: Schema.brand<Schema.String, "EDATraceId">;
|
|
209
|
+
readonly spanId: Schema.brand<Schema.String, "EDASpanId">;
|
|
210
|
+
readonly sampled: Schema.Boolean;
|
|
211
|
+
readonly tracestate: Schema.NullOr<Schema.String>;
|
|
212
|
+
}>;
|
|
213
|
+
readonly attributes: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean]>>;
|
|
214
|
+
}>>;
|
|
215
|
+
readonly attributes: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Number, Schema.Boolean]>>;
|
|
216
|
+
}>;
|
|
217
|
+
}>;
|
|
218
|
+
type EDAWebSocketAttachment = typeof EDAWebSocketAttachment.Type;
|
|
219
|
+
/** Serialize a server frame for a text WebSocket message. */
|
|
220
|
+
declare const encodeEDAWebSocketServerFrame: (frame: EDAWebSocketServerFrame, protocol?: EDAWebSocketServerFrameEncoder) => string;
|
|
221
|
+
/** Decode an unknown attachment value from host WebSocket hibernation storage. */
|
|
222
|
+
declare const decodeEDAWebSocketAttachment: (input: unknown) => Effect.Effect<EDAWebSocketAttachment, unknown>;
|
|
223
|
+
/** Decode an inbound text WebSocket message at the host boundary. */
|
|
224
|
+
declare const decodeEDAWebSocketClientMessage: (input: string) => Effect.Effect<EDAWebSocketClientFrame, unknown>;
|
|
225
|
+
/** Short close reason that fits the WebSocket protocol reason limit. */
|
|
226
|
+
declare const laggedCloseReason: (seq: SequenceNumber) => string;
|
|
227
|
+
//#endregion
|
|
228
|
+
export { EDAWebSocketAckFrame, EDAWebSocketAttachment, EDAWebSocketClientFrame, EDAWebSocketErrorFrame, EDAWebSocketEventsFrame, EDAWebSocketFlowControl, EDAWebSocketHeartbeatFrame, EDAWebSocketHelloFrame, EDAWebSocketLaggedFrame, EDAWebSocketServerFrame, EDA_WEB_SOCKET_PROTOCOL_VERSION, EDA_WS_CLOSE_GOING_AWAY, EDA_WS_CLOSE_LAGGED, EDA_WS_CLOSE_PROTOCOL_ERROR, EDA_WS_CLOSE_SEND_FAILED, EDA_WS_CLOSE_UNSUPPORTED_DATA, FrameId, SubscriberId, decodeEDAWebSocketAttachment, decodeEDAWebSocketClientMessage, defaultEDAWebSocketFlowControl, encodeEDAWebSocketServerFrame, laggedCloseReason };
|
|
229
|
+
//# sourceMappingURL=websocket-protocol.d.ts.map
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { SequenceNumber, SessionId } from "../types/core.js";
|
|
2
|
+
import { EDATraceMetadata } from "../types/tracing.js";
|
|
3
|
+
import { mr as PositionedEvent, yr as UnixEpochMillis } from "../durable-DsV9PxZC.js";
|
|
4
|
+
import { EDAWebSocketWireAckFrame, EDAWebSocketWireClientFrame, EDAWebSocketWireErrorFrame, EDAWebSocketWireFlowControl, EDAWebSocketWireHeartbeatFrame, EDAWebSocketWireHelloFrame, EDAWebSocketWireLaggedFrame, edaFrameworkWebSocketWireProtocol } from "./websocket-wire.js";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Schema from "effect/Schema";
|
|
7
|
+
//#region src/host/websocket-protocol.ts
|
|
8
|
+
/** Current EDA live-event WebSocket protocol version. */
|
|
9
|
+
const EDA_WEB_SOCKET_PROTOCOL_VERSION = 1;
|
|
10
|
+
/** WebSocket close code used when a subscriber cannot keep up with live delivery. */
|
|
11
|
+
const EDA_WS_CLOSE_LAGGED = 4008;
|
|
12
|
+
/** WebSocket close code used for normal host-driven shutdown. */
|
|
13
|
+
const EDA_WS_CLOSE_GOING_AWAY = 1001;
|
|
14
|
+
/** WebSocket close code used for malformed client protocol messages. */
|
|
15
|
+
const EDA_WS_CLOSE_PROTOCOL_ERROR = 1002;
|
|
16
|
+
/** WebSocket close code used when the host cannot send a frame. */
|
|
17
|
+
const EDA_WS_CLOSE_SEND_FAILED = 1011;
|
|
18
|
+
/** WebSocket close code used for unsupported binary messages. */
|
|
19
|
+
const EDA_WS_CLOSE_UNSUPPORTED_DATA = 1003;
|
|
20
|
+
/** Live subscriber identity persisted in WebSocket attachments. */
|
|
21
|
+
const SubscriberId = Schema.NonEmptyString.pipe(Schema.brand("SubscriberId"));
|
|
22
|
+
/** Per-connection monotonically increasing server frame id. */
|
|
23
|
+
const FrameId = Schema.Int.check(Schema.isGreaterThanOrEqualTo(1)).pipe(Schema.brand("FrameId"));
|
|
24
|
+
/** Flow-control policy announced by the server in the hello frame. */
|
|
25
|
+
const EDAWebSocketFlowControl = EDAWebSocketWireFlowControl;
|
|
26
|
+
/** Default bounded policy sized for fast model deltas and large durable tool/message events. */
|
|
27
|
+
const defaultEDAWebSocketFlowControl = {
|
|
28
|
+
ackTimeoutMs: 3e4,
|
|
29
|
+
heartbeatIntervalMs: 1e4,
|
|
30
|
+
maxFrameBytes: 256 * 1024,
|
|
31
|
+
maxFrameEvents: 1,
|
|
32
|
+
maxInFlightFrames: 16,
|
|
33
|
+
subscriberBufferCapacityEvents: 2048
|
|
34
|
+
};
|
|
35
|
+
/** First server frame; announces protocol and flow-control policy. */
|
|
36
|
+
const EDAWebSocketHelloFrame = Schema.Struct({
|
|
37
|
+
...EDAWebSocketWireHelloFrame.fields,
|
|
38
|
+
subscriberId: SubscriberId,
|
|
39
|
+
resumeSeq: SequenceNumber
|
|
40
|
+
});
|
|
41
|
+
/** Ordered positioned events delivered to the client. */
|
|
42
|
+
const EDAWebSocketEventsFrame = Schema.Struct({
|
|
43
|
+
_tag: Schema.Literal("events"),
|
|
44
|
+
frameId: FrameId,
|
|
45
|
+
events: Schema.NonEmptyArray(PositionedEvent),
|
|
46
|
+
durableThroughSeq: SequenceNumber
|
|
47
|
+
});
|
|
48
|
+
/** Idle server keepalive frame that clients may ignore and must not ACK. */
|
|
49
|
+
const EDAWebSocketHeartbeatFrame = Schema.Struct({
|
|
50
|
+
...EDAWebSocketWireHeartbeatFrame.fields,
|
|
51
|
+
serverTimeMs: UnixEpochMillis,
|
|
52
|
+
durableThroughSeq: SequenceNumber
|
|
53
|
+
});
|
|
54
|
+
/** Optional final frame sent before a lag-close. */
|
|
55
|
+
const EDAWebSocketLaggedFrame = Schema.Struct({
|
|
56
|
+
...EDAWebSocketWireLaggedFrame.fields,
|
|
57
|
+
resumeSeq: SequenceNumber
|
|
58
|
+
});
|
|
59
|
+
/** Optional final frame sent before a protocol/internal close. */
|
|
60
|
+
const EDAWebSocketErrorFrame = EDAWebSocketWireErrorFrame;
|
|
61
|
+
/** Server-to-client application frame union. */
|
|
62
|
+
const EDAWebSocketServerFrame = Schema.Union([
|
|
63
|
+
EDAWebSocketHelloFrame,
|
|
64
|
+
EDAWebSocketEventsFrame,
|
|
65
|
+
EDAWebSocketHeartbeatFrame,
|
|
66
|
+
EDAWebSocketLaggedFrame,
|
|
67
|
+
EDAWebSocketErrorFrame
|
|
68
|
+
]);
|
|
69
|
+
/** Client acknowledgement after applying a server frame. */
|
|
70
|
+
const EDAWebSocketAckFrame = Schema.Struct({
|
|
71
|
+
...EDAWebSocketWireAckFrame.fields,
|
|
72
|
+
frameId: FrameId,
|
|
73
|
+
durableThroughSeq: SequenceNumber
|
|
74
|
+
});
|
|
75
|
+
/** Client-to-server application frame union. */
|
|
76
|
+
const EDAWebSocketClientFrame = Schema.Union([EDAWebSocketAckFrame]);
|
|
77
|
+
/** Small attachment persisted by hibernation-capable WebSocket hosts. */
|
|
78
|
+
const EDAWebSocketAttachment = Schema.Struct({
|
|
79
|
+
kind: Schema.Literal("eda-events-v1"),
|
|
80
|
+
sessionId: SessionId,
|
|
81
|
+
subscriberId: SubscriberId,
|
|
82
|
+
lastAckedSeq: SequenceNumber,
|
|
83
|
+
trace: EDATraceMetadata
|
|
84
|
+
});
|
|
85
|
+
/** Serialize a server frame for a text WebSocket message. */
|
|
86
|
+
const encodeEDAWebSocketServerFrame = (frame, protocol) => (protocol ?? edaFrameworkWebSocketWireProtocol.host).encodeServerFrame(frame);
|
|
87
|
+
/** Decode an unknown attachment value from host WebSocket hibernation storage. */
|
|
88
|
+
const decodeEDAWebSocketAttachment = (input) => Schema.decodeUnknownEffect(EDAWebSocketAttachment)(input);
|
|
89
|
+
/** Decode an inbound text WebSocket message at the host boundary. */
|
|
90
|
+
const decodeEDAWebSocketClientMessage = (input) => Effect.try({
|
|
91
|
+
try: () => JSON.parse(input),
|
|
92
|
+
catch: (error) => error
|
|
93
|
+
}).pipe(Effect.flatMap((json) => Schema.decodeUnknownEffect(EDAWebSocketWireClientFrame)(json)), Effect.flatMap((frame) => Schema.decodeUnknownEffect(EDAWebSocketClientFrame)(frame)));
|
|
94
|
+
/** Short close reason that fits the WebSocket protocol reason limit. */
|
|
95
|
+
const laggedCloseReason = (seq) => `lag;seq=${seq}`;
|
|
96
|
+
//#endregion
|
|
97
|
+
export { EDAWebSocketAckFrame, EDAWebSocketAttachment, EDAWebSocketClientFrame, EDAWebSocketErrorFrame, EDAWebSocketEventsFrame, EDAWebSocketFlowControl, EDAWebSocketHeartbeatFrame, EDAWebSocketHelloFrame, EDAWebSocketLaggedFrame, EDAWebSocketServerFrame, EDA_WEB_SOCKET_PROTOCOL_VERSION, EDA_WS_CLOSE_GOING_AWAY, EDA_WS_CLOSE_LAGGED, EDA_WS_CLOSE_PROTOCOL_ERROR, EDA_WS_CLOSE_SEND_FAILED, EDA_WS_CLOSE_UNSUPPORTED_DATA, FrameId, SubscriberId, decodeEDAWebSocketAttachment, decodeEDAWebSocketClientMessage, defaultEDAWebSocketFlowControl, encodeEDAWebSocketServerFrame, laggedCloseReason };
|
|
98
|
+
|
|
99
|
+
//# sourceMappingURL=websocket-protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket-protocol.js","names":[],"sources":["../../src/host/websocket-protocol.ts"],"sourcesContent":["import * as Effect from \"effect/Effect\";\nimport * as Schema from \"effect/Schema\";\nimport {\n EDA_WEB_SOCKET_WIRE_PROTOCOL_VERSION,\n EDAWebSocketWireAckFrame,\n EDAWebSocketWireClientFrame,\n EDAWebSocketWireErrorFrame,\n EDAWebSocketWireFlowControl,\n EDAWebSocketWireHeartbeatFrame,\n EDAWebSocketWireHelloFrame,\n EDAWebSocketWireLaggedFrame,\n edaFrameworkWebSocketWireProtocol,\n type EDAWebSocketServerFrameEncoder,\n} from \"./websocket-wire\";\n\nimport { SequenceNumber, SessionId } from \"../types/core\";\nimport { PositionedEvent, UnixEpochMillis } from \"../types/events\";\nimport { EDATraceMetadata } from \"../types/tracing\";\n\n/** Current EDA live-event WebSocket protocol version. */\nexport const EDA_WEB_SOCKET_PROTOCOL_VERSION = EDA_WEB_SOCKET_WIRE_PROTOCOL_VERSION;\n\n/** WebSocket close code used when a subscriber cannot keep up with live delivery. */\nexport const EDA_WS_CLOSE_LAGGED = 4008;\n\n/** WebSocket close code used for normal host-driven shutdown. */\nexport const EDA_WS_CLOSE_GOING_AWAY = 1001;\n\n/** WebSocket close code used for malformed client protocol messages. */\nexport const EDA_WS_CLOSE_PROTOCOL_ERROR = 1002;\n\n/** WebSocket close code used when the host cannot send a frame. */\nexport const EDA_WS_CLOSE_SEND_FAILED = 1011;\n\n/** WebSocket close code used for unsupported binary messages. */\nexport const EDA_WS_CLOSE_UNSUPPORTED_DATA = 1003;\n\n/** Live subscriber identity persisted in WebSocket attachments. */\nexport const SubscriberId = Schema.NonEmptyString.pipe(Schema.brand(\"SubscriberId\"));\nexport type SubscriberId = typeof SubscriberId.Type;\n\n/** Per-connection monotonically increasing server frame id. */\nexport const FrameId = Schema.Int.check(Schema.isGreaterThanOrEqualTo(1)).pipe(\n Schema.brand(\"FrameId\"),\n);\nexport type FrameId = typeof FrameId.Type;\n\n/** Flow-control policy announced by the server in the hello frame. */\nexport const EDAWebSocketFlowControl = EDAWebSocketWireFlowControl;\nexport type EDAWebSocketFlowControl = typeof EDAWebSocketFlowControl.Type;\n\n/** Default bounded policy sized for fast model deltas and large durable tool/message events. */\nexport const defaultEDAWebSocketFlowControl: EDAWebSocketFlowControl = {\n ackTimeoutMs: 30_000,\n heartbeatIntervalMs: 10_000,\n maxFrameBytes: 256 * 1024,\n maxFrameEvents: 1,\n maxInFlightFrames: 16,\n subscriberBufferCapacityEvents: 2_048,\n};\n\n/** First server frame; announces protocol and flow-control policy. */\nexport const EDAWebSocketHelloFrame = Schema.Struct({\n ...EDAWebSocketWireHelloFrame.fields,\n subscriberId: SubscriberId,\n resumeSeq: SequenceNumber,\n});\nexport type EDAWebSocketHelloFrame = typeof EDAWebSocketHelloFrame.Type;\n\n/** Ordered positioned events delivered to the client. */\nexport const EDAWebSocketEventsFrame = Schema.Struct({\n _tag: Schema.Literal(\"events\"),\n frameId: FrameId,\n events: Schema.NonEmptyArray(PositionedEvent),\n durableThroughSeq: SequenceNumber,\n});\nexport type EDAWebSocketEventsFrame = typeof EDAWebSocketEventsFrame.Type;\n\n/** Idle server keepalive frame that clients may ignore and must not ACK. */\nexport const EDAWebSocketHeartbeatFrame = Schema.Struct({\n ...EDAWebSocketWireHeartbeatFrame.fields,\n serverTimeMs: UnixEpochMillis,\n durableThroughSeq: SequenceNumber,\n});\nexport type EDAWebSocketHeartbeatFrame = typeof EDAWebSocketHeartbeatFrame.Type;\n\n/** Optional final frame sent before a lag-close. */\nexport const EDAWebSocketLaggedFrame = Schema.Struct({\n ...EDAWebSocketWireLaggedFrame.fields,\n resumeSeq: SequenceNumber,\n});\nexport type EDAWebSocketLaggedFrame = typeof EDAWebSocketLaggedFrame.Type;\n\n/** Optional final frame sent before a protocol/internal close. */\nexport const EDAWebSocketErrorFrame = EDAWebSocketWireErrorFrame;\nexport type EDAWebSocketErrorFrame = typeof EDAWebSocketErrorFrame.Type;\n\n/** Server-to-client application frame union. */\nexport const EDAWebSocketServerFrame = Schema.Union([\n EDAWebSocketHelloFrame,\n EDAWebSocketEventsFrame,\n EDAWebSocketHeartbeatFrame,\n EDAWebSocketLaggedFrame,\n EDAWebSocketErrorFrame,\n]);\nexport type EDAWebSocketServerFrame = typeof EDAWebSocketServerFrame.Type;\n\n/** Client acknowledgement after applying a server frame. */\nexport const EDAWebSocketAckFrame = Schema.Struct({\n ...EDAWebSocketWireAckFrame.fields,\n frameId: FrameId,\n durableThroughSeq: SequenceNumber,\n});\nexport type EDAWebSocketAckFrame = typeof EDAWebSocketAckFrame.Type;\n\n/** Client-to-server application frame union. */\nexport const EDAWebSocketClientFrame = Schema.Union([EDAWebSocketAckFrame]);\nexport type EDAWebSocketClientFrame = typeof EDAWebSocketClientFrame.Type;\n\n/** Small attachment persisted by hibernation-capable WebSocket hosts. */\nexport const EDAWebSocketAttachment = Schema.Struct({\n kind: Schema.Literal(\"eda-events-v1\"),\n sessionId: SessionId,\n subscriberId: SubscriberId,\n lastAckedSeq: SequenceNumber,\n trace: EDATraceMetadata,\n});\nexport type EDAWebSocketAttachment = typeof EDAWebSocketAttachment.Type;\n\n/** Serialize a server frame for a text WebSocket message. */\nexport const encodeEDAWebSocketServerFrame = (\n frame: EDAWebSocketServerFrame,\n protocol?: EDAWebSocketServerFrameEncoder,\n): string => (protocol ?? edaFrameworkWebSocketWireProtocol.host).encodeServerFrame(frame);\n\n/** Decode an unknown attachment value from host WebSocket hibernation storage. */\nexport const decodeEDAWebSocketAttachment = (\n input: unknown,\n): Effect.Effect<EDAWebSocketAttachment, unknown> =>\n Schema.decodeUnknownEffect(EDAWebSocketAttachment)(input);\n\n/** Decode an inbound text WebSocket message at the host boundary. */\nexport const decodeEDAWebSocketClientMessage = (\n input: string,\n): Effect.Effect<EDAWebSocketClientFrame, unknown> =>\n Effect.try({\n try: () => JSON.parse(input) as unknown,\n catch: (error) => error,\n }).pipe(\n Effect.flatMap((json) => Schema.decodeUnknownEffect(EDAWebSocketWireClientFrame)(json)),\n Effect.flatMap((frame) => Schema.decodeUnknownEffect(EDAWebSocketClientFrame)(frame)),\n );\n\n/** Short close reason that fits the WebSocket protocol reason limit. */\nexport const laggedCloseReason = (seq: SequenceNumber): string => `lag;seq=${seq}`;\n"],"mappings":";;;;;;;;AAoBA,MAAa,kCAAA;;AAGb,MAAa,sBAAsB;;AAGnC,MAAa,0BAA0B;;AAGvC,MAAa,8BAA8B;;AAG3C,MAAa,2BAA2B;;AAGxC,MAAa,gCAAgC;;AAG7C,MAAa,eAAe,OAAO,eAAe,KAAK,OAAO,MAAM,cAAc,CAAC;;AAInF,MAAa,UAAU,OAAO,IAAI,MAAM,OAAO,uBAAuB,CAAC,CAAC,EAAE,KACxE,OAAO,MAAM,SAAS,CACxB;;AAIA,MAAa,0BAA0B;;AAIvC,MAAa,iCAA0D;CACrE,cAAc;CACd,qBAAqB;CACrB,eAAe,MAAM;CACrB,gBAAgB;CAChB,mBAAmB;CACnB,gCAAgC;AAClC;;AAGA,MAAa,yBAAyB,OAAO,OAAO;CAClD,GAAG,2BAA2B;CAC9B,cAAc;CACd,WAAW;AACb,CAAC;;AAID,MAAa,0BAA0B,OAAO,OAAO;CACnD,MAAM,OAAO,QAAQ,QAAQ;CAC7B,SAAS;CACT,QAAQ,OAAO,cAAc,eAAe;CAC5C,mBAAmB;AACrB,CAAC;;AAID,MAAa,6BAA6B,OAAO,OAAO;CACtD,GAAG,+BAA+B;CAClC,cAAc;CACd,mBAAmB;AACrB,CAAC;;AAID,MAAa,0BAA0B,OAAO,OAAO;CACnD,GAAG,4BAA4B;CAC/B,WAAW;AACb,CAAC;;AAID,MAAa,yBAAyB;;AAItC,MAAa,0BAA0B,OAAO,MAAM;CAClD;CACA;CACA;CACA;CACA;AACF,CAAC;;AAID,MAAa,uBAAuB,OAAO,OAAO;CAChD,GAAG,yBAAyB;CAC5B,SAAS;CACT,mBAAmB;AACrB,CAAC;;AAID,MAAa,0BAA0B,OAAO,MAAM,CAAC,oBAAoB,CAAC;;AAI1E,MAAa,yBAAyB,OAAO,OAAO;CAClD,MAAM,OAAO,QAAQ,eAAe;CACpC,WAAW;CACX,cAAc;CACd,cAAc;CACd,OAAO;AACT,CAAC;;AAID,MAAa,iCACX,OACA,cACY,YAAY,kCAAkC,MAAM,kBAAkB,KAAK;;AAGzF,MAAa,gCACX,UAEA,OAAO,oBAAoB,sBAAsB,EAAE,KAAK;;AAG1D,MAAa,mCACX,UAEA,OAAO,IAAI;CACT,WAAW,KAAK,MAAM,KAAK;CAC3B,QAAQ,UAAU;AACpB,CAAC,EAAE,KACD,OAAO,SAAS,SAAS,OAAO,oBAAoB,2BAA2B,EAAE,IAAI,CAAC,GACtF,OAAO,SAAS,UAAU,OAAO,oBAAoB,uBAAuB,EAAE,KAAK,CAAC,CACtF;;AAGF,MAAa,qBAAqB,QAAgC,WAAW"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { EDAFrameworkWebSocketEvent, EDAWebSocketEventConsumerPolicy, EDAWebSocketServerFrameEncoder, EDAWebSocketWireAckFrame, EDAWebSocketWireClientFrame, EDAWebSocketWireErrorFrame, EDAWebSocketWireFlowControl, EDAWebSocketWireHeartbeatFrame, EDAWebSocketWireHelloFrame, EDAWebSocketWireLaggedFrame, EDA_WEB_SOCKET_WIRE_PROTOCOL_VERSION, edaFrameworkWebSocketWireProtocol, makeEDAWebSocketWireProtocol };
|
|
1
|
+
import { a as EDAWebSocketWireAckFrame, c as EDAWebSocketWireFlowControl, d as EDAWebSocketWireLaggedFrame, f as EDAWebSocketWireProtocol, h as makeEDAWebSocketWireProtocol, i as EDAWebSocketServerFrameInput, l as EDAWebSocketWireHeartbeatFrame, m as edaFrameworkWebSocketWireProtocol, n as EDAWebSocketEventConsumerPolicy, o as EDAWebSocketWireClientFrame, p as EDA_WEB_SOCKET_WIRE_PROTOCOL_VERSION, r as EDAWebSocketServerFrameEncoder, s as EDAWebSocketWireErrorFrame, t as EDAFrameworkWebSocketEvent, u as EDAWebSocketWireHelloFrame } from "../websocket-wire-QD2SquQE.js";
|
|
2
|
+
export { EDAFrameworkWebSocketEvent, EDAWebSocketEventConsumerPolicy, EDAWebSocketServerFrameEncoder, EDAWebSocketServerFrameInput, EDAWebSocketWireAckFrame, EDAWebSocketWireClientFrame, EDAWebSocketWireErrorFrame, EDAWebSocketWireFlowControl, EDAWebSocketWireHeartbeatFrame, EDAWebSocketWireHelloFrame, EDAWebSocketWireLaggedFrame, EDAWebSocketWireProtocol, EDA_WEB_SOCKET_WIRE_PROTOCOL_VERSION, edaFrameworkWebSocketWireProtocol, makeEDAWebSocketWireProtocol };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Position } from "../types/core.js";
|
|
2
|
-
import {
|
|
2
|
+
import { V as EDADurableEvent, cr as EventEnvelope } from "../durable-DsV9PxZC.js";
|
|
3
3
|
import { EDAEphemeralEvent } from "../types/events.js";
|
|
4
4
|
import * as Schema from "effect/Schema";
|
|
5
5
|
//#region src/host/websocket-wire.ts
|
|
@@ -45,31 +45,47 @@ const EDAWebSocketWireAckFrame = Schema.Struct({
|
|
|
45
45
|
const EDAWebSocketWireClientFrame = Schema.Union([EDAWebSocketWireAckFrame]);
|
|
46
46
|
/** Complete framework-owned event union present on every EDA WebSocket. */
|
|
47
47
|
const EDAFrameworkWebSocketEvent = Schema.Union([EDADurableEvent, EDAEphemeralEvent]);
|
|
48
|
-
const
|
|
49
|
-
const
|
|
48
|
+
const makeEDAWebSocketDomainSchemas = (event) => {
|
|
49
|
+
const positionedEvent = Schema.Struct({
|
|
50
50
|
position: Position,
|
|
51
51
|
event
|
|
52
52
|
});
|
|
53
|
-
const
|
|
53
|
+
const eventsFrame = Schema.Struct({
|
|
54
54
|
_tag: Schema.Literal("events"),
|
|
55
55
|
frameId: PositiveInt,
|
|
56
|
-
events: Schema.NonEmptyArray(
|
|
56
|
+
events: Schema.NonEmptyArray(positionedEvent),
|
|
57
57
|
durableThroughSeq: NonNegativeInt
|
|
58
58
|
});
|
|
59
|
-
const DomainServerFrame = Schema.Union([
|
|
60
|
-
EDAWebSocketWireHelloFrame,
|
|
61
|
-
DomainEventsFrame,
|
|
62
|
-
EDAWebSocketWireHeartbeatFrame,
|
|
63
|
-
EDAWebSocketWireLaggedFrame,
|
|
64
|
-
EDAWebSocketWireErrorFrame
|
|
65
|
-
]);
|
|
66
59
|
return {
|
|
67
|
-
event
|
|
68
|
-
positionedEvent
|
|
69
|
-
eventsFrame
|
|
70
|
-
serverFrame: Schema.
|
|
71
|
-
|
|
72
|
-
|
|
60
|
+
event,
|
|
61
|
+
positionedEvent,
|
|
62
|
+
eventsFrame,
|
|
63
|
+
serverFrame: Schema.Union([
|
|
64
|
+
EDAWebSocketWireHelloFrame,
|
|
65
|
+
eventsFrame,
|
|
66
|
+
EDAWebSocketWireHeartbeatFrame,
|
|
67
|
+
EDAWebSocketWireLaggedFrame,
|
|
68
|
+
EDAWebSocketWireErrorFrame
|
|
69
|
+
])
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
makeEDAWebSocketDomainSchemas(EventEnvelope);
|
|
73
|
+
const makeEDAWebSocketWireProtocolFromEventSchema = (event) => {
|
|
74
|
+
const domain = makeEDAWebSocketDomainSchemas(event);
|
|
75
|
+
const encodeDomainServerFrame = Schema.encodeSync(domain.serverFrame);
|
|
76
|
+
const encodeUnknownDomainServerFrame = Schema.encodeUnknownSync(domain.serverFrame);
|
|
77
|
+
const encodeServerFrame = (frame) => JSON.stringify(encodeDomainServerFrame(frame));
|
|
78
|
+
return {
|
|
79
|
+
domain,
|
|
80
|
+
wire: {
|
|
81
|
+
event: Schema.toEncoded(domain.event),
|
|
82
|
+
positionedEvent: Schema.toEncoded(domain.positionedEvent),
|
|
83
|
+
eventsFrame: Schema.toEncoded(domain.eventsFrame),
|
|
84
|
+
serverFrame: Schema.toEncoded(domain.serverFrame),
|
|
85
|
+
clientFrame: EDAWebSocketWireClientFrame
|
|
86
|
+
},
|
|
87
|
+
encodeServerFrame,
|
|
88
|
+
host: { encodeServerFrame: (frame) => JSON.stringify(encodeUnknownDomainServerFrame(frame)) }
|
|
73
89
|
};
|
|
74
90
|
};
|
|
75
91
|
/** Strict framework-only protocol used when an app registers no custom events. */
|
|
@@ -78,8 +94,9 @@ const edaFrameworkWebSocketWireProtocol = makeEDAWebSocketWireProtocolFromEventS
|
|
|
78
94
|
* Bind the generic EDA WebSocket transport to one app's custom event schema.
|
|
79
95
|
*
|
|
80
96
|
* Framework durable and ephemeral events are included automatically. Future EDA
|
|
81
|
-
* apps register only their custom events
|
|
82
|
-
*
|
|
97
|
+
* apps register only their custom events. Servers use the returned domain schemas
|
|
98
|
+
* and typed encoder; external consumers decode with the wire schemas. Pass the
|
|
99
|
+
* returned `host` adapter to the selected host package.
|
|
83
100
|
*/
|
|
84
101
|
const makeEDAWebSocketWireProtocol = (options) => makeEDAWebSocketWireProtocolFromEventSchema(Schema.Union([EDAFrameworkWebSocketEvent, options.appEvents]));
|
|
85
102
|
//#endregion
|