@mastra/platform-workspace 1.2.1 → 1.3.0-alpha.1
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 +31 -0
- package/dist/index.cjs +39 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +40 -7
- package/dist/index.js.map +1 -1
- package/dist/sandbox.d.ts +13 -4
- 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 } from "buffer";
|
|
2
2
|
import nodePath from "path";
|
|
3
|
-
import { FileExistsError, FileNotFoundError, MastraFilesystem, MastraSandbox, ProcessHandle, SandboxNotReadyError, SandboxProcessManager, WorkspaceReadOnlyError } from "@mastra/core/workspace";
|
|
3
|
+
import { FileExistsError, FileNotFoundError, MastraFilesystem, MastraSandbox, ProcessHandle, SandboxNotReadyError, SandboxProcessManager, UnsupportedStdinCloseError, WorkspaceReadOnlyError } from "@mastra/core/workspace";
|
|
4
4
|
//#region src/client.ts
|
|
5
5
|
const DEFAULT_PROXY_URL = "https://workspaces.mastra.ai";
|
|
6
6
|
/**
|
|
@@ -800,6 +800,9 @@ var PlatformProcessHandle = class extends ProcessHandle {
|
|
|
800
800
|
async sendStdin() {
|
|
801
801
|
throw new Error("Platform sandbox command execution does not support stdin");
|
|
802
802
|
}
|
|
803
|
+
async closeStdin() {
|
|
804
|
+
throw new UnsupportedStdinCloseError("Platform sandbox command execution does not support closing stdin");
|
|
805
|
+
}
|
|
803
806
|
};
|
|
804
807
|
var PlatformProcessManager = class extends SandboxProcessManager {
|
|
805
808
|
spawnCounter = 0;
|
|
@@ -911,6 +914,12 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
|
|
|
911
914
|
* failed/timed out, but now coalesced via `_leaseInFlight`).
|
|
912
915
|
*/
|
|
913
916
|
_transportReadyPromise = null;
|
|
917
|
+
/**
|
|
918
|
+
* The sidecar address of the most recent `start()`, kept so a timed-out
|
|
919
|
+
* probe can be restarted by a later exec ({@link _awaitTransportReady})
|
|
920
|
+
* instead of pinning the sandbox to the lease path for its lifetime.
|
|
921
|
+
*/
|
|
922
|
+
_probeTarget = null;
|
|
914
923
|
constructor(options = {}) {
|
|
915
924
|
super({
|
|
916
925
|
...options,
|
|
@@ -1063,14 +1072,24 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
|
|
|
1063
1072
|
* HTTP round-trip.
|
|
1064
1073
|
*
|
|
1065
1074
|
* `null`/absent `instanceUrl` (proxy discovery failed, or an older proxy
|
|
1066
|
-
* that predates the field)
|
|
1067
|
-
*
|
|
1075
|
+
* that predates the field) evicts any stale registry address and leaves
|
|
1076
|
+
* executes on the lease path.
|
|
1068
1077
|
*/
|
|
1069
1078
|
_populateAddressFromResponse(json) {
|
|
1070
1079
|
if (!this._addressRegistry) return;
|
|
1071
|
-
if (!json.instanceUrl)
|
|
1080
|
+
if (!json.instanceUrl) {
|
|
1081
|
+
this._probeGeneration++;
|
|
1082
|
+
this._probeTarget = null;
|
|
1083
|
+
this._transportReadyPromise = null;
|
|
1084
|
+
this._addressRegistry.delete(json.id);
|
|
1085
|
+
return;
|
|
1086
|
+
}
|
|
1072
1087
|
this._addressRegistry.delete(json.id);
|
|
1073
1088
|
const generation = ++this._probeGeneration;
|
|
1089
|
+
this._probeTarget = {
|
|
1090
|
+
sandboxId: json.id,
|
|
1091
|
+
instanceUrl: json.instanceUrl
|
|
1092
|
+
};
|
|
1074
1093
|
this._transportReadyPromise = this._probeSidecarThenRegister(json.id, json.instanceUrl, generation);
|
|
1075
1094
|
}
|
|
1076
1095
|
/**
|
|
@@ -1080,8 +1099,9 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
|
|
|
1080
1099
|
* fall back to the lease path until the probe succeeds.
|
|
1081
1100
|
*
|
|
1082
1101
|
* If the sidecar never comes up within {@link SIDECAR_PROBE_TIMEOUT_MS},
|
|
1083
|
-
* the registry stays unpopulated
|
|
1084
|
-
*
|
|
1102
|
+
* the registry stays unpopulated, `_transportReadyPromise` is cleared,
|
|
1103
|
+
* and a later {@link _awaitTransportReady} call restarts the probe
|
|
1104
|
+
* instead of pinning this sandbox to the lease path.
|
|
1085
1105
|
*
|
|
1086
1106
|
* @param generation - The probe generation captured at call time. If this
|
|
1087
1107
|
* no longer matches `_probeGeneration` when the probe succeeds, the probe
|
|
@@ -1115,6 +1135,7 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
|
|
|
1115
1135
|
} catch {}
|
|
1116
1136
|
await new Promise((r) => setTimeout(r, SIDECAR_PROBE_INTERVAL_MS));
|
|
1117
1137
|
}
|
|
1138
|
+
if (generation === this._probeGeneration && this._transportReadyPromise) this._transportReadyPromise = null;
|
|
1118
1139
|
this.logger.warn("platform-workspace probe timed out", {
|
|
1119
1140
|
sandboxId,
|
|
1120
1141
|
sessionId: this._client.sessionId,
|
|
@@ -1135,7 +1156,12 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
|
|
|
1135
1156
|
*/
|
|
1136
1157
|
async _awaitTransportReady() {
|
|
1137
1158
|
if (this._sandboxId && this._addressRegistry?.get(this._sandboxId)) return;
|
|
1138
|
-
if (!this._transportReadyPromise)
|
|
1159
|
+
if (!this._transportReadyPromise) {
|
|
1160
|
+
const target = this._probeTarget;
|
|
1161
|
+
if (!target || this._sandboxId !== target.sandboxId) return;
|
|
1162
|
+
const generation = ++this._probeGeneration;
|
|
1163
|
+
this._transportReadyPromise = this._probeSidecarThenRegister(target.sandboxId, target.instanceUrl, generation);
|
|
1164
|
+
}
|
|
1139
1165
|
await Promise.race([this._transportReadyPromise, new Promise((r) => setTimeout(r, TRANSPORT_READY_WAIT_MS))]);
|
|
1140
1166
|
}
|
|
1141
1167
|
/**
|
|
@@ -1202,6 +1228,8 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
|
|
|
1202
1228
|
if (!this._sandboxId) return;
|
|
1203
1229
|
const destroyedSandboxId = this._sandboxId;
|
|
1204
1230
|
this._probeGeneration++;
|
|
1231
|
+
this._probeTarget = null;
|
|
1232
|
+
this._transportReadyPromise = null;
|
|
1205
1233
|
await this._client.request(`/sandbox/${encodeURIComponent(destroyedSandboxId)}`, { method: "DELETE" });
|
|
1206
1234
|
this._sandboxId = void 0;
|
|
1207
1235
|
this._createdAt = null;
|
|
@@ -1212,6 +1240,8 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
|
|
|
1212
1240
|
async snapshot() {
|
|
1213
1241
|
await this.captureCheckpoint();
|
|
1214
1242
|
}
|
|
1243
|
+
/** Snapshots persist real checkpoints that can seed future sandboxes. */
|
|
1244
|
+
supportsCheckpoints = true;
|
|
1215
1245
|
/**
|
|
1216
1246
|
* Capture the sandbox's checkpoint on demand, outside any refresh timer the
|
|
1217
1247
|
* workspace-proxy owns internally.
|
|
@@ -1331,6 +1361,9 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
|
|
|
1331
1361
|
* the cached `'running'` state (see `MastraSandbox._start`).
|
|
1332
1362
|
*/
|
|
1333
1363
|
_clearDestroyedState(destroyedSandboxId) {
|
|
1364
|
+
this._probeGeneration++;
|
|
1365
|
+
this._probeTarget = null;
|
|
1366
|
+
this._transportReadyPromise = null;
|
|
1334
1367
|
this._sandboxId = void 0;
|
|
1335
1368
|
this._createdAt = null;
|
|
1336
1369
|
this._lease = null;
|