Skip to content

Commit 419ccbb

Browse files
authored
fix: add ability to create workspaces from other workspaces (#877)
Signed-off-by: Donnie Adams <donnie@acorn.io>
1 parent 0927125 commit 419ccbb

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

pkg/engine/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func appendInputAsEnv(env []string, input string) []string {
223223

224224
newEnv = appendEnv(newEnv, "GPTSCRIPT_INPUT", input)
225225

226-
if err := json.Unmarshal([]byte(input), &data); err != nil {
226+
if err := dec.Decode(&data); err != nil {
227227
// ignore invalid JSON
228228
return newEnv
229229
}

pkg/sdkserver/workspaces.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,29 @@ import (
44
"encoding/json"
55
"fmt"
66
"net/http"
7+
"strings"
78

89
gcontext "github.com/gptscript-ai/gptscript/pkg/context"
910
"github.com/gptscript-ai/gptscript/pkg/loader"
1011
)
1112

1213
type workspaceCommonRequest struct {
13-
ID string `json:"id"`
14-
WorkspaceToolRepo string `json:"workspaceToolRepo"`
14+
ID string `json:"id"`
15+
WorkspaceTool string `json:"workspaceTool"`
1516
}
1617

1718
func (w workspaceCommonRequest) getToolRepo() string {
18-
if w.WorkspaceToolRepo != "" {
19-
return w.WorkspaceToolRepo
19+
if w.WorkspaceTool != "" {
20+
return w.WorkspaceTool
2021
}
2122
return "github.com/gptscript-ai/workspace-provider"
2223
}
2324

2425
type createWorkspaceRequest struct {
2526
workspaceCommonRequest `json:",inline"`
26-
ProviderType string `json:"providerType"`
27+
ProviderType string `json:"providerType"`
28+
DirectoryDataHome string `json:"directoryDataHome"`
29+
FromWorkspaceIDs []string `json:"fromWorkspaceIDs"`
2730
}
2831

2932
func (s *server) createWorkspace(w http.ResponseWriter, r *http.Request) {
@@ -49,8 +52,8 @@ func (s *server) createWorkspace(w http.ResponseWriter, r *http.Request) {
4952
prg,
5053
s.gptscriptOpts.Env,
5154
fmt.Sprintf(
52-
`{"provider": "%s"}`,
53-
reqObject.ProviderType,
55+
`{"provider": "%s", "data_home": "%s", "workspace_ids": "%s"}`,
56+
reqObject.ProviderType, reqObject.DirectoryDataHome, strings.Join(reqObject.FromWorkspaceIDs, ","),
5457
),
5558
)
5659
if err != nil {

0 commit comments

Comments
 (0)