create-mastra 0.3.4-alpha.0 → 0.3.4-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +415 -138
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -17,7 +17,6 @@ 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';
|
|
@@ -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.transports?.default) {
|
|
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;
|
|
@@ -1208,7 +1479,7 @@ var FileService = class {
|
|
|
1208
1479
|
fs3__default__default.writeFileSync(filePath, fileContent);
|
|
1209
1480
|
}
|
|
1210
1481
|
};
|
|
1211
|
-
|
|
1482
|
+
new PinoLogger({
|
|
1212
1483
|
name: "Mastra CLI",
|
|
1213
1484
|
level: "debug"
|
|
1214
1485
|
});
|
|
@@ -1234,7 +1505,7 @@ var getProviderImportAndModelItem = (llmProvider) => {
|
|
|
1234
1505
|
let modelItem = "";
|
|
1235
1506
|
if (llmProvider === "openai") {
|
|
1236
1507
|
providerImport = `import { openai } from '${getAISDKPackage(llmProvider)}';`;
|
|
1237
|
-
modelItem = `openai('gpt-4o')`;
|
|
1508
|
+
modelItem = `openai('gpt-4o-mini')`;
|
|
1238
1509
|
} else if (llmProvider === "anthropic") {
|
|
1239
1510
|
providerImport = `import { anthropic } from '${getAISDKPackage(llmProvider)}';`;
|
|
1240
1511
|
modelItem = `anthropic('claude-3-5-sonnet-20241022')`;
|
|
@@ -1269,7 +1540,7 @@ ${providerImport}
|
|
|
1269
1540
|
import { Agent } from '@mastra/core/agent';
|
|
1270
1541
|
import { Memory } from '@mastra/memory';
|
|
1271
1542
|
import { LibSQLStore } from '@mastra/libsql';
|
|
1272
|
-
${addExampleTool ? `import { weatherTool } from '../tools';` : ""}
|
|
1543
|
+
${addExampleTool ? `import { weatherTool } from '../tools/weather-tool';` : ""}
|
|
1273
1544
|
|
|
1274
1545
|
export const weatherAgent = new Agent({
|
|
1275
1546
|
name: 'Weather Agent',
|
|
@@ -1279,14 +1550,7 @@ export const weatherAgent = new Agent({
|
|
|
1279
1550
|
memory: new Memory({
|
|
1280
1551
|
storage: new LibSQLStore({
|
|
1281
1552
|
url: "file:../mastra.db", // path is relative to the .mastra/output directory
|
|
1282
|
-
})
|
|
1283
|
-
options: {
|
|
1284
|
-
lastMessages: 10,
|
|
1285
|
-
semanticRecall: false,
|
|
1286
|
-
threads: {
|
|
1287
|
-
generateTitle: false
|
|
1288
|
-
}
|
|
1289
|
-
}
|
|
1553
|
+
})
|
|
1290
1554
|
})
|
|
1291
1555
|
});
|
|
1292
1556
|
`;
|
|
@@ -1301,7 +1565,7 @@ async function writeWorkflowSample(destPath, llmProvider) {
|
|
|
1301
1565
|
const { providerImport, modelItem } = getProviderImportAndModelItem(llmProvider);
|
|
1302
1566
|
const content = `${providerImport}
|
|
1303
1567
|
import { Agent } from '@mastra/core/agent';
|
|
1304
|
-
import {
|
|
1568
|
+
import { createStep, createWorkflow } from '@mastra/core/workflows';
|
|
1305
1569
|
import { z } from 'zod';
|
|
1306
1570
|
|
|
1307
1571
|
const llm = ${modelItem};
|
|
@@ -1354,80 +1618,106 @@ const agent = new Agent({
|
|
|
1354
1618
|
\`,
|
|
1355
1619
|
});
|
|
1356
1620
|
|
|
1357
|
-
const forecastSchema = z.
|
|
1358
|
-
z.
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
}),
|
|
1366
|
-
);
|
|
1621
|
+
const forecastSchema = z.object({
|
|
1622
|
+
date: z.string(),
|
|
1623
|
+
maxTemp: z.number(),
|
|
1624
|
+
minTemp: z.number(),
|
|
1625
|
+
precipitationChance: z.number(),
|
|
1626
|
+
condition: z.string(),
|
|
1627
|
+
location: z.string(),
|
|
1628
|
+
})
|
|
1367
1629
|
|
|
1368
|
-
|
|
1630
|
+
function getWeatherCondition(code: number): string {
|
|
1631
|
+
const conditions: Record<number, string> = {
|
|
1632
|
+
0: 'Clear sky',
|
|
1633
|
+
1: 'Mainly clear',
|
|
1634
|
+
2: 'Partly cloudy',
|
|
1635
|
+
3: 'Overcast',
|
|
1636
|
+
45: 'Foggy',
|
|
1637
|
+
48: 'Depositing rime fog',
|
|
1638
|
+
51: 'Light drizzle',
|
|
1639
|
+
53: 'Moderate drizzle',
|
|
1640
|
+
55: 'Dense drizzle',
|
|
1641
|
+
61: 'Slight rain',
|
|
1642
|
+
63: 'Moderate rain',
|
|
1643
|
+
65: 'Heavy rain',
|
|
1644
|
+
71: 'Slight snow fall',
|
|
1645
|
+
73: 'Moderate snow fall',
|
|
1646
|
+
75: 'Heavy snow fall',
|
|
1647
|
+
95: 'Thunderstorm',
|
|
1648
|
+
}
|
|
1649
|
+
return conditions[code] || 'Unknown'
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
const fetchWeather = createStep({
|
|
1369
1653
|
id: 'fetch-weather',
|
|
1370
1654
|
description: 'Fetches weather forecast for a given city',
|
|
1371
1655
|
inputSchema: z.object({
|
|
1372
1656
|
city: z.string().describe('The city to get the weather for'),
|
|
1373
1657
|
}),
|
|
1374
1658
|
outputSchema: forecastSchema,
|
|
1375
|
-
execute: async ({
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
if (!triggerData) {
|
|
1379
|
-
throw new Error('Trigger data not found');
|
|
1659
|
+
execute: async ({ inputData }) => {
|
|
1660
|
+
if (!inputData) {
|
|
1661
|
+
throw new Error('Input data not found');
|
|
1380
1662
|
}
|
|
1381
1663
|
|
|
1382
|
-
const geocodingUrl = \`https://geocoding-api.open-meteo.com/v1/search?name=\${encodeURIComponent(
|
|
1664
|
+
const geocodingUrl = \`https://geocoding-api.open-meteo.com/v1/search?name=\${encodeURIComponent(inputData.city)}&count=1\`;
|
|
1383
1665
|
const geocodingResponse = await fetch(geocodingUrl);
|
|
1384
1666
|
const geocodingData = (await geocodingResponse.json()) as {
|
|
1385
1667
|
results: { latitude: number; longitude: number; name: string }[];
|
|
1386
1668
|
};
|
|
1387
1669
|
|
|
1388
1670
|
if (!geocodingData.results?.[0]) {
|
|
1389
|
-
throw new Error(\`Location '\${
|
|
1671
|
+
throw new Error(\`Location '\${inputData.city}' not found\`);
|
|
1390
1672
|
}
|
|
1391
1673
|
|
|
1392
1674
|
const { latitude, longitude, name } = geocodingData.results[0];
|
|
1393
1675
|
|
|
1394
|
-
const weatherUrl = \`https://api.open-meteo.com/v1/forecast?latitude=\${latitude}&longitude=\${longitude}&
|
|
1676
|
+
const weatherUrl = \`https://api.open-meteo.com/v1/forecast?latitude=\${latitude}&longitude=\${longitude}¤t=precipitation,weathercode&timezone=auto,&hourly=precipitation_probability,temperature_2m\`;
|
|
1395
1677
|
const response = await fetch(weatherUrl);
|
|
1396
1678
|
const data = (await response.json()) as {
|
|
1397
|
-
|
|
1398
|
-
time: string
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1679
|
+
current: {
|
|
1680
|
+
time: string
|
|
1681
|
+
precipitation: number
|
|
1682
|
+
weathercode: number
|
|
1683
|
+
}
|
|
1684
|
+
hourly: {
|
|
1685
|
+
precipitation_probability: number[]
|
|
1686
|
+
temperature_2m: number[]
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1405
1689
|
|
|
1406
|
-
const forecast =
|
|
1407
|
-
date,
|
|
1408
|
-
maxTemp: data.
|
|
1409
|
-
minTemp: data.
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1690
|
+
const forecast = {
|
|
1691
|
+
date: new Date().toISOString(),
|
|
1692
|
+
maxTemp: Math.max(...data.hourly.temperature_2m),
|
|
1693
|
+
minTemp: Math.min(...data.hourly.temperature_2m),
|
|
1694
|
+
condition: getWeatherCondition(data.current.weathercode),
|
|
1695
|
+
precipitationChance: data.hourly.precipitation_probability.reduce(
|
|
1696
|
+
(acc, curr) => Math.max(acc, curr),
|
|
1697
|
+
0
|
|
1698
|
+
),
|
|
1699
|
+
}
|
|
1414
1700
|
|
|
1415
1701
|
return forecast;
|
|
1416
1702
|
},
|
|
1417
1703
|
});
|
|
1418
1704
|
|
|
1419
1705
|
|
|
1420
|
-
const planActivities =
|
|
1706
|
+
const planActivities = createStep({
|
|
1421
1707
|
id: 'plan-activities',
|
|
1422
1708
|
description: 'Suggests activities based on weather conditions',
|
|
1423
|
-
|
|
1424
|
-
|
|
1709
|
+
inputSchema: forecastSchema,
|
|
1710
|
+
outputSchema: z.object({
|
|
1711
|
+
activities: z.string(),
|
|
1712
|
+
}),
|
|
1713
|
+
execute: async ({ inputData }) => {
|
|
1714
|
+
const forecast = inputData
|
|
1425
1715
|
|
|
1426
|
-
if (!forecast
|
|
1427
|
-
throw new Error('Forecast data not found')
|
|
1716
|
+
if (!forecast) {
|
|
1717
|
+
throw new Error('Forecast data not found')
|
|
1428
1718
|
}
|
|
1429
1719
|
|
|
1430
|
-
const prompt = \`Based on the following weather forecast for \${forecast
|
|
1720
|
+
const prompt = \`Based on the following weather forecast for \${forecast.location}, suggest appropriate activities:
|
|
1431
1721
|
\${JSON.stringify(forecast, null, 2)}
|
|
1432
1722
|
\`;
|
|
1433
1723
|
|
|
@@ -1451,35 +1741,16 @@ const planActivities = new Step({
|
|
|
1451
1741
|
},
|
|
1452
1742
|
});
|
|
1453
1743
|
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
1: 'Mainly clear',
|
|
1458
|
-
2: 'Partly cloudy',
|
|
1459
|
-
3: 'Overcast',
|
|
1460
|
-
45: 'Foggy',
|
|
1461
|
-
48: 'Depositing rime fog',
|
|
1462
|
-
51: 'Light drizzle',
|
|
1463
|
-
53: 'Moderate drizzle',
|
|
1464
|
-
55: 'Dense drizzle',
|
|
1465
|
-
61: 'Slight rain',
|
|
1466
|
-
63: 'Moderate rain',
|
|
1467
|
-
65: 'Heavy rain',
|
|
1468
|
-
71: 'Slight snow fall',
|
|
1469
|
-
73: 'Moderate snow fall',
|
|
1470
|
-
75: 'Heavy snow fall',
|
|
1471
|
-
95: 'Thunderstorm',
|
|
1472
|
-
};
|
|
1473
|
-
return conditions[code] || 'Unknown';
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
|
-
const weatherWorkflow = new Workflow({
|
|
1477
|
-
name: 'weather-workflow',
|
|
1478
|
-
triggerSchema: z.object({
|
|
1744
|
+
const weatherWorkflow = createWorkflow({
|
|
1745
|
+
id: 'weather-workflow',
|
|
1746
|
+
inputSchema: z.object({
|
|
1479
1747
|
city: z.string().describe('The city to get the weather for'),
|
|
1480
1748
|
}),
|
|
1749
|
+
outputSchema: z.object({
|
|
1750
|
+
activities: z.string(),
|
|
1751
|
+
})
|
|
1481
1752
|
})
|
|
1482
|
-
.
|
|
1753
|
+
.then(fetchWeather)
|
|
1483
1754
|
.then(planActivities);
|
|
1484
1755
|
|
|
1485
1756
|
weatherWorkflow.commit();
|
|
@@ -1541,10 +1812,10 @@ export const mastra = new Mastra()
|
|
|
1541
1812
|
destPath,
|
|
1542
1813
|
`
|
|
1543
1814
|
import { Mastra } from '@mastra/core/mastra';
|
|
1544
|
-
import {
|
|
1815
|
+
import { PinoLogger } from '@mastra/loggers';
|
|
1545
1816
|
import { LibSQLStore } from '@mastra/libsql';
|
|
1546
|
-
${addWorkflow ? `import { weatherWorkflow } from './workflows';` : ""}
|
|
1547
|
-
${addAgent ? `import { weatherAgent } from './agents';` : ""}
|
|
1817
|
+
${addWorkflow ? `import { weatherWorkflow } from './workflows/weather-workflow';` : ""}
|
|
1818
|
+
${addAgent ? `import { weatherAgent } from './agents/weather-agent';` : ""}
|
|
1548
1819
|
|
|
1549
1820
|
export const mastra = new Mastra({
|
|
1550
1821
|
${filteredExports.join("\n ")}
|
|
@@ -1552,7 +1823,7 @@ export const mastra = new Mastra({
|
|
|
1552
1823
|
// stores telemetry, evals, ... into memory storage, if it needs to persist, change to file:../mastra.db
|
|
1553
1824
|
url: ":memory:",
|
|
1554
1825
|
}),
|
|
1555
|
-
logger:
|
|
1826
|
+
logger: new PinoLogger({
|
|
1556
1827
|
name: 'Mastra',
|
|
1557
1828
|
level: 'info',
|
|
1558
1829
|
}),
|
|
@@ -1588,7 +1859,9 @@ var writeAPIKey = async ({
|
|
|
1588
1859
|
apiKey = "your-api-key"
|
|
1589
1860
|
}) => {
|
|
1590
1861
|
const key = await getAPIKey(provider);
|
|
1591
|
-
|
|
1862
|
+
const escapedKey = shellQuote.quote([key]);
|
|
1863
|
+
const escapedApiKey = shellQuote.quote([apiKey]);
|
|
1864
|
+
await exec(`echo ${escapedKey}=${escapedApiKey} >> .env`);
|
|
1592
1865
|
};
|
|
1593
1866
|
var createMastraDir = async (directory) => {
|
|
1594
1867
|
let dir = directory.trim().split("/").filter((item) => item !== "");
|
|
@@ -1602,7 +1875,7 @@ var createMastraDir = async (directory) => {
|
|
|
1602
1875
|
}
|
|
1603
1876
|
};
|
|
1604
1877
|
var writeCodeSample = async (dirPath, component, llmProvider, importComponents) => {
|
|
1605
|
-
const destPath = dirPath + `/${component}/
|
|
1878
|
+
const destPath = dirPath + `/${component}/weather-${component.slice(0, -1)}.ts`;
|
|
1606
1879
|
try {
|
|
1607
1880
|
await writeCodeSampleForComponents(llmProvider, component, destPath, importComponents);
|
|
1608
1881
|
} catch (err) {
|
|
@@ -1782,6 +2055,10 @@ var init = async ({
|
|
|
1782
2055
|
if (needsMemory) {
|
|
1783
2056
|
await depService.installPackages(["@mastra/memory"]);
|
|
1784
2057
|
}
|
|
2058
|
+
const needsLoggers = await depService.checkDependencies(["@mastra/loggers"]) !== `ok`;
|
|
2059
|
+
if (needsLoggers) {
|
|
2060
|
+
await depService.installPackages(["@mastra/loggers"]);
|
|
2061
|
+
}
|
|
1785
2062
|
}
|
|
1786
2063
|
const key = await getAPIKey(llmProvider || "openai");
|
|
1787
2064
|
const aiSdkPackage = getAISDKPackage(llmProvider);
|
|
@@ -1801,7 +2078,7 @@ var init = async ({
|
|
|
1801
2078
|
${color2.green("Mastra initialized successfully!")}
|
|
1802
2079
|
|
|
1803
2080
|
Add your ${color2.cyan(key)} as an environment variable
|
|
1804
|
-
in your ${color2.cyan(".env
|
|
2081
|
+
in your ${color2.cyan(".env")} file
|
|
1805
2082
|
`);
|
|
1806
2083
|
} else {
|
|
1807
2084
|
me(`
|
|
@@ -1990,7 +2267,7 @@ async function getCreateVersionTag() {
|
|
|
1990
2267
|
const pkgPath = fileURLToPath(import.meta.resolve("create-mastra/package.json"));
|
|
1991
2268
|
const json = await fsExtra.readJSON(pkgPath);
|
|
1992
2269
|
const { stdout } = await execa("npm", ["dist-tag", "create-mastra"]);
|
|
1993
|
-
const tagLine = stdout.split("\n").find((distLine) => distLine.
|
|
2270
|
+
const tagLine = stdout.split("\n").find((distLine) => distLine.endsWith(`: ${json.version}`));
|
|
1994
2271
|
const tag = tagLine ? tagLine.split(":")[0].trim() : "latest";
|
|
1995
2272
|
return tag;
|
|
1996
2273
|
} catch {
|