@@ -91,28 +91,31 @@ async function switchModel(context) {
9191
9292 const provider = minimalModelManager . providers [ selected . value ] ;
9393
94- // Force auto -detection for local providers
94+ // Auto -detection for local HTTP providers (only if not configured)
9595 if ( provider . type === 'local' && provider . httpConfig ) {
96- await vscode . window . withProgress ( {
97- location : vscode . ProgressLocation . Notification ,
98- title : `Detecting ${ provider . name } ...` ,
99- cancellable : false
100- } , async ( ) => {
101- // Clear existing config to force re-detection
102- delete updatedContext . apiKeys [ selected . value ] ;
103-
104- // Run auto-detection
105- const detected = await autoDetectLocalProvider ( selected . value , minimalModelManager . providers ) ;
106- if ( detected ) {
107- updatedContext . apiKeys [ selected . value ] = detected ;
108- fileManager . saveApiKey ( selected . value , detected , minimalModelManager . providers ) ;
109- updateStatusBar ( ) ;
110- vscode . window . showInformationMessage ( `${ provider . name } detected: ${ detected . split ( '|' ) [ 0 ] } ` ) ;
111- } else {
112- updateStatusBar ( ) ;
113- vscode . window . showWarningMessage ( `$(warning) ${ provider . name } not found...` ) ;
114- }
115- } ) ;
96+ // Skip auto-detection if already configured
97+ if ( updatedContext . apiKeys [ selected . value ] ) {
98+ updateStatusBar ( ) ;
99+ vscode . window . showInformationMessage ( t ( 'messages.modelSwitched' , provider . name ) ) ;
100+ } else {
101+ // Run auto-detection only if not configured
102+ await vscode . window . withProgress ( {
103+ location : vscode . ProgressLocation . Notification ,
104+ title : t ( 'messages.operationAlreadyRunning' ) ,
105+ cancellable : false
106+ } , async ( ) => {
107+ const detected = await autoDetectLocalProvider ( selected . value , minimalModelManager . providers ) ;
108+ if ( detected ) {
109+ updatedContext . apiKeys [ selected . value ] = detected ;
110+ fileManager . saveApiKey ( selected . value , detected , minimalModelManager . providers ) ;
111+ updateStatusBar ( ) ;
112+ vscode . window . showInformationMessage ( t ( 'messages.apiKeySaved' , provider . name ) ) ;
113+ } else {
114+ updateStatusBar ( ) ;
115+ vscode . window . showWarningMessage ( t ( 'messages.noPath' , provider . name ) ) ;
116+ }
117+ } ) ;
118+ }
116119
117120 } else {
118121 // All non-HTTP local providers: Process providers + Remote providers
@@ -197,19 +200,22 @@ async function validateApiConnection(context) {
197200 * Auto-detect local HTTP provider
198201 * @param {string } modelId - Model identifier
199202 * @param {Object } providers - Provider configurations
203+ * @param {string|null } manualUrl - Optional manual URL to test (instead of autoDetectUrls)
200204 * @returns {Promise<string|null> } Detected URL or null
201205 */
202- async function autoDetectLocalProvider ( modelId , providers ) {
206+ async function autoDetectLocalProvider ( modelId , providers , manualUrl = null ) {
203207 const provider = providers [ modelId ] ;
204- if ( ! provider ?. autoDetectUrls ) {
208+ if ( ! provider ?. autoDetectUrls && ! manualUrl ) {
205209 return null ;
206210 }
207211
208- // Hole den passenden HTTP Provider Handler
209212 const localProviders = require ( '../localProviders' ) ;
210213 const providerHandler = localProviders . getHttpProvider ( provider . name ) ;
211214
212- for ( const url of provider . autoDetectUrls ) {
215+ // If manual URL provided, test only that one
216+ const urlsToTest = manualUrl ? [ manualUrl ] : provider . autoDetectUrls ;
217+
218+ for ( const url of urlsToTest ) {
213219 if ( await testHttpProvider ( url , provider ) ) {
214220 if ( providerHandler && providerHandler . detectBestModel ) {
215221 const bestModel = await providerHandler . detectBestModel (
@@ -219,7 +225,6 @@ async function autoDetectLocalProvider(modelId, providers) {
219225 ) ;
220226 return `${ url } |${ bestModel || provider . fallback } ` ;
221227 }
222- // Andere Provider (Process-basierte): nur URL zurückgeben
223228 return url ;
224229 }
225230 }
@@ -241,5 +246,6 @@ module.exports = {
241246 callAI,
242247 switchModel,
243248 setApiKey,
244- validateApiConnection
249+ validateApiConnection,
250+ autoDetectLocalProvider
245251} ;
0 commit comments