@@ -9,6 +9,7 @@ import { getConfigEnvValue, getLowerCaseProcessEnvValue, pickEnvVars } from '../
99import { NetworkConfig , ImageBuildConfig } from './squid-service' ;
1010import { applyHostPathPrefixToVolumes } from './host-path-prefix' ;
1111import { buildContainerSecurityHardening } from './service-security' ;
12+ import { OPENAI_ENV , ANTHROPIC_ENV , GEMINI_ENV , COPILOT_ENV } from '../api-proxy-env-constants' ;
1213
1314interface ApiProxyServiceConfigParams {
1415 config : WrapperConfig ;
@@ -22,17 +23,17 @@ interface ApiProxyServiceConfigParams {
2223 * Centralizes the repetitive per-provider target/basePath conditional env generation.
2324 */
2425function buildProviderTargetEnv ( config : WrapperConfig ) : Record < string , string > {
25- const copilotProviderType = config . copilotProviderType || getConfigEnvValue ( config , 'COPILOT_PROVIDER_TYPE' ) ;
26- const copilotProviderBaseUrl = config . copilotProviderBaseUrl || getConfigEnvValue ( config , 'COPILOT_PROVIDER_BASE_URL' ) ;
26+ const copilotProviderType = config . copilotProviderType || getConfigEnvValue ( config , COPILOT_ENV . PROVIDER_TYPE ) ;
27+ const copilotProviderBaseUrl = config . copilotProviderBaseUrl || getConfigEnvValue ( config , COPILOT_ENV . PROVIDER_BASE_URL ) ;
2728 const copilotProviderApiKey = config . copilotProviderApiKey ;
2829
2930 const env : Record < string , string > = { } ;
3031
3132 const providers : Array < { target ?: string ; basePath ?: string ; envTarget : string ; envBasePath : string ; stripTarget ?: boolean } > = [
32- { target : config . copilotApiTarget , basePath : config . copilotApiBasePath , envTarget : 'COPILOT_API_TARGET' , envBasePath : 'COPILOT_API_BASE_PATH' , stripTarget : true } ,
33- { target : config . openaiApiTarget , basePath : config . openaiApiBasePath , envTarget : 'OPENAI_API_TARGET' , envBasePath : 'OPENAI_API_BASE_PATH' , stripTarget : true } ,
34- { target : config . anthropicApiTarget , basePath : config . anthropicApiBasePath , envTarget : 'ANTHROPIC_API_TARGET' , envBasePath : 'ANTHROPIC_API_BASE_PATH' , stripTarget : true } ,
35- { target : config . geminiApiTarget , basePath : config . geminiApiBasePath , envTarget : 'GEMINI_API_TARGET' , envBasePath : 'GEMINI_API_BASE_PATH' , stripTarget : true } ,
33+ { target : config . copilotApiTarget , basePath : config . copilotApiBasePath , envTarget : COPILOT_ENV . API_TARGET , envBasePath : COPILOT_ENV . API_BASE_PATH , stripTarget : true } ,
34+ { target : config . openaiApiTarget , basePath : config . openaiApiBasePath , envTarget : OPENAI_ENV . TARGET , envBasePath : OPENAI_ENV . BASE_PATH , stripTarget : true } ,
35+ { target : config . anthropicApiTarget , basePath : config . anthropicApiBasePath , envTarget : ANTHROPIC_ENV . TARGET , envBasePath : ANTHROPIC_ENV . BASE_PATH , stripTarget : true } ,
36+ { target : config . geminiApiTarget , basePath : config . geminiApiBasePath , envTarget : GEMINI_ENV . TARGET , envBasePath : GEMINI_ENV . BASE_PATH , stripTarget : true } ,
3637 ] ;
3738
3839 for ( const { target, basePath, envTarget, envBasePath, stripTarget } of providers ) {
@@ -41,9 +42,9 @@ function buildProviderTargetEnv(config: WrapperConfig): Record<string, string> {
4142 }
4243
4344 // Copilot-specific provider passthrough
44- if ( copilotProviderType ) env . COPILOT_PROVIDER_TYPE = copilotProviderType ;
45- if ( copilotProviderBaseUrl ) env . COPILOT_PROVIDER_BASE_URL = copilotProviderBaseUrl ;
46- if ( copilotProviderApiKey ) env . COPILOT_PROVIDER_API_KEY = copilotProviderApiKey ;
45+ if ( copilotProviderType ) env [ COPILOT_ENV . PROVIDER_TYPE ] = copilotProviderType ;
46+ if ( copilotProviderBaseUrl ) env [ COPILOT_ENV . PROVIDER_BASE_URL ] = copilotProviderBaseUrl ;
47+ if ( copilotProviderApiKey ) env [ COPILOT_ENV . PROVIDER_API_KEY ] = copilotProviderApiKey ;
4748
4849 // Pre-startup model validation (non-sensitive config value).
4950 // Prefer explicit requestedModel, but fall back to COPILOT_MODEL when present so
@@ -101,10 +102,10 @@ export function buildApiProxyServiceConfig(params: ApiProxyServiceConfigParams):
101102 ) ,
102103 environment : {
103104 // Pass API keys securely to sidecar (not visible to agent)
104- ...( config . openaiApiKey && { OPENAI_API_KEY : config . openaiApiKey } ) ,
105- ...( config . anthropicApiKey && { ANTHROPIC_API_KEY : config . anthropicApiKey } ) ,
106- ...( config . copilotGithubToken && { COPILOT_GITHUB_TOKEN : config . copilotGithubToken } ) ,
107- ...( config . geminiApiKey && { GEMINI_API_KEY : config . geminiApiKey } ) ,
105+ ...( config . openaiApiKey && { [ OPENAI_ENV . KEY ] : config . openaiApiKey } ) ,
106+ ...( config . anthropicApiKey && { [ ANTHROPIC_ENV . KEY ] : config . anthropicApiKey } ) ,
107+ ...( config . copilotGithubToken && { [ COPILOT_ENV . GITHUB_TOKEN ] : config . copilotGithubToken } ) ,
108+ ...( config . geminiApiKey && { [ GEMINI_ENV . KEY ] : config . geminiApiKey } ) ,
108109 // Configurable API targets (for GHES/GHEC / custom endpoints)
109110 // Strip any scheme prefix — server.js also normalizes defensively, but
110111 // stripping here prevents a scheme-prefixed hostname from reaching the
@@ -259,8 +260,8 @@ export function buildApiProxyServiceConfig(params: ApiProxyServiceConfigParams):
259260 'AWF_ANTHROPIC_STRIP_ANSI' ,
260261 ) ,
261262 // Custom auth header names for internal AI gateways
262- ...( config . openaiApiAuthHeader && { AWF_OPENAI_AUTH_HEADER : config . openaiApiAuthHeader } ) ,
263- ...( config . anthropicApiAuthHeader && { AWF_ANTHROPIC_AUTH_HEADER : config . anthropicApiAuthHeader } ) ,
263+ ...( config . openaiApiAuthHeader && { [ OPENAI_ENV . AUTH_HEADER ] : config . openaiApiAuthHeader } ) ,
264+ ...( config . anthropicApiAuthHeader && { [ ANTHROPIC_ENV . AUTH_HEADER ] : config . anthropicApiAuthHeader } ) ,
264265 ...( config . anthropicTokenUrl && { AWF_AUTH_ANTHROPIC_TOKEN_URL : config . anthropicTokenUrl } ) ,
265266 // NOTE: AWF_ANTHROPIC_TRANSFORM_FILE is intentionally NOT forwarded from the host.
266267 // The api-proxy container holds live API credentials; loading arbitrary host-side JS
0 commit comments