@agent-native/core 0.176.1 → 0.176.2-nightly-20260831184159

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 (1037) hide show
  1. package/corpus/README.md +1 -1
  2. package/corpus/templates/analytics/.agents/skills/frontend-design/SKILL.md +4 -0
  3. package/corpus/templates/analytics/.agents/skills/secrets/SKILL.md +47 -0
  4. package/corpus/templates/analytics/AGENTS.md +13 -2
  5. package/corpus/templates/analytics/CHANGELOG.md +8 -0
  6. package/corpus/templates/analytics/actions/certify-dashboard.ts +39 -0
  7. package/corpus/templates/analytics/actions/get-sql-dashboard.ts +1 -1
  8. package/corpus/templates/analytics/actions/list-analysis-revisions.ts +4 -2
  9. package/corpus/templates/analytics/actions/list-dashboard-revisions.ts +4 -2
  10. package/corpus/templates/analytics/actions/search-analytics-query-catalog.ts +1 -0
  11. package/corpus/templates/analytics/actions/search-dashboard-references.ts +2 -1
  12. package/corpus/templates/analytics/actions/set-workspace-feature-flag.ts +2 -2
  13. package/corpus/templates/analytics/app/components/agents/FeatureFlagsFleetPanel.tsx +16 -1
  14. package/corpus/templates/analytics/app/components/layout/Layout.tsx +58 -0
  15. package/corpus/templates/analytics/app/components/layout/Sidebar.tsx +7 -19
  16. package/corpus/templates/analytics/app/global.css +0 -7
  17. package/corpus/templates/analytics/app/hooks/use-navigation-state.ts +1 -1
  18. package/corpus/templates/analytics/app/i18n-data.ts +42 -0
  19. package/corpus/templates/analytics/app/lib/track-metric.ts +15 -0
  20. package/corpus/templates/analytics/app/pages/NotFound.tsx +1 -1
  21. package/corpus/templates/analytics/app/pages/Placeholder.tsx +1 -1
  22. package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/index.tsx +115 -2
  23. package/corpus/templates/analytics/app/pages/adhoc/sql-dashboard/types.ts +8 -0
  24. package/corpus/templates/analytics/app/pages/sessions/SessionsPage.tsx +23 -25
  25. package/corpus/templates/analytics/app/root.tsx +5 -5
  26. package/corpus/templates/analytics/app/routes/_index.tsx +18 -20
  27. package/corpus/templates/analytics/app/routes/dashboard.tsx +1 -1
  28. package/corpus/templates/analytics/app/routes/home.tsx +39 -0
  29. package/corpus/templates/analytics/changelog/2026-08-27-show-analytics-s-own-registered-flags-in-fleet-feature-flag-.md +6 -0
  30. package/corpus/templates/analytics/changelog/2026-08-28-analytics-loading-placeholders-now-use-a-smooth-whole-surfac.md +6 -0
  31. package/corpus/templates/analytics/changelog/2026-08-28-analytics-loading-states-use-a-softer-whole-surfac.md +6 -0
  32. package/corpus/templates/analytics/changelog/2026-08-28-analytics-sidebar-horizontal-spacing-is-tighter.md +6 -0
  33. package/corpus/templates/analytics/changelog/2026-08-28-sidebar-branding-matches-the-app-text-color-with-a-tighter-m.md +6 -0
  34. package/corpus/templates/analytics/changelog/2026-08-28-sidebar-branding-uses-a-monochrome-agent-native-mark.md +6 -0
  35. package/corpus/templates/analytics/changelog/2026-08-29-analytics-loading-shine-is-more-subtle.md +6 -0
  36. package/corpus/templates/analytics/changelog/2026-08-29-chat-edits-can-be-reverted-to-saved-checkpoints.md +6 -0
  37. package/corpus/templates/analytics/changelog/2026-08-29-dashboard-certification-lives-in-the-overflow-menu.md +6 -0
  38. package/corpus/templates/analytics/changelog/2026-08-29-public-marketing-home.md +6 -0
  39. package/corpus/templates/analytics/package.json +2 -0
  40. package/corpus/templates/analytics/public/manifest.json +1 -1
  41. package/corpus/templates/analytics/server/db/schema.ts +4 -0
  42. package/corpus/templates/analytics/server/handlers/events.ts +10 -1
  43. package/corpus/templates/analytics/server/handlers/first-party-analytics.ts +9 -1
  44. package/corpus/templates/analytics/server/handlers/session-replay.ts +10 -1
  45. package/corpus/templates/analytics/server/lib/agent-readable-resource-context.ts +22 -2
  46. package/corpus/templates/analytics/server/lib/analytics-query-catalog.ts +82 -7
  47. package/corpus/templates/analytics/server/lib/dashboard-certification.ts +58 -0
  48. package/corpus/templates/analytics/server/lib/dashboard-report.ts +1 -0
  49. package/corpus/templates/analytics/server/lib/dashboards-store.ts +429 -46
  50. package/corpus/templates/analytics/server/lib/workspace-feature-flags.ts +204 -32
  51. package/corpus/templates/analytics/server/plugins/agent-chat.ts +139 -0
  52. package/corpus/templates/analytics/server/plugins/auth.ts +1 -0
  53. package/corpus/templates/analytics/server/plugins/core-routes.ts +3 -2
  54. package/corpus/templates/analytics/server/plugins/db.ts +11 -0
  55. package/corpus/templates/assets/.agents/skills/frontend-design/SKILL.md +4 -0
  56. package/corpus/templates/assets/.agents/skills/secrets/SKILL.md +47 -0
  57. package/corpus/templates/assets/app/components/layout/Header.tsx +2 -2
  58. package/corpus/templates/assets/app/components/layout/Layout.tsx +4 -3
  59. package/corpus/templates/assets/app/components/layout/Sidebar.tsx +14 -27
  60. package/corpus/templates/assets/app/hooks/use-navigation-state.ts +2 -2
  61. package/corpus/templates/assets/app/root.tsx +29 -9
  62. package/corpus/templates/assets/app/routes/_index.tsx +15 -116
  63. package/corpus/templates/assets/app/routes/chat.$threadId.tsx +1 -1
  64. package/corpus/templates/assets/app/routes/home.tsx +137 -0
  65. package/corpus/templates/assets/app/routes/library.tsx +5 -1
  66. package/corpus/templates/assets/app/routes/settings.tsx +28 -25
  67. package/corpus/templates/assets/changelog/2026-08-26-templates-across-brand-kits.md +1 -0
  68. package/corpus/templates/assets/public/manifest.json +1 -1
  69. package/corpus/templates/assets/server/plugins/auth.ts +1 -0
  70. package/corpus/templates/brain/.agents/skills/frontend-design/SKILL.md +4 -0
  71. package/corpus/templates/brain/.agents/skills/secrets/SKILL.md +47 -0
  72. package/corpus/templates/brain/app/components/layout/Layout.tsx +3 -3
  73. package/corpus/templates/brain/app/components/layout/Sidebar.tsx +10 -23
  74. package/corpus/templates/brain/app/lib/brain.ts +2 -2
  75. package/corpus/templates/brain/app/root.tsx +13 -3
  76. package/corpus/templates/brain/app/routes/_index.tsx +15 -55
  77. package/corpus/templates/brain/app/routes/home.tsx +76 -0
  78. package/corpus/templates/brain/app/routes.ts +1 -0
  79. package/corpus/templates/brain/public/manifest.json +1 -1
  80. package/corpus/templates/brain/server/lib/brain-health.ts +2 -2
  81. package/corpus/templates/brain/server/plugins/auth.ts +1 -1
  82. package/corpus/templates/brain/server/plugins/core-routes.ts +2 -1
  83. package/corpus/templates/calendar/.agents/skills/frontend-design/SKILL.md +4 -0
  84. package/corpus/templates/calendar/.agents/skills/secrets/SKILL.md +47 -0
  85. package/corpus/templates/calendar/CHANGELOG.md +12 -0
  86. package/corpus/templates/calendar/actions/event-action-helpers.ts +2 -1
  87. package/corpus/templates/calendar/actions/manage-event-draft.ts +1 -1
  88. package/corpus/templates/calendar/actions/update-event.ts +8 -1
  89. package/corpus/templates/calendar/amplify.yml +15 -0
  90. package/corpus/templates/calendar/app/components/calendar/ApolloPanel.tsx +2 -2
  91. package/corpus/templates/calendar/app/components/calendar/CreateEventDialog.tsx +102 -109
  92. package/corpus/templates/calendar/app/components/calendar/DayView.tsx +23 -10
  93. package/corpus/templates/calendar/app/components/calendar/DeleteEventDialog.tsx +2 -11
  94. package/corpus/templates/calendar/app/components/calendar/EventAttendeesSection.tsx +150 -141
  95. package/corpus/templates/calendar/app/components/calendar/EventCard.tsx +3 -1
  96. package/corpus/templates/calendar/app/components/calendar/EventDescription.tsx +2 -2
  97. package/corpus/templates/calendar/app/components/calendar/EventDetailPopover.tsx +359 -222
  98. package/corpus/templates/calendar/app/components/calendar/InlineEventPickers.tsx +13 -5
  99. package/corpus/templates/calendar/app/components/calendar/WeekView.tsx +21 -9
  100. package/corpus/templates/calendar/app/components/layout/Sidebar.tsx +21 -32
  101. package/corpus/templates/calendar/app/global.css +11 -0
  102. package/corpus/templates/calendar/app/hooks/use-meeting-start-notifications.ts +10 -0
  103. package/corpus/templates/calendar/app/hooks/use-navigation-state.ts +3 -3
  104. package/corpus/templates/calendar/app/i18n-data.ts +110 -0
  105. package/corpus/templates/calendar/app/lib/calendar-timezone.ts +12 -3
  106. package/corpus/templates/calendar/app/lib/event-popover-style.ts +43 -0
  107. package/corpus/templates/calendar/app/lib/mcp-embed.ts +8 -2
  108. package/corpus/templates/calendar/app/lib/utils.ts +3 -1
  109. package/corpus/templates/calendar/app/pages/BookingPage.tsx +2 -8
  110. package/corpus/templates/calendar/app/pages/CalendarView.tsx +9 -11
  111. package/corpus/templates/calendar/app/pages/ManageBookingPage.tsx +2 -6
  112. package/corpus/templates/calendar/app/pages/NotFound.tsx +1 -1
  113. package/corpus/templates/calendar/app/pages/Settings.tsx +54 -0
  114. package/corpus/templates/calendar/app/root.tsx +9 -1
  115. package/corpus/templates/calendar/app/routes/{_app._index.tsx → _app.home.tsx} +1 -1
  116. package/corpus/templates/calendar/app/routes/_index.tsx +34 -0
  117. package/corpus/templates/calendar/app/routes/event.tsx +2 -6
  118. package/corpus/templates/calendar/changelog/2026-08-28-all-day-events-stay-in-the-compact-top-bar-in-day-and-week-v.md +6 -0
  119. package/corpus/templates/calendar/changelog/2026-08-28-calendar-organizer-note-emails-now-link-back-to-agent-native.md +6 -0
  120. package/corpus/templates/calendar/changelog/2026-08-28-calendar-shows-google-profile-photos-in-the-desktop-app.md +6 -0
  121. package/corpus/templates/calendar/changelog/2026-08-28-event-creators-can-choose-whether-a-meeting-shows-as-free-or.md +6 -0
  122. package/corpus/templates/calendar/changelog/2026-08-28-event-popovers-match-notion-calendar-s-density-a-284px-blurr.md +6 -0
  123. package/corpus/templates/calendar/changelog/2026-08-28-fixed-calendar-navigation-scheduling-permissions-and-action-.md +6 -0
  124. package/corpus/templates/calendar/changelog/2026-08-28-google-calendar-connections-use-the-registered-callback-on-m.md +6 -0
  125. package/corpus/templates/calendar/changelog/2026-08-28-sidebar-branding-matches-the-app-text-color-with-a-tighter-m.md +6 -0
  126. package/corpus/templates/calendar/changelog/2026-08-28-sidebar-branding-uses-a-monochrome-agent-native-mark.md +6 -0
  127. package/corpus/templates/calendar/changelog/2026-08-28-the-calendar-sidebar-keeps-the-settings-link-compact.md +6 -0
  128. package/corpus/templates/calendar/changelog/2026-08-28-the-calendar-sidebar-keeps-the-workspace-picker-compact.md +6 -0
  129. package/corpus/templates/calendar/changelog/2026-08-29-public-marketing-home.md +6 -0
  130. package/corpus/templates/calendar/public/manifest.json +1 -1
  131. package/corpus/templates/calendar/server/handlers/google-auth.ts +10 -2
  132. package/corpus/templates/calendar/server/lib/emails.ts +2 -1
  133. package/corpus/templates/calendar/server/lib/event-guest-notifications.ts +31 -5
  134. package/corpus/templates/calendar/server/lib/google-calendar.ts +4 -2
  135. package/corpus/templates/calendar/server/plugins/auth.ts +1 -0
  136. package/corpus/templates/calendar/server/plugins/core-routes.ts +5 -3
  137. package/corpus/templates/calendar/shared/event-permissions.ts +12 -0
  138. package/corpus/templates/chat/.agents/skills/frontend-design/SKILL.md +4 -0
  139. package/corpus/templates/chat/.agents/skills/secrets/SKILL.md +47 -0
  140. package/corpus/templates/chat/AGENTS.md +5 -4
  141. package/corpus/templates/chat/app/components/layout/Header.tsx +1 -1
  142. package/corpus/templates/chat/app/components/layout/Layout.tsx +5 -4
  143. package/corpus/templates/chat/app/components/layout/Sidebar.tsx +16 -25
  144. package/corpus/templates/chat/app/hooks/use-navigation-state.ts +5 -5
  145. package/corpus/templates/chat/app/root.tsx +16 -3
  146. package/corpus/templates/chat/app/routes/_index.tsx +17 -74
  147. package/corpus/templates/chat/app/routes/chat.$threadId.tsx +1 -1
  148. package/corpus/templates/chat/app/routes/home.tsx +94 -0
  149. package/corpus/templates/chat/netlify.toml +2 -1
  150. package/corpus/templates/chat/public/manifest.json +1 -1
  151. package/corpus/templates/chat/server/plugins/auth.ts +1 -0
  152. package/corpus/templates/clips/.agents/skills/frontend-design/SKILL.md +4 -0
  153. package/corpus/templates/clips/.agents/skills/secrets/SKILL.md +47 -0
  154. package/corpus/templates/clips/actions/add-comment.ts +18 -1
  155. package/corpus/templates/clips/actions/get-recording-player-data.ts +2 -0
  156. package/corpus/templates/clips/actions/list-comments.ts +2 -0
  157. package/corpus/templates/clips/actions/list-notifications.ts +60 -28
  158. package/corpus/templates/clips/actions/list-recording-mention-members.ts +64 -0
  159. package/corpus/templates/clips/actions/list-recordings.ts +1 -1
  160. package/corpus/templates/clips/actions/reply-to-comment.ts +17 -1
  161. package/corpus/templates/clips/actions/update-comment.ts +36 -2
  162. package/corpus/templates/clips/app/components/library/empty-state.tsx +1 -3
  163. package/corpus/templates/clips/app/components/library/library-grid.tsx +18 -6
  164. package/corpus/templates/clips/app/components/library/library-layout.tsx +6 -58
  165. package/corpus/templates/clips/app/components/library/recording-card.tsx +101 -3
  166. package/corpus/templates/clips/app/components/library/sort-menu.tsx +2 -2
  167. package/corpus/templates/clips/app/components/player/comment-composer.tsx +284 -0
  168. package/corpus/templates/clips/app/components/player/comments-panel.tsx +162 -46
  169. package/corpus/templates/clips/app/components/player/transcript-panel.tsx +38 -133
  170. package/corpus/templates/clips/app/components/player/video-player.tsx +1 -1
  171. package/corpus/templates/clips/app/components/recorder/recorder-engine.ts +99 -20
  172. package/corpus/templates/clips/app/components/recorder/recording-toolbar.tsx +110 -116
  173. package/corpus/templates/clips/app/components/recorder/storage-setup-card.tsx +83 -60
  174. package/corpus/templates/clips/app/components/settings/ai-setup-section.tsx +17 -11
  175. package/corpus/templates/clips/app/components/settings/types.ts +5 -1
  176. package/corpus/templates/clips/app/components/settings/video-storage-section.tsx +21 -12
  177. package/corpus/templates/clips/app/global.css +0 -27
  178. package/corpus/templates/clips/app/hooks/use-desktop-promo.ts +3 -17
  179. package/corpus/templates/clips/app/hooks/use-mention-members.ts +24 -0
  180. package/corpus/templates/clips/app/hooks/use-navigation-state.ts +2 -2
  181. package/corpus/templates/clips/app/i18n/en-US.ts +15 -0
  182. package/corpus/templates/clips/app/lib/recording-backup.ts +245 -0
  183. package/corpus/templates/clips/app/lib/recording-retry.ts +189 -0
  184. package/corpus/templates/clips/app/lib/recording-status.ts +32 -0
  185. package/corpus/templates/clips/app/root.tsx +11 -2
  186. package/corpus/templates/clips/app/routes/_app.home.tsx +62 -0
  187. package/corpus/templates/clips/app/routes/_app.notifications.tsx +45 -12
  188. package/corpus/templates/clips/app/routes/_app.settings._index.tsx +2 -0
  189. package/corpus/templates/clips/app/routes/_index.tsx +11 -40
  190. package/corpus/templates/clips/app/routes/download.tsx +148 -15
  191. package/corpus/templates/clips/app/routes/embed.$shareId.tsx +4 -3
  192. package/corpus/templates/clips/app/routes/r.$recordingId.tsx +6 -11
  193. package/corpus/templates/clips/app/routes/record.tsx +72 -13
  194. package/corpus/templates/clips/app/routes/share.$shareId.tsx +40 -24
  195. package/corpus/templates/clips/app/routes/share.meeting.$meetingId.tsx +2 -7
  196. package/corpus/templates/clips/changelog/2026-08-28-chrome-extension-download-help.md +6 -0
  197. package/corpus/templates/clips/changelog/2026-08-28-clips-loading-skeletons-use-a-softer-whole-surface.md +6 -0
  198. package/corpus/templates/clips/changelog/2026-08-28-comment-composer-no-longer-has-an-outer-border.md +6 -0
  199. package/corpus/templates/clips/changelog/2026-08-29-clips-loading-shine-is-more-subtle.md +6 -0
  200. package/corpus/templates/clips/desktop/src/app.tsx +377 -476
  201. package/corpus/templates/clips/desktop/src/components/ui/skeleton.tsx +1 -1
  202. package/corpus/templates/clips/desktop/src/components/ui/spinner.tsx +1 -17
  203. package/corpus/templates/clips/desktop/src/lib/recorder.ts +4 -0
  204. package/corpus/templates/clips/desktop/src/overlays/countdown.tsx +0 -8
  205. package/corpus/templates/clips/desktop/src/overlays/record-pill.tsx +221 -460
  206. package/corpus/templates/clips/desktop/src/styles.css +0 -40
  207. package/corpus/templates/clips/desktop/src/tailwind.css +28 -14
  208. package/corpus/templates/clips/desktop/src-tauri/src/clips/mod.rs +15 -11
  209. package/corpus/templates/clips/desktop/src-tauri/src/lib.rs +9 -0
  210. package/corpus/templates/clips/desktop/src-tauri/src/native_screen.rs +192 -57
  211. package/corpus/templates/clips/desktop/src-tauri/src/recording_indicator.rs +9 -3
  212. package/corpus/templates/clips/desktop/src-tauri/src/tray.rs +12 -0
  213. package/corpus/templates/clips/desktop/src-tauri/src/util.rs +97 -3
  214. package/corpus/templates/clips/public/manifest.json +1 -1
  215. package/corpus/templates/clips/server/db/schema.ts +1 -0
  216. package/corpus/templates/clips/server/lib/activity-notifications.ts +30 -5
  217. package/corpus/templates/clips/server/lib/comment-mentions.ts +23 -0
  218. package/corpus/templates/clips/server/lib/emails.ts +2 -2
  219. package/corpus/templates/clips/server/lib/recording-page-access.ts +16 -0
  220. package/corpus/templates/clips/server/lib/transactional-email-templates.ts +14 -7
  221. package/corpus/templates/clips/server/plugins/auth.ts +1 -0
  222. package/corpus/templates/clips/server/plugins/core-routes.ts +5 -0
  223. package/corpus/templates/clips/server/plugins/db.ts +5 -0
  224. package/corpus/templates/clips/server/routes/api/auth/google-calendar.get.ts +4 -2
  225. package/corpus/templates/clips/server/routes/api/clips-latest.json.get.ts +77 -22
  226. package/corpus/templates/clips/server/routes/api/public-recording.get.ts +11 -0
  227. package/corpus/templates/clips/server/routes/api/uploads/[recordingId]/interrupt.post.ts +4 -4
  228. package/corpus/templates/clips/server/routes/api/uploads/[recordingId]/resume.get.ts +1 -1
  229. package/corpus/templates/clips/shared/comment-mentions.ts +71 -0
  230. package/corpus/templates/clips/shared/prerendered-public-paths.ts +1 -1
  231. package/corpus/templates/clips/shared/recording-core.ts +5 -0
  232. package/corpus/templates/clips/shared/recording-playhead.css +207 -0
  233. package/corpus/templates/clips/shared/recording-playhead.tsx +616 -0
  234. package/corpus/templates/content/.agents/skills/frontend-design/SKILL.md +4 -0
  235. package/corpus/templates/content/.agents/skills/secrets/SKILL.md +47 -0
  236. package/corpus/templates/content/CHANGELOG.md +6 -0
  237. package/corpus/templates/content/actions/_property-utils.ts +45 -9
  238. package/corpus/templates/content/actions/edit-document.ts +17 -0
  239. package/corpus/templates/content/actions/get-document.ts +31 -11
  240. package/corpus/templates/content/actions/list-document-properties.ts +30 -2
  241. package/corpus/templates/content/actions/list-document-versions.ts +49 -17
  242. package/corpus/templates/content/actions/list-documents.ts +13 -2
  243. package/corpus/templates/content/actions/restore-document-version.ts +8 -1
  244. package/corpus/templates/content/actions/update-document.ts +8 -0
  245. package/corpus/templates/content/app/components/QueryErrorState.tsx +1 -0
  246. package/corpus/templates/content/app/components/editor/DocumentBlockFields.tsx +28 -8
  247. package/corpus/templates/content/app/components/editor/DocumentEditor.tsx +94 -61
  248. package/corpus/templates/content/app/components/editor/DocumentProperties.tsx +24 -10
  249. package/corpus/templates/content/app/components/editor/database/DatabaseView.tsx +16 -13
  250. package/corpus/templates/content/app/components/editor/database/settings.tsx +16 -13
  251. package/corpus/templates/content/app/components/layout/Layout.tsx +35 -1
  252. package/corpus/templates/content/app/components/sidebar/DocumentSidebar.tsx +5 -18
  253. package/corpus/templates/content/app/hooks/use-document-properties.ts +5 -3
  254. package/corpus/templates/content/app/hooks/use-documents.ts +3 -1
  255. package/corpus/templates/content/app/hooks/use-navigation-state.ts +3 -3
  256. package/corpus/templates/content/app/root.tsx +9 -4
  257. package/corpus/templates/content/app/routes/{_app._index.tsx → _app.home.tsx} +12 -4
  258. package/corpus/templates/content/app/routes/_index.tsx +33 -0
  259. package/corpus/templates/content/changelog/2026-08-26-shared-page-load-failures-now-stay-visible-and-safe.md +6 -0
  260. package/corpus/templates/content/docs/product/capabilities/content.workspace.session-restore.md +2 -2
  261. package/corpus/templates/content/e2e/playwright.config.ts +1 -1
  262. package/corpus/templates/content/package.json +2 -0
  263. package/corpus/templates/content/parity/matrix.md +1 -1
  264. package/corpus/templates/content/parity/matrix.ts +1 -1
  265. package/corpus/templates/content/public/manifest.json +1 -1
  266. package/corpus/templates/content/server/db/schema.ts +1 -0
  267. package/corpus/templates/content/server/lib/document-version-context.ts +67 -0
  268. package/corpus/templates/content/server/plugins/agent-chat.ts +155 -0
  269. package/corpus/templates/content/server/plugins/auth.ts +1 -0
  270. package/corpus/templates/content/server/plugins/core-routes.ts +3 -2
  271. package/corpus/templates/content/server/plugins/db.ts +5 -0
  272. package/corpus/templates/content/shared/api.ts +6 -4
  273. package/corpus/templates/crm/.agents/skills/frontend-design/SKILL.md +4 -0
  274. package/corpus/templates/crm/.agents/skills/secrets/SKILL.md +47 -0
  275. package/corpus/templates/crm/actions/list-crm-dashboard-revisions.ts +1 -1
  276. package/corpus/templates/crm/agent-native.app-skill.json +1 -1
  277. package/corpus/templates/crm/app/components/layout/CrmCommandMenu.tsx +1 -1
  278. package/corpus/templates/crm/app/components/layout/CrmLayout.tsx +36 -1
  279. package/corpus/templates/crm/app/components/layout/CrmSidebar.tsx +3 -3
  280. package/corpus/templates/crm/app/root.tsx +28 -7
  281. package/corpus/templates/crm/app/routes/_index.tsx +28 -18
  282. package/corpus/templates/crm/app/routes/home.tsx +27 -0
  283. package/corpus/templates/crm/app/routes/setup.tsx +2 -2
  284. package/corpus/templates/crm/app/routes.ts +1 -0
  285. package/corpus/templates/crm/public/manifest.json +1 -1
  286. package/corpus/templates/crm/server/plugins/agent-chat.ts +81 -0
  287. package/corpus/templates/crm/server/plugins/auth.ts +1 -0
  288. package/corpus/templates/crm/server/plugins/core-routes.ts +2 -1
  289. package/corpus/templates/crm/server/plugins/db.ts +7 -1
  290. package/corpus/templates/crm/shared/crm-navigation.ts +3 -2
  291. package/corpus/templates/design/.agents/skills/design-generation/SKILL.md +13 -0
  292. package/corpus/templates/design/.agents/skills/frontend-design/SKILL.md +4 -0
  293. package/corpus/templates/design/.agents/skills/secrets/SKILL.md +47 -0
  294. package/corpus/templates/design/.generated/bridge/editor-chrome.generated.ts +22 -10
  295. package/corpus/templates/design/AGENTS.md +1 -1
  296. package/corpus/templates/design/actions/add-breakpoint.ts +3 -1
  297. package/corpus/templates/design/actions/add-fusion-screens.ts +2 -0
  298. package/corpus/templates/design/actions/add-localhost-screens.ts +16 -11
  299. package/corpus/templates/design/actions/apply-a11y-fix.ts +6 -8
  300. package/corpus/templates/design/actions/apply-component-prop-edit.ts +3 -1
  301. package/corpus/templates/design/actions/apply-design-token-edit.ts +3 -1
  302. package/corpus/templates/design/actions/apply-motion-edit.ts +18 -13
  303. package/corpus/templates/design/actions/apply-shader-fill.ts +3 -1
  304. package/corpus/templates/design/actions/apply-source-edit.ts +6 -1
  305. package/corpus/templates/design/actions/apply-tweaks.ts +3 -1
  306. package/corpus/templates/design/actions/apply-visual-edit.ts +14 -9
  307. package/corpus/templates/design/actions/clone-creative-context-design.ts +6 -1
  308. package/corpus/templates/design/actions/create-component.ts +3 -1
  309. package/corpus/templates/design/actions/create-file.ts +3 -1
  310. package/corpus/templates/design/actions/delete-file.ts +3 -1
  311. package/corpus/templates/design/actions/detach-component-instance.ts +3 -1
  312. package/corpus/templates/design/actions/edit-design.ts +16 -11
  313. package/corpus/templates/design/actions/generate-design.ts +19 -14
  314. package/corpus/templates/design/actions/get-design-branch-diff.ts +26 -31
  315. package/corpus/templates/design/actions/get-design-review.ts +25 -31
  316. package/corpus/templates/design/actions/get-design-system-index-status.ts +55 -0
  317. package/corpus/templates/design/actions/get-design-system.ts +1 -1
  318. package/corpus/templates/design/actions/hydrate-figma-paste-images.ts +3 -1
  319. package/corpus/templates/design/actions/import-design-source.ts +16 -9
  320. package/corpus/templates/design/actions/import-design-tokens.ts +3 -1
  321. package/corpus/templates/design/actions/import-figma-clipboard.ts +28 -16
  322. package/corpus/templates/design/actions/import-figma-frame.ts +3 -1
  323. package/corpus/templates/design/actions/insert-asset.ts +3 -1
  324. package/corpus/templates/design/actions/insert-design-native-asset.ts +3 -1
  325. package/corpus/templates/design/actions/insert-figma-library-asset.ts +3 -1
  326. package/corpus/templates/design/actions/list-design-versions.ts +23 -0
  327. package/corpus/templates/design/actions/migrate-board-objects-to-file.ts +3 -1
  328. package/corpus/templates/design/actions/open-visual-edit.ts +23 -20
  329. package/corpus/templates/design/actions/present-design-variants.ts +7 -2
  330. package/corpus/templates/design/actions/refresh-design-system-with-builder.ts +66 -10
  331. package/corpus/templates/design/actions/remove-breakpoint.ts +3 -1
  332. package/corpus/templates/design/actions/remove-motion-timeline.ts +3 -1
  333. package/corpus/templates/design/actions/restore-design-version.ts +16 -0
  334. package/corpus/templates/design/actions/set-layout-grid.ts +94 -0
  335. package/corpus/templates/design/actions/swap-component-instance.ts +6 -1
  336. package/corpus/templates/design/actions/update-design.ts +16 -11
  337. package/corpus/templates/design/actions/update-file.ts +2 -0
  338. package/corpus/templates/design/app/components/design/DesignCanvas.tsx +25 -0
  339. package/corpus/templates/design/app/components/design/EditPanel.tsx +36 -8
  340. package/corpus/templates/design/app/components/design/LayersPanel.tsx +6 -6
  341. package/corpus/templates/design/app/components/design/MultiScreenCanvas.tsx +185 -29
  342. package/corpus/templates/design/app/components/design/ReviewCommentsPanel.tsx +4 -4
  343. package/corpus/templates/design/app/components/design/ReviewPanel.tsx +1 -1
  344. package/corpus/templates/design/app/components/design/bridge/editor-chrome.bridge.ts +35 -10
  345. package/corpus/templates/design/app/components/design/canvas-primitive-style.ts +16 -9
  346. package/corpus/templates/design/app/components/design/edit-panel/component-section.tsx +51 -21
  347. package/corpus/templates/design/app/components/design/edit-panel/effects-properties.tsx +18 -17
  348. package/corpus/templates/design/app/components/design/edit-panel/field-primitives.tsx +6 -1
  349. package/corpus/templates/design/app/components/design/edit-panel/frame-presets-panel.tsx +3 -3
  350. package/corpus/templates/design/app/components/design/edit-panel/layout-grid-properties.tsx +88 -0
  351. package/corpus/templates/design/app/components/design/edit-panel/panel-primitives.tsx +5 -2
  352. package/corpus/templates/design/app/components/design/edit-panel/position-layout-properties.tsx +8 -4
  353. package/corpus/templates/design/app/components/design/edit-panel/typography-helpers.ts +8 -103
  354. package/corpus/templates/design/app/components/design/edit-panel/typography-properties.tsx +68 -83
  355. package/corpus/templates/design/app/components/design/editor/MakeRealDialog.tsx +35 -10
  356. package/corpus/templates/design/app/components/design/inspector/AutoLayoutMatrix.tsx +29 -24
  357. package/corpus/templates/design/app/components/design/inspector/DesignColorPicker.tsx +6 -0
  358. package/corpus/templates/design/app/components/design/inspector/GlslShaderPanel.tsx +72 -71
  359. package/corpus/templates/design/app/components/design/inspector/InspectorControlPopover.tsx +1 -1
  360. package/corpus/templates/design/app/components/design/keyboard-shortcuts.ts +9 -0
  361. package/corpus/templates/design/app/components/design/multi-screen/types.ts +8 -0
  362. package/corpus/templates/design/app/components/layout/Layout.tsx +32 -0
  363. package/corpus/templates/design/app/components/layout/Sidebar.tsx +8 -21
  364. package/corpus/templates/design/app/global.css +72 -1
  365. package/corpus/templates/design/app/hooks/use-navigation-state.ts +1 -1
  366. package/corpus/templates/design/app/hooks/useDesignHotkeys.ts +32 -1
  367. package/corpus/templates/design/app/i18n-data.ts +116 -12
  368. package/corpus/templates/design/app/i18n-keyboard-shortcuts.ts +3 -1
  369. package/corpus/templates/design/app/lib/design-system-data.ts +36 -0
  370. package/corpus/templates/design/app/pages/DesignEditor.tsx +170 -34
  371. package/corpus/templates/design/app/pages/DesignSystems.tsx +126 -11
  372. package/corpus/templates/design/app/pages/Index.tsx +15 -7
  373. package/corpus/templates/design/app/pages/NotFound.tsx +1 -1
  374. package/corpus/templates/design/app/pages/Templates.tsx +18 -3
  375. package/corpus/templates/design/app/pages/VisualEdit.tsx +1 -1
  376. package/corpus/templates/design/app/pages/design-editor/code-layer-state.ts +3 -3
  377. package/corpus/templates/design/app/pages/design-editor/commands/README.md +1 -0
  378. package/corpus/templates/design/app/pages/design-editor/commands/geometry-commit.ts +2 -1
  379. package/corpus/templates/design/app/pages/design-editor/commands/set-layout-grid.ts +66 -0
  380. package/corpus/templates/design/app/pages/design-editor/design-data-geometry-utils.ts +5 -0
  381. package/corpus/templates/design/app/pages/design-editor/effects/publish-agent-selection-context.ts +9 -1
  382. package/corpus/templates/design/app/pages/design-editor/effects/resume-pending-generation.ts +39 -9
  383. package/corpus/templates/design/app/pages/design-editor/generation-prompt-directives.ts +31 -2
  384. package/corpus/templates/design/app/pages/design-editor/geometry-persistence.ts +26 -0
  385. package/corpus/templates/design/app/pages/design-editor/intake-question-topics.ts +335 -0
  386. package/corpus/templates/design/app/pages/design-editor/nudge-intent.ts +8 -1
  387. package/corpus/templates/design/app/root.tsx +12 -2
  388. package/corpus/templates/design/app/routes/_index.tsx +14 -1
  389. package/corpus/templates/design/app/routes/home.tsx +21 -0
  390. package/corpus/templates/design/changelog/2026-08-21-builder-design-system-imports-reconcile-after-indexing.md +1 -1
  391. package/corpus/templates/design/changelog/2026-08-28-frames-can-carry-an-8px-layout-grid-that-positions-snap-to.md +6 -0
  392. package/corpus/templates/design/changelog/2026-08-28-x-and-y-are-always-whole-numbers.md +6 -0
  393. package/corpus/templates/design/public/manifest.json +1 -1
  394. package/corpus/templates/design/server/db/schema.ts +2 -0
  395. package/corpus/templates/design/server/handlers/design-system-builder-link.ts +84 -0
  396. package/corpus/templates/design/server/lib/builder-design-system-proxy.ts +9 -1
  397. package/corpus/templates/design/server/lib/design-versions.ts +1017 -0
  398. package/corpus/templates/design/server/plugins/agent-chat.ts +144 -0
  399. package/corpus/templates/design/server/plugins/auth.ts +1 -1
  400. package/corpus/templates/design/server/plugins/core-routes.ts +3 -2
  401. package/corpus/templates/design/server/plugins/db.ts +7 -0
  402. package/corpus/templates/design/server/routes/api/design-system-builder-link.get.ts +1 -0
  403. package/corpus/templates/design/shared/canvas-math.ts +106 -14
  404. package/corpus/templates/design/shared/layout-grid.ts +80 -0
  405. package/corpus/templates/dispatch/.agents/skills/frontend-design/SKILL.md +4 -0
  406. package/corpus/templates/dispatch/.agents/skills/secrets/SKILL.md +47 -0
  407. package/corpus/templates/dispatch/AGENTS.md +11 -13
  408. package/corpus/templates/dispatch/actions/list-workspace-connections.ts +10 -5
  409. package/corpus/templates/dispatch/app/i18n-data.ts +120 -0
  410. package/corpus/templates/dispatch/app/root.tsx +11 -1
  411. package/corpus/templates/dispatch/app/routes/_index.tsx +34 -7
  412. package/corpus/templates/dispatch/app/routes/home.tsx +7 -0
  413. package/corpus/templates/dispatch/package.json +1 -0
  414. package/corpus/templates/dispatch/public/manifest.json +1 -1
  415. package/corpus/templates/factory/.agents/skills/factory-graphs/SKILL.md +11 -2
  416. package/corpus/templates/factory/.agents/skills/frontend-design/SKILL.md +4 -0
  417. package/corpus/templates/factory/.agents/skills/secrets/SKILL.md +47 -0
  418. package/corpus/templates/factory/.env.example +2 -14
  419. package/corpus/templates/factory/AGENTS.md +12 -11
  420. package/corpus/templates/factory/README.md +15 -17
  421. package/corpus/templates/factory/actions/{babysit-agent-native-pull-request.ts → babysit-factory-pull-request.ts} +125 -88
  422. package/corpus/templates/factory/actions/create-factory-automation.ts +161 -0
  423. package/corpus/templates/factory/actions/create-factory.ts +4 -124
  424. package/corpus/templates/factory/actions/delete-factory.ts +11 -23
  425. package/corpus/templates/factory/actions/{start-builder-for-item.ts → dispatch-factory-item.ts} +169 -57
  426. package/corpus/templates/factory/actions/get-slack-feedback-context.ts +30 -10
  427. package/corpus/templates/factory/actions/get-triage-config.ts +22 -0
  428. package/corpus/templates/factory/actions/get-triage-item.ts +49 -2
  429. package/corpus/templates/factory/actions/{govern-agent-native-pull-request.ts → govern-factory-pull-request.ts} +95 -112
  430. package/corpus/templates/factory/actions/ingest-github-observation.ts +9 -2
  431. package/corpus/templates/factory/actions/list-factory-audit.ts +85 -12
  432. package/corpus/templates/factory/actions/list-factory-automation-templates.ts +56 -0
  433. package/corpus/templates/factory/actions/list-factory-automations.ts +36 -3
  434. package/corpus/templates/factory/actions/list-factory-graph-versions.ts +37 -10
  435. package/corpus/templates/factory/actions/list-triage-items.ts +120 -15
  436. package/corpus/templates/factory/actions/poll-github-sources.ts +102 -58
  437. package/corpus/templates/factory/actions/poll-sentry-errors.ts +73 -36
  438. package/corpus/templates/factory/actions/poll-slack-channel.ts +112 -28
  439. package/corpus/templates/factory/actions/{babysit-pull-request.ts → propose-pr-babysit-status.ts} +9 -47
  440. package/corpus/templates/factory/actions/reconcile-triage-run.ts +1 -1
  441. package/corpus/templates/factory/actions/save-factory-automation.ts +131 -33
  442. package/corpus/templates/factory/actions/save-factory-graph.ts +31 -8
  443. package/corpus/templates/factory/actions/save-triage-config.ts +7 -27
  444. package/corpus/templates/factory/actions/save-triage-rule.ts +1 -1
  445. package/corpus/templates/factory/app/components/factory/CreateFactoryAutomationView.tsx +258 -0
  446. package/corpus/templates/factory/app/components/factory/FactoryAuditView.tsx +349 -106
  447. package/corpus/templates/factory/app/components/factory/FactoryAutomationFields.tsx +614 -0
  448. package/corpus/templates/factory/app/components/factory/FactoryInboxView.tsx +1136 -0
  449. package/corpus/templates/factory/app/components/factory/FactoryInspector.tsx +7 -14
  450. package/corpus/templates/factory/app/components/factory/FactorySettingsView.tsx +4 -223
  451. package/corpus/templates/factory/app/components/factory/NewFactoryForm.tsx +10 -205
  452. package/corpus/templates/factory/app/components/factory/SlackMrkdwn.tsx +100 -0
  453. package/corpus/templates/factory/app/components/factory/audit-filters.ts +30 -0
  454. package/corpus/templates/factory/app/components/factory/factory-automation-form.ts +120 -0
  455. package/corpus/templates/factory/app/components/factory/inbox-filters.ts +84 -0
  456. package/corpus/templates/factory/app/components/factory/inbox-source-url.ts +23 -0
  457. package/corpus/templates/factory/app/components/factory/slack-emoji.ts +165 -0
  458. package/corpus/templates/factory/app/components/factory/slack-mrkdwn.ts +128 -0
  459. package/corpus/templates/factory/app/components/layout/Header.tsx +1 -1
  460. package/corpus/templates/factory/app/components/layout/Layout.tsx +63 -6
  461. package/corpus/templates/factory/app/components/layout/Sidebar.tsx +13 -26
  462. package/corpus/templates/factory/app/components/triage/triage-status-pill.tsx +63 -14
  463. package/corpus/templates/factory/app/global.css +106 -0
  464. package/corpus/templates/factory/app/hooks/use-navigation-state.ts +16 -10
  465. package/corpus/templates/factory/app/i18n/en-US.ts +154 -7
  466. package/corpus/templates/factory/app/lib/factory-tab-params.ts +59 -0
  467. package/corpus/templates/factory/app/lib/safe-http-url.ts +8 -0
  468. package/corpus/templates/factory/app/root.tsx +16 -3
  469. package/corpus/templates/factory/app/routes/_index.tsx +27 -5
  470. package/corpus/templates/factory/app/routes/factory.tsx +325 -733
  471. package/corpus/templates/factory/app/routes/home.tsx +13 -0
  472. package/corpus/templates/factory/app/routes/new-factory.tsx +3 -5
  473. package/corpus/templates/factory/changelog/2026-08-26-inbox-full-screen-thread.md +6 -0
  474. package/corpus/templates/factory/changelog/2026-08-26-inbox-thread-and-audit-labels.md +6 -0
  475. package/corpus/templates/factory/changelog/2026-08-27-audit-run-list-stacks.md +6 -0
  476. package/corpus/templates/factory/changelog/2026-08-27-audit-run-names-wrap.md +6 -0
  477. package/corpus/templates/factory/changelog/2026-08-27-factory-opens-on-inbox.md +6 -0
  478. package/corpus/templates/factory/changelog/2026-08-27-github-repository-url.md +6 -0
  479. package/corpus/templates/factory/changelog/2026-08-27-inbox-filters.md +6 -0
  480. package/corpus/templates/factory/changelog/2026-08-27-polling-does-not-enable-automations.md +6 -0
  481. package/corpus/templates/factory/changelog/2026-08-27-pr-babysit-can-poll-github.md +6 -0
  482. package/corpus/templates/factory/changelog/2026-08-28-factory-automations-use-workspace-connections.md +6 -0
  483. package/corpus/templates/factory/changelog/2026-08-28-inbox-approve-and-start-removed.md +6 -0
  484. package/corpus/templates/factory/changelog/2026-08-28-pr-babysit-audit-shows-decisions.md +6 -0
  485. package/corpus/templates/factory/changelog/2026-08-28-pr-babysit-reviews-next-github-prs.md +6 -0
  486. package/corpus/templates/factory/changelog/2026-08-28-pr-babysit-sticky-out-of-scope.md +6 -0
  487. package/corpus/templates/factory/changelog/2026-08-28-pr-babysit-uses-github-evidence.md +6 -0
  488. package/corpus/templates/factory/changelog/2026-08-29-audit-filters-pagination-scroll.md +6 -0
  489. package/corpus/templates/factory/changelog/2026-08-29-create-factory-automations.md +6 -0
  490. package/corpus/templates/factory/changelog/2026-08-29-dispatch-reaction-argument.md +6 -0
  491. package/corpus/templates/factory/changelog/2026-08-29-factory-action-names-match-behavior.md +6 -0
  492. package/corpus/templates/factory/public/manifest.json +1 -1
  493. package/corpus/templates/factory/server/connectors/slack.ts +8 -6
  494. package/corpus/templates/factory/server/db/schema.ts +23 -0
  495. package/corpus/templates/factory/server/lib/audit-cursor.ts +44 -0
  496. package/corpus/templates/factory/server/lib/factory-action-names.ts +15 -0
  497. package/corpus/templates/factory/server/lib/factory-audit-report.ts +29 -9
  498. package/corpus/templates/factory/server/lib/factory-automation-caller.ts +38 -0
  499. package/corpus/templates/factory/server/lib/factory-automation-config.ts +543 -0
  500. package/corpus/templates/factory/server/lib/factory-automation-plan.ts +0 -48
  501. package/corpus/templates/factory/server/lib/factory-automation-repair.ts +2 -18
  502. package/corpus/templates/factory/server/lib/factory-poll-cursors.ts +98 -0
  503. package/corpus/templates/factory/server/lib/factory-scope.ts +8 -0
  504. package/corpus/templates/factory/server/lib/github-repository.ts +104 -0
  505. package/corpus/templates/factory/server/lib/inbox-cursor.ts +34 -0
  506. package/corpus/templates/factory/server/lib/pr-babysit-prompt.ts +33 -0
  507. package/corpus/templates/factory/server/lib/require-factory-automation.ts +58 -17
  508. package/corpus/templates/factory/server/lib/safe-http-url.ts +8 -0
  509. package/corpus/templates/factory/server/lib/slack-feedback-prompt.ts +19 -10
  510. package/corpus/templates/factory/server/lib/source-reaction.ts +37 -0
  511. package/corpus/templates/factory/server/plugins/agent-chat.ts +18 -22
  512. package/corpus/templates/factory/server/plugins/auth.ts +1 -0
  513. package/corpus/templates/factory/server/plugins/factory-migrations.ts +26 -0
  514. package/corpus/templates/factory/server/plugins/factory-scheduler-job.ts +277 -164
  515. package/corpus/templates/factory/server/plugins/integrations.ts +5 -7
  516. package/corpus/templates/factory/server/triage/github-client.ts +274 -3
  517. package/corpus/templates/factory/server/triage/github-ingestion.ts +3 -1
  518. package/corpus/templates/factory/server/triage/metadata.ts +12 -0
  519. package/corpus/templates/factory/server/triage/pr-babysit.ts +22 -21
  520. package/corpus/templates/factory/server/triage/review-skill-alignment.ts +11 -11
  521. package/corpus/templates/factory/server/triage/review-state.ts +39 -0
  522. package/corpus/templates/factory/server/triage/slack-client.ts +14 -6
  523. package/corpus/templates/factory/server/triage/slack-poller.ts +34 -65
  524. package/corpus/templates/factory/server/triage/slack-user-labels.ts +126 -0
  525. package/corpus/templates/forms/.agents/skills/frontend-design/SKILL.md +4 -0
  526. package/corpus/templates/forms/.agents/skills/secrets/SKILL.md +47 -0
  527. package/corpus/templates/forms/AGENTS.md +4 -3
  528. package/corpus/templates/forms/actions/response-insights.ts +4 -4
  529. package/corpus/templates/forms/actions/retry-response-deliveries.ts +26 -0
  530. package/corpus/templates/forms/app/components/layout/Sidebar.tsx +8 -33
  531. package/corpus/templates/forms/app/hooks/use-navigation-state.ts +1 -1
  532. package/corpus/templates/forms/app/lib/route-prewarm.ts +1 -1
  533. package/corpus/templates/forms/app/root.tsx +3 -2
  534. package/corpus/templates/forms/app/routes/_app.home.tsx +47 -0
  535. package/corpus/templates/forms/app/routes/_app.tsx +2 -1
  536. package/corpus/templates/forms/app/routes/_index.tsx +10 -23
  537. package/corpus/templates/forms/public/manifest.json +1 -1
  538. package/corpus/templates/forms/server/db/schema.ts +64 -17
  539. package/corpus/templates/forms/server/handlers/submissions.ts +1022 -94
  540. package/corpus/templates/forms/server/lib/integrations.ts +100 -33
  541. package/corpus/templates/forms/server/middleware/00-public-cors.ts +1 -1
  542. package/corpus/templates/forms/server/plugins/auth.ts +1 -0
  543. package/corpus/templates/forms/server/plugins/core-routes.ts +1 -0
  544. package/corpus/templates/forms/server/plugins/db.ts +40 -0
  545. package/corpus/templates/macros/.agents/skills/frontend-design/SKILL.md +4 -0
  546. package/corpus/templates/macros/.agents/skills/secrets/SKILL.md +47 -0
  547. package/corpus/templates/macros/actions/view-screen.ts +1 -1
  548. package/corpus/templates/macros/app/components/layout/AppLayout.tsx +9 -21
  549. package/corpus/templates/macros/app/components/layout/Header.tsx +1 -1
  550. package/corpus/templates/macros/app/root.tsx +22 -8
  551. package/corpus/templates/macros/app/routes/_index.tsx +16 -291
  552. package/corpus/templates/macros/app/routes/home.tsx +312 -0
  553. package/corpus/templates/macros/server/plugins/auth.ts +9 -7
  554. package/corpus/templates/macros/server/plugins/core-routes.ts +1 -0
  555. package/corpus/templates/mail/.agents/skills/frontend-design/SKILL.md +4 -0
  556. package/corpus/templates/mail/.agents/skills/inbox-automations/SKILL.md +13 -2
  557. package/corpus/templates/mail/.agents/skills/inbox-reads-and-triage/SKILL.md +1 -1
  558. package/corpus/templates/mail/.agents/skills/secrets/SKILL.md +47 -0
  559. package/corpus/templates/mail/AGENTS.md +5 -2
  560. package/corpus/templates/mail/actions/apply-ai-filter.ts +294 -0
  561. package/corpus/templates/mail/actions/create-automation.ts +1 -0
  562. package/corpus/templates/mail/actions/get-ai-filter.ts +19 -0
  563. package/corpus/templates/mail/actions/manage-automations.ts +162 -157
  564. package/corpus/templates/mail/actions/manage-email-rules.ts +3 -0
  565. package/corpus/templates/mail/actions/navigate.ts +1 -1
  566. package/corpus/templates/mail/actions/update-automation.ts +1 -0
  567. package/corpus/templates/mail/actions/update-mail-preferences.ts +1 -0
  568. package/corpus/templates/mail/app/components/email/AiFilterDialog.tsx +127 -0
  569. package/corpus/templates/mail/app/components/email/EmailList.tsx +63 -0
  570. package/corpus/templates/mail/app/components/email/EmailThread.tsx +95 -0
  571. package/corpus/templates/mail/app/components/email/MobileActionBar.tsx +35 -3
  572. package/corpus/templates/mail/app/components/layout/AppLayout.tsx +17 -22
  573. package/corpus/templates/mail/app/components/settings/AiFilterSection.tsx +401 -0
  574. package/corpus/templates/mail/app/hooks/use-ai-filter.ts +48 -0
  575. package/corpus/templates/mail/app/hooks/use-automations.ts +1 -0
  576. package/corpus/templates/mail/app/hooks/use-emails.ts +11 -3
  577. package/corpus/templates/mail/app/i18n/en-US.ts +55 -0
  578. package/corpus/templates/mail/app/lib/automation-visibility.ts +17 -0
  579. package/corpus/templates/mail/app/pages/InboxPage.tsx +5 -2
  580. package/corpus/templates/mail/app/pages/SettingsPage.tsx +16 -8
  581. package/corpus/templates/mail/app/pages/inbox-zero.ts +1 -2
  582. package/corpus/templates/mail/app/root.tsx +20 -8
  583. package/corpus/templates/mail/app/routes/_index.tsx +16 -55
  584. package/corpus/templates/mail/app/routes/home.tsx +71 -0
  585. package/corpus/templates/mail/changelog/2026-08-28-mail-settings-show-chat-created-automations.md +6 -0
  586. package/corpus/templates/mail/public/manifest.json +1 -1
  587. package/corpus/templates/mail/server/db/schema.ts +3 -0
  588. package/corpus/templates/mail/server/handlers/emails.ts +34 -11
  589. package/corpus/templates/mail/server/handlers/google-auth.ts +1 -1
  590. package/corpus/templates/mail/server/lib/ai-filter.ts +103 -0
  591. package/corpus/templates/mail/server/lib/automation-actions.ts +14 -9
  592. package/corpus/templates/mail/server/lib/automation-engine.ts +142 -18
  593. package/corpus/templates/mail/server/lib/automations.ts +9 -0
  594. package/corpus/templates/mail/server/lib/email-state.ts +7 -2
  595. package/corpus/templates/mail/server/lib/gmail-query.ts +10 -0
  596. package/corpus/templates/mail/server/lib/google-auth.ts +5 -8
  597. package/corpus/templates/mail/server/lib/jobs.ts +1 -5
  598. package/corpus/templates/mail/server/onboarding.ts +2 -2
  599. package/corpus/templates/mail/server/plugins/agent-chat.ts +5 -2
  600. package/corpus/templates/mail/server/plugins/auth.ts +1 -0
  601. package/corpus/templates/mail/server/plugins/core-routes.ts +4 -1
  602. package/corpus/templates/mail/server/plugins/db.ts +6 -0
  603. package/corpus/templates/mail/server/routes/api/attachments.get.ts +1 -5
  604. package/corpus/templates/mail/shared/ai-filter.ts +74 -0
  605. package/corpus/templates/mail/shared/types.ts +2 -0
  606. package/corpus/templates/plan/.agents/skills/frontend-design/SKILL.md +4 -0
  607. package/corpus/templates/plan/.agents/skills/secrets/SKILL.md +47 -0
  608. package/corpus/templates/plan/actions/list-plan-versions.ts +20 -5
  609. package/corpus/templates/plan/agent-native.json +1 -4
  610. package/corpus/templates/plan/app/components/editor/PlanDocumentEditor.tsx +5 -2
  611. package/corpus/templates/plan/app/components/layout/Layout.tsx +41 -1
  612. package/corpus/templates/plan/app/components/layout/Sidebar.tsx +4 -16
  613. package/corpus/templates/plan/app/components/plan/PlanMarkdownEditor.tsx +7 -4
  614. package/corpus/templates/plan/app/components/plan/wireframe/Wireframe.tsx +1 -1
  615. package/corpus/templates/plan/app/components/plan/wireframe/html-artboard.css +15 -0
  616. package/corpus/templates/plan/app/components/plan/wireframe/kit/plan-wireframe-tokens.css +0 -15
  617. package/corpus/templates/plan/app/components/plan/wireframe/kit/primitives.tsx +2 -2
  618. package/corpus/templates/plan/app/hooks/use-plan-presence.ts +20 -10
  619. package/corpus/templates/plan/app/pages/PlansPage.tsx +2 -2
  620. package/corpus/templates/plan/app/root.tsx +13 -7
  621. package/corpus/templates/plan/app/routes/_index.tsx +31 -6
  622. package/corpus/templates/plan/app/routes/chat.tsx +3 -6
  623. package/corpus/templates/plan/app/routes/home.tsx +11 -0
  624. package/corpus/templates/plan/app/routes/local-plans.$slug.tsx +2 -6
  625. package/corpus/templates/plan/app/routes/plans.$id.tsx +3 -6
  626. package/corpus/templates/plan/app/routes/plans.tsx +3 -6
  627. package/corpus/templates/plan/app/routes/recaps.$id.tsx +3 -6
  628. package/corpus/templates/plan/app/routes/recaps.tsx +3 -6
  629. package/corpus/templates/plan/changelog/2026-08-28-plan-loading-skeletons-use-a-softer-whole-surface.md +6 -0
  630. package/corpus/templates/plan/changelog/2026-08-29-plan-loading-shine-is-more-subtle.md +6 -0
  631. package/corpus/templates/plan/public/manifest.json +1 -1
  632. package/corpus/templates/plan/server/db/schema.ts +1 -0
  633. package/corpus/templates/plan/server/lib/plan-versions.ts +57 -0
  634. package/corpus/templates/plan/server/plugins/agent-chat.ts +83 -0
  635. package/corpus/templates/plan/server/plugins/core-routes.ts +1 -0
  636. package/corpus/templates/plan/server/plugins/db.ts +10 -0
  637. package/corpus/templates/slides/.agents/skills/frontend-design/SKILL.md +4 -0
  638. package/corpus/templates/slides/.agents/skills/secrets/SKILL.md +47 -0
  639. package/corpus/templates/slides/CHANGELOG.md +9 -0
  640. package/corpus/templates/slides/actions/_deck-write.ts +65 -0
  641. package/corpus/templates/slides/actions/add-slide.ts +44 -24
  642. package/corpus/templates/slides/actions/clone-context-slide.ts +22 -12
  643. package/corpus/templates/slides/actions/create-deck.ts +36 -21
  644. package/corpus/templates/slides/actions/delete-design-system.ts +10 -3
  645. package/corpus/templates/slides/actions/import-file.ts +9 -3
  646. package/corpus/templates/slides/actions/import-pptx.ts +11 -4
  647. package/corpus/templates/slides/actions/list-deck-versions.ts +20 -8
  648. package/corpus/templates/slides/actions/patch-deck.ts +29 -3
  649. package/corpus/templates/slides/actions/restore-deck-version.ts +37 -22
  650. package/corpus/templates/slides/actions/save-deck.ts +35 -22
  651. package/corpus/templates/slides/actions/update-deck-aspect-ratio.ts +31 -16
  652. package/corpus/templates/slides/actions/update-slide.ts +250 -37
  653. package/corpus/templates/slides/app/components/deck/SlideRenderer.tsx +10 -4
  654. package/corpus/templates/slides/app/components/editor/EditorActionCluster.tsx +2 -2
  655. package/corpus/templates/slides/app/components/editor/EditorToolbar.tsx +7 -8
  656. package/corpus/templates/slides/app/components/editor/ImageOverlay.tsx +78 -12
  657. package/corpus/templates/slides/app/components/editor/SlideContextToolbar.tsx +42 -4
  658. package/corpus/templates/slides/app/components/editor/SlideEditor.tsx +381 -53
  659. package/corpus/templates/slides/app/components/editor/SlidesLayersPanel.tsx +20 -34
  660. package/corpus/templates/slides/app/components/editor/slide-style.ts +5 -0
  661. package/corpus/templates/slides/app/components/editor/style-clipboard.ts +2 -0
  662. package/corpus/templates/slides/app/components/layout/AgentWorkIndicator.tsx +18 -2
  663. package/corpus/templates/slides/app/components/layout/Header.tsx +1 -1
  664. package/corpus/templates/slides/app/components/layout/Layout.tsx +39 -10
  665. package/corpus/templates/slides/app/components/layout/Sidebar.tsx +7 -20
  666. package/corpus/templates/slides/app/components/presentation/PresenterView.tsx +35 -15
  667. package/corpus/templates/slides/app/components/presentation/present-channel.ts +12 -0
  668. package/corpus/templates/slides/app/global.css +45 -13
  669. package/corpus/templates/slides/app/hooks/use-navigation-state.ts +1 -1
  670. package/corpus/templates/slides/app/i18n/en-US.ts +11 -0
  671. package/corpus/templates/slides/app/lib/sanitize-slide-html.ts +133 -5
  672. package/corpus/templates/slides/app/lib/slide-image-replacement.ts +741 -17
  673. package/corpus/templates/slides/app/lib/validate-native-slide-html.ts +1 -0
  674. package/corpus/templates/slides/app/pages/DeckEditor.tsx +288 -95
  675. package/corpus/templates/slides/app/pages/DesignSystems.tsx +5 -5
  676. package/corpus/templates/slides/app/pages/Index.tsx +7 -7
  677. package/corpus/templates/slides/app/pages/NotFound.tsx +1 -1
  678. package/corpus/templates/slides/app/pages/SharedPresentation.tsx +1 -1
  679. package/corpus/templates/slides/app/root.tsx +4 -23
  680. package/corpus/templates/slides/app/routes/_index.tsx +18 -7
  681. package/corpus/templates/slides/app/routes/home.tsx +26 -0
  682. package/corpus/templates/slides/changelog/2026-08-27-image-fit-controls-apply-cover-crops-and-position.md +6 -0
  683. package/corpus/templates/slides/changelog/2026-08-28-image-edits-persist-while-dropped-images-finish-uploading.md +6 -0
  684. package/corpus/templates/slides/changelog/2026-08-28-shared-slides-with-a-style-block-render-again.md +6 -0
  685. package/corpus/templates/slides/changelog/2026-08-28-slides-loading-skeletons-use-a-softer-whole-surface.md +6 -0
  686. package/corpus/templates/slides/changelog/2026-08-28-standard-empty-home-layout.md +6 -0
  687. package/corpus/templates/slides/changelog/2026-08-29-chat-imports-attached-decks-on-request.md +6 -0
  688. package/corpus/templates/slides/changelog/2026-08-29-slides-loading-shine-is-more-subtle.md +6 -0
  689. package/corpus/templates/slides/package.json +3 -0
  690. package/corpus/templates/slides/public/manifest.json +1 -1
  691. package/corpus/templates/slides/server/db/schema.ts +1 -0
  692. package/corpus/templates/slides/server/handlers/google-docs-auth.ts +1 -1
  693. package/corpus/templates/slides/server/lib/chat-attachments.ts +102 -7
  694. package/corpus/templates/slides/server/lib/deck-versions.ts +77 -2
  695. package/corpus/templates/slides/server/plugins/agent-chat.ts +95 -1
  696. package/corpus/templates/slides/server/plugins/auth.ts +1 -0
  697. package/corpus/templates/slides/server/plugins/core-routes.ts +8 -1
  698. package/corpus/templates/slides/server/plugins/db.ts +5 -0
  699. package/corpus/templates/tasks/.agents/skills/frontend-design/SKILL.md +4 -0
  700. package/corpus/templates/tasks/.agents/skills/secrets/SKILL.md +47 -0
  701. package/corpus/templates/tasks/AGENTS.md +2 -1
  702. package/corpus/templates/tasks/README.md +3 -1
  703. package/corpus/templates/tasks/app/components/layout/Sidebar.tsx +5 -18
  704. package/corpus/templates/tasks/app/root.tsx +19 -3
  705. package/corpus/templates/tasks/app/routes/_index.tsx +28 -14
  706. package/corpus/templates/tasks/app/routes/home.tsx +24 -0
  707. package/corpus/templates/tasks/public/manifest.json +1 -1
  708. package/corpus/templates/tasks/server/plugins/auth.ts +1 -0
  709. package/dist/a2a/client.d.ts +4 -0
  710. package/dist/a2a/client.js +15 -2
  711. package/dist/action.d.ts +3 -1
  712. package/dist/agent/engine/ai-sdk-engine.js +13 -9
  713. package/dist/agent/engine/anthropic-engine.js +2 -1
  714. package/dist/agent/engine/builder-engine.js +23 -5
  715. package/dist/agent/engine/limit-provider-tools.d.ts +3 -0
  716. package/dist/agent/engine/limit-provider-tools.js +23 -0
  717. package/dist/agent/engine/openai-compatible-endpoint.d.ts +2 -0
  718. package/dist/agent/engine/openai-compatible-endpoint.js +4 -0
  719. package/dist/agent/engine/output-tokens.d.ts +12 -6
  720. package/dist/agent/engine/output-tokens.js +42 -16
  721. package/dist/agent/engine/registry.d.ts +1 -1
  722. package/dist/agent/engine/registry.js +69 -16
  723. package/dist/agent/production-agent.js +107 -13
  724. package/dist/agent/run-manager.d.ts +9 -0
  725. package/dist/agent/run-manager.js +35 -6
  726. package/dist/agent/thread-data-builder.d.ts +6 -1
  727. package/dist/agent/thread-data-builder.js +20 -5
  728. package/dist/agent/types.d.ts +2 -0
  729. package/dist/app-config/agent.d.ts +4 -0
  730. package/dist/app-config/agent.js +44 -0
  731. package/dist/app-config/integrations.d.ts +1 -0
  732. package/dist/app-config/integrations.js +8 -0
  733. package/dist/app-config/migration.d.ts +1 -0
  734. package/dist/app-config/migration.js +4 -0
  735. package/dist/app-config/observability.d.ts +4 -1
  736. package/dist/app-config/observability.js +25 -1
  737. package/dist/app-config/schema.d.ts +9 -0
  738. package/dist/app-config/store.js +1 -0
  739. package/dist/client/AgentAskPopover.d.ts +2 -1
  740. package/dist/client/AgentAskPopover.js +2 -2
  741. package/dist/client/AgentPanel.d.ts +35 -10
  742. package/dist/client/AgentPanel.js +136 -119
  743. package/dist/client/AssistantChat.d.ts +9 -2
  744. package/dist/client/AssistantChat.js +161 -36
  745. package/dist/client/ConnectBuilderCard.js +3 -1
  746. package/dist/client/DefaultSpinner.d.ts +13 -1
  747. package/dist/client/DefaultSpinner.js +52 -46
  748. package/dist/client/FeedbackButton.d.ts +12 -0
  749. package/dist/client/FeedbackButton.js +62 -28
  750. package/dist/client/MultiTabAssistantChat.js +30 -11
  751. package/dist/client/NewWorkspaceAppFlow.js +5 -3
  752. package/dist/client/agent-chat/index.d.ts +1 -0
  753. package/dist/client/agent-chat/index.js +1 -0
  754. package/dist/client/agent-chat-adapter.js +16 -1
  755. package/dist/client/agent-chat.d.ts +9 -0
  756. package/dist/client/agent-chat.js +6 -3
  757. package/dist/client/agent-page/AgentJobsTab.d.ts +2 -1
  758. package/dist/client/agent-page/AgentJobsTab.js +8 -5
  759. package/dist/client/agent-page/AgentTabsPage.js +2 -2
  760. package/dist/client/analytics.d.ts +2 -0
  761. package/dist/client/analytics.js +86 -15
  762. package/dist/client/app-providers.js +13 -1
  763. package/dist/client/auth/AuthPage.d.ts +87 -0
  764. package/dist/client/auth/AuthPage.js +1847 -0
  765. package/dist/client/auth/ResetPasswordPage.d.ts +9 -0
  766. package/dist/client/auth/ResetPasswordPage.js +119 -0
  767. package/dist/client/auth/entry.d.ts +1 -0
  768. package/dist/client/auth/entry.js +15 -0
  769. package/dist/client/chat/message-components.d.ts +53 -0
  770. package/dist/client/chat/message-components.js +181 -11
  771. package/dist/client/chat/run-recovery.d.ts +4 -1
  772. package/dist/client/chat/run-recovery.js +30 -12
  773. package/dist/client/chat/tool-call-display.d.ts +4 -2
  774. package/dist/client/chat/tool-call-display.js +16 -11
  775. package/dist/client/chat-first.js +8 -2
  776. package/dist/client/chat-model-groups.js +11 -1
  777. package/dist/client/collab/index.d.ts +1 -1
  778. package/dist/client/components/CodeRequiredDialog.js +22 -35
  779. package/dist/client/components/icons/AgentNativeIcon.d.ts +3 -3
  780. package/dist/client/components/icons/AgentNativeIcon.js +4 -4
  781. package/dist/client/components/ui/message-scroller.js +1 -1
  782. package/dist/client/composer/runtime-adapters.js +2 -0
  783. package/dist/client/feedback-context.d.ts +1 -0
  784. package/dist/client/feedback-context.js +3 -2
  785. package/dist/client/host-bridge.d.ts +1 -0
  786. package/dist/client/index.d.ts +2 -2
  787. package/dist/client/index.js +1 -1
  788. package/dist/client/integrations/IntegrationsPanel.d.ts +2 -1
  789. package/dist/client/integrations/IntegrationsPanel.js +3 -3
  790. package/dist/client/observability/ThumbsFeedback.js +73 -10
  791. package/dist/client/onboarding/FirstRunOnboarding.js +24 -15
  792. package/dist/client/onboarding/OnboardingPanel.js +5 -3
  793. package/dist/client/onboarding/first-run-startup-gate.js +7 -1
  794. package/dist/client/resources/McpIntegrationDialog.d.ts +2 -1
  795. package/dist/client/resources/McpIntegrationDialog.js +10 -2
  796. package/dist/client/session-replay.js +10 -0
  797. package/dist/client/settings/BuilderConnectPopover.d.ts +25 -0
  798. package/dist/client/settings/BuilderConnectPopover.js +55 -0
  799. package/dist/client/settings/SettingsPanel.js +21 -7
  800. package/dist/client/settings/SettingsTabsPage.d.ts +1 -1
  801. package/dist/client/settings/SettingsTabsPage.js +42 -25
  802. package/dist/client/settings/VoiceTranscriptionSection.js +16 -22
  803. package/dist/client/settings/index.d.ts +1 -0
  804. package/dist/client/settings/index.js +1 -0
  805. package/dist/client/settings/useBuilderStatus.d.ts +7 -0
  806. package/dist/client/settings/useBuilderStatus.js +77 -21
  807. package/dist/client/setup-connections/BuilderConnectCard.js +2 -1
  808. package/dist/client/setup-connections/useBuilderConnectCardController.d.ts +3 -1
  809. package/dist/client/setup-connections/useBuilderConnectCardController.js +4 -2
  810. package/dist/client/sse-event-processor.js +8 -0
  811. package/dist/client/terminal/AgentTerminal.js +6 -7
  812. package/dist/client/transcription/BuilderTranscriptionCta.js +17 -69
  813. package/dist/client/ui/index.d.ts +1 -0
  814. package/dist/client/ui/index.js +1 -0
  815. package/dist/client/use-chat-models.js +5 -4
  816. package/dist/client/webmcp.d.ts +4 -0
  817. package/dist/client/webmcp.js +51 -4
  818. package/dist/collab/client.d.ts +13 -0
  819. package/dist/collab/client.js +96 -21
  820. package/dist/dashboard-storage/index.d.ts +1 -1
  821. package/dist/dashboard-storage/schema.d.ts +19 -0
  822. package/dist/dashboard-storage/schema.js +1 -0
  823. package/dist/dashboard-storage/store.d.ts +9 -0
  824. package/dist/dashboard-storage/store.js +93 -3
  825. package/dist/deploy/build.d.ts +19 -3
  826. package/dist/deploy/build.js +262 -10
  827. package/dist/index.browser.d.ts +1 -1
  828. package/dist/index.browser.js +1 -1
  829. package/dist/index.d.ts +1 -1
  830. package/dist/index.js +1 -1
  831. package/dist/ingestion/media.js +7 -2
  832. package/dist/integrations/config-store.js +2 -4
  833. package/dist/integrations/google-docs-poller.d.ts +1 -1
  834. package/dist/integrations/google-docs-poller.js +100 -24
  835. package/dist/integrations/plugin.js +45 -15
  836. package/dist/integrations/webhook-handler.js +2 -1
  837. package/dist/jobs/background-automation-runner.js +17 -1
  838. package/dist/localization/core-messages/ar-SA.js +19 -0
  839. package/dist/localization/core-messages/de-DE.js +19 -0
  840. package/dist/localization/core-messages/en-US.d.ts +19 -0
  841. package/dist/localization/core-messages/en-US.js +19 -0
  842. package/dist/localization/core-messages/es-ES.js +19 -0
  843. package/dist/localization/core-messages/fr-FR.js +19 -0
  844. package/dist/localization/core-messages/hi-IN.js +19 -0
  845. package/dist/localization/core-messages/ja-JP.js +19 -0
  846. package/dist/localization/core-messages/ko-KR.js +19 -0
  847. package/dist/localization/core-messages/pt-BR.js +19 -0
  848. package/dist/localization/core-messages/zh-CN.js +19 -0
  849. package/dist/localization/core-messages/zh-TW.js +19 -0
  850. package/dist/localization/core-messages.d.ts +19 -0
  851. package/dist/localization/default-messages.d.ts +11 -0
  852. package/dist/localization/default-messages.js +11 -0
  853. package/dist/mcp/analytics.d.ts +103 -0
  854. package/dist/mcp/analytics.js +204 -0
  855. package/dist/mcp/build-server.d.ts +7 -0
  856. package/dist/mcp/build-server.js +132 -35
  857. package/dist/mcp/screen-memory-stdio.d.ts +7 -7
  858. package/dist/mcp/server.js +37 -8
  859. package/dist/mcp/stdio.js +1 -0
  860. package/dist/mcp-client/errors.js +30 -10
  861. package/dist/mcp-client/oauth-routes.d.ts +7 -2
  862. package/dist/mcp-client/oauth-routes.js +12 -3
  863. package/dist/mcp-client/routes.js +2 -1
  864. package/dist/oauth-tokens/store.js +6 -3
  865. package/dist/observability/routes.d.ts +5 -5
  866. package/dist/observability/routes.js +8 -2
  867. package/dist/observability/store.d.ts +1 -1
  868. package/dist/observability/store.js +18 -3
  869. package/dist/observability/types.d.ts +1 -0
  870. package/dist/onboarding/plugin.js +16 -4
  871. package/dist/progress/routes.d.ts +1 -1
  872. package/dist/provider-api/actions/custom-provider-registration.d.ts +16 -16
  873. package/dist/provider-api/actions/provider-api.d.ts +12 -12
  874. package/dist/resources/handlers.d.ts +2 -2
  875. package/dist/secrets/routes.d.ts +9 -9
  876. package/dist/server/action-routes.d.ts +1 -6
  877. package/dist/server/action-routes.js +61 -18
  878. package/dist/server/agent-chat/plugin-options.d.ts +8 -1
  879. package/dist/server/agent-chat-plugin.d.ts +3 -0
  880. package/dist/server/agent-chat-plugin.js +49 -4
  881. package/dist/server/agent-engine-api-key-route.d.ts +1 -1
  882. package/dist/server/agent-run-context.d.ts +1 -0
  883. package/dist/server/agent-run-context.js +6 -0
  884. package/dist/server/analytics.d.ts +3 -2
  885. package/dist/server/analytics.js +18 -7
  886. package/dist/server/app-url.d.ts +5 -2
  887. package/dist/server/app-url.js +4 -3
  888. package/dist/server/auth.d.ts +25 -0
  889. package/dist/server/auth.js +168 -21
  890. package/dist/server/better-auth-instance.js +18 -4
  891. package/dist/server/better-auth-migrations.d.ts +14 -0
  892. package/dist/server/better-auth-migrations.js +5 -1
  893. package/dist/server/builder-api-auth.js +30 -6
  894. package/dist/server/builder-browser.d.ts +10 -0
  895. package/dist/server/builder-browser.js +22 -5
  896. package/dist/server/builder-design-systems.d.ts +11 -0
  897. package/dist/server/builder-design-systems.js +52 -3
  898. package/dist/server/builder-oauth.d.ts +13 -6
  899. package/dist/server/builder-oauth.js +121 -63
  900. package/dist/server/capture-error.js +3 -0
  901. package/dist/server/cookie-namespace.d.ts +1 -0
  902. package/dist/server/cookie-namespace.js +3 -0
  903. package/dist/server/core-routes-plugin.d.ts +25 -9
  904. package/dist/server/core-routes-plugin.js +180 -76
  905. package/dist/server/credential-provider.js +22 -12
  906. package/dist/server/email.d.ts +4 -0
  907. package/dist/server/email.js +13 -5
  908. package/dist/server/framework-request-handler.js +6 -3
  909. package/dist/server/google-credential-check.d.ts +7 -3
  910. package/dist/server/google-credential-check.js +71 -0
  911. package/dist/server/google-oauth-credentials.d.ts +4 -3
  912. package/dist/server/google-oauth-credentials.js +7 -8
  913. package/dist/server/google-oauth.d.ts +9 -4
  914. package/dist/server/google-oauth.js +14 -93
  915. package/dist/server/index.d.ts +1 -1
  916. package/dist/server/index.js +1 -1
  917. package/dist/server/jwks-secret-rotation.d.ts +29 -0
  918. package/dist/server/jwks-secret-rotation.js +150 -0
  919. package/dist/server/onboarding-html.d.ts +2 -14
  920. package/dist/server/onboarding-html.js +254 -2519
  921. package/dist/server/origin-allowlist.d.ts +15 -0
  922. package/dist/server/origin-allowlist.js +93 -0
  923. package/dist/server/release-migrations.js +48 -0
  924. package/dist/server/request-context.d.ts +2 -0
  925. package/dist/server/request-context.js +7 -2
  926. package/dist/server/self-dispatch.js +5 -0
  927. package/dist/server/sentry.js +5 -0
  928. package/dist/server/ssr-handler.js +5 -0
  929. package/dist/server/transcribe-voice.d.ts +1 -1
  930. package/dist/server/workspace-provider-oauth.d.ts +9 -0
  931. package/dist/server/workspace-provider-oauth.js +96 -31
  932. package/dist/shared/index.d.ts +2 -0
  933. package/dist/shared/index.js +2 -0
  934. package/dist/shared/loading-labels.d.ts +1 -0
  935. package/dist/shared/loading-labels.js +55 -0
  936. package/dist/shared/qa-test-email.d.ts +1 -0
  937. package/dist/shared/qa-test-email.js +42 -0
  938. package/dist/shared/route-warmup-config.js +2 -2
  939. package/dist/shared/sign-in-journey.js +1 -1
  940. package/dist/shared/ssr-auth-redirect.d.ts +8 -0
  941. package/dist/shared/ssr-auth-redirect.js +56 -0
  942. package/dist/shared/test-traffic.d.ts +8 -0
  943. package/dist/shared/test-traffic.js +11 -0
  944. package/dist/styles/agent-native.css +50 -14
  945. package/dist/styles/blocks.css +0 -6
  946. package/dist/templates/chat/.agents/skills/frontend-design/SKILL.md +4 -0
  947. package/dist/templates/chat/.agents/skills/secrets/SKILL.md +47 -0
  948. package/dist/templates/chat/AGENTS.md +5 -4
  949. package/dist/templates/chat/app/components/layout/Header.tsx +1 -1
  950. package/dist/templates/chat/app/components/layout/Layout.tsx +5 -4
  951. package/dist/templates/chat/app/components/layout/Sidebar.tsx +16 -25
  952. package/dist/templates/chat/app/hooks/use-navigation-state.ts +5 -5
  953. package/dist/templates/chat/app/root.tsx +16 -3
  954. package/dist/templates/chat/app/routes/_index.tsx +17 -74
  955. package/dist/templates/chat/app/routes/chat.$threadId.tsx +1 -1
  956. package/dist/templates/chat/app/routes/home.tsx +94 -0
  957. package/dist/templates/chat/netlify.toml +2 -1
  958. package/dist/templates/chat/public/manifest.json +1 -1
  959. package/dist/templates/chat/server/plugins/auth.ts +1 -0
  960. package/dist/templates/default/.agents/skills/frontend-design/SKILL.md +4 -0
  961. package/dist/templates/default/.agents/skills/secrets/SKILL.md +47 -0
  962. package/dist/templates/default/AGENTS.md +10 -6
  963. package/dist/templates/default/DEVELOPING.md +8 -1
  964. package/dist/templates/default/app/hooks/use-navigation-state.ts +1 -1
  965. package/dist/templates/default/app/root.tsx +10 -3
  966. package/dist/templates/default/app/routes/_index.tsx +10 -86
  967. package/dist/templates/default/app/routes/home.tsx +94 -0
  968. package/dist/templates/default/app/routes/settings.tsx +1 -1
  969. package/dist/templates/default/public/manifest.json +1 -1
  970. package/dist/templates/default/server/plugins/auth.ts +5 -0
  971. package/dist/templates/headless/.agents/skills/secrets/SKILL.md +47 -0
  972. package/dist/templates/workspace-core/.agents/skills/frontend-design/SKILL.md +4 -0
  973. package/dist/templates/workspace-core/.agents/skills/secrets/SKILL.md +47 -0
  974. package/dist/templates/workspace-root/.env.example +3 -2
  975. package/dist/terminal/pty-server.d.ts +2 -0
  976. package/dist/terminal/pty-server.js +22 -5
  977. package/dist/tracking/registry.d.ts +1 -0
  978. package/dist/tracking/registry.js +12 -0
  979. package/dist/usage/store.d.ts +1 -0
  980. package/dist/usage/store.js +16 -7
  981. package/dist/vite/client.d.ts +1 -1
  982. package/dist/vite/client.js +59 -0
  983. package/dist/workspace-connections/index.d.ts +1 -1
  984. package/dist/workspace-connections/index.js +1 -1
  985. package/dist/workspace-connections/store.d.ts +1 -0
  986. package/dist/workspace-connections/store.js +4 -0
  987. package/docs/content/aws-amplify.mdx +179 -0
  988. package/docs/content/client-agent-chat.mdx +1 -1
  989. package/docs/content/deploy-an-app.mdx +2 -1
  990. package/docs/content/deployment.mdx +14 -3
  991. package/docs/content/environment-variables.mdx +1 -0
  992. package/docs/content/template-forms-agent.mdx +65 -0
  993. package/docs/content/template-forms-developers.mdx +220 -65
  994. package/docs/content/template-forms-features.mdx +154 -0
  995. package/docs/content/template-forms-integrations.mdx +40 -0
  996. package/docs/content/template-forms.mdx +49 -36
  997. package/docs/content/template-mail-developers.mdx +3 -3
  998. package/docs/content/toolkit-settings.mdx +3 -3
  999. package/docs/content/webmcp.mdx +31 -12
  1000. package/package.json +3 -3
  1001. package/src/templates/chat/.agents/skills/frontend-design/SKILL.md +4 -0
  1002. package/src/templates/chat/.agents/skills/secrets/SKILL.md +47 -0
  1003. package/src/templates/chat/AGENTS.md +5 -4
  1004. package/src/templates/chat/app/components/layout/Header.tsx +1 -1
  1005. package/src/templates/chat/app/components/layout/Layout.tsx +5 -4
  1006. package/src/templates/chat/app/components/layout/Sidebar.tsx +16 -25
  1007. package/src/templates/chat/app/hooks/use-navigation-state.ts +5 -5
  1008. package/src/templates/chat/app/root.tsx +16 -3
  1009. package/src/templates/chat/app/routes/_index.tsx +17 -74
  1010. package/src/templates/chat/app/routes/chat.$threadId.tsx +1 -1
  1011. package/src/templates/chat/app/routes/home.tsx +94 -0
  1012. package/src/templates/chat/netlify.toml +2 -1
  1013. package/src/templates/chat/public/manifest.json +1 -1
  1014. package/src/templates/chat/server/plugins/auth.ts +1 -0
  1015. package/src/templates/default/.agents/skills/frontend-design/SKILL.md +4 -0
  1016. package/src/templates/default/.agents/skills/secrets/SKILL.md +47 -0
  1017. package/src/templates/default/AGENTS.md +10 -6
  1018. package/src/templates/default/DEVELOPING.md +8 -1
  1019. package/src/templates/default/app/hooks/use-navigation-state.ts +1 -1
  1020. package/src/templates/default/app/root.tsx +10 -3
  1021. package/src/templates/default/app/routes/_index.tsx +10 -86
  1022. package/src/templates/default/app/routes/home.tsx +94 -0
  1023. package/src/templates/default/app/routes/settings.tsx +1 -1
  1024. package/src/templates/default/public/manifest.json +1 -1
  1025. package/src/templates/default/server/plugins/auth.ts +5 -0
  1026. package/src/templates/headless/.agents/skills/secrets/SKILL.md +47 -0
  1027. package/src/templates/workspace-core/.agents/skills/frontend-design/SKILL.md +4 -0
  1028. package/src/templates/workspace-core/.agents/skills/secrets/SKILL.md +47 -0
  1029. package/src/templates/workspace-root/.env.example +3 -2
  1030. package/corpus/templates/factory/actions/approve-factory-item.ts +0 -244
  1031. package/corpus/templates/factory/app/components/factory/FactorySourceSettingsGroup.tsx +0 -33
  1032. package/corpus/templates/factory/server/routes/_agent-native/factory/builder-callback.post.ts +0 -116
  1033. package/corpus/templates/factory/server/triage/ai-services-git.ts +0 -205
  1034. package/corpus/templates/factory/server/triage/builder-executor.ts +0 -123
  1035. package/docs/content/template-forms-building-publishing.mdx +0 -135
  1036. package/docs/content/template-forms-responses.mdx +0 -120
  1037. /package/corpus/templates/clips/{server/lib → shared}/upload-interruption.ts +0 -0
@@ -5,7 +5,7 @@ import {
5
5
  verifyCaptcha,
6
6
  } from "@agent-native/core/server";
7
7
  import { assertAccess } from "@agent-native/core/sharing";
8
- import { and, eq, desc, isNull, sql } from "drizzle-orm";
8
+ import { and, desc, eq, isNull, lt, or, sql } from "drizzle-orm";
9
9
  import {
10
10
  defineEventHandler,
11
11
  getRouterParam,
@@ -28,13 +28,20 @@ import {
28
28
  } from "../../shared/submitter-email.js";
29
29
  import type {
30
30
  FormField,
31
- FormIntegration,
32
31
  FormResponse,
33
32
  FormSettings,
34
33
  } from "../../shared/types.js";
35
34
  import { getDb, schema } from "../db/index.js";
36
- import { fireIntegrations } from "../lib/integrations.js";
37
- import { sendNewResponseEmail } from "../lib/response-email.js";
35
+ import {
36
+ buildIntegrationDeliverySnapshots,
37
+ deliverIntegrationDelivery,
38
+ fireIntegrations,
39
+ type IntegrationDeliverySnapshot,
40
+ } from "../lib/integrations.js";
41
+ import {
42
+ sendNewResponseEmail,
43
+ type NewResponseEmailArgs,
44
+ } from "../lib/response-email.js";
38
45
  import {
39
46
  isEmptySubmissionValue,
40
47
  validateSubmissionField,
@@ -44,6 +51,75 @@ const MAX_PAYLOAD_BYTES = 100 * 1024; // 100KB
44
51
  const MIN_FILL_TIME_MS = 500; // reject submits faster than this
45
52
  const MAX_META_TEXT_LENGTH = 500;
46
53
  const MAX_CHAT_SESSION_IDS = 5;
54
+ const MAX_IDEMPOTENCY_KEY_LENGTH = 200;
55
+ const APPLICATION_STATE_DESTINATION = "application-state";
56
+ const RESPONSE_EMAIL_DESTINATION = "email";
57
+ const DELIVERY_CLAIM_LEASE_MS = 60_000;
58
+ const DELIVERY_CLAIM_HEARTBEAT_MS = Math.floor(DELIVERY_CLAIM_LEASE_MS / 3);
59
+
60
+ type ResponseDeliveryStatus = "pending" | "processing" | "succeeded" | "failed";
61
+
62
+ interface DeliverySnapshot {
63
+ formId: string;
64
+ formTitle: string;
65
+ ownerEmail: string | null;
66
+ orgId: string | null;
67
+ fields: FormField[];
68
+ data: Record<string, unknown>;
69
+ submittedAt: string;
70
+ submitterEmail: string | null;
71
+ chatSessionIds: string[];
72
+ activeRunId: string | null;
73
+ pageUrl: string | null;
74
+ clientSurface: string | null;
75
+ emailOnNewResponses: boolean;
76
+ integrations: IntegrationDeliverySnapshot[];
77
+ }
78
+
79
+ type StoredDeliveryPayload =
80
+ | {
81
+ kind: "application-state";
82
+ ownerEmail: string;
83
+ value: { formId: string; responseId: string; timestamp: string };
84
+ }
85
+ | { kind: "email"; args: NewResponseEmailArgs; orgId: string | null }
86
+ | { kind: "integration"; snapshot: IntegrationDeliverySnapshot };
87
+
88
+ function configuredDeliveryStatuses(snapshot: DeliverySnapshot) {
89
+ const statuses: Record<string, "pending"> = {};
90
+ if (snapshot.ownerEmail) statuses[APPLICATION_STATE_DESTINATION] = "pending";
91
+ if (snapshot.emailOnNewResponses && snapshot.ownerEmail) {
92
+ statuses[RESPONSE_EMAIL_DESTINATION] = "pending";
93
+ }
94
+ for (const integration of snapshot.integrations) {
95
+ statuses[`integration:${integration.id}`] = "pending";
96
+ }
97
+ return statuses;
98
+ }
99
+
100
+ function submissionMetadata(body: Record<string, unknown>, anonymous: boolean) {
101
+ const meta =
102
+ !anonymous && typeof body._meta === "object" && body._meta !== null
103
+ ? (body._meta as {
104
+ chatSessionId?: unknown;
105
+ chatSessionIds?: unknown;
106
+ activeRunId?: unknown;
107
+ pageUrl?: unknown;
108
+ clientSurface?: unknown;
109
+ submitterEmail?: unknown;
110
+ })
111
+ : null;
112
+ return {
113
+ submitterEmail: cleanSubmitterEmail(meta?.submitterEmail),
114
+ chatSessionIds: cleanChatSessionIds([
115
+ meta?.chatSessionId,
116
+ meta?.chatSessionIds,
117
+ ]),
118
+ activeRunId: cleanMetaText(meta?.activeRunId),
119
+ pageUrl: scrubPageUrl(meta?.pageUrl),
120
+ clientSurface: cleanClientSurface(meta?.clientSurface),
121
+ };
122
+ }
47
123
 
48
124
  function cleanMetaText(value: unknown): string | null {
49
125
  if (typeof value !== "string") return null;
@@ -77,10 +153,775 @@ function cleanChatSessionIds(value: unknown): string[] {
77
153
  return ids;
78
154
  }
79
155
 
156
+ function isObjectRecord(value: unknown): value is Record<string, unknown> {
157
+ return typeof value === "object" && value !== null && !Array.isArray(value);
158
+ }
159
+
160
+ function parseIntegrationSnapshot(value: unknown): IntegrationDeliverySnapshot {
161
+ if (
162
+ !isObjectRecord(value) ||
163
+ typeof value.id !== "string" ||
164
+ typeof value.type !== "string" ||
165
+ typeof value.name !== "string" ||
166
+ typeof value.url !== "string" ||
167
+ !("payload" in value)
168
+ ) {
169
+ throw new Error("Invalid response integration delivery snapshot");
170
+ }
171
+ return {
172
+ id: value.id,
173
+ type: value.type as IntegrationDeliverySnapshot["type"],
174
+ name: value.name,
175
+ url: value.url,
176
+ payload: value.payload,
177
+ };
178
+ }
179
+
180
+ function parseDeliverySnapshot(
181
+ value: string | null | undefined,
182
+ ): DeliverySnapshot | null {
183
+ if (!value) return null;
184
+ let parsed: unknown;
185
+ try {
186
+ parsed = JSON.parse(value);
187
+ } catch {
188
+ throw new Error("Unreadable response delivery snapshot");
189
+ }
190
+ if (
191
+ !isObjectRecord(parsed) ||
192
+ typeof parsed.formId !== "string" ||
193
+ typeof parsed.formTitle !== "string" ||
194
+ (parsed.ownerEmail !== null && typeof parsed.ownerEmail !== "string") ||
195
+ (parsed.orgId !== null && typeof parsed.orgId !== "string") ||
196
+ !Array.isArray(parsed.fields) ||
197
+ !isObjectRecord(parsed.data) ||
198
+ typeof parsed.submittedAt !== "string" ||
199
+ (parsed.submitterEmail !== null &&
200
+ typeof parsed.submitterEmail !== "string") ||
201
+ !Array.isArray(parsed.chatSessionIds) ||
202
+ !parsed.chatSessionIds.every((id) => typeof id === "string") ||
203
+ (parsed.activeRunId !== null && typeof parsed.activeRunId !== "string") ||
204
+ (parsed.pageUrl !== null && typeof parsed.pageUrl !== "string") ||
205
+ (parsed.clientSurface !== null &&
206
+ typeof parsed.clientSurface !== "string") ||
207
+ typeof parsed.emailOnNewResponses !== "boolean" ||
208
+ !Array.isArray(parsed.integrations)
209
+ ) {
210
+ throw new Error("Invalid response delivery snapshot");
211
+ }
212
+ return {
213
+ formId: parsed.formId,
214
+ formTitle: parsed.formTitle,
215
+ ownerEmail: parsed.ownerEmail,
216
+ orgId: parsed.orgId,
217
+ fields: parsed.fields as FormField[],
218
+ data: parsed.data,
219
+ submittedAt: parsed.submittedAt,
220
+ submitterEmail: parsed.submitterEmail,
221
+ chatSessionIds: parsed.chatSessionIds,
222
+ activeRunId: parsed.activeRunId,
223
+ pageUrl: parsed.pageUrl,
224
+ clientSurface: parsed.clientSurface,
225
+ emailOnNewResponses: parsed.emailOnNewResponses,
226
+ integrations: parsed.integrations.map(parseIntegrationSnapshot),
227
+ };
228
+ }
229
+
230
+ function buildDeliverySnapshot({
231
+ form,
232
+ settings,
233
+ fields,
234
+ data,
235
+ responseId,
236
+ submittedAt,
237
+ submitterEmail,
238
+ pageUrl,
239
+ clientSurface,
240
+ chatSessionIds,
241
+ activeRunId,
242
+ }: {
243
+ form: typeof schema.forms.$inferSelect;
244
+ settings: FormSettings;
245
+ fields: FormField[];
246
+ data: Record<string, unknown>;
247
+ responseId: string;
248
+ submittedAt: string;
249
+ submitterEmail: string | null;
250
+ pageUrl: string | null;
251
+ clientSurface: string | null;
252
+ chatSessionIds: string[];
253
+ activeRunId: string | null;
254
+ }): DeliverySnapshot {
255
+ const submission = {
256
+ formId: form.id,
257
+ formTitle: form.title,
258
+ responseId,
259
+ fields,
260
+ data,
261
+ submittedAt,
262
+ submitterEmail,
263
+ chatSessionIds,
264
+ activeRunId,
265
+ pageUrl,
266
+ clientSurface,
267
+ };
268
+ return {
269
+ formId: form.id,
270
+ formTitle: form.title,
271
+ ownerEmail: form.ownerEmail ?? null,
272
+ orgId: form.orgId ?? null,
273
+ fields,
274
+ data,
275
+ submittedAt,
276
+ submitterEmail,
277
+ chatSessionIds,
278
+ activeRunId,
279
+ pageUrl,
280
+ clientSurface,
281
+ emailOnNewResponses: settings.emailOnNewResponses === true,
282
+ integrations: buildIntegrationDeliverySnapshots(
283
+ settings.integrations ?? [],
284
+ submission,
285
+ ),
286
+ };
287
+ }
288
+
289
+ function buildResponseDeliveryRows(
290
+ snapshot: DeliverySnapshot,
291
+ responseId: string,
292
+ ) {
293
+ const createdAt = new Date().toISOString();
294
+ const rows: Array<typeof schema.responseDeliveries.$inferInsert> = [];
295
+ const add = (
296
+ destination: string,
297
+ kind: "application-state" | "email" | "integration",
298
+ payload: StoredDeliveryPayload,
299
+ ) => {
300
+ rows.push({
301
+ id: nanoid(),
302
+ responseId,
303
+ destination,
304
+ kind,
305
+ payload: JSON.stringify(payload),
306
+ status: "pending",
307
+ claimToken: null,
308
+ claimedAt: null,
309
+ errorMessage: null,
310
+ createdAt,
311
+ updatedAt: createdAt,
312
+ });
313
+ };
314
+
315
+ if (snapshot.ownerEmail) {
316
+ add(APPLICATION_STATE_DESTINATION, "application-state", {
317
+ kind: "application-state",
318
+ ownerEmail: snapshot.ownerEmail,
319
+ value: {
320
+ formId: snapshot.formId,
321
+ responseId,
322
+ timestamp: snapshot.submittedAt,
323
+ },
324
+ });
325
+ }
326
+ if (snapshot.emailOnNewResponses && snapshot.ownerEmail) {
327
+ add(RESPONSE_EMAIL_DESTINATION, "email", {
328
+ kind: "email",
329
+ orgId: snapshot.orgId,
330
+ args: {
331
+ to: snapshot.ownerEmail,
332
+ formTitle: snapshot.formTitle,
333
+ fields: snapshot.fields,
334
+ data: snapshot.data,
335
+ submittedAt: snapshot.submittedAt,
336
+ },
337
+ });
338
+ }
339
+ for (const integration of snapshot.integrations) {
340
+ add(`integration:${integration.id}`, "integration", {
341
+ kind: "integration",
342
+ snapshot: integration,
343
+ });
344
+ }
345
+ return rows;
346
+ }
347
+
348
+ async function ensureResponseDeliveryRows(
349
+ db: ReturnType<typeof getDb>,
350
+ responseId: string,
351
+ snapshot: DeliverySnapshot,
352
+ ) {
353
+ let rows = await db
354
+ .select()
355
+ .from(schema.responseDeliveries)
356
+ .where(eq(schema.responseDeliveries.responseId, responseId));
357
+ if (rows.length > 0) return rows;
358
+
359
+ const values = buildResponseDeliveryRows(snapshot, responseId);
360
+ if (values.length > 0) {
361
+ await db
362
+ .insert(schema.responseDeliveries)
363
+ .values(values)
364
+ .onConflictDoNothing();
365
+ rows = await db
366
+ .select()
367
+ .from(schema.responseDeliveries)
368
+ .where(eq(schema.responseDeliveries.responseId, responseId));
369
+ }
370
+ return rows;
371
+ }
372
+
373
+ async function claimResponseDelivery(
374
+ db: ReturnType<typeof getDb>,
375
+ deliveryId: string,
376
+ ): Promise<string | null> {
377
+ const claimToken = nanoid();
378
+ const now = new Date();
379
+ const nowIso = now.toISOString();
380
+ const staleIso = new Date(
381
+ now.getTime() - DELIVERY_CLAIM_LEASE_MS,
382
+ ).toISOString();
383
+ const [claimed] = await db
384
+ .update(schema.responseDeliveries)
385
+ .set({
386
+ status: "processing",
387
+ claimToken,
388
+ claimedAt: nowIso,
389
+ updatedAt: nowIso,
390
+ errorMessage: null,
391
+ })
392
+ .where(
393
+ and(
394
+ eq(schema.responseDeliveries.id, deliveryId),
395
+ or(
396
+ eq(schema.responseDeliveries.status, "pending"),
397
+ eq(schema.responseDeliveries.status, "failed"),
398
+ and(
399
+ eq(schema.responseDeliveries.status, "processing"),
400
+ lt(schema.responseDeliveries.claimedAt, staleIso),
401
+ ),
402
+ ),
403
+ ),
404
+ )
405
+ .returning({ id: schema.responseDeliveries.id });
406
+ return claimed ? claimToken : null;
407
+ }
408
+
409
+ async function renewResponseDeliveryClaim(
410
+ db: ReturnType<typeof getDb>,
411
+ deliveryId: string,
412
+ claimToken: string,
413
+ ): Promise<void> {
414
+ const nowIso = new Date().toISOString();
415
+ const [renewed] = await db
416
+ .update(schema.responseDeliveries)
417
+ .set({ claimedAt: nowIso, updatedAt: nowIso })
418
+ .where(
419
+ and(
420
+ eq(schema.responseDeliveries.id, deliveryId),
421
+ eq(schema.responseDeliveries.claimToken, claimToken),
422
+ eq(schema.responseDeliveries.status, "processing"),
423
+ ),
424
+ )
425
+ .returning({ id: schema.responseDeliveries.id });
426
+ if (!renewed) throw new Error("Response delivery claim was lost");
427
+ }
428
+
429
+ function startResponseDeliveryLeaseHeartbeat(
430
+ db: ReturnType<typeof getDb>,
431
+ deliveryId: string,
432
+ claimToken: string,
433
+ ) {
434
+ let stopped = false;
435
+ let failure: unknown = null;
436
+ let pendingRenewal: Promise<void> | null = null;
437
+ const timer = setInterval(() => {
438
+ if (stopped || failure || pendingRenewal) return;
439
+ pendingRenewal = renewResponseDeliveryClaim(db, deliveryId, claimToken)
440
+ .catch((error) => {
441
+ failure = error;
442
+ clearInterval(timer);
443
+ })
444
+ .finally(() => {
445
+ pendingRenewal = null;
446
+ });
447
+ }, DELIVERY_CLAIM_HEARTBEAT_MS);
448
+ (timer as ReturnType<typeof setInterval> & { unref?: () => void }).unref?.();
449
+
450
+ return {
451
+ assertHealthy() {
452
+ if (failure) throw failure;
453
+ },
454
+ async stop() {
455
+ stopped = true;
456
+ clearInterval(timer);
457
+ await pendingRenewal;
458
+ },
459
+ };
460
+ }
461
+
462
+ async function markResponseDelivery(
463
+ db: ReturnType<typeof getDb>,
464
+ deliveryId: string,
465
+ claimToken: string,
466
+ status: Exclude<ResponseDeliveryStatus, "processing">,
467
+ errorMessage: string | null = null,
468
+ ): Promise<void> {
469
+ const nowIso = new Date().toISOString();
470
+ try {
471
+ const [updated] = await db
472
+ .update(schema.responseDeliveries)
473
+ .set({
474
+ status,
475
+ claimToken: null,
476
+ claimedAt: null,
477
+ errorMessage,
478
+ updatedAt: nowIso,
479
+ })
480
+ .where(
481
+ and(
482
+ eq(schema.responseDeliveries.id, deliveryId),
483
+ eq(schema.responseDeliveries.claimToken, claimToken),
484
+ ),
485
+ )
486
+ .returning({ id: schema.responseDeliveries.id });
487
+ if (updated) return;
488
+ throw new Error("Response delivery claim was lost");
489
+ } catch (error) {
490
+ // The database client can report a transport error after applying the
491
+ // update. Re-read before retrying an external effect so that accepted
492
+ // delivery is reconciled instead of duplicated.
493
+ const [current] = await db
494
+ .select({
495
+ status: schema.responseDeliveries.status,
496
+ claimToken: schema.responseDeliveries.claimToken,
497
+ })
498
+ .from(schema.responseDeliveries)
499
+ .where(eq(schema.responseDeliveries.id, deliveryId));
500
+ if (current?.status === status && current.claimToken === null) return;
501
+ throw error;
502
+ }
503
+ }
504
+
505
+ function parseStoredDeliveryPayload(value: string): StoredDeliveryPayload {
506
+ let parsed: unknown;
507
+ try {
508
+ parsed = JSON.parse(value);
509
+ } catch {
510
+ throw new Error("Unreadable response delivery payload");
511
+ }
512
+ if (!isObjectRecord(parsed) || typeof parsed.kind !== "string") {
513
+ throw new Error("Invalid response delivery payload");
514
+ }
515
+ if (
516
+ parsed.kind === "application-state" &&
517
+ typeof parsed.ownerEmail === "string" &&
518
+ isObjectRecord(parsed.value) &&
519
+ typeof parsed.value.formId === "string" &&
520
+ typeof parsed.value.responseId === "string" &&
521
+ typeof parsed.value.timestamp === "string"
522
+ ) {
523
+ return {
524
+ kind: "application-state",
525
+ ownerEmail: parsed.ownerEmail,
526
+ value: {
527
+ formId: parsed.value.formId,
528
+ responseId: parsed.value.responseId,
529
+ timestamp: parsed.value.timestamp,
530
+ },
531
+ };
532
+ }
533
+ if (
534
+ parsed.kind === "email" &&
535
+ (parsed.orgId === null || typeof parsed.orgId === "string") &&
536
+ isObjectRecord(parsed.args) &&
537
+ typeof parsed.args.to === "string" &&
538
+ typeof parsed.args.formTitle === "string" &&
539
+ Array.isArray(parsed.args.fields) &&
540
+ isObjectRecord(parsed.args.data) &&
541
+ typeof parsed.args.submittedAt === "string"
542
+ ) {
543
+ return {
544
+ kind: "email",
545
+ orgId: parsed.orgId,
546
+ args: {
547
+ to: parsed.args.to,
548
+ formTitle: parsed.args.formTitle,
549
+ fields: parsed.args.fields as FormField[],
550
+ data: parsed.args.data,
551
+ submittedAt: parsed.args.submittedAt,
552
+ },
553
+ };
554
+ }
555
+ if (parsed.kind === "integration") {
556
+ return {
557
+ kind: "integration",
558
+ snapshot: parseIntegrationSnapshot(parsed.snapshot),
559
+ };
560
+ }
561
+ throw new Error("Invalid response delivery payload");
562
+ }
563
+
564
+ function deliveryErrorMessage(error: unknown): string {
565
+ return (error instanceof Error ? error.message : String(error)).slice(0, 500);
566
+ }
567
+
568
+ async function deliverStoredResponseDelivery(
569
+ row: typeof schema.responseDeliveries.$inferSelect,
570
+ ): Promise<void> {
571
+ const payload = parseStoredDeliveryPayload(row.payload);
572
+ switch (payload.kind) {
573
+ case "application-state": {
574
+ const { appStatePut } =
575
+ await import("@agent-native/core/application-state");
576
+ await appStatePut(payload.ownerEmail, "new-submission", payload.value);
577
+ return;
578
+ }
579
+ case "email":
580
+ await runWithRequestContext(
581
+ {
582
+ userEmail: payload.args.to,
583
+ orgId: payload.orgId ?? undefined,
584
+ },
585
+ () => sendNewResponseEmail(payload.args),
586
+ );
587
+ return;
588
+ case "integration":
589
+ await deliverIntegrationDelivery(
590
+ payload.snapshot,
591
+ `forms:${row.responseId}:${row.destination}`,
592
+ );
593
+ }
594
+ }
595
+
596
+ async function deliverStoredResponseDeliveries(
597
+ db: ReturnType<typeof getDb>,
598
+ responseId: string,
599
+ snapshot: DeliverySnapshot,
600
+ ): Promise<boolean> {
601
+ const rows = await ensureResponseDeliveryRows(db, responseId, snapshot);
602
+ await Promise.all(
603
+ rows.map(async (row) => {
604
+ const claimToken = await claimResponseDelivery(db, row.id);
605
+ if (!claimToken) return;
606
+ const heartbeat = startResponseDeliveryLeaseHeartbeat(
607
+ db,
608
+ row.id,
609
+ claimToken,
610
+ );
611
+ try {
612
+ await deliverStoredResponseDelivery(row);
613
+ await heartbeat.stop();
614
+ heartbeat.assertHealthy();
615
+ await markResponseDelivery(db, row.id, claimToken, "succeeded");
616
+ } catch (error) {
617
+ await heartbeat.stop();
618
+ console.warn(`[forms] ${row.destination} delivery failed:`, error);
619
+ await markResponseDelivery(
620
+ db,
621
+ row.id,
622
+ claimToken,
623
+ "failed",
624
+ deliveryErrorMessage(error),
625
+ );
626
+ }
627
+ }),
628
+ );
629
+ await refreshResponseDeliverySummary(db, responseId);
630
+ const currentRows = await db
631
+ .select()
632
+ .from(schema.responseDeliveries)
633
+ .where(eq(schema.responseDeliveries.responseId, responseId));
634
+ return currentRows.some((row) => row.status !== "succeeded");
635
+ }
636
+
637
+ export async function reconcileResponseDeliveries(responseId: string) {
638
+ const db = getDb();
639
+ const [response] = await db
640
+ .select({
641
+ id: schema.responses.id,
642
+ deliverySnapshot: schema.responses.deliverySnapshot,
643
+ })
644
+ .from(schema.responses)
645
+ .where(eq(schema.responses.id, responseId));
646
+ if (!response) throw new Error(`Response ${responseId} not found`);
647
+
648
+ const snapshot = parseDeliverySnapshot(response.deliverySnapshot);
649
+ if (!snapshot) {
650
+ throw new Error(`Response ${responseId} has no delivery snapshot`);
651
+ }
652
+
653
+ const pending = await deliverStoredResponseDeliveries(
654
+ db,
655
+ response.id,
656
+ snapshot,
657
+ );
658
+ return {
659
+ success: !pending,
660
+ retryable: pending,
661
+ id: response.id,
662
+ };
663
+ }
664
+
665
+ function deliverySummary(
666
+ rows: Array<typeof schema.responseDeliveries.$inferSelect>,
667
+ ) {
668
+ const summary: Record<string, "pending" | "succeeded" | "failed"> = {};
669
+ for (const row of [...rows].sort((a, b) =>
670
+ a.destination.localeCompare(b.destination),
671
+ )) {
672
+ summary[row.destination] =
673
+ row.status === "processing" ? "pending" : row.status;
674
+ }
675
+ return summary;
676
+ }
677
+
678
+ async function refreshResponseDeliverySummary(
679
+ db: ReturnType<typeof getDb>,
680
+ responseId: string,
681
+ ): Promise<void> {
682
+ await db.transaction(async (tx) => {
683
+ const [response] = await tx
684
+ .select({ deliveryStatus: schema.responses.deliveryStatus })
685
+ .from(schema.responses)
686
+ .where(eq(schema.responses.id, responseId));
687
+ if (!response) return;
688
+
689
+ // Serialize all summary writers on the response row before reading the
690
+ // delivery rows, so a retry cannot commit an older aggregate after a
691
+ // newer destination status has been recorded.
692
+ await tx
693
+ .update(schema.responses)
694
+ .set({ deliveryStatus: response.deliveryStatus })
695
+ .where(eq(schema.responses.id, responseId));
696
+ const rows = await tx
697
+ .select()
698
+ .from(schema.responseDeliveries)
699
+ .where(eq(schema.responseDeliveries.responseId, responseId));
700
+ await tx
701
+ .update(schema.responses)
702
+ .set({ deliveryStatus: JSON.stringify(deliverySummary(rows)) })
703
+ .where(eq(schema.responses.id, responseId));
704
+ });
705
+ }
706
+
707
+ async function deliverBestEffortResponseSideEffects({
708
+ form,
709
+ settings,
710
+ fields,
711
+ data,
712
+ responseId,
713
+ submittedAt,
714
+ submitterEmail,
715
+ pageUrl,
716
+ clientSurface,
717
+ chatSessionIds,
718
+ activeRunId,
719
+ }: {
720
+ form: typeof schema.forms.$inferSelect;
721
+ settings: FormSettings;
722
+ fields: FormField[];
723
+ data: Record<string, unknown>;
724
+ responseId: string;
725
+ submittedAt: string;
726
+ submitterEmail: string | null;
727
+ pageUrl: string | null;
728
+ clientSurface: string | null;
729
+ chatSessionIds: string[];
730
+ activeRunId: string | null;
731
+ }): Promise<void> {
732
+ const run = async (label: string, effect: () => Promise<void>) => {
733
+ try {
734
+ await effect();
735
+ } catch (error) {
736
+ console.warn(`[forms] ${label} delivery failed:`, error);
737
+ }
738
+ };
739
+ if (form.ownerEmail) {
740
+ await run("application state", async () => {
741
+ const { appStatePut } =
742
+ await import("@agent-native/core/application-state");
743
+ await appStatePut(form.ownerEmail!, "new-submission", {
744
+ formId: form.id,
745
+ responseId,
746
+ timestamp: submittedAt,
747
+ });
748
+ });
749
+ }
750
+ if (settings.emailOnNewResponses === true && form.ownerEmail) {
751
+ await run("new response email", async () => {
752
+ await runWithRequestContext(
753
+ { userEmail: form.ownerEmail!, orgId: form.orgId ?? undefined },
754
+ () =>
755
+ sendNewResponseEmail({
756
+ to: form.ownerEmail!,
757
+ formTitle: form.title,
758
+ fields,
759
+ data,
760
+ submittedAt,
761
+ }),
762
+ );
763
+ });
764
+ }
765
+ const integrations = settings.integrations ?? [];
766
+ if (integrations.length > 0) {
767
+ await fireIntegrations(integrations, {
768
+ formId: form.id,
769
+ formTitle: form.title,
770
+ responseId,
771
+ fields,
772
+ data,
773
+ submittedAt,
774
+ submitterEmail,
775
+ chatSessionIds,
776
+ activeRunId,
777
+ pageUrl,
778
+ clientSurface,
779
+ });
780
+ }
781
+ }
782
+
783
+ async function deliverResponseSideEffects({
784
+ db,
785
+ form,
786
+ settings,
787
+ fields,
788
+ data,
789
+ responseId,
790
+ submittedAt,
791
+ submitterEmail,
792
+ pageUrl,
793
+ clientSurface,
794
+ chatSessionIds,
795
+ activeRunId,
796
+ trackDelivery,
797
+ deliverySnapshot,
798
+ }: {
799
+ db: ReturnType<typeof getDb>;
800
+ form: typeof schema.forms.$inferSelect;
801
+ settings: FormSettings;
802
+ fields: FormField[];
803
+ data: Record<string, unknown>;
804
+ responseId: string;
805
+ submittedAt: string;
806
+ submitterEmail: string | null;
807
+ pageUrl: string | null;
808
+ clientSurface: string | null;
809
+ chatSessionIds: string[];
810
+ activeRunId: string | null;
811
+ trackDelivery: boolean;
812
+ deliverySnapshot: DeliverySnapshot | null;
813
+ }): Promise<boolean> {
814
+ if (!trackDelivery) {
815
+ await deliverBestEffortResponseSideEffects({
816
+ form,
817
+ settings,
818
+ fields,
819
+ data,
820
+ responseId,
821
+ submittedAt,
822
+ submitterEmail,
823
+ pageUrl,
824
+ clientSurface,
825
+ chatSessionIds,
826
+ activeRunId,
827
+ });
828
+ return false;
829
+ }
830
+ const snapshot =
831
+ deliverySnapshot ??
832
+ buildDeliverySnapshot({
833
+ form,
834
+ settings,
835
+ fields,
836
+ data,
837
+ responseId,
838
+ submittedAt,
839
+ submitterEmail,
840
+ pageUrl,
841
+ clientSurface,
842
+ chatSessionIds,
843
+ activeRunId,
844
+ });
845
+ return deliverStoredResponseDeliveries(db, responseId, snapshot);
846
+ }
847
+
80
848
  export const submitForm = defineEventHandler(async (event: H3Event) => {
81
849
  const db = getDb();
82
850
  const id = getRouterParam(event, "id") as string;
83
851
 
852
+ // coercion-ok: malformed request bodies are rejected as invalid submissions.
853
+ const body = await readBody(event).catch(() => null);
854
+ if (!body || typeof body !== "object" || Array.isArray(body)) {
855
+ setResponseStatus(event, 400);
856
+ return { error: "Invalid submission payload" };
857
+ }
858
+
859
+ // Check overall payload size
860
+ const bodyStr = JSON.stringify(body);
861
+ if (Buffer.byteLength(bodyStr, "utf8") > MAX_PAYLOAD_BYTES) {
862
+ setResponseStatus(event, 413);
863
+ return { error: "Payload too large" };
864
+ }
865
+
866
+ const rawIdempotencyKey = getRequestHeader(event, "idempotency-key");
867
+ if (
868
+ rawIdempotencyKey &&
869
+ rawIdempotencyKey.trim().length > MAX_IDEMPOTENCY_KEY_LENGTH
870
+ ) {
871
+ setResponseStatus(event, 400);
872
+ return { error: "Idempotency-Key is too long" };
873
+ }
874
+ const idempotencyKey = rawIdempotencyKey?.trim() || null;
875
+
876
+ // A retry must be able to reconcile a persisted response even after its
877
+ // form is unpublished or soft-deleted. The immutable snapshot is the only
878
+ // input needed for delivery, so do this lookup before loading the active
879
+ // form or applying one-time submission checks.
880
+ if (idempotencyKey) {
881
+ const [existing] = await db
882
+ .select({
883
+ id: schema.responses.id,
884
+ deliverySnapshot: schema.responses.deliverySnapshot,
885
+ })
886
+ .from(schema.responses)
887
+ .where(
888
+ and(
889
+ eq(schema.responses.formId, id),
890
+ eq(schema.responses.idempotencyKey, idempotencyKey),
891
+ ),
892
+ );
893
+ if (existing) {
894
+ try {
895
+ const snapshot = parseDeliverySnapshot(existing.deliverySnapshot);
896
+ if (!snapshot) {
897
+ throw new Error(`Response ${existing.id} has no delivery snapshot`);
898
+ }
899
+ const deliveryPending = await deliverStoredResponseDeliveries(
900
+ db,
901
+ existing.id,
902
+ snapshot,
903
+ );
904
+ if (deliveryPending) {
905
+ setResponseStatus(event, 503);
906
+ return {
907
+ error: "Response delivery is still pending",
908
+ retryable: true,
909
+ id: existing.id,
910
+ };
911
+ }
912
+ } catch (error) {
913
+ console.warn("[forms] response delivery retry failed:", error);
914
+ setResponseStatus(event, 503);
915
+ return {
916
+ error: "Response delivery is still pending",
917
+ retryable: true,
918
+ id: existing.id,
919
+ };
920
+ }
921
+ return { success: true, id: existing.id };
922
+ }
923
+ }
924
+
84
925
  // guard:allow-unscoped — public submission endpoint intentionally accepts anonymous responses for published forms by id; it returns no owner data and rejects non-published forms.
85
926
  // Public submission endpoint: published forms are intentionally readable
86
927
  // without an authenticated viewer, but only by exact id and published status.
@@ -116,18 +957,95 @@ export const submitForm = defineEventHandler(async (event: H3Event) => {
116
957
  }
117
958
  }
118
959
 
119
- const body = await readBody(event).catch(() => null);
120
- if (!body || typeof body !== "object" || Array.isArray(body)) {
121
- setResponseStatus(event, 400);
122
- return { error: "Invalid submission payload" };
123
- }
124
-
125
- // Check overall payload size
126
- const bodyStr = JSON.stringify(body);
127
- if (Buffer.byteLength(bodyStr, "utf8") > MAX_PAYLOAD_BYTES) {
128
- setResponseStatus(event, 413);
129
- return { error: "Payload too large" };
130
- }
960
+ const finishResponse = async ({
961
+ responseId,
962
+ fields,
963
+ data,
964
+ submittedAt,
965
+ submitterEmail,
966
+ pageUrl,
967
+ clientSurface,
968
+ chatSessionIds,
969
+ activeRunId,
970
+ deliverySnapshot,
971
+ }: {
972
+ responseId: string;
973
+ fields: FormField[];
974
+ data: Record<string, unknown>;
975
+ submittedAt: string;
976
+ submitterEmail: string | null;
977
+ pageUrl: string | null;
978
+ clientSurface: string | null;
979
+ chatSessionIds: string[];
980
+ activeRunId: string | null;
981
+ deliverySnapshot: string | null | undefined;
982
+ }) => {
983
+ try {
984
+ const tracked = idempotencyKey !== null;
985
+ let parsedDeliverySnapshot = tracked
986
+ ? parseDeliverySnapshot(deliverySnapshot)
987
+ : null;
988
+ if (tracked && !parsedDeliverySnapshot) {
989
+ parsedDeliverySnapshot = buildDeliverySnapshot({
990
+ form,
991
+ settings,
992
+ fields,
993
+ data,
994
+ responseId,
995
+ submittedAt,
996
+ submitterEmail,
997
+ pageUrl,
998
+ clientSurface,
999
+ chatSessionIds,
1000
+ activeRunId,
1001
+ });
1002
+ await db
1003
+ .update(schema.responses)
1004
+ .set({ deliverySnapshot: JSON.stringify(parsedDeliverySnapshot) })
1005
+ .where(
1006
+ and(
1007
+ eq(schema.responses.id, responseId),
1008
+ isNull(schema.responses.deliverySnapshot),
1009
+ ),
1010
+ );
1011
+ }
1012
+ const deliveryPending = await deliverResponseSideEffects({
1013
+ db,
1014
+ form,
1015
+ settings,
1016
+ fields,
1017
+ data,
1018
+ responseId,
1019
+ submittedAt,
1020
+ submitterEmail,
1021
+ pageUrl,
1022
+ clientSurface,
1023
+ chatSessionIds,
1024
+ activeRunId,
1025
+ trackDelivery: tracked,
1026
+ deliverySnapshot: parsedDeliverySnapshot,
1027
+ });
1028
+ if (deliveryPending) {
1029
+ setResponseStatus(event, 503);
1030
+ return {
1031
+ error: "Response delivery is still pending",
1032
+ retryable: true,
1033
+ id: responseId,
1034
+ };
1035
+ }
1036
+ } catch (error) {
1037
+ console.warn("[forms] response delivery status update failed:", error);
1038
+ if (idempotencyKey) {
1039
+ setResponseStatus(event, 503);
1040
+ return {
1041
+ error: "Response delivery is still pending",
1042
+ retryable: true,
1043
+ id: responseId,
1044
+ };
1045
+ }
1046
+ }
1047
+ return { success: true, id: responseId };
1048
+ };
131
1049
 
132
1050
  // Honeypot: silently accept-and-drop if filled. Bots that fire-and-forget
133
1051
  // get a 200 and never know they were caught.
@@ -207,30 +1125,31 @@ export const submitForm = defineEventHandler(async (event: H3Event) => {
207
1125
  // who sent feedback in Slack). Never required. Prefer the Forms-host session
208
1126
  // when present; cross-app feedback submissions fall back to the client hint,
209
1127
  // which is useful context but not verified identity.
210
- const meta =
211
- !anonymous && typeof body._meta === "object" && body._meta !== null
212
- ? (body._meta as {
213
- submitterEmail?: unknown;
214
- chatSessionId?: unknown;
215
- chatSessionIds?: unknown;
216
- activeRunId?: unknown;
217
- pageUrl?: unknown;
218
- clientSurface?: unknown;
219
- })
220
- : null;
1128
+ const metadata = submissionMetadata(
1129
+ body as Record<string, unknown>,
1130
+ anonymous,
1131
+ );
221
1132
  const session = anonymous ? null : await getSession(event).catch(() => null);
222
1133
  const submitterEmail =
223
- cleanSubmitterEmail(session?.email) ??
224
- cleanSubmitterEmail(meta?.submitterEmail);
225
- const chatSessionIds = cleanChatSessionIds([
226
- meta?.chatSessionId,
227
- meta?.chatSessionIds,
228
- ]);
229
- const activeRunId = cleanMetaText(meta?.activeRunId);
230
- const pageUrl = scrubPageUrl(meta?.pageUrl);
231
- const clientSurface = cleanClientSurface(meta?.clientSurface);
232
-
233
- await db.insert(schema.responses).values({
1134
+ cleanSubmitterEmail(session?.email) ?? metadata.submitterEmail;
1135
+ const { chatSessionIds, activeRunId, pageUrl, clientSurface } = metadata;
1136
+ const deliverySnapshot = idempotencyKey
1137
+ ? buildDeliverySnapshot({
1138
+ form,
1139
+ settings,
1140
+ fields,
1141
+ data,
1142
+ responseId,
1143
+ submittedAt: now,
1144
+ submitterEmail,
1145
+ pageUrl,
1146
+ clientSurface,
1147
+ chatSessionIds,
1148
+ activeRunId,
1149
+ })
1150
+ : null;
1151
+
1152
+ const responseValues = {
234
1153
  id: responseId,
235
1154
  formId: id,
236
1155
  data: JSON.stringify(data),
@@ -239,69 +1158,78 @@ export const submitForm = defineEventHandler(async (event: H3Event) => {
239
1158
  submitterEmail,
240
1159
  pageUrl,
241
1160
  clientSurface,
242
- });
243
-
244
- // Write submission notification to application state (SQL-backed)
245
- try {
246
- const { appStatePut } =
247
- await import("@agent-native/core/application-state");
248
- await appStatePut(form.ownerEmail, "new-submission", {
249
- formId: id,
250
- responseId,
251
- timestamp: now,
252
- });
253
- } catch {
254
- // Non-critical — don't fail the submission
255
- }
1161
+ idempotencyKey,
1162
+ deliveryStatus: deliverySnapshot
1163
+ ? JSON.stringify(configuredDeliveryStatuses(deliverySnapshot))
1164
+ : null,
1165
+ deliverySnapshot: deliverySnapshot
1166
+ ? JSON.stringify(deliverySnapshot)
1167
+ : null,
1168
+ };
256
1169
 
257
- if (settings.emailOnNewResponses === true && form.ownerEmail) {
258
- try {
259
- await runWithRequestContext(
260
- { userEmail: form.ownerEmail, orgId: form.orgId ?? undefined },
261
- () =>
262
- sendNewResponseEmail({
263
- to: form.ownerEmail!,
264
- formTitle: form.title,
265
- fields,
266
- data,
267
- submittedAt: now,
268
- }),
1170
+ if (idempotencyKey) {
1171
+ const [inserted] = await db
1172
+ .insert(schema.responses)
1173
+ .values(responseValues)
1174
+ .onConflictDoNothing()
1175
+ .returning({ id: schema.responses.id });
1176
+ if (!inserted) {
1177
+ const [existing] = await db
1178
+ .select({
1179
+ id: schema.responses.id,
1180
+ data: schema.responses.data,
1181
+ submittedAt: schema.responses.submittedAt,
1182
+ submitterEmail: schema.responses.submitterEmail,
1183
+ pageUrl: schema.responses.pageUrl,
1184
+ clientSurface: schema.responses.clientSurface,
1185
+ deliveryStatus: schema.responses.deliveryStatus,
1186
+ deliverySnapshot: schema.responses.deliverySnapshot,
1187
+ })
1188
+ .from(schema.responses)
1189
+ .where(
1190
+ and(
1191
+ eq(schema.responses.formId, id),
1192
+ eq(schema.responses.idempotencyKey, idempotencyKey),
1193
+ ),
1194
+ );
1195
+ if (!existing) {
1196
+ throw new Error(
1197
+ "Submission idempotency conflict could not be resolved",
1198
+ );
1199
+ }
1200
+ const existingMetadata = submissionMetadata(
1201
+ body as Record<string, unknown>,
1202
+ anonymous,
269
1203
  );
270
- } catch (error) {
271
- // Email is best-effort — a provider outage must not reject a public
272
- // submission that was already persisted successfully.
273
- console.warn("[forms] new response email failed:", error);
274
- }
275
- }
276
-
277
- // Fire integrations best-effort and never fail the submission. Keep this
278
- // awaited: serverless hosts can freeze fire-and-forget work as soon as the
279
- // HTTP response returns, which silently drops Slack/webhook delivery.
280
- // pageUrl and clientSurface are persisted on the response (above) so owners
281
- // can see which screen and which app feedback came from; chat session ids and
282
- // run ids remain integration-only debug breadcrumbs we don't retain in SQL.
283
- try {
284
- const integrations: FormIntegration[] = settings.integrations ?? [];
285
- if (integrations.length > 0) {
286
- await fireIntegrations(integrations, {
287
- formId: id,
288
- formTitle: form.title,
289
- responseId,
1204
+ return finishResponse({
1205
+ responseId: existing.id,
290
1206
  fields,
291
- data,
292
- submittedAt: now,
293
- submitterEmail,
294
- chatSessionIds,
295
- activeRunId,
296
- pageUrl,
297
- clientSurface,
1207
+ data: JSON.parse(existing.data),
1208
+ submittedAt: existing.submittedAt,
1209
+ submitterEmail: existing.submitterEmail,
1210
+ pageUrl: existing.pageUrl,
1211
+ clientSurface: existing.clientSurface,
1212
+ chatSessionIds: existingMetadata.chatSessionIds,
1213
+ activeRunId: existingMetadata.activeRunId,
1214
+ deliverySnapshot: existing.deliverySnapshot,
298
1215
  });
299
1216
  }
300
- } catch {
301
- // Non-critical
1217
+ } else {
1218
+ await db.insert(schema.responses).values(responseValues);
302
1219
  }
303
1220
 
304
- return { success: true, id: responseId };
1221
+ return finishResponse({
1222
+ responseId,
1223
+ fields,
1224
+ data,
1225
+ submittedAt: now,
1226
+ submitterEmail,
1227
+ pageUrl,
1228
+ clientSurface,
1229
+ chatSessionIds,
1230
+ activeRunId,
1231
+ deliverySnapshot: responseValues.deliverySnapshot,
1232
+ });
305
1233
  });
306
1234
 
307
1235
  export const listResponses = defineEventHandler(async (event: H3Event) => {