@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.
Files changed (47) hide show
  1. package/CHANGELOG.md +3488 -5
  2. package/LICENSE.md +15 -0
  3. package/README.md +2 -3
  4. package/dist/index.cjs +366 -363
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.ts +7 -2
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +340 -336
  9. package/dist/index.js.map +1 -1
  10. package/dist/studio/assets/CommitMono-400-Regular-DzkyLZ26.woff2 +0 -0
  11. package/dist/studio/assets/CommitMono-700-Regular-DmOSN4kd.woff2 +0 -0
  12. package/dist/studio/assets/MonaSans-VariableFont_wdth-wght-CX-7s9jm.ttf +0 -0
  13. package/dist/studio/assets/babel-lWBcy2sH.js +16 -0
  14. package/dist/studio/assets/bash-atvbtKCR.js +1 -0
  15. package/dist/studio/assets/core-uJnW0DDG.js +12 -0
  16. package/dist/studio/assets/engine-compile-BkERmzkH.js +137 -0
  17. package/dist/studio/assets/engine-javascript-CSIo_1eZ.js +1 -0
  18. package/dist/studio/assets/estree-Dd9JfUIE.js +44 -0
  19. package/dist/studio/assets/github-dark-DHJKELXO.js +1 -0
  20. package/dist/studio/assets/github-light-DAi9KRSo.js +1 -0
  21. package/dist/studio/assets/index-BWC9t29j.js +2 -0
  22. package/dist/studio/assets/index-yUiD89B4.js +1 -0
  23. package/dist/studio/assets/javascript-ySlJ1b_l.js +1 -0
  24. package/dist/studio/assets/json-BQoSv7ci.js +1 -0
  25. package/dist/studio/assets/jsx-BAng5TT0.js +1 -0
  26. package/dist/studio/assets/livekit-client.esm-CKIgC2IJ.js +39 -0
  27. package/dist/studio/assets/main-D0m4O3FR.js +768 -0
  28. package/dist/studio/assets/markdown-UIAJJxZW.js +1 -0
  29. package/dist/studio/assets/preload-helper-PPVm8Dsz.js +1 -0
  30. package/dist/studio/assets/python-DhUJRlN_.js +1 -0
  31. package/dist/studio/assets/shell-CjFT_Tl9.js +1 -0
  32. package/dist/studio/assets/standalone-Dfz2oS5J.js +29 -0
  33. package/dist/studio/assets/style-B7CpWlks.css +1 -0
  34. package/dist/studio/assets/tsx-B6W0miNI.js +1 -0
  35. package/dist/studio/assets/typescript-Dj6nwHGl.js +1 -0
  36. package/dist/studio/index.html +100 -0
  37. package/dist/studio/mastra.svg +17 -0
  38. package/dist/studio/routes-manifest.json +27 -0
  39. package/dist/utils/auth.d.ts.map +1 -1
  40. package/dist/utils/deps.d.ts.map +1 -1
  41. package/dist/utils/execa.d.ts +2 -2
  42. package/dist/utils/execa.d.ts.map +1 -1
  43. package/dist/utils/logger.d.ts +4 -4
  44. package/dist/utils/logger.d.ts.map +1 -1
  45. package/package.json +26 -19
  46. package/versions.json +1 -1
  47. package/templates/instrumentation-template.js +0 -69
package/dist/index.cjs CHANGED
@@ -1,297 +1,325 @@
1
- 'use strict';
2
-
3
- var url = require('url');
4
- var path = require('path');
5
- var deployer = require('@mastra/deployer');
6
- var esm = require('fs-extra/esm');
7
- var os = require('os');
8
- var fs = require('fs');
9
- var error = require('@mastra/core/error');
10
- var stream = require('stream');
11
- var execa = require('execa');
12
- var logger$1 = require('@mastra/core/logger');
13
- var loggers = require('@mastra/loggers');
14
- var redis = require('redis');
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
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
17
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
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
- function _interopNamespace(e) {
20
- if (e && e.__esModule) return e;
21
- var n = Object.create(null);
22
- if (e) {
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
- var os__default = /*#__PURE__*/_interopDefault(os);
38
- var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
74
+ const serviceAuth = new MastraCloudServiceAuth();
39
75
 
40
- // src/index.ts
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
- // src/utils/auth.ts
43
- function getAuthEntrypoint() {
44
- return `
45
- import { MastraAuthProvider } from '@mastra/core/server';
87
+ const serverConfig = mastra.getServer();
88
+ const userAuth = serverConfig?.auth;
46
89
 
47
- class MastraCloudAuth extends MastraAuthProvider {
48
- constructor (auth) {
49
- super()
50
- this.auth = auth
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
- async authenticateToken (...args) {
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
- async authorizeUser (...args) {
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
- const serverConfig = mastra.getServer()
79
- if (serverConfig && serverConfig.experimental_auth) {
80
- const auth = serverConfig.experimental_auth
81
- serverConfig.experimental_auth = new MastraCloudAuth(auth)
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
- var LOCAL = process.env.LOCAL === "true";
86
- var TEAM_ID = process.env.TEAM_ID ?? "";
87
- var PROJECT_ID = process.env.PROJECT_ID ?? "";
88
- var BUILD_ID = process.env.BUILD_ID ?? "";
89
- var BUILD_URL = process.env.BUILD_URL ?? "";
90
- var LOG_REDIS_URL = process.env.LOG_REDIS_URL ?? "redis://localhost:6379";
91
- var USER_IP_ADDRESS = process.env.USER_IP_ADDRESS ?? "";
92
- var MASTRA_DIRECTORY = process.env.MASTRA_DIRECTORY ?? "src/mastra";
93
- var PROJECT_ENV_VARS = safelyParseJson(process.env.PROJECT_ENV_VARS ?? "{}");
94
- LOCAL ? os__default.default.tmpdir() + "/project" : process.env.PROJECT_ROOT ?? "/project";
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
- try {
97
- return JSON.parse(json);
98
- } catch {
99
- return {};
100
- }
134
+ try {
135
+ return JSON.parse(json);
136
+ } catch {
137
+ return {};
138
+ }
101
139
  }
102
- var redisClient = redis.createClient({
103
- url: LOG_REDIS_URL
104
- });
105
- var RedisTransport = class extends logger$1.LoggerTransport {
106
- _transform(chunk, _encoding, callback) {
107
- chunk = chunk.toString();
108
- const logKey = `builder:logs:${TEAM_ID}:${PROJECT_ID}:${BUILD_ID}`;
109
- const ttl = 2 * 24 * 60 * 60;
110
- const logData = typeof chunk === "string" ? chunk : JSON.stringify(chunk);
111
- process.nextTick(async () => {
112
- try {
113
- if (!redisClient.isOpen) {
114
- await redisClient.connect().catch((err) => {
115
- console.error("Redis connection error:", err);
116
- });
117
- }
118
- const pipeline = redisClient.multi();
119
- pipeline.rPush(logKey, logData);
120
- pipeline.expire(logKey, ttl);
121
- await pipeline.exec();
122
- } catch (err) {
123
- console.error("Redis logging error:", err);
124
- }
125
- });
126
- callback(null, chunk);
127
- }
128
- _write(chunk, encoding, callback) {
129
- if (typeof callback === "function") {
130
- this._transform(chunk, encoding || "utf8", callback);
131
- return true;
132
- }
133
- this._transform(chunk, encoding || "utf8", (error) => {
134
- if (error) console.error("Transform error in write:", error);
135
- });
136
- return true;
137
- }
138
- async _flush() {
139
- await new Promise((resolve2) => setTimeout(resolve2, 10));
140
- }
141
- async _destroy(err, cb) {
142
- await closeLogger();
143
- cb(err);
144
- }
145
- getLogs(_args) {
146
- return Promise.resolve({
147
- logs: [],
148
- total: 0,
149
- page: _args?.page ?? 1,
150
- perPage: _args?.perPage ?? 100,
151
- hasMore: false
152
- });
153
- }
154
- getLogsByRunId(_args) {
155
- return Promise.resolve({
156
- logs: [],
157
- total: 0,
158
- page: _args?.page ?? 1,
159
- perPage: _args?.perPage ?? 100,
160
- hasMore: false
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
- var transport = new RedisTransport();
165
- var closeLogger = async () => {
166
- if (redisClient.isOpen) {
167
- setTimeout(async () => {
168
- await redisClient.quit();
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
- var logger = new loggers.PinoLogger({
173
- level: "info",
174
- transports: {
175
- redis: transport
176
- }
206
+ const logger = new _mastra_loggers.PinoLogger({
207
+ level: "info",
208
+ transports: { redis: transport }
177
209
  });
178
-
179
- // src/utils/execa.ts
180
- var createPinoStream = () => {
181
- return new stream.Transform({
182
- transform(chunk, encoding, callback) {
183
- const line = chunk.toString().trim();
184
- if (line) {
185
- logger.info(line);
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
- cmd,
193
- args,
194
- cwd = process.cwd(),
195
- env = PROJECT_ENV_VARS
196
- }) {
197
- const pinoStream = createPinoStream();
198
- try {
199
- const subprocess = execa.execa(cmd, args, {
200
- cwd,
201
- env: {
202
- ...process.env,
203
- ...env
204
- }
205
- });
206
- subprocess.stdout?.pipe(pinoStream);
207
- subprocess.stderr?.pipe(pinoStream);
208
- const { stdout, stderr, exitCode } = await subprocess;
209
- return { stdout, stderr, success: exitCode === 0 };
210
- } catch (error) {
211
- logger.error(`Process failed: ${error}`);
212
- return { success: false, error: error instanceof Error ? error : new Error(String(error)) };
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
- // src/utils/deps.ts
217
- var MEMOIZED = /* @__PURE__ */ new Map();
248
+ //#endregion
249
+ //#region src/utils/deps.ts
250
+ const MEMOIZED = /* @__PURE__ */ new Map();
218
251
  function findLockFile(dir) {
219
- const lockFiles = ["pnpm-lock.yaml", "package-lock.json", "yarn.lock", "bun.lock"];
220
- for (const file of lockFiles) {
221
- if (fs__namespace.existsSync(path.join(dir, file))) {
222
- return file;
223
- }
224
- }
225
- const parentDir = path.resolve(dir, "..");
226
- if (parentDir !== dir) {
227
- return findLockFile(parentDir);
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
- const cached = MEMOIZED.get(path);
233
- if (cached) {
234
- return cached;
235
- }
236
- const lockFile = findLockFile(path);
237
- let pm = "npm";
238
- switch (lockFile) {
239
- case "pnpm-lock.yaml":
240
- pm = "pnpm";
241
- break;
242
- case "package-lock.json":
243
- pm = "npm";
244
- break;
245
- case "yarn.lock":
246
- pm = "yarn";
247
- break;
248
- case "bun.lock":
249
- pm = "bun";
250
- break;
251
- default:
252
- pm = "npm";
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
- pm = pm ?? detectPm({ path });
259
- logger.info(`Installing dependencies with ${pm} in ${path}`);
260
- const args = ["install"];
261
- const { success, error: error$1 } = await runWithExeca({ cmd: pm, args, cwd: path });
262
- if (!success) {
263
- throw new error.MastraError(
264
- {
265
- id: "FAIL_INSTALL_DEPS",
266
- category: "USER",
267
- domain: "DEPLOYER"
268
- },
269
- error$1
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
- try {
275
- const fileService = new deployer.FileService();
276
- return fileService.getFirstExistingFile([
277
- path.join(mastraDir, MASTRA_DIRECTORY, "index.ts"),
278
- path.join(mastraDir, MASTRA_DIRECTORY, "index.js")
279
- ]);
280
- } catch (error$1) {
281
- throw new error.MastraError(
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
- // src/utils/report.ts
319
+ //#endregion
320
+ //#region src/utils/report.ts
293
321
  function successEntrypoint() {
294
- return `
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
- projectId: PROJECT_ID,
304
- buildId: BUILD_ID,
305
- status: "success",
306
- url: BUILD_URL,
307
- userIpAddress: USER_IP_ADDRESS
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
- // src/index.ts
319
- var CloudDeployer = class extends deployer.Deployer {
320
- constructor() {
321
- super({ name: "cloud" });
322
- }
323
- async deploy(_outputDirectory) {
324
- }
325
- async writeInstrumentationFile(outputDirectory) {
326
- const instrumentationFile = path.join(outputDirectory, "instrumentation.mjs");
327
- const __dirname = path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
328
- await esm.copy(path.join(__dirname, "../templates", "instrumentation-template.js"), instrumentationFile);
329
- }
330
- async writePackageJson(outputDirectory, dependencies) {
331
- const versions = await esm.readJSON(path.join(path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)))), "../versions.json"));
332
- for (const [pkgName, version] of Object.entries(versions || {})) {
333
- dependencies.set(pkgName, version);
334
- }
335
- return super.writePackageJson(outputDirectory, dependencies);
336
- }
337
- async lint() {
338
- }
339
- async installDependencies(outputDirectory, _rootDir = process.cwd()) {
340
- await installDeps({ path: path.join(outputDirectory, "output"), pm: "npm" });
341
- }
342
- async bundle(mastraDir, outputDirectory) {
343
- const currentCwd = process.cwd();
344
- process.chdir(mastraDir);
345
- const mastraEntryFile = getMastraEntryFile(mastraDir);
346
- const defaultToolsPath = path.join(mastraDir, MASTRA_DIRECTORY, "tools");
347
- await this._bundle(
348
- this.getEntry(),
349
- mastraEntryFile,
350
- {
351
- outputDirectory,
352
- projectRoot: mastraDir
353
- },
354
- [defaultToolsPath]
355
- );
356
- process.chdir(currentCwd);
357
- }
358
- getAuthEntrypoint() {
359
- return getAuthEntrypoint();
360
- }
361
- getEntry() {
362
- return `
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/scores/scoreTraces';
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
- connectionUrl: process.env.MASTRA_STORAGE_URL,
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?.memory?.setStorage(storage)
431
- mastra?.memory?.setVector(vector)
432
-
433
- registerHook(AvailableHooks.ON_GENERATION, ({ input, output, metric, runId, agentName, instructions }) => {
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, { playground: false, swaggerUI: false, tools: getToolExports(tools) });
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
- //# sourceMappingURL=index.cjs.map
509
+
507
510
  //# sourceMappingURL=index.cjs.map