feat(session): paginated session list with infinite scroll and assistant mode improvements (#243)

* feat(session): paginated session list with infinite scroll and search

Replace per-directory useQueries session listing with a combined
cursor-based useInfiniteQuery (25 per page, loads more on scroll) and
move search into the API query instead of client-side filtering.

Add OpenCodeClient.listSessionsPage backed by the v2 /api/session
endpoint plus a toLegacySession adapter. Add invalidateSessionListCaches
to centralize session-list cache invalidation for infinite queries, and
update EventContext and useSSE to handle the new infinite-query cache
shape.

* fix(session): centralize and debounce session-list cache invalidation

Migrate ResetPermissionsDialog off the stale per-directory cache key
(which no longer matches the infinite-query key shape and hardcoded the
opencode URL) to the shared invalidateSessionListCaches helper, and drop
the now-unused repoDirectory prop and its call sites.

Debounce session-list invalidation on SSE session.updated events in
EventContext and useSSE so a burst of updates coalesces into a single
refetch instead of one per event. Fix the directory fallback in
EventContext getClient so it never returns the joined directory key.

* fix(permissions): scope instance dispose to the repo directory

Drop the session-list cache invalidation from ResetPermissionsDialog:
disposing the OpenCode instance does not change the persisted session
list, so the refetch was unnecessary, and the prior cache key no longer
matched the paginated shape.

Guard the reset-permissions route against an empty repo directory so it
never forwards /instance/dispose without a directory, which would
dispose the entire server instead of only the repo's instance.
This commit is contained in:
Chris Scott authored and GitHub committed 2026-05-31 10:32:14 -04:00
1 parent 78d934772e
commit eedbbfb94e
17 files changed
+931 -116

No files matched your search

+47 -1
View File
@@ -19,6 +19,34 @@ type SendPromptResponse = paths['/session/{sessionID}/message']['post']['respons
type LspStatusResponse = paths['/lsp']['get']['responses']['200']['content']['application/json']
type LspStatus = LspStatusResponse[number]
type LegacySession = SessionListResponse[number]
type SessionV2Info = {
id: string
parentID?: string
projectID: string
workspaceID?: string
title: string
time: LegacySession['time']
path?: unknown
}
type SessionPageCursor = { previous?: string; next?: string }
type SessionPageResponse = { items: SessionV2Info[]; cursor?: SessionPageCursor }
type SessionPageParams = { limit?: number; order?: 'asc' | 'desc'; search?: string; cursor?: string }
type SessionPage = { items: LegacySession[]; nextCursor?: string }
function toLegacySession(session: SessionV2Info, directory?: string): LegacySession {
return {
id: session.id,
projectID: session.projectID,
workspaceID: session.workspaceID,
directory: directory ?? '',
parentID: session.parentID,
title: session.title || 'Untitled Session',
version: 'v2',
time: session.time,
} as LegacySession
}
export type { SendPromptResponse, SendCommandResponse, LspStatus }
export class OpenCodeClient {
@@ -34,7 +62,7 @@ export class OpenCodeClient {
this.directory = directory
}
private getParams(params?: Record<string, string>) {
private getParams(params?: Record<string, string | number | boolean | undefined>) {
if (!this.directory) return params
return { ...params, directory: this.directory }
}
@@ -45,6 +73,24 @@ export class OpenCodeClient {
})
}
async listSessionsPage(params?: SessionPageParams): Promise<SessionPage> {
const isCursorRequest = params?.cursor !== undefined
const queryParams = isCursorRequest
? { cursor: params.cursor }
: this.getParams({
...(params?.limit !== undefined && { limit: params.limit }),
...(params?.order !== undefined && { order: params.order }),
...(params?.search !== undefined && { search: params.search }),
})
const response = await fetchWrapper<SessionPageResponse>(`${this.baseURL}/api/session`, {
params: queryParams,
})
return {
items: response.items.map((item) => toLegacySession(item, this.directory)),
nextCursor: response.cursor?.next,
}
}
async getSession(sessionID: string) {
return fetchWrapper<SessionResponse>(`${this.baseURL}/session/${sessionID}`, {
params: this.getParams(),