@@ -56,7 +56,6 @@ import {
5656import { aihubmixHeaders } from './integrations/aihubmix.js' ;
5757import type { AgentCliEnvPrefs } from './app-config.js' ;
5858import type { RuntimeAgentDef } from './runtimes/types.js' ;
59- import { resolveModelForAgent } from './runtimes/models.js' ;
6059import { preparePromptFileForAgent , type PreparedPromptFile } from './runtimes/prompt-file.js' ;
6160import { configuredAllowedInternalHosts } from './origin-validation.js' ;
6261import {
@@ -76,7 +75,19 @@ import {
7675 type ProviderTestRequest ,
7776} from '@open-design/contracts/api/connectionTest' ;
7877import { googleGenerateContentUrl } from './integrations/google-models.js' ;
79- import { resolveAmrProfile } from './integrations/vela.js' ;
78+ import { readVelaCredentialRevision , resolveAmrProfile } from './integrations/vela.js' ;
79+ import { amrModelLoadingCache } from './runtimes/amr-model-cache.js' ;
80+ import { buildAmrModelCacheKey } from './runtimes/amr-model-probe.js' ;
81+ import {
82+ fetchVelaPresetModels ,
83+ fetchVelaRemoteModelsWithRetry ,
84+ } from './runtimes/defs/amr.js' ;
85+ import {
86+ getRememberedLiveModels ,
87+ preferFreshLiveModels ,
88+ resolveDefaultModelFromOptions ,
89+ resolveModelForAgent ,
90+ } from './runtimes/models.js' ;
8091
8192export { validateBaseUrl } from '@open-design/contracts/api/connectionTest' ;
8293
@@ -1880,12 +1891,9 @@ function attachAgentStreamHandlers(
18801891 child,
18811892 prompt,
18821893 cwd,
1883- // Same substitution as the chat-run path in server.ts — adapters whose
1884- // CLI rejects the synthetic 'default' (e.g. AMR / vela, which forces
1885- // session/set_model before session/prompt) need the def's first
1886- // concrete fallback id here too, otherwise Test connection deadlocks
1887- // on the same `session/set_model must be called before session/prompt`
1888- // error the chat-run path already handles.
1894+ // Same substitution as the chat-run path in server.ts: omitted models can
1895+ // resolve to a concrete fallback, while an explicit 'default' is preserved
1896+ // so ACP runtimes can use their upstream configured default.
18891897 model : resolveModelForAgent ( def as never , model ?? null , modelEnv , liveModelScope ) ,
18901898 mcpServers : [ ] ,
18911899 send,
@@ -1963,11 +1971,41 @@ async function prepareOpenCodeConnectionTestCwd(tempDir: string): Promise<void>
19631971 }
19641972}
19651973
1974+ async function resolveConnectionTestModelForAgent (
1975+ def : RuntimeAgentDef ,
1976+ requestedModel : string | null ,
1977+ env : NodeJS . ProcessEnv ,
1978+ liveModelScope : string | null ,
1979+ launchPath ?: string | null ,
1980+ ) : Promise < string | null > {
1981+ const resolved = resolveModelForAgent ( def , requestedModel , env , liveModelScope ) ;
1982+ if ( def . id !== 'amr' || resolved !== 'default' || ! launchPath ) return resolved ;
1983+
1984+ try {
1985+ const cacheKey = buildAmrModelCacheKey ( {
1986+ launchPath,
1987+ env,
1988+ credentialRevision : readVelaCredentialRevision ( env ) ,
1989+ } ) ;
1990+ const catalog = await amrModelLoadingCache . get ( cacheKey , {
1991+ fetchPreset : ( ) => fetchVelaPresetModels ( launchPath , env ) ,
1992+ fetchRemote : ( ) => fetchVelaRemoteModelsWithRetry ( launchPath , env ) ,
1993+ } ) ;
1994+ const liveModels = preferFreshLiveModels (
1995+ catalog . models ?? [ ] ,
1996+ getRememberedLiveModels ( def . id , liveModelScope ) ,
1997+ ) ;
1998+ return resolveDefaultModelFromOptions ( liveModels ) ?? resolved ;
1999+ } catch {
2000+ return resolved ;
2001+ }
2002+ }
2003+
19662004async function testAgentConnectionInternal (
19672005 input : AgentConnectionInput ,
19682006) : Promise < ConnectionTestResponse > {
19692007 const start = Date . now ( ) ;
1970- const model =
2008+ let model =
19712009 typeof input . model === 'string' && input . model . trim ( )
19722010 ? input . model . trim ( )
19732011 : 'default' ;
@@ -2221,6 +2259,13 @@ async function testAgentConnectionInternal(
22212259 ...baseEnv ,
22222260 ...( mmdRouteLaunchEnv || { } ) ,
22232261 } , executableResolution ) ;
2262+ model = await resolveConnectionTestModelForAgent (
2263+ def ,
2264+ model ,
2265+ env ,
2266+ liveModelScope ,
2267+ executableResolution . launchPath ,
2268+ ) ?? model ;
22242269 const auth = await probeAgentAuthStatus ( def , executableResolution . launchPath , env ) ;
22252270 if ( auth ?. status === 'missing' ) {
22262271 // Preflight auth probe runs after binary resolution but before the
@@ -2278,7 +2323,7 @@ async function testAgentConnectionInternal(
22782323 child ,
22792324 SMOKE_PROMPT ,
22802325 tempDir ,
2281- input . model ,
2326+ model ,
22822327 env ,
22832328 liveModelScope ,
22842329 sink . send ,
0 commit comments