Skip to content

Commit 8f309b1

Browse files
committed
tweaks
1 parent e85d5f1 commit 8f309b1

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

packages/opencode/src/tool/batch.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,23 @@ export const BatchTool = Tool.define("batch", async () => {
7878
const successfulCalls = results.filter((r) => r.success).length
7979
const failedCalls = toolCalls.length - successfulCalls
8080

81+
const outputParts = results.map((r) => {
82+
if (r.success) {
83+
return `<tool_result name="${r.tool}">\n${r.result.output}\n</tool_result>`
84+
}
85+
const errorMessage = r.error instanceof Error ? r.error.message : String(r.error)
86+
return `<tool_result name="${r.tool}">\nError: ${errorMessage}\n</tool_result>`
87+
})
88+
8189
const outputMessage =
8290
failedCalls > 0
83-
? `Executed ${successfulCalls}/${toolCalls.length} tools successfully. ${failedCalls} failed.`
84-
: `All ${successfulCalls} tools executed successfully.\n\nKeep using the batch tool for optimal performance in your next response!`
91+
? `Executed ${successfulCalls}/${toolCalls.length} tools successfully. ${failedCalls} failed.\n\n${outputParts.join("\n\n")}`
92+
: `All ${successfulCalls} tools executed successfully.\n\n${outputParts.join("\n\n")}\n\nKeep using the batch tool for optimal performance in your next response!`
8593

8694
return {
8795
title: `Batch execution (${successfulCalls}/${toolCalls.length} successful)`,
8896
output: outputMessage,
89-
attachments: results.filter((result) => result.success).flatMap((r) => r.result.attachments),
97+
attachments: results.filter((result) => result.success).flatMap((r) => r.result.attachments ?? []),
9098
metadata: {
9199
totalCalls: toolCalls.length,
92100
successful: successfulCalls,

0 commit comments

Comments
 (0)