@agent-native/core 0.93.0 → 0.94.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1197) hide show
  1. package/corpus/README.md +2 -2
  2. package/corpus/core/CHANGELOG.md +25 -0
  3. package/corpus/core/docs/content/a2a-protocol.mdx +21 -5
  4. package/corpus/core/docs/content/actions.mdx +9 -23
  5. package/corpus/core/docs/content/agent-mentions.mdx +31 -29
  6. package/corpus/core/docs/content/agent-native-toolkit.mdx +15 -6
  7. package/corpus/core/docs/content/agent-surfaces.mdx +9 -13
  8. package/corpus/core/docs/content/agent-teams.mdx +1 -0
  9. package/corpus/core/docs/content/authentication.mdx +10 -3
  10. package/corpus/core/docs/content/automation-connectors.mdx +82 -39
  11. package/corpus/core/docs/content/automations.mdx +17 -3
  12. package/corpus/core/docs/content/blueprint-installer.mdx +11 -4
  13. package/corpus/core/docs/content/cli-adapters.mdx +9 -6
  14. package/corpus/core/docs/content/client.mdx +16 -0
  15. package/corpus/core/docs/content/cloneable-saas.mdx +14 -11
  16. package/corpus/core/docs/content/code-agents-ui.mdx +65 -0
  17. package/corpus/core/docs/content/components.mdx +30 -14
  18. package/corpus/core/docs/content/context-awareness.mdx +27 -15
  19. package/corpus/core/docs/content/creating-templates.mdx +15 -9
  20. package/corpus/core/docs/content/cross-app-sso.mdx +16 -6
  21. package/corpus/core/docs/content/data-programs.mdx +1 -1
  22. package/corpus/core/docs/content/database.mdx +17 -5
  23. package/corpus/core/docs/content/deployment.mdx +19 -18
  24. package/corpus/core/docs/content/dispatch.mdx +6 -2
  25. package/corpus/core/docs/content/drop-in-agent.mdx +10 -4
  26. package/corpus/core/docs/content/durable-background-runs.mdx +9 -5
  27. package/corpus/core/docs/content/durable-resume.mdx +9 -4
  28. package/corpus/core/docs/content/embedding-sdk.mdx +26 -8
  29. package/corpus/core/docs/content/evals.mdx +3 -5
  30. package/corpus/core/docs/content/extensions.mdx +22 -9
  31. package/corpus/core/docs/content/external-agents.mdx +25 -34
  32. package/corpus/core/docs/content/faq.mdx +8 -0
  33. package/corpus/core/docs/content/file-uploads.mdx +12 -3
  34. package/corpus/core/docs/content/frames.mdx +16 -0
  35. package/corpus/core/docs/content/generative-ui.mdx +1 -1
  36. package/corpus/core/docs/content/getting-started.mdx +34 -21
  37. package/corpus/core/docs/content/harness-agents.mdx +8 -4
  38. package/corpus/core/docs/content/human-approval.mdx +8 -3
  39. package/corpus/core/docs/content/internationalization.mdx +9 -4
  40. package/corpus/core/docs/content/key-concepts.mdx +13 -20
  41. package/corpus/core/docs/content/local-file-mode.mdx +14 -8
  42. package/corpus/core/docs/content/locales/ar-SA/actions.mdx +2 -2
  43. package/corpus/core/docs/content/locales/ar-SA/agent-native-toolkit.mdx +2 -2
  44. package/corpus/core/docs/content/locales/ar-SA/agent-surfaces.mdx +8 -10
  45. package/corpus/core/docs/content/locales/ar-SA/agent-teams.mdx +1 -0
  46. package/corpus/core/docs/content/locales/ar-SA/authentication.mdx +1 -1
  47. package/corpus/core/docs/content/locales/ar-SA/components.mdx +11 -1
  48. package/corpus/core/docs/content/locales/ar-SA/creating-templates.mdx +3 -7
  49. package/corpus/core/docs/content/locales/ar-SA/cross-app-sso.mdx +16 -6
  50. package/corpus/core/docs/content/locales/ar-SA/deployment.mdx +8 -0
  51. package/corpus/core/docs/content/locales/ar-SA/external-agents.mdx +2 -7
  52. package/corpus/core/docs/content/locales/ar-SA/key-concepts.mdx +13 -20
  53. package/corpus/core/docs/content/locales/ar-SA/multi-tenancy.mdx +5 -5
  54. package/corpus/core/docs/content/locales/ar-SA/notifications.mdx +18 -10
  55. package/corpus/core/docs/content/locales/ar-SA/processors.mdx +11 -5
  56. package/corpus/core/docs/content/locales/ar-SA/server.mdx +17 -10
  57. package/corpus/core/docs/content/locales/ar-SA/sharing.mdx +10 -10
  58. package/corpus/core/docs/content/locales/ar-SA/skills-guide.mdx +34 -17
  59. package/corpus/core/docs/content/locales/ar-SA/template-assets.mdx +16 -13
  60. package/corpus/core/docs/content/locales/ar-SA/template-brain.mdx +3 -1
  61. package/corpus/core/docs/content/locales/ar-SA/template-clips.mdx +3 -3
  62. package/corpus/core/docs/content/locales/ar-SA/template-design.mdx +3 -1
  63. package/corpus/core/docs/content/locales/ar-SA/template-dispatch.mdx +5 -1
  64. package/corpus/core/docs/content/locales/ar-SA/template-mail.mdx +8 -0
  65. package/corpus/core/docs/content/locales/ar-SA/tracking.mdx +9 -6
  66. package/corpus/core/docs/content/locales/ar-SA/using-your-agent.mdx +0 -7
  67. package/corpus/core/docs/content/locales/ar-SA/voice-input.mdx +6 -0
  68. package/corpus/core/docs/content/locales/ar-SA/workspace-connections.mdx +9 -2
  69. package/corpus/core/docs/content/locales/ar-SA/workspace.mdx +19 -18
  70. package/corpus/core/docs/content/locales/de-DE/actions.mdx +2 -2
  71. package/corpus/core/docs/content/locales/de-DE/agent-native-toolkit.mdx +2 -2
  72. package/corpus/core/docs/content/locales/de-DE/agent-surfaces.mdx +8 -10
  73. package/corpus/core/docs/content/locales/de-DE/agent-teams.mdx +1 -0
  74. package/corpus/core/docs/content/locales/de-DE/authentication.mdx +1 -1
  75. package/corpus/core/docs/content/locales/de-DE/components.mdx +11 -1
  76. package/corpus/core/docs/content/locales/de-DE/creating-templates.mdx +3 -7
  77. package/corpus/core/docs/content/locales/de-DE/cross-app-sso.mdx +16 -6
  78. package/corpus/core/docs/content/locales/de-DE/deployment.mdx +8 -0
  79. package/corpus/core/docs/content/locales/de-DE/external-agents.mdx +3 -7
  80. package/corpus/core/docs/content/locales/de-DE/key-concepts.mdx +13 -20
  81. package/corpus/core/docs/content/locales/de-DE/multi-tenancy.mdx +5 -5
  82. package/corpus/core/docs/content/locales/de-DE/notifications.mdx +18 -10
  83. package/corpus/core/docs/content/locales/de-DE/processors.mdx +11 -5
  84. package/corpus/core/docs/content/locales/de-DE/server.mdx +18 -10
  85. package/corpus/core/docs/content/locales/de-DE/sharing.mdx +10 -10
  86. package/corpus/core/docs/content/locales/de-DE/skills-guide.mdx +34 -17
  87. package/corpus/core/docs/content/locales/de-DE/template-assets.mdx +16 -13
  88. package/corpus/core/docs/content/locales/de-DE/template-brain.mdx +3 -1
  89. package/corpus/core/docs/content/locales/de-DE/template-clips.mdx +3 -3
  90. package/corpus/core/docs/content/locales/de-DE/template-design.mdx +3 -1
  91. package/corpus/core/docs/content/locales/de-DE/template-dispatch.mdx +5 -1
  92. package/corpus/core/docs/content/locales/de-DE/template-mail.mdx +8 -0
  93. package/corpus/core/docs/content/locales/de-DE/tracking.mdx +9 -6
  94. package/corpus/core/docs/content/locales/de-DE/using-your-agent.mdx +0 -7
  95. package/corpus/core/docs/content/locales/de-DE/voice-input.mdx +6 -0
  96. package/corpus/core/docs/content/locales/de-DE/workspace-connections.mdx +9 -2
  97. package/corpus/core/docs/content/locales/de-DE/workspace.mdx +19 -18
  98. package/corpus/core/docs/content/locales/es-ES/actions.mdx +2 -2
  99. package/corpus/core/docs/content/locales/es-ES/agent-native-toolkit.mdx +2 -2
  100. package/corpus/core/docs/content/locales/es-ES/agent-surfaces.mdx +8 -10
  101. package/corpus/core/docs/content/locales/es-ES/agent-teams.mdx +1 -0
  102. package/corpus/core/docs/content/locales/es-ES/authentication.mdx +1 -1
  103. package/corpus/core/docs/content/locales/es-ES/components.mdx +11 -1
  104. package/corpus/core/docs/content/locales/es-ES/creating-templates.mdx +3 -7
  105. package/corpus/core/docs/content/locales/es-ES/cross-app-sso.mdx +16 -6
  106. package/corpus/core/docs/content/locales/es-ES/deployment.mdx +8 -0
  107. package/corpus/core/docs/content/locales/es-ES/external-agents.mdx +3 -7
  108. package/corpus/core/docs/content/locales/es-ES/key-concepts.mdx +13 -20
  109. package/corpus/core/docs/content/locales/es-ES/multi-tenancy.mdx +5 -5
  110. package/corpus/core/docs/content/locales/es-ES/notifications.mdx +18 -10
  111. package/corpus/core/docs/content/locales/es-ES/processors.mdx +11 -5
  112. package/corpus/core/docs/content/locales/es-ES/server.mdx +17 -10
  113. package/corpus/core/docs/content/locales/es-ES/sharing.mdx +10 -10
  114. package/corpus/core/docs/content/locales/es-ES/skills-guide.mdx +34 -17
  115. package/corpus/core/docs/content/locales/es-ES/template-assets.mdx +16 -13
  116. package/corpus/core/docs/content/locales/es-ES/template-brain.mdx +3 -1
  117. package/corpus/core/docs/content/locales/es-ES/template-clips.mdx +3 -3
  118. package/corpus/core/docs/content/locales/es-ES/template-design.mdx +3 -1
  119. package/corpus/core/docs/content/locales/es-ES/template-dispatch.mdx +5 -1
  120. package/corpus/core/docs/content/locales/es-ES/template-mail.mdx +8 -0
  121. package/corpus/core/docs/content/locales/es-ES/tracking.mdx +9 -6
  122. package/corpus/core/docs/content/locales/es-ES/using-your-agent.mdx +0 -7
  123. package/corpus/core/docs/content/locales/es-ES/voice-input.mdx +6 -0
  124. package/corpus/core/docs/content/locales/es-ES/workspace-connections.mdx +9 -2
  125. package/corpus/core/docs/content/locales/es-ES/workspace.mdx +19 -18
  126. package/corpus/core/docs/content/locales/fr-FR/actions.mdx +2 -2
  127. package/corpus/core/docs/content/locales/fr-FR/agent-native-toolkit.mdx +2 -2
  128. package/corpus/core/docs/content/locales/fr-FR/agent-surfaces.mdx +8 -10
  129. package/corpus/core/docs/content/locales/fr-FR/agent-teams.mdx +1 -0
  130. package/corpus/core/docs/content/locales/fr-FR/authentication.mdx +1 -1
  131. package/corpus/core/docs/content/locales/fr-FR/components.mdx +11 -1
  132. package/corpus/core/docs/content/locales/fr-FR/creating-templates.mdx +3 -7
  133. package/corpus/core/docs/content/locales/fr-FR/cross-app-sso.mdx +16 -6
  134. package/corpus/core/docs/content/locales/fr-FR/deployment.mdx +8 -0
  135. package/corpus/core/docs/content/locales/fr-FR/external-agents.mdx +3 -7
  136. package/corpus/core/docs/content/locales/fr-FR/key-concepts.mdx +13 -20
  137. package/corpus/core/docs/content/locales/fr-FR/multi-tenancy.mdx +5 -5
  138. package/corpus/core/docs/content/locales/fr-FR/notifications.mdx +18 -10
  139. package/corpus/core/docs/content/locales/fr-FR/processors.mdx +11 -5
  140. package/corpus/core/docs/content/locales/fr-FR/server.mdx +17 -10
  141. package/corpus/core/docs/content/locales/fr-FR/sharing.mdx +10 -10
  142. package/corpus/core/docs/content/locales/fr-FR/skills-guide.mdx +34 -17
  143. package/corpus/core/docs/content/locales/fr-FR/template-assets.mdx +16 -13
  144. package/corpus/core/docs/content/locales/fr-FR/template-brain.mdx +3 -1
  145. package/corpus/core/docs/content/locales/fr-FR/template-clips.mdx +3 -3
  146. package/corpus/core/docs/content/locales/fr-FR/template-design.mdx +3 -1
  147. package/corpus/core/docs/content/locales/fr-FR/template-dispatch.mdx +5 -1
  148. package/corpus/core/docs/content/locales/fr-FR/template-mail.mdx +8 -0
  149. package/corpus/core/docs/content/locales/fr-FR/tracking.mdx +9 -6
  150. package/corpus/core/docs/content/locales/fr-FR/using-your-agent.mdx +0 -7
  151. package/corpus/core/docs/content/locales/fr-FR/voice-input.mdx +6 -0
  152. package/corpus/core/docs/content/locales/fr-FR/workspace-connections.mdx +9 -2
  153. package/corpus/core/docs/content/locales/fr-FR/workspace.mdx +19 -18
  154. package/corpus/core/docs/content/locales/hi-IN/actions.mdx +2 -2
  155. package/corpus/core/docs/content/locales/hi-IN/agent-native-toolkit.mdx +2 -2
  156. package/corpus/core/docs/content/locales/hi-IN/agent-surfaces.mdx +8 -10
  157. package/corpus/core/docs/content/locales/hi-IN/agent-teams.mdx +1 -0
  158. package/corpus/core/docs/content/locales/hi-IN/authentication.mdx +1 -1
  159. package/corpus/core/docs/content/locales/hi-IN/components.mdx +11 -1
  160. package/corpus/core/docs/content/locales/hi-IN/creating-templates.mdx +3 -7
  161. package/corpus/core/docs/content/locales/hi-IN/cross-app-sso.mdx +16 -6
  162. package/corpus/core/docs/content/locales/hi-IN/deployment.mdx +8 -0
  163. package/corpus/core/docs/content/locales/hi-IN/external-agents.mdx +2 -7
  164. package/corpus/core/docs/content/locales/hi-IN/key-concepts.mdx +13 -20
  165. package/corpus/core/docs/content/locales/hi-IN/multi-tenancy.mdx +5 -5
  166. package/corpus/core/docs/content/locales/hi-IN/notifications.mdx +18 -10
  167. package/corpus/core/docs/content/locales/hi-IN/processors.mdx +11 -5
  168. package/corpus/core/docs/content/locales/hi-IN/server.mdx +17 -10
  169. package/corpus/core/docs/content/locales/hi-IN/sharing.mdx +10 -10
  170. package/corpus/core/docs/content/locales/hi-IN/skills-guide.mdx +34 -17
  171. package/corpus/core/docs/content/locales/hi-IN/template-assets.mdx +16 -13
  172. package/corpus/core/docs/content/locales/hi-IN/template-brain.mdx +3 -1
  173. package/corpus/core/docs/content/locales/hi-IN/template-clips.mdx +3 -3
  174. package/corpus/core/docs/content/locales/hi-IN/template-design.mdx +3 -1
  175. package/corpus/core/docs/content/locales/hi-IN/template-dispatch.mdx +5 -1
  176. package/corpus/core/docs/content/locales/hi-IN/template-mail.mdx +8 -0
  177. package/corpus/core/docs/content/locales/hi-IN/tracking.mdx +9 -6
  178. package/corpus/core/docs/content/locales/hi-IN/using-your-agent.mdx +0 -7
  179. package/corpus/core/docs/content/locales/hi-IN/voice-input.mdx +6 -0
  180. package/corpus/core/docs/content/locales/hi-IN/workspace-connections.mdx +9 -2
  181. package/corpus/core/docs/content/locales/hi-IN/workspace.mdx +19 -18
  182. package/corpus/core/docs/content/locales/ja-JP/actions.mdx +2 -2
  183. package/corpus/core/docs/content/locales/ja-JP/agent-native-toolkit.mdx +2 -2
  184. package/corpus/core/docs/content/locales/ja-JP/agent-surfaces.mdx +8 -10
  185. package/corpus/core/docs/content/locales/ja-JP/agent-teams.mdx +1 -0
  186. package/corpus/core/docs/content/locales/ja-JP/authentication.mdx +1 -1
  187. package/corpus/core/docs/content/locales/ja-JP/components.mdx +11 -1
  188. package/corpus/core/docs/content/locales/ja-JP/creating-templates.mdx +3 -7
  189. package/corpus/core/docs/content/locales/ja-JP/cross-app-sso.mdx +16 -6
  190. package/corpus/core/docs/content/locales/ja-JP/deployment.mdx +8 -0
  191. package/corpus/core/docs/content/locales/ja-JP/external-agents.mdx +2 -7
  192. package/corpus/core/docs/content/locales/ja-JP/key-concepts.mdx +13 -20
  193. package/corpus/core/docs/content/locales/ja-JP/multi-tenancy.mdx +5 -5
  194. package/corpus/core/docs/content/locales/ja-JP/notifications.mdx +18 -10
  195. package/corpus/core/docs/content/locales/ja-JP/processors.mdx +11 -5
  196. package/corpus/core/docs/content/locales/ja-JP/server.mdx +17 -10
  197. package/corpus/core/docs/content/locales/ja-JP/sharing.mdx +10 -10
  198. package/corpus/core/docs/content/locales/ja-JP/skills-guide.mdx +34 -17
  199. package/corpus/core/docs/content/locales/ja-JP/template-assets.mdx +16 -13
  200. package/corpus/core/docs/content/locales/ja-JP/template-brain.mdx +3 -1
  201. package/corpus/core/docs/content/locales/ja-JP/template-clips.mdx +3 -4
  202. package/corpus/core/docs/content/locales/ja-JP/template-design.mdx +3 -1
  203. package/corpus/core/docs/content/locales/ja-JP/template-dispatch.mdx +5 -1
  204. package/corpus/core/docs/content/locales/ja-JP/template-mail.mdx +8 -0
  205. package/corpus/core/docs/content/locales/ja-JP/tracking.mdx +9 -6
  206. package/corpus/core/docs/content/locales/ja-JP/using-your-agent.mdx +0 -7
  207. package/corpus/core/docs/content/locales/ja-JP/voice-input.mdx +6 -0
  208. package/corpus/core/docs/content/locales/ja-JP/workspace-connections.mdx +9 -2
  209. package/corpus/core/docs/content/locales/ja-JP/workspace.mdx +19 -18
  210. package/corpus/core/docs/content/locales/ko-KR/actions.mdx +2 -2
  211. package/corpus/core/docs/content/locales/ko-KR/agent-native-toolkit.mdx +2 -2
  212. package/corpus/core/docs/content/locales/ko-KR/agent-surfaces.mdx +8 -10
  213. package/corpus/core/docs/content/locales/ko-KR/agent-teams.mdx +1 -0
  214. package/corpus/core/docs/content/locales/ko-KR/authentication.mdx +1 -1
  215. package/corpus/core/docs/content/locales/ko-KR/components.mdx +11 -1
  216. package/corpus/core/docs/content/locales/ko-KR/creating-templates.mdx +3 -7
  217. package/corpus/core/docs/content/locales/ko-KR/cross-app-sso.mdx +16 -6
  218. package/corpus/core/docs/content/locales/ko-KR/deployment.mdx +8 -0
  219. package/corpus/core/docs/content/locales/ko-KR/external-agents.mdx +2 -7
  220. package/corpus/core/docs/content/locales/ko-KR/key-concepts.mdx +13 -20
  221. package/corpus/core/docs/content/locales/ko-KR/multi-tenancy.mdx +5 -5
  222. package/corpus/core/docs/content/locales/ko-KR/notifications.mdx +18 -10
  223. package/corpus/core/docs/content/locales/ko-KR/processors.mdx +11 -5
  224. package/corpus/core/docs/content/locales/ko-KR/server.mdx +17 -10
  225. package/corpus/core/docs/content/locales/ko-KR/sharing.mdx +10 -10
  226. package/corpus/core/docs/content/locales/ko-KR/skills-guide.mdx +34 -17
  227. package/corpus/core/docs/content/locales/ko-KR/template-assets.mdx +16 -13
  228. package/corpus/core/docs/content/locales/ko-KR/template-brain.mdx +3 -1
  229. package/corpus/core/docs/content/locales/ko-KR/template-clips.mdx +3 -4
  230. package/corpus/core/docs/content/locales/ko-KR/template-design.mdx +3 -1
  231. package/corpus/core/docs/content/locales/ko-KR/template-dispatch.mdx +5 -1
  232. package/corpus/core/docs/content/locales/ko-KR/template-mail.mdx +8 -0
  233. package/corpus/core/docs/content/locales/ko-KR/tracking.mdx +9 -6
  234. package/corpus/core/docs/content/locales/ko-KR/using-your-agent.mdx +0 -7
  235. package/corpus/core/docs/content/locales/ko-KR/voice-input.mdx +6 -0
  236. package/corpus/core/docs/content/locales/ko-KR/workspace-connections.mdx +9 -2
  237. package/corpus/core/docs/content/locales/ko-KR/workspace.mdx +19 -18
  238. package/corpus/core/docs/content/locales/pt-BR/actions.mdx +2 -2
  239. package/corpus/core/docs/content/locales/pt-BR/agent-native-toolkit.mdx +2 -2
  240. package/corpus/core/docs/content/locales/pt-BR/agent-surfaces.mdx +8 -10
  241. package/corpus/core/docs/content/locales/pt-BR/agent-teams.mdx +1 -0
  242. package/corpus/core/docs/content/locales/pt-BR/authentication.mdx +1 -1
  243. package/corpus/core/docs/content/locales/pt-BR/components.mdx +11 -1
  244. package/corpus/core/docs/content/locales/pt-BR/creating-templates.mdx +3 -7
  245. package/corpus/core/docs/content/locales/pt-BR/cross-app-sso.mdx +16 -6
  246. package/corpus/core/docs/content/locales/pt-BR/deployment.mdx +8 -0
  247. package/corpus/core/docs/content/locales/pt-BR/external-agents.mdx +3 -7
  248. package/corpus/core/docs/content/locales/pt-BR/key-concepts.mdx +13 -20
  249. package/corpus/core/docs/content/locales/pt-BR/multi-tenancy.mdx +5 -5
  250. package/corpus/core/docs/content/locales/pt-BR/notifications.mdx +18 -10
  251. package/corpus/core/docs/content/locales/pt-BR/processors.mdx +11 -5
  252. package/corpus/core/docs/content/locales/pt-BR/server.mdx +17 -10
  253. package/corpus/core/docs/content/locales/pt-BR/sharing.mdx +10 -10
  254. package/corpus/core/docs/content/locales/pt-BR/skills-guide.mdx +34 -17
  255. package/corpus/core/docs/content/locales/pt-BR/template-assets.mdx +16 -13
  256. package/corpus/core/docs/content/locales/pt-BR/template-brain.mdx +3 -1
  257. package/corpus/core/docs/content/locales/pt-BR/template-clips.mdx +3 -3
  258. package/corpus/core/docs/content/locales/pt-BR/template-design.mdx +3 -1
  259. package/corpus/core/docs/content/locales/pt-BR/template-dispatch.mdx +5 -1
  260. package/corpus/core/docs/content/locales/pt-BR/template-mail.mdx +8 -0
  261. package/corpus/core/docs/content/locales/pt-BR/tracking.mdx +9 -6
  262. package/corpus/core/docs/content/locales/pt-BR/using-your-agent.mdx +0 -7
  263. package/corpus/core/docs/content/locales/pt-BR/voice-input.mdx +6 -0
  264. package/corpus/core/docs/content/locales/pt-BR/workspace-connections.mdx +9 -2
  265. package/corpus/core/docs/content/locales/pt-BR/workspace.mdx +19 -18
  266. package/corpus/core/docs/content/locales/zh-CN/actions.mdx +2 -2
  267. package/corpus/core/docs/content/locales/zh-CN/agent-native-toolkit.mdx +2 -2
  268. package/corpus/core/docs/content/locales/zh-CN/agent-surfaces.mdx +8 -10
  269. package/corpus/core/docs/content/locales/zh-CN/agent-teams.mdx +1 -0
  270. package/corpus/core/docs/content/locales/zh-CN/authentication.mdx +1 -1
  271. package/corpus/core/docs/content/locales/zh-CN/components.mdx +11 -1
  272. package/corpus/core/docs/content/locales/zh-CN/creating-templates.mdx +3 -7
  273. package/corpus/core/docs/content/locales/zh-CN/cross-app-sso.mdx +16 -6
  274. package/corpus/core/docs/content/locales/zh-CN/deployment.mdx +8 -0
  275. package/corpus/core/docs/content/locales/zh-CN/external-agents.mdx +2 -7
  276. package/corpus/core/docs/content/locales/zh-CN/key-concepts.mdx +13 -20
  277. package/corpus/core/docs/content/locales/zh-CN/multi-tenancy.mdx +5 -5
  278. package/corpus/core/docs/content/locales/zh-CN/notifications.mdx +18 -10
  279. package/corpus/core/docs/content/locales/zh-CN/processors.mdx +11 -5
  280. package/corpus/core/docs/content/locales/zh-CN/server.mdx +16 -10
  281. package/corpus/core/docs/content/locales/zh-CN/sharing.mdx +10 -10
  282. package/corpus/core/docs/content/locales/zh-CN/skills-guide.mdx +34 -17
  283. package/corpus/core/docs/content/locales/zh-CN/template-assets.mdx +16 -13
  284. package/corpus/core/docs/content/locales/zh-CN/template-brain.mdx +3 -1
  285. package/corpus/core/docs/content/locales/zh-CN/template-clips.mdx +3 -4
  286. package/corpus/core/docs/content/locales/zh-CN/template-design.mdx +3 -1
  287. package/corpus/core/docs/content/locales/zh-CN/template-dispatch.mdx +5 -1
  288. package/corpus/core/docs/content/locales/zh-CN/template-mail.mdx +8 -0
  289. package/corpus/core/docs/content/locales/zh-CN/tracking.mdx +9 -6
  290. package/corpus/core/docs/content/locales/zh-CN/using-your-agent.mdx +0 -7
  291. package/corpus/core/docs/content/locales/zh-CN/voice-input.mdx +6 -0
  292. package/corpus/core/docs/content/locales/zh-CN/workspace-connections.mdx +9 -2
  293. package/corpus/core/docs/content/locales/zh-CN/workspace.mdx +19 -18
  294. package/corpus/core/docs/content/locales/zh-TW/actions.mdx +2 -2
  295. package/corpus/core/docs/content/locales/zh-TW/agent-native-toolkit.mdx +2 -2
  296. package/corpus/core/docs/content/locales/zh-TW/agent-surfaces.mdx +8 -10
  297. package/corpus/core/docs/content/locales/zh-TW/agent-teams.mdx +1 -0
  298. package/corpus/core/docs/content/locales/zh-TW/authentication.mdx +1 -1
  299. package/corpus/core/docs/content/locales/zh-TW/components.mdx +11 -1
  300. package/corpus/core/docs/content/locales/zh-TW/creating-templates.mdx +3 -7
  301. package/corpus/core/docs/content/locales/zh-TW/cross-app-sso.mdx +16 -6
  302. package/corpus/core/docs/content/locales/zh-TW/deployment.mdx +8 -0
  303. package/corpus/core/docs/content/locales/zh-TW/external-agents.mdx +2 -7
  304. package/corpus/core/docs/content/locales/zh-TW/key-concepts.mdx +13 -20
  305. package/corpus/core/docs/content/locales/zh-TW/multi-tenancy.mdx +5 -5
  306. package/corpus/core/docs/content/locales/zh-TW/notifications.mdx +18 -10
  307. package/corpus/core/docs/content/locales/zh-TW/processors.mdx +11 -5
  308. package/corpus/core/docs/content/locales/zh-TW/server.mdx +16 -10
  309. package/corpus/core/docs/content/locales/zh-TW/sharing.mdx +10 -10
  310. package/corpus/core/docs/content/locales/zh-TW/skills-guide.mdx +34 -17
  311. package/corpus/core/docs/content/locales/zh-TW/template-assets.mdx +16 -13
  312. package/corpus/core/docs/content/locales/zh-TW/template-brain.mdx +3 -1
  313. package/corpus/core/docs/content/locales/zh-TW/template-clips.mdx +3 -4
  314. package/corpus/core/docs/content/locales/zh-TW/template-design.mdx +3 -1
  315. package/corpus/core/docs/content/locales/zh-TW/template-dispatch.mdx +5 -1
  316. package/corpus/core/docs/content/locales/zh-TW/template-mail.mdx +8 -0
  317. package/corpus/core/docs/content/locales/zh-TW/tracking.mdx +9 -6
  318. package/corpus/core/docs/content/locales/zh-TW/using-your-agent.mdx +0 -7
  319. package/corpus/core/docs/content/locales/zh-TW/voice-input.mdx +6 -0
  320. package/corpus/core/docs/content/locales/zh-TW/workspace-connections.mdx +9 -2
  321. package/corpus/core/docs/content/locales/zh-TW/workspace.mdx +19 -18
  322. package/corpus/core/docs/content/mcp-apps.mdx +14 -32
  323. package/corpus/core/docs/content/mcp-clients.mdx +48 -54
  324. package/corpus/core/docs/content/mcp-protocol.mdx +25 -10
  325. package/corpus/core/docs/content/messaging.mdx +19 -11
  326. package/corpus/core/docs/content/multi-app-workspace.mdx +11 -96
  327. package/corpus/core/docs/content/multi-tenancy.mdx +5 -5
  328. package/corpus/core/docs/content/native-chat-ui.mdx +4 -4
  329. package/corpus/core/docs/content/notifications.mdx +19 -12
  330. package/corpus/core/docs/content/observability.mdx +2 -4
  331. package/corpus/core/docs/content/observational-memory.mdx +7 -3
  332. package/corpus/core/docs/content/onboarding.mdx +9 -2
  333. package/corpus/core/docs/content/plan-plugin.mdx +10 -2
  334. package/corpus/core/docs/content/pr-visual-recap.mdx +1 -1
  335. package/corpus/core/docs/content/processors.mdx +11 -5
  336. package/corpus/core/docs/content/pure-agent-apps.mdx +5 -1
  337. package/corpus/core/docs/content/real-time-collaboration.mdx +30 -67
  338. package/corpus/core/docs/content/recurring-jobs.mdx +8 -6
  339. package/corpus/core/docs/content/routing.mdx +3 -4
  340. package/corpus/core/docs/content/sandbox-adapters.mdx +30 -53
  341. package/corpus/core/docs/content/security.mdx +8 -0
  342. package/corpus/core/docs/content/server.mdx +17 -10
  343. package/corpus/core/docs/content/sharing.mdx +10 -10
  344. package/corpus/core/docs/content/skills-guide.mdx +35 -16
  345. package/corpus/core/docs/content/template-analytics.mdx +11 -8
  346. package/corpus/core/docs/content/template-assets.mdx +16 -13
  347. package/corpus/core/docs/content/template-brain.mdx +3 -1
  348. package/corpus/core/docs/content/template-calendar.mdx +12 -4
  349. package/corpus/core/docs/content/template-chat.mdx +4 -4
  350. package/corpus/core/docs/content/template-clips.mdx +3 -3
  351. package/corpus/core/docs/content/template-content.mdx +23 -18
  352. package/corpus/core/docs/content/template-design.mdx +3 -1
  353. package/corpus/core/docs/content/template-dispatch.mdx +5 -1
  354. package/corpus/core/docs/content/template-mail.mdx +14 -2
  355. package/corpus/core/docs/content/template-plan.mdx +22 -15
  356. package/corpus/core/docs/content/template-slides.mdx +11 -3
  357. package/corpus/core/docs/content/toolkit-agent-ux.mdx +46 -3
  358. package/corpus/core/docs/content/toolkit-collaboration.mdx +58 -4
  359. package/corpus/core/docs/content/toolkit-command-navigation.mdx +8 -2
  360. package/corpus/core/docs/content/toolkit-comments-review.mdx +10 -2
  361. package/corpus/core/docs/content/toolkit-history.mdx +8 -3
  362. package/corpus/core/docs/content/toolkit-observability.mdx +48 -2
  363. package/corpus/core/docs/content/toolkit-org-team.mdx +8 -2
  364. package/corpus/core/docs/content/toolkit-resources.mdx +45 -2
  365. package/corpus/core/docs/content/toolkit-settings.mdx +8 -2
  366. package/corpus/core/docs/content/toolkit-setup-connections.mdx +7 -2
  367. package/corpus/core/docs/content/toolkit-sharing.mdx +46 -3
  368. package/corpus/core/docs/content/toolkit-ui.mdx +82 -11
  369. package/corpus/core/docs/content/tracking.mdx +10 -8
  370. package/corpus/core/docs/content/using-your-agent.mdx +0 -12
  371. package/corpus/core/docs/content/voice-input.mdx +7 -1
  372. package/corpus/core/docs/content/what-is-agent-native.mdx +7 -8
  373. package/corpus/core/docs/content/workspace-connections.mdx +16 -23
  374. package/corpus/core/docs/content/workspace-management.mdx +16 -4
  375. package/corpus/core/docs/content/workspace.mdx +19 -18
  376. package/corpus/core/package.json +1 -1
  377. package/corpus/core/src/agent/context-xray/tokenize.ts +6 -1
  378. package/corpus/core/src/agent/engine/ai-sdk-engine.ts +9 -5
  379. package/corpus/core/src/agent/engine/anthropic-engine.ts +2 -4
  380. package/corpus/core/src/agent/engine/builder-engine.ts +5 -7
  381. package/corpus/core/src/agent/engine/index.ts +1 -0
  382. package/corpus/core/src/agent/engine/registry.ts +40 -0
  383. package/corpus/core/src/agent/harness/ai-sdk-adapter.ts +6 -1
  384. package/corpus/core/src/agent/harness/background.ts +96 -19
  385. package/corpus/core/src/agent/harness/index.ts +11 -0
  386. package/corpus/core/src/agent/harness/lifecycle.ts +498 -0
  387. package/corpus/core/src/agent/harness/runner.ts +38 -0
  388. package/corpus/core/src/agent/harness/store.ts +22 -3
  389. package/corpus/core/src/agent/model-config.ts +4 -1
  390. package/corpus/core/src/agent/production-agent.ts +190 -6
  391. package/corpus/core/src/agent/run-manager.ts +5 -1
  392. package/corpus/core/src/application-state/index.ts +1 -0
  393. package/corpus/core/src/application-state/store.ts +32 -0
  394. package/corpus/core/src/cli/code-agent-connector.ts +263 -8
  395. package/corpus/core/src/cli/code-agent-executor.ts +15 -1
  396. package/corpus/core/src/client/AgentPanel.tsx +41 -38
  397. package/corpus/core/src/client/AssistantChat.tsx +53 -5
  398. package/corpus/core/src/client/MultiTabAssistantChat.tsx +33 -40
  399. package/corpus/core/src/client/appearance.ts +8 -5
  400. package/corpus/core/src/client/chat/connectors.ts +293 -29
  401. package/corpus/core/src/client/chat/message-components.tsx +23 -1
  402. package/corpus/core/src/client/chat/runtime.ts +126 -25
  403. package/corpus/core/src/client/chat/tool-call-display.tsx +45 -4
  404. package/corpus/core/src/client/composer/RealtimeVoiceMode.tsx +294 -0
  405. package/corpus/core/src/client/composer/TiptapComposer.tsx +21 -20
  406. package/corpus/core/src/client/composer/VoiceButton.tsx +20 -0
  407. package/corpus/core/src/client/composer/index.ts +22 -0
  408. package/corpus/core/src/client/composer/useRealtimeVoiceMode.tsx +640 -0
  409. package/corpus/core/src/client/guided-questions.tsx +12 -3
  410. package/corpus/core/src/client/index.ts +18 -0
  411. package/corpus/core/src/client/settings/DemoModeSection.tsx +4 -3
  412. package/corpus/core/src/client/settings/SettingsPanel.tsx +4 -0
  413. package/corpus/core/src/client/settings/SettingsTabsPage.tsx +95 -37
  414. package/corpus/core/src/client/use-chat-models.ts +17 -17
  415. package/corpus/core/src/client/use-db-sync.ts +108 -7
  416. package/corpus/core/src/code-agents/background-controller.ts +18 -0
  417. package/corpus/core/src/collab/ydoc-manager.ts +41 -6
  418. package/corpus/core/src/db/migrations.ts +17 -1
  419. package/corpus/core/src/demo/fetch-interceptor.ts +16 -11
  420. package/corpus/core/src/integrations/adapters/slack.ts +41 -2
  421. package/corpus/core/src/integrations/awaiting-input-store.ts +130 -0
  422. package/corpus/core/src/integrations/computer-supervision-store.ts +423 -0
  423. package/corpus/core/src/integrations/computer-supervision.ts +213 -0
  424. package/corpus/core/src/integrations/index.ts +29 -1
  425. package/corpus/core/src/integrations/plugin.ts +231 -2
  426. package/corpus/core/src/integrations/remote-commands-store.ts +334 -3
  427. package/corpus/core/src/integrations/remote-devices-store.ts +68 -9
  428. package/corpus/core/src/integrations/remote-json-safety.ts +127 -0
  429. package/corpus/core/src/integrations/remote-run-events-store.ts +104 -19
  430. package/corpus/core/src/integrations/remote-types.ts +66 -3
  431. package/corpus/core/src/integrations/webhook-handler.ts +161 -2
  432. package/corpus/core/src/localization/default-messages.ts +28 -0
  433. package/corpus/core/src/mcp-client/config.ts +48 -2
  434. package/corpus/core/src/mcp-client/index.ts +35 -2
  435. package/corpus/core/src/mcp-client/tool-policy.ts +182 -0
  436. package/corpus/core/src/secrets/register-framework-secrets.ts +27 -4
  437. package/corpus/core/src/server/agent-chat-plugin.ts +62 -8
  438. package/corpus/core/src/server/index.ts +16 -0
  439. package/corpus/core/src/server/realtime-voice.ts +590 -0
  440. package/corpus/core/src/shared/reasoning-effort.ts +61 -19
  441. package/corpus/core/src/styles/agent-conversation.css +17 -0
  442. package/corpus/core/src/templates/workspace-core/.agents/skills/voice-transcription/SKILL.md +39 -5
  443. package/corpus/templates/brain/app/lib/settings-navigation.ts +22 -0
  444. package/corpus/templates/brain/app/routes/settings.tsx +367 -252
  445. package/corpus/templates/brain/changelog/2026-07-10-brain-settings-now-separate-assistant-behavior-publishing-re.md +6 -0
  446. package/corpus/templates/brain/changelog/2026-07-10-organization-settings-now-opens-directly-from-the-workspace-.md +6 -0
  447. package/corpus/templates/calendar/.agents/skills/event-management/SKILL.md +36 -4
  448. package/corpus/templates/calendar/AGENTS.md +4 -0
  449. package/corpus/templates/calendar/actions/create-event.ts +7 -19
  450. package/corpus/templates/calendar/actions/delete-event.ts +10 -3
  451. package/corpus/templates/calendar/actions/rsvp-event.ts +1 -1
  452. package/corpus/templates/calendar/actions/update-event.ts +4 -3
  453. package/corpus/templates/calendar/app/components/calendar/CreateEventDialog.tsx +100 -13
  454. package/corpus/templates/calendar/app/components/calendar/DayView.tsx +12 -4
  455. package/corpus/templates/calendar/app/components/calendar/EventDetailPanel.tsx +3 -3
  456. package/corpus/templates/calendar/app/components/calendar/EventDetailPopover.tsx +86 -8
  457. package/corpus/templates/calendar/app/components/calendar/EventDialog.tsx +3 -1
  458. package/corpus/templates/calendar/app/components/calendar/WeekView.tsx +12 -4
  459. package/corpus/templates/calendar/app/hooks/use-events.ts +1 -0
  460. package/corpus/templates/calendar/app/lib/event-account-selection.ts +36 -0
  461. package/corpus/templates/calendar/app/lib/event-form-initialization.ts +21 -0
  462. package/corpus/templates/calendar/app/lib/event-mutation-inputs.ts +18 -0
  463. package/corpus/templates/calendar/app/pages/CalendarView.tsx +119 -26
  464. package/corpus/templates/calendar/changelog/2026-07-10-choose-which-connected-google-account-receives-a-new-event-w.md +6 -0
  465. package/corpus/templates/calendar/server/db/schema.ts +2 -0
  466. package/corpus/templates/calendar/server/handlers/bookings.ts +43 -6
  467. package/corpus/templates/calendar/server/handlers/events.ts +28 -9
  468. package/corpus/templates/calendar/server/lib/google-calendar.ts +66 -38
  469. package/corpus/templates/calendar/server/plugins/db.ts +5 -0
  470. package/corpus/templates/clips/.agents/skills/ai-video-tools/SKILL.md +12 -3
  471. package/corpus/templates/clips/.agents/skills/meetings/SKILL.md +1 -1
  472. package/corpus/templates/clips/AGENTS.md +4 -2
  473. package/corpus/templates/clips/actions/regenerate-title.ts +53 -7
  474. package/corpus/templates/clips/actions/request-transcript.ts +152 -41
  475. package/corpus/templates/clips/actions/save-browser-transcript.ts +11 -9
  476. package/corpus/templates/clips/app/components/player/comments-panel.tsx +101 -53
  477. package/corpus/templates/clips/app/components/player/playback-comment-overlay.tsx +102 -0
  478. package/corpus/templates/clips/app/components/player/video-player.tsx +10 -1
  479. package/corpus/templates/clips/app/hooks/use-auto-title.ts +14 -0
  480. package/corpus/templates/clips/app/routes/embed.$shareId.tsx +2 -0
  481. package/corpus/templates/clips/changelog/2026-07-10-comment-replies-now-open-inline-and-focus-immediately-while-.md +6 -0
  482. package/corpus/templates/clips/changelog/2026-07-10-dismissed-upload-warnings-now-keep-recordings-in-clip-drafts.md +6 -0
  483. package/corpus/templates/clips/changelog/2026-07-10-dragging-the-meeting-recorder-no-longer-opens-the-expanded.md +6 -0
  484. package/corpus/templates/clips/changelog/2026-07-10-finishing-meeting-notes-no-longer-opens-your-browser.md +6 -0
  485. package/corpus/templates/clips/changelog/2026-07-10-meeting-recordings-now-keep-microphone-audio-and-recover-tra.md +6 -0
  486. package/corpus/templates/clips/changelog/2026-07-10-recording-pause-and-resume-controls-now-respond-reliably-on-.md +6 -0
  487. package/corpus/templates/clips/changelog/2026-07-10-starting-and-joining-a-meeting-now-closes-the-desktop-popover.md +6 -0
  488. package/corpus/templates/clips/changelog/2026-07-10-timestamped-comments-now-appear-over-the-video-as-playback-r.md +6 -0
  489. package/corpus/templates/clips/changelog/2026-07-10-transcript-backed-titles-and-summaries-now-finish-after-recording.md +6 -0
  490. package/corpus/templates/clips/changelog/2026-07-10-zoom-meetings-now-open-directly-in-the-desktop-app.md +6 -0
  491. package/corpus/templates/clips/chrome-extension/src/overlay.ts +49 -7
  492. package/corpus/templates/clips/desktop/src/app.tsx +70 -42
  493. package/corpus/templates/clips/desktop/src/hooks/useMeetingTranscription.ts +8 -14
  494. package/corpus/templates/clips/desktop/src/lib/meeting-join-url.ts +33 -0
  495. package/corpus/templates/clips/desktop/src/lib/pause-transition.ts +79 -0
  496. package/corpus/templates/clips/desktop/src/lib/pill-interaction.ts +19 -0
  497. package/corpus/templates/clips/desktop/src/lib/recorder.ts +90 -39
  498. package/corpus/templates/clips/desktop/src/lib/transcription-engine.ts +3 -2
  499. package/corpus/templates/clips/desktop/src/overlays/meeting-notification.tsx +3 -2
  500. package/corpus/templates/clips/desktop/src/overlays/recording-pill.tsx +32 -6
  501. package/corpus/templates/clips/desktop/src/overlays/toolbar.tsx +50 -5
  502. package/corpus/templates/clips/desktop/src/styles.css +11 -19
  503. package/corpus/templates/clips/desktop/src-tauri/src/lib.rs +2 -1
  504. package/corpus/templates/clips/desktop/src-tauri/src/native_screen.rs +121 -4
  505. package/corpus/templates/clips/desktop/src-tauri/src/native_speech.rs +97 -17
  506. package/corpus/templates/clips/desktop/src-tauri/src/whisper_speech.rs +80 -5
  507. package/corpus/templates/clips/desktop/src-tauri/tauri.conf.json +1 -1
  508. package/corpus/templates/clips/vitest.config.ts +23 -0
  509. package/corpus/templates/content/app/components/editor/DocumentEditor.tsx +28 -9
  510. package/corpus/templates/content/changelog/2026-07-10-open-documents-no-longer-make-constant-background-requests-w.md +6 -0
  511. package/corpus/templates/design/.agents/skills/design-systems/SKILL.md +21 -4
  512. package/corpus/templates/design/AGENTS.md +7 -0
  513. package/corpus/templates/design/app/components/design/DesignCanvas.tsx +132 -7
  514. package/corpus/templates/design/app/components/design/MultiScreenCanvas.tsx +73 -18
  515. package/corpus/templates/design/app/components/design/bridge/editor-chrome.bridge.ts +6 -1
  516. package/corpus/templates/design/app/components/design/multi-screen/frame-geometry.ts +135 -5
  517. package/corpus/templates/design/app/lib/clipboard-content-lineage.ts +64 -0
  518. package/corpus/templates/design/app/lib/design-clipboard-managed-styles.ts +247 -0
  519. package/corpus/templates/design/app/lib/design-clipboard.ts +60 -3
  520. package/corpus/templates/design/app/lib/design-import.ts +31 -3
  521. package/corpus/templates/design/app/pages/design-editor/latest-write-queue.ts +56 -0
  522. package/corpus/templates/design/app/pages/design-editor/performance-buffer-guard.ts +80 -0
  523. package/corpus/templates/design/changelog/2026-07-10-concurrent-agent-and-artboard-edits-no-longer-show-misleadin.md +6 -0
  524. package/corpus/templates/design/changelog/2026-07-10-designs-with-html-examples-inside-alpine-attributes-or-comme.md +6 -0
  525. package/corpus/templates/design/changelog/2026-07-10-interactive-designs-no-longer-appear-blank-in-the-canvas-whe.md +6 -0
  526. package/corpus/templates/design/changelog/2026-07-10-long-overview-editing-sessions-lots-of-pan-zoom-screen-switc.md +6 -0
  527. package/corpus/templates/design/changelog/2026-07-10-rapid-breakpoint-and-edit-scope-changes-no-longer-jump-back-.md +6 -0
  528. package/corpus/templates/design/changelog/2026-07-10-responsive-breakpoint-previews-stay-visible-while-panning-ac.md +6 -0
  529. package/corpus/templates/design/changelog/2026-07-10-rich-design-clipboard-markers-are-now-accepted-only-from-the.md +6 -0
  530. package/corpus/templates/design/e2e/helpers.ts +16 -5
  531. package/corpus/templates/design/server/source-workspace.ts +28 -2
  532. package/corpus/templates/design/shared/html-integrity.ts +119 -24
  533. package/corpus/templates/dispatch/AGENTS.md +10 -2
  534. package/corpus/templates/dispatch/actions/view-screen.ts +11 -0
  535. package/corpus/templates/dispatch/app/hooks/use-navigation-state.ts +13 -0
  536. package/corpus/templates/dispatch/app/i18n/zh-TW.ts +3 -0
  537. package/corpus/templates/dispatch/app/i18n-data.ts +37 -1
  538. package/corpus/templates/dispatch/app/routes/operations.tsx +1 -0
  539. package/corpus/templates/dispatch/changelog/2026-07-10-dispatch-now-has-a-cleaner-chat-history-and-quieter-sidebar-.md +6 -0
  540. package/corpus/templates/dispatch/changelog/2026-07-10-operations-console-brings-agent-monitoring-and-database-inspection-tog.md +6 -0
  541. package/corpus/templates/mail/actions/get-integration-statuses.ts +36 -0
  542. package/corpus/templates/mail/app/components/email/EmailThread.tsx +3 -2
  543. package/corpus/templates/mail/app/components/email/IntegrationsSidebar.tsx +3 -3
  544. package/corpus/templates/mail/app/hooks/use-apollo.ts +5 -71
  545. package/corpus/templates/mail/app/hooks/use-draft-queue.ts +1 -1
  546. package/corpus/templates/mail/app/hooks/use-integrations.ts +51 -48
  547. package/corpus/templates/mail/app/lib/integration-status.ts +31 -0
  548. package/corpus/templates/mail/app/lib/sync-invalidation.ts +5 -0
  549. package/corpus/templates/mail/app/pages/SettingsPage.tsx +3 -0
  550. package/corpus/templates/mail/app/root.tsx +22 -12
  551. package/corpus/templates/mail/changelog/2026-07-10-email-content-backgrounds-now-blend-cleanly-with-dark-mode.md +6 -0
  552. package/corpus/templates/mail/changelog/2026-07-10-mail-settings-now-group-drafting-automation-and-connected-se.md +6 -0
  553. package/corpus/templates/mail/changelog/2026-07-10-organization-settings-now-opens-directly-from-the-workspace-.md +6 -0
  554. package/dist/agent/context-xray/tokenize.d.ts.map +1 -1
  555. package/dist/agent/context-xray/tokenize.js +6 -1
  556. package/dist/agent/context-xray/tokenize.js.map +1 -1
  557. package/dist/agent/engine/ai-sdk-engine.d.ts.map +1 -1
  558. package/dist/agent/engine/ai-sdk-engine.js +8 -3
  559. package/dist/agent/engine/ai-sdk-engine.js.map +1 -1
  560. package/dist/agent/engine/anthropic-engine.d.ts.map +1 -1
  561. package/dist/agent/engine/anthropic-engine.js +2 -4
  562. package/dist/agent/engine/anthropic-engine.js.map +1 -1
  563. package/dist/agent/engine/builder-engine.d.ts +1 -1
  564. package/dist/agent/engine/builder-engine.d.ts.map +1 -1
  565. package/dist/agent/engine/builder-engine.js +2 -3
  566. package/dist/agent/engine/builder-engine.js.map +1 -1
  567. package/dist/agent/engine/index.d.ts +1 -1
  568. package/dist/agent/engine/index.d.ts.map +1 -1
  569. package/dist/agent/engine/index.js +1 -1
  570. package/dist/agent/engine/index.js.map +1 -1
  571. package/dist/agent/engine/registry.d.ts +13 -0
  572. package/dist/agent/engine/registry.d.ts.map +1 -1
  573. package/dist/agent/engine/registry.js +33 -0
  574. package/dist/agent/engine/registry.js.map +1 -1
  575. package/dist/agent/harness/ai-sdk-adapter.d.ts.map +1 -1
  576. package/dist/agent/harness/ai-sdk-adapter.js +3 -1
  577. package/dist/agent/harness/ai-sdk-adapter.js.map +1 -1
  578. package/dist/agent/harness/background.d.ts +9 -9
  579. package/dist/agent/harness/background.d.ts.map +1 -1
  580. package/dist/agent/harness/background.js +77 -19
  581. package/dist/agent/harness/background.js.map +1 -1
  582. package/dist/agent/harness/index.d.ts +1 -0
  583. package/dist/agent/harness/index.d.ts.map +1 -1
  584. package/dist/agent/harness/index.js +1 -0
  585. package/dist/agent/harness/index.js.map +1 -1
  586. package/dist/agent/harness/lifecycle.d.ts +45 -0
  587. package/dist/agent/harness/lifecycle.d.ts.map +1 -0
  588. package/dist/agent/harness/lifecycle.js +318 -0
  589. package/dist/agent/harness/lifecycle.js.map +1 -0
  590. package/dist/agent/harness/runner.d.ts.map +1 -1
  591. package/dist/agent/harness/runner.js +29 -1
  592. package/dist/agent/harness/runner.js.map +1 -1
  593. package/dist/agent/harness/store.d.ts +2 -0
  594. package/dist/agent/harness/store.d.ts.map +1 -1
  595. package/dist/agent/harness/store.js +17 -3
  596. package/dist/agent/harness/store.js.map +1 -1
  597. package/dist/agent/model-config.d.ts +2 -2
  598. package/dist/agent/model-config.d.ts.map +1 -1
  599. package/dist/agent/model-config.js +4 -1
  600. package/dist/agent/model-config.js.map +1 -1
  601. package/dist/agent/production-agent.d.ts +38 -0
  602. package/dist/agent/production-agent.d.ts.map +1 -1
  603. package/dist/agent/production-agent.js +135 -4
  604. package/dist/agent/production-agent.js.map +1 -1
  605. package/dist/agent/run-manager.d.ts.map +1 -1
  606. package/dist/agent/run-manager.js.map +1 -1
  607. package/dist/application-state/index.d.ts +1 -1
  608. package/dist/application-state/index.d.ts.map +1 -1
  609. package/dist/application-state/index.js +1 -1
  610. package/dist/application-state/index.js.map +1 -1
  611. package/dist/application-state/store.d.ts +6 -0
  612. package/dist/application-state/store.d.ts.map +1 -1
  613. package/dist/application-state/store.js +31 -0
  614. package/dist/application-state/store.js.map +1 -1
  615. package/dist/cli/code-agent-connector.d.ts +9 -0
  616. package/dist/cli/code-agent-connector.d.ts.map +1 -1
  617. package/dist/cli/code-agent-connector.js +212 -10
  618. package/dist/cli/code-agent-connector.js.map +1 -1
  619. package/dist/cli/code-agent-executor.d.ts +2 -0
  620. package/dist/cli/code-agent-executor.d.ts.map +1 -1
  621. package/dist/cli/code-agent-executor.js +8 -1
  622. package/dist/cli/code-agent-executor.js.map +1 -1
  623. package/dist/client/AgentPanel.d.ts.map +1 -1
  624. package/dist/client/AgentPanel.js +6 -5
  625. package/dist/client/AgentPanel.js.map +1 -1
  626. package/dist/client/AssistantChat.d.ts +6 -0
  627. package/dist/client/AssistantChat.d.ts.map +1 -1
  628. package/dist/client/AssistantChat.js +34 -4
  629. package/dist/client/AssistantChat.js.map +1 -1
  630. package/dist/client/MultiTabAssistantChat.d.ts.map +1 -1
  631. package/dist/client/MultiTabAssistantChat.js +16 -37
  632. package/dist/client/MultiTabAssistantChat.js.map +1 -1
  633. package/dist/client/appearance.d.ts +4 -2
  634. package/dist/client/appearance.d.ts.map +1 -1
  635. package/dist/client/appearance.js +8 -5
  636. package/dist/client/appearance.js.map +1 -1
  637. package/dist/client/chat/connectors.d.ts.map +1 -1
  638. package/dist/client/chat/connectors.js +206 -28
  639. package/dist/client/chat/connectors.js.map +1 -1
  640. package/dist/client/chat/message-components.d.ts.map +1 -1
  641. package/dist/client/chat/message-components.js +17 -1
  642. package/dist/client/chat/message-components.js.map +1 -1
  643. package/dist/client/chat/runtime.d.ts.map +1 -1
  644. package/dist/client/chat/runtime.js +84 -24
  645. package/dist/client/chat/runtime.js.map +1 -1
  646. package/dist/client/chat/tool-call-display.d.ts +8 -1
  647. package/dist/client/chat/tool-call-display.d.ts.map +1 -1
  648. package/dist/client/chat/tool-call-display.js +21 -3
  649. package/dist/client/chat/tool-call-display.js.map +1 -1
  650. package/dist/client/composer/RealtimeVoiceMode.d.ts +54 -0
  651. package/dist/client/composer/RealtimeVoiceMode.d.ts.map +1 -0
  652. package/dist/client/composer/RealtimeVoiceMode.js +63 -0
  653. package/dist/client/composer/RealtimeVoiceMode.js.map +1 -0
  654. package/dist/client/composer/TiptapComposer.d.ts +1 -0
  655. package/dist/client/composer/TiptapComposer.d.ts.map +1 -1
  656. package/dist/client/composer/TiptapComposer.js +17 -20
  657. package/dist/client/composer/TiptapComposer.js.map +1 -1
  658. package/dist/client/composer/VoiceButton.d.ts.map +1 -1
  659. package/dist/client/composer/VoiceButton.js +9 -0
  660. package/dist/client/composer/VoiceButton.js.map +1 -1
  661. package/dist/client/composer/index.d.ts +2 -0
  662. package/dist/client/composer/index.d.ts.map +1 -1
  663. package/dist/client/composer/index.js +2 -0
  664. package/dist/client/composer/index.js.map +1 -1
  665. package/dist/client/composer/useRealtimeVoiceMode.d.ts +56 -0
  666. package/dist/client/composer/useRealtimeVoiceMode.d.ts.map +1 -0
  667. package/dist/client/composer/useRealtimeVoiceMode.js +492 -0
  668. package/dist/client/composer/useRealtimeVoiceMode.js.map +1 -0
  669. package/dist/client/guided-questions.d.ts.map +1 -1
  670. package/dist/client/guided-questions.js +7 -2
  671. package/dist/client/guided-questions.js.map +1 -1
  672. package/dist/client/index.d.ts +1 -1
  673. package/dist/client/index.d.ts.map +1 -1
  674. package/dist/client/index.js +1 -1
  675. package/dist/client/index.js.map +1 -1
  676. package/dist/client/settings/DemoModeSection.d.ts.map +1 -1
  677. package/dist/client/settings/DemoModeSection.js +4 -3
  678. package/dist/client/settings/DemoModeSection.js.map +1 -1
  679. package/dist/client/settings/SettingsPanel.d.ts.map +1 -1
  680. package/dist/client/settings/SettingsPanel.js +4 -0
  681. package/dist/client/settings/SettingsPanel.js.map +1 -1
  682. package/dist/client/settings/SettingsTabsPage.d.ts +10 -3
  683. package/dist/client/settings/SettingsTabsPage.d.ts.map +1 -1
  684. package/dist/client/settings/SettingsTabsPage.js +49 -11
  685. package/dist/client/settings/SettingsTabsPage.js.map +1 -1
  686. package/dist/client/use-chat-models.d.ts.map +1 -1
  687. package/dist/client/use-chat-models.js +6 -14
  688. package/dist/client/use-chat-models.js.map +1 -1
  689. package/dist/client/use-db-sync.d.ts.map +1 -1
  690. package/dist/client/use-db-sync.js +87 -7
  691. package/dist/client/use-db-sync.js.map +1 -1
  692. package/dist/code-agents/background-controller.d.ts +1 -1
  693. package/dist/code-agents/background-controller.d.ts.map +1 -1
  694. package/dist/code-agents/background-controller.js +17 -1
  695. package/dist/code-agents/background-controller.js.map +1 -1
  696. package/dist/collab/routes.d.ts +1 -1
  697. package/dist/collab/struct-routes.d.ts +1 -1
  698. package/dist/collab/ydoc-manager.d.ts +9 -1
  699. package/dist/collab/ydoc-manager.d.ts.map +1 -1
  700. package/dist/collab/ydoc-manager.js +30 -6
  701. package/dist/collab/ydoc-manager.js.map +1 -1
  702. package/dist/db/migrations.d.ts.map +1 -1
  703. package/dist/db/migrations.js +4 -2
  704. package/dist/db/migrations.js.map +1 -1
  705. package/dist/demo/fetch-interceptor.d.ts +5 -1
  706. package/dist/demo/fetch-interceptor.d.ts.map +1 -1
  707. package/dist/demo/fetch-interceptor.js +16 -12
  708. package/dist/demo/fetch-interceptor.js.map +1 -1
  709. package/dist/integrations/adapters/slack.d.ts +2 -0
  710. package/dist/integrations/adapters/slack.d.ts.map +1 -1
  711. package/dist/integrations/adapters/slack.js +38 -2
  712. package/dist/integrations/adapters/slack.js.map +1 -1
  713. package/dist/integrations/awaiting-input-store.d.ts +27 -0
  714. package/dist/integrations/awaiting-input-store.d.ts.map +1 -0
  715. package/dist/integrations/awaiting-input-store.js +112 -0
  716. package/dist/integrations/awaiting-input-store.js.map +1 -0
  717. package/dist/integrations/computer-supervision-store.d.ts +65 -0
  718. package/dist/integrations/computer-supervision-store.d.ts.map +1 -0
  719. package/dist/integrations/computer-supervision-store.js +296 -0
  720. package/dist/integrations/computer-supervision-store.js.map +1 -0
  721. package/dist/integrations/computer-supervision.d.ts +11 -0
  722. package/dist/integrations/computer-supervision.d.ts.map +1 -0
  723. package/dist/integrations/computer-supervision.js +160 -0
  724. package/dist/integrations/computer-supervision.js.map +1 -0
  725. package/dist/integrations/index.d.ts +6 -3
  726. package/dist/integrations/index.d.ts.map +1 -1
  727. package/dist/integrations/index.js +5 -2
  728. package/dist/integrations/index.js.map +1 -1
  729. package/dist/integrations/plugin.d.ts.map +1 -1
  730. package/dist/integrations/plugin.js +205 -3
  731. package/dist/integrations/plugin.js.map +1 -1
  732. package/dist/integrations/remote-commands-store.d.ts +15 -1
  733. package/dist/integrations/remote-commands-store.d.ts.map +1 -1
  734. package/dist/integrations/remote-commands-store.js +273 -3
  735. package/dist/integrations/remote-commands-store.js.map +1 -1
  736. package/dist/integrations/remote-devices-store.d.ts +4 -3
  737. package/dist/integrations/remote-devices-store.d.ts.map +1 -1
  738. package/dist/integrations/remote-devices-store.js +49 -2
  739. package/dist/integrations/remote-devices-store.js.map +1 -1
  740. package/dist/integrations/remote-json-safety.d.ts +6 -0
  741. package/dist/integrations/remote-json-safety.d.ts.map +1 -0
  742. package/dist/integrations/remote-json-safety.js +114 -0
  743. package/dist/integrations/remote-json-safety.js.map +1 -0
  744. package/dist/integrations/remote-run-events-store.d.ts +11 -1
  745. package/dist/integrations/remote-run-events-store.d.ts.map +1 -1
  746. package/dist/integrations/remote-run-events-store.js +85 -17
  747. package/dist/integrations/remote-run-events-store.js.map +1 -1
  748. package/dist/integrations/remote-types.d.ts +54 -3
  749. package/dist/integrations/remote-types.d.ts.map +1 -1
  750. package/dist/integrations/remote-types.js.map +1 -1
  751. package/dist/integrations/webhook-handler.d.ts.map +1 -1
  752. package/dist/integrations/webhook-handler.js +133 -4
  753. package/dist/integrations/webhook-handler.js.map +1 -1
  754. package/dist/localization/default-messages.d.ts +26 -0
  755. package/dist/localization/default-messages.d.ts.map +1 -1
  756. package/dist/localization/default-messages.js +26 -0
  757. package/dist/localization/default-messages.js.map +1 -1
  758. package/dist/mcp-client/config.d.ts.map +1 -1
  759. package/dist/mcp-client/config.js +44 -3
  760. package/dist/mcp-client/config.js.map +1 -1
  761. package/dist/mcp-client/index.d.ts +6 -1
  762. package/dist/mcp-client/index.d.ts.map +1 -1
  763. package/dist/mcp-client/index.js +11 -3
  764. package/dist/mcp-client/index.js.map +1 -1
  765. package/dist/mcp-client/tool-policy.d.ts +24 -0
  766. package/dist/mcp-client/tool-policy.d.ts.map +1 -0
  767. package/dist/mcp-client/tool-policy.js +139 -0
  768. package/dist/mcp-client/tool-policy.js.map +1 -0
  769. package/dist/observability/routes.d.ts +5 -5
  770. package/dist/resources/handlers.d.ts +3 -3
  771. package/dist/secrets/register-framework-secrets.d.ts +3 -4
  772. package/dist/secrets/register-framework-secrets.d.ts.map +1 -1
  773. package/dist/secrets/register-framework-secrets.js +25 -4
  774. package/dist/secrets/register-framework-secrets.js.map +1 -1
  775. package/dist/secrets/routes.d.ts +9 -9
  776. package/dist/server/agent-chat-plugin.d.ts.map +1 -1
  777. package/dist/server/agent-chat-plugin.js +53 -6
  778. package/dist/server/agent-chat-plugin.js.map +1 -1
  779. package/dist/server/index.d.ts +2 -1
  780. package/dist/server/index.d.ts.map +1 -1
  781. package/dist/server/index.js +2 -1
  782. package/dist/server/index.js.map +1 -1
  783. package/dist/server/realtime-voice.d.ts +53 -0
  784. package/dist/server/realtime-voice.d.ts.map +1 -0
  785. package/dist/server/realtime-voice.js +404 -0
  786. package/dist/server/realtime-voice.js.map +1 -0
  787. package/dist/shared/reasoning-effort.d.ts +20 -0
  788. package/dist/shared/reasoning-effort.d.ts.map +1 -1
  789. package/dist/shared/reasoning-effort.js +52 -18
  790. package/dist/shared/reasoning-effort.js.map +1 -1
  791. package/dist/styles/agent-conversation.css +17 -0
  792. package/dist/templates/workspace-core/.agents/skills/voice-transcription/SKILL.md +39 -5
  793. package/docs/content/a2a-protocol.mdx +21 -5
  794. package/docs/content/actions.mdx +9 -23
  795. package/docs/content/agent-mentions.mdx +31 -29
  796. package/docs/content/agent-native-toolkit.mdx +15 -6
  797. package/docs/content/agent-surfaces.mdx +9 -13
  798. package/docs/content/agent-teams.mdx +1 -0
  799. package/docs/content/authentication.mdx +10 -3
  800. package/docs/content/automation-connectors.mdx +82 -39
  801. package/docs/content/automations.mdx +17 -3
  802. package/docs/content/blueprint-installer.mdx +11 -4
  803. package/docs/content/cli-adapters.mdx +9 -6
  804. package/docs/content/client.mdx +16 -0
  805. package/docs/content/cloneable-saas.mdx +14 -11
  806. package/docs/content/code-agents-ui.mdx +65 -0
  807. package/docs/content/components.mdx +30 -14
  808. package/docs/content/context-awareness.mdx +27 -15
  809. package/docs/content/creating-templates.mdx +15 -9
  810. package/docs/content/cross-app-sso.mdx +16 -6
  811. package/docs/content/data-programs.mdx +1 -1
  812. package/docs/content/database.mdx +17 -5
  813. package/docs/content/deployment.mdx +19 -18
  814. package/docs/content/dispatch.mdx +6 -2
  815. package/docs/content/drop-in-agent.mdx +10 -4
  816. package/docs/content/durable-background-runs.mdx +9 -5
  817. package/docs/content/durable-resume.mdx +9 -4
  818. package/docs/content/embedding-sdk.mdx +26 -8
  819. package/docs/content/evals.mdx +3 -5
  820. package/docs/content/extensions.mdx +22 -9
  821. package/docs/content/external-agents.mdx +25 -34
  822. package/docs/content/faq.mdx +8 -0
  823. package/docs/content/file-uploads.mdx +12 -3
  824. package/docs/content/frames.mdx +16 -0
  825. package/docs/content/generative-ui.mdx +1 -1
  826. package/docs/content/getting-started.mdx +34 -21
  827. package/docs/content/harness-agents.mdx +8 -4
  828. package/docs/content/human-approval.mdx +8 -3
  829. package/docs/content/internationalization.mdx +9 -4
  830. package/docs/content/key-concepts.mdx +13 -20
  831. package/docs/content/local-file-mode.mdx +14 -8
  832. package/docs/content/locales/ar-SA/actions.mdx +2 -2
  833. package/docs/content/locales/ar-SA/agent-native-toolkit.mdx +2 -2
  834. package/docs/content/locales/ar-SA/agent-surfaces.mdx +8 -10
  835. package/docs/content/locales/ar-SA/agent-teams.mdx +1 -0
  836. package/docs/content/locales/ar-SA/authentication.mdx +1 -1
  837. package/docs/content/locales/ar-SA/components.mdx +11 -1
  838. package/docs/content/locales/ar-SA/creating-templates.mdx +3 -7
  839. package/docs/content/locales/ar-SA/cross-app-sso.mdx +16 -6
  840. package/docs/content/locales/ar-SA/deployment.mdx +8 -0
  841. package/docs/content/locales/ar-SA/external-agents.mdx +2 -7
  842. package/docs/content/locales/ar-SA/key-concepts.mdx +13 -20
  843. package/docs/content/locales/ar-SA/multi-tenancy.mdx +5 -5
  844. package/docs/content/locales/ar-SA/notifications.mdx +18 -10
  845. package/docs/content/locales/ar-SA/processors.mdx +11 -5
  846. package/docs/content/locales/ar-SA/server.mdx +17 -10
  847. package/docs/content/locales/ar-SA/sharing.mdx +10 -10
  848. package/docs/content/locales/ar-SA/skills-guide.mdx +34 -17
  849. package/docs/content/locales/ar-SA/template-assets.mdx +16 -13
  850. package/docs/content/locales/ar-SA/template-brain.mdx +3 -1
  851. package/docs/content/locales/ar-SA/template-clips.mdx +3 -3
  852. package/docs/content/locales/ar-SA/template-design.mdx +3 -1
  853. package/docs/content/locales/ar-SA/template-dispatch.mdx +5 -1
  854. package/docs/content/locales/ar-SA/template-mail.mdx +8 -0
  855. package/docs/content/locales/ar-SA/tracking.mdx +9 -6
  856. package/docs/content/locales/ar-SA/using-your-agent.mdx +0 -7
  857. package/docs/content/locales/ar-SA/voice-input.mdx +6 -0
  858. package/docs/content/locales/ar-SA/workspace-connections.mdx +9 -2
  859. package/docs/content/locales/ar-SA/workspace.mdx +19 -18
  860. package/docs/content/locales/de-DE/actions.mdx +2 -2
  861. package/docs/content/locales/de-DE/agent-native-toolkit.mdx +2 -2
  862. package/docs/content/locales/de-DE/agent-surfaces.mdx +8 -10
  863. package/docs/content/locales/de-DE/agent-teams.mdx +1 -0
  864. package/docs/content/locales/de-DE/authentication.mdx +1 -1
  865. package/docs/content/locales/de-DE/components.mdx +11 -1
  866. package/docs/content/locales/de-DE/creating-templates.mdx +3 -7
  867. package/docs/content/locales/de-DE/cross-app-sso.mdx +16 -6
  868. package/docs/content/locales/de-DE/deployment.mdx +8 -0
  869. package/docs/content/locales/de-DE/external-agents.mdx +3 -7
  870. package/docs/content/locales/de-DE/key-concepts.mdx +13 -20
  871. package/docs/content/locales/de-DE/multi-tenancy.mdx +5 -5
  872. package/docs/content/locales/de-DE/notifications.mdx +18 -10
  873. package/docs/content/locales/de-DE/processors.mdx +11 -5
  874. package/docs/content/locales/de-DE/server.mdx +18 -10
  875. package/docs/content/locales/de-DE/sharing.mdx +10 -10
  876. package/docs/content/locales/de-DE/skills-guide.mdx +34 -17
  877. package/docs/content/locales/de-DE/template-assets.mdx +16 -13
  878. package/docs/content/locales/de-DE/template-brain.mdx +3 -1
  879. package/docs/content/locales/de-DE/template-clips.mdx +3 -3
  880. package/docs/content/locales/de-DE/template-design.mdx +3 -1
  881. package/docs/content/locales/de-DE/template-dispatch.mdx +5 -1
  882. package/docs/content/locales/de-DE/template-mail.mdx +8 -0
  883. package/docs/content/locales/de-DE/tracking.mdx +9 -6
  884. package/docs/content/locales/de-DE/using-your-agent.mdx +0 -7
  885. package/docs/content/locales/de-DE/voice-input.mdx +6 -0
  886. package/docs/content/locales/de-DE/workspace-connections.mdx +9 -2
  887. package/docs/content/locales/de-DE/workspace.mdx +19 -18
  888. package/docs/content/locales/es-ES/actions.mdx +2 -2
  889. package/docs/content/locales/es-ES/agent-native-toolkit.mdx +2 -2
  890. package/docs/content/locales/es-ES/agent-surfaces.mdx +8 -10
  891. package/docs/content/locales/es-ES/agent-teams.mdx +1 -0
  892. package/docs/content/locales/es-ES/authentication.mdx +1 -1
  893. package/docs/content/locales/es-ES/components.mdx +11 -1
  894. package/docs/content/locales/es-ES/creating-templates.mdx +3 -7
  895. package/docs/content/locales/es-ES/cross-app-sso.mdx +16 -6
  896. package/docs/content/locales/es-ES/deployment.mdx +8 -0
  897. package/docs/content/locales/es-ES/external-agents.mdx +3 -7
  898. package/docs/content/locales/es-ES/key-concepts.mdx +13 -20
  899. package/docs/content/locales/es-ES/multi-tenancy.mdx +5 -5
  900. package/docs/content/locales/es-ES/notifications.mdx +18 -10
  901. package/docs/content/locales/es-ES/processors.mdx +11 -5
  902. package/docs/content/locales/es-ES/server.mdx +17 -10
  903. package/docs/content/locales/es-ES/sharing.mdx +10 -10
  904. package/docs/content/locales/es-ES/skills-guide.mdx +34 -17
  905. package/docs/content/locales/es-ES/template-assets.mdx +16 -13
  906. package/docs/content/locales/es-ES/template-brain.mdx +3 -1
  907. package/docs/content/locales/es-ES/template-clips.mdx +3 -3
  908. package/docs/content/locales/es-ES/template-design.mdx +3 -1
  909. package/docs/content/locales/es-ES/template-dispatch.mdx +5 -1
  910. package/docs/content/locales/es-ES/template-mail.mdx +8 -0
  911. package/docs/content/locales/es-ES/tracking.mdx +9 -6
  912. package/docs/content/locales/es-ES/using-your-agent.mdx +0 -7
  913. package/docs/content/locales/es-ES/voice-input.mdx +6 -0
  914. package/docs/content/locales/es-ES/workspace-connections.mdx +9 -2
  915. package/docs/content/locales/es-ES/workspace.mdx +19 -18
  916. package/docs/content/locales/fr-FR/actions.mdx +2 -2
  917. package/docs/content/locales/fr-FR/agent-native-toolkit.mdx +2 -2
  918. package/docs/content/locales/fr-FR/agent-surfaces.mdx +8 -10
  919. package/docs/content/locales/fr-FR/agent-teams.mdx +1 -0
  920. package/docs/content/locales/fr-FR/authentication.mdx +1 -1
  921. package/docs/content/locales/fr-FR/components.mdx +11 -1
  922. package/docs/content/locales/fr-FR/creating-templates.mdx +3 -7
  923. package/docs/content/locales/fr-FR/cross-app-sso.mdx +16 -6
  924. package/docs/content/locales/fr-FR/deployment.mdx +8 -0
  925. package/docs/content/locales/fr-FR/external-agents.mdx +3 -7
  926. package/docs/content/locales/fr-FR/key-concepts.mdx +13 -20
  927. package/docs/content/locales/fr-FR/multi-tenancy.mdx +5 -5
  928. package/docs/content/locales/fr-FR/notifications.mdx +18 -10
  929. package/docs/content/locales/fr-FR/processors.mdx +11 -5
  930. package/docs/content/locales/fr-FR/server.mdx +17 -10
  931. package/docs/content/locales/fr-FR/sharing.mdx +10 -10
  932. package/docs/content/locales/fr-FR/skills-guide.mdx +34 -17
  933. package/docs/content/locales/fr-FR/template-assets.mdx +16 -13
  934. package/docs/content/locales/fr-FR/template-brain.mdx +3 -1
  935. package/docs/content/locales/fr-FR/template-clips.mdx +3 -3
  936. package/docs/content/locales/fr-FR/template-design.mdx +3 -1
  937. package/docs/content/locales/fr-FR/template-dispatch.mdx +5 -1
  938. package/docs/content/locales/fr-FR/template-mail.mdx +8 -0
  939. package/docs/content/locales/fr-FR/tracking.mdx +9 -6
  940. package/docs/content/locales/fr-FR/using-your-agent.mdx +0 -7
  941. package/docs/content/locales/fr-FR/voice-input.mdx +6 -0
  942. package/docs/content/locales/fr-FR/workspace-connections.mdx +9 -2
  943. package/docs/content/locales/fr-FR/workspace.mdx +19 -18
  944. package/docs/content/locales/hi-IN/actions.mdx +2 -2
  945. package/docs/content/locales/hi-IN/agent-native-toolkit.mdx +2 -2
  946. package/docs/content/locales/hi-IN/agent-surfaces.mdx +8 -10
  947. package/docs/content/locales/hi-IN/agent-teams.mdx +1 -0
  948. package/docs/content/locales/hi-IN/authentication.mdx +1 -1
  949. package/docs/content/locales/hi-IN/components.mdx +11 -1
  950. package/docs/content/locales/hi-IN/creating-templates.mdx +3 -7
  951. package/docs/content/locales/hi-IN/cross-app-sso.mdx +16 -6
  952. package/docs/content/locales/hi-IN/deployment.mdx +8 -0
  953. package/docs/content/locales/hi-IN/external-agents.mdx +2 -7
  954. package/docs/content/locales/hi-IN/key-concepts.mdx +13 -20
  955. package/docs/content/locales/hi-IN/multi-tenancy.mdx +5 -5
  956. package/docs/content/locales/hi-IN/notifications.mdx +18 -10
  957. package/docs/content/locales/hi-IN/processors.mdx +11 -5
  958. package/docs/content/locales/hi-IN/server.mdx +17 -10
  959. package/docs/content/locales/hi-IN/sharing.mdx +10 -10
  960. package/docs/content/locales/hi-IN/skills-guide.mdx +34 -17
  961. package/docs/content/locales/hi-IN/template-assets.mdx +16 -13
  962. package/docs/content/locales/hi-IN/template-brain.mdx +3 -1
  963. package/docs/content/locales/hi-IN/template-clips.mdx +3 -3
  964. package/docs/content/locales/hi-IN/template-design.mdx +3 -1
  965. package/docs/content/locales/hi-IN/template-dispatch.mdx +5 -1
  966. package/docs/content/locales/hi-IN/template-mail.mdx +8 -0
  967. package/docs/content/locales/hi-IN/tracking.mdx +9 -6
  968. package/docs/content/locales/hi-IN/using-your-agent.mdx +0 -7
  969. package/docs/content/locales/hi-IN/voice-input.mdx +6 -0
  970. package/docs/content/locales/hi-IN/workspace-connections.mdx +9 -2
  971. package/docs/content/locales/hi-IN/workspace.mdx +19 -18
  972. package/docs/content/locales/ja-JP/actions.mdx +2 -2
  973. package/docs/content/locales/ja-JP/agent-native-toolkit.mdx +2 -2
  974. package/docs/content/locales/ja-JP/agent-surfaces.mdx +8 -10
  975. package/docs/content/locales/ja-JP/agent-teams.mdx +1 -0
  976. package/docs/content/locales/ja-JP/authentication.mdx +1 -1
  977. package/docs/content/locales/ja-JP/components.mdx +11 -1
  978. package/docs/content/locales/ja-JP/creating-templates.mdx +3 -7
  979. package/docs/content/locales/ja-JP/cross-app-sso.mdx +16 -6
  980. package/docs/content/locales/ja-JP/deployment.mdx +8 -0
  981. package/docs/content/locales/ja-JP/external-agents.mdx +2 -7
  982. package/docs/content/locales/ja-JP/key-concepts.mdx +13 -20
  983. package/docs/content/locales/ja-JP/multi-tenancy.mdx +5 -5
  984. package/docs/content/locales/ja-JP/notifications.mdx +18 -10
  985. package/docs/content/locales/ja-JP/processors.mdx +11 -5
  986. package/docs/content/locales/ja-JP/server.mdx +17 -10
  987. package/docs/content/locales/ja-JP/sharing.mdx +10 -10
  988. package/docs/content/locales/ja-JP/skills-guide.mdx +34 -17
  989. package/docs/content/locales/ja-JP/template-assets.mdx +16 -13
  990. package/docs/content/locales/ja-JP/template-brain.mdx +3 -1
  991. package/docs/content/locales/ja-JP/template-clips.mdx +3 -4
  992. package/docs/content/locales/ja-JP/template-design.mdx +3 -1
  993. package/docs/content/locales/ja-JP/template-dispatch.mdx +5 -1
  994. package/docs/content/locales/ja-JP/template-mail.mdx +8 -0
  995. package/docs/content/locales/ja-JP/tracking.mdx +9 -6
  996. package/docs/content/locales/ja-JP/using-your-agent.mdx +0 -7
  997. package/docs/content/locales/ja-JP/voice-input.mdx +6 -0
  998. package/docs/content/locales/ja-JP/workspace-connections.mdx +9 -2
  999. package/docs/content/locales/ja-JP/workspace.mdx +19 -18
  1000. package/docs/content/locales/ko-KR/actions.mdx +2 -2
  1001. package/docs/content/locales/ko-KR/agent-native-toolkit.mdx +2 -2
  1002. package/docs/content/locales/ko-KR/agent-surfaces.mdx +8 -10
  1003. package/docs/content/locales/ko-KR/agent-teams.mdx +1 -0
  1004. package/docs/content/locales/ko-KR/authentication.mdx +1 -1
  1005. package/docs/content/locales/ko-KR/components.mdx +11 -1
  1006. package/docs/content/locales/ko-KR/creating-templates.mdx +3 -7
  1007. package/docs/content/locales/ko-KR/cross-app-sso.mdx +16 -6
  1008. package/docs/content/locales/ko-KR/deployment.mdx +8 -0
  1009. package/docs/content/locales/ko-KR/external-agents.mdx +2 -7
  1010. package/docs/content/locales/ko-KR/key-concepts.mdx +13 -20
  1011. package/docs/content/locales/ko-KR/multi-tenancy.mdx +5 -5
  1012. package/docs/content/locales/ko-KR/notifications.mdx +18 -10
  1013. package/docs/content/locales/ko-KR/processors.mdx +11 -5
  1014. package/docs/content/locales/ko-KR/server.mdx +17 -10
  1015. package/docs/content/locales/ko-KR/sharing.mdx +10 -10
  1016. package/docs/content/locales/ko-KR/skills-guide.mdx +34 -17
  1017. package/docs/content/locales/ko-KR/template-assets.mdx +16 -13
  1018. package/docs/content/locales/ko-KR/template-brain.mdx +3 -1
  1019. package/docs/content/locales/ko-KR/template-clips.mdx +3 -4
  1020. package/docs/content/locales/ko-KR/template-design.mdx +3 -1
  1021. package/docs/content/locales/ko-KR/template-dispatch.mdx +5 -1
  1022. package/docs/content/locales/ko-KR/template-mail.mdx +8 -0
  1023. package/docs/content/locales/ko-KR/tracking.mdx +9 -6
  1024. package/docs/content/locales/ko-KR/using-your-agent.mdx +0 -7
  1025. package/docs/content/locales/ko-KR/voice-input.mdx +6 -0
  1026. package/docs/content/locales/ko-KR/workspace-connections.mdx +9 -2
  1027. package/docs/content/locales/ko-KR/workspace.mdx +19 -18
  1028. package/docs/content/locales/pt-BR/actions.mdx +2 -2
  1029. package/docs/content/locales/pt-BR/agent-native-toolkit.mdx +2 -2
  1030. package/docs/content/locales/pt-BR/agent-surfaces.mdx +8 -10
  1031. package/docs/content/locales/pt-BR/agent-teams.mdx +1 -0
  1032. package/docs/content/locales/pt-BR/authentication.mdx +1 -1
  1033. package/docs/content/locales/pt-BR/components.mdx +11 -1
  1034. package/docs/content/locales/pt-BR/creating-templates.mdx +3 -7
  1035. package/docs/content/locales/pt-BR/cross-app-sso.mdx +16 -6
  1036. package/docs/content/locales/pt-BR/deployment.mdx +8 -0
  1037. package/docs/content/locales/pt-BR/external-agents.mdx +3 -7
  1038. package/docs/content/locales/pt-BR/key-concepts.mdx +13 -20
  1039. package/docs/content/locales/pt-BR/multi-tenancy.mdx +5 -5
  1040. package/docs/content/locales/pt-BR/notifications.mdx +18 -10
  1041. package/docs/content/locales/pt-BR/processors.mdx +11 -5
  1042. package/docs/content/locales/pt-BR/server.mdx +17 -10
  1043. package/docs/content/locales/pt-BR/sharing.mdx +10 -10
  1044. package/docs/content/locales/pt-BR/skills-guide.mdx +34 -17
  1045. package/docs/content/locales/pt-BR/template-assets.mdx +16 -13
  1046. package/docs/content/locales/pt-BR/template-brain.mdx +3 -1
  1047. package/docs/content/locales/pt-BR/template-clips.mdx +3 -3
  1048. package/docs/content/locales/pt-BR/template-design.mdx +3 -1
  1049. package/docs/content/locales/pt-BR/template-dispatch.mdx +5 -1
  1050. package/docs/content/locales/pt-BR/template-mail.mdx +8 -0
  1051. package/docs/content/locales/pt-BR/tracking.mdx +9 -6
  1052. package/docs/content/locales/pt-BR/using-your-agent.mdx +0 -7
  1053. package/docs/content/locales/pt-BR/voice-input.mdx +6 -0
  1054. package/docs/content/locales/pt-BR/workspace-connections.mdx +9 -2
  1055. package/docs/content/locales/pt-BR/workspace.mdx +19 -18
  1056. package/docs/content/locales/zh-CN/actions.mdx +2 -2
  1057. package/docs/content/locales/zh-CN/agent-native-toolkit.mdx +2 -2
  1058. package/docs/content/locales/zh-CN/agent-surfaces.mdx +8 -10
  1059. package/docs/content/locales/zh-CN/agent-teams.mdx +1 -0
  1060. package/docs/content/locales/zh-CN/authentication.mdx +1 -1
  1061. package/docs/content/locales/zh-CN/components.mdx +11 -1
  1062. package/docs/content/locales/zh-CN/creating-templates.mdx +3 -7
  1063. package/docs/content/locales/zh-CN/cross-app-sso.mdx +16 -6
  1064. package/docs/content/locales/zh-CN/deployment.mdx +8 -0
  1065. package/docs/content/locales/zh-CN/external-agents.mdx +2 -7
  1066. package/docs/content/locales/zh-CN/key-concepts.mdx +13 -20
  1067. package/docs/content/locales/zh-CN/multi-tenancy.mdx +5 -5
  1068. package/docs/content/locales/zh-CN/notifications.mdx +18 -10
  1069. package/docs/content/locales/zh-CN/processors.mdx +11 -5
  1070. package/docs/content/locales/zh-CN/server.mdx +16 -10
  1071. package/docs/content/locales/zh-CN/sharing.mdx +10 -10
  1072. package/docs/content/locales/zh-CN/skills-guide.mdx +34 -17
  1073. package/docs/content/locales/zh-CN/template-assets.mdx +16 -13
  1074. package/docs/content/locales/zh-CN/template-brain.mdx +3 -1
  1075. package/docs/content/locales/zh-CN/template-clips.mdx +3 -4
  1076. package/docs/content/locales/zh-CN/template-design.mdx +3 -1
  1077. package/docs/content/locales/zh-CN/template-dispatch.mdx +5 -1
  1078. package/docs/content/locales/zh-CN/template-mail.mdx +8 -0
  1079. package/docs/content/locales/zh-CN/tracking.mdx +9 -6
  1080. package/docs/content/locales/zh-CN/using-your-agent.mdx +0 -7
  1081. package/docs/content/locales/zh-CN/voice-input.mdx +6 -0
  1082. package/docs/content/locales/zh-CN/workspace-connections.mdx +9 -2
  1083. package/docs/content/locales/zh-CN/workspace.mdx +19 -18
  1084. package/docs/content/locales/zh-TW/actions.mdx +2 -2
  1085. package/docs/content/locales/zh-TW/agent-native-toolkit.mdx +2 -2
  1086. package/docs/content/locales/zh-TW/agent-surfaces.mdx +8 -10
  1087. package/docs/content/locales/zh-TW/agent-teams.mdx +1 -0
  1088. package/docs/content/locales/zh-TW/authentication.mdx +1 -1
  1089. package/docs/content/locales/zh-TW/components.mdx +11 -1
  1090. package/docs/content/locales/zh-TW/creating-templates.mdx +3 -7
  1091. package/docs/content/locales/zh-TW/cross-app-sso.mdx +16 -6
  1092. package/docs/content/locales/zh-TW/deployment.mdx +8 -0
  1093. package/docs/content/locales/zh-TW/external-agents.mdx +2 -7
  1094. package/docs/content/locales/zh-TW/key-concepts.mdx +13 -20
  1095. package/docs/content/locales/zh-TW/multi-tenancy.mdx +5 -5
  1096. package/docs/content/locales/zh-TW/notifications.mdx +18 -10
  1097. package/docs/content/locales/zh-TW/processors.mdx +11 -5
  1098. package/docs/content/locales/zh-TW/server.mdx +16 -10
  1099. package/docs/content/locales/zh-TW/sharing.mdx +10 -10
  1100. package/docs/content/locales/zh-TW/skills-guide.mdx +34 -17
  1101. package/docs/content/locales/zh-TW/template-assets.mdx +16 -13
  1102. package/docs/content/locales/zh-TW/template-brain.mdx +3 -1
  1103. package/docs/content/locales/zh-TW/template-clips.mdx +3 -4
  1104. package/docs/content/locales/zh-TW/template-design.mdx +3 -1
  1105. package/docs/content/locales/zh-TW/template-dispatch.mdx +5 -1
  1106. package/docs/content/locales/zh-TW/template-mail.mdx +8 -0
  1107. package/docs/content/locales/zh-TW/tracking.mdx +9 -6
  1108. package/docs/content/locales/zh-TW/using-your-agent.mdx +0 -7
  1109. package/docs/content/locales/zh-TW/voice-input.mdx +6 -0
  1110. package/docs/content/locales/zh-TW/workspace-connections.mdx +9 -2
  1111. package/docs/content/locales/zh-TW/workspace.mdx +19 -18
  1112. package/docs/content/mcp-apps.mdx +14 -32
  1113. package/docs/content/mcp-clients.mdx +48 -54
  1114. package/docs/content/mcp-protocol.mdx +25 -10
  1115. package/docs/content/messaging.mdx +19 -11
  1116. package/docs/content/multi-app-workspace.mdx +11 -96
  1117. package/docs/content/multi-tenancy.mdx +5 -5
  1118. package/docs/content/native-chat-ui.mdx +4 -4
  1119. package/docs/content/notifications.mdx +19 -12
  1120. package/docs/content/observability.mdx +2 -4
  1121. package/docs/content/observational-memory.mdx +7 -3
  1122. package/docs/content/onboarding.mdx +9 -2
  1123. package/docs/content/plan-plugin.mdx +10 -2
  1124. package/docs/content/pr-visual-recap.mdx +1 -1
  1125. package/docs/content/processors.mdx +11 -5
  1126. package/docs/content/pure-agent-apps.mdx +5 -1
  1127. package/docs/content/real-time-collaboration.mdx +30 -67
  1128. package/docs/content/recurring-jobs.mdx +8 -6
  1129. package/docs/content/routing.mdx +3 -4
  1130. package/docs/content/sandbox-adapters.mdx +30 -53
  1131. package/docs/content/security.mdx +8 -0
  1132. package/docs/content/server.mdx +17 -10
  1133. package/docs/content/sharing.mdx +10 -10
  1134. package/docs/content/skills-guide.mdx +35 -16
  1135. package/docs/content/template-analytics.mdx +11 -8
  1136. package/docs/content/template-assets.mdx +16 -13
  1137. package/docs/content/template-brain.mdx +3 -1
  1138. package/docs/content/template-calendar.mdx +12 -4
  1139. package/docs/content/template-chat.mdx +4 -4
  1140. package/docs/content/template-clips.mdx +3 -3
  1141. package/docs/content/template-content.mdx +23 -18
  1142. package/docs/content/template-design.mdx +3 -1
  1143. package/docs/content/template-dispatch.mdx +5 -1
  1144. package/docs/content/template-mail.mdx +14 -2
  1145. package/docs/content/template-plan.mdx +22 -15
  1146. package/docs/content/template-slides.mdx +11 -3
  1147. package/docs/content/toolkit-agent-ux.mdx +46 -3
  1148. package/docs/content/toolkit-collaboration.mdx +58 -4
  1149. package/docs/content/toolkit-command-navigation.mdx +8 -2
  1150. package/docs/content/toolkit-comments-review.mdx +10 -2
  1151. package/docs/content/toolkit-history.mdx +8 -3
  1152. package/docs/content/toolkit-observability.mdx +48 -2
  1153. package/docs/content/toolkit-org-team.mdx +8 -2
  1154. package/docs/content/toolkit-resources.mdx +45 -2
  1155. package/docs/content/toolkit-settings.mdx +8 -2
  1156. package/docs/content/toolkit-setup-connections.mdx +7 -2
  1157. package/docs/content/toolkit-sharing.mdx +46 -3
  1158. package/docs/content/toolkit-ui.mdx +82 -11
  1159. package/docs/content/tracking.mdx +10 -8
  1160. package/docs/content/using-your-agent.mdx +0 -12
  1161. package/docs/content/voice-input.mdx +7 -1
  1162. package/docs/content/what-is-agent-native.mdx +7 -8
  1163. package/docs/content/workspace-connections.mdx +16 -23
  1164. package/docs/content/workspace-management.mdx +16 -4
  1165. package/docs/content/workspace.mdx +19 -18
  1166. package/package.json +1 -1
  1167. package/src/templates/workspace-core/.agents/skills/voice-transcription/SKILL.md +39 -5
  1168. package/corpus/core/docs/content/locales/ar-SA/migration-workbench.mdx +0 -76
  1169. package/corpus/core/docs/content/locales/de-DE/migration-workbench.mdx +0 -76
  1170. package/corpus/core/docs/content/locales/es-ES/migration-workbench.mdx +0 -76
  1171. package/corpus/core/docs/content/locales/fr-FR/migration-workbench.mdx +0 -76
  1172. package/corpus/core/docs/content/locales/hi-IN/migration-workbench.mdx +0 -74
  1173. package/corpus/core/docs/content/locales/ja-JP/migration-workbench.mdx +0 -76
  1174. package/corpus/core/docs/content/locales/ko-KR/migration-workbench.mdx +0 -74
  1175. package/corpus/core/docs/content/locales/pt-BR/migration-workbench.mdx +0 -76
  1176. package/corpus/core/docs/content/locales/zh-CN/migration-workbench.mdx +0 -74
  1177. package/corpus/core/docs/content/locales/zh-TW/migration-workbench.mdx +0 -74
  1178. package/corpus/core/docs/content/migration-workbench.mdx +0 -74
  1179. package/corpus/core/docs/content/toolkit-app-adapters.mdx +0 -55
  1180. package/corpus/core/docs/content/toolkit-collaboration-ui.mdx +0 -60
  1181. package/corpus/core/docs/content/toolkit-sharing-ui.mdx +0 -45
  1182. package/corpus/core/docs/content/toolkit-shell-hooks.mdx +0 -36
  1183. package/docs/content/locales/ar-SA/migration-workbench.mdx +0 -76
  1184. package/docs/content/locales/de-DE/migration-workbench.mdx +0 -76
  1185. package/docs/content/locales/es-ES/migration-workbench.mdx +0 -76
  1186. package/docs/content/locales/fr-FR/migration-workbench.mdx +0 -76
  1187. package/docs/content/locales/hi-IN/migration-workbench.mdx +0 -74
  1188. package/docs/content/locales/ja-JP/migration-workbench.mdx +0 -76
  1189. package/docs/content/locales/ko-KR/migration-workbench.mdx +0 -74
  1190. package/docs/content/locales/pt-BR/migration-workbench.mdx +0 -76
  1191. package/docs/content/locales/zh-CN/migration-workbench.mdx +0 -74
  1192. package/docs/content/locales/zh-TW/migration-workbench.mdx +0 -74
  1193. package/docs/content/migration-workbench.mdx +0 -74
  1194. package/docs/content/toolkit-app-adapters.mdx +0 -55
  1195. package/docs/content/toolkit-collaboration-ui.mdx +0 -60
  1196. package/docs/content/toolkit-sharing-ui.mdx +0 -45
  1197. package/docs/content/toolkit-shell-hooks.mdx +0 -36
@@ -1,10 +1,11 @@
1
1
  import { useEffect, useRef, useState } from "react";
2
- import { ensureDemoModeFetchInterceptor } from "../demo/fetch-interceptor.js";
2
+ import { ensureDemoModeFetchInterceptor, refreshDemoModeFetchInterceptor, } from "../demo/fetch-interceptor.js";
3
3
  import { agentNativePath } from "./api-path.js";
4
4
  import { ensureEmbedAuthFetchInterceptor, isEmbedAuthActive, } from "./embed-auth.js";
5
5
  import { bumpChangeVersion } from "./use-change-version.js";
6
6
  const POLL_ABORT_MIN_MS = 10_000;
7
7
  const SSE_FALLBACK_INTERVAL_MS = 15_000;
8
+ const IDLE_POLL_INTERVAL_MS = 15_000;
8
9
  const POLL_AUTH_FAILURE_COOLDOWN_MS = 60_000;
9
10
  /**
10
11
  * Max cadence for SSE/poll-driven query invalidation in `useDbSync`. Events
@@ -115,6 +116,7 @@ class SyncTransport {
115
116
  sseConnected = false;
116
117
  authFailureUntil = 0;
117
118
  consecutiveFailures = 0;
119
+ activeChatIds = new Set();
118
120
  constructor(pollUrl, sseUrl) {
119
121
  this.pollUrl = pollUrl;
120
122
  this.sseUrl = sseUrl;
@@ -124,11 +126,20 @@ class SyncTransport {
124
126
  // -------------------------------------------------------------------------
125
127
  add(id, sub) {
126
128
  const wasEmpty = this.subscribers.size === 0;
129
+ const wasActive = this.isActive;
127
130
  this.subscribers.set(id, sub);
128
131
  if (wasEmpty) {
129
132
  this.stopped = false;
130
133
  this.start();
131
134
  }
135
+ else if (!wasActive && this.isActive) {
136
+ // A collab surface (or other active subscriber) just joined. Catch up
137
+ // immediately rather than waiting out an idle-cadence timer.
138
+ this.pollNow();
139
+ }
140
+ else {
141
+ this.reschedule();
142
+ }
132
143
  sub.onSseStateChange?.(this.sseConnected);
133
144
  }
134
145
  remove(id) {
@@ -161,6 +172,17 @@ class SyncTransport {
161
172
  }
162
173
  return isFinite(min) ? min : 2000;
163
174
  }
175
+ get effectiveIdleInterval() {
176
+ let min = Infinity;
177
+ for (const sub of this.subscribers.values()) {
178
+ if (sub.idleInterval < min)
179
+ min = sub.idleInterval;
180
+ }
181
+ return isFinite(min) ? min : IDLE_POLL_INTERVAL_MS;
182
+ }
183
+ get isActive() {
184
+ return this.activeChatIds.size > 0;
185
+ }
164
186
  get effectiveFallbackInterval() {
165
187
  let min = Infinity;
166
188
  for (const sub of this.subscribers.values()) {
@@ -173,6 +195,10 @@ class SyncTransport {
173
195
  // Event fan-out
174
196
  // -------------------------------------------------------------------------
175
197
  fan(events, version) {
198
+ if (events.some((event) => event.source === "app-state" &&
199
+ (event.key === "demo-mode" || event.key === "*"))) {
200
+ void refreshDemoModeFetchInterceptor();
201
+ }
176
202
  for (const sub of this.subscribers.values()) {
177
203
  sub.onEvents(events, version);
178
204
  }
@@ -206,9 +232,11 @@ class SyncTransport {
206
232
  }, authDelay);
207
233
  return;
208
234
  }
209
- const base = this.sseConnected
210
- ? this.effectiveFallbackInterval
211
- : this.effectiveInterval;
235
+ const base = this.isActive
236
+ ? this.effectiveInterval
237
+ : this.sseConnected
238
+ ? this.effectiveFallbackInterval
239
+ : this.effectiveIdleInterval;
212
240
  // Exponential backoff while polls keep failing (500s during a deploy,
213
241
  // DNS blips, a struggling DB). Auth failures have their own cooldown
214
242
  // above; this covers everything else so a down server isn't hammered at
@@ -350,6 +378,34 @@ class SyncTransport {
350
378
  handleFocus = () => {
351
379
  this.pollNow();
352
380
  };
381
+ handleChatRunning = (event) => {
382
+ const detail = event.detail;
383
+ const running = typeof detail?.isRunning === "boolean"
384
+ ? detail.isRunning
385
+ : typeof detail?.running === "boolean"
386
+ ? detail.running
387
+ : null;
388
+ if (running === null)
389
+ return;
390
+ const id = typeof detail?.tabId === "string" && detail.tabId
391
+ ? detail.tabId
392
+ : "__default__";
393
+ const wasActive = this.isActive;
394
+ if (running)
395
+ this.activeChatIds.add(id);
396
+ else
397
+ this.activeChatIds.delete(id);
398
+ if (wasActive === this.isActive)
399
+ return;
400
+ if (this.isActive) {
401
+ // Run start is a high-signal indication that cross-process writes are
402
+ // imminent. Catch up now, then stay on the active cadence.
403
+ this.pollNow();
404
+ }
405
+ else {
406
+ this.reschedule();
407
+ }
408
+ };
353
409
  start() {
354
410
  // Universal demo-mode redaction for the UI. Idempotent + browser-only +
355
411
  // a no-op until demo mode is on. Lives here because every template root
@@ -361,6 +417,7 @@ class SyncTransport {
361
417
  void this.poll();
362
418
  }
363
419
  window.addEventListener("focus", this.handleFocus);
420
+ window.addEventListener("agentNative.chatRunning", this.handleChatRunning);
364
421
  document.addEventListener("visibilitychange", this.handleVisibilityChange);
365
422
  }
366
423
  teardown() {
@@ -371,6 +428,7 @@ class SyncTransport {
371
428
  this.timer = null;
372
429
  }
373
430
  window.removeEventListener("focus", this.handleFocus);
431
+ window.removeEventListener("agentNative.chatRunning", this.handleChatRunning);
374
432
  document.removeEventListener("visibilitychange", this.handleVisibilityChange);
375
433
  }
376
434
  }
@@ -424,6 +482,7 @@ export function subscribeSyncEvents(options) {
424
482
  onSseStateChange: options.onSseStateChange,
425
483
  pauseWhenHidden: options.pauseWhenHidden ?? true,
426
484
  interval: options.interval ?? 60_000,
485
+ idleInterval: options.interval ?? 60_000,
427
486
  fallbackInterval: options.fallbackInterval ?? 60_000,
428
487
  });
429
488
  return () => {
@@ -469,6 +528,7 @@ export function subscribeSyncEvents(options) {
469
528
  */
470
529
  export function useDbSync(options = {}) {
471
530
  const { queryClient, pollUrl = agentNativePath(options.eventsUrl ?? "/_agent-native/poll"), sseUrl = resolveSseUrl(options.sseUrl), interval = 2000, fallbackInterval = Math.max(options.fallbackInterval ?? SSE_FALLBACK_INTERVAL_MS, interval), pauseWhenHidden = true, } = options;
531
+ const idleInterval = options.interval === undefined ? IDLE_POLL_INTERVAL_MS : interval;
472
532
  const onEventRef = useRef(options.onEvent);
473
533
  onEventRef.current = options.onEvent;
474
534
  const ignoreSourceRef = useRef(options.ignoreSource);
@@ -550,8 +610,12 @@ export function useDbSync(options = {}) {
550
610
  for (const evt of relevant) {
551
611
  const src = typeof evt.source === "string" ? evt.source : "";
552
612
  const ver = typeof evt.version === "number" ? evt.version : 0;
553
- if (src && ver > 0)
613
+ if (src && ver > 0) {
554
614
  bumpChangeVersion(src, ver);
615
+ if (typeof evt.key === "string" && evt.key) {
616
+ bumpChangeVersion(`${src}:${evt.key}`, ver);
617
+ }
618
+ }
555
619
  }
556
620
  // Awareness (cursor/presence) events never change action/extension/
557
621
  // app-state query results, but they arrive on every peer keystroke and
@@ -598,7 +662,12 @@ export function useDbSync(options = {}) {
598
662
  // turn starved run heartbeat writes and surfaced as `stale_run`.
599
663
  if (!suppressesWholeBatch) {
600
664
  const hasDataChangingEvent = invalidating.some((evt) => evt.source !== "app-state");
601
- if (hasDataChangingEvent) {
665
+ // The broad action invalidate above already covers every fixed
666
+ // framework prefix. Re-invalidating ["action"] immediately after it
667
+ // cancels/restarts the same active reads and creates a duplicate
668
+ // request wave. Keep the fixed-prefix pass for non-action sources;
669
+ // action batches get exactly one compatibility invalidation.
670
+ if (hasDataChangingEvent && !hasActionEvent) {
602
671
  queryClient.invalidateQueries({ queryKey: ["action"] });
603
672
  queryClient.invalidateQueries({ queryKey: ["extension"] });
604
673
  queryClient.invalidateQueries({ queryKey: ["extensions"] });
@@ -645,6 +714,7 @@ export function useDbSync(options = {}) {
645
714
  onEvents,
646
715
  pauseWhenHidden,
647
716
  interval,
717
+ idleInterval,
648
718
  fallbackInterval,
649
719
  });
650
720
  return () => {
@@ -668,6 +738,7 @@ export function useDbSync(options = {}) {
668
738
  sseUrl,
669
739
  queryClient,
670
740
  interval,
741
+ idleInterval,
671
742
  fallbackInterval,
672
743
  pauseWhenHidden,
673
744
  ]);
@@ -695,6 +766,7 @@ export const useFileWatcher = useDbSync;
695
766
  */
696
767
  export function useScreenRefreshKey(options = {}) {
697
768
  const { pollUrl = agentNativePath(options.pollUrl ?? "/_agent-native/poll"), sseUrl = resolveSseUrl(options.sseUrl), interval = 2000, fallbackInterval = Math.max(options.fallbackInterval ?? SSE_FALLBACK_INTERVAL_MS, interval), pauseWhenHidden = true, } = options;
769
+ const idleInterval = options.interval === undefined ? IDLE_POLL_INTERVAL_MS : interval;
698
770
  const [key, setKey] = useState(0);
699
771
  useEffect(() => {
700
772
  const id = Symbol("useScreenRefreshKey");
@@ -716,6 +788,7 @@ export function useScreenRefreshKey(options = {}) {
716
788
  onEvents,
717
789
  pauseWhenHidden,
718
790
  interval,
791
+ idleInterval,
719
792
  fallbackInterval,
720
793
  });
721
794
  return () => {
@@ -724,7 +797,14 @@ export function useScreenRefreshKey(options = {}) {
724
797
  releaseTransport(pollUrl, sseUrl);
725
798
  }
726
799
  };
727
- }, [pollUrl, sseUrl, interval, fallbackInterval, pauseWhenHidden]);
800
+ }, [
801
+ pollUrl,
802
+ sseUrl,
803
+ interval,
804
+ idleInterval,
805
+ fallbackInterval,
806
+ pauseWhenHidden,
807
+ ]);
728
808
  return key;
729
809
  }
730
810
  //# sourceMappingURL=use-db-sync.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-db-sync.js","sourceRoot":"","sources":["../../src/client/use-db-sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEpD,OAAO,EAAE,8BAA8B,EAAE,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAA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AAG,EAAE,KAAK,EAAE,EAAE,CACb,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EACtE,CAAC,CACF,CAAC;YACF,iBAAiB,GAAG,IAAI,CAAC,GAAG,CAC1B,iBAAiB,EACjB,OAAO,IAAI,CAAC,EACZ,eAAe,CAChB,CAAC;QACJ,CAAC;QAED,MAAM,SAAS,GAAG,oBAAoB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACxD,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE;YAChB,QAAQ;YACR,eAAe;YACf,QAAQ;YACR,gBAAgB;SACjB,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE;YACV,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YACrB,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,IAAI,EAAE,CAAC;gBACnC,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YACpC,CAAC;QACH,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,EAAE,eAAe,CAAC,CAAC,CAAC;IAEnE,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { useEffect, useRef, useState } from \"react\";\n\nimport { ensureDemoModeFetchInterceptor } from \"../demo/fetch-interceptor.js\";\nimport { agentNativePath } from \"./api-path.js\";\nimport {\n ensureEmbedAuthFetchInterceptor,\n isEmbedAuthActive,\n} from \"./embed-auth.js\";\nimport { bumpChangeVersion } from \"./use-change-version.js\";\n\ninterface Query {\n queryKey: readonly unknown[];\n}\n\ninterface QueryClient {\n invalidateQueries(opts?: {\n queryKey?: string[];\n predicate?: (query: Query) => boolean;\n }): void;\n}\n\nconst POLL_ABORT_MIN_MS = 10_000;\nconst SSE_FALLBACK_INTERVAL_MS = 15_000;\nconst POLL_AUTH_FAILURE_COOLDOWN_MS = 60_000;\n/**\n * Max cadence for SSE/poll-driven query invalidation in `useDbSync`. Events\n * that arrive within this window of the first one in a burst are merged into\n * a single `invalidateForEvents` call instead of one call per event — see the\n * `queueInvalidateBatch` comment at the call site.\n */\nconst INVALIDATE_COALESCE_MS = 250;\n\nclass HttpStatusError extends Error {\n status: number;\n\n constructor(status: number) {\n super(\"HTTP \" + status);\n this.status = status;\n }\n}\n\nexport type SyncEvent = {\n version?: number;\n source?: string;\n type?: string;\n key?: string;\n requestSource?: string;\n [k: string]: unknown;\n};\n\ntype PollResponse = {\n version: number;\n events: SyncEvent[];\n};\n\n/** Callback delivered to each transport subscriber for every batch of events. */\ntype EventSubscriber = (\n events: SyncEvent[],\n version: number | undefined,\n) => void;\n\nfunction getPollAbortMs(interval: number): number {\n return Math.max(POLL_ABORT_MIN_MS, interval * 4);\n}\n\nfunction isDocumentHidden(): boolean {\n return (\n typeof document !== \"undefined\" && document.visibilityState === \"hidden\"\n );\n}\n\nfunction resolveSseUrl(sseUrl: string | false | undefined): string | false {\n if (sseUrl === false) return false;\n if (isEmbedAuthActive()) return false;\n return agentNativePath(sseUrl ?? \"/_agent-native/events\");\n}\n\nfunction normalizeEventPayload(payload: unknown): SyncEvent[] {\n if (!payload || typeof payload !== \"object\") return [];\n const record = payload as { type?: unknown; events?: unknown };\n if (record.type === \"batch\" && Array.isArray(record.events)) {\n return record.events.filter(\n (event): event is SyncEvent => !!event && typeof event === \"object\",\n );\n }\n if (Array.isArray(record.events)) {\n return record.events.filter(\n (event): event is SyncEvent => !!event && typeof event === \"object\",\n );\n }\n return [payload as SyncEvent];\n}\n\nfunction isAuthFailure(error: unknown): boolean {\n return (\n !!error &&\n typeof error === \"object\" &&\n \"status\" in error &&\n ((error as { status?: unknown }).status === 401 ||\n (error as { status?: unknown }).status === 403)\n );\n}\n\n/**\n * App-state keys that drive immediate UI navigation/interaction and must\n * never sit behind the invalidation coalesce window (see\n * `isInteractionCriticalSyncEvent`).\n */\nconst INTERACTION_CRITICAL_APP_STATE_KEYS = [\n \"navigate\",\n \"show-questions\",\n \"__set_url__\",\n];\n\n/**\n * True for sync events that drive immediate, agent-initiated UI navigation\n * or interaction rather than passive data invalidation — app-state writes in\n * general (they back `[\"app-state\"]` queries directly), and specifically the\n * `navigate` / `show-questions` / `__set_url__` app-state keys that\n * `invalidateForEvents` special-cases into their own query keys below.\n *\n * `useDbSync` batches ordinary invalidation-driving events (action/collab/db\n * change events) into one flush per `INVALIDATE_COALESCE_MS` so a chatty doc\n * doesn't refetch on every keystroke. That trade-off is wrong for these\n * events: agent-driven navigation, `set-url`, and guided-questions prompts\n * must land as close to instantly as possible, so any batch containing one\n * of these bypasses the coalesce window and flushes immediately instead.\n *\n * Exported as a small pure predicate so this classification is unit-testable\n * independent of the transport/timer plumbing around it.\n */\nexport function isInteractionCriticalSyncEvent(event: SyncEvent): boolean {\n return (\n event.source === \"app-state\" &&\n (event.key === \"*\" ||\n INTERACTION_CRITICAL_APP_STATE_KEYS.some(\n (key) =>\n event.key === key ||\n (typeof event.key === \"string\" && event.key.startsWith(`${key}:`)),\n ))\n );\n}\n\nasync function fetchPollJson<T>(\n pollUrl: string,\n since: number,\n interval: number,\n): Promise<T> {\n const controller =\n typeof AbortController === \"undefined\" ? null : new AbortController();\n const timeout = controller\n ? setTimeout(() => controller.abort(), getPollAbortMs(interval))\n : null;\n\n try {\n const res = await fetch(\n `${pollUrl}?since=${since}`,\n controller ? { signal: controller.signal } : undefined,\n );\n if (!res.ok) throw new HttpStatusError(res.status);\n // Await the json before the finally so a body-stream abort doesn't\n // produce a dangling promise that escapes as an unhandled rejection.\n return await res.json();\n } finally {\n if (timeout) clearTimeout(timeout);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Shared SSE + poll transport\n//\n// One SyncTransport per (pollUrl, sseUrl) pair is held in a module-level\n// registry. Both `useDbSync` and `useScreenRefreshKey` subscribe to it, so a\n// single browser tab opens exactly ONE SSE connection and ONE poll loop\n// regardless of how many hook instances are mounted.\n//\n// Lifecycle: the transport starts when the first subscriber joins and shuts\n// down when the last subscriber leaves. This makes it safe to SSR and to\n// mount/unmount hooks independently.\n// ---------------------------------------------------------------------------\n\ninterface TransportSubscription {\n onEvents: EventSubscriber;\n /**\n * Whether this subscriber wants the transport to pause when the tab is\n * hidden. The transport pauses only when ALL subscribers request it — any\n * subscriber with `pauseWhenHidden: false` keeps the connection alive.\n */\n pauseWhenHidden: boolean;\n /**\n * Requested poll interval in ms. The transport uses the minimum across all\n * subscribers so the most-frequent caller is satisfied.\n */\n interval: number;\n /** Requested fallback interval while SSE is connected. */\n fallbackInterval: number;\n /**\n * Optional: notified when the shared SSE connection opens or closes (also\n * fired once with the current state when the subscriber joins). Lets\n * subscribers with their own fallback loops (e.g. the collab doc poll)\n * relax their cadence while the push path is healthy.\n */\n onSseStateChange?: (connected: boolean) => void;\n}\n\nclass SyncTransport {\n private subscribers = new Map<symbol, TransportSubscription>();\n private versionRef = 0;\n private timer: ReturnType<typeof setTimeout> | null = null;\n private stopped = false;\n private inFlight = false;\n private eventSource: EventSource | null = null;\n private sseConnected = false;\n private authFailureUntil = 0;\n private consecutiveFailures = 0;\n\n constructor(\n private readonly pollUrl: string,\n private readonly sseUrl: string | false,\n ) {}\n\n // -------------------------------------------------------------------------\n // Subscriber management\n // -------------------------------------------------------------------------\n\n add(id: symbol, sub: TransportSubscription): void {\n const wasEmpty = this.subscribers.size === 0;\n this.subscribers.set(id, sub);\n if (wasEmpty) {\n this.stopped = false;\n this.start();\n }\n sub.onSseStateChange?.(this.sseConnected);\n }\n\n remove(id: symbol): void {\n this.subscribers.delete(id);\n if (this.subscribers.size === 0) {\n this.teardown();\n } else {\n // Recalculate poll interval in case the leaving subscriber was the\n // fastest caller; reschedule with the updated cadence.\n this.reschedule();\n }\n }\n\n // -------------------------------------------------------------------------\n // Derived settings (aggregate over active subscribers)\n // -------------------------------------------------------------------------\n\n private get effectivePauseWhenHidden(): boolean {\n // Pause only if every subscriber has opted in.\n for (const sub of this.subscribers.values()) {\n if (!sub.pauseWhenHidden) return false;\n }\n return true;\n }\n\n private get effectiveInterval(): number {\n let min = Infinity;\n for (const sub of this.subscribers.values()) {\n if (sub.interval < min) min = sub.interval;\n }\n return isFinite(min) ? min : 2000;\n }\n\n private get effectiveFallbackInterval(): number {\n let min = Infinity;\n for (const sub of this.subscribers.values()) {\n if (sub.fallbackInterval < min) min = sub.fallbackInterval;\n }\n return isFinite(min) ? min : SSE_FALLBACK_INTERVAL_MS;\n }\n\n // -------------------------------------------------------------------------\n // Event fan-out\n // -------------------------------------------------------------------------\n\n private fan(events: SyncEvent[], version: number | undefined): void {\n for (const sub of this.subscribers.values()) {\n sub.onEvents(events, version);\n }\n }\n\n private setSseConnected(connected: boolean): void {\n if (this.sseConnected === connected) return;\n this.sseConnected = connected;\n for (const sub of this.subscribers.values()) {\n sub.onSseStateChange?.(connected);\n }\n }\n\n // -------------------------------------------------------------------------\n // SSE + poll loop (mirrors the original per-hook logic exactly)\n // -------------------------------------------------------------------------\n\n private authFailureDelayMs(): number {\n return Math.max(0, this.authFailureUntil - Date.now());\n }\n\n private schedulePoll(): void {\n if (this.stopped) return;\n if (this.effectivePauseWhenHidden && isDocumentHidden()) return;\n if (this.timer) clearTimeout(this.timer);\n const authDelay = this.authFailureDelayMs();\n if (authDelay > 0) {\n this.timer = setTimeout(() => {\n this.timer = null;\n void this.poll();\n }, authDelay);\n return;\n }\n const base = this.sseConnected\n ? this.effectiveFallbackInterval\n : this.effectiveInterval;\n // Exponential backoff while polls keep failing (500s during a deploy,\n // DNS blips, a struggling DB). Auth failures have their own cooldown\n // above; this covers everything else so a down server isn't hammered at\n // full cadence. Resets on the first successful poll.\n const delay =\n this.consecutiveFailures > 0\n ? Math.min(base * 2 ** Math.min(this.consecutiveFailures, 5), 30_000)\n : base;\n this.timer = setTimeout(() => {\n this.timer = null;\n void this.poll();\n }, delay);\n }\n\n private reschedule(): void {\n // Only need to act if a timer is already pending; next natural tick will\n // pick up the new effective interval otherwise.\n if (this.timer !== null) {\n clearTimeout(this.timer);\n this.timer = null;\n this.schedulePoll();\n }\n }\n\n private closeEvents(): void {\n if (!this.eventSource) return;\n this.eventSource.close();\n this.eventSource = null;\n this.setSseConnected(false);\n }\n\n private connectEvents(): void {\n if (\n this.stopped ||\n !this.sseUrl ||\n this.eventSource ||\n typeof EventSource === \"undefined\" ||\n (this.effectivePauseWhenHidden && isDocumentHidden())\n ) {\n return;\n }\n\n const source = new EventSource(this.sseUrl);\n this.eventSource = source;\n source.onopen = () => {\n this.setSseConnected(true);\n this.schedulePoll();\n };\n source.onerror = () => {\n this.setSseConnected(false);\n // When the browser gives up permanently (HTTP error → readyState\n // CLOSED), it won't auto-reconnect. Drop the ref so a later\n // connectEvents() (on focus/visibility) can establish a fresh stream;\n // otherwise the non-null closed `eventSource` blocks reconnection and\n // we'd be stuck on polling-only forever.\n if (source.readyState === EventSource.CLOSED) {\n this.eventSource = null;\n }\n this.schedulePoll();\n };\n source.onmessage = (message) => {\n try {\n const payload = JSON.parse(message.data);\n const events = normalizeEventPayload(payload);\n const version =\n typeof payload?.version === \"number\" ? payload.version : undefined;\n this.applyVersion(events, version);\n this.fan(events, version);\n } catch {\n // Ignore malformed SSE frames; polling is the safety net.\n }\n };\n }\n\n /**\n * Advance the transport's shared version cursor. Subscribers receive the\n * raw events and decide independently which ones are \"fresh\" relative to\n * their own cursor, but the transport-level cursor ensures the poll\n * `?since=` parameter always advances.\n */\n private applyVersion(events: SyncEvent[], version: number | undefined): void {\n let max = typeof version === \"number\" ? version : 0;\n for (const evt of events) {\n const v = typeof evt.version === \"number\" ? evt.version : 0;\n if (v > max) max = v;\n }\n if (max > this.versionRef) this.versionRef = max;\n }\n\n private async poll(): Promise<void> {\n if (this.stopped || this.inFlight) return;\n this.inFlight = true;\n try {\n const data = await fetchPollJson<PollResponse>(\n this.pollUrl,\n this.versionRef,\n this.effectiveInterval,\n );\n if (this.stopped) return;\n this.consecutiveFailures = 0;\n const events = data.events ?? [];\n this.applyVersion(events, data.version);\n this.fan(events, data.version);\n } catch (err) {\n if (this.stopped) return;\n this.consecutiveFailures++;\n if (isAuthFailure(err)) {\n this.authFailureUntil = Date.now() + POLL_AUTH_FAILURE_COOLDOWN_MS;\n this.closeEvents();\n }\n // Network error — retried on the next (backed-off) interval.\n } finally {\n this.inFlight = false;\n this.schedulePoll();\n }\n }\n\n private pollNow(): void {\n if (this.effectivePauseWhenHidden && isDocumentHidden()) return;\n if (this.authFailureDelayMs() > 0) {\n this.schedulePoll();\n return;\n }\n if (this.timer) {\n clearTimeout(this.timer);\n this.timer = null;\n }\n this.connectEvents();\n void this.poll();\n }\n\n private handleVisibilityChange = (): void => {\n if (document.visibilityState === \"visible\") {\n this.connectEvents();\n this.pollNow();\n } else if (this.effectivePauseWhenHidden) {\n this.closeEvents();\n if (this.timer) {\n clearTimeout(this.timer);\n this.timer = null;\n }\n }\n };\n\n private handleFocus = (): void => {\n this.pollNow();\n };\n\n private start(): void {\n // Universal demo-mode redaction for the UI. Idempotent + browser-only +\n // a no-op until demo mode is on. Lives here because every template root\n // already mounts useDbSync, so this needs zero per-template wiring.\n ensureEmbedAuthFetchInterceptor();\n ensureDemoModeFetchInterceptor();\n\n if (!this.effectivePauseWhenHidden || !isDocumentHidden()) {\n this.connectEvents();\n void this.poll();\n }\n window.addEventListener(\"focus\", this.handleFocus);\n document.addEventListener(\"visibilitychange\", this.handleVisibilityChange);\n }\n\n private teardown(): void {\n this.stopped = true;\n this.closeEvents();\n if (this.timer) {\n clearTimeout(this.timer);\n this.timer = null;\n }\n window.removeEventListener(\"focus\", this.handleFocus);\n document.removeEventListener(\n \"visibilitychange\",\n this.handleVisibilityChange,\n );\n }\n}\n\n/**\n * Registry of active transports keyed by \"<pollUrl>\\0<sseUrl>\".\n * Module-level singleton: survives React render cycles, shared across all\n * hook instances in the same browser tab.\n */\nconst transportRegistry = new Map<string, SyncTransport>();\n\nfunction getOrCreateTransport(\n pollUrl: string,\n sseUrl: string | false,\n): SyncTransport {\n const key = `${pollUrl}\\0${String(sseUrl)}`;\n let transport = transportRegistry.get(key);\n if (!transport) {\n transport = new SyncTransport(pollUrl, sseUrl);\n transportRegistry.set(key, transport);\n }\n return transport;\n}\n\n/** Remove a transport from the registry once torn down (last subscriber left). */\nfunction releaseTransport(pollUrl: string, sseUrl: string | false): void {\n const key = `${pollUrl}\\0${String(sseUrl)}`;\n // Leave the entry in place: SSE/poll is already stopped inside the class;\n // the next subscriber will re-start it via `add()`. Clearing the map entry\n // prevents any dangling reference from the old SyncTransport instance.\n transportRegistry.delete(key);\n}\n\n// ---------------------------------------------------------------------------\n// Internal test helper — reset transport registry between tests.\n// ---------------------------------------------------------------------------\n/** @internal */\nexport function _resetSyncTransportRegistryForTests(): void {\n transportRegistry.clear();\n}\n\nexport interface SubscribeSyncEventsOptions {\n /** Receives every batch of change events (SSE push or poll). */\n onEvents: (events: SyncEvent[], version: number | undefined) => void;\n /** Notified when the shared SSE connection opens/closes (and once on join). */\n onSseStateChange?: (connected: boolean) => void;\n pollUrl?: string;\n sseUrl?: string | false;\n pauseWhenHidden?: boolean;\n /**\n * Poll cadence this subscriber requests from the SHARED poll loop. The\n * transport uses the minimum across subscribers, so the defaults here are\n * deliberately high: subscribing must not speed up the shared poll —\n * useDbSync (mounted by every template root) already sets the pace.\n */\n interval?: number;\n fallbackInterval?: number;\n}\n\n/**\n * Subscribe to the shared SSE + poll transport without the React Query\n * invalidation behavior of `useDbSync`. Use this instead of opening another\n * `EventSource` to `/_agent-native/events` — a browser tab should hold ONE\n * SSE connection no matter how many features listen to it (extra streams eat\n * the per-origin connection budget and starve data fetches, especially on\n * HTTP/1.1 dev servers).\n *\n * Returns an unsubscribe function. Safe to call only in browser contexts.\n */\nexport function subscribeSyncEvents(\n options: SubscribeSyncEventsOptions,\n): () => void {\n const pollUrl = agentNativePath(options.pollUrl ?? \"/_agent-native/poll\");\n const sseUrl = resolveSseUrl(options.sseUrl);\n const transport = getOrCreateTransport(pollUrl, sseUrl);\n const id = Symbol(\"subscribeSyncEvents\");\n transport.add(id, {\n onEvents: options.onEvents,\n onSseStateChange: options.onSseStateChange,\n pauseWhenHidden: options.pauseWhenHidden ?? true,\n interval: options.interval ?? 60_000,\n fallbackInterval: options.fallbackInterval ?? 60_000,\n });\n return () => {\n transport.remove(id);\n if (!transport[\"subscribers\"].size) {\n releaseTransport(pollUrl, sseUrl);\n }\n };\n}\n\n/**\n * Hook that listens to /_agent-native/events for DB change events and\n * invalidates react-query caches when changes are detected. Falls back to\n * /_agent-native/poll so cross-process/serverless writes still show up.\n *\n * Works in all deployment environments (serverless, edge, long-lived server).\n * SSE is the fast path; polling is the safety net.\n *\n * @param options.queryClient - The react-query QueryClient instance\n * @param options.queryKeys - **Deprecated and ignored.** The hook uses\n * framework-owned fixed prefixes plus per-source change counters instead of\n * caller-supplied key lists. Kept in the type signature for backward\n * compatibility — existing call sites that still pass this option keep\n * working but the value has no effect.\n * @param options.pollUrl - Poll endpoint URL. Default: \"/_agent-native/poll\"\n * @param options.sseUrl - SSE endpoint URL. Default: \"/_agent-native/events\".\n * Pass false to disable SSE and use polling only.\n * @param options.onEvent - Optional callback for each change event\n * @param options.interval - Poll interval in ms. Default: 2000\n * @param options.fallbackInterval - Poll interval while SSE is connected.\n * Default: 15000\n * @param options.pauseWhenHidden - Pause polling while the tab is hidden.\n * Default: true\n * @param options.ignoreSource - Skip events whose `requestSource` matches this\n * value. Use a per-tab ID so the UI ignores its own writes while still\n * picking up changes from other tabs, agents, and scripts.\n * @param options.actionInvalidatePredicate - Optional filter for the broad\n * compatibility invalidate triggered by `action` events. Use this to keep\n * expensive active queries on explicit-refresh semantics while still letting\n * normal source-versioned queries react through `useChangeVersion`.\n * @param options.suppressActionInvalidationFor - Action names whose sync events\n * should not invalidate all action queries. Use only for high-volume\n * background actions that perform their own narrow client invalidation.\n */\nexport function useDbSync(\n options: {\n queryClient?: QueryClient;\n queryKeys?: string[];\n pollUrl?: string;\n sseUrl?: string | false;\n /** @deprecated Use pollUrl instead */\n eventsUrl?: string;\n onEvent?: (data: any) => void;\n interval?: number;\n fallbackInterval?: number;\n pauseWhenHidden?: boolean;\n ignoreSource?: string;\n actionInvalidatePredicate?: (query: Query) => boolean;\n suppressActionInvalidationFor?: string[];\n } = {},\n): void {\n const {\n queryClient,\n pollUrl = agentNativePath(options.eventsUrl ?? \"/_agent-native/poll\"),\n sseUrl = resolveSseUrl(options.sseUrl),\n interval = 2000,\n fallbackInterval = Math.max(\n options.fallbackInterval ?? SSE_FALLBACK_INTERVAL_MS,\n interval,\n ),\n pauseWhenHidden = true,\n } = options;\n\n const onEventRef = useRef(options.onEvent);\n onEventRef.current = options.onEvent;\n\n const ignoreSourceRef = useRef(options.ignoreSource);\n ignoreSourceRef.current = options.ignoreSource;\n const actionInvalidatePredicateRef = useRef(\n options.actionInvalidatePredicate,\n );\n actionInvalidatePredicateRef.current = options.actionInvalidatePredicate;\n const suppressActionInvalidationForRef = useRef(\n options.suppressActionInvalidationFor,\n );\n suppressActionInvalidationForRef.current =\n options.suppressActionInvalidationFor;\n\n useEffect(() => {\n const id = Symbol(\"useDbSync\");\n // Per-subscriber version cursor: tracks which events have already been\n // processed by THIS subscriber so stale poll re-deliveries are ignored.\n let subscriberVersion = 0;\n\n // Coalesce bursts of SSE-driven invalidation into at most one flush per\n // INVALIDATE_COALESCE_MS. A chatty doc (many small agent edits, several\n // peers editing at once) can otherwise deliver a handful of `action`/\n // `collab` events within a few hundred ms, each independently calling\n // `queryClient.invalidateQueries` and firing `onEvent` — every one of\n // those touches whatever query subscribers are mounted (e.g. a\n // full-page editor) even though the end state only needs to be\n // refreshed once. Version bookkeeping stays synchronous (below) so\n // freshness filtering for the NEXT batch is unaffected by the delay.\n //\n // This coalesce window is wrong for interaction-critical events (agent\n // navigation, `set-url`, guided questions — see\n // `isInteractionCriticalSyncEvent`): those must reach the UI immediately,\n // not up to INVALIDATE_COALESCE_MS late. So a fresh batch containing one\n // of those flushes synchronously (queued + new events together,\n // canceling any pending timer) instead of joining the coalesce window.\n // Pure invalidation bursts with no interaction-critical members keep the\n // coalesced behavior.\n let pendingInvalidateEvents: SyncEvent[] = [];\n let invalidateTimer: ReturnType<typeof setTimeout> | null = null;\n\n function flushInvalidateBatch() {\n if (invalidateTimer) {\n clearTimeout(invalidateTimer);\n invalidateTimer = null;\n }\n if (pendingInvalidateEvents.length === 0) return;\n const batch = pendingInvalidateEvents;\n pendingInvalidateEvents = [];\n invalidateForEvents(batch);\n }\n\n function queueInvalidateBatch(events: SyncEvent[]) {\n pendingInvalidateEvents.push(...events);\n if (events.some(isInteractionCriticalSyncEvent)) {\n flushInvalidateBatch();\n return;\n }\n if (invalidateTimer) return;\n invalidateTimer = setTimeout(\n flushInvalidateBatch,\n INVALIDATE_COALESCE_MS,\n );\n }\n\n function hasAppStateEvent(events: SyncEvent[], key: string): boolean {\n return events.some(\n (event) =>\n event.source === \"app-state\" &&\n (event.key === key ||\n event.key === \"*\" ||\n (typeof event.key === \"string\" && event.key.startsWith(`${key}:`))),\n );\n }\n\n function invalidateForEvents(events: SyncEvent[]) {\n const ignore = ignoreSourceRef.current;\n const relevant = ignore\n ? events.filter((e) => e.requestSource !== ignore)\n : events;\n const suppressedActions = new Set(\n suppressActionInvalidationForRef.current ?? [],\n );\n const isSuppressedActionEvent = (evt: SyncEvent) =>\n evt.source === \"action\" &&\n typeof evt.key === \"string\" &&\n suppressedActions.has(evt.key);\n const nonAwareness = relevant.filter((e) => e.source !== \"awareness\");\n const suppressesWholeBatch =\n nonAwareness.length > 0 &&\n nonAwareness.every((evt) => evt.source === \"action\") &&\n nonAwareness.every(isSuppressedActionEvent);\n\n // Bump per-source change counters. Components that read these via\n // `useChangeVersion(source)` and fold the value into a React Query\n // queryKey get a targeted refetch — no whole-cache invalidate, no\n // request storm. See `use-change-version.ts` for the contract.\n for (const evt of relevant) {\n const src = typeof evt.source === \"string\" ? evt.source : \"\";\n const ver = typeof evt.version === \"number\" ? evt.version : 0;\n if (src && ver > 0) bumpChangeVersion(src, ver);\n }\n\n // Awareness (cursor/presence) events never change action/extension/\n // app-state query results, but they arrive on every peer keystroke and\n // carry no version (so the freshness filter always passes them). Keep\n // them out of the invalidate block or an idle collaborative doc turns\n // every peer's cursor move into a framework-wide refetch storm; they\n // still reach onEvent below for callers that render presence.\n const invalidating = relevant.filter((e) => e.source !== \"awareness\");\n\n if (invalidating.length > 0 && queryClient) {\n const hasActionEvent = invalidating.some(\n (evt) => evt.source === \"action\" && !isSuppressedActionEvent(evt),\n );\n if (hasActionEvent) {\n // Custom apps frequently start with raw `useQuery` calls before\n // graduating to `useActionQuery` or source-versioned query keys.\n // A successful mutating action is the core \"agent changed app data\"\n // signal, so refresh active queries broadly as a compatibility\n // safety net. Other event sources stay targeted to avoid request\n // storms from noisy domain-specific writes.\n const predicate = actionInvalidatePredicateRef.current;\n queryClient.invalidateQueries(predicate ? { predicate } : undefined);\n }\n\n // Framework-level invalidate: a small, fixed list of query-key\n // prefixes the framework's own hooks/components use (action results,\n // extension state, application-state, the agent's `set-url` channel,\n // etc.). Templates' own data queries do NOT live here — they react\n // through `useChangeVersion(source)` in their query keys instead, so\n // a single change event doesn't fan out into \"refetch everything\".\n // Suppressed-action-only batches skip this whole list (their\n // mutations perform their own narrow invalidation) — but events must\n // STILL reach the onEvent forwarding below, so guard, don't return.\n //\n // Invalidation is scoped by source. Data-query prefixes (action,\n // extension, tool) refetch only when the batch carries an event that\n // can actually change action/extension-backed data — action\n // mutations, settings, extension, collab, screen-refresh, etc.\n // `app-state` events (agent/UI navigation, selection, and the\n // set-url/questions command channel) drive their OWN keys below and\n // must NEVER fan out into \"refetch every action query\": an active\n // agent session mirrors navigation + selection into application_state\n // continuously, and the serverless poll path replays those writes\n // back to the originating tab (the DB-scan fallback cannot preserve\n // `requestSource`, so `ignoreSource` can't filter them). Fanning each\n // one into a full `[\"action\"]` refetch turned a normal session into a\n // client fetch storm that exhausted the DB connection pool — which in\n // turn starved run heartbeat writes and surfaced as `stale_run`.\n if (!suppressesWholeBatch) {\n const hasDataChangingEvent = invalidating.some(\n (evt) => evt.source !== \"app-state\",\n );\n if (hasDataChangingEvent) {\n queryClient.invalidateQueries({ queryKey: [\"action\"] });\n queryClient.invalidateQueries({ queryKey: [\"extension\"] });\n queryClient.invalidateQueries({ queryKey: [\"extensions\"] });\n queryClient.invalidateQueries({ queryKey: [\"extension-slots\"] });\n queryClient.invalidateQueries({ queryKey: [\"slot-installs\"] });\n queryClient.invalidateQueries({ queryKey: [\"slot-available\"] });\n queryClient.invalidateQueries({ queryKey: [\"tool\"] });\n queryClient.invalidateQueries({ queryKey: [\"tools\"] });\n }\n if (invalidating.some((evt) => evt.source === \"app-state\")) {\n queryClient.invalidateQueries({ queryKey: [\"app-state\"] });\n }\n if (hasAppStateEvent(invalidating, \"navigate\")) {\n queryClient.invalidateQueries({ queryKey: [\"navigate-command\"] });\n }\n if (hasAppStateEvent(invalidating, \"show-questions\")) {\n queryClient.invalidateQueries({ queryKey: [\"show-questions\"] });\n }\n if (hasAppStateEvent(invalidating, \"__set_url__\")) {\n queryClient.invalidateQueries({ queryKey: [\"__set_url__\"] });\n }\n }\n }\n\n // Always forward all events to onEvent — templates can layer surgical\n // logic on top (e.g. ignore their own writes via requestSource, or\n // invalidate inactive queries for a specific source).\n for (const evt of events) {\n onEventRef.current?.(evt);\n }\n }\n\n function onEvents(events: SyncEvent[], version: number | undefined): void {\n const freshEvents = events.filter((event) => {\n const v = typeof event.version === \"number\" ? event.version : 0;\n return v === 0 || v > subscriberVersion;\n });\n\n if (freshEvents.length > 0) {\n queueInvalidateBatch(freshEvents);\n }\n\n const maxEventVersion = freshEvents.reduce(\n (max, event) =>\n Math.max(max, typeof event.version === \"number\" ? event.version : 0),\n 0,\n );\n subscriberVersion = Math.max(\n subscriberVersion,\n version ?? 0,\n maxEventVersion,\n );\n }\n\n const transport = getOrCreateTransport(pollUrl, sseUrl);\n transport.add(id, {\n onEvents,\n pauseWhenHidden,\n interval,\n fallbackInterval,\n });\n\n return () => {\n if (invalidateTimer) {\n clearTimeout(invalidateTimer);\n // Flush synchronously on unmount so a pending batch isn't silently\n // dropped (e.g. a route change right after an agent edit lands).\n flushInvalidateBatch();\n }\n transport.remove(id);\n // If the registry still holds this transport, and the transport is now\n // empty, evict it so the next mount gets a fresh instance rather than a\n // stopped-but-still-registered one (the registry entry being cleared by\n // releaseTransport is the signal to rebuild state).\n if (!transport[\"subscribers\"].size) {\n releaseTransport(pollUrl, sseUrl);\n }\n };\n }, [\n pollUrl,\n sseUrl,\n queryClient,\n interval,\n fallbackInterval,\n pauseWhenHidden,\n ]);\n}\n\n/** @deprecated Use useDbSync instead */\nexport const useFileWatcher = useDbSync;\n\n/**\n * Subscribe to `refresh-screen` events from the agent. Returns an integer\n * that increments every time the agent invokes the framework's `refresh-screen`\n * tool. Apply it as a React `key` on the main content wrapper (the part\n * OUTSIDE the agent chat sidebar) so that region remounts and re-fetches its\n * data while the chat, sidebar, and any other persistent chrome keep their\n * in-flight state.\n *\n * Usage in a template's root:\n *\n * const screenKey = useScreenRefreshKey();\n * return (\n * <AppLayout>\n * <div key={screenKey}>\n * <Outlet />\n * </div>\n * </AppLayout>\n * );\n */\nexport function useScreenRefreshKey(\n options: {\n pollUrl?: string;\n sseUrl?: string | false;\n interval?: number;\n fallbackInterval?: number;\n pauseWhenHidden?: boolean;\n } = {},\n): number {\n const {\n pollUrl = agentNativePath(options.pollUrl ?? \"/_agent-native/poll\"),\n sseUrl = resolveSseUrl(options.sseUrl),\n interval = 2000,\n fallbackInterval = Math.max(\n options.fallbackInterval ?? SSE_FALLBACK_INTERVAL_MS,\n interval,\n ),\n pauseWhenHidden = true,\n } = options;\n const [key, setKey] = useState(0);\n\n useEffect(() => {\n const id = Symbol(\"useScreenRefreshKey\");\n // Per-subscriber version cursor (same freshness logic as useDbSync).\n let subscriberVersion = 0;\n\n function onEvents(events: SyncEvent[], version: number | undefined): void {\n const freshEvents = events.filter((event) => {\n const v = typeof event.version === \"number\" ? event.version : 0;\n return v === 0 || v > subscriberVersion;\n });\n if (freshEvents.some((e) => e.source === \"screen-refresh\")) {\n setKey((k) => k + 1);\n }\n const maxEventVersion = freshEvents.reduce(\n (max, event) =>\n Math.max(max, typeof event.version === \"number\" ? event.version : 0),\n 0,\n );\n subscriberVersion = Math.max(\n subscriberVersion,\n version ?? 0,\n maxEventVersion,\n );\n }\n\n const transport = getOrCreateTransport(pollUrl, sseUrl);\n transport.add(id, {\n onEvents,\n pauseWhenHidden,\n interval,\n fallbackInterval,\n });\n\n return () => {\n transport.remove(id);\n if (!transport[\"subscribers\"].size) {\n releaseTransport(pollUrl, sseUrl);\n }\n };\n }, [pollUrl, sseUrl, interval, fallbackInterval, pauseWhenHidden]);\n\n return key;\n}\n"]}
1
+ {"version":3,"file":"use-db-sync.js","sourceRoot":"","sources":["../../src/client/use-db-sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEpD,OAAO,EACL,8BAA8B,EAC9B,+BAA+B,GAChC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EACL,+BAA+B,EAC/B,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAa5D,MAAM,iBAAiB,GAAG,MAAM,CAAC;AACjC,MAAM,wBAAwB,GAAG,MAAM,CAAC;AACxC,MAAM,qBAAqB,GAAG,MAAM,CAAC;AACrC,MAAM,6BAA6B,GAAG,MAAM,CAAC;AAC7C;;;;;GAKG;AACH,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAEnC,MAAM,eAAgB,SAAQ,KAAK;IACjC,MAAM,CAAS;IAEf,YAAY,MAAc;QACxB,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,M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,EACtE,CAAC,CACF,CAAC;YACF,iBAAiB,GAAG,IAAI,CAAC,GAAG,CAC1B,iBAAiB,EACjB,OAAO,IAAI,CAAC,EACZ,eAAe,CAChB,CAAC;QACJ,CAAC;QAED,MAAM,SAAS,GAAG,oBAAoB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACxD,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE;YAChB,QAAQ;YACR,eAAe;YACf,QAAQ;YACR,YAAY;YACZ,gBAAgB;SACjB,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE;YACV,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YACrB,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,IAAI,EAAE,CAAC;gBACnC,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YACpC,CAAC;QACH,CAAC,CAAC;IACJ,CAAC,EAAE;QACD,OAAO;QACP,MAAM;QACN,QAAQ;QACR,YAAY;QACZ,gBAAgB;QAChB,eAAe;KAChB,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { useEffect, useRef, useState } from \"react\";\n\nimport {\n ensureDemoModeFetchInterceptor,\n refreshDemoModeFetchInterceptor,\n} from \"../demo/fetch-interceptor.js\";\nimport { agentNativePath } from \"./api-path.js\";\nimport {\n ensureEmbedAuthFetchInterceptor,\n isEmbedAuthActive,\n} from \"./embed-auth.js\";\nimport { bumpChangeVersion } from \"./use-change-version.js\";\n\ninterface Query {\n queryKey: readonly unknown[];\n}\n\ninterface QueryClient {\n invalidateQueries(opts?: {\n queryKey?: string[];\n predicate?: (query: Query) => boolean;\n }): void;\n}\n\nconst POLL_ABORT_MIN_MS = 10_000;\nconst SSE_FALLBACK_INTERVAL_MS = 15_000;\nconst IDLE_POLL_INTERVAL_MS = 15_000;\nconst POLL_AUTH_FAILURE_COOLDOWN_MS = 60_000;\n/**\n * Max cadence for SSE/poll-driven query invalidation in `useDbSync`. Events\n * that arrive within this window of the first one in a burst are merged into\n * a single `invalidateForEvents` call instead of one call per event — see the\n * `queueInvalidateBatch` comment at the call site.\n */\nconst INVALIDATE_COALESCE_MS = 250;\n\nclass HttpStatusError extends Error {\n status: number;\n\n constructor(status: number) {\n super(\"HTTP \" + status);\n this.status = status;\n }\n}\n\nexport type SyncEvent = {\n version?: number;\n source?: string;\n type?: string;\n key?: string;\n requestSource?: string;\n [k: string]: unknown;\n};\n\ntype PollResponse = {\n version: number;\n events: SyncEvent[];\n};\n\n/** Callback delivered to each transport subscriber for every batch of events. */\ntype EventSubscriber = (\n events: SyncEvent[],\n version: number | undefined,\n) => void;\n\nfunction getPollAbortMs(interval: number): number {\n return Math.max(POLL_ABORT_MIN_MS, interval * 4);\n}\n\nfunction isDocumentHidden(): boolean {\n return (\n typeof document !== \"undefined\" && document.visibilityState === \"hidden\"\n );\n}\n\nfunction resolveSseUrl(sseUrl: string | false | undefined): string | false {\n if (sseUrl === false) return false;\n if (isEmbedAuthActive()) return false;\n return agentNativePath(sseUrl ?? \"/_agent-native/events\");\n}\n\nfunction normalizeEventPayload(payload: unknown): SyncEvent[] {\n if (!payload || typeof payload !== \"object\") return [];\n const record = payload as { type?: unknown; events?: unknown };\n if (record.type === \"batch\" && Array.isArray(record.events)) {\n return record.events.filter(\n (event): event is SyncEvent => !!event && typeof event === \"object\",\n );\n }\n if (Array.isArray(record.events)) {\n return record.events.filter(\n (event): event is SyncEvent => !!event && typeof event === \"object\",\n );\n }\n return [payload as SyncEvent];\n}\n\nfunction isAuthFailure(error: unknown): boolean {\n return (\n !!error &&\n typeof error === \"object\" &&\n \"status\" in error &&\n ((error as { status?: unknown }).status === 401 ||\n (error as { status?: unknown }).status === 403)\n );\n}\n\n/**\n * App-state keys that drive immediate UI navigation/interaction and must\n * never sit behind the invalidation coalesce window (see\n * `isInteractionCriticalSyncEvent`).\n */\nconst INTERACTION_CRITICAL_APP_STATE_KEYS = [\n \"navigate\",\n \"show-questions\",\n \"__set_url__\",\n];\n\n/**\n * True for sync events that drive immediate, agent-initiated UI navigation\n * or interaction rather than passive data invalidation — app-state writes in\n * general (they back `[\"app-state\"]` queries directly), and specifically the\n * `navigate` / `show-questions` / `__set_url__` app-state keys that\n * `invalidateForEvents` special-cases into their own query keys below.\n *\n * `useDbSync` batches ordinary invalidation-driving events (action/collab/db\n * change events) into one flush per `INVALIDATE_COALESCE_MS` so a chatty doc\n * doesn't refetch on every keystroke. That trade-off is wrong for these\n * events: agent-driven navigation, `set-url`, and guided-questions prompts\n * must land as close to instantly as possible, so any batch containing one\n * of these bypasses the coalesce window and flushes immediately instead.\n *\n * Exported as a small pure predicate so this classification is unit-testable\n * independent of the transport/timer plumbing around it.\n */\nexport function isInteractionCriticalSyncEvent(event: SyncEvent): boolean {\n return (\n event.source === \"app-state\" &&\n (event.key === \"*\" ||\n INTERACTION_CRITICAL_APP_STATE_KEYS.some(\n (key) =>\n event.key === key ||\n (typeof event.key === \"string\" && event.key.startsWith(`${key}:`)),\n ))\n );\n}\n\nasync function fetchPollJson<T>(\n pollUrl: string,\n since: number,\n interval: number,\n): Promise<T> {\n const controller =\n typeof AbortController === \"undefined\" ? null : new AbortController();\n const timeout = controller\n ? setTimeout(() => controller.abort(), getPollAbortMs(interval))\n : null;\n\n try {\n const res = await fetch(\n `${pollUrl}?since=${since}`,\n controller ? { signal: controller.signal } : undefined,\n );\n if (!res.ok) throw new HttpStatusError(res.status);\n // Await the json before the finally so a body-stream abort doesn't\n // produce a dangling promise that escapes as an unhandled rejection.\n return await res.json();\n } finally {\n if (timeout) clearTimeout(timeout);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Shared SSE + poll transport\n//\n// One SyncTransport per (pollUrl, sseUrl) pair is held in a module-level\n// registry. Both `useDbSync` and `useScreenRefreshKey` subscribe to it, so a\n// single browser tab opens exactly ONE SSE connection and ONE poll loop\n// regardless of how many hook instances are mounted.\n//\n// Lifecycle: the transport starts when the first subscriber joins and shuts\n// down when the last subscriber leaves. This makes it safe to SSR and to\n// mount/unmount hooks independently.\n// ---------------------------------------------------------------------------\n\ninterface TransportSubscription {\n onEvents: EventSubscriber;\n /**\n * Whether this subscriber wants the transport to pause when the tab is\n * hidden. The transport pauses only when ALL subscribers request it — any\n * subscriber with `pauseWhenHidden: false` keeps the connection alive.\n */\n pauseWhenHidden: boolean;\n /**\n * Requested poll interval in ms. The transport uses the minimum across all\n * subscribers so the most-frequent caller is satisfied.\n */\n interval: number;\n /** Requested poll interval while the tab has no active agent work. */\n idleInterval: number;\n /** Requested fallback interval while SSE is connected. */\n fallbackInterval: number;\n /**\n * Optional: notified when the shared SSE connection opens or closes (also\n * fired once with the current state when the subscriber joins). Lets\n * subscribers with their own fallback loops (e.g. the collab doc poll)\n * relax their cadence while the push path is healthy.\n */\n onSseStateChange?: (connected: boolean) => void;\n}\n\nclass SyncTransport {\n private subscribers = new Map<symbol, TransportSubscription>();\n private versionRef = 0;\n private timer: ReturnType<typeof setTimeout> | null = null;\n private stopped = false;\n private inFlight = false;\n private eventSource: EventSource | null = null;\n private sseConnected = false;\n private authFailureUntil = 0;\n private consecutiveFailures = 0;\n private activeChatIds = new Set<string>();\n\n constructor(\n private readonly pollUrl: string,\n private readonly sseUrl: string | false,\n ) {}\n\n // -------------------------------------------------------------------------\n // Subscriber management\n // -------------------------------------------------------------------------\n\n add(id: symbol, sub: TransportSubscription): void {\n const wasEmpty = this.subscribers.size === 0;\n const wasActive = this.isActive;\n this.subscribers.set(id, sub);\n if (wasEmpty) {\n this.stopped = false;\n this.start();\n } else if (!wasActive && this.isActive) {\n // A collab surface (or other active subscriber) just joined. Catch up\n // immediately rather than waiting out an idle-cadence timer.\n this.pollNow();\n } else {\n this.reschedule();\n }\n sub.onSseStateChange?.(this.sseConnected);\n }\n\n remove(id: symbol): void {\n this.subscribers.delete(id);\n if (this.subscribers.size === 0) {\n this.teardown();\n } else {\n // Recalculate poll interval in case the leaving subscriber was the\n // fastest caller; reschedule with the updated cadence.\n this.reschedule();\n }\n }\n\n // -------------------------------------------------------------------------\n // Derived settings (aggregate over active subscribers)\n // -------------------------------------------------------------------------\n\n private get effectivePauseWhenHidden(): boolean {\n // Pause only if every subscriber has opted in.\n for (const sub of this.subscribers.values()) {\n if (!sub.pauseWhenHidden) return false;\n }\n return true;\n }\n\n private get effectiveInterval(): number {\n let min = Infinity;\n for (const sub of this.subscribers.values()) {\n if (sub.interval < min) min = sub.interval;\n }\n return isFinite(min) ? min : 2000;\n }\n\n private get effectiveIdleInterval(): number {\n let min = Infinity;\n for (const sub of this.subscribers.values()) {\n if (sub.idleInterval < min) min = sub.idleInterval;\n }\n return isFinite(min) ? min : IDLE_POLL_INTERVAL_MS;\n }\n\n private get isActive(): boolean {\n return this.activeChatIds.size > 0;\n }\n\n private get effectiveFallbackInterval(): number {\n let min = Infinity;\n for (const sub of this.subscribers.values()) {\n if (sub.fallbackInterval < min) min = sub.fallbackInterval;\n }\n return isFinite(min) ? min : SSE_FALLBACK_INTERVAL_MS;\n }\n\n // -------------------------------------------------------------------------\n // Event fan-out\n // -------------------------------------------------------------------------\n\n private fan(events: SyncEvent[], version: number | undefined): void {\n if (\n events.some(\n (event) =>\n event.source === \"app-state\" &&\n (event.key === \"demo-mode\" || event.key === \"*\"),\n )\n ) {\n void refreshDemoModeFetchInterceptor();\n }\n for (const sub of this.subscribers.values()) {\n sub.onEvents(events, version);\n }\n }\n\n private setSseConnected(connected: boolean): void {\n if (this.sseConnected === connected) return;\n this.sseConnected = connected;\n for (const sub of this.subscribers.values()) {\n sub.onSseStateChange?.(connected);\n }\n }\n\n // -------------------------------------------------------------------------\n // SSE + poll loop (mirrors the original per-hook logic exactly)\n // -------------------------------------------------------------------------\n\n private authFailureDelayMs(): number {\n return Math.max(0, this.authFailureUntil - Date.now());\n }\n\n private schedulePoll(): void {\n if (this.stopped) return;\n if (this.effectivePauseWhenHidden && isDocumentHidden()) return;\n if (this.timer) clearTimeout(this.timer);\n const authDelay = this.authFailureDelayMs();\n if (authDelay > 0) {\n this.timer = setTimeout(() => {\n this.timer = null;\n void this.poll();\n }, authDelay);\n return;\n }\n const base = this.isActive\n ? this.effectiveInterval\n : this.sseConnected\n ? this.effectiveFallbackInterval\n : this.effectiveIdleInterval;\n // Exponential backoff while polls keep failing (500s during a deploy,\n // DNS blips, a struggling DB). Auth failures have their own cooldown\n // above; this covers everything else so a down server isn't hammered at\n // full cadence. Resets on the first successful poll.\n const delay =\n this.consecutiveFailures > 0\n ? Math.min(base * 2 ** Math.min(this.consecutiveFailures, 5), 30_000)\n : base;\n this.timer = setTimeout(() => {\n this.timer = null;\n void this.poll();\n }, delay);\n }\n\n private reschedule(): void {\n // Only need to act if a timer is already pending; next natural tick will\n // pick up the new effective interval otherwise.\n if (this.timer !== null) {\n clearTimeout(this.timer);\n this.timer = null;\n this.schedulePoll();\n }\n }\n\n private closeEvents(): void {\n if (!this.eventSource) return;\n this.eventSource.close();\n this.eventSource = null;\n this.setSseConnected(false);\n }\n\n private connectEvents(): void {\n if (\n this.stopped ||\n !this.sseUrl ||\n this.eventSource ||\n typeof EventSource === \"undefined\" ||\n (this.effectivePauseWhenHidden && isDocumentHidden())\n ) {\n return;\n }\n\n const source = new EventSource(this.sseUrl);\n this.eventSource = source;\n source.onopen = () => {\n this.setSseConnected(true);\n this.schedulePoll();\n };\n source.onerror = () => {\n this.setSseConnected(false);\n // When the browser gives up permanently (HTTP error → readyState\n // CLOSED), it won't auto-reconnect. Drop the ref so a later\n // connectEvents() (on focus/visibility) can establish a fresh stream;\n // otherwise the non-null closed `eventSource` blocks reconnection and\n // we'd be stuck on polling-only forever.\n if (source.readyState === EventSource.CLOSED) {\n this.eventSource = null;\n }\n this.schedulePoll();\n };\n source.onmessage = (message) => {\n try {\n const payload = JSON.parse(message.data);\n const events = normalizeEventPayload(payload);\n const version =\n typeof payload?.version === \"number\" ? payload.version : undefined;\n this.applyVersion(events, version);\n this.fan(events, version);\n } catch {\n // Ignore malformed SSE frames; polling is the safety net.\n }\n };\n }\n\n /**\n * Advance the transport's shared version cursor. Subscribers receive the\n * raw events and decide independently which ones are \"fresh\" relative to\n * their own cursor, but the transport-level cursor ensures the poll\n * `?since=` parameter always advances.\n */\n private applyVersion(events: SyncEvent[], version: number | undefined): void {\n let max = typeof version === \"number\" ? version : 0;\n for (const evt of events) {\n const v = typeof evt.version === \"number\" ? evt.version : 0;\n if (v > max) max = v;\n }\n if (max > this.versionRef) this.versionRef = max;\n }\n\n private async poll(): Promise<void> {\n if (this.stopped || this.inFlight) return;\n this.inFlight = true;\n try {\n const data = await fetchPollJson<PollResponse>(\n this.pollUrl,\n this.versionRef,\n this.effectiveInterval,\n );\n if (this.stopped) return;\n this.consecutiveFailures = 0;\n const events = data.events ?? [];\n this.applyVersion(events, data.version);\n this.fan(events, data.version);\n } catch (err) {\n if (this.stopped) return;\n this.consecutiveFailures++;\n if (isAuthFailure(err)) {\n this.authFailureUntil = Date.now() + POLL_AUTH_FAILURE_COOLDOWN_MS;\n this.closeEvents();\n }\n // Network error — retried on the next (backed-off) interval.\n } finally {\n this.inFlight = false;\n this.schedulePoll();\n }\n }\n\n private pollNow(): void {\n if (this.effectivePauseWhenHidden && isDocumentHidden()) return;\n if (this.authFailureDelayMs() > 0) {\n this.schedulePoll();\n return;\n }\n if (this.timer) {\n clearTimeout(this.timer);\n this.timer = null;\n }\n this.connectEvents();\n void this.poll();\n }\n\n private handleVisibilityChange = (): void => {\n if (document.visibilityState === \"visible\") {\n this.connectEvents();\n this.pollNow();\n } else if (this.effectivePauseWhenHidden) {\n this.closeEvents();\n if (this.timer) {\n clearTimeout(this.timer);\n this.timer = null;\n }\n }\n };\n\n private handleFocus = (): void => {\n this.pollNow();\n };\n\n private handleChatRunning = (event: Event): void => {\n const detail = (\n event as CustomEvent<{\n isRunning?: unknown;\n running?: unknown;\n tabId?: unknown;\n }>\n ).detail;\n const running =\n typeof detail?.isRunning === \"boolean\"\n ? detail.isRunning\n : typeof detail?.running === \"boolean\"\n ? detail.running\n : null;\n if (running === null) return;\n\n const id =\n typeof detail?.tabId === \"string\" && detail.tabId\n ? detail.tabId\n : \"__default__\";\n const wasActive = this.isActive;\n if (running) this.activeChatIds.add(id);\n else this.activeChatIds.delete(id);\n if (wasActive === this.isActive) return;\n\n if (this.isActive) {\n // Run start is a high-signal indication that cross-process writes are\n // imminent. Catch up now, then stay on the active cadence.\n this.pollNow();\n } else {\n this.reschedule();\n }\n };\n\n private start(): void {\n // Universal demo-mode redaction for the UI. Idempotent + browser-only +\n // a no-op until demo mode is on. Lives here because every template root\n // already mounts useDbSync, so this needs zero per-template wiring.\n ensureEmbedAuthFetchInterceptor();\n ensureDemoModeFetchInterceptor();\n\n if (!this.effectivePauseWhenHidden || !isDocumentHidden()) {\n this.connectEvents();\n void this.poll();\n }\n window.addEventListener(\"focus\", this.handleFocus);\n window.addEventListener(\"agentNative.chatRunning\", this.handleChatRunning);\n document.addEventListener(\"visibilitychange\", this.handleVisibilityChange);\n }\n\n private teardown(): void {\n this.stopped = true;\n this.closeEvents();\n if (this.timer) {\n clearTimeout(this.timer);\n this.timer = null;\n }\n window.removeEventListener(\"focus\", this.handleFocus);\n window.removeEventListener(\n \"agentNative.chatRunning\",\n this.handleChatRunning,\n );\n document.removeEventListener(\n \"visibilitychange\",\n this.handleVisibilityChange,\n );\n }\n}\n\n/**\n * Registry of active transports keyed by \"<pollUrl>\\0<sseUrl>\".\n * Module-level singleton: survives React render cycles, shared across all\n * hook instances in the same browser tab.\n */\nconst transportRegistry = new Map<string, SyncTransport>();\n\nfunction getOrCreateTransport(\n pollUrl: string,\n sseUrl: string | false,\n): SyncTransport {\n const key = `${pollUrl}\\0${String(sseUrl)}`;\n let transport = transportRegistry.get(key);\n if (!transport) {\n transport = new SyncTransport(pollUrl, sseUrl);\n transportRegistry.set(key, transport);\n }\n return transport;\n}\n\n/** Remove a transport from the registry once torn down (last subscriber left). */\nfunction releaseTransport(pollUrl: string, sseUrl: string | false): void {\n const key = `${pollUrl}\\0${String(sseUrl)}`;\n // Leave the entry in place: SSE/poll is already stopped inside the class;\n // the next subscriber will re-start it via `add()`. Clearing the map entry\n // prevents any dangling reference from the old SyncTransport instance.\n transportRegistry.delete(key);\n}\n\n// ---------------------------------------------------------------------------\n// Internal test helper — reset transport registry between tests.\n// ---------------------------------------------------------------------------\n/** @internal */\nexport function _resetSyncTransportRegistryForTests(): void {\n transportRegistry.clear();\n}\n\nexport interface SubscribeSyncEventsOptions {\n /** Receives every batch of change events (SSE push or poll). */\n onEvents: (events: SyncEvent[], version: number | undefined) => void;\n /** Notified when the shared SSE connection opens/closes (and once on join). */\n onSseStateChange?: (connected: boolean) => void;\n pollUrl?: string;\n sseUrl?: string | false;\n pauseWhenHidden?: boolean;\n /**\n * Poll cadence this subscriber requests from the SHARED poll loop. The\n * transport uses the minimum across subscribers, so the defaults here are\n * deliberately high: subscribing must not speed up the shared poll —\n * useDbSync (mounted by every template root) already sets the pace.\n */\n interval?: number;\n fallbackInterval?: number;\n}\n\n/**\n * Subscribe to the shared SSE + poll transport without the React Query\n * invalidation behavior of `useDbSync`. Use this instead of opening another\n * `EventSource` to `/_agent-native/events` — a browser tab should hold ONE\n * SSE connection no matter how many features listen to it (extra streams eat\n * the per-origin connection budget and starve data fetches, especially on\n * HTTP/1.1 dev servers).\n *\n * Returns an unsubscribe function. Safe to call only in browser contexts.\n */\nexport function subscribeSyncEvents(\n options: SubscribeSyncEventsOptions,\n): () => void {\n const pollUrl = agentNativePath(options.pollUrl ?? \"/_agent-native/poll\");\n const sseUrl = resolveSseUrl(options.sseUrl);\n const transport = getOrCreateTransport(pollUrl, sseUrl);\n const id = Symbol(\"subscribeSyncEvents\");\n transport.add(id, {\n onEvents: options.onEvents,\n onSseStateChange: options.onSseStateChange,\n pauseWhenHidden: options.pauseWhenHidden ?? true,\n interval: options.interval ?? 60_000,\n idleInterval: options.interval ?? 60_000,\n fallbackInterval: options.fallbackInterval ?? 60_000,\n });\n return () => {\n transport.remove(id);\n if (!transport[\"subscribers\"].size) {\n releaseTransport(pollUrl, sseUrl);\n }\n };\n}\n\n/**\n * Hook that listens to /_agent-native/events for DB change events and\n * invalidates react-query caches when changes are detected. Falls back to\n * /_agent-native/poll so cross-process/serverless writes still show up.\n *\n * Works in all deployment environments (serverless, edge, long-lived server).\n * SSE is the fast path; polling is the safety net.\n *\n * @param options.queryClient - The react-query QueryClient instance\n * @param options.queryKeys - **Deprecated and ignored.** The hook uses\n * framework-owned fixed prefixes plus per-source change counters instead of\n * caller-supplied key lists. Kept in the type signature for backward\n * compatibility — existing call sites that still pass this option keep\n * working but the value has no effect.\n * @param options.pollUrl - Poll endpoint URL. Default: \"/_agent-native/poll\"\n * @param options.sseUrl - SSE endpoint URL. Default: \"/_agent-native/events\".\n * Pass false to disable SSE and use polling only.\n * @param options.onEvent - Optional callback for each change event\n * @param options.interval - Poll interval in ms. Default: 2000\n * @param options.fallbackInterval - Poll interval while SSE is connected.\n * Default: 15000\n * @param options.pauseWhenHidden - Pause polling while the tab is hidden.\n * Default: true\n * @param options.ignoreSource - Skip events whose `requestSource` matches this\n * value. Use a per-tab ID so the UI ignores its own writes while still\n * picking up changes from other tabs, agents, and scripts.\n * @param options.actionInvalidatePredicate - Optional filter for the broad\n * compatibility invalidate triggered by `action` events. Use this to keep\n * expensive active queries on explicit-refresh semantics while still letting\n * normal source-versioned queries react through `useChangeVersion`.\n * @param options.suppressActionInvalidationFor - Action names whose sync events\n * should not invalidate all action queries. Use only for high-volume\n * background actions that perform their own narrow client invalidation.\n */\nexport function useDbSync(\n options: {\n queryClient?: QueryClient;\n queryKeys?: string[];\n pollUrl?: string;\n sseUrl?: string | false;\n /** @deprecated Use pollUrl instead */\n eventsUrl?: string;\n onEvent?: (data: any) => void;\n interval?: number;\n fallbackInterval?: number;\n pauseWhenHidden?: boolean;\n ignoreSource?: string;\n actionInvalidatePredicate?: (query: Query) => boolean;\n suppressActionInvalidationFor?: string[];\n } = {},\n): void {\n const {\n queryClient,\n pollUrl = agentNativePath(options.eventsUrl ?? \"/_agent-native/poll\"),\n sseUrl = resolveSseUrl(options.sseUrl),\n interval = 2000,\n fallbackInterval = Math.max(\n options.fallbackInterval ?? SSE_FALLBACK_INTERVAL_MS,\n interval,\n ),\n pauseWhenHidden = true,\n } = options;\n const idleInterval =\n options.interval === undefined ? IDLE_POLL_INTERVAL_MS : interval;\n\n const onEventRef = useRef(options.onEvent);\n onEventRef.current = options.onEvent;\n\n const ignoreSourceRef = useRef(options.ignoreSource);\n ignoreSourceRef.current = options.ignoreSource;\n const actionInvalidatePredicateRef = useRef(\n options.actionInvalidatePredicate,\n );\n actionInvalidatePredicateRef.current = options.actionInvalidatePredicate;\n const suppressActionInvalidationForRef = useRef(\n options.suppressActionInvalidationFor,\n );\n suppressActionInvalidationForRef.current =\n options.suppressActionInvalidationFor;\n\n useEffect(() => {\n const id = Symbol(\"useDbSync\");\n // Per-subscriber version cursor: tracks which events have already been\n // processed by THIS subscriber so stale poll re-deliveries are ignored.\n let subscriberVersion = 0;\n\n // Coalesce bursts of SSE-driven invalidation into at most one flush per\n // INVALIDATE_COALESCE_MS. A chatty doc (many small agent edits, several\n // peers editing at once) can otherwise deliver a handful of `action`/\n // `collab` events within a few hundred ms, each independently calling\n // `queryClient.invalidateQueries` and firing `onEvent` — every one of\n // those touches whatever query subscribers are mounted (e.g. a\n // full-page editor) even though the end state only needs to be\n // refreshed once. Version bookkeeping stays synchronous (below) so\n // freshness filtering for the NEXT batch is unaffected by the delay.\n //\n // This coalesce window is wrong for interaction-critical events (agent\n // navigation, `set-url`, guided questions — see\n // `isInteractionCriticalSyncEvent`): those must reach the UI immediately,\n // not up to INVALIDATE_COALESCE_MS late. So a fresh batch containing one\n // of those flushes synchronously (queued + new events together,\n // canceling any pending timer) instead of joining the coalesce window.\n // Pure invalidation bursts with no interaction-critical members keep the\n // coalesced behavior.\n let pendingInvalidateEvents: SyncEvent[] = [];\n let invalidateTimer: ReturnType<typeof setTimeout> | null = null;\n\n function flushInvalidateBatch() {\n if (invalidateTimer) {\n clearTimeout(invalidateTimer);\n invalidateTimer = null;\n }\n if (pendingInvalidateEvents.length === 0) return;\n const batch = pendingInvalidateEvents;\n pendingInvalidateEvents = [];\n invalidateForEvents(batch);\n }\n\n function queueInvalidateBatch(events: SyncEvent[]) {\n pendingInvalidateEvents.push(...events);\n if (events.some(isInteractionCriticalSyncEvent)) {\n flushInvalidateBatch();\n return;\n }\n if (invalidateTimer) return;\n invalidateTimer = setTimeout(\n flushInvalidateBatch,\n INVALIDATE_COALESCE_MS,\n );\n }\n\n function hasAppStateEvent(events: SyncEvent[], key: string): boolean {\n return events.some(\n (event) =>\n event.source === \"app-state\" &&\n (event.key === key ||\n event.key === \"*\" ||\n (typeof event.key === \"string\" && event.key.startsWith(`${key}:`))),\n );\n }\n\n function invalidateForEvents(events: SyncEvent[]) {\n const ignore = ignoreSourceRef.current;\n const relevant = ignore\n ? events.filter((e) => e.requestSource !== ignore)\n : events;\n const suppressedActions = new Set(\n suppressActionInvalidationForRef.current ?? [],\n );\n const isSuppressedActionEvent = (evt: SyncEvent) =>\n evt.source === \"action\" &&\n typeof evt.key === \"string\" &&\n suppressedActions.has(evt.key);\n const nonAwareness = relevant.filter((e) => e.source !== \"awareness\");\n const suppressesWholeBatch =\n nonAwareness.length > 0 &&\n nonAwareness.every((evt) => evt.source === \"action\") &&\n nonAwareness.every(isSuppressedActionEvent);\n\n // Bump per-source change counters. Components that read these via\n // `useChangeVersion(source)` and fold the value into a React Query\n // queryKey get a targeted refetch — no whole-cache invalidate, no\n // request storm. See `use-change-version.ts` for the contract.\n for (const evt of relevant) {\n const src = typeof evt.source === \"string\" ? evt.source : \"\";\n const ver = typeof evt.version === \"number\" ? evt.version : 0;\n if (src && ver > 0) {\n bumpChangeVersion(src, ver);\n if (typeof evt.key === \"string\" && evt.key) {\n bumpChangeVersion(`${src}:${evt.key}`, ver);\n }\n }\n }\n\n // Awareness (cursor/presence) events never change action/extension/\n // app-state query results, but they arrive on every peer keystroke and\n // carry no version (so the freshness filter always passes them). Keep\n // them out of the invalidate block or an idle collaborative doc turns\n // every peer's cursor move into a framework-wide refetch storm; they\n // still reach onEvent below for callers that render presence.\n const invalidating = relevant.filter((e) => e.source !== \"awareness\");\n\n if (invalidating.length > 0 && queryClient) {\n const hasActionEvent = invalidating.some(\n (evt) => evt.source === \"action\" && !isSuppressedActionEvent(evt),\n );\n if (hasActionEvent) {\n // Custom apps frequently start with raw `useQuery` calls before\n // graduating to `useActionQuery` or source-versioned query keys.\n // A successful mutating action is the core \"agent changed app data\"\n // signal, so refresh active queries broadly as a compatibility\n // safety net. Other event sources stay targeted to avoid request\n // storms from noisy domain-specific writes.\n const predicate = actionInvalidatePredicateRef.current;\n queryClient.invalidateQueries(predicate ? { predicate } : undefined);\n }\n\n // Framework-level invalidate: a small, fixed list of query-key\n // prefixes the framework's own hooks/components use (action results,\n // extension state, application-state, the agent's `set-url` channel,\n // etc.). Templates' own data queries do NOT live here — they react\n // through `useChangeVersion(source)` in their query keys instead, so\n // a single change event doesn't fan out into \"refetch everything\".\n // Suppressed-action-only batches skip this whole list (their\n // mutations perform their own narrow invalidation) — but events must\n // STILL reach the onEvent forwarding below, so guard, don't return.\n //\n // Invalidation is scoped by source. Data-query prefixes (action,\n // extension, tool) refetch only when the batch carries an event that\n // can actually change action/extension-backed data — action\n // mutations, settings, extension, collab, screen-refresh, etc.\n // `app-state` events (agent/UI navigation, selection, and the\n // set-url/questions command channel) drive their OWN keys below and\n // must NEVER fan out into \"refetch every action query\": an active\n // agent session mirrors navigation + selection into application_state\n // continuously, and the serverless poll path replays those writes\n // back to the originating tab (the DB-scan fallback cannot preserve\n // `requestSource`, so `ignoreSource` can't filter them). Fanning each\n // one into a full `[\"action\"]` refetch turned a normal session into a\n // client fetch storm that exhausted the DB connection pool — which in\n // turn starved run heartbeat writes and surfaced as `stale_run`.\n if (!suppressesWholeBatch) {\n const hasDataChangingEvent = invalidating.some(\n (evt) => evt.source !== \"app-state\",\n );\n // The broad action invalidate above already covers every fixed\n // framework prefix. Re-invalidating [\"action\"] immediately after it\n // cancels/restarts the same active reads and creates a duplicate\n // request wave. Keep the fixed-prefix pass for non-action sources;\n // action batches get exactly one compatibility invalidation.\n if (hasDataChangingEvent && !hasActionEvent) {\n queryClient.invalidateQueries({ queryKey: [\"action\"] });\n queryClient.invalidateQueries({ queryKey: [\"extension\"] });\n queryClient.invalidateQueries({ queryKey: [\"extensions\"] });\n queryClient.invalidateQueries({ queryKey: [\"extension-slots\"] });\n queryClient.invalidateQueries({ queryKey: [\"slot-installs\"] });\n queryClient.invalidateQueries({ queryKey: [\"slot-available\"] });\n queryClient.invalidateQueries({ queryKey: [\"tool\"] });\n queryClient.invalidateQueries({ queryKey: [\"tools\"] });\n }\n if (invalidating.some((evt) => evt.source === \"app-state\")) {\n queryClient.invalidateQueries({ queryKey: [\"app-state\"] });\n }\n if (hasAppStateEvent(invalidating, \"navigate\")) {\n queryClient.invalidateQueries({ queryKey: [\"navigate-command\"] });\n }\n if (hasAppStateEvent(invalidating, \"show-questions\")) {\n queryClient.invalidateQueries({ queryKey: [\"show-questions\"] });\n }\n if (hasAppStateEvent(invalidating, \"__set_url__\")) {\n queryClient.invalidateQueries({ queryKey: [\"__set_url__\"] });\n }\n }\n }\n\n // Always forward all events to onEvent — templates can layer surgical\n // logic on top (e.g. ignore their own writes via requestSource, or\n // invalidate inactive queries for a specific source).\n for (const evt of events) {\n onEventRef.current?.(evt);\n }\n }\n\n function onEvents(events: SyncEvent[], version: number | undefined): void {\n const freshEvents = events.filter((event) => {\n const v = typeof event.version === \"number\" ? event.version : 0;\n return v === 0 || v > subscriberVersion;\n });\n\n if (freshEvents.length > 0) {\n queueInvalidateBatch(freshEvents);\n }\n\n const maxEventVersion = freshEvents.reduce(\n (max, event) =>\n Math.max(max, typeof event.version === \"number\" ? event.version : 0),\n 0,\n );\n subscriberVersion = Math.max(\n subscriberVersion,\n version ?? 0,\n maxEventVersion,\n );\n }\n\n const transport = getOrCreateTransport(pollUrl, sseUrl);\n transport.add(id, {\n onEvents,\n pauseWhenHidden,\n interval,\n idleInterval,\n fallbackInterval,\n });\n\n return () => {\n if (invalidateTimer) {\n clearTimeout(invalidateTimer);\n // Flush synchronously on unmount so a pending batch isn't silently\n // dropped (e.g. a route change right after an agent edit lands).\n flushInvalidateBatch();\n }\n transport.remove(id);\n // If the registry still holds this transport, and the transport is now\n // empty, evict it so the next mount gets a fresh instance rather than a\n // stopped-but-still-registered one (the registry entry being cleared by\n // releaseTransport is the signal to rebuild state).\n if (!transport[\"subscribers\"].size) {\n releaseTransport(pollUrl, sseUrl);\n }\n };\n }, [\n pollUrl,\n sseUrl,\n queryClient,\n interval,\n idleInterval,\n fallbackInterval,\n pauseWhenHidden,\n ]);\n}\n\n/** @deprecated Use useDbSync instead */\nexport const useFileWatcher = useDbSync;\n\n/**\n * Subscribe to `refresh-screen` events from the agent. Returns an integer\n * that increments every time the agent invokes the framework's `refresh-screen`\n * tool. Apply it as a React `key` on the main content wrapper (the part\n * OUTSIDE the agent chat sidebar) so that region remounts and re-fetches its\n * data while the chat, sidebar, and any other persistent chrome keep their\n * in-flight state.\n *\n * Usage in a template's root:\n *\n * const screenKey = useScreenRefreshKey();\n * return (\n * <AppLayout>\n * <div key={screenKey}>\n * <Outlet />\n * </div>\n * </AppLayout>\n * );\n */\nexport function useScreenRefreshKey(\n options: {\n pollUrl?: string;\n sseUrl?: string | false;\n interval?: number;\n fallbackInterval?: number;\n pauseWhenHidden?: boolean;\n } = {},\n): number {\n const {\n pollUrl = agentNativePath(options.pollUrl ?? \"/_agent-native/poll\"),\n sseUrl = resolveSseUrl(options.sseUrl),\n interval = 2000,\n fallbackInterval = Math.max(\n options.fallbackInterval ?? SSE_FALLBACK_INTERVAL_MS,\n interval,\n ),\n pauseWhenHidden = true,\n } = options;\n const idleInterval =\n options.interval === undefined ? IDLE_POLL_INTERVAL_MS : interval;\n const [key, setKey] = useState(0);\n\n useEffect(() => {\n const id = Symbol(\"useScreenRefreshKey\");\n // Per-subscriber version cursor (same freshness logic as useDbSync).\n let subscriberVersion = 0;\n\n function onEvents(events: SyncEvent[], version: number | undefined): void {\n const freshEvents = events.filter((event) => {\n const v = typeof event.version === \"number\" ? event.version : 0;\n return v === 0 || v > subscriberVersion;\n });\n if (freshEvents.some((e) => e.source === \"screen-refresh\")) {\n setKey((k) => k + 1);\n }\n const maxEventVersion = freshEvents.reduce(\n (max, event) =>\n Math.max(max, typeof event.version === \"number\" ? event.version : 0),\n 0,\n );\n subscriberVersion = Math.max(\n subscriberVersion,\n version ?? 0,\n maxEventVersion,\n );\n }\n\n const transport = getOrCreateTransport(pollUrl, sseUrl);\n transport.add(id, {\n onEvents,\n pauseWhenHidden,\n interval,\n idleInterval,\n fallbackInterval,\n });\n\n return () => {\n transport.remove(id);\n if (!transport[\"subscribers\"].size) {\n releaseTransport(pollUrl, sseUrl);\n }\n };\n }, [\n pollUrl,\n sseUrl,\n interval,\n idleInterval,\n fallbackInterval,\n pauseWhenHidden,\n ]);\n\n return key;\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import { type CodeAgentFollowUpMode, type CodeAgentPermissionMode } from "../cli/code-agent-runs.js";
2
2
  import type { ReasoningEffort } from "../shared/reasoning-effort.js";
3
3
  import { type BackgroundAgentRun, type BackgroundAgentTranscriptEvent, type ListBackgroundAgentRunsOptions } from "./background-run.js";
4
- export type BackgroundAgentControlCommand = "approve" | "resume" | "retry" | "stop";
4
+ export type BackgroundAgentControlCommand = "approve" | "deny" | "resume" | "retry" | "stop";
5
5
  export interface BackgroundAgentControlInput {
6
6
  runId: string;
7
7
  command: BackgroundAgentControlCommand;
@@ -1 +1 @@
1
- {"version":3,"file":"background-controller.d.ts","sourceRoot":"","sources":["../../src/code-agents/background-controller.ts"],"names":[],"mappings":"AAIA,OAAO,EAML,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC7B,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAKL,KAAK,kB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BAA8B,EAAE,CAAC,GACzC,8BAA8B,EAAE,CAAC;IACrC,YAAY,CACV,KAAK,EAAE,4BAA4B,GAClC,OAAO,CAAC,4BAA4B,CAAC,CAAC;IACzC,OAAO,CACL,KAAK,EAAE,2BAA2B,GACjC,OAAO,CAAC,4BAA4B,CAAC,CAAC;CAC1C;AAED,wBAAgB,wCAAwC,CACtD,WAAW,EAAE,yBAAyB,EAAE,GACvC,yBAAyB,CA4C3B;AAED,wBAAgB,wCAAwC,IAAI,yBAAyB,CAQpF;AAED,eAAO,MAAM,kCAAkC,2BACH,CAAC"}
1
+ {"version":3,"file":"background-controller.d.ts","sourceRoot":"","sources":["../../src/code-agents/background-controller.ts"],"names":[],"mappings":"AAKA,OAAO,EAML,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC7B,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAKL,KAAK,kBAAkB,EACvB,KAAK,8BAA8B,EACnC,KAAK,8BAA8B,EACpC,MAAM,qBAAqB,CAAC;AAG7B,MAAM,MAAM,6BAA6B,GACrC,SAAS,GACT,MAAM,GACN,QAAQ,GACR,OAAO,GACP,MAAM,CAAC;AAEX,MAAM,WAAW,2BAA2B;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,6BAA6B,CAAC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;CAChC;AAED,MAAM,WAAW,4BAA4B;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,qBAAqB,CAAC;IAC7B,cAAc,CAAC,EAAE,uBAAuB,CAAC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;CAChC;AAED,MAAM,WAAW,4BAA4B;IAC3C,EAAE,EAAE,OAAO,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAC/B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,yBAAyB;IACxC,IAAI,CACF,OAAO,CAAC,EAAE,8BAA8B,GACvC,OAAO,CAAC,kBAAkB,EAAE,CAAC,GAAG,kBAAkB,EAAE,CAAC;IACxD,GAAG,CACD,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,GAAG,kBAAkB,GAAG,IAAI,CAAC;IAClE,UAAU,CACR,KAAK,EAAE,MAAM,GAEX,OAAO,CAAC,8BAA8B,EAAE,CAAC,GACzC,8BAA8B,EAAE,CAAC;IACrC,YAAY,CACV,KAAK,EAAE,4BAA4B,GAClC,OAAO,CAAC,4BAA4B,CAAC,CAAC;IACzC,OAAO,CACL,KAAK,EAAE,2BAA2B,GACjC,OAAO,CAAC,4BAA4B,CAAC,CAAC;CAC1C;AAED,wBAAgB,wCAAwC,CACtD,WAAW,EAAE,yBAAyB,EAAE,GACvC,yBAAyB,CA4C3B;AAED,wBAAgB,wCAAwC,IAAI,yBAAyB,CAQpF;AAED,eAAO,MAAM,kCAAkC,2BACH,CAAC"}
@@ -1,4 +1,4 @@
1
- import { executeExistingCodeAgentRun, executePendingCodeAgentApproval, } from "../cli/code-agent-executor.js";
1
+ import { executeDenyCodeAgentApproval, executeExistingCodeAgentRun, executePendingCodeAgentApproval, } from "../cli/code-agent-executor.js";
2
2
  import { appendCodeAgentTranscriptEvent, getCodeAgentRunRecord, isActiveCodeAgentRun, queueCodeAgentFollowUp, updateCodeAgentRunRecord, } from "../cli/code-agent-runs.js";
3
3
  import { getBackgroundAgentRun, listBackgroundAgentRuns, listBackgroundAgentTranscriptEvents, toBackgroundAgentRun, } from "./background-run.js";
4
4
  export function createCompositeBackgroundAgentController(controllers) {
@@ -146,6 +146,22 @@ async function controlLocalCodeBackgroundAgentRun(input) {
146
146
  error: approved ? undefined : `Run not found: ${run.id}`,
147
147
  };
148
148
  }
149
+ case "deny": {
150
+ const denied = await executeDenyCodeAgentApproval(run.id, {
151
+ stdout: input.stdout,
152
+ });
153
+ return {
154
+ ok: Boolean(denied),
155
+ runId: run.id,
156
+ run: denied
157
+ ? toBackgroundAgentRun(denied)
158
+ : currentBackgroundRun(run.id),
159
+ message: denied
160
+ ? "Pending approval denied for the Agent-Native Code run."
161
+ : undefined,
162
+ error: denied ? undefined : `Run not found: ${run.id}`,
163
+ };
164
+ }
149
165
  case "resume":
150
166
  case "retry": {
151
167
  // A control action must return immediately — awaiting