create-mastra 0.0.0-storage-20250225005900 → 0.0.0-taofeeqInngest-20250603090617
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/{LICENSE → LICENSE.md} +3 -1
- package/README.md +1 -2
- package/dist/index.js +812 -265
- package/dist/index.js.map +1 -1
- package/dist/templates/dev.entry.js +13 -12
- package/package.json +17 -16
- package/dist/starter-files/workflow.ts +0 -182
- package/starter-files/config.ts +0 -28
- package/starter-files/mastra-pg.docker-compose.yaml +0 -15
- package/starter-files/tools.ts +0 -95
- package/starter-files/workflow.ts +0 -183
package/dist/index.js
CHANGED
|
@@ -4,26 +4,25 @@ 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
|
|
8
|
-
import { PostHog } from 'posthog-node';
|
|
7
|
+
import path2, { dirname } from 'node:path';
|
|
9
8
|
import { fileURLToPath } from 'node:url';
|
|
9
|
+
import { PostHog } from 'posthog-node';
|
|
10
10
|
import h, { stdin, stdout } from 'node:process';
|
|
11
11
|
import * as f from 'node:readline';
|
|
12
12
|
import f__default from 'node:readline';
|
|
13
13
|
import tty, { WriteStream } from 'node:tty';
|
|
14
14
|
import child_process from 'node:child_process';
|
|
15
15
|
import util from 'node:util';
|
|
16
|
-
import prettier from 'prettier';
|
|
17
|
-
import fsExtra3 from 'fs-extra/esm';
|
|
18
16
|
import fs4 from 'node:fs/promises';
|
|
19
17
|
import { execa } from 'execa';
|
|
18
|
+
import fsExtra3, { readJSON, ensureFile, writeJSON } from 'fs-extra/esm';
|
|
19
|
+
import prettier from 'prettier';
|
|
20
20
|
import pino from 'pino';
|
|
21
21
|
import pretty from 'pino-pretty';
|
|
22
|
-
import { Transform } from 'node:stream';
|
|
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,13 +34,13 @@ 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"));
|
|
42
41
|
this.distinctId = distinctId;
|
|
43
42
|
this.sessionId = sessionId;
|
|
44
|
-
} catch
|
|
43
|
+
} catch {
|
|
45
44
|
this.sessionId = randomUUID();
|
|
46
45
|
this.distinctId = this.getDistinctId();
|
|
47
46
|
}
|
|
@@ -63,15 +62,16 @@ var PosthogAnalytics = class {
|
|
|
63
62
|
}
|
|
64
63
|
writeCliConfig({ distinctId, sessionId }) {
|
|
65
64
|
try {
|
|
66
|
-
writeFileSync(
|
|
67
|
-
} catch
|
|
65
|
+
writeFileSync(path2.join(__dirname, "mastra-cli.json"), JSON.stringify({ distinctId, sessionId }));
|
|
66
|
+
} catch {
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
69
|
initializePostHog(apiKey, host) {
|
|
71
70
|
this.client = new PostHog(apiKey, {
|
|
72
71
|
host,
|
|
73
72
|
flushAt: 1,
|
|
74
|
-
flushInterval: 0
|
|
73
|
+
flushInterval: 0,
|
|
74
|
+
disableGeoip: false
|
|
75
75
|
});
|
|
76
76
|
this.captureSessionStart();
|
|
77
77
|
process.on("exit", () => {
|
|
@@ -80,7 +80,7 @@ var PosthogAnalytics = class {
|
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
isTelemetryEnabled() {
|
|
83
|
-
if (process.env.
|
|
83
|
+
if (process.env.MASTRA_TELEMETRY_DISABLED) {
|
|
84
84
|
return false;
|
|
85
85
|
}
|
|
86
86
|
return true;
|
|
@@ -135,17 +135,19 @@ var PosthogAnalytics = class {
|
|
|
135
135
|
event: "cli_command",
|
|
136
136
|
properties: {
|
|
137
137
|
...this.getSystemProperties(),
|
|
138
|
-
...commandData
|
|
138
|
+
...commandData,
|
|
139
|
+
origin: options?.origin || "oss"
|
|
139
140
|
}
|
|
140
141
|
});
|
|
141
|
-
} catch
|
|
142
|
+
} catch {
|
|
142
143
|
}
|
|
143
144
|
}
|
|
144
145
|
// Helper method to wrap command execution with timing
|
|
145
146
|
async trackCommandExecution({
|
|
146
147
|
command,
|
|
147
148
|
args,
|
|
148
|
-
execution
|
|
149
|
+
execution,
|
|
150
|
+
origin
|
|
149
151
|
}) {
|
|
150
152
|
const startTime = process.hrtime();
|
|
151
153
|
try {
|
|
@@ -156,7 +158,8 @@ var PosthogAnalytics = class {
|
|
|
156
158
|
command,
|
|
157
159
|
args,
|
|
158
160
|
durationMs,
|
|
159
|
-
status: "success"
|
|
161
|
+
status: "success",
|
|
162
|
+
origin
|
|
160
163
|
});
|
|
161
164
|
return result;
|
|
162
165
|
} catch (error) {
|
|
@@ -167,7 +170,8 @@ var PosthogAnalytics = class {
|
|
|
167
170
|
args,
|
|
168
171
|
durationMs,
|
|
169
172
|
status: "error",
|
|
170
|
-
error: error instanceof Error ? error.message : String(error)
|
|
173
|
+
error: error instanceof Error ? error.message : String(error),
|
|
174
|
+
origin
|
|
171
175
|
});
|
|
172
176
|
throw error;
|
|
173
177
|
}
|
|
@@ -179,7 +183,7 @@ var PosthogAnalytics = class {
|
|
|
179
183
|
}
|
|
180
184
|
try {
|
|
181
185
|
await this.client.shutdown();
|
|
182
|
-
} catch
|
|
186
|
+
} catch {
|
|
183
187
|
}
|
|
184
188
|
}
|
|
185
189
|
};
|
|
@@ -352,14 +356,14 @@ function q({onlyFirst:e=false}={}){const F=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(
|
|
|
352
356
|
`).map(t=>oD(t,u,F)).join(`
|
|
353
357
|
`)}var nD=Object.defineProperty,aD=(e,u,F)=>u in e?nD(e,u,{enumerable:true,configurable:true,writable:true,value:F}):e[u]=F,a$1=(e,u,F)=>(aD(e,typeof u!="symbol"?u+"":u,F),F);function hD(e,u){if(e===u)return;const F=e.split(`
|
|
354
358
|
`),t=u.split(`
|
|
355
|
-
`),s=[];for(let C=0;C<Math.max(F.length,t.length);C++)F[C]!==t[C]&&s.push(C);return s}const V$1=Symbol("clack:cancel");function lD(e){return e===V$1}function v(e,u){e.isTTY&&e.setRawMode(u);}const z=new Map([["k","up"],["j","down"],["h","left"],["l","right"]]),xD=new Set(["up","down","left","right","space","enter"]);class x{constructor({render:u,input:F=stdin,output:t=stdout,...s},C=true){a$1(this,"input"),a$1(this,"output"),a$1(this,"rl"),a$1(this,"opts"),a$1(this,"_track",false),a$1(this,"_render"),a$1(this,"_cursor",0),a$1(this,"state","initial"),a$1(this,"value"),a$1(this,"error",""),a$1(this,"subscribers",new Map),a$1(this,"_prevFrame",""),this.opts=s,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=u.bind(this),this._track=C,this.input=F,this.output=t;}prompt(){const u=new WriteStream(0);return u._write=(F,t,s)=>{this._track&&(this.value=this.rl.line.replace(/\t/g,""),this._cursor=this.rl.cursor,this.emit("value",this.value)),s();},this.input.pipe(u),this.rl=f__default.createInterface({input:this.input,output:u,tabSize:2,prompt:"",escapeCodeTimeout:50}),f__default.emitKeypressEvents(this.input,this.rl),this.rl.prompt(),this.opts.initialValue!==void 0&&this._track&&this.rl.write(this.opts.initialValue),this.input.on("keypress",this.onKeypress),v(this.input,true),this.output.on("resize",this.render),this.render(),new Promise((F,t)=>{this.once("submit",()=>{this.output.write(srcExports.cursor.show),this.output.off("resize",this.render),v(this.input,false),F(this.value);}),this.once("cancel",()=>{this.output.write(srcExports.cursor.show),this.output.off("resize",this.render),v(this.input,false),F(V$1);});})}on(u,F){const t=this.subscribers.get(u)??[];t.push({cb:F}),this.subscribers.set(u,t);}once(u,F){const t=this.subscribers.get(u)??[];t.push({cb:F,once:true}),this.subscribers.set(u,t);}emit(u,...F){const t=this.subscribers.get(u)??[],s=[];for(const C of t)C.cb(...F),C.once&&s.push(()=>t.splice(t.indexOf(C),1));for(const C of s)C();}unsubscribe(){this.subscribers.clear();}onKeypress(u,F){if(this.state==="error"&&(this.state="active"),F?.name&&!this._track&&z.has(F.name)&&this.emit("cursor",z.get(F.name)),F?.name&&xD.has(F.name)&&this.emit("cursor",F.name),u&&(u.toLowerCase()==="y"||u.toLowerCase()==="n")&&this.emit("confirm",u.toLowerCase()==="y"),u===" "&&this.opts.placeholder&&(this.value||(this.rl.write(this.opts.placeholder),this.emit("value",this.opts.placeholder))),u&&this.emit("key",u.toLowerCase()),F?.name==="return"){if(this.opts.validate){const t=this.opts.validate(this.value);t&&(this.error=t,this.state="error",this.rl.write(this.value));}this.state!=="error"&&(this.state="submit");}u===""&&(this.state="cancel"),(this.state==="submit"||this.state==="cancel")&&this.emit("finalize"),this.render(),(this.state==="submit"||this.state==="cancel")&&this.close();}close(){this.input.unpipe(),this.input.removeListener("keypress",this.onKeypress),this.output.write(`
|
|
356
|
-
`),v(this.input,false),this.rl.close(),this.emit(`${this.state}`,this.value),this.unsubscribe();}restoreCursor(){const u=R$1(this._prevFrame,process.stdout.columns,{hard:true}).split(`
|
|
359
|
+
`),s=[];for(let C=0;C<Math.max(F.length,t.length);C++)F[C]!==t[C]&&s.push(C);return s}const V$1=Symbol("clack:cancel");function lD(e){return e===V$1}function v$1(e,u){e.isTTY&&e.setRawMode(u);}const z=new Map([["k","up"],["j","down"],["h","left"],["l","right"]]),xD=new Set(["up","down","left","right","space","enter"]);class x{constructor({render:u,input:F=stdin,output:t=stdout,...s},C=true){a$1(this,"input"),a$1(this,"output"),a$1(this,"rl"),a$1(this,"opts"),a$1(this,"_track",false),a$1(this,"_render"),a$1(this,"_cursor",0),a$1(this,"state","initial"),a$1(this,"value"),a$1(this,"error",""),a$1(this,"subscribers",new Map),a$1(this,"_prevFrame",""),this.opts=s,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=u.bind(this),this._track=C,this.input=F,this.output=t;}prompt(){const u=new WriteStream(0);return u._write=(F,t,s)=>{this._track&&(this.value=this.rl.line.replace(/\t/g,""),this._cursor=this.rl.cursor,this.emit("value",this.value)),s();},this.input.pipe(u),this.rl=f__default.createInterface({input:this.input,output:u,tabSize:2,prompt:"",escapeCodeTimeout:50}),f__default.emitKeypressEvents(this.input,this.rl),this.rl.prompt(),this.opts.initialValue!==void 0&&this._track&&this.rl.write(this.opts.initialValue),this.input.on("keypress",this.onKeypress),v$1(this.input,true),this.output.on("resize",this.render),this.render(),new Promise((F,t)=>{this.once("submit",()=>{this.output.write(srcExports.cursor.show),this.output.off("resize",this.render),v$1(this.input,false),F(this.value);}),this.once("cancel",()=>{this.output.write(srcExports.cursor.show),this.output.off("resize",this.render),v$1(this.input,false),F(V$1);});})}on(u,F){const t=this.subscribers.get(u)??[];t.push({cb:F}),this.subscribers.set(u,t);}once(u,F){const t=this.subscribers.get(u)??[];t.push({cb:F,once:true}),this.subscribers.set(u,t);}emit(u,...F){const t=this.subscribers.get(u)??[],s=[];for(const C of t)C.cb(...F),C.once&&s.push(()=>t.splice(t.indexOf(C),1));for(const C of s)C();}unsubscribe(){this.subscribers.clear();}onKeypress(u,F){if(this.state==="error"&&(this.state="active"),F?.name&&!this._track&&z.has(F.name)&&this.emit("cursor",z.get(F.name)),F?.name&&xD.has(F.name)&&this.emit("cursor",F.name),u&&(u.toLowerCase()==="y"||u.toLowerCase()==="n")&&this.emit("confirm",u.toLowerCase()==="y"),u===" "&&this.opts.placeholder&&(this.value||(this.rl.write(this.opts.placeholder),this.emit("value",this.opts.placeholder))),u&&this.emit("key",u.toLowerCase()),F?.name==="return"){if(this.opts.validate){const t=this.opts.validate(this.value);t&&(this.error=t,this.state="error",this.rl.write(this.value));}this.state!=="error"&&(this.state="submit");}u===""&&(this.state="cancel"),(this.state==="submit"||this.state==="cancel")&&this.emit("finalize"),this.render(),(this.state==="submit"||this.state==="cancel")&&this.close();}close(){this.input.unpipe(),this.input.removeListener("keypress",this.onKeypress),this.output.write(`
|
|
360
|
+
`),v$1(this.input,false),this.rl.close(),this.emit(`${this.state}`,this.value),this.unsubscribe();}restoreCursor(){const u=R$1(this._prevFrame,process.stdout.columns,{hard:true}).split(`
|
|
357
361
|
`).length-1;this.output.write(srcExports.cursor.move(-999,u*-1));}render(){const u=R$1(this._render(this)??"",process.stdout.columns,{hard:true});if(u!==this._prevFrame){if(this.state==="initial")this.output.write(srcExports.cursor.hide);else {const F=hD(this._prevFrame,u);if(this.restoreCursor(),F&&F?.length===1){const t=F[0];this.output.write(srcExports.cursor.move(0,t)),this.output.write(srcExports.erase.lines(1));const s=u.split(`
|
|
358
362
|
`);this.output.write(s[t]),this._prevFrame=u,this.output.write(srcExports.cursor.move(0,s.length-t-1));return}else if(F&&F?.length>1){const t=F[0];this.output.write(srcExports.cursor.move(0,t)),this.output.write(srcExports.erase.down());const s=u.split(`
|
|
359
363
|
`).slice(t);this.output.write(s.join(`
|
|
360
364
|
`)),this._prevFrame=u;return}this.output.write(srcExports.erase.down());}this.output.write(u),this.state==="initial"&&(this.state="active"),this._prevFrame=u;}}}class BD extends x{get cursor(){return this.value?0:1}get _value(){return this.cursor===0}constructor(u){super(u,false),this.value=!!u.initialValue,this.on("value",()=>{this.value=this._value;}),this.on("confirm",F=>{this.output.write(srcExports.cursor.move(0,-1)),this.value=F,this.state="submit",this.close();}),this.on("cursor",()=>{this.value=!this.value;});}}var fD=Object.defineProperty,gD=(e,u,F)=>u in e?fD(e,u,{enumerable:true,configurable:true,writable:true,value:F}):e[u]=F,K$1=(e,u,F)=>(gD(e,typeof u!="symbol"?u+"":u,F),F);let vD=class extends x{constructor(u){super(u,false),K$1(this,"options"),K$1(this,"cursor",0),this.options=u.options,this.value=[...u.initialValues??[]],this.cursor=Math.max(this.options.findIndex(({value:F})=>F===u.cursorAt),0),this.on("key",F=>{F==="a"&&this.toggleAll();}),this.on("cursor",F=>{switch(F){case "left":case "up":this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;break;case "down":case "right":this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;break;case "space":this.toggleValue();break}});}get _value(){return this.options[this.cursor].value}toggleAll(){const u=this.value.length===this.options.length;this.value=u?[]:this.options.map(F=>F.value);}toggleValue(){const u=this.value.includes(this._value);this.value=u?this.value.filter(F=>F!==this._value):[...this.value,this._value];}};var wD=Object.defineProperty,yD=(e,u,F)=>u in e?wD(e,u,{enumerable:true,configurable:true,writable:true,value:F}):e[u]=F,Z=(e,u,F)=>(yD(e,typeof u!="symbol"?u+"":u,F),F);let $D=class extends x{constructor(u){super(u,false),Z(this,"options"),Z(this,"cursor",0),this.options=u.options,this.cursor=this.options.findIndex(({value:F})=>F===u.initialValue),this.cursor===-1&&(this.cursor=0),this.changeValue(),this.on("cursor",F=>{switch(F){case "left":case "up":this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;break;case "down":case "right":this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;break}this.changeValue();});}get _value(){return this.options[this.cursor]}changeValue(){this.value=this._value.value;}};var TD=Object.defineProperty,jD=(e,u,F)=>u in e?TD(e,u,{enumerable:true,configurable:true,writable:true,value:F}):e[u]=F,MD=(e,u,F)=>(jD(e,u+"",F),F);class PD extends x{constructor(u){super(u),MD(this,"valueWithCursor",""),this.on("finalize",()=>{this.value||(this.value=u.defaultValue),this.valueWithCursor=this.value;}),this.on("value",()=>{if(this.cursor>=this.value.length)this.valueWithCursor=`${this.value}${color2.inverse(color2.hidden("_"))}`;else {const F=this.value.slice(0,this.cursor),t=this.value.slice(this.cursor);this.valueWithCursor=`${F}${color2.inverse(t[0])}${t.slice(1)}`;}});}get cursor(){return this._cursor}}const WD=globalThis.process.platform.startsWith("win");function OD({input:e=stdin,output:u=stdout,overwrite:F=true,hideCursor:t=true}={}){const s=f.createInterface({input:e,output:u,prompt:"",tabSize:1});f.emitKeypressEvents(e,s),e.isTTY&&e.setRawMode(true);const C=(D,{name:i})=>{if(String(D)===""){t&&u.write(srcExports.cursor.show),process.exit(0);return}if(!F)return;let n=i==="return"?0:-1,E=i==="return"?-1:0;f.moveCursor(u,n,E,()=>{f.clearLine(u,1,()=>{e.once("keypress",C);});});};return t&&u.write(srcExports.cursor.hide),e.once("keypress",C),()=>{e.off("keypress",C),t&&u.write(srcExports.cursor.show),e.isTTY&&!WD&&e.setRawMode(false),s.terminal=false,s.close();}}
|
|
361
365
|
|
|
362
|
-
function K(){return h.platform!=="win32"?h.env.TERM!=="linux":!!h.env.CI||!!h.env.WT_SESSION||!!h.env.TERMINUS_SUBLIME||h.env.ConEmuTask==="{cmd::Cmder}"||h.env.TERM_PROGRAM==="Terminus-Sublime"||h.env.TERM_PROGRAM==="vscode"||h.env.TERM==="xterm-256color"||h.env.TERM==="alacritty"||h.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}const C=K(),u=(s,n)=>C?s:n,Y=u("\u25C6","*"),P=u("\u25A0","x"),V=u("\u25B2","x"),M=u("\u25C7","o"),Q=u("\u250C","T"),a=u("\u2502","|"),$=u("\u2514","\u2014"),I=u("\u25CF",">"),T=u("\u25CB"," "),j=u("\u25FB","[\u2022]"),b=u("\u25FC","[+]"),B=u("\u25FB","[ ]"),G=u("\u2500","-"),H=u("\u256E","+"),ee=u("\u251C","+"),te=u("\u256F","+"),y=s=>{switch(s){case "initial":case "active":return color2.cyan(Y);case "cancel":return color2.red(P);case "error":return color2.yellow(V);case "submit":return color2.green(M)}},E=s=>{const{cursor:n,options:t,style:i}=s,r=s.maxItems??1/0,o=Math.max(process.stdout.rows-4,0),c=Math.min(o,Math.max(r,5));let l=0;n>=l+c-3?l=Math.max(Math.min(n-c+3,t.length-c),0):n<l+2&&(l=Math.max(n-2,0));const d=c<t.length&&l>0,p=c<t.length&&l+c<t.length;return t.slice(l,l+c).map((S,f,x)=>{const g=f===0&&d,m=f===x.length-1&&p;return g||m?color2.dim("..."):i(S,f+l===n)})},ae=s=>new PD({validate:s.validate,placeholder:s.placeholder,defaultValue:s.defaultValue,initialValue:s.initialValue,render(){const n=`${color2.gray(a)}
|
|
366
|
+
function K(){return h.platform!=="win32"?h.env.TERM!=="linux":!!h.env.CI||!!h.env.WT_SESSION||!!h.env.TERMINUS_SUBLIME||h.env.ConEmuTask==="{cmd::Cmder}"||h.env.TERM_PROGRAM==="Terminus-Sublime"||h.env.TERM_PROGRAM==="vscode"||h.env.TERM==="xterm-256color"||h.env.TERM==="alacritty"||h.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}const C=K(),u=(s,n)=>C?s:n,Y=u("\u25C6","*"),P=u("\u25A0","x"),V=u("\u25B2","x"),M=u("\u25C7","o"),Q=u("\u250C","T"),a=u("\u2502","|"),$=u("\u2514","\u2014"),I=u("\u25CF",">"),T=u("\u25CB"," "),j=u("\u25FB","[\u2022]"),b=u("\u25FC","[+]"),B=u("\u25FB","[ ]"),G=u("\u2500","-"),H=u("\u256E","+"),ee=u("\u251C","+"),te=u("\u256F","+"),se=u("\u25CF","\u2022"),re=u("\u25C6","*"),ie=u("\u25B2","!"),ne=u("\u25A0","x"),y=s=>{switch(s){case "initial":case "active":return color2.cyan(Y);case "cancel":return color2.red(P);case "error":return color2.yellow(V);case "submit":return color2.green(M)}},E=s=>{const{cursor:n,options:t,style:i}=s,r=s.maxItems??1/0,o=Math.max(process.stdout.rows-4,0),c=Math.min(o,Math.max(r,5));let l=0;n>=l+c-3?l=Math.max(Math.min(n-c+3,t.length-c),0):n<l+2&&(l=Math.max(n-2,0));const d=c<t.length&&l>0,p=c<t.length&&l+c<t.length;return t.slice(l,l+c).map((S,f,x)=>{const g=f===0&&d,m=f===x.length-1&&p;return g||m?color2.dim("..."):i(S,f+l===n)})},ae=s=>new PD({validate:s.validate,placeholder:s.placeholder,defaultValue:s.defaultValue,initialValue:s.initialValue,render(){const n=`${color2.gray(a)}
|
|
363
367
|
${y(this.state)} ${s.message}
|
|
364
368
|
`,t=s.placeholder?color2.inverse(s.placeholder[0])+color2.dim(s.placeholder.slice(1)):color2.inverse(color2.hidden("_")),i=this.value?this.valueWithCursor:t;switch(this.state){case "error":return `${n.trim()}
|
|
365
369
|
${color2.yellow(a)} ${i}
|
|
@@ -404,10 +408,290 @@ ${color2.gray(ee+G.repeat(r+2)+te)}
|
|
|
404
408
|
`);},ge=(s="")=>{process.stdout.write(`${color2.gray(a)}
|
|
405
409
|
${color2.gray($)} ${s}
|
|
406
410
|
|
|
407
|
-
`);},
|
|
411
|
+
`);},v={message:(s="",{symbol:n=color2.gray(a)}={})=>{const t=[`${color2.gray(a)}`];if(s){const[i,...r]=s.split(`
|
|
412
|
+
`);t.push(`${n} ${i}`,...r.map(o=>`${color2.gray(a)} ${o}`));}process.stdout.write(`${t.join(`
|
|
413
|
+
`)}
|
|
414
|
+
`);},info:s=>{v.message(s,{symbol:color2.blue(se)});},success:s=>{v.message(s,{symbol:color2.green(re)});},step:s=>{v.message(s,{symbol:color2.green(M)});},warn:s=>{v.message(s,{symbol:color2.yellow(ie)});},warning:s=>{v.warn(s);},error:s=>{v.message(s,{symbol:color2.red(ne)});}},_=()=>{const s=C?["\u25D2","\u25D0","\u25D3","\u25D1"]:["\u2022","o","O","0"],n=C?80:120;let t,i,r=false,o="";const c=g=>{const m=g>1?"Something went wrong":"Canceled";r&&x(m,g);},l=()=>c(2),d=()=>c(1),p=()=>{process.on("uncaughtExceptionMonitor",l),process.on("unhandledRejection",l),process.on("SIGINT",d),process.on("SIGTERM",d),process.on("exit",c);},S=()=>{process.removeListener("uncaughtExceptionMonitor",l),process.removeListener("unhandledRejection",l),process.removeListener("SIGINT",d),process.removeListener("SIGTERM",d),process.removeListener("exit",c);},f=(g="")=>{r=true,t=OD(),o=g.replace(/\.+$/,""),process.stdout.write(`${color2.gray(a)}
|
|
408
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}
|
|
409
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};
|
|
410
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
|
+
|
|
411
695
|
// eslint-disable-next-line no-warning-comments
|
|
412
696
|
// TODO: Use a better method when it's added to Node.js (https://github.com/nodejs/node/pull/40240)
|
|
413
697
|
// Lots of optionals here to support Deno.
|
|
@@ -781,39 +1065,65 @@ function yoctoSpinner(options) {
|
|
|
781
1065
|
}
|
|
782
1066
|
|
|
783
1067
|
var LogLevel = {
|
|
784
|
-
INFO: "info"
|
|
785
|
-
|
|
786
|
-
|
|
1068
|
+
INFO: "info",
|
|
1069
|
+
ERROR: "error"};
|
|
1070
|
+
var MastraLogger = class {
|
|
1071
|
+
name;
|
|
1072
|
+
level;
|
|
787
1073
|
transports;
|
|
788
1074
|
constructor(options = {}) {
|
|
789
|
-
this.
|
|
790
|
-
|
|
791
|
-
this.
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
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({
|
|
797
1103
|
colorize: true,
|
|
798
1104
|
levelFirst: true,
|
|
799
1105
|
ignore: "pid,hostname",
|
|
800
1106
|
colorizeObjects: true,
|
|
801
1107
|
translateTime: "SYS:standard",
|
|
802
1108
|
singleLine: false
|
|
803
|
-
})
|
|
804
|
-
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
const transportsAry = [...this.getTransports().entries()];
|
|
1112
|
+
this.logger = pino(
|
|
1113
|
+
{
|
|
1114
|
+
name: options.name || "app",
|
|
1115
|
+
level: options.level || LogLevel.INFO,
|
|
1116
|
+
formatters: {
|
|
1117
|
+
level: (label) => ({ level: label })
|
|
1118
|
+
}
|
|
1119
|
+
},
|
|
1120
|
+
options.overrideDefaultTransports ? options?.transports?.default : transportsAry.length === 0 ? prettyStream : pino.multistream([
|
|
1121
|
+
...transportsAry.map(([, transport]) => ({
|
|
805
1122
|
stream: transport,
|
|
806
1123
|
level: options.level || LogLevel.INFO
|
|
807
1124
|
})),
|
|
808
1125
|
{
|
|
809
|
-
stream:
|
|
810
|
-
colorize: true,
|
|
811
|
-
levelFirst: true,
|
|
812
|
-
ignore: "pid,hostname",
|
|
813
|
-
colorizeObjects: true,
|
|
814
|
-
translateTime: "SYS:standard",
|
|
815
|
-
singleLine: false
|
|
816
|
-
}),
|
|
1126
|
+
stream: prettyStream,
|
|
817
1127
|
level: options.level || LogLevel.INFO
|
|
818
1128
|
}
|
|
819
1129
|
])
|
|
@@ -831,67 +1141,8 @@ var Logger = class {
|
|
|
831
1141
|
error(message, args = {}) {
|
|
832
1142
|
this.logger.error(args, message);
|
|
833
1143
|
}
|
|
834
|
-
// Stream creation for process output handling
|
|
835
|
-
createStream() {
|
|
836
|
-
return new Transform({
|
|
837
|
-
transform: (chunk, _encoding, callback) => {
|
|
838
|
-
const line = chunk.toString().trim();
|
|
839
|
-
if (line) {
|
|
840
|
-
this.info(line);
|
|
841
|
-
}
|
|
842
|
-
callback(null, chunk);
|
|
843
|
-
}
|
|
844
|
-
});
|
|
845
|
-
}
|
|
846
|
-
async getLogs(transportId) {
|
|
847
|
-
if (!transportId || !this.transports[transportId]) {
|
|
848
|
-
return [];
|
|
849
|
-
}
|
|
850
|
-
return this.transports[transportId].getLogs();
|
|
851
|
-
}
|
|
852
|
-
async getLogsByRunId({ runId, transportId }) {
|
|
853
|
-
return this.transports[transportId]?.getLogsByRunId({ runId });
|
|
854
|
-
}
|
|
855
1144
|
};
|
|
856
|
-
function createLogger(options) {
|
|
857
|
-
return new Logger(options);
|
|
858
|
-
}
|
|
859
1145
|
|
|
860
|
-
function getPackageManager() {
|
|
861
|
-
const userAgent = process.env.npm_config_user_agent || "";
|
|
862
|
-
const execPath = process.env.npm_execpath || "";
|
|
863
|
-
if (userAgent.includes("yarn")) {
|
|
864
|
-
return "yarn";
|
|
865
|
-
}
|
|
866
|
-
if (userAgent.includes("pnpm")) {
|
|
867
|
-
return "pnpm";
|
|
868
|
-
}
|
|
869
|
-
if (userAgent.includes("npm")) {
|
|
870
|
-
return "npm";
|
|
871
|
-
}
|
|
872
|
-
if (execPath.includes("yarn")) {
|
|
873
|
-
return "yarn";
|
|
874
|
-
}
|
|
875
|
-
if (execPath.includes("pnpm")) {
|
|
876
|
-
return "pnpm";
|
|
877
|
-
}
|
|
878
|
-
if (execPath.includes("npm")) {
|
|
879
|
-
return "npm";
|
|
880
|
-
}
|
|
881
|
-
return "npm";
|
|
882
|
-
}
|
|
883
|
-
function getPackageManagerInstallCommand(pm) {
|
|
884
|
-
switch (pm) {
|
|
885
|
-
case "npm":
|
|
886
|
-
return "install";
|
|
887
|
-
case "yarn":
|
|
888
|
-
return "add";
|
|
889
|
-
case "pnpm":
|
|
890
|
-
return "add";
|
|
891
|
-
default:
|
|
892
|
-
return "install";
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
1146
|
var DepsService = class {
|
|
896
1147
|
packageManager;
|
|
897
1148
|
constructor() {
|
|
@@ -900,11 +1151,11 @@ var DepsService = class {
|
|
|
900
1151
|
findLockFile(dir) {
|
|
901
1152
|
const lockFiles = ["pnpm-lock.yaml", "package-lock.json", "yarn.lock", "bun.lock"];
|
|
902
1153
|
for (const file of lockFiles) {
|
|
903
|
-
if (fs3__default__default.existsSync(
|
|
1154
|
+
if (fs3__default__default.existsSync(path2.join(dir, file))) {
|
|
904
1155
|
return file;
|
|
905
1156
|
}
|
|
906
1157
|
}
|
|
907
|
-
const parentDir =
|
|
1158
|
+
const parentDir = path2.resolve(dir, "..");
|
|
908
1159
|
if (parentDir !== dir) {
|
|
909
1160
|
return this.findLockFile(parentDir);
|
|
910
1161
|
}
|
|
@@ -941,7 +1192,7 @@ var DepsService = class {
|
|
|
941
1192
|
}
|
|
942
1193
|
async checkDependencies(dependencies) {
|
|
943
1194
|
try {
|
|
944
|
-
const packageJsonPath =
|
|
1195
|
+
const packageJsonPath = path2.join(process.cwd(), "package.json");
|
|
945
1196
|
try {
|
|
946
1197
|
await fs4.access(packageJsonPath);
|
|
947
1198
|
} catch {
|
|
@@ -961,7 +1212,7 @@ var DepsService = class {
|
|
|
961
1212
|
}
|
|
962
1213
|
async getProjectName() {
|
|
963
1214
|
try {
|
|
964
|
-
const packageJsonPath =
|
|
1215
|
+
const packageJsonPath = path2.join(process.cwd(), "package.json");
|
|
965
1216
|
const packageJson = await fs4.readFile(packageJsonPath, "utf-8");
|
|
966
1217
|
const pkg = JSON.parse(packageJson);
|
|
967
1218
|
return pkg.name;
|
|
@@ -972,7 +1223,7 @@ var DepsService = class {
|
|
|
972
1223
|
async getPackageVersion() {
|
|
973
1224
|
const __filename = fileURLToPath(import.meta.url);
|
|
974
1225
|
const __dirname = dirname(__filename);
|
|
975
|
-
const pkgJsonPath =
|
|
1226
|
+
const pkgJsonPath = path2.join(__dirname, "..", "package.json");
|
|
976
1227
|
const content = await fsExtra3.readJSON(pkgJsonPath);
|
|
977
1228
|
return content.version;
|
|
978
1229
|
}
|
|
@@ -985,6 +1236,156 @@ var DepsService = class {
|
|
|
985
1236
|
await fs4.writeFile("package.json", JSON.stringify(packageJson, null, 2));
|
|
986
1237
|
}
|
|
987
1238
|
};
|
|
1239
|
+
function getPackageManager() {
|
|
1240
|
+
const userAgent = process.env.npm_config_user_agent || "";
|
|
1241
|
+
const execPath = process.env.npm_execpath || "";
|
|
1242
|
+
if (userAgent.includes("yarn")) {
|
|
1243
|
+
return "yarn";
|
|
1244
|
+
}
|
|
1245
|
+
if (userAgent.includes("pnpm")) {
|
|
1246
|
+
return "pnpm";
|
|
1247
|
+
}
|
|
1248
|
+
if (userAgent.includes("npm")) {
|
|
1249
|
+
return "npm";
|
|
1250
|
+
}
|
|
1251
|
+
if (execPath.includes("yarn")) {
|
|
1252
|
+
return "yarn";
|
|
1253
|
+
}
|
|
1254
|
+
if (execPath.includes("pnpm")) {
|
|
1255
|
+
return "pnpm";
|
|
1256
|
+
}
|
|
1257
|
+
if (execPath.includes("npm")) {
|
|
1258
|
+
return "npm";
|
|
1259
|
+
}
|
|
1260
|
+
return "npm";
|
|
1261
|
+
}
|
|
1262
|
+
function getPackageManagerInstallCommand(pm) {
|
|
1263
|
+
switch (pm) {
|
|
1264
|
+
case "npm":
|
|
1265
|
+
return "install";
|
|
1266
|
+
case "yarn":
|
|
1267
|
+
return "add";
|
|
1268
|
+
case "pnpm":
|
|
1269
|
+
return "add";
|
|
1270
|
+
default:
|
|
1271
|
+
return "install";
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
var args = ["-y", "@mastra/mcp-docs-server@latest"];
|
|
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
|
+
};
|
|
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
|
+
};
|
|
1302
|
+
};
|
|
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
|
+
}
|
|
1313
|
+
return {
|
|
1314
|
+
...original,
|
|
1315
|
+
mcpServers: {
|
|
1316
|
+
...original?.mcpServers || {},
|
|
1317
|
+
...createMcpConfig(editor).mcpServers
|
|
1318
|
+
}
|
|
1319
|
+
};
|
|
1320
|
+
}
|
|
1321
|
+
async function writeMergedConfig(configPath, editor) {
|
|
1322
|
+
const configExists = existsSync(configPath);
|
|
1323
|
+
const config = makeConfig(configExists ? await readJSON(configPath) : {}, editor);
|
|
1324
|
+
await ensureFile(configPath);
|
|
1325
|
+
await writeJSON(configPath, config, {
|
|
1326
|
+
spaces: 2
|
|
1327
|
+
});
|
|
1328
|
+
}
|
|
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 }) {
|
|
1337
|
+
if (editor === `cursor`) {
|
|
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");
|
|
1342
|
+
}
|
|
1343
|
+
if (editor === `cursor-global`) {
|
|
1344
|
+
const alreadyInstalled = await globalMCPIsAlreadyInstalled(editor);
|
|
1345
|
+
if (alreadyInstalled) {
|
|
1346
|
+
return;
|
|
1347
|
+
}
|
|
1348
|
+
await writeMergedConfig(cursorGlobalMCPConfigPath, "cursor-global");
|
|
1349
|
+
}
|
|
1350
|
+
if (editor === `windsurf`) {
|
|
1351
|
+
const alreadyInstalled = await globalMCPIsAlreadyInstalled(editor);
|
|
1352
|
+
if (alreadyInstalled) {
|
|
1353
|
+
return;
|
|
1354
|
+
}
|
|
1355
|
+
await writeMergedConfig(windsurfGlobalMCPConfigPath, editor);
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
async function globalMCPIsAlreadyInstalled(editor) {
|
|
1359
|
+
let configPath = ``;
|
|
1360
|
+
if (editor === "windsurf") {
|
|
1361
|
+
configPath = windsurfGlobalMCPConfigPath;
|
|
1362
|
+
} else if (editor === "cursor-global") {
|
|
1363
|
+
configPath = cursorGlobalMCPConfigPath;
|
|
1364
|
+
} else if (editor === "vscode") {
|
|
1365
|
+
configPath = vscodeGlobalMCPConfigPath;
|
|
1366
|
+
}
|
|
1367
|
+
if (!configPath || !existsSync(configPath)) {
|
|
1368
|
+
return false;
|
|
1369
|
+
}
|
|
1370
|
+
try {
|
|
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
|
+
}
|
|
1379
|
+
if (!configContents?.mcpServers) return false;
|
|
1380
|
+
const hasMastraMCP = Object.values(configContents.mcpServers).some(
|
|
1381
|
+
(server) => server?.args?.find((arg) => arg?.includes(`@mastra/mcp-docs-server`))
|
|
1382
|
+
);
|
|
1383
|
+
return hasMastraMCP;
|
|
1384
|
+
} catch (e) {
|
|
1385
|
+
console.error(e);
|
|
1386
|
+
return false;
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
988
1389
|
var EnvService = class {
|
|
989
1390
|
};
|
|
990
1391
|
var FileEnvService = class extends EnvService {
|
|
@@ -1056,8 +1457,8 @@ var FileService = class {
|
|
|
1056
1457
|
*/
|
|
1057
1458
|
async copyStarterFile(inputFile, outputFilePath, replaceIfExists) {
|
|
1058
1459
|
const __filename = fileURLToPath(import.meta.url);
|
|
1059
|
-
const __dirname =
|
|
1060
|
-
const filePath =
|
|
1460
|
+
const __dirname = path2.dirname(__filename);
|
|
1461
|
+
const filePath = path2.resolve(__dirname, "starter-files", inputFile);
|
|
1061
1462
|
const fileString = fs3__default__default.readFileSync(filePath, "utf8");
|
|
1062
1463
|
if (fs3__default__default.existsSync(outputFilePath) && !replaceIfExists) {
|
|
1063
1464
|
console.log(`${outputFilePath} already exists`);
|
|
@@ -1067,7 +1468,7 @@ var FileService = class {
|
|
|
1067
1468
|
return true;
|
|
1068
1469
|
}
|
|
1069
1470
|
async setupEnvFile({ dbUrl }) {
|
|
1070
|
-
const envPath =
|
|
1471
|
+
const envPath = path2.join(process.cwd(), ".env.development");
|
|
1071
1472
|
await fsExtra3.ensureFile(envPath);
|
|
1072
1473
|
const fileEnvService = new FileEnvService(envPath);
|
|
1073
1474
|
await fileEnvService.setEnvValue("DB_URL", dbUrl);
|
|
@@ -1091,7 +1492,7 @@ var FileService = class {
|
|
|
1091
1492
|
fs3__default__default.writeFileSync(filePath, fileContent);
|
|
1092
1493
|
}
|
|
1093
1494
|
};
|
|
1094
|
-
|
|
1495
|
+
new PinoLogger({
|
|
1095
1496
|
name: "Mastra CLI",
|
|
1096
1497
|
level: "debug"
|
|
1097
1498
|
});
|
|
@@ -1104,6 +1505,10 @@ var getAISDKPackage = (llmProvider) => {
|
|
|
1104
1505
|
return "@ai-sdk/anthropic";
|
|
1105
1506
|
case "groq":
|
|
1106
1507
|
return "@ai-sdk/groq";
|
|
1508
|
+
case "google":
|
|
1509
|
+
return "@ai-sdk/google";
|
|
1510
|
+
case "cerebras":
|
|
1511
|
+
return "@ai-sdk/cerebras";
|
|
1107
1512
|
default:
|
|
1108
1513
|
return "@ai-sdk/openai";
|
|
1109
1514
|
}
|
|
@@ -1113,13 +1518,19 @@ var getProviderImportAndModelItem = (llmProvider) => {
|
|
|
1113
1518
|
let modelItem = "";
|
|
1114
1519
|
if (llmProvider === "openai") {
|
|
1115
1520
|
providerImport = `import { openai } from '${getAISDKPackage(llmProvider)}';`;
|
|
1116
|
-
modelItem = `openai('gpt-4o')`;
|
|
1521
|
+
modelItem = `openai('gpt-4o-mini')`;
|
|
1117
1522
|
} else if (llmProvider === "anthropic") {
|
|
1118
1523
|
providerImport = `import { anthropic } from '${getAISDKPackage(llmProvider)}';`;
|
|
1119
1524
|
modelItem = `anthropic('claude-3-5-sonnet-20241022')`;
|
|
1120
1525
|
} else if (llmProvider === "groq") {
|
|
1121
1526
|
providerImport = `import { groq } from '${getAISDKPackage(llmProvider)}';`;
|
|
1122
|
-
modelItem = `groq('
|
|
1527
|
+
modelItem = `groq('llama-3.3-70b-versatile')`;
|
|
1528
|
+
} else if (llmProvider === "google") {
|
|
1529
|
+
providerImport = `import { google } from '${getAISDKPackage(llmProvider)}';`;
|
|
1530
|
+
modelItem = `google('gemini-1.5-pro-latest')`;
|
|
1531
|
+
} else if (llmProvider === "cerebras") {
|
|
1532
|
+
providerImport = `import { cerebras } from '${getAISDKPackage(llmProvider)}';`;
|
|
1533
|
+
modelItem = `cerebras('llama-3.3-70b')`;
|
|
1123
1534
|
}
|
|
1124
1535
|
return { providerImport, modelItem };
|
|
1125
1536
|
};
|
|
@@ -1130,6 +1541,7 @@ async function writeAgentSample(llmProvider, destPath, addExampleTool) {
|
|
|
1130
1541
|
|
|
1131
1542
|
Your primary function is to help users get weather details for specific locations. When responding:
|
|
1132
1543
|
- Always ask for a location if none is provided
|
|
1544
|
+
- If the location name isn\u2019t in English, please translate it
|
|
1133
1545
|
- If giving a location with multiple parts (e.g. "New York, NY"), use the most relevant part (e.g. "New York")
|
|
1134
1546
|
- Include relevant details like humidity, wind conditions, and precipitation
|
|
1135
1547
|
- Keep responses concise but informative
|
|
@@ -1137,15 +1549,22 @@ async function writeAgentSample(llmProvider, destPath, addExampleTool) {
|
|
|
1137
1549
|
${addExampleTool ? "Use the weatherTool to fetch current weather data." : ""}
|
|
1138
1550
|
`;
|
|
1139
1551
|
const content = `
|
|
1140
|
-
${providerImport}
|
|
1552
|
+
${providerImport}
|
|
1141
1553
|
import { Agent } from '@mastra/core/agent';
|
|
1142
|
-
|
|
1554
|
+
import { Memory } from '@mastra/memory';
|
|
1555
|
+
import { LibSQLStore } from '@mastra/libsql';
|
|
1556
|
+
${addExampleTool ? `import { weatherTool } from '../tools/weather-tool';` : ""}
|
|
1143
1557
|
|
|
1144
1558
|
export const weatherAgent = new Agent({
|
|
1145
1559
|
name: 'Weather Agent',
|
|
1146
1560
|
instructions: \`${instructions}\`,
|
|
1147
1561
|
model: ${modelItem},
|
|
1148
1562
|
${addExampleTool ? "tools: { weatherTool }," : ""}
|
|
1563
|
+
memory: new Memory({
|
|
1564
|
+
storage: new LibSQLStore({
|
|
1565
|
+
url: "file:../mastra.db", // path is relative to the .mastra/output directory
|
|
1566
|
+
})
|
|
1567
|
+
})
|
|
1149
1568
|
});
|
|
1150
1569
|
`;
|
|
1151
1570
|
const formattedContent = await prettier.format(content, {
|
|
@@ -1159,7 +1578,7 @@ async function writeWorkflowSample(destPath, llmProvider) {
|
|
|
1159
1578
|
const { providerImport, modelItem } = getProviderImportAndModelItem(llmProvider);
|
|
1160
1579
|
const content = `${providerImport}
|
|
1161
1580
|
import { Agent } from '@mastra/core/agent';
|
|
1162
|
-
import {
|
|
1581
|
+
import { createStep, createWorkflow } from '@mastra/core/workflows';
|
|
1163
1582
|
import { z } from 'zod';
|
|
1164
1583
|
|
|
1165
1584
|
const llm = ${modelItem};
|
|
@@ -1212,79 +1631,107 @@ const agent = new Agent({
|
|
|
1212
1631
|
\`,
|
|
1213
1632
|
});
|
|
1214
1633
|
|
|
1215
|
-
const
|
|
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
|
+
})
|
|
1642
|
+
|
|
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({
|
|
1216
1666
|
id: 'fetch-weather',
|
|
1217
1667
|
description: 'Fetches weather forecast for a given city',
|
|
1218
1668
|
inputSchema: z.object({
|
|
1219
1669
|
city: z.string().describe('The city to get the weather for'),
|
|
1220
1670
|
}),
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
throw new Error('Trigger data not found');
|
|
1671
|
+
outputSchema: forecastSchema,
|
|
1672
|
+
execute: async ({ inputData }) => {
|
|
1673
|
+
if (!inputData) {
|
|
1674
|
+
throw new Error('Input data not found');
|
|
1226
1675
|
}
|
|
1227
1676
|
|
|
1228
|
-
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\`;
|
|
1229
1678
|
const geocodingResponse = await fetch(geocodingUrl);
|
|
1230
1679
|
const geocodingData = (await geocodingResponse.json()) as {
|
|
1231
1680
|
results: { latitude: number; longitude: number; name: string }[];
|
|
1232
1681
|
};
|
|
1233
1682
|
|
|
1234
1683
|
if (!geocodingData.results?.[0]) {
|
|
1235
|
-
throw new Error(\`Location '\${
|
|
1684
|
+
throw new Error(\`Location '\${inputData.city}' not found\`);
|
|
1236
1685
|
}
|
|
1237
1686
|
|
|
1238
1687
|
const { latitude, longitude, name } = geocodingData.results[0];
|
|
1239
1688
|
|
|
1240
|
-
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\`;
|
|
1241
1690
|
const response = await fetch(weatherUrl);
|
|
1242
1691
|
const data = (await response.json()) as {
|
|
1243
|
-
|
|
1244
|
-
time: string
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1692
|
+
current: {
|
|
1693
|
+
time: string
|
|
1694
|
+
precipitation: number
|
|
1695
|
+
weathercode: number
|
|
1696
|
+
}
|
|
1697
|
+
hourly: {
|
|
1698
|
+
precipitation_probability: number[]
|
|
1699
|
+
temperature_2m: number[]
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1251
1702
|
|
|
1252
|
-
const forecast =
|
|
1253
|
-
date,
|
|
1254
|
-
maxTemp: data.
|
|
1255
|
-
minTemp: data.
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
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
|
+
location: name
|
|
1713
|
+
}
|
|
1260
1714
|
|
|
1261
1715
|
return forecast;
|
|
1262
1716
|
},
|
|
1263
1717
|
});
|
|
1264
1718
|
|
|
1265
|
-
const forecastSchema = z.array(
|
|
1266
|
-
z.object({
|
|
1267
|
-
date: z.string(),
|
|
1268
|
-
maxTemp: z.number(),
|
|
1269
|
-
minTemp: z.number(),
|
|
1270
|
-
precipitationChance: z.number(),
|
|
1271
|
-
condition: z.string(),
|
|
1272
|
-
location: z.string(),
|
|
1273
|
-
}),
|
|
1274
|
-
);
|
|
1275
1719
|
|
|
1276
|
-
const planActivities =
|
|
1720
|
+
const planActivities = createStep({
|
|
1277
1721
|
id: 'plan-activities',
|
|
1278
1722
|
description: 'Suggests activities based on weather conditions',
|
|
1279
1723
|
inputSchema: forecastSchema,
|
|
1280
|
-
|
|
1281
|
-
|
|
1724
|
+
outputSchema: z.object({
|
|
1725
|
+
activities: z.string(),
|
|
1726
|
+
}),
|
|
1727
|
+
execute: async ({ inputData }) => {
|
|
1728
|
+
const forecast = inputData
|
|
1282
1729
|
|
|
1283
|
-
if (!forecast
|
|
1284
|
-
throw new Error('Forecast data not found')
|
|
1730
|
+
if (!forecast) {
|
|
1731
|
+
throw new Error('Forecast data not found')
|
|
1285
1732
|
}
|
|
1286
1733
|
|
|
1287
|
-
const prompt = \`Based on the following weather forecast for \${forecast
|
|
1734
|
+
const prompt = \`Based on the following weather forecast for \${forecast.location}, suggest appropriate activities:
|
|
1288
1735
|
\${JSON.stringify(forecast, null, 2)}
|
|
1289
1736
|
\`;
|
|
1290
1737
|
|
|
@@ -1295,45 +1742,29 @@ const planActivities = new Step({
|
|
|
1295
1742
|
},
|
|
1296
1743
|
]);
|
|
1297
1744
|
|
|
1745
|
+
let activitiesText = '';
|
|
1746
|
+
|
|
1298
1747
|
for await (const chunk of response.textStream) {
|
|
1299
1748
|
process.stdout.write(chunk);
|
|
1749
|
+
activitiesText += chunk;
|
|
1300
1750
|
}
|
|
1301
1751
|
|
|
1302
1752
|
return {
|
|
1303
|
-
activities:
|
|
1753
|
+
activities: activitiesText,
|
|
1304
1754
|
};
|
|
1305
1755
|
},
|
|
1306
1756
|
});
|
|
1307
1757
|
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
1: 'Mainly clear',
|
|
1312
|
-
2: 'Partly cloudy',
|
|
1313
|
-
3: 'Overcast',
|
|
1314
|
-
45: 'Foggy',
|
|
1315
|
-
48: 'Depositing rime fog',
|
|
1316
|
-
51: 'Light drizzle',
|
|
1317
|
-
53: 'Moderate drizzle',
|
|
1318
|
-
55: 'Dense drizzle',
|
|
1319
|
-
61: 'Slight rain',
|
|
1320
|
-
63: 'Moderate rain',
|
|
1321
|
-
65: 'Heavy rain',
|
|
1322
|
-
71: 'Slight snow fall',
|
|
1323
|
-
73: 'Moderate snow fall',
|
|
1324
|
-
75: 'Heavy snow fall',
|
|
1325
|
-
95: 'Thunderstorm',
|
|
1326
|
-
};
|
|
1327
|
-
return conditions[code] || 'Unknown';
|
|
1328
|
-
}
|
|
1329
|
-
|
|
1330
|
-
const weatherWorkflow = new Workflow({
|
|
1331
|
-
name: 'weather-workflow',
|
|
1332
|
-
triggerSchema: z.object({
|
|
1758
|
+
const weatherWorkflow = createWorkflow({
|
|
1759
|
+
id: 'weather-workflow',
|
|
1760
|
+
inputSchema: z.object({
|
|
1333
1761
|
city: z.string().describe('The city to get the weather for'),
|
|
1334
1762
|
}),
|
|
1763
|
+
outputSchema: z.object({
|
|
1764
|
+
activities: z.string(),
|
|
1765
|
+
})
|
|
1335
1766
|
})
|
|
1336
|
-
.
|
|
1767
|
+
.then(fetchWeather)
|
|
1337
1768
|
.then(planActivities);
|
|
1338
1769
|
|
|
1339
1770
|
weatherWorkflow.commit();
|
|
@@ -1373,7 +1804,7 @@ var writeIndexFile = async ({
|
|
|
1373
1804
|
addWorkflow
|
|
1374
1805
|
}) => {
|
|
1375
1806
|
const indexPath = dirPath + "/index.ts";
|
|
1376
|
-
const destPath =
|
|
1807
|
+
const destPath = path2.join(indexPath);
|
|
1377
1808
|
try {
|
|
1378
1809
|
await fs4.writeFile(destPath, "");
|
|
1379
1810
|
const filteredExports = [
|
|
@@ -1395,13 +1826,18 @@ export const mastra = new Mastra()
|
|
|
1395
1826
|
destPath,
|
|
1396
1827
|
`
|
|
1397
1828
|
import { Mastra } from '@mastra/core/mastra';
|
|
1398
|
-
import {
|
|
1399
|
-
|
|
1400
|
-
${
|
|
1829
|
+
import { PinoLogger } from '@mastra/loggers';
|
|
1830
|
+
import { LibSQLStore } from '@mastra/libsql';
|
|
1831
|
+
${addWorkflow ? `import { weatherWorkflow } from './workflows/weather-workflow';` : ""}
|
|
1832
|
+
${addAgent ? `import { weatherAgent } from './agents/weather-agent';` : ""}
|
|
1401
1833
|
|
|
1402
1834
|
export const mastra = new Mastra({
|
|
1403
1835
|
${filteredExports.join("\n ")}
|
|
1404
|
-
|
|
1836
|
+
storage: new LibSQLStore({
|
|
1837
|
+
// stores telemetry, evals, ... into memory storage, if it needs to persist, change to file:../mastra.db
|
|
1838
|
+
url: ":memory:",
|
|
1839
|
+
}),
|
|
1840
|
+
logger: new PinoLogger({
|
|
1405
1841
|
name: 'Mastra',
|
|
1406
1842
|
level: 'info',
|
|
1407
1843
|
}),
|
|
@@ -1422,6 +1858,12 @@ var getAPIKey = async (provider) => {
|
|
|
1422
1858
|
case "groq":
|
|
1423
1859
|
key = "GROQ_API_KEY";
|
|
1424
1860
|
return key;
|
|
1861
|
+
case "google":
|
|
1862
|
+
key = "GOOGLE_GENERATIVE_AI_API_KEY";
|
|
1863
|
+
return key;
|
|
1864
|
+
case "cerebras":
|
|
1865
|
+
key = "CEREBRAS_API_KEY";
|
|
1866
|
+
return key;
|
|
1425
1867
|
default:
|
|
1426
1868
|
return key;
|
|
1427
1869
|
}
|
|
@@ -1431,11 +1873,13 @@ var writeAPIKey = async ({
|
|
|
1431
1873
|
apiKey = "your-api-key"
|
|
1432
1874
|
}) => {
|
|
1433
1875
|
const key = await getAPIKey(provider);
|
|
1434
|
-
|
|
1876
|
+
const escapedKey = shellQuote.quote([key]);
|
|
1877
|
+
const escapedApiKey = shellQuote.quote([apiKey]);
|
|
1878
|
+
await exec(`echo ${escapedKey}=${escapedApiKey} >> .env`);
|
|
1435
1879
|
};
|
|
1436
1880
|
var createMastraDir = async (directory) => {
|
|
1437
1881
|
let dir = directory.trim().split("/").filter((item) => item !== "");
|
|
1438
|
-
const dirPath =
|
|
1882
|
+
const dirPath = path2.join(process.cwd(), ...dir, "mastra");
|
|
1439
1883
|
try {
|
|
1440
1884
|
await fs4.access(dirPath);
|
|
1441
1885
|
return { ok: false };
|
|
@@ -1445,7 +1889,7 @@ var createMastraDir = async (directory) => {
|
|
|
1445
1889
|
}
|
|
1446
1890
|
};
|
|
1447
1891
|
var writeCodeSample = async (dirPath, component, llmProvider, importComponents) => {
|
|
1448
|
-
const destPath = dirPath + `/${component}/
|
|
1892
|
+
const destPath = dirPath + `/${component}/weather-${component.slice(0, -1)}.ts`;
|
|
1449
1893
|
try {
|
|
1450
1894
|
await writeCodeSampleForComponents(llmProvider, component, destPath, importComponents);
|
|
1451
1895
|
} catch (err) {
|
|
@@ -1480,7 +1924,9 @@ var interactivePrompt = async () => {
|
|
|
1480
1924
|
options: [
|
|
1481
1925
|
{ value: "openai", label: "OpenAI", hint: "recommended" },
|
|
1482
1926
|
{ value: "anthropic", label: "Anthropic" },
|
|
1483
|
-
{ value: "groq", label: "Groq" }
|
|
1927
|
+
{ value: "groq", label: "Groq" },
|
|
1928
|
+
{ value: "google", label: "Google" },
|
|
1929
|
+
{ value: "cerebras", label: "Cerebras" }
|
|
1484
1930
|
]
|
|
1485
1931
|
}),
|
|
1486
1932
|
llmApiKey: async ({ results: { llmProvider } }) => {
|
|
@@ -1503,7 +1949,82 @@ var interactivePrompt = async () => {
|
|
|
1503
1949
|
addExample: () => ce({
|
|
1504
1950
|
message: "Add example",
|
|
1505
1951
|
initialValue: false
|
|
1506
|
-
})
|
|
1952
|
+
}),
|
|
1953
|
+
configureEditorWithDocsMCP: async () => {
|
|
1954
|
+
const windsurfIsAlreadyInstalled = await globalMCPIsAlreadyInstalled(`windsurf`);
|
|
1955
|
+
const cursorIsAlreadyInstalled = await globalMCPIsAlreadyInstalled(`cursor`);
|
|
1956
|
+
const vscodeIsAlreadyInstalled = await globalMCPIsAlreadyInstalled(`vscode`);
|
|
1957
|
+
const editor = await le({
|
|
1958
|
+
message: `Make your AI IDE into a Mastra expert? (installs Mastra docs MCP server)`,
|
|
1959
|
+
options: [
|
|
1960
|
+
{ value: "skip", label: "Skip for now", hint: "default" },
|
|
1961
|
+
{
|
|
1962
|
+
value: "cursor",
|
|
1963
|
+
label: "Cursor (project only)",
|
|
1964
|
+
hint: cursorIsAlreadyInstalled ? `Already installed globally` : void 0
|
|
1965
|
+
},
|
|
1966
|
+
{
|
|
1967
|
+
value: "cursor-global",
|
|
1968
|
+
label: "Cursor (global, all projects)",
|
|
1969
|
+
hint: cursorIsAlreadyInstalled ? `Already installed` : void 0
|
|
1970
|
+
},
|
|
1971
|
+
{
|
|
1972
|
+
value: "windsurf",
|
|
1973
|
+
label: "Windsurf",
|
|
1974
|
+
hint: windsurfIsAlreadyInstalled ? `Already installed` : void 0
|
|
1975
|
+
},
|
|
1976
|
+
{
|
|
1977
|
+
value: "vscode",
|
|
1978
|
+
label: "VSCode",
|
|
1979
|
+
hint: vscodeIsAlreadyInstalled ? `Already installed` : void 0
|
|
1980
|
+
}
|
|
1981
|
+
]
|
|
1982
|
+
});
|
|
1983
|
+
if (editor === `skip`) return void 0;
|
|
1984
|
+
if (editor === `windsurf` && windsurfIsAlreadyInstalled) {
|
|
1985
|
+
v.message(`
|
|
1986
|
+
Windsurf is already installed, skipping.`);
|
|
1987
|
+
return void 0;
|
|
1988
|
+
}
|
|
1989
|
+
if (editor === `vscode` && vscodeIsAlreadyInstalled) {
|
|
1990
|
+
v.message(`
|
|
1991
|
+
VSCode is already installed, skipping.`);
|
|
1992
|
+
return void 0;
|
|
1993
|
+
}
|
|
1994
|
+
if (editor === `cursor`) {
|
|
1995
|
+
v.message(
|
|
1996
|
+
`
|
|
1997
|
+
Note: you will need to go into Cursor Settings -> MCP Settings and manually enable the installed Mastra MCP server.
|
|
1998
|
+
`
|
|
1999
|
+
);
|
|
2000
|
+
}
|
|
2001
|
+
if (editor === `cursor-global`) {
|
|
2002
|
+
const confirm2 = await le({
|
|
2003
|
+
message: `Global install will add/update ${cursorGlobalMCPConfigPath} and make the Mastra docs MCP server available in all your Cursor projects. Continue?`,
|
|
2004
|
+
options: [
|
|
2005
|
+
{ value: "yes", label: "Yes, I understand" },
|
|
2006
|
+
{ value: "skip", label: "No, skip for now" }
|
|
2007
|
+
]
|
|
2008
|
+
});
|
|
2009
|
+
if (confirm2 !== `yes`) {
|
|
2010
|
+
return void 0;
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
if (editor === `windsurf`) {
|
|
2014
|
+
const confirm2 = await le({
|
|
2015
|
+
message: `Windsurf only supports a global MCP config (at ${windsurfGlobalMCPConfigPath}) is it ok to add/update that global config?
|
|
2016
|
+
This means the Mastra docs MCP server will be available in all your Windsurf projects.`,
|
|
2017
|
+
options: [
|
|
2018
|
+
{ value: "yes", label: "Yes, I understand" },
|
|
2019
|
+
{ value: "skip", label: "No, skip for now" }
|
|
2020
|
+
]
|
|
2021
|
+
});
|
|
2022
|
+
if (confirm2 !== `yes`) {
|
|
2023
|
+
return void 0;
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
return editor;
|
|
2027
|
+
}
|
|
1507
2028
|
},
|
|
1508
2029
|
{
|
|
1509
2030
|
onCancel: () => {
|
|
@@ -1523,7 +2044,8 @@ var init = async ({
|
|
|
1523
2044
|
addExample = false,
|
|
1524
2045
|
components,
|
|
1525
2046
|
llmProvider = "openai",
|
|
1526
|
-
llmApiKey
|
|
2047
|
+
llmApiKey,
|
|
2048
|
+
configureEditorWithDocsMCP
|
|
1527
2049
|
}) => {
|
|
1528
2050
|
s.start("Initializing Mastra");
|
|
1529
2051
|
try {
|
|
@@ -1549,19 +2071,39 @@ var init = async ({
|
|
|
1549
2071
|
(component) => writeCodeSample(dirPath, component, llmProvider, components)
|
|
1550
2072
|
)
|
|
1551
2073
|
]);
|
|
2074
|
+
const depService = new DepsService();
|
|
2075
|
+
const needsLibsql = await depService.checkDependencies(["@mastra/libsql"]) !== `ok`;
|
|
2076
|
+
if (needsLibsql) {
|
|
2077
|
+
await depService.installPackages(["@mastra/libsql"]);
|
|
2078
|
+
}
|
|
2079
|
+
const needsMemory = components.includes(`agents`) && await depService.checkDependencies(["@mastra/memory"]) !== `ok`;
|
|
2080
|
+
if (needsMemory) {
|
|
2081
|
+
await depService.installPackages(["@mastra/memory"]);
|
|
2082
|
+
}
|
|
2083
|
+
const needsLoggers = await depService.checkDependencies(["@mastra/loggers"]) !== `ok`;
|
|
2084
|
+
if (needsLoggers) {
|
|
2085
|
+
await depService.installPackages(["@mastra/loggers"]);
|
|
2086
|
+
}
|
|
1552
2087
|
}
|
|
1553
2088
|
const key = await getAPIKey(llmProvider || "openai");
|
|
1554
2089
|
const aiSdkPackage = getAISDKPackage(llmProvider);
|
|
1555
|
-
const
|
|
2090
|
+
const depsService = new DepsService();
|
|
2091
|
+
const pm = depsService.packageManager;
|
|
1556
2092
|
const installCommand = getPackageManagerInstallCommand(pm);
|
|
1557
2093
|
await exec2(`${pm} ${installCommand} ${aiSdkPackage}`);
|
|
2094
|
+
if (configureEditorWithDocsMCP) {
|
|
2095
|
+
await installMastraDocsMCPServer({
|
|
2096
|
+
editor: configureEditorWithDocsMCP,
|
|
2097
|
+
directory: process.cwd()
|
|
2098
|
+
});
|
|
2099
|
+
}
|
|
1558
2100
|
s.stop();
|
|
1559
2101
|
if (!llmApiKey) {
|
|
1560
2102
|
me(`
|
|
1561
2103
|
${color2.green("Mastra initialized successfully!")}
|
|
1562
2104
|
|
|
1563
2105
|
Add your ${color2.cyan(key)} as an environment variable
|
|
1564
|
-
in your ${color2.cyan(".env
|
|
2106
|
+
in your ${color2.cyan(".env")} file
|
|
1565
2107
|
`);
|
|
1566
2108
|
} else {
|
|
1567
2109
|
me(`
|
|
@@ -1576,9 +2118,12 @@ var init = async ({
|
|
|
1576
2118
|
}
|
|
1577
2119
|
};
|
|
1578
2120
|
var exec3 = util.promisify(child_process.exec);
|
|
1579
|
-
var execWithTimeout = async (command, timeoutMs
|
|
2121
|
+
var execWithTimeout = async (command, timeoutMs) => {
|
|
1580
2122
|
try {
|
|
1581
2123
|
const promise = exec3(command, { killSignal: "SIGTERM" });
|
|
2124
|
+
if (!timeoutMs) {
|
|
2125
|
+
return await promise;
|
|
2126
|
+
}
|
|
1582
2127
|
let timeoutId;
|
|
1583
2128
|
const timeout = new Promise((_, reject) => {
|
|
1584
2129
|
timeoutId = setTimeout(() => reject(new Error("Command timed out")), timeoutMs);
|
|
@@ -1599,9 +2144,28 @@ var execWithTimeout = async (command, timeoutMs = 18e4) => {
|
|
|
1599
2144
|
throw error;
|
|
1600
2145
|
}
|
|
1601
2146
|
};
|
|
1602
|
-
|
|
2147
|
+
async function installMastraDependency(pm, dependency, versionTag, isDev, timeout) {
|
|
2148
|
+
let installCommand = getPackageManagerInstallCommand(pm);
|
|
2149
|
+
if (isDev) {
|
|
2150
|
+
installCommand = `${installCommand} --save-dev`;
|
|
2151
|
+
}
|
|
2152
|
+
try {
|
|
2153
|
+
await execWithTimeout(`${pm} ${installCommand} ${dependency}${versionTag}`, timeout);
|
|
2154
|
+
} catch (err) {
|
|
2155
|
+
console.log("err", err);
|
|
2156
|
+
if (versionTag === "@latest") {
|
|
2157
|
+
throw err;
|
|
2158
|
+
}
|
|
2159
|
+
await execWithTimeout(`${pm} ${installCommand} ${dependency}@latest`, timeout);
|
|
2160
|
+
}
|
|
2161
|
+
}
|
|
2162
|
+
var createMastraProject = async ({
|
|
2163
|
+
projectName: name,
|
|
2164
|
+
createVersionTag,
|
|
2165
|
+
timeout
|
|
2166
|
+
}) => {
|
|
1603
2167
|
pe(color2.inverse("Mastra Create"));
|
|
1604
|
-
const projectName = await ae({
|
|
2168
|
+
const projectName = name ?? await ae({
|
|
1605
2169
|
message: "What do you want to name your project?",
|
|
1606
2170
|
placeholder: "my-mastra-app",
|
|
1607
2171
|
defaultValue: "my-mastra-app"
|
|
@@ -1629,14 +2193,17 @@ var createMastraProject = async ({ createVersionTag }) => {
|
|
|
1629
2193
|
s2.message("Creating project");
|
|
1630
2194
|
await exec3(`npm init -y`);
|
|
1631
2195
|
await exec3(`npm pkg set type="module"`);
|
|
2196
|
+
await exec3(`npm pkg set engines.node=">=20.9.0"`);
|
|
1632
2197
|
const depsService = new DepsService();
|
|
1633
2198
|
await depsService.addScriptsToPackageJson({
|
|
1634
|
-
dev: "mastra dev"
|
|
2199
|
+
dev: "mastra dev",
|
|
2200
|
+
build: "mastra build",
|
|
2201
|
+
start: "mastra start"
|
|
1635
2202
|
});
|
|
1636
2203
|
s2.stop("Project created");
|
|
1637
2204
|
s2.start(`Installing ${pm} dependencies`);
|
|
1638
2205
|
await exec3(`${pm} ${installCommand} zod`);
|
|
1639
|
-
await exec3(`${pm} ${installCommand} typescript
|
|
2206
|
+
await exec3(`${pm} ${installCommand} typescript @types/node --save-dev`);
|
|
1640
2207
|
await exec3(`echo '{
|
|
1641
2208
|
"compilerOptions": {
|
|
1642
2209
|
"target": "ES2022",
|
|
@@ -1646,25 +2213,23 @@ var createMastraProject = async ({ createVersionTag }) => {
|
|
|
1646
2213
|
"forceConsistentCasingInFileNames": true,
|
|
1647
2214
|
"strict": true,
|
|
1648
2215
|
"skipLibCheck": true,
|
|
2216
|
+
"noEmit": true,
|
|
1649
2217
|
"outDir": "dist"
|
|
1650
2218
|
},
|
|
1651
2219
|
"include": [
|
|
1652
2220
|
"src/**/*"
|
|
1653
|
-
],
|
|
1654
|
-
"exclude": [
|
|
1655
|
-
"node_modules",
|
|
1656
|
-
"dist",
|
|
1657
|
-
".mastra"
|
|
1658
2221
|
]
|
|
1659
2222
|
}' > tsconfig.json`);
|
|
1660
2223
|
s2.stop(`${pm} dependencies installed`);
|
|
1661
2224
|
s2.start("Installing mastra");
|
|
1662
2225
|
const versionTag = createVersionTag ? `@${createVersionTag}` : "@latest";
|
|
1663
|
-
await
|
|
2226
|
+
await installMastraDependency(pm, "mastra", versionTag, true, timeout);
|
|
1664
2227
|
s2.stop("mastra installed");
|
|
1665
|
-
s2.start("Installing
|
|
1666
|
-
await
|
|
1667
|
-
|
|
2228
|
+
s2.start("Installing dependencies");
|
|
2229
|
+
await installMastraDependency(pm, "@mastra/core", versionTag, false, timeout);
|
|
2230
|
+
await installMastraDependency(pm, "@mastra/libsql", versionTag, false, timeout);
|
|
2231
|
+
await installMastraDependency(pm, "@mastra/memory", versionTag, false, timeout);
|
|
2232
|
+
s2.stop("Dependencies installed");
|
|
1668
2233
|
s2.start("Adding .gitignore");
|
|
1669
2234
|
await exec3(`echo output.txt >> .gitignore`);
|
|
1670
2235
|
await exec3(`echo node_modules >> .gitignore`);
|
|
@@ -1673,17 +2238,20 @@ var createMastraProject = async ({ createVersionTag }) => {
|
|
|
1673
2238
|
await exec3(`echo .env.development >> .gitignore`);
|
|
1674
2239
|
await exec3(`echo .env >> .gitignore`);
|
|
1675
2240
|
await exec3(`echo *.db >> .gitignore`);
|
|
2241
|
+
await exec3(`echo *.db-* >> .gitignore`);
|
|
1676
2242
|
s2.stop(".gitignore added");
|
|
1677
2243
|
ge("Project created successfully");
|
|
1678
2244
|
console.log("");
|
|
1679
2245
|
return { projectName };
|
|
1680
2246
|
};
|
|
1681
|
-
var create = async (
|
|
2247
|
+
var create = async (args2) => {
|
|
1682
2248
|
const { projectName } = await createMastraProject({
|
|
1683
|
-
|
|
2249
|
+
projectName: args2?.projectName,
|
|
2250
|
+
createVersionTag: args2?.createVersionTag,
|
|
2251
|
+
timeout: args2?.timeout
|
|
1684
2252
|
});
|
|
1685
|
-
const directory = "/
|
|
1686
|
-
if (
|
|
2253
|
+
const directory = args2.directory || "src/";
|
|
2254
|
+
if (args2.components === void 0 || args2.llmProvider === void 0 || args2.addExample === void 0) {
|
|
1687
2255
|
const result = await interactivePrompt();
|
|
1688
2256
|
await init({
|
|
1689
2257
|
...result,
|
|
@@ -1692,75 +2260,43 @@ var create = async (args) => {
|
|
|
1692
2260
|
postCreate({ projectName });
|
|
1693
2261
|
return;
|
|
1694
2262
|
}
|
|
1695
|
-
const { components = [], llmProvider = "openai", addExample = false, llmApiKey } =
|
|
2263
|
+
const { components = [], llmProvider = "openai", addExample = false, llmApiKey } = args2;
|
|
1696
2264
|
await init({
|
|
1697
2265
|
directory,
|
|
1698
2266
|
components,
|
|
1699
2267
|
llmProvider,
|
|
1700
2268
|
addExample,
|
|
1701
|
-
llmApiKey
|
|
2269
|
+
llmApiKey,
|
|
2270
|
+
configureEditorWithDocsMCP: args2.mcpServer
|
|
1702
2271
|
});
|
|
1703
2272
|
postCreate({ projectName });
|
|
1704
2273
|
};
|
|
1705
2274
|
var postCreate = ({ projectName }) => {
|
|
2275
|
+
const packageManager = getPackageManager();
|
|
1706
2276
|
ge(`
|
|
1707
2277
|
${color2.green("To start your project:")}
|
|
1708
2278
|
|
|
1709
2279
|
${color2.cyan("cd")} ${projectName}
|
|
1710
|
-
${color2.cyan(
|
|
2280
|
+
${color2.cyan(`${packageManager} run dev`)}
|
|
1711
2281
|
`);
|
|
1712
2282
|
};
|
|
1713
2283
|
|
|
1714
2284
|
async function getPackageVersion() {
|
|
1715
2285
|
const __filename = fileURLToPath(import.meta.url);
|
|
1716
2286
|
const __dirname = dirname(__filename);
|
|
1717
|
-
const pkgJsonPath =
|
|
2287
|
+
const pkgJsonPath = path2.join(__dirname, "..", "package.json");
|
|
1718
2288
|
const content = await fsExtra.readJSON(pkgJsonPath);
|
|
1719
2289
|
return content.version;
|
|
1720
2290
|
}
|
|
1721
|
-
async function tryReadPackageJson(paths) {
|
|
1722
|
-
let lastError;
|
|
1723
|
-
for (const path2 of paths) {
|
|
1724
|
-
try {
|
|
1725
|
-
const content = await fsExtra.readJSON(path2);
|
|
1726
|
-
if (content.name === "create-mastra") {
|
|
1727
|
-
return content;
|
|
1728
|
-
}
|
|
1729
|
-
} catch (err) {
|
|
1730
|
-
lastError = err;
|
|
1731
|
-
continue;
|
|
1732
|
-
}
|
|
1733
|
-
}
|
|
1734
|
-
throw lastError || new Error("Could not find create-mastra package.json in any of the expected locations");
|
|
1735
|
-
}
|
|
1736
2291
|
async function getCreateVersionTag() {
|
|
1737
2292
|
try {
|
|
1738
|
-
const
|
|
1739
|
-
const
|
|
1740
|
-
const
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
path.join(binDir, "..", "..", "..", "..", "package.json"),
|
|
1746
|
-
// Standard node_modules paths
|
|
1747
|
-
path.join(binDir, "..", "create-mastra", "package.json"),
|
|
1748
|
-
path.join(binDir, "..", "..", "create-mastra", "package.json"),
|
|
1749
|
-
path.join(binDir, "..", "..", "..", "create-mastra", "package.json"),
|
|
1750
|
-
path.join(binDir, "..", "..", "..", "..", "create-mastra", "package.json"),
|
|
1751
|
-
// pnpm specific paths (.pnpm directory)
|
|
1752
|
-
path.join(binDir, "..", ".pnpm", "create-mastra@*", "node_modules", "create-mastra", "package.json"),
|
|
1753
|
-
path.join(binDir, "..", "..", ".pnpm", "create-mastra@*", "node_modules", "create-mastra", "package.json"),
|
|
1754
|
-
// pnpm dlx specific path
|
|
1755
|
-
path.join(binDir, "..", "..", "package.json"),
|
|
1756
|
-
path.join(binDir, "..", "..", "node_modules", "create-mastra", "package.json")
|
|
1757
|
-
];
|
|
1758
|
-
const content = await tryReadPackageJson(possiblePaths);
|
|
1759
|
-
if (content.version?.includes("-")) {
|
|
1760
|
-
const tag = content.version.split("-")[1].split(".")[0];
|
|
1761
|
-
return tag;
|
|
1762
|
-
}
|
|
1763
|
-
} catch (error) {
|
|
2293
|
+
const pkgPath = fileURLToPath(import.meta.resolve("create-mastra/package.json"));
|
|
2294
|
+
const json = await fsExtra.readJSON(pkgPath);
|
|
2295
|
+
const { stdout } = await execa("npm", ["dist-tag", "create-mastra"]);
|
|
2296
|
+
const tagLine = stdout.split("\n").find((distLine) => distLine.endsWith(`: ${json.version}`));
|
|
2297
|
+
const tag = tagLine ? tagLine.split(":")[0].trim() : "latest";
|
|
2298
|
+
return tag;
|
|
2299
|
+
} catch {
|
|
1764
2300
|
console.error('We could not resolve the create-mastra version tag, falling back to "latest"');
|
|
1765
2301
|
}
|
|
1766
2302
|
return "latest";
|
|
@@ -1780,16 +2316,23 @@ program.version(`${version}`, "-v, --version").description(`create-mastra ${vers
|
|
|
1780
2316
|
command: "version"
|
|
1781
2317
|
});
|
|
1782
2318
|
console.log(`create-mastra ${version}`);
|
|
1783
|
-
} catch
|
|
2319
|
+
} catch {
|
|
1784
2320
|
}
|
|
1785
2321
|
});
|
|
1786
|
-
program.name("create-mastra").description("Create a new Mastra project").
|
|
2322
|
+
program.name("create-mastra").description("Create a new Mastra project").argument("[project-name]", "Directory name of the project").option(
|
|
2323
|
+
"-p, --project-name <string>",
|
|
2324
|
+
"Project name that will be used in package.json and as the project directory name."
|
|
2325
|
+
).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) => {
|
|
2326
|
+
const projectName = projectNameArg || args.projectName;
|
|
2327
|
+
const timeout = args?.timeout ? args?.timeout === true ? 6e4 : parseInt(args?.timeout, 10) : void 0;
|
|
1787
2328
|
if (args.default) {
|
|
1788
2329
|
await create({
|
|
1789
2330
|
components: ["agents", "tools", "workflows"],
|
|
1790
2331
|
llmProvider: "openai",
|
|
1791
|
-
addExample:
|
|
1792
|
-
createVersionTag
|
|
2332
|
+
addExample: true,
|
|
2333
|
+
createVersionTag,
|
|
2334
|
+
timeout,
|
|
2335
|
+
mcpServer: args.mcp
|
|
1793
2336
|
});
|
|
1794
2337
|
return;
|
|
1795
2338
|
}
|
|
@@ -1798,7 +2341,11 @@ program.name("create-mastra").description("Create a new Mastra project").option(
|
|
|
1798
2341
|
llmProvider: args.llm,
|
|
1799
2342
|
addExample: args.example,
|
|
1800
2343
|
llmApiKey: args["llm-api-key"],
|
|
1801
|
-
createVersionTag
|
|
2344
|
+
createVersionTag,
|
|
2345
|
+
timeout,
|
|
2346
|
+
projectName,
|
|
2347
|
+
directory: args.dir,
|
|
2348
|
+
mcpServer: args.mcp
|
|
1802
2349
|
});
|
|
1803
2350
|
});
|
|
1804
2351
|
program.parse(process.argv);
|