mastra 0.6.1-alpha.4 → 0.6.1-alpha.6

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/README.md CHANGED
@@ -90,17 +90,25 @@ const mastra = new Mastra({
90
90
  });
91
91
  ```
92
92
 
93
- ### Deploy
93
+ ### Lint
94
94
 
95
- `mastra deploy`
95
+ `mastra lint`
96
96
 
97
- This command deploys the mastra project to a serverless platform like Vercel or Cloudflare Workers.
97
+ Validates your Mastra project structure and code.
98
98
 
99
- The deploy command does the following:
99
+ Options:
100
+
101
+ ```bash
102
+ --root Path to your root folder
103
+ --tools Comma-separated list of paths to tool files to include
104
+ ```
100
105
 
101
- - Initializes the mastra project
102
- - Builds the project
103
- - Deploys the built project to the platform
106
+ Example usage:
107
+
108
+ ```bash
109
+ # Lint default directory
110
+ mastra lint
111
+ ```
104
112
 
105
113
  # Telemetry
106
114
 
@@ -404,6 +404,7 @@ async function writeAgentSample(llmProvider, destPath, addExampleTool) {
404
404
  ${providerImport}
405
405
  import { Agent } from '@mastra/core/agent';
406
406
  import { Memory } from '@mastra/memory';
407
+ import { LibSQLStore } from '@mastra/libsql';
407
408
  ${addExampleTool ? `import { weatherTool } from '../tools';` : ""}
408
409
 
409
410
  export const weatherAgent = new Agent({
@@ -412,6 +413,9 @@ export const weatherAgent = new Agent({
412
413
  model: ${modelItem},
413
414
  ${addExampleTool ? "tools: { weatherTool }," : ""}
414
415
  memory: new Memory({
416
+ storage: new LibSQLStore({
417
+ url: "file:../mastra.db", // path is relative to the .mastra/output directory
418
+ }),
415
419
  options: {
416
420
  lastMessages: 10,
417
421
  semanticRecall: false,
@@ -1 +1 @@
1
- export { create } from '../../chunk-YW5YUAZU.js';
1
+ export { create } from '../../chunk-6PMRPTZU.js';
package/dist/index.js CHANGED
@@ -1,20 +1,21 @@
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, convertToViteEnvVar, FileService as FileService$1 } from './chunk-YW5YUAZU.js';
5
- export { create } from './chunk-YW5YUAZU.js';
4
+ import { DepsService, create, checkPkgJson, checkAndInstallCoreDeps, interactivePrompt, init, logger, FileService, convertToViteEnvVar } from './chunk-6PMRPTZU.js';
5
+ export { create } from './chunk-6PMRPTZU.js';
6
6
  import { Command } from 'commander';
7
7
  import { config } from 'dotenv';
8
8
  import { join as join$1, dirname } from 'node:path';
9
- import { getServerOptions, getWatcherInputOptions, writeTelemetryConfig, createWatcher, FileService as FileService$2 } from '@mastra/deployer/build';
9
+ import { getServerOptions, FileService as FileService$2, getWatcherInputOptions, writeTelemetryConfig, createWatcher } from '@mastra/deployer/build';
10
10
  import { Bundler } from '@mastra/deployer/bundler';
11
- import { FileService, getDeployer } from '@mastra/deployer';
11
+ import { getDeployer, FileService as FileService$1 } from '@mastra/deployer';
12
12
  import { join } from 'path';
13
13
  import { isWebContainer } from '@webcontainer/env';
14
14
  import { execa } from 'execa';
15
15
  import { writeFile } from 'node:fs/promises';
16
16
  import { fileURLToPath } from 'node:url';
17
17
  import * as fsExtra from 'fs-extra';
18
+ import { readFileSync } from 'fs';
18
19
 
19
20
  var BuildBundler = class extends Bundler {
20
21
  constructor() {
@@ -92,14 +93,18 @@ var BuildBundler = class extends Bundler {
92
93
  });
93
94
  `;
94
95
  }
96
+ async lint(entryFile, outputDirectory, toolsPaths) {
97
+ await super.lint(entryFile, outputDirectory, toolsPaths);
98
+ }
95
99
  };
96
- async function build({ dir, tools }) {
97
- const mastraDir = dir ? dir.startsWith("/") ? dir : join$1(process.cwd(), dir) : join$1(process.cwd(), "src", "mastra");
98
- const outputDirectory = join$1(process.cwd(), ".mastra");
100
+ async function build({ dir: dir2, tools, root }) {
101
+ const rootDir = root || process.cwd();
102
+ const mastraDir = dir2 ? dir2.startsWith("/") ? dir2 : join$1(rootDir, dir2) : join$1(rootDir, "src", "mastra");
103
+ const outputDirectory = join$1(rootDir, ".mastra");
99
104
  const defaultToolsPath = join$1(mastraDir, "tools");
100
105
  const discoveredTools = [defaultToolsPath, ...tools ?? []];
101
106
  try {
102
- const fs = new FileService$1();
107
+ const fs = new FileService();
103
108
  const mastraEntryFile = fs.getFirstExistingFile([join$1(mastraDir, "index.ts"), join$1(mastraDir, "index.js")]);
104
109
  const platformDeployer = await getDeployer(mastraEntryFile, outputDirectory);
105
110
  if (!platformDeployer) {
@@ -122,11 +127,11 @@ async function build({ dir, tools }) {
122
127
  }
123
128
  }
124
129
  }
125
- async function deploy({ dir }) {
126
- let mastraDir = dir || join(process.cwd(), "src/mastra");
130
+ async function deploy({ dir: dir2 }) {
131
+ let mastraDir = dir2 || join(process.cwd(), "src/mastra");
127
132
  try {
128
133
  const outputDirectory = join(process.cwd(), ".mastra");
129
- const fs = new FileService$1();
134
+ const fs = new FileService();
130
135
  const mastraEntryFile = fs.getFirstExistingFile([join(mastraDir, "index.ts"), join(mastraDir, "index.js")]);
131
136
  const deployer = await getDeployer(mastraEntryFile, outputDirectory);
132
137
  if (!deployer) {
@@ -160,7 +165,7 @@ var DevBundler = class extends Bundler {
160
165
  getEnvFiles() {
161
166
  const possibleFiles = [".env.development", ".env.local", ".env"];
162
167
  try {
163
- const fileService = new FileService();
168
+ const fileService = new FileService$1();
164
169
  const envFile = fileService.getFirstExistingFile(possibleFiles);
165
170
  return Promise.resolve([envFile]);
166
171
  } catch {
@@ -331,16 +336,16 @@ async function rebundleAndRestart(dotMastraPath, port, bundler) {
331
336
  }
332
337
  async function dev({
333
338
  port,
334
- dir,
339
+ dir: dir2,
335
340
  root,
336
341
  tools
337
342
  }) {
338
343
  const rootDir = root || process.cwd();
339
- const mastraDir = dir ? dir.startsWith("/") ? dir : join(process.cwd(), dir) : join(process.cwd(), "src", "mastra");
344
+ const mastraDir = dir2 ? dir2.startsWith("/") ? dir2 : join(process.cwd(), dir2) : join(process.cwd(), "src", "mastra");
340
345
  const dotMastraPath = join(rootDir, ".mastra");
341
346
  const defaultToolsPath = join(mastraDir, "tools");
342
347
  const discoveredTools = [defaultToolsPath, ...tools || []];
343
- const fileService = new FileService();
348
+ const fileService = new FileService$1();
344
349
  const entryFile = fileService.getFirstExistingFile([join(mastraDir, "index.ts"), join(mastraDir, "index.js")]);
345
350
  const bundler = new DevBundler();
346
351
  await bundler.prepare(dotMastraPath);
@@ -368,6 +373,202 @@ async function dev({
368
373
  });
369
374
  }
370
375
 
376
+ // src/commands/lint/rules/mastraCoreRule.ts
377
+ var mastraCoreRule = {
378
+ name: "mastra-core",
379
+ description: "Checks if @mastra/core is installed",
380
+ async run(context) {
381
+ const hasCore = context.mastraPackages.some((pkg) => pkg.name === "@mastra/core");
382
+ if (!hasCore) {
383
+ logger.error("@mastra/core is not installed. This package is required for Mastra to work properly.");
384
+ return false;
385
+ }
386
+ return true;
387
+ }
388
+ };
389
+
390
+ // src/commands/lint/rules/mastraDepsCompatibilityRule.ts
391
+ var mastraDepsCompatibilityRule = {
392
+ name: "mastra-deps-compatibility",
393
+ description: "Checks if Mastra package versions are compatible",
394
+ async run(context) {
395
+ if (context.mastraPackages.length === 0) {
396
+ logger.warn("No Mastra packages found in package.json");
397
+ return true;
398
+ }
399
+ const hasAlpha = context.mastraPackages.some((pkg) => pkg.isAlpha);
400
+ const hasNonAlpha = context.mastraPackages.some((pkg) => !pkg.isAlpha);
401
+ if (hasAlpha && hasNonAlpha) {
402
+ logger.error("Inconsistent Mastra package versions found:");
403
+ context.mastraPackages.forEach(({ name, version: version2 }) => {
404
+ logger.error(` ${name}: ${version2}`);
405
+ });
406
+ logger.error("All Mastra packages should be either alpha or non-alpha versions");
407
+ return false;
408
+ }
409
+ logger.info("All Mastra package versions are consistent!");
410
+ return true;
411
+ }
412
+ };
413
+ function readNextConfig(dir) {
414
+ const nextConfigPath = join(dir, "next.config.js");
415
+ try {
416
+ const nextConfigContent = readFileSync(nextConfigPath, "utf-8");
417
+ const configMatch = nextConfigContent.match(/const nextConfig = ({[\s\S]*?});/);
418
+ if (!configMatch?.[1]) {
419
+ return null;
420
+ }
421
+ const configStr = configMatch[1].replace(/\n/g, "").replace(/\s+/g, " ");
422
+ return eval(`(${configStr})`);
423
+ } catch {
424
+ return null;
425
+ }
426
+ }
427
+ function isNextJsProject(dir2) {
428
+ const nextConfigPath2 = join(dir2, "next.config.js");
429
+ try {
430
+ readFileSync(nextConfigPath2, "utf-8");
431
+ return true;
432
+ } catch {
433
+ return false;
434
+ }
435
+ }
436
+ var nextConfigRule = {
437
+ name: "next-config",
438
+ description: "Checks if Next.js config is properly configured for Mastra packages",
439
+ async run(context) {
440
+ if (!isNextJsProject(context.rootDir)) {
441
+ return true;
442
+ }
443
+ const nextConfig = readNextConfig(context.rootDir);
444
+ if (!nextConfig) {
445
+ return false;
446
+ }
447
+ const serverExternals = nextConfig.serverExternalPackages || [];
448
+ const hasMastraExternals = serverExternals.some(
449
+ (pkg) => pkg === "@mastra/*" || pkg === "@mastra/core" || pkg.startsWith("@mastra/")
450
+ );
451
+ if (!hasMastraExternals) {
452
+ logger.error("next.config.js is missing Mastra packages in serverExternalPackages");
453
+ logger.error("Please add the following to your next.config.js:");
454
+ logger.error(' serverExternalPackages: ["@mastra/*"],');
455
+ return false;
456
+ }
457
+ logger.info("Next.js config is properly configured for Mastra packages");
458
+ return true;
459
+ }
460
+ };
461
+ function readTsConfig(dir2) {
462
+ const tsConfigPath = join(dir2, "tsconfig.json");
463
+ try {
464
+ const tsConfigContent = readFileSync(tsConfigPath, "utf-8");
465
+ return JSON.parse(tsConfigContent);
466
+ } catch {
467
+ return null;
468
+ }
469
+ }
470
+ var tsConfigRule = {
471
+ name: "ts-config",
472
+ description: "Checks if TypeScript config is properly configured for Mastra packages",
473
+ async run(context) {
474
+ const tsConfig = readTsConfig(context.rootDir);
475
+ if (!tsConfig) {
476
+ logger.warn("No tsconfig.json found. This might cause issues with Mastra packages.");
477
+ return true;
478
+ }
479
+ const { module, moduleResolution } = tsConfig.compilerOptions || {};
480
+ const isValidConfig = moduleResolution === "bundler" || module === "CommonJS";
481
+ if (!isValidConfig) {
482
+ logger.error("tsconfig.json has invalid configuration");
483
+ logger.error("Please set either:");
484
+ logger.error(' "compilerOptions": {');
485
+ logger.error(' "moduleResolution": "bundler"');
486
+ logger.error(" }");
487
+ logger.error("or");
488
+ logger.error(' "compilerOptions": {');
489
+ logger.error(' "module": "CommonJS"');
490
+ logger.error(" }");
491
+ logger.error("For the recommended TypeScript configuration, see:");
492
+ logger.error("https://mastra.ai/en/docs/getting-started/installation#initialize-typescript");
493
+ return false;
494
+ }
495
+ logger.info("TypeScript config is properly configured for Mastra packages");
496
+ return true;
497
+ }
498
+ };
499
+
500
+ // src/commands/lint/rules/index.ts
501
+ var rules = [nextConfigRule, tsConfigRule, mastraCoreRule, mastraDepsCompatibilityRule];
502
+
503
+ // src/commands/lint/index.ts
504
+ function readPackageJson(dir2) {
505
+ const packageJsonPath = join(dir2, "package.json");
506
+ try {
507
+ const packageJsonContent = readFileSync(packageJsonPath, "utf-8");
508
+ return JSON.parse(packageJsonContent);
509
+ } catch (error) {
510
+ if (error instanceof Error) {
511
+ logger.error(`Failed to read package.json: ${error.message}`);
512
+ }
513
+ throw error;
514
+ }
515
+ }
516
+ function getMastraPackages(packageJson) {
517
+ const allDependencies = {
518
+ ...packageJson.dependencies,
519
+ ...packageJson.devDependencies
520
+ };
521
+ const mastraPackages = Object.entries(allDependencies).filter(
522
+ ([name]) => name.startsWith("@mastra/") || name === "mastra"
523
+ );
524
+ return mastraPackages.map(([name, version2]) => ({
525
+ name,
526
+ version: version2,
527
+ isAlpha: version2.includes("alpha")
528
+ }));
529
+ }
530
+ async function lint({ dir: dir2, root, tools }) {
531
+ try {
532
+ const rootDir = root || process.cwd();
533
+ const mastraDir = dir2 ? dir2.startsWith("/") ? dir2 : join(process.cwd(), dir2) : join(process.cwd(), "src", "mastra");
534
+ const outputDirectory = join(rootDir, ".mastra");
535
+ const defaultToolsPath = join(mastraDir, "tools");
536
+ const discoveredTools = [defaultToolsPath, ...tools ?? []];
537
+ const packageJson = readPackageJson(rootDir);
538
+ const mastraPackages = getMastraPackages(packageJson);
539
+ const context = {
540
+ rootDir,
541
+ mastraDir,
542
+ outputDirectory,
543
+ discoveredTools,
544
+ packageJson,
545
+ mastraPackages
546
+ };
547
+ const results = await Promise.all(rules.map((rule) => rule.run(context)));
548
+ const allRulesPassed = results.every((result) => result);
549
+ if (allRulesPassed) {
550
+ const fileService = new FileService();
551
+ const mastraEntryFile = fileService.getFirstExistingFile([
552
+ join(mastraDir, "index.ts"),
553
+ join(mastraDir, "index.js")
554
+ ]);
555
+ const platformDeployer = await getDeployer(mastraEntryFile, outputDirectory);
556
+ if (!platformDeployer) {
557
+ const deployer = new BuildBundler();
558
+ await deployer.lint(mastraEntryFile, outputDirectory, discoveredTools);
559
+ } else {
560
+ await platformDeployer.lint(mastraEntryFile, outputDirectory, discoveredTools);
561
+ }
562
+ }
563
+ return allRulesPassed;
564
+ } catch (error) {
565
+ if (error instanceof Error) {
566
+ logger.error(`Lint check failed: ${error.message}`);
567
+ }
568
+ return false;
569
+ }
570
+ }
571
+
371
572
  // src/index.ts
372
573
  var depsService = new DepsService();
373
574
  var version = await depsService.getPackageVersion();
@@ -457,6 +658,16 @@ program.command("init").description("Initialize Mastra in your project").option(
457
658
  origin
458
659
  });
459
660
  });
661
+ program.command("lint").description("Lint your Mastra project").option("-d, --dir <path>", "Path to your Mastra folder").option("-r, --root <path>", "Path to your root folder").option("-t, --tools <toolsDirs>", "Comma-separated list of paths to tool files to include").action(async (args) => {
662
+ await analytics.trackCommandExecution({
663
+ command: "lint",
664
+ args,
665
+ execution: async () => {
666
+ await lint({ dir: args.dir, root: args.root, tools: args.tools ? args.tools.split(",") : [] });
667
+ },
668
+ origin
669
+ });
670
+ });
460
671
  program.command("dev").description("Start mastra server").option("-d, --dir <dir>", "Path to your mastra folder").option("-r, --root <root>", "Path to your root folder").option("-t, --tools <toolsDirs>", "Comma-separated list of paths to tool files to include").option("-p, --port <port>", "deprecated: Port number for the development server (defaults to 4111)").action((args) => {
461
672
  analytics.trackCommand({
462
673
  command: "dev",
@@ -474,14 +685,15 @@ program.command("dev").description("Start mastra server").option("-d, --dir <dir
474
685
  logger.error(err.message);
475
686
  });
476
687
  });
477
- 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) => {
688
+ program.command("build").description("Build your Mastra project").option("-d, --dir <path>", "Path to your Mastra Folder").option("-r, --root <path>", "Path to your root folder").option("-t, --tools <toolsDirs>", "Comma-separated list of paths to tool files to include").action(async (args) => {
478
689
  await analytics.trackCommandExecution({
479
690
  command: "mastra build",
480
691
  args,
481
692
  execution: async () => {
482
693
  await build({
483
- dir: args.dir,
484
- tools: args.tools ? args.tools.split(",") : []
694
+ dir: args?.dir,
695
+ root: args?.root,
696
+ tools: args?.tools ? args.tools.split(",") : []
485
697
  });
486
698
  },
487
699
  origin
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mastra",
3
- "version": "0.6.1-alpha.4",
3
+ "version": "0.6.1-alpha.6",
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.9.2-alpha.4",
58
- "@mastra/deployer": "^0.3.2-alpha.4"
57
+ "@mastra/core": "^0.9.2-alpha.6",
58
+ "@mastra/deployer": "^0.3.2-alpha.6"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@microsoft/api-extractor": "^7.52.5",
@@ -73,8 +73,8 @@
73
73
  "typescript": "^5.8.2",
74
74
  "vitest": "^3.1.2",
75
75
  "@internal/lint": "0.0.2",
76
- "@mastra/client-js": "0.1.20-alpha.4",
77
- "@mastra/playground-ui": "5.0.2-alpha.4"
76
+ "@mastra/client-js": "0.1.20-alpha.6",
77
+ "@mastra/playground-ui": "5.0.2-alpha.6"
78
78
  },
79
79
  "scripts": {
80
80
  "build": "npm-run-all --serial build:lib copy-starter-files copy-templates build:playground",