Skip to content

chore: move the workspace-provider tool to a daemon #881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion pkg/engine/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@ const DaemonURLSuffix = ".daemon.gptscript.local"
func (e *Engine) runHTTP(ctx context.Context, prg *types.Program, tool types.Tool, input string) (cmdRet *Return, cmdErr error) {
envMap := map[string]string{}

for _, env := range appendInputAsEnv(nil, input) {
k, v, _ := strings.Cut(env, "=")
envMap[k] = v
}

for _, env := range e.Env {
k, v, _ := strings.Cut(env, "=")
envMap[k] = v
}

toolURL := strings.Split(tool.Instructions, "\n")[0][2:]
toolURL = os.Expand(toolURL, func(s string) string {
return envMap[s]
return url.PathEscape(envMap[s])
})

parsed, err := url.Parse(toolURL)
Expand Down Expand Up @@ -61,6 +66,10 @@ func (e *Engine) runHTTP(ctx context.Context, prg *types.Program, tool types.Too
}, nil
}

if body, ok := envMap["BODY"]; ok {
input = body
}

req, err := http.NewRequestWithContext(ctx, http.MethodPost, toolURL, strings.NewReader(input))
if err != nil {
return nil, err
Expand Down
13 changes: 6 additions & 7 deletions pkg/sdkserver/workspaces.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sdkserver

import (
"encoding/base64"
"encoding/json"
"fmt"
"net/http"
Expand Down Expand Up @@ -175,8 +176,7 @@ func (s *server) removeAllWithPrefixInWorkspace(w http.ResponseWriter, r *http.R
type writeFileInWorkspaceRequest struct {
workspaceCommonRequest `json:",inline"`
FilePath string `json:"filePath"`
Contents string `json:"contents"`
Base64EncodedInput bool `json:"base64EncodedInput"`
Contents []byte `json:"contents"`
}

func (s *server) writeFileInWorkspace(w http.ResponseWriter, r *http.Request) {
Expand All @@ -198,8 +198,8 @@ func (s *server) writeFileInWorkspace(w http.ResponseWriter, r *http.Request) {
prg,
reqObject.Env,
fmt.Sprintf(
`{"workspace_id": "%s", "file_path": "%s", "file_contents": "%s", "write_file_base64_encoded_input": %t}`,
reqObject.ID, reqObject.FilePath, reqObject.Contents, reqObject.Base64EncodedInput,
`{"workspace_id": "%s", "file_path": "%s", "body": "%s"}`,
reqObject.ID, reqObject.FilePath, base64.StdEncoding.EncodeToString(reqObject.Contents),
),
)
if err != nil {
Expand Down Expand Up @@ -249,7 +249,6 @@ func (s *server) removeFileInWorkspace(w http.ResponseWriter, r *http.Request) {
type readFileInWorkspaceRequest struct {
workspaceCommonRequest `json:",inline"`
FilePath string `json:"filePath"`
Base64EncodeOutput bool `json:"base64EncodeOutput"`
}

func (s *server) readFileInWorkspace(w http.ResponseWriter, r *http.Request) {
Expand All @@ -271,8 +270,8 @@ func (s *server) readFileInWorkspace(w http.ResponseWriter, r *http.Request) {
prg,
reqObject.Env,
fmt.Sprintf(
`{"workspace_id": "%s", "file_path": "%s", "read_file_base64_encode_output": %t}`,
reqObject.ID, reqObject.FilePath, reqObject.Base64EncodeOutput,
`{"workspace_id": "%s", "file_path": "%s"}`,
reqObject.ID, reqObject.FilePath,
),
)
if err != nil {
Expand Down