@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.
@@ -1,6 +1,5 @@
1
- import { Container, ContainerProxy } from "@cloudflare/containers";
1
+ import { DurableObject, WorkerEntrypoint } from "cloudflare:workers";
2
2
  import { type EveHostContainerEnvironment, type EveHostForwardingMetadata, type EveHostReadinessEvidence, type EveScheduleCronEntry } from "./eve-host.js";
3
- export { ContainerProxy };
4
3
  /** The deployment's single SQLite-backed Workflow World. */
5
4
  export declare class EdenWorldDurableObject {
6
5
  private readonly core;
@@ -9,13 +8,16 @@ export declare class EdenWorldDurableObject {
9
8
  alarm(): Promise<void>;
10
9
  }
11
10
  /**
12
- * Delivers the container's own HTTPS requests to its public workers.dev origin
13
- * back into the container over the internal port instead of the public edge.
14
- * The Workflow local World posts queue deliveries to
15
- * `WORKFLOW_LOCAL_BASE_URL`, which must remain the public origin so Eve's
16
- * externally visible callback URLs stay correct; re-routing that traffic
17
- * inside the Worker lets the public Worker path refuse the unauthenticated
18
- * queue endpoints without breaking delivery.
11
+ * Delivers the container's own HTTPS requests to its public workers.dev
12
+ * origin back into the deployment without crossing the public edge. The
13
+ * Workflow local World posts queue deliveries to `WORKFLOW_LOCAL_BASE_URL`,
14
+ * which must remain the public origin so Eve's externally visible callback
15
+ * URLs stay correct; the DO registers an outbound-HTTPS intercept for that
16
+ * hostname aimed at `EveHostLoopback`, and this function routes the request:
17
+ * non-public hosts egress plainly, `/__eden/world/rpc` reaches the World
18
+ * Durable Object, and everything else re-enters the container over the
19
+ * internal port so the public Worker path can keep refusing the
20
+ * unauthenticated queue endpoints.
19
21
  */
20
22
  export declare function routeEveOutboundRequest(request: Request, env: EveHostContainerEnvironment): Promise<Response>;
21
23
  /**
@@ -24,63 +26,83 @@ export declare function routeEveOutboundRequest(request: Request, env: EveHostCo
24
26
  * package's public declaration surface, so plain-Node consumers never load
25
27
  * `cloudflare:workers`-dependent code.
26
28
  */
27
- type EveHostContainerContext = ConstructorParameters<typeof Container>[0];
28
- export declare class EveHostContainer extends Container<EveHostContainerEnvironment> {
29
- defaultPort: 8080;
30
- sleepAfter: string | number;
31
- requiredPorts: 8080[];
32
- interceptHttps: boolean;
33
- enableInternet: boolean;
34
- pingEndpoint: string;
29
+ /**
30
+ * The WorkerEntrypoint the container's intercepted outbound HTTPS traffic is
31
+ * delivered to (registered by `EveHostDurableContainer` right after every
32
+ * `ctx.container.start()`). Props carry the DO instance name because
33
+ * entrypoint props cannot hold a Fetcher.
34
+ */
35
+ export declare class EveHostLoopback extends WorkerEntrypoint<EveHostContainerEnvironment> {
36
+ fetch(request: Request): Promise<Response>;
37
+ }
38
+ /**
39
+ * The Eve host Durable Object. It drives `ctx.container` directly: the
40
+ * image is selected at `start()` from this Worker version's `images.eve`
41
+ * entry, the writable filesystem is preserved across sleep via a container
42
+ * snapshot, and an update restarts the instance when `inspect()` shows the
43
+ * running image predates the configured one.
44
+ */
45
+ export declare class EveHostDurableContainer extends DurableObject<EveHostContainerEnvironment> {
35
46
  readonly lifecycle: import("./eve-host.js").EveHostLifecycleObserver;
36
47
  private readinessStarted;
37
- /** Evidence is cached only under the deployment whose image was verified. */
48
+ /** Evidence is cached only while the container it was proven on keeps running. */
38
49
  private readinessEvidence;
50
+ /** True once the running container's image was proven to equal `images.eve`. */
51
+ private imageVerified;
39
52
  /**
40
53
  * Bumped whenever the Container stops or is reset. Readiness work captures
41
- * the epoch it started under and may only record a marker or cache
42
- * evidence if no stop happened in between.
54
+ * the epoch it started under and may only cache evidence if no stop
55
+ * happened in between.
43
56
  */
44
57
  private readinessEpoch;
58
+ private monitorAttached;
59
+ private readonly envVars;
60
+ private readonly sleepAfterMs;
45
61
  private readonly readiness;
46
- constructor(ctx: EveHostContainerContext, env: EveHostContainerEnvironment);
62
+ constructor(ctx: DurableObjectState, env: EveHostContainerEnvironment);
63
+ private containerRuntime;
64
+ /** Container lifetime the platform keeps after the DO goes inactive. */
65
+ private get inactivityTimeoutMs();
66
+ private attachMonitor;
67
+ private recordContainerStopped;
68
+ /** Routes the container's own requests to its public origin back inside. */
69
+ private registerLoopbackIntercept;
47
70
  /**
48
- * Compares the deployment the running Container was started under (stored
49
- * in Durable Object storage, which survives Worker redeploys) against the
50
- * deployment the *current* Worker stamps on the forwarded request. A
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.
71
+ * Records request activity and arms the sleep alarm at
72
+ * `lastActivityAt + sleepAfter`. The alarm — not the inactivity timeout —
73
+ * is what snapshots the writable filesystem before the container stops.
63
74
  */
64
- private reconcileStartedDeployment;
65
- private containerServesImage;
75
+ private touchActivity;
66
76
  /**
67
- * Records the started deployment only when the running Container provably
68
- * serves this deployment's image (`inspect()` matches the forwarded
69
- * `x-eden-eve-image`). `false` or unknown (no `inspect`, a throwing call,
70
- * or no image field) never records — a start inside the
71
- * Worker-active-before-image-rollout window must not pin the old image.
72
- * When the Worker stamps no image, the marker is recorded unverified,
73
- * matching pre-drift behavior.
77
+ * Starts the container when it is not running. A stored workspace snapshot
78
+ * is restored only when it was captured from the exact image this Worker
79
+ * version configures — restoring an older snapshot silently runs the
80
+ * previous image — so after an image update the container starts fresh and
81
+ * workspace files intentionally do not carry across.
74
82
  */
75
- private recordStartedDeployment;
76
- ensureEveReady(signal?: AbortSignal, requestDeploymentId?: string, requestImage?: string): Promise<EveHostReadinessEvidence>;
83
+ private ensureContainerStarted;
84
+ /**
85
+ * Replaces the running container when `inspect()` proves it still serves a
86
+ * pre-update image: this Worker version's `images.eve` is selected at
87
+ * `start()`, so an in-place update must stop the stale instance itself.
88
+ */
89
+ private reconcileRunningImage;
90
+ ensureEveReady(signal?: AbortSignal): Promise<EveHostReadinessEvidence>;
77
91
  fetch(request: Request): Promise<Response>;
78
- onStart(): void;
79
- onStop(params: {
80
- readonly exitCode: number;
81
- readonly reason: "exit" | "runtime_signal";
82
- }): void;
83
- onError(error: unknown): unknown;
92
+ /**
93
+ * Queue deliveries and loopback traffic enter here: same readiness and
94
+ * forwarding as `fetch` without the deployment-header echo rules (the
95
+ * loopback path is not a deployment-health signal).
96
+ */
97
+ loopbackFetch(request: Request): Promise<Response>;
98
+ /**
99
+ * The idle-sleep path: once the container has been quiet for `sleepAfter`,
100
+ * snapshot the writable filesystem (so `/workspace` survives the sleep)
101
+ * and destroy the instance. A snapshot failure retries up to
102
+ * `EVE_HOST_SNAPSHOT_MAX_ATTEMPTS` times, then destroys anyway so billing
103
+ * for the running container stops.
104
+ */
105
+ alarm(): Promise<void>;
84
106
  }
85
107
  export type EveHostWorkerEnvironment = EveHostContainerEnvironment;
86
108
  export interface EveHostWorkerOptions extends EveHostForwardingMetadata {