chore: sync connectai
This commit is contained in:
+31
-14
@@ -4,6 +4,11 @@ import {
|
||||
getConfig,
|
||||
_getBrainDir,
|
||||
findBrainFiles,
|
||||
buildApiUrl,
|
||||
logError,
|
||||
logInfo,
|
||||
resolveEngine,
|
||||
summarizeText
|
||||
} from './utils';
|
||||
import { AgentExecutor } from './agent';
|
||||
import { BridgeInterface } from './bridge';
|
||||
@@ -228,6 +233,7 @@ export class SidebarChatProvider implements vscode.WebviewViewProvider, BridgeIn
|
||||
visionContent: files // Agent seems to handle files via visionContent
|
||||
});
|
||||
} catch (error: any) {
|
||||
logError('Prompt handling failed in sidebar provider.', { error: error?.message || String(error), promptPreview: summarizeText(value || '', 200) });
|
||||
this._view.webview.postMessage({ type: 'error', value: error.message });
|
||||
}
|
||||
}
|
||||
@@ -240,22 +246,32 @@ export class SidebarChatProvider implements vscode.WebviewViewProvider, BridgeIn
|
||||
let defaultModel = config.defaultModel;
|
||||
let models: string[] = [];
|
||||
|
||||
if (url.includes('1234') || url.includes('v1')) {
|
||||
const primaryEngine = resolveEngine(url);
|
||||
const engines = primaryEngine === 'lmstudio' ? ['lmstudio', 'ollama'] as const : ['ollama', 'lmstudio'] as const;
|
||||
|
||||
for (const engine of engines) {
|
||||
const modelsUrl = buildApiUrl(url, engine, 'models');
|
||||
try {
|
||||
const res = await fetch(`${url}/v1/models`, { signal: AbortSignal.timeout(5000) });
|
||||
if (res.ok) {
|
||||
const data = await res.json() as any;
|
||||
models = data.data.map((m: any) => m.id);
|
||||
logInfo('Model discovery started.', { engine, modelsUrl });
|
||||
const res = await fetch(modelsUrl, { signal: AbortSignal.timeout(5000) });
|
||||
const rawText = await res.text();
|
||||
if (!res.ok) {
|
||||
logError('Model discovery returned non-OK status.', { engine, modelsUrl, status: res.status, body: summarizeText(rawText, 300) });
|
||||
continue;
|
||||
}
|
||||
} catch (e) { console.error("[G1] LM Studio models fetch failed:", e); }
|
||||
} else {
|
||||
try {
|
||||
const res = await fetch(`${url}/api/tags`, { signal: AbortSignal.timeout(5000) });
|
||||
if (res.ok) {
|
||||
const data = await res.json() as any;
|
||||
models = data.models.map((m: any) => m.name);
|
||||
|
||||
const data = rawText ? JSON.parse(rawText) as any : {};
|
||||
models = engine === 'lmstudio'
|
||||
? (data.data || []).map((m: any) => m.id)
|
||||
: (data.models || []).map((m: any) => m.name);
|
||||
|
||||
if (models.length > 0) {
|
||||
logInfo('Model discovery succeeded.', { engine, count: models.length, modelsPreview: models.slice(0, 5) });
|
||||
break;
|
||||
}
|
||||
} catch (e) { console.error("[G1] Ollama models fetch failed:", e); }
|
||||
} catch (e: any) {
|
||||
logError('Model discovery failed.', { engine, modelsUrl, error: e?.message || String(e) });
|
||||
}
|
||||
}
|
||||
|
||||
if (models.length === 0) {
|
||||
@@ -278,6 +294,7 @@ export class SidebarChatProvider implements vscode.WebviewViewProvider, BridgeIn
|
||||
|
||||
this._view.webview.postMessage({ type: 'modelsList', value: models });
|
||||
} catch (err) {
|
||||
logError('Model list update failed.', err);
|
||||
this._view.webview.postMessage({ type: 'modelsList', value: [getConfig().defaultModel] });
|
||||
}
|
||||
}
|
||||
@@ -513,7 +530,7 @@ window.addEventListener('message',e=>{const msg=e.data;switch(msg.type){
|
||||
case 'restoreHistory':
|
||||
chat.innerHTML='';
|
||||
document.body.classList.remove('init');
|
||||
msg.value.forEach(m => addMsg(m.content, m.role === 'assistant' ? 'ai' : 'user'));
|
||||
msg.value.filter(m => !m.internal).forEach(m => addMsg(m.content, m.role === 'assistant' ? 'ai' : 'user'));
|
||||
break;
|
||||
case 'sessionList':
|
||||
historyList.innerHTML='';
|
||||
|
||||
Reference in New Issue
Block a user