UNPKG

@adonis-agora/agent

Version:

Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.

46 lines • 2.74 kB
/** * Turns a media file's raw bytes into the plain text that gets chunked, embedded, and indexed. The * extraction seam — so the RAG stack itself stays format-agnostic. Ships the text-family extractors; * bring your own for PDF/DOCX/etc. by registering a parser on a {@link MimeTextExtractor} (so no PDF * library is ever a hard dependency of `@adonis-agora/agent`). Mirrors the reference `rag-media` * `TextExtractor` contract exactly. */ export interface TextExtractor { extract(bytes: Buffer, contentType: string): Promise<string>; } /** Thrown when no extractor is registered for a content type — ingestion treats it as "skip, don't index". */ export declare class UnsupportedContentTypeError extends Error { readonly contentType: string; constructor(contentType: string); } /** How a single content type (or `type/*` family) turns bytes into text. */ export type ExtractFn = (bytes: Buffer, contentType: string) => string | Promise<string>; /** * A {@link TextExtractor} that dispatches by content type. Register exact types (`application/json`) or * a whole family (`text/*`); an exact match always wins over a family. Unregistered types throw * {@link UnsupportedContentTypeError}. This is the extension point for binary formats: * `.register('application/pdf', pdfFn)` — the PDF/DOCX library stays entirely on the host side. */ export declare class MimeTextExtractor implements TextExtractor { private readonly exact; private readonly families; register(contentType: string, fn: ExtractFn): this; extract(bytes: Buffer, contentType: string): Promise<string>; /** Whether a content type would resolve to an extractor (without reading bytes). */ supports(contentType: string): boolean; private resolve; } /** Strip any `; charset=…` parameter off a content type and lower-case it. */ export declare function normalizeContentType(contentType: string): string; /** Decode bytes as UTF-8 — the extractor for `text/*` and JSON. */ export declare function decodeUtf8(bytes: Buffer): string; /** Decode UTF-8 then strip HTML: drop `<script>`/`<style>` bodies and tags, decode common entities. */ export declare function extractHtmlText(bytes: Buffer): string; /** * The default extractor: `text/plain`, `text/csv`, `text/markdown` (and the whole `text/*` family) plus * `application/json` decode as UTF-8, `text/html` is tag-stripped, and everything else — PDF, DOCX, * images — throws {@link UnsupportedContentTypeError} (so binary formats are skipped rather than indexed * as garbage). Extend it for those: `.register('application/pdf', myPdfExtractor)`. */ export declare function defaultTextExtractor(): MimeTextExtractor; //# sourceMappingURL=text-extractor.d.ts.map