create-mastra 0.0.0-storage-20250225005900 → 0.0.0-vector-query-sources-20250516172905
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 +386 -142
- package/dist/index.js.map +1 -1
- package/dist/templates/dev.entry.js +18 -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
|
@@ -5,21 +5,21 @@ 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
7
|
import path, { dirname } from 'node:path';
|
|
8
|
-
import { PostHog } from 'posthog-node';
|
|
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
|
+
import { Transform } from 'node:stream';
|
|
20
21
|
import pino from 'pino';
|
|
21
22
|
import pretty from 'pino-pretty';
|
|
22
|
-
import { Transform } from 'node:stream';
|
|
23
23
|
import fsExtra from 'fs-extra';
|
|
24
24
|
|
|
25
25
|
var __filename = fileURLToPath(import.meta.url);
|
|
@@ -41,7 +41,7 @@ var PosthogAnalytics = class {
|
|
|
41
41
|
const { distinctId, sessionId } = JSON.parse(readFileSync(cliConfigPath, "utf-8"));
|
|
42
42
|
this.distinctId = distinctId;
|
|
43
43
|
this.sessionId = sessionId;
|
|
44
|
-
} catch
|
|
44
|
+
} catch {
|
|
45
45
|
this.sessionId = randomUUID();
|
|
46
46
|
this.distinctId = this.getDistinctId();
|
|
47
47
|
}
|
|
@@ -64,14 +64,15 @@ var PosthogAnalytics = class {
|
|
|
64
64
|
writeCliConfig({ distinctId, sessionId }) {
|
|
65
65
|
try {
|
|
66
66
|
writeFileSync(path.join(__dirname, "mastra-cli.json"), JSON.stringify({ distinctId, sessionId }));
|
|
67
|
-
} catch
|
|
67
|
+
} catch {
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
initializePostHog(apiKey, host) {
|
|
71
71
|
this.client = new PostHog(apiKey, {
|
|
72
72
|
host,
|
|
73
73
|
flushAt: 1,
|
|
74
|
-
flushInterval: 0
|
|
74
|
+
flushInterval: 0,
|
|
75
|
+
disableGeoip: false
|
|
75
76
|
});
|
|
76
77
|
this.captureSessionStart();
|
|
77
78
|
process.on("exit", () => {
|
|
@@ -80,7 +81,7 @@ var PosthogAnalytics = class {
|
|
|
80
81
|
});
|
|
81
82
|
}
|
|
82
83
|
isTelemetryEnabled() {
|
|
83
|
-
if (process.env.
|
|
84
|
+
if (process.env.MASTRA_TELEMETRY_DISABLED) {
|
|
84
85
|
return false;
|
|
85
86
|
}
|
|
86
87
|
return true;
|
|
@@ -135,17 +136,19 @@ var PosthogAnalytics = class {
|
|
|
135
136
|
event: "cli_command",
|
|
136
137
|
properties: {
|
|
137
138
|
...this.getSystemProperties(),
|
|
138
|
-
...commandData
|
|
139
|
+
...commandData,
|
|
140
|
+
origin: options?.origin || "oss"
|
|
139
141
|
}
|
|
140
142
|
});
|
|
141
|
-
} catch
|
|
143
|
+
} catch {
|
|
142
144
|
}
|
|
143
145
|
}
|
|
144
146
|
// Helper method to wrap command execution with timing
|
|
145
147
|
async trackCommandExecution({
|
|
146
148
|
command,
|
|
147
149
|
args,
|
|
148
|
-
execution
|
|
150
|
+
execution,
|
|
151
|
+
origin
|
|
149
152
|
}) {
|
|
150
153
|
const startTime = process.hrtime();
|
|
151
154
|
try {
|
|
@@ -156,7 +159,8 @@ var PosthogAnalytics = class {
|
|
|
156
159
|
command,
|
|
157
160
|
args,
|
|
158
161
|
durationMs,
|
|
159
|
-
status: "success"
|
|
162
|
+
status: "success",
|
|
163
|
+
origin
|
|
160
164
|
});
|
|
161
165
|
return result;
|
|
162
166
|
} catch (error) {
|
|
@@ -167,7 +171,8 @@ var PosthogAnalytics = class {
|
|
|
167
171
|
args,
|
|
168
172
|
durationMs,
|
|
169
173
|
status: "error",
|
|
170
|
-
error: error instanceof Error ? error.message : String(error)
|
|
174
|
+
error: error instanceof Error ? error.message : String(error),
|
|
175
|
+
origin
|
|
171
176
|
});
|
|
172
177
|
throw error;
|
|
173
178
|
}
|
|
@@ -179,7 +184,7 @@ var PosthogAnalytics = class {
|
|
|
179
184
|
}
|
|
180
185
|
try {
|
|
181
186
|
await this.client.shutdown();
|
|
182
|
-
} catch
|
|
187
|
+
} catch {
|
|
183
188
|
}
|
|
184
189
|
}
|
|
185
190
|
};
|
|
@@ -352,14 +357,14 @@ function q({onlyFirst:e=false}={}){const F=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(
|
|
|
352
357
|
`).map(t=>oD(t,u,F)).join(`
|
|
353
358
|
`)}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
359
|
`),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(`
|
|
360
|
+
`),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(`
|
|
361
|
+
`),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
362
|
`).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
363
|
`);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
364
|
`).slice(t);this.output.write(s.join(`
|
|
360
365
|
`)),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
366
|
|
|
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)}
|
|
367
|
+
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
368
|
${y(this.state)} ${s.message}
|
|
364
369
|
`,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
370
|
${color2.yellow(a)} ${i}
|
|
@@ -404,7 +409,10 @@ ${color2.gray(ee+G.repeat(r+2)+te)}
|
|
|
404
409
|
`);},ge=(s="")=>{process.stdout.write(`${color2.gray(a)}
|
|
405
410
|
${color2.gray($)} ${s}
|
|
406
411
|
|
|
407
|
-
`);},
|
|
412
|
+
`);},v={message:(s="",{symbol:n=color2.gray(a)}={})=>{const t=[`${color2.gray(a)}`];if(s){const[i,...r]=s.split(`
|
|
413
|
+
`);t.push(`${n} ${i}`,...r.map(o=>`${color2.gray(a)} ${o}`));}process.stdout.write(`${t.join(`
|
|
414
|
+
`)}
|
|
415
|
+
`);},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
416
|
`);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
417
|
`),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
418
|
|
|
@@ -791,7 +799,14 @@ var Logger = class {
|
|
|
791
799
|
this.logger = pino(
|
|
792
800
|
{
|
|
793
801
|
name: options.name || "app",
|
|
794
|
-
level: options.level || LogLevel.INFO
|
|
802
|
+
level: options.level || LogLevel.INFO,
|
|
803
|
+
formatters: {
|
|
804
|
+
level: (label) => {
|
|
805
|
+
return {
|
|
806
|
+
level: label
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
}
|
|
795
810
|
},
|
|
796
811
|
options.overrideDefaultTransports ? options?.transports?.default : transportsAry.length === 0 ? pretty({
|
|
797
812
|
colorize: true,
|
|
@@ -801,7 +816,7 @@ var Logger = class {
|
|
|
801
816
|
translateTime: "SYS:standard",
|
|
802
817
|
singleLine: false
|
|
803
818
|
}) : pino.multistream([
|
|
804
|
-
...transportsAry.map(([
|
|
819
|
+
...transportsAry.map(([, transport]) => ({
|
|
805
820
|
stream: transport,
|
|
806
821
|
level: options.level || LogLevel.INFO
|
|
807
822
|
})),
|
|
@@ -857,41 +872,6 @@ function createLogger(options) {
|
|
|
857
872
|
return new Logger(options);
|
|
858
873
|
}
|
|
859
874
|
|
|
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
875
|
var DepsService = class {
|
|
896
876
|
packageManager;
|
|
897
877
|
constructor() {
|
|
@@ -985,6 +965,143 @@ var DepsService = class {
|
|
|
985
965
|
await fs4.writeFile("package.json", JSON.stringify(packageJson, null, 2));
|
|
986
966
|
}
|
|
987
967
|
};
|
|
968
|
+
function getPackageManager() {
|
|
969
|
+
const userAgent = process.env.npm_config_user_agent || "";
|
|
970
|
+
const execPath = process.env.npm_execpath || "";
|
|
971
|
+
if (userAgent.includes("yarn")) {
|
|
972
|
+
return "yarn";
|
|
973
|
+
}
|
|
974
|
+
if (userAgent.includes("pnpm")) {
|
|
975
|
+
return "pnpm";
|
|
976
|
+
}
|
|
977
|
+
if (userAgent.includes("npm")) {
|
|
978
|
+
return "npm";
|
|
979
|
+
}
|
|
980
|
+
if (execPath.includes("yarn")) {
|
|
981
|
+
return "yarn";
|
|
982
|
+
}
|
|
983
|
+
if (execPath.includes("pnpm")) {
|
|
984
|
+
return "pnpm";
|
|
985
|
+
}
|
|
986
|
+
if (execPath.includes("npm")) {
|
|
987
|
+
return "npm";
|
|
988
|
+
}
|
|
989
|
+
return "npm";
|
|
990
|
+
}
|
|
991
|
+
function getPackageManagerInstallCommand(pm) {
|
|
992
|
+
switch (pm) {
|
|
993
|
+
case "npm":
|
|
994
|
+
return "install";
|
|
995
|
+
case "yarn":
|
|
996
|
+
return "add";
|
|
997
|
+
case "pnpm":
|
|
998
|
+
return "add";
|
|
999
|
+
default:
|
|
1000
|
+
return "install";
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
var args = ["-y", "@mastra/mcp-docs-server@latest"];
|
|
1004
|
+
var createMcpConfig = (editor) => {
|
|
1005
|
+
if (editor === "vscode") {
|
|
1006
|
+
return {
|
|
1007
|
+
servers: {
|
|
1008
|
+
mastra: process.platform === `win32` ? {
|
|
1009
|
+
command: "cmd",
|
|
1010
|
+
args: ["/c", "npx", ...args],
|
|
1011
|
+
type: "stdio"
|
|
1012
|
+
} : {
|
|
1013
|
+
command: "npx",
|
|
1014
|
+
args,
|
|
1015
|
+
type: "stdio"
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
};
|
|
1019
|
+
}
|
|
1020
|
+
return {
|
|
1021
|
+
mcpServers: {
|
|
1022
|
+
mastra: process.platform === `win32` ? {
|
|
1023
|
+
command: "cmd",
|
|
1024
|
+
args: ["/c", "npx", ...args]
|
|
1025
|
+
} : {
|
|
1026
|
+
command: "npx",
|
|
1027
|
+
args
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
};
|
|
1031
|
+
};
|
|
1032
|
+
function makeConfig(original, editor) {
|
|
1033
|
+
if (editor === "vscode") {
|
|
1034
|
+
return {
|
|
1035
|
+
...original,
|
|
1036
|
+
servers: {
|
|
1037
|
+
...original?.servers || {},
|
|
1038
|
+
...createMcpConfig(editor).servers
|
|
1039
|
+
}
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
return {
|
|
1043
|
+
...original,
|
|
1044
|
+
mcpServers: {
|
|
1045
|
+
...original?.mcpServers || {},
|
|
1046
|
+
...createMcpConfig(editor).mcpServers
|
|
1047
|
+
}
|
|
1048
|
+
};
|
|
1049
|
+
}
|
|
1050
|
+
async function writeMergedConfig(configPath, editor) {
|
|
1051
|
+
const configExists = existsSync(configPath);
|
|
1052
|
+
const config = makeConfig(configExists ? await readJSON(configPath) : {}, editor);
|
|
1053
|
+
await ensureFile(configPath);
|
|
1054
|
+
await writeJSON(configPath, config, {
|
|
1055
|
+
spaces: 2
|
|
1056
|
+
});
|
|
1057
|
+
}
|
|
1058
|
+
var windsurfGlobalMCPConfigPath = path.join(os.homedir(), ".codeium", "windsurf", "mcp_config.json");
|
|
1059
|
+
var cursorGlobalMCPConfigPath = path.join(os.homedir(), ".cursor", "mcp.json");
|
|
1060
|
+
path.join(process.cwd(), ".vscode", "mcp.json");
|
|
1061
|
+
async function installMastraDocsMCPServer({ editor, directory }) {
|
|
1062
|
+
if (editor === `cursor`) {
|
|
1063
|
+
await writeMergedConfig(path.join(directory, ".cursor", "mcp.json"), "cursor");
|
|
1064
|
+
}
|
|
1065
|
+
if (editor === `vscode`) {
|
|
1066
|
+
await writeMergedConfig(path.join(directory, ".vscode", "mcp.json"), "vscode");
|
|
1067
|
+
}
|
|
1068
|
+
if (editor === `cursor-global`) {
|
|
1069
|
+
const alreadyInstalled = await globalMCPIsAlreadyInstalled(editor);
|
|
1070
|
+
if (alreadyInstalled) {
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
await writeMergedConfig(cursorGlobalMCPConfigPath, "cursor-global");
|
|
1074
|
+
}
|
|
1075
|
+
if (editor === `windsurf`) {
|
|
1076
|
+
const alreadyInstalled = await globalMCPIsAlreadyInstalled(editor);
|
|
1077
|
+
if (alreadyInstalled) {
|
|
1078
|
+
return;
|
|
1079
|
+
}
|
|
1080
|
+
await writeMergedConfig(windsurfGlobalMCPConfigPath, editor);
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
async function globalMCPIsAlreadyInstalled(editor) {
|
|
1084
|
+
let configPath = ``;
|
|
1085
|
+
if (editor === "windsurf") {
|
|
1086
|
+
configPath = windsurfGlobalMCPConfigPath;
|
|
1087
|
+
} else if (editor === "cursor-global") {
|
|
1088
|
+
configPath = cursorGlobalMCPConfigPath;
|
|
1089
|
+
}
|
|
1090
|
+
if (!configPath || !existsSync(configPath)) {
|
|
1091
|
+
return false;
|
|
1092
|
+
}
|
|
1093
|
+
try {
|
|
1094
|
+
const configContents = await readJSON(configPath);
|
|
1095
|
+
if (!configContents?.mcpServers) return false;
|
|
1096
|
+
const hasMastraMCP = Object.values(configContents.mcpServers).some(
|
|
1097
|
+
(server) => server?.args?.find((arg) => arg?.includes(`@mastra/mcp-docs-server`))
|
|
1098
|
+
);
|
|
1099
|
+
return hasMastraMCP;
|
|
1100
|
+
} catch (e) {
|
|
1101
|
+
console.error(e);
|
|
1102
|
+
return false;
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
988
1105
|
var EnvService = class {
|
|
989
1106
|
};
|
|
990
1107
|
var FileEnvService = class extends EnvService {
|
|
@@ -1104,6 +1221,10 @@ var getAISDKPackage = (llmProvider) => {
|
|
|
1104
1221
|
return "@ai-sdk/anthropic";
|
|
1105
1222
|
case "groq":
|
|
1106
1223
|
return "@ai-sdk/groq";
|
|
1224
|
+
case "google":
|
|
1225
|
+
return "@ai-sdk/google";
|
|
1226
|
+
case "cerebras":
|
|
1227
|
+
return "@ai-sdk/cerebras";
|
|
1107
1228
|
default:
|
|
1108
1229
|
return "@ai-sdk/openai";
|
|
1109
1230
|
}
|
|
@@ -1119,7 +1240,13 @@ var getProviderImportAndModelItem = (llmProvider) => {
|
|
|
1119
1240
|
modelItem = `anthropic('claude-3-5-sonnet-20241022')`;
|
|
1120
1241
|
} else if (llmProvider === "groq") {
|
|
1121
1242
|
providerImport = `import { groq } from '${getAISDKPackage(llmProvider)}';`;
|
|
1122
|
-
modelItem = `groq('
|
|
1243
|
+
modelItem = `groq('llama-3.3-70b-versatile')`;
|
|
1244
|
+
} else if (llmProvider === "google") {
|
|
1245
|
+
providerImport = `import { google } from '${getAISDKPackage(llmProvider)}';`;
|
|
1246
|
+
modelItem = `google('gemini-1.5-pro-latest')`;
|
|
1247
|
+
} else if (llmProvider === "cerebras") {
|
|
1248
|
+
providerImport = `import { cerebras } from '${getAISDKPackage(llmProvider)}';`;
|
|
1249
|
+
modelItem = `cerebras('llama-3.3-70b')`;
|
|
1123
1250
|
}
|
|
1124
1251
|
return { providerImport, modelItem };
|
|
1125
1252
|
};
|
|
@@ -1130,6 +1257,7 @@ async function writeAgentSample(llmProvider, destPath, addExampleTool) {
|
|
|
1130
1257
|
|
|
1131
1258
|
Your primary function is to help users get weather details for specific locations. When responding:
|
|
1132
1259
|
- Always ask for a location if none is provided
|
|
1260
|
+
- If the location name isn\u2019t in English, please translate it
|
|
1133
1261
|
- If giving a location with multiple parts (e.g. "New York, NY"), use the most relevant part (e.g. "New York")
|
|
1134
1262
|
- Include relevant details like humidity, wind conditions, and precipitation
|
|
1135
1263
|
- Keep responses concise but informative
|
|
@@ -1137,8 +1265,10 @@ async function writeAgentSample(llmProvider, destPath, addExampleTool) {
|
|
|
1137
1265
|
${addExampleTool ? "Use the weatherTool to fetch current weather data." : ""}
|
|
1138
1266
|
`;
|
|
1139
1267
|
const content = `
|
|
1140
|
-
${providerImport}
|
|
1268
|
+
${providerImport}
|
|
1141
1269
|
import { Agent } from '@mastra/core/agent';
|
|
1270
|
+
import { Memory } from '@mastra/memory';
|
|
1271
|
+
import { LibSQLStore } from '@mastra/libsql';
|
|
1142
1272
|
${addExampleTool ? `import { weatherTool } from '../tools';` : ""}
|
|
1143
1273
|
|
|
1144
1274
|
export const weatherAgent = new Agent({
|
|
@@ -1146,6 +1276,18 @@ export const weatherAgent = new Agent({
|
|
|
1146
1276
|
instructions: \`${instructions}\`,
|
|
1147
1277
|
model: ${modelItem},
|
|
1148
1278
|
${addExampleTool ? "tools: { weatherTool }," : ""}
|
|
1279
|
+
memory: new Memory({
|
|
1280
|
+
storage: new LibSQLStore({
|
|
1281
|
+
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
|
+
}
|
|
1290
|
+
})
|
|
1149
1291
|
});
|
|
1150
1292
|
`;
|
|
1151
1293
|
const formattedContent = await prettier.format(content, {
|
|
@@ -1212,14 +1354,26 @@ const agent = new Agent({
|
|
|
1212
1354
|
\`,
|
|
1213
1355
|
});
|
|
1214
1356
|
|
|
1357
|
+
const forecastSchema = z.array(
|
|
1358
|
+
z.object({
|
|
1359
|
+
date: z.string(),
|
|
1360
|
+
maxTemp: z.number(),
|
|
1361
|
+
minTemp: z.number(),
|
|
1362
|
+
precipitationChance: z.number(),
|
|
1363
|
+
condition: z.string(),
|
|
1364
|
+
location: z.string(),
|
|
1365
|
+
}),
|
|
1366
|
+
);
|
|
1367
|
+
|
|
1215
1368
|
const fetchWeather = new Step({
|
|
1216
1369
|
id: 'fetch-weather',
|
|
1217
1370
|
description: 'Fetches weather forecast for a given city',
|
|
1218
1371
|
inputSchema: z.object({
|
|
1219
1372
|
city: z.string().describe('The city to get the weather for'),
|
|
1220
1373
|
}),
|
|
1374
|
+
outputSchema: forecastSchema,
|
|
1221
1375
|
execute: async ({ context }) => {
|
|
1222
|
-
const triggerData = context?.
|
|
1376
|
+
const triggerData = context?.getStepResult<{ city: string }>('trigger');
|
|
1223
1377
|
|
|
1224
1378
|
if (!triggerData) {
|
|
1225
1379
|
throw new Error('Trigger data not found');
|
|
@@ -1262,23 +1416,12 @@ const fetchWeather = new Step({
|
|
|
1262
1416
|
},
|
|
1263
1417
|
});
|
|
1264
1418
|
|
|
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
1419
|
|
|
1276
1420
|
const planActivities = new Step({
|
|
1277
1421
|
id: 'plan-activities',
|
|
1278
1422
|
description: 'Suggests activities based on weather conditions',
|
|
1279
|
-
inputSchema: forecastSchema,
|
|
1280
1423
|
execute: async ({ context, mastra }) => {
|
|
1281
|
-
const forecast = context?.
|
|
1424
|
+
const forecast = context?.getStepResult(fetchWeather);
|
|
1282
1425
|
|
|
1283
1426
|
if (!forecast || forecast.length === 0) {
|
|
1284
1427
|
throw new Error('Forecast data not found');
|
|
@@ -1295,12 +1438,15 @@ const planActivities = new Step({
|
|
|
1295
1438
|
},
|
|
1296
1439
|
]);
|
|
1297
1440
|
|
|
1441
|
+
let activitiesText = '';
|
|
1442
|
+
|
|
1298
1443
|
for await (const chunk of response.textStream) {
|
|
1299
1444
|
process.stdout.write(chunk);
|
|
1445
|
+
activitiesText += chunk;
|
|
1300
1446
|
}
|
|
1301
1447
|
|
|
1302
1448
|
return {
|
|
1303
|
-
activities:
|
|
1449
|
+
activities: activitiesText,
|
|
1304
1450
|
};
|
|
1305
1451
|
},
|
|
1306
1452
|
});
|
|
@@ -1396,11 +1542,16 @@ export const mastra = new Mastra()
|
|
|
1396
1542
|
`
|
|
1397
1543
|
import { Mastra } from '@mastra/core/mastra';
|
|
1398
1544
|
import { createLogger } from '@mastra/core/logger';
|
|
1545
|
+
import { LibSQLStore } from '@mastra/libsql';
|
|
1399
1546
|
${addWorkflow ? `import { weatherWorkflow } from './workflows';` : ""}
|
|
1400
1547
|
${addAgent ? `import { weatherAgent } from './agents';` : ""}
|
|
1401
1548
|
|
|
1402
1549
|
export const mastra = new Mastra({
|
|
1403
1550
|
${filteredExports.join("\n ")}
|
|
1551
|
+
storage: new LibSQLStore({
|
|
1552
|
+
// stores telemetry, evals, ... into memory storage, if it needs to persist, change to file:../mastra.db
|
|
1553
|
+
url: ":memory:",
|
|
1554
|
+
}),
|
|
1404
1555
|
logger: createLogger({
|
|
1405
1556
|
name: 'Mastra',
|
|
1406
1557
|
level: 'info',
|
|
@@ -1422,6 +1573,12 @@ var getAPIKey = async (provider) => {
|
|
|
1422
1573
|
case "groq":
|
|
1423
1574
|
key = "GROQ_API_KEY";
|
|
1424
1575
|
return key;
|
|
1576
|
+
case "google":
|
|
1577
|
+
key = "GOOGLE_GENERATIVE_AI_API_KEY";
|
|
1578
|
+
return key;
|
|
1579
|
+
case "cerebras":
|
|
1580
|
+
key = "CEREBRAS_API_KEY";
|
|
1581
|
+
return key;
|
|
1425
1582
|
default:
|
|
1426
1583
|
return key;
|
|
1427
1584
|
}
|
|
@@ -1480,7 +1637,9 @@ var interactivePrompt = async () => {
|
|
|
1480
1637
|
options: [
|
|
1481
1638
|
{ value: "openai", label: "OpenAI", hint: "recommended" },
|
|
1482
1639
|
{ value: "anthropic", label: "Anthropic" },
|
|
1483
|
-
{ value: "groq", label: "Groq" }
|
|
1640
|
+
{ value: "groq", label: "Groq" },
|
|
1641
|
+
{ value: "google", label: "Google" },
|
|
1642
|
+
{ value: "cerebras", label: "Cerebras" }
|
|
1484
1643
|
]
|
|
1485
1644
|
}),
|
|
1486
1645
|
llmApiKey: async ({ results: { llmProvider } }) => {
|
|
@@ -1503,7 +1662,71 @@ var interactivePrompt = async () => {
|
|
|
1503
1662
|
addExample: () => ce({
|
|
1504
1663
|
message: "Add example",
|
|
1505
1664
|
initialValue: false
|
|
1506
|
-
})
|
|
1665
|
+
}),
|
|
1666
|
+
configureEditorWithDocsMCP: async () => {
|
|
1667
|
+
const windsurfIsAlreadyInstalled = await globalMCPIsAlreadyInstalled(`windsurf`);
|
|
1668
|
+
const cursorIsAlreadyInstalled = await globalMCPIsAlreadyInstalled(`cursor`);
|
|
1669
|
+
const editor = await le({
|
|
1670
|
+
message: `Make your AI IDE into a Mastra expert? (installs Mastra docs MCP server)`,
|
|
1671
|
+
options: [
|
|
1672
|
+
{ value: "skip", label: "Skip for now", hint: "default" },
|
|
1673
|
+
{
|
|
1674
|
+
value: "cursor",
|
|
1675
|
+
label: "Cursor (project only)",
|
|
1676
|
+
hint: cursorIsAlreadyInstalled ? `Already installed globally` : void 0
|
|
1677
|
+
},
|
|
1678
|
+
{
|
|
1679
|
+
value: "cursor-global",
|
|
1680
|
+
label: "Cursor (global, all projects)",
|
|
1681
|
+
hint: cursorIsAlreadyInstalled ? `Already installed` : void 0
|
|
1682
|
+
},
|
|
1683
|
+
{
|
|
1684
|
+
value: "windsurf",
|
|
1685
|
+
label: "Windsurf",
|
|
1686
|
+
hint: windsurfIsAlreadyInstalled ? `Already installed` : void 0
|
|
1687
|
+
}
|
|
1688
|
+
]
|
|
1689
|
+
});
|
|
1690
|
+
if (editor === `skip`) return void 0;
|
|
1691
|
+
if (editor === `windsurf` && windsurfIsAlreadyInstalled) {
|
|
1692
|
+
v.message(`
|
|
1693
|
+
Windsurf is already installed, skipping.`);
|
|
1694
|
+
return void 0;
|
|
1695
|
+
}
|
|
1696
|
+
if (editor === `cursor`) {
|
|
1697
|
+
v.message(
|
|
1698
|
+
`
|
|
1699
|
+
Note: you will need to go into Cursor Settings -> MCP Settings and manually enable the installed Mastra MCP server.
|
|
1700
|
+
`
|
|
1701
|
+
);
|
|
1702
|
+
}
|
|
1703
|
+
if (editor === `cursor-global`) {
|
|
1704
|
+
const confirm2 = await le({
|
|
1705
|
+
message: `Global install will add/update ${cursorGlobalMCPConfigPath} and make the Mastra docs MCP server available in all your Cursor projects. Continue?`,
|
|
1706
|
+
options: [
|
|
1707
|
+
{ value: "yes", label: "Yes, I understand" },
|
|
1708
|
+
{ value: "skip", label: "No, skip for now" }
|
|
1709
|
+
]
|
|
1710
|
+
});
|
|
1711
|
+
if (confirm2 !== `yes`) {
|
|
1712
|
+
return void 0;
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
if (editor === `windsurf`) {
|
|
1716
|
+
const confirm2 = await le({
|
|
1717
|
+
message: `Windsurf only supports a global MCP config (at ${windsurfGlobalMCPConfigPath}) is it ok to add/update that global config?
|
|
1718
|
+
This means the Mastra docs MCP server will be available in all your Windsurf projects.`,
|
|
1719
|
+
options: [
|
|
1720
|
+
{ value: "yes", label: "Yes, I understand" },
|
|
1721
|
+
{ value: "skip", label: "No, skip for now" }
|
|
1722
|
+
]
|
|
1723
|
+
});
|
|
1724
|
+
if (confirm2 !== `yes`) {
|
|
1725
|
+
return void 0;
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
return editor;
|
|
1729
|
+
}
|
|
1507
1730
|
},
|
|
1508
1731
|
{
|
|
1509
1732
|
onCancel: () => {
|
|
@@ -1523,7 +1746,8 @@ var init = async ({
|
|
|
1523
1746
|
addExample = false,
|
|
1524
1747
|
components,
|
|
1525
1748
|
llmProvider = "openai",
|
|
1526
|
-
llmApiKey
|
|
1749
|
+
llmApiKey,
|
|
1750
|
+
configureEditorWithDocsMCP
|
|
1527
1751
|
}) => {
|
|
1528
1752
|
s.start("Initializing Mastra");
|
|
1529
1753
|
try {
|
|
@@ -1549,12 +1773,28 @@ var init = async ({
|
|
|
1549
1773
|
(component) => writeCodeSample(dirPath, component, llmProvider, components)
|
|
1550
1774
|
)
|
|
1551
1775
|
]);
|
|
1776
|
+
const depService = new DepsService();
|
|
1777
|
+
const needsLibsql = await depService.checkDependencies(["@mastra/libsql"]) !== `ok`;
|
|
1778
|
+
if (needsLibsql) {
|
|
1779
|
+
await depService.installPackages(["@mastra/libsql"]);
|
|
1780
|
+
}
|
|
1781
|
+
const needsMemory = components.includes(`agents`) && await depService.checkDependencies(["@mastra/memory"]) !== `ok`;
|
|
1782
|
+
if (needsMemory) {
|
|
1783
|
+
await depService.installPackages(["@mastra/memory"]);
|
|
1784
|
+
}
|
|
1552
1785
|
}
|
|
1553
1786
|
const key = await getAPIKey(llmProvider || "openai");
|
|
1554
1787
|
const aiSdkPackage = getAISDKPackage(llmProvider);
|
|
1555
|
-
const
|
|
1788
|
+
const depsService = new DepsService();
|
|
1789
|
+
const pm = depsService.packageManager;
|
|
1556
1790
|
const installCommand = getPackageManagerInstallCommand(pm);
|
|
1557
1791
|
await exec2(`${pm} ${installCommand} ${aiSdkPackage}`);
|
|
1792
|
+
if (configureEditorWithDocsMCP) {
|
|
1793
|
+
await installMastraDocsMCPServer({
|
|
1794
|
+
editor: configureEditorWithDocsMCP,
|
|
1795
|
+
directory: process.cwd()
|
|
1796
|
+
});
|
|
1797
|
+
}
|
|
1558
1798
|
s.stop();
|
|
1559
1799
|
if (!llmApiKey) {
|
|
1560
1800
|
me(`
|
|
@@ -1576,9 +1816,12 @@ var init = async ({
|
|
|
1576
1816
|
}
|
|
1577
1817
|
};
|
|
1578
1818
|
var exec3 = util.promisify(child_process.exec);
|
|
1579
|
-
var execWithTimeout = async (command, timeoutMs
|
|
1819
|
+
var execWithTimeout = async (command, timeoutMs) => {
|
|
1580
1820
|
try {
|
|
1581
1821
|
const promise = exec3(command, { killSignal: "SIGTERM" });
|
|
1822
|
+
if (!timeoutMs) {
|
|
1823
|
+
return await promise;
|
|
1824
|
+
}
|
|
1582
1825
|
let timeoutId;
|
|
1583
1826
|
const timeout = new Promise((_, reject) => {
|
|
1584
1827
|
timeoutId = setTimeout(() => reject(new Error("Command timed out")), timeoutMs);
|
|
@@ -1599,9 +1842,28 @@ var execWithTimeout = async (command, timeoutMs = 18e4) => {
|
|
|
1599
1842
|
throw error;
|
|
1600
1843
|
}
|
|
1601
1844
|
};
|
|
1602
|
-
|
|
1845
|
+
async function installMastraDependency(pm, dependency, versionTag, isDev, timeout) {
|
|
1846
|
+
let installCommand = getPackageManagerInstallCommand(pm);
|
|
1847
|
+
if (isDev) {
|
|
1848
|
+
installCommand = `${installCommand} --save-dev`;
|
|
1849
|
+
}
|
|
1850
|
+
try {
|
|
1851
|
+
await execWithTimeout(`${pm} ${installCommand} ${dependency}${versionTag}`, timeout);
|
|
1852
|
+
} catch (err) {
|
|
1853
|
+
console.log("err", err);
|
|
1854
|
+
if (versionTag === "@latest") {
|
|
1855
|
+
throw err;
|
|
1856
|
+
}
|
|
1857
|
+
await execWithTimeout(`${pm} ${installCommand} ${dependency}@latest`, timeout);
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
var createMastraProject = async ({
|
|
1861
|
+
projectName: name,
|
|
1862
|
+
createVersionTag,
|
|
1863
|
+
timeout
|
|
1864
|
+
}) => {
|
|
1603
1865
|
pe(color2.inverse("Mastra Create"));
|
|
1604
|
-
const projectName = await ae({
|
|
1866
|
+
const projectName = name ?? await ae({
|
|
1605
1867
|
message: "What do you want to name your project?",
|
|
1606
1868
|
placeholder: "my-mastra-app",
|
|
1607
1869
|
defaultValue: "my-mastra-app"
|
|
@@ -1629,14 +1891,16 @@ var createMastraProject = async ({ createVersionTag }) => {
|
|
|
1629
1891
|
s2.message("Creating project");
|
|
1630
1892
|
await exec3(`npm init -y`);
|
|
1631
1893
|
await exec3(`npm pkg set type="module"`);
|
|
1894
|
+
await exec3(`npm pkg set engines.node=">=20.9.0"`);
|
|
1632
1895
|
const depsService = new DepsService();
|
|
1633
1896
|
await depsService.addScriptsToPackageJson({
|
|
1634
|
-
dev: "mastra dev"
|
|
1897
|
+
dev: "mastra dev",
|
|
1898
|
+
build: "mastra build"
|
|
1635
1899
|
});
|
|
1636
1900
|
s2.stop("Project created");
|
|
1637
1901
|
s2.start(`Installing ${pm} dependencies`);
|
|
1638
1902
|
await exec3(`${pm} ${installCommand} zod`);
|
|
1639
|
-
await exec3(`${pm} ${installCommand} typescript
|
|
1903
|
+
await exec3(`${pm} ${installCommand} typescript @types/node --save-dev`);
|
|
1640
1904
|
await exec3(`echo '{
|
|
1641
1905
|
"compilerOptions": {
|
|
1642
1906
|
"target": "ES2022",
|
|
@@ -1646,25 +1910,23 @@ var createMastraProject = async ({ createVersionTag }) => {
|
|
|
1646
1910
|
"forceConsistentCasingInFileNames": true,
|
|
1647
1911
|
"strict": true,
|
|
1648
1912
|
"skipLibCheck": true,
|
|
1913
|
+
"noEmit": true,
|
|
1649
1914
|
"outDir": "dist"
|
|
1650
1915
|
},
|
|
1651
1916
|
"include": [
|
|
1652
1917
|
"src/**/*"
|
|
1653
|
-
],
|
|
1654
|
-
"exclude": [
|
|
1655
|
-
"node_modules",
|
|
1656
|
-
"dist",
|
|
1657
|
-
".mastra"
|
|
1658
1918
|
]
|
|
1659
1919
|
}' > tsconfig.json`);
|
|
1660
1920
|
s2.stop(`${pm} dependencies installed`);
|
|
1661
1921
|
s2.start("Installing mastra");
|
|
1662
1922
|
const versionTag = createVersionTag ? `@${createVersionTag}` : "@latest";
|
|
1663
|
-
await
|
|
1923
|
+
await installMastraDependency(pm, "mastra", versionTag, true, timeout);
|
|
1664
1924
|
s2.stop("mastra installed");
|
|
1665
|
-
s2.start("Installing
|
|
1666
|
-
await
|
|
1667
|
-
|
|
1925
|
+
s2.start("Installing dependencies");
|
|
1926
|
+
await installMastraDependency(pm, "@mastra/core", versionTag, false, timeout);
|
|
1927
|
+
await installMastraDependency(pm, "@mastra/libsql", versionTag, false, timeout);
|
|
1928
|
+
await installMastraDependency(pm, "@mastra/memory", versionTag, false, timeout);
|
|
1929
|
+
s2.stop("Dependencies installed");
|
|
1668
1930
|
s2.start("Adding .gitignore");
|
|
1669
1931
|
await exec3(`echo output.txt >> .gitignore`);
|
|
1670
1932
|
await exec3(`echo node_modules >> .gitignore`);
|
|
@@ -1673,17 +1935,20 @@ var createMastraProject = async ({ createVersionTag }) => {
|
|
|
1673
1935
|
await exec3(`echo .env.development >> .gitignore`);
|
|
1674
1936
|
await exec3(`echo .env >> .gitignore`);
|
|
1675
1937
|
await exec3(`echo *.db >> .gitignore`);
|
|
1938
|
+
await exec3(`echo *.db-* >> .gitignore`);
|
|
1676
1939
|
s2.stop(".gitignore added");
|
|
1677
1940
|
ge("Project created successfully");
|
|
1678
1941
|
console.log("");
|
|
1679
1942
|
return { projectName };
|
|
1680
1943
|
};
|
|
1681
|
-
var create = async (
|
|
1944
|
+
var create = async (args2) => {
|
|
1682
1945
|
const { projectName } = await createMastraProject({
|
|
1683
|
-
|
|
1946
|
+
projectName: args2?.projectName,
|
|
1947
|
+
createVersionTag: args2?.createVersionTag,
|
|
1948
|
+
timeout: args2?.timeout
|
|
1684
1949
|
});
|
|
1685
|
-
const directory = "/
|
|
1686
|
-
if (
|
|
1950
|
+
const directory = args2.directory || "src/";
|
|
1951
|
+
if (args2.components === void 0 || args2.llmProvider === void 0 || args2.addExample === void 0) {
|
|
1687
1952
|
const result = await interactivePrompt();
|
|
1688
1953
|
await init({
|
|
1689
1954
|
...result,
|
|
@@ -1692,22 +1957,24 @@ var create = async (args) => {
|
|
|
1692
1957
|
postCreate({ projectName });
|
|
1693
1958
|
return;
|
|
1694
1959
|
}
|
|
1695
|
-
const { components = [], llmProvider = "openai", addExample = false, llmApiKey } =
|
|
1960
|
+
const { components = [], llmProvider = "openai", addExample = false, llmApiKey } = args2;
|
|
1696
1961
|
await init({
|
|
1697
1962
|
directory,
|
|
1698
1963
|
components,
|
|
1699
1964
|
llmProvider,
|
|
1700
1965
|
addExample,
|
|
1701
|
-
llmApiKey
|
|
1966
|
+
llmApiKey,
|
|
1967
|
+
configureEditorWithDocsMCP: args2.mcpServer
|
|
1702
1968
|
});
|
|
1703
1969
|
postCreate({ projectName });
|
|
1704
1970
|
};
|
|
1705
1971
|
var postCreate = ({ projectName }) => {
|
|
1972
|
+
const packageManager = getPackageManager();
|
|
1706
1973
|
ge(`
|
|
1707
1974
|
${color2.green("To start your project:")}
|
|
1708
1975
|
|
|
1709
1976
|
${color2.cyan("cd")} ${projectName}
|
|
1710
|
-
${color2.cyan(
|
|
1977
|
+
${color2.cyan(`${packageManager} run dev`)}
|
|
1711
1978
|
`);
|
|
1712
1979
|
};
|
|
1713
1980
|
|
|
@@ -1718,49 +1985,15 @@ async function getPackageVersion() {
|
|
|
1718
1985
|
const content = await fsExtra.readJSON(pkgJsonPath);
|
|
1719
1986
|
return content.version;
|
|
1720
1987
|
}
|
|
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
1988
|
async function getCreateVersionTag() {
|
|
1737
1989
|
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) {
|
|
1990
|
+
const pkgPath = fileURLToPath(import.meta.resolve("create-mastra/package.json"));
|
|
1991
|
+
const json = await fsExtra.readJSON(pkgPath);
|
|
1992
|
+
const { stdout } = await execa("npm", ["dist-tag", "create-mastra"]);
|
|
1993
|
+
const tagLine = stdout.split("\n").find((distLine) => distLine.includes(`: ${json.version}`));
|
|
1994
|
+
const tag = tagLine ? tagLine.split(":")[0].trim() : "latest";
|
|
1995
|
+
return tag;
|
|
1996
|
+
} catch {
|
|
1764
1997
|
console.error('We could not resolve the create-mastra version tag, falling back to "latest"');
|
|
1765
1998
|
}
|
|
1766
1999
|
return "latest";
|
|
@@ -1780,16 +2013,23 @@ program.version(`${version}`, "-v, --version").description(`create-mastra ${vers
|
|
|
1780
2013
|
command: "version"
|
|
1781
2014
|
});
|
|
1782
2015
|
console.log(`create-mastra ${version}`);
|
|
1783
|
-
} catch
|
|
2016
|
+
} catch {
|
|
1784
2017
|
}
|
|
1785
2018
|
});
|
|
1786
|
-
program.name("create-mastra").description("Create a new Mastra project").
|
|
2019
|
+
program.name("create-mastra").description("Create a new Mastra project").argument("[project-name]", "Directory name of the project").option(
|
|
2020
|
+
"-p, --project-name <string>",
|
|
2021
|
+
"Project name that will be used in package.json and as the project directory name."
|
|
2022
|
+
).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) => {
|
|
2023
|
+
const projectName = projectNameArg || args.projectName;
|
|
2024
|
+
const timeout = args?.timeout ? args?.timeout === true ? 6e4 : parseInt(args?.timeout, 10) : void 0;
|
|
1787
2025
|
if (args.default) {
|
|
1788
2026
|
await create({
|
|
1789
2027
|
components: ["agents", "tools", "workflows"],
|
|
1790
2028
|
llmProvider: "openai",
|
|
1791
|
-
addExample:
|
|
1792
|
-
createVersionTag
|
|
2029
|
+
addExample: true,
|
|
2030
|
+
createVersionTag,
|
|
2031
|
+
timeout,
|
|
2032
|
+
mcpServer: args.mcp
|
|
1793
2033
|
});
|
|
1794
2034
|
return;
|
|
1795
2035
|
}
|
|
@@ -1798,7 +2038,11 @@ program.name("create-mastra").description("Create a new Mastra project").option(
|
|
|
1798
2038
|
llmProvider: args.llm,
|
|
1799
2039
|
addExample: args.example,
|
|
1800
2040
|
llmApiKey: args["llm-api-key"],
|
|
1801
|
-
createVersionTag
|
|
2041
|
+
createVersionTag,
|
|
2042
|
+
timeout,
|
|
2043
|
+
projectName,
|
|
2044
|
+
directory: args.dir,
|
|
2045
|
+
mcpServer: args.mcp
|
|
1802
2046
|
});
|
|
1803
2047
|
});
|
|
1804
2048
|
program.parse(process.argv);
|