mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-18 03:27:08 +00:00
* feat(web): sort and filter the session list The session list had one fixed order, the user's last message, and active and archived sessions were interleaved inside each project. With in-progress pinning off by default, a connected session could sit below a stack of archived ones, and archived sessions could not be listed on their own. A sort and filter button in the list toolbar now sets: - Sort by: last message (the existing default), date created, or recent activity including agent output. - Active first (on by default): connected sessions lead each project, and projects with one lead the list. Manual pins still come first. - Show: all sessions, active only, or archived only. The open session stays visible, and archived-only keeps projects expanded instead of auto-collapsing them. Choices persist and stay in sync across consumers and tabs. The Display setting "Show active sessions only" is now the Active status, and an existing true value carries over. via [HAPI](https://hapi.run) Co-Authored-By: HAPI <noreply@hapi.run> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(web): keep the default project order while searching Relevance ranking keeps the incoming project order for equal scores, so passing the list view into grouping let Active first and the chosen sort reorder equally relevant search results. Group with the default last-message order while a text query is active, as before. via [HAPI](https://hapi.run) Co-Authored-By: HAPI <noreply@hapi.run> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(web): drop the Recent activity session sort The Hub advances updatedAt only for human messages; agent output moves an in-memory progress clock that clients never see. Recent activity therefore ordered like Last message. Ordering by user input is the agreed contract across clients (see #1512), so remove the option rather than add a new activity clock. A stored "activity" value falls back to the default. via [HAPI](https://hapi.run) Co-Authored-By: HAPI <noreply@hapi.run> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: HAPI <noreply@hapi.run> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
42 lines
1.7 KiB
TypeScript
42 lines
1.7 KiB
TypeScript
import type { SessionSummary } from '@/types/api'
|
|
import type { SessionListSort, SessionListStatus, SessionListView } from '@/hooks/useSessionListView'
|
|
|
|
type OrderFields = Pick<SessionSummary, 'id' | 'active' | 'createdAt' | 'lastUserMessageAt'>
|
|
|
|
/**
|
|
* - last-message: the user's latest prompt, falling back to creation (the
|
|
* long-standing default, which agent output never reorders).
|
|
* - created: newest sessions first.
|
|
*/
|
|
export function getSessionSortKey(session: OrderFields, sort: SessionListSort): number {
|
|
return sort === 'created'
|
|
? session.createdAt ?? 0
|
|
: session.lastUserMessageAt ?? session.createdAt ?? 0
|
|
}
|
|
|
|
export type SessionComparator = (a: SessionSummary, b: SessionSummary) => number
|
|
|
|
export function createSessionComparator(view: Pick<SessionListView, 'sort' | 'activeFirst'>): SessionComparator {
|
|
return (a, b) => {
|
|
if (view.activeFirst && a.active !== b.active) return a.active ? -1 : 1
|
|
return getSessionSortKey(b, view.sort) - getSessionSortKey(a, view.sort)
|
|
|| (b.createdAt ?? 0) - (a.createdAt ?? 0)
|
|
|| (a.id < b.id ? -1 : a.id > b.id ? 1 : 0)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Status filter. "Archived" means not connected: closed sessions and ones
|
|
* whose CLI went away. The open session always stays visible so switching
|
|
* the filter never yanks it out from under the user.
|
|
*/
|
|
export function filterSessionsByStatus<T extends Pick<SessionSummary, 'id' | 'active'>>(
|
|
sessions: T[],
|
|
status: SessionListStatus,
|
|
selectedSessionId?: string | null
|
|
): T[] {
|
|
if (status === 'all') return sessions
|
|
const wantActive = status === 'active'
|
|
return sessions.filter(session => session.active === wantActive || session.id === selectedSessionId)
|
|
}
|