( ctx: ExecutionContext, inputTools: unknown )
| 35 | * added to the block are included, and `usageControl: 'none'` tools are dropped. |
| 36 | */ |
| 37 | export async function buildSimToolSpecs( |
| 38 | ctx: ExecutionContext, |
| 39 | inputTools: unknown |
| 40 | ): Promise<PiToolSpec[]> { |
| 41 | if (!Array.isArray(inputTools)) return [] |
| 42 | |
| 43 | const specs: PiToolSpec[] = [] |
| 44 | |
| 45 | for (const tool of inputTools as ToolInput[]) { |
| 46 | if ((tool.usageControl || 'auto') === 'none') continue |
| 47 | if (!tool.type || tool.type === 'mcp' || tool.type === 'custom-tool') continue |
| 48 | |
| 49 | try { |
| 50 | const provider = await transformBlockTool(tool, { |
| 51 | selectedOperation: tool.operation, |
| 52 | getAllBlocks, |
| 53 | getTool, |
| 54 | getToolAsync, |
| 55 | }) |
| 56 | |
| 57 | if (!provider?.id) continue |
| 58 | |
| 59 | const toolId = provider.id |
| 60 | const preseededParams = provider.params || {} |
| 61 | |
| 62 | specs.push({ |
| 63 | name: toolId, |
| 64 | description: provider.description || '', |
| 65 | parameters: (provider.parameters as Record<string, unknown>) || { |
| 66 | type: 'object', |
| 67 | properties: {}, |
| 68 | }, |
| 69 | execute: async (args) => { |
| 70 | try { |
| 71 | const result = await executeTool( |
| 72 | toolId, |
| 73 | { |
| 74 | ...preseededParams, |
| 75 | ...args, |
| 76 | // Trusted execution context, spread last so an LLM-supplied |
| 77 | // `_context` arg can't override it. executeTool reads this directly |
| 78 | // for OAuth-credential resolution and internal-route identity, the |
| 79 | // same way the Agent block's tool calls do. |
| 80 | _context: { |
| 81 | workflowId: ctx.workflowId, |
| 82 | workspaceId: ctx.workspaceId, |
| 83 | executionId: ctx.executionId, |
| 84 | userId: ctx.userId, |
| 85 | isDeployedContext: ctx.isDeployedContext, |
| 86 | enforceCredentialAccess: ctx.enforceCredentialAccess, |
| 87 | callChain: ctx.callChain, |
| 88 | }, |
| 89 | }, |
| 90 | { executionContext: ctx } |
| 91 | ) |
| 92 | return toToolResult(result) |
| 93 | } catch (error) { |
| 94 | return { text: getErrorMessage(error, 'Tool execution failed'), isError: true } |
no test coverage detected