@@ -126,92 +126,20 @@ import {
126126} from './option-parsers' ;
127127import { processAgentImageOption } from './domain-utils' ;
128128
129- export const program = new Command ( ) ;
130-
131- /**
132- * Resolve the Copilot BYOK key from supported environment variables.
133- * COPILOT_API_KEY takes precedence over COPILOT_PROVIDER_API_KEY.
134- */
135- export function resolveCopilotApiKey (
136- env : Record < string , string | undefined > = process . env
137- ) : string | undefined {
138- return env . COPILOT_API_KEY || env . COPILOT_PROVIDER_API_KEY ;
139- }
140-
141- /**
142- * Derive a Copilot API target hostname from COPILOT_PROVIDER_BASE_URL.
143- * Returns undefined when the value is empty or not a valid URL/host.
144- */
145- export function deriveCopilotApiTargetFromProviderBaseUrl (
146- providerBaseUrl : string | undefined
147- ) : string | undefined {
148- const trimmed = providerBaseUrl ?. trim ( ) ;
149- if ( ! trimmed ) return undefined ;
150-
151- const candidate = trimmed . includes ( '://' )
152- ? trimmed
153- : `https://${ trimmed } ` ;
154-
155- try {
156- return new URL ( candidate ) . hostname || undefined ;
157- } catch {
158- return undefined ;
159- }
160- }
161-
162- /**
163- * Derive a Copilot API base-path prefix from COPILOT_PROVIDER_BASE_URL.
164- * Returns undefined when the value is empty, invalid, or has no path.
165- */
166- export function deriveCopilotApiBasePathFromProviderBaseUrl (
167- providerBaseUrl : string | undefined
168- ) : string | undefined {
169- const trimmed = providerBaseUrl ?. trim ( ) ;
170- if ( ! trimmed ) return undefined ;
171-
172- const candidate = trimmed . includes ( '://' )
173- ? trimmed
174- : `https://${ trimmed } ` ;
129+ import {
130+ resolveCopilotApiKey ,
131+ resolveCopilotApiRouting ,
132+ } from './copilot-api-resolver' ;
175133
176- try {
177- const pathname = new URL ( candidate ) . pathname . replace ( / \/ + $ / , '' ) ;
178- if ( ! pathname || pathname === '/' ) return undefined ;
179- return pathname . startsWith ( '/' ) ? pathname : `/${ pathname } ` ;
180- } catch {
181- return undefined ;
182- }
183- }
134+ // Re-export for backwards compatibility (used by cli.test.ts and other consumers)
135+ export {
136+ resolveCopilotApiKey ,
137+ deriveCopilotApiTargetFromProviderBaseUrl ,
138+ deriveCopilotApiBasePathFromProviderBaseUrl ,
139+ resolveCopilotApiRouting ,
140+ } from './copilot-api-resolver' ;
184141
185- /**
186- * Resolve Copilot target/base-path routing for BYOK provider-style env vars.
187- *
188- * Target precedence:
189- * 1. --copilot-api-target
190- * 2. COPILOT_API_TARGET
191- * 3. Hostname from COPILOT_PROVIDER_BASE_URL
192- *
193- * Base path precedence:
194- * 1. COPILOT_API_BASE_PATH
195- * 2. Pathname from COPILOT_PROVIDER_BASE_URL
196- */
197- export function resolveCopilotApiRouting (
198- options : { copilotApiTarget ?: string } ,
199- env : Record < string , string | undefined > = process . env
200- ) : { copilotApiTarget ? : string ; copilotApiBasePath ? : string } {
201- const providerBaseUrl = env . COPILOT_PROVIDER_BASE_URL ;
202- const copilotApiTargetFromProviderBaseUrl = deriveCopilotApiTargetFromProviderBaseUrl ( providerBaseUrl ) ;
203- const copilotApiBasePathFromProviderBaseUrl = deriveCopilotApiBasePathFromProviderBaseUrl ( providerBaseUrl ) ;
204-
205- return {
206- copilotApiTarget :
207- options . copilotApiTarget ||
208- env . COPILOT_API_TARGET ||
209- copilotApiTargetFromProviderBaseUrl ,
210- copilotApiBasePath :
211- env . COPILOT_API_BASE_PATH ||
212- copilotApiBasePathFromProviderBaseUrl ,
213- } ;
214- }
142+ export const program = new Command ( ) ;
215143
216144// Option group markers used by the custom help formatter to insert section headers.
217145// Each key is the long flag name of the first option in a group.
0 commit comments