diff options
| author | Peter Stone <thepeterstone@gmail.com> | 2026-03-07 23:54:32 +0000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-03-08 06:27:34 +0000 |
| commit | d422394021e4fb9ddb5405024468f03d962c5f5d (patch) | |
| tree | e3d4ef9c9b49aee21cba553c33abbbbdb7359f72 /internal | |
| parent | c6ce11e17af9a4b62bbbc082e5f13bb3a3b656a6 (diff) | |
feat(api): update template handlers to use AgentConfig
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/api/templates.go | 14 | ||||
| -rw-r--r-- | internal/api/templates_test.go | 13 |
2 files changed, 17 insertions, 10 deletions
diff --git a/internal/api/templates.go b/internal/api/templates.go index 0139895..024a6df 100644 --- a/internal/api/templates.go +++ b/internal/api/templates.go @@ -27,7 +27,7 @@ func (s *Server) handleCreateTemplate(w http.ResponseWriter, r *http.Request) { var input struct { Name string `json:"name"` Description string `json:"description"` - Claude task.ClaudeConfig `json:"claude"` + Agent task.AgentConfig `json:"agent"` Timeout string `json:"timeout"` Priority string `json:"priority"` Tags []string `json:"tags"` @@ -46,13 +46,16 @@ func (s *Server) handleCreateTemplate(w http.ResponseWriter, r *http.Request) { ID: uuid.New().String(), Name: input.Name, Description: input.Description, - Claude: input.Claude, + Agent: input.Agent, Timeout: input.Timeout, Priority: input.Priority, Tags: input.Tags, CreatedAt: now, UpdatedAt: now, } + if tmpl.Agent.Type == "" { + tmpl.Agent.Type = "claude" + } if tmpl.Priority == "" { tmpl.Priority = "normal" } @@ -98,7 +101,7 @@ func (s *Server) handleUpdateTemplate(w http.ResponseWriter, r *http.Request) { var input struct { Name string `json:"name"` Description string `json:"description"` - Claude task.ClaudeConfig `json:"claude"` + Agent task.AgentConfig `json:"agent"` Timeout string `json:"timeout"` Priority string `json:"priority"` Tags []string `json:"tags"` @@ -114,7 +117,10 @@ func (s *Server) handleUpdateTemplate(w http.ResponseWriter, r *http.Request) { existing.Name = input.Name existing.Description = input.Description - existing.Claude = input.Claude + existing.Agent = input.Agent + if existing.Agent.Type == "" { + existing.Agent.Type = "claude" + } existing.Timeout = input.Timeout existing.Priority = input.Priority if input.Tags != nil { diff --git a/internal/api/templates_test.go b/internal/api/templates_test.go index bbcfc87..474c5d4 100644 --- a/internal/api/templates_test.go +++ b/internal/api/templates_test.go @@ -34,7 +34,8 @@ func TestCreateTemplate_Success(t *testing.T) { payload := `{ "name": "Go: Run Tests", "description": "Run the full test suite with race detector", - "claude": { + "agent": { + "type": "claude", "model": "sonnet", "instructions": "Run go test -race ./...", "max_budget_usd": 0.50, @@ -65,7 +66,7 @@ func TestCreateTemplate_Success(t *testing.T) { func TestGetTemplate_AfterCreate(t *testing.T) { srv, _ := testServer(t) - payload := `{"name": "Fetch Me", "claude": {"instructions": "do thing", "model": "haiku"}}` + payload := `{"name": "Fetch Me", "agent": {"type": "claude", "instructions": "do thing", "model": "haiku"}}` req := httptest.NewRequest("POST", "/api/templates", bytes.NewBufferString(payload)) w := httptest.NewRecorder() srv.Handler().ServeHTTP(w, req) @@ -107,14 +108,14 @@ func TestGetTemplate_NotFound(t *testing.T) { func TestUpdateTemplate(t *testing.T) { srv, _ := testServer(t) - payload := `{"name": "Original Name", "claude": {"instructions": "original"}}` + payload := `{"name": "Original Name", "agent": {"type": "claude", "instructions": "original"}}` req := httptest.NewRequest("POST", "/api/templates", bytes.NewBufferString(payload)) w := httptest.NewRecorder() srv.Handler().ServeHTTP(w, req) var created storage.Template json.NewDecoder(w.Body).Decode(&created) - update := `{"name": "Updated Name", "claude": {"instructions": "updated"}}` + update := `{"name": "Updated Name", "agent": {"type": "claude", "instructions": "updated"}}` req2 := httptest.NewRequest("PUT", fmt.Sprintf("/api/templates/%s", created.ID), bytes.NewBufferString(update)) w2 := httptest.NewRecorder() srv.Handler().ServeHTTP(w2, req2) @@ -132,7 +133,7 @@ func TestUpdateTemplate(t *testing.T) { func TestUpdateTemplate_NotFound(t *testing.T) { srv, _ := testServer(t) - update := `{"name": "Ghost", "claude": {"instructions": "x"}}` + update := `{"name": "Ghost", "agent": {"type": "claude", "instructions": "x"}}` req := httptest.NewRequest("PUT", "/api/templates/nonexistent", bytes.NewBufferString(update)) w := httptest.NewRecorder() srv.Handler().ServeHTTP(w, req) @@ -145,7 +146,7 @@ func TestUpdateTemplate_NotFound(t *testing.T) { func TestDeleteTemplate(t *testing.T) { srv, _ := testServer(t) - payload := `{"name": "To Delete", "claude": {"instructions": "bye"}}` + payload := `{"name": "To Delete", "agent": {"type": "claude", "instructions": "bye"}}` req := httptest.NewRequest("POST", "/api/templates", bytes.NewBufferString(payload)) w := httptest.NewRecorder() srv.Handler().ServeHTTP(w, req) |
