-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathexecution-stack.ts
More file actions
38 lines (34 loc) · 1.55 KB
/
Copy pathexecution-stack.ts
File metadata and controls
38 lines (34 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// ---------------------------------------------------------------------------
// Shared execution stack — the wiring that turns an organization into a
// runnable executor + engine. Used by the protected HTTP API (per-request)
// and the MCP session DO (per-session) so changes to the stack flow to both.
// ---------------------------------------------------------------------------
import { env } from "cloudflare:workers";
import { Effect } from "effect";
import { createExecutionEngine } from "@executor-js/execution";
import { makeDynamicWorkerExecutor } from "@executor-js/runtime-dynamic-worker";
import { withExecutionUsageTracking } from "../api/execution-usage";
import { AutumnService } from "./autumn";
import { createCloudPlugins, createScopedExecutor } from "./executor";
export const makeExecutionStack = (
userId: string,
organizationId: string,
organizationName: string,
) =>
Effect.gen(function* () {
const plugins = createCloudPlugins();
const executor = yield* createScopedExecutor(
userId,
organizationId,
organizationName,
plugins,
).pipe(Effect.withSpan("McpSessionDO.createScopedExecutor"));
const codeExecutor = makeDynamicWorkerExecutor({ loader: env.LOADER });
const autumn = yield* AutumnService;
const engine = withExecutionUsageTracking(
organizationId,
createExecutionEngine({ executor, codeExecutor }),
(orgId) => Effect.runFork(autumn.trackExecution(orgId)),
);
return { executor, engine, plugins };
}).pipe(Effect.withSpan("McpSessionDO.makeExecutionStack"));