mastra 0.2.0-alpha.152 → 0.2.0-alpha.155

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.
@@ -226,17 +226,29 @@ var logger = createLogger({
226
226
 
227
227
  // src/commands/init/utils.ts
228
228
  var exec = util.promisify(child_process.exec);
229
+ var getAISDKPackage = (llmProvider) => {
230
+ switch (llmProvider) {
231
+ case "openai":
232
+ return "@ai-sdk/openai";
233
+ case "anthropic":
234
+ return "@ai-sdk/anthropic";
235
+ case "groq":
236
+ return "@ai-sdk/groq";
237
+ default:
238
+ return "@ai-sdk/openai";
239
+ }
240
+ };
229
241
  async function writeAgentSample(llmProvider, destPath, addExampleTool) {
230
242
  let providerImport = "";
231
243
  let modelItem = "";
232
244
  if (llmProvider === "openai") {
233
- providerImport = `import { openai } from '@ai-sdk/openai';`;
245
+ providerImport = `import { openai } from '${getAISDKPackage(llmProvider)}';`;
234
246
  modelItem = `openai('gpt-4o')`;
235
247
  } else if (llmProvider === "anthropic") {
236
- providerImport = `import { anthropic } from '@ai-sdk/anthropic';`;
248
+ providerImport = `import { anthropic } from '${getAISDKPackage(llmProvider)}';`;
237
249
  modelItem = `anthropic('claude-3-5-sonnet-20241022')`;
238
250
  } else if (llmProvider === "groq") {
239
- providerImport = `import { groq } from '@ai-sdk/groq';`;
251
+ providerImport = `import { groq } from '${getAISDKPackage(llmProvider)}';`;
240
252
  modelItem = `groq('llama3-groq-70b-8192-tool-use-preview')`;
241
253
  }
242
254
  const instructions = `
@@ -277,10 +289,10 @@ async function writeToolSample(destPath) {
277
289
  const fileService = new FileService();
278
290
  await fileService.copyStarterFile("tools.ts", destPath);
279
291
  }
280
- async function writeCodeSampleForComponents(llmprovider, component, destPath, components) {
292
+ async function writeCodeSampleForComponents(llmprovider, component, destPath, importComponents) {
281
293
  switch (component) {
282
294
  case "agents":
283
- return writeAgentSample(llmprovider, destPath, components.includes("tools"));
295
+ return writeAgentSample(llmprovider, destPath, importComponents.includes("tools"));
284
296
  case "tools":
285
297
  return writeToolSample(destPath);
286
298
  case "workflows":
@@ -400,10 +412,10 @@ var createMastraDir = async (directory) => {
400
412
  return { ok: true, dirPath };
401
413
  }
402
414
  };
403
- var writeCodeSample = async (dirPath, component, llmProvider, components) => {
415
+ var writeCodeSample = async (dirPath, component, llmProvider, importComponents) => {
404
416
  const destPath = dirPath + `/${component}/index.ts`;
405
417
  try {
406
- await writeCodeSampleForComponents(llmProvider, component, destPath, components);
418
+ await writeCodeSampleForComponents(llmProvider, component, destPath, importComponents);
407
419
  } catch (err) {
408
420
  throw err;
409
421
  }
@@ -491,6 +503,7 @@ var checkPkgJson = async () => {
491
503
 
492
504
  // src/commands/init/init.ts
493
505
  var s = p.spinner();
506
+ var exec2 = util.promisify(child_process.exec);
494
507
  var init = async ({
495
508
  directory,
496
509
  addExample = false,
@@ -518,12 +531,14 @@ var init = async ({
518
531
  ]);
519
532
  if (addExample) {
520
533
  await Promise.all([
521
- components.map(
534
+ ...components.map(
522
535
  (component) => writeCodeSample(dirPath, component, llmProvider, components)
523
536
  )
524
537
  ]);
525
538
  }
526
539
  const key = await getAPIKey(llmProvider || "openai");
540
+ const aiSdkPackage = getAISDKPackage(llmProvider);
541
+ await exec2(`npm i ${aiSdkPackage}`);
527
542
  s.stop();
528
543
  if (!llmApiKey) {
529
544
  p.note(`
@@ -544,7 +559,7 @@ var init = async ({
544
559
  return { success: false };
545
560
  }
546
561
  };
547
- var exec2 = util.promisify(child_process.exec);
562
+ var exec3 = util.promisify(child_process.exec);
548
563
  var createMastraProject = async () => {
549
564
  p.intro(color2.inverse("Mastra Create"));
550
565
  const projectName = await p.text({
@@ -571,17 +586,17 @@ var createMastraProject = async () => {
571
586
  }
572
587
  process.chdir(projectName);
573
588
  s2.message("Creating project");
574
- await exec2(`npm init -y`);
575
- await exec2(`npm pkg set type="module"`);
589
+ await exec3(`npm init -y`);
590
+ await exec3(`npm pkg set type="module"`);
576
591
  const depsService = new DepsService();
577
592
  await depsService.addScriptsToPackageJson({
578
593
  dev: "mastra dev"
579
594
  });
580
595
  s2.stop("Project created");
581
596
  s2.start("Installing npm dependencies");
582
- await exec2(`npm i zod`);
583
- await exec2(`npm i typescript tsx @types/node --save-dev`);
584
- await exec2(`echo '{
597
+ await exec3(`npm i zod`);
598
+ await exec3(`npm i typescript tsx @types/node --save-dev`);
599
+ await exec3(`echo '{
585
600
  "compilerOptions": {
586
601
  "target": "ES2022",
587
602
  "module": "ES2022",
@@ -603,18 +618,19 @@ var createMastraProject = async () => {
603
618
  }' > tsconfig.json`);
604
619
  s2.stop("NPM dependencies installed");
605
620
  s2.start("Installing mastra");
606
- await exec2(`npm i -D mastra`);
621
+ await exec3(`npm i -D mastra`);
607
622
  s2.stop("mastra installed");
608
623
  s2.start("Installing @mastra/core");
609
- await exec2(`npm i @mastra/core@alpha`);
624
+ await exec3(`npm i @mastra/core@alpha`);
610
625
  s2.stop("@mastra/core installed");
611
626
  s2.start("Adding .gitignore");
612
- await exec2(`echo output.txt >> .gitignore`);
613
- await exec2(`echo node_modules >> .gitignore`);
614
- await exec2(`echo dist >> .gitignore`);
615
- await exec2(`echo .mastra >> .gitignore`);
616
- await exec2(`echo .env.development >> .gitignore`);
617
- await exec2(`echo .env >> .gitignore`);
627
+ await exec3(`echo output.txt >> .gitignore`);
628
+ await exec3(`echo node_modules >> .gitignore`);
629
+ await exec3(`echo dist >> .gitignore`);
630
+ await exec3(`echo .mastra >> .gitignore`);
631
+ await exec3(`echo .env.development >> .gitignore`);
632
+ await exec3(`echo .env >> .gitignore`);
633
+ await exec3(`echo *.db >> .gitignore`);
618
634
  s2.stop(".gitignore added");
619
635
  p.outro("Project created successfully");
620
636
  console.log("");
@@ -1 +1 @@
1
- export { create } from '../../chunk-6I2TYSHJ.js';
1
+ export { create } from '../../chunk-UU6XEV7T.js';
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #! /usr/bin/env node
2
2
  import { PosthogAnalytics } from './chunk-K5HPNH5H.js';
3
3
  export { PosthogAnalytics } from './chunk-K5HPNH5H.js';
4
- import { DepsService, create, checkPkgJson, checkAndInstallCoreDeps, interactivePrompt, init, FileService, logger } from './chunk-6I2TYSHJ.js';
5
- export { create } from './chunk-6I2TYSHJ.js';
4
+ import { DepsService, create, checkPkgJson, checkAndInstallCoreDeps, interactivePrompt, init, FileService, logger } from './chunk-UU6XEV7T.js';
5
+ export { create } from './chunk-UU6XEV7T.js';
6
6
  import { Command } from 'commander';
7
7
  import 'picocolors';
8
8
  import { join, dirname } from 'node:path';
@@ -13,9 +13,7 @@ import { readFileSync } from 'node:fs';
13
13
  import { fileURLToPath as fileURLToPath$1 } from 'node:url';
14
14
  import { getDeployer, FileService as FileService$2 } from '@mastra/deployer';
15
15
  import { join as join$1 } from 'path';
16
- import 'child_process';
17
16
  import { execa } from 'execa';
18
- import { writeFileSync } from 'fs';
19
17
  import { fileURLToPath } from 'url';
20
18
  import { MastraBundler } from '@mastra/core/bundler';
21
19
  import 'dotenv';
@@ -58,8 +56,8 @@ async function build({ dir }) {
58
56
  const mastraDir = dir ?? process.cwd();
59
57
  const outputDirectory = join(mastraDir, ".mastra");
60
58
  const deployer = new BuildBundler();
61
- const fs2 = new FileService();
62
- const mastraEntryFile = fs2.getFirstExistingFile([
59
+ const fs = new FileService();
60
+ const mastraEntryFile = fs.getFirstExistingFile([
63
61
  join(mastraDir, "src", "mastra", "index.ts"),
64
62
  join(mastraDir, "src", "mastra", "index.js")
65
63
  ]);
@@ -71,8 +69,8 @@ async function deploy({ dir }) {
71
69
  let mastraDir = dir || join$1(process.cwd(), "src/mastra");
72
70
  try {
73
71
  const outputDirectory = join$1(process.cwd(), ".mastra");
74
- const fs2 = new FileService();
75
- const mastraEntryFile = fs2.getFirstExistingFile([join$1(mastraDir, "index.ts"), join$1(mastraDir, "index.js")]);
72
+ const fs = new FileService();
73
+ const mastraEntryFile = fs.getFirstExistingFile([join$1(mastraDir, "index.ts"), join$1(mastraDir, "index.js")]);
76
74
  const deployer = await getDeployer(mastraEntryFile, outputDirectory);
77
75
  if (!deployer) {
78
76
  logger.warn("No deployer found.");
@@ -137,15 +135,25 @@ var DevBundler = class extends MastraBundler {
137
135
  join(this.mastraDir, "index.ts"),
138
136
  join(this.mastraDir, "index.js")
139
137
  ]);
138
+ const envFiles = await this.getEnvFiles();
140
139
  const inputOptions = await getWatcherInputOptions(entryFile, "node");
141
140
  const watcher = await createWatcher(
142
141
  {
143
142
  ...inputOptions,
143
+ plugins: [
144
+ // @ts-ignore - types are good
145
+ ...inputOptions.plugins,
146
+ {
147
+ name: "env-watcher",
148
+ buildStart() {
149
+ for (const envFile of envFiles) {
150
+ this.addWatchFile(envFile);
151
+ }
152
+ }
153
+ }
154
+ ],
144
155
  input: {
145
156
  index: join(__dirname, "templates", "dev.entry.js")
146
- },
147
- watch: {
148
- include: await this.getEnvFiles()
149
157
  }
150
158
  },
151
159
  {
@@ -250,7 +258,6 @@ async function dev({ port, dir, root }) {
250
258
  const bundler = new DevBundler(mastraDir);
251
259
  const env = await bundler.loadEnvVars();
252
260
  await bundler.prepare(dotMastraPath);
253
- writeFileSync(join$1(dotMastraPath, "evals.json"), ``);
254
261
  const watcher = await bundler.watch(dotMastraPath);
255
262
  await startServer(dotMastraPath, port, env);
256
263
  watcher.on("event", (event) => {
@@ -60,7 +60,7 @@ const fetchWeather = new Step({
60
60
  city: z.string().describe('The city to get the weather for'),
61
61
  }),
62
62
  execute: async ({ context }) => {
63
- const triggerData = context.machineContext?.getStepPayload<{ city: string }>('trigger');
63
+ const triggerData = context?.getStepPayload<{ city: string }>('trigger');
64
64
 
65
65
  if (!triggerData) {
66
66
  throw new Error('Trigger data not found');
@@ -119,7 +119,7 @@ const planActivities = new Step({
119
119
  description: 'Suggests activities based on weather conditions',
120
120
  inputSchema: forecastSchema,
121
121
  execute: async ({ context, mastra }) => {
122
- const forecast = context.machineContext?.getStepPayload<z.infer<typeof forecastSchema>>('fetch-weather');
122
+ const forecast = context?.getStepPayload<z.infer<typeof forecastSchema>>('fetch-weather');
123
123
 
124
124
  if (!forecast) {
125
125
  throw new Error('Forecast data not found');
@@ -4,13 +4,12 @@ import { mastra } from '#mastra';
4
4
  import { createNodeServer } from '#server';
5
5
  import { evaluate } from '@mastra/core/eval';
6
6
  import { AvailableHooks, registerHook } from '@mastra/core/hooks';
7
+ import { MastraStorage } from '@mastra/core/storage';
7
8
 
8
9
  // @ts-ignore
9
- const evalStore = [];
10
- // @ts-ignore
11
- await createNodeServer(mastra, { playground: true, swaggerUI: true, evalStore });
10
+ await createNodeServer(mastra, { playground: true, swaggerUI: true });
12
11
 
13
- registerHook(AvailableHooks.ON_GENERATION, ({ input, output, metric, runId, agentName }) => {
12
+ registerHook(AvailableHooks.ON_GENERATION, ({ input, output, metric, runId, agentName, instructions }) => {
14
13
  evaluate({
15
14
  agentName,
16
15
  input,
@@ -18,9 +17,21 @@ registerHook(AvailableHooks.ON_GENERATION, ({ input, output, metric, runId, agen
18
17
  output,
19
18
  runId,
20
19
  globalRunId: runId,
20
+ instructions,
21
21
  });
22
22
  });
23
23
 
24
24
  registerHook(AvailableHooks.ON_EVALUATION, async traceObject => {
25
- evalStore.push(traceObject);
25
+ if (mastra?.memory?.storage) {
26
+ await mastra.memory.storage.insert({
27
+ tableName: MastraStorage.TABLE_EVALS,
28
+ record: {
29
+ result: JSON.stringify(traceObject.result),
30
+ meta: JSON.stringify(traceObject.meta),
31
+ input: traceObject.input,
32
+ output: traceObject.output,
33
+ createdAt: new Date().toISOString(),
34
+ },
35
+ });
36
+ }
26
37
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mastra",
3
- "version": "0.2.0-alpha.152",
3
+ "version": "0.2.0-alpha.155",
4
4
  "license": "MIT",
5
5
  "description": "cli for mastra",
6
6
  "type": "module",
@@ -55,8 +55,8 @@
55
55
  "yocto-spinner": "^0.1.1",
56
56
  "zod": "^3.24.1",
57
57
  "zod-to-json-schema": "^3.24.1",
58
- "@mastra/core": "^0.2.0-alpha.95",
59
- "@mastra/deployer": "^0.1.0-alpha.44"
58
+ "@mastra/core": "^0.2.0-alpha.98",
59
+ "@mastra/deployer": "^0.1.0-alpha.47"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@ai-sdk/openai": "^1.1.9",
@@ -75,7 +75,7 @@
75
75
  },
76
76
  "scripts": {
77
77
  "build": "npm-run-all --serial build:lib copy-starter-files copy-templates build:playground",
78
- "build:lib": "tsup-node --config tsup.config.js",
78
+ "build:lib": "tsup --config tsup.config.js",
79
79
  "build:watch": "pnpm run build:lib --watch --onSuccess \"pnpm run copy-starter-files && pnpm run copy-templates\"",
80
80
  "copy-starter-files": "cpy \"src/starter-files/**/*\" \"dist/starter-files\"",
81
81
  "copy-templates": "cpy \"src/templates/**/*\" \"dist/templates/\"",