create-mastra 0.0.0-afterToolExecute-20250415041527 → 0.0.0-agui-20250501191909

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 CHANGED
@@ -1030,20 +1030,41 @@ async function writeMergedConfig(configPath) {
1030
1030
  });
1031
1031
  }
1032
1032
  var windsurfGlobalMCPConfigPath = path.join(os.homedir(), ".codeium", "windsurf", "mcp_config.json");
1033
+ var cursorGlobalMCPConfigPath = path.join(os.homedir(), ".cursor", "mcp.json");
1033
1034
  async function installMastraDocsMCPServer({
1034
1035
  editor,
1035
1036
  directory
1036
1037
  }) {
1037
- if (editor === `cursor`) await writeMergedConfig(path.join(directory, ".cursor", "mcp.json"));
1038
- const windsurfIsInstalled = await globalWindsurfMCPIsAlreadyInstalled();
1039
- if (editor === `windsurf` && !windsurfIsInstalled) await writeMergedConfig(windsurfGlobalMCPConfigPath);
1038
+ if (editor === `cursor`) {
1039
+ await writeMergedConfig(path.join(directory, ".cursor", "mcp.json"));
1040
+ }
1041
+ if (editor === `cursor-global`) {
1042
+ const alreadyInstalled = await globalMCPIsAlreadyInstalled(editor);
1043
+ if (alreadyInstalled) {
1044
+ return;
1045
+ }
1046
+ await writeMergedConfig(cursorGlobalMCPConfigPath);
1047
+ }
1048
+ if (editor === `windsurf`) {
1049
+ const alreadyInstalled = await globalMCPIsAlreadyInstalled(editor);
1050
+ if (alreadyInstalled) {
1051
+ return;
1052
+ }
1053
+ await writeMergedConfig(windsurfGlobalMCPConfigPath);
1054
+ }
1040
1055
  }
1041
- async function globalWindsurfMCPIsAlreadyInstalled() {
1042
- if (!existsSync(windsurfGlobalMCPConfigPath)) {
1056
+ async function globalMCPIsAlreadyInstalled(editor) {
1057
+ let configPath = ``;
1058
+ if (editor === "windsurf") {
1059
+ configPath = windsurfGlobalMCPConfigPath;
1060
+ } else if (editor === "cursor-global") {
1061
+ configPath = cursorGlobalMCPConfigPath;
1062
+ }
1063
+ if (!configPath || !existsSync(configPath)) {
1043
1064
  return false;
1044
1065
  }
1045
1066
  try {
1046
- const configContents = await readJSON(windsurfGlobalMCPConfigPath);
1067
+ const configContents = await readJSON(configPath);
1047
1068
  if (!configContents?.mcpServers) return false;
1048
1069
  const hasMastraMCP = Object.values(configContents.mcpServers).some(
1049
1070
  (server) => server?.args?.find((arg) => arg?.includes(`@mastra/mcp-docs-server`))
@@ -1219,6 +1240,7 @@ async function writeAgentSample(llmProvider, destPath, addExampleTool) {
1219
1240
  const content = `
1220
1241
  ${providerImport}
1221
1242
  import { Agent } from '@mastra/core/agent';
1243
+ import { Memory } from '@mastra/memory';
1222
1244
  ${addExampleTool ? `import { weatherTool } from '../tools';` : ""}
1223
1245
 
1224
1246
  export const weatherAgent = new Agent({
@@ -1226,6 +1248,15 @@ export const weatherAgent = new Agent({
1226
1248
  instructions: \`${instructions}\`,
1227
1249
  model: ${modelItem},
1228
1250
  ${addExampleTool ? "tools: { weatherTool }," : ""}
1251
+ memory: new Memory({
1252
+ options: {
1253
+ lastMessages: 10,
1254
+ semanticRecall: false,
1255
+ threads: {
1256
+ generateTitle: false
1257
+ }
1258
+ }
1259
+ })
1229
1260
  });
1230
1261
  `;
1231
1262
  const formattedContent = await prettier.format(content, {
@@ -1480,11 +1511,16 @@ export const mastra = new Mastra()
1480
1511
  `
1481
1512
  import { Mastra } from '@mastra/core/mastra';
1482
1513
  import { createLogger } from '@mastra/core/logger';
1514
+ import { LibSQLStore } from '@mastra/libsql';
1483
1515
  ${addWorkflow ? `import { weatherWorkflow } from './workflows';` : ""}
1484
1516
  ${addAgent ? `import { weatherAgent } from './agents';` : ""}
1485
1517
 
1486
1518
  export const mastra = new Mastra({
1487
1519
  ${filteredExports.join("\n ")}
1520
+ storage: new LibSQLStore({
1521
+ // stores telemetry, evals, ... into memory storage, if it needs to persist, change to file:../mastra.db
1522
+ url: ":memory:",
1523
+ }),
1488
1524
  logger: createLogger({
1489
1525
  name: 'Mastra',
1490
1526
  level: 'info',
@@ -1597,12 +1633,22 @@ var interactivePrompt = async () => {
1597
1633
  initialValue: false
1598
1634
  }),
1599
1635
  configureEditorWithDocsMCP: async () => {
1600
- const windsurfIsAlreadyInstalled = await globalWindsurfMCPIsAlreadyInstalled();
1636
+ const windsurfIsAlreadyInstalled = await globalMCPIsAlreadyInstalled(`windsurf`);
1637
+ const cursorIsAlreadyInstalled = await globalMCPIsAlreadyInstalled(`cursor`);
1601
1638
  const editor = await le({
1602
1639
  message: `Make your AI IDE into a Mastra expert? (installs Mastra docs MCP server)`,
1603
1640
  options: [
1604
1641
  { value: "skip", label: "Skip for now", hint: "default" },
1605
- { value: "cursor", label: "Cursor" },
1642
+ {
1643
+ value: "cursor",
1644
+ label: "Cursor (project only)",
1645
+ hint: cursorIsAlreadyInstalled ? `Already installed globally` : void 0
1646
+ },
1647
+ {
1648
+ value: "cursor-global",
1649
+ label: "Cursor (global, all projects)",
1650
+ hint: cursorIsAlreadyInstalled ? `Already installed` : void 0
1651
+ },
1606
1652
  {
1607
1653
  value: "windsurf",
1608
1654
  label: "Windsurf",
@@ -1623,6 +1669,18 @@ Note: you will need to go into Cursor Settings -> MCP Settings and manually enab
1623
1669
  `
1624
1670
  );
1625
1671
  }
1672
+ if (editor === `cursor-global`) {
1673
+ const confirm2 = await le({
1674
+ message: `Global install will add/update ${cursorGlobalMCPConfigPath} and make the Mastra docs MCP server available in all your Cursor projects. Continue?`,
1675
+ options: [
1676
+ { value: "yes", label: "Yes, I understand" },
1677
+ { value: "skip", label: "No, skip for now" }
1678
+ ]
1679
+ });
1680
+ if (confirm2 !== `yes`) {
1681
+ return void 0;
1682
+ }
1683
+ }
1626
1684
  if (editor === `windsurf`) {
1627
1685
  const confirm2 = await le({
1628
1686
  message: `Windsurf only supports a global MCP config (at ${windsurfGlobalMCPConfigPath}) is it ok to add/update that global config?
@@ -1684,6 +1742,15 @@ var init = async ({
1684
1742
  (component) => writeCodeSample(dirPath, component, llmProvider, components)
1685
1743
  )
1686
1744
  ]);
1745
+ const depService = new DepsService();
1746
+ const needsLibsql = await depService.checkDependencies(["@mastra/libsql"]) !== `ok`;
1747
+ if (needsLibsql) {
1748
+ await depService.installPackages(["@mastra/libsql"]);
1749
+ }
1750
+ const needsMemory = components.includes(`agents`) && await depService.checkDependencies(["@mastra/memory"]) !== `ok`;
1751
+ if (needsMemory) {
1752
+ await depService.installPackages(["@mastra/memory"]);
1753
+ }
1687
1754
  }
1688
1755
  const key = await getAPIKey(llmProvider || "openai");
1689
1756
  const aiSdkPackage = getAISDKPackage(llmProvider);
@@ -1744,6 +1811,21 @@ var execWithTimeout = async (command, timeoutMs) => {
1744
1811
  throw error;
1745
1812
  }
1746
1813
  };
1814
+ async function installMastraDependency(pm, dependency, versionTag, isDev, timeout) {
1815
+ let installCommand = getPackageManagerInstallCommand(pm);
1816
+ if (isDev) {
1817
+ installCommand = `${installCommand} --save-dev`;
1818
+ }
1819
+ try {
1820
+ await execWithTimeout(`${pm} ${installCommand} ${dependency}${versionTag}`, timeout);
1821
+ } catch (err) {
1822
+ console.log("err", err);
1823
+ if (versionTag === "@latest") {
1824
+ throw err;
1825
+ }
1826
+ await execWithTimeout(`${pm} ${installCommand} ${dependency}@latest`, timeout);
1827
+ }
1828
+ }
1747
1829
  var createMastraProject = async ({
1748
1830
  projectName: name,
1749
1831
  createVersionTag,
@@ -1780,12 +1862,13 @@ var createMastraProject = async ({
1780
1862
  await exec3(`npm pkg set type="module"`);
1781
1863
  const depsService = new DepsService();
1782
1864
  await depsService.addScriptsToPackageJson({
1783
- dev: "mastra dev"
1865
+ dev: "mastra dev",
1866
+ build: "mastra build"
1784
1867
  });
1785
1868
  s2.stop("Project created");
1786
1869
  s2.start(`Installing ${pm} dependencies`);
1787
1870
  await exec3(`${pm} ${installCommand} zod`);
1788
- await exec3(`${pm} ${installCommand} typescript tsx @types/node --save-dev`);
1871
+ await exec3(`${pm} ${installCommand} typescript @types/node --save-dev`);
1789
1872
  await exec3(`echo '{
1790
1873
  "compilerOptions": {
1791
1874
  "target": "ES2022",
@@ -1795,25 +1878,23 @@ var createMastraProject = async ({
1795
1878
  "forceConsistentCasingInFileNames": true,
1796
1879
  "strict": true,
1797
1880
  "skipLibCheck": true,
1881
+ "noEmit": true,
1798
1882
  "outDir": "dist"
1799
1883
  },
1800
1884
  "include": [
1801
1885
  "src/**/*"
1802
- ],
1803
- "exclude": [
1804
- "node_modules",
1805
- "dist",
1806
- ".mastra"
1807
1886
  ]
1808
1887
  }' > tsconfig.json`);
1809
1888
  s2.stop(`${pm} dependencies installed`);
1810
1889
  s2.start("Installing mastra");
1811
1890
  const versionTag = createVersionTag ? `@${createVersionTag}` : "@latest";
1812
- await execWithTimeout(`${pm} ${installCommand} mastra${versionTag}`, timeout);
1891
+ await installMastraDependency(pm, "mastra", versionTag, true, timeout);
1813
1892
  s2.stop("mastra installed");
1814
- s2.start("Installing @mastra/core");
1815
- await execWithTimeout(`${pm} ${installCommand} @mastra/core${versionTag}`, timeout);
1816
- s2.stop("@mastra/core installed");
1893
+ s2.start("Installing dependencies");
1894
+ await installMastraDependency(pm, "@mastra/core", versionTag, false, timeout);
1895
+ await installMastraDependency(pm, "@mastra/libsql", versionTag, false, timeout);
1896
+ await installMastraDependency(pm, "@mastra/memory", versionTag, false, timeout);
1897
+ s2.stop("Dependencies installed");
1817
1898
  s2.start("Adding .gitignore");
1818
1899
  await exec3(`echo output.txt >> .gitignore`);
1819
1900
  await exec3(`echo node_modules >> .gitignore`);
@@ -1834,8 +1915,8 @@ var create = async (args2) => {
1834
1915
  createVersionTag: args2?.createVersionTag,
1835
1916
  timeout: args2?.timeout
1836
1917
  });
1837
- const directory = "/src";
1838
- if (!args2.components || !args2.llmProvider || !args2.addExample) {
1918
+ const directory = args2.directory || "src/";
1919
+ if (args2.components === void 0 || args2.llmProvider === void 0 || args2.addExample === void 0) {
1839
1920
  const result = await interactivePrompt();
1840
1921
  await init({
1841
1922
  ...result,
@@ -1870,48 +1951,14 @@ async function getPackageVersion() {
1870
1951
  const content = await fsExtra.readJSON(pkgJsonPath);
1871
1952
  return content.version;
1872
1953
  }
1873
- async function tryReadPackageJson(paths) {
1874
- let lastError;
1875
- for (const path2 of paths) {
1876
- try {
1877
- const content = await fsExtra.readJSON(path2);
1878
- if (content.name === "create-mastra") {
1879
- return content;
1880
- }
1881
- } catch (err) {
1882
- lastError = err;
1883
- continue;
1884
- }
1885
- }
1886
- throw lastError || new Error("Could not find create-mastra package.json in any of the expected locations");
1887
- }
1888
1954
  async function getCreateVersionTag() {
1889
1955
  try {
1890
- const binPath = process.argv[1];
1891
- const binDir = dirname(binPath);
1892
- const possiblePaths = [
1893
- // Direct parent paths
1894
- path.join(binDir, "..", "package.json"),
1895
- path.join(binDir, "..", "..", "package.json"),
1896
- path.join(binDir, "..", "..", "..", "package.json"),
1897
- path.join(binDir, "..", "..", "..", "..", "package.json"),
1898
- // Standard node_modules paths
1899
- path.join(binDir, "..", "create-mastra", "package.json"),
1900
- path.join(binDir, "..", "..", "create-mastra", "package.json"),
1901
- path.join(binDir, "..", "..", "..", "create-mastra", "package.json"),
1902
- path.join(binDir, "..", "..", "..", "..", "create-mastra", "package.json"),
1903
- // pnpm specific paths (.pnpm directory)
1904
- path.join(binDir, "..", ".pnpm", "create-mastra@*", "node_modules", "create-mastra", "package.json"),
1905
- path.join(binDir, "..", "..", ".pnpm", "create-mastra@*", "node_modules", "create-mastra", "package.json"),
1906
- // pnpm dlx specific path
1907
- path.join(binDir, "..", "..", "package.json"),
1908
- path.join(binDir, "..", "..", "node_modules", "create-mastra", "package.json")
1909
- ];
1910
- const content = await tryReadPackageJson(possiblePaths);
1911
- if (content.version?.includes("-")) {
1912
- const tag = content.version.split("-")[1].split(".")[0];
1913
- return tag;
1914
- }
1956
+ const pkgPath = fileURLToPath(import.meta.resolve("create-mastra/package.json"));
1957
+ const json = await fsExtra.readJSON(pkgPath);
1958
+ const { stdout } = await execa("npm", ["dist-tag", "create-mastra"]);
1959
+ const tagLine = stdout.split("\n").find((distLine) => distLine.includes(`: ${json.version}`));
1960
+ const tag = tagLine ? tagLine.split(":")[0].trim() : "latest";
1961
+ return tag;
1915
1962
  } catch {
1916
1963
  console.error('We could not resolve the create-mastra version tag, falling back to "latest"');
1917
1964
  }
@@ -1935,7 +1982,11 @@ program.version(`${version}`, "-v, --version").description(`create-mastra ${vers
1935
1982
  } catch {
1936
1983
  }
1937
1984
  });
1938
- program.name("create-mastra").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").action(async (args) => {
1985
+ program.name("create-mastra").description("Create a new Mastra project").argument("[project-name]", "Directory name of the project").option(
1986
+ "-p, --project-name <string>",
1987
+ "Project name that will be used in package.json and as the project directory name."
1988
+ ).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/)").action(async (projectNameArg, args) => {
1989
+ const projectName = projectNameArg || args.projectName;
1939
1990
  const timeout = args?.timeout ? args?.timeout === true ? 6e4 : parseInt(args?.timeout, 10) : void 0;
1940
1991
  if (args.default) {
1941
1992
  await create({
@@ -1953,7 +2004,9 @@ program.name("create-mastra").description("Create a new Mastra project").option(
1953
2004
  addExample: args.example,
1954
2005
  llmApiKey: args["llm-api-key"],
1955
2006
  createVersionTag,
1956
- timeout
2007
+ timeout,
2008
+ projectName,
2009
+ directory: args.dir
1957
2010
  });
1958
2011
  });
1959
2012
  program.parse(process.argv);