Skip to content

Commit f28388f

Browse files
committed
Release V2.2.1 with bugfixes and better http provider support
1 parent 41db4ff commit f28388f

3 files changed

Lines changed: 70 additions & 38 deletions

File tree

aiduino/extension/out/utils/apiKeyManager.js

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,29 +63,55 @@ class ApiKeyManager {
6363
}
6464
})
6565

66-
if (input) {
66+
if (input) {
67+
let finalValue = input;
68+
69+
// For HTTP-based local providers: Run model detection
70+
if (provider.type === 'local' && provider.httpConfig) {
71+
let normalizedUrl = input;
72+
73+
// Normalize URL: Add default port if missing
74+
try {
75+
const testUrl = new URL(input);
76+
if (!testUrl.port && provider.defaultPort) {
77+
normalizedUrl = `${testUrl.protocol}//${testUrl.hostname}:${provider.defaultPort}${testUrl.pathname}`;
78+
}
79+
} catch (e) {
80+
// Keep original if URL parsing fails
81+
}
82+
83+
// Use existing autoDetectLocalProvider with manual URL
84+
const apiManager = require('./apiManager');
85+
const detected = await apiManager.autoDetectLocalProvider(currentModel, providers, normalizedUrl);
86+
87+
if (detected) {
88+
finalValue = detected;
89+
} else {
90+
vscode.window.showErrorMessage(`${providerName} ${t('errors.localProviderNotRunning')} (${normalizedUrl})`);
91+
return false;
92+
}
93+
}
94+
6795
// Save API key using fileManager
68-
if (fileManager.saveApiKey(currentModel, input, providers)) {
96+
if (fileManager.saveApiKey(currentModel, finalValue, providers)) {
6997
// Update in-memory API keys
70-
apiKeys[currentModel] = input;
71-
98+
apiKeys[currentModel] = finalValue;
99+
72100
// Update status bar
73101
updateStatusBar();
74-
102+
75103
// Show success message
76-
const successMessage = t('messages.apiKeySaved', providerName) ||
77-
`${providerName} API key saved!`;
104+
const successMessage = t('messages.apiKeySaved', providerName);
78105
vscode.window.showInformationMessage(successMessage);
79-
106+
80107
return true;
81108
} else {
82-
const errorMessage = t('errors.saveFailed', 'File save failed') ||
83-
`Failed to save API key: File save failed`;
109+
const errorMessage = t('errors.saveFailed');
84110
vscode.window.showErrorMessage(errorMessage);
85111
return false;
86112
}
87113
}
88-
114+
89115
return false;
90116

91117
} finally {

aiduino/extension/out/utils/apiManager.js

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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
};

installer/aiduino.vsix

308 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)