Skip to content

Commit eb51d6d

Browse files
improvement(copilot): tool dependency errors show as skipped (#864)
* Dependency errors show as skipped instead of errored * Update apps/sim/lib/copilot/tools/client-tools/run-workflow.ts Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * Lint --------- Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
1 parent f3880ad commit eb51d6d

File tree

3 files changed

+29
-45
lines changed

3 files changed

+29
-45
lines changed

apps/sim/lib/copilot/tools/client-tools/run-workflow.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,15 @@ export class RunWorkflowTool extends BaseTool {
168168
// Execution failed
169169
const errorMessage = (result as any)?.error || 'Workflow execution failed'
170170

171-
// Notify server of error
172-
await this.notify(toolCall.id, 'errored', `Workflow execution failed: ${errorMessage}`)
171+
// Check if error message is exactly 'skipped' to notify 'rejected' instead of 'errored'
172+
const targetState = errorMessage === 'skipped' ? 'rejected' : 'errored'
173+
const message =
174+
targetState === 'rejected'
175+
? `Workflow execution skipped: ${errorMessage}`
176+
: `Workflow execution failed: ${errorMessage}`
177+
await this.notify(toolCall.id, targetState, message)
173178

174-
options?.onStateChange?.('errored')
179+
options?.onStateChange?.(targetState)
175180

176181
return {
177182
success: false,
@@ -184,9 +189,11 @@ export class RunWorkflowTool extends BaseTool {
184189

185190
const errorMessage = error?.message || 'An unknown error occurred'
186191

187-
await this.notify(toolCall.id, 'errored', `Workflow execution failed: ${errorMessage}`)
192+
// Check if error message is exactly 'skipped' to notify 'rejected' instead of 'errored'
193+
const targetState = errorMessage === 'skipped' ? 'rejected' : 'errored'
194+
await this.notify(toolCall.id, targetState, `Workflow execution failed: ${errorMessage}`)
188195

189-
options?.onStateChange?.('errored')
196+
options?.onStateChange?.(targetState)
190197

191198
return {
192199
success: false,

apps/sim/lib/copilot/tools/inline-tool-call.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@ async function clientAcceptTool(
7070
}
7171
} catch (error) {
7272
console.error('Error executing client tool:', error)
73-
setToolCallState(toolCall, 'errored', {
74-
error: error instanceof Error ? error.message : 'Tool execution failed',
73+
const errorMessage = error instanceof Error ? error.message : 'Tool execution failed'
74+
// Check if error message is exactly 'skipped' to set 'rejected' state instead of 'errored'
75+
const targetState = errorMessage === 'skipped' ? 'rejected' : 'errored'
76+
setToolCallState(toolCall, targetState, {
77+
error: errorMessage,
7578
})
7679
}
7780
}

apps/sim/stores/copilot/store.ts

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,6 @@ function getToolDisplayNameByState(toolCall: any): string {
288288
* don't go through createToolCall()
289289
*/
290290
function ensureToolCallDisplayNames(messages: CopilotMessage[]): CopilotMessage[] {
291-
console.log('[DEBUG] ensureToolCallDisplayNames called, processing', messages.length, 'messages')
292-
293291
return messages.map((message: CopilotMessage) => {
294292
if (message.role === 'assistant' && (message.toolCalls || message.contentBlocks)) {
295293
// Check for workflow tools before recalculating
@@ -307,11 +305,6 @@ function ensureToolCallDisplayNames(messages: CopilotMessage[]): CopilotMessage[
307305
)
308306

309307
if (hasWorkflowTools) {
310-
console.log(
311-
'[DEBUG] ensureToolCallDisplayNames found workflow tools in message:',
312-
message.id
313-
)
314-
315308
// Log current states before recalculation
316309
const workflowToolStates = message.contentBlocks
317310
?.filter(
@@ -325,11 +318,6 @@ function ensureToolCallDisplayNames(messages: CopilotMessage[]): CopilotMessage[
325318
state: (b as any).toolCall.state,
326319
displayName: (b as any).toolCall.displayName,
327320
}))
328-
329-
console.log(
330-
'[DEBUG] Current workflow tool states before recalculation:',
331-
workflowToolStates
332-
)
333321
}
334322

335323
return {
@@ -408,7 +396,8 @@ function handleToolFailure(toolCall: any, error: string): void {
408396
return
409397
}
410398

411-
toolCall.state = 'errored'
399+
// Check if error message is exactly 'skipped' to set 'rejected' state instead of 'errored'
400+
toolCall.state = error === 'skipped' ? 'rejected' : 'errored'
412401
toolCall.error = error
413402

414403
// Update displayName to match the error state
@@ -488,7 +477,12 @@ function setToolCallState(
488477
break
489478

490479
case 'rejected':
491-
// User rejected the tool
480+
// User rejected the tool or tool was skipped
481+
toolCall.endTime = Date.now()
482+
toolCall.duration = toolCall.endTime - toolCall.startTime
483+
if (error) {
484+
toolCall.error = error
485+
}
492486
break
493487

494488
case 'background':
@@ -687,7 +681,7 @@ const sseHandlers: Record<string, SSEHandler> = {
687681

688682
// Handle tool result events - simplified
689683
tool_result: (data, context, get, set) => {
690-
const { toolCallId, result, success } = data
684+
const { toolCallId, result, success, error } = data
691685

692686
if (!toolCallId) return
693687

@@ -729,15 +723,11 @@ const sseHandlers: Record<string, SSEHandler> = {
729723
if (toolSupportsReadyForReview(toolCall.name)) {
730724
processWorkflowToolResult(toolCall, parsedResult, get)
731725
}
732-
733-
// COMMENTED OUT OLD LOGIC:
734-
// finalizeToolCall(toolCall, true, parsedResult, get)
735726
} else {
736-
// NEW LOGIC: Use centralized state management
737-
setToolCallState(toolCall, 'errored', { error: result || 'Tool execution failed' })
727+
const errorMessage = error || result || 'Tool execution failed'
728+
const targetState = errorMessage === 'skipped' ? 'rejected' : 'errored'
738729

739-
// COMMENTED OUT OLD LOGIC:
740-
// handleToolFailure(toolCall, result || 'Tool execution failed')
730+
setToolCallState(toolCall, targetState, { error: errorMessage })
741731
}
742732

743733
// Update both contentBlocks and toolCalls atomically before UI update
@@ -792,24 +782,13 @@ const sseHandlers: Record<string, SSEHandler> = {
792782
const toolData = data.data
793783
if (!toolData) return
794784

795-
// Log the raw tool data from LLM stream
796-
if (toolData.name === 'run_workflow') {
797-
console.log('🔍 LLM tool call data:', JSON.stringify(toolData, null, 2))
798-
console.log('🔍 LLM arguments field:', JSON.stringify(toolData.arguments, null, 2))
799-
}
800-
801785
// Check if tool call already exists
802786
const existingToolCall = context.toolCalls.find((tc) => tc.id === toolData.id)
803787

804788
if (existingToolCall) {
805789
// Update existing tool call with new arguments (for partial -> complete transition)
806790
existingToolCall.input = toolData.arguments || {}
807791

808-
// Log the updated tool call
809-
if (toolData.name === 'run_workflow') {
810-
console.log('🔍 Updated existing tool call:', JSON.stringify(existingToolCall, null, 2))
811-
}
812-
813792
// Update the content block as well
814793
updateContentBlockToolCall(context.contentBlocks, toolData.id, existingToolCall)
815794
updateStreamingMessage(set, context)
@@ -818,11 +797,6 @@ const sseHandlers: Record<string, SSEHandler> = {
818797

819798
const toolCall = createToolCall(toolData.id, toolData.name, toolData.arguments)
820799

821-
// Log the created tool call
822-
if (toolData.name === 'run_workflow') {
823-
console.log('🔍 Created tool call:', JSON.stringify(toolCall, null, 2))
824-
}
825-
826800
context.toolCalls.push(toolCall)
827801

828802
context.contentBlocks.push({

0 commit comments

Comments
 (0)