@mastra/deployer-vercel 0.0.0-storage-20250225005900 → 0.0.0-support-d1-client-20250701191943

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.
@@ -1,4 +1,6 @@
1
- Elastic License 2.0 (ELv2)
1
+ # Elastic License 2.0 (ELv2)
2
+
3
+ Copyright (c) 2025 Mastra AI, Inc.
2
4
 
3
5
  **Acceptance**
4
6
  By using the software, you agree to all of the terms and conditions below.
package/README.md CHANGED
@@ -25,8 +25,9 @@ import { Mastra } from '@mastra/core';
25
25
  import { VercelDeployer } from '@mastra/deployer-vercel';
26
26
 
27
27
  const deployer = new VercelDeployer({
28
- scope: 'your-team-id',
28
+ teamSlug: 'your-team-slug',
29
29
  projectName: 'your-project-name',
30
+ token: 'your-vercel-token',
30
31
  });
31
32
 
32
33
  const mastra = new Mastra({
@@ -39,8 +40,9 @@ const mastra = new Mastra({
39
40
 
40
41
  ### Constructor Options
41
42
 
42
- - `scope` (required): Your Vercel team ID or username
43
+ - `teamSlug` (required): Your Vercel team slug
43
44
  - `projectName`: Name of your Vercel project (will be created if it doesn't exist)
45
+ - `token`: Your Vercel API token (required for authentication)
44
46
 
45
47
  ## Project Structure
46
48
 
@@ -0,0 +1,13 @@
1
+ import { Deployer } from '@mastra/deployer';
2
+
3
+ export declare class VercelDeployer extends Deployer {
4
+ constructor();
5
+ prepare(outputDirectory: string): Promise<void>;
6
+ private getEntry;
7
+ private writeVercelJSON;
8
+ bundle(entryFile: string, outputDirectory: string, toolsPaths: string[]): Promise<void>;
9
+ deploy(): Promise<void>;
10
+ lint(entryFile: string, outputDirectory: string, toolsPaths: string[]): Promise<void>;
11
+ }
12
+
13
+ export { }
@@ -1,21 +1,13 @@
1
1
  import { Deployer } from '@mastra/deployer';
2
2
 
3
3
  export declare class VercelDeployer extends Deployer {
4
- private teamId;
5
- private projectName;
6
- private token;
7
- constructor({ teamId, projectName, token }: {
8
- teamId: string;
9
- projectName: string;
10
- token: string;
11
- });
12
- writeFiles(outputDirectory: string): void;
13
- private getProjectId;
14
- private syncEnv;
4
+ constructor();
15
5
  prepare(outputDirectory: string): Promise<void>;
16
6
  private getEntry;
17
- bundle(entryFile: string, outputDirectory: string): Promise<void>;
18
- deploy(outputDirectory: string): Promise<void>;
7
+ private writeVercelJSON;
8
+ bundle(entryFile: string, outputDirectory: string, toolsPaths: string[]): Promise<void>;
9
+ deploy(): Promise<void>;
10
+ lint(entryFile: string, outputDirectory: string, toolsPaths: string[]): Promise<void>;
19
11
  }
20
12
 
21
13
  export { }
package/dist/index.cjs ADDED
@@ -0,0 +1,138 @@
1
+ 'use strict';
2
+
3
+ var fs = require('fs');
4
+ var path = require('path');
5
+ var process = require('process');
6
+ var deployer = require('@mastra/deployer');
7
+ var esm = require('fs-extra/esm');
8
+
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
+
11
+ var process__default = /*#__PURE__*/_interopDefault(process);
12
+
13
+ // src/index.ts
14
+ var VercelDeployer = class extends deployer.Deployer {
15
+ constructor() {
16
+ super({ name: "VERCEL" });
17
+ this.outputDir = path.join(".vercel", "output", "functions", "index.func");
18
+ }
19
+ async prepare(outputDirectory) {
20
+ await super.prepare(outputDirectory);
21
+ this.writeVercelJSON(path.join(outputDirectory, this.outputDir, "..", ".."));
22
+ }
23
+ getEntry() {
24
+ return `
25
+ import { handle } from 'hono/vercel'
26
+ import { mastra } from '#mastra';
27
+ import { createHonoServer } from '#server';
28
+ import { evaluate } from '@mastra/core/eval';
29
+ import { AvailableHooks, registerHook } from '@mastra/core/hooks';
30
+ import { TABLE_EVALS } from '@mastra/core/storage';
31
+ import { checkEvalStorageFields } from '@mastra/core/utils';
32
+
33
+ registerHook(AvailableHooks.ON_GENERATION, ({ input, output, metric, runId, agentName, instructions }) => {
34
+ evaluate({
35
+ agentName,
36
+ input,
37
+ metric,
38
+ output,
39
+ runId,
40
+ globalRunId: runId,
41
+ instructions,
42
+ });
43
+ });
44
+
45
+ registerHook(AvailableHooks.ON_EVALUATION, async traceObject => {
46
+ const storage = mastra.getStorage();
47
+ if (storage) {
48
+ // Check for required fields
49
+ const logger = mastra?.getLogger();
50
+ const areFieldsValid = checkEvalStorageFields(traceObject, logger);
51
+ if (!areFieldsValid) return;
52
+
53
+ await storage.insert({
54
+ tableName: TABLE_EVALS,
55
+ record: {
56
+ input: traceObject.input,
57
+ output: traceObject.output,
58
+ result: JSON.stringify(traceObject.result || {}),
59
+ agent_name: traceObject.agentName,
60
+ metric_name: traceObject.metricName,
61
+ instructions: traceObject.instructions,
62
+ test_info: null,
63
+ global_run_id: traceObject.globalRunId,
64
+ run_id: traceObject.runId,
65
+ created_at: new Date().toISOString(),
66
+ },
67
+ });
68
+ }
69
+ });
70
+
71
+ const app = await createHonoServer(mastra);
72
+
73
+ export const GET = handle(app);
74
+ export const POST = handle(app);
75
+ export const PUT = handle(app);
76
+ export const DELETE = handle(app);
77
+ export const OPTIONS = handle(app);
78
+ export const HEAD = handle(app);
79
+ `;
80
+ }
81
+ writeVercelJSON(outputDirectory) {
82
+ fs.writeFileSync(
83
+ path.join(outputDirectory, "config.json"),
84
+ JSON.stringify({
85
+ version: 3,
86
+ routes: [
87
+ {
88
+ src: "/(.*)",
89
+ dest: "/"
90
+ }
91
+ ]
92
+ })
93
+ );
94
+ }
95
+ async bundle(entryFile, outputDirectory, toolsPaths) {
96
+ const result = await this._bundle(
97
+ this.getEntry(),
98
+ entryFile,
99
+ outputDirectory,
100
+ toolsPaths,
101
+ path.join(outputDirectory, this.outputDir)
102
+ );
103
+ const nodeVersion = process__default.default.version?.split(".")?.[0]?.replace("v", "") ?? "22";
104
+ fs.writeFileSync(
105
+ path.join(outputDirectory, this.outputDir, ".vc-config.json"),
106
+ JSON.stringify(
107
+ {
108
+ handler: "index.mjs",
109
+ launcherType: "Nodejs",
110
+ runtime: `nodejs${nodeVersion}.x`,
111
+ shouldAddHelpers: true
112
+ },
113
+ null,
114
+ 2
115
+ )
116
+ );
117
+ await esm.move(path.join(outputDirectory, ".vercel", "output"), path.join(process__default.default.cwd(), ".vercel", "output"), {
118
+ overwrite: true
119
+ });
120
+ return result;
121
+ }
122
+ async deploy() {
123
+ this.logger?.info("Deploying to Vercel is deprecated. Please use the Vercel dashboard to deploy.");
124
+ }
125
+ async lint(entryFile, outputDirectory, toolsPaths) {
126
+ await super.lint(entryFile, outputDirectory, toolsPaths);
127
+ const hasLibsql = await this.deps.checkDependencies(["@mastra/libsql"]) === `ok`;
128
+ if (hasLibsql) {
129
+ this.logger.error(
130
+ `Vercel Deployer does not support @libsql/client(which may have been installed by @mastra/libsql) as a dependency.
131
+ Use other Mastra Storage options instead e.g @mastra/pg`
132
+ );
133
+ process__default.default.exit(1);
134
+ }
135
+ }
136
+ };
137
+
138
+ exports.VercelDeployer = VercelDeployer;
@@ -0,0 +1 @@
1
+ export { VercelDeployer } from './_tsup-dts-rollup.cjs';
package/dist/index.js CHANGED
@@ -1,142 +1,130 @@
1
- import { Deployer } from '@mastra/deployer';
2
- import '@mastra/deployer/build';
3
- import '@rollup/plugin-virtual';
4
- import * as child_process from 'child_process';
5
- import { writeFileSync, readFileSync } from 'fs';
1
+ import { writeFileSync } from 'fs';
6
2
  import { join } from 'path';
7
3
  import process from 'process';
4
+ import { Deployer } from '@mastra/deployer';
5
+ import { move } from 'fs-extra/esm';
8
6
 
9
7
  // src/index.ts
10
8
  var VercelDeployer = class extends Deployer {
11
- teamId;
12
- projectName;
13
- token;
14
- constructor({ teamId, projectName, token }) {
9
+ constructor() {
15
10
  super({ name: "VERCEL" });
16
- this.teamId = teamId;
17
- this.projectName = projectName;
18
- this.token = token;
19
- }
20
- writeFiles(outputDirectory) {
21
- writeFileSync(
22
- join(outputDirectory, this.outputDir, "vercel.json"),
23
- JSON.stringify(
24
- {
25
- version: 2,
26
- installCommand: "npm install --omit=dev",
27
- builds: [
28
- {
29
- src: "index.mjs",
30
- use: "@vercel/node",
31
- config: { includeFiles: ["**"] }
32
- }
33
- ],
34
- routes: [
35
- {
36
- src: "/(.*)",
37
- dest: "index.mjs"
38
- }
39
- ]
40
- },
41
- null,
42
- 2
43
- )
44
- );
45
- }
46
- getProjectId({ dir }) {
47
- const projectJsonPath = join(dir, ".vercel", "project.json");
48
- try {
49
- const projectJson = JSON.parse(readFileSync(projectJsonPath, "utf-8"));
50
- return projectJson.projectId;
51
- } catch (error) {
52
- throw new Error("Could not find project ID. Make sure the project has been deployed first.");
53
- }
54
- }
55
- async syncEnv(envVars) {
56
- console.log("Syncing environment variables...");
57
- const vercelEnvVars = Array.from(envVars.entries()).map(([key, value]) => {
58
- if (!key || !value) {
59
- throw new Error(`Invalid environment variable format: ${key || value}`);
60
- }
61
- return {
62
- key,
63
- value,
64
- target: ["production", "preview", "development"],
65
- type: "plain"
66
- };
67
- });
68
- try {
69
- const projectId = this.getProjectId({ dir: process.cwd() });
70
- const response = await fetch(
71
- `https://api.vercel.com/v10/projects/${projectId}/env?teamId=${this.teamId}&upsert=true`,
72
- {
73
- method: "POST",
74
- headers: {
75
- Authorization: `Bearer ${this.token}`,
76
- "Content-Type": "application/json"
77
- },
78
- body: JSON.stringify(vercelEnvVars)
79
- }
80
- );
81
- if (!response.ok) {
82
- const error = await response.json();
83
- throw new Error(`Failed to sync environment variables: ${error.message}`);
84
- }
85
- console.log("\u2713 Successfully synced environment variables");
86
- } catch (error) {
87
- if (error instanceof Error) {
88
- console.error("Failed to sync environment variables:", error.message);
89
- } else {
90
- console.error("Failed to sync environment variables:", error);
91
- }
92
- throw error;
93
- }
11
+ this.outputDir = join(".vercel", "output", "functions", "index.func");
94
12
  }
95
13
  async prepare(outputDirectory) {
96
14
  await super.prepare(outputDirectory);
97
- await this.writeFiles(outputDirectory);
15
+ this.writeVercelJSON(join(outputDirectory, this.outputDir, "..", ".."));
98
16
  }
99
17
  getEntry() {
100
18
  return `
101
19
  import { handle } from 'hono/vercel'
102
20
  import { mastra } from '#mastra';
103
21
  import { createHonoServer } from '#server';
22
+ import { evaluate } from '@mastra/core/eval';
23
+ import { AvailableHooks, registerHook } from '@mastra/core/hooks';
24
+ import { TABLE_EVALS } from '@mastra/core/storage';
25
+ import { checkEvalStorageFields } from '@mastra/core/utils';
26
+
27
+ registerHook(AvailableHooks.ON_GENERATION, ({ input, output, metric, runId, agentName, instructions }) => {
28
+ evaluate({
29
+ agentName,
30
+ input,
31
+ metric,
32
+ output,
33
+ runId,
34
+ globalRunId: runId,
35
+ instructions,
36
+ });
37
+ });
38
+
39
+ registerHook(AvailableHooks.ON_EVALUATION, async traceObject => {
40
+ const storage = mastra.getStorage();
41
+ if (storage) {
42
+ // Check for required fields
43
+ const logger = mastra?.getLogger();
44
+ const areFieldsValid = checkEvalStorageFields(traceObject, logger);
45
+ if (!areFieldsValid) return;
46
+
47
+ await storage.insert({
48
+ tableName: TABLE_EVALS,
49
+ record: {
50
+ input: traceObject.input,
51
+ output: traceObject.output,
52
+ result: JSON.stringify(traceObject.result || {}),
53
+ agent_name: traceObject.agentName,
54
+ metric_name: traceObject.metricName,
55
+ instructions: traceObject.instructions,
56
+ test_info: null,
57
+ global_run_id: traceObject.globalRunId,
58
+ run_id: traceObject.runId,
59
+ created_at: new Date().toISOString(),
60
+ },
61
+ });
62
+ }
63
+ });
104
64
 
105
65
  const app = await createHonoServer(mastra);
106
66
 
107
67
  export const GET = handle(app);
108
68
  export const POST = handle(app);
69
+ export const PUT = handle(app);
70
+ export const DELETE = handle(app);
71
+ export const OPTIONS = handle(app);
72
+ export const HEAD = handle(app);
109
73
  `;
110
74
  }
111
- async bundle(entryFile, outputDirectory) {
112
- return this._bundle(this.getEntry(), entryFile, outputDirectory);
75
+ writeVercelJSON(outputDirectory) {
76
+ writeFileSync(
77
+ join(outputDirectory, "config.json"),
78
+ JSON.stringify({
79
+ version: 3,
80
+ routes: [
81
+ {
82
+ src: "/(.*)",
83
+ dest: "/"
84
+ }
85
+ ]
86
+ })
87
+ );
113
88
  }
114
- async deploy(outputDirectory) {
115
- const envVars = await this.loadEnvVars();
116
- const commandArgs = [
117
- "--scope",
118
- this.teamId,
119
- "--cwd",
120
- join(outputDirectory, this.outputDir),
121
- "--token",
122
- this.token,
123
- "deploy",
124
- "--yes",
125
- ...this.projectName ? ["--name", this.projectName] : []
126
- ];
127
- child_process.execSync(`npx vercel ${commandArgs.join(" ")}`, {
128
- cwd: join(outputDirectory, this.outputDir),
129
- env: {
130
- // ...this.env,
131
- PATH: process.env.PATH
132
- },
133
- stdio: "inherit"
89
+ async bundle(entryFile, outputDirectory, toolsPaths) {
90
+ const result = await this._bundle(
91
+ this.getEntry(),
92
+ entryFile,
93
+ outputDirectory,
94
+ toolsPaths,
95
+ join(outputDirectory, this.outputDir)
96
+ );
97
+ const nodeVersion = process.version?.split(".")?.[0]?.replace("v", "") ?? "22";
98
+ writeFileSync(
99
+ join(outputDirectory, this.outputDir, ".vc-config.json"),
100
+ JSON.stringify(
101
+ {
102
+ handler: "index.mjs",
103
+ launcherType: "Nodejs",
104
+ runtime: `nodejs${nodeVersion}.x`,
105
+ shouldAddHelpers: true
106
+ },
107
+ null,
108
+ 2
109
+ )
110
+ );
111
+ await move(join(outputDirectory, ".vercel", "output"), join(process.cwd(), ".vercel", "output"), {
112
+ overwrite: true
134
113
  });
135
- this.logger.info("Deployment started on Vercel. You can wait for it to finish or exit this command.");
136
- if (envVars.size > 0) {
137
- await this.syncEnv(envVars);
138
- } else {
139
- this.logger.info("\nAdd your ENV vars to .env or your vercel dashboard.\n");
114
+ return result;
115
+ }
116
+ async deploy() {
117
+ this.logger?.info("Deploying to Vercel is deprecated. Please use the Vercel dashboard to deploy.");
118
+ }
119
+ async lint(entryFile, outputDirectory, toolsPaths) {
120
+ await super.lint(entryFile, outputDirectory, toolsPaths);
121
+ const hasLibsql = await this.deps.checkDependencies(["@mastra/libsql"]) === `ok`;
122
+ if (hasLibsql) {
123
+ this.logger.error(
124
+ `Vercel Deployer does not support @libsql/client(which may have been installed by @mastra/libsql) as a dependency.
125
+ Use other Mastra Storage options instead e.g @mastra/pg`
126
+ );
127
+ process.exit(1);
140
128
  }
141
129
  }
142
130
  };
package/package.json CHANGED
@@ -1,37 +1,52 @@
1
1
  {
2
2
  "name": "@mastra/deployer-vercel",
3
- "version": "0.0.0-storage-20250225005900",
3
+ "version": "0.0.0-support-d1-client-20250701191943",
4
4
  "description": "",
5
5
  "type": "module",
6
+ "files": [
7
+ "dist"
8
+ ],
6
9
  "main": "dist/index.js",
7
10
  "types": "dist/index.d.ts",
8
11
  "exports": {
9
12
  ".": {
10
- "types": "./dist/index.d.ts",
11
- "default": "./dist/index.js"
13
+ "import": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ },
17
+ "require": {
18
+ "types": "./dist/index.d.cts",
19
+ "default": "./dist/index.cjs"
20
+ }
12
21
  },
13
22
  "./package.json": "./package.json"
14
23
  },
15
24
  "keywords": [],
16
25
  "author": "",
17
- "license": "ISC",
26
+ "license": "Elastic-2.0",
18
27
  "dependencies": {
19
28
  "@rollup/plugin-virtual": "^3.0.2",
20
- "fs-extra": "^11.2.0",
21
- "@mastra/core": "^0.0.0-storage-20250225005900",
22
- "@mastra/deployer": "^0.0.0-storage-20250225005900"
29
+ "fs-extra": "^11.3.0",
30
+ "@mastra/deployer": "0.0.0-support-d1-client-20250701191943"
23
31
  },
24
32
  "devDependencies": {
25
- "@microsoft/api-extractor": "^7.49.2",
26
- "@types/node": "^22.13.1",
27
- "tsup": "^8.0.1",
28
- "typescript": "^5.7.3",
29
- "vercel": "^39.3.0",
30
- "vitest": "^3.0.4"
33
+ "@microsoft/api-extractor": "^7.52.8",
34
+ "@types/fs-extra": "^11.0.4",
35
+ "@types/node": "^20.19.0",
36
+ "eslint": "^9.29.0",
37
+ "tsup": "^8.5.0",
38
+ "typescript": "^5.8.3",
39
+ "vitest": "^3.2.4",
40
+ "@internal/lint": "0.0.0-support-d1-client-20250701191943",
41
+ "@mastra/core": "0.0.0-support-d1-client-20250701191943"
42
+ },
43
+ "peerDependencies": {
44
+ "@mastra/core": "0.0.0-support-d1-client-20250701191943"
31
45
  },
32
46
  "scripts": {
33
- "build": "tsup src/index.ts --format esm --experimental-dts --clean --treeshake",
47
+ "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
34
48
  "build:watch": "pnpm build --watch",
35
- "test": "vitest run"
49
+ "test": "vitest run",
50
+ "lint": "eslint ."
36
51
  }
37
52
  }
@@ -1,19 +0,0 @@
1
-
2
- 
3
- > @mastra/deployer-vercel@0.1.5-alpha.1 build /Users/ward/projects/mastra/mastra/deployers/vercel
4
- > tsup src/index.ts --format esm --experimental-dts --clean --treeshake
5
-
6
- CLI Building entry: src/index.ts
7
- CLI Using tsconfig: tsconfig.json
8
- CLI tsup v8.3.6
9
- TSC Build start
10
- TSC ⚡️ Build success in 1574ms
11
- DTS Build start
12
- CLI Target: es2022
13
- Analysis will use the bundled TypeScript version 5.7.3
14
- Writing package typings: /Users/ward/projects/mastra/mastra/deployers/vercel/dist/_tsup-dts-rollup.d.ts
15
- DTS ⚡️ Build success in 1368ms
16
- CLI Cleaning output folder
17
- ESM Build start
18
- ESM dist/index.js 4.08 KB
19
- ESM ⚡️ Build success in 119ms