Skip to content

Commit

Permalink
chore: add getfile to agents and workflows APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Dec 17, 2024
1 parent 00f73a5 commit ef8de8f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/api/handlers/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit ef8de8f

Please sign in to comment.