@mastra/platform-workspace 0.2.3 → 0.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/dist/sandbox.d.ts CHANGED
@@ -21,6 +21,55 @@ export interface PlatformSandboxOptions extends Omit<MastraSandboxOptions, 'proc
21
21
  */
22
22
  webSocketFactory?: DirectExecWebSocketFactory;
23
23
  }
24
+ /**
25
+ * Diagnostic error thrown when the direct-exec WebSocket transport fails
26
+ * twice in a row (opening handshake refused or socket closed mid-stream
27
+ * without an `exit` frame). Distinguishes "the sandbox transport is broken"
28
+ * from "your command failed" so callers can decide whether to retry at a
29
+ * higher level (e.g. reprovision the sandbox) or surface the error.
30
+ *
31
+ * `opened` is `true` when the WebSocket completed its handshake at least
32
+ * once before closing; `false` when Railway refused the upgrade outright.
33
+ */
34
+ export declare class SandboxExecTransportError extends Error {
35
+ readonly sandboxId: string | undefined;
36
+ readonly command: string;
37
+ readonly attempts: number;
38
+ readonly opened: boolean;
39
+ readonly closeCode: number | undefined;
40
+ readonly closeReason: string | undefined;
41
+ readonly wsEndpoint: string;
42
+ constructor(message: string, diagnostics: {
43
+ sandboxId?: string;
44
+ command: string;
45
+ attempts: number;
46
+ opened: boolean;
47
+ closeCode?: number;
48
+ closeReason?: string;
49
+ wsEndpoint: string;
50
+ });
51
+ }
52
+ /**
53
+ * Thrown when `/exec-lease` returns 410 Gone — the sandbox has been destroyed
54
+ * (Railway destroy, quota reclamation, etc.). The client cannot recover from
55
+ * this on its own because it does not own the binding store; only the fleet
56
+ * layer can clear the stale sandbox id and provision a fresh one. Callers
57
+ * (typically `SandboxFleet`) must catch this and reprovision-and-replay.
58
+ *
59
+ * When this is thrown the cached `_lease` and `_sandboxId` on the sandbox
60
+ * instance are cleared, so the next `ensureRunning()` on a reused instance
61
+ * will re-provision cleanly.
62
+ */
63
+ export declare class SandboxDestroyedError extends Error {
64
+ readonly sandboxId: string | undefined;
65
+ readonly command: string;
66
+ readonly attempts: number;
67
+ constructor(message: string, diagnostics: {
68
+ sandboxId?: string;
69
+ command: string;
70
+ attempts: number;
71
+ });
72
+ }
24
73
  declare class PlatformProcessManager extends SandboxProcessManager<PlatformSandbox> {
25
74
  private spawnCounter;
26
75
  /**
@@ -63,16 +112,6 @@ export declare class PlatformSandbox extends MastraSandbox {
63
112
  * Cleared (regardless of success or failure) when the request settles.
64
113
  */
65
114
  private _leaseInFlight;
66
- /**
67
- * Tri-state feature detection for the platform's exec-lease endpoint:
68
- * undefined — not yet tried (default; try direct on first exec)
69
- * true — endpoint present, use direct exec
70
- * false — endpoint absent (404/501) OR the WebSocket transport failed
71
- * once; fall back permanently to /exec for this sandbox
72
- * Sticky per instance so we make the fallback decision once per sandbox
73
- * lifetime instead of paying an extra round-trip on every exec.
74
- */
75
- private _directExecAvailable;
76
115
  constructor(options?: PlatformSandboxOptions);
77
116
  private generateId;
78
117
  /**
@@ -109,8 +148,28 @@ export declare class PlatformSandbox extends MastraSandbox {
109
148
  * execution on the remote sandbox.
110
149
  */
111
150
  executeCommand(command: string, args?: string[], options?: ExecuteCommandOptions): Promise<CommandResult>;
112
- private _tryDirectExec;
113
- private _execViaProxy;
151
+ /**
152
+ * Run a single exec against the direct-exec transport, with one in-flight
153
+ * retry on WebSocket transport failure (socket closed without an `exit`
154
+ * frame and the exec did not time out). The retry mints a fresh lease
155
+ * — the failure could be a stale JWT — and reopens a new WebSocket.
156
+ *
157
+ * Error taxonomy:
158
+ * - **410 on `/exec-lease`** (either attempt) → the sandbox is gone.
159
+ * Nulls the cached `_lease` and `_sandboxId` and throws
160
+ * {@link SandboxDestroyedError}. Callers (typically `SandboxFleet`) must
161
+ * catch this, clear the stale binding, and reprovision + replay.
162
+ * - **Persistent transport failure** (both WS attempts close without an
163
+ * `exit` frame against a live sandbox) → {@link SandboxExecTransportError}
164
+ * with WebSocket close diagnostics.
165
+ * - **Other `PlatformApiError`s** (404/500/501) propagate directly.
166
+ * - **Real command result** (exit code from Railway's exit frame, or
167
+ * `timedOut: true`) returns normally.
168
+ *
169
+ * Returns a result with a real `exitCode` OR `timedOut: true`. Never
170
+ * returns `{ exitCode: null, timedOut: false }` — that case throws.
171
+ */
172
+ private _runDirectExec;
114
173
  /**
115
174
  * Return a cached exec lease, minting a fresh one when the cache is empty
116
175
  * or the JWT is within {@link LEASE_REFRESH_MARGIN_MS} of `expiresAt`.
@@ -1 +1 @@
1
- {"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../src/sandbox.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EACV,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,oBAAoB,EACpB,WAAW,EACX,cAAc,EACd,mBAAmB,EACnB,WAAW,EACX,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAwB,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AACnH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEzD,OAAO,KAAK,EAAE,0BAA0B,EAAa,MAAM,kBAAkB,CAAC;AAG9E,MAAM,MAAM,+BAA+B,GAAG,UAAU,GAAG,SAAS,CAAC;AAErE,MAAM,WAAW,sBAAuB,SAAQ,IAAI,CAAC,oBAAoB,EAAE,WAAW,CAAC,EAAE,qBAAqB;IAC5G,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,gBAAgB,CAAC,EAAE,+BAA+B,CAAC;IACnD,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAClC;;;;;OAKG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,KAAK,CAAC,OAAO,GAAE,mBAAwB,GAAG,eAAe;IAwBnD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAyDtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAY9B;;;;;;;;;;;;;;;;OAgBG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,aAAa,CAAC;IAqC/G;;;;;;;;;;;;;;;;;;;;OAoBG;YACW,cAAc;IA+F5B;;;;;;OAMG;YACW,YAAY;IA0CpB,OAAO,IAAI,OAAO,CAAC,WAAW,CAAC;IA+BrC,eAAe,CAAC,IAAI,CAAC,EAAE;QAAE,cAAc,CAAC,EAAE,cAAc,CAAA;KAAE,GAAG,MAAM;CAQpE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/platform-workspace",
3
- "version": "0.2.3",
3
+ "version": "0.3.0-alpha.1",
4
4
  "description": "Mastra Platform workspace sandbox and filesystem providers",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -29,7 +29,7 @@
29
29
  "vitest": "4.1.10",
30
30
  "@internal/lint": "0.0.119",
31
31
  "@internal/types-builder": "0.0.94",
32
- "@mastra/core": "1.55.0"
32
+ "@mastra/core": "1.56.0-alpha.3"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "@mastra/core": ">=1.4.0-0 <2.0.0-0"