mastra 0.5.0 → 0.6.0-alpha.2

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.
@@ -382,6 +382,7 @@ async function writeAgentSample(llmProvider, destPath, addExampleTool) {
382
382
  const content = `
383
383
  ${providerImport}
384
384
  import { Agent } from '@mastra/core/agent';
385
+ import { Memory } from '@mastra/memory';
385
386
  ${addExampleTool ? `import { weatherTool } from '../tools';` : ""}
386
387
 
387
388
  export const weatherAgent = new Agent({
@@ -389,6 +390,15 @@ export const weatherAgent = new Agent({
389
390
  instructions: \`${instructions}\`,
390
391
  model: ${modelItem},
391
392
  ${addExampleTool ? "tools: { weatherTool }," : ""}
393
+ memory: new Memory({
394
+ options: {
395
+ lastMessages: 10,
396
+ semanticRecall: false,
397
+ threads: {
398
+ generateTitle: false
399
+ }
400
+ }
401
+ })
392
402
  });
393
403
  `;
394
404
  const formattedContent = await prettier.format(content, {
@@ -643,11 +653,16 @@ export const mastra = new Mastra()
643
653
  `
644
654
  import { Mastra } from '@mastra/core/mastra';
645
655
  import { createLogger } from '@mastra/core/logger';
656
+ import { LibSQLStore } from '@mastra/libsql';
646
657
  ${addWorkflow ? `import { weatherWorkflow } from './workflows';` : ""}
647
658
  ${addAgent ? `import { weatherAgent } from './agents';` : ""}
648
659
 
649
660
  export const mastra = new Mastra({
650
661
  ${filteredExports.join("\n ")}
662
+ storage: new LibSQLStore({
663
+ // stores telemetry, evals, ... into memory storage, if it needs to persist, change to file:../mastra.db
664
+ url: ":memory:",
665
+ }),
651
666
  logger: createLogger({
652
667
  name: 'Mastra',
653
668
  level: 'info',
@@ -659,18 +674,24 @@ export const mastra = new Mastra({
659
674
  throw err;
660
675
  }
661
676
  };
662
- var checkAndInstallCoreDeps = async () => {
677
+ var checkAndInstallCoreDeps = async (addExample) => {
663
678
  const depsService = new DepsService();
664
- const depCheck = await depsService.checkDependencies(["@mastra/core"]);
679
+ let depCheck = await depsService.checkDependencies(["@mastra/core"]);
665
680
  if (depCheck !== "ok") {
666
- await installCoreDeps();
681
+ await installCoreDeps("@mastra/core");
682
+ }
683
+ if (addExample) {
684
+ depCheck = await depsService.checkDependencies(["@mastra/libsql"]);
685
+ if (depCheck !== "ok") {
686
+ await installCoreDeps("@mastra/libsql");
687
+ }
667
688
  }
668
689
  };
669
690
  var spinner = yoctoSpinner({ text: "Installing Mastra core dependencies\n" });
670
- async function installCoreDeps() {
691
+ async function installCoreDeps(pkg) {
671
692
  try {
672
693
  const confirm2 = await p.confirm({
673
- message: "You do not have the @mastra/core package installed. Would you like to install it?",
694
+ message: `You do not have the ${pkg} package installed. Would you like to install it?`,
674
695
  initialValue: false
675
696
  });
676
697
  if (p.isCancel(confirm2)) {
@@ -683,7 +704,7 @@ async function installCoreDeps() {
683
704
  }
684
705
  spinner.start();
685
706
  const depsService = new DepsService();
686
- await depsService.installPackages(["@mastra/core@latest"]);
707
+ await depsService.installPackages([`${pkg}@latest`]);
687
708
  spinner.success("@mastra/core installed successfully");
688
709
  } catch (err) {
689
710
  console.error(err);
@@ -894,6 +915,15 @@ var init = async ({
894
915
  (component) => writeCodeSample(dirPath, component, llmProvider, components)
895
916
  )
896
917
  ]);
918
+ const depService = new DepsService();
919
+ const needsLibsql = await depService.checkDependencies(["@mastra/libsql"]) !== `ok`;
920
+ if (needsLibsql) {
921
+ await depService.installPackages(["@mastra/libsql"]);
922
+ }
923
+ const needsMemory = components.includes(`agents`) && await depService.checkDependencies(["@mastra/memory"]) !== `ok`;
924
+ if (needsMemory) {
925
+ await depService.installPackages(["@mastra/memory"]);
926
+ }
897
927
  }
898
928
  const key = await getAPIKey(llmProvider || "openai");
899
929
  const aiSdkPackage = getAISDKPackage(llmProvider);
@@ -1033,9 +1063,11 @@ var createMastraProject = async ({
1033
1063
  const versionTag = createVersionTag ? `@${createVersionTag}` : "@latest";
1034
1064
  await installMastraDependency(pm, "mastra", versionTag, true, timeout);
1035
1065
  s2.stop("mastra installed");
1036
- s2.start("Installing @mastra/core");
1066
+ s2.start("Installing dependencies");
1037
1067
  await installMastraDependency(pm, "@mastra/core", versionTag, false, timeout);
1038
- s2.stop("@mastra/core installed");
1068
+ await installMastraDependency(pm, "@mastra/libsql", versionTag, false, timeout);
1069
+ await installMastraDependency(pm, "@mastra/memory", versionTag, false, timeout);
1070
+ s2.stop("Dependencies installed");
1039
1071
  s2.start("Adding .gitignore");
1040
1072
  await exec3(`echo output.txt >> .gitignore`);
1041
1073
  await exec3(`echo node_modules >> .gitignore`);
@@ -1058,8 +1090,8 @@ var create = async (args2) => {
1058
1090
  createVersionTag: args2?.createVersionTag,
1059
1091
  timeout: args2?.timeout
1060
1092
  });
1061
- const directory = "/src";
1062
- if (!args2.components || !args2.llmProvider || !args2.addExample) {
1093
+ const directory = args2.directory || "src/";
1094
+ if (args2.components === void 0 || args2.llmProvider === void 0 || args2.addExample === void 0) {
1063
1095
  const result = await interactivePrompt();
1064
1096
  await init({
1065
1097
  ...result,
@@ -8,6 +8,7 @@ declare const create: (args: {
8
8
  llmApiKey?: string;
9
9
  createVersionTag?: string;
10
10
  timeout?: number;
11
+ directory?: string;
11
12
  }) => Promise<void>;
12
13
 
13
14
  export { create };
@@ -1 +1 @@
1
- export { create } from '../../chunk-BY3FZLXQ.js';
1
+ export { create } from '../../chunk-A5NF2IHE.js';
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
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-BY3FZLXQ.js';
5
- export { create } from './chunk-BY3FZLXQ.js';
4
+ import { DepsService, create, checkPkgJson, checkAndInstallCoreDeps, interactivePrompt, init, logger, convertToViteEnvVar, FileService as FileService$1 } from './chunk-A5NF2IHE.js';
5
+ export { create } from './chunk-A5NF2IHE.js';
6
6
  import { Command } from 'commander';
7
7
  import { config } from 'dotenv';
8
8
  import { join as join$1, dirname } from 'node:path';
@@ -94,7 +94,7 @@ var BuildBundler = class extends Bundler {
94
94
  }
95
95
  };
96
96
  async function build({ dir, tools }) {
97
- const mastraDir = dir ?? join$1(process.cwd(), "src", "mastra");
97
+ const mastraDir = dir ? dir.startsWith("/") ? dir : join$1(process.cwd(), dir) : join$1(process.cwd(), "src", "mastra");
98
98
  const outputDirectory = join$1(process.cwd(), ".mastra");
99
99
  const defaultToolsPath = join$1(mastraDir, "tools");
100
100
  const discoveredTools = [defaultToolsPath, ...tools ?? []];
@@ -213,11 +213,8 @@ var DevBundler = class extends Bundler {
213
213
  {
214
214
  name: "tools-watcher",
215
215
  async buildEnd() {
216
- const toolsInputOptions2 = Array.from(Object.keys(inputOptions.input || {})).filter((key) => key.startsWith("tools/")).map((key) => `./${key}.mjs`);
217
- await writeFile(
218
- join$1(outputDir, "tools.mjs"),
219
- `export const tools = ${JSON.stringify(toolsInputOptions2)};`
220
- );
216
+ const toolsInputPaths = Array.from(Object.keys(toolsInputOptions || {})).filter((key) => key.startsWith("tools/")).map((key) => `./${key}.mjs`);
217
+ await writeFile(join$1(outputDir, "tools.mjs"), `export const tools = ${JSON.stringify(toolsInputPaths)};`);
221
218
  }
222
219
  }
223
220
  ],
@@ -335,7 +332,7 @@ async function dev({
335
332
  tools
336
333
  }) {
337
334
  const rootDir = root || process.cwd();
338
- const mastraDir = join(rootDir, dir || "src/mastra");
335
+ const mastraDir = dir ? dir.startsWith("/") ? dir : join(process.cwd(), dir) : join(process.cwd(), "src", "mastra");
339
336
  const dotMastraPath = join(rootDir, ".mastra");
340
337
  const defaultToolsPath = join(mastraDir, "tools");
341
338
  const discoveredTools = [defaultToolsPath, ...tools || []];
@@ -387,13 +384,14 @@ program.version(`${version}`, "-v, --version").description(`Mastra CLI ${version
387
384
  } catch {
388
385
  }
389
386
  });
390
- program.command("create").description("Create a new Mastra project").option("--default", "Quick start with defaults(src, OpenAI, no examples)").option("-c, --components <components>", "Comma-separated list of components (agents, tools, workflows)").option("-l, --llm <model-provider>", "Default model provider (openai, anthropic, groq, google, or cerebras))").option("-k, --llm-api-key <api-key>", "API key for the model provider").option("-e, --example", "Include example code").option("-t, --timeout [timeout]", "Configurable timeout for package installation, defaults to 60000 ms").option(
387
+ program.command("create [project-name]").description("Create a new Mastra project").option("--default", "Quick start with defaults(src, OpenAI, no examples)").option("-c, --components <components>", "Comma-separated list of components (agents, tools, workflows)").option("-l, --llm <model-provider>", "Default model provider (openai, anthropic, groq, google, or cerebras))").option("-k, --llm-api-key <api-key>", "API key for the model provider").option("-e, --example", "Include example code").option("-n, --no-example", "Do not include example code").option("-t, --timeout [timeout]", "Configurable timeout for package installation, defaults to 60000 ms").option("-d, --dir <directory>", "Target directory for Mastra source code (default: src/)").option(
391
388
  "-p, --project-name <string>",
392
389
  "Project name that will be used in package.json and as the project directory name."
393
- ).action(async (args) => {
390
+ ).action(async (projectNameArg, args) => {
391
+ const projectName = projectNameArg || args.projectName;
394
392
  await analytics.trackCommandExecution({
395
393
  command: "create",
396
- args,
394
+ args: { ...args, projectName },
397
395
  execution: async () => {
398
396
  const timeout = args?.timeout ? args?.timeout === true ? 6e4 : parseInt(args?.timeout, 10) : void 0;
399
397
  if (args.default) {
@@ -411,19 +409,20 @@ program.command("create").description("Create a new Mastra project").option("--d
411
409
  addExample: args.example,
412
410
  llmApiKey: args["llm-api-key"],
413
411
  timeout,
414
- projectName: args.projectName
412
+ projectName,
413
+ directory: args.dir
415
414
  });
416
415
  },
417
416
  origin
418
417
  });
419
418
  });
420
- program.command("init").description("Initialize Mastra in your project").option("--default", "Quick start with defaults(src, OpenAI, no examples)").option("-d, --dir <directory>", "Directory for Mastra files to (defaults to src/)").option("-c, --components <components>", "Comma-separated list of components (agents, tools, workflows)").option("-l, --llm <model-provider>", "Default model provider (openai, anthropic, groq, google or cerebras))").option("-k, --llm-api-key <api-key>", "API key for the model provider").option("-e, --example", "Include example code").action(async (args) => {
419
+ program.command("init").description("Initialize Mastra in your project").option("--default", "Quick start with defaults(src, OpenAI, no examples)").option("-d, --dir <directory>", "Directory for Mastra files to (defaults to src/)").option("-c, --components <components>", "Comma-separated list of components (agents, tools, workflows)").option("-l, --llm <model-provider>", "Default model provider (openai, anthropic, groq, google or cerebras))").option("-k, --llm-api-key <api-key>", "API key for the model provider").option("-e, --example", "Include example code").option("-n, --no-example", "Do not include example code").action(async (args) => {
421
420
  await analytics.trackCommandExecution({
422
421
  command: "init",
423
422
  args,
424
423
  execution: async () => {
425
424
  await checkPkgJson();
426
- await checkAndInstallCoreDeps();
425
+ await checkAndInstallCoreDeps(args?.example || args?.default);
427
426
  if (!Object.keys(args).length) {
428
427
  const result = await interactivePrompt();
429
428
  await init({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mastra",
3
- "version": "0.5.0",
3
+ "version": "0.6.0-alpha.2",
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.0",
58
- "@mastra/deployer": "^0.3.0"
57
+ "@mastra/core": "^0.9.1-alpha.2",
58
+ "@mastra/deployer": "^0.3.1-alpha.2"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@microsoft/api-extractor": "^7.52.1",
@@ -73,8 +73,8 @@
73
73
  "typescript": "^5.8.2",
74
74
  "vitest": "^3.0.9",
75
75
  "@internal/lint": "0.0.2",
76
- "@mastra/client-js": "0.1.18",
77
- "@mastra/playground-ui": "5.0.0"
76
+ "@mastra/client-js": "0.1.19-alpha.2",
77
+ "@mastra/playground-ui": "5.0.1-alpha.2"
78
78
  },
79
79
  "scripts": {
80
80
  "build": "npm-run-all --serial build:lib copy-starter-files copy-templates build:playground",