@@ -113,18 +113,21 @@ function getGptMajor(modelID: string): number | undefined {
113113 return Number ( match [ 1 ] )
114114}
115115
116- function buildConfigOverlayJSON ( providerID : string ) : string {
116+ function buildConfigOverlayJSON ( providerIDs : string [ ] ) : string {
117117 // Merge into any existing OPENCODE_CONFIG_CONTENT the user provided.
118118 const existingRaw = process . env . OPENCODE_CONFIG_CONTENT
119119 const existing = existingRaw ? safeJsonParse ( existingRaw ) : { }
120120 const overlay = {
121- provider : {
122- [ providerID ] : {
123- options : {
124- useResponsesApi : true ,
121+ provider : Object . fromEntries (
122+ providerIDs . map ( ( providerID ) => [
123+ providerID ,
124+ {
125+ options : {
126+ useResponsesApi : true ,
127+ } ,
125128 } ,
126- } ,
127- } ,
129+ ] ) ,
130+ ) ,
128131 }
129132 return JSON . stringify ( deepMerge ( existing , overlay ) )
130133}
@@ -187,6 +190,9 @@ async function probeModel(input: {
187190async function main ( ) {
188191 const args = parseArgs ( process . argv . slice ( 2 ) )
189192
193+ // IMPORTANT: Provider/Config uses Instance.state caching. Ensure config is set BEFORE importing Provider.
194+ process . env . OPENCODE_CONFIG_CONTENT = buildConfigOverlayJSON ( args . providerIDs )
195+
190196 const { Instance } = await import ( "../src/project/instance" )
191197 const { Provider } = await import ( "../src/provider/provider" )
192198
@@ -198,12 +204,6 @@ async function main() {
198204 directory : process . cwd ( ) ,
199205 async fn ( ) {
200206 for ( const providerID of args . providerIDs ) {
201- // Force the opt-in flag for this provider.
202- process . env . OPENCODE_CONFIG_CONTENT = buildConfigOverlayJSON ( providerID )
203-
204- // Reload provider state by importing after env var is set.
205- // Provider uses Instance.state caching, so the safest approach is to filter the already-loaded
206- // provider models list and just probe calls (routing is decided per-model loader).
207207 const provider = await Provider . getProvider ( providerID )
208208 if ( ! provider ) {
209209 process . stdout . write ( `\n## ${ providerID } \n` )
0 commit comments