mastra 0.1.57-unstable.56 → 0.1.57-unstable.88
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/create/create.d.ts +8 -0
- package/dist/commands/create/create.d.ts.map +1 -0
- package/dist/commands/create/create.js +35 -0
- package/dist/commands/create/utils.d.ts +4 -0
- package/dist/commands/create/utils.d.ts.map +1 -0
- package/dist/commands/create/utils.js +58 -0
- package/dist/commands/deploy/cloudflare/index.d.ts.map +1 -1
- package/dist/commands/deploy/cloudflare/index.js +2 -0
- package/dist/commands/deploy/deployer.d.ts +4 -2
- package/dist/commands/deploy/deployer.d.ts.map +1 -1
- package/dist/commands/deploy/deployer.js +4 -4
- package/dist/commands/deploy/index.d.ts +2 -1
- package/dist/commands/deploy/index.d.ts.map +1 -1
- package/dist/commands/deploy/index.js +2 -2
- package/dist/commands/deploy/netlify/index.d.ts.map +1 -1
- package/dist/commands/deploy/netlify/index.js +2 -0
- package/dist/commands/deploy/vercel/index.d.ts +2 -1
- package/dist/commands/deploy/vercel/index.d.ts.map +1 -1
- package/dist/commands/deploy/vercel/index.js +4 -1
- package/dist/commands/dev.d.ts +1 -7
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +117 -12
- package/dist/commands/engine/down.d.ts +1 -1
- package/dist/commands/engine/down.d.ts.map +1 -1
- package/dist/commands/engine/down.js +3 -2
- package/dist/commands/engine/up.d.ts +1 -1
- package/dist/commands/engine/up.d.ts.map +1 -1
- package/dist/commands/engine/up.js +3 -2
- package/dist/commands/init/init.d.ts +2 -2
- package/dist/commands/init/init.d.ts.map +1 -1
- package/dist/commands/init/init.js +33 -9
- package/dist/commands/init/utils.d.ts +21 -9
- package/dist/commands/init/utils.d.ts.map +1 -1
- package/dist/commands/init/utils.js +64 -74
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +57 -57
- package/dist/services/service.deps.d.ts +1 -0
- package/dist/services/service.deps.d.ts.map +1 -1
- package/dist/services/service.deps.js +8 -0
- package/dist/services/service.docker.d.ts +1 -0
- package/dist/services/service.docker.d.ts.map +1 -1
- package/dist/services/service.docker.js +20 -0
- package/dist/src/starter-files/config.ts +28 -0
- package/dist/src/starter-files/mastra-pg.docker-compose.yaml +15 -0
- package/dist/src/starter-files/tools.ts +95 -0
- package/dist/src/starter-files/workflow.ts +173 -0
- package/dist/templates/express-server.d.ts.map +1 -1
- package/dist/templates/express-server.js +70 -43
- package/dist/templates/netlify.d.ts.map +1 -1
- package/dist/templates/netlify.js +199 -34
- package/dist/templates/worker.d.ts.map +1 -1
- package/dist/templates/worker.js +255 -35
- package/dist/utils/bundle.d.ts +4 -1
- package/dist/utils/bundle.d.ts.map +1 -1
- package/dist/utils/bundle.js +28 -13
- package/package.json +7 -3
- package/src/playground/dist/assets/dark-plus-C3mMm8J8.js +1 -0
- package/src/playground/dist/assets/erb-BgreK6rt.js +1 -0
- package/src/playground/dist/assets/{gdresource-D_y5yz_M.js → gdresource-NFcQ0Q3Z.js} +1 -1
- package/src/playground/dist/assets/gdscript-BVlVXSjx.js +1 -0
- package/src/playground/dist/assets/{hcl-Cztwc-HH.js → hcl-_Zu0RE-q.js} +1 -1
- package/src/playground/dist/assets/index-BiEU7Tmg.js +389 -0
- package/src/playground/dist/assets/index-Cke4BidO.js +13 -0
- package/src/playground/dist/assets/light-plus-B7mTdjB0.js +1 -0
- package/src/playground/dist/assets/{monokai-CQWsIgnU.js → monokai-D4h5O-jR.js} +1 -1
- package/src/playground/dist/assets/prisma-CZzQMiei.js +1 -0
- package/src/playground/dist/assets/red-bN70gL4F.js +1 -0
- package/src/playground/dist/assets/rst-BCmapc_q.js +1 -0
- package/src/playground/dist/assets/ruby-DsC6krmi.js +1 -0
- package/src/playground/dist/assets/{solarized-dark-CmY0Y6Yh.js → solarized-dark-DXbdFlpD.js} +1 -1
- package/src/playground/dist/assets/{solarized-light-DZQMDcrx.js → solarized-light-L9t79GZl.js} +1 -1
- package/src/playground/dist/assets/style-7CS44jOg.css +1 -0
- package/src/playground/dist/assets/twig-CvAdjvFj.js +1 -0
- package/src/playground/dist/assets/{vue-html-x3hEOujm.js → vue-html-59TQSa_j.js} +1 -1
- package/src/playground/dist/assets/vue-srE0XGv_.js +1 -0
- package/src/playground/dist/index.html +2 -2
- package/src/starter-files/tools.ts +88 -14
- package/src/starter-files/workflow.ts +160 -21
- package/src/playground/dist/assets/dark-plus-B74Y8nHz.js +0 -1
- package/src/playground/dist/assets/erb-DuefeV9w.js +0 -1
- package/src/playground/dist/assets/gdscript-BIguuW30.js +0 -1
- package/src/playground/dist/assets/index-CzqDlQul.js +0 -13
- package/src/playground/dist/assets/index-qFy09kRJ.js +0 -360
- package/src/playground/dist/assets/light-plus-w1el_4yc.js +0 -1
- package/src/playground/dist/assets/prisma-DFIOpqzz.js +0 -1
- package/src/playground/dist/assets/red-2pWuV6-S.js +0 -1
- package/src/playground/dist/assets/rst-BtGMdPX_.js +0 -1
- package/src/playground/dist/assets/ruby-C8Yez0Ov.js +0 -1
- package/src/playground/dist/assets/style-x_8NJ6Q9.css +0 -1
- package/src/playground/dist/assets/twig-DN6YEzOP.js +0 -1
- package/src/playground/dist/assets/vue-xldAUJov.js +0 -1
- package/src/starter-files/api.ts +0 -11
- package/src/starter-files/framework-utils.ts +0 -33
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/commands/init/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/commands/init/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAiB3C,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,WAAW,GAAG,MAAM,CAAC;AAC1D,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,WAAW,GAAG,OAAO,CAAC;AAE1D,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,WAAW,EAAE,WAAW,CAI7D,CAAC;AAEF,wBAAsB,gBAAgB,CAAC,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,iBA8BzG;AAED,wBAAsB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,iBAGzD;AAED,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,iBAGrD;AAED,wBAAsB,4BAA4B,CAChD,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,UAAU,EACrB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,UAAU,EAAE,sBAYzB;AAED,eAAO,MAAM,mBAAmB,YAAmB,MAAM,aAAa,MAAM,kBAI3E,CAAC;AAEF,eAAO,MAAM,cAAc,oDAKxB;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;CACnB,kBAwCA,CAAC;AAEF,eAAO,MAAM,mBAAmB,YAAmB,MAAM,qBAOxD,CAAC;AAEF,eAAO,MAAM,uBAAuB,qBAOnC,CAAC;AAGF,wBAAsB,eAAe,kBA0BpC;AAED,eAAO,MAAM,SAAS,aAAoB,WAAW,oBAYpD,CAAC;AAEF,eAAO,MAAM,WAAW,0BAGrB;IACD,QAAQ,EAAE,WAAW,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,kBAGA,CAAC;AACF,eAAO,MAAM,eAAe,cAAqB,MAAM,KAAG,OAAO,CAAC;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAA;CAAE,CAe9G,CAAC;AAEF,eAAO,MAAM,eAAe,YACjB,MAAM,aACJ,UAAU,eACR,WAAW,cACZ,UAAU,EAAE,kBASzB,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;;;EAuE7B,CAAC;AAEF,eAAO,MAAM,YAAY,qBAmBxB,CAAC"}
|
|
@@ -10,22 +10,33 @@ import fs from 'fs/promises';
|
|
|
10
10
|
import { DepsService } from '../../services/service.deps.js';
|
|
11
11
|
import { FileService } from '../../services/service.file.js';
|
|
12
12
|
import { logger } from '../../utils/logger.js';
|
|
13
|
-
import { init } from './init.js';
|
|
14
13
|
const exec = util.promisify(child_process.exec);
|
|
15
14
|
export const modelToConfigMap = {
|
|
16
15
|
openai: { provider: 'OPEN_AI', name: 'gpt-4o', toolChoice: 'auto' },
|
|
17
16
|
anthropic: { provider: 'ANTHROPIC', name: 'claude-3-5-sonnet-20241022', toolChoice: 'auto' },
|
|
18
17
|
groq: { provider: 'GROQ', name: 'llama3-groq-70b-8192-tool-use-preview', toolChoice: 'auto' },
|
|
19
18
|
};
|
|
20
|
-
export async function writeAgentSample(llmProvider, destPath) {
|
|
19
|
+
export async function writeAgentSample(llmProvider, destPath, addExampleTool) {
|
|
21
20
|
const model = modelToConfigMap[llmProvider];
|
|
21
|
+
const instructions = `
|
|
22
|
+
You are a helpful weather assistant that provides accurate weather information.
|
|
23
|
+
|
|
24
|
+
Your primary function is to help users get weather details for specific locations. When responding:
|
|
25
|
+
- Always ask for a location if none is provided
|
|
26
|
+
- Include relevant details like humidity, wind conditions, and precipitation
|
|
27
|
+
- Keep responses concise but informative
|
|
28
|
+
|
|
29
|
+
${addExampleTool ? 'Use the weatherTool to fetch current weather data.' : ''}
|
|
30
|
+
`;
|
|
22
31
|
const content = `
|
|
23
32
|
import { Agent } from '@mastra/core';
|
|
33
|
+
${addExampleTool ? `import { weatherTool } from '../tools';` : ''}
|
|
24
34
|
|
|
25
|
-
export const
|
|
26
|
-
name: '
|
|
27
|
-
instructions:
|
|
35
|
+
export const weatherAgent = new Agent({
|
|
36
|
+
name: 'Weather Agent',
|
|
37
|
+
instructions: \`${instructions}\`,
|
|
28
38
|
model: ${JSON.stringify(model, null, 2)},
|
|
39
|
+
${addExampleTool ? 'tools: { weatherTool },' : ''}
|
|
29
40
|
});
|
|
30
41
|
`;
|
|
31
42
|
const formattedContent = await prettier.format(content, {
|
|
@@ -43,13 +54,13 @@ export async function writeToolSample(destPath) {
|
|
|
43
54
|
const fileService = new FileService();
|
|
44
55
|
await fileService.copyStarterFile('tools.ts', destPath);
|
|
45
56
|
}
|
|
46
|
-
export async function writeCodeSampleForComponents(llmprovider, component, destPath) {
|
|
47
|
-
switch (
|
|
48
|
-
case
|
|
49
|
-
return writeAgentSample(llmprovider, destPath);
|
|
50
|
-
case
|
|
57
|
+
export async function writeCodeSampleForComponents(llmprovider, component, destPath, components) {
|
|
58
|
+
switch (component) {
|
|
59
|
+
case 'agents':
|
|
60
|
+
return writeAgentSample(llmprovider, destPath, components.includes('tools'));
|
|
61
|
+
case 'tools':
|
|
51
62
|
return writeToolSample(destPath);
|
|
52
|
-
case
|
|
63
|
+
case 'workflows':
|
|
53
64
|
return writeWorkflowSample(destPath);
|
|
54
65
|
default:
|
|
55
66
|
return '';
|
|
@@ -59,26 +70,30 @@ export const createComponentsDir = async (dirPath, component) => {
|
|
|
59
70
|
const componentPath = dirPath + `/${component}`;
|
|
60
71
|
await fsExtra.ensureDir(componentPath);
|
|
61
72
|
};
|
|
62
|
-
export const writeIndexFile = async (dirPath, addExample) => {
|
|
73
|
+
export const writeIndexFile = async ({ dirPath, addAgent, addExample, addWorkflow, }) => {
|
|
63
74
|
const indexPath = dirPath + '/index.ts';
|
|
64
75
|
const destPath = path.join(indexPath);
|
|
65
76
|
try {
|
|
66
77
|
await fs.writeFile(destPath, '');
|
|
78
|
+
const filteredExports = [
|
|
79
|
+
addWorkflow ? `workflows: { weatherWorkflow },` : '',
|
|
80
|
+
addAgent ? `agents: { weatherAgent },` : '',
|
|
81
|
+
].filter(Boolean);
|
|
67
82
|
if (!addExample) {
|
|
68
83
|
await fs.writeFile(destPath, `
|
|
69
84
|
import { Mastra } from '@mastra/core';
|
|
70
85
|
|
|
71
|
-
export const mastra = new Mastra(
|
|
86
|
+
export const mastra = new Mastra()
|
|
72
87
|
`);
|
|
73
88
|
return;
|
|
74
89
|
}
|
|
75
90
|
await fs.writeFile(destPath, `
|
|
76
91
|
import { Mastra, createLogger } from '@mastra/core';
|
|
77
|
-
|
|
78
|
-
import {
|
|
92
|
+
${addWorkflow ? `import { weatherWorkflow } from './workflows';` : ''}
|
|
93
|
+
${addAgent ? `import { weatherAgent } from './agents';` : ''}
|
|
79
94
|
|
|
80
95
|
export const mastra = new Mastra({
|
|
81
|
-
|
|
96
|
+
${filteredExports.join('\n ')}
|
|
82
97
|
logger: createLogger({
|
|
83
98
|
type: 'CONSOLE',
|
|
84
99
|
level: 'INFO',
|
|
@@ -123,26 +138,29 @@ export async function installCoreDeps() {
|
|
|
123
138
|
}
|
|
124
139
|
spinner.start();
|
|
125
140
|
const depsService = new DepsService();
|
|
126
|
-
await depsService.installPackages(['@mastra/core']);
|
|
141
|
+
await depsService.installPackages(['@mastra/core@alpha']);
|
|
127
142
|
spinner.success('@mastra/core installed successfully');
|
|
128
143
|
}
|
|
129
144
|
catch (err) {
|
|
130
145
|
console.error(err);
|
|
131
146
|
}
|
|
132
147
|
}
|
|
133
|
-
export const
|
|
148
|
+
export const getAPIKey = async (provider) => {
|
|
134
149
|
let key = 'OPENAI_API_KEY';
|
|
135
150
|
switch (provider) {
|
|
136
151
|
case 'anthropic':
|
|
137
152
|
key = 'ANTHROPIC_API_KEY';
|
|
138
|
-
return;
|
|
153
|
+
return key;
|
|
139
154
|
case 'groq':
|
|
140
155
|
key = 'GROQ_API_KEY';
|
|
141
|
-
return;
|
|
156
|
+
return key;
|
|
142
157
|
default:
|
|
143
|
-
key
|
|
158
|
+
return key;
|
|
144
159
|
}
|
|
145
|
-
|
|
160
|
+
};
|
|
161
|
+
export const writeAPIKey = async ({ provider, apiKey = 'your-api-key', }) => {
|
|
162
|
+
const key = await getAPIKey(provider);
|
|
163
|
+
await exec(`echo ${key}=${apiKey} >> .env.development`);
|
|
146
164
|
};
|
|
147
165
|
export const createMastraDir = async (directory) => {
|
|
148
166
|
let dir = directory
|
|
@@ -159,17 +177,17 @@ export const createMastraDir = async (directory) => {
|
|
|
159
177
|
return { ok: true, dirPath };
|
|
160
178
|
}
|
|
161
179
|
};
|
|
162
|
-
export const writeCodeSample = async (dirPath, component, llmProvider) => {
|
|
180
|
+
export const writeCodeSample = async (dirPath, component, llmProvider, components) => {
|
|
163
181
|
const destPath = dirPath + `/${component}/index.ts`;
|
|
164
182
|
try {
|
|
165
|
-
await writeCodeSampleForComponents(llmProvider, component, destPath);
|
|
183
|
+
await writeCodeSampleForComponents(llmProvider, component, destPath, components);
|
|
166
184
|
}
|
|
167
185
|
catch (err) {
|
|
168
186
|
throw err;
|
|
169
187
|
}
|
|
170
188
|
};
|
|
171
189
|
export const interactivePrompt = async () => {
|
|
172
|
-
p.intro(color.inverse('
|
|
190
|
+
p.intro(color.inverse('Mastra Init'));
|
|
173
191
|
const mastraProject = await p.group({
|
|
174
192
|
directory: () => p.text({
|
|
175
193
|
message: 'Where should we create the Mastra files? (default: src/)',
|
|
@@ -198,6 +216,23 @@ export const interactivePrompt = async () => {
|
|
|
198
216
|
{ value: 'groq', label: 'Groq' },
|
|
199
217
|
],
|
|
200
218
|
}),
|
|
219
|
+
llmApiKey: async ({ results: { llmProvider } }) => {
|
|
220
|
+
const keyChoice = await p.select({
|
|
221
|
+
message: `Enter your ${llmProvider} API key?`,
|
|
222
|
+
options: [
|
|
223
|
+
{ value: 'skip', label: 'Skip for now', hint: 'default' },
|
|
224
|
+
{ value: 'enter', label: 'Enter API key' },
|
|
225
|
+
],
|
|
226
|
+
initialValue: 'skip',
|
|
227
|
+
});
|
|
228
|
+
if (keyChoice === 'enter') {
|
|
229
|
+
return p.text({
|
|
230
|
+
message: 'Enter your API key:',
|
|
231
|
+
placeholder: 'sk-...',
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
return undefined;
|
|
235
|
+
},
|
|
201
236
|
addExample: () => p.confirm({
|
|
202
237
|
message: 'Add example',
|
|
203
238
|
initialValue: false,
|
|
@@ -208,50 +243,11 @@ export const interactivePrompt = async () => {
|
|
|
208
243
|
process.exit(0);
|
|
209
244
|
},
|
|
210
245
|
});
|
|
211
|
-
const s = p.spinner();
|
|
212
|
-
s.start('Initializing Mastra');
|
|
213
246
|
const { shouldAddTools, components, ...rest } = mastraProject;
|
|
214
247
|
const mastraComponents = shouldAddTools ? [...components, 'tools'] : components;
|
|
215
|
-
|
|
216
|
-
const result = { ...rest, components: mastraComponents };
|
|
217
|
-
const { success } = await init(result);
|
|
218
|
-
if (!success) {
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
s.stop('Mastra initialized successfully');
|
|
222
|
-
p.note('You are all set!');
|
|
223
|
-
p.outro(`Problems? ${color.underline(color.cyan('https://github.com/mastra-ai/mastra'))}`);
|
|
224
|
-
}
|
|
225
|
-
catch (err) {
|
|
226
|
-
s.stop('Could not initialize Mastra');
|
|
227
|
-
logger.error(err);
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
export const initializeMinimal = async () => {
|
|
231
|
-
const confirm = await p.confirm({
|
|
232
|
-
message: 'No package.json detected. Create a new project?',
|
|
233
|
-
initialValue: true,
|
|
234
|
-
});
|
|
235
|
-
if (p.isCancel(confirm)) {
|
|
236
|
-
p.cancel('Operation cancelled');
|
|
237
|
-
process.exit(0);
|
|
238
|
-
}
|
|
239
|
-
if (!confirm) {
|
|
240
|
-
p.cancel('Operation cancelled');
|
|
241
|
-
process.exit(0);
|
|
242
|
-
}
|
|
243
|
-
const s = p.spinner();
|
|
244
|
-
s.start('Creating project');
|
|
245
|
-
await exec(`npm init -y`);
|
|
246
|
-
await exec(`npm i zod typescript tsx @types/node --save-dev`);
|
|
247
|
-
s.message('Installing dependencies');
|
|
248
|
-
await exec(`echo output.txt >> .gitignore`);
|
|
249
|
-
await exec(`echo node_modules >> .gitignore`);
|
|
250
|
-
await exec(`npm i @mastra/core@alpha`);
|
|
251
|
-
s.stop('Project creation successful');
|
|
252
|
-
logger.break();
|
|
248
|
+
return { ...rest, components: mastraComponents };
|
|
253
249
|
};
|
|
254
|
-
export const
|
|
250
|
+
export const checkPkgJson = async () => {
|
|
255
251
|
const cwd = process.cwd();
|
|
256
252
|
const pkgJsonPath = path.join(cwd, 'package.json');
|
|
257
253
|
let isPkgJsonPresent = false;
|
|
@@ -265,12 +261,6 @@ export const checkPkgJsonAndCreateStarter = async () => {
|
|
|
265
261
|
if (isPkgJsonPresent) {
|
|
266
262
|
return;
|
|
267
263
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
return { isStarter: true };
|
|
271
|
-
}
|
|
272
|
-
catch (err) {
|
|
273
|
-
logger.error(`Could not create project: ${err}`);
|
|
274
|
-
process.exit(0);
|
|
275
|
-
}
|
|
264
|
+
logger.info('no package.json found, create one or run "mastra create" to create a new project');
|
|
265
|
+
process.exit(0);
|
|
276
266
|
};
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAsQA,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
import * as p from '@clack/prompts';
|
|
3
2
|
import { Command } from 'commander';
|
|
4
3
|
import color from 'picocolors';
|
|
5
4
|
import { PosthogAnalytics } from './analytics/index.js';
|
|
6
|
-
import {
|
|
7
|
-
import { listAgents } from './commands/agents/list-agent.js';
|
|
8
|
-
import { updateAgentIndexFile } from './commands/agents/update-agent-file.js';
|
|
5
|
+
import { create } from './commands/create/create.js';
|
|
9
6
|
import { cloudflareDeploy, netlifyDeploy, vercelDeploy } from './commands/deploy/index.js';
|
|
10
7
|
import { dev } from './commands/dev.js';
|
|
11
8
|
import { add } from './commands/engine/add.js';
|
|
@@ -14,13 +11,14 @@ import { generate } from './commands/engine/generate.js';
|
|
|
14
11
|
import { migrate } from './commands/engine/migrate.js';
|
|
15
12
|
import { up } from './commands/engine/up.js';
|
|
16
13
|
import { init } from './commands/init/init.js';
|
|
17
|
-
import { checkAndInstallCoreDeps,
|
|
14
|
+
import { checkAndInstallCoreDeps, checkPkgJson, interactivePrompt } from './commands/init/utils.js';
|
|
18
15
|
import { DepsService } from './services/service.deps.js';
|
|
19
16
|
import { findApiKeys } from './utils/find-api-keys.js';
|
|
20
17
|
import { getEnv } from './utils/get-env.js';
|
|
21
18
|
import { logger } from './utils/logger.js';
|
|
22
19
|
const depsService = new DepsService();
|
|
23
20
|
const version = await depsService.getPackageVersion();
|
|
21
|
+
const projectName = 'mastra-starter';
|
|
24
22
|
const analytics = new PosthogAnalytics({
|
|
25
23
|
apiKey: 'phc_SBLpZVAB6jmHOct9CABq3PF0Yn5FU3G2FgT4xUr2XrT',
|
|
26
24
|
host: 'https://us.posthog.com',
|
|
@@ -39,31 +37,65 @@ program
|
|
|
39
37
|
}
|
|
40
38
|
catch (e) { }
|
|
41
39
|
});
|
|
40
|
+
program
|
|
41
|
+
.command('create')
|
|
42
|
+
.description('Create a new Mastra project')
|
|
43
|
+
.option('--default', 'Quick start with defaults(src, OpenAI, no examples)')
|
|
44
|
+
.option('-c, --components <components>', 'Comma-separated list of components (agents, tools, workflows)')
|
|
45
|
+
.option('-l, --llm <model-provider>', 'Default model provider (openai, anthropic, or groq))')
|
|
46
|
+
.option('-k, --llm-api-key <api-key>', 'API key for the model provider')
|
|
47
|
+
.option('-e, --example', 'Include example code')
|
|
48
|
+
.action(async (args) => {
|
|
49
|
+
await analytics.trackCommandExecution({
|
|
50
|
+
command: 'create',
|
|
51
|
+
args,
|
|
52
|
+
execution: async () => {
|
|
53
|
+
if (args.default) {
|
|
54
|
+
await create({
|
|
55
|
+
components: ['agents', 'tools', 'workflows'],
|
|
56
|
+
llmProvider: 'openai',
|
|
57
|
+
addExample: false,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
await create({
|
|
61
|
+
components: args.components,
|
|
62
|
+
llmProvider: args.llm,
|
|
63
|
+
addExample: args.example,
|
|
64
|
+
llmApiKey: args['llm-api-key'],
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
});
|
|
42
69
|
program
|
|
43
70
|
.command('init')
|
|
44
|
-
.description('Initialize
|
|
71
|
+
.description('Initialize Mastra in your project')
|
|
45
72
|
.option('--default', 'Quick start with defaults(src, OpenAI, no examples)')
|
|
46
73
|
.option('-d, --dir <directory>', 'Directory for Mastra files to (defaults to src/)')
|
|
47
74
|
.option('-c, --components <components>', 'Comma-separated list of components (agents, tools, workflows)')
|
|
48
75
|
.option('-l, --llm <model-provider>', 'Default model provider (openai, anthropic, or groq))')
|
|
76
|
+
.option('-k, --llm-api-key <api-key>', 'API key for the model provider')
|
|
49
77
|
.option('-e, --example', 'Include example code')
|
|
50
|
-
.option('-ne, --no-example', 'Skip example code')
|
|
51
78
|
.action(async (args) => {
|
|
52
79
|
await analytics.trackCommandExecution({
|
|
53
80
|
command: 'init',
|
|
54
81
|
args,
|
|
55
82
|
execution: async () => {
|
|
56
|
-
await
|
|
83
|
+
await checkPkgJson();
|
|
57
84
|
await checkAndInstallCoreDeps();
|
|
58
|
-
if (!Object.keys(args).length)
|
|
59
|
-
|
|
85
|
+
if (!Object.keys(args).length) {
|
|
86
|
+
const result = await interactivePrompt();
|
|
87
|
+
await init({
|
|
88
|
+
...result,
|
|
89
|
+
llmApiKey: result?.llmApiKey,
|
|
90
|
+
});
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
60
93
|
if (args?.default) {
|
|
61
94
|
init({
|
|
62
95
|
directory: 'src/',
|
|
63
96
|
components: ['agents', 'tools', 'workflows'],
|
|
64
97
|
llmProvider: 'openai',
|
|
65
98
|
addExample: false,
|
|
66
|
-
showSpinner: true,
|
|
67
99
|
});
|
|
68
100
|
return;
|
|
69
101
|
}
|
|
@@ -73,7 +105,7 @@ program
|
|
|
73
105
|
components: componentsArr,
|
|
74
106
|
llmProvider: args.llm,
|
|
75
107
|
addExample: args.example,
|
|
76
|
-
|
|
108
|
+
llmApiKey: args['llm-api-key'],
|
|
77
109
|
});
|
|
78
110
|
return;
|
|
79
111
|
},
|
|
@@ -85,12 +117,13 @@ program
|
|
|
85
117
|
.option('-d, --dir <dir>', 'Path to your mastra folder')
|
|
86
118
|
.option('-e, --env <env>', 'Environment File to use (defaults to .env.development)')
|
|
87
119
|
.option('-t, --tools <toolsDirs>', 'Comma-separated list of paths to tool files to include')
|
|
120
|
+
.option('-p, --port <port>', 'Port number for the development server (defaults to 4111)')
|
|
88
121
|
.action(args => {
|
|
89
122
|
analytics.trackCommand({
|
|
90
123
|
command: 'dev',
|
|
91
124
|
});
|
|
92
125
|
const apiKeys = findApiKeys();
|
|
93
|
-
dev({ port: 4111, env: apiKeys, dir: args?.dir, toolsDirs: args?.tools });
|
|
126
|
+
dev({ port: args?.port ? parseInt(args.port) : 4111, env: apiKeys, dir: args?.dir, toolsDirs: args?.tools });
|
|
94
127
|
});
|
|
95
128
|
const engine = program.command('engine').description('Manage the mastra engine');
|
|
96
129
|
engine
|
|
@@ -120,24 +153,26 @@ engine
|
|
|
120
153
|
engine
|
|
121
154
|
.command('up')
|
|
122
155
|
.description('Runs docker-compose up to start docker containers')
|
|
123
|
-
.
|
|
156
|
+
.option('-f, --file <path>', 'Path to docker-compose file')
|
|
157
|
+
.action(async (args) => {
|
|
124
158
|
await analytics.trackCommandExecution({
|
|
125
159
|
command: 'engine up',
|
|
126
|
-
args
|
|
160
|
+
args,
|
|
127
161
|
execution: async () => {
|
|
128
|
-
await up();
|
|
162
|
+
await up(args.file);
|
|
129
163
|
},
|
|
130
164
|
});
|
|
131
165
|
});
|
|
132
166
|
engine
|
|
133
167
|
.command('down')
|
|
134
168
|
.description('Runs docker-compose down to shut down docker containers')
|
|
135
|
-
.
|
|
169
|
+
.option('-f, --file <path>', 'Path to docker-compose file')
|
|
170
|
+
.action(async (args) => {
|
|
136
171
|
await analytics.trackCommandExecution({
|
|
137
172
|
command: 'engine down',
|
|
138
173
|
args: {},
|
|
139
174
|
execution: async () => {
|
|
140
|
-
await down();
|
|
175
|
+
await down(args.file);
|
|
141
176
|
},
|
|
142
177
|
});
|
|
143
178
|
});
|
|
@@ -160,55 +195,18 @@ engine
|
|
|
160
195
|
},
|
|
161
196
|
});
|
|
162
197
|
});
|
|
163
|
-
const agent = program.command('agent').description('Manage Mastra agents');
|
|
164
|
-
agent
|
|
165
|
-
.command('new')
|
|
166
|
-
.description('Create a new agent')
|
|
167
|
-
.option('-d, --dir <dir>', 'Path to your mastra folder')
|
|
168
|
-
.action(async (args) => {
|
|
169
|
-
await analytics.trackCommandExecution({
|
|
170
|
-
command: 'agent new',
|
|
171
|
-
args: {},
|
|
172
|
-
execution: async () => {
|
|
173
|
-
const result = await createNewAgent({ dir: args?.dir });
|
|
174
|
-
if (!result)
|
|
175
|
-
return;
|
|
176
|
-
await updateAgentIndexFile({ newAgentName: result, dir: args?.dir });
|
|
177
|
-
},
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
agent
|
|
181
|
-
.command('list')
|
|
182
|
-
.description('List all agents')
|
|
183
|
-
.option('-d, --dir <dir>', 'Path to your mastra folder')
|
|
184
|
-
.action(async (args) => {
|
|
185
|
-
await analytics.trackCommandExecution({
|
|
186
|
-
command: 'agent list',
|
|
187
|
-
args,
|
|
188
|
-
execution: async () => {
|
|
189
|
-
const agents = await listAgents({ dir: args?.dir });
|
|
190
|
-
if (!agents.length) {
|
|
191
|
-
p.note('No Agents...');
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
p.intro(color.bgCyan(color.black(' Agents List ')));
|
|
195
|
-
agents.forEach((agent, index) => {
|
|
196
|
-
logger.log(`${index + 1}. ${color.blue(agent)}`);
|
|
197
|
-
});
|
|
198
|
-
},
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
198
|
const deploy = program.command('deploy').description('Deploy your Mastra project');
|
|
202
199
|
deploy
|
|
203
200
|
.command('vercel')
|
|
204
201
|
.description('Deploy your Mastra project to Vercel')
|
|
205
202
|
.option('-d, --dir <dir>', 'Path to your mastra folder')
|
|
203
|
+
.option('-n, --name <name>', 'Name of the project')
|
|
206
204
|
.action(async (args) => {
|
|
207
205
|
await analytics.trackCommandExecution({
|
|
208
206
|
command: 'deploy vercel',
|
|
209
207
|
args,
|
|
210
208
|
execution: async () => {
|
|
211
|
-
await vercelDeploy({ dir: args?.dir });
|
|
209
|
+
await vercelDeploy({ dir: args?.dir, projectName: args?.name || projectName });
|
|
212
210
|
},
|
|
213
211
|
});
|
|
214
212
|
});
|
|
@@ -239,3 +237,5 @@ deploy
|
|
|
239
237
|
});
|
|
240
238
|
});
|
|
241
239
|
program.parse(process.argv);
|
|
240
|
+
export { create } from './commands/create/create.js';
|
|
241
|
+
export { PosthogAnalytics } from './analytics/index.js';
|
|
@@ -11,5 +11,6 @@ export declare class DepsService {
|
|
|
11
11
|
checkDependencies(dependencies: string[]): Promise<string>;
|
|
12
12
|
getProjectName(): Promise<any>;
|
|
13
13
|
getPackageVersion(): Promise<string>;
|
|
14
|
+
addScriptsToPackageJson(scripts: Record<string, string>): Promise<void>;
|
|
14
15
|
}
|
|
15
16
|
//# sourceMappingURL=service.deps.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.deps.d.ts","sourceRoot":"","sources":["../../src/services/service.deps.ts"],"names":[],"mappings":"AASA,qBAAa,WAAW;IACtB,OAAO,CAAC,cAAc,CAAS;;IAM/B,OAAO,CAAC,YAAY;IAcpB,OAAO,CAAC,iBAAiB;IAcZ,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE;;;;;IAgBlC,iBAAiB,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAwB1D,cAAc;IAWd,iBAAiB;
|
|
1
|
+
{"version":3,"file":"service.deps.d.ts","sourceRoot":"","sources":["../../src/services/service.deps.ts"],"names":[],"mappings":"AASA,qBAAa,WAAW;IACtB,OAAO,CAAC,cAAc,CAAS;;IAM/B,OAAO,CAAC,YAAY;IAcpB,OAAO,CAAC,iBAAiB;IAcZ,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE;;;;;IAgBlC,iBAAiB,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAwB1D,cAAc;IAWd,iBAAiB;IASjB,uBAAuB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;CAQrE"}
|
|
@@ -89,4 +89,12 @@ export class DepsService {
|
|
|
89
89
|
const content = (await fsExtra.readJSON(pkgJsonPath));
|
|
90
90
|
return content.version;
|
|
91
91
|
}
|
|
92
|
+
async addScriptsToPackageJson(scripts) {
|
|
93
|
+
const packageJson = JSON.parse(await fsPromises.readFile('package.json', 'utf-8'));
|
|
94
|
+
packageJson.scripts = {
|
|
95
|
+
...packageJson.scripts,
|
|
96
|
+
...scripts,
|
|
97
|
+
};
|
|
98
|
+
await fsPromises.writeFile('package.json', JSON.stringify(packageJson, null, 2));
|
|
99
|
+
}
|
|
92
100
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.docker.d.ts","sourceRoot":"","sources":["../../src/services/service.docker.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"service.docker.d.ts","sourceRoot":"","sources":["../../src/services/service.docker.ts"],"names":[],"mappings":"AAQA,qBAAa,aAAa;IACxB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAqB5B,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAQ1C,SAAS,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;YAqBlD,eAAe;IAUvB,aAAa,CAAC,EAClB,mBAAmB,GACpB,GAAE;QAAE,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;QAAC,mBAAmB,CAAC,EAAE,MAAM,CAAA;KAAO;;;IAW1F,kBAAkB;IASlB,oBAAoB,CAAC,iBAAiB,EAAE,MAAM;IAS9C,mBAAmB,CAAC,iBAAiB,EAAE,MAAM;IAS7C,kBAAkB,CAAC,EACvB,oBAAoB,EACpB,YAAY,GACb,EAAE;QACD,oBAAoB,EAAE,MAAM,CAAC;QAC7B,YAAY,EAAE,MAAM,CAAC;KACtB;;;IAUD,OAAO,CAAC,eAAe;IAqBvB,cAAc,CAAC,WAAW,EAAE,MAAM;CAmBnC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { execa } from 'execa';
|
|
2
|
+
import fs from 'fs';
|
|
2
3
|
import path from 'path';
|
|
3
4
|
import { check } from 'tcp-port-used';
|
|
4
5
|
import { fileURLToPath } from 'url';
|
|
@@ -108,4 +109,23 @@ export class DockerService {
|
|
|
108
109
|
],
|
|
109
110
|
});
|
|
110
111
|
}
|
|
112
|
+
getComposeFile(composePath) {
|
|
113
|
+
const fileService = new FileService();
|
|
114
|
+
let composeFile;
|
|
115
|
+
if (composePath) {
|
|
116
|
+
if (!fs.existsSync(composePath)) {
|
|
117
|
+
throw new Error(`Docker compose file not found: ${composePath}`);
|
|
118
|
+
}
|
|
119
|
+
composeFile = composePath;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
composeFile = fileService.getFirstExistingFile([
|
|
123
|
+
'mastra-pg.docker-compose.yaml',
|
|
124
|
+
'mastra-pg.docker-compose.yml',
|
|
125
|
+
'docker-compose.yaml',
|
|
126
|
+
'docker-compose.yml',
|
|
127
|
+
]);
|
|
128
|
+
}
|
|
129
|
+
return composeFile;
|
|
130
|
+
}
|
|
111
131
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import { Config } from '@mastra/core';
|
|
3
|
+
|
|
4
|
+
export const config: Config = {
|
|
5
|
+
name: 'PROJECT_NAME',
|
|
6
|
+
integrations: [],
|
|
7
|
+
db: {
|
|
8
|
+
provider: 'postgres',
|
|
9
|
+
uri: process.env.DB_URL!,
|
|
10
|
+
},
|
|
11
|
+
runner: {
|
|
12
|
+
provider: 'inngest',
|
|
13
|
+
uri: process.env.INNGEST_URL!,
|
|
14
|
+
signingKey: process.env.INNGEST_SIGNING_KEY!,
|
|
15
|
+
eventKey: process.env.INNGEST_EVENT_KEY!,
|
|
16
|
+
},
|
|
17
|
+
workflows: {
|
|
18
|
+
blueprintDirPath: '/mastra/blueprints',
|
|
19
|
+
systemEvents: {},
|
|
20
|
+
systemApis: [],
|
|
21
|
+
},
|
|
22
|
+
agents: {
|
|
23
|
+
agentDirPath: '/mastra/agents',
|
|
24
|
+
vectorProvider: [],
|
|
25
|
+
},
|
|
26
|
+
systemHostURL: process.env.APP_URL!,
|
|
27
|
+
routeRegistrationPath: '/api/mastra',
|
|
28
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
services:
|
|
2
|
+
db:
|
|
3
|
+
image: pgvector/pgvector:pg16
|
|
4
|
+
container_name: 'REPLACE_PROJECT_NAME-db'
|
|
5
|
+
ports:
|
|
6
|
+
- 'REPLACE_DB_PORT:5432'
|
|
7
|
+
environment:
|
|
8
|
+
POSTGRES_USER: ${POSTGRES_USER:-postgres}
|
|
9
|
+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
|
|
10
|
+
POSTGRES_DB: ${POSTGRES_DB:-mastra}
|
|
11
|
+
volumes:
|
|
12
|
+
- pgdata:/var/lib/postgresql/data
|
|
13
|
+
|
|
14
|
+
volumes:
|
|
15
|
+
pgdata:
|