@@ -32,10 +32,7 @@ import {
3232 authorizeOrganizationSelector ,
3333 resolveOrganization ,
3434} from "./organization" ;
35- import type {
36- McpSessionApprovalResult ,
37- McpSessionResumeApprovalResult ,
38- } from "../mcp/session-durable-object" ;
35+ import { mcpSessionStub } from "@executor-js/cloudflare/mcp/session-stub" ;
3936
4037const COOKIE_OPTIONS = {
4138 path : "/" ,
@@ -122,23 +119,7 @@ const requireSelectedOrganization = Effect.gen(function* () {
122119 } ;
123120} ) ;
124121
125- const getMcpSessionStub = ( mcpSessionId : string ) =>
126- Effect . try ( {
127- try : ( ) => {
128- const ns = env . MCP_SESSION ;
129- return ns . get ( ns . idFromString ( mcpSessionId ) ) ;
130- } ,
131- catch : ( ) => undefined ,
132- } ) . pipe ( Effect . orElseSucceed ( ( ) => null ) ) ;
133-
134- const requireMcpSessionStub = ( mcpSessionId : string , executionId : string ) =>
135- Effect . gen ( function * ( ) {
136- const stub = yield * getMcpSessionStub ( mcpSessionId ) ;
137- if ( ! stub ) {
138- return yield * new McpExecutionNotFoundError ( { executionId } ) ;
139- }
140- return stub ;
141- } ) ;
122+ const getMcpSessionStub = ( mcpSessionId : string ) => mcpSessionStub ( env . MCP_SESSION , mcpSessionId ) ;
142123
143124const failMcpApprovalResult = (
144125 result : { readonly status : "not_found" | "forbidden" } ,
@@ -528,13 +509,12 @@ export const CloudSessionAuthHandlers = HttpApiBuilder.group(
528509 . handle ( "getMcpPaused" , ( { params } ) =>
529510 Effect . gen ( function * ( ) {
530511 const owner = yield * requireSelectedOrganization ;
531- const stub = yield * requireMcpSessionStub ( params . mcpSessionId , params . executionId ) ;
532- const result = yield * Effect . promise (
533- ( ) =>
534- stub . getPausedExecutionForApproval ( params . executionId , {
535- accountId : owner . accountId ,
536- organizationId : owner . organizationId ,
537- } ) as Promise < McpSessionApprovalResult > ,
512+ const stub = getMcpSessionStub ( params . mcpSessionId ) ;
513+ const result = yield * Effect . promise ( ( ) =>
514+ stub . getPausedExecutionForApproval ( params . executionId , {
515+ accountId : owner . accountId ,
516+ organizationId : owner . organizationId ,
517+ } ) ,
538518 ) ;
539519
540520 if ( result . status !== "ok" ) {
@@ -550,20 +530,19 @@ export const CloudSessionAuthHandlers = HttpApiBuilder.group(
550530 . handle ( "resumeMcpExecution" , ( { params, payload } ) =>
551531 Effect . gen ( function * ( ) {
552532 const owner = yield * requireSelectedOrganization ;
553- const stub = yield * requireMcpSessionStub ( params . mcpSessionId , params . executionId ) ;
554- const result = yield * Effect . promise (
555- ( ) =>
556- stub . resumeExecutionForApproval (
557- params . executionId ,
558- {
559- accountId : owner . accountId ,
560- organizationId : owner . organizationId ,
561- } ,
562- {
563- action : payload . action ,
564- content : payload . content as Record < string , unknown > | undefined ,
565- } ,
566- ) as Promise < McpSessionResumeApprovalResult > ,
533+ const stub = getMcpSessionStub ( params . mcpSessionId ) ;
534+ const result = yield * Effect . promise ( ( ) =>
535+ stub . resumeExecutionForApproval (
536+ params . executionId ,
537+ {
538+ accountId : owner . accountId ,
539+ organizationId : owner . organizationId ,
540+ } ,
541+ {
542+ action : payload . action ,
543+ content : payload . content as Record < string , unknown > | undefined ,
544+ } ,
545+ ) ,
567546 ) ;
568547
569548 if ( result . status !== "ok" ) {
0 commit comments