mastra 0.10.6-alpha.0 → 0.10.6-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.
@@ -1053,7 +1053,6 @@ var execWithTimeout = async (command, timeoutMs) => {
1053
1053
  throw error;
1054
1054
  }
1055
1055
  } catch (error) {
1056
- console.error(error);
1057
1056
  throw error;
1058
1057
  }
1059
1058
  };
@@ -1065,11 +1064,18 @@ async function installMastraDependency(pm, dependency, versionTag, isDev, timeou
1065
1064
  try {
1066
1065
  await execWithTimeout(`${pm} ${installCommand} ${dependency}${versionTag}`, timeout);
1067
1066
  } catch (err) {
1068
- console.log("err", err);
1069
1067
  if (versionTag === "@latest") {
1070
- throw err;
1068
+ throw new Error(
1069
+ `Failed to install ${dependency}@latest: ${err instanceof Error ? err.message : "Unknown error"}`
1070
+ );
1071
+ }
1072
+ try {
1073
+ await execWithTimeout(`${pm} ${installCommand} ${dependency}@latest`, timeout);
1074
+ } catch (fallbackErr) {
1075
+ throw new Error(
1076
+ `Failed to install ${dependency} (tried ${versionTag} and @latest): ${fallbackErr instanceof Error ? fallbackErr.message : "Unknown error"}`
1077
+ );
1071
1078
  }
1072
- await execWithTimeout(`${pm} ${installCommand} ${dependency}@latest`, timeout);
1073
1079
  }
1074
1080
  }
1075
1081
  var createMastraProject = async ({
@@ -1088,36 +1094,44 @@ var createMastraProject = async ({
1088
1094
  process.exit(0);
1089
1095
  }
1090
1096
  const s2 = p.spinner();
1091
- s2.start("Creating project");
1092
1097
  try {
1093
- await fs4.mkdir(projectName);
1094
- } catch (error) {
1095
- if (error instanceof Error && "code" in error && error.code === "EEXIST") {
1096
- s2.stop(
1097
- `A directory named "${projectName}" already exists. Please choose a different name or delete the existing directory.`
1098
+ s2.start("Creating project");
1099
+ try {
1100
+ await fs4.mkdir(projectName);
1101
+ } catch (error) {
1102
+ if (error instanceof Error && "code" in error && error.code === "EEXIST") {
1103
+ s2.stop(`A directory named "${projectName}" already exists. Please choose a different name.`);
1104
+ process.exit(1);
1105
+ }
1106
+ throw new Error(
1107
+ `Failed to create project directory: ${error instanceof Error ? error.message : "Unknown error"}`
1098
1108
  );
1099
- process.exit(1);
1100
1109
  }
1101
- throw error;
1102
- }
1103
- process.chdir(projectName);
1104
- const pm = getPackageManager();
1105
- const installCommand = getPackageManagerInstallCommand(pm);
1106
- s2.message("Creating project");
1107
- await exec3(`npm init -y`);
1108
- await exec3(`npm pkg set type="module"`);
1109
- await exec3(`npm pkg set engines.node=">=20.9.0"`);
1110
- const depsService = new DepsService();
1111
- await depsService.addScriptsToPackageJson({
1112
- dev: "mastra dev",
1113
- build: "mastra build",
1114
- start: "mastra start"
1115
- });
1116
- s2.stop("Project created");
1117
- s2.start(`Installing ${pm} dependencies`);
1118
- await exec3(`${pm} ${installCommand} zod`);
1119
- await exec3(`${pm} ${installCommand} typescript @types/node --save-dev`);
1120
- await exec3(`echo '{
1110
+ process.chdir(projectName);
1111
+ const pm = getPackageManager();
1112
+ const installCommand = getPackageManagerInstallCommand(pm);
1113
+ s2.message("Initializing project structure");
1114
+ try {
1115
+ await exec3(`npm init -y`);
1116
+ await exec3(`npm pkg set type="module"`);
1117
+ await exec3(`npm pkg set engines.node=">=20.9.0"`);
1118
+ const depsService = new DepsService();
1119
+ await depsService.addScriptsToPackageJson({
1120
+ dev: "mastra dev",
1121
+ build: "mastra build",
1122
+ start: "mastra start"
1123
+ });
1124
+ } catch (error) {
1125
+ throw new Error(
1126
+ `Failed to initialize project structure: ${error instanceof Error ? error.message : "Unknown error"}`
1127
+ );
1128
+ }
1129
+ s2.stop("Project structure created");
1130
+ s2.start(`Installing ${pm} dependencies`);
1131
+ try {
1132
+ await exec3(`${pm} ${installCommand} zod`);
1133
+ await exec3(`${pm} ${installCommand} typescript @types/node --save-dev`);
1134
+ await exec3(`echo '{
1121
1135
  "compilerOptions": {
1122
1136
  "target": "ES2022",
1123
1137
  "module": "ES2022",
@@ -1133,29 +1147,54 @@ var createMastraProject = async ({
1133
1147
  "src/**/*"
1134
1148
  ]
1135
1149
  }' > tsconfig.json`);
1136
- s2.stop(`${pm} dependencies installed`);
1137
- s2.start("Installing mastra");
1138
- const versionTag = createVersionTag ? `@${createVersionTag}` : "@latest";
1139
- await installMastraDependency(pm, "mastra", versionTag, true, timeout);
1140
- s2.stop("mastra installed");
1141
- s2.start("Installing dependencies");
1142
- await installMastraDependency(pm, "@mastra/core", versionTag, false, timeout);
1143
- await installMastraDependency(pm, "@mastra/libsql", versionTag, false, timeout);
1144
- await installMastraDependency(pm, "@mastra/memory", versionTag, false, timeout);
1145
- s2.stop("Dependencies installed");
1146
- s2.start("Adding .gitignore");
1147
- await exec3(`echo output.txt >> .gitignore`);
1148
- await exec3(`echo node_modules >> .gitignore`);
1149
- await exec3(`echo dist >> .gitignore`);
1150
- await exec3(`echo .mastra >> .gitignore`);
1151
- await exec3(`echo .env.development >> .gitignore`);
1152
- await exec3(`echo .env >> .gitignore`);
1153
- await exec3(`echo *.db >> .gitignore`);
1154
- await exec3(`echo *.db-* >> .gitignore`);
1155
- s2.stop(".gitignore added");
1156
- p.outro("Project created successfully");
1157
- console.log("");
1158
- return { projectName };
1150
+ } catch (error) {
1151
+ throw new Error(
1152
+ `Failed to install basic dependencies: ${error instanceof Error ? error.message : "Unknown error"}`
1153
+ );
1154
+ }
1155
+ s2.stop(`${pm} dependencies installed`);
1156
+ s2.start("Installing mastra");
1157
+ const versionTag = createVersionTag ? `@${createVersionTag}` : "@latest";
1158
+ try {
1159
+ await installMastraDependency(pm, "mastra", versionTag, true, timeout);
1160
+ } catch (error) {
1161
+ throw new Error(`Failed to install Mastra CLI: ${error instanceof Error ? error.message : "Unknown error"}`);
1162
+ }
1163
+ s2.stop("mastra installed");
1164
+ s2.start("Installing dependencies");
1165
+ try {
1166
+ await installMastraDependency(pm, "@mastra/core", versionTag, false, timeout);
1167
+ await installMastraDependency(pm, "@mastra/libsql", versionTag, false, timeout);
1168
+ await installMastraDependency(pm, "@mastra/memory", versionTag, false, timeout);
1169
+ } catch (error) {
1170
+ throw new Error(
1171
+ `Failed to install Mastra dependencies: ${error instanceof Error ? error.message : "Unknown error"}`
1172
+ );
1173
+ }
1174
+ s2.stop("Mastra dependencies installed");
1175
+ s2.start("Adding .gitignore");
1176
+ try {
1177
+ await exec3(`echo output.txt >> .gitignore`);
1178
+ await exec3(`echo node_modules >> .gitignore`);
1179
+ await exec3(`echo dist >> .gitignore`);
1180
+ await exec3(`echo .mastra >> .gitignore`);
1181
+ await exec3(`echo .env.development >> .gitignore`);
1182
+ await exec3(`echo .env >> .gitignore`);
1183
+ await exec3(`echo *.db >> .gitignore`);
1184
+ await exec3(`echo *.db-* >> .gitignore`);
1185
+ } catch (error) {
1186
+ throw new Error(`Failed to create .gitignore: ${error instanceof Error ? error.message : "Unknown error"}`);
1187
+ }
1188
+ s2.stop(".gitignore added");
1189
+ p.outro("Project created successfully");
1190
+ console.log("");
1191
+ return { projectName };
1192
+ } catch (error) {
1193
+ s2.stop();
1194
+ const errorMessage = error instanceof Error ? error.message : "An unexpected error occurred";
1195
+ p.cancel(`Project creation failed: ${errorMessage}`);
1196
+ process.exit(1);
1197
+ }
1159
1198
  };
1160
1199
 
1161
1200
  // src/commands/create/create.ts
@@ -1 +1 @@
1
- export { create } from '../../chunk-DJA4WBIU.js';
1
+ export { create } from '../../chunk-25NEZQOD.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, FileService } from './chunk-DJA4WBIU.js';
5
- export { create } from './chunk-DJA4WBIU.js';
4
+ import { DepsService, create, checkPkgJson, checkAndInstallCoreDeps, interactivePrompt, init, logger, FileService } from './chunk-25NEZQOD.js';
5
+ export { create } from './chunk-25NEZQOD.js';
6
6
  import { Command } from 'commander';
7
7
  import { config } from 'dotenv';
8
8
  import { join, dirname } from 'path';
@@ -12,12 +12,13 @@ import { getDeployer, FileService as FileService$1 } from '@mastra/deployer';
12
12
  import { isWebContainer } from '@webcontainer/env';
13
13
  import { execa } from 'execa';
14
14
  import getPort from 'get-port';
15
- import { writeFile } from 'fs/promises';
15
+ import { spawn, exec } from 'child_process';
16
16
  import { fileURLToPath } from 'url';
17
+ import open from 'open';
18
+ import { writeFile } from 'fs/promises';
17
19
  import * as fsExtra from 'fs-extra';
18
20
  import fs, { readFileSync } from 'fs';
19
21
  import stripJsonComments from 'strip-json-comments';
20
- import { spawn } from 'child_process';
21
22
 
22
23
  var BuildBundler = class extends Bundler {
23
24
  customEnvFile;
@@ -113,7 +114,7 @@ async function build({
113
114
  const rootDir = root || process.cwd();
114
115
  const mastraDir = dir2 ? dir2.startsWith("/") ? dir2 : join(rootDir, dir2) : join(rootDir, "src", "mastra");
115
116
  const outputDirectory = join(rootDir, ".mastra");
116
- const defaultToolsPath = join(mastraDir, "tools/**/*");
117
+ const defaultToolsPath = join(mastraDir, "tools/**/*.{js,ts}");
117
118
  const discoveredTools = [defaultToolsPath, ...tools ?? []];
118
119
  try {
119
120
  const fs2 = new FileService();
@@ -171,6 +172,69 @@ async function deploy({ dir: dir2 }) {
171
172
  logger.warn("No deployer found.");
172
173
  }
173
174
  }
175
+ function openBrowser(url, opt) {
176
+ const browser = process.env.BROWSER || "";
177
+ if (browser.toLowerCase() !== "none") {
178
+ const browserArgs = process.env.BROWSER_ARGS ? process.env.BROWSER_ARGS.split(" ") : [];
179
+ void startBrowserProcess(browser, browserArgs, url);
180
+ }
181
+ }
182
+ var supportedChromiumBrowsers = [
183
+ "Google Chrome Canary",
184
+ "Google Chrome Dev",
185
+ "Google Chrome Beta",
186
+ "Google Chrome",
187
+ "Microsoft Edge",
188
+ "Brave Browser",
189
+ "Vivaldi",
190
+ "Chromium",
191
+ "Arc"
192
+ ];
193
+ async function startBrowserProcess(browser, browserArgs, url) {
194
+ const preferredOSXBrowser = browser === "google chrome" ? "Google Chrome" : browser;
195
+ const shouldTryOpenChromeWithAppleScript = process.platform === "darwin" && (!preferredOSXBrowser || supportedChromiumBrowsers.includes(preferredOSXBrowser));
196
+ if (shouldTryOpenChromeWithAppleScript) {
197
+ try {
198
+ const ps = await execAsync("ps cax");
199
+ const openedBrowser = preferredOSXBrowser && ps.includes(preferredOSXBrowser) ? preferredOSXBrowser : supportedChromiumBrowsers.find((b) => ps.includes(b));
200
+ if (openedBrowser) {
201
+ const packageDir = dirname(fileURLToPath(import.meta.resolve("mastra/package.json")));
202
+ await execAsync(`osascript openChrome.applescript "${url}" "${openedBrowser}"`, {
203
+ cwd: join(packageDir, "bin")
204
+ });
205
+ return true;
206
+ }
207
+ } catch {
208
+ }
209
+ }
210
+ if (process.platform === "darwin" && browser === "open") {
211
+ browser = void 0;
212
+ }
213
+ try {
214
+ const options = browser ? { app: { name: browser, arguments: browserArgs } } : {};
215
+ new Promise((_, reject) => {
216
+ open(url, options).then((subprocess) => {
217
+ subprocess.on("error", reject);
218
+ }).catch(reject);
219
+ }).catch((err) => {
220
+ console.error(err.stack || err.message);
221
+ });
222
+ return true;
223
+ } catch {
224
+ return false;
225
+ }
226
+ }
227
+ function execAsync(command, options) {
228
+ return new Promise((resolve, reject) => {
229
+ exec(command, options, (error, stdout) => {
230
+ if (error) {
231
+ reject(error);
232
+ } else {
233
+ resolve(stdout.toString());
234
+ }
235
+ });
236
+ });
237
+ }
174
238
  var DevBundler = class extends Bundler {
175
239
  customEnvFile;
176
240
  constructor(customEnvFile) {
@@ -282,6 +346,7 @@ var DevBundler = class extends Bundler {
282
346
  // src/commands/dev/dev.ts
283
347
  var currentServerProcess;
284
348
  var isRestarting = false;
349
+ var isInitialServerStart = true;
285
350
  var ON_ERROR_MAX_RESTARTS = 3;
286
351
  var startServer = async (dotMastraPath, port, env, errorRestartCount = 0) => {
287
352
  let serverIsReady = false;
@@ -316,6 +381,10 @@ var startServer = async (dotMastraPath, port, env, errorRestartCount = 0) => {
316
381
  currentServerProcess.on("message", async (message) => {
317
382
  if (message?.type === "server-ready") {
318
383
  serverIsReady = true;
384
+ if (isInitialServerStart) {
385
+ isInitialServerStart = false;
386
+ void openBrowser(`http://localhost:${port}`, true);
387
+ }
319
388
  try {
320
389
  await fetch(`http://localhost:${port}/__refresh`, {
321
390
  method: "POST",
@@ -385,7 +454,7 @@ async function dev({
385
454
  const rootDir = root || process.cwd();
386
455
  const mastraDir = dir2 ? dir2.startsWith("/") ? dir2 : join(process.cwd(), dir2) : join(process.cwd(), "src", "mastra");
387
456
  const dotMastraPath = join(rootDir, ".mastra");
388
- const defaultToolsPath = join(mastraDir, "tools/**/*");
457
+ const defaultToolsPath = join(mastraDir, "tools/**/*.{js,ts}");
389
458
  const discoveredTools = [defaultToolsPath, ...tools || []];
390
459
  const fileService = new FileService$1();
391
460
  const entryFile = fileService.getFirstExistingFile([join(mastraDir, "index.ts"), join(mastraDir, "index.js")]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mastra",
3
- "version": "0.10.6-alpha.0",
3
+ "version": "0.10.6-alpha.2",
4
4
  "license": "Elastic-2.0",
5
5
  "description": "cli for mastra",
6
6
  "type": "module",
@@ -44,6 +44,7 @@
44
44
  "fs-extra": "^11.3.0",
45
45
  "get-port": "^7.1.0",
46
46
  "json-schema-to-zod": "^2.6.1",
47
+ "open": "^10.1.2",
47
48
  "picocolors": "^1.1.1",
48
49
  "posthog-node": "4.16.0",
49
50
  "prettier": "^3.5.3",
@@ -57,9 +58,9 @@
57
58
  "yocto-spinner": "^0.1.2",
58
59
  "zod": "^3.25.57",
59
60
  "zod-to-json-schema": "^3.24.5",
60
- "@mastra/deployer": "^0.10.6-alpha.0",
61
- "@mastra/mcp": "^0.10.4-alpha.0",
62
- "@mastra/loggers": "^0.10.2"
61
+ "@mastra/loggers": "^0.10.2",
62
+ "@mastra/deployer": "^0.10.6-alpha.1",
63
+ "@mastra/mcp": "^0.10.4-alpha.0"
63
64
  },
64
65
  "devDependencies": {
65
66
  "@microsoft/api-extractor": "^7.52.8",
@@ -78,9 +79,9 @@
78
79
  "typescript": "^5.8.3",
79
80
  "vitest": "^3.2.3",
80
81
  "@internal/lint": "0.0.12",
81
- "@mastra/playground-ui": "5.1.6-alpha.0",
82
- "@mastra/core": "0.10.6-alpha.0",
83
- "@mastra/client-js": "0.10.5-alpha.0"
82
+ "@mastra/client-js": "0.10.5-alpha.1",
83
+ "@mastra/core": "0.10.6-alpha.1",
84
+ "@mastra/playground-ui": "5.1.6-alpha.1"
84
85
  },
85
86
  "peerDependencies": {
86
87
  "@mastra/core": "^0.10.2-alpha.0"