Skip to content

Commit bf1b000

Browse files
committed
feat: allow daemons to request environment variables
Daemon tools can now request which environment variables it needs from the calling tool. These environment variables will be sent in the X-GPTScript-Env header. Signed-off-by: Donnie Adams <[email protected]>
1 parent bb6456f commit bf1b000

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pkg/engine/http.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func (e *Engine) runHTTP(ctx context.Context, prg *types.Program, tool types.Too
4040
return nil, err
4141
}
4242

43+
var requestedEnvVars map[string]struct{}
4344
if strings.HasSuffix(parsed.Hostname(), DaemonURLSuffix) {
4445
referencedToolName := strings.TrimSuffix(parsed.Hostname(), DaemonURLSuffix)
4546
referencedToolRefs, ok := tool.ToolMapping[referencedToolName]
@@ -60,6 +61,14 @@ func (e *Engine) runHTTP(ctx context.Context, prg *types.Program, tool types.Too
6061
}
6162
parsed.Host = toolURLParsed.Host
6263
toolURL = parsed.String()
64+
65+
metadataEnvVars := strings.Split(referencedTool.MetaData["requestedEnvVars"], ",")
66+
requestedEnvVars = make(map[string]struct{}, len(metadataEnvVars))
67+
for _, e := range metadataEnvVars {
68+
if e != "" {
69+
requestedEnvVars[e] = struct{}{}
70+
}
71+
}
6372
}
6473

6574
if tool.Blocking {
@@ -78,7 +87,7 @@ func (e *Engine) runHTTP(ctx context.Context, prg *types.Program, tool types.Too
7887
}
7988

8089
for _, k := range slices.Sorted(maps.Keys(envMap)) {
81-
if strings.HasPrefix(k, "GPTSCRIPT_WORKSPACE_") {
90+
if _, ok := requestedEnvVars[k]; ok || strings.HasPrefix(k, "GPTSCRIPT_WORKSPACE_") {
8291
req.Header.Add("X-GPTScript-Env", k+"="+envMap[k])
8392
}
8493
}

0 commit comments

Comments
 (0)