From 7e40d06f5e52d5f8ecb1ff19d4cc5a0601a4d71e Mon Sep 17 00:00:00 2001 From: Theodore Li Date: Mon, 16 Mar 2026 17:31:12 -0700 Subject: [PATCH] fix: add promptForToolApproval to prevent tool hang in mothership chat Tools with requiresConfirmation (e.g. user_table) blocked indefinitely in mothership because the frontend has no approval UI. Added a new promptForToolApproval orchestrator option so mothership auto-executes these tools while copilot continues to prompt for user approval. Made-with: Cursor --- apps/sim/app/api/copilot/chat/route.ts | 2 ++ apps/sim/app/api/mothership/chat/route.ts | 3 ++- apps/sim/lib/copilot/orchestrator/sse/handlers/handlers.ts | 4 ++-- apps/sim/lib/copilot/orchestrator/types.ts | 7 +++++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/apps/sim/app/api/copilot/chat/route.ts b/apps/sim/app/api/copilot/chat/route.ts index 57e6575d6ce..305280b8f0c 100644 --- a/apps/sim/app/api/copilot/chat/route.ts +++ b/apps/sim/app/api/copilot/chat/route.ts @@ -302,6 +302,7 @@ export async function POST(req: NextRequest) { goRoute: '/api/copilot', autoExecuteTools: true, interactive: true, + promptForToolApproval: true, }, }) @@ -315,6 +316,7 @@ export async function POST(req: NextRequest) { goRoute: '/api/copilot', autoExecuteTools: true, interactive: true, + promptForToolApproval: true, }) const responseData = { diff --git a/apps/sim/app/api/mothership/chat/route.ts b/apps/sim/app/api/mothership/chat/route.ts index 247f70360e6..eee1f4c2e0c 100644 --- a/apps/sim/app/api/mothership/chat/route.ts +++ b/apps/sim/app/api/mothership/chat/route.ts @@ -261,7 +261,8 @@ export async function POST(req: NextRequest) { chatId: actualChatId, goRoute: '/api/mothership', autoExecuteTools: true, - interactive: false, + interactive: true, + promptForToolApproval: false, onComplete: async (result: OrchestratorResult) => { if (!actualChatId) return diff --git a/apps/sim/lib/copilot/orchestrator/sse/handlers/handlers.ts b/apps/sim/lib/copilot/orchestrator/sse/handlers/handlers.ts index 04c779c08b9..fcd63272245 100644 --- a/apps/sim/lib/copilot/orchestrator/sse/handlers/handlers.ts +++ b/apps/sim/lib/copilot/orchestrator/sse/handlers/handlers.ts @@ -320,7 +320,7 @@ export const sseHandlers: Record = { return } - if (requiresConfirmation) { + if (requiresConfirmation && options.promptForToolApproval) { const decision = await waitForToolDecision( toolCallId, options.timeout || STREAM_TIMEOUT_MS, @@ -569,7 +569,7 @@ export const subAgentHandlers: Record = { return } - if (requiresConfirmation) { + if (requiresConfirmation && options.promptForToolApproval) { const decision = await waitForToolDecision( toolCallId, options.timeout || STREAM_TIMEOUT_MS, diff --git a/apps/sim/lib/copilot/orchestrator/types.ts b/apps/sim/lib/copilot/orchestrator/types.ts index 4f912dc4989..130666c81e6 100644 --- a/apps/sim/lib/copilot/orchestrator/types.ts +++ b/apps/sim/lib/copilot/orchestrator/types.ts @@ -139,6 +139,13 @@ export interface OrchestratorOptions { onError?: (error: Error) => void | Promise abortSignal?: AbortSignal interactive?: boolean + /** + * When true, tools with `requiresConfirmation` will block until the client + * explicitly approves or rejects. When false (e.g. Mothership chat), those + * tools are auto-executed without waiting for user approval. + * Defaults to false. + */ + promptForToolApproval?: boolean } export interface OrchestratorResult {