Optimize chat rendering & add web session activity tracking (#214)
* feat: add chat virtualization and turn grouping infrastructure Implement VirtualMessageList with virtualization and overscan for smooth scrolling Refactor MessageList to render only visible messages and pass scroll refs Introduce TurnGroupingContext and provider to stabilize per-turn rendering and reduce re-renders * feat: add web server session activity endpoint for visibility restore Add /api/session-activity endpoint to expose tracked session activity Use web server activity first when restoring visibility, with fallback to global status Update server SSE to set session phase on activity events * feat(chat): split TurnGroupingContext into UI/Streaming contexts Add separate UI state and streaming contexts to reduce re-renders. Skip animations for items visible in collapsed view when expanding. Track shown parts in collapsed mode to fade in progressively * feat(ui): cache turn groups with expand state and guard web activity Add isExpanded to the turn cache key to trigger updates correctly Expose isGroupExpanded from UI state so groups reflect expand/collapse Limit web server session activity fetch to web runtime only
This commit is contained in:
committed by
GitHub
parent
adbc5af95f
commit
f34027df10
@@ -1193,6 +1193,61 @@ const isAnyUiVisible = () => globalVisibilityState === true;
|
||||
|
||||
const isUiVisible = (token) => uiVisibilityByToken.get(token)?.visible === true;
|
||||
|
||||
// Session activity tracking (mirrors desktop session_activity.rs)
|
||||
const sessionActivityPhases = new Map(); // sessionId -> { phase: 'idle'|'busy'|'cooldown', updatedAt: number }
|
||||
const sessionActivityCooldowns = new Map(); // sessionId -> timeoutId
|
||||
const SESSION_COOLDOWN_DURATION_MS = 2000;
|
||||
|
||||
const setSessionActivityPhase = (sessionId, phase) => {
|
||||
if (!sessionId || typeof sessionId !== 'string') return;
|
||||
|
||||
// Cancel existing cooldown timer
|
||||
const existingTimer = sessionActivityCooldowns.get(sessionId);
|
||||
if (existingTimer) {
|
||||
clearTimeout(existingTimer);
|
||||
sessionActivityCooldowns.delete(sessionId);
|
||||
}
|
||||
|
||||
const current = sessionActivityPhases.get(sessionId);
|
||||
if (current?.phase === phase) return; // No change
|
||||
|
||||
sessionActivityPhases.set(sessionId, { phase, updatedAt: Date.now() });
|
||||
|
||||
// Schedule transition from cooldown to idle
|
||||
if (phase === 'cooldown') {
|
||||
const timer = setTimeout(() => {
|
||||
const now = sessionActivityPhases.get(sessionId);
|
||||
if (now?.phase === 'cooldown') {
|
||||
sessionActivityPhases.set(sessionId, { phase: 'idle', updatedAt: Date.now() });
|
||||
}
|
||||
sessionActivityCooldowns.delete(sessionId);
|
||||
}, SESSION_COOLDOWN_DURATION_MS);
|
||||
sessionActivityCooldowns.set(sessionId, timer);
|
||||
}
|
||||
};
|
||||
|
||||
const getSessionActivitySnapshot = () => {
|
||||
const result = {};
|
||||
for (const [sessionId, data] of sessionActivityPhases) {
|
||||
result[sessionId] = { type: data.phase };
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const resetAllSessionActivityToIdle = () => {
|
||||
// Cancel all cooldown timers
|
||||
for (const timer of sessionActivityCooldowns.values()) {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
sessionActivityCooldowns.clear();
|
||||
|
||||
// Reset all phases to idle
|
||||
const now = Date.now();
|
||||
for (const [sessionId] of sessionActivityPhases) {
|
||||
sessionActivityPhases.set(sessionId, { phase: 'idle', updatedAt: now });
|
||||
}
|
||||
};
|
||||
|
||||
const resolveVapidSubject = async () => {
|
||||
const configured = process.env.OPENCHAMBER_VAPID_SUBJECT;
|
||||
if (typeof configured === 'string' && configured.trim().length > 0) {
|
||||
@@ -2691,6 +2746,12 @@ async function main(options = {}) {
|
||||
});
|
||||
});
|
||||
|
||||
// Session activity status endpoint - returns tracked activity phases for all sessions
|
||||
// Used by UI on visibility restore to get accurate status without waiting for SSE
|
||||
app.get('/api/session-activity', (_req, res) => {
|
||||
res.json(getSessionActivitySnapshot());
|
||||
});
|
||||
|
||||
app.get('/api/openchamber/update-check', async (_req, res) => {
|
||||
try {
|
||||
const { checkForUpdates } = await import('./lib/package-manager.js');
|
||||
@@ -2912,6 +2973,7 @@ async function main(options = {}) {
|
||||
void maybeSendPushForTrigger(payload);
|
||||
const activity = deriveSessionActivity(payload);
|
||||
if (activity) {
|
||||
setSessionActivityPhase(activity.sessionId, activity.phase);
|
||||
writeSseEvent(res, {
|
||||
type: 'openchamber:session-activity',
|
||||
properties: {
|
||||
@@ -3032,6 +3094,7 @@ async function main(options = {}) {
|
||||
void maybeSendPushForTrigger(payload);
|
||||
const activity = deriveSessionActivity(payload);
|
||||
if (activity) {
|
||||
setSessionActivityPhase(activity.sessionId, activity.phase);
|
||||
writeSseEvent(res, {
|
||||
type: 'openchamber:session-activity',
|
||||
properties: {
|
||||
|
||||
Reference in New Issue
Block a user