@mastra/platform-workspace 1.6.1 → 1.6.2

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/dist/index.js CHANGED
@@ -302,11 +302,7 @@ var PlatformFilesystem = class extends MastraFilesystem {
302
302
  }
303
303
  async readdir(path, options) {
304
304
  await this.ensureReady();
305
- const prefix = keyFromPath(path);
306
- const json = await (await this._client.request(`/fs/${encodeURIComponent(this._bucketName)}/${encodeKeyPath(prefix)}`, { query: {
307
- delimiter: options?.recursive ? void 0 : "/",
308
- prefix: prefix ? `${prefix.replace(/\/$/, "")}/` : void 0
309
- } })).json();
305
+ const json = await this.listPrefix(keyFromPath(path), options?.recursive);
310
306
  return [...(json.commonPrefixes ?? []).map((prefix) => ({
311
307
  name: nameFromPath(prefix.replace(/\/$/, "")),
312
308
  type: "directory"
@@ -316,6 +312,13 @@ var PlatformFilesystem = class extends MastraFilesystem {
316
312
  size: object.size
317
313
  }))].filter((entry) => !options?.extension || entry.type === "directory" || matchesExtension(entry.name, options.extension));
318
314
  }
315
+ async listPrefix(prefix, recursive) {
316
+ const normalized = prefix.replace(/\/$/, "");
317
+ return await (await this._client.request(`/fs/${encodeURIComponent(this._bucketName)}/`, { query: {
318
+ delimiter: recursive ? void 0 : "/",
319
+ prefix: normalized ? `${normalized}/` : void 0
320
+ } })).json();
321
+ }
319
322
  async exists(path) {
320
323
  try {
321
324
  await this.stat(path);
@@ -340,8 +343,17 @@ var PlatformFilesystem = class extends MastraFilesystem {
340
343
  try {
341
344
  response = await this._client.request(`/fs/${encodeURIComponent(this._bucketName)}/${encodeKeyPath(keyFromPath(path))}`, { method: "HEAD" });
342
345
  } catch (error) {
343
- if (isNotFound(error)) throw new FileNotFoundError(path);
344
- throw error;
346
+ if (!isNotFound(error)) throw error;
347
+ const listing = await this.listPrefix(keyFromPath(path));
348
+ if (!listing.contents?.length && !listing.commonPrefixes?.length) throw new FileNotFoundError(path);
349
+ return {
350
+ name: nameFromPath(path),
351
+ path: normalized,
352
+ type: "directory",
353
+ size: 0,
354
+ createdAt: /* @__PURE__ */ new Date(0),
355
+ modifiedAt: /* @__PURE__ */ new Date(0)
356
+ };
345
357
  }
346
358
  return {
347
359
  name: nameFromPath(path),