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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +28 -27
  3. package/dist/{command-queues-CQ9cwRP7.d.ts → command-queues-CV7O-51r.d.ts} +7 -6
  4. package/dist/{compaction-1LSZR944.d.ts → compaction-zbvLREI8.d.ts} +8 -6
  5. package/dist/context-projection-n6Rdup0N.d.ts +140 -0
  6. package/dist/{core-Hv3cFydL.d.ts → core-CYT6DBaS.d.ts} +2 -2
  7. package/dist/domain/command-queues.d.ts +1 -1
  8. package/dist/domain/context-projection.d.ts +2 -0
  9. package/dist/domain/context-projection.js +32 -0
  10. package/dist/domain/context-projection.js.map +1 -0
  11. package/dist/domain/message-transcript.d.ts +1 -1
  12. package/dist/domain/reduced-state-schema.d.ts +2 -0
  13. package/dist/domain/reduced-state-schema.js +2 -1
  14. package/dist/domain/reduced-state-schema.js.map +1 -1
  15. package/dist/domain/reduced-state.d.ts +1 -1
  16. package/dist/domain/reduced-state.js +1 -1
  17. package/dist/{durable-DlScwmCy.d.ts → durable-B7M6TD_0.d.ts} +341 -2
  18. package/dist/{durable-C3Rz7kg3.js → durable-DsV9PxZC.js} +13 -2
  19. package/dist/durable-DsV9PxZC.js.map +1 -0
  20. package/dist/{keep-alive-DYDsH6qN.d.ts → event-factory-CLJcyymV.d.ts} +5 -29
  21. package/dist/{keep-alive-p8dIcSVy.js → event-factory-tcpLgdMN.js} +3 -10
  22. package/dist/event-factory-tcpLgdMN.js.map +1 -0
  23. package/dist/host/websocket-protocol.d.ts +229 -0
  24. package/dist/host/websocket-protocol.js +99 -0
  25. package/dist/host/websocket-protocol.js.map +1 -0
  26. package/dist/host/websocket-wire.d.ts +1 -1
  27. package/dist/host/websocket-wire.js +2 -2
  28. package/dist/host/websocket-wire.js.map +1 -1
  29. package/dist/{id-generator-C2Q15uZM.d.ts → id-generator-Ckl8_XWW.d.ts} +2 -2
  30. package/dist/index.d.ts +4 -4
  31. package/dist/index.js +2 -2
  32. package/dist/keep-alive-Chl5SJxy.d.ts +29 -0
  33. package/dist/{message-transcript-BCHdHAe2.d.ts → message-transcript-DiOPBY3l.d.ts} +3 -3
  34. package/dist/{prompt-projector-DimXJPOJ.d.ts → prompt-projector-C1IbkHr0.d.ts} +5 -5
  35. package/dist/{reduced-state-C4nVVzz9.js → reduced-state-TMi7ISla.js} +20 -4
  36. package/dist/reduced-state-TMi7ISla.js.map +1 -0
  37. package/dist/{reducer-registry-C0svUa63.d.ts → reducer-registry-CjSJBPKo.d.ts} +2 -2
  38. package/dist/{runtime-DcdPOEuE.d.ts → runtime-DOgmAKsO.d.ts} +7 -6
  39. package/dist/services/compaction.d.ts +1 -1
  40. package/dist/services/compaction.js +4 -3
  41. package/dist/services/compaction.js.map +1 -1
  42. package/dist/services/id-generator.d.ts +1 -1
  43. package/dist/services/keep-alive.d.ts +2 -0
  44. package/dist/services/keep-alive.js +13 -0
  45. package/dist/services/keep-alive.js.map +1 -0
  46. package/dist/services/prompt-projector.d.ts +1 -1
  47. package/dist/services/reducer-registry.d.ts +1 -1
  48. package/dist/services/runtime-layer.d.ts +58 -0
  49. package/dist/services/runtime-layer.js +42 -0
  50. package/dist/services/runtime-layer.js.map +1 -0
  51. package/dist/services/runtime.d.ts +1 -1
  52. package/dist/services/runtime.js +4 -3
  53. package/dist/services/runtime.js.map +1 -1
  54. package/dist/services/session-query.d.ts +1 -1
  55. package/dist/services/session-query.js +76 -1
  56. package/dist/services/session-query.js.map +1 -0
  57. package/dist/services/session-state.d.ts +2 -0
  58. package/dist/services/session-state.js +2 -0
  59. package/dist/services/session-store.d.ts +2 -2
  60. package/dist/services/session-store.js +181 -2
  61. package/dist/services/session-store.js.map +1 -0
  62. package/dist/services/sink-checkpoint-store.d.ts +2 -0
  63. package/dist/services/sink-checkpoint-store.js +49 -0
  64. package/dist/services/sink-checkpoint-store.js.map +1 -0
  65. package/dist/services/sink-registry.d.ts +1 -1
  66. package/dist/services/sink-registry.js +1 -1
  67. package/dist/services/tool-registry.d.ts +1 -1
  68. package/dist/services/websocket-subscriber.d.ts +54 -0
  69. package/dist/services/websocket-subscriber.js +190 -0
  70. package/dist/services/websocket-subscriber.js.map +1 -0
  71. package/dist/session-query-C-C4m1eq.d.ts +38 -0
  72. package/dist/{session-query-hxfujxUH.d.ts → session-state-CjOSvWbe.d.ts} +134 -42
  73. package/dist/{session-query-Cbf-e0rG.js → session-state-SStf0KUo.js} +18 -77
  74. package/dist/session-state-SStf0KUo.js.map +1 -0
  75. package/dist/{session-store-D2Ore1QC.d.ts → session-store-DZZUffUy.d.ts} +5 -94
  76. package/dist/sink-checkpoint-store-BZmQFTRE.d.ts +40 -0
  77. package/dist/{sink-registry-BziFpxoE.d.ts → sink-registry-Cf79ICdW.d.ts} +11 -40
  78. package/dist/{sink-registry-CFC6xjsN.js → sink-registry-D13eUO_c.js} +9 -47
  79. package/dist/sink-registry-D13eUO_c.js.map +1 -0
  80. package/dist/testkit/layers.d.ts +14 -11
  81. package/dist/testkit/layers.js +8 -5
  82. package/dist/testkit/layers.js.map +1 -1
  83. package/dist/{tool-registry-CcnkAAQK.d.ts → tool-registry-B7Wona6N.d.ts} +3 -3
  84. package/dist/types/core.d.ts +1 -1
  85. package/dist/types/core.js +1 -1
  86. package/dist/types/core.js.map +1 -1
  87. package/dist/types/events/durable.d.ts +2 -2
  88. package/dist/types/events/durable.js +2 -2
  89. package/dist/types/events.d.ts +2 -2
  90. package/dist/types/events.js +2 -2
  91. package/dist/{websocket-wire-D3tLrhe2.d.ts → websocket-wire-QD2SquQE.d.ts} +74 -2
  92. package/docs/message-steering.md +1 -1
  93. package/docs/releasing.md +42 -24
  94. package/docs/spec.md +11 -11
  95. package/docs/websocket-protocol.md +4 -4
  96. package/package.json +55 -35
  97. package/dist/durable-C3Rz7kg3.js.map +0 -1
  98. package/dist/durable-object-runtime-CiMKxGs6.d.ts +0 -257
  99. package/dist/durable-object-runtime-wKiqaAt2.js +0 -1494
  100. package/dist/durable-object-runtime-wKiqaAt2.js.map +0 -1
  101. package/dist/durable-object-storage-Czy7IPrh.d.ts +0 -41
  102. package/dist/host/durable-object-runtime.d.ts +0 -2
  103. package/dist/host/durable-object-runtime.js +0 -2
  104. package/dist/host/durable-object-storage.d.ts +0 -2
  105. package/dist/host/durable-object-storage.js +0 -0
  106. package/dist/host/durable-object.d.ts +0 -83
  107. package/dist/host/durable-object.js +0 -191
  108. package/dist/host/durable-object.js.map +0 -1
  109. package/dist/keep-alive-p8dIcSVy.js.map +0 -1
  110. package/dist/reduced-state-C4nVVzz9.js.map +0 -1
  111. package/dist/session-query-Cbf-e0rG.js.map +0 -1
  112. package/dist/session-store-pYxQW9qh.js +0 -214
  113. package/dist/session-store-pYxQW9qh.js.map +0 -1
  114. package/dist/sink-registry-CFC6xjsN.js.map +0 -1
  115. package/examples/001-no-tools/README.md +0 -65
  116. package/examples/001-no-tools/worker.ts +0 -79
  117. package/examples/002-slack-bridge/README.md +0 -134
  118. package/examples/002-slack-bridge/events.ts +0 -115
  119. package/examples/002-slack-bridge/reducer.ts +0 -216
  120. package/examples/002-slack-bridge/scenario.test.ts +0 -223
  121. package/examples/002-slack-bridge/sinks.ts +0 -109
  122. package/examples/002-slack-bridge/worker.ts +0 -140
  123. package/examples/003-sandbox-lifecycle/README.md +0 -78
  124. package/examples/003-sandbox-lifecycle/events.ts +0 -203
  125. package/examples/003-sandbox-lifecycle/reducer.ts +0 -305
  126. package/examples/003-sandbox-lifecycle/scenario.test.ts +0 -202
  127. package/examples/_shared/event-id.ts +0 -12
  128. package/examples/_shared/http.ts +0 -27
  129. package/examples/_shared/openai.ts +0 -33
@@ -1,140 +0,0 @@
1
- import * as Prompt from "effect/unstable/ai/Prompt";
2
-
3
- import { CommandIdempotencyKey, SubmitMessageCommand } from "../../src/types/commands";
4
- import { SessionId } from "../../src/types/core";
5
- import { UnixEpochMillis } from "../../src/types/events";
6
- import { makeRootEDATraceMetadata } from "../../src/types/tracing";
7
- import {
8
- EDASessionDurableObject,
9
- getEDASessionDurableObjectByName,
10
- } from "../../src/host/durable-object";
11
- import { mintExampleEventId } from "../_shared/event-id";
12
- import { json, parseJsonObject, pathParam, requiredString } from "../_shared/http";
13
- import { makeExampleOpenAiOptions, type ExampleOpenAiEnv } from "../_shared/openai";
14
- import {
15
- SlackChannelId,
16
- SlackEventId,
17
- SlackEvents,
18
- SlackTeamId,
19
- SlackThreadTs,
20
- SlackUserId,
21
- } from "./events";
22
- import { SlackBridgeReducer } from "./reducer";
23
- import { loggingSlackClient, makeSlackReplySink } from "./sinks";
24
-
25
- /** Bindings used by the Slack bridge EDA example Worker. */
26
- export interface SlackBridgeEDAEnv extends ExampleOpenAiEnv {
27
- readonly SlackBridgeEDASession: DurableObjectNamespace<SlackBridgeEDASession>;
28
- }
29
-
30
- /** Concrete session object with Slack reducer + reply sink installed. */
31
- export class SlackBridgeEDASession extends EDASessionDurableObject<SlackBridgeEDAEnv> {
32
- constructor(ctx: DurableObjectState, env: SlackBridgeEDAEnv) {
33
- super(ctx, env, {
34
- ...makeExampleOpenAiOptions(env),
35
- reducers: [SlackBridgeReducer],
36
- sinks: [makeSlackReplySink(loggingSlackClient)],
37
- });
38
- }
39
- }
40
-
41
- /**
42
- * Minimal Slack-ish facade.
43
- *
44
- * The important move is submitting `[command, SlackMessageReceived]` together:
45
- * one durable admission boundary captures both the model input and its Slack
46
- * identity/idempotency metadata.
47
- */
48
- export default {
49
- async fetch(request, env): Promise<Response> {
50
- const url = new URL(request.url);
51
-
52
- const rawSlackSessionId = pathParam(url.pathname, /^\/sessions\/([^/]+)\/slack\/events\/?$/);
53
- if (request.method === "POST" && rawSlackSessionId !== null) {
54
- const body = await parseJsonObject(request);
55
- const parsed = parseSlackEvent(body);
56
- if ("error" in parsed) {
57
- return json({ error: parsed.error }, 400);
58
- }
59
-
60
- const sessionId = SessionId.make(rawSlackSessionId);
61
- const session = getEDASessionDurableObjectByName(env.SlackBridgeEDASession, sessionId);
62
- const idempotencyKey = CommandIdempotencyKey.make(`slack:event:${parsed.slackEventId}`);
63
- const trace = makeRootEDATraceMetadata();
64
-
65
- const committed = await session.submitBatch({
66
- sessionId,
67
- trace,
68
- items: [
69
- new SubmitMessageCommand({
70
- idempotencyKey,
71
- disposition: "queue",
72
- content: [Prompt.textPart({ text: parsed.text })],
73
- }),
74
- SlackEvents.messageReceived({
75
- relatedCommandIdempotencyKey: idempotencyKey,
76
- teamId: SlackTeamId.make(parsed.teamId),
77
- channelId: SlackChannelId.make(parsed.channelId),
78
- threadTs: SlackThreadTs.make(parsed.threadTs),
79
- slackEventId: SlackEventId.make(parsed.slackEventId),
80
- slackUserId: SlackUserId.make(parsed.slackUserId),
81
- text: parsed.text,
82
- createdAtMs: UnixEpochMillis.make(Date.now()),
83
- eventId: await mintExampleEventId(),
84
- sessionId,
85
- }),
86
- ],
87
- });
88
-
89
- return json({ committed, messages: await session.messages({ sessionId, trace }) }, 202);
90
- }
91
-
92
- const rawMessagesSessionId = pathParam(url.pathname, /^\/sessions\/([^/]+)\/messages\/?$/);
93
- if (request.method === "GET" && rawMessagesSessionId !== null) {
94
- const sessionId = SessionId.make(rawMessagesSessionId);
95
- const session = getEDASessionDurableObjectByName(env.SlackBridgeEDASession, sessionId);
96
- return json(await session.messages({ sessionId, trace: makeRootEDATraceMetadata() }));
97
- }
98
-
99
- return json(
100
- {
101
- error: "Use POST /sessions/:sessionId/slack/events or GET /sessions/:sessionId/messages",
102
- },
103
- 404,
104
- );
105
- },
106
- } satisfies ExportedHandler<SlackBridgeEDAEnv>;
107
-
108
- interface ParsedSlackEvent {
109
- readonly teamId: string;
110
- readonly channelId: string;
111
- readonly threadTs: string;
112
- readonly slackEventId: string;
113
- readonly slackUserId: string;
114
- readonly text: string;
115
- }
116
-
117
- const parseSlackEvent = (
118
- body: Record<string, unknown>,
119
- ): ParsedSlackEvent | { readonly error: string } => {
120
- const teamId = requiredString(body, "teamId");
121
- const channelId = requiredString(body, "channelId");
122
- const threadTs = requiredString(body, "threadTs");
123
- const slackEventId = requiredString(body, "slackEventId");
124
- const slackUserId = requiredString(body, "slackUserId");
125
- const text = requiredString(body, "text");
126
- if (
127
- teamId === undefined ||
128
- channelId === undefined ||
129
- threadTs === undefined ||
130
- slackEventId === undefined ||
131
- slackUserId === undefined ||
132
- text === undefined
133
- ) {
134
- return {
135
- error:
136
- "Expected JSON body with teamId, channelId, threadTs, slackEventId, slackUserId, and text",
137
- };
138
- }
139
- return { teamId, channelId, threadTs, slackEventId, slackUserId, text };
140
- };
@@ -1,78 +0,0 @@
1
- # 003 — Sandbox Lifecycle
2
-
3
- This example shows the design space where EDA becomes much more than chat persistence.
4
-
5
- A coding agent session often owns product state tightly coupled to the agent run:
6
-
7
- - a sandbox starts;
8
- - commands run inside it;
9
- - a preview URL appears;
10
- - a human approval is requested;
11
- - the tool finishes;
12
- - the sandbox is stopped later.
13
-
14
- In EDA, those are not side-channel callbacks. They are durable app events in the same ordered session history as the framework tool and message lifecycle.
15
-
16
- ## The sequence
17
-
18
- ```text
19
- seq event projection effect
20
- --- ------------------------------------------------ -------------------------------
21
- 1 effect-durable-agent/ToolCallCreated tool card appears
22
- 2 example.sandbox/SandboxStarting sandbox status: starting
23
- 3 example.sandbox/SandboxStarted sandbox status: running
24
- 4 example.sandbox/CommandStarted command row starts
25
- 5 example.sandbox/CommandCompleted command row gets wallClockTimeMs
26
- 6 example.sandbox/PreviewReady preview card gets URL
27
- 7 example.sandbox/ApprovalRequested approval card waits
28
- 8 example.sandbox/ApprovalGranted approval card resolves
29
- 9 effect-durable-agent/ToolCallCompleted tool card completes
30
- 10 example.sandbox/SandboxStopped sandbox status: stopped
31
- ```
32
-
33
- ## What to notice
34
-
35
- ### 1. Framework state and app state reduce together
36
-
37
- `reducer.ts` folds both EDA framework events and sandbox app events:
38
-
39
- ```text
40
- ToolCallCreated
41
- SandboxStarting
42
- SandboxStarted
43
- CommandStarted
44
- CommandCompleted
45
- PreviewReady
46
- ApprovalRequested
47
- ApprovalGranted
48
- ToolCallCompleted
49
- SandboxStopped
50
- ```
51
-
52
- That one reducer derives the UI model: active sandbox, running command, last command timing, preview URL, approval state, tool card status, and stop reason.
53
-
54
- ### 2. SSR handoff is just reducer math
55
-
56
- `scenario.test.ts` demonstrates the handoff directly:
57
-
58
- ```text
59
- server renders state through seq N
60
- client receives state_N
61
- client requests events where seq > N
62
- client reduces the suffix
63
- client converges to the same state as a full replay
64
- ```
65
-
66
- No separate sandbox sync protocol is needed. The sandbox lifecycle is already part of the same event sequence as the agent lifecycle.
67
-
68
- ### 3. Recovery has a real source of truth
69
-
70
- If the process restarts, EDA can replay the durable session log and recover the committed facts. The reducer knows whether the sandbox started, which command finished, whether approval was granted, and where the tool lifecycle ended.
71
-
72
- ## Files
73
-
74
- - `events.ts` — sandbox/preview/approval durable event schemas.
75
- - `reducer.ts` — pure UI/app projection over framework + app events.
76
- - `scenario.test.ts` — executable reducer and SSR handoff scenarios.
77
-
78
- This example intentionally has no Worker facade. It is about the state-machine model itself, without HTTP or provider plumbing getting in the way.
@@ -1,203 +0,0 @@
1
- import * as Schema from "effect/Schema";
2
-
3
- import { EventId, SessionId, ToolCallId } from "../../src/types/core";
4
- import {
5
- DurableEventEnvelope,
6
- EventNamespace,
7
- EventType,
8
- NonNegativeInt,
9
- UnixEpochMillis,
10
- makeRootEDAEventTrace,
11
- schemaV1,
12
- } from "../../src/types/events";
13
-
14
- export const sandboxLifecycleNamespace = EventNamespace.make("example.sandbox");
15
-
16
- export const sandboxStartingEventType = EventType.make("SandboxStarting");
17
- export const sandboxStartedEventType = EventType.make("SandboxStarted");
18
- export const sandboxCommandStartedEventType = EventType.make("CommandStarted");
19
- export const sandboxCommandCompletedEventType = EventType.make("CommandCompleted");
20
- export const previewReadyEventType = EventType.make("PreviewReady");
21
- export const approvalRequestedEventType = EventType.make("ApprovalRequested");
22
- export const approvalGrantedEventType = EventType.make("ApprovalGranted");
23
- export const sandboxStoppedEventType = EventType.make("SandboxStopped");
24
-
25
- export const SandboxId = Schema.NonEmptyString.pipe(Schema.brand("SandboxId"));
26
- export type SandboxId = typeof SandboxId.Type;
27
-
28
- export const SandboxCommandId = Schema.NonEmptyString.pipe(Schema.brand("SandboxCommandId"));
29
- export type SandboxCommandId = typeof SandboxCommandId.Type;
30
-
31
- export const PreviewUrl = Schema.NonEmptyString.pipe(Schema.brand("PreviewUrl"));
32
- export type PreviewUrl = typeof PreviewUrl.Type;
33
-
34
- export const ApprovalAction = Schema.NonEmptyString.pipe(Schema.brand("ApprovalAction"));
35
- export type ApprovalAction = typeof ApprovalAction.Type;
36
-
37
- export const ApproverId = Schema.NonEmptyString.pipe(Schema.brand("ApproverId"));
38
- export type ApproverId = typeof ApproverId.Type;
39
-
40
- export const SandboxStartingPayload = Schema.Struct({ toolCallId: ToolCallId });
41
- export type SandboxStartingPayload = typeof SandboxStartingPayload.Type;
42
-
43
- export const SandboxStartedPayload = Schema.Struct({
44
- toolCallId: ToolCallId,
45
- sandboxId: SandboxId,
46
- });
47
- export type SandboxStartedPayload = typeof SandboxStartedPayload.Type;
48
-
49
- export const SandboxCommandStartedPayload = Schema.Struct({
50
- sandboxId: SandboxId,
51
- commandId: SandboxCommandId,
52
- command: Schema.NonEmptyString,
53
- });
54
- export type SandboxCommandStartedPayload = typeof SandboxCommandStartedPayload.Type;
55
-
56
- export const SandboxCommandCompletedPayload = Schema.Struct({
57
- sandboxId: SandboxId,
58
- commandId: SandboxCommandId,
59
- wallClockTimeMs: NonNegativeInt,
60
- });
61
- export type SandboxCommandCompletedPayload = typeof SandboxCommandCompletedPayload.Type;
62
-
63
- export const PreviewReadyPayload = Schema.Struct({
64
- sandboxId: SandboxId,
65
- url: PreviewUrl,
66
- });
67
- export type PreviewReadyPayload = typeof PreviewReadyPayload.Type;
68
-
69
- export const ApprovalRequestedPayload = Schema.Struct({
70
- sandboxId: SandboxId,
71
- action: ApprovalAction,
72
- });
73
- export type ApprovalRequestedPayload = typeof ApprovalRequestedPayload.Type;
74
-
75
- export const ApprovalGrantedPayload = Schema.Struct({
76
- sandboxId: SandboxId,
77
- action: ApprovalAction,
78
- approverId: ApproverId,
79
- });
80
- export type ApprovalGrantedPayload = typeof ApprovalGrantedPayload.Type;
81
-
82
- export const SandboxStoppedPayload = Schema.Struct({
83
- sandboxId: SandboxId,
84
- reason: Schema.NonEmptyString,
85
- });
86
- export type SandboxStoppedPayload = typeof SandboxStoppedPayload.Type;
87
-
88
- interface AppEventContext {
89
- readonly createdAtMs: UnixEpochMillis;
90
- readonly eventId: EventId;
91
- readonly sessionId: SessionId;
92
- }
93
-
94
- export const SandboxEvents = {
95
- starting: (input: AppEventContext & SandboxStartingPayload): DurableEventEnvelope => {
96
- const { createdAtMs, eventId, sessionId, ...payload } = input;
97
- return sandboxDurableEvent({
98
- createdAtMs,
99
- eventId,
100
- payload: SandboxStartingPayload.make(payload),
101
- sessionId,
102
- type: sandboxStartingEventType,
103
- });
104
- },
105
-
106
- started: (input: AppEventContext & SandboxStartedPayload): DurableEventEnvelope => {
107
- const { createdAtMs, eventId, sessionId, ...payload } = input;
108
- return sandboxDurableEvent({
109
- createdAtMs,
110
- eventId,
111
- payload: SandboxStartedPayload.make(payload),
112
- sessionId,
113
- type: sandboxStartedEventType,
114
- });
115
- },
116
-
117
- commandStarted: (input: AppEventContext & SandboxCommandStartedPayload): DurableEventEnvelope => {
118
- const { createdAtMs, eventId, sessionId, ...payload } = input;
119
- return sandboxDurableEvent({
120
- createdAtMs,
121
- eventId,
122
- payload: SandboxCommandStartedPayload.make(payload),
123
- sessionId,
124
- type: sandboxCommandStartedEventType,
125
- });
126
- },
127
-
128
- commandCompleted: (
129
- input: AppEventContext & SandboxCommandCompletedPayload,
130
- ): DurableEventEnvelope => {
131
- const { createdAtMs, eventId, sessionId, ...payload } = input;
132
- return sandboxDurableEvent({
133
- createdAtMs,
134
- eventId,
135
- payload: SandboxCommandCompletedPayload.make(payload),
136
- sessionId,
137
- type: sandboxCommandCompletedEventType,
138
- });
139
- },
140
-
141
- previewReady: (input: AppEventContext & PreviewReadyPayload): DurableEventEnvelope => {
142
- const { createdAtMs, eventId, sessionId, ...payload } = input;
143
- return sandboxDurableEvent({
144
- createdAtMs,
145
- eventId,
146
- payload: PreviewReadyPayload.make(payload),
147
- sessionId,
148
- type: previewReadyEventType,
149
- });
150
- },
151
-
152
- approvalRequested: (input: AppEventContext & ApprovalRequestedPayload): DurableEventEnvelope => {
153
- const { createdAtMs, eventId, sessionId, ...payload } = input;
154
- return sandboxDurableEvent({
155
- createdAtMs,
156
- eventId,
157
- payload: ApprovalRequestedPayload.make(payload),
158
- sessionId,
159
- type: approvalRequestedEventType,
160
- });
161
- },
162
-
163
- approvalGranted: (input: AppEventContext & ApprovalGrantedPayload): DurableEventEnvelope => {
164
- const { createdAtMs, eventId, sessionId, ...payload } = input;
165
- return sandboxDurableEvent({
166
- createdAtMs,
167
- eventId,
168
- payload: ApprovalGrantedPayload.make(payload),
169
- sessionId,
170
- type: approvalGrantedEventType,
171
- });
172
- },
173
-
174
- stopped: (input: AppEventContext & SandboxStoppedPayload): DurableEventEnvelope => {
175
- const { createdAtMs, eventId, sessionId, ...payload } = input;
176
- return sandboxDurableEvent({
177
- createdAtMs,
178
- eventId,
179
- payload: SandboxStoppedPayload.make(payload),
180
- sessionId,
181
- type: sandboxStoppedEventType,
182
- });
183
- },
184
- };
185
-
186
- const sandboxDurableEvent = (input: {
187
- readonly createdAtMs: UnixEpochMillis;
188
- readonly eventId: EventId;
189
- readonly payload: unknown;
190
- readonly sessionId: SessionId;
191
- readonly type: EventType;
192
- }): DurableEventEnvelope =>
193
- DurableEventEnvelope.make({
194
- namespace: sandboxLifecycleNamespace,
195
- type: input.type,
196
- schemaVersion: schemaV1,
197
- durability: "durable",
198
- eventId: input.eventId,
199
- sessionId: input.sessionId,
200
- createdAtMs: input.createdAtMs,
201
- trace: makeRootEDAEventTrace(),
202
- payload: input.payload,
203
- });