@mastra/mesa 0.0.0-agent-learning-fetch-again-20260701195212

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,29 @@
1
+ # @mastra/mesa
2
+
3
+ ## 0.0.0-agent-learning-fetch-again-20260701195212
4
+
5
+ ### Minor Changes
6
+
7
+ - Added a Mesa filesystem provider for Mastra workspaces. ([#18740](https://github.com/mastra-ai/mastra/pull/18740))
8
+
9
+ ```ts
10
+ import { Workspace } from '@mastra/core/workspace';
11
+ import { MesaFilesystem } from '@mastra/mesa';
12
+
13
+ const workspace = new Workspace({
14
+ filesystem: new MesaFilesystem({
15
+ apiKey: process.env.MESA_API_KEY,
16
+ org: 'acme',
17
+ repos: [{ name: 'docs', bookmark: 'main' }],
18
+ }),
19
+ });
20
+ ```
21
+
22
+ ### Patch Changes
23
+
24
+ - Updated dependencies [[`0f69865`](https://github.com/mastra-ai/mastra/commit/0f69865aced225d98eac812e22699dc445ee18cb), [`cc440a3`](https://github.com/mastra-ai/mastra/commit/cc440a39400d8ce06655462b26c1666a1b3d4320), [`ea6327b`](https://github.com/mastra-ai/mastra/commit/ea6327ba2d63ca647804bc97b347e03a58617162), [`3439fa8`](https://github.com/mastra-ai/mastra/commit/3439fa836ecfcaa257b40c20b30ac2a8be22e9ea), [`85107f2`](https://github.com/mastra-ai/mastra/commit/85107f2758b527147fccbedff962961927c2d3b8), [`06ff9e0`](https://github.com/mastra-ai/mastra/commit/06ff9e0befd1d642ab87ff749285ee4091205c7e), [`7f5e1ff`](https://github.com/mastra-ai/mastra/commit/7f5e1ff695a92f672bb3976363925d1e9136b54a), [`b8375c1`](https://github.com/mastra-ai/mastra/commit/b8375c1f8fe905df8ae2ae9a893bb365f17aec4e), [`003f35d`](https://github.com/mastra-ai/mastra/commit/003f35d19e07b23b4bacc591c8bc0c59b42124ae)]:
25
+ - @mastra/core@0.0.0-agent-learning-fetch-again-20260701195212
26
+
27
+ ## 0.1.0
28
+
29
+ Initial release.
package/LICENSE.md ADDED
@@ -0,0 +1,30 @@
1
+ Portions of this software are licensed as follows:
2
+
3
+ - All content that resides under any directory named "ee/" within this
4
+ repository, including but not limited to:
5
+ - `packages/core/src/auth/ee/`
6
+ - `packages/server/src/server/auth/ee/`
7
+ is licensed under the license defined in `ee/LICENSE`.
8
+
9
+ - All third-party components incorporated into the Mastra Software are
10
+ licensed under the original license provided by the owner of the
11
+ applicable component.
12
+
13
+ - Content outside of the above-mentioned directories or restrictions is
14
+ available under the "Apache License 2.0" as defined below.
15
+
16
+ # Apache License 2.0
17
+
18
+ Copyright (c) 2025 Kepler Software, Inc.
19
+
20
+ Licensed under the Apache License, Version 2.0 (the "License");
21
+ you may not use this file except in compliance with the License.
22
+ You may obtain a copy of the License at
23
+
24
+ http://www.apache.org/licenses/LICENSE-2.0
25
+
26
+ Unless required by applicable law or agreed to in writing, software
27
+ distributed under the License is distributed on an "AS IS" BASIS,
28
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29
+ See the License for the specific language governing permissions and
30
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # @mastra/mesa
2
+
3
+ Mesa filesystem provider for Mastra workspaces.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @mastra/core @mastra/mesa
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { Agent } from '@mastra/core/agent';
15
+ import { Workspace } from '@mastra/core/workspace';
16
+ import { MesaFilesystem } from '@mastra/mesa';
17
+
18
+ const workspace = new Workspace({
19
+ filesystem: new MesaFilesystem({
20
+ apiKey: process.env.MESA_API_KEY,
21
+ org: 'acme',
22
+ repos: [{ name: 'docs', bookmark: 'main' }],
23
+ }),
24
+ });
25
+
26
+ const agent = new Agent({
27
+ name: 'my-agent',
28
+ model: '__GATEWAY_ANTHROPIC_MODEL_OPUS__',
29
+ workspace,
30
+ });
31
+ ```
32
+
33
+ Filesystem methods expect absolute paths rooted at the Mesa mount. Include the org slug and repo name:
34
+
35
+ ```typescript
36
+ await workspace.filesystem.readFile('/acme/docs/README.md');
37
+ ```
38
+
39
+ ## License
40
+
41
+ Apache-2.0
package/dist/index.cjs ADDED
@@ -0,0 +1,505 @@
1
+ 'use strict';
2
+
3
+ var path = require('path/posix');
4
+ var workspace = require('@mastra/core/workspace');
5
+ var sdk = require('@mesadev/sdk');
6
+
7
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
+
9
+ var path__default = /*#__PURE__*/_interopDefault(path);
10
+
11
+ // src/filesystem/index.ts
12
+ function generateId() {
13
+ return `mesa-fs-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
14
+ }
15
+ function normalizePath(inputPath) {
16
+ return path__default.default.normalize(inputPath.startsWith("/") ? inputPath : `/${inputPath}`);
17
+ }
18
+ function getExtension(name) {
19
+ const dot = name.lastIndexOf(".");
20
+ return dot === -1 ? "" : name.slice(dot);
21
+ }
22
+ function matchesExtension(name, extensions) {
23
+ if (!extensions) return true;
24
+ const ext = getExtension(name);
25
+ return extensions.some((candidate) => candidate === ext || candidate === ext.slice(1));
26
+ }
27
+ function toMesaContent(content) {
28
+ if (typeof content === "string") return content;
29
+ if (Buffer.isBuffer(content)) return new Uint8Array(content);
30
+ return content;
31
+ }
32
+ function toError(error) {
33
+ return error instanceof Error ? error : new Error(String(error));
34
+ }
35
+ function getMesaErrorKind(error) {
36
+ const err = error && typeof error === "object" ? error : void 0;
37
+ const code = typeof err?.code === "string" ? err.code : void 0;
38
+ const name = typeof err?.name === "string" ? err.name : void 0;
39
+ for (const value of [code, name]) {
40
+ switch (value) {
41
+ case "ENOENT":
42
+ case "NotFound":
43
+ case "NoSuchFile":
44
+ case "NoSuchKey":
45
+ return "notFound";
46
+ case "EEXIST":
47
+ case "AlreadyExists":
48
+ return "alreadyExists";
49
+ case "ENOTDIR":
50
+ case "NotDirectory":
51
+ return "notDirectory";
52
+ case "EISDIR":
53
+ case "IsDirectory":
54
+ return "isDirectory";
55
+ case "ENOTEMPTY":
56
+ case "DirectoryNotEmpty":
57
+ return "directoryNotEmpty";
58
+ }
59
+ }
60
+ const message = typeof err?.message === "string" ? err.message : error instanceof Error ? error.message : String(error);
61
+ if (/\b(no such file|not found|enoent)\b/i.test(message)) return "notFound";
62
+ if (/\b(already exists|eexist)\b/i.test(message)) return "alreadyExists";
63
+ if (/\b(not a directory|enotdir)\b/i.test(message)) return "notDirectory";
64
+ if (/\b(is a directory|eisdir)\b/i.test(message)) return "isDirectory";
65
+ if (/\b(directory not empty|enotempty)\b/i.test(message)) return "directoryNotEmpty";
66
+ return void 0;
67
+ }
68
+ function mapMesaError(error, inputPath, context = "file") {
69
+ switch (getMesaErrorKind(error)) {
70
+ case "notFound":
71
+ return context === "directory" ? new workspace.DirectoryNotFoundError(inputPath) : new workspace.FileNotFoundError(inputPath);
72
+ case "alreadyExists":
73
+ return new workspace.FileExistsError(inputPath);
74
+ case "notDirectory":
75
+ return new workspace.NotDirectoryError(inputPath);
76
+ case "isDirectory":
77
+ return new workspace.IsDirectoryError(inputPath);
78
+ case "directoryNotEmpty":
79
+ return new workspace.DirectoryNotEmptyError(inputPath);
80
+ default:
81
+ return toError(error);
82
+ }
83
+ }
84
+ var MesaFilesystem = class extends workspace.MastraFilesystem {
85
+ id;
86
+ name = "MesaFilesystem";
87
+ provider = "mesa";
88
+ readOnly;
89
+ icon = "mesa";
90
+ displayName = "Mesa";
91
+ description = "Versioned Mesa filesystem for workspace files";
92
+ status = "pending";
93
+ _apiKey;
94
+ _org;
95
+ _repos;
96
+ _cache;
97
+ _ttl;
98
+ _telemetry;
99
+ _fetch;
100
+ _userAgent;
101
+ _mesa;
102
+ _filesystem;
103
+ constructor(options) {
104
+ super({ name: "MesaFilesystem", ...options });
105
+ this.id = generateId();
106
+ this.readOnly = options.readOnly;
107
+ this._org = options.org;
108
+ this._repos = options.repos;
109
+ this._apiKey = options.apiKey;
110
+ this._cache = options.cache;
111
+ this._ttl = options.ttl;
112
+ this._telemetry = options.telemetry;
113
+ this._fetch = options.fetch;
114
+ this._userAgent = options.userAgent;
115
+ }
116
+ /**
117
+ * The active Mesa client, available after initialization when this instance
118
+ * created the client itself.
119
+ */
120
+ get client() {
121
+ return this._mesa;
122
+ }
123
+ /**
124
+ * The active Mesa filesystem. Accessing this before initialization throws.
125
+ */
126
+ get filesystem() {
127
+ if (!this._filesystem) {
128
+ throw new Error("MesaFilesystem is not initialized. Call init() first or perform a filesystem operation.");
129
+ }
130
+ return this._filesystem;
131
+ }
132
+ async init() {
133
+ if (!this._repos || this._repos.length === 0) {
134
+ throw new Error("MesaFilesystem requires at least one repo.");
135
+ }
136
+ this._mesa = new sdk.Mesa({
137
+ apiKey: this._apiKey,
138
+ org: this._org,
139
+ fetch: this._fetch,
140
+ userAgent: this._userAgent
141
+ });
142
+ const repos = this.readOnly ? this._repos.map((repo) => ({ ...repo, readOnly: true })) : this._repos;
143
+ this._filesystem = await this._mesa.fs.mount({
144
+ repos,
145
+ cache: this._cache,
146
+ ttl: this._ttl,
147
+ telemetry: this._telemetry
148
+ });
149
+ }
150
+ getInfo() {
151
+ return {
152
+ id: this.id,
153
+ name: this.name,
154
+ provider: this.provider,
155
+ status: this.status,
156
+ error: this.error,
157
+ readOnly: this.readOnly,
158
+ icon: this.icon,
159
+ metadata: {
160
+ ...this._org && { org: this._org },
161
+ ...this._repos && { repos: this._repos.map((repo) => repo.name) },
162
+ mode: "client"
163
+ }
164
+ };
165
+ }
166
+ getInstructions() {
167
+ const parts = ["Mesa filesystem. Paths are rooted at the Mesa mount. Include the org and repo name in paths."];
168
+ if (this._org) {
169
+ parts.push(`Org: "${this._org}".`);
170
+ } else {
171
+ parts.push("Use the Mesa org resolved by the SDK as the first path segment.");
172
+ }
173
+ if (this._repos && this._repos.length > 0) {
174
+ const repoNames = this._repos.map((repo) => `"${repo.name}"`).join(", ");
175
+ const firstRepo = this._repos[0]?.name ?? "repo";
176
+ const orgSegment = this._org ?? "org";
177
+ parts.push(`Mounted repos: ${repoNames}. For example "/${orgSegment}/${firstRepo}/file.txt".`);
178
+ }
179
+ parts.push("Files are versioned by Mesa.");
180
+ if (this.readOnly) {
181
+ parts.push("Mounted read-only.");
182
+ }
183
+ return parts.join(" ");
184
+ }
185
+ async readFile(inputPath, options) {
186
+ await this.ensureReady();
187
+ const target = normalizePath(inputPath);
188
+ try {
189
+ const buffer = Buffer.from(await this.filesystem.readFileBuffer(target));
190
+ if (options?.encoding) return buffer.toString(options.encoding);
191
+ return buffer;
192
+ } catch (error) {
193
+ throw mapMesaError(error, inputPath);
194
+ }
195
+ }
196
+ async writeFile(inputPath, content, options) {
197
+ await this.ensureReady();
198
+ this.assertWritable("writeFile");
199
+ const target = normalizePath(inputPath);
200
+ if (options?.overwrite === false && await this.exists(target)) {
201
+ throw new workspace.FileExistsError(inputPath);
202
+ }
203
+ if (options?.expectedMtime) {
204
+ await this.assertExpectedMtime(inputPath, options.expectedMtime);
205
+ }
206
+ if (options?.recursive === false) {
207
+ await this.assertParentDirectoryExists(target);
208
+ } else {
209
+ await this.ensureParentDirectory(target);
210
+ }
211
+ try {
212
+ await this.filesystem.writeFile(target, toMesaContent(content));
213
+ } catch (error) {
214
+ const mapped = mapMesaError(error, inputPath);
215
+ if (mapped instanceof workspace.NotDirectoryError) throw new workspace.NotDirectoryError(path__default.default.dirname(target));
216
+ if (mapped instanceof workspace.FileNotFoundError) throw new workspace.DirectoryNotFoundError(path__default.default.dirname(target));
217
+ throw mapped;
218
+ }
219
+ }
220
+ async appendFile(inputPath, content) {
221
+ await this.ensureReady();
222
+ this.assertWritable("appendFile");
223
+ const target = normalizePath(inputPath);
224
+ await this.ensureParentDirectory(target);
225
+ try {
226
+ await this.filesystem.appendFile(target, toMesaContent(content));
227
+ } catch (error) {
228
+ const mapped = mapMesaError(error, inputPath);
229
+ if (mapped instanceof workspace.FileNotFoundError) throw new workspace.DirectoryNotFoundError(path__default.default.dirname(target));
230
+ throw mapped;
231
+ }
232
+ }
233
+ async deleteFile(inputPath, options) {
234
+ await this.ensureReady();
235
+ this.assertWritable("deleteFile");
236
+ const target = normalizePath(inputPath);
237
+ try {
238
+ const stats = await this.filesystem.stat(target);
239
+ if (stats.isDirectory) throw new workspace.IsDirectoryError(inputPath);
240
+ await this.filesystem.rm(target, { force: options?.force });
241
+ } catch (error) {
242
+ if (error instanceof workspace.IsDirectoryError) throw error;
243
+ const mapped = mapMesaError(error, inputPath);
244
+ if (mapped instanceof workspace.FileNotFoundError) {
245
+ if (options?.force) return;
246
+ throw mapped;
247
+ }
248
+ throw mapped;
249
+ }
250
+ }
251
+ async copyFile(src, dest, options) {
252
+ await this.ensureReady();
253
+ this.assertWritable("copyFile");
254
+ const source = normalizePath(src);
255
+ const target = normalizePath(dest);
256
+ if (options?.overwrite === false && await this.exists(target)) {
257
+ throw new workspace.FileExistsError(dest);
258
+ }
259
+ await this.ensureParentDirectory(target);
260
+ try {
261
+ await this.filesystem.cp(source, target, { recursive: options?.recursive });
262
+ } catch (error) {
263
+ const mapped = mapMesaError(error, src);
264
+ if (mapped instanceof workspace.FileExistsError) throw new workspace.FileExistsError(dest);
265
+ throw mapped;
266
+ }
267
+ }
268
+ async moveFile(src, dest, options) {
269
+ await this.ensureReady();
270
+ this.assertWritable("moveFile");
271
+ const source = normalizePath(src);
272
+ const target = normalizePath(dest);
273
+ if (options?.overwrite === false && await this.exists(target)) {
274
+ throw new workspace.FileExistsError(dest);
275
+ }
276
+ await this.ensureParentDirectory(target);
277
+ try {
278
+ await this.filesystem.mv(source, target);
279
+ } catch (error) {
280
+ const mapped = mapMesaError(error, src);
281
+ if (mapped instanceof workspace.FileExistsError) throw new workspace.FileExistsError(dest);
282
+ throw mapped;
283
+ }
284
+ }
285
+ async mkdir(inputPath, options) {
286
+ await this.ensureReady();
287
+ this.assertWritable("mkdir");
288
+ const target = normalizePath(inputPath);
289
+ try {
290
+ await this.filesystem.mkdir(target, { recursive: options?.recursive ?? true });
291
+ } catch (error) {
292
+ const mapped = mapMesaError(error, inputPath);
293
+ if (mapped instanceof workspace.FileNotFoundError) throw new workspace.DirectoryNotFoundError(path__default.default.dirname(target));
294
+ throw mapped;
295
+ }
296
+ }
297
+ async rmdir(inputPath, options) {
298
+ await this.ensureReady();
299
+ this.assertWritable("rmdir");
300
+ const target = normalizePath(inputPath);
301
+ try {
302
+ const stats = await this.filesystem.stat(target);
303
+ if (!stats.isDirectory) throw new workspace.NotDirectoryError(inputPath);
304
+ if (!options?.recursive) {
305
+ const entries = await this.filesystem.readdirWithFileTypes(target);
306
+ if (entries.length > 0) throw new workspace.DirectoryNotEmptyError(inputPath);
307
+ }
308
+ await this.filesystem.rm(target, { recursive: options?.recursive ?? true, force: options?.force });
309
+ } catch (error) {
310
+ if (error instanceof workspace.NotDirectoryError) throw error;
311
+ if (error instanceof workspace.DirectoryNotEmptyError) throw error;
312
+ const mapped = mapMesaError(error, inputPath, "directory");
313
+ if (mapped instanceof workspace.DirectoryNotFoundError) {
314
+ if (options?.force) return;
315
+ throw mapped;
316
+ }
317
+ throw mapped;
318
+ }
319
+ }
320
+ async readdir(inputPath, options) {
321
+ await this.ensureReady();
322
+ const target = normalizePath(inputPath);
323
+ try {
324
+ return await this.readDirectory(target, options);
325
+ } catch (error) {
326
+ throw mapMesaError(error, inputPath, "directory");
327
+ }
328
+ }
329
+ async exists(inputPath) {
330
+ await this.ensureReady();
331
+ const target = normalizePath(inputPath);
332
+ try {
333
+ return await this.filesystem.exists(target);
334
+ } catch (error) {
335
+ if (getMesaErrorKind(error) === "notFound") return false;
336
+ throw mapMesaError(error, inputPath);
337
+ }
338
+ }
339
+ async stat(inputPath) {
340
+ await this.ensureReady();
341
+ const target = normalizePath(inputPath);
342
+ try {
343
+ const stats = await this.filesystem.stat(target);
344
+ return this.toFileStat(target, stats);
345
+ } catch (error) {
346
+ throw mapMesaError(error, inputPath);
347
+ }
348
+ }
349
+ async realpath(inputPath) {
350
+ await this.ensureReady();
351
+ try {
352
+ return await this.filesystem.realpath(normalizePath(inputPath));
353
+ } catch (error) {
354
+ throw mapMesaError(error, inputPath);
355
+ }
356
+ }
357
+ /**
358
+ * Create a Mesa-backed Bash runtime for this filesystem.
359
+ */
360
+ async bash(options) {
361
+ await this.ensureReady();
362
+ return this.filesystem.bash(options);
363
+ }
364
+ /**
365
+ * Mesa change management operations for the mounted filesystem.
366
+ */
367
+ get change() {
368
+ return this.filesystem.change;
369
+ }
370
+ /**
371
+ * Mesa bookmark management operations for the mounted filesystem.
372
+ */
373
+ get bookmark() {
374
+ return this.filesystem.bookmark;
375
+ }
376
+ assertWritable(operation) {
377
+ if (this.readOnly) {
378
+ throw new workspace.WorkspaceReadOnlyError(operation);
379
+ }
380
+ }
381
+ async assertExpectedMtime(inputPath, expectedMtime) {
382
+ try {
383
+ const currentStat = await this.stat(inputPath);
384
+ if (currentStat.modifiedAt.getTime() !== expectedMtime.getTime()) {
385
+ throw new workspace.StaleFileError(inputPath, expectedMtime, currentStat.modifiedAt);
386
+ }
387
+ } catch (error) {
388
+ if (error instanceof workspace.StaleFileError) throw error;
389
+ if (error instanceof workspace.FileNotFoundError) return;
390
+ throw error;
391
+ }
392
+ }
393
+ async ensureParentDirectory(inputPath) {
394
+ const parent = path__default.default.dirname(inputPath);
395
+ if (parent === "/" || parent === inputPath) return;
396
+ try {
397
+ await this.filesystem.mkdir(parent, { recursive: true });
398
+ } catch (error) {
399
+ const mapped = mapMesaError(error, parent, "directory");
400
+ if (!(mapped instanceof workspace.FileExistsError)) throw mapped;
401
+ }
402
+ }
403
+ async assertParentDirectoryExists(inputPath) {
404
+ const parent = path__default.default.dirname(inputPath);
405
+ if (parent === "/" || parent === inputPath) return;
406
+ try {
407
+ const stats = await this.filesystem.stat(parent);
408
+ if (!stats.isDirectory) {
409
+ throw new workspace.NotDirectoryError(parent);
410
+ }
411
+ } catch (error) {
412
+ if (error instanceof workspace.NotDirectoryError) throw error;
413
+ throw mapMesaError(error, parent, "directory");
414
+ }
415
+ }
416
+ async readDirectory(inputPath, options, depth = 0) {
417
+ const entries = await this.filesystem.readdirWithFileTypes(inputPath);
418
+ const extensions = options?.extension ? Array.isArray(options.extension) ? options.extension : [options.extension] : void 0;
419
+ const result = [];
420
+ for (const entry of entries) {
421
+ const childPath = path__default.default.join(inputPath, entry.name);
422
+ if (entry.isFile) {
423
+ if (matchesExtension(entry.name, extensions)) {
424
+ const stat = await this.safeStat(childPath);
425
+ result.push({ name: entry.name, type: "file", size: stat?.size });
426
+ }
427
+ continue;
428
+ }
429
+ if (entry.isDirectory) {
430
+ result.push({ name: entry.name, type: "directory" });
431
+ if (options?.recursive && (options.maxDepth === void 0 || depth < options.maxDepth)) {
432
+ const childEntries = await this.readDirectory(childPath, options, depth + 1);
433
+ result.push(...childEntries.map((child) => ({ ...child, name: `${entry.name}/${child.name}` })));
434
+ }
435
+ continue;
436
+ }
437
+ result.push(this.toFileEntry(entry));
438
+ }
439
+ return result;
440
+ }
441
+ async safeStat(inputPath) {
442
+ try {
443
+ return await this.filesystem.stat(inputPath);
444
+ } catch {
445
+ return void 0;
446
+ }
447
+ }
448
+ toFileEntry(entry) {
449
+ return {
450
+ name: entry.name,
451
+ type: entry.isDirectory ? "directory" : "file",
452
+ isSymlink: entry.isSymbolicLink || void 0
453
+ };
454
+ }
455
+ toFileStat(inputPath, stats) {
456
+ const target = normalizePath(inputPath);
457
+ return {
458
+ name: target === "/" ? "/" : path__default.default.basename(target),
459
+ path: target,
460
+ type: stats.isDirectory ? "directory" : "file",
461
+ size: stats.isDirectory ? 0 : stats.size,
462
+ createdAt: stats.mtime,
463
+ modifiedAt: stats.mtime
464
+ };
465
+ }
466
+ };
467
+
468
+ // src/provider.ts
469
+ var mesaFilesystemProvider = {
470
+ id: "mesa",
471
+ name: "Mesa",
472
+ description: "Versioned Mesa filesystem for workspace files",
473
+ configSchema: {
474
+ type: "object",
475
+ required: ["repos"],
476
+ properties: {
477
+ apiKey: { type: "string", description: "Mesa API key. Falls back to MESA_API_KEY when omitted." },
478
+ org: { type: "string", description: "Mesa org slug" },
479
+ repos: {
480
+ type: "array",
481
+ description: "Mesa repos to mount",
482
+ minItems: 1,
483
+ items: {
484
+ type: "object",
485
+ required: ["name"],
486
+ properties: {
487
+ name: { type: "string", description: "Mesa repo name" },
488
+ bookmark: { type: "string", description: "Bookmark to mount" },
489
+ changeId: { type: "string", description: "Change ID to mount" },
490
+ readOnly: { type: "boolean", description: "Mount this repo as read-only" }
491
+ }
492
+ }
493
+ },
494
+ cache: { type: "object", description: "Mesa filesystem cache configuration" },
495
+ ttl: { type: "number", description: "Mesa mount token lifetime in seconds" },
496
+ readOnly: { type: "boolean", description: "Mount all repos as read-only", default: false }
497
+ }
498
+ },
499
+ createFilesystem: (config) => new MesaFilesystem(config)
500
+ };
501
+
502
+ exports.MesaFilesystem = MesaFilesystem;
503
+ exports.mesaFilesystemProvider = mesaFilesystemProvider;
504
+ //# sourceMappingURL=index.cjs.map
505
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/filesystem/index.ts","../src/provider.ts"],"names":["path","DirectoryNotFoundError","FileNotFoundError","FileExistsError","NotDirectoryError","IsDirectoryError","DirectoryNotEmptyError","MastraFilesystem","Mesa","WorkspaceReadOnlyError","StaleFileError"],"mappings":";;;;;;;;;;;AA0DA,SAAS,UAAA,GAAqB;AAC5B,EAAA,OAAO,WAAW,IAAA,CAAK,GAAA,EAAI,CAAE,QAAA,CAAS,EAAE,CAAC,CAAA,CAAA,EAAI,IAAA,CAAK,MAAA,GAAS,QAAA,CAAS,EAAE,EAAE,KAAA,CAAM,CAAA,EAAG,CAAC,CAAC,CAAA,CAAA;AACrF;AAEA,SAAS,cAAc,SAAA,EAA2B;AAChD,EAAA,OAAOA,qBAAA,CAAK,UAAU,SAAA,CAAU,UAAA,CAAW,GAAG,CAAA,GAAI,SAAA,GAAY,CAAA,CAAA,EAAI,SAAS,CAAA,CAAE,CAAA;AAC/E;AAEA,SAAS,aAA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AAuC;AAAA,MAC3E,UAAU,EAAE,IAAA,EAAM,WAAW,WAAA,EAAa,8BAAA,EAAgC,SAAS,KAAA;AAAM;AAC3F,GACF;AAAA,EACA,gBAAA,EAAkB,CAAA,MAAA,KAAU,IAAI,cAAA,CAAe,MAAM;AACvD","file":"index.cjs","sourcesContent":["import path from 'node:path/posix';\n\nimport type {\n CopyOptions,\n FileContent,\n FileEntry,\n FilesystemInfo,\n FileStat,\n ListOptions,\n MastraFilesystemOptions,\n ProviderStatus,\n ReadOptions,\n RemoveOptions,\n WriteOptions,\n} from '@mastra/core/workspace';\nimport {\n DirectoryNotEmptyError,\n DirectoryNotFoundError,\n FileExistsError,\n FileNotFoundError,\n IsDirectoryError,\n MastraFilesystem,\n NotDirectoryError,\n StaleFileError,\n WorkspaceReadOnlyError,\n} from '@mastra/core/workspace';\nimport { Mesa } from '@mesadev/sdk';\nimport type { Bash, MesaBashOptions, MesaFileSystem, MesaOptions, RepoConfig, TelemetryConfig } from '@mesadev/sdk';\n\ntype MesaFsStat = Awaited<ReturnType<MesaFileSystem['stat']>>;\ntype MesaDirent = Awaited<ReturnType<NonNullable<MesaFileSystem['readdirWithFileTypes']>>>[number];\n\nexport interface MesaFilesystemOptions extends MastraFilesystemOptions {\n /** Mesa API key. Falls back to MESA_API_KEY when omitted. */\n apiKey?: string;\n /** Block all write operations through the Mastra filesystem interface. */\n readOnly?: boolean;\n /** Mesa org slug. Falls back to Mesa SDK org inference when omitted. */\n org?: string;\n /** Mesa repos to mount. */\n repos: RepoConfig[];\n /** Mesa filesystem cache configuration. */\n cache?: {\n diskCache?: {\n path: string;\n maxSizeBytes?: number;\n };\n };\n /** Mesa mount token lifetime in seconds. */\n ttl?: number;\n /** Mesa filesystem telemetry configuration. */\n telemetry?: TelemetryConfig;\n /** Custom fetch implementation for Mesa API calls. */\n fetch?: MesaOptions['fetch'];\n /** User agent for Mesa API calls. */\n userAgent?: string;\n}\n\nfunction generateId(): string {\n return `mesa-fs-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;\n}\n\nfunction normalizePath(inputPath: string): string {\n return path.normalize(inputPath.startsWith('/') ? inputPath : `/${inputPath}`);\n}\n\nfunction getExtension(name: string): string {\n const dot = name.lastIndexOf('.');\n return dot === -1 ? '' : name.slice(dot);\n}\n\nfunction matchesExtension(name: string, extensions?: string[]): boolean {\n if (!extensions) return true;\n const ext = getExtension(name);\n return extensions.some(candidate => candidate === ext || candidate === ext.slice(1));\n}\n\nfunction toMesaContent(content: FileContent): string | Uint8Array {\n if (typeof content === 'string') return content;\n if (Buffer.isBuffer(content)) return new Uint8Array(content);\n return content;\n}\n\ntype MesaErrorKind = 'notFound' | 'alreadyExists' | 'notDirectory' | 'isDirectory' | 'directoryNotEmpty';\n\nfunction toError(error: unknown): Error {\n return error instanceof Error ? error : new Error(String(error));\n}\n\nfunction getMesaErrorKind(error: unknown): MesaErrorKind | undefined {\n const err =\n error && typeof error === 'object' ? (error as { code?: unknown; name?: unknown; message?: unknown }) : undefined;\n const code = typeof err?.code === 'string' ? err.code : undefined;\n const name = typeof err?.name === 'string' ? err.name : undefined;\n\n for (const value of [code, name]) {\n switch (value) {\n case 'ENOENT':\n case 'NotFound':\n case 'NoSuchFile':\n case 'NoSuchKey':\n return 'notFound';\n case 'EEXIST':\n case 'AlreadyExists':\n return 'alreadyExists';\n case 'ENOTDIR':\n case 'NotDirectory':\n return 'notDirectory';\n case 'EISDIR':\n case 'IsDirectory':\n return 'isDirectory';\n case 'ENOTEMPTY':\n case 'DirectoryNotEmpty':\n return 'directoryNotEmpty';\n }\n }\n\n const message =\n typeof err?.message === 'string' ? err.message : error instanceof Error ? error.message : String(error);\n if (/\\b(no such file|not found|enoent)\\b/i.test(message)) return 'notFound';\n if (/\\b(already exists|eexist)\\b/i.test(message)) return 'alreadyExists';\n if (/\\b(not a directory|enotdir)\\b/i.test(message)) return 'notDirectory';\n if (/\\b(is a directory|eisdir)\\b/i.test(message)) return 'isDirectory';\n if (/\\b(directory not empty|enotempty)\\b/i.test(message)) return 'directoryNotEmpty';\n\n return undefined;\n}\n\nfunction mapMesaError(error: unknown, inputPath: string, context: 'file' | 'directory' = 'file'): Error {\n switch (getMesaErrorKind(error)) {\n case 'notFound':\n return context === 'directory' ? new DirectoryNotFoundError(inputPath) : new FileNotFoundError(inputPath);\n case 'alreadyExists':\n return new FileExistsError(inputPath);\n case 'notDirectory':\n return new NotDirectoryError(inputPath);\n case 'isDirectory':\n return new IsDirectoryError(inputPath);\n case 'directoryNotEmpty':\n return new DirectoryNotEmptyError(inputPath);\n default:\n return toError(error);\n }\n}\n\n/**\n * Workspace filesystem adapter backed by Mesa.\n *\n * This provider runs in the Mastra process and implements the workspace file\n * API against Mesa repos. It does not mount Mesa into a sandbox.\n */\nexport class MesaFilesystem extends MastraFilesystem {\n readonly id: string;\n readonly name = 'MesaFilesystem';\n readonly provider = 'mesa';\n readonly readOnly?: boolean;\n readonly icon = 'mesa';\n readonly displayName = 'Mesa';\n readonly description = 'Versioned Mesa filesystem for workspace files';\n\n status: ProviderStatus = 'pending';\n\n private readonly _apiKey?: string;\n private readonly _org?: string;\n private readonly _repos?: RepoConfig[];\n private readonly _cache?: {\n diskCache?: {\n path: string;\n maxSizeBytes?: number;\n };\n };\n private readonly _ttl?: number;\n private readonly _telemetry?: TelemetryConfig;\n private readonly _fetch?: MesaOptions['fetch'];\n private readonly _userAgent?: string;\n\n private _mesa?: Mesa;\n private _filesystem?: MesaFileSystem;\n\n constructor(options: MesaFilesystemOptions) {\n super({ name: 'MesaFilesystem', ...options });\n\n this.id = generateId();\n this.readOnly = options.readOnly;\n this._org = options.org;\n this._repos = options.repos;\n this._apiKey = options.apiKey;\n this._cache = options.cache;\n this._ttl = options.ttl;\n this._telemetry = options.telemetry;\n this._fetch = options.fetch;\n this._userAgent = options.userAgent;\n }\n\n /**\n * The active Mesa client, available after initialization when this instance\n * created the client itself.\n */\n get client(): Mesa | undefined {\n return this._mesa;\n }\n\n /**\n * The active Mesa filesystem. Accessing this before initialization throws.\n */\n get filesystem(): MesaFileSystem {\n if (!this._filesystem) {\n throw new Error('MesaFilesystem is not initialized. Call init() first or perform a filesystem operation.');\n }\n return this._filesystem;\n }\n\n override async init(): Promise<void> {\n if (!this._repos || this._repos.length === 0) {\n throw new Error('MesaFilesystem requires at least one repo.');\n }\n\n this._mesa = new Mesa({\n apiKey: this._apiKey,\n org: this._org,\n fetch: this._fetch,\n userAgent: this._userAgent,\n });\n\n const repos = this.readOnly ? this._repos.map(repo => ({ ...repo, readOnly: true })) : this._repos;\n this._filesystem = await this._mesa.fs.mount({\n repos,\n cache: this._cache,\n ttl: this._ttl,\n telemetry: this._telemetry,\n });\n }\n\n getInfo(): FilesystemInfo<{\n org?: string;\n repos?: string[];\n mode: 'mounted' | 'client';\n }> {\n return {\n id: this.id,\n name: this.name,\n provider: this.provider,\n status: this.status,\n error: this.error,\n readOnly: this.readOnly,\n icon: this.icon,\n metadata: {\n ...(this._org && { org: this._org }),\n ...(this._repos && { repos: this._repos.map(repo => repo.name) }),\n mode: 'client',\n },\n };\n }\n\n getInstructions(): string {\n const parts = ['Mesa filesystem. Paths are rooted at the Mesa mount. Include the org and repo name in paths.'];\n\n if (this._org) {\n parts.push(`Org: \"${this._org}\".`);\n } else {\n parts.push('Use the Mesa org resolved by the SDK as the first path segment.');\n }\n\n if (this._repos && this._repos.length > 0) {\n const repoNames = this._repos.map(repo => `\"${repo.name}\"`).join(', ');\n const firstRepo = this._repos[0]?.name ?? 'repo';\n const orgSegment = this._org ?? 'org';\n parts.push(`Mounted repos: ${repoNames}. For example \"/${orgSegment}/${firstRepo}/file.txt\".`);\n }\n\n parts.push('Files are versioned by Mesa.');\n\n if (this.readOnly) {\n parts.push('Mounted read-only.');\n }\n\n return parts.join(' ');\n }\n\n async readFile(inputPath: string, options?: ReadOptions): Promise<string | Buffer> {\n await this.ensureReady();\n const target = normalizePath(inputPath);\n\n try {\n const buffer = Buffer.from(await this.filesystem.readFileBuffer(target));\n if (options?.encoding) return buffer.toString(options.encoding);\n return buffer;\n } catch (error) {\n throw mapMesaError(error, inputPath);\n }\n }\n\n async writeFile(inputPath: string, content: FileContent, options?: WriteOptions): Promise<void> {\n await this.ensureReady();\n this.assertWritable('writeFile');\n const target = normalizePath(inputPath);\n\n if (options?.overwrite === false && (await this.exists(target))) {\n throw new FileExistsError(inputPath);\n }\n\n if (options?.expectedMtime) {\n await this.assertExpectedMtime(inputPath, options.expectedMtime);\n }\n\n if (options?.recursive === false) {\n await this.assertParentDirectoryExists(target);\n } else {\n await this.ensureParentDirectory(target);\n }\n\n try {\n await this.filesystem.writeFile(target, toMesaContent(content));\n } catch (error) {\n const mapped = mapMesaError(error, inputPath);\n if (mapped instanceof NotDirectoryError) throw new NotDirectoryError(path.dirname(target));\n if (mapped instanceof FileNotFoundError) throw new DirectoryNotFoundError(path.dirname(target));\n throw mapped;\n }\n }\n\n async appendFile(inputPath: string, content: FileContent): Promise<void> {\n await this.ensureReady();\n this.assertWritable('appendFile');\n const target = normalizePath(inputPath);\n\n await this.ensureParentDirectory(target);\n\n try {\n await this.filesystem.appendFile(target, toMesaContent(content));\n } catch (error) {\n const mapped = mapMesaError(error, inputPath);\n if (mapped instanceof FileNotFoundError) throw new DirectoryNotFoundError(path.dirname(target));\n throw mapped;\n }\n }\n\n async deleteFile(inputPath: string, options?: RemoveOptions): Promise<void> {\n await this.ensureReady();\n this.assertWritable('deleteFile');\n const target = normalizePath(inputPath);\n\n try {\n const stats = await this.filesystem.stat(target);\n if (stats.isDirectory) throw new IsDirectoryError(inputPath);\n await this.filesystem.rm(target, { force: options?.force });\n } catch (error) {\n if (error instanceof IsDirectoryError) throw error;\n const mapped = mapMesaError(error, inputPath);\n if (mapped instanceof FileNotFoundError) {\n if (options?.force) return;\n throw mapped;\n }\n throw mapped;\n }\n }\n\n async copyFile(src: string, dest: string, options?: CopyOptions): Promise<void> {\n await this.ensureReady();\n this.assertWritable('copyFile');\n const source = normalizePath(src);\n const target = normalizePath(dest);\n\n if (options?.overwrite === false && (await this.exists(target))) {\n throw new FileExistsError(dest);\n }\n\n await this.ensureParentDirectory(target);\n\n try {\n await this.filesystem.cp(source, target, { recursive: options?.recursive });\n } catch (error) {\n const mapped = mapMesaError(error, src);\n if (mapped instanceof FileExistsError) throw new FileExistsError(dest);\n throw mapped;\n }\n }\n\n async moveFile(src: string, dest: string, options?: CopyOptions): Promise<void> {\n await this.ensureReady();\n this.assertWritable('moveFile');\n const source = normalizePath(src);\n const target = normalizePath(dest);\n\n if (options?.overwrite === false && (await this.exists(target))) {\n throw new FileExistsError(dest);\n }\n\n await this.ensureParentDirectory(target);\n\n try {\n await this.filesystem.mv(source, target);\n } catch (error) {\n const mapped = mapMesaError(error, src);\n if (mapped instanceof FileExistsError) throw new FileExistsError(dest);\n throw mapped;\n }\n }\n\n async mkdir(inputPath: string, options?: { recursive?: boolean }): Promise<void> {\n await this.ensureReady();\n this.assertWritable('mkdir');\n const target = normalizePath(inputPath);\n\n try {\n await this.filesystem.mkdir(target, { recursive: options?.recursive ?? true });\n } catch (error) {\n const mapped = mapMesaError(error, inputPath);\n if (mapped instanceof FileNotFoundError) throw new DirectoryNotFoundError(path.dirname(target));\n throw mapped;\n }\n }\n\n async rmdir(inputPath: string, options?: RemoveOptions): Promise<void> {\n await this.ensureReady();\n this.assertWritable('rmdir');\n const target = normalizePath(inputPath);\n\n try {\n const stats = await this.filesystem.stat(target);\n if (!stats.isDirectory) throw new NotDirectoryError(inputPath);\n\n if (!options?.recursive) {\n const entries = await this.filesystem.readdirWithFileTypes(target);\n if (entries.length > 0) throw new DirectoryNotEmptyError(inputPath);\n }\n\n await this.filesystem.rm(target, { recursive: options?.recursive ?? true, force: options?.force });\n } catch (error) {\n if (error instanceof NotDirectoryError) throw error;\n if (error instanceof DirectoryNotEmptyError) throw error;\n const mapped = mapMesaError(error, inputPath, 'directory');\n if (mapped instanceof DirectoryNotFoundError) {\n if (options?.force) return;\n throw mapped;\n }\n throw mapped;\n }\n }\n\n async readdir(inputPath: string, options?: ListOptions): Promise<FileEntry[]> {\n await this.ensureReady();\n const target = normalizePath(inputPath);\n\n try {\n return await this.readDirectory(target, options);\n } catch (error) {\n throw mapMesaError(error, inputPath, 'directory');\n }\n }\n\n async exists(inputPath: string): Promise<boolean> {\n await this.ensureReady();\n const target = normalizePath(inputPath);\n\n try {\n return await this.filesystem.exists(target);\n } catch (error) {\n if (getMesaErrorKind(error) === 'notFound') return false;\n throw mapMesaError(error, inputPath);\n }\n }\n\n async stat(inputPath: string): Promise<FileStat> {\n await this.ensureReady();\n const target = normalizePath(inputPath);\n\n try {\n const stats = await this.filesystem.stat(target);\n return this.toFileStat(target, stats);\n } catch (error) {\n throw mapMesaError(error, inputPath);\n }\n }\n\n async realpath(inputPath: string): Promise<string> {\n await this.ensureReady();\n try {\n return await this.filesystem.realpath(normalizePath(inputPath));\n } catch (error) {\n throw mapMesaError(error, inputPath);\n }\n }\n\n /**\n * Create a Mesa-backed Bash runtime for this filesystem.\n */\n async bash(options?: MesaBashOptions): Promise<Bash> {\n await this.ensureReady();\n return this.filesystem.bash(options);\n }\n\n /**\n * Mesa change management operations for the mounted filesystem.\n */\n get change(): MesaFileSystem['change'] {\n return this.filesystem.change;\n }\n\n /**\n * Mesa bookmark management operations for the mounted filesystem.\n */\n get bookmark(): MesaFileSystem['bookmark'] {\n return this.filesystem.bookmark;\n }\n\n private assertWritable(operation: string): void {\n if (this.readOnly) {\n throw new WorkspaceReadOnlyError(operation);\n }\n }\n\n private async assertExpectedMtime(inputPath: string, expectedMtime: Date): Promise<void> {\n try {\n const currentStat = await this.stat(inputPath);\n if (currentStat.modifiedAt.getTime() !== expectedMtime.getTime()) {\n throw new StaleFileError(inputPath, expectedMtime, currentStat.modifiedAt);\n }\n } catch (error) {\n if (error instanceof StaleFileError) throw error;\n if (error instanceof FileNotFoundError) return;\n throw error;\n }\n }\n\n private async ensureParentDirectory(inputPath: string): Promise<void> {\n const parent = path.dirname(inputPath);\n if (parent === '/' || parent === inputPath) return;\n\n try {\n await this.filesystem.mkdir(parent, { recursive: true });\n } catch (error) {\n const mapped = mapMesaError(error, parent, 'directory');\n if (!(mapped instanceof FileExistsError)) throw mapped;\n }\n }\n\n private async assertParentDirectoryExists(inputPath: string): Promise<void> {\n const parent = path.dirname(inputPath);\n if (parent === '/' || parent === inputPath) return;\n\n try {\n const stats = await this.filesystem.stat(parent);\n if (!stats.isDirectory) {\n throw new NotDirectoryError(parent);\n }\n } catch (error) {\n if (error instanceof NotDirectoryError) throw error;\n throw mapMesaError(error, parent, 'directory');\n }\n }\n\n private async readDirectory(inputPath: string, options?: ListOptions, depth = 0): Promise<FileEntry[]> {\n const entries = await this.filesystem.readdirWithFileTypes(inputPath);\n const extensions = options?.extension\n ? Array.isArray(options.extension)\n ? options.extension\n : [options.extension]\n : undefined;\n\n const result: FileEntry[] = [];\n for (const entry of entries) {\n const childPath = path.join(inputPath, entry.name);\n if (entry.isFile) {\n if (matchesExtension(entry.name, extensions)) {\n const stat = await this.safeStat(childPath);\n result.push({ name: entry.name, type: 'file', size: stat?.size });\n }\n continue;\n }\n\n if (entry.isDirectory) {\n result.push({ name: entry.name, type: 'directory' });\n\n if (options?.recursive && (options.maxDepth === undefined || depth < options.maxDepth)) {\n const childEntries = await this.readDirectory(childPath, options, depth + 1);\n result.push(...childEntries.map(child => ({ ...child, name: `${entry.name}/${child.name}` })));\n }\n continue;\n }\n\n result.push(this.toFileEntry(entry));\n }\n\n return result;\n }\n\n private async safeStat(inputPath: string): Promise<MesaFsStat | undefined> {\n try {\n return await this.filesystem.stat(inputPath);\n } catch {\n return undefined;\n }\n }\n\n private toFileEntry(entry: MesaDirent): FileEntry {\n return {\n name: entry.name,\n type: entry.isDirectory ? 'directory' : 'file',\n isSymlink: entry.isSymbolicLink || undefined,\n };\n }\n\n private toFileStat(inputPath: string, stats: MesaFsStat): FileStat {\n const target = normalizePath(inputPath);\n\n return {\n name: target === '/' ? '/' : path.basename(target),\n path: target,\n type: stats.isDirectory ? 'directory' : 'file',\n size: stats.isDirectory ? 0 : stats.size,\n createdAt: stats.mtime,\n modifiedAt: stats.mtime,\n };\n }\n}\n","/**\n * Mesa filesystem provider descriptor for MastraEditor.\n */\nimport type { FilesystemProvider } from '@mastra/core/editor';\n\nimport { MesaFilesystem } from './filesystem';\nimport type { MesaFilesystemOptions } from './filesystem';\n\nexport const mesaFilesystemProvider: FilesystemProvider<MesaFilesystemOptions> = {\n id: 'mesa',\n name: 'Mesa',\n description: 'Versioned Mesa filesystem for workspace files',\n configSchema: {\n type: 'object',\n required: ['repos'],\n properties: {\n apiKey: { type: 'string', description: 'Mesa API key. Falls back to MESA_API_KEY when omitted.' },\n org: { type: 'string', description: 'Mesa org slug' },\n repos: {\n type: 'array',\n description: 'Mesa repos to mount',\n minItems: 1,\n items: {\n type: 'object',\n required: ['name'],\n properties: {\n name: { type: 'string', description: 'Mesa repo name' },\n bookmark: { type: 'string', description: 'Bookmark to mount' },\n changeId: { type: 'string', description: 'Change ID to mount' },\n readOnly: { type: 'boolean', description: 'Mount this repo as read-only' },\n },\n },\n },\n cache: { type: 'object', description: 'Mesa filesystem cache configuration' },\n ttl: { type: 'number', description: 'Mesa mount token lifetime in seconds' },\n readOnly: { type: 'boolean', description: 'Mount all repos as read-only', default: false },\n },\n },\n createFilesystem: config => new MesaFilesystem(config),\n};\n"]}
package/dist/index.js ADDED
@@ -0,0 +1,498 @@
1
+ import path from 'path/posix';
2
+ import { MastraFilesystem, FileExistsError, NotDirectoryError, FileNotFoundError, DirectoryNotFoundError, IsDirectoryError, DirectoryNotEmptyError, WorkspaceReadOnlyError, StaleFileError } from '@mastra/core/workspace';
3
+ import { Mesa } from '@mesadev/sdk';
4
+
5
+ // src/filesystem/index.ts
6
+ function generateId() {
7
+ return `mesa-fs-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
8
+ }
9
+ function normalizePath(inputPath) {
10
+ return path.normalize(inputPath.startsWith("/") ? inputPath : `/${inputPath}`);
11
+ }
12
+ function getExtension(name) {
13
+ const dot = name.lastIndexOf(".");
14
+ return dot === -1 ? "" : name.slice(dot);
15
+ }
16
+ function matchesExtension(name, extensions) {
17
+ if (!extensions) return true;
18
+ const ext = getExtension(name);
19
+ return extensions.some((candidate) => candidate === ext || candidate === ext.slice(1));
20
+ }
21
+ function toMesaContent(content) {
22
+ if (typeof content === "string") return content;
23
+ if (Buffer.isBuffer(content)) return new Uint8Array(content);
24
+ return content;
25
+ }
26
+ function toError(error) {
27
+ return error instanceof Error ? error : new Error(String(error));
28
+ }
29
+ function getMesaErrorKind(error) {
30
+ const err = error && typeof error === "object" ? error : void 0;
31
+ const code = typeof err?.code === "string" ? err.code : void 0;
32
+ const name = typeof err?.name === "string" ? err.name : void 0;
33
+ for (const value of [code, name]) {
34
+ switch (value) {
35
+ case "ENOENT":
36
+ case "NotFound":
37
+ case "NoSuchFile":
38
+ case "NoSuchKey":
39
+ return "notFound";
40
+ case "EEXIST":
41
+ case "AlreadyExists":
42
+ return "alreadyExists";
43
+ case "ENOTDIR":
44
+ case "NotDirectory":
45
+ return "notDirectory";
46
+ case "EISDIR":
47
+ case "IsDirectory":
48
+ return "isDirectory";
49
+ case "ENOTEMPTY":
50
+ case "DirectoryNotEmpty":
51
+ return "directoryNotEmpty";
52
+ }
53
+ }
54
+ const message = typeof err?.message === "string" ? err.message : error instanceof Error ? error.message : String(error);
55
+ if (/\b(no such file|not found|enoent)\b/i.test(message)) return "notFound";
56
+ if (/\b(already exists|eexist)\b/i.test(message)) return "alreadyExists";
57
+ if (/\b(not a directory|enotdir)\b/i.test(message)) return "notDirectory";
58
+ if (/\b(is a directory|eisdir)\b/i.test(message)) return "isDirectory";
59
+ if (/\b(directory not empty|enotempty)\b/i.test(message)) return "directoryNotEmpty";
60
+ return void 0;
61
+ }
62
+ function mapMesaError(error, inputPath, context = "file") {
63
+ switch (getMesaErrorKind(error)) {
64
+ case "notFound":
65
+ return context === "directory" ? new DirectoryNotFoundError(inputPath) : new FileNotFoundError(inputPath);
66
+ case "alreadyExists":
67
+ return new FileExistsError(inputPath);
68
+ case "notDirectory":
69
+ return new NotDirectoryError(inputPath);
70
+ case "isDirectory":
71
+ return new IsDirectoryError(inputPath);
72
+ case "directoryNotEmpty":
73
+ return new DirectoryNotEmptyError(inputPath);
74
+ default:
75
+ return toError(error);
76
+ }
77
+ }
78
+ var MesaFilesystem = class extends MastraFilesystem {
79
+ id;
80
+ name = "MesaFilesystem";
81
+ provider = "mesa";
82
+ readOnly;
83
+ icon = "mesa";
84
+ displayName = "Mesa";
85
+ description = "Versioned Mesa filesystem for workspace files";
86
+ status = "pending";
87
+ _apiKey;
88
+ _org;
89
+ _repos;
90
+ _cache;
91
+ _ttl;
92
+ _telemetry;
93
+ _fetch;
94
+ _userAgent;
95
+ _mesa;
96
+ _filesystem;
97
+ constructor(options) {
98
+ super({ name: "MesaFilesystem", ...options });
99
+ this.id = generateId();
100
+ this.readOnly = options.readOnly;
101
+ this._org = options.org;
102
+ this._repos = options.repos;
103
+ this._apiKey = options.apiKey;
104
+ this._cache = options.cache;
105
+ this._ttl = options.ttl;
106
+ this._telemetry = options.telemetry;
107
+ this._fetch = options.fetch;
108
+ this._userAgent = options.userAgent;
109
+ }
110
+ /**
111
+ * The active Mesa client, available after initialization when this instance
112
+ * created the client itself.
113
+ */
114
+ get client() {
115
+ return this._mesa;
116
+ }
117
+ /**
118
+ * The active Mesa filesystem. Accessing this before initialization throws.
119
+ */
120
+ get filesystem() {
121
+ if (!this._filesystem) {
122
+ throw new Error("MesaFilesystem is not initialized. Call init() first or perform a filesystem operation.");
123
+ }
124
+ return this._filesystem;
125
+ }
126
+ async init() {
127
+ if (!this._repos || this._repos.length === 0) {
128
+ throw new Error("MesaFilesystem requires at least one repo.");
129
+ }
130
+ this._mesa = new Mesa({
131
+ apiKey: this._apiKey,
132
+ org: this._org,
133
+ fetch: this._fetch,
134
+ userAgent: this._userAgent
135
+ });
136
+ const repos = this.readOnly ? this._repos.map((repo) => ({ ...repo, readOnly: true })) : this._repos;
137
+ this._filesystem = await this._mesa.fs.mount({
138
+ repos,
139
+ cache: this._cache,
140
+ ttl: this._ttl,
141
+ telemetry: this._telemetry
142
+ });
143
+ }
144
+ getInfo() {
145
+ return {
146
+ id: this.id,
147
+ name: this.name,
148
+ provider: this.provider,
149
+ status: this.status,
150
+ error: this.error,
151
+ readOnly: this.readOnly,
152
+ icon: this.icon,
153
+ metadata: {
154
+ ...this._org && { org: this._org },
155
+ ...this._repos && { repos: this._repos.map((repo) => repo.name) },
156
+ mode: "client"
157
+ }
158
+ };
159
+ }
160
+ getInstructions() {
161
+ const parts = ["Mesa filesystem. Paths are rooted at the Mesa mount. Include the org and repo name in paths."];
162
+ if (this._org) {
163
+ parts.push(`Org: "${this._org}".`);
164
+ } else {
165
+ parts.push("Use the Mesa org resolved by the SDK as the first path segment.");
166
+ }
167
+ if (this._repos && this._repos.length > 0) {
168
+ const repoNames = this._repos.map((repo) => `"${repo.name}"`).join(", ");
169
+ const firstRepo = this._repos[0]?.name ?? "repo";
170
+ const orgSegment = this._org ?? "org";
171
+ parts.push(`Mounted repos: ${repoNames}. For example "/${orgSegment}/${firstRepo}/file.txt".`);
172
+ }
173
+ parts.push("Files are versioned by Mesa.");
174
+ if (this.readOnly) {
175
+ parts.push("Mounted read-only.");
176
+ }
177
+ return parts.join(" ");
178
+ }
179
+ async readFile(inputPath, options) {
180
+ await this.ensureReady();
181
+ const target = normalizePath(inputPath);
182
+ try {
183
+ const buffer = Buffer.from(await this.filesystem.readFileBuffer(target));
184
+ if (options?.encoding) return buffer.toString(options.encoding);
185
+ return buffer;
186
+ } catch (error) {
187
+ throw mapMesaError(error, inputPath);
188
+ }
189
+ }
190
+ async writeFile(inputPath, content, options) {
191
+ await this.ensureReady();
192
+ this.assertWritable("writeFile");
193
+ const target = normalizePath(inputPath);
194
+ if (options?.overwrite === false && await this.exists(target)) {
195
+ throw new FileExistsError(inputPath);
196
+ }
197
+ if (options?.expectedMtime) {
198
+ await this.assertExpectedMtime(inputPath, options.expectedMtime);
199
+ }
200
+ if (options?.recursive === false) {
201
+ await this.assertParentDirectoryExists(target);
202
+ } else {
203
+ await this.ensureParentDirectory(target);
204
+ }
205
+ try {
206
+ await this.filesystem.writeFile(target, toMesaContent(content));
207
+ } catch (error) {
208
+ const mapped = mapMesaError(error, inputPath);
209
+ if (mapped instanceof NotDirectoryError) throw new NotDirectoryError(path.dirname(target));
210
+ if (mapped instanceof FileNotFoundError) throw new DirectoryNotFoundError(path.dirname(target));
211
+ throw mapped;
212
+ }
213
+ }
214
+ async appendFile(inputPath, content) {
215
+ await this.ensureReady();
216
+ this.assertWritable("appendFile");
217
+ const target = normalizePath(inputPath);
218
+ await this.ensureParentDirectory(target);
219
+ try {
220
+ await this.filesystem.appendFile(target, toMesaContent(content));
221
+ } catch (error) {
222
+ const mapped = mapMesaError(error, inputPath);
223
+ if (mapped instanceof FileNotFoundError) throw new DirectoryNotFoundError(path.dirname(target));
224
+ throw mapped;
225
+ }
226
+ }
227
+ async deleteFile(inputPath, options) {
228
+ await this.ensureReady();
229
+ this.assertWritable("deleteFile");
230
+ const target = normalizePath(inputPath);
231
+ try {
232
+ const stats = await this.filesystem.stat(target);
233
+ if (stats.isDirectory) throw new IsDirectoryError(inputPath);
234
+ await this.filesystem.rm(target, { force: options?.force });
235
+ } catch (error) {
236
+ if (error instanceof IsDirectoryError) throw error;
237
+ const mapped = mapMesaError(error, inputPath);
238
+ if (mapped instanceof FileNotFoundError) {
239
+ if (options?.force) return;
240
+ throw mapped;
241
+ }
242
+ throw mapped;
243
+ }
244
+ }
245
+ async copyFile(src, dest, options) {
246
+ await this.ensureReady();
247
+ this.assertWritable("copyFile");
248
+ const source = normalizePath(src);
249
+ const target = normalizePath(dest);
250
+ if (options?.overwrite === false && await this.exists(target)) {
251
+ throw new FileExistsError(dest);
252
+ }
253
+ await this.ensureParentDirectory(target);
254
+ try {
255
+ await this.filesystem.cp(source, target, { recursive: options?.recursive });
256
+ } catch (error) {
257
+ const mapped = mapMesaError(error, src);
258
+ if (mapped instanceof FileExistsError) throw new FileExistsError(dest);
259
+ throw mapped;
260
+ }
261
+ }
262
+ async moveFile(src, dest, options) {
263
+ await this.ensureReady();
264
+ this.assertWritable("moveFile");
265
+ const source = normalizePath(src);
266
+ const target = normalizePath(dest);
267
+ if (options?.overwrite === false && await this.exists(target)) {
268
+ throw new FileExistsError(dest);
269
+ }
270
+ await this.ensureParentDirectory(target);
271
+ try {
272
+ await this.filesystem.mv(source, target);
273
+ } catch (error) {
274
+ const mapped = mapMesaError(error, src);
275
+ if (mapped instanceof FileExistsError) throw new FileExistsError(dest);
276
+ throw mapped;
277
+ }
278
+ }
279
+ async mkdir(inputPath, options) {
280
+ await this.ensureReady();
281
+ this.assertWritable("mkdir");
282
+ const target = normalizePath(inputPath);
283
+ try {
284
+ await this.filesystem.mkdir(target, { recursive: options?.recursive ?? true });
285
+ } catch (error) {
286
+ const mapped = mapMesaError(error, inputPath);
287
+ if (mapped instanceof FileNotFoundError) throw new DirectoryNotFoundError(path.dirname(target));
288
+ throw mapped;
289
+ }
290
+ }
291
+ async rmdir(inputPath, options) {
292
+ await this.ensureReady();
293
+ this.assertWritable("rmdir");
294
+ const target = normalizePath(inputPath);
295
+ try {
296
+ const stats = await this.filesystem.stat(target);
297
+ if (!stats.isDirectory) throw new NotDirectoryError(inputPath);
298
+ if (!options?.recursive) {
299
+ const entries = await this.filesystem.readdirWithFileTypes(target);
300
+ if (entries.length > 0) throw new DirectoryNotEmptyError(inputPath);
301
+ }
302
+ await this.filesystem.rm(target, { recursive: options?.recursive ?? true, force: options?.force });
303
+ } catch (error) {
304
+ if (error instanceof NotDirectoryError) throw error;
305
+ if (error instanceof DirectoryNotEmptyError) throw error;
306
+ const mapped = mapMesaError(error, inputPath, "directory");
307
+ if (mapped instanceof DirectoryNotFoundError) {
308
+ if (options?.force) return;
309
+ throw mapped;
310
+ }
311
+ throw mapped;
312
+ }
313
+ }
314
+ async readdir(inputPath, options) {
315
+ await this.ensureReady();
316
+ const target = normalizePath(inputPath);
317
+ try {
318
+ return await this.readDirectory(target, options);
319
+ } catch (error) {
320
+ throw mapMesaError(error, inputPath, "directory");
321
+ }
322
+ }
323
+ async exists(inputPath) {
324
+ await this.ensureReady();
325
+ const target = normalizePath(inputPath);
326
+ try {
327
+ return await this.filesystem.exists(target);
328
+ } catch (error) {
329
+ if (getMesaErrorKind(error) === "notFound") return false;
330
+ throw mapMesaError(error, inputPath);
331
+ }
332
+ }
333
+ async stat(inputPath) {
334
+ await this.ensureReady();
335
+ const target = normalizePath(inputPath);
336
+ try {
337
+ const stats = await this.filesystem.stat(target);
338
+ return this.toFileStat(target, stats);
339
+ } catch (error) {
340
+ throw mapMesaError(error, inputPath);
341
+ }
342
+ }
343
+ async realpath(inputPath) {
344
+ await this.ensureReady();
345
+ try {
346
+ return await this.filesystem.realpath(normalizePath(inputPath));
347
+ } catch (error) {
348
+ throw mapMesaError(error, inputPath);
349
+ }
350
+ }
351
+ /**
352
+ * Create a Mesa-backed Bash runtime for this filesystem.
353
+ */
354
+ async bash(options) {
355
+ await this.ensureReady();
356
+ return this.filesystem.bash(options);
357
+ }
358
+ /**
359
+ * Mesa change management operations for the mounted filesystem.
360
+ */
361
+ get change() {
362
+ return this.filesystem.change;
363
+ }
364
+ /**
365
+ * Mesa bookmark management operations for the mounted filesystem.
366
+ */
367
+ get bookmark() {
368
+ return this.filesystem.bookmark;
369
+ }
370
+ assertWritable(operation) {
371
+ if (this.readOnly) {
372
+ throw new WorkspaceReadOnlyError(operation);
373
+ }
374
+ }
375
+ async assertExpectedMtime(inputPath, expectedMtime) {
376
+ try {
377
+ const currentStat = await this.stat(inputPath);
378
+ if (currentStat.modifiedAt.getTime() !== expectedMtime.getTime()) {
379
+ throw new StaleFileError(inputPath, expectedMtime, currentStat.modifiedAt);
380
+ }
381
+ } catch (error) {
382
+ if (error instanceof StaleFileError) throw error;
383
+ if (error instanceof FileNotFoundError) return;
384
+ throw error;
385
+ }
386
+ }
387
+ async ensureParentDirectory(inputPath) {
388
+ const parent = path.dirname(inputPath);
389
+ if (parent === "/" || parent === inputPath) return;
390
+ try {
391
+ await this.filesystem.mkdir(parent, { recursive: true });
392
+ } catch (error) {
393
+ const mapped = mapMesaError(error, parent, "directory");
394
+ if (!(mapped instanceof FileExistsError)) throw mapped;
395
+ }
396
+ }
397
+ async assertParentDirectoryExists(inputPath) {
398
+ const parent = path.dirname(inputPath);
399
+ if (parent === "/" || parent === inputPath) return;
400
+ try {
401
+ const stats = await this.filesystem.stat(parent);
402
+ if (!stats.isDirectory) {
403
+ throw new NotDirectoryError(parent);
404
+ }
405
+ } catch (error) {
406
+ if (error instanceof NotDirectoryError) throw error;
407
+ throw mapMesaError(error, parent, "directory");
408
+ }
409
+ }
410
+ async readDirectory(inputPath, options, depth = 0) {
411
+ const entries = await this.filesystem.readdirWithFileTypes(inputPath);
412
+ const extensions = options?.extension ? Array.isArray(options.extension) ? options.extension : [options.extension] : void 0;
413
+ const result = [];
414
+ for (const entry of entries) {
415
+ const childPath = path.join(inputPath, entry.name);
416
+ if (entry.isFile) {
417
+ if (matchesExtension(entry.name, extensions)) {
418
+ const stat = await this.safeStat(childPath);
419
+ result.push({ name: entry.name, type: "file", size: stat?.size });
420
+ }
421
+ continue;
422
+ }
423
+ if (entry.isDirectory) {
424
+ result.push({ name: entry.name, type: "directory" });
425
+ if (options?.recursive && (options.maxDepth === void 0 || depth < options.maxDepth)) {
426
+ const childEntries = await this.readDirectory(childPath, options, depth + 1);
427
+ result.push(...childEntries.map((child) => ({ ...child, name: `${entry.name}/${child.name}` })));
428
+ }
429
+ continue;
430
+ }
431
+ result.push(this.toFileEntry(entry));
432
+ }
433
+ return result;
434
+ }
435
+ async safeStat(inputPath) {
436
+ try {
437
+ return await this.filesystem.stat(inputPath);
438
+ } catch {
439
+ return void 0;
440
+ }
441
+ }
442
+ toFileEntry(entry) {
443
+ return {
444
+ name: entry.name,
445
+ type: entry.isDirectory ? "directory" : "file",
446
+ isSymlink: entry.isSymbolicLink || void 0
447
+ };
448
+ }
449
+ toFileStat(inputPath, stats) {
450
+ const target = normalizePath(inputPath);
451
+ return {
452
+ name: target === "/" ? "/" : path.basename(target),
453
+ path: target,
454
+ type: stats.isDirectory ? "directory" : "file",
455
+ size: stats.isDirectory ? 0 : stats.size,
456
+ createdAt: stats.mtime,
457
+ modifiedAt: stats.mtime
458
+ };
459
+ }
460
+ };
461
+
462
+ // src/provider.ts
463
+ var mesaFilesystemProvider = {
464
+ id: "mesa",
465
+ name: "Mesa",
466
+ description: "Versioned Mesa filesystem for workspace files",
467
+ configSchema: {
468
+ type: "object",
469
+ required: ["repos"],
470
+ properties: {
471
+ apiKey: { type: "string", description: "Mesa API key. Falls back to MESA_API_KEY when omitted." },
472
+ org: { type: "string", description: "Mesa org slug" },
473
+ repos: {
474
+ type: "array",
475
+ description: "Mesa repos to mount",
476
+ minItems: 1,
477
+ items: {
478
+ type: "object",
479
+ required: ["name"],
480
+ properties: {
481
+ name: { type: "string", description: "Mesa repo name" },
482
+ bookmark: { type: "string", description: "Bookmark to mount" },
483
+ changeId: { type: "string", description: "Change ID to mount" },
484
+ readOnly: { type: "boolean", description: "Mount this repo as read-only" }
485
+ }
486
+ }
487
+ },
488
+ cache: { type: "object", description: "Mesa filesystem cache configuration" },
489
+ ttl: { type: "number", description: "Mesa mount token lifetime in seconds" },
490
+ readOnly: { type: "boolean", description: "Mount all repos as read-only", default: false }
491
+ }
492
+ },
493
+ createFilesystem: (config) => new MesaFilesystem(config)
494
+ };
495
+
496
+ export { MesaFilesystem, mesaFilesystemProvider };
497
+ //# sourceMappingURL=index.js.map
498
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/filesystem/index.ts","../src/provider.ts"],"names":[],"mappings":";;;;;AA0DA,SAAS,UAAA,GAAqB;AAC5B,EAAA,OAAO,WAAW,IAAA,CAAK,GAAA,EAAI,CAAE,QAAA,CAAS,EAAE,CAAC,CAAA,CAAA,EAAI,I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QAAA,EAAU,EAAE,IAAA,EAAM,SAAA,EAAW,aAAa,8BAAA;AAA+B;AAC3E;AACF,OACF;AAAA,MACA,KAAA,EAAO,EAAE,IAAA,EAAM,QAAA,EAAU,aAAa,qCAAA,EAAsC;AAAA,MAC5E,GAAA,EAAK,EAAE,IAAA,EAAM,QAAA,EAAU,aAAa,sCAAA,EAAuC;AAAA,MAC3E,UAAU,EAAE,IAAA,EAAM,WAAW,WAAA,EAAa,8BAAA,EAAgC,SAAS,KAAA;AAAM;AAC3F,GACF;AAAA,EACA,gBAAA,EAAkB,CAAA,MAAA,KAAU,IAAI,cAAA,CAAe,MAAM;AACvD","file":"index.js","sourcesContent":["import path from 'node:path/posix';\n\nimport type {\n CopyOptions,\n FileContent,\n FileEntry,\n FilesystemInfo,\n FileStat,\n ListOptions,\n MastraFilesystemOptions,\n ProviderStatus,\n ReadOptions,\n RemoveOptions,\n WriteOptions,\n} from '@mastra/core/workspace';\nimport {\n DirectoryNotEmptyError,\n DirectoryNotFoundError,\n FileExistsError,\n FileNotFoundError,\n IsDirectoryError,\n MastraFilesystem,\n NotDirectoryError,\n StaleFileError,\n WorkspaceReadOnlyError,\n} from '@mastra/core/workspace';\nimport { Mesa } from '@mesadev/sdk';\nimport type { Bash, MesaBashOptions, MesaFileSystem, MesaOptions, RepoConfig, TelemetryConfig } from '@mesadev/sdk';\n\ntype MesaFsStat = Awaited<ReturnType<MesaFileSystem['stat']>>;\ntype MesaDirent = Awaited<ReturnType<NonNullable<MesaFileSystem['readdirWithFileTypes']>>>[number];\n\nexport interface MesaFilesystemOptions extends MastraFilesystemOptions {\n /** Mesa API key. Falls back to MESA_API_KEY when omitted. */\n apiKey?: string;\n /** Block all write operations through the Mastra filesystem interface. */\n readOnly?: boolean;\n /** Mesa org slug. Falls back to Mesa SDK org inference when omitted. */\n org?: string;\n /** Mesa repos to mount. */\n repos: RepoConfig[];\n /** Mesa filesystem cache configuration. */\n cache?: {\n diskCache?: {\n path: string;\n maxSizeBytes?: number;\n };\n };\n /** Mesa mount token lifetime in seconds. */\n ttl?: number;\n /** Mesa filesystem telemetry configuration. */\n telemetry?: TelemetryConfig;\n /** Custom fetch implementation for Mesa API calls. */\n fetch?: MesaOptions['fetch'];\n /** User agent for Mesa API calls. */\n userAgent?: string;\n}\n\nfunction generateId(): string {\n return `mesa-fs-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;\n}\n\nfunction normalizePath(inputPath: string): string {\n return path.normalize(inputPath.startsWith('/') ? inputPath : `/${inputPath}`);\n}\n\nfunction getExtension(name: string): string {\n const dot = name.lastIndexOf('.');\n return dot === -1 ? '' : name.slice(dot);\n}\n\nfunction matchesExtension(name: string, extensions?: string[]): boolean {\n if (!extensions) return true;\n const ext = getExtension(name);\n return extensions.some(candidate => candidate === ext || candidate === ext.slice(1));\n}\n\nfunction toMesaContent(content: FileContent): string | Uint8Array {\n if (typeof content === 'string') return content;\n if (Buffer.isBuffer(content)) return new Uint8Array(content);\n return content;\n}\n\ntype MesaErrorKind = 'notFound' | 'alreadyExists' | 'notDirectory' | 'isDirectory' | 'directoryNotEmpty';\n\nfunction toError(error: unknown): Error {\n return error instanceof Error ? error : new Error(String(error));\n}\n\nfunction getMesaErrorKind(error: unknown): MesaErrorKind | undefined {\n const err =\n error && typeof error === 'object' ? (error as { code?: unknown; name?: unknown; message?: unknown }) : undefined;\n const code = typeof err?.code === 'string' ? err.code : undefined;\n const name = typeof err?.name === 'string' ? err.name : undefined;\n\n for (const value of [code, name]) {\n switch (value) {\n case 'ENOENT':\n case 'NotFound':\n case 'NoSuchFile':\n case 'NoSuchKey':\n return 'notFound';\n case 'EEXIST':\n case 'AlreadyExists':\n return 'alreadyExists';\n case 'ENOTDIR':\n case 'NotDirectory':\n return 'notDirectory';\n case 'EISDIR':\n case 'IsDirectory':\n return 'isDirectory';\n case 'ENOTEMPTY':\n case 'DirectoryNotEmpty':\n return 'directoryNotEmpty';\n }\n }\n\n const message =\n typeof err?.message === 'string' ? err.message : error instanceof Error ? error.message : String(error);\n if (/\\b(no such file|not found|enoent)\\b/i.test(message)) return 'notFound';\n if (/\\b(already exists|eexist)\\b/i.test(message)) return 'alreadyExists';\n if (/\\b(not a directory|enotdir)\\b/i.test(message)) return 'notDirectory';\n if (/\\b(is a directory|eisdir)\\b/i.test(message)) return 'isDirectory';\n if (/\\b(directory not empty|enotempty)\\b/i.test(message)) return 'directoryNotEmpty';\n\n return undefined;\n}\n\nfunction mapMesaError(error: unknown, inputPath: string, context: 'file' | 'directory' = 'file'): Error {\n switch (getMesaErrorKind(error)) {\n case 'notFound':\n return context === 'directory' ? new DirectoryNotFoundError(inputPath) : new FileNotFoundError(inputPath);\n case 'alreadyExists':\n return new FileExistsError(inputPath);\n case 'notDirectory':\n return new NotDirectoryError(inputPath);\n case 'isDirectory':\n return new IsDirectoryError(inputPath);\n case 'directoryNotEmpty':\n return new DirectoryNotEmptyError(inputPath);\n default:\n return toError(error);\n }\n}\n\n/**\n * Workspace filesystem adapter backed by Mesa.\n *\n * This provider runs in the Mastra process and implements the workspace file\n * API against Mesa repos. It does not mount Mesa into a sandbox.\n */\nexport class MesaFilesystem extends MastraFilesystem {\n readonly id: string;\n readonly name = 'MesaFilesystem';\n readonly provider = 'mesa';\n readonly readOnly?: boolean;\n readonly icon = 'mesa';\n readonly displayName = 'Mesa';\n readonly description = 'Versioned Mesa filesystem for workspace files';\n\n status: ProviderStatus = 'pending';\n\n private readonly _apiKey?: string;\n private readonly _org?: string;\n private readonly _repos?: RepoConfig[];\n private readonly _cache?: {\n diskCache?: {\n path: string;\n maxSizeBytes?: number;\n };\n };\n private readonly _ttl?: number;\n private readonly _telemetry?: TelemetryConfig;\n private readonly _fetch?: MesaOptions['fetch'];\n private readonly _userAgent?: string;\n\n private _mesa?: Mesa;\n private _filesystem?: MesaFileSystem;\n\n constructor(options: MesaFilesystemOptions) {\n super({ name: 'MesaFilesystem', ...options });\n\n this.id = generateId();\n this.readOnly = options.readOnly;\n this._org = options.org;\n this._repos = options.repos;\n this._apiKey = options.apiKey;\n this._cache = options.cache;\n this._ttl = options.ttl;\n this._telemetry = options.telemetry;\n this._fetch = options.fetch;\n this._userAgent = options.userAgent;\n }\n\n /**\n * The active Mesa client, available after initialization when this instance\n * created the client itself.\n */\n get client(): Mesa | undefined {\n return this._mesa;\n }\n\n /**\n * The active Mesa filesystem. Accessing this before initialization throws.\n */\n get filesystem(): MesaFileSystem {\n if (!this._filesystem) {\n throw new Error('MesaFilesystem is not initialized. Call init() first or perform a filesystem operation.');\n }\n return this._filesystem;\n }\n\n override async init(): Promise<void> {\n if (!this._repos || this._repos.length === 0) {\n throw new Error('MesaFilesystem requires at least one repo.');\n }\n\n this._mesa = new Mesa({\n apiKey: this._apiKey,\n org: this._org,\n fetch: this._fetch,\n userAgent: this._userAgent,\n });\n\n const repos = this.readOnly ? this._repos.map(repo => ({ ...repo, readOnly: true })) : this._repos;\n this._filesystem = await this._mesa.fs.mount({\n repos,\n cache: this._cache,\n ttl: this._ttl,\n telemetry: this._telemetry,\n });\n }\n\n getInfo(): FilesystemInfo<{\n org?: string;\n repos?: string[];\n mode: 'mounted' | 'client';\n }> {\n return {\n id: this.id,\n name: this.name,\n provider: this.provider,\n status: this.status,\n error: this.error,\n readOnly: this.readOnly,\n icon: this.icon,\n metadata: {\n ...(this._org && { org: this._org }),\n ...(this._repos && { repos: this._repos.map(repo => repo.name) }),\n mode: 'client',\n },\n };\n }\n\n getInstructions(): string {\n const parts = ['Mesa filesystem. Paths are rooted at the Mesa mount. Include the org and repo name in paths.'];\n\n if (this._org) {\n parts.push(`Org: \"${this._org}\".`);\n } else {\n parts.push('Use the Mesa org resolved by the SDK as the first path segment.');\n }\n\n if (this._repos && this._repos.length > 0) {\n const repoNames = this._repos.map(repo => `\"${repo.name}\"`).join(', ');\n const firstRepo = this._repos[0]?.name ?? 'repo';\n const orgSegment = this._org ?? 'org';\n parts.push(`Mounted repos: ${repoNames}. For example \"/${orgSegment}/${firstRepo}/file.txt\".`);\n }\n\n parts.push('Files are versioned by Mesa.');\n\n if (this.readOnly) {\n parts.push('Mounted read-only.');\n }\n\n return parts.join(' ');\n }\n\n async readFile(inputPath: string, options?: ReadOptions): Promise<string | Buffer> {\n await this.ensureReady();\n const target = normalizePath(inputPath);\n\n try {\n const buffer = Buffer.from(await this.filesystem.readFileBuffer(target));\n if (options?.encoding) return buffer.toString(options.encoding);\n return buffer;\n } catch (error) {\n throw mapMesaError(error, inputPath);\n }\n }\n\n async writeFile(inputPath: string, content: FileContent, options?: WriteOptions): Promise<void> {\n await this.ensureReady();\n this.assertWritable('writeFile');\n const target = normalizePath(inputPath);\n\n if (options?.overwrite === false && (await this.exists(target))) {\n throw new FileExistsError(inputPath);\n }\n\n if (options?.expectedMtime) {\n await this.assertExpectedMtime(inputPath, options.expectedMtime);\n }\n\n if (options?.recursive === false) {\n await this.assertParentDirectoryExists(target);\n } else {\n await this.ensureParentDirectory(target);\n }\n\n try {\n await this.filesystem.writeFile(target, toMesaContent(content));\n } catch (error) {\n const mapped = mapMesaError(error, inputPath);\n if (mapped instanceof NotDirectoryError) throw new NotDirectoryError(path.dirname(target));\n if (mapped instanceof FileNotFoundError) throw new DirectoryNotFoundError(path.dirname(target));\n throw mapped;\n }\n }\n\n async appendFile(inputPath: string, content: FileContent): Promise<void> {\n await this.ensureReady();\n this.assertWritable('appendFile');\n const target = normalizePath(inputPath);\n\n await this.ensureParentDirectory(target);\n\n try {\n await this.filesystem.appendFile(target, toMesaContent(content));\n } catch (error) {\n const mapped = mapMesaError(error, inputPath);\n if (mapped instanceof FileNotFoundError) throw new DirectoryNotFoundError(path.dirname(target));\n throw mapped;\n }\n }\n\n async deleteFile(inputPath: string, options?: RemoveOptions): Promise<void> {\n await this.ensureReady();\n this.assertWritable('deleteFile');\n const target = normalizePath(inputPath);\n\n try {\n const stats = await this.filesystem.stat(target);\n if (stats.isDirectory) throw new IsDirectoryError(inputPath);\n await this.filesystem.rm(target, { force: options?.force });\n } catch (error) {\n if (error instanceof IsDirectoryError) throw error;\n const mapped = mapMesaError(error, inputPath);\n if (mapped instanceof FileNotFoundError) {\n if (options?.force) return;\n throw mapped;\n }\n throw mapped;\n }\n }\n\n async copyFile(src: string, dest: string, options?: CopyOptions): Promise<void> {\n await this.ensureReady();\n this.assertWritable('copyFile');\n const source = normalizePath(src);\n const target = normalizePath(dest);\n\n if (options?.overwrite === false && (await this.exists(target))) {\n throw new FileExistsError(dest);\n }\n\n await this.ensureParentDirectory(target);\n\n try {\n await this.filesystem.cp(source, target, { recursive: options?.recursive });\n } catch (error) {\n const mapped = mapMesaError(error, src);\n if (mapped instanceof FileExistsError) throw new FileExistsError(dest);\n throw mapped;\n }\n }\n\n async moveFile(src: string, dest: string, options?: CopyOptions): Promise<void> {\n await this.ensureReady();\n this.assertWritable('moveFile');\n const source = normalizePath(src);\n const target = normalizePath(dest);\n\n if (options?.overwrite === false && (await this.exists(target))) {\n throw new FileExistsError(dest);\n }\n\n await this.ensureParentDirectory(target);\n\n try {\n await this.filesystem.mv(source, target);\n } catch (error) {\n const mapped = mapMesaError(error, src);\n if (mapped instanceof FileExistsError) throw new FileExistsError(dest);\n throw mapped;\n }\n }\n\n async mkdir(inputPath: string, options?: { recursive?: boolean }): Promise<void> {\n await this.ensureReady();\n this.assertWritable('mkdir');\n const target = normalizePath(inputPath);\n\n try {\n await this.filesystem.mkdir(target, { recursive: options?.recursive ?? true });\n } catch (error) {\n const mapped = mapMesaError(error, inputPath);\n if (mapped instanceof FileNotFoundError) throw new DirectoryNotFoundError(path.dirname(target));\n throw mapped;\n }\n }\n\n async rmdir(inputPath: string, options?: RemoveOptions): Promise<void> {\n await this.ensureReady();\n this.assertWritable('rmdir');\n const target = normalizePath(inputPath);\n\n try {\n const stats = await this.filesystem.stat(target);\n if (!stats.isDirectory) throw new NotDirectoryError(inputPath);\n\n if (!options?.recursive) {\n const entries = await this.filesystem.readdirWithFileTypes(target);\n if (entries.length > 0) throw new DirectoryNotEmptyError(inputPath);\n }\n\n await this.filesystem.rm(target, { recursive: options?.recursive ?? true, force: options?.force });\n } catch (error) {\n if (error instanceof NotDirectoryError) throw error;\n if (error instanceof DirectoryNotEmptyError) throw error;\n const mapped = mapMesaError(error, inputPath, 'directory');\n if (mapped instanceof DirectoryNotFoundError) {\n if (options?.force) return;\n throw mapped;\n }\n throw mapped;\n }\n }\n\n async readdir(inputPath: string, options?: ListOptions): Promise<FileEntry[]> {\n await this.ensureReady();\n const target = normalizePath(inputPath);\n\n try {\n return await this.readDirectory(target, options);\n } catch (error) {\n throw mapMesaError(error, inputPath, 'directory');\n }\n }\n\n async exists(inputPath: string): Promise<boolean> {\n await this.ensureReady();\n const target = normalizePath(inputPath);\n\n try {\n return await this.filesystem.exists(target);\n } catch (error) {\n if (getMesaErrorKind(error) === 'notFound') return false;\n throw mapMesaError(error, inputPath);\n }\n }\n\n async stat(inputPath: string): Promise<FileStat> {\n await this.ensureReady();\n const target = normalizePath(inputPath);\n\n try {\n const stats = await this.filesystem.stat(target);\n return this.toFileStat(target, stats);\n } catch (error) {\n throw mapMesaError(error, inputPath);\n }\n }\n\n async realpath(inputPath: string): Promise<string> {\n await this.ensureReady();\n try {\n return await this.filesystem.realpath(normalizePath(inputPath));\n } catch (error) {\n throw mapMesaError(error, inputPath);\n }\n }\n\n /**\n * Create a Mesa-backed Bash runtime for this filesystem.\n */\n async bash(options?: MesaBashOptions): Promise<Bash> {\n await this.ensureReady();\n return this.filesystem.bash(options);\n }\n\n /**\n * Mesa change management operations for the mounted filesystem.\n */\n get change(): MesaFileSystem['change'] {\n return this.filesystem.change;\n }\n\n /**\n * Mesa bookmark management operations for the mounted filesystem.\n */\n get bookmark(): MesaFileSystem['bookmark'] {\n return this.filesystem.bookmark;\n }\n\n private assertWritable(operation: string): void {\n if (this.readOnly) {\n throw new WorkspaceReadOnlyError(operation);\n }\n }\n\n private async assertExpectedMtime(inputPath: string, expectedMtime: Date): Promise<void> {\n try {\n const currentStat = await this.stat(inputPath);\n if (currentStat.modifiedAt.getTime() !== expectedMtime.getTime()) {\n throw new StaleFileError(inputPath, expectedMtime, currentStat.modifiedAt);\n }\n } catch (error) {\n if (error instanceof StaleFileError) throw error;\n if (error instanceof FileNotFoundError) return;\n throw error;\n }\n }\n\n private async ensureParentDirectory(inputPath: string): Promise<void> {\n const parent = path.dirname(inputPath);\n if (parent === '/' || parent === inputPath) return;\n\n try {\n await this.filesystem.mkdir(parent, { recursive: true });\n } catch (error) {\n const mapped = mapMesaError(error, parent, 'directory');\n if (!(mapped instanceof FileExistsError)) throw mapped;\n }\n }\n\n private async assertParentDirectoryExists(inputPath: string): Promise<void> {\n const parent = path.dirname(inputPath);\n if (parent === '/' || parent === inputPath) return;\n\n try {\n const stats = await this.filesystem.stat(parent);\n if (!stats.isDirectory) {\n throw new NotDirectoryError(parent);\n }\n } catch (error) {\n if (error instanceof NotDirectoryError) throw error;\n throw mapMesaError(error, parent, 'directory');\n }\n }\n\n private async readDirectory(inputPath: string, options?: ListOptions, depth = 0): Promise<FileEntry[]> {\n const entries = await this.filesystem.readdirWithFileTypes(inputPath);\n const extensions = options?.extension\n ? Array.isArray(options.extension)\n ? options.extension\n : [options.extension]\n : undefined;\n\n const result: FileEntry[] = [];\n for (const entry of entries) {\n const childPath = path.join(inputPath, entry.name);\n if (entry.isFile) {\n if (matchesExtension(entry.name, extensions)) {\n const stat = await this.safeStat(childPath);\n result.push({ name: entry.name, type: 'file', size: stat?.size });\n }\n continue;\n }\n\n if (entry.isDirectory) {\n result.push({ name: entry.name, type: 'directory' });\n\n if (options?.recursive && (options.maxDepth === undefined || depth < options.maxDepth)) {\n const childEntries = await this.readDirectory(childPath, options, depth + 1);\n result.push(...childEntries.map(child => ({ ...child, name: `${entry.name}/${child.name}` })));\n }\n continue;\n }\n\n result.push(this.toFileEntry(entry));\n }\n\n return result;\n }\n\n private async safeStat(inputPath: string): Promise<MesaFsStat | undefined> {\n try {\n return await this.filesystem.stat(inputPath);\n } catch {\n return undefined;\n }\n }\n\n private toFileEntry(entry: MesaDirent): FileEntry {\n return {\n name: entry.name,\n type: entry.isDirectory ? 'directory' : 'file',\n isSymlink: entry.isSymbolicLink || undefined,\n };\n }\n\n private toFileStat(inputPath: string, stats: MesaFsStat): FileStat {\n const target = normalizePath(inputPath);\n\n return {\n name: target === '/' ? '/' : path.basename(target),\n path: target,\n type: stats.isDirectory ? 'directory' : 'file',\n size: stats.isDirectory ? 0 : stats.size,\n createdAt: stats.mtime,\n modifiedAt: stats.mtime,\n };\n }\n}\n","/**\n * Mesa filesystem provider descriptor for MastraEditor.\n */\nimport type { FilesystemProvider } from '@mastra/core/editor';\n\nimport { MesaFilesystem } from './filesystem';\nimport type { MesaFilesystemOptions } from './filesystem';\n\nexport const mesaFilesystemProvider: FilesystemProvider<MesaFilesystemOptions> = {\n id: 'mesa',\n name: 'Mesa',\n description: 'Versioned Mesa filesystem for workspace files',\n configSchema: {\n type: 'object',\n required: ['repos'],\n properties: {\n apiKey: { type: 'string', description: 'Mesa API key. Falls back to MESA_API_KEY when omitted.' },\n org: { type: 'string', description: 'Mesa org slug' },\n repos: {\n type: 'array',\n description: 'Mesa repos to mount',\n minItems: 1,\n items: {\n type: 'object',\n required: ['name'],\n properties: {\n name: { type: 'string', description: 'Mesa repo name' },\n bookmark: { type: 'string', description: 'Bookmark to mount' },\n changeId: { type: 'string', description: 'Change ID to mount' },\n readOnly: { type: 'boolean', description: 'Mount this repo as read-only' },\n },\n },\n },\n cache: { type: 'object', description: 'Mesa filesystem cache configuration' },\n ttl: { type: 'number', description: 'Mesa mount token lifetime in seconds' },\n readOnly: { type: 'boolean', description: 'Mount all repos as read-only', default: false },\n },\n },\n createFilesystem: config => new MesaFilesystem(config),\n};\n"]}
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@mastra/mesa",
3
+ "version": "0.0.0-agent-learning-fetch-again-20260701195212",
4
+ "description": "Mesa filesystem provider for Mastra workspaces",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.cjs"
17
+ }
18
+ },
19
+ "./package.json": "./package.json"
20
+ },
21
+ "license": "Apache-2.0",
22
+ "dependencies": {
23
+ "@mesadev/sdk": "0.38.0"
24
+ },
25
+ "devDependencies": {
26
+ "@types/node": "22.19.21",
27
+ "eslint": "^10.4.1",
28
+ "tsup": "^8.5.1",
29
+ "typescript": "^6.0.3",
30
+ "vitest": "4.1.8",
31
+ "@internal/lint": "0.0.0-agent-learning-fetch-again-20260701195212",
32
+ "@internal/workspace-test-utils": "0.0.54",
33
+ "@internal/types-builder": "0.0.0-agent-learning-fetch-again-20260701195212",
34
+ "@mastra/core": "0.0.0-agent-learning-fetch-again-20260701195212"
35
+ },
36
+ "peerDependencies": {
37
+ "@mastra/core": "0.0.0-agent-learning-fetch-again-20260701195212"
38
+ },
39
+ "files": [
40
+ "dist",
41
+ "CHANGELOG.md"
42
+ ],
43
+ "homepage": "https://mastra.ai",
44
+ "repository": {
45
+ "type": "git",
46
+ "url": "git+https://github.com/mastra-ai/mastra.git",
47
+ "directory": "workspaces/mesa"
48
+ },
49
+ "bugs": {
50
+ "url": "https://github.com/mastra-ai/mastra/issues"
51
+ },
52
+ "engines": {
53
+ "node": ">=22.13.0"
54
+ },
55
+ "scripts": {
56
+ "build": "tsup --silent --config tsup.config.ts",
57
+ "build:lib": "pnpm build",
58
+ "build:watch": "pnpm build --watch",
59
+ "test:unit": "vitest run --exclude '**/*.integration.test.ts'",
60
+ "test:watch": "vitest watch",
61
+ "test": "pnpm test:unit",
62
+ "test:cloud": "vitest run ./src/**/*.integration.test.ts",
63
+ "lint": "eslint ."
64
+ }
65
+ }