import { apiFetch } from '../../shared/api/http' import type { DocumentLifecycleState } from '../../shared/types' export interface StoreInfo { name: string slug: string type: string embedder: string isDefault: boolean connected: boolean documentCount: number chunkCount: number errorMessage?: string } export interface StoreDetail { id: string name: string slug: string kind: string embedder: string isDefault: boolean config: Record createdAt: string } export interface StoreCreatePayload { name: string slug: string kind: string embedder: string config: Record isDefault?: boolean } export interface StoreUpdatePayload { name?: string slug?: string kind?: string embedder?: string config?: Record isDefault?: boolean } export interface StoreDocEntry { docId: string filename: string state: DocumentLifecycleState chunkCount: number pushedAt: string } export interface QueryResult { chunkId: string docId: string filename: string text: string score: number pageRange?: [number, number] } export function fetchStores(): Promise { return apiFetch('/api/stores') } export function fetchStore(slug: string): Promise { return apiFetch(`/api/stores/${encodeURIComponent(slug)}`) } export function createStore(payload: StoreCreatePayload): Promise { return apiFetch('/api/stores', { method: 'POST', body: JSON.stringify(payload), }) } export function updateStore(slug: string, payload: StoreUpdatePayload): Promise { return apiFetch(`/api/stores/${encodeURIComponent(slug)}`, { method: 'PATCH', body: JSON.stringify(payload), }) } export function deleteStore(slug: string): Promise { return apiFetch(`/api/stores/${encodeURIComponent(slug)}`, { method: 'DELETE' }) } export function fetchStoreDocuments(store: string): Promise { return apiFetch(`/api/stores/${encodeURIComponent(store)}/documents`) } export function removeDocumentFromStore(store: string, docId: string): Promise { return apiFetch( `/api/stores/${encodeURIComponent(store)}/documents/${encodeURIComponent(docId)}`, { method: 'DELETE' }, ) } export function queryStore(store: string, query: string, topK = 5): Promise { return apiFetch(`/api/stores/${encodeURIComponent(store)}/query`, { method: 'POST', body: JSON.stringify({ query, top_k: topK }), }) }