mastra 0.2.0 → 0.2.1
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/analytics/index.js +1 -1
- package/dist/{chunk-K5HPNH5H.js → chunk-DHTLEROT.js} +2 -1
- package/dist/{chunk-TT6FMV27.js → chunk-P6O5VEBX.js} +4 -4
- package/dist/commands/create/create.js +1 -1
- package/dist/index.js +42 -39
- package/dist/starter-files/config.ts +2 -5
- package/dist/starter-files/tools.ts +9 -2
- package/dist/starter-files/workflow.ts +2 -2
- package/dist/templates/dev.entry.js +1 -1
- package/package.json +9 -5
- package/src/playground/dist/assets/index-BNNiZU0r.js +13 -0
- package/src/playground/dist/assets/index-BuVI_uRP.js +458 -0
- package/src/playground/dist/assets/style-DWhqBxda.css +1 -0
- package/src/playground/dist/index.html +2 -2
- package/src/playground/dist/assets/index-CoDuckY1.js +0 -13
- package/src/playground/dist/assets/index-CxbV91Kn.js +0 -457
- package/src/playground/dist/assets/style-hX1Pk3t-.css +0 -1
package/dist/analytics/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { PosthogAnalytics } from '../chunk-
|
|
1
|
+
export { PosthogAnalytics } from '../chunk-DHTLEROT.js';
|
|
@@ -375,7 +375,7 @@ async function installCoreDeps() {
|
|
|
375
375
|
}
|
|
376
376
|
spinner.start();
|
|
377
377
|
const depsService = new DepsService();
|
|
378
|
-
await depsService.installPackages(["@mastra/core@
|
|
378
|
+
await depsService.installPackages(["@mastra/core@latest"]);
|
|
379
379
|
spinner.success("@mastra/core installed successfully");
|
|
380
380
|
} catch (err) {
|
|
381
381
|
console.error(err);
|
|
@@ -466,7 +466,7 @@ var interactivePrompt = async () => {
|
|
|
466
466
|
placeholder: "sk-..."
|
|
467
467
|
});
|
|
468
468
|
}
|
|
469
|
-
return
|
|
469
|
+
return void 0;
|
|
470
470
|
},
|
|
471
471
|
addExample: () => p.confirm({
|
|
472
472
|
message: "Add example",
|
|
@@ -618,10 +618,10 @@ var createMastraProject = async () => {
|
|
|
618
618
|
}' > tsconfig.json`);
|
|
619
619
|
s2.stop("NPM dependencies installed");
|
|
620
620
|
s2.start("Installing mastra");
|
|
621
|
-
await exec3(`npm i -D mastra`);
|
|
621
|
+
await exec3(`npm i -D mastra@latest`);
|
|
622
622
|
s2.stop("mastra installed");
|
|
623
623
|
s2.start("Installing @mastra/core");
|
|
624
|
-
await exec3(`npm i @mastra/core@
|
|
624
|
+
await exec3(`npm i @mastra/core@latest`);
|
|
625
625
|
s2.stop("@mastra/core installed");
|
|
626
626
|
s2.start("Adding .gitignore");
|
|
627
627
|
await exec3(`echo output.txt >> .gitignore`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { create } from '../../chunk-
|
|
1
|
+
export { create } from '../../chunk-P6O5VEBX.js';
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
import { PosthogAnalytics } from './chunk-
|
|
3
|
-
export { PosthogAnalytics } from './chunk-
|
|
4
|
-
import { DepsService, create, checkPkgJson, checkAndInstallCoreDeps, interactivePrompt, init,
|
|
5
|
-
export { create } from './chunk-
|
|
2
|
+
import { PosthogAnalytics } from './chunk-DHTLEROT.js';
|
|
3
|
+
export { PosthogAnalytics } from './chunk-DHTLEROT.js';
|
|
4
|
+
import { DepsService, create, checkPkgJson, checkAndInstallCoreDeps, interactivePrompt, init, logger, FileService as FileService$1 } from './chunk-P6O5VEBX.js';
|
|
5
|
+
export { create } from './chunk-P6O5VEBX.js';
|
|
6
6
|
import { Command } from 'commander';
|
|
7
7
|
import 'picocolors';
|
|
8
|
-
import { join, dirname } from 'node:path';
|
|
9
|
-
import { FileService as FileService$2
|
|
8
|
+
import { join as join$1, dirname } from 'node:path';
|
|
9
|
+
import { getWatcherInputOptions, writeTelemetryConfig, createWatcher, FileService as FileService$2 } from '@mastra/deployer/build';
|
|
10
10
|
import { Bundler } from '@mastra/deployer/bundler';
|
|
11
11
|
import * as fsExtra from 'fs-extra';
|
|
12
12
|
import { readFileSync } from 'node:fs';
|
|
13
13
|
import { fileURLToPath } from 'node:url';
|
|
14
|
-
import {
|
|
15
|
-
import { join
|
|
14
|
+
import { FileService, getDeployer } from '@mastra/deployer';
|
|
15
|
+
import { join } from 'path';
|
|
16
16
|
import { execa } from 'execa';
|
|
17
17
|
import '@mastra/core/bundler';
|
|
18
18
|
import 'dotenv';
|
|
@@ -35,8 +35,8 @@ var BuildBundler = class extends Bundler {
|
|
|
35
35
|
await super.prepare(outputDirectory);
|
|
36
36
|
const __filename = fileURLToPath(import.meta.url);
|
|
37
37
|
const __dirname = dirname(__filename);
|
|
38
|
-
const playgroundServePath = join(outputDirectory, this.outputDir, "playground");
|
|
39
|
-
await fsExtra.copy(join(dirname(__dirname), "src/playground/dist"), playgroundServePath, {
|
|
38
|
+
const playgroundServePath = join$1(outputDirectory, this.outputDir, "playground");
|
|
39
|
+
await fsExtra.copy(join$1(dirname(__dirname), "src/playground/dist"), playgroundServePath, {
|
|
40
40
|
overwrite: true
|
|
41
41
|
});
|
|
42
42
|
}
|
|
@@ -46,30 +46,30 @@ var BuildBundler = class extends Bundler {
|
|
|
46
46
|
getEntry() {
|
|
47
47
|
const __filename = fileURLToPath(import.meta.url);
|
|
48
48
|
const __dirname = dirname(__filename);
|
|
49
|
-
return readFileSync(join(__dirname, "templates", "dev.entry.js"), "utf8");
|
|
49
|
+
return readFileSync(join$1(__dirname, "templates", "dev.entry.js"), "utf8");
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
// src/commands/build/build.ts
|
|
54
54
|
async function build({ dir }) {
|
|
55
55
|
const mastraDir = dir ?? process.cwd();
|
|
56
|
-
const outputDirectory = join(mastraDir, ".mastra");
|
|
56
|
+
const outputDirectory = join$1(mastraDir, ".mastra");
|
|
57
57
|
const deployer = new BuildBundler();
|
|
58
|
-
const fs = new FileService();
|
|
58
|
+
const fs = new FileService$1();
|
|
59
59
|
const mastraEntryFile = fs.getFirstExistingFile([
|
|
60
|
-
join(mastraDir, "src", "mastra", "index.ts"),
|
|
61
|
-
join(mastraDir, "src", "mastra", "index.js")
|
|
60
|
+
join$1(mastraDir, "src", "mastra", "index.ts"),
|
|
61
|
+
join$1(mastraDir, "src", "mastra", "index.js")
|
|
62
62
|
]);
|
|
63
|
-
console.log(join(mastraDir, "index.ts"), join(mastraDir, "index.js"));
|
|
63
|
+
console.log(join$1(mastraDir, "index.ts"), join$1(mastraDir, "index.js"));
|
|
64
64
|
await deployer.prepare(outputDirectory);
|
|
65
65
|
await deployer.bundle(mastraEntryFile, outputDirectory);
|
|
66
66
|
}
|
|
67
67
|
async function deploy({ dir }) {
|
|
68
|
-
let mastraDir = dir || join
|
|
68
|
+
let mastraDir = dir || join(process.cwd(), "src/mastra");
|
|
69
69
|
try {
|
|
70
|
-
const outputDirectory = join
|
|
71
|
-
const fs = new FileService();
|
|
72
|
-
const mastraEntryFile = fs.getFirstExistingFile([join
|
|
70
|
+
const outputDirectory = join(process.cwd(), ".mastra");
|
|
71
|
+
const fs = new FileService$1();
|
|
72
|
+
const mastraEntryFile = fs.getFirstExistingFile([join(mastraDir, "index.ts"), join(mastraDir, "index.js")]);
|
|
73
73
|
const deployer = await getDeployer(mastraEntryFile, outputDirectory);
|
|
74
74
|
if (!deployer) {
|
|
75
75
|
logger.warn("No deployer found.");
|
|
@@ -102,7 +102,7 @@ var DevBundler = class extends Bundler {
|
|
|
102
102
|
getEnvFiles() {
|
|
103
103
|
const possibleFiles = [".env.development", ".env"];
|
|
104
104
|
try {
|
|
105
|
-
const fileService = new FileService
|
|
105
|
+
const fileService = new FileService();
|
|
106
106
|
const envFile = fileService.getFirstExistingFile(possibleFiles);
|
|
107
107
|
return Promise.resolve([envFile]);
|
|
108
108
|
} catch (err) {
|
|
@@ -115,8 +115,8 @@ var DevBundler = class extends Bundler {
|
|
|
115
115
|
await super.prepare(outputDirectory);
|
|
116
116
|
const __filename = fileURLToPath(import.meta.url);
|
|
117
117
|
const __dirname = dirname(__filename);
|
|
118
|
-
const playgroundServePath = join(outputDirectory, this.outputDir, "playground");
|
|
119
|
-
await fsExtra.copy(join(dirname(__dirname), "src/playground/dist"), playgroundServePath, {
|
|
118
|
+
const playgroundServePath = join$1(outputDirectory, this.outputDir, "playground");
|
|
119
|
+
await fsExtra.copy(join$1(dirname(__dirname), "src/playground/dist"), playgroundServePath, {
|
|
120
120
|
overwrite: true
|
|
121
121
|
});
|
|
122
122
|
}
|
|
@@ -125,13 +125,14 @@ var DevBundler = class extends Bundler {
|
|
|
125
125
|
const __dirname = dirname(__filename);
|
|
126
126
|
const envFiles = await this.getEnvFiles();
|
|
127
127
|
const inputOptions = await getWatcherInputOptions(entryFile, "node");
|
|
128
|
-
await writeTelemetryConfig(entryFile, join(outputDirectory, this.outputDir));
|
|
129
|
-
await this.writeInstrumentationFile(join(outputDirectory, this.outputDir));
|
|
128
|
+
await writeTelemetryConfig(entryFile, join$1(outputDirectory, this.outputDir));
|
|
129
|
+
await this.writeInstrumentationFile(join$1(outputDirectory, this.outputDir));
|
|
130
130
|
const watcher = await createWatcher(
|
|
131
131
|
{
|
|
132
132
|
...inputOptions,
|
|
133
133
|
plugins: [
|
|
134
134
|
// @ts-ignore - types are good
|
|
135
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
135
136
|
...inputOptions.plugins,
|
|
136
137
|
{
|
|
137
138
|
name: "env-watcher",
|
|
@@ -143,11 +144,11 @@ var DevBundler = class extends Bundler {
|
|
|
143
144
|
}
|
|
144
145
|
],
|
|
145
146
|
input: {
|
|
146
|
-
index: join(__dirname, "templates", "dev.entry.js")
|
|
147
|
+
index: join$1(__dirname, "templates", "dev.entry.js")
|
|
147
148
|
}
|
|
148
149
|
},
|
|
149
150
|
{
|
|
150
|
-
dir: join(outputDirectory, this.outputDir)
|
|
151
|
+
dir: join$1(outputDirectory, this.outputDir)
|
|
151
152
|
}
|
|
152
153
|
);
|
|
153
154
|
this.logger.info("Starting watcher...");
|
|
@@ -178,15 +179,16 @@ var isRestarting = false;
|
|
|
178
179
|
var startServer = async (dotMastraPath, port, env) => {
|
|
179
180
|
try {
|
|
180
181
|
logger.info("[Mastra Dev] - Starting server...");
|
|
182
|
+
const instrumentation = import.meta.resolve("@opentelemetry/instrumentation/hook.mjs");
|
|
181
183
|
currentServerProcess = execa(
|
|
182
184
|
"node",
|
|
183
|
-
["--import=./instrumentation.mjs",
|
|
185
|
+
["--import=./instrumentation.mjs", `--import=${instrumentation}`, "index.mjs"],
|
|
184
186
|
{
|
|
185
187
|
cwd: dotMastraPath,
|
|
186
188
|
env: {
|
|
187
189
|
PORT: port.toString() || "4111",
|
|
188
190
|
...Object.fromEntries(env),
|
|
189
|
-
MASTRA_DEFAULT_STORAGE_URL: `file:${join
|
|
191
|
+
MASTRA_DEFAULT_STORAGE_URL: `file:${join(dotMastraPath, "..", "mastra.db")}`
|
|
190
192
|
},
|
|
191
193
|
stdio: "inherit",
|
|
192
194
|
reject: false
|
|
@@ -236,26 +238,25 @@ async function rebundleAndRestart(dotMastraPath, port, bundler) {
|
|
|
236
238
|
try {
|
|
237
239
|
if (currentServerProcess) {
|
|
238
240
|
logger.debug("Stopping current server...");
|
|
239
|
-
currentServerProcess.kill();
|
|
240
|
-
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
241
|
+
currentServerProcess.kill("SIGKILL");
|
|
241
242
|
}
|
|
242
243
|
const env = await bundler.loadEnvVars();
|
|
243
|
-
await startServer(dotMastraPath, port, env);
|
|
244
|
+
await startServer(join(dotMastraPath, "output"), port, env);
|
|
244
245
|
} finally {
|
|
245
246
|
isRestarting = false;
|
|
246
247
|
}
|
|
247
248
|
}
|
|
248
249
|
async function dev({ port, dir, root }) {
|
|
249
250
|
const rootDir = root || process.cwd();
|
|
250
|
-
const mastraDir = join
|
|
251
|
-
const dotMastraPath = join
|
|
252
|
-
const fileService = new FileService
|
|
253
|
-
const entryFile = fileService.getFirstExistingFile([join
|
|
251
|
+
const mastraDir = join(rootDir, dir || "src/mastra");
|
|
252
|
+
const dotMastraPath = join(rootDir, ".mastra");
|
|
253
|
+
const fileService = new FileService();
|
|
254
|
+
const entryFile = fileService.getFirstExistingFile([join(mastraDir, "index.ts"), join(mastraDir, "index.js")]);
|
|
254
255
|
const bundler = new DevBundler();
|
|
255
256
|
const env = await bundler.loadEnvVars();
|
|
256
257
|
await bundler.prepare(dotMastraPath);
|
|
257
258
|
const watcher = await bundler.watch(entryFile, dotMastraPath);
|
|
258
|
-
await startServer(join
|
|
259
|
+
await startServer(join(dotMastraPath, "output"), port, env);
|
|
259
260
|
watcher.on("event", (event) => {
|
|
260
261
|
if (event.code === "BUNDLE_END") {
|
|
261
262
|
logger.info("[Mastra Dev] - Bundling finished, restarting server...");
|
|
@@ -328,7 +329,7 @@ program.command("init").description("Initialize Mastra in your project").option(
|
|
|
328
329
|
return;
|
|
329
330
|
}
|
|
330
331
|
if (args?.default) {
|
|
331
|
-
init({
|
|
332
|
+
await init({
|
|
332
333
|
directory: "src/",
|
|
333
334
|
components: ["agents", "tools", "workflows"],
|
|
334
335
|
llmProvider: "openai",
|
|
@@ -337,7 +338,7 @@ program.command("init").description("Initialize Mastra in your project").option(
|
|
|
337
338
|
return;
|
|
338
339
|
}
|
|
339
340
|
const componentsArr = args.components ? args.components.split(",") : [];
|
|
340
|
-
init({
|
|
341
|
+
await init({
|
|
341
342
|
directory: args.dir,
|
|
342
343
|
components: componentsArr,
|
|
343
344
|
llmProvider: args.llm,
|
|
@@ -356,6 +357,8 @@ program.command("dev").description("Start mastra server").option("-d, --dir <dir
|
|
|
356
357
|
port: args?.port ? parseInt(args.port) : 4111,
|
|
357
358
|
dir: args?.dir,
|
|
358
359
|
root: args?.root
|
|
360
|
+
}).catch((err) => {
|
|
361
|
+
logger.error(err.message);
|
|
359
362
|
});
|
|
360
363
|
});
|
|
361
364
|
program.command("build").description("Build your Mastra project").option("-d, --dir <path>", "Path to directory").action(async (args) => {
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { Config } from '@mastra/core';
|
|
3
|
-
|
|
4
|
-
export const config: Config = {
|
|
1
|
+
export const config = {
|
|
5
2
|
name: 'PROJECT_NAME',
|
|
6
3
|
integrations: [],
|
|
7
4
|
db: {
|
|
@@ -25,4 +22,4 @@ export const config: Config = {
|
|
|
25
22
|
},
|
|
26
23
|
systemHostURL: process.env.APP_URL!,
|
|
27
24
|
routeRegistrationPath: '/api/mastra',
|
|
28
|
-
};
|
|
25
|
+
} as const;
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { createTool } from '@mastra/core/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
|
|
4
|
+
interface GeocodingResponse {
|
|
5
|
+
results: {
|
|
6
|
+
latitude: number;
|
|
7
|
+
longitude: number;
|
|
8
|
+
name: string;
|
|
9
|
+
}[];
|
|
10
|
+
}
|
|
4
11
|
interface WeatherResponse {
|
|
5
12
|
current: {
|
|
6
13
|
time: string;
|
|
@@ -36,7 +43,7 @@ export const weatherTool = createTool({
|
|
|
36
43
|
const getWeather = async (location: string) => {
|
|
37
44
|
const geocodingUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(location)}&count=1`;
|
|
38
45
|
const geocodingResponse = await fetch(geocodingUrl);
|
|
39
|
-
const geocodingData = await geocodingResponse.json();
|
|
46
|
+
const geocodingData = (await geocodingResponse.json()) as GeocodingResponse;
|
|
40
47
|
|
|
41
48
|
if (!geocodingData.results?.[0]) {
|
|
42
49
|
throw new Error(`Location '${location}' not found`);
|
|
@@ -47,7 +54,7 @@ const getWeather = async (location: string) => {
|
|
|
47
54
|
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
55
|
|
|
49
56
|
const response = await fetch(weatherUrl);
|
|
50
|
-
const data
|
|
57
|
+
const data = (await response.json()) as WeatherResponse;
|
|
51
58
|
|
|
52
59
|
return {
|
|
53
60
|
temperature: data.current.temperature_2m,
|
|
@@ -121,11 +121,11 @@ const planActivities = new Step({
|
|
|
121
121
|
execute: async ({ context, mastra }) => {
|
|
122
122
|
const forecast = context?.getStepPayload<z.infer<typeof forecastSchema>>('fetch-weather');
|
|
123
123
|
|
|
124
|
-
if (!forecast) {
|
|
124
|
+
if (!forecast || forecast.length === 0) {
|
|
125
125
|
throw new Error('Forecast data not found');
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
const prompt = `Based on the following weather forecast for ${forecast[0]
|
|
128
|
+
const prompt = `Based on the following weather forecast for ${forecast[0]?.location}, suggest appropriate activities:
|
|
129
129
|
${JSON.stringify(forecast, null, 2)}
|
|
130
130
|
`;
|
|
131
131
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mastra",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "cli for mastra",
|
|
6
6
|
"type": "module",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@clack/prompts": "^0.8.2",
|
|
38
38
|
"@dagrejs/dagre": "^1.1.4",
|
|
39
|
+
"@opentelemetry/instrumentation": "^0.57.2",
|
|
39
40
|
"@swc/core": "^1.9.3",
|
|
40
41
|
"chokidar": "^4.0.3",
|
|
41
42
|
"commander": "^12.1.0",
|
|
@@ -54,8 +55,8 @@
|
|
|
54
55
|
"yocto-spinner": "^0.1.1",
|
|
55
56
|
"zod": "^3.24.1",
|
|
56
57
|
"zod-to-json-schema": "^3.24.1",
|
|
57
|
-
"@mastra/core": "^0.2.
|
|
58
|
-
"@mastra/deployer": "^0.1.
|
|
58
|
+
"@mastra/core": "^0.2.1",
|
|
59
|
+
"@mastra/deployer": "^0.1.1"
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
|
61
62
|
"@ai-sdk/openai": "^1.1.9",
|
|
@@ -66,13 +67,15 @@
|
|
|
66
67
|
"@types/prompt": "^1.1.8",
|
|
67
68
|
"@types/tcp-port-used": "^1.0.4",
|
|
68
69
|
"cpy-cli": "^5.0.0",
|
|
70
|
+
"eslint": "^9.20.1",
|
|
69
71
|
"memfs": "^4.14.0",
|
|
70
72
|
"npm-run-all": "^4.1.5",
|
|
71
73
|
"rollup": "^4.30.1",
|
|
72
74
|
"tsup": "^8.3.5",
|
|
73
75
|
"type-fest": "^4.30.0",
|
|
74
76
|
"typescript": "^5.7.3",
|
|
75
|
-
"vitest": "^3.0.4"
|
|
77
|
+
"vitest": "^3.0.4",
|
|
78
|
+
"@internal/lint": "0.0.0"
|
|
76
79
|
},
|
|
77
80
|
"scripts": {
|
|
78
81
|
"build": "npm-run-all --serial build:lib copy-starter-files copy-templates build:playground",
|
|
@@ -86,6 +89,7 @@
|
|
|
86
89
|
"test:watch": "vitest watch",
|
|
87
90
|
"clean": "rm -rf dist && rm -rf node_modules",
|
|
88
91
|
"typecheck": "tsc --noEmit --incremental",
|
|
89
|
-
"postinstall": "node src/scripts/postinstall.js"
|
|
92
|
+
"postinstall": "node src/scripts/postinstall.js",
|
|
93
|
+
"lint": "eslint ."
|
|
90
94
|
}
|
|
91
95
|
}
|