create-mastra 0.0.0-fix-message-embedding-20250506021742 → 0.0.0-inject-middleware-20250528222017
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 +514 -181
- package/dist/index.js.map +1 -1
- package/dist/templates/dev.entry.js +0 -5
- package/package.json +3 -3
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 0;
|
|
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,65 @@ 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
|
+
async getLogs(transportId) {
|
|
1083
|
+
if (!transportId || !this.transports.has(transportId)) {
|
|
1084
|
+
return [];
|
|
1085
|
+
}
|
|
1086
|
+
return this.transports.get(transportId).getLogs() ?? [];
|
|
1087
|
+
}
|
|
1088
|
+
async getLogsByRunId({ transportId, runId }) {
|
|
1089
|
+
if (!transportId || !this.transports.has(transportId) || !runId) {
|
|
1090
|
+
return [];
|
|
1091
|
+
}
|
|
1092
|
+
return this.transports.get(transportId).getLogsByRunId({ runId }) ?? [];
|
|
1093
|
+
}
|
|
1094
|
+
};
|
|
1095
|
+
|
|
1096
|
+
var PinoLogger = class extends MastraLogger {
|
|
1097
|
+
logger;
|
|
1098
|
+
constructor(options = {}) {
|
|
1099
|
+
super(options);
|
|
1100
|
+
let prettyStream = void 0;
|
|
1101
|
+
if (!options.overrideDefaultTransports) {
|
|
1102
|
+
prettyStream = pretty({
|
|
1103
|
+
colorize: true,
|
|
1104
|
+
levelFirst: true,
|
|
1105
|
+
ignore: "pid,hostname",
|
|
1106
|
+
colorizeObjects: true,
|
|
1107
|
+
translateTime: "SYS:standard",
|
|
1108
|
+
singleLine: false
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
const transportsAry = [...this.getTransports().entries()];
|
|
799
1112
|
this.logger = pino(
|
|
800
1113
|
{
|
|
801
1114
|
name: options.name || "app",
|
|
802
1115
|
level: options.level || LogLevel.INFO,
|
|
803
1116
|
formatters: {
|
|
804
|
-
level: (label) => {
|
|
805
|
-
return {
|
|
806
|
-
level: label
|
|
807
|
-
};
|
|
808
|
-
}
|
|
1117
|
+
level: (label) => ({ level: label })
|
|
809
1118
|
}
|
|
810
1119
|
},
|
|
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([
|
|
1120
|
+
options.overrideDefaultTransports ? options?.transports?.default : transportsAry.length === 0 ? prettyStream : pino.multistream([
|
|
819
1121
|
...transportsAry.map(([, transport]) => ({
|
|
820
1122
|
stream: transport,
|
|
821
1123
|
level: options.level || LogLevel.INFO
|
|
822
1124
|
})),
|
|
823
1125
|
{
|
|
824
|
-
stream:
|
|
825
|
-
colorize: true,
|
|
826
|
-
levelFirst: true,
|
|
827
|
-
ignore: "pid,hostname",
|
|
828
|
-
colorizeObjects: true,
|
|
829
|
-
translateTime: "SYS:standard",
|
|
830
|
-
singleLine: false
|
|
831
|
-
}),
|
|
1126
|
+
stream: prettyStream,
|
|
832
1127
|
level: options.level || LogLevel.INFO
|
|
833
1128
|
}
|
|
834
1129
|
])
|
|
@@ -846,31 +1141,7 @@ var Logger = class {
|
|
|
846
1141
|
error(message, args = {}) {
|
|
847
1142
|
this.logger.error(args, message);
|
|
848
1143
|
}
|
|
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
1144
|
};
|
|
871
|
-
function createLogger(options) {
|
|
872
|
-
return new Logger(options);
|
|
873
|
-
}
|
|
874
1145
|
|
|
875
1146
|
var DepsService = class {
|
|
876
1147
|
packageManager;
|
|
@@ -880,11 +1151,11 @@ var DepsService = class {
|
|
|
880
1151
|
findLockFile(dir) {
|
|
881
1152
|
const lockFiles = ["pnpm-lock.yaml", "package-lock.json", "yarn.lock", "bun.lock"];
|
|
882
1153
|
for (const file of lockFiles) {
|
|
883
|
-
if (fs3__default__default.existsSync(
|
|
1154
|
+
if (fs3__default__default.existsSync(path2.join(dir, file))) {
|
|
884
1155
|
return file;
|
|
885
1156
|
}
|
|
886
1157
|
}
|
|
887
|
-
const parentDir =
|
|
1158
|
+
const parentDir = path2.resolve(dir, "..");
|
|
888
1159
|
if (parentDir !== dir) {
|
|
889
1160
|
return this.findLockFile(parentDir);
|
|
890
1161
|
}
|
|
@@ -921,7 +1192,7 @@ var DepsService = class {
|
|
|
921
1192
|
}
|
|
922
1193
|
async checkDependencies(dependencies) {
|
|
923
1194
|
try {
|
|
924
|
-
const packageJsonPath =
|
|
1195
|
+
const packageJsonPath = path2.join(process.cwd(), "package.json");
|
|
925
1196
|
try {
|
|
926
1197
|
await fs4.access(packageJsonPath);
|
|
927
1198
|
} catch {
|
|
@@ -941,7 +1212,7 @@ var DepsService = class {
|
|
|
941
1212
|
}
|
|
942
1213
|
async getProjectName() {
|
|
943
1214
|
try {
|
|
944
|
-
const packageJsonPath =
|
|
1215
|
+
const packageJsonPath = path2.join(process.cwd(), "package.json");
|
|
945
1216
|
const packageJson = await fs4.readFile(packageJsonPath, "utf-8");
|
|
946
1217
|
const pkg = JSON.parse(packageJson);
|
|
947
1218
|
return pkg.name;
|
|
@@ -952,7 +1223,7 @@ var DepsService = class {
|
|
|
952
1223
|
async getPackageVersion() {
|
|
953
1224
|
const __filename = fileURLToPath(import.meta.url);
|
|
954
1225
|
const __dirname = dirname(__filename);
|
|
955
|
-
const pkgJsonPath =
|
|
1226
|
+
const pkgJsonPath = path2.join(__dirname, "..", "package.json");
|
|
956
1227
|
const content = await fsExtra3.readJSON(pkgJsonPath);
|
|
957
1228
|
return content.version;
|
|
958
1229
|
}
|
|
@@ -1001,56 +1272,87 @@ function getPackageManagerInstallCommand(pm) {
|
|
|
1001
1272
|
}
|
|
1002
1273
|
}
|
|
1003
1274
|
var args = ["-y", "@mastra/mcp-docs-server@latest"];
|
|
1004
|
-
var
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1275
|
+
var createMcpConfig = (editor) => {
|
|
1276
|
+
if (editor === "vscode") {
|
|
1277
|
+
return {
|
|
1278
|
+
servers: {
|
|
1279
|
+
mastra: process.platform === `win32` ? {
|
|
1280
|
+
command: "cmd",
|
|
1281
|
+
args: ["/c", "npx", ...args],
|
|
1282
|
+
type: "stdio"
|
|
1283
|
+
} : {
|
|
1284
|
+
command: "npx",
|
|
1285
|
+
args,
|
|
1286
|
+
type: "stdio"
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
};
|
|
1013
1290
|
}
|
|
1291
|
+
return {
|
|
1292
|
+
mcpServers: {
|
|
1293
|
+
mastra: process.platform === `win32` ? {
|
|
1294
|
+
command: "cmd",
|
|
1295
|
+
args: ["/c", "npx", ...args]
|
|
1296
|
+
} : {
|
|
1297
|
+
command: "npx",
|
|
1298
|
+
args
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
};
|
|
1014
1302
|
};
|
|
1015
|
-
function makeConfig(original) {
|
|
1303
|
+
function makeConfig(original, editor) {
|
|
1304
|
+
if (editor === "vscode") {
|
|
1305
|
+
return {
|
|
1306
|
+
...original,
|
|
1307
|
+
servers: {
|
|
1308
|
+
...original?.servers || {},
|
|
1309
|
+
...createMcpConfig(editor).servers
|
|
1310
|
+
}
|
|
1311
|
+
};
|
|
1312
|
+
}
|
|
1016
1313
|
return {
|
|
1017
1314
|
...original,
|
|
1018
1315
|
mcpServers: {
|
|
1019
1316
|
...original?.mcpServers || {},
|
|
1020
|
-
...
|
|
1317
|
+
...createMcpConfig(editor).mcpServers
|
|
1021
1318
|
}
|
|
1022
1319
|
};
|
|
1023
1320
|
}
|
|
1024
|
-
async function writeMergedConfig(configPath) {
|
|
1321
|
+
async function writeMergedConfig(configPath, editor) {
|
|
1025
1322
|
const configExists = existsSync(configPath);
|
|
1026
|
-
const config = makeConfig(configExists ? await readJSON(configPath) : {});
|
|
1323
|
+
const config = makeConfig(configExists ? await readJSON(configPath) : {}, editor);
|
|
1027
1324
|
await ensureFile(configPath);
|
|
1028
1325
|
await writeJSON(configPath, config, {
|
|
1029
1326
|
spaces: 2
|
|
1030
1327
|
});
|
|
1031
1328
|
}
|
|
1032
|
-
var windsurfGlobalMCPConfigPath =
|
|
1033
|
-
var cursorGlobalMCPConfigPath =
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1329
|
+
var windsurfGlobalMCPConfigPath = path2.join(os.homedir(), ".codeium", "windsurf", "mcp_config.json");
|
|
1330
|
+
var cursorGlobalMCPConfigPath = path2.join(os.homedir(), ".cursor", "mcp.json");
|
|
1331
|
+
path2.join(process.cwd(), ".vscode", "mcp.json");
|
|
1332
|
+
var vscodeGlobalMCPConfigPath = path2.join(
|
|
1333
|
+
os.homedir(),
|
|
1334
|
+
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")
|
|
1335
|
+
);
|
|
1336
|
+
async function installMastraDocsMCPServer({ editor, directory }) {
|
|
1038
1337
|
if (editor === `cursor`) {
|
|
1039
|
-
await writeMergedConfig(
|
|
1338
|
+
await writeMergedConfig(path2.join(directory, ".cursor", "mcp.json"), "cursor");
|
|
1339
|
+
}
|
|
1340
|
+
if (editor === `vscode`) {
|
|
1341
|
+
await writeMergedConfig(path2.join(directory, ".vscode", "mcp.json"), "vscode");
|
|
1040
1342
|
}
|
|
1041
1343
|
if (editor === `cursor-global`) {
|
|
1042
1344
|
const alreadyInstalled = await globalMCPIsAlreadyInstalled(editor);
|
|
1043
1345
|
if (alreadyInstalled) {
|
|
1044
1346
|
return;
|
|
1045
1347
|
}
|
|
1046
|
-
await writeMergedConfig(cursorGlobalMCPConfigPath);
|
|
1348
|
+
await writeMergedConfig(cursorGlobalMCPConfigPath, "cursor-global");
|
|
1047
1349
|
}
|
|
1048
1350
|
if (editor === `windsurf`) {
|
|
1049
1351
|
const alreadyInstalled = await globalMCPIsAlreadyInstalled(editor);
|
|
1050
1352
|
if (alreadyInstalled) {
|
|
1051
1353
|
return;
|
|
1052
1354
|
}
|
|
1053
|
-
await writeMergedConfig(windsurfGlobalMCPConfigPath);
|
|
1355
|
+
await writeMergedConfig(windsurfGlobalMCPConfigPath, editor);
|
|
1054
1356
|
}
|
|
1055
1357
|
}
|
|
1056
1358
|
async function globalMCPIsAlreadyInstalled(editor) {
|
|
@@ -1059,12 +1361,21 @@ async function globalMCPIsAlreadyInstalled(editor) {
|
|
|
1059
1361
|
configPath = windsurfGlobalMCPConfigPath;
|
|
1060
1362
|
} else if (editor === "cursor-global") {
|
|
1061
1363
|
configPath = cursorGlobalMCPConfigPath;
|
|
1364
|
+
} else if (editor === "vscode") {
|
|
1365
|
+
configPath = vscodeGlobalMCPConfigPath;
|
|
1062
1366
|
}
|
|
1063
1367
|
if (!configPath || !existsSync(configPath)) {
|
|
1064
1368
|
return false;
|
|
1065
1369
|
}
|
|
1066
1370
|
try {
|
|
1067
1371
|
const configContents = await readJSON(configPath);
|
|
1372
|
+
if (editor === "vscode") {
|
|
1373
|
+
if (!configContents?.servers) return false;
|
|
1374
|
+
const hasMastraMCP2 = Object.values(configContents.servers).some(
|
|
1375
|
+
(server) => server?.args?.find((arg) => arg?.includes(`@mastra/mcp-docs-server`))
|
|
1376
|
+
);
|
|
1377
|
+
return hasMastraMCP2;
|
|
1378
|
+
}
|
|
1068
1379
|
if (!configContents?.mcpServers) return false;
|
|
1069
1380
|
const hasMastraMCP = Object.values(configContents.mcpServers).some(
|
|
1070
1381
|
(server) => server?.args?.find((arg) => arg?.includes(`@mastra/mcp-docs-server`))
|
|
@@ -1146,8 +1457,8 @@ var FileService = class {
|
|
|
1146
1457
|
*/
|
|
1147
1458
|
async copyStarterFile(inputFile, outputFilePath, replaceIfExists) {
|
|
1148
1459
|
const __filename = fileURLToPath(import.meta.url);
|
|
1149
|
-
const __dirname =
|
|
1150
|
-
const filePath =
|
|
1460
|
+
const __dirname = path2.dirname(__filename);
|
|
1461
|
+
const filePath = path2.resolve(__dirname, "starter-files", inputFile);
|
|
1151
1462
|
const fileString = fs3__default__default.readFileSync(filePath, "utf8");
|
|
1152
1463
|
if (fs3__default__default.existsSync(outputFilePath) && !replaceIfExists) {
|
|
1153
1464
|
console.log(`${outputFilePath} already exists`);
|
|
@@ -1157,7 +1468,7 @@ var FileService = class {
|
|
|
1157
1468
|
return true;
|
|
1158
1469
|
}
|
|
1159
1470
|
async setupEnvFile({ dbUrl }) {
|
|
1160
|
-
const envPath =
|
|
1471
|
+
const envPath = path2.join(process.cwd(), ".env.development");
|
|
1161
1472
|
await fsExtra3.ensureFile(envPath);
|
|
1162
1473
|
const fileEnvService = new FileEnvService(envPath);
|
|
1163
1474
|
await fileEnvService.setEnvValue("DB_URL", dbUrl);
|
|
@@ -1181,7 +1492,7 @@ var FileService = class {
|
|
|
1181
1492
|
fs3__default__default.writeFileSync(filePath, fileContent);
|
|
1182
1493
|
}
|
|
1183
1494
|
};
|
|
1184
|
-
|
|
1495
|
+
new PinoLogger({
|
|
1185
1496
|
name: "Mastra CLI",
|
|
1186
1497
|
level: "debug"
|
|
1187
1498
|
});
|
|
@@ -1207,7 +1518,7 @@ var getProviderImportAndModelItem = (llmProvider) => {
|
|
|
1207
1518
|
let modelItem = "";
|
|
1208
1519
|
if (llmProvider === "openai") {
|
|
1209
1520
|
providerImport = `import { openai } from '${getAISDKPackage(llmProvider)}';`;
|
|
1210
|
-
modelItem = `openai('gpt-4o')`;
|
|
1521
|
+
modelItem = `openai('gpt-4o-mini')`;
|
|
1211
1522
|
} else if (llmProvider === "anthropic") {
|
|
1212
1523
|
providerImport = `import { anthropic } from '${getAISDKPackage(llmProvider)}';`;
|
|
1213
1524
|
modelItem = `anthropic('claude-3-5-sonnet-20241022')`;
|
|
@@ -1242,7 +1553,7 @@ ${providerImport}
|
|
|
1242
1553
|
import { Agent } from '@mastra/core/agent';
|
|
1243
1554
|
import { Memory } from '@mastra/memory';
|
|
1244
1555
|
import { LibSQLStore } from '@mastra/libsql';
|
|
1245
|
-
${addExampleTool ? `import { weatherTool } from '../tools';` : ""}
|
|
1556
|
+
${addExampleTool ? `import { weatherTool } from '../tools/weather-tool';` : ""}
|
|
1246
1557
|
|
|
1247
1558
|
export const weatherAgent = new Agent({
|
|
1248
1559
|
name: 'Weather Agent',
|
|
@@ -1252,14 +1563,7 @@ export const weatherAgent = new Agent({
|
|
|
1252
1563
|
memory: new Memory({
|
|
1253
1564
|
storage: new LibSQLStore({
|
|
1254
1565
|
url: "file:../mastra.db", // path is relative to the .mastra/output directory
|
|
1255
|
-
})
|
|
1256
|
-
options: {
|
|
1257
|
-
lastMessages: 10,
|
|
1258
|
-
semanticRecall: false,
|
|
1259
|
-
threads: {
|
|
1260
|
-
generateTitle: false
|
|
1261
|
-
}
|
|
1262
|
-
}
|
|
1566
|
+
})
|
|
1263
1567
|
})
|
|
1264
1568
|
});
|
|
1265
1569
|
`;
|
|
@@ -1274,7 +1578,7 @@ async function writeWorkflowSample(destPath, llmProvider) {
|
|
|
1274
1578
|
const { providerImport, modelItem } = getProviderImportAndModelItem(llmProvider);
|
|
1275
1579
|
const content = `${providerImport}
|
|
1276
1580
|
import { Agent } from '@mastra/core/agent';
|
|
1277
|
-
import {
|
|
1581
|
+
import { createStep, createWorkflow } from '@mastra/core/workflows';
|
|
1278
1582
|
import { z } from 'zod';
|
|
1279
1583
|
|
|
1280
1584
|
const llm = ${modelItem};
|
|
@@ -1327,80 +1631,106 @@ const agent = new Agent({
|
|
|
1327
1631
|
\`,
|
|
1328
1632
|
});
|
|
1329
1633
|
|
|
1330
|
-
const forecastSchema = z.
|
|
1331
|
-
z.
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
}),
|
|
1339
|
-
);
|
|
1634
|
+
const forecastSchema = z.object({
|
|
1635
|
+
date: z.string(),
|
|
1636
|
+
maxTemp: z.number(),
|
|
1637
|
+
minTemp: z.number(),
|
|
1638
|
+
precipitationChance: z.number(),
|
|
1639
|
+
condition: z.string(),
|
|
1640
|
+
location: z.string(),
|
|
1641
|
+
})
|
|
1340
1642
|
|
|
1341
|
-
|
|
1643
|
+
function getWeatherCondition(code: number): string {
|
|
1644
|
+
const conditions: Record<number, string> = {
|
|
1645
|
+
0: 'Clear sky',
|
|
1646
|
+
1: 'Mainly clear',
|
|
1647
|
+
2: 'Partly cloudy',
|
|
1648
|
+
3: 'Overcast',
|
|
1649
|
+
45: 'Foggy',
|
|
1650
|
+
48: 'Depositing rime fog',
|
|
1651
|
+
51: 'Light drizzle',
|
|
1652
|
+
53: 'Moderate drizzle',
|
|
1653
|
+
55: 'Dense drizzle',
|
|
1654
|
+
61: 'Slight rain',
|
|
1655
|
+
63: 'Moderate rain',
|
|
1656
|
+
65: 'Heavy rain',
|
|
1657
|
+
71: 'Slight snow fall',
|
|
1658
|
+
73: 'Moderate snow fall',
|
|
1659
|
+
75: 'Heavy snow fall',
|
|
1660
|
+
95: 'Thunderstorm',
|
|
1661
|
+
}
|
|
1662
|
+
return conditions[code] || 'Unknown'
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
const fetchWeather = createStep({
|
|
1342
1666
|
id: 'fetch-weather',
|
|
1343
1667
|
description: 'Fetches weather forecast for a given city',
|
|
1344
1668
|
inputSchema: z.object({
|
|
1345
1669
|
city: z.string().describe('The city to get the weather for'),
|
|
1346
1670
|
}),
|
|
1347
1671
|
outputSchema: forecastSchema,
|
|
1348
|
-
execute: async ({
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
if (!triggerData) {
|
|
1352
|
-
throw new Error('Trigger data not found');
|
|
1672
|
+
execute: async ({ inputData }) => {
|
|
1673
|
+
if (!inputData) {
|
|
1674
|
+
throw new Error('Input data not found');
|
|
1353
1675
|
}
|
|
1354
1676
|
|
|
1355
|
-
const geocodingUrl = \`https://geocoding-api.open-meteo.com/v1/search?name=\${encodeURIComponent(
|
|
1677
|
+
const geocodingUrl = \`https://geocoding-api.open-meteo.com/v1/search?name=\${encodeURIComponent(inputData.city)}&count=1\`;
|
|
1356
1678
|
const geocodingResponse = await fetch(geocodingUrl);
|
|
1357
1679
|
const geocodingData = (await geocodingResponse.json()) as {
|
|
1358
1680
|
results: { latitude: number; longitude: number; name: string }[];
|
|
1359
1681
|
};
|
|
1360
1682
|
|
|
1361
1683
|
if (!geocodingData.results?.[0]) {
|
|
1362
|
-
throw new Error(\`Location '\${
|
|
1684
|
+
throw new Error(\`Location '\${inputData.city}' not found\`);
|
|
1363
1685
|
}
|
|
1364
1686
|
|
|
1365
1687
|
const { latitude, longitude, name } = geocodingData.results[0];
|
|
1366
1688
|
|
|
1367
|
-
const weatherUrl = \`https://api.open-meteo.com/v1/forecast?latitude=\${latitude}&longitude=\${longitude}&
|
|
1689
|
+
const weatherUrl = \`https://api.open-meteo.com/v1/forecast?latitude=\${latitude}&longitude=\${longitude}¤t=precipitation,weathercode&timezone=auto,&hourly=precipitation_probability,temperature_2m\`;
|
|
1368
1690
|
const response = await fetch(weatherUrl);
|
|
1369
1691
|
const data = (await response.json()) as {
|
|
1370
|
-
|
|
1371
|
-
time: string
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1692
|
+
current: {
|
|
1693
|
+
time: string
|
|
1694
|
+
precipitation: number
|
|
1695
|
+
weathercode: number
|
|
1696
|
+
}
|
|
1697
|
+
hourly: {
|
|
1698
|
+
precipitation_probability: number[]
|
|
1699
|
+
temperature_2m: number[]
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1378
1702
|
|
|
1379
|
-
const forecast =
|
|
1380
|
-
date,
|
|
1381
|
-
maxTemp: data.
|
|
1382
|
-
minTemp: data.
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1703
|
+
const forecast = {
|
|
1704
|
+
date: new Date().toISOString(),
|
|
1705
|
+
maxTemp: Math.max(...data.hourly.temperature_2m),
|
|
1706
|
+
minTemp: Math.min(...data.hourly.temperature_2m),
|
|
1707
|
+
condition: getWeatherCondition(data.current.weathercode),
|
|
1708
|
+
precipitationChance: data.hourly.precipitation_probability.reduce(
|
|
1709
|
+
(acc, curr) => Math.max(acc, curr),
|
|
1710
|
+
0
|
|
1711
|
+
),
|
|
1712
|
+
}
|
|
1387
1713
|
|
|
1388
1714
|
return forecast;
|
|
1389
1715
|
},
|
|
1390
1716
|
});
|
|
1391
1717
|
|
|
1392
1718
|
|
|
1393
|
-
const planActivities =
|
|
1719
|
+
const planActivities = createStep({
|
|
1394
1720
|
id: 'plan-activities',
|
|
1395
1721
|
description: 'Suggests activities based on weather conditions',
|
|
1396
|
-
|
|
1397
|
-
|
|
1722
|
+
inputSchema: forecastSchema,
|
|
1723
|
+
outputSchema: z.object({
|
|
1724
|
+
activities: z.string(),
|
|
1725
|
+
}),
|
|
1726
|
+
execute: async ({ inputData }) => {
|
|
1727
|
+
const forecast = inputData
|
|
1398
1728
|
|
|
1399
|
-
if (!forecast
|
|
1400
|
-
throw new Error('Forecast data not found')
|
|
1729
|
+
if (!forecast) {
|
|
1730
|
+
throw new Error('Forecast data not found')
|
|
1401
1731
|
}
|
|
1402
1732
|
|
|
1403
|
-
const prompt = \`Based on the following weather forecast for \${forecast
|
|
1733
|
+
const prompt = \`Based on the following weather forecast for \${forecast.location}, suggest appropriate activities:
|
|
1404
1734
|
\${JSON.stringify(forecast, null, 2)}
|
|
1405
1735
|
\`;
|
|
1406
1736
|
|
|
@@ -1424,35 +1754,16 @@ const planActivities = new Step({
|
|
|
1424
1754
|
},
|
|
1425
1755
|
});
|
|
1426
1756
|
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
1: 'Mainly clear',
|
|
1431
|
-
2: 'Partly cloudy',
|
|
1432
|
-
3: 'Overcast',
|
|
1433
|
-
45: 'Foggy',
|
|
1434
|
-
48: 'Depositing rime fog',
|
|
1435
|
-
51: 'Light drizzle',
|
|
1436
|
-
53: 'Moderate drizzle',
|
|
1437
|
-
55: 'Dense drizzle',
|
|
1438
|
-
61: 'Slight rain',
|
|
1439
|
-
63: 'Moderate rain',
|
|
1440
|
-
65: 'Heavy rain',
|
|
1441
|
-
71: 'Slight snow fall',
|
|
1442
|
-
73: 'Moderate snow fall',
|
|
1443
|
-
75: 'Heavy snow fall',
|
|
1444
|
-
95: 'Thunderstorm',
|
|
1445
|
-
};
|
|
1446
|
-
return conditions[code] || 'Unknown';
|
|
1447
|
-
}
|
|
1448
|
-
|
|
1449
|
-
const weatherWorkflow = new Workflow({
|
|
1450
|
-
name: 'weather-workflow',
|
|
1451
|
-
triggerSchema: z.object({
|
|
1757
|
+
const weatherWorkflow = createWorkflow({
|
|
1758
|
+
id: 'weather-workflow',
|
|
1759
|
+
inputSchema: z.object({
|
|
1452
1760
|
city: z.string().describe('The city to get the weather for'),
|
|
1453
1761
|
}),
|
|
1762
|
+
outputSchema: z.object({
|
|
1763
|
+
activities: z.string(),
|
|
1764
|
+
})
|
|
1454
1765
|
})
|
|
1455
|
-
.
|
|
1766
|
+
.then(fetchWeather)
|
|
1456
1767
|
.then(planActivities);
|
|
1457
1768
|
|
|
1458
1769
|
weatherWorkflow.commit();
|
|
@@ -1492,7 +1803,7 @@ var writeIndexFile = async ({
|
|
|
1492
1803
|
addWorkflow
|
|
1493
1804
|
}) => {
|
|
1494
1805
|
const indexPath = dirPath + "/index.ts";
|
|
1495
|
-
const destPath =
|
|
1806
|
+
const destPath = path2.join(indexPath);
|
|
1496
1807
|
try {
|
|
1497
1808
|
await fs4.writeFile(destPath, "");
|
|
1498
1809
|
const filteredExports = [
|
|
@@ -1514,10 +1825,10 @@ export const mastra = new Mastra()
|
|
|
1514
1825
|
destPath,
|
|
1515
1826
|
`
|
|
1516
1827
|
import { Mastra } from '@mastra/core/mastra';
|
|
1517
|
-
import {
|
|
1828
|
+
import { PinoLogger } from '@mastra/loggers';
|
|
1518
1829
|
import { LibSQLStore } from '@mastra/libsql';
|
|
1519
|
-
${addWorkflow ? `import { weatherWorkflow } from './workflows';` : ""}
|
|
1520
|
-
${addAgent ? `import { weatherAgent } from './agents';` : ""}
|
|
1830
|
+
${addWorkflow ? `import { weatherWorkflow } from './workflows/weather-workflow';` : ""}
|
|
1831
|
+
${addAgent ? `import { weatherAgent } from './agents/weather-agent';` : ""}
|
|
1521
1832
|
|
|
1522
1833
|
export const mastra = new Mastra({
|
|
1523
1834
|
${filteredExports.join("\n ")}
|
|
@@ -1525,7 +1836,7 @@ export const mastra = new Mastra({
|
|
|
1525
1836
|
// stores telemetry, evals, ... into memory storage, if it needs to persist, change to file:../mastra.db
|
|
1526
1837
|
url: ":memory:",
|
|
1527
1838
|
}),
|
|
1528
|
-
logger:
|
|
1839
|
+
logger: new PinoLogger({
|
|
1529
1840
|
name: 'Mastra',
|
|
1530
1841
|
level: 'info',
|
|
1531
1842
|
}),
|
|
@@ -1561,11 +1872,13 @@ var writeAPIKey = async ({
|
|
|
1561
1872
|
apiKey = "your-api-key"
|
|
1562
1873
|
}) => {
|
|
1563
1874
|
const key = await getAPIKey(provider);
|
|
1564
|
-
|
|
1875
|
+
const escapedKey = shellQuote.quote([key]);
|
|
1876
|
+
const escapedApiKey = shellQuote.quote([apiKey]);
|
|
1877
|
+
await exec(`echo ${escapedKey}=${escapedApiKey} >> .env`);
|
|
1565
1878
|
};
|
|
1566
1879
|
var createMastraDir = async (directory) => {
|
|
1567
1880
|
let dir = directory.trim().split("/").filter((item) => item !== "");
|
|
1568
|
-
const dirPath =
|
|
1881
|
+
const dirPath = path2.join(process.cwd(), ...dir, "mastra");
|
|
1569
1882
|
try {
|
|
1570
1883
|
await fs4.access(dirPath);
|
|
1571
1884
|
return { ok: false };
|
|
@@ -1575,7 +1888,7 @@ var createMastraDir = async (directory) => {
|
|
|
1575
1888
|
}
|
|
1576
1889
|
};
|
|
1577
1890
|
var writeCodeSample = async (dirPath, component, llmProvider, importComponents) => {
|
|
1578
|
-
const destPath = dirPath + `/${component}/
|
|
1891
|
+
const destPath = dirPath + `/${component}/weather-${component.slice(0, -1)}.ts`;
|
|
1579
1892
|
try {
|
|
1580
1893
|
await writeCodeSampleForComponents(llmProvider, component, destPath, importComponents);
|
|
1581
1894
|
} catch (err) {
|
|
@@ -1639,6 +1952,7 @@ var interactivePrompt = async () => {
|
|
|
1639
1952
|
configureEditorWithDocsMCP: async () => {
|
|
1640
1953
|
const windsurfIsAlreadyInstalled = await globalMCPIsAlreadyInstalled(`windsurf`);
|
|
1641
1954
|
const cursorIsAlreadyInstalled = await globalMCPIsAlreadyInstalled(`cursor`);
|
|
1955
|
+
const vscodeIsAlreadyInstalled = await globalMCPIsAlreadyInstalled(`vscode`);
|
|
1642
1956
|
const editor = await le({
|
|
1643
1957
|
message: `Make your AI IDE into a Mastra expert? (installs Mastra docs MCP server)`,
|
|
1644
1958
|
options: [
|
|
@@ -1657,6 +1971,11 @@ var interactivePrompt = async () => {
|
|
|
1657
1971
|
value: "windsurf",
|
|
1658
1972
|
label: "Windsurf",
|
|
1659
1973
|
hint: windsurfIsAlreadyInstalled ? `Already installed` : void 0
|
|
1974
|
+
},
|
|
1975
|
+
{
|
|
1976
|
+
value: "vscode",
|
|
1977
|
+
label: "VSCode",
|
|
1978
|
+
hint: vscodeIsAlreadyInstalled ? `Already installed` : void 0
|
|
1660
1979
|
}
|
|
1661
1980
|
]
|
|
1662
1981
|
});
|
|
@@ -1666,6 +1985,11 @@ var interactivePrompt = async () => {
|
|
|
1666
1985
|
Windsurf is already installed, skipping.`);
|
|
1667
1986
|
return void 0;
|
|
1668
1987
|
}
|
|
1988
|
+
if (editor === `vscode` && vscodeIsAlreadyInstalled) {
|
|
1989
|
+
v.message(`
|
|
1990
|
+
VSCode is already installed, skipping.`);
|
|
1991
|
+
return void 0;
|
|
1992
|
+
}
|
|
1669
1993
|
if (editor === `cursor`) {
|
|
1670
1994
|
v.message(
|
|
1671
1995
|
`
|
|
@@ -1755,6 +2079,10 @@ var init = async ({
|
|
|
1755
2079
|
if (needsMemory) {
|
|
1756
2080
|
await depService.installPackages(["@mastra/memory"]);
|
|
1757
2081
|
}
|
|
2082
|
+
const needsLoggers = await depService.checkDependencies(["@mastra/loggers"]) !== `ok`;
|
|
2083
|
+
if (needsLoggers) {
|
|
2084
|
+
await depService.installPackages(["@mastra/loggers"]);
|
|
2085
|
+
}
|
|
1758
2086
|
}
|
|
1759
2087
|
const key = await getAPIKey(llmProvider || "openai");
|
|
1760
2088
|
const aiSdkPackage = getAISDKPackage(llmProvider);
|
|
@@ -1774,7 +2102,7 @@ var init = async ({
|
|
|
1774
2102
|
${color2.green("Mastra initialized successfully!")}
|
|
1775
2103
|
|
|
1776
2104
|
Add your ${color2.cyan(key)} as an environment variable
|
|
1777
|
-
in your ${color2.cyan(".env
|
|
2105
|
+
in your ${color2.cyan(".env")} file
|
|
1778
2106
|
`);
|
|
1779
2107
|
} else {
|
|
1780
2108
|
me(`
|
|
@@ -1864,6 +2192,7 @@ var createMastraProject = async ({
|
|
|
1864
2192
|
s2.message("Creating project");
|
|
1865
2193
|
await exec3(`npm init -y`);
|
|
1866
2194
|
await exec3(`npm pkg set type="module"`);
|
|
2195
|
+
await exec3(`npm pkg set engines.node=">=20.9.0"`);
|
|
1867
2196
|
const depsService = new DepsService();
|
|
1868
2197
|
await depsService.addScriptsToPackageJson({
|
|
1869
2198
|
dev: "mastra dev",
|
|
@@ -1935,23 +2264,25 @@ var create = async (args2) => {
|
|
|
1935
2264
|
components,
|
|
1936
2265
|
llmProvider,
|
|
1937
2266
|
addExample,
|
|
1938
|
-
llmApiKey
|
|
2267
|
+
llmApiKey,
|
|
2268
|
+
configureEditorWithDocsMCP: args2.mcpServer
|
|
1939
2269
|
});
|
|
1940
2270
|
postCreate({ projectName });
|
|
1941
2271
|
};
|
|
1942
2272
|
var postCreate = ({ projectName }) => {
|
|
2273
|
+
const packageManager = getPackageManager();
|
|
1943
2274
|
ge(`
|
|
1944
2275
|
${color2.green("To start your project:")}
|
|
1945
2276
|
|
|
1946
2277
|
${color2.cyan("cd")} ${projectName}
|
|
1947
|
-
${color2.cyan(
|
|
2278
|
+
${color2.cyan(`${packageManager} run dev`)}
|
|
1948
2279
|
`);
|
|
1949
2280
|
};
|
|
1950
2281
|
|
|
1951
2282
|
async function getPackageVersion() {
|
|
1952
2283
|
const __filename = fileURLToPath(import.meta.url);
|
|
1953
2284
|
const __dirname = dirname(__filename);
|
|
1954
|
-
const pkgJsonPath =
|
|
2285
|
+
const pkgJsonPath = path2.join(__dirname, "..", "package.json");
|
|
1955
2286
|
const content = await fsExtra.readJSON(pkgJsonPath);
|
|
1956
2287
|
return content.version;
|
|
1957
2288
|
}
|
|
@@ -1960,7 +2291,7 @@ async function getCreateVersionTag() {
|
|
|
1960
2291
|
const pkgPath = fileURLToPath(import.meta.resolve("create-mastra/package.json"));
|
|
1961
2292
|
const json = await fsExtra.readJSON(pkgPath);
|
|
1962
2293
|
const { stdout } = await execa("npm", ["dist-tag", "create-mastra"]);
|
|
1963
|
-
const tagLine = stdout.split("\n").find((distLine) => distLine.
|
|
2294
|
+
const tagLine = stdout.split("\n").find((distLine) => distLine.endsWith(`: ${json.version}`));
|
|
1964
2295
|
const tag = tagLine ? tagLine.split(":")[0].trim() : "latest";
|
|
1965
2296
|
return tag;
|
|
1966
2297
|
} catch {
|
|
@@ -1989,16 +2320,17 @@ program.version(`${version}`, "-v, --version").description(`create-mastra ${vers
|
|
|
1989
2320
|
program.name("create-mastra").description("Create a new Mastra project").argument("[project-name]", "Directory name of the project").option(
|
|
1990
2321
|
"-p, --project-name <string>",
|
|
1991
2322
|
"Project name that will be used in package.json and as the project directory name."
|
|
1992
|
-
).option("--default", "Quick start with defaults(src, OpenAI, no 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/)").action(async (projectNameArg, args) => {
|
|
2323
|
+
).option("--default", "Quick start with defaults(src, OpenAI, no 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) => {
|
|
1993
2324
|
const projectName = projectNameArg || args.projectName;
|
|
1994
2325
|
const timeout = args?.timeout ? args?.timeout === true ? 6e4 : parseInt(args?.timeout, 10) : void 0;
|
|
1995
2326
|
if (args.default) {
|
|
1996
2327
|
await create({
|
|
1997
2328
|
components: ["agents", "tools", "workflows"],
|
|
1998
2329
|
llmProvider: "openai",
|
|
1999
|
-
addExample:
|
|
2330
|
+
addExample: true,
|
|
2000
2331
|
createVersionTag,
|
|
2001
|
-
timeout
|
|
2332
|
+
timeout,
|
|
2333
|
+
mcpServer: args.mcp
|
|
2002
2334
|
});
|
|
2003
2335
|
return;
|
|
2004
2336
|
}
|
|
@@ -2010,7 +2342,8 @@ program.name("create-mastra").description("Create a new Mastra project").argumen
|
|
|
2010
2342
|
createVersionTag,
|
|
2011
2343
|
timeout,
|
|
2012
2344
|
projectName,
|
|
2013
|
-
directory: args.dir
|
|
2345
|
+
directory: args.dir,
|
|
2346
|
+
mcpServer: args.mcp
|
|
2014
2347
|
});
|
|
2015
2348
|
});
|
|
2016
2349
|
program.parse(process.argv);
|