From ef8de8fa59ae4e0f0aeba84ed11741dd99c061d2 Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Tue, 17 Dec 2024 16:20:01 -0700 Subject: [PATCH] chore: add getfile to agents and workflows APIs --- pkg/api/handlers/agent.go | 18 ++++++++++++++++++ pkg/api/router/router.go | 2 ++ 2 files changed, 20 insertions(+) diff --git a/pkg/api/handlers/agent.go b/pkg/api/handlers/agent.go index 0042cc27..efd7eae3 100644 --- a/pkg/api/handlers/agent.go +++ b/pkg/api/handlers/agent.go @@ -281,6 +281,24 @@ func (a *AgentHandler) ListFiles(req api.Context) error { return listFiles(req.Context(), req, a.gptscript, workspaceName) } +func (a *AgentHandler) GetFile(req api.Context) error { + var ( + agentID = req.PathValue("id") + ) + + var agent v1.Agent + if err := req.Get(&agent, agentID); err != nil { + return err + } + + var workspace v1.Workspace + if err := req.Get(&workspace, agent.Status.WorkspaceName); err != nil { + return err + } + + return getFileInWorkspace(req.Context(), req, a.gptscript, workspace.Status.WorkspaceID, "files/") +} + func (a *AgentHandler) UploadFile(req api.Context) error { workspaceName, err := a.getWorkspaceName(req, req.PathValue("id")) if err != nil { diff --git a/pkg/api/router/router.go b/pkg/api/router/router.go index fdcd8bba..e30cd87e 100644 --- a/pkg/api/router/router.go +++ b/pkg/api/router/router.go @@ -97,6 +97,7 @@ func Router(services *services.Services) (http.Handler, error) { // Agent files mux.HandleFunc("GET /api/agents/{id}/files", agents.ListFiles) + mux.HandleFunc("GET /api/agents/{id}/file/{file...}", agents.GetFile) mux.HandleFunc("POST /api/agents/{id}/files/{file}", agents.UploadFile) mux.HandleFunc("DELETE /api/agents/{id}/files/{file}", agents.DeleteFile) @@ -151,6 +152,7 @@ func Router(services *services.Services) (http.Handler, error) { // Workflow files mux.HandleFunc("GET /api/workflows/{id}/files", agents.ListFiles) + mux.HandleFunc("GET /api/workflows/{id}/file/{file...}", agents.GetFile) mux.HandleFunc("POST /api/workflows/{id}/files/{file}", agents.UploadFile) mux.HandleFunc("DELETE /api/workflows/{id}/files/{file}", agents.DeleteFile)