From 865912929945ce7f8345233735fbbdb7ea148407 Mon Sep 17 00:00:00 2001 From: Donnie Adams Date: Sat, 8 Mar 2025 15:14:23 -0500 Subject: [PATCH] enhance: allow 100MB workspace file uploads Signed-off-by: Donnie Adams --- pkg/api/handlers/agent.go | 10 +++++++++- pkg/api/handlers/files.go | 15 ++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/pkg/api/handlers/agent.go b/pkg/api/handlers/agent.go index c91feaabe..aaae06445 100644 --- a/pkg/api/handlers/agent.go +++ b/pkg/api/handlers/agent.go @@ -372,7 +372,15 @@ func (a *AgentHandler) UploadFile(req api.Context) error { return err } - if err := uploadFile(req.Context(), req, a.gptscript, workspaceName); err != nil { + var ws v1.Workspace + if err := req.Get(&ws, workspaceName); err != nil { + return fmt.Errorf("failed to get workspace with id %s: %w", workspaceName, err) + } + + if _, err := uploadFileToWorkspace(req.Context(), req, a.gptscript, ws.Status.WorkspaceID, "files/", api.BodyOptions{ + // 100MB + MaxBytes: 100 * 1024 * 1024, + }); err != nil { return err } diff --git a/pkg/api/handlers/files.go b/pkg/api/handlers/files.go index ebd5200ca..8f3090d70 100644 --- a/pkg/api/handlers/files.go +++ b/pkg/api/handlers/files.go @@ -71,7 +71,10 @@ func (f *FilesHandler) UploadFile(req api.Context) error { return types.NewErrNotFound("no workspace found") } - _, err = uploadFileToWorkspace(req.Context(), req, f.gptScript, thread.Status.WorkspaceID, "files/") + _, err = uploadFileToWorkspace(req.Context(), req, f.gptScript, thread.Status.WorkspaceID, "files/", api.BodyOptions{ + // 100MB + MaxBytes: 100 * 1024 * 1024, + }) return err } @@ -282,16 +285,6 @@ func convertFile(file, prefix string) types.File { } } -func uploadFile(ctx context.Context, req api.Context, gClient *gptscript.GPTScript, workspaceName string) error { - var ws v1.Workspace - if err := req.Get(&ws, workspaceName); err != nil { - return fmt.Errorf("failed to get workspace with id %s: %w", workspaceName, err) - } - - _, err := uploadFileToWorkspace(ctx, req, gClient, ws.Status.WorkspaceID, "files/") - return err -} - func getFileInWorkspace(ctx context.Context, req api.Context, gClient *gptscript.GPTScript, workspaceID, prefix string) error { file := req.PathValue("file") if file == "" {