Skip to content

Commit 376315d

Browse files
committed
chore: move the workspace-provider tool to a daemon
This also adds support in the daemon implementation for dynamic paths, something that is needed for the workspace-provider daemon to work. Signed-off-by: Donnie Adams <[email protected]>
1 parent 36f9708 commit 376315d

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

pkg/engine/http.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@ const DaemonURLSuffix = ".daemon.gptscript.local"
1818
func (e *Engine) runHTTP(ctx context.Context, prg *types.Program, tool types.Tool, input string) (cmdRet *Return, cmdErr error) {
1919
envMap := map[string]string{}
2020

21+
for _, env := range appendInputAsEnv(nil, input) {
22+
k, v, _ := strings.Cut(env, "=")
23+
envMap[k] = v
24+
}
25+
2126
for _, env := range e.Env {
2227
k, v, _ := strings.Cut(env, "=")
2328
envMap[k] = v
2429
}
2530

2631
toolURL := strings.Split(tool.Instructions, "\n")[0][2:]
2732
toolURL = os.Expand(toolURL, func(s string) string {
28-
return envMap[s]
33+
return url.PathEscape(envMap[s])
2934
})
3035

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

69+
if body, ok := envMap["BODY"]; ok {
70+
input = body
71+
}
72+
6473
req, err := http.NewRequestWithContext(ctx, http.MethodPost, toolURL, strings.NewReader(input))
6574
if err != nil {
6675
return nil, err

pkg/sdkserver/workspaces.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package sdkserver
22

33
import (
4+
"encoding/base64"
45
"encoding/json"
56
"fmt"
67
"net/http"
@@ -175,8 +176,7 @@ func (s *server) removeAllWithPrefixInWorkspace(w http.ResponseWriter, r *http.R
175176
type writeFileInWorkspaceRequest struct {
176177
workspaceCommonRequest `json:",inline"`
177178
FilePath string `json:"filePath"`
178-
Contents string `json:"contents"`
179-
Base64EncodedInput bool `json:"base64EncodedInput"`
179+
Contents []byte `json:"contents"`
180180
}
181181

182182
func (s *server) writeFileInWorkspace(w http.ResponseWriter, r *http.Request) {
@@ -198,8 +198,8 @@ func (s *server) writeFileInWorkspace(w http.ResponseWriter, r *http.Request) {
198198
prg,
199199
reqObject.Env,
200200
fmt.Sprintf(
201-
`{"workspace_id": "%s", "file_path": "%s", "file_contents": "%s", "write_file_base64_encoded_input": %t}`,
202-
reqObject.ID, reqObject.FilePath, reqObject.Contents, reqObject.Base64EncodedInput,
201+
`{"workspace_id": "%s", "file_path": "%s", "body": "%s"}`,
202+
reqObject.ID, reqObject.FilePath, base64.StdEncoding.EncodeToString(reqObject.Contents),
203203
),
204204
)
205205
if err != nil {
@@ -249,7 +249,6 @@ func (s *server) removeFileInWorkspace(w http.ResponseWriter, r *http.Request) {
249249
type readFileInWorkspaceRequest struct {
250250
workspaceCommonRequest `json:",inline"`
251251
FilePath string `json:"filePath"`
252-
Base64EncodeOutput bool `json:"base64EncodeOutput"`
253252
}
254253

255254
func (s *server) readFileInWorkspace(w http.ResponseWriter, r *http.Request) {
@@ -271,8 +270,8 @@ func (s *server) readFileInWorkspace(w http.ResponseWriter, r *http.Request) {
271270
prg,
272271
reqObject.Env,
273272
fmt.Sprintf(
274-
`{"workspace_id": "%s", "file_path": "%s", "read_file_base64_encode_output": %t}`,
275-
reqObject.ID, reqObject.FilePath, reqObject.Base64EncodeOutput,
273+
`{"workspace_id": "%s", "file_path": "%s"}`,
274+
reqObject.ID, reqObject.FilePath,
276275
),
277276
)
278277
if err != nil {

0 commit comments

Comments
 (0)