* Track MCP tool executions in Autumn billing MCP tool calls bypassed the execution-usage tracking wrapper because the session DO built the engine implicitly inside createExecutorMcpServer. Build the engine in the DO, wrap it with withExecutionUsageTracking, and pass it through so executions increment the Autumn `executions` feature. * fix lockfile
Unified · Split
| @@ -10,14 +10,18 @@ import { drizzle } from "drizzle-orm/postgres-js"; · 9 unmodified lines | |||
| 10 | import postgres from "postgres"; | 10 | import postgres from "postgres"; |
| 11 | 11 | ||
| 12 | import { createExecutorMcpServer } from "@executor/host-mcp"; | 12 | import { createExecutorMcpServer } from "@executor/host-mcp"; |
| 13 | import { createExecutionEngine } from "@executor/execution"; | ||
| 13 | import { makeDynamicWorkerExecutor } from "@executor/runtime-dynamic-worker"; | 14 | import { makeDynamicWorkerExecutor } from "@executor/runtime-dynamic-worker"; |
| 14 | import type { DrizzleDb } from "@executor/storage-postgres"; | 15 | import type { DrizzleDb } from "@executor/storage-postgres"; |
| 15 | import * as sharedSchema from "@executor/storage-postgres/schema"; | 16 | import * as sharedSchema from "@executor/storage-postgres/schema"; |
| 16 | 17 | ||
| 18 | import { makeTrackExecutionUsage } from "./api/autumn"; | ||
| 19 | import { withExecutionUsageTracking } from "./api/execution-usage"; | ||
| 17 | import { UserStoreService } from "./auth/context"; | 20 | import { UserStoreService } from "./auth/context"; |
| 18 | import { resolveOrganization } from "./auth/resolve-organization"; | 21 | import { resolveOrganization } from "./auth/resolve-organization"; |
| 19 | import { WorkOSAuth } from "./auth/workos"; | 22 | import { WorkOSAuth } from "./auth/workos"; |
| 20 | import { server } from "./env"; | 23 | import { server } from "./env"; |
| 24 | import { AutumnService } from "./services/autumn"; | ||
| 21 | import { createOrgExecutor } from "./services/executor"; | 25 | import { createOrgExecutor } from "./services/executor"; |
| 22 | import { DbService } from "./services/db"; | 26 | import { DbService } from "./services/db"; |
| 23 | import * as cloudSchema from "./services/schema"; | 27 | import * as cloudSchema from "./services/schema"; |
| @@ -107,7 +111,12 @@ export class McpSessionDO extends DurableObject { · 83 unmodified lines | |||
| 107 | 111 | ||
| 108 | const DbLive = Layer.succeed(DbService, this.dbHandle.db); | 112 | const DbLive = Layer.succeed(DbService, this.dbHandle.db); |
| 109 | const UserStoreLive = UserStoreService.Live.pipe(Layer.provide(DbLive)); | 113 | const UserStoreLive = UserStoreService.Live.pipe(Layer.provide(DbLive)); |
| 110 | const Services = Layer.mergeAll(DbLive, UserStoreLive, WorkOSAuth.Default); | 114 | const Services = Layer.mergeAll( |
| 115 | DbLive, | ||
| 116 | UserStoreLive, | ||
| 117 | WorkOSAuth.Default, | ||
| 118 | AutumnService.Default, | ||
| 119 | ); | ||
| 111 | 120 | ||
| 112 | const program = Effect.gen(function* () { | 121 | const program = Effect.gen(function* () { |
| 113 | const org = yield* resolveOrganization(token.organizationId); | 122 | const org = yield* resolveOrganization(token.organizationId); |
| @@ -116,7 +125,13 @@ export class McpSessionDO extends DurableObject { · 2 unmodified lines | |||
| 116 | 125 | ||
| 117 | const executor = yield* createOrgExecutor(org.id, org.name); | 126 | const executor = yield* createOrgExecutor(org.id, org.name); |
| 118 | const codeExecutor = makeDynamicWorkerExecutor({ loader: env.LOADER }); | 127 | const codeExecutor = makeDynamicWorkerExecutor({ loader: env.LOADER }); |
| 119 | return yield* Effect.promise(() => createExecutorMcpServer({ executor, codeExecutor })); | 128 | const autumn = yield* AutumnService; |
| 129 | const engine = withExecutionUsageTracking( | ||
| 130 | org.id, | ||
| 131 | createExecutionEngine({ executor, codeExecutor }), | ||
| 132 | makeTrackExecutionUsage(autumn), | ||
| 133 | ); | ||
| 134 | return yield* Effect.promise(() => createExecutorMcpServer({ engine })); | ||
| 120 | }).pipe(Effect.provide(Services)); | 135 | }).pipe(Effect.provide(Services)); |
| 121 | 136 | ||
| 122 | this.mcpServer = await Effect.runPromise(program); | 137 | this.mcpServer = await Effect.runPromise(program); |
| @@ -324,6 +324,7 @@ · 323 unmodified lines | |||
| 324 | "name": "@executor/codemode-core", | 324 | "name": "@executor/codemode-core", |
| 325 | "version": "1.4.3", | 325 | "version": "1.4.3", |
| 326 | "dependencies": { | 326 | "dependencies": { |
| 327 | "@babel/parser": "^7.29.2", | ||
| 327 | "@standard-schema/spec": "^1.0.0", | 328 | "@standard-schema/spec": "^1.0.0", |
| 328 | "ajv": "^8.17.1", | 329 | "ajv": "^8.17.1", |
| 329 | "ajv-formats": "^3.0.1", | 330 | "ajv-formats": "^3.0.1", |