feat: context compaction button in token bar (≥50% usage)
This commit is contained in:
17
src/App.tsx
17
src/App.tsx
@@ -43,6 +43,21 @@ export default function App() {
|
||||
setSplitSession(prev => prev === key ? null : key);
|
||||
}, []);
|
||||
|
||||
const handleCompact = useCallback(async (key: string): Promise<boolean> => {
|
||||
const client = getClient();
|
||||
if (!client) return false;
|
||||
try {
|
||||
const res = await client.send('sessions.compact', { key });
|
||||
// Reload history after compaction to reflect new state
|
||||
if (res?.compacted) {
|
||||
switchSession(key);
|
||||
}
|
||||
return !!res?.compacted;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}, [getClient, switchSession]);
|
||||
|
||||
// Split pane drag
|
||||
useEffect(() => {
|
||||
if (!splitDragging) return;
|
||||
@@ -152,7 +167,7 @@ export default function App() {
|
||||
<div ref={splitContainerRef} className="flex-1 flex min-w-0" aria-hidden={sidebarOpen ? true : undefined}>
|
||||
{/* Primary pane */}
|
||||
<main className="flex flex-col min-w-0" style={splitSession ? { width: `${splitRatio}%` } : { flex: 1 }} aria-label={t('app.mainChat')}>
|
||||
<Header status={status} sessionKey={activeSession} onToggleSidebar={() => setSidebarOpen(!sidebarOpen)} activeSessionData={sessions.find(s => s.key === activeSession)} onLogout={logout} soundEnabled={soundEnabled} onToggleSound={toggleSound} messages={messages} agentAvatarUrl={agentIdentity?.avatar} agentName={agentIdentity?.name} />
|
||||
<Header status={status} sessionKey={activeSession} onToggleSidebar={() => setSidebarOpen(!sidebarOpen)} activeSessionData={sessions.find(s => s.key === activeSession)} onLogout={logout} soundEnabled={soundEnabled} onToggleSound={toggleSound} messages={messages} agentAvatarUrl={agentIdentity?.avatar} agentName={agentIdentity?.name} onCompact={handleCompact} />
|
||||
<ConnectionBanner status={status} />
|
||||
<Suspense fallback={<div className="flex-1 flex items-center justify-center text-pc-text-muted"><div className="animate-pulse text-sm">Loading…</div></div>}>
|
||||
<Chat messages={messages} isGenerating={isGenerating} isLoadingHistory={isLoadingHistory} status={status} sessionKey={activeSession} onSend={sendMessage} onAbort={abort} agentAvatarUrl={agentIdentity?.avatar} />
|
||||
|
||||
Reference in New Issue
Block a user