mastra 0.4.10-alpha.3 → 0.5.0-alpha.5
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/index.js +25 -74
- package/dist/templates/dev.entry.js +6 -4
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { DepsService, create, checkPkgJson, checkAndInstallCoreDeps, interactive
|
|
|
5
5
|
export { create } from './chunk-BY3FZLXQ.js';
|
|
6
6
|
import { Command } from 'commander';
|
|
7
7
|
import { config } from 'dotenv';
|
|
8
|
-
import { join as join$1, dirname
|
|
8
|
+
import { join as join$1, dirname } from 'node:path';
|
|
9
9
|
import { getServerOptions, getWatcherInputOptions, writeTelemetryConfig, createWatcher, FileService as FileService$2 } from '@mastra/deployer/build';
|
|
10
10
|
import { Bundler } from '@mastra/deployer/bundler';
|
|
11
11
|
import * as fsExtra2 from 'fs-extra';
|
|
@@ -15,7 +15,7 @@ import { FileService, getDeployer } from '@mastra/deployer';
|
|
|
15
15
|
import { join } from 'path';
|
|
16
16
|
import { isWebContainer } from '@webcontainer/env';
|
|
17
17
|
import { execa } from 'execa';
|
|
18
|
-
import {
|
|
18
|
+
import { writeFile } from 'node:fs/promises';
|
|
19
19
|
|
|
20
20
|
var BuildBundler = class extends Bundler {
|
|
21
21
|
constructor() {
|
|
@@ -34,8 +34,8 @@ var BuildBundler = class extends Bundler {
|
|
|
34
34
|
async prepare(outputDirectory) {
|
|
35
35
|
await super.prepare(outputDirectory);
|
|
36
36
|
}
|
|
37
|
-
bundle(entryFile, outputDirectory) {
|
|
38
|
-
return this._bundle(this.getEntry(), entryFile, outputDirectory);
|
|
37
|
+
bundle(entryFile, outputDirectory, toolsPaths) {
|
|
38
|
+
return this._bundle(this.getEntry(), entryFile, outputDirectory, toolsPaths);
|
|
39
39
|
}
|
|
40
40
|
getEntry() {
|
|
41
41
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -43,9 +43,11 @@ var BuildBundler = class extends Bundler {
|
|
|
43
43
|
return readFileSync(join$1(__dirname, "templates", "dev.entry.js"), "utf8");
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
|
-
async function build({ dir }) {
|
|
46
|
+
async function build({ dir, tools }) {
|
|
47
47
|
const mastraDir = dir ?? join$1(process.cwd(), "src", "mastra");
|
|
48
48
|
const outputDirectory = join$1(process.cwd(), ".mastra");
|
|
49
|
+
const defaultToolsPath = join$1(mastraDir, "tools");
|
|
50
|
+
const discoveredTools = [defaultToolsPath, ...tools ?? []];
|
|
49
51
|
try {
|
|
50
52
|
const fs = new FileService$1();
|
|
51
53
|
const mastraEntryFile = fs.getFirstExistingFile([join$1(mastraDir, "index.ts"), join$1(mastraDir, "index.js")]);
|
|
@@ -53,12 +55,12 @@ async function build({ dir }) {
|
|
|
53
55
|
if (!platformDeployer) {
|
|
54
56
|
const deployer = new BuildBundler();
|
|
55
57
|
await deployer.prepare(outputDirectory);
|
|
56
|
-
await deployer.bundle(mastraEntryFile, outputDirectory);
|
|
58
|
+
await deployer.bundle(mastraEntryFile, outputDirectory, discoveredTools);
|
|
57
59
|
return;
|
|
58
60
|
}
|
|
59
61
|
logger.info("Deployer found, preparing deployer build...");
|
|
60
62
|
await platformDeployer.prepare(outputDirectory);
|
|
61
|
-
await platformDeployer.bundle(mastraEntryFile, outputDirectory);
|
|
63
|
+
await platformDeployer.bundle(mastraEntryFile, outputDirectory, discoveredTools);
|
|
62
64
|
logger.info("You can now deploy the .mastra/output directory to your target platform.");
|
|
63
65
|
} catch (error) {
|
|
64
66
|
if (error instanceof Error) {
|
|
@@ -79,7 +81,7 @@ async function deploy({ dir }) {
|
|
|
79
81
|
}
|
|
80
82
|
try {
|
|
81
83
|
await deployer.prepare(outputDirectory);
|
|
82
|
-
await deployer.bundle(mastraEntryFile, outputDirectory);
|
|
84
|
+
await deployer.bundle(mastraEntryFile, outputDirectory, []);
|
|
83
85
|
try {
|
|
84
86
|
await deployer.deploy(outputDirectory);
|
|
85
87
|
} catch (error) {
|
|
@@ -98,7 +100,6 @@ async function deploy({ dir }) {
|
|
|
98
100
|
}
|
|
99
101
|
}
|
|
100
102
|
var DevBundler = class extends Bundler {
|
|
101
|
-
mastraToolsPaths = [];
|
|
102
103
|
constructor() {
|
|
103
104
|
super("Dev");
|
|
104
105
|
}
|
|
@@ -112,11 +113,6 @@ var DevBundler = class extends Bundler {
|
|
|
112
113
|
}
|
|
113
114
|
return Promise.resolve([]);
|
|
114
115
|
}
|
|
115
|
-
async loadEnvVars() {
|
|
116
|
-
const superEnvVars = await super.loadEnvVars();
|
|
117
|
-
superEnvVars.set("MASTRA_TOOLS_PATH", this.mastraToolsPaths.join(","));
|
|
118
|
-
return superEnvVars;
|
|
119
|
-
}
|
|
120
116
|
async writePackageJson() {
|
|
121
117
|
}
|
|
122
118
|
async prepare(outputDirectory) {
|
|
@@ -133,55 +129,9 @@ var DevBundler = class extends Bundler {
|
|
|
133
129
|
const __dirname = dirname(__filename);
|
|
134
130
|
const envFiles = await this.getEnvFiles();
|
|
135
131
|
const inputOptions = await getWatcherInputOptions(entryFile, "node");
|
|
132
|
+
const toolsInputOptions = await this.getToolsInputOptions(toolsPaths);
|
|
136
133
|
await writeTelemetryConfig(entryFile, join$1(outputDirectory, this.outputDir));
|
|
137
134
|
await this.writeInstrumentationFile(join$1(outputDirectory, this.outputDir));
|
|
138
|
-
if (toolsPaths?.length) {
|
|
139
|
-
for (const toolPath of toolsPaths) {
|
|
140
|
-
if (await fsExtra2.pathExists(toolPath)) {
|
|
141
|
-
const toolName = basename(toolPath);
|
|
142
|
-
const toolOutputPath = join$1(outputDirectory, this.outputDir, "tools", toolName);
|
|
143
|
-
const fileService = new FileService();
|
|
144
|
-
const entryFile2 = fileService.getFirstExistingFile([
|
|
145
|
-
join$1(toolPath, "index.ts"),
|
|
146
|
-
join$1(toolPath, "index.js"),
|
|
147
|
-
toolPath
|
|
148
|
-
// if toolPath itself is a file
|
|
149
|
-
]);
|
|
150
|
-
if (!entryFile2 || (await stat(entryFile2)).isDirectory()) {
|
|
151
|
-
this.logger.warn(`No entry file found in ${toolPath}, skipping...`);
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
const toolInputOptions = await getWatcherInputOptions(entryFile2, "node");
|
|
155
|
-
const watcher2 = await createWatcher(
|
|
156
|
-
{
|
|
157
|
-
...toolInputOptions,
|
|
158
|
-
input: {
|
|
159
|
-
index: entryFile2
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
dir: toolOutputPath
|
|
164
|
-
}
|
|
165
|
-
);
|
|
166
|
-
await new Promise((resolve, reject) => {
|
|
167
|
-
const cb = (event) => {
|
|
168
|
-
if (event.code === "BUNDLE_END") {
|
|
169
|
-
watcher2.off("event", cb);
|
|
170
|
-
resolve(void 0);
|
|
171
|
-
}
|
|
172
|
-
if (event.code === "ERROR") {
|
|
173
|
-
watcher2.off("event", cb);
|
|
174
|
-
reject(event);
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
watcher2.on("event", cb);
|
|
178
|
-
});
|
|
179
|
-
this.mastraToolsPaths.push(join$1(toolOutputPath, "index.mjs"));
|
|
180
|
-
} else {
|
|
181
|
-
this.logger.warn(`Tool path ${toolPath} does not exist, skipping...`);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
135
|
const outputDir = join$1(outputDirectory, this.outputDir);
|
|
186
136
|
const copyPublic = this.copyPublic.bind(this);
|
|
187
137
|
const watcher = await createWatcher(
|
|
@@ -199,16 +149,6 @@ var DevBundler = class extends Bundler {
|
|
|
199
149
|
}
|
|
200
150
|
}
|
|
201
151
|
},
|
|
202
|
-
{
|
|
203
|
-
name: "tools-watcher",
|
|
204
|
-
buildStart() {
|
|
205
|
-
if (toolsPaths?.length) {
|
|
206
|
-
for (const toolPath of toolsPaths) {
|
|
207
|
-
this.addWatchFile(toolPath);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
},
|
|
212
152
|
{
|
|
213
153
|
name: "public-dir-watcher",
|
|
214
154
|
buildStart() {
|
|
@@ -217,10 +157,21 @@ var DevBundler = class extends Bundler {
|
|
|
217
157
|
buildEnd() {
|
|
218
158
|
return copyPublic(dirname(entryFile), outputDirectory);
|
|
219
159
|
}
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
name: "tools-watcher",
|
|
163
|
+
async buildEnd() {
|
|
164
|
+
const toolsInputOptions2 = Array.from(Object.keys(inputOptions.input || {})).filter((key) => key.startsWith("tools/")).map((key) => `./${key}.mjs`);
|
|
165
|
+
await writeFile(
|
|
166
|
+
join$1(outputDir, "tools.mjs"),
|
|
167
|
+
`export const tools = ${JSON.stringify(toolsInputOptions2)};`
|
|
168
|
+
);
|
|
169
|
+
}
|
|
220
170
|
}
|
|
221
171
|
],
|
|
222
172
|
input: {
|
|
223
|
-
index: join$1(__dirname, "templates", "dev.entry.js")
|
|
173
|
+
index: join$1(__dirname, "templates", "dev.entry.js"),
|
|
174
|
+
...toolsInputOptions
|
|
224
175
|
}
|
|
225
176
|
},
|
|
226
177
|
{
|
|
@@ -466,12 +417,12 @@ program.command("dev").description("Start mastra server").option("-d, --dir <dir
|
|
|
466
417
|
logger.error(err.message);
|
|
467
418
|
});
|
|
468
419
|
});
|
|
469
|
-
program.command("build").description("Build your Mastra project").option("-d, --dir <path>", "Path to directory").action(async (args) => {
|
|
420
|
+
program.command("build").description("Build your Mastra project").option("-d, --dir <path>", "Path to directory").option("-t, --tools <toolsDirs>", "Comma-separated list of paths to tool files to include").action(async (args) => {
|
|
470
421
|
await analytics.trackCommandExecution({
|
|
471
422
|
command: "mastra build",
|
|
472
423
|
args,
|
|
473
424
|
execution: async () => {
|
|
474
|
-
await build({ dir: args.dir });
|
|
425
|
+
await build({ dir: args.dir, tools: args.tools ? args.tools.split(",") : [] });
|
|
475
426
|
},
|
|
476
427
|
origin
|
|
477
428
|
});
|
|
@@ -21,18 +21,20 @@ registerHook(AvailableHooks.ON_GENERATION, ({ input, output, metric, runId, agen
|
|
|
21
21
|
});
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
if (mastra.
|
|
25
|
-
|
|
24
|
+
if (mastra.getStorage()) {
|
|
25
|
+
// start storage init in the background
|
|
26
|
+
mastra.getStorage().init();
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
registerHook(AvailableHooks.ON_EVALUATION, async traceObject => {
|
|
29
|
-
|
|
30
|
+
const storage = mastra.getStorage();
|
|
31
|
+
if (storage) {
|
|
30
32
|
// Check for required fields
|
|
31
33
|
const logger = mastra?.getLogger();
|
|
32
34
|
const areFieldsValid = checkEvalStorageFields(traceObject, logger);
|
|
33
35
|
if (!areFieldsValid) return;
|
|
34
36
|
|
|
35
|
-
await
|
|
37
|
+
await storage.insert({
|
|
36
38
|
tableName: TABLE_EVALS,
|
|
37
39
|
record: {
|
|
38
40
|
input: traceObject.input,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mastra",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0-alpha.5",
|
|
4
4
|
"license": "Elastic-2.0",
|
|
5
5
|
"description": "cli for mastra",
|
|
6
6
|
"type": "module",
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"yocto-spinner": "^0.1.2",
|
|
55
55
|
"zod": "^3.24.2",
|
|
56
56
|
"zod-to-json-schema": "^3.24.3",
|
|
57
|
-
"@mastra/core": "^0.
|
|
58
|
-
"@mastra/deployer": "^0.
|
|
57
|
+
"@mastra/core": "^0.9.0-alpha.4",
|
|
58
|
+
"@mastra/deployer": "^0.3.0-alpha.5"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@microsoft/api-extractor": "^7.52.1",
|
|
@@ -72,9 +72,9 @@
|
|
|
72
72
|
"type-fest": "^4.37.0",
|
|
73
73
|
"typescript": "^5.8.2",
|
|
74
74
|
"vitest": "^3.0.9",
|
|
75
|
+
"@mastra/client-js": "0.1.18-alpha.4",
|
|
75
76
|
"@internal/lint": "0.0.2",
|
|
76
|
-
"@mastra/playground-ui": "
|
|
77
|
-
"@mastra/client-js": "0.1.18-alpha.2"
|
|
77
|
+
"@mastra/playground-ui": "5.0.0-alpha.4"
|
|
78
78
|
},
|
|
79
79
|
"scripts": {
|
|
80
80
|
"build": "npm-run-all --serial build:lib copy-starter-files copy-templates build:playground",
|