diff options
| author | adamdottv <[email protected]> | 2025-05-15 12:44:16 -0500 |
|---|---|---|
| committer | adamdottv <[email protected]> | 2025-05-15 12:44:16 -0500 |
| commit | a65e593ab4f35e1a647832ba36be2c696e1f5165 (patch) | |
| tree | 38eed9994399e426a418c1e0424fe55133b648f4 /internal/tui/components | |
| parent | 5d9058eb74581091d84b2cd935927da636b3dd37 (diff) | |
| download | opencode-a65e593ab4f35e1a647832ba36be2c696e1f5165.tar.gz opencode-a65e593ab4f35e1a647832ba36be2c696e1f5165.zip | |
feat: batch tool
Diffstat (limited to 'internal/tui/components')
| -rw-r--r-- | internal/tui/components/chat/message.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/internal/tui/components/chat/message.go b/internal/tui/components/chat/message.go index 58c0aed49..f887337ae 100644 --- a/internal/tui/components/chat/message.go +++ b/internal/tui/components/chat/message.go @@ -266,6 +266,8 @@ func toolName(name string) string { return "Write" case tools.PatchToolName: return "Patch" + case tools.BatchToolName: + return "Batch" } return name } @@ -292,6 +294,8 @@ func getToolAction(name string) string { return "Preparing write..." case tools.PatchToolName: return "Preparing patch..." + case tools.BatchToolName: + return "Running batch operations..." } return "Working..." } @@ -443,6 +447,10 @@ func renderToolParams(paramWidth int, toolCall message.ToolCall) string { json.Unmarshal([]byte(toolCall.Input), ¶ms) filePath := removeWorkingDirPrefix(params.FilePath) return renderParams(paramWidth, filePath) + case tools.BatchToolName: + var params tools.BatchParams + json.Unmarshal([]byte(toolCall.Input), ¶ms) + return renderParams(paramWidth, fmt.Sprintf("%d parallel calls", len(params.Calls))) default: input := strings.ReplaceAll(toolCall.Input, "\n", " ") params = renderParams(paramWidth, input) @@ -540,6 +548,38 @@ func renderToolResponse(toolCall message.ToolCall, response message.ToolResult, toMarkdown(resultContent, true, width), t.Background(), ) + case tools.BatchToolName: + var batchResult tools.BatchResult + if err := json.Unmarshal([]byte(resultContent), &batchResult); err != nil { + return baseStyle.Width(width).Foreground(t.Error()).Render(fmt.Sprintf("Error parsing batch result: %s", err)) + } + + var toolCalls []string + for i, result := range batchResult.Results { + toolName := toolName(result.ToolName) + + // Format the tool input as a string + inputStr := string(result.ToolInput) + + // Format the result + var resultStr string + if result.Error != "" { + resultStr = fmt.Sprintf("Error: %s", result.Error) + } else { + var toolResponse tools.ToolResponse + if err := json.Unmarshal(result.Result, &toolResponse); err != nil { + resultStr = "Error parsing tool response" + } else { + resultStr = truncateHeight(toolResponse.Content, 3) + } + } + + // Format the tool call + toolCall := fmt.Sprintf("%d. %s: %s\n %s", i+1, toolName, inputStr, resultStr) + toolCalls = append(toolCalls, toolCall) + } + + return baseStyle.Width(width).Foreground(t.TextMuted()).Render(strings.Join(toolCalls, "\n\n")) default: resultContent = fmt.Sprintf("```text\n%s\n```", resultContent) return styles.ForceReplaceBackgroundWithLipgloss( |
