Files
simstudioai--sim/apps/sim/tools/workflow/executor.ts
T
wehub-resource-sync d25d482dc2
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:20:55 +08:00

71 lines
2.5 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
const parentWorkspaceId = params._context?.workspaceId
return {
input: inputData,
triggerType: 'workflow',
useDraftState: !isDeployedContext,
...(parentWorkspaceId ? { parentWorkspaceId } : {}),
}
},
},
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,
}
},
}