@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
package/dist/eve-host.d.ts
CHANGED
|
@@ -2,10 +2,22 @@ export declare const EVE_HOST_DEFAULTS: {
|
|
|
2
2
|
readonly compatibilityDate: "2026-04-01";
|
|
3
3
|
readonly healthPath: "/eve/v1/health";
|
|
4
4
|
readonly internalPort: 8080;
|
|
5
|
-
readonly
|
|
6
|
-
readonly
|
|
7
|
-
readonly sleepAfter: "24h";
|
|
5
|
+
readonly instance: "standard-1";
|
|
6
|
+
readonly sleepAfter: "1h";
|
|
8
7
|
};
|
|
8
|
+
/**
|
|
9
|
+
* Cloudflare stops a container at most 6 hours after its Durable Object goes
|
|
10
|
+
* inactive (`setInactivityTimeout` rejects longer values). The idle-sleep
|
|
11
|
+
* alarm must fire before that so it can snapshot first, and the inactivity
|
|
12
|
+
* timeout is `sleepAfter` plus this margin.
|
|
13
|
+
*/
|
|
14
|
+
export declare const EVE_HOST_SLEEP_SNAPSHOT_MARGIN_MS: number;
|
|
15
|
+
export declare const EVE_HOST_MAX_SLEEP_AFTER_MS: number;
|
|
16
|
+
/**
|
|
17
|
+
* Parses a `sleepAfter` duration ("300ms", "30s", "15m", "1h", or a bare
|
|
18
|
+
* number of seconds) and enforces Cloudflare's inactivity ceiling.
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseEveSleepAfterMs(value: string): number;
|
|
9
21
|
export declare const EVE_SCHEDULE_WAKE_TRIGGER_CRON = "* * * * *";
|
|
10
22
|
/**
|
|
11
23
|
* How far ahead of a tick the every-minute wake trigger starts the Container.
|
|
@@ -51,10 +63,10 @@ export declare function parseEveScheduleCron(cron: string): ParsedEveCron | unde
|
|
|
51
63
|
export declare function eveScheduleCronFiresWithin(cron: string, nowMs: number, leadMs?: number): boolean;
|
|
52
64
|
/** Queue and World RPC routes are private; webhooks and manifests stay forwarded. */
|
|
53
65
|
export declare function isEveWorkflowInternalRoute(pathname: string): boolean;
|
|
54
|
-
export declare const EVE_HOST_OWNED_HEADERS: readonly ["forwarded", "x-
|
|
66
|
+
export declare const EVE_HOST_OWNED_HEADERS: readonly ["forwarded", "x-real-ip", "true-client-ip", "x-original-host", "x-original-proto", "x-envoy-original-host", "x-envoy-original-proto", "x-proxy-host", "x-host", "x-eve-public-origin", "x-workflow-local-base-url"];
|
|
55
67
|
export declare const WORKER_NAME_PATTERN: RegExp;
|
|
56
68
|
export declare const IDENTIFIER_PATTERN: RegExp;
|
|
57
|
-
export type EveHostErrorCode = "HOST_ORIGIN_UNAVAILABLE" | "HOST_REQUEST_ABORTED" | "HOST_READINESS_UNPROVEN"
|
|
69
|
+
export type EveHostErrorCode = "HOST_ORIGIN_UNAVAILABLE" | "HOST_REQUEST_ABORTED" | "HOST_READINESS_UNPROVEN";
|
|
58
70
|
export declare class EveHostError extends Error {
|
|
59
71
|
readonly code: EveHostErrorCode;
|
|
60
72
|
constructor(code: EveHostErrorCode, message: string);
|
|
@@ -67,8 +79,6 @@ export declare function resolveStableWorkersDevOrigin(request: StableWorkersDevO
|
|
|
67
79
|
export interface EveHostIdentity {
|
|
68
80
|
readonly workerName: string;
|
|
69
81
|
readonly containerApplicationName: string;
|
|
70
|
-
readonly containerClassName: string;
|
|
71
|
-
readonly containerBindingName: string;
|
|
72
82
|
readonly stableContainerInstanceName: string;
|
|
73
83
|
readonly deploymentId: string;
|
|
74
84
|
readonly generationId: string;
|
|
@@ -92,8 +102,7 @@ export interface EveHostConfigRequest extends EveHostIdentity {
|
|
|
92
102
|
* Durable Object state already published for this exact target. In-place
|
|
93
103
|
* updates carry the recorded binding and migration history forward
|
|
94
104
|
* verbatim: a class is only ever added once (`new_sqlite_classes` entries
|
|
95
|
-
* are append-only) and a class is never
|
|
96
|
-
* `deleted_classes` migration permanently destroys that class's data.
|
|
105
|
+
* are append-only) and a class is never removed.
|
|
97
106
|
*/
|
|
98
107
|
readonly durableObjects?: {
|
|
99
108
|
readonly bindings?: readonly EveDurableBinding[];
|
|
@@ -106,24 +115,24 @@ export interface EveDurableBinding {
|
|
|
106
115
|
readonly class_name: string;
|
|
107
116
|
}
|
|
108
117
|
/**
|
|
109
|
-
* One `migrations` entry as it appears in wrangler config.
|
|
110
|
-
*
|
|
111
|
-
*
|
|
118
|
+
* One `migrations` entry as it appears in wrangler config. Entries are
|
|
119
|
+
* compared by tag and carried forward verbatim across in-place updates;
|
|
120
|
+
* `new_sqlite_classes` declares a class.
|
|
112
121
|
*/
|
|
113
122
|
export interface EveDurableMigration {
|
|
114
123
|
readonly tag: string;
|
|
115
|
-
readonly new_sqlite_classes
|
|
124
|
+
readonly new_sqlite_classes?: readonly string[];
|
|
116
125
|
}
|
|
117
126
|
export interface EveHostWranglerConfig {
|
|
118
127
|
readonly account_id?: string;
|
|
119
128
|
readonly name: string;
|
|
120
129
|
readonly main: string;
|
|
121
130
|
readonly compatibility_date: string;
|
|
131
|
+
readonly compatibility_flags: readonly ["enable_ctx_exports"];
|
|
122
132
|
readonly workers_dev: true;
|
|
123
133
|
readonly vars: {
|
|
124
134
|
readonly EVE_PUBLIC_ORIGIN: string;
|
|
125
135
|
readonly EVE_CONTAINER_INSTANCE_NAME: string;
|
|
126
|
-
readonly EVE_CONTAINER_BINDING_NAME: string;
|
|
127
136
|
readonly EDEN_EVE_DEPLOYMENT_ID: string;
|
|
128
137
|
readonly EDEN_EVE_GENERATION_ID: string;
|
|
129
138
|
readonly EVE_RUNTIME_VARIABLE_NAMES: readonly string[];
|
|
@@ -138,10 +147,12 @@ export interface EveHostWranglerConfig {
|
|
|
138
147
|
{
|
|
139
148
|
readonly name: string;
|
|
140
149
|
readonly class_name: string;
|
|
141
|
-
readonly
|
|
142
|
-
readonly
|
|
143
|
-
|
|
144
|
-
|
|
150
|
+
readonly scheduling_policy: "durable_object";
|
|
151
|
+
readonly images: {
|
|
152
|
+
readonly eve: {
|
|
153
|
+
readonly image: string;
|
|
154
|
+
};
|
|
155
|
+
};
|
|
145
156
|
}
|
|
146
157
|
];
|
|
147
158
|
readonly durable_objects: {
|
|
@@ -177,36 +188,14 @@ export interface EveHostForwardingMetadata {
|
|
|
177
188
|
readonly deploymentId: string;
|
|
178
189
|
readonly generationId: string;
|
|
179
190
|
readonly correlationId: string;
|
|
180
|
-
/** The image this deployment's Worker config selects; the Durable Object verifies a running Container actually serves it before recording the deployment as started. */
|
|
181
|
-
readonly containerImage?: string;
|
|
182
191
|
readonly runtimeRevisionHandle?: string;
|
|
183
192
|
}
|
|
184
193
|
export declare function createTrustedEveRequest(request: Request, metadata: EveHostForwardingMetadata): Request;
|
|
185
|
-
export interface EveContainerTransport {
|
|
186
|
-
readonly containerFetch: (request: Request) => Promise<Response>;
|
|
187
|
-
readonly fetch: (request: Request) => Promise<Response>;
|
|
188
|
-
}
|
|
189
|
-
export interface EveHostProxyOptions extends EveHostForwardingMetadata {
|
|
190
|
-
readonly transport: EveContainerTransport;
|
|
191
|
-
readonly ensureReady: (signal: AbortSignal) => Promise<void>;
|
|
192
|
-
}
|
|
193
|
-
export declare function createEveHostProxy(options: EveHostProxyOptions): (request: Request) => Promise<Response>;
|
|
194
|
-
export interface EveHostLifecycleEvent {
|
|
195
|
-
readonly type: "start_requested" | "started" | "health_ready" | "stopped" | "errored" | "image_mismatch" | "replaced";
|
|
196
|
-
readonly at: number;
|
|
197
|
-
readonly safeStatus?: string;
|
|
198
|
-
}
|
|
199
|
-
export interface EveHostLifecycleObserver {
|
|
200
|
-
readonly events: readonly EveHostLifecycleEvent[];
|
|
201
|
-
record(type: EveHostLifecycleEvent["type"], safeStatus?: string): EveHostLifecycleEvent;
|
|
202
|
-
}
|
|
203
|
-
export declare function createEveHostLifecycleObserver(now?: () => number): EveHostLifecycleObserver;
|
|
204
194
|
export interface EveHostContainerEnvironment {
|
|
205
195
|
readonly [name: string]: unknown;
|
|
206
196
|
readonly EVE_RUNTIME_VARIABLE_NAMES?: readonly string[];
|
|
207
197
|
readonly EVE_PUBLIC_ORIGIN?: string;
|
|
208
198
|
readonly EVE_CONTAINER_INSTANCE_NAME?: string;
|
|
209
|
-
readonly EVE_CONTAINER_BINDING_NAME?: string;
|
|
210
199
|
readonly EDEN_EVE_DEPLOYMENT_ID?: string;
|
|
211
200
|
readonly EDEN_EVE_GENERATION_ID?: string;
|
|
212
201
|
readonly EDEN_EVE_RUNTIME_REVISION?: string;
|
|
@@ -221,20 +210,19 @@ export interface EveHostReadinessEvidence {
|
|
|
221
210
|
readonly checkedAt: string;
|
|
222
211
|
}
|
|
223
212
|
export interface EveHostReadinessOptions {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
};
|
|
232
|
-
}) => Promise<void>;
|
|
213
|
+
/**
|
|
214
|
+
* Ensures the Container is started (`ctx.container.start` when not
|
|
215
|
+
* running). Transient failures — scheduling-capacity errors surface only
|
|
216
|
+
* through `monitor()`/`start()` — are retried inside the gate's overall
|
|
217
|
+
* readiness deadline.
|
|
218
|
+
*/
|
|
219
|
+
readonly start: (signal: AbortSignal) => Promise<void>;
|
|
233
220
|
readonly healthFetch: (request: Request) => Promise<Response>;
|
|
234
221
|
readonly healthPath?: "/eve/v1/health";
|
|
235
222
|
readonly port?: 8080;
|
|
236
|
-
|
|
237
|
-
readonly
|
|
223
|
+
/** Total deadline covering start retries and the health poll. */
|
|
224
|
+
readonly readinessTimeoutMs?: number;
|
|
225
|
+
/** Per-probe cap on a single health request. */
|
|
238
226
|
readonly healthTimeoutMs?: number;
|
|
239
227
|
readonly waitIntervalMs?: number;
|
|
240
228
|
}
|
package/dist/eve-host.js
CHANGED
|
@@ -2,10 +2,43 @@ export const EVE_HOST_DEFAULTS = {
|
|
|
2
2
|
compatibilityDate: "2026-04-01",
|
|
3
3
|
healthPath: "/eve/v1/health",
|
|
4
4
|
internalPort: 8080,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
sleepAfter: "24h",
|
|
5
|
+
instance: "standard-1",
|
|
6
|
+
sleepAfter: "1h",
|
|
8
7
|
};
|
|
8
|
+
/**
|
|
9
|
+
* Cloudflare stops a container at most 6 hours after its Durable Object goes
|
|
10
|
+
* inactive (`setInactivityTimeout` rejects longer values). The idle-sleep
|
|
11
|
+
* alarm must fire before that so it can snapshot first, and the inactivity
|
|
12
|
+
* timeout is `sleepAfter` plus this margin.
|
|
13
|
+
*/
|
|
14
|
+
export const EVE_HOST_SLEEP_SNAPSHOT_MARGIN_MS = 15 * 60_000;
|
|
15
|
+
export const EVE_HOST_MAX_SLEEP_AFTER_MS = 6 * 3_600_000 - EVE_HOST_SLEEP_SNAPSHOT_MARGIN_MS;
|
|
16
|
+
/**
|
|
17
|
+
* Parses a `sleepAfter` duration ("300ms", "30s", "15m", "1h", or a bare
|
|
18
|
+
* number of seconds) and enforces Cloudflare's inactivity ceiling.
|
|
19
|
+
*/
|
|
20
|
+
export function parseEveSleepAfterMs(value) {
|
|
21
|
+
const match = /^([0-9]+)(ms|s|m|h|d)?$/u.exec(value.trim());
|
|
22
|
+
if (match === null) {
|
|
23
|
+
throw new EveHostError("HOST_READINESS_UNPROVEN", "The Container sleepAfter override is not a parseable duration.");
|
|
24
|
+
}
|
|
25
|
+
const amount = Number.parseInt(match[1] ?? "", 10);
|
|
26
|
+
const unit = match[2] ?? "s";
|
|
27
|
+
const factor = unit === "ms"
|
|
28
|
+
? 1
|
|
29
|
+
: unit === "s"
|
|
30
|
+
? 1_000
|
|
31
|
+
: unit === "m"
|
|
32
|
+
? 60_000
|
|
33
|
+
: unit === "h"
|
|
34
|
+
? 3_600_000
|
|
35
|
+
: 86_400_000;
|
|
36
|
+
const ms = amount * factor;
|
|
37
|
+
if (ms > EVE_HOST_MAX_SLEEP_AFTER_MS) {
|
|
38
|
+
throw new EveHostError("HOST_READINESS_UNPROVEN", "The Container sleepAfter override exceeds 345m (5 h 45 min); Cloudflare stops a container within 6 hours of its Durable Object going idle, so Eden must snapshot before then.");
|
|
39
|
+
}
|
|
40
|
+
return ms;
|
|
41
|
+
}
|
|
9
42
|
export const EVE_SCHEDULE_WAKE_TRIGGER_CRON = "* * * * *";
|
|
10
43
|
/**
|
|
11
44
|
* How far ahead of a tick the every-minute wake trigger starts the Container.
|
|
@@ -168,15 +201,7 @@ export function isEveWorkflowInternalRoute(pathname) {
|
|
|
168
201
|
}
|
|
169
202
|
export const EVE_HOST_OWNED_HEADERS = [
|
|
170
203
|
"forwarded",
|
|
171
|
-
"x-forwarded-for",
|
|
172
|
-
"x-forwarded-host",
|
|
173
|
-
"x-forwarded-port",
|
|
174
|
-
"x-forwarded-proto",
|
|
175
|
-
"x-forwarded-server",
|
|
176
|
-
"x-forwarded-scheme",
|
|
177
204
|
"x-real-ip",
|
|
178
|
-
"cf-connecting-ip",
|
|
179
|
-
"cf-visitor",
|
|
180
205
|
"true-client-ip",
|
|
181
206
|
"x-original-host",
|
|
182
207
|
"x-original-proto",
|
|
@@ -186,23 +211,10 @@ export const EVE_HOST_OWNED_HEADERS = [
|
|
|
186
211
|
"x-host",
|
|
187
212
|
"x-eve-public-origin",
|
|
188
213
|
"x-workflow-local-base-url",
|
|
189
|
-
"x-eden-eve-callback-base",
|
|
190
|
-
"x-eden-eve-deployment-id",
|
|
191
|
-
"x-eden-eve-generation-id",
|
|
192
|
-
"x-eden-eve-image",
|
|
193
|
-
"x-eden-eve-started-deployment",
|
|
194
|
-
"x-eden-eve-public-origin",
|
|
195
|
-
"x-eden-eve-correlation-id",
|
|
196
|
-
"x-eden-eve-container-name",
|
|
197
|
-
"x-eden-eve-container-id",
|
|
198
|
-
"x-eden-eve-runtime-revision",
|
|
199
|
-
"x-eden-container-name",
|
|
200
|
-
"x-eden-container-id",
|
|
201
|
-
"cf-container-target-port",
|
|
202
214
|
];
|
|
203
215
|
const EVE_HOST_OWNED_HEADER_SET = new Set(EVE_HOST_OWNED_HEADERS);
|
|
204
216
|
export const WORKER_NAME_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/u;
|
|
205
|
-
const SUBDOMAIN_PATTERN =
|
|
217
|
+
const SUBDOMAIN_PATTERN = WORKER_NAME_PATTERN;
|
|
206
218
|
export const IDENTIFIER_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/u;
|
|
207
219
|
const INSTANCE_NAME_PATTERN = /^[a-z0-9](?:[a-z0-9._-]{0,125}[a-z0-9])?$/u;
|
|
208
220
|
const SHA256_IMAGE_PATTERN = /^(?:[a-z0-9.-]+\/)?[a-z0-9._/-]+@sha256:[0-9a-f]{64}$/u;
|
|
@@ -267,13 +279,9 @@ export function createEveHostConfig(request) {
|
|
|
267
279
|
if (!WORKER_NAME_PATTERN.test(request.workerName)) {
|
|
268
280
|
throw new EveHostError("HOST_ORIGIN_UNAVAILABLE", "The exact Worker name is not valid.");
|
|
269
281
|
}
|
|
270
|
-
if (!WORKER_NAME_PATTERN.test(request.containerApplicationName)
|
|
271
|
-
!IDENTIFIER_PATTERN.test(request.containerClassName)) {
|
|
282
|
+
if (!WORKER_NAME_PATTERN.test(request.containerApplicationName)) {
|
|
272
283
|
throw new EveHostError("HOST_READINESS_UNPROVEN", "The Container application and class names must be stable safe identifiers.");
|
|
273
284
|
}
|
|
274
|
-
if (!IDENTIFIER_PATTERN.test(request.containerBindingName)) {
|
|
275
|
-
throw new EveHostError("HOST_READINESS_UNPROVEN", "The Container binding name must be a valid Worker environment identifier.");
|
|
276
|
-
}
|
|
277
285
|
if (!INSTANCE_NAME_PATTERN.test(request.stableContainerInstanceName)) {
|
|
278
286
|
throw new EveHostError("HOST_READINESS_UNPROVEN", "The stable Container instance name must be a bounded logical identifier.");
|
|
279
287
|
}
|
|
@@ -293,36 +301,31 @@ export function createEveHostConfig(request) {
|
|
|
293
301
|
}
|
|
294
302
|
}
|
|
295
303
|
if (request.containerSleepAfter !== undefined) {
|
|
296
|
-
|
|
297
|
-
throw new EveHostError("HOST_READINESS_UNPROVEN", "The Container sleepAfter override is not a parseable duration.");
|
|
298
|
-
}
|
|
304
|
+
parseEveSleepAfterMs(request.containerSleepAfter);
|
|
299
305
|
}
|
|
300
306
|
const container = {
|
|
301
307
|
name: request.containerApplicationName,
|
|
302
|
-
class_name:
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
? {}
|
|
306
|
-
: { image_build_context: request.containerImageBuildContext }),
|
|
307
|
-
max_instances: EVE_HOST_DEFAULTS.maxInstances,
|
|
308
|
-
instance_type: EVE_HOST_DEFAULTS.instanceType,
|
|
308
|
+
class_name: "EveHostDurableContainer",
|
|
309
|
+
scheduling_policy: "durable_object",
|
|
310
|
+
images: { eve: { image: request.containerImage } },
|
|
309
311
|
};
|
|
310
312
|
const worldCloudflare = request.workflowWorld === "@moinulmoin/eden-world-cloudflare";
|
|
311
313
|
const priorMigrations = [];
|
|
312
314
|
for (const migration of request.durableObjects?.migrations ?? []) {
|
|
315
|
+
const validClassList = (value) => Array.isArray(value) &&
|
|
316
|
+
value.every((className) => typeof className === "string" &&
|
|
317
|
+
IDENTIFIER_PATTERN.test(className));
|
|
313
318
|
if (typeof migration.tag !== "string" ||
|
|
314
319
|
migration.tag.length === 0 ||
|
|
315
|
-
!
|
|
316
|
-
migration.new_sqlite_classes.some((className) => typeof className !== "string" ||
|
|
317
|
-
!IDENTIFIER_PATTERN.test(className))) {
|
|
320
|
+
!validClassList(migration.new_sqlite_classes)) {
|
|
318
321
|
throw new EveHostError("HOST_READINESS_UNPROVEN", "The recorded Durable Object migration history is not safely reusable; refusing to drop or rewrite prior tags.");
|
|
319
322
|
}
|
|
320
323
|
priorMigrations.push(migration);
|
|
321
324
|
}
|
|
322
325
|
const bindings = [
|
|
323
326
|
{
|
|
324
|
-
name:
|
|
325
|
-
class_name:
|
|
327
|
+
name: "EVE_CONTAINER",
|
|
328
|
+
class_name: "EveHostDurableContainer",
|
|
326
329
|
},
|
|
327
330
|
...(worldCloudflare
|
|
328
331
|
? [{ name: "EDEN_WORLD", class_name: "EdenWorldDurableObject" }]
|
|
@@ -343,7 +346,7 @@ export function createEveHostConfig(request) {
|
|
|
343
346
|
bindings.push(priorBinding);
|
|
344
347
|
}
|
|
345
348
|
}
|
|
346
|
-
const declaredClasses = new Set(priorMigrations.flatMap((migration) => migration.new_sqlite_classes));
|
|
349
|
+
const declaredClasses = new Set(priorMigrations.flatMap((migration) => migration.new_sqlite_classes ?? []));
|
|
347
350
|
const newClasses = [
|
|
348
351
|
...new Set(bindings.map((binding) => binding.class_name)),
|
|
349
352
|
].filter((className) => !declaredClasses.has(className));
|
|
@@ -368,11 +371,11 @@ export function createEveHostConfig(request) {
|
|
|
368
371
|
name: request.workerName,
|
|
369
372
|
main: "worker.ts",
|
|
370
373
|
compatibility_date: EVE_HOST_DEFAULTS.compatibilityDate,
|
|
374
|
+
compatibility_flags: ["enable_ctx_exports"],
|
|
371
375
|
workers_dev: true,
|
|
372
376
|
vars: {
|
|
373
377
|
EVE_PUBLIC_ORIGIN: request.stableWorkersDevOrigin,
|
|
374
378
|
EVE_CONTAINER_INSTANCE_NAME: request.stableContainerInstanceName,
|
|
375
|
-
EVE_CONTAINER_BINDING_NAME: request.containerBindingName,
|
|
376
379
|
EDEN_EVE_DEPLOYMENT_ID: request.deploymentId,
|
|
377
380
|
EDEN_EVE_GENERATION_ID: request.generationId,
|
|
378
381
|
EVE_RUNTIME_VARIABLE_NAMES: request.runtimeVariableNames ?? [],
|
|
@@ -395,9 +398,9 @@ export function createEveHostConfig(request) {
|
|
|
395
398
|
},
|
|
396
399
|
container: {
|
|
397
400
|
applicationName: request.containerApplicationName,
|
|
398
|
-
className:
|
|
401
|
+
className: "EveHostDurableContainer",
|
|
399
402
|
instanceName: request.stableContainerInstanceName,
|
|
400
|
-
bindingName:
|
|
403
|
+
bindingName: "EVE_CONTAINER",
|
|
401
404
|
port: EVE_HOST_DEFAULTS.internalPort,
|
|
402
405
|
publicOrigin: request.stableWorkersDevOrigin,
|
|
403
406
|
deploymentId: request.deploymentId,
|
|
@@ -414,10 +417,8 @@ export function generateEveHostWorkerSource(request) {
|
|
|
414
417
|
const workerOptions = {
|
|
415
418
|
publicOrigin: request.config.container.publicOrigin,
|
|
416
419
|
workerName: request.config.worker.name,
|
|
417
|
-
containerBindingName: request.config.container.bindingName,
|
|
418
420
|
deploymentId: request.config.container.deploymentId,
|
|
419
421
|
generationId: request.config.container.generationId,
|
|
420
|
-
containerImage: request.config.worker.containers[0].image,
|
|
421
422
|
stableContainerInstanceName: request.config.container.instanceName,
|
|
422
423
|
...(request.config.container.runtimeRevisionHandle === undefined
|
|
423
424
|
? {}
|
|
@@ -429,18 +430,15 @@ export function generateEveHostWorkerSource(request) {
|
|
|
429
430
|
: { schedules: request.config.container.schedules }),
|
|
430
431
|
};
|
|
431
432
|
return [
|
|
432
|
-
`import {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
: `export { ContainerProxy, EveHostContainer as ${request.config.container.className} };`,
|
|
433
|
+
`import { EdenWorldDurableObject, EveHostDurableContainer, EveHostLoopback, createEveHostWorker } from ${JSON.stringify(moduleSpecifier)};`,
|
|
434
|
+
`export { EveHostLoopback };`,
|
|
435
|
+
"export { EveHostDurableContainer };",
|
|
436
436
|
"",
|
|
437
437
|
...(request.config.worker.vars.EDEN_EVE_WORLD_CLOUDFLARE === true ||
|
|
438
438
|
request.config.worker.durable_objects.bindings.some((binding) => binding.class_name === "EdenWorldDurableObject") ||
|
|
439
|
-
request.config.worker.migrations.some((migration) => migration.new_sqlite_classes.includes("EdenWorldDurableObject"))
|
|
440
|
-
? [
|
|
439
|
+
request.config.worker.migrations.some((migration) => (migration.new_sqlite_classes ?? []).includes("EdenWorldDurableObject"))
|
|
440
|
+
? ["export { EdenWorldDurableObject };"]
|
|
441
441
|
: []),
|
|
442
|
-
`EveHostContainer.outboundByHost = { ${JSON.stringify(new URL(request.config.container.publicOrigin).hostname)}: routeEveOutboundRequest };`,
|
|
443
|
-
"",
|
|
444
442
|
`export default createEveHostWorker(${JSON.stringify(workerOptions)});`,
|
|
445
443
|
"",
|
|
446
444
|
].join("\n");
|
|
@@ -495,9 +493,6 @@ export function createTrustedEveRequest(request, metadata) {
|
|
|
495
493
|
headers.set("x-eden-eve-deployment-id", metadata.deploymentId);
|
|
496
494
|
headers.set("x-eden-eve-generation-id", metadata.generationId);
|
|
497
495
|
headers.set("x-eden-eve-correlation-id", metadata.correlationId);
|
|
498
|
-
if (metadata.containerImage !== undefined) {
|
|
499
|
-
headers.set("x-eden-eve-image", metadata.containerImage);
|
|
500
|
-
}
|
|
501
496
|
if (metadata.runtimeRevisionHandle !== undefined) {
|
|
502
497
|
headers.set("x-eden-eve-runtime-revision", metadata.runtimeRevisionHandle);
|
|
503
498
|
}
|
|
@@ -512,40 +507,11 @@ export function createTrustedEveRequest(request, metadata) {
|
|
|
512
507
|
};
|
|
513
508
|
return new Request(targetUrl, init);
|
|
514
509
|
}
|
|
515
|
-
function isWebSocketUpgrade(request) {
|
|
516
|
-
return request.headers.get("upgrade")?.toLowerCase() === "websocket";
|
|
517
|
-
}
|
|
518
510
|
function throwIfAborted(signal) {
|
|
519
511
|
if (signal.aborted) {
|
|
520
512
|
throw new EveHostError("HOST_REQUEST_ABORTED", "The client request was cancelled before Eve became ready.");
|
|
521
513
|
}
|
|
522
514
|
}
|
|
523
|
-
export function createEveHostProxy(options) {
|
|
524
|
-
return async (request) => {
|
|
525
|
-
throwIfAborted(request.signal);
|
|
526
|
-
await options.ensureReady(request.signal);
|
|
527
|
-
throwIfAborted(request.signal);
|
|
528
|
-
const forwarded = createTrustedEveRequest(request, options);
|
|
529
|
-
return isWebSocketUpgrade(request)
|
|
530
|
-
? options.transport.fetch(forwarded)
|
|
531
|
-
: options.transport.containerFetch(forwarded);
|
|
532
|
-
};
|
|
533
|
-
}
|
|
534
|
-
export function createEveHostLifecycleObserver(now = Date.now) {
|
|
535
|
-
const events = [];
|
|
536
|
-
return {
|
|
537
|
-
events,
|
|
538
|
-
record(type, safeStatus) {
|
|
539
|
-
const event = {
|
|
540
|
-
type,
|
|
541
|
-
at: now(),
|
|
542
|
-
...(safeStatus === undefined ? {} : { safeStatus }),
|
|
543
|
-
};
|
|
544
|
-
events.push(event);
|
|
545
|
-
return event;
|
|
546
|
-
},
|
|
547
|
-
};
|
|
548
|
-
}
|
|
549
515
|
function responseBodyIsReady(value) {
|
|
550
516
|
if (typeof value !== "object" || value === null)
|
|
551
517
|
return false;
|
|
@@ -605,8 +571,7 @@ function raceWithAbort(promise, signal) {
|
|
|
605
571
|
export function createEveReadinessGate(options) {
|
|
606
572
|
const port = options.port ?? EVE_HOST_DEFAULTS.internalPort;
|
|
607
573
|
const healthPath = options.healthPath ?? EVE_HOST_DEFAULTS.healthPath;
|
|
608
|
-
const
|
|
609
|
-
const portReadyTimeoutMs = options.portReadyTimeoutMs ?? 30_000;
|
|
574
|
+
const readinessTimeoutMs = options.readinessTimeoutMs ?? 150_000;
|
|
610
575
|
const healthTimeoutMs = options.healthTimeoutMs ?? 10_000;
|
|
611
576
|
const waitIntervalMs = options.waitIntervalMs ?? 300;
|
|
612
577
|
let evidence;
|
|
@@ -614,83 +579,101 @@ export function createEveReadinessGate(options) {
|
|
|
614
579
|
let inFlightController;
|
|
615
580
|
let generation = 0;
|
|
616
581
|
const run = async (signal) => {
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
582
|
+
const deadline = Date.now() + readinessTimeoutMs;
|
|
583
|
+
let lastFailure;
|
|
584
|
+
const sleep = () => new Promise((resolve, reject) => {
|
|
585
|
+
const timer = setTimeout(resolve, waitIntervalMs);
|
|
586
|
+
signal.addEventListener("abort", () => {
|
|
587
|
+
clearTimeout(timer);
|
|
588
|
+
reject(new EveHostError("HOST_REQUEST_ABORTED", "The client request was cancelled before Eve became ready."));
|
|
589
|
+
}, { once: true });
|
|
590
|
+
});
|
|
591
|
+
const probe = async () => {
|
|
592
|
+
const healthController = new AbortController();
|
|
593
|
+
let rejectHealthTimeout;
|
|
594
|
+
const abortHealth = () => {
|
|
595
|
+
healthController.abort();
|
|
596
|
+
rejectHealthTimeout?.(new EveHostError("HOST_REQUEST_ABORTED", "The client request was cancelled before Eve became ready."));
|
|
597
|
+
};
|
|
598
|
+
signal.addEventListener("abort", abortHealth, { once: true });
|
|
599
|
+
const healthTimeoutResult = new Promise((_resolve, reject) => {
|
|
600
|
+
rejectHealthTimeout = reject;
|
|
626
601
|
});
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
602
|
+
const healthTimeout = setTimeout(() => {
|
|
603
|
+
healthController.abort();
|
|
604
|
+
rejectHealthTimeout?.(new EveHostError("HOST_READINESS_UNPROVEN", "The bounded Eve health probe timed out."));
|
|
605
|
+
}, healthTimeoutMs);
|
|
606
|
+
let response;
|
|
607
|
+
try {
|
|
608
|
+
const healthRequest = new Request(`http://localhost${healthPath}`, {
|
|
609
|
+
method: "GET",
|
|
610
|
+
signal: healthController.signal,
|
|
611
|
+
});
|
|
612
|
+
const healthResult = options.healthFetch(healthRequest);
|
|
613
|
+
response = await Promise.race([healthResult, healthTimeoutResult]);
|
|
631
614
|
}
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
615
|
+
catch {
|
|
616
|
+
// The port is not open yet (or the probe was aborted); poll again
|
|
617
|
+
// until the overall readiness deadline.
|
|
618
|
+
return undefined;
|
|
619
|
+
}
|
|
620
|
+
finally {
|
|
621
|
+
clearTimeout(healthTimeout);
|
|
622
|
+
signal.removeEventListener("abort", abortHealth);
|
|
623
|
+
}
|
|
624
|
+
if (response.status !== 200) {
|
|
625
|
+
await response.arrayBuffer().catch(() => undefined);
|
|
626
|
+
lastFailure = new EveHostError("HOST_READINESS_UNPROVEN", "The Eve health route did not return the expected successful status.");
|
|
627
|
+
return undefined;
|
|
628
|
+
}
|
|
629
|
+
if (!(response.headers.get("content-type") ?? "")
|
|
630
|
+
.toLowerCase()
|
|
631
|
+
.startsWith("application/json")) {
|
|
632
|
+
await response.arrayBuffer().catch(() => undefined);
|
|
633
|
+
lastFailure = new EveHostError("HOST_READINESS_UNPROVEN", "The Eve health route did not return the expected JSON contract.");
|
|
634
|
+
return undefined;
|
|
635
|
+
}
|
|
636
|
+
let body;
|
|
637
|
+
try {
|
|
638
|
+
body = await response.json();
|
|
639
|
+
}
|
|
640
|
+
catch {
|
|
641
|
+
lastFailure = new EveHostError("HOST_READINESS_UNPROVEN", "The Eve health route did not return a valid ready response.");
|
|
642
|
+
return undefined;
|
|
643
|
+
}
|
|
644
|
+
if (!responseBodyIsReady(body)) {
|
|
645
|
+
lastFailure = new EveHostError("HOST_READINESS_UNPROVEN", "The Eve health route is reachable but has not reported ready.");
|
|
646
|
+
return undefined;
|
|
647
|
+
}
|
|
648
|
+
return {
|
|
649
|
+
healthPath,
|
|
650
|
+
healthStatus: "ready",
|
|
651
|
+
healthVerified: true,
|
|
652
|
+
port,
|
|
653
|
+
checkedAt: new Date().toISOString(),
|
|
654
|
+
};
|
|
639
655
|
};
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
const healthTimeout = setTimeout(() => {
|
|
645
|
-
healthController.abort();
|
|
646
|
-
rejectHealthTimeout?.(new EveHostError("HOST_READINESS_UNPROVEN", "The bounded Eve health probe timed out."));
|
|
647
|
-
}, healthTimeoutMs);
|
|
648
|
-
let response;
|
|
649
|
-
try {
|
|
650
|
-
const healthRequest = new Request(`http://localhost${healthPath}`, {
|
|
651
|
-
method: "GET",
|
|
652
|
-
signal: healthController.signal,
|
|
653
|
-
});
|
|
654
|
-
const healthResult = options.healthFetch(healthRequest);
|
|
655
|
-
response = await Promise.race([healthResult, healthTimeoutResult]);
|
|
656
|
-
}
|
|
657
|
-
catch {
|
|
658
|
-
if (signal.aborted) {
|
|
659
|
-
throw new EveHostError("HOST_REQUEST_ABORTED", "The client request was cancelled before Eve became ready.");
|
|
656
|
+
for (;;) {
|
|
657
|
+
throwIfAborted(signal);
|
|
658
|
+
try {
|
|
659
|
+
await options.start(signal);
|
|
660
660
|
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
.
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
}
|
|
677
|
-
let body;
|
|
678
|
-
try {
|
|
679
|
-
body = await response.json();
|
|
680
|
-
}
|
|
681
|
-
catch {
|
|
682
|
-
throw new EveHostError("HOST_READINESS_UNPROVEN", "The Eve health route did not return a valid ready response.");
|
|
683
|
-
}
|
|
684
|
-
if (!responseBodyIsReady(body)) {
|
|
685
|
-
throw new EveHostError("HOST_READINESS_UNPROVEN", "The Eve health route is reachable but has not reported ready.");
|
|
661
|
+
catch (error) {
|
|
662
|
+
throwIfAborted(signal);
|
|
663
|
+
// Transient scheduling/capacity failures surface through start() or
|
|
664
|
+
// monitor(); retry until the readiness deadline.
|
|
665
|
+
lastFailure = error instanceof EveHostError
|
|
666
|
+
? error
|
|
667
|
+
: new EveHostError("HOST_READINESS_UNPROVEN", "The Eve Container could not be scheduled for start.");
|
|
668
|
+
}
|
|
669
|
+
const result = await probe();
|
|
670
|
+
if (result !== undefined)
|
|
671
|
+
return result;
|
|
672
|
+
if (Date.now() >= deadline) {
|
|
673
|
+
throw lastFailure ?? new EveHostError("HOST_READINESS_UNPROVEN", "The Eve Container did not reach its readiness deadline.");
|
|
674
|
+
}
|
|
675
|
+
await sleep();
|
|
686
676
|
}
|
|
687
|
-
return {
|
|
688
|
-
healthPath,
|
|
689
|
-
healthStatus: "ready",
|
|
690
|
-
healthVerified: true,
|
|
691
|
-
port,
|
|
692
|
-
checkedAt: new Date().toISOString(),
|
|
693
|
-
};
|
|
694
677
|
};
|
|
695
678
|
const gate = ((signal) => {
|
|
696
679
|
throwIfAborted(signal);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export type { EveDurableBinding, EveDurableMigration,
|
|
1
|
+
export { createEveHostConfig, generateEveHostWorkerSource, parseEveScheduleCron, resolveStableWorkersDevOrigin, } from "./eve-host.js";
|
|
2
|
+
export type { EveDurableBinding, EveDurableMigration, EveHostConfig, EveScheduleCronEntry, } from "./eve-host.js";
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createEveHostConfig, generateEveHostWorkerSource, parseEveScheduleCron, resolveStableWorkersDevOrigin, } from "./eve-host.js";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moinulmoin/eden-runtime-cloudflare",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Cloudflare Worker/Container host runtime for Eden's Eve deployments.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -20,9 +20,8 @@
|
|
|
20
20
|
"NOTICE"
|
|
21
21
|
],
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@cloudflare
|
|
24
|
-
"@
|
|
25
|
-
"@cloudflare/workers-types": "5.20260810.1"
|
|
23
|
+
"@moinulmoin/eden-world-cloudflare": "0.7.0",
|
|
24
|
+
"@cloudflare/workers-types": "5.20261006.1"
|
|
26
25
|
},
|
|
27
26
|
"repository": {
|
|
28
27
|
"type": "git",
|