diff --git a/surfsense_web/contracts/types/chat-threads.types.ts b/surfsense_web/contracts/types/chat-threads.types.ts index d360c3732..683a72e21 100644 --- a/surfsense_web/contracts/types/chat-threads.types.ts +++ b/surfsense_web/contracts/types/chat-threads.types.ts @@ -44,6 +44,30 @@ export const deleteSnapshotRequest = z.object({ snapshot_id: z.number(), }); +/** + * Search space snapshot info (includes thread context) + */ +export const searchSpaceSnapshotInfo = z.object({ + id: z.number(), + share_token: z.string(), + public_url: z.string(), + created_at: z.string(), + message_count: z.number(), + thread_id: z.number(), + thread_title: z.string(), +}); + +/** + * List snapshots for search space + */ +export const listSearchSpaceSnapshotsRequest = z.object({ + search_space_id: z.number(), +}); + +export const listSearchSpaceSnapshotsResponse = z.object({ + snapshots: z.array(searchSpaceSnapshotInfo), +}); + // Type exports export type SnapshotInfo = z.infer; export type CreateSnapshotRequest = z.infer; @@ -51,3 +75,6 @@ export type CreateSnapshotResponse = z.infer; export type ListSnapshotsRequest = z.infer; export type ListSnapshotsResponse = z.infer; export type DeleteSnapshotRequest = z.infer; +export type SearchSpaceSnapshotInfo = z.infer; +export type ListSearchSpaceSnapshotsRequest = z.infer; +export type ListSearchSpaceSnapshotsResponse = z.infer; diff --git a/surfsense_web/lib/apis/chat-threads-api.service.ts b/surfsense_web/lib/apis/chat-threads-api.service.ts index 144defcb2..985eebc76 100644 --- a/surfsense_web/lib/apis/chat-threads-api.service.ts +++ b/surfsense_web/lib/apis/chat-threads-api.service.ts @@ -5,8 +5,12 @@ import { createSnapshotResponse, type DeleteSnapshotRequest, deleteSnapshotRequest, + type ListSearchSpaceSnapshotsRequest, + type ListSearchSpaceSnapshotsResponse, type ListSnapshotsRequest, type ListSnapshotsResponse, + listSearchSpaceSnapshotsRequest, + listSearchSpaceSnapshotsResponse, listSnapshotsRequest, listSnapshotsResponse, } from "@/contracts/types/chat-threads.types"; @@ -63,6 +67,25 @@ class ChatThreadsApiService { `/api/v1/threads/${parsed.data.thread_id}/snapshots/${parsed.data.snapshot_id}` ); }; + + /** + * List all snapshots for a search space. + */ + listSearchSpaceSnapshots = async ( + request: ListSearchSpaceSnapshotsRequest + ): Promise => { + const parsed = listSearchSpaceSnapshotsRequest.safeParse(request); + + if (!parsed.success) { + const errorMessage = parsed.error.issues.map((issue) => issue.message).join(", "); + throw new ValidationError(`Invalid request: ${errorMessage}`); + } + + return baseApiService.get( + `/api/v1/searchspaces/${parsed.data.search_space_id}/snapshots`, + listSearchSpaceSnapshotsResponse + ); + }; } export const chatThreadsApiService = new ChatThreadsApiService();