@mastra/deployer-vercel 0.0.0-vector-sources-20250516175436 → 0.0.0-vector-extension-schema-20250922130418
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 +3660 -0
- package/LICENSE.md +11 -42
- package/dist/index.cjs +42 -147
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +14 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -129
- package/dist/index.js.map +1 -0
- package/package.json +31 -17
- package/dist/_tsup-dts-rollup.d.cts +0 -23
- package/dist/_tsup-dts-rollup.d.ts +0 -23
- package/dist/index.d.cts +0 -1
package/LICENSE.md
CHANGED
|
@@ -1,46 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Apache License 2.0
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2025
|
|
3
|
+
Copyright (c) 2025 Kepler Software, Inc.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
|
|
17
|
-
|
|
18
|
-
**Patents**
|
|
19
|
-
The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
20
|
-
|
|
21
|
-
**Notices**
|
|
22
|
-
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
|
|
23
|
-
|
|
24
|
-
If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
|
|
25
|
-
|
|
26
|
-
**No Other Rights**
|
|
27
|
-
These terms do not imply any licenses other than those expressly granted in these terms.
|
|
28
|
-
|
|
29
|
-
**Termination**
|
|
30
|
-
If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
|
|
31
|
-
|
|
32
|
-
**No Liability**
|
|
33
|
-
As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
|
|
34
|
-
|
|
35
|
-
**Definitions**
|
|
36
|
-
The _licensor_ is the entity offering these terms, and the _software_ is the software the licensor makes available under these terms, including any portion of it.
|
|
37
|
-
|
|
38
|
-
_you_ refers to the individual or entity agreeing to these terms.
|
|
39
|
-
|
|
40
|
-
_your company_ is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. _control_ means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
41
|
-
|
|
42
|
-
_your licenses_ are all the licenses granted to you for the software under these terms.
|
|
43
|
-
|
|
44
|
-
_use_ means anything you do with the software requiring one of your licenses.
|
|
45
|
-
|
|
46
|
-
_trademark_ means trademarks, service marks, and similar rights.
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
package/dist/index.cjs
CHANGED
|
@@ -1,113 +1,31 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var child_process = require('child_process');
|
|
4
3
|
var fs = require('fs');
|
|
5
4
|
var path = require('path');
|
|
6
5
|
var process = require('process');
|
|
7
6
|
var deployer = require('@mastra/deployer');
|
|
7
|
+
var esm = require('fs-extra/esm');
|
|
8
8
|
|
|
9
9
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
10
|
|
|
11
|
-
function _interopNamespace(e) {
|
|
12
|
-
if (e && e.__esModule) return e;
|
|
13
|
-
var n = Object.create(null);
|
|
14
|
-
if (e) {
|
|
15
|
-
Object.keys(e).forEach(function (k) {
|
|
16
|
-
if (k !== 'default') {
|
|
17
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
18
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function () { return e[k]; }
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
n.default = e;
|
|
26
|
-
return Object.freeze(n);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
var child_process__namespace = /*#__PURE__*/_interopNamespace(child_process);
|
|
30
11
|
var process__default = /*#__PURE__*/_interopDefault(process);
|
|
31
12
|
|
|
32
13
|
// src/index.ts
|
|
33
14
|
var VercelDeployer = class extends deployer.Deployer {
|
|
34
|
-
|
|
35
|
-
projectName;
|
|
36
|
-
token;
|
|
37
|
-
constructor({ teamSlug, projectName, token }) {
|
|
15
|
+
constructor() {
|
|
38
16
|
super({ name: "VERCEL" });
|
|
39
|
-
this.
|
|
40
|
-
this.projectName = projectName;
|
|
41
|
-
this.token = token;
|
|
42
|
-
}
|
|
43
|
-
getProjectId({ dir }) {
|
|
44
|
-
const projectJsonPath = path.join(dir, "output", ".vercel", "project.json");
|
|
45
|
-
try {
|
|
46
|
-
const projectJson = JSON.parse(fs.readFileSync(projectJsonPath, "utf-8"));
|
|
47
|
-
return projectJson.projectId;
|
|
48
|
-
} catch {
|
|
49
|
-
throw new Error("Could not find project ID. Make sure the project has been deployed first.");
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
async getTeamId() {
|
|
53
|
-
const response = await fetch(`https://api.vercel.com/v2/teams`, {
|
|
54
|
-
headers: {
|
|
55
|
-
Authorization: `Bearer ${this.token}`
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
const res = await response.json();
|
|
59
|
-
const teams = res.teams;
|
|
60
|
-
return teams.find((team) => team.slug === this.teamSlug)?.id;
|
|
61
|
-
}
|
|
62
|
-
async syncEnv(envVars, { outputDirectory }) {
|
|
63
|
-
console.log("Syncing environment variables...");
|
|
64
|
-
const vercelEnvVars = Array.from(envVars.entries()).map(([key, value]) => {
|
|
65
|
-
if (!key || !value) {
|
|
66
|
-
throw new Error(`Invalid environment variable format: ${key || value}`);
|
|
67
|
-
}
|
|
68
|
-
return {
|
|
69
|
-
key,
|
|
70
|
-
value,
|
|
71
|
-
target: ["production", "preview", "development"],
|
|
72
|
-
type: "plain"
|
|
73
|
-
};
|
|
74
|
-
});
|
|
75
|
-
try {
|
|
76
|
-
const projectId = this.getProjectId({ dir: outputDirectory });
|
|
77
|
-
const teamId = await this.getTeamId();
|
|
78
|
-
const response = await fetch(
|
|
79
|
-
`https://api.vercel.com/v10/projects/${projectId}/env?teamId=${teamId}&upsert=true`,
|
|
80
|
-
{
|
|
81
|
-
method: "POST",
|
|
82
|
-
headers: {
|
|
83
|
-
Authorization: `Bearer ${this.token}`,
|
|
84
|
-
"Content-Type": "application/json"
|
|
85
|
-
},
|
|
86
|
-
body: JSON.stringify(vercelEnvVars)
|
|
87
|
-
}
|
|
88
|
-
);
|
|
89
|
-
if (!response.ok) {
|
|
90
|
-
const error = await response.json();
|
|
91
|
-
throw new Error(`Failed to sync environment variables: ${error.message}`);
|
|
92
|
-
}
|
|
93
|
-
console.log("\u2713 Successfully synced environment variables");
|
|
94
|
-
} catch (error) {
|
|
95
|
-
if (error instanceof Error) {
|
|
96
|
-
console.error("Failed to sync environment variables:", error.message);
|
|
97
|
-
} else {
|
|
98
|
-
console.error("Failed to sync environment variables:", error);
|
|
99
|
-
}
|
|
100
|
-
throw error;
|
|
101
|
-
}
|
|
17
|
+
this.outputDir = path.join(".vercel", "output", "functions", "index.func");
|
|
102
18
|
}
|
|
103
19
|
async prepare(outputDirectory) {
|
|
104
20
|
await super.prepare(outputDirectory);
|
|
21
|
+
this.writeVercelJSON(path.join(outputDirectory, this.outputDir, "..", ".."));
|
|
105
22
|
}
|
|
106
23
|
getEntry() {
|
|
107
24
|
return `
|
|
108
25
|
import { handle } from 'hono/vercel'
|
|
109
26
|
import { mastra } from '#mastra';
|
|
110
|
-
import { createHonoServer } from '#server';
|
|
27
|
+
import { createHonoServer, getToolExports } from '#server';
|
|
28
|
+
import { tools } from '#tools';
|
|
111
29
|
import { evaluate } from '@mastra/core/eval';
|
|
112
30
|
import { AvailableHooks, registerHook } from '@mastra/core/hooks';
|
|
113
31
|
import { TABLE_EVALS } from '@mastra/core/storage';
|
|
@@ -125,11 +43,6 @@ registerHook(AvailableHooks.ON_GENERATION, ({ input, output, metric, runId, agen
|
|
|
125
43
|
});
|
|
126
44
|
});
|
|
127
45
|
|
|
128
|
-
if (mastra.getStorage()) {
|
|
129
|
-
// start storage init in the background
|
|
130
|
-
mastra.getStorage().init();
|
|
131
|
-
}
|
|
132
|
-
|
|
133
46
|
registerHook(AvailableHooks.ON_EVALUATION, async traceObject => {
|
|
134
47
|
const storage = mastra.getStorage();
|
|
135
48
|
if (storage) {
|
|
@@ -156,82 +69,62 @@ registerHook(AvailableHooks.ON_EVALUATION, async traceObject => {
|
|
|
156
69
|
}
|
|
157
70
|
});
|
|
158
71
|
|
|
159
|
-
const app = await createHonoServer(mastra);
|
|
72
|
+
const app = await createHonoServer(mastra, { tools: getToolExports(tools) });
|
|
160
73
|
|
|
161
74
|
export const GET = handle(app);
|
|
162
75
|
export const POST = handle(app);
|
|
163
76
|
export const PUT = handle(app);
|
|
164
77
|
export const DELETE = handle(app);
|
|
78
|
+
export const PATCH = handle(app);
|
|
165
79
|
export const OPTIONS = handle(app);
|
|
166
80
|
export const HEAD = handle(app);
|
|
167
81
|
`;
|
|
168
82
|
}
|
|
169
|
-
writeVercelJSON(outputDirectory
|
|
83
|
+
writeVercelJSON(outputDirectory) {
|
|
84
|
+
fs.writeFileSync(
|
|
85
|
+
path.join(outputDirectory, "config.json"),
|
|
86
|
+
JSON.stringify({
|
|
87
|
+
version: 3,
|
|
88
|
+
routes: [
|
|
89
|
+
{
|
|
90
|
+
src: "/(.*)",
|
|
91
|
+
dest: "/"
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
})
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
async bundle(entryFile, outputDirectory, { toolsPaths, projectRoot }) {
|
|
98
|
+
const result = await this._bundle(
|
|
99
|
+
this.getEntry(),
|
|
100
|
+
entryFile,
|
|
101
|
+
{ outputDirectory, projectRoot },
|
|
102
|
+
toolsPaths,
|
|
103
|
+
path.join(outputDirectory, this.outputDir)
|
|
104
|
+
);
|
|
105
|
+
const nodeVersion = process__default.default.version?.split(".")?.[0]?.replace("v", "") ?? "22";
|
|
170
106
|
fs.writeFileSync(
|
|
171
|
-
path.join(outputDirectory, this.outputDir, "
|
|
107
|
+
path.join(outputDirectory, this.outputDir, ".vc-config.json"),
|
|
172
108
|
JSON.stringify(
|
|
173
109
|
{
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
src: "index.mjs",
|
|
179
|
-
use: "@vercel/node",
|
|
180
|
-
config: { includeFiles: files }
|
|
181
|
-
}
|
|
182
|
-
],
|
|
183
|
-
routes: [
|
|
184
|
-
{
|
|
185
|
-
src: "/(.*)",
|
|
186
|
-
dest: "index.mjs"
|
|
187
|
-
}
|
|
188
|
-
]
|
|
110
|
+
handler: "index.mjs",
|
|
111
|
+
launcherType: "Nodejs",
|
|
112
|
+
runtime: `nodejs${nodeVersion}.x`,
|
|
113
|
+
shouldAddHelpers: true
|
|
189
114
|
},
|
|
190
115
|
null,
|
|
191
116
|
2
|
|
192
117
|
)
|
|
193
118
|
);
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
const result = await this._bundle(this.getEntry(), entryFile, outputDirectory, toolsPaths);
|
|
197
|
-
const files = fs.readdirSync(path.join(outputDirectory, this.outputDir), {
|
|
198
|
-
recursive: true
|
|
119
|
+
await esm.move(path.join(outputDirectory, ".vercel", "output"), path.join(process__default.default.cwd(), ".vercel", "output"), {
|
|
120
|
+
overwrite: true
|
|
199
121
|
});
|
|
200
|
-
const filesWithoutNodeModules = files.filter(
|
|
201
|
-
(file) => typeof file === "string" && !file.startsWith("node_modules")
|
|
202
|
-
);
|
|
203
|
-
this.writeVercelJSON(outputDirectory, filesWithoutNodeModules);
|
|
204
122
|
return result;
|
|
205
123
|
}
|
|
206
|
-
async deploy(
|
|
207
|
-
|
|
208
|
-
const commandArgs = [
|
|
209
|
-
"--scope",
|
|
210
|
-
this.teamSlug,
|
|
211
|
-
"--cwd",
|
|
212
|
-
path.join(outputDirectory, this.outputDir),
|
|
213
|
-
"--token",
|
|
214
|
-
this.token,
|
|
215
|
-
"deploy",
|
|
216
|
-
"--yes",
|
|
217
|
-
...this.projectName ? ["--name", this.projectName] : []
|
|
218
|
-
];
|
|
219
|
-
child_process__namespace.execSync(`npx vercel ${commandArgs.join(" ")}`, {
|
|
220
|
-
cwd: path.join(outputDirectory, this.outputDir),
|
|
221
|
-
env: {
|
|
222
|
-
PATH: process__default.default.env.PATH
|
|
223
|
-
},
|
|
224
|
-
stdio: "inherit"
|
|
225
|
-
});
|
|
226
|
-
this.logger.info("Deployment started on Vercel. You can wait for it to finish or exit this command.");
|
|
227
|
-
if (envVars.size > 0) {
|
|
228
|
-
await this.syncEnv(envVars, { outputDirectory });
|
|
229
|
-
} else {
|
|
230
|
-
this.logger.info("\nAdd your ENV vars to .env or your vercel dashboard.\n");
|
|
231
|
-
}
|
|
124
|
+
async deploy() {
|
|
125
|
+
this.logger?.info("Deploying to Vercel is deprecated. Please use the Vercel dashboard to deploy.");
|
|
232
126
|
}
|
|
233
127
|
async lint(entryFile, outputDirectory, toolsPaths) {
|
|
234
|
-
await super.lint(entryFile, outputDirectory, toolsPaths);
|
|
235
128
|
await super.lint(entryFile, outputDirectory, toolsPaths);
|
|
236
129
|
const hasLibsql = await this.deps.checkDependencies(["@mastra/libsql"]) === `ok`;
|
|
237
130
|
if (hasLibsql) {
|
|
@@ -245,3 +138,5 @@ export const HEAD = handle(app);
|
|
|
245
138
|
};
|
|
246
139
|
|
|
247
140
|
exports.VercelDeployer = VercelDeployer;
|
|
141
|
+
//# sourceMappingURL=index.cjs.map
|
|
142
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["Deployer","join","writeFileSync","process","move"],"mappings":";;;;;;;;;;;;;AAMO,IAAM,cAAA,GAAN,cAA6BA,iBAAA,CAAS;AAAA,EAC3C,WAAA,GAAc;AACZ,IAAA,KAAA,CAAM,EAAE,IAAA,EAAM,QAAA,EAAU,CAAA;AACxB,IAAA,IAAA,CAAK,SAAA,GAAYC,SAAA,CAAK,SAAA,EAAW,QAAA,EAAU,aAAa,YAAY,CAAA;AAAA,EACtE;AAAA,EAEA,MAAM,QAAQ,eAAA,EAAwC;AACpD,IAAA,MAAM,KAAA,CAAM,QAAQ,eAAe,CAAA;AAEnC,IAAA,IAAA,CAAK,gBAAgBA,SAAA,CAAK,eAAA,EAAiB,KAAK,SAAA,EAAW,IAAA,EAAM,IAAI,CAAC,CAAA;AAAA,EACxE;AAAA,EAEQ,QAAA,GAAmB;AACzB,IAAA,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA;AAAA,EA0DT;AAAA,EAEQ,gBAAgB,eAAA,EAAyB;AAC/C,IAAAC,gBAAA;AAAA,MACED,SAAA,CAAK,iBAAiB,aAAa,CAAA;AAAA,MACnC,KAAK,SAAA,CAAU;AAAA,QACb,OAAA,EAAS,CAAA;AAAA,QACT,MAAA,EAAQ;AAAA,UACN;AAAA,YACE,GAAA,EAAK,OAAA;AAAA,YACL,IAAA,EAAM;AAAA;AACR;AACF,OACD;AAAA,KACH;AAAA,EACF;AAAA,EAEA,MAAM,MAAA,CACJ,SAAA,EACA,iBACA,EAAE,UAAA,EAAY,aAAY,EACX;AACf,IAAA,MAAM,MAAA,GAAS,MAAM,IAAA,CAAK,OAAA;AAAA,MACxB,KAAK,QAAA,EAAS;AAAA,MACd,SAAA;AAAA,MACA,EAAE,iBAAiB,WAAA,EAAY;AAAA,MAC/B,UAAA;AAAA,MACAA,SAAA,CAAK,eAAA,EAAiB,IAAA,CAAK,SAAS;AAAA,KACtC;AAEA,IAAA,MAAM,WAAA,GAAcE,wBAAA,CAAQ,OAAA,EAAS,KAAA,CAAM,GAAG,CAAA,GAAI,CAAC,CAAA,EAAG,OAAA,CAAQ,GAAA,EAAK,EAAE,CAAA,IAAK,IAAA;AAC1E,IAAAD,gBAAA;AAAA,MACED,SAAA,CAAK,eAAA,EAAiB,IAAA,CAAK,SAAA,EAAW,iBAAiB,CAAA;AAAA,MACvD,IAAA,CAAK,SAAA;AAAA,QACH;AAAA,UACE,OAAA,EAAS,WAAA;AAAA,UACT,YAAA,EAAc,QAAA;AAAA,UACd,OAAA,EAAS,SAAS,WAAW,CAAA,EAAA,CAAA;AAAA,UAC7B,gBAAA,EAAkB;AAAA,SACpB;AAAA,QACA,IAAA;AAAA,QACA;AAAA;AACF,KACF;AAEA,IAAA,MAAMG,QAAA,CAAKH,SAAA,CAAK,eAAA,EAAiB,SAAA,EAAW,QAAQ,CAAA,EAAGA,SAAA,CAAKE,wBAAA,CAAQ,GAAA,EAAI,EAAG,SAAA,EAAW,QAAQ,CAAA,EAAG;AAAA,MAC/F,SAAA,EAAW;AAAA,KACZ,CAAA;AAED,IAAA,OAAO,MAAA;AAAA,EACT;AAAA,EAEA,MAAM,MAAA,GAAwB;AAC5B,IAAA,IAAA,CAAK,MAAA,EAAQ,KAAK,+EAA+E,CAAA;AAAA,EACnG;AAAA,EAEA,MAAM,IAAA,CAAK,SAAA,EAAmB,eAAA,EAAyB,UAAA,EAAkD;AACvG,IAAA,MAAM,KAAA,CAAM,IAAA,CAAK,SAAA,EAAW,eAAA,EAAiB,UAAU,CAAA;AAEvD,IAAA,MAAM,SAAA,GAAa,MAAM,IAAA,CAAK,IAAA,CAAK,kBAAkB,CAAC,gBAAgB,CAAC,CAAA,KAAO,CAAA,EAAA,CAAA;AAE9E,IAAA,IAAI,SAAA,EAAW;AACb,MAAA,IAAA,CAAK,MAAA,CAAO,KAAA;AAAA,QACV,CAAA;AAAA,+DAAA;AAAA,OAEF;AACA,MAAAA,wBAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,IAChB;AAAA,EACF;AACF","file":"index.cjs","sourcesContent":["import { writeFileSync } from 'fs';\nimport { join } from 'path';\nimport process from 'process';\nimport { Deployer } from '@mastra/deployer';\nimport { move } from 'fs-extra/esm';\n\nexport class VercelDeployer extends Deployer {\n constructor() {\n super({ name: 'VERCEL' });\n this.outputDir = join('.vercel', 'output', 'functions', 'index.func');\n }\n\n async prepare(outputDirectory: string): Promise<void> {\n await super.prepare(outputDirectory);\n\n this.writeVercelJSON(join(outputDirectory, this.outputDir, '..', '..'));\n }\n\n private getEntry(): string {\n return `\nimport { handle } from 'hono/vercel'\nimport { mastra } from '#mastra';\nimport { createHonoServer, getToolExports } from '#server';\nimport { tools } from '#tools';\nimport { evaluate } from '@mastra/core/eval';\nimport { AvailableHooks, registerHook } from '@mastra/core/hooks';\nimport { TABLE_EVALS } from '@mastra/core/storage';\nimport { checkEvalStorageFields } from '@mastra/core/utils';\n\nregisterHook(AvailableHooks.ON_GENERATION, ({ input, output, metric, runId, agentName, instructions }) => {\n evaluate({\n agentName,\n input,\n metric,\n output,\n runId,\n globalRunId: runId,\n instructions,\n });\n});\n\nregisterHook(AvailableHooks.ON_EVALUATION, async traceObject => {\n const storage = mastra.getStorage();\n if (storage) {\n // Check for required fields\n const logger = mastra?.getLogger();\n const areFieldsValid = checkEvalStorageFields(traceObject, logger);\n if (!areFieldsValid) return;\n\n await storage.insert({\n tableName: TABLE_EVALS,\n record: {\n input: traceObject.input,\n output: traceObject.output,\n result: JSON.stringify(traceObject.result || {}),\n agent_name: traceObject.agentName,\n metric_name: traceObject.metricName,\n instructions: traceObject.instructions,\n test_info: null,\n global_run_id: traceObject.globalRunId,\n run_id: traceObject.runId,\n created_at: new Date().toISOString(),\n },\n });\n }\n});\n\nconst app = await createHonoServer(mastra, { tools: getToolExports(tools) });\n\nexport const GET = handle(app);\nexport const POST = handle(app);\nexport const PUT = handle(app);\nexport const DELETE = handle(app);\nexport const PATCH = handle(app);\nexport const OPTIONS = handle(app);\nexport const HEAD = handle(app);\n`;\n }\n\n private writeVercelJSON(outputDirectory: string) {\n writeFileSync(\n join(outputDirectory, 'config.json'),\n JSON.stringify({\n version: 3,\n routes: [\n {\n src: '/(.*)',\n dest: '/',\n },\n ],\n }),\n );\n }\n\n async bundle(\n entryFile: string,\n outputDirectory: string,\n { toolsPaths, projectRoot }: { toolsPaths: (string | string[])[]; projectRoot: string },\n ): Promise<void> {\n const result = await this._bundle(\n this.getEntry(),\n entryFile,\n { outputDirectory, projectRoot },\n toolsPaths,\n join(outputDirectory, this.outputDir),\n );\n\n const nodeVersion = process.version?.split('.')?.[0]?.replace('v', '') ?? '22';\n writeFileSync(\n join(outputDirectory, this.outputDir, '.vc-config.json'),\n JSON.stringify(\n {\n handler: 'index.mjs',\n launcherType: 'Nodejs',\n runtime: `nodejs${nodeVersion}.x`,\n shouldAddHelpers: true,\n },\n null,\n 2,\n ),\n );\n\n await move(join(outputDirectory, '.vercel', 'output'), join(process.cwd(), '.vercel', 'output'), {\n overwrite: true,\n });\n\n return result;\n }\n\n async deploy(): Promise<void> {\n this.logger?.info('Deploying to Vercel is deprecated. Please use the Vercel dashboard to deploy.');\n }\n\n async lint(entryFile: string, outputDirectory: string, toolsPaths: (string | string[])[]): Promise<void> {\n await super.lint(entryFile, outputDirectory, toolsPaths);\n\n const hasLibsql = (await this.deps.checkDependencies(['@mastra/libsql'])) === `ok`;\n\n if (hasLibsql) {\n this.logger.error(\n `Vercel Deployer does not support @libsql/client(which may have been installed by @mastra/libsql) as a dependency. \n Use other Mastra Storage options instead e.g @mastra/pg`,\n );\n process.exit(1);\n }\n }\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { Deployer } from '@mastra/deployer';
|
|
2
|
+
export declare class VercelDeployer extends Deployer {
|
|
3
|
+
constructor();
|
|
4
|
+
prepare(outputDirectory: string): Promise<void>;
|
|
5
|
+
private getEntry;
|
|
6
|
+
private writeVercelJSON;
|
|
7
|
+
bundle(entryFile: string, outputDirectory: string, { toolsPaths, projectRoot }: {
|
|
8
|
+
toolsPaths: (string | string[])[];
|
|
9
|
+
projectRoot: string;
|
|
10
|
+
}): Promise<void>;
|
|
11
|
+
deploy(): Promise<void>;
|
|
12
|
+
lint(entryFile: string, outputDirectory: string, toolsPaths: (string | string[])[]): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAG5C,qBAAa,cAAe,SAAQ,QAAQ;;IAMpC,OAAO,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAMrD,OAAO,CAAC,QAAQ;IA6DhB,OAAO,CAAC,eAAe;IAejB,MAAM,CACV,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,EACvB,EAAE,UAAU,EAAE,WAAW,EAAE,EAAE;QAAE,UAAU,EAAE,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,GACtF,OAAO,CAAC,IAAI,CAAC;IA+BV,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAIvB,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAazG"}
|
package/dist/index.js
CHANGED
|
@@ -1,88 +1,25 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { readFileSync, writeFileSync, readdirSync } from 'fs';
|
|
1
|
+
import { writeFileSync } from 'fs';
|
|
3
2
|
import { join } from 'path';
|
|
4
3
|
import process from 'process';
|
|
5
4
|
import { Deployer } from '@mastra/deployer';
|
|
5
|
+
import { move } from 'fs-extra/esm';
|
|
6
6
|
|
|
7
7
|
// src/index.ts
|
|
8
8
|
var VercelDeployer = class extends Deployer {
|
|
9
|
-
|
|
10
|
-
projectName;
|
|
11
|
-
token;
|
|
12
|
-
constructor({ teamSlug, projectName, token }) {
|
|
9
|
+
constructor() {
|
|
13
10
|
super({ name: "VERCEL" });
|
|
14
|
-
this.
|
|
15
|
-
this.projectName = projectName;
|
|
16
|
-
this.token = token;
|
|
17
|
-
}
|
|
18
|
-
getProjectId({ dir }) {
|
|
19
|
-
const projectJsonPath = join(dir, "output", ".vercel", "project.json");
|
|
20
|
-
try {
|
|
21
|
-
const projectJson = JSON.parse(readFileSync(projectJsonPath, "utf-8"));
|
|
22
|
-
return projectJson.projectId;
|
|
23
|
-
} catch {
|
|
24
|
-
throw new Error("Could not find project ID. Make sure the project has been deployed first.");
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
async getTeamId() {
|
|
28
|
-
const response = await fetch(`https://api.vercel.com/v2/teams`, {
|
|
29
|
-
headers: {
|
|
30
|
-
Authorization: `Bearer ${this.token}`
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
const res = await response.json();
|
|
34
|
-
const teams = res.teams;
|
|
35
|
-
return teams.find((team) => team.slug === this.teamSlug)?.id;
|
|
36
|
-
}
|
|
37
|
-
async syncEnv(envVars, { outputDirectory }) {
|
|
38
|
-
console.log("Syncing environment variables...");
|
|
39
|
-
const vercelEnvVars = Array.from(envVars.entries()).map(([key, value]) => {
|
|
40
|
-
if (!key || !value) {
|
|
41
|
-
throw new Error(`Invalid environment variable format: ${key || value}`);
|
|
42
|
-
}
|
|
43
|
-
return {
|
|
44
|
-
key,
|
|
45
|
-
value,
|
|
46
|
-
target: ["production", "preview", "development"],
|
|
47
|
-
type: "plain"
|
|
48
|
-
};
|
|
49
|
-
});
|
|
50
|
-
try {
|
|
51
|
-
const projectId = this.getProjectId({ dir: outputDirectory });
|
|
52
|
-
const teamId = await this.getTeamId();
|
|
53
|
-
const response = await fetch(
|
|
54
|
-
`https://api.vercel.com/v10/projects/${projectId}/env?teamId=${teamId}&upsert=true`,
|
|
55
|
-
{
|
|
56
|
-
method: "POST",
|
|
57
|
-
headers: {
|
|
58
|
-
Authorization: `Bearer ${this.token}`,
|
|
59
|
-
"Content-Type": "application/json"
|
|
60
|
-
},
|
|
61
|
-
body: JSON.stringify(vercelEnvVars)
|
|
62
|
-
}
|
|
63
|
-
);
|
|
64
|
-
if (!response.ok) {
|
|
65
|
-
const error = await response.json();
|
|
66
|
-
throw new Error(`Failed to sync environment variables: ${error.message}`);
|
|
67
|
-
}
|
|
68
|
-
console.log("\u2713 Successfully synced environment variables");
|
|
69
|
-
} catch (error) {
|
|
70
|
-
if (error instanceof Error) {
|
|
71
|
-
console.error("Failed to sync environment variables:", error.message);
|
|
72
|
-
} else {
|
|
73
|
-
console.error("Failed to sync environment variables:", error);
|
|
74
|
-
}
|
|
75
|
-
throw error;
|
|
76
|
-
}
|
|
11
|
+
this.outputDir = join(".vercel", "output", "functions", "index.func");
|
|
77
12
|
}
|
|
78
13
|
async prepare(outputDirectory) {
|
|
79
14
|
await super.prepare(outputDirectory);
|
|
15
|
+
this.writeVercelJSON(join(outputDirectory, this.outputDir, "..", ".."));
|
|
80
16
|
}
|
|
81
17
|
getEntry() {
|
|
82
18
|
return `
|
|
83
19
|
import { handle } from 'hono/vercel'
|
|
84
20
|
import { mastra } from '#mastra';
|
|
85
|
-
import { createHonoServer } from '#server';
|
|
21
|
+
import { createHonoServer, getToolExports } from '#server';
|
|
22
|
+
import { tools } from '#tools';
|
|
86
23
|
import { evaluate } from '@mastra/core/eval';
|
|
87
24
|
import { AvailableHooks, registerHook } from '@mastra/core/hooks';
|
|
88
25
|
import { TABLE_EVALS } from '@mastra/core/storage';
|
|
@@ -100,11 +37,6 @@ registerHook(AvailableHooks.ON_GENERATION, ({ input, output, metric, runId, agen
|
|
|
100
37
|
});
|
|
101
38
|
});
|
|
102
39
|
|
|
103
|
-
if (mastra.getStorage()) {
|
|
104
|
-
// start storage init in the background
|
|
105
|
-
mastra.getStorage().init();
|
|
106
|
-
}
|
|
107
|
-
|
|
108
40
|
registerHook(AvailableHooks.ON_EVALUATION, async traceObject => {
|
|
109
41
|
const storage = mastra.getStorage();
|
|
110
42
|
if (storage) {
|
|
@@ -131,82 +63,62 @@ registerHook(AvailableHooks.ON_EVALUATION, async traceObject => {
|
|
|
131
63
|
}
|
|
132
64
|
});
|
|
133
65
|
|
|
134
|
-
const app = await createHonoServer(mastra);
|
|
66
|
+
const app = await createHonoServer(mastra, { tools: getToolExports(tools) });
|
|
135
67
|
|
|
136
68
|
export const GET = handle(app);
|
|
137
69
|
export const POST = handle(app);
|
|
138
70
|
export const PUT = handle(app);
|
|
139
71
|
export const DELETE = handle(app);
|
|
72
|
+
export const PATCH = handle(app);
|
|
140
73
|
export const OPTIONS = handle(app);
|
|
141
74
|
export const HEAD = handle(app);
|
|
142
75
|
`;
|
|
143
76
|
}
|
|
144
|
-
writeVercelJSON(outputDirectory
|
|
77
|
+
writeVercelJSON(outputDirectory) {
|
|
145
78
|
writeFileSync(
|
|
146
|
-
join(outputDirectory,
|
|
79
|
+
join(outputDirectory, "config.json"),
|
|
80
|
+
JSON.stringify({
|
|
81
|
+
version: 3,
|
|
82
|
+
routes: [
|
|
83
|
+
{
|
|
84
|
+
src: "/(.*)",
|
|
85
|
+
dest: "/"
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
})
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
async bundle(entryFile, outputDirectory, { toolsPaths, projectRoot }) {
|
|
92
|
+
const result = await this._bundle(
|
|
93
|
+
this.getEntry(),
|
|
94
|
+
entryFile,
|
|
95
|
+
{ outputDirectory, projectRoot },
|
|
96
|
+
toolsPaths,
|
|
97
|
+
join(outputDirectory, this.outputDir)
|
|
98
|
+
);
|
|
99
|
+
const nodeVersion = process.version?.split(".")?.[0]?.replace("v", "") ?? "22";
|
|
100
|
+
writeFileSync(
|
|
101
|
+
join(outputDirectory, this.outputDir, ".vc-config.json"),
|
|
147
102
|
JSON.stringify(
|
|
148
103
|
{
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
src: "index.mjs",
|
|
154
|
-
use: "@vercel/node",
|
|
155
|
-
config: { includeFiles: files }
|
|
156
|
-
}
|
|
157
|
-
],
|
|
158
|
-
routes: [
|
|
159
|
-
{
|
|
160
|
-
src: "/(.*)",
|
|
161
|
-
dest: "index.mjs"
|
|
162
|
-
}
|
|
163
|
-
]
|
|
104
|
+
handler: "index.mjs",
|
|
105
|
+
launcherType: "Nodejs",
|
|
106
|
+
runtime: `nodejs${nodeVersion}.x`,
|
|
107
|
+
shouldAddHelpers: true
|
|
164
108
|
},
|
|
165
109
|
null,
|
|
166
110
|
2
|
|
167
111
|
)
|
|
168
112
|
);
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
const result = await this._bundle(this.getEntry(), entryFile, outputDirectory, toolsPaths);
|
|
172
|
-
const files = readdirSync(join(outputDirectory, this.outputDir), {
|
|
173
|
-
recursive: true
|
|
113
|
+
await move(join(outputDirectory, ".vercel", "output"), join(process.cwd(), ".vercel", "output"), {
|
|
114
|
+
overwrite: true
|
|
174
115
|
});
|
|
175
|
-
const filesWithoutNodeModules = files.filter(
|
|
176
|
-
(file) => typeof file === "string" && !file.startsWith("node_modules")
|
|
177
|
-
);
|
|
178
|
-
this.writeVercelJSON(outputDirectory, filesWithoutNodeModules);
|
|
179
116
|
return result;
|
|
180
117
|
}
|
|
181
|
-
async deploy(
|
|
182
|
-
|
|
183
|
-
const commandArgs = [
|
|
184
|
-
"--scope",
|
|
185
|
-
this.teamSlug,
|
|
186
|
-
"--cwd",
|
|
187
|
-
join(outputDirectory, this.outputDir),
|
|
188
|
-
"--token",
|
|
189
|
-
this.token,
|
|
190
|
-
"deploy",
|
|
191
|
-
"--yes",
|
|
192
|
-
...this.projectName ? ["--name", this.projectName] : []
|
|
193
|
-
];
|
|
194
|
-
child_process.execSync(`npx vercel ${commandArgs.join(" ")}`, {
|
|
195
|
-
cwd: join(outputDirectory, this.outputDir),
|
|
196
|
-
env: {
|
|
197
|
-
PATH: process.env.PATH
|
|
198
|
-
},
|
|
199
|
-
stdio: "inherit"
|
|
200
|
-
});
|
|
201
|
-
this.logger.info("Deployment started on Vercel. You can wait for it to finish or exit this command.");
|
|
202
|
-
if (envVars.size > 0) {
|
|
203
|
-
await this.syncEnv(envVars, { outputDirectory });
|
|
204
|
-
} else {
|
|
205
|
-
this.logger.info("\nAdd your ENV vars to .env or your vercel dashboard.\n");
|
|
206
|
-
}
|
|
118
|
+
async deploy() {
|
|
119
|
+
this.logger?.info("Deploying to Vercel is deprecated. Please use the Vercel dashboard to deploy.");
|
|
207
120
|
}
|
|
208
121
|
async lint(entryFile, outputDirectory, toolsPaths) {
|
|
209
|
-
await super.lint(entryFile, outputDirectory, toolsPaths);
|
|
210
122
|
await super.lint(entryFile, outputDirectory, toolsPaths);
|
|
211
123
|
const hasLibsql = await this.deps.checkDependencies(["@mastra/libsql"]) === `ok`;
|
|
212
124
|
if (hasLibsql) {
|
|
@@ -220,3 +132,5 @@ export const HEAD = handle(app);
|
|
|
220
132
|
};
|
|
221
133
|
|
|
222
134
|
export { VercelDeployer };
|
|
135
|
+
//# sourceMappingURL=index.js.map
|
|
136
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"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","file":"index.js","sourcesContent":["import { writeFileSync } from 'fs';\nimport { join } from 'path';\nimport process from 'process';\nimport { Deployer } from '@mastra/deployer';\nimport { move } from 'fs-extra/esm';\n\nexport class VercelDeployer extends Deployer {\n constructor() {\n super({ name: 'VERCEL' });\n this.outputDir = join('.vercel', 'output', 'functions', 'index.func');\n }\n\n async prepare(outputDirectory: string): Promise<void> {\n await super.prepare(outputDirectory);\n\n this.writeVercelJSON(join(outputDirectory, this.outputDir, '..', '..'));\n }\n\n private getEntry(): string {\n return `\nimport { handle } from 'hono/vercel'\nimport { mastra } from '#mastra';\nimport { createHonoServer, getToolExports } from '#server';\nimport { tools } from '#tools';\nimport { evaluate } from '@mastra/core/eval';\nimport { AvailableHooks, registerHook } from '@mastra/core/hooks';\nimport { TABLE_EVALS } from '@mastra/core/storage';\nimport { checkEvalStorageFields } from '@mastra/core/utils';\n\nregisterHook(AvailableHooks.ON_GENERATION, ({ input, output, metric, runId, agentName, instructions }) => {\n evaluate({\n agentName,\n input,\n metric,\n output,\n runId,\n globalRunId: runId,\n instructions,\n });\n});\n\nregisterHook(AvailableHooks.ON_EVALUATION, async traceObject => {\n const storage = mastra.getStorage();\n if (storage) {\n // Check for required fields\n const logger = mastra?.getLogger();\n const areFieldsValid = checkEvalStorageFields(traceObject, logger);\n if (!areFieldsValid) return;\n\n await storage.insert({\n tableName: TABLE_EVALS,\n record: {\n input: traceObject.input,\n output: traceObject.output,\n result: JSON.stringify(traceObject.result || {}),\n agent_name: traceObject.agentName,\n metric_name: traceObject.metricName,\n instructions: traceObject.instructions,\n test_info: null,\n global_run_id: traceObject.globalRunId,\n run_id: traceObject.runId,\n created_at: new Date().toISOString(),\n },\n });\n }\n});\n\nconst app = await createHonoServer(mastra, { tools: getToolExports(tools) });\n\nexport const GET = handle(app);\nexport const POST = handle(app);\nexport const PUT = handle(app);\nexport const DELETE = handle(app);\nexport const PATCH = handle(app);\nexport const OPTIONS = handle(app);\nexport const HEAD = handle(app);\n`;\n }\n\n private writeVercelJSON(outputDirectory: string) {\n writeFileSync(\n join(outputDirectory, 'config.json'),\n JSON.stringify({\n version: 3,\n routes: [\n {\n src: '/(.*)',\n dest: '/',\n },\n ],\n }),\n );\n }\n\n async bundle(\n entryFile: string,\n outputDirectory: string,\n { toolsPaths, projectRoot }: { toolsPaths: (string | string[])[]; projectRoot: string },\n ): Promise<void> {\n const result = await this._bundle(\n this.getEntry(),\n entryFile,\n { outputDirectory, projectRoot },\n toolsPaths,\n join(outputDirectory, this.outputDir),\n );\n\n const nodeVersion = process.version?.split('.')?.[0]?.replace('v', '') ?? '22';\n writeFileSync(\n join(outputDirectory, this.outputDir, '.vc-config.json'),\n JSON.stringify(\n {\n handler: 'index.mjs',\n launcherType: 'Nodejs',\n runtime: `nodejs${nodeVersion}.x`,\n shouldAddHelpers: true,\n },\n null,\n 2,\n ),\n );\n\n await move(join(outputDirectory, '.vercel', 'output'), join(process.cwd(), '.vercel', 'output'), {\n overwrite: true,\n });\n\n return result;\n }\n\n async deploy(): Promise<void> {\n this.logger?.info('Deploying to Vercel is deprecated. Please use the Vercel dashboard to deploy.');\n }\n\n async lint(entryFile: string, outputDirectory: string, toolsPaths: (string | string[])[]): Promise<void> {\n await super.lint(entryFile, outputDirectory, toolsPaths);\n\n const hasLibsql = (await this.deps.checkDependencies(['@mastra/libsql'])) === `ok`;\n\n if (hasLibsql) {\n this.logger.error(\n `Vercel Deployer does not support @libsql/client(which may have been installed by @mastra/libsql) as a dependency. \n Use other Mastra Storage options instead e.g @mastra/pg`,\n );\n process.exit(1);\n }\n }\n}\n"]}
|