跳到主要内容
非官方简体中文翻译,内容版权归 Mastra 所有,遵循 Apache-2.0 许可。

Mesa

Stores workspace files in Mesa repos through the standard Mastra WorkspaceFilesystem interface.

Use MesaFilesystem when agents need versioned file storage. For a local directory, use LocalFilesystem. For object storage, use S3Filesystem, GCSFilesystem, or AzureBlobFilesystem.

备注

MesaFilesystem runs in the Mastra process.

Mesa's POSIX mount (for using a Mesa filesystem within a sandbox) isn't yet part of the @mastra/mesa package. Support is coming soon.

Installation
Installation的直接链接

npm install @mastra/mesa

Usage example
Usage example的直接链接

Mount one Mesa repo and pass the filesystem to a workspace:

src/mastra/workspace.ts
import { Agent } from '@mastra/core/agent'
import { Workspace } from '@mastra/core/workspace'
import { MesaFilesystem, repo } from '@mastra/mesa'

const workspace = new Workspace({
filesystem: new MesaFilesystem({
privateKey: process.env.MESA_PRIVATE_KEY,
authors: [{ name: 'File Agent', email: 'agent@example.com' }],
layout: {
'/docs': repo('docs', { mode: 'rw', at: { bookmark: 'main' } }),
},
}),
})

const agent = new Agent({
id: 'file-agent',
name: 'file-agent',
model: 'anthropic/claude-opus-4-7',
workspace,
})

privateKey falls back to MESA_PRIVATE_KEY when omitted. The layout uses repo(), re-exported from the Mesa SDK, to declare which repos to mount and where.

Constructor parameters
Constructor parameters的直接链接

privateKey?:

string
Mesa private key. Falls back to MESA_PRIVATE_KEY when omitted.

authors:

[Author, ...Author[]]
Commit authors attributed to writes made through this filesystem.

layout:

Layout
Mesa mount layout mapping absolute paths to repos, built with repo().

cache?:

{ diskCache?: { path: string; maxSizeBytes?: number } }
Mesa filesystem cache configuration.

ttl?:

number
Mesa mount token lifetime in seconds.

readOnly?:

boolean
= false
Mount every repo in the layout as read-only.

Properties
Properties的直接链接

id:

string
Filesystem instance identifier.

name:

string
Provider name ('MesaFilesystem').

provider:

string
Provider identifier ('mesa').

readOnly:

boolean | undefined
Whether write operations are blocked.

client:

Mesa | undefined
Mesa SDK client created by this provider. Undefined before initialization.

filesystem:

MesaFileSystem
Active Mesa filesystem. Access this after initialization when you need the raw Mesa SDK filesystem.

change:

MesaFileSystem["change"]
Mesa change management operations for the mounted filesystem.

bookmark:

MesaFileSystem["bookmark"]
Mesa bookmark management operations for the mounted filesystem.

Methods
Methods的直接链接

MesaFilesystem implements the WorkspaceFilesystem interface.

File operations
File operations的直接链接

readFile(path, options?)
readfilepath-options的直接链接

Reads a file from Mesa.

const content = await filesystem.readFile('/docs/README.md', {
encoding: 'utf-8',
})

Returns: Promise<string | Buffer>

writeFile(path, content, options?)
writefilepath-content-options的直接链接

Writes a file to Mesa.

await filesystem.writeFile('/docs/report.md', '# Report')

Returns: Promise<void>

appendFile(path, content)
appendfilepath-content的直接链接

Appends content to a file.

await filesystem.appendFile('/docs/log.txt', 'new line\n')

Returns: Promise<void>

deleteFile(path, options?)
deletefilepath-options的直接链接

Deletes a file.

await filesystem.deleteFile('/docs/old-report.md')

Returns: Promise<void>

copyFile(src, dest, options?)
copyfilesrc-dest-options的直接链接

Copies a file.

await filesystem.copyFile('/docs/report.md', '/docs/archive/report.md')

Returns: Promise<void>

moveFile(src, dest, options?)
movefilesrc-dest-options的直接链接

Moves or renames a file.

await filesystem.moveFile('/docs/draft.md', '/docs/final.md')

Returns: Promise<void>

Directory operations
Directory operations的直接链接

mkdir(path, options?)
mkdirpath-options的直接链接

Creates a directory.

await filesystem.mkdir('/docs/reports', { recursive: true })

Returns: Promise<void>

rmdir(path, options?)
rmdirpath-options的直接链接

Removes a directory.

await filesystem.rmdir('/docs/reports', { recursive: true })

Returns: Promise<void>

readdir(path, options?)
readdirpath-options的直接链接

Lists directory entries.

const entries = await filesystem.readdir('/docs', {
recursive: true,
extension: '.md',
})

Returns: Promise<FileEntry[]>

Path operations
Path operations的直接链接

exists(path)
existspath的直接链接

Checks whether a path exists.

const exists = await filesystem.exists('/docs/README.md')

Returns: Promise<boolean>

stat(path)
statpath的直接链接

Returns file or directory metadata.

const stat = await filesystem.stat('/docs/README.md')

Returns: Promise<FileStat>

realpath(path)
realpathpath的直接链接

Returns the canonical path from Mesa.

const realPath = await filesystem.realpath('/docs/README.md')

Returns: Promise<string>

Mesa operations
Mesa operations的直接链接

bash(options?)
bashoptions的直接链接

Creates a Mesa-backed Bash runtime for this filesystem.

const bash = await filesystem.bash({
cwd: '/docs',
})

Returns: Promise<Bash>

Path semantics
Path semantics的直接链接

Methods expect absolute paths. For MesaFilesystem, paths are rooted at the Mesa mount and start with a path from the layout:

await filesystem.readFile('/docs/README.md')

Don't omit the leading slash:

await filesystem.readFile('docs/README.md') // Incorrect
await filesystem.readFile('/docs/README.md') // Correct

When you mount multiple repos, each repo is available under its layout path:

const filesystem = new MesaFilesystem({
authors: [{ name: 'File Agent' }],
layout: {
'/docs': repo('docs', { mode: 'rw', at: { bookmark: 'main' } }),
'/website': repo('website', { mode: 'rw', at: { bookmark: 'main' } }),
},
})

await filesystem.readFile('/docs/README.md')
await filesystem.readFile('/website/package.json')

Mesa versioning APIs
Mesa versioning APIs的直接链接

Access the underlying Mesa filesystem for Mesa-specific change and bookmark operations:

await filesystem.writeFile('/docs/draft.md', 'Draft')

const current = await filesystem.change.current({
repo: 'docs',
})

await filesystem.bookmark.move({
repo: 'docs',
name: 'main',
changeId: current.changeId,
})

More details on versioning semantics can be found in Mesa's docs.

Read-only mode
Read-only mode的直接链接

Set readOnly: true to mount every repo in the layout read-only and block write operations through Mastra:

const filesystem = new MesaFilesystem({
authors: [{ name: 'File Agent' }],
layout: { '/docs': repo('docs', { mode: 'ro', at: { bookmark: 'main' } }) },
readOnly: true,
})

Read operations still work. Write operations throw WorkspaceReadOnlyError.

Concurrency
Concurrency的直接链接

overwrite: false and expectedMtime use preflight checks before writing. These checks aren't atomic unless Mesa adds native conditional writes for app mounts.