@agent-native/core 0.7.13 → 0.7.15

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 (908) hide show
  1. package/README.md +56 -6
  2. package/dist/a2a/client.d.ts +44 -1
  3. package/dist/a2a/client.d.ts.map +1 -1
  4. package/dist/a2a/client.js +88 -11
  5. package/dist/a2a/client.js.map +1 -1
  6. package/dist/a2a/handlers.d.ts +10 -0
  7. package/dist/a2a/handlers.d.ts.map +1 -1
  8. package/dist/a2a/handlers.js +417 -67
  9. package/dist/a2a/handlers.js.map +1 -1
  10. package/dist/a2a/server.d.ts.map +1 -1
  11. package/dist/a2a/server.js +212 -19
  12. package/dist/a2a/server.js.map +1 -1
  13. package/dist/a2a/task-store.d.ts +20 -1
  14. package/dist/a2a/task-store.d.ts.map +1 -1
  15. package/dist/a2a/task-store.js +72 -2
  16. package/dist/a2a/task-store.js.map +1 -1
  17. package/dist/agent/default-model.d.ts +21 -0
  18. package/dist/agent/default-model.d.ts.map +1 -0
  19. package/dist/agent/default-model.js +21 -0
  20. package/dist/agent/default-model.js.map +1 -0
  21. package/dist/agent/engine/ai-sdk-engine.d.ts.map +1 -1
  22. package/dist/agent/engine/ai-sdk-engine.js +7 -4
  23. package/dist/agent/engine/ai-sdk-engine.js.map +1 -1
  24. package/dist/agent/engine/anthropic-engine.d.ts +1 -1
  25. package/dist/agent/engine/anthropic-engine.d.ts.map +1 -1
  26. package/dist/agent/engine/anthropic-engine.js +10 -4
  27. package/dist/agent/engine/anthropic-engine.js.map +1 -1
  28. package/dist/agent/engine/builder-engine.d.ts +1 -1
  29. package/dist/agent/engine/builder-engine.d.ts.map +1 -1
  30. package/dist/agent/engine/builder-engine.js +11 -26
  31. package/dist/agent/engine/builder-engine.js.map +1 -1
  32. package/dist/agent/engine/builtin.js +1 -1
  33. package/dist/agent/engine/builtin.js.map +1 -1
  34. package/dist/agent/engine/registry.d.ts +27 -7
  35. package/dist/agent/engine/registry.d.ts.map +1 -1
  36. package/dist/agent/engine/registry.js +101 -20
  37. package/dist/agent/engine/registry.js.map +1 -1
  38. package/dist/agent/index.d.ts +1 -0
  39. package/dist/agent/index.d.ts.map +1 -1
  40. package/dist/agent/index.js +1 -0
  41. package/dist/agent/index.js.map +1 -1
  42. package/dist/agent/production-agent.d.ts +25 -3
  43. package/dist/agent/production-agent.d.ts.map +1 -1
  44. package/dist/agent/production-agent.js +227 -36
  45. package/dist/agent/production-agent.js.map +1 -1
  46. package/dist/application-state/handlers.d.ts.map +1 -1
  47. package/dist/application-state/handlers.js +10 -6
  48. package/dist/application-state/handlers.js.map +1 -1
  49. package/dist/application-state/script-helpers.d.ts +1 -1
  50. package/dist/application-state/script-helpers.d.ts.map +1 -1
  51. package/dist/application-state/script-helpers.js +12 -8
  52. package/dist/application-state/script-helpers.js.map +1 -1
  53. package/dist/application-state/store.d.ts.map +1 -1
  54. package/dist/application-state/store.js +19 -10
  55. package/dist/application-state/store.js.map +1 -1
  56. package/dist/chat-threads/store.d.ts +3 -0
  57. package/dist/chat-threads/store.d.ts.map +1 -1
  58. package/dist/chat-threads/store.js +36 -1
  59. package/dist/chat-threads/store.js.map +1 -1
  60. package/dist/cli/create.d.ts.map +1 -1
  61. package/dist/cli/create.js +79 -13
  62. package/dist/cli/create.js.map +1 -1
  63. package/dist/cli/index.js +97 -39
  64. package/dist/cli/index.js.map +1 -1
  65. package/dist/cli/templates-meta.d.ts +4 -0
  66. package/dist/cli/templates-meta.d.ts.map +1 -1
  67. package/dist/cli/templates-meta.js +67 -12
  68. package/dist/cli/templates-meta.js.map +1 -1
  69. package/dist/cli/workspacify.d.ts +2 -0
  70. package/dist/cli/workspacify.d.ts.map +1 -1
  71. package/dist/cli/workspacify.js +5 -4
  72. package/dist/cli/workspacify.js.map +1 -1
  73. package/dist/client/AgentPanel.d.ts +7 -2
  74. package/dist/client/AgentPanel.d.ts.map +1 -1
  75. package/dist/client/AgentPanel.js +81 -32
  76. package/dist/client/AgentPanel.js.map +1 -1
  77. package/dist/client/AgentTaskCard.d.ts.map +1 -1
  78. package/dist/client/AgentTaskCard.js +5 -2
  79. package/dist/client/AgentTaskCard.js.map +1 -1
  80. package/dist/client/AssistantChat.d.ts +2 -0
  81. package/dist/client/AssistantChat.d.ts.map +1 -1
  82. package/dist/client/AssistantChat.js +183 -84
  83. package/dist/client/AssistantChat.js.map +1 -1
  84. package/dist/client/ConnectBuilderCard.d.ts.map +1 -1
  85. package/dist/client/ConnectBuilderCard.js +2 -1
  86. package/dist/client/ConnectBuilderCard.js.map +1 -1
  87. package/dist/client/DefaultSpinner.d.ts +1 -1
  88. package/dist/client/DefaultSpinner.d.ts.map +1 -1
  89. package/dist/client/DefaultSpinner.js +2 -9
  90. package/dist/client/DefaultSpinner.js.map +1 -1
  91. package/dist/client/ErrorBoundary.d.ts +1 -3
  92. package/dist/client/ErrorBoundary.d.ts.map +1 -1
  93. package/dist/client/ErrorBoundary.js +37 -9
  94. package/dist/client/ErrorBoundary.js.map +1 -1
  95. package/dist/client/FeedbackButton.d.ts.map +1 -1
  96. package/dist/client/FeedbackButton.js +4 -3
  97. package/dist/client/FeedbackButton.js.map +1 -1
  98. package/dist/client/MultiTabAssistantChat.d.ts.map +1 -1
  99. package/dist/client/MultiTabAssistantChat.js +165 -68
  100. package/dist/client/MultiTabAssistantChat.js.map +1 -1
  101. package/dist/client/agent-chat-adapter.d.ts.map +1 -1
  102. package/dist/client/agent-chat-adapter.js +2 -1
  103. package/dist/client/agent-chat-adapter.js.map +1 -1
  104. package/dist/client/agent-chat.d.ts +11 -0
  105. package/dist/client/agent-chat.d.ts.map +1 -1
  106. package/dist/client/agent-chat.js +4 -2
  107. package/dist/client/agent-chat.js.map +1 -1
  108. package/dist/client/analytics.d.ts.map +1 -1
  109. package/dist/client/analytics.js +70 -1
  110. package/dist/client/analytics.js.map +1 -1
  111. package/dist/client/api-path.d.ts +5 -0
  112. package/dist/client/api-path.d.ts.map +1 -0
  113. package/dist/client/api-path.js +48 -0
  114. package/dist/client/api-path.js.map +1 -0
  115. package/dist/client/components/AgentPresenceChip.d.ts +12 -0
  116. package/dist/client/components/AgentPresenceChip.d.ts.map +1 -0
  117. package/dist/client/components/AgentPresenceChip.js +42 -0
  118. package/dist/client/components/AgentPresenceChip.js.map +1 -0
  119. package/dist/client/components/ApiKeySettings.d.ts.map +1 -1
  120. package/dist/client/components/ApiKeySettings.js +3 -2
  121. package/dist/client/components/ApiKeySettings.js.map +1 -1
  122. package/dist/client/components/CodeRequiredDialog.d.ts.map +1 -1
  123. package/dist/client/components/CodeRequiredDialog.js +3 -2
  124. package/dist/client/components/CodeRequiredDialog.js.map +1 -1
  125. package/dist/client/components/PresenceBar.d.ts +17 -0
  126. package/dist/client/components/PresenceBar.d.ts.map +1 -0
  127. package/dist/client/components/PresenceBar.js +118 -0
  128. package/dist/client/components/PresenceBar.js.map +1 -0
  129. package/dist/client/composer/ComposerPlusMenu.d.ts +6 -1
  130. package/dist/client/composer/ComposerPlusMenu.d.ts.map +1 -1
  131. package/dist/client/composer/ComposerPlusMenu.js +22 -83
  132. package/dist/client/composer/ComposerPlusMenu.js.map +1 -1
  133. package/dist/client/composer/TiptapComposer.d.ts +3 -1
  134. package/dist/client/composer/TiptapComposer.d.ts.map +1 -1
  135. package/dist/client/composer/TiptapComposer.js +245 -23
  136. package/dist/client/composer/TiptapComposer.js.map +1 -1
  137. package/dist/client/composer/draft-key.d.ts +2 -0
  138. package/dist/client/composer/draft-key.d.ts.map +1 -0
  139. package/dist/client/composer/draft-key.js +8 -0
  140. package/dist/client/composer/draft-key.js.map +1 -0
  141. package/dist/client/composer/types.d.ts +1 -0
  142. package/dist/client/composer/types.d.ts.map +1 -1
  143. package/dist/client/composer/use-file-search.d.ts.map +1 -1
  144. package/dist/client/composer/use-file-search.js +2 -1
  145. package/dist/client/composer/use-file-search.js.map +1 -1
  146. package/dist/client/composer/use-mention-search.d.ts.map +1 -1
  147. package/dist/client/composer/use-mention-search.js +2 -1
  148. package/dist/client/composer/use-mention-search.js.map +1 -1
  149. package/dist/client/composer/use-skills.d.ts.map +1 -1
  150. package/dist/client/composer/use-skills.js +2 -1
  151. package/dist/client/composer/use-skills.js.map +1 -1
  152. package/dist/client/composer/useVoiceDictation.d.ts +3 -1
  153. package/dist/client/composer/useVoiceDictation.d.ts.map +1 -1
  154. package/dist/client/composer/useVoiceDictation.js +101 -18
  155. package/dist/client/composer/useVoiceDictation.js.map +1 -1
  156. package/dist/client/dev-mode.d.ts +14 -0
  157. package/dist/client/dev-mode.d.ts.map +1 -0
  158. package/dist/client/dev-mode.js +14 -0
  159. package/dist/client/dev-mode.js.map +1 -0
  160. package/dist/client/dev-overlay/DevOverlay.d.ts +26 -0
  161. package/dist/client/dev-overlay/DevOverlay.d.ts.map +1 -0
  162. package/dist/client/dev-overlay/DevOverlay.js +315 -0
  163. package/dist/client/dev-overlay/DevOverlay.js.map +1 -0
  164. package/dist/client/dev-overlay/builtins.d.ts +6 -0
  165. package/dist/client/dev-overlay/builtins.d.ts.map +1 -0
  166. package/dist/client/dev-overlay/builtins.js +35 -0
  167. package/dist/client/dev-overlay/builtins.js.map +1 -0
  168. package/dist/client/dev-overlay/index.d.ts +6 -0
  169. package/dist/client/dev-overlay/index.d.ts.map +1 -0
  170. package/dist/client/dev-overlay/index.js +5 -0
  171. package/dist/client/dev-overlay/index.js.map +1 -0
  172. package/dist/client/dev-overlay/registry.d.ts +13 -0
  173. package/dist/client/dev-overlay/registry.d.ts.map +1 -0
  174. package/dist/client/dev-overlay/registry.js +63 -0
  175. package/dist/client/dev-overlay/registry.js.map +1 -0
  176. package/dist/client/dev-overlay/types.d.ts +56 -0
  177. package/dist/client/dev-overlay/types.d.ts.map +1 -0
  178. package/dist/client/dev-overlay/types.js +9 -0
  179. package/dist/client/dev-overlay/types.js.map +1 -0
  180. package/dist/client/dev-overlay/use-dev-option.d.ts +12 -0
  181. package/dist/client/dev-overlay/use-dev-option.d.ts.map +1 -0
  182. package/dist/client/dev-overlay/use-dev-option.js +73 -0
  183. package/dist/client/dev-overlay/use-dev-option.js.map +1 -0
  184. package/dist/client/dev-overlay/use-dev-overlay-shortcut.d.ts +6 -0
  185. package/dist/client/dev-overlay/use-dev-overlay-shortcut.d.ts.map +1 -0
  186. package/dist/client/dev-overlay/use-dev-overlay-shortcut.js +29 -0
  187. package/dist/client/dev-overlay/use-dev-overlay-shortcut.js.map +1 -0
  188. package/dist/client/frame.d.ts +1 -0
  189. package/dist/client/frame.d.ts.map +1 -1
  190. package/dist/client/frame.js +32 -11
  191. package/dist/client/frame.js.map +1 -1
  192. package/dist/client/index.d.ts +7 -0
  193. package/dist/client/index.d.ts.map +1 -1
  194. package/dist/client/index.js +9 -0
  195. package/dist/client/index.js.map +1 -1
  196. package/dist/client/integrations/IntegrationCard.d.ts.map +1 -1
  197. package/dist/client/integrations/IntegrationCard.js +3 -2
  198. package/dist/client/integrations/IntegrationCard.js.map +1 -1
  199. package/dist/client/integrations/IntegrationsPanel.d.ts.map +1 -1
  200. package/dist/client/integrations/IntegrationsPanel.js +3 -2
  201. package/dist/client/integrations/IntegrationsPanel.js.map +1 -1
  202. package/dist/client/integrations/useIntegrationStatus.d.ts.map +1 -1
  203. package/dist/client/integrations/useIntegrationStatus.js +2 -1
  204. package/dist/client/integrations/useIntegrationStatus.js.map +1 -1
  205. package/dist/client/notifications/NotificationsBell.d.ts.map +1 -1
  206. package/dist/client/notifications/NotificationsBell.js +26 -8
  207. package/dist/client/notifications/NotificationsBell.js.map +1 -1
  208. package/dist/client/observability/ThumbsFeedback.d.ts.map +1 -1
  209. package/dist/client/observability/ThumbsFeedback.js +2 -1
  210. package/dist/client/observability/ThumbsFeedback.js.map +1 -1
  211. package/dist/client/observability/useObservability.d.ts.map +1 -1
  212. package/dist/client/observability/useObservability.js +2 -1
  213. package/dist/client/observability/useObservability.js.map +1 -1
  214. package/dist/client/onboarding/OnboardingPanel.d.ts +0 -7
  215. package/dist/client/onboarding/OnboardingPanel.d.ts.map +1 -1
  216. package/dist/client/onboarding/OnboardingPanel.js +20 -10
  217. package/dist/client/onboarding/OnboardingPanel.js.map +1 -1
  218. package/dist/client/onboarding/index.d.ts +1 -0
  219. package/dist/client/onboarding/index.d.ts.map +1 -1
  220. package/dist/client/onboarding/index.js +1 -0
  221. package/dist/client/onboarding/index.js.map +1 -1
  222. package/dist/client/onboarding/use-onboarding.d.ts +1 -7
  223. package/dist/client/onboarding/use-onboarding.d.ts.map +1 -1
  224. package/dist/client/onboarding/use-onboarding.js +27 -13
  225. package/dist/client/onboarding/use-onboarding.js.map +1 -1
  226. package/dist/client/onboarding/use-preview-mode.d.ts +10 -0
  227. package/dist/client/onboarding/use-preview-mode.d.ts.map +1 -0
  228. package/dist/client/onboarding/use-preview-mode.js +35 -0
  229. package/dist/client/onboarding/use-preview-mode.js.map +1 -0
  230. package/dist/client/org/OrgSwitcher.d.ts.map +1 -1
  231. package/dist/client/org/OrgSwitcher.js +2 -1
  232. package/dist/client/org/OrgSwitcher.js.map +1 -1
  233. package/dist/client/org/RequireActiveOrg.d.ts.map +1 -1
  234. package/dist/client/org/RequireActiveOrg.js +15 -10
  235. package/dist/client/org/RequireActiveOrg.js.map +1 -1
  236. package/dist/client/org/TeamPage.d.ts.map +1 -1
  237. package/dist/client/org/TeamPage.js +132 -9
  238. package/dist/client/org/TeamPage.js.map +1 -1
  239. package/dist/client/org/hooks.d.ts +30 -0
  240. package/dist/client/org/hooks.d.ts.map +1 -1
  241. package/dist/client/org/hooks.js +67 -1
  242. package/dist/client/org/hooks.js.map +1 -1
  243. package/dist/client/org/index.d.ts +2 -2
  244. package/dist/client/org/index.d.ts.map +1 -1
  245. package/dist/client/org/index.js +1 -1
  246. package/dist/client/org/index.js.map +1 -1
  247. package/dist/client/progress/RunsTray.d.ts.map +1 -1
  248. package/dist/client/progress/RunsTray.js +2 -1
  249. package/dist/client/progress/RunsTray.js.map +1 -1
  250. package/dist/client/resources/McpServerDetail.d.ts +0 -8
  251. package/dist/client/resources/McpServerDetail.d.ts.map +1 -1
  252. package/dist/client/resources/McpServerDetail.js +6 -1
  253. package/dist/client/resources/McpServerDetail.js.map +1 -1
  254. package/dist/client/resources/ResourceEditor.d.ts.map +1 -1
  255. package/dist/client/resources/ResourceEditor.js +2 -1
  256. package/dist/client/resources/ResourceEditor.js.map +1 -1
  257. package/dist/client/resources/ResourcesPanel.d.ts.map +1 -1
  258. package/dist/client/resources/ResourcesPanel.js +7 -2
  259. package/dist/client/resources/ResourcesPanel.js.map +1 -1
  260. package/dist/client/resources/use-mcp-servers.d.ts.map +1 -1
  261. package/dist/client/resources/use-mcp-servers.js +7 -2
  262. package/dist/client/resources/use-mcp-servers.js.map +1 -1
  263. package/dist/client/resources/use-resources.d.ts.map +1 -1
  264. package/dist/client/resources/use-resources.js +9 -7
  265. package/dist/client/resources/use-resources.js.map +1 -1
  266. package/dist/client/settings/AgentsSection.d.ts.map +1 -1
  267. package/dist/client/settings/AgentsSection.js +7 -5
  268. package/dist/client/settings/AgentsSection.js.map +1 -1
  269. package/dist/client/settings/AutomationsSection.d.ts.map +1 -1
  270. package/dist/client/settings/AutomationsSection.js +10 -5
  271. package/dist/client/settings/AutomationsSection.js.map +1 -1
  272. package/dist/client/settings/BackgroundAgentSection.d.ts.map +1 -1
  273. package/dist/client/settings/BackgroundAgentSection.js +2 -1
  274. package/dist/client/settings/BackgroundAgentSection.js.map +1 -1
  275. package/dist/client/settings/SecretsSection.d.ts.map +1 -1
  276. package/dist/client/settings/SecretsSection.js +12 -4
  277. package/dist/client/settings/SecretsSection.js.map +1 -1
  278. package/dist/client/settings/SettingsPanel.d.ts.map +1 -1
  279. package/dist/client/settings/SettingsPanel.js +38 -33
  280. package/dist/client/settings/SettingsPanel.js.map +1 -1
  281. package/dist/client/settings/UsageSection.d.ts.map +1 -1
  282. package/dist/client/settings/UsageSection.js +2 -1
  283. package/dist/client/settings/UsageSection.js.map +1 -1
  284. package/dist/client/settings/VoiceTranscriptionSection.d.ts +2 -4
  285. package/dist/client/settings/VoiceTranscriptionSection.d.ts.map +1 -1
  286. package/dist/client/settings/VoiceTranscriptionSection.js +66 -23
  287. package/dist/client/settings/VoiceTranscriptionSection.js.map +1 -1
  288. package/dist/client/settings/useBuilderStatus.d.ts +9 -0
  289. package/dist/client/settings/useBuilderStatus.d.ts.map +1 -1
  290. package/dist/client/settings/useBuilderStatus.js +31 -3
  291. package/dist/client/settings/useBuilderStatus.js.map +1 -1
  292. package/dist/client/sharing/ShareButton.d.ts.map +1 -1
  293. package/dist/client/sharing/ShareButton.js +7 -2
  294. package/dist/client/sharing/ShareButton.js.map +1 -1
  295. package/dist/client/sharing/ShareDialog.d.ts.map +1 -1
  296. package/dist/client/sharing/ShareDialog.js +4 -3
  297. package/dist/client/sharing/ShareDialog.js.map +1 -1
  298. package/dist/client/sse-event-processor.d.ts.map +1 -1
  299. package/dist/client/sse-event-processor.js +10 -0
  300. package/dist/client/sse-event-processor.js.map +1 -1
  301. package/dist/client/terminal/AgentTerminal.d.ts +1 -0
  302. package/dist/client/terminal/AgentTerminal.d.ts.map +1 -1
  303. package/dist/client/terminal/AgentTerminal.js +12 -8
  304. package/dist/client/terminal/AgentTerminal.js.map +1 -1
  305. package/dist/client/tools/EmbeddedTool.d.ts +20 -0
  306. package/dist/client/tools/EmbeddedTool.d.ts.map +1 -0
  307. package/dist/client/tools/EmbeddedTool.js +113 -0
  308. package/dist/client/tools/EmbeddedTool.js.map +1 -0
  309. package/dist/client/tools/ExtensionSlot.d.ts +27 -0
  310. package/dist/client/tools/ExtensionSlot.d.ts.map +1 -0
  311. package/dist/client/tools/ExtensionSlot.js +96 -0
  312. package/dist/client/tools/ExtensionSlot.js.map +1 -0
  313. package/dist/client/tools/ToolEditor.d.ts +5 -0
  314. package/dist/client/tools/ToolEditor.d.ts.map +1 -0
  315. package/dist/client/tools/ToolEditor.js +99 -0
  316. package/dist/client/tools/ToolEditor.js.map +1 -0
  317. package/dist/client/tools/ToolViewer.d.ts +5 -0
  318. package/dist/client/tools/ToolViewer.d.ts.map +1 -0
  319. package/dist/client/tools/ToolViewer.js +275 -0
  320. package/dist/client/tools/ToolViewer.js.map +1 -0
  321. package/dist/client/tools/ToolViewerPage.d.ts +2 -0
  322. package/dist/client/tools/ToolViewerPage.d.ts.map +1 -0
  323. package/dist/client/tools/ToolViewerPage.js +24 -0
  324. package/dist/client/tools/ToolViewerPage.js.map +1 -0
  325. package/dist/client/tools/ToolsListPage.d.ts +2 -0
  326. package/dist/client/tools/ToolsListPage.d.ts.map +1 -0
  327. package/dist/client/tools/ToolsListPage.js +73 -0
  328. package/dist/client/tools/ToolsListPage.js.map +1 -0
  329. package/dist/client/tools/ToolsSidebarSection.d.ts +2 -0
  330. package/dist/client/tools/ToolsSidebarSection.d.ts.map +1 -0
  331. package/dist/client/tools/ToolsSidebarSection.js +189 -0
  332. package/dist/client/tools/ToolsSidebarSection.js.map +1 -0
  333. package/dist/client/tools/iframe-bridge.d.ts +16 -0
  334. package/dist/client/tools/iframe-bridge.d.ts.map +1 -0
  335. package/dist/client/tools/iframe-bridge.js +118 -0
  336. package/dist/client/tools/iframe-bridge.js.map +1 -0
  337. package/dist/client/tools/index.d.ts +8 -0
  338. package/dist/client/tools/index.d.ts.map +1 -0
  339. package/dist/client/tools/index.js +8 -0
  340. package/dist/client/tools/index.js.map +1 -0
  341. package/dist/client/use-action.d.ts.map +1 -1
  342. package/dist/client/use-action.js +2 -1
  343. package/dist/client/use-action.js.map +1 -1
  344. package/dist/client/use-avatar.d.ts.map +1 -1
  345. package/dist/client/use-avatar.js +3 -2
  346. package/dist/client/use-avatar.js.map +1 -1
  347. package/dist/client/use-builder-enabled.d.ts.map +1 -1
  348. package/dist/client/use-builder-enabled.js +2 -1
  349. package/dist/client/use-builder-enabled.js.map +1 -1
  350. package/dist/client/use-chat-threads.d.ts +1 -0
  351. package/dist/client/use-chat-threads.d.ts.map +1 -1
  352. package/dist/client/use-chat-threads.js +31 -1
  353. package/dist/client/use-chat-threads.js.map +1 -1
  354. package/dist/client/use-db-sync.d.ts.map +1 -1
  355. package/dist/client/use-db-sync.js +9 -8
  356. package/dist/client/use-db-sync.js.map +1 -1
  357. package/dist/client/use-dev-mode.d.ts.map +1 -1
  358. package/dist/client/use-dev-mode.js +2 -1
  359. package/dist/client/use-dev-mode.js.map +1 -1
  360. package/dist/client/use-send-to-agent-chat.d.ts.map +1 -1
  361. package/dist/client/use-send-to-agent-chat.js +3 -1
  362. package/dist/client/use-send-to-agent-chat.js.map +1 -1
  363. package/dist/client/use-session.d.ts.map +1 -1
  364. package/dist/client/use-session.js +2 -1
  365. package/dist/client/use-session.js.map +1 -1
  366. package/dist/client/useProductionAgent.d.ts.map +1 -1
  367. package/dist/client/useProductionAgent.js +2 -1
  368. package/dist/client/useProductionAgent.js.map +1 -1
  369. package/dist/collab/agent-identity.d.ts +15 -0
  370. package/dist/collab/agent-identity.d.ts.map +1 -0
  371. package/dist/collab/agent-identity.js +14 -0
  372. package/dist/collab/agent-identity.js.map +1 -0
  373. package/dist/collab/agent-presence.d.ts +59 -0
  374. package/dist/collab/agent-presence.d.ts.map +1 -0
  375. package/dist/collab/agent-presence.js +165 -0
  376. package/dist/collab/agent-presence.js.map +1 -0
  377. package/dist/collab/awareness.d.ts +7 -0
  378. package/dist/collab/awareness.d.ts.map +1 -1
  379. package/dist/collab/awareness.js +2 -2
  380. package/dist/collab/awareness.js.map +1 -1
  381. package/dist/collab/client-struct.d.ts +43 -0
  382. package/dist/collab/client-struct.d.ts.map +1 -0
  383. package/dist/collab/client-struct.js +272 -0
  384. package/dist/collab/client-struct.js.map +1 -0
  385. package/dist/collab/client.d.ts +2 -0
  386. package/dist/collab/client.d.ts.map +1 -1
  387. package/dist/collab/client.js +18 -3
  388. package/dist/collab/client.js.map +1 -1
  389. package/dist/collab/index.d.ts +6 -1
  390. package/dist/collab/index.d.ts.map +1 -1
  391. package/dist/collab/index.js +11 -1
  392. package/dist/collab/index.js.map +1 -1
  393. package/dist/collab/json-to-yjs.d.ts +72 -0
  394. package/dist/collab/json-to-yjs.d.ts.map +1 -0
  395. package/dist/collab/json-to-yjs.js +456 -0
  396. package/dist/collab/json-to-yjs.js.map +1 -0
  397. package/dist/collab/struct-routes.d.ts +52 -0
  398. package/dist/collab/struct-routes.d.ts.map +1 -0
  399. package/dist/collab/struct-routes.js +74 -0
  400. package/dist/collab/struct-routes.js.map +1 -0
  401. package/dist/collab/ydoc-manager.d.ts +19 -0
  402. package/dist/collab/ydoc-manager.d.ts.map +1 -1
  403. package/dist/collab/ydoc-manager.js +49 -0
  404. package/dist/collab/ydoc-manager.js.map +1 -1
  405. package/dist/credentials/index.d.ts +27 -10
  406. package/dist/credentials/index.d.ts.map +1 -1
  407. package/dist/credentials/index.js +61 -19
  408. package/dist/credentials/index.js.map +1 -1
  409. package/dist/db/client.d.ts.map +1 -1
  410. package/dist/db/client.js +10 -1
  411. package/dist/db/client.js.map +1 -1
  412. package/dist/db/migrations.d.ts +13 -5
  413. package/dist/db/migrations.d.ts.map +1 -1
  414. package/dist/db/migrations.js +9 -2
  415. package/dist/db/migrations.js.map +1 -1
  416. package/dist/deploy/build.d.ts +12 -1
  417. package/dist/deploy/build.d.ts.map +1 -1
  418. package/dist/deploy/build.js +196 -24
  419. package/dist/deploy/build.js.map +1 -1
  420. package/dist/file-upload/builder.d.ts.map +1 -1
  421. package/dist/file-upload/builder.js +2 -1
  422. package/dist/file-upload/builder.js.map +1 -1
  423. package/dist/file-upload/registry.d.ts.map +1 -1
  424. package/dist/file-upload/registry.js +25 -1
  425. package/dist/file-upload/registry.js.map +1 -1
  426. package/dist/index.d.ts +1 -1
  427. package/dist/index.d.ts.map +1 -1
  428. package/dist/index.js +1 -1
  429. package/dist/index.js.map +1 -1
  430. package/dist/integrations/adapters/email.d.ts +17 -0
  431. package/dist/integrations/adapters/email.d.ts.map +1 -0
  432. package/dist/integrations/adapters/email.js +740 -0
  433. package/dist/integrations/adapters/email.js.map +1 -0
  434. package/dist/integrations/adapters/slack.d.ts.map +1 -1
  435. package/dist/integrations/adapters/slack.js +190 -32
  436. package/dist/integrations/adapters/slack.js.map +1 -1
  437. package/dist/integrations/adapters/telegram.d.ts.map +1 -1
  438. package/dist/integrations/adapters/telegram.js +56 -5
  439. package/dist/integrations/adapters/telegram.js.map +1 -1
  440. package/dist/integrations/adapters/whatsapp.d.ts.map +1 -1
  441. package/dist/integrations/adapters/whatsapp.js +91 -12
  442. package/dist/integrations/adapters/whatsapp.js.map +1 -1
  443. package/dist/integrations/google-docs-poller.d.ts.map +1 -1
  444. package/dist/integrations/google-docs-poller.js +5 -2
  445. package/dist/integrations/google-docs-poller.js.map +1 -1
  446. package/dist/integrations/index.d.ts +1 -0
  447. package/dist/integrations/index.d.ts.map +1 -1
  448. package/dist/integrations/index.js +1 -0
  449. package/dist/integrations/index.js.map +1 -1
  450. package/dist/integrations/internal-token.d.ts +18 -0
  451. package/dist/integrations/internal-token.d.ts.map +1 -0
  452. package/dist/integrations/internal-token.js +102 -0
  453. package/dist/integrations/internal-token.js.map +1 -0
  454. package/dist/integrations/pending-tasks-retry-job.d.ts +15 -0
  455. package/dist/integrations/pending-tasks-retry-job.d.ts.map +1 -0
  456. package/dist/integrations/pending-tasks-retry-job.js +210 -0
  457. package/dist/integrations/pending-tasks-retry-job.js.map +1 -0
  458. package/dist/integrations/pending-tasks-store.d.ts +56 -0
  459. package/dist/integrations/pending-tasks-store.d.ts.map +1 -0
  460. package/dist/integrations/pending-tasks-store.js +204 -0
  461. package/dist/integrations/pending-tasks-store.js.map +1 -0
  462. package/dist/integrations/plugin.d.ts.map +1 -1
  463. package/dist/integrations/plugin.js +340 -15
  464. package/dist/integrations/plugin.js.map +1 -1
  465. package/dist/integrations/task-queue-stats.d.ts +22 -0
  466. package/dist/integrations/task-queue-stats.d.ts.map +1 -0
  467. package/dist/integrations/task-queue-stats.js +117 -0
  468. package/dist/integrations/task-queue-stats.js.map +1 -0
  469. package/dist/integrations/types.d.ts +35 -2
  470. package/dist/integrations/types.d.ts.map +1 -1
  471. package/dist/integrations/webhook-handler.d.ts +29 -4
  472. package/dist/integrations/webhook-handler.d.ts.map +1 -1
  473. package/dist/integrations/webhook-handler.js +323 -85
  474. package/dist/integrations/webhook-handler.js.map +1 -1
  475. package/dist/jobs/cron.d.ts.map +1 -1
  476. package/dist/jobs/cron.js +12 -4
  477. package/dist/jobs/cron.js.map +1 -1
  478. package/dist/jobs/scheduler.d.ts.map +1 -1
  479. package/dist/jobs/scheduler.js +141 -16
  480. package/dist/jobs/scheduler.js.map +1 -1
  481. package/dist/jobs/tools.d.ts.map +1 -1
  482. package/dist/jobs/tools.js +94 -3
  483. package/dist/jobs/tools.js.map +1 -1
  484. package/dist/mcp/server.d.ts.map +1 -1
  485. package/dist/mcp/server.js +128 -62
  486. package/dist/mcp/server.js.map +1 -1
  487. package/dist/mcp-client/hub-routes.d.ts +14 -0
  488. package/dist/mcp-client/hub-routes.d.ts.map +1 -1
  489. package/dist/mcp-client/hub-routes.js +42 -2
  490. package/dist/mcp-client/hub-routes.js.map +1 -1
  491. package/dist/mcp-client/index.d.ts +1 -1
  492. package/dist/mcp-client/index.d.ts.map +1 -1
  493. package/dist/mcp-client/index.js +1 -1
  494. package/dist/mcp-client/index.js.map +1 -1
  495. package/dist/mcp-client/manager.d.ts +3 -0
  496. package/dist/mcp-client/manager.d.ts.map +1 -1
  497. package/dist/mcp-client/manager.js +33 -3
  498. package/dist/mcp-client/manager.js.map +1 -1
  499. package/dist/mcp-client/remote-store.d.ts +49 -1
  500. package/dist/mcp-client/remote-store.d.ts.map +1 -1
  501. package/dist/mcp-client/remote-store.js +253 -6
  502. package/dist/mcp-client/remote-store.js.map +1 -1
  503. package/dist/mcp-client/routes.d.ts.map +1 -1
  504. package/dist/mcp-client/routes.js +11 -9
  505. package/dist/mcp-client/routes.js.map +1 -1
  506. package/dist/mcp-client/visibility.d.ts +7 -3
  507. package/dist/mcp-client/visibility.d.ts.map +1 -1
  508. package/dist/mcp-client/visibility.js +16 -7
  509. package/dist/mcp-client/visibility.js.map +1 -1
  510. package/dist/notifications/actions.d.ts.map +1 -1
  511. package/dist/notifications/actions.js +7 -1
  512. package/dist/notifications/actions.js.map +1 -1
  513. package/dist/notifications/routes.d.ts +1 -1
  514. package/dist/notifications/routes.d.ts.map +1 -1
  515. package/dist/notifications/routes.js +20 -3
  516. package/dist/notifications/routes.js.map +1 -1
  517. package/dist/notifications/store.d.ts.map +1 -1
  518. package/dist/notifications/store.js +6 -1
  519. package/dist/notifications/store.js.map +1 -1
  520. package/dist/oauth-tokens/google-refresh.d.ts.map +1 -1
  521. package/dist/oauth-tokens/google-refresh.js +6 -0
  522. package/dist/oauth-tokens/google-refresh.js.map +1 -1
  523. package/dist/oauth-tokens/store.d.ts +43 -2
  524. package/dist/oauth-tokens/store.d.ts.map +1 -1
  525. package/dist/oauth-tokens/store.js +83 -14
  526. package/dist/oauth-tokens/store.js.map +1 -1
  527. package/dist/observability/experiments.js +5 -5
  528. package/dist/observability/experiments.js.map +1 -1
  529. package/dist/observability/routes.d.ts.map +1 -1
  530. package/dist/observability/routes.js +37 -8
  531. package/dist/observability/routes.js.map +1 -1
  532. package/dist/observability/store.d.ts.map +1 -1
  533. package/dist/observability/store.js +19 -3
  534. package/dist/observability/store.js.map +1 -1
  535. package/dist/observability/types.d.ts +7 -0
  536. package/dist/observability/types.d.ts.map +1 -1
  537. package/dist/observability/types.js.map +1 -1
  538. package/dist/onboarding/default-steps.d.ts.map +1 -1
  539. package/dist/onboarding/default-steps.js +10 -4
  540. package/dist/onboarding/default-steps.js.map +1 -1
  541. package/dist/onboarding/plugin.d.ts.map +1 -1
  542. package/dist/onboarding/plugin.js +63 -32
  543. package/dist/onboarding/plugin.js.map +1 -1
  544. package/dist/onboarding/types.d.ts +6 -1
  545. package/dist/onboarding/types.d.ts.map +1 -1
  546. package/dist/org/accept-pending.d.ts.map +1 -1
  547. package/dist/org/accept-pending.js +2 -1
  548. package/dist/org/accept-pending.js.map +1 -1
  549. package/dist/org/context.d.ts +35 -0
  550. package/dist/org/context.d.ts.map +1 -1
  551. package/dist/org/context.js +136 -0
  552. package/dist/org/context.js.map +1 -1
  553. package/dist/org/handlers.d.ts +76 -0
  554. package/dist/org/handlers.d.ts.map +1 -1
  555. package/dist/org/handlers.js +411 -2
  556. package/dist/org/handlers.js.map +1 -1
  557. package/dist/org/index.d.ts +2 -2
  558. package/dist/org/index.d.ts.map +1 -1
  559. package/dist/org/index.js +2 -2
  560. package/dist/org/index.js.map +1 -1
  561. package/dist/org/migrations.d.ts.map +1 -1
  562. package/dist/org/migrations.js +8 -0
  563. package/dist/org/migrations.js.map +1 -1
  564. package/dist/org/plugin.d.ts +6 -0
  565. package/dist/org/plugin.d.ts.map +1 -1
  566. package/dist/org/plugin.js +71 -7
  567. package/dist/org/plugin.js.map +1 -1
  568. package/dist/org/schema.d.ts +38 -0
  569. package/dist/org/schema.d.ts.map +1 -1
  570. package/dist/org/schema.js +2 -0
  571. package/dist/org/schema.js.map +1 -1
  572. package/dist/org/types.d.ts +7 -0
  573. package/dist/org/types.d.ts.map +1 -1
  574. package/dist/progress/actions.d.ts.map +1 -1
  575. package/dist/progress/actions.js +10 -1
  576. package/dist/progress/actions.js.map +1 -1
  577. package/dist/progress/routes.d.ts +1 -1
  578. package/dist/progress/routes.d.ts.map +1 -1
  579. package/dist/progress/routes.js +20 -3
  580. package/dist/progress/routes.js.map +1 -1
  581. package/dist/progress/store.d.ts.map +1 -1
  582. package/dist/progress/store.js +6 -1
  583. package/dist/progress/store.js.map +1 -1
  584. package/dist/resources/handlers.d.ts.map +1 -1
  585. package/dist/resources/handlers.js +35 -7
  586. package/dist/resources/handlers.js.map +1 -1
  587. package/dist/resources/script-helpers.d.ts.map +1 -1
  588. package/dist/resources/script-helpers.js +15 -3
  589. package/dist/resources/script-helpers.js.map +1 -1
  590. package/dist/resources/store.d.ts.map +1 -1
  591. package/dist/resources/store.js +12 -4
  592. package/dist/resources/store.js.map +1 -1
  593. package/dist/scripts/call-agent.d.ts +1 -0
  594. package/dist/scripts/call-agent.d.ts.map +1 -1
  595. package/dist/scripts/call-agent.js +146 -36
  596. package/dist/scripts/call-agent.js.map +1 -1
  597. package/dist/scripts/chat/search-chats.d.ts.map +1 -1
  598. package/dist/scripts/chat/search-chats.js +3 -2
  599. package/dist/scripts/chat/search-chats.js.map +1 -1
  600. package/dist/scripts/db/exec.d.ts +1 -1
  601. package/dist/scripts/db/exec.d.ts.map +1 -1
  602. package/dist/scripts/db/exec.js +22 -3
  603. package/dist/scripts/db/exec.js.map +1 -1
  604. package/dist/scripts/db/index.d.ts.map +1 -1
  605. package/dist/scripts/db/index.js +2 -0
  606. package/dist/scripts/db/index.js.map +1 -1
  607. package/dist/scripts/db/migrate-user-api-keys.d.ts +24 -0
  608. package/dist/scripts/db/migrate-user-api-keys.d.ts.map +1 -0
  609. package/dist/scripts/db/migrate-user-api-keys.js +234 -0
  610. package/dist/scripts/db/migrate-user-api-keys.js.map +1 -0
  611. package/dist/scripts/db/query.d.ts +1 -1
  612. package/dist/scripts/db/query.d.ts.map +1 -1
  613. package/dist/scripts/db/query.js +22 -3
  614. package/dist/scripts/db/query.js.map +1 -1
  615. package/dist/scripts/db/scoping.d.ts.map +1 -1
  616. package/dist/scripts/db/scoping.js +15 -9
  617. package/dist/scripts/db/scoping.js.map +1 -1
  618. package/dist/scripts/db/wipe-leaked-builder-keys.d.ts +27 -0
  619. package/dist/scripts/db/wipe-leaked-builder-keys.d.ts.map +1 -0
  620. package/dist/scripts/db/wipe-leaked-builder-keys.js +163 -0
  621. package/dist/scripts/db/wipe-leaked-builder-keys.js.map +1 -0
  622. package/dist/scripts/dev/shell.d.ts.map +1 -1
  623. package/dist/scripts/dev/shell.js +3 -1
  624. package/dist/scripts/dev/shell.js.map +1 -1
  625. package/dist/scripts/resources/delete-memory.d.ts.map +1 -1
  626. package/dist/scripts/resources/delete-memory.js +2 -1
  627. package/dist/scripts/resources/delete-memory.js.map +1 -1
  628. package/dist/scripts/resources/delete.d.ts.map +1 -1
  629. package/dist/scripts/resources/delete.js +2 -1
  630. package/dist/scripts/resources/delete.js.map +1 -1
  631. package/dist/scripts/resources/list.d.ts.map +1 -1
  632. package/dist/scripts/resources/list.js +2 -1
  633. package/dist/scripts/resources/list.js.map +1 -1
  634. package/dist/scripts/resources/migrate-learnings.d.ts.map +1 -1
  635. package/dist/scripts/resources/migrate-learnings.js +2 -1
  636. package/dist/scripts/resources/migrate-learnings.js.map +1 -1
  637. package/dist/scripts/resources/read.d.ts.map +1 -1
  638. package/dist/scripts/resources/read.js +2 -1
  639. package/dist/scripts/resources/read.js.map +1 -1
  640. package/dist/scripts/resources/save-memory.d.ts.map +1 -1
  641. package/dist/scripts/resources/save-memory.js +2 -1
  642. package/dist/scripts/resources/save-memory.js.map +1 -1
  643. package/dist/scripts/resources/write.d.ts.map +1 -1
  644. package/dist/scripts/resources/write.js +2 -1
  645. package/dist/scripts/resources/write.js.map +1 -1
  646. package/dist/secrets/onboarding.d.ts.map +1 -1
  647. package/dist/secrets/onboarding.js +24 -16
  648. package/dist/secrets/onboarding.js.map +1 -1
  649. package/dist/secrets/register-framework-secrets.d.ts +5 -0
  650. package/dist/secrets/register-framework-secrets.d.ts.map +1 -1
  651. package/dist/secrets/register-framework-secrets.js +7 -44
  652. package/dist/secrets/register-framework-secrets.js.map +1 -1
  653. package/dist/secrets/routes.d.ts.map +1 -1
  654. package/dist/secrets/routes.js +139 -37
  655. package/dist/secrets/routes.js.map +1 -1
  656. package/dist/secrets/storage.d.ts.map +1 -1
  657. package/dist/secrets/storage.js +23 -12
  658. package/dist/secrets/storage.js.map +1 -1
  659. package/dist/secrets/substitution.d.ts +24 -2
  660. package/dist/secrets/substitution.d.ts.map +1 -1
  661. package/dist/secrets/substitution.js +58 -8
  662. package/dist/secrets/substitution.js.map +1 -1
  663. package/dist/server/action-discovery.d.ts.map +1 -1
  664. package/dist/server/action-discovery.js +54 -51
  665. package/dist/server/action-discovery.js.map +1 -1
  666. package/dist/server/action-routes.d.ts.map +1 -1
  667. package/dist/server/action-routes.js +42 -15
  668. package/dist/server/action-routes.js.map +1 -1
  669. package/dist/server/agent-chat-plugin.d.ts.map +1 -1
  670. package/dist/server/agent-chat-plugin.js +632 -373
  671. package/dist/server/agent-chat-plugin.js.map +1 -1
  672. package/dist/server/agent-discovery.d.ts +8 -0
  673. package/dist/server/agent-discovery.d.ts.map +1 -1
  674. package/dist/server/agent-discovery.js +39 -12
  675. package/dist/server/agent-discovery.js.map +1 -1
  676. package/dist/server/agent-teams.d.ts.map +1 -1
  677. package/dist/server/agent-teams.js +4 -1
  678. package/dist/server/agent-teams.js.map +1 -1
  679. package/dist/server/analytics.d.ts +0 -1
  680. package/dist/server/analytics.d.ts.map +1 -1
  681. package/dist/server/analytics.js +0 -1
  682. package/dist/server/analytics.js.map +1 -1
  683. package/dist/server/app-base-path.d.ts +4 -0
  684. package/dist/server/app-base-path.d.ts.map +1 -0
  685. package/dist/server/app-base-path.js +33 -0
  686. package/dist/server/app-base-path.js.map +1 -0
  687. package/dist/server/auth.d.ts +29 -0
  688. package/dist/server/auth.d.ts.map +1 -1
  689. package/dist/server/auth.js +629 -82
  690. package/dist/server/auth.js.map +1 -1
  691. package/dist/server/better-auth-instance.d.ts +1 -0
  692. package/dist/server/better-auth-instance.d.ts.map +1 -1
  693. package/dist/server/better-auth-instance.js +67 -15
  694. package/dist/server/better-auth-instance.js.map +1 -1
  695. package/dist/server/builder-browser.d.ts +16 -1
  696. package/dist/server/builder-browser.d.ts.map +1 -1
  697. package/dist/server/builder-browser.js +102 -16
  698. package/dist/server/builder-browser.js.map +1 -1
  699. package/dist/server/cli-capture.d.ts +31 -0
  700. package/dist/server/cli-capture.d.ts.map +1 -0
  701. package/dist/server/cli-capture.js +120 -0
  702. package/dist/server/cli-capture.js.map +1 -0
  703. package/dist/server/collab-plugin.d.ts +16 -0
  704. package/dist/server/collab-plugin.d.ts.map +1 -1
  705. package/dist/server/collab-plugin.js +87 -19
  706. package/dist/server/collab-plugin.js.map +1 -1
  707. package/dist/server/core-routes-plugin.d.ts.map +1 -1
  708. package/dist/server/core-routes-plugin.js +499 -164
  709. package/dist/server/core-routes-plugin.js.map +1 -1
  710. package/dist/server/create-server.d.ts +2 -0
  711. package/dist/server/create-server.d.ts.map +1 -1
  712. package/dist/server/create-server.js +82 -11
  713. package/dist/server/create-server.js.map +1 -1
  714. package/dist/server/credential-provider.d.ts +54 -2
  715. package/dist/server/credential-provider.d.ts.map +1 -1
  716. package/dist/server/credential-provider.js +164 -2
  717. package/dist/server/credential-provider.js.map +1 -1
  718. package/dist/server/csrf.d.ts +58 -0
  719. package/dist/server/csrf.d.ts.map +1 -0
  720. package/dist/server/csrf.js +165 -0
  721. package/dist/server/csrf.js.map +1 -0
  722. package/dist/server/design-token-utils.d.ts +132 -0
  723. package/dist/server/design-token-utils.d.ts.map +1 -0
  724. package/dist/server/design-token-utils.js +714 -0
  725. package/dist/server/design-token-utils.js.map +1 -0
  726. package/dist/server/email.d.ts +10 -0
  727. package/dist/server/email.d.ts.map +1 -1
  728. package/dist/server/email.js +63 -16
  729. package/dist/server/email.js.map +1 -1
  730. package/dist/server/framework-request-handler.d.ts +20 -0
  731. package/dist/server/framework-request-handler.d.ts.map +1 -1
  732. package/dist/server/framework-request-handler.js +140 -24
  733. package/dist/server/framework-request-handler.js.map +1 -1
  734. package/dist/server/google-auth-plugin.d.ts.map +1 -1
  735. package/dist/server/google-auth-plugin.js +10 -2
  736. package/dist/server/google-auth-plugin.js.map +1 -1
  737. package/dist/server/google-oauth.d.ts +102 -3
  738. package/dist/server/google-oauth.d.ts.map +1 -1
  739. package/dist/server/google-oauth.js +263 -43
  740. package/dist/server/google-oauth.js.map +1 -1
  741. package/dist/server/index.d.ts +5 -5
  742. package/dist/server/index.d.ts.map +1 -1
  743. package/dist/server/index.js +5 -5
  744. package/dist/server/index.js.map +1 -1
  745. package/dist/server/oauth-helpers.d.ts +8 -3
  746. package/dist/server/oauth-helpers.d.ts.map +1 -1
  747. package/dist/server/oauth-helpers.js +12 -8
  748. package/dist/server/oauth-helpers.js.map +1 -1
  749. package/dist/server/onboarding-html.d.ts.map +1 -1
  750. package/dist/server/onboarding-html.js +50 -9
  751. package/dist/server/onboarding-html.js.map +1 -1
  752. package/dist/server/poll.d.ts +33 -0
  753. package/dist/server/poll.d.ts.map +1 -1
  754. package/dist/server/poll.js +43 -2
  755. package/dist/server/poll.js.map +1 -1
  756. package/dist/server/request-context.d.ts +102 -3
  757. package/dist/server/request-context.d.ts.map +1 -1
  758. package/dist/server/request-context.js +100 -7
  759. package/dist/server/request-context.js.map +1 -1
  760. package/dist/server/security-headers.d.ts +51 -0
  761. package/dist/server/security-headers.d.ts.map +1 -0
  762. package/dist/server/security-headers.js +90 -0
  763. package/dist/server/security-headers.js.map +1 -0
  764. package/dist/server/ssr-handler.d.ts.map +1 -1
  765. package/dist/server/ssr-handler.js +96 -2
  766. package/dist/server/ssr-handler.js.map +1 -1
  767. package/dist/server/transcribe-voice.d.ts.map +1 -1
  768. package/dist/server/transcribe-voice.js +376 -60
  769. package/dist/server/transcribe-voice.js.map +1 -1
  770. package/dist/server/voice-providers-status.d.ts +12 -0
  771. package/dist/server/voice-providers-status.d.ts.map +1 -0
  772. package/dist/server/voice-providers-status.js +71 -0
  773. package/dist/server/voice-providers-status.js.map +1 -0
  774. package/dist/sharing/access.d.ts.map +1 -1
  775. package/dist/sharing/access.js +16 -13
  776. package/dist/sharing/access.js.map +1 -1
  777. package/dist/sharing/actions/share-resource.d.ts +1 -0
  778. package/dist/sharing/actions/share-resource.d.ts.map +1 -1
  779. package/dist/sharing/actions/share-resource.js +45 -0
  780. package/dist/sharing/actions/share-resource.js.map +1 -1
  781. package/dist/sharing/schema.d.ts +1 -1
  782. package/dist/styles/agent-native.css +5 -0
  783. package/dist/templates/default/.agents/skills/delegate-to-agent/SKILL.md +54 -0
  784. package/dist/templates/default/app/root.tsx +51 -14
  785. package/dist/templates/default/app/routes/_index.tsx +6 -1
  786. package/dist/templates/default/public/favicon.svg +13 -0
  787. package/dist/templates/default/public/icon-180.svg +12 -3
  788. package/dist/templates/default/public/icon-192.svg +12 -3
  789. package/dist/templates/default/public/icon-512.svg +12 -3
  790. package/dist/templates/default/react-router.config.ts +3 -0
  791. package/dist/templates/workspace-core/package.json +22 -4
  792. package/dist/templates/workspace-core/src/credentials.ts +32 -5
  793. package/dist/templates/workspace-core/tsconfig.json +4 -1
  794. package/dist/terminal/pty-server.d.ts.map +1 -1
  795. package/dist/terminal/pty-server.js +7 -1
  796. package/dist/terminal/pty-server.js.map +1 -1
  797. package/dist/terminal/terminal-plugin.d.ts.map +1 -1
  798. package/dist/terminal/terminal-plugin.js +26 -6
  799. package/dist/terminal/terminal-plugin.js.map +1 -1
  800. package/dist/tools/actions.d.ts +3 -0
  801. package/dist/tools/actions.d.ts.map +1 -0
  802. package/dist/tools/actions.js +270 -0
  803. package/dist/tools/actions.js.map +1 -0
  804. package/dist/tools/fetch-tool.d.ts +1 -0
  805. package/dist/tools/fetch-tool.d.ts.map +1 -1
  806. package/dist/tools/fetch-tool.js +39 -17
  807. package/dist/tools/fetch-tool.js.map +1 -1
  808. package/dist/tools/html-shell.d.ts +44 -0
  809. package/dist/tools/html-shell.d.ts.map +1 -0
  810. package/dist/tools/html-shell.js +485 -0
  811. package/dist/tools/html-shell.js.map +1 -0
  812. package/dist/tools/proxy-security.d.ts +12 -0
  813. package/dist/tools/proxy-security.d.ts.map +1 -0
  814. package/dist/tools/proxy-security.js +158 -0
  815. package/dist/tools/proxy-security.js.map +1 -0
  816. package/dist/tools/routes.d.ts +2 -0
  817. package/dist/tools/routes.d.ts.map +1 -0
  818. package/dist/tools/routes.js +629 -0
  819. package/dist/tools/routes.js.map +1 -0
  820. package/dist/tools/schema.d.ts +578 -0
  821. package/dist/tools/schema.d.ts.map +1 -0
  822. package/dist/tools/schema.js +115 -0
  823. package/dist/tools/schema.js.map +1 -0
  824. package/dist/tools/slots/routes.d.ts +15 -0
  825. package/dist/tools/slots/routes.d.ts.map +1 -0
  826. package/dist/tools/slots/routes.js +94 -0
  827. package/dist/tools/slots/routes.js.map +1 -0
  828. package/dist/tools/slots/schema.d.ts +303 -0
  829. package/dist/tools/slots/schema.d.ts.map +1 -0
  830. package/dist/tools/slots/schema.js +76 -0
  831. package/dist/tools/slots/schema.js.map +1 -0
  832. package/dist/tools/slots/store.d.ts +66 -0
  833. package/dist/tools/slots/store.d.ts.map +1 -0
  834. package/dist/tools/slots/store.js +227 -0
  835. package/dist/tools/slots/store.js.map +1 -0
  836. package/dist/tools/store.d.ts +40 -0
  837. package/dist/tools/store.d.ts.map +1 -0
  838. package/dist/tools/store.js +181 -0
  839. package/dist/tools/store.js.map +1 -0
  840. package/dist/tools/theme.d.ts +2 -0
  841. package/dist/tools/theme.d.ts.map +1 -0
  842. package/dist/tools/theme.js +67 -0
  843. package/dist/tools/theme.js.map +1 -0
  844. package/dist/tools/url-safety.d.ts +24 -0
  845. package/dist/tools/url-safety.d.ts.map +1 -0
  846. package/dist/tools/url-safety.js +224 -0
  847. package/dist/tools/url-safety.js.map +1 -0
  848. package/dist/tracking/providers.d.ts.map +1 -1
  849. package/dist/tracking/providers.js +28 -11
  850. package/dist/tracking/providers.js.map +1 -1
  851. package/dist/tracking/registry.d.ts.map +1 -1
  852. package/dist/tracking/registry.js +7 -3
  853. package/dist/tracking/registry.js.map +1 -1
  854. package/dist/transcription/builder-transcription.d.ts.map +1 -1
  855. package/dist/transcription/builder-transcription.js +26 -14
  856. package/dist/transcription/builder-transcription.js.map +1 -1
  857. package/dist/triggers/actions.d.ts.map +1 -1
  858. package/dist/triggers/actions.js +11 -6
  859. package/dist/triggers/actions.js.map +1 -1
  860. package/dist/triggers/condition-evaluator.d.ts +8 -0
  861. package/dist/triggers/condition-evaluator.d.ts.map +1 -1
  862. package/dist/triggers/condition-evaluator.js +39 -4
  863. package/dist/triggers/condition-evaluator.js.map +1 -1
  864. package/dist/triggers/dispatcher.d.ts.map +1 -1
  865. package/dist/triggers/dispatcher.js +67 -4
  866. package/dist/triggers/dispatcher.js.map +1 -1
  867. package/dist/vite/action-types-plugin.d.ts.map +1 -1
  868. package/dist/vite/action-types-plugin.js +18 -7
  869. package/dist/vite/action-types-plugin.js.map +1 -1
  870. package/dist/vite/client.d.ts +2 -0
  871. package/dist/vite/client.d.ts.map +1 -1
  872. package/dist/vite/client.js +240 -8
  873. package/dist/vite/client.js.map +1 -1
  874. package/docs/content/a2a-protocol.md +2 -2
  875. package/docs/content/authentication.md +78 -12
  876. package/docs/content/cloneable-saas.md +59 -62
  877. package/docs/content/drop-in-agent.md +2 -2
  878. package/docs/content/faq.md +73 -43
  879. package/docs/content/getting-started.md +37 -61
  880. package/docs/content/mcp-clients.md +14 -1
  881. package/docs/content/messaging.md +324 -0
  882. package/docs/content/onboarding.md +82 -12
  883. package/docs/content/pure-agent-apps.md +55 -28
  884. package/docs/content/template-analytics.md +65 -59
  885. package/docs/content/template-calendar.md +61 -56
  886. package/docs/content/template-clips.md +25 -23
  887. package/docs/content/template-content.md +36 -26
  888. package/docs/content/template-design.md +55 -0
  889. package/docs/content/template-dispatch.md +15 -1
  890. package/docs/content/template-forms.md +19 -16
  891. package/docs/content/template-mail.md +78 -80
  892. package/docs/content/template-slides.md +43 -31
  893. package/docs/content/template-video.md +49 -22
  894. package/docs/content/tools.md +107 -0
  895. package/docs/content/what-is-agent-native.md +89 -105
  896. package/package.json +5 -1
  897. package/src/templates/default/.agents/skills/delegate-to-agent/SKILL.md +54 -0
  898. package/src/templates/default/app/root.tsx +51 -14
  899. package/src/templates/default/app/routes/_index.tsx +6 -1
  900. package/src/templates/default/public/favicon.svg +13 -0
  901. package/src/templates/default/public/icon-180.svg +12 -3
  902. package/src/templates/default/public/icon-192.svg +12 -3
  903. package/src/templates/default/public/icon-512.svg +12 -3
  904. package/src/templates/default/react-router.config.ts +3 -0
  905. package/src/templates/workspace-core/package.json +22 -4
  906. package/src/templates/workspace-core/src/credentials.ts +32 -5
  907. package/src/templates/workspace-core/tsconfig.json +4 -1
  908. package/docs/content/integrations.md +0 -198
@@ -1,20 +1,22 @@
1
- import { runWithRequestContext, getRequestOrgId } from "./request-context.js";
1
+ import { runWithRequestContext, getRequestOrgId, getRequestUserEmail, getRequestRunContext, ensureRequestRunContext, } from "./request-context.js";
2
2
  import { getSetting, putSetting } from "../settings/store.js";
3
3
  import { getH3App, trackPluginInit } from "./framework-request-handler.js";
4
4
  import { createProductionAgentHandler, runAgentLoop, actionsToEngineTools, getActiveRunForThreadAsync, abortRun, subscribeToRun, } from "../agent/production-agent.js";
5
5
  import { resolveEngine, createAnthropicEngine } from "../agent/engine/index.js";
6
+ import { DEFAULT_MODEL } from "../agent/default-model.js";
6
7
  import { McpClientManager, loadMcpConfig, autoDetectMcpConfig, mcpToolsToActionEntries, syncMcpActionEntries, mountMcpServersRoutes, mountMcpHubRoutes, buildMergedConfig, getHubStatus, isHubServeEnabled, } from "../mcp-client/index.js";
7
8
  import { discoverAgents } from "./agent-discovery.js";
8
9
  import { loadSchemaPromptBlock } from "./schema-prompt.js";
9
10
  import { buildAssistantMessage, extractThreadMeta, } from "../agent/thread-data-builder.js";
10
11
  import { defineEventHandler, setResponseStatus, setResponseHeader, getMethod, getQuery, getHeader, } from "h3";
11
- import { getSession } from "./auth.js";
12
+ import { getSession, DEV_MODE_USER_EMAIL } from "./auth.js";
12
13
  import { getOrigin } from "./google-oauth.js";
13
- import { createThread, getThread, listThreads, searchThreads, updateThreadData, withThreadDataLock, deleteThread, setThreadQueuedMessages, } from "../chat-threads/store.js";
14
+ import { createThread, forkThread, getThread, listThreads, searchThreads, updateThreadData, withThreadDataLock, deleteThread, setThreadQueuedMessages, } from "../chat-threads/store.js";
14
15
  import { resourceListAccessible, resourceList, resourceGet, resourceGetByPath, ensurePersonalDefaults, SHARED_OWNER, } from "../resources/store.js";
15
16
  import nodePath from "node:path";
16
17
  import { readBody } from "./h3-helpers.js";
17
18
  import { getBuilderBrowserConnectUrl } from "./builder-browser.js";
19
+ import { captureCliOutput } from "./cli-capture.js";
18
20
  // Lazy fs — loaded via dynamic import() on first use.
19
21
  // This avoids require() which bundlers convert to createRequire(import.meta.url)
20
22
  // that crashes on CF Workers where import.meta.url is undefined.
@@ -27,7 +29,9 @@ async function lazyFs() {
27
29
  }
28
30
  /**
29
31
  * Wraps a core CLI script (that writes to console.log) as a ActionEntry
30
- * by capturing stdout.
32
+ * by capturing stdout. Uses an AsyncLocalStorage-backed capture so
33
+ * concurrent tool calls do not corrupt the global console/stdout pointers
34
+ * (see `cli-capture.ts`).
31
35
  */
32
36
  function wrapCliScript(tool, cliDefault, opts) {
33
37
  return {
@@ -38,39 +42,7 @@ function wrapCliScript(tool, cliDefault, opts) {
38
42
  for (const [k, v] of Object.entries(args)) {
39
43
  cliArgs.push(`--${k}`, v);
40
44
  }
41
- const logs = [];
42
- const origLog = console.log;
43
- const origError = console.error;
44
- const origStdoutWrite = process.stdout.write;
45
- console.log = (...a) => {
46
- logs.push(a.map(String).join(" "));
47
- };
48
- console.error = (...a) => {
49
- logs.push(a.map(String).join(" "));
50
- };
51
- // Intercept process.stdout.write so scripts that write directly
52
- // (e.g. resource-read) have their output captured
53
- process.stdout.write = ((chunk, ...rest) => {
54
- if (typeof chunk === "string") {
55
- logs.push(chunk);
56
- }
57
- else if (Buffer.isBuffer(chunk)) {
58
- logs.push(chunk.toString());
59
- }
60
- return true;
61
- });
62
- try {
63
- await cliDefault(cliArgs);
64
- }
65
- catch (err) {
66
- logs.push(`Error: ${err?.message ?? String(err)}`);
67
- }
68
- finally {
69
- console.log = origLog;
70
- console.error = origError;
71
- process.stdout.write = origStdoutWrite;
72
- }
73
- return logs.join("\n") || "(no output)";
45
+ return captureCliOutput(() => cliDefault(cliArgs));
74
46
  },
75
47
  };
76
48
  }
@@ -156,6 +128,12 @@ function createRefreshScreenEntry() {
156
128
  }
157
129
  /** Well-known application-state key used by the refresh-screen tool. */
158
130
  const SCREEN_REFRESH_KEY = "__screen_refresh__";
131
+ /**
132
+ * In-memory rate-limit tracker for `/generate-title`. Keyed by user email,
133
+ * value is recent invocation timestamps within the rolling window. Stale
134
+ * entries are pruned on read.
135
+ */
136
+ const generateTitleRateLimit = new Map();
159
137
  /**
160
138
  * Creates the `set-search-params` / `set-url-path` tools. Writes a one-shot
161
139
  * URL command to application_state; the client's URLSync component applies
@@ -673,17 +651,94 @@ function createBuilderBrowserTool(deps) {
673
651
  },
674
652
  },
675
653
  run: async (args) => {
676
- const configured = !!(process.env.BUILDER_PRIVATE_KEY && process.env.BUILDER_PUBLIC_KEY);
654
+ const { resolveBuilderCredentials } = await import("./credential-provider.js");
655
+ const creds = await resolveBuilderCredentials();
656
+ const configured = !!(creds.privateKey && creds.publicKey);
677
657
  const prompt = typeof args?.prompt === "string" ? args.prompt : "";
678
658
  return JSON.stringify({
679
659
  kind: "connect-builder-card",
680
660
  configured,
681
661
  connectUrl: getBuilderBrowserConnectUrl(deps.getOrigin()),
682
- orgName: process.env.BUILDER_ORG_NAME || null,
662
+ orgName: creds.orgName || null,
683
663
  prompt,
684
664
  });
685
665
  },
686
666
  },
667
+ "activate-browser": {
668
+ tool: {
669
+ description: "Activate browser automation tools. Call this when you need to interact with a real browser — e.g. to extract design tokens from a rendered page, take screenshots, read computed styles from JS-heavy sites, or test a live URL. After activation, chrome-devtools MCP tools (navigate, click, evaluate_script, take_screenshot, etc.) become available on your next action. Requires Builder.io connection.",
670
+ parameters: {
671
+ type: "object",
672
+ properties: {
673
+ sessionId: {
674
+ type: "string",
675
+ description: "Optional session identifier for the browser connection. Auto-generated if omitted.",
676
+ },
677
+ },
678
+ },
679
+ },
680
+ run: async (args) => {
681
+ const { resolveBuilderCredentials } = await import("./credential-provider.js");
682
+ const creds = await resolveBuilderCredentials();
683
+ if (!creds.privateKey || !creds.publicKey) {
684
+ return JSON.stringify({
685
+ error: "builder-not-connected",
686
+ message: "Builder.io is not connected. Call `connect-builder` first to enable browser automation.",
687
+ });
688
+ }
689
+ const { requestBuilderBrowserConnection } = await import("./builder-browser.js");
690
+ const sessionId = (typeof args?.sessionId === "string" && args.sessionId) ||
691
+ `an-browser-${Date.now()}`;
692
+ let connection;
693
+ try {
694
+ connection = await requestBuilderBrowserConnection({ sessionId });
695
+ }
696
+ catch (err) {
697
+ return JSON.stringify({
698
+ error: "browser-connection-failed",
699
+ message: `Failed to get browser connection: ${err?.message ?? err}`,
700
+ });
701
+ }
702
+ const wsUrl = connection.wsUrl;
703
+ if (!wsUrl) {
704
+ return JSON.stringify({
705
+ error: "no-ws-url",
706
+ message: "Browser connection did not return a WebSocket URL.",
707
+ });
708
+ }
709
+ const manager = getGlobalMcpManager();
710
+ if (!manager) {
711
+ return JSON.stringify({
712
+ error: "no-mcp-manager",
713
+ message: "MCP manager is not available.",
714
+ });
715
+ }
716
+ // Add chrome-devtools-mcp server pointing at the provisioned browser
717
+ const currentConfig = manager.getConfig();
718
+ const servers = { ...(currentConfig?.servers ?? {}) };
719
+ servers["chrome-devtools"] = {
720
+ command: "npx",
721
+ args: [
722
+ "-y",
723
+ "chrome-devtools-mcp@latest",
724
+ "--wsEndpoint",
725
+ wsUrl,
726
+ "--categoryEmulation=false",
727
+ ],
728
+ type: "stdio",
729
+ };
730
+ await manager.reconfigure({
731
+ servers,
732
+ source: currentConfig?.source ?? "runtime",
733
+ });
734
+ return JSON.stringify({
735
+ success: true,
736
+ message: "Browser activated. Chrome DevTools MCP tools (mcp__chrome-devtools__*) are now available. Use them on your next action to navigate pages, read DOM, take screenshots, evaluate JavaScript, etc.",
737
+ wsUrl,
738
+ sessionId,
739
+ });
740
+ },
741
+ },
687
742
  };
688
743
  }
689
744
  /**
@@ -875,6 +930,9 @@ const FRAMEWORK_CORE_COMPACT = `
875
930
  5. **Screen refresh is automatic** — The framework auto-refreshes after mutating tool calls. Only call \`refresh-screen\` when you mutated data via a path the framework can't detect.
876
931
  6. **Memory** — Use \`save-memory\` proactively when you learn preferences, corrections, or project context.
877
932
  7. **Security** — Always use parameterized queries. Never \`dangerouslySetInnerHTML\`, \`innerHTML\`, or \`eval()\`.
933
+ 8. **\`db-*\` tools are internal only** — \`db-query\`, \`db-exec\`, \`db-patch\` ONLY access the app's own SQL database (settings, application_state, template tables). They CANNOT reach BigQuery, HubSpot, GA4, Jira, or any external data source. If the user asks about a table that is NOT in the app schema (e.g. \`dbt_analytics.*\`, \`dbt_mart.*\`, or any fully-qualified \`project.dataset.table\`), use the appropriate template action instead — \`bigquery\` for warehouse tables, \`ga4-report\` for Google Analytics, \`hubspot-deals\` for HubSpot, etc. **Never use \`db-query\` for external data — it will fail.**
934
+ 9. **Never fabricate data** — Do NOT invent numbers, metrics, records, or query results. Do NOT present estimated or example data as if it were real. If a data source is unavailable (missing credentials, connection error, tool failure), say so clearly, note the gap, and work with whatever data you do have. If no data can be retrieved at all, say "I can't retrieve this data right now" and explain why. Presenting made-up data as real is a critical failure — it is worse than admitting the limitation.
935
+ 10. **Never fabricate success from tool errors** — When any tool call returns an error (marked \`isError: true\`, contains "Command failed", "Error:", or non-zero exit output), the operation FAILED. Do NOT synthesize a success narrative or describe what the action "would have" produced. Report the failure verbatim from the tool output. This applies especially to \`shell(command="pnpm action ...")\` calls: if the action threw, it did NOT succeed.
878
936
 
879
937
  ### Resources
880
938
 
@@ -887,7 +945,7 @@ When the user says "show me", "go to", "open", etc., ALWAYS use \`navigate\` fir
887
945
 
888
946
  ### Extended Capabilities
889
947
 
890
- You also have tools for: inline embeds, chat history search, agent teams/sub-agents, recurring jobs, A2A cross-app calls, structured memory, and browser access. Call \`get-framework-context\` to read detailed instructions for any of these when needed.
948
+ You also have tools for: inline embeds, chat history search, agent teams/sub-agents, recurring jobs, A2A cross-app calls, structured memory, and browser automation (\`activate-browser\` to provision a real Chrome). Call \`get-framework-context\` to read detailed instructions for any of these when needed.
891
949
  `;
892
950
  /**
893
951
  * Verbose framework sections returned by the `get-framework-context` tool.
@@ -954,11 +1012,26 @@ Convert natural language to 5-field cron format:
954
1012
  builder: `### Connecting Builder.io
955
1013
 
956
1014
  When the user asks to connect Builder.io or you hit a "Builder not configured" error, call the \`connect-builder\` tool. It renders a one-click Connect card inline — do NOT write out multi-step setup instructions yourself.`,
957
- browser: `### Browser Access
958
-
959
- Use \`connect-builder\` when you need browser access backed by Builder. It renders a Connect card that provisions a browser session.
960
-
961
- - If Builder is not configured, the card will guide the user through setup.`,
1015
+ browser: `### Browser Automation
1016
+
1017
+ You can activate a real Chrome browser via Builder.io for tasks that need full page rendering:
1018
+ - Extracting design tokens from JS-heavy or SPA websites (computed styles, rendered colors/fonts)
1019
+ - Taking screenshots of live pages
1020
+ - Testing interactive flows on deployed URLs
1021
+ - Reading content from pages that require JavaScript execution
1022
+
1023
+ **How to use:**
1024
+ 1. Call \`activate-browser\` — this provisions a Chrome instance and registers chrome-devtools MCP tools
1025
+ 2. On your next action, use \`mcp__chrome-devtools__navigate_page\`, \`mcp__chrome-devtools__evaluate_script\`, \`mcp__chrome-devtools__take_screenshot\`, etc.
1026
+ 3. If Builder is not connected, call \`connect-builder\` first
1027
+
1028
+ **When to recommend browser automation:**
1029
+ - User wants to import a design system from a URL (JS-rendered sites give almost no useful data from plain HTML fetch)
1030
+ - User asks you to check how a deployed site looks or behaves
1031
+ - Any task involving reading computed/rendered page state
1032
+ - When \`web-request\` returns minimal/skeleton HTML from a modern SPA
1033
+
1034
+ Prefer \`web-request\` for simple API calls and static pages. Use browser automation when you need the real rendered page.`,
962
1035
  "call-agent": `### call-agent — External Apps Only
963
1036
 
964
1037
  The \`call-agent\` tool sends a message to a DIFFERENT, separately-deployed app's agent (A2A protocol). It is **not** for calling actions within the current app.
@@ -1023,6 +1096,9 @@ const FRAMEWORK_CORE = `
1023
1096
  5. **Screen refresh is automatic after action calls** — The framework auto-emits a refresh event after any successful mutating tool call (template actions like \`log-meal\`, \`update-form\`, \`edit-document\`, and the \`db-exec\` / \`db-patch\` tools). The UI re-fetches its queries without a full page reload. You do NOT need to call \`refresh-screen\` after an action — it's already handled. Only call \`refresh-screen\` explicitly when (a) you mutated data via a path the framework can't detect (e.g. writing directly to an external system whose results the app mirrors), or (b) you want to pass a \`scope\` hint so the UI narrows which queries to refetch. Do NOT tell the user to reload the page.
1024
1097
  6. **Memory** — Use the structured memory system to persist knowledge across sessions. Use \`save-memory\` proactively when you learn preferences, corrections, or project context. Update shared AGENTS.md for instructions that should apply to all users.
1025
1098
  7. **Security** — Always use \`defineAction\` with a Zod \`schema:\` for input validation. Never construct SQL with string concatenation — use parameterized queries via db-query/db-exec. Never use \`dangerouslySetInnerHTML\`, \`innerHTML\`, or \`eval()\`. Never expose secrets in responses or source code. Every table with user data must have \`owner_email\`.
1099
+ 8. **\`db-*\` tools are internal only** — \`db-query\`, \`db-exec\`, \`db-patch\` ONLY access the app's own SQL database (settings, application_state, template tables). They CANNOT reach BigQuery, HubSpot, GA4, Jira, or any external data source. If the user asks about a table that is NOT in the app schema (e.g. \`dbt_analytics.*\`, \`dbt_mart.*\`, or any fully-qualified \`project.dataset.table\`), use the appropriate template action instead — \`bigquery\` for warehouse tables, \`ga4-report\` for Google Analytics, \`hubspot-deals\` for HubSpot, etc. **Never use \`db-query\` for external data — it will fail.**
1100
+ 9. **Never fabricate data** — Do NOT invent numbers, metrics, records, or query results. Do NOT present estimated or example data as if it were real. If a data source is unavailable (missing credentials, connection error, tool failure), say so clearly, note the gap, and work with whatever data you do have. If no data can be retrieved at all, say "I can't retrieve this data right now" and explain why. Presenting made-up data as real is a critical failure — it is worse than admitting the limitation.
1101
+ 10. **Never fabricate success from tool errors** — When any tool call returns an error (marked \`isError: true\`, contains "Command failed", "Error:", or non-zero exit output), the operation FAILED. Do NOT synthesize a success narrative, format a result table, or describe what the action "would have" produced. Report the failure verbatim from the tool output. This applies especially to \`shell(command="pnpm action ...")\` calls: if the underlying action threw (visible in the error text), the action did NOT succeed — report the error, do not describe a successful outcome.
1026
1102
 
1027
1103
  ### Resources
1028
1104
 
@@ -1123,11 +1199,9 @@ Job instructions should be self-contained — include which actions to call, wha
1123
1199
 
1124
1200
  When the user asks to connect Builder.io, needs Builder for LLM access / browser automation, or you hit a "Builder not configured" error, call the \`connect-builder\` tool. It renders a one-click Connect card inline in the chat — do NOT write out multi-step setup instructions yourself (no "Option 1 / Option 2", no terminal commands). Just call the tool and let the card handle the rest.
1125
1201
 
1126
- ### Browser Access
1202
+ ### Browser Automation
1127
1203
 
1128
- Use \`connect-builder\` when you need browser access backed by Builder. It renders a Connect card that provisions a browser session.
1129
-
1130
- - If Builder is not configured, the card will guide the user through setup.
1204
+ Call \`activate-browser\` to provision a real Chrome browser. After activation, chrome-devtools MCP tools become available for navigating pages, reading rendered DOM, taking screenshots, and evaluating JavaScript. If Builder is not connected, call \`connect-builder\` first. Use browser automation proactively when tasks benefit from full page rendering (design system extraction from URLs, visual verification, SPA content reading).
1131
1205
 
1132
1206
  ### call-agent — External Apps Only
1133
1207
 
@@ -1182,8 +1256,16 @@ The agent and the UI are equal partners — everything the UI can do, you can do
1182
1256
 
1183
1257
  **In production mode, you operate through registered actions exposed as tools.** These are your capabilities — use them to read data, take actions, and help the user. You cannot edit source code or access the filesystem directly. Your tools are the app's API.
1184
1258
 
1259
+ ### Tools (Mini-Apps) — Use \`create-tool\` for tools / widgets / dashboards
1260
+
1261
+ If the user asks you to create, build, or make a **tool**, **widget**, **dashboard**, **calculator**, **mini-app**, or any small self-contained interactive utility — call \`create-tool\` immediately with a self-contained Alpine.js HTML body. This is **NOT** a code change and does **NOT** go through \`connect-builder\`. Tools are sandboxed mini-apps stored in the database — no source files are touched, no PR is opened, no build is required. The tool appears in the Tools view and can be edited later via \`update-tool\`.
1262
+
1263
+ When in doubt — if the request mentions "tool", "widget", "dashboard", "calculator", or asks for a small interactive utility — choose \`create-tool\`. Do **not** preface the call with planning text like "let me build the dashboard…" — just call \`create-tool\` directly. One tool call, one response.
1264
+
1185
1265
  ### Code Changes Not Available — Call \`connect-builder\` Immediately
1186
1266
 
1267
+ If the request matches the Tools section above (tool / widget / dashboard / calculator / mini-app), use \`create-tool\` instead — do NOT route it to \`connect-builder\`.
1268
+
1187
1269
  When the user asks you to change the UI, modify code, add a feature, fix a bug in the app itself, change styles, add a hook, create a component, add a route, add an integration, or anything else that requires editing source files — you MUST take exactly these steps, in order:
1188
1270
 
1189
1271
  1. Call the \`connect-builder\` tool, passing the user's full request verbatim as the \`prompt\` argument. This renders an inline card. If Builder is connected, the card hands the prompt off to Builder's cloud agent on one click and returns a branch URL; otherwise it shows a connect / waitlist flow. Either way, Builder writes the code — no local setup, no clone, no install.
@@ -1231,9 +1313,13 @@ The agent and the UI are equal partners — everything the UI can do, you can do
1231
1313
 
1232
1314
  **In production mode, you operate through registered actions exposed as tools.** These are your capabilities — use them to read data, take actions, and help the user. You cannot edit source code or access the filesystem directly. Your tools are the app's API.
1233
1315
 
1316
+ ### Tools (Mini-Apps) — Use \`create-tool\`
1317
+
1318
+ If the user asks for a **tool**, **widget**, **dashboard**, **calculator**, or **mini-app**, call \`create-tool\` immediately with a self-contained Alpine.js HTML body. This is NOT a code change — tools are sandboxed mini-apps stored in the database. Do not preface with "let me build…" — just call \`create-tool\`.
1319
+
1234
1320
  ### Code Changes — Call \`connect-builder\`
1235
1321
 
1236
- When the user asks to change the UI, modify code, add a feature, or fix a bug in the app itself — call \`connect-builder\` immediately, passing the user's request as the \`prompt\`. Do NOT write code, list files, make plans, or spawn sub-agents for code changes. Builder handles it in the cloud. Mention \`npx agent-native create <app-name>\` as an offline fallback.
1322
+ When the user asks to change the UI, modify code, add a feature, or fix a bug in the app itself — call \`connect-builder\` immediately, passing the user's request as the \`prompt\`. (Tool / widget / dashboard requests use \`create-tool\` instead — see above.) Do NOT write code, list files, make plans, or spawn sub-agents for code changes. Builder handles it in the cloud. Mention \`npx agent-native create <app-name>\` as an offline fallback.
1237
1323
  ${FRAMEWORK_CORE_COMPACT}`;
1238
1324
  const DEV_FRAMEWORK_PROMPT_COMPACT = `## Agent-Native Framework — Development Mode
1239
1325
 
@@ -1590,7 +1676,7 @@ export function createAgentChatPlugin(options) {
1590
1676
  if (mcpConfig?.source) {
1591
1677
  console.log(`[mcp-client] loaded config from ${mcpConfig.source} (${Object.keys(mcpConfig.servers).length} server(s))`);
1592
1678
  }
1593
- else {
1679
+ else if (process.env.DEBUG) {
1594
1680
  console.log("[mcp-client] no configured MCP servers — skipping MCP tools");
1595
1681
  }
1596
1682
  }
@@ -1668,9 +1754,8 @@ export function createAgentChatPlugin(options) {
1668
1754
  ...engineScripts,
1669
1755
  };
1670
1756
  const callAgentScript = await createCallAgentScriptEntry(options?.appId);
1671
- let _currentRequestOrigin = "http://localhost:3000";
1672
1757
  const browserTools = createBuilderBrowserTool({
1673
- getOrigin: () => _currentRequestOrigin,
1758
+ getOrigin: () => getRequestRunContext()?.requestOrigin ?? "http://localhost:3000",
1674
1759
  });
1675
1760
  // Auto-mount A2A protocol endpoints so every app is discoverable
1676
1761
  // and callable by other agents via the standard protocol.
@@ -1801,27 +1886,57 @@ export function createAgentChatPlugin(options) {
1801
1886
  }
1802
1887
  catch { }
1803
1888
  }
1804
- // Mutable owner set per-request by the production handler, read by
1805
- // automation tools and fetch tool via closure. Declared here (before
1806
- // allScripts) so the tools are in scope when allScripts is built.
1807
- let _currentRunOwner = "local@localhost";
1808
- // Automation tools + fetch tool depend on _currentRunOwner via callback
1889
+ // Per-request owner is read from the AsyncLocalStorage run context
1890
+ // (populated by prepareRun). Module-scope `let` would race across
1891
+ // concurrent requests on a long-lived Node process overlapping
1892
+ // tool calls would observe whichever request wrote last. ALS gives
1893
+ // each async call-chain its own view of the owner.
1894
+ //
1895
+ // Falls back to `getRequestUserEmail()` so callers that wrap work
1896
+ // in `runWithRequestContext({ userEmail }, …)` without going through
1897
+ // `prepareRun` (recurring jobs, trigger dispatcher) still see the
1898
+ // correct owner.
1899
+ //
1900
+ // SECURITY: returns `null` when neither the run context nor the
1901
+ // request user-email is populated. Consumers MUST short-circuit
1902
+ // with an explicit error rather than fall back to a sentinel
1903
+ // identity (e.g. DEV_MODE_USER_EMAIL). The previous fallback to
1904
+ // `local@localhost` slipped past `guard-no-localhost-fallback`
1905
+ // because the literal was hidden behind a symbolic alias —
1906
+ // any agent loop that reached this code without a populated
1907
+ // session would resolve `${keys.NAME}` against the dev-shim's
1908
+ // `app_secrets WHERE scope_id='local@localhost'` rows. See
1909
+ // audit 02 (HIGH: getCurrentRunOwner) and the
1910
+ // 2026-04-29 credentials-leak incident for the prior shape.
1911
+ const getCurrentRunOwner = () => getRequestRunContext()?.owner ?? getRequestUserEmail() ?? null;
1912
+ const requireCurrentRunOwner = (operation) => {
1913
+ const owner = getCurrentRunOwner();
1914
+ if (!owner) {
1915
+ throw new Error(`[agent-chat] No authenticated owner in run context — ` +
1916
+ `refusing to ${operation}. Ensure the request goes through ` +
1917
+ `prepareRun() or is wrapped in runWithRequestContext({ userEmail, ... }).`);
1918
+ }
1919
+ return owner;
1920
+ };
1921
+ // Automation tools + fetch tool — depend on owner via callback.
1922
+ // Each callback short-circuits with a clear error when the run context
1923
+ // has no authenticated owner (see SECURITY note on getCurrentRunOwner).
1809
1924
  let automationTools = {};
1810
1925
  try {
1811
1926
  const { createAutomationToolEntries } = await import("../triggers/actions.js");
1812
- automationTools = createAutomationToolEntries(() => _currentRunOwner);
1927
+ automationTools = createAutomationToolEntries(() => requireCurrentRunOwner("manage automations"));
1813
1928
  }
1814
1929
  catch { }
1815
1930
  let notificationTools = {};
1816
1931
  try {
1817
1932
  const { createNotificationToolEntries } = await import("../notifications/actions.js");
1818
- notificationTools = createNotificationToolEntries(() => _currentRunOwner);
1933
+ notificationTools = createNotificationToolEntries(() => requireCurrentRunOwner("manage notifications"));
1819
1934
  }
1820
1935
  catch { }
1821
1936
  let progressTools = {};
1822
1937
  try {
1823
1938
  const { createProgressToolEntries } = await import("../progress/actions.js");
1824
- progressTools = createProgressToolEntries(() => _currentRunOwner);
1939
+ progressTools = createProgressToolEntries(() => requireCurrentRunOwner("manage progress"));
1825
1940
  }
1826
1941
  catch { }
1827
1942
  let fetchTool = {};
@@ -1829,10 +1944,10 @@ export function createAgentChatPlugin(options) {
1829
1944
  const { createFetchToolEntry } = await import("../tools/fetch-tool.js");
1830
1945
  const { resolveKeyReferences, validateUrlAllowlist, getKeyAllowlist } = await import("../secrets/substitution.js");
1831
1946
  fetchTool = createFetchToolEntry({
1832
- resolveKeys: async (text) => resolveKeyReferences(text, "user", _currentRunOwner),
1947
+ resolveKeys: async (text) => resolveKeyReferences(text, "user", requireCurrentRunOwner("resolve key references")),
1833
1948
  validateUrl: async (url, usedKeys) => {
1834
1949
  for (const keyName of usedKeys) {
1835
- const allowlist = await getKeyAllowlist(keyName, "user", _currentRunOwner);
1950
+ const allowlist = await getKeyAllowlist(keyName, "user", requireCurrentRunOwner("validate URL allowlist"));
1836
1951
  if (allowlist && !validateUrlAllowlist(url, allowlist)) {
1837
1952
  return false;
1838
1953
  }
@@ -1842,6 +1957,12 @@ export function createAgentChatPlugin(options) {
1842
1957
  });
1843
1958
  }
1844
1959
  catch { }
1960
+ let toolActions = {};
1961
+ try {
1962
+ const { createToolActionEntries } = await import("../tools/actions.js");
1963
+ toolActions = createToolActionEntries();
1964
+ }
1965
+ catch { }
1845
1966
  // In dev mode, template actions (templateScripts and discoveredActions) are
1846
1967
  // NOT registered as native tools — the agent invokes them via shell instead.
1847
1968
  // This avoids degenerate empty-object tool calls that Anthropic models
@@ -1852,12 +1973,14 @@ export function createAgentChatPlugin(options) {
1852
1973
  ...resourceScripts,
1853
1974
  ...docsScripts,
1854
1975
  ...(lazyContext ? frameworkContextTool : {}),
1976
+ ...urlTools,
1855
1977
  ...chatScripts,
1856
1978
  ...callAgentScript,
1857
1979
  ...automationTools,
1858
1980
  ...notificationTools,
1859
1981
  ...progressTools,
1860
1982
  ...fetchTool,
1983
+ ...toolActions,
1861
1984
  ...browserTools,
1862
1985
  ...devScriptsForA2A,
1863
1986
  }
@@ -1876,6 +1999,7 @@ export function createAgentChatPlugin(options) {
1876
1999
  ...notificationTools,
1877
2000
  ...progressTools,
1878
2001
  ...fetchTool,
2002
+ ...toolActions,
1879
2003
  ...browserTools,
1880
2004
  ...devScriptsForA2A,
1881
2005
  };
@@ -1893,11 +2017,80 @@ export function createAgentChatPlugin(options) {
1893
2017
  streaming: true,
1894
2018
  handler: async function* (message, context) {
1895
2019
  // Resolve the caller's identity for user-scoped data access.
2020
+ // Priority: A2A-JWT verified email (set by the A2A handler in
2021
+ // request-context) > dev session DB (dev only) > Google OAuth
2022
+ // tokeninfo (prod only). Without the JWT-verified-email path,
2023
+ // cross-app A2A calls landed owned by `local@localhost` (dev) or
2024
+ // `dispatch@shared`, which made resources invisible to the actual
2025
+ // signed-in user.
2026
+ //
2027
+ // SECURITY: we deliberately do NOT trust `context.metadata.userEmail`
2028
+ // as a fallback. The A2A endpoint runs in three modes — JWT-signed
2029
+ // (verified email lands in request context), API-key (caller is
2030
+ // app-authenticated but NOT user-authenticated), and unsigned
2031
+ // (no auth at all). Trusting caller-supplied metadata on the latter
2032
+ // two paths would let any reachable caller forge `metadata.userEmail`
2033
+ // and impersonate an arbitrary user. The JWT path already populates
2034
+ // the request context, so the metadata fallback was only ever used
2035
+ // on the unauthenticated paths — exactly where it's unsafe.
1896
2036
  const isDev = process.env.NODE_ENV !== "production";
1897
2037
  let userEmail;
1898
- if (isDev) {
1899
- userEmail = context.metadata?.userEmail || undefined;
1900
- if (!userEmail) {
2038
+ // 1. JWT-verified email from A2A receiver (auth boundary already
2039
+ // enforced upstream). Works in dev AND prod.
2040
+ try {
2041
+ const { getRequestUserEmail } = await import("./request-context.js");
2042
+ userEmail = getRequestUserEmail();
2043
+ }
2044
+ catch { }
2045
+ // Dev-mode-only: when no JWT-verified email is present, fall back
2046
+ // to the most recently logged-in session. This is convenient for a
2047
+ // single-developer dev box but is a silent-impersonation hole if
2048
+ // it ever fires in production or on an exposed dev environment
2049
+ // (preview deploys, ngrok tunnels, etc.).
2050
+ //
2051
+ // SECURITY: gate this fallback narrowly:
2052
+ // - NODE_ENV strictly === "development" (not "test", not unset).
2053
+ // - AUTH_MODE === "local" (the dev-only auth shim).
2054
+ // - Request host is localhost / 127.0.0.1 (best-effort: when the
2055
+ // A2A handler doesn't have direct H3 event access, we rely on
2056
+ // env-based shape checks).
2057
+ //
2058
+ // In production this MUST never fire — the runtime assertion
2059
+ // below crashes loud if NODE_ENV === "production" somehow reaches
2060
+ // this block.
2061
+ if (!userEmail && isDev) {
2062
+ if (process.env.NODE_ENV === "production") {
2063
+ throw new Error("[agent-chat] Dev-mode 'latest session' fallback reached in production — refusing.");
2064
+ }
2065
+ const strictlyDev = process.env.NODE_ENV === "development";
2066
+ const localAuthMode = process.env.AUTH_MODE === "local";
2067
+ // Request host check: rely on the request-context request origin
2068
+ // which prepareRun() / mountActionRoutes populate. The A2A
2069
+ // handler doesn't have direct H3 event access, but on a
2070
+ // misconfigured non-localhost dev box we still want to refuse.
2071
+ let isLocalHost = false;
2072
+ try {
2073
+ const origin = getRequestRunContext()?.requestOrigin;
2074
+ if (origin) {
2075
+ const url = new URL(origin);
2076
+ isLocalHost =
2077
+ url.hostname === "localhost" ||
2078
+ url.hostname === "127.0.0.1" ||
2079
+ url.hostname === "::1";
2080
+ }
2081
+ else {
2082
+ // No origin in context — the A2A handler runs without an
2083
+ // explicit request origin. Treat absence as permissive only
2084
+ // when we're confident the process is dev-only (NODE_ENV
2085
+ // strictly "development" + AUTH_MODE=local). Otherwise
2086
+ // refuse.
2087
+ isLocalHost = strictlyDev && localAuthMode;
2088
+ }
2089
+ }
2090
+ catch {
2091
+ isLocalHost = false;
2092
+ }
2093
+ if (strictlyDev && localAuthMode && isLocalHost) {
1901
2094
  try {
1902
2095
  const { getDbExec } = await import("../db/client.js");
1903
2096
  const db = getDbExec();
@@ -1911,7 +2104,7 @@ export function createAgentChatPlugin(options) {
1911
2104
  catch { }
1912
2105
  }
1913
2106
  }
1914
- else {
2107
+ if (!userEmail && !isDev) {
1915
2108
  const googleToken = context.metadata?.googleToken;
1916
2109
  if (googleToken) {
1917
2110
  try {
@@ -1926,9 +2119,6 @@ export function createAgentChatPlugin(options) {
1926
2119
  catch { }
1927
2120
  }
1928
2121
  }
1929
- if (userEmail) {
1930
- process.env.AGENT_USER_EMAIL = userEmail;
1931
- }
1932
2122
  const text = message.parts
1933
2123
  .filter((p) => p.type === "text")
1934
2124
  .map((p) => p.text)
@@ -1952,7 +2142,9 @@ export function createAgentChatPlugin(options) {
1952
2142
  const devActive = isDevMode();
1953
2143
  const handler = devActive && devHandler ? devHandler : prodHandler;
1954
2144
  // Build the same system prompt the interactive agent uses
1955
- const owner = userEmail || "local@localhost";
2145
+ if (!userEmail)
2146
+ throw new Error("no authenticated user");
2147
+ const owner = userEmail;
1956
2148
  const resources = await loadResourcesForPrompt(owner, lazyContext);
1957
2149
  const schemaBlock = lazyContext
1958
2150
  ? ""
@@ -1960,8 +2152,7 @@ export function createAgentChatPlugin(options) {
1960
2152
  const systemPrompt = devActive
1961
2153
  ? devPrompt + resources + schemaBlock
1962
2154
  : basePrompt + resources + schemaBlock;
1963
- const model = options?.model ??
1964
- (canToggle ? "claude-sonnet-4-6" : "claude-haiku-4-5-20251001");
2155
+ const model = options?.model ?? DEFAULT_MODEL;
1965
2156
  // Build tools — same as interactive handler but WITHOUT call-agent
1966
2157
  // to prevent infinite recursive A2A loops (agent calling itself).
1967
2158
  // In dev mode, template actions are invoked via shell (not native tools),
@@ -1971,7 +2162,9 @@ export function createAgentChatPlugin(options) {
1971
2162
  ...resourceScripts,
1972
2163
  ...docsScripts,
1973
2164
  ...(lazyContext ? frameworkContextTool : {}),
2165
+ ...urlTools,
1974
2166
  ...chatScripts,
2167
+ ...toolActions,
1975
2168
  ...browserTools,
1976
2169
  ...devScriptsForA2A,
1977
2170
  }
@@ -1984,6 +2177,7 @@ export function createAgentChatPlugin(options) {
1984
2177
  ...(lazyContext ? frameworkContextTool : {}),
1985
2178
  ...urlTools,
1986
2179
  ...chatScripts,
2180
+ ...toolActions,
1987
2181
  ...browserTools,
1988
2182
  };
1989
2183
  const a2aTools = actionsToEngineTools(a2aActions);
@@ -2078,8 +2272,7 @@ export function createAgentChatPlugin(options) {
2078
2272
  engineOption: options?.engine,
2079
2273
  apiKey: options?.apiKey,
2080
2274
  });
2081
- const model = options?.model ??
2082
- (canToggle ? "claude-sonnet-4-6" : "claude-haiku-4-5-20251001");
2275
+ const model = options?.model ?? DEFAULT_MODEL;
2083
2276
  // Same actions as A2A — without call-agent to prevent loops.
2084
2277
  // In dev mode, template actions go through shell, not native tools.
2085
2278
  const devActiveMcp = isDevMode();
@@ -2088,7 +2281,9 @@ export function createAgentChatPlugin(options) {
2088
2281
  ...resourceScripts,
2089
2282
  ...docsScripts,
2090
2283
  ...(lazyContext ? frameworkContextTool : {}),
2284
+ ...urlTools,
2091
2285
  ...chatScripts,
2286
+ ...toolActions,
2092
2287
  ...devScriptsForA2A,
2093
2288
  }
2094
2289
  : {
@@ -2100,12 +2295,13 @@ export function createAgentChatPlugin(options) {
2100
2295
  ...(lazyContext ? frameworkContextTool : {}),
2101
2296
  ...urlTools,
2102
2297
  ...chatScripts,
2298
+ ...toolActions,
2103
2299
  };
2104
2300
  const mcpTools = actionsToEngineTools(mcpActions);
2105
- const resources = await loadResourcesForPrompt("local@localhost", lazyContext);
2301
+ const resources = await loadResourcesForPrompt(DEV_MODE_USER_EMAIL, lazyContext);
2106
2302
  const schemaBlock = lazyContext
2107
2303
  ? ""
2108
- : await buildSchemaBlock("local@localhost", devActiveMcp);
2304
+ : await buildSchemaBlock(DEV_MODE_USER_EMAIL, devActiveMcp);
2109
2305
  // Build the MCP handler's own prompt — always use the shell-based
2110
2306
  // dev prompt in dev mode because mcpActions routes template actions
2111
2307
  // through shell (`devScriptsForA2A`), regardless of `nativeActionsInDev`.
@@ -2143,13 +2339,15 @@ export function createAgentChatPlugin(options) {
2143
2339
  });
2144
2340
  // Resolve owner from the H3 event's session — matches how resources are created
2145
2341
  const getOwnerFromEvent = async (event) => {
2146
- try {
2147
- const session = await getSession(event);
2148
- return session?.email || "local@localhost";
2149
- }
2150
- catch {
2151
- return "local@localhost";
2342
+ const session = await getSession(event);
2343
+ if (!session?.email) {
2344
+ const { createError } = await import("h3");
2345
+ throw createError({
2346
+ statusCode: 401,
2347
+ statusMessage: "Unauthenticated",
2348
+ });
2152
2349
  }
2350
+ return session.email;
2153
2351
  };
2154
2352
  // Auto-mount template actions as HTTP endpoints under /_agent-native/actions/
2155
2353
  // Include engine management script so the UI can call manage-agent-engine.
@@ -2241,6 +2439,15 @@ export function createAgentChatPlugin(options) {
2241
2439
  else {
2242
2440
  repo.messages.push(assistantMsg);
2243
2441
  }
2442
+ // Store debug metadata so we can inspect what the LLM actually
2443
+ // received (system prompt, model, engine) when diagnosing issues.
2444
+ const runCtx = getRequestRunContext();
2445
+ repo._debug = {
2446
+ systemPrompt: runCtx?.systemPrompt,
2447
+ model: runCtx?.model ?? resolvedModel,
2448
+ engine: runCtx?.engine?.name ?? "unknown",
2449
+ timestamp: Date.now(),
2450
+ };
2244
2451
  const meta = extractThreadMeta(repo);
2245
2452
  await updateThreadData(threadId, JSON.stringify(repo), meta.title || thread.title, meta.preview || thread.preview, repo.messages.length);
2246
2453
  }
@@ -2248,13 +2455,32 @@ export function createAgentChatPlugin(options) {
2248
2455
  // Best-effort — don't break cleanup
2249
2456
  }
2250
2457
  });
2251
- // Emit agent.turn.completed for automation triggers
2458
+ // Emit agent.turn.completed for automation triggers.
2459
+ //
2460
+ // SECURITY: include `owner` so the trigger dispatcher's tenant-scope
2461
+ // check engages (see triggers/dispatcher.ts:212-218). Without an
2462
+ // owner, every user's matching `agent.turn.completed` trigger
2463
+ // would fire when ANY user's chat turn completes — cross-tenant
2464
+ // fan-out (audit 12 #9). Owner comes from the thread row when
2465
+ // available (most reliable; persisted at thread create time),
2466
+ // falling back to the current run context's owner. If neither
2467
+ // resolves we skip emission entirely rather than emit unowned.
2252
2468
  try {
2253
- const { emit } = await import("../event-bus/index.js");
2254
- emit("agent.turn.completed", {
2255
- threadId,
2256
- model: resolvedModel,
2257
- });
2469
+ let ownerEmail;
2470
+ try {
2471
+ const ownerThread = await getThread(threadId);
2472
+ ownerEmail = ownerThread?.ownerEmail;
2473
+ }
2474
+ catch {
2475
+ // ignore — fall through to run-context owner
2476
+ }
2477
+ if (!ownerEmail) {
2478
+ ownerEmail = getRequestRunContext()?.owner;
2479
+ }
2480
+ if (ownerEmail) {
2481
+ const { emit } = await import("../event-bus/index.js");
2482
+ emit("agent.turn.completed", { threadId, model: resolvedModel }, { owner: ownerEmail });
2483
+ }
2258
2484
  }
2259
2485
  catch {
2260
2486
  // Event bus not available — skip
@@ -2315,20 +2541,10 @@ export function createAgentChatPlugin(options) {
2315
2541
  // Each run gets its own send function, keyed by threadId so concurrent
2316
2542
  // requests for different threads don't clobber each other.
2317
2543
  const _runSendByThread = new Map();
2318
- let _currentRunUserApiKey;
2319
- let _currentRunThreadId = "";
2320
- let _currentRunSystemPrompt = basePrompt;
2321
- // Populated by onEngineResolved per request so sub-agents inherit
2322
- // whichever provider + model the user configured (OpenRouter, Groq, …)
2323
- // instead of silently falling back to Anthropic + Claude.
2324
- let _currentRunEngine;
2325
- let _currentRunModel;
2326
- // Default to Haiku in production mode to manage costs for hosted apps
2327
- const resolvedModel = options?.model ??
2328
- (canToggle ? "claude-sonnet-4-6" : "claude-haiku-4-5-20251001");
2544
+ const resolvedModel = options?.model ?? DEFAULT_MODEL;
2329
2545
  const teamTools = createTeamTools({
2330
- getOwner: () => _currentRunOwner,
2331
- getSystemPrompt: () => _currentRunSystemPrompt,
2546
+ getOwner: () => requireCurrentRunOwner("spawn or manage sub-agents"),
2547
+ getSystemPrompt: () => getRequestRunContext()?.systemPrompt ?? basePrompt,
2332
2548
  getActions: () => isDevMode()
2333
2549
  ? {
2334
2550
  // Sub-agents spawned in dev mode also invoke template actions
@@ -2349,20 +2565,24 @@ export function createAgentChatPlugin(options) {
2349
2565
  ...urlTools,
2350
2566
  ...chatScripts,
2351
2567
  },
2352
- getEngine: () => _currentRunEngine ??
2353
- createAnthropicEngine({
2354
- // Sub-agents must inherit the parent run's resolved key so a
2355
- // BYO-key user can't bypass the free-tier check on the parent
2356
- // run and then have agent-teams spawn delegations bill the platform key.
2357
- apiKey: _currentRunUserApiKey ??
2358
- options?.apiKey ??
2359
- process.env.ANTHROPIC_API_KEY,
2360
- }),
2361
- getModel: () => _currentRunModel ?? resolvedModel,
2362
- getParentThreadId: () => _currentRunThreadId,
2568
+ getEngine: () => {
2569
+ const runCtx = getRequestRunContext();
2570
+ return (runCtx?.engine ??
2571
+ createAnthropicEngine({
2572
+ // Sub-agents must inherit the parent run's resolved key so a
2573
+ // BYO-key user can't bypass the free-tier check on the parent
2574
+ // run and then have agent-teams spawn delegations bill the platform key.
2575
+ apiKey: runCtx?.userApiKey ??
2576
+ options?.apiKey ??
2577
+ process.env.ANTHROPIC_API_KEY,
2578
+ }));
2579
+ },
2580
+ getModel: () => getRequestRunContext()?.model ?? resolvedModel,
2581
+ getParentThreadId: () => getRequestRunContext()?.threadId ?? "",
2363
2582
  getSend: () => {
2364
2583
  // Return the send for the current run's thread
2365
- const send = _runSendByThread.get(_currentRunThreadId);
2584
+ const threadId = getRequestRunContext()?.threadId ?? "";
2585
+ const send = _runSendByThread.get(threadId);
2366
2586
  return send ?? null;
2367
2587
  },
2368
2588
  });
@@ -2374,6 +2594,19 @@ export function createAgentChatPlugin(options) {
2374
2594
  jobTools = createJobTools();
2375
2595
  }
2376
2596
  catch { }
2597
+ // Lean mode: only template actions + essential framework tools. Drop
2598
+ // web-request, browser tools, teams, jobs, automations, notifications,
2599
+ // progress, call-agent, and MCP entries to keep the tool list tight and
2600
+ // prevent the LLM from reaching for web-request instead of the
2601
+ // template's native actions (e.g. log-meal).
2602
+ const leanActions = {
2603
+ ...templateScripts,
2604
+ ...resourceScripts,
2605
+ ...refreshScreenTool,
2606
+ ...urlTools,
2607
+ ...chatScripts,
2608
+ ...toolActions,
2609
+ };
2377
2610
  const prodActions = {
2378
2611
  ...templateScripts,
2379
2612
  ...resourceScripts,
@@ -2390,6 +2623,7 @@ export function createAgentChatPlugin(options) {
2390
2623
  ...notificationTools,
2391
2624
  ...progressTools,
2392
2625
  ...fetchTool,
2626
+ ...toolActions,
2393
2627
  ...browserTools,
2394
2628
  ...mcpActionEntries,
2395
2629
  };
@@ -2420,27 +2654,37 @@ export function createAgentChatPlugin(options) {
2420
2654
  // and tokens that minimal/voice apps don't need.
2421
2655
  const leanBasePrompt = (options?.systemPrompt ?? "") + prodActionsPrompt;
2422
2656
  // Per-request preamble shared by both prod and dev handlers. Resolves
2423
- // owner + user API key (stashed on the closure so downstream tools can
2424
- // reach them) and the template-authored `extraContext`. `extraContext`
2425
- // runs in every prompt variant (lean, lazy, full) — if a template
2426
- // defined it, they opted in; framework-provided content is what the
2427
- // token-saving modes strip.
2657
+ // owner + user API key onto the AsyncLocalStorage run context so
2658
+ // downstream tool closures (automation, fetch, team) read the
2659
+ // current request's identity without racing against concurrent
2660
+ // requests. `extraContext` runs in every prompt variant (lean, lazy,
2661
+ // full) if a template defined it, they opted in; framework-provided
2662
+ // content is what the token-saving modes strip.
2428
2663
  const prepareRun = async (event) => {
2429
- _currentRequestOrigin = getOrigin(event);
2430
2664
  const owner = await getOwnerFromEvent(event);
2431
- _currentRunOwner = owner;
2432
2665
  const { getOwnerActiveApiKey } = await import("../agent/production-agent.js");
2433
- _currentRunUserApiKey = await getOwnerActiveApiKey(owner);
2666
+ const userApiKey = await getOwnerActiveApiKey(owner);
2667
+ const runCtx = ensureRequestRunContext();
2668
+ if (runCtx) {
2669
+ runCtx.requestOrigin = getOrigin(event);
2670
+ runCtx.owner = owner;
2671
+ runCtx.userApiKey = userApiKey;
2672
+ }
2434
2673
  const extra = await resolveExtraContext(event, owner);
2435
2674
  return { owner, extra };
2436
2675
  };
2676
+ const setSystemPromptOnContext = (prompt) => {
2677
+ const runCtx = ensureRequestRunContext();
2678
+ if (runCtx)
2679
+ runCtx.systemPrompt = prompt;
2680
+ return prompt;
2681
+ };
2437
2682
  const prodHandler = createProductionAgentHandler({
2438
- actions: prodActions,
2683
+ actions: leanPrompt ? leanActions : prodActions,
2439
2684
  systemPrompt: async (event) => {
2440
2685
  const { owner, extra } = await prepareRun(event);
2441
2686
  if (leanPrompt) {
2442
- _currentRunSystemPrompt = leanBasePrompt + extra;
2443
- return _currentRunSystemPrompt;
2687
+ return setSystemPromptOnContext(leanBasePrompt + extra);
2444
2688
  }
2445
2689
  const resources = await loadResourcesForPrompt(owner, lazyContext);
2446
2690
  // In lazy context mode, skip embedding the full schema — the agent
@@ -2448,21 +2692,23 @@ export function createAgentChatPlugin(options) {
2448
2692
  const schemaBlock = lazyContext
2449
2693
  ? ""
2450
2694
  : await buildSchemaBlock(owner, false);
2451
- _currentRunSystemPrompt =
2452
- basePrompt + resources + schemaBlock + extra;
2453
- return _currentRunSystemPrompt;
2695
+ return setSystemPromptOnContext(basePrompt + resources + schemaBlock + extra);
2454
2696
  },
2455
- model: options?.model ??
2456
- (isHostedProd ? "claude-haiku-4-5-20251001" : undefined),
2697
+ model: options?.model ?? DEFAULT_MODEL,
2457
2698
  apiKey: options?.apiKey,
2458
2699
  skipFilesContext: leanPrompt,
2459
2700
  onEngineResolved: (engine, model) => {
2460
- _currentRunEngine = engine;
2461
- _currentRunModel = model;
2701
+ const runCtx = ensureRequestRunContext();
2702
+ if (runCtx) {
2703
+ runCtx.engine = engine;
2704
+ runCtx.model = model;
2705
+ }
2462
2706
  },
2463
2707
  onRunStart: (send, threadId) => {
2464
2708
  _runSendByThread.set(threadId, send);
2465
- _currentRunThreadId = threadId;
2709
+ const runCtx = ensureRequestRunContext();
2710
+ if (runCtx)
2711
+ runCtx.threadId = threadId;
2466
2712
  },
2467
2713
  onRunComplete: async (run, threadId) => {
2468
2714
  if (threadId)
@@ -2487,28 +2733,31 @@ export function createAgentChatPlugin(options) {
2487
2733
  // template's actions as native tools instead of routing through shell.
2488
2734
  // Templates with structured-arg actions (objects/arrays) need this to
2489
2735
  // avoid round-tripping JSON through the CLI parser.
2490
- const devActions = devNative
2491
- ? prodActions
2492
- : {
2493
- ...resourceScripts,
2494
- ...docsScripts,
2495
- ...(lazyContext ? frameworkContextTool : {}),
2496
- ...chatScripts,
2497
- ...callAgentScript,
2498
- ...teamTools,
2499
- ...jobTools,
2500
- ...automationTools,
2501
- ...notificationTools,
2502
- ...progressTools,
2503
- ...fetchTool,
2504
- ...browserTools,
2505
- ...mcpActionEntries,
2506
- ...(await createDevScriptRegistry()),
2507
- };
2736
+ const devActions = leanPrompt
2737
+ ? leanActions
2738
+ : devNative
2739
+ ? prodActions
2740
+ : {
2741
+ ...resourceScripts,
2742
+ ...docsScripts,
2743
+ ...(lazyContext ? frameworkContextTool : {}),
2744
+ ...chatScripts,
2745
+ ...callAgentScript,
2746
+ ...teamTools,
2747
+ ...jobTools,
2748
+ ...automationTools,
2749
+ ...notificationTools,
2750
+ ...progressTools,
2751
+ ...fetchTool,
2752
+ ...toolActions,
2753
+ ...browserTools,
2754
+ ...mcpActionEntries,
2755
+ ...(await createDevScriptRegistry()),
2756
+ };
2508
2757
  // Keep dev action dict in sync with runtime MCP additions. When
2509
2758
  // native-actions mode is on (lean or `nativeActionsInDev`), devActions
2510
2759
  // === prodActions so the prod listener already covers it.
2511
- if (devActions !== prodActions) {
2760
+ if (devActions !== prodActions && devActions !== leanActions) {
2512
2761
  mcpManager.onChange(() => {
2513
2762
  syncMcpActionEntries(mcpManager, devActions);
2514
2763
  });
@@ -2518,27 +2767,29 @@ export function createAgentChatPlugin(options) {
2518
2767
  systemPrompt: async (event) => {
2519
2768
  const { owner, extra } = await prepareRun(event);
2520
2769
  if (leanPrompt) {
2521
- _currentRunSystemPrompt = leanBasePrompt + extra;
2522
- return _currentRunSystemPrompt;
2770
+ return setSystemPromptOnContext(leanBasePrompt + extra);
2523
2771
  }
2524
2772
  const resources = await loadResourcesForPrompt(owner, lazyContext);
2525
2773
  const schemaBlock = lazyContext
2526
2774
  ? ""
2527
2775
  : await buildSchemaBlock(owner, true);
2528
- _currentRunSystemPrompt =
2529
- devPrompt + resources + schemaBlock + extra;
2530
- return _currentRunSystemPrompt;
2776
+ return setSystemPromptOnContext(devPrompt + resources + schemaBlock + extra);
2531
2777
  },
2532
2778
  model: options?.model,
2533
2779
  apiKey: options?.apiKey,
2534
2780
  skipFilesContext: leanPrompt,
2535
2781
  onEngineResolved: (engine, model) => {
2536
- _currentRunEngine = engine;
2537
- _currentRunModel = model;
2782
+ const runCtx = ensureRequestRunContext();
2783
+ if (runCtx) {
2784
+ runCtx.engine = engine;
2785
+ runCtx.model = model;
2786
+ }
2538
2787
  },
2539
2788
  onRunStart: (send, threadId) => {
2540
2789
  _runSendByThread.set(threadId, send);
2541
- _currentRunThreadId = threadId;
2790
+ const runCtx = ensureRequestRunContext();
2791
+ if (runCtx)
2792
+ runCtx.threadId = threadId;
2542
2793
  },
2543
2794
  onRunComplete: async (run, threadId) => {
2544
2795
  if (threadId)
@@ -2586,10 +2837,11 @@ export function createAgentChatPlugin(options) {
2586
2837
  return { devMode: currentDevMode, canToggle };
2587
2838
  }));
2588
2839
  // Mount save-key BEFORE the prefix handler so it isn't shadowed.
2589
- // Persists the user's key per-owner in the SQL settings table so it
2590
- // survives across serverless invocations (where mutating process.env
2591
- // and writing .env are both no-ops). Also updates process.env and
2592
- // .env when running locally for fast pickup by other handlers.
2840
+ // Persists the user's API key in `app_secrets` (encrypted, scope=user,
2841
+ // scopeId=email). Hard rule: never mutates process.env, never writes
2842
+ // .env. User-pasted secrets must not become deploy-level identity —
2843
+ // that's the cross-tenant leak class (KVesta Space, 2026-04).
2844
+ // Consumers read these values per-request via `resolveSecret(key)`.
2593
2845
  getH3App(nitroApp).use(`${routePath}/save-key`, defineEventHandler(async (event) => {
2594
2846
  if (getMethod(event) !== "POST") {
2595
2847
  setResponseStatus(event, 405);
@@ -2603,75 +2855,35 @@ export function createAgentChatPlugin(options) {
2603
2855
  return { error: "API key is required" };
2604
2856
  }
2605
2857
  const trimmedKey = key.trim();
2606
- // Persist per-owner so the key survives cold starts in serverless
2607
- // and so the user's key isn't shared across users on multi-tenant
2608
- // hosted deployments. We require a real authenticated owner here —
2609
- // `local@localhost` is the unauthenticated fallback and must never
2610
- // become the shared key bucket on hosted deployments.
2611
2858
  const ownerEmail = await getOwnerFromEvent(event);
2612
- if (isHostedProd &&
2613
- (!ownerEmail || ownerEmail === "local@localhost")) {
2859
+ if (!ownerEmail || ownerEmail === DEV_MODE_USER_EMAIL) {
2614
2860
  setResponseStatus(event, 401);
2615
2861
  return { error: "Authentication required" };
2616
2862
  }
2617
- if (ownerEmail && ownerEmail !== "local@localhost") {
2618
- try {
2619
- await putSetting(`user-api-key:${provider}:${ownerEmail}`, {
2620
- key: trimmedKey,
2621
- });
2622
- // Verify the write actually landed — some managed DB drivers
2623
- // swallow errors on degraded connections. Without this the
2624
- // client sees "saved", reloads, and the usage-limit card
2625
- // re-appears on the next message because the key isn't
2626
- // really persisted.
2627
- const check = await getSetting(`user-api-key:${provider}:${ownerEmail}`);
2628
- if (!check ||
2629
- typeof check.key !== "string" ||
2630
- check.key !== trimmedKey) {
2631
- throw new Error("settings write did not persist");
2632
- }
2633
- }
2634
- catch (err) {
2635
- if (isHostedProd) {
2636
- console.error("[agent-chat] save-key persistence failed:", err instanceof Error ? err.message : err);
2637
- setResponseStatus(event, 500);
2638
- return {
2639
- error: "Failed to persist API key. Please try again or contact support.",
2640
- };
2641
- }
2642
- // Local dev falls through to the env-file path below.
2643
- }
2644
- }
2645
- // In hosted/multi-tenant mode we deliberately do NOT touch
2646
- // process.env or .env: the per-owner SQL lookup above is the
2647
- // single source of truth, and overwriting the shared env key
2648
- // would leak one tenant's credentials into every subsequent
2649
- // request that hit the same warm instance without its own key.
2650
- if (!isHostedProd) {
2651
- const providerToEnv = {
2652
- anthropic: "ANTHROPIC_API_KEY",
2653
- openai: "OPENAI_API_KEY",
2654
- google: "GOOGLE_GENERATIVE_AI_API_KEY",
2655
- groq: "GROQ_API_KEY",
2656
- mistral: "MISTRAL_API_KEY",
2657
- cohere: "COHERE_API_KEY",
2863
+ const providerToEnv = {
2864
+ anthropic: "ANTHROPIC_API_KEY",
2865
+ openai: "OPENAI_API_KEY",
2866
+ google: "GOOGLE_GENERATIVE_AI_API_KEY",
2867
+ groq: "GROQ_API_KEY",
2868
+ mistral: "MISTRAL_API_KEY",
2869
+ cohere: "COHERE_API_KEY",
2870
+ };
2871
+ const secretKey = providerToEnv[provider] ?? `${provider.toUpperCase()}_API_KEY`;
2872
+ try {
2873
+ const { writeAppSecret } = await import("../secrets/storage.js");
2874
+ await writeAppSecret({
2875
+ key: secretKey,
2876
+ value: trimmedKey,
2877
+ scope: "user",
2878
+ scopeId: ownerEmail,
2879
+ });
2880
+ }
2881
+ catch (err) {
2882
+ console.error("[agent-chat] save-key persistence failed:", err instanceof Error ? err.message : err);
2883
+ setResponseStatus(event, 500);
2884
+ return {
2885
+ error: "Failed to persist API key. Please try again or contact support.",
2658
2886
  };
2659
- const envVar = providerToEnv[provider] ?? `${provider.toUpperCase()}_API_KEY`;
2660
- try {
2661
- const path = await import("path");
2662
- const { upsertEnvFile } = await import("./create-server.js");
2663
- const envPath = path.join(process.cwd(), ".env");
2664
- await upsertEnvFile(envPath, [
2665
- { key: envVar, value: trimmedKey },
2666
- ]);
2667
- }
2668
- catch {
2669
- // Edge runtime — can't write .env, but can still update process.env
2670
- }
2671
- // Update process.env so the agent works immediately in the
2672
- // current local-dev invocation; the SQL persist above covers
2673
- // future invocations.
2674
- process.env[envVar] = trimmedKey;
2675
2887
  }
2676
2888
  return { ok: true };
2677
2889
  }));
@@ -2709,7 +2921,7 @@ export function createAgentChatPlugin(options) {
2709
2921
  // Query resources
2710
2922
  try {
2711
2923
  const resources = currentDevMode
2712
- ? await resourceListAccessible("local@localhost")
2924
+ ? await resourceListAccessible(DEV_MODE_USER_EMAIL)
2713
2925
  : await resourceList(SHARED_OWNER);
2714
2926
  for (const r of resources) {
2715
2927
  if (!seen.has(r.path)) {
@@ -2794,7 +3006,7 @@ export function createAgentChatPlugin(options) {
2794
3006
  // Query resources with skills/ prefix
2795
3007
  try {
2796
3008
  const resourceSkills = currentDevMode
2797
- ? await resourceListAccessible("local@localhost", "skills/")
3009
+ ? await resourceListAccessible(DEV_MODE_USER_EMAIL, "skills/")
2798
3010
  : await resourceList(SHARED_OWNER, "skills/");
2799
3011
  for (const r of resourceSkills) {
2800
3012
  // Try to get content to parse frontmatter
@@ -2839,6 +3051,22 @@ export function createAgentChatPlugin(options) {
2839
3051
  setResponseStatus(event, 405);
2840
3052
  return { error: "Method not allowed" };
2841
3053
  }
3054
+ // Resolve the caller and run the entire stream inside a request
3055
+ // context so custom mention providers can use `accessFilter` /
3056
+ // `resolveAccess` when querying ownable tables. Without this,
3057
+ // a provider that searches `decks` (or any sharable resource)
3058
+ // would see every row regardless of ownership.
3059
+ const mentionsOwner = await getOwnerFromEvent(event).catch(() => undefined);
3060
+ let mentionsOrgId;
3061
+ if (options?.resolveOrgId) {
3062
+ try {
3063
+ const resolved = await options.resolveOrgId(event);
3064
+ mentionsOrgId = resolved ?? undefined;
3065
+ }
3066
+ catch {
3067
+ mentionsOrgId = undefined;
3068
+ }
3069
+ }
2842
3070
  const query = getQuery(event);
2843
3071
  const q = typeof query.q === "string" ? query.q.toLowerCase() : "";
2844
3072
  const matchesQuery = (item) => !q ||
@@ -2849,148 +3077,154 @@ export function createAgentChatPlugin(options) {
2849
3077
  setResponseHeader(event, "Content-Type", "application/x-ndjson");
2850
3078
  setResponseHeader(event, "Cache-Control", "no-cache");
2851
3079
  const stream = new ReadableStream({
2852
- async start(controller) {
2853
- const MAX_RESULTS = 50;
2854
- let totalSent = 0;
2855
- let cancelled = false;
2856
- const flush = (batch) => {
2857
- if (cancelled)
2858
- return;
2859
- const filtered = batch.filter(matchesQuery);
2860
- if (filtered.length === 0)
2861
- return;
2862
- const remaining = MAX_RESULTS - totalSent;
2863
- const toSend = filtered.slice(0, remaining);
2864
- if (toSend.length > 0) {
2865
- totalSent += toSend.length;
2866
- try {
2867
- controller.enqueue(enc.encode(JSON.stringify({ items: toSend }) + "\n"));
2868
- }
2869
- catch {
2870
- // Stream was closed by client
2871
- cancelled = true;
2872
- }
2873
- }
2874
- };
2875
- // All sources run in parallel; each flushes independently.
2876
- const sources = [];
2877
- // 1. Resources from SQL (fast — flush first)
2878
- sources.push((async () => {
3080
+ start(controller) {
3081
+ return runWithRequestContext({
3082
+ userEmail: mentionsOwner,
3083
+ orgId: mentionsOrgId,
3084
+ }, () => mentionsStreamWork(controller));
3085
+ },
3086
+ cancel() {
3087
+ // Client disconnected — stop enqueuing
3088
+ },
3089
+ });
3090
+ return stream;
3091
+ async function mentionsStreamWork(controller) {
3092
+ const MAX_RESULTS = 50;
3093
+ let totalSent = 0;
3094
+ let cancelled = false;
3095
+ const flush = (batch) => {
3096
+ if (cancelled)
3097
+ return;
3098
+ const filtered = batch.filter(matchesQuery);
3099
+ if (filtered.length === 0)
3100
+ return;
3101
+ const remaining = MAX_RESULTS - totalSent;
3102
+ const toSend = filtered.slice(0, remaining);
3103
+ if (toSend.length > 0) {
3104
+ totalSent += toSend.length;
2879
3105
  try {
2880
- const resources = currentDevMode
2881
- ? await resourceListAccessible("local@localhost")
2882
- : await resourceList(SHARED_OWNER);
2883
- flush(resources.map((r) => {
2884
- const isShared = r.owner === SHARED_OWNER;
2885
- return {
2886
- id: `resource:${r.path}`,
2887
- label: r.path.split("/").pop() || r.path,
2888
- description: r.path,
2889
- icon: "file",
2890
- source: isShared
2891
- ? "resource:shared"
2892
- : "resource:private",
2893
- refType: "file",
2894
- refPath: r.path,
2895
- section: "Files",
2896
- };
2897
- }));
3106
+ controller.enqueue(enc.encode(JSON.stringify({ items: toSend }) + "\n"));
2898
3107
  }
2899
- catch { }
2900
- })());
2901
- // 2. Codebase files (dev mode only — can be slow on large repos)
2902
- if (currentDevMode) {
2903
- sources.push((async () => {
2904
- const codebaseFiles = [];
2905
- try {
2906
- await collectFiles(process.cwd(), "", 0, codebaseFiles);
2907
- }
2908
- catch { }
2909
- flush(codebaseFiles.map((f) => ({
2910
- id: `codebase:${f.path}`,
2911
- label: f.name,
2912
- description: f.path !== f.name ? f.path : undefined,
2913
- icon: f.type,
2914
- source: "codebase",
3108
+ catch {
3109
+ // Stream was closed by client
3110
+ cancelled = true;
3111
+ }
3112
+ }
3113
+ };
3114
+ // All sources run in parallel; each flushes independently.
3115
+ const sources = [];
3116
+ // 1. Resources from SQL (fast — flush first)
3117
+ sources.push((async () => {
3118
+ try {
3119
+ const resources = currentDevMode
3120
+ ? await resourceListAccessible(DEV_MODE_USER_EMAIL)
3121
+ : await resourceList(SHARED_OWNER);
3122
+ flush(resources.map((r) => {
3123
+ const isShared = r.owner === SHARED_OWNER;
3124
+ return {
3125
+ id: `resource:${r.path}`,
3126
+ label: r.path.split("/").pop() || r.path,
3127
+ description: r.path,
3128
+ icon: "file",
3129
+ source: isShared
3130
+ ? "resource:shared"
3131
+ : "resource:private",
2915
3132
  refType: "file",
2916
- refPath: f.path,
3133
+ refPath: r.path,
2917
3134
  section: "Files",
2918
- })));
2919
- })());
3135
+ };
3136
+ }));
2920
3137
  }
2921
- // 3. Custom mention providers (each flushes independently)
2922
- for (const [key, provider] of Object.entries(mentionProviders)) {
2923
- sources.push((async () => {
2924
- try {
2925
- const providerItems = await provider.search(q, event);
2926
- flush(providerItems.map((item) => ({
2927
- id: item.id,
2928
- label: item.label,
2929
- description: item.description,
2930
- icon: item.icon || provider.icon || "file",
2931
- source: key,
2932
- refType: item.refType,
2933
- refPath: item.refPath,
2934
- refId: item.refId,
2935
- section: provider.label,
2936
- })));
2937
- }
2938
- catch (e) {
2939
- console.error(`[agent-native] Mention provider "${key}" failed:`, e);
2940
- }
2941
- })());
2942
- }
2943
- // 4. Custom workspace agents
3138
+ catch { }
3139
+ })());
3140
+ // 2. Codebase files (dev mode only — can be slow on large repos)
3141
+ if (currentDevMode) {
2944
3142
  sources.push((async () => {
3143
+ const codebaseFiles = [];
2945
3144
  try {
2946
- const owner = await getOwnerFromEvent(event);
2947
- const { listAccessibleCustomAgents } = await import("../resources/agents.js");
2948
- const agents = await listAccessibleCustomAgents(owner);
2949
- flush(agents.map((agent) => ({
2950
- id: `custom-agent:${agent.id}`,
2951
- label: agent.name,
2952
- description: agent.description || agent.path,
2953
- icon: "agent",
2954
- source: "agent:custom",
2955
- refType: "custom-agent",
2956
- refPath: agent.path,
2957
- refId: agent.id,
2958
- section: "Agents",
2959
- })));
2960
- }
2961
- catch (e) {
2962
- console.error("[agent-native] Custom agent discovery failed:", e);
3145
+ await collectFiles(process.cwd(), "", 0, codebaseFiles);
2963
3146
  }
3147
+ catch { }
3148
+ flush(codebaseFiles.map((f) => ({
3149
+ id: `codebase:${f.path}`,
3150
+ label: f.name,
3151
+ description: f.path !== f.name ? f.path : undefined,
3152
+ icon: f.type,
3153
+ source: "codebase",
3154
+ refType: "file",
3155
+ refPath: f.path,
3156
+ section: "Files",
3157
+ })));
2964
3158
  })());
2965
- // 5. Peer agent discovery (network call — often slowest)
3159
+ }
3160
+ // 3. Custom mention providers (each flushes independently)
3161
+ for (const [key, provider] of Object.entries(mentionProviders)) {
2966
3162
  sources.push((async () => {
2967
3163
  try {
2968
- const agents = await discoverAgents(options?.appId);
2969
- flush(agents.map((agent) => ({
2970
- id: `agent:${agent.id}`,
2971
- label: agent.name,
2972
- description: agent.description,
2973
- icon: "agent",
2974
- source: "agent",
2975
- refType: "agent",
2976
- refPath: agent.url,
2977
- refId: agent.id,
2978
- section: "Connected Agents",
3164
+ const providerItems = await provider.search(q, event);
3165
+ flush(providerItems.map((item) => ({
3166
+ id: item.id,
3167
+ label: item.label,
3168
+ description: item.description,
3169
+ icon: item.icon || provider.icon || "file",
3170
+ source: key,
3171
+ refType: item.refType,
3172
+ refPath: item.refPath,
3173
+ refId: item.refId,
3174
+ section: provider.label,
2979
3175
  })));
2980
3176
  }
2981
3177
  catch (e) {
2982
- console.error("[agent-native] Agent discovery failed:", e);
3178
+ console.error(`[agent-native] Mention provider "${key}" failed:`, e);
2983
3179
  }
2984
3180
  })());
2985
- await Promise.all(sources);
2986
- if (!cancelled)
2987
- controller.close();
2988
- },
2989
- cancel() {
2990
- // Client disconnected stop enqueuing
2991
- },
2992
- });
2993
- return stream;
3181
+ }
3182
+ // 4. Custom workspace agents
3183
+ sources.push((async () => {
3184
+ try {
3185
+ const owner = await getOwnerFromEvent(event);
3186
+ const { listAccessibleCustomAgents } = await import("../resources/agents.js");
3187
+ const agents = await listAccessibleCustomAgents(owner);
3188
+ flush(agents.map((agent) => ({
3189
+ id: `custom-agent:${agent.id}`,
3190
+ label: agent.name,
3191
+ description: agent.description || agent.path,
3192
+ icon: "agent",
3193
+ source: "agent:custom",
3194
+ refType: "custom-agent",
3195
+ refPath: agent.path,
3196
+ refId: agent.id,
3197
+ section: "Agents",
3198
+ })));
3199
+ }
3200
+ catch (e) {
3201
+ console.error("[agent-native] Custom agent discovery failed:", e);
3202
+ }
3203
+ })());
3204
+ // 5. Peer agent discovery (network call — often slowest)
3205
+ sources.push((async () => {
3206
+ try {
3207
+ const agents = await discoverAgents(options?.appId);
3208
+ flush(agents.map((agent) => ({
3209
+ id: `agent:${agent.id}`,
3210
+ label: agent.name,
3211
+ description: agent.description,
3212
+ icon: "agent",
3213
+ source: "agent",
3214
+ refType: "agent",
3215
+ refPath: agent.url,
3216
+ refId: agent.id,
3217
+ section: "Connected Agents",
3218
+ })));
3219
+ }
3220
+ catch (e) {
3221
+ console.error("[agent-native] Agent discovery failed:", e);
3222
+ }
3223
+ })());
3224
+ await Promise.all(sources);
3225
+ if (!cancelled)
3226
+ controller.close();
3227
+ }
2994
3228
  }));
2995
3229
  // ─── Generate thread title ──────────────────────────────────────────
2996
3230
  getH3App(nitroApp).use(`${routePath}/generate-title`, defineEventHandler(async (event) => {
@@ -2999,6 +3233,19 @@ export function createAgentChatPlugin(options) {
2999
3233
  return { error: "Method not allowed" };
3000
3234
  }
3001
3235
  const ownerEmail = await getOwnerFromEvent(event);
3236
+ // Per-user rate limit: 10 calls / 60s. Prevents an authenticated
3237
+ // user from spamming the endpoint to exhaust shared Anthropic
3238
+ // credits on platform-key deployments.
3239
+ const now = Date.now();
3240
+ const limitWindowMs = 60_000;
3241
+ const limitMax = 10;
3242
+ const recent = (generateTitleRateLimit.get(ownerEmail) ?? []).filter((t) => now - t < limitWindowMs);
3243
+ if (recent.length >= limitMax) {
3244
+ setResponseStatus(event, 429);
3245
+ return { error: "Rate limit exceeded" };
3246
+ }
3247
+ recent.push(now);
3248
+ generateTitleRateLimit.set(ownerEmail, recent);
3002
3249
  const body = await readBody(event);
3003
3250
  const message = body?.message;
3004
3251
  if (!message || typeof message !== "string") {
@@ -3091,10 +3338,15 @@ export function createAgentChatPlugin(options) {
3091
3338
  // Check in-memory first, then SQL (cross-isolate on Workers)
3092
3339
  const run = await getActiveRunForThreadAsync(threadId);
3093
3340
  if (!run) {
3094
- setResponseStatus(event, 404);
3095
- return { error: "No active run for this thread" };
3341
+ return {
3342
+ active: false,
3343
+ threadId,
3344
+ status: "idle",
3345
+ heartbeatAt: null,
3346
+ };
3096
3347
  }
3097
3348
  return {
3349
+ active: true,
3098
3350
  runId: run.runId,
3099
3351
  threadId: run.threadId,
3100
3352
  status: run.status,
@@ -3288,6 +3540,19 @@ export function createAgentChatPlugin(options) {
3288
3540
  await setThreadQueuedMessages(threadId, queued);
3289
3541
  return { ok: true };
3290
3542
  }
3543
+ // POST /threads/:id/fork — duplicate a thread with all its messages
3544
+ if (method === "POST" &&
3545
+ /\/threads\/[^/?]+\/fork/.test(event.node?.req?.url || event.path || "")) {
3546
+ const body = await readBody(event);
3547
+ const forked = await forkThread(threadId, owner, {
3548
+ id: body?.id,
3549
+ });
3550
+ if (!forked) {
3551
+ setResponseStatus(event, 404);
3552
+ return { error: "Thread not found" };
3553
+ }
3554
+ return forked;
3555
+ }
3291
3556
  if (method === "DELETE") {
3292
3557
  const thread = await getThread(threadId);
3293
3558
  if (!thread || thread.ownerEmail !== owner) {
@@ -3353,14 +3618,6 @@ export function createAgentChatPlugin(options) {
3353
3618
  // Session not available
3354
3619
  }
3355
3620
  }
3356
- // Also set process.env for backwards compat (CLI scripts, legacy readers)
3357
- process.env.AGENT_USER_EMAIL = owner;
3358
- if (resolvedOrgId) {
3359
- process.env.AGENT_ORG_ID = resolvedOrgId;
3360
- }
3361
- else {
3362
- delete process.env.AGENT_ORG_ID;
3363
- }
3364
3621
  // Propagate the caller's IANA timezone from `x-user-timezone` so that
3365
3622
  // tool calls made by the agent (e.g. log-meal with no explicit date)
3366
3623
  // resolve "today" in the user's local timezone instead of server UTC.
@@ -3370,8 +3627,6 @@ export function createAgentChatPlugin(options) {
3370
3627
  tzRaw.trim().length < 64
3371
3628
  ? tzRaw.trim()
3372
3629
  : undefined;
3373
- if (timezone)
3374
- process.env.AGENT_USER_TIMEZONE = timezone;
3375
3630
  return runWithRequestContext({ userEmail: owner, orgId: resolvedOrgId, timezone }, () => {
3376
3631
  const handler = currentDevMode && devHandler ? devHandler : prodHandler;
3377
3632
  return handler(event);
@@ -3395,6 +3650,7 @@ export function createAgentChatPlugin(options) {
3395
3650
  ...notificationTools,
3396
3651
  ...progressTools,
3397
3652
  ...fetchTool,
3653
+ ...toolActions,
3398
3654
  }),
3399
3655
  getSystemPrompt: async (owner) => {
3400
3656
  const resources = await loadResourcesForPrompt(owner, lazyContext);
@@ -3435,6 +3691,7 @@ export function createAgentChatPlugin(options) {
3435
3691
  ...notificationTools,
3436
3692
  ...progressTools,
3437
3693
  ...fetchTool,
3694
+ ...toolActions,
3438
3695
  }),
3439
3696
  getSystemPrompt: async (owner) => {
3440
3697
  const resources = await loadResourcesForPrompt(owner, lazyContext);
@@ -3488,9 +3745,10 @@ export function getGlobalMcpManager() {
3488
3745
  return _globalMcpManager;
3489
3746
  }
3490
3747
  function mountMcpHubStatusRoute(nitroApp) {
3491
- if (globalThis.__agentNativeMcpHubStatusMounted)
3748
+ const mountedApps = (globalThis.__agentNativeMcpHubStatusMountedApps ??= new WeakSet());
3749
+ if (mountedApps.has(nitroApp))
3492
3750
  return;
3493
- globalThis.__agentNativeMcpHubStatusMounted = true;
3751
+ mountedApps.add(nitroApp);
3494
3752
  try {
3495
3753
  getH3App(nitroApp).use("/_agent-native/mcp/hub/status", defineEventHandler(async (event) => {
3496
3754
  if (getMethod(event) !== "GET") {
@@ -3506,10 +3764,11 @@ function mountMcpHubStatusRoute(nitroApp) {
3506
3764
  }
3507
3765
  }
3508
3766
  function mountMcpStatusRoute(nitroApp, manager) {
3509
- // Idempotent agent-chat-plugin can be invoked once per process; guard anyway.
3510
- if (globalThis.__agentNativeMcpStatusMounted)
3767
+ // Idempotent per Nitro app; dev-all may host multiple templates in one process.
3768
+ const mountedApps = (globalThis.__agentNativeMcpStatusMountedApps ??= new WeakSet());
3769
+ if (mountedApps.has(nitroApp))
3511
3770
  return;
3512
- globalThis.__agentNativeMcpStatusMounted = true;
3771
+ mountedApps.add(nitroApp);
3513
3772
  try {
3514
3773
  getH3App(nitroApp).use("/_agent-native/mcp/status", defineEventHandler(async (event) => {
3515
3774
  if (getMethod(event) !== "GET") {