@mastra/platform-workspace 1.7.0-alpha.1 → 1.7.0-alpha.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.cjs +15 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/dist/sandbox.d.ts +11 -0
- package/dist/sandbox.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Buffer as Buffer$1 } from "buffer";
|
|
2
2
|
import nodePath from "path";
|
|
3
|
-
import { FileExistsError, FileNotFoundError, MastraFilesystem, MastraSandbox, ProcessHandle, SandboxNotReadyError, SandboxProcessManager, UnsupportedStdinCloseError, WorkspaceReadOnlyError } from "@mastra/core/workspace";
|
|
3
|
+
import { FileExistsError, FileNotFoundError, MastraFilesystem, MastraSandbox, ProcessHandle, SandboxError, SandboxNotReadyError, SandboxProcessManager, UnsupportedStdinCloseError, WorkspaceReadOnlyError } from "@mastra/core/workspace";
|
|
4
4
|
import { CommandExitError, Sandbox, TimeoutError } from "e2b";
|
|
5
5
|
import { execFile } from "child_process";
|
|
6
6
|
import { createHash } from "crypto";
|
|
@@ -1141,6 +1141,7 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
|
|
|
1141
1141
|
_usesProviderRoutes;
|
|
1142
1142
|
_environmentId;
|
|
1143
1143
|
_sandboxId;
|
|
1144
|
+
_reattach;
|
|
1144
1145
|
_seedCheckpointName;
|
|
1145
1146
|
_templateDefinition;
|
|
1146
1147
|
_templateBuildEnvs;
|
|
@@ -1232,6 +1233,7 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
|
|
|
1232
1233
|
this._environmentId = options.environmentId ?? process.env.MASTRA_ENVIRONMENT_ID ?? "";
|
|
1233
1234
|
if (!this._environmentId && !options.sandboxId) throw new Error("environmentId is required");
|
|
1234
1235
|
this._sandboxId = options.sandboxId;
|
|
1236
|
+
this._reattach = options.reattach ?? "best-effort";
|
|
1235
1237
|
this._seedCheckpointName = options.seedCheckpointName;
|
|
1236
1238
|
this._usesProviderRoutes = options.template !== void 0;
|
|
1237
1239
|
this._template = options.template;
|
|
@@ -1248,6 +1250,16 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
|
|
|
1248
1250
|
generateId() {
|
|
1249
1251
|
return `platform-sandbox-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
1250
1252
|
}
|
|
1253
|
+
_failIfReattachRequired(reason, cause) {
|
|
1254
|
+
if (this._reattach !== "required") return;
|
|
1255
|
+
throw new SandboxError(`Platform sandbox ${this._sandboxId} could not be reattached (${reason}); refusing to provision a replacement because reattach is 'required'. Clear the persisted sandboxId to start a fresh sandbox.`, "SANDBOX_REATTACH_FAILED", {
|
|
1256
|
+
provider: "platform",
|
|
1257
|
+
sandboxId: this._sandboxId,
|
|
1258
|
+
logicalId: this.id,
|
|
1259
|
+
reason,
|
|
1260
|
+
...cause !== void 0 && { cause }
|
|
1261
|
+
});
|
|
1262
|
+
}
|
|
1251
1263
|
_request(path, options = {}) {
|
|
1252
1264
|
return this._usesProviderRoutes ? this._client.requestProvider(path, options) : this._client.request(path, options);
|
|
1253
1265
|
}
|
|
@@ -1277,6 +1289,7 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
|
|
|
1277
1289
|
fetch: this._client.fetch,
|
|
1278
1290
|
environmentId: this._environmentId,
|
|
1279
1291
|
...options.sandboxId !== void 0 && { sandboxId: options.sandboxId },
|
|
1292
|
+
reattach: this._reattach,
|
|
1280
1293
|
...seedCheckpointName !== void 0 && { seedCheckpointName },
|
|
1281
1294
|
...this._template !== void 0 && { template: this._template },
|
|
1282
1295
|
idleTimeoutMinutes: options.idleTimeoutMinutes ?? this._idleTimeoutMinutes,
|
|
@@ -1319,9 +1332,11 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
|
|
|
1319
1332
|
this._logStartComplete(json.id, startedAt, requestMs, "reattach");
|
|
1320
1333
|
return { outcome: "connected" };
|
|
1321
1334
|
}
|
|
1335
|
+
this._failIfReattachRequired("destroyed");
|
|
1322
1336
|
this._sandboxId = void 0;
|
|
1323
1337
|
} catch (error) {
|
|
1324
1338
|
if (!(error instanceof PlatformApiError) || error.status !== 404 && error.status !== 410) throw error;
|
|
1339
|
+
this._failIfReattachRequired(String(error.status), error);
|
|
1325
1340
|
this._sandboxId = void 0;
|
|
1326
1341
|
}
|
|
1327
1342
|
if (!this._environmentId) throw new Error("environmentId is required");
|