Files
shumai/packages/webui/components/search/search-by-image.ts
T
Yiling-J 3943407093 feat(search): add image similarity search (#537)
* feat(search): add image similarity search

* feat(search): support pasting image attachments
2026-11-21 10:32:46 +08:00

22 lines
745 B
TypeScript

import { client } from '@/ui/api/client'
import { m } from '@/ui/paraglide/messages.js'
import type { ImageSearchRequest } from '@shumai/dtos'
export async function searchByImage(
folderId: string,
request: ImageSearchRequest,
signal: AbortSignal,
) {
const res = await client.api.folders[':folderId']['image-search'].$post(
{ param: { folderId }, json: request },
{ init: { signal } },
)
if (!res.ok) {
if (res.status === 409) throw new Error(m.image_search_waiting_for_index())
if (res.status === 422) throw new Error(m.enable_embedding_agent_hint())
if (res.status === 400 || res.status === 413) throw new Error(m.image_search_invalid_image())
throw new Error(m.search_failed())
}
return res.json()
}