/** * Extraction service client factory. * Uses @bytelyst/api-client under the hood for consistent auth token injection. */ import { createApiClient } from '@bytelyst/api-client'; import type { ExtractionClientConfig, ExtractRequest, ExtractResponse, BatchExtractRequest, BatchExtractResponse, ExtractionTask, } from './types.js'; export interface ExtractionClient { /** Single document extraction. */ extract(req: ExtractRequest): Promise; /** Batch extraction (multiple inputs, shared config). */ extractBatch(req: BatchExtractRequest): Promise; /** List available extraction tasks. */ listTasks(productId?: string): Promise; /** Get a single task by ID. */ getTask(id: string, productId?: string): Promise; } /** * Create a typed extraction service client. * * @example * ```ts * const client = createExtractionClient({ * baseUrl: "http://localhost:4005", * getToken: () => localStorage.getItem("access_token"), * }); * * const result = await client.extract({ * text: "John said we should ship by Friday.", * taskId: "transcript-extraction", * }); * ``` */ export function createExtractionClient(config: ExtractionClientConfig): ExtractionClient { const api = createApiClient({ baseUrl: config.baseUrl, getToken: config.getToken, }); return { async extract(req: ExtractRequest): Promise { return api.fetch('/api/extract', { method: 'POST', body: JSON.stringify(req), }); }, async extractBatch(req: BatchExtractRequest): Promise { return api.fetch('/api/extract/batch', { method: 'POST', body: JSON.stringify(req), }); }, async listTasks(productId?: string): Promise { const qs = productId ? `?productId=${encodeURIComponent(productId)}` : ''; return api.fetch(`/api/tasks${qs}`); }, async getTask(id: string, productId?: string): Promise { const qs = productId ? `?productId=${encodeURIComponent(productId)}` : ''; return api.fetch(`/api/tasks/${encodeURIComponent(id)}${qs}`); }, }; }