(customTool: any, isClient = true, workflowId?: string)
| 255 | * @param workflowId Optional workflow ID for server-side |
| 256 | */ |
| 257 | export function createCustomToolRequestBody(customTool: any, isClient = true, workflowId?: string) { |
| 258 | return (params: Record<string, any>) => { |
| 259 | // Get environment variables - try multiple sources in order of preference: |
| 260 | // 1. envVars parameter (passed from provider/agent context) |
| 261 | // 2. Client-side store (if running in browser) |
| 262 | // 3. Empty object (fallback) |
| 263 | const envVars = normalizeStringRecord(params.envVars || (isClient ? getClientEnvVars() : {})) |
| 264 | |
| 265 | const workflowVariables = normalizeWorkflowVariables(params.workflowVariables) |
| 266 | |
| 267 | const blockData = normalizeRecord(params.blockData) |
| 268 | const blockNameMapping = normalizeStringRecord(params.blockNameMapping) |
| 269 | |
| 270 | // Include everything needed for execution |
| 271 | return { |
| 272 | code: customTool.code, |
| 273 | params: params, // These will be available in the VM context |
| 274 | schema: customTool.schema.function.parameters, // For validation |
| 275 | envVars: envVars, // Environment variables |
| 276 | workflowVariables: workflowVariables, // Workflow variables for <variable.name> resolution |
| 277 | blockData: blockData, // Runtime block outputs for <block.field> resolution |
| 278 | blockNameMapping: blockNameMapping, // Block name to ID mapping |
| 279 | workflowId: params._context?.workflowId || workflowId, // Pass workflowId for server-side context |
| 280 | userId: params._context?.userId, // Pass userId for auth context |
| 281 | isCustomTool: true, // Flag to indicate this is a custom tool execution |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | // Get a tool by its ID |
| 287 | export function getTool(toolId: string, _workspaceId?: string): ToolConfig | undefined { |
no test coverage detected