@agent-native/core 0.98.17 → 0.99.1

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 (583) hide show
  1. package/corpus/README.md +2 -2
  2. package/corpus/core/CHANGELOG.md +25 -0
  3. package/corpus/core/docs/content/actions.mdx +1 -1
  4. package/corpus/core/docs/content/authentication.mdx +1 -1
  5. package/corpus/core/docs/content/dispatch.mdx +3 -3
  6. package/corpus/core/docs/content/external-agents.mdx +30 -19
  7. package/corpus/core/docs/content/locales/ar-SA/actions.mdx +1 -1
  8. package/corpus/core/docs/content/locales/ar-SA/authentication.mdx +1 -1
  9. package/corpus/core/docs/content/locales/ar-SA/dispatch.mdx +3 -3
  10. package/corpus/core/docs/content/locales/ar-SA/external-agents.mdx +23 -19
  11. package/corpus/core/docs/content/locales/ar-SA/mcp-clients.mdx +31 -3
  12. package/corpus/core/docs/content/locales/ar-SA/mcp-protocol.mdx +29 -15
  13. package/corpus/core/docs/content/locales/ar-SA/plan-plugin.mdx +3 -3
  14. package/corpus/core/docs/content/locales/ar-SA/server.mdx +2 -2
  15. package/corpus/core/docs/content/locales/ar-SA/skills-guide.mdx +1 -1
  16. package/corpus/core/docs/content/locales/ar-SA/template-assets.mdx +1 -1
  17. package/corpus/core/docs/content/locales/ar-SA/template-dispatch.mdx +2 -2
  18. package/corpus/core/docs/content/locales/ar-SA/template-plan.mdx +3 -3
  19. package/corpus/core/docs/content/locales/de-DE/actions.mdx +1 -1
  20. package/corpus/core/docs/content/locales/de-DE/authentication.mdx +1 -1
  21. package/corpus/core/docs/content/locales/de-DE/dispatch.mdx +3 -3
  22. package/corpus/core/docs/content/locales/de-DE/external-agents.mdx +23 -19
  23. package/corpus/core/docs/content/locales/de-DE/mcp-clients.mdx +37 -3
  24. package/corpus/core/docs/content/locales/de-DE/mcp-protocol.mdx +29 -15
  25. package/corpus/core/docs/content/locales/de-DE/plan-plugin.mdx +3 -3
  26. package/corpus/core/docs/content/locales/de-DE/server.mdx +2 -2
  27. package/corpus/core/docs/content/locales/de-DE/skills-guide.mdx +1 -1
  28. package/corpus/core/docs/content/locales/de-DE/template-assets.mdx +1 -1
  29. package/corpus/core/docs/content/locales/de-DE/template-dispatch.mdx +2 -2
  30. package/corpus/core/docs/content/locales/de-DE/template-plan.mdx +3 -3
  31. package/corpus/core/docs/content/locales/es-ES/actions.mdx +1 -1
  32. package/corpus/core/docs/content/locales/es-ES/authentication.mdx +1 -1
  33. package/corpus/core/docs/content/locales/es-ES/dispatch.mdx +3 -3
  34. package/corpus/core/docs/content/locales/es-ES/external-agents.mdx +32 -19
  35. package/corpus/core/docs/content/locales/es-ES/mcp-clients.mdx +17 -3
  36. package/corpus/core/docs/content/locales/es-ES/mcp-protocol.mdx +38 -15
  37. package/corpus/core/docs/content/locales/es-ES/plan-plugin.mdx +3 -3
  38. package/corpus/core/docs/content/locales/es-ES/server.mdx +2 -2
  39. package/corpus/core/docs/content/locales/es-ES/skills-guide.mdx +1 -1
  40. package/corpus/core/docs/content/locales/es-ES/template-assets.mdx +1 -1
  41. package/corpus/core/docs/content/locales/es-ES/template-dispatch.mdx +2 -2
  42. package/corpus/core/docs/content/locales/es-ES/template-plan.mdx +3 -3
  43. package/corpus/core/docs/content/locales/fr-FR/actions.mdx +1 -1
  44. package/corpus/core/docs/content/locales/fr-FR/authentication.mdx +1 -1
  45. package/corpus/core/docs/content/locales/fr-FR/dispatch.mdx +3 -3
  46. package/corpus/core/docs/content/locales/fr-FR/external-agents.mdx +23 -19
  47. package/corpus/core/docs/content/locales/fr-FR/mcp-clients.mdx +17 -3
  48. package/corpus/core/docs/content/locales/fr-FR/mcp-protocol.mdx +29 -15
  49. package/corpus/core/docs/content/locales/fr-FR/plan-plugin.mdx +3 -3
  50. package/corpus/core/docs/content/locales/fr-FR/server.mdx +2 -2
  51. package/corpus/core/docs/content/locales/fr-FR/skills-guide.mdx +1 -1
  52. package/corpus/core/docs/content/locales/fr-FR/template-assets.mdx +1 -1
  53. package/corpus/core/docs/content/locales/fr-FR/template-dispatch.mdx +2 -2
  54. package/corpus/core/docs/content/locales/fr-FR/template-plan.mdx +3 -3
  55. package/corpus/core/docs/content/locales/hi-IN/actions.mdx +1 -1
  56. package/corpus/core/docs/content/locales/hi-IN/authentication.mdx +1 -1
  57. package/corpus/core/docs/content/locales/hi-IN/dispatch.mdx +3 -3
  58. package/corpus/core/docs/content/locales/hi-IN/external-agents.mdx +31 -19
  59. package/corpus/core/docs/content/locales/hi-IN/mcp-clients.mdx +17 -3
  60. package/corpus/core/docs/content/locales/hi-IN/mcp-protocol.mdx +36 -15
  61. package/corpus/core/docs/content/locales/hi-IN/plan-plugin.mdx +3 -3
  62. package/corpus/core/docs/content/locales/hi-IN/server.mdx +2 -2
  63. package/corpus/core/docs/content/locales/hi-IN/skills-guide.mdx +1 -1
  64. package/corpus/core/docs/content/locales/hi-IN/template-assets.mdx +1 -1
  65. package/corpus/core/docs/content/locales/hi-IN/template-dispatch.mdx +2 -2
  66. package/corpus/core/docs/content/locales/hi-IN/template-plan.mdx +3 -3
  67. package/corpus/core/docs/content/locales/ja-JP/actions.mdx +1 -1
  68. package/corpus/core/docs/content/locales/ja-JP/authentication.mdx +1 -1
  69. package/corpus/core/docs/content/locales/ja-JP/dispatch.mdx +3 -3
  70. package/corpus/core/docs/content/locales/ja-JP/external-agents.mdx +23 -19
  71. package/corpus/core/docs/content/locales/ja-JP/mcp-clients.mdx +34 -3
  72. package/corpus/core/docs/content/locales/ja-JP/mcp-protocol.mdx +29 -15
  73. package/corpus/core/docs/content/locales/ja-JP/plan-plugin.mdx +3 -3
  74. package/corpus/core/docs/content/locales/ja-JP/server.mdx +2 -2
  75. package/corpus/core/docs/content/locales/ja-JP/skills-guide.mdx +1 -1
  76. package/corpus/core/docs/content/locales/ja-JP/template-assets.mdx +1 -1
  77. package/corpus/core/docs/content/locales/ja-JP/template-dispatch.mdx +2 -2
  78. package/corpus/core/docs/content/locales/ja-JP/template-plan.mdx +3 -3
  79. package/corpus/core/docs/content/locales/ko-KR/actions.mdx +1 -1
  80. package/corpus/core/docs/content/locales/ko-KR/authentication.mdx +1 -1
  81. package/corpus/core/docs/content/locales/ko-KR/dispatch.mdx +3 -3
  82. package/corpus/core/docs/content/locales/ko-KR/external-agents.mdx +30 -19
  83. package/corpus/core/docs/content/locales/ko-KR/mcp-clients.mdx +33 -3
  84. package/corpus/core/docs/content/locales/ko-KR/mcp-protocol.mdx +36 -15
  85. package/corpus/core/docs/content/locales/ko-KR/plan-plugin.mdx +3 -3
  86. package/corpus/core/docs/content/locales/ko-KR/server.mdx +2 -2
  87. package/corpus/core/docs/content/locales/ko-KR/skills-guide.mdx +1 -1
  88. package/corpus/core/docs/content/locales/ko-KR/template-assets.mdx +1 -1
  89. package/corpus/core/docs/content/locales/ko-KR/template-dispatch.mdx +2 -2
  90. package/corpus/core/docs/content/locales/ko-KR/template-plan.mdx +3 -3
  91. package/corpus/core/docs/content/locales/pt-BR/actions.mdx +1 -1
  92. package/corpus/core/docs/content/locales/pt-BR/authentication.mdx +1 -1
  93. package/corpus/core/docs/content/locales/pt-BR/dispatch.mdx +3 -3
  94. package/corpus/core/docs/content/locales/pt-BR/external-agents.mdx +32 -19
  95. package/corpus/core/docs/content/locales/pt-BR/mcp-clients.mdx +34 -3
  96. package/corpus/core/docs/content/locales/pt-BR/mcp-protocol.mdx +32 -15
  97. package/corpus/core/docs/content/locales/pt-BR/plan-plugin.mdx +3 -3
  98. package/corpus/core/docs/content/locales/pt-BR/server.mdx +2 -2
  99. package/corpus/core/docs/content/locales/pt-BR/skills-guide.mdx +1 -1
  100. package/corpus/core/docs/content/locales/pt-BR/template-assets.mdx +1 -1
  101. package/corpus/core/docs/content/locales/pt-BR/template-dispatch.mdx +2 -2
  102. package/corpus/core/docs/content/locales/pt-BR/template-plan.mdx +3 -3
  103. package/corpus/core/docs/content/locales/zh-CN/actions.mdx +1 -1
  104. package/corpus/core/docs/content/locales/zh-CN/authentication.mdx +1 -1
  105. package/corpus/core/docs/content/locales/zh-CN/dispatch.mdx +3 -3
  106. package/corpus/core/docs/content/locales/zh-CN/external-agents.mdx +23 -19
  107. package/corpus/core/docs/content/locales/zh-CN/mcp-clients.mdx +28 -3
  108. package/corpus/core/docs/content/locales/zh-CN/mcp-protocol.mdx +29 -15
  109. package/corpus/core/docs/content/locales/zh-CN/plan-plugin.mdx +3 -3
  110. package/corpus/core/docs/content/locales/zh-CN/server.mdx +2 -2
  111. package/corpus/core/docs/content/locales/zh-CN/skills-guide.mdx +1 -1
  112. package/corpus/core/docs/content/locales/zh-CN/template-assets.mdx +1 -1
  113. package/corpus/core/docs/content/locales/zh-CN/template-dispatch.mdx +2 -2
  114. package/corpus/core/docs/content/locales/zh-CN/template-plan.mdx +3 -3
  115. package/corpus/core/docs/content/locales/zh-TW/actions.mdx +1 -1
  116. package/corpus/core/docs/content/locales/zh-TW/authentication.mdx +1 -1
  117. package/corpus/core/docs/content/locales/zh-TW/dispatch.mdx +3 -3
  118. package/corpus/core/docs/content/locales/zh-TW/external-agents.mdx +23 -19
  119. package/corpus/core/docs/content/locales/zh-TW/mcp-clients.mdx +28 -3
  120. package/corpus/core/docs/content/locales/zh-TW/mcp-protocol.mdx +30 -15
  121. package/corpus/core/docs/content/locales/zh-TW/plan-plugin.mdx +3 -3
  122. package/corpus/core/docs/content/locales/zh-TW/server.mdx +2 -2
  123. package/corpus/core/docs/content/locales/zh-TW/skills-guide.mdx +1 -1
  124. package/corpus/core/docs/content/locales/zh-TW/template-assets.mdx +1 -1
  125. package/corpus/core/docs/content/locales/zh-TW/template-dispatch.mdx +2 -2
  126. package/corpus/core/docs/content/locales/zh-TW/template-plan.mdx +3 -3
  127. package/corpus/core/docs/content/mcp-clients.mdx +31 -4
  128. package/corpus/core/docs/content/mcp-protocol.mdx +35 -15
  129. package/corpus/core/docs/content/plan-plugin.mdx +3 -3
  130. package/corpus/core/docs/content/server.mdx +2 -2
  131. package/corpus/core/docs/content/skills-guide.mdx +1 -1
  132. package/corpus/core/docs/content/template-assets.mdx +1 -1
  133. package/corpus/core/docs/content/template-dispatch.mdx +2 -2
  134. package/corpus/core/docs/content/template-plan.mdx +3 -3
  135. package/corpus/core/package.json +1 -1
  136. package/corpus/core/src/a2a/client.ts +3 -0
  137. package/corpus/core/src/a2a/handlers.ts +95 -7
  138. package/corpus/core/src/agent/production-agent.ts +21 -0
  139. package/corpus/core/src/cli/connect.ts +50 -24
  140. package/corpus/core/src/cli/mcp-config-writers.ts +10 -0
  141. package/corpus/core/src/cli/mcp.ts +5 -5
  142. package/corpus/core/src/cli/pr-visual-recap-workflow.ts +1 -1
  143. package/corpus/core/src/cli/skills-content/assets-skill.ts +1 -1
  144. package/corpus/core/src/cli/skills-content/design-exploration-skill.ts +1 -1
  145. package/corpus/core/src/cli/skills-content/help.ts +1 -1
  146. package/corpus/core/src/cli/skills-content/plan-setup-auth.ts +1 -1
  147. package/corpus/core/src/cli/skills-content/visual-plan-skill.ts +1 -1
  148. package/corpus/core/src/cli/skills-content/visual-recap-skill.ts +2 -2
  149. package/corpus/core/src/cli/skills.ts +23 -12
  150. package/corpus/core/src/client/analytics.ts +13 -0
  151. package/corpus/core/src/client/resources/McpIntegrationDialog.tsx +5 -0
  152. package/corpus/core/src/client/resources/mcp-integration-catalog.ts +17 -0
  153. package/corpus/core/src/embedding/agent.ts +8 -6
  154. package/corpus/core/src/localization/default-messages.ts +7 -0
  155. package/corpus/core/src/mcp/ask-app-inline-tasks.ts +125 -0
  156. package/corpus/core/src/mcp/build-server.ts +65 -3
  157. package/corpus/core/src/mcp/builtin-tools.ts +186 -22
  158. package/corpus/core/src/mcp/connect-route.ts +17 -14
  159. package/corpus/core/src/mcp/oauth-route.ts +38 -13
  160. package/corpus/core/src/mcp/route-paths.ts +34 -0
  161. package/corpus/core/src/mcp/server.ts +21 -10
  162. package/corpus/core/src/mcp/stdio.ts +34 -16
  163. package/corpus/core/src/mcp/workspace-resolve.ts +2 -1
  164. package/corpus/core/src/mcp-client/manager.ts +5 -3
  165. package/corpus/core/src/mcp-client/remote-store.ts +10 -10
  166. package/corpus/core/src/server/agent-chat/action-filters-a2a.ts +13 -0
  167. package/corpus/core/src/server/agent-chat-plugin.ts +42 -9
  168. package/corpus/core/src/server/agent-teams.ts +17 -0
  169. package/corpus/core/src/server/auth.ts +22 -6
  170. package/corpus/core/src/server/core-routes-plugin.ts +30 -24
  171. package/corpus/core/src/server/csrf.ts +17 -0
  172. package/corpus/core/src/server/framework-request-handler.ts +8 -2
  173. package/corpus/core/src/server/google-oauth.ts +12 -2
  174. package/corpus/core/src/server/http-response-telemetry.ts +6 -1
  175. package/corpus/core/src/server/recap-image-route.ts +3 -3
  176. package/corpus/core/src/server/security-headers.ts +7 -1
  177. package/corpus/core/src/server/ssr-handler.ts +2 -0
  178. package/corpus/core/src/shared/cache-control.ts +6 -4
  179. package/corpus/core/src/templates/default/.agents/skills/security/SKILL.md +10 -0
  180. package/corpus/core/src/templates/workspace-core/.agents/skills/authentication/SKILL.md +15 -6
  181. package/corpus/core/src/templates/workspace-core/.agents/skills/external-agents/SKILL.md +16 -10
  182. package/corpus/core/src/templates/workspace-core/.agents/skills/performance/SKILL.md +20 -1
  183. package/corpus/core/src/templates/workspace-core/.agents/skills/security/SKILL.md +10 -0
  184. package/corpus/templates/analytics/.agents/skills/security/SKILL.md +10 -0
  185. package/corpus/templates/analytics/app/assets/replay-cursor.svg +17 -0
  186. package/corpus/templates/analytics/app/components/dashboard/SqlChart.tsx +4 -3
  187. package/corpus/templates/analytics/app/global.css +71 -4
  188. package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/DashboardFilterBar.tsx +32 -4
  189. package/corpus/templates/analytics/app/pages/monitoring/errors/IssueDetail.tsx +1 -1
  190. package/corpus/templates/analytics/app/pages/sessions/SessionDetailPage.tsx +49 -11
  191. package/corpus/templates/analytics/app/pages/sessions/SessionsPage.tsx +4 -6
  192. package/corpus/templates/analytics/changelog/2026-07-13-all-time-dashboard-filters-no-longer-send-invalid-dates-to-b.md +6 -0
  193. package/corpus/templates/analytics/changelog/2026-07-13-daily-dashboard-emails-recover-more-reliably-from-serverless.md +6 -0
  194. package/corpus/templates/analytics/changelog/2026-07-13-error-issue-titles-wrap-instead-of-overflowing.md +6 -0
  195. package/corpus/templates/analytics/changelog/2026-07-13-saving-a-new-dashboard-view-no-longer-fails-with-a-server-er.md +6 -0
  196. package/corpus/templates/analytics/changelog/2026-07-13-session-replay-cursors-stay-hidden-until-their-first-recorde.md +6 -0
  197. package/corpus/templates/analytics/changelog/2026-07-13-session-replay-links-now-support-cmd-click-and-middle-click-.md +6 -0
  198. package/corpus/templates/analytics/changelog/2026-07-13-session-replays-keep-a-visible-mac-style-cursor-over-the-vis.md +6 -0
  199. package/corpus/templates/analytics/server/jobs/dashboard-report.ts +21 -2
  200. package/corpus/templates/analytics/server/lib/dashboard-report-subscriptions.ts +57 -1
  201. package/corpus/templates/analytics/server/lib/dashboard-report.ts +266 -28
  202. package/corpus/templates/analytics/server/lib/dashboards-store.ts +43 -4
  203. package/corpus/templates/analytics/server/lib/error-capture.ts +24 -5
  204. package/corpus/templates/analytics/server/plugins/agent-chat.ts +5 -0
  205. package/corpus/templates/analytics/server/routes/[...page].get.ts +0 -2
  206. package/corpus/templates/assets/.agents/skills/security/SKILL.md +10 -0
  207. package/corpus/templates/assets/agent-native.app-skill.json +1 -1
  208. package/corpus/templates/brain/.agents/skills/security/SKILL.md +10 -0
  209. package/corpus/templates/calendar/.agents/skills/security/SKILL.md +10 -0
  210. package/corpus/templates/calendar/AGENTS.md +2 -1
  211. package/corpus/templates/calendar/app/components/calendar/EventDetailPopover.tsx +0 -19
  212. package/corpus/templates/calendar/app/lib/attendee-local-time.ts +14 -5
  213. package/corpus/templates/calendar/changelog/2026-07-13-your-local-time-now-follows-your-browser-timezone-and-event-.md +6 -0
  214. package/corpus/templates/chat/.agents/skills/security/SKILL.md +10 -0
  215. package/corpus/templates/clips/.agents/skills/recording/SKILL.md +7 -2
  216. package/corpus/templates/clips/.agents/skills/security/SKILL.md +10 -0
  217. package/corpus/templates/clips/AGENTS.md +7 -0
  218. package/corpus/templates/clips/actions/list-meetings.ts +19 -4
  219. package/corpus/templates/clips/actions/start-meeting-recording.ts +7 -1
  220. package/corpus/templates/clips/app/components/library/recording-card.tsx +27 -26
  221. package/corpus/templates/clips/app/components/library/space-card.tsx +4 -6
  222. package/corpus/templates/clips/app/components/meetings/transcript-bubbles.tsx +75 -78
  223. package/corpus/templates/clips/app/components/recorder/confetti-canvas.tsx +18 -1
  224. package/corpus/templates/clips/app/components/recorder/recorder-engine.ts +6 -12
  225. package/corpus/templates/clips/app/components/recorder/recording-toolbar.tsx +19 -2
  226. package/corpus/templates/clips/app/lib/camera-composite.ts +70 -10
  227. package/corpus/templates/clips/app/routes/_app.meetings.$meetingId.tsx +1 -1
  228. package/corpus/templates/clips/app/routes/record.tsx +5 -25
  229. package/corpus/templates/clips/changelog/2026-07-13-clips-desktop-now-requires-macos-13-for-native-capture.md +6 -0
  230. package/corpus/templates/clips/changelog/2026-07-13-clips-hide-solo-meeting-reminders.md +6 -0
  231. package/corpus/templates/clips/changelog/2026-07-13-clips-now-removes-duplicate-mic-and-system-transcript-turns-.md +6 -0
  232. package/corpus/templates/clips/changelog/2026-07-13-desktop-recordings-run-cooler-and-quieter-live-transcription.md +6 -0
  233. package/corpus/templates/clips/changelog/2026-07-13-meeting-recordings-now-stop-after-a-calendar-meeting-ends-an.md +6 -0
  234. package/corpus/templates/clips/changelog/2026-07-13-meeting-transcripts-now-use-a-clean-agent-chat-style-reading.md +6 -0
  235. package/corpus/templates/clips/changelog/2026-07-13-screen-recordings-use-less-processing-power-during-longer-ca.md +6 -0
  236. package/corpus/templates/clips/chrome-extension/src/background.ts +5 -3
  237. package/corpus/templates/clips/chrome-extension/src/offscreen.ts +17 -14
  238. package/corpus/templates/clips/chrome-extension/src/overlay.ts +8 -2
  239. package/corpus/templates/clips/desktop/README.md +3 -0
  240. package/corpus/templates/clips/desktop/src/hooks/useMeetingTranscription.ts +9 -0
  241. package/corpus/templates/clips/desktop/src/lib/recorder.ts +8 -2
  242. package/corpus/templates/clips/desktop/src/lib/silence-events.ts +1 -0
  243. package/corpus/templates/clips/desktop/src/lib/transcription-capture.ts +5 -0
  244. package/corpus/templates/clips/desktop/src/lib/transcription-engine.ts +134 -5
  245. package/corpus/templates/clips/desktop/src/lib/upload-video-stream.ts +28 -0
  246. package/corpus/templates/clips/desktop/src/overlays/flow-bar.tsx +10 -3
  247. package/corpus/templates/clips/desktop/src/overlays/meeting-notification.tsx +42 -9
  248. package/corpus/templates/clips/desktop/src/overlays/recording-pill.tsx +10 -2
  249. package/corpus/templates/clips/desktop/src-tauri/Cargo.toml +6 -1
  250. package/corpus/templates/clips/desktop/src-tauri/src/notifications.rs +77 -1
  251. package/corpus/templates/clips/desktop/src-tauri/src/silence_detector.rs +104 -25
  252. package/corpus/templates/clips/desktop/src-tauri/src/system_audio.rs +4 -0
  253. package/corpus/templates/clips/desktop/src-tauri/src/whisper_speech.rs +287 -32
  254. package/corpus/templates/clips/desktop/src-tauri/tauri.conf.json +1 -1
  255. package/corpus/templates/clips/server/lib/calendar-event-classification.ts +28 -0
  256. package/corpus/templates/clips/server/routes/[...page].get.ts +1 -59
  257. package/corpus/templates/clips/shared/recording-capture.ts +37 -0
  258. package/corpus/templates/content/.agents/skills/security/SKILL.md +10 -0
  259. package/corpus/templates/content/agent-native.app-skill.json +1 -1
  260. package/corpus/templates/content/app/components/sidebar/DocumentSidebar.tsx +18 -16
  261. package/corpus/templates/content/server/routes/[...page].get.ts +1 -15
  262. package/corpus/templates/design/.agents/skills/security/SKILL.md +10 -0
  263. package/corpus/templates/design/actions/connect-assets-mcp.ts +1 -1
  264. package/corpus/templates/design/agent-native.app-skill.json +1 -1
  265. package/corpus/templates/design/app/components/design/DesignCanvas.tsx +88 -12
  266. package/corpus/templates/design/app/components/design/MultiScreenCanvas.tsx +1 -0
  267. package/corpus/templates/design/app/components/design/bridge/editor-chrome.bridge.ts +4 -1
  268. package/corpus/templates/design/changelog/2026-07-13-adding-shapes-preserves-canvas-background.md +6 -0
  269. package/corpus/templates/design/changelog/2026-07-13-clicking-quickly-between-overlapping-elements-no-longer-bounc.md +6 -0
  270. package/corpus/templates/design/server/plugins/assets-mcp.ts +1 -1
  271. package/corpus/templates/design/server/routes/[...page].get.ts +0 -2
  272. package/corpus/templates/dispatch/.agents/skills/security/SKILL.md +10 -0
  273. package/corpus/templates/forms/.agents/skills/security/SKILL.md +10 -0
  274. package/corpus/templates/macros/.agents/skills/security/SKILL.md +10 -0
  275. package/corpus/templates/mail/.agents/skills/security/SKILL.md +10 -0
  276. package/corpus/templates/plan/.agents/skills/security/SKILL.md +10 -0
  277. package/corpus/templates/plan/.agents/skills/visual-plan/SKILL.md +1 -1
  278. package/corpus/templates/plan/.agents/skills/visual-recap/SKILL.md +2 -2
  279. package/corpus/templates/plan/agent-native.app-skill.json +1 -1
  280. package/corpus/templates/plan/app/lib/plan-local-bridge.ts +6 -1
  281. package/corpus/templates/plan/app/pages/PlansPage.tsx +15 -6
  282. package/corpus/templates/plan/changelog/2026-07-13-fixed-local-plan-previews-continuously-flickering-while-revi.md +6 -0
  283. package/corpus/templates/plan/server/routes/[...page].get.ts +0 -2
  284. package/corpus/templates/slides/.agents/skills/security/SKILL.md +10 -0
  285. package/dist/a2a/client.d.ts +2 -0
  286. package/dist/a2a/client.d.ts.map +1 -1
  287. package/dist/a2a/client.js +2 -0
  288. package/dist/a2a/client.js.map +1 -1
  289. package/dist/a2a/handlers.d.ts.map +1 -1
  290. package/dist/a2a/handlers.js +84 -7
  291. package/dist/a2a/handlers.js.map +1 -1
  292. package/dist/agent/production-agent.d.ts +9 -0
  293. package/dist/agent/production-agent.d.ts.map +1 -1
  294. package/dist/agent/production-agent.js +12 -0
  295. package/dist/agent/production-agent.js.map +1 -1
  296. package/dist/cli/connect.d.ts +2 -2
  297. package/dist/cli/connect.d.ts.map +1 -1
  298. package/dist/cli/connect.js +45 -23
  299. package/dist/cli/connect.js.map +1 -1
  300. package/dist/cli/mcp-config-writers.d.ts.map +1 -1
  301. package/dist/cli/mcp-config-writers.js +7 -0
  302. package/dist/cli/mcp-config-writers.js.map +1 -1
  303. package/dist/cli/mcp.js +5 -3
  304. package/dist/cli/mcp.js.map +1 -1
  305. package/dist/cli/pr-visual-recap-workflow.d.ts +1 -1
  306. package/dist/cli/pr-visual-recap-workflow.d.ts.map +1 -1
  307. package/dist/cli/pr-visual-recap-workflow.js +1 -1
  308. package/dist/cli/pr-visual-recap-workflow.js.map +1 -1
  309. package/dist/cli/skills-content/assets-skill.d.ts +1 -1
  310. package/dist/cli/skills-content/assets-skill.d.ts.map +1 -1
  311. package/dist/cli/skills-content/assets-skill.js +1 -1
  312. package/dist/cli/skills-content/assets-skill.js.map +1 -1
  313. package/dist/cli/skills-content/design-exploration-skill.d.ts +1 -1
  314. package/dist/cli/skills-content/design-exploration-skill.d.ts.map +1 -1
  315. package/dist/cli/skills-content/design-exploration-skill.js +1 -1
  316. package/dist/cli/skills-content/design-exploration-skill.js.map +1 -1
  317. package/dist/cli/skills-content/help.d.ts +1 -1
  318. package/dist/cli/skills-content/help.d.ts.map +1 -1
  319. package/dist/cli/skills-content/help.js +1 -1
  320. package/dist/cli/skills-content/help.js.map +1 -1
  321. package/dist/cli/skills-content/plan-setup-auth.d.ts +1 -1
  322. package/dist/cli/skills-content/plan-setup-auth.d.ts.map +1 -1
  323. package/dist/cli/skills-content/plan-setup-auth.js +1 -1
  324. package/dist/cli/skills-content/plan-setup-auth.js.map +1 -1
  325. package/dist/cli/skills-content/visual-plan-skill.d.ts +1 -1
  326. package/dist/cli/skills-content/visual-plan-skill.d.ts.map +1 -1
  327. package/dist/cli/skills-content/visual-plan-skill.js +1 -1
  328. package/dist/cli/skills-content/visual-plan-skill.js.map +1 -1
  329. package/dist/cli/skills-content/visual-recap-skill.d.ts +1 -1
  330. package/dist/cli/skills-content/visual-recap-skill.d.ts.map +1 -1
  331. package/dist/cli/skills-content/visual-recap-skill.js +2 -2
  332. package/dist/cli/skills-content/visual-recap-skill.js.map +1 -1
  333. package/dist/cli/skills.d.ts.map +1 -1
  334. package/dist/cli/skills.js +16 -12
  335. package/dist/cli/skills.js.map +1 -1
  336. package/dist/client/analytics.d.ts.map +1 -1
  337. package/dist/client/analytics.js +11 -0
  338. package/dist/client/analytics.js.map +1 -1
  339. package/dist/client/resources/McpIntegrationDialog.d.ts.map +1 -1
  340. package/dist/client/resources/McpIntegrationDialog.js +1 -1
  341. package/dist/client/resources/McpIntegrationDialog.js.map +1 -1
  342. package/dist/client/resources/mcp-integration-catalog.d.ts +1 -0
  343. package/dist/client/resources/mcp-integration-catalog.d.ts.map +1 -1
  344. package/dist/client/resources/mcp-integration-catalog.js +14 -0
  345. package/dist/client/resources/mcp-integration-catalog.js.map +1 -1
  346. package/dist/collab/awareness.d.ts +2 -2
  347. package/dist/collab/awareness.d.ts.map +1 -1
  348. package/dist/collab/routes.d.ts +1 -1
  349. package/dist/collab/struct-routes.d.ts +1 -1
  350. package/dist/embedding/agent.d.ts.map +1 -1
  351. package/dist/embedding/agent.js +6 -7
  352. package/dist/embedding/agent.js.map +1 -1
  353. package/dist/localization/default-messages.d.ts +5 -0
  354. package/dist/localization/default-messages.d.ts.map +1 -1
  355. package/dist/localization/default-messages.js +5 -0
  356. package/dist/localization/default-messages.js.map +1 -1
  357. package/dist/mcp/ask-app-inline-tasks.d.ts +47 -0
  358. package/dist/mcp/ask-app-inline-tasks.d.ts.map +1 -0
  359. package/dist/mcp/ask-app-inline-tasks.js +87 -0
  360. package/dist/mcp/ask-app-inline-tasks.js.map +1 -0
  361. package/dist/mcp/build-server.d.ts.map +1 -1
  362. package/dist/mcp/build-server.js +56 -3
  363. package/dist/mcp/build-server.js.map +1 -1
  364. package/dist/mcp/builtin-tools.d.ts.map +1 -1
  365. package/dist/mcp/builtin-tools.js +141 -21
  366. package/dist/mcp/builtin-tools.js.map +1 -1
  367. package/dist/mcp/connect-route.d.ts +12 -10
  368. package/dist/mcp/connect-route.d.ts.map +1 -1
  369. package/dist/mcp/connect-route.js +17 -14
  370. package/dist/mcp/connect-route.js.map +1 -1
  371. package/dist/mcp/oauth-route.d.ts +1 -1
  372. package/dist/mcp/oauth-route.d.ts.map +1 -1
  373. package/dist/mcp/oauth-route.js +30 -13
  374. package/dist/mcp/oauth-route.js.map +1 -1
  375. package/dist/mcp/route-paths.d.ts +13 -0
  376. package/dist/mcp/route-paths.d.ts.map +1 -0
  377. package/dist/mcp/route-paths.js +27 -0
  378. package/dist/mcp/route-paths.js.map +1 -0
  379. package/dist/mcp/server.d.ts +2 -1
  380. package/dist/mcp/server.d.ts.map +1 -1
  381. package/dist/mcp/server.js +14 -6
  382. package/dist/mcp/server.js.map +1 -1
  383. package/dist/mcp/stdio.d.ts +7 -6
  384. package/dist/mcp/stdio.d.ts.map +1 -1
  385. package/dist/mcp/stdio.js +27 -15
  386. package/dist/mcp/stdio.js.map +1 -1
  387. package/dist/mcp/workspace-resolve.d.ts +2 -1
  388. package/dist/mcp/workspace-resolve.d.ts.map +1 -1
  389. package/dist/mcp/workspace-resolve.js +2 -1
  390. package/dist/mcp/workspace-resolve.js.map +1 -1
  391. package/dist/mcp-client/manager.js +6 -3
  392. package/dist/mcp-client/manager.js.map +1 -1
  393. package/dist/mcp-client/remote-store.js +5 -7
  394. package/dist/mcp-client/remote-store.js.map +1 -1
  395. package/dist/notifications/routes.d.ts +3 -3
  396. package/dist/progress/routes.d.ts +1 -1
  397. package/dist/provider-api/corpus-jobs.d.ts +2 -2
  398. package/dist/resources/handlers.d.ts +2 -2
  399. package/dist/server/agent-chat/action-filters-a2a.d.ts.map +1 -1
  400. package/dist/server/agent-chat/action-filters-a2a.js +11 -1
  401. package/dist/server/agent-chat/action-filters-a2a.js.map +1 -1
  402. package/dist/server/agent-chat-plugin.d.ts.map +1 -1
  403. package/dist/server/agent-chat-plugin.js +43 -11
  404. package/dist/server/agent-chat-plugin.js.map +1 -1
  405. package/dist/server/agent-engine-api-key-route.d.ts +1 -1
  406. package/dist/server/agent-teams.d.ts.map +1 -1
  407. package/dist/server/agent-teams.js +15 -1
  408. package/dist/server/agent-teams.js.map +1 -1
  409. package/dist/server/auth.d.ts.map +1 -1
  410. package/dist/server/auth.js +16 -6
  411. package/dist/server/auth.js.map +1 -1
  412. package/dist/server/core-routes-plugin.d.ts +4 -3
  413. package/dist/server/core-routes-plugin.d.ts.map +1 -1
  414. package/dist/server/core-routes-plugin.js +20 -15
  415. package/dist/server/core-routes-plugin.js.map +1 -1
  416. package/dist/server/csrf.d.ts.map +1 -1
  417. package/dist/server/csrf.js +11 -0
  418. package/dist/server/csrf.js.map +1 -1
  419. package/dist/server/framework-request-handler.d.ts.map +1 -1
  420. package/dist/server/framework-request-handler.js +8 -2
  421. package/dist/server/framework-request-handler.js.map +1 -1
  422. package/dist/server/google-oauth.d.ts +2 -0
  423. package/dist/server/google-oauth.d.ts.map +1 -1
  424. package/dist/server/google-oauth.js +11 -2
  425. package/dist/server/google-oauth.js.map +1 -1
  426. package/dist/server/http-response-telemetry.d.ts.map +1 -1
  427. package/dist/server/http-response-telemetry.js +4 -1
  428. package/dist/server/http-response-telemetry.js.map +1 -1
  429. package/dist/server/recap-image-route.js +3 -3
  430. package/dist/server/recap-image-route.js.map +1 -1
  431. package/dist/server/security-headers.d.ts.map +1 -1
  432. package/dist/server/security-headers.js +4 -1
  433. package/dist/server/security-headers.js.map +1 -1
  434. package/dist/server/ssr-handler.d.ts.map +1 -1
  435. package/dist/server/ssr-handler.js +3 -1
  436. package/dist/server/ssr-handler.js.map +1 -1
  437. package/dist/shared/cache-control.d.ts +7 -6
  438. package/dist/shared/cache-control.d.ts.map +1 -1
  439. package/dist/shared/cache-control.js +4 -3
  440. package/dist/shared/cache-control.js.map +1 -1
  441. package/dist/templates/default/.agents/skills/security/SKILL.md +10 -0
  442. package/dist/templates/workspace-core/.agents/skills/authentication/SKILL.md +15 -6
  443. package/dist/templates/workspace-core/.agents/skills/external-agents/SKILL.md +16 -10
  444. package/dist/templates/workspace-core/.agents/skills/performance/SKILL.md +20 -1
  445. package/dist/templates/workspace-core/.agents/skills/security/SKILL.md +10 -0
  446. package/docs/content/actions.mdx +1 -1
  447. package/docs/content/authentication.mdx +1 -1
  448. package/docs/content/dispatch.mdx +3 -3
  449. package/docs/content/external-agents.mdx +30 -19
  450. package/docs/content/locales/ar-SA/actions.mdx +1 -1
  451. package/docs/content/locales/ar-SA/authentication.mdx +1 -1
  452. package/docs/content/locales/ar-SA/dispatch.mdx +3 -3
  453. package/docs/content/locales/ar-SA/external-agents.mdx +23 -19
  454. package/docs/content/locales/ar-SA/mcp-clients.mdx +31 -3
  455. package/docs/content/locales/ar-SA/mcp-protocol.mdx +29 -15
  456. package/docs/content/locales/ar-SA/plan-plugin.mdx +3 -3
  457. package/docs/content/locales/ar-SA/server.mdx +2 -2
  458. package/docs/content/locales/ar-SA/skills-guide.mdx +1 -1
  459. package/docs/content/locales/ar-SA/template-assets.mdx +1 -1
  460. package/docs/content/locales/ar-SA/template-dispatch.mdx +2 -2
  461. package/docs/content/locales/ar-SA/template-plan.mdx +3 -3
  462. package/docs/content/locales/de-DE/actions.mdx +1 -1
  463. package/docs/content/locales/de-DE/authentication.mdx +1 -1
  464. package/docs/content/locales/de-DE/dispatch.mdx +3 -3
  465. package/docs/content/locales/de-DE/external-agents.mdx +23 -19
  466. package/docs/content/locales/de-DE/mcp-clients.mdx +37 -3
  467. package/docs/content/locales/de-DE/mcp-protocol.mdx +29 -15
  468. package/docs/content/locales/de-DE/plan-plugin.mdx +3 -3
  469. package/docs/content/locales/de-DE/server.mdx +2 -2
  470. package/docs/content/locales/de-DE/skills-guide.mdx +1 -1
  471. package/docs/content/locales/de-DE/template-assets.mdx +1 -1
  472. package/docs/content/locales/de-DE/template-dispatch.mdx +2 -2
  473. package/docs/content/locales/de-DE/template-plan.mdx +3 -3
  474. package/docs/content/locales/es-ES/actions.mdx +1 -1
  475. package/docs/content/locales/es-ES/authentication.mdx +1 -1
  476. package/docs/content/locales/es-ES/dispatch.mdx +3 -3
  477. package/docs/content/locales/es-ES/external-agents.mdx +32 -19
  478. package/docs/content/locales/es-ES/mcp-clients.mdx +17 -3
  479. package/docs/content/locales/es-ES/mcp-protocol.mdx +38 -15
  480. package/docs/content/locales/es-ES/plan-plugin.mdx +3 -3
  481. package/docs/content/locales/es-ES/server.mdx +2 -2
  482. package/docs/content/locales/es-ES/skills-guide.mdx +1 -1
  483. package/docs/content/locales/es-ES/template-assets.mdx +1 -1
  484. package/docs/content/locales/es-ES/template-dispatch.mdx +2 -2
  485. package/docs/content/locales/es-ES/template-plan.mdx +3 -3
  486. package/docs/content/locales/fr-FR/actions.mdx +1 -1
  487. package/docs/content/locales/fr-FR/authentication.mdx +1 -1
  488. package/docs/content/locales/fr-FR/dispatch.mdx +3 -3
  489. package/docs/content/locales/fr-FR/external-agents.mdx +23 -19
  490. package/docs/content/locales/fr-FR/mcp-clients.mdx +17 -3
  491. package/docs/content/locales/fr-FR/mcp-protocol.mdx +29 -15
  492. package/docs/content/locales/fr-FR/plan-plugin.mdx +3 -3
  493. package/docs/content/locales/fr-FR/server.mdx +2 -2
  494. package/docs/content/locales/fr-FR/skills-guide.mdx +1 -1
  495. package/docs/content/locales/fr-FR/template-assets.mdx +1 -1
  496. package/docs/content/locales/fr-FR/template-dispatch.mdx +2 -2
  497. package/docs/content/locales/fr-FR/template-plan.mdx +3 -3
  498. package/docs/content/locales/hi-IN/actions.mdx +1 -1
  499. package/docs/content/locales/hi-IN/authentication.mdx +1 -1
  500. package/docs/content/locales/hi-IN/dispatch.mdx +3 -3
  501. package/docs/content/locales/hi-IN/external-agents.mdx +31 -19
  502. package/docs/content/locales/hi-IN/mcp-clients.mdx +17 -3
  503. package/docs/content/locales/hi-IN/mcp-protocol.mdx +36 -15
  504. package/docs/content/locales/hi-IN/plan-plugin.mdx +3 -3
  505. package/docs/content/locales/hi-IN/server.mdx +2 -2
  506. package/docs/content/locales/hi-IN/skills-guide.mdx +1 -1
  507. package/docs/content/locales/hi-IN/template-assets.mdx +1 -1
  508. package/docs/content/locales/hi-IN/template-dispatch.mdx +2 -2
  509. package/docs/content/locales/hi-IN/template-plan.mdx +3 -3
  510. package/docs/content/locales/ja-JP/actions.mdx +1 -1
  511. package/docs/content/locales/ja-JP/authentication.mdx +1 -1
  512. package/docs/content/locales/ja-JP/dispatch.mdx +3 -3
  513. package/docs/content/locales/ja-JP/external-agents.mdx +23 -19
  514. package/docs/content/locales/ja-JP/mcp-clients.mdx +34 -3
  515. package/docs/content/locales/ja-JP/mcp-protocol.mdx +29 -15
  516. package/docs/content/locales/ja-JP/plan-plugin.mdx +3 -3
  517. package/docs/content/locales/ja-JP/server.mdx +2 -2
  518. package/docs/content/locales/ja-JP/skills-guide.mdx +1 -1
  519. package/docs/content/locales/ja-JP/template-assets.mdx +1 -1
  520. package/docs/content/locales/ja-JP/template-dispatch.mdx +2 -2
  521. package/docs/content/locales/ja-JP/template-plan.mdx +3 -3
  522. package/docs/content/locales/ko-KR/actions.mdx +1 -1
  523. package/docs/content/locales/ko-KR/authentication.mdx +1 -1
  524. package/docs/content/locales/ko-KR/dispatch.mdx +3 -3
  525. package/docs/content/locales/ko-KR/external-agents.mdx +30 -19
  526. package/docs/content/locales/ko-KR/mcp-clients.mdx +33 -3
  527. package/docs/content/locales/ko-KR/mcp-protocol.mdx +36 -15
  528. package/docs/content/locales/ko-KR/plan-plugin.mdx +3 -3
  529. package/docs/content/locales/ko-KR/server.mdx +2 -2
  530. package/docs/content/locales/ko-KR/skills-guide.mdx +1 -1
  531. package/docs/content/locales/ko-KR/template-assets.mdx +1 -1
  532. package/docs/content/locales/ko-KR/template-dispatch.mdx +2 -2
  533. package/docs/content/locales/ko-KR/template-plan.mdx +3 -3
  534. package/docs/content/locales/pt-BR/actions.mdx +1 -1
  535. package/docs/content/locales/pt-BR/authentication.mdx +1 -1
  536. package/docs/content/locales/pt-BR/dispatch.mdx +3 -3
  537. package/docs/content/locales/pt-BR/external-agents.mdx +32 -19
  538. package/docs/content/locales/pt-BR/mcp-clients.mdx +34 -3
  539. package/docs/content/locales/pt-BR/mcp-protocol.mdx +32 -15
  540. package/docs/content/locales/pt-BR/plan-plugin.mdx +3 -3
  541. package/docs/content/locales/pt-BR/server.mdx +2 -2
  542. package/docs/content/locales/pt-BR/skills-guide.mdx +1 -1
  543. package/docs/content/locales/pt-BR/template-assets.mdx +1 -1
  544. package/docs/content/locales/pt-BR/template-dispatch.mdx +2 -2
  545. package/docs/content/locales/pt-BR/template-plan.mdx +3 -3
  546. package/docs/content/locales/zh-CN/actions.mdx +1 -1
  547. package/docs/content/locales/zh-CN/authentication.mdx +1 -1
  548. package/docs/content/locales/zh-CN/dispatch.mdx +3 -3
  549. package/docs/content/locales/zh-CN/external-agents.mdx +23 -19
  550. package/docs/content/locales/zh-CN/mcp-clients.mdx +28 -3
  551. package/docs/content/locales/zh-CN/mcp-protocol.mdx +29 -15
  552. package/docs/content/locales/zh-CN/plan-plugin.mdx +3 -3
  553. package/docs/content/locales/zh-CN/server.mdx +2 -2
  554. package/docs/content/locales/zh-CN/skills-guide.mdx +1 -1
  555. package/docs/content/locales/zh-CN/template-assets.mdx +1 -1
  556. package/docs/content/locales/zh-CN/template-dispatch.mdx +2 -2
  557. package/docs/content/locales/zh-CN/template-plan.mdx +3 -3
  558. package/docs/content/locales/zh-TW/actions.mdx +1 -1
  559. package/docs/content/locales/zh-TW/authentication.mdx +1 -1
  560. package/docs/content/locales/zh-TW/dispatch.mdx +3 -3
  561. package/docs/content/locales/zh-TW/external-agents.mdx +23 -19
  562. package/docs/content/locales/zh-TW/mcp-clients.mdx +28 -3
  563. package/docs/content/locales/zh-TW/mcp-protocol.mdx +30 -15
  564. package/docs/content/locales/zh-TW/plan-plugin.mdx +3 -3
  565. package/docs/content/locales/zh-TW/server.mdx +2 -2
  566. package/docs/content/locales/zh-TW/skills-guide.mdx +1 -1
  567. package/docs/content/locales/zh-TW/template-assets.mdx +1 -1
  568. package/docs/content/locales/zh-TW/template-dispatch.mdx +2 -2
  569. package/docs/content/locales/zh-TW/template-plan.mdx +3 -3
  570. package/docs/content/mcp-clients.mdx +31 -4
  571. package/docs/content/mcp-protocol.mdx +35 -15
  572. package/docs/content/plan-plugin.mdx +3 -3
  573. package/docs/content/server.mdx +2 -2
  574. package/docs/content/skills-guide.mdx +1 -1
  575. package/docs/content/template-assets.mdx +1 -1
  576. package/docs/content/template-dispatch.mdx +2 -2
  577. package/docs/content/template-plan.mdx +3 -3
  578. package/package.json +2 -2
  579. package/src/templates/default/.agents/skills/security/SKILL.md +10 -0
  580. package/src/templates/workspace-core/.agents/skills/authentication/SKILL.md +15 -6
  581. package/src/templates/workspace-core/.agents/skills/external-agents/SKILL.md +16 -10
  582. package/src/templates/workspace-core/.agents/skills/performance/SKILL.md +20 -1
  583. package/src/templates/workspace-core/.agents/skills/security/SKILL.md +10 -0
@@ -1 +1 @@
1
- {"version":3,"file":"csrf.d.ts","sourceRoot":"","sources":["../../src/server/csrf.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAsIH;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,eAAe,GAAE,MAAyB;;GAsB3C"}
1
+ {"version":3,"file":"csrf.d.ts","sourceRoot":"","sources":["../../src/server/csrf.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAuJH;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,eAAe,GAAE,MAAyB;;GAsB3C"}
@@ -43,6 +43,7 @@
43
43
  * cross-origin-callable route, add it there.
44
44
  */
45
45
  import { defineEventHandler, getMethod, getRequestHeader, setResponseStatus, } from "h3";
46
+ import { MCP_PUBLIC_ROUTE_PREFIX } from "../mcp/route-paths.js";
46
47
  import { getConfiguredAppBasePath } from "./app-base-path.js";
47
48
  /**
48
49
  * Path prefixes (relative to the framework prefix `/_agent-native`) that are
@@ -150,11 +151,21 @@ function isOnAllowlist(pathname, frameworkPrefix) {
150
151
  function matchingFrameworkPrefix(pathname, frameworkPrefix) {
151
152
  if (pathname.startsWith(frameworkPrefix))
152
153
  return frameworkPrefix;
154
+ if (pathname === MCP_PUBLIC_ROUTE_PREFIX ||
155
+ pathname.startsWith(`${MCP_PUBLIC_ROUTE_PREFIX}/`)) {
156
+ return MCP_PUBLIC_ROUTE_PREFIX;
157
+ }
153
158
  const basePath = getConfiguredAppBasePath();
154
159
  const basePathFrameworkPrefix = `${basePath}${frameworkPrefix}`;
155
160
  if (basePath && pathname.startsWith(basePathFrameworkPrefix)) {
156
161
  return basePathFrameworkPrefix;
157
162
  }
163
+ const basePathMcpPrefix = `${basePath}${MCP_PUBLIC_ROUTE_PREFIX}`;
164
+ if (basePath &&
165
+ (pathname === basePathMcpPrefix ||
166
+ pathname.startsWith(`${basePathMcpPrefix}/`))) {
167
+ return basePathMcpPrefix;
168
+ }
158
169
  return undefined;
159
170
  }
160
171
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"csrf.js","sourceRoot":"","sources":["../../src/server/csrf.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,IAAI,CAAC;AAEZ,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAE9D;;;;;GAKG;AACH,MAAM,uBAAuB,GAAG;IAC9B,4EAA4E;IAC5E,gBAAgB;IAChB,2EAA2E;IAC3E,gEAAgE;IAChE,eAAe;IACf,qEAAqE;IACrE,4DAA4D;IAC5D,6BAA6B;IAC7B,2EAA2E;IAC3E,gEAAgE;IAChE,MAAM;IACN,sEAAsE;IACtE,0EAA0E;IAC1E,4DAA4D;IAC5D,QAAQ;IACR,8DAA8D;IAC9D,kBAAkB;IAClB,uEA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AAK,CAAC;YAAE,OAAO,SAAS,CAAC;QAEhD,IAAI,eAAe,CAAC,KAAK,CAAC;YAAE,OAAO,SAAS,CAAC;QAE7C,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAC9B,OAAO;YACL,KAAK,EACH,6IAA6I;SAChJ,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * Defense-in-depth CSRF check for framework state-changing routes.\n *\n * Threat model: action endpoints (`/_agent-native/actions/*`), extension\n * endpoints (`/_agent-native/extensions/*` and the legacy\n * `/_agent-native/tools/*` alias), and a handful of other state-changing\n * `/_agent-native/*` routes use the better-auth session cookie, which is\n * configured with `SameSite=None; Secure; Partitioned` so the iframe editor\n * (and other cross-site embeds) can authenticate. `SameSite=None` means the\n * browser ships the session cookie on top-level form POSTs from any origin —\n * which is exactly the precondition for classic cross-site request forgery.\n *\n * The browser still gates \"non-simple\" requests behind a CORS preflight, so\n * an attacker who has to send `Content-Type: application/json` is forced\n * through OPTIONS, which our CORS middleware (`create-server.ts`) rejects\n * for disallowed origins. But the simple-request bypass (`Content-Type:\n * text/plain` on a `<form enctype=\"text/plain\">` POST, or `multipart/form-data`)\n * never preflights — the browser delivers it cross-origin with cookies.\n *\n * Mitigation: this middleware rejects any state-changing\n * (`POST/PUT/PATCH/DELETE`) request to `/_agent-native/*` that\n *\n * 1. carries the auth-cookie pattern (any cookie at all is a heuristic\n * good-enough proxy — we don't want to deny anonymous fetches), AND\n * 2. is NOT clearly same-origin / first-party. We trust:\n * - `Sec-Fetch-Site: same-origin` (sent by every modern browser on\n * same-origin fetch — Chrome/Firefox/Safari/Edge all support it).\n * - `X-Agent-Native-CSRF` custom header. Custom headers force a\n * preflight, so an attacker can't add one cross-origin.\n * - `Content-Type: application/json` request body. Same logic — JSON\n * Content-Type is a non-simple request that triggers preflight.\n *\n * Why the existing CORS check isn't enough: a simple-request POST never\n * preflights, so the browser sends it through and only blocks the *response*\n * from being readable cross-origin. The state change (delete-account, write\n * SQL, etc.) happens server-side regardless. We need a server-side check that\n * proves first-party intent before running the action.\n *\n * Opt-out marker: a handful of routes legitimately accept cross-origin POSTs\n * — webhook endpoints (Slack, Telegram, email), the public A2A endpoint\n * (`/_agent-native/a2a`), the integrations process-task self-fire, and so on.\n * Those are listed in `CSRF_ALLOWLIST_PREFIXES` below; if you add a new\n * cross-origin-callable route, add it there.\n */\n\nimport {\n defineEventHandler,\n getMethod,\n getRequestHeader,\n setResponseStatus,\n} from \"h3\";\n\nimport { getConfiguredAppBasePath } from \"./app-base-path.js\";\n\n/**\n * Path prefixes (relative to the framework prefix `/_agent-native`) that are\n * allowed to receive cross-origin state-changing POSTs without first-party\n * markers. These are signed/authenticated through other mechanisms (HMAC,\n * JWT, internal token) so they don't need cookie-based CSRF protection.\n */\nconst CSRF_ALLOWLIST_PREFIXES = [\n // Integration webhooks — verified by HMAC against a per-integration secret.\n \"/integrations/\",\n // Agent Teams durable sub-agent processor self-fire — verified by the same\n // HMAC internal-token scheme as the integration/A2A processors.\n \"/agent-teams/\",\n // Durable sandbox-execution processor self-fire (run-code background\n // queue) — verified by the same HMAC internal-token scheme.\n \"/sandbox/_process-execution\",\n // A2A JSON-RPC endpoints — verified by signed JWT (when A2A_SECRET set) or\n // explicitly opt-in unauthenticated (handled at the A2A layer).\n \"/a2a\",\n // Better Auth's own login/sign-in/social-callback routes. Better Auth\n // ships its own CSRF protection (Origin/Sec-Fetch checks on its handlers)\n // and cookies are needed for the OAuth callback round-trip.\n \"/auth/\",\n // Stripe / Paddle / billing webhooks dropped in by templates.\n \"/billing/webhook\",\n // Public share endpoints — read-only and never cookie-driven, but kept\n // here so a templated POST (e.g. comment-on-public-recording) doesn't 403.\n \"/share/\",\n // OAuth callbacks (Builder, Google, Slack, Notion, Zoom). These get a\n // `code` query param via top-level navigation — they DO ride the session\n // cookie and they SHOULD validate state, but the framework can't see the\n // state token. Each callback handler is responsible for its own CSRF\n // check (signed state tokens).\n \"/oauth/\",\n // Builder's CLI-auth callback — uses the BUILDER_STATE_PARAM signed token\n // to authenticate the round-trip; framework CSRF check would block it.\n \"/builder/callback\",\n];\n\nconst STATE_CHANGING_METHODS = new Set([\"POST\", \"PUT\", \"PATCH\", \"DELETE\"]);\n\n/**\n * Decide whether a request is \"first-party enough\" to trust as not-CSRF.\n * Any of the following make a request non-CSRF:\n *\n * - `Sec-Fetch-Site: same-origin` (or `none` for top-level navigations\n * to our own pages — but state-changing methods don't ship `none`).\n * - `X-Agent-Native-CSRF` header (any value, even \"1\"). This is a custom\n * header so the browser forces a preflight cross-origin, which our\n * CORS layer rejects for disallowed origins.\n * - `Content-Type: application/json` (case-insensitive). JSON content\n * type is a non-simple request that triggers preflight.\n *\n * We accept ANY of these — the goal is \"did the request come through a\n * channel the browser would have preflighted\", not a strict-mode token.\n *\n * NOTE: `Sec-Fetch-Site: same-site` is deliberately NOT trusted. Under a\n * shared cookie domain (COOKIE_DOMAIN / crossSubDomainCookies), the browser\n * labels a request from a SIBLING subdomain (evil.example.com → app.example.com)\n * as `same-site` even though it is cross-origin and would ride the shared\n * session cookie — a CSRF vector. Legitimate first-party clients all also send\n * `X-Agent-Native-CSRF` or `application/json`, so they still pass via those\n * paths and iframe/embed flows are unaffected.\n */\nfunction looksFirstParty(event: any): boolean {\n const sfs = getRequestHeader(event, \"sec-fetch-site\");\n if (sfs === \"same-origin\" || sfs === \"none\") {\n return true;\n }\n if (getRequestHeader(event, \"x-agent-native-csrf\")) {\n return true;\n }\n const contentType = getRequestHeader(event, \"content-type\");\n if (\n contentType &&\n typeof contentType === \"string\" &&\n contentType.toLowerCase().includes(\"application/json\")\n ) {\n return true;\n }\n return false;\n}\n\n/**\n * Returns true when the request carries any cookie. We use \"has any cookie\"\n * as a coarse heuristic for \"the browser is going to attach the session\n * cookie\" — anonymous tools (curl, server-to-server) typically don't send\n * cookies, so they bypass this check entirely.\n */\nfunction requestHasCookies(event: any): boolean {\n const cookie = getRequestHeader(event, \"cookie\");\n return typeof cookie === \"string\" && cookie.trim().length > 0;\n}\n\n/**\n * The path is the full request URL pathname (e.g.\n * `/_agent-native/actions/foo` or `/app/_agent-native/actions/foo`).\n * `frameworkPrefix` is the root framework route prefix without a trailing\n * slash, e.g. `/_agent-native`.\n */\nfunction isOnAllowlist(pathname: string, frameworkPrefix: string): boolean {\n if (!pathname.startsWith(frameworkPrefix)) return false;\n const sub = pathname.slice(frameworkPrefix.length);\n for (const allowed of CSRF_ALLOWLIST_PREFIXES) {\n if (sub.startsWith(allowed)) return true;\n }\n return false;\n}\n\nfunction matchingFrameworkPrefix(\n pathname: string,\n frameworkPrefix: string,\n): string | undefined {\n if (pathname.startsWith(frameworkPrefix)) return frameworkPrefix;\n\n const basePath = getConfiguredAppBasePath();\n const basePathFrameworkPrefix = `${basePath}${frameworkPrefix}`;\n if (basePath && pathname.startsWith(basePathFrameworkPrefix)) {\n return basePathFrameworkPrefix;\n }\n\n return undefined;\n}\n\n/**\n * Create the framework CSRF middleware.\n *\n * Mount this BEFORE any state-changing route handler. The middleware\n * - lets every non-state-changing method through (GET/HEAD/OPTIONS).\n * - lets requests without cookies through (anonymous/server tools).\n * - lets allowlisted paths through (webhooks, A2A, OAuth callbacks).\n * - lets first-party-shaped requests through (custom header, JSON\n * Content-Type, or `Sec-Fetch-Site: same-origin`).\n * - rejects everything else with 403.\n */\nexport function createCsrfMiddleware(\n frameworkPrefix: string = \"/_agent-native\",\n) {\n return defineEventHandler((event) => {\n const method = getMethod(event);\n if (!STATE_CHANGING_METHODS.has(method)) return undefined;\n\n const pathname = event.url?.pathname ?? \"\";\n const matchingPrefix = matchingFrameworkPrefix(pathname, frameworkPrefix);\n if (!matchingPrefix) return undefined;\n if (isOnAllowlist(pathname, matchingPrefix)) return undefined;\n\n // No cookie = no risk of confused-deputy CSRF on the session cookie.\n if (!requestHasCookies(event)) return undefined;\n\n if (looksFirstParty(event)) return undefined;\n\n setResponseStatus(event, 403);\n return {\n error:\n \"CSRF check failed: state-changing requests must include a same-origin marker. Set Content-Type: application/json or X-Agent-Native-CSRF: 1.\",\n };\n });\n}\n"]}
1
+ {"version":3,"file":"csrf.js","sourceRoot":"","sources":["../../src/server/csrf.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,IAAI,CAAC;AAEZ,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAE9D;;;;;GAKG;AACH,MAAM,uBAAuB,GAAG;IAC9B,4EAA4E;IAC5E,gBAAgB;IAChB,2EAA2E;IAC3E,gEAAgE;IAChE,eAAe;IACf,qEAAqE;IACrE,4DAA4D;IAC5D,6BAA6B;IAC7B,2EAA2E;IAC3E,gEAAgE;IAChE,MAAM;IACN,sEAAsE;IACtE,0EAA0E;IAC1E,4DAA4D;IAC5D,QAAQ;IACR,8DAA8D;IAC9D,kBAAkB;IAClB,uEAAuE;IACvE,2EAA2E;IAC3E,SAAS;IACT,sEAAsE;IACtE,yEAAyE;IACzE,yEAAyE;IACzE,qEAAqE;IACrE,+BAA+B;IAC/B,SAAS;IACT,0EAA0E;IAC1E,uEAAuE;IACvE,mBAAmB;CACpB,CAAC;AAEF,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;AAE3E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAS,eAAe,CAAC,KAAU;IACjC,MAAM,GAAG,GAAG,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;IACtD,IAAI,GAAG,KAAK,aAAa,IAAI,GAAG,KAAK,MAAM,EAAE,CAAC;QAC5C,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,gBAAgB,CAA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IAA6I;SAChJ,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * Defense-in-depth CSRF check for framework state-changing routes.\n *\n * Threat model: action endpoints (`/_agent-native/actions/*`), extension\n * endpoints (`/_agent-native/extensions/*` and the legacy\n * `/_agent-native/tools/*` alias), and a handful of other state-changing\n * `/_agent-native/*` routes use the better-auth session cookie, which is\n * configured with `SameSite=None; Secure; Partitioned` so the iframe editor\n * (and other cross-site embeds) can authenticate. `SameSite=None` means the\n * browser ships the session cookie on top-level form POSTs from any origin —\n * which is exactly the precondition for classic cross-site request forgery.\n *\n * The browser still gates \"non-simple\" requests behind a CORS preflight, so\n * an attacker who has to send `Content-Type: application/json` is forced\n * through OPTIONS, which our CORS middleware (`create-server.ts`) rejects\n * for disallowed origins. But the simple-request bypass (`Content-Type:\n * text/plain` on a `<form enctype=\"text/plain\">` POST, or `multipart/form-data`)\n * never preflights — the browser delivers it cross-origin with cookies.\n *\n * Mitigation: this middleware rejects any state-changing\n * (`POST/PUT/PATCH/DELETE`) request to `/_agent-native/*` that\n *\n * 1. carries the auth-cookie pattern (any cookie at all is a heuristic\n * good-enough proxy — we don't want to deny anonymous fetches), AND\n * 2. is NOT clearly same-origin / first-party. We trust:\n * - `Sec-Fetch-Site: same-origin` (sent by every modern browser on\n * same-origin fetch — Chrome/Firefox/Safari/Edge all support it).\n * - `X-Agent-Native-CSRF` custom header. Custom headers force a\n * preflight, so an attacker can't add one cross-origin.\n * - `Content-Type: application/json` request body. Same logic — JSON\n * Content-Type is a non-simple request that triggers preflight.\n *\n * Why the existing CORS check isn't enough: a simple-request POST never\n * preflights, so the browser sends it through and only blocks the *response*\n * from being readable cross-origin. The state change (delete-account, write\n * SQL, etc.) happens server-side regardless. We need a server-side check that\n * proves first-party intent before running the action.\n *\n * Opt-out marker: a handful of routes legitimately accept cross-origin POSTs\n * — webhook endpoints (Slack, Telegram, email), the public A2A endpoint\n * (`/_agent-native/a2a`), the integrations process-task self-fire, and so on.\n * Those are listed in `CSRF_ALLOWLIST_PREFIXES` below; if you add a new\n * cross-origin-callable route, add it there.\n */\n\nimport {\n defineEventHandler,\n getMethod,\n getRequestHeader,\n setResponseStatus,\n} from \"h3\";\n\nimport { MCP_PUBLIC_ROUTE_PREFIX } from \"../mcp/route-paths.js\";\nimport { getConfiguredAppBasePath } from \"./app-base-path.js\";\n\n/**\n * Path prefixes (relative to the framework prefix `/_agent-native`) that are\n * allowed to receive cross-origin state-changing POSTs without first-party\n * markers. These are signed/authenticated through other mechanisms (HMAC,\n * JWT, internal token) so they don't need cookie-based CSRF protection.\n */\nconst CSRF_ALLOWLIST_PREFIXES = [\n // Integration webhooks — verified by HMAC against a per-integration secret.\n \"/integrations/\",\n // Agent Teams durable sub-agent processor self-fire — verified by the same\n // HMAC internal-token scheme as the integration/A2A processors.\n \"/agent-teams/\",\n // Durable sandbox-execution processor self-fire (run-code background\n // queue) — verified by the same HMAC internal-token scheme.\n \"/sandbox/_process-execution\",\n // A2A JSON-RPC endpoints — verified by signed JWT (when A2A_SECRET set) or\n // explicitly opt-in unauthenticated (handled at the A2A layer).\n \"/a2a\",\n // Better Auth's own login/sign-in/social-callback routes. Better Auth\n // ships its own CSRF protection (Origin/Sec-Fetch checks on its handlers)\n // and cookies are needed for the OAuth callback round-trip.\n \"/auth/\",\n // Stripe / Paddle / billing webhooks dropped in by templates.\n \"/billing/webhook\",\n // Public share endpoints — read-only and never cookie-driven, but kept\n // here so a templated POST (e.g. comment-on-public-recording) doesn't 403.\n \"/share/\",\n // OAuth callbacks (Builder, Google, Slack, Notion, Zoom). These get a\n // `code` query param via top-level navigation — they DO ride the session\n // cookie and they SHOULD validate state, but the framework can't see the\n // state token. Each callback handler is responsible for its own CSRF\n // check (signed state tokens).\n \"/oauth/\",\n // Builder's CLI-auth callback — uses the BUILDER_STATE_PARAM signed token\n // to authenticate the round-trip; framework CSRF check would block it.\n \"/builder/callback\",\n];\n\nconst STATE_CHANGING_METHODS = new Set([\"POST\", \"PUT\", \"PATCH\", \"DELETE\"]);\n\n/**\n * Decide whether a request is \"first-party enough\" to trust as not-CSRF.\n * Any of the following make a request non-CSRF:\n *\n * - `Sec-Fetch-Site: same-origin` (or `none` for top-level navigations\n * to our own pages — but state-changing methods don't ship `none`).\n * - `X-Agent-Native-CSRF` header (any value, even \"1\"). This is a custom\n * header so the browser forces a preflight cross-origin, which our\n * CORS layer rejects for disallowed origins.\n * - `Content-Type: application/json` (case-insensitive). JSON content\n * type is a non-simple request that triggers preflight.\n *\n * We accept ANY of these — the goal is \"did the request come through a\n * channel the browser would have preflighted\", not a strict-mode token.\n *\n * NOTE: `Sec-Fetch-Site: same-site` is deliberately NOT trusted. Under a\n * shared cookie domain (COOKIE_DOMAIN / crossSubDomainCookies), the browser\n * labels a request from a SIBLING subdomain (evil.example.com → app.example.com)\n * as `same-site` even though it is cross-origin and would ride the shared\n * session cookie — a CSRF vector. Legitimate first-party clients all also send\n * `X-Agent-Native-CSRF` or `application/json`, so they still pass via those\n * paths and iframe/embed flows are unaffected.\n */\nfunction looksFirstParty(event: any): boolean {\n const sfs = getRequestHeader(event, \"sec-fetch-site\");\n if (sfs === \"same-origin\" || sfs === \"none\") {\n return true;\n }\n if (getRequestHeader(event, \"x-agent-native-csrf\")) {\n return true;\n }\n const contentType = getRequestHeader(event, \"content-type\");\n if (\n contentType &&\n typeof contentType === \"string\" &&\n contentType.toLowerCase().includes(\"application/json\")\n ) {\n return true;\n }\n return false;\n}\n\n/**\n * Returns true when the request carries any cookie. We use \"has any cookie\"\n * as a coarse heuristic for \"the browser is going to attach the session\n * cookie\" — anonymous tools (curl, server-to-server) typically don't send\n * cookies, so they bypass this check entirely.\n */\nfunction requestHasCookies(event: any): boolean {\n const cookie = getRequestHeader(event, \"cookie\");\n return typeof cookie === \"string\" && cookie.trim().length > 0;\n}\n\n/**\n * The path is the full request URL pathname (e.g.\n * `/_agent-native/actions/foo` or `/app/_agent-native/actions/foo`).\n * `frameworkPrefix` is the root framework route prefix without a trailing\n * slash, e.g. `/_agent-native`.\n */\nfunction isOnAllowlist(pathname: string, frameworkPrefix: string): boolean {\n if (!pathname.startsWith(frameworkPrefix)) return false;\n const sub = pathname.slice(frameworkPrefix.length);\n for (const allowed of CSRF_ALLOWLIST_PREFIXES) {\n if (sub.startsWith(allowed)) return true;\n }\n return false;\n}\n\nfunction matchingFrameworkPrefix(\n pathname: string,\n frameworkPrefix: string,\n): string | undefined {\n if (pathname.startsWith(frameworkPrefix)) return frameworkPrefix;\n\n if (\n pathname === MCP_PUBLIC_ROUTE_PREFIX ||\n pathname.startsWith(`${MCP_PUBLIC_ROUTE_PREFIX}/`)\n ) {\n return MCP_PUBLIC_ROUTE_PREFIX;\n }\n\n const basePath = getConfiguredAppBasePath();\n const basePathFrameworkPrefix = `${basePath}${frameworkPrefix}`;\n if (basePath && pathname.startsWith(basePathFrameworkPrefix)) {\n return basePathFrameworkPrefix;\n }\n\n const basePathMcpPrefix = `${basePath}${MCP_PUBLIC_ROUTE_PREFIX}`;\n if (\n basePath &&\n (pathname === basePathMcpPrefix ||\n pathname.startsWith(`${basePathMcpPrefix}/`))\n ) {\n return basePathMcpPrefix;\n }\n\n return undefined;\n}\n\n/**\n * Create the framework CSRF middleware.\n *\n * Mount this BEFORE any state-changing route handler. The middleware\n * - lets every non-state-changing method through (GET/HEAD/OPTIONS).\n * - lets requests without cookies through (anonymous/server tools).\n * - lets allowlisted paths through (webhooks, A2A, OAuth callbacks).\n * - lets first-party-shaped requests through (custom header, JSON\n * Content-Type, or `Sec-Fetch-Site: same-origin`).\n * - rejects everything else with 403.\n */\nexport function createCsrfMiddleware(\n frameworkPrefix: string = \"/_agent-native\",\n) {\n return defineEventHandler((event) => {\n const method = getMethod(event);\n if (!STATE_CHANGING_METHODS.has(method)) return undefined;\n\n const pathname = event.url?.pathname ?? \"\";\n const matchingPrefix = matchingFrameworkPrefix(pathname, frameworkPrefix);\n if (!matchingPrefix) return undefined;\n if (isOnAllowlist(pathname, matchingPrefix)) return undefined;\n\n // No cookie = no risk of confused-deputy CSRF on the session cookie.\n if (!requestHasCookies(event)) return undefined;\n\n if (looksFirstParty(event)) return undefined;\n\n setResponseStatus(event, 403);\n return {\n error:\n \"CSRF check failed: state-changing requests must include a same-origin marker. Set Content-Type: application/json or X-Agent-Native-CSRF: 1.\",\n };\n });\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"framework-request-handler.d.ts","sourceRoot":"","sources":["../../src/server/framework-request-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,YAAY,EAAW,MAAM,IAAI,CAAC;AAUhD,QAAA,MAAM,gBAAgB,mBAAmB,CAAC;AAkD1C;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;IAC/C,GAAG,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;CAClC;AAED;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAQ3E;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,GAAG,GAAG,SAAS,CA+FjD;AA0CD;;;;;;;;;;GAUG;AACH,wBAAsB,cAAc,CAAC,QAAQ,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAOjE;AAmBD;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,GAAG,EACb,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,EACtB,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO,GACjC,IAAI,CAuCN;AA6FD;;;GAGG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,GAAG,EACb,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAqBf;AAoUD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,uBAAuB,CAC3C,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,GAAG,CAAC,CAyBd;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
1
+ {"version":3,"file":"framework-request-handler.d.ts","sourceRoot":"","sources":["../../src/server/framework-request-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,YAAY,EAAW,MAAM,IAAI,CAAC;AAWhD,QAAA,MAAM,gBAAgB,mBAAmB,CAAC;AAmD1C;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;IAC/C,GAAG,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;CAClC;AAED;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAQ3E;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,GAAG,GAAG,SAAS,CAmGjD;AA0CD;;;;;;;;;;GAUG;AACH,wBAAsB,cAAc,CAAC,QAAQ,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAOjE;AAmBD;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,GAAG,EACb,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,EACtB,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO,GACjC,IAAI,CAuCN;AA6FD;;;GAGG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,GAAG,EACb,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAqBf;AAoUD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,uBAAuB,CAC3C,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,GAAG,CAAC,CAyBd;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import { setResponseHeader, setResponseStatus } from "h3";
2
2
  import { getMissingDefaultPlugins } from "../deploy/route-discovery.js";
3
+ import { MCP_PUBLIC_ROUTE_PREFIX } from "../mcp/route-paths.js";
3
4
  import { getConfiguredAppBasePath } from "./app-base-path.js";
4
5
  import { captureError } from "./capture-error.js";
5
6
  import { createCsrfMiddleware } from "./csrf.js";
@@ -22,7 +23,8 @@ function pathMatchesPrefix(reqPath, prefix) {
22
23
  }
23
24
  function supportsAppBasePathMount(path) {
24
25
  return (pathMatchesPrefix(path, FRAMEWORK_PREFIX) ||
25
- pathMatchesPrefix(path, WELL_KNOWN_PREFIX));
26
+ pathMatchesPrefix(path, WELL_KNOWN_PREFIX) ||
27
+ pathMatchesPrefix(path, MCP_PUBLIC_ROUTE_PREFIX));
26
28
  }
27
29
  function resolveMountMatch(reqPath, path) {
28
30
  if (pathMatchesPrefix(reqPath, path)) {
@@ -110,6 +112,9 @@ export function getH3App(nitroApp) {
110
112
  registerMiddleware(nitroApp, WELL_KNOWN_PREFIX, readinessGate, {
111
113
  prepend: true,
112
114
  });
115
+ registerMiddleware(nitroApp, MCP_PUBLIC_ROUTE_PREFIX, readinessGate, {
116
+ prepend: true,
117
+ });
113
118
  // CSRF (see csrf.ts): registered here — synchronously, on the very
114
119
  // first `getH3App()` call for this nitroApp — rather than inside
115
120
  // createCoreRoutesPlugin's own async init chain. Real deployments mount
@@ -139,7 +144,8 @@ export function getH3App(nitroApp) {
139
144
  nitroApp.hooks?.hook?.("request", async (event) => {
140
145
  const reqPath = event.url?.pathname ?? "";
141
146
  if (resolveMountMatch(reqPath, FRAMEWORK_PREFIX) ||
142
- resolveMountMatch(reqPath, WELL_KNOWN_PREFIX)) {
147
+ resolveMountMatch(reqPath, WELL_KNOWN_PREFIX) ||
148
+ resolveMountMatch(reqPath, MCP_PUBLIC_ROUTE_PREFIX)) {
143
149
  await awaitFrameworkRoutesReadyForRequest(nitroApp, reqPath);
144
150
  }
145
151
  });
@@ -1 +1 @@
1
- {"version":3,"file":"framework-request-handler.js","sourceRoot":"","sources":["../../src/server/framework-request-handler.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAC;AAE1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAEjD,MAAM,YAAY,GAAG,IAAI,OAAO,EAAU,CAAC;AAC3C,MAAM,YAAY,GAAG,IAAI,OAAO,EAAU,CAAC;AAC3C,MAAM,gBAAgB,GAAG,gBAAgB,CAAC;AAC1C,MAAM,iBAAiB,GAAG,cAAc,CAAC;AACzC,MAAM,YAAY,GAAG,oBAAoB,CAAC;AAC1C,MAAM,qBAAqB,GAAG,8BAA8B,CAAC;AAC7D,MAAM,gBAAgB,GAAG,gCAAgC,CAAC;AAC1D,MAAM,6BAA6B,GAAG,qCAAqC,CAAC;AAC5E,MAAM,iBAAiB,GAAG,gCAAgC,CAAC;AAC3D,MAAM,yBAAyB,GAAG,iCAAiC,CAAC;AACpE,MAAM,iCAAiC,GACrC,yCAAyC,CAAC;AAO5C,SAAS,cAAc;IACrB,OAAO,wBAAwB,EAAE,CAAC;AACpC,CAAC;AAED,SAAS,iBAAiB,CAAC,OAAe,EAAE,MAAc;IACxD,OAAO,OAAO,KAAK,MAAM,IAAI,OAAO,CAAC,UAAU,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,wBAAwB,CAAC,IAAY;IAC5C,O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AA8D;QAC9D,MAAM,QAAQ,IAAI,OAAO,CAAC;IAC5B,CAAC;AACH,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC","sourcesContent":["/**\n * Framework request handler — registers framework routes on Nitro's h3 instance.\n *\n * Nitro 3 exposes its h3 app as `nitroApp.h3`. We register framework routes\n * directly on it as middleware (`nitroApp.h3[\"~middleware\"]`), giving each\n * plugin a path-prefix-matched handler that runs before any file-based route.\n *\n * Plugins call `getH3App(nitroApp).use(path, handler)` exactly like h3 v1's\n * `app.use()` — the wrapper translates that into v2 middleware registration.\n *\n * Default plugins that the template doesn't provide are auto-mounted on the\n * first call to `getH3App()` per nitroApp instance.\n */\nimport type { EventHandler, H3Event } from \"h3\";\nimport { setResponseHeader, setResponseStatus } from \"h3\";\n\nimport { getMissingDefaultPlugins } from \"../deploy/route-discovery.js\";\nimport { getConfiguredAppBasePath } from \"./app-base-path.js\";\nimport { captureError } from \"./capture-error.js\";\nimport { createCsrfMiddleware } from \"./csrf.js\";\n\nconst BOOTSTRAPPED = new WeakSet<object>();\nconst IN_BOOTSTRAP = new WeakSet<object>();\nconst FRAMEWORK_PREFIX = \"/_agent-native\";\nconst WELL_KNOWN_PREFIX = \"/.well-known\";\nconst APP_SHIM_KEY = \"_agentNativeH3Shim\";\nconst BOOTSTRAP_PROMISE_KEY = \"_agentNativeBootstrapPromise\";\nconst PLUGIN_READY_KEY = \"_agentNativePluginReadyPromise\";\nconst PLUGIN_READY_PLACEHOLDERS_KEY = \"_agentNativePluginReadyPlaceholders\";\nconst PLUGIN_FAILED_KEY = \"_agentNativePluginInitFailures\";\nconst PROVIDED_PLUGIN_STEMS_KEY = \"_agentNativeProvidedPluginStems\";\nconst MIDDLEWARE_DISPATCHER_PATCHED_KEY =\n \"_agentNativeMiddlewareDispatcherPatched\";\n\ninterface PluginReadyEntry {\n promise: Promise<void>;\n paths?: string[];\n}\n\nfunction getAppBasePath(): string {\n return getConfiguredAppBasePath();\n}\n\nfunction pathMatchesPrefix(reqPath: string, prefix: string): boolean {\n return reqPath === prefix || reqPath.startsWith(prefix + \"/\");\n}\n\nfunction supportsAppBasePathMount(path: string): boolean {\n return (\n pathMatchesPrefix(path, FRAMEWORK_PREFIX) ||\n pathMatchesPrefix(path, WELL_KNOWN_PREFIX)\n );\n}\n\nfunction resolveMountMatch(\n reqPath: string,\n path: string,\n): { mountPath: string; strippedPath: string } | null {\n if (pathMatchesPrefix(reqPath, path)) {\n return { mountPath: path, strippedPath: reqPath.slice(path.length) || \"/\" };\n }\n\n const appBasePath = getAppBasePath();\n if (!appBasePath || !supportsAppBasePathMount(path)) return null;\n\n const prefixedPath = `${appBasePath}${path}`;\n if (!pathMatchesPrefix(reqPath, prefixedPath)) return null;\n return {\n mountPath: prefixedPath,\n strippedPath: reqPath.slice(prefixedPath.length) || \"/\",\n };\n}\n\n/**\n * Wrapper around Nitro's h3 instance that exposes a v1-style `.use()` API\n * for registering path-prefix middleware.\n */\nexport interface H3AppShim {\n use(path: string, handler: EventHandler): void;\n use(handler: EventHandler): void;\n}\n\n/**\n * Mark a default plugin slot as supplied by the app/template before the\n * framework default bootstrap runs.\n *\n * Bundled serverless functions often don't have the original\n * `server/plugins/*.ts` tree on disk at runtime, so filesystem route discovery\n * can falsely conclude a template plugin is missing. Explicit plugin factories\n * call this synchronously before awaiting bootstrap so the framework does not\n * auto-mount a generic default over the app's custom implementation.\n */\nexport function markDefaultPluginProvided(nitroApp: any, stem: string): void {\n if (!nitroApp || !stem) return;\n const existing = nitroApp[PROVIDED_PLUGIN_STEMS_KEY] as\n | Set<string>\n | undefined;\n const provided = existing ?? new Set<string>();\n provided.add(stem);\n nitroApp[PROVIDED_PLUGIN_STEMS_KEY] = provided;\n}\n\n/**\n * Get (or create) the shared H3 app wrapper for a nitroApp. Plugins use this\n * to register routes via `.use(path, handler)`.\n *\n * On the first call per nitroApp, we kick off auto-mounting any missing\n * default plugins. User-facing plugin factories (createAgentChatPlugin,\n * createAuthPlugin, etc.) await this bootstrap via `awaitBootstrap()` so the\n * default plugins finish registering middleware before requests arrive.\n */\nexport function getH3App(nitroApp: any): H3AppShim {\n if (!nitroApp) throw new Error(\"getH3App: nitroApp is required\");\n ensureGlobalMiddlewareDispatch(nitroApp);\n\n // Reuse the cached shim if we've wrapped this nitroApp before\n const cached = nitroApp[APP_SHIM_KEY] as H3AppShim | undefined;\n if (cached) return cached;\n\n const shim: H3AppShim = {\n use(arg1: string | EventHandler, arg2?: EventHandler) {\n const path = typeof arg1 === \"string\" ? arg1 : \"\";\n const handler = (typeof arg1 === \"string\" ? arg2 : arg1) as EventHandler;\n if (typeof handler !== \"function\") {\n throw new Error(\"getH3App.use: handler must be a function\");\n }\n registerMiddleware(nitroApp, path, handler);\n },\n };\n\n nitroApp[APP_SHIM_KEY] = shim;\n\n if (!BOOTSTRAPPED.has(nitroApp)) {\n BOOTSTRAPPED.add(nitroApp);\n nitroApp[BOOTSTRAP_PROMISE_KEY] = bootstrapDefaultPlugins(nitroApp).catch(\n (err) => {\n console.warn(\n \"[agent-native] Failed to auto-mount default plugins:\",\n (err as Error).message,\n );\n captureError(err, {\n route: \"default-plugin-bootstrap\",\n tags: { phase: \"default-plugin-bootstrap\" },\n });\n },\n );\n\n // Readiness gate: Nitro v3 doesn't await async plugins, so routes\n // registered inside an async plugin may not exist when the first\n // request arrives. These middleware entries hold framework routes\n // until default-plugin bootstrap and tracked plugin inits complete.\n const readinessGate = (async (event: H3Event) => {\n const eventAny = event as any;\n await awaitFrameworkRoutesReadyForRequest(\n nitroApp,\n eventAny.context?._mountedPathname ?? event.url?.pathname ?? \"\",\n );\n // Fall through — the actual route handler runs next.\n return undefined;\n }) as EventHandler;\n registerMiddleware(nitroApp, FRAMEWORK_PREFIX, readinessGate, {\n prepend: true,\n });\n registerMiddleware(nitroApp, WELL_KNOWN_PREFIX, readinessGate, {\n prepend: true,\n });\n\n // CSRF (see csrf.ts): registered here — synchronously, on the very\n // first `getH3App()` call for this nitroApp — rather than inside\n // createCoreRoutesPlugin's own async init chain. Real deployments mount\n // core-routes and agent-chat as SEPARATE, independently-async-initialized\n // Nitro plugin files with no explicit ordering between them; both\n // eventually call `getH3App(nitroApp).use(...)` to register their own\n // routes (CSRF, action routes) after their own async setup (DB reads,\n // dynamic imports) resolves in unpredictable relative order. The\n // readiness gate above only guarantees every tracked plugin has FINISHED\n // registering by the time a gated request is released — it does NOT\n // guarantee CSRF's registration call happens to `.push()` onto\n // `~middleware` before an action route's does. If agent-chat's action\n // route push happened to land first, that route would match and run\n // before CSRF ever saw the request. Registering CSRF here instead makes\n // it the first non-prepended middleware pushed onto the array for this\n // nitroApp, full stop — every plugin's own route registrations reach\n // `getH3App()` (and therefore run after this point) before they can\n // register anything, regardless of which plugin's async chain resolves\n // first.\n registerMiddleware(nitroApp, \"\", createCsrfMiddleware());\n\n // Primary gate: Nitro bridges this `request` hook to h3's `config.onRequest`,\n // which h3 awaits BEFORE `handler()` snapshots middleware and resolves the\n // route. The middleware gate above runs too late on production dispatchers —\n // its await finishes after the snapshot, so a route registered during async\n // init is missing from the request and 404s. The middleware gate stays as a\n // fallback for runtimes where `onRequest` isn't wired.\n nitroApp.hooks?.hook?.(\"request\", async (event: H3Event) => {\n const reqPath = event.url?.pathname ?? \"\";\n if (\n resolveMountMatch(reqPath, FRAMEWORK_PREFIX) ||\n resolveMountMatch(reqPath, WELL_KNOWN_PREFIX)\n ) {\n await awaitFrameworkRoutesReadyForRequest(nitroApp, reqPath);\n }\n });\n }\n\n return shim;\n}\n\n/**\n * Nitro 3 production builds generate a route dispatcher by overriding h3's\n * internal `~getMiddleware()` hook. Some generated dispatchers return only\n * route-rule middleware and skip the global `h3[\"~middleware\"]` array that\n * `getH3App().use()` appends to. Wrap the dispatcher once so framework routes\n * registered at runtime are still part of request dispatch.\n */\nfunction ensureGlobalMiddlewareDispatch(nitroApp: any): void {\n const h3 = nitroApp?.h3;\n if (!h3) return;\n const current = h3[\"~getMiddleware\"];\n if (h3[MIDDLEWARE_DISPATCHER_PATCHED_KEY] === current) return;\n\n const original = typeof current === \"function\" ? current.bind(h3) : undefined;\n\n const wrappedGetMiddleware = (event: H3Event, route: unknown) => {\n const originalResult = original ? original(event, route) : [];\n const originalList = Array.isArray(originalResult)\n ? originalResult\n : originalResult\n ? [originalResult]\n : [];\n const globalMiddleware = Array.isArray(h3[\"~middleware\"])\n ? h3[\"~middleware\"]\n : [];\n if (globalMiddleware.length === 0) return originalList;\n\n const alreadyIncluded = new Set(originalList);\n const missingGlobal = globalMiddleware.filter(\n (middleware) => !alreadyIncluded.has(middleware),\n );\n return missingGlobal.length\n ? [...missingGlobal, ...originalList]\n : originalList;\n };\n\n h3[\"~getMiddleware\"] = wrappedGetMiddleware;\n h3[MIDDLEWARE_DISPATCHER_PATCHED_KEY] = wrappedGetMiddleware;\n}\n\n/**\n * Wait for the framework's default-plugin bootstrap to complete.\n *\n * Called by user-facing plugin factories (`createAgentChatPlugin`, etc.) at\n * the top of their plugin function, so that by the time the function returns\n * — and Nitro starts accepting requests — all default plugins have finished\n * registering their middleware.\n *\n * No-op when called from inside the bootstrap itself (avoids deadlock when a\n * default plugin happens to be running as part of bootstrap).\n */\nexport async function awaitBootstrap(nitroApp: any): Promise<void> {\n if (!nitroApp || IN_BOOTSTRAP.has(nitroApp)) return;\n // Trigger bootstrap if it hasn't been already (idempotent — getH3App\n // creates the shim and kicks off bootstrap on first call).\n getH3App(nitroApp);\n const promise = nitroApp[BOOTSTRAP_PROMISE_KEY];\n if (promise) await promise;\n}\n\n/**\n * Wait until framework routes are safe to dispatch.\n *\n * Request-time gates must wait for both phases:\n * 1. default-plugin bootstrap, which discovers and starts missing plugins\n * 2. async plugin init promises, which register routes such as A2A cards\n */\nasync function awaitFrameworkRoutesReadyForRequest(\n nitroApp: any,\n reqPath: string,\n): Promise<void> {\n if (!nitroApp) return;\n const bootstrapPromise = nitroApp[BOOTSTRAP_PROMISE_KEY];\n if (bootstrapPromise) await bootstrapPromise;\n await awaitPluginsReady(nitroApp, reqPath);\n}\n\n/**\n * Track an async plugin's initialization promise. Nitro v3 calls plugins\n * synchronously and doesn't await async return values, so routes registered\n * inside an async plugin may not be ready when the first request arrives.\n *\n * Call this from the TOP of any async plugin so that the readiness gate\n * (installed by getH3App) can hold /_agent-native requests until the plugin\n * finishes mounting its routes.\n */\nexport function trackPluginInit(\n nitroApp: any,\n promise: Promise<void>,\n options: { paths?: string[] } = {},\n): void {\n if (!nitroApp) return;\n // Ensure the readiness gate exists even when the tracked plugin is the first\n // framework code to run in a serverless isolate. Otherwise an immediate\n // first request can fall through before the plugin registers its routes.\n getH3App(nitroApp);\n // Attach a no-op catch so the promise doesn't surface as an unhandled\n // rejection when Nitro v3 drops the async return value. The actual error\n // is still observable when awaitPluginsReady() re-awaits the promise.\n const safe = promise.catch((err) => {\n console.error(\n \"[agent-native] Plugin init failed:\",\n (err as Error).message || err,\n );\n // Record the failure so the readiness gate can return a retryable 503 for\n // this plugin's routes instead of letting them fall through to a bare\n // \"Cannot find any route matching\" 404. That bare 404 is what kept biting\n // external MCP clients (pi/codex/claude) and the connect flow on cold /\n // propagating instances whose async init rejected (e.g. DB not yet\n // reachable): the route never registered, so the placeholder released into\n // a 404 the client couldn't recover from. A 503 is at least retryable.\n const failures = (nitroApp[PLUGIN_FAILED_KEY] ??= new Map<\n string,\n string\n >());\n const msg = (err as Error)?.message || String(err);\n for (const p of options.paths?.filter(Boolean) ?? []) failures.set(p, msg);\n });\n const entry: PluginReadyEntry = {\n promise: safe,\n paths: options.paths?.filter(Boolean),\n };\n const existing = nitroApp[PLUGIN_READY_KEY] as PluginReadyEntry[] | undefined;\n if (existing) {\n existing.push(entry);\n } else {\n nitroApp[PLUGIN_READY_KEY] = [entry];\n }\n installPluginReadyPlaceholders(nitroApp, entry.paths);\n}\n\nfunction installPluginReadyPlaceholders(\n nitroApp: any,\n paths: string[] | undefined,\n): void {\n if (!paths?.length) return;\n const existing = nitroApp[PLUGIN_READY_PLACEHOLDERS_KEY] as\n | Set<string>\n | undefined;\n const installed = existing ?? new Set<string>();\n nitroApp[PLUGIN_READY_PLACEHOLDERS_KEY] = installed;\n\n for (const path of paths) {\n if (!path || installed.has(path)) continue;\n installed.add(path);\n registerMiddleware(\n nitroApp,\n path,\n (async (event: H3Event) => {\n const eventAny = event as any;\n const reqPath =\n eventAny.context?._mountedPathname ?? event.url?.pathname ?? path;\n await awaitFrameworkRoutesReadyForRequest(nitroApp, reqPath);\n // If this plugin's async init failed, its real route was never\n // registered. Return a retryable 503 instead of releasing into a bare\n // 404 (external MCP clients can't recover from a 404; a 503 is at least\n // a \"try again\" the client / next instance can act on).\n const failures = nitroApp[PLUGIN_FAILED_KEY] as\n | Map<string, string>\n | undefined;\n if (failures?.size) {\n for (const [failedPath, msg] of failures) {\n if (resolveMountMatch(reqPath, failedPath)) {\n setResponseStatus(event, 503);\n setResponseHeader(event, \"retry-after\", \"5\");\n return {\n error: `agent-native route is initializing or unavailable: ${msg}`,\n };\n }\n }\n }\n return undefined;\n }) as EventHandler,\n {\n prepend: true,\n },\n );\n }\n}\n\nfunction logFrameworkRouteError(args: {\n method: string | undefined;\n route: string;\n status: number;\n error: unknown;\n}): void {\n const error = args.error as any;\n const message = error?.message || String(args.error);\n const prefix = `[agent-native] ${args.method ?? \"\"} ${args.route} failed (${args.status})`;\n if (process.env.NODE_ENV === \"production\") {\n console.error(`${prefix}: ${message}`);\n return;\n }\n console.error(`${prefix}: ${message}`, error?.stack || args.error);\n}\n\nfunction isClientAbortError(error: unknown, event: H3Event): boolean {\n const err = error as any;\n const message = typeof err?.message === \"string\" ? err.message : \"\";\n const code = typeof err?.code === \"string\" ? err.code : \"\";\n const node = (event as any).node;\n return (\n message === \"aborted\" ||\n code === \"ECONNRESET\" ||\n node?.req?.destroyed === true ||\n node?.res?.destroyed === true\n );\n}\n\nfunction debugClientAbort(args: {\n method: string | undefined;\n route: string;\n error: unknown;\n}): void {\n if (process.env.NODE_ENV === \"production\") return;\n const err = args.error as any;\n const message = err?.message || String(args.error);\n console.debug?.(\n `[agent-native] ${args.method ?? \"\"} ${args.route} aborted by client: ${message}`,\n );\n}\n\n/**\n * Await all tracked plugin initializations. Called by the readiness gate\n * middleware before dispatching framework routes.\n */\nexport async function awaitPluginsReady(\n nitroApp: any,\n reqPath?: string,\n): Promise<void> {\n const entries = nitroApp[PLUGIN_READY_KEY] as PluginReadyEntry[] | undefined;\n if (!entries?.length) return;\n\n const relevant = reqPath\n ? entries.filter((entry) =>\n entry.paths?.length\n ? entry.paths.some((path) => resolveMountMatch(reqPath, path))\n : true,\n )\n : entries;\n\n if (relevant.length) {\n await Promise.all(relevant.map((entry) => entry.promise));\n const completed = new Set(relevant);\n const latest =\n (nitroApp[PLUGIN_READY_KEY] as PluginReadyEntry[] | undefined) ?? [];\n nitroApp[PLUGIN_READY_KEY] = latest.filter(\n (entry) => !completed.has(entry),\n );\n }\n}\n\n/**\n * Register a path-prefix middleware on Nitro's h3 instance.\n *\n * The middleware:\n * - Returns `next()` (continues) if the request path doesn't match.\n * - Otherwise dispatches to the handler. If the handler returns a value,\n * it short-circuits the request. If it returns undefined, next() runs.\n *\n * Path matching emulates h3 v1's `app.use(path, ...)` behavior:\n * - Exact-match prefix: `/foo` matches `/foo`, `/foo/bar`, but not `/foobar`\n * - Empty path: middleware runs on every request\n */\nfunction registerMiddleware(\n nitroApp: any,\n path: string,\n handler: EventHandler,\n options: { prepend?: boolean } = {},\n) {\n const h3 = nitroApp.h3;\n if (!h3 || !Array.isArray(h3[\"~middleware\"])) {\n throw new Error(\n \"[agent-native] Cannot register route: nitroApp.h3 is not available. \" +\n \"Make sure you're calling getH3App() from inside a Nitro plugin.\",\n );\n }\n\n const middleware = async (event: H3Event, next: () => any) => {\n let originalPathname: string | undefined;\n let originalEventPath: string | undefined;\n let hadEventPath = false;\n // Only true once this specific middleware invocation has actually\n // stripped a mount prefix (i.e. `path` was non-empty and matched).\n // Global (`path === \"\"`) middleware never mutates event.path/pathname,\n // so `restoreOriginalPath` must be a no-op for it — otherwise it would\n // unconditionally `delete event.path` on every pass-through (hadEventPath\n // defaults to false), corrupting the event for any middleware that runs\n // later in the chain (a real bug: two or more global middlewares in\n // sequence, e.g. security-headers + CORS + CSRF, would wipe event.path\n // for everything downstream, including the final route handler).\n let didStripPath = false;\n const restoreOriginalPath = () => {\n if (!didStripPath) return;\n if (originalPathname !== undefined) {\n try {\n event.url.pathname = originalPathname;\n } catch {\n // ignore\n }\n originalPathname = undefined;\n }\n if (hadEventPath) {\n try {\n (event as any).path = originalEventPath;\n } catch {\n // ignore\n }\n } else {\n try {\n delete (event as any).path;\n } catch {\n // ignore\n }\n }\n };\n if (path) {\n const reqPath = event.url?.pathname ?? \"\";\n const match = resolveMountMatch(reqPath, path);\n if (!match) {\n return next();\n }\n // Strip the mount prefix from event.url.pathname so handlers that\n // dispatch sub-routes can read `event.path` (or `event.url.pathname`)\n // and see the path RELATIVE to their mount point — matching h3 v1's\n // `app.use(path, handler)` semantics.\n const eventAny = event as any;\n hadEventPath = \"path\" in eventAny;\n originalEventPath = eventAny.path;\n didStripPath = true;\n try {\n originalPathname = event.url.pathname;\n // Save the full path in context so handlers that need the original URL\n // (e.g. Better Auth, which extracts its own basePath prefix) can\n // reconstruct a Request with the un-stripped URL.\n eventAny.context = eventAny.context ?? {};\n eventAny.context._mountedPathname = originalPathname;\n eventAny.context._mountPrefix = match.mountPath;\n event.url.pathname = match.strippedPath;\n eventAny.path = `${match.strippedPath}${event.url.search || \"\"}`;\n } catch {\n // event.url is read-only on some runtimes — fall through. Handlers\n // that don't depend on prefix stripping (most of them) still work.\n }\n }\n try {\n const result = await handler(event);\n if (result === undefined) {\n // Restore the original pathname BEFORE calling next() so downstream\n // middleware sees the full URL — not the stripped mount-relative path.\n // Matches h3 v2's own sub-app middleware pattern where the restore\n // happens inside the next() callback, not after it returns.\n restoreOriginalPath();\n return next();\n }\n return result;\n } catch (err) {\n // Log 500s to the server console so they're debuggable, and respond\n // with JSON instead of the default HTML error page so clients can\n // surface error messages. This only applies to routes mounted under\n // the framework prefix (or middleware mounted at `/`, for which we\n // still want visibility).\n const reqPath = originalPathname ?? event.url?.pathname ?? \"\";\n const e = err as any;\n const status =\n typeof e?.statusCode === \"number\"\n ? e.statusCode\n : typeof e?.status === \"number\"\n ? e.status\n : 500;\n if (isClientAbortError(err, event)) {\n debugClientAbort({ method: event.method, route: reqPath, error: err });\n return undefined;\n }\n logFrameworkRouteError({\n method: event.method,\n route: reqPath,\n status,\n error: err,\n });\n // Forward 5xx to server-side Sentry — Nitro's own `error` hook may not\n // fire here because we convert the throw into a normal JSON response,\n // and a console.error alone is invisible in deployed environments.\n // 4xx are user-input errors (validation, auth) and aren't worth\n // alerting on. Lazy-loaded so the framework-request-handler module\n // doesn't pull @sentry/node into bundles that don't need it.\n if (status >= 500) {\n // Static `import` would create a cycle (sentry.ts imports auth.ts\n // which imports… eventually, framework-request-handler.ts).\n import(\"./sentry.js\")\n .then(({ captureRouteError, isServerSentryEnabled }) => {\n if (!isServerSentryEnabled()) return;\n captureRouteError(err, {\n route: reqPath,\n method: event.method,\n userAgent: (() => {\n try {\n return event.headers?.get(\"user-agent\") ?? undefined;\n } catch {\n return undefined;\n }\n })(),\n });\n })\n .catch(() => {\n // Sentry is observability — never let it break a response path.\n });\n }\n try {\n setResponseStatus(event, status);\n setResponseHeader(event, \"content-type\", \"application/json\");\n } catch {\n // Response already sent — best effort.\n }\n return {\n error: e?.message || \"Internal server error\",\n // Only surface the stack to clients when explicitly enabled.\n // `NODE_ENV !== \"production\"` was unsafe — preview deploys and\n // any host that forgets to set NODE_ENV=production leaked stack\n // traces (file paths, dependency versions, internal route\n // topology) to anonymous callers. Operators who want stacks in\n // dev set `AGENT_NATIVE_DEBUG_ERRORS=1` explicitly.\n ...(status >= 500 &&\n process.env.AGENT_NATIVE_DEBUG_ERRORS === \"1\" &&\n e?.stack\n ? { stack: e.stack }\n : {}),\n };\n } finally {\n // Restore the original pathname so downstream middleware sees the\n // full URL.\n restoreOriginalPath();\n }\n };\n\n if (options.prepend) {\n h3[\"~middleware\"].unshift(middleware);\n } else {\n h3[\"~middleware\"].push(middleware);\n }\n}\n\n/**\n * Auto-mount any default framework plugins that the template doesn't provide.\n *\n * Runs once per nitroApp on the first `getH3App()` call. Uses route-discovery\n * to find which default plugin stems are missing from `server/plugins/`, then\n * dynamically imports and mounts them. If a workspace core is present in the\n * ancestor chain, plugin slots the workspace core exports are mounted from\n * there instead of from @agent-native/core — this is the middle layer of the\n * three-layer inheritance model (app local > workspace core > framework).\n */\nasync function bootstrapDefaultPlugins(nitroApp: any): Promise<void> {\n IN_BOOTSTRAP.add(nitroApp);\n try {\n const cwd = process.cwd();\n const discoveredMissing = await getMissingDefaultPlugins(cwd);\n const provided = nitroApp[PROVIDED_PLUGIN_STEMS_KEY] as\n | Set<string>\n | undefined;\n const missing = provided\n ? discoveredMissing.filter((stem) => !provided.has(stem))\n : discoveredMissing;\n if (missing.length === 0) return;\n\n // Lazy import to avoid circular dependency at module load time\n const serverModule = await import(\"./index.js\");\n const terminalModule = await import(\"../terminal/terminal-plugin.js\");\n const integrationsModule = await import(\"../integrations/plugin.js\");\n const contextXrayModule = await import(\"../agent/context-xray/plugin.js\");\n const observationalMemoryModule =\n await import(\"../agent/observational-memory/plugin.js\");\n const orgModule = await import(\"../org/plugin.js\");\n const onboardingModule = await import(\"../onboarding/plugin.js\");\n\n const frameworkImpls: Record<\n string,\n ((nitroApp: any) => void | Promise<void>) | undefined\n > = {\n \"agent-chat\": (serverModule as any).defaultAgentChatPlugin,\n auth: (serverModule as any).defaultAuthPlugin,\n \"context-xray\": (contextXrayModule as any).defaultContextXrayPlugin,\n \"core-routes\": (serverModule as any).defaultCoreRoutesPlugin,\n integrations: (integrationsModule as any).defaultIntegrationsPlugin,\n \"observational-memory\": (observationalMemoryModule as any)\n .defaultObservationalMemoryPlugin,\n onboarding: (onboardingModule as any).defaultOnboardingPlugin,\n org: (orgModule as any).defaultOrgPlugin,\n resources: (serverModule as any).defaultResourcesPlugin,\n sentry: (serverModule as any).defaultSentryPlugin,\n terminal: (terminalModule as any).defaultTerminalPlugin,\n };\n\n // Workspace core layer: if the app is inside an enterprise monorepo with\n // `agent-native.workspaceCore` configured, pull in any plugin slots the\n // workspace core exports from its server entry. We dynamically import the\n // workspace core package at runtime.\n let workspaceImpls: Record<\n string,\n ((nitroApp: any) => void | Promise<void>) | undefined\n > = {};\n try {\n const { getWorkspaceCoreExports } =\n await import(\"../deploy/workspace-core.js\");\n const ws = await getWorkspaceCoreExports(cwd);\n if (ws && Object.keys(ws.plugins).length > 0) {\n try {\n const wsServerModule = await loadWorkspaceCoreServer(\n ws.packageName,\n ws.packageDir,\n );\n for (const [slot, exportName] of Object.entries(ws.plugins)) {\n if (!exportName) continue;\n const impl = (wsServerModule as any)[exportName];\n if (typeof impl === \"function\") {\n workspaceImpls[slot] = impl;\n }\n }\n if (process.env.DEBUG) {\n console.log(\n `[agent-native] Workspace core ${ws.packageName} provides plugin slots: ${Object.keys(workspaceImpls).join(\", \")}`,\n );\n }\n } catch (e) {\n const msg = (e as Error).message ?? \"\";\n // Common cause: workspace-core's package.json points \"./server\"\n // at a TS source file (the scaffold default), but Node can't\n // resolve relative `.js` imports inside it without a TS loader.\n // Tell the user to compile to dist/ rather than just dumping the\n // raw resolution error.\n const tsLoadHint = /\\.js' imported from .*\\.ts/.test(msg)\n ? \" — workspace-core src is TypeScript but isn't being compiled. \" +\n \"Run `pnpm --filter \" +\n ws.packageName +\n \" build` and point its `./server` export at dist/server/index.js.\"\n : \"\";\n console.warn(\n `[agent-native] Failed to load workspace core ${ws.packageName}/server: ${msg}${tsLoadHint}`,\n );\n }\n }\n } catch {\n // Workspace shared package isn't available (e.g. running on an edge\n // runtime without fs). Silently fall through to framework defaults.\n }\n\n if (process.env.DEBUG)\n console.log(\n `[agent-native] Auto-mounting ${missing.length} default plugin(s): ${missing.join(\", \")}`,\n );\n\n for (const stem of missing) {\n // Prefer workspace-core impl over framework default when both exist.\n const impl = workspaceImpls[stem] ?? frameworkImpls[stem];\n if (typeof impl === \"function\") {\n try {\n await impl(nitroApp);\n } catch (e) {\n console.warn(\n `[agent-native] Failed to auto-mount default plugin ${stem}:`,\n (e as Error).message,\n );\n captureError(e, {\n route: \"default-plugin-bootstrap\",\n tags: { phase: \"default-plugin-bootstrap\", plugin: stem },\n });\n }\n }\n }\n } finally {\n IN_BOOTSTRAP.delete(nitroApp);\n }\n}\n\n/**\n * Load a workspace-core's `/server` entry, transparently handling TS source.\n *\n * The scaffolded workspace-core template ships TS sources without a build\n * step (exports point at `./src/server/index.ts`), so plain `await import()`\n * blows up the moment Node hits a relative `.js` import inside (the standard\n * TS ESM convention) — and even before that, Node may resolve the package\n * relative to the framework's own location rather than the user's monorepo.\n *\n * We try Node's plain `import()` first (fastest path when the user has\n * compiled to dist/) and fall through to jiti on any error. jiti is anchored\n * to a real file inside the workspace-core's directory, so its module\n * resolution starts in the right node_modules tree (handles pnpm hoisting\n * and linked workspaces) AND handles TS source files + `.js` → `.ts` ESM\n * extension remapping.\n *\n * Edge runtimes without `fs` won't be able to load jiti at all; the outer\n * try/catch silently falls through to framework defaults in that case.\n */\nexport async function loadWorkspaceCoreServer(\n packageName: string,\n packageDir: string,\n): Promise<any> {\n let firstErr: unknown;\n try {\n return await import(/* @vite-ignore */ `${packageName}/server`);\n } catch (e) {\n firstErr = e;\n }\n\n try {\n const { createJiti } = await import(\"jiti\");\n const { pathToFileURL } = await import(\"node:url\");\n const path = await import(\"node:path\");\n // Anchor jiti to a real file inside the workspace-core package so its\n // module resolution starts in the right node_modules tree (handles pnpm\n // hoisting and linked workspaces).\n const anchor = pathToFileURL(\n path.join(packageDir, \"package.json\"),\n ).toString();\n const jiti = createJiti(anchor, { interopDefault: true });\n return await jiti.import(`${packageName}/server`);\n } catch (jitiErr) {\n // jiti also failed — rethrow the original Node error since it's usually\n // more informative about *why* the package wasn't resolvable.\n throw firstErr ?? jitiErr;\n }\n}\n\nexport { FRAMEWORK_PREFIX };\n"]}
1
+ {"version":3,"file":"framework-request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C;IACpD,CAAC;IAAC,OAAO,OAAO,EAAE,CAAC;QACjB,wEAAwE;QACxE,8DAA8D;QAC9D,MAAM,QAAQ,IAAI,OAAO,CAAC;IAC5B,CAAC;AACH,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC","sourcesContent":["/**\n * Framework request handler — registers framework routes on Nitro's h3 instance.\n *\n * Nitro 3 exposes its h3 app as `nitroApp.h3`. We register framework routes\n * directly on it as middleware (`nitroApp.h3[\"~middleware\"]`), giving each\n * plugin a path-prefix-matched handler that runs before any file-based route.\n *\n * Plugins call `getH3App(nitroApp).use(path, handler)` exactly like h3 v1's\n * `app.use()` — the wrapper translates that into v2 middleware registration.\n *\n * Default plugins that the template doesn't provide are auto-mounted on the\n * first call to `getH3App()` per nitroApp instance.\n */\nimport type { EventHandler, H3Event } from \"h3\";\nimport { setResponseHeader, setResponseStatus } from \"h3\";\n\nimport { getMissingDefaultPlugins } from \"../deploy/route-discovery.js\";\nimport { MCP_PUBLIC_ROUTE_PREFIX } from \"../mcp/route-paths.js\";\nimport { getConfiguredAppBasePath } from \"./app-base-path.js\";\nimport { captureError } from \"./capture-error.js\";\nimport { createCsrfMiddleware } from \"./csrf.js\";\n\nconst BOOTSTRAPPED = new WeakSet<object>();\nconst IN_BOOTSTRAP = new WeakSet<object>();\nconst FRAMEWORK_PREFIX = \"/_agent-native\";\nconst WELL_KNOWN_PREFIX = \"/.well-known\";\nconst APP_SHIM_KEY = \"_agentNativeH3Shim\";\nconst BOOTSTRAP_PROMISE_KEY = \"_agentNativeBootstrapPromise\";\nconst PLUGIN_READY_KEY = \"_agentNativePluginReadyPromise\";\nconst PLUGIN_READY_PLACEHOLDERS_KEY = \"_agentNativePluginReadyPlaceholders\";\nconst PLUGIN_FAILED_KEY = \"_agentNativePluginInitFailures\";\nconst PROVIDED_PLUGIN_STEMS_KEY = \"_agentNativeProvidedPluginStems\";\nconst MIDDLEWARE_DISPATCHER_PATCHED_KEY =\n \"_agentNativeMiddlewareDispatcherPatched\";\n\ninterface PluginReadyEntry {\n promise: Promise<void>;\n paths?: string[];\n}\n\nfunction getAppBasePath(): string {\n return getConfiguredAppBasePath();\n}\n\nfunction pathMatchesPrefix(reqPath: string, prefix: string): boolean {\n return reqPath === prefix || reqPath.startsWith(prefix + \"/\");\n}\n\nfunction supportsAppBasePathMount(path: string): boolean {\n return (\n pathMatchesPrefix(path, FRAMEWORK_PREFIX) ||\n pathMatchesPrefix(path, WELL_KNOWN_PREFIX) ||\n pathMatchesPrefix(path, MCP_PUBLIC_ROUTE_PREFIX)\n );\n}\n\nfunction resolveMountMatch(\n reqPath: string,\n path: string,\n): { mountPath: string; strippedPath: string } | null {\n if (pathMatchesPrefix(reqPath, path)) {\n return { mountPath: path, strippedPath: reqPath.slice(path.length) || \"/\" };\n }\n\n const appBasePath = getAppBasePath();\n if (!appBasePath || !supportsAppBasePathMount(path)) return null;\n\n const prefixedPath = `${appBasePath}${path}`;\n if (!pathMatchesPrefix(reqPath, prefixedPath)) return null;\n return {\n mountPath: prefixedPath,\n strippedPath: reqPath.slice(prefixedPath.length) || \"/\",\n };\n}\n\n/**\n * Wrapper around Nitro's h3 instance that exposes a v1-style `.use()` API\n * for registering path-prefix middleware.\n */\nexport interface H3AppShim {\n use(path: string, handler: EventHandler): void;\n use(handler: EventHandler): void;\n}\n\n/**\n * Mark a default plugin slot as supplied by the app/template before the\n * framework default bootstrap runs.\n *\n * Bundled serverless functions often don't have the original\n * `server/plugins/*.ts` tree on disk at runtime, so filesystem route discovery\n * can falsely conclude a template plugin is missing. Explicit plugin factories\n * call this synchronously before awaiting bootstrap so the framework does not\n * auto-mount a generic default over the app's custom implementation.\n */\nexport function markDefaultPluginProvided(nitroApp: any, stem: string): void {\n if (!nitroApp || !stem) return;\n const existing = nitroApp[PROVIDED_PLUGIN_STEMS_KEY] as\n | Set<string>\n | undefined;\n const provided = existing ?? new Set<string>();\n provided.add(stem);\n nitroApp[PROVIDED_PLUGIN_STEMS_KEY] = provided;\n}\n\n/**\n * Get (or create) the shared H3 app wrapper for a nitroApp. Plugins use this\n * to register routes via `.use(path, handler)`.\n *\n * On the first call per nitroApp, we kick off auto-mounting any missing\n * default plugins. User-facing plugin factories (createAgentChatPlugin,\n * createAuthPlugin, etc.) await this bootstrap via `awaitBootstrap()` so the\n * default plugins finish registering middleware before requests arrive.\n */\nexport function getH3App(nitroApp: any): H3AppShim {\n if (!nitroApp) throw new Error(\"getH3App: nitroApp is required\");\n ensureGlobalMiddlewareDispatch(nitroApp);\n\n // Reuse the cached shim if we've wrapped this nitroApp before\n const cached = nitroApp[APP_SHIM_KEY] as H3AppShim | undefined;\n if (cached) return cached;\n\n const shim: H3AppShim = {\n use(arg1: string | EventHandler, arg2?: EventHandler) {\n const path = typeof arg1 === \"string\" ? arg1 : \"\";\n const handler = (typeof arg1 === \"string\" ? arg2 : arg1) as EventHandler;\n if (typeof handler !== \"function\") {\n throw new Error(\"getH3App.use: handler must be a function\");\n }\n registerMiddleware(nitroApp, path, handler);\n },\n };\n\n nitroApp[APP_SHIM_KEY] = shim;\n\n if (!BOOTSTRAPPED.has(nitroApp)) {\n BOOTSTRAPPED.add(nitroApp);\n nitroApp[BOOTSTRAP_PROMISE_KEY] = bootstrapDefaultPlugins(nitroApp).catch(\n (err) => {\n console.warn(\n \"[agent-native] Failed to auto-mount default plugins:\",\n (err as Error).message,\n );\n captureError(err, {\n route: \"default-plugin-bootstrap\",\n tags: { phase: \"default-plugin-bootstrap\" },\n });\n },\n );\n\n // Readiness gate: Nitro v3 doesn't await async plugins, so routes\n // registered inside an async plugin may not exist when the first\n // request arrives. These middleware entries hold framework routes\n // until default-plugin bootstrap and tracked plugin inits complete.\n const readinessGate = (async (event: H3Event) => {\n const eventAny = event as any;\n await awaitFrameworkRoutesReadyForRequest(\n nitroApp,\n eventAny.context?._mountedPathname ?? event.url?.pathname ?? \"\",\n );\n // Fall through — the actual route handler runs next.\n return undefined;\n }) as EventHandler;\n registerMiddleware(nitroApp, FRAMEWORK_PREFIX, readinessGate, {\n prepend: true,\n });\n registerMiddleware(nitroApp, WELL_KNOWN_PREFIX, readinessGate, {\n prepend: true,\n });\n registerMiddleware(nitroApp, MCP_PUBLIC_ROUTE_PREFIX, readinessGate, {\n prepend: true,\n });\n\n // CSRF (see csrf.ts): registered here — synchronously, on the very\n // first `getH3App()` call for this nitroApp — rather than inside\n // createCoreRoutesPlugin's own async init chain. Real deployments mount\n // core-routes and agent-chat as SEPARATE, independently-async-initialized\n // Nitro plugin files with no explicit ordering between them; both\n // eventually call `getH3App(nitroApp).use(...)` to register their own\n // routes (CSRF, action routes) after their own async setup (DB reads,\n // dynamic imports) resolves in unpredictable relative order. The\n // readiness gate above only guarantees every tracked plugin has FINISHED\n // registering by the time a gated request is released — it does NOT\n // guarantee CSRF's registration call happens to `.push()` onto\n // `~middleware` before an action route's does. If agent-chat's action\n // route push happened to land first, that route would match and run\n // before CSRF ever saw the request. Registering CSRF here instead makes\n // it the first non-prepended middleware pushed onto the array for this\n // nitroApp, full stop — every plugin's own route registrations reach\n // `getH3App()` (and therefore run after this point) before they can\n // register anything, regardless of which plugin's async chain resolves\n // first.\n registerMiddleware(nitroApp, \"\", createCsrfMiddleware());\n\n // Primary gate: Nitro bridges this `request` hook to h3's `config.onRequest`,\n // which h3 awaits BEFORE `handler()` snapshots middleware and resolves the\n // route. The middleware gate above runs too late on production dispatchers —\n // its await finishes after the snapshot, so a route registered during async\n // init is missing from the request and 404s. The middleware gate stays as a\n // fallback for runtimes where `onRequest` isn't wired.\n nitroApp.hooks?.hook?.(\"request\", async (event: H3Event) => {\n const reqPath = event.url?.pathname ?? \"\";\n if (\n resolveMountMatch(reqPath, FRAMEWORK_PREFIX) ||\n resolveMountMatch(reqPath, WELL_KNOWN_PREFIX) ||\n resolveMountMatch(reqPath, MCP_PUBLIC_ROUTE_PREFIX)\n ) {\n await awaitFrameworkRoutesReadyForRequest(nitroApp, reqPath);\n }\n });\n }\n\n return shim;\n}\n\n/**\n * Nitro 3 production builds generate a route dispatcher by overriding h3's\n * internal `~getMiddleware()` hook. Some generated dispatchers return only\n * route-rule middleware and skip the global `h3[\"~middleware\"]` array that\n * `getH3App().use()` appends to. Wrap the dispatcher once so framework routes\n * registered at runtime are still part of request dispatch.\n */\nfunction ensureGlobalMiddlewareDispatch(nitroApp: any): void {\n const h3 = nitroApp?.h3;\n if (!h3) return;\n const current = h3[\"~getMiddleware\"];\n if (h3[MIDDLEWARE_DISPATCHER_PATCHED_KEY] === current) return;\n\n const original = typeof current === \"function\" ? current.bind(h3) : undefined;\n\n const wrappedGetMiddleware = (event: H3Event, route: unknown) => {\n const originalResult = original ? original(event, route) : [];\n const originalList = Array.isArray(originalResult)\n ? originalResult\n : originalResult\n ? [originalResult]\n : [];\n const globalMiddleware = Array.isArray(h3[\"~middleware\"])\n ? h3[\"~middleware\"]\n : [];\n if (globalMiddleware.length === 0) return originalList;\n\n const alreadyIncluded = new Set(originalList);\n const missingGlobal = globalMiddleware.filter(\n (middleware) => !alreadyIncluded.has(middleware),\n );\n return missingGlobal.length\n ? [...missingGlobal, ...originalList]\n : originalList;\n };\n\n h3[\"~getMiddleware\"] = wrappedGetMiddleware;\n h3[MIDDLEWARE_DISPATCHER_PATCHED_KEY] = wrappedGetMiddleware;\n}\n\n/**\n * Wait for the framework's default-plugin bootstrap to complete.\n *\n * Called by user-facing plugin factories (`createAgentChatPlugin`, etc.) at\n * the top of their plugin function, so that by the time the function returns\n * — and Nitro starts accepting requests — all default plugins have finished\n * registering their middleware.\n *\n * No-op when called from inside the bootstrap itself (avoids deadlock when a\n * default plugin happens to be running as part of bootstrap).\n */\nexport async function awaitBootstrap(nitroApp: any): Promise<void> {\n if (!nitroApp || IN_BOOTSTRAP.has(nitroApp)) return;\n // Trigger bootstrap if it hasn't been already (idempotent — getH3App\n // creates the shim and kicks off bootstrap on first call).\n getH3App(nitroApp);\n const promise = nitroApp[BOOTSTRAP_PROMISE_KEY];\n if (promise) await promise;\n}\n\n/**\n * Wait until framework routes are safe to dispatch.\n *\n * Request-time gates must wait for both phases:\n * 1. default-plugin bootstrap, which discovers and starts missing plugins\n * 2. async plugin init promises, which register routes such as A2A cards\n */\nasync function awaitFrameworkRoutesReadyForRequest(\n nitroApp: any,\n reqPath: string,\n): Promise<void> {\n if (!nitroApp) return;\n const bootstrapPromise = nitroApp[BOOTSTRAP_PROMISE_KEY];\n if (bootstrapPromise) await bootstrapPromise;\n await awaitPluginsReady(nitroApp, reqPath);\n}\n\n/**\n * Track an async plugin's initialization promise. Nitro v3 calls plugins\n * synchronously and doesn't await async return values, so routes registered\n * inside an async plugin may not be ready when the first request arrives.\n *\n * Call this from the TOP of any async plugin so that the readiness gate\n * (installed by getH3App) can hold /_agent-native requests until the plugin\n * finishes mounting its routes.\n */\nexport function trackPluginInit(\n nitroApp: any,\n promise: Promise<void>,\n options: { paths?: string[] } = {},\n): void {\n if (!nitroApp) return;\n // Ensure the readiness gate exists even when the tracked plugin is the first\n // framework code to run in a serverless isolate. Otherwise an immediate\n // first request can fall through before the plugin registers its routes.\n getH3App(nitroApp);\n // Attach a no-op catch so the promise doesn't surface as an unhandled\n // rejection when Nitro v3 drops the async return value. The actual error\n // is still observable when awaitPluginsReady() re-awaits the promise.\n const safe = promise.catch((err) => {\n console.error(\n \"[agent-native] Plugin init failed:\",\n (err as Error).message || err,\n );\n // Record the failure so the readiness gate can return a retryable 503 for\n // this plugin's routes instead of letting them fall through to a bare\n // \"Cannot find any route matching\" 404. That bare 404 is what kept biting\n // external MCP clients (pi/codex/claude) and the connect flow on cold /\n // propagating instances whose async init rejected (e.g. DB not yet\n // reachable): the route never registered, so the placeholder released into\n // a 404 the client couldn't recover from. A 503 is at least retryable.\n const failures = (nitroApp[PLUGIN_FAILED_KEY] ??= new Map<\n string,\n string\n >());\n const msg = (err as Error)?.message || String(err);\n for (const p of options.paths?.filter(Boolean) ?? []) failures.set(p, msg);\n });\n const entry: PluginReadyEntry = {\n promise: safe,\n paths: options.paths?.filter(Boolean),\n };\n const existing = nitroApp[PLUGIN_READY_KEY] as PluginReadyEntry[] | undefined;\n if (existing) {\n existing.push(entry);\n } else {\n nitroApp[PLUGIN_READY_KEY] = [entry];\n }\n installPluginReadyPlaceholders(nitroApp, entry.paths);\n}\n\nfunction installPluginReadyPlaceholders(\n nitroApp: any,\n paths: string[] | undefined,\n): void {\n if (!paths?.length) return;\n const existing = nitroApp[PLUGIN_READY_PLACEHOLDERS_KEY] as\n | Set<string>\n | undefined;\n const installed = existing ?? new Set<string>();\n nitroApp[PLUGIN_READY_PLACEHOLDERS_KEY] = installed;\n\n for (const path of paths) {\n if (!path || installed.has(path)) continue;\n installed.add(path);\n registerMiddleware(\n nitroApp,\n path,\n (async (event: H3Event) => {\n const eventAny = event as any;\n const reqPath =\n eventAny.context?._mountedPathname ?? event.url?.pathname ?? path;\n await awaitFrameworkRoutesReadyForRequest(nitroApp, reqPath);\n // If this plugin's async init failed, its real route was never\n // registered. Return a retryable 503 instead of releasing into a bare\n // 404 (external MCP clients can't recover from a 404; a 503 is at least\n // a \"try again\" the client / next instance can act on).\n const failures = nitroApp[PLUGIN_FAILED_KEY] as\n | Map<string, string>\n | undefined;\n if (failures?.size) {\n for (const [failedPath, msg] of failures) {\n if (resolveMountMatch(reqPath, failedPath)) {\n setResponseStatus(event, 503);\n setResponseHeader(event, \"retry-after\", \"5\");\n return {\n error: `agent-native route is initializing or unavailable: ${msg}`,\n };\n }\n }\n }\n return undefined;\n }) as EventHandler,\n {\n prepend: true,\n },\n );\n }\n}\n\nfunction logFrameworkRouteError(args: {\n method: string | undefined;\n route: string;\n status: number;\n error: unknown;\n}): void {\n const error = args.error as any;\n const message = error?.message || String(args.error);\n const prefix = `[agent-native] ${args.method ?? \"\"} ${args.route} failed (${args.status})`;\n if (process.env.NODE_ENV === \"production\") {\n console.error(`${prefix}: ${message}`);\n return;\n }\n console.error(`${prefix}: ${message}`, error?.stack || args.error);\n}\n\nfunction isClientAbortError(error: unknown, event: H3Event): boolean {\n const err = error as any;\n const message = typeof err?.message === \"string\" ? err.message : \"\";\n const code = typeof err?.code === \"string\" ? err.code : \"\";\n const node = (event as any).node;\n return (\n message === \"aborted\" ||\n code === \"ECONNRESET\" ||\n node?.req?.destroyed === true ||\n node?.res?.destroyed === true\n );\n}\n\nfunction debugClientAbort(args: {\n method: string | undefined;\n route: string;\n error: unknown;\n}): void {\n if (process.env.NODE_ENV === \"production\") return;\n const err = args.error as any;\n const message = err?.message || String(args.error);\n console.debug?.(\n `[agent-native] ${args.method ?? \"\"} ${args.route} aborted by client: ${message}`,\n );\n}\n\n/**\n * Await all tracked plugin initializations. Called by the readiness gate\n * middleware before dispatching framework routes.\n */\nexport async function awaitPluginsReady(\n nitroApp: any,\n reqPath?: string,\n): Promise<void> {\n const entries = nitroApp[PLUGIN_READY_KEY] as PluginReadyEntry[] | undefined;\n if (!entries?.length) return;\n\n const relevant = reqPath\n ? entries.filter((entry) =>\n entry.paths?.length\n ? entry.paths.some((path) => resolveMountMatch(reqPath, path))\n : true,\n )\n : entries;\n\n if (relevant.length) {\n await Promise.all(relevant.map((entry) => entry.promise));\n const completed = new Set(relevant);\n const latest =\n (nitroApp[PLUGIN_READY_KEY] as PluginReadyEntry[] | undefined) ?? [];\n nitroApp[PLUGIN_READY_KEY] = latest.filter(\n (entry) => !completed.has(entry),\n );\n }\n}\n\n/**\n * Register a path-prefix middleware on Nitro's h3 instance.\n *\n * The middleware:\n * - Returns `next()` (continues) if the request path doesn't match.\n * - Otherwise dispatches to the handler. If the handler returns a value,\n * it short-circuits the request. If it returns undefined, next() runs.\n *\n * Path matching emulates h3 v1's `app.use(path, ...)` behavior:\n * - Exact-match prefix: `/foo` matches `/foo`, `/foo/bar`, but not `/foobar`\n * - Empty path: middleware runs on every request\n */\nfunction registerMiddleware(\n nitroApp: any,\n path: string,\n handler: EventHandler,\n options: { prepend?: boolean } = {},\n) {\n const h3 = nitroApp.h3;\n if (!h3 || !Array.isArray(h3[\"~middleware\"])) {\n throw new Error(\n \"[agent-native] Cannot register route: nitroApp.h3 is not available. \" +\n \"Make sure you're calling getH3App() from inside a Nitro plugin.\",\n );\n }\n\n const middleware = async (event: H3Event, next: () => any) => {\n let originalPathname: string | undefined;\n let originalEventPath: string | undefined;\n let hadEventPath = false;\n // Only true once this specific middleware invocation has actually\n // stripped a mount prefix (i.e. `path` was non-empty and matched).\n // Global (`path === \"\"`) middleware never mutates event.path/pathname,\n // so `restoreOriginalPath` must be a no-op for it — otherwise it would\n // unconditionally `delete event.path` on every pass-through (hadEventPath\n // defaults to false), corrupting the event for any middleware that runs\n // later in the chain (a real bug: two or more global middlewares in\n // sequence, e.g. security-headers + CORS + CSRF, would wipe event.path\n // for everything downstream, including the final route handler).\n let didStripPath = false;\n const restoreOriginalPath = () => {\n if (!didStripPath) return;\n if (originalPathname !== undefined) {\n try {\n event.url.pathname = originalPathname;\n } catch {\n // ignore\n }\n originalPathname = undefined;\n }\n if (hadEventPath) {\n try {\n (event as any).path = originalEventPath;\n } catch {\n // ignore\n }\n } else {\n try {\n delete (event as any).path;\n } catch {\n // ignore\n }\n }\n };\n if (path) {\n const reqPath = event.url?.pathname ?? \"\";\n const match = resolveMountMatch(reqPath, path);\n if (!match) {\n return next();\n }\n // Strip the mount prefix from event.url.pathname so handlers that\n // dispatch sub-routes can read `event.path` (or `event.url.pathname`)\n // and see the path RELATIVE to their mount point — matching h3 v1's\n // `app.use(path, handler)` semantics.\n const eventAny = event as any;\n hadEventPath = \"path\" in eventAny;\n originalEventPath = eventAny.path;\n didStripPath = true;\n try {\n originalPathname = event.url.pathname;\n // Save the full path in context so handlers that need the original URL\n // (e.g. Better Auth, which extracts its own basePath prefix) can\n // reconstruct a Request with the un-stripped URL.\n eventAny.context = eventAny.context ?? {};\n eventAny.context._mountedPathname = originalPathname;\n eventAny.context._mountPrefix = match.mountPath;\n event.url.pathname = match.strippedPath;\n eventAny.path = `${match.strippedPath}${event.url.search || \"\"}`;\n } catch {\n // event.url is read-only on some runtimes — fall through. Handlers\n // that don't depend on prefix stripping (most of them) still work.\n }\n }\n try {\n const result = await handler(event);\n if (result === undefined) {\n // Restore the original pathname BEFORE calling next() so downstream\n // middleware sees the full URL — not the stripped mount-relative path.\n // Matches h3 v2's own sub-app middleware pattern where the restore\n // happens inside the next() callback, not after it returns.\n restoreOriginalPath();\n return next();\n }\n return result;\n } catch (err) {\n // Log 500s to the server console so they're debuggable, and respond\n // with JSON instead of the default HTML error page so clients can\n // surface error messages. This only applies to routes mounted under\n // the framework prefix (or middleware mounted at `/`, for which we\n // still want visibility).\n const reqPath = originalPathname ?? event.url?.pathname ?? \"\";\n const e = err as any;\n const status =\n typeof e?.statusCode === \"number\"\n ? e.statusCode\n : typeof e?.status === \"number\"\n ? e.status\n : 500;\n if (isClientAbortError(err, event)) {\n debugClientAbort({ method: event.method, route: reqPath, error: err });\n return undefined;\n }\n logFrameworkRouteError({\n method: event.method,\n route: reqPath,\n status,\n error: err,\n });\n // Forward 5xx to server-side Sentry — Nitro's own `error` hook may not\n // fire here because we convert the throw into a normal JSON response,\n // and a console.error alone is invisible in deployed environments.\n // 4xx are user-input errors (validation, auth) and aren't worth\n // alerting on. Lazy-loaded so the framework-request-handler module\n // doesn't pull @sentry/node into bundles that don't need it.\n if (status >= 500) {\n // Static `import` would create a cycle (sentry.ts imports auth.ts\n // which imports… eventually, framework-request-handler.ts).\n import(\"./sentry.js\")\n .then(({ captureRouteError, isServerSentryEnabled }) => {\n if (!isServerSentryEnabled()) return;\n captureRouteError(err, {\n route: reqPath,\n method: event.method,\n userAgent: (() => {\n try {\n return event.headers?.get(\"user-agent\") ?? undefined;\n } catch {\n return undefined;\n }\n })(),\n });\n })\n .catch(() => {\n // Sentry is observability — never let it break a response path.\n });\n }\n try {\n setResponseStatus(event, status);\n setResponseHeader(event, \"content-type\", \"application/json\");\n } catch {\n // Response already sent — best effort.\n }\n return {\n error: e?.message || \"Internal server error\",\n // Only surface the stack to clients when explicitly enabled.\n // `NODE_ENV !== \"production\"` was unsafe — preview deploys and\n // any host that forgets to set NODE_ENV=production leaked stack\n // traces (file paths, dependency versions, internal route\n // topology) to anonymous callers. Operators who want stacks in\n // dev set `AGENT_NATIVE_DEBUG_ERRORS=1` explicitly.\n ...(status >= 500 &&\n process.env.AGENT_NATIVE_DEBUG_ERRORS === \"1\" &&\n e?.stack\n ? { stack: e.stack }\n : {}),\n };\n } finally {\n // Restore the original pathname so downstream middleware sees the\n // full URL.\n restoreOriginalPath();\n }\n };\n\n if (options.prepend) {\n h3[\"~middleware\"].unshift(middleware);\n } else {\n h3[\"~middleware\"].push(middleware);\n }\n}\n\n/**\n * Auto-mount any default framework plugins that the template doesn't provide.\n *\n * Runs once per nitroApp on the first `getH3App()` call. Uses route-discovery\n * to find which default plugin stems are missing from `server/plugins/`, then\n * dynamically imports and mounts them. If a workspace core is present in the\n * ancestor chain, plugin slots the workspace core exports are mounted from\n * there instead of from @agent-native/core — this is the middle layer of the\n * three-layer inheritance model (app local > workspace core > framework).\n */\nasync function bootstrapDefaultPlugins(nitroApp: any): Promise<void> {\n IN_BOOTSTRAP.add(nitroApp);\n try {\n const cwd = process.cwd();\n const discoveredMissing = await getMissingDefaultPlugins(cwd);\n const provided = nitroApp[PROVIDED_PLUGIN_STEMS_KEY] as\n | Set<string>\n | undefined;\n const missing = provided\n ? discoveredMissing.filter((stem) => !provided.has(stem))\n : discoveredMissing;\n if (missing.length === 0) return;\n\n // Lazy import to avoid circular dependency at module load time\n const serverModule = await import(\"./index.js\");\n const terminalModule = await import(\"../terminal/terminal-plugin.js\");\n const integrationsModule = await import(\"../integrations/plugin.js\");\n const contextXrayModule = await import(\"../agent/context-xray/plugin.js\");\n const observationalMemoryModule =\n await import(\"../agent/observational-memory/plugin.js\");\n const orgModule = await import(\"../org/plugin.js\");\n const onboardingModule = await import(\"../onboarding/plugin.js\");\n\n const frameworkImpls: Record<\n string,\n ((nitroApp: any) => void | Promise<void>) | undefined\n > = {\n \"agent-chat\": (serverModule as any).defaultAgentChatPlugin,\n auth: (serverModule as any).defaultAuthPlugin,\n \"context-xray\": (contextXrayModule as any).defaultContextXrayPlugin,\n \"core-routes\": (serverModule as any).defaultCoreRoutesPlugin,\n integrations: (integrationsModule as any).defaultIntegrationsPlugin,\n \"observational-memory\": (observationalMemoryModule as any)\n .defaultObservationalMemoryPlugin,\n onboarding: (onboardingModule as any).defaultOnboardingPlugin,\n org: (orgModule as any).defaultOrgPlugin,\n resources: (serverModule as any).defaultResourcesPlugin,\n sentry: (serverModule as any).defaultSentryPlugin,\n terminal: (terminalModule as any).defaultTerminalPlugin,\n };\n\n // Workspace core layer: if the app is inside an enterprise monorepo with\n // `agent-native.workspaceCore` configured, pull in any plugin slots the\n // workspace core exports from its server entry. We dynamically import the\n // workspace core package at runtime.\n let workspaceImpls: Record<\n string,\n ((nitroApp: any) => void | Promise<void>) | undefined\n > = {};\n try {\n const { getWorkspaceCoreExports } =\n await import(\"../deploy/workspace-core.js\");\n const ws = await getWorkspaceCoreExports(cwd);\n if (ws && Object.keys(ws.plugins).length > 0) {\n try {\n const wsServerModule = await loadWorkspaceCoreServer(\n ws.packageName,\n ws.packageDir,\n );\n for (const [slot, exportName] of Object.entries(ws.plugins)) {\n if (!exportName) continue;\n const impl = (wsServerModule as any)[exportName];\n if (typeof impl === \"function\") {\n workspaceImpls[slot] = impl;\n }\n }\n if (process.env.DEBUG) {\n console.log(\n `[agent-native] Workspace core ${ws.packageName} provides plugin slots: ${Object.keys(workspaceImpls).join(\", \")}`,\n );\n }\n } catch (e) {\n const msg = (e as Error).message ?? \"\";\n // Common cause: workspace-core's package.json points \"./server\"\n // at a TS source file (the scaffold default), but Node can't\n // resolve relative `.js` imports inside it without a TS loader.\n // Tell the user to compile to dist/ rather than just dumping the\n // raw resolution error.\n const tsLoadHint = /\\.js' imported from .*\\.ts/.test(msg)\n ? \" — workspace-core src is TypeScript but isn't being compiled. \" +\n \"Run `pnpm --filter \" +\n ws.packageName +\n \" build` and point its `./server` export at dist/server/index.js.\"\n : \"\";\n console.warn(\n `[agent-native] Failed to load workspace core ${ws.packageName}/server: ${msg}${tsLoadHint}`,\n );\n }\n }\n } catch {\n // Workspace shared package isn't available (e.g. running on an edge\n // runtime without fs). Silently fall through to framework defaults.\n }\n\n if (process.env.DEBUG)\n console.log(\n `[agent-native] Auto-mounting ${missing.length} default plugin(s): ${missing.join(\", \")}`,\n );\n\n for (const stem of missing) {\n // Prefer workspace-core impl over framework default when both exist.\n const impl = workspaceImpls[stem] ?? frameworkImpls[stem];\n if (typeof impl === \"function\") {\n try {\n await impl(nitroApp);\n } catch (e) {\n console.warn(\n `[agent-native] Failed to auto-mount default plugin ${stem}:`,\n (e as Error).message,\n );\n captureError(e, {\n route: \"default-plugin-bootstrap\",\n tags: { phase: \"default-plugin-bootstrap\", plugin: stem },\n });\n }\n }\n }\n } finally {\n IN_BOOTSTRAP.delete(nitroApp);\n }\n}\n\n/**\n * Load a workspace-core's `/server` entry, transparently handling TS source.\n *\n * The scaffolded workspace-core template ships TS sources without a build\n * step (exports point at `./src/server/index.ts`), so plain `await import()`\n * blows up the moment Node hits a relative `.js` import inside (the standard\n * TS ESM convention) — and even before that, Node may resolve the package\n * relative to the framework's own location rather than the user's monorepo.\n *\n * We try Node's plain `import()` first (fastest path when the user has\n * compiled to dist/) and fall through to jiti on any error. jiti is anchored\n * to a real file inside the workspace-core's directory, so its module\n * resolution starts in the right node_modules tree (handles pnpm hoisting\n * and linked workspaces) AND handles TS source files + `.js` → `.ts` ESM\n * extension remapping.\n *\n * Edge runtimes without `fs` won't be able to load jiti at all; the outer\n * try/catch silently falls through to framework defaults in that case.\n */\nexport async function loadWorkspaceCoreServer(\n packageName: string,\n packageDir: string,\n): Promise<any> {\n let firstErr: unknown;\n try {\n return await import(/* @vite-ignore */ `${packageName}/server`);\n } catch (e) {\n firstErr = e;\n }\n\n try {\n const { createJiti } = await import(\"jiti\");\n const { pathToFileURL } = await import(\"node:url\");\n const path = await import(\"node:path\");\n // Anchor jiti to a real file inside the workspace-core package so its\n // module resolution starts in the right node_modules tree (handles pnpm\n // hoisting and linked workspaces).\n const anchor = pathToFileURL(\n path.join(packageDir, \"package.json\"),\n ).toString();\n const jiti = createJiti(anchor, { interopDefault: true });\n return await jiti.import(`${packageName}/server`);\n } catch (jitiErr) {\n // jiti also failed — rethrow the original Node error since it's usually\n // more informative about *why* the package wasn't resolvable.\n throw firstErr ?? jitiErr;\n }\n}\n\nexport { FRAMEWORK_PREFIX };\n"]}
@@ -24,6 +24,8 @@ import { type H3Event } from "h3";
24
24
  export declare function isElectron(event: H3Event): boolean;
25
25
  /** Detect requests from a mobile browser (iOS/Android). */
26
26
  export declare function isMobile(event: H3Event): boolean;
27
+ /** Return whether a candidate is one of this deployment's configured origins. */
28
+ export declare function isConfiguredAppOrigin(value: string | undefined): boolean;
27
29
  /**
28
30
  * Get the origin from forwarded headers or Host.
29
31
  *
@@ -1 +1 @@
1
- {"version":3,"file":"google-oauth.d.ts","sourceRoot":"","sources":["../../src/server/google-oauth.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAKL,KAAK,OAAO,EACb,MAAM,IAAI,CAAC;AAiEZ;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAElD;AAED,2DAA2D;AAC3D,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEhD;AA8HD;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAgChD;AAED,uEAAuE;AACvE,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED,sEAAsE;AACtE,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,SAAM,GAAG,MAAM,CAG5D;AAgED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,OAAO,GACb,OAAO,CAqCT;AAED;;;;;;;;;;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QAAQ,CAMxD;AAED,wBAAgB,wBAAwB,CACtC,OAAO,SAA4B,GAClC,QAAQ,CAKV"}
@@ -8,7 +8,7 @@
8
8
  */
9
9
  import crypto from "node:crypto";
10
10
  import { getHeader, getQuery, setResponseStatus, setResponseHeader, } from "h3";
11
- import { getConfiguredAppBasePath } from "./app-base-path.js";
11
+ import { getAppBasePathFromViteEnv } from "./app-base-path.js";
12
12
  import { getAppName } from "./app-name.js";
13
13
  import { signupAttributionFromCookieHeader } from "./attribution.js";
14
14
  import { addSession, getSession, getSessionMaxAge, hasLegacySessionForEmail, setFrameworkSessionCookie, } from "./auth.js";
@@ -133,6 +133,11 @@ function getConfiguredOriginAllowlist() {
133
133
  }
134
134
  return out;
135
135
  }
136
+ /** Return whether a candidate is one of this deployment's configured origins. */
137
+ export function isConfiguredAppOrigin(value) {
138
+ const origin = normalizeOrigin(value);
139
+ return !!origin && getConfiguredOriginAllowlist().has(origin);
140
+ }
136
141
  function getWorkspaceCallbackOrigin() {
137
142
  const publicAuthOrigin = firstOriginFromEnv(EXPLICIT_PUBLIC_ORIGIN_ENV_KEYS, {
138
143
  allowLoopback: true,
@@ -229,7 +234,11 @@ export function getOrigin(event) {
229
234
  }
230
235
  /** App mount prefix, if the template is served under APP_BASE_PATH. */
231
236
  export function getAppBasePath() {
232
- return getConfiguredAppBasePath();
237
+ // Vite statically replaces VITE_* values in the server bundle during the
238
+ // build, but Netlify/Nitro does not necessarily expose those build vars at
239
+ // runtime. Keep auth and OAuth path matching aligned with the SSR handler by
240
+ // falling back to import.meta.env (including BASE_URL).
241
+ return getAppBasePathFromViteEnv();
233
242
  }
234
243
  /** Build an absolute same-origin URL that preserves APP_BASE_PATH. */
235
244
  export function getAppUrl(event, path = "/") {