ReferenceAsk
Remy Reference/agent/defineReader
?

defineReader

Defines a source's reader: the code that reads each built document into the app's own tables.
defineReader(source, config: ReaderConfig) → Reader

Declares the reader for a data source. Given the source and a ReaderConfig, it returns a Reader that the platform runs over every document the source builds, whether the document arrived through add(), a sync, or a bulk job. Export it as the default from its own file, and point the source's reader entry in mindstudio.json at that file. A throw fails that one delivery, and the platform retries it. Deliveries outside jobs retry after 1, 5, 15, 60, and 240 minutes, then park until you run reader retry. The declaration takes timeoutMs (per document, default 60,000, max 300,000) and concurrency (default 16, max 64).

Parameters
source
DataSource
RequiredThe data source this reader belongs to.
config
ReaderConfig
RequiredThe handlers: read and removed, plus optional cleared and relinked.
Read relations into a table
// dist/datasources/manuals.reader.ts
import { defineReader } from '@mindstudio-ai/agent';

export default defineReader(Manuals, {
  read: async (document) => {
    const found = await extractRelations(await document.chunks());
    await Evidence.removeAll((r, $) => r.documentId === $.id, { id: document.id });
    await Evidence.push(found.map((f) => ({ ...f, documentId: document.id, sourceId: document.sourceId })));
  },
  removed: async (documentId) => {
    await Evidence.removeAll((r, $) => r.documentId === $.id, { id: documentId });
  },
  cleared: async (sourceId) => {
    await Evidence.removeAll((r, $) => r.sourceId === $.id, { id: sourceId });
  },
});