@mastra/deployer 1.0.0-beta.14 → 1.0.0-beta.16

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.
Files changed (63) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/dist/build/analyze/analyzeEntry.d.ts.map +1 -1
  3. package/dist/build/analyze.cjs +2 -2
  4. package/dist/build/analyze.js +1 -1
  5. package/dist/build/babel/remove-deployer.d.ts.map +1 -1
  6. package/dist/build/bundler.cjs +3 -3
  7. package/dist/build/bundler.d.ts.map +1 -1
  8. package/dist/build/bundler.js +1 -1
  9. package/dist/build/bundlerOptions.d.ts.map +1 -1
  10. package/dist/build/deployer.d.ts.map +1 -1
  11. package/dist/build/index.cjs +10 -10
  12. package/dist/build/index.js +3 -3
  13. package/dist/build/plugins/node-modules-extension-resolver.d.ts.map +1 -1
  14. package/dist/build/plugins/remove-all-except.d.ts +10 -0
  15. package/dist/build/plugins/remove-all-except.d.ts.map +1 -0
  16. package/dist/build/serverOptions.d.ts.map +1 -1
  17. package/dist/build/shared/extract-mastra-option.d.ts +4 -8
  18. package/dist/build/shared/extract-mastra-option.d.ts.map +1 -1
  19. package/dist/bundler/index.cjs +3 -3
  20. package/dist/bundler/index.d.ts.map +1 -1
  21. package/dist/bundler/index.js +1 -1
  22. package/dist/{chunk-IVKDKRCR.cjs → chunk-7F6JKGX4.cjs} +20 -12
  23. package/dist/chunk-7F6JKGX4.cjs.map +1 -0
  24. package/dist/{chunk-HNSVE6YO.js → chunk-BDA7RMRF.js} +191 -171
  25. package/dist/chunk-BDA7RMRF.js.map +1 -0
  26. package/dist/{chunk-UJXH5MNH.cjs → chunk-CRIOGWZD.cjs} +190 -171
  27. package/dist/chunk-CRIOGWZD.cjs.map +1 -0
  28. package/dist/{chunk-ZXT4NSIV.js → chunk-ESR6AK5N.js} +14 -6
  29. package/dist/chunk-ESR6AK5N.js.map +1 -0
  30. package/dist/{chunk-V5W7WIXT.cjs → chunk-HRCR6OKC.cjs} +11 -22
  31. package/dist/chunk-HRCR6OKC.cjs.map +1 -0
  32. package/dist/{chunk-C6UFSG3V.js → chunk-ONWHS3PA.js} +34 -79
  33. package/dist/chunk-ONWHS3PA.js.map +1 -0
  34. package/dist/{chunk-PB5O2NTZ.cjs → chunk-OVVUJ46G.cjs} +39 -85
  35. package/dist/chunk-OVVUJ46G.cjs.map +1 -0
  36. package/dist/{chunk-BFA354MH.js → chunk-WFIG7I5C.js} +5 -16
  37. package/dist/chunk-WFIG7I5C.js.map +1 -0
  38. package/dist/index.cjs +4 -15
  39. package/dist/index.cjs.map +1 -1
  40. package/dist/index.js +3 -14
  41. package/dist/index.js.map +1 -1
  42. package/dist/server/index.cjs +269 -15
  43. package/dist/server/index.cjs.map +1 -1
  44. package/dist/server/index.d.ts.map +1 -1
  45. package/dist/server/index.js +267 -13
  46. package/dist/server/index.js.map +1 -1
  47. package/package.json +6 -6
  48. package/dist/build/babel/get-deployer.d.ts +0 -3
  49. package/dist/build/babel/get-deployer.d.ts.map +0 -1
  50. package/dist/build/babel/remove-all-options-bundler.d.ts +0 -5
  51. package/dist/build/babel/remove-all-options-bundler.d.ts.map +0 -1
  52. package/dist/build/babel/remove-all-options-deployer.d.ts +0 -5
  53. package/dist/build/babel/remove-all-options-deployer.d.ts.map +0 -1
  54. package/dist/build/babel/remove-all-options-server.d.ts +0 -5
  55. package/dist/build/babel/remove-all-options-server.d.ts.map +0 -1
  56. package/dist/chunk-BFA354MH.js.map +0 -1
  57. package/dist/chunk-C6UFSG3V.js.map +0 -1
  58. package/dist/chunk-HNSVE6YO.js.map +0 -1
  59. package/dist/chunk-IVKDKRCR.cjs.map +0 -1
  60. package/dist/chunk-PB5O2NTZ.cjs.map +0 -1
  61. package/dist/chunk-UJXH5MNH.cjs.map +0 -1
  62. package/dist/chunk-V5W7WIXT.cjs.map +0 -1
  63. package/dist/chunk-ZXT4NSIV.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRo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CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,wCAmB/D;AAED,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,mBAER;cAGgC,QAAQ;eAAa,SAAS;2CA2ShE;AAED,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAmC,mDAqDlG"}
@@ -1,16 +1,16 @@
1
1
  import { normalizeStudioBase } from '../chunk-HHA2Y3AS.js';
2
2
  import { readFile } from 'fs/promises';
3
3
  import * as https from 'https';
4
- import { join } from 'path/posix';
4
+ import { join } from 'path';
5
5
  import { createServer } from 'http';
6
6
  import { Http2ServerRequest } from 'http2';
7
7
  import { Writable, Readable } from 'stream';
8
8
  import crypto from 'crypto';
9
9
  import { getMimeType } from 'hono/utils/mime';
10
10
  import { existsSync, createReadStream, lstatSync } from 'fs';
11
- import { join as join$1 } from 'path';
12
11
  import { html } from 'hono/html';
13
12
  import { Tool } from '@mastra/core/tools';
13
+ import { formatZodError } from '@mastra/server/handlers/error';
14
14
  import { MastraServer as MastraServer$1, redactStreamChunk } from '@mastra/server/server-adapter';
15
15
  import util from 'util';
16
16
  import { Buffer as Buffer$1 } from 'buffer';
@@ -628,14 +628,14 @@ var serveStatic = (options = { root: "" }) => {
628
628
  return next();
629
629
  }
630
630
  }
631
- let path = join$1(
631
+ let path = join(
632
632
  root,
633
633
  !optionPath && options.rewriteRequestPath ? options.rewriteRequestPath(filename, c) : filename
634
634
  );
635
635
  let stats = getStats(path);
636
636
  if (stats && stats.isDirectory()) {
637
637
  const indexFile = options.index ?? "index.html";
638
- path = join$1(path, indexFile);
638
+ path = join(path, indexFile);
639
639
  stats = getStats(path);
640
640
  }
641
641
  if (!stats) {
@@ -2842,6 +2842,209 @@ var stream = (c, cb, onError3) => {
2842
2842
  })();
2843
2843
  return c.newResponse(stream2.responseReadable);
2844
2844
  };
2845
+ var util2;
2846
+ (function(util22) {
2847
+ util22.assertEqual = (_) => {
2848
+ };
2849
+ function assertIs(_arg) {
2850
+ }
2851
+ util22.assertIs = assertIs;
2852
+ function assertNever(_x) {
2853
+ throw new Error();
2854
+ }
2855
+ util22.assertNever = assertNever;
2856
+ util22.arrayToEnum = (items) => {
2857
+ const obj = {};
2858
+ for (const item of items) {
2859
+ obj[item] = item;
2860
+ }
2861
+ return obj;
2862
+ };
2863
+ util22.getValidEnumValues = (obj) => {
2864
+ const validKeys = util22.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
2865
+ const filtered = {};
2866
+ for (const k of validKeys) {
2867
+ filtered[k] = obj[k];
2868
+ }
2869
+ return util22.objectValues(filtered);
2870
+ };
2871
+ util22.objectValues = (obj) => {
2872
+ return util22.objectKeys(obj).map(function(e) {
2873
+ return obj[e];
2874
+ });
2875
+ };
2876
+ util22.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
2877
+ const keys = [];
2878
+ for (const key in object) {
2879
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
2880
+ keys.push(key);
2881
+ }
2882
+ }
2883
+ return keys;
2884
+ };
2885
+ util22.find = (arr, checker) => {
2886
+ for (const item of arr) {
2887
+ if (checker(item))
2888
+ return item;
2889
+ }
2890
+ return void 0;
2891
+ };
2892
+ util22.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
2893
+ function joinValues(array, separator = " | ") {
2894
+ return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
2895
+ }
2896
+ util22.joinValues = joinValues;
2897
+ util22.jsonStringifyReplacer = (_, value) => {
2898
+ if (typeof value === "bigint") {
2899
+ return value.toString();
2900
+ }
2901
+ return value;
2902
+ };
2903
+ })(util2 || (util2 = {}));
2904
+ var objectUtil;
2905
+ (function(objectUtil2) {
2906
+ objectUtil2.mergeShapes = (first, second) => {
2907
+ return {
2908
+ ...first,
2909
+ ...second
2910
+ // second overwrites first
2911
+ };
2912
+ };
2913
+ })(objectUtil || (objectUtil = {}));
2914
+ util2.arrayToEnum([
2915
+ "string",
2916
+ "nan",
2917
+ "number",
2918
+ "integer",
2919
+ "float",
2920
+ "boolean",
2921
+ "date",
2922
+ "bigint",
2923
+ "symbol",
2924
+ "function",
2925
+ "undefined",
2926
+ "null",
2927
+ "array",
2928
+ "object",
2929
+ "unknown",
2930
+ "promise",
2931
+ "void",
2932
+ "never",
2933
+ "map",
2934
+ "set"
2935
+ ]);
2936
+ util2.arrayToEnum([
2937
+ "invalid_type",
2938
+ "invalid_literal",
2939
+ "custom",
2940
+ "invalid_union",
2941
+ "invalid_union_discriminator",
2942
+ "invalid_enum_value",
2943
+ "unrecognized_keys",
2944
+ "invalid_arguments",
2945
+ "invalid_return_type",
2946
+ "invalid_date",
2947
+ "invalid_string",
2948
+ "too_small",
2949
+ "too_big",
2950
+ "invalid_intersection_types",
2951
+ "not_multiple_of",
2952
+ "not_finite"
2953
+ ]);
2954
+ var ZodError = class _ZodError extends Error {
2955
+ get errors() {
2956
+ return this.issues;
2957
+ }
2958
+ constructor(issues) {
2959
+ super();
2960
+ this.issues = [];
2961
+ this.addIssue = (sub) => {
2962
+ this.issues = [...this.issues, sub];
2963
+ };
2964
+ this.addIssues = (subs = []) => {
2965
+ this.issues = [...this.issues, ...subs];
2966
+ };
2967
+ const actualProto = new.target.prototype;
2968
+ if (Object.setPrototypeOf) {
2969
+ Object.setPrototypeOf(this, actualProto);
2970
+ } else {
2971
+ this.__proto__ = actualProto;
2972
+ }
2973
+ this.name = "ZodError";
2974
+ this.issues = issues;
2975
+ }
2976
+ format(_mapper) {
2977
+ const mapper = _mapper || function(issue) {
2978
+ return issue.message;
2979
+ };
2980
+ const fieldErrors = { _errors: [] };
2981
+ const processError = (error) => {
2982
+ for (const issue of error.issues) {
2983
+ if (issue.code === "invalid_union") {
2984
+ issue.unionErrors.map(processError);
2985
+ } else if (issue.code === "invalid_return_type") {
2986
+ processError(issue.returnTypeError);
2987
+ } else if (issue.code === "invalid_arguments") {
2988
+ processError(issue.argumentsError);
2989
+ } else if (issue.path.length === 0) {
2990
+ fieldErrors._errors.push(mapper(issue));
2991
+ } else {
2992
+ let curr = fieldErrors;
2993
+ let i = 0;
2994
+ while (i < issue.path.length) {
2995
+ const el = issue.path[i];
2996
+ const terminal = i === issue.path.length - 1;
2997
+ if (!terminal) {
2998
+ curr[el] = curr[el] || { _errors: [] };
2999
+ } else {
3000
+ curr[el] = curr[el] || { _errors: [] };
3001
+ curr[el]._errors.push(mapper(issue));
3002
+ }
3003
+ curr = curr[el];
3004
+ i++;
3005
+ }
3006
+ }
3007
+ }
3008
+ };
3009
+ processError(this);
3010
+ return fieldErrors;
3011
+ }
3012
+ static assert(value) {
3013
+ if (!(value instanceof _ZodError)) {
3014
+ throw new Error(`Not a ZodError: ${value}`);
3015
+ }
3016
+ }
3017
+ toString() {
3018
+ return this.message;
3019
+ }
3020
+ get message() {
3021
+ return JSON.stringify(this.issues, util2.jsonStringifyReplacer, 2);
3022
+ }
3023
+ get isEmpty() {
3024
+ return this.issues.length === 0;
3025
+ }
3026
+ flatten(mapper = (issue) => issue.message) {
3027
+ const fieldErrors = {};
3028
+ const formErrors = [];
3029
+ for (const sub of this.issues) {
3030
+ if (sub.path.length > 0) {
3031
+ const firstEl = sub.path[0];
3032
+ fieldErrors[firstEl] = fieldErrors[firstEl] || [];
3033
+ fieldErrors[firstEl].push(mapper(sub));
3034
+ } else {
3035
+ formErrors.push(mapper(sub));
3036
+ }
3037
+ }
3038
+ return { formErrors, fieldErrors };
3039
+ }
3040
+ get formErrors() {
3041
+ return this.flatten();
3042
+ }
3043
+ };
3044
+ ZodError.create = (issues) => {
3045
+ const error = new ZodError(issues);
3046
+ return error;
3047
+ };
2845
3048
  var authenticationMiddleware = async (c, next) => {
2846
3049
  const mastra = c.get("mastra");
2847
3050
  const authConfig = mastra.getServer()?.auth;
@@ -3035,13 +3238,48 @@ var MastraServer = class extends MastraServer$1 {
3035
3238
  const queryParams = request.query();
3036
3239
  let body;
3037
3240
  if (route.method === "POST" || route.method === "PUT" || route.method === "PATCH") {
3038
- try {
3039
- body = await request.json();
3040
- } catch {
3241
+ const contentType = request.header("content-type") || "";
3242
+ if (contentType.includes("multipart/form-data")) {
3243
+ try {
3244
+ const formData = await request.formData();
3245
+ body = await this.parseFormData(formData);
3246
+ } catch (error) {
3247
+ console.error("Failed to parse multipart form data:", error);
3248
+ if (error instanceof Error && error.message.toLowerCase().includes("size")) {
3249
+ throw error;
3250
+ }
3251
+ }
3252
+ } else {
3253
+ try {
3254
+ body = await request.json();
3255
+ } catch (error) {
3256
+ console.error("Failed to parse JSON body:", error);
3257
+ }
3041
3258
  }
3042
3259
  }
3043
3260
  return { urlParams, queryParams, body };
3044
3261
  }
3262
+ /**
3263
+ * Parse FormData into a plain object, converting File objects to Buffers.
3264
+ */
3265
+ async parseFormData(formData) {
3266
+ const result = {};
3267
+ for (const [key, value] of formData.entries()) {
3268
+ if (value instanceof File) {
3269
+ const arrayBuffer = await value.arrayBuffer();
3270
+ result[key] = Buffer.from(arrayBuffer);
3271
+ } else if (typeof value === "string") {
3272
+ try {
3273
+ result[key] = JSON.parse(value);
3274
+ } catch {
3275
+ result[key] = value;
3276
+ }
3277
+ } else {
3278
+ result[key] = value;
3279
+ }
3280
+ }
3281
+ return result;
3282
+ }
3045
3283
  async sendResponse(route, response, result) {
3046
3284
  if (route.responseType === "json") {
3047
3285
  return response.json(result, 200);
@@ -3113,10 +3351,13 @@ var MastraServer = class extends MastraServer$1 {
3113
3351
  params.queryParams = await this.parseQueryParams(route, params.queryParams);
3114
3352
  } catch (error) {
3115
3353
  console.error("Error parsing query params", error);
3354
+ if (error instanceof ZodError) {
3355
+ return c.json(formatZodError(error, "query parameters"), 400);
3356
+ }
3116
3357
  return c.json(
3117
3358
  {
3118
3359
  error: "Invalid query parameters",
3119
- details: error instanceof Error ? error.message : "Unknown error"
3360
+ issues: [{ field: "unknown", message: error instanceof Error ? error.message : "Unknown error" }]
3120
3361
  },
3121
3362
  400
3122
3363
  );
@@ -3127,10 +3368,13 @@ var MastraServer = class extends MastraServer$1 {
3127
3368
  params.body = await this.parseBody(route, params.body);
3128
3369
  } catch (error) {
3129
3370
  console.error("Error parsing body:", error instanceof Error ? error.message : String(error));
3371
+ if (error instanceof ZodError) {
3372
+ return c.json(formatZodError(error, "request body"), 400);
3373
+ }
3130
3374
  return c.json(
3131
3375
  {
3132
3376
  error: "Invalid request body",
3133
- details: error instanceof Error ? error.message : "Unknown error"
3377
+ issues: [{ field: "unknown", message: error instanceof Error ? error.message : "Unknown error" }]
3134
3378
  },
3135
3379
  400
3136
3380
  );
@@ -3369,6 +3613,7 @@ var html2 = `
3369
3613
  `;
3370
3614
 
3371
3615
  // src/server/index.ts
3616
+ var getStudioPath = () => process.env.MASTRA_STUDIO_PATH || "./playground";
3372
3617
  function getToolExports(tools) {
3373
3618
  try {
3374
3619
  return tools.reduce((acc, toolModule) => {
@@ -3404,7 +3649,13 @@ async function createHonoServer(mastra, options = {
3404
3649
  customRouteAuthConfig.set(routeKey, requiresAuth);
3405
3650
  }
3406
3651
  }
3407
- app.onError((err, c) => errorHandler(err, c, options.isDev));
3652
+ const customOnError = server?.onError;
3653
+ app.onError((err, c) => {
3654
+ if (customOnError) {
3655
+ return customOnError(err, c);
3656
+ }
3657
+ return errorHandler(err, c, options.isDev);
3658
+ });
3408
3659
  const bodyLimitOptions = {
3409
3660
  maxSize: server?.bodySizeLimit ?? 4.5 * 1024 * 1024,
3410
3661
  // 4.5 MB,
@@ -3545,10 +3796,11 @@ async function createHonoServer(mastra, options = {
3545
3796
  });
3546
3797
  }
3547
3798
  );
3799
+ const studioPath = getStudioPath();
3548
3800
  app.use(
3549
3801
  `${studioBasePath}/assets/*`,
3550
3802
  serveStatic({
3551
- root: "./playground/assets",
3803
+ root: join(studioPath, "assets"),
3552
3804
  rewriteRequestPath: (path) => {
3553
3805
  let rewritten = path;
3554
3806
  if (studioBasePath && rewritten.startsWith(studioBasePath)) {
@@ -3572,7 +3824,8 @@ async function createHonoServer(mastra, options = {
3572
3824
  }
3573
3825
  const isPlaygroundRoute = studioBasePath === "" || requestPath === studioBasePath || requestPath.startsWith(`${studioBasePath}/`);
3574
3826
  if (options?.playground && isPlaygroundRoute) {
3575
- let indexHtml = await readFile(join(process.cwd(), "./playground/index.html"), "utf-8");
3827
+ const studioPath = getStudioPath();
3828
+ let indexHtml = await readFile(join(studioPath, "index.html"), "utf-8");
3576
3829
  const port = serverOptions?.port ?? (Number(process.env.PORT) || 4111);
3577
3830
  const hideCloudCta = process.env.MASTRA_HIDE_CLOUD_CTA === "true";
3578
3831
  const host = serverOptions?.host ?? "localhost";
@@ -3589,11 +3842,12 @@ async function createHonoServer(mastra, options = {
3589
3842
  return c.newResponse(html2, 200, { "Content-Type": "text/html" });
3590
3843
  });
3591
3844
  if (options?.playground) {
3845
+ const studioPath = getStudioPath();
3592
3846
  const playgroundPath = studioBasePath ? `${studioBasePath}/*` : "*";
3593
3847
  app.use(
3594
3848
  playgroundPath,
3595
3849
  serveStatic({
3596
- root: "./playground",
3850
+ root: studioPath,
3597
3851
  rewriteRequestPath: (path) => {
3598
3852
  if (studioBasePath && path.startsWith(studioBasePath)) {
3599
3853
  return path.slice(studioBasePath.length);