@mastra/deployer 1.0.0-beta.8 → 1.0.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.
Files changed (183) hide show
  1. package/CHANGELOG.md +805 -0
  2. package/dist/arktype-aI7TBD0R-CCZH3EYK.js +8 -0
  3. package/dist/{arktype-aI7TBD0R-JG4WETGU.js.map → arktype-aI7TBD0R-CCZH3EYK.js.map} +1 -1
  4. package/dist/{arktype-aI7TBD0R-RMRB5ZNY.cjs → arktype-aI7TBD0R-XHBHUL3T.cjs} +3 -3
  5. package/dist/{arktype-aI7TBD0R-RMRB5ZNY.cjs.map → arktype-aI7TBD0R-XHBHUL3T.cjs.map} +1 -1
  6. package/dist/build/analyze/analyzeEntry.d.ts.map +1 -1
  7. package/dist/build/analyze/bundleExternals.d.ts +4 -5
  8. package/dist/build/analyze/bundleExternals.d.ts.map +1 -1
  9. package/dist/build/analyze.cjs +2 -2
  10. package/dist/build/analyze.d.ts +5 -5
  11. package/dist/build/analyze.d.ts.map +1 -1
  12. package/dist/build/analyze.js +1 -1
  13. package/dist/build/babel/remove-deployer.d.ts.map +1 -1
  14. package/dist/build/bundler.cjs +3 -3
  15. package/dist/build/bundler.d.ts +3 -1
  16. package/dist/build/bundler.d.ts.map +1 -1
  17. package/dist/build/bundler.js +1 -1
  18. package/dist/build/bundlerOptions.d.ts.map +1 -1
  19. package/dist/build/deployer.d.ts.map +1 -1
  20. package/dist/build/index.cjs +19 -10
  21. package/dist/build/index.d.ts +2 -0
  22. package/dist/build/index.d.ts.map +1 -1
  23. package/dist/build/index.js +4 -3
  24. package/dist/build/package-info.d.ts +9 -0
  25. package/dist/build/package-info.d.ts.map +1 -0
  26. package/dist/build/plugins/node-modules-extension-resolver.d.ts +7 -0
  27. package/dist/build/plugins/node-modules-extension-resolver.d.ts.map +1 -1
  28. package/dist/build/plugins/remove-all-except.d.ts +10 -0
  29. package/dist/build/plugins/remove-all-except.d.ts.map +1 -0
  30. package/dist/build/plugins/tsconfig-paths.d.ts +1 -1
  31. package/dist/build/plugins/tsconfig-paths.d.ts.map +1 -1
  32. package/dist/build/serverOptions.d.ts.map +1 -1
  33. package/dist/build/shared/extract-mastra-option.d.ts +4 -8
  34. package/dist/build/shared/extract-mastra-option.d.ts.map +1 -1
  35. package/dist/build/types.d.ts +5 -0
  36. package/dist/build/types.d.ts.map +1 -1
  37. package/dist/build/utils.d.ts +35 -4
  38. package/dist/build/utils.d.ts.map +1 -1
  39. package/dist/build/watcher.d.ts +2 -1
  40. package/dist/build/watcher.d.ts.map +1 -1
  41. package/dist/bundler/index.cjs +6 -2
  42. package/dist/bundler/index.d.ts +10 -7
  43. package/dist/bundler/index.d.ts.map +1 -1
  44. package/dist/bundler/index.js +1 -1
  45. package/dist/chunk-2VG357HT.cjs +4 -0
  46. package/dist/{chunk-4YYZKC2P.cjs.map → chunk-2VG357HT.cjs.map} +1 -1
  47. package/dist/chunk-5FPJTHRK.js +88 -0
  48. package/dist/chunk-5FPJTHRK.js.map +1 -0
  49. package/dist/{chunk-2OTEFUER.cjs → chunk-5TYVF4KJ.cjs} +31 -24
  50. package/dist/chunk-5TYVF4KJ.cjs.map +1 -0
  51. package/dist/{chunk-3NVSKU27.cjs → chunk-7EPD2XJR.cjs} +76 -20
  52. package/dist/chunk-7EPD2XJR.cjs.map +1 -0
  53. package/dist/{chunk-46SXOVGO.js → chunk-DBXWQ2CA.js} +10 -10
  54. package/dist/chunk-DBXWQ2CA.js.map +1 -0
  55. package/dist/chunk-G6GFAPPU.js +6 -0
  56. package/dist/{chunk-PDVYEX76.js.map → chunk-G6GFAPPU.js.map} +1 -1
  57. package/dist/chunk-GU4OME5Q.cjs +112 -0
  58. package/dist/chunk-GU4OME5Q.cjs.map +1 -0
  59. package/dist/chunk-HPGDVJAZ.js +3 -0
  60. package/dist/{chunk-HXYLK6CH.js.map → chunk-HPGDVJAZ.js.map} +1 -1
  61. package/dist/{chunk-I47TD6VX.js → chunk-HWSYWSD7.js} +279 -191
  62. package/dist/chunk-HWSYWSD7.js.map +1 -0
  63. package/dist/{chunk-IR2ZJ7CP.cjs → chunk-JBE6KM7R.cjs} +3 -3
  64. package/dist/{chunk-IR2ZJ7CP.cjs.map → chunk-JBE6KM7R.cjs.map} +1 -1
  65. package/dist/{chunk-NZ47MQSD.cjs → chunk-JRUJ546M.cjs} +10 -10
  66. package/dist/chunk-JRUJ546M.cjs.map +1 -0
  67. package/dist/{chunk-IL36YSXF.cjs → chunk-KE4NVPI4.cjs} +3 -3
  68. package/dist/{chunk-IL36YSXF.cjs.map → chunk-KE4NVPI4.cjs.map} +1 -1
  69. package/dist/chunk-MCWU6IKS.js +14 -0
  70. package/dist/{chunk-L4SN27ZE.js.map → chunk-MCWU6IKS.js.map} +1 -1
  71. package/dist/{chunk-HGMQ75WR.js → chunk-NGQZZ54Y.js} +68 -13
  72. package/dist/chunk-NGQZZ54Y.js.map +1 -0
  73. package/dist/chunk-QAOUDKHK.js +67 -0
  74. package/dist/chunk-QAOUDKHK.js.map +1 -0
  75. package/dist/{chunk-IJ2JJVRX.js → chunk-SD6NHZ2H.js} +47 -28
  76. package/dist/chunk-SD6NHZ2H.js.map +1 -0
  77. package/dist/{chunk-SYGG6SXN.cjs → chunk-T7NCLSYN.cjs} +298 -210
  78. package/dist/chunk-T7NCLSYN.cjs.map +1 -0
  79. package/dist/{chunk-2NO5NO4J.js → chunk-V4HCIN6G.js} +3 -3
  80. package/dist/{chunk-2NO5NO4J.js.map → chunk-V4HCIN6G.js.map} +1 -1
  81. package/dist/{chunk-UEEYA5FR.cjs → chunk-VOI3B5MX.cjs} +54 -34
  82. package/dist/chunk-VOI3B5MX.cjs.map +1 -0
  83. package/dist/chunk-ZXQ7DOYU.cjs +16 -0
  84. package/dist/{chunk-BJURVMEW.cjs.map → chunk-ZXQ7DOYU.cjs.map} +1 -1
  85. package/dist/default-u_dwuiYb-JPNIZQKK.cjs +9 -0
  86. package/dist/{default-u_dwuiYb-WPBHZH2R.cjs.map → default-u_dwuiYb-JPNIZQKK.cjs.map} +1 -1
  87. package/dist/default-u_dwuiYb-RK5OD4MY.js +3 -0
  88. package/dist/{default-u_dwuiYb-MRYQILW4.js.map → default-u_dwuiYb-RK5OD4MY.js.map} +1 -1
  89. package/dist/docs/README.md +32 -0
  90. package/dist/docs/SKILL.md +36 -0
  91. package/dist/docs/SOURCE_MAP.json +27 -0
  92. package/dist/docs/deployer/01-reference.md +93 -0
  93. package/dist/docs/deployment/01-overview.md +64 -0
  94. package/dist/docs/deployment/02-mastra-server.md +129 -0
  95. package/dist/docs/deployment/03-monorepo.md +142 -0
  96. package/dist/docs/deployment/04-cloud-providers.md +17 -0
  97. package/dist/docs/deployment/05-web-framework.md +55 -0
  98. package/dist/docs/deployment/06-workflow-runners.md +11 -0
  99. package/dist/effect-QlVUlMFu-HN3LWZSQ.cjs +17 -0
  100. package/dist/{effect-QlVUlMFu-N7VAYT2B.cjs.map → effect-QlVUlMFu-HN3LWZSQ.cjs.map} +1 -1
  101. package/dist/{effect-QlVUlMFu-NH625H3V.js → effect-QlVUlMFu-XOJ2F4UA.js} +4 -4
  102. package/dist/{effect-QlVUlMFu-NH625H3V.js.map → effect-QlVUlMFu-XOJ2F4UA.js.map} +1 -1
  103. package/dist/{esm-T7FR74HN.js → esm-6TGK2CUM.js} +41 -41
  104. package/dist/esm-6TGK2CUM.js.map +1 -0
  105. package/dist/{esm-BZAOWJTI.cjs → esm-SQKX5ABS.cjs} +82 -82
  106. package/dist/esm-SQKX5ABS.cjs.map +1 -0
  107. package/dist/index.cjs +4 -15
  108. package/dist/index.cjs.map +1 -1
  109. package/dist/index.js +3 -14
  110. package/dist/index.js.map +1 -1
  111. package/dist/server/index.cjs +523 -87
  112. package/dist/server/index.cjs.map +1 -1
  113. package/dist/server/index.d.ts.map +1 -1
  114. package/dist/server/index.js +521 -86
  115. package/dist/server/index.js.map +1 -1
  116. package/dist/server/types.d.ts +1 -1
  117. package/dist/server/types.d.ts.map +1 -1
  118. package/dist/sury-CWZTCd75-KEHKUXG7.cjs +17 -0
  119. package/dist/{sury-CWZTCd75-E5BDQIXB.cjs.map → sury-CWZTCd75-KEHKUXG7.cjs.map} +1 -1
  120. package/dist/{sury-CWZTCd75-HWBNYVQW.js → sury-CWZTCd75-L2D76L25.js} +4 -4
  121. package/dist/{sury-CWZTCd75-HWBNYVQW.js.map → sury-CWZTCd75-L2D76L25.js.map} +1 -1
  122. package/dist/typebox-Dei93FPO-LBLFC3RD.js +8 -0
  123. package/dist/{typebox-Dei93FPO-XXPZXWWK.js.map → typebox-Dei93FPO-LBLFC3RD.js.map} +1 -1
  124. package/dist/{typebox-Dei93FPO-42ICWLXF.cjs → typebox-Dei93FPO-RDSW6DFA.cjs} +3 -3
  125. package/dist/{typebox-Dei93FPO-42ICWLXF.cjs.map → typebox-Dei93FPO-RDSW6DFA.cjs.map} +1 -1
  126. package/dist/valibot--1zFm7rT-NVADAEQI.cjs +17 -0
  127. package/dist/{valibot--1zFm7rT-ALWQ34TP.cjs.map → valibot--1zFm7rT-NVADAEQI.cjs.map} +1 -1
  128. package/dist/{valibot--1zFm7rT-W6DSEVCL.js → valibot--1zFm7rT-R2UKWLZC.js} +4 -4
  129. package/dist/{valibot--1zFm7rT-W6DSEVCL.js.map → valibot--1zFm7rT-R2UKWLZC.js.map} +1 -1
  130. package/dist/{valibot-D_HTw1Gn-PN7GEV4F.cjs → valibot-D_HTw1Gn-DSFFOUBW.cjs} +7 -7
  131. package/dist/{valibot-D_HTw1Gn-PN7GEV4F.cjs.map → valibot-D_HTw1Gn-DSFFOUBW.cjs.map} +1 -1
  132. package/dist/{valibot-D_HTw1Gn-LVFT5X5F.js → valibot-D_HTw1Gn-KWXWP2TJ.js} +5 -5
  133. package/dist/{valibot-D_HTw1Gn-LVFT5X5F.js.map → valibot-D_HTw1Gn-KWXWP2TJ.js.map} +1 -1
  134. package/dist/validator/custom-resolver.cjs +2 -2
  135. package/dist/validator/custom-resolver.js +1 -1
  136. package/dist/{zod-Bwrt9trS-UDAV5VDV.js → zod-Bwrt9trS-GCUGPBJX.js} +5 -5
  137. package/dist/{zod-Bwrt9trS-UDAV5VDV.js.map → zod-Bwrt9trS-GCUGPBJX.js.map} +1 -1
  138. package/dist/{zod-Bwrt9trS-C5ATNTZG.cjs → zod-Bwrt9trS-ZZHFZ7YQ.cjs} +7 -7
  139. package/dist/{zod-Bwrt9trS-C5ATNTZG.cjs.map → zod-Bwrt9trS-ZZHFZ7YQ.cjs.map} +1 -1
  140. package/dist/{zod-DSgpEGAE-EH7N2QK7.cjs → zod-DSgpEGAE-3CMS4FSB.cjs} +7 -7
  141. package/dist/{zod-DSgpEGAE-EH7N2QK7.cjs.map → zod-DSgpEGAE-3CMS4FSB.cjs.map} +1 -1
  142. package/dist/{zod-DSgpEGAE-AVWGGTUD.js → zod-DSgpEGAE-IPE3O2NQ.js} +5 -5
  143. package/dist/{zod-DSgpEGAE-AVWGGTUD.js.map → zod-DSgpEGAE-IPE3O2NQ.js.map} +1 -1
  144. package/package.json +15 -15
  145. package/dist/arktype-aI7TBD0R-JG4WETGU.js +0 -8
  146. package/dist/build/babel/get-deployer.d.ts +0 -3
  147. package/dist/build/babel/get-deployer.d.ts.map +0 -1
  148. package/dist/build/babel/remove-all-options-bundler.d.ts +0 -5
  149. package/dist/build/babel/remove-all-options-bundler.d.ts.map +0 -1
  150. package/dist/build/babel/remove-all-options-deployer.d.ts +0 -5
  151. package/dist/build/babel/remove-all-options-deployer.d.ts.map +0 -1
  152. package/dist/build/babel/remove-all-options-server.d.ts +0 -5
  153. package/dist/build/babel/remove-all-options-server.d.ts.map +0 -1
  154. package/dist/chunk-2OTEFUER.cjs.map +0 -1
  155. package/dist/chunk-3NVSKU27.cjs.map +0 -1
  156. package/dist/chunk-46SXOVGO.js.map +0 -1
  157. package/dist/chunk-4YYZKC2P.cjs +0 -4
  158. package/dist/chunk-5CWPEG6R.js +0 -62
  159. package/dist/chunk-5CWPEG6R.js.map +0 -1
  160. package/dist/chunk-BJURVMEW.cjs +0 -16
  161. package/dist/chunk-HGMQ75WR.js.map +0 -1
  162. package/dist/chunk-HXYLK6CH.js +0 -3
  163. package/dist/chunk-I47TD6VX.js.map +0 -1
  164. package/dist/chunk-IJ2JJVRX.js.map +0 -1
  165. package/dist/chunk-KTLA3OLD.js +0 -169
  166. package/dist/chunk-KTLA3OLD.js.map +0 -1
  167. package/dist/chunk-L4SN27ZE.js +0 -14
  168. package/dist/chunk-NZ47MQSD.cjs.map +0 -1
  169. package/dist/chunk-PDVYEX76.js +0 -6
  170. package/dist/chunk-SYGG6SXN.cjs.map +0 -1
  171. package/dist/chunk-UEEYA5FR.cjs.map +0 -1
  172. package/dist/chunk-YQFLK7ZK.cjs +0 -196
  173. package/dist/chunk-YQFLK7ZK.cjs.map +0 -1
  174. package/dist/default-u_dwuiYb-MRYQILW4.js +0 -3
  175. package/dist/default-u_dwuiYb-WPBHZH2R.cjs +0 -9
  176. package/dist/effect-QlVUlMFu-N7VAYT2B.cjs +0 -17
  177. package/dist/esm-BZAOWJTI.cjs.map +0 -1
  178. package/dist/esm-T7FR74HN.js.map +0 -1
  179. package/dist/server/handlers/prompt.d.ts +0 -3
  180. package/dist/server/handlers/prompt.d.ts.map +0 -1
  181. package/dist/sury-CWZTCd75-E5BDQIXB.cjs +0 -17
  182. package/dist/typebox-Dei93FPO-XXPZXWWK.js +0 -8
  183. package/dist/valibot--1zFm7rT-ALWQ34TP.cjs +0 -17
@@ -1,16 +1,18 @@
1
+ import { normalizeStudioBase } from '../chunk-QAOUDKHK.js';
1
2
  import { readFile } from 'fs/promises';
2
3
  import * as https from 'https';
3
- import { join } from 'path/posix';
4
+ import { join, dirname } from 'path';
5
+ import { fileURLToPath } from 'url';
4
6
  import { createServer } from 'http';
5
7
  import { Http2ServerRequest } from 'http2';
6
8
  import { Writable, Readable } from 'stream';
7
9
  import crypto from 'crypto';
8
10
  import { getMimeType } from 'hono/utils/mime';
9
11
  import { existsSync, createReadStream, lstatSync } from 'fs';
10
- import { join as join$1 } from 'path';
11
12
  import { html } from 'hono/html';
12
13
  import { Tool } from '@mastra/core/tools';
13
- import { MastraServer as MastraServer$1, redactStreamChunk } from '@mastra/server/server-adapter';
14
+ import { formatZodError } from '@mastra/server/handlers/error';
15
+ import { MastraServer as MastraServer$1, normalizeQueryParams, redactStreamChunk } from '@mastra/server/server-adapter';
14
16
  import util from 'util';
15
17
  import { Buffer as Buffer$1 } from 'buffer';
16
18
  import { isDevPlaygroundRequest, isProtectedPath, canAccessPublicly, checkRules, defaultAuthConfig } from '@mastra/server/auth';
@@ -57,7 +59,7 @@ var newHeadersFromIncoming = (incoming) => {
57
59
  }
58
60
  return new Headers(headerRecord);
59
61
  };
60
- var wrapBodyStream = Symbol("wrapBodyStream");
62
+ var wrapBodyStream = /* @__PURE__ */ Symbol("wrapBodyStream");
61
63
  var newRequestFromIncoming = (method, url, headers, incoming, abortController) => {
62
64
  const init = {
63
65
  method,
@@ -105,13 +107,13 @@ var newRequestFromIncoming = (method, url, headers, incoming, abortController) =
105
107
  }
106
108
  return new Request2(url, init);
107
109
  };
108
- var getRequestCache = Symbol("getRequestCache");
109
- var requestCache = Symbol("requestCache");
110
- var incomingKey = Symbol("incomingKey");
111
- var urlKey = Symbol("urlKey");
112
- var headersKey = Symbol("headersKey");
113
- var abortControllerKey = Symbol("abortControllerKey");
114
- var getAbortController = Symbol("getAbortController");
110
+ var getRequestCache = /* @__PURE__ */ Symbol("getRequestCache");
111
+ var requestCache = /* @__PURE__ */ Symbol("requestCache");
112
+ var incomingKey = /* @__PURE__ */ Symbol("incomingKey");
113
+ var urlKey = /* @__PURE__ */ Symbol("urlKey");
114
+ var headersKey = /* @__PURE__ */ Symbol("headersKey");
115
+ var abortControllerKey = /* @__PURE__ */ Symbol("abortControllerKey");
116
+ var getAbortController = /* @__PURE__ */ Symbol("getAbortController");
115
117
  var requestPrototype = {
116
118
  get method() {
117
119
  return this[incomingKey].method || "GET";
@@ -202,9 +204,9 @@ var newRequest = (incoming, defaultHostname) => {
202
204
  req[urlKey] = url.href;
203
205
  return req;
204
206
  };
205
- var responseCache = Symbol("responseCache");
206
- var getResponseCache = Symbol("getResponseCache");
207
- var cacheKey = Symbol("cache");
207
+ var responseCache = /* @__PURE__ */ Symbol("responseCache");
208
+ var getResponseCache = /* @__PURE__ */ Symbol("getResponseCache");
209
+ var cacheKey = /* @__PURE__ */ Symbol("cache");
208
210
  var GlobalResponse = global.Response;
209
211
  var Response2 = class _Response {
210
212
  #body;
@@ -346,7 +348,7 @@ global.fetch = (info, init) => {
346
348
  };
347
349
  return webFetch(info, init);
348
350
  };
349
- var outgoingEnded = Symbol("outgoingEnded");
351
+ var outgoingEnded = /* @__PURE__ */ Symbol("outgoingEnded");
350
352
  var handleRequestError = () => new Response(null, {
351
353
  status: 400
352
354
  });
@@ -627,14 +629,14 @@ var serveStatic = (options = { root: "" }) => {
627
629
  return next();
628
630
  }
629
631
  }
630
- let path = join$1(
632
+ let path = join(
631
633
  root,
632
634
  !optionPath && options.rewriteRequestPath ? options.rewriteRequestPath(filename, c) : filename
633
635
  );
634
636
  let stats = getStats(path);
635
637
  if (stats && stats.isDirectory()) {
636
638
  const indexFile = options.index ?? "index.html";
637
- path = join$1(path, indexFile);
639
+ path = join(path, indexFile);
638
640
  stats = getStats(path);
639
641
  }
640
642
  if (!stats) {
@@ -1000,12 +1002,12 @@ var ERR_STREAM_WRITE_AFTER_END = class extends Error {
1000
1002
  };
1001
1003
 
1002
1004
  // ../../node_modules/.pnpm/fetch-to-node@2.1.0/node_modules/fetch-to-node/dist/fetch-to-node/http-incoming.js
1003
- var kHeaders = Symbol("kHeaders");
1004
- var kHeadersDistinct = Symbol("kHeadersDistinct");
1005
- var kHeadersCount = Symbol("kHeadersCount");
1006
- var kTrailers = Symbol("kTrailers");
1007
- var kTrailersDistinct = Symbol("kTrailersDistinct");
1008
- var kTrailersCount = Symbol("kTrailersCount");
1005
+ var kHeaders = /* @__PURE__ */ Symbol("kHeaders");
1006
+ var kHeadersDistinct = /* @__PURE__ */ Symbol("kHeadersDistinct");
1007
+ var kHeadersCount = /* @__PURE__ */ Symbol("kHeadersCount");
1008
+ var kTrailers = /* @__PURE__ */ Symbol("kTrailers");
1009
+ var kTrailersDistinct = /* @__PURE__ */ Symbol("kTrailersDistinct");
1010
+ var kTrailersCount = /* @__PURE__ */ Symbol("kTrailersCount");
1009
1011
  var FetchIncomingMessage = class extends Readable {
1010
1012
  get socket() {
1011
1013
  return null;
@@ -1371,8 +1373,8 @@ function isUint8Array(value) {
1371
1373
  }
1372
1374
 
1373
1375
  // ../../node_modules/.pnpm/fetch-to-node@2.1.0/node_modules/fetch-to-node/dist/fetch-to-node/internal-http.js
1374
- var kNeedDrain = Symbol("kNeedDrain");
1375
- var kOutHeaders = Symbol("kOutHeaders");
1376
+ var kNeedDrain = /* @__PURE__ */ Symbol("kNeedDrain");
1377
+ var kOutHeaders = /* @__PURE__ */ Symbol("kOutHeaders");
1376
1378
  function utcDate() {
1377
1379
  return (/* @__PURE__ */ new Date()).toUTCString();
1378
1380
  }
@@ -1392,14 +1394,14 @@ function checkInvalidHeaderChar(val) {
1392
1394
  return headerCharRegex.test(val);
1393
1395
  }
1394
1396
  var chunkExpression = /(?:^|\W)chunked(?:$|\W)/i;
1395
- var kCorked = Symbol("corked");
1396
- var kChunkedBuffer = Symbol("kChunkedBuffer");
1397
- var kChunkedLength = Symbol("kChunkedLength");
1398
- var kUniqueHeaders = Symbol("kUniqueHeaders");
1399
- var kBytesWritten = Symbol("kBytesWritten");
1400
- var kErrored = Symbol("errored");
1401
- var kHighWaterMark = Symbol("kHighWaterMark");
1402
- var kRejectNonStandardBodyWrites = Symbol("kRejectNonStandardBodyWrites");
1397
+ var kCorked = /* @__PURE__ */ Symbol("corked");
1398
+ var kChunkedBuffer = /* @__PURE__ */ Symbol("kChunkedBuffer");
1399
+ var kChunkedLength = /* @__PURE__ */ Symbol("kChunkedLength");
1400
+ var kUniqueHeaders = /* @__PURE__ */ Symbol("kUniqueHeaders");
1401
+ var kBytesWritten = /* @__PURE__ */ Symbol("kBytesWritten");
1402
+ var kErrored = /* @__PURE__ */ Symbol("errored");
1403
+ var kHighWaterMark = /* @__PURE__ */ Symbol("kHighWaterMark");
1404
+ var kRejectNonStandardBodyWrites = /* @__PURE__ */ Symbol("kRejectNonStandardBodyWrites");
1403
1405
  var nop = () => {
1404
1406
  };
1405
1407
  var RE_CONN_CLOSE = /(?:^|\W)close(?:$|\W)/i;
@@ -2666,11 +2668,21 @@ function toFetchResponse(res) {
2666
2668
  var HTTPException = class extends Error {
2667
2669
  res;
2668
2670
  status;
2671
+ /**
2672
+ * Creates an instance of `HTTPException`.
2673
+ * @param status - HTTP status code for the exception. Defaults to 500.
2674
+ * @param options - Additional options for the exception.
2675
+ */
2669
2676
  constructor(status = 500, options) {
2670
2677
  super(options?.message, { cause: options?.cause });
2671
2678
  this.res = options?.res;
2672
2679
  this.status = status;
2673
2680
  }
2681
+ /**
2682
+ * Returns the response object associated with the exception.
2683
+ * If a response object is not provided, a new response is created with the error message and status code.
2684
+ * @returns The response object.
2685
+ */
2674
2686
  getResponse() {
2675
2687
  if (this.res) {
2676
2688
  const newResponse = new Response(this.res.body, {
@@ -2745,7 +2757,13 @@ var StreamingApi = class {
2745
2757
  writable;
2746
2758
  abortSubscribers = [];
2747
2759
  responseReadable;
2760
+ /**
2761
+ * Whether the stream has been aborted.
2762
+ */
2748
2763
  aborted = false;
2764
+ /**
2765
+ * Whether the stream has been closed normally.
2766
+ */
2749
2767
  closed = false;
2750
2768
  constructor(writable, _readable) {
2751
2769
  this.writable = writable;
@@ -2797,6 +2815,10 @@ var StreamingApi = class {
2797
2815
  onAbort(listener) {
2798
2816
  this.abortSubscribers.push(listener);
2799
2817
  }
2818
+ /**
2819
+ * Abort the stream.
2820
+ * You can call this method when stream is aborted by external event.
2821
+ */
2800
2822
  abort() {
2801
2823
  if (!this.aborted) {
2802
2824
  this.aborted = true;
@@ -2841,6 +2863,209 @@ var stream = (c, cb, onError3) => {
2841
2863
  })();
2842
2864
  return c.newResponse(stream2.responseReadable);
2843
2865
  };
2866
+ var util2;
2867
+ (function(util22) {
2868
+ util22.assertEqual = (_) => {
2869
+ };
2870
+ function assertIs(_arg) {
2871
+ }
2872
+ util22.assertIs = assertIs;
2873
+ function assertNever(_x) {
2874
+ throw new Error();
2875
+ }
2876
+ util22.assertNever = assertNever;
2877
+ util22.arrayToEnum = (items) => {
2878
+ const obj = {};
2879
+ for (const item of items) {
2880
+ obj[item] = item;
2881
+ }
2882
+ return obj;
2883
+ };
2884
+ util22.getValidEnumValues = (obj) => {
2885
+ const validKeys = util22.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
2886
+ const filtered = {};
2887
+ for (const k of validKeys) {
2888
+ filtered[k] = obj[k];
2889
+ }
2890
+ return util22.objectValues(filtered);
2891
+ };
2892
+ util22.objectValues = (obj) => {
2893
+ return util22.objectKeys(obj).map(function(e) {
2894
+ return obj[e];
2895
+ });
2896
+ };
2897
+ util22.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
2898
+ const keys = [];
2899
+ for (const key in object) {
2900
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
2901
+ keys.push(key);
2902
+ }
2903
+ }
2904
+ return keys;
2905
+ };
2906
+ util22.find = (arr, checker) => {
2907
+ for (const item of arr) {
2908
+ if (checker(item))
2909
+ return item;
2910
+ }
2911
+ return void 0;
2912
+ };
2913
+ util22.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
2914
+ function joinValues(array, separator = " | ") {
2915
+ return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
2916
+ }
2917
+ util22.joinValues = joinValues;
2918
+ util22.jsonStringifyReplacer = (_, value) => {
2919
+ if (typeof value === "bigint") {
2920
+ return value.toString();
2921
+ }
2922
+ return value;
2923
+ };
2924
+ })(util2 || (util2 = {}));
2925
+ var objectUtil;
2926
+ (function(objectUtil2) {
2927
+ objectUtil2.mergeShapes = (first, second) => {
2928
+ return {
2929
+ ...first,
2930
+ ...second
2931
+ // second overwrites first
2932
+ };
2933
+ };
2934
+ })(objectUtil || (objectUtil = {}));
2935
+ util2.arrayToEnum([
2936
+ "string",
2937
+ "nan",
2938
+ "number",
2939
+ "integer",
2940
+ "float",
2941
+ "boolean",
2942
+ "date",
2943
+ "bigint",
2944
+ "symbol",
2945
+ "function",
2946
+ "undefined",
2947
+ "null",
2948
+ "array",
2949
+ "object",
2950
+ "unknown",
2951
+ "promise",
2952
+ "void",
2953
+ "never",
2954
+ "map",
2955
+ "set"
2956
+ ]);
2957
+ util2.arrayToEnum([
2958
+ "invalid_type",
2959
+ "invalid_literal",
2960
+ "custom",
2961
+ "invalid_union",
2962
+ "invalid_union_discriminator",
2963
+ "invalid_enum_value",
2964
+ "unrecognized_keys",
2965
+ "invalid_arguments",
2966
+ "invalid_return_type",
2967
+ "invalid_date",
2968
+ "invalid_string",
2969
+ "too_small",
2970
+ "too_big",
2971
+ "invalid_intersection_types",
2972
+ "not_multiple_of",
2973
+ "not_finite"
2974
+ ]);
2975
+ var ZodError = class _ZodError extends Error {
2976
+ get errors() {
2977
+ return this.issues;
2978
+ }
2979
+ constructor(issues) {
2980
+ super();
2981
+ this.issues = [];
2982
+ this.addIssue = (sub) => {
2983
+ this.issues = [...this.issues, sub];
2984
+ };
2985
+ this.addIssues = (subs = []) => {
2986
+ this.issues = [...this.issues, ...subs];
2987
+ };
2988
+ const actualProto = new.target.prototype;
2989
+ if (Object.setPrototypeOf) {
2990
+ Object.setPrototypeOf(this, actualProto);
2991
+ } else {
2992
+ this.__proto__ = actualProto;
2993
+ }
2994
+ this.name = "ZodError";
2995
+ this.issues = issues;
2996
+ }
2997
+ format(_mapper) {
2998
+ const mapper = _mapper || function(issue) {
2999
+ return issue.message;
3000
+ };
3001
+ const fieldErrors = { _errors: [] };
3002
+ const processError = (error) => {
3003
+ for (const issue of error.issues) {
3004
+ if (issue.code === "invalid_union") {
3005
+ issue.unionErrors.map(processError);
3006
+ } else if (issue.code === "invalid_return_type") {
3007
+ processError(issue.returnTypeError);
3008
+ } else if (issue.code === "invalid_arguments") {
3009
+ processError(issue.argumentsError);
3010
+ } else if (issue.path.length === 0) {
3011
+ fieldErrors._errors.push(mapper(issue));
3012
+ } else {
3013
+ let curr = fieldErrors;
3014
+ let i = 0;
3015
+ while (i < issue.path.length) {
3016
+ const el = issue.path[i];
3017
+ const terminal = i === issue.path.length - 1;
3018
+ if (!terminal) {
3019
+ curr[el] = curr[el] || { _errors: [] };
3020
+ } else {
3021
+ curr[el] = curr[el] || { _errors: [] };
3022
+ curr[el]._errors.push(mapper(issue));
3023
+ }
3024
+ curr = curr[el];
3025
+ i++;
3026
+ }
3027
+ }
3028
+ }
3029
+ };
3030
+ processError(this);
3031
+ return fieldErrors;
3032
+ }
3033
+ static assert(value) {
3034
+ if (!(value instanceof _ZodError)) {
3035
+ throw new Error(`Not a ZodError: ${value}`);
3036
+ }
3037
+ }
3038
+ toString() {
3039
+ return this.message;
3040
+ }
3041
+ get message() {
3042
+ return JSON.stringify(this.issues, util2.jsonStringifyReplacer, 2);
3043
+ }
3044
+ get isEmpty() {
3045
+ return this.issues.length === 0;
3046
+ }
3047
+ flatten(mapper = (issue) => issue.message) {
3048
+ const fieldErrors = {};
3049
+ const formErrors = [];
3050
+ for (const sub of this.issues) {
3051
+ if (sub.path.length > 0) {
3052
+ const firstEl = sub.path[0];
3053
+ fieldErrors[firstEl] = fieldErrors[firstEl] || [];
3054
+ fieldErrors[firstEl].push(mapper(sub));
3055
+ } else {
3056
+ formErrors.push(mapper(sub));
3057
+ }
3058
+ }
3059
+ return { formErrors, fieldErrors };
3060
+ }
3061
+ get formErrors() {
3062
+ return this.flatten();
3063
+ }
3064
+ };
3065
+ ZodError.create = (issues) => {
3066
+ const error = new ZodError(issues);
3067
+ return error;
3068
+ };
2844
3069
  var authenticationMiddleware = async (c, next) => {
2845
3070
  const mastra = c.get("mastra");
2846
3071
  const authConfig = mastra.getServer()?.auth;
@@ -2984,8 +3209,6 @@ var MastraServer = class extends MastraServer$1 {
2984
3209
  c.set("mastra", this.mastra);
2985
3210
  c.set("tools", this.tools || {});
2986
3211
  c.set("taskStore", this.taskStore);
2987
- c.set("playground", this.playground === true);
2988
- c.set("isDev", this.isDev === true);
2989
3212
  c.set("abortSignal", c.req.raw.signal);
2990
3213
  c.set("customRouteAuthConfig", this.customRouteAuthConfig);
2991
3214
  return next();
@@ -3033,16 +3256,51 @@ var MastraServer = class extends MastraServer$1 {
3033
3256
  }
3034
3257
  async getParams(route, request) {
3035
3258
  const urlParams = request.param();
3036
- const queryParams = request.query();
3259
+ const queryParams = normalizeQueryParams(request.queries());
3037
3260
  let body;
3038
3261
  if (route.method === "POST" || route.method === "PUT" || route.method === "PATCH") {
3039
- try {
3040
- body = await request.json();
3041
- } catch {
3262
+ const contentType = request.header("content-type") || "";
3263
+ if (contentType.includes("multipart/form-data")) {
3264
+ try {
3265
+ const formData = await request.formData();
3266
+ body = await this.parseFormData(formData);
3267
+ } catch (error) {
3268
+ console.error("Failed to parse multipart form data:", error);
3269
+ if (error instanceof Error && error.message.toLowerCase().includes("size")) {
3270
+ throw error;
3271
+ }
3272
+ }
3273
+ } else {
3274
+ try {
3275
+ body = await request.json();
3276
+ } catch (error) {
3277
+ console.error("Failed to parse JSON body:", error);
3278
+ }
3042
3279
  }
3043
3280
  }
3044
3281
  return { urlParams, queryParams, body };
3045
3282
  }
3283
+ /**
3284
+ * Parse FormData into a plain object, converting File objects to Buffers.
3285
+ */
3286
+ async parseFormData(formData) {
3287
+ const result = {};
3288
+ for (const [key, value] of formData.entries()) {
3289
+ if (value instanceof File) {
3290
+ const arrayBuffer = await value.arrayBuffer();
3291
+ result[key] = Buffer.from(arrayBuffer);
3292
+ } else if (typeof value === "string") {
3293
+ try {
3294
+ result[key] = JSON.parse(value);
3295
+ } catch {
3296
+ result[key] = value;
3297
+ }
3298
+ } else {
3299
+ result[key] = value;
3300
+ }
3301
+ }
3302
+ return result;
3303
+ }
3046
3304
  async sendResponse(route, response, result) {
3047
3305
  if (route.responseType === "json") {
3048
3306
  return response.json(result, 200);
@@ -3114,10 +3372,13 @@ var MastraServer = class extends MastraServer$1 {
3114
3372
  params.queryParams = await this.parseQueryParams(route, params.queryParams);
3115
3373
  } catch (error) {
3116
3374
  console.error("Error parsing query params", error);
3375
+ if (error instanceof ZodError) {
3376
+ return c.json(formatZodError(error, "query parameters"), 400);
3377
+ }
3117
3378
  return c.json(
3118
3379
  {
3119
3380
  error: "Invalid query parameters",
3120
- details: error instanceof Error ? error.message : "Unknown error"
3381
+ issues: [{ field: "unknown", message: error instanceof Error ? error.message : "Unknown error" }]
3121
3382
  },
3122
3383
  400
3123
3384
  );
@@ -3128,10 +3389,13 @@ var MastraServer = class extends MastraServer$1 {
3128
3389
  params.body = await this.parseBody(route, params.body);
3129
3390
  } catch (error) {
3130
3391
  console.error("Error parsing body:", error instanceof Error ? error.message : String(error));
3392
+ if (error instanceof ZodError) {
3393
+ return c.json(formatZodError(error, "request body"), 400);
3394
+ }
3131
3395
  return c.json(
3132
3396
  {
3133
3397
  error: "Invalid request body",
3134
- details: error instanceof Error ? error.message : "Unknown error"
3398
+ issues: [{ field: "unknown", message: error instanceof Error ? error.message : "Unknown error" }]
3135
3399
  },
3136
3400
  400
3137
3401
  );
@@ -3180,8 +3444,8 @@ var MastraServer = class extends MastraServer$1 {
3180
3444
  }
3181
3445
  };
3182
3446
 
3183
- // ../../node_modules/.pnpm/hono-openapi@1.1.1_@hono+standard-validator@0.2.0_@standard-schema+spec@1.0.0_hono@4.10_dee62e986c04f5a510cb45dc6cf3f0e3/node_modules/hono-openapi/dist/index.js
3184
- var uniqueSymbol = Symbol("openapi");
3447
+ // ../../node_modules/.pnpm/hono-openapi@1.1.1_@hono+standard-validator@0.2.1_@standard-schema+spec@1.1.0_hono@4.11_9131e3cfc9e6aabf665461e37801bbee/node_modules/hono-openapi/dist/index.js
3448
+ var uniqueSymbol = /* @__PURE__ */ Symbol("openapi");
3185
3449
  function describeRoute(spec) {
3186
3450
  const middleware2 = async (_c, next) => {
3187
3451
  await next();
@@ -3262,6 +3526,126 @@ async function restartAllActiveWorkflowRunsHandler(c) {
3262
3526
  }
3263
3527
  }
3264
3528
 
3529
+ // src/server/handlers/root.ts
3530
+ async function rootHandler(c) {
3531
+ const baseUrl = new URL(c.req.url).origin;
3532
+ return c.html(
3533
+ /* html */
3534
+ `
3535
+ <!doctype html>
3536
+ <html lang="en">
3537
+ <head>
3538
+ <meta charset="UTF-8" />
3539
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
3540
+ <title>Mastra API</title>
3541
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/inter-ui/3.19.3/inter.min.css" />
3542
+ <style>
3543
+ body {
3544
+ margin: 0;
3545
+ padding: 0;
3546
+ background-color: #0d0d0d;
3547
+ color: #ffffff;
3548
+ font-family:
3549
+ 'Inter',
3550
+ -apple-system,
3551
+ BlinkMacSystemFont,
3552
+ system-ui,
3553
+ sans-serif;
3554
+ min-height: 100vh;
3555
+ display: flex;
3556
+ flex-direction: column;
3557
+ }
3558
+
3559
+ main {
3560
+ flex: 1;
3561
+ display: flex;
3562
+ flex-direction: column;
3563
+ align-items: center;
3564
+ justify-content: center;
3565
+ padding: 2rem;
3566
+ text-align: center;
3567
+ }
3568
+
3569
+ h1 {
3570
+ font-size: 4rem;
3571
+ font-weight: 600;
3572
+ margin: 0 0 1rem 0;
3573
+ background: linear-gradient(to right, #fff, #ccc);
3574
+ -webkit-background-clip: text;
3575
+ -webkit-text-fill-color: transparent;
3576
+ line-height: 1.2;
3577
+ }
3578
+
3579
+ .subtitle {
3580
+ color: #9ca3af;
3581
+ font-size: 1.25rem;
3582
+ max-width: 600px;
3583
+ margin: 0 auto 3rem auto;
3584
+ line-height: 1.6;
3585
+ }
3586
+
3587
+ .link {
3588
+ color: #ffffff;
3589
+ }
3590
+
3591
+ .link:hover {
3592
+ text-decoration: none;
3593
+ }
3594
+
3595
+ .docs-link {
3596
+ background-color: #1a1a1a;
3597
+ padding: 1rem 2rem;
3598
+ border-radius: 0.5rem;
3599
+ display: flex;
3600
+ align-items: center;
3601
+ gap: 1rem;
3602
+ font-family: monospace;
3603
+ font-size: 1rem;
3604
+ color: #ffffff;
3605
+ text-decoration: none;
3606
+ transition: background-color 0.2s;
3607
+ }
3608
+
3609
+ .docs-link:hover {
3610
+ background-color: #252525;
3611
+ }
3612
+
3613
+ .arrow-icon {
3614
+ transition: transform 0.2s;
3615
+ }
3616
+
3617
+ .docs-link:hover .arrow-icon {
3618
+ transform: translateX(4px);
3619
+ }
3620
+ </style>
3621
+ </head>
3622
+ <body>
3623
+ <main>
3624
+ <h1>Welcome to the Mastra API</h1>
3625
+ <p class="subtitle">
3626
+ Discover all available endpoints through Swagger UI. You can also define your own <a href="https://mastra.ai/docs/server-db/custom-api-routes" target="_blank" class="link">API routes</a>.
3627
+ </p>
3628
+ <a href="${baseUrl}/swagger-ui" target="_blank" class="docs-link">
3629
+ Browse Swagger UI
3630
+ <svg
3631
+ class="arrow-icon"
3632
+ width="20"
3633
+ height="20"
3634
+ viewBox="0 0 24 24"
3635
+ fill="none"
3636
+ stroke="currentColor"
3637
+ strokeWidth="2"
3638
+ >
3639
+ <path d="M5 12h14M12 5l7 7-7 7" />
3640
+ </svg>
3641
+ </a>
3642
+ </main>
3643
+ </body>
3644
+ </html>
3645
+ `
3646
+ );
3647
+ }
3648
+
3265
3649
  // src/server/welcome.ts
3266
3650
  var html2 = `
3267
3651
  <!doctype html>
@@ -3370,6 +3754,18 @@ var html2 = `
3370
3754
  `;
3371
3755
 
3372
3756
  // src/server/index.ts
3757
+ var getStudioPath = () => {
3758
+ if (process.env.MASTRA_STUDIO_PATH) {
3759
+ return process.env.MASTRA_STUDIO_PATH;
3760
+ }
3761
+ let __dirname = ".";
3762
+ if (import.meta.url) {
3763
+ const __filename = fileURLToPath(import.meta.url);
3764
+ __dirname = dirname(__filename);
3765
+ }
3766
+ const studioPath = process.env.MASTRA_STUDIO_PATH || join(__dirname, "studio");
3767
+ return studioPath;
3768
+ };
3373
3769
  function getToolExports(tools) {
3374
3770
  try {
3375
3771
  return tools.reduce((acc, toolModule) => {
@@ -3405,7 +3801,13 @@ async function createHonoServer(mastra, options = {
3405
3801
  customRouteAuthConfig.set(routeKey, requiresAuth);
3406
3802
  }
3407
3803
  }
3408
- app.onError((err, c) => errorHandler(err, c, options.isDev));
3804
+ const customOnError = server?.onError;
3805
+ app.onError((err, c) => {
3806
+ if (customOnError) {
3807
+ return customOnError(err, c);
3808
+ }
3809
+ return errorHandler(err, c, options.isDev);
3810
+ });
3409
3811
  const bodyLimitOptions = {
3410
3812
  maxSize: server?.bodySizeLimit ?? 4.5 * 1024 * 1024,
3411
3813
  // 4.5 MB,
@@ -3416,10 +3818,8 @@ async function createHonoServer(mastra, options = {
3416
3818
  mastra,
3417
3819
  tools: options.tools,
3418
3820
  taskStore: a2aTaskStore,
3419
- playground: options.playground,
3420
- isDev: options.isDev,
3421
3821
  bodyLimitOptions,
3422
- openapiPath: "/openapi.json",
3822
+ openapiPath: options?.isDev || server?.build?.openAPIDocs ? "/openapi.json" : void 0,
3423
3823
  customRouteAuthConfig
3424
3824
  });
3425
3825
  honoServerAdapter.registerContextMiddleware();
@@ -3456,6 +3856,21 @@ async function createHonoServer(mastra, options = {
3456
3856
  }),
3457
3857
  healthHandler
3458
3858
  );
3859
+ if (options?.isDev || server?.build?.swaggerUI) {
3860
+ app.get(
3861
+ "/api",
3862
+ describeRoute({
3863
+ description: "API Welcome Page",
3864
+ tags: ["system"],
3865
+ responses: {
3866
+ 200: {
3867
+ description: "Success"
3868
+ }
3869
+ }
3870
+ }),
3871
+ rootHandler
3872
+ );
3873
+ }
3459
3874
  honoServerAdapter.registerAuthMiddleware();
3460
3875
  if (server?.middleware) {
3461
3876
  const normalizedMiddlewares = Array.isArray(server.middleware) ? server.middleware : [server.middleware];
@@ -3482,18 +3897,11 @@ async function createHonoServer(mastra, options = {
3482
3897
  middlewares.push(describeRoute(route.openapi));
3483
3898
  }
3484
3899
  const handler = "handler" in route ? route.handler : await route.createHandler({ mastra });
3485
- if (route.method === "GET") {
3486
- app.get(route.path, ...middlewares, handler);
3487
- } else if (route.method === "POST") {
3488
- app.post(route.path, ...middlewares, handler);
3489
- } else if (route.method === "PUT") {
3490
- app.put(route.path, ...middlewares, handler);
3491
- } else if (route.method === "DELETE") {
3492
- app.delete(route.path, ...middlewares, handler);
3493
- } else if (route.method === "PATCH") {
3494
- app.patch(route.path, ...middlewares, handler);
3495
- } else if (route.method === "ALL") {
3496
- app.all(route.path, ...middlewares, handler);
3900
+ const allHandlers = [...middlewares, handler];
3901
+ if (route.method === "ALL") {
3902
+ app.all(route.path, allHandlers[0], ...allHandlers.slice(1));
3903
+ } else {
3904
+ app.on(route.method, route.path, allHandlers[0], ...allHandlers.slice(1));
3497
3905
  }
3498
3906
  }
3499
3907
  }
@@ -3502,6 +3910,12 @@ async function createHonoServer(mastra, options = {
3502
3910
  }
3503
3911
  await honoServerAdapter.registerRoutes();
3504
3912
  if (options?.isDev || server?.build?.swaggerUI) {
3913
+ if (!options?.isDev && server?.build?.swaggerUI && !server?.build?.openAPIDocs) {
3914
+ const logger2 = mastra.getLogger();
3915
+ logger2.warn(
3916
+ "Swagger UI is enabled but OpenAPI documentation is disabled. The Swagger UI will not function properly without the OpenAPI endpoint. Please enable openAPIDocs in your server.build configuration:\n server: { build: { swaggerUI: true, openAPIDocs: true } }"
3917
+ );
3918
+ }
3505
3919
  app.get(
3506
3920
  "/swagger-ui",
3507
3921
  describeRoute({
@@ -3519,23 +3933,25 @@ async function createHonoServer(mastra, options = {
3519
3933
  restartAllActiveWorkflowRunsHandler
3520
3934
  );
3521
3935
  }
3522
- if (options?.playground) {
3936
+ const serverOptions = mastra.getServer();
3937
+ const studioBasePath = normalizeStudioBase(serverOptions?.studioBase ?? "/");
3938
+ if (options?.studio) {
3523
3939
  app.get(
3524
- "/refresh-events",
3940
+ `${studioBasePath}/refresh-events`,
3525
3941
  describeRoute({
3526
3942
  hide: true
3527
3943
  }),
3528
3944
  handleClientsRefresh
3529
3945
  );
3530
3946
  app.post(
3531
- "/__refresh",
3947
+ `${studioBasePath}/__refresh`,
3532
3948
  describeRoute({
3533
3949
  hide: true
3534
3950
  }),
3535
3951
  handleTriggerClientsRefresh
3536
3952
  );
3537
3953
  app.get(
3538
- "/__hot-reload-status",
3954
+ `${studioBasePath}/__hot-reload-status`,
3539
3955
  describeRoute({
3540
3956
  hide: true
3541
3957
  }),
@@ -3546,48 +3962,66 @@ async function createHonoServer(mastra, options = {
3546
3962
  });
3547
3963
  }
3548
3964
  );
3549
- app.use("/assets/*", async (c, next) => {
3550
- const path = c.req.path;
3551
- if (path.endsWith(".js")) {
3552
- c.header("Content-Type", "application/javascript");
3553
- } else if (path.endsWith(".css")) {
3554
- c.header("Content-Type", "text/css");
3555
- }
3556
- await next();
3557
- });
3965
+ const studioPath = getStudioPath();
3558
3966
  app.use(
3559
- "/assets/*",
3967
+ `${studioBasePath}/assets/*`,
3560
3968
  serveStatic({
3561
- root: "./playground/assets"
3969
+ root: join(studioPath, "assets"),
3970
+ rewriteRequestPath: (path) => {
3971
+ let rewritten = path;
3972
+ if (studioBasePath && rewritten.startsWith(studioBasePath)) {
3973
+ rewritten = rewritten.slice(studioBasePath.length);
3974
+ }
3975
+ if (rewritten.startsWith("/assets")) {
3976
+ rewritten = rewritten.slice("/assets".length);
3977
+ }
3978
+ return rewritten;
3979
+ }
3562
3980
  })
3563
3981
  );
3564
3982
  }
3565
3983
  app.get("*", async (c, next) => {
3566
- if (c.req.path.startsWith("/api/") || c.req.path.startsWith("/swagger-ui") || c.req.path.startsWith("/openapi.json")) {
3984
+ const requestPath = c.req.path;
3985
+ if (requestPath === "/api" || requestPath.startsWith("/api/") || requestPath.startsWith("/swagger-ui") || requestPath.startsWith("/openapi.json")) {
3567
3986
  return await next();
3568
3987
  }
3569
- const path = c.req.path;
3570
- if (path.includes(".") && !path.endsWith(".html")) {
3988
+ if (requestPath.includes(".") && !requestPath.endsWith(".html")) {
3571
3989
  return await next();
3572
3990
  }
3573
- if (options?.playground) {
3574
- let indexHtml = await readFile(join(process.cwd(), "./playground/index.html"), "utf-8");
3575
- const serverOptions = mastra.getServer();
3991
+ const isStudioRoute = studioBasePath === "" || requestPath === studioBasePath || requestPath.startsWith(`${studioBasePath}/`);
3992
+ if (options?.studio && isStudioRoute) {
3993
+ const studioPath = getStudioPath();
3994
+ let indexHtml = await readFile(join(studioPath, "index.html"), "utf-8");
3576
3995
  const port = serverOptions?.port ?? (Number(process.env.PORT) || 4111);
3577
3996
  const hideCloudCta = process.env.MASTRA_HIDE_CLOUD_CTA === "true";
3578
3997
  const host = serverOptions?.host ?? "localhost";
3998
+ const key = serverOptions?.https?.key ?? (process.env.MASTRA_HTTPS_KEY ? Buffer.from(process.env.MASTRA_HTTPS_KEY, "base64") : void 0);
3999
+ const cert = serverOptions?.https?.cert ?? (process.env.MASTRA_HTTPS_CERT ? Buffer.from(process.env.MASTRA_HTTPS_CERT, "base64") : void 0);
4000
+ const protocol = key && cert ? "https" : "http";
4001
+ const cloudApiEndpoint = process.env.MASTRA_CLOUD_API_ENDPOINT || "";
3579
4002
  indexHtml = indexHtml.replace(`'%%MASTRA_SERVER_HOST%%'`, `'${host}'`);
3580
4003
  indexHtml = indexHtml.replace(`'%%MASTRA_SERVER_PORT%%'`, `'${port}'`);
3581
4004
  indexHtml = indexHtml.replace(`'%%MASTRA_HIDE_CLOUD_CTA%%'`, `'${hideCloudCta}'`);
4005
+ indexHtml = indexHtml.replace(`'%%MASTRA_SERVER_PROTOCOL%%'`, `'${protocol}'`);
4006
+ indexHtml = indexHtml.replace(`'%%MASTRA_CLOUD_API_ENDPOINT%%'`, `'${cloudApiEndpoint}'`);
4007
+ indexHtml = indexHtml.replaceAll("%%MASTRA_STUDIO_BASE_PATH%%", studioBasePath);
3582
4008
  return c.newResponse(indexHtml, 200, { "Content-Type": "text/html" });
3583
4009
  }
3584
4010
  return c.newResponse(html2, 200, { "Content-Type": "text/html" });
3585
4011
  });
3586
- if (options?.playground) {
4012
+ if (options?.studio) {
4013
+ const studioRootPath = getStudioPath();
4014
+ const studioPath = studioBasePath ? `${studioBasePath}/*` : "*";
3587
4015
  app.use(
3588
- "*",
4016
+ studioPath,
3589
4017
  serveStatic({
3590
- root: "./playground"
4018
+ root: studioRootPath,
4019
+ rewriteRequestPath: (path) => {
4020
+ if (studioBasePath && path.startsWith(studioBasePath)) {
4021
+ return path.slice(studioBasePath.length);
4022
+ }
4023
+ return path;
4024
+ }
3591
4025
  })
3592
4026
  );
3593
4027
  }
@@ -3617,9 +4051,10 @@ async function createNodeServer(mastra, options = { tools: {} }) {
3617
4051
  },
3618
4052
  () => {
3619
4053
  const logger2 = mastra.getLogger();
3620
- logger2.info(` Mastra API running on port ${protocol}://${host}:${port}/api`);
3621
- if (options?.playground) {
3622
- const studioUrl = `${protocol}://${host}:${port}`;
4054
+ logger2.info(` Mastra API running on ${protocol}://${host}:${port}/api`);
4055
+ if (options?.studio) {
4056
+ const studioBasePath = normalizeStudioBase(serverOptions?.studioBase ?? "/");
4057
+ const studioUrl = `${protocol}://${host}:${port}${studioBasePath}`;
3623
4058
  logger2.info(`\u{1F468}\u200D\u{1F4BB} Studio available at ${studioUrl}`);
3624
4059
  }
3625
4060
  if (process.send) {