mastra 0.1.57-unstable.57 → 0.1.57-unstable.89
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/netlify/index.d.ts.map +1 -1
- package/dist/commands/deploy/netlify/index.js +2 -0
- package/dist/commands/deploy/vercel/index.d.ts.map +1 -1
- package/dist/commands/deploy/vercel/index.js +2 -0
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +97 -10
- 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 +54 -56
- 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 +30 -31
- 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 +1 -0
- package/dist/utils/bundle.d.ts.map +1 -1
- package/dist/utils/bundle.js +9 -8
- package/package.json +5 -3
- 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-Dx4A5Op9.js → index-Cke4BidO.js} +2 -2
- 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 +1 -1
- package/src/starter-files/tools.ts +88 -14
- package/src/starter-files/workflow.ts +160 -21
- package/src/playground/dist/assets/index-DY22QVI1.js +0 -389
- 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
|
@@ -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,7 +11,7 @@ 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';
|
|
@@ -40,31 +37,65 @@ program
|
|
|
40
37
|
}
|
|
41
38
|
catch (e) { }
|
|
42
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
|
+
});
|
|
43
69
|
program
|
|
44
70
|
.command('init')
|
|
45
|
-
.description('Initialize
|
|
71
|
+
.description('Initialize Mastra in your project')
|
|
46
72
|
.option('--default', 'Quick start with defaults(src, OpenAI, no examples)')
|
|
47
73
|
.option('-d, --dir <directory>', 'Directory for Mastra files to (defaults to src/)')
|
|
48
74
|
.option('-c, --components <components>', 'Comma-separated list of components (agents, tools, workflows)')
|
|
49
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')
|
|
50
77
|
.option('-e, --example', 'Include example code')
|
|
51
|
-
.option('-ne, --no-example', 'Skip example code')
|
|
52
78
|
.action(async (args) => {
|
|
53
79
|
await analytics.trackCommandExecution({
|
|
54
80
|
command: 'init',
|
|
55
81
|
args,
|
|
56
82
|
execution: async () => {
|
|
57
|
-
await
|
|
83
|
+
await checkPkgJson();
|
|
58
84
|
await checkAndInstallCoreDeps();
|
|
59
|
-
if (!Object.keys(args).length)
|
|
60
|
-
|
|
85
|
+
if (!Object.keys(args).length) {
|
|
86
|
+
const result = await interactivePrompt();
|
|
87
|
+
await init({
|
|
88
|
+
...result,
|
|
89
|
+
llmApiKey: result?.llmApiKey,
|
|
90
|
+
});
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
61
93
|
if (args?.default) {
|
|
62
94
|
init({
|
|
63
95
|
directory: 'src/',
|
|
64
96
|
components: ['agents', 'tools', 'workflows'],
|
|
65
97
|
llmProvider: 'openai',
|
|
66
98
|
addExample: false,
|
|
67
|
-
showSpinner: true,
|
|
68
99
|
});
|
|
69
100
|
return;
|
|
70
101
|
}
|
|
@@ -74,7 +105,7 @@ program
|
|
|
74
105
|
components: componentsArr,
|
|
75
106
|
llmProvider: args.llm,
|
|
76
107
|
addExample: args.example,
|
|
77
|
-
|
|
108
|
+
llmApiKey: args['llm-api-key'],
|
|
78
109
|
});
|
|
79
110
|
return;
|
|
80
111
|
},
|
|
@@ -86,12 +117,13 @@ program
|
|
|
86
117
|
.option('-d, --dir <dir>', 'Path to your mastra folder')
|
|
87
118
|
.option('-e, --env <env>', 'Environment File to use (defaults to .env.development)')
|
|
88
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)')
|
|
89
121
|
.action(args => {
|
|
90
122
|
analytics.trackCommand({
|
|
91
123
|
command: 'dev',
|
|
92
124
|
});
|
|
93
125
|
const apiKeys = findApiKeys();
|
|
94
|
-
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 });
|
|
95
127
|
});
|
|
96
128
|
const engine = program.command('engine').description('Manage the mastra engine');
|
|
97
129
|
engine
|
|
@@ -121,24 +153,26 @@ engine
|
|
|
121
153
|
engine
|
|
122
154
|
.command('up')
|
|
123
155
|
.description('Runs docker-compose up to start docker containers')
|
|
124
|
-
.
|
|
156
|
+
.option('-f, --file <path>', 'Path to docker-compose file')
|
|
157
|
+
.action(async (args) => {
|
|
125
158
|
await analytics.trackCommandExecution({
|
|
126
159
|
command: 'engine up',
|
|
127
|
-
args
|
|
160
|
+
args,
|
|
128
161
|
execution: async () => {
|
|
129
|
-
await up();
|
|
162
|
+
await up(args.file);
|
|
130
163
|
},
|
|
131
164
|
});
|
|
132
165
|
});
|
|
133
166
|
engine
|
|
134
167
|
.command('down')
|
|
135
168
|
.description('Runs docker-compose down to shut down docker containers')
|
|
136
|
-
.
|
|
169
|
+
.option('-f, --file <path>', 'Path to docker-compose file')
|
|
170
|
+
.action(async (args) => {
|
|
137
171
|
await analytics.trackCommandExecution({
|
|
138
172
|
command: 'engine down',
|
|
139
173
|
args: {},
|
|
140
174
|
execution: async () => {
|
|
141
|
-
await down();
|
|
175
|
+
await down(args.file);
|
|
142
176
|
},
|
|
143
177
|
});
|
|
144
178
|
});
|
|
@@ -161,44 +195,6 @@ engine
|
|
|
161
195
|
},
|
|
162
196
|
});
|
|
163
197
|
});
|
|
164
|
-
const agent = program.command('agent').description('Manage Mastra agents');
|
|
165
|
-
agent
|
|
166
|
-
.command('new')
|
|
167
|
-
.description('Create a new agent')
|
|
168
|
-
.option('-d, --dir <dir>', 'Path to your mastra folder')
|
|
169
|
-
.action(async (args) => {
|
|
170
|
-
await analytics.trackCommandExecution({
|
|
171
|
-
command: 'agent new',
|
|
172
|
-
args: {},
|
|
173
|
-
execution: async () => {
|
|
174
|
-
const result = await createNewAgent({ dir: args?.dir });
|
|
175
|
-
if (!result)
|
|
176
|
-
return;
|
|
177
|
-
await updateAgentIndexFile({ newAgentName: result, dir: args?.dir });
|
|
178
|
-
},
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
agent
|
|
182
|
-
.command('list')
|
|
183
|
-
.description('List all agents')
|
|
184
|
-
.option('-d, --dir <dir>', 'Path to your mastra folder')
|
|
185
|
-
.action(async (args) => {
|
|
186
|
-
await analytics.trackCommandExecution({
|
|
187
|
-
command: 'agent list',
|
|
188
|
-
args,
|
|
189
|
-
execution: async () => {
|
|
190
|
-
const agents = await listAgents({ dir: args?.dir });
|
|
191
|
-
if (!agents.length) {
|
|
192
|
-
p.note('No Agents...');
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
p.intro(color.bgCyan(color.black(' Agents List ')));
|
|
196
|
-
agents.forEach((agent, index) => {
|
|
197
|
-
logger.log(`${index + 1}. ${color.blue(agent)}`);
|
|
198
|
-
});
|
|
199
|
-
},
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
198
|
const deploy = program.command('deploy').description('Deploy your Mastra project');
|
|
203
199
|
deploy
|
|
204
200
|
.command('vercel')
|
|
@@ -241,3 +237,5 @@ deploy
|
|
|
241
237
|
});
|
|
242
238
|
});
|
|
243
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:
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { createTool } from '@mastra/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
interface WeatherResponse {
|
|
5
|
+
current: {
|
|
6
|
+
time: string;
|
|
7
|
+
temperature_2m: number;
|
|
8
|
+
apparent_temperature: number;
|
|
9
|
+
relative_humidity_2m: number;
|
|
10
|
+
wind_speed_10m: number;
|
|
11
|
+
wind_gusts_10m: number;
|
|
12
|
+
weather_code: number;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const weatherTool = createTool({
|
|
17
|
+
id: 'get-weather',
|
|
18
|
+
description: 'Get current weather for a location',
|
|
19
|
+
inputSchema: z.object({
|
|
20
|
+
location: z.string().describe('City name'),
|
|
21
|
+
}),
|
|
22
|
+
outputSchema: z.object({
|
|
23
|
+
temperature: z.number(),
|
|
24
|
+
feelsLike: z.number(),
|
|
25
|
+
humidity: z.number(),
|
|
26
|
+
windSpeed: z.number(),
|
|
27
|
+
windGust: z.number(),
|
|
28
|
+
conditions: z.string(),
|
|
29
|
+
location: z.string(),
|
|
30
|
+
}),
|
|
31
|
+
execute: async ({ context }) => {
|
|
32
|
+
return await getWeather(context.location);
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const getWeather = async (location: string) => {
|
|
37
|
+
const geocodingUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(location)}&count=1`;
|
|
38
|
+
const geocodingResponse = await fetch(geocodingUrl);
|
|
39
|
+
const geocodingData = await geocodingResponse.json();
|
|
40
|
+
|
|
41
|
+
if (!geocodingData.results?.[0]) {
|
|
42
|
+
throw new Error(`Location '${location}' not found`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const { latitude, longitude, name } = geocodingData.results[0];
|
|
46
|
+
|
|
47
|
+
const weatherUrl = `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}¤t=temperature_2m,apparent_temperature,relative_humidity_2m,wind_speed_10m,wind_gusts_10m,weather_code`;
|
|
48
|
+
|
|
49
|
+
const response = await fetch(weatherUrl);
|
|
50
|
+
const data: WeatherResponse = await response.json();
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
temperature: data.current.temperature_2m,
|
|
54
|
+
feelsLike: data.current.apparent_temperature,
|
|
55
|
+
humidity: data.current.relative_humidity_2m,
|
|
56
|
+
windSpeed: data.current.wind_speed_10m,
|
|
57
|
+
windGust: data.current.wind_gusts_10m,
|
|
58
|
+
conditions: getWeatherCondition(data.current.weather_code),
|
|
59
|
+
location: name,
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
function getWeatherCondition(code: number): string {
|
|
64
|
+
const conditions: Record<number, string> = {
|
|
65
|
+
0: 'Clear sky',
|
|
66
|
+
1: 'Mainly clear',
|
|
67
|
+
2: 'Partly cloudy',
|
|
68
|
+
3: 'Overcast',
|
|
69
|
+
45: 'Foggy',
|
|
70
|
+
48: 'Depositing rime fog',
|
|
71
|
+
51: 'Light drizzle',
|
|
72
|
+
53: 'Moderate drizzle',
|
|
73
|
+
55: 'Dense drizzle',
|
|
74
|
+
56: 'Light freezing drizzle',
|
|
75
|
+
57: 'Dense freezing drizzle',
|
|
76
|
+
61: 'Slight rain',
|
|
77
|
+
63: 'Moderate rain',
|
|
78
|
+
65: 'Heavy rain',
|
|
79
|
+
66: 'Light freezing rain',
|
|
80
|
+
67: 'Heavy freezing rain',
|
|
81
|
+
71: 'Slight snow fall',
|
|
82
|
+
73: 'Moderate snow fall',
|
|
83
|
+
75: 'Heavy snow fall',
|
|
84
|
+
77: 'Snow grains',
|
|
85
|
+
80: 'Slight rain showers',
|
|
86
|
+
81: 'Moderate rain showers',
|
|
87
|
+
82: 'Violent rain showers',
|
|
88
|
+
85: 'Slight snow showers',
|
|
89
|
+
86: 'Heavy snow showers',
|
|
90
|
+
95: 'Thunderstorm',
|
|
91
|
+
96: 'Thunderstorm with slight hail',
|
|
92
|
+
99: 'Thunderstorm with heavy hail',
|
|
93
|
+
};
|
|
94
|
+
return conditions[code] || 'Unknown';
|
|
95
|
+
}
|