Skip to content

Commit eb269be

Browse files
authored
Merge pull request #532 from rumpl/fix-todos-sidebar
Fix rendering of the todos in the sidebar
2 parents 641fecc + b9ec2a5 commit eb269be

1 file changed

Lines changed: 8 additions & 14 deletions

File tree

pkg/tui/components/todo/todo.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package todo
33
import (
44
"encoding/json"
55
"fmt"
6+
"log/slog"
67
"strings"
78

89
"github.com/charmbracelet/lipgloss/v2"
910

1011
"github.com/docker/cagent/pkg/tools"
12+
"github.com/docker/cagent/pkg/tools/builtin"
1113
"github.com/docker/cagent/pkg/tui/styles"
1214
)
1315

@@ -42,9 +44,7 @@ func (c *Component) SetTodos(toolCall tools.ToolCall) error {
4244
arguments := toolCall.Function.Arguments
4345
switch toolName {
4446
case "create_todo":
45-
var params struct {
46-
Description string `json:"description"`
47-
}
47+
var params builtin.CreateTodoArgs
4848
if err := json.Unmarshal([]byte(arguments), &params); err != nil {
4949
return err
5050
}
@@ -58,30 +58,23 @@ func (c *Component) SetTodos(toolCall tools.ToolCall) error {
5858
c.todos = append(c.todos, newTodo)
5959

6060
case "create_todos":
61-
var params struct {
62-
Todos []struct {
63-
Description string `json:"description"`
64-
} `json:"todos"`
65-
}
61+
var params builtin.CreateTodosArgs
6662
if err := json.Unmarshal([]byte(arguments), &params); err != nil {
6763
return err
6864
}
6965

7066
// Add all new todos
71-
for _, todoParam := range params.Todos {
67+
for _, todoParam := range params.Descriptions {
7268
newTodo := Todo{
7369
ID: fmt.Sprintf("todo_%d", len(c.todos)+1),
74-
Description: todoParam.Description,
70+
Description: todoParam,
7571
Status: "pending",
7672
}
7773
c.todos = append(c.todos, newTodo)
7874
}
7975

8076
case "update_todo":
81-
var params struct {
82-
ID string `json:"id"`
83-
Status string `json:"status"`
84-
}
77+
var params builtin.UpdateTodoArgs
8578
if err := json.Unmarshal([]byte(arguments), &params); err != nil {
8679
return err
8780
}
@@ -101,6 +94,7 @@ func (c *Component) SetTodos(toolCall tools.ToolCall) error {
10194
// Render renders the todo component
10295
func (c *Component) Render() string {
10396
if len(c.todos) == 0 {
97+
slog.Debug("No todos to render")
10498
return ""
10599
}
106100

0 commit comments

Comments
 (0)