11package defaulttool
22
33import (
4- "fmt"
5-
64 tea "charm.land/bubbletea/v2"
7- "github.com/charmbracelet/glamour/v2"
85
96 "github.com/docker/cagent/pkg/tui/components/spinner"
107 "github.com/docker/cagent/pkg/tui/components/toolcommon"
@@ -18,25 +15,22 @@ import (
1815// that don't have a specialized component registered.
1916// It provides a standard visualization with tool name, arguments, and results.
2017type Component struct {
21- message * types.Message
22- renderer * glamour.TermRenderer
23- spinner spinner.Spinner
24- width int
25- height int
18+ message * types.Message
19+ spinner spinner.Spinner
20+ width int
21+ height int
2622}
2723
2824// New creates a new default tool component.
2925func New (
3026 msg * types.Message ,
31- renderer * glamour.TermRenderer ,
3227 _ * service.SessionState ,
3328) layout.Model {
3429 return & Component {
35- message : msg ,
36- renderer : renderer ,
37- spinner : spinner .New (spinner .ModeSpinnerOnly ),
38- width : 80 ,
39- height : 1 ,
30+ message : msg ,
31+ spinner : spinner .New (spinner .ModeSpinnerOnly ),
32+ width : 80 ,
33+ height : 1 ,
4034 }
4135}
4236
@@ -68,20 +62,20 @@ func (c *Component) Update(msg tea.Msg) (layout.Model, tea.Cmd) {
6862func (c * Component ) View () string {
6963 msg := c .message
7064 displayName := msg .ToolDefinition .DisplayName ()
71- content := fmt .Sprintf ("%s %s" , toolcommon .Icon (msg .ToolStatus ), styles .HighlightStyle .Render (displayName ))
7265
73- if msg .ToolStatus == types .ToolStatusPending || msg .ToolStatus == types .ToolStatusRunning {
74- content += " " + c .spinner .View ()
66+ var argsContent string
67+ if msg .ToolCall .Function .Arguments != "" {
68+ argsContent = renderToolArgs (msg .ToolCall , c .width - 3 )
7569 }
7670
77- if msg . ToolCall . Function . Arguments ! = "" {
78- content += " \n " + renderToolArgs ( msg .ToolCall , c . width - 3 )
71+ if argsContent = = "" {
72+ return toolcommon . RenderTool ( toolcommon . Icon ( msg .ToolStatus ), msg . ToolDefinition . DisplayName (), c . spinner . View (), "" , c . width )
7973 }
8074
8175 var resultContent string
8276 if (msg .ToolStatus == types .ToolStatusCompleted || msg .ToolStatus == types .ToolStatusError ) && msg .Content != "" {
8377 resultContent = toolcommon .FormatToolResult (msg .Content , c .width )
8478 }
8579
86- return styles . BaseStyle . PaddingLeft ( 2 ). PaddingTop ( 1 ). Render (content + resultContent )
80+ return toolcommon . RenderTool ( toolcommon . Icon ( msg . ToolStatus ), styles . HighlightStyle . Render (displayName ), argsContent , resultContent , c . width )
8781}
0 commit comments