mastra 0.11.2 → 0.11.3-alpha.0

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
@@ -1,10 +1,10 @@
1
1
  #! /usr/bin/env node
2
- import { DepsService, create, checkPkgJson, checkAndInstallCoreDeps, interactivePrompt, init, logger, FileService } from './chunk-Q7EUFCXR.js';
3
- export { create } from './chunk-Q7EUFCXR.js';
2
+ import { create, checkPkgJson, checkAndInstallCoreDeps, interactivePrompt, init, logger, FileService, DepsService } from './chunk-YGURCKOZ.js';
3
+ export { create } from './chunk-YGURCKOZ.js';
4
4
  import { PosthogAnalytics, setAnalytics } from './chunk-OQQFOUQW.js';
5
5
  export { PosthogAnalytics } from './chunk-OQQFOUQW.js';
6
6
  import { Command } from 'commander';
7
- import color from 'picocolors';
7
+ import pc2 from 'picocolors';
8
8
  import * as p2 from '@clack/prompts';
9
9
  import fs, { readFileSync } from 'fs';
10
10
  import path, { join, dirname } from 'path';
@@ -22,6 +22,10 @@ import { fileURLToPath } from 'url';
22
22
  import * as fsExtra from 'fs-extra';
23
23
  import { spawn } from 'child_process';
24
24
 
25
+ // package.json
26
+ var package_default = {
27
+ version: "0.11.3-alpha.0"};
28
+
25
29
  // src/utils/string.ts
26
30
  var toCamelCase = (str) => {
27
31
  return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
@@ -201,7 +205,7 @@ async function initializeScorer(scorerId, filename, customPath) {
201
205
  }
202
206
  function showSuccessNote() {
203
207
  p2.note(`
204
- ${color.green("To use: Add the Scorer to your workflow or agent!")}
208
+ ${pc2.green("To use: Add the Scorer to your workflow or agent!")}
205
209
  `);
206
210
  }
207
211
  async function showInteractivePrompt(providedCustomDir) {
@@ -212,7 +216,7 @@ async function showInteractivePrompt(providedCustomDir) {
212
216
  let customPath = providedCustomDir;
213
217
  if (!providedCustomDir) {
214
218
  const useCustomDir = await p2.confirm({
215
- message: `Would you like to use a custom directory?${color.gray("(Default: src/mastra/scorers)")}`,
219
+ message: `Would you like to use a custom directory?${pc2.gray("(Default: src/mastra/scorers)")}`,
216
220
  initialValue: false
217
221
  });
218
222
  if (p2.isCancel(useCustomDir)) {
@@ -728,7 +732,7 @@ var lintProject = async (args) => {
728
732
  });
729
733
  };
730
734
  function listAllScorers() {
731
- p2.intro(color.inverse(" Available Scorers "));
735
+ p2.intro(pc2.inverse(" Available Scorers "));
732
736
  const groupedScorers = AVAILABLE_SCORERS.reduce(
733
737
  (acc, scorer) => {
734
738
  if (!acc[scorer.category]) {
@@ -741,10 +745,10 @@ function listAllScorers() {
741
745
  );
742
746
  for (const [category, scorers] of Object.entries(groupedScorers)) {
743
747
  const categoryLabel = category === "accuracy-and-reliability" ? "Accuracy and Reliability" : "Output Quality";
744
- p2.log.info(`${color.bold(color.cyan(categoryLabel))} Scorers:`);
748
+ p2.log.info(`${pc2.bold(pc2.cyan(categoryLabel))} Scorers:`);
745
749
  for (const scorer of scorers) {
746
- p2.log.message(` ${color.bold(scorer.name)} ${color.dim(`(${scorer.id})`)}
747
- ${color.dim(scorer.description)}
750
+ p2.log.message(` ${pc2.bold(scorer.name)} ${pc2.dim(`(${scorer.id})`)}
751
+ ${pc2.dim(scorer.description)}
748
752
  `);
749
753
  }
750
754
  }
@@ -762,6 +766,122 @@ var listScorers = async (args) => {
762
766
  origin: origin5
763
767
  });
764
768
  };
769
+ var DevLogger = class {
770
+ options;
771
+ constructor(options = {}) {
772
+ this.options = {
773
+ timestamp: false,
774
+ colors: true,
775
+ ...options
776
+ };
777
+ }
778
+ formatTime() {
779
+ if (!this.options.timestamp) return "";
780
+ return pc2.dim((/* @__PURE__ */ new Date()).toLocaleTimeString());
781
+ }
782
+ formatPrefix(text2, color2) {
783
+ const time = this.formatTime();
784
+ const prefix = pc2.bold(color2(text2));
785
+ return time ? `${time} ${prefix}` : prefix;
786
+ }
787
+ info(message) {
788
+ const prefix = this.formatPrefix("\u25D0", pc2.cyan);
789
+ console.log(`${prefix} ${message}`);
790
+ }
791
+ success(message) {
792
+ const prefix = this.formatPrefix("\u2713", pc2.green);
793
+ console.log(`${prefix} ${pc2.green(message)}`);
794
+ }
795
+ warn(message) {
796
+ const prefix = this.formatPrefix("\u26A0", pc2.yellow);
797
+ console.log(`${prefix} ${pc2.yellow(message)}`);
798
+ }
799
+ error(message) {
800
+ const prefix = this.formatPrefix("\u2717", pc2.red);
801
+ console.log(`${prefix} ${pc2.red(message)}`);
802
+ }
803
+ starting() {
804
+ const prefix = this.formatPrefix("\u25C7", pc2.blue);
805
+ console.log(`${prefix} ${pc2.blue("Starting Mastra dev server...")}`);
806
+ }
807
+ ready(host, port, startTime) {
808
+ console.log("");
809
+ const timing = startTime ? `${Date.now() - startTime} ms` : "XXX ms";
810
+ console.log(pc2.inverse(pc2.green(" mastra ")) + ` ${pc2.green(version)} ${pc2.gray("ready in")} ${timing}`);
811
+ console.log("");
812
+ console.log(`${pc2.dim("\u2502")} ${pc2.bold("Local:")} ${pc2.cyan(`http://${host}:${port}/`)}`);
813
+ console.log(`${pc2.dim("\u2502")} ${pc2.bold("API:")} ${`http://${host}:${port}/api`}`);
814
+ console.log("");
815
+ }
816
+ bundling() {
817
+ const prefix = this.formatPrefix("\u25D0", pc2.magenta);
818
+ console.log(`${prefix} ${pc2.magenta("Bundling...")}`);
819
+ }
820
+ bundleComplete() {
821
+ const prefix = this.formatPrefix("\u2713", pc2.green);
822
+ console.log(`${prefix} ${pc2.green("Bundle complete")}`);
823
+ }
824
+ watching() {
825
+ const time = this.formatTime();
826
+ const icon = pc2.dim("\u25EF");
827
+ const message = pc2.dim("watching for file changes...");
828
+ const fullMessage = `${icon} ${message}`;
829
+ console.log(time ? `${time} ${fullMessage}` : fullMessage);
830
+ }
831
+ restarting() {
832
+ const prefix = this.formatPrefix("\u21BB", pc2.blue);
833
+ console.log(`${prefix} ${pc2.blue("Restarting server...")}`);
834
+ }
835
+ fileChange(file) {
836
+ const prefix = this.formatPrefix("\u26A1", pc2.cyan);
837
+ const fileName = path.basename(file);
838
+ console.log(`${prefix} ${pc2.cyan("File changed:")} ${pc2.dim(fileName)}`);
839
+ }
840
+ // Enhanced error reporting
841
+ serverError(error) {
842
+ console.log("");
843
+ console.log(pc2.red(" \u2717 ") + pc2.bold(pc2.red("Server Error")));
844
+ console.log("");
845
+ console.log(` ${pc2.red("\u2502")} ${error}`);
846
+ console.log("");
847
+ }
848
+ shutdown() {
849
+ console.log("");
850
+ const prefix = this.formatPrefix("\u2713", pc2.green);
851
+ console.log(`${prefix} ${pc2.green("Dev server stopped")}`);
852
+ }
853
+ envInfo(info) {
854
+ console.log("");
855
+ console.log(` ${pc2.dim("\u2502")} ${pc2.bold("Environment:")} ${pc2.cyan(info.env || "development")}`);
856
+ console.log(` ${pc2.dim("\u2502")} ${pc2.bold("Root:")} ${pc2.dim(info.root)}`);
857
+ console.log(` ${pc2.dim("\u2502")} ${pc2.bold("Port:")} ${pc2.cyan(info.port.toString())}`);
858
+ }
859
+ raw(message) {
860
+ console.log(message);
861
+ }
862
+ debug(message) {
863
+ if (process.env.DEBUG || process.env.MASTRA_DEBUG) {
864
+ const prefix = this.formatPrefix("\u25E6", pc2.gray);
865
+ console.log(`${prefix} ${pc2.gray(message)}`);
866
+ }
867
+ }
868
+ spinnerChars = ["\u25D0", "\u25D3", "\u25D1", "\u25D2"];
869
+ spinnerIndex = 0;
870
+ getSpinnerChar() {
871
+ const char = this.spinnerChars[this.spinnerIndex];
872
+ this.spinnerIndex = (this.spinnerIndex + 1) % this.spinnerChars.length;
873
+ return char || "\u25D0";
874
+ }
875
+ clearLine() {
876
+ process.stdout.write("\r\x1B[K");
877
+ }
878
+ update(message) {
879
+ this.clearLine();
880
+ const prefix = this.formatPrefix(this.getSpinnerChar(), pc2.cyan);
881
+ process.stdout.write(`${prefix} ${message}`);
882
+ }
883
+ };
884
+ var devLogger = new DevLogger();
765
885
  var DevBundler = class extends Bundler {
766
886
  customEnvFile;
767
887
  constructor(customEnvFile) {
@@ -887,17 +1007,17 @@ var DevBundler = class extends Bundler {
887
1007
  sourcemap: sourcemapEnabled
888
1008
  }
889
1009
  );
890
- this.logger.info("Starting watcher...");
1010
+ devLogger.info("Preparing development environment...");
891
1011
  return new Promise((resolve, reject) => {
892
1012
  const cb = (event) => {
893
1013
  if (event.code === "BUNDLE_END") {
894
- this.logger.info("Bundling finished, starting server...");
1014
+ devLogger.success("Initial bundle complete");
895
1015
  watcher.off("event", cb);
896
1016
  resolve(watcher);
897
1017
  }
898
1018
  if (event.code === "ERROR") {
899
1019
  console.log(event);
900
- this.logger.error("Bundling failed, stopping watcher...");
1020
+ devLogger.error("Bundling failed - check console for details");
901
1021
  watcher.off("event", cb);
902
1022
  reject(event);
903
1023
  }
@@ -912,11 +1032,16 @@ var DevBundler = class extends Bundler {
912
1032
  // src/commands/dev/dev.ts
913
1033
  var currentServerProcess;
914
1034
  var isRestarting = false;
1035
+ var serverStartTime;
915
1036
  var ON_ERROR_MAX_RESTARTS = 3;
916
- var startServer = async (dotMastraPath, port, env, startOptions = {}, errorRestartCount = 0) => {
1037
+ var startServer = async (dotMastraPath, {
1038
+ port,
1039
+ host
1040
+ }, env, startOptions = {}, errorRestartCount = 0) => {
917
1041
  let serverIsReady = false;
918
1042
  try {
919
- logger.info("[Mastra Dev] - Starting server...");
1043
+ serverStartTime = Date.now();
1044
+ devLogger.starting();
920
1045
  const commands = [];
921
1046
  if (startOptions.inspect) {
922
1047
  commands.push("--inspect");
@@ -945,7 +1070,7 @@ var startServer = async (dotMastraPath, port, env, startOptions = {}, errorResta
945
1070
  PORT: port.toString(),
946
1071
  MASTRA_DEFAULT_STORAGE_URL: `file:${join(dotMastraPath, "..", "mastra.db")}`
947
1072
  },
948
- stdio: ["inherit", "inherit", "inherit", "ipc"],
1073
+ stdio: ["inherit", "pipe", "pipe", "ipc"],
949
1074
  reject: false
950
1075
  });
951
1076
  if (currentServerProcess?.exitCode && currentServerProcess?.exitCode !== 0) {
@@ -956,11 +1081,29 @@ var startServer = async (dotMastraPath, port, env, startOptions = {}, errorResta
956
1081
  `Server failed to start with error: ${currentServerProcess.stderr || currentServerProcess.stdout}`
957
1082
  );
958
1083
  }
1084
+ if (currentServerProcess.stdout) {
1085
+ currentServerProcess.stdout.on("data", (data) => {
1086
+ const output = data.toString();
1087
+ if (!output.includes("Playground available") && !output.includes("\u{1F468}\u200D\u{1F4BB}") && !output.includes("Mastra API running on port")) {
1088
+ process2.stdout.write(output);
1089
+ }
1090
+ });
1091
+ }
1092
+ if (currentServerProcess.stderr) {
1093
+ currentServerProcess.stderr.on("data", (data) => {
1094
+ const output = data.toString();
1095
+ if (!output.includes("Playground available") && !output.includes("\u{1F468}\u200D\u{1F4BB}") && !output.includes("Mastra API running on port")) {
1096
+ process2.stderr.write(output);
1097
+ }
1098
+ });
1099
+ }
959
1100
  currentServerProcess.on("message", async (message) => {
960
1101
  if (message?.type === "server-ready") {
961
1102
  serverIsReady = true;
1103
+ devLogger.ready(host, port, serverStartTime);
1104
+ devLogger.watching();
962
1105
  try {
963
- await fetch(`http://localhost:${port}/__refresh`, {
1106
+ await fetch(`http://${host}:${port}/__refresh`, {
964
1107
  method: "POST",
965
1108
  headers: {
966
1109
  "Content-Type": "application/json"
@@ -969,7 +1112,7 @@ var startServer = async (dotMastraPath, port, env, startOptions = {}, errorResta
969
1112
  } catch {
970
1113
  await new Promise((resolve) => setTimeout(resolve, 1500));
971
1114
  try {
972
- await fetch(`http://localhost:${port}/__refresh`, {
1115
+ await fetch(`http://${host}:${port}/__refresh`, {
973
1116
  method: "POST",
974
1117
  headers: {
975
1118
  "Content-Type": "application/json"
@@ -982,8 +1125,11 @@ var startServer = async (dotMastraPath, port, env, startOptions = {}, errorResta
982
1125
  });
983
1126
  } catch (err) {
984
1127
  const execaError = err;
985
- if (execaError.stderr) logger.error("Server error output:", { stderr: execaError.stderr });
986
- if (execaError.stdout) logger.debug("Server output:", { stdout: execaError.stdout });
1128
+ if (execaError.stderr) {
1129
+ devLogger.serverError(execaError.stderr);
1130
+ devLogger.debug(`Server error output: ${execaError.stderr}`);
1131
+ }
1132
+ if (execaError.stdout) devLogger.debug(`Server output: ${execaError.stdout}`);
987
1133
  if (!serverIsReady) {
988
1134
  throw err;
989
1135
  }
@@ -991,29 +1137,50 @@ var startServer = async (dotMastraPath, port, env, startOptions = {}, errorResta
991
1137
  if (!isRestarting) {
992
1138
  errorRestartCount++;
993
1139
  if (errorRestartCount > ON_ERROR_MAX_RESTARTS) {
994
- logger.error(`Server failed to start after ${ON_ERROR_MAX_RESTARTS} error attempts. Giving up.`);
1140
+ devLogger.error(`Server failed to start after ${ON_ERROR_MAX_RESTARTS} error attempts. Giving up.`);
995
1141
  process2.exit(1);
996
1142
  }
997
- logger.error(
1143
+ devLogger.warn(
998
1144
  `Attempting to restart server after error... (Attempt ${errorRestartCount}/${ON_ERROR_MAX_RESTARTS})`
999
1145
  );
1000
- startServer(dotMastraPath, port, env, startOptions, errorRestartCount);
1146
+ startServer(
1147
+ dotMastraPath,
1148
+ {
1149
+ port,
1150
+ host
1151
+ },
1152
+ env,
1153
+ startOptions,
1154
+ errorRestartCount
1155
+ );
1001
1156
  }
1002
1157
  }, 1e3);
1003
1158
  }
1004
1159
  };
1005
- async function rebundleAndRestart(dotMastraPath, port, bundler, startOptions = {}) {
1160
+ async function rebundleAndRestart(dotMastraPath, {
1161
+ port,
1162
+ host
1163
+ }, bundler, startOptions = {}) {
1006
1164
  if (isRestarting) {
1007
1165
  return;
1008
1166
  }
1009
1167
  isRestarting = true;
1010
1168
  try {
1011
1169
  if (currentServerProcess) {
1012
- logger.debug("Stopping current server...");
1170
+ devLogger.restarting();
1171
+ devLogger.debug("Stopping current server...");
1013
1172
  currentServerProcess.kill("SIGINT");
1014
1173
  }
1015
1174
  const env = await bundler.loadEnvVars();
1016
- await startServer(join(dotMastraPath, "output"), port, env, startOptions);
1175
+ await startServer(
1176
+ join(dotMastraPath, "output"),
1177
+ {
1178
+ port,
1179
+ host
1180
+ },
1181
+ env,
1182
+ startOptions
1183
+ );
1017
1184
  } finally {
1018
1185
  isRestarting = false;
1019
1186
  }
@@ -1045,6 +1212,7 @@ async function dev({
1045
1212
  bundler.__setLogger(logger);
1046
1213
  const serverOptions = await getServerOptions(entryFile, join(dotMastraPath, "output"));
1047
1214
  let portToUse = port ?? serverOptions?.port ?? process2.env.PORT;
1215
+ let hostToUse = serverOptions?.host ?? process2.env.HOST ?? "localhost";
1048
1216
  if (!portToUse || isNaN(Number(portToUse))) {
1049
1217
  const portList = Array.from({ length: 21 }, (_, i) => 4111 + i);
1050
1218
  portToUse = String(
@@ -1059,22 +1227,40 @@ async function dev({
1059
1227
  for (const [key, value] of loadedEnv.entries()) {
1060
1228
  process2.env[key] = value;
1061
1229
  }
1062
- await startServer(join(dotMastraPath, "output"), Number(portToUse), loadedEnv, startOptions);
1230
+ await startServer(
1231
+ join(dotMastraPath, "output"),
1232
+ {
1233
+ port: Number(portToUse),
1234
+ host: hostToUse
1235
+ },
1236
+ loadedEnv,
1237
+ startOptions
1238
+ );
1063
1239
  watcher.on("event", (event) => {
1240
+ if (event.code === "BUNDLE_START") {
1241
+ devLogger.bundling();
1242
+ }
1064
1243
  if (event.code === "BUNDLE_END") {
1065
- logger.info("[Mastra Dev] - Bundling finished, restarting server...");
1066
- rebundleAndRestart(dotMastraPath, Number(portToUse), bundler, startOptions);
1244
+ devLogger.bundleComplete();
1245
+ devLogger.info("Bundling finished, restarting server...");
1246
+ rebundleAndRestart(
1247
+ dotMastraPath,
1248
+ {
1249
+ port: Number(portToUse),
1250
+ host: hostToUse
1251
+ },
1252
+ bundler,
1253
+ startOptions
1254
+ );
1067
1255
  }
1068
1256
  });
1069
1257
  process2.on("SIGINT", () => {
1070
- logger.info("[Mastra Dev] - Stopping server...");
1258
+ devLogger.shutdown();
1071
1259
  if (currentServerProcess) {
1072
1260
  currentServerProcess.kill();
1073
1261
  }
1074
1262
  watcher.close().catch(() => {
1075
- }).finally(() => {
1076
- process2.exit(0);
1077
- });
1263
+ }).finally(() => process2.exit(0));
1078
1264
  });
1079
1265
  }
1080
1266
 
@@ -1156,8 +1342,8 @@ var startProject = async (args) => {
1156
1342
  };
1157
1343
 
1158
1344
  // src/index.ts
1159
- var depsService = new DepsService();
1160
- var version = await depsService.getPackageVersion();
1345
+ var mastraPkg = package_default;
1346
+ var version = mastraPkg.version;
1161
1347
  var analytics = new PosthogAnalytics({
1162
1348
  apiKey: "phc_SBLpZVAB6jmHOct9CABq3PF0Yn5FU3G2FgT4xUr2XrT",
1163
1349
  host: "https://us.posthog.com",
@@ -1169,7 +1355,7 @@ var origin2 = process.env.MASTRA_ANALYTICS_ORIGIN;
1169
1355
  program.name("mastra").version(`${version}`, "-v, --version").addHelpText(
1170
1356
  "before",
1171
1357
  `
1172
- ${color.bold(color.cyan("Mastra"))} is a typescript framework for building AI applications, agents, and workflows.
1358
+ ${pc2.bold(pc2.cyan("Mastra"))} is a typescript framework for building AI applications, agents, and workflows.
1173
1359
  `
1174
1360
  ).action(() => {
1175
1361
  program.help();
@@ -1195,6 +1381,6 @@ scorersCommand.command("add [scorer-name]").description("Add a new scorer to you
1195
1381
  scorersCommand.command("list").description("List available scorer templates").action(listScorers);
1196
1382
  program.parse(process.argv);
1197
1383
 
1198
- export { analytics, origin2 as origin };
1384
+ export { analytics, origin2 as origin, version };
1199
1385
  //# sourceMappingURL=index.js.map
1200
1386
  //# sourceMappingURL=index.js.map