| 1 | import type { |
| 2 | HistoryIndexStatus, HistorySearchContextLine, HistorySearchContextRequest, HistorySearchPage, |
| 3 | HistorySearchRequest, HistorySessionPage, HistorySessionPageRequest, |
| 4 | } from "./historyCatalogTypes"; |
| 5 | import type { SessionMeta } from "./types"; |
| 6 | |
| 7 | export interface HistoryCatalogBindings { |
| 8 | ListHistorySessions(req: HistorySessionPageRequest): Promise<HistorySessionPage>; |
| 9 | SearchHistoryContent(req: HistorySearchRequest): Promise<HistorySearchPage>; |
| 10 | GetHistorySearchContext(req: HistorySearchContextRequest): Promise<HistorySearchContextLine[]>; |
| 11 | GetHistoryIndexStatus(): Promise<HistoryIndexStatus>; |
| 12 | RebuildHistoryIndex(): Promise<void>; |
| 13 | } |
| 14 | |
| 15 | export function makeMockHistoryCatalogBindings(sessions: SessionMeta[]): HistoryCatalogBindings { |
| 16 | const status = async (): Promise<HistoryIndexStatus> => ({ |
| 17 | state: "ready", mode: "memory", revision: 1, indexed: sessions.length, total: sessions.length, pending: 0, failed: 0, |
| 18 | }); |
| 19 | return { |
| 20 | async ListHistorySessions(req) { |
| 21 | const start = req.cursor ? Number(req.cursor) || 0 : 0; |
| 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 | const limit = Math.max(1, Math.min(req.limit || 50, 200)); |
| 28 | return { items: items.slice(start, start + limit).map((session) => ({ ...session })), nextCursor: start + limit < items.length ? String(start + limit) : "", revision: 1, partial: false, staleCursor: false }; |
| 29 | }, |
| 30 | async SearchHistoryContent() { return { items: [], nextCursor: "", revision: 1, partial: false, staleCursor: false, status: await status() }; }, |
| 31 | async GetHistorySearchContext() { return []; }, |
| 32 | GetHistoryIndexStatus: status, |
| 33 | async RebuildHistoryIndex() {}, |
| 34 | }; |
| 35 | } |
| 36 |