@mastra/server 1.58.0-alpha.9 → 1.58.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 (352) hide show
  1. package/CHANGELOG.md +248 -0
  2. package/dist/{a2a-_D2EA4oa.js → a2a-CUkzkdTZ.js} +3 -3
  3. package/dist/{a2a-_D2EA4oa.js.map → a2a-CUkzkdTZ.js.map} +1 -1
  4. package/dist/{a2a-B6YkZ2i9.cjs → a2a-DzZHH3OH.cjs} +3 -3
  5. package/dist/{a2a-B6YkZ2i9.cjs.map → a2a-DzZHH3OH.cjs.map} +1 -1
  6. package/dist/{agent-versions-DBwhQgbJ.js → agent-versions-CWEnD62A.js} +3 -3
  7. package/dist/{agent-versions-DBwhQgbJ.js.map → agent-versions-CWEnD62A.js.map} +1 -1
  8. package/dist/{agent-versions-znzuht90.cjs → agent-versions-xeysPGel.cjs} +3 -3
  9. package/dist/{agent-versions-znzuht90.cjs.map → agent-versions-xeysPGel.cjs.map} +1 -1
  10. package/dist/{agents-DXkajFi1.cjs → agents-0Tw3kkD_.cjs} +2 -2
  11. package/dist/{agents-DXkajFi1.cjs.map → agents-0Tw3kkD_.cjs.map} +1 -1
  12. package/dist/{agents-D0eC6_5b.js → agents-uT8ZDE4k.js} +2 -2
  13. package/dist/{agents-D0eC6_5b.js.map → agents-uT8ZDE4k.js.map} +1 -1
  14. package/dist/{api-schema-manifest-D7g1cmet.cjs → api-schema-manifest-BPk3u4B-.cjs} +3 -3
  15. package/dist/{api-schema-manifest-D7g1cmet.cjs.map → api-schema-manifest-BPk3u4B-.cjs.map} +1 -1
  16. package/dist/{api-schema-manifest-CfgTQzaK.js → api-schema-manifest-DSelT9XK.js} +3 -3
  17. package/dist/{api-schema-manifest-CfgTQzaK.js.map → api-schema-manifest-DSelT9XK.js.map} +1 -1
  18. package/dist/{background-tasks-DnmhLalp.js → background-tasks-BtWM0sZs.js} +2 -2
  19. package/dist/{background-tasks-DnmhLalp.js.map → background-tasks-BtWM0sZs.js.map} +1 -1
  20. package/dist/{background-tasks-CYgzzUnb.cjs → background-tasks-C5G2jJax.cjs} +2 -2
  21. package/dist/{background-tasks-CYgzzUnb.cjs.map → background-tasks-C5G2jJax.cjs.map} +1 -1
  22. package/dist/{builder-registry-DE5w7bNk.js → builder-registry-B8KyPAOP.js} +3 -3
  23. package/dist/{builder-registry-DE5w7bNk.js.map → builder-registry-B8KyPAOP.js.map} +1 -1
  24. package/dist/{builder-registry-BoaXBdm_.cjs → builder-registry-Dcou-kzd.cjs} +3 -3
  25. package/dist/{builder-registry-BoaXBdm_.cjs.map → builder-registry-Dcou-kzd.cjs.map} +1 -1
  26. package/dist/{channels-BqkOxxEk.js → channels-B9yt3a2P.js} +2 -2
  27. package/dist/{channels-BqkOxxEk.js.map → channels-B9yt3a2P.js.map} +1 -1
  28. package/dist/{channels-BonQBJT0.cjs → channels-BRoq3VKR.cjs} +2 -2
  29. package/dist/{channels-BonQBJT0.cjs.map → channels-BRoq3VKR.cjs.map} +1 -1
  30. package/dist/{default-options-BcPyp2Gx.cjs → default-options-C9HZGjYi.cjs} +6 -3
  31. package/dist/{default-options-BcPyp2Gx.cjs.map → default-options-C9HZGjYi.cjs.map} +1 -1
  32. package/dist/{default-options-DGCDKR3I.js → default-options-C9JVjlto.js} +6 -3
  33. package/dist/{default-options-DGCDKR3I.js.map → default-options-C9JVjlto.js.map} +1 -1
  34. package/dist/{dist-D-2BtcNU.js → dist-7r8jzEWH.js} +68 -1303
  35. package/dist/dist-7r8jzEWH.js.map +1 -0
  36. package/dist/{dist-DhqgxyoU.cjs → dist-DEgLyP8h.cjs} +77 -1315
  37. package/dist/dist-DEgLyP8h.cjs.map +1 -0
  38. package/dist/docs/SKILL.md +2 -1
  39. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  40. package/dist/docs/references/docs-server-custom-adapters.md +1 -1
  41. package/dist/docs/references/docs-server-custom-api-routes.md +375 -0
  42. package/dist/docs/references/reference-server-create-route.md +27 -1
  43. package/dist/{dynamic-workflows-B4LI2B52.js → dynamic-workflows-B0TE8mjA.js} +2 -2
  44. package/dist/{dynamic-workflows-B4LI2B52.js.map → dynamic-workflows-B0TE8mjA.js.map} +1 -1
  45. package/dist/{dynamic-workflows-BXeywVEf.cjs → dynamic-workflows-C-6vmau5.cjs} +2 -2
  46. package/dist/{dynamic-workflows-BXeywVEf.cjs.map → dynamic-workflows-C-6vmau5.cjs.map} +1 -1
  47. package/dist/{editor-builder-Cy-eOCYp.js → editor-builder-Byg6wbi6.js} +3 -3
  48. package/dist/{editor-builder-Cy-eOCYp.js.map → editor-builder-Byg6wbi6.js.map} +1 -1
  49. package/dist/{editor-builder-BexykVlx.cjs → editor-builder-C3ZvffGu.cjs} +2 -2
  50. package/dist/{editor-builder-BexykVlx.cjs.map → editor-builder-C3ZvffGu.cjs.map} +1 -1
  51. package/dist/{editor-builder-CYY0CsMd.js → editor-builder-DJUxdzC8.js} +2 -2
  52. package/dist/{editor-builder-CYY0CsMd.js.map → editor-builder-DJUxdzC8.js.map} +1 -1
  53. package/dist/{editor-builder-LvpimMOA.cjs → editor-builder-DT7ypWfa.cjs} +3 -3
  54. package/dist/{editor-builder-LvpimMOA.cjs.map → editor-builder-DT7ypWfa.cjs.map} +1 -1
  55. package/dist/{observability-new-endpoints-Dk3oatL8.cjs → observability-new-endpoints-BC-dasRY.cjs} +2 -2
  56. package/dist/{observability-new-endpoints-Dk3oatL8.cjs.map → observability-new-endpoints-BC-dasRY.cjs.map} +1 -1
  57. package/dist/{observability-new-endpoints-YK2DjZto.js → observability-new-endpoints-Drx0C8uc.js} +2 -2
  58. package/dist/{observability-new-endpoints-YK2DjZto.js.map → observability-new-endpoints-Drx0C8uc.js.map} +1 -1
  59. package/dist/{probe-image-size-DYJVSL0b.cjs → probe-image-size-C2F59z8Z.cjs} +56 -1707
  60. package/dist/probe-image-size-C2F59z8Z.cjs.map +1 -0
  61. package/dist/{probe-image-size-BQgIJeY_.js → probe-image-size-mXCWYNrz.js} +22 -1673
  62. package/dist/probe-image-size-mXCWYNrz.js.map +1 -0
  63. package/dist/{route-builder-CgLVYL1c.cjs → route-builder-BAAedfru.cjs} +11 -2
  64. package/dist/route-builder-BAAedfru.cjs.map +1 -0
  65. package/dist/{route-builder-CIk5k35M.js → route-builder-YQ_gLIvW.js} +11 -2
  66. package/dist/route-builder-YQ_gLIvW.js.map +1 -0
  67. package/dist/{routes-Bj3bjfJ3.cjs → routes-0BEh3stO.cjs} +10 -10
  68. package/dist/{routes-Bj3bjfJ3.cjs.map → routes-0BEh3stO.cjs.map} +1 -1
  69. package/dist/{routes-Q1t7kbml.js → routes-BsMPy5bu.js} +10 -10
  70. package/dist/{routes-Q1t7kbml.js.map → routes-BsMPy5bu.js.map} +1 -1
  71. package/dist/{schedules-CK3-IE0h.cjs → schedules-DOK225ZZ.cjs} +2 -2
  72. package/dist/{schedules-CK3-IE0h.cjs.map → schedules-DOK225ZZ.cjs.map} +1 -1
  73. package/dist/{schedules-qxFoU-Tb.js → schedules-RjPcNOmY.js} +2 -2
  74. package/dist/{schedules-qxFoU-Tb.js.map → schedules-RjPcNOmY.js.map} +1 -1
  75. package/dist/{schema-Bv9OdW1f-BY6u3u8K.cjs → schema-Bv9OdW1f-CHHI-NTr.cjs} +2 -76
  76. package/dist/schema-Bv9OdW1f-CHHI-NTr.cjs.map +1 -0
  77. package/dist/{schema-Bv9OdW1f-CIOfv-3w.js → schema-Bv9OdW1f-DLSJSqQv.js} +2 -76
  78. package/dist/schema-Bv9OdW1f-DLSJSqQv.js.map +1 -0
  79. package/dist/schema-CGeYTFwm.js +2 -0
  80. package/dist/schema-DkBbires.cjs +1 -0
  81. package/dist/{scorer-versions-PL0wCOT-.cjs → scorer-versions-CYXtxMTU.cjs} +2 -2
  82. package/dist/{scorer-versions-PL0wCOT-.cjs.map → scorer-versions-CYXtxMTU.cjs.map} +1 -1
  83. package/dist/{scorer-versions-DNdVTLOq.js → scorer-versions-CdVjOtQO.js} +2 -2
  84. package/dist/{scorer-versions-DNdVTLOq.js.map → scorer-versions-CdVjOtQO.js.map} +1 -1
  85. package/dist/server/handlers/a2a.cjs +1 -1
  86. package/dist/server/handlers/a2a.d.ts +545 -505
  87. package/dist/server/handlers/a2a.d.ts.map +1 -1
  88. package/dist/server/handlers/a2a.js +1 -1
  89. package/dist/server/handlers/agent-builder.cjs +4 -4
  90. package/dist/server/handlers/agent-builder.d.ts +1069 -764
  91. package/dist/server/handlers/agent-builder.d.ts.map +1 -1
  92. package/dist/server/handlers/agent-builder.js +4 -4
  93. package/dist/server/handlers/agent-controller.cjs +61 -11
  94. package/dist/server/handlers/agent-controller.cjs.map +1 -1
  95. package/dist/server/handlers/agent-controller.d.ts +1547 -893
  96. package/dist/server/handlers/agent-controller.d.ts.map +1 -1
  97. package/dist/server/handlers/agent-controller.js +61 -11
  98. package/dist/server/handlers/agent-controller.js.map +1 -1
  99. package/dist/server/handlers/agent-versions.cjs +3 -3
  100. package/dist/server/handlers/agent-versions.d.ts +8504 -8312
  101. package/dist/server/handlers/agent-versions.d.ts.map +1 -1
  102. package/dist/server/handlers/agent-versions.js +3 -3
  103. package/dist/server/handlers/agents.cjs +6 -6
  104. package/dist/server/handlers/agents.d.ts +9984 -9832
  105. package/dist/server/handlers/agents.d.ts.map +1 -1
  106. package/dist/server/handlers/agents.js +6 -6
  107. package/dist/server/handlers/auth.cjs +1 -1
  108. package/dist/server/handlers/auth.d.ts +693 -297
  109. package/dist/server/handlers/auth.d.ts.map +1 -1
  110. package/dist/server/handlers/auth.js +1 -1
  111. package/dist/server/handlers/background-tasks.cjs +1 -1
  112. package/dist/server/handlers/background-tasks.d.ts +190 -130
  113. package/dist/server/handlers/background-tasks.d.ts.map +1 -1
  114. package/dist/server/handlers/background-tasks.js +1 -1
  115. package/dist/server/handlers/builder-registry.cjs +1 -1
  116. package/dist/server/handlers/builder-registry.d.ts +218 -121
  117. package/dist/server/handlers/builder-registry.d.ts.map +1 -1
  118. package/dist/server/handlers/builder-registry.js +1 -1
  119. package/dist/server/handlers/channels.cjs +1 -1
  120. package/dist/server/handlers/channels.d.ts +157 -77
  121. package/dist/server/handlers/channels.d.ts.map +1 -1
  122. package/dist/server/handlers/channels.js +1 -1
  123. package/dist/server/handlers/conversations.cjs +1 -1
  124. package/dist/server/handlers/conversations.d.ts +221 -141
  125. package/dist/server/handlers/conversations.d.ts.map +1 -1
  126. package/dist/server/handlers/conversations.js +1 -1
  127. package/dist/server/handlers/datasets.cjs +1 -1
  128. package/dist/server/handlers/datasets.d.ts +2669 -2234
  129. package/dist/server/handlers/datasets.d.ts.map +1 -1
  130. package/dist/server/handlers/datasets.js +1 -1
  131. package/dist/server/handlers/dynamic-workflows.cjs +1 -1
  132. package/dist/server/handlers/dynamic-workflows.d.ts +506 -426
  133. package/dist/server/handlers/dynamic-workflows.d.ts.map +1 -1
  134. package/dist/server/handlers/dynamic-workflows.js +1 -1
  135. package/dist/server/handlers/editor-builder.cjs +1 -1
  136. package/dist/server/handlers/editor-builder.d.ts +305 -245
  137. package/dist/server/handlers/editor-builder.d.ts.map +1 -1
  138. package/dist/server/handlers/editor-builder.js +1 -1
  139. package/dist/server/handlers/favorites-enrichment.cjs +1 -1
  140. package/dist/server/handlers/favorites-enrichment.js +1 -1
  141. package/dist/server/handlers/logs.cjs +1 -1
  142. package/dist/server/handlers/logs.d.ts +245 -185
  143. package/dist/server/handlers/logs.d.ts.map +1 -1
  144. package/dist/server/handlers/logs.js +1 -1
  145. package/dist/server/handlers/mcp-client-versions.cjs +2 -2
  146. package/dist/server/handlers/mcp-client-versions.d.ts +447 -307
  147. package/dist/server/handlers/mcp-client-versions.d.ts.map +1 -1
  148. package/dist/server/handlers/mcp-client-versions.js +2 -2
  149. package/dist/server/handlers/mcp.cjs +1 -1
  150. package/dist/server/handlers/mcp.d.ts +357 -156
  151. package/dist/server/handlers/mcp.d.ts.map +1 -1
  152. package/dist/server/handlers/mcp.js +1 -1
  153. package/dist/server/handlers/memory.cjs +1 -1
  154. package/dist/server/handlers/memory.d.ts +1723 -1223
  155. package/dist/server/handlers/memory.d.ts.map +1 -1
  156. package/dist/server/handlers/memory.js +1 -1
  157. package/dist/server/handlers/observability-new-endpoints.cjs +1 -1
  158. package/dist/server/handlers/observability-new-endpoints.d.ts +3239 -2158
  159. package/dist/server/handlers/observability-new-endpoints.d.ts.map +1 -1
  160. package/dist/server/handlers/observability-new-endpoints.js +1 -1
  161. package/dist/server/handlers/observability-shared.cjs +1 -1
  162. package/dist/server/handlers/observability-shared.js +1 -1
  163. package/dist/server/handlers/observability.cjs +2 -2
  164. package/dist/server/handlers/observability.d.ts +267 -149
  165. package/dist/server/handlers/observability.d.ts.map +1 -1
  166. package/dist/server/handlers/observability.js +2 -2
  167. package/dist/server/handlers/processor-providers.cjs +1 -1
  168. package/dist/server/handlers/processor-providers.d.ts +74 -34
  169. package/dist/server/handlers/processor-providers.d.ts.map +1 -1
  170. package/dist/server/handlers/processor-providers.js +1 -1
  171. package/dist/server/handlers/processors.cjs +1 -1
  172. package/dist/server/handlers/processors.d.ts +222 -173
  173. package/dist/server/handlers/processors.d.ts.map +1 -1
  174. package/dist/server/handlers/processors.js +1 -1
  175. package/dist/server/handlers/prompt-block-versions.cjs +2 -2
  176. package/dist/server/handlers/prompt-block-versions.d.ts +646 -506
  177. package/dist/server/handlers/prompt-block-versions.d.ts.map +1 -1
  178. package/dist/server/handlers/prompt-block-versions.js +2 -2
  179. package/dist/server/handlers/responses.cjs +1 -1
  180. package/dist/server/handlers/responses.d.ts +352 -362
  181. package/dist/server/handlers/responses.d.ts.map +1 -1
  182. package/dist/server/handlers/responses.js +1 -1
  183. package/dist/server/handlers/schedules.cjs +1 -1
  184. package/dist/server/handlers/schedules.d.ts +1190 -1028
  185. package/dist/server/handlers/schedules.d.ts.map +1 -1
  186. package/dist/server/handlers/schedules.js +1 -1
  187. package/dist/server/handlers/scorer-versions.cjs +3 -3
  188. package/dist/server/handlers/scorer-versions.d.ts +551 -411
  189. package/dist/server/handlers/scorer-versions.d.ts.map +1 -1
  190. package/dist/server/handlers/scorer-versions.js +3 -3
  191. package/dist/server/handlers/scores.cjs +1 -1
  192. package/dist/server/handlers/scores.d.ts +287 -167
  193. package/dist/server/handlers/scores.d.ts.map +1 -1
  194. package/dist/server/handlers/scores.js +1 -1
  195. package/dist/server/handlers/stored-agent-favorites.cjs +4 -4
  196. package/dist/server/handlers/stored-agent-favorites.d.ts +62 -22
  197. package/dist/server/handlers/stored-agent-favorites.d.ts.map +1 -1
  198. package/dist/server/handlers/stored-agent-favorites.js +4 -4
  199. package/dist/server/handlers/stored-agents.cjs +4 -4
  200. package/dist/server/handlers/stored-agents.d.ts +12056 -16152
  201. package/dist/server/handlers/stored-agents.d.ts.map +1 -1
  202. package/dist/server/handlers/stored-agents.js +4 -4
  203. package/dist/server/handlers/stored-mcp-clients.cjs +2 -2
  204. package/dist/server/handlers/stored-mcp-clients.d.ts +417 -324
  205. package/dist/server/handlers/stored-mcp-clients.d.ts.map +1 -1
  206. package/dist/server/handlers/stored-mcp-clients.js +2 -2
  207. package/dist/server/handlers/stored-prompt-blocks.cjs +2 -2
  208. package/dist/server/handlers/stored-prompt-blocks.d.ts +603 -555
  209. package/dist/server/handlers/stored-prompt-blocks.d.ts.map +1 -1
  210. package/dist/server/handlers/stored-prompt-blocks.js +2 -2
  211. package/dist/server/handlers/stored-scorers.cjs +3 -3
  212. package/dist/server/handlers/stored-scorers.d.ts +556 -472
  213. package/dist/server/handlers/stored-scorers.d.ts.map +1 -1
  214. package/dist/server/handlers/stored-scorers.js +3 -3
  215. package/dist/server/handlers/stored-skill-favorites.cjs +3 -3
  216. package/dist/server/handlers/stored-skill-favorites.d.ts +62 -22
  217. package/dist/server/handlers/stored-skill-favorites.d.ts.map +1 -1
  218. package/dist/server/handlers/stored-skill-favorites.js +3 -3
  219. package/dist/server/handlers/stored-skills.cjs +3 -3
  220. package/dist/server/handlers/stored-skills.d.ts +632 -515
  221. package/dist/server/handlers/stored-skills.d.ts.map +1 -1
  222. package/dist/server/handlers/stored-skills.js +3 -3
  223. package/dist/server/handlers/stored-workspaces.cjs +2 -2
  224. package/dist/server/handlers/stored-workspaces.d.ts +646 -546
  225. package/dist/server/handlers/stored-workspaces.d.ts.map +1 -1
  226. package/dist/server/handlers/stored-workspaces.js +2 -2
  227. package/dist/server/handlers/system.cjs +2 -2
  228. package/dist/server/handlers/system.d.ts +146 -106
  229. package/dist/server/handlers/system.d.ts.map +1 -1
  230. package/dist/server/handlers/system.js +2 -2
  231. package/dist/server/handlers/tool-providers.cjs +1 -1
  232. package/dist/server/handlers/tool-providers.d.ts +580 -331
  233. package/dist/server/handlers/tool-providers.d.ts.map +1 -1
  234. package/dist/server/handlers/tool-providers.js +1 -1
  235. package/dist/server/handlers/tools.cjs +5 -5
  236. package/dist/server/handlers/tools.d.ts +177 -77
  237. package/dist/server/handlers/tools.d.ts.map +1 -1
  238. package/dist/server/handlers/tools.js +5 -5
  239. package/dist/server/handlers/validate-agent-instructions.cjs +1 -1
  240. package/dist/server/handlers/validate-agent-instructions.js +1 -1
  241. package/dist/server/handlers/vector.cjs +1 -1
  242. package/dist/server/handlers/vector.d.ts +282 -126
  243. package/dist/server/handlers/vector.d.ts.map +1 -1
  244. package/dist/server/handlers/vector.js +1 -1
  245. package/dist/server/handlers/workflows.cjs +3 -3
  246. package/dist/server/handlers/workflows.d.ts +1703 -1181
  247. package/dist/server/handlers/workflows.d.ts.map +1 -1
  248. package/dist/server/handlers/workflows.js +3 -3
  249. package/dist/server/handlers/workspace.cjs +1 -1
  250. package/dist/server/handlers/workspace.d.ts +1936 -1150
  251. package/dist/server/handlers/workspace.d.ts.map +1 -1
  252. package/dist/server/handlers/workspace.js +1 -1
  253. package/dist/server/handlers.cjs +2 -2
  254. package/dist/server/handlers.js +2 -2
  255. package/dist/server/schemas/agent-versions.d.ts +70 -10
  256. package/dist/server/schemas/agent-versions.d.ts.map +1 -1
  257. package/dist/server/schemas/agents.d.ts +21 -3
  258. package/dist/server/schemas/agents.d.ts.map +1 -1
  259. package/dist/server/schemas/default-options.d.ts +7 -1
  260. package/dist/server/schemas/default-options.d.ts.map +1 -1
  261. package/dist/server/schemas/index.cjs +7 -7
  262. package/dist/server/schemas/index.js +7 -7
  263. package/dist/server/schemas/stored-agents.d.ts +140 -20
  264. package/dist/server/schemas/stored-agents.d.ts.map +1 -1
  265. package/dist/server/server-adapter/index.cjs +28 -7
  266. package/dist/server/server-adapter/index.cjs.map +1 -1
  267. package/dist/server/server-adapter/index.d.ts +14 -1
  268. package/dist/server/server-adapter/index.d.ts.map +1 -1
  269. package/dist/server/server-adapter/index.js +28 -7
  270. package/dist/server/server-adapter/index.js.map +1 -1
  271. package/dist/server/server-adapter/openapi-utils.d.ts.map +1 -1
  272. package/dist/server/server-adapter/routes/a2a.d.ts +544 -504
  273. package/dist/server/server-adapter/routes/a2a.d.ts.map +1 -1
  274. package/dist/server/server-adapter/routes/agent-builder.d.ts +1054 -749
  275. package/dist/server/server-adapter/routes/agent-builder.d.ts.map +1 -1
  276. package/dist/server/server-adapter/routes/channels.d.ts +153 -73
  277. package/dist/server/server-adapter/routes/channels.d.ts.map +1 -1
  278. package/dist/server/server-adapter/routes/conversations.d.ts +218 -138
  279. package/dist/server/server-adapter/routes/conversations.d.ts.map +1 -1
  280. package/dist/server/server-adapter/routes/datasets.d.ts +2312 -1877
  281. package/dist/server/server-adapter/routes/datasets.d.ts.map +1 -1
  282. package/dist/server/server-adapter/routes/editor-builder.d.ts +506 -349
  283. package/dist/server/server-adapter/routes/editor-builder.d.ts.map +1 -1
  284. package/dist/server/server-adapter/routes/legacy.d.ts +615 -629
  285. package/dist/server/server-adapter/routes/legacy.d.ts.map +1 -1
  286. package/dist/server/server-adapter/routes/logs.d.ts +243 -183
  287. package/dist/server/server-adapter/routes/logs.d.ts.map +1 -1
  288. package/dist/server/server-adapter/routes/mcp.d.ts +347 -147
  289. package/dist/server/server-adapter/routes/mcp.d.ts.map +1 -1
  290. package/dist/server/server-adapter/routes/memory.d.ts +1699 -1199
  291. package/dist/server/server-adapter/routes/memory.d.ts.map +1 -1
  292. package/dist/server/server-adapter/routes/observability.d.ts +2761 -2103
  293. package/dist/server/server-adapter/routes/observability.d.ts.map +1 -1
  294. package/dist/server/server-adapter/routes/processor-providers.d.ts +70 -30
  295. package/dist/server/server-adapter/routes/processor-providers.d.ts.map +1 -1
  296. package/dist/server/server-adapter/routes/processors.d.ts +220 -171
  297. package/dist/server/server-adapter/routes/processors.d.ts.map +1 -1
  298. package/dist/server/server-adapter/routes/responses.d.ts +350 -360
  299. package/dist/server/server-adapter/routes/responses.d.ts.map +1 -1
  300. package/dist/server/server-adapter/routes/route-builder.d.ts +6 -2
  301. package/dist/server/server-adapter/routes/route-builder.d.ts.map +1 -1
  302. package/dist/server/server-adapter/routes/scorers.d.ts +282 -162
  303. package/dist/server/server-adapter/routes/scorers.d.ts.map +1 -1
  304. package/dist/server/server-adapter/routes/stored-mcp-clients.d.ts +821 -588
  305. package/dist/server/server-adapter/routes/stored-mcp-clients.d.ts.map +1 -1
  306. package/dist/server/server-adapter/routes/stored-prompt-blocks.d.ts +1252 -1064
  307. package/dist/server/server-adapter/routes/stored-prompt-blocks.d.ts.map +1 -1
  308. package/dist/server/server-adapter/routes/stored-scorers.d.ts +1046 -822
  309. package/dist/server/server-adapter/routes/stored-scorers.d.ts.map +1 -1
  310. package/dist/server/server-adapter/routes/stored-skills.d.ts +683 -526
  311. package/dist/server/server-adapter/routes/stored-skills.d.ts.map +1 -1
  312. package/dist/server/server-adapter/routes/stored-workspaces.d.ts +637 -537
  313. package/dist/server/server-adapter/routes/stored-workspaces.d.ts.map +1 -1
  314. package/dist/server/server-adapter/routes/system.d.ts +145 -105
  315. package/dist/server/server-adapter/routes/system.d.ts.map +1 -1
  316. package/dist/server/server-adapter/routes/tool-providers.d.ts +566 -317
  317. package/dist/server/server-adapter/routes/tool-providers.d.ts.map +1 -1
  318. package/dist/server/server-adapter/routes/tools.d.ts +103 -43
  319. package/dist/server/server-adapter/routes/tools.d.ts.map +1 -1
  320. package/dist/server/server-adapter/routes/vectors.d.ts +275 -119
  321. package/dist/server/server-adapter/routes/vectors.d.ts.map +1 -1
  322. package/dist/server/server-adapter/routes/workflows.d.ts +1586 -1104
  323. package/dist/server/server-adapter/routes/workflows.d.ts.map +1 -1
  324. package/dist/server/server-adapter/routes/workspace.d.ts +1026 -613
  325. package/dist/server/server-adapter/routes/workspace.d.ts.map +1 -1
  326. package/dist/{stored-agents-CWC-Nj6N.js → stored-agents-BRBZM-Xl.js} +2 -2
  327. package/dist/{stored-agents-CWC-Nj6N.js.map → stored-agents-BRBZM-Xl.js.map} +1 -1
  328. package/dist/{stored-agents-d2kvyKAb.cjs → stored-agents-CPxfYRH9.cjs} +2 -2
  329. package/dist/{stored-agents-d2kvyKAb.cjs.map → stored-agents-CPxfYRH9.cjs.map} +1 -1
  330. package/dist/{stored-scorers-yaft2JFH.js → stored-scorers-B__LF0Cy.js} +2 -2
  331. package/dist/{stored-scorers-yaft2JFH.js.map → stored-scorers-B__LF0Cy.js.map} +1 -1
  332. package/dist/{stored-scorers-Dm0HwOZe.cjs → stored-scorers-Cml7jPJv.cjs} +2 -2
  333. package/dist/{stored-scorers-Dm0HwOZe.cjs.map → stored-scorers-Cml7jPJv.cjs.map} +1 -1
  334. package/dist/sync-BHatXKfg.cjs +1679 -0
  335. package/dist/sync-BHatXKfg.cjs.map +1 -0
  336. package/dist/sync-djJ8Lmds.js +1656 -0
  337. package/dist/sync-djJ8Lmds.js.map +1 -0
  338. package/dist/{utils-wESuBh27.cjs → utils-Bna_JCkb.cjs} +3 -3
  339. package/dist/{utils-wESuBh27.cjs.map → utils-Bna_JCkb.cjs.map} +1 -1
  340. package/dist/{utils-BUK03Frl.js → utils-QXKhjIm6.js} +3 -3
  341. package/dist/{utils-BUK03Frl.js.map → utils-QXKhjIm6.js.map} +1 -1
  342. package/package.json +9 -9
  343. package/dist/dist-D-2BtcNU.js.map +0 -1
  344. package/dist/dist-DhqgxyoU.cjs.map +0 -1
  345. package/dist/probe-image-size-BQgIJeY_.js.map +0 -1
  346. package/dist/probe-image-size-DYJVSL0b.cjs.map +0 -1
  347. package/dist/route-builder-CIk5k35M.js.map +0 -1
  348. package/dist/route-builder-CgLVYL1c.cjs.map +0 -1
  349. package/dist/schema-B8-5YCsA.js +0 -2
  350. package/dist/schema-BieM1qrc.cjs +0 -1
  351. package/dist/schema-Bv9OdW1f-BY6u3u8K.cjs.map +0 -1
  352. package/dist/schema-Bv9OdW1f-CIOfv-3w.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"api-schema-manifest-D7g1cmet.cjs","names":["schemaToJsonSchema","SERVER_ROUTES"],"sources":["../src/server/server-adapter/api-schema-manifest.ts"],"sourcesContent":["import type { JSONSchema7 } from '@mastra/schema-compat';\nimport { schemaToJsonSchema } from './openapi-utils';\nimport { SERVER_ROUTES } from './routes/index';\nimport type { ServerRoute } from './routes/index';\n\nexport interface ApiSchemaResponseShape {\n kind: 'array' | 'record' | 'object-property' | 'single' | 'unknown';\n listProperty?: string;\n paginationProperty?: string;\n}\n\nexport interface ApiSchemaManifestRoute {\n method: string;\n path: string;\n responseType: string;\n pathParamSchema?: JSONSchema7;\n queryParamSchema?: JSONSchema7;\n bodySchema?: JSONSchema7;\n responseSchema?: JSONSchema7;\n responseShape: ApiSchemaResponseShape;\n}\n\nexport interface ApiSchemaManifest {\n version: 1;\n routes: ApiSchemaManifestRoute[];\n}\n\nfunction convertSchema(schema: ServerRoute['bodySchema']): JSONSchema7 | undefined {\n return schema ? schemaToJsonSchema(schema) : undefined;\n}\n\nfunction asJsonSchema(value: unknown): JSONSchema7 | undefined {\n return value && typeof value === 'object' && !Array.isArray(value) ? (value as JSONSchema7) : undefined;\n}\n\nfunction schemaType(schema: JSONSchema7 | undefined): JSONSchema7['type'] | undefined {\n const type = schema?.type;\n return Array.isArray(type) ? type.find(Boolean) : type;\n}\n\nfunction inferResponseShape(responseSchema: JSONSchema7 | undefined): ApiSchemaResponseShape {\n if (!responseSchema) return { kind: 'unknown' };\n\n const type = schemaType(responseSchema);\n if (type === 'array') return { kind: 'array' };\n if (type !== 'object') return { kind: 'single' };\n\n const properties =\n responseSchema.properties && !Array.isArray(responseSchema.properties) ? responseSchema.properties : {};\n const propertyNames = Object.keys(properties);\n const paginationProperty = 'page' in properties ? 'page' : 'pagination' in properties ? 'pagination' : undefined;\n const listProperty = Object.entries(properties).find(\n ([, property]) => schemaType(asJsonSchema(property)) === 'array',\n )?.[0];\n\n if (listProperty && (paginationProperty || propertyNames.length <= 2)) {\n return { kind: 'object-property', listProperty, paginationProperty };\n }\n if (responseSchema.additionalProperties && propertyNames.length === 0) return { kind: 'record' };\n return { kind: 'single' };\n}\n\nfunction isManifestRoute(route: ServerRoute): boolean {\n return route.responseType === 'json' && !route.deprecated;\n}\n\nexport function buildApiSchemaManifest(routes: readonly ServerRoute[] = SERVER_ROUTES): ApiSchemaManifest {\n return {\n version: 1,\n routes: routes.filter(isManifestRoute).map(route => {\n const responseSchema = convertSchema(route.responseSchema);\n return {\n method: route.method,\n path: route.path,\n responseType: route.responseType,\n pathParamSchema: convertSchema(route.pathParamSchema),\n queryParamSchema: convertSchema(route.queryParamSchema),\n bodySchema: convertSchema(route.bodySchema),\n responseSchema,\n responseShape: inferResponseShape(responseSchema),\n };\n }),\n };\n}\n"],"mappings":";;;AA2BA,SAAS,cAAc,QAA4D;CACjF,OAAO,SAASA,sBAAAA,mBAAmB,MAAM,IAAI,KAAA;AAC/C;AAEA,SAAS,aAAa,OAAyC;CAC7D,OAAO,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,IAAK,QAAwB,KAAA;AAChG;AAEA,SAAS,WAAW,QAAkE;CACpF,MAAM,OAAO,QAAQ;CACrB,OAAO,MAAM,QAAQ,IAAI,IAAI,KAAK,KAAK,OAAO,IAAI;AACpD;AAEA,SAAS,mBAAmB,gBAAiE;CAC3F,IAAI,CAAC,gBAAgB,OAAO,EAAE,MAAM,UAAU;CAE9C,MAAM,OAAO,WAAW,cAAc;CACtC,IAAI,SAAS,SAAS,OAAO,EAAE,MAAM,QAAQ;CAC7C,IAAI,SAAS,UAAU,OAAO,EAAE,MAAM,SAAS;CAE/C,MAAM,aACJ,eAAe,cAAc,CAAC,MAAM,QAAQ,eAAe,UAAU,IAAI,eAAe,aAAa,CAAC;CACxG,MAAM,gBAAgB,OAAO,KAAK,UAAU;CAC5C,MAAM,qBAAqB,UAAU,aAAa,SAAS,gBAAgB,aAAa,eAAe,KAAA;CACvG,MAAM,eAAe,OAAO,QAAQ,UAAU,CAAC,CAAC,MAC7C,GAAG,cAAc,WAAW,aAAa,QAAQ,CAAC,MAAM,OAC3D,CAAC,GAAG;CAEJ,IAAI,iBAAiB,sBAAsB,cAAc,UAAU,IACjE,OAAO;EAAE,MAAM;EAAmB;EAAc;CAAmB;CAErE,IAAI,eAAe,wBAAwB,cAAc,WAAW,GAAG,OAAO,EAAE,MAAM,SAAS;CAC/F,OAAO,EAAE,MAAM,SAAS;AAC1B;AAEA,SAAS,gBAAgB,OAA6B;CACpD,OAAO,MAAM,iBAAiB,UAAU,CAAC,MAAM;AACjD;AAEA,SAAgB,uBAAuB,SAAiCC,eAAAA,eAAkC;CACxG,OAAO;EACL,SAAS;EACT,QAAQ,OAAO,OAAO,eAAe,CAAC,CAAC,KAAI,UAAS;GAClD,MAAM,iBAAiB,cAAc,MAAM,cAAc;GACzD,OAAO;IACL,QAAQ,MAAM;IACd,MAAM,MAAM;IACZ,cAAc,MAAM;IACpB,iBAAiB,cAAc,MAAM,eAAe;IACpD,kBAAkB,cAAc,MAAM,gBAAgB;IACtD,YAAY,cAAc,MAAM,UAAU;IAC1C;IACA,eAAe,mBAAmB,cAAc;GAClD;EACF,CAAC;CACH;AACF"}
1
+ {"version":3,"file":"api-schema-manifest-BPk3u4B-.cjs","names":["schemaToJsonSchema","SERVER_ROUTES"],"sources":["../src/server/server-adapter/api-schema-manifest.ts"],"sourcesContent":["import type { JSONSchema7 } from '@mastra/schema-compat';\nimport { schemaToJsonSchema } from './openapi-utils';\nimport { SERVER_ROUTES } from './routes/index';\nimport type { ServerRoute } from './routes/index';\n\nexport interface ApiSchemaResponseShape {\n kind: 'array' | 'record' | 'object-property' | 'single' | 'unknown';\n listProperty?: string;\n paginationProperty?: string;\n}\n\nexport interface ApiSchemaManifestRoute {\n method: string;\n path: string;\n responseType: string;\n pathParamSchema?: JSONSchema7;\n queryParamSchema?: JSONSchema7;\n bodySchema?: JSONSchema7;\n responseSchema?: JSONSchema7;\n responseShape: ApiSchemaResponseShape;\n}\n\nexport interface ApiSchemaManifest {\n version: 1;\n routes: ApiSchemaManifestRoute[];\n}\n\nfunction convertSchema(schema: ServerRoute['bodySchema']): JSONSchema7 | undefined {\n return schema ? schemaToJsonSchema(schema) : undefined;\n}\n\nfunction asJsonSchema(value: unknown): JSONSchema7 | undefined {\n return value && typeof value === 'object' && !Array.isArray(value) ? (value as JSONSchema7) : undefined;\n}\n\nfunction schemaType(schema: JSONSchema7 | undefined): JSONSchema7['type'] | undefined {\n const type = schema?.type;\n return Array.isArray(type) ? type.find(Boolean) : type;\n}\n\nfunction inferResponseShape(responseSchema: JSONSchema7 | undefined): ApiSchemaResponseShape {\n if (!responseSchema) return { kind: 'unknown' };\n\n const type = schemaType(responseSchema);\n if (type === 'array') return { kind: 'array' };\n if (type !== 'object') return { kind: 'single' };\n\n const properties =\n responseSchema.properties && !Array.isArray(responseSchema.properties) ? responseSchema.properties : {};\n const propertyNames = Object.keys(properties);\n const paginationProperty = 'page' in properties ? 'page' : 'pagination' in properties ? 'pagination' : undefined;\n const listProperty = Object.entries(properties).find(\n ([, property]) => schemaType(asJsonSchema(property)) === 'array',\n )?.[0];\n\n if (listProperty && (paginationProperty || propertyNames.length <= 2)) {\n return { kind: 'object-property', listProperty, paginationProperty };\n }\n if (responseSchema.additionalProperties && propertyNames.length === 0) return { kind: 'record' };\n return { kind: 'single' };\n}\n\nfunction isManifestRoute(route: ServerRoute): boolean {\n return route.responseType === 'json' && !route.deprecated;\n}\n\nexport function buildApiSchemaManifest(routes: readonly ServerRoute[] = SERVER_ROUTES): ApiSchemaManifest {\n return {\n version: 1,\n routes: routes.filter(isManifestRoute).map(route => {\n const responseSchema = convertSchema(route.responseSchema);\n return {\n method: route.method,\n path: route.path,\n responseType: route.responseType,\n pathParamSchema: convertSchema(route.pathParamSchema),\n queryParamSchema: convertSchema(route.queryParamSchema),\n bodySchema: convertSchema(route.bodySchema),\n responseSchema,\n responseShape: inferResponseShape(responseSchema),\n };\n }),\n };\n}\n"],"mappings":";;;AA2BA,SAAS,cAAc,QAA4D;CACjF,OAAO,SAASA,sBAAAA,mBAAmB,MAAM,IAAI,KAAA;AAC/C;AAEA,SAAS,aAAa,OAAyC;CAC7D,OAAO,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,IAAK,QAAwB,KAAA;AAChG;AAEA,SAAS,WAAW,QAAkE;CACpF,MAAM,OAAO,QAAQ;CACrB,OAAO,MAAM,QAAQ,IAAI,IAAI,KAAK,KAAK,OAAO,IAAI;AACpD;AAEA,SAAS,mBAAmB,gBAAiE;CAC3F,IAAI,CAAC,gBAAgB,OAAO,EAAE,MAAM,UAAU;CAE9C,MAAM,OAAO,WAAW,cAAc;CACtC,IAAI,SAAS,SAAS,OAAO,EAAE,MAAM,QAAQ;CAC7C,IAAI,SAAS,UAAU,OAAO,EAAE,MAAM,SAAS;CAE/C,MAAM,aACJ,eAAe,cAAc,CAAC,MAAM,QAAQ,eAAe,UAAU,IAAI,eAAe,aAAa,CAAC;CACxG,MAAM,gBAAgB,OAAO,KAAK,UAAU;CAC5C,MAAM,qBAAqB,UAAU,aAAa,SAAS,gBAAgB,aAAa,eAAe,KAAA;CACvG,MAAM,eAAe,OAAO,QAAQ,UAAU,CAAC,CAAC,MAC7C,GAAG,cAAc,WAAW,aAAa,QAAQ,CAAC,MAAM,OAC3D,CAAC,GAAG;CAEJ,IAAI,iBAAiB,sBAAsB,cAAc,UAAU,IACjE,OAAO;EAAE,MAAM;EAAmB;EAAc;CAAmB;CAErE,IAAI,eAAe,wBAAwB,cAAc,WAAW,GAAG,OAAO,EAAE,MAAM,SAAS;CAC/F,OAAO,EAAE,MAAM,SAAS;AAC1B;AAEA,SAAS,gBAAgB,OAA6B;CACpD,OAAO,MAAM,iBAAiB,UAAU,CAAC,MAAM;AACjD;AAEA,SAAgB,uBAAuB,SAAiCC,eAAAA,eAAkC;CACxG,OAAO;EACL,SAAS;EACT,QAAQ,OAAO,OAAO,eAAe,CAAC,CAAC,KAAI,UAAS;GAClD,MAAM,iBAAiB,cAAc,MAAM,cAAc;GACzD,OAAO;IACL,QAAQ,MAAM;IACd,MAAM,MAAM;IACZ,cAAc,MAAM;IACpB,iBAAiB,cAAc,MAAM,eAAe;IACpD,kBAAkB,cAAc,MAAM,gBAAgB;IACtD,YAAY,cAAc,MAAM,UAAU;IAC1C;IACA,eAAe,mBAAmB,cAAc;GAClD;EACF,CAAC;CACH;AACF"}
@@ -1,5 +1,5 @@
1
- import { c as schemaToJsonSchema } from "./route-builder-CIk5k35M.js";
2
- import { t as SERVER_ROUTES } from "./routes-Q1t7kbml.js";
1
+ import { c as schemaToJsonSchema } from "./route-builder-YQ_gLIvW.js";
2
+ import { t as SERVER_ROUTES } from "./routes-BsMPy5bu.js";
3
3
  //#region src/server/server-adapter/api-schema-manifest.ts
4
4
  function convertSchema(schema) {
5
5
  return schema ? schemaToJsonSchema(schema) : void 0;
@@ -52,4 +52,4 @@ function buildApiSchemaManifest(routes = SERVER_ROUTES) {
52
52
  //#endregion
53
53
  export { buildApiSchemaManifest };
54
54
 
55
- //# sourceMappingURL=api-schema-manifest-CfgTQzaK.js.map
55
+ //# sourceMappingURL=api-schema-manifest-DSelT9XK.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"api-schema-manifest-CfgTQzaK.js","names":[],"sources":["../src/server/server-adapter/api-schema-manifest.ts"],"sourcesContent":["import type { JSONSchema7 } from '@mastra/schema-compat';\nimport { schemaToJsonSchema } from './openapi-utils';\nimport { SERVER_ROUTES } from './routes/index';\nimport type { ServerRoute } from './routes/index';\n\nexport interface ApiSchemaResponseShape {\n kind: 'array' | 'record' | 'object-property' | 'single' | 'unknown';\n listProperty?: string;\n paginationProperty?: string;\n}\n\nexport interface ApiSchemaManifestRoute {\n method: string;\n path: string;\n responseType: string;\n pathParamSchema?: JSONSchema7;\n queryParamSchema?: JSONSchema7;\n bodySchema?: JSONSchema7;\n responseSchema?: JSONSchema7;\n responseShape: ApiSchemaResponseShape;\n}\n\nexport interface ApiSchemaManifest {\n version: 1;\n routes: ApiSchemaManifestRoute[];\n}\n\nfunction convertSchema(schema: ServerRoute['bodySchema']): JSONSchema7 | undefined {\n return schema ? schemaToJsonSchema(schema) : undefined;\n}\n\nfunction asJsonSchema(value: unknown): JSONSchema7 | undefined {\n return value && typeof value === 'object' && !Array.isArray(value) ? (value as JSONSchema7) : undefined;\n}\n\nfunction schemaType(schema: JSONSchema7 | undefined): JSONSchema7['type'] | undefined {\n const type = schema?.type;\n return Array.isArray(type) ? type.find(Boolean) : type;\n}\n\nfunction inferResponseShape(responseSchema: JSONSchema7 | undefined): ApiSchemaResponseShape {\n if (!responseSchema) return { kind: 'unknown' };\n\n const type = schemaType(responseSchema);\n if (type === 'array') return { kind: 'array' };\n if (type !== 'object') return { kind: 'single' };\n\n const properties =\n responseSchema.properties && !Array.isArray(responseSchema.properties) ? responseSchema.properties : {};\n const propertyNames = Object.keys(properties);\n const paginationProperty = 'page' in properties ? 'page' : 'pagination' in properties ? 'pagination' : undefined;\n const listProperty = Object.entries(properties).find(\n ([, property]) => schemaType(asJsonSchema(property)) === 'array',\n )?.[0];\n\n if (listProperty && (paginationProperty || propertyNames.length <= 2)) {\n return { kind: 'object-property', listProperty, paginationProperty };\n }\n if (responseSchema.additionalProperties && propertyNames.length === 0) return { kind: 'record' };\n return { kind: 'single' };\n}\n\nfunction isManifestRoute(route: ServerRoute): boolean {\n return route.responseType === 'json' && !route.deprecated;\n}\n\nexport function buildApiSchemaManifest(routes: readonly ServerRoute[] = SERVER_ROUTES): ApiSchemaManifest {\n return {\n version: 1,\n routes: routes.filter(isManifestRoute).map(route => {\n const responseSchema = convertSchema(route.responseSchema);\n return {\n method: route.method,\n path: route.path,\n responseType: route.responseType,\n pathParamSchema: convertSchema(route.pathParamSchema),\n queryParamSchema: convertSchema(route.queryParamSchema),\n bodySchema: convertSchema(route.bodySchema),\n responseSchema,\n responseShape: inferResponseShape(responseSchema),\n };\n }),\n };\n}\n"],"mappings":";;;AA2BA,SAAS,cAAc,QAA4D;CACjF,OAAO,SAAS,mBAAmB,MAAM,IAAI,KAAA;AAC/C;AAEA,SAAS,aAAa,OAAyC;CAC7D,OAAO,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,IAAK,QAAwB,KAAA;AAChG;AAEA,SAAS,WAAW,QAAkE;CACpF,MAAM,OAAO,QAAQ;CACrB,OAAO,MAAM,QAAQ,IAAI,IAAI,KAAK,KAAK,OAAO,IAAI;AACpD;AAEA,SAAS,mBAAmB,gBAAiE;CAC3F,IAAI,CAAC,gBAAgB,OAAO,EAAE,MAAM,UAAU;CAE9C,MAAM,OAAO,WAAW,cAAc;CACtC,IAAI,SAAS,SAAS,OAAO,EAAE,MAAM,QAAQ;CAC7C,IAAI,SAAS,UAAU,OAAO,EAAE,MAAM,SAAS;CAE/C,MAAM,aACJ,eAAe,cAAc,CAAC,MAAM,QAAQ,eAAe,UAAU,IAAI,eAAe,aAAa,CAAC;CACxG,MAAM,gBAAgB,OAAO,KAAK,UAAU;CAC5C,MAAM,qBAAqB,UAAU,aAAa,SAAS,gBAAgB,aAAa,eAAe,KAAA;CACvG,MAAM,eAAe,OAAO,QAAQ,UAAU,CAAC,CAAC,MAC7C,GAAG,cAAc,WAAW,aAAa,QAAQ,CAAC,MAAM,OAC3D,CAAC,GAAG;CAEJ,IAAI,iBAAiB,sBAAsB,cAAc,UAAU,IACjE,OAAO;EAAE,MAAM;EAAmB;EAAc;CAAmB;CAErE,IAAI,eAAe,wBAAwB,cAAc,WAAW,GAAG,OAAO,EAAE,MAAM,SAAS;CAC/F,OAAO,EAAE,MAAM,SAAS;AAC1B;AAEA,SAAS,gBAAgB,OAA6B;CACpD,OAAO,MAAM,iBAAiB,UAAU,CAAC,MAAM;AACjD;AAEA,SAAgB,uBAAuB,SAAiC,eAAkC;CACxG,OAAO;EACL,SAAS;EACT,QAAQ,OAAO,OAAO,eAAe,CAAC,CAAC,KAAI,UAAS;GAClD,MAAM,iBAAiB,cAAc,MAAM,cAAc;GACzD,OAAO;IACL,QAAQ,MAAM;IACd,MAAM,MAAM;IACZ,cAAc,MAAM;IACpB,iBAAiB,cAAc,MAAM,eAAe;IACpD,kBAAkB,cAAc,MAAM,gBAAgB;IACtD,YAAY,cAAc,MAAM,UAAU;IAC1C;IACA,eAAe,mBAAmB,cAAc;GAClD;EACF,CAAC;CACH;AACF"}
1
+ {"version":3,"file":"api-schema-manifest-DSelT9XK.js","names":[],"sources":["../src/server/server-adapter/api-schema-manifest.ts"],"sourcesContent":["import type { JSONSchema7 } from '@mastra/schema-compat';\nimport { schemaToJsonSchema } from './openapi-utils';\nimport { SERVER_ROUTES } from './routes/index';\nimport type { ServerRoute } from './routes/index';\n\nexport interface ApiSchemaResponseShape {\n kind: 'array' | 'record' | 'object-property' | 'single' | 'unknown';\n listProperty?: string;\n paginationProperty?: string;\n}\n\nexport interface ApiSchemaManifestRoute {\n method: string;\n path: string;\n responseType: string;\n pathParamSchema?: JSONSchema7;\n queryParamSchema?: JSONSchema7;\n bodySchema?: JSONSchema7;\n responseSchema?: JSONSchema7;\n responseShape: ApiSchemaResponseShape;\n}\n\nexport interface ApiSchemaManifest {\n version: 1;\n routes: ApiSchemaManifestRoute[];\n}\n\nfunction convertSchema(schema: ServerRoute['bodySchema']): JSONSchema7 | undefined {\n return schema ? schemaToJsonSchema(schema) : undefined;\n}\n\nfunction asJsonSchema(value: unknown): JSONSchema7 | undefined {\n return value && typeof value === 'object' && !Array.isArray(value) ? (value as JSONSchema7) : undefined;\n}\n\nfunction schemaType(schema: JSONSchema7 | undefined): JSONSchema7['type'] | undefined {\n const type = schema?.type;\n return Array.isArray(type) ? type.find(Boolean) : type;\n}\n\nfunction inferResponseShape(responseSchema: JSONSchema7 | undefined): ApiSchemaResponseShape {\n if (!responseSchema) return { kind: 'unknown' };\n\n const type = schemaType(responseSchema);\n if (type === 'array') return { kind: 'array' };\n if (type !== 'object') return { kind: 'single' };\n\n const properties =\n responseSchema.properties && !Array.isArray(responseSchema.properties) ? responseSchema.properties : {};\n const propertyNames = Object.keys(properties);\n const paginationProperty = 'page' in properties ? 'page' : 'pagination' in properties ? 'pagination' : undefined;\n const listProperty = Object.entries(properties).find(\n ([, property]) => schemaType(asJsonSchema(property)) === 'array',\n )?.[0];\n\n if (listProperty && (paginationProperty || propertyNames.length <= 2)) {\n return { kind: 'object-property', listProperty, paginationProperty };\n }\n if (responseSchema.additionalProperties && propertyNames.length === 0) return { kind: 'record' };\n return { kind: 'single' };\n}\n\nfunction isManifestRoute(route: ServerRoute): boolean {\n return route.responseType === 'json' && !route.deprecated;\n}\n\nexport function buildApiSchemaManifest(routes: readonly ServerRoute[] = SERVER_ROUTES): ApiSchemaManifest {\n return {\n version: 1,\n routes: routes.filter(isManifestRoute).map(route => {\n const responseSchema = convertSchema(route.responseSchema);\n return {\n method: route.method,\n path: route.path,\n responseType: route.responseType,\n pathParamSchema: convertSchema(route.pathParamSchema),\n queryParamSchema: convertSchema(route.queryParamSchema),\n bodySchema: convertSchema(route.bodySchema),\n responseSchema,\n responseShape: inferResponseShape(responseSchema),\n };\n }),\n };\n}\n"],"mappings":";;;AA2BA,SAAS,cAAc,QAA4D;CACjF,OAAO,SAAS,mBAAmB,MAAM,IAAI,KAAA;AAC/C;AAEA,SAAS,aAAa,OAAyC;CAC7D,OAAO,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,IAAK,QAAwB,K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AU;IAC1C;IACA,eAAe,mBAAmB,cAAc;GAClD;EACF,CAAC;CACH;AACF"}
@@ -1,5 +1,5 @@
1
1
  import { t as HTTPException } from "./http-exception-CyfxZB6W.js";
2
- import { n as createRoute } from "./route-builder-CIk5k35M.js";
2
+ import { n as createRoute } from "./route-builder-YQ_gLIvW.js";
3
3
  import { z as z$1 } from "zod";
4
4
  //#region src/server/schemas/background-tasks.ts
5
5
  const backgroundTaskStatusSchema = z$1.enum([
@@ -140,4 +140,4 @@ const GET_BACKGROUND_TASK_ROUTE = createRoute({
140
140
  //#endregion
141
141
  export { GET_BACKGROUND_TASK_ROUTE as n, LIST_BACKGROUND_TASKS_ROUTE as r, BACKGROUND_TASK_STREAM_ROUTE as t };
142
142
 
143
- //# sourceMappingURL=background-tasks-DnmhLalp.js.map
143
+ //# sourceMappingURL=background-tasks-BtWM0sZs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"background-tasks-DnmhLalp.js","names":["z"],"sources":["../src/server/schemas/background-tasks.ts","../src/server/handlers/background-tasks.ts"],"sourcesContent":["import { z } from 'zod';\n\nexport const backgroundTaskStatusSchema = z.enum([\n 'pending',\n 'running',\n 'suspended',\n 'completed',\n 'failed',\n 'cancelled',\n 'timed_out',\n]);\n\nexport const backgroundTaskStreamQuerySchema = z.object({\n agentId: z.string().optional(),\n runId: z.string().optional(),\n threadId: z.string().optional(),\n resourceId: z.string().optional(),\n taskId: z.string().optional(),\n});\n\nexport const backgroundTaskDateColumnSchema = z.enum(['createdAt', 'startedAt', 'suspendedAt', 'completedAt']);\n\nexport const listBackgroundTasksQuerySchema = z.object({\n agentId: z.string().optional(),\n status: backgroundTaskStatusSchema.optional(),\n runId: z.string().optional(),\n threadId: z.string().optional(),\n resourceId: z.string().optional(),\n toolName: z.string().optional(),\n toolCallId: z.string().optional(),\n fromDate: z.coerce.date().optional(),\n toDate: z.coerce.date().optional(),\n dateFilterBy: backgroundTaskDateColumnSchema.optional(),\n orderBy: backgroundTaskDateColumnSchema.optional(),\n orderDirection: z.enum(['asc', 'desc']).optional(),\n page: z.coerce.number().optional(),\n perPage: z.coerce.number().optional(),\n});\n\nexport const backgroundTaskIdPathParams = z.object({\n backgroundTaskId: z.string(),\n});\n\nexport const backgroundTaskResponseSchema = z.object({\n id: z.string(),\n status: backgroundTaskStatusSchema,\n toolName: z.string(),\n toolCallId: z.string(),\n args: z.record(z.string(), z.unknown()),\n agentId: z.string(),\n threadId: z.string().optional(),\n resourceId: z.string().optional(),\n runId: z.string(),\n result: z.unknown().optional(),\n error: z.object({ message: z.string(), stack: z.string().optional() }).optional(),\n createdAt: z.date(),\n startedAt: z.date().optional(),\n completedAt: z.date().optional(),\n retryCount: z.number(),\n maxRetries: z.number(),\n timeoutMs: z.number(),\n suspendPayload: z.unknown().optional(),\n});\n\nexport const listBackgroundTaskResponseSchema = z.object({\n tasks: z.array(backgroundTaskResponseSchema),\n total: z.number(),\n});\n\nexport const backgroundTaskStreamResponseSchema = z.unknown();\n","import { HTTPException } from '../http-exception';\nimport {\n backgroundTaskResponseSchema,\n backgroundTaskStreamQuerySchema,\n backgroundTaskStreamResponseSchema,\n listBackgroundTaskResponseSchema,\n listBackgroundTasksQuerySchema,\n backgroundTaskIdPathParams,\n} from '../schemas/background-tasks';\nimport { createRoute } from '../server-adapter/routes/route-builder';\n\nexport const BACKGROUND_TASK_STREAM_ROUTE = createRoute({\n method: 'GET',\n path: '/background-tasks/stream',\n responseType: 'stream' as const,\n streamFormat: 'sse' as const,\n queryParamSchema: backgroundTaskStreamQuerySchema,\n responseSchema: backgroundTaskStreamResponseSchema,\n summary: 'Stream background task events via SSE',\n description: 'Real-time Server-Sent Events stream of background task completion/failure events.',\n tags: ['Background Tasks'],\n requiresAuth: true,\n handler: async ({ mastra, agentId, runId, threadId, resourceId, taskId, abortSignal }) => {\n const bgManager = mastra.backgroundTaskManager;\n if (!bgManager) {\n // Background tasks are not enabled — return an empty stream that stays\n // open until the client disconnects. This avoids spamming the logs with\n // false-positive errors when clients (e.g. the studio UI) optimistically\n // subscribe to the stream.\n return new ReadableStream({\n start(controller) {\n abortSignal?.addEventListener('abort', () => {\n try {\n controller.close();\n } catch {\n // Already closed\n }\n });\n },\n });\n }\n\n return bgManager.stream({ agentId, runId, threadId, resourceId, taskId, abortSignal });\n },\n});\n\nexport const LIST_BACKGROUND_TASKS_ROUTE = createRoute({\n method: 'GET',\n path: '/background-tasks',\n responseType: 'json' as const,\n queryParamSchema: listBackgroundTasksQuerySchema,\n responseSchema: listBackgroundTaskResponseSchema,\n summary: 'List background tasks',\n description: 'Returns background tasks filtered by status, agent, run, etc.',\n tags: ['Background Tasks'],\n requiresAuth: true,\n handler: async ({ mastra, ...params }) => {\n const bgManager = mastra.backgroundTaskManager;\n if (!bgManager) {\n // Background tasks not enabled — there are no tasks to return.\n return { tasks: [], total: 0 };\n }\n\n return bgManager.listTasks(params);\n },\n});\n\nexport const GET_BACKGROUND_TASK_ROUTE = createRoute({\n method: 'GET',\n path: '/background-tasks/:backgroundTaskId',\n responseType: 'json' as const,\n pathParamSchema: backgroundTaskIdPathParams,\n responseSchema: backgroundTaskResponseSchema,\n summary: 'Get a background task by ID',\n description: 'Returns a background task by ID.',\n tags: ['Background Tasks'],\n requiresAuth: true,\n handler: async ({ mastra, backgroundTaskId }) => {\n const bgManager = mastra.backgroundTaskManager;\n if (!bgManager) {\n // Background tasks not enabled — the task can't exist.\n throw new HTTPException(404, { message: 'Background task not found' });\n }\n\n const task = await bgManager.getTask(backgroundTaskId);\n if (!task) {\n throw new HTTPException(404, { message: 'Background task not found' });\n }\n return task;\n },\n});\n"],"mappings":";;;;AAEA,MAAa,6BAA6BA,IAAE,KAAK;CAC/C;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAa,kCAAkCA,IAAE,OAAO;CACtD,SAASA,IAAE,OAAO,CAAC,CAAC,SAAS;CAC7B,OAAOA,IAAE,OAAO,CAAC,CAAC,SAAS;CAC3B,UAAUA,IAAE,OAAO,CAAC,CA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aAAa;EACxC,MAAM,YAAY,OAAO;EACzB,IAAI,CAAC,WAEH,OAAO;GAAE,OAAO,CAAC;GAAG,OAAO;EAAE;EAG/B,OAAO,UAAU,UAAU,MAAM;CACnC;AACF,CAAC;AAED,MAAa,4BAA4B,YAAY;CACnD,QAAQ;CACR,MAAM;CACN,cAAc;CACd,iBAAiB;CACjB,gBAAgB;CAChB,SAAS;CACT,aAAa;CACb,MAAM,CAAC,kBAAkB;CACzB,cAAc;CACd,SAAS,OAAO,EAAE,QAAQ,uBAAuB;EAC/C,MAAM,YAAY,OAAO;EACzB,IAAI,CAAC,WAEH,MAAM,IAAI,cAAc,KAAK,EAAE,SAAS,4BAA4B,CAAC;EAGvE,MAAM,OAAO,MAAM,UAAU,QAAQ,gBAAgB;EACrD,IAAI,CAAC,MACH,MAAM,IAAI,cAAc,KAAK,EAAE,SAAS,4BAA4B,CAAC;EAEvE,OAAO;CACT;AACF,CAAC"}
1
+ {"version":3,"file":"background-tasks-BtWM0sZs.js","names":["z"],"sources":["../src/server/schemas/background-tasks.ts","../src/server/handlers/background-tasks.ts"],"sourcesContent":["import { z } from 'zod';\n\nexport const backgroundTaskStatusSchema = z.enum([\n 'pending',\n 'running',\n 'suspended',\n 'completed',\n 'failed',\n 'cancelled',\n 'timed_out',\n]);\n\nexport const backgroundTaskStreamQuerySchema = z.object({\n agentId: z.string().optional(),\n runId: z.string().optional(),\n threadId: z.string().optional(),\n resourceId: z.string().optional(),\n taskId: z.string().optional(),\n});\n\nexport const backgroundTaskDateColumnSchema = z.enum(['createdAt', 'startedAt', 'suspendedAt', 'completedAt']);\n\nexport const listBackgroundTasksQuerySchema = z.object({\n agentId: z.string().optional(),\n status: backgroundTaskStatusSchema.optional(),\n runId: z.string().optional(),\n threadId: z.string().optional(),\n resourceId: z.string().optional(),\n toolName: z.string().optional(),\n toolCallId: z.string().optional(),\n fromDate: z.coerce.date().optional(),\n toDate: z.coerce.date().optional(),\n dateFilterBy: backgroundTaskDateColumnSchema.optional(),\n orderBy: backgroundTaskDateColumnSchema.optional(),\n orderDirection: z.enum(['asc', 'desc']).optional(),\n page: z.coerce.number().optional(),\n perPage: z.coerce.number().optional(),\n});\n\nexport const backgroundTaskIdPathParams = z.object({\n backgroundTaskId: z.string(),\n});\n\nexport const backgroundTaskResponseSchema = z.object({\n id: z.string(),\n status: backgroundTaskStatusSchema,\n toolName: z.string(),\n toolCallId: z.string(),\n args: z.record(z.string(), z.unknown()),\n agentId: z.string(),\n threadId: z.string().optional(),\n resourceId: z.string().optional(),\n runId: z.string(),\n result: z.unknown().optional(),\n error: z.object({ message: z.string(), stack: z.string().optional() }).optional(),\n createdAt: z.date(),\n startedAt: z.date().optional(),\n completedAt: z.date().optional(),\n retryCount: z.number(),\n maxRetries: z.number(),\n timeoutMs: z.number(),\n suspendPayload: z.unknown().optional(),\n});\n\nexport const listBackgroundTaskResponseSchema = z.object({\n tasks: z.array(backgroundTaskResponseSchema),\n total: z.number(),\n});\n\nexport const backgroundTaskStreamResponseSchema = z.unknown();\n","import { HTTPException } from '../http-exception';\nimport {\n backgroundTaskResponseSchema,\n backgroundTaskStreamQuerySchema,\n backgroundTaskStreamResponseSchema,\n listBackgroundTaskResponseSchema,\n listBackgroundTasksQuerySchema,\n backgroundTaskIdPathParams,\n} from '../schemas/background-tasks';\nimport { createRoute } from '../server-adapter/routes/route-builder';\n\nexport const BACKGROUND_TASK_STREAM_ROUTE = createRoute({\n method: 'GET',\n path: '/background-tasks/stream',\n responseType: 'stream' as const,\n streamFormat: 'sse' as const,\n queryParamSchema: backgroundTaskStreamQuerySchema,\n responseSchema: backgroundTaskStreamResponseSchema,\n summary: 'Stream background task events via SSE',\n description: 'Real-time Server-Sent Events stream of background task completion/failure events.',\n tags: ['Background Tasks'],\n requiresAuth: true,\n handler: async ({ mastra, agentId, runId, threadId, resourceId, taskId, abortSignal }) => {\n const bgManager = mastra.backgroundTaskManager;\n if (!bgManager) {\n // Background tasks are not enabled — return an empty stream that stays\n // open until the client disconnects. This avoids spamming the logs with\n // false-positive errors when clients (e.g. the studio UI) optimistically\n // subscribe to the stream.\n return new ReadableStream({\n start(controller) {\n abortSignal?.addEventListener('abort', () => {\n try {\n controller.close();\n } catch {\n // Already closed\n }\n });\n },\n });\n }\n\n return bgManager.stream({ agentId, runId, threadId, resourceId, taskId, abortSignal });\n },\n});\n\nexport const LIST_BACKGROUND_TASKS_ROUTE = createRoute({\n method: 'GET',\n path: '/background-tasks',\n responseType: 'json' as const,\n queryParamSchema: listBackgroundTasksQuerySchema,\n responseSchema: listBackgroundTaskResponseSchema,\n summary: 'List background tasks',\n description: 'Returns background tasks filtered by status, agent, run, etc.',\n tags: ['Background Tasks'],\n requiresAuth: true,\n handler: async ({ mastra, ...params }) => {\n const bgManager = mastra.backgroundTaskManager;\n if (!bgManager) {\n // Background tasks not enabled — there are no tasks to return.\n return { tasks: [], total: 0 };\n }\n\n return bgManager.listTasks(params);\n },\n});\n\nexport const GET_BACKGROUND_TASK_ROUTE = createRoute({\n method: 'GET',\n path: '/background-tasks/:backgroundTaskId',\n responseType: 'json' as const,\n pathParamSchema: backgroundTaskIdPathParams,\n responseSchema: backgroundTaskResponseSchema,\n summary: 'Get a background task by ID',\n description: 'Returns a background task by ID.',\n tags: ['Background Tasks'],\n requiresAuth: true,\n handler: async ({ mastra, backgroundTaskId }) => {\n const bgManager = mastra.backgroundTaskManager;\n if (!bgManager) {\n // Background tasks not enabled — the task can't exist.\n throw new HTTPException(404, { message: 'Background task not found' });\n }\n\n const task = await bgManager.getTask(backgroundTaskId);\n if (!task) {\n throw new HTTPException(404, { message: 'Background task not found' });\n }\n return task;\n },\n});\n"],"mappings":";;;;AAEA,MAAa,6BAA6BA,IAAE,KAAK;CAC/C;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAa,kCAAkCA,IAAE,OAAO;CACtD,SAASA,IAAE,OAAO,CAAC,CAAC,SAAS;CAC7B,OAAOA,IAAE,OAAO,CAAC,CAAC,SAAS;CAC3B,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S,OAAO,EAAE,QAAQ,GAAG,aAAa;EACxC,MAAM,YAAY,OAAO;EACzB,IAAI,CAAC,WAEH,OAAO;GAAE,OAAO,CAAC;GAAG,OAAO;EAAE;EAG/B,OAAO,UAAU,UAAU,MAAM;CACnC;AACF,CAAC;AAED,MAAa,4BAA4B,YAAY;CACnD,QAAQ;CACR,MAAM;CACN,cAAc;CACd,iBAAiB;CACjB,gBAAgB;CAChB,SAAS;CACT,aAAa;CACb,MAAM,CAAC,kBAAkB;CACzB,cAAc;CACd,SAAS,OAAO,EAAE,QAAQ,uBAAuB;EAC/C,MAAM,YAAY,OAAO;EACzB,IAAI,CAAC,WAEH,MAAM,IAAI,cAAc,KAAK,EAAE,SAAS,4BAA4B,CAAC;EAGvE,MAAM,OAAO,MAAM,UAAU,QAAQ,gBAAgB;EACrD,IAAI,CAAC,MACH,MAAM,IAAI,cAAc,KAAK,EAAE,SAAS,4BAA4B,CAAC;EAEvE,OAAO;CACT;AACF,CAAC"}
@@ -1,5 +1,5 @@
1
1
  const require_http_exception = require("./http-exception-CKDHupKw.cjs");
2
- const require_route_builder = require("./route-builder-CgLVYL1c.cjs");
2
+ const require_route_builder = require("./route-builder-BAAedfru.cjs");
3
3
  let zod = require("zod");
4
4
  //#region src/server/schemas/background-tasks.ts
5
5
  const backgroundTaskStatusSchema = zod.z.enum([
@@ -158,4 +158,4 @@ Object.defineProperty(exports, "LIST_BACKGROUND_TASKS_ROUTE", {
158
158
  }
159
159
  });
160
160
 
161
- //# sourceMappingURL=background-tasks-CYgzzUnb.cjs.map
161
+ //# sourceMappingURL=background-tasks-C5G2jJax.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"background-tasks-CYgzzUnb.cjs","names":["z","createRoute","HTTPException"],"sources":["../src/server/schemas/background-tasks.ts","../src/server/handlers/background-tasks.ts"],"sourcesContent":["import { z } from 'zod';\n\nexport const backgroundTaskStatusSchema = z.enum([\n 'pending',\n 'running',\n 'suspended',\n 'completed',\n 'failed',\n 'cancelled',\n 'timed_out',\n]);\n\nexport const backgroundTaskStreamQuerySchema = z.object({\n agentId: z.string().optional(),\n runId: z.string().optional(),\n threadId: z.string().optional(),\n resourceId: z.string().optional(),\n taskId: z.string().optional(),\n});\n\nexport const backgroundTaskDateColumnSchema = z.enum(['createdAt', 'startedAt', 'suspendedAt', 'completedAt']);\n\nexport const listBackgroundTasksQuerySchema = z.object({\n agentId: z.string().optional(),\n status: backgroundTaskStatusSchema.optional(),\n runId: z.string().optional(),\n threadId: z.string().optional(),\n resourceId: z.string().optional(),\n toolName: z.string().optional(),\n toolCallId: z.string().optional(),\n fromDate: z.coerce.date().optional(),\n toDate: z.coerce.date().optional(),\n dateFilterBy: backgroundTaskDateColumnSchema.optional(),\n orderBy: backgroundTaskDateColumnSchema.optional(),\n orderDirection: z.enum(['asc', 'desc']).optional(),\n page: z.coerce.number().optional(),\n perPage: z.coerce.number().optional(),\n});\n\nexport const backgroundTaskIdPathParams = z.object({\n backgroundTaskId: z.string(),\n});\n\nexport const backgroundTaskResponseSchema = z.object({\n id: z.string(),\n status: backgroundTaskStatusSchema,\n toolName: z.string(),\n toolCallId: z.string(),\n args: z.record(z.string(), z.unknown()),\n agentId: z.string(),\n threadId: z.string().optional(),\n resourceId: z.string().optional(),\n runId: z.string(),\n result: z.unknown().optional(),\n error: z.object({ message: z.string(), stack: z.string().optional() }).optional(),\n createdAt: z.date(),\n startedAt: z.date().optional(),\n completedAt: z.date().optional(),\n retryCount: z.number(),\n maxRetries: z.number(),\n timeoutMs: z.number(),\n suspendPayload: z.unknown().optional(),\n});\n\nexport const listBackgroundTaskResponseSchema = z.object({\n tasks: z.array(backgroundTaskResponseSchema),\n total: z.number(),\n});\n\nexport const backgroundTaskStreamResponseSchema = z.unknown();\n","import { HTTPException } from '../http-exception';\nimport {\n backgroundTaskResponseSchema,\n backgroundTaskStreamQuerySchema,\n backgroundTaskStreamResponseSchema,\n listBackgroundTaskResponseSchema,\n listBackgroundTasksQuerySchema,\n backgroundTaskIdPathParams,\n} from '../schemas/background-tasks';\nimport { createRoute } from '../server-adapter/routes/route-builder';\n\nexport const BACKGROUND_TASK_STREAM_ROUTE = createRoute({\n method: 'GET',\n path: '/background-tasks/stream',\n responseType: 'stream' as const,\n streamFormat: 'sse' as const,\n queryParamSchema: backgroundTaskStreamQuerySchema,\n responseSchema: backgroundTaskStreamResponseSchema,\n summary: 'Stream background task events via SSE',\n description: 'Real-time Server-Sent Events stream of background task completion/failure events.',\n tags: ['Background Tasks'],\n requiresAuth: true,\n handler: async ({ mastra, agentId, runId, threadId, resourceId, taskId, abortSignal }) => {\n const bgManager = mastra.backgroundTaskManager;\n if (!bgManager) {\n // Background tasks are not enabled — return an empty stream that stays\n // open until the client disconnects. This avoids spamming the logs with\n // false-positive errors when clients (e.g. the studio UI) optimistically\n // subscribe to the stream.\n return new ReadableStream({\n start(controller) {\n abortSignal?.addEventListener('abort', () => {\n try {\n controller.close();\n } catch {\n // Already closed\n }\n });\n },\n });\n }\n\n return bgManager.stream({ agentId, runId, threadId, resourceId, taskId, abortSignal });\n },\n});\n\nexport const LIST_BACKGROUND_TASKS_ROUTE = createRoute({\n method: 'GET',\n path: '/background-tasks',\n responseType: 'json' as const,\n queryParamSchema: listBackgroundTasksQuerySchema,\n responseSchema: listBackgroundTaskResponseSchema,\n summary: 'List background tasks',\n description: 'Returns background tasks filtered by status, agent, run, etc.',\n tags: ['Background Tasks'],\n requiresAuth: true,\n handler: async ({ mastra, ...params }) => {\n const bgManager = mastra.backgroundTaskManager;\n if (!bgManager) {\n // Background tasks not enabled — there are no tasks to return.\n return { tasks: [], total: 0 };\n }\n\n return bgManager.listTasks(params);\n },\n});\n\nexport const GET_BACKGROUND_TASK_ROUTE = createRoute({\n method: 'GET',\n path: '/background-tasks/:backgroundTaskId',\n responseType: 'json' as const,\n pathParamSchema: backgroundTaskIdPathParams,\n responseSchema: backgroundTaskResponseSchema,\n summary: 'Get a background task by ID',\n description: 'Returns a background task by ID.',\n tags: ['Background Tasks'],\n requiresAuth: true,\n handler: async ({ mastra, backgroundTaskId }) => {\n const bgManager = mastra.backgroundTaskManager;\n if (!bgManager) {\n // Background tasks not enabled — the task can't exist.\n throw new HTTPException(404, { message: 'Background task not found' });\n }\n\n const task = await bgManager.getTask(backgroundTaskId);\n if (!task) {\n throw new HTTPException(404, { message: 'Background task not found' });\n }\n return task;\n },\n});\n"],"mappings":";;;;AAEA,MAAa,6BAA6BA,IAAAA,EAAE,KAAK;CAC/C;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAa,kCAAkCA,IAAAA,EAAE,OAAO;CACtD,SAASA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS;CAC7B,OAAOA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS;CAC3B,UAAUA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS;CAC9B,YAAYA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS;CAChC,QAAQA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS;AAC9B,CAAC;AAED,MAAa,iCAAiCA,IAAAA,EAAE,KAAK;CAAC;CAAa;CAAa;CAAe;AAAa,CAAC;AAE7G,MAAa,iCAAiCA,IAAAA,EAAE,OAAO;CACrD,SAASA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS;CAC7B,QAAQ,2BAA2B,SAAS;CAC5C,OAAOA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS;CAC3B,UAAUA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS;CAC9B,YAAYA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS;CAChC,UAAUA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS;CAC9B,YAAYA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS;CAChC,UAAUA,IAAAA,EAAE,OAAO,KAAK,CAAC,CAAC,SAAS;CACnC,QAAQA,IAAAA,EAAE,OAAO,KAAK,CAAC,CAAC,SAAS;CACjC,cAAc,+BAA+B,SAAS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B,IAAI,CAAC,WAEH,MAAM,IAAIC,uBAAAA,cAAc,KAAK,EAAE,SAAS,4BAA4B,CAAC;EAGvE,MAAM,OAAO,MAAM,UAAU,QAAQ,gBAAgB;EACrD,IAAI,CAAC,MACH,MAAM,IAAIA,uBAAAA,cAAc,KAAK,EAAE,SAAS,4BAA4B,CAAC;EAEvE,OAAO;CACT;AACF,CAAC"}
1
+ {"version":3,"file":"background-tasks-C5G2jJax.cjs","names":["z","createRoute","HTTPException"],"sources":["../src/server/schemas/background-tasks.ts","../src/server/handlers/background-tasks.ts"],"sourcesContent":["import { z } from 'zod';\n\nexport const backgroundTaskStatusSchema = z.enum([\n 'pending',\n 'running',\n 'suspended',\n 'completed',\n 'failed',\n 'cancelled',\n 'timed_out',\n]);\n\nexport const backgroundTaskStreamQuerySchema = z.object({\n agentId: z.string().optional(),\n runId: z.string().optional(),\n threadId: z.string().optional(),\n resourceId: z.string().optional(),\n taskId: z.string().optional(),\n});\n\nexport const backgroundTaskDateColumnSchema = z.enum(['createdAt', 'startedAt', 'suspendedAt', 'completedAt']);\n\nexport const listBackgroundTasksQuerySchema = z.object({\n agentId: z.string().optional(),\n status: backgroundTaskStatusSchema.optional(),\n runId: z.string().optional(),\n threadId: z.string().optional(),\n resourceId: z.string().optional(),\n toolName: z.string().optional(),\n toolCallId: z.string().optional(),\n fromDate: z.coerce.date().optional(),\n toDate: z.coerce.date().optional(),\n dateFilterBy: backgroundTaskDateColumnSchema.optional(),\n orderBy: backgroundTaskDateColumnSchema.optional(),\n orderDirection: z.enum(['asc', 'desc']).optional(),\n page: z.coerce.number().optional(),\n perPage: z.coerce.number().optional(),\n});\n\nexport const backgroundTaskIdPathParams = z.object({\n backgroundTaskId: z.string(),\n});\n\nexport const backgroundTaskResponseSchema = z.object({\n id: z.string(),\n status: backgroundTaskStatusSchema,\n toolName: z.string(),\n toolCallId: z.string(),\n args: z.record(z.string(), z.unknown()),\n agentId: z.string(),\n threadId: z.string().optional(),\n resourceId: z.string().optional(),\n runId: z.string(),\n result: z.unknown().optional(),\n error: z.object({ message: z.string(), stack: z.string().optional() }).optional(),\n createdAt: z.date(),\n startedAt: z.date().optional(),\n completedAt: z.date().optional(),\n retryCount: z.number(),\n maxRetries: z.number(),\n timeoutMs: z.number(),\n suspendPayload: z.unknown().optional(),\n});\n\nexport const listBackgroundTaskResponseSchema = z.object({\n tasks: z.array(backgroundTaskResponseSchema),\n total: z.number(),\n});\n\nexport const backgroundTaskStreamResponseSchema = z.unknown();\n","import { HTTPException } from '../http-exception';\nimport {\n backgroundTaskResponseSchema,\n backgroundTaskStreamQuerySchema,\n backgroundTaskStreamResponseSchema,\n listBackgroundTaskResponseSchema,\n listBackgroundTasksQuerySchema,\n backgroundTaskIdPathParams,\n} from '../schemas/background-tasks';\nimport { createRoute } from '../server-adapter/routes/route-builder';\n\nexport const BACKGROUND_TASK_STREAM_ROUTE = createRoute({\n method: 'GET',\n path: '/background-tasks/stream',\n responseType: 'stream' as const,\n streamFormat: 'sse' as const,\n queryParamSchema: backgroundTaskStreamQuerySchema,\n responseSchema: backgroundTaskStreamResponseSchema,\n summary: 'Stream background task events via SSE',\n description: 'Real-time Server-Sent Events stream of background task completion/failure events.',\n tags: ['Background Tasks'],\n requiresAuth: true,\n handler: async ({ mastra, agentId, runId, threadId, resourceId, taskId, abortSignal }) => {\n const bgManager = mastra.backgroundTaskManager;\n if (!bgManager) {\n // Background tasks are not enabled — return an empty stream that stays\n // open until the client disconnects. This avoids spamming the logs with\n // false-positive errors when clients (e.g. the studio UI) optimistically\n // subscribe to the stream.\n return new ReadableStream({\n start(controller) {\n abortSignal?.addEventListener('abort', () => {\n try {\n controller.close();\n } catch {\n // Already closed\n }\n });\n },\n });\n }\n\n return bgManager.stream({ agentId, runId, threadId, resourceId, taskId, abortSignal });\n },\n});\n\nexport const LIST_BACKGROUND_TASKS_ROUTE = createRoute({\n method: 'GET',\n path: '/background-tasks',\n responseType: 'json' as const,\n queryParamSchema: listBackgroundTasksQuerySchema,\n responseSchema: listBackgroundTaskResponseSchema,\n summary: 'List background tasks',\n description: 'Returns background tasks filtered by status, agent, run, etc.',\n tags: ['Background Tasks'],\n requiresAuth: true,\n handler: async ({ mastra, ...params }) => {\n const bgManager = mastra.backgroundTaskManager;\n if (!bgManager) {\n // Background tasks not enabled — there are no tasks to return.\n return { tasks: [], total: 0 };\n }\n\n return bgManager.listTasks(params);\n },\n});\n\nexport const GET_BACKGROUND_TASK_ROUTE = createRoute({\n method: 'GET',\n path: '/background-tasks/:backgroundTaskId',\n responseType: 'json' as const,\n pathParamSchema: backgroundTaskIdPathParams,\n responseSchema: backgroundTaskResponseSchema,\n summary: 'Get a background task by ID',\n description: 'Returns a background task by ID.',\n tags: ['Background Tasks'],\n requiresAuth: true,\n handler: async ({ mastra, backgroundTaskId }) => {\n const bgManager = mastra.backgroundTaskManager;\n if (!bgManager) {\n // Background tasks not enabled — the task can't exist.\n throw new HTTPException(404, { message: 'Background task not found' });\n }\n\n const task = await bgManager.getTask(backgroundTaskId);\n if (!task) {\n throw new HTTPException(404, { message: 'Background task not found' });\n }\n return task;\n },\n});\n"],"mappings":";;;;AAEA,MAAa,6BAA6BA,IAAAA,EAAE,KAAK;CAC/C;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAa,kCAAkCA,IAAAA,EAAE,OAAO;CACtD,SAASA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS;CAC7B,OAAOA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS;CAC3B,UAAUA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS;CAC9B,YAAYA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS;CAChC,QAAQA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS;AAC9B,CAAC;AAED,MAAa,iCAAiCA,IAAAA,EAAE,KAAK;CAAC;CAAa;CAAa;CAAe;AAAa,CAAC;AAE7G,MAAa,iCAAiCA,IAAAA,EAAE,OAAO;CACrD,SAASA,IAAAA,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;CACT,aAAa;CACb,MAAM,CAAC,kBAAkB;CACzB,cAAc;CACd,SAAS,OAAO,EAAE,QAAQ,GAAG,aAAa;EACxC,MAAM,YAAY,OAAO;EACzB,IAAI,CAAC,WAEH,OAAO;GAAE,OAAO,CAAC;GAAG,OAAO;EAAE;EAG/B,OAAO,UAAU,UAAU,MAAM;CACnC;AACF,CAAC;AAED,MAAa,4BAA4BA,sBAAAA,YAAY;CACnD,QAAQ;CACR,MAAM;CACN,cAAc;CACd,iBAAiB;CACjB,gBAAgB;CAChB,SAAS;CACT,aAAa;CACb,MAAM,CAAC,kBAAkB;CACzB,cAAc;CACd,SAAS,OAAO,EAAE,QAAQ,uBAAuB;EAC/C,MAAM,YAAY,OAAO;EACzB,IAAI,CAAC,WAEH,MAAM,IAAIC,uBAAAA,cAAc,KAAK,EAAE,SAAS,4BAA4B,CAAC;EAGvE,MAAM,OAAO,MAAM,UAAU,QAAQ,gBAAgB;EACrD,IAAI,CAAC,MACH,MAAM,IAAIA,uBAAAA,cAAc,KAAK,EAAE,SAAS,4BAA4B,CAAC;EAEvE,OAAO;CACT;AACF,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { t as HTTPException } from "./http-exception-CyfxZB6W.js";
2
- import { n as createRoute } from "./route-builder-CIk5k35M.js";
3
- import { c as toSlug } from "./utils-BUK03Frl.js";
2
+ import { n as createRoute } from "./route-builder-YQ_gLIvW.js";
3
+ import { c as toSlug } from "./utils-QXKhjIm6.js";
4
4
  import { handleError } from "./server/handlers/error.js";
5
5
  import { H as skillsShPreviewResponseSchema, K as skillsShSearchResponseSchema, z as skillsShListResponseSchema } from "./workspace-S5GiJ3Nx.js";
6
6
  import { getCallerAuthorId } from "./server/handlers/authorship.js";
@@ -351,4 +351,4 @@ const BUILDER_REGISTRY_INSTALL_ROUTE = createRoute({
351
351
  //#endregion
352
352
  export { LIST_BUILDER_REGISTRIES_ROUTE as a, BUILDER_REGISTRY_SEARCH_ROUTE as i, BUILDER_REGISTRY_POPULAR_ROUTE as n, BUILDER_REGISTRY_PREVIEW_ROUTE as r, BUILDER_REGISTRY_INSTALL_ROUTE as t };
353
353
 
354
- //# sourceMappingURL=builder-registry-DE5w7bNk.js.map
354
+ //# sourceMappingURL=builder-registry-B8KyPAOP.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"builder-registry-DE5w7bNk.js","names":[],"sources":["../src/server/schemas/builder-registry.ts","../src/server/handlers/builder-registry.ts"],"sourcesContent":["/**\n * Builder Registry Schemas\n *\n * Schemas for the Agent Builder skill registry routes. These are distinct from\n * the workspace skills.sh proxy schemas because:\n * - Builder routes are not scoped to a workspace.\n * - Builder install does not accept a `mount` field.\n * - Builder install body carries visibility + the resolved registry id.\n * - Builder install response returns the created stored skill id.\n *\n * The upstream skills.sh proxy response shapes are reused via the shared\n * `skillsShSearchResponseSchema`, `skillsShListResponseSchema`, and\n * `skillsShPreviewResponseSchema` since the wire shape from skills.sh is\n * registry-independent.\n */\n\nimport { z } from 'zod/v4';\n\n// =============================================================================\n// Registry list\n// =============================================================================\n\n/** Single entry in the registries list. */\nexport const builderRegistryEntrySchema = z.object({\n id: z.literal('skills-sh').describe('Stable registry identifier'),\n enabled: z.boolean().describe('Whether this registry is enabled in the running deployment'),\n label: z.string().describe('Human-readable registry name'),\n});\n\n/** Response for `GET /editor/builder/registries`. */\nexport const builderRegistriesResponseSchema = z.object({\n registries: z.array(builderRegistryEntrySchema),\n});\n\n// =============================================================================\n// Search / popular / preview\n// =============================================================================\n\n/** Path params used by every per-registry route. */\nexport const builderRegistryPathParams = z.object({\n registryId: z.string().describe('Registry identifier (e.g. \"skills-sh\")'),\n});\n\nexport const builderRegistrySearchQuerySchema = z.object({\n q: z.string().describe('Search query'),\n limit: z.coerce.number().int().min(1).max(100).optional().default(10).describe('Maximum number of results (1-100)'),\n});\n\nexport const builderRegistryPopularQuerySchema = z\n .object({\n limit: z.coerce.number().int().min(1).max(100).optional().default(10).describe('Maximum number of results (1-100)'),\n offset: z.coerce\n .number()\n .int()\n .min(0)\n .optional()\n .default(0)\n .describe('Offset for pagination (must be a multiple of `limit`)'),\n })\n .refine(args => args.offset % args.limit === 0, {\n message: 'offset must be a multiple of limit (the upstream registry pages by `limit`)',\n path: ['offset'],\n });\n\nexport const builderRegistryPreviewQuerySchema = z.object({\n owner: z.string().describe('GitHub repository owner'),\n repo: z.string().describe('GitHub repository name'),\n path: z.string().describe('Skill name within repo'),\n});\n\n// =============================================================================\n// Install\n// =============================================================================\n\n/**\n * Body for `POST /editor/builder/registries/:registryId/install`.\n *\n * Visibility behaves like the standard stored-skill create flow: optional,\n * defaults to private when the caller is authenticated.\n */\nexport const builderRegistryInstallBodySchema = z.object({\n owner: z.string().describe('GitHub repository owner'),\n repo: z.string().describe('GitHub repository name'),\n skillName: z.string().describe('Skill name from the registry'),\n visibility: z.enum(['private', 'public']).optional().describe('Visibility for the new stored skill'),\n});\n\n/** Response for the install route. Mirrors stored-skill identity fields. */\nexport const builderRegistryInstallResponseSchema = z.object({\n storedSkillId: z.string().describe('Id of the newly created stored skill'),\n name: z.string().describe('Resolved skill name'),\n filesWritten: z.number().describe('Number of files materialized into the skill version snapshot'),\n});\n\nexport type BuilderRegistryEntry = z.infer<typeof builderRegistryEntrySchema>;\nexport type BuilderRegistriesResponse = z.infer<typeof builderRegistriesResponseSchema>;\nexport type BuilderRegistryInstallBody = z.infer<typeof builderRegistryInstallBodySchema>;\nexport type BuilderRegistryInstallResponse = z.infer<typeof builderRegistryInstallResponseSchema>;\n","/**\n * Builder Registry Handlers\n *\n * Routes that let admins browse and install skills from configured external\n * registries (currently just skills.sh) directly into the Builder's stored\n * skills DB. Distinct from the workspace skills.sh routes, which write to a\n * workspace filesystem and never touch storage.\n *\n * Registry availability is driven by `AgentBuilderOptions.registries`. When\n * the requested registry is disabled (or the builder is missing entirely),\n * the routes 404 instead of leaking the surface.\n */\n\nimport type { Mastra } from '@mastra/core';\nimport type { StorageSkillFileNode } from '@mastra/core/storage';\n\nimport { HTTPException } from '../http-exception';\nimport {\n builderRegistriesResponseSchema,\n builderRegistryInstallBodySchema,\n builderRegistryInstallResponseSchema,\n builderRegistryPathParams,\n builderRegistryPopularQuerySchema,\n builderRegistryPreviewQuerySchema,\n builderRegistrySearchQuerySchema,\n} from '../schemas/builder-registry';\nimport {\n skillsShListResponseSchema,\n skillsShPreviewResponseSchema,\n skillsShSearchResponseSchema,\n} from '../schemas/workspace';\nimport { createRoute } from '../server-adapter/routes/route-builder';\nimport { toSlug } from '../utils';\nimport { getCallerAuthorId } from './authorship';\nimport { handleError } from './error';\nimport {\n assertSafeFilePath,\n assertSafeSkillName,\n fetchSkillFiles,\n getPopularSkillsSh,\n previewSkillsSh,\n searchSkillsSh,\n} from './skills-sh-shared';\n\n// =============================================================================\n// Registry resolution\n// =============================================================================\n\n/** Stable identifiers + display labels for every supported registry. */\nconst REGISTRY_LABELS: Record<string, string> = {\n 'skills-sh': 'skills.sh',\n};\n\ninterface RegistryStatus {\n id: 'skills-sh';\n enabled: boolean;\n label: string;\n}\n\n/**\n * Resolve which registries are enabled for the running deployment by reading\n * the builder's `registries` config. Returns a list with all known registries\n * (so the frontend can render an empty/disabled state) plus their enabled\n * flag.\n */\nasync function resolveRegistries(mastra: Mastra): Promise<RegistryStatus[]> {\n const editor = mastra.getEditor();\n if (!editor || typeof editor.resolveBuilder !== 'function') {\n return [{ id: 'skills-sh', enabled: false, label: REGISTRY_LABELS['skills-sh']! }];\n }\n const builder = await editor.resolveBuilder();\n const registries = builder?.getRegistries?.();\n return [\n {\n id: 'skills-sh',\n enabled: registries?.skillsSh?.enabled === true,\n label: REGISTRY_LABELS['skills-sh']!,\n },\n ];\n}\n\n/**\n * Hard-gate: throws 404 when the requested registry is unknown or disabled.\n * Mirrors `requireBuilderFeature` semantics — no surface leak for OFF registries.\n */\nasync function requireEnabledRegistry(mastra: Mastra, registryId: string): Promise<void> {\n const list = await resolveRegistries(mastra);\n const match = list.find(r => r.id === registryId);\n if (!match || !match.enabled) {\n throw new HTTPException(404, { message: 'Registry not found' });\n }\n}\n\n// =============================================================================\n// File-tree helpers\n// =============================================================================\n\n/**\n * Convert a flat list of `{ path, content, encoding }` entries into the\n * `StorageSkillFileNode` tree shape expected by the stored-skills create path.\n *\n * Each path is validated via `assertSafeFilePath` to prevent traversal from\n * upstream-controlled responses. Folder nodes are created on demand.\n */\nfunction buildFileTree(\n files: Array<{ path: string; content: string; encoding: 'utf-8' | 'base64' }>,\n): StorageSkillFileNode[] {\n const root: StorageSkillFileNode[] = [];\n\n for (const file of files) {\n const safePath = assertSafeFilePath(file.path);\n const segments = safePath.split('/').filter(Boolean);\n if (segments.length === 0) continue;\n\n let cursor = root;\n for (let i = 0; i < segments.length - 1; i++) {\n const segment = segments[i]!;\n let folder = cursor.find(node => node.type === 'folder' && node.name === segment);\n if (!folder) {\n folder = { name: segment, type: 'folder', children: [] };\n cursor.push(folder);\n }\n if (!folder.children) folder.children = [];\n cursor = folder.children;\n }\n\n const fileName = segments[segments.length - 1]!;\n const content = file.encoding === 'base64' ? Buffer.from(file.content, 'base64').toString('utf-8') : file.content;\n cursor.push({ name: fileName, type: 'file', content });\n }\n\n return root;\n}\n\n/**\n * Locally-bound SKILL.md frontmatter parser.\n *\n * Mirrors `parseSkillSnapshotFromFiles` from `@mastra/core/workspace`, but\n * inlined here because the server package's `@mastra/core` peer floor\n * (>=1.32.0) predates that helper. Once the floor is bumped to a release\n * containing the helper, this can be replaced by the shared core import.\n *\n * Only SKILL.md is consulted — frontmatter is split from the body using a\n * minimal YAML key:value reader sufficient for the fields registries\n * actually use (name, description). The body is everything after the\n * second `---` line, trimmed.\n */\ntype ParsedSkillSnapshot = {\n name?: string;\n description?: string;\n instructions: string;\n};\n\nfunction parseSkillSnapshot(\n files: Array<{ path: string; content: string; encoding: 'utf-8' | 'base64' }>,\n): ParsedSkillSnapshot | null {\n const skillMd = files.find(f => f.path === 'SKILL.md');\n if (!skillMd) return null;\n\n const raw =\n skillMd.encoding === 'base64' ? Buffer.from(skillMd.content, 'base64').toString('utf-8') : skillMd.content;\n\n const fmMatch = raw.match(/^---\\r?\\n([\\s\\S]*?)\\r?\\n---\\r?\\n?([\\s\\S]*)$/);\n if (!fmMatch) {\n return { instructions: raw.trim() };\n }\n\n const fmBlock = fmMatch[1] ?? '';\n const body = fmMatch[2] ?? '';\n const frontmatter: Record<string, string> = {};\n for (const line of fmBlock.split(/\\r?\\n/)) {\n const m = line.match(/^([A-Za-z0-9_-]+)\\s*:\\s*(.*)$/);\n if (!m) continue;\n const key = m[1];\n const value = m[2] ?? '';\n if (!key) continue;\n // Strip surrounding quotes, leave the rest as-is. Registry SKILL.md\n // frontmatter is consistently flat string fields in practice.\n frontmatter[key] = value.trim().replace(/^[\"'](.*)[\"']$/, '$1');\n }\n\n return {\n name: frontmatter.name,\n description: frontmatter.description,\n instructions: body.trim(),\n };\n}\n\n// =============================================================================\n// Routes\n// =============================================================================\n\n/**\n * GET /editor/builder/registries\n *\n * Lists every known registry and whether it's enabled in this deployment.\n * Used by the Builder UI to decide whether to show the \"Browse registry\"\n * entry point at all.\n */\nexport const LIST_BUILDER_REGISTRIES_ROUTE = createRoute({\n method: 'GET',\n path: '/editor/builder/registries',\n responseType: 'json',\n responseSchema: builderRegistriesResponseSchema,\n summary: 'List available skill registries',\n description: 'Returns the configured external skill registries and their enabled state.',\n tags: ['Editor'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:read',\n handler: async ({ mastra }) => {\n try {\n const registries = await resolveRegistries(mastra);\n return { registries };\n } catch (error) {\n return handleError(error, 'Error listing builder registries');\n }\n },\n});\n\n/**\n * GET /editor/builder/registries/:registryId/search\n *\n * Proxies a search query to the underlying registry. Currently only\n * registryId=\"skills-sh\" is supported.\n */\nexport const BUILDER_REGISTRY_SEARCH_ROUTE = createRoute({\n method: 'GET',\n path: '/editor/builder/registries/:registryId/search',\n responseType: 'json',\n pathParamSchema: builderRegistryPathParams,\n queryParamSchema: builderRegistrySearchQuerySchema,\n responseSchema: skillsShSearchResponseSchema,\n summary: 'Search skills in a registry',\n description: 'Proxies a search request to the configured registry to avoid CORS issues.',\n tags: ['Editor', 'Skills'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:read',\n handler: async ({ mastra, registryId, q, limit }) => {\n try {\n await requireEnabledRegistry(mastra, registryId);\n return await searchSkillsSh({ q, limit });\n } catch (error) {\n if (error instanceof HTTPException) throw error;\n return handleError(error, 'Error searching registry');\n }\n },\n});\n\n/**\n * GET /editor/builder/registries/:registryId/popular\n *\n * Returns the most popular skills in a registry.\n */\nexport const BUILDER_REGISTRY_POPULAR_ROUTE = createRoute({\n method: 'GET',\n path: '/editor/builder/registries/:registryId/popular',\n responseType: 'json',\n pathParamSchema: builderRegistryPathParams,\n queryParamSchema: builderRegistryPopularQuerySchema,\n responseSchema: skillsShListResponseSchema,\n summary: 'Get popular skills from a registry',\n description: 'Proxies a popular-skills request to the configured registry to avoid CORS issues.',\n tags: ['Editor', 'Skills'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:read',\n handler: async ({ mastra, registryId, limit, offset }) => {\n try {\n await requireEnabledRegistry(mastra, registryId);\n return await getPopularSkillsSh({ limit, offset });\n } catch (error) {\n if (error instanceof HTTPException) throw error;\n return handleError(error, 'Error fetching popular skills');\n }\n },\n});\n\n/**\n * GET /editor/builder/registries/:registryId/preview\n *\n * Returns the rendered SKILL.md content for a single skill in the registry.\n */\nexport const BUILDER_REGISTRY_PREVIEW_ROUTE = createRoute({\n method: 'GET',\n path: '/editor/builder/registries/:registryId/preview',\n responseType: 'json',\n pathParamSchema: builderRegistryPathParams,\n queryParamSchema: builderRegistryPreviewQuerySchema,\n responseSchema: skillsShPreviewResponseSchema,\n summary: 'Preview a skill from a registry',\n description: 'Fetches the SKILL.md content for a single skill in the configured registry.',\n tags: ['Editor', 'Skills'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:read',\n handler: async ({ mastra, registryId, owner, repo, path: skillName }) => {\n try {\n await requireEnabledRegistry(mastra, registryId);\n return await previewSkillsSh({ owner, repo, skillName });\n } catch (error) {\n if (error instanceof HTTPException) throw error;\n return handleError(error, 'Error fetching skill preview');\n }\n },\n});\n\n/**\n * POST /editor/builder/registries/:registryId/install\n *\n * Fetches the full file tree for a skill from the registry, parses the\n * SKILL.md frontmatter for name/description, and persists everything as a\n * new stored skill. The registry origin is recorded under `metadata.origin`\n * so the UI can surface \"imported from skills.sh\" badges and re-resolve the\n * source later.\n *\n * Collisions (a stored skill with the derived id already exists) return 409\n * so the UI can offer an \"Open existing\" link instead of silently\n * overwriting.\n */\nexport const BUILDER_REGISTRY_INSTALL_ROUTE = createRoute({\n method: 'POST',\n path: '/editor/builder/registries/:registryId/install',\n responseType: 'json',\n pathParamSchema: builderRegistryPathParams,\n bodySchema: builderRegistryInstallBodySchema,\n responseSchema: builderRegistryInstallResponseSchema,\n summary: 'Install a registry skill into stored skills',\n description: 'Fetches a skill from the configured registry and persists it as a new stored skill.',\n tags: ['Editor', 'Skills'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:write',\n handler: async ({ mastra, requestContext, registryId, owner, repo, skillName, visibility: bodyVisibility }) => {\n try {\n await requireEnabledRegistry(mastra, registryId);\n\n const storage = mastra.getStorage();\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not configured' });\n }\n const skillStore = await storage.getStore('skills');\n if (!skillStore) {\n throw new HTTPException(500, { message: 'Skills storage domain is not available' });\n }\n\n // Pull files from the registry\n const result = await fetchSkillFiles(owner, repo, skillName);\n if (!result || result.files.length === 0) {\n throw new HTTPException(404, {\n message: `Could not find skill \"${skillName}\" in ${owner}/${repo}.`,\n });\n }\n\n const safeSkillId = assertSafeSkillName(result.skillId);\n const files = buildFileTree(result.files);\n\n // Parse SKILL.md frontmatter into structured fields. Splitting\n // frontmatter (name/description) from the markdown body keeps the\n // body as the agent-facing `instructions` instead of polluting it\n // with raw YAML metadata. SKILL.md missing or unparseable simply\n // yields a null snapshot — registry-provided values then fill in.\n const snapshot = parseSkillSnapshot(result.files);\n\n const resolvedName = snapshot?.name ?? safeSkillId;\n const description = snapshot?.description ?? `Imported from ${owner}/${repo}`;\n const id = toSlug(resolvedName) || safeSkillId;\n\n if (!id) {\n throw new HTTPException(400, {\n message: 'Could not derive skill ID from registry skill metadata.',\n });\n }\n\n // Reject collisions instead of silently overwriting; UI offers \"Open existing\".\n const existing = await skillStore.getById(id);\n if (existing) {\n throw new HTTPException(409, {\n message: `Skill with id \"${id}\" already exists.`,\n // Surface the existing id so the client can deep-link.\n cause: { storedSkillId: id },\n });\n }\n\n // Match the standard create flow: no caller = always public, otherwise default private.\n const authorId = getCallerAuthorId(requestContext) ?? undefined;\n const visibility: 'private' | 'public' = authorId ? (bodyVisibility ?? 'private') : 'public';\n\n // Use the SKILL.md body (post-frontmatter) as instructions. Frontmatter\n // values are already lifted into structured columns above, so re-storing\n // them in `instructions` would both duplicate metadata and feed YAML\n // into the agent's prompt. Fall back to description when no usable body\n // exists so `resolved.snapshot.instructions` stays non-empty.\n const instructions = snapshot?.instructions?.trim() ? snapshot.instructions : description;\n\n await skillStore.create({\n skill: {\n id,\n authorId,\n visibility,\n name: resolvedName,\n description,\n instructions,\n files,\n metadata: {\n origin: {\n type: 'skills-sh',\n owner,\n repo,\n skillName,\n },\n },\n },\n });\n\n return {\n storedSkillId: id,\n name: resolvedName,\n filesWritten: result.files.length,\n };\n } catch (error) {\n if (error instanceof HTTPException) throw error;\n return handleError(error, 'Error installing registry skill');\n }\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,6BAA6B,EAAE,OAAO;CACjD,IAAI,EAAE,QAAQ,WAAW,CAAC,CAAC,SAAS,4BAA4B;CAChE,SAAS,EAAE,QAAQ,CAAC,CAAC,SAAS,4DAA4D;CAC1F,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS,8BAA8B;AAC3D,CAAC;;AAGD,MAAa,kCAAkC,EAAE,OAAO,EACtD,YAAY,EAAE,MAAM,0BAA0B,EAChD,CAAC;;AAOD,MAAa,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C,MAAM,cAAc,UAAU,eAAe,iBAAiB,MAAM,GAAG;GACvE,MAAM,KAAK,OAAO,YAAY,KAAK;GAEnC,IAAI,CAAC,IACH,MAAM,IAAI,cAAc,KAAK,EAC3B,SAAS,0DACX,CAAC;GAKH,IAAI,MADmB,WAAW,QAAQ,EAAE,GAE1C,MAAM,IAAI,cAAc,KAAK;IAC3B,SAAS,kBAAkB,GAAG;IAE9B,OAAO,EAAE,eAAe,GAAG;GAC7B,CAAC;GAIH,MAAM,WAAW,kBAAkB,cAAc,KAAK,KAAA;GACtD,MAAM,aAAmC,WAAY,kBAAkB,YAAa;GAOpF,MAAM,eAAe,UAAU,cAAc,KAAK,IAAI,SAAS,eAAe;GAE9E,MAAM,WAAW,OAAO,EACtB,OAAO;IACL;IACA;IACA;IACA,MAAM;IACN;IACA;IACA;IACA,UAAU,EACR,QAAQ;KACN,MAAM;KACN;KACA;KACA;IACF,EACF;GACF,EACF,CAAC;GAED,OAAO;IACL,eAAe;IACf,MAAM;IACN,cAAc,OAAO,MAAM;GAC7B;EACF,SAAS,OAAO;GACd,IAAI,iBAAiB,eAAe,MAAM;GAC1C,OAAO,YAAY,OAAO,iCAAiC;EAC7D;CACF;AACF,CAAC"}
1
+ {"version":3,"file":"builder-registry-B8KyPAOP.js","names":[],"sources":["../src/server/schemas/builder-registry.ts","../src/server/handlers/builder-registry.ts"],"sourcesContent":["/**\n * Builder Registry Schemas\n *\n * Schemas for the Agent Builder skill registry routes. These are distinct from\n * the workspace skills.sh proxy schemas because:\n * - Builder routes are not scoped to a workspace.\n * - Builder install does not accept a `mount` field.\n * - Builder install body carries visibility + the resolved registry id.\n * - Builder install response returns the created stored skill id.\n *\n * The upstream skills.sh proxy response shapes are reused via the shared\n * `skillsShSearchResponseSchema`, `skillsShListResponseSchema`, and\n * `skillsShPreviewResponseSchema` since the wire shape from skills.sh is\n * registry-independent.\n */\n\nimport { z } from 'zod/v4';\n\n// =============================================================================\n// Registry list\n// =============================================================================\n\n/** Single entry in the registries list. */\nexport const builderRegistryEntrySchema = z.object({\n id: z.literal('skills-sh').describe('Stable registry identifier'),\n enabled: z.boolean().describe('Whether this registry is enabled in the running deployment'),\n label: z.string().describe('Human-readable registry name'),\n});\n\n/** Response for `GET /editor/builder/registries`. */\nexport const builderRegistriesResponseSchema = z.object({\n registries: z.array(builderRegistryEntrySchema),\n});\n\n// =============================================================================\n// Search / popular / preview\n// =============================================================================\n\n/** Path params used by every per-registry route. */\nexport const builderRegistryPathParams = z.object({\n registryId: z.string().describe('Registry identifier (e.g. \"skills-sh\")'),\n});\n\nexport const builderRegistrySearchQuerySchema = z.object({\n q: z.string().describe('Search query'),\n limit: z.coerce.number().int().min(1).max(100).optional().default(10).describe('Maximum number of results (1-100)'),\n});\n\nexport const builderRegistryPopularQuerySchema = z\n .object({\n limit: z.coerce.number().int().min(1).max(100).optional().default(10).describe('Maximum number of results (1-100)'),\n offset: z.coerce\n .number()\n .int()\n .min(0)\n .optional()\n .default(0)\n .describe('Offset for pagination (must be a multiple of `limit`)'),\n })\n .refine(args => args.offset % args.limit === 0, {\n message: 'offset must be a multiple of limit (the upstream registry pages by `limit`)',\n path: ['offset'],\n });\n\nexport const builderRegistryPreviewQuerySchema = z.object({\n owner: z.string().describe('GitHub repository owner'),\n repo: z.string().describe('GitHub repository name'),\n path: z.string().describe('Skill name within repo'),\n});\n\n// =============================================================================\n// Install\n// =============================================================================\n\n/**\n * Body for `POST /editor/builder/registries/:registryId/install`.\n *\n * Visibility behaves like the standard stored-skill create flow: optional,\n * defaults to private when the caller is authenticated.\n */\nexport const builderRegistryInstallBodySchema = z.object({\n owner: z.string().describe('GitHub repository owner'),\n repo: z.string().describe('GitHub repository name'),\n skillName: z.string().describe('Skill name from the registry'),\n visibility: z.enum(['private', 'public']).optional().describe('Visibility for the new stored skill'),\n});\n\n/** Response for the install route. Mirrors stored-skill identity fields. */\nexport const builderRegistryInstallResponseSchema = z.object({\n storedSkillId: z.string().describe('Id of the newly created stored skill'),\n name: z.string().describe('Resolved skill name'),\n filesWritten: z.number().describe('Number of files materialized into the skill version snapshot'),\n});\n\nexport type BuilderRegistryEntry = z.infer<typeof builderRegistryEntrySchema>;\nexport type BuilderRegistriesResponse = z.infer<typeof builderRegistriesResponseSchema>;\nexport type BuilderRegistryInstallBody = z.infer<typeof builderRegistryInstallBodySchema>;\nexport type BuilderRegistryInstallResponse = z.infer<typeof builderRegistryInstallResponseSchema>;\n","/**\n * Builder Registry Handlers\n *\n * Routes that let admins browse and install skills from configured external\n * registries (currently just skills.sh) directly into the Builder's stored\n * skills DB. Distinct from the workspace skills.sh routes, which write to a\n * workspace filesystem and never touch storage.\n *\n * Registry availability is driven by `AgentBuilderOptions.registries`. When\n * the requested registry is disabled (or the builder is missing entirely),\n * the routes 404 instead of leaking the surface.\n */\n\nimport type { Mastra } from '@mastra/core';\nimport type { StorageSkillFileNode } from '@mastra/core/storage';\n\nimport { HTTPException } from '../http-exception';\nimport {\n builderRegistriesResponseSchema,\n builderRegistryInstallBodySchema,\n builderRegistryInstallResponseSchema,\n builderRegistryPathParams,\n builderRegistryPopularQuerySchema,\n builderRegistryPreviewQuerySchema,\n builderRegistrySearchQuerySchema,\n} from '../schemas/builder-registry';\nimport {\n skillsShListResponseSchema,\n skillsShPreviewResponseSchema,\n skillsShSearchResponseSchema,\n} from '../schemas/workspace';\nimport { createRoute } from '../server-adapter/routes/route-builder';\nimport { toSlug } from '../utils';\nimport { getCallerAuthorId } from './authorship';\nimport { handleError } from './error';\nimport {\n assertSafeFilePath,\n assertSafeSkillName,\n fetchSkillFiles,\n getPopularSkillsSh,\n previewSkillsSh,\n searchSkillsSh,\n} from './skills-sh-shared';\n\n// =============================================================================\n// Registry resolution\n// =============================================================================\n\n/** Stable identifiers + display labels for every supported registry. */\nconst REGISTRY_LABELS: Record<string, string> = {\n 'skills-sh': 'skills.sh',\n};\n\ninterface RegistryStatus {\n id: 'skills-sh';\n enabled: boolean;\n label: string;\n}\n\n/**\n * Resolve which registries are enabled for the running deployment by reading\n * the builder's `registries` config. Returns a list with all known registries\n * (so the frontend can render an empty/disabled state) plus their enabled\n * flag.\n */\nasync function resolveRegistries(mastra: Mastra): Promise<RegistryStatus[]> {\n const editor = mastra.getEditor();\n if (!editor || typeof editor.resolveBuilder !== 'function') {\n return [{ id: 'skills-sh', enabled: false, label: REGISTRY_LABELS['skills-sh']! }];\n }\n const builder = await editor.resolveBuilder();\n const registries = builder?.getRegistries?.();\n return [\n {\n id: 'skills-sh',\n enabled: registries?.skillsSh?.enabled === true,\n label: REGISTRY_LABELS['skills-sh']!,\n },\n ];\n}\n\n/**\n * Hard-gate: throws 404 when the requested registry is unknown or disabled.\n * Mirrors `requireBuilderFeature` semantics — no surface leak for OFF registries.\n */\nasync function requireEnabledRegistry(mastra: Mastra, registryId: string): Promise<void> {\n const list = await resolveRegistries(mastra);\n const match = list.find(r => r.id === registryId);\n if (!match || !match.enabled) {\n throw new HTTPException(404, { message: 'Registry not found' });\n }\n}\n\n// =============================================================================\n// File-tree helpers\n// =============================================================================\n\n/**\n * Convert a flat list of `{ path, content, encoding }` entries into the\n * `StorageSkillFileNode` tree shape expected by the stored-skills create path.\n *\n * Each path is validated via `assertSafeFilePath` to prevent traversal from\n * upstream-controlled responses. Folder nodes are created on demand.\n */\nfunction buildFileTree(\n files: Array<{ path: string; content: string; encoding: 'utf-8' | 'base64' }>,\n): StorageSkillFileNode[] {\n const root: StorageSkillFileNode[] = [];\n\n for (const file of files) {\n const safePath = assertSafeFilePath(file.path);\n const segments = safePath.split('/').filter(Boolean);\n if (segments.length === 0) continue;\n\n let cursor = root;\n for (let i = 0; i < segments.length - 1; i++) {\n const segment = segments[i]!;\n let folder = cursor.find(node => node.type === 'folder' && node.name === segment);\n if (!folder) {\n folder = { name: segment, type: 'folder', children: [] };\n cursor.push(folder);\n }\n if (!folder.children) folder.children = [];\n cursor = folder.children;\n }\n\n const fileName = segments[segments.length - 1]!;\n const content = file.encoding === 'base64' ? Buffer.from(file.content, 'base64').toString('utf-8') : file.content;\n cursor.push({ name: fileName, type: 'file', content });\n }\n\n return root;\n}\n\n/**\n * Locally-bound SKILL.md frontmatter parser.\n *\n * Mirrors `parseSkillSnapshotFromFiles` from `@mastra/core/workspace`, but\n * inlined here because the server package's `@mastra/core` peer floor\n * (>=1.32.0) predates that helper. Once the floor is bumped to a release\n * containing the helper, this can be replaced by the shared core import.\n *\n * Only SKILL.md is consulted — frontmatter is split from the body using a\n * minimal YAML key:value reader sufficient for the fields registries\n * actually use (name, description). The body is everything after the\n * second `---` line, trimmed.\n */\ntype ParsedSkillSnapshot = {\n name?: string;\n description?: string;\n instructions: string;\n};\n\nfunction parseSkillSnapshot(\n files: Array<{ path: string; content: string; encoding: 'utf-8' | 'base64' }>,\n): ParsedSkillSnapshot | null {\n const skillMd = files.find(f => f.path === 'SKILL.md');\n if (!skillMd) return null;\n\n const raw =\n skillMd.encoding === 'base64' ? Buffer.from(skillMd.content, 'base64').toString('utf-8') : skillMd.content;\n\n const fmMatch = raw.match(/^---\\r?\\n([\\s\\S]*?)\\r?\\n---\\r?\\n?([\\s\\S]*)$/);\n if (!fmMatch) {\n return { instructions: raw.trim() };\n }\n\n const fmBlock = fmMatch[1] ?? '';\n const body = fmMatch[2] ?? '';\n const frontmatter: Record<string, string> = {};\n for (const line of fmBlock.split(/\\r?\\n/)) {\n const m = line.match(/^([A-Za-z0-9_-]+)\\s*:\\s*(.*)$/);\n if (!m) continue;\n const key = m[1];\n const value = m[2] ?? '';\n if (!key) continue;\n // Strip surrounding quotes, leave the rest as-is. Registry SKILL.md\n // frontmatter is consistently flat string fields in practice.\n frontmatter[key] = value.trim().replace(/^[\"'](.*)[\"']$/, '$1');\n }\n\n return {\n name: frontmatter.name,\n description: frontmatter.description,\n instructions: body.trim(),\n };\n}\n\n// =============================================================================\n// Routes\n// =============================================================================\n\n/**\n * GET /editor/builder/registries\n *\n * Lists every known registry and whether it's enabled in this deployment.\n * Used by the Builder UI to decide whether to show the \"Browse registry\"\n * entry point at all.\n */\nexport const LIST_BUILDER_REGISTRIES_ROUTE = createRoute({\n method: 'GET',\n path: '/editor/builder/registries',\n responseType: 'json',\n responseSchema: builderRegistriesResponseSchema,\n summary: 'List available skill registries',\n description: 'Returns the configured external skill registries and their enabled state.',\n tags: ['Editor'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:read',\n handler: async ({ mastra }) => {\n try {\n const registries = await resolveRegistries(mastra);\n return { registries };\n } catch (error) {\n return handleError(error, 'Error listing builder registries');\n }\n },\n});\n\n/**\n * GET /editor/builder/registries/:registryId/search\n *\n * Proxies a search query to the underlying registry. Currently only\n * registryId=\"skills-sh\" is supported.\n */\nexport const BUILDER_REGISTRY_SEARCH_ROUTE = createRoute({\n method: 'GET',\n path: '/editor/builder/registries/:registryId/search',\n responseType: 'json',\n pathParamSchema: builderRegistryPathParams,\n queryParamSchema: builderRegistrySearchQuerySchema,\n responseSchema: skillsShSearchResponseSchema,\n summary: 'Search skills in a registry',\n description: 'Proxies a search request to the configured registry to avoid CORS issues.',\n tags: ['Editor', 'Skills'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:read',\n handler: async ({ mastra, registryId, q, limit }) => {\n try {\n await requireEnabledRegistry(mastra, registryId);\n return await searchSkillsSh({ q, limit });\n } catch (error) {\n if (error instanceof HTTPException) throw error;\n return handleError(error, 'Error searching registry');\n }\n },\n});\n\n/**\n * GET /editor/builder/registries/:registryId/popular\n *\n * Returns the most popular skills in a registry.\n */\nexport const BUILDER_REGISTRY_POPULAR_ROUTE = createRoute({\n method: 'GET',\n path: '/editor/builder/registries/:registryId/popular',\n responseType: 'json',\n pathParamSchema: builderRegistryPathParams,\n queryParamSchema: builderRegistryPopularQuerySchema,\n responseSchema: skillsShListResponseSchema,\n summary: 'Get popular skills from a registry',\n description: 'Proxies a popular-skills request to the configured registry to avoid CORS issues.',\n tags: ['Editor', 'Skills'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:read',\n handler: async ({ mastra, registryId, limit, offset }) => {\n try {\n await requireEnabledRegistry(mastra, registryId);\n return await getPopularSkillsSh({ limit, offset });\n } catch (error) {\n if (error instanceof HTTPException) throw error;\n return handleError(error, 'Error fetching popular skills');\n }\n },\n});\n\n/**\n * GET /editor/builder/registries/:registryId/preview\n *\n * Returns the rendered SKILL.md content for a single skill in the registry.\n */\nexport const BUILDER_REGISTRY_PREVIEW_ROUTE = createRoute({\n method: 'GET',\n path: '/editor/builder/registries/:registryId/preview',\n responseType: 'json',\n pathParamSchema: builderRegistryPathParams,\n queryParamSchema: builderRegistryPreviewQuerySchema,\n responseSchema: skillsShPreviewResponseSchema,\n summary: 'Preview a skill from a registry',\n description: 'Fetches the SKILL.md content for a single skill in the configured registry.',\n tags: ['Editor', 'Skills'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:read',\n handler: async ({ mastra, registryId, owner, repo, path: skillName }) => {\n try {\n await requireEnabledRegistry(mastra, registryId);\n return await previewSkillsSh({ owner, repo, skillName });\n } catch (error) {\n if (error instanceof HTTPException) throw error;\n return handleError(error, 'Error fetching skill preview');\n }\n },\n});\n\n/**\n * POST /editor/builder/registries/:registryId/install\n *\n * Fetches the full file tree for a skill from the registry, parses the\n * SKILL.md frontmatter for name/description, and persists everything as a\n * new stored skill. The registry origin is recorded under `metadata.origin`\n * so the UI can surface \"imported from skills.sh\" badges and re-resolve the\n * source later.\n *\n * Collisions (a stored skill with the derived id already exists) return 409\n * so the UI can offer an \"Open existing\" link instead of silently\n * overwriting.\n */\nexport const BUILDER_REGISTRY_INSTALL_ROUTE = createRoute({\n method: 'POST',\n path: '/editor/builder/registries/:registryId/install',\n responseType: 'json',\n pathParamSchema: builderRegistryPathParams,\n bodySchema: builderRegistryInstallBodySchema,\n responseSchema: builderRegistryInstallResponseSchema,\n summary: 'Install a registry skill into stored skills',\n description: 'Fetches a skill from the configured registry and persists it as a new stored skill.',\n tags: ['Editor', 'Skills'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:write',\n handler: async ({ mastra, requestContext, registryId, owner, repo, skillName, visibility: bodyVisibility }) => {\n try {\n await requireEnabledRegistry(mastra, registryId);\n\n const storage = mastra.getStorage();\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not configured' });\n }\n const skillStore = await storage.getStore('skills');\n if (!skillStore) {\n throw new HTTPException(500, { message: 'Skills storage domain is not available' });\n }\n\n // Pull files from the registry\n const result = await fetchSkillFiles(owner, repo, skillName);\n if (!result || result.files.length === 0) {\n throw new HTTPException(404, {\n message: `Could not find skill \"${skillName}\" in ${owner}/${repo}.`,\n });\n }\n\n const safeSkillId = assertSafeSkillName(result.skillId);\n const files = buildFileTree(result.files);\n\n // Parse SKILL.md frontmatter into structured fields. Splitting\n // frontmatter (name/description) from the markdown body keeps the\n // body as the agent-facing `instructions` instead of polluting it\n // with raw YAML metadata. SKILL.md missing or unparseable simply\n // yields a null snapshot — registry-provided values then fill in.\n const snapshot = parseSkillSnapshot(result.files);\n\n const resolvedName = snapshot?.name ?? safeSkillId;\n const description = snapshot?.description ?? `Imported from ${owner}/${repo}`;\n const id = toSlug(resolvedName) || safeSkillId;\n\n if (!id) {\n throw new HTTPException(400, {\n message: 'Could not derive skill ID from registry skill metadata.',\n });\n }\n\n // Reject collisions instead of silently overwriting; UI offers \"Open existing\".\n const existing = await skillStore.getById(id);\n if (existing) {\n throw new HTTPException(409, {\n message: `Skill with id \"${id}\" already exists.`,\n // Surface the existing id so the client can deep-link.\n cause: { storedSkillId: id },\n });\n }\n\n // Match the standard create flow: no caller = always public, otherwise default private.\n const authorId = getCallerAuthorId(requestContext) ?? undefined;\n const visibility: 'private' | 'public' = authorId ? (bodyVisibility ?? 'private') : 'public';\n\n // Use the SKILL.md body (post-frontmatter) as instructions. Frontmatter\n // values are already lifted into structured columns above, so re-storing\n // them in `instructions` would both duplicate metadata and feed YAML\n // into the agent's prompt. Fall back to description when no usable body\n // exists so `resolved.snapshot.instructions` stays non-empty.\n const instructions = snapshot?.instructions?.trim() ? snapshot.instructions : description;\n\n await skillStore.create({\n skill: {\n id,\n authorId,\n visibility,\n name: resolvedName,\n description,\n instructions,\n files,\n metadata: {\n origin: {\n type: 'skills-sh',\n owner,\n repo,\n skillName,\n },\n },\n },\n });\n\n return {\n storedSkillId: id,\n name: resolvedName,\n filesWritten: result.files.length,\n };\n } catch (error) {\n if (error instanceof HTTPException) throw error;\n return handleError(error, 'Error installing registry skill');\n }\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,6BAA6B,EAAE,OAAO;CACjD,IAAI,EAAE,QAAQ,WAAW,CAAC,CAAC,SAAS,4BAA4B;CAChE,SAAS,EAAE,QAAQ,CAAC,CAAC,SAAS,4DAA4D;CAC1F,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS,8BAA8B;AAC3D,CAAC;;AAGD,MAAa,kCAAkC,EAAE,OAAO,EACtD,YAAY,EAAE,MAAM,0BAA0B,EAChD,CAAC;;AAOD,MAAa,4BAA4B,EAAE,OAAO,EAChD,YAAY,EAAE,OAAO,CAAC,CAAC,SAAS,0CAAwC,EAC1E,CAAC;AAED,MAAa,mCAAmC,EAAE,OAAO;CACvD,GAAG,EAAE,OAAO,CAAC,CAAC,SAAS,cAAc;CACrC,OAAO,EAAE,OAAO,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,SAAS,mCAAmC;AACpH,CAAC;AAED,MAAa,oCAAoC,EAC9C,OAAO;CACN,OAAO,EAAE,OAAO,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,SAAS,mCAAmC;CAClH,QAAQ,EAAE,OACP,OAAO,CAAC,CACR,IAAI,CAAC,CACL,IAAI,CAAC,CAAC,CACN,SAAS,CAAC,CACV,QAAQ,CAAC,CAAC,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AAS,OAAO;GACd,IAAI,iBAAiB,eAAe,MAAM;GAC1C,OAAO,YAAY,OAAO,iCAAiC;EAC7D;CACF;AACF,CAAC"}
@@ -1,6 +1,6 @@
1
1
  const require_http_exception = require("./http-exception-CKDHupKw.cjs");
2
- const require_route_builder = require("./route-builder-CgLVYL1c.cjs");
3
- const require_utils = require("./utils-wESuBh27.cjs");
2
+ const require_route_builder = require("./route-builder-BAAedfru.cjs");
3
+ const require_utils = require("./utils-Bna_JCkb.cjs");
4
4
  const require_server_handlers_error = require("./server/handlers/error.cjs");
5
5
  const require_workspace = require("./workspace-Cz9hE2ei.cjs");
6
6
  const require_server_handlers_authorship = require("./server/handlers/authorship.cjs");
@@ -380,4 +380,4 @@ Object.defineProperty(exports, "LIST_BUILDER_REGISTRIES_ROUTE", {
380
380
  }
381
381
  });
382
382
 
383
- //# sourceMappingURL=builder-registry-BoaXBdm_.cjs.map
383
+ //# sourceMappingURL=builder-registry-Dcou-kzd.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"builder-registry-BoaXBdm_.cjs","names":["z","HTTPException","assertSafeFilePath","createRoute","handleError","skillsShSearchResponseSchema","searchSkillsSh","skillsShListResponseSchema","getPopularSkillsSh","skillsShPreviewResponseSchema","previewSkillsSh","fetchSkillFiles","assertSafeSkillName","toSlug","getCallerAuthorId"],"sources":["../src/server/schemas/builder-registry.ts","../src/server/handlers/builder-registry.ts"],"sourcesContent":["/**\n * Builder Registry Schemas\n *\n * Schemas for the Agent Builder skill registry routes. These are distinct from\n * the workspace skills.sh proxy schemas because:\n * - Builder routes are not scoped to a workspace.\n * - Builder install does not accept a `mount` field.\n * - Builder install body carries visibility + the resolved registry id.\n * - Builder install response returns the created stored skill id.\n *\n * The upstream skills.sh proxy response shapes are reused via the shared\n * `skillsShSearchResponseSchema`, `skillsShListResponseSchema`, and\n * `skillsShPreviewResponseSchema` since the wire shape from skills.sh is\n * registry-independent.\n */\n\nimport { z } from 'zod/v4';\n\n// =============================================================================\n// Registry list\n// =============================================================================\n\n/** Single entry in the registries list. */\nexport const builderRegistryEntrySchema = z.object({\n id: z.literal('skills-sh').describe('Stable registry identifier'),\n enabled: z.boolean().describe('Whether this registry is enabled in the running deployment'),\n label: z.string().describe('Human-readable registry name'),\n});\n\n/** Response for `GET /editor/builder/registries`. */\nexport const builderRegistriesResponseSchema = z.object({\n registries: z.array(builderRegistryEntrySchema),\n});\n\n// =============================================================================\n// Search / popular / preview\n// =============================================================================\n\n/** Path params used by every per-registry route. */\nexport const builderRegistryPathParams = z.object({\n registryId: z.string().describe('Registry identifier (e.g. \"skills-sh\")'),\n});\n\nexport const builderRegistrySearchQuerySchema = z.object({\n q: z.string().describe('Search query'),\n limit: z.coerce.number().int().min(1).max(100).optional().default(10).describe('Maximum number of results (1-100)'),\n});\n\nexport const builderRegistryPopularQuerySchema = z\n .object({\n limit: z.coerce.number().int().min(1).max(100).optional().default(10).describe('Maximum number of results (1-100)'),\n offset: z.coerce\n .number()\n .int()\n .min(0)\n .optional()\n .default(0)\n .describe('Offset for pagination (must be a multiple of `limit`)'),\n })\n .refine(args => args.offset % args.limit === 0, {\n message: 'offset must be a multiple of limit (the upstream registry pages by `limit`)',\n path: ['offset'],\n });\n\nexport const builderRegistryPreviewQuerySchema = z.object({\n owner: z.string().describe('GitHub repository owner'),\n repo: z.string().describe('GitHub repository name'),\n path: z.string().describe('Skill name within repo'),\n});\n\n// =============================================================================\n// Install\n// =============================================================================\n\n/**\n * Body for `POST /editor/builder/registries/:registryId/install`.\n *\n * Visibility behaves like the standard stored-skill create flow: optional,\n * defaults to private when the caller is authenticated.\n */\nexport const builderRegistryInstallBodySchema = z.object({\n owner: z.string().describe('GitHub repository owner'),\n repo: z.string().describe('GitHub repository name'),\n skillName: z.string().describe('Skill name from the registry'),\n visibility: z.enum(['private', 'public']).optional().describe('Visibility for the new stored skill'),\n});\n\n/** Response for the install route. Mirrors stored-skill identity fields. */\nexport const builderRegistryInstallResponseSchema = z.object({\n storedSkillId: z.string().describe('Id of the newly created stored skill'),\n name: z.string().describe('Resolved skill name'),\n filesWritten: z.number().describe('Number of files materialized into the skill version snapshot'),\n});\n\nexport type BuilderRegistryEntry = z.infer<typeof builderRegistryEntrySchema>;\nexport type BuilderRegistriesResponse = z.infer<typeof builderRegistriesResponseSchema>;\nexport type BuilderRegistryInstallBody = z.infer<typeof builderRegistryInstallBodySchema>;\nexport type BuilderRegistryInstallResponse = z.infer<typeof builderRegistryInstallResponseSchema>;\n","/**\n * Builder Registry Handlers\n *\n * Routes that let admins browse and install skills from configured external\n * registries (currently just skills.sh) directly into the Builder's stored\n * skills DB. Distinct from the workspace skills.sh routes, which write to a\n * workspace filesystem and never touch storage.\n *\n * Registry availability is driven by `AgentBuilderOptions.registries`. When\n * the requested registry is disabled (or the builder is missing entirely),\n * the routes 404 instead of leaking the surface.\n */\n\nimport type { Mastra } from '@mastra/core';\nimport type { StorageSkillFileNode } from '@mastra/core/storage';\n\nimport { HTTPException } from '../http-exception';\nimport {\n builderRegistriesResponseSchema,\n builderRegistryInstallBodySchema,\n builderRegistryInstallResponseSchema,\n builderRegistryPathParams,\n builderRegistryPopularQuerySchema,\n builderRegistryPreviewQuerySchema,\n builderRegistrySearchQuerySchema,\n} from '../schemas/builder-registry';\nimport {\n skillsShListResponseSchema,\n skillsShPreviewResponseSchema,\n skillsShSearchResponseSchema,\n} from '../schemas/workspace';\nimport { createRoute } from '../server-adapter/routes/route-builder';\nimport { toSlug } from '../utils';\nimport { getCallerAuthorId } from './authorship';\nimport { handleError } from './error';\nimport {\n assertSafeFilePath,\n assertSafeSkillName,\n fetchSkillFiles,\n getPopularSkillsSh,\n previewSkillsSh,\n searchSkillsSh,\n} from './skills-sh-shared';\n\n// =============================================================================\n// Registry resolution\n// =============================================================================\n\n/** Stable identifiers + display labels for every supported registry. */\nconst REGISTRY_LABELS: Record<string, string> = {\n 'skills-sh': 'skills.sh',\n};\n\ninterface RegistryStatus {\n id: 'skills-sh';\n enabled: boolean;\n label: string;\n}\n\n/**\n * Resolve which registries are enabled for the running deployment by reading\n * the builder's `registries` config. Returns a list with all known registries\n * (so the frontend can render an empty/disabled state) plus their enabled\n * flag.\n */\nasync function resolveRegistries(mastra: Mastra): Promise<RegistryStatus[]> {\n const editor = mastra.getEditor();\n if (!editor || typeof editor.resolveBuilder !== 'function') {\n return [{ id: 'skills-sh', enabled: false, label: REGISTRY_LABELS['skills-sh']! }];\n }\n const builder = await editor.resolveBuilder();\n const registries = builder?.getRegistries?.();\n return [\n {\n id: 'skills-sh',\n enabled: registries?.skillsSh?.enabled === true,\n label: REGISTRY_LABELS['skills-sh']!,\n },\n ];\n}\n\n/**\n * Hard-gate: throws 404 when the requested registry is unknown or disabled.\n * Mirrors `requireBuilderFeature` semantics — no surface leak for OFF registries.\n */\nasync function requireEnabledRegistry(mastra: Mastra, registryId: string): Promise<void> {\n const list = await resolveRegistries(mastra);\n const match = list.find(r => r.id === registryId);\n if (!match || !match.enabled) {\n throw new HTTPException(404, { message: 'Registry not found' });\n }\n}\n\n// =============================================================================\n// File-tree helpers\n// =============================================================================\n\n/**\n * Convert a flat list of `{ path, content, encoding }` entries into the\n * `StorageSkillFileNode` tree shape expected by the stored-skills create path.\n *\n * Each path is validated via `assertSafeFilePath` to prevent traversal from\n * upstream-controlled responses. Folder nodes are created on demand.\n */\nfunction buildFileTree(\n files: Array<{ path: string; content: string; encoding: 'utf-8' | 'base64' }>,\n): StorageSkillFileNode[] {\n const root: StorageSkillFileNode[] = [];\n\n for (const file of files) {\n const safePath = assertSafeFilePath(file.path);\n const segments = safePath.split('/').filter(Boolean);\n if (segments.length === 0) continue;\n\n let cursor = root;\n for (let i = 0; i < segments.length - 1; i++) {\n const segment = segments[i]!;\n let folder = cursor.find(node => node.type === 'folder' && node.name === segment);\n if (!folder) {\n folder = { name: segment, type: 'folder', children: [] };\n cursor.push(folder);\n }\n if (!folder.children) folder.children = [];\n cursor = folder.children;\n }\n\n const fileName = segments[segments.length - 1]!;\n const content = file.encoding === 'base64' ? Buffer.from(file.content, 'base64').toString('utf-8') : file.content;\n cursor.push({ name: fileName, type: 'file', content });\n }\n\n return root;\n}\n\n/**\n * Locally-bound SKILL.md frontmatter parser.\n *\n * Mirrors `parseSkillSnapshotFromFiles` from `@mastra/core/workspace`, but\n * inlined here because the server package's `@mastra/core` peer floor\n * (>=1.32.0) predates that helper. Once the floor is bumped to a release\n * containing the helper, this can be replaced by the shared core import.\n *\n * Only SKILL.md is consulted — frontmatter is split from the body using a\n * minimal YAML key:value reader sufficient for the fields registries\n * actually use (name, description). The body is everything after the\n * second `---` line, trimmed.\n */\ntype ParsedSkillSnapshot = {\n name?: string;\n description?: string;\n instructions: string;\n};\n\nfunction parseSkillSnapshot(\n files: Array<{ path: string; content: string; encoding: 'utf-8' | 'base64' }>,\n): ParsedSkillSnapshot | null {\n const skillMd = files.find(f => f.path === 'SKILL.md');\n if (!skillMd) return null;\n\n const raw =\n skillMd.encoding === 'base64' ? Buffer.from(skillMd.content, 'base64').toString('utf-8') : skillMd.content;\n\n const fmMatch = raw.match(/^---\\r?\\n([\\s\\S]*?)\\r?\\n---\\r?\\n?([\\s\\S]*)$/);\n if (!fmMatch) {\n return { instructions: raw.trim() };\n }\n\n const fmBlock = fmMatch[1] ?? '';\n const body = fmMatch[2] ?? '';\n const frontmatter: Record<string, string> = {};\n for (const line of fmBlock.split(/\\r?\\n/)) {\n const m = line.match(/^([A-Za-z0-9_-]+)\\s*:\\s*(.*)$/);\n if (!m) continue;\n const key = m[1];\n const value = m[2] ?? '';\n if (!key) continue;\n // Strip surrounding quotes, leave the rest as-is. Registry SKILL.md\n // frontmatter is consistently flat string fields in practice.\n frontmatter[key] = value.trim().replace(/^[\"'](.*)[\"']$/, '$1');\n }\n\n return {\n name: frontmatter.name,\n description: frontmatter.description,\n instructions: body.trim(),\n };\n}\n\n// =============================================================================\n// Routes\n// =============================================================================\n\n/**\n * GET /editor/builder/registries\n *\n * Lists every known registry and whether it's enabled in this deployment.\n * Used by the Builder UI to decide whether to show the \"Browse registry\"\n * entry point at all.\n */\nexport const LIST_BUILDER_REGISTRIES_ROUTE = createRoute({\n method: 'GET',\n path: '/editor/builder/registries',\n responseType: 'json',\n responseSchema: builderRegistriesResponseSchema,\n summary: 'List available skill registries',\n description: 'Returns the configured external skill registries and their enabled state.',\n tags: ['Editor'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:read',\n handler: async ({ mastra }) => {\n try {\n const registries = await resolveRegistries(mastra);\n return { registries };\n } catch (error) {\n return handleError(error, 'Error listing builder registries');\n }\n },\n});\n\n/**\n * GET /editor/builder/registries/:registryId/search\n *\n * Proxies a search query to the underlying registry. Currently only\n * registryId=\"skills-sh\" is supported.\n */\nexport const BUILDER_REGISTRY_SEARCH_ROUTE = createRoute({\n method: 'GET',\n path: '/editor/builder/registries/:registryId/search',\n responseType: 'json',\n pathParamSchema: builderRegistryPathParams,\n queryParamSchema: builderRegistrySearchQuerySchema,\n responseSchema: skillsShSearchResponseSchema,\n summary: 'Search skills in a registry',\n description: 'Proxies a search request to the configured registry to avoid CORS issues.',\n tags: ['Editor', 'Skills'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:read',\n handler: async ({ mastra, registryId, q, limit }) => {\n try {\n await requireEnabledRegistry(mastra, registryId);\n return await searchSkillsSh({ q, limit });\n } catch (error) {\n if (error instanceof HTTPException) throw error;\n return handleError(error, 'Error searching registry');\n }\n },\n});\n\n/**\n * GET /editor/builder/registries/:registryId/popular\n *\n * Returns the most popular skills in a registry.\n */\nexport const BUILDER_REGISTRY_POPULAR_ROUTE = createRoute({\n method: 'GET',\n path: '/editor/builder/registries/:registryId/popular',\n responseType: 'json',\n pathParamSchema: builderRegistryPathParams,\n queryParamSchema: builderRegistryPopularQuerySchema,\n responseSchema: skillsShListResponseSchema,\n summary: 'Get popular skills from a registry',\n description: 'Proxies a popular-skills request to the configured registry to avoid CORS issues.',\n tags: ['Editor', 'Skills'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:read',\n handler: async ({ mastra, registryId, limit, offset }) => {\n try {\n await requireEnabledRegistry(mastra, registryId);\n return await getPopularSkillsSh({ limit, offset });\n } catch (error) {\n if (error instanceof HTTPException) throw error;\n return handleError(error, 'Error fetching popular skills');\n }\n },\n});\n\n/**\n * GET /editor/builder/registries/:registryId/preview\n *\n * Returns the rendered SKILL.md content for a single skill in the registry.\n */\nexport const BUILDER_REGISTRY_PREVIEW_ROUTE = createRoute({\n method: 'GET',\n path: '/editor/builder/registries/:registryId/preview',\n responseType: 'json',\n pathParamSchema: builderRegistryPathParams,\n queryParamSchema: builderRegistryPreviewQuerySchema,\n responseSchema: skillsShPreviewResponseSchema,\n summary: 'Preview a skill from a registry',\n description: 'Fetches the SKILL.md content for a single skill in the configured registry.',\n tags: ['Editor', 'Skills'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:read',\n handler: async ({ mastra, registryId, owner, repo, path: skillName }) => {\n try {\n await requireEnabledRegistry(mastra, registryId);\n return await previewSkillsSh({ owner, repo, skillName });\n } catch (error) {\n if (error instanceof HTTPException) throw error;\n return handleError(error, 'Error fetching skill preview');\n }\n },\n});\n\n/**\n * POST /editor/builder/registries/:registryId/install\n *\n * Fetches the full file tree for a skill from the registry, parses the\n * SKILL.md frontmatter for name/description, and persists everything as a\n * new stored skill. The registry origin is recorded under `metadata.origin`\n * so the UI can surface \"imported from skills.sh\" badges and re-resolve the\n * source later.\n *\n * Collisions (a stored skill with the derived id already exists) return 409\n * so the UI can offer an \"Open existing\" link instead of silently\n * overwriting.\n */\nexport const BUILDER_REGISTRY_INSTALL_ROUTE = createRoute({\n method: 'POST',\n path: '/editor/builder/registries/:registryId/install',\n responseType: 'json',\n pathParamSchema: builderRegistryPathParams,\n bodySchema: builderRegistryInstallBodySchema,\n responseSchema: builderRegistryInstallResponseSchema,\n summary: 'Install a registry skill into stored skills',\n description: 'Fetches a skill from the configured registry and persists it as a new stored skill.',\n tags: ['Editor', 'Skills'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:write',\n handler: async ({ mastra, requestContext, registryId, owner, repo, skillName, visibility: bodyVisibility }) => {\n try {\n await requireEnabledRegistry(mastra, registryId);\n\n const storage = mastra.getStorage();\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not configured' });\n }\n const skillStore = await storage.getStore('skills');\n if (!skillStore) {\n throw new HTTPException(500, { message: 'Skills storage domain is not available' });\n }\n\n // Pull files from the registry\n const result = await fetchSkillFiles(owner, repo, skillName);\n if (!result || result.files.length === 0) {\n throw new HTTPException(404, {\n message: `Could not find skill \"${skillName}\" in ${owner}/${repo}.`,\n });\n }\n\n const safeSkillId = assertSafeSkillName(result.skillId);\n const files = buildFileTree(result.files);\n\n // Parse SKILL.md frontmatter into structured fields. Splitting\n // frontmatter (name/description) from the markdown body keeps the\n // body as the agent-facing `instructions` instead of polluting it\n // with raw YAML metadata. SKILL.md missing or unparseable simply\n // yields a null snapshot — registry-provided values then fill in.\n const snapshot = parseSkillSnapshot(result.files);\n\n const resolvedName = snapshot?.name ?? safeSkillId;\n const description = snapshot?.description ?? `Imported from ${owner}/${repo}`;\n const id = toSlug(resolvedName) || safeSkillId;\n\n if (!id) {\n throw new HTTPException(400, {\n message: 'Could not derive skill ID from registry skill metadata.',\n });\n }\n\n // Reject collisions instead of silently overwriting; UI offers \"Open existing\".\n const existing = await skillStore.getById(id);\n if (existing) {\n throw new HTTPException(409, {\n message: `Skill with id \"${id}\" already exists.`,\n // Surface the existing id so the client can deep-link.\n cause: { storedSkillId: id },\n });\n }\n\n // Match the standard create flow: no caller = always public, otherwise default private.\n const authorId = getCallerAuthorId(requestContext) ?? undefined;\n const visibility: 'private' | 'public' = authorId ? (bodyVisibility ?? 'private') : 'public';\n\n // Use the SKILL.md body (post-frontmatter) as instructions. Frontmatter\n // values are already lifted into structured columns above, so re-storing\n // them in `instructions` would both duplicate metadata and feed YAML\n // into the agent's prompt. Fall back to description when no usable body\n // exists so `resolved.snapshot.instructions` stays non-empty.\n const instructions = snapshot?.instructions?.trim() ? snapshot.instructions : description;\n\n await skillStore.create({\n skill: {\n id,\n authorId,\n visibility,\n name: resolvedName,\n description,\n instructions,\n files,\n metadata: {\n origin: {\n type: 'skills-sh',\n owner,\n repo,\n skillName,\n },\n },\n },\n });\n\n return {\n storedSkillId: id,\n name: resolvedName,\n filesWritten: result.files.length,\n };\n } catch (error) {\n if (error instanceof HTTPException) throw error;\n return handleError(error, 'Error installing registry skill');\n }\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,6BAA6BA,OAAAA,EAAE,OAAO;CACjD,IAAIA,OAAAA,EAAE,QAAQ,WAAW,CAAC,CAAC,SAAS,4BAA4B;CAChE,SAASA,OAAAA,EAAE,QAAQ,CAAC,CAAC,SAAS,4DAA4D;CAC1F,OAAOA,OAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,8BAA8B;AAC3D,CAAC;;AAGD,MAAa,kCAAkCA,OAAAA,EAAE,OAAO,EACtD,YAAYA,OAAAA,EAAE,MAAM,0BAA0B,EAChD,CAAC;;AAOD,MAAa,4BAA4BA,OAAAA,EAAE,OAAO,EAChD,YAAYA,OAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,0CAAwC,EAC1E,CAAC;AAED,MAAa,mCAAmCA,OAAAA,EAAE,OAAO;CACvD,GAAGA,OAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,cAAc;CACrC,OAAOA,OAAAA,EAAE,OAAO,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,SAAS,mCAAmC;AACpH,CAAC;AAED,MAAa,oCAAoCA,OAAAA,EAC9C,OAAO;CACN,OAAOA,OAAAA,EAAE,OAAO,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC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ACX,CAAC;GAKH,IAAI,MADmB,WAAW,QAAQ,EAAE,GAE1C,MAAM,IAAIA,uBAAAA,cAAc,KAAK;IAC3B,SAAS,kBAAkB,GAAG;IAE9B,OAAO,EAAE,eAAe,GAAG;GAC7B,CAAC;GAIH,MAAM,WAAWa,mCAAAA,kBAAkB,cAAc,KAAK,KAAA;GACtD,MAAM,aAAmC,WAAY,kBAAkB,YAAa;GAOpF,MAAM,eAAe,UAAU,cAAc,KAAK,IAAI,SAAS,eAAe;GAE9E,MAAM,WAAW,OAAO,EACtB,OAAO;IACL;IACA;IACA;IACA,MAAM;IACN;IACA;IACA;IACA,UAAU,EACR,QAAQ;KACN,MAAM;KACN;KACA;KACA;IACF,EACF;GACF,EACF,CAAC;GAED,OAAO;IACL,eAAe;IACf,MAAM;IACN,cAAc,OAAO,MAAM;GAC7B;EACF,SAAS,OAAO;GACd,IAAI,iBAAiBb,uBAAAA,eAAe,MAAM;GAC1C,OAAOG,8BAAAA,YAAY,OAAO,iCAAiC;EAC7D;CACF;AACF,CAAC"}
1
+ {"version":3,"file":"builder-registry-Dcou-kzd.cjs","names":["z","HTTPException","assertSafeFilePath","createRoute","handleError","skillsShSearchResponseSchema","searchSkillsSh","skillsShListResponseSchema","getPopularSkillsSh","skillsShPreviewResponseSchema","previewSkillsSh","fetchSkillFiles","assertSafeSkillName","toSlug","getCallerAuthorId"],"sources":["../src/server/schemas/builder-registry.ts","../src/server/handlers/builder-registry.ts"],"sourcesContent":["/**\n * Builder Registry Schemas\n *\n * Schemas for the Agent Builder skill registry routes. These are distinct from\n * the workspace skills.sh proxy schemas because:\n * - Builder routes are not scoped to a workspace.\n * - Builder install does not accept a `mount` field.\n * - Builder install body carries visibility + the resolved registry id.\n * - Builder install response returns the created stored skill id.\n *\n * The upstream skills.sh proxy response shapes are reused via the shared\n * `skillsShSearchResponseSchema`, `skillsShListResponseSchema`, and\n * `skillsShPreviewResponseSchema` since the wire shape from skills.sh is\n * registry-independent.\n */\n\nimport { z } from 'zod/v4';\n\n// =============================================================================\n// Registry list\n// =============================================================================\n\n/** Single entry in the registries list. */\nexport const builderRegistryEntrySchema = z.object({\n id: z.literal('skills-sh').describe('Stable registry identifier'),\n enabled: z.boolean().describe('Whether this registry is enabled in the running deployment'),\n label: z.string().describe('Human-readable registry name'),\n});\n\n/** Response for `GET /editor/builder/registries`. */\nexport const builderRegistriesResponseSchema = z.object({\n registries: z.array(builderRegistryEntrySchema),\n});\n\n// =============================================================================\n// Search / popular / preview\n// =============================================================================\n\n/** Path params used by every per-registry route. */\nexport const builderRegistryPathParams = z.object({\n registryId: z.string().describe('Registry identifier (e.g. \"skills-sh\")'),\n});\n\nexport const builderRegistrySearchQuerySchema = z.object({\n q: z.string().describe('Search query'),\n limit: z.coerce.number().int().min(1).max(100).optional().default(10).describe('Maximum number of results (1-100)'),\n});\n\nexport const builderRegistryPopularQuerySchema = z\n .object({\n limit: z.coerce.number().int().min(1).max(100).optional().default(10).describe('Maximum number of results (1-100)'),\n offset: z.coerce\n .number()\n .int()\n .min(0)\n .optional()\n .default(0)\n .describe('Offset for pagination (must be a multiple of `limit`)'),\n })\n .refine(args => args.offset % args.limit === 0, {\n message: 'offset must be a multiple of limit (the upstream registry pages by `limit`)',\n path: ['offset'],\n });\n\nexport const builderRegistryPreviewQuerySchema = z.object({\n owner: z.string().describe('GitHub repository owner'),\n repo: z.string().describe('GitHub repository name'),\n path: z.string().describe('Skill name within repo'),\n});\n\n// =============================================================================\n// Install\n// =============================================================================\n\n/**\n * Body for `POST /editor/builder/registries/:registryId/install`.\n *\n * Visibility behaves like the standard stored-skill create flow: optional,\n * defaults to private when the caller is authenticated.\n */\nexport const builderRegistryInstallBodySchema = z.object({\n owner: z.string().describe('GitHub repository owner'),\n repo: z.string().describe('GitHub repository name'),\n skillName: z.string().describe('Skill name from the registry'),\n visibility: z.enum(['private', 'public']).optional().describe('Visibility for the new stored skill'),\n});\n\n/** Response for the install route. Mirrors stored-skill identity fields. */\nexport const builderRegistryInstallResponseSchema = z.object({\n storedSkillId: z.string().describe('Id of the newly created stored skill'),\n name: z.string().describe('Resolved skill name'),\n filesWritten: z.number().describe('Number of files materialized into the skill version snapshot'),\n});\n\nexport type BuilderRegistryEntry = z.infer<typeof builderRegistryEntrySchema>;\nexport type BuilderRegistriesResponse = z.infer<typeof builderRegistriesResponseSchema>;\nexport type BuilderRegistryInstallBody = z.infer<typeof builderRegistryInstallBodySchema>;\nexport type BuilderRegistryInstallResponse = z.infer<typeof builderRegistryInstallResponseSchema>;\n","/**\n * Builder Registry Handlers\n *\n * Routes that let admins browse and install skills from configured external\n * registries (currently just skills.sh) directly into the Builder's stored\n * skills DB. Distinct from the workspace skills.sh routes, which write to a\n * workspace filesystem and never touch storage.\n *\n * Registry availability is driven by `AgentBuilderOptions.registries`. When\n * the requested registry is disabled (or the builder is missing entirely),\n * the routes 404 instead of leaking the surface.\n */\n\nimport type { Mastra } from '@mastra/core';\nimport type { StorageSkillFileNode } from '@mastra/core/storage';\n\nimport { HTTPException } from '../http-exception';\nimport {\n builderRegistriesResponseSchema,\n builderRegistryInstallBodySchema,\n builderRegistryInstallResponseSchema,\n builderRegistryPathParams,\n builderRegistryPopularQuerySchema,\n builderRegistryPreviewQuerySchema,\n builderRegistrySearchQuerySchema,\n} from '../schemas/builder-registry';\nimport {\n skillsShListResponseSchema,\n skillsShPreviewResponseSchema,\n skillsShSearchResponseSchema,\n} from '../schemas/workspace';\nimport { createRoute } from '../server-adapter/routes/route-builder';\nimport { toSlug } from '../utils';\nimport { getCallerAuthorId } from './authorship';\nimport { handleError } from './error';\nimport {\n assertSafeFilePath,\n assertSafeSkillName,\n fetchSkillFiles,\n getPopularSkillsSh,\n previewSkillsSh,\n searchSkillsSh,\n} from './skills-sh-shared';\n\n// =============================================================================\n// Registry resolution\n// =============================================================================\n\n/** Stable identifiers + display labels for every supported registry. */\nconst REGISTRY_LABELS: Record<string, string> = {\n 'skills-sh': 'skills.sh',\n};\n\ninterface RegistryStatus {\n id: 'skills-sh';\n enabled: boolean;\n label: string;\n}\n\n/**\n * Resolve which registries are enabled for the running deployment by reading\n * the builder's `registries` config. Returns a list with all known registries\n * (so the frontend can render an empty/disabled state) plus their enabled\n * flag.\n */\nasync function resolveRegistries(mastra: Mastra): Promise<RegistryStatus[]> {\n const editor = mastra.getEditor();\n if (!editor || typeof editor.resolveBuilder !== 'function') {\n return [{ id: 'skills-sh', enabled: false, label: REGISTRY_LABELS['skills-sh']! }];\n }\n const builder = await editor.resolveBuilder();\n const registries = builder?.getRegistries?.();\n return [\n {\n id: 'skills-sh',\n enabled: registries?.skillsSh?.enabled === true,\n label: REGISTRY_LABELS['skills-sh']!,\n },\n ];\n}\n\n/**\n * Hard-gate: throws 404 when the requested registry is unknown or disabled.\n * Mirrors `requireBuilderFeature` semantics — no surface leak for OFF registries.\n */\nasync function requireEnabledRegistry(mastra: Mastra, registryId: string): Promise<void> {\n const list = await resolveRegistries(mastra);\n const match = list.find(r => r.id === registryId);\n if (!match || !match.enabled) {\n throw new HTTPException(404, { message: 'Registry not found' });\n }\n}\n\n// =============================================================================\n// File-tree helpers\n// =============================================================================\n\n/**\n * Convert a flat list of `{ path, content, encoding }` entries into the\n * `StorageSkillFileNode` tree shape expected by the stored-skills create path.\n *\n * Each path is validated via `assertSafeFilePath` to prevent traversal from\n * upstream-controlled responses. Folder nodes are created on demand.\n */\nfunction buildFileTree(\n files: Array<{ path: string; content: string; encoding: 'utf-8' | 'base64' }>,\n): StorageSkillFileNode[] {\n const root: StorageSkillFileNode[] = [];\n\n for (const file of files) {\n const safePath = assertSafeFilePath(file.path);\n const segments = safePath.split('/').filter(Boolean);\n if (segments.length === 0) continue;\n\n let cursor = root;\n for (let i = 0; i < segments.length - 1; i++) {\n const segment = segments[i]!;\n let folder = cursor.find(node => node.type === 'folder' && node.name === segment);\n if (!folder) {\n folder = { name: segment, type: 'folder', children: [] };\n cursor.push(folder);\n }\n if (!folder.children) folder.children = [];\n cursor = folder.children;\n }\n\n const fileName = segments[segments.length - 1]!;\n const content = file.encoding === 'base64' ? Buffer.from(file.content, 'base64').toString('utf-8') : file.content;\n cursor.push({ name: fileName, type: 'file', content });\n }\n\n return root;\n}\n\n/**\n * Locally-bound SKILL.md frontmatter parser.\n *\n * Mirrors `parseSkillSnapshotFromFiles` from `@mastra/core/workspace`, but\n * inlined here because the server package's `@mastra/core` peer floor\n * (>=1.32.0) predates that helper. Once the floor is bumped to a release\n * containing the helper, this can be replaced by the shared core import.\n *\n * Only SKILL.md is consulted — frontmatter is split from the body using a\n * minimal YAML key:value reader sufficient for the fields registries\n * actually use (name, description). The body is everything after the\n * second `---` line, trimmed.\n */\ntype ParsedSkillSnapshot = {\n name?: string;\n description?: string;\n instructions: string;\n};\n\nfunction parseSkillSnapshot(\n files: Array<{ path: string; content: string; encoding: 'utf-8' | 'base64' }>,\n): ParsedSkillSnapshot | null {\n const skillMd = files.find(f => f.path === 'SKILL.md');\n if (!skillMd) return null;\n\n const raw =\n skillMd.encoding === 'base64' ? Buffer.from(skillMd.content, 'base64').toString('utf-8') : skillMd.content;\n\n const fmMatch = raw.match(/^---\\r?\\n([\\s\\S]*?)\\r?\\n---\\r?\\n?([\\s\\S]*)$/);\n if (!fmMatch) {\n return { instructions: raw.trim() };\n }\n\n const fmBlock = fmMatch[1] ?? '';\n const body = fmMatch[2] ?? '';\n const frontmatter: Record<string, string> = {};\n for (const line of fmBlock.split(/\\r?\\n/)) {\n const m = line.match(/^([A-Za-z0-9_-]+)\\s*:\\s*(.*)$/);\n if (!m) continue;\n const key = m[1];\n const value = m[2] ?? '';\n if (!key) continue;\n // Strip surrounding quotes, leave the rest as-is. Registry SKILL.md\n // frontmatter is consistently flat string fields in practice.\n frontmatter[key] = value.trim().replace(/^[\"'](.*)[\"']$/, '$1');\n }\n\n return {\n name: frontmatter.name,\n description: frontmatter.description,\n instructions: body.trim(),\n };\n}\n\n// =============================================================================\n// Routes\n// =============================================================================\n\n/**\n * GET /editor/builder/registries\n *\n * Lists every known registry and whether it's enabled in this deployment.\n * Used by the Builder UI to decide whether to show the \"Browse registry\"\n * entry point at all.\n */\nexport const LIST_BUILDER_REGISTRIES_ROUTE = createRoute({\n method: 'GET',\n path: '/editor/builder/registries',\n responseType: 'json',\n responseSchema: builderRegistriesResponseSchema,\n summary: 'List available skill registries',\n description: 'Returns the configured external skill registries and their enabled state.',\n tags: ['Editor'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:read',\n handler: async ({ mastra }) => {\n try {\n const registries = await resolveRegistries(mastra);\n return { registries };\n } catch (error) {\n return handleError(error, 'Error listing builder registries');\n }\n },\n});\n\n/**\n * GET /editor/builder/registries/:registryId/search\n *\n * Proxies a search query to the underlying registry. Currently only\n * registryId=\"skills-sh\" is supported.\n */\nexport const BUILDER_REGISTRY_SEARCH_ROUTE = createRoute({\n method: 'GET',\n path: '/editor/builder/registries/:registryId/search',\n responseType: 'json',\n pathParamSchema: builderRegistryPathParams,\n queryParamSchema: builderRegistrySearchQuerySchema,\n responseSchema: skillsShSearchResponseSchema,\n summary: 'Search skills in a registry',\n description: 'Proxies a search request to the configured registry to avoid CORS issues.',\n tags: ['Editor', 'Skills'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:read',\n handler: async ({ mastra, registryId, q, limit }) => {\n try {\n await requireEnabledRegistry(mastra, registryId);\n return await searchSkillsSh({ q, limit });\n } catch (error) {\n if (error instanceof HTTPException) throw error;\n return handleError(error, 'Error searching registry');\n }\n },\n});\n\n/**\n * GET /editor/builder/registries/:registryId/popular\n *\n * Returns the most popular skills in a registry.\n */\nexport const BUILDER_REGISTRY_POPULAR_ROUTE = createRoute({\n method: 'GET',\n path: '/editor/builder/registries/:registryId/popular',\n responseType: 'json',\n pathParamSchema: builderRegistryPathParams,\n queryParamSchema: builderRegistryPopularQuerySchema,\n responseSchema: skillsShListResponseSchema,\n summary: 'Get popular skills from a registry',\n description: 'Proxies a popular-skills request to the configured registry to avoid CORS issues.',\n tags: ['Editor', 'Skills'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:read',\n handler: async ({ mastra, registryId, limit, offset }) => {\n try {\n await requireEnabledRegistry(mastra, registryId);\n return await getPopularSkillsSh({ limit, offset });\n } catch (error) {\n if (error instanceof HTTPException) throw error;\n return handleError(error, 'Error fetching popular skills');\n }\n },\n});\n\n/**\n * GET /editor/builder/registries/:registryId/preview\n *\n * Returns the rendered SKILL.md content for a single skill in the registry.\n */\nexport const BUILDER_REGISTRY_PREVIEW_ROUTE = createRoute({\n method: 'GET',\n path: '/editor/builder/registries/:registryId/preview',\n responseType: 'json',\n pathParamSchema: builderRegistryPathParams,\n queryParamSchema: builderRegistryPreviewQuerySchema,\n responseSchema: skillsShPreviewResponseSchema,\n summary: 'Preview a skill from a registry',\n description: 'Fetches the SKILL.md content for a single skill in the configured registry.',\n tags: ['Editor', 'Skills'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:read',\n handler: async ({ mastra, registryId, owner, repo, path: skillName }) => {\n try {\n await requireEnabledRegistry(mastra, registryId);\n return await previewSkillsSh({ owner, repo, skillName });\n } catch (error) {\n if (error instanceof HTTPException) throw error;\n return handleError(error, 'Error fetching skill preview');\n }\n },\n});\n\n/**\n * POST /editor/builder/registries/:registryId/install\n *\n * Fetches the full file tree for a skill from the registry, parses the\n * SKILL.md frontmatter for name/description, and persists everything as a\n * new stored skill. The registry origin is recorded under `metadata.origin`\n * so the UI can surface \"imported from skills.sh\" badges and re-resolve the\n * source later.\n *\n * Collisions (a stored skill with the derived id already exists) return 409\n * so the UI can offer an \"Open existing\" link instead of silently\n * overwriting.\n */\nexport const BUILDER_REGISTRY_INSTALL_ROUTE = createRoute({\n method: 'POST',\n path: '/editor/builder/registries/:registryId/install',\n responseType: 'json',\n pathParamSchema: builderRegistryPathParams,\n bodySchema: builderRegistryInstallBodySchema,\n responseSchema: builderRegistryInstallResponseSchema,\n summary: 'Install a registry skill into stored skills',\n description: 'Fetches a skill from the configured registry and persists it as a new stored skill.',\n tags: ['Editor', 'Skills'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:write',\n handler: async ({ mastra, requestContext, registryId, owner, repo, skillName, visibility: bodyVisibility }) => {\n try {\n await requireEnabledRegistry(mastra, registryId);\n\n const storage = mastra.getStorage();\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not configured' });\n }\n const skillStore = await storage.getStore('skills');\n if (!skillStore) {\n throw new HTTPException(500, { message: 'Skills storage domain is not available' });\n }\n\n // Pull files from the registry\n const result = await fetchSkillFiles(owner, repo, skillName);\n if (!result || result.files.length === 0) {\n throw new HTTPException(404, {\n message: `Could not find skill \"${skillName}\" in ${owner}/${repo}.`,\n });\n }\n\n const safeSkillId = assertSafeSkillName(result.skillId);\n const files = buildFileTree(result.files);\n\n // Parse SKILL.md frontmatter into structured fields. Splitting\n // frontmatter (name/description) from the markdown body keeps the\n // body as the agent-facing `instructions` instead of polluting it\n // with raw YAML metadata. SKILL.md missing or unparseable simply\n // yields a null snapshot — registry-provided values then fill in.\n const snapshot = parseSkillSnapshot(result.files);\n\n const resolvedName = snapshot?.name ?? safeSkillId;\n const description = snapshot?.description ?? `Imported from ${owner}/${repo}`;\n const id = toSlug(resolvedName) || safeSkillId;\n\n if (!id) {\n throw new HTTPException(400, {\n message: 'Could not derive skill ID from registry skill metadata.',\n });\n }\n\n // Reject collisions instead of silently overwriting; UI offers \"Open existing\".\n const existing = await skillStore.getById(id);\n if (existing) {\n throw new HTTPException(409, {\n message: `Skill with id \"${id}\" already exists.`,\n // Surface the existing id so the client can deep-link.\n cause: { storedSkillId: id },\n });\n }\n\n // Match the standard create flow: no caller = always public, otherwise default private.\n const authorId = getCallerAuthorId(requestContext) ?? undefined;\n const visibility: 'private' | 'public' = authorId ? (bodyVisibility ?? 'private') : 'public';\n\n // Use the SKILL.md body (post-frontmatter) as instructions. Frontmatter\n // values are already lifted into structured columns above, so re-storing\n // them in `instructions` would both duplicate metadata and feed YAML\n // into the agent's prompt. Fall back to description when no usable body\n // exists so `resolved.snapshot.instructions` stays non-empty.\n const instructions = snapshot?.instructions?.trim() ? snapshot.instructions : description;\n\n await skillStore.create({\n skill: {\n id,\n authorId,\n visibility,\n name: resolvedName,\n description,\n instructions,\n files,\n metadata: {\n origin: {\n type: 'skills-sh',\n owner,\n repo,\n skillName,\n },\n },\n },\n });\n\n return {\n storedSkillId: id,\n name: resolvedName,\n filesWritten: result.files.length,\n };\n } catch (error) {\n if (error instanceof HTTPException) throw error;\n return handleError(error, 'Error installing registry skill');\n }\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,6BAA6BA,OAAAA,EAAE,OAAO;CACjD,IAAIA,OAAAA,EAAE,QAAQ,WAAW,CAAC,CAAC,SAAS,4BAA4B;CAChE,SAASA,OAAAA,EAAE,QAAQ,CAAC,CAAC,SAAS,4DAA4D;CAC1F,OAAOA,OAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,8BAA8B;AAC3D,CAAC;;AAGD,MAAa,kCAAkCA,OAAAA,EAAE,OAAO,EACtD,YAAYA,OAAAA,EAAE,MAAM,0BAA0B,EAChD,CAAC;;AAOD,MAAa,4BAA4BA,OAAAA,EAAE,OAAO,EAChD,YAAYA,OAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,0CAAwC,EAC1E,CAAC;AAED,MAAa,mCAAmCA,OAAAA,EAAE,OAAO;CACvD,GAAGA,OAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,cAAc;CACrC,OAAOA,OAAAA,EAAE,OAAO,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,SAAS,mCAAmC;AACpH,CAAC;AAED,MAAa,oCAAoCA,OAAAA,EAC9C,OAAO;CACN,OAAOA,OAAAA,EAAE,OAAO,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,SAAS,CAAC,C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,cAAc,KAAK,EAC3B,SAAS,0DACX,CAAC;GAKH,IAAI,MADmB,WAAW,QAAQ,EAAE,GAE1C,MAAM,IAAIA,uBAAAA,cAAc,KAAK;IAC3B,SAAS,kBAAkB,GAAG;IAE9B,OAAO,EAAE,eAAe,GAAG;GAC7B,CAAC;GAIH,MAAM,WAAWa,mCAAAA,kBAAkB,cAAc,KAAK,KAAA;GACtD,MAAM,aAAmC,WAAY,kBAAkB,YAAa;GAOpF,MAAM,eAAe,UAAU,cAAc,KAAK,IAAI,SAAS,eAAe;GAE9E,MAAM,WAAW,OAAO,EACtB,OAAO;IACL;IACA;IACA;IACA,MAAM;IACN;IACA;IACA;IACA,UAAU,EACR,QAAQ;KACN,MAAM;KACN;KACA;KACA;IACF,EACF;GACF,EACF,CAAC;GAED,OAAO;IACL,eAAe;IACf,MAAM;IACN,cAAc,OAAO,MAAM;GAC7B;EACF,SAAS,OAAO;GACd,IAAI,iBAAiBb,uBAAAA,eAAe,MAAM;GAC1C,OAAOG,8BAAAA,YAAY,OAAO,iCAAiC;EAC7D;CACF;AACF,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { t as HTTPException } from "./http-exception-CyfxZB6W.js";
2
- import { n as createRoute } from "./route-builder-CIk5k35M.js";
2
+ import { n as createRoute } from "./route-builder-YQ_gLIvW.js";
3
3
  import "./constants-Cp1x-6sJ.js";
4
4
  import { handleError } from "./server/handlers/error.js";
5
5
  import { assertWriteAccess, getCallerAuthorId, hasAdminBypass, hasScopedPermission } from "./server/handlers/authorship.js";
@@ -204,4 +204,4 @@ const DISCONNECT_CHANNEL_ROUTE = createRoute({
204
204
  //#endregion
205
205
  export { LIST_CHANNEL_PLATFORMS_ROUTE as i, DISCONNECT_CHANNEL_ROUTE as n, LIST_CHANNEL_INSTALLATIONS_ROUTE as r, CONNECT_CHANNEL_ROUTE as t };
206
206
 
207
- //# sourceMappingURL=channels-BqkOxxEk.js.map
207
+ //# sourceMappingURL=channels-B9yt3a2P.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"channels-BqkOxxEk.js","names":[],"sources":["../src/server/schemas/channels.ts","../src/server/handlers/channels.ts"],"sourcesContent":["import { z } from 'zod/v4';\n\n// ============================================================================\n// Path Parameter Schemas\n// ============================================================================\n\nexport const channelPlatformPathParams = z.object({\n platform: z.string().describe('Channel platform identifier (e.g., \"slack\")'),\n});\n\nexport const channelAgentPathParams = z.object({\n platform: z.string().describe('Channel platform identifier (e.g., \"slack\")'),\n agentId: z.string().describe('Agent identifier'),\n});\n\n// ============================================================================\n// Body Parameter Schemas\n// ============================================================================\n\nexport const connectChannelBodySchema = z.object({\n agentId: z.string().describe('Agent identifier to connect'),\n options: z.record(z.string(), z.unknown()).optional().describe('Platform-specific connection options'),\n});\n\n// ============================================================================\n// Response Schemas\n// ============================================================================\n\nconst channelPlatformInfoSchema = z.object({\n id: z.string().describe('Platform identifier'),\n name: z.string().describe('Human-readable platform name'),\n isConfigured: z.boolean().describe('Whether the platform is ready to connect agents'),\n connectOptionsSchema: z.record(z.string(), z.unknown()).optional().describe('JSON Schema for connect options'),\n});\n\nconst channelInstallationInfoSchema = z.object({\n id: z.string().describe('Installation identifier'),\n platform: z.string().describe('Platform identifier'),\n agentId: z.string().describe('Connected agent identifier'),\n status: z.enum(['active', 'pending']).describe('Installation status'),\n displayName: z.string().optional().describe('Platform-specific display name'),\n installedAt: z.coerce.date().optional().describe('Installation timestamp'),\n});\n\nconst channelConnectOAuthSchema = z.object({\n type: z.literal('oauth').describe('OAuth-based connection requiring browser redirect'),\n authorizationUrl: z.string().describe('OAuth authorization URL for user redirect'),\n installationId: z.string().describe('Installation identifier'),\n});\n\nconst channelConnectDeepLinkSchema = z.object({\n type: z.literal('deep_link').describe('Deep-link connection requiring native app interaction'),\n url: z.string().describe('Deep link URL to open in platform app'),\n installationId: z.string().describe('Installation identifier'),\n});\n\nconst channelConnectImmediateSchema = z.object({\n type: z.literal('immediate').describe('Immediate connection with no user interaction needed'),\n installationId: z.string().describe('Installation identifier'),\n});\n\nconst channelConnectResultSchema = z.discriminatedUnion('type', [\n channelConnectOAuthSchema,\n channelConnectDeepLinkSchema,\n channelConnectImmediateSchema,\n]);\n\nexport const listChannelPlatformsResponseSchema = z.array(channelPlatformInfoSchema);\n\nexport const listChannelInstallationsResponseSchema = z.array(channelInstallationInfoSchema);\n\nexport const connectChannelResponseSchema = channelConnectResultSchema;\n\nexport const disconnectChannelResponseSchema = z.object({\n success: z.boolean(),\n});\n","import type { Mastra } from '@mastra/core';\nimport type { ChannelProvider } from '@mastra/core/channels';\nimport type { RequestContext } from '@mastra/core/di';\nimport { coreFeatures } from '@mastra/core/features';\n\nimport { MASTRA_USER_KEY } from '../constants';\nimport { HTTPException } from '../http-exception';\nimport {\n channelPlatformPathParams,\n channelAgentPathParams,\n connectChannelBodySchema,\n listChannelPlatformsResponseSchema,\n listChannelInstallationsResponseSchema,\n connectChannelResponseSchema,\n disconnectChannelResponseSchema,\n} from '../schemas/channels';\nimport { createRoute } from '../server-adapter/routes/route-builder';\n\nimport { assertWriteAccess, getCallerAuthorId, hasAdminBypass, hasScopedPermission } from './authorship';\nimport { handleError } from './error';\n\n// ============================================================================\n// Feature gate + helpers\n// ============================================================================\n\nfunction assertChannelsAvailable(): void {\n if (!coreFeatures.has('channels')) {\n throw new HTTPException(501, { message: 'Channels require a newer version of @mastra/core' });\n }\n}\n\nfunction getChannelOrThrow(mastra: Mastra, platform: string): ChannelProvider {\n const channels = Object.values(mastra.channels ?? {});\n const channel = channels.find(c => c.id === platform);\n if (!channel) {\n const available = channels.map(c => c.id).join(', ');\n throw new HTTPException(404, {\n message: `Channel \"${platform}\" is not registered. Available: ${available || 'none'}`,\n });\n }\n return channel;\n}\n\n/**\n * Unified connect/disconnect authorization.\n *\n * - Stored agent exists → same write access as editing the agent record.\n * - Code-defined agent (no stored record) → route's `requiresAuth` is the gate.\n * - Agent doesn't exist anywhere:\n * - connect → 404 (can't connect a channel to a non-existent agent)\n * - disconnect → orphan cleanup, gated on `channels:write`\n */\nasync function assertChannelAgentWriteAccess(\n mastra: Mastra,\n requestContext: RequestContext,\n agentId: string,\n action: 'connect' | 'disconnect',\n): Promise<void> {\n const storage = mastra.getStorage();\n const agentsStore = storage ? await storage.getStore('agents') : null;\n const stored = agentsStore ? await agentsStore.getById(agentId) : null;\n\n if (stored) {\n assertWriteAccess({\n requestContext,\n resource: 'agents',\n resourceId: agentId,\n action: 'edit',\n record: stored,\n });\n return;\n }\n\n // Not in stored-agents (or storage doesn't support it). Check the runtime\n // registry for a code-defined agent.\n const codeDefined = mastra.getAgentById(agentId);\n if (codeDefined) {\n // Code-defined agents have no owner/ACL — route's requiresAuth /\n // requiresPermission is the gate. Pass-through.\n return;\n }\n\n if (action === 'connect') {\n throw new HTTPException(404, { message: `Agent \"${agentId}\" not found` });\n }\n\n // Disconnect against an unknown agentId = orphan cleanup (stored agent was\n // deleted but the channel installation row is still around). Allow it, but\n // gate on channels:write so this isn't an \"any authenticated user\" backdoor.\n // Follow the same no-auth-configured pass-through as assertWriteAccess.\n const callerAuthorId = getCallerAuthorId(requestContext);\n if (!callerAuthorId && !requestContext.get(MASTRA_USER_KEY)) return;\n if (hasAdminBypass(requestContext, 'channels')) return;\n if (hasScopedPermission({ requestContext, resource: 'channels', action: 'write' })) return;\n\n throw new HTTPException(404, { message: 'Not found' });\n}\n\n// ============================================================================\n// Route Definitions\n// ============================================================================\n\n/**\n * GET /channels/platforms - List available channel platforms\n */\nexport const LIST_CHANNEL_PLATFORMS_ROUTE = createRoute({\n method: 'GET',\n path: '/channels/platforms',\n responseType: 'json',\n responseSchema: listChannelPlatformsResponseSchema,\n summary: 'List channel platforms',\n description: 'Returns available channel platforms and their configuration status',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra }) => {\n assertChannelsAvailable();\n try {\n const channels = Object.values(mastra.channels ?? {});\n return channels.map(channel => {\n if (channel.getInfo) {\n return channel.getInfo();\n }\n return {\n id: channel.id,\n name: channel.id.charAt(0).toUpperCase() + channel.id.slice(1),\n isConfigured: true,\n };\n });\n } catch (error) {\n return handleError(error, 'Error listing channel platforms');\n }\n },\n});\n\n/**\n * GET /channels/:platform/installations - List installations for a platform\n */\nexport const LIST_CHANNEL_INSTALLATIONS_ROUTE = createRoute({\n method: 'GET',\n path: '/channels/:platform/installations',\n responseType: 'json',\n pathParamSchema: channelPlatformPathParams,\n responseSchema: listChannelInstallationsResponseSchema,\n summary: 'List channel installations',\n description: 'Returns all active and pending installations for a channel platform',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra, platform }) => {\n assertChannelsAvailable();\n try {\n const channel = getChannelOrThrow(mastra, platform);\n\n if (!channel.listInstallations) {\n return [];\n }\n\n return await channel.listInstallations();\n } catch (error) {\n return handleError(error, 'Error listing channel installations');\n }\n },\n});\n\n/**\n * POST /channels/:platform/connect - Connect an agent to a platform\n */\nexport const CONNECT_CHANNEL_ROUTE = createRoute({\n method: 'POST',\n path: '/channels/:platform/connect',\n responseType: 'json',\n pathParamSchema: channelPlatformPathParams,\n bodySchema: connectChannelBodySchema,\n responseSchema: connectChannelResponseSchema,\n summary: 'Connect agent to channel',\n description: 'Creates a platform app for the agent and returns an OAuth authorization URL',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra, requestContext, platform, agentId, options }) => {\n assertChannelsAvailable();\n try {\n const channel = getChannelOrThrow(mastra, platform);\n\n if (!channel.connect) {\n throw new HTTPException(400, {\n message: `Channel \"${platform}\" does not support programmatic connection`,\n });\n }\n\n await assertChannelAgentWriteAccess(mastra, requestContext, agentId, 'connect');\n\n return await channel.connect(agentId, options);\n } catch (error) {\n return handleError(error, 'Error connecting agent to channel');\n }\n },\n});\n\n/**\n * POST /channels/:platform/:agentId/disconnect - Disconnect an agent from a platform\n */\nexport const DISCONNECT_CHANNEL_ROUTE = createRoute({\n method: 'POST',\n path: '/channels/:platform/:agentId/disconnect',\n responseType: 'json',\n pathParamSchema: channelAgentPathParams,\n responseSchema: disconnectChannelResponseSchema,\n summary: 'Disconnect agent from channel',\n description: 'Deletes the platform app and cleans up the installation',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra, requestContext, platform, agentId }) => {\n assertChannelsAvailable();\n try {\n const channel = getChannelOrThrow(mastra, platform);\n\n if (!channel.disconnect) {\n throw new HTTPException(400, {\n message: `Channel \"${platform}\" does not support programmatic disconnection`,\n });\n }\n\n await assertChannelAgentWriteAccess(mastra, requestContext, agentId, 'disconnect');\n\n await channel.disconnect(agentId);\n return { success: true };\n } catch (error) {\n return handleError(error, 'Error disconnecting agent from channel');\n }\n },\n});\n"],"mappings":";;;;;;;;AAMA,MAAa,4BAA4B,EAAE,OAAO,EAChD,UAAU,EAAE,OAAO,CAAC,CAAC,SAAS,+CAA6C,EAC7E,CAAC;AAED,MAAa,yBAAyB,EAAE,OAAO;CAC7C,UAAU,EAAE,OAAO,CAAC,CAAC,SAAS,+CAA6C;CAC3E,SAAS,EAAE,OAAO,CAAC,CAAC,SAAS,kBAAkB;AACjD,CAAC;AAMD,MAAa,2BAA2B,EAAE,OAAO;CAC/C,SAAS,EAAE,OAAO,CAAC,CAAC,SAAS,6BAA6B;CAC1D,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,sCAAsC;AACvG,CAAC;AAMD,MAAM,4BAA4B,EAAE,OAAO;CACzC,IAAI,EAAE,OAAO,CAAC,CAAC,SAAS,qBAAqB;CAC7C,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS,8BAA8B;CACxD,cAAc,EAAE,QAAQ,CAAC,CAAC,SAAS,iDAAiD;CACpF,sBAAsB,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,iCAAiC;AAC/G,CAAC;AAED,MAAM,gCAAgC,EAAE,OAAO;CAC7C,IAAI,EAAE,OAAO,CAAC,CAAC,SAAS,yBAAyB;CACjD,UAA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AmC;EAC/D;CACF;AACF,CAAC;;;;AAKD,MAAa,2BAA2B,YAAY;CAClD,QAAQ;CACR,MAAM;CACN,cAAc;CACd,iBAAiB;CACjB,gBAAgB;CAChB,SAAS;CACT,aAAa;CACb,MAAM,CAAC,UAAU;CACjB,cAAc;CACd,SAAS,OAAO,EAAE,QAAQ,gBAAgB,UAAU,cAAc;EAChE,wBAAwB;EACxB,IAAI;GACF,MAAM,UAAU,kBAAkB,QAAQ,QAAQ;GAElD,IAAI,CAAC,QAAQ,YACX,MAAM,IAAI,cAAc,KAAK,EAC3B,SAAS,YAAY,SAAS,+CAChC,CAAC;GAGH,MAAM,8BAA8B,QAAQ,gBAAgB,SAAS,YAAY;GAEjF,MAAM,QAAQ,WAAW,OAAO;GAChC,OAAO,EAAE,SAAS,KAAK;EACzB,SAAS,OAAO;GACd,OAAO,YAAY,OAAO,wCAAwC;EACpE;CACF;AACF,CAAC"}
1
+ {"version":3,"file":"channels-B9yt3a2P.js","names":[],"sources":["../src/server/schemas/channels.ts","../src/server/handlers/channels.ts"],"sourcesContent":["import { z } from 'zod/v4';\n\n// ============================================================================\n// Path Parameter Schemas\n// ============================================================================\n\nexport const channelPlatformPathParams = z.object({\n platform: z.string().describe('Channel platform identifier (e.g., \"slack\")'),\n});\n\nexport const channelAgentPathParams = z.object({\n platform: z.string().describe('Channel platform identifier (e.g., \"slack\")'),\n agentId: z.string().describe('Agent identifier'),\n});\n\n// ============================================================================\n// Body Parameter Schemas\n// ============================================================================\n\nexport const connectChannelBodySchema = z.object({\n agentId: z.string().describe('Agent identifier to connect'),\n options: z.record(z.string(), z.unknown()).optional().describe('Platform-specific connection options'),\n});\n\n// ============================================================================\n// Response Schemas\n// ============================================================================\n\nconst channelPlatformInfoSchema = z.object({\n id: z.string().describe('Platform identifier'),\n name: z.string().describe('Human-readable platform name'),\n isConfigured: z.boolean().describe('Whether the platform is ready to connect agents'),\n connectOptionsSchema: z.record(z.string(), z.unknown()).optional().describe('JSON Schema for connect options'),\n});\n\nconst channelInstallationInfoSchema = z.object({\n id: z.string().describe('Installation identifier'),\n platform: z.string().describe('Platform identifier'),\n agentId: z.string().describe('Connected agent identifier'),\n status: z.enum(['active', 'pending']).describe('Installation status'),\n displayName: z.string().optional().describe('Platform-specific display name'),\n installedAt: z.coerce.date().optional().describe('Installation timestamp'),\n});\n\nconst channelConnectOAuthSchema = z.object({\n type: z.literal('oauth').describe('OAuth-based connection requiring browser redirect'),\n authorizationUrl: z.string().describe('OAuth authorization URL for user redirect'),\n installationId: z.string().describe('Installation identifier'),\n});\n\nconst channelConnectDeepLinkSchema = z.object({\n type: z.literal('deep_link').describe('Deep-link connection requiring native app interaction'),\n url: z.string().describe('Deep link URL to open in platform app'),\n installationId: z.string().describe('Installation identifier'),\n});\n\nconst channelConnectImmediateSchema = z.object({\n type: z.literal('immediate').describe('Immediate connection with no user interaction needed'),\n installationId: z.string().describe('Installation identifier'),\n});\n\nconst channelConnectResultSchema = z.discriminatedUnion('type', [\n channelConnectOAuthSchema,\n channelConnectDeepLinkSchema,\n channelConnectImmediateSchema,\n]);\n\nexport const listChannelPlatformsResponseSchema = z.array(channelPlatformInfoSchema);\n\nexport const listChannelInstallationsResponseSchema = z.array(channelInstallationInfoSchema);\n\nexport const connectChannelResponseSchema = channelConnectResultSchema;\n\nexport const disconnectChannelResponseSchema = z.object({\n success: z.boolean(),\n});\n","import type { Mastra } from '@mastra/core';\nimport type { ChannelProvider } from '@mastra/core/channels';\nimport type { RequestContext } from '@mastra/core/di';\nimport { coreFeatures } from '@mastra/core/features';\n\nimport { MASTRA_USER_KEY } from '../constants';\nimport { HTTPException } from '../http-exception';\nimport {\n channelPlatformPathParams,\n channelAgentPathParams,\n connectChannelBodySchema,\n listChannelPlatformsResponseSchema,\n listChannelInstallationsResponseSchema,\n connectChannelResponseSchema,\n disconnectChannelResponseSchema,\n} from '../schemas/channels';\nimport { createRoute } from '../server-adapter/routes/route-builder';\n\nimport { assertWriteAccess, getCallerAuthorId, hasAdminBypass, hasScopedPermission } from './authorship';\nimport { handleError } from './error';\n\n// ============================================================================\n// Feature gate + helpers\n// ============================================================================\n\nfunction assertChannelsAvailable(): void {\n if (!coreFeatures.has('channels')) {\n throw new HTTPException(501, { message: 'Channels require a newer version of @mastra/core' });\n }\n}\n\nfunction getChannelOrThrow(mastra: Mastra, platform: string): ChannelProvider {\n const channels = Object.values(mastra.channels ?? {});\n const channel = channels.find(c => c.id === platform);\n if (!channel) {\n const available = channels.map(c => c.id).join(', ');\n throw new HTTPException(404, {\n message: `Channel \"${platform}\" is not registered. Available: ${available || 'none'}`,\n });\n }\n return channel;\n}\n\n/**\n * Unified connect/disconnect authorization.\n *\n * - Stored agent exists → same write access as editing the agent record.\n * - Code-defined agent (no stored record) → route's `requiresAuth` is the gate.\n * - Agent doesn't exist anywhere:\n * - connect → 404 (can't connect a channel to a non-existent agent)\n * - disconnect → orphan cleanup, gated on `channels:write`\n */\nasync function assertChannelAgentWriteAccess(\n mastra: Mastra,\n requestContext: RequestContext,\n agentId: string,\n action: 'connect' | 'disconnect',\n): Promise<void> {\n const storage = mastra.getStorage();\n const agentsStore = storage ? await storage.getStore('agents') : null;\n const stored = agentsStore ? await agentsStore.getById(agentId) : null;\n\n if (stored) {\n assertWriteAccess({\n requestContext,\n resource: 'agents',\n resourceId: agentId,\n action: 'edit',\n record: stored,\n });\n return;\n }\n\n // Not in stored-agents (or storage doesn't support it). Check the runtime\n // registry for a code-defined agent.\n const codeDefined = mastra.getAgentById(agentId);\n if (codeDefined) {\n // Code-defined agents have no owner/ACL — route's requiresAuth /\n // requiresPermission is the gate. Pass-through.\n return;\n }\n\n if (action === 'connect') {\n throw new HTTPException(404, { message: `Agent \"${agentId}\" not found` });\n }\n\n // Disconnect against an unknown agentId = orphan cleanup (stored agent was\n // deleted but the channel installation row is still around). Allow it, but\n // gate on channels:write so this isn't an \"any authenticated user\" backdoor.\n // Follow the same no-auth-configured pass-through as assertWriteAccess.\n const callerAuthorId = getCallerAuthorId(requestContext);\n if (!callerAuthorId && !requestContext.get(MASTRA_USER_KEY)) return;\n if (hasAdminBypass(requestContext, 'channels')) return;\n if (hasScopedPermission({ requestContext, resource: 'channels', action: 'write' })) return;\n\n throw new HTTPException(404, { message: 'Not found' });\n}\n\n// ============================================================================\n// Route Definitions\n// ============================================================================\n\n/**\n * GET /channels/platforms - List available channel platforms\n */\nexport const LIST_CHANNEL_PLATFORMS_ROUTE = createRoute({\n method: 'GET',\n path: '/channels/platforms',\n responseType: 'json',\n responseSchema: listChannelPlatformsResponseSchema,\n summary: 'List channel platforms',\n description: 'Returns available channel platforms and their configuration status',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra }) => {\n assertChannelsAvailable();\n try {\n const channels = Object.values(mastra.channels ?? {});\n return channels.map(channel => {\n if (channel.getInfo) {\n return channel.getInfo();\n }\n return {\n id: channel.id,\n name: channel.id.charAt(0).toUpperCase() + channel.id.slice(1),\n isConfigured: true,\n };\n });\n } catch (error) {\n return handleError(error, 'Error listing channel platforms');\n }\n },\n});\n\n/**\n * GET /channels/:platform/installations - List installations for a platform\n */\nexport const LIST_CHANNEL_INSTALLATIONS_ROUTE = createRoute({\n method: 'GET',\n path: '/channels/:platform/installations',\n responseType: 'json',\n pathParamSchema: channelPlatformPathParams,\n responseSchema: listChannelInstallationsResponseSchema,\n summary: 'List channel installations',\n description: 'Returns all active and pending installations for a channel platform',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra, platform }) => {\n assertChannelsAvailable();\n try {\n const channel = getChannelOrThrow(mastra, platform);\n\n if (!channel.listInstallations) {\n return [];\n }\n\n return await channel.listInstallations();\n } catch (error) {\n return handleError(error, 'Error listing channel installations');\n }\n },\n});\n\n/**\n * POST /channels/:platform/connect - Connect an agent to a platform\n */\nexport const CONNECT_CHANNEL_ROUTE = createRoute({\n method: 'POST',\n path: '/channels/:platform/connect',\n responseType: 'json',\n pathParamSchema: channelPlatformPathParams,\n bodySchema: connectChannelBodySchema,\n responseSchema: connectChannelResponseSchema,\n summary: 'Connect agent to channel',\n description: 'Creates a platform app for the agent and returns an OAuth authorization URL',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra, requestContext, platform, agentId, options }) => {\n assertChannelsAvailable();\n try {\n const channel = getChannelOrThrow(mastra, platform);\n\n if (!channel.connect) {\n throw new HTTPException(400, {\n message: `Channel \"${platform}\" does not support programmatic connection`,\n });\n }\n\n await assertChannelAgentWriteAccess(mastra, requestContext, agentId, 'connect');\n\n return await channel.connect(agentId, options);\n } catch (error) {\n return handleError(error, 'Error connecting agent to channel');\n }\n },\n});\n\n/**\n * POST /channels/:platform/:agentId/disconnect - Disconnect an agent from a platform\n */\nexport const DISCONNECT_CHANNEL_ROUTE = createRoute({\n method: 'POST',\n path: '/channels/:platform/:agentId/disconnect',\n responseType: 'json',\n pathParamSchema: channelAgentPathParams,\n responseSchema: disconnectChannelResponseSchema,\n summary: 'Disconnect agent from channel',\n description: 'Deletes the platform app and cleans up the installation',\n tags: ['Channels'],\n requiresAuth: true,\n handler: async ({ mastra, requestContext, platform, agentId }) => {\n assertChannelsAvailable();\n try {\n const channel = getChannelOrThrow(mastra, platform);\n\n if (!channel.disconnect) {\n throw new HTTPException(400, {\n message: `Channel \"${platform}\" does not support programmatic disconnection`,\n });\n }\n\n await assertChannelAgentWriteAccess(mastra, requestContext, agentId, 'disconnect');\n\n await channel.disconnect(agentId);\n return { success: true };\n } catch (error) {\n return handleError(error, 'Error disconnecting agent from channel');\n }\n },\n});\n"],"mappings":";;;;;;;;AAMA,MAAa,4BAA4B,EAAE,OAAO,EAChD,UAAU,EAAE,OAAO,CAAC,CAAC,SAAS,+CAA6C,EAC7E,CAAC;AAED,MAAa,yBAAyB,EAAE,OAAO;CAC7C,UAAU,EAAE,OAAO,CAAC,CAAC,SAAS,+CAA6C;CAC3E,SAAS,EAAE,OAAO,CAAC,CAAC,SAAS,kBAAkB;AACjD,CAAC;AAMD,MAAa,2BAA2B,EAAE,OAAO;CAC/C,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