@mastra/vercel 1.2.0-alpha.0 → 1.3.0-alpha.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 CHANGED
@@ -1,5 +1,98 @@
1
1
  # @mastra/vercel
2
2
 
3
+ ## 1.3.0-alpha.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
+ - **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.
24
+ - **Bulk file upload**: `sandbox.writeFiles(files)` uploads multiple files in one call using the Vercel Sandbox SDK.
25
+ - **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.
26
+ - **Real destroy**: `destroy()` now permanently deletes the sandbox and its snapshots (previously it only stopped it). Use `stop()` for a resumable snapshot-stop.
27
+ - **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).
28
+
29
+ ```typescript
30
+ import { VercelSandbox } from '@mastra/vercel';
31
+
32
+ const sandbox = new VercelSandbox({ sandboxName: 'my-preview', ports: [4111] });
33
+ await sandbox.start();
34
+ const url = await sandbox.networking.getPortUrl(4111);
35
+ ```
36
+
37
+ ### Patch Changes
38
+
39
+ - 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)]:
40
+ - @mastra/core@1.52.0-alpha.5
41
+
42
+ ## 1.2.0
43
+
44
+ ### Minor Changes
45
+
46
+ - **Breaking change:** Renamed the Vercel sandbox exports to make the MicroVM and serverless implementations explicit. `VercelSandbox` now refers to the MicroVM-backed Vercel Sandbox product. The serverless implementation is now exported as `VercelServerlessSandbox`. ([#18667](https://github.com/mastra-ai/mastra/pull/18667))
47
+ - If you have been using `VercelSandbox` in your code, you should update your imports to use `VercelServerlessSandbox` instead.
48
+
49
+ ```diff
50
+ -import { VercelSandbox } from '@mastra/vercel';
51
+ -import type { VercelSandboxOptions } from '@mastra/vercel';
52
+ +import { VercelServerlessSandbox } from '@mastra/vercel';
53
+ +import type { VercelServerlessSandboxOptions } from '@mastra/vercel';
54
+
55
+ -const sandbox = new VercelSandbox({
56
+ +const sandbox = new VercelServerlessSandbox({
57
+ token: process.env.VERCEL_TOKEN,
58
+ });
59
+
60
+ -const options: VercelSandboxOptions = {
61
+ +const options: VercelServerlessSandboxOptions = {
62
+ token: process.env.VERCEL_TOKEN,
63
+ };
64
+ ```
65
+
66
+ - If you have been using `VercelMicroVMSandbox` in your code, you should update your imports to use `VercelSandbox` instead.
67
+
68
+ ```diff
69
+ -import { VercelMicroVMSandbox } from '@mastra/vercel';
70
+ +import { VercelSandbox } from '@mastra/vercel';
71
+ -import type { VercelMicroVMSandboxOptions } from '@mastra/vercel';
72
+ +import type { VercelSandboxOptions } from '@mastra/vercel';
73
+
74
+ -const sandbox = new VercelMicroVMSandbox();
75
+ +const sandbox = new VercelSandbox();
76
+
77
+ -const options: VercelMicroVMSandboxOptions = {
78
+ +const options: VercelSandboxOptions = {
79
+ runtime: 'node24',
80
+ };
81
+ ```
82
+
83
+ - Provider descriptors are also split by runtime:
84
+
85
+ ```ts
86
+ import { vercelSandboxProvider, vercelServerlessSandboxProvider } from '@mastra/vercel';
87
+ ```
88
+
89
+ Use `vercelSandboxProvider` for MicroVM-backed Vercel Sandbox instances and `vercelServerlessSandboxProvider` for Vercel Functions-backed serverless instances.
90
+
91
+ ### Patch Changes
92
+
93
+ - Updated dependencies [[`b9a2961`](https://github.com/mastra-ai/mastra/commit/b9a2961c1be81e3639c0879e58588c26dd0ae866), [`b33c77d`](https://github.com/mastra-ai/mastra/commit/b33c77d5293f14a794f3ec38dc947a6676de2764), [`1274eb3`](https://github.com/mastra-ai/mastra/commit/1274eb3a9508f579ceb3187fbce34408222d4b71), [`cdd5f93`](https://github.com/mastra-ai/mastra/commit/cdd5f939cefa67390629704dce92563ccbf492b2), [`1274eb3`](https://github.com/mastra-ai/mastra/commit/1274eb3a9508f579ceb3187fbce34408222d4b71), [`0ac14ce`](https://github.com/mastra-ai/mastra/commit/0ac14cea48e1b0a7857782153c78f7242fdf7e1a), [`9566d27`](https://github.com/mastra-ai/mastra/commit/9566d27ead3d95bdbe5a69e5a082a68222829cf2), [`8be63b0`](https://github.com/mastra-ai/mastra/commit/8be63b015fb8d72cea1220f05e7dc3bb997cc249), [`1009f77`](https://github.com/mastra-ai/mastra/commit/1009f772aa40016b49267c8566d0c29f6a16aa3c), [`1b8728a`](https://github.com/mastra-ai/mastra/commit/1b8728a57fd844205a452b0b4216d20ff60c784a), [`23c31de`](https://github.com/mastra-ai/mastra/commit/23c31de96ed8153402dcf092ac84b27a0c3638c1), [`0368766`](https://github.com/mastra-ai/mastra/commit/0368766744c7ea3df4d6059e2cc15f7bdf55f5a6), [`6f578ac`](https://github.com/mastra-ai/mastra/commit/6f578acba84930b406b2a0700b17cfdfaf5aae56), [`345eecc`](https://github.com/mastra-ai/mastra/commit/345eecce6ba519b5d987f0e10b5de4c8e5734580), [`1917c53`](https://github.com/mastra-ai/mastra/commit/1917c53b19dac43926f29c496893b0686462dca4), [`c01012f`](https://github.com/mastra-ai/mastra/commit/c01012f50368d29eb3fc3764df42d48291973d23), [`705ba98`](https://github.com/mastra-ai/mastra/commit/705ba98726d388a596e896225f237907ca6807a9), [`95857bc`](https://github.com/mastra-ai/mastra/commit/95857bcd6669da7193f503e803f0d72a2bd66be6), [`e62c108`](https://github.com/mastra-ai/mastra/commit/e62c108409dfd6a6cac0a48ec39c5cc81d24fd52), [`2866f04`](https://github.com/mastra-ai/mastra/commit/2866f04953edb78c1637fa45cc53abe24122edcb), [`ee14cae`](https://github.com/mastra-ai/mastra/commit/ee14cae244805783bde518a6142de28b744b169c), [`e84e791`](https://github.com/mastra-ai/mastra/commit/e84e79174031d7bc8793ca6c805eb38b06e7cfb1), [`c2f0b7f`](https://github.com/mastra-ai/mastra/commit/c2f0b7f1370f4428d165f51f0d1d9a48331cc257), [`213feb8`](https://github.com/mastra-ai/mastra/commit/213feb87bfdd1d8ec00ea660e218f9bcfcb34e7b), [`58e287b`](https://github.com/mastra-ai/mastra/commit/58e287b1edaf978b13745a1795989cad3826e82b), [`e420b3c`](https://github.com/mastra-ai/mastra/commit/e420b3c3ffc98bbc5b791897ea390bb47af99696), [`be875ed`](https://github.com/mastra-ai/mastra/commit/be875ed43f856742ce58529f531b5ea0ae6911f3), [`9eefdc0`](https://github.com/mastra-ai/mastra/commit/9eefdc0ac03f989718c6d835334940a977938895), [`bfbbb01`](https://github.com/mastra-ai/mastra/commit/bfbbb01bd845ba54cdc0c678c277d08a7cb847e4), [`7d112ca`](https://github.com/mastra-ai/mastra/commit/7d112ca17078479b2659b88ba1c85b936cfc111c)]:
94
+ - @mastra/core@1.48.0
95
+
3
96
  ## 1.2.0-alpha.0
4
97
 
5
98
  ### 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 8 vCPUs and up to 4 exposed ports per sandbox. Memory is allocated at 2048 MB per vCPU.
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
- async start() {
637
- if (this._sandbox) {
638
- return;
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
- const hasExplicitCreds = Boolean(this._token || this._teamId || this._projectId);
641
- if (hasExplicitCreds && !(this._token && this._teamId && this._projectId)) {
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 all three to use the VERCEL_OIDC_TOKEN.`
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
- this._sandbox = await sandbox.Sandbox.create({
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
- ...hasExplicitCreds ? { token: this._token, teamId: this._teamId, projectId: this._projectId } : {}
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._teardown();
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._teardown();
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
- try {
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).`] : [],