Update Astra: v2.80.19 - Refactoring Sidebar, LM Studio integration, and new tests
This commit is contained in:
+63
-9
@@ -2,14 +2,15 @@ import * as vscode from 'vscode';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
// axios removed in favor of native fetch
|
||||
import {
|
||||
_getBrainDir,
|
||||
import {
|
||||
_getBrainDir,
|
||||
_isBrainDirExplicitlySet,
|
||||
findBrainFiles,
|
||||
SYSTEM_PROMPT,
|
||||
buildApiUrl,
|
||||
logError,
|
||||
logInfo
|
||||
logInfo,
|
||||
resolveEngine
|
||||
} from './utils';
|
||||
import { getConfig, validateConfig } from './config';
|
||||
import { AgentExecutor } from './agent';
|
||||
@@ -17,6 +18,11 @@ import { BridgeServer } from './bridge';
|
||||
import { SidebarChatProvider } from './sidebarProvider';
|
||||
import { HealthCheckMonitor } from './core/health';
|
||||
import { initAstraPathResolver } from './core/astraPath';
|
||||
import { LMStudioClient } from './lmstudio/client';
|
||||
import { ActivityTracker } from './lmstudio/activityTracker';
|
||||
import { ModelLifecycleManager } from './lmstudio/lifecycleManager';
|
||||
|
||||
let _lifecycleManager: ModelLifecycleManager | undefined;
|
||||
|
||||
/**
|
||||
* Astra Extension Entry Point
|
||||
@@ -40,12 +46,52 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
|
||||
// 1. Ensure Brain Directory
|
||||
await _ensureBrainDir(context);
|
||||
|
||||
// 2. Initialize Agent Executor
|
||||
const agent = new AgentExecutor(context);
|
||||
|
||||
// 3. Initialize Sidebar Provider
|
||||
const provider = new SidebarChatProvider(context.extensionUri, context, agent);
|
||||
// 2. Initialize LM Studio Lifecycle Subsystem
|
||||
let provider: SidebarChatProvider | undefined;
|
||||
const initialUrl = getConfig().ollamaUrl;
|
||||
const activityTracker = new ActivityTracker();
|
||||
const lmStudioClient = new LMStudioClient(initialUrl);
|
||||
const lifecycle = new ModelLifecycleManager({
|
||||
client: lmStudioClient,
|
||||
activity: activityTracker,
|
||||
getConfig: () => {
|
||||
const cfg = vscode.workspace.getConfiguration('g1nation');
|
||||
return {
|
||||
idleTimeoutMs: cfg.get<number>('lmStudio.idleTimeoutMs', 300000),
|
||||
autoLoadOnSelect: cfg.get<boolean>('lmStudio.autoLoadOnSelect', true),
|
||||
};
|
||||
},
|
||||
notifyError: (msg) => provider?.postLmStudioError(msg),
|
||||
initialEngine: resolveEngine(initialUrl),
|
||||
});
|
||||
_lifecycleManager = lifecycle;
|
||||
context.subscriptions.push({ dispose: () => activityTracker.dispose() });
|
||||
context.subscriptions.push({ dispose: () => lifecycle.dispose() });
|
||||
|
||||
// React to engine URL changes — re-target the SDK and reset state.
|
||||
context.subscriptions.push(
|
||||
vscode.workspace.onDidChangeConfiguration((e) => {
|
||||
if (!e.affectsConfiguration('g1nation.ollamaUrl')) return;
|
||||
const newUrl = vscode.workspace.getConfiguration('g1nation').get<string>('ollamaUrl', '');
|
||||
lmStudioClient.setBaseUrl(newUrl);
|
||||
lifecycle.setEngine(resolveEngine(newUrl));
|
||||
})
|
||||
);
|
||||
|
||||
// 3. Initialize Agent Executor (with stream lifecycle hooks)
|
||||
const agent = new AgentExecutor(context, {
|
||||
onStreamLifecycle: {
|
||||
start: () => lifecycle.onStreamStart(),
|
||||
end: () => lifecycle.onStreamEnd(),
|
||||
},
|
||||
});
|
||||
|
||||
// 4. Initialize Sidebar Provider
|
||||
provider = new SidebarChatProvider(context.extensionUri, context, agent, {
|
||||
lifecycle,
|
||||
activity: activityTracker,
|
||||
});
|
||||
context.subscriptions.push(
|
||||
vscode.window.registerWebviewViewProvider(SidebarChatProvider.viewType, provider)
|
||||
);
|
||||
@@ -85,8 +131,16 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
}
|
||||
}
|
||||
|
||||
export function deactivate() {
|
||||
export async function deactivate() {
|
||||
HealthCheckMonitor.dispose();
|
||||
if (_lifecycleManager) {
|
||||
try {
|
||||
await _lifecycleManager.disposeAndUnload(2000);
|
||||
} catch (e) {
|
||||
logError('Lifecycle dispose during deactivate failed.', e);
|
||||
}
|
||||
_lifecycleManager = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
async function runInitialSetup(context: vscode.ExtensionContext) {
|
||||
|
||||
Reference in New Issue
Block a user