( toolCallId: string, toolName: string, params: Record<string, unknown> )
| 265 | } |
| 266 | |
| 267 | async function doExecuteRunTool( |
| 268 | toolCallId: string, |
| 269 | toolName: string, |
| 270 | params: Record<string, unknown> |
| 271 | ): Promise<void> { |
| 272 | const { activeWorkflowId, setActiveWorkflow } = useWorkflowRegistry.getState() |
| 273 | const targetWorkflowId = |
| 274 | typeof params.workflowId === 'string' && params.workflowId.length > 0 |
| 275 | ? params.workflowId |
| 276 | : activeWorkflowId |
| 277 | |
| 278 | if (!targetWorkflowId) { |
| 279 | logger.warn('[RunTool] Execution prevented: no active workflow', { toolCallId, toolName }) |
| 280 | await reportCompletion( |
| 281 | toolCallId, |
| 282 | MothershipStreamV1ToolOutcome.error, |
| 283 | 'No active workflow found' |
| 284 | ) |
| 285 | return |
| 286 | } |
| 287 | |
| 288 | const existingToolCallId = activeRunToolByWorkflowId.get(targetWorkflowId) |
| 289 | if (existingToolCallId) { |
| 290 | logger.warn('[RunTool] Execution prevented: another run tool is already active', { |
| 291 | toolCallId, |
| 292 | toolName, |
| 293 | existingToolCallId, |
| 294 | }) |
| 295 | await reportCompletion( |
| 296 | toolCallId, |
| 297 | MothershipStreamV1ToolOutcome.error, |
| 298 | 'Workflow is already being executed by another tool. Wait for it to complete.' |
| 299 | ) |
| 300 | return |
| 301 | } |
| 302 | |
| 303 | setActiveWorkflow(targetWorkflowId) |
| 304 | activeRunToolByWorkflowId.set(targetWorkflowId, toolCallId) |
| 305 | |
| 306 | const { getWorkflowExecution, setIsExecuting } = useExecutionStore.getState() |
| 307 | const { isExecuting } = getWorkflowExecution(targetWorkflowId) |
| 308 | |
| 309 | if (isExecuting) { |
| 310 | logger.warn('[RunTool] Execution prevented: already executing', { toolCallId, toolName }) |
| 311 | activeRunToolByWorkflowId.delete(targetWorkflowId) |
| 312 | await reportCompletion( |
| 313 | toolCallId, |
| 314 | MothershipStreamV1ToolOutcome.error, |
| 315 | 'Workflow is already executing. Try again later' |
| 316 | ) |
| 317 | return |
| 318 | } |
| 319 | |
| 320 | // Extract params for all tool types |
| 321 | const workflowInput = resolveWorkflowInput(params) |
| 322 | const triggerBlockId = resolveTriggerBlockId(params) |
| 323 | const useDraftState = params.useDeployedState !== true |
| 324 |
no test coverage detected