refactor: optimize core engine and retrieval logic for v2.80.43
This commit is contained in:
+69
-2
@@ -64,6 +64,7 @@ export class SidebarChatProvider implements vscode.WebviewViewProvider, BridgeIn
|
||||
static readonly activeChronicleProjectStateKey = 'g1nation.activeChronicleProjectId';
|
||||
static readonly lastAutoChronicleSignatureStateKey = 'g1nation.lastAutoChronicleSignature';
|
||||
_view?: vscode.WebviewView;
|
||||
_panel?: vscode.WebviewPanel;
|
||||
public brainEnabled = true;
|
||||
_currentSessionBrainId: string | null = null;
|
||||
_currentNegativePrompt: string = '';
|
||||
@@ -93,6 +94,36 @@ export class SidebarChatProvider implements vscode.WebviewViewProvider, BridgeIn
|
||||
context: vscode.WebviewViewResolveContext,
|
||||
_token: vscode.CancellationToken,
|
||||
) {
|
||||
this._initView(webviewView);
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the chat as a standalone editor panel (Column 3 by default).
|
||||
* Reuses the same view-init logic via a WebviewPanel→WebviewView adapter
|
||||
* so the rest of the provider keeps using `this._view` unchanged.
|
||||
*/
|
||||
public openAsPanel(column: vscode.ViewColumn = vscode.ViewColumn.Three): vscode.WebviewPanel {
|
||||
if (this._panel) {
|
||||
this._panel.reveal(column);
|
||||
return this._panel;
|
||||
}
|
||||
const panel = vscode.window.createWebviewPanel(
|
||||
SidebarChatProvider.viewType,
|
||||
'Astra Chat',
|
||||
column,
|
||||
{ enableScripts: true, localResourceRoots: [this._extensionUri], retainContextWhenHidden: true }
|
||||
);
|
||||
this._panel = panel;
|
||||
const adapter = wrapPanelAsView(panel);
|
||||
panel.onDidDispose(() => {
|
||||
if (this._panel === panel) this._panel = undefined;
|
||||
if (this._view === adapter) this._view = undefined;
|
||||
});
|
||||
this._initView(adapter);
|
||||
return panel;
|
||||
}
|
||||
|
||||
private _initView(webviewView: vscode.WebviewView) {
|
||||
this._view = webviewView;
|
||||
|
||||
webviewView.webview.options = {
|
||||
@@ -108,8 +139,8 @@ export class SidebarChatProvider implements vscode.WebviewViewProvider, BridgeIn
|
||||
// 5초 이내에 이미 갱신했으면 건너뜀
|
||||
if (now - _lastVisibilityRefresh < 5000) return;
|
||||
_lastVisibilityRefresh = now;
|
||||
|
||||
logInfo('Sidebar became visible, restoring state...');
|
||||
|
||||
logInfo('Astra view became visible, restoring state...');
|
||||
void this._sendModels();
|
||||
void this._sendBrainProfiles();
|
||||
void this._sendAgentsList();
|
||||
@@ -2043,3 +2074,39 @@ export class SidebarChatProvider implements vscode.WebviewViewProvider, BridgeIn
|
||||
.replace('__SCRIPT_URI__', scriptUri);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapter that makes a {@link vscode.WebviewPanel} quack like a
|
||||
* {@link vscode.WebviewView}, so providers written against the view API can
|
||||
* mount inside an editor column without their internals knowing the difference.
|
||||
*
|
||||
* `onDidChangeVisibility` is synthesized from `onDidChangeViewState` — panels
|
||||
* fire that event for both visibility *and* column moves, but the listener
|
||||
* here only re-fires when the visible flag actually toggles.
|
||||
*/
|
||||
export function wrapPanelAsView(panel: vscode.WebviewPanel): vscode.WebviewView {
|
||||
const visibilityEmitter = new vscode.EventEmitter<void>();
|
||||
let _lastVisible = panel.visible;
|
||||
panel.onDidChangeViewState(() => {
|
||||
if (panel.visible !== _lastVisible) {
|
||||
_lastVisible = panel.visible;
|
||||
visibilityEmitter.fire();
|
||||
}
|
||||
});
|
||||
panel.onDidDispose(() => visibilityEmitter.dispose());
|
||||
const adapter: any = {
|
||||
viewType: panel.viewType,
|
||||
webview: panel.webview,
|
||||
get visible() { return panel.visible; },
|
||||
get title() { return panel.title; },
|
||||
set title(v: string | undefined) { panel.title = v ?? ''; },
|
||||
description: undefined as string | undefined,
|
||||
badge: undefined as vscode.ViewBadge | undefined,
|
||||
onDidChangeVisibility: visibilityEmitter.event,
|
||||
onDidDispose: panel.onDidDispose,
|
||||
show(preserveFocus?: boolean) {
|
||||
panel.reveal(panel.viewColumn ?? vscode.ViewColumn.Three, preserveFocus);
|
||||
},
|
||||
};
|
||||
return adapter as vscode.WebviewView;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user