Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 28 additions & 19 deletions apps/sim/lib/copilot/orchestrator/sse/handlers/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export const sseHandlers: Record<string, SSEHandler> = {
return
}

if (!isToolAvailableOnSimSide(toolName)) {
if (!isToolAvailableOnSimSide(toolName) && !clientExecutable) {
return
}

Expand Down Expand Up @@ -396,16 +396,21 @@ export const sseHandlers: Record<string, SSEHandler> = {
return
}

// Auto-allowed client-executable tool: client runs it, we wait for completion.
// Client-executable tool: execute server-side if available, otherwise
// delegate to the client (React UI) and wait for completion.
if (clientExecutable) {
toolCall.status = 'executing'
const completion = await waitForToolCompletion(
toolCallId,
options.timeout || STREAM_TIMEOUT_MS,
options.abortSignal
)
handleClientCompletion(toolCall, toolCallId, completion)
await emitSyntheticToolResult(toolCallId, toolCall.name, completion, options)
if (isToolAvailableOnSimSide(toolName)) {
fireToolExecution()
} else {
toolCall.status = 'executing'
const completion = await waitForToolCompletion(
toolCallId,
options.timeout || STREAM_TIMEOUT_MS,
options.abortSignal
)
handleClientCompletion(toolCall, toolCallId, completion)
await emitSyntheticToolResult(toolCallId, toolCall.name, completion, options)
}
return
}

Expand Down Expand Up @@ -548,7 +553,7 @@ export const subAgentHandlers: Record<string, SSEHandler> = {
return
}

if (!isToolAvailableOnSimSide(toolName)) {
if (!isToolAvailableOnSimSide(toolName) && !clientExecutable) {
return
}

Expand Down Expand Up @@ -643,14 +648,18 @@ export const subAgentHandlers: Record<string, SSEHandler> = {
}

if (clientExecutable) {
toolCall.status = 'executing'
const completion = await waitForToolCompletion(
toolCallId,
options.timeout || STREAM_TIMEOUT_MS,
options.abortSignal
)
handleClientCompletion(toolCall, toolCallId, completion)
await emitSyntheticToolResult(toolCallId, toolCall.name, completion, options)
if (isToolAvailableOnSimSide(toolName)) {
fireToolExecution()
} else {
toolCall.status = 'executing'
const completion = await waitForToolCompletion(
toolCallId,
options.timeout || STREAM_TIMEOUT_MS,
options.abortSignal
)
handleClientCompletion(toolCall, toolCallId, completion)
await emitSyntheticToolResult(toolCallId, toolCall.name, completion, options)
}
return
}

Expand Down
Loading