@mastra/server 1.83.0-alpha.9 → 1.83.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 (665) hide show
  1. package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/@internal_core@0.1.4/dist/request-context/index.d.ts +19 -0
  2. package/dist/_types/{@mastra_schema-compat@1.4.0-alpha.1 → @mastra_schema-compat@1.4.0}/dist/provider-compats/anthropic.d.ts +1 -1
  3. package/dist/_types/{@mastra_schema-compat@1.4.0-alpha.1 → @mastra_schema-compat@1.4.0}/dist/provider-compats/deepseek.d.ts +1 -1
  4. package/dist/_types/{@mastra_schema-compat@1.4.0-alpha.1 → @mastra_schema-compat@1.4.0}/dist/provider-compats/meta.d.ts +1 -1
  5. package/dist/_types/{@mastra_schema-compat@1.4.0-alpha.1 → @mastra_schema-compat@1.4.0}/dist/schema.types.d.ts +3 -3
  6. package/dist/{a2a-DIcMx6x-.cjs → a2a-Bz7vRGfF.cjs} +9 -6
  7. package/dist/a2a-Bz7vRGfF.cjs.map +1 -0
  8. package/dist/{a2a-DTTGA2Xg.js → a2a-CY85JalK.js} +9 -6
  9. package/dist/a2a-CY85JalK.js.map +1 -0
  10. package/dist/{agent-builder-DtBRYFZ3.js → agent-builder-Ce1pjSjg.js} +6 -6
  11. package/dist/{agent-builder-DtBRYFZ3.js.map → agent-builder-Ce1pjSjg.js.map} +1 -1
  12. package/dist/{agent-builder-BXBfs0w4.cjs → agent-builder-DWtgp1cb.cjs} +6 -6
  13. package/dist/{agent-builder-BXBfs0w4.cjs.map → agent-builder-DWtgp1cb.cjs.map} +1 -1
  14. package/dist/{agents-BCgiMlDq.js → agents-B0OpLdbp.js} +444 -3
  15. package/dist/agents-B0OpLdbp.js.map +1 -0
  16. package/dist/{agents-DjpBmwhv.cjs → agents-BgaBbcwb.cjs} +136 -53
  17. package/dist/agents-BgaBbcwb.cjs.map +1 -0
  18. package/dist/{agents-CTgjTASj.js → agents-BjlUjmb1.js} +136 -53
  19. package/dist/agents-BjlUjmb1.js.map +1 -0
  20. package/dist/{agents-CjcvdF2e.cjs → agents-CH_G37hG.cjs} +521 -2
  21. package/dist/agents-CH_G37hG.cjs.map +1 -0
  22. package/dist/{api-schema-manifest-B8s3TuPU.js → api-schema-manifest-CsTpd03O.js} +9 -9
  23. package/dist/api-schema-manifest-CsTpd03O.js.map +1 -0
  24. package/dist/{api-schema-manifest-Czr4Bmrw.cjs → api-schema-manifest-DT9X0fAm.cjs} +9 -9
  25. package/dist/api-schema-manifest-DT9X0fAm.cjs.map +1 -0
  26. package/dist/{background-tasks-CYvlxFz3.js → background-tasks-BKnoXtUN.js} +3 -3
  27. package/dist/{background-tasks-CYvlxFz3.js.map → background-tasks-BKnoXtUN.js.map} +1 -1
  28. package/dist/{background-tasks-Dv9o8cR7.cjs → background-tasks-BqW1_VmH.cjs} +3 -3
  29. package/dist/{background-tasks-Dv9o8cR7.cjs.map → background-tasks-BqW1_VmH.cjs.map} +1 -1
  30. package/dist/{builder-registry-BmrttdGj.js → builder-registry-ByghMyfA.js} +3 -3
  31. package/dist/{builder-registry-BmrttdGj.js.map → builder-registry-ByghMyfA.js.map} +1 -1
  32. package/dist/{builder-registry-CmbtZzbE.cjs → builder-registry-DPsdmtZG.cjs} +3 -3
  33. package/dist/{builder-registry-CmbtZzbE.cjs.map → builder-registry-DPsdmtZG.cjs.map} +1 -1
  34. package/dist/catalogue-CGQdyojN.cjs +1378 -0
  35. package/dist/catalogue-CGQdyojN.cjs.map +1 -0
  36. package/dist/catalogue-CUJevxy3.js +1376 -0
  37. package/dist/catalogue-CUJevxy3.js.map +1 -0
  38. package/dist/{channels-KHhb7hAm.js → channels-DIE-lJkq.js} +3 -3
  39. package/dist/{channels-KHhb7hAm.js.map → channels-DIE-lJkq.js.map} +1 -1
  40. package/dist/{channels-CXwFVxi2.cjs → channels-k5dF1IBc.cjs} +3 -3
  41. package/dist/{channels-CXwFVxi2.cjs.map → channels-k5dF1IBc.cjs.map} +1 -1
  42. package/dist/{constants-CXAvBYcz.js → constants-0xZU_h4R.js} +10 -2
  43. package/dist/constants-0xZU_h4R.js.map +1 -0
  44. package/dist/{constants-DMg8hUOR.cjs → constants-1yTmKUZD.cjs} +15 -1
  45. package/dist/constants-1yTmKUZD.cjs.map +1 -0
  46. package/dist/{conversations-BFqmDglO.cjs → conversations-Bvk5VVVJ.cjs} +6 -5
  47. package/dist/conversations-Bvk5VVVJ.cjs.map +1 -0
  48. package/dist/{conversations-BkX00xDs.js → conversations-DYqwqCWH.js} +6 -5
  49. package/dist/conversations-DYqwqCWH.js.map +1 -0
  50. package/dist/{datasets--F0QkdGX.js → datasets-C1XJLHN8.js} +6 -1
  51. package/dist/datasets-C1XJLHN8.js.map +1 -0
  52. package/dist/{datasets-BiEAIm0s.cjs → datasets-hqDd4IUN.cjs} +6 -1
  53. package/dist/datasets-hqDd4IUN.cjs.map +1 -0
  54. package/dist/dist-BVw6-hMs.js +1 -0
  55. package/dist/{dist-DHiTIWvp.js → dist-C-Hmkkat.js} +7 -7
  56. package/dist/{dist-DHiTIWvp.js.map → dist-C-Hmkkat.js.map} +1 -1
  57. package/dist/{dist-DLzcAC-F.cjs → dist-Clh3uSOV.cjs} +12 -12
  58. package/dist/{dist-DLzcAC-F.cjs.map → dist-Clh3uSOV.cjs.map} +1 -1
  59. package/dist/{dist-BRBLnUAY.cjs → dist-DPgpEz_7.cjs} +1 -1
  60. package/dist/docs/SKILL.md +3 -1
  61. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  62. package/dist/docs/references/docs-server-mcp.md +315 -0
  63. package/dist/docs/references/reference-observability-tracing-advanced-queries.md +2 -1
  64. package/dist/docs/references/reference-server-dispatch-route.md +124 -0
  65. package/dist/docs/references/reference-server-invoke-route.md +10 -0
  66. package/dist/{dynamic-workflows-QgKLYkiC.cjs → dynamic-workflows-DPgV6qtS.cjs} +2 -2
  67. package/dist/{dynamic-workflows-QgKLYkiC.cjs.map → dynamic-workflows-DPgV6qtS.cjs.map} +1 -1
  68. package/dist/{dynamic-workflows-CYtakeIQ.js → dynamic-workflows-DmkCJ4Lp.js} +2 -2
  69. package/dist/{dynamic-workflows-CYtakeIQ.js.map → dynamic-workflows-DmkCJ4Lp.js.map} +1 -1
  70. package/dist/{editor-builder-C4H2l6tz.js → editor-builder-CGM0scw2.js} +10 -4
  71. package/dist/editor-builder-CGM0scw2.js.map +1 -0
  72. package/dist/{editor-builder-fe70YP8g.js → editor-builder-CXLdplIj.js} +2 -2
  73. package/dist/{editor-builder-fe70YP8g.js.map → editor-builder-CXLdplIj.js.map} +1 -1
  74. package/dist/{editor-builder-Cqw1npOK.cjs → editor-builder-SP_ledm3.cjs} +10 -4
  75. package/dist/editor-builder-SP_ledm3.cjs.map +1 -0
  76. package/dist/{editor-builder-xQmDgVgJ.cjs → editor-builder-eF2IetF2.cjs} +2 -2
  77. package/dist/{editor-builder-xQmDgVgJ.cjs.map → editor-builder-eF2IetF2.cjs.map} +1 -1
  78. package/dist/{helpers-C9QZKOhz.js → helpers-B56oH6qp.js} +27 -8
  79. package/dist/helpers-B56oH6qp.js.map +1 -0
  80. package/dist/{helpers-0LJI4DxR.cjs → helpers-Dpdta8ai.cjs} +31 -6
  81. package/dist/helpers-Dpdta8ai.cjs.map +1 -0
  82. package/dist/{knowledge-CRkWkTBC.cjs → knowledge-2fms70NN.cjs} +4 -4
  83. package/dist/{knowledge-CRkWkTBC.cjs.map → knowledge-2fms70NN.cjs.map} +1 -1
  84. package/dist/{knowledge-Dfe_CFtt.js → knowledge-BblTTH3z.js} +4 -4
  85. package/dist/{knowledge-Dfe_CFtt.js.map → knowledge-BblTTH3z.js.map} +1 -1
  86. package/dist/{logs-Dg2AWexF.js → logs-D_hKQuvQ.js} +3 -3
  87. package/dist/{logs-Dg2AWexF.js.map → logs-D_hKQuvQ.js.map} +1 -1
  88. package/dist/{logs-B2ov1yZQ.cjs → logs-Deoh0l4I.cjs} +3 -3
  89. package/dist/{logs-B2ov1yZQ.cjs.map → logs-Deoh0l4I.cjs.map} +1 -1
  90. package/dist/{mcp-bsPRIGFX.js → mcp-CSRuYaWN.js} +3 -3
  91. package/dist/{mcp-bsPRIGFX.js.map → mcp-CSRuYaWN.js.map} +1 -1
  92. package/dist/{mcp-Bon4eIV1.cjs → mcp-oWjcmsQb.cjs} +3 -3
  93. package/dist/{mcp-Bon4eIV1.cjs.map → mcp-oWjcmsQb.cjs.map} +1 -1
  94. package/dist/{memory-Dw7xG5nn.js → memory-CGlo-6_V.js} +105 -12
  95. package/dist/memory-CGlo-6_V.js.map +1 -0
  96. package/dist/{memory-BRE3ofvI.cjs → memory-CzSke9Em.cjs} +105 -12
  97. package/dist/memory-CzSke9Em.cjs.map +1 -0
  98. package/dist/{observability-DHJ7mzoE.cjs → observability-BCJsmSH0.cjs} +27 -3
  99. package/dist/observability-BCJsmSH0.cjs.map +1 -0
  100. package/dist/{observability-BYIy4kPf.js → observability-Z2tDxHS1.js} +27 -3
  101. package/dist/observability-Z2tDxHS1.js.map +1 -0
  102. package/dist/{observability-new-endpoints-BOe3wej1.cjs → observability-new-endpoints-C_HEkpZ1.cjs} +157 -5
  103. package/dist/observability-new-endpoints-C_HEkpZ1.cjs.map +1 -0
  104. package/dist/{observability-new-endpoints-COy7lpeR.js → observability-new-endpoints-dr0XcNkP.js} +158 -6
  105. package/dist/observability-new-endpoints-dr0XcNkP.js.map +1 -0
  106. package/dist/{plans-D_GKFz2x.js → plans-BemJO4-7.js} +7 -6
  107. package/dist/plans-BemJO4-7.js.map +1 -0
  108. package/dist/{plans-_nR8lqgD.cjs → plans-CffjV2_6.cjs} +7 -6
  109. package/dist/plans-CffjV2_6.cjs.map +1 -0
  110. package/dist/{probe-image-size-DbJ3ZfUz.js → probe-image-size-jA5gozO6.js} +2 -2
  111. package/dist/{probe-image-size-DbJ3ZfUz.js.map → probe-image-size-jA5gozO6.js.map} +1 -1
  112. package/dist/{probe-image-size-CN-PYGus.cjs → probe-image-size-qOT5Pn0l.cjs} +2 -2
  113. package/dist/{probe-image-size-CN-PYGus.cjs.map → probe-image-size-qOT5Pn0l.cjs.map} +1 -1
  114. package/dist/{responses-C_OEJoxU.js → responses-BofWEQYg.js} +11 -8
  115. package/dist/responses-BofWEQYg.js.map +1 -0
  116. package/dist/{responses-CdWbS4jA.cjs → responses-D0mb5ubj.cjs} +11 -8
  117. package/dist/responses-D0mb5ubj.cjs.map +1 -0
  118. package/dist/{route-builder-B9C5vT54.cjs → route-builder-DjTBxSZN.cjs} +10 -10
  119. package/dist/{route-builder-B9C5vT54.cjs.map → route-builder-DjTBxSZN.cjs.map} +1 -1
  120. package/dist/{route-builder-DfDT1g4L.js → route-builder-Dz18c3qm.js} +9 -9
  121. package/dist/{route-builder-DfDT1g4L.js.map → route-builder-Dz18c3qm.js.map} +1 -1
  122. package/dist/{routes-D3T0BV1r.cjs → routes-01JAJiMe.cjs} +646 -27
  123. package/dist/routes-01JAJiMe.cjs.map +1 -0
  124. package/dist/{routes-Cu4-Al-k.js → routes-CmkPohqd.js} +593 -28
  125. package/dist/routes-CmkPohqd.js.map +1 -0
  126. package/dist/{schedules-BQvnAe1j.cjs → schedules-BRwhbppl.cjs} +77 -22
  127. package/dist/schedules-BRwhbppl.cjs.map +1 -0
  128. package/dist/{schedules-BcAIELfB.js → schedules-Zct_0ZwE.js} +77 -22
  129. package/dist/schedules-Zct_0ZwE.js.map +1 -0
  130. package/dist/{schema-xsUy1mlm-CAPin6jE.js → schema-TQPB_dl2-CCzMcdDx.js} +9 -6
  131. package/dist/{schema-xsUy1mlm-CAPin6jE.js.map → schema-TQPB_dl2-CCzMcdDx.js.map} +1 -1
  132. package/dist/{schema-xsUy1mlm-pvZI8YC0.cjs → schema-TQPB_dl2-CJX1q58F.cjs} +9 -6
  133. package/dist/{schema-xsUy1mlm-pvZI8YC0.cjs.map → schema-TQPB_dl2-CJX1q58F.cjs.map} +1 -1
  134. package/dist/{scores-DEvPN0kz.cjs → scores-0MyV08tL.cjs} +26 -11
  135. package/dist/scores-0MyV08tL.cjs.map +1 -0
  136. package/dist/{scores-Dm0yu1Pt.js → scores-CVssMyoQ.js} +26 -11
  137. package/dist/scores-CVssMyoQ.js.map +1 -0
  138. package/dist/server/auth/helpers.d.ts +7 -1
  139. package/dist/server/auth/helpers.d.ts.map +1 -1
  140. package/dist/server/auth/index.cjs +4 -2
  141. package/dist/server/auth/index.js +3 -3
  142. package/dist/server/constants.d.ts +8 -1
  143. package/dist/server/constants.d.ts.map +1 -1
  144. package/dist/server/handlers/a2a.cjs +1 -1
  145. package/dist/server/handlers/a2a.d.ts +4 -0
  146. package/dist/server/handlers/a2a.d.ts.map +1 -1
  147. package/dist/server/handlers/a2a.js +1 -1
  148. package/dist/server/handlers/agent-access.cjs +42 -0
  149. package/dist/server/handlers/agent-access.cjs.map +1 -0
  150. package/dist/server/handlers/agent-access.d.ts +19 -0
  151. package/dist/server/handlers/agent-access.d.ts.map +1 -0
  152. package/dist/server/handlers/agent-access.js +39 -0
  153. package/dist/server/handlers/agent-access.js.map +1 -0
  154. package/dist/server/handlers/agent-builder.cjs +1 -1
  155. package/dist/server/handlers/agent-builder.d.ts +32 -0
  156. package/dist/server/handlers/agent-builder.d.ts.map +1 -1
  157. package/dist/server/handlers/agent-builder.js +1 -1
  158. package/dist/server/handlers/agent-controller.cjs +4 -3
  159. package/dist/server/handlers/agent-controller.cjs.map +1 -1
  160. package/dist/server/handlers/agent-controller.d.ts +72 -0
  161. package/dist/server/handlers/agent-controller.d.ts.map +1 -1
  162. package/dist/server/handlers/agent-controller.js +4 -3
  163. package/dist/server/handlers/agent-controller.js.map +1 -1
  164. package/dist/server/handlers/agent-versions.cjs +30 -2
  165. package/dist/server/handlers/agent-versions.cjs.map +1 -1
  166. package/dist/server/handlers/agent-versions.d.ts +12 -0
  167. package/dist/server/handlers/agent-versions.d.ts.map +1 -1
  168. package/dist/server/handlers/agent-versions.js +30 -2
  169. package/dist/server/handlers/agent-versions.js.map +1 -1
  170. package/dist/server/handlers/agents.cjs +1 -1
  171. package/dist/server/handlers/agents.d.ts +91 -2
  172. package/dist/server/handlers/agents.d.ts.map +1 -1
  173. package/dist/server/handlers/agents.js +1 -1
  174. package/dist/server/handlers/auth.cjs +3 -3
  175. package/dist/server/handlers/auth.d.ts +40 -0
  176. package/dist/server/handlers/auth.d.ts.map +1 -1
  177. package/dist/server/handlers/auth.js +3 -3
  178. package/dist/server/handlers/authorship.cjs +1 -1
  179. package/dist/server/handlers/authorship.js +1 -1
  180. package/dist/server/handlers/background-tasks.cjs +1 -1
  181. package/dist/server/handlers/background-tasks.d.ts +8 -0
  182. package/dist/server/handlers/background-tasks.d.ts.map +1 -1
  183. package/dist/server/handlers/background-tasks.js +1 -1
  184. package/dist/server/handlers/builder-registry.cjs +1 -1
  185. package/dist/server/handlers/builder-registry.d.ts +10 -0
  186. package/dist/server/handlers/builder-registry.d.ts.map +1 -1
  187. package/dist/server/handlers/builder-registry.js +1 -1
  188. package/dist/server/handlers/channels.cjs +1 -1
  189. package/dist/server/handlers/channels.d.ts +10 -0
  190. package/dist/server/handlers/channels.d.ts.map +1 -1
  191. package/dist/server/handlers/channels.js +1 -1
  192. package/dist/server/handlers/conversations.cjs +1 -1
  193. package/dist/server/handlers/conversations.d.ts +8 -0
  194. package/dist/server/handlers/conversations.d.ts.map +1 -1
  195. package/dist/server/handlers/conversations.js +1 -1
  196. package/dist/server/handlers/datasets.cjs +5 -4
  197. package/dist/server/handlers/datasets.cjs.map +1 -1
  198. package/dist/server/handlers/datasets.d.ts +86 -0
  199. package/dist/server/handlers/datasets.d.ts.map +1 -1
  200. package/dist/server/handlers/datasets.js +5 -4
  201. package/dist/server/handlers/datasets.js.map +1 -1
  202. package/dist/server/handlers/dynamic-workflows.cjs +1 -1
  203. package/dist/server/handlers/dynamic-workflows.d.ts +8 -0
  204. package/dist/server/handlers/dynamic-workflows.d.ts.map +1 -1
  205. package/dist/server/handlers/dynamic-workflows.js +1 -1
  206. package/dist/server/handlers/editor-builder.cjs +1 -1
  207. package/dist/server/handlers/editor-builder.d.ts +6 -0
  208. package/dist/server/handlers/editor-builder.d.ts.map +1 -1
  209. package/dist/server/handlers/editor-builder.js +1 -1
  210. package/dist/server/handlers/favorites-enrichment.cjs +1 -1
  211. package/dist/server/handlers/favorites-enrichment.js +1 -1
  212. package/dist/server/handlers/knowledge.cjs +1 -1
  213. package/dist/server/handlers/knowledge.d.ts +18 -0
  214. package/dist/server/handlers/knowledge.d.ts.map +1 -1
  215. package/dist/server/handlers/knowledge.js +1 -1
  216. package/dist/server/handlers/logs.cjs +1 -1
  217. package/dist/server/handlers/logs.d.ts +6 -0
  218. package/dist/server/handlers/logs.d.ts.map +1 -1
  219. package/dist/server/handlers/logs.js +1 -1
  220. package/dist/server/handlers/mcp-client-versions.cjs +2 -2
  221. package/dist/server/handlers/mcp-client-versions.d.ts +14 -0
  222. package/dist/server/handlers/mcp-client-versions.d.ts.map +1 -1
  223. package/dist/server/handlers/mcp-client-versions.js +2 -2
  224. package/dist/server/handlers/mcp.cjs +1 -1
  225. package/dist/server/handlers/mcp.d.ts +42 -0
  226. package/dist/server/handlers/mcp.d.ts.map +1 -1
  227. package/dist/server/handlers/mcp.js +1 -1
  228. package/dist/server/handlers/memory.cjs +1 -1
  229. package/dist/server/handlers/memory.d.ts +52 -0
  230. package/dist/server/handlers/memory.d.ts.map +1 -1
  231. package/dist/server/handlers/memory.js +1 -1
  232. package/dist/server/handlers/observability-new-endpoints.cjs +1 -1
  233. package/dist/server/handlers/observability-new-endpoints.d.ts +163 -3
  234. package/dist/server/handlers/observability-new-endpoints.d.ts.map +1 -1
  235. package/dist/server/handlers/observability-new-endpoints.js +1 -1
  236. package/dist/server/handlers/observability-shared.cjs +8 -1
  237. package/dist/server/handlers/observability-shared.cjs.map +1 -1
  238. package/dist/server/handlers/observability-shared.d.ts +13 -0
  239. package/dist/server/handlers/observability-shared.d.ts.map +1 -1
  240. package/dist/server/handlers/observability-shared.js +7 -2
  241. package/dist/server/handlers/observability-shared.js.map +1 -1
  242. package/dist/server/handlers/observability-signal-context.cjs +1 -1
  243. package/dist/server/handlers/observability-signal-context.js +1 -1
  244. package/dist/server/handlers/observability.cjs +2 -2
  245. package/dist/server/handlers/observability.d.ts +12 -0
  246. package/dist/server/handlers/observability.d.ts.map +1 -1
  247. package/dist/server/handlers/observability.js +2 -2
  248. package/dist/server/handlers/plans.cjs +1 -1
  249. package/dist/server/handlers/plans.d.ts +2 -0
  250. package/dist/server/handlers/plans.d.ts.map +1 -1
  251. package/dist/server/handlers/plans.js +1 -1
  252. package/dist/server/handlers/processor-providers.cjs +1 -1
  253. package/dist/server/handlers/processor-providers.d.ts +4 -0
  254. package/dist/server/handlers/processor-providers.d.ts.map +1 -1
  255. package/dist/server/handlers/processor-providers.js +1 -1
  256. package/dist/server/handlers/processors.cjs +57 -6
  257. package/dist/server/handlers/processors.cjs.map +1 -1
  258. package/dist/server/handlers/processors.d.ts +6 -0
  259. package/dist/server/handlers/processors.d.ts.map +1 -1
  260. package/dist/server/handlers/processors.js +57 -6
  261. package/dist/server/handlers/processors.js.map +1 -1
  262. package/dist/server/handlers/prompt-block-versions.cjs +2 -2
  263. package/dist/server/handlers/prompt-block-versions.d.ts +14 -0
  264. package/dist/server/handlers/prompt-block-versions.d.ts.map +1 -1
  265. package/dist/server/handlers/prompt-block-versions.js +2 -2
  266. package/dist/server/handlers/responses.cjs +1 -1
  267. package/dist/server/handlers/responses.d.ts +17 -11
  268. package/dist/server/handlers/responses.d.ts.map +1 -1
  269. package/dist/server/handlers/responses.js +1 -1
  270. package/dist/server/handlers/responses.storage.cjs +4 -3
  271. package/dist/server/handlers/responses.storage.cjs.map +1 -1
  272. package/dist/server/handlers/responses.storage.d.ts.map +1 -1
  273. package/dist/server/handlers/responses.storage.js +4 -3
  274. package/dist/server/handlers/responses.storage.js.map +1 -1
  275. package/dist/server/handlers/schedules.cjs +1 -1
  276. package/dist/server/handlers/schedules.d.ts +18 -0
  277. package/dist/server/handlers/schedules.d.ts.map +1 -1
  278. package/dist/server/handlers/schedules.js +1 -1
  279. package/dist/server/handlers/scorer-versions.cjs +2 -2
  280. package/dist/server/handlers/scorer-versions.d.ts +14 -0
  281. package/dist/server/handlers/scorer-versions.d.ts.map +1 -1
  282. package/dist/server/handlers/scorer-versions.js +2 -2
  283. package/dist/server/handlers/scores.cjs +1 -1
  284. package/dist/server/handlers/scores.d.ts +12 -0
  285. package/dist/server/handlers/scores.d.ts.map +1 -1
  286. package/dist/server/handlers/scores.js +1 -1
  287. package/dist/server/handlers/stored-agent-favorites.cjs +3 -3
  288. package/dist/server/handlers/stored-agent-favorites.d.ts +4 -0
  289. package/dist/server/handlers/stored-agent-favorites.d.ts.map +1 -1
  290. package/dist/server/handlers/stored-agent-favorites.js +3 -3
  291. package/dist/server/handlers/stored-agents.cjs +41 -3
  292. package/dist/server/handlers/stored-agents.cjs.map +1 -1
  293. package/dist/server/handlers/stored-agents.d.ts +14 -0
  294. package/dist/server/handlers/stored-agents.d.ts.map +1 -1
  295. package/dist/server/handlers/stored-agents.js +41 -3
  296. package/dist/server/handlers/stored-agents.js.map +1 -1
  297. package/dist/server/handlers/stored-mcp-clients.cjs +2 -2
  298. package/dist/server/handlers/stored-mcp-clients.d.ts +10 -0
  299. package/dist/server/handlers/stored-mcp-clients.d.ts.map +1 -1
  300. package/dist/server/handlers/stored-mcp-clients.js +2 -2
  301. package/dist/server/handlers/stored-prompt-blocks.cjs +2 -2
  302. package/dist/server/handlers/stored-prompt-blocks.d.ts +10 -0
  303. package/dist/server/handlers/stored-prompt-blocks.d.ts.map +1 -1
  304. package/dist/server/handlers/stored-prompt-blocks.js +2 -2
  305. package/dist/server/handlers/stored-scorers.cjs +2 -2
  306. package/dist/server/handlers/stored-scorers.d.ts +10 -0
  307. package/dist/server/handlers/stored-scorers.d.ts.map +1 -1
  308. package/dist/server/handlers/stored-scorers.js +2 -2
  309. package/dist/server/handlers/stored-skill-favorites.cjs +3 -3
  310. package/dist/server/handlers/stored-skill-favorites.d.ts +4 -0
  311. package/dist/server/handlers/stored-skill-favorites.d.ts.map +1 -1
  312. package/dist/server/handlers/stored-skill-favorites.js +3 -3
  313. package/dist/server/handlers/stored-skills.cjs +3 -3
  314. package/dist/server/handlers/stored-skills.d.ts +12 -0
  315. package/dist/server/handlers/stored-skills.d.ts.map +1 -1
  316. package/dist/server/handlers/stored-skills.js +3 -3
  317. package/dist/server/handlers/stored-workspaces.cjs +2 -2
  318. package/dist/server/handlers/stored-workspaces.d.ts +10 -0
  319. package/dist/server/handlers/stored-workspaces.d.ts.map +1 -1
  320. package/dist/server/handlers/stored-workspaces.js +2 -2
  321. package/dist/server/handlers/system.cjs +3 -3
  322. package/dist/server/handlers/system.d.ts +6 -0
  323. package/dist/server/handlers/system.d.ts.map +1 -1
  324. package/dist/server/handlers/system.js +3 -3
  325. package/dist/server/handlers/tool-providers.cjs +2 -2
  326. package/dist/server/handlers/tool-providers.d.ts +26 -0
  327. package/dist/server/handlers/tool-providers.d.ts.map +1 -1
  328. package/dist/server/handlers/tool-providers.js +2 -2
  329. package/dist/server/handlers/tools.cjs +2 -1
  330. package/dist/server/handlers/tools.d.ts +20 -0
  331. package/dist/server/handlers/tools.d.ts.map +1 -1
  332. package/dist/server/handlers/tools.js +1 -1
  333. package/dist/server/handlers/utils.cjs +1 -1
  334. package/dist/server/handlers/utils.js +1 -1
  335. package/dist/server/handlers/validate-agent-instructions.cjs +1 -1
  336. package/dist/server/handlers/validate-agent-instructions.js +1 -1
  337. package/dist/server/handlers/vector.cjs +1 -1
  338. package/dist/server/handlers/vector.d.ts +16 -0
  339. package/dist/server/handlers/vector.d.ts.map +1 -1
  340. package/dist/server/handlers/vector.js +1 -1
  341. package/dist/server/handlers/voice.cjs +1 -1
  342. package/dist/server/handlers/voice.d.ts.map +1 -1
  343. package/dist/server/handlers/voice.js +1 -1
  344. package/dist/server/handlers/workflow-builder.cjs +1 -1
  345. package/dist/server/handlers/workflow-builder.d.ts +4 -0
  346. package/dist/server/handlers/workflow-builder.d.ts.map +1 -1
  347. package/dist/server/handlers/workflow-builder.js +1 -1
  348. package/dist/server/handlers/workflows.cjs +2 -1
  349. package/dist/server/handlers/workflows.d.ts +57 -0
  350. package/dist/server/handlers/workflows.d.ts.map +1 -1
  351. package/dist/server/handlers/workflows.js +1 -1
  352. package/dist/server/handlers/workspace.cjs +1 -1
  353. package/dist/server/handlers/workspace.d.ts +103 -23
  354. package/dist/server/handlers/workspace.d.ts.map +1 -1
  355. package/dist/server/handlers/workspace.js +1 -1
  356. package/dist/server/handlers.cjs +17 -17
  357. package/dist/server/handlers.js +17 -17
  358. package/dist/server/mcp/capabilities.d.ts +25 -0
  359. package/dist/server/mcp/capabilities.d.ts.map +1 -0
  360. package/dist/server/mcp/catalogue.d.ts +76 -0
  361. package/dist/server/mcp/catalogue.d.ts.map +1 -0
  362. package/dist/server/mcp/config.d.ts +49 -0
  363. package/dist/server/mcp/config.d.ts.map +1 -0
  364. package/dist/server/mcp/descriptor.d.ts +40 -0
  365. package/dist/server/mcp/descriptor.d.ts.map +1 -0
  366. package/dist/server/mcp/oauth.d.ts +46 -0
  367. package/dist/server/mcp/oauth.d.ts.map +1 -0
  368. package/dist/server/mcp/result-size.d.ts +26 -0
  369. package/dist/server/mcp/result-size.d.ts.map +1 -0
  370. package/dist/server/mcp/route.d.ts +21 -0
  371. package/dist/server/mcp/route.d.ts.map +1 -0
  372. package/dist/server/mcp/schema.d.ts +13 -0
  373. package/dist/server/mcp/schema.d.ts.map +1 -0
  374. package/dist/server/mcp/toolsets/memory.d.ts +8 -0
  375. package/dist/server/mcp/toolsets/memory.d.ts.map +1 -0
  376. package/dist/server/mcp/toolsets/observability.d.ts +4 -0
  377. package/dist/server/mcp/toolsets/observability.d.ts.map +1 -0
  378. package/dist/server/mcp/toolsets/stored-agents.d.ts +8 -0
  379. package/dist/server/mcp/toolsets/stored-agents.d.ts.map +1 -0
  380. package/dist/server/schemas/agents.d.ts +1 -1
  381. package/dist/server/schemas/datasets.d.ts +10 -0
  382. package/dist/server/schemas/datasets.d.ts.map +1 -1
  383. package/dist/server/schemas/index.cjs +10 -11
  384. package/dist/server/schemas/index.js +4 -5
  385. package/dist/server/schemas/system.d.ts +2 -0
  386. package/dist/server/schemas/system.d.ts.map +1 -1
  387. package/dist/server/server-adapter/api-schema-manifest.d.ts +1 -1
  388. package/dist/server/server-adapter/index.cjs +45 -1831
  389. package/dist/server/server-adapter/index.d.ts +126 -3
  390. package/dist/server/server-adapter/index.d.ts.map +1 -1
  391. package/dist/server/server-adapter/index.js +7 -1805
  392. package/dist/server/server-adapter/openapi-utils.d.ts +2 -2
  393. package/dist/server/server-adapter/openapi-utils.d.ts.map +1 -1
  394. package/dist/server/server-adapter/routes/a2a.d.ts +4 -0
  395. package/dist/server/server-adapter/routes/a2a.d.ts.map +1 -1
  396. package/dist/server/server-adapter/routes/agent-builder.d.ts +32 -0
  397. package/dist/server/server-adapter/routes/agent-builder.d.ts.map +1 -1
  398. package/dist/server/server-adapter/routes/channels.d.ts +10 -0
  399. package/dist/server/server-adapter/routes/channels.d.ts.map +1 -1
  400. package/dist/server/server-adapter/routes/conversations.d.ts +11 -3
  401. package/dist/server/server-adapter/routes/conversations.d.ts.map +1 -1
  402. package/dist/server/server-adapter/routes/datasets.d.ts +86 -0
  403. package/dist/server/server-adapter/routes/datasets.d.ts.map +1 -1
  404. package/dist/server/server-adapter/routes/editor-builder.d.ts +20 -0
  405. package/dist/server/server-adapter/routes/editor-builder.d.ts.map +1 -1
  406. package/dist/server/server-adapter/routes/index.d.ts +26 -1
  407. package/dist/server/server-adapter/routes/index.d.ts.map +1 -1
  408. package/dist/server/server-adapter/routes/knowledge.d.ts +18 -0
  409. package/dist/server/server-adapter/routes/knowledge.d.ts.map +1 -1
  410. package/dist/server/server-adapter/routes/legacy.d.ts +8 -0
  411. package/dist/server/server-adapter/routes/legacy.d.ts.map +1 -1
  412. package/dist/server/server-adapter/routes/logs.d.ts +6 -0
  413. package/dist/server/server-adapter/routes/logs.d.ts.map +1 -1
  414. package/dist/server/server-adapter/routes/mcp.d.ts +37 -1
  415. package/dist/server/server-adapter/routes/mcp.d.ts.map +1 -1
  416. package/dist/server/server-adapter/routes/memory.d.ts +52 -0
  417. package/dist/server/server-adapter/routes/memory.d.ts.map +1 -1
  418. package/dist/server/server-adapter/routes/observability.d.ts +97 -1
  419. package/dist/server/server-adapter/routes/observability.d.ts.map +1 -1
  420. package/dist/server/server-adapter/routes/processor-providers.d.ts +4 -0
  421. package/dist/server/server-adapter/routes/processor-providers.d.ts.map +1 -1
  422. package/dist/server/server-adapter/routes/processors.d.ts +6 -0
  423. package/dist/server/server-adapter/routes/processors.d.ts.map +1 -1
  424. package/dist/server/server-adapter/routes/responses.d.ts +6 -0
  425. package/dist/server/server-adapter/routes/responses.d.ts.map +1 -1
  426. package/dist/server/server-adapter/routes/route-builder.d.ts +5 -1
  427. package/dist/server/server-adapter/routes/route-builder.d.ts.map +1 -1
  428. package/dist/server/server-adapter/routes/scorers.d.ts +12 -0
  429. package/dist/server/server-adapter/routes/scorers.d.ts.map +1 -1
  430. package/dist/server/server-adapter/routes/stored-mcp-clients.d.ts +24 -0
  431. package/dist/server/server-adapter/routes/stored-mcp-clients.d.ts.map +1 -1
  432. package/dist/server/server-adapter/routes/stored-prompt-blocks.d.ts +24 -0
  433. package/dist/server/server-adapter/routes/stored-prompt-blocks.d.ts.map +1 -1
  434. package/dist/server/server-adapter/routes/stored-scorers.d.ts +24 -0
  435. package/dist/server/server-adapter/routes/stored-scorers.d.ts.map +1 -1
  436. package/dist/server/server-adapter/routes/stored-skills.d.ts +16 -0
  437. package/dist/server/server-adapter/routes/stored-skills.d.ts.map +1 -1
  438. package/dist/server/server-adapter/routes/stored-workspaces.d.ts +10 -0
  439. package/dist/server/server-adapter/routes/stored-workspaces.d.ts.map +1 -1
  440. package/dist/server/server-adapter/routes/system.d.ts +6 -0
  441. package/dist/server/server-adapter/routes/system.d.ts.map +1 -1
  442. package/dist/server/server-adapter/routes/tool-providers.d.ts +26 -0
  443. package/dist/server/server-adapter/routes/tool-providers.d.ts.map +1 -1
  444. package/dist/server/server-adapter/routes/tools.d.ts +6 -0
  445. package/dist/server/server-adapter/routes/tools.d.ts.map +1 -1
  446. package/dist/server/server-adapter/routes/vectors.d.ts +16 -0
  447. package/dist/server/server-adapter/routes/vectors.d.ts.map +1 -1
  448. package/dist/server/server-adapter/routes/workflows.d.ts +50 -0
  449. package/dist/server/server-adapter/routes/workflows.d.ts.map +1 -1
  450. package/dist/server/server-adapter/routes/workspace.d.ts +42 -0
  451. package/dist/server/server-adapter/routes/workspace.d.ts.map +1 -1
  452. package/dist/server-adapter-B7dLE5si.cjs +2386 -0
  453. package/dist/server-adapter-B7dLE5si.cjs.map +1 -0
  454. package/dist/server-adapter-BywLWVKp.js +2189 -0
  455. package/dist/server-adapter-BywLWVKp.js.map +1 -0
  456. package/dist/{system-zL047vEq.cjs → system-DdMSBAOY.cjs} +2 -1
  457. package/dist/system-DdMSBAOY.cjs.map +1 -0
  458. package/dist/{system-DlW760k2.js → system-FnU7vyxd.js} +2 -1
  459. package/dist/system-FnU7vyxd.js.map +1 -0
  460. package/dist/{tools-Daot5Zgz.cjs → tools-CawMeeZg.cjs} +71 -29
  461. package/dist/tools-CawMeeZg.cjs.map +1 -0
  462. package/dist/{tools-BJFq9JKF.js → tools-oHRh4msa.js} +65 -29
  463. package/dist/tools-oHRh4msa.js.map +1 -0
  464. package/dist/{utils-yedETkNk.js → utils-BfySxdfF.js} +3 -3
  465. package/dist/{utils-yedETkNk.js.map → utils-BfySxdfF.js.map} +1 -1
  466. package/dist/{utils-BXEJ6FZC.cjs → utils-DFhesFfA.cjs} +2 -2
  467. package/dist/{utils-BXEJ6FZC.cjs.map → utils-DFhesFfA.cjs.map} +1 -1
  468. package/dist/{utils-DptI_ERr.cjs → utils-Dn_OA_6N.cjs} +6 -6
  469. package/dist/{utils-DptI_ERr.cjs.map → utils-Dn_OA_6N.cjs.map} +1 -1
  470. package/dist/{utils-CTYtskHa.js → utils-Dv1D6ob-.js} +2 -2
  471. package/dist/{utils-CTYtskHa.js.map → utils-Dv1D6ob-.js.map} +1 -1
  472. package/dist/{vector-CZ26vo6u.js → vector-Bz-glead.js} +2 -2
  473. package/dist/{vector-CZ26vo6u.js.map → vector-Bz-glead.js.map} +1 -1
  474. package/dist/{vector-DBe45tnv.cjs → vector-DIFU_fwU.cjs} +2 -2
  475. package/dist/{vector-DBe45tnv.cjs.map → vector-DIFU_fwU.cjs.map} +1 -1
  476. package/dist/voice-C6bAqs79.js +42 -0
  477. package/dist/voice-C6bAqs79.js.map +1 -0
  478. package/dist/{voice-CBbxcsCM.cjs → voice-Dk0O5mVD.cjs} +29 -9
  479. package/dist/voice-Dk0O5mVD.cjs.map +1 -0
  480. package/dist/{workflow-builder-CkrdTcoM.cjs → workflow-builder-BPUjAdaC.cjs} +5 -5
  481. package/dist/{workflow-builder-CkrdTcoM.cjs.map → workflow-builder-BPUjAdaC.cjs.map} +1 -1
  482. package/dist/{workflow-builder-C5ufahUw.js → workflow-builder-D2fwGsLw.js} +5 -5
  483. package/dist/{workflow-builder-C5ufahUw.js.map → workflow-builder-D2fwGsLw.js.map} +1 -1
  484. package/dist/{workflows-C_Mqj_80.js → workflows-B-QJ0Tnv.js} +38 -7
  485. package/dist/workflows-B-QJ0Tnv.js.map +1 -0
  486. package/dist/{workflows-B5uWFrJ1.cjs → workflows-CwkEHIKW.cjs} +43 -6
  487. package/dist/workflows-CwkEHIKW.cjs.map +1 -0
  488. package/dist/{workspace-BwlPQO3M.js → workspace-CbTB2svI.js} +99 -41
  489. package/dist/workspace-CbTB2svI.js.map +1 -0
  490. package/dist/{workspace-CD9pQ61P.cjs → workspace-CsPtSXQd.cjs} +99 -41
  491. package/dist/workspace-CsPtSXQd.cjs.map +1 -0
  492. package/package.json +17 -10
  493. package/dist/a2a-DIcMx6x-.cjs.map +0 -1
  494. package/dist/a2a-DTTGA2Xg.js.map +0 -1
  495. package/dist/agents-BCgiMlDq.js.map +0 -1
  496. package/dist/agents-CTgjTASj.js.map +0 -1
  497. package/dist/agents-CjcvdF2e.cjs.map +0 -1
  498. package/dist/agents-DjpBmwhv.cjs.map +0 -1
  499. package/dist/api-schema-manifest-B8s3TuPU.js.map +0 -1
  500. package/dist/api-schema-manifest-Czr4Bmrw.cjs.map +0 -1
  501. package/dist/constants-CXAvBYcz.js.map +0 -1
  502. package/dist/constants-DMg8hUOR.cjs.map +0 -1
  503. package/dist/conversations-BFqmDglO.cjs.map +0 -1
  504. package/dist/conversations-BkX00xDs.js.map +0 -1
  505. package/dist/datasets--F0QkdGX.js.map +0 -1
  506. package/dist/datasets-BiEAIm0s.cjs.map +0 -1
  507. package/dist/dist-tbh2LUPc.js +0 -1
  508. package/dist/editor-builder-C4H2l6tz.js.map +0 -1
  509. package/dist/editor-builder-Cqw1npOK.cjs.map +0 -1
  510. package/dist/helpers-0LJI4DxR.cjs.map +0 -1
  511. package/dist/helpers-C9QZKOhz.js.map +0 -1
  512. package/dist/memory-BRE3ofvI.cjs.map +0 -1
  513. package/dist/memory-Dw7xG5nn.js.map +0 -1
  514. package/dist/observability-BYIy4kPf.js.map +0 -1
  515. package/dist/observability-DHJ7mzoE.cjs.map +0 -1
  516. package/dist/observability-new-endpoints-BOe3wej1.cjs.map +0 -1
  517. package/dist/observability-new-endpoints-COy7lpeR.js.map +0 -1
  518. package/dist/plans-D_GKFz2x.js.map +0 -1
  519. package/dist/plans-_nR8lqgD.cjs.map +0 -1
  520. package/dist/responses-C_OEJoxU.js.map +0 -1
  521. package/dist/responses-CdWbS4jA.cjs.map +0 -1
  522. package/dist/routes-CtGp_lBn.cjs +0 -523
  523. package/dist/routes-CtGp_lBn.cjs.map +0 -1
  524. package/dist/routes-Cu4-Al-k.js.map +0 -1
  525. package/dist/routes-D3T0BV1r.cjs.map +0 -1
  526. package/dist/routes-MRZFTKei.js +0 -446
  527. package/dist/routes-MRZFTKei.js.map +0 -1
  528. package/dist/schedules-BQvnAe1j.cjs.map +0 -1
  529. package/dist/schedules-BcAIELfB.js.map +0 -1
  530. package/dist/scores-DEvPN0kz.cjs.map +0 -1
  531. package/dist/scores-Dm0yu1Pt.js.map +0 -1
  532. package/dist/server/server-adapter/index.cjs.map +0 -1
  533. package/dist/server/server-adapter/index.js.map +0 -1
  534. package/dist/system-DlW760k2.js.map +0 -1
  535. package/dist/system-zL047vEq.cjs.map +0 -1
  536. package/dist/tools-BJFq9JKF.js.map +0 -1
  537. package/dist/tools-Daot5Zgz.cjs.map +0 -1
  538. package/dist/voice-CBbxcsCM.cjs.map +0 -1
  539. package/dist/voice-CzFWhWPJ.js +0 -22
  540. package/dist/voice-CzFWhWPJ.js.map +0 -1
  541. package/dist/workflows-B5uWFrJ1.cjs.map +0 -1
  542. package/dist/workflows-C_Mqj_80.js.map +0 -1
  543. package/dist/workspace-BwlPQO3M.js.map +0 -1
  544. package/dist/workspace-CD9pQ61P.cjs.map +0 -1
  545. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/@internal_core@0.1.4/dist/routes/index.d.ts +0 -0
  546. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/@internal_core@0.1.4/dist/types/index.d.ts +0 -0
  547. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/classic/checks.d.ts +0 -0
  548. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/classic/coerce.d.ts +0 -0
  549. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/classic/compat.d.ts +0 -0
  550. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/classic/deep-partial.d.ts +0 -0
  551. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/classic/errors.d.ts +0 -0
  552. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/classic/external.d.ts +0 -0
  553. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/classic/from-json-schema.d.ts +0 -0
  554. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/classic/in-out.d.ts +0 -0
  555. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/classic/index.d.ts +0 -0
  556. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/classic/iso.d.ts +0 -0
  557. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/classic/parse.d.ts +0 -0
  558. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/classic/schemas.d.ts +0 -0
  559. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/core/api.d.ts +0 -0
  560. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/core/checks.d.ts +0 -0
  561. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/core/compile.d.ts +0 -0
  562. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/core/core.d.ts +0 -0
  563. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/core/doc.d.ts +0 -0
  564. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/core/errors.d.ts +0 -0
  565. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/core/index.d.ts +0 -0
  566. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/core/json-schema-generator.d.ts +0 -0
  567. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/core/json-schema-processors.d.ts +0 -0
  568. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/core/json-schema.d.ts +0 -0
  569. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/core/memoizer.d.ts +0 -0
  570. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/core/parse.d.ts +0 -0
  571. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/core/regexes.d.ts +0 -0
  572. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/core/registries.d.ts +0 -0
  573. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/core/schemas.d.ts +0 -0
  574. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/core/standard-schema.d.ts +0 -0
  575. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/core/to-json-schema.d.ts +0 -0
  576. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/core/util.d.ts +0 -0
  577. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/core/versions.d.ts +0 -0
  578. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/index.d.cts +0 -0
  579. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/ar.d.ts +0 -0
  580. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/az.d.ts +0 -0
  581. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/be.d.ts +0 -0
  582. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/bg.d.ts +0 -0
  583. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/bn.d.ts +0 -0
  584. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/ca.d.ts +0 -0
  585. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/ckb.d.ts +0 -0
  586. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/cs.d.ts +0 -0
  587. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/da.d.ts +0 -0
  588. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/de.d.ts +0 -0
  589. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/el.d.ts +0 -0
  590. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/en.d.ts +0 -0
  591. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/eo.d.ts +0 -0
  592. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/es.d.ts +0 -0
  593. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/fa.d.ts +0 -0
  594. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/fi.d.ts +0 -0
  595. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/fr-CA.d.ts +0 -0
  596. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/fr.d.ts +0 -0
  597. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/gu.d.ts +0 -0
  598. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/he.d.ts +0 -0
  599. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/hi.d.ts +0 -0
  600. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/hr.d.ts +0 -0
  601. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/hu.d.ts +0 -0
  602. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/hy.d.ts +0 -0
  603. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/id.d.ts +0 -0
  604. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/index.d.ts +0 -0
  605. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/is.d.ts +0 -0
  606. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/it.d.ts +0 -0
  607. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/ja.d.ts +0 -0
  608. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/ka.d.ts +0 -0
  609. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/kh.d.ts +0 -0
  610. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/km.d.ts +0 -0
  611. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/kn.d.ts +0 -0
  612. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/ko.d.ts +0 -0
  613. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/lt.d.ts +0 -0
  614. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/mk.d.ts +0 -0
  615. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/ms.d.ts +0 -0
  616. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/ne.d.ts +0 -0
  617. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/nl.d.ts +0 -0
  618. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/nn.d.ts +0 -0
  619. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/no.d.ts +0 -0
  620. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/ota.d.ts +0 -0
  621. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/pl.d.ts +0 -0
  622. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/ps.d.ts +0 -0
  623. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/pt-BR.d.ts +0 -0
  624. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/pt.d.ts +0 -0
  625. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/ro.d.ts +0 -0
  626. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/ru.d.ts +0 -0
  627. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/sk.d.ts +0 -0
  628. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/sl.d.ts +0 -0
  629. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/sv.d.ts +0 -0
  630. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/ta.d.ts +0 -0
  631. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/tg.d.ts +0 -0
  632. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/th.d.ts +0 -0
  633. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/tk.d.ts +0 -0
  634. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/tr.d.ts +0 -0
  635. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/ua.d.ts +0 -0
  636. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/uk.d.ts +0 -0
  637. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/ur.d.ts +0 -0
  638. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/uz.d.ts +0 -0
  639. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/vi.d.ts +0 -0
  640. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/yo.d.ts +0 -0
  641. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/zh-CN.d.ts +0 -0
  642. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/_types/zod@4.6.7/v4/locales/zh-TW.d.ts +0 -0
  643. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/dist/routes/index.d.ts +0 -0
  644. /package/dist/_types/{@internal_voice@0.0.44 → @internal_voice@0.0.45}/package.json +0 -0
  645. /package/dist/_types/{@mastra_schema-compat@1.4.0-alpha.1/dist/_types/@internal_ai-sdk-v4@0.0.95 → @mastra_schema-compat@1.4.0/dist/_types/@internal_ai-sdk-v4@0.0.96}/dist/index.d.ts +0 -0
  646. /package/dist/_types/{@mastra_schema-compat@1.4.0-alpha.1/dist/_types/@internal_ai-sdk-v5@0.0.95 → @mastra_schema-compat@1.4.0/dist/_types/@internal_ai-sdk-v5@0.0.96}/dist/index.d.ts +0 -0
  647. /package/dist/_types/{@mastra_schema-compat@1.4.0-alpha.1/dist/_types/@internal_ai-v6@0.0.95 → @mastra_schema-compat@1.4.0/dist/_types/@internal_ai-v6@0.0.96}/dist/index.d.ts +0 -0
  648. /package/dist/_types/{@mastra_schema-compat@1.4.0-alpha.1 → @mastra_schema-compat@1.4.0}/dist/_types/@standard-schema_spec@1.1.0/dist/index.d.ts +0 -0
  649. /package/dist/_types/{@mastra_schema-compat@1.4.0-alpha.1 → @mastra_schema-compat@1.4.0}/dist/_types/@types_json-schema@7.0.15/index.d.ts +0 -0
  650. /package/dist/_types/{@mastra_schema-compat@1.4.0-alpha.1 → @mastra_schema-compat@1.4.0}/dist/index.d.ts +0 -0
  651. /package/dist/_types/{@mastra_schema-compat@1.4.0-alpha.1 → @mastra_schema-compat@1.4.0}/dist/null-to-undefined.d.ts +0 -0
  652. /package/dist/_types/{@mastra_schema-compat@1.4.0-alpha.1 → @mastra_schema-compat@1.4.0}/dist/provider-compats/google.d.ts +0 -0
  653. /package/dist/_types/{@mastra_schema-compat@1.4.0-alpha.1 → @mastra_schema-compat@1.4.0}/dist/provider-compats/openai-reasoning.d.ts +0 -0
  654. /package/dist/_types/{@mastra_schema-compat@1.4.0-alpha.1 → @mastra_schema-compat@1.4.0}/dist/provider-compats/openai.d.ts +0 -0
  655. /package/dist/_types/{@mastra_schema-compat@1.4.0-alpha.1 → @mastra_schema-compat@1.4.0}/dist/schema-compatibility-v3.d.ts +0 -0
  656. /package/dist/_types/{@mastra_schema-compat@1.4.0-alpha.1 → @mastra_schema-compat@1.4.0}/dist/schema-compatibility-v4.d.ts +0 -0
  657. /package/dist/_types/{@mastra_schema-compat@1.4.0-alpha.1 → @mastra_schema-compat@1.4.0}/dist/schema-compatibility.d.ts +0 -0
  658. /package/dist/_types/{@mastra_schema-compat@1.4.0-alpha.1 → @mastra_schema-compat@1.4.0}/dist/schema.d.ts +0 -0
  659. /package/dist/_types/{@mastra_schema-compat@1.4.0-alpha.1 → @mastra_schema-compat@1.4.0}/dist/standard-schema/standard-schema.d.ts +0 -0
  660. /package/dist/_types/{@mastra_schema-compat@1.4.0-alpha.1 → @mastra_schema-compat@1.4.0}/dist/standard-schema/standard-schema.types.d.ts +0 -0
  661. /package/dist/_types/{@mastra_schema-compat@1.4.0-alpha.1 → @mastra_schema-compat@1.4.0}/dist/standard-schema-compat.d.ts +0 -0
  662. /package/dist/_types/{@mastra_schema-compat@1.4.0-alpha.1 → @mastra_schema-compat@1.4.0}/dist/types.d.ts +0 -0
  663. /package/dist/_types/{@mastra_schema-compat@1.4.0-alpha.1 → @mastra_schema-compat@1.4.0}/dist/utils.d.ts +0 -0
  664. /package/dist/_types/{@mastra_schema-compat@1.4.0-alpha.1 → @mastra_schema-compat@1.4.0}/dist/zod-to-json.d.ts +0 -0
  665. /package/dist/_types/{@mastra_schema-compat@1.4.0-alpha.1 → @mastra_schema-compat@1.4.0}/package.json +0 -0
@@ -1,1806 +1,8 @@
1
- import { a as findMatchingCustomRoute, f as pathMatchesPattern, g as CustomRouteMatcher, i as coreAuthMiddleware, l as isProtectedCustomRoute, s as isCustomRoutePublic, t as authorizeAuthenticatedUser } from "../../helpers-C9QZKOhz.js";
2
- import { a as MASTRA_KNOWLEDGE_PRINCIPALS_KEY, c as MASTRA_STUDIO_CLIENT_TYPE, d as MASTRA_USER_PERMISSIONS_KEY, g as isStudioClientTypeHeader, h as isReservedRequestContextKey, i as MASTRA_IS_STUDIO_KEY, n as MASTRA_AUTH_TOKEN_KEY, p as RESERVED_REQUEST_CONTEXT_KEYS, r as MASTRA_CLIENT_TYPE_HEADER, s as MASTRA_RESOURCE_ID_KEY$1, t as MASTRA_AUTH_MODE_KEY, u as MASTRA_USER_KEY } from "../../constants-CXAvBYcz.js";
3
- import { formatZodError, isZodError } from "../handlers/error.js";
4
1
  import { t as HTTPException } from "../../http-exception-CzaWkxMl.js";
5
- import { o as normalizeRoutePath, t as WorkflowRegistry } from "../../utils-yedETkNk.js";
6
- import { a as wrapSchemaForQueryParams, i as pickParams, n as createRoute, o as convertCustomRoutesToOpenAPIPaths, r as jsonQueryParam, s as generateOpenAPIDocument, t as createPublicRoute } from "../../route-builder-DfDT1g4L.js";
7
- import { i as KNOWLEDGE_ROUTES, n as OPT_IN_ROUTES, r as SERVER_ROUTES, t as ALL_SERVER_ROUTES } from "../../routes-Cu4-Al-k.js";
8
- import { z } from "zod/v4";
9
- import { Readable } from "stream";
10
- import { hasPermission } from "@mastra/core/auth/ee";
11
- import { RequestContext } from "@mastra/core/request-context";
12
- import { MastraServerBase } from "@mastra/core/server";
13
- import { Hono } from "hono";
14
- import { safeStringify } from "@mastra/core/utils";
15
- import { pipeline } from "stream/promises";
16
- // src/server/server-adapter/routes/permissions.ts
17
- /**
18
- * Map HTTP methods to permission actions.
19
- * POST is context-dependent (write for data, execute for operations).
20
- */
21
- const METHOD_TO_ACTION = {
22
- GET: "read",
23
- POST: "write",
24
- PUT: "write",
25
- PATCH: "write",
26
- DELETE: "delete"
27
- };
28
- /**
29
- * Path patterns that indicate an "execute" action rather than "write" for POST requests.
30
- * These are typically operation endpoints rather than data creation endpoints.
31
- */
32
- const EXECUTE_PATTERNS = [
33
- "/generate",
34
- "/stream",
35
- "/execute",
36
- "/start",
37
- "/resume",
38
- "/restart",
39
- "/cancel",
40
- "/approve",
41
- "/decline",
42
- "/speak",
43
- "/listen",
44
- "/query",
45
- "/search",
46
- "/observe",
47
- "/time-travel",
48
- "/enhance",
49
- "/clone"
50
- ];
51
- const PUBLISH_PATTERNS = [
52
- "/publish",
53
- "/activate",
54
- "/restore"
55
- ];
56
- /**
57
- * Maps `/stored/<family>` URL segments to canonical permission resource slugs.
58
- */
59
- const STORED_RESOURCE_SEGMENTS = {
60
- agents: "stored-agents",
61
- "mcp-clients": "stored-mcp-clients",
62
- "prompt-blocks": "stored-prompt-blocks",
63
- scorers: "stored-scorers",
64
- skills: "stored-skills",
65
- workspaces: "stored-workspaces"
66
- };
67
- /**
68
- * Extracts the primary resource name from a route path.
69
- *
70
- * The resource is derived from the first path segment, with special handling
71
- * for compound resources and well-known paths.
72
- *
73
- * Note: The canonical list of resources is generated in permissions.generated.ts
74
- * from SERVER_ROUTES via `pnpm generate:permissions`.
75
- *
76
- * @param path - The route path (e.g., '/agents/:agentId/generate')
77
- * @returns The resource name (e.g., 'agents') or null if not identifiable
78
- *
79
- * @example
80
- * extractResource('/agents/:agentId') // → 'agents'
81
- * extractResource('/memory/threads/:threadId') // → 'memory'
82
- * extractResource('/stored/agents/:agentId') // → 'stored-agents'
83
- * extractResource('/stored/skills/:skillId') // → 'stored-skills'
84
- */
85
- function extractResource(path) {
86
- const segments = path.replace(/^\//, "").split("/");
87
- if (segments.length === 0) return null;
88
- const firstSegment = segments[0];
89
- if (firstSegment === "stored" && segments[1]) return STORED_RESOURCE_SEGMENTS[segments[1]] ?? null;
90
- if (firstSegment === ".well-known") return "a2a";
91
- return firstSegment || null;
92
- }
93
- /**
94
- * Determines the action based on HTTP method and path context.
95
- *
96
- * @param method - HTTP method (GET, POST, PUT, DELETE, etc.)
97
- * @param path - The route path for context
98
- * @returns The action string (read, write, execute, delete)
99
- */
100
- function deriveAction(method, path) {
101
- const upperMethod = method.toUpperCase();
102
- if (upperMethod === "POST") {
103
- if (path.startsWith("/stored/")) {
104
- if (PUBLISH_PATTERNS.some((pattern) => path.endsWith(pattern))) return "publish";
105
- }
106
- return EXECUTE_PATTERNS.some((pattern) => path.includes(pattern)) ? "execute" : "write";
107
- }
108
- return METHOD_TO_ACTION[upperMethod] || "read";
109
- }
110
- /**
111
- * Derives a permission string from a route's path and method.
112
- *
113
- * Uses convention: `{resource}:{action}`
114
- *
115
- * @param route - The server route to derive permission for
116
- * @returns The derived permission string, or null if cannot be derived
117
- *
118
- * @example
119
- * derivePermission({ path: '/agents', method: 'GET' }) // → 'agents:read'
120
- * derivePermission({ path: '/agents/:id/generate', method: 'POST' }) // → 'agents:execute'
121
- * derivePermission({ path: '/workflows/:id', method: 'DELETE' }) // → 'workflows:delete'
122
- */
123
- function derivePermission(route) {
124
- if (route.method === "ALL") return null;
125
- const resource = extractResource(route.path);
126
- if (!resource) return null;
127
- return `${resource}:${deriveAction(route.method, route.path)}`;
128
- }
129
- /**
130
- * Gets the effective permission for a route.
131
- *
132
- * Priority:
133
- * 1. Explicit requiresPermission on the route (string or string[])
134
- * 2. Derived permission from path/method convention
135
- * 3. null (no permission required - should only happen for public routes)
136
- *
137
- * When the route specifies an array of permissions, the user needs ANY ONE
138
- * of them (logical OR). This is useful for routes that serve multiple
139
- * resource types.
140
- *
141
- * @param route - The server route
142
- * @returns The permission string, array of alternative permissions, or null
143
- */
144
- function getEffectivePermission(route) {
145
- if (route.requiresAuth === false) return null;
146
- if (route.requiresPermission) return route.requiresPermission;
147
- return derivePermission(route);
148
- }
149
- // src/server/server-adapter/routes/fga-manifest.ts
150
- function isProtectedFGARoute$1(route) {
151
- return route.requiresAuth !== false;
152
- }
153
- function getToolRoutePermission(path) {
154
- return path.includes("/execute") ? "tools:execute" : "tools:read";
155
- }
156
- function getAgentToolResourceId(agentId, toolId) {
157
- return `${agentId}:${toolId}`;
158
- }
159
- function getMCPToolResourceId(serverId, toolId) {
160
- return JSON.stringify([serverId, toolId]);
161
- }
162
- const STORED_ROUTE_FGA = {
163
- agents: {
164
- resourceType: "stored-agents",
165
- idParams: ["storedAgentId", "agentId"]
166
- },
167
- "mcp-clients": {
168
- resourceType: "stored-mcp-clients",
169
- idParams: ["storedMCPClientId", "mcpClientId"]
170
- },
171
- "prompt-blocks": {
172
- resourceType: "stored-prompt-blocks",
173
- idParams: ["storedPromptBlockId", "promptBlockId"]
174
- },
175
- scorers: {
176
- resourceType: "stored-scorers",
177
- idParams: ["storedScorerId", "scorerId"]
178
- },
179
- skills: {
180
- resourceType: "stored-skills",
181
- idParams: ["storedSkillId"]
182
- },
183
- workspaces: {
184
- resourceType: "stored-workspaces",
185
- idParams: ["storedWorkspaceId"]
186
- }
187
- };
188
- function getStoredResourceRouteFGAConfig(path, permission) {
189
- const match = path.match(/^\/stored\/([^/]+)/);
190
- if (!match?.[1]) return null;
191
- const config = STORED_ROUTE_FGA[match[1]];
192
- if (!config) return null;
193
- return {
194
- resourceType: config.resourceType,
195
- resourceId: (params, { requestContext }) => {
196
- for (const idParam of config.idParams) {
197
- const id = params[idParam];
198
- if (typeof id === "string" && id) return id;
199
- }
200
- const scopedResourceId = requestContext?.get(MASTRA_RESOURCE_ID_KEY$1);
201
- return typeof scopedResourceId === "string" && scopedResourceId ? scopedResourceId : config.resourceType;
202
- },
203
- permission
204
- };
205
- }
206
- function getBuiltInRouteFGAConfig(route) {
207
- if (!isProtectedFGARoute$1(route) || !route.path || !route.method) return null;
208
- const permission = getEffectivePermission(route);
209
- if (!permission) return null;
210
- const path = route.path;
211
- const storedRouteConfig = getStoredResourceRouteFGAConfig(path, permission);
212
- if (storedRouteConfig) return storedRouteConfig;
213
- if (path.startsWith("/agents/:agentId/tools/:toolId")) return {
214
- resourceType: "tool",
215
- resourceId: ({ agentId, toolId }) => getAgentToolResourceId(String(agentId), String(toolId)),
216
- permission: getToolRoutePermission(path)
217
- };
218
- if (path.startsWith("/agents/:agentId")) return {
219
- resourceType: "agent",
220
- resourceIdParam: "agentId",
221
- permission
222
- };
223
- if (path.startsWith("/workflows/:workflowId")) return {
224
- resourceType: "workflow",
225
- resourceIdParam: "workflowId",
226
- permission
227
- };
228
- if (path.startsWith("/tools/:toolId")) return {
229
- resourceType: "tool",
230
- resourceIdParam: "toolId",
231
- permission
232
- };
233
- if (path.startsWith("/mcp/:serverId/tools/:toolId")) return {
234
- resourceType: "tool",
235
- resourceId: ({ serverId, toolId }) => getMCPToolResourceId(String(serverId), String(toolId)),
236
- permission: getToolRoutePermission(path)
237
- };
238
- if (path.startsWith("/mcp/:serverId")) return {
239
- resourceType: "mcp",
240
- resourceIdParam: "serverId",
241
- permission
242
- };
243
- if (path.startsWith("/knowledge/:knowledgeKey")) return {
244
- resourceType: "knowledge",
245
- resourceIdParam: "knowledgeKey",
246
- permission
247
- };
248
- if (path.startsWith("/memory/threads/:threadId") || path.startsWith("/memory/network/threads/:threadId")) return {
249
- resourceType: "thread",
250
- resourceIdParam: "threadId",
251
- permission
252
- };
253
- if (path === "/memory/threads" || path === "/memory/network/threads") return {
254
- resourceType: "thread",
255
- resourceId: ({ threadId, resourceId }) => {
256
- if (typeof threadId === "string") return threadId;
257
- return typeof resourceId === "string" ? resourceId : void 0;
258
- },
259
- permission
260
- };
261
- if (path === "/memory/save-messages" || path === "/memory/network/save-messages") return {
262
- resourceType: "thread",
263
- resourceId: ({ messages }) => {
264
- if (!Array.isArray(messages)) return void 0;
265
- const threadId = messages.find((message) => message && typeof message === "object" && "threadId" in message)?.threadId;
266
- return typeof threadId === "string" ? threadId : void 0;
267
- },
268
- permission
269
- };
270
- if (path === "/v1/responses") return {
271
- resourceType: "agent",
272
- resourceIdParam: "agent_id",
273
- permission
274
- };
275
- if (path.startsWith("/v1/responses/:responseId")) return {
276
- resourceType: "response",
277
- resourceIdParam: "responseId",
278
- permission
279
- };
280
- if (path === "/v1/conversations") return {
281
- resourceType: "agent",
282
- resourceIdParam: "agent_id",
283
- permission
284
- };
285
- if (path.startsWith("/v1/conversations/:conversationId")) return {
286
- resourceType: "conversation",
287
- resourceIdParam: "conversationId",
288
- permission
289
- };
290
- return null;
291
- }
292
- // src/server/server-adapter/mcp-auth.ts
293
- /**
294
- * Key under which `applyMcpRequestAuth` attaches the trusted request context to
295
- * `req.auth`. `@mastra/mcp` reads the same registered symbol and copies the
296
- * values into the request context its tools receive. A symbol cannot come out
297
- * of a token or JSON payload, so only server code can supply it.
298
- */
299
- const MCP_TRUSTED_REQUEST_CONTEXT = Symbol.for("mastra.mcp.trustedRequestContext");
300
- function normalizeScopes(value) {
301
- if (Array.isArray(value)) return value.filter((s) => typeof s === "string");
302
- if (typeof value === "string") return value.split(/[\s,]+/).filter(Boolean);
303
- return [];
304
- }
305
- function resolveClientId(user) {
306
- for (const key of [
307
- "id",
308
- "sub",
309
- "userId",
310
- "email"
311
- ]) {
312
- const value = user[key];
313
- if (typeof value === "string" && value) return value;
314
- }
315
- return "";
316
- }
317
- /**
318
- * Build the default `AuthInfo` from the Mastra request context.
319
- *
320
- * Returns `undefined` when the request carries no identity at all, so servers
321
- * without auth keep behaving exactly as before.
322
- */
323
- function buildMcpAuthInfoFromRequestContext(requestContext) {
324
- const user = requestContext.get(MASTRA_USER_KEY);
325
- const token = requestContext.get(MASTRA_AUTH_TOKEN_KEY);
326
- const hasUser = !!user && typeof user === "object";
327
- const hasToken = typeof token === "string" && token.length > 0;
328
- if (!hasUser && !hasToken) return void 0;
329
- const userRecord = hasUser ? user : {};
330
- return {
331
- token: hasToken ? token : "",
332
- clientId: resolveClientId(userRecord),
333
- scopes: normalizeScopes(userRecord.scopes ?? userRecord.scope ?? userRecord.permissions),
334
- ...hasUser ? { extra: { user: userRecord } } : {}
335
- };
336
- }
337
- /**
338
- * Populate `req.auth` on the Node request that is about to be handed to an MCP
339
- * transport.
340
- *
341
- * Resolution order:
342
- * 1. An already-set `req.auth` keeps its identity.
343
- * 2. A configured `setRequestAuth` hook runs and fully owns the result.
344
- * 3. Otherwise the principal resolved by Mastra server auth is bridged from the
345
- * request context using the default mapping.
346
- *
347
- * Whichever way `req.auth` is set, the trusted request context is attached to
348
- * it so MCP tools see the same principal as Mastra routes.
349
- */
350
- async function applyMcpRequestAuth({ req, requestContext, setRequestAuth }) {
351
- const request = req;
352
- if (!requestContext) return;
353
- if (!request.auth) {
354
- if (setRequestAuth) await setRequestAuth(req, requestContext);
355
- else {
356
- const authInfo = buildMcpAuthInfoFromRequestContext(requestContext);
357
- if (authInfo) request.auth = authInfo;
358
- }
359
- }
360
- if (request.auth && typeof request.auth === "object") attachTrustedRequestContext(request.auth, requestContext);
361
- }
362
- /**
363
- * Hands MCP tools the values Mastra server auth resolved for this request
364
- * (user, permissions, roles, resource id, tenant, auth mode), so a tool called
365
- * over MCP is authorized the same way as the matching HTTP route. The token is
366
- * left out; it is already on `authInfo`.
367
- */
368
- function attachTrustedRequestContext(auth, requestContext) {
369
- const trusted = {};
370
- for (const key of RESERVED_REQUEST_CONTEXT_KEYS) {
371
- if (key === "mastra__authToken" || !requestContext.has(key)) continue;
372
- trusted[key] = requestContext.get(key);
373
- }
374
- Object.defineProperty(auth, MCP_TRUSTED_REQUEST_CONTEXT, {
375
- value: trusted,
376
- configurable: true
377
- });
378
- }
379
- // src/server/server-adapter/mcp-disconnect.ts
380
- /**
381
- * Forwards a fetch `Request` abort to the simulated Node response used by fetch-based
382
- * adapters (Hono, Elysia, Next) to drive the MCP Node transport.
383
- *
384
- * `fetch-to-node`'s `toReqRes` ignores `Request.signal`, and the MCP Node transport only
385
- * aborts an in-flight request when `res` emits `close`. Without this, a client that
386
- * disconnects before any response bytes are sent leaves the tool call running to completion.
387
- *
388
- * Call it after `startHTTP` has been invoked so the transport's `close` listener is attached.
389
- */
390
- function propagateRequestAbort(signal, res) {
391
- if (!signal) return;
392
- const onAbort = () => {
393
- if (res.writableFinished) return;
394
- try {
395
- res.emit("close");
396
- } catch {}
397
- };
398
- if (signal.aborted) {
399
- onAbort();
400
- return;
401
- }
402
- signal.addEventListener("abort", onAbort, { once: true });
403
- res.once("finish", () => signal.removeEventListener("abort", onAbort));
404
- }
405
- // src/server/server-adapter/redact.ts
406
- /**
407
- * Redacts request data from a v2 format payload.
408
- * Removes `metadata.request` and `output.steps[].request` from the payload.
409
- */
410
- function redactV2Payload(payload) {
411
- const redactedPayload = { ...payload };
412
- if (redactedPayload.metadata && typeof redactedPayload.metadata === "object") {
413
- const { request, ...metadataRest } = redactedPayload.metadata;
414
- redactedPayload.metadata = metadataRest;
415
- }
416
- if (redactedPayload.output && typeof redactedPayload.output === "object") {
417
- const output = { ...redactedPayload.output };
418
- if (Array.isArray(output.steps)) output.steps = output.steps.map((step) => {
419
- if (step && typeof step === "object") {
420
- const { request, ...stepRest } = step;
421
- return stepRest;
422
- }
423
- return step;
424
- });
425
- redactedPayload.output = output;
426
- }
427
- return redactedPayload;
428
- }
429
- /**
430
- * Redacts sensitive data from stream chunks before they are sent to clients.
431
- *
432
- * This function strips out request bodies that may contain sensitive information
433
- * such as system prompts, tool definitions, API keys, and other configuration data.
434
- *
435
- * Handles both v1 (legacy) and v2 stream formats:
436
- *
437
- * v1 format (fields at root level):
438
- * - `step-start.request` - Contains the full LLM request body
439
- * - `step-finish.request` - Contains the request body
440
- * - `finish.request` - Contains the request body (if present)
441
- *
442
- * v2 format (fields nested in payload):
443
- * - `step-start.payload.request` - Contains the full LLM request body
444
- * - `step-finish.payload.metadata.request` - Contains the request metadata
445
- * - `step-finish.payload.output.steps[].request` - Contains request data for each step
446
- * - `finish.payload.metadata.request` - Contains the request metadata
447
- * - `finish.payload.output.steps[].request` - Contains request data for each step
448
- *
449
- * @param chunk - The stream chunk to redact
450
- * @returns A new chunk with sensitive data removed, or the original chunk if no redaction needed
451
- */
452
- function redactStreamChunk(chunk) {
453
- if (!chunk || typeof chunk !== "object") return chunk;
454
- const typedChunk = chunk;
455
- switch (chunk.type) {
456
- case "step-start":
457
- if ("payload" in typedChunk && typedChunk.payload && typeof typedChunk.payload === "object") {
458
- const { payload, ...rest } = typedChunk;
459
- const { request, ...payloadRest } = payload;
460
- return {
461
- ...rest,
462
- type: "step-start",
463
- payload: {
464
- ...payloadRest,
465
- request: {}
466
- }
467
- };
468
- } else if ("request" in typedChunk) {
469
- const { request, ...rest } = typedChunk;
470
- return {
471
- ...rest,
472
- type: "step-start",
473
- request: {}
474
- };
475
- }
476
- return chunk;
477
- case "step-finish":
478
- if ("payload" in typedChunk && typedChunk.payload && typeof typedChunk.payload === "object") {
479
- const { payload, ...rest } = typedChunk;
480
- return {
481
- ...rest,
482
- type: "step-finish",
483
- payload: redactV2Payload(payload)
484
- };
485
- } else if ("request" in typedChunk) {
486
- const { request, ...rest } = typedChunk;
487
- return {
488
- ...rest,
489
- type: "step-finish"
490
- };
491
- }
492
- return chunk;
493
- case "finish":
494
- if ("payload" in typedChunk && typedChunk.payload && typeof typedChunk.payload === "object") {
495
- const { payload, ...rest } = typedChunk;
496
- return {
497
- ...rest,
498
- type: "finish",
499
- payload: redactV2Payload(payload)
500
- };
501
- } else if ("request" in typedChunk) {
502
- const { request, ...rest } = typedChunk;
503
- return {
504
- ...rest,
505
- type: "finish"
506
- };
507
- }
508
- return chunk;
509
- default: return chunk;
510
- }
511
- }
512
- // src/server/server-adapter/serialize.ts
513
- /**
514
- * Serializes a stream chunk to JSON for wire transport.
515
- *
516
- * Stream chunks can contain values that plain `JSON.stringify` throws on
517
- * (e.g. BigInt produced by zod coercions/transforms in structuredOutput
518
- * schemas, or circular references) — `safeStringify` handles those. A single
519
- * bad chunk must never kill the whole stream — Studio relies on later chunks
520
- * (`workflow-step-result`, `workflow-finish`) to render run state.
521
- *
522
- * Returns `{ ok: false, error }` if the chunk cannot be serialized at all
523
- * (e.g. a throwing getter/toJSON) — callers should log the error, skip the
524
- * chunk, and keep streaming.
525
- */
526
- function serializeStreamChunk(chunk) {
527
- try {
528
- return {
529
- ok: true,
530
- json: safeStringify(withPlainPayloadError(chunk))
531
- };
532
- } catch (error) {
533
- return {
534
- ok: false,
535
- error: error instanceof Error ? error : new Error(String(error))
536
- };
537
- }
538
- }
539
- /**
540
- * `JSON.stringify(new Error('x'))` keeps only own enumerable fields, so an Error subclass that sets `name`
541
- * arrives as `{ name }` and clients show `[object Object]`. Send the message too; never the stack. An
542
- * error whose class curates its JSON (`toJSON`, e.g. MastraError) keeps that shape, so fields it leaves
543
- * out stay out.
544
- */
545
- function withPlainPayloadError(chunk) {
546
- if (!chunk || typeof chunk !== "object" || !("payload" in chunk)) return chunk;
547
- const { payload } = chunk;
548
- if (!payload || typeof payload !== "object" || !("error" in payload)) return chunk;
549
- const { error } = payload;
550
- if (!(error instanceof Error)) return withoutStack(chunk, payload, error);
551
- const plain = {
552
- ...curatedJson(error) ?? error,
553
- message: error.message
554
- };
555
- delete plain.stack;
556
- if (!plain.name && error.name !== "Error") plain.name = error.name;
557
- return {
558
- ...chunk,
559
- payload: {
560
- ...payload,
561
- error: plain
562
- }
563
- };
564
- }
565
- /** An error that is already a plain object (a replayed one) is kept as is, minus its stack. */
566
- function withoutStack(chunk, payload, error) {
567
- if (!error || typeof error !== "object" || Array.isArray(error) || !("stack" in error)) return chunk;
568
- const { stack: _stack, ...rest } = error;
569
- return {
570
- ...chunk,
571
- payload: {
572
- ...payload,
573
- error: rest
574
- }
575
- };
576
- }
577
- function curatedJson(error) {
578
- const toJSON = error.toJSON;
579
- if (typeof toJSON !== "function") return void 0;
580
- try {
581
- const json = toJSON.call(error);
582
- return json && typeof json === "object" ? json : void 0;
583
- } catch {
584
- return;
585
- }
586
- }
587
- // src/server/server-adapter/stream-disconnect.ts
588
- /**
589
- * Cancels `reader` once when the Node response closes, so a disconnected client stops the upstream stream.
590
- *
591
- * Cancels right away when the response is already destroyed: if the client dropped while the route handler
592
- * was still running, `close` fired before this listener existed. Call `dispose()` before ending the response
593
- * so the close that follows a normal end does not cancel.
594
- */
595
- function cancelReaderOnResponseClose(reader, res) {
596
- let canceled = false;
597
- const cancel = (reason) => {
598
- if (canceled) return;
599
- canceled = true;
600
- reader.cancel(reason).catch(() => {});
601
- };
602
- const onClose = () => cancel("request aborted");
603
- res.on("close", onClose);
604
- if (res.destroyed) onClose();
605
- return {
606
- cancel,
607
- dispose: () => res.off("close", onClose)
608
- };
609
- }
610
- const pendingWrites = /* @__PURE__ */ new WeakMap();
611
- function getPendingWrites(res) {
612
- const existing = pendingWrites.get(res);
613
- if (existing) return existing;
614
- const queue = [];
615
- const release = () => {
616
- for (const resolve of queue.splice(0)) resolve();
617
- };
618
- res.on("drain", release);
619
- res.on("close", release);
620
- pendingWrites.set(res, queue);
621
- return queue;
622
- }
623
- /**
624
- * Writes `chunk` and, when the socket buffer is full, waits for `drain` so a slow client pauses reads from the
625
- * upstream stream instead of growing the buffer. Resolves on `close` too, so a dropped client never stalls the caller.
626
- */
627
- async function writeWithBackpressure(res, chunk) {
628
- if (res.write(chunk) !== false || res.destroyed) return;
629
- await new Promise((resolve) => getPendingWrites(res).push(resolve));
630
- }
631
- // src/server/server-adapter/index.ts
632
- function getCustomHTTPExceptionResponse(error) {
633
- if (!(error instanceof HTTPException) || !error.res) return;
634
- return error.getResponse();
635
- }
636
- /**
637
- * Response for an HTTPException thrown from a `registerApiRoute` handler, or undefined for
638
- * any other error (which callers keep behind a generic 500). Duck-typed so an HTTPException
639
- * from `hono/http-exception`, possibly a separate Hono install, is recognised too.
640
- */
641
- function getCustomRouteHTTPExceptionResponse(error) {
642
- if (!(error instanceof Error)) return void 0;
643
- const httpError = error;
644
- const status = httpError.status;
645
- if (typeof httpError.getResponse !== "function" || typeof status !== "number" || !Number.isInteger(status) || status < 400 || status > 599) return;
646
- if (httpError.res) return httpError.getResponse.call(httpError);
647
- return Response.json({ error: httpError.message }, { status });
648
- }
649
- /**
650
- * Only allowlisted causes are exposed to clients; any other cause stays server-side:
651
- * - `cause.failingItems` (dataset schema-update rejections)
652
- * - `cause.field` + `cause.errors` (schema validation failures), reduced to each error's path and message
653
- */
654
- function getSafeErrorCause(error) {
655
- try {
656
- const raw = error instanceof Error ? error.cause : void 0;
657
- if (!raw || typeof raw !== "object" || Array.isArray(raw)) return void 0;
658
- if (Array.isArray(raw.failingItems)) return { failingItems: raw.failingItems };
659
- const { field, errors } = raw;
660
- if (typeof field === "string" && Array.isArray(errors)) return {
661
- field,
662
- errors: errors.flatMap((e) => e && typeof e.path === "string" && typeof e.message === "string" ? [{
663
- path: e.path,
664
- message: e.message
665
- }] : [])
666
- };
667
- } catch {}
668
- }
669
- /**
670
- * Maps a handler error to the status and JSON body every adapter sends:
671
- * `error.status` (HTTPException) first, then `error.details.status` (MastraError), else 500.
672
- */
673
- function getHTTPErrorResponse(error) {
674
- const message = error instanceof Error ? error.message : "Unknown error";
675
- if (error && typeof error === "object") {
676
- if ("status" in error) {
677
- const cause = getSafeErrorCause(error);
678
- return {
679
- status: error.status,
680
- body: {
681
- error: message,
682
- ...cause ? { cause } : {}
683
- }
684
- };
685
- }
686
- if ("details" in error && error.details && typeof error.details === "object" && "status" in error.details) return {
687
- status: error.details.status,
688
- body: { error: message }
689
- };
690
- }
691
- return {
692
- status: 500,
693
- body: { error: message }
694
- };
695
- }
696
- /**
697
- * Hono/adapter context key set by the framework-public middleware.
698
- *
699
- * When true, the current request targets a route the framework has declared
700
- * public (via `createPublicRoute()` / `requiresAuth: false`). Adapter authors
701
- * MUST short-circuit any user-registered middleware for such requests so that
702
- * users cannot accidentally (or intentionally) 401 routes the framework needs
703
- * to keep reachable (e.g. Studio sign-in endpoints).
704
- */
705
- const MASTRA_FRAMEWORK_PUBLIC_KEY = "__mastraFrameworkPublic";
706
- const AGENT_CHANNEL_WEBHOOK_PATH = /^\/api\/agents\/([^/]+)\/channels\/([^/]+)\/webhook\/?$/;
707
- function isAbortSignalError(error) {
708
- if (!error || typeof error !== "object") return false;
709
- const { code, name } = error;
710
- return name === "AbortError" || code === "ABORT_ERR";
711
- }
712
- function isExpectedResponseCloseError(error) {
713
- if (!error || typeof error !== "object") return false;
714
- const { code } = error;
715
- return code === "ECONNRESET" || code === "EPIPE" || code === "ERR_STREAM_DESTROYED" || code === "ERR_STREAM_WRITE_AFTER_END" || code === "ERR_STREAM_PREMATURE_CLOSE";
716
- }
717
- /**
718
- * Returns `response` with a pass-through body that holds the re-dispatched
719
- * custom route `request` until that body is fully read, errors or is cancelled.
720
- *
721
- * `new Request(url, { signal })` gives the request its own signal and forwards
722
- * the outer abort to it through a listener that only weakly references the
723
- * request's controller (nodejs/undici#4068). Once a custom route returns a
724
- * streaming Response, nothing else holds that inner Request, so a GC can drop
725
- * it and a client disconnect never reaches `c.req.raw.signal` (#29154).
726
- *
727
- * The reference lives on the body because the body is reachable exactly while
728
- * an adapter is still sending the response. Anything reachable from the outer
729
- * signal (a WeakMap keyed by it, or an abort listener on it) would leak instead:
730
- * undici's request finalizer holds the outer signal strongly while the inner
731
- * controller is alive, so signal -> request -> controller -> signal is never
732
- * collected when the signal never aborts, as after a normal Express response.
733
- * An abort ends or cancels the body, which releases the request too.
734
- */
735
- function retainRequestWhileBodyIsOpen(response, request) {
736
- const source = response.body;
737
- if (!source) return response;
738
- const reader = source.getReader();
739
- const retained = { request };
740
- const release = () => {
741
- retained.request = void 0;
742
- };
743
- const body = new ReadableStream({
744
- async pull(controller) {
745
- try {
746
- const { done, value } = await reader.read();
747
- if (done) {
748
- release();
749
- controller.close();
750
- } else controller.enqueue(value);
751
- } catch (error) {
752
- release();
753
- controller.error(error);
754
- }
755
- },
756
- cancel(reason) {
757
- release();
758
- return reader.cancel(reason);
759
- }
760
- }, { highWaterMark: 0 });
761
- return new Response(body, {
762
- status: response.status,
763
- statusText: response.statusText,
764
- headers: response.headers
765
- });
766
- }
767
- function isResponseClosed(response) {
768
- return Boolean(response.writableEnded || response.destroyed);
769
- }
770
- function isProtectedFGARoute(route) {
771
- return route.requiresAuth !== false;
772
- }
773
- function formatRoute(route) {
774
- return `${route.method} ${route.path}`;
775
- }
776
- function isSchemaApiRoute(route) {
777
- return "_mastraSchemaRoute" in route && route._mastraSchemaRoute === true;
778
- }
779
- function getFGAProvider(mastra, requestContext) {
780
- if (requestContext) {
781
- if (requestContext.get("mastra__authMode") === "studio") {
782
- const studioFga = mastra?.getStudio?.()?.fga;
783
- if (studioFga) return studioFga;
784
- }
785
- }
786
- return mastra?.getServer?.()?.fga;
787
- }
788
- function getFGARouteInfo(route) {
789
- return {
790
- path: route.path,
791
- method: route.method,
792
- requiresAuth: route.requiresAuth,
793
- requiresPermission: route.requiresPermission,
794
- fga: route.fga
795
- };
796
- }
797
- function getRoutePermissions(route) {
798
- return [getEffectivePermission(route), route.fga?.permission].flatMap((value) => Array.isArray(value) ? value : [value]).filter((permission) => Boolean(permission));
799
- }
800
- async function resolveRouteFGAConfig(fgaProvider, route, requestContext, params) {
801
- if (route.fga) return route.fga;
802
- const resolvedConfig = await fgaProvider.resolveRouteFGA?.({
803
- route: getFGARouteInfo(route),
804
- params,
805
- requestContext
806
- });
807
- if (resolvedConfig) return resolvedConfig;
808
- return getBuiltInRouteFGAConfig(route);
809
- }
810
- function getSchemaTypeName(schema) {
811
- const schemaDef = schema?._def ?? schema?.def;
812
- return schemaDef?.typeName ?? schemaDef?.type;
813
- }
814
- function unwrapOptionalNullable(schema) {
815
- let inner = schema;
816
- let typeName = getSchemaTypeName(inner);
817
- while (typeName === "ZodOptional" || typeName === "ZodNullable" || typeName === "optional" || typeName === "nullable") {
818
- const innerDef = inner?._def ?? inner?.def;
819
- if (!innerDef?.innerType) return inner;
820
- inner = innerDef.innerType;
821
- typeName = getSchemaTypeName(inner);
822
- }
823
- return inner;
824
- }
825
- function parseComplexQueryParams(queryParamSchema, params) {
826
- if (!(queryParamSchema instanceof z.ZodObject)) return params;
827
- const parsedParams = { ...params };
828
- const shape = queryParamSchema.shape;
829
- for (const [key, fieldSchema] of Object.entries(shape)) {
830
- const rawValue = parsedParams[key];
831
- if (typeof rawValue !== "string") continue;
832
- const typeName = getSchemaTypeName(unwrapOptionalNullable(fieldSchema));
833
- if (!(typeName === "ZodObject" || typeName === "ZodArray" || typeName === "ZodRecord" || typeName === "object" || typeName === "array" || typeName === "record")) continue;
834
- try {
835
- parsedParams[key] = JSON.parse(rawValue);
836
- } catch {}
837
- }
838
- return parsedParams;
839
- }
840
- /**
841
- * Property names that must never be written onto objects built from untrusted
842
- * input: assigning them can mutate the object's prototype chain.
843
- */
844
- const UNSAFE_OBJECT_KEYS = /* @__PURE__ */ new Set([
845
- "__proto__",
846
- "prototype",
847
- "constructor"
848
- ]);
849
- /**
850
- * Returns whether `key` is safe to use as a property name when building an
851
- * object from untrusted input (query strings, form fields, etc.).
852
- */
853
- function isSafeObjectKey(key) {
854
- return !UNSAFE_OBJECT_KEYS.has(key);
855
- }
856
- /**
857
- * Normalizes query parameters from various HTTP framework formats to a consistent structure.
858
- * Handles both single string values and arrays (for repeated query params like ?tag=a&tag=b).
859
- * Reconstructs bracket-notation keys (e.g., `orderBy[field]=createdAt`) into JSON strings
860
- * so that z.preprocess JSON.parse can handle them.
861
- * Filters out non-string values that some frameworks may include.
862
- *
863
- * @param rawQuery - Raw query parameters from the HTTP framework (may contain strings, arrays, or nested objects)
864
- * @returns Normalized query parameters as Record<string, string | string[]>
865
- */
866
- function normalizeQueryParams(rawQuery) {
867
- const queryParams = {};
868
- const bracketGroups = {};
869
- for (const [key, value] of Object.entries(rawQuery)) {
870
- const bracketMatch = key.match(/^([^[]+)\[([^\]]+)\]$/);
871
- if (bracketMatch) {
872
- const parent = bracketMatch[1];
873
- const child = bracketMatch[2];
874
- const strValue = Array.isArray(value) ? value.filter((v) => typeof v === "string")[0] : typeof value === "string" ? value : void 0;
875
- if (strValue !== void 0 && isSafeObjectKey(parent) && isSafeObjectKey(child)) {
876
- if (!Object.hasOwn(bracketGroups, parent)) bracketGroups[parent] = {};
877
- bracketGroups[parent][child] = strValue;
878
- }
879
- } else if (typeof value === "string") {
880
- if (isSafeObjectKey(key)) queryParams[key] = value;
881
- } else if (Array.isArray(value)) {
882
- if (!isSafeObjectKey(key)) continue;
883
- const stringValues = value.filter((v) => typeof v === "string");
884
- queryParams[key] = stringValues.length === 1 ? stringValues[0] : stringValues;
885
- }
886
- }
887
- for (const [parent, children] of Object.entries(bracketGroups)) if (!Object.hasOwn(queryParams, parent)) queryParams[parent] = JSON.stringify(children);
888
- return queryParams;
889
- }
890
- /**
891
- * Abstract base class for server adapters that handle HTTP requests.
892
- *
893
- * This class extends `MastraServerBase` to inherit app storage functionality
894
- * and provides the framework for registering routes, middleware, and handling requests.
895
- *
896
- * Framework-specific adapters in @mastra/hono and @mastra/express extend this class
897
- * (both named `MastraServer` in their respective packages) and implement the abstract
898
- * methods for their specific framework.
899
- *
900
- * @template TApp - The type of the server app (e.g., Hono, Express Application)
901
- * @template TRequest - The type of the request object
902
- * @template TResponse - The type of the response object
903
- */
904
- var MastraServer = class extends MastraServerBase {
905
- /** Request bodies cannot set agent scopes: handlers strip `scopes`, and `mastra__scopes` is a reserved key. */
906
- reservesAgentScopes = true;
907
- mastra;
908
- bodyLimitOptions;
909
- tools;
910
- prefix;
911
- openapiPath;
912
- taskStore;
913
- customRouteAuthConfig;
914
- streamOptions;
915
- httpLoggingConfig;
916
- customApiRoutes;
917
- mcpOptions;
918
- customRouteHandler = null;
919
- /** Mirrors the custom-route app's router so auth can ask which route a request runs. */
920
- customRouteMatcher = null;
921
- /**
922
- * Whether custom (non-schema) API routes were registered. Adapters use this
923
- * at request time to decide if they need to preserve a pristine copy of the
924
- * request body for the custom-route bridge.
925
- */
926
- get hasCustomRouteHandler() {
927
- return this.customRouteHandler !== null;
928
- }
929
- constructor({ app, mastra, bodyLimitOptions, tools, prefix = "/api", openapiPath = "", taskStore, customRouteAuthConfig, streamOptions, customApiRoutes, mcpOptions }) {
930
- super({
931
- app,
932
- name: "MastraServer"
933
- });
934
- this.mastra = mastra;
935
- this.bodyLimitOptions = bodyLimitOptions;
936
- this.tools = tools;
937
- this.prefix = normalizeRoutePath(prefix);
938
- this.openapiPath = openapiPath;
939
- this.taskStore = taskStore;
940
- this.customRouteAuthConfig = customRouteAuthConfig;
941
- this.streamOptions = {
942
- redact: true,
943
- ...streamOptions
944
- };
945
- this.customApiRoutes = customApiRoutes;
946
- this.mcpOptions = mcpOptions;
947
- const serverConfig = mastra.getServer();
948
- this.httpLoggingConfig = this.parseLoggingConfig(serverConfig?.build?.apiReqLogs);
949
- mastra.setMastraServer(this);
950
- }
951
- /**
952
- * Parses the apiReqLogs configuration into a normalized HttpLoggingConfig.
953
- * @param config - The raw config value from server.build.apiReqLogs
954
- * @returns Normalized HttpLoggingConfig or undefined if disabled
955
- */
956
- parseLoggingConfig(config) {
957
- if (config === true) return {
958
- enabled: true,
959
- level: "info",
960
- redactHeaders: ["authorization", "cookie"]
961
- };
962
- if (typeof config === "object" && config.enabled) return {
963
- enabled: true,
964
- level: config.level || "info",
965
- excludePaths: config.excludePaths,
966
- includeHeaders: config.includeHeaders,
967
- includeQueryParams: config.includeQueryParams,
968
- redactHeaders: [.../* @__PURE__ */ new Set([...["authorization", "cookie"], ...config.redactHeaders || []])]
969
- };
970
- }
971
- /**
972
- * Determines if a request to the given path should be logged.
973
- * @param path - The request path to check
974
- * @returns true if the request should be logged, false otherwise
975
- */
976
- shouldLogRequest(path) {
977
- if (!this.httpLoggingConfig?.enabled) return false;
978
- return !(this.httpLoggingConfig.excludePaths || []).some((excluded) => path === excluded || path.startsWith(excluded + "/"));
979
- }
980
- /** Warn when a request looks like an agent channel webhook whose route was never registered. */
981
- warnIfUnregisteredChannelWebhook(path, method, status) {
982
- if (status !== 404 || method.toUpperCase() !== "POST") return;
983
- const match = AGENT_CHANNEL_WEBHOOK_PATH.exec(path);
984
- if (!match) return;
985
- const routes = this.customApiRoutes ?? this.mastra.getServer()?.apiRoutes;
986
- if (findMatchingCustomRoute(path, method.toUpperCase(), routes)) return;
987
- const agentId = match[1];
988
- const platform = match[2];
989
- const platformLabel = /^[a-z0-9]+(?:[-_][a-z0-9]+)*$/i.test(platform) ? platform.split(/[-_]/).map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1)).join(" ") : "channel";
990
- this.mastra.getLogger()?.warn(`Received a ${platformLabel} webhook, but this agent doesn't have a ${platformLabel} adapter. Add one to the agent's channels.adapters configuration and restart the server.`, {
991
- agentId,
992
- platform
993
- });
994
- }
995
- mergeRequestContext({ paramsRequestContext, bodyRequestContext }) {
996
- const requestContext = new RequestContext();
997
- if (bodyRequestContext) for (const [key, value] of Object.entries(bodyRequestContext)) {
998
- if (isReservedRequestContextKey(key)) continue;
999
- requestContext.set(key, value);
1000
- }
1001
- if (paramsRequestContext) for (const [key, value] of Object.entries(paramsRequestContext)) {
1002
- if (isReservedRequestContextKey(key)) continue;
1003
- requestContext.set(key, value);
1004
- }
1005
- return requestContext;
1006
- }
1007
- applyRequestMetadataToContext({ requestContext, getHeader }) {
1008
- if (isStudioClientTypeHeader(getHeader("x-mastra-client-type"))) requestContext.set(MASTRA_IS_STUDIO_KEY, true);
1009
- }
1010
- /**
1011
- * Determines which auth configuration to use for the current request.
1012
- *
1013
- * Request routing logic:
1014
- * 1. If `x-mastra-client-type: studio` header is present AND `studio.auth` is configured:
1015
- * → Use studio auth (for internal team members accessing Studio UI)
1016
- * 2. If studio header is present but `studio.auth` is NOT configured:
1017
- * → No auth required (Studio development mode)
1018
- * 3. Otherwise:
1019
- * → Use server auth (for external customers calling API)
1020
- *
1021
- * Security note: The header is only for routing - auth validation happens
1022
- * via session cookies/tokens. If someone spoofs the studio header but doesn't
1023
- * have a valid studio session, they'll get a 401 (not fall back to server auth).
1024
- */
1025
- getEffectiveAuthConfig(getHeader) {
1026
- const isStudioRequest = isStudioClientTypeHeader(getHeader(MASTRA_CLIENT_TYPE_HEADER));
1027
- const studioAuth = this.mastra.getStudio?.()?.auth;
1028
- const serverAuth = this.mastra.getServer()?.auth;
1029
- if (isStudioRequest && studioAuth) return {
1030
- authConfig: studioAuth,
1031
- authMode: "studio"
1032
- };
1033
- if (serverAuth) return {
1034
- authConfig: serverAuth,
1035
- authMode: "server"
1036
- };
1037
- return null;
1038
- }
1039
- /**
1040
- * Gets the effective RBAC provider for the current request based on auth mode.
1041
- */
1042
- getEffectiveRBACProvider(requestContext) {
1043
- return getEffectiveRBACProvider(this.mastra, requestContext);
1044
- }
1045
- /**
1046
- * Gets the effective FGA provider for the current request based on auth mode.
1047
- */
1048
- getEffectiveFGAProvider(requestContext) {
1049
- if (requestContext.get("mastra__authMode") === "studio") return this.mastra.getStudio?.()?.fga ?? this.mastra.getServer()?.fga;
1050
- return this.mastra.getServer()?.fga;
1051
- }
1052
- /**
1053
- * Check if the current request should be authenticated/authorized.
1054
- * Returns null if auth passes, or an error response if it fails.
1055
- *
1056
- * This is a thin wrapper around coreAuthMiddleware that:
1057
- * 1. Routes to the correct auth provider (studio vs server) based on request headers
1058
- * 2. Handles route-level requiresAuth opt-out (not available in global middleware)
1059
- * 3. Delegates all other auth logic to coreAuthMiddleware
1060
- * 4. Translates the AuthResult into the {status, error} format adapters expect
1061
- *
1062
- * Security: When `x-mastra-client-type: studio` header is present and studio auth
1063
- * is configured, we ONLY use studio auth. If authentication fails, we return 401
1064
- * and redirect to login - we do NOT fall back to server auth. This prevents
1065
- * external users from spoofing the studio header to access Studio UI.
1066
- */
1067
- async checkRouteAuth(route, context) {
1068
- const effectiveAuth = this.getEffectiveAuthConfig(context.getHeader);
1069
- if (!effectiveAuth) return null;
1070
- const { authConfig, authMode } = effectiveAuth;
1071
- context.requestContext.set(MASTRA_AUTH_MODE_KEY, authMode);
1072
- if (route.requiresAuth === false) return null;
1073
- const authHeader = context.getHeader("authorization");
1074
- let token = authHeader ? authHeader.replace("Bearer ", "") : null;
1075
- if (!token) token = context.getQuery("apiKey") || null;
1076
- const fallbackHeaders = new Headers();
1077
- for (const headerName of ["authorization", "cookie"]) {
1078
- const headerValue = context.getHeader(headerName);
1079
- if (headerValue) fallbackHeaders.set(headerName, headerValue);
1080
- }
1081
- const result = await coreAuthMiddleware({
1082
- path: context.path,
1083
- method: context.method,
1084
- getHeader: context.getHeader,
1085
- mastra: this.mastra,
1086
- authConfig,
1087
- customRouteAuthConfig: context.customRouteAuthConfig ?? this.customRouteAuthConfig,
1088
- requestContext: context.requestContext,
1089
- rawRequest: context.request ?? new Request(`http://localhost${context.path}`, {
1090
- method: context.method,
1091
- headers: fallbackHeaders
1092
- }),
1093
- token,
1094
- buildAuthorizeContext: context.buildAuthorizeContext ?? (() => null),
1095
- requiresAuth: route.requiresAuth
1096
- });
1097
- if (result.action === "next") {
1098
- if (result.headers) return {
1099
- status: 200,
1100
- error: "",
1101
- headers: result.headers
1102
- };
1103
- return null;
1104
- }
1105
- const errorBody = result.body;
1106
- return {
1107
- status: result.status,
1108
- error: errorBody?.error ?? "Access denied",
1109
- headers: result.headers
1110
- };
1111
- }
1112
- /**
1113
- * Check if the user has the required permission for a route.
1114
- *
1115
- * Uses convention-based permission derivation:
1116
- * 1. If route has explicit `requiresPermission`, use that
1117
- * 2. Otherwise, derive permission from path/method (e.g., GET /agents → agents:read)
1118
- * 3. Routes with `requiresAuth: false` skip permission checks
1119
- *
1120
- * When the route specifies an array of permissions, the user needs ANY ONE
1121
- * of them (logical OR).
1122
- *
1123
- * @param route - The route being accessed
1124
- * @param userPermissions - The user's permissions from the request context
1125
- * @returns Error response if permission denied, null if allowed
1126
- */
1127
- /**
1128
- * Check if the user has the required permission for a route.
1129
- *
1130
- * Uses convention-based permission derivation:
1131
- * 1. If route has explicit `requiresPermission`, use that
1132
- * 2. Otherwise, derive permission from path/method (e.g., GET /agents → agents:read)
1133
- * 3. Routes with `requiresAuth: false` skip permission checks
1134
- *
1135
- * Permission checks use the RBAC provider that corresponds to the auth mode
1136
- * (studio vs server) that was used for authentication.
1137
- *
1138
- * @param route - The route being accessed
1139
- * @param userPermissions - The user's permissions from the request context
1140
- * @param hasPermissionFn - Function to check if user permissions match required permission
1141
- * @param requestContext - Request context to determine which RBAC provider to use
1142
- * @returns Error response if permission denied, null if allowed
1143
- */
1144
- checkRoutePermission(route, userPermissions, hasPermissionFn, requestContext) {
1145
- return getRoutePermissionError(this.mastra, route, userPermissions, hasPermissionFn, requestContext);
1146
- }
1147
- /**
1148
- * Build a matcher that answers "is this (path, method) a framework-public
1149
- * route?" — i.e. registered with `requiresAuth: false`.
1150
- *
1151
- * Adapters call this once at registration time and use the returned function
1152
- * inside their context middleware to stash a boolean on the per-request
1153
- * context under `MASTRA_FRAMEWORK_PUBLIC_KEY`. That boolean is then read by
1154
- * per-user-middleware wrappers to short-circuit user middleware for
1155
- * framework-public routes, guaranteeing that user middleware cannot 401
1156
- * routes the framework declared public (e.g. Studio sign-in endpoints).
1157
- *
1158
- * The matcher considers:
1159
- * - Built-in `SERVER_ROUTES` entries with `requiresAuth === false`
1160
- * (paths joined with the adapter's configured `prefix`).
1161
- * - Custom user API routes registered with `requiresAuth: false` via the
1162
- * `customRouteAuthConfig` map.
1163
- */
1164
- getFrameworkPublicMatcher() {
1165
- const prefix = this.prefix ?? "";
1166
- const publicRoutes = SERVER_ROUTES.filter((r) => r.requiresAuth === false).map((r) => ({
1167
- method: r.method.toUpperCase(),
1168
- pattern: `${prefix}${r.path}`
1169
- }));
1170
- return (path, method) => {
1171
- const upperMethod = method.toUpperCase();
1172
- for (const r of publicRoutes) if ((r.method === upperMethod || r.method === "ALL") && pathMatchesPattern(path, r.pattern)) return true;
1173
- return isCustomRoutePublic(path, upperMethod, this.customRouteAuthConfig);
1174
- };
1175
- }
1176
- async init() {
1177
- this.registerContextMiddleware();
1178
- this.registerAuthMiddleware();
1179
- this.validateAuthResourceScoping();
1180
- this.registerUserMiddleware();
1181
- this.registerHttpLoggingMiddleware();
1182
- await this.validateEELicense();
1183
- await this.validateAgentBuilderLicense();
1184
- await this.validateFGAPolicyCoverage();
1185
- await this.registerCustomApiRoutes();
1186
- await this.registerRoutes();
1187
- }
1188
- /**
1189
- * Validate that EE features have a valid license in production.
1190
- * Throws if RBAC or FGA is configured without a valid license outside dev/test environments.
1191
- */
1192
- async validateEELicense() {
1193
- const serverConfig = this.mastra.getServer();
1194
- const studioConfig = this.mastra.getStudio?.();
1195
- const configuredFeatures = [serverConfig?.rbac || studioConfig?.rbac ? "RBAC" : null, serverConfig?.fga || studioConfig?.fga ? "FGA" : null].filter((feature) => feature !== null);
1196
- if (configuredFeatures.length === 0) return;
1197
- try {
1198
- const { isEEEnabled } = await import("@mastra/core/auth/ee");
1199
- if (!isEEEnabled()) {
1200
- const featureList = configuredFeatures.join(" and ");
1201
- throw new Error(`[mastra/auth-ee] ${featureList} ${configuredFeatures.length === 1 ? "is" : "are"} configured but no valid EE license was found.\n${featureList} ${configuredFeatures.length === 1 ? "requires" : "require"} a Mastra Enterprise License for production use.\nSet the MASTRA_EE_LICENSE environment variable with your license key.
1202
- Learn more: https://github.com/mastra-ai/mastra/blob/main/ee/LICENSE`);
1203
- }
1204
- } catch (err) {
1205
- if (err instanceof Error && err.message.startsWith("[mastra/auth-ee]")) throw err;
1206
- throw new Error(`[mastra/auth-ee] ${configuredFeatures.join(" and ")} ${configuredFeatures.length === 1 ? "is" : "are"} configured but the EE module (@mastra/core/auth/ee) could not be loaded.\nEnsure @mastra/core is updated to a version that includes EE support.`);
1207
- }
1208
- }
1209
- /**
1210
- * Validate that an Agent Builder configuration has a valid EE license.
1211
- * Throws if the editor is configured with builder support but no valid EE license is available.
1212
- */
1213
- async validateAgentBuilderLicense() {
1214
- if (!this.mastra.getEditor()?.hasEnabledBuilderConfig?.()) return;
1215
- try {
1216
- const { isEEEnabled } = await import("@mastra/core/auth/ee");
1217
- if (!isEEEnabled()) throw new Error("[mastra/auth-ee] Agent Builder is configured but no valid EE license was found.\nAgent Builder requires a Mastra Enterprise License for production use.\nSet the MASTRA_EE_LICENSE environment variable with your license key.\nLearn more: https://github.com/mastra-ai/mastra/blob/main/ee/LICENSE");
1218
- } catch (err) {
1219
- if (err instanceof Error && err.message.startsWith("[mastra/auth-ee]")) throw err;
1220
- throw new Error("[mastra/auth-ee] Agent Builder is configured but the EE module (@mastra/core/auth/ee) could not be loaded.\nEnsure @mastra/core is updated to a version that includes EE support.");
1221
- }
1222
- }
1223
- /**
1224
- * Warn when `server.auth` is configured without `mapUserToResourceId`.
1225
- *
1226
- * Without it, MASTRA_RESOURCE_ID_KEY is never set in the request context, so
1227
- * built-in routes fall back to the client-supplied resource ID (for example
1228
- * `memory.resource`) and ownership checks run against a caller-chosen value.
1229
- */
1230
- validateAuthResourceScoping() {
1231
- const auth = this.mastra.getServer()?.auth;
1232
- if (!auth || typeof auth.mapUserToResourceId === "function") return;
1233
- this.mastra.getLogger()?.warn("[mastra/auth] server.auth is configured without mapUserToResourceId. Memory, thread and workflow ownership checks will trust the resource ID supplied by the client (e.g. memory.resource in the request body), so an authenticated user can read or write another user's threads. Configure server.auth.mapUserToResourceId to derive the resource ID from the authenticated user.");
1234
- }
1235
- /**
1236
- * Validate route-level FGA policy coverage when an FGA provider opts into
1237
- * startup checks.
1238
- */
1239
- async validateFGAPolicyCoverage() {
1240
- const serverConfig = this.mastra.getServer();
1241
- const studioConfig = this.mastra.getStudio?.();
1242
- const fgaProvider = serverConfig?.fga ?? studioConfig?.fga;
1243
- if (!fgaProvider) return;
1244
- const customRoutes = (this.customApiRoutes ?? serverConfig?.apiRoutes ?? []).filter((route) => !route._mastraInternal);
1245
- const routes = [...SERVER_ROUTES, ...customRoutes];
1246
- if (fgaProvider.validatePermissions) {
1247
- const permissions = [...new Set(routes.flatMap((route) => getRoutePermissions(route)))];
1248
- await fgaProvider.validatePermissions(permissions);
1249
- }
1250
- const auditMode = fgaProvider.auditProtectedRoutes ?? (fgaProvider.requireForProtectedRoutes ? "warn" : false);
1251
- if (!auditMode || fgaProvider.resolveRouteFGA) return;
1252
- const missingRoutes = routes.filter((route) => isProtectedFGARoute(route) && !route.fga && !getBuiltInRouteFGAConfig(route));
1253
- if (missingRoutes.length === 0) return;
1254
- const routeList = missingRoutes.map((route) => formatRoute(route));
1255
- const message = `[mastra/auth-ee] FGA is configured but ${missingRoutes.length} protected route${missingRoutes.length === 1 ? " is" : "s are"} missing FGA metadata: ${routeList.join(", ")}`;
1256
- if (auditMode === "error") throw new Error(message);
1257
- this.mastra.getLogger()?.warn(message, {
1258
- routes: routeList,
1259
- count: missingRoutes.length
1260
- });
1261
- }
1262
- /**
1263
- * Register user-provided middleware from the Mastra config (`server.middleware`)
1264
- * and from `mastra.setServerMiddleware()`. Called by init() between
1265
- * registerAuthMiddleware() and registerHttpLoggingMiddleware().
1266
- *
1267
- * Mastra middleware handlers use Hono's `(c, next)` signature, so only
1268
- * Hono-based adapters can run them. Those adapters override this method and
1269
- * MUST wrap each handler with `skipIfFrameworkPublic` (exported by
1270
- * `@mastra/hono`) so user middleware cannot block framework-public routes.
1271
- * The default implementation warns when middleware is configured so the
1272
- * config is not silently ignored on adapters that cannot honor it.
1273
- */
1274
- registerUserMiddleware() {
1275
- const instanceMiddleware = this.mastra.getServerMiddleware?.() ?? [];
1276
- const configMiddleware = this.mastra.getServer()?.middleware;
1277
- const hasConfigMiddleware = Array.isArray(configMiddleware) ? configMiddleware.length > 0 : !!configMiddleware;
1278
- if (instanceMiddleware.length === 0 && !hasConfigMiddleware) return;
1279
- this.mastra.getLogger()?.warn("Mastra server middleware (`server.middleware` or `setServerMiddleware()`) is configured, but this server adapter cannot run Hono middleware handlers. The configured middleware will not run — register middleware through your server framework instead.");
1280
- }
1281
- /**
1282
- * Override in adapters to register custom API routes defined via registerApiRoute().
1283
- * Called by init() between registerAuthMiddleware() and registerRoutes().
1284
- */
1285
- async registerCustomApiRoutes() {}
1286
- /** Ensures every custom route has an auth entry without overriding supplied values. */
1287
- initializeCustomRouteAuthConfig(routes) {
1288
- this.customRouteAuthConfig ??= /* @__PURE__ */ new Map();
1289
- for (const route of routes) {
1290
- const routeKey = `${route.method}:${route.path}`;
1291
- if (!this.customRouteAuthConfig.has(routeKey)) this.customRouteAuthConfig.set(routeKey, route.requiresAuth !== false);
1292
- }
1293
- }
1294
- /**
1295
- * Registers schema-aware custom routes through the adapter's native route pipeline.
1296
- * Returns the remaining Hono-style routes for the custom-route bridge.
1297
- */
1298
- async registerSchemaApiRoutes() {
1299
- const routes = this.customApiRoutes ?? this.mastra.getServer()?.apiRoutes ?? [];
1300
- this.validateCustomRoutePaths(routes);
1301
- this.initializeCustomRouteAuthConfig(routes);
1302
- const schemaRoutes = routes.filter(isSchemaApiRoute);
1303
- for (const route of schemaRoutes) {
1304
- const prefix = OPT_IN_ROUTES.includes(route) ? this.prefix : "";
1305
- await this.registerRoute(this.app, route, { prefix });
1306
- }
1307
- return routes.filter((route) => !isSchemaApiRoute(route));
1308
- }
1309
- /**
1310
- * Validates that no custom route path collides with the built-in route prefix.
1311
- * Throws if any route path starts with the server's `apiPrefix`.
1312
- */
1313
- validateCustomRoutePaths(routes) {
1314
- const prefix = this.prefix ?? "";
1315
- if (!prefix) return;
1316
- for (const route of routes) {
1317
- if (route._mastraInternal) continue;
1318
- if (route.path.startsWith(`${prefix}/`) || route.path === prefix) throw new Error(`Custom API route "${route.path}" must not start with "${prefix}" — that path is reserved for built-in Mastra routes. Choose a different path (e.g. "${route.path.replace(prefix, "/custom")}").`);
1319
- }
1320
- }
1321
- /**
1322
- * Creates an internal Hono sub-app with all custom API routes registered.
1323
- * Stores the handler on this instance for use by handleCustomRouteRequest().
1324
- * Returns true if custom routes were found and registered.
1325
- */
1326
- async buildCustomRouteHandler(routes) {
1327
- if (routes.length === 0) return false;
1328
- const NOT_FOUND_HEADER = "x-mastra-custom-route-not-found";
1329
- const mastra = this.mastra;
1330
- const app = new Hono();
1331
- app.use("*", async (c, next) => {
1332
- c.set("mastra", mastra);
1333
- c.set("requestContext", c.env?.requestContext ?? new RequestContext());
1334
- await next();
1335
- });
1336
- const serverOnError = this.mastra.getServer()?.onError;
1337
- app.onError((err, c) => {
1338
- if (serverOnError) return serverOnError(err, c);
1339
- const httpExceptionResponse = getCustomRouteHTTPExceptionResponse(err);
1340
- if (httpExceptionResponse) return httpExceptionResponse;
1341
- this.mastra.getLogger()?.error(`Custom route handler failed: ${c.req.method} ${c.req.path}`, {
1342
- method: c.req.method,
1343
- path: c.req.path,
1344
- error: err instanceof Error ? err.stack ?? err.message : String(err)
1345
- });
1346
- return c.json({ error: "Internal Server Error" }, 500);
1347
- });
1348
- const matcherEntries = [];
1349
- for (const route of routes) {
1350
- const handler = "handler" in route && route.handler ? route.handler : "createHandler" in route ? await route.createHandler({ mastra }) : void 0;
1351
- if (!handler) continue;
1352
- const middlewares = [];
1353
- if (route.middleware) middlewares.push(...Array.isArray(route.middleware) ? route.middleware : [route.middleware]);
1354
- const allHandlers = [...middlewares, handler];
1355
- matcherEntries.push({
1356
- method: route.method,
1357
- path: route.path,
1358
- handlerCount: allHandlers.length,
1359
- route
1360
- });
1361
- if (route.method === "ALL") app.all(route.path, allHandlers[0], ...allHandlers.slice(1));
1362
- else app.on(route.method, route.path, allHandlers[0], ...allHandlers.slice(1));
1363
- }
1364
- app.notFound(() => new Response(null, {
1365
- status: 404,
1366
- headers: { [NOT_FOUND_HEADER]: "true" }
1367
- }));
1368
- this.customRouteHandler = async (request, env, executionCtx) => app.fetch(request, env, executionCtx);
1369
- this.customRouteMatcher = new CustomRouteMatcher(matcherEntries);
1370
- return true;
1371
- }
1372
- /**
1373
- * Returns the custom route the custom-route app will run for `url` (the same URL
1374
- * passed to `handleCustomRouteRequest`), with its decoded path params, or
1375
- * undefined if none will.
1376
- */
1377
- matchCustomRoute(url, method) {
1378
- if (!this.customRouteMatcher) return void 0;
1379
- try {
1380
- const match = this.customRouteMatcher.matchUrl(url, method);
1381
- return match ? {
1382
- route: match.entry.route,
1383
- params: match.params
1384
- } : void 0;
1385
- } catch {
1386
- return;
1387
- }
1388
- }
1389
- /**
1390
- * Works out what auth applies to a request before it's forwarded to the
1391
- * custom-route app. The route that decides is the one the app will dispatch
1392
- * `dispatchUrl` to, not the route the outer framework matched, because the two
1393
- * routers can disagree on precedence, case, trailing slashes and encoding.
1394
- *
1395
- * `requestPath` is the path passed to `checkRouteAuth`. When the dispatched route
1396
- * requires auth, the returned `customRouteAuthConfig` marks that path protected so
1397
- * the auth middleware can't skip auth on it. `fallbackRoute` is used when the app
1398
- * won't dispatch the request (it 404s and nothing runs); pass the framework's own
1399
- * route when there is one so its auth still applies.
1400
- */
1401
- resolveCustomRouteAuth(dispatchUrl, method, requestPath, fallbackRoute) {
1402
- const match = this.matchCustomRoute(dispatchUrl, method);
1403
- const route = match?.route ?? fallbackRoute;
1404
- const requiresAuth = route ? this.customRouteAuthConfig?.get(`${route.method}:${route.path}`) ?? route.requiresAuth !== false : isProtectedCustomRoute(requestPath, method, this.customRouteAuthConfig);
1405
- const serverRoute = {
1406
- method: route?.method ?? method,
1407
- path: route?.path ?? requestPath,
1408
- responseType: "json",
1409
- handler: async () => {},
1410
- requiresAuth: requiresAuth ? route?.requiresAuth === true ? true : void 0 : false,
1411
- requiresPermission: route?.requiresPermission,
1412
- fga: route?.fga
1413
- };
1414
- let customRouteAuthConfig;
1415
- if (requiresAuth) {
1416
- customRouteAuthConfig = new Map(this.customRouteAuthConfig ?? []);
1417
- customRouteAuthConfig.set(`${method.toUpperCase()}:${requestPath}`, true);
1418
- }
1419
- return {
1420
- match,
1421
- requiresAuth,
1422
- serverRoute,
1423
- customRouteAuthConfig
1424
- };
1425
- }
1426
- /**
1427
- * Forwards a request to the internal custom route handler.
1428
- * Returns the Response if a custom route matched, or null to fall through.
1429
- */
1430
- async handleCustomRouteRequest(url, method, headers, body, requestContext, signal, executionCtx) {
1431
- if (!this.customRouteHandler) return null;
1432
- const fetchHeaders = new Headers();
1433
- for (const [key, value] of Object.entries(headers)) if (typeof value === "string") fetchHeaders.set(key, value);
1434
- else if (Array.isArray(value)) value.forEach((v) => {
1435
- fetchHeaders.append(key, v);
1436
- });
1437
- const init = {
1438
- method,
1439
- headers: fetchHeaders,
1440
- signal
1441
- };
1442
- if ([
1443
- "POST",
1444
- "PUT",
1445
- "PATCH",
1446
- "DELETE"
1447
- ].includes(method) && body !== void 0) {
1448
- if (body instanceof ArrayBuffer || body instanceof Uint8Array || body instanceof ReadableStream) {
1449
- init.body = body;
1450
- if (body instanceof ReadableStream) init.duplex = "half";
1451
- } else if (((typeof headers["content-type"] === "string" ? headers["content-type"] : "") || "").includes("application/json")) init.body = JSON.stringify(body);
1452
- else if (typeof body === "string") init.body = body;
1453
- }
1454
- const request = new globalThis.Request(url, init);
1455
- const response = await this.customRouteHandler(request, { requestContext }, executionCtx);
1456
- if (response.headers.get("x-mastra-custom-route-not-found") === "true") return null;
1457
- return signal ? retainRequestWhileBodyIsOpen(response, request) : response;
1458
- }
1459
- /**
1460
- * Pipes a custom route Response to a Node.js ServerResponse (http.ServerResponse).
1461
- * Works with Koa (ctx.res), Express (res), and Fastify (reply.raw).
1462
- */
1463
- async writeCustomRouteResponse(response, nodeRes, signal) {
1464
- const headers = {};
1465
- response.headers.forEach((value, key) => {
1466
- if (key.toLowerCase() !== "set-cookie") headers[key] = value;
1467
- });
1468
- const setCookies = response.headers.getSetCookie?.();
1469
- if (setCookies && setCookies.length > 0) headers["set-cookie"] = setCookies;
1470
- if (isResponseClosed(nodeRes)) {
1471
- await response.body?.cancel();
1472
- return;
1473
- }
1474
- nodeRes.writeHead(response.status, headers);
1475
- if (response.body) {
1476
- let responseBodyError;
1477
- let responseBodyErrorAfterResponseClosed = false;
1478
- try {
1479
- const responseStream = Readable.fromWeb(response.body);
1480
- responseStream.once("error", (error) => {
1481
- responseBodyError = error;
1482
- responseBodyErrorAfterResponseClosed = isResponseClosed(nodeRes);
1483
- });
1484
- if (signal) await pipeline(responseStream, nodeRes, { signal });
1485
- else await pipeline(responseStream, nodeRes);
1486
- } catch (error) {
1487
- const expectedSignalAbort = signal?.aborted && isAbortSignalError(error) && (!responseBodyError || responseBodyErrorAfterResponseClosed);
1488
- const expectedResponseClose = (!responseBodyError || responseBodyErrorAfterResponseClosed) && isResponseClosed(nodeRes) && isExpectedResponseCloseError(error);
1489
- if (!expectedSignalAbort && !expectedResponseClose) throw error;
1490
- }
1491
- } else {
1492
- const text = await response.text();
1493
- if (!isResponseClosed(nodeRes)) nodeRes.end(text);
1494
- }
1495
- }
1496
- /**
1497
- * Builds the OpenAPI spec object with servers field and custom route paths.
1498
- */
1499
- buildOpenAPISpec(config, prefix) {
1500
- const openApiSpec = generateOpenAPIDocument(SERVER_ROUTES, config);
1501
- if (prefix) openApiSpec.servers = [{ url: prefix }];
1502
- const allCustomRoutes = this.customApiRoutes ?? this.mastra.getServer()?.apiRoutes;
1503
- if (allCustomRoutes && allCustomRoutes.length > 0) {
1504
- const componentSchemas = openApiSpec.components?.schemas ?? Object.create(null);
1505
- const isPrefixed = (route) => OPT_IN_ROUTES.includes(route);
1506
- const customPaths = convertCustomRoutesToOpenAPIPaths(allCustomRoutes.filter((route) => !isPrefixed(route)), componentSchemas);
1507
- const prefixedPaths = convertCustomRoutesToOpenAPIPaths(allCustomRoutes.filter(isPrefixed), componentSchemas);
1508
- if (Object.keys(componentSchemas).length > 0) openApiSpec.components = {
1509
- ...openApiSpec.components,
1510
- schemas: componentSchemas
1511
- };
1512
- if (prefix) {
1513
- for (const pathKey of Object.keys(customPaths)) if (!customPaths[pathKey].servers) customPaths[pathKey].servers = [{ url: "/" }];
1514
- }
1515
- Object.assign(customPaths, prefixedPaths);
1516
- openApiSpec.paths = {
1517
- ...openApiSpec.paths,
1518
- ...customPaths
1519
- };
1520
- }
1521
- return openApiSpec;
1522
- }
1523
- async registerOpenAPIRoute(app, config = {}, { prefix }) {
1524
- const { title = "Mastra API", version = "1.0.0", description = "Mastra Server API", path = "/openapi.json" } = config;
1525
- const openApiSpec = this.buildOpenAPISpec({
1526
- title,
1527
- version,
1528
- description
1529
- }, prefix);
1530
- const openApiRoute = {
1531
- method: "GET",
1532
- path,
1533
- responseType: "json",
1534
- handler: async () => openApiSpec
1535
- };
1536
- await this.registerRoute(app, openApiRoute, { prefix });
1537
- }
1538
- async registerRoutes() {
1539
- for (const route of SERVER_ROUTES) await this.registerRoute(this.app, route, { prefix: this.prefix });
1540
- if (this.openapiPath) await this.registerOpenAPIRoute(this.app, {
1541
- title: "Mastra API",
1542
- version: "1.0.0",
1543
- description: "Mastra Server API",
1544
- path: this.openapiPath
1545
- }, { prefix: this.prefix });
1546
- }
1547
- async parsePathParams(route, params) {
1548
- return parseRoutePathParams(route, params);
1549
- }
1550
- async parseQueryParams(route, params) {
1551
- return parseRouteQueryParams(route, params);
1552
- }
1553
- async parseBody(route, body) {
1554
- return parseRouteBody(route, body);
1555
- }
1556
- resolveValidationError(route, error, context) {
1557
- return resolveRouteValidationError(this.mastra, route, error, context);
1558
- }
1559
- };
1560
- /**
1561
- * The RBAC provider for the auth mode the request was authenticated with
1562
- * (studio vs server).
1563
- */
1564
- function getEffectiveRBACProvider(mastra, requestContext) {
1565
- if (requestContext.get("mastra__authMode") === "studio") return mastra.getStudio?.()?.rbac ?? mastra.getServer()?.rbac;
1566
- return mastra.getServer()?.rbac;
1567
- }
1568
- /**
1569
- * Check if the user has the required permission for a route.
1570
- *
1571
- * Uses convention-based permission derivation:
1572
- * 1. If route has explicit `requiresPermission`, use that
1573
- * 2. Otherwise, derive permission from path/method (e.g., GET /agents → agents:read)
1574
- * 3. Routes with `requiresAuth: false` skip permission checks
1575
- *
1576
- * When the route specifies an array of permissions, the user needs ANY ONE
1577
- * of them (logical OR). Without an RBAC provider, authenticated users get full access.
1578
- *
1579
- * @returns Error response if permission denied, null if allowed
1580
- */
1581
- function getRoutePermissionError(mastra, route, userPermissions, hasPermissionFn, requestContext) {
1582
- if (!getEffectiveRBACProvider(mastra, requestContext)) return null;
1583
- const requiredPermission = getEffectivePermission(route);
1584
- if (!requiredPermission) return null;
1585
- const permissions = Array.isArray(requiredPermission) ? requiredPermission : [requiredPermission];
1586
- if (!(userPermissions && permissions.some((perm) => hasPermissionFn(userPermissions, perm)))) return {
1587
- status: 403,
1588
- error: "Forbidden",
1589
- message: `Missing required permission: ${permissions.join(" or ")}`
1590
- };
1591
- return null;
1592
- }
1593
- async function parseRoutePathParams(route, params) {
1594
- const pathParamSchema = route.pathParamSchema;
1595
- if (!pathParamSchema) return params;
1596
- return pathParamSchema.parseAsync(params);
1597
- }
1598
- async function parseRouteQueryParams(route, params) {
1599
- const queryParamSchema = route.queryParamSchema;
1600
- if (!queryParamSchema) return params;
1601
- const normalizedParams = parseComplexQueryParams(queryParamSchema, params);
1602
- return queryParamSchema.parseAsync(normalizedParams);
1603
- }
1604
- async function parseRouteBody(route, body) {
1605
- const bodySchema = route.bodySchema;
1606
- if (!bodySchema) return body;
1607
- if (body === void 0) {
1608
- const omitted = await bodySchema.safeParseAsync(void 0);
1609
- if (omitted.success) return omitted.data;
1610
- const schemaType = getSchemaTypeName(unwrapOptionalNullable(bodySchema));
1611
- if (schemaType === "object" || schemaType === "ZodObject") {
1612
- const emptyObject = await bodySchema.safeParseAsync({});
1613
- if (emptyObject.success) return emptyObject.data;
1614
- }
1615
- throw omitted.error;
1616
- }
1617
- return bodySchema.parseAsync(body);
1618
- }
1619
- const VALIDATION_CONTEXT_LABELS = {
1620
- query: "query parameters",
1621
- body: "request body",
1622
- path: "path parameters"
1623
- };
1624
- function resolveRouteValidationError(mastra, route, error, context) {
1625
- const hook = route.onValidationError ?? mastra.getServer()?.onValidationError;
1626
- if (hook) try {
1627
- const result = hook(error, context);
1628
- if (result) return result;
1629
- } catch (hookError) {
1630
- mastra.getLogger()?.error("Error in custom onValidationError hook", { error: hookError instanceof Error ? {
1631
- message: hookError.message,
1632
- stack: hookError.stack
1633
- } : hookError });
1634
- }
1635
- return {
1636
- status: 400,
1637
- body: formatZodError(error, VALIDATION_CONTEXT_LABELS[context])
1638
- };
1639
- }
1640
- /**
1641
- * Runs a server route in-process as the caller, with the checks its HTTP
1642
- * endpoint applies on every adapter: authentication, auth's `authorizeUser`,
1643
- * `authorize` and `rules` (against the route's path under `apiPrefix`), input
1644
- * validation, RBAC permission and FGA. Lets code outside an HTTP request (such
1645
- * as an MCP tool) reuse a route without proxying through the HTTP server.
1646
- *
1647
- * Authentication is not re-run: when server or studio auth is configured, the
1648
- * request context must already carry the user Mastra server auth resolved
1649
- * (`MASTRA_USER_KEY`), otherwise the call is refused with 401.
1650
- *
1651
- * Only JSON routes are supported; other response types throw. The handler gets
1652
- * the parsed params, `mastra`, `requestContext` and `abortSignal`, but not the
1653
- * HTTP-only `request`, `registeredTools`, `taskStore` or `routePrefix`, so
1654
- * routes that read those are not suitable.
1655
- */
1656
- async function invokeRoute(route, options) {
1657
- if (route.responseType !== "json") throw new Error(`invokeRoute only runs JSON routes; ${route.method} ${route.path} answers with '${route.responseType}'`);
1658
- const { mastra, requestContext } = options;
1659
- const studioAuth = mastra.getStudio?.()?.auth;
1660
- const serverAuth = mastra.getServer()?.auth;
1661
- const authConfigured = Boolean(studioAuth || serverAuth);
1662
- if (authConfigured && route.requiresAuth !== false) {
1663
- const user = requestContext.get(MASTRA_USER_KEY);
1664
- if (!user) return {
1665
- status: 401,
1666
- body: { error: "Authentication required" }
1667
- };
1668
- const authConfig = requestContext.get("mastra__authMode") === "studio" && studioAuth ? studioAuth : serverAuth;
1669
- if (authConfig) {
1670
- const path = `${normalizeRoutePath(mastra.getServer()?.apiPrefix ?? "/api")}${route.path.replace(/:(\w+)/g, (_, name) => encodeURIComponent(options.pathParams?.[name] ?? ""))}`;
1671
- const token = requestContext.get(MASTRA_AUTH_TOKEN_KEY);
1672
- const authorizationError = await authorizeAuthenticatedUser({
1673
- path,
1674
- method: route.method,
1675
- user,
1676
- mastra,
1677
- authConfig,
1678
- requestContext,
1679
- rawRequest: new Request(`http://localhost${path}`, {
1680
- method: route.method,
1681
- headers: typeof token === "string" && token ? { authorization: `Bearer ${token}` } : void 0
1682
- }),
1683
- buildAuthorizeContext: () => null
1684
- });
1685
- if (authorizationError) return authorizationError;
1686
- }
1687
- }
1688
- const parse = async (context, run) => {
1689
- try {
1690
- return { value: await run() };
1691
- } catch (error) {
1692
- if (isZodError(error)) return { error: resolveRouteValidationError(mastra, route, error, context) };
1693
- throw error;
1694
- }
1695
- };
1696
- const pathParams = await parse("path", () => parseRoutePathParams(route, options.pathParams ?? {}));
1697
- if (pathParams.error) return pathParams.error;
1698
- const query = await parse("query", () => parseRouteQueryParams(route, options.query ?? {}));
1699
- if (query.error) return query.error;
1700
- const body = await parse("body", () => parseRouteBody(route, options.body));
1701
- if (body.error) return body.error;
1702
- const params = {
1703
- ...pathParams.value,
1704
- ...query.value,
1705
- ...typeof body.value === "object" ? body.value : {}
1706
- };
1707
- if (authConfigured) {
1708
- const permissionError = getRoutePermissionError(mastra, route, requestContext.get(MASTRA_USER_PERMISSIONS_KEY), hasPermission, requestContext);
1709
- if (permissionError) return {
1710
- status: permissionError.status,
1711
- body: {
1712
- error: permissionError.error,
1713
- message: permissionError.message
1714
- }
1715
- };
1716
- }
1717
- const fgaError = await checkRouteFGA(mastra, route, requestContext, params);
1718
- if (fgaError) return {
1719
- status: fgaError.status,
1720
- body: {
1721
- error: fgaError.error,
1722
- message: fgaError.message
1723
- }
1724
- };
1725
- try {
1726
- return {
1727
- status: 200,
1728
- body: await route.handler({
1729
- ...params,
1730
- requestContext,
1731
- mastra,
1732
- abortSignal: options.abortSignal ?? new AbortController().signal
1733
- })
1734
- };
1735
- } catch (error) {
1736
- return getHTTPErrorResponse(error);
1737
- }
1738
- }
1739
- /**
1740
- * Check FGA authorization for an HTTP route.
1741
- * Returns null if authorized or FGA not configured, or an error object if denied.
1742
- */
1743
- async function checkRouteFGA(mastra, route, requestContext, params) {
1744
- const fgaProvider = getFGAProvider(mastra, requestContext);
1745
- if (!fgaProvider) return null;
1746
- const fgaConfig = await resolveRouteFGAConfig(fgaProvider, route, requestContext, params);
1747
- if (!fgaConfig) {
1748
- if (fgaProvider.requireForProtectedRoutes && isProtectedFGARoute(route)) return {
1749
- status: 403,
1750
- error: "Forbidden",
1751
- message: "FGA authorization denied: route FGA metadata is required"
1752
- };
1753
- return null;
1754
- }
1755
- const user = requestContext?.get("user");
1756
- if (!user) return {
1757
- status: 403,
1758
- error: "Forbidden",
1759
- message: "FGA authorization denied: authenticated user is required"
1760
- };
1761
- const resourceId = typeof fgaConfig.resourceId === "function" ? fgaConfig.resourceId(params, { requestContext }) : fgaConfig.resourceId || (fgaConfig.resourceIdParam ? params[fgaConfig.resourceIdParam] : void 0);
1762
- if (!fgaConfig.resourceType || !resourceId) return {
1763
- status: 403,
1764
- error: "Forbidden",
1765
- message: "FGA authorization denied: route FGA metadata is incomplete"
1766
- };
1767
- const effectivePermission = route.path ? getEffectivePermission(route) : null;
1768
- const permission = fgaConfig.permission || effectivePermission || `${getFGAResourcePermissionSlug(fgaConfig.resourceType)}:${deriveFGAAction(route.method)}`;
1769
- if (!await fgaProvider.check(user, {
1770
- resource: {
1771
- type: fgaConfig.resourceType,
1772
- id: resourceId
1773
- },
1774
- permission,
1775
- context: {
1776
- resourceId,
1777
- requestContext
1778
- }
1779
- })) return {
1780
- status: 403,
1781
- error: "Forbidden",
1782
- message: `FGA authorization denied: cannot ${permission} on ${fgaConfig.resourceType}:${resourceId}`
1783
- };
1784
- return null;
1785
- }
1786
- function deriveFGAAction(method) {
1787
- switch (method.toUpperCase()) {
1788
- case "GET": return "read";
1789
- case "DELETE": return "delete";
1790
- case "POST":
1791
- case "PUT":
1792
- case "PATCH": return "write";
1793
- default: return "read";
1794
- }
1795
- }
1796
- function getFGAResourcePermissionSlug(resourceType) {
1797
- return {
1798
- agent: "agents",
1799
- workflow: "workflows",
1800
- tool: "tools",
1801
- thread: "memory"
1802
- }[resourceType] ?? resourceType;
1803
- }
1804
- export { ALL_SERVER_ROUTES, HTTPException, KNOWLEDGE_ROUTES, MASTRA_AUTH_MODE_KEY, MASTRA_CLIENT_TYPE_HEADER, MASTRA_FRAMEWORK_PUBLIC_KEY, MASTRA_IS_STUDIO_KEY, MASTRA_KNOWLEDGE_PRINCIPALS_KEY, MASTRA_STUDIO_CLIENT_TYPE, MastraServer, OPT_IN_ROUTES, RESERVED_REQUEST_CONTEXT_KEYS, SERVER_ROUTES, WorkflowRegistry, applyMcpRequestAuth, buildMcpAuthInfoFromRequestContext, cancelReaderOnResponseClose, checkRouteFGA, convertCustomRoutesToOpenAPIPaths, createPublicRoute, createRoute, deriveAction, derivePermission, extractResource, generateOpenAPIDocument, getCustomHTTPExceptionResponse, getCustomRouteHTTPExceptionResponse, getEffectivePermission, getEffectiveRBACProvider, getFGAProvider, getHTTPErrorResponse, getRoutePermissionError, invokeRoute, isReservedRequestContextKey, isSafeObjectKey, isStudioClientTypeHeader, isZodError, jsonQueryParam, normalizeQueryParams, normalizeRoutePath, parseRouteBody, parseRoutePathParams, parseRouteQueryParams, pickParams, propagateRequestAbort, redactStreamChunk, resolveRouteValidationError, serializeStreamChunk, wrapSchemaForQueryParams, writeWithBackpressure };
1805
-
1806
- //# sourceMappingURL=index.js.map
2
+ import { a as wrapSchemaForQueryParams, i as pickParams, n as createRoute, o as convertCustomRoutesToOpenAPIPaths, r as jsonQueryParam, s as generateOpenAPIDocument, t as createPublicRoute } from "../../route-builder-Dz18c3qm.js";
3
+ import { o as normalizeRoutePath, t as WorkflowRegistry } from "../../utils-BfySxdfF.js";
4
+ import { _ as isStudioClientTypeHeader, a as MASTRA_KNOWLEDGE_PRINCIPALS_KEY, g as isReservedRequestContextKey, i as MASTRA_IS_STUDIO_KEY, l as MASTRA_STUDIO_CLIENT_TYPE, m as RESERVED_REQUEST_CONTEXT_KEYS, r as MASTRA_CLIENT_TYPE_HEADER, t as MASTRA_AUTH_MODE_KEY } from "../../constants-0xZU_h4R.js";
5
+ import { isZodError } from "../handlers/error.js";
6
+ import { a as derivePermission, d as resolveServerRoute, i as deriveAction, l as KNOWLEDGE_ROUTES, n as OPT_IN_ROUTES, o as extractResource, r as SERVER_ROUTES, s as getEffectivePermission, t as ALL_SERVER_ROUTES, u as BUILTIN_MCP_HTTP_ROUTE } from "../../routes-CmkPohqd.js";
7
+ import { A as createMCPOAuthMetadataRoutes, C as writeWithBackpressure, D as applyMcpRequestAuth, E as propagateRequestAbort, M as isMCPOAuthDiscoveryEnabled, N as mcpWWWAuthenticate, O as buildMcpAuthInfoFromRequestContext, S as cancelReaderOnResponseClose, T as redactStreamChunk, _ as parseRouteBody, a as checkRouteFGA, b as registerDispatchAdapter, c as getCustomHTTPExceptionResponse, d as getFGAProvider, f as getHTTPErrorResponse, g as normalizeQueryParams, h as isSafeObjectKey, i as bindDispatchAdapter, j as isMCPAudienceEnforced, k as checkMCPAudience, l as getCustomRouteHTTPExceptionResponse, m as invokeRoute, n as MastraServer, o as checkRouteRBAC, p as getRoutePermissionError, r as authorizeRoute, s as dispatchRoute, t as MASTRA_FRAMEWORK_PUBLIC_KEY, u as getEffectiveRBACProvider, v as parseRoutePathParams, w as serializeStreamChunk, x as resolveRouteValidationError, y as parseRouteQueryParams } from "../../server-adapter-BywLWVKp.js";
8
+ export { ALL_SERVER_ROUTES, BUILTIN_MCP_HTTP_ROUTE, HTTPException, KNOWLEDGE_ROUTES, MASTRA_AUTH_MODE_KEY, MASTRA_CLIENT_TYPE_HEADER, MASTRA_FRAMEWORK_PUBLIC_KEY, MASTRA_IS_STUDIO_KEY, MASTRA_KNOWLEDGE_PRINCIPALS_KEY, MASTRA_STUDIO_CLIENT_TYPE, MastraServer, OPT_IN_ROUTES, RESERVED_REQUEST_CONTEXT_KEYS, SERVER_ROUTES, WorkflowRegistry, applyMcpRequestAuth, authorizeRoute, bindDispatchAdapter, buildMcpAuthInfoFromRequestContext, cancelReaderOnResponseClose, checkMCPAudience, checkRouteFGA, checkRouteRBAC, convertCustomRoutesToOpenAPIPaths, createMCPOAuthMetadataRoutes, createPublicRoute, createRoute, deriveAction, derivePermission, dispatchRoute, extractResource, generateOpenAPIDocument, getCustomHTTPExceptionResponse, getCustomRouteHTTPExceptionResponse, getEffectivePermission, getEffectiveRBACProvider, getFGAProvider, getHTTPErrorResponse, getRoutePermissionError, invokeRoute, isMCPAudienceEnforced, isMCPOAuthDiscoveryEnabled, isReservedRequestContextKey, isSafeObjectKey, isStudioClientTypeHeader, isZodError, jsonQueryParam, mcpWWWAuthenticate, normalizeQueryParams, normalizeRoutePath, parseRouteBody, parseRoutePathParams, parseRouteQueryParams, pickParams, propagateRequestAbort, redactStreamChunk, registerDispatchAdapter, resolveRouteValidationError, resolveServerRoute, serializeStreamChunk, wrapSchemaForQueryParams, writeWithBackpressure };