mastra 0.6.4-alpha.0 → 0.7.0-alpha.2
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/{chunk-SKKSZR7C.js → chunk-AMYIYOXP.js} +94 -87
- package/dist/commands/create/create.js +1 -1
- package/dist/index.js +2 -2
- package/package.json +13 -7
- package/src/playground/dist/assets/{index-wEYafJdK.js → index-B7uB4AVM.js} +243 -215
- package/src/playground/dist/assets/{index-CaqWW4co.js → index-CO5K8l6Q.js} +1 -1
- package/src/playground/dist/assets/{index-Dvof5B-Q.js → index-CqirvehQ.js} +1 -1
- package/src/playground/dist/assets/style-CHx3RKRi.css +1 -0
- package/src/playground/dist/index.html +2 -2
- package/src/playground/dist/assets/style-DuOhUtk_.css +0 -1
|
@@ -11,8 +11,9 @@ import { execa } from 'execa';
|
|
|
11
11
|
import fsExtra3, { readJSON, ensureFile, writeJSON } from 'fs-extra/esm';
|
|
12
12
|
import os from 'os';
|
|
13
13
|
import prettier from 'prettier';
|
|
14
|
+
import shellQuote from 'shell-quote';
|
|
14
15
|
import yoctoSpinner from 'yocto-spinner';
|
|
15
|
-
import {
|
|
16
|
+
import { PinoLogger } from '@mastra/loggers';
|
|
16
17
|
|
|
17
18
|
// src/commands/create/create.ts
|
|
18
19
|
var DepsService = class {
|
|
@@ -369,7 +370,7 @@ var FileService = class {
|
|
|
369
370
|
fs3__default.writeFileSync(filePath, fileContent);
|
|
370
371
|
}
|
|
371
372
|
};
|
|
372
|
-
var logger =
|
|
373
|
+
var logger = new PinoLogger({
|
|
373
374
|
name: "Mastra CLI",
|
|
374
375
|
level: "debug"
|
|
375
376
|
});
|
|
@@ -397,7 +398,7 @@ var getProviderImportAndModelItem = (llmProvider) => {
|
|
|
397
398
|
let modelItem = "";
|
|
398
399
|
if (llmProvider === "openai") {
|
|
399
400
|
providerImport = `import { openai } from '${getAISDKPackage(llmProvider)}';`;
|
|
400
|
-
modelItem = `openai('gpt-4o')`;
|
|
401
|
+
modelItem = `openai('gpt-4o-mini')`;
|
|
401
402
|
} else if (llmProvider === "anthropic") {
|
|
402
403
|
providerImport = `import { anthropic } from '${getAISDKPackage(llmProvider)}';`;
|
|
403
404
|
modelItem = `anthropic('claude-3-5-sonnet-20241022')`;
|
|
@@ -432,7 +433,7 @@ ${providerImport}
|
|
|
432
433
|
import { Agent } from '@mastra/core/agent';
|
|
433
434
|
import { Memory } from '@mastra/memory';
|
|
434
435
|
import { LibSQLStore } from '@mastra/libsql';
|
|
435
|
-
${addExampleTool ? `import { weatherTool } from '../tools';` : ""}
|
|
436
|
+
${addExampleTool ? `import { weatherTool } from '../tools/weather-tool';` : ""}
|
|
436
437
|
|
|
437
438
|
export const weatherAgent = new Agent({
|
|
438
439
|
name: 'Weather Agent',
|
|
@@ -442,14 +443,7 @@ export const weatherAgent = new Agent({
|
|
|
442
443
|
memory: new Memory({
|
|
443
444
|
storage: new LibSQLStore({
|
|
444
445
|
url: "file:../mastra.db", // path is relative to the .mastra/output directory
|
|
445
|
-
})
|
|
446
|
-
options: {
|
|
447
|
-
lastMessages: 10,
|
|
448
|
-
semanticRecall: false,
|
|
449
|
-
threads: {
|
|
450
|
-
generateTitle: false
|
|
451
|
-
}
|
|
452
|
-
}
|
|
446
|
+
})
|
|
453
447
|
})
|
|
454
448
|
});
|
|
455
449
|
`;
|
|
@@ -464,7 +458,7 @@ async function writeWorkflowSample(destPath, llmProvider) {
|
|
|
464
458
|
const { providerImport, modelItem } = getProviderImportAndModelItem(llmProvider);
|
|
465
459
|
const content = `${providerImport}
|
|
466
460
|
import { Agent } from '@mastra/core/agent';
|
|
467
|
-
import {
|
|
461
|
+
import { createStep, createWorkflow } from '@mastra/core/workflows';
|
|
468
462
|
import { z } from 'zod';
|
|
469
463
|
|
|
470
464
|
const llm = ${modelItem};
|
|
@@ -517,80 +511,106 @@ const agent = new Agent({
|
|
|
517
511
|
\`,
|
|
518
512
|
});
|
|
519
513
|
|
|
520
|
-
const forecastSchema = z.
|
|
521
|
-
z.
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
)
|
|
514
|
+
const forecastSchema = z.object({
|
|
515
|
+
date: z.string(),
|
|
516
|
+
maxTemp: z.number(),
|
|
517
|
+
minTemp: z.number(),
|
|
518
|
+
precipitationChance: z.number(),
|
|
519
|
+
condition: z.string(),
|
|
520
|
+
location: z.string(),
|
|
521
|
+
})
|
|
522
|
+
|
|
523
|
+
function getWeatherCondition(code: number): string {
|
|
524
|
+
const conditions: Record<number, string> = {
|
|
525
|
+
0: 'Clear sky',
|
|
526
|
+
1: 'Mainly clear',
|
|
527
|
+
2: 'Partly cloudy',
|
|
528
|
+
3: 'Overcast',
|
|
529
|
+
45: 'Foggy',
|
|
530
|
+
48: 'Depositing rime fog',
|
|
531
|
+
51: 'Light drizzle',
|
|
532
|
+
53: 'Moderate drizzle',
|
|
533
|
+
55: 'Dense drizzle',
|
|
534
|
+
61: 'Slight rain',
|
|
535
|
+
63: 'Moderate rain',
|
|
536
|
+
65: 'Heavy rain',
|
|
537
|
+
71: 'Slight snow fall',
|
|
538
|
+
73: 'Moderate snow fall',
|
|
539
|
+
75: 'Heavy snow fall',
|
|
540
|
+
95: 'Thunderstorm',
|
|
541
|
+
}
|
|
542
|
+
return conditions[code] || 'Unknown'
|
|
543
|
+
}
|
|
530
544
|
|
|
531
|
-
const fetchWeather =
|
|
545
|
+
const fetchWeather = createStep({
|
|
532
546
|
id: 'fetch-weather',
|
|
533
547
|
description: 'Fetches weather forecast for a given city',
|
|
534
548
|
inputSchema: z.object({
|
|
535
549
|
city: z.string().describe('The city to get the weather for'),
|
|
536
550
|
}),
|
|
537
551
|
outputSchema: forecastSchema,
|
|
538
|
-
execute: async ({
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
if (!triggerData) {
|
|
542
|
-
throw new Error('Trigger data not found');
|
|
552
|
+
execute: async ({ inputData }) => {
|
|
553
|
+
if (!inputData) {
|
|
554
|
+
throw new Error('Input data not found');
|
|
543
555
|
}
|
|
544
556
|
|
|
545
|
-
const geocodingUrl = \`https://geocoding-api.open-meteo.com/v1/search?name=\${encodeURIComponent(
|
|
557
|
+
const geocodingUrl = \`https://geocoding-api.open-meteo.com/v1/search?name=\${encodeURIComponent(inputData.city)}&count=1\`;
|
|
546
558
|
const geocodingResponse = await fetch(geocodingUrl);
|
|
547
559
|
const geocodingData = (await geocodingResponse.json()) as {
|
|
548
560
|
results: { latitude: number; longitude: number; name: string }[];
|
|
549
561
|
};
|
|
550
562
|
|
|
551
563
|
if (!geocodingData.results?.[0]) {
|
|
552
|
-
throw new Error(\`Location '\${
|
|
564
|
+
throw new Error(\`Location '\${inputData.city}' not found\`);
|
|
553
565
|
}
|
|
554
566
|
|
|
555
567
|
const { latitude, longitude, name } = geocodingData.results[0];
|
|
556
568
|
|
|
557
|
-
const weatherUrl = \`https://api.open-meteo.com/v1/forecast?latitude=\${latitude}&longitude=\${longitude}&
|
|
569
|
+
const weatherUrl = \`https://api.open-meteo.com/v1/forecast?latitude=\${latitude}&longitude=\${longitude}¤t=precipitation,weathercode&timezone=auto,&hourly=precipitation_probability,temperature_2m\`;
|
|
558
570
|
const response = await fetch(weatherUrl);
|
|
559
571
|
const data = (await response.json()) as {
|
|
560
|
-
|
|
561
|
-
time: string
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
572
|
+
current: {
|
|
573
|
+
time: string
|
|
574
|
+
precipitation: number
|
|
575
|
+
weathercode: number
|
|
576
|
+
}
|
|
577
|
+
hourly: {
|
|
578
|
+
precipitation_probability: number[]
|
|
579
|
+
temperature_2m: number[]
|
|
580
|
+
}
|
|
581
|
+
}
|
|
568
582
|
|
|
569
|
-
const forecast =
|
|
570
|
-
date,
|
|
571
|
-
maxTemp: data.
|
|
572
|
-
minTemp: data.
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
583
|
+
const forecast = {
|
|
584
|
+
date: new Date().toISOString(),
|
|
585
|
+
maxTemp: Math.max(...data.hourly.temperature_2m),
|
|
586
|
+
minTemp: Math.min(...data.hourly.temperature_2m),
|
|
587
|
+
condition: getWeatherCondition(data.current.weathercode),
|
|
588
|
+
precipitationChance: data.hourly.precipitation_probability.reduce(
|
|
589
|
+
(acc, curr) => Math.max(acc, curr),
|
|
590
|
+
0
|
|
591
|
+
),
|
|
592
|
+
}
|
|
577
593
|
|
|
578
594
|
return forecast;
|
|
579
595
|
},
|
|
580
596
|
});
|
|
581
597
|
|
|
582
598
|
|
|
583
|
-
const planActivities =
|
|
599
|
+
const planActivities = createStep({
|
|
584
600
|
id: 'plan-activities',
|
|
585
601
|
description: 'Suggests activities based on weather conditions',
|
|
586
|
-
|
|
587
|
-
|
|
602
|
+
inputSchema: forecastSchema,
|
|
603
|
+
outputSchema: z.object({
|
|
604
|
+
activities: z.string(),
|
|
605
|
+
}),
|
|
606
|
+
execute: async ({ inputData }) => {
|
|
607
|
+
const forecast = inputData
|
|
588
608
|
|
|
589
|
-
if (!forecast
|
|
590
|
-
throw new Error('Forecast data not found')
|
|
609
|
+
if (!forecast) {
|
|
610
|
+
throw new Error('Forecast data not found')
|
|
591
611
|
}
|
|
592
612
|
|
|
593
|
-
const prompt = \`Based on the following weather forecast for \${forecast
|
|
613
|
+
const prompt = \`Based on the following weather forecast for \${forecast.location}, suggest appropriate activities:
|
|
594
614
|
\${JSON.stringify(forecast, null, 2)}
|
|
595
615
|
\`;
|
|
596
616
|
|
|
@@ -614,35 +634,16 @@ const planActivities = new Step({
|
|
|
614
634
|
},
|
|
615
635
|
});
|
|
616
636
|
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
1: 'Mainly clear',
|
|
621
|
-
2: 'Partly cloudy',
|
|
622
|
-
3: 'Overcast',
|
|
623
|
-
45: 'Foggy',
|
|
624
|
-
48: 'Depositing rime fog',
|
|
625
|
-
51: 'Light drizzle',
|
|
626
|
-
53: 'Moderate drizzle',
|
|
627
|
-
55: 'Dense drizzle',
|
|
628
|
-
61: 'Slight rain',
|
|
629
|
-
63: 'Moderate rain',
|
|
630
|
-
65: 'Heavy rain',
|
|
631
|
-
71: 'Slight snow fall',
|
|
632
|
-
73: 'Moderate snow fall',
|
|
633
|
-
75: 'Heavy snow fall',
|
|
634
|
-
95: 'Thunderstorm',
|
|
635
|
-
};
|
|
636
|
-
return conditions[code] || 'Unknown';
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
const weatherWorkflow = new Workflow({
|
|
640
|
-
name: 'weather-workflow',
|
|
641
|
-
triggerSchema: z.object({
|
|
637
|
+
const weatherWorkflow = createWorkflow({
|
|
638
|
+
id: 'weather-workflow',
|
|
639
|
+
inputSchema: z.object({
|
|
642
640
|
city: z.string().describe('The city to get the weather for'),
|
|
643
641
|
}),
|
|
642
|
+
outputSchema: z.object({
|
|
643
|
+
activities: z.string(),
|
|
644
|
+
})
|
|
644
645
|
})
|
|
645
|
-
.
|
|
646
|
+
.then(fetchWeather)
|
|
646
647
|
.then(planActivities);
|
|
647
648
|
|
|
648
649
|
weatherWorkflow.commit();
|
|
@@ -704,10 +705,10 @@ export const mastra = new Mastra()
|
|
|
704
705
|
destPath,
|
|
705
706
|
`
|
|
706
707
|
import { Mastra } from '@mastra/core/mastra';
|
|
707
|
-
import {
|
|
708
|
+
import { PinoLogger } from '@mastra/loggers';
|
|
708
709
|
import { LibSQLStore } from '@mastra/libsql';
|
|
709
|
-
${addWorkflow ? `import { weatherWorkflow } from './workflows';` : ""}
|
|
710
|
-
${addAgent ? `import { weatherAgent } from './agents';` : ""}
|
|
710
|
+
${addWorkflow ? `import { weatherWorkflow } from './workflows/weather-workflow';` : ""}
|
|
711
|
+
${addAgent ? `import { weatherAgent } from './agents/weather-agent';` : ""}
|
|
711
712
|
|
|
712
713
|
export const mastra = new Mastra({
|
|
713
714
|
${filteredExports.join("\n ")}
|
|
@@ -715,7 +716,7 @@ export const mastra = new Mastra({
|
|
|
715
716
|
// stores telemetry, evals, ... into memory storage, if it needs to persist, change to file:../mastra.db
|
|
716
717
|
url: ":memory:",
|
|
717
718
|
}),
|
|
718
|
-
logger:
|
|
719
|
+
logger: new PinoLogger({
|
|
719
720
|
name: 'Mastra',
|
|
720
721
|
level: 'info',
|
|
721
722
|
}),
|
|
@@ -786,7 +787,9 @@ var writeAPIKey = async ({
|
|
|
786
787
|
apiKey = "your-api-key"
|
|
787
788
|
}) => {
|
|
788
789
|
const key = await getAPIKey(provider);
|
|
789
|
-
|
|
790
|
+
const escapedKey = shellQuote.quote([key]);
|
|
791
|
+
const escapedApiKey = shellQuote.quote([apiKey]);
|
|
792
|
+
await exec(`echo ${escapedKey}=${escapedApiKey} >> .env`);
|
|
790
793
|
};
|
|
791
794
|
var createMastraDir = async (directory) => {
|
|
792
795
|
let dir = directory.trim().split("/").filter((item) => item !== "");
|
|
@@ -800,7 +803,7 @@ var createMastraDir = async (directory) => {
|
|
|
800
803
|
}
|
|
801
804
|
};
|
|
802
805
|
var writeCodeSample = async (dirPath, component, llmProvider, importComponents) => {
|
|
803
|
-
const destPath = dirPath + `/${component}/
|
|
806
|
+
const destPath = dirPath + `/${component}/weather-${component.slice(0, -1)}.ts`;
|
|
804
807
|
try {
|
|
805
808
|
await writeCodeSampleForComponents(llmProvider, component, destPath, importComponents);
|
|
806
809
|
} catch (err) {
|
|
@@ -998,6 +1001,10 @@ var init = async ({
|
|
|
998
1001
|
if (needsMemory) {
|
|
999
1002
|
await depService.installPackages(["@mastra/memory"]);
|
|
1000
1003
|
}
|
|
1004
|
+
const needsLoggers = await depService.checkDependencies(["@mastra/loggers"]) !== `ok`;
|
|
1005
|
+
if (needsLoggers) {
|
|
1006
|
+
await depService.installPackages(["@mastra/loggers"]);
|
|
1007
|
+
}
|
|
1001
1008
|
}
|
|
1002
1009
|
const key = await getAPIKey(llmProvider || "openai");
|
|
1003
1010
|
const aiSdkPackage = getAISDKPackage(llmProvider);
|
|
@@ -1017,7 +1024,7 @@ var init = async ({
|
|
|
1017
1024
|
${color2.green("Mastra initialized successfully!")}
|
|
1018
1025
|
|
|
1019
1026
|
Add your ${color2.cyan(key)} as an environment variable
|
|
1020
|
-
in your ${color2.cyan(".env
|
|
1027
|
+
in your ${color2.cyan(".env")} file
|
|
1021
1028
|
`);
|
|
1022
1029
|
} else {
|
|
1023
1030
|
p.note(`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { create } from '../../chunk-
|
|
1
|
+
export { create } from '../../chunk-AMYIYOXP.js';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
2
|
import { PosthogAnalytics } from './chunk-7OXWUU2Q.js';
|
|
3
3
|
export { PosthogAnalytics } from './chunk-7OXWUU2Q.js';
|
|
4
|
-
import { DepsService, create, checkPkgJson, checkAndInstallCoreDeps, interactivePrompt, init, logger, FileService, convertToViteEnvVar } from './chunk-
|
|
5
|
-
export { create } from './chunk-
|
|
4
|
+
import { DepsService, create, checkPkgJson, checkAndInstallCoreDeps, interactivePrompt, init, logger, FileService, convertToViteEnvVar } from './chunk-AMYIYOXP.js';
|
|
5
|
+
export { create } from './chunk-AMYIYOXP.js';
|
|
6
6
|
import { Command } from 'commander';
|
|
7
7
|
import { config } from 'dotenv';
|
|
8
8
|
import { join as join$1, dirname } from 'node:path';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mastra",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0-alpha.2",
|
|
4
4
|
"license": "Elastic-2.0",
|
|
5
5
|
"description": "cli for mastra",
|
|
6
6
|
"type": "module",
|
|
@@ -47,23 +47,25 @@
|
|
|
47
47
|
"posthog-node": "4.16.0",
|
|
48
48
|
"prettier": "^3.5.3",
|
|
49
49
|
"prompt": "^1.3.0",
|
|
50
|
+
"shell-quote": "^1.8.2",
|
|
50
51
|
"shiki": "^1.29.2",
|
|
51
|
-
"superjson": "^2.2.2",
|
|
52
52
|
"strip-json-comments": "^5.0.1",
|
|
53
|
+
"superjson": "^2.2.2",
|
|
53
54
|
"swr": "^2.3.3",
|
|
54
55
|
"tcp-port-used": "^1.0.2",
|
|
55
56
|
"yocto-spinner": "^0.1.2",
|
|
56
57
|
"zod": "^3.24.3",
|
|
57
58
|
"zod-to-json-schema": "^3.24.5",
|
|
58
|
-
"@mastra/
|
|
59
|
-
"@mastra/
|
|
60
|
-
"@mastra/mcp": "^0.
|
|
59
|
+
"@mastra/deployer": "^0.4.0-alpha.1",
|
|
60
|
+
"@mastra/loggers": "^0.2.0-alpha.2",
|
|
61
|
+
"@mastra/mcp": "^0.6.0-alpha.1"
|
|
61
62
|
},
|
|
62
63
|
"devDependencies": {
|
|
63
64
|
"@microsoft/api-extractor": "^7.52.5",
|
|
64
65
|
"@types/fs-extra": "^11.0.4",
|
|
65
66
|
"@types/node": "^20.17.27",
|
|
66
67
|
"@types/prompt": "^1.1.9",
|
|
68
|
+
"@types/shell-quote": "^1.7.5",
|
|
67
69
|
"@types/tcp-port-used": "^1.0.4",
|
|
68
70
|
"cpy-cli": "^5.0.0",
|
|
69
71
|
"eslint": "^9.23.0",
|
|
@@ -75,8 +77,12 @@
|
|
|
75
77
|
"typescript": "^5.8.2",
|
|
76
78
|
"vitest": "^3.1.2",
|
|
77
79
|
"@internal/lint": "0.0.5",
|
|
78
|
-
"@mastra/client-js": "0.
|
|
79
|
-
"@mastra/playground-ui": "5.0
|
|
80
|
+
"@mastra/client-js": "0.2.0-alpha.1",
|
|
81
|
+
"@mastra/playground-ui": "5.1.0-alpha.1",
|
|
82
|
+
"@mastra/core": "0.10.0-alpha.1"
|
|
83
|
+
},
|
|
84
|
+
"peerDependencies": {
|
|
85
|
+
"@mastra/core": "^0.9.4"
|
|
80
86
|
},
|
|
81
87
|
"scripts": {
|
|
82
88
|
"build": "npm-run-all --serial build:lib copy-starter-files copy-templates build:playground",
|