@mastra/vercel 0.1.0 → 0.2.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.
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Vercel Sandbox (MicroVM) Provider
3
+ *
4
+ * Wraps the official `@vercel/sandbox` SDK, which provisions ephemeral
5
+ * Firecracker MicroVMs (Amazon Linux 2023) with a persistent in-session
6
+ * filesystem, command execution, background processes, and exposed ports.
7
+ *
8
+ * This is distinct from the `VercelSandbox` provider in this package, which
9
+ * runs commands as Vercel serverless Functions and is stateless.
10
+ *
11
+ * @see https://vercel.com/docs/vercel-sandbox
12
+ */
13
+ import type { RequestContext } from '@mastra/core/di';
14
+ import type { CommandResult, ExecuteCommandOptions, InstructionsOption, MastraSandboxOptions, ProviderStatus, SandboxInfo } from '@mastra/core/workspace';
15
+ import { MastraSandbox } from '@mastra/core/workspace';
16
+ import { Sandbox } from '@vercel/sandbox';
17
+ import { VercelMicroVMProcessManager } from './process-manager.js';
18
+ /** Vercel Sandbox runtimes (default `node24`). */
19
+ export type VercelMicroVMRuntime = 'node24' | 'node22' | 'node26' | 'python3.13';
20
+ /**
21
+ * Vercel Sandbox (MicroVM) provider configuration.
22
+ *
23
+ * Authentication: the SDK uses the `VERCEL_OIDC_TOKEN` environment variable
24
+ * automatically when available. To authenticate from an environment without
25
+ * OIDC, supply `token`, `teamId`, and `projectId` together (falling back to
26
+ * the `VERCEL_TOKEN`, `VERCEL_TEAM_ID`, and `VERCEL_PROJECT_ID` env vars).
27
+ */
28
+ export interface VercelMicroVMSandboxOptions extends Omit<MastraSandboxOptions, 'processes'> {
29
+ /** Unique identifier for this sandbox instance. */
30
+ id?: string;
31
+ /** Optional sandbox name passed to the Vercel API. Auto-generated if omitted. */
32
+ sandboxName?: string;
33
+ /** Vercel API token. Falls back to the `VERCEL_TOKEN` env var. */
34
+ token?: string;
35
+ /** Vercel team ID. Falls back to the `VERCEL_TEAM_ID` env var. */
36
+ teamId?: string;
37
+ /** Vercel project ID. Falls back to the `VERCEL_PROJECT_ID` env var. */
38
+ projectId?: string;
39
+ /** Sandbox runtime. @default 'node24' */
40
+ runtime?: VercelMicroVMRuntime;
41
+ /**
42
+ * Timeout in milliseconds before the sandbox auto-terminates.
43
+ * @default 300_000 // 5 minutes
44
+ */
45
+ timeout?: number;
46
+ /** Resources to allocate. `vcpus` controls CPU count (2048 MB memory per vCPU). */
47
+ resources?: {
48
+ vcpus?: number;
49
+ };
50
+ /** Ports to expose from the sandbox (up to 4). Access via `getInfo().metadata.domains`. */
51
+ ports?: number[];
52
+ /** Default environment variables inherited by all commands. */
53
+ env?: Record<string, string>;
54
+ /** Custom metadata surfaced via `getInfo()`. */
55
+ metadata?: Record<string, unknown>;
56
+ /**
57
+ * Custom instructions that override the default instructions
58
+ * returned by `getInstructions()`.
59
+ *
60
+ * - `string` — Fully replaces the default instructions. Pass an empty
61
+ * string to suppress instructions entirely.
62
+ * - `(opts) => string` — Receives the default instructions and optional
63
+ * request context so you can extend or customise per-request.
64
+ */
65
+ instructions?: InstructionsOption;
66
+ }
67
+ /**
68
+ * Vercel Sandbox (MicroVM) provider for Mastra workspaces.
69
+ *
70
+ * @example Basic usage
71
+ * ```typescript
72
+ * import { Workspace } from '@mastra/core/workspace';
73
+ * import { VercelMicroVMSandbox } from '@mastra/vercel';
74
+ *
75
+ * const workspace = new Workspace({
76
+ * sandbox: new VercelMicroVMSandbox({ runtime: 'node24', timeout: 600_000 }),
77
+ * });
78
+ *
79
+ * const result = await workspace.sandbox.executeCommand('node', ['--version']);
80
+ * ```
81
+ */
82
+ export declare class VercelMicroVMSandbox extends MastraSandbox {
83
+ readonly id: string;
84
+ readonly name = "VercelMicroVMSandbox";
85
+ readonly provider = "vercel-microvm";
86
+ status: ProviderStatus;
87
+ readonly processes: VercelMicroVMProcessManager;
88
+ private _sandbox;
89
+ private _createdAt;
90
+ private readonly _sandboxName?;
91
+ private readonly _token?;
92
+ private readonly _teamId?;
93
+ private readonly _projectId?;
94
+ private readonly _runtime;
95
+ private readonly _timeout;
96
+ private readonly _vcpus?;
97
+ private readonly _ports?;
98
+ private readonly _env;
99
+ private readonly _metadata;
100
+ private readonly _instructionsOverride?;
101
+ constructor(options?: VercelMicroVMSandboxOptions);
102
+ /**
103
+ * The underlying `@vercel/sandbox` instance.
104
+ * Throws if the sandbox has not been started yet.
105
+ */
106
+ get sandbox(): Sandbox;
107
+ start(): Promise<void>;
108
+ stop(): Promise<void>;
109
+ destroy(): Promise<void>;
110
+ private _teardown;
111
+ executeCommand(command: string, args?: string[], options?: ExecuteCommandOptions): Promise<CommandResult>;
112
+ getInfo(): SandboxInfo;
113
+ getInstructions(opts?: {
114
+ requestContext?: RequestContext;
115
+ }): string;
116
+ private _getDefaultInstructions;
117
+ }
118
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/microvm/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EACV,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,oBAAoB,EACpB,cAAc,EACd,WAAW,EACZ,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAwB,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AAIhE,kDAAkD;AAClD,MAAM,MAAM,oBAAoB,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,YAAY,CAAC;AAMjF;;;;;;;GAOG;AACH,MAAM,WAAW,2BAA4B,SAAQ,IAAI,CAAC,oBAAoB,EAAE,WAAW,CAAC;IAC1F,mDAAmD;IACnD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,iFAAi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AAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAW;IACnC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAyB;IAC9C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA0B;IACpD,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAqB;gBAEhD,OAAO,GAAE,2BAAgC;IAqBrD;;;OAGG;IACH,IAAI,OAAO,IAAI,OAAO,CAKrB;IAMK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAgCtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;YAIhB,SAAS;IAgBjB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,aAAa,CAAC;IA8E/G,OAAO,IAAI,WAAW;IA8BtB,eAAe,CAAC,IAAI,CAAC,EAAE;QAAE,cAAc,CAAC,EAAE,cAAc,CAAA;KAAE,GAAG,MAAM;IAOnE,OAAO,CAAC,uBAAuB;CAchC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Vercel Sandbox (MicroVM) Process Manager
3
+ *
4
+ * Implements SandboxProcessManager for the `@vercel/sandbox` SDK. Each spawn()
5
+ * starts a detached command via `sandbox.runCommand({ detached: true })` and
6
+ * streams its output through the command's async `logs()` iterator.
7
+ *
8
+ * The Vercel Sandbox SDK does not expose a stdin channel for running commands,
9
+ * so `sendStdin()` throws a clear "not supported" error.
10
+ */
11
+ import { ProcessHandle, SandboxProcessManager } from '@mastra/core/workspace';
12
+ import type { ProcessInfo, SpawnProcessOptions } from '@mastra/core/workspace';
13
+ import type { VercelMicroVMSandbox } from './index.js';
14
+ export interface VercelMicroVMProcessManagerOptions {
15
+ env?: Record<string, string | undefined>;
16
+ }
17
+ /**
18
+ * Vercel Sandbox implementation of SandboxProcessManager. Uses one detached
19
+ * `runCommand` per spawned process.
20
+ */
21
+ export declare class VercelMicroVMProcessManager extends SandboxProcessManager<VercelMicroVMSandbox> {
22
+ spawn(command: string, options?: SpawnProcessOptions): Promise<ProcessHandle>;
23
+ list(): Promise<ProcessInfo[]>;
24
+ }
25
+ //# sourceMappingURL=process-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-manager.d.ts","sourceRoot":"","sources":["../../src/microvm/process-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,KAAK,EAAiB,WAAW,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE9F,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAgIpD,MAAM,WAAW,kCAAkC;IACjD,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;CAC1C;AAED;;;GAGG;AACH,qBAAa,2BAA4B,SAAQ,qBAAqB,CAAC,oBAAoB,CAAC;IACpF,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,aAAa,CAAC;IAiCjF,IAAI,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;CAYrC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Vercel Sandbox (MicroVM) provider descriptor for MastraEditor.
3
+ *
4
+ * @example
5
+ * ```typescript
6
+ * import { vercelMicroVMSandboxProvider } from '@mastra/vercel';
7
+ *
8
+ * const editor = new MastraEditor({
9
+ * sandboxes: [vercelMicroVMSandboxProvider],
10
+ * });
11
+ * ```
12
+ */
13
+ import type { SandboxProvider } from '@mastra/core/editor';
14
+ /**
15
+ * Serializable subset of VercelMicroVMSandboxOptions for editor storage.
16
+ */
17
+ interface VercelMicroVMProviderConfig {
18
+ token?: string;
19
+ teamId?: string;
20
+ projectId?: string;
21
+ runtime?: 'node24' | 'node22' | 'node26' | 'python3.13';
22
+ timeout?: number;
23
+ vcpus?: number;
24
+ ports?: number[];
25
+ env?: Record<string, string>;
26
+ }
27
+ export declare const vercelMicroVMSandboxProvider: SandboxProvider<VercelMicroVMProviderConfig>;
28
+ export {};
29
+ //# sourceMappingURL=microvm-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"microvm-provider.d.ts","sourceRoot":"","sources":["../src/microvm-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG3D;;GAEG;AACH,UAAU,2BAA2B;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,YAAY,CAAC;IACxD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAED,eAAO,MAAM,4BAA4B,EAAE,eAAe,CAAC,2BAA2B,CAyCrF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/vercel",
3
- "version": "0.1.0",
3
+ "version": "0.2.0-alpha.0",
4
4
  "description": "Vercel serverless sandbox provider for Mastra workspaces",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -19,19 +19,21 @@
19
19
  "./package.json": "./package.json"
20
20
  },
21
21
  "license": "Apache-2.0",
22
- "dependencies": {},
22
+ "dependencies": {
23
+ "@vercel/sandbox": "2.0.2"
24
+ },
23
25
  "devDependencies": {
24
26
  "@types/node": "22.19.15",
25
- "@vitest/coverage-v8": "4.0.18",
26
- "@vitest/ui": "4.0.18",
27
+ "@vitest/coverage-v8": "4.1.5",
28
+ "@vitest/ui": "4.1.5",
27
29
  "dotenv": "^17.3.1",
28
- "eslint": "^9.39.4",
30
+ "eslint": "^10.2.1",
29
31
  "tsup": "^8.5.1",
30
- "typescript": "^5.9.3",
31
- "vitest": "4.0.18",
32
- "@internal/types-builder": "0.0.51",
33
- "@internal/lint": "0.0.76",
34
- "@mastra/core": "1.19.0"
32
+ "typescript": "^6.0.3",
33
+ "vitest": "4.1.5",
34
+ "@internal/lint": "0.0.99",
35
+ "@internal/types-builder": "0.0.74",
36
+ "@mastra/core": "1.38.0-alpha.3"
35
37
  },
36
38
  "peerDependencies": {
37
39
  "@mastra/core": ">=1.12.0-0 <2.0.0-0"