mastra 0.2.0-alpha.151 → 0.2.0-alpha.153

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,18 @@ 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`);
618
633
  s2.stop(".gitignore added");
619
634
  p.outro("Project created successfully");
620
635
  console.log("");
@@ -1 +1 @@
1
- export { create } from '../../chunk-6I2TYSHJ.js';
1
+ export { create } from '../../chunk-VQREOIU7.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-VQREOIU7.js';
5
+ export { create } from './chunk-VQREOIU7.js';
6
6
  import { Command } from 'commander';
7
7
  import 'picocolors';
8
8
  import { join, dirname } from 'node:path';
@@ -137,15 +137,25 @@ var DevBundler = class extends MastraBundler {
137
137
  join(this.mastraDir, "index.ts"),
138
138
  join(this.mastraDir, "index.js")
139
139
  ]);
140
+ const envFiles = await this.getEnvFiles();
140
141
  const inputOptions = await getWatcherInputOptions(entryFile, "node");
141
142
  const watcher = await createWatcher(
142
143
  {
143
144
  ...inputOptions,
145
+ plugins: [
146
+ // @ts-ignore - types are good
147
+ ...inputOptions.plugins,
148
+ {
149
+ name: "env-watcher",
150
+ buildStart() {
151
+ for (const envFile of envFiles) {
152
+ this.addWatchFile(envFile);
153
+ }
154
+ }
155
+ }
156
+ ],
144
157
  input: {
145
158
  index: join(__dirname, "templates", "dev.entry.js")
146
- },
147
- watch: {
148
- include: await this.getEnvFiles()
149
159
  }
150
160
  },
151
161
  {
@@ -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');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mastra",
3
- "version": "0.2.0-alpha.151",
3
+ "version": "0.2.0-alpha.153",
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.94",
59
- "@mastra/deployer": "^0.1.0-alpha.43"
58
+ "@mastra/core": "^0.2.0-alpha.96",
59
+ "@mastra/deployer": "^0.1.0-alpha.45"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@ai-sdk/openai": "^1.1.9",