import { Document } from "../types"; import { BaseDocumentLoader } from "./base"; export class TextDocumentLoader extends BaseDocumentLoader { supportedExtensions = ["txt", "md", "markdown"]; async load(filePath: string, content: Buffer): Promise { try { const text = content.toString("utf-8"); const cleanedText = this.cleanText(text); const metadata = this.createBaseMetadata(filePath, content.length); return { id: this.generateDocumentId(filePath), content: cleanedText, metadata, source: filePath, }; } catch (error) { throw new Error(`Failed to load text document: ${error}`); } } }