-
Notifications
You must be signed in to change notification settings - Fork 359
Codex: inject openai-proxy provider in generated config when API proxy is enabled
#27711
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
Changes from all commits
d82938b
0323020
fa325a1
4e82cf1
c794dd1
79137c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,13 +2,21 @@ package workflow | |
|
|
||
| import ( | ||
| "fmt" | ||
| "net" | ||
| "strconv" | ||
| "strings" | ||
|
|
||
| "github.com/github/gh-aw/pkg/constants" | ||
| "github.com/github/gh-aw/pkg/logger" | ||
| ) | ||
|
|
||
| var codexMCPLog = logger.New("workflow:codex_mcp") | ||
|
|
||
| const ( | ||
| codexOpenAIProxyProviderID = "openai-proxy" | ||
| codexOpenAIProxyProviderName = "OpenAI AWF proxy" | ||
| ) | ||
|
Comment on lines
+15
to
+18
|
||
|
|
||
| // RenderMCPConfig generates MCP server configuration for Codex | ||
| func (e *CodexEngine) RenderMCPConfig(yaml *strings.Builder, tools map[string]any, mcpTools []string, workflowData *WorkflowData) error { | ||
| if codexMCPLog.Enabled() { | ||
|
|
@@ -118,8 +126,15 @@ func (e *CodexEngine) RenderMCPConfig(yaml *strings.Builder, tools map[string]an | |
| shellPolicyDelimiter := GenerateHeredocDelimiterFromSeed("CODEX_SHELL_POLICY", workflowData.FrontmatterHash) | ||
| yaml.WriteString(" cat > \"/tmp/gh-aw/mcp-config/config.toml\" << " + shellPolicyDelimiter + "\n") | ||
| e.renderShellEnvironmentPolicyToml(yaml, tools, mcpTools, " ") | ||
| if isFirewallEnabled(workflowData) { | ||
| e.renderOpenAIProxyProviderToml(yaml, " ") | ||
| } | ||
| yaml.WriteString(" " + shellPolicyDelimiter + "\n") | ||
| yaml.WriteString(" cat \"${RUNNER_TEMP}/gh-aw/mcp-config/config.toml\" >> \"/tmp/gh-aw/mcp-config/config.toml\"\n") | ||
| if isFirewallEnabled(workflowData) { | ||
| e.renderAppendConvertedConfigWithoutOpenAIProxy(yaml) | ||
| } else { | ||
| yaml.WriteString(" cat \"${RUNNER_TEMP}/gh-aw/mcp-config/config.toml\" >> \"/tmp/gh-aw/mcp-config/config.toml\"\n") | ||
| } | ||
| if workflowData.EngineConfig != nil && strings.TrimSpace(workflowData.EngineConfig.Config) != "" { | ||
| customConfigDelimiter := GenerateHeredocDelimiterFromSeed("CODEX_CUSTOM_CONFIG", workflowData.FrontmatterHash) | ||
| yaml.WriteString(" \n") | ||
|
|
@@ -139,6 +154,31 @@ func (e *CodexEngine) RenderMCPConfig(yaml *strings.Builder, tools map[string]an | |
| return nil | ||
| } | ||
|
|
||
| func (e *CodexEngine) renderOpenAIProxyProviderToml(yaml *strings.Builder, indent string) { | ||
| yaml.WriteString("\n") | ||
| yaml.WriteString(indent + "model_provider = \"" + codexOpenAIProxyProviderID + "\"\n") | ||
| yaml.WriteString("\n") | ||
| yaml.WriteString(indent + "[model_providers." + codexOpenAIProxyProviderID + "]\n") | ||
| yaml.WriteString(indent + "name = \"" + codexOpenAIProxyProviderName + "\"\n") | ||
| yaml.WriteString(indent + "base_url = \"" + e.getOpenAIProxyProviderBaseURL() + "\"\n") | ||
| yaml.WriteString(indent + "env_key = \"OPENAI_API_KEY\"\n") | ||
| yaml.WriteString(indent + "supports_websockets = false\n") | ||
| } | ||
|
|
||
| func (e *CodexEngine) getOpenAIProxyProviderBaseURL() string { | ||
| return "http://" + net.JoinHostPort(constants.AWFAPIProxyContainerIP, strconv.Itoa(constants.ClaudeLLMGatewayPort)) | ||
| } | ||
|
|
||
| func (e *CodexEngine) renderAppendConvertedConfigWithoutOpenAIProxy(yaml *strings.Builder) { | ||
| yaml.WriteString(" awk '\n") | ||
| yaml.WriteString(" BEGIN { skip_openai_proxy = 0 }\n") | ||
| yaml.WriteString(" /^[[:space:]]*model_provider[[:space:]]*=/ { next }\n") | ||
| yaml.WriteString(" /^\\[model_providers\\.openai-proxy\\][[:space:]]*$/ { skip_openai_proxy = 1; next }\n") | ||
| yaml.WriteString(" /^\\[/ { skip_openai_proxy = 0 }\n") | ||
| yaml.WriteString(" !skip_openai_proxy { print }\n") | ||
| yaml.WriteString(" ' \"${RUNNER_TEMP}/gh-aw/mcp-config/config.toml\" >> \"/tmp/gh-aw/mcp-config/config.toml\"\n") | ||
| } | ||
|
|
||
| // renderCodexMCPConfigWithContext generates custom MCP server configuration for a single tool in codex workflow config.toml | ||
| // This version includes workflowData to determine if localhost URLs should be rewritten | ||
| func (e *CodexEngine) renderCodexMCPConfigWithContext(yaml *strings.Builder, toolName string, toolConfig map[string]any, workflowData *WorkflowData) error { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
toolsmap andmcpToolsslice are shared across subtests. IfRenderMCPConfigmutates either (even indirectly), it can create hidden coupling and flaky tests. Instantiate freshtools/mcpToolsinside eacht.Run(or clone them) to keep subtests isolated.