Skip to content

Class: MastraFileSystemAdapter

Thin Mastra MastraFilesystem adapter over a @dbx-tools/shared-fs FileSystem. Identity fields are getters that read the source on access; construction does not snapshot them.

  • MastraFilesystem

new MastraFileSystemAdapter(fs, options?): MastraFileSystemAdapter

FileSystem

MastraFileSystemAdapterOptions = {}

MastraFileSystemAdapter

MastraFilesystem.constructor

component: RegisteredLogger

MastraFilesystem.component


optional error?: string

Error message when status is ‘error’

MastraFilesystem.error


protected logger: IMastraLogger

MastraFilesystem.logger


status: ProviderStatus = "pending"

Current status of the filesystem

MastraFilesystem.status

get basePath(): string

string


get id(): string

Unique identifier for this filesystem instance

string

MastraFilesystem.id


get name(): string

Human-readable name (e.g., ‘LocalFilesystem’, ‘AgentFS’)

string

MastraFilesystem.name


get provider(): string

Provider type identifier

string

MastraFilesystem.provider


get readOnly(): boolean

boolean

__setLogger(logger): void

Set the logger for the agent

IMastraLogger

void

MastraFilesystem.__setLogger


__setRawConfig(rawConfig): void

Internal

Sets the raw storage configuration for this primitive.

Record<string, unknown>

void

MastraFilesystem.__setRawConfig


_destroy(): Promise<void>

Destroy the filesystem and clean up all resources (wrapper with status management).

This method is race-condition-safe - concurrent calls will return the same promise. Handles status management.

Subclasses override destroy() to provide their destroy logic.

Promise<void>

MastraFilesystem._destroy


_init(): Promise<void>

Initialize the filesystem (wrapper with status management and race-condition safety).

This method is race-condition-safe - concurrent calls will return the same promise. Handles status management automatically.

Subclasses override init() to provide their initialization logic.

Promise<void>

MastraFilesystem._init


appendFile(inputPath, content): Promise<void>

string

FileContent

Promise<void>

MastraFilesystem.appendFile


copyFile(src, dest, options?): Promise<void>

string

string

CopyOptions

Promise<void>

MastraFilesystem.copyFile


deleteFile(inputPath, options?): Promise<void>

string

RemoveOptions

Promise<void>

MastraFilesystem.deleteFile


destroy(): Promise<void>

Override this method to implement filesystem destroy logic.

Called by _destroy() after status is set to ‘destroying’. Status will be set to ‘destroyed’ on success, ‘error’ on failure.

Promise<void>

MastraFilesystem.destroy


protected ensureReady(): Promise<void>

Ensure the filesystem is ready.

Calls _init() if status is not ‘ready’. Useful for lazy initialization where operations should automatically initialize the filesystem if needed.

Promise<void>

if the filesystem fails to reach ‘ready’ status

async readFile(path: string): Promise<string | Buffer> {
await this.ensureReady();
// Now safe to use the filesystem
}

MastraFilesystem.ensureReady


exists(inputPath): Promise<boolean>

string

Promise<boolean>

MastraFilesystem.exists


getInfo(): FilesystemInfo<{ backend: string; root: string; }>

FilesystemInfo<{ backend: string; root: string; }>


getInstructions(): string

string


init(): Promise<void>

Override this method to implement filesystem initialization logic.

Called by _init() after status is set to ‘initializing’. Status will be set to ‘ready’ on success, ‘error’ on failure.

Promise<void>

async init(): Promise<void> {
this._client = new StorageClient({ ... });
await this._client.connect();
}

MastraFilesystem.init


mkdir(inputPath, options?): Promise<void>

string

boolean

Promise<void>

MastraFilesystem.mkdir


moveFile(src, dest, options?): Promise<void>

string

string

CopyOptions

Promise<void>

MastraFilesystem.moveFile


readdir(inputPath, options?): Promise<FileEntry[]>

string

ListOptions

Promise<FileEntry[]>

MastraFilesystem.readdir


readFile(inputPath, options?): Promise<string | Buffer<ArrayBufferLike>>

string

ReadOptions

Promise<string | Buffer<ArrayBufferLike>>

MastraFilesystem.readFile


rmdir(inputPath, options?): Promise<void>

string

RemoveOptions

Promise<void>

MastraFilesystem.rmdir


stat(inputPath): Promise<FileStat>

string

Promise<FileStat>

MastraFilesystem.stat


toRawConfig(): Record<string, unknown> | undefined

Returns the raw storage configuration this primitive was created from, or undefined if it was created from code.

Record<string, unknown> | undefined

MastraFilesystem.toRawConfig


writeFile(inputPath, content, options?): Promise<void>

string

FileContent

WriteOptions

Promise<void>

MastraFilesystem.writeFile