- extraction-service: Fastify scaffold (port 4005) with extract/tasks modules - src/lib/: config, errors, cosmos, product-config, python-bridge - src/modules/extract/: types (Zod schemas), routes (POST /extract, batch, models) - src/modules/tasks/: types, repository (Cosmos CRUD), routes (CRUD endpoints) - Python sidecar: FastAPI app, LangExtract wrapper, models, task registry - @bytelyst/extraction package: types, client factory, index exports - Both pnpm build pass clean
79 lines
2.2 KiB
TypeScript
79 lines
2.2 KiB
TypeScript
/**
|
|
* 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<ExtractResponse>;
|
|
|
|
/** Batch extraction (multiple inputs, shared config). */
|
|
extractBatch(req: BatchExtractRequest): Promise<BatchExtractResponse>;
|
|
|
|
/** List available extraction tasks. */
|
|
listTasks(productId?: string): Promise<ExtractionTask[]>;
|
|
|
|
/** Get a single task by ID. */
|
|
getTask(id: string, productId?: string): Promise<ExtractionTask>;
|
|
}
|
|
|
|
/**
|
|
* 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<ExtractResponse> {
|
|
return api.fetch<ExtractResponse>('/api/extract', {
|
|
method: 'POST',
|
|
body: JSON.stringify(req),
|
|
});
|
|
},
|
|
|
|
async extractBatch(req: BatchExtractRequest): Promise<BatchExtractResponse> {
|
|
return api.fetch<BatchExtractResponse>('/api/extract/batch', {
|
|
method: 'POST',
|
|
body: JSON.stringify(req),
|
|
});
|
|
},
|
|
|
|
async listTasks(productId?: string): Promise<ExtractionTask[]> {
|
|
const qs = productId ? `?productId=${encodeURIComponent(productId)}` : '';
|
|
return api.fetch<ExtractionTask[]>(`/api/tasks${qs}`);
|
|
},
|
|
|
|
async getTask(id: string, productId?: string): Promise<ExtractionTask> {
|
|
const qs = productId ? `?productId=${encodeURIComponent(productId)}` : '';
|
|
return api.fetch<ExtractionTask>(`/api/tasks/${encodeURIComponent(id)}${qs}`);
|
|
},
|
|
};
|
|
}
|