Update Astra: v2.80.19 - Refactoring Sidebar, LM Studio integration, and new tests
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
import * as vscode from 'vscode';
|
||||
import * as path from 'path';
|
||||
import { SidebarChatProvider } from '../sidebarProvider';
|
||||
import { getActiveBrainProfile, logInfo } from '../utils';
|
||||
|
||||
/**
|
||||
* Handles chat-domain messages: prompts, model selection, sessions, streaming control,
|
||||
* generic webview transport (export, settings, addMessage), action approvals, and the
|
||||
* cross-cutting `ready` bootstrap.
|
||||
*
|
||||
* Returns true when the message was handled by this domain, false otherwise — the
|
||||
* caller chains domain handlers until one accepts the message.
|
||||
*/
|
||||
export async function handleChatMessage(provider: SidebarChatProvider, data: any): Promise<boolean> {
|
||||
switch (data.type) {
|
||||
case 'prompt':
|
||||
case 'promptWithFile':
|
||||
provider._lmStudio?.activity.bump();
|
||||
await provider._context.globalState.update(SidebarChatProvider.blankChatStateKey, false);
|
||||
await provider._handlePrompt(data);
|
||||
await provider._autoWriteChronicleAfterPrompt();
|
||||
await provider._saveCurrentSession();
|
||||
return true;
|
||||
case 'activity':
|
||||
provider._lmStudio?.activity.bump();
|
||||
return true;
|
||||
case 'ready':
|
||||
await provider._sendBrainStatus();
|
||||
await provider._sendBrainProfiles();
|
||||
await provider._sendSessionList();
|
||||
await provider._sendModels();
|
||||
await provider._sendChronicleProjects();
|
||||
await provider._restoreActiveSessionIntoView();
|
||||
return true;
|
||||
case 'getModels':
|
||||
await provider._sendModels();
|
||||
return true;
|
||||
case 'getSessions':
|
||||
await provider._sendSessionList();
|
||||
return true;
|
||||
case 'newChat':
|
||||
provider._currentSessionId = null;
|
||||
provider._currentSessionBrainId = getActiveBrainProfile().id;
|
||||
provider._agent.resetConversation();
|
||||
await provider._context.globalState.update(SidebarChatProvider.activeSessionStateKey, null);
|
||||
await provider._context.globalState.update(SidebarChatProvider.lastVisibleChatStateKey, null);
|
||||
await provider._context.globalState.update(SidebarChatProvider.blankChatStateKey, true);
|
||||
provider.clearChat();
|
||||
await provider._sendBrainStatus();
|
||||
return true;
|
||||
case 'stopGeneration':
|
||||
provider._agent.stop();
|
||||
return true;
|
||||
case 'loadSession':
|
||||
await provider._loadSession(data.id);
|
||||
return true;
|
||||
case 'deleteSession':
|
||||
await provider._deleteSession(data.id);
|
||||
return true;
|
||||
case 'openSettings':
|
||||
vscode.commands.executeCommand('workbench.action.openSettings', 'g1nation');
|
||||
return true;
|
||||
case 'addMessage':
|
||||
provider._view?.webview.postMessage({ type: 'addMessage', role: data.role, value: data.value, rationale: data.rationale });
|
||||
return true;
|
||||
case 'refreshModels':
|
||||
await provider._sendModels(true);
|
||||
return true;
|
||||
case 'model':
|
||||
await vscode.workspace.getConfiguration('g1nation').update('defaultModel', data.value, vscode.ConfigurationTarget.Global);
|
||||
logInfo(`Default model updated to: ${data.value}`);
|
||||
provider._lmStudio?.lifecycle.onModelSelected(data.value);
|
||||
return true;
|
||||
case 'proactiveTrigger':
|
||||
await provider._handleProactiveSuggestion(data.context);
|
||||
return true;
|
||||
case 'exportResponse': {
|
||||
const workspacePath = vscode.workspace.workspaceFolders?.[0].uri.fsPath || '';
|
||||
const defaultPath = path.join(workspacePath, 'g1_response.md');
|
||||
const uri = await vscode.window.showSaveDialog({
|
||||
defaultUri: vscode.Uri.file(defaultPath),
|
||||
filters: { 'Markdown': ['md'] }
|
||||
});
|
||||
if (uri) {
|
||||
await vscode.workspace.fs.writeFile(uri, Buffer.from(data.text, 'utf8'));
|
||||
vscode.window.showInformationMessage(`✅ Exported to ${path.basename(uri.fsPath)}`);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case 'approveAction':
|
||||
await provider._agent.approveTransaction();
|
||||
return true;
|
||||
case 'rejectAction':
|
||||
await provider._agent.rejectTransaction();
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user