@mastra/deployer-cloud 1.80.0-alpha.3 → 1.80.0-alpha.4
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/dist/index.cjs +9 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +8 -16
- package/dist/index.js.map +1 -1
- package/dist/studio/assets/CodeDiff.es-yDX8ENTX.js +305 -0
- package/dist/studio/assets/{ada-C5qYipkI.js → ada-X3Y2mlq2.js} +1 -1
- package/dist/studio/assets/{ahk-CA9gdOdF.js → ahk-DwADkxyd.js} +1 -1
- package/dist/studio/assets/{angular-html-DolB2A6S.js → angular-html-BswFT_28.js} +1 -1
- package/dist/studio/assets/angular-html-DOLkzBtu.js +1 -0
- package/dist/studio/assets/{angular-ts-B1PKGDnJ.js → angular-ts-DOMhGxLQ.js} +1 -1
- package/dist/studio/assets/{apl-BmC_IO_Q.js → apl-Dio8Ke0X.js} +1 -1
- package/dist/studio/assets/{astro-SDMRz_OH.js → astro-CN6YWUG3.js} +1 -1
- package/dist/studio/assets/babel-B_E7dii_.js +16 -0
- package/dist/studio/assets/beancount-C2IN4Vk8.js +1 -0
- package/dist/studio/assets/{blade-B6w4c-X9.js → blade-BrDpNfUX.js} +1 -1
- package/dist/studio/assets/{cobol-CtA7PaQL.js → cobol-BvqUwMCV.js} +1 -1
- package/dist/studio/assets/coq-CGaSfhwR.js +1 -0
- package/dist/studio/assets/{crystal-BezZpOOT.js → crystal-DEF7AEJQ.js} +1 -1
- package/dist/studio/assets/csharp-B3DbjJyj.js +1 -0
- package/dist/studio/assets/csharp-CFKDkFDZ.js +1 -0
- package/dist/studio/assets/css-BGIxQoYs.js +1 -0
- package/dist/studio/assets/css-DgaLhXQH.js +1 -0
- package/dist/studio/assets/dart-DjhkpiWP.js +1 -0
- package/dist/studio/assets/dart-_dH3dQdM.js +1 -0
- package/dist/studio/assets/{dist-D73uoo3G.js → dist-BVq4x0k2.js} +1 -1
- package/dist/studio/assets/dist-BZ0nnT2j.js +1 -0
- package/dist/studio/assets/dist-BcV0fxOe.js +23 -0
- package/dist/studio/assets/dist-CmRzlq9h.js +1 -0
- package/dist/studio/assets/dist-Dcq2nGKl.js +6 -0
- package/dist/studio/assets/dist-DjFwFQ6-.js +1 -0
- package/dist/studio/assets/dist-DkOJ_COt.js +1 -0
- package/dist/studio/assets/dist-rcSvr8nT.js +13 -0
- package/dist/studio/assets/dist-t_wjP-TL.js +1 -0
- package/dist/studio/assets/dotenv-CuH5my32.js +1 -0
- package/dist/studio/assets/{edge-D7PqnmbS.js → edge-B_SBzXGF.js} +1 -1
- package/dist/studio/assets/{elixir-DeblBytM.js → elixir-BL8v4QDr.js} +1 -1
- package/dist/studio/assets/elixir-BN3BkYei.js +1 -0
- package/dist/studio/assets/emacs-lisp-DR2vtWaj.js +1 -0
- package/dist/studio/assets/{erb-BfjjH6As.js → erb-BjlLGk-_.js} +1 -1
- package/dist/studio/assets/{estree-vwDM3qKy.js → estree-CvDFpEmC.js} +1 -1
- package/dist/studio/assets/{glimmer-js-DHbJ63Uk.js → glimmer-js-CIdbWayl.js} +1 -1
- package/dist/studio/assets/{glimmer-ts-78YraEOQ.js → glimmer-ts-B16xCo2k.js} +1 -1
- package/dist/studio/assets/gn-CAXYAgV-.js +1 -0
- package/dist/studio/assets/{hack-i70bJskv.js → hack-C30D-q0p.js} +1 -1
- package/dist/studio/assets/haml-BU6KMePS.js +1 -0
- package/dist/studio/assets/{haml-CAMQ1nWo.js → haml-C1zHJAQt.js} +1 -1
- package/dist/studio/assets/handlebars-WZCg7K7Q.js +1 -0
- package/dist/studio/assets/handlebars-g-3gLrXt.js +1 -0
- package/dist/studio/assets/html-BCy9P6D2.js +1 -0
- package/dist/studio/assets/{html-B2cKP6UN.js → html-DSw1lh5G.js} +1 -1
- package/dist/studio/assets/{html-derivative-Dhubv07u.js → html-derivative-DyzJkWO6.js} +1 -1
- package/dist/studio/assets/html-derivative-ekTk9Unt.js +1 -0
- package/dist/studio/assets/{index-B5bDI3Sz.js → index-CStRllzQ.js} +2 -2
- package/dist/studio/assets/{jinja-CRuWSMeX.js → jinja-dRcm23Ea.js} +1 -1
- package/dist/studio/assets/julia-C8a5hZkp.js +1 -0
- package/dist/studio/assets/{julia-3RSkklau.js → julia-hqywDEUR.js} +1 -1
- package/dist/studio/assets/{just-G7MH58_L.js → just-CP_wDfXI.js} +1 -1
- package/dist/studio/assets/latex-B_Ztlc7G.js +1 -0
- package/dist/studio/assets/latex-Bn9nYtub.js +1 -0
- package/dist/studio/assets/lib-DRuii7jc.js +1 -0
- package/dist/studio/assets/{liquid-DdvxCDBI.js → liquid-CQNtsgCr.js} +1 -1
- package/dist/studio/assets/livekit-client.esm-DMHgtGvw.js +39 -0
- package/dist/studio/assets/luau-VGWVLoqX.js +1 -0
- package/dist/studio/assets/main-DW5us475.js +699 -0
- package/dist/studio/assets/marko-DPS0EkZ1.js +1 -0
- package/dist/studio/assets/{mdc-Cm3Vtzgo.js → mdc-C6srEd4p.js} +1 -1
- package/dist/studio/assets/monokai-BscAjiQZ.js +1 -0
- package/dist/studio/assets/moonbit-D9W784E_.js +1 -0
- package/dist/studio/assets/{nextflow-groovy-C6U6GzKG.js → nextflow-groovy-C770ykRh.js} +1 -1
- package/dist/studio/assets/nextflow-groovy-D5vAge1Z.js +1 -0
- package/dist/studio/assets/nextflow-uA5IJerx.js +1 -0
- package/dist/studio/assets/nim-DN3EGtL-.js +1 -0
- package/dist/studio/assets/{nim-CkcqHVhZ.js → nim-ZjzS1dcU.js} +1 -1
- package/dist/studio/assets/nushell--0fT3PI1.js +1 -0
- package/dist/studio/assets/one-dark-pro-C6YyR8OD.js +1 -0
- package/dist/studio/assets/{org-BIKsc680.js → org-BRAbLUOJ.js} +1 -1
- package/dist/studio/assets/p-map-D81h6UuU.js +1 -0
- package/dist/studio/assets/perl-Ciba4h2-.js +1 -0
- package/dist/studio/assets/{perl-CrgxsDZk.js → perl-sgZsTtaf.js} +1 -1
- package/dist/studio/assets/php-D9QpVhjP.js +1 -0
- package/dist/studio/assets/php-DBfnyu6d.js +1 -0
- package/dist/studio/assets/powershell-Blb2ISmZ.js +1 -0
- package/dist/studio/assets/{powershell-CB0_OCr_.js → powershell-CItYMEtV.js} +1 -1
- package/dist/studio/assets/pug-C_nSP9Mg.js +1 -0
- package/dist/studio/assets/{pug-ikVFMdBJ.js → pug-nGRwXpob.js} +1 -1
- package/dist/studio/assets/{razor-Ble7Vzo2.js → razor-UAq-8THt.js} +1 -1
- package/dist/studio/assets/red-CYlAq2b0.js +1 -0
- package/dist/studio/assets/{rst-CkovH8lR.js → rst-BCaXiUC4.js} +1 -1
- package/dist/studio/assets/ruby-C4ARPOX3.js +1 -0
- package/dist/studio/assets/{ruby-Dg1QxBW5.js → ruby-Dl3oLoVp.js} +1 -1
- package/dist/studio/assets/rust-Ch0zZBV0.js +1 -0
- package/dist/studio/assets/rust-DBZE5Si3.js +1 -0
- package/dist/studio/assets/{sas-2IEyvoFV.js → sas-BowjnAvi.js} +1 -1
- package/dist/studio/assets/{scss-CPpsOPrU.js → scss-CWs8DVSa.js} +1 -1
- package/dist/studio/assets/scss-D3wBkj3d.js +1 -0
- package/dist/studio/assets/solarized-dark-b97czJOk.js +1 -0
- package/dist/studio/assets/solarized-light-DFPxpIYQ.js +1 -0
- package/dist/studio/assets/{soy-A62BAwxz.js → soy-CUUUw2U6.js} +1 -1
- package/dist/studio/assets/sql-CNu3Or2W.js +1 -0
- package/dist/studio/assets/sql-CfM2IJm3.js +1 -0
- package/dist/studio/assets/{stata-BGsmlsHF.js → stata-Dj4sbAEx.js} +1 -1
- package/dist/studio/assets/style-IQMl5TX8.css +3 -0
- package/dist/studio/assets/{svelte-DcpG3o7o.js → svelte-BaCIHHWd.js} +1 -1
- package/dist/studio/assets/{templ-CvnTbAXa.js → templ-BfgLc4ra.js} +1 -1
- package/dist/studio/assets/{ts-tags--pZs7vYD.js → ts-tags-DLz2GTd3.js} +1 -1
- package/dist/studio/assets/twig-HaHkB3PH.js +1 -0
- package/dist/studio/assets/twig-lMQ09cjh.js +1 -0
- package/dist/studio/assets/typespec-BGhR2SqG.js +1 -0
- package/dist/studio/assets/{typst-Czf1dSai.js → typst-DDNSzYFN.js} +1 -1
- package/dist/studio/assets/{vue-CAw-zJtI.js → vue-qH43U_rv.js} +1 -1
- package/dist/studio/assets/{vue-vine-DPTR_ZYD.js → vue-vine-6XI2pIvQ.js} +1 -1
- package/dist/studio/assets/yaml-BEzOWJ7L.js +1 -0
- package/dist/studio/index.html +2 -2
- package/package.json +9 -9
- package/versions.json +1 -1
- package/dist/studio/assets/CodeDiff.es-BZoVKavl.js +0 -305
- package/dist/studio/assets/angular-html-06u8ifAB.js +0 -1
- package/dist/studio/assets/babel-qZlmxQ8K.js +0 -16
- package/dist/studio/assets/beancount-D-usSTwE.js +0 -1
- package/dist/studio/assets/coq-DuBRPxYg.js +0 -1
- package/dist/studio/assets/csharp-BviNWcUb.js +0 -1
- package/dist/studio/assets/csharp-DoUovMB6.js +0 -1
- package/dist/studio/assets/css-BN7bbgzh.js +0 -1
- package/dist/studio/assets/css-LbU1hoFO.js +0 -1
- package/dist/studio/assets/dart-BcpK88xC.js +0 -1
- package/dist/studio/assets/dart-zFqxHoQA.js +0 -1
- package/dist/studio/assets/dist-BeXC2sV7.js +0 -1
- package/dist/studio/assets/dist-BgTAL0Im.js +0 -1
- package/dist/studio/assets/dist-C4qaiM5N.js +0 -1
- package/dist/studio/assets/dist-CTvjM30z.js +0 -1
- package/dist/studio/assets/dist-CXMb7aeG.js +0 -13
- package/dist/studio/assets/dist-CgVs1BGt.js +0 -1
- package/dist/studio/assets/dist-DIJvMGBR.js +0 -23
- package/dist/studio/assets/dist-DOBwC-Vj.js +0 -6
- package/dist/studio/assets/dotenv-_5a1GRtc.js +0 -1
- package/dist/studio/assets/elixir-BjfTbpsD.js +0 -1
- package/dist/studio/assets/emacs-lisp-c_oH4hRZ.js +0 -1
- package/dist/studio/assets/gn-ilITqXS6.js +0 -1
- package/dist/studio/assets/haml-3Fo4mycZ.js +0 -1
- package/dist/studio/assets/handlebars-B5qiZlCO.js +0 -1
- package/dist/studio/assets/handlebars-CXhBu6gL.js +0 -1
- package/dist/studio/assets/html-Bls34fXK.js +0 -1
- package/dist/studio/assets/html-derivative-CPgLVSxm.js +0 -1
- package/dist/studio/assets/julia-DKmDyKMZ.js +0 -1
- package/dist/studio/assets/latex-CLPpIAp7.js +0 -1
- package/dist/studio/assets/latex-YWqeWI-c.js +0 -1
- package/dist/studio/assets/lib-5J3uDSIY.js +0 -1
- package/dist/studio/assets/livekit-client.esm-D6tj57cg.js +0 -39
- package/dist/studio/assets/luau-C2pBCSgt.js +0 -1
- package/dist/studio/assets/main-B5OUigHD.js +0 -693
- package/dist/studio/assets/marko-DJ3i0CIR.js +0 -1
- package/dist/studio/assets/monokai-B_bV9PQ9.js +0 -1
- package/dist/studio/assets/moonbit-DgjMoLWr.js +0 -1
- package/dist/studio/assets/nextflow-groovy-DQJ40bag.js +0 -1
- package/dist/studio/assets/nextflow-rSIivlom.js +0 -1
- package/dist/studio/assets/nim-BLCC9zUt.js +0 -1
- package/dist/studio/assets/nushell-DHYfO66s.js +0 -1
- package/dist/studio/assets/one-dark-pro-CLwyXe_n.js +0 -1
- package/dist/studio/assets/p-map-C_4OPQuz.js +0 -1
- package/dist/studio/assets/perl-DldNfCGA.js +0 -1
- package/dist/studio/assets/php-B1kreupY.js +0 -1
- package/dist/studio/assets/php-kBxV6T2i.js +0 -1
- package/dist/studio/assets/powershell-BAeOcVkI.js +0 -1
- package/dist/studio/assets/pug-B0eKJDyz.js +0 -1
- package/dist/studio/assets/red-DX1BQOs8.js +0 -1
- package/dist/studio/assets/ruby-DfKa-Cpp.js +0 -1
- package/dist/studio/assets/rust-08ePcFzV.js +0 -1
- package/dist/studio/assets/rust-CSjmjZYD.js +0 -1
- package/dist/studio/assets/scss-CTp9_vex.js +0 -1
- package/dist/studio/assets/solarized-dark-UdsmMDCL.js +0 -1
- package/dist/studio/assets/solarized-light-C1IUL_tW.js +0 -1
- package/dist/studio/assets/sql-CP0rg-5b.js +0 -1
- package/dist/studio/assets/sql-DOnR2rig.js +0 -1
- package/dist/studio/assets/style-CSTC_W6c.css +0 -3
- package/dist/studio/assets/twig-BL9b48tu.js +0 -1
- package/dist/studio/assets/twig-CiXWCF20.js +0 -1
- package/dist/studio/assets/typespec-BRdr0IET.js +0 -1
- package/dist/studio/assets/yaml-DjjjKWKb.js +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
2
|
+
// \0rolldown/runtime.js
|
|
3
3
|
var __create = Object.create;
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -20,7 +20,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
20
20
|
value: mod,
|
|
21
21
|
enumerable: true
|
|
22
22
|
}) : target, mod));
|
|
23
|
-
//#endregion
|
|
24
23
|
let path = require("path");
|
|
25
24
|
let url = require("url");
|
|
26
25
|
let _mastra_deployer = require("@mastra/deployer");
|
|
@@ -35,7 +34,7 @@ let execa = require("execa");
|
|
|
35
34
|
let _mastra_core_logger = require("@mastra/core/logger");
|
|
36
35
|
let _mastra_loggers = require("@mastra/loggers");
|
|
37
36
|
let redis = require("redis");
|
|
38
|
-
|
|
37
|
+
// src/utils/auth.ts
|
|
39
38
|
function getAuthEntrypoint() {
|
|
40
39
|
const tokensObject = {};
|
|
41
40
|
if (process.env.PLAYGROUND_JWT_TOKEN) tokensObject[process.env.PLAYGROUND_JWT_TOKEN] = {
|
|
@@ -116,8 +115,7 @@ function getAuthEntrypoint() {
|
|
|
116
115
|
}
|
|
117
116
|
`;
|
|
118
117
|
}
|
|
119
|
-
|
|
120
|
-
//#region src/utils/constants.ts
|
|
118
|
+
// src/utils/constants.ts
|
|
121
119
|
const LOCAL = process.env.LOCAL === "true";
|
|
122
120
|
const TEAM_ID = process.env.TEAM_ID ?? "";
|
|
123
121
|
const PROJECT_ID = process.env.PROJECT_ID ?? "";
|
|
@@ -137,8 +135,7 @@ function safelyParseJson(json) {
|
|
|
137
135
|
return {};
|
|
138
136
|
}
|
|
139
137
|
}
|
|
140
|
-
|
|
141
|
-
//#region src/utils/logger.ts
|
|
138
|
+
// src/utils/logger.ts
|
|
142
139
|
const redisClient = (0, redis.createClient)({ url: LOG_REDIS_URL });
|
|
143
140
|
var RedisTransport = class extends _mastra_core_logger.LoggerTransport {
|
|
144
141
|
_transform(chunk, _encoding, callback) {
|
|
@@ -207,8 +204,7 @@ const logger = new _mastra_loggers.PinoLogger({
|
|
|
207
204
|
level: "info",
|
|
208
205
|
transports: { redis: transport }
|
|
209
206
|
});
|
|
210
|
-
|
|
211
|
-
//#region src/utils/execa.ts
|
|
207
|
+
// src/utils/execa.ts
|
|
212
208
|
const createPinoStream = () => {
|
|
213
209
|
return new stream.Writable({ write(chunk, _encoding, callback) {
|
|
214
210
|
const line = chunk.toString().trim();
|
|
@@ -245,8 +241,7 @@ async function runWithExeca({ cmd, args, cwd = process.cwd(), env = PROJECT_ENV_
|
|
|
245
241
|
};
|
|
246
242
|
}
|
|
247
243
|
}
|
|
248
|
-
|
|
249
|
-
//#region src/utils/deps.ts
|
|
244
|
+
// src/utils/deps.ts
|
|
250
245
|
const MEMOIZED = /* @__PURE__ */ new Map();
|
|
251
246
|
function findLockFile(dir) {
|
|
252
247
|
for (const file of [
|
|
@@ -303,8 +298,7 @@ async function installDeps({ path, pm }) {
|
|
|
303
298
|
domain: "DEPLOYER"
|
|
304
299
|
}, error);
|
|
305
300
|
}
|
|
306
|
-
|
|
307
|
-
//#region src/utils/file.ts
|
|
301
|
+
// src/utils/file.ts
|
|
308
302
|
function getMastraEntryFile(mastraDir) {
|
|
309
303
|
try {
|
|
310
304
|
return new _mastra_deployer.FileService().getFirstExistingFile([(0, path.join)(mastraDir, MASTRA_DIRECTORY, "index.ts"), (0, path.join)(mastraDir, MASTRA_DIRECTORY, "index.js")]);
|
|
@@ -316,8 +310,7 @@ function getMastraEntryFile(mastraDir) {
|
|
|
316
310
|
}, error);
|
|
317
311
|
}
|
|
318
312
|
}
|
|
319
|
-
|
|
320
|
-
//#region src/utils/report.ts
|
|
313
|
+
// src/utils/report.ts
|
|
321
314
|
function successEntrypoint() {
|
|
322
315
|
return `
|
|
323
316
|
if (process.env.CI !== 'true') {
|
|
@@ -342,8 +335,7 @@ function successEntrypoint() {
|
|
|
342
335
|
}
|
|
343
336
|
`;
|
|
344
337
|
}
|
|
345
|
-
|
|
346
|
-
//#region src/index.ts
|
|
338
|
+
// src/index.ts
|
|
347
339
|
var CloudDeployer = class extends _mastra_deployer.Deployer {
|
|
348
340
|
studio;
|
|
349
341
|
constructor({ studio } = {}) {
|
|
@@ -505,7 +497,6 @@ console.log(JSON.stringify({
|
|
|
505
497
|
`;
|
|
506
498
|
}
|
|
507
499
|
};
|
|
508
|
-
//#endregion
|
|
509
500
|
exports.CloudDeployer = CloudDeployer;
|
|
510
501
|
|
|
511
502
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["createClient","LoggerTransport","PinoLogger","Writable","join","resolve","MastraError","FileService","join","MastraError","Deployer","__filename","fileURLToPath","__dirname","dirname","join","copy","readJSON"],"sources":["../src/utils/auth.ts","../src/utils/constants.ts","../src/utils/logger.ts","../src/utils/execa.ts","../src/utils/deps.ts","../src/utils/file.ts","../src/utils/report.ts","../src/index.ts"],"sourcesContent":["export function getAuthEntrypoint() {\n const tokensObject: Record<string, { id: string; role: string }> = {};\n\n if (process.env.PLAYGROUND_JWT_TOKEN) {\n tokensObject[process.env.PLAYGROUND_JWT_TOKEN] = { id: 'business-api', role: 'api' };\n }\n if (process.env.BUSINESS_JWT_TOKEN) {\n tokensObject[process.env.BUSINESS_JWT_TOKEN] = { id: 'business-api', role: 'api' };\n }\n\n return `\n import { SimpleAuth, CompositeAuth } from '@mastra/core/server';\n import { MastraCloudAuthProvider, MastraRBACCloud } from '@mastra/auth-cloud';\n\n // Service token auth (for business-api, playground internal calls)\n class MastraCloudServiceAuth extends SimpleAuth {\n constructor() {\n super({\n tokens: ${JSON.stringify(tokensObject)}\n });\n }\n\n async authorizeUser(user, request) {\n // Allow access to /api path\n if (request && request.url && new URL(request.url).pathname === '/api') {\n return true;\n }\n // Allow access for business-api users\n if (user && user.id === 'business-api') {\n return true;\n }\n return false;\n }\n }\n\n const serviceAuth = new MastraCloudServiceAuth();\n\n // Cloud user auth (for end users via OAuth)\n // Only enabled if MASTRA_CLOUD_API_URL is set\n let cloudUserAuth = null;\n if (process.env.MASTRA_CLOUD_API_URL) {\n cloudUserAuth = new MastraCloudAuthProvider({\n projectId: process.env.PROJECT_ID,\n cloudBaseUrl: process.env.MASTRA_CLOUD_API_URL,\n callbackUrl: process.env.MASTRA_CLOUD_CALLBACK_URL || \\`\\${process.env.MASTRA_CLOUD_API_URL}/auth/callback\\`,\n });\n }\n\n const serverConfig = mastra.getServer();\n const userAuth = serverConfig?.auth;\n\n // Only enable auth if cloudUserAuth or userAuth are defined\n if (serverConfig && (cloudUserAuth || userAuth)) {\n // Build provider list: service auth first, then cloud user auth, then user's custom auth\n const providers = [serviceAuth];\n if (cloudUserAuth) {\n providers.push(cloudUserAuth);\n }\n if (userAuth) {\n providers.push(userAuth);\n }\n\n serverConfig.auth = new CompositeAuth(providers);\n\n // If cloud auth is enabled but no RBAC is configured, add default cloud RBAC\n if (cloudUserAuth && !serverConfig.rbac) {\n serverConfig.rbac = new MastraRBACCloud({\n roleMapping: {\n owner: ['*'],\n admin: ['*:read', '*:write', '*:execute'],\n api: ['*:read', '*:write', '*:execute'],\n member: ['*:read', '*:execute'],\n viewer: ['*:read'],\n _default: [],\n },\n });\n }\n }\n `;\n}\n","import os from 'node:os';\n\nexport const LOCAL = process.env.LOCAL === 'true';\nexport const TEAM_ID: string = process.env.TEAM_ID ?? '';\nexport const PROJECT_ID: string = process.env.PROJECT_ID ?? '';\nexport const BUILD_ID: string = process.env.BUILD_ID ?? '';\nexport const BUILD_URL: string = process.env.BUILD_URL ?? '';\nexport const LOG_REDIS_URL: string = process.env.LOG_REDIS_URL ?? 'redis://localhost:6379';\nexport const BUSINESS_JWT_TOKEN: string = process.env.BUSINESS_JWT_TOKEN ?? '';\nexport const PLAYGROUND_JWT_TOKEN: string = process.env.PLAYGROUND_JWT_TOKEN ?? '';\nexport const USER_IP_ADDRESS: string = process.env.USER_IP_ADDRESS ?? '';\nexport const MASTRA_DIRECTORY: string = process.env.MASTRA_DIRECTORY ?? 'src/mastra';\nexport const PROJECT_ENV_VARS: Record<string, string> = safelyParseJson(process.env.PROJECT_ENV_VARS ?? '{}');\n\nexport const PROJECT_ROOT = LOCAL ? os.tmpdir() + '/project' : (process.env.PROJECT_ROOT ?? '/project');\n\nexport function safelyParseJson(json: string) {\n try {\n return JSON.parse(json);\n } catch {\n return {};\n }\n}\n","import type { TransformCallback } from 'node:stream';\nimport type { BaseLogMessage, LogLevel } from '@mastra/core/logger';\nimport { LoggerTransport } from '@mastra/core/logger';\nimport { PinoLogger } from '@mastra/loggers';\nimport { createClient } from 'redis';\nimport { BUILD_ID, LOG_REDIS_URL, PROJECT_ID, TEAM_ID } from './constants.js';\n\nconst redisClient = createClient({\n url: LOG_REDIS_URL,\n});\n\nclass RedisTransport extends LoggerTransport {\n _transform(chunk: any, _encoding: string, callback: TransformCallback): void {\n chunk = chunk.toString();\n const logKey = `builder:logs:${TEAM_ID}:${PROJECT_ID}:${BUILD_ID}`;\n const ttl = 2 * 24 * 60 * 60; // 2 days in seconds\n const logData = typeof chunk === 'string' ? chunk : JSON.stringify(chunk);\n\n // Don't block the event loop - process logs asynchronously\n process.nextTick(async () => {\n try {\n // Connect to Redis if not already connected\n if (!redisClient.isOpen) {\n await redisClient.connect().catch(err => {\n console.error('Redis connection error:', err);\n });\n }\n\n // Use pipeline to batch Redis operations\n const pipeline = redisClient.multi();\n pipeline.rPush(logKey, logData);\n pipeline.expire(logKey, ttl);\n await pipeline.exec();\n } catch (err) {\n console.error('Redis logging error:', err);\n }\n });\n\n // Immediately pass through the chunk without waiting\n callback(null, chunk);\n }\n\n _write(chunk: any, encoding?: string, callback?: (error?: Error | null) => void): boolean {\n if (typeof callback === 'function') {\n this._transform(chunk, encoding || 'utf8', callback);\n return true;\n }\n\n this._transform(chunk, encoding || 'utf8', (error: Error | null | undefined) => {\n if (error) console.error('Transform error in write:', error);\n });\n return true;\n }\n\n async _flush(): Promise<void> {\n // // Ensure the pipeline is closed and flushed\n // redisClient.quit().catch(err => {\n // console.error('Redis connection error:', err);\n // });\n // callback();\n await new Promise(resolve => setTimeout(resolve, 10));\n }\n\n async _destroy(err: Error, cb: Function) {\n await closeLogger();\n cb(err);\n }\n\n listLogs(_args: {\n fromDate?: Date;\n toDate?: Date;\n logLevel?: LogLevel;\n filters?: Record<string, any>;\n returnPaginationResults?: boolean;\n page?: number;\n perPage?: number;\n }): Promise<{ logs: BaseLogMessage[]; total: number; page: number; perPage: number; hasMore: boolean }> {\n return Promise.resolve({\n logs: [],\n total: 0,\n page: _args?.page ?? 1,\n perPage: _args?.perPage ?? 100,\n hasMore: false,\n });\n }\n\n listLogsByRunId(_args?: {\n fromDate?: Date;\n toDate?: Date;\n logLevel?: LogLevel;\n filters?: Record<string, any>;\n returnPaginationResults?: boolean;\n page?: number;\n perPage?: number;\n }): Promise<{\n logs: BaseLogMessage[];\n total: number;\n page: number;\n perPage: number;\n hasMore: boolean;\n }> {\n return Promise.resolve({\n logs: [],\n total: 0,\n page: _args?.page ?? 1,\n perPage: _args?.perPage ?? 100,\n hasMore: false,\n });\n }\n}\n\nexport const transport = new RedisTransport();\n\nexport const closeLogger = async () => {\n if (redisClient.isOpen) {\n setTimeout(async () => {\n await redisClient.quit();\n }, 10);\n }\n};\n\nexport const logger = new PinoLogger({\n level: 'info',\n transports: {\n redis: transport,\n },\n});\n","import { createRequire } from 'node:module';\nimport { Writable } from 'node:stream';\nimport { execa } from 'execa';\nimport { PROJECT_ENV_VARS, PROJECT_ROOT } from './constants.js';\nimport { logger } from './logger.js';\n\nexport const createPinoStream = () => {\n return new Writable({\n write(chunk, _encoding, callback) {\n // Convert Buffer/string to string and trim whitespace\n const line = chunk.toString().trim();\n\n if (line) {\n // Log each line through Pino\n logger.info(line);\n }\n\n callback();\n },\n });\n};\n\nexport async function runWithExeca({\n cmd,\n args,\n cwd = process.cwd(),\n env = PROJECT_ENV_VARS,\n}: {\n cmd: string;\n args: string[];\n cwd?: string;\n env?: Record<string, string>;\n}): Promise<{ stdout?: string; stderr?: string; success: boolean; error?: Error }> {\n const pinoStream = createPinoStream();\n\n try {\n const subprocess = execa(cmd, args, {\n cwd,\n stdin: 'ignore',\n env: {\n ...process.env,\n ...env,\n },\n });\n\n // Pipe stdout and stderr through the logging stream.\n // { end: false } prevents the first stream to close from ending pinoStream\n // while the other may still be writing.\n subprocess.stdout?.pipe(pinoStream, { end: false });\n subprocess.stderr?.pipe(pinoStream, { end: false });\n\n const { stdout, stderr, exitCode } = await subprocess;\n pinoStream.end();\n return { stdout, stderr, success: exitCode === 0 };\n } catch (error) {\n pinoStream.end();\n logger.error('Process failed', { error });\n return { success: false, error: error instanceof Error ? error : new Error(String(error)) };\n }\n}\n\nexport function runWithChildProcess(cmd: string, args: string[]): { stdout?: string; stderr?: string } {\n const pinoStream = createPinoStream();\n\n try {\n const __require = typeof require === 'function' ? require : createRequire(import.meta.url);\n const { stdout, stderr } = __require('node:child_process').spawnSync(cmd, args, {\n cwd: PROJECT_ROOT,\n encoding: 'utf8',\n shell: true,\n env: {\n ...process.env,\n ...PROJECT_ENV_VARS,\n },\n maxBuffer: 1024 * 1024 * 10, // 10MB buffer\n });\n\n if (stdout) {\n pinoStream.write(stdout);\n }\n if (stderr) {\n pinoStream.write(stderr);\n }\n\n pinoStream.end();\n return { stdout, stderr };\n } catch (error) {\n logger.error('Process failed' + error);\n pinoStream.end();\n return {};\n }\n}\n","import * as fs from 'node:fs';\nimport { join, resolve } from 'node:path';\n\nimport { MastraError } from '@mastra/core/error';\nimport { runWithExeca } from './execa.js';\nimport { logger } from './logger.js';\n\nconst MEMOIZED = new Map();\n\nfunction findLockFile(dir: string): string | null {\n const lockFiles = ['pnpm-lock.yaml', 'package-lock.json', 'yarn.lock', 'bun.lock'];\n for (const file of lockFiles) {\n if (fs.existsSync(join(dir, file))) {\n return file;\n }\n }\n const parentDir = resolve(dir, '..');\n if (parentDir !== dir) {\n return findLockFile(parentDir);\n }\n return null;\n}\n\nexport function detectPm({ path }: { path: string }): string {\n const cached = MEMOIZED.get(path);\n if (cached) {\n return cached;\n }\n\n const lockFile = findLockFile(path);\n let pm: string = 'npm';\n switch (lockFile) {\n case 'pnpm-lock.yaml':\n pm = 'pnpm';\n break;\n case 'package-lock.json':\n pm = 'npm';\n break;\n case 'yarn.lock':\n pm = 'yarn';\n break;\n case 'bun.lock':\n pm = 'bun';\n break;\n default:\n pm = 'npm';\n }\n\n MEMOIZED.set(path, pm);\n return pm;\n}\n\nexport async function installNodeVersion({ path }: { path: string }) {\n let nvmrcExists = false;\n let nodeVersionExists = false;\n\n try {\n fs.accessSync(join(path, '.nvmrc'));\n nvmrcExists = true;\n } catch {\n // File does not exist\n }\n\n try {\n fs.accessSync(join(path, '.node-version'));\n nodeVersionExists = true;\n } catch {\n // File does not exist\n }\n\n if (nvmrcExists || nodeVersionExists) {\n logger.info('Node version file found, installing specified Node.js version...');\n const { success, error } = await runWithExeca({\n cmd: 'n',\n args: ['auto'],\n cwd: path,\n });\n if (!success) {\n throw new MastraError(\n {\n id: 'NODE_FAIL_INSTALL_SPECIFIED_VERSION',\n category: 'USER',\n domain: 'DEPLOYER',\n },\n error,\n );\n }\n }\n}\n\nexport async function installDeps({ path, pm }: { path: string; pm?: string }) {\n pm = pm ?? detectPm({ path });\n logger.info('Installing dependencies', { pm, path });\n // --force is needed to install peer deps for external packages in the mastra output directory\n // --legacy-peer-deps=false is needed to override other overrides by the repo package manager such as pnpm. Pnpm would set it to true\n const args = ['install', '--legacy-peer-deps=false', '--force'];\n const { success, error } = await runWithExeca({ cmd: pm, args, cwd: path });\n if (!success) {\n throw new MastraError(\n {\n id: 'FAIL_INSTALL_DEPS',\n category: 'USER',\n domain: 'DEPLOYER',\n },\n error,\n );\n }\n}\n\nexport async function runInstallCommand({ path, installCommand }: { path: string; installCommand: string }) {\n logger.info('Running install command', { command: installCommand, path });\n const { success, error } = await runWithExeca({ cmd: 'sh', args: ['-c', installCommand], cwd: path });\n if (!success) {\n throw new MastraError(\n {\n id: 'FAIL_CUSTOM_INSTALL_COMMAND',\n category: 'USER',\n domain: 'DEPLOYER',\n },\n error,\n );\n }\n}\n\nexport async function runScript({ scriptName, path, args }: { scriptName: string; path: string; args?: string[] }) {\n const pm = detectPm({ path });\n logger.info('Running script', { script: scriptName, pm });\n const { success, error } = await runWithExeca({\n cmd: pm,\n args: pm === 'npm' ? ['run', scriptName, ...(args ?? [])] : [scriptName, ...(args ?? [])],\n cwd: path,\n });\n if (!success) {\n throw new MastraError(\n {\n id: 'FAIL_BUILD_SCRIPT',\n category: 'USER',\n domain: 'DEPLOYER',\n },\n error,\n );\n }\n}\n\nexport async function runBuildCommand({ command, path }: { command: string; path: string }) {\n logger.info('Running build command', { command });\n const { success, error } = await runWithExeca({ cmd: 'sh', args: ['-c', command], cwd: path });\n if (!success) {\n throw new MastraError(\n {\n id: 'FAIL_BUILD_COMMAND',\n category: 'USER',\n domain: 'DEPLOYER',\n },\n error,\n );\n }\n}\n","import { join } from 'node:path';\nimport { MastraError } from '@mastra/core/error';\nimport { FileService } from '@mastra/deployer';\n\nimport { MASTRA_DIRECTORY } from './constants.js';\n\nexport function getMastraEntryFile(mastraDir: string) {\n try {\n const fileService = new FileService();\n return fileService.getFirstExistingFile([\n join(mastraDir, MASTRA_DIRECTORY, 'index.ts'),\n join(mastraDir, MASTRA_DIRECTORY, 'index.js'),\n ]);\n } catch (error) {\n throw new MastraError(\n {\n id: 'MASTRA_ENTRY_FILE_NOT_FOUND',\n category: 'USER',\n domain: 'DEPLOYER',\n },\n error,\n );\n }\n}\n","import { PROJECT_ID, BUILD_ID, BUILD_URL, USER_IP_ADDRESS } from './constants.js';\n\nexport function successEntrypoint() {\n return `\n if (process.env.CI !== 'true') {\n await fetch('${process.env.REPORTER_API_URL}', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: 'Bearer ${process.env.REPORTER_API_URL_AUTH_TOKEN}',\n },\n body: JSON.stringify(${JSON.stringify({\n projectId: PROJECT_ID,\n buildId: BUILD_ID,\n status: 'success',\n url: BUILD_URL,\n userIpAddress: USER_IP_ADDRESS,\n })}),\n }).catch(err => {\n console.error('Failed to report build status to monitoring service', {\n error: err,\n });\n })\n }\n `;\n}\n","import { join, dirname } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { Config } from '@mastra/core/mastra';\nimport { Deployer } from '@mastra/deployer';\nimport { copy, readJSON } from 'fs-extra/esm';\n\nimport { getAuthEntrypoint } from './utils/auth.js';\nimport { MASTRA_DIRECTORY, BUILD_ID, PROJECT_ID, TEAM_ID } from './utils/constants.js';\nimport { installDeps } from './utils/deps.js';\nimport { getMastraEntryFile } from './utils/file.js';\nimport { successEntrypoint } from './utils/report.js';\n\nexport class CloudDeployer extends Deployer {\n private studio: boolean;\n\n constructor({ studio }: { studio?: boolean } = {}) {\n super({ name: 'cloud' });\n this.studio = studio ?? false;\n }\n\n protected async getUserBundlerOptions(\n mastraEntryFile: string,\n outputDirectory: string,\n ): Promise<NonNullable<Config['bundler']>> {\n const bundlerOptions = await super.getUserBundlerOptions(mastraEntryFile, outputDirectory);\n\n // Always force externals: true for cloud deployments.\n // The cloud deployer installs all dependencies from npm into node_modules,\n // so bundling them inline serves no purpose. Bundling inline can also cause\n // circular module evaluation deadlocks when dynamic imports (e.g. in\n // MemoryLibSQL.init()) reference chunks that depend back on the entry module,\n // resulting in \"Detected unsettled top-level await\" warnings.\n return {\n ...bundlerOptions,\n externals: true,\n };\n }\n\n async deploy(_outputDirectory: string): Promise<void> {}\n\n async prepare(outputDirectory: string): Promise<void> {\n await super.prepare(outputDirectory);\n\n if (this.studio) {\n const __filename = fileURLToPath(import.meta.url);\n const __dirname = dirname(__filename);\n\n const studioServePath = join(outputDirectory, this.outputDir, 'studio');\n await copy(join(dirname(__dirname), join('dist', 'studio')), studioServePath, {\n overwrite: true,\n });\n }\n }\n async writePackageJson(outputDirectory: string, dependencies: Map<string, string>) {\n const versions = (await readJSON(join(dirname(fileURLToPath(import.meta.url)), '../versions.json'))) as\n | Record<string, string>\n | undefined;\n for (const [pkgName, version] of Object.entries(versions || {})) {\n dependencies.set(pkgName, version);\n }\n\n return super.writePackageJson(outputDirectory, dependencies);\n }\n\n async lint() {}\n\n protected async installDependencies(outputDirectory: string, _rootDir = process.cwd()) {\n await installDeps({ path: join(outputDirectory, 'output'), pm: 'npm' });\n }\n\n async bundle(mastraDir: string, outputDirectory: string): Promise<void> {\n const currentCwd = process.cwd();\n process.chdir(mastraDir);\n\n const mastraEntryFile = getMastraEntryFile(mastraDir);\n\n const mastraAppDir = join(mastraDir, MASTRA_DIRECTORY);\n\n // Use the getAllToolPaths method to prepare tools paths\n const discoveredTools = this.getAllToolPaths(mastraAppDir);\n\n await this.prepare(outputDirectory);\n await this._bundle(\n this.getEntry(),\n mastraEntryFile,\n {\n outputDirectory,\n projectRoot: mastraDir,\n },\n discoveredTools,\n );\n process.chdir(currentCwd);\n }\n\n getAuthEntrypoint() {\n return getAuthEntrypoint();\n }\n\n private getEntry(): string {\n return `\nimport { createNodeServer, getToolExports } from '#server';\nimport { tools } from '#tools';\nimport { mastra } from '#mastra';\nimport { MultiLogger } from '@mastra/core/logger';\nimport { PinoLogger } from '@mastra/loggers';\nimport { HttpTransport } from '@mastra/loggers/http';\nimport { LibSQLStore, LibSQLVector } from '@mastra/libsql';\nimport { scoreTracesWorkflow } from '@mastra/core/evals/scoreTraces';\n\nconst startTime = process.env.RUNNER_START_TIME ? new Date(process.env.RUNNER_START_TIME).getTime() : Date.now();\nconst createNodeServerStartTime = Date.now();\n\nconsole.log(JSON.stringify({\n message: \"Server starting\",\n operation: 'builder.createNodeServer',\n operation_startTime: createNodeServerStartTime,\n type: \"READINESS\",\n startTime,\n metadata: {\n teamId: \"${TEAM_ID}\",\n projectId: \"${PROJECT_ID}\",\n buildId: \"${BUILD_ID}\",\n },\n}));\n\nconst transports = {}\nif (process.env.CI !== 'true') {\n if (process.env.BUSINESS_API_RUNNER_LOGS_ENDPOINT) {\n transports.default = new HttpTransport({\n url: process.env.BUSINESS_API_RUNNER_LOGS_ENDPOINT,\n headers: {\n Authorization: 'Bearer ' + process.env.BUSINESS_JWT_TOKEN,\n },\n });\n }\n}\n\nconst logger = new PinoLogger({\n name: 'MastraCloud',\n transports,\n level: 'debug',\n});\nconst existingLogger = mastra?.getLogger();\nconst combinedLogger = existingLogger ? new MultiLogger([logger, existingLogger]) : logger;\n\nmastra.setLogger({ logger: combinedLogger });\n\nif (process.env.MASTRA_STORAGE_URL && process.env.MASTRA_STORAGE_AUTH_TOKEN) {\n const { MastraStorage } = await import('@mastra/core/storage');\n logger.info('Using Mastra Cloud Storage: ' + process.env.MASTRA_STORAGE_URL)\n const storage = new LibSQLStore({\n id: 'mastra-cloud-storage-libsql',\n url: process.env.MASTRA_STORAGE_URL,\n authToken: process.env.MASTRA_STORAGE_AUTH_TOKEN,\n })\n const vector = new LibSQLVector({\n id: 'mastra-cloud-storage-libsql-vector',\n url: process.env.MASTRA_STORAGE_URL,\n authToken: process.env.MASTRA_STORAGE_AUTH_TOKEN,\n })\n\n await storage.init()\n mastra?.setStorage(storage)\n} else {\n const userStorage = mastra?.getStorage();\n if (userStorage && !userStorage.disableInit) {\n userStorage.init();\n }\n}\n\nif (mastra?.getStorage()) {\n mastra.__registerInternalWorkflow(scoreTracesWorkflow);\n}\n\n${getAuthEntrypoint()}\n\nawait createNodeServer(mastra, { studio: ${this.studio}, swaggerUI: false, tools: getToolExports(tools) });\n\n${successEntrypoint()}\n\nconsole.log(JSON.stringify({\n message: \"Server started\",\n operation: 'builder.createNodeServer',\n operation_startTime: createNodeServerStartTime,\n operation_durationMs: Date.now() - createNodeServerStartTime,\n type: \"READINESS\",\n startTime,\n metadata: {\n teamId: \"${TEAM_ID}\",\n projectId: \"${PROJECT_ID}\",\n buildId: \"${BUILD_ID}\",\n },\n}));\n\n\nconsole.log(JSON.stringify({\n message: \"Runner Initialized\",\n type: \"READINESS\",\n startTime,\n durationMs: Date.now() - startTime,\n metadata: {\n teamId: \"${TEAM_ID}\",\n projectId: \"${PROJECT_ID}\",\n buildId: \"${BUILD_ID}\",\n },\n}));\n`;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAgB,oBAAoB;CAClC,MAAM,eAA6D,CAAC;CAEpE,IAAI,QAAQ,IAAI,sBACd,aAAa,QAAQ,IAAI,wBAAwB;EAAE,IAAI;EAAgB,MAAM;CAAM;CAErF,IAAI,QAAQ,IAAI,oBACd,aAAa,QAAQ,IAAI,sBAAsB;EAAE,IAAI;EAAgB,MAAM;CAAM;CAGnF,OAAO;;;;;;;;kBAQS,KAAK,UAAU,YAAY,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6D/C;;;AC7EA,MAAa,QAAQ,QAAQ,IAAI,UAAU;AAC3C,MAAa,UAAkB,QAAQ,IAAI,WAAW;AACtD,MAAa,aAAqB,QAAQ,IAAI,cAAc;AAC5D,MAAa,WAAmB,QAAQ,IAAI,YAAY;AACxD,MAAa,YAAoB,QAAQ,IAAI,aAAa;AAC1D,MAAa,gBAAwB,QAAQ,IAAI,iBAAiB;AACxB,QAAQ,IAAI;AACV,QAAQ,IAAI;AACxD,MAAa,kBAA0B,QAAQ,IA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WAA2B;EACzB,OAAO;;;;;;;;;;;;;;;;;;;;eAoBI,QAAQ;kBACL,WAAW;gBACb,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqDvB,kBAAkB,EAAE;;2CAEqB,KAAK,OAAO;;EAErD,kBAAkB,EAAE;;;;;;;;;;eAUP,QAAQ;kBACL,WAAW;gBACb,SAAS;;;;;;;;;;;eAWV,QAAQ;kBACL,WAAW;gBACb,SAAS;;;;CAIvB;AACF"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["createClient","LoggerTransport","PinoLogger","Writable","join","resolve","MastraError","FileService","join","MastraError","Deployer","__filename","fileURLToPath","__dirname","dirname","join","copy","readJSON"],"sources":["../src/utils/auth.ts","../src/utils/constants.ts","../src/utils/logger.ts","../src/utils/execa.ts","../src/utils/deps.ts","../src/utils/file.ts","../src/utils/report.ts","../src/index.ts"],"sourcesContent":["export function getAuthEntrypoint() {\n const tokensObject: Record<string, { id: string; role: string }> = {};\n\n if (process.env.PLAYGROUND_JWT_TOKEN) {\n tokensObject[process.env.PLAYGROUND_JWT_TOKEN] = { id: 'business-api', role: 'api' };\n }\n if (process.env.BUSINESS_JWT_TOKEN) {\n tokensObject[process.env.BUSINESS_JWT_TOKEN] = { id: 'business-api', role: 'api' };\n }\n\n return `\n import { SimpleAuth, CompositeAuth } from '@mastra/core/server';\n import { MastraCloudAuthProvider, MastraRBACCloud } from '@mastra/auth-cloud';\n\n // Service token auth (for business-api, playground internal calls)\n class MastraCloudServiceAuth extends SimpleAuth {\n constructor() {\n super({\n tokens: ${JSON.stringify(tokensObject)}\n });\n }\n\n async authorizeUser(user, request) {\n // Allow access to /api path\n if (request && request.url && new URL(request.url).pathname === '/api') {\n return true;\n }\n // Allow access for business-api users\n if (user && user.id === 'business-api') {\n return true;\n }\n return false;\n }\n }\n\n const serviceAuth = new MastraCloudServiceAuth();\n\n // Cloud user auth (for end users via OAuth)\n // Only enabled if MASTRA_CLOUD_API_URL is set\n let cloudUserAuth = null;\n if (process.env.MASTRA_CLOUD_API_URL) {\n cloudUserAuth = new MastraCloudAuthProvider({\n projectId: process.env.PROJECT_ID,\n cloudBaseUrl: process.env.MASTRA_CLOUD_API_URL,\n callbackUrl: process.env.MASTRA_CLOUD_CALLBACK_URL || \\`\\${process.env.MASTRA_CLOUD_API_URL}/auth/callback\\`,\n });\n }\n\n const serverConfig = mastra.getServer();\n const userAuth = serverConfig?.auth;\n\n // Only enable auth if cloudUserAuth or userAuth are defined\n if (serverConfig && (cloudUserAuth || userAuth)) {\n // Build provider list: service auth first, then cloud user auth, then user's custom auth\n const providers = [serviceAuth];\n if (cloudUserAuth) {\n providers.push(cloudUserAuth);\n }\n if (userAuth) {\n providers.push(userAuth);\n }\n\n serverConfig.auth = new CompositeAuth(providers);\n\n // If cloud auth is enabled but no RBAC is configured, add default cloud RBAC\n if (cloudUserAuth && !serverConfig.rbac) {\n serverConfig.rbac = new MastraRBACCloud({\n roleMapping: {\n owner: ['*'],\n admin: ['*:read', '*:write', '*:execute'],\n api: ['*:read', '*:write', '*:execute'],\n member: ['*:read', '*:execute'],\n viewer: ['*:read'],\n _default: [],\n },\n });\n }\n }\n `;\n}\n","import os from 'node:os';\n\nexport const LOCAL = process.env.LOCAL === 'true';\nexport const TEAM_ID: string = process.env.TEAM_ID ?? '';\nexport const PROJECT_ID: string = process.env.PROJECT_ID ?? '';\nexport const BUILD_ID: string = process.env.BUILD_ID ?? '';\nexport const BUILD_URL: string = process.env.BUILD_URL ?? '';\nexport const LOG_REDIS_URL: string = process.env.LOG_REDIS_URL ?? 'redis://localhost:6379';\nexport const BUSINESS_JWT_TOKEN: string = process.env.BUSINESS_JWT_TOKEN ?? '';\nexport const PLAYGROUND_JWT_TOKEN: string = process.env.PLAYGROUND_JWT_TOKEN ?? '';\nexport const USER_IP_ADDRESS: string = process.env.USER_IP_ADDRESS ?? '';\nexport const MASTRA_DIRECTORY: string = process.env.MASTRA_DIRECTORY ?? 'src/mastra';\nexport const PROJECT_ENV_VARS: Record<string, string> = safelyParseJson(process.env.PROJECT_ENV_VARS ?? '{}');\n\nexport const PROJECT_ROOT = LOCAL ? os.tmpdir() + '/project' : (process.env.PROJECT_ROOT ?? '/project');\n\nexport function safelyParseJson(json: string) {\n try {\n return JSON.parse(json);\n } catch {\n return {};\n }\n}\n","import type { TransformCallback } from 'node:stream';\nimport type { BaseLogMessage, LogLevel } from '@mastra/core/logger';\nimport { LoggerTransport } from '@mastra/core/logger';\nimport { PinoLogger } from '@mastra/loggers';\nimport { createClient } from 'redis';\nimport { BUILD_ID, LOG_REDIS_URL, PROJECT_ID, TEAM_ID } from './constants.js';\n\nconst redisClient = createClient({\n url: LOG_REDIS_URL,\n});\n\nclass RedisTransport extends LoggerTransport {\n _transform(chunk: any, _encoding: string, callback: TransformCallback): void {\n chunk = chunk.toString();\n const logKey = `builder:logs:${TEAM_ID}:${PROJECT_ID}:${BUILD_ID}`;\n const ttl = 2 * 24 * 60 * 60; // 2 days in seconds\n const logData = typeof chunk === 'string' ? chunk : JSON.stringify(chunk);\n\n // Don't block the event loop - process logs asynchronously\n process.nextTick(async () => {\n try {\n // Connect to Redis if not already connected\n if (!redisClient.isOpen) {\n await redisClient.connect().catch(err => {\n console.error('Redis connection error:', err);\n });\n }\n\n // Use pipeline to batch Redis operations\n const pipeline = redisClient.multi();\n pipeline.rPush(logKey, logData);\n pipeline.expire(logKey, ttl);\n await pipeline.exec();\n } catch (err) {\n console.error('Redis logging error:', err);\n }\n });\n\n // Immediately pass through the chunk without waiting\n callback(null, chunk);\n }\n\n _write(chunk: any, encoding?: string, callback?: (error?: Error | null) => void): boolean {\n if (typeof callback === 'function') {\n this._transform(chunk, encoding || 'utf8', callback);\n return true;\n }\n\n this._transform(chunk, encoding || 'utf8', (error: Error | null | undefined) => {\n if (error) console.error('Transform error in write:', error);\n });\n return true;\n }\n\n async _flush(): Promise<void> {\n // // Ensure the pipeline is closed and flushed\n // redisClient.quit().catch(err => {\n // console.error('Redis connection error:', err);\n // });\n // callback();\n await new Promise(resolve => setTimeout(resolve, 10));\n }\n\n async _destroy(err: Error, cb: Function) {\n await closeLogger();\n cb(err);\n }\n\n listLogs(_args: {\n fromDate?: Date;\n toDate?: Date;\n logLevel?: LogLevel;\n filters?: Record<string, any>;\n returnPaginationResults?: boolean;\n page?: number;\n perPage?: number;\n }): Promise<{ logs: BaseLogMessage[]; total: number; page: number; perPage: number; hasMore: boolean }> {\n return Promise.resolve({\n logs: [],\n total: 0,\n page: _args?.page ?? 1,\n perPage: _args?.perPage ?? 100,\n hasMore: false,\n });\n }\n\n listLogsByRunId(_args?: {\n fromDate?: Date;\n toDate?: Date;\n logLevel?: LogLevel;\n filters?: Record<string, any>;\n returnPaginationResults?: boolean;\n page?: number;\n perPage?: number;\n }): Promise<{\n logs: BaseLogMessage[];\n total: number;\n page: number;\n perPage: number;\n hasMore: boolean;\n }> {\n return Promise.resolve({\n logs: [],\n total: 0,\n page: _args?.page ?? 1,\n perPage: _args?.perPage ?? 100,\n hasMore: false,\n });\n }\n}\n\nexport const transport = new RedisTransport();\n\nexport const closeLogger = async () => {\n if (redisClient.isOpen) {\n setTimeout(async () => {\n await redisClient.quit();\n }, 10);\n }\n};\n\nexport const logger = new PinoLogger({\n level: 'info',\n transports: {\n redis: transport,\n },\n});\n","import { createRequire } from 'node:module';\nimport { Writable } from 'node:stream';\nimport { execa } from 'execa';\nimport { PROJECT_ENV_VARS, PROJECT_ROOT } from './constants.js';\nimport { logger } from './logger.js';\n\nexport const createPinoStream = () => {\n return new Writable({\n write(chunk, _encoding, callback) {\n // Convert Buffer/string to string and trim whitespace\n const line = chunk.toString().trim();\n\n if (line) {\n // Log each line through Pino\n logger.info(line);\n }\n\n callback();\n },\n });\n};\n\nexport async function runWithExeca({\n cmd,\n args,\n cwd = process.cwd(),\n env = PROJECT_ENV_VARS,\n}: {\n cmd: string;\n args: string[];\n cwd?: string;\n env?: Record<string, string>;\n}): Promise<{ stdout?: string; stderr?: string; success: boolean; error?: Error }> {\n const pinoStream = createPinoStream();\n\n try {\n const subprocess = execa(cmd, args, {\n cwd,\n stdin: 'ignore',\n env: {\n ...process.env,\n ...env,\n },\n });\n\n // Pipe stdout and stderr through the logging stream.\n // { end: false } prevents the first stream to close from ending pinoStream\n // while the other may still be writing.\n subprocess.stdout?.pipe(pinoStream, { end: false });\n subprocess.stderr?.pipe(pinoStream, { end: false });\n\n const { stdout, stderr, exitCode } = await subprocess;\n pinoStream.end();\n return { stdout, stderr, success: exitCode === 0 };\n } catch (error) {\n pinoStream.end();\n logger.error('Process failed', { error });\n return { success: false, error: error instanceof Error ? error : new Error(String(error)) };\n }\n}\n\nexport function runWithChildProcess(cmd: string, args: string[]): { stdout?: string; stderr?: string } {\n const pinoStream = createPinoStream();\n\n try {\n const __require = typeof require === 'function' ? require : createRequire(import.meta.url);\n const { stdout, stderr } = __require('node:child_process').spawnSync(cmd, args, {\n cwd: PROJECT_ROOT,\n encoding: 'utf8',\n shell: true,\n env: {\n ...process.env,\n ...PROJECT_ENV_VARS,\n },\n maxBuffer: 1024 * 1024 * 10, // 10MB buffer\n });\n\n if (stdout) {\n pinoStream.write(stdout);\n }\n if (stderr) {\n pinoStream.write(stderr);\n }\n\n pinoStream.end();\n return { stdout, stderr };\n } catch (error) {\n logger.error('Process failed' + error);\n pinoStream.end();\n return {};\n }\n}\n","import * as fs from 'node:fs';\nimport { join, resolve } from 'node:path';\n\nimport { MastraError } from '@mastra/core/error';\nimport { runWithExeca } from './execa.js';\nimport { logger } from './logger.js';\n\nconst MEMOIZED = new Map();\n\nfunction findLockFile(dir: string): string | null {\n const lockFiles = ['pnpm-lock.yaml', 'package-lock.json', 'yarn.lock', 'bun.lock'];\n for (const file of lockFiles) {\n if (fs.existsSync(join(dir, file))) {\n return file;\n }\n }\n const parentDir = resolve(dir, '..');\n if (parentDir !== dir) {\n return findLockFile(parentDir);\n }\n return null;\n}\n\nexport function detectPm({ path }: { path: string }): string {\n const cached = MEMOIZED.get(path);\n if (cached) {\n return cached;\n }\n\n const lockFile = findLockFile(path);\n let pm: string = 'npm';\n switch (lockFile) {\n case 'pnpm-lock.yaml':\n pm = 'pnpm';\n break;\n case 'package-lock.json':\n pm = 'npm';\n break;\n case 'yarn.lock':\n pm = 'yarn';\n break;\n case 'bun.lock':\n pm = 'bun';\n break;\n default:\n pm = 'npm';\n }\n\n MEMOIZED.set(path, pm);\n return pm;\n}\n\nexport async function installNodeVersion({ path }: { path: string }) {\n let nvmrcExists = false;\n let nodeVersionExists = false;\n\n try {\n fs.accessSync(join(path, '.nvmrc'));\n nvmrcExists = true;\n } catch {\n // File does not exist\n }\n\n try {\n fs.accessSync(join(path, '.node-version'));\n nodeVersionExists = true;\n } catch {\n // File does not exist\n }\n\n if (nvmrcExists || nodeVersionExists) {\n logger.info('Node version file found, installing specified Node.js version...');\n const { success, error } = await runWithExeca({\n cmd: 'n',\n args: ['auto'],\n cwd: path,\n });\n if (!success) {\n throw new MastraError(\n {\n id: 'NODE_FAIL_INSTALL_SPECIFIED_VERSION',\n category: 'USER',\n domain: 'DEPLOYER',\n },\n error,\n );\n }\n }\n}\n\nexport async function installDeps({ path, pm }: { path: string; pm?: string }) {\n pm = pm ?? detectPm({ path });\n logger.info('Installing dependencies', { pm, path });\n // --force is needed to install peer deps for external packages in the mastra output directory\n // --legacy-peer-deps=false is needed to override other overrides by the repo package manager such as pnpm. Pnpm would set it to true\n const args = ['install', '--legacy-peer-deps=false', '--force'];\n const { success, error } = await runWithExeca({ cmd: pm, args, cwd: path });\n if (!success) {\n throw new MastraError(\n {\n id: 'FAIL_INSTALL_DEPS',\n category: 'USER',\n domain: 'DEPLOYER',\n },\n error,\n );\n }\n}\n\nexport async function runInstallCommand({ path, installCommand }: { path: string; installCommand: string }) {\n logger.info('Running install command', { command: installCommand, path });\n const { success, error } = await runWithExeca({ cmd: 'sh', args: ['-c', installCommand], cwd: path });\n if (!success) {\n throw new MastraError(\n {\n id: 'FAIL_CUSTOM_INSTALL_COMMAND',\n category: 'USER',\n domain: 'DEPLOYER',\n },\n error,\n );\n }\n}\n\nexport async function runScript({ scriptName, path, args }: { scriptName: string; path: string; args?: string[] }) {\n const pm = detectPm({ path });\n logger.info('Running script', { script: scriptName, pm });\n const { success, error } = await runWithExeca({\n cmd: pm,\n args: pm === 'npm' ? ['run', scriptName, ...(args ?? [])] : [scriptName, ...(args ?? [])],\n cwd: path,\n });\n if (!success) {\n throw new MastraError(\n {\n id: 'FAIL_BUILD_SCRIPT',\n category: 'USER',\n domain: 'DEPLOYER',\n },\n error,\n );\n }\n}\n\nexport async function runBuildCommand({ command, path }: { command: string; path: string }) {\n logger.info('Running build command', { command });\n const { success, error } = await runWithExeca({ cmd: 'sh', args: ['-c', command], cwd: path });\n if (!success) {\n throw new MastraError(\n {\n id: 'FAIL_BUILD_COMMAND',\n category: 'USER',\n domain: 'DEPLOYER',\n },\n error,\n );\n }\n}\n","import { join } from 'node:path';\nimport { MastraError } from '@mastra/core/error';\nimport { FileService } from '@mastra/deployer';\n\nimport { MASTRA_DIRECTORY } from './constants.js';\n\nexport function getMastraEntryFile(mastraDir: string) {\n try {\n const fileService = new FileService();\n return fileService.getFirstExistingFile([\n join(mastraDir, MASTRA_DIRECTORY, 'index.ts'),\n join(mastraDir, MASTRA_DIRECTORY, 'index.js'),\n ]);\n } catch (error) {\n throw new MastraError(\n {\n id: 'MASTRA_ENTRY_FILE_NOT_FOUND',\n category: 'USER',\n domain: 'DEPLOYER',\n },\n error,\n );\n }\n}\n","import { PROJECT_ID, BUILD_ID, BUILD_URL, USER_IP_ADDRESS } from './constants.js';\n\nexport function successEntrypoint() {\n return `\n if (process.env.CI !== 'true') {\n await fetch('${process.env.REPORTER_API_URL}', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: 'Bearer ${process.env.REPORTER_API_URL_AUTH_TOKEN}',\n },\n body: JSON.stringify(${JSON.stringify({\n projectId: PROJECT_ID,\n buildId: BUILD_ID,\n status: 'success',\n url: BUILD_URL,\n userIpAddress: USER_IP_ADDRESS,\n })}),\n }).catch(err => {\n console.error('Failed to report build status to monitoring service', {\n error: err,\n });\n })\n }\n `;\n}\n","import { join, dirname } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { Config } from '@mastra/core/mastra';\nimport { Deployer } from '@mastra/deployer';\nimport { copy, readJSON } from 'fs-extra/esm';\n\nimport { getAuthEntrypoint } from './utils/auth.js';\nimport { MASTRA_DIRECTORY, BUILD_ID, PROJECT_ID, TEAM_ID } from './utils/constants.js';\nimport { installDeps } from './utils/deps.js';\nimport { getMastraEntryFile } from './utils/file.js';\nimport { successEntrypoint } from './utils/report.js';\n\nexport class CloudDeployer extends Deployer {\n private studio: boolean;\n\n constructor({ studio }: { studio?: boolean } = {}) {\n super({ name: 'cloud' });\n this.studio = studio ?? false;\n }\n\n protected async getUserBundlerOptions(\n mastraEntryFile: string,\n outputDirectory: string,\n ): Promise<NonNullable<Config['bundler']>> {\n const bundlerOptions = await super.getUserBundlerOptions(mastraEntryFile, outputDirectory);\n\n // Always force externals: true for cloud deployments.\n // The cloud deployer installs all dependencies from npm into node_modules,\n // so bundling them inline serves no purpose. Bundling inline can also cause\n // circular module evaluation deadlocks when dynamic imports (e.g. in\n // MemoryLibSQL.init()) reference chunks that depend back on the entry module,\n // resulting in \"Detected unsettled top-level await\" warnings.\n return {\n ...bundlerOptions,\n externals: true,\n };\n }\n\n async deploy(_outputDirectory: string): Promise<void> {}\n\n async prepare(outputDirectory: string): Promise<void> {\n await super.prepare(outputDirectory);\n\n if (this.studio) {\n const __filename = fileURLToPath(import.meta.url);\n const __dirname = dirname(__filename);\n\n const studioServePath = join(outputDirectory, this.outputDir, 'studio');\n await copy(join(dirname(__dirname), join('dist', 'studio')), studioServePath, {\n overwrite: true,\n });\n }\n }\n async writePackageJson(outputDirectory: string, dependencies: Map<string, string>) {\n const versions = (await readJSON(join(dirname(fileURLToPath(import.meta.url)), '../versions.json'))) as\n | Record<string, string>\n | undefined;\n for (const [pkgName, version] of Object.entries(versions || {})) {\n dependencies.set(pkgName, version);\n }\n\n return super.writePackageJson(outputDirectory, dependencies);\n }\n\n async lint() {}\n\n protected async installDependencies(outputDirectory: string, _rootDir = process.cwd()) {\n await installDeps({ path: join(outputDirectory, 'output'), pm: 'npm' });\n }\n\n async bundle(mastraDir: string, outputDirectory: string): Promise<void> {\n const currentCwd = process.cwd();\n process.chdir(mastraDir);\n\n const mastraEntryFile = getMastraEntryFile(mastraDir);\n\n const mastraAppDir = join(mastraDir, MASTRA_DIRECTORY);\n\n // Use the getAllToolPaths method to prepare tools paths\n const discoveredTools = this.getAllToolPaths(mastraAppDir);\n\n await this.prepare(outputDirectory);\n await this._bundle(\n this.getEntry(),\n mastraEntryFile,\n {\n outputDirectory,\n projectRoot: mastraDir,\n },\n discoveredTools,\n );\n process.chdir(currentCwd);\n }\n\n getAuthEntrypoint() {\n return getAuthEntrypoint();\n }\n\n private getEntry(): string {\n return `\nimport { createNodeServer, getToolExports } from '#server';\nimport { tools } from '#tools';\nimport { mastra } from '#mastra';\nimport { MultiLogger } from '@mastra/core/logger';\nimport { PinoLogger } from '@mastra/loggers';\nimport { HttpTransport } from '@mastra/loggers/http';\nimport { LibSQLStore, LibSQLVector } from '@mastra/libsql';\nimport { scoreTracesWorkflow } from '@mastra/core/evals/scoreTraces';\n\nconst startTime = process.env.RUNNER_START_TIME ? new Date(process.env.RUNNER_START_TIME).getTime() : Date.now();\nconst createNodeServerStartTime = Date.now();\n\nconsole.log(JSON.stringify({\n message: \"Server starting\",\n operation: 'builder.createNodeServer',\n operation_startTime: createNodeServerStartTime,\n type: \"READINESS\",\n startTime,\n metadata: {\n teamId: \"${TEAM_ID}\",\n projectId: \"${PROJECT_ID}\",\n buildId: \"${BUILD_ID}\",\n },\n}));\n\nconst transports = {}\nif (process.env.CI !== 'true') {\n if (process.env.BUSINESS_API_RUNNER_LOGS_ENDPOINT) {\n transports.default = new HttpTransport({\n url: process.env.BUSINESS_API_RUNNER_LOGS_ENDPOINT,\n headers: {\n Authorization: 'Bearer ' + process.env.BUSINESS_JWT_TOKEN,\n },\n });\n }\n}\n\nconst logger = new PinoLogger({\n name: 'MastraCloud',\n transports,\n level: 'debug',\n});\nconst existingLogger = mastra?.getLogger();\nconst combinedLogger = existingLogger ? new MultiLogger([logger, existingLogger]) : logger;\n\nmastra.setLogger({ logger: combinedLogger });\n\nif (process.env.MASTRA_STORAGE_URL && process.env.MASTRA_STORAGE_AUTH_TOKEN) {\n const { MastraStorage } = await import('@mastra/core/storage');\n logger.info('Using Mastra Cloud Storage: ' + process.env.MASTRA_STORAGE_URL)\n const storage = new LibSQLStore({\n id: 'mastra-cloud-storage-libsql',\n url: process.env.MASTRA_STORAGE_URL,\n authToken: process.env.MASTRA_STORAGE_AUTH_TOKEN,\n })\n const vector = new LibSQLVector({\n id: 'mastra-cloud-storage-libsql-vector',\n url: process.env.MASTRA_STORAGE_URL,\n authToken: process.env.MASTRA_STORAGE_AUTH_TOKEN,\n })\n\n await storage.init()\n mastra?.setStorage(storage)\n} else {\n const userStorage = mastra?.getStorage();\n if (userStorage && !userStorage.disableInit) {\n userStorage.init();\n }\n}\n\nif (mastra?.getStorage()) {\n mastra.__registerInternalWorkflow(scoreTracesWorkflow);\n}\n\n${getAuthEntrypoint()}\n\nawait createNodeServer(mastra, { studio: ${this.studio}, swaggerUI: false, tools: getToolExports(tools) });\n\n${successEntrypoint()}\n\nconsole.log(JSON.stringify({\n message: \"Server started\",\n operation: 'builder.createNodeServer',\n operation_startTime: createNodeServerStartTime,\n operation_durationMs: Date.now() - createNodeServerStartTime,\n type: \"READINESS\",\n startTime,\n metadata: {\n teamId: \"${TEAM_ID}\",\n projectId: \"${PROJECT_ID}\",\n buildId: \"${BUILD_ID}\",\n },\n}));\n\n\nconsole.log(JSON.stringify({\n message: \"Runner Initialized\",\n type: \"READINESS\",\n startTime,\n durationMs: Date.now() - startTime,\n metadata: {\n teamId: \"${TEAM_ID}\",\n projectId: \"${PROJECT_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,kBAAkB,CAAC;EAGlG,KAAK,MAAM,CAAC,SAAS,YAAY,OAAO,QAAQ,YAAY,CAAC,CAAC,GAC5D,aAAa,IAAI,SAAS,OAAO;EAGnC,OAAO,MAAM,iBAAiB,iBAAiB,YAAY;CAC7D;CAEA,MAAM,OAAO,CAAC;CAEd,MAAgB,oBAAoB,iBAAyB,WAAW,QAAQ,IAAI,GAAG;EACrF,MAAM,YAAY;GAAE,OAAA,GAAMG,KAAAA,KAAAA,CAAK,iBAAiB,QAAQ;GAAG,IAAI;EAAM,CAAC;CACxE;CAEA,MAAM,OAAO,WAAmB,iBAAwC;EACtE,MAAM,aAAa,QAAQ,IAAI;EAC/B,QAAQ,MAAM,SAAS;EAEvB,MAAM,kBAAkB,mBAAmB,SAAS;EAEpD,MAAM,gBAAA,GAAeA,KAAAA,KAAAA,CAAK,WAAW,gBAAgB;EAGrD,MAAM,kBAAkB,KAAK,gBAAgB,YAAY;EAEzD,MAAM,KAAK,QAAQ,eAAe;EAClC,MAAM,KAAK,QACT,KAAK,SAAS,GACd,iBACA;GACE;GACA,aAAa;EACf,GACA,eACF;EACA,QAAQ,MAAM,UAAU;CAC1B;CAEA,oBAAoB;EAClB,OAAO,kBAAkB;CAC3B;CAEA,WAA2B;EACzB,OAAO;;;;;;;;;;;;;;;;;;;;eAoBI,QAAQ;kBACL,WAAW;gBACb,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqDvB,kBAAkB,EAAE;;2CAEqB,KAAK,OAAO;;EAErD,kBAAkB,EAAE;;;;;;;;;;eAUP,QAAQ;kBACL,WAAW;gBACb,SAAS;;;;;;;;;;;eAWV,QAAQ;kBACL,WAAW;gBACb,SAAS;;;;CAIvB;AACF"}
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import { execa } from "execa";
|
|
|
10
10
|
import { LoggerTransport } from "@mastra/core/logger";
|
|
11
11
|
import { PinoLogger } from "@mastra/loggers";
|
|
12
12
|
import { createClient } from "redis";
|
|
13
|
-
|
|
13
|
+
// src/utils/auth.ts
|
|
14
14
|
function getAuthEntrypoint() {
|
|
15
15
|
const tokensObject = {};
|
|
16
16
|
if (process.env.PLAYGROUND_JWT_TOKEN) tokensObject[process.env.PLAYGROUND_JWT_TOKEN] = {
|
|
@@ -91,8 +91,7 @@ function getAuthEntrypoint() {
|
|
|
91
91
|
}
|
|
92
92
|
`;
|
|
93
93
|
}
|
|
94
|
-
|
|
95
|
-
//#region src/utils/constants.ts
|
|
94
|
+
// src/utils/constants.ts
|
|
96
95
|
const LOCAL = process.env.LOCAL === "true";
|
|
97
96
|
const TEAM_ID = process.env.TEAM_ID ?? "";
|
|
98
97
|
const PROJECT_ID = process.env.PROJECT_ID ?? "";
|
|
@@ -112,8 +111,7 @@ function safelyParseJson(json) {
|
|
|
112
111
|
return {};
|
|
113
112
|
}
|
|
114
113
|
}
|
|
115
|
-
|
|
116
|
-
//#region src/utils/logger.ts
|
|
114
|
+
// src/utils/logger.ts
|
|
117
115
|
const redisClient = createClient({ url: LOG_REDIS_URL });
|
|
118
116
|
var RedisTransport = class extends LoggerTransport {
|
|
119
117
|
_transform(chunk, _encoding, callback) {
|
|
@@ -182,8 +180,7 @@ const logger = new PinoLogger({
|
|
|
182
180
|
level: "info",
|
|
183
181
|
transports: { redis: transport }
|
|
184
182
|
});
|
|
185
|
-
|
|
186
|
-
//#region src/utils/execa.ts
|
|
183
|
+
// src/utils/execa.ts
|
|
187
184
|
const createPinoStream = () => {
|
|
188
185
|
return new Writable({ write(chunk, _encoding, callback) {
|
|
189
186
|
const line = chunk.toString().trim();
|
|
@@ -220,8 +217,7 @@ async function runWithExeca({ cmd, args, cwd = process.cwd(), env = PROJECT_ENV_
|
|
|
220
217
|
};
|
|
221
218
|
}
|
|
222
219
|
}
|
|
223
|
-
|
|
224
|
-
//#region src/utils/deps.ts
|
|
220
|
+
// src/utils/deps.ts
|
|
225
221
|
const MEMOIZED = /* @__PURE__ */ new Map();
|
|
226
222
|
function findLockFile(dir) {
|
|
227
223
|
for (const file of [
|
|
@@ -278,8 +274,7 @@ async function installDeps({ path, pm }) {
|
|
|
278
274
|
domain: "DEPLOYER"
|
|
279
275
|
}, error);
|
|
280
276
|
}
|
|
281
|
-
|
|
282
|
-
//#region src/utils/file.ts
|
|
277
|
+
// src/utils/file.ts
|
|
283
278
|
function getMastraEntryFile(mastraDir) {
|
|
284
279
|
try {
|
|
285
280
|
return new FileService().getFirstExistingFile([join(mastraDir, MASTRA_DIRECTORY, "index.ts"), join(mastraDir, MASTRA_DIRECTORY, "index.js")]);
|
|
@@ -291,8 +286,7 @@ function getMastraEntryFile(mastraDir) {
|
|
|
291
286
|
}, error);
|
|
292
287
|
}
|
|
293
288
|
}
|
|
294
|
-
|
|
295
|
-
//#region src/utils/report.ts
|
|
289
|
+
// src/utils/report.ts
|
|
296
290
|
function successEntrypoint() {
|
|
297
291
|
return `
|
|
298
292
|
if (process.env.CI !== 'true') {
|
|
@@ -317,8 +311,7 @@ function successEntrypoint() {
|
|
|
317
311
|
}
|
|
318
312
|
`;
|
|
319
313
|
}
|
|
320
|
-
|
|
321
|
-
//#region src/index.ts
|
|
314
|
+
// src/index.ts
|
|
322
315
|
var CloudDeployer = class extends Deployer {
|
|
323
316
|
studio;
|
|
324
317
|
constructor({ studio } = {}) {
|
|
@@ -480,7 +473,6 @@ console.log(JSON.stringify({
|
|
|
480
473
|
`;
|
|
481
474
|
}
|
|
482
475
|
};
|
|
483
|
-
//#endregion
|
|
484
476
|
export { CloudDeployer };
|
|
485
477
|
|
|
486
478
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/utils/auth.ts","../src/utils/constants.ts","../src/utils/logger.ts","../src/utils/execa.ts","../src/utils/deps.ts","../src/utils/file.ts","../src/utils/report.ts","../src/index.ts"],"sourcesContent":["export function getAuthEntrypoint() {\n const tokensObject: Record<string, { id: string; role: string }> = {};\n\n if (process.env.PLAYGROUND_JWT_TOKEN) {\n tokensObject[process.env.PLAYGROUND_JWT_TOKEN] = { id: 'business-api', role: 'api' };\n }\n if (process.env.BUSINESS_JWT_TOKEN) {\n tokensObject[process.env.BUSINESS_JWT_TOKEN] = { id: 'business-api', role: 'api' };\n }\n\n return `\n import { SimpleAuth, CompositeAuth } from '@mastra/core/server';\n import { MastraCloudAuthProvider, MastraRBACCloud } from '@mastra/auth-cloud';\n\n // Service token auth (for business-api, playground internal calls)\n class MastraCloudServiceAuth extends SimpleAuth {\n constructor() {\n super({\n tokens: ${JSON.stringify(tokensObject)}\n });\n }\n\n async authorizeUser(user, request) {\n // Allow access to /api path\n if (request && request.url && new URL(request.url).pathname === '/api') {\n return true;\n }\n // Allow access for business-api users\n if (user && user.id === 'business-api') {\n return true;\n }\n return false;\n }\n }\n\n const serviceAuth = new MastraCloudServiceAuth();\n\n // Cloud user auth (for end users via OAuth)\n // Only enabled if MASTRA_CLOUD_API_URL is set\n let cloudUserAuth = null;\n if (process.env.MASTRA_CLOUD_API_URL) {\n cloudUserAuth = new MastraCloudAuthProvider({\n projectId: process.env.PROJECT_ID,\n cloudBaseUrl: process.env.MASTRA_CLOUD_API_URL,\n callbackUrl: process.env.MASTRA_CLOUD_CALLBACK_URL || \\`\\${process.env.MASTRA_CLOUD_API_URL}/auth/callback\\`,\n });\n }\n\n const serverConfig = mastra.getServer();\n const userAuth = serverConfig?.auth;\n\n // Only enable auth if cloudUserAuth or userAuth are defined\n if (serverConfig && (cloudUserAuth || userAuth)) {\n // Build provider list: service auth first, then cloud user auth, then user's custom auth\n const providers = [serviceAuth];\n if (cloudUserAuth) {\n providers.push(cloudUserAuth);\n }\n if (userAuth) {\n providers.push(userAuth);\n }\n\n serverConfig.auth = new CompositeAuth(providers);\n\n // If cloud auth is enabled but no RBAC is configured, add default cloud RBAC\n if (cloudUserAuth && !serverConfig.rbac) {\n serverConfig.rbac = new MastraRBACCloud({\n roleMapping: {\n owner: ['*'],\n admin: ['*:read', '*:write', '*:execute'],\n api: ['*:read', '*:write', '*:execute'],\n member: ['*:read', '*:execute'],\n viewer: ['*:read'],\n _default: [],\n },\n });\n }\n }\n `;\n}\n","import os from 'node:os';\n\nexport const LOCAL = process.env.LOCAL === 'true';\nexport const TEAM_ID: string = process.env.TEAM_ID ?? '';\nexport const PROJECT_ID: string = process.env.PROJECT_ID ?? '';\nexport const BUILD_ID: string = process.env.BUILD_ID ?? '';\nexport const BUILD_URL: string = process.env.BUILD_URL ?? '';\nexport const LOG_REDIS_URL: string = process.env.LOG_REDIS_URL ?? 'redis://localhost:6379';\nexport const BUSINESS_JWT_TOKEN: string = process.env.BUSINESS_JWT_TOKEN ?? '';\nexport const PLAYGROUND_JWT_TOKEN: string = process.env.PLAYGROUND_JWT_TOKEN ?? '';\nexport const USER_IP_ADDRESS: string = process.env.USER_IP_ADDRESS ?? '';\nexport const MASTRA_DIRECTORY: string = process.env.MASTRA_DIRECTORY ?? 'src/mastra';\nexport const PROJECT_ENV_VARS: Record<string, string> = safelyParseJson(process.env.PROJECT_ENV_VARS ?? '{}');\n\nexport const PROJECT_ROOT = LOCAL ? os.tmpdir() + '/project' : (process.env.PROJECT_ROOT ?? '/project');\n\nexport function safelyParseJson(json: string) {\n try {\n return JSON.parse(json);\n } catch {\n return {};\n }\n}\n","import type { TransformCallback } from 'node:stream';\nimport type { BaseLogMessage, LogLevel } from '@mastra/core/logger';\nimport { LoggerTransport } from '@mastra/core/logger';\nimport { PinoLogger } from '@mastra/loggers';\nimport { createClient } from 'redis';\nimport { BUILD_ID, LOG_REDIS_URL, PROJECT_ID, TEAM_ID } from './constants.js';\n\nconst redisClient = createClient({\n url: LOG_REDIS_URL,\n});\n\nclass RedisTransport extends LoggerTransport {\n _transform(chunk: any, _encoding: string, callback: TransformCallback): void {\n chunk = chunk.toString();\n const logKey = `builder:logs:${TEAM_ID}:${PROJECT_ID}:${BUILD_ID}`;\n const ttl = 2 * 24 * 60 * 60; // 2 days in seconds\n const logData = typeof chunk === 'string' ? chunk : JSON.stringify(chunk);\n\n // Don't block the event loop - process logs asynchronously\n process.nextTick(async () => {\n try {\n // Connect to Redis if not already connected\n if (!redisClient.isOpen) {\n await redisClient.connect().catch(err => {\n console.error('Redis connection error:', err);\n });\n }\n\n // Use pipeline to batch Redis operations\n const pipeline = redisClient.multi();\n pipeline.rPush(logKey, logData);\n pipeline.expire(logKey, ttl);\n await pipeline.exec();\n } catch (err) {\n console.error('Redis logging error:', err);\n }\n });\n\n // Immediately pass through the chunk without waiting\n callback(null, chunk);\n }\n\n _write(chunk: any, encoding?: string, callback?: (error?: Error | null) => void): boolean {\n if (typeof callback === 'function') {\n this._transform(chunk, encoding || 'utf8', callback);\n return true;\n }\n\n this._transform(chunk, encoding || 'utf8', (error: Error | null | undefined) => {\n if (error) console.error('Transform error in write:', error);\n });\n return true;\n }\n\n async _flush(): Promise<void> {\n // // Ensure the pipeline is closed and flushed\n // redisClient.quit().catch(err => {\n // console.error('Redis connection error:', err);\n // });\n // callback();\n await new Promise(resolve => setTimeout(resolve, 10));\n }\n\n async _destroy(err: Error, cb: Function) {\n await closeLogger();\n cb(err);\n }\n\n listLogs(_args: {\n fromDate?: Date;\n toDate?: Date;\n logLevel?: LogLevel;\n filters?: Record<string, any>;\n returnPaginationResults?: boolean;\n page?: number;\n perPage?: number;\n }): Promise<{ logs: BaseLogMessage[]; total: number; page: number; perPage: number; hasMore: boolean }> {\n return Promise.resolve({\n logs: [],\n total: 0,\n page: _args?.page ?? 1,\n perPage: _args?.perPage ?? 100,\n hasMore: false,\n });\n }\n\n listLogsByRunId(_args?: {\n fromDate?: Date;\n toDate?: Date;\n logLevel?: LogLevel;\n filters?: Record<string, any>;\n returnPaginationResults?: boolean;\n page?: number;\n perPage?: number;\n }): Promise<{\n logs: BaseLogMessage[];\n total: number;\n page: number;\n perPage: number;\n hasMore: boolean;\n }> {\n return Promise.resolve({\n logs: [],\n total: 0,\n page: _args?.page ?? 1,\n perPage: _args?.perPage ?? 100,\n hasMore: false,\n });\n }\n}\n\nexport const transport = new RedisTransport();\n\nexport const closeLogger = async () => {\n if (redisClient.isOpen) {\n setTimeout(async () => {\n await redisClient.quit();\n }, 10);\n }\n};\n\nexport const logger = new PinoLogger({\n level: 'info',\n transports: {\n redis: transport,\n },\n});\n","import { createRequire } from 'node:module';\nimport { Writable } from 'node:stream';\nimport { execa } from 'execa';\nimport { PROJECT_ENV_VARS, PROJECT_ROOT } from './constants.js';\nimport { logger } from './logger.js';\n\nexport const createPinoStream = () => {\n return new Writable({\n write(chunk, _encoding, callback) {\n // Convert Buffer/string to string and trim whitespace\n const line = chunk.toString().trim();\n\n if (line) {\n // Log each line through Pino\n logger.info(line);\n }\n\n callback();\n },\n });\n};\n\nexport async function runWithExeca({\n cmd,\n args,\n cwd = process.cwd(),\n env = PROJECT_ENV_VARS,\n}: {\n cmd: string;\n args: string[];\n cwd?: string;\n env?: Record<string, string>;\n}): Promise<{ stdout?: string; stderr?: string; success: boolean; error?: Error }> {\n const pinoStream = createPinoStream();\n\n try {\n const subprocess = execa(cmd, args, {\n cwd,\n stdin: 'ignore',\n env: {\n ...process.env,\n ...env,\n },\n });\n\n // Pipe stdout and stderr through the logging stream.\n // { end: false } prevents the first stream to close from ending pinoStream\n // while the other may still be writing.\n subprocess.stdout?.pipe(pinoStream, { end: false });\n subprocess.stderr?.pipe(pinoStream, { end: false });\n\n const { stdout, stderr, exitCode } = await subprocess;\n pinoStream.end();\n return { stdout, stderr, success: exitCode === 0 };\n } catch (error) {\n pinoStream.end();\n logger.error('Process failed', { error });\n return { success: false, error: error instanceof Error ? error : new Error(String(error)) };\n }\n}\n\nexport function runWithChildProcess(cmd: string, args: string[]): { stdout?: string; stderr?: string } {\n const pinoStream = createPinoStream();\n\n try {\n const __require = typeof require === 'function' ? require : createRequire(import.meta.url);\n const { stdout, stderr } = __require('node:child_process').spawnSync(cmd, args, {\n cwd: PROJECT_ROOT,\n encoding: 'utf8',\n shell: true,\n env: {\n ...process.env,\n ...PROJECT_ENV_VARS,\n },\n maxBuffer: 1024 * 1024 * 10, // 10MB buffer\n });\n\n if (stdout) {\n pinoStream.write(stdout);\n }\n if (stderr) {\n pinoStream.write(stderr);\n }\n\n pinoStream.end();\n return { stdout, stderr };\n } catch (error) {\n logger.error('Process failed' + error);\n pinoStream.end();\n return {};\n }\n}\n","import * as fs from 'node:fs';\nimport { join, resolve } from 'node:path';\n\nimport { MastraError } from '@mastra/core/error';\nimport { runWithExeca } from './execa.js';\nimport { logger } from './logger.js';\n\nconst MEMOIZED = new Map();\n\nfunction findLockFile(dir: string): string | null {\n const lockFiles = ['pnpm-lock.yaml', 'package-lock.json', 'yarn.lock', 'bun.lock'];\n for (const file of lockFiles) {\n if (fs.existsSync(join(dir, file))) {\n return file;\n }\n }\n const parentDir = resolve(dir, '..');\n if (parentDir !== dir) {\n return findLockFile(parentDir);\n }\n return null;\n}\n\nexport function detectPm({ path }: { path: string }): string {\n const cached = MEMOIZED.get(path);\n if (cached) {\n return cached;\n }\n\n const lockFile = findLockFile(path);\n let pm: string = 'npm';\n switch (lockFile) {\n case 'pnpm-lock.yaml':\n pm = 'pnpm';\n break;\n case 'package-lock.json':\n pm = 'npm';\n break;\n case 'yarn.lock':\n pm = 'yarn';\n break;\n case 'bun.lock':\n pm = 'bun';\n break;\n default:\n pm = 'npm';\n }\n\n MEMOIZED.set(path, pm);\n return pm;\n}\n\nexport async function installNodeVersion({ path }: { path: string }) {\n let nvmrcExists = false;\n let nodeVersionExists = false;\n\n try {\n fs.accessSync(join(path, '.nvmrc'));\n nvmrcExists = true;\n } catch {\n // File does not exist\n }\n\n try {\n fs.accessSync(join(path, '.node-version'));\n nodeVersionExists = true;\n } catch {\n // File does not exist\n }\n\n if (nvmrcExists || nodeVersionExists) {\n logger.info('Node version file found, installing specified Node.js version...');\n const { success, error } = await runWithExeca({\n cmd: 'n',\n args: ['auto'],\n cwd: path,\n });\n if (!success) {\n throw new MastraError(\n {\n id: 'NODE_FAIL_INSTALL_SPECIFIED_VERSION',\n category: 'USER',\n domain: 'DEPLOYER',\n },\n error,\n );\n }\n }\n}\n\nexport async function installDeps({ path, pm }: { path: string; pm?: string }) {\n pm = pm ?? detectPm({ path });\n logger.info('Installing dependencies', { pm, path });\n // --force is needed to install peer deps for external packages in the mastra output directory\n // --legacy-peer-deps=false is needed to override other overrides by the repo package manager such as pnpm. Pnpm would set it to true\n const args = ['install', '--legacy-peer-deps=false', '--force'];\n const { success, error } = await runWithExeca({ cmd: pm, args, cwd: path });\n if (!success) {\n throw new MastraError(\n {\n id: 'FAIL_INSTALL_DEPS',\n category: 'USER',\n domain: 'DEPLOYER',\n },\n error,\n );\n }\n}\n\nexport async function runInstallCommand({ path, installCommand }: { path: string; installCommand: string }) {\n logger.info('Running install command', { command: installCommand, path });\n const { success, error } = await runWithExeca({ cmd: 'sh', args: ['-c', installCommand], cwd: path });\n if (!success) {\n throw new MastraError(\n {\n id: 'FAIL_CUSTOM_INSTALL_COMMAND',\n category: 'USER',\n domain: 'DEPLOYER',\n },\n error,\n );\n }\n}\n\nexport async function runScript({ scriptName, path, args }: { scriptName: string; path: string; args?: string[] }) {\n const pm = detectPm({ path });\n logger.info('Running script', { script: scriptName, pm });\n const { success, error } = await runWithExeca({\n cmd: pm,\n args: pm === 'npm' ? ['run', scriptName, ...(args ?? [])] : [scriptName, ...(args ?? [])],\n cwd: path,\n });\n if (!success) {\n throw new MastraError(\n {\n id: 'FAIL_BUILD_SCRIPT',\n category: 'USER',\n domain: 'DEPLOYER',\n },\n error,\n );\n }\n}\n\nexport async function runBuildCommand({ command, path }: { command: string; path: string }) {\n logger.info('Running build command', { command });\n const { success, error } = await runWithExeca({ cmd: 'sh', args: ['-c', command], cwd: path });\n if (!success) {\n throw new MastraError(\n {\n id: 'FAIL_BUILD_COMMAND',\n category: 'USER',\n domain: 'DEPLOYER',\n },\n error,\n );\n }\n}\n","import { join } from 'node:path';\nimport { MastraError } from '@mastra/core/error';\nimport { FileService } from '@mastra/deployer';\n\nimport { MASTRA_DIRECTORY } from './constants.js';\n\nexport function getMastraEntryFile(mastraDir: string) {\n try {\n const fileService = new FileService();\n return fileService.getFirstExistingFile([\n join(mastraDir, MASTRA_DIRECTORY, 'index.ts'),\n join(mastraDir, MASTRA_DIRECTORY, 'index.js'),\n ]);\n } catch (error) {\n throw new MastraError(\n {\n id: 'MASTRA_ENTRY_FILE_NOT_FOUND',\n category: 'USER',\n domain: 'DEPLOYER',\n },\n error,\n );\n }\n}\n","import { PROJECT_ID, BUILD_ID, BUILD_URL, USER_IP_ADDRESS } from './constants.js';\n\nexport function successEntrypoint() {\n return `\n if (process.env.CI !== 'true') {\n await fetch('${process.env.REPORTER_API_URL}', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: 'Bearer ${process.env.REPORTER_API_URL_AUTH_TOKEN}',\n },\n body: JSON.stringify(${JSON.stringify({\n projectId: PROJECT_ID,\n buildId: BUILD_ID,\n status: 'success',\n url: BUILD_URL,\n userIpAddress: USER_IP_ADDRESS,\n })}),\n }).catch(err => {\n console.error('Failed to report build status to monitoring service', {\n error: err,\n });\n })\n }\n `;\n}\n","import { join, dirname } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { Config } from '@mastra/core/mastra';\nimport { Deployer } from '@mastra/deployer';\nimport { copy, readJSON } from 'fs-extra/esm';\n\nimport { getAuthEntrypoint } from './utils/auth.js';\nimport { MASTRA_DIRECTORY, BUILD_ID, PROJECT_ID, TEAM_ID } from './utils/constants.js';\nimport { installDeps } from './utils/deps.js';\nimport { getMastraEntryFile } from './utils/file.js';\nimport { successEntrypoint } from './utils/report.js';\n\nexport class CloudDeployer extends Deployer {\n private studio: boolean;\n\n constructor({ studio }: { studio?: boolean } = {}) {\n super({ name: 'cloud' });\n this.studio = studio ?? false;\n }\n\n protected async getUserBundlerOptions(\n mastraEntryFile: string,\n outputDirectory: string,\n ): Promise<NonNullable<Config['bundler']>> {\n const bundlerOptions = await super.getUserBundlerOptions(mastraEntryFile, outputDirectory);\n\n // Always force externals: true for cloud deployments.\n // The cloud deployer installs all dependencies from npm into node_modules,\n // so bundling them inline serves no purpose. Bundling inline can also cause\n // circular module evaluation deadlocks when dynamic imports (e.g. in\n // MemoryLibSQL.init()) reference chunks that depend back on the entry module,\n // resulting in \"Detected unsettled top-level await\" warnings.\n return {\n ...bundlerOptions,\n externals: true,\n };\n }\n\n async deploy(_outputDirectory: string): Promise<void> {}\n\n async prepare(outputDirectory: string): Promise<void> {\n await super.prepare(outputDirectory);\n\n if (this.studio) {\n const __filename = fileURLToPath(import.meta.url);\n const __dirname = dirname(__filename);\n\n const studioServePath = join(outputDirectory, this.outputDir, 'studio');\n await copy(join(dirname(__dirname), join('dist', 'studio')), studioServePath, {\n overwrite: true,\n });\n }\n }\n async writePackageJson(outputDirectory: string, dependencies: Map<string, string>) {\n const versions = (await readJSON(join(dirname(fileURLToPath(import.meta.url)), '../versions.json'))) as\n | Record<string, string>\n | undefined;\n for (const [pkgName, version] of Object.entries(versions || {})) {\n dependencies.set(pkgName, version);\n }\n\n return super.writePackageJson(outputDirectory, dependencies);\n }\n\n async lint() {}\n\n protected async installDependencies(outputDirectory: string, _rootDir = process.cwd()) {\n await installDeps({ path: join(outputDirectory, 'output'), pm: 'npm' });\n }\n\n async bundle(mastraDir: string, outputDirectory: string): Promise<void> {\n const currentCwd = process.cwd();\n process.chdir(mastraDir);\n\n const mastraEntryFile = getMastraEntryFile(mastraDir);\n\n const mastraAppDir = join(mastraDir, MASTRA_DIRECTORY);\n\n // Use the getAllToolPaths method to prepare tools paths\n const discoveredTools = this.getAllToolPaths(mastraAppDir);\n\n await this.prepare(outputDirectory);\n await this._bundle(\n this.getEntry(),\n mastraEntryFile,\n {\n outputDirectory,\n projectRoot: mastraDir,\n },\n discoveredTools,\n );\n process.chdir(currentCwd);\n }\n\n getAuthEntrypoint() {\n return getAuthEntrypoint();\n }\n\n private getEntry(): string {\n return `\nimport { createNodeServer, getToolExports } from '#server';\nimport { tools } from '#tools';\nimport { mastra } from '#mastra';\nimport { MultiLogger } from '@mastra/core/logger';\nimport { PinoLogger } from '@mastra/loggers';\nimport { HttpTransport } from '@mastra/loggers/http';\nimport { LibSQLStore, LibSQLVector } from '@mastra/libsql';\nimport { scoreTracesWorkflow } from '@mastra/core/evals/scoreTraces';\n\nconst startTime = process.env.RUNNER_START_TIME ? new Date(process.env.RUNNER_START_TIME).getTime() : Date.now();\nconst createNodeServerStartTime = Date.now();\n\nconsole.log(JSON.stringify({\n message: \"Server starting\",\n operation: 'builder.createNodeServer',\n operation_startTime: createNodeServerStartTime,\n type: \"READINESS\",\n startTime,\n metadata: {\n teamId: \"${TEAM_ID}\",\n projectId: \"${PROJECT_ID}\",\n buildId: \"${BUILD_ID}\",\n },\n}));\n\nconst transports = {}\nif (process.env.CI !== 'true') {\n if (process.env.BUSINESS_API_RUNNER_LOGS_ENDPOINT) {\n transports.default = new HttpTransport({\n url: process.env.BUSINESS_API_RUNNER_LOGS_ENDPOINT,\n headers: {\n Authorization: 'Bearer ' + process.env.BUSINESS_JWT_TOKEN,\n },\n });\n }\n}\n\nconst logger = new PinoLogger({\n name: 'MastraCloud',\n transports,\n level: 'debug',\n});\nconst existingLogger = mastra?.getLogger();\nconst combinedLogger = existingLogger ? new MultiLogger([logger, existingLogger]) : logger;\n\nmastra.setLogger({ logger: combinedLogger });\n\nif (process.env.MASTRA_STORAGE_URL && process.env.MASTRA_STORAGE_AUTH_TOKEN) {\n const { MastraStorage } = await import('@mastra/core/storage');\n logger.info('Using Mastra Cloud Storage: ' + process.env.MASTRA_STORAGE_URL)\n const storage = new LibSQLStore({\n id: 'mastra-cloud-storage-libsql',\n url: process.env.MASTRA_STORAGE_URL,\n authToken: process.env.MASTRA_STORAGE_AUTH_TOKEN,\n })\n const vector = new LibSQLVector({\n id: 'mastra-cloud-storage-libsql-vector',\n url: process.env.MASTRA_STORAGE_URL,\n authToken: process.env.MASTRA_STORAGE_AUTH_TOKEN,\n })\n\n await storage.init()\n mastra?.setStorage(storage)\n} else {\n const userStorage = mastra?.getStorage();\n if (userStorage && !userStorage.disableInit) {\n userStorage.init();\n }\n}\n\nif (mastra?.getStorage()) {\n mastra.__registerInternalWorkflow(scoreTracesWorkflow);\n}\n\n${getAuthEntrypoint()}\n\nawait createNodeServer(mastra, { studio: ${this.studio}, swaggerUI: false, tools: getToolExports(tools) });\n\n${successEntrypoint()}\n\nconsole.log(JSON.stringify({\n message: \"Server started\",\n operation: 'builder.createNodeServer',\n operation_startTime: createNodeServerStartTime,\n operation_durationMs: Date.now() - createNodeServerStartTime,\n type: \"READINESS\",\n startTime,\n metadata: {\n teamId: \"${TEAM_ID}\",\n projectId: \"${PROJECT_ID}\",\n buildId: \"${BUILD_ID}\",\n },\n}));\n\n\nconsole.log(JSON.stringify({\n message: \"Runner Initialized\",\n type: \"READINESS\",\n startTime,\n durationMs: Date.now() - startTime,\n metadata: {\n teamId: \"${TEAM_ID}\",\n projectId: \"${PROJECT_ID}\",\n buildId: \"${BUILD_ID}\",\n },\n}));\n`;\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAAA,SAAgB,oBAAoB;CAClC,MAAM,eAA6D,CAAC;CAEpE,IAAI,QAAQ,IAAI,sBACd,aAAa,QAAQ,IAAI,wBAAwB;EAAE,IAAI;EAAgB,MAAM;CAAM;CAErF,IAAI,QAAQ,IAAI,oBACd,aAAa,QAAQ,IAAI,sBAAsB;EAAE,IAAI;EAAgB,MAAM;CAAM;CAGnF,OAAO;;;;;;;;kBAQS,KAAK,UAAU,YAAY,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6D/C;;;AC7EA,MAAa,QAAQ,QAAQ,IAAI,UAAU;AAC3C,MAAa,UAAkB,QAAQ,IAAI,WAAW;AACtD,MAAa,aAAqB,QAAQ,IAAI,cAAc;AAC5D,MAAa,WAAmB,QAAQ,IAAI,YAAY;AACxD,MAAa,Y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AAS,KAAK,QAAQ,cAAc,YAAY,GAAG,CAAC,GAAG,kBAAkB,CAAC;EAGlG,KAAK,MAAM,CAAC,SAAS,YAAY,OAAO,QAAQ,YAAY,CAAC,CAAC,GAC5D,aAAa,IAAI,SAAS,OAAO;EAGnC,OAAO,MAAM,iBAAiB,iBAAiB,YAAY;CAC7D;CAEA,MAAM,OAAO,CAAC;CAEd,MAAgB,oBAAoB,iBAAyB,WAAW,QAAQ,IAAI,GAAG;EACrF,MAAM,YAAY;GAAE,MAAM,KAAK,iBAAiB,QAAQ;GAAG,IAAI;EAAM,CAAC;CACxE;CAEA,MAAM,OAAO,WAAmB,iBAAwC;EACtE,MAAM,aAAa,QAAQ,IAAI;EAC/B,QAAQ,MAAM,SAAS;EAEvB,MAAM,kBAAkB,mBAAmB,SAAS;EAEpD,MAAM,eAAe,KAAK,WAAW,gBAAgB;EAGrD,MAAM,kBAAkB,KAAK,gBAAgB,YAAY;EAEzD,MAAM,KAAK,QAAQ,eAAe;EAClC,MAAM,KAAK,QACT,KAAK,SAAS,GACd,iBACA;GACE;GACA,aAAa;EACf,GACA,eACF;EACA,QAAQ,MAAM,UAAU;CAC1B;CAEA,oBAAoB;EAClB,OAAO,kBAAkB;CAC3B;CAEA,WAA2B;EACzB,OAAO;;;;;;;;;;;;;;;;;;;;eAoBI,QAAQ;kBACL,WAAW;gBACb,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqDvB,kBAAkB,EAAE;;2CAEqB,KAAK,OAAO;;EAErD,kBAAkB,EAAE;;;;;;;;;;eAUP,QAAQ;kBACL,WAAW;gBACb,SAAS;;;;;;;;;;;eAWV,QAAQ;kBACL,WAAW;gBACb,SAAS;;;;CAIvB;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/utils/auth.ts","../src/utils/constants.ts","../src/utils/logger.ts","../src/utils/execa.ts","../src/utils/deps.ts","../src/utils/file.ts","../src/utils/report.ts","../src/index.ts"],"sourcesContent":["export function getAuthEntrypoint() {\n const tokensObject: Record<string, { id: string; role: string }> = {};\n\n if (process.env.PLAYGROUND_JWT_TOKEN) {\n tokensObject[process.env.PLAYGROUND_JWT_TOKEN] = { id: 'business-api', role: 'api' };\n }\n if (process.env.BUSINESS_JWT_TOKEN) {\n tokensObject[process.env.BUSINESS_JWT_TOKEN] = { id: 'business-api', role: 'api' };\n }\n\n return `\n import { SimpleAuth, CompositeAuth } from '@mastra/core/server';\n import { MastraCloudAuthProvider, MastraRBACCloud } from '@mastra/auth-cloud';\n\n // Service token auth (for business-api, playground internal calls)\n class MastraCloudServiceAuth extends SimpleAuth {\n constructor() {\n super({\n tokens: ${JSON.stringify(tokensObject)}\n });\n }\n\n async authorizeUser(user, request) {\n // Allow access to /api path\n if (request && request.url && new URL(request.url).pathname === '/api') {\n return true;\n }\n // Allow access for business-api users\n if (user && user.id === 'business-api') {\n return true;\n }\n return false;\n }\n }\n\n const serviceAuth = new MastraCloudServiceAuth();\n\n // Cloud user auth (for end users via OAuth)\n // Only enabled if MASTRA_CLOUD_API_URL is set\n let cloudUserAuth = null;\n if (process.env.MASTRA_CLOUD_API_URL) {\n cloudUserAuth = new MastraCloudAuthProvider({\n projectId: process.env.PROJECT_ID,\n cloudBaseUrl: process.env.MASTRA_CLOUD_API_URL,\n callbackUrl: process.env.MASTRA_CLOUD_CALLBACK_URL || \\`\\${process.env.MASTRA_CLOUD_API_URL}/auth/callback\\`,\n });\n }\n\n const serverConfig = mastra.getServer();\n const userAuth = serverConfig?.auth;\n\n // Only enable auth if cloudUserAuth or userAuth are defined\n if (serverConfig && (cloudUserAuth || userAuth)) {\n // Build provider list: service auth first, then cloud user auth, then user's custom auth\n const providers = [serviceAuth];\n if (cloudUserAuth) {\n providers.push(cloudUserAuth);\n }\n if (userAuth) {\n providers.push(userAuth);\n }\n\n serverConfig.auth = new CompositeAuth(providers);\n\n // If cloud auth is enabled but no RBAC is configured, add default cloud RBAC\n if (cloudUserAuth && !serverConfig.rbac) {\n serverConfig.rbac = new MastraRBACCloud({\n roleMapping: {\n owner: ['*'],\n admin: ['*:read', '*:write', '*:execute'],\n api: ['*:read', '*:write', '*:execute'],\n member: ['*:read', '*:execute'],\n viewer: ['*:read'],\n _default: [],\n },\n });\n }\n }\n `;\n}\n","import os from 'node:os';\n\nexport const LOCAL = process.env.LOCAL === 'true';\nexport const TEAM_ID: string = process.env.TEAM_ID ?? '';\nexport const PROJECT_ID: string = process.env.PROJECT_ID ?? '';\nexport const BUILD_ID: string = process.env.BUILD_ID ?? '';\nexport const BUILD_URL: string = process.env.BUILD_URL ?? '';\nexport const LOG_REDIS_URL: string = process.env.LOG_REDIS_URL ?? 'redis://localhost:6379';\nexport const BUSINESS_JWT_TOKEN: string = process.env.BUSINESS_JWT_TOKEN ?? '';\nexport const PLAYGROUND_JWT_TOKEN: string = process.env.PLAYGROUND_JWT_TOKEN ?? '';\nexport const USER_IP_ADDRESS: string = process.env.USER_IP_ADDRESS ?? '';\nexport const MASTRA_DIRECTORY: string = process.env.MASTRA_DIRECTORY ?? 'src/mastra';\nexport const PROJECT_ENV_VARS: Record<string, string> = safelyParseJson(process.env.PROJECT_ENV_VARS ?? '{}');\n\nexport const PROJECT_ROOT = LOCAL ? os.tmpdir() + '/project' : (process.env.PROJECT_ROOT ?? '/project');\n\nexport function safelyParseJson(json: string) {\n try {\n return JSON.parse(json);\n } catch {\n return {};\n }\n}\n","import type { TransformCallback } from 'node:stream';\nimport type { BaseLogMessage, LogLevel } from '@mastra/core/logger';\nimport { LoggerTransport } from '@mastra/core/logger';\nimport { PinoLogger } from '@mastra/loggers';\nimport { createClient } from 'redis';\nimport { BUILD_ID, LOG_REDIS_URL, PROJECT_ID, TEAM_ID } from './constants.js';\n\nconst redisClient = createClient({\n url: LOG_REDIS_URL,\n});\n\nclass RedisTransport extends LoggerTransport {\n _transform(chunk: any, _encoding: string, callback: TransformCallback): void {\n chunk = chunk.toString();\n const logKey = `builder:logs:${TEAM_ID}:${PROJECT_ID}:${BUILD_ID}`;\n const ttl = 2 * 24 * 60 * 60; // 2 days in seconds\n const logData = typeof chunk === 'string' ? chunk : JSON.stringify(chunk);\n\n // Don't block the event loop - process logs asynchronously\n process.nextTick(async () => {\n try {\n // Connect to Redis if not already connected\n if (!redisClient.isOpen) {\n await redisClient.connect().catch(err => {\n console.error('Redis connection error:', err);\n });\n }\n\n // Use pipeline to batch Redis operations\n const pipeline = redisClient.multi();\n pipeline.rPush(logKey, logData);\n pipeline.expire(logKey, ttl);\n await pipeline.exec();\n } catch (err) {\n console.error('Redis logging error:', err);\n }\n });\n\n // Immediately pass through the chunk without waiting\n callback(null, chunk);\n }\n\n _write(chunk: any, encoding?: string, callback?: (error?: Error | null) => void): boolean {\n if (typeof callback === 'function') {\n this._transform(chunk, encoding || 'utf8', callback);\n return true;\n }\n\n this._transform(chunk, encoding || 'utf8', (error: Error | null | undefined) => {\n if (error) console.error('Transform error in write:', error);\n });\n return true;\n }\n\n async _flush(): Promise<void> {\n // // Ensure the pipeline is closed and flushed\n // redisClient.quit().catch(err => {\n // console.error('Redis connection error:', err);\n // });\n // callback();\n await new Promise(resolve => setTimeout(resolve, 10));\n }\n\n async _destroy(err: Error, cb: Function) {\n await closeLogger();\n cb(err);\n }\n\n listLogs(_args: {\n fromDate?: Date;\n toDate?: Date;\n logLevel?: LogLevel;\n filters?: Record<string, any>;\n returnPaginationResults?: boolean;\n page?: number;\n perPage?: number;\n }): Promise<{ logs: BaseLogMessage[]; total: number; page: number; perPage: number; hasMore: boolean }> {\n return Promise.resolve({\n logs: [],\n total: 0,\n page: _args?.page ?? 1,\n perPage: _args?.perPage ?? 100,\n hasMore: false,\n });\n }\n\n listLogsByRunId(_args?: {\n fromDate?: Date;\n toDate?: Date;\n logLevel?: LogLevel;\n filters?: Record<string, any>;\n returnPaginationResults?: boolean;\n page?: number;\n perPage?: number;\n }): Promise<{\n logs: BaseLogMessage[];\n total: number;\n page: number;\n perPage: number;\n hasMore: boolean;\n }> {\n return Promise.resolve({\n logs: [],\n total: 0,\n page: _args?.page ?? 1,\n perPage: _args?.perPage ?? 100,\n hasMore: false,\n });\n }\n}\n\nexport const transport = new RedisTransport();\n\nexport const closeLogger = async () => {\n if (redisClient.isOpen) {\n setTimeout(async () => {\n await redisClient.quit();\n }, 10);\n }\n};\n\nexport const logger = new PinoLogger({\n level: 'info',\n transports: {\n redis: transport,\n },\n});\n","import { createRequire } from 'node:module';\nimport { Writable } from 'node:stream';\nimport { execa } from 'execa';\nimport { PROJECT_ENV_VARS, PROJECT_ROOT } from './constants.js';\nimport { logger } from './logger.js';\n\nexport const createPinoStream = () => {\n return new Writable({\n write(chunk, _encoding, callback) {\n // Convert Buffer/string to string and trim whitespace\n const line = chunk.toString().trim();\n\n if (line) {\n // Log each line through Pino\n logger.info(line);\n }\n\n callback();\n },\n });\n};\n\nexport async function runWithExeca({\n cmd,\n args,\n cwd = process.cwd(),\n env = PROJECT_ENV_VARS,\n}: {\n cmd: string;\n args: string[];\n cwd?: string;\n env?: Record<string, string>;\n}): Promise<{ stdout?: string; stderr?: string; success: boolean; error?: Error }> {\n const pinoStream = createPinoStream();\n\n try {\n const subprocess = execa(cmd, args, {\n cwd,\n stdin: 'ignore',\n env: {\n ...process.env,\n ...env,\n },\n });\n\n // Pipe stdout and stderr through the logging stream.\n // { end: false } prevents the first stream to close from ending pinoStream\n // while the other may still be writing.\n subprocess.stdout?.pipe(pinoStream, { end: false });\n subprocess.stderr?.pipe(pinoStream, { end: false });\n\n const { stdout, stderr, exitCode } = await subprocess;\n pinoStream.end();\n return { stdout, stderr, success: exitCode === 0 };\n } catch (error) {\n pinoStream.end();\n logger.error('Process failed', { error });\n return { success: false, error: error instanceof Error ? error : new Error(String(error)) };\n }\n}\n\nexport function runWithChildProcess(cmd: string, args: string[]): { stdout?: string; stderr?: string } {\n const pinoStream = createPinoStream();\n\n try {\n const __require = typeof require === 'function' ? require : createRequire(import.meta.url);\n const { stdout, stderr } = __require('node:child_process').spawnSync(cmd, args, {\n cwd: PROJECT_ROOT,\n encoding: 'utf8',\n shell: true,\n env: {\n ...process.env,\n ...PROJECT_ENV_VARS,\n },\n maxBuffer: 1024 * 1024 * 10, // 10MB buffer\n });\n\n if (stdout) {\n pinoStream.write(stdout);\n }\n if (stderr) {\n pinoStream.write(stderr);\n }\n\n pinoStream.end();\n return { stdout, stderr };\n } catch (error) {\n logger.error('Process failed' + error);\n pinoStream.end();\n return {};\n }\n}\n","import * as fs from 'node:fs';\nimport { join, resolve } from 'node:path';\n\nimport { MastraError } from '@mastra/core/error';\nimport { runWithExeca } from './execa.js';\nimport { logger } from './logger.js';\n\nconst MEMOIZED = new Map();\n\nfunction findLockFile(dir: string): string | null {\n const lockFiles = ['pnpm-lock.yaml', 'package-lock.json', 'yarn.lock', 'bun.lock'];\n for (const file of lockFiles) {\n if (fs.existsSync(join(dir, file))) {\n return file;\n }\n }\n const parentDir = resolve(dir, '..');\n if (parentDir !== dir) {\n return findLockFile(parentDir);\n }\n return null;\n}\n\nexport function detectPm({ path }: { path: string }): string {\n const cached = MEMOIZED.get(path);\n if (cached) {\n return cached;\n }\n\n const lockFile = findLockFile(path);\n let pm: string = 'npm';\n switch (lockFile) {\n case 'pnpm-lock.yaml':\n pm = 'pnpm';\n break;\n case 'package-lock.json':\n pm = 'npm';\n break;\n case 'yarn.lock':\n pm = 'yarn';\n break;\n case 'bun.lock':\n pm = 'bun';\n break;\n default:\n pm = 'npm';\n }\n\n MEMOIZED.set(path, pm);\n return pm;\n}\n\nexport async function installNodeVersion({ path }: { path: string }) {\n let nvmrcExists = false;\n let nodeVersionExists = false;\n\n try {\n fs.accessSync(join(path, '.nvmrc'));\n nvmrcExists = true;\n } catch {\n // File does not exist\n }\n\n try {\n fs.accessSync(join(path, '.node-version'));\n nodeVersionExists = true;\n } catch {\n // File does not exist\n }\n\n if (nvmrcExists || nodeVersionExists) {\n logger.info('Node version file found, installing specified Node.js version...');\n const { success, error } = await runWithExeca({\n cmd: 'n',\n args: ['auto'],\n cwd: path,\n });\n if (!success) {\n throw new MastraError(\n {\n id: 'NODE_FAIL_INSTALL_SPECIFIED_VERSION',\n category: 'USER',\n domain: 'DEPLOYER',\n },\n error,\n );\n }\n }\n}\n\nexport async function installDeps({ path, pm }: { path: string; pm?: string }) {\n pm = pm ?? detectPm({ path });\n logger.info('Installing dependencies', { pm, path });\n // --force is needed to install peer deps for external packages in the mastra output directory\n // --legacy-peer-deps=false is needed to override other overrides by the repo package manager such as pnpm. Pnpm would set it to true\n const args = ['install', '--legacy-peer-deps=false', '--force'];\n const { success, error } = await runWithExeca({ cmd: pm, args, cwd: path });\n if (!success) {\n throw new MastraError(\n {\n id: 'FAIL_INSTALL_DEPS',\n category: 'USER',\n domain: 'DEPLOYER',\n },\n error,\n );\n }\n}\n\nexport async function runInstallCommand({ path, installCommand }: { path: string; installCommand: string }) {\n logger.info('Running install command', { command: installCommand, path });\n const { success, error } = await runWithExeca({ cmd: 'sh', args: ['-c', installCommand], cwd: path });\n if (!success) {\n throw new MastraError(\n {\n id: 'FAIL_CUSTOM_INSTALL_COMMAND',\n category: 'USER',\n domain: 'DEPLOYER',\n },\n error,\n );\n }\n}\n\nexport async function runScript({ scriptName, path, args }: { scriptName: string; path: string; args?: string[] }) {\n const pm = detectPm({ path });\n logger.info('Running script', { script: scriptName, pm });\n const { success, error } = await runWithExeca({\n cmd: pm,\n args: pm === 'npm' ? ['run', scriptName, ...(args ?? [])] : [scriptName, ...(args ?? [])],\n cwd: path,\n });\n if (!success) {\n throw new MastraError(\n {\n id: 'FAIL_BUILD_SCRIPT',\n category: 'USER',\n domain: 'DEPLOYER',\n },\n error,\n );\n }\n}\n\nexport async function runBuildCommand({ command, path }: { command: string; path: string }) {\n logger.info('Running build command', { command });\n const { success, error } = await runWithExeca({ cmd: 'sh', args: ['-c', command], cwd: path });\n if (!success) {\n throw new MastraError(\n {\n id: 'FAIL_BUILD_COMMAND',\n category: 'USER',\n domain: 'DEPLOYER',\n },\n error,\n );\n }\n}\n","import { join } from 'node:path';\nimport { MastraError } from '@mastra/core/error';\nimport { FileService } from '@mastra/deployer';\n\nimport { MASTRA_DIRECTORY } from './constants.js';\n\nexport function getMastraEntryFile(mastraDir: string) {\n try {\n const fileService = new FileService();\n return fileService.getFirstExistingFile([\n join(mastraDir, MASTRA_DIRECTORY, 'index.ts'),\n join(mastraDir, MASTRA_DIRECTORY, 'index.js'),\n ]);\n } catch (error) {\n throw new MastraError(\n {\n id: 'MASTRA_ENTRY_FILE_NOT_FOUND',\n category: 'USER',\n domain: 'DEPLOYER',\n },\n error,\n );\n }\n}\n","import { PROJECT_ID, BUILD_ID, BUILD_URL, USER_IP_ADDRESS } from './constants.js';\n\nexport function successEntrypoint() {\n return `\n if (process.env.CI !== 'true') {\n await fetch('${process.env.REPORTER_API_URL}', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: 'Bearer ${process.env.REPORTER_API_URL_AUTH_TOKEN}',\n },\n body: JSON.stringify(${JSON.stringify({\n projectId: PROJECT_ID,\n buildId: BUILD_ID,\n status: 'success',\n url: BUILD_URL,\n userIpAddress: USER_IP_ADDRESS,\n })}),\n }).catch(err => {\n console.error('Failed to report build status to monitoring service', {\n error: err,\n });\n })\n }\n `;\n}\n","import { join, dirname } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { Config } from '@mastra/core/mastra';\nimport { Deployer } from '@mastra/deployer';\nimport { copy, readJSON } from 'fs-extra/esm';\n\nimport { getAuthEntrypoint } from './utils/auth.js';\nimport { MASTRA_DIRECTORY, BUILD_ID, PROJECT_ID, TEAM_ID } from './utils/constants.js';\nimport { installDeps } from './utils/deps.js';\nimport { getMastraEntryFile } from './utils/file.js';\nimport { successEntrypoint } from './utils/report.js';\n\nexport class CloudDeployer extends Deployer {\n private studio: boolean;\n\n constructor({ studio }: { studio?: boolean } = {}) {\n super({ name: 'cloud' });\n this.studio = studio ?? false;\n }\n\n protected async getUserBundlerOptions(\n mastraEntryFile: string,\n outputDirectory: string,\n ): Promise<NonNullable<Config['bundler']>> {\n const bundlerOptions = await super.getUserBundlerOptions(mastraEntryFile, outputDirectory);\n\n // Always force externals: true for cloud deployments.\n // The cloud deployer installs all dependencies from npm into node_modules,\n // so bundling them inline serves no purpose. Bundling inline can also cause\n // circular module evaluation deadlocks when dynamic imports (e.g. in\n // MemoryLibSQL.init()) reference chunks that depend back on the entry module,\n // resulting in \"Detected unsettled top-level await\" warnings.\n return {\n ...bundlerOptions,\n externals: true,\n };\n }\n\n async deploy(_outputDirectory: string): Promise<void> {}\n\n async prepare(outputDirectory: string): Promise<void> {\n await super.prepare(outputDirectory);\n\n if (this.studio) {\n const __filename = fileURLToPath(import.meta.url);\n const __dirname = dirname(__filename);\n\n const studioServePath = join(outputDirectory, this.outputDir, 'studio');\n await copy(join(dirname(__dirname), join('dist', 'studio')), studioServePath, {\n overwrite: true,\n });\n }\n }\n async writePackageJson(outputDirectory: string, dependencies: Map<string, string>) {\n const versions = (await readJSON(join(dirname(fileURLToPath(import.meta.url)), '../versions.json'))) as\n | Record<string, string>\n | undefined;\n for (const [pkgName, version] of Object.entries(versions || {})) {\n dependencies.set(pkgName, version);\n }\n\n return super.writePackageJson(outputDirectory, dependencies);\n }\n\n async lint() {}\n\n protected async installDependencies(outputDirectory: string, _rootDir = process.cwd()) {\n await installDeps({ path: join(outputDirectory, 'output'), pm: 'npm' });\n }\n\n async bundle(mastraDir: string, outputDirectory: string): Promise<void> {\n const currentCwd = process.cwd();\n process.chdir(mastraDir);\n\n const mastraEntryFile = getMastraEntryFile(mastraDir);\n\n const mastraAppDir = join(mastraDir, MASTRA_DIRECTORY);\n\n // Use the getAllToolPaths method to prepare tools paths\n const discoveredTools = this.getAllToolPaths(mastraAppDir);\n\n await this.prepare(outputDirectory);\n await this._bundle(\n this.getEntry(),\n mastraEntryFile,\n {\n outputDirectory,\n projectRoot: mastraDir,\n },\n discoveredTools,\n );\n process.chdir(currentCwd);\n }\n\n getAuthEntrypoint() {\n return getAuthEntrypoint();\n }\n\n private getEntry(): string {\n return `\nimport { createNodeServer, getToolExports } from '#server';\nimport { tools } from '#tools';\nimport { mastra } from '#mastra';\nimport { MultiLogger } from '@mastra/core/logger';\nimport { PinoLogger } from '@mastra/loggers';\nimport { HttpTransport } from '@mastra/loggers/http';\nimport { LibSQLStore, LibSQLVector } from '@mastra/libsql';\nimport { scoreTracesWorkflow } from '@mastra/core/evals/scoreTraces';\n\nconst startTime = process.env.RUNNER_START_TIME ? new Date(process.env.RUNNER_START_TIME).getTime() : Date.now();\nconst createNodeServerStartTime = Date.now();\n\nconsole.log(JSON.stringify({\n message: \"Server starting\",\n operation: 'builder.createNodeServer',\n operation_startTime: createNodeServerStartTime,\n type: \"READINESS\",\n startTime,\n metadata: {\n teamId: \"${TEAM_ID}\",\n projectId: \"${PROJECT_ID}\",\n buildId: \"${BUILD_ID}\",\n },\n}));\n\nconst transports = {}\nif (process.env.CI !== 'true') {\n if (process.env.BUSINESS_API_RUNNER_LOGS_ENDPOINT) {\n transports.default = new HttpTransport({\n url: process.env.BUSINESS_API_RUNNER_LOGS_ENDPOINT,\n headers: {\n Authorization: 'Bearer ' + process.env.BUSINESS_JWT_TOKEN,\n },\n });\n }\n}\n\nconst logger = new PinoLogger({\n name: 'MastraCloud',\n transports,\n level: 'debug',\n});\nconst existingLogger = mastra?.getLogger();\nconst combinedLogger = existingLogger ? new MultiLogger([logger, existingLogger]) : logger;\n\nmastra.setLogger({ logger: combinedLogger });\n\nif (process.env.MASTRA_STORAGE_URL && process.env.MASTRA_STORAGE_AUTH_TOKEN) {\n const { MastraStorage } = await import('@mastra/core/storage');\n logger.info('Using Mastra Cloud Storage: ' + process.env.MASTRA_STORAGE_URL)\n const storage = new LibSQLStore({\n id: 'mastra-cloud-storage-libsql',\n url: process.env.MASTRA_STORAGE_URL,\n authToken: process.env.MASTRA_STORAGE_AUTH_TOKEN,\n })\n const vector = new LibSQLVector({\n id: 'mastra-cloud-storage-libsql-vector',\n url: process.env.MASTRA_STORAGE_URL,\n authToken: process.env.MASTRA_STORAGE_AUTH_TOKEN,\n })\n\n await storage.init()\n mastra?.setStorage(storage)\n} else {\n const userStorage = mastra?.getStorage();\n if (userStorage && !userStorage.disableInit) {\n userStorage.init();\n }\n}\n\nif (mastra?.getStorage()) {\n mastra.__registerInternalWorkflow(scoreTracesWorkflow);\n}\n\n${getAuthEntrypoint()}\n\nawait createNodeServer(mastra, { studio: ${this.studio}, swaggerUI: false, tools: getToolExports(tools) });\n\n${successEntrypoint()}\n\nconsole.log(JSON.stringify({\n message: \"Server started\",\n operation: 'builder.createNodeServer',\n operation_startTime: createNodeServerStartTime,\n operation_durationMs: Date.now() - createNodeServerStartTime,\n type: \"READINESS\",\n startTime,\n metadata: {\n teamId: \"${TEAM_ID}\",\n projectId: \"${PROJECT_ID}\",\n buildId: \"${BUILD_ID}\",\n },\n}));\n\n\nconsole.log(JSON.stringify({\n message: \"Runner Initialized\",\n type: \"READINESS\",\n startTime,\n durationMs: Date.now() - startTime,\n metadata: {\n teamId: \"${TEAM_ID}\",\n projectId: \"${PROJECT_ID}\",\n buildId: \"${BUILD_ID}\",\n },\n}));\n`;\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAAA,SAAgB,oBAAoB;CAClC,MAAM,eAA6D,CAAC;CAEpE,IAAI,QAAQ,IAAI,sBACd,aAAa,QAAQ,IAAI,wBAAwB;EAAE,IAAI;EAAgB,MAAM;CAAM;CAErF,IAAI,QAAQ,IAAI,oBACd,aAAa,QAAQ,IAAI,sBAAsB;EAAE,IAAI;EAAgB,MAAM;CAAM;CAGnF,OAAO;;;;;;;;kBAQS,KAAK,UAAU,YAAY,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6D/C;;AC7EA,MAAa,QAAQ,QAAQ,IAAI,UAAU;AAC3C,MAAa,UAAkB,QAAQ,IAAI,WAAW;AACtD,MAAa,aAAqB,QAAQ,IAAI,cAAc;AAC5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