( toolCall: ToolCallState, context: StreamingContext, execContext: ExecutionContext, options?: OrchestratorOptions )
| 435 | } |
| 436 | |
| 437 | async function executeToolAndReportInner( |
| 438 | toolCall: ToolCallState, |
| 439 | context: StreamingContext, |
| 440 | execContext: ExecutionContext, |
| 441 | options?: OrchestratorOptions |
| 442 | ): Promise<AsyncToolCompletion> { |
| 443 | if (toolCall.status === 'executing') { |
| 444 | return buildCompletionSignal({ |
| 445 | status: MothershipStreamV1AsyncToolRecordStatus.running, |
| 446 | message: 'Tool already executing', |
| 447 | }) |
| 448 | } |
| 449 | if (toolCall.endTime || isTerminalToolCallStatus(toolCall.status)) { |
| 450 | return terminalCompletionFromToolCall(toolCall) |
| 451 | } |
| 452 | |
| 453 | const markToolCallCancelled = (message: string) => { |
| 454 | setTerminalToolCallState(toolCall, { |
| 455 | status: MothershipStreamV1ToolOutcome.cancelled, |
| 456 | error: message, |
| 457 | }) |
| 458 | } |
| 459 | |
| 460 | if (abortRequested(context, execContext, options)) { |
| 461 | markToolCallCancelled('Request aborted before tool execution') |
| 462 | markToolResultSeen(toolCall.id) |
| 463 | await completeAsyncToolCall({ |
| 464 | toolCallId: toolCall.id, |
| 465 | status: MothershipStreamV1AsyncToolRecordStatus.cancelled, |
| 466 | result: { cancelled: true }, |
| 467 | error: 'Request aborted before tool execution', |
| 468 | }).catch((err) => { |
| 469 | logger.warn('Failed to persist async tool status', { |
| 470 | toolCallId: toolCall.id, |
| 471 | error: toError(err).message, |
| 472 | }) |
| 473 | }) |
| 474 | publishTerminalToolConfirmation({ |
| 475 | toolCallId: toolCall.id, |
| 476 | status: MothershipStreamV1ToolOutcome.cancelled, |
| 477 | message: 'Request aborted before tool execution', |
| 478 | data: { cancelled: true }, |
| 479 | }) |
| 480 | return cancelledCompletion('Request aborted before tool execution') |
| 481 | } |
| 482 | |
| 483 | toolCall.status = 'executing' |
| 484 | await upsertAsyncToolCall({ |
| 485 | runId: context.runId, |
| 486 | toolCallId: toolCall.id, |
| 487 | toolName: toolCall.name, |
| 488 | args: toolCall.params, |
| 489 | }).catch((err) => { |
| 490 | logger.warn('Failed to persist async tool row before execution', { |
| 491 | toolCallId: toolCall.id, |
| 492 | error: toError(err).message, |
| 493 | }) |
| 494 | }) |
no test coverage detected