Skip to content

Commit

Permalink
fix: add ability to create workspaces from other workspaces (#877)
Browse files Browse the repository at this point in the history
Signed-off-by: Donnie Adams <[email protected]>
  • Loading branch information
thedadams authored Oct 16, 2024
1 parent 0927125 commit 419ccbb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/engine/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func appendInputAsEnv(env []string, input string) []string {

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

if err := json.Unmarshal([]byte(input), &data); err != nil {
if err := dec.Decode(&data); err != nil {
// ignore invalid JSON
return newEnv
}
Expand Down
17 changes: 10 additions & 7 deletions pkg/sdkserver/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@ import (
"encoding/json"
"fmt"
"net/http"
"strings"

gcontext "github.com/gptscript-ai/gptscript/pkg/context"
"github.com/gptscript-ai/gptscript/pkg/loader"
)

type workspaceCommonRequest struct {
ID string `json:"id"`
WorkspaceToolRepo string `json:"workspaceToolRepo"`
ID string `json:"id"`
WorkspaceTool string `json:"workspaceTool"`
}

func (w workspaceCommonRequest) getToolRepo() string {
if w.WorkspaceToolRepo != "" {
return w.WorkspaceToolRepo
if w.WorkspaceTool != "" {
return w.WorkspaceTool
}
return "github.com/gptscript-ai/workspace-provider"
}

type createWorkspaceRequest struct {
workspaceCommonRequest `json:",inline"`
ProviderType string `json:"providerType"`
ProviderType string `json:"providerType"`
DirectoryDataHome string `json:"directoryDataHome"`
FromWorkspaceIDs []string `json:"fromWorkspaceIDs"`
}

func (s *server) createWorkspace(w http.ResponseWriter, r *http.Request) {
Expand All @@ -49,8 +52,8 @@ func (s *server) createWorkspace(w http.ResponseWriter, r *http.Request) {
prg,
s.gptscriptOpts.Env,
fmt.Sprintf(
`{"provider": "%s"}`,
reqObject.ProviderType,
`{"provider": "%s", "data_home": "%s", "workspace_ids": "%s"}`,
reqObject.ProviderType, reqObject.DirectoryDataHome, strings.Join(reqObject.FromWorkspaceIDs, ","),
),
)
if err != nil {
Expand Down

0 comments on commit 419ccbb

Please sign in to comment.