chore: bump version to v2.33.5 and optimize sidebar UI
This commit is contained in:
+56
-8
@@ -322,7 +322,7 @@ export class SidebarChatProvider implements vscode.WebviewViewProvider, BridgeIn
|
||||
}
|
||||
|
||||
const sessions = this._getSessions();
|
||||
const session = sessions.find(s => s.id === id);
|
||||
const session = sessions.find(s => s.id === id) || this._getSessionById(id);
|
||||
if (session) {
|
||||
const history = Array.isArray(session.history) ? session.history : [];
|
||||
if (history.length === 0) {
|
||||
@@ -409,6 +409,35 @@ export class SidebarChatProvider implements vscode.WebviewViewProvider, BridgeIn
|
||||
.slice(0, 50);
|
||||
}
|
||||
|
||||
private _getSessionById(id: string): ChatSession | null {
|
||||
const rawSessions = this._context.globalState.get<any[]>('chat_sessions', []) || [];
|
||||
const raw = rawSessions.find((session: any) => String(session?.id) === String(id));
|
||||
if (!raw) return null;
|
||||
|
||||
const history = Array.isArray(raw.history)
|
||||
? raw.history.filter((message: any) =>
|
||||
message
|
||||
&& (message.role === 'user' || message.role === 'assistant' || message.role === 'system')
|
||||
&& message.content !== undefined
|
||||
)
|
||||
: [];
|
||||
if (history.length === 0) return null;
|
||||
|
||||
const firstMsg = history.find((message: ChatMessage) => message.role === 'user')?.content;
|
||||
const fallbackTitle = typeof firstMsg === 'string'
|
||||
? firstMsg.substring(0, 50).replace(/\n/g, ' ') + (firstMsg.length > 50 ? '...' : '')
|
||||
: 'Chat Session';
|
||||
|
||||
return {
|
||||
id: String(raw.id),
|
||||
title: String(raw.title || fallbackTitle),
|
||||
timestamp: typeof raw.timestamp === 'number' ? raw.timestamp : Date.now(),
|
||||
history,
|
||||
brainProfileId: String(raw.brainProfileId || getActiveBrainProfile().id),
|
||||
negativePrompt: String(raw.negativePrompt || '')
|
||||
};
|
||||
}
|
||||
|
||||
private async _putSessions(sessions: ChatSession[]) {
|
||||
await this._context.globalState.update('chat_sessions', sessions.slice(0, 50));
|
||||
}
|
||||
@@ -2108,15 +2137,21 @@ export class SidebarChatProvider implements vscode.WebviewViewProvider, BridgeIn
|
||||
break;
|
||||
case 'restoreHistory':
|
||||
case 'sessionLoaded':
|
||||
const historyData = msg.type === 'sessionLoaded' ? msg.value : msg;
|
||||
const history = Array.isArray(historyData.history) ? historyData.history : (Array.isArray(historyData) ? historyData : []);
|
||||
const historyPayload = msg.type === 'sessionLoaded' ? msg.value : msg.value;
|
||||
const history = Array.isArray(historyPayload)
|
||||
? historyPayload
|
||||
: (Array.isArray(historyPayload?.history) ? historyPayload.history : []);
|
||||
|
||||
if (history && history.length > 0) {
|
||||
chat.innerHTML = '';
|
||||
history.forEach(m => addMsg(m.content, m.role === 'assistant' ? 'assistant' : 'user', m.rationale));
|
||||
history.forEach(m => {
|
||||
if (!m || m.internal) return;
|
||||
addMsg(m.content, m.role === 'assistant' ? 'assistant' : 'user', m.rationale);
|
||||
});
|
||||
chat.scrollTop = chat.scrollHeight;
|
||||
}
|
||||
if (historyData.negativePrompt !== undefined) {
|
||||
negativePrompt.value = historyData.negativePrompt;
|
||||
if (historyPayload?.negativePrompt !== undefined) {
|
||||
negativePrompt.value = historyPayload.negativePrompt;
|
||||
}
|
||||
historyOverlay.classList.remove('visible');
|
||||
break;
|
||||
@@ -2163,8 +2198,21 @@ export class SidebarChatProvider implements vscode.WebviewViewProvider, BridgeIn
|
||||
historyList.innerHTML = '';
|
||||
msg.value.forEach(s => {
|
||||
const el = document.createElement('div'); el.className = 'history-item';
|
||||
el.innerHTML = \`<div style="font-weight:600; color:var(--text-bright); mb-2">\${s.title}</div><div style="font-size:10px; color:var(--text-dim)">\${new Date(s.timestamp).toLocaleString()} · \${s.messageCount} msgs</div>\`;
|
||||
el.onclick = () => vscode.postMessage({ type: 'loadSession', id: s.id });
|
||||
el.setAttribute('role', 'button');
|
||||
el.tabIndex = 0;
|
||||
el.dataset.sessionId = s.id;
|
||||
el.innerHTML = \`<div style="font-weight:600; color:var(--text-bright); margin-bottom:2px;">\${s.title}</div><div style="font-size:10px; color:var(--text-dim)">\${new Date(s.timestamp).toLocaleString()} · \${s.messageCount} msgs</div>\`;
|
||||
const load = () => {
|
||||
if (!el.dataset.sessionId) return;
|
||||
vscode.postMessage({ type: 'loadSession', id: el.dataset.sessionId });
|
||||
};
|
||||
el.addEventListener('click', load);
|
||||
el.addEventListener('keydown', event => {
|
||||
if (event.key === 'Enter' || event.key === ' ') {
|
||||
event.preventDefault();
|
||||
load();
|
||||
}
|
||||
});
|
||||
historyList.appendChild(el);
|
||||
});
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user