| 1 | import type { |
| 2 | HistoryIndexStatus, HistorySearchContextLine, HistorySearchContextRequest, HistorySearchPage, |
| 3 | HistorySearchRequest, HistorySessionPage, HistorySessionPageRequest, |
| 4 | } from "./historyCatalogTypes"; |
| 5 | import type { SessionMeta } from "./types"; |
| 6 | import { mockReadSnapshotPage } from "./mockReadSnapshot"; |
| 7 | |
| 8 | export interface HistoryCatalogBindings { |
| 9 | ListHistorySessions(req: HistorySessionPageRequest): Promise<HistorySessionPage>; |
| 10 | SearchHistoryContent(req: HistorySearchRequest): Promise<HistorySearchPage>; |
| 11 | GetHistorySearchContext(req: HistorySearchContextRequest): Promise<HistorySearchContextLine[]>; |
| 12 | GetHistoryIndexStatus(): Promise<HistoryIndexStatus>; |
| 13 | RebuildHistoryIndex(): Promise<void>; |
| 14 | } |
| 15 | |
| 16 | export function makeMockHistoryCatalogBindings(sessions: SessionMeta[]): HistoryCatalogBindings { |
| 17 | const status = async (): Promise<HistoryIndexStatus> => ({ |
| 18 | state: "ready", mode: "memory", revision: 1, indexed: sessions.length, total: sessions.length, pending: 0, failed: 0, |
| 19 | }); |
| 20 | return { |
| 21 | async ListHistorySessions(req) { |
| 22 | const query = req.query.trim().toLowerCase(); |
| 23 | const items = sessions.filter((session) => |
| 24 | (req.scope === "all" || (session.scope || "global") === req.scope) && |
| 25 | (req.status !== "current" || session.current) && (req.status !== "open" || session.open) && |
| 26 | (!query || [session.title, session.preview, session.topicTitle, session.workspaceRoot].some((value) => (value || "").toLowerCase().includes(query)))); |
| 27 | return { ...mockReadSnapshotPage("history-sessions", [req.scope, req.workspaceRoot, req.status, req.timeFilter, query], req.cursor, req.limit, items), revision: 1, partial: false, staleCursor: false }; |
| 28 | }, |
| 29 | async SearchHistoryContent() { return { items: [], nextCursor: "", revision: 1, partial: false, staleCursor: false, status: await status() }; }, |
| 30 | async GetHistorySearchContext() { return []; }, |
| 31 | GetHistoryIndexStatus: status, |
| 32 | async RebuildHistoryIndex() {}, |
| 33 | }; |
| 34 | } |
| 35 |