Class: TextLoader
Defined in: packages/agentos/src/memory/ingestion/TextLoader.ts:127
Loader for plain-text, CSV, TSV, JSON, and YAML files.
The loader performs minimal transformation:
.json— re-serialises with pretty-printing so stored content is consistently formatted..yaml/.yml— theyamlpackage is used to parse and re-dump for consistent formatting; falls back to raw text on parse error.- All other extensions — content is returned as-is.
Metadata includes the approximate wordCount and a format label derived
from the file extension.
Implements
Example
const loader = new TextLoader();
const doc = await loader.load('/data/notes.txt');
console.log(doc.metadata.wordCount); // e.g. 312
Implements
Constructors
Constructor
new TextLoader():
TextLoader
Returns
TextLoader
Properties
supportedExtensions
readonlysupportedExtensions:string[]
Defined in: packages/agentos/src/memory/ingestion/TextLoader.ts:129
File extensions this loader handles, each with a leading dot.
Used by LoaderRegistry to route file paths to the correct loader.
Example
['.md', '.mdx']
Implementation of
IDocumentLoader.supportedExtensions
Methods
canLoad()
canLoad(
source):boolean
Defined in: packages/agentos/src/memory/ingestion/TextLoader.ts:136
Returns true when this loader is capable of handling source.
For string sources the check is purely extension-based. For Buffer
sources the loader may inspect magic bytes when relevant.
Parameters
source
Absolute file path or raw bytes.
string | Buffer
Returns
boolean
Implementation of
load()
load(
source,_options?):Promise<LoadedDocument>
Defined in: packages/agentos/src/memory/ingestion/TextLoader.ts:150
Parses source and returns a normalised LoadedDocument.
When source is a string the loader treats it as an absolute (or
resolvable) file path and reads the file from disk. When source is a
Buffer the loader parses the bytes directly and derives as much
metadata as possible from the buffer content alone.
Parameters
source
Absolute file path OR raw document bytes.
string | Buffer
_options?
Optional hints such as a format override.
Returns
Promise<LoadedDocument>
A promise resolving to the fully-populated LoadedDocument.
Throws
When the file cannot be read or the format is not parsable.