(
tool: {
params?: Record<string, any>
parameters?: Record<string, any>
paramsTransform?: (params: Record<string, any>) => Record<string, any>
},
llmArgs: Record<string, any>,
request: {
workflowId?: string
workspaceId?: string
chatId?: string
userId?: string
environmentVariables?: Record<string, any>
workflowVariables?: Record<string, any>
blockData?: Record<string, any>
blockNameMapping?: Record<string, string>
isDeployedContext?: boolean
callChain?: string[]
}
)
| 1261 | * Prepare tool execution parameters, separating tool parameters from system parameters |
| 1262 | */ |
| 1263 | export function prepareToolExecution( |
| 1264 | tool: { |
| 1265 | params?: Record<string, any> |
| 1266 | parameters?: Record<string, any> |
| 1267 | paramsTransform?: (params: Record<string, any>) => Record<string, any> |
| 1268 | }, |
| 1269 | llmArgs: Record<string, any>, |
| 1270 | request: { |
| 1271 | workflowId?: string |
| 1272 | workspaceId?: string |
| 1273 | chatId?: string |
| 1274 | userId?: string |
| 1275 | environmentVariables?: Record<string, any> |
| 1276 | workflowVariables?: Record<string, any> |
| 1277 | blockData?: Record<string, any> |
| 1278 | blockNameMapping?: Record<string, string> |
| 1279 | isDeployedContext?: boolean |
| 1280 | callChain?: string[] |
| 1281 | } |
| 1282 | ): { |
| 1283 | toolParams: Record<string, any> |
| 1284 | executionParams: Record<string, any> |
| 1285 | } { |
| 1286 | let toolParams = mergeToolParameters(tool.params || {}, llmArgs) as Record<string, any> |
| 1287 | |
| 1288 | if (tool.paramsTransform) { |
| 1289 | try { |
| 1290 | toolParams = tool.paramsTransform(toolParams) |
| 1291 | } catch (err) { |
| 1292 | logger.warn('paramsTransform failed, using raw params', { error: err }) |
| 1293 | } |
| 1294 | } |
| 1295 | |
| 1296 | const executionParams = { |
| 1297 | ...toolParams, |
| 1298 | ...(request.workflowId |
| 1299 | ? { |
| 1300 | _context: { |
| 1301 | workflowId: request.workflowId, |
| 1302 | ...(request.workspaceId ? { workspaceId: request.workspaceId } : {}), |
| 1303 | ...(request.chatId ? { chatId: request.chatId } : {}), |
| 1304 | ...(request.userId ? { userId: request.userId } : {}), |
| 1305 | ...(request.isDeployedContext !== undefined |
| 1306 | ? { isDeployedContext: request.isDeployedContext } |
| 1307 | : {}), |
| 1308 | ...(request.callChain ? { callChain: request.callChain } : {}), |
| 1309 | }, |
| 1310 | } |
| 1311 | : {}), |
| 1312 | ...(request.environmentVariables |
| 1313 | ? { envVars: normalizeStringRecord(request.environmentVariables) } |
| 1314 | : {}), |
| 1315 | ...(request.workflowVariables |
| 1316 | ? { workflowVariables: normalizeWorkflowVariables(request.workflowVariables) } |
| 1317 | : {}), |
| 1318 | ...(request.blockData ? { blockData: normalizeRecord(request.blockData) } : {}), |
| 1319 | ...(request.blockNameMapping |
| 1320 | ? { blockNameMapping: normalizeStringRecord(request.blockNameMapping) } |
no test coverage detected