@moinulmoin/eden-runtime-cloudflare 0.1.5 → 0.2.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 (47) hide show
  1. package/NOTICE +0 -31
  2. package/dist/eden-eve-host-worker.mjs +1 -9
  3. package/dist/eve-host-runtime.d.ts +0 -1
  4. package/dist/eve-host-runtime.js +0 -1
  5. package/dist/eve-host.d.ts +2 -1
  6. package/dist/eve-host.js +2 -8
  7. package/dist/index.d.ts +0 -18
  8. package/dist/index.js +0 -5
  9. package/package.json +2 -6
  10. package/dist/artifact-runtime.d.ts +0 -27
  11. package/dist/artifact-runtime.js +0 -14
  12. package/dist/http-host.d.ts +0 -6
  13. package/dist/http-host.js +0 -419
  14. package/dist/model-adapter-internal.d.ts +0 -12
  15. package/dist/model-adapter-internal.js +0 -172
  16. package/dist/model-adapter.d.ts +0 -9
  17. package/dist/model-adapter.js +0 -56
  18. package/dist/model-contracts.d.ts +0 -92
  19. package/dist/model-contracts.js +0 -2
  20. package/dist/model-normalizers.d.ts +0 -7
  21. package/dist/model-normalizers.js +0 -453
  22. package/dist/session-checkpoint.d.ts +0 -48
  23. package/dist/session-checkpoint.js +0 -300
  24. package/dist/session-identity.d.ts +0 -9
  25. package/dist/session-identity.js +0 -45
  26. package/dist/session-jobs.d.ts +0 -69
  27. package/dist/session-jobs.js +0 -427
  28. package/dist/session-journal.d.ts +0 -154
  29. package/dist/session-journal.js +0 -391
  30. package/dist/session-schema.d.ts +0 -21
  31. package/dist/session-schema.js +0 -247
  32. package/dist/session-state.d.ts +0 -165
  33. package/dist/session-state.js +0 -168
  34. package/dist/session.d.ts +0 -40
  35. package/dist/session.js +0 -792
  36. package/dist/test-execution.d.ts +0 -8
  37. package/dist/test-execution.js +0 -12
  38. package/dist/test-worker.d.ts +0 -12
  39. package/dist/test-worker.js +0 -214
  40. package/dist/tool-harness.d.ts +0 -31
  41. package/dist/tool-harness.js +0 -226
  42. package/dist/turn-runner-storage.d.ts +0 -28
  43. package/dist/turn-runner-storage.js +0 -583
  44. package/dist/turn-runner-types.d.ts +0 -112
  45. package/dist/turn-runner-types.js +0 -21
  46. package/dist/turn-runner.d.ts +0 -6
  47. package/dist/turn-runner.js +0 -370
package/NOTICE CHANGED
@@ -1,24 +1,6 @@
1
- eve
2
- Copyright 2026 Vercel, Inc. and contributors
3
-
4
- This product includes software developed at Vercel, Inc.
5
- (https://vercel.com/).
6
-
7
1
  Eden
8
2
  Copyright 2026 Eden contributors
9
3
 
10
- This repository contains Eden-owned modified derivative implementations
11
- informed by portable concepts from the Eve framework:
12
-
13
- Eve, version 0.31.3
14
- https://github.com/vercel/eve
15
- reference commit: 0b102bc90e7cf2c3e294f6ca3af86c307d449b1a
16
-
17
- Eve is distributed under the Apache License, Version 2.0. The applicable
18
- Apache-2.0 terms are included in LICENSE. This notice is retained for the
19
- Eve attribution obligation; it does not grant ownership of Eden's original
20
- implementation.
21
-
22
4
  Cloudflare Containers
23
5
  @cloudflare/containers, version 0.3.7
24
6
  https://github.com/cloudflare/containers
@@ -27,16 +9,3 @@ Eden's generated Worker host bundle includes software from
27
9
  `@cloudflare/containers`, distributed under MIT OR Apache-2.0. Eden
28
10
  redistributes that bundled software under the Apache-2.0 option included in
29
11
  LICENSE.
30
-
31
- The following Eden source files are marked in-file as modified derivatives of
32
- portable Eve concepts:
33
-
34
- packages/definitions/src/index.ts
35
- packages/compiler/src/index.ts
36
- packages/client/src/protocol.ts
37
- packages/runtime-cloudflare/src/session-journal.ts
38
- packages/runtime-cloudflare/src/model-normalizers.ts
39
-
40
- Eden does not include unmodified Eve source. The listed files are Eden-owned
41
- modifications and must retain their in-file modified-derivative notices when
42
- redistributed.
@@ -1417,14 +1417,7 @@ var EVE_HOST_DEFAULTS = {
1417
1417
  healthPath: "/eve/v1/health",
1418
1418
  internalPort: 8080,
1419
1419
  maxInstances: 1,
1420
- startCommand: [
1421
- "./node_modules/.bin/eve",
1422
- "start",
1423
- "--host",
1424
- "0.0.0.0",
1425
- "--port",
1426
- "8080"
1427
- ],
1420
+ instanceType: "basic",
1428
1421
  sleepAfter: "24h"
1429
1422
  };
1430
1423
  var EVE_HOST_OWNED_HEADERS = [
@@ -1814,7 +1807,6 @@ var EveHostContainer = class extends Container {
1814
1807
  defaultPort = EVE_HOST_DEFAULTS.internalPort;
1815
1808
  requiredPorts = [EVE_HOST_DEFAULTS.internalPort];
1816
1809
  sleepAfter = EVE_HOST_DEFAULTS.sleepAfter;
1817
- entrypoint = [...EVE_HOST_DEFAULTS.startCommand];
1818
1810
  enableInternet = true;
1819
1811
  pingEndpoint = "localhost/eve/v1/health";
1820
1812
  lifecycle = createEveHostLifecycleObserver();
@@ -11,7 +11,6 @@ export declare class EveHostContainer extends Container<EveHostContainerEnvironm
11
11
  defaultPort: 8080;
12
12
  requiredPorts: 8080[];
13
13
  sleepAfter: "24h";
14
- entrypoint: ("./node_modules/.bin/eve" | "start" | "--host" | "0.0.0.0" | "--port" | "8080")[];
15
14
  enableInternet: boolean;
16
15
  pingEndpoint: string;
17
16
  readonly lifecycle: import("./eve-host.js").EveHostLifecycleObserver;
@@ -4,7 +4,6 @@ export class EveHostContainer extends Container {
4
4
  defaultPort = EVE_HOST_DEFAULTS.internalPort;
5
5
  requiredPorts = [EVE_HOST_DEFAULTS.internalPort];
6
6
  sleepAfter = EVE_HOST_DEFAULTS.sleepAfter;
7
- entrypoint = [...EVE_HOST_DEFAULTS.startCommand];
8
7
  enableInternet = true;
9
8
  pingEndpoint = "localhost/eve/v1/health";
10
9
  lifecycle = createEveHostLifecycleObserver();
@@ -3,7 +3,7 @@ export declare const EVE_HOST_DEFAULTS: {
3
3
  readonly healthPath: "/eve/v1/health";
4
4
  readonly internalPort: 8080;
5
5
  readonly maxInstances: 1;
6
- readonly startCommand: readonly ["./node_modules/.bin/eve", "start", "--host", "0.0.0.0", "--port", "8080"];
6
+ readonly instanceType: "basic";
7
7
  readonly sleepAfter: "24h";
8
8
  };
9
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"];
@@ -57,6 +57,7 @@ export interface EveHostWranglerConfig {
57
57
  readonly image: string;
58
58
  readonly image_build_context?: string;
59
59
  readonly max_instances: 1;
60
+ readonly instance_type: "basic";
60
61
  }
61
62
  ];
62
63
  readonly durable_objects: {
package/dist/eve-host.js CHANGED
@@ -3,14 +3,7 @@ export const EVE_HOST_DEFAULTS = {
3
3
  healthPath: "/eve/v1/health",
4
4
  internalPort: 8080,
5
5
  maxInstances: 1,
6
- startCommand: [
7
- "./node_modules/.bin/eve",
8
- "start",
9
- "--host",
10
- "0.0.0.0",
11
- "--port",
12
- "8080",
13
- ],
6
+ instanceType: "basic",
14
7
  sleepAfter: "24h",
15
8
  };
16
9
  export const EVE_HOST_OWNED_HEADERS = [
@@ -141,6 +134,7 @@ export function createEveHostConfig(request) {
141
134
  ? {}
142
135
  : { image_build_context: request.containerImageBuildContext }),
143
136
  max_instances: EVE_HOST_DEFAULTS.maxInstances,
137
+ instance_type: EVE_HOST_DEFAULTS.instanceType,
144
138
  };
145
139
  return {
146
140
  worker: {
package/dist/index.d.ts CHANGED
@@ -1,21 +1,3 @@
1
- import type { EdenEvent, EdenEventType, EdenSessionSnapshot, EdenVersionSet } from "@moinulmoin/eden-definitions";
2
- export { configureEdenArtifact, readConfiguredEdenArtifact, } from "./artifact-runtime.js";
3
- export type { EdenArtifactGenerationMetadata, EdenConfiguredArtifact, EdenRuntimeAgentArtifact, } from "./artifact-runtime.js";
4
- export type { EdenEvent, EdenEventDataByType, EdenEventType, EdenSessionSnapshot, EdenVersionSet, } from "@moinulmoin/eden-definitions";
5
- export { createModelAdapter, normalizeEdenJsonValue, normalizeModelFailure, normalizeModelMessages, normalizeModelResult, } from "./model-adapter.js";
6
- export type { EdenModelAdapter, EdenModelCorrelation, EdenModelFailure, EdenModelFailureCode, EdenModelFinishReason, EdenModelMessage, EdenModelMessagePart, EdenModelOptions, EdenModelOutcome, EdenModelAdapterCall, EdenModelAdapterRequest, EdenModelRequest, EdenModelResult, EdenModelRole, EdenModelToolCall, EdenModelToolChoice, EdenModelToolDefinition, EdenModelToolResult, EdenModelUsage, } from "./model-adapter.js";
7
- export interface EdenRuntimeConfiguration {
8
- readonly versions: EdenVersionSet;
9
- }
10
- export interface EdenSessionStore {
11
- createSession(): Promise<EdenSessionSnapshot>;
12
- readEvents(sessionId: string, startIndex?: number): Promise<readonly EdenEvent<EdenEventType>[]>;
13
- }
14
- export interface EdenRuntime {
15
- readonly configuration: EdenRuntimeConfiguration;
16
- readonly sessions: EdenSessionStore;
17
- }
18
- export declare function createRuntime(configuration: EdenRuntimeConfiguration, sessions: EdenSessionStore): EdenRuntime;
19
1
  export { EVE_HOST_DEFAULTS, EVE_HOST_OWNED_HEADERS, EveHostError, createEveHostConfig, createEveHostLifecycleObserver, createEveHostProxy, createEveReadinessGate, createTrustedEveRequest, generateEveHostWorkerSource, resolveStableWorkersDevOrigin, } from "./eve-host.js";
20
2
  export type { EveContainerTransport, EveHostConfig, EveHostConfigRequest, EveHostContainerConfig, EveHostContainerEnvironment, EveHostErrorCode, EveHostForwardingMetadata, EveHostIdentity, EveHostLifecycleEvent, EveHostLifecycleObserver, EveHostProxyOptions, EveHostReadinessEvidence, EveHostReadinessOptions, EveReadinessGate, EveHostWranglerConfig, EveGeneratedWorkerSourceRequest, StableWorkersDevOriginRequest, } from "./eve-host.js";
21
3
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,7 +1,2 @@
1
- export { configureEdenArtifact, readConfiguredEdenArtifact, } from "./artifact-runtime.js";
2
- export { createModelAdapter, normalizeEdenJsonValue, normalizeModelFailure, normalizeModelMessages, normalizeModelResult, } from "./model-adapter.js";
3
- export function createRuntime(configuration, sessions) {
4
- return { configuration, sessions };
5
- }
6
1
  export { EVE_HOST_DEFAULTS, EVE_HOST_OWNED_HEADERS, EveHostError, createEveHostConfig, createEveHostLifecycleObserver, createEveHostProxy, createEveReadinessGate, createTrustedEveRequest, generateEveHostWorkerSource, resolveStableWorkersDevOrigin, } from "./eve-host.js";
7
2
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moinulmoin/eden-runtime-cloudflare",
3
- "version": "0.1.5",
4
- "description": "Cloudflare runtime for Eden Deploy and Eden Agent.",
3
+ "version": "0.2.0",
4
+ "description": "Cloudflare Worker/Container host runtime for Eden's Eve deployments.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
7
7
  "types": "./dist/index.d.ts",
@@ -19,12 +19,8 @@
19
19
  "LICENSE",
20
20
  "NOTICE"
21
21
  ],
22
- "dependencies": {
23
- "@moinulmoin/eden-definitions": "0.1.5"
24
- },
25
22
  "devDependencies": {
26
23
  "@cloudflare/containers": "0.3.7",
27
- "@cloudflare/vitest-pool-workers": "0.20.3",
28
24
  "@cloudflare/workers-types": "5.20260810.1"
29
25
  },
30
26
  "repository": {
@@ -1,27 +0,0 @@
1
- import type { EdenAgentDefinition, EdenJsonValue, EdenToolDefinition } from "@moinulmoin/eden-definitions";
2
- export interface EdenArtifactGenerationMetadata {
3
- readonly generationId: string;
4
- readonly bundleDigest: string;
5
- readonly manifestVersion: string;
6
- readonly runtimeVersion: string;
7
- readonly agentBundleVersion: string;
8
- readonly protocolVersion: string;
9
- /** Generated artifact/schema-contract version, not the installed SQLite level. */
10
- readonly schemaVersion: number;
11
- readonly toolNames: readonly string[];
12
- readonly executionMode: "local" | "remote";
13
- }
14
- export interface EdenRuntimeAgentArtifact {
15
- readonly agent: EdenAgentDefinition;
16
- readonly instructions: string;
17
- readonly tools: Readonly<Record<string, EdenToolDefinition>>;
18
- readonly toolSchemas: Readonly<Record<string, EdenJsonValue>>;
19
- readonly moduleMap?: unknown;
20
- }
21
- export interface EdenConfiguredArtifact {
22
- readonly artifact: EdenRuntimeAgentArtifact;
23
- readonly generation: EdenArtifactGenerationMetadata;
24
- }
25
- export declare function configureEdenArtifact(artifact: EdenRuntimeAgentArtifact, generation: EdenArtifactGenerationMetadata): void;
26
- export declare function readConfiguredEdenArtifact(): EdenConfiguredArtifact | undefined;
27
- //# sourceMappingURL=artifact-runtime.d.ts.map
@@ -1,14 +0,0 @@
1
- let configuredArtifact;
2
- export function configureEdenArtifact(artifact, generation) {
3
- configuredArtifact = Object.freeze({
4
- artifact,
5
- generation: Object.freeze({
6
- ...generation,
7
- toolNames: Object.freeze([...generation.toolNames]),
8
- }),
9
- });
10
- }
11
- export function readConfiguredEdenArtifact() {
12
- return configuredArtifact;
13
- }
14
- //# sourceMappingURL=artifact-runtime.js.map
@@ -1,6 +0,0 @@
1
- export interface EdenWorkerEnvironment {
2
- readonly EDEN_BEARER_SECRET?: string;
3
- readonly EDEN_SESSIONS?: DurableObjectNamespace;
4
- }
5
- export declare function handleEdenRequest(request: Request, env: EdenWorkerEnvironment): Promise<Response>;
6
- //# sourceMappingURL=http-host.d.ts.map
package/dist/http-host.js DELETED
@@ -1,419 +0,0 @@
1
- import { EDEN_VERSIONS, } from "@moinulmoin/eden-definitions";
2
- import { createOpaqueMessageId, createOpaqueSessionId, createOpaqueTurnId, createSessionObjectName, isOpaqueSessionId, } from "./session-identity.js";
3
- import { readConfiguredEdenArtifact } from "./artifact-runtime.js";
4
- import { SESSION_SCHEMA_VERSION } from "./session-schema.js";
5
- const HEALTH_PATH = "/eden/v1/health";
6
- const INFO_PATH = "/eden/v1/info";
7
- const SESSION_PATH = "/eden/v1/session";
8
- const STREAM_SUFFIX = "/stream";
9
- const MAX_CREATE_BODY_BYTES = 1_024;
10
- const MAX_COMMAND_BODY_BYTES = 32 * 1_024;
11
- const MAX_MESSAGE_BYTES = 16 * 1_024;
12
- const MAX_JSON_DEPTH = 32;
13
- const FIXED_PRINCIPAL = "principal:test";
14
- const UNSUPPORTED_IDENTITY_HEADERS = new Set([
15
- "x-eden-principal",
16
- "x-eden-tenant",
17
- "x-eden-identity",
18
- "x-eden-session-id",
19
- "x-eden-object-name",
20
- "x-durable-object-id",
21
- ]);
22
- function jsonResponse(body, status = 200, headers = {}) {
23
- const responseHeaders = new Headers(headers);
24
- responseHeaders.set("content-type", "application/json; charset=utf-8");
25
- responseHeaders.set("cache-control", "no-store");
26
- return new Response(JSON.stringify(body), { status, headers: responseHeaders });
27
- }
28
- function errorResponse(code, status) {
29
- return jsonResponse({
30
- code,
31
- message: code === "unauthorized"
32
- ? "Authorization is required."
33
- : code === "not_found"
34
- ? "Resource was not found."
35
- : code === "conflict"
36
- ? "The session cannot accept this operation."
37
- : code === "internal_error"
38
- ? "The request could not be completed."
39
- : "The request is invalid.",
40
- }, status);
41
- }
42
- function constantTimeEqual(left, right) {
43
- const leftBytes = new TextEncoder().encode(left);
44
- const rightBytes = new TextEncoder().encode(right);
45
- const length = Math.max(leftBytes.length, rightBytes.length);
46
- let difference = leftBytes.length ^ rightBytes.length;
47
- for (let index = 0; index < length; index += 1) {
48
- difference |= (leftBytes[index] ?? 0) ^ (rightBytes[index] ?? 0);
49
- }
50
- return difference === 0;
51
- }
52
- function isAuthorized(request, configuredBearer) {
53
- if (configuredBearer === undefined || configuredBearer.length === 0) {
54
- return false;
55
- }
56
- const header = request.headers.get("authorization");
57
- if (header === null || !header.startsWith("Bearer "))
58
- return false;
59
- const bearer = header.slice("Bearer ".length);
60
- if (bearer.length === 0 || bearer.includes(" "))
61
- return false;
62
- return constantTimeEqual(bearer, configuredBearer);
63
- }
64
- function hasUnsupportedIdentityHeader(request) {
65
- let unsupported = false;
66
- request.headers.forEach((_value, key) => {
67
- if (UNSUPPORTED_IDENTITY_HEADERS.has(key.toLowerCase())) {
68
- unsupported = true;
69
- }
70
- });
71
- return unsupported;
72
- }
73
- function contentTypeIsJson(request) {
74
- const contentType = request.headers.get("content-type");
75
- if (contentType === null)
76
- return false;
77
- return contentType.split(";", 1)[0]?.trim().toLowerCase() === "application/json";
78
- }
79
- async function readBoundedBody(request, maximumBytes) {
80
- const declaredLength = request.headers.get("content-length");
81
- if (declaredLength !== null) {
82
- const parsedLength = Number(declaredLength);
83
- if (!Number.isSafeInteger(parsedLength) ||
84
- parsedLength < 0 ||
85
- parsedLength > maximumBytes) {
86
- return { status: "too_large" };
87
- }
88
- }
89
- const reader = request.body?.getReader();
90
- if (reader === undefined) {
91
- return { status: "invalid" };
92
- }
93
- const chunks = [];
94
- let total = 0;
95
- try {
96
- while (true) {
97
- const next = await reader.read();
98
- if (next.done)
99
- break;
100
- total += next.value.byteLength;
101
- if (total > maximumBytes) {
102
- await reader.cancel();
103
- return { status: "too_large" };
104
- }
105
- chunks.push(next.value);
106
- }
107
- }
108
- catch {
109
- return { status: "invalid" };
110
- }
111
- const bytes = new Uint8Array(total);
112
- let offset = 0;
113
- for (const chunk of chunks) {
114
- bytes.set(chunk, offset);
115
- offset += chunk.byteLength;
116
- }
117
- try {
118
- return {
119
- status: "ok",
120
- value: JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes)),
121
- };
122
- }
123
- catch {
124
- return { status: "invalid" };
125
- }
126
- }
127
- function parseObject(value) {
128
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
129
- return undefined;
130
- }
131
- return value;
132
- }
133
- function exceedsJsonDepth(value, depth = 0, seen = new WeakSet()) {
134
- if (depth > MAX_JSON_DEPTH)
135
- return true;
136
- if (typeof value !== "object" || value === null)
137
- return false;
138
- if (seen.has(value))
139
- return true;
140
- seen.add(value);
141
- try {
142
- if (Array.isArray(value)) {
143
- return value.some((item) => exceedsJsonDepth(item, depth + 1, seen));
144
- }
145
- return Object.values(value).some((item) => exceedsJsonDepth(item, depth + 1, seen));
146
- }
147
- finally {
148
- // Keep cycle tracking path-local so repeated references in separate
149
- // branches remain valid JSON while true cycles still fail closed.
150
- seen.delete(value);
151
- }
152
- }
153
- function hasOnlyKeys(value, keys) {
154
- const allowed = new Set(keys);
155
- return Object.keys(value).every((key) => allowed.has(key));
156
- }
157
- function validateCreateBody(value) {
158
- const body = parseObject(value);
159
- return body !== undefined && Object.keys(body).length === 0;
160
- }
161
- function validateCommandBody(value) {
162
- const body = parseObject(value);
163
- if (body === undefined ||
164
- !hasOnlyKeys(body, ["message"]) ||
165
- typeof body.message !== "string") {
166
- return false;
167
- }
168
- return (body.message.trim().length > 0 &&
169
- new TextEncoder().encode(body.message).byteLength <= MAX_MESSAGE_BYTES);
170
- }
171
- function readStreamQuery(url) {
172
- const allowed = new Set(["startIndex", "follow"]);
173
- const queryKeys = [];
174
- url.searchParams.forEach((_value, key) => queryKeys.push(key));
175
- for (const key of queryKeys) {
176
- if (!allowed.has(key))
177
- return undefined;
178
- }
179
- const startValues = url.searchParams.getAll("startIndex");
180
- if (startValues.length > 1)
181
- return undefined;
182
- const rawStartIndex = startValues[0] ?? "0";
183
- const startIndex = Number(rawStartIndex);
184
- if (!Number.isSafeInteger(startIndex) ||
185
- startIndex < 0 ||
186
- rawStartIndex !== String(startIndex)) {
187
- return undefined;
188
- }
189
- const followValues = url.searchParams.getAll("follow");
190
- if (followValues.length > 1)
191
- return undefined;
192
- const rawFollow = followValues[0];
193
- if (rawFollow !== undefined && rawFollow !== "true" && rawFollow !== "false") {
194
- return undefined;
195
- }
196
- return {
197
- startIndex,
198
- follow: rawFollow !== "false",
199
- };
200
- }
201
- function hasQuery(url) {
202
- let present = false;
203
- url.searchParams.forEach(() => {
204
- present = true;
205
- });
206
- return present;
207
- }
208
- function sessionIdFromPath(pathname) {
209
- if (!pathname.startsWith(`${SESSION_PATH}/`))
210
- return undefined;
211
- const suffix = pathname.slice(`${SESSION_PATH}/`.length);
212
- if (suffix.length === 0 || suffix.includes("/"))
213
- return undefined;
214
- let decoded;
215
- try {
216
- decoded = decodeURIComponent(suffix);
217
- }
218
- catch {
219
- return undefined;
220
- }
221
- return isOpaqueSessionId(decoded) ? decoded : undefined;
222
- }
223
- function sessionStub(env, sessionId) {
224
- if (env.EDEN_SESSIONS === undefined)
225
- return undefined;
226
- return env.EDEN_SESSIONS.get(env.EDEN_SESSIONS.idFromName(createSessionObjectName(sessionId)));
227
- }
228
- async function initializeSession(env, sessionId) {
229
- const stub = sessionStub(env, sessionId);
230
- if (stub === undefined)
231
- return false;
232
- const response = await stub.fetch("https://eden/_eden/initialize", {
233
- method: "POST",
234
- headers: { "content-type": "application/json" },
235
- body: JSON.stringify({
236
- sessionId,
237
- ownerPrincipal: FIXED_PRINCIPAL,
238
- versions: EDEN_VERSIONS,
239
- }),
240
- });
241
- await response.arrayBuffer();
242
- return response.status === 200 || response.status === 201;
243
- }
244
- async function acceptCommand(env, sessionId, request, turnId, messageId) {
245
- const stub = sessionStub(env, sessionId);
246
- if (stub === undefined)
247
- return errorResponse("internal_error", 500);
248
- let response;
249
- try {
250
- response = await stub.fetch("https://eden/_eden/accept", {
251
- method: "POST",
252
- headers: { "content-type": "application/json" },
253
- body: JSON.stringify({
254
- sessionId,
255
- ownerPrincipal: FIXED_PRINCIPAL,
256
- turnId,
257
- messageId,
258
- message: request.message,
259
- }),
260
- });
261
- }
262
- catch {
263
- return errorResponse("internal_error", 500);
264
- }
265
- const status = response.status;
266
- await response.arrayBuffer();
267
- if (status === 200 || status === 202) {
268
- return jsonResponse({ sessionId, turnId, status: "accepted" }, 202);
269
- }
270
- if (status === 404)
271
- return errorResponse("not_found", 404);
272
- if (status === 409)
273
- return errorResponse("conflict", 409);
274
- if (status === 400)
275
- return errorResponse("invalid_request", 400);
276
- return errorResponse("internal_error", 500);
277
- }
278
- async function streamEvents(env, sessionId, query) {
279
- const stub = sessionStub(env, sessionId);
280
- if (stub === undefined)
281
- return errorResponse("internal_error", 500);
282
- let response;
283
- try {
284
- response = await stub.fetch("https://eden/_eden/stream", {
285
- method: "POST",
286
- headers: { "content-type": "application/json" },
287
- body: JSON.stringify({
288
- sessionId,
289
- ownerPrincipal: FIXED_PRINCIPAL,
290
- startIndex: query.startIndex,
291
- follow: query.follow,
292
- }),
293
- });
294
- }
295
- catch {
296
- return errorResponse("internal_error", 500);
297
- }
298
- if (response.status === 404) {
299
- await response.arrayBuffer();
300
- return errorResponse("not_found", 404);
301
- }
302
- if (response.status !== 200) {
303
- await response.arrayBuffer();
304
- return errorResponse("internal_error", 500);
305
- }
306
- return new Response(response.body, {
307
- status: 200,
308
- headers: {
309
- "content-type": "application/x-ndjson; charset=utf-8",
310
- "cache-control": "no-store",
311
- },
312
- });
313
- }
314
- async function handleCreate(request, env) {
315
- if (request.method !== "POST") {
316
- return errorResponse("not_found", 404);
317
- }
318
- if (hasQuery(new URL(request.url))) {
319
- return errorResponse("invalid_request", 400);
320
- }
321
- if (!contentTypeIsJson(request))
322
- return errorResponse("invalid_request", 400);
323
- const body = await readBoundedBody(request, MAX_CREATE_BODY_BYTES);
324
- if (body.status !== "ok" ||
325
- exceedsJsonDepth(body.value) ||
326
- !validateCreateBody(body.value)) {
327
- return errorResponse(body.status === "too_large" ? "request_too_large" : "invalid_request", 400);
328
- }
329
- const sessionId = createOpaqueSessionId();
330
- if (!(await initializeSession(env, sessionId))) {
331
- return errorResponse("internal_error", 500);
332
- }
333
- return jsonResponse({
334
- sessionId,
335
- status: "new",
336
- versions: EDEN_VERSIONS,
337
- sqliteSchemaVersion: SESSION_SCHEMA_VERSION,
338
- }, 201);
339
- }
340
- async function handleCommand(request, env, sessionId) {
341
- if (request.method !== "POST") {
342
- return errorResponse("not_found", 404);
343
- }
344
- if (hasQuery(new URL(request.url))) {
345
- return errorResponse("invalid_request", 400);
346
- }
347
- if (!contentTypeIsJson(request))
348
- return errorResponse("invalid_request", 400);
349
- const body = await readBoundedBody(request, MAX_COMMAND_BODY_BYTES);
350
- if (body.status !== "ok" ||
351
- exceedsJsonDepth(body.value) ||
352
- !validateCommandBody(body.value)) {
353
- return errorResponse(body.status === "too_large" ? "request_too_large" : "invalid_request", 400);
354
- }
355
- return acceptCommand(env, sessionId, body.value, createOpaqueTurnId(), createOpaqueMessageId());
356
- }
357
- async function handleStream(request, env, sessionId) {
358
- if (request.method !== "GET")
359
- return errorResponse("not_found", 404);
360
- const query = readStreamQuery(new URL(request.url));
361
- if (query === undefined)
362
- return errorResponse("invalid_request", 400);
363
- return streamEvents(env, sessionId, query);
364
- }
365
- export async function handleEdenRequest(request, env) {
366
- if (!isAuthorized(request, env.EDEN_BEARER_SECRET)) {
367
- return errorResponse("unauthorized", 401);
368
- }
369
- if (hasUnsupportedIdentityHeader(request)) {
370
- return errorResponse("invalid_request", 400);
371
- }
372
- const url = new URL(request.url);
373
- if (url.pathname === HEALTH_PATH) {
374
- return request.method === "GET"
375
- ? jsonResponse({ status: "ok" })
376
- : errorResponse("not_found", 404);
377
- }
378
- if (url.pathname === INFO_PATH) {
379
- const generation = readConfiguredEdenArtifact()?.generation;
380
- return request.method === "GET"
381
- ? jsonResponse({
382
- service: "eden",
383
- protocol: EDEN_VERSIONS.protocol,
384
- versions: EDEN_VERSIONS,
385
- sqliteSchemaVersion: SESSION_SCHEMA_VERSION,
386
- ...(generation === undefined
387
- ? {}
388
- : {
389
- generation: {
390
- generationId: generation.generationId,
391
- bundleDigest: generation.bundleDigest,
392
- manifestVersion: generation.manifestVersion,
393
- runtimeVersion: generation.runtimeVersion,
394
- agentBundleVersion: generation.agentBundleVersion,
395
- protocolVersion: generation.protocolVersion,
396
- schemaVersion: generation.schemaVersion,
397
- toolNames: generation.toolNames,
398
- },
399
- }),
400
- })
401
- : errorResponse("not_found", 404);
402
- }
403
- if (url.pathname === SESSION_PATH) {
404
- return handleCreate(request, env);
405
- }
406
- if (url.pathname.endsWith(STREAM_SUFFIX)) {
407
- const basePath = url.pathname.slice(0, -STREAM_SUFFIX.length);
408
- const streamSessionId = sessionIdFromPath(basePath);
409
- if (streamSessionId === undefined) {
410
- return errorResponse("not_found", 404);
411
- }
412
- return handleStream(request, env, streamSessionId);
413
- }
414
- const sessionId = sessionIdFromPath(url.pathname);
415
- if (sessionId === undefined)
416
- return errorResponse("not_found", 404);
417
- return handleCommand(request, env, sessionId);
418
- }
419
- //# sourceMappingURL=http-host.js.map
@@ -1,12 +0,0 @@
1
- import { type EdenModelAdapter, type EdenModelAdapterCall } from "./model-adapter.js";
2
- interface InternalWorkersAIOptions {
3
- readonly binding: unknown;
4
- readonly modelId: string;
5
- readonly gatewayId: string;
6
- }
7
- /** Internal only. The public runtime contract never accepts a binding. */
8
- export declare function createWorkersAIModelProvider(options: InternalWorkersAIOptions): EdenModelAdapterCall;
9
- /** Internal only. The public runtime contract never accepts a binding. */
10
- export declare function createWorkersAIModelAdapter(options: InternalWorkersAIOptions): EdenModelAdapter;
11
- export {};
12
- //# sourceMappingURL=model-adapter-internal.d.ts.map