@moinulmoin/eden-runtime-cloudflare 0.5.0 → 0.7.0
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/NOTICE +0 -9
- package/dist/eden-eve-host-worker.mjs +626 -1803
- package/dist/eve-host-runtime.d.ts +119 -59
- package/dist/eve-host-runtime.js +530 -204
- package/dist/eve-host.d.ts +39 -51
- package/dist/eve-host.js +148 -165
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/package.json +3 -4
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DurableObject, WorkerEntrypoint } from "cloudflare:workers";
|
|
2
2
|
import { type EveHostContainerEnvironment, type EveHostForwardingMetadata, type EveHostReadinessEvidence, type EveScheduleCronEntry } from "./eve-host.js";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Carry archive limits. `chunkBytes` stays safely under the per-key limit;
|
|
5
|
+
* `maxBytes` caps the compressed archive (tests shrink both).
|
|
6
|
+
*/
|
|
7
|
+
export declare const EVE_HOST_CARRY_LIMITS: {
|
|
8
|
+
chunkBytes: number;
|
|
9
|
+
maxBytes: number;
|
|
10
|
+
};
|
|
4
11
|
/** The deployment's single SQLite-backed Workflow World. */
|
|
5
12
|
export declare class EdenWorldDurableObject {
|
|
6
13
|
private readonly core;
|
|
@@ -9,13 +16,16 @@ export declare class EdenWorldDurableObject {
|
|
|
9
16
|
alarm(): Promise<void>;
|
|
10
17
|
}
|
|
11
18
|
/**
|
|
12
|
-
* Delivers the container's own HTTPS requests to its public workers.dev
|
|
13
|
-
* back into the
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
+
* Delivers the container's own HTTPS requests to its public workers.dev
|
|
20
|
+
* origin back into the deployment without crossing the public edge. The
|
|
21
|
+
* Workflow local World posts queue deliveries to `WORKFLOW_LOCAL_BASE_URL`,
|
|
22
|
+
* which must remain the public origin so Eve's externally visible callback
|
|
23
|
+
* URLs stay correct; the DO registers an outbound-HTTPS intercept for that
|
|
24
|
+
* hostname aimed at `EveHostLoopback`, and this function routes the request:
|
|
25
|
+
* non-public hosts egress plainly, `/__eden/world/rpc` reaches the World
|
|
26
|
+
* Durable Object, and everything else re-enters the container over the
|
|
27
|
+
* internal port so the public Worker path can keep refusing the
|
|
28
|
+
* unauthenticated queue endpoints.
|
|
19
29
|
*/
|
|
20
30
|
export declare function routeEveOutboundRequest(request: Request, env: EveHostContainerEnvironment): Promise<Response>;
|
|
21
31
|
/**
|
|
@@ -24,68 +34,118 @@ export declare function routeEveOutboundRequest(request: Request, env: EveHostCo
|
|
|
24
34
|
* package's public declaration surface, so plain-Node consumers never load
|
|
25
35
|
* `cloudflare:workers`-dependent code.
|
|
26
36
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
/**
|
|
38
|
+
* The WorkerEntrypoint the container's intercepted outbound HTTPS traffic is
|
|
39
|
+
* delivered to (registered by `EveHostDurableContainer` right after every
|
|
40
|
+
* `ctx.container.start()`). Props carry the DO instance name because
|
|
41
|
+
* entrypoint props cannot hold a Fetcher.
|
|
42
|
+
*/
|
|
43
|
+
export declare class EveHostLoopback extends WorkerEntrypoint<EveHostContainerEnvironment> {
|
|
44
|
+
fetch(request: Request): Promise<Response>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The Eve host Durable Object. It drives `ctx.container` directly: the
|
|
48
|
+
* image is selected at `start()` from this Worker version's `images.eve`
|
|
49
|
+
* entry, the writable filesystem is preserved across sleep via a container
|
|
50
|
+
* snapshot, and an update restarts the instance when `inspect()` shows the
|
|
51
|
+
* running image predates the configured one.
|
|
52
|
+
*/
|
|
53
|
+
export declare class EveHostDurableContainer extends DurableObject<EveHostContainerEnvironment> {
|
|
54
|
+
/** Evidence is cached only while the container it was proven on keeps running. */
|
|
38
55
|
private readinessEvidence;
|
|
56
|
+
/** True once the running container's image was proven to equal `images.eve`. */
|
|
57
|
+
private imageVerified;
|
|
39
58
|
/**
|
|
40
59
|
* Bumped whenever the Container stops or is reset. Readiness work captures
|
|
41
|
-
* the epoch it started under and may only
|
|
42
|
-
*
|
|
60
|
+
* the epoch it started under and may only cache evidence if no stop
|
|
61
|
+
* happened in between.
|
|
43
62
|
*/
|
|
44
63
|
private readinessEpoch;
|
|
64
|
+
private monitorAttached;
|
|
65
|
+
/** Serializes sandbox-session carry-outs on this Durable Object instance. */
|
|
66
|
+
private carryOutQueue;
|
|
67
|
+
/** True only while the last start was fresh from `images.eve`, not a snapshot. */
|
|
68
|
+
private pendingCarryRestore;
|
|
69
|
+
/** Shared single-flight carry restore for the current container generation. */
|
|
70
|
+
private carryRestorePromise;
|
|
71
|
+
private readonly envVars;
|
|
72
|
+
private readonly sleepAfterMs;
|
|
45
73
|
private readonly readiness;
|
|
46
|
-
constructor(ctx:
|
|
74
|
+
constructor(ctx: DurableObjectState, env: EveHostContainerEnvironment);
|
|
75
|
+
private containerRuntime;
|
|
76
|
+
/** Container lifetime the platform keeps after the DO goes inactive: long
|
|
77
|
+
* enough for the idle alarm to snapshot first, within Cloudflare's 6 h cap. */
|
|
78
|
+
private get inactivityTimeoutMs();
|
|
79
|
+
private attachMonitor;
|
|
80
|
+
private recordContainerStopped;
|
|
81
|
+
/** Routes the container's own requests to its public origin back inside. */
|
|
82
|
+
private registerLoopbackIntercept;
|
|
47
83
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* stale Durable Object still detects the update because the header is
|
|
52
|
-
* stamped by new Worker code, not this code's environment.
|
|
53
|
-
*
|
|
54
|
-
* DO-managed Container instances are excluded from the application's fleet
|
|
55
|
-
* rollout — the image is only re-selected on the next
|
|
56
|
-
* `ctx.container.start()` — so an update must stop the instance itself.
|
|
57
|
-
* A missing marker means the running image cannot be trusted, so the
|
|
58
|
-
* container is restarted too (first update from runtimes that predate the
|
|
59
|
-
* marker). Restarts are rate-limited because Cloudflare activates a new
|
|
60
|
-
* Worker before the image rollout lands; starting in that window would
|
|
61
|
-
* re-launch the *old* image, so the deployment marker is only recorded
|
|
62
|
-
* after `inspect()` proves the running image is the expected one.
|
|
84
|
+
* Records request activity and arms the sleep alarm at
|
|
85
|
+
* `lastActivityAt + sleepAfter`. The alarm — not the inactivity timeout —
|
|
86
|
+
* is what snapshots the writable filesystem before the container stops.
|
|
63
87
|
*/
|
|
64
|
-
private
|
|
65
|
-
private containerServesImage;
|
|
88
|
+
private touchActivity;
|
|
66
89
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* When the Worker stamps no image, the marker is recorded unverified,
|
|
73
|
-
* matching pre-drift behavior.
|
|
90
|
+
* Starts the container when it is not running. A stored workspace snapshot
|
|
91
|
+
* is restored only when it was captured from the exact image this Worker
|
|
92
|
+
* version configures — restoring an older snapshot silently runs the
|
|
93
|
+
* previous image — so after an image update the container starts fresh and
|
|
94
|
+
* the readiness path restores the carried sandbox sessions instead.
|
|
74
95
|
*/
|
|
75
|
-
private
|
|
76
|
-
|
|
96
|
+
private ensureContainerStarted;
|
|
97
|
+
/**
|
|
98
|
+
* Replaces the running container when it still serves a pre-update image:
|
|
99
|
+
* this Worker version's `images.eve` is selected at `start()`, so an
|
|
100
|
+
* in-place update must stop the stale instance itself. `inspect()` reports
|
|
101
|
+
* an empty image for a snapshot-restored container, so the image recorded
|
|
102
|
+
* at start stands in for it.
|
|
103
|
+
*/
|
|
104
|
+
private reconcileRunningImage;
|
|
105
|
+
/**
|
|
106
|
+
* Streams `/workspace/.eve/sandbox-cache/just-bash/sessions` — every
|
|
107
|
+
* conversation's sandbox files and metadata — into Durable Object storage,
|
|
108
|
+
* so a fresh container started by an image update can restore them. Not
|
|
109
|
+
* carried: templates and the rest of `/workspace`, which come from the new
|
|
110
|
+
* image. One carry runs at a time on this Durable Object; a failure never
|
|
111
|
+
* blocks the destroy that follows and leaves the previous carry intact.
|
|
112
|
+
*/
|
|
113
|
+
private carrySandboxSessionsOut;
|
|
114
|
+
private carrySandboxSessionsOutNow;
|
|
115
|
+
/**
|
|
116
|
+
* Single restore per fresh container generation, shared by every
|
|
117
|
+
* concurrent readiness caller: the first caller starts it, everyone awaits
|
|
118
|
+
* the same promise, and no request is forwarded before it settles.
|
|
119
|
+
*/
|
|
120
|
+
private restoreCarriedSandboxSessions;
|
|
121
|
+
/**
|
|
122
|
+
* Extracts the carried sandbox sessions into a container that started
|
|
123
|
+
* fresh from `images.eve`. The archive streams chunk by chunk from Durable
|
|
124
|
+
* Object storage through exec stdin, so it never sits in isolate memory. A
|
|
125
|
+
* failure is logged and swallowed: the agent still serves, only the
|
|
126
|
+
* carried files are missing.
|
|
127
|
+
*/
|
|
128
|
+
private carrySandboxSessionsIn;
|
|
129
|
+
ensureEveReady(signal?: AbortSignal): Promise<EveHostReadinessEvidence>;
|
|
77
130
|
fetch(request: Request): Promise<Response>;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
131
|
+
/**
|
|
132
|
+
* Queue deliveries and loopback traffic enter here: same readiness and
|
|
133
|
+
* forwarding as `fetch` without the deployment-header echo rules (the
|
|
134
|
+
* loopback path is not a deployment-health signal).
|
|
135
|
+
*/
|
|
136
|
+
loopbackFetch(request: Request): Promise<Response>;
|
|
137
|
+
private forwardToEve;
|
|
138
|
+
/**
|
|
139
|
+
* The idle-sleep path: once the container has been quiet for `sleepAfter`,
|
|
140
|
+
* snapshot the writable filesystem (so `/workspace` survives the sleep)
|
|
141
|
+
* and destroy the instance. A snapshot failure retries up to
|
|
142
|
+
* `EVE_HOST_SNAPSHOT_MAX_ATTEMPTS` times, then destroys anyway so billing
|
|
143
|
+
* for the running container stops.
|
|
144
|
+
*/
|
|
145
|
+
alarm(): Promise<void>;
|
|
84
146
|
}
|
|
85
|
-
export type EveHostWorkerEnvironment = EveHostContainerEnvironment;
|
|
86
147
|
export interface EveHostWorkerOptions extends EveHostForwardingMetadata {
|
|
87
148
|
readonly workerName: string;
|
|
88
|
-
readonly containerBindingName: string;
|
|
89
149
|
readonly stableContainerInstanceName: string;
|
|
90
150
|
readonly schedules?: readonly EveScheduleCronEntry[];
|
|
91
151
|
}
|
|
@@ -94,11 +154,11 @@ export interface EveHostWorkerOptions extends EveHostForwardingMetadata {
|
|
|
94
154
|
* declarations never reference provider ambient types.
|
|
95
155
|
*/
|
|
96
156
|
export interface EveHostWorkerHandler {
|
|
97
|
-
fetch(request: Request, env:
|
|
157
|
+
fetch(request: Request, env: EveHostContainerEnvironment): Promise<Response>;
|
|
98
158
|
scheduled?(event: {
|
|
99
159
|
readonly cron: string;
|
|
100
160
|
readonly scheduledTime: number;
|
|
101
|
-
}, env:
|
|
161
|
+
}, env: EveHostContainerEnvironment, ctx: {
|
|
102
162
|
waitUntil(task: Promise<unknown>): void;
|
|
103
163
|
}): void;
|
|
104
164
|
}
|