@moinulmoin/eden-runtime-cloudflare 0.11.1 → 0.11.3
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/dist/eden-eve-host-worker.mjs +54 -19
- package/dist/eve-host-runtime.js +37 -14
- package/dist/eve-host.js +4 -0
- package/package.json +2 -2
|
@@ -24497,6 +24497,7 @@ var init_core3 = __esm({
|
|
|
24497
24497
|
waitUntil;
|
|
24498
24498
|
retireDeployment;
|
|
24499
24499
|
currentDeploymentId;
|
|
24500
|
+
isDeploymentRemoved;
|
|
24500
24501
|
constructor(opts) {
|
|
24501
24502
|
this.sql = opts.sql;
|
|
24502
24503
|
this.delivery = opts.delivery;
|
|
@@ -24506,6 +24507,7 @@ var init_core3 = __esm({
|
|
|
24506
24507
|
});
|
|
24507
24508
|
this.retireDeployment = opts.retireDeployment;
|
|
24508
24509
|
this.currentDeploymentId = opts.currentDeploymentId;
|
|
24510
|
+
this.isDeploymentRemoved = opts.isDeploymentRemoved;
|
|
24509
24511
|
}
|
|
24510
24512
|
rows(query, ...args) {
|
|
24511
24513
|
return this.sql.exec(query, ...args).toArray();
|
|
@@ -24573,8 +24575,8 @@ var init_core3 = __esm({
|
|
|
24573
24575
|
return WorkflowRunSchema.parse(value);
|
|
24574
24576
|
}
|
|
24575
24577
|
assertDeploymentActive(deploymentId) {
|
|
24576
|
-
if (this.rows("SELECT deployment_id FROM workflow_retired_deployments WHERE deployment_id=?", deploymentId).length)
|
|
24577
|
-
throw new WorkflowWorldError(`Deployment ${deploymentId} has been retired
|
|
24578
|
+
if (this.isDeploymentRemoved?.(deploymentId) || this.rows("SELECT deployment_id FROM workflow_retired_deployments WHERE deployment_id=?", deploymentId).length)
|
|
24579
|
+
throw new WorkflowWorldError(`Deployment ${deploymentId} has been retired; its sessions ended. Start a new session.`, { status: 409 });
|
|
24578
24580
|
}
|
|
24579
24581
|
deliverySettled(messageId, attempt) {
|
|
24580
24582
|
this.sql.exec("UPDATE workflow_delivery_claims SET settled=1 WHERE message_id=? AND attempt=?", messageId, attempt);
|
|
@@ -25368,11 +25370,20 @@ var init_core3 = __esm({
|
|
|
25368
25370
|
const body = sqlBytes(row.body);
|
|
25369
25371
|
const message = this.queueMessage(body);
|
|
25370
25372
|
const deploymentId = this.queueTarget(message, row.deployment_id == null ? void 0 : String(row.deployment_id));
|
|
25371
|
-
this.assertDeploymentActive(deploymentId);
|
|
25372
|
-
this.sql.exec("UPDATE workflow_queue_messages SET deployment_id=? WHERE id=?", deploymentId, id);
|
|
25373
25373
|
let transfer = this.rows("SELECT * FROM workflow_sandbox_transfers WHERE message_id=?", id)[0];
|
|
25374
25374
|
const sandbox = transfer ? void 0 : this.successorSandbox(message);
|
|
25375
|
-
const
|
|
25375
|
+
const source = transfer ? String(transfer.source_deployment_id) : sandbox?.sourceDeploymentId ?? (row.source_deployment_id == null ? void 0 : String(row.source_deployment_id));
|
|
25376
|
+
if (this.isDeploymentRemoved?.(deploymentId) || source && this.isDeploymentRemoved?.(source) || this.rows("SELECT deployment_id FROM workflow_retired_deployments WHERE deployment_id=? OR deployment_id=?", deploymentId, source ?? deploymentId).length) {
|
|
25377
|
+
this.atomic(() => {
|
|
25378
|
+
this.sql.exec("UPDATE workflow_sandbox_transfers SET completed=-1 WHERE message_id=? AND completed=0", id);
|
|
25379
|
+
this.deliverySettled(id, attempt);
|
|
25380
|
+
this.sql.exec("UPDATE workflow_queue_messages SET completed=1,idempotency_key=NULL,lease_until=0 WHERE id=?", id);
|
|
25381
|
+
});
|
|
25382
|
+
return;
|
|
25383
|
+
}
|
|
25384
|
+
this.assertDeploymentActive(deploymentId);
|
|
25385
|
+
this.sql.exec("UPDATE workflow_queue_messages SET deployment_id=? WHERE id=?", deploymentId, id);
|
|
25386
|
+
const sourceDeploymentId = source;
|
|
25376
25387
|
if (sandbox && sourceDeploymentId && sourceDeploymentId !== deploymentId) {
|
|
25377
25388
|
this.assertDeploymentActive(sourceDeploymentId);
|
|
25378
25389
|
this.sql.exec("UPDATE workflow_queue_messages SET source_deployment_id=? WHERE id=?", sourceDeploymentId, id);
|
|
@@ -25443,7 +25454,7 @@ var init_core3 = __esm({
|
|
|
25443
25454
|
if (this.currentDeploymentId && ids.includes(this.currentDeploymentId))
|
|
25444
25455
|
throw new WorkflowWorldError("Cannot retire the current deployment", { status: 409 });
|
|
25445
25456
|
const states = this.drainState(ids);
|
|
25446
|
-
if (ids.some((id) => !states[id].drained))
|
|
25457
|
+
if (ids.some((id) => !this.isDeploymentRemoved?.(id) && !states[id].drained))
|
|
25447
25458
|
throw new WorkflowWorldError("Cannot retire a deployment with live runs, queued messages, or unfinished transfers", { status: 409 });
|
|
25448
25459
|
if (!this.retireDeployment)
|
|
25449
25460
|
throw new WorkflowWorldError("Deployment retirement is unavailable", { status: 501 });
|
|
@@ -25827,6 +25838,10 @@ var RESERVED_EVE_HOST_VARIABLES = /* @__PURE__ */ new Set([
|
|
|
25827
25838
|
"PORT",
|
|
25828
25839
|
"NITRO_PORT",
|
|
25829
25840
|
"NODE_ENV",
|
|
25841
|
+
"EVE_DEV",
|
|
25842
|
+
"VERCEL",
|
|
25843
|
+
"VERCEL_ENV",
|
|
25844
|
+
"VERCEL_TARGET_ENV",
|
|
25830
25845
|
"NODE_EXTRA_CA_CERTS",
|
|
25831
25846
|
"WORKFLOW_LOCAL_BASE_URL",
|
|
25832
25847
|
"EDEN_WORLD_URL",
|
|
@@ -26131,7 +26146,7 @@ async function publish(from, to) {
|
|
|
26131
26146
|
var EVE_HOST_ENTRYPOINT = Object.freeze([
|
|
26132
26147
|
"/bin/sh",
|
|
26133
26148
|
"-c",
|
|
26134
|
-
"rm -f /dev/kvm; cd /workspace && exec ./node_modules/.bin/eve start --host 0.0.0.0 --port 8080"
|
|
26149
|
+
"unset EVE_DEV VERCEL VERCEL_ENV VERCEL_TARGET_ENV; rm -f /dev/kvm; cd /workspace && exec ./node_modules/.bin/eve start --host 0.0.0.0 --port 8080"
|
|
26135
26150
|
]);
|
|
26136
26151
|
var EVE_HOST_CONTAINER_ACTIVITY_KEY = "eden.eve.host.last-activity-at";
|
|
26137
26152
|
var EVE_HOST_CONTAINER_SNAPSHOT_KEY = "eden.eve.host.workspace-snapshot";
|
|
@@ -26154,6 +26169,9 @@ var EdenWorldDurableObject = class extends DurableObject {
|
|
|
26154
26169
|
super(ctx, env);
|
|
26155
26170
|
this.core = new WorldCore({
|
|
26156
26171
|
...env.EDEN_EVE_DEPLOYMENT_ID === void 0 ? {} : { currentDeploymentId: env.EDEN_EVE_DEPLOYMENT_ID },
|
|
26172
|
+
// The published route table is authoritative, including before cleanup
|
|
26173
|
+
// has finished fencing and deleting an insecure legacy container.
|
|
26174
|
+
isDeploymentRemoved: (id) => env.EDEN_EVE_DEPLOYMENTS !== void 0 && id !== env.EDEN_EVE_DEPLOYMENT_ID && deploymentImages(env)[id] === void 0,
|
|
26157
26175
|
sql: {
|
|
26158
26176
|
exec: ctx.storage.sql.exec.bind(ctx.storage.sql),
|
|
26159
26177
|
transactionSync: ctx.storage.transactionSync.bind(ctx.storage)
|
|
@@ -26274,16 +26292,16 @@ async function routeEveOutboundRequest(request, env, sourceDeploymentId, expecte
|
|
|
26274
26292
|
}
|
|
26275
26293
|
if (new URL(request.url).pathname === "/__eden/world/rpc") {
|
|
26276
26294
|
const route = deploymentImages(env)[deploymentId];
|
|
26277
|
-
|
|
26278
|
-
|
|
26279
|
-
|
|
26280
|
-
|
|
26281
|
-
|
|
26282
|
-
|
|
26283
|
-
|
|
26284
|
-
|
|
26285
|
-
|
|
26286
|
-
}
|
|
26295
|
+
if (env.EDEN_EVE_DEPLOYMENTS !== void 0 && route === void 0) {
|
|
26296
|
+
return new Response("Deployment retired; its sessions ended.", { status: 403 });
|
|
26297
|
+
}
|
|
26298
|
+
const supplied = request.headers.get("x-eden-world-token") ?? "";
|
|
26299
|
+
const encoder = new TextEncoder();
|
|
26300
|
+
const expected = encoder.encode(expectedWorldToken ?? "");
|
|
26301
|
+
const actual = encoder.encode(supplied);
|
|
26302
|
+
const subtle = crypto.subtle;
|
|
26303
|
+
if (expected.length === 0 || actual.length !== expected.length || !subtle.timingSafeEqual(actual, expected)) {
|
|
26304
|
+
return new Response(null, { status: 403 });
|
|
26287
26305
|
}
|
|
26288
26306
|
const world = env.EDEN_WORLD;
|
|
26289
26307
|
if (world === void 0) return new Response(null, { status: 404 });
|
|
@@ -26355,6 +26373,9 @@ var EveHostDurableContainer = class extends DurableObject {
|
|
|
26355
26373
|
throw new Error("The Container deployment identity does not match its persisted owner.");
|
|
26356
26374
|
}
|
|
26357
26375
|
const record2 = deploymentImages(this.env)[id];
|
|
26376
|
+
if (affinity && record2 === void 0) {
|
|
26377
|
+
throw new Error(`Deployment ${id} has been retired; its sessions ended. Start a new session.`);
|
|
26378
|
+
}
|
|
26358
26379
|
if (stored === void 0) await this.ctx.storage.put("eden.eve.host.deployment-id", id);
|
|
26359
26380
|
this.deploymentId = id;
|
|
26360
26381
|
this.envVars.EDEN_EVE_DEPLOYMENT_ID = id;
|
|
@@ -26442,7 +26463,7 @@ var EveHostDurableContainer = class extends DurableObject {
|
|
|
26442
26463
|
const id = this.deploymentId;
|
|
26443
26464
|
if (id === void 0) throw new Error("Container deployment identity has not been resolved.");
|
|
26444
26465
|
const record2 = deploymentImages(this.env)[id];
|
|
26445
|
-
if (this.env.EDEN_EVE_DEPLOYMENTS !== void 0 && record2 === void 0
|
|
26466
|
+
if (this.env.EDEN_EVE_DEPLOYMENTS !== void 0 && record2 === void 0) throw new Error(`Deployment ${id} has no retained Container image.`);
|
|
26446
26467
|
return runtime.images[record2?.image ?? "eve"];
|
|
26447
26468
|
}
|
|
26448
26469
|
constructor(ctx, env) {
|
|
@@ -26503,6 +26524,15 @@ var EveHostDurableContainer = class extends DurableObject {
|
|
|
26503
26524
|
if (runtime?.running === true) {
|
|
26504
26525
|
this.ctx.blockConcurrencyWhile(async () => {
|
|
26505
26526
|
if (env.EDEN_EVE_DEPLOYMENTS !== void 0) {
|
|
26527
|
+
const stored = await this.ctx.storage.get("eden.eve.host.deployment-id");
|
|
26528
|
+
const namespace = env.EVE_CONTAINER;
|
|
26529
|
+
const owner = stored ?? (this.ctx.id.equals(namespace.idFromName(env.EVE_CONTAINER_INSTANCE_NAME)) ? "eden-cloudflare" : void 0);
|
|
26530
|
+
if (owner !== void 0 && deploymentImages(env)[owner] === void 0) {
|
|
26531
|
+
await runtime.destroy(new Error("deployment-retired"));
|
|
26532
|
+
this.recordContainerStopped();
|
|
26533
|
+
await this.ctx.storage.deleteAlarm();
|
|
26534
|
+
return;
|
|
26535
|
+
}
|
|
26506
26536
|
await this.identifyDeployment();
|
|
26507
26537
|
await this.registerLoopbackIntercept(runtime);
|
|
26508
26538
|
}
|
|
@@ -26956,7 +26986,12 @@ var EveHostDurableContainer = class extends DurableObject {
|
|
|
26956
26986
|
return response;
|
|
26957
26987
|
}
|
|
26958
26988
|
async retire(deploymentId) {
|
|
26959
|
-
|
|
26989
|
+
const removed = this.env.EDEN_EVE_DEPLOYMENTS !== void 0 && deploymentId !== this.env.EDEN_EVE_DEPLOYMENT_ID && deploymentImages(this.env)[deploymentId] === void 0;
|
|
26990
|
+
const namespace = this.env.EVE_CONTAINER;
|
|
26991
|
+
if (!this.ctx.id.equals(namespace.idFromName(deploymentInstance(this.env, deploymentId)))) {
|
|
26992
|
+
throw new Error("The retirement target does not match its Container instance.");
|
|
26993
|
+
}
|
|
26994
|
+
if (!removed && await this.deploymentBusy(deploymentId)) {
|
|
26960
26995
|
throw new Error("Cannot retire a deployment with active deliveries or transfers.");
|
|
26961
26996
|
}
|
|
26962
26997
|
const runtime = this.containerRuntime();
|
package/dist/eve-host-runtime.js
CHANGED
|
@@ -92,7 +92,7 @@ async function publish(from, to) {
|
|
|
92
92
|
const EVE_HOST_ENTRYPOINT = Object.freeze([
|
|
93
93
|
"/bin/sh",
|
|
94
94
|
"-c",
|
|
95
|
-
"rm -f /dev/kvm; cd /workspace && exec ./node_modules/.bin/eve start --host 0.0.0.0 --port 8080",
|
|
95
|
+
"unset EVE_DEV VERCEL VERCEL_ENV VERCEL_TARGET_ENV; rm -f /dev/kvm; cd /workspace && exec ./node_modules/.bin/eve start --host 0.0.0.0 --port 8080",
|
|
96
96
|
]);
|
|
97
97
|
/** Durable Object storage keys owned by `EveHostDurableContainer`. */
|
|
98
98
|
const EVE_HOST_CONTAINER_ACTIVITY_KEY = "eden.eve.host.last-activity-at";
|
|
@@ -138,6 +138,10 @@ export class EdenWorldDurableObject extends DurableObject {
|
|
|
138
138
|
super(ctx, env);
|
|
139
139
|
this.core = new WorldCore({
|
|
140
140
|
...(env.EDEN_EVE_DEPLOYMENT_ID === undefined ? {} : { currentDeploymentId: env.EDEN_EVE_DEPLOYMENT_ID }),
|
|
141
|
+
// The published route table is authoritative, including before cleanup
|
|
142
|
+
// has finished fencing and deleting an insecure legacy container.
|
|
143
|
+
isDeploymentRemoved: (id) => env.EDEN_EVE_DEPLOYMENTS !== undefined &&
|
|
144
|
+
id !== env.EDEN_EVE_DEPLOYMENT_ID && deploymentImages(env)[id] === undefined,
|
|
141
145
|
sql: {
|
|
142
146
|
exec: ctx.storage.sql.exec.bind(ctx.storage.sql),
|
|
143
147
|
transactionSync: ctx.storage.transactionSync.bind(ctx.storage),
|
|
@@ -281,17 +285,16 @@ export async function routeEveOutboundRequest(request, env, sourceDeploymentId,
|
|
|
281
285
|
}
|
|
282
286
|
if (new URL(request.url).pathname === "/__eden/world/rpc") {
|
|
283
287
|
const route = deploymentImages(env)[deploymentId];
|
|
284
|
-
|
|
285
|
-
(
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
288
|
+
if (env.EDEN_EVE_DEPLOYMENTS !== undefined && route === undefined) {
|
|
289
|
+
return new Response("Deployment retired; its sessions ended.", { status: 403 });
|
|
290
|
+
}
|
|
291
|
+
const supplied = request.headers.get("x-eden-world-token") ?? "";
|
|
292
|
+
const encoder = new TextEncoder();
|
|
293
|
+
const expected = encoder.encode(expectedWorldToken ?? "");
|
|
294
|
+
const actual = encoder.encode(supplied);
|
|
295
|
+
const subtle = crypto.subtle;
|
|
296
|
+
if (expected.length === 0 || actual.length !== expected.length || !subtle.timingSafeEqual(actual, expected)) {
|
|
297
|
+
return new Response(null, { status: 403 });
|
|
295
298
|
}
|
|
296
299
|
const world = env.EDEN_WORLD;
|
|
297
300
|
if (world === undefined)
|
|
@@ -383,6 +386,9 @@ export class EveHostDurableContainer extends DurableObject {
|
|
|
383
386
|
throw new Error("The Container deployment identity does not match its persisted owner.");
|
|
384
387
|
}
|
|
385
388
|
const record = deploymentImages(this.env)[id];
|
|
389
|
+
if (affinity && record === undefined) {
|
|
390
|
+
throw new Error(`Deployment ${id} has been retired; its sessions ended. Start a new session.`);
|
|
391
|
+
}
|
|
386
392
|
if (stored === undefined)
|
|
387
393
|
await this.ctx.storage.put("eden.eve.host.deployment-id", id);
|
|
388
394
|
this.deploymentId = id;
|
|
@@ -481,7 +487,7 @@ export class EveHostDurableContainer extends DurableObject {
|
|
|
481
487
|
if (id === undefined)
|
|
482
488
|
throw new Error("Container deployment identity has not been resolved.");
|
|
483
489
|
const record = deploymentImages(this.env)[id];
|
|
484
|
-
if (this.env.EDEN_EVE_DEPLOYMENTS !== undefined && record === undefined
|
|
490
|
+
if (this.env.EDEN_EVE_DEPLOYMENTS !== undefined && record === undefined)
|
|
485
491
|
throw new Error(`Deployment ${id} has no retained Container image.`);
|
|
486
492
|
return runtime.images[record?.image ?? "eve"];
|
|
487
493
|
}
|
|
@@ -543,6 +549,17 @@ export class EveHostDurableContainer extends DurableObject {
|
|
|
543
549
|
// container generation is also gone, so both are re-attached here.
|
|
544
550
|
this.ctx.blockConcurrencyWhile(async () => {
|
|
545
551
|
if (env.EDEN_EVE_DEPLOYMENTS !== undefined) {
|
|
552
|
+
const stored = await this.ctx.storage.get("eden.eve.host.deployment-id");
|
|
553
|
+
const namespace = env.EVE_CONTAINER;
|
|
554
|
+
const owner = stored ?? (this.ctx.id.equals(namespace.idFromName(env.EVE_CONTAINER_INSTANCE_NAME)) ? "eden-cloudflare" : undefined);
|
|
555
|
+
if (owner !== undefined && deploymentImages(env)[owner] === undefined) {
|
|
556
|
+
// Removed routes must not make the constructor fail before the
|
|
557
|
+
// retirement RPC can destroy a still-running legacy container.
|
|
558
|
+
await runtime.destroy(new Error("deployment-retired"));
|
|
559
|
+
this.recordContainerStopped();
|
|
560
|
+
await this.ctx.storage.deleteAlarm();
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
546
563
|
await this.identifyDeployment();
|
|
547
564
|
await this.registerLoopbackIntercept(runtime);
|
|
548
565
|
}
|
|
@@ -1021,7 +1038,13 @@ export class EveHostDurableContainer extends DurableObject {
|
|
|
1021
1038
|
async retire(deploymentId) {
|
|
1022
1039
|
// World routes the fenced target to its named DO. Retirement must not
|
|
1023
1040
|
// restore or trust a stored owner left by an earlier retirement attempt.
|
|
1024
|
-
|
|
1041
|
+
const removed = this.env.EDEN_EVE_DEPLOYMENTS !== undefined &&
|
|
1042
|
+
deploymentId !== this.env.EDEN_EVE_DEPLOYMENT_ID && deploymentImages(this.env)[deploymentId] === undefined;
|
|
1043
|
+
const namespace = this.env.EVE_CONTAINER;
|
|
1044
|
+
if (!this.ctx.id.equals(namespace.idFromName(deploymentInstance(this.env, deploymentId)))) {
|
|
1045
|
+
throw new Error("The retirement target does not match its Container instance.");
|
|
1046
|
+
}
|
|
1047
|
+
if (!removed && await this.deploymentBusy(deploymentId)) {
|
|
1025
1048
|
throw new Error("Cannot retire a deployment with active deliveries or transfers.");
|
|
1026
1049
|
}
|
|
1027
1050
|
const runtime = this.containerRuntime();
|
package/dist/eve-host.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moinulmoin/eden-runtime-cloudflare",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.3",
|
|
4
4
|
"description": "Cloudflare Worker/Container host runtime for Eden's Eve deployments.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"NOTICE"
|
|
21
21
|
],
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@moinulmoin/eden-world-cloudflare": "0.11.
|
|
23
|
+
"@moinulmoin/eden-world-cloudflare": "0.11.3",
|
|
24
24
|
"@cloudflare/workers-types": "5.20261006.1"
|
|
25
25
|
},
|
|
26
26
|
"repository": {
|