import type { ResumeResponse } from "@executor-js/execution"; import type { IncomingTraceHeaders, McpApprovalOwner, McpSessionApprovalResult, McpSessionModelResumeResult, McpSessionResumeApprovalResult, } from "./agent-session-durable-object"; import { mcpSessionDurableObjectName } from "./execution-owner-directory"; export interface McpSessionNamespace { readonly idFromName: (name: string) => Id; readonly get: (id: Id) => unknown; } export interface McpSessionStub { readonly validateMcpSessionOwner: ( identity: McpApprovalOwner, ) => Promise<"ok" | "not_found" | "forbidden" | "terminated">; readonly _cf_scheduleDestroy: () => Promise; readonly getPausedExecutionForApproval: ( executionId: string, identity: McpApprovalOwner, incoming?: IncomingTraceHeaders, ) => Promise; readonly resumeExecutionForApproval: ( executionId: string, identity: McpApprovalOwner, response: ResumeResponse, incoming?: IncomingTraceHeaders, ) => Promise; readonly resumeExecutionForModel: ( executionId: string, identity: McpApprovalOwner, response: ResumeResponse, incoming?: IncomingTraceHeaders, ) => Promise; } export const mcpSessionStub = ( namespace: McpSessionNamespace, sessionId: string, ): McpSessionStub => // oxlint-disable-next-line executor/no-double-cast -- boundary: Workers types expose only DurableObjectStub, but RPC methods are generated from the bound DO class. namespace.get( namespace.idFromName(mcpSessionDurableObjectName(sessionId)), ) as unknown as McpSessionStub;