@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
@@ -322,19 +322,17 @@ async function addRemoteServerInternal(scope, scopeId, input) {
322
322
  function normalizeEndpointPath(pathname) {
323
323
  return pathname.replace(/\/+$/, "") || "/";
324
324
  }
325
- function expectedFirstPartyMcpUrl(appUrl) {
325
+ function expectedFirstPartyMcpUrls(appUrl) {
326
326
  try {
327
- return new URL(`${appUrl.replace(/\/+$/, "")}/_agent-native/mcp`);
327
+ const base = appUrl.replace(/\/+$/, "");
328
+ return [new URL(`${base}/mcp`), new URL(`${base}/_agent-native/mcp`)];
328
329
  }
329
330
  catch {
330
- return null;
331
+ return [];
331
332
  }
332
333
  }
333
334
  function sameFirstPartyMcpEndpoint(endpointUrl, appUrl) {
334
- const expected = expectedFirstPartyMcpUrl(appUrl);
335
- if (!expected)
336
- return false;
337
- return (endpointUrl.origin === expected.origin &&
335
+ return expectedFirstPartyMcpUrls(appUrl).some((expected) => endpointUrl.origin === expected.origin &&
338
336
  normalizeEndpointPath(endpointUrl.pathname) ===
339
337
  normalizeEndpointPath(expected.pathname) &&
340
338
  endpointUrl.search === expected.search);
@@ -1 +1 @@
1
- {"version":3,"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C,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC7C,CAAC;IACD,MAAM,CAAC,GAAG,+BAA+B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACpD,IAAI,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IACpB,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACpB,wEAAwE;IACxE,yEAAyE;IACzE,MAAM,KAAK,GAAmB,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;IACjE,OAAO;QACL,KAAK;QACL,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;QACX,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;KACX,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Persistent store for user-added remote MCP servers.\n *\n * Servers added through the settings UI live in the framework's `settings`\n * table, keyed by scope:\n * - User scope: `u:<email>:mcp-servers-remote`\n * - Org scope: `o:<orgId>:mcp-servers-remote`\n *\n * Both scopes store the same shape — a list of `StoredRemoteMcpServer`\n * records. The running MCP manager merges this list with the file-based\n * `mcp.config.json` on startup and after every mutation.\n *\n * SECURITY: HTTP MCP servers commonly require a bearer token in the\n * `Authorization` header. Those values are written to the encrypted\n * `app_secrets` table (AES-256-GCM via writeAppSecret). The settings row\n * stores only the secret-key reference (`headerSecretKey`), not the raw\n * value. Callers retrieving headers must call `materializeHeaders` to\n * fetch the cleartext at request time. Legacy rows that wrote headers\n * cleartext into `headers` continue to work read-only — they should be\n * re-saved to migrate.\n */\n\nimport { createHash } from \"node:crypto\";\n\nimport type { SecretScope } from \"../secrets/register.js\";\nimport {\n writeAppSecret,\n readAppSecret,\n deleteAppSecret,\n} from \"../secrets/storage.js\";\nimport {\n getOrgSetting,\n putOrgSetting,\n deleteOrgSetting,\n} from \"../settings/org-settings.js\";\nimport {\n getUserSetting,\n putUserSetting,\n deleteUserSetting,\n} from \"../settings/user-settings.js\";\nimport type { McpHttpServerConfig } from \"./config.js\";\n\nconst SETTINGS_KEY = \"mcp-servers-remote\";\n\nexport type RemoteMcpScope = \"user\" | \"org\";\n\nfunction toSecretScope(scope: RemoteMcpScope): SecretScope {\n return scope === \"user\" ? \"user\" : \"workspace\";\n}\n\nexport interface StoredRemoteMcpServer {\n /** Stable unique id — used for removal / URLs. */\n id: string;\n /** Human-readable name. Also used as the MCP server id (prefixed with scope). */\n name: string;\n /** Streamable HTTP MCP server URL. */\n url: string;\n /**\n * Optional non-secret headers to pass to the MCP server. SECURITY: secret\n * material (Authorization, X-Api-Key, …) is moved out of this field at\n * write time and stored encrypted in `app_secrets`; see\n * `headerSecretKey`. Legacy rows may still contain cleartext headers and\n * are honored read-only.\n */\n headers?: Record<string, string>;\n /**\n * Reference to the encrypted secret holding the JSON-stringified secret\n * headers map (e.g. `{\"Authorization\":\"Bearer …\"}`). Resolved at request\n * time via `readAppSecret`. Undefined when no secret-class headers were\n * supplied (or for legacy cleartext rows).\n */\n headerSecretKey?: string;\n /**\n * Trusted first-party Agent-Native app. Only framework-controlled\n * registrations should set this; management routes intentionally do not\n * expose it for arbitrary user-added MCP servers.\n */\n firstParty?: boolean;\n /** Canonical first-party app id from the org directory, e.g. `assets`. */\n firstPartyAppId?: string;\n /** Optional description shown in the UI. */\n description?: string;\n /** ms since epoch. */\n createdAt: number;\n}\n\n/**\n * Header names that are routed through the encrypted-at-rest secrets store\n * instead of being written to the plaintext `settings` row. Match is\n * case-insensitive and substring-based to catch one-off names like\n * `x-zapier-api-key`.\n */\nconst SECRET_HEADER_NAME_PATTERNS = [\n /authorization/i,\n /api[-_]?key/i,\n /token/i,\n /secret/i,\n /bearer/i,\n /x-.*-key/i,\n];\n\nfunction isSecretHeaderName(name: string): boolean {\n return SECRET_HEADER_NAME_PATTERNS.some((re) => re.test(name));\n}\n\n/** Split a headers map into (cleartext, secret) buckets. */\nfunction partitionHeaders(headers: Record<string, string> | undefined): {\n cleartext: Record<string, string> | undefined;\n secret: Record<string, string> | undefined;\n} {\n if (!headers) return { cleartext: undefined, secret: undefined };\n const cleartext: Record<string, string> = {};\n const secret: Record<string, string> = {};\n for (const [k, v] of Object.entries(headers)) {\n if (typeof v !== \"string\") continue;\n if (isSecretHeaderName(k)) secret[k] = v;\n else cleartext[k] = v;\n }\n return {\n cleartext: Object.keys(cleartext).length > 0 ? cleartext : undefined,\n secret: Object.keys(secret).length > 0 ? secret : undefined,\n };\n}\n\n/** Tiny nanoid — matches the inline helper used elsewhere in this package. */\nfunction shortId(): string {\n const rand =\n globalThis.crypto?.randomUUID?.().replace(/-/g, \"\") ??\n Math.random().toString(36).slice(2) + Date.now().toString(36);\n return rand.slice(0, 16);\n}\n\n/**\n * Validate a candidate MCP server name — used as a key in the merged config\n * and as part of the prefixed tool name (`mcp__<merged-key>__<tool>`).\n *\n * Allowed: letters, digits, hyphen; 1–40 chars. Lowercased. Underscores are\n * excluded on purpose — the merged-key format uses `_` as a separator between\n * `<scope>`, `<owner>`, and `<name>`, so allowing `_` in names would make the\n * parse ambiguous.\n */\nexport function normalizeServerName(input: string): string {\n return input\n .trim()\n .toLowerCase()\n .replace(/[^a-z0-9-]/g, \"-\")\n .slice(0, 40);\n}\n\n/**\n * Short, deterministic, URL-safe hash of an email. Used as the owner\n * discriminator in user-scope merged keys so two users with the same server\n * name don't collide in the global MCP manager.\n */\nexport function hashEmail(email: string): string {\n return createHash(\"sha256\")\n .update(email.toLowerCase().trim())\n .digest(\"hex\")\n .slice(0, 10);\n}\n\n/**\n * Sanitise an org id to the character set allowed in merged keys.\n * Org ids are already nanoid-style alphanumeric, but we normalise defensively.\n */\nfunction sanitiseOrgId(orgId: string): string {\n return orgId.toLowerCase().replace(/[^a-z0-9-]/g, \"-\");\n}\n\n/**\n * Hostname patterns that are always rejected to prevent SSRF via DNS rebinding\n * or well-known internal service names.\n */\nconst BLOCKED_HOSTNAME_PATTERNS: RegExp[] = [\n /^localhost$/i,\n /\\.localhost$/i,\n /\\.local$/i,\n /\\.internal$/i,\n // DNS rebind services\n /\\.nip\\.io$/i,\n /\\.sslip\\.io$/i,\n /\\.xip\\.io$/i,\n /\\.localtest\\.me$/i,\n /\\.lvh\\.me$/i,\n // Cloud metadata hosts\n /^metadata\\.google\\.internal$/i,\n /^instance-data$/i,\n];\n\n/** Literal IPs that are always rejected (cloud metadata endpoints). */\nconst BLOCKED_IPS = new Set([\n \"169.254.169.254\", // AWS/GCP/Azure IMDS\n \"100.100.100.200\", // Alibaba Cloud metadata\n \"::1\",\n]);\n\n/** Parse a dotted-decimal IPv4 string to a 32-bit integer for range checks. */\nfunction ipv4ToInt(ip: string): number | null {\n const parts = ip.split(\".\");\n if (parts.length !== 4) return null;\n let n = 0;\n for (const part of parts) {\n const byte = parseInt(part, 10);\n if (isNaN(byte) || byte < 0 || byte > 255) return null;\n n = (n << 8) | byte;\n }\n return n >>> 0;\n}\n\nfunction isPrivateIpv4(hostname: string): boolean {\n const n = ipv4ToInt(hostname);\n if (n === null) return false;\n // 10.0.0.0/8\n if ((n & 0xff000000) >>> 0 === 0x0a000000) return true;\n // 172.16.0.0/12\n if ((n & 0xfff00000) >>> 0 === 0xac100000) return true;\n // 192.168.0.0/16\n if ((n & 0xffff0000) >>> 0 === 0xc0a80000) return true;\n // 169.254.0.0/16 (link-local, includes AWS/GCP metadata)\n if ((n & 0xffff0000) >>> 0 === 0xa9fe0000) return true;\n // 127.0.0.0/8 (loopback)\n if ((n & 0xff000000) >>> 0 === 0x7f000000) return true;\n return false;\n}\n\nfunction isBlockedHostname(hostname: string): boolean {\n const normalized = hostname.toLowerCase().replace(/^\\[|\\]$/g, \"\");\n if (BLOCKED_IPS.has(normalized)) return true;\n if (isPrivateIpv4(normalized)) return true;\n // IPv6 ULA (fc00::/7) and link-local (fe80::/10)\n if (normalized === \"::1\") return true;\n if (normalized.startsWith(\"fc\") || normalized.startsWith(\"fd\")) return true;\n if (normalized.startsWith(\"fe80\")) return true;\n if (normalized.startsWith(\"::ffff:\")) {\n const mapped = normalized.slice(\"::ffff:\".length);\n if (isPrivateIpv4(mapped)) return true;\n const hexMatch = /^([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i.exec(mapped);\n if (hexMatch) {\n const value =\n (parseInt(hexMatch[1], 16) << 16) | parseInt(hexMatch[2], 16);\n const dotted = [\n (value >>> 24) & 0xff,\n (value >>> 16) & 0xff,\n (value >>> 8) & 0xff,\n value & 0xff,\n ].join(\".\");\n if (isPrivateIpv4(dotted)) return true;\n }\n }\n for (const pattern of BLOCKED_HOSTNAME_PATTERNS) {\n if (pattern.test(normalized)) return true;\n }\n return false;\n}\n\n/** Reject obviously-wrong URLs. Allows http only for localhost. */\nexport function validateRemoteUrl(raw: string): {\n ok: boolean;\n url?: URL;\n error?: string;\n} {\n let url: URL;\n try {\n url = new URL(raw);\n } catch {\n return { ok: false, error: \"Not a valid URL\" };\n }\n if (url.protocol === \"https:\") {\n if (isBlockedHostname(url.hostname)) {\n return {\n ok: false,\n error: `Host \"${url.hostname}\" is not allowed (private/internal address)`,\n };\n }\n return { ok: true, url };\n }\n if (url.protocol === \"http:\") {\n const host = url.hostname;\n if (host === \"localhost\" || host === \"127.0.0.1\") {\n return { ok: true, url };\n }\n return { ok: false, error: \"Plain http is only allowed for localhost\" };\n }\n return { ok: false, error: `Unsupported protocol: ${url.protocol}` };\n}\n\nasync function readList(\n scope: RemoteMcpScope,\n scopeId: string,\n): Promise<StoredRemoteMcpServer[]> {\n const raw =\n scope === \"user\"\n ? await getUserSetting(scopeId, SETTINGS_KEY)\n : await getOrgSetting(scopeId, SETTINGS_KEY);\n if (!raw || !Array.isArray((raw as any).servers)) return [];\n return ((raw as any).servers as StoredRemoteMcpServer[]).filter(\n (s) => s && typeof s.id === \"string\" && typeof s.url === \"string\",\n );\n}\n\nasync function writeList(\n scope: RemoteMcpScope,\n scopeId: string,\n servers: StoredRemoteMcpServer[],\n): Promise<void> {\n if (scope === \"user\") {\n await putUserSetting(scopeId, SETTINGS_KEY, { servers });\n } else {\n await putOrgSetting(scopeId, SETTINGS_KEY, { servers });\n }\n}\n\nexport async function listRemoteServers(\n scope: RemoteMcpScope,\n scopeId: string,\n): Promise<StoredRemoteMcpServer[]> {\n return readList(scope, scopeId);\n}\n\nexport async function addRemoteServer(\n scope: RemoteMcpScope,\n scopeId: string,\n input: {\n name: string;\n url: string;\n headers?: Record<string, string>;\n description?: string;\n firstParty?: boolean;\n },\n): Promise<\n { ok: true; server: StoredRemoteMcpServer } | { ok: false; error: string }\n> {\n if (input.firstParty) {\n return {\n ok: false,\n error:\n \"First-party MCP servers must be registered through the trusted first-party registration path\",\n };\n }\n return addRemoteServerInternal(scope, scopeId, input);\n}\n\nexport async function addFirstPartyRemoteServer(\n orgId: string,\n input: {\n appId: string;\n name: string;\n url: string;\n description?: string;\n },\n): Promise<\n { ok: true; server: StoredRemoteMcpServer } | { ok: false; error: string }\n> {\n const trust = await isFirstPartyRemoteEndpointTrusted(\n orgId,\n input.appId,\n input.url,\n );\n if (!trust.ok) return { ok: false, error: trust.error };\n return addRemoteServerInternal(\"org\", orgId, {\n name: input.name,\n url: input.url,\n description: input.description,\n firstParty: true,\n firstPartyAppId: input.appId.trim().toLowerCase(),\n });\n}\n\nasync function addRemoteServerInternal(\n scope: RemoteMcpScope,\n scopeId: string,\n input: {\n name: string;\n url: string;\n headers?: Record<string, string>;\n description?: string;\n firstParty?: boolean;\n firstPartyAppId?: string;\n },\n): Promise<\n { ok: true; server: StoredRemoteMcpServer } | { ok: false; error: string }\n> {\n const name = normalizeServerName(input.name);\n if (!name) return { ok: false, error: \"Name is required\" };\n if (input.firstParty && scope !== \"org\") {\n return { ok: false, error: \"First-party MCP servers must be org-scoped\" };\n }\n const urlCheck = validateRemoteUrl(input.url);\n if (!urlCheck.ok) return { ok: false, error: urlCheck.error ?? \"Bad URL\" };\n\n const existing = await readList(scope, scopeId);\n if (existing.some((s) => s.name === name)) {\n return { ok: false, error: `A server named \"${name}\" already exists` };\n }\n\n const id = `mcps_${shortId()}`;\n const { cleartext, secret } = partitionHeaders(input.headers);\n\n // Persist secret-class headers in the encrypted secrets table; the\n // settings row only references the secret key, never the cleartext.\n let headerSecretKey: string | undefined;\n if (secret) {\n headerSecretKey = `mcp_headers:${id}`;\n try {\n await writeAppSecret({\n key: headerSecretKey,\n value: JSON.stringify(secret),\n scope: toSecretScope(scope),\n scopeId,\n description: `Encrypted MCP headers for ${name}`,\n });\n } catch (err: any) {\n return {\n ok: false,\n error: `Failed to encrypt MCP headers: ${err?.message ?? err}`,\n };\n }\n }\n\n const server: StoredRemoteMcpServer = {\n id,\n name,\n url: urlCheck.url!.toString(),\n headers: cleartext,\n headerSecretKey,\n ...(input.firstParty ? { firstParty: true } : {}),\n ...(input.firstPartyAppId\n ? { firstPartyAppId: input.firstPartyAppId }\n : {}),\n description: input.description?.trim() || undefined,\n createdAt: Date.now(),\n };\n await writeList(scope, scopeId, [...existing, server]);\n return { ok: true, server };\n}\n\nfunction normalizeEndpointPath(pathname: string): string {\n return pathname.replace(/\\/+$/, \"\") || \"/\";\n}\n\nfunction expectedFirstPartyMcpUrl(appUrl: string): URL | null {\n try {\n return new URL(`${appUrl.replace(/\\/+$/, \"\")}/_agent-native/mcp`);\n } catch {\n return null;\n }\n}\n\nfunction sameFirstPartyMcpEndpoint(endpointUrl: URL, appUrl: string): boolean {\n const expected = expectedFirstPartyMcpUrl(appUrl);\n if (!expected) return false;\n return (\n endpointUrl.origin === expected.origin &&\n normalizeEndpointPath(endpointUrl.pathname) ===\n normalizeEndpointPath(expected.pathname) &&\n endpointUrl.search === expected.search\n );\n}\n\nexport async function isFirstPartyRemoteEndpointTrusted(\n orgId: string,\n appId: string,\n endpoint: string,\n): Promise<{ ok: true } | { ok: false; error: string }> {\n const normalizedAppId = appId.trim().toLowerCase();\n if (!orgId.trim()) {\n return { ok: false, error: \"Organization id is required\" };\n }\n if (!normalizedAppId) {\n return { ok: false, error: \"First-party app id is required\" };\n }\n\n let endpointUrl: URL;\n try {\n endpointUrl = new URL(endpoint);\n } catch {\n return { ok: false, error: \"Not a valid URL\" };\n }\n\n try {\n const { getRequestOrgId } = await import(\"../server/request-context.js\");\n const requestOrgId = getRequestOrgId();\n if (requestOrgId && requestOrgId !== orgId) {\n return {\n ok: false,\n error:\n \"First-party MCP server org does not match the active request organization\",\n };\n }\n } catch {\n // No request context helper available: the org-directory lookup below will\n // still fail closed if it cannot authenticate a first-party app list.\n }\n\n const { fetchOrgApps } = await import(\"../mcp/org-directory.js\");\n const apps = await fetchOrgApps({ serviceOrgId: orgId });\n const app = apps.find((candidate) => candidate.id === normalizedAppId);\n if (!app) {\n return {\n ok: false,\n error: \"Could not verify the first-party app in the org directory\",\n };\n }\n if (!sameFirstPartyMcpEndpoint(endpointUrl, app.url)) {\n return {\n ok: false,\n error:\n \"First-party MCP URL does not match the org-directory app endpoint\",\n };\n }\n return { ok: true };\n}\n\nexport async function removeRemoteServer(\n scope: RemoteMcpScope,\n scopeId: string,\n id: string,\n): Promise<boolean> {\n const existing = await readList(scope, scopeId);\n const removed = existing.find((s) => s.id === id);\n const next = existing.filter((s) => s.id !== id);\n if (next.length === existing.length) return false;\n if (next.length === 0) {\n if (scope === \"user\") {\n await deleteUserSetting(scopeId, SETTINGS_KEY);\n } else {\n await deleteOrgSetting(scopeId, SETTINGS_KEY);\n }\n } else {\n await writeList(scope, scopeId, next);\n }\n // Best-effort: drop the encrypted-headers secret too. Errors are logged\n // but don't fail the deletion — the settings row is already gone, so a\n // dangling secret is harmless (it just can't be read back).\n if (removed?.headerSecretKey) {\n try {\n await deleteAppSecret({\n key: removed.headerSecretKey,\n scope: toSecretScope(scope),\n scopeId,\n });\n } catch (err: any) {\n // eslint-disable-next-line no-console\n console.warn(\n `[mcp-client] Failed to delete MCP header secret ${removed.headerSecretKey}: ${err?.message ?? err}`,\n );\n }\n }\n return true;\n}\n\n/**\n * Resolve the full headers map (cleartext + decrypted secret headers) for a\n * stored MCP server. Used when projecting the stored record into the\n * runtime `McpHttpServerConfig` shape that `McpClientManager` consumes.\n *\n * For legacy rows that wrote secrets cleartext into `headers`, this\n * returns those cleartext values unchanged — they should be re-saved\n * through `addRemoteServer` to migrate to encrypted storage.\n */\nexport async function materializeHeaders(\n scope: RemoteMcpScope,\n scopeId: string,\n stored: StoredRemoteMcpServer,\n): Promise<Record<string, string> | undefined> {\n const merged: Record<string, string> = { ...(stored.headers ?? {}) };\n if (stored.headerSecretKey) {\n try {\n const secret = await readAppSecret({\n key: stored.headerSecretKey,\n scope: toSecretScope(scope),\n scopeId,\n });\n if (secret) {\n const parsed = JSON.parse(secret.value) as Record<string, string>;\n for (const [k, v] of Object.entries(parsed)) {\n if (typeof v === \"string\") merged[k] = v;\n }\n }\n } catch (err: any) {\n // eslint-disable-next-line no-console\n console.warn(\n `[mcp-client] Failed to decrypt MCP headers for ${stored.name}: ${err?.message ?? err}`,\n );\n }\n }\n return Object.keys(merged).length > 0 ? merged : undefined;\n}\n\n/**\n * Project a stored server into the runtime `McpHttpServerConfig` shape that\n * `McpClientManager` consumes. The merged-config key is the scope + name\n * so a user-scope and org-scope server can both share a readable name\n * without clobbering each other.\n *\n * SECURITY: when the stored row references encrypted headers\n * (`headerSecretKey`), callers should use `toHttpServerConfigAsync`\n * instead — this synchronous variant returns ONLY the cleartext headers\n * already present on the row. Returning the row's literal headers without\n * the secret material means the runtime client would call the MCP server\n * without auth (request will fail), but never leaks the encrypted secret.\n */\nexport function toHttpServerConfig(\n stored: StoredRemoteMcpServer,\n): McpHttpServerConfig {\n return {\n type: \"http\",\n url: stored.url,\n headers: stored.headers,\n ...(stored.firstParty ? { firstParty: true } : {}),\n ...(stored.firstPartyAppId\n ? { firstPartyAppId: stored.firstPartyAppId }\n : {}),\n description: stored.description,\n };\n}\n\n/**\n * Async variant of `toHttpServerConfig` that resolves any encrypted\n * `headerSecretKey` reference from `app_secrets` and returns the full\n * cleartext headers map for use at runtime. Use this when actually\n * configuring an MCP client; use the sync variant only when serializing\n * stored data (e.g. for read-only listings that shouldn't disclose\n * secrets).\n */\nexport async function toHttpServerConfigAsync(\n scope: RemoteMcpScope,\n scopeId: string,\n stored: StoredRemoteMcpServer,\n): Promise<McpHttpServerConfig> {\n return {\n type: \"http\",\n url: stored.url,\n headers: await materializeHeaders(scope, scopeId, stored),\n ...(stored.firstParty ? { firstParty: true } : {}),\n ...(stored.firstPartyAppId\n ? { firstPartyAppId: stored.firstPartyAppId }\n : {}),\n ...(stored.firstParty && scope === \"org\"\n ? { firstPartyOrgId: scopeId }\n : {}),\n description: stored.description,\n };\n}\n\n/**\n * Build the merged-config key for a stored server.\n *\n * The key encodes the owning scope + owner identity so two users adding a\n * server called `zapier` produce distinct ids (`user_ab12cd34ef_zapier` vs\n * `user_99aa88bb77_zapier`) and Alice's tool calls never route through Bob's\n * credentials in a shared-process deployment.\n *\n * - User scope: `user_<emailhash>_<name>`\n * - Org scope: `org_<orgId>_<name>`\n *\n * `ownerId` is the raw email for user scope, and the org id for org scope.\n */\nexport function mergedConfigKey(\n scope: RemoteMcpScope,\n stored: StoredRemoteMcpServer,\n ownerId: string,\n): string {\n const owner = scope === \"user\" ? hashEmail(ownerId) : sanitiseOrgId(ownerId);\n return `${scope}_${owner}_${stored.name}`;\n}\n\n/**\n * Parse a merged key (or a full prefixed tool name like\n * `mcp__user_abcd1234ef_zapier__run-task`) back into its scope + owner + name\n * components. Returns null for non-merged keys (e.g. stdio file-config servers\n * like `claude-in-chrome`) so callers can treat them as always-visible.\n *\n * `hub_<orgId>_<name>` entries (pulled from a remote hub via\n * `hub-client.ts`) project to `scope: \"org\"` so they pass through the same\n * per-request visibility gate as locally-stored org servers — the tool is\n * only visible to requests whose active org matches the hub entry's org.\n */\nexport function parseMergedKey(\n keyOrToolName: string,\n): { scope: RemoteMcpScope; owner: string; name: string } | null {\n let key = keyOrToolName;\n if (key.startsWith(\"mcp__\")) {\n const rest = key.slice(\"mcp__\".length);\n const idx = rest.indexOf(\"__\");\n key = idx >= 0 ? rest.slice(0, idx) : rest;\n }\n const m = /^(user|org|hub)_([^_]+)_(.+)$/.exec(key);\n if (!m) return null;\n const prefix = m[1];\n // Hub-sourced servers are scoped to the org they came from — treat them\n // as org-scope for visibility purposes (see isMcpToolAllowedForRequest).\n const scope: RemoteMcpScope = prefix === \"user\" ? \"user\" : \"org\";\n return {\n scope,\n owner: m[2],\n name: m[3],\n };\n}\n"]}
1
+ {"version":3,"file":"remote-store.js","sourceRoot":"","sources":["../../src/mcp-client/remote-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EACL,cAAc,EACd,aAAa,EACb,eAAe,GAChB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,aAAa,EACb,aAAa,EACb,gBAAgB,GACjB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,cAAc,EACd,cAAc,EACd,iBAAiB,GAClB,MAAM,8BAA8B,CAAC;AAGtC,MAAM,YAAY,GAAG,oBAAoB,CAAC;AAI1C,SAAS,aAAa,CAAC,KAAqB;IAC1C,OAAO,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC;AACjD,CAAC;AAsCD;;;;;GAKG;AACH,MAAM,2BAA2B,GAAG;IAClC,gBAAgB;IAChB,cAAc;IACd,QAAQ;IACR,SAAS;IACT,SAAS;IACT,WAAW;CACZ,CAAC;AAEF,SAAS,kBAAkB,CAAC,IAAY;IACtC,OAAO,2BAA2B,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AACjE,CAAC;AAED,4DAA4D;AAC5D,SAAS,gBAAgB,CAAC,OAA2C;IAInE,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IACjE,MAAM,SAAS,GAA2B,EAAE,CAAC;IA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IACxB,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACvC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/B,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC7C,CAAC;IACD,MAAM,CAAC,GAAG,+BAA+B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACpD,IAAI,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IACpB,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACpB,wEAAwE;IACxE,yEAAyE;IACzE,MAAM,KAAK,GAAmB,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;IACjE,OAAO;QACL,KAAK;QACL,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;QACX,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;KACX,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Persistent store for user-added remote MCP servers.\n *\n * Servers added through the settings UI live in the framework's `settings`\n * table, keyed by scope:\n * - User scope: `u:<email>:mcp-servers-remote`\n * - Org scope: `o:<orgId>:mcp-servers-remote`\n *\n * Both scopes store the same shape — a list of `StoredRemoteMcpServer`\n * records. The running MCP manager merges this list with the file-based\n * `mcp.config.json` on startup and after every mutation.\n *\n * SECURITY: HTTP MCP servers commonly require a bearer token in the\n * `Authorization` header. Those values are written to the encrypted\n * `app_secrets` table (AES-256-GCM via writeAppSecret). The settings row\n * stores only the secret-key reference (`headerSecretKey`), not the raw\n * value. Callers retrieving headers must call `materializeHeaders` to\n * fetch the cleartext at request time. Legacy rows that wrote headers\n * cleartext into `headers` continue to work read-only — they should be\n * re-saved to migrate.\n */\n\nimport { createHash } from \"node:crypto\";\n\nimport type { SecretScope } from \"../secrets/register.js\";\nimport {\n writeAppSecret,\n readAppSecret,\n deleteAppSecret,\n} from \"../secrets/storage.js\";\nimport {\n getOrgSetting,\n putOrgSetting,\n deleteOrgSetting,\n} from \"../settings/org-settings.js\";\nimport {\n getUserSetting,\n putUserSetting,\n deleteUserSetting,\n} from \"../settings/user-settings.js\";\nimport type { McpHttpServerConfig } from \"./config.js\";\n\nconst SETTINGS_KEY = \"mcp-servers-remote\";\n\nexport type RemoteMcpScope = \"user\" | \"org\";\n\nfunction toSecretScope(scope: RemoteMcpScope): SecretScope {\n return scope === \"user\" ? \"user\" : \"workspace\";\n}\n\nexport interface StoredRemoteMcpServer {\n /** Stable unique id — used for removal / URLs. */\n id: string;\n /** Human-readable name. Also used as the MCP server id (prefixed with scope). */\n name: string;\n /** Streamable HTTP MCP server URL. */\n url: string;\n /**\n * Optional non-secret headers to pass to the MCP server. SECURITY: secret\n * material (Authorization, X-Api-Key, …) is moved out of this field at\n * write time and stored encrypted in `app_secrets`; see\n * `headerSecretKey`. Legacy rows may still contain cleartext headers and\n * are honored read-only.\n */\n headers?: Record<string, string>;\n /**\n * Reference to the encrypted secret holding the JSON-stringified secret\n * headers map (e.g. `{\"Authorization\":\"Bearer …\"}`). Resolved at request\n * time via `readAppSecret`. Undefined when no secret-class headers were\n * supplied (or for legacy cleartext rows).\n */\n headerSecretKey?: string;\n /**\n * Trusted first-party Agent-Native app. Only framework-controlled\n * registrations should set this; management routes intentionally do not\n * expose it for arbitrary user-added MCP servers.\n */\n firstParty?: boolean;\n /** Canonical first-party app id from the org directory, e.g. `assets`. */\n firstPartyAppId?: string;\n /** Optional description shown in the UI. */\n description?: string;\n /** ms since epoch. */\n createdAt: number;\n}\n\n/**\n * Header names that are routed through the encrypted-at-rest secrets store\n * instead of being written to the plaintext `settings` row. Match is\n * case-insensitive and substring-based to catch one-off names like\n * `x-zapier-api-key`.\n */\nconst SECRET_HEADER_NAME_PATTERNS = [\n /authorization/i,\n /api[-_]?key/i,\n /token/i,\n /secret/i,\n /bearer/i,\n /x-.*-key/i,\n];\n\nfunction isSecretHeaderName(name: string): boolean {\n return SECRET_HEADER_NAME_PATTERNS.some((re) => re.test(name));\n}\n\n/** Split a headers map into (cleartext, secret) buckets. */\nfunction partitionHeaders(headers: Record<string, string> | undefined): {\n cleartext: Record<string, string> | undefined;\n secret: Record<string, string> | undefined;\n} {\n if (!headers) return { cleartext: undefined, secret: undefined };\n const cleartext: Record<string, string> = {};\n const secret: Record<string, string> = {};\n for (const [k, v] of Object.entries(headers)) {\n if (typeof v !== \"string\") continue;\n if (isSecretHeaderName(k)) secret[k] = v;\n else cleartext[k] = v;\n }\n return {\n cleartext: Object.keys(cleartext).length > 0 ? cleartext : undefined,\n secret: Object.keys(secret).length > 0 ? secret : undefined,\n };\n}\n\n/** Tiny nanoid — matches the inline helper used elsewhere in this package. */\nfunction shortId(): string {\n const rand =\n globalThis.crypto?.randomUUID?.().replace(/-/g, \"\") ??\n Math.random().toString(36).slice(2) + Date.now().toString(36);\n return rand.slice(0, 16);\n}\n\n/**\n * Validate a candidate MCP server name — used as a key in the merged config\n * and as part of the prefixed tool name (`mcp__<merged-key>__<tool>`).\n *\n * Allowed: letters, digits, hyphen; 1–40 chars. Lowercased. Underscores are\n * excluded on purpose — the merged-key format uses `_` as a separator between\n * `<scope>`, `<owner>`, and `<name>`, so allowing `_` in names would make the\n * parse ambiguous.\n */\nexport function normalizeServerName(input: string): string {\n return input\n .trim()\n .toLowerCase()\n .replace(/[^a-z0-9-]/g, \"-\")\n .slice(0, 40);\n}\n\n/**\n * Short, deterministic, URL-safe hash of an email. Used as the owner\n * discriminator in user-scope merged keys so two users with the same server\n * name don't collide in the global MCP manager.\n */\nexport function hashEmail(email: string): string {\n return createHash(\"sha256\")\n .update(email.toLowerCase().trim())\n .digest(\"hex\")\n .slice(0, 10);\n}\n\n/**\n * Sanitise an org id to the character set allowed in merged keys.\n * Org ids are already nanoid-style alphanumeric, but we normalise defensively.\n */\nfunction sanitiseOrgId(orgId: string): string {\n return orgId.toLowerCase().replace(/[^a-z0-9-]/g, \"-\");\n}\n\n/**\n * Hostname patterns that are always rejected to prevent SSRF via DNS rebinding\n * or well-known internal service names.\n */\nconst BLOCKED_HOSTNAME_PATTERNS: RegExp[] = [\n /^localhost$/i,\n /\\.localhost$/i,\n /\\.local$/i,\n /\\.internal$/i,\n // DNS rebind services\n /\\.nip\\.io$/i,\n /\\.sslip\\.io$/i,\n /\\.xip\\.io$/i,\n /\\.localtest\\.me$/i,\n /\\.lvh\\.me$/i,\n // Cloud metadata hosts\n /^metadata\\.google\\.internal$/i,\n /^instance-data$/i,\n];\n\n/** Literal IPs that are always rejected (cloud metadata endpoints). */\nconst BLOCKED_IPS = new Set([\n \"169.254.169.254\", // AWS/GCP/Azure IMDS\n \"100.100.100.200\", // Alibaba Cloud metadata\n \"::1\",\n]);\n\n/** Parse a dotted-decimal IPv4 string to a 32-bit integer for range checks. */\nfunction ipv4ToInt(ip: string): number | null {\n const parts = ip.split(\".\");\n if (parts.length !== 4) return null;\n let n = 0;\n for (const part of parts) {\n const byte = parseInt(part, 10);\n if (isNaN(byte) || byte < 0 || byte > 255) return null;\n n = (n << 8) | byte;\n }\n return n >>> 0;\n}\n\nfunction isPrivateIpv4(hostname: string): boolean {\n const n = ipv4ToInt(hostname);\n if (n === null) return false;\n // 10.0.0.0/8\n if ((n & 0xff000000) >>> 0 === 0x0a000000) return true;\n // 172.16.0.0/12\n if ((n & 0xfff00000) >>> 0 === 0xac100000) return true;\n // 192.168.0.0/16\n if ((n & 0xffff0000) >>> 0 === 0xc0a80000) return true;\n // 169.254.0.0/16 (link-local, includes AWS/GCP metadata)\n if ((n & 0xffff0000) >>> 0 === 0xa9fe0000) return true;\n // 127.0.0.0/8 (loopback)\n if ((n & 0xff000000) >>> 0 === 0x7f000000) return true;\n return false;\n}\n\nfunction isBlockedHostname(hostname: string): boolean {\n const normalized = hostname.toLowerCase().replace(/^\\[|\\]$/g, \"\");\n if (BLOCKED_IPS.has(normalized)) return true;\n if (isPrivateIpv4(normalized)) return true;\n // IPv6 ULA (fc00::/7) and link-local (fe80::/10)\n if (normalized === \"::1\") return true;\n if (normalized.startsWith(\"fc\") || normalized.startsWith(\"fd\")) return true;\n if (normalized.startsWith(\"fe80\")) return true;\n if (normalized.startsWith(\"::ffff:\")) {\n const mapped = normalized.slice(\"::ffff:\".length);\n if (isPrivateIpv4(mapped)) return true;\n const hexMatch = /^([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i.exec(mapped);\n if (hexMatch) {\n const value =\n (parseInt(hexMatch[1], 16) << 16) | parseInt(hexMatch[2], 16);\n const dotted = [\n (value >>> 24) & 0xff,\n (value >>> 16) & 0xff,\n (value >>> 8) & 0xff,\n value & 0xff,\n ].join(\".\");\n if (isPrivateIpv4(dotted)) return true;\n }\n }\n for (const pattern of BLOCKED_HOSTNAME_PATTERNS) {\n if (pattern.test(normalized)) return true;\n }\n return false;\n}\n\n/** Reject obviously-wrong URLs. Allows http only for localhost. */\nexport function validateRemoteUrl(raw: string): {\n ok: boolean;\n url?: URL;\n error?: string;\n} {\n let url: URL;\n try {\n url = new URL(raw);\n } catch {\n return { ok: false, error: \"Not a valid URL\" };\n }\n if (url.protocol === \"https:\") {\n if (isBlockedHostname(url.hostname)) {\n return {\n ok: false,\n error: `Host \"${url.hostname}\" is not allowed (private/internal address)`,\n };\n }\n return { ok: true, url };\n }\n if (url.protocol === \"http:\") {\n const host = url.hostname;\n if (host === \"localhost\" || host === \"127.0.0.1\") {\n return { ok: true, url };\n }\n return { ok: false, error: \"Plain http is only allowed for localhost\" };\n }\n return { ok: false, error: `Unsupported protocol: ${url.protocol}` };\n}\n\nasync function readList(\n scope: RemoteMcpScope,\n scopeId: string,\n): Promise<StoredRemoteMcpServer[]> {\n const raw =\n scope === \"user\"\n ? await getUserSetting(scopeId, SETTINGS_KEY)\n : await getOrgSetting(scopeId, SETTINGS_KEY);\n if (!raw || !Array.isArray((raw as any).servers)) return [];\n return ((raw as any).servers as StoredRemoteMcpServer[]).filter(\n (s) => s && typeof s.id === \"string\" && typeof s.url === \"string\",\n );\n}\n\nasync function writeList(\n scope: RemoteMcpScope,\n scopeId: string,\n servers: StoredRemoteMcpServer[],\n): Promise<void> {\n if (scope === \"user\") {\n await putUserSetting(scopeId, SETTINGS_KEY, { servers });\n } else {\n await putOrgSetting(scopeId, SETTINGS_KEY, { servers });\n }\n}\n\nexport async function listRemoteServers(\n scope: RemoteMcpScope,\n scopeId: string,\n): Promise<StoredRemoteMcpServer[]> {\n return readList(scope, scopeId);\n}\n\nexport async function addRemoteServer(\n scope: RemoteMcpScope,\n scopeId: string,\n input: {\n name: string;\n url: string;\n headers?: Record<string, string>;\n description?: string;\n firstParty?: boolean;\n },\n): Promise<\n { ok: true; server: StoredRemoteMcpServer } | { ok: false; error: string }\n> {\n if (input.firstParty) {\n return {\n ok: false,\n error:\n \"First-party MCP servers must be registered through the trusted first-party registration path\",\n };\n }\n return addRemoteServerInternal(scope, scopeId, input);\n}\n\nexport async function addFirstPartyRemoteServer(\n orgId: string,\n input: {\n appId: string;\n name: string;\n url: string;\n description?: string;\n },\n): Promise<\n { ok: true; server: StoredRemoteMcpServer } | { ok: false; error: string }\n> {\n const trust = await isFirstPartyRemoteEndpointTrusted(\n orgId,\n input.appId,\n input.url,\n );\n if (!trust.ok) return { ok: false, error: trust.error };\n return addRemoteServerInternal(\"org\", orgId, {\n name: input.name,\n url: input.url,\n description: input.description,\n firstParty: true,\n firstPartyAppId: input.appId.trim().toLowerCase(),\n });\n}\n\nasync function addRemoteServerInternal(\n scope: RemoteMcpScope,\n scopeId: string,\n input: {\n name: string;\n url: string;\n headers?: Record<string, string>;\n description?: string;\n firstParty?: boolean;\n firstPartyAppId?: string;\n },\n): Promise<\n { ok: true; server: StoredRemoteMcpServer } | { ok: false; error: string }\n> {\n const name = normalizeServerName(input.name);\n if (!name) return { ok: false, error: \"Name is required\" };\n if (input.firstParty && scope !== \"org\") {\n return { ok: false, error: \"First-party MCP servers must be org-scoped\" };\n }\n const urlCheck = validateRemoteUrl(input.url);\n if (!urlCheck.ok) return { ok: false, error: urlCheck.error ?? \"Bad URL\" };\n\n const existing = await readList(scope, scopeId);\n if (existing.some((s) => s.name === name)) {\n return { ok: false, error: `A server named \"${name}\" already exists` };\n }\n\n const id = `mcps_${shortId()}`;\n const { cleartext, secret } = partitionHeaders(input.headers);\n\n // Persist secret-class headers in the encrypted secrets table; the\n // settings row only references the secret key, never the cleartext.\n let headerSecretKey: string | undefined;\n if (secret) {\n headerSecretKey = `mcp_headers:${id}`;\n try {\n await writeAppSecret({\n key: headerSecretKey,\n value: JSON.stringify(secret),\n scope: toSecretScope(scope),\n scopeId,\n description: `Encrypted MCP headers for ${name}`,\n });\n } catch (err: any) {\n return {\n ok: false,\n error: `Failed to encrypt MCP headers: ${err?.message ?? err}`,\n };\n }\n }\n\n const server: StoredRemoteMcpServer = {\n id,\n name,\n url: urlCheck.url!.toString(),\n headers: cleartext,\n headerSecretKey,\n ...(input.firstParty ? { firstParty: true } : {}),\n ...(input.firstPartyAppId\n ? { firstPartyAppId: input.firstPartyAppId }\n : {}),\n description: input.description?.trim() || undefined,\n createdAt: Date.now(),\n };\n await writeList(scope, scopeId, [...existing, server]);\n return { ok: true, server };\n}\n\nfunction normalizeEndpointPath(pathname: string): string {\n return pathname.replace(/\\/+$/, \"\") || \"/\";\n}\n\nfunction expectedFirstPartyMcpUrls(appUrl: string): URL[] {\n try {\n const base = appUrl.replace(/\\/+$/, \"\");\n return [new URL(`${base}/mcp`), new URL(`${base}/_agent-native/mcp`)];\n } catch {\n return [];\n }\n}\n\nfunction sameFirstPartyMcpEndpoint(endpointUrl: URL, appUrl: string): boolean {\n return expectedFirstPartyMcpUrls(appUrl).some(\n (expected) =>\n endpointUrl.origin === expected.origin &&\n normalizeEndpointPath(endpointUrl.pathname) ===\n normalizeEndpointPath(expected.pathname) &&\n endpointUrl.search === expected.search,\n );\n}\n\nexport async function isFirstPartyRemoteEndpointTrusted(\n orgId: string,\n appId: string,\n endpoint: string,\n): Promise<{ ok: true } | { ok: false; error: string }> {\n const normalizedAppId = appId.trim().toLowerCase();\n if (!orgId.trim()) {\n return { ok: false, error: \"Organization id is required\" };\n }\n if (!normalizedAppId) {\n return { ok: false, error: \"First-party app id is required\" };\n }\n\n let endpointUrl: URL;\n try {\n endpointUrl = new URL(endpoint);\n } catch {\n return { ok: false, error: \"Not a valid URL\" };\n }\n\n try {\n const { getRequestOrgId } = await import(\"../server/request-context.js\");\n const requestOrgId = getRequestOrgId();\n if (requestOrgId && requestOrgId !== orgId) {\n return {\n ok: false,\n error:\n \"First-party MCP server org does not match the active request organization\",\n };\n }\n } catch {\n // No request context helper available: the org-directory lookup below will\n // still fail closed if it cannot authenticate a first-party app list.\n }\n\n const { fetchOrgApps } = await import(\"../mcp/org-directory.js\");\n const apps = await fetchOrgApps({ serviceOrgId: orgId });\n const app = apps.find((candidate) => candidate.id === normalizedAppId);\n if (!app) {\n return {\n ok: false,\n error: \"Could not verify the first-party app in the org directory\",\n };\n }\n if (!sameFirstPartyMcpEndpoint(endpointUrl, app.url)) {\n return {\n ok: false,\n error:\n \"First-party MCP URL does not match the org-directory app endpoint\",\n };\n }\n return { ok: true };\n}\n\nexport async function removeRemoteServer(\n scope: RemoteMcpScope,\n scopeId: string,\n id: string,\n): Promise<boolean> {\n const existing = await readList(scope, scopeId);\n const removed = existing.find((s) => s.id === id);\n const next = existing.filter((s) => s.id !== id);\n if (next.length === existing.length) return false;\n if (next.length === 0) {\n if (scope === \"user\") {\n await deleteUserSetting(scopeId, SETTINGS_KEY);\n } else {\n await deleteOrgSetting(scopeId, SETTINGS_KEY);\n }\n } else {\n await writeList(scope, scopeId, next);\n }\n // Best-effort: drop the encrypted-headers secret too. Errors are logged\n // but don't fail the deletion — the settings row is already gone, so a\n // dangling secret is harmless (it just can't be read back).\n if (removed?.headerSecretKey) {\n try {\n await deleteAppSecret({\n key: removed.headerSecretKey,\n scope: toSecretScope(scope),\n scopeId,\n });\n } catch (err: any) {\n // eslint-disable-next-line no-console\n console.warn(\n `[mcp-client] Failed to delete MCP header secret ${removed.headerSecretKey}: ${err?.message ?? err}`,\n );\n }\n }\n return true;\n}\n\n/**\n * Resolve the full headers map (cleartext + decrypted secret headers) for a\n * stored MCP server. Used when projecting the stored record into the\n * runtime `McpHttpServerConfig` shape that `McpClientManager` consumes.\n *\n * For legacy rows that wrote secrets cleartext into `headers`, this\n * returns those cleartext values unchanged — they should be re-saved\n * through `addRemoteServer` to migrate to encrypted storage.\n */\nexport async function materializeHeaders(\n scope: RemoteMcpScope,\n scopeId: string,\n stored: StoredRemoteMcpServer,\n): Promise<Record<string, string> | undefined> {\n const merged: Record<string, string> = { ...(stored.headers ?? {}) };\n if (stored.headerSecretKey) {\n try {\n const secret = await readAppSecret({\n key: stored.headerSecretKey,\n scope: toSecretScope(scope),\n scopeId,\n });\n if (secret) {\n const parsed = JSON.parse(secret.value) as Record<string, string>;\n for (const [k, v] of Object.entries(parsed)) {\n if (typeof v === \"string\") merged[k] = v;\n }\n }\n } catch (err: any) {\n // eslint-disable-next-line no-console\n console.warn(\n `[mcp-client] Failed to decrypt MCP headers for ${stored.name}: ${err?.message ?? err}`,\n );\n }\n }\n return Object.keys(merged).length > 0 ? merged : undefined;\n}\n\n/**\n * Project a stored server into the runtime `McpHttpServerConfig` shape that\n * `McpClientManager` consumes. The merged-config key is the scope + name\n * so a user-scope and org-scope server can both share a readable name\n * without clobbering each other.\n *\n * SECURITY: when the stored row references encrypted headers\n * (`headerSecretKey`), callers should use `toHttpServerConfigAsync`\n * instead — this synchronous variant returns ONLY the cleartext headers\n * already present on the row. Returning the row's literal headers without\n * the secret material means the runtime client would call the MCP server\n * without auth (request will fail), but never leaks the encrypted secret.\n */\nexport function toHttpServerConfig(\n stored: StoredRemoteMcpServer,\n): McpHttpServerConfig {\n return {\n type: \"http\",\n url: stored.url,\n headers: stored.headers,\n ...(stored.firstParty ? { firstParty: true } : {}),\n ...(stored.firstPartyAppId\n ? { firstPartyAppId: stored.firstPartyAppId }\n : {}),\n description: stored.description,\n };\n}\n\n/**\n * Async variant of `toHttpServerConfig` that resolves any encrypted\n * `headerSecretKey` reference from `app_secrets` and returns the full\n * cleartext headers map for use at runtime. Use this when actually\n * configuring an MCP client; use the sync variant only when serializing\n * stored data (e.g. for read-only listings that shouldn't disclose\n * secrets).\n */\nexport async function toHttpServerConfigAsync(\n scope: RemoteMcpScope,\n scopeId: string,\n stored: StoredRemoteMcpServer,\n): Promise<McpHttpServerConfig> {\n return {\n type: \"http\",\n url: stored.url,\n headers: await materializeHeaders(scope, scopeId, stored),\n ...(stored.firstParty ? { firstParty: true } : {}),\n ...(stored.firstPartyAppId\n ? { firstPartyAppId: stored.firstPartyAppId }\n : {}),\n ...(stored.firstParty && scope === \"org\"\n ? { firstPartyOrgId: scopeId }\n : {}),\n description: stored.description,\n };\n}\n\n/**\n * Build the merged-config key for a stored server.\n *\n * The key encodes the owning scope + owner identity so two users adding a\n * server called `zapier` produce distinct ids (`user_ab12cd34ef_zapier` vs\n * `user_99aa88bb77_zapier`) and Alice's tool calls never route through Bob's\n * credentials in a shared-process deployment.\n *\n * - User scope: `user_<emailhash>_<name>`\n * - Org scope: `org_<orgId>_<name>`\n *\n * `ownerId` is the raw email for user scope, and the org id for org scope.\n */\nexport function mergedConfigKey(\n scope: RemoteMcpScope,\n stored: StoredRemoteMcpServer,\n ownerId: string,\n): string {\n const owner = scope === \"user\" ? hashEmail(ownerId) : sanitiseOrgId(ownerId);\n return `${scope}_${owner}_${stored.name}`;\n}\n\n/**\n * Parse a merged key (or a full prefixed tool name like\n * `mcp__user_abcd1234ef_zapier__run-task`) back into its scope + owner + name\n * components. Returns null for non-merged keys (e.g. stdio file-config servers\n * like `claude-in-chrome`) so callers can treat them as always-visible.\n *\n * `hub_<orgId>_<name>` entries (pulled from a remote hub via\n * `hub-client.ts`) project to `scope: \"org\"` so they pass through the same\n * per-request visibility gate as locally-stored org servers — the tool is\n * only visible to requests whose active org matches the hub entry's org.\n */\nexport function parseMergedKey(\n keyOrToolName: string,\n): { scope: RemoteMcpScope; owner: string; name: string } | null {\n let key = keyOrToolName;\n if (key.startsWith(\"mcp__\")) {\n const rest = key.slice(\"mcp__\".length);\n const idx = rest.indexOf(\"__\");\n key = idx >= 0 ? rest.slice(0, idx) : rest;\n }\n const m = /^(user|org|hub)_([^_]+)_(.+)$/.exec(key);\n if (!m) return null;\n const prefix = m[1];\n // Hub-sourced servers are scoped to the org they came from — treat them\n // as org-scope for visibility purposes (see isMcpToolAllowedForRequest).\n const scope: RemoteMcpScope = prefix === \"user\" ? \"user\" : \"org\";\n return {\n scope,\n owner: m[2],\n name: m[3],\n };\n}\n"]}
@@ -13,13 +13,13 @@
13
13
  export declare function createNotificationsHandler(): import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<"" | import("./types.js").Notification[] | {
14
14
  count: number;
15
15
  updated?: undefined;
16
- error?: undefined;
17
16
  ok?: undefined;
17
+ error?: undefined;
18
18
  } | {
19
19
  count?: undefined;
20
20
  updated: number;
21
- error?: undefined;
22
21
  ok?: undefined;
22
+ error?: undefined;
23
23
  } | {
24
24
  count?: undefined;
25
25
  updated?: undefined;
@@ -28,7 +28,7 @@ export declare function createNotificationsHandler(): import("h3").EventHandlerW
28
28
  } | {
29
29
  count?: undefined;
30
30
  updated?: undefined;
31
- error?: undefined;
32
31
  ok: boolean;
32
+ error?: undefined;
33
33
  }>>;
34
34
  //# sourceMappingURL=routes.d.ts.map
@@ -15,7 +15,7 @@ export declare function createProgressHandler(): import("h3").EventHandlerWithFe
15
15
  error: string;
16
16
  ok?: undefined;
17
17
  } | {
18
- ok: boolean;
19
18
  error?: undefined;
19
+ ok: boolean;
20
20
  }>>;
21
21
  //# sourceMappingURL=routes.d.ts.map
@@ -73,7 +73,6 @@ export declare function createProviderCorpusJobAction(options: CreateProviderCor
73
73
  offset?: unknown;
74
74
  limit?: unknown;
75
75
  }, {
76
- deleted?: undefined;
77
76
  jobs: {
78
77
  id: string;
79
78
  name: string;
@@ -84,6 +83,7 @@ export declare function createProviderCorpusJobAction(options: CreateProviderCor
84
83
  updatedAt: string;
85
84
  }[];
86
85
  total: number;
86
+ deleted?: undefined;
87
87
  jobId?: undefined;
88
88
  } | {
89
89
  jobs?: undefined;
@@ -91,9 +91,9 @@ export declare function createProviderCorpusJobAction(options: CreateProviderCor
91
91
  deleted: boolean;
92
92
  jobId: string;
93
93
  } | {
94
- deleted?: undefined;
95
94
  jobs?: undefined;
96
95
  total?: undefined;
96
+ deleted?: undefined;
97
97
  jobId?: undefined;
98
98
  hits: Record<string, unknown>[];
99
99
  offset: number;
@@ -52,8 +52,8 @@ export declare function handleDeleteResource(event: any): Promise<{
52
52
  error: string;
53
53
  ok?: undefined;
54
54
  } | {
55
- error?: undefined;
56
55
  ok: boolean;
56
+ error?: undefined;
57
57
  }>;
58
58
  /** POST /_agent-native/resources/upload — upload a file as a resource */
59
59
  export declare function handleUploadResource(event: any): Promise<import("./store.js").Resource | {
@@ -74,10 +74,10 @@ export declare function handleUploadResource(event: any): Promise<import("./stor
74
74
  runId: string | null;
75
75
  expiresAt: number | null;
76
76
  metadata: string | null;
77
- error?: undefined;
78
77
  url: string;
79
78
  provider: string;
80
79
  storageSetupRequired?: undefined;
80
+ error?: undefined;
81
81
  } | {
82
82
  error: string;
83
83
  storageSetupRequired: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"action-filters-a2a.d.ts","sourceRoot":"","sources":["../../../src/server/agent-chat/action-filters-a2a.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,0BAA0B,EAC/B,KAAK,oBAAoB,EAC1B,MAAM,gCAAgC,CAAC;AAExC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAEL,KAAK,WAAW,EACjB,MAAM,iCAAiC,CAAC;AACzC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AE,IAAI,CACjB,sBAAsB,EACtB,oBAAoB,GAAG,kBAAkB,CAC1C,EACD,cAAc,EAAE,UAAU,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,EACjD,MAAM,GAAE,kBAAsD,qEAQ/D;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,UAAU,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,EAC7C,aAAa,EAAE,IAAI,CACjB,sBAAsB,EACtB,oBAAoB,GAAG,kBAAkB,CAC1C,EACD,cAAc,EAAE,UAAU,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,EACjD,MAAM,GAAE,kBAAsD,qEAQ/D;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,cAAc,EAAE,UAAU,EAAE,EAC5B,gBAAgB,CAAC,EAAE,MAAM,EAAE,GAC1B;IAAE,KAAK,EAAE,UAAU,EAAE,CAAC;IAAC,cAAc,EAAE,UAAU,EAAE,CAAA;CAAE,CAKvD;AAED,wBAAgB,uBAAuB,CACrC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EAC5C,UAAU,CAAC,EAAE,MAAM,EAAE,GACpB,MAAM,EAAE,CAEV"}
@@ -1,7 +1,8 @@
1
1
  import { getHeader } from "h3";
2
2
  import { appendA2AArtifactLinks, } from "../../a2a/artifact-response.js";
3
3
  import { collectFinalResponseTextFromAgentEvents } from "../../a2a/response-text.js";
4
- import { filterInitialEngineTools, } from "../../agent/production-agent.js";
4
+ import { resolveMainChatMaxOutputTokens } from "../../agent/engine/output-tokens.js";
5
+ import { filterInitialEngineTools, resolveAgentRequestReasoningEffort, } from "../../agent/production-agent.js";
5
6
  import { runAgentLoopDirectWithSoftTimeout } from "../../agent/run-loop-with-resume.js";
6
7
  import { withConfiguredAppBasePath } from "../app-base-path.js";
7
8
  // ---------------------------------------------------------------------------
@@ -98,6 +99,15 @@ function formatA2ATerminalError(event) {
98
99
  function runDelegatedAgentLoop(runOptions, pluginOptions, timeoutOptions, runner) {
99
100
  return runner({
100
101
  ...runOptions,
102
+ // Delegated runs resolve their own model and do not pass through the
103
+ // interactive request handler's output-token setup. Use the same
104
+ // model-aware headroom here so reasoning models (notably GPT-5.x) do
105
+ // not spend the small internal default entirely on reasoning before
106
+ // emitting a tool call or answer. Preserve explicit test/caller values.
107
+ maxOutputTokens: runOptions.maxOutputTokens ??
108
+ resolveMainChatMaxOutputTokens(runOptions.model),
109
+ reasoningEffort: runOptions.reasoningEffort ??
110
+ resolveAgentRequestReasoningEffort({ model: runOptions.model }),
101
111
  finalResponseGuard: pluginOptions.finalResponseGuard,
102
112
  }, pluginOptions.runSoftTimeoutMs, timeoutOptions);
103
113
  }
@@ -1 +1 @@
1
- {"version":3,"file":"action-filters-a2a.js","sourceRoot":"","sources":["../../../src/server/agent-chat/action-filters-a2a.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAE/B,OAAO,EACL,sBAAsB,GAGvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,uCAAuC,EAAE,MAAM,4BAA4B,CAAC;AAErF,OAAO,EACL,wBAAwB,GAEzB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AAExF,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAGhE,8EAA8E;AAC9E,4EAA4E;AAC5E,uEAAuE;AACvE,oCAAoC;AACpC,8EAA8E;AAE9E,MAAM,UAAU,qBAAqB,CACnC,OAAoC;IAEpC,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,KAAK,IAAI,CAAC,CACvE,CAAC;AACJ,CAAC;AAED;;;;2DAI2D;AAC3D,MAAM,UAAU,gBAAgB,CA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Ac,EACd,MAAM,CACP,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAC7B,UAA6C,EAC7C,aAGC,EACD,cAAiD,EACjD,MAAM,GAAuB,iCAAiC;IAE9D,OAAO,qBAAqB,CAC1B,UAAU,EACV,aAAa,EACb,cAAc,EACd,MAAM,CACP,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CACxC,cAA4B,EAC5B,gBAA2B;IAE3B,OAAO;QACL,KAAK,EAAE,wBAAwB,CAAC,cAAc,EAAE,gBAAgB,CAAC;QACjE,cAAc;KACf,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,eAA4C,EAC5C,UAAqB;IAErB,OAAO,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import { getHeader } from \"h3\";\n\nimport {\n appendA2AArtifactLinks,\n type A2AArtifactResponseOptions,\n type A2AToolResultSummary,\n} from \"../../a2a/artifact-response.js\";\nimport { collectFinalResponseTextFromAgentEvents } from \"../../a2a/response-text.js\";\nimport type { EngineTool } from \"../../agent/engine/types.js\";\nimport {\n filterInitialEngineTools,\n type ActionEntry,\n} from \"../../agent/production-agent.js\";\nimport { runAgentLoopDirectWithSoftTimeout } from \"../../agent/run-loop-with-resume.js\";\nimport type { AgentChatEvent } from \"../../agent/types.js\";\nimport { withConfiguredAppBasePath } from \"../app-base-path.js\";\nimport type { AgentChatPluginOptions } from \"./plugin-options.js\";\n\n// ---------------------------------------------------------------------------\n// Action-visibility filters (read-only / agent-exposed / public-agent-safe)\n// and the A2A (agent-to-agent) final-response assembly + delegated-run\n// helpers that share those filters.\n// ---------------------------------------------------------------------------\n\nexport function filterReadOnlyActions(\n actions: Record<string, ActionEntry>,\n): Record<string, ActionEntry> {\n return Object.fromEntries(\n Object.entries(actions).filter(([, entry]) => entry.readOnly === true),\n );\n}\n\n/** Drop actions that opted out of agent exposure via `agentTool: false`. They\n * remain callable from the frontend / HTTP (mounted separately from this\n * agent tool surface — see `httpActions`) but never appear in any agent tool\n * list (in-app assistant, MCP, A2A, job/trigger runners) or actions prompt.\n * Default-allow: only an explicit `false` is excluded. */\nexport function filterAgentTools(\n actions: Record<string, ActionEntry>,\n): Record<string, ActionEntry> {\n return Object.fromEntries(\n Object.entries(actions).filter(([, entry]) => entry.agentTool !== false),\n );\n}\n\nexport function filterPublicAgentActions(\n actions: Record<string, ActionEntry>,\n): Record<string, ActionEntry> {\n return Object.fromEntries(\n Object.entries(actions).filter(([, entry]) => {\n const config = entry.publicAgent;\n return (\n config?.expose === true &&\n config.readOnly === true &&\n config.requiresAuth !== true &&\n config.isConsequential !== true\n );\n }),\n );\n}\n\nexport function buildPublicAgentA2ASkills(\n actions: Record<string, ActionEntry>,\n): Array<{\n id: string;\n name: string;\n description: string;\n publicAgent: ActionEntry[\"publicAgent\"];\n}> {\n return Object.entries(filterPublicAgentActions(actions)).map(\n ([name, entry]) => ({\n id: name,\n name,\n description: entry.tool.description,\n publicAgent: entry.publicAgent,\n }),\n );\n}\n\nexport function resolveArtifactBaseUrl(\n event: any | undefined,\n): string | undefined {\n const fromEnv =\n process.env.APP_URL ||\n process.env.URL ||\n process.env.DEPLOY_URL ||\n process.env.BETTER_AUTH_URL;\n if (fromEnv) return withConfiguredAppBasePath(String(fromEnv));\n\n try {\n const proto = getHeader(event, \"x-forwarded-proto\") || \"https\";\n const host = getHeader(event, \"host\");\n if (host) return withConfiguredAppBasePath(`${proto}://${host}`);\n } catch {}\n\n return undefined;\n}\n\nexport function assembleA2AFinalResponse(\n events: readonly AgentChatEvent[],\n toolResults: readonly A2AToolResultSummary[],\n options: A2AArtifactResponseOptions & { event?: any } = {},\n): { responseText: string; finalText: string } {\n const terminalError = getA2ATerminalErrorEvent(events);\n const responseText = collectFinalResponseTextFromAgentEvents(events, {\n fallbackToPreToolText: !terminalError,\n });\n const finalText = appendA2AArtifactLinks(responseText, [...toolResults], {\n baseUrl: options.baseUrl ?? resolveArtifactBaseUrl(options.event),\n includeReferencedArtifacts: true,\n });\n if (terminalError && !finalText.trim()) {\n throw new Error(formatA2ATerminalError(terminalError));\n }\n return { responseText, finalText };\n}\n\nfunction getA2ATerminalErrorEvent(\n events: readonly AgentChatEvent[],\n): Extract<AgentChatEvent, { type: \"error\" }> | null {\n for (let i = events.length - 1; i >= 0; i--) {\n const event = events[i];\n if (event.type === \"clear\") continue;\n if (event.type === \"done\") return null;\n if (event.type === \"error\") return event;\n if (event.type === \"auto_continue\") {\n return {\n type: \"error\",\n error: `Agent stopped before finishing (${event.reason}).`,\n errorCode: event.reason,\n recoverable: true,\n };\n }\n }\n return null;\n}\n\nfunction formatA2ATerminalError(\n event: Extract<AgentChatEvent, { type: \"error\" }>,\n): string {\n const parts = [\n event.error || \"Agent failed before producing a final response.\",\n event.errorCode ? `code: ${event.errorCode}` : \"\",\n event.details ? `details: ${event.details}` : \"\",\n ].filter(Boolean);\n return parts.join(\"\\n\");\n}\n\ntype A2AAgentLoopRunner = typeof runAgentLoopDirectWithSoftTimeout;\n\nfunction runDelegatedAgentLoop(\n runOptions: Parameters<A2AAgentLoopRunner>[0],\n pluginOptions: Pick<\n AgentChatPluginOptions,\n \"finalResponseGuard\" | \"runSoftTimeoutMs\"\n >,\n timeoutOptions: Parameters<A2AAgentLoopRunner>[2],\n runner: A2AAgentLoopRunner,\n) {\n return runner(\n {\n ...runOptions,\n finalResponseGuard: pluginOptions.finalResponseGuard,\n },\n pluginOptions.runSoftTimeoutMs,\n timeoutOptions,\n );\n}\n\n/**\n * Run an A2A-delegated agent turn with the same final-response guard used by\n * the app's interactive chat surface.\n *\n * Keeping this in one helper prevents delegated calls from silently bypassing\n * template guarantees such as Analytics' requirement to query real data\n * before presenting metrics or exhaustive provider conclusions.\n */\nexport function runA2AAgentLoop(\n runOptions: Parameters<A2AAgentLoopRunner>[0],\n pluginOptions: Pick<\n AgentChatPluginOptions,\n \"finalResponseGuard\" | \"runSoftTimeoutMs\"\n >,\n timeoutOptions: Parameters<A2AAgentLoopRunner>[2],\n runner: A2AAgentLoopRunner = runAgentLoopDirectWithSoftTimeout,\n) {\n return runDelegatedAgentLoop(\n runOptions,\n pluginOptions,\n timeoutOptions,\n runner,\n );\n}\n\n/**\n * Run the MCP-local ask_app turn with the same app-level response guard as\n * A2A. Keeping this seam shared prevents hosted MCP callers from bypassing\n * template guarantees when the request cannot use the self-A2A route.\n */\nexport function runMCPAgentLoop(\n runOptions: Parameters<A2AAgentLoopRunner>[0],\n pluginOptions: Pick<\n AgentChatPluginOptions,\n \"finalResponseGuard\" | \"runSoftTimeoutMs\"\n >,\n timeoutOptions: Parameters<A2AAgentLoopRunner>[2],\n runner: A2AAgentLoopRunner = runAgentLoopDirectWithSoftTimeout,\n) {\n return runDelegatedAgentLoop(\n runOptions,\n pluginOptions,\n timeoutOptions,\n runner,\n );\n}\n\n/**\n * Keep delegated A2A turns on the same compact initial tool surface as\n * interactive chat. `tool-search` remains in the initial set, while the\n * complete registry is supplied separately so the run loop can load a matched\n * schema after a tool-search result.\n */\nexport function createA2AEngineToolSurface(\n availableTools: EngineTool[],\n initialToolNames?: string[],\n): { tools: EngineTool[]; availableTools: EngineTool[] } {\n return {\n tools: filterInitialEngineTools(availableTools, initialToolNames),\n availableTools,\n };\n}\n\nexport function resolveInitialToolNames(\n templateActions: Record<string, ActionEntry>,\n configured?: string[],\n): string[] {\n return configured ?? Object.keys(templateActions);\n}\n"]}
1
+ {"version":3,"file":"action-filters-a2a.js","sourceRoot":"","sources":["../../../src/server/agent-chat/action-filters-a2a.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAE/B,OAAO,EACL,sBAAsB,GAGvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,uCAAuC,EAAE,MAAM,4BAA4B,CAAC;AACrF,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AAErF,OAAO,EACL,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UAAqB;IAErB,OAAO,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import { getHeader } from \"h3\";\n\nimport {\n appendA2AArtifactLinks,\n type A2AArtifactResponseOptions,\n type A2AToolResultSummary,\n} from \"../../a2a/artifact-response.js\";\nimport { collectFinalResponseTextFromAgentEvents } from \"../../a2a/response-text.js\";\nimport { resolveMainChatMaxOutputTokens } from \"../../agent/engine/output-tokens.js\";\nimport type { EngineTool } from \"../../agent/engine/types.js\";\nimport {\n filterInitialEngineTools,\n resolveAgentRequestReasoningEffort,\n type ActionEntry,\n} from \"../../agent/production-agent.js\";\nimport { runAgentLoopDirectWithSoftTimeout } from \"../../agent/run-loop-with-resume.js\";\nimport type { AgentChatEvent } from \"../../agent/types.js\";\nimport { withConfiguredAppBasePath } from \"../app-base-path.js\";\nimport type { AgentChatPluginOptions } from \"./plugin-options.js\";\n\n// ---------------------------------------------------------------------------\n// Action-visibility filters (read-only / agent-exposed / public-agent-safe)\n// and the A2A (agent-to-agent) final-response assembly + delegated-run\n// helpers that share those filters.\n// ---------------------------------------------------------------------------\n\nexport function filterReadOnlyActions(\n actions: Record<string, ActionEntry>,\n): Record<string, ActionEntry> {\n return Object.fromEntries(\n Object.entries(actions).filter(([, entry]) => entry.readOnly === true),\n );\n}\n\n/** Drop actions that opted out of agent exposure via `agentTool: false`. They\n * remain callable from the frontend / HTTP (mounted separately from this\n * agent tool surface — see `httpActions`) but never appear in any agent tool\n * list (in-app assistant, MCP, A2A, job/trigger runners) or actions prompt.\n * Default-allow: only an explicit `false` is excluded. */\nexport function filterAgentTools(\n actions: Record<string, ActionEntry>,\n): Record<string, ActionEntry> {\n return Object.fromEntries(\n Object.entries(actions).filter(([, entry]) => entry.agentTool !== false),\n );\n}\n\nexport function filterPublicAgentActions(\n actions: Record<string, ActionEntry>,\n): Record<string, ActionEntry> {\n return Object.fromEntries(\n Object.entries(actions).filter(([, entry]) => {\n const config = entry.publicAgent;\n return (\n config?.expose === true &&\n config.readOnly === true &&\n config.requiresAuth !== true &&\n config.isConsequential !== true\n );\n }),\n );\n}\n\nexport function buildPublicAgentA2ASkills(\n actions: Record<string, ActionEntry>,\n): Array<{\n id: string;\n name: string;\n description: string;\n publicAgent: ActionEntry[\"publicAgent\"];\n}> {\n return Object.entries(filterPublicAgentActions(actions)).map(\n ([name, entry]) => ({\n id: name,\n name,\n description: entry.tool.description,\n publicAgent: entry.publicAgent,\n }),\n );\n}\n\nexport function resolveArtifactBaseUrl(\n event: any | undefined,\n): string | undefined {\n const fromEnv =\n process.env.APP_URL ||\n process.env.URL ||\n process.env.DEPLOY_URL ||\n process.env.BETTER_AUTH_URL;\n if (fromEnv) return withConfiguredAppBasePath(String(fromEnv));\n\n try {\n const proto = getHeader(event, \"x-forwarded-proto\") || \"https\";\n const host = getHeader(event, \"host\");\n if (host) return withConfiguredAppBasePath(`${proto}://${host}`);\n } catch {}\n\n return undefined;\n}\n\nexport function assembleA2AFinalResponse(\n events: readonly AgentChatEvent[],\n toolResults: readonly A2AToolResultSummary[],\n options: A2AArtifactResponseOptions & { event?: any } = {},\n): { responseText: string; finalText: string } {\n const terminalError = getA2ATerminalErrorEvent(events);\n const responseText = collectFinalResponseTextFromAgentEvents(events, {\n fallbackToPreToolText: !terminalError,\n });\n const finalText = appendA2AArtifactLinks(responseText, [...toolResults], {\n baseUrl: options.baseUrl ?? resolveArtifactBaseUrl(options.event),\n includeReferencedArtifacts: true,\n });\n if (terminalError && !finalText.trim()) {\n throw new Error(formatA2ATerminalError(terminalError));\n }\n return { responseText, finalText };\n}\n\nfunction getA2ATerminalErrorEvent(\n events: readonly AgentChatEvent[],\n): Extract<AgentChatEvent, { type: \"error\" }> | null {\n for (let i = events.length - 1; i >= 0; i--) {\n const event = events[i];\n if (event.type === \"clear\") continue;\n if (event.type === \"done\") return null;\n if (event.type === \"error\") return event;\n if (event.type === \"auto_continue\") {\n return {\n type: \"error\",\n error: `Agent stopped before finishing (${event.reason}).`,\n errorCode: event.reason,\n recoverable: true,\n };\n }\n }\n return null;\n}\n\nfunction formatA2ATerminalError(\n event: Extract<AgentChatEvent, { type: \"error\" }>,\n): string {\n const parts = [\n event.error || \"Agent failed before producing a final response.\",\n event.errorCode ? `code: ${event.errorCode}` : \"\",\n event.details ? `details: ${event.details}` : \"\",\n ].filter(Boolean);\n return parts.join(\"\\n\");\n}\n\ntype A2AAgentLoopRunner = typeof runAgentLoopDirectWithSoftTimeout;\n\nfunction runDelegatedAgentLoop(\n runOptions: Parameters<A2AAgentLoopRunner>[0],\n pluginOptions: Pick<\n AgentChatPluginOptions,\n \"finalResponseGuard\" | \"runSoftTimeoutMs\"\n >,\n timeoutOptions: Parameters<A2AAgentLoopRunner>[2],\n runner: A2AAgentLoopRunner,\n) {\n return runner(\n {\n ...runOptions,\n // Delegated runs resolve their own model and do not pass through the\n // interactive request handler's output-token setup. Use the same\n // model-aware headroom here so reasoning models (notably GPT-5.x) do\n // not spend the small internal default entirely on reasoning before\n // emitting a tool call or answer. Preserve explicit test/caller values.\n maxOutputTokens:\n runOptions.maxOutputTokens ??\n resolveMainChatMaxOutputTokens(runOptions.model),\n reasoningEffort:\n runOptions.reasoningEffort ??\n resolveAgentRequestReasoningEffort({ model: runOptions.model }),\n finalResponseGuard: pluginOptions.finalResponseGuard,\n },\n pluginOptions.runSoftTimeoutMs,\n timeoutOptions,\n );\n}\n\n/**\n * Run an A2A-delegated agent turn with the same final-response guard used by\n * the app's interactive chat surface.\n *\n * Keeping this in one helper prevents delegated calls from silently bypassing\n * template guarantees such as Analytics' requirement to query real data\n * before presenting metrics or exhaustive provider conclusions.\n */\nexport function runA2AAgentLoop(\n runOptions: Parameters<A2AAgentLoopRunner>[0],\n pluginOptions: Pick<\n AgentChatPluginOptions,\n \"finalResponseGuard\" | \"runSoftTimeoutMs\"\n >,\n timeoutOptions: Parameters<A2AAgentLoopRunner>[2],\n runner: A2AAgentLoopRunner = runAgentLoopDirectWithSoftTimeout,\n) {\n return runDelegatedAgentLoop(\n runOptions,\n pluginOptions,\n timeoutOptions,\n runner,\n );\n}\n\n/**\n * Run the MCP-local ask_app turn with the same app-level response guard as\n * A2A. Keeping this seam shared prevents hosted MCP callers from bypassing\n * template guarantees when the request cannot use the self-A2A route.\n */\nexport function runMCPAgentLoop(\n runOptions: Parameters<A2AAgentLoopRunner>[0],\n pluginOptions: Pick<\n AgentChatPluginOptions,\n \"finalResponseGuard\" | \"runSoftTimeoutMs\"\n >,\n timeoutOptions: Parameters<A2AAgentLoopRunner>[2],\n runner: A2AAgentLoopRunner = runAgentLoopDirectWithSoftTimeout,\n) {\n return runDelegatedAgentLoop(\n runOptions,\n pluginOptions,\n timeoutOptions,\n runner,\n );\n}\n\n/**\n * Keep delegated A2A turns on the same compact initial tool surface as\n * interactive chat. `tool-search` remains in the initial set, while the\n * complete registry is supplied separately so the run loop can load a matched\n * schema after a tool-search result.\n */\nexport function createA2AEngineToolSurface(\n availableTools: EngineTool[],\n initialToolNames?: string[],\n): { tools: EngineTool[]; availableTools: EngineTool[] } {\n return {\n tools: filterInitialEngineTools(availableTools, initialToolNames),\n availableTools,\n };\n}\n\nexport function resolveInitialToolNames(\n templateActions: Record<string, ActionEntry>,\n configured?: string[],\n): string[] {\n return configured ?? Object.keys(templateActions);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"agent-chat-plugin.d.ts","sourceRoot":"","sources":["../../src/server/agent-chat-plugin.ts"],"names":[],"mappings":"AAyIA,OAAO,EACL,yBAAyB,EACzB,KAAK,6BAA6B,EACnC,MAAM,+BAA+B,CAAC;AAoCvC,OAAO,EAAE,yBAAyB,EAAE,CAAC;AACrC,YAAY,EAAE,6BAA6B,EAAE,CAAC;AAmB9C,OAAO,EACL,0BAA0B,EAK1B,eAAe,EACf,eAAe,EACf,wBAAwB,EACxB,yBAAyB,EAE1B,MAAM,oCAAoC,CAAC;AAW5C,OAAO,EACL,gCAAgC,EAOjC,MAAM,mCAAmC,CAAC;AAC3C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AsB,uCAAuC,CAC3D,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,OAAO,CAAC,CAUlB;AAaD,wBAAgB,qBAAqB,CACnC,OAAO,CAAC,EAAE,sBAAsB,GAC/B,cAAc,CA49JhB;AAED;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,cAAwC,CAAC;AAE9E,OAAO,EAEL,mBAAmB,EACnB,uBAAuB,EAGxB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAC/B,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
@@ -36,7 +36,7 @@ import { getOrigin } from "./google-oauth.js";
36
36
  import { readBody } from "./h3-helpers.js";
37
37
  import { FIRST_SESSION_PERSONALIZATION, getModelFamilyOverlay, } from "./prompts/index.js";
38
38
  import { mountRealtimeVoiceRoutes } from "./realtime-voice.js";
39
- import { runWithRequestContext, getRequestOrgId, getRequestUserEmail, getRequestRunContext, ensureRequestRunContext, } from "./request-context.js";
39
+ import { runWithRequestContext, getRequestContext, getRequestOrgId, getRequestUserEmail, getRequestRunContext, ensureRequestRunContext, } from "./request-context.js";
40
40
  export { handleSharedThreadRequest };
41
41
  // Lazy fs — loaded via dynamic import() on first use.
42
42
  // This avoids require() which bundlers convert to createRequire(import.meta.url)
@@ -961,6 +961,23 @@ export function createAgentChatPlugin(options) {
961
961
  if (a2aRunContext) {
962
962
  a2aRunContext.owner = userEmail;
963
963
  a2aRunContext.userApiKey = ownerApiKey;
964
+ // The async processor restores the original request origin from
965
+ // task metadata. Only derive a fallback for synchronous A2A calls
966
+ // where the inbound event is still the caller request.
967
+ if (!a2aRunContext.requestOrigin) {
968
+ const restoredOrigin = getRequestContext()?.requestOrigin;
969
+ if (restoredOrigin) {
970
+ a2aRunContext.requestOrigin = restoredOrigin;
971
+ }
972
+ }
973
+ if (!a2aRunContext.requestOrigin) {
974
+ try {
975
+ a2aRunContext.requestOrigin = getOrigin(context.event);
976
+ }
977
+ catch {
978
+ // Keep the owner context even when no browser origin exists.
979
+ }
980
+ }
964
981
  }
965
982
  const a2aEngine = await resolveEngine({
966
983
  engineOption: options?.engine,
@@ -975,16 +992,6 @@ export function createAgentChatPlugin(options) {
975
992
  ? ""
976
993
  : await buildSchemaBlock(owner, databaseToolsMode);
977
994
  const extra = await resolveExtraContext(context.event, owner);
978
- // Stable content first, most-volatile-per-day last: the
979
- // runtime-context block is appended after resources/schema/extra so
980
- // a day rollover (or the resources/extra content changing) only
981
- // invalidates the cached prompt prefix as late as possible.
982
- const runtimeContext = runtimeContextForEvent(context.event);
983
- const systemPrompt = devActive
984
- ? devPrompt + resources + schemaBlock + extra + runtimeContext
985
- : basePrompt + resources + schemaBlock + extra + runtimeContext;
986
- if (a2aRunContext)
987
- a2aRunContext.systemPrompt = systemPrompt;
988
995
  const a2aModelCandidate = options?.model ??
989
996
  (await getStoredModelForEngine(a2aEngine, {
990
997
  appId: options?.appId,
@@ -995,6 +1002,30 @@ export function createAgentChatPlugin(options) {
995
1002
  a2aRunContext.engine = a2aEngine;
996
1003
  a2aRunContext.model = model;
997
1004
  }
1005
+ // Keep delegated runs aligned with the interactive production
1006
+ // prompt's model-specific behavior without importing interactive
1007
+ // onboarding into a background/cross-app task.
1008
+ const modelOverlay = getModelFamilyOverlay(model);
1009
+ // Stable content first, most-volatile-per-day last: the
1010
+ // runtime-context block is appended after resources/schema/extra so
1011
+ // a day rollover (or the resources/extra content changing) only
1012
+ // invalidates the cached prompt prefix as late as possible.
1013
+ const runtimeContext = runtimeContextForEvent(context.event);
1014
+ const systemPrompt = devActive
1015
+ ? devPrompt +
1016
+ resources +
1017
+ schemaBlock +
1018
+ extra +
1019
+ modelOverlay +
1020
+ runtimeContext
1021
+ : basePrompt +
1022
+ resources +
1023
+ schemaBlock +
1024
+ extra +
1025
+ modelOverlay +
1026
+ runtimeContext;
1027
+ if (a2aRunContext)
1028
+ a2aRunContext.systemPrompt = systemPrompt;
998
1029
  // Build tools — same as interactive handler but WITHOUT call-agent
999
1030
  // to prevent infinite recursive A2A loops (agent calling itself).
1000
1031
  // In dev mode, template actions are invoked via bash (not native tools),
@@ -4335,6 +4366,7 @@ Non-code requests are still fine on this surface: read data, navigate the UI, su
4335
4366
  "/_agent-native/actions",
4336
4367
  "/_agent-native/agent-model-defaults",
4337
4368
  "/_agent-native/mcp",
4369
+ "/mcp",
4338
4370
  ],
4339
4371
  });
4340
4372
  };