@mastra/deployer-sandbox 0.1.2 → 0.1.3

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.
@@ -89,7 +89,7 @@
89
89
  connectSSE();
90
90
  })();
91
91
  </script>
92
- <script type="module" crossorigin src="./assets/index-CbYta8Tj.js"></script>
92
+ <script type="module" crossorigin src="./assets/index-sToavS1V.js"></script>
93
93
  <link rel="modulepreload" crossorigin href="./assets/preload-helper-PPVm8Dsz.js">
94
94
  <link rel="stylesheet" crossorigin href="./assets/style-BWN25Qlo.css">
95
95
  </head>
@@ -6,6 +6,7 @@
6
6
  "evaluation",
7
7
  "experiments",
8
8
  "integrations",
9
+ "intelligence",
9
10
  "login",
10
11
  "logs",
11
12
  "mcps",
@@ -17,7 +18,6 @@
17
18
  "resources",
18
19
  "scorers",
19
20
  "settings",
20
- "signals",
21
21
  "signup",
22
22
  "templates",
23
23
  "tools",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/deployer-sandbox",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Deploy a Mastra server into any workspace sandbox that supports networking and get a live public URL",
5
5
  "type": "module",
6
6
  "files": [
@@ -38,7 +38,7 @@
38
38
  "license": "Apache-2.0",
39
39
  "dependencies": {
40
40
  "fs-extra": "^11.3.5",
41
- "@mastra/deployer": "^1.53.0"
41
+ "@mastra/deployer": "^1.54.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/fs-extra": "^11.0.4",
@@ -46,13 +46,13 @@
46
46
  "@vitest/coverage-v8": "4.1.10",
47
47
  "@vitest/ui": "4.1.10",
48
48
  "eslint": "^10.4.1",
49
- "tsup": "^8.5.1",
49
+ "tsdown": "0.22.9",
50
50
  "typescript": "^6.0.3",
51
51
  "vitest": "4.1.10",
52
- "@internal/playground": "1.20.2",
53
- "@internal/types-builder": "0.0.92",
54
- "@mastra/core": "1.53.0",
55
- "@internal/lint": "0.0.117"
52
+ "@internal/playground": "1.20.3",
53
+ "@internal/types-builder": "0.0.93",
54
+ "@internal/lint": "0.0.118",
55
+ "@mastra/core": "1.54.0"
56
56
  },
57
57
  "homepage": "https://mastra.ai",
58
58
  "repository": {
@@ -70,8 +70,8 @@
70
70
  "node": ">=22.13.0"
71
71
  },
72
72
  "scripts": {
73
- "build": "tsup --silent --config tsup.config.ts",
74
- "build:watch": "tsup --watch --silent --config tsup.config.ts",
73
+ "build": "tsdown --silent --config tsdown.config.ts",
74
+ "build:watch": "tsdown --watch --silent --config tsdown.config.ts",
75
75
  "test": "vitest run",
76
76
  "lint": "oxlint . && eslint .",
77
77
  "lint:fix": "oxlint --fix . && eslint --fix ."
@@ -1,115 +0,0 @@
1
- 'use strict';
2
-
3
- // src/shared.ts
4
- var REMOTE_DIR_NAME = "mastra-app";
5
- var DEFAULT_PORT = 4111;
6
- var SERVER_SCRIPT = ".mastra-server.sh";
7
- var SERVER_PIDFILE = ".mastra-server.pid";
8
- var SERVER_LOGFILE = ".mastra-server.log";
9
- var INSTALL_MARKER = ".mastra-install-hash";
10
- async function getInfoSafe(sandbox) {
11
- try {
12
- return await sandbox.getInfo?.();
13
- } catch {
14
- return void 0;
15
- }
16
- }
17
- async function resolveRemoteDir(sandbox, remoteDir) {
18
- if (remoteDir) return remoteDir;
19
- const result = await runInSandbox(sandbox, `printf %s "\${HOME:-$(pwd)}"`, { allowFailure: true });
20
- const base = result.stdout.trim();
21
- if (!base) {
22
- throw new Error("Could not resolve the sandbox home directory. Pass `remoteDir` explicitly.");
23
- }
24
- return `${base}/${REMOTE_DIR_NAME}`;
25
- }
26
- function shellQuote(value) {
27
- return `'${value.replace(/'/g, `'\\''`)}'`;
28
- }
29
- async function runInSandbox(sandbox, script, opts) {
30
- if (!sandbox.executeCommand) {
31
- throw new Error(
32
- `Sandbox provider "${sandbox.provider}" does not support executeCommand, which is required for sandbox deploys.`
33
- );
34
- }
35
- const result = await sandbox.executeCommand(
36
- "sh",
37
- ["-c", script],
38
- opts?.timeout ? { timeout: opts.timeout } : void 0
39
- );
40
- if (!result.success && !opts?.allowFailure) {
41
- const what = opts?.label ?? truncate(script, 120);
42
- throw new Error(
43
- `Command failed inside sandbox (exit ${result.exitCode}): ${what}
44
- ${truncate(result.stderr || result.stdout, 4e3)}`
45
- );
46
- }
47
- return { stdout: result.stdout, stderr: result.stderr, exitCode: result.exitCode };
48
- }
49
- function truncate(value, max) {
50
- return value.length > max ? `${value.slice(0, max)}\u2026 (truncated)` : value;
51
- }
52
- async function killPreviousServer(sandbox, remoteDir) {
53
- const pidfile = shellQuote(`${remoteDir}/${SERVER_PIDFILE}`);
54
- const script = [
55
- `if [ -f ${pidfile} ]; then`,
56
- ` pid="$(cat ${pidfile})"`,
57
- ` kill "$pid" 2>/dev/null || true`,
58
- // Wait up to ~5s for the old server to release the port, then force-kill.
59
- ` i=0`,
60
- ` while kill -0 "$pid" 2>/dev/null && [ "$i" -lt 50 ]; do sleep 0.1; i=$((i + 1)); done`,
61
- ` kill -9 "$pid" 2>/dev/null || true`,
62
- ` rm -f ${pidfile}`,
63
- `fi`
64
- ].join("\n");
65
- await runInSandbox(sandbox, script, { allowFailure: true, timeout: 15e3 });
66
- }
67
- async function launchServer(sandbox, remoteDir) {
68
- const script = `${remoteDir}/${SERVER_SCRIPT}`;
69
- await runInSandbox(sandbox, `nohup sh ${shellQuote(script)} >/dev/null 2>&1 & echo launched`);
70
- }
71
- async function tailServerLog(sandbox, remoteDir, lines = 50) {
72
- const logfile = `${remoteDir}/${SERVER_LOGFILE}`;
73
- const result = await runInSandbox(
74
- sandbox,
75
- `tail -n ${Math.floor(lines)} ${shellQuote(logfile)} 2>/dev/null || true`,
76
- {
77
- allowFailure: true
78
- }
79
- );
80
- return result.stdout;
81
- }
82
- async function waitForHealthy(url, opts = {}) {
83
- const path = opts.path ?? "/api";
84
- const timeoutMs = opts.timeoutMs ?? 6e4;
85
- const intervalMs = opts.intervalMs ?? 1e3;
86
- const deadline = Date.now() + timeoutMs;
87
- while (Date.now() < deadline) {
88
- try {
89
- const res = await fetch(new URL(path, url), { signal: AbortSignal.timeout(intervalMs * 5) });
90
- const providerError = res.status === 410 || res.headers.has("x-vercel-error");
91
- if (res.status < 500 && !providerError) {
92
- return true;
93
- }
94
- } catch {
95
- }
96
- await new Promise((resolve) => setTimeout(resolve, intervalMs));
97
- }
98
- return false;
99
- }
100
-
101
- exports.DEFAULT_PORT = DEFAULT_PORT;
102
- exports.INSTALL_MARKER = INSTALL_MARKER;
103
- exports.SERVER_LOGFILE = SERVER_LOGFILE;
104
- exports.SERVER_PIDFILE = SERVER_PIDFILE;
105
- exports.SERVER_SCRIPT = SERVER_SCRIPT;
106
- exports.getInfoSafe = getInfoSafe;
107
- exports.killPreviousServer = killPreviousServer;
108
- exports.launchServer = launchServer;
109
- exports.resolveRemoteDir = resolveRemoteDir;
110
- exports.runInSandbox = runInSandbox;
111
- exports.shellQuote = shellQuote;
112
- exports.tailServerLog = tailServerLog;
113
- exports.waitForHealthy = waitForHealthy;
114
- //# sourceMappingURL=chunk-CSXC6CZL.cjs.map
115
- //# sourceMappingURL=chunk-CSXC6CZL.cjs.map
@@ -1,101 +0,0 @@
1
- // src/shared.ts
2
- var REMOTE_DIR_NAME = "mastra-app";
3
- var DEFAULT_PORT = 4111;
4
- var SERVER_SCRIPT = ".mastra-server.sh";
5
- var SERVER_PIDFILE = ".mastra-server.pid";
6
- var SERVER_LOGFILE = ".mastra-server.log";
7
- var INSTALL_MARKER = ".mastra-install-hash";
8
- async function getInfoSafe(sandbox) {
9
- try {
10
- return await sandbox.getInfo?.();
11
- } catch {
12
- return void 0;
13
- }
14
- }
15
- async function resolveRemoteDir(sandbox, remoteDir) {
16
- if (remoteDir) return remoteDir;
17
- const result = await runInSandbox(sandbox, `printf %s "\${HOME:-$(pwd)}"`, { allowFailure: true });
18
- const base = result.stdout.trim();
19
- if (!base) {
20
- throw new Error("Could not resolve the sandbox home directory. Pass `remoteDir` explicitly.");
21
- }
22
- return `${base}/${REMOTE_DIR_NAME}`;
23
- }
24
- function shellQuote(value) {
25
- return `'${value.replace(/'/g, `'\\''`)}'`;
26
- }
27
- async function runInSandbox(sandbox, script, opts) {
28
- if (!sandbox.executeCommand) {
29
- throw new Error(
30
- `Sandbox provider "${sandbox.provider}" does not support executeCommand, which is required for sandbox deploys.`
31
- );
32
- }
33
- const result = await sandbox.executeCommand(
34
- "sh",
35
- ["-c", script],
36
- opts?.timeout ? { timeout: opts.timeout } : void 0
37
- );
38
- if (!result.success && !opts?.allowFailure) {
39
- const what = opts?.label ?? truncate(script, 120);
40
- throw new Error(
41
- `Command failed inside sandbox (exit ${result.exitCode}): ${what}
42
- ${truncate(result.stderr || result.stdout, 4e3)}`
43
- );
44
- }
45
- return { stdout: result.stdout, stderr: result.stderr, exitCode: result.exitCode };
46
- }
47
- function truncate(value, max) {
48
- return value.length > max ? `${value.slice(0, max)}\u2026 (truncated)` : value;
49
- }
50
- async function killPreviousServer(sandbox, remoteDir) {
51
- const pidfile = shellQuote(`${remoteDir}/${SERVER_PIDFILE}`);
52
- const script = [
53
- `if [ -f ${pidfile} ]; then`,
54
- ` pid="$(cat ${pidfile})"`,
55
- ` kill "$pid" 2>/dev/null || true`,
56
- // Wait up to ~5s for the old server to release the port, then force-kill.
57
- ` i=0`,
58
- ` while kill -0 "$pid" 2>/dev/null && [ "$i" -lt 50 ]; do sleep 0.1; i=$((i + 1)); done`,
59
- ` kill -9 "$pid" 2>/dev/null || true`,
60
- ` rm -f ${pidfile}`,
61
- `fi`
62
- ].join("\n");
63
- await runInSandbox(sandbox, script, { allowFailure: true, timeout: 15e3 });
64
- }
65
- async function launchServer(sandbox, remoteDir) {
66
- const script = `${remoteDir}/${SERVER_SCRIPT}`;
67
- await runInSandbox(sandbox, `nohup sh ${shellQuote(script)} >/dev/null 2>&1 & echo launched`);
68
- }
69
- async function tailServerLog(sandbox, remoteDir, lines = 50) {
70
- const logfile = `${remoteDir}/${SERVER_LOGFILE}`;
71
- const result = await runInSandbox(
72
- sandbox,
73
- `tail -n ${Math.floor(lines)} ${shellQuote(logfile)} 2>/dev/null || true`,
74
- {
75
- allowFailure: true
76
- }
77
- );
78
- return result.stdout;
79
- }
80
- async function waitForHealthy(url, opts = {}) {
81
- const path = opts.path ?? "/api";
82
- const timeoutMs = opts.timeoutMs ?? 6e4;
83
- const intervalMs = opts.intervalMs ?? 1e3;
84
- const deadline = Date.now() + timeoutMs;
85
- while (Date.now() < deadline) {
86
- try {
87
- const res = await fetch(new URL(path, url), { signal: AbortSignal.timeout(intervalMs * 5) });
88
- const providerError = res.status === 410 || res.headers.has("x-vercel-error");
89
- if (res.status < 500 && !providerError) {
90
- return true;
91
- }
92
- } catch {
93
- }
94
- await new Promise((resolve) => setTimeout(resolve, intervalMs));
95
- }
96
- return false;
97
- }
98
-
99
- export { DEFAULT_PORT, INSTALL_MARKER, SERVER_LOGFILE, SERVER_PIDFILE, SERVER_SCRIPT, getInfoSafe, killPreviousServer, launchServer, resolveRemoteDir, runInSandbox, shellQuote, tailServerLog, waitForHealthy };
100
- //# sourceMappingURL=chunk-Z636GNUQ.js.map
101
- //# sourceMappingURL=chunk-Z636GNUQ.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/shared.ts"],"names":[],"mappings":";AAGO,IAAM,eAAA,GAAkB,YAAA;AAExB,IAAM,YAAA,GAAe;AAErB,IAAM,aAAA,GAAgB;AAEtB,IAAM,cAAA,GAAiB;AAEvB,IAAM,cAAA,GAAiB;AAEvB,IAAM,cAAA,GAAiB;AAG9B,eAAsB,YAAY,OAAA,EAA6D;AAC7F,EAAA,IAAI;AACF,IAAA,OAAO,MAAM,QAAQ,OAAA,IAAU;AAAA,EACjC,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,MAAA;AAAA,EACT;AACF;AAQA,eAAsB,gBAAA,CAAiB,SAA2B,SAAA,EAAqC;AACrG,EAAA,IAAI,WAAW,OAAO,SAAA;AACtB,EAAA,MAAM,MAAA,GAAS,M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;AACA,EAAA,OAAO,KAAA;AACT","file":"chunk-Z636GNUQ.js","sourcesContent":["import type { SandboxInfo, WorkspaceSandbox } from '@mastra/core/workspace';\n\n/** Directory name (under the sandbox user's home) that the app is deployed into by default. */\nexport const REMOTE_DIR_NAME = 'mastra-app';\n/** Default port the Mastra server listens on. */\nexport const DEFAULT_PORT = 4111;\n/** Launch script written into the remote dir. Re-running it restarts the server (e.g. after a wake). */\nexport const SERVER_SCRIPT = '.mastra-server.sh';\n/** Pidfile written by the launch script. */\nexport const SERVER_PIDFILE = '.mastra-server.pid';\n/** Server log file inside the remote dir. */\nexport const SERVER_LOGFILE = '.mastra-server.log';\n/** Marker recording the package.json hash of the last completed dependency install. */\nexport const INSTALL_MARKER = '.mastra-install-hash';\n\n/** getInfo may be sync or async, and may throw — normalize to `undefined` on failure. */\nexport async function getInfoSafe(sandbox: WorkspaceSandbox): Promise<SandboxInfo | undefined> {\n try {\n return await sandbox.getInfo?.();\n } catch {\n return undefined;\n }\n}\n\n/**\n * Resolve the directory the app is (or will be) deployed into. Defaults to\n * `$HOME/mastra-app` resolved inside the sandbox — home directories persist\n * across snapshot stop/resume on providers that support it, unlike `/tmp`.\n * The sandbox must be running.\n */\nexport async function resolveRemoteDir(sandbox: WorkspaceSandbox, remoteDir?: string): Promise<string> {\n if (remoteDir) return remoteDir;\n const result = await runInSandbox(sandbox, `printf %s \"\\${HOME:-$(pwd)}\"`, { allowFailure: true });\n const base = result.stdout.trim();\n if (!base) {\n throw new Error('Could not resolve the sandbox home directory. Pass `remoteDir` explicitly.');\n }\n return `${base}/${REMOTE_DIR_NAME}`;\n}\n\n/** Single-quote a value for POSIX shells. */\nexport function shellQuote(value: string): string {\n return `'${value.replace(/'/g, `'\\\\''`)}'`;\n}\n\n/** Run a shell script string inside the sandbox and throw on failure. */\nexport async function runInSandbox(\n sandbox: WorkspaceSandbox,\n script: string,\n opts?: {\n allowFailure?: boolean;\n timeout?: number;\n /** Safe description used in error messages instead of the script itself. */\n label?: string;\n },\n): Promise<{ stdout: string; stderr: string; exitCode: number }> {\n if (!sandbox.executeCommand) {\n throw new Error(\n `Sandbox provider \"${sandbox.provider}\" does not support executeCommand, which is required for sandbox deploys.`,\n );\n }\n // Run via `sh -c` (argv style): providers pass `command` straight to their\n // exec API as an executable, so a raw script string with spaces would fail.\n const result = await sandbox.executeCommand(\n 'sh',\n ['-c', script],\n opts?.timeout ? { timeout: opts.timeout } : undefined,\n );\n if (!result.success && !opts?.allowFailure) {\n // Never echo the full script back: it can contain secrets (env values)\n // or entire base64 upload chunks. Use the label or a bounded excerpt.\n const what = opts?.label ?? truncate(script, 120);\n throw new Error(\n `Command failed inside sandbox (exit ${result.exitCode}): ${what}\\n${truncate(result.stderr || result.stdout, 4_000)}`,\n );\n }\n return { stdout: result.stdout, stderr: result.stderr, exitCode: result.exitCode };\n}\n\nfunction truncate(value: string, max: number): string {\n return value.length > max ? `${value.slice(0, max)}… (truncated)` : value;\n}\n\n/**\n * Kill the previously launched server (if any) using its pidfile, waiting for\n * the process to exit (bounded, then SIGKILL) so the replacement never races\n * the old server for the port. Safe when nothing is running.\n */\nexport async function killPreviousServer(sandbox: WorkspaceSandbox, remoteDir: string): Promise<void> {\n const pidfile = shellQuote(`${remoteDir}/${SERVER_PIDFILE}`);\n const script = [\n `if [ -f ${pidfile} ]; then`,\n ` pid=\"$(cat ${pidfile})\"`,\n ` kill \"$pid\" 2>/dev/null || true`,\n // Wait up to ~5s for the old server to release the port, then force-kill.\n ` i=0`,\n ` while kill -0 \"$pid\" 2>/dev/null && [ \"$i\" -lt 50 ]; do sleep 0.1; i=$((i + 1)); done`,\n ` kill -9 \"$pid\" 2>/dev/null || true`,\n ` rm -f ${pidfile}`,\n `fi`,\n ].join('\\n');\n await runInSandbox(sandbox, script, { allowFailure: true, timeout: 15_000 });\n}\n\n/**\n * Launch (or relaunch) the server by running the recorded launch script,\n * detached via nohup. Deliberately NOT `processes.spawn()`: provider process\n * handles follow the command's log stream, which would keep the calling\n * process's event loop alive for as long as the server runs. The server's\n * lifecycle is managed through its pidfile instead.\n */\nexport async function launchServer(sandbox: WorkspaceSandbox, remoteDir: string): Promise<void> {\n const script = `${remoteDir}/${SERVER_SCRIPT}`;\n await runInSandbox(sandbox, `nohup sh ${shellQuote(script)} >/dev/null 2>&1 & echo launched`);\n}\n\n/** Tail the server log from inside the sandbox. */\nexport async function tailServerLog(sandbox: WorkspaceSandbox, remoteDir: string, lines = 50): Promise<string> {\n const logfile = `${remoteDir}/${SERVER_LOGFILE}`;\n const result = await runInSandbox(\n sandbox,\n `tail -n ${Math.floor(lines)} ${shellQuote(logfile)} 2>/dev/null || true`,\n {\n allowFailure: true,\n },\n );\n return result.stdout;\n}\n\n/**\n * Poll `${url}${path}` until the server responds. Any HTTP status below 500\n * counts as \"the server is up\" — gateway errors (502/503) mean nothing is\n * listening on the port, and 410 is what some providers (e.g. Vercel) return\n * from their edge when the sandbox itself is stopped.\n */\nexport async function waitForHealthy(\n url: string,\n opts: { path?: string; timeoutMs?: number; intervalMs?: number } = {},\n): Promise<boolean> {\n const path = opts.path ?? '/api';\n const timeoutMs = opts.timeoutMs ?? 60_000;\n const intervalMs = opts.intervalMs ?? 1_000;\n const deadline = Date.now() + timeoutMs;\n\n while (Date.now() < deadline) {\n try {\n const res = await fetch(new URL(path, url), { signal: AbortSignal.timeout(intervalMs * 5) });\n // A provider-edge error header means the response came from the sandbox\n // infrastructure (stopped/unreachable VM), not from the Mastra server.\n const providerError = res.status === 410 || res.headers.has('x-vercel-error');\n if (res.status < 500 && !providerError) {\n return true;\n }\n } catch {\n // Not reachable yet.\n }\n await new Promise(resolve => setTimeout(resolve, intervalMs));\n }\n return false;\n}\n"]}