Files
sim/apps/sim/tools/workflow/executor.ts
waleed a25b26e1e9 fix(tool-input): correct workflow selector visibility and tighten (optional) spacing
- Set workflowId param to user-only in workflow_executor tool config
  so "Select Workflow" no longer shows "(optional)" indicator
- Tighten (optional) label spacing with -ml-[3px] to counteract
  parent Label's gap-[6px], making it feel inline with the label text

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 11:42:45 -08:00

69 lines
2.4 KiB
TypeScript

import type { ToolConfig } from '@/tools/types'
import type { WorkflowExecutorParams, WorkflowExecutorResponse } from '@/tools/workflow/types'
/**
* Tool for executing workflows as blocks within other workflows.
* This tool is used by the WorkflowBlockHandler to provide the execution capability.
*/
export const workflowExecutorTool: ToolConfig<
WorkflowExecutorParams,
WorkflowExecutorResponse['output']
> = {
id: 'workflow_executor',
name: 'Workflow Executor',
description:
'Execute another workflow as a sub-workflow. Pass inputs as a JSON object with field names matching the child workflow\'s input format. Example: if child expects "name" and "email", pass {"name": "John", "email": "john@example.com"}',
version: '1.0.0',
params: {
workflowId: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'The ID of the workflow to execute',
},
inputMapping: {
type: 'object',
required: false,
visibility: 'user-or-llm',
description:
'JSON object with keys matching the child workflow\'s input field names. Each key should map to the value you want to pass for that input field. Example: {"fieldName": "value", "otherField": 123}',
},
},
request: {
url: (params: WorkflowExecutorParams) => `/api/workflows/${params.workflowId}/execute`,
method: 'POST',
headers: () => ({ 'Content-Type': 'application/json' }),
body: (params: WorkflowExecutorParams) => {
let inputData = params.inputMapping || {}
if (typeof inputData === 'string') {
try {
inputData = JSON.parse(inputData)
} catch {
inputData = {}
}
}
// Use draft state for manual runs (not deployed), deployed state for deployed runs
const isDeployedContext = params._context?.isDeployedContext
return {
input: inputData,
triggerType: 'api',
useDraftState: !isDeployedContext,
}
},
},
transformResponse: async (response: Response) => {
const data = await response.json()
const outputData = data?.output ?? {}
return {
success: data?.success ?? false,
duration: data?.metadata?.duration ?? 0,
childWorkflowId: data?.workflowId ?? '',
childWorkflowName: data?.workflowName ?? '',
output: outputData, // For OpenAI provider
result: outputData, // For backwards compatibility
error: data?.error,
}
},
}