(params, ctx)
| 30 | return `Invalid parameters for tool 'batch':\n${formattedErrors}\n\nExpected payload format:\n [{"tool": "tool_name", "parameters": {...}}, {...}]` |
| 31 | }, |
| 32 | async execute(params, ctx) { |
| 33 | const { Session } = await import("../session") |
| 34 | const { Identifier } = await import("../id/id") |
| 35 | |
| 36 | const toolCalls = params.tool_calls.slice(0, 10) |
| 37 | const discardedCalls = params.tool_calls.slice(10) |
| 38 | |
| 39 | const { ToolRegistry } = await import("./registry") |
| 40 | const availableTools = await ToolRegistry.tools("") |
| 41 | const toolMap = new Map(availableTools.map((t) => [t.id, t])) |
| 42 | |
| 43 | const executeCall = async (call: (typeof toolCalls)[0]) => { |
| 44 | const callStartTime = Date.now() |
| 45 | const partID = Identifier.ascending("part") |
| 46 | |
| 47 | try { |
| 48 | if (DISALLOWED.has(call.tool)) { |
| 49 | throw new Error( |
| 50 | `Tool '${call.tool}' is not allowed in batch. Disallowed tools: ${Array.from(DISALLOWED).join(", ")}`, |
| 51 | ) |
| 52 | } |
| 53 | |
| 54 | const tool = toolMap.get(call.tool) |
| 55 | if (!tool) { |
| 56 | const availableToolsList = Array.from(toolMap.keys()).filter((name) => !FILTERED_FROM_SUGGESTIONS.has(name)) |
| 57 | throw new Error(`Tool '${call.tool}' not found. Available tools: ${availableToolsList.join(", ")}`) |
| 58 | } |
| 59 | const validatedParams = tool.parameters.parse(call.parameters) |
| 60 | |
| 61 | await Session.updatePart({ |
| 62 | id: partID, |
| 63 | messageID: ctx.messageID, |
| 64 | sessionID: ctx.sessionID, |
| 65 | type: "tool", |
| 66 | tool: call.tool, |
| 67 | callID: partID, |
| 68 | state: { |
| 69 | status: "running", |
| 70 | input: call.parameters, |
| 71 | time: { |
| 72 | start: callStartTime, |
| 73 | }, |
| 74 | }, |
| 75 | }) |
| 76 | |
| 77 | const result = await tool.execute(validatedParams, { ...ctx, callID: partID }) |
| 78 | |
| 79 | await Session.updatePart({ |
| 80 | id: partID, |
| 81 | messageID: ctx.messageID, |
| 82 | sessionID: ctx.sessionID, |
| 83 | type: "tool", |
| 84 | tool: call.tool, |
| 85 | callID: partID, |
| 86 | state: { |
| 87 | status: "completed", |
| 88 | input: call.parameters, |
| 89 | output: result.output, |
nothing calls this directly
no test coverage detected