create-mastra 0.0.0-agui-20250501191909 → 0.0.0-cli-debug-2-20250611100354
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/README.md +0 -1
- package/dist/index.js +548 -185
- package/dist/index.js.map +1 -1
- package/dist/templates/dev.entry.js +0 -5
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { randomUUID } from 'node:crypto';
|
|
|
4
4
|
import * as fs3__default from 'node:fs';
|
|
5
5
|
import fs3__default__default, { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
6
6
|
import os from 'node:os';
|
|
7
|
-
import
|
|
7
|
+
import path2, { dirname } from 'node:path';
|
|
8
8
|
import { fileURLToPath } from 'node:url';
|
|
9
9
|
import { PostHog } from 'posthog-node';
|
|
10
10
|
import h, { stdin, stdout } from 'node:process';
|
|
@@ -17,13 +17,12 @@ import fs4 from 'node:fs/promises';
|
|
|
17
17
|
import { execa } from 'execa';
|
|
18
18
|
import fsExtra3, { readJSON, ensureFile, writeJSON } from 'fs-extra/esm';
|
|
19
19
|
import prettier from 'prettier';
|
|
20
|
-
import { Transform } from 'node:stream';
|
|
21
20
|
import pino from 'pino';
|
|
22
21
|
import pretty from 'pino-pretty';
|
|
23
22
|
import fsExtra from 'fs-extra';
|
|
24
23
|
|
|
25
24
|
var __filename = fileURLToPath(import.meta.url);
|
|
26
|
-
var __dirname =
|
|
25
|
+
var __dirname = path2.dirname(__filename);
|
|
27
26
|
var PosthogAnalytics = class {
|
|
28
27
|
sessionId;
|
|
29
28
|
client;
|
|
@@ -35,7 +34,7 @@ var PosthogAnalytics = class {
|
|
|
35
34
|
host = "https://app.posthog.com"
|
|
36
35
|
}) {
|
|
37
36
|
this.version = version;
|
|
38
|
-
const cliConfigPath =
|
|
37
|
+
const cliConfigPath = path2.join(__dirname, "mastra-cli.json");
|
|
39
38
|
if (existsSync(cliConfigPath)) {
|
|
40
39
|
try {
|
|
41
40
|
const { distinctId, sessionId } = JSON.parse(readFileSync(cliConfigPath, "utf-8"));
|
|
@@ -63,7 +62,7 @@ var PosthogAnalytics = class {
|
|
|
63
62
|
}
|
|
64
63
|
writeCliConfig({ distinctId, sessionId }) {
|
|
65
64
|
try {
|
|
66
|
-
writeFileSync(
|
|
65
|
+
writeFileSync(path2.join(__dirname, "mastra-cli.json"), JSON.stringify({ distinctId, sessionId }));
|
|
67
66
|
} catch {
|
|
68
67
|
}
|
|
69
68
|
}
|
|
@@ -416,6 +415,283 @@ ${color2.gray($)} ${s}
|
|
|
416
415
|
`);let m=0,w=0;p(),i=setInterval(()=>{const L=color2.magenta(s[m]),O=".".repeat(Math.floor(w)).slice(0,3);process.stdout.write(srcExports.cursor.move(-999,0)),process.stdout.write(srcExports.erase.down(1)),process.stdout.write(`${L} ${o}${O}`),m=m+1<s.length?m+1:0,w=w<s.length?w+.125:0;},n);},x=(g="",m=0)=>{o=g??o,r=false,clearInterval(i);const w=m===0?color2.green(M):m===1?color2.red(P):color2.red(V);process.stdout.write(srcExports.cursor.move(-999,0)),process.stdout.write(srcExports.erase.down(1)),process.stdout.write(`${w} ${o}
|
|
417
416
|
`),S(),t();};return {start:f,stop:x,message:(g="")=>{o=g??o;}}};function ye(){const s=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");return new RegExp(s,"g")}const ve=async(s,n)=>{const t={},i=Object.keys(s);for(const r of i){const o=s[r],c=await o({results:t})?.catch(l=>{throw l});if(typeof n?.onCancel=="function"&&lD(c)){t[r]="canceled",n.onCancel({results:t});continue}t[r]=c;}return t};
|
|
418
417
|
|
|
418
|
+
var shellQuote$1 = {};
|
|
419
|
+
|
|
420
|
+
var quote;
|
|
421
|
+
var hasRequiredQuote;
|
|
422
|
+
|
|
423
|
+
function requireQuote () {
|
|
424
|
+
if (hasRequiredQuote) return quote;
|
|
425
|
+
hasRequiredQuote = 1;
|
|
426
|
+
|
|
427
|
+
quote = function quote(xs) {
|
|
428
|
+
return xs.map(function (s) {
|
|
429
|
+
if (s === '') {
|
|
430
|
+
return '\'\'';
|
|
431
|
+
}
|
|
432
|
+
if (s && typeof s === 'object') {
|
|
433
|
+
return s.op.replace(/(.)/g, '\\$1');
|
|
434
|
+
}
|
|
435
|
+
if ((/["\s]/).test(s) && !(/'/).test(s)) {
|
|
436
|
+
return "'" + s.replace(/(['\\])/g, '\\$1') + "'";
|
|
437
|
+
}
|
|
438
|
+
if ((/["'\s]/).test(s)) {
|
|
439
|
+
return '"' + s.replace(/(["\\$`!])/g, '\\$1') + '"';
|
|
440
|
+
}
|
|
441
|
+
return String(s).replace(/([A-Za-z]:)?([#!"$&'()*,:;<=>?@[\\\]^`{|}])/g, '$1\\$2');
|
|
442
|
+
}).join(' ');
|
|
443
|
+
};
|
|
444
|
+
return quote;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
var parse;
|
|
448
|
+
var hasRequiredParse;
|
|
449
|
+
|
|
450
|
+
function requireParse () {
|
|
451
|
+
if (hasRequiredParse) return parse;
|
|
452
|
+
hasRequiredParse = 1;
|
|
453
|
+
|
|
454
|
+
// '<(' is process substitution operator and
|
|
455
|
+
// can be parsed the same as control operator
|
|
456
|
+
var CONTROL = '(?:' + [
|
|
457
|
+
'\\|\\|',
|
|
458
|
+
'\\&\\&',
|
|
459
|
+
';;',
|
|
460
|
+
'\\|\\&',
|
|
461
|
+
'\\<\\(',
|
|
462
|
+
'\\<\\<\\<',
|
|
463
|
+
'>>',
|
|
464
|
+
'>\\&',
|
|
465
|
+
'<\\&',
|
|
466
|
+
'[&;()|<>]'
|
|
467
|
+
].join('|') + ')';
|
|
468
|
+
var controlRE = new RegExp('^' + CONTROL + '$');
|
|
469
|
+
var META = '|&;()<> \\t';
|
|
470
|
+
var SINGLE_QUOTE = '"((\\\\"|[^"])*?)"';
|
|
471
|
+
var DOUBLE_QUOTE = '\'((\\\\\'|[^\'])*?)\'';
|
|
472
|
+
var hash = /^#$/;
|
|
473
|
+
|
|
474
|
+
var SQ = "'";
|
|
475
|
+
var DQ = '"';
|
|
476
|
+
var DS = '$';
|
|
477
|
+
|
|
478
|
+
var TOKEN = '';
|
|
479
|
+
var mult = 0x100000000; // Math.pow(16, 8);
|
|
480
|
+
for (var i = 0; i < 4; i++) {
|
|
481
|
+
TOKEN += (mult * Math.random()).toString(16);
|
|
482
|
+
}
|
|
483
|
+
var startsWithToken = new RegExp('^' + TOKEN);
|
|
484
|
+
|
|
485
|
+
function matchAll(s, r) {
|
|
486
|
+
var origIndex = r.lastIndex;
|
|
487
|
+
|
|
488
|
+
var matches = [];
|
|
489
|
+
var matchObj;
|
|
490
|
+
|
|
491
|
+
while ((matchObj = r.exec(s))) {
|
|
492
|
+
matches.push(matchObj);
|
|
493
|
+
if (r.lastIndex === matchObj.index) {
|
|
494
|
+
r.lastIndex += 1;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
r.lastIndex = origIndex;
|
|
499
|
+
|
|
500
|
+
return matches;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
function getVar(env, pre, key) {
|
|
504
|
+
var r = typeof env === 'function' ? env(key) : env[key];
|
|
505
|
+
if (typeof r === 'undefined' && key != '') {
|
|
506
|
+
r = '';
|
|
507
|
+
} else if (typeof r === 'undefined') {
|
|
508
|
+
r = '$';
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
if (typeof r === 'object') {
|
|
512
|
+
return pre + TOKEN + JSON.stringify(r) + TOKEN;
|
|
513
|
+
}
|
|
514
|
+
return pre + r;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
function parseInternal(string, env, opts) {
|
|
518
|
+
if (!opts) {
|
|
519
|
+
opts = {};
|
|
520
|
+
}
|
|
521
|
+
var BS = opts.escape || '\\';
|
|
522
|
+
var BAREWORD = '(\\' + BS + '[\'"' + META + ']|[^\\s\'"' + META + '])+';
|
|
523
|
+
|
|
524
|
+
var chunker = new RegExp([
|
|
525
|
+
'(' + CONTROL + ')', // control chars
|
|
526
|
+
'(' + BAREWORD + '|' + SINGLE_QUOTE + '|' + DOUBLE_QUOTE + ')+'
|
|
527
|
+
].join('|'), 'g');
|
|
528
|
+
|
|
529
|
+
var matches = matchAll(string, chunker);
|
|
530
|
+
|
|
531
|
+
if (matches.length === 0) {
|
|
532
|
+
return [];
|
|
533
|
+
}
|
|
534
|
+
if (!env) {
|
|
535
|
+
env = {};
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
var commented = false;
|
|
539
|
+
|
|
540
|
+
return matches.map(function (match) {
|
|
541
|
+
var s = match[0];
|
|
542
|
+
if (!s || commented) {
|
|
543
|
+
return void undefined;
|
|
544
|
+
}
|
|
545
|
+
if (controlRE.test(s)) {
|
|
546
|
+
return { op: s };
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
// Hand-written scanner/parser for Bash quoting rules:
|
|
550
|
+
//
|
|
551
|
+
// 1. inside single quotes, all characters are printed literally.
|
|
552
|
+
// 2. inside double quotes, all characters are printed literally
|
|
553
|
+
// except variables prefixed by '$' and backslashes followed by
|
|
554
|
+
// either a double quote or another backslash.
|
|
555
|
+
// 3. outside of any quotes, backslashes are treated as escape
|
|
556
|
+
// characters and not printed (unless they are themselves escaped)
|
|
557
|
+
// 4. quote context can switch mid-token if there is no whitespace
|
|
558
|
+
// between the two quote contexts (e.g. all'one'"token" parses as
|
|
559
|
+
// "allonetoken")
|
|
560
|
+
var quote = false;
|
|
561
|
+
var esc = false;
|
|
562
|
+
var out = '';
|
|
563
|
+
var isGlob = false;
|
|
564
|
+
var i;
|
|
565
|
+
|
|
566
|
+
function parseEnvVar() {
|
|
567
|
+
i += 1;
|
|
568
|
+
var varend;
|
|
569
|
+
var varname;
|
|
570
|
+
var char = s.charAt(i);
|
|
571
|
+
|
|
572
|
+
if (char === '{') {
|
|
573
|
+
i += 1;
|
|
574
|
+
if (s.charAt(i) === '}') {
|
|
575
|
+
throw new Error('Bad substitution: ' + s.slice(i - 2, i + 1));
|
|
576
|
+
}
|
|
577
|
+
varend = s.indexOf('}', i);
|
|
578
|
+
if (varend < 0) {
|
|
579
|
+
throw new Error('Bad substitution: ' + s.slice(i));
|
|
580
|
+
}
|
|
581
|
+
varname = s.slice(i, varend);
|
|
582
|
+
i = varend;
|
|
583
|
+
} else if ((/[*@#?$!_-]/).test(char)) {
|
|
584
|
+
varname = char;
|
|
585
|
+
i += 1;
|
|
586
|
+
} else {
|
|
587
|
+
var slicedFromI = s.slice(i);
|
|
588
|
+
varend = slicedFromI.match(/[^\w\d_]/);
|
|
589
|
+
if (!varend) {
|
|
590
|
+
varname = slicedFromI;
|
|
591
|
+
i = s.length;
|
|
592
|
+
} else {
|
|
593
|
+
varname = slicedFromI.slice(0, varend.index);
|
|
594
|
+
i += varend.index - 1;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
return getVar(env, '', varname);
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
for (i = 0; i < s.length; i++) {
|
|
601
|
+
var c = s.charAt(i);
|
|
602
|
+
isGlob = isGlob || (!quote && (c === '*' || c === '?'));
|
|
603
|
+
if (esc) {
|
|
604
|
+
out += c;
|
|
605
|
+
esc = false;
|
|
606
|
+
} else if (quote) {
|
|
607
|
+
if (c === quote) {
|
|
608
|
+
quote = false;
|
|
609
|
+
} else if (quote == SQ) {
|
|
610
|
+
out += c;
|
|
611
|
+
} else { // Double quote
|
|
612
|
+
if (c === BS) {
|
|
613
|
+
i += 1;
|
|
614
|
+
c = s.charAt(i);
|
|
615
|
+
if (c === DQ || c === BS || c === DS) {
|
|
616
|
+
out += c;
|
|
617
|
+
} else {
|
|
618
|
+
out += BS + c;
|
|
619
|
+
}
|
|
620
|
+
} else if (c === DS) {
|
|
621
|
+
out += parseEnvVar();
|
|
622
|
+
} else {
|
|
623
|
+
out += c;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
} else if (c === DQ || c === SQ) {
|
|
627
|
+
quote = c;
|
|
628
|
+
} else if (controlRE.test(c)) {
|
|
629
|
+
return { op: s };
|
|
630
|
+
} else if (hash.test(c)) {
|
|
631
|
+
commented = true;
|
|
632
|
+
var commentObj = { comment: string.slice(match.index + i + 1) };
|
|
633
|
+
if (out.length) {
|
|
634
|
+
return [out, commentObj];
|
|
635
|
+
}
|
|
636
|
+
return [commentObj];
|
|
637
|
+
} else if (c === BS) {
|
|
638
|
+
esc = true;
|
|
639
|
+
} else if (c === DS) {
|
|
640
|
+
out += parseEnvVar();
|
|
641
|
+
} else {
|
|
642
|
+
out += c;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
if (isGlob) {
|
|
647
|
+
return { op: 'glob', pattern: out };
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
return out;
|
|
651
|
+
}).reduce(function (prev, arg) { // finalize parsed arguments
|
|
652
|
+
// TODO: replace this whole reduce with a concat
|
|
653
|
+
return typeof arg === 'undefined' ? prev : prev.concat(arg);
|
|
654
|
+
}, []);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
parse = function parse(s, env, opts) {
|
|
658
|
+
var mapped = parseInternal(s, env, opts);
|
|
659
|
+
if (typeof env !== 'function') {
|
|
660
|
+
return mapped;
|
|
661
|
+
}
|
|
662
|
+
return mapped.reduce(function (acc, s) {
|
|
663
|
+
if (typeof s === 'object') {
|
|
664
|
+
return acc.concat(s);
|
|
665
|
+
}
|
|
666
|
+
var xs = s.split(RegExp('(' + TOKEN + '.*?' + TOKEN + ')', 'g'));
|
|
667
|
+
if (xs.length === 1) {
|
|
668
|
+
return acc.concat(xs[0]);
|
|
669
|
+
}
|
|
670
|
+
return acc.concat(xs.filter(Boolean).map(function (x) {
|
|
671
|
+
if (startsWithToken.test(x)) {
|
|
672
|
+
return JSON.parse(x.split(TOKEN)[1]);
|
|
673
|
+
}
|
|
674
|
+
return x;
|
|
675
|
+
}));
|
|
676
|
+
}, []);
|
|
677
|
+
};
|
|
678
|
+
return parse;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
var hasRequiredShellQuote;
|
|
682
|
+
|
|
683
|
+
function requireShellQuote () {
|
|
684
|
+
if (hasRequiredShellQuote) return shellQuote$1;
|
|
685
|
+
hasRequiredShellQuote = 1;
|
|
686
|
+
|
|
687
|
+
shellQuote$1.quote = requireQuote();
|
|
688
|
+
shellQuote$1.parse = requireParse();
|
|
689
|
+
return shellQuote$1;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
var shellQuoteExports = requireShellQuote();
|
|
693
|
+
var shellQuote = /*@__PURE__*/getDefaultExportFromCjs(shellQuoteExports);
|
|
694
|
+
|
|
419
695
|
// eslint-disable-next-line no-warning-comments
|
|
420
696
|
// TODO: Use a better method when it's added to Node.js (https://github.com/nodejs/node/pull/40240)
|
|
421
697
|
// Lots of optionals here to support Deno.
|
|
@@ -789,46 +1065,88 @@ function yoctoSpinner(options) {
|
|
|
789
1065
|
}
|
|
790
1066
|
|
|
791
1067
|
var LogLevel = {
|
|
792
|
-
INFO: "info"
|
|
793
|
-
|
|
794
|
-
|
|
1068
|
+
INFO: "info",
|
|
1069
|
+
ERROR: "error"};
|
|
1070
|
+
var MastraLogger = class {
|
|
1071
|
+
name;
|
|
1072
|
+
level;
|
|
795
1073
|
transports;
|
|
796
1074
|
constructor(options = {}) {
|
|
797
|
-
this.
|
|
798
|
-
|
|
1075
|
+
this.name = options.name || "Mastra";
|
|
1076
|
+
this.level = options.level || LogLevel.ERROR;
|
|
1077
|
+
this.transports = new Map(Object.entries(options.transports || {}));
|
|
1078
|
+
}
|
|
1079
|
+
getTransports() {
|
|
1080
|
+
return this.transports;
|
|
1081
|
+
}
|
|
1082
|
+
trackException(_error) {
|
|
1083
|
+
}
|
|
1084
|
+
async getLogs(transportId, params) {
|
|
1085
|
+
if (!transportId || !this.transports.has(transportId)) {
|
|
1086
|
+
return { logs: [], total: 0, page: params?.page ?? 1, perPage: params?.perPage ?? 100, hasMore: false };
|
|
1087
|
+
}
|
|
1088
|
+
return this.transports.get(transportId).getLogs(params) ?? {
|
|
1089
|
+
logs: [],
|
|
1090
|
+
total: 0,
|
|
1091
|
+
page: params?.page ?? 1,
|
|
1092
|
+
perPage: params?.perPage ?? 100,
|
|
1093
|
+
hasMore: false
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
async getLogsByRunId({
|
|
1097
|
+
transportId,
|
|
1098
|
+
runId,
|
|
1099
|
+
fromDate,
|
|
1100
|
+
toDate,
|
|
1101
|
+
logLevel,
|
|
1102
|
+
filters,
|
|
1103
|
+
page,
|
|
1104
|
+
perPage
|
|
1105
|
+
}) {
|
|
1106
|
+
if (!transportId || !this.transports.has(transportId) || !runId) {
|
|
1107
|
+
return { logs: [], total: 0, page: page ?? 1, perPage: perPage ?? 100, hasMore: false };
|
|
1108
|
+
}
|
|
1109
|
+
return this.transports.get(transportId).getLogsByRunId({ runId, fromDate, toDate, logLevel, filters, page, perPage }) ?? {
|
|
1110
|
+
logs: [],
|
|
1111
|
+
total: 0,
|
|
1112
|
+
page: page ?? 1,
|
|
1113
|
+
perPage: perPage ?? 100,
|
|
1114
|
+
hasMore: false
|
|
1115
|
+
};
|
|
1116
|
+
}
|
|
1117
|
+
};
|
|
1118
|
+
|
|
1119
|
+
var PinoLogger = class extends MastraLogger {
|
|
1120
|
+
logger;
|
|
1121
|
+
constructor(options = {}) {
|
|
1122
|
+
super(options);
|
|
1123
|
+
let prettyStream = void 0;
|
|
1124
|
+
if (!options.overrideDefaultTransports) {
|
|
1125
|
+
prettyStream = pretty({
|
|
1126
|
+
colorize: true,
|
|
1127
|
+
levelFirst: true,
|
|
1128
|
+
ignore: "pid,hostname",
|
|
1129
|
+
colorizeObjects: true,
|
|
1130
|
+
translateTime: "SYS:standard",
|
|
1131
|
+
singleLine: false
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
const transportsAry = [...this.getTransports().entries()];
|
|
799
1135
|
this.logger = pino(
|
|
800
1136
|
{
|
|
801
1137
|
name: options.name || "app",
|
|
802
1138
|
level: options.level || LogLevel.INFO,
|
|
803
1139
|
formatters: {
|
|
804
|
-
level: (label) => {
|
|
805
|
-
return {
|
|
806
|
-
level: label
|
|
807
|
-
};
|
|
808
|
-
}
|
|
1140
|
+
level: (label) => ({ level: label })
|
|
809
1141
|
}
|
|
810
1142
|
},
|
|
811
|
-
options.overrideDefaultTransports ? options?.transports?.default : transportsAry.length === 0 ?
|
|
812
|
-
colorize: true,
|
|
813
|
-
levelFirst: true,
|
|
814
|
-
ignore: "pid,hostname",
|
|
815
|
-
colorizeObjects: true,
|
|
816
|
-
translateTime: "SYS:standard",
|
|
817
|
-
singleLine: false
|
|
818
|
-
}) : pino.multistream([
|
|
1143
|
+
options.overrideDefaultTransports ? options?.transports?.default : transportsAry.length === 0 ? prettyStream : pino.multistream([
|
|
819
1144
|
...transportsAry.map(([, transport]) => ({
|
|
820
1145
|
stream: transport,
|
|
821
1146
|
level: options.level || LogLevel.INFO
|
|
822
1147
|
})),
|
|
823
1148
|
{
|
|
824
|
-
stream:
|
|
825
|
-
colorize: true,
|
|
826
|
-
levelFirst: true,
|
|
827
|
-
ignore: "pid,hostname",
|
|
828
|
-
colorizeObjects: true,
|
|
829
|
-
translateTime: "SYS:standard",
|
|
830
|
-
singleLine: false
|
|
831
|
-
}),
|
|
1149
|
+
stream: prettyStream,
|
|
832
1150
|
level: options.level || LogLevel.INFO
|
|
833
1151
|
}
|
|
834
1152
|
])
|
|
@@ -846,31 +1164,7 @@ var Logger = class {
|
|
|
846
1164
|
error(message, args = {}) {
|
|
847
1165
|
this.logger.error(args, message);
|
|
848
1166
|
}
|
|
849
|
-
// Stream creation for process output handling
|
|
850
|
-
createStream() {
|
|
851
|
-
return new Transform({
|
|
852
|
-
transform: (chunk, _encoding, callback) => {
|
|
853
|
-
const line = chunk.toString().trim();
|
|
854
|
-
if (line) {
|
|
855
|
-
this.info(line);
|
|
856
|
-
}
|
|
857
|
-
callback(null, chunk);
|
|
858
|
-
}
|
|
859
|
-
});
|
|
860
|
-
}
|
|
861
|
-
async getLogs(transportId) {
|
|
862
|
-
if (!transportId || !this.transports[transportId]) {
|
|
863
|
-
return [];
|
|
864
|
-
}
|
|
865
|
-
return this.transports[transportId].getLogs();
|
|
866
|
-
}
|
|
867
|
-
async getLogsByRunId({ runId, transportId }) {
|
|
868
|
-
return this.transports[transportId]?.getLogsByRunId({ runId });
|
|
869
|
-
}
|
|
870
1167
|
};
|
|
871
|
-
function createLogger(options) {
|
|
872
|
-
return new Logger(options);
|
|
873
|
-
}
|
|
874
1168
|
|
|
875
1169
|
var DepsService = class {
|
|
876
1170
|
packageManager;
|
|
@@ -880,11 +1174,11 @@ var DepsService = class {
|
|
|
880
1174
|
findLockFile(dir) {
|
|
881
1175
|
const lockFiles = ["pnpm-lock.yaml", "package-lock.json", "yarn.lock", "bun.lock"];
|
|
882
1176
|
for (const file of lockFiles) {
|
|
883
|
-
if (fs3__default__default.existsSync(
|
|
1177
|
+
if (fs3__default__default.existsSync(path2.join(dir, file))) {
|
|
884
1178
|
return file;
|
|
885
1179
|
}
|
|
886
1180
|
}
|
|
887
|
-
const parentDir =
|
|
1181
|
+
const parentDir = path2.resolve(dir, "..");
|
|
888
1182
|
if (parentDir !== dir) {
|
|
889
1183
|
return this.findLockFile(parentDir);
|
|
890
1184
|
}
|
|
@@ -921,7 +1215,7 @@ var DepsService = class {
|
|
|
921
1215
|
}
|
|
922
1216
|
async checkDependencies(dependencies) {
|
|
923
1217
|
try {
|
|
924
|
-
const packageJsonPath =
|
|
1218
|
+
const packageJsonPath = path2.join(process.cwd(), "package.json");
|
|
925
1219
|
try {
|
|
926
1220
|
await fs4.access(packageJsonPath);
|
|
927
1221
|
} catch {
|
|
@@ -941,7 +1235,7 @@ var DepsService = class {
|
|
|
941
1235
|
}
|
|
942
1236
|
async getProjectName() {
|
|
943
1237
|
try {
|
|
944
|
-
const packageJsonPath =
|
|
1238
|
+
const packageJsonPath = path2.join(process.cwd(), "package.json");
|
|
945
1239
|
const packageJson = await fs4.readFile(packageJsonPath, "utf-8");
|
|
946
1240
|
const pkg = JSON.parse(packageJson);
|
|
947
1241
|
return pkg.name;
|
|
@@ -952,7 +1246,7 @@ var DepsService = class {
|
|
|
952
1246
|
async getPackageVersion() {
|
|
953
1247
|
const __filename = fileURLToPath(import.meta.url);
|
|
954
1248
|
const __dirname = dirname(__filename);
|
|
955
|
-
const pkgJsonPath =
|
|
1249
|
+
const pkgJsonPath = path2.join(__dirname, "..", "package.json");
|
|
956
1250
|
const content = await fsExtra3.readJSON(pkgJsonPath);
|
|
957
1251
|
return content.version;
|
|
958
1252
|
}
|
|
@@ -1000,57 +1294,85 @@ function getPackageManagerInstallCommand(pm) {
|
|
|
1000
1294
|
return "install";
|
|
1001
1295
|
}
|
|
1002
1296
|
}
|
|
1003
|
-
var args = ["-y", "@mastra/mcp-docs-server
|
|
1004
|
-
var
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1297
|
+
var args = ["-y", "@mastra/mcp-docs-server"];
|
|
1298
|
+
var createMcpConfig = (editor) => {
|
|
1299
|
+
if (editor === "vscode") {
|
|
1300
|
+
return {
|
|
1301
|
+
servers: {
|
|
1302
|
+
mastra: process.platform === `win32` ? {
|
|
1303
|
+
command: "cmd",
|
|
1304
|
+
args: ["/c", "npx", ...args],
|
|
1305
|
+
type: "stdio"
|
|
1306
|
+
} : {
|
|
1307
|
+
command: "npx",
|
|
1308
|
+
args,
|
|
1309
|
+
type: "stdio"
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
};
|
|
1013
1313
|
}
|
|
1314
|
+
return {
|
|
1315
|
+
mcpServers: {
|
|
1316
|
+
mastra: {
|
|
1317
|
+
command: "npx",
|
|
1318
|
+
args
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
};
|
|
1014
1322
|
};
|
|
1015
|
-
function makeConfig(original) {
|
|
1323
|
+
function makeConfig(original, editor) {
|
|
1324
|
+
if (editor === "vscode") {
|
|
1325
|
+
return {
|
|
1326
|
+
...original,
|
|
1327
|
+
servers: {
|
|
1328
|
+
...original?.servers || {},
|
|
1329
|
+
...createMcpConfig(editor).servers
|
|
1330
|
+
}
|
|
1331
|
+
};
|
|
1332
|
+
}
|
|
1016
1333
|
return {
|
|
1017
1334
|
...original,
|
|
1018
1335
|
mcpServers: {
|
|
1019
1336
|
...original?.mcpServers || {},
|
|
1020
|
-
...
|
|
1337
|
+
...createMcpConfig(editor).mcpServers
|
|
1021
1338
|
}
|
|
1022
1339
|
};
|
|
1023
1340
|
}
|
|
1024
|
-
async function writeMergedConfig(configPath) {
|
|
1341
|
+
async function writeMergedConfig(configPath, editor) {
|
|
1025
1342
|
const configExists = existsSync(configPath);
|
|
1026
|
-
const config = makeConfig(configExists ? await readJSON(configPath) : {});
|
|
1343
|
+
const config = makeConfig(configExists ? await readJSON(configPath) : {}, editor);
|
|
1027
1344
|
await ensureFile(configPath);
|
|
1028
1345
|
await writeJSON(configPath, config, {
|
|
1029
1346
|
spaces: 2
|
|
1030
1347
|
});
|
|
1031
1348
|
}
|
|
1032
|
-
var windsurfGlobalMCPConfigPath =
|
|
1033
|
-
var cursorGlobalMCPConfigPath =
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1349
|
+
var windsurfGlobalMCPConfigPath = path2.join(os.homedir(), ".codeium", "windsurf", "mcp_config.json");
|
|
1350
|
+
var cursorGlobalMCPConfigPath = path2.join(os.homedir(), ".cursor", "mcp.json");
|
|
1351
|
+
path2.join(process.cwd(), ".vscode", "mcp.json");
|
|
1352
|
+
var vscodeGlobalMCPConfigPath = path2.join(
|
|
1353
|
+
os.homedir(),
|
|
1354
|
+
process.platform === "win32" ? path2.join("AppData", "Roaming", "Code", "User", "settings.json") : process.platform === "darwin" ? path2.join("Library", "Application Support", "Code", "User", "settings.json") : path2.join(".config", "Code", "User", "settings.json")
|
|
1355
|
+
);
|
|
1356
|
+
async function installMastraDocsMCPServer({ editor, directory }) {
|
|
1038
1357
|
if (editor === `cursor`) {
|
|
1039
|
-
await writeMergedConfig(
|
|
1358
|
+
await writeMergedConfig(path2.join(directory, ".cursor", "mcp.json"), "cursor");
|
|
1359
|
+
}
|
|
1360
|
+
if (editor === `vscode`) {
|
|
1361
|
+
await writeMergedConfig(path2.join(directory, ".vscode", "mcp.json"), "vscode");
|
|
1040
1362
|
}
|
|
1041
1363
|
if (editor === `cursor-global`) {
|
|
1042
1364
|
const alreadyInstalled = await globalMCPIsAlreadyInstalled(editor);
|
|
1043
1365
|
if (alreadyInstalled) {
|
|
1044
1366
|
return;
|
|
1045
1367
|
}
|
|
1046
|
-
await writeMergedConfig(cursorGlobalMCPConfigPath);
|
|
1368
|
+
await writeMergedConfig(cursorGlobalMCPConfigPath, "cursor-global");
|
|
1047
1369
|
}
|
|
1048
1370
|
if (editor === `windsurf`) {
|
|
1049
1371
|
const alreadyInstalled = await globalMCPIsAlreadyInstalled(editor);
|
|
1050
1372
|
if (alreadyInstalled) {
|
|
1051
1373
|
return;
|
|
1052
1374
|
}
|
|
1053
|
-
await writeMergedConfig(windsurfGlobalMCPConfigPath);
|
|
1375
|
+
await writeMergedConfig(windsurfGlobalMCPConfigPath, editor);
|
|
1054
1376
|
}
|
|
1055
1377
|
}
|
|
1056
1378
|
async function globalMCPIsAlreadyInstalled(editor) {
|
|
@@ -1059,12 +1381,21 @@ async function globalMCPIsAlreadyInstalled(editor) {
|
|
|
1059
1381
|
configPath = windsurfGlobalMCPConfigPath;
|
|
1060
1382
|
} else if (editor === "cursor-global") {
|
|
1061
1383
|
configPath = cursorGlobalMCPConfigPath;
|
|
1384
|
+
} else if (editor === "vscode") {
|
|
1385
|
+
configPath = vscodeGlobalMCPConfigPath;
|
|
1062
1386
|
}
|
|
1063
1387
|
if (!configPath || !existsSync(configPath)) {
|
|
1064
1388
|
return false;
|
|
1065
1389
|
}
|
|
1066
1390
|
try {
|
|
1067
1391
|
const configContents = await readJSON(configPath);
|
|
1392
|
+
if (editor === "vscode") {
|
|
1393
|
+
if (!configContents?.servers) return false;
|
|
1394
|
+
const hasMastraMCP2 = Object.values(configContents.servers).some(
|
|
1395
|
+
(server) => server?.args?.find((arg) => arg?.includes(`@mastra/mcp-docs-server`))
|
|
1396
|
+
);
|
|
1397
|
+
return hasMastraMCP2;
|
|
1398
|
+
}
|
|
1068
1399
|
if (!configContents?.mcpServers) return false;
|
|
1069
1400
|
const hasMastraMCP = Object.values(configContents.mcpServers).some(
|
|
1070
1401
|
(server) => server?.args?.find((arg) => arg?.includes(`@mastra/mcp-docs-server`))
|
|
@@ -1146,8 +1477,8 @@ var FileService = class {
|
|
|
1146
1477
|
*/
|
|
1147
1478
|
async copyStarterFile(inputFile, outputFilePath, replaceIfExists) {
|
|
1148
1479
|
const __filename = fileURLToPath(import.meta.url);
|
|
1149
|
-
const __dirname =
|
|
1150
|
-
const filePath =
|
|
1480
|
+
const __dirname = path2.dirname(__filename);
|
|
1481
|
+
const filePath = path2.resolve(__dirname, "starter-files", inputFile);
|
|
1151
1482
|
const fileString = fs3__default__default.readFileSync(filePath, "utf8");
|
|
1152
1483
|
if (fs3__default__default.existsSync(outputFilePath) && !replaceIfExists) {
|
|
1153
1484
|
console.log(`${outputFilePath} already exists`);
|
|
@@ -1157,7 +1488,7 @@ var FileService = class {
|
|
|
1157
1488
|
return true;
|
|
1158
1489
|
}
|
|
1159
1490
|
async setupEnvFile({ dbUrl }) {
|
|
1160
|
-
const envPath =
|
|
1491
|
+
const envPath = path2.join(process.cwd(), ".env.development");
|
|
1161
1492
|
await fsExtra3.ensureFile(envPath);
|
|
1162
1493
|
const fileEnvService = new FileEnvService(envPath);
|
|
1163
1494
|
await fileEnvService.setEnvValue("DB_URL", dbUrl);
|
|
@@ -1181,7 +1512,7 @@ var FileService = class {
|
|
|
1181
1512
|
fs3__default__default.writeFileSync(filePath, fileContent);
|
|
1182
1513
|
}
|
|
1183
1514
|
};
|
|
1184
|
-
|
|
1515
|
+
new PinoLogger({
|
|
1185
1516
|
name: "Mastra CLI",
|
|
1186
1517
|
level: "debug"
|
|
1187
1518
|
});
|
|
@@ -1207,7 +1538,7 @@ var getProviderImportAndModelItem = (llmProvider) => {
|
|
|
1207
1538
|
let modelItem = "";
|
|
1208
1539
|
if (llmProvider === "openai") {
|
|
1209
1540
|
providerImport = `import { openai } from '${getAISDKPackage(llmProvider)}';`;
|
|
1210
|
-
modelItem = `openai('gpt-4o')`;
|
|
1541
|
+
modelItem = `openai('gpt-4o-mini')`;
|
|
1211
1542
|
} else if (llmProvider === "anthropic") {
|
|
1212
1543
|
providerImport = `import { anthropic } from '${getAISDKPackage(llmProvider)}';`;
|
|
1213
1544
|
modelItem = `anthropic('claude-3-5-sonnet-20241022')`;
|
|
@@ -1241,7 +1572,8 @@ async function writeAgentSample(llmProvider, destPath, addExampleTool) {
|
|
|
1241
1572
|
${providerImport}
|
|
1242
1573
|
import { Agent } from '@mastra/core/agent';
|
|
1243
1574
|
import { Memory } from '@mastra/memory';
|
|
1244
|
-
|
|
1575
|
+
import { LibSQLStore } from '@mastra/libsql';
|
|
1576
|
+
${addExampleTool ? `import { weatherTool } from '../tools/weather-tool';` : ""}
|
|
1245
1577
|
|
|
1246
1578
|
export const weatherAgent = new Agent({
|
|
1247
1579
|
name: 'Weather Agent',
|
|
@@ -1249,13 +1581,9 @@ export const weatherAgent = new Agent({
|
|
|
1249
1581
|
model: ${modelItem},
|
|
1250
1582
|
${addExampleTool ? "tools: { weatherTool }," : ""}
|
|
1251
1583
|
memory: new Memory({
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
threads: {
|
|
1256
|
-
generateTitle: false
|
|
1257
|
-
}
|
|
1258
|
-
}
|
|
1584
|
+
storage: new LibSQLStore({
|
|
1585
|
+
url: "file:../mastra.db", // path is relative to the .mastra/output directory
|
|
1586
|
+
})
|
|
1259
1587
|
})
|
|
1260
1588
|
});
|
|
1261
1589
|
`;
|
|
@@ -1270,7 +1598,7 @@ async function writeWorkflowSample(destPath, llmProvider) {
|
|
|
1270
1598
|
const { providerImport, modelItem } = getProviderImportAndModelItem(llmProvider);
|
|
1271
1599
|
const content = `${providerImport}
|
|
1272
1600
|
import { Agent } from '@mastra/core/agent';
|
|
1273
|
-
import {
|
|
1601
|
+
import { createStep, createWorkflow } from '@mastra/core/workflows';
|
|
1274
1602
|
import { z } from 'zod';
|
|
1275
1603
|
|
|
1276
1604
|
const llm = ${modelItem};
|
|
@@ -1323,80 +1651,107 @@ const agent = new Agent({
|
|
|
1323
1651
|
\`,
|
|
1324
1652
|
});
|
|
1325
1653
|
|
|
1326
|
-
const forecastSchema = z.
|
|
1327
|
-
z.
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
}),
|
|
1335
|
-
);
|
|
1654
|
+
const forecastSchema = z.object({
|
|
1655
|
+
date: z.string(),
|
|
1656
|
+
maxTemp: z.number(),
|
|
1657
|
+
minTemp: z.number(),
|
|
1658
|
+
precipitationChance: z.number(),
|
|
1659
|
+
condition: z.string(),
|
|
1660
|
+
location: z.string(),
|
|
1661
|
+
})
|
|
1336
1662
|
|
|
1337
|
-
|
|
1663
|
+
function getWeatherCondition(code: number): string {
|
|
1664
|
+
const conditions: Record<number, string> = {
|
|
1665
|
+
0: 'Clear sky',
|
|
1666
|
+
1: 'Mainly clear',
|
|
1667
|
+
2: 'Partly cloudy',
|
|
1668
|
+
3: 'Overcast',
|
|
1669
|
+
45: 'Foggy',
|
|
1670
|
+
48: 'Depositing rime fog',
|
|
1671
|
+
51: 'Light drizzle',
|
|
1672
|
+
53: 'Moderate drizzle',
|
|
1673
|
+
55: 'Dense drizzle',
|
|
1674
|
+
61: 'Slight rain',
|
|
1675
|
+
63: 'Moderate rain',
|
|
1676
|
+
65: 'Heavy rain',
|
|
1677
|
+
71: 'Slight snow fall',
|
|
1678
|
+
73: 'Moderate snow fall',
|
|
1679
|
+
75: 'Heavy snow fall',
|
|
1680
|
+
95: 'Thunderstorm',
|
|
1681
|
+
}
|
|
1682
|
+
return conditions[code] || 'Unknown'
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1685
|
+
const fetchWeather = createStep({
|
|
1338
1686
|
id: 'fetch-weather',
|
|
1339
1687
|
description: 'Fetches weather forecast for a given city',
|
|
1340
1688
|
inputSchema: z.object({
|
|
1341
1689
|
city: z.string().describe('The city to get the weather for'),
|
|
1342
1690
|
}),
|
|
1343
1691
|
outputSchema: forecastSchema,
|
|
1344
|
-
execute: async ({
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
if (!triggerData) {
|
|
1348
|
-
throw new Error('Trigger data not found');
|
|
1692
|
+
execute: async ({ inputData }) => {
|
|
1693
|
+
if (!inputData) {
|
|
1694
|
+
throw new Error('Input data not found');
|
|
1349
1695
|
}
|
|
1350
1696
|
|
|
1351
|
-
const geocodingUrl = \`https://geocoding-api.open-meteo.com/v1/search?name=\${encodeURIComponent(
|
|
1697
|
+
const geocodingUrl = \`https://geocoding-api.open-meteo.com/v1/search?name=\${encodeURIComponent(inputData.city)}&count=1\`;
|
|
1352
1698
|
const geocodingResponse = await fetch(geocodingUrl);
|
|
1353
1699
|
const geocodingData = (await geocodingResponse.json()) as {
|
|
1354
1700
|
results: { latitude: number; longitude: number; name: string }[];
|
|
1355
1701
|
};
|
|
1356
1702
|
|
|
1357
1703
|
if (!geocodingData.results?.[0]) {
|
|
1358
|
-
throw new Error(\`Location '\${
|
|
1704
|
+
throw new Error(\`Location '\${inputData.city}' not found\`);
|
|
1359
1705
|
}
|
|
1360
1706
|
|
|
1361
1707
|
const { latitude, longitude, name } = geocodingData.results[0];
|
|
1362
1708
|
|
|
1363
|
-
const weatherUrl = \`https://api.open-meteo.com/v1/forecast?latitude=\${latitude}&longitude=\${longitude}&
|
|
1709
|
+
const weatherUrl = \`https://api.open-meteo.com/v1/forecast?latitude=\${latitude}&longitude=\${longitude}¤t=precipitation,weathercode&timezone=auto,&hourly=precipitation_probability,temperature_2m\`;
|
|
1364
1710
|
const response = await fetch(weatherUrl);
|
|
1365
1711
|
const data = (await response.json()) as {
|
|
1366
|
-
|
|
1367
|
-
time: string
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1712
|
+
current: {
|
|
1713
|
+
time: string
|
|
1714
|
+
precipitation: number
|
|
1715
|
+
weathercode: number
|
|
1716
|
+
}
|
|
1717
|
+
hourly: {
|
|
1718
|
+
precipitation_probability: number[]
|
|
1719
|
+
temperature_2m: number[]
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1374
1722
|
|
|
1375
|
-
const forecast =
|
|
1376
|
-
date,
|
|
1377
|
-
maxTemp: data.
|
|
1378
|
-
minTemp: data.
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1723
|
+
const forecast = {
|
|
1724
|
+
date: new Date().toISOString(),
|
|
1725
|
+
maxTemp: Math.max(...data.hourly.temperature_2m),
|
|
1726
|
+
minTemp: Math.min(...data.hourly.temperature_2m),
|
|
1727
|
+
condition: getWeatherCondition(data.current.weathercode),
|
|
1728
|
+
precipitationChance: data.hourly.precipitation_probability.reduce(
|
|
1729
|
+
(acc, curr) => Math.max(acc, curr),
|
|
1730
|
+
0
|
|
1731
|
+
),
|
|
1732
|
+
location: name
|
|
1733
|
+
}
|
|
1383
1734
|
|
|
1384
1735
|
return forecast;
|
|
1385
1736
|
},
|
|
1386
1737
|
});
|
|
1387
1738
|
|
|
1388
1739
|
|
|
1389
|
-
const planActivities =
|
|
1740
|
+
const planActivities = createStep({
|
|
1390
1741
|
id: 'plan-activities',
|
|
1391
1742
|
description: 'Suggests activities based on weather conditions',
|
|
1392
|
-
|
|
1393
|
-
|
|
1743
|
+
inputSchema: forecastSchema,
|
|
1744
|
+
outputSchema: z.object({
|
|
1745
|
+
activities: z.string(),
|
|
1746
|
+
}),
|
|
1747
|
+
execute: async ({ inputData }) => {
|
|
1748
|
+
const forecast = inputData
|
|
1394
1749
|
|
|
1395
|
-
if (!forecast
|
|
1396
|
-
throw new Error('Forecast data not found')
|
|
1750
|
+
if (!forecast) {
|
|
1751
|
+
throw new Error('Forecast data not found')
|
|
1397
1752
|
}
|
|
1398
1753
|
|
|
1399
|
-
const prompt = \`Based on the following weather forecast for \${forecast
|
|
1754
|
+
const prompt = \`Based on the following weather forecast for \${forecast.location}, suggest appropriate activities:
|
|
1400
1755
|
\${JSON.stringify(forecast, null, 2)}
|
|
1401
1756
|
\`;
|
|
1402
1757
|
|
|
@@ -1408,7 +1763,7 @@ const planActivities = new Step({
|
|
|
1408
1763
|
]);
|
|
1409
1764
|
|
|
1410
1765
|
let activitiesText = '';
|
|
1411
|
-
|
|
1766
|
+
|
|
1412
1767
|
for await (const chunk of response.textStream) {
|
|
1413
1768
|
process.stdout.write(chunk);
|
|
1414
1769
|
activitiesText += chunk;
|
|
@@ -1420,35 +1775,16 @@ const planActivities = new Step({
|
|
|
1420
1775
|
},
|
|
1421
1776
|
});
|
|
1422
1777
|
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
1: 'Mainly clear',
|
|
1427
|
-
2: 'Partly cloudy',
|
|
1428
|
-
3: 'Overcast',
|
|
1429
|
-
45: 'Foggy',
|
|
1430
|
-
48: 'Depositing rime fog',
|
|
1431
|
-
51: 'Light drizzle',
|
|
1432
|
-
53: 'Moderate drizzle',
|
|
1433
|
-
55: 'Dense drizzle',
|
|
1434
|
-
61: 'Slight rain',
|
|
1435
|
-
63: 'Moderate rain',
|
|
1436
|
-
65: 'Heavy rain',
|
|
1437
|
-
71: 'Slight snow fall',
|
|
1438
|
-
73: 'Moderate snow fall',
|
|
1439
|
-
75: 'Heavy snow fall',
|
|
1440
|
-
95: 'Thunderstorm',
|
|
1441
|
-
};
|
|
1442
|
-
return conditions[code] || 'Unknown';
|
|
1443
|
-
}
|
|
1444
|
-
|
|
1445
|
-
const weatherWorkflow = new Workflow({
|
|
1446
|
-
name: 'weather-workflow',
|
|
1447
|
-
triggerSchema: z.object({
|
|
1778
|
+
const weatherWorkflow = createWorkflow({
|
|
1779
|
+
id: 'weather-workflow',
|
|
1780
|
+
inputSchema: z.object({
|
|
1448
1781
|
city: z.string().describe('The city to get the weather for'),
|
|
1449
1782
|
}),
|
|
1783
|
+
outputSchema: z.object({
|
|
1784
|
+
activities: z.string(),
|
|
1785
|
+
})
|
|
1450
1786
|
})
|
|
1451
|
-
.
|
|
1787
|
+
.then(fetchWeather)
|
|
1452
1788
|
.then(planActivities);
|
|
1453
1789
|
|
|
1454
1790
|
weatherWorkflow.commit();
|
|
@@ -1488,7 +1824,7 @@ var writeIndexFile = async ({
|
|
|
1488
1824
|
addWorkflow
|
|
1489
1825
|
}) => {
|
|
1490
1826
|
const indexPath = dirPath + "/index.ts";
|
|
1491
|
-
const destPath =
|
|
1827
|
+
const destPath = path2.join(indexPath);
|
|
1492
1828
|
try {
|
|
1493
1829
|
await fs4.writeFile(destPath, "");
|
|
1494
1830
|
const filteredExports = [
|
|
@@ -1510,10 +1846,10 @@ export const mastra = new Mastra()
|
|
|
1510
1846
|
destPath,
|
|
1511
1847
|
`
|
|
1512
1848
|
import { Mastra } from '@mastra/core/mastra';
|
|
1513
|
-
import {
|
|
1849
|
+
import { PinoLogger } from '@mastra/loggers';
|
|
1514
1850
|
import { LibSQLStore } from '@mastra/libsql';
|
|
1515
|
-
${addWorkflow ? `import { weatherWorkflow } from './workflows';` : ""}
|
|
1516
|
-
${addAgent ? `import { weatherAgent } from './agents';` : ""}
|
|
1851
|
+
${addWorkflow ? `import { weatherWorkflow } from './workflows/weather-workflow';` : ""}
|
|
1852
|
+
${addAgent ? `import { weatherAgent } from './agents/weather-agent';` : ""}
|
|
1517
1853
|
|
|
1518
1854
|
export const mastra = new Mastra({
|
|
1519
1855
|
${filteredExports.join("\n ")}
|
|
@@ -1521,7 +1857,7 @@ export const mastra = new Mastra({
|
|
|
1521
1857
|
// stores telemetry, evals, ... into memory storage, if it needs to persist, change to file:../mastra.db
|
|
1522
1858
|
url: ":memory:",
|
|
1523
1859
|
}),
|
|
1524
|
-
logger:
|
|
1860
|
+
logger: new PinoLogger({
|
|
1525
1861
|
name: 'Mastra',
|
|
1526
1862
|
level: 'info',
|
|
1527
1863
|
}),
|
|
@@ -1557,11 +1893,13 @@ var writeAPIKey = async ({
|
|
|
1557
1893
|
apiKey = "your-api-key"
|
|
1558
1894
|
}) => {
|
|
1559
1895
|
const key = await getAPIKey(provider);
|
|
1560
|
-
|
|
1896
|
+
const escapedKey = shellQuote.quote([key]);
|
|
1897
|
+
const escapedApiKey = shellQuote.quote([apiKey]);
|
|
1898
|
+
await exec(`echo ${escapedKey}=${escapedApiKey} >> .env`);
|
|
1561
1899
|
};
|
|
1562
1900
|
var createMastraDir = async (directory) => {
|
|
1563
1901
|
let dir = directory.trim().split("/").filter((item) => item !== "");
|
|
1564
|
-
const dirPath =
|
|
1902
|
+
const dirPath = path2.join(process.cwd(), ...dir, "mastra");
|
|
1565
1903
|
try {
|
|
1566
1904
|
await fs4.access(dirPath);
|
|
1567
1905
|
return { ok: false };
|
|
@@ -1571,7 +1909,7 @@ var createMastraDir = async (directory) => {
|
|
|
1571
1909
|
}
|
|
1572
1910
|
};
|
|
1573
1911
|
var writeCodeSample = async (dirPath, component, llmProvider, importComponents) => {
|
|
1574
|
-
const destPath = dirPath + `/${component}/
|
|
1912
|
+
const destPath = dirPath + `/${component}/weather-${component.slice(0, -1)}.ts`;
|
|
1575
1913
|
try {
|
|
1576
1914
|
await writeCodeSampleForComponents(llmProvider, component, destPath, importComponents);
|
|
1577
1915
|
} catch (err) {
|
|
@@ -1635,6 +1973,7 @@ var interactivePrompt = async () => {
|
|
|
1635
1973
|
configureEditorWithDocsMCP: async () => {
|
|
1636
1974
|
const windsurfIsAlreadyInstalled = await globalMCPIsAlreadyInstalled(`windsurf`);
|
|
1637
1975
|
const cursorIsAlreadyInstalled = await globalMCPIsAlreadyInstalled(`cursor`);
|
|
1976
|
+
const vscodeIsAlreadyInstalled = await globalMCPIsAlreadyInstalled(`vscode`);
|
|
1638
1977
|
const editor = await le({
|
|
1639
1978
|
message: `Make your AI IDE into a Mastra expert? (installs Mastra docs MCP server)`,
|
|
1640
1979
|
options: [
|
|
@@ -1653,6 +1992,11 @@ var interactivePrompt = async () => {
|
|
|
1653
1992
|
value: "windsurf",
|
|
1654
1993
|
label: "Windsurf",
|
|
1655
1994
|
hint: windsurfIsAlreadyInstalled ? `Already installed` : void 0
|
|
1995
|
+
},
|
|
1996
|
+
{
|
|
1997
|
+
value: "vscode",
|
|
1998
|
+
label: "VSCode",
|
|
1999
|
+
hint: vscodeIsAlreadyInstalled ? `Already installed` : void 0
|
|
1656
2000
|
}
|
|
1657
2001
|
]
|
|
1658
2002
|
});
|
|
@@ -1662,6 +2006,11 @@ var interactivePrompt = async () => {
|
|
|
1662
2006
|
Windsurf is already installed, skipping.`);
|
|
1663
2007
|
return void 0;
|
|
1664
2008
|
}
|
|
2009
|
+
if (editor === `vscode` && vscodeIsAlreadyInstalled) {
|
|
2010
|
+
v.message(`
|
|
2011
|
+
VSCode is already installed, skipping.`);
|
|
2012
|
+
return void 0;
|
|
2013
|
+
}
|
|
1665
2014
|
if (editor === `cursor`) {
|
|
1666
2015
|
v.message(
|
|
1667
2016
|
`
|
|
@@ -1751,6 +2100,10 @@ var init = async ({
|
|
|
1751
2100
|
if (needsMemory) {
|
|
1752
2101
|
await depService.installPackages(["@mastra/memory"]);
|
|
1753
2102
|
}
|
|
2103
|
+
const needsLoggers = await depService.checkDependencies(["@mastra/loggers"]) !== `ok`;
|
|
2104
|
+
if (needsLoggers) {
|
|
2105
|
+
await depService.installPackages(["@mastra/loggers"]);
|
|
2106
|
+
}
|
|
1754
2107
|
}
|
|
1755
2108
|
const key = await getAPIKey(llmProvider || "openai");
|
|
1756
2109
|
const aiSdkPackage = getAISDKPackage(llmProvider);
|
|
@@ -1770,7 +2123,7 @@ var init = async ({
|
|
|
1770
2123
|
${color2.green("Mastra initialized successfully!")}
|
|
1771
2124
|
|
|
1772
2125
|
Add your ${color2.cyan(key)} as an environment variable
|
|
1773
|
-
in your ${color2.cyan(".env
|
|
2126
|
+
in your ${color2.cyan(".env")} file
|
|
1774
2127
|
`);
|
|
1775
2128
|
} else {
|
|
1776
2129
|
me(`
|
|
@@ -1831,7 +2184,7 @@ var createMastraProject = async ({
|
|
|
1831
2184
|
createVersionTag,
|
|
1832
2185
|
timeout
|
|
1833
2186
|
}) => {
|
|
1834
|
-
pe(color2.inverse("Mastra Create"));
|
|
2187
|
+
pe(color2.inverse(" Mastra Create "));
|
|
1835
2188
|
const projectName = name ?? await ae({
|
|
1836
2189
|
message: "What do you want to name your project?",
|
|
1837
2190
|
placeholder: "my-mastra-app",
|
|
@@ -1860,10 +2213,12 @@ var createMastraProject = async ({
|
|
|
1860
2213
|
s2.message("Creating project");
|
|
1861
2214
|
await exec3(`npm init -y`);
|
|
1862
2215
|
await exec3(`npm pkg set type="module"`);
|
|
2216
|
+
await exec3(`npm pkg set engines.node=">=20.9.0"`);
|
|
1863
2217
|
const depsService = new DepsService();
|
|
1864
2218
|
await depsService.addScriptsToPackageJson({
|
|
1865
2219
|
dev: "mastra dev",
|
|
1866
|
-
build: "mastra build"
|
|
2220
|
+
build: "mastra build",
|
|
2221
|
+
start: "mastra start"
|
|
1867
2222
|
});
|
|
1868
2223
|
s2.stop("Project created");
|
|
1869
2224
|
s2.start(`Installing ${pm} dependencies`);
|
|
@@ -1887,7 +2242,7 @@ var createMastraProject = async ({
|
|
|
1887
2242
|
}' > tsconfig.json`);
|
|
1888
2243
|
s2.stop(`${pm} dependencies installed`);
|
|
1889
2244
|
s2.start("Installing mastra");
|
|
1890
|
-
const versionTag = createVersionTag ?
|
|
2245
|
+
const versionTag = createVersionTag ? `@latest` : "@latest";
|
|
1891
2246
|
await installMastraDependency(pm, "mastra", versionTag, true, timeout);
|
|
1892
2247
|
s2.stop("mastra installed");
|
|
1893
2248
|
s2.start("Installing dependencies");
|
|
@@ -1916,13 +2271,16 @@ var create = async (args2) => {
|
|
|
1916
2271
|
timeout: args2?.timeout
|
|
1917
2272
|
});
|
|
1918
2273
|
const directory = args2.directory || "src/";
|
|
2274
|
+
console.log("args", args2);
|
|
1919
2275
|
if (args2.components === void 0 || args2.llmProvider === void 0 || args2.addExample === void 0) {
|
|
2276
|
+
console.log("got to interactive prompt");
|
|
1920
2277
|
const result = await interactivePrompt();
|
|
1921
2278
|
await init({
|
|
1922
2279
|
...result,
|
|
1923
2280
|
llmApiKey: result?.llmApiKey
|
|
1924
2281
|
});
|
|
1925
2282
|
postCreate({ projectName });
|
|
2283
|
+
console.log("done with interactive prompt");
|
|
1926
2284
|
return;
|
|
1927
2285
|
}
|
|
1928
2286
|
const { components = [], llmProvider = "openai", addExample = false, llmApiKey } = args2;
|
|
@@ -1931,23 +2289,25 @@ var create = async (args2) => {
|
|
|
1931
2289
|
components,
|
|
1932
2290
|
llmProvider,
|
|
1933
2291
|
addExample,
|
|
1934
|
-
llmApiKey
|
|
2292
|
+
llmApiKey,
|
|
2293
|
+
configureEditorWithDocsMCP: args2.mcpServer
|
|
1935
2294
|
});
|
|
1936
2295
|
postCreate({ projectName });
|
|
1937
2296
|
};
|
|
1938
2297
|
var postCreate = ({ projectName }) => {
|
|
2298
|
+
const packageManager = getPackageManager();
|
|
1939
2299
|
ge(`
|
|
1940
2300
|
${color2.green("To start your project:")}
|
|
1941
2301
|
|
|
1942
2302
|
${color2.cyan("cd")} ${projectName}
|
|
1943
|
-
${color2.cyan(
|
|
2303
|
+
${color2.cyan(`${packageManager} run dev`)}
|
|
1944
2304
|
`);
|
|
1945
2305
|
};
|
|
1946
2306
|
|
|
1947
2307
|
async function getPackageVersion() {
|
|
1948
2308
|
const __filename = fileURLToPath(import.meta.url);
|
|
1949
2309
|
const __dirname = dirname(__filename);
|
|
1950
|
-
const pkgJsonPath =
|
|
2310
|
+
const pkgJsonPath = path2.join(__dirname, "..", "package.json");
|
|
1951
2311
|
const content = await fsExtra.readJSON(pkgJsonPath);
|
|
1952
2312
|
return content.version;
|
|
1953
2313
|
}
|
|
@@ -1956,7 +2316,7 @@ async function getCreateVersionTag() {
|
|
|
1956
2316
|
const pkgPath = fileURLToPath(import.meta.resolve("create-mastra/package.json"));
|
|
1957
2317
|
const json = await fsExtra.readJSON(pkgPath);
|
|
1958
2318
|
const { stdout } = await execa("npm", ["dist-tag", "create-mastra"]);
|
|
1959
|
-
const tagLine = stdout.split("\n").find((distLine) => distLine.
|
|
2319
|
+
const tagLine = stdout.split("\n").find((distLine) => distLine.endsWith(`: ${json.version}`));
|
|
1960
2320
|
const tag = tagLine ? tagLine.split(":")[0].trim() : "latest";
|
|
1961
2321
|
return tag;
|
|
1962
2322
|
} catch {
|
|
@@ -1985,16 +2345,18 @@ program.version(`${version}`, "-v, --version").description(`create-mastra ${vers
|
|
|
1985
2345
|
program.name("create-mastra").description("Create a new Mastra project").argument("[project-name]", "Directory name of the project").option(
|
|
1986
2346
|
"-p, --project-name <string>",
|
|
1987
2347
|
"Project name that will be used in package.json and as the project directory name."
|
|
1988
|
-
).option("--default", "Quick start with defaults(src, OpenAI,
|
|
2348
|
+
).option("--default", "Quick start with defaults(src, OpenAI, examples)").option("-c, --components <components>", "Comma-separated list of components (agents, tools, workflows)").option("-l, --llm <model-provider>", "Default model provider (openai, anthropic, groq, google, or cerebras)").option("-k, --llm-api-key <api-key>", "API key for the model provider").option("-e, --example", "Include example code").option("-n, --no-example", "Do not include example code").option("-t, --timeout [timeout]", "Configurable timeout for package installation, defaults to 60000 ms").option("-d, --dir <directory>", "Target directory for Mastra source code (default: src/)").option("-m, --mcp <mcp>", "MCP Server for code editor (cursor, cursor-global, windsurf, vscode)").action(async (projectNameArg, args) => {
|
|
1989
2349
|
const projectName = projectNameArg || args.projectName;
|
|
1990
2350
|
const timeout = args?.timeout ? args?.timeout === true ? 6e4 : parseInt(args?.timeout, 10) : void 0;
|
|
1991
2351
|
if (args.default) {
|
|
1992
2352
|
await create({
|
|
1993
2353
|
components: ["agents", "tools", "workflows"],
|
|
1994
2354
|
llmProvider: "openai",
|
|
1995
|
-
addExample:
|
|
2355
|
+
addExample: true,
|
|
1996
2356
|
createVersionTag,
|
|
1997
|
-
timeout
|
|
2357
|
+
timeout,
|
|
2358
|
+
mcpServer: args.mcp,
|
|
2359
|
+
directory: "src/"
|
|
1998
2360
|
});
|
|
1999
2361
|
return;
|
|
2000
2362
|
}
|
|
@@ -2006,7 +2368,8 @@ program.name("create-mastra").description("Create a new Mastra project").argumen
|
|
|
2006
2368
|
createVersionTag,
|
|
2007
2369
|
timeout,
|
|
2008
2370
|
projectName,
|
|
2009
|
-
directory: args.dir
|
|
2371
|
+
directory: args.dir,
|
|
2372
|
+
mcpServer: args.mcp
|
|
2010
2373
|
});
|
|
2011
2374
|
});
|
|
2012
2375
|
program.parse(process.argv);
|