@mastra/platform-workspace 0.2.1 → 0.2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # @mastra/platform
2
2
 
3
+ ## 0.2.2
4
+
5
+ ### Patch Changes
6
+
7
+ - **Added:** Direct exec data plane for `PlatformSandbox`. ([#20326](https://github.com/mastra-ai/mastra/pull/20326))
8
+
9
+ Commands now execute against Railway's WebSocket endpoint directly using a short-lived JWT lease minted by the workspace proxy, instead of proxying every exec through the HTTP proxy. This removes the workspace proxy from the exec hot path — cutting latency for large-payload commands (e.g. `pnpm install`) and eliminating duplicated observability spans.
10
+
11
+ The change is transparent: `executeCommand` still returns the same `CommandResult` shape. If the proxy's `/exec-lease` endpoint is unavailable (older deployments), the client automatically falls back to the legacy `POST /sandbox/:id/exec` route for the lifetime of the sandbox.
12
+
13
+ - Fixed platform sandbox reattach and made provisioning resilient to transient proxy failures: ([#20294](https://github.com/mastra-ai/mastra/pull/20294))
14
+
15
+ - The workspace proxy assigns its own sandbox id on create (the advisory id in the request body is not honored), but `getInfo()` never exposed it, so callers persisting a reattach id (e.g. the Factory sandbox fleet, which reads `metadata.sandboxId`) stored the locally generated construction id instead. Every reattach then 404'd and each session open provisioned a brand-new sandbox and re-cloned the repository. `getInfo()` now reports the platform-assigned id in `metadata.sandboxId`, and `start()` treats a sandbox record with `destroyedAt` set as gone (falls through to a fresh provision) instead of pointing exec at a dead resource.
16
+ - Sandbox creation retries transient workspace-proxy 5xx responses with a short backoff. Provisioning intermittently fails with proxy 500s while the provider is under load; a retry keeps a single flaky window from failing the caller's whole workflow (e.g. Factory kickoff runs). Non-transient errors (4xx) still fail immediately.
17
+
18
+ - Updated dependencies [[`ce93a3c`](https://github.com/mastra-ai/mastra/commit/ce93a3c114ea1cbfbd576f3db41d7c26c9844f5b), [`5718a22`](https://github.com/mastra-ai/mastra/commit/5718a229281dcfd36bcd1f42a242e3717e510a33), [`a211d09`](https://github.com/mastra-ai/mastra/commit/a211d09185dc65a746534914cf38b67f21ee9bac), [`0dca9d0`](https://github.com/mastra-ai/mastra/commit/0dca9d0b1356024a53b72ea6f040db528b126caa), [`6218217`](https://github.com/mastra-ai/mastra/commit/62182171b6cfca0b099f1c6a77a2e65e7639ab86), [`5807d3a`](https://github.com/mastra-ai/mastra/commit/5807d3ae1d259b8b7d6df7e5bf2b485c694af9c8), [`57661af`](https://github.com/mastra-ai/mastra/commit/57661afeca52ff9af4e72675ede2134fa503d5a5), [`05db566`](https://github.com/mastra-ai/mastra/commit/05db566fcbdcbf33d0bffca0c72ec30129e2e3ca), [`57661af`](https://github.com/mastra-ai/mastra/commit/57661afeca52ff9af4e72675ede2134fa503d5a5), [`57661af`](https://github.com/mastra-ai/mastra/commit/57661afeca52ff9af4e72675ede2134fa503d5a5), [`5718a22`](https://github.com/mastra-ai/mastra/commit/5718a229281dcfd36bcd1f42a242e3717e510a33), [`57661af`](https://github.com/mastra-ai/mastra/commit/57661afeca52ff9af4e72675ede2134fa503d5a5), [`d1b7e3a`](https://github.com/mastra-ai/mastra/commit/d1b7e3a978a309a5653eeaa490d2d6c7c53bd093), [`29c584a`](https://github.com/mastra-ai/mastra/commit/29c584a13a88831e5ed1fdeb0ff8e82eae180433), [`c093146`](https://github.com/mastra-ai/mastra/commit/c0931466404d3c521308ea119cb165bb7e695155), [`8124754`](https://github.com/mastra-ai/mastra/commit/8124754ae89fbc69f8136d1df4a91904d0f84c4e), [`d12b2e4`](https://github.com/mastra-ai/mastra/commit/d12b2e4023fd9e3d3e93a9169f5088bcee2a849c)]:
19
+ - @mastra/core@1.54.0
20
+
21
+ ## 0.2.2-alpha.0
22
+
23
+ ### Patch Changes
24
+
25
+ - Fixed platform sandbox reattach and made provisioning resilient to transient proxy failures: ([#20294](https://github.com/mastra-ai/mastra/pull/20294))
26
+
27
+ - The workspace proxy assigns its own sandbox id on create (the advisory id in the request body is not honored), but `getInfo()` never exposed it, so callers persisting a reattach id (e.g. the Factory sandbox fleet, which reads `metadata.sandboxId`) stored the locally generated construction id instead. Every reattach then 404'd and each session open provisioned a brand-new sandbox and re-cloned the repository. `getInfo()` now reports the platform-assigned id in `metadata.sandboxId`, and `start()` treats a sandbox record with `destroyedAt` set as gone (falls through to a fresh provision) instead of pointing exec at a dead resource.
28
+ - Sandbox creation retries transient workspace-proxy 5xx responses with a short backoff. Provisioning intermittently fails with proxy 500s while the provider is under load; a retry keeps a single flaky window from failing the caller's whole workflow (e.g. Factory kickoff runs). Non-transient errors (4xx) still fail immediately.
29
+
30
+ - Updated dependencies [[`6218217`](https://github.com/mastra-ai/mastra/commit/62182171b6cfca0b099f1c6a77a2e65e7639ab86), [`d12b2e4`](https://github.com/mastra-ai/mastra/commit/d12b2e4023fd9e3d3e93a9169f5088bcee2a849c)]:
31
+ - @mastra/core@1.54.0-alpha.4
32
+
3
33
  ## 0.2.1
4
34
 
5
35
  ### Patch Changes
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Direct exec client — opens Railway's tcp-proxy exec WebSocket directly using
3
+ * a short-lived JWT minted by the workspace proxy's exec-lease endpoint. This
4
+ * removes the platform data plane from the exec stdout/stderr path entirely
5
+ * (see `docs/factory/direct-sandbox-connection.md` in the Platform repo),
6
+ * cutting payload-scaled Cloud Run egress and RTT for commands like
7
+ * `pnpm install` that stream tens of MB of output.
8
+ *
9
+ * The frame protocol below mirrors `connectExecWs()` in `railway@3.5.5`
10
+ * (`workspaces/railway/node_modules/railway/dist/index.js`). The `railway`
11
+ * SDK's version is pinned on both sides (platform + here); a version bump
12
+ * signals the protocol may have drifted and this module must be revisited.
13
+ */
14
+ /**
15
+ * Minimal WebSocket surface this module depends on. Matches both the browser
16
+ * `WebSocket` global and Node 22+'s built-in `WebSocket`. Extracted so tests
17
+ * can inject a fake without pulling in `ws` or jsdom.
18
+ */
19
+ export interface DirectExecWebSocket {
20
+ binaryType: 'blob' | 'arraybuffer';
21
+ onopen: ((event: unknown) => void) | null;
22
+ onmessage: ((event: {
23
+ data: unknown;
24
+ }) => void) | null;
25
+ onclose: ((event: {
26
+ code: number;
27
+ reason: string;
28
+ }) => void) | null;
29
+ onerror: ((event: unknown) => void) | null;
30
+ send(data: string): void;
31
+ close(code?: number, reason?: string): void;
32
+ }
33
+ /**
34
+ * Factory that opens a WebSocket to `endpoint` with the given subprotocols.
35
+ * Defaults to the global `WebSocket` when omitted, which works on Node 22+
36
+ * (the package's minimum) and in the browser. Tests inject a fake here.
37
+ */
38
+ export type DirectExecWebSocketFactory = (endpoint: string, subprotocols: string[]) => DirectExecWebSocket;
39
+ /** Lease payload returned by `POST /v1/projects/:projectId/sandbox/:sandboxId/exec-lease`. */
40
+ export interface ExecLease {
41
+ jwt: string;
42
+ wsEndpoint: string;
43
+ subprotocol: string;
44
+ /** ISO-8601 UTC. Null when the provider issues a JWT without an `exp` claim. */
45
+ expiresAt: string | null;
46
+ }
47
+ /** Inputs to a direct exec invocation. Mirrors the shape of the `/exec` route body. */
48
+ export interface DirectExecOptions {
49
+ command: string;
50
+ cwd?: string;
51
+ env?: Record<string, string>;
52
+ /**
53
+ * Wall-clock cap for the exec. When elapsed, we close the socket and
54
+ * return `{timedOut: true, exitCode: 124}` matching the semantics of the
55
+ * proxy's `/exec` route.
56
+ */
57
+ timeoutMs?: number;
58
+ onStdout?: (chunk: string) => void;
59
+ onStderr?: (chunk: string) => void;
60
+ /** Injected for tests. Defaults to `globalThis.WebSocket`. */
61
+ webSocketFactory?: DirectExecWebSocketFactory;
62
+ }
63
+ /**
64
+ * Result of a direct exec. Shape matches the workspace-proxy `/exec` response
65
+ * so the caller (`PlatformSandbox.executeCommand`) can hand it back with no
66
+ * translation.
67
+ *
68
+ * `exitCode` is `null` when the socket closed without an `exit` frame AND the
69
+ * exec did not time out (rare — usually a mid-stream network drop). Callers
70
+ * currently coerce `null` to `1` upstream; kept nullable here to preserve the
71
+ * distinction for future observability.
72
+ */
73
+ export interface DirectExecResult {
74
+ exitCode: number | null;
75
+ stdout: string;
76
+ stderr: string;
77
+ truncated: boolean;
78
+ timedOut: boolean;
79
+ }
80
+ /**
81
+ * Open the provider exec WebSocket using `lease`, run `command`, and resolve
82
+ * with the accumulated stdout/stderr + exit code. See the module docstring
83
+ * for the wire protocol reference.
84
+ *
85
+ * The client sends `stdin_close` immediately after `init_exec`, matching the
86
+ * SDK's own one-shot exec behavior — we never stream stdin from the caller.
87
+ */
88
+ export declare function execViaLease(lease: ExecLease, options: DirectExecOptions): Promise<DirectExecResult>;
89
+ //# sourceMappingURL=direct-exec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"direct-exec.d.ts","sourceRoot":"","sources":["../src/direct-exec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAeH;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,GAAG,aAAa,CAAC;IACnC,MAAM,EAAE,CAAC,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IAC1C,SAAS,EAAE,CAAC,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IACvD,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IACpE,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC;IAC3C,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7C;AAED;;;;GAIG;AACH,MAAM,MAAM,0BAA0B,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAA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