@mastra/vercel 1.2.0 → 1.3.0
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 +79 -0
- package/README.md +1 -1
- package/dist/index.cjs +108 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +108 -22
- package/dist/index.js.map +1 -1
- package/dist/microvm/index.d.ts +44 -2
- package/dist/microvm/index.d.ts.map +1 -1
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,84 @@
|
|
|
1
1
|
# @mastra/vercel
|
|
2
2
|
|
|
3
|
+
## 1.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added `clone()` support to the sandbox providers. `clone()` constructs an unstarted sibling sandbox that inherits the template's configuration (credentials, image, resources) with per-instance overrides for `id` and `env`, so one configured sandbox can act as a template for a fleet of sandbox clones (for example, one per project). ([#19616](https://github.com/mastra-ai/mastra/pull/19616))
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const template = new E2BSandbox({ apiKey, template: 'base' });
|
|
11
|
+
|
|
12
|
+
const projectSandbox = template.clone({
|
|
13
|
+
id: 'mc-project-42',
|
|
14
|
+
env: { GITHUB_TOKEN: token },
|
|
15
|
+
idleTimeoutMinutes: 30,
|
|
16
|
+
});
|
|
17
|
+
await projectSandbox.start();
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`idleTimeoutMinutes` is a best-effort hint that maps to each provider's native lifetime knob (Railway `idleTimeoutMinutes`, E2B/Modal/Vercel timeout in milliseconds, Daytona `autoStopInterval`, Blaxel TTL duration). Docker and Apple Container ignore it since they have no provider-side idle teardown.
|
|
21
|
+
|
|
22
|
+
- Added networking and bulk file upload support to `VercelSandbox`: ([#19577](https://github.com/mastra-ai/mastra/pull/19577))
|
|
23
|
+
|
|
24
|
+
- **Public port URLs**: `sandbox.networking.getPortUrl(port)` returns the public URL for a declared port, enabling preview URLs and deploys with the new `@mastra/deployer-sandbox` package.
|
|
25
|
+
- **Bulk file upload**: `sandbox.writeFiles(files)` uploads multiple files in one call using the Vercel Sandbox SDK.
|
|
26
|
+
- **Named sandbox resume**: when `sandboxName` is set, `start()` now reuses an existing sandbox with that name instead of always creating a new one. Stopping a named sandbox snapshots its filesystem, and the next `start()` resumes it.
|
|
27
|
+
- **Real destroy**: `destroy()` now permanently deletes the sandbox and its snapshots (previously it only stopped it). Use `stop()` for a resumable snapshot-stop.
|
|
28
|
+
- **Resume-less lookups**: `networking.getPortUrl()`, `stop()`, and `destroy()` on a named sandbox now attach to the existing sandbox with `resume: false` when the instance hasn't been started in the current process. Resolving a URL or tearing down a stopped sandbox never wakes it (and never starts billing).
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { VercelSandbox } from '@mastra/vercel';
|
|
32
|
+
|
|
33
|
+
const sandbox = new VercelSandbox({ sandboxName: 'my-preview', ports: [4111] });
|
|
34
|
+
await sandbox.start();
|
|
35
|
+
const url = await sandbox.networking.getPortUrl(4111);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Patch Changes
|
|
39
|
+
|
|
40
|
+
- Updated dependencies [[`ec857fc`](https://github.com/mastra-ai/mastra/commit/ec857fc79c264b53b38e16478c789b7177f2ad59), [`d7385ad`](https://github.com/mastra-ai/mastra/commit/d7385ad9e88f9e4f33d15c0ec0bfebedde0cbc2e), [`41a5392`](https://github.com/mastra-ai/mastra/commit/41a5392d9f6c5e18d6b227f0fc0ddf49c50774e9), [`3d6e539`](https://github.com/mastra-ai/mastra/commit/3d6e539272eb2ea0407034605ee1906b3be06b39), [`1426af2`](https://github.com/mastra-ai/mastra/commit/1426af24975879c000d13ac75673f630fcc970c1), [`a40adeb`](https://github.com/mastra-ai/mastra/commit/a40adeb222b961a56a58af56a106106525721b74), [`8a0d145`](https://github.com/mastra-ai/mastra/commit/8a0d145aadbdf7278665aceaaec364b35dd9bd94), [`bd2f1d2`](https://github.com/mastra-ai/mastra/commit/bd2f1d274d05e60e2366f005ea0d94d5cea0d5ff), [`e1f2fae`](https://github.com/mastra-ai/mastra/commit/e1f2faebaf048c3d4c2e2c01d293767c195d5794), [`63aa799`](https://github.com/mastra-ai/mastra/commit/63aa799c6b44eacc7806cda6846b7c5bbee06b37), [`b7e79c3`](https://github.com/mastra-ai/mastra/commit/b7e79c3c02ac5cd415db34ba0975ceafc1464333), [`675fbff`](https://github.com/mastra-ai/mastra/commit/675fbff84d3274391b33e852f76083c38a5514e5), [`da009e1`](https://github.com/mastra-ai/mastra/commit/da009e1aacd89ed94b8d1b2af09c9d4fe7c4db49), [`3b77e77`](https://github.com/mastra-ai/mastra/commit/3b77e7704936522e4769d29de1b5ea6901f302bd), [`c7d30cd`](https://github.com/mastra-ai/mastra/commit/c7d30cd86009c407df91105591f03cd6e3d2854d), [`21a0eb8`](https://github.com/mastra-ai/mastra/commit/21a0eb86746ba0b703acea360d4f84c6a5a493f2), [`8b20926`](https://github.com/mastra-ai/mastra/commit/8b20926cd59e2ba3d66458e062fa0e6e2ada3e68), [`975295d`](https://github.com/mastra-ai/mastra/commit/975295d418552f0d46a59edfef4c3ee555f9930a), [`73db8db`](https://github.com/mastra-ai/mastra/commit/73db8db90d69ab6153c7942749f624db0d96952d), [`6b1bf3b`](https://github.com/mastra-ai/mastra/commit/6b1bf3b9494bd51aa8f654c68c9355d6046fa2a1), [`35c2181`](https://github.com/mastra-ai/mastra/commit/35c2181e6a50e47c90ba36260db7c9723d54696f), [`0a2c22c`](https://github.com/mastra-ai/mastra/commit/0a2c22c902604439ec490319e14c17f331e0c84c), [`4cfdd64`](https://github.com/mastra-ai/mastra/commit/4cfdd645794feaea0c4ea711e70ecdfbef0c5b8e), [`b75d749`](https://github.com/mastra-ai/mastra/commit/b75d749621ff5d17e86bcb4ee809d301fb4f7cf3), [`821648b`](https://github.com/mastra-ai/mastra/commit/821648bf2871ef840100c7bacbecf676010bd12a), [`de86fd7`](https://github.com/mastra-ai/mastra/commit/de86fd7119f0438381d1a642e3d258143c0b9c29), [`2745031`](https://github.com/mastra-ai/mastra/commit/2745031d1d4a4978f037092da371428c32e2842a), [`b4b7ea8`](https://github.com/mastra-ai/mastra/commit/b4b7ea8733f033fc441ea47ed03f6afb17ec2248), [`3a8024c`](https://github.com/mastra-ai/mastra/commit/3a8024ce615f8aa89479c0d71fe61d10bb0040be), [`35865a5`](https://github.com/mastra-ai/mastra/commit/35865a53e194aa9634d6a70a97010e7a6b9d58b1), [`74faf8b`](https://github.com/mastra-ai/mastra/commit/74faf8bd9c1018f2492653c06b1e25fc8300e9e6), [`ef03fbc`](https://github.com/mastra-ai/mastra/commit/ef03fbcc556bcbc04c9b3d06fab88771ecaa043c), [`675fbff`](https://github.com/mastra-ai/mastra/commit/675fbff84d3274391b33e852f76083c38a5514e5), [`70687f7`](https://github.com/mastra-ai/mastra/commit/70687f7e495a322a02070b4a67cb0c77a5ca91ec), [`1fadac4`](https://github.com/mastra-ai/mastra/commit/1fadac44537caeefe81f9f775ae2f2f3d94e9069), [`73db8db`](https://github.com/mastra-ai/mastra/commit/73db8db90d69ab6153c7942749f624db0d96952d), [`76b7181`](https://github.com/mastra-ai/mastra/commit/76b71810366e6d90b9d3973149d1c7ba3659ffb9), [`792ec9a`](https://github.com/mastra-ai/mastra/commit/792ec9a0869bab8274cf5e0ed2840738737a1607), [`712b864`](https://github.com/mastra-ai/mastra/commit/712b864aa1ed12b14c54390ec17b69de163c37f7), [`85e4fb5`](https://github.com/mastra-ai/mastra/commit/85e4fb50087a81c74df3a762f53b56373db0b912), [`0c0e8d7`](https://github.com/mastra-ai/mastra/commit/0c0e8d7becd4d1445c656b78d5d845f606c1ff9d), [`a7bbe77`](https://github.com/mastra-ai/mastra/commit/a7bbe773577f60bc4761b534ef7ec6b476332dad), [`72e437c`](https://github.com/mastra-ai/mastra/commit/72e437c515942c80b9def5b026e0bdee61b469d9), [`8f7a5de`](https://github.com/mastra-ai/mastra/commit/8f7a5dedc246cdc938bb65516703cf9b27b03756), [`a7bbe77`](https://github.com/mastra-ai/mastra/commit/a7bbe773577f60bc4761b534ef7ec6b476332dad), [`11f6cd9`](https://github.com/mastra-ai/mastra/commit/11f6cd96fe42582403416608beb212cc1a2cc79e), [`ef03c0c`](https://github.com/mastra-ai/mastra/commit/ef03c0cfc62367a458e4cc56462e2148b35681c5), [`4fb4d88`](https://github.com/mastra-ai/mastra/commit/4fb4d881bc107acee13890ad4d78661016c510ed), [`4e68363`](https://github.com/mastra-ai/mastra/commit/4e683634f94ebd062d26a3bb6093a8dfc7263d37), [`c328769`](https://github.com/mastra-ai/mastra/commit/c3287698ff8ef98dba86d415faa566fa3e5f4d56), [`9f7c67a`](https://github.com/mastra-ai/mastra/commit/9f7c67abeeb52c41c51a9b5edee60b62afe7cd8d), [`3b65e68`](https://github.com/mastra-ai/mastra/commit/3b65e68d7f1c771c7a70eea42d83fefdd28cad88), [`4eba27a`](https://github.com/mastra-ai/mastra/commit/4eba27adcf60f991df0e62f94b3e75b4e67f3b4b), [`c701be3`](https://github.com/mastra-ai/mastra/commit/c701be32d7d9aa94a66da8c6cc38dcac6856f464), [`db650ce`](https://github.com/mastra-ai/mastra/commit/db650ce490348914e85b93651d83acdf8f2a4c31), [`232fcbc`](https://github.com/mastra-ai/mastra/commit/232fcbc14fce625dd672ba043329c0b732c62be2), [`6354eeb`](https://github.com/mastra-ai/mastra/commit/6354eeb32efa9f5f68f51dda394e90e2ee76f1fb), [`a8799bb`](https://github.com/mastra-ai/mastra/commit/a8799bb8e44f4a60d01e4e2acd3448ff80bf14f8), [`3d6e539`](https://github.com/mastra-ai/mastra/commit/3d6e539272eb2ea0407034605ee1906b3be06b39), [`e3868e2`](https://github.com/mastra-ai/mastra/commit/e3868e22babfffd0133771669ca724501c2dd58e), [`9251370`](https://github.com/mastra-ai/mastra/commit/9251370ad413af464aa22d7566338bec5613e8de), [`3491666`](https://github.com/mastra-ai/mastra/commit/34916663c4fdd43b48c21f4ab2d5fb6dcccc94f9), [`c0bec73`](https://github.com/mastra-ai/mastra/commit/c0bec732c93d1a22ae5e51ed66cf8cacca8bd6a6)]:
|
|
41
|
+
- @mastra/core@1.52.0
|
|
42
|
+
|
|
43
|
+
## 1.3.0-alpha.0
|
|
44
|
+
|
|
45
|
+
### Minor Changes
|
|
46
|
+
|
|
47
|
+
- Added `clone()` support to the sandbox providers. `clone()` constructs an unstarted sibling sandbox that inherits the template's configuration (credentials, image, resources) with per-instance overrides for `id` and `env`, so one configured sandbox can act as a template for a fleet of sandbox clones (for example, one per project). ([#19616](https://github.com/mastra-ai/mastra/pull/19616))
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
const template = new E2BSandbox({ apiKey, template: 'base' });
|
|
51
|
+
|
|
52
|
+
const projectSandbox = template.clone({
|
|
53
|
+
id: 'mc-project-42',
|
|
54
|
+
env: { GITHUB_TOKEN: token },
|
|
55
|
+
idleTimeoutMinutes: 30,
|
|
56
|
+
});
|
|
57
|
+
await projectSandbox.start();
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`idleTimeoutMinutes` is a best-effort hint that maps to each provider's native lifetime knob (Railway `idleTimeoutMinutes`, E2B/Modal/Vercel timeout in milliseconds, Daytona `autoStopInterval`, Blaxel TTL duration). Docker and Apple Container ignore it since they have no provider-side idle teardown.
|
|
61
|
+
|
|
62
|
+
- Added networking and bulk file upload support to `VercelSandbox`: ([#19577](https://github.com/mastra-ai/mastra/pull/19577))
|
|
63
|
+
- **Public port URLs**: `sandbox.networking.getPortUrl(port)` returns the public URL for a declared port, enabling preview URLs and deploys with the new `@mastra/deployer-sandbox` package.
|
|
64
|
+
- **Bulk file upload**: `sandbox.writeFiles(files)` uploads multiple files in one call using the Vercel Sandbox SDK.
|
|
65
|
+
- **Named sandbox resume**: when `sandboxName` is set, `start()` now reuses an existing sandbox with that name instead of always creating a new one. Stopping a named sandbox snapshots its filesystem, and the next `start()` resumes it.
|
|
66
|
+
- **Real destroy**: `destroy()` now permanently deletes the sandbox and its snapshots (previously it only stopped it). Use `stop()` for a resumable snapshot-stop.
|
|
67
|
+
- **Resume-less lookups**: `networking.getPortUrl()`, `stop()`, and `destroy()` on a named sandbox now attach to the existing sandbox with `resume: false` when the instance hasn't been started in the current process. Resolving a URL or tearing down a stopped sandbox never wakes it (and never starts billing).
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { VercelSandbox } from '@mastra/vercel';
|
|
71
|
+
|
|
72
|
+
const sandbox = new VercelSandbox({ sandboxName: 'my-preview', ports: [4111] });
|
|
73
|
+
await sandbox.start();
|
|
74
|
+
const url = await sandbox.networking.getPortUrl(4111);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Patch Changes
|
|
78
|
+
|
|
79
|
+
- Updated dependencies [[`ec857fc`](https://github.com/mastra-ai/mastra/commit/ec857fc79c264b53b38e16478c789b7177f2ad59), [`e1f2fae`](https://github.com/mastra-ai/mastra/commit/e1f2faebaf048c3d4c2e2c01d293767c195d5794), [`63aa799`](https://github.com/mastra-ai/mastra/commit/63aa799c6b44eacc7806cda6846b7c5bbee06b37), [`73db8db`](https://github.com/mastra-ai/mastra/commit/73db8db90d69ab6153c7942749f624db0d96952d), [`73db8db`](https://github.com/mastra-ai/mastra/commit/73db8db90d69ab6153c7942749f624db0d96952d), [`76b7181`](https://github.com/mastra-ai/mastra/commit/76b71810366e6d90b9d3973149d1c7ba3659ffb9), [`0c0e8d7`](https://github.com/mastra-ai/mastra/commit/0c0e8d7becd4d1445c656b78d5d845f606c1ff9d), [`9f7c67a`](https://github.com/mastra-ai/mastra/commit/9f7c67abeeb52c41c51a9b5edee60b62afe7cd8d), [`3b65e68`](https://github.com/mastra-ai/mastra/commit/3b65e68d7f1c771c7a70eea42d83fefdd28cad88), [`e3868e2`](https://github.com/mastra-ai/mastra/commit/e3868e22babfffd0133771669ca724501c2dd58e)]:
|
|
80
|
+
- @mastra/core@1.52.0-alpha.5
|
|
81
|
+
|
|
3
82
|
## 1.2.0
|
|
4
83
|
|
|
5
84
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -77,7 +77,7 @@ const info = await sandbox.getInfo();
|
|
|
77
77
|
console.log(info.metadata.domains);
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
Vercel supports up to
|
|
80
|
+
Vercel supports up to 32 vCPUs and up to 15 exposed ports per sandbox. Memory is allocated at 2048 MB per vCPU.
|
|
81
81
|
|
|
82
82
|
### Streaming command output
|
|
83
83
|
|
package/dist/index.cjs
CHANGED
|
@@ -583,12 +583,29 @@ var VercelSandboxProcessManager = class extends workspace.SandboxProcessManager
|
|
|
583
583
|
|
|
584
584
|
// src/microvm/index.ts
|
|
585
585
|
var LOG_PREFIX2 = "[VercelSandbox]";
|
|
586
|
-
var VercelSandbox = class extends workspace.MastraSandbox {
|
|
586
|
+
var VercelSandbox = class _VercelSandbox extends workspace.MastraSandbox {
|
|
587
587
|
id;
|
|
588
588
|
name = "VercelSandbox";
|
|
589
589
|
provider = "vercel-sandbox";
|
|
590
590
|
status = "pending";
|
|
591
|
+
/**
|
|
592
|
+
* Networking capability: public HTTPS URLs for exposed ports.
|
|
593
|
+
* A port must be declared in `ports` at construction time for a URL to exist.
|
|
594
|
+
*/
|
|
595
|
+
networking = {
|
|
596
|
+
getPortUrl: async (port) => {
|
|
597
|
+
const sandbox = this._sandbox ?? await this.attach();
|
|
598
|
+
if (!sandbox) return null;
|
|
599
|
+
try {
|
|
600
|
+
return sandbox.domain(port);
|
|
601
|
+
} catch {
|
|
602
|
+
return null;
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
};
|
|
591
606
|
_sandbox = null;
|
|
607
|
+
/** True when `_sandbox` came from a resume-less lookup — `start()` must still resume it. */
|
|
608
|
+
_attachedWithoutResume = false;
|
|
592
609
|
_createdAt = null;
|
|
593
610
|
_sandboxName;
|
|
594
611
|
_token;
|
|
@@ -601,6 +618,7 @@ var VercelSandbox = class extends workspace.MastraSandbox {
|
|
|
601
618
|
_env;
|
|
602
619
|
_metadata;
|
|
603
620
|
_instructionsOverride;
|
|
621
|
+
_constructorOptions;
|
|
604
622
|
constructor(options = {}) {
|
|
605
623
|
super({
|
|
606
624
|
...options,
|
|
@@ -619,6 +637,29 @@ var VercelSandbox = class extends workspace.MastraSandbox {
|
|
|
619
637
|
this._env = options.env ?? {};
|
|
620
638
|
this._metadata = options.metadata ?? {};
|
|
621
639
|
this._instructionsOverride = options.instructions;
|
|
640
|
+
this._constructorOptions = { ...options };
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* Construct a sibling `VercelSandbox` that inherits this sandbox's
|
|
644
|
+
* configuration (credentials, runtime, resources, ports, metadata,
|
|
645
|
+
* instructions) with per-instance overrides.
|
|
646
|
+
*
|
|
647
|
+
* Performs no I/O — the sandbox clone provisions a fresh MicroVM on its
|
|
648
|
+
* own `start()` (Vercel sandboxes cannot be reconnected to, so
|
|
649
|
+
* `options.sandboxId` is ignored). Use it when one configured sandbox acts
|
|
650
|
+
* as the template for a fleet of independent sandboxes (e.g. one per
|
|
651
|
+
* project).
|
|
652
|
+
*
|
|
653
|
+
* `options.idleTimeoutMinutes` maps to the Vercel sandbox `timeout` (ms).
|
|
654
|
+
*/
|
|
655
|
+
clone(options = {}) {
|
|
656
|
+
const { id: _id, sandboxName: _sandboxName, ...base } = this._constructorOptions;
|
|
657
|
+
return new _VercelSandbox({
|
|
658
|
+
...base,
|
|
659
|
+
...options.id !== void 0 && { id: options.id },
|
|
660
|
+
...options.env !== void 0 && { env: options.env },
|
|
661
|
+
...options.idleTimeoutMinutes !== void 0 && { timeout: options.idleTimeoutMinutes * 6e4 }
|
|
662
|
+
});
|
|
622
663
|
}
|
|
623
664
|
/**
|
|
624
665
|
* The underlying `@vercel/sandbox` instance.
|
|
@@ -633,45 +674,90 @@ var VercelSandbox = class extends workspace.MastraSandbox {
|
|
|
633
674
|
// ---------------------------------------------------------------------------
|
|
634
675
|
// Lifecycle
|
|
635
676
|
// ---------------------------------------------------------------------------
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
677
|
+
/**
|
|
678
|
+
* Attach to an existing named sandbox WITHOUT resuming it (`resume: false`),
|
|
679
|
+
* so lookups (URL resolution, stop, destroy) never wake a stopped sandbox
|
|
680
|
+
* and start billing. Returns null when unnamed or when no sandbox with this
|
|
681
|
+
* name exists.
|
|
682
|
+
*/
|
|
683
|
+
async attach() {
|
|
684
|
+
if (this._sandbox) return this._sandbox;
|
|
685
|
+
if (!this._sandboxName) return null;
|
|
686
|
+
try {
|
|
687
|
+
this._sandbox = await sandbox.Sandbox.get({
|
|
688
|
+
name: this._sandboxName,
|
|
689
|
+
resume: false,
|
|
690
|
+
...this.credentialParams()
|
|
691
|
+
});
|
|
692
|
+
this._attachedWithoutResume = true;
|
|
693
|
+
return this._sandbox;
|
|
694
|
+
} catch {
|
|
695
|
+
return null;
|
|
639
696
|
}
|
|
640
|
-
|
|
641
|
-
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* The token is the credential: when provided, the SDK requires teamId and
|
|
700
|
+
* projectId alongside it. Without a token the SDK authenticates via the
|
|
701
|
+
* `VERCEL_OIDC_TOKEN`; a stray teamId/projectId (for example, an exported
|
|
702
|
+
* `VERCEL_TEAM_ID` in the shell) must not break OIDC auth, so it is ignored.
|
|
703
|
+
*/
|
|
704
|
+
credentialParams() {
|
|
705
|
+
if (!this._token) return {};
|
|
706
|
+
if (!(this._teamId && this._projectId)) {
|
|
642
707
|
throw new Error(
|
|
643
|
-
`${LOG_PREFIX2} Incomplete credentials. Provide token, teamId, and projectId together (or the VERCEL_TOKEN, VERCEL_TEAM_ID, and VERCEL_PROJECT_ID env vars), or omit
|
|
708
|
+
`${LOG_PREFIX2} Incomplete credentials. Provide token, teamId, and projectId together (or the VERCEL_TOKEN, VERCEL_TEAM_ID, and VERCEL_PROJECT_ID env vars), or omit the token to use the VERCEL_OIDC_TOKEN.`
|
|
644
709
|
);
|
|
645
710
|
}
|
|
711
|
+
return { token: this._token, teamId: this._teamId, projectId: this._projectId };
|
|
712
|
+
}
|
|
713
|
+
async start() {
|
|
714
|
+
if (this._sandbox && !this._attachedWithoutResume) {
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
646
717
|
this.logger.debug(`${LOG_PREFIX2} Creating sandbox...`, { runtime: this._runtime, timeout: this._timeout });
|
|
647
|
-
|
|
648
|
-
...this._sandboxName ? { name: this._sandboxName } : {},
|
|
718
|
+
const params = {
|
|
649
719
|
runtime: this._runtime,
|
|
650
720
|
timeout: this._timeout,
|
|
651
721
|
...this._vcpus ? { resources: { vcpus: this._vcpus } } : {},
|
|
652
722
|
...this._ports?.length ? { ports: this._ports } : {},
|
|
653
723
|
...Object.keys(this._env).length ? { env: this._env } : {},
|
|
654
|
-
...
|
|
655
|
-
}
|
|
724
|
+
...this.credentialParams()
|
|
725
|
+
};
|
|
726
|
+
this._sandbox = this._sandboxName ? await sandbox.Sandbox.getOrCreate({ ...params, name: this._sandboxName }) : await sandbox.Sandbox.create(params);
|
|
727
|
+
this._attachedWithoutResume = false;
|
|
656
728
|
this._createdAt = /* @__PURE__ */ new Date();
|
|
657
729
|
this.logger.debug(`${LOG_PREFIX2} Sandbox ready: ${this._sandbox.name}`);
|
|
658
730
|
}
|
|
731
|
+
/** Snapshot-stop: the filesystem persists and a named sandbox resumes on the next `start()`. */
|
|
659
732
|
async stop() {
|
|
660
|
-
await this.
|
|
733
|
+
const sandbox = this._sandbox ?? await this.attach();
|
|
734
|
+
if (!sandbox) {
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
await sandbox.stop();
|
|
738
|
+
this._sandbox = null;
|
|
739
|
+
this._attachedWithoutResume = false;
|
|
661
740
|
}
|
|
741
|
+
/** Permanently delete the sandbox and its snapshots. */
|
|
662
742
|
async destroy() {
|
|
663
|
-
await this.
|
|
664
|
-
|
|
665
|
-
async _teardown() {
|
|
666
|
-
if (!this._sandbox) {
|
|
743
|
+
const sandbox = this._sandbox ?? await this.attach();
|
|
744
|
+
if (!sandbox) {
|
|
667
745
|
return;
|
|
668
746
|
}
|
|
669
|
-
|
|
670
|
-
await this._sandbox.stop();
|
|
671
|
-
} catch (error) {
|
|
672
|
-
this.logger.warn(`${LOG_PREFIX2} Error stopping sandbox:`, error);
|
|
673
|
-
}
|
|
747
|
+
await sandbox.delete();
|
|
674
748
|
this._sandbox = null;
|
|
749
|
+
this._attachedWithoutResume = false;
|
|
750
|
+
}
|
|
751
|
+
// ---------------------------------------------------------------------------
|
|
752
|
+
// File Upload
|
|
753
|
+
// ---------------------------------------------------------------------------
|
|
754
|
+
/**
|
|
755
|
+
* Bulk-write files into the sandbox filesystem via the SDK's native upload.
|
|
756
|
+
* Relative paths resolve against /vercel/sandbox.
|
|
757
|
+
*/
|
|
758
|
+
async writeFiles(files) {
|
|
759
|
+
await this.ensureRunning();
|
|
760
|
+
await this.sandbox.writeFiles(files.map((f) => ({ path: f.path, content: f.content })));
|
|
675
761
|
}
|
|
676
762
|
// ---------------------------------------------------------------------------
|
|
677
763
|
// Command Execution
|
|
@@ -775,7 +861,7 @@ var VercelSandbox = class extends workspace.MastraSandbox {
|
|
|
775
861
|
return [
|
|
776
862
|
"Vercel Sandbox: an ephemeral Firecracker MicroVM running Amazon Linux 2023.",
|
|
777
863
|
`- Runtime: ${this._runtime}. Working directory defaults to /vercel/sandbox.`,
|
|
778
|
-
"- Persistent filesystem within the session; state is lost when the sandbox stops.",
|
|
864
|
+
this._sandboxName ? "- Persistent filesystem: stopping snapshots the filesystem and the named sandbox resumes it on the next start. Processes do not survive a stop." : "- Persistent filesystem within the session; state is lost when the sandbox stops.",
|
|
779
865
|
"- Runs as the vercel-sandbox user with sudo access (install packages via dnf).",
|
|
780
866
|
`- The sandbox auto-terminates after ${Math.round(this._timeout / 1e3)} seconds.`,
|
|
781
867
|
...this._ports?.length ? [`- Exposed ports: ${this._ports.join(", ")} (reachable via public HTTPS domains).`] : [],
|