Skip to content

feat: allow daemons to request environment variables #945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion pkg/engine/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func (e *Engine) runHTTP(ctx context.Context, prg *types.Program, tool types.Too
return nil, err
}

var requestedEnvVars map[string]struct{}
if strings.HasSuffix(parsed.Hostname(), DaemonURLSuffix) {
referencedToolName := strings.TrimSuffix(parsed.Hostname(), DaemonURLSuffix)
referencedToolRefs, ok := tool.ToolMapping[referencedToolName]
Expand All @@ -60,6 +61,14 @@ func (e *Engine) runHTTP(ctx context.Context, prg *types.Program, tool types.Too
}
parsed.Host = toolURLParsed.Host
toolURL = parsed.String()

metadataEnvVars := strings.Split(referencedTool.MetaData["requestedEnvVars"], ",")
requestedEnvVars = make(map[string]struct{}, len(metadataEnvVars))
for _, e := range metadataEnvVars {
if e != "" {
requestedEnvVars[e] = struct{}{}
}
}
}

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

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