@moinulmoin/eden-runtime-cloudflare 0.1.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.
Files changed (48) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +42 -0
  3. package/dist/artifact-runtime.d.ts +27 -0
  4. package/dist/artifact-runtime.js +14 -0
  5. package/dist/eden-eve-host-worker.mjs +1960 -0
  6. package/dist/eve-host-runtime.d.ts +46 -0
  7. package/dist/eve-host-runtime.js +127 -0
  8. package/dist/eve-host.d.ts +166 -0
  9. package/dist/eve-host.js +495 -0
  10. package/dist/http-host.d.ts +6 -0
  11. package/dist/http-host.js +419 -0
  12. package/dist/index.d.ts +21 -0
  13. package/dist/index.js +7 -0
  14. package/dist/model-adapter-internal.d.ts +12 -0
  15. package/dist/model-adapter-internal.js +172 -0
  16. package/dist/model-adapter.d.ts +9 -0
  17. package/dist/model-adapter.js +56 -0
  18. package/dist/model-contracts.d.ts +92 -0
  19. package/dist/model-contracts.js +2 -0
  20. package/dist/model-normalizers.d.ts +7 -0
  21. package/dist/model-normalizers.js +453 -0
  22. package/dist/session-checkpoint.d.ts +48 -0
  23. package/dist/session-checkpoint.js +300 -0
  24. package/dist/session-identity.d.ts +9 -0
  25. package/dist/session-identity.js +45 -0
  26. package/dist/session-jobs.d.ts +69 -0
  27. package/dist/session-jobs.js +427 -0
  28. package/dist/session-journal.d.ts +154 -0
  29. package/dist/session-journal.js +391 -0
  30. package/dist/session-schema.d.ts +21 -0
  31. package/dist/session-schema.js +247 -0
  32. package/dist/session-state.d.ts +165 -0
  33. package/dist/session-state.js +168 -0
  34. package/dist/session.d.ts +40 -0
  35. package/dist/session.js +792 -0
  36. package/dist/test-execution.d.ts +8 -0
  37. package/dist/test-execution.js +12 -0
  38. package/dist/test-worker.d.ts +12 -0
  39. package/dist/test-worker.js +214 -0
  40. package/dist/tool-harness.d.ts +31 -0
  41. package/dist/tool-harness.js +226 -0
  42. package/dist/turn-runner-storage.d.ts +28 -0
  43. package/dist/turn-runner-storage.js +583 -0
  44. package/dist/turn-runner-types.d.ts +112 -0
  45. package/dist/turn-runner-types.js +21 -0
  46. package/dist/turn-runner.d.ts +6 -0
  47. package/dist/turn-runner.js +370 -0
  48. package/package.json +51 -0
@@ -0,0 +1,46 @@
1
+ import { Container } from "@cloudflare/containers";
2
+ import { type EveHostContainerEnvironment, type EveHostForwardingMetadata, type EveHostReadinessEvidence } from "./eve-host.js";
3
+ /**
4
+ * This module is the only Eve-host surface that depends on provider runtime
5
+ * packages. It is bundled into the deployed Worker directory instead of the
6
+ * package's public declaration surface, so plain-Node consumers never load
7
+ * `cloudflare:workers`-dependent code.
8
+ */
9
+ type EveHostContainerContext = ConstructorParameters<typeof Container>[0];
10
+ export declare class EveHostContainer extends Container<EveHostContainerEnvironment> {
11
+ defaultPort: 8080;
12
+ requiredPorts: 8080[];
13
+ sleepAfter: "24h";
14
+ entrypoint: ("./node_modules/.bin/eve" | "start" | "--host" | "0.0.0.0" | "--port" | "8080")[];
15
+ enableInternet: boolean;
16
+ pingEndpoint: string;
17
+ readonly lifecycle: import("./eve-host.js").EveHostLifecycleObserver;
18
+ private readinessStarted;
19
+ private readinessEvidence;
20
+ private readonly readiness;
21
+ constructor(ctx: EveHostContainerContext, env: EveHostContainerEnvironment);
22
+ ensureEveReady(signal?: AbortSignal): Promise<EveHostReadinessEvidence>;
23
+ fetch(request: Request): Promise<Response>;
24
+ onStart(): void;
25
+ onStop(params: {
26
+ readonly exitCode: number;
27
+ readonly reason: "exit" | "runtime_signal";
28
+ }): void;
29
+ onError(error: unknown): unknown;
30
+ }
31
+ export type EveHostWorkerEnvironment = EveHostContainerEnvironment;
32
+ export interface EveHostWorkerOptions extends EveHostForwardingMetadata {
33
+ readonly workerName: string;
34
+ readonly containerBindingName: string;
35
+ readonly stableContainerInstanceName: string;
36
+ }
37
+ /**
38
+ * Structural worker-handler shape. Declared locally so the emitted module
39
+ * declarations never reference provider ambient types.
40
+ */
41
+ export interface EveHostWorkerHandler {
42
+ fetch(request: Request, env: EveHostWorkerEnvironment): Promise<Response>;
43
+ }
44
+ export declare function createEveHostWorker(options: EveHostWorkerOptions): EveHostWorkerHandler;
45
+ export {};
46
+ //# sourceMappingURL=eve-host-runtime.d.ts.map
@@ -0,0 +1,127 @@
1
+ import { Container } from "@cloudflare/containers";
2
+ import { EVE_HOST_DEFAULTS, EveHostError, assertNonEmpty, assertStableOrigin, createEveHostLifecycleObserver, createEveReadinessGate, createTrustedEveRequest, IDENTIFIER_PATTERN, readProtectedRuntimeVariables, WORKER_NAME_PATTERN, } from "./eve-host.js";
3
+ export class EveHostContainer extends Container {
4
+ defaultPort = EVE_HOST_DEFAULTS.internalPort;
5
+ requiredPorts = [EVE_HOST_DEFAULTS.internalPort];
6
+ sleepAfter = EVE_HOST_DEFAULTS.sleepAfter;
7
+ entrypoint = [...EVE_HOST_DEFAULTS.startCommand];
8
+ enableInternet = true;
9
+ pingEndpoint = "localhost/eve/v1/health";
10
+ lifecycle = createEveHostLifecycleObserver();
11
+ readinessStarted = false;
12
+ readinessEvidence;
13
+ readiness;
14
+ constructor(ctx, env) {
15
+ super(ctx, env);
16
+ const publicOrigin = env.EVE_PUBLIC_ORIGIN;
17
+ const deploymentId = env.EDEN_EVE_DEPLOYMENT_ID;
18
+ const generationId = env.EDEN_EVE_GENERATION_ID;
19
+ if (publicOrigin === undefined ||
20
+ deploymentId === undefined ||
21
+ generationId === undefined) {
22
+ throw new EveHostError("HOST_ORIGIN_UNAVAILABLE", "The verified public origin and deployment identity must exist before Eve starts.");
23
+ }
24
+ assertStableOrigin(publicOrigin);
25
+ assertNonEmpty(deploymentId, "deployment identity");
26
+ assertNonEmpty(generationId, "generation identity");
27
+ const runtimeEnv = readProtectedRuntimeVariables(env);
28
+ this.envVars = {
29
+ ...runtimeEnv,
30
+ HOST: "0.0.0.0",
31
+ NITRO_HOST: "0.0.0.0",
32
+ PORT: String(EVE_HOST_DEFAULTS.internalPort),
33
+ NITRO_PORT: String(EVE_HOST_DEFAULTS.internalPort),
34
+ NODE_ENV: "production",
35
+ WORKFLOW_LOCAL_BASE_URL: publicOrigin,
36
+ EDEN_EVE_DEPLOYMENT_ID: deploymentId,
37
+ EDEN_EVE_GENERATION_ID: generationId,
38
+ ...(env.EDEN_EVE_RUNTIME_REVISION === undefined
39
+ ? {}
40
+ : { EDEN_EVE_RUNTIME_REVISION: env.EDEN_EVE_RUNTIME_REVISION }),
41
+ };
42
+ this.readiness = createEveReadinessGate({
43
+ startAndWaitForPorts: (options) => this.startAndWaitForPorts(options),
44
+ healthFetch: (request) => this.containerFetch(request, EVE_HOST_DEFAULTS.internalPort),
45
+ });
46
+ }
47
+ async ensureEveReady(signal = new AbortController().signal) {
48
+ if (this.readinessEvidence !== undefined) {
49
+ return this.readinessEvidence;
50
+ }
51
+ if (!this.readinessStarted) {
52
+ this.readinessStarted = true;
53
+ this.lifecycle.record("start_requested");
54
+ }
55
+ const evidence = await this.readiness(signal);
56
+ this.readinessEvidence = evidence;
57
+ this.lifecycle.record("health_ready", evidence.healthStatus);
58
+ return evidence;
59
+ }
60
+ async fetch(request) {
61
+ await this.ensureEveReady(request.signal);
62
+ return super.fetch(request);
63
+ }
64
+ onStart() {
65
+ if (this.lifecycle.events.some((event) => event.type === "started")) {
66
+ this.lifecycle.record("replaced");
67
+ }
68
+ this.lifecycle.record("started");
69
+ }
70
+ onStop(params) {
71
+ this.readinessStarted = false;
72
+ this.readinessEvidence = undefined;
73
+ this.readiness.reset();
74
+ this.lifecycle.record("stopped", `${params.reason}:${params.exitCode}`);
75
+ }
76
+ onError(error) {
77
+ this.readinessStarted = false;
78
+ this.readinessEvidence = undefined;
79
+ this.readiness.reset();
80
+ this.lifecycle.record("errored", error instanceof Error ? error.name : "unknown");
81
+ throw new EveHostError("HOST_READINESS_UNPROVEN", "The Eve Container supervisor reported an error.");
82
+ }
83
+ }
84
+ export function createEveHostWorker(options) {
85
+ if (!WORKER_NAME_PATTERN.test(options.workerName)) {
86
+ throw new EveHostError("HOST_ORIGIN_UNAVAILABLE", "The exact Worker name is not valid.");
87
+ }
88
+ assertStableOrigin(options.publicOrigin, options.workerName);
89
+ assertNonEmpty(options.stableContainerInstanceName, "Container instance name");
90
+ if (!IDENTIFIER_PATTERN.test(options.containerBindingName)) {
91
+ throw new EveHostError("HOST_READINESS_UNPROVEN", "The Container binding name is not valid.");
92
+ }
93
+ return {
94
+ async fetch(request, env) {
95
+ const namespace = env[options.containerBindingName];
96
+ if (namespace === undefined) {
97
+ throw new EveHostError("HOST_READINESS_UNPROVEN", "The configured Container binding is unavailable.");
98
+ }
99
+ const container = namespace.getByName(options.stableContainerInstanceName);
100
+ const forwarded = createTrustedEveRequest(request, {
101
+ publicOrigin: options.publicOrigin,
102
+ deploymentId: options.deploymentId,
103
+ generationId: options.generationId,
104
+ correlationId: globalThis.crypto.randomUUID(),
105
+ ...(options.runtimeRevisionHandle === undefined
106
+ ? {}
107
+ : { runtimeRevisionHandle: options.runtimeRevisionHandle }),
108
+ });
109
+ const response = await container.fetch(forwarded);
110
+ const headers = new Headers(response.headers);
111
+ headers.set("x-eden-eve-worker-name", options.workerName);
112
+ headers.set("x-eden-eve-public-origin", options.publicOrigin);
113
+ headers.set("x-eden-eve-deployment-id", options.deploymentId);
114
+ headers.set("x-eden-eve-generation-id", options.generationId);
115
+ headers.set("x-eden-eve-container-instance", options.stableContainerInstanceName);
116
+ if (options.runtimeRevisionHandle !== undefined) {
117
+ headers.set("x-eden-eve-runtime-revision", options.runtimeRevisionHandle);
118
+ }
119
+ return new Response(response.body, {
120
+ status: response.status,
121
+ statusText: response.statusText,
122
+ headers,
123
+ });
124
+ },
125
+ };
126
+ }
127
+ //# sourceMappingURL=eve-host-runtime.js.map
@@ -0,0 +1,166 @@
1
+ export declare const EVE_HOST_DEFAULTS: {
2
+ readonly compatibilityDate: "2026-04-01";
3
+ readonly healthPath: "/eve/v1/health";
4
+ readonly internalPort: 8080;
5
+ readonly maxInstances: 1;
6
+ readonly startCommand: readonly ["./node_modules/.bin/eve", "start", "--host", "0.0.0.0", "--port", "8080"];
7
+ readonly sleepAfter: "24h";
8
+ };
9
+ 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-public-origin", "x-eden-eve-correlation-id", "x-eden-eve-container-name", "x-eden-eve-container-id", "x-eden-eve-runtime-revision", "x-eden-deployment-id", "x-eden-generation-id", "x-eden-container-name", "x-eden-container-id", "cf-container-target-port"];
10
+ export declare const WORKER_NAME_PATTERN: RegExp;
11
+ export declare const IDENTIFIER_PATTERN: RegExp;
12
+ export type EveHostErrorCode = "HOST_ORIGIN_UNAVAILABLE" | "HOST_REQUEST_ABORTED" | "HOST_READINESS_UNPROVEN" | "HOST_TRANSPORT_UNTESTABLE" | "HOST_WEBSOCKET_UNSUPPORTED";
13
+ export declare class EveHostError extends Error {
14
+ readonly code: EveHostErrorCode;
15
+ constructor(code: EveHostErrorCode, message: string);
16
+ }
17
+ export interface StableWorkersDevOriginRequest {
18
+ readonly workerName: string;
19
+ readonly workersDevSubdomain: string;
20
+ }
21
+ export declare function resolveStableWorkersDevOrigin(request: StableWorkersDevOriginRequest): string;
22
+ export interface EveHostIdentity {
23
+ readonly workerName: string;
24
+ readonly containerApplicationName: string;
25
+ readonly containerClassName: string;
26
+ readonly containerBindingName: string;
27
+ readonly stableContainerInstanceName: string;
28
+ readonly deploymentId: string;
29
+ readonly generationId: string;
30
+ }
31
+ export interface EveHostConfigRequest extends EveHostIdentity {
32
+ readonly accountId?: string;
33
+ readonly stableWorkersDevOrigin: string;
34
+ readonly containerImage: string;
35
+ readonly containerImageBuildContext?: string;
36
+ readonly runtimeVariableNames?: readonly string[];
37
+ readonly runtimeRevisionHandle?: string;
38
+ }
39
+ export interface EveHostWranglerConfig {
40
+ readonly account_id?: string;
41
+ readonly name: string;
42
+ readonly main: string;
43
+ readonly compatibility_date: string;
44
+ readonly workers_dev: true;
45
+ readonly vars: {
46
+ readonly EVE_PUBLIC_ORIGIN: string;
47
+ readonly EVE_CONTAINER_INSTANCE_NAME: string;
48
+ readonly EDEN_EVE_DEPLOYMENT_ID: string;
49
+ readonly EDEN_EVE_GENERATION_ID: string;
50
+ readonly EVE_RUNTIME_VARIABLE_NAMES: readonly string[];
51
+ readonly EDEN_EVE_RUNTIME_REVISION?: string;
52
+ };
53
+ readonly containers: readonly [
54
+ {
55
+ readonly name: string;
56
+ readonly class_name: string;
57
+ readonly image: string;
58
+ readonly image_build_context?: string;
59
+ readonly max_instances: 1;
60
+ }
61
+ ];
62
+ readonly durable_objects: {
63
+ readonly bindings: readonly [
64
+ {
65
+ readonly name: string;
66
+ readonly class_name: string;
67
+ }
68
+ ];
69
+ };
70
+ readonly migrations: readonly [
71
+ {
72
+ readonly tag: "v1";
73
+ readonly new_sqlite_classes: readonly [string];
74
+ }
75
+ ];
76
+ }
77
+ export interface EveHostContainerConfig {
78
+ readonly applicationName: string;
79
+ readonly className: string;
80
+ readonly instanceName: string;
81
+ readonly bindingName: string;
82
+ readonly port: 8080;
83
+ readonly publicOrigin: string;
84
+ readonly deploymentId: string;
85
+ readonly generationId: string;
86
+ readonly runtimeRevisionHandle?: string;
87
+ }
88
+ export interface EveHostConfig {
89
+ readonly worker: EveHostWranglerConfig;
90
+ readonly container: EveHostContainerConfig;
91
+ }
92
+ export interface EveGeneratedWorkerSourceRequest {
93
+ readonly config: EveHostConfig;
94
+ }
95
+ export declare function assertNonEmpty(value: string, subject: string): void;
96
+ export declare function assertStableOrigin(value: string, workerName?: string): void;
97
+ export declare function createEveHostConfig(request: EveHostConfigRequest): EveHostConfig;
98
+ export declare function generateEveHostWorkerSource(request: EveGeneratedWorkerSourceRequest): string;
99
+ export interface EveHostForwardingMetadata {
100
+ readonly publicOrigin: string;
101
+ readonly deploymentId: string;
102
+ readonly generationId: string;
103
+ readonly correlationId: string;
104
+ readonly runtimeRevisionHandle?: string;
105
+ }
106
+ export declare function createTrustedEveRequest(request: Request, metadata: EveHostForwardingMetadata): Request;
107
+ export interface EveContainerTransport {
108
+ readonly containerFetch: (request: Request) => Promise<Response>;
109
+ readonly fetch: (request: Request) => Promise<Response>;
110
+ }
111
+ export interface EveHostProxyOptions extends EveHostForwardingMetadata {
112
+ readonly transport: EveContainerTransport;
113
+ readonly ensureReady: (signal: AbortSignal) => Promise<void>;
114
+ }
115
+ export declare function createEveHostProxy(options: EveHostProxyOptions): (request: Request) => Promise<Response>;
116
+ export interface EveHostLifecycleEvent {
117
+ readonly type: "start_requested" | "started" | "health_ready" | "stopped" | "errored" | "replaced";
118
+ readonly at: number;
119
+ readonly safeStatus?: string;
120
+ }
121
+ export interface EveHostLifecycleObserver {
122
+ readonly events: readonly EveHostLifecycleEvent[];
123
+ record(type: EveHostLifecycleEvent["type"], safeStatus?: string): EveHostLifecycleEvent;
124
+ }
125
+ export declare function createEveHostLifecycleObserver(now?: () => number): EveHostLifecycleObserver;
126
+ export interface EveHostContainerEnvironment {
127
+ readonly [name: string]: unknown;
128
+ readonly EVE_RUNTIME_VARIABLE_NAMES?: readonly string[];
129
+ readonly EVE_PUBLIC_ORIGIN?: string;
130
+ readonly EVE_CONTAINER_INSTANCE_NAME?: string;
131
+ readonly EDEN_EVE_DEPLOYMENT_ID?: string;
132
+ readonly EDEN_EVE_GENERATION_ID?: string;
133
+ readonly EDEN_EVE_RUNTIME_REVISION?: string;
134
+ }
135
+ export interface EveHostReadinessEvidence {
136
+ readonly healthPath: "/eve/v1/health";
137
+ readonly healthStatus: "ready";
138
+ readonly healthVerified: true;
139
+ readonly port: 8080;
140
+ readonly checkedAt: string;
141
+ }
142
+ export interface EveHostReadinessOptions {
143
+ readonly startAndWaitForPorts: (options: {
144
+ readonly ports: 8080;
145
+ readonly cancellationOptions: {
146
+ readonly abort: AbortSignal;
147
+ readonly instanceGetTimeoutMS: number;
148
+ readonly portReadyTimeoutMS: number;
149
+ readonly waitInterval: number;
150
+ };
151
+ }) => Promise<void>;
152
+ readonly healthFetch: (request: Request) => Promise<Response>;
153
+ readonly healthPath?: "/eve/v1/health";
154
+ readonly port?: 8080;
155
+ readonly instanceGetTimeoutMs?: number;
156
+ readonly portReadyTimeoutMs?: number;
157
+ readonly healthTimeoutMs?: number;
158
+ readonly waitIntervalMs?: number;
159
+ }
160
+ export interface EveReadinessGate {
161
+ (signal: AbortSignal): Promise<EveHostReadinessEvidence>;
162
+ reset(): void;
163
+ }
164
+ export declare function readProtectedRuntimeVariables(env: EveHostContainerEnvironment): Record<string, string>;
165
+ export declare function createEveReadinessGate(options: EveHostReadinessOptions): EveReadinessGate;
166
+ //# sourceMappingURL=eve-host.d.ts.map