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.
- package/CHANGELOG.md +9 -0
- package/README.md +28 -27
- package/dist/{command-queues-CQ9cwRP7.d.ts → command-queues-CV7O-51r.d.ts} +7 -6
- package/dist/{compaction-1LSZR944.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 +1 -1
- package/dist/host/websocket-wire.js +2 -2
- 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-DimXJPOJ.d.ts → prompt-projector-C1IbkHr0.d.ts} +5 -5
- 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-DcdPOEuE.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 +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-hxfujxUH.d.ts → session-state-CjOSvWbe.d.ts} +134 -42
- package/dist/{session-query-Cbf-e0rG.js → session-state-SStf0KUo.js} +18 -77
- 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-BziFpxoE.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-D3tLrhe2.d.ts → websocket-wire-QD2SquQE.d.ts} +74 -2
- package/docs/message-steering.md +1 -1
- package/docs/releasing.md +42 -24
- package/docs/spec.md +11 -11
- package/docs/websocket-protocol.md +4 -4
- package/package.json +55 -35
- package/dist/durable-C3Rz7kg3.js.map +0 -1
- package/dist/durable-object-runtime-CiMKxGs6.d.ts +0 -257
- package/dist/durable-object-runtime-wKiqaAt2.js +0 -1494
- package/dist/durable-object-runtime-wKiqaAt2.js.map +0 -1
- package/dist/durable-object-storage-Czy7IPrh.d.ts +0 -41
- package/dist/host/durable-object-runtime.d.ts +0 -2
- package/dist/host/durable-object-runtime.js +0 -2
- package/dist/host/durable-object-storage.d.ts +0 -2
- package/dist/host/durable-object-storage.js +0 -0
- package/dist/host/durable-object.d.ts +0 -83
- package/dist/host/durable-object.js +0 -191
- package/dist/host/durable-object.js.map +0 -1
- package/dist/keep-alive-p8dIcSVy.js.map +0 -1
- package/dist/reduced-state-C4nVVzz9.js.map +0 -1
- package/dist/session-query-Cbf-e0rG.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/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,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
|
-
});
|