@mastra/deployer-cloud 0.0.0-error-handler-fix-20251020202607 → 0.0.0-esbuild-bundle-worker-20260807182016
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 +3488 -5
- package/LICENSE.md +15 -0
- package/README.md +2 -3
- package/dist/index.cjs +366 -363
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +7 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +340 -336
- package/dist/index.js.map +1 -1
- package/dist/studio/assets/CommitMono-400-Regular-DzkyLZ26.woff2 +0 -0
- package/dist/studio/assets/CommitMono-700-Regular-DmOSN4kd.woff2 +0 -0
- package/dist/studio/assets/MonaSans-VariableFont_wdth-wght-CX-7s9jm.ttf +0 -0
- package/dist/studio/assets/babel-lWBcy2sH.js +16 -0
- package/dist/studio/assets/bash-atvbtKCR.js +1 -0
- package/dist/studio/assets/core-uJnW0DDG.js +12 -0
- package/dist/studio/assets/engine-compile-BkERmzkH.js +137 -0
- package/dist/studio/assets/engine-javascript-CSIo_1eZ.js +1 -0
- package/dist/studio/assets/estree-Dd9JfUIE.js +44 -0
- package/dist/studio/assets/github-dark-DHJKELXO.js +1 -0
- package/dist/studio/assets/github-light-DAi9KRSo.js +1 -0
- package/dist/studio/assets/index-BWC9t29j.js +2 -0
- package/dist/studio/assets/index-yUiD89B4.js +1 -0
- package/dist/studio/assets/javascript-ySlJ1b_l.js +1 -0
- package/dist/studio/assets/json-BQoSv7ci.js +1 -0
- package/dist/studio/assets/jsx-BAng5TT0.js +1 -0
- package/dist/studio/assets/livekit-client.esm-CKIgC2IJ.js +39 -0
- package/dist/studio/assets/main-D0m4O3FR.js +768 -0
- package/dist/studio/assets/markdown-UIAJJxZW.js +1 -0
- package/dist/studio/assets/preload-helper-PPVm8Dsz.js +1 -0
- package/dist/studio/assets/python-DhUJRlN_.js +1 -0
- package/dist/studio/assets/shell-CjFT_Tl9.js +1 -0
- package/dist/studio/assets/standalone-Dfz2oS5J.js +29 -0
- package/dist/studio/assets/style-B7CpWlks.css +1 -0
- package/dist/studio/assets/tsx-B6W0miNI.js +1 -0
- package/dist/studio/assets/typescript-Dj6nwHGl.js +1 -0
- package/dist/studio/index.html +100 -0
- package/dist/studio/mastra.svg +17 -0
- package/dist/studio/routes-manifest.json +27 -0
- package/dist/utils/auth.d.ts.map +1 -1
- package/dist/utils/deps.d.ts.map +1 -1
- package/dist/utils/execa.d.ts +2 -2
- package/dist/utils/execa.d.ts.map +1 -1
- package/dist/utils/logger.d.ts +4 -4
- package/dist/utils/logger.d.ts.map +1 -1
- package/package.json +26 -19
- package/versions.json +1 -1
- package/templates/instrumentation-template.js +0 -69
package/dist/index.cjs
CHANGED
|
@@ -1,297 +1,325 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
let path = require("path");
|
|
25
|
+
let url = require("url");
|
|
26
|
+
let _mastra_deployer = require("@mastra/deployer");
|
|
27
|
+
let fs_extra_esm = require("fs-extra/esm");
|
|
28
|
+
let os = require("os");
|
|
29
|
+
os = __toESM(os, 1);
|
|
30
|
+
let fs = require("fs");
|
|
31
|
+
fs = __toESM(fs, 1);
|
|
32
|
+
let _mastra_core_error = require("@mastra/core/error");
|
|
33
|
+
let stream = require("stream");
|
|
34
|
+
let execa = require("execa");
|
|
35
|
+
let _mastra_core_logger = require("@mastra/core/logger");
|
|
36
|
+
let _mastra_loggers = require("@mastra/loggers");
|
|
37
|
+
let redis = require("redis");
|
|
38
|
+
//#region src/utils/auth.ts
|
|
39
|
+
function getAuthEntrypoint() {
|
|
40
|
+
const tokensObject = {};
|
|
41
|
+
if (process.env.PLAYGROUND_JWT_TOKEN) tokensObject[process.env.PLAYGROUND_JWT_TOKEN] = {
|
|
42
|
+
id: "business-api",
|
|
43
|
+
role: "api"
|
|
44
|
+
};
|
|
45
|
+
if (process.env.BUSINESS_JWT_TOKEN) tokensObject[process.env.BUSINESS_JWT_TOKEN] = {
|
|
46
|
+
id: "business-api",
|
|
47
|
+
role: "api"
|
|
48
|
+
};
|
|
49
|
+
return `
|
|
50
|
+
import { SimpleAuth, CompositeAuth } from '@mastra/core/server';
|
|
51
|
+
import { MastraCloudAuthProvider, MastraRBACCloud } from '@mastra/auth-cloud';
|
|
15
52
|
|
|
16
|
-
|
|
17
|
-
|
|
53
|
+
// Service token auth (for business-api, playground internal calls)
|
|
54
|
+
class MastraCloudServiceAuth extends SimpleAuth {
|
|
55
|
+
constructor() {
|
|
56
|
+
super({
|
|
57
|
+
tokens: ${JSON.stringify(tokensObject)}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
18
60
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
Object.keys(e).forEach(function (k) {
|
|
24
|
-
if (k !== 'default') {
|
|
25
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
26
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
27
|
-
enumerable: true,
|
|
28
|
-
get: function () { return e[k]; }
|
|
29
|
-
});
|
|
61
|
+
async authorizeUser(user, request) {
|
|
62
|
+
// Allow access to /api path
|
|
63
|
+
if (request && request.url && new URL(request.url).pathname === '/api') {
|
|
64
|
+
return true;
|
|
30
65
|
}
|
|
31
|
-
|
|
66
|
+
// Allow access for business-api users
|
|
67
|
+
if (user && user.id === 'business-api') {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
32
72
|
}
|
|
33
|
-
n.default = e;
|
|
34
|
-
return Object.freeze(n);
|
|
35
|
-
}
|
|
36
73
|
|
|
37
|
-
|
|
38
|
-
var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
|
|
74
|
+
const serviceAuth = new MastraCloudServiceAuth();
|
|
39
75
|
|
|
40
|
-
//
|
|
76
|
+
// Cloud user auth (for end users via OAuth)
|
|
77
|
+
// Only enabled if MASTRA_CLOUD_API_URL is set
|
|
78
|
+
let cloudUserAuth = null;
|
|
79
|
+
if (process.env.MASTRA_CLOUD_API_URL) {
|
|
80
|
+
cloudUserAuth = new MastraCloudAuthProvider({
|
|
81
|
+
projectId: process.env.PROJECT_ID,
|
|
82
|
+
cloudBaseUrl: process.env.MASTRA_CLOUD_API_URL,
|
|
83
|
+
callbackUrl: process.env.MASTRA_CLOUD_CALLBACK_URL || \`\${process.env.MASTRA_CLOUD_API_URL}/auth/callback\`,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
41
86
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return `
|
|
45
|
-
import { MastraAuthProvider } from '@mastra/core/server';
|
|
87
|
+
const serverConfig = mastra.getServer();
|
|
88
|
+
const userAuth = serverConfig?.auth;
|
|
46
89
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
90
|
+
// Only enable auth if cloudUserAuth or userAuth are defined
|
|
91
|
+
if (serverConfig && (cloudUserAuth || userAuth)) {
|
|
92
|
+
// Build provider list: service auth first, then cloud user auth, then user's custom auth
|
|
93
|
+
const providers = [serviceAuth];
|
|
94
|
+
if (cloudUserAuth) {
|
|
95
|
+
providers.push(cloudUserAuth);
|
|
51
96
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (typeof args[0] === 'string') {
|
|
55
|
-
const token = args[0].replace('Bearer ', '');
|
|
56
|
-
const validTokens = [];
|
|
57
|
-
${process.env.PLAYGROUND_JWT_TOKEN ? `validTokens.push('${process.env.PLAYGROUND_JWT_TOKEN}');` : ""}
|
|
58
|
-
${process.env.BUSINESS_JWT_TOKEN ? `validTokens.push('${process.env.BUSINESS_JWT_TOKEN}');` : ""}
|
|
59
|
-
|
|
60
|
-
if (validTokens.includes(token)) {
|
|
61
|
-
return { id: 'business-api' }
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return this.auth.authenticateToken(...args)
|
|
97
|
+
if (userAuth) {
|
|
98
|
+
providers.push(userAuth);
|
|
65
99
|
}
|
|
66
100
|
|
|
67
|
-
|
|
68
|
-
if (args[1] && args[1].path === '/api') {
|
|
69
|
-
return true
|
|
70
|
-
}
|
|
71
|
-
if (args[0] && args[0].id === 'business-api') {
|
|
72
|
-
return true
|
|
73
|
-
}
|
|
74
|
-
return this.auth.authorizeUser(...args)
|
|
75
|
-
}
|
|
76
|
-
}
|
|
101
|
+
serverConfig.auth = new CompositeAuth(providers);
|
|
77
102
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
103
|
+
// If cloud auth is enabled but no RBAC is configured, add default cloud RBAC
|
|
104
|
+
if (cloudUserAuth && !serverConfig.rbac) {
|
|
105
|
+
serverConfig.rbac = new MastraRBACCloud({
|
|
106
|
+
roleMapping: {
|
|
107
|
+
owner: ['*'],
|
|
108
|
+
admin: ['*:read', '*:write', '*:execute'],
|
|
109
|
+
api: ['*:read', '*:write', '*:execute'],
|
|
110
|
+
member: ['*:read', '*:execute'],
|
|
111
|
+
viewer: ['*:read'],
|
|
112
|
+
_default: [],
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
}
|
|
82
116
|
}
|
|
83
117
|
`;
|
|
84
118
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/utils/constants.ts
|
|
121
|
+
const LOCAL = process.env.LOCAL === "true";
|
|
122
|
+
const TEAM_ID = process.env.TEAM_ID ?? "";
|
|
123
|
+
const PROJECT_ID = process.env.PROJECT_ID ?? "";
|
|
124
|
+
const BUILD_ID = process.env.BUILD_ID ?? "";
|
|
125
|
+
const BUILD_URL = process.env.BUILD_URL ?? "";
|
|
126
|
+
const LOG_REDIS_URL = process.env.LOG_REDIS_URL ?? "redis://localhost:6379";
|
|
127
|
+
process.env.BUSINESS_JWT_TOKEN;
|
|
128
|
+
process.env.PLAYGROUND_JWT_TOKEN;
|
|
129
|
+
const USER_IP_ADDRESS = process.env.USER_IP_ADDRESS ?? "";
|
|
130
|
+
const MASTRA_DIRECTORY = process.env.MASTRA_DIRECTORY ?? "src/mastra";
|
|
131
|
+
const PROJECT_ENV_VARS = safelyParseJson(process.env.PROJECT_ENV_VARS ?? "{}");
|
|
132
|
+
LOCAL ? os.default.tmpdir() + "" : process.env.PROJECT_ROOT;
|
|
95
133
|
function safelyParseJson(json) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
134
|
+
try {
|
|
135
|
+
return JSON.parse(json);
|
|
136
|
+
} catch {
|
|
137
|
+
return {};
|
|
138
|
+
}
|
|
101
139
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
});
|
|
105
|
-
var RedisTransport = class extends
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
});
|
|
162
|
-
}
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/utils/logger.ts
|
|
142
|
+
const redisClient = (0, redis.createClient)({ url: LOG_REDIS_URL });
|
|
143
|
+
var RedisTransport = class extends _mastra_core_logger.LoggerTransport {
|
|
144
|
+
_transform(chunk, _encoding, callback) {
|
|
145
|
+
chunk = chunk.toString();
|
|
146
|
+
const logKey = `builder:logs:${TEAM_ID}:${PROJECT_ID}:${BUILD_ID}`;
|
|
147
|
+
const ttl = 2880 * 60;
|
|
148
|
+
const logData = typeof chunk === "string" ? chunk : JSON.stringify(chunk);
|
|
149
|
+
process.nextTick(async () => {
|
|
150
|
+
try {
|
|
151
|
+
if (!redisClient.isOpen) await redisClient.connect().catch((err) => {
|
|
152
|
+
console.error("Redis connection error:", err);
|
|
153
|
+
});
|
|
154
|
+
const pipeline = redisClient.multi();
|
|
155
|
+
pipeline.rPush(logKey, logData);
|
|
156
|
+
pipeline.expire(logKey, ttl);
|
|
157
|
+
await pipeline.exec();
|
|
158
|
+
} catch (err) {
|
|
159
|
+
console.error("Redis logging error:", err);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
callback(null, chunk);
|
|
163
|
+
}
|
|
164
|
+
_write(chunk, encoding, callback) {
|
|
165
|
+
if (typeof callback === "function") {
|
|
166
|
+
this._transform(chunk, encoding || "utf8", callback);
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
this._transform(chunk, encoding || "utf8", (error) => {
|
|
170
|
+
if (error) console.error("Transform error in write:", error);
|
|
171
|
+
});
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
async _flush() {
|
|
175
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
176
|
+
}
|
|
177
|
+
async _destroy(err, cb) {
|
|
178
|
+
await closeLogger();
|
|
179
|
+
cb(err);
|
|
180
|
+
}
|
|
181
|
+
listLogs(_args) {
|
|
182
|
+
return Promise.resolve({
|
|
183
|
+
logs: [],
|
|
184
|
+
total: 0,
|
|
185
|
+
page: _args?.page ?? 1,
|
|
186
|
+
perPage: _args?.perPage ?? 100,
|
|
187
|
+
hasMore: false
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
listLogsByRunId(_args) {
|
|
191
|
+
return Promise.resolve({
|
|
192
|
+
logs: [],
|
|
193
|
+
total: 0,
|
|
194
|
+
page: _args?.page ?? 1,
|
|
195
|
+
perPage: _args?.perPage ?? 100,
|
|
196
|
+
hasMore: false
|
|
197
|
+
});
|
|
198
|
+
}
|
|
163
199
|
};
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}, 10);
|
|
170
|
-
}
|
|
200
|
+
const transport = new RedisTransport();
|
|
201
|
+
const closeLogger = async () => {
|
|
202
|
+
if (redisClient.isOpen) setTimeout(async () => {
|
|
203
|
+
await redisClient.quit();
|
|
204
|
+
}, 10);
|
|
171
205
|
};
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
redis: transport
|
|
176
|
-
}
|
|
206
|
+
const logger = new _mastra_loggers.PinoLogger({
|
|
207
|
+
level: "info",
|
|
208
|
+
transports: { redis: transport }
|
|
177
209
|
});
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
callback(null, chunk);
|
|
188
|
-
}
|
|
189
|
-
});
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/utils/execa.ts
|
|
212
|
+
const createPinoStream = () => {
|
|
213
|
+
return new stream.Writable({ write(chunk, _encoding, callback) {
|
|
214
|
+
const line = chunk.toString().trim();
|
|
215
|
+
if (line) logger.info(line);
|
|
216
|
+
callback();
|
|
217
|
+
} });
|
|
190
218
|
};
|
|
191
|
-
async function runWithExeca({
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
219
|
+
async function runWithExeca({ cmd, args, cwd = process.cwd(), env = PROJECT_ENV_VARS }) {
|
|
220
|
+
const pinoStream = createPinoStream();
|
|
221
|
+
try {
|
|
222
|
+
const subprocess = (0, execa.execa)(cmd, args, {
|
|
223
|
+
cwd,
|
|
224
|
+
stdin: "ignore",
|
|
225
|
+
env: {
|
|
226
|
+
...process.env,
|
|
227
|
+
...env
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
subprocess.stdout?.pipe(pinoStream, { end: false });
|
|
231
|
+
subprocess.stderr?.pipe(pinoStream, { end: false });
|
|
232
|
+
const { stdout, stderr, exitCode } = await subprocess;
|
|
233
|
+
pinoStream.end();
|
|
234
|
+
return {
|
|
235
|
+
stdout,
|
|
236
|
+
stderr,
|
|
237
|
+
success: exitCode === 0
|
|
238
|
+
};
|
|
239
|
+
} catch (error) {
|
|
240
|
+
pinoStream.end();
|
|
241
|
+
logger.error("Process failed", { error });
|
|
242
|
+
return {
|
|
243
|
+
success: false,
|
|
244
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
245
|
+
};
|
|
246
|
+
}
|
|
214
247
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
248
|
+
//#endregion
|
|
249
|
+
//#region src/utils/deps.ts
|
|
250
|
+
const MEMOIZED = /* @__PURE__ */ new Map();
|
|
218
251
|
function findLockFile(dir) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
return null;
|
|
252
|
+
for (const file of [
|
|
253
|
+
"pnpm-lock.yaml",
|
|
254
|
+
"package-lock.json",
|
|
255
|
+
"yarn.lock",
|
|
256
|
+
"bun.lock"
|
|
257
|
+
]) if (fs.existsSync((0, path.join)(dir, file))) return file;
|
|
258
|
+
const parentDir = (0, path.resolve)(dir, "..");
|
|
259
|
+
if (parentDir !== dir) return findLockFile(parentDir);
|
|
260
|
+
return null;
|
|
230
261
|
}
|
|
231
|
-
function detectPm({ path }) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
MEMOIZED.set(path, pm);
|
|
255
|
-
return pm;
|
|
262
|
+
function detectPm({ path: path$1 }) {
|
|
263
|
+
const cached = MEMOIZED.get(path$1);
|
|
264
|
+
if (cached) return cached;
|
|
265
|
+
const lockFile = findLockFile(path$1);
|
|
266
|
+
let pm = "npm";
|
|
267
|
+
switch (lockFile) {
|
|
268
|
+
case "pnpm-lock.yaml":
|
|
269
|
+
pm = "pnpm";
|
|
270
|
+
break;
|
|
271
|
+
case "package-lock.json":
|
|
272
|
+
pm = "npm";
|
|
273
|
+
break;
|
|
274
|
+
case "yarn.lock":
|
|
275
|
+
pm = "yarn";
|
|
276
|
+
break;
|
|
277
|
+
case "bun.lock":
|
|
278
|
+
pm = "bun";
|
|
279
|
+
break;
|
|
280
|
+
default: pm = "npm";
|
|
281
|
+
}
|
|
282
|
+
MEMOIZED.set(path$1, pm);
|
|
283
|
+
return pm;
|
|
256
284
|
}
|
|
257
|
-
async function installDeps({ path, pm }) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
285
|
+
async function installDeps({ path: path$3, pm }) {
|
|
286
|
+
pm = pm ?? detectPm({ path: path$3 });
|
|
287
|
+
logger.info("Installing dependencies", {
|
|
288
|
+
pm,
|
|
289
|
+
path: path$3
|
|
290
|
+
});
|
|
291
|
+
const { success, error } = await runWithExeca({
|
|
292
|
+
cmd: pm,
|
|
293
|
+
args: [
|
|
294
|
+
"install",
|
|
295
|
+
"--legacy-peer-deps=false",
|
|
296
|
+
"--force"
|
|
297
|
+
],
|
|
298
|
+
cwd: path$3
|
|
299
|
+
});
|
|
300
|
+
if (!success) throw new _mastra_core_error.MastraError({
|
|
301
|
+
id: "FAIL_INSTALL_DEPS",
|
|
302
|
+
category: "USER",
|
|
303
|
+
domain: "DEPLOYER"
|
|
304
|
+
}, error);
|
|
272
305
|
}
|
|
306
|
+
//#endregion
|
|
307
|
+
//#region src/utils/file.ts
|
|
273
308
|
function getMastraEntryFile(mastraDir) {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
id: "MASTRA_ENTRY_FILE_NOT_FOUND",
|
|
284
|
-
category: "USER",
|
|
285
|
-
domain: "DEPLOYER"
|
|
286
|
-
},
|
|
287
|
-
error$1
|
|
288
|
-
);
|
|
289
|
-
}
|
|
309
|
+
try {
|
|
310
|
+
return new _mastra_deployer.FileService().getFirstExistingFile([(0, path.join)(mastraDir, MASTRA_DIRECTORY, "index.ts"), (0, path.join)(mastraDir, MASTRA_DIRECTORY, "index.js")]);
|
|
311
|
+
} catch (error) {
|
|
312
|
+
throw new _mastra_core_error.MastraError({
|
|
313
|
+
id: "MASTRA_ENTRY_FILE_NOT_FOUND",
|
|
314
|
+
category: "USER",
|
|
315
|
+
domain: "DEPLOYER"
|
|
316
|
+
}, error);
|
|
317
|
+
}
|
|
290
318
|
}
|
|
291
|
-
|
|
292
|
-
|
|
319
|
+
//#endregion
|
|
320
|
+
//#region src/utils/report.ts
|
|
293
321
|
function successEntrypoint() {
|
|
294
|
-
|
|
322
|
+
return `
|
|
295
323
|
if (process.env.CI !== 'true') {
|
|
296
324
|
await fetch('${process.env.REPORTER_API_URL}', {
|
|
297
325
|
method: 'POST',
|
|
@@ -300,12 +328,12 @@ function successEntrypoint() {
|
|
|
300
328
|
Authorization: 'Bearer ${process.env.REPORTER_API_URL_AUTH_TOKEN}',
|
|
301
329
|
},
|
|
302
330
|
body: JSON.stringify(${JSON.stringify({
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
331
|
+
projectId: PROJECT_ID,
|
|
332
|
+
buildId: BUILD_ID,
|
|
333
|
+
status: "success",
|
|
334
|
+
url: BUILD_URL,
|
|
335
|
+
userIpAddress: USER_IP_ADDRESS
|
|
336
|
+
})}),
|
|
309
337
|
}).catch(err => {
|
|
310
338
|
console.error('Failed to report build status to monitoring service', {
|
|
311
339
|
error: err,
|
|
@@ -314,62 +342,68 @@ function successEntrypoint() {
|
|
|
314
342
|
}
|
|
315
343
|
`;
|
|
316
344
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
var CloudDeployer = class extends
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
345
|
+
//#endregion
|
|
346
|
+
//#region src/index.ts
|
|
347
|
+
var CloudDeployer = class extends _mastra_deployer.Deployer {
|
|
348
|
+
studio;
|
|
349
|
+
constructor({ studio } = {}) {
|
|
350
|
+
super({ name: "cloud" });
|
|
351
|
+
this.studio = studio ?? false;
|
|
352
|
+
}
|
|
353
|
+
async getUserBundlerOptions(mastraEntryFile, outputDirectory) {
|
|
354
|
+
return {
|
|
355
|
+
...await super.getUserBundlerOptions(mastraEntryFile, outputDirectory),
|
|
356
|
+
externals: true
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
async deploy(_outputDirectory) {}
|
|
360
|
+
async prepare(outputDirectory) {
|
|
361
|
+
await super.prepare(outputDirectory);
|
|
362
|
+
if (this.studio) {
|
|
363
|
+
const __dirname = (0, path.dirname)((0, url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
|
|
364
|
+
const studioServePath = (0, path.join)(outputDirectory, this.outputDir, "studio");
|
|
365
|
+
await (0, fs_extra_esm.copy)((0, path.join)((0, path.dirname)(__dirname), (0, path.join)("dist", "studio")), studioServePath, { overwrite: true });
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
async writePackageJson(outputDirectory, dependencies) {
|
|
369
|
+
const versions = await (0, fs_extra_esm.readJSON)((0, path.join)((0, path.dirname)((0, url.fileURLToPath)(require("url").pathToFileURL(__filename).href)), "../versions.json"));
|
|
370
|
+
for (const [pkgName, version] of Object.entries(versions || {})) dependencies.set(pkgName, version);
|
|
371
|
+
return super.writePackageJson(outputDirectory, dependencies);
|
|
372
|
+
}
|
|
373
|
+
async lint() {}
|
|
374
|
+
async installDependencies(outputDirectory, _rootDir = process.cwd()) {
|
|
375
|
+
await installDeps({
|
|
376
|
+
path: (0, path.join)(outputDirectory, "output"),
|
|
377
|
+
pm: "npm"
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
async bundle(mastraDir, outputDirectory) {
|
|
381
|
+
const currentCwd = process.cwd();
|
|
382
|
+
process.chdir(mastraDir);
|
|
383
|
+
const mastraEntryFile = getMastraEntryFile(mastraDir);
|
|
384
|
+
const mastraAppDir = (0, path.join)(mastraDir, MASTRA_DIRECTORY);
|
|
385
|
+
const discoveredTools = this.getAllToolPaths(mastraAppDir);
|
|
386
|
+
await this.prepare(outputDirectory);
|
|
387
|
+
await this._bundle(this.getEntry(), mastraEntryFile, {
|
|
388
|
+
outputDirectory,
|
|
389
|
+
projectRoot: mastraDir
|
|
390
|
+
}, discoveredTools);
|
|
391
|
+
process.chdir(currentCwd);
|
|
392
|
+
}
|
|
393
|
+
getAuthEntrypoint() {
|
|
394
|
+
return getAuthEntrypoint();
|
|
395
|
+
}
|
|
396
|
+
getEntry() {
|
|
397
|
+
return `
|
|
363
398
|
import { createNodeServer, getToolExports } from '#server';
|
|
364
399
|
import { tools } from '#tools';
|
|
365
400
|
import { mastra } from '#mastra';
|
|
366
401
|
import { MultiLogger } from '@mastra/core/logger';
|
|
367
402
|
import { PinoLogger } from '@mastra/loggers';
|
|
368
403
|
import { HttpTransport } from '@mastra/loggers/http';
|
|
369
|
-
import { evaluate } from '@mastra/core/eval';
|
|
370
|
-
import { AvailableHooks, registerHook } from '@mastra/core/hooks';
|
|
371
404
|
import { LibSQLStore, LibSQLVector } from '@mastra/libsql';
|
|
372
|
-
import { scoreTracesWorkflow } from '@mastra/core/
|
|
405
|
+
import { scoreTracesWorkflow } from '@mastra/core/evals/scoreTraces';
|
|
406
|
+
|
|
373
407
|
const startTime = process.env.RUNNER_START_TIME ? new Date(process.env.RUNNER_START_TIME).getTime() : Date.now();
|
|
374
408
|
const createNodeServerStartTime = Date.now();
|
|
375
409
|
|
|
@@ -408,58 +442,27 @@ const combinedLogger = existingLogger ? new MultiLogger([logger, existingLogger]
|
|
|
408
442
|
|
|
409
443
|
mastra.setLogger({ logger: combinedLogger });
|
|
410
444
|
|
|
411
|
-
if (mastra?.storage) {
|
|
412
|
-
mastra.storage.init()
|
|
413
|
-
}
|
|
414
|
-
|
|
415
445
|
if (process.env.MASTRA_STORAGE_URL && process.env.MASTRA_STORAGE_AUTH_TOKEN) {
|
|
416
446
|
const { MastraStorage } = await import('@mastra/core/storage');
|
|
417
447
|
logger.info('Using Mastra Cloud Storage: ' + process.env.MASTRA_STORAGE_URL)
|
|
418
448
|
const storage = new LibSQLStore({
|
|
449
|
+
id: 'mastra-cloud-storage-libsql',
|
|
419
450
|
url: process.env.MASTRA_STORAGE_URL,
|
|
420
451
|
authToken: process.env.MASTRA_STORAGE_AUTH_TOKEN,
|
|
421
452
|
})
|
|
422
453
|
const vector = new LibSQLVector({
|
|
423
|
-
|
|
454
|
+
id: 'mastra-cloud-storage-libsql-vector',
|
|
455
|
+
url: process.env.MASTRA_STORAGE_URL,
|
|
424
456
|
authToken: process.env.MASTRA_STORAGE_AUTH_TOKEN,
|
|
425
457
|
})
|
|
426
458
|
|
|
427
459
|
await storage.init()
|
|
428
460
|
mastra?.setStorage(storage)
|
|
429
|
-
|
|
430
|
-
mastra?.
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
evaluate({
|
|
435
|
-
agentName,
|
|
436
|
-
input,
|
|
437
|
-
metric,
|
|
438
|
-
output,
|
|
439
|
-
runId,
|
|
440
|
-
globalRunId: runId,
|
|
441
|
-
instructions,
|
|
442
|
-
});
|
|
443
|
-
});
|
|
444
|
-
registerHook(AvailableHooks.ON_EVALUATION, async traceObject => {
|
|
445
|
-
if (mastra?.storage) {
|
|
446
|
-
await mastra.storage.insert({
|
|
447
|
-
tableName: MastraStorage.TABLE_EVALS,
|
|
448
|
-
record: {
|
|
449
|
-
input: traceObject.input,
|
|
450
|
-
output: traceObject.output,
|
|
451
|
-
result: JSON.stringify(traceObject.result),
|
|
452
|
-
agent_name: traceObject.agentName,
|
|
453
|
-
metric_name: traceObject.metricName,
|
|
454
|
-
instructions: traceObject.instructions,
|
|
455
|
-
test_info: null,
|
|
456
|
-
global_run_id: traceObject.globalRunId,
|
|
457
|
-
run_id: traceObject.runId,
|
|
458
|
-
created_at: new Date().toISOString(),
|
|
459
|
-
},
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
});
|
|
461
|
+
} else {
|
|
462
|
+
const userStorage = mastra?.getStorage();
|
|
463
|
+
if (userStorage && !userStorage.disableInit) {
|
|
464
|
+
userStorage.init();
|
|
465
|
+
}
|
|
463
466
|
}
|
|
464
467
|
|
|
465
468
|
if (mastra?.getStorage()) {
|
|
@@ -468,7 +471,7 @@ if (mastra?.getStorage()) {
|
|
|
468
471
|
|
|
469
472
|
${getAuthEntrypoint()}
|
|
470
473
|
|
|
471
|
-
await createNodeServer(mastra, {
|
|
474
|
+
await createNodeServer(mastra, { studio: ${this.studio}, swaggerUI: false, tools: getToolExports(tools) });
|
|
472
475
|
|
|
473
476
|
${successEntrypoint()}
|
|
474
477
|
|
|
@@ -499,9 +502,9 @@ console.log(JSON.stringify({
|
|
|
499
502
|
},
|
|
500
503
|
}));
|
|
501
504
|
`;
|
|
502
|
-
|
|
505
|
+
}
|
|
503
506
|
};
|
|
504
|
-
|
|
507
|
+
//#endregion
|
|
505
508
|
exports.CloudDeployer = CloudDeployer;
|
|
506
|
-
|
|
509
|
+
|
|
507
510
|
//# sourceMappingURL=index.cjs.map
|