Skip to content

Commit 87863a7

Browse files
chore: handle workspace ids from sdk natively
1 parent 3661044 commit 87863a7

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

pkg/engine/http.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ func (e *Engine) runHTTP(ctx context.Context, prg *types.Program, tool types.Too
7575
return nil, err
7676
}
7777

78+
for _, env := range e.Env {
79+
if strings.HasPrefix(env, "GPTSCRIPT_") {
80+
req.Header.Add("X-GPTScript-Env", env)
81+
}
82+
}
83+
7884
req.Header.Set("X-GPTScript-Tool-Name", tool.Parameters.Name)
7985

8086
if err := json.Unmarshal([]byte(input), &map[string]any{}); err == nil {

pkg/gptscript/gptscript.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,20 @@ func New(ctx context.Context, o ...Options) (*GPTScript, error) {
168168
}
169169

170170
func (g *GPTScript) getEnv(env []string) ([]string, error) {
171+
var (
172+
id string
173+
)
174+
175+
scheme, rest, isScheme := strings.Cut(g.WorkspacePath, "://")
176+
if isScheme && scheme == "directory" {
177+
id = g.WorkspacePath
178+
g.WorkspacePath = rest
179+
} else if isScheme {
180+
id = g.WorkspacePath
181+
g.WorkspacePath = ""
182+
g.DeleteWorkspaceOnClose = true
183+
}
184+
171185
if g.WorkspacePath == "" {
172186
var err error
173187
g.WorkspacePath, err = os.MkdirTemp("", "gptscript-workspace-*")
@@ -184,9 +198,12 @@ func (g *GPTScript) getEnv(env []string) ([]string, error) {
184198
if err := os.MkdirAll(g.WorkspacePath, 0700); err != nil {
185199
return nil, err
186200
}
201+
if id == "" {
202+
id = hash.ID(g.WorkspacePath)
203+
}
187204
return slices.Concat(g.ExtraEnv, env, []string{
188205
fmt.Sprintf("GPTSCRIPT_WORKSPACE_DIR=%s", g.WorkspacePath),
189-
fmt.Sprintf("GPTSCRIPT_WORKSPACE_ID=%s", hash.ID(g.WorkspacePath)),
206+
fmt.Sprintf("GPTSCRIPT_WORKSPACE_ID=%s", id),
190207
}), nil
191208
}
192209

0 commit comments

Comments
 (0)