@mastra/platform-workspace 1.11.1-alpha.0 → 1.12.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/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { PlatformClient, PlatformApiError, type PlatformClientOptions, type PlatformProxyError, type SandboxProvider, } from './client.js';
2
2
  export { PlatformFilesystem, type PlatformFilesystemOptions } from './filesystem.js';
3
3
  export { Template, type AptInstallOptions, type JsonPrimitive, type JsonValue, type NpmInstallOptions, type PipInstallOptions, type SandboxTemplateBuildOptions, type SandboxTemplateBuildResult, type SandboxTemplateBuilder, type SandboxTemplateMethod, type SetEnvsOptions, type SandboxTemplateOperation, type SerializedSandboxTemplate, } from './template.js';
4
- export { PlatformSandbox, SandboxExecTransportError, SandboxDestroyedError, type PlatformSandboxOptions, type PlatformSandboxNetworkIsolation, type PlatformSandboxTemplate, type SandboxAddressRegistry, type SandboxTemplatePending, } from './sandbox.js';
4
+ export { PlatformSandbox, SandboxExecTransportError, SandboxDestroyedError, type PlatformSandboxOptions, type PlatformSandboxNetworkIsolation, type PlatformSandboxTemplate, type SandboxAddressRegistry, type SandboxPortAuthCookie, type SandboxTemplatePending, } from './sandbox.js';
5
5
  export { createRepoTemplate, type PlatformRepoTemplateOptions, type PlatformRepoTemplateRepository, type PlatformRepoTemplateResolver, } from './repo-template.js';
6
6
  export { PlatformSandboxFilesystem } from './sandbox-filesystem.js';
7
7
  export { platformFilesystemProvider, platformSandboxProvider } from './provider.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,eAAe,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAE,KAAK,yBAAyB,EAAE,MAAM,iBAAiB,CAAC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B,CAAC;AACrF,OAAO,EACL,QAAQ,EACR,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,2BAA2B,EAChC,KAAK,0BAA0B,EAC/B,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,cAAc,EACnB,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,GAC/B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,eAAe,EACf,yBAAyB,EACzB,qBAAqB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,+BAA+B,EACpC,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,GAC5B,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,kBAAkB,EAClB,KAAK,2BAA2B,EAChC,KAAK,8BAA8B,EACnC,KAAK,4BAA4B,GAClC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACpF,OAAO,EACL,sBAAsB,EACtB,KAAK,6BAA6B,EAClC,KAAK,8BAA8B,GACpC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,eAAe,GACrB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,+BAA+B,EAAE,MAAM,uBAAuB,CAAC"}
package/dist/index.js CHANGED
@@ -1028,6 +1028,20 @@ var FilesApiFilesystem = class extends MastraFilesystem {
1028
1028
  throw new Error(`${operation} ${subject} failed (exit ${result.exitCode}): ${result.stderr.trim()}`);
1029
1029
  }
1030
1030
  };
1031
+ const KILL_DESCENDANTS_TIMEOUT_MS = 1e4;
1032
+ /**
1033
+ * A shell command that kills every process `pid` started, at any depth, but
1034
+ * not `pid` itself. It pauses `pid` first: a wrapper like npm exits on its own
1035
+ * once its child dies, and `kill(pid)` would then report it wasn't running.
1036
+ */
1037
+ function killDescendants(pid) {
1038
+ return [
1039
+ `kill -STOP ${pid}`,
1040
+ "kill_children() { for child in $(pgrep -P \"$1\"); do kill -STOP \"$child\"; (kill_children \"$child\"); kill -KILL \"$child\"; done; }",
1041
+ `kill_children ${pid}`,
1042
+ "true"
1043
+ ].join("\n");
1044
+ }
1031
1045
  /**
1032
1046
  * Output callbacks for `run`/`connect` that hold output until the handle
1033
1047
  * exists. The SDK's handle reads events from construction, before `run()`
@@ -1130,7 +1144,16 @@ var CommandsApiProcessHandle = class extends ProcessHandle {
1130
1144
  }
1131
1145
  async kill() {
1132
1146
  if (this.exitCode !== void 0) return false;
1133
- return this.manager.runCommands("kill", (commands) => commands.kill(this.inner.pid));
1147
+ return this.manager.runCommands("kill", async (commands) => {
1148
+ try {
1149
+ await (await commands.run(killDescendants(this.inner.pid), {
1150
+ background: true,
1151
+ stdin: false,
1152
+ timeoutMs: KILL_DESCENDANTS_TIMEOUT_MS
1153
+ })).wait();
1154
+ } catch {}
1155
+ return commands.kill(this.inner.pid);
1156
+ });
1134
1157
  }
1135
1158
  async sendStdin(data) {
1136
1159
  if (this.exitCode !== void 0) throw new Error(`Process ${this.pid} has already exited with code ${this.exitCode}`);
@@ -1710,6 +1733,8 @@ var SandboxExecTransportError = class extends Error {
1710
1733
  this.wsEndpoint = diagnostics.wsEndpoint;
1711
1734
  }
1712
1735
  };
1736
+ /** E2B's sandbox control port (envd). Never a preview. */
1737
+ const E2B_CONTROL_PORT = 49983;
1713
1738
  /**
1714
1739
  * Thrown when `/exec-lease` returns 410 Gone — the sandbox has been destroyed
1715
1740
  * (Railway destroy, quota reclamation, etc.). The client cannot recover from
@@ -1899,6 +1924,41 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
1899
1924
  get sandboxId() {
1900
1925
  return this.status === "running" ? this._sandboxId : void 0;
1901
1926
  }
1927
+ _networking = { getPortUrl: async (port) => (await this._previewGrant(port))?.url ?? null };
1928
+ /**
1929
+ * A cookie that signs a browser you control, such as an agent's own
1930
+ * browser, in to a port for an hour, so it opens the port's URL without
1931
+ * signing in. Never share it.
1932
+ *
1933
+ * `null` in the same cases as `networking.getPortUrl()`.
1934
+ */
1935
+ async getPortAuthCookie(port) {
1936
+ return (await this._previewGrant(port))?.cookie ?? null;
1937
+ }
1938
+ async _previewGrant(port) {
1939
+ if (!Number.isInteger(port) || port < 1 || port > 65535 || port === E2B_CONTROL_PORT) return null;
1940
+ if (this._client.sandboxProvider !== "e2b") return null;
1941
+ const sandboxId = this.sandboxId;
1942
+ if (!sandboxId) return null;
1943
+ try {
1944
+ const { url, cookie } = await (await this._request(`/sandbox/${encodeURIComponent(sandboxId)}/preview-grants`, {
1945
+ method: "POST",
1946
+ headers: { "content-type": "application/json" },
1947
+ body: JSON.stringify({ port })
1948
+ })).json();
1949
+ return {
1950
+ url: `${new URL(url).origin}/`,
1951
+ cookie
1952
+ };
1953
+ } catch (error) {
1954
+ if (error instanceof PlatformApiError && error.status === 410) {
1955
+ if (this._sandboxId === sandboxId) this._clearDestroyedState(sandboxId);
1956
+ return null;
1957
+ }
1958
+ if (error instanceof PlatformApiError && error.status === 404) return null;
1959
+ throw error;
1960
+ }
1961
+ }
1902
1962
  _client;
1903
1963
  _usesProviderRoutes;
1904
1964
  _environmentId;
@@ -1999,6 +2059,7 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
1999
2059
  this._hasRecoveryKey = options.id !== void 0;
2000
2060
  this.id = options.id ?? this.generateId();
2001
2061
  this._client = new PlatformClient(options);
2062
+ if (this._client.sandboxProvider === "e2b") this.networking = this._networking;
2002
2063
  this._environmentId = options.environmentId ?? process.env.MASTRA_ENVIRONMENT_ID ?? "";
2003
2064
  if (!this._environmentId && !options.sandboxId) throw new Error("environmentId is required");
2004
2065
  this._sandboxId = options.sandboxId;