@moinulmoin/eden-runtime-cloudflare 0.5.0 → 0.6.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.
@@ -2,8 +2,7 @@ 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 maxInstances: 1;
6
- readonly instanceType: "basic";
5
+ readonly instance: "standard-1";
7
6
  readonly sleepAfter: "24h";
8
7
  };
9
8
  export declare const EVE_SCHEDULE_WAKE_TRIGGER_CRON = "* * * * *";
@@ -51,7 +50,7 @@ export declare function parseEveScheduleCron(cron: string): ParsedEveCron | unde
51
50
  export declare function eveScheduleCronFiresWithin(cron: string, nowMs: number, leadMs?: number): boolean;
52
51
  /** Queue and World RPC routes are private; webhooks and manifests stay forwarded. */
53
52
  export declare function isEveWorkflowInternalRoute(pathname: string): boolean;
54
- export declare const EVE_HOST_OWNED_HEADERS: readonly ["forwarded", "x-forwarded-for", "x-forwarded-host", "x-forwarded-port", "x-forwarded-proto", "x-forwarded-server", "x-forwarded-scheme", "x-real-ip", "cf-connecting-ip", "cf-visitor", "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", "x-eden-eve-callback-base", "x-eden-eve-deployment-id", "x-eden-eve-generation-id", "x-eden-eve-image", "x-eden-eve-started-deployment", "x-eden-eve-public-origin", "x-eden-eve-correlation-id", "x-eden-eve-container-name", "x-eden-eve-container-id", "x-eden-eve-runtime-revision", "x-eden-container-name", "x-eden-container-id", "cf-container-target-port"];
53
+ export declare const EVE_HOST_OWNED_HEADERS: readonly ["forwarded", "x-forwarded-for", "x-forwarded-host", "x-forwarded-port", "x-forwarded-proto", "x-forwarded-server", "x-forwarded-scheme", "x-real-ip", "cf-connecting-ip", "cf-visitor", "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", "x-eden-eve-callback-base", "x-eden-eve-deployment-id", "x-eden-eve-generation-id", "x-eden-eve-started-deployment", "x-eden-eve-public-origin", "x-eden-eve-correlation-id", "x-eden-eve-container-name", "x-eden-eve-container-id", "x-eden-eve-runtime-revision", "x-eden-container-name", "x-eden-container-id", "cf-container-target-port"];
55
54
  export declare const WORKER_NAME_PATTERN: RegExp;
56
55
  export declare const IDENTIFIER_PATTERN: RegExp;
57
56
  export type EveHostErrorCode = "HOST_ORIGIN_UNAVAILABLE" | "HOST_REQUEST_ABORTED" | "HOST_READINESS_UNPROVEN" | "HOST_TRANSPORT_UNTESTABLE" | "HOST_WEBSOCKET_UNSUPPORTED";
@@ -92,8 +91,7 @@ export interface EveHostConfigRequest extends EveHostIdentity {
92
91
  * Durable Object state already published for this exact target. In-place
93
92
  * updates carry the recorded binding and migration history forward
94
93
  * verbatim: a class is only ever added once (`new_sqlite_classes` entries
95
- * are append-only) and a class is never silently removed — a
96
- * `deleted_classes` migration permanently destroys that class's data.
94
+ * are append-only) and a class is never removed.
97
95
  */
98
96
  readonly durableObjects?: {
99
97
  readonly bindings?: readonly EveDurableBinding[];
@@ -106,19 +104,20 @@ export interface EveDurableBinding {
106
104
  readonly class_name: string;
107
105
  }
108
106
  /**
109
- * One `migrations` entry as it appears in wrangler config. Only the
110
- * `new_sqlite_classes` form Eden has ever emitted is modelled; entries are
111
- * compared by tag and carried forward verbatim across in-place updates.
107
+ * One `migrations` entry as it appears in wrangler config. Entries are
108
+ * compared by tag and carried forward verbatim across in-place updates;
109
+ * `new_sqlite_classes` declares a class.
112
110
  */
113
111
  export interface EveDurableMigration {
114
112
  readonly tag: string;
115
- readonly new_sqlite_classes: readonly string[];
113
+ readonly new_sqlite_classes?: readonly string[];
116
114
  }
117
115
  export interface EveHostWranglerConfig {
118
116
  readonly account_id?: string;
119
117
  readonly name: string;
120
118
  readonly main: string;
121
119
  readonly compatibility_date: string;
120
+ readonly compatibility_flags: readonly ["enable_ctx_exports"];
122
121
  readonly workers_dev: true;
123
122
  readonly vars: {
124
123
  readonly EVE_PUBLIC_ORIGIN: string;
@@ -138,10 +137,12 @@ export interface EveHostWranglerConfig {
138
137
  {
139
138
  readonly name: string;
140
139
  readonly class_name: string;
141
- readonly image: string;
142
- readonly image_build_context?: string;
143
- readonly max_instances: 1;
144
- readonly instance_type: "basic";
140
+ readonly scheduling_policy: "durable_object";
141
+ readonly images: {
142
+ readonly eve: {
143
+ readonly image: string;
144
+ };
145
+ };
145
146
  }
146
147
  ];
147
148
  readonly durable_objects: {
@@ -177,8 +178,6 @@ export interface EveHostForwardingMetadata {
177
178
  readonly deploymentId: string;
178
179
  readonly generationId: string;
179
180
  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
181
  readonly runtimeRevisionHandle?: string;
183
182
  }
184
183
  export declare function createTrustedEveRequest(request: Request, metadata: EveHostForwardingMetadata): Request;
@@ -221,20 +220,19 @@ export interface EveHostReadinessEvidence {
221
220
  readonly checkedAt: string;
222
221
  }
223
222
  export interface EveHostReadinessOptions {
224
- readonly startAndWaitForPorts: (options: {
225
- readonly ports: 8080;
226
- readonly cancellationOptions: {
227
- readonly abort: AbortSignal;
228
- readonly instanceGetTimeoutMS: number;
229
- readonly portReadyTimeoutMS: number;
230
- readonly waitInterval: number;
231
- };
232
- }) => Promise<void>;
223
+ /**
224
+ * Ensures the Container is started (`ctx.container.start` when not
225
+ * running). Transient failures — scheduling-capacity errors surface only
226
+ * through `monitor()`/`start()` — are retried inside the gate's overall
227
+ * readiness deadline.
228
+ */
229
+ readonly start: (signal: AbortSignal) => Promise<void>;
233
230
  readonly healthFetch: (request: Request) => Promise<Response>;
234
231
  readonly healthPath?: "/eve/v1/health";
235
232
  readonly port?: 8080;
236
- readonly instanceGetTimeoutMs?: number;
237
- readonly portReadyTimeoutMs?: number;
233
+ /** Total deadline covering start retries and the health poll. */
234
+ readonly readinessTimeoutMs?: number;
235
+ /** Per-probe cap on a single health request. */
238
236
  readonly healthTimeoutMs?: number;
239
237
  readonly waitIntervalMs?: number;
240
238
  }
package/dist/eve-host.js CHANGED
@@ -2,8 +2,7 @@ export const EVE_HOST_DEFAULTS = {
2
2
  compatibilityDate: "2026-04-01",
3
3
  healthPath: "/eve/v1/health",
4
4
  internalPort: 8080,
5
- maxInstances: 1,
6
- instanceType: "basic",
5
+ instance: "standard-1",
7
6
  sleepAfter: "24h",
8
7
  };
9
8
  export const EVE_SCHEDULE_WAKE_TRIGGER_CRON = "* * * * *";
@@ -189,7 +188,6 @@ export const EVE_HOST_OWNED_HEADERS = [
189
188
  "x-eden-eve-callback-base",
190
189
  "x-eden-eve-deployment-id",
191
190
  "x-eden-eve-generation-id",
192
- "x-eden-eve-image",
193
191
  "x-eden-eve-started-deployment",
194
192
  "x-eden-eve-public-origin",
195
193
  "x-eden-eve-correlation-id",
@@ -300,21 +298,18 @@ export function createEveHostConfig(request) {
300
298
  const container = {
301
299
  name: request.containerApplicationName,
302
300
  class_name: request.containerClassName,
303
- image: request.containerImage,
304
- ...(request.containerImageBuildContext === undefined
305
- ? {}
306
- : { image_build_context: request.containerImageBuildContext }),
307
- max_instances: EVE_HOST_DEFAULTS.maxInstances,
308
- instance_type: EVE_HOST_DEFAULTS.instanceType,
301
+ scheduling_policy: "durable_object",
302
+ images: { eve: { image: request.containerImage } },
309
303
  };
310
304
  const worldCloudflare = request.workflowWorld === "@moinulmoin/eden-world-cloudflare";
311
305
  const priorMigrations = [];
312
306
  for (const migration of request.durableObjects?.migrations ?? []) {
307
+ const validClassList = (value) => Array.isArray(value) &&
308
+ value.every((className) => typeof className === "string" &&
309
+ IDENTIFIER_PATTERN.test(className));
313
310
  if (typeof migration.tag !== "string" ||
314
311
  migration.tag.length === 0 ||
315
- !Array.isArray(migration.new_sqlite_classes) ||
316
- migration.new_sqlite_classes.some((className) => typeof className !== "string" ||
317
- !IDENTIFIER_PATTERN.test(className))) {
312
+ !validClassList(migration.new_sqlite_classes)) {
318
313
  throw new EveHostError("HOST_READINESS_UNPROVEN", "The recorded Durable Object migration history is not safely reusable; refusing to drop or rewrite prior tags.");
319
314
  }
320
315
  priorMigrations.push(migration);
@@ -343,7 +338,7 @@ export function createEveHostConfig(request) {
343
338
  bindings.push(priorBinding);
344
339
  }
345
340
  }
346
- const declaredClasses = new Set(priorMigrations.flatMap((migration) => migration.new_sqlite_classes));
341
+ const declaredClasses = new Set(priorMigrations.flatMap((migration) => migration.new_sqlite_classes ?? []));
347
342
  const newClasses = [
348
343
  ...new Set(bindings.map((binding) => binding.class_name)),
349
344
  ].filter((className) => !declaredClasses.has(className));
@@ -368,6 +363,7 @@ export function createEveHostConfig(request) {
368
363
  name: request.workerName,
369
364
  main: "worker.ts",
370
365
  compatibility_date: EVE_HOST_DEFAULTS.compatibilityDate,
366
+ compatibility_flags: ["enable_ctx_exports"],
371
367
  workers_dev: true,
372
368
  vars: {
373
369
  EVE_PUBLIC_ORIGIN: request.stableWorkersDevOrigin,
@@ -417,7 +413,6 @@ export function generateEveHostWorkerSource(request) {
417
413
  containerBindingName: request.config.container.bindingName,
418
414
  deploymentId: request.config.container.deploymentId,
419
415
  generationId: request.config.container.generationId,
420
- containerImage: request.config.worker.containers[0].image,
421
416
  stableContainerInstanceName: request.config.container.instanceName,
422
417
  ...(request.config.container.runtimeRevisionHandle === undefined
423
418
  ? {}
@@ -428,19 +423,19 @@ export function generateEveHostWorkerSource(request) {
428
423
  ? {}
429
424
  : { schedules: request.config.container.schedules }),
430
425
  };
426
+ const exportContainerClass = request.config.container.className === "EveHostDurableContainer"
427
+ ? "export { EveHostDurableContainer };"
428
+ : `export { EveHostDurableContainer as ${request.config.container.className} };`;
431
429
  return [
432
- `import { ContainerProxy, EveHostContainer, createEveHostWorker, routeEveOutboundRequest } from ${JSON.stringify(moduleSpecifier)};`,
433
- request.config.container.className === "EveHostContainer"
434
- ? "export { ContainerProxy, EveHostContainer };"
435
- : `export { ContainerProxy, EveHostContainer as ${request.config.container.className} };`,
430
+ `import { EdenWorldDurableObject, EveHostDurableContainer, EveHostLoopback, createEveHostWorker } from ${JSON.stringify(moduleSpecifier)};`,
431
+ `export { EveHostLoopback };`,
432
+ exportContainerClass,
436
433
  "",
437
434
  ...(request.config.worker.vars.EDEN_EVE_WORLD_CLOUDFLARE === true ||
438
435
  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
- ? [`export { EdenWorldDurableObject } from ${JSON.stringify(moduleSpecifier)};`]
436
+ request.config.worker.migrations.some((migration) => (migration.new_sqlite_classes ?? []).includes("EdenWorldDurableObject"))
437
+ ? ["export { EdenWorldDurableObject };"]
441
438
  : []),
442
- `EveHostContainer.outboundByHost = { ${JSON.stringify(new URL(request.config.container.publicOrigin).hostname)}: routeEveOutboundRequest };`,
443
- "",
444
439
  `export default createEveHostWorker(${JSON.stringify(workerOptions)});`,
445
440
  "",
446
441
  ].join("\n");
@@ -495,9 +490,6 @@ export function createTrustedEveRequest(request, metadata) {
495
490
  headers.set("x-eden-eve-deployment-id", metadata.deploymentId);
496
491
  headers.set("x-eden-eve-generation-id", metadata.generationId);
497
492
  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
493
  if (metadata.runtimeRevisionHandle !== undefined) {
502
494
  headers.set("x-eden-eve-runtime-revision", metadata.runtimeRevisionHandle);
503
495
  }
@@ -605,8 +597,7 @@ function raceWithAbort(promise, signal) {
605
597
  export function createEveReadinessGate(options) {
606
598
  const port = options.port ?? EVE_HOST_DEFAULTS.internalPort;
607
599
  const healthPath = options.healthPath ?? EVE_HOST_DEFAULTS.healthPath;
608
- const instanceGetTimeoutMs = options.instanceGetTimeoutMs ?? 120_000;
609
- const portReadyTimeoutMs = options.portReadyTimeoutMs ?? 30_000;
600
+ const readinessTimeoutMs = options.readinessTimeoutMs ?? 150_000;
610
601
  const healthTimeoutMs = options.healthTimeoutMs ?? 10_000;
611
602
  const waitIntervalMs = options.waitIntervalMs ?? 300;
612
603
  let evidence;
@@ -614,83 +605,101 @@ export function createEveReadinessGate(options) {
614
605
  let inFlightController;
615
606
  let generation = 0;
616
607
  const run = async (signal) => {
617
- try {
618
- await options.startAndWaitForPorts({
619
- ports: port,
620
- cancellationOptions: {
621
- abort: signal,
622
- instanceGetTimeoutMS: instanceGetTimeoutMs,
623
- portReadyTimeoutMS: portReadyTimeoutMs,
624
- waitInterval: waitIntervalMs,
625
- },
608
+ const deadline = Date.now() + readinessTimeoutMs;
609
+ let lastFailure;
610
+ const sleep = () => new Promise((resolve, reject) => {
611
+ const timer = setTimeout(resolve, waitIntervalMs);
612
+ signal.addEventListener("abort", () => {
613
+ clearTimeout(timer);
614
+ reject(new EveHostError("HOST_REQUEST_ABORTED", "The client request was cancelled before Eve became ready."));
615
+ }, { once: true });
616
+ });
617
+ const probe = async () => {
618
+ const healthController = new AbortController();
619
+ let rejectHealthTimeout;
620
+ const abortHealth = () => {
621
+ healthController.abort();
622
+ rejectHealthTimeout?.(new EveHostError("HOST_REQUEST_ABORTED", "The client request was cancelled before Eve became ready."));
623
+ };
624
+ signal.addEventListener("abort", abortHealth, { once: true });
625
+ const healthTimeoutResult = new Promise((_resolve, reject) => {
626
+ rejectHealthTimeout = reject;
626
627
  });
627
- }
628
- catch {
629
- if (signal.aborted) {
630
- throw new EveHostError("HOST_REQUEST_ABORTED", "The client request was cancelled before Eve became ready.");
628
+ const healthTimeout = setTimeout(() => {
629
+ healthController.abort();
630
+ rejectHealthTimeout?.(new EveHostError("HOST_READINESS_UNPROVEN", "The bounded Eve health probe timed out."));
631
+ }, healthTimeoutMs);
632
+ let response;
633
+ try {
634
+ const healthRequest = new Request(`http://localhost${healthPath}`, {
635
+ method: "GET",
636
+ signal: healthController.signal,
637
+ });
638
+ const healthResult = options.healthFetch(healthRequest);
639
+ response = await Promise.race([healthResult, healthTimeoutResult]);
631
640
  }
632
- throw new EveHostError("HOST_READINESS_UNPROVEN", "The Eve Container did not reach its internal port readiness deadline.");
633
- }
634
- const healthController = new AbortController();
635
- let rejectHealthTimeout;
636
- const abortHealth = () => {
637
- healthController.abort();
638
- rejectHealthTimeout?.(new EveHostError("HOST_REQUEST_ABORTED", "The client request was cancelled before Eve became ready."));
641
+ catch {
642
+ // The port is not open yet (or the probe was aborted); poll again
643
+ // until the overall readiness deadline.
644
+ return undefined;
645
+ }
646
+ finally {
647
+ clearTimeout(healthTimeout);
648
+ signal.removeEventListener("abort", abortHealth);
649
+ }
650
+ if (response.status !== 200) {
651
+ await response.arrayBuffer().catch(() => undefined);
652
+ lastFailure = new EveHostError("HOST_READINESS_UNPROVEN", "The Eve health route did not return the expected successful status.");
653
+ return undefined;
654
+ }
655
+ if (!(response.headers.get("content-type") ?? "")
656
+ .toLowerCase()
657
+ .startsWith("application/json")) {
658
+ await response.arrayBuffer().catch(() => undefined);
659
+ lastFailure = new EveHostError("HOST_READINESS_UNPROVEN", "The Eve health route did not return the expected JSON contract.");
660
+ return undefined;
661
+ }
662
+ let body;
663
+ try {
664
+ body = await response.json();
665
+ }
666
+ catch {
667
+ lastFailure = new EveHostError("HOST_READINESS_UNPROVEN", "The Eve health route did not return a valid ready response.");
668
+ return undefined;
669
+ }
670
+ if (!responseBodyIsReady(body)) {
671
+ lastFailure = new EveHostError("HOST_READINESS_UNPROVEN", "The Eve health route is reachable but has not reported ready.");
672
+ return undefined;
673
+ }
674
+ return {
675
+ healthPath,
676
+ healthStatus: "ready",
677
+ healthVerified: true,
678
+ port,
679
+ checkedAt: new Date().toISOString(),
680
+ };
639
681
  };
640
- signal.addEventListener("abort", abortHealth, { once: true });
641
- const healthTimeoutResult = new Promise((_resolve, reject) => {
642
- rejectHealthTimeout = reject;
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.");
682
+ for (;;) {
683
+ throwIfAborted(signal);
684
+ try {
685
+ await options.start(signal);
660
686
  }
661
- throw new EveHostError("HOST_READINESS_UNPROVEN", "The bounded Eve health probe did not complete.");
662
- }
663
- finally {
664
- clearTimeout(healthTimeout);
665
- signal.removeEventListener("abort", abortHealth);
666
- }
667
- if (response.status !== 200) {
668
- await response.arrayBuffer().catch(() => undefined);
669
- throw new EveHostError("HOST_READINESS_UNPROVEN", "The Eve health route did not return the expected successful status.");
670
- }
671
- if (!(response.headers.get("content-type") ?? "")
672
- .toLowerCase()
673
- .startsWith("application/json")) {
674
- await response.arrayBuffer().catch(() => undefined);
675
- throw new EveHostError("HOST_READINESS_UNPROVEN", "The Eve health route did not return the expected JSON contract.");
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.");
687
+ catch (error) {
688
+ throwIfAborted(signal);
689
+ // Transient scheduling/capacity failures surface through start() or
690
+ // monitor(); retry until the readiness deadline.
691
+ lastFailure = error instanceof EveHostError
692
+ ? error
693
+ : new EveHostError("HOST_READINESS_UNPROVEN", "The Eve Container could not be scheduled for start.");
694
+ }
695
+ const result = await probe();
696
+ if (result !== undefined)
697
+ return result;
698
+ if (Date.now() >= deadline) {
699
+ throw lastFailure ?? new EveHostError("HOST_READINESS_UNPROVEN", "The Eve Container did not reach its readiness deadline.");
700
+ }
701
+ await sleep();
686
702
  }
687
- return {
688
- healthPath,
689
- healthStatus: "ready",
690
- healthVerified: true,
691
- port,
692
- checkedAt: new Date().toISOString(),
693
- };
694
703
  };
695
704
  const gate = ((signal) => {
696
705
  throwIfAborted(signal);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moinulmoin/eden-runtime-cloudflare",
3
- "version": "0.5.0",
3
+ "version": "0.6.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/containers": "0.3.7",
24
- "@moinulmoin/eden-world-cloudflare": "0.5.0",
25
- "@cloudflare/workers-types": "5.20260810.1"
23
+ "@moinulmoin/eden-world-cloudflare": "0.6.0",
24
+ "@cloudflare/workers-types": "5.20261006.1"
26
25
  },
27
26
  "repository": {
28
27
  "type": "git",