create-mastra 0.0.0-declaration-maps-20250730004430 → 0.0.0-dynamic-model-router-20251009204130

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
@@ -4,22 +4,16 @@ The easiest way to get started with Mastra is by using `create-mastra`. This CLI
4
4
 
5
5
  ## Usage
6
6
 
7
- Using npx:
8
-
9
- ```bash
10
- npx create-mastra@latest
11
- ```
12
-
13
7
  Using npm:
14
8
 
15
9
  ```bash
16
- npm create mastra@latest
10
+ npx create-mastra@latest
17
11
  ```
18
12
 
19
13
  Using yarn:
20
14
 
21
15
  ```bash
22
- yarn create mastra
16
+ yarn dlx create-mastra@latest
23
17
  ```
24
18
 
25
19
  Using pnpm:
package/dist/index.js CHANGED
@@ -12,15 +12,15 @@ import y$1, { stdout, stdin } from 'node:process';
12
12
  import * as g from 'node:readline';
13
13
  import g__default from 'node:readline';
14
14
  import { Writable } from 'node:stream';
15
- import fs from 'node:fs/promises';
15
+ import fs5 from 'node:fs/promises';
16
16
  import child_process from 'node:child_process';
17
17
  import tty from 'node:tty';
18
18
  import pino from 'pino';
19
19
  import pretty from 'pino-pretty';
20
20
  import { execa } from 'execa';
21
- import fsExtra3, { readJSON, ensureFile, writeJSON } from 'fs-extra/esm';
21
+ import fsExtra, { readJSON, ensureFile, writeJSON } from 'fs-extra/esm';
22
22
  import prettier from 'prettier';
23
- import fsExtra from 'fs-extra';
23
+ import fsExtra$1 from 'fs-extra';
24
24
 
25
25
  var __filename = fileURLToPath(import.meta.url);
26
26
  var __dirname = path3.dirname(__filename);
@@ -1196,18 +1196,6 @@ function getPackageManager() {
1196
1196
  }
1197
1197
  return "npm";
1198
1198
  }
1199
- function getPackageManagerInstallCommand(pm) {
1200
- switch (pm) {
1201
- case "npm":
1202
- return "install";
1203
- case "yarn":
1204
- return "add";
1205
- case "pnpm":
1206
- return "add";
1207
- default:
1208
- return "install";
1209
- }
1210
- }
1211
1199
  var logger = new PinoLogger({
1212
1200
  name: "Mastra CLI",
1213
1201
  level: "info"
@@ -1226,7 +1214,7 @@ async function cloneTemplate(options) {
1226
1214
  await updatePackageJson(projectPath, projectName);
1227
1215
  const envExamplePath = path3.join(projectPath, ".env.example");
1228
1216
  if (await fileExists(envExamplePath)) {
1229
- await fs.copyFile(envExamplePath, path3.join(projectPath, ".env"));
1217
+ await fs5.copyFile(envExamplePath, path3.join(projectPath, ".env"));
1230
1218
  }
1231
1219
  spinner5.success(`Template "${template.title}" cloned successfully to ${projectName}`);
1232
1220
  return projectPath;
@@ -1237,7 +1225,7 @@ async function cloneTemplate(options) {
1237
1225
  }
1238
1226
  async function directoryExists(dirPath) {
1239
1227
  try {
1240
- const stat = await fs.stat(dirPath);
1228
+ const stat = await fs5.stat(dirPath);
1241
1229
  return stat.isDirectory();
1242
1230
  } catch {
1243
1231
  return false;
@@ -1245,14 +1233,14 @@ async function directoryExists(dirPath) {
1245
1233
  }
1246
1234
  async function fileExists(filePath) {
1247
1235
  try {
1248
- const stat = await fs.stat(filePath);
1236
+ const stat = await fs5.stat(filePath);
1249
1237
  return stat.isFile();
1250
1238
  } catch {
1251
1239
  return false;
1252
1240
  }
1253
1241
  }
1254
1242
  async function cloneRepositoryWithoutGit(repoUrl, targetPath) {
1255
- await fs.mkdir(targetPath, { recursive: true });
1243
+ await fs5.mkdir(targetPath, { recursive: true });
1256
1244
  try {
1257
1245
  const degitRepo = repoUrl.replace("https://github.com/", "");
1258
1246
  const degitCommand = shellQuote.quote(["npx", "degit", degitRepo, targetPath]);
@@ -1267,7 +1255,7 @@ async function cloneRepositoryWithoutGit(repoUrl, targetPath) {
1267
1255
  });
1268
1256
  const gitDir = path3.join(targetPath, ".git");
1269
1257
  if (await directoryExists(gitDir)) {
1270
- await fs.rm(gitDir, { recursive: true, force: true });
1258
+ await fs5.rm(gitDir, { recursive: true, force: true });
1271
1259
  }
1272
1260
  } catch (gitError) {
1273
1261
  throw new Error(`Failed to clone repository: ${gitError instanceof Error ? gitError.message : "Unknown error"}`);
@@ -1277,10 +1265,10 @@ async function cloneRepositoryWithoutGit(repoUrl, targetPath) {
1277
1265
  async function updatePackageJson(projectPath, projectName) {
1278
1266
  const packageJsonPath = path3.join(projectPath, "package.json");
1279
1267
  try {
1280
- const packageJsonContent = await fs.readFile(packageJsonPath, "utf-8");
1268
+ const packageJsonContent = await fs5.readFile(packageJsonPath, "utf-8");
1281
1269
  const packageJson = JSON.parse(packageJsonContent);
1282
1270
  packageJson.name = projectName;
1283
- await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2), "utf-8");
1271
+ await fs5.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2), "utf-8");
1284
1272
  } catch (error) {
1285
1273
  logger.warn(`Could not update package.json: ${error instanceof Error ? error.message : "Unknown error"}`);
1286
1274
  }
@@ -1362,6 +1350,20 @@ function findTemplateByName(templates, templateName) {
1362
1350
  function getDefaultProjectName(template) {
1363
1351
  return template.slug.replace(/^template-/, "");
1364
1352
  }
1353
+ function getPackageManagerAddCommand(pm) {
1354
+ switch (pm) {
1355
+ case "npm":
1356
+ return "install --audit=false --fund=false --loglevel=error --progress=false --update-notifier=false";
1357
+ case "yarn":
1358
+ return "add";
1359
+ case "pnpm":
1360
+ return "add --loglevel=error";
1361
+ case "bun":
1362
+ return "add";
1363
+ default:
1364
+ return "add";
1365
+ }
1366
+ }
1365
1367
  var DepsService = class {
1366
1368
  packageManager;
1367
1369
  constructor() {
@@ -1396,14 +1398,10 @@ var DepsService = class {
1396
1398
  }
1397
1399
  }
1398
1400
  async installPackages(packages) {
1399
- let runCommand = this.packageManager;
1400
- if (this.packageManager === "npm") {
1401
- runCommand = `${this.packageManager} i`;
1402
- } else {
1403
- runCommand = `${this.packageManager} add`;
1404
- }
1401
+ const pm = this.packageManager;
1402
+ const installCommand = getPackageManagerAddCommand(pm);
1405
1403
  const packageList = packages.join(" ");
1406
- return execa(`${runCommand} ${packageList}`, {
1404
+ return execa(`${pm} ${installCommand} ${packageList}`, {
1407
1405
  all: true,
1408
1406
  shell: true,
1409
1407
  stdio: "inherit"
@@ -1413,11 +1411,11 @@ var DepsService = class {
1413
1411
  try {
1414
1412
  const packageJsonPath = path3.join(process.cwd(), "package.json");
1415
1413
  try {
1416
- await fs.access(packageJsonPath);
1414
+ await fs5.access(packageJsonPath);
1417
1415
  } catch {
1418
1416
  return "No package.json file found in the current directory";
1419
1417
  }
1420
- const packageJson = JSON.parse(await fs.readFile(packageJsonPath, "utf-8"));
1418
+ const packageJson = JSON.parse(await fs5.readFile(packageJsonPath, "utf-8"));
1421
1419
  for (const dependency of dependencies) {
1422
1420
  if (!packageJson.dependencies || !packageJson.dependencies[dependency]) {
1423
1421
  return `Please install ${dependency} before running this command (${this.packageManager} install ${dependency})`;
@@ -1432,27 +1430,20 @@ var DepsService = class {
1432
1430
  async getProjectName() {
1433
1431
  try {
1434
1432
  const packageJsonPath = path3.join(process.cwd(), "package.json");
1435
- const packageJson = await fs.readFile(packageJsonPath, "utf-8");
1433
+ const packageJson = await fs5.readFile(packageJsonPath, "utf-8");
1436
1434
  const pkg = JSON.parse(packageJson);
1437
1435
  return pkg.name;
1438
1436
  } catch (err) {
1439
1437
  throw err;
1440
1438
  }
1441
1439
  }
1442
- async getPackageVersion() {
1443
- const __filename = fileURLToPath(import.meta.url);
1444
- const __dirname = dirname(__filename);
1445
- const pkgJsonPath = path3.join(__dirname, "..", "package.json");
1446
- const content = await fsExtra3.readJSON(pkgJsonPath);
1447
- return content.version;
1448
- }
1449
1440
  async addScriptsToPackageJson(scripts) {
1450
- const packageJson = JSON.parse(await fs.readFile("package.json", "utf-8"));
1441
+ const packageJson = JSON.parse(await fs5.readFile("package.json", "utf-8"));
1451
1442
  packageJson.scripts = {
1452
1443
  ...packageJson.scripts,
1453
1444
  ...scripts
1454
1445
  };
1455
- await fs.writeFile("package.json", JSON.stringify(packageJson, null, 2));
1446
+ await fs5.writeFile("package.json", JSON.stringify(packageJson, null, 2));
1456
1447
  }
1457
1448
  };
1458
1449
  var args = ["-y", "@mastra/mcp-docs-server"];
@@ -1605,7 +1596,7 @@ var FileEnvService = class extends EnvService {
1605
1596
  ${key}=${value}`;
1606
1597
  }
1607
1598
  await this.writeFile({ filePath, data });
1608
- console.log(`${key} set to ${value} in ENV file.`);
1599
+ console.info(`${key} set to ${value} in ENV file.`);
1609
1600
  return data;
1610
1601
  }
1611
1602
  async getEnvValue(key) {
@@ -1642,15 +1633,15 @@ var FileService = class {
1642
1633
  const filePath = path3.resolve(__dirname, "starter-files", inputFile);
1643
1634
  const fileString = fs4__default__default.readFileSync(filePath, "utf8");
1644
1635
  if (fs4__default__default.existsSync(outputFilePath) && !replaceIfExists) {
1645
- console.log(`${outputFilePath} already exists`);
1636
+ console.info(`${outputFilePath} already exists`);
1646
1637
  return false;
1647
1638
  }
1648
- await fsExtra3.outputFile(outputFilePath, fileString);
1639
+ await fsExtra.outputFile(outputFilePath, fileString);
1649
1640
  return true;
1650
1641
  }
1651
1642
  async setupEnvFile({ dbUrl }) {
1652
1643
  const envPath = path3.join(process.cwd(), ".env.development");
1653
- await fsExtra3.ensureFile(envPath);
1644
+ await fsExtra.ensureFile(envPath);
1654
1645
  const fileEnvService = new FileEnvService(envPath);
1655
1646
  await fileEnvService.setEnvValue("DB_URL", dbUrl);
1656
1647
  }
@@ -1674,6 +1665,12 @@ var FileService = class {
1674
1665
  }
1675
1666
  };
1676
1667
  var exec2 = util.promisify(child_process.exec);
1668
+ var getAISDKPackageVersion = (llmProvider) => {
1669
+ switch (llmProvider) {
1670
+ default:
1671
+ return "latest";
1672
+ }
1673
+ };
1677
1674
  var getAISDKPackage = (llmProvider) => {
1678
1675
  switch (llmProvider) {
1679
1676
  case "openai":
@@ -1686,6 +1683,8 @@ var getAISDKPackage = (llmProvider) => {
1686
1683
  return "@ai-sdk/google";
1687
1684
  case "cerebras":
1688
1685
  return "@ai-sdk/cerebras";
1686
+ case "mistral":
1687
+ return "@ai-sdk/mistral";
1689
1688
  default:
1690
1689
  return "@ai-sdk/openai";
1691
1690
  }
@@ -1704,10 +1703,13 @@ var getProviderImportAndModelItem = (llmProvider) => {
1704
1703
  modelItem = `groq('llama-3.3-70b-versatile')`;
1705
1704
  } else if (llmProvider === "google") {
1706
1705
  providerImport = `import { google } from '${getAISDKPackage(llmProvider)}';`;
1707
- modelItem = `google('gemini-2.5-pro-exp-03-25')`;
1706
+ modelItem = `google('gemini-2.5-pro')`;
1708
1707
  } else if (llmProvider === "cerebras") {
1709
1708
  providerImport = `import { cerebras } from '${getAISDKPackage(llmProvider)}';`;
1710
1709
  modelItem = `cerebras('llama-3.3-70b')`;
1710
+ } else if (llmProvider === "mistral") {
1711
+ providerImport = `import { mistral } from '${getAISDKPackage(llmProvider)}';`;
1712
+ modelItem = `mistral('mistral-medium-2508')`;
1711
1713
  }
1712
1714
  return { providerImport, modelItem };
1713
1715
  };
@@ -1750,8 +1752,8 @@ export const weatherAgent = new Agent({
1750
1752
  parser: "typescript",
1751
1753
  singleQuote: true
1752
1754
  });
1753
- await fs.writeFile(destPath, "");
1754
- await fs.writeFile(destPath, formattedContent);
1755
+ await fs5.writeFile(destPath, "");
1756
+ await fs5.writeFile(destPath, formattedContent);
1755
1757
  }
1756
1758
  async function writeWorkflowSample(destPath) {
1757
1759
  const content = `import { createStep, createWorkflow } from '@mastra/core/workflows';
@@ -1944,7 +1946,7 @@ export { weatherWorkflow };`;
1944
1946
  semi: true,
1945
1947
  singleQuote: true
1946
1948
  });
1947
- await fs.writeFile(destPath, formattedContent);
1949
+ await fs5.writeFile(destPath, formattedContent);
1948
1950
  }
1949
1951
  async function writeToolSample(destPath) {
1950
1952
  const fileService = new FileService();
@@ -1964,7 +1966,7 @@ async function writeCodeSampleForComponents(llmprovider, component, destPath, im
1964
1966
  }
1965
1967
  var createComponentsDir = async (dirPath, component) => {
1966
1968
  const componentPath = dirPath + `/${component}`;
1967
- await fsExtra3.ensureDir(componentPath);
1969
+ await fsExtra.ensureDir(componentPath);
1968
1970
  };
1969
1971
  var writeIndexFile = async ({
1970
1972
  dirPath,
@@ -1975,13 +1977,13 @@ var writeIndexFile = async ({
1975
1977
  const indexPath = dirPath + "/index.ts";
1976
1978
  const destPath = path3.join(indexPath);
1977
1979
  try {
1978
- await fs.writeFile(destPath, "");
1980
+ await fs5.writeFile(destPath, "");
1979
1981
  const filteredExports = [
1980
1982
  addWorkflow ? `workflows: { weatherWorkflow },` : "",
1981
1983
  addAgent ? `agents: { weatherAgent },` : ""
1982
1984
  ].filter(Boolean);
1983
1985
  if (!addExample) {
1984
- await fs.writeFile(
1986
+ await fs5.writeFile(
1985
1987
  destPath,
1986
1988
  `
1987
1989
  import { Mastra } from '@mastra/core';
@@ -1991,7 +1993,7 @@ export const mastra = new Mastra()
1991
1993
  );
1992
1994
  return;
1993
1995
  }
1994
- await fs.writeFile(
1996
+ await fs5.writeFile(
1995
1997
  destPath,
1996
1998
  `
1997
1999
  import { Mastra } from '@mastra/core/mastra';
@@ -2003,13 +2005,21 @@ ${addAgent ? `import { weatherAgent } from './agents/weather-agent';` : ""}
2003
2005
  export const mastra = new Mastra({
2004
2006
  ${filteredExports.join("\n ")}
2005
2007
  storage: new LibSQLStore({
2006
- // stores telemetry, evals, ... into memory storage, if it needs to persist, change to file:../mastra.db
2008
+ // stores observability, scores, ... into memory storage, if it needs to persist, change to file:../mastra.db
2007
2009
  url: ":memory:",
2008
2010
  }),
2009
2011
  logger: new PinoLogger({
2010
2012
  name: 'Mastra',
2011
2013
  level: 'info',
2012
2014
  }),
2015
+ telemetry: {
2016
+ // Telemetry is deprecated and will be removed in the Nov 4th release
2017
+ enabled: false,
2018
+ },
2019
+ observability: {
2020
+ // Enables DefaultExporter and CloudExporter for AI tracing
2021
+ default: { enabled: true },
2022
+ },
2013
2023
  });
2014
2024
  `
2015
2025
  );
@@ -2033,27 +2043,28 @@ var getAPIKey = async (provider) => {
2033
2043
  case "cerebras":
2034
2044
  key = "CEREBRAS_API_KEY";
2035
2045
  return key;
2046
+ case "mistral":
2047
+ key = "MISTRAL_API_KEY";
2048
+ return key;
2036
2049
  default:
2037
2050
  return key;
2038
2051
  }
2039
2052
  };
2040
- var writeAPIKey = async ({
2041
- provider,
2042
- apiKey = "your-api-key"
2043
- }) => {
2053
+ var writeAPIKey = async ({ provider, apiKey }) => {
2054
+ const envFileName = apiKey ? ".env" : ".env.example";
2044
2055
  const key = await getAPIKey(provider);
2045
2056
  const escapedKey = shellQuote.quote([key]);
2046
- const escapedApiKey = shellQuote.quote([apiKey]);
2047
- await exec2(`echo ${escapedKey}=${escapedApiKey} >> .env`);
2057
+ const escapedApiKey = shellQuote.quote([apiKey ? apiKey : "your-api-key"]);
2058
+ await exec2(`echo ${escapedKey}=${escapedApiKey} >> ${envFileName}`);
2048
2059
  };
2049
2060
  var createMastraDir = async (directory) => {
2050
2061
  let dir = directory.trim().split("/").filter((item) => item !== "");
2051
2062
  const dirPath = path3.join(process.cwd(), ...dir, "mastra");
2052
2063
  try {
2053
- await fs.access(dirPath);
2064
+ await fs5.access(dirPath);
2054
2065
  return { ok: false };
2055
2066
  } catch {
2056
- await fsExtra3.ensureDir(dirPath);
2067
+ await fsExtra.ensureDir(dirPath);
2057
2068
  return { ok: true, dirPath };
2058
2069
  }
2059
2070
  };
@@ -2065,8 +2076,19 @@ var writeCodeSample = async (dirPath, component, llmProvider, importComponents)
2065
2076
  throw err;
2066
2077
  }
2067
2078
  };
2068
- var interactivePrompt = async () => {
2069
- Ie(color2.inverse(" Mastra Init "));
2079
+ var LLM_PROVIDERS = [
2080
+ { value: "openai", label: "OpenAI", hint: "recommended" },
2081
+ { value: "anthropic", label: "Anthropic" },
2082
+ { value: "groq", label: "Groq" },
2083
+ { value: "google", label: "Google" },
2084
+ { value: "cerebras", label: "Cerebras" },
2085
+ { value: "mistral", label: "Mistral" }
2086
+ ];
2087
+ var interactivePrompt = async (args2 = {}) => {
2088
+ const { skip = {}, options: { showBanner = true } = {} } = args2;
2089
+ if (showBanner) {
2090
+ Ie(color2.inverse(" Mastra Init "));
2091
+ }
2070
2092
  const mastraProject = await Ce(
2071
2093
  {
2072
2094
  directory: () => he({
@@ -2074,19 +2096,15 @@ var interactivePrompt = async () => {
2074
2096
  placeholder: "src/",
2075
2097
  defaultValue: "src/"
2076
2098
  }),
2077
- llmProvider: () => ve({
2078
- message: "Select default provider:",
2079
- options: [
2080
- { value: "openai", label: "OpenAI", hint: "recommended" },
2081
- { value: "anthropic", label: "Anthropic" },
2082
- { value: "groq", label: "Groq" },
2083
- { value: "google", label: "Google" },
2084
- { value: "cerebras", label: "Cerebras" }
2085
- ]
2099
+ llmProvider: () => skip?.llmProvider ? void 0 : ve({
2100
+ message: "Select a default provider:",
2101
+ options: LLM_PROVIDERS
2086
2102
  }),
2087
2103
  llmApiKey: async ({ results: { llmProvider } }) => {
2104
+ if (skip?.llmApiKey) return void 0;
2105
+ const llmName = LLM_PROVIDERS.find((p6) => p6.value === llmProvider)?.label || "provider";
2088
2106
  const keyChoice = await ve({
2089
- message: `Enter your ${llmProvider} API key?`,
2107
+ message: `Enter your ${llmName} API key?`,
2090
2108
  options: [
2091
2109
  { value: "skip", label: "Skip for now", hint: "default" },
2092
2110
  { value: "enter", label: "Enter API key" }
@@ -2096,7 +2114,10 @@ var interactivePrompt = async () => {
2096
2114
  if (keyChoice === "enter") {
2097
2115
  return he({
2098
2116
  message: "Enter your API key:",
2099
- placeholder: "sk-..."
2117
+ placeholder: "sk-...",
2118
+ validate: (value) => {
2119
+ if (value.length === 0) return "API key cannot be empty";
2120
+ }
2100
2121
  });
2101
2122
  }
2102
2123
  return void 0;
@@ -2106,7 +2127,7 @@ var interactivePrompt = async () => {
2106
2127
  const cursorIsAlreadyInstalled = await globalMCPIsAlreadyInstalled(`cursor`);
2107
2128
  const vscodeIsAlreadyInstalled = await globalMCPIsAlreadyInstalled(`vscode`);
2108
2129
  const editor = await ve({
2109
- message: `Make your AI IDE into a Mastra expert? (installs Mastra docs MCP server)`,
2130
+ message: `Make your IDE into a Mastra expert? (Installs Mastra's MCP server)`,
2110
2131
  options: [
2111
2132
  { value: "skip", label: "Skip for now", hint: "default" },
2112
2133
  {
@@ -2236,10 +2257,11 @@ var init = async ({
2236
2257
  }
2237
2258
  const key = await getAPIKey(llmProvider || "openai");
2238
2259
  const aiSdkPackage = getAISDKPackage(llmProvider);
2260
+ const aiSdkPackageVersion = getAISDKPackageVersion(llmProvider);
2239
2261
  const depsService = new DepsService();
2240
2262
  const pm = depsService.packageManager;
2241
- const installCommand = getPackageManagerInstallCommand(pm);
2242
- await exec3(`${pm} ${installCommand} ${aiSdkPackage}`);
2263
+ const installCommand = getPackageManagerAddCommand(pm);
2264
+ await exec3(`${pm} ${installCommand} ${aiSdkPackage}@${aiSdkPackageVersion}`);
2243
2265
  if (configureEditorWithDocsMCP) {
2244
2266
  await installMastraDocsMCPServer({
2245
2267
  editor: configureEditorWithDocsMCP,
@@ -2293,9 +2315,9 @@ var execWithTimeout = async (command, timeoutMs) => {
2293
2315
  }
2294
2316
  };
2295
2317
  async function installMastraDependency(pm, dependency, versionTag, isDev, timeout) {
2296
- let installCommand = getPackageManagerInstallCommand(pm);
2318
+ let installCommand = getPackageManagerAddCommand(pm);
2297
2319
  if (isDev) {
2298
- installCommand = `${installCommand} --save-dev`;
2320
+ installCommand = `${installCommand} -D`;
2299
2321
  }
2300
2322
  try {
2301
2323
  await execWithTimeout(`${pm} ${installCommand} ${dependency}${versionTag}`, timeout);
@@ -2317,23 +2339,39 @@ async function installMastraDependency(pm, dependency, versionTag, isDev, timeou
2317
2339
  var createMastraProject = async ({
2318
2340
  projectName: name,
2319
2341
  createVersionTag,
2320
- timeout
2342
+ timeout,
2343
+ llmProvider,
2344
+ llmApiKey,
2345
+ needsInteractive
2321
2346
  }) => {
2322
2347
  Ie(color2.inverse(" Mastra Create "));
2323
2348
  const projectName = name ?? await he({
2324
2349
  message: "What do you want to name your project?",
2325
2350
  placeholder: "my-mastra-app",
2326
- defaultValue: "my-mastra-app"
2351
+ defaultValue: "my-mastra-app",
2352
+ validate: (value) => {
2353
+ if (value.length === 0) return "Project name cannot be empty";
2354
+ if (fs4__default__default.existsSync(value)) {
2355
+ return `A directory named "${value}" already exists. Please choose a different name.`;
2356
+ }
2357
+ }
2327
2358
  });
2328
2359
  if (pD(projectName)) {
2329
2360
  xe("Operation cancelled");
2330
2361
  process.exit(0);
2331
2362
  }
2363
+ let result;
2364
+ if (needsInteractive) {
2365
+ result = await interactivePrompt({
2366
+ options: { showBanner: false },
2367
+ skip: { llmProvider: llmProvider !== void 0, llmApiKey: llmApiKey !== void 0 }
2368
+ });
2369
+ }
2332
2370
  const s2 = Y();
2333
2371
  try {
2334
2372
  s2.start("Creating project");
2335
2373
  try {
2336
- await fs.mkdir(projectName);
2374
+ await fs5.mkdir(projectName);
2337
2375
  } catch (error) {
2338
2376
  if (error instanceof Error && "code" in error && error.code === "EEXIST") {
2339
2377
  s2.stop(`A directory named "${projectName}" already exists. Please choose a different name.`);
@@ -2345,7 +2383,7 @@ var createMastraProject = async ({
2345
2383
  }
2346
2384
  process.chdir(projectName);
2347
2385
  const pm = getPackageManager();
2348
- const installCommand = getPackageManagerInstallCommand(pm);
2386
+ const installCommand = getPackageManagerAddCommand(pm);
2349
2387
  s2.message("Initializing project structure");
2350
2388
  try {
2351
2389
  await exec4(`npm init -y`);
@@ -2389,15 +2427,15 @@ var createMastraProject = async ({
2389
2427
  );
2390
2428
  }
2391
2429
  s2.stop(`${pm} dependencies installed`);
2392
- s2.start("Installing mastra");
2430
+ s2.start("Installing Mastra CLI");
2393
2431
  const versionTag = createVersionTag ? `@${createVersionTag}` : "@latest";
2394
2432
  try {
2395
2433
  await installMastraDependency(pm, "mastra", versionTag, true, timeout);
2396
2434
  } catch (error) {
2397
2435
  throw new Error(`Failed to install Mastra CLI: ${error instanceof Error ? error.message : "Unknown error"}`);
2398
2436
  }
2399
- s2.stop("mastra installed");
2400
- s2.start("Installing dependencies");
2437
+ s2.stop("Mastra CLI installed");
2438
+ s2.start("Installing Mastra dependencies");
2401
2439
  try {
2402
2440
  await installMastraDependency(pm, "@mastra/core", versionTag, false, timeout);
2403
2441
  await installMastraDependency(pm, "@mastra/libsql", versionTag, false, timeout);
@@ -2423,8 +2461,8 @@ var createMastraProject = async ({
2423
2461
  }
2424
2462
  s2.stop(".gitignore added");
2425
2463
  Se("Project created successfully");
2426
- console.log("");
2427
- return { projectName };
2464
+ console.info("");
2465
+ return { projectName, result };
2428
2466
  } catch (error) {
2429
2467
  s2.stop();
2430
2468
  const errorMessage = error instanceof Error ? error.message : "An unexpected error occurred";
@@ -2434,17 +2472,20 @@ var createMastraProject = async ({
2434
2472
  };
2435
2473
  var create = async (args2) => {
2436
2474
  if (args2.template !== void 0) {
2437
- await createFromTemplate(args2);
2475
+ await createFromTemplate({ ...args2, injectedAnalytics: args2.analytics });
2438
2476
  return;
2439
2477
  }
2440
- const { projectName } = await createMastraProject({
2478
+ const needsInteractive = args2.components === void 0 || args2.llmProvider === void 0 || args2.addExample === void 0;
2479
+ const { projectName, result } = await createMastraProject({
2441
2480
  projectName: args2?.projectName,
2442
2481
  createVersionTag: args2?.createVersionTag,
2443
- timeout: args2?.timeout
2482
+ timeout: args2?.timeout,
2483
+ llmProvider: args2?.llmProvider,
2484
+ llmApiKey: args2?.llmApiKey,
2485
+ needsInteractive
2444
2486
  });
2445
2487
  const directory = args2.directory || "src/";
2446
- if (args2.components === void 0 || args2.llmProvider === void 0 || args2.addExample === void 0) {
2447
- const result = await interactivePrompt();
2488
+ if (needsInteractive && result) {
2448
2489
  await init({
2449
2490
  ...result,
2450
2491
  llmApiKey: result?.llmApiKey,
@@ -2604,8 +2645,13 @@ async function createFromTemplate(args2) {
2604
2645
  projectName = response;
2605
2646
  }
2606
2647
  try {
2607
- const analytics = getAnalytics();
2608
- if (analytics) ;
2648
+ const analytics = args2.injectedAnalytics || getAnalytics();
2649
+ if (analytics) {
2650
+ analytics.trackEvent("cli_template_used", {
2651
+ template_slug: selectedTemplate.slug,
2652
+ template_title: selectedTemplate.title
2653
+ });
2654
+ }
2609
2655
  const projectPath = await cloneTemplate({
2610
2656
  template: selectedTemplate,
2611
2657
  projectName
@@ -2614,7 +2660,7 @@ async function createFromTemplate(args2) {
2614
2660
  Me(`
2615
2661
  ${color2.green("Mastra template installed!")}
2616
2662
 
2617
- Add the necessary environment
2663
+ Add the necessary environment
2618
2664
  variables in your ${color2.cyan(".env")} file
2619
2665
  `);
2620
2666
  postCreate({ projectName });
@@ -2628,13 +2674,13 @@ async function getPackageVersion() {
2628
2674
  const __filename = fileURLToPath(import.meta.url);
2629
2675
  const __dirname = dirname(__filename);
2630
2676
  const pkgJsonPath = path3.join(__dirname, "..", "package.json");
2631
- const content = await fsExtra.readJSON(pkgJsonPath);
2677
+ const content = await fsExtra$1.readJSON(pkgJsonPath);
2632
2678
  return content.version;
2633
2679
  }
2634
2680
  async function getCreateVersionTag() {
2635
2681
  try {
2636
2682
  const pkgPath = fileURLToPath(import.meta.resolve("create-mastra/package.json"));
2637
- const json = await fsExtra.readJSON(pkgPath);
2683
+ const json = await fsExtra$1.readJSON(pkgPath);
2638
2684
  const { stdout } = await execa("npm", ["dist-tag", "create-mastra"]);
2639
2685
  const tagLine = stdout.split("\n").find((distLine) => distLine.endsWith(`: ${json.version}`));
2640
2686
  const tag = tagLine ? tagLine.split(":")[0].trim() : "latest";
@@ -2658,14 +2704,14 @@ program.version(`${version}`, "-v, --version").description(`create-mastra ${vers
2658
2704
  analytics.trackCommand({
2659
2705
  command: "version"
2660
2706
  });
2661
- console.log(`create-mastra ${version}`);
2707
+ console.info(`create-mastra ${version}`);
2662
2708
  } catch {
2663
2709
  }
2664
2710
  });
2665
2711
  program.name("create-mastra").description("Create a new Mastra project").argument("[project-name]", "Directory name of the project").option(
2666
2712
  "-p, --project-name <string>",
2667
2713
  "Project name that will be used in package.json and as the project directory name."
2668
- ).option("--default", "Quick start with defaults(src, OpenAI, 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("-m, --mcp <mcp>", "MCP Server for code editor (cursor, cursor-global, windsurf, vscode)").option(
2714
+ ).option("--default", "Quick start with defaults (src, OpenAI, 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("-m, --mcp <mcp>", "MCP Server for code editor (cursor, cursor-global, windsurf, vscode)").option(
2669
2715
  "--template [template-name]",
2670
2716
  "Create project from a template (use template name, public GitHub URL, or leave blank to select from list)"
2671
2717
  ).action(async (projectNameArg, args) => {
@@ -2680,7 +2726,8 @@ program.name("create-mastra").description("Create a new Mastra project").argumen
2680
2726
  timeout,
2681
2727
  mcpServer: args.mcp,
2682
2728
  directory: "src/",
2683
- template: args.template
2729
+ template: args.template,
2730
+ analytics
2684
2731
  });
2685
2732
  return;
2686
2733
  }
@@ -2688,13 +2735,14 @@ program.name("create-mastra").description("Create a new Mastra project").argumen
2688
2735
  components: args.components ? args.components.split(",") : [],
2689
2736
  llmProvider: args.llm,
2690
2737
  addExample: args.example,
2691
- llmApiKey: args["llm-api-key"],
2738
+ llmApiKey: args.llmApiKey,
2692
2739
  createVersionTag,
2693
2740
  timeout,
2694
2741
  projectName,
2695
2742
  directory: args.dir,
2696
2743
  mcpServer: args.mcp,
2697
- template: args.template
2744
+ template: args.template,
2745
+ analytics
2698
2746
  });
2699
2747
  });
2700
2748
  program.parse(process.argv);