| 14 | } |
| 15 | |
| 16 | export async function apiSearch( |
| 17 | query: string, |
| 18 | filters: SearchFilters = {}, |
| 19 | page = 0, |
| 20 | pageSize = 20, |
| 21 | apiUrl = "" |
| 22 | ): Promise<SearchApiResponse> { |
| 23 | const params = new URLSearchParams({ q: query, page: String(page), pageSize: String(pageSize) }); |
| 24 | |
| 25 | if (filters.dateFrom) params.set("dateFrom", String(filters.dateFrom)); |
| 26 | if (filters.dateTo) params.set("dateTo", String(filters.dateTo)); |
| 27 | if (filters.role) params.set("role", filters.role); |
| 28 | if (filters.conversationId) params.set("conversationId", filters.conversationId); |
| 29 | if (filters.contentType) params.set("contentType", filters.contentType); |
| 30 | if (filters.model) params.set("model", filters.model); |
| 31 | if (filters.tagIds?.length) params.set("tagIds", filters.tagIds.join(",")); |
| 32 | |
| 33 | const res = await fetch(`${apiUrl}/api/search?${params.toString()}`); |
| 34 | if (!res.ok) throw new Error(`Search API error: ${res.status}`); |
| 35 | return res.json() as Promise<SearchApiResponse>; |
| 36 | } |