@agent-native/core 0.121.2 → 0.122.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 (460) hide show
  1. package/corpus/README.md +2 -2
  2. package/corpus/core/CHANGELOG.md +139 -0
  3. package/corpus/core/docs/content/actions.mdx +2 -2
  4. package/corpus/core/docs/content/agent-surfaces.mdx +1 -1
  5. package/corpus/core/docs/content/authentication.mdx +2 -0
  6. package/corpus/core/docs/content/deployment.mdx +36 -0
  7. package/corpus/core/docs/content/http-api.mdx +266 -0
  8. package/corpus/core/docs/content/syncing-template-changes.mdx +159 -0
  9. package/corpus/core/package.json +2 -1
  10. package/corpus/core/src/a2a/activity.ts +38 -27
  11. package/corpus/core/src/agent/engine/builder-engine.ts +35 -4
  12. package/corpus/core/src/agent/run-manager.ts +20 -1
  13. package/corpus/core/src/agent/run-store.ts +4 -1
  14. package/corpus/core/src/agent/types.ts +28 -8
  15. package/corpus/core/src/chat-threads/store.ts +45 -0
  16. package/corpus/core/src/checkpoints/index.ts +2 -0
  17. package/corpus/core/src/checkpoints/route-match.ts +13 -0
  18. package/corpus/core/src/cli/create.ts +105 -17
  19. package/corpus/core/src/cli/index.ts +20 -0
  20. package/corpus/core/src/cli/template-baseline.ts +410 -0
  21. package/corpus/core/src/cli/template-sync.ts +1004 -0
  22. package/corpus/core/src/cli/templates-meta.ts +1 -0
  23. package/corpus/core/src/client/AssistantChat.tsx +38 -12
  24. package/corpus/core/src/client/NewWorkspaceAppFlow.tsx +75 -10
  25. package/corpus/core/src/client/chat/message-components.tsx +127 -66
  26. package/corpus/core/src/client/chat/tool-call-display.tsx +29 -5
  27. package/corpus/core/src/client/error-format.ts +18 -0
  28. package/corpus/core/src/client/org/OrgSwitcher.tsx +30 -8
  29. package/corpus/core/src/client/org/TeamPage.tsx +7 -6
  30. package/corpus/core/src/client/sse-event-processor.ts +3 -0
  31. package/corpus/core/src/data-widgets/index.ts +41 -0
  32. package/corpus/core/src/deploy/build.ts +11 -9
  33. package/corpus/core/src/integrations/webhook-handler.ts +63 -9
  34. package/corpus/core/src/org/auto-join-domain.ts +4 -3
  35. package/corpus/core/src/org/context.ts +108 -39
  36. package/corpus/core/src/org/index.ts +5 -0
  37. package/corpus/core/src/org/service-identity.ts +60 -0
  38. package/corpus/core/src/provider-api/index.ts +22 -1
  39. package/corpus/core/src/scripts/docs/search.ts +12 -1
  40. package/corpus/core/src/server/agent-chat/context-tools.ts +9 -4
  41. package/corpus/core/src/server/agent-chat/framework-prompts.ts +38 -66
  42. package/corpus/core/src/server/agent-chat-plugin.ts +17 -10
  43. package/corpus/core/src/server/agents-bundle.ts +84 -5
  44. package/corpus/core/src/server/auth.ts +4 -3
  45. package/corpus/core/src/server/builder-browser.ts +47 -19
  46. package/corpus/core/src/server/core-routes-plugin.ts +2 -2
  47. package/corpus/core/src/server/credential-provider.ts +209 -68
  48. package/corpus/core/src/server/index.ts +3 -0
  49. package/corpus/core/src/server/prompts/framework-core-compact.ts +6 -13
  50. package/corpus/core/src/server/prompts/framework-core.ts +9 -21
  51. package/corpus/core/src/server/prompts/index.ts +0 -1
  52. package/corpus/core/src/server/prompts/shared-rules.ts +19 -11
  53. package/corpus/core/src/server/ssr-handler.ts +13 -2
  54. package/corpus/core/src/settings/user-settings.ts +13 -1
  55. package/corpus/core/src/shared/cache-control.ts +141 -0
  56. package/corpus/core/src/templates/chat/.agents/skills/upgrade-agent-native/SKILL.md +24 -2
  57. package/corpus/core/src/templates/chat/_gitignore +1 -0
  58. package/corpus/core/src/templates/default/.agents/skills/upgrade-agent-native/SKILL.md +24 -2
  59. package/corpus/core/src/templates/headless/.agents/skills/upgrade-agent-native/SKILL.md +24 -2
  60. package/corpus/core/src/templates/workspace-core/.agents/skills/performance/SKILL.md +19 -0
  61. package/corpus/core/src/templates/workspace-core/.agents/skills/upgrade-agent-native/SKILL.md +24 -2
  62. package/corpus/core/src/templates/workspace-core/.agents/skills/visual-answer/SKILL.md +1 -0
  63. package/corpus/core/src/vite/agents-bundle-plugin.ts +7 -6
  64. package/corpus/core/src/vite/client.ts +5 -0
  65. package/corpus/templates/analytics/.agents/skills/adhoc-analysis/SKILL.md +4 -5
  66. package/corpus/templates/analytics/.agents/skills/admin-surfaces/SKILL.md +55 -0
  67. package/corpus/templates/analytics/.agents/skills/dashboard-management/SKILL.md +10 -0
  68. package/corpus/templates/analytics/.agents/skills/dashboard-management/references/template-catalog-and-demo.md +62 -0
  69. package/corpus/templates/analytics/.agents/skills/dashboard-ops/SKILL.md +85 -0
  70. package/corpus/templates/analytics/.agents/skills/data-querying/SKILL.md +27 -2
  71. package/corpus/templates/analytics/.agents/skills/data-querying/references/inline-chart-embeds.md +139 -0
  72. package/corpus/templates/analytics/.agents/skills/monitoring/SKILL.md +77 -0
  73. package/corpus/templates/analytics/.agents/skills/upgrade-agent-native/SKILL.md +24 -2
  74. package/corpus/templates/analytics/AGENTS.md +91 -563
  75. package/corpus/templates/analytics/_gitignore +1 -0
  76. package/corpus/templates/analytics/actions/bigquery.ts +12 -4
  77. package/corpus/templates/analytics/actions/generate-chart.ts +5 -5
  78. package/corpus/templates/analytics/app/components/dashboard/SqlChart.tsx +30 -1
  79. package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/DashboardFilterBar.tsx +3 -0
  80. package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/SqlChartCard.tsx +1 -1
  81. package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/index.tsx +1 -0
  82. package/corpus/templates/analytics/changelog/2026-07-24-analytics-finds-saved-dashboards-and-queries-far-more-reliab.md +6 -0
  83. package/corpus/templates/analytics/changelog/2026-07-24-notion-access-errors-now-explain-that-a-page-needs-sharing-w.md +6 -0
  84. package/corpus/templates/analytics/server/lib/agent-chat-plan-mode.ts +7 -0
  85. package/corpus/templates/analytics/server/lib/analytics-query-catalog.ts +191 -30
  86. package/corpus/templates/analytics/server/lib/bigquery.ts +11 -1
  87. package/corpus/templates/analytics/server/lib/notion.ts +15 -4
  88. package/corpus/templates/analytics/server/plugins/agent-chat.ts +10 -0
  89. package/corpus/templates/assets/.agents/skills/upgrade-agent-native/SKILL.md +24 -2
  90. package/corpus/templates/brain/.agents/skills/upgrade-agent-native/SKILL.md +24 -2
  91. package/corpus/templates/brain/_gitignore +1 -0
  92. package/corpus/templates/calendar/.agents/skills/upgrade-agent-native/SKILL.md +24 -2
  93. package/corpus/templates/calendar/_gitignore +1 -0
  94. package/corpus/templates/chat/.agents/skills/upgrade-agent-native/SKILL.md +24 -2
  95. package/corpus/templates/chat/_gitignore +1 -0
  96. package/corpus/templates/clips/.agents/skills/upgrade-agent-native/SKILL.md +24 -2
  97. package/corpus/templates/clips/.agents/skills/video-sharing/SKILL.md +34 -0
  98. package/corpus/templates/clips/AGENTS.md +5 -4
  99. package/corpus/templates/clips/_gitignore +1 -0
  100. package/corpus/templates/clips/actions/cleanup-transcript.ts +5 -0
  101. package/corpus/templates/clips/actions/get-recording-insights.ts +44 -8
  102. package/corpus/templates/clips/actions/get-recording-player-data.ts +39 -70
  103. package/corpus/templates/clips/actions/list-clip-views.ts +2 -4
  104. package/corpus/templates/clips/actions/list-recordings.ts +69 -19
  105. package/corpus/templates/clips/actions/list-viewers.ts +5 -2
  106. package/corpus/templates/clips/actions/regenerate-summary.ts +5 -1
  107. package/corpus/templates/clips/actions/request-transcript.ts +28 -1
  108. package/corpus/templates/clips/app/components/editor/stitch-manager.tsx +21 -1
  109. package/corpus/templates/clips/app/components/meetings/quick-ask-sidebar.tsx +14 -1
  110. package/corpus/templates/clips/app/components/player/insights-panel.tsx +8 -20
  111. package/corpus/templates/clips/app/components/player/recording-views-badge.tsx +335 -0
  112. package/corpus/templates/clips/app/components/player/video-player.tsx +13 -8
  113. package/corpus/templates/clips/app/components/sharing/share-ui.tsx +2 -1
  114. package/corpus/templates/clips/app/i18n/en-US.ts +13 -2
  115. package/corpus/templates/clips/app/lib/capture-permissions.ts +110 -0
  116. package/corpus/templates/clips/app/lib/recording-link.ts +32 -0
  117. package/corpus/templates/clips/app/routes/_app.meetings.$meetingId.tsx +27 -0
  118. package/corpus/templates/clips/app/routes/r.$recordingId.tsx +46 -15
  119. package/corpus/templates/clips/app/routes/record.tsx +77 -31
  120. package/corpus/templates/clips/app/routes/share.$shareId.tsx +42 -31
  121. package/corpus/templates/clips/changelog/2026-07-24-clip-pages-now-show-a-view-count-with-viewer-avatars-next-to.md +6 -0
  122. package/corpus/templates/clips/changelog/2026-07-24-clip-summaries-read-like-a-description-you-d-write-yourself-.md +6 -0
  123. package/corpus/templates/clips/changelog/2026-07-24-clip-view-counts-now-separate-human-views-from-agent-views-s.md +6 -0
  124. package/corpus/templates/clips/changelog/2026-07-24-clips-actions-can-now-be-called-by-org-service-tokens-so-ext.md +6 -0
  125. package/corpus/templates/clips/changelog/2026-07-24-clips-no-longer-briefly-shows-a-dock-icon-while-launching.md +6 -0
  126. package/corpus/templates/clips/changelog/2026-07-24-fixed-owner-and-editor-share-links-redirecting-to-the-record.md +6 -0
  127. package/corpus/templates/clips/changelog/2026-07-24-meeting-and-note-recordings-now-start-as-a-compact-pill-on-t.md +6 -0
  128. package/corpus/templates/clips/changelog/2026-07-24-new-clips-now-copy-a-shareable-link-instead-of-the-owner-onl.md +6 -0
  129. package/corpus/templates/clips/changelog/2026-07-24-opening-a-share-link-as-the-clip-s-owner-now-goes-straight-t.md +6 -0
  130. package/corpus/templates/clips/changelog/2026-07-24-permissions-and-rewind-controls-now-use-compact-consistent-h.md +6 -0
  131. package/corpus/templates/clips/changelog/2026-07-24-quitting-the-desktop-app-no-longer-shows-a-false-macos-crash.md +6 -0
  132. package/corpus/templates/clips/changelog/2026-07-24-screen-recording-permission-errors-now-name-the-exact-app-to.md +6 -0
  133. package/corpus/templates/clips/changelog/2026-07-24-the-desktop-app-now-copies-a-new-clip-s-share-link-to-your-c.md +6 -0
  134. package/corpus/templates/clips/changelog/2026-07-24-the-recording-toolbar-now-stays-above-other-apps-including-o.md +6 -0
  135. package/corpus/templates/clips/changelog/2026-07-24-transcript-captions-now-use-real-speech-timings-instead-of-a.md +6 -0
  136. package/corpus/templates/clips/changelog/2026-07-24-video-playback-no-longer-stutters-and-replays-the-last-momen.md +6 -0
  137. package/corpus/templates/clips/chrome-extension/src/background.ts +17 -1
  138. package/corpus/templates/clips/desktop/package.json +2 -0
  139. package/corpus/templates/clips/desktop/src/app.tsx +89 -0
  140. package/corpus/templates/clips/desktop/src/hooks/useMeetingTranscription.ts +9 -3
  141. package/corpus/templates/clips/desktop/src/lib/audio-meter.ts +51 -0
  142. package/corpus/templates/clips/desktop/src/lib/native-notification.ts +44 -0
  143. package/corpus/templates/clips/desktop/src/lib/recording-link.ts +67 -0
  144. package/corpus/templates/clips/desktop/src/overlays/live-audio-bars.tsx +35 -35
  145. package/corpus/templates/clips/desktop/src/overlays/live-transcript.tsx +3 -2
  146. package/corpus/templates/clips/desktop/src/overlays/recording-pill.tsx +47 -46
  147. package/corpus/templates/clips/desktop/src/styles.css +127 -78
  148. package/corpus/templates/clips/desktop/src-tauri/Cargo.toml +7 -0
  149. package/corpus/templates/clips/desktop/src-tauri/Info.plist +6 -0
  150. package/corpus/templates/clips/desktop/src-tauri/capabilities/default.json +1 -0
  151. package/corpus/templates/clips/desktop/src-tauri/src/clips/mod.rs +7 -3
  152. package/corpus/templates/clips/desktop/src-tauri/src/lib.rs +4 -1
  153. package/corpus/templates/clips/desktop/src-tauri/src/main.rs +8 -0
  154. package/corpus/templates/clips/desktop/src-tauri/src/recording_indicator.rs +21 -10
  155. package/corpus/templates/clips/desktop/src-tauri/src/util.rs +40 -0
  156. package/corpus/templates/clips/server/db/schema.ts +25 -0
  157. package/corpus/templates/clips/server/lib/agent-views.ts +145 -0
  158. package/corpus/templates/clips/server/lib/public-agent-context.ts +7 -0
  159. package/corpus/templates/clips/server/lib/recording-share-grant.ts +79 -0
  160. package/corpus/templates/clips/server/lib/recordings.ts +51 -3
  161. package/corpus/templates/clips/server/plugins/db.ts +23 -0
  162. package/corpus/templates/clips/server/routes/api/public-recording.get.ts +49 -17
  163. package/corpus/templates/clips/shared/recording-link.ts +43 -0
  164. package/corpus/templates/clips/shared/share-attribution.ts +4 -0
  165. package/corpus/templates/clips/shared/share-dashboard-redirect.ts +42 -0
  166. package/corpus/templates/clips/shared/view-analytics.ts +26 -0
  167. package/corpus/templates/content/.agents/skills/content/SKILL.md +5 -0
  168. package/corpus/templates/content/.agents/skills/content/references/local-file-mode.md +135 -0
  169. package/corpus/templates/content/.agents/skills/document-editing/SKILL.md +12 -0
  170. package/corpus/templates/content/.agents/skills/document-editing/references/databases.md +238 -0
  171. package/corpus/templates/content/.agents/skills/document-editing/references/document-behavior.md +91 -0
  172. package/corpus/templates/content/.agents/skills/upgrade-agent-native/SKILL.md +24 -2
  173. package/corpus/templates/content/AGENTS.md +62 -583
  174. package/corpus/templates/content/_gitignore +1 -0
  175. package/corpus/templates/design/.agents/skills/creative-context/SKILL.md +11 -0
  176. package/corpus/templates/design/.agents/skills/design-generation/SKILL.md +50 -8
  177. package/corpus/templates/design/.agents/skills/design-generation/references/code-layers.md +81 -0
  178. package/corpus/templates/design/.agents/skills/design-generation/references/code-workspace.md +42 -0
  179. package/corpus/templates/design/.agents/skills/design-generation/references/editor-extensions.md +34 -0
  180. package/corpus/templates/design/.agents/skills/responsive-breakpoints/SKILL.md +4 -1
  181. package/corpus/templates/design/.agents/skills/upgrade-agent-native/SKILL.md +24 -2
  182. package/corpus/templates/design/.agents/skills/visual-edit/SKILL.md +17 -0
  183. package/corpus/templates/design/.generated/bridge/editor-chrome.generated.ts +8196 -0
  184. package/corpus/templates/design/.generated/bridge/embedded-wheel.generated.ts +265 -0
  185. package/corpus/templates/design/.generated/bridge/hit-test.generated.ts +642 -0
  186. package/corpus/templates/design/.generated/bridge/motion-preview.generated.ts +571 -0
  187. package/corpus/templates/design/.generated/bridge/nav.generated.ts +91 -0
  188. package/corpus/templates/design/.generated/bridge/sample.generated.ts +23 -0
  189. package/corpus/templates/design/.generated/bridge/shader-fill-preview.generated.ts +263 -0
  190. package/corpus/templates/design/.generated/bridge/shader-runtime.generated.ts +518 -0
  191. package/corpus/templates/design/.generated/bridge/tweak.generated.ts +20 -0
  192. package/corpus/templates/design/.generated/bridge/zoom.generated.ts +32 -0
  193. package/corpus/templates/design/AGENTS.md +88 -503
  194. package/corpus/templates/design/_gitignore +1 -0
  195. package/corpus/templates/dispatch/.agents/skills/upgrade-agent-native/SKILL.md +24 -2
  196. package/corpus/templates/dispatch/_gitignore +1 -0
  197. package/corpus/templates/dispatch/changelog/2026-07-24-signing-in-now-puts-you-in-your-companys-workspace.md +6 -0
  198. package/corpus/templates/forms/.agents/skills/upgrade-agent-native/SKILL.md +24 -2
  199. package/corpus/templates/forms/_gitignore +1 -0
  200. package/corpus/templates/forms/server/lib/public-form-ssr.ts +2 -2
  201. package/corpus/templates/macros/.agents/skills/upgrade-agent-native/SKILL.md +24 -2
  202. package/corpus/templates/macros/_gitignore +1 -0
  203. package/corpus/templates/mail/.agents/skills/upgrade-agent-native/SKILL.md +24 -2
  204. package/corpus/templates/mail/_gitignore +1 -0
  205. package/corpus/templates/plan/.agents/skills/upgrade-agent-native/SKILL.md +24 -2
  206. package/corpus/templates/plan/_gitignore +1 -0
  207. package/corpus/templates/slides/.agents/skills/upgrade-agent-native/SKILL.md +24 -2
  208. package/corpus/templates/slides/_gitignore +1 -0
  209. package/corpus/templates/slides/server/plugins/db.ts +4 -0
  210. package/corpus/templates/tasks/.agents/skills/upgrade-agent-native/SKILL.md +24 -2
  211. package/corpus/templates/tasks/AGENTS.md +1 -1
  212. package/corpus/templates/tasks/_gitignore +1 -0
  213. package/dist/a2a/activity.d.ts +4 -1
  214. package/dist/a2a/activity.d.ts.map +1 -1
  215. package/dist/a2a/activity.js +27 -16
  216. package/dist/a2a/activity.js.map +1 -1
  217. package/dist/agent/engine/builder-engine.d.ts +1 -0
  218. package/dist/agent/engine/builder-engine.d.ts.map +1 -1
  219. package/dist/agent/engine/builder-engine.js +31 -4
  220. package/dist/agent/engine/builder-engine.js.map +1 -1
  221. package/dist/agent/run-manager.d.ts.map +1 -1
  222. package/dist/agent/run-manager.js +18 -1
  223. package/dist/agent/run-manager.js.map +1 -1
  224. package/dist/agent/run-store.d.ts +1 -0
  225. package/dist/agent/run-store.d.ts.map +1 -1
  226. package/dist/agent/run-store.js +2 -1
  227. package/dist/agent/run-store.js.map +1 -1
  228. package/dist/agent/types.d.ts +12 -1
  229. package/dist/agent/types.d.ts.map +1 -1
  230. package/dist/agent/types.js +21 -1
  231. package/dist/agent/types.js.map +1 -1
  232. package/dist/chat-threads/store.d.ts +10 -0
  233. package/dist/chat-threads/store.d.ts.map +1 -1
  234. package/dist/chat-threads/store.js +41 -0
  235. package/dist/chat-threads/store.js.map +1 -1
  236. package/dist/checkpoints/index.d.ts +1 -0
  237. package/dist/checkpoints/index.d.ts.map +1 -1
  238. package/dist/checkpoints/index.js +1 -0
  239. package/dist/checkpoints/index.js.map +1 -1
  240. package/dist/checkpoints/route-match.d.ts +8 -0
  241. package/dist/checkpoints/route-match.d.ts.map +1 -0
  242. package/dist/checkpoints/route-match.js +13 -0
  243. package/dist/checkpoints/route-match.js.map +1 -0
  244. package/dist/cli/create.d.ts +35 -4
  245. package/dist/cli/create.d.ts.map +1 -1
  246. package/dist/cli/create.js +69 -19
  247. package/dist/cli/create.js.map +1 -1
  248. package/dist/cli/index.js +19 -0
  249. package/dist/cli/index.js.map +1 -1
  250. package/dist/cli/template-baseline.d.ts +54 -0
  251. package/dist/cli/template-baseline.d.ts.map +1 -0
  252. package/dist/cli/template-baseline.js +334 -0
  253. package/dist/cli/template-baseline.js.map +1 -0
  254. package/dist/cli/template-sync.d.ts +57 -0
  255. package/dist/cli/template-sync.d.ts.map +1 -0
  256. package/dist/cli/template-sync.js +787 -0
  257. package/dist/cli/template-sync.js.map +1 -0
  258. package/dist/cli/templates-meta.d.ts.map +1 -1
  259. package/dist/cli/templates-meta.js +1 -0
  260. package/dist/cli/templates-meta.js.map +1 -1
  261. package/dist/client/AssistantChat.d.ts +2 -1
  262. package/dist/client/AssistantChat.d.ts.map +1 -1
  263. package/dist/client/AssistantChat.js +38 -10
  264. package/dist/client/AssistantChat.js.map +1 -1
  265. package/dist/client/NewWorkspaceAppFlow.d.ts.map +1 -1
  266. package/dist/client/NewWorkspaceAppFlow.js +32 -2
  267. package/dist/client/NewWorkspaceAppFlow.js.map +1 -1
  268. package/dist/client/chat/message-components.d.ts +20 -0
  269. package/dist/client/chat/message-components.d.ts.map +1 -1
  270. package/dist/client/chat/message-components.js +81 -46
  271. package/dist/client/chat/message-components.js.map +1 -1
  272. package/dist/client/chat/tool-call-display.d.ts.map +1 -1
  273. package/dist/client/chat/tool-call-display.js +14 -6
  274. package/dist/client/chat/tool-call-display.js.map +1 -1
  275. package/dist/client/error-format.d.ts.map +1 -1
  276. package/dist/client/error-format.js +13 -0
  277. package/dist/client/error-format.js.map +1 -1
  278. package/dist/client/org/OrgSwitcher.d.ts +8 -1
  279. package/dist/client/org/OrgSwitcher.d.ts.map +1 -1
  280. package/dist/client/org/OrgSwitcher.js +3 -2
  281. package/dist/client/org/OrgSwitcher.js.map +1 -1
  282. package/dist/client/org/TeamPage.d.ts.map +1 -1
  283. package/dist/client/org/TeamPage.js +1 -1
  284. package/dist/client/org/TeamPage.js.map +1 -1
  285. package/dist/client/sse-event-processor.d.ts.map +1 -1
  286. package/dist/client/sse-event-processor.js +3 -0
  287. package/dist/client/sse-event-processor.js.map +1 -1
  288. package/dist/collab/awareness.d.ts +2 -2
  289. package/dist/collab/awareness.d.ts.map +1 -1
  290. package/dist/data-widgets/index.d.ts +3 -0
  291. package/dist/data-widgets/index.d.ts.map +1 -1
  292. package/dist/data-widgets/index.js +33 -0
  293. package/dist/data-widgets/index.js.map +1 -1
  294. package/dist/deploy/build.d.ts.map +1 -1
  295. package/dist/deploy/build.js +11 -7
  296. package/dist/deploy/build.js.map +1 -1
  297. package/dist/eject/provider-api-definitions.d.ts +1 -0
  298. package/dist/eject/provider-api-definitions.d.ts.map +1 -1
  299. package/dist/integrations/webhook-handler.d.ts.map +1 -1
  300. package/dist/integrations/webhook-handler.js +46 -9
  301. package/dist/integrations/webhook-handler.js.map +1 -1
  302. package/dist/org/auto-join-domain.d.ts +3 -2
  303. package/dist/org/auto-join-domain.d.ts.map +1 -1
  304. package/dist/org/auto-join-domain.js +1 -1
  305. package/dist/org/auto-join-domain.js.map +1 -1
  306. package/dist/org/context.d.ts.map +1 -1
  307. package/dist/org/context.js +84 -28
  308. package/dist/org/context.js.map +1 -1
  309. package/dist/org/index.d.ts +1 -0
  310. package/dist/org/index.d.ts.map +1 -1
  311. package/dist/org/index.js +1 -0
  312. package/dist/org/index.js.map +1 -1
  313. package/dist/org/service-identity.d.ts +43 -0
  314. package/dist/org/service-identity.d.ts.map +1 -0
  315. package/dist/org/service-identity.js +34 -0
  316. package/dist/org/service-identity.js.map +1 -0
  317. package/dist/provider-api/actions/custom-provider-registration.d.ts +14 -14
  318. package/dist/provider-api/actions/provider-api.d.ts +13 -11
  319. package/dist/provider-api/actions/provider-api.d.ts.map +1 -1
  320. package/dist/provider-api/index.d.ts +4 -0
  321. package/dist/provider-api/index.d.ts.map +1 -1
  322. package/dist/provider-api/index.js +17 -1
  323. package/dist/provider-api/index.js.map +1 -1
  324. package/dist/resources/handlers.d.ts +1 -1
  325. package/dist/scripts/docs/search.d.ts.map +1 -1
  326. package/dist/scripts/docs/search.js +12 -1
  327. package/dist/scripts/docs/search.js.map +1 -1
  328. package/dist/server/agent-chat/context-tools.d.ts.map +1 -1
  329. package/dist/server/agent-chat/context-tools.js +3 -3
  330. package/dist/server/agent-chat/context-tools.js.map +1 -1
  331. package/dist/server/agent-chat/framework-prompts.d.ts +8 -3
  332. package/dist/server/agent-chat/framework-prompts.d.ts.map +1 -1
  333. package/dist/server/agent-chat/framework-prompts.js +33 -62
  334. package/dist/server/agent-chat/framework-prompts.js.map +1 -1
  335. package/dist/server/agent-chat-plugin.d.ts.map +1 -1
  336. package/dist/server/agent-chat-plugin.js +16 -10
  337. package/dist/server/agent-chat-plugin.js.map +1 -1
  338. package/dist/server/agents-bundle.d.ts +18 -0
  339. package/dist/server/agents-bundle.d.ts.map +1 -1
  340. package/dist/server/agents-bundle.js +70 -4
  341. package/dist/server/agents-bundle.js.map +1 -1
  342. package/dist/server/auth.d.ts.map +1 -1
  343. package/dist/server/auth.js +4 -3
  344. package/dist/server/auth.js.map +1 -1
  345. package/dist/server/builder-browser.d.ts.map +1 -1
  346. package/dist/server/builder-browser.js +43 -19
  347. package/dist/server/builder-browser.js.map +1 -1
  348. package/dist/server/core-routes-plugin.js +2 -2
  349. package/dist/server/core-routes-plugin.js.map +1 -1
  350. package/dist/server/credential-provider.d.ts +38 -2
  351. package/dist/server/credential-provider.d.ts.map +1 -1
  352. package/dist/server/credential-provider.js +142 -64
  353. package/dist/server/credential-provider.js.map +1 -1
  354. package/dist/server/index.d.ts +1 -1
  355. package/dist/server/index.d.ts.map +1 -1
  356. package/dist/server/index.js +1 -1
  357. package/dist/server/index.js.map +1 -1
  358. package/dist/server/prompts/framework-core-compact.d.ts +1 -1
  359. package/dist/server/prompts/framework-core-compact.d.ts.map +1 -1
  360. package/dist/server/prompts/framework-core-compact.js +7 -13
  361. package/dist/server/prompts/framework-core-compact.js.map +1 -1
  362. package/dist/server/prompts/framework-core.d.ts +1 -1
  363. package/dist/server/prompts/framework-core.d.ts.map +1 -1
  364. package/dist/server/prompts/framework-core.js +10 -21
  365. package/dist/server/prompts/framework-core.js.map +1 -1
  366. package/dist/server/prompts/index.d.ts +1 -1
  367. package/dist/server/prompts/index.d.ts.map +1 -1
  368. package/dist/server/prompts/index.js +1 -1
  369. package/dist/server/prompts/index.js.map +1 -1
  370. package/dist/server/prompts/shared-rules.d.ts +16 -10
  371. package/dist/server/prompts/shared-rules.d.ts.map +1 -1
  372. package/dist/server/prompts/shared-rules.js +19 -10
  373. package/dist/server/prompts/shared-rules.js.map +1 -1
  374. package/dist/server/ssr-handler.d.ts +1 -1
  375. package/dist/server/ssr-handler.d.ts.map +1 -1
  376. package/dist/server/ssr-handler.js +10 -3
  377. package/dist/server/ssr-handler.js.map +1 -1
  378. package/dist/settings/user-settings.d.ts.map +1 -1
  379. package/dist/settings/user-settings.js +13 -1
  380. package/dist/settings/user-settings.js.map +1 -1
  381. package/dist/shared/cache-control.d.ts +52 -0
  382. package/dist/shared/cache-control.d.ts.map +1 -1
  383. package/dist/shared/cache-control.js +107 -0
  384. package/dist/shared/cache-control.js.map +1 -1
  385. package/dist/templates/chat/.agents/skills/upgrade-agent-native/SKILL.md +24 -2
  386. package/dist/templates/chat/_gitignore +1 -0
  387. package/dist/templates/default/.agents/skills/upgrade-agent-native/SKILL.md +24 -2
  388. package/dist/templates/headless/.agents/skills/upgrade-agent-native/SKILL.md +24 -2
  389. package/dist/templates/workspace-core/.agents/skills/performance/SKILL.md +19 -0
  390. package/dist/templates/workspace-core/.agents/skills/upgrade-agent-native/SKILL.md +24 -2
  391. package/dist/templates/workspace-core/.agents/skills/visual-answer/SKILL.md +1 -0
  392. package/dist/vite/agents-bundle-plugin.d.ts.map +1 -1
  393. package/dist/vite/agents-bundle-plugin.js +8 -7
  394. package/dist/vite/agents-bundle-plugin.js.map +1 -1
  395. package/dist/vite/client.d.ts.map +1 -1
  396. package/dist/vite/client.js +2 -0
  397. package/dist/vite/client.js.map +1 -1
  398. package/docs/content/actions.mdx +2 -2
  399. package/docs/content/agent-surfaces.mdx +1 -1
  400. package/docs/content/authentication.mdx +2 -0
  401. package/docs/content/deployment.mdx +36 -0
  402. package/docs/content/http-api.mdx +266 -0
  403. package/docs/content/syncing-template-changes.mdx +159 -0
  404. package/package.json +4 -3
  405. package/src/a2a/activity.ts +38 -27
  406. package/src/agent/engine/builder-engine.ts +35 -4
  407. package/src/agent/run-manager.ts +20 -1
  408. package/src/agent/run-store.ts +4 -1
  409. package/src/agent/types.ts +28 -8
  410. package/src/chat-threads/store.ts +45 -0
  411. package/src/checkpoints/index.ts +2 -0
  412. package/src/checkpoints/route-match.ts +13 -0
  413. package/src/cli/create.ts +105 -17
  414. package/src/cli/index.ts +20 -0
  415. package/src/cli/template-baseline.ts +410 -0
  416. package/src/cli/template-sync.ts +1004 -0
  417. package/src/cli/templates-meta.ts +1 -0
  418. package/src/client/AssistantChat.tsx +38 -12
  419. package/src/client/NewWorkspaceAppFlow.tsx +75 -10
  420. package/src/client/chat/message-components.tsx +127 -66
  421. package/src/client/chat/tool-call-display.tsx +29 -5
  422. package/src/client/error-format.ts +18 -0
  423. package/src/client/org/OrgSwitcher.tsx +30 -8
  424. package/src/client/org/TeamPage.tsx +7 -6
  425. package/src/client/sse-event-processor.ts +3 -0
  426. package/src/data-widgets/index.ts +41 -0
  427. package/src/deploy/build.ts +11 -9
  428. package/src/integrations/webhook-handler.ts +63 -9
  429. package/src/org/auto-join-domain.ts +4 -3
  430. package/src/org/context.ts +108 -39
  431. package/src/org/index.ts +5 -0
  432. package/src/org/service-identity.ts +60 -0
  433. package/src/provider-api/index.ts +22 -1
  434. package/src/scripts/docs/search.ts +12 -1
  435. package/src/server/__snapshots__/agent-chat-plugin.surface.spec.ts.snap +25 -36
  436. package/src/server/agent-chat/context-tools.ts +9 -4
  437. package/src/server/agent-chat/framework-prompts.ts +38 -66
  438. package/src/server/agent-chat-plugin.ts +17 -10
  439. package/src/server/agents-bundle.ts +84 -5
  440. package/src/server/auth.ts +4 -3
  441. package/src/server/builder-browser.ts +47 -19
  442. package/src/server/core-routes-plugin.ts +2 -2
  443. package/src/server/credential-provider.ts +209 -68
  444. package/src/server/index.ts +3 -0
  445. package/src/server/prompts/framework-core-compact.ts +6 -13
  446. package/src/server/prompts/framework-core.ts +9 -21
  447. package/src/server/prompts/index.ts +0 -1
  448. package/src/server/prompts/shared-rules.ts +19 -11
  449. package/src/server/ssr-handler.ts +13 -2
  450. package/src/settings/user-settings.ts +13 -1
  451. package/src/shared/cache-control.ts +141 -0
  452. package/src/templates/chat/.agents/skills/upgrade-agent-native/SKILL.md +24 -2
  453. package/src/templates/chat/_gitignore +1 -0
  454. package/src/templates/default/.agents/skills/upgrade-agent-native/SKILL.md +24 -2
  455. package/src/templates/headless/.agents/skills/upgrade-agent-native/SKILL.md +24 -2
  456. package/src/templates/workspace-core/.agents/skills/performance/SKILL.md +19 -0
  457. package/src/templates/workspace-core/.agents/skills/upgrade-agent-native/SKILL.md +24 -2
  458. package/src/templates/workspace-core/.agents/skills/visual-answer/SKILL.md +1 -0
  459. package/src/vite/agents-bundle-plugin.ts +7 -6
  460. package/src/vite/client.ts +5 -0
@@ -0,0 +1,159 @@
1
+ ---
2
+ title: "Syncing Template Changes"
3
+ description: "agent-native template pulls later upstream first-party template changes into an app that was generated from a template, using a real per-file three-way merge against a pristine baseline."
4
+ ---
5
+
6
+ # Syncing Template Changes
7
+
8
+ `agent-native create` copies a first-party template into your app and then makes it yours — substituting the app name, renaming `_gitignore`, rewriting `package.json`, pinning `workspace:*` and `catalog:` dependencies to concrete versions, and (in a workspace) swapping in inherited auth and chat plugins. From that moment the app is a fork. Fixes and improvements that land in the template upstream do not reach it.
9
+
10
+ `agent-native upgrade` does not close that gap. It moves package versions, runs import codemods, and refreshes skill directories — it never touches a file that was copied out of a template.
11
+
12
+ `agent-native template` is the missing half. It re-fetches the template at a newer version, re-applies the exact transforms `create` applied, and merges the result into your app file by file.
13
+
14
+ ## Quick start {#quick-start}
15
+
16
+ ```bash
17
+ agent-native upgrade
18
+ agent-native template sync
19
+ ```
20
+
21
+ `sync` defaults to the template version matching your installed `@agent-native/core`, so running it after `upgrade` keeps code and packages on the same version.
22
+
23
+ Look before you merge:
24
+
25
+ ```bash
26
+ agent-native template status
27
+ agent-native template diff
28
+ ```
29
+
30
+ ## How the merge works {#how-the-merge-works}
31
+
32
+ A useful merge needs three trees, not two:
33
+
34
+ - **base** — the pristine template as it was when your app was generated.
35
+ - **theirs** — the same template at the version you are syncing to, put through the same transform pipeline.
36
+ - **ours** — your app as it stands now.
37
+
38
+ With those, every file falls into a clear case. Upstream did not touch it, so it is left alone. You never touched it, so it fast-forwards. Both of you changed it, so it gets conflict markers. Nothing is overwritten just because it differs.
39
+
40
+ Without a base, "sync" can only mean overwrite, which silently discards your work or reverts upstream's.
41
+
42
+ ## The baseline {#the-baseline}
43
+
44
+ The base tree is stored as a git ref in your own repo:
45
+
46
+ ```txt
47
+ refs/agent-native/template-baseline/apps/slides
48
+ ```
49
+
50
+ It is written with git plumbing against a throwaway index file. Your `HEAD`, your branch, your index, and your working tree are never touched — running `template baseline` mid-edit is safe, and `git status` reads identically before and after.
51
+
52
+ On first write, the fetch and push refspecs for `refs/agent-native/*` are added to your remote so the baseline survives a clone. If the app is not in a git repo, the baseline falls back to a tarball under `.agent-native/`.
53
+
54
+ Apps generated before provenance existed have no baseline. Create one, then sync:
55
+
56
+ ```bash
57
+ agent-native template baseline
58
+ agent-native template sync
59
+ ```
60
+
61
+ ## Provenance {#provenance}
62
+
63
+ `create` records what a later merge needs in the app's `package.json`:
64
+
65
+ ```json
66
+ {
67
+ "agent-native": {
68
+ "scaffold": {
69
+ "template": "slides",
70
+ "frameworkSkills": "default",
71
+ "templateRef": "@agent-native/core@0.120.3",
72
+ "templateSource": "github",
73
+ "coreVersion": "0.120.3",
74
+ "shape": "workspace"
75
+ }
76
+ }
77
+ }
78
+ ```
79
+
80
+ `templateRef` is the immutable tag the template was actually fetched from, which is what makes the base reproducible. `shape` decides whether the workspace transforms are replayed during materialization.
81
+
82
+ ## Commands {#commands}
83
+
84
+ ### status {#status}
85
+
86
+ ```bash
87
+ agent-native template status [app]
88
+ ```
89
+
90
+ Reports the recorded ref, the latest available ref, whether a baseline exists, how many files upstream changed, and how many you have modified locally.
91
+
92
+ ### diff {#diff}
93
+
94
+ ```bash
95
+ agent-native template diff [app] [--to <ref>]
96
+ ```
97
+
98
+ A read-only unified diff of what changed upstream between your baseline and the target. Writes nothing.
99
+
100
+ ### sync {#sync}
101
+
102
+ ```bash
103
+ agent-native template sync [app] [--to <ref>] [--dry-run] [--force]
104
+ ```
105
+
106
+ Performs the merge. `--to` defaults to the ref matching the installed core. `--dry-run` prints the plan without writing.
107
+
108
+ `sync` refuses to run when the app directory has uncommitted changes, so a bad merge is always recoverable with `git checkout`. `--force` overrides this; prefer committing first.
109
+
110
+ When the merge is clean, the baseline advances automatically. When there are conflicts it deliberately does not — see `accept`.
111
+
112
+ ### accept {#accept}
113
+
114
+ ```bash
115
+ agent-native template accept [app]
116
+ ```
117
+
118
+ Advances the baseline after you resolve conflict markers. It refuses while any `<<<<<<<` remains, so the baseline can never move past an unresolved merge and quietly bake conflict markers into your next base.
119
+
120
+ ### baseline {#baseline}
121
+
122
+ ```bash
123
+ agent-native template baseline [app] [--ref <ref>] [--template <name>]
124
+ ```
125
+
126
+ Records a baseline for an app that predates scaffold provenance. Pass `--ref` when you know which version the app actually came from; the closer it is to the truth, the fewer phantom conflicts the first sync produces.
127
+
128
+ ## What is never merged {#what-is-never-merged}
129
+
130
+ Some files are yours by definition, and some cannot be merged meaningfully:
131
+
132
+ - Secrets and local config: `.env`, `.env.local`
133
+ - Lockfiles: `pnpm-lock.yaml`
134
+ - Generated output: `node_modules`, `.output`, `.react-router`, `dist`, `build`
135
+ - App-owned content: `learnings.md`, pending entries under `changelog/`
136
+
137
+ Binary files are never marker-merged. If both sides changed one, your copy is kept and the file is reported for manual handling. Symlinks are reported rather than clobbered.
138
+
139
+ ## Contributing changes back {#contributing-changes-back}
140
+
141
+ Syncing is one-directional by design: upstream is the source of truth for template content, and the transforms `create` applies are not perfectly reversible. Recovering `{{APP_NAME}}` from a concrete app name is a guess, and files that `create` rewrote wholesale — `package.json`, `netlify.toml`, `app/root.tsx`, `server/plugins/auth.ts` — have no faithful inverse at all.
142
+
143
+ If you are working inside the framework monorepo and want to push an app-side improvement back into a template, the `contribute:template` script does the reverse pass with those limits made explicit:
144
+
145
+ ```bash
146
+ pnpm contribute:template --app <path-to-app> --dry-run
147
+ ```
148
+
149
+ It diffs your app against its baseline so only your own changes are candidates, inverts the placeholder substitution on just those files, three-way merges them into `templates/<name>/` as unstaged edits on the current branch, and prints everything it refused to touch so you can port the intent by hand.
150
+
151
+ ## Relationship to other commands {#relationship-to-other-commands}
152
+
153
+ | Command | Moves |
154
+ | ---------------------------- | -------------------------------------------------------------- |
155
+ | `agent-native upgrade` | `@agent-native/*` package versions, imports, skill directories |
156
+ | `agent-native template sync` | files copied out of a template at scaffold time |
157
+ | `agent-native eject` | a framework component into app-owned source, with provenance |
158
+
159
+ `upgrade` and `template sync` are complementary and safe to run together. `eject` is the opposite move — it takes ownership of a file deliberately, and ejected files are tracked separately in `agent-native.ejections.json`.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-native/core",
3
- "version": "0.121.2",
3
+ "version": "0.122.0",
4
4
  "description": "Framework for agent-native application development — where AI agents and UI share SQL state, actions, and context",
5
5
  "homepage": "https://github.com/BuilderIO/agent-native#readme",
6
6
  "bugs": {
@@ -139,6 +139,7 @@
139
139
  "./client/AgentPanel": "./dist/client/AgentPanel.js",
140
140
  "./client/application-state": "./dist/client/application-state.js",
141
141
  "./client/api-path": "./dist/client/api-path.js",
142
+ "./client/clipboard": "./dist/client/clipboard.js",
142
143
  "./client/route-state": "./dist/client/route-state.js",
143
144
  "./client/observability": "./dist/client/observability/index.js",
144
145
  "./client/onboarding": "./dist/client/onboarding/index.js",
@@ -37,6 +37,9 @@ export interface A2AAgentActivitySnapshot extends Record<string, unknown> {
37
37
  activePhase: A2AAgentActivityPhase;
38
38
  reasoning: string[];
39
39
  toolCalls: A2AAgentActivityToolCall[];
40
+ /** Response text segments, indexed by how many tool calls preceded them. */
41
+ response?: string[];
42
+ /** Tail segment only. Kept so peers predating `response` still render. */
40
43
  responseText?: string;
41
44
  }
42
45
 
@@ -47,7 +50,7 @@ export interface A2AAgentActivityState {
47
50
  activePhase: A2AAgentActivityPhase;
48
51
  reasoning: string[];
49
52
  toolCalls: A2AAgentActivityToolCall[];
50
- responseText: string;
53
+ response: string[];
51
54
  }
52
55
 
53
56
  export function createA2AAgentActivityState(
@@ -60,7 +63,7 @@ export function createA2AAgentActivityState(
60
63
  activePhase: "reasoning",
61
64
  reasoning: [],
62
65
  toolCalls: [],
63
- responseText: "",
66
+ response: [],
64
67
  };
65
68
  }
66
69
 
@@ -90,7 +93,6 @@ export function applyA2AAgentActivityEvent(
90
93
  break;
91
94
  case "tool_start":
92
95
  next.activePhase = "tool";
93
- next.responseText = "";
94
96
  next.toolCalls = appendToolCall(next.toolCalls, toolFromEvent(event));
95
97
  changed = true;
96
98
  break;
@@ -101,10 +103,11 @@ export function applyA2AAgentActivityEvent(
101
103
  break;
102
104
  case "text":
103
105
  next.activePhase = "responding";
104
- next.responseText = appendBoundedText(
105
- next.responseText,
106
+ next.response = appendBoundedSegment(
107
+ next.response,
106
108
  event.text,
107
109
  MAX_A2A_ACTIVITY_RESPONSE_CHARS,
110
+ next.toolCalls.length,
108
111
  );
109
112
  changed = true;
110
113
  break;
@@ -117,7 +120,7 @@ export function applyA2AAgentActivityEvent(
117
120
  changed = true;
118
121
  break;
119
122
  case "clear":
120
- next.responseText = "";
123
+ next.response = [];
121
124
  changed = true;
122
125
  break;
123
126
  }
@@ -138,10 +141,15 @@ export function buildA2AAgentActivitySnapshot(
138
141
  activePhase: state.activePhase,
139
142
  reasoning: state.reasoning,
140
143
  toolCalls: state.toolCalls,
141
- ...(state.responseText ? { responseText: state.responseText } : {}),
144
+ ...(state.response.length ? { response: state.response } : {}),
145
+ ...(tailSegment(state) ? { responseText: tailSegment(state) } : {}),
142
146
  };
143
147
  }
144
148
 
149
+ function tailSegment(state: A2AAgentActivityState): string {
150
+ return state.response[state.toolCalls.length] ?? "";
151
+ }
152
+
145
153
  export function buildA2AAgentActivityPart(
146
154
  state: A2AAgentActivityState,
147
155
  ): DataPart {
@@ -165,8 +173,10 @@ export function parseA2AAgentActivityPart(
165
173
  !isPhase(data.activePhase) ||
166
174
  data.updatedAt < data.startedAt ||
167
175
  data.durationMs !== data.updatedAt - data.startedAt ||
168
- !isSafeReasoning(data.reasoning) ||
176
+ !isSafeSegments(data.reasoning, MAX_A2A_ACTIVITY_REASONING_CHARS) ||
169
177
  !isSafeToolCalls(data.toolCalls) ||
178
+ (data.response !== undefined &&
179
+ !isSafeSegments(data.response, MAX_A2A_ACTIVITY_RESPONSE_CHARS)) ||
170
180
  (data.responseText !== undefined &&
171
181
  !isSafeText(data.responseText, MAX_A2A_ACTIVITY_RESPONSE_CHARS)) ||
172
182
  activityCharacterCount(data) > MAX_A2A_ACTIVITY_TOTAL_CHARS
@@ -193,14 +203,6 @@ function toolFromEvent(
193
203
  };
194
204
  }
195
205
 
196
- function appendBoundedText(
197
- current: string,
198
- addition: string,
199
- maxChars: number,
200
- ) {
201
- return sanitizeText(`${current}${addition}`, maxChars);
202
- }
203
-
204
206
  function appendBoundedSegment(
205
207
  current: string[],
206
208
  addition: string,
@@ -293,7 +295,7 @@ function isPhase(value: unknown): value is A2AAgentActivityPhase {
293
295
  );
294
296
  }
295
297
 
296
- function isSafeReasoning(value: unknown): value is string[] {
298
+ function isSafeSegments(value: unknown, maxChars: number): value is string[] {
297
299
  return (
298
300
  Array.isArray(value) &&
299
301
  value.length <= MAX_A2A_ACTIVITY_REASONING_SEGMENTS &&
@@ -301,8 +303,8 @@ function isSafeReasoning(value: unknown): value is string[] {
301
303
  (total, text) =>
302
304
  total + (typeof text === "string" ? text.length : Infinity),
303
305
  0,
304
- ) <= MAX_A2A_ACTIVITY_REASONING_CHARS &&
305
- value.every((text) => isSafeText(text, MAX_A2A_ACTIVITY_REASONING_CHARS))
306
+ ) <= maxChars &&
307
+ value.every((text) => isSafeText(text, maxChars))
306
308
  );
307
309
  }
308
310
 
@@ -349,14 +351,14 @@ function isSafeToolId(value: unknown): value is string {
349
351
  }
350
352
 
351
353
  function activityCharacterCount(data: Record<string, unknown>): number {
352
- const reasoning = Array.isArray(data.reasoning)
353
- ? data.reasoning.reduce(
354
- (total, text) => total + (typeof text === "string" ? text.length : 0),
355
- 0,
356
- )
357
- : 0;
358
- const response =
359
- typeof data.responseText === "string" ? data.responseText.length : 0;
354
+ const reasoning = segmentCharacterCount(data.reasoning);
355
+ // `responseText` duplicates the tail of `response`; counting both would
356
+ // reject a snapshot that is within budget.
357
+ const response = Array.isArray(data.response)
358
+ ? segmentCharacterCount(data.response)
359
+ : typeof data.responseText === "string"
360
+ ? data.responseText.length
361
+ : 0;
360
362
  const tools = Array.isArray(data.toolCalls)
361
363
  ? data.toolCalls.reduce((total, tool) => {
362
364
  if (!isRecord(tool)) return total;
@@ -369,3 +371,12 @@ function activityCharacterCount(data: Record<string, unknown>): number {
369
371
  : 0;
370
372
  return reasoning + response + tools;
371
373
  }
374
+
375
+ function segmentCharacterCount(value: unknown): number {
376
+ return Array.isArray(value)
377
+ ? value.reduce(
378
+ (total, text) => total + (typeof text === "string" ? text.length : 0),
379
+ 0,
380
+ )
381
+ : 0;
382
+ }
@@ -71,6 +71,8 @@ const MAX_BACKGROUND_BUILDER_GATEWAY_TIMEOUT_MS = 14 * 60_000;
71
71
  const MAX_LOCAL_BUILDER_GATEWAY_TIMEOUT_MS =
72
72
  MAX_BACKGROUND_BUILDER_GATEWAY_TIMEOUT_MS;
73
73
  const BUILDER_GATEWAY_NETWORK_ERROR_CODE = "builder_gateway_network_error";
74
+ export const BUILDER_MODEL_UNAUTHORIZED_ERROR_CODE =
75
+ "builder_model_unauthorized";
74
76
 
75
77
  export const BUILDER_DEFAULT_MODEL = BUILDER_MODEL_CONFIG.defaultModel;
76
78
 
@@ -669,8 +671,16 @@ async function* parseJsonlStream(
669
671
  explicitErrMsg ??
670
672
  `Gateway error (no detail; raw event: ${JSON.stringify(event)})`;
671
673
  const gatewayErrCode = event.errorCode ?? event.code;
674
+ // The gateway already authenticated this request before streaming,
675
+ // so a bare "Unauthorized" here means the account cannot use this
676
+ // model — not that the connection is broken. Only a message that
677
+ // names the credential may tear down the Builder connection.
672
678
  const isCredentialAuthError =
673
679
  Boolean(explicitErrMsg) &&
680
+ isBuilderCredentialAuthErrorInStream(String(errMsg));
681
+ const isModelAuthError =
682
+ Boolean(explicitErrMsg) &&
683
+ !isCredentialAuthError &&
674
684
  isBuilderCredentialAuthError(String(errMsg));
675
685
  // Anthropic's bare "Connection error." often arrives here with no
676
686
  // gateway code. Tag it as a network error so in-run retries and
@@ -680,10 +690,12 @@ async function* parseJsonlStream(
680
690
  isProviderConnectionErrorMessage(String(explicitErrMsg));
681
691
  const errCode = isCredentialAuthError
682
692
  ? "builder_auth_error"
683
- : isProviderConnectionError
684
- ? BUILDER_GATEWAY_NETWORK_ERROR_CODE
685
- : (gatewayErrCode ??
686
- (!explicitErrMsg ? "builder_gateway_error" : undefined));
693
+ : isModelAuthError
694
+ ? BUILDER_MODEL_UNAUTHORIZED_ERROR_CODE
695
+ : isProviderConnectionError
696
+ ? BUILDER_GATEWAY_NETWORK_ERROR_CODE
697
+ : (gatewayErrCode ??
698
+ (!explicitErrMsg ? "builder_gateway_error" : undefined));
687
699
  console.error(
688
700
  `[builder-engine] stop reason=error model=${model} code=${errCode ?? "(none)"} error=${errMsg}`,
689
701
  );
@@ -988,6 +1000,25 @@ function isBuilderCredentialAuthError(message: string): boolean {
988
1000
  );
989
1001
  }
990
1002
 
1003
+ /**
1004
+ * Stricter than {@link isBuilderCredentialAuthError} for errors that arrive
1005
+ * inside an already-authenticated stream, where a bare "unauthorized" is far
1006
+ * more likely to be a per-model entitlement rejection than a bad credential.
1007
+ * Misreading one there disconnects Builder for every model, including the ones
1008
+ * that still work.
1009
+ */
1010
+ function isBuilderCredentialAuthErrorInStream(message: string): boolean {
1011
+ if (!isBuilderCredentialAuthError(message)) return false;
1012
+ const lowerMessage = message.toLowerCase();
1013
+ return (
1014
+ lowerMessage.includes("private key") ||
1015
+ lowerMessage.includes("access token") ||
1016
+ lowerMessage.includes("invalid token") ||
1017
+ lowerMessage.includes("invalid_token") ||
1018
+ lowerMessage.includes("token invalid")
1019
+ );
1020
+ }
1021
+
991
1022
  function normalizeBuilderGatewayFetchError(
992
1023
  err: unknown,
993
1024
  timedOut: boolean,
@@ -29,6 +29,7 @@ import {
29
29
  setRunError,
30
30
  setRunTerminalReason,
31
31
  } from "./run-store.js";
32
+ import { isContinuationTerminalReason } from "./types.js";
32
33
  import type { AgentChatEvent, RunEvent, RunStatus } from "./types.js";
33
34
 
34
35
  export interface ActiveRun {
@@ -1429,10 +1430,28 @@ function subscribeFromSQL(
1429
1430
  return;
1430
1431
  }
1431
1432
  } else if (run?.status === "completed") {
1433
+ // A chunk boundary is also status "completed" (with a
1434
+ // continuation terminal_reason, and a chained successor run
1435
+ // already carrying the turn). Synthesizing `done` here told the
1436
+ // client the agent stopped while it was still working, which
1437
+ // surfaced as a premature "stopped without sending a final
1438
+ // message". Prefer the run's REAL terminal event, then the
1439
+ // terminal_reason, before falling back to `done`.
1440
+ const existing = await getLastTerminalRunEvent(runId).catch(
1441
+ () => null,
1442
+ );
1443
+ const terminalEvent = existing
1444
+ ? existing.event
1445
+ : isContinuationTerminalReason(run.terminalReason)
1446
+ ? { type: "auto_continue", reason: run.terminalReason }
1447
+ : { type: "done" };
1432
1448
  try {
1433
1449
  controller.enqueue(
1434
1450
  encoder.encode(
1435
- `data: ${JSON.stringify({ type: "done", seq: lastSeq })}\n\n`,
1451
+ `data: ${JSON.stringify({
1452
+ ...terminalEvent,
1453
+ seq: existing?.seq ?? lastSeq,
1454
+ })}\n\n`,
1436
1455
  ),
1437
1456
  );
1438
1457
  } catch {
@@ -1929,11 +1929,12 @@ export async function getRunById(runId: string): Promise<{
1929
1929
  startedAt: number;
1930
1930
  errorCode: string | null;
1931
1931
  errorDetail: string | null;
1932
+ terminalReason: string | null;
1932
1933
  } | null> {
1933
1934
  await ensureRunTables();
1934
1935
  const client = getDbExec();
1935
1936
  const { rows } = await client.execute({
1936
- sql: `SELECT id, thread_id, status, started_at, error_code, error_detail FROM agent_runs WHERE id = ?`,
1937
+ sql: `SELECT id, thread_id, status, started_at, error_code, error_detail, terminal_reason FROM agent_runs WHERE id = ?`,
1937
1938
  args: [runId],
1938
1939
  });
1939
1940
  if (rows.length === 0) return null;
@@ -1944,6 +1945,7 @@ export async function getRunById(runId: string): Promise<{
1944
1945
  started_at: number | string;
1945
1946
  error_code?: string | null;
1946
1947
  error_detail?: string | null;
1948
+ terminal_reason?: string | null;
1947
1949
  };
1948
1950
  return {
1949
1951
  id: r.id,
@@ -1952,6 +1954,7 @@ export async function getRunById(runId: string): Promise<{
1952
1954
  startedAt: Number(r.started_at),
1953
1955
  errorCode: r.error_code ?? null,
1954
1956
  errorDetail: r.error_detail ?? null,
1957
+ terminalReason: r.terminal_reason ?? null,
1955
1958
  };
1956
1959
  }
1957
1960
 
@@ -369,18 +369,38 @@ export type AgentChatEvent =
369
369
  }
370
370
  | {
371
371
  type: "auto_continue";
372
- reason:
373
- | "run_timeout"
374
- | "loop_limit"
375
- | "max_tokens"
376
- | "no_progress"
377
- | "stream_ended"
378
- | "gateway_timeout"
379
- | "network_interrupted";
372
+ reason: ContinuationReason;
380
373
  maxIterations?: number;
381
374
  }
382
375
  | { type: "clear" };
383
376
 
377
+ export const CONTINUATION_REASONS = [
378
+ "run_timeout",
379
+ "loop_limit",
380
+ "max_tokens",
381
+ "no_progress",
382
+ "stream_ended",
383
+ "gateway_timeout",
384
+ "network_interrupted",
385
+ ] as const;
386
+
387
+ export type ContinuationReason = (typeof CONTINUATION_REASONS)[number];
388
+
389
+ /**
390
+ * True when an `agent_runs.terminal_reason` marks a CHUNK boundary rather than
391
+ * the end of the turn. Both writers (`terminalReasonForRun` in run-manager and
392
+ * `markBackgroundContinuationChunkTerminal` in production-agent) record
393
+ * status='completed' with one of these while a chained successor run carries the
394
+ * turn on, so such a row must never be reported to a client as a plain `done`.
395
+ * Mirrored client-side by `BACKGROUND_CONTINUATION_TERMINAL_REASONS`.
396
+ */
397
+ export function isContinuationTerminalReason(reason: unknown): boolean {
398
+ return (
399
+ reason === "auto_continue" ||
400
+ CONTINUATION_REASONS.includes(reason as ContinuationReason)
401
+ );
402
+ }
403
+
384
404
  export interface RunEvent {
385
405
  seq: number;
386
406
  event: AgentChatEvent;
@@ -1290,6 +1290,51 @@ export async function getThreadByShareToken(
1290
1290
  return null;
1291
1291
  }
1292
1292
 
1293
+ /**
1294
+ * Grant a user an explicit share on a thread they don't own. Used by the
1295
+ * messaging-integration path, where a channel conversation runs as the
1296
+ * integration service principal and so creates a thread owned by
1297
+ * `integration@<platform>` rather than the human who asked — without this the
1298
+ * "Open thread" deep link resolves to a 404 for them.
1299
+ *
1300
+ * Idempotent, and never downgrades an existing stronger role.
1301
+ */
1302
+ export async function grantThreadUserShare(
1303
+ threadId: string,
1304
+ userEmail: string,
1305
+ role: ShareRole,
1306
+ grantedBy: string,
1307
+ ): Promise<void> {
1308
+ const normalizedEmail = userEmail.trim().toLowerCase();
1309
+ if (!threadId || !normalizedEmail.includes("@")) return;
1310
+ await ensureTable();
1311
+ const client = getDbExec();
1312
+ const { rows } = await client.execute({
1313
+ sql: `SELECT id, role FROM chat_thread_shares WHERE resource_id = ? AND principal_type = 'user' AND LOWER(principal_id) = ?`,
1314
+ args: [threadId, normalizedEmail],
1315
+ });
1316
+ const existing = rows[0];
1317
+ if (existing) {
1318
+ if (roleSatisfies(existing.role as ShareRole, role)) return;
1319
+ await client.execute({
1320
+ sql: `UPDATE chat_thread_shares SET role = ? WHERE id = ?`,
1321
+ args: [role, existing.id as string],
1322
+ });
1323
+ return;
1324
+ }
1325
+ await client.execute({
1326
+ sql: `INSERT INTO chat_thread_shares (id, resource_id, principal_type, principal_id, role, created_by, created_at) VALUES (?, ?, 'user', ?, ?, ?, ?)`,
1327
+ args: [
1328
+ crypto.randomUUID(),
1329
+ threadId,
1330
+ normalizedEmail,
1331
+ role,
1332
+ grantedBy,
1333
+ new Date().toISOString(),
1334
+ ],
1335
+ });
1336
+ }
1337
+
1293
1338
  export async function deleteThread(id: string): Promise<boolean> {
1294
1339
  await ensureTable();
1295
1340
  const client = getDbExec();
@@ -6,6 +6,8 @@ export {
6
6
  cleanupOldCheckpoints,
7
7
  } from "./store.js";
8
8
 
9
+ export { isCheckpointRestorePath } from "./route-match.js";
10
+
9
11
  export {
10
12
  isGitRepo,
11
13
  hasUncommittedChanges,
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The framework mount shim normally rewrites `event.path` to the mount-relative
3
+ * remainder ("/restore"), but it falls back to the unstripped request path when
4
+ * `event.url` is read-only on the host runtime. Accept both so a restore POST
5
+ * never silently 405s.
6
+ */
7
+ export function isCheckpointRestorePath(path: string | undefined): boolean {
8
+ if (!path) return false;
9
+ return (
10
+ /(^|\/)checkpoints\/restore(?:[/?]|$)/.test(path) ||
11
+ /^\/?restore(?:[/?]|$)/.test(path)
12
+ );
13
+ }