@agent-native/core 0.169.1 → 0.171.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (463) hide show
  1. package/agent-native.eject.json +4 -1
  2. package/bin/agent-native.js +23 -5
  3. package/corpus/README.md +1 -1
  4. package/corpus/templates/analytics/.agents/skills/secrets/SKILL.md +11 -4
  5. package/corpus/templates/analytics/actions/query-agent-native-analytics.ts +1 -1
  6. package/corpus/templates/analytics/app/i18n-data.ts +28 -0
  7. package/corpus/templates/analytics/app/pages/Agents.tsx +25 -1
  8. package/corpus/templates/analytics/app/routes/$.tsx +10 -0
  9. package/corpus/templates/analytics/app/routes.ts +3 -1
  10. package/corpus/templates/analytics/changelog/2026-08-22-fixed-the-agent-native-templates-first-party-dashboard-panel.md +6 -0
  11. package/corpus/templates/analytics/changelog/2026-08-22-org-admin-panels-no-longer-report-a-database-error-as-a-per.md +9 -0
  12. package/corpus/templates/analytics/changelog/2026-08-22-slack-requests-report-invalid-inputs.md +6 -0
  13. package/corpus/templates/analytics/changelog/2026-08-22-unknown-analytics-links-now-return-a-real-not-found-status.md +6 -0
  14. package/corpus/templates/analytics/docs/schemas/first-party-analytics.md +2 -1
  15. package/corpus/templates/analytics/docs/schemas/tracked-events.md +2 -0
  16. package/corpus/templates/analytics/scripts/emit-netlify-dashboard-report-cron.ts +29 -7
  17. package/corpus/templates/analytics/server/handlers/slack.ts +59 -5
  18. package/corpus/templates/analytics/server/lib/db-admin-connections.ts +11 -6
  19. package/corpus/templates/analytics/server/lib/first-party-analytics.ts +132 -2
  20. package/corpus/templates/analytics/server/lib/slack.ts +4 -2
  21. package/corpus/templates/analytics/vitest.config.ts +6 -1
  22. package/corpus/templates/assets/.agents/skills/secrets/SKILL.md +11 -4
  23. package/corpus/templates/assets/app/routes/library.tsx +5 -3
  24. package/corpus/templates/assets/app/routes.ts +3 -1
  25. package/corpus/templates/assets/changelog/2026-08-22-library-page-loads-again-instead-of-crashing-on-open.md +6 -0
  26. package/corpus/templates/assets/vitest.config.ts +6 -1
  27. package/corpus/templates/brain/.agents/skills/secrets/SKILL.md +11 -4
  28. package/corpus/templates/brain/app/components/ui/pointer-lock.ts +1 -0
  29. package/corpus/templates/brain/app/routes/sources.tsx +8 -3
  30. package/corpus/templates/brain/changelog/2026-08-22-tuning-or-adding-a-source-no-longer-leaves-the-sources-page.md +6 -0
  31. package/corpus/templates/brain/vitest.config.ts +1 -0
  32. package/corpus/templates/calendar/.agents/skills/secrets/SKILL.md +11 -4
  33. package/corpus/templates/calendar/actions/list-booking-links.ts +83 -4
  34. package/corpus/templates/calendar/actions/update-booking-link.ts +4 -3
  35. package/corpus/templates/calendar/app/components/calendar/EventDetailPanel.tsx +11 -3
  36. package/corpus/templates/calendar/app/components/calendar/EventDetailPopover.tsx +1 -1
  37. package/corpus/templates/calendar/app/components/calendar/GoogleConnectBanner.tsx +103 -44
  38. package/corpus/templates/calendar/app/components/calendar/OutOfOfficeEvent.tsx +28 -24
  39. package/corpus/templates/calendar/app/components/layout/AppLayout.tsx +9 -2
  40. package/corpus/templates/calendar/app/components/layout/Sidebar.tsx +47 -58
  41. package/corpus/templates/calendar/app/hooks/use-booking-links.ts +5 -1
  42. package/corpus/templates/calendar/app/lib/event-layout.ts +52 -26
  43. package/corpus/templates/calendar/app/pages/BookingLinksPage.tsx +126 -98
  44. package/corpus/templates/calendar/app/pages/CalendarView.tsx +1 -0
  45. package/corpus/templates/calendar/app/pages/Settings.tsx +88 -81
  46. package/corpus/templates/calendar/app/routes.ts +3 -1
  47. package/corpus/templates/calendar/changelog/2026-08-22-booking-link-visibility-respects-shared-access.md +6 -0
  48. package/corpus/templates/calendar/changelog/2026-08-22-clicking-an-out-of-office-event-s-marker-no-longer-creates-a.md +6 -0
  49. package/corpus/templates/calendar/changelog/2026-08-22-event-detail-views-now-show-your-calendar-timezone.md +6 -0
  50. package/corpus/templates/calendar/changelog/2026-08-22-google-calendar-can-now-connect-with-the-shared-google-oauth.md +6 -0
  51. package/corpus/templates/calendar/changelog/2026-08-22-overlapping-events-now-show-each-others-boundaries.md +6 -0
  52. package/corpus/templates/calendar/changelog/2026-08-22-public-booking-pages-now-offer-time-slots-from-the-host-s-we.md +6 -0
  53. package/corpus/templates/calendar/server/handlers/bookings.ts +5 -7
  54. package/corpus/templates/calendar/server/handlers/google-auth.ts +10 -2
  55. package/corpus/templates/calendar/server/lib/google-calendar.ts +139 -14
  56. package/corpus/templates/calendar/server/onboarding.ts +85 -0
  57. package/corpus/templates/calendar/server/plugins/agent-chat.ts +2 -0
  58. package/corpus/templates/calendar/shared/api.ts +9 -1
  59. package/corpus/templates/chat/.agents/skills/secrets/SKILL.md +11 -4
  60. package/corpus/templates/chat/app/routes.ts +3 -1
  61. package/corpus/templates/chat/vitest.config.ts +8 -0
  62. package/corpus/templates/clips/.agents/skills/secrets/SKILL.md +11 -4
  63. package/corpus/templates/clips/actions/get-meeting.ts +9 -4
  64. package/corpus/templates/clips/actions/list-recordings.ts +16 -3
  65. package/corpus/templates/clips/actions/search-meetings.ts +1 -0
  66. package/corpus/templates/clips/actions/view-screen.ts +8 -1
  67. package/corpus/templates/clips/app/components/meetings/meeting-history-row.tsx +32 -1
  68. package/corpus/templates/clips/app/components/player/delete-recording-menu.tsx +1 -1
  69. package/corpus/templates/clips/app/components/recorder/recorder-engine.ts +29 -1
  70. package/corpus/templates/clips/app/i18n/en-US.ts +5 -0
  71. package/corpus/templates/clips/app/routes/_app.meetings.$meetingId.tsx +33 -4
  72. package/corpus/templates/clips/app/routes/_app.meetings._index.tsx +1 -0
  73. package/corpus/templates/clips/app/routes/access-request.approve.tsx +16 -9
  74. package/corpus/templates/clips/app/routes/embed.$shareId.tsx +17 -7
  75. package/corpus/templates/clips/app/routes/share.$shareId.tsx +17 -7
  76. package/corpus/templates/clips/changelog/2026-08-21-camera-bubble-black-circle.md +6 -0
  77. package/corpus/templates/clips/changelog/2026-08-22-screen-recordings-respect-the-microphone-toggle.md +6 -0
  78. package/corpus/templates/clips/changelog/2026-08-22-the-recordings-library-no-longer-fails-right-after-server-start.md +6 -0
  79. package/corpus/templates/clips/changelog/2026-08-23-the-agent-can-see-your-library-right-after-server-start.md +6 -0
  80. package/corpus/templates/clips/chrome-extension/src/background.ts +1 -2
  81. package/corpus/templates/clips/chrome-extension/src/native-transcription.ts +39 -7
  82. package/corpus/templates/clips/chrome-extension/src/offscreen.ts +21 -25
  83. package/corpus/templates/clips/desktop/src/app.tsx +53 -24
  84. package/corpus/templates/clips/desktop/src/lib/bubble-playback.ts +68 -0
  85. package/corpus/templates/clips/desktop/src/lib/recorder.ts +3 -0
  86. package/corpus/templates/clips/desktop/src/lib/transcription-capture.ts +72 -14
  87. package/corpus/templates/clips/desktop/src/lib/updater.ts +8 -3
  88. package/corpus/templates/clips/desktop/src/overlays/bubble.tsx +162 -20
  89. package/corpus/templates/clips/desktop/src-tauri/src/clips/mod.rs +43 -6
  90. package/corpus/templates/clips/desktop/src-tauri/src/native_screen/custom_capture.rs +150 -13
  91. package/corpus/templates/clips/desktop/src-tauri/src/tray.rs +12 -0
  92. package/corpus/templates/clips/server/lib/calendar-event-meetings.ts +28 -3
  93. package/corpus/templates/clips/server/lib/emails.ts +17 -33
  94. package/corpus/templates/content/.agents/skills/secrets/SKILL.md +11 -4
  95. package/corpus/templates/content/app/components/editor/VisualEditor.tsx +140 -15
  96. package/corpus/templates/content/app/components/sidebar/DocumentSidebar.tsx +12 -14
  97. package/corpus/templates/content/app/components/ui/pointer-lock.ts +1 -0
  98. package/corpus/templates/content/app/hooks/use-content-database.ts +18 -2
  99. package/corpus/templates/content/app/hooks/use-local-storage.ts +38 -22
  100. package/corpus/templates/content/app/i18n-data.ts +25 -0
  101. package/corpus/templates/content/app/routes.ts +3 -1
  102. package/corpus/templates/content/changelog/2026-08-22-code-blocks-inserted-from-the-slash-menu-no-longer-get-stuck.md +6 -0
  103. package/corpus/templates/content/changelog/2026-08-22-the-sidebar-page-tree-no-longer-flashes-empty-after-creating-a-page.md +6 -0
  104. package/corpus/templates/content/docs/solutions/2026-08-21-content-mermaid-rendering-shape.md +233 -0
  105. package/corpus/templates/content/server/plugins/agent-chat.ts +9 -2
  106. package/corpus/templates/content/vitest.config.ts +7 -1
  107. package/corpus/templates/crm/.agents/skills/secrets/SKILL.md +11 -4
  108. package/corpus/templates/design/.agents/skills/secrets/SKILL.md +11 -4
  109. package/corpus/templates/design/.generated/bridge/editor-chrome.generated.ts +1383 -88
  110. package/corpus/templates/design/actions/generate-design.ts +98 -47
  111. package/corpus/templates/design/actions/get-design-system.ts +6 -1
  112. package/corpus/templates/design/actions/refresh-design-system-with-builder.ts +146 -0
  113. package/corpus/templates/design/app/components/design/DesignCanvas.tsx +70 -26
  114. package/corpus/templates/design/app/components/design/MultiScreenCanvas.tsx +284 -136
  115. package/corpus/templates/design/app/components/design/bridge/editor-chrome.bridge.ts +2057 -141
  116. package/corpus/templates/design/app/components/design/editor/DesignBottomToolbar.tsx +6 -2
  117. package/corpus/templates/design/app/components/design/editor/DesignWorkspaceRail.tsx +4 -4
  118. package/corpus/templates/design/app/components/design/keyboard-shortcuts.ts +10 -1
  119. package/corpus/templates/design/app/components/design/multi-screen/alt-hover-measurement.ts +19 -2
  120. package/corpus/templates/design/app/components/design/multi-screen/types.ts +9 -2
  121. package/corpus/templates/design/app/components/layout/Header.tsx +15 -0
  122. package/corpus/templates/design/app/components/layout/Layout.tsx +7 -2
  123. package/corpus/templates/design/app/hooks/useDesignHotkeys.ts +11 -4
  124. package/corpus/templates/design/app/i18n-data.ts +1 -0
  125. package/corpus/templates/design/app/i18n-keyboard-shortcuts.ts +12 -0
  126. package/corpus/templates/design/app/lib/design-system-data.ts +68 -0
  127. package/corpus/templates/design/app/pages/DesignEditor.tsx +77 -35
  128. package/corpus/templates/design/app/pages/DesignSystems.tsx +136 -42
  129. package/corpus/templates/design/app/pages/Index.tsx +2 -0
  130. package/corpus/templates/design/app/pages/Templates.tsx +0 -10
  131. package/corpus/templates/design/app/pages/design-editor/code-layer-state.ts +10 -0
  132. package/corpus/templates/design/app/pages/design-editor/collab-sync.ts +50 -0
  133. package/corpus/templates/design/app/pages/design-editor/commands/apply-design-editor-command.ts +1 -1
  134. package/corpus/templates/design/app/pages/design-editor/commands/apply-file-content-update.ts +10 -8
  135. package/corpus/templates/design/app/pages/design-editor/commands/apply-local-content-update.ts +6 -6
  136. package/corpus/templates/design/app/pages/design-editor/commands/apply-pending-visual-styles-with-agent.ts +1 -1
  137. package/corpus/templates/design/app/pages/design-editor/commands/commit-visual-styles.ts +18 -7
  138. package/corpus/templates/design/app/pages/design-editor/commands/escape-hotkey.ts +4 -90
  139. package/corpus/templates/design/app/pages/design-editor/commands/layer-marquee-selection-change.ts +2 -1
  140. package/corpus/templates/design/app/pages/design-editor/commands/layer-selection-change.ts +4 -3
  141. package/corpus/templates/design/app/pages/design-editor/commands/screen-element-select.ts +12 -2
  142. package/corpus/templates/design/app/pages/design-editor/commands/screen-visual-style-change.ts +9 -2
  143. package/corpus/templates/design/app/pages/design-editor/commands/send-runtime-layer-move-semantic-handoff.ts +1 -1
  144. package/corpus/templates/design/app/pages/design-editor/commands/send-runtime-layer-semantic-handoff.ts +1 -1
  145. package/corpus/templates/design/app/pages/design-editor/commands/send-runtime-layer-state-semantic-handoff.ts +1 -1
  146. package/corpus/templates/design/app/pages/design-editor/commands/start-sidebar-resize.ts +1 -1
  147. package/corpus/templates/design/app/pages/design-editor/editor-state.ts +11 -1
  148. package/corpus/templates/design/app/pages/design-editor/effects/adopt-db-file-content.ts +11 -19
  149. package/corpus/templates/design/app/pages/design-editor/effects/observe-collab-text.ts +6 -6
  150. package/corpus/templates/design/app/pages/design-editor/effects/publish-agent-selection-context.ts +1 -1
  151. package/corpus/templates/design/app/pages/design-editor/effects/seed-collab-content.ts +12 -15
  152. package/corpus/templates/design/app/pages/design-editor/selection-state.ts +5 -59
  153. package/corpus/templates/design/app/pages/design-editor/tool-state.ts +8 -0
  154. package/corpus/templates/design/app/pages/design-editor/types.ts +3 -3
  155. package/corpus/templates/design/app/routes.ts +3 -1
  156. package/corpus/templates/design/changelog/2026-08-20-canvas-edits-patch-the-frame-instead-of-rebuilding-it.md +6 -0
  157. package/corpus/templates/design/changelog/2026-08-21-builder-design-system-imports-reconcile-after-indexing.md +6 -0
  158. package/corpus/templates/design/changelog/2026-08-21-draw-mode-needs-shift-y.md +6 -0
  159. package/corpus/templates/design/changelog/2026-08-21-eyedropper-shortcut.md +6 -0
  160. package/corpus/templates/design/changelog/2026-08-21-figma-style-alignment-guides-and-snapping.md +6 -0
  161. package/corpus/templates/design/changelog/2026-08-21-group-transforms-keep-the-selection.md +6 -0
  162. package/corpus/templates/design/changelog/2026-08-21-inspector-fields-keep-focus-on-enter.md +6 -0
  163. package/corpus/templates/design/changelog/2026-08-21-pen-alt-keeps-the-incoming-handle.md +6 -0
  164. package/corpus/templates/design/changelog/2026-08-21-pen-on-the-board-creates-one-vector.md +6 -0
  165. package/corpus/templates/design/changelog/2026-08-21-scale-a-multi-selection-from-the-group-handles.md +6 -0
  166. package/corpus/templates/design/changelog/2026-08-21-scale-resizes-text-with-the-object.md +6 -0
  167. package/corpus/templates/design/changelog/2026-08-21-selecting-another-object-keeps-the-scale-tool-armed.md +6 -0
  168. package/corpus/templates/design/changelog/2026-08-21-the-shape-tool-remembers-the-shape-you-picked.md +6 -0
  169. package/corpus/templates/design/changelog/2026-08-21-vectors-drawn-in-a-frame-land-where-you-drew-them.md +6 -0
  170. package/corpus/templates/design/changelog/2026-08-22-multi-screen-generation-no-longer-loses-a-saved-screens-layo.md +6 -0
  171. package/corpus/templates/design/changelog/2026-08-22-rename-and-search-fields-are-labeled-for-screen-readers.md +6 -0
  172. package/corpus/templates/design/package.json +2 -0
  173. package/corpus/templates/design/server/lib/builder-design-system-proxy.ts +311 -0
  174. package/corpus/templates/design/shared/canvas-math.ts +612 -206
  175. package/corpus/templates/design/shared/pen-path.ts +37 -0
  176. package/corpus/templates/design/vitest.config.ts +7 -1
  177. package/corpus/templates/dispatch/.agents/skills/secrets/SKILL.md +11 -4
  178. package/corpus/templates/dispatch/actions/list-workspace-connections.ts +34 -3
  179. package/corpus/templates/dispatch/app/routes/integrations.tsx +55 -21
  180. package/corpus/templates/dispatch/app/routes.ts +3 -1
  181. package/corpus/templates/factory/.agents/skills/secrets/SKILL.md +11 -4
  182. package/corpus/templates/factory/.env.example +2 -7
  183. package/corpus/templates/factory/AGENTS.md +3 -0
  184. package/corpus/templates/factory/README.md +5 -3
  185. package/corpus/templates/factory/actions/create-factory.ts +16 -3
  186. package/corpus/templates/factory/actions/get-slack-feedback-context.ts +2 -0
  187. package/corpus/templates/factory/actions/get-triage-item.ts +2 -0
  188. package/corpus/templates/factory/actions/list-factory-audit.ts +116 -36
  189. package/corpus/templates/factory/actions/list-factory-automations.ts +2 -1
  190. package/corpus/templates/factory/actions/list-triage-items.ts +22 -19
  191. package/corpus/templates/factory/actions/run-factory-automation.ts +7 -3
  192. package/corpus/templates/factory/actions/save-factory-automation.ts +5 -2
  193. package/corpus/templates/factory/actions/save-triage-config.ts +2 -8
  194. package/corpus/templates/factory/actions/start-builder-for-item.ts +21 -0
  195. package/corpus/templates/factory/app/components/factory/FactoryAuditView.tsx +229 -297
  196. package/corpus/templates/factory/app/components/factory/FactorySettingsView.tsx +397 -247
  197. package/corpus/templates/factory/app/components/factory/FactorySourceSettingsGroup.tsx +33 -0
  198. package/corpus/templates/factory/app/components/factory/NewFactoryForm.tsx +202 -162
  199. package/corpus/templates/factory/app/i18n/en-US.ts +32 -4
  200. package/corpus/templates/factory/app/routes/factory.tsx +84 -11
  201. package/corpus/templates/factory/app/routes.ts +3 -1
  202. package/corpus/templates/factory/changelog/2026-08-21-activity-runs-use-automation-display-names.md +6 -0
  203. package/corpus/templates/factory/changelog/2026-08-21-create-and-settings-source-cards.md +6 -0
  204. package/corpus/templates/factory/changelog/2026-08-21-keep-automations-visible-while-running.md +6 -0
  205. package/corpus/templates/factory/changelog/2026-08-21-nested-factory-automations-can-poll.md +6 -0
  206. package/corpus/templates/factory/changelog/2026-08-21-settings-sticky-unsaved-bar.md +6 -0
  207. package/corpus/templates/factory/server/connectors/credentials.ts +10 -5
  208. package/corpus/templates/factory/server/lib/factory-audit-report.ts +412 -0
  209. package/corpus/templates/factory/server/lib/factory-config-reconcile.ts +321 -0
  210. package/corpus/templates/factory/server/lib/factory-scope.ts +25 -2
  211. package/corpus/templates/factory/server/lib/require-factory-automation.ts +13 -4
  212. package/corpus/templates/factory/server/plugins/factory-migrations.ts +148 -4
  213. package/corpus/templates/factory/server/plugins/factory-scheduler-job.ts +4 -6
  214. package/corpus/templates/factory/vitest.config.ts +17 -2
  215. package/corpus/templates/forms/.agents/skills/secrets/SKILL.md +11 -4
  216. package/corpus/templates/forms/app/routes/_app.settings.tsx +4 -1
  217. package/corpus/templates/forms/changelog/2026-08-22-the-extensions-link-now-opens-the-extensions-tab-instead-o.md +6 -0
  218. package/corpus/templates/forms/server/lib/public-form-ssr.ts +11 -1
  219. package/corpus/templates/forms/vitest.config.ts +1 -0
  220. package/corpus/templates/macros/.agents/skills/secrets/SKILL.md +11 -4
  221. package/corpus/templates/macros/app/routes.ts +3 -1
  222. package/corpus/templates/macros/vitest.config.ts +6 -1
  223. package/corpus/templates/mail/.agents/skills/secrets/SKILL.md +11 -4
  224. package/corpus/templates/mail/actions/manage-gmail-filters.ts +10 -2
  225. package/corpus/templates/mail/app/components/GoogleConnectBanner.tsx +100 -37
  226. package/corpus/templates/mail/app/components/email/IntegrationsSidebar.tsx +14 -2
  227. package/corpus/templates/mail/app/components/layout/AppLayout.tsx +66 -36
  228. package/corpus/templates/mail/app/hooks/use-google-auth.ts +2 -0
  229. package/corpus/templates/mail/app/lib/google-oauth-setup.ts +17 -0
  230. package/corpus/templates/mail/app/pages/InboxPage.tsx +69 -9
  231. package/corpus/templates/mail/app/routes/$.tsx +9 -0
  232. package/corpus/templates/mail/app/routes/$view.$threadId.tsx +23 -1
  233. package/corpus/templates/mail/app/routes/$view.tsx +47 -1
  234. package/corpus/templates/mail/app/routes.ts +3 -1
  235. package/corpus/templates/mail/changelog/2026-08-22-gmail-can-now-connect-with-the-shared-google-oauth.md +6 -0
  236. package/corpus/templates/mail/changelog/2026-08-22-gmail-filters-now-shows-the-real-error.md +6 -0
  237. package/corpus/templates/mail/changelog/2026-08-22-unknown-mail-urls-now-show-the-404-page.md +6 -0
  238. package/corpus/templates/mail/server/handlers/google-auth.ts +11 -2
  239. package/corpus/templates/mail/server/lib/google-auth.ts +92 -12
  240. package/corpus/templates/mail/server/onboarding.ts +66 -18
  241. package/corpus/templates/mail/vitest.config.ts +6 -1
  242. package/corpus/templates/plan/.agents/skills/secrets/SKILL.md +11 -4
  243. package/corpus/templates/plan/app/routes/settings.tsx +4 -1
  244. package/corpus/templates/plan/app/routes.ts +3 -1
  245. package/corpus/templates/plan/changelog/2026-08-22-the-extensions-link-now-opens-the-extensions-tab-instead-o.md +6 -0
  246. package/corpus/templates/plan/netlify.toml +1 -1
  247. package/corpus/templates/slides/.agents/skills/secrets/SKILL.md +11 -4
  248. package/corpus/templates/slides/actions/patch-deck.ts +79 -10
  249. package/corpus/templates/slides/actions/update-slide.ts +11 -1
  250. package/corpus/templates/slides/app/components/deck/SlideRenderer.tsx +14 -4
  251. package/corpus/templates/slides/app/components/editor/ExportMenu.tsx +10 -52
  252. package/corpus/templates/slides/app/components/editor/GoogleDocImportHint.tsx +8 -53
  253. package/corpus/templates/slides/app/components/editor/GoogleDriveConnectionCta.tsx +9 -75
  254. package/corpus/templates/slides/app/components/editor/GoogleSlidesReferenceImport.tsx +8 -60
  255. package/corpus/templates/slides/app/components/editor/SlideContextToolbar.tsx +10 -2
  256. package/corpus/templates/slides/app/components/editor/SlideEditor.tsx +19 -7
  257. package/corpus/templates/slides/app/lib/sanitize-slide-html.ts +49 -36
  258. package/corpus/templates/slides/app/routes/access-request.approve.tsx +16 -9
  259. package/corpus/templates/slides/app/routes.ts +3 -1
  260. package/corpus/templates/slides/changelog/2026-08-22-already-uploaded-chat-images-are-no-longer-dropped.md +6 -0
  261. package/corpus/templates/slides/changelog/2026-08-22-google-drive-and-slides-can-now-connect-with-the-shared-google-oauth.md +6 -0
  262. package/corpus/templates/slides/changelog/2026-08-22-multi-slide-repairs-now-report-slides-that-still-overflow.md +6 -0
  263. package/corpus/templates/slides/changelog/2026-08-22-update-slide-now-reports-which-batched-edit-was-skipped.md +6 -0
  264. package/corpus/templates/slides/server/handlers/google-docs-auth.ts +52 -1
  265. package/corpus/templates/slides/server/lib/chat-attachments.ts +29 -3
  266. package/corpus/templates/slides/server/lib/google-docs-oauth.ts +66 -16
  267. package/corpus/templates/slides/server/lib/slide-content-patch.ts +13 -2
  268. package/corpus/templates/slides/server/plugins/agent-chat.ts +5 -2
  269. package/corpus/templates/slides/tsconfig.json +5 -0
  270. package/corpus/templates/slides/vitest.config.ts +6 -1
  271. package/corpus/templates/tasks/.agents/skills/secrets/SKILL.md +11 -4
  272. package/corpus/templates/tasks/app/routes/settings.tsx +4 -1
  273. package/corpus/templates/tasks/app/routes.ts +3 -1
  274. package/corpus/templates/tasks/changelog/2026-08-22-the-extensions-link-now-opens-the-extensions-tab-instead-o.md +6 -0
  275. package/corpus/templates/tasks/vitest.config.ts +7 -1
  276. package/dist/action.d.ts +91 -0
  277. package/dist/action.js +50 -0
  278. package/dist/agent/abort-reasons.d.ts +38 -0
  279. package/dist/agent/abort-reasons.js +49 -0
  280. package/dist/agent/engine/ai-sdk-engine.js +8 -5
  281. package/dist/agent/engine/anthropic-engine.js +7 -5
  282. package/dist/agent/engine/first-event-timeout.d.ts +42 -17
  283. package/dist/agent/engine/first-event-timeout.js +67 -25
  284. package/dist/agent/production-agent.d.ts +23 -0
  285. package/dist/agent/production-agent.js +107 -102
  286. package/dist/agent/run-loop-with-resume.d.ts +2 -28
  287. package/dist/agent/run-loop-with-resume.js +25 -40
  288. package/dist/agent/run-manager.js +5 -4
  289. package/dist/agent/run-store.d.ts +55 -0
  290. package/dist/agent/run-store.js +124 -1
  291. package/dist/agent/tool-search.js +2 -1
  292. package/dist/agent/types.d.ts +9 -4
  293. package/dist/app-config/auth.d.ts +1 -0
  294. package/dist/app-config/auth.js +7 -0
  295. package/dist/app-config/configuration-error.d.ts +11 -0
  296. package/dist/app-config/configuration-error.js +14 -0
  297. package/dist/app-config/index.d.ts +1 -0
  298. package/dist/app-config/index.js +1 -0
  299. package/dist/app-config/integrations.d.ts +1 -0
  300. package/dist/app-config/integrations.js +10 -0
  301. package/dist/app-config/plugins.d.ts +34 -0
  302. package/dist/app-config/plugins.js +39 -0
  303. package/dist/app-config/run-lifecycle-invariants.d.ts +18 -9
  304. package/dist/app-config/run-lifecycle-invariants.js +18 -25
  305. package/dist/app-config/schema.d.ts +17 -0
  306. package/dist/app-config/schema.js +2 -0
  307. package/dist/chat-threads/schema-migrations.js +20 -0
  308. package/dist/chat-threads/store.js +21 -4
  309. package/dist/cli/native-dependencies.d.ts +4 -0
  310. package/dist/cli/native-dependencies.js +15 -0
  311. package/dist/client/EnvironmentBadge.d.ts +1 -1
  312. package/dist/client/EnvironmentBadge.js +40 -5
  313. package/dist/client/MultiTabAssistantChat.d.ts +1 -1
  314. package/dist/client/MultiTabAssistantChat.js +35 -14
  315. package/dist/client/agent-chat/index.d.ts +1 -1
  316. package/dist/client/agent-chat/index.js +1 -1
  317. package/dist/client/agent-page/use-jobs.d.ts +2 -1
  318. package/dist/client/agent-page/use-jobs.js +3 -5
  319. package/dist/client/agent-sidebar-state.js +3 -1
  320. package/dist/client/blocks/library/code-tabs.js +5 -0
  321. package/dist/client/blocks/library/code.js +1 -0
  322. package/dist/client/chat-first/apps-rail.js +2 -2
  323. package/dist/client/chat-model-groups.d.ts +12 -0
  324. package/dist/client/chat-model-groups.js +3 -2
  325. package/dist/client/integrations/GoogleProductLogo.d.ts +5 -0
  326. package/dist/client/integrations/GoogleProductLogo.js +45 -0
  327. package/dist/client/integrations/index.d.ts +2 -0
  328. package/dist/client/integrations/index.js +2 -0
  329. package/dist/client/integrations/workspace-provider-oauth.d.ts +8 -0
  330. package/dist/client/integrations/workspace-provider-oauth.js +13 -0
  331. package/dist/client/resources/mcp-integration-catalog.js +0 -29
  332. package/dist/client/settings/SettingsTabsPage.js +10 -6
  333. package/dist/client/sharing/ShareButton.js +11 -2
  334. package/dist/client/use-chat-models.d.ts +6 -0
  335. package/dist/client/use-chat-models.js +10 -0
  336. package/dist/client/use-db-sync.js +27 -9
  337. package/dist/collab/routes.d.ts +1 -1
  338. package/dist/collab/struct-routes.d.ts +1 -1
  339. package/dist/connections/catalog.d.ts +111 -9
  340. package/dist/connections/catalog.js +86 -30
  341. package/dist/db/create-get-db.js +18 -0
  342. package/dist/db/ddl-guard.d.ts +0 -4
  343. package/dist/db/ddl-guard.js +46 -0
  344. package/dist/deploy/build.d.ts +19 -0
  345. package/dist/deploy/build.js +190 -16
  346. package/dist/deploy/function-bundle.d.ts +45 -0
  347. package/dist/deploy/function-bundle.js +337 -0
  348. package/dist/deploy/workspace-deploy.js +19 -1
  349. package/dist/eject/workspace-connections.js +4 -0
  350. package/dist/email-catalog/registry.d.ts +4 -0
  351. package/dist/email-catalog/registry.js +79 -14
  352. package/dist/extensions/content-patch.js +14 -2
  353. package/dist/integrations/plugin.d.ts +10 -0
  354. package/dist/integrations/plugin.js +40 -6
  355. package/dist/jobs/actions/run-automation-now.d.ts +2 -1
  356. package/dist/jobs/actions/run-automation-now.js +11 -5
  357. package/dist/jobs/frontmatter.js +53 -2
  358. package/dist/jobs/run-now.d.ts +11 -1
  359. package/dist/jobs/run-now.js +42 -7
  360. package/dist/jobs/scheduler.d.ts +1 -0
  361. package/dist/jobs/scheduler.js +2 -1
  362. package/dist/localization/core-messages/ar-SA.js +3 -0
  363. package/dist/localization/core-messages/de-DE.js +3 -0
  364. package/dist/localization/core-messages/en-US.d.ts +3 -0
  365. package/dist/localization/core-messages/en-US.js +3 -0
  366. package/dist/localization/core-messages/es-ES.js +3 -0
  367. package/dist/localization/core-messages/fr-FR.js +3 -0
  368. package/dist/localization/core-messages/hi-IN.js +3 -0
  369. package/dist/localization/core-messages/ja-JP.js +3 -0
  370. package/dist/localization/core-messages/ko-KR.js +3 -0
  371. package/dist/localization/core-messages/pt-BR.js +3 -0
  372. package/dist/localization/core-messages/zh-CN.js +3 -0
  373. package/dist/localization/core-messages/zh-TW.js +3 -0
  374. package/dist/localization/core-messages.d.ts +3 -0
  375. package/dist/localization/default-messages.d.ts +2 -5
  376. package/dist/localization/default-messages.js +2 -5
  377. package/dist/mcp/build-server.d.ts +9 -0
  378. package/dist/mcp/build-server.js +37 -8
  379. package/dist/mcp-client/oauth-client.d.ts +7 -0
  380. package/dist/mcp-client/oauth-client.js +12 -1
  381. package/dist/oauth-tokens/index.d.ts +1 -1
  382. package/dist/oauth-tokens/index.js +1 -1
  383. package/dist/oauth-tokens/lifecycle.d.ts +11 -0
  384. package/dist/oauth-tokens/lifecycle.js +17 -0
  385. package/dist/oauth-tokens/store.js +7 -0
  386. package/dist/observability/posthog-ai.d.ts +15 -1
  387. package/dist/observability/posthog-ai.js +24 -12
  388. package/dist/observability/traces.js +158 -28
  389. package/dist/onboarding/app-profile.js +2 -2
  390. package/dist/onboarding/plugin.js +10 -2
  391. package/dist/onboarding/types.d.ts +2 -0
  392. package/dist/provider-api/actions/custom-provider-registration.d.ts +1 -1
  393. package/dist/provider-api/actions/provider-api.d.ts +2 -2
  394. package/dist/provider-api/index.js +2 -0
  395. package/dist/resources/handlers.d.ts +2 -2
  396. package/dist/resources/store.js +13 -4
  397. package/dist/scripts/agent-engines/list-agent-engines.js +29 -3
  398. package/dist/secrets/register-framework-secrets.js +1 -1
  399. package/dist/server/action-discovery.js +5 -0
  400. package/dist/server/agent-chat/action-filters-a2a.d.ts +27 -3
  401. package/dist/server/agent-chat/action-filters-a2a.js +48 -9
  402. package/dist/server/agent-chat-plugin.js +36 -9
  403. package/dist/server/agent-discovery.js +43 -20
  404. package/dist/server/auth.js +18 -16
  405. package/dist/server/beta-opt-out-html.js +45 -4
  406. package/dist/server/better-auth-instance.d.ts +2 -1
  407. package/dist/server/better-auth-instance.js +37 -7
  408. package/dist/server/builder-design-systems.d.ts +4 -1
  409. package/dist/server/builder-design-systems.js +87 -6
  410. package/dist/server/builder-oauth.d.ts +1 -7
  411. package/dist/server/builder-oauth.js +80 -163
  412. package/dist/server/core-routes-plugin.d.ts +29 -0
  413. package/dist/server/core-routes-plugin.js +100 -20
  414. package/dist/server/default-plugins.d.ts +18 -0
  415. package/dist/server/default-plugins.js +22 -0
  416. package/dist/server/edge.d.ts +1 -0
  417. package/dist/server/edge.js +1 -0
  418. package/dist/server/framework-request-handler.js +31 -3
  419. package/dist/server/google-oauth.d.ts +3 -0
  420. package/dist/server/google-oauth.js +3 -0
  421. package/dist/server/index.d.ts +4 -4
  422. package/dist/server/index.js +3 -3
  423. package/dist/server/onboarding-html.js +37 -3
  424. package/dist/server/realtime-token.d.ts +1 -1
  425. package/dist/server/workspace-provider-oauth.d.ts +6 -1
  426. package/dist/server/workspace-provider-oauth.js +72 -20
  427. package/dist/shared/agent-sidebar-url.d.ts +1 -0
  428. package/dist/shared/agent-sidebar-url.js +1 -0
  429. package/dist/shared/environment-lanes.d.ts +2 -0
  430. package/dist/shared/environment-lanes.js +3 -1
  431. package/dist/shared/index.d.ts +3 -1
  432. package/dist/shared/index.js +3 -1
  433. package/dist/shared/surface-visibility.d.ts +31 -0
  434. package/dist/shared/surface-visibility.js +57 -0
  435. package/dist/templates/chat/.agents/skills/secrets/SKILL.md +11 -4
  436. package/dist/templates/chat/app/routes.ts +3 -1
  437. package/dist/templates/chat/vitest.config.ts +8 -0
  438. package/dist/templates/default/.agents/skills/secrets/SKILL.md +11 -4
  439. package/dist/templates/default/app/routes.ts +3 -1
  440. package/dist/templates/headless/.agents/skills/secrets/SKILL.md +11 -4
  441. package/dist/templates/workspace-core/.agents/skills/secrets/SKILL.md +11 -4
  442. package/dist/tracking/registry.d.ts +11 -0
  443. package/dist/tracking/registry.js +5 -2
  444. package/dist/triggers/actions.js +10 -3
  445. package/dist/usage/store.js +23 -3
  446. package/dist/user-profile/actions/get-auth-methods.js +18 -5
  447. package/dist/vite/client.js +33 -7
  448. package/docs/content/actions-access-control.mdx +43 -4
  449. package/docs/content/actions-defining.mdx +16 -0
  450. package/docs/content/authentication.mdx +40 -21
  451. package/docs/content/environment-variables.mdx +1 -0
  452. package/docs/content/template-clips-capture-everywhere.mdx +29 -30
  453. package/docs/content/template-clips-developers.mdx +4 -4
  454. package/docs/content/template-clips.mdx +3 -1
  455. package/package.json +2 -2
  456. package/src/eject/workspace-connections.ts +4 -0
  457. package/src/templates/chat/.agents/skills/secrets/SKILL.md +11 -4
  458. package/src/templates/chat/app/routes.ts +3 -1
  459. package/src/templates/chat/vitest.config.ts +8 -0
  460. package/src/templates/default/.agents/skills/secrets/SKILL.md +11 -4
  461. package/src/templates/default/app/routes.ts +3 -1
  462. package/src/templates/headless/.agents/skills/secrets/SKILL.md +11 -4
  463. package/src/templates/workspace-core/.agents/skills/secrets/SKILL.md +11 -4
@@ -74,6 +74,7 @@ export declare class McpOAuthClientProvider implements OAuthClientProvider {
74
74
  }
75
75
  export declare function startMcpOAuthAuthorization(options: McpOAuthProviderOptions & {
76
76
  scope?: string;
77
+ resourceMetadataUrl?: string;
77
78
  }): Promise<McpOAuthStartResult>;
78
79
  export declare function finishMcpOAuthAuthorization(options: McpOAuthProviderOptions & {
79
80
  authorizationCode: string;
@@ -99,6 +100,12 @@ export declare function getMcpOAuthConnectionState(options: {
99
100
  scopeId: string;
100
101
  serverUrl: string;
101
102
  }): Promise<OAuthCredentialState<McpOAuthCredentialBundle>>;
103
+ export declare function markMcpOAuthReconnectRequired(options: {
104
+ key: string;
105
+ scope: "user" | "org";
106
+ scopeId: string;
107
+ serverUrl: string;
108
+ }): Promise<boolean>;
102
109
  export declare function deleteMcpOAuthCredentials(options: {
103
110
  key: string;
104
111
  scope: "user" | "org";
@@ -8,7 +8,7 @@
8
8
  */
9
9
  import { auth, refreshAuthorization, validateAuthorizationResponseIssuer, } from "@modelcontextprotocol/client";
10
10
  import { ssrfSafeFetch } from "../extensions/url-safety.js";
11
- import { readOAuthCredentialState, resolveOAuthCredentialAccess, revokeOAuthCredential, saveOAuthCredential, } from "../oauth-tokens/lifecycle.js";
11
+ import { readOAuthCredentialState, resolveOAuthCredentialAccess, markOAuthReconnectRequired, revokeOAuthCredential, saveOAuthCredential, } from "../oauth-tokens/lifecycle.js";
12
12
  import { validateRemoteUrl } from "./remote-url.js";
13
13
  const TOKEN_EXPIRY_SKEW_MS = 60_000;
14
14
  const MAX_OAUTH_REDIRECTS = 5;
@@ -312,6 +312,9 @@ export async function startMcpOAuthAuthorization(options) {
312
312
  const result = await auth(provider, {
313
313
  serverUrl: options.serverUrl,
314
314
  scope: options.scope,
315
+ ...(options.resourceMetadataUrl
316
+ ? { resourceMetadataUrl: new URL(options.resourceMetadataUrl) }
317
+ : {}),
315
318
  fetchFn: guardedOAuthFetch(),
316
319
  });
317
320
  if (result !== "REDIRECT" || !provider.authorizationRedirect) {
@@ -408,6 +411,14 @@ export async function getMcpOAuthConnectionState(options) {
408
411
  validateCredential: (credential) => serverUrlsMatch(credential.serverUrl, serverUrl),
409
412
  });
410
413
  }
414
+ export async function markMcpOAuthReconnectRequired(options) {
415
+ const serverUrl = canonicalServerUrl(options.serverUrl);
416
+ return markOAuthReconnectRequired(credentialIdentity({ ...options, serverUrl }), {
417
+ allowLegacy: true,
418
+ legacyAccountKey: true,
419
+ validateCredential: (credential) => serverUrlsMatch(credential.serverUrl, serverUrl),
420
+ });
421
+ }
411
422
  export async function deleteMcpOAuthCredentials(options) {
412
423
  if (!options.serverUrl)
413
424
  return false;
@@ -1,3 +1,3 @@
1
1
  export { getOAuthTokens, getOAuthTokenSnapshot, OAuthAccountOwnedByOtherUserError, saveOAuthTokens, replaceOAuthTokensIfRevision, deleteOAuthTokens, deleteOAuthTokensIfRevision, listOAuthAccounts, listOAuthAccountsByOwner, hasOAuthTokens, setOAuthDisplayName, } from "./store.js";
2
- export { readOAuthCredentialState, resolveOAuthCredentialAccess, revokeOAuthCredential, saveOAuthCredential, type OAuthCredential, type OAuthCredentialIdentity, type OAuthCredentialOwner, type OAuthCredentialState, type OAuthRevocationResult, } from "./lifecycle.js";
2
+ export { readOAuthCredentialState, resolveOAuthCredentialAccess, markOAuthReconnectRequired, revokeOAuthCredential, saveOAuthCredential, type OAuthCredential, type OAuthCredentialIdentity, type OAuthCredentialOwner, type OAuthCredentialState, type OAuthRevocationResult, } from "./lifecycle.js";
3
3
  export { refreshExpiringGoogleTokens, startGoogleTokenRefreshLoop, } from "./google-refresh.js";
@@ -1,3 +1,3 @@
1
1
  export { getOAuthTokens, getOAuthTokenSnapshot, OAuthAccountOwnedByOtherUserError, saveOAuthTokens, replaceOAuthTokensIfRevision, deleteOAuthTokens, deleteOAuthTokensIfRevision, listOAuthAccounts, listOAuthAccountsByOwner, hasOAuthTokens, setOAuthDisplayName, } from "./store.js";
2
- export { readOAuthCredentialState, resolveOAuthCredentialAccess, revokeOAuthCredential, saveOAuthCredential, } from "./lifecycle.js";
2
+ export { readOAuthCredentialState, resolveOAuthCredentialAccess, markOAuthReconnectRequired, revokeOAuthCredential, saveOAuthCredential, } from "./lifecycle.js";
3
3
  export { refreshExpiringGoogleTokens, startGoogleTokenRefreshLoop, } from "./google-refresh.js";
@@ -67,6 +67,17 @@ export declare function readOAuthCredentialState<T extends OAuthCredential = OAu
67
67
  now?: number;
68
68
  validateCredential?: (credential: T) => boolean;
69
69
  }): Promise<OAuthCredentialState<T>>;
70
+ /**
71
+ * Force a stored credential into `reconnect_required` without a refresh attempt.
72
+ * For a token the provider rejected server-side (e.g. a 401/403) while it still
73
+ * looks valid locally, so the credential itself carries the reconnect signal
74
+ * instead of a side channel. Returns false when there is nothing to mark.
75
+ */
76
+ export declare function markOAuthReconnectRequired<T extends OAuthCredential = OAuthCredential>(identity: OAuthCredentialIdentity, options?: {
77
+ allowLegacy?: boolean;
78
+ legacyAccountKey?: boolean;
79
+ validateCredential?: (credential: T) => boolean;
80
+ }): Promise<boolean>;
70
81
  export declare function resolveOAuthCredentialAccess<T extends OAuthCredential = OAuthCredential>(identity: OAuthCredentialIdentity, options: {
71
82
  refresh: (context: OAuthRefreshContext<T>) => Promise<T>;
72
83
  allowLegacy?: boolean;
@@ -232,6 +232,23 @@ export async function readOAuthCredentialState(identity, options = {}) {
232
232
  async function markReconnectRequired(identity, snapshot, legacyAccountKey) {
233
233
  await replaceOAuthTokensIfRevision(identity.provider, storageAccountId(identity, legacyAccountKey), snapshot.storageOwner, snapshot.revision, snapshot.legacyRevision, snapshot.storageVersion, withLifecycle(identity, snapshot.credential, "refresh_failed"));
234
234
  }
235
+ /**
236
+ * Force a stored credential into `reconnect_required` without a refresh attempt.
237
+ * For a token the provider rejected server-side (e.g. a 401/403) while it still
238
+ * looks valid locally, so the credential itself carries the reconnect signal
239
+ * instead of a side channel. Returns false when there is nothing to mark.
240
+ */
241
+ export async function markOAuthReconnectRequired(identity, options = {}) {
242
+ const stored = await readStoredOAuthCredentialState(identity, {
243
+ allowLegacy: options.allowLegacy,
244
+ legacyAccountKey: options.legacyAccountKey,
245
+ validateCredential: options.validateCredential,
246
+ });
247
+ if (stored.kind === "missing" || stored.kind === "malformed")
248
+ return false;
249
+ await markReconnectRequired(identity, stored, options.legacyAccountKey === true);
250
+ return true;
251
+ }
235
252
  export async function resolveOAuthCredentialAccess(identity, options) {
236
253
  assertIdentity(identity);
237
254
  const dependencies = { ...defaultDependencies, ...options.dependencies };
@@ -318,6 +318,13 @@ export async function saveOAuthTokens(provider, accountId, tokens, owner) {
318
318
  ...(existingTokens ?? {}),
319
319
  ...cleanedIncomingTokens,
320
320
  };
321
+ const existingScope = existingTokens?.scope;
322
+ const incomingScope = cleanedIncomingTokens.scope;
323
+ if (typeof existingScope === "string" && typeof incomingScope === "string") {
324
+ tokensToStore.scope = Array.from(new Set(`${existingScope} ${incomingScope}`
325
+ .split(/[\s,]+/)
326
+ .filter((scope) => scope.length > 0))).join(" ");
327
+ }
321
328
  const result = await client.execute({
322
329
  sql: isPostgres()
323
330
  ? `INSERT INTO ${table} (provider, account_id, owner, display_name, tokens, updated_at, revision) VALUES (?, ?, ?, ?, ?, ?, ?) ON CONFLICT (provider, account_id) DO UPDATE SET owner=EXCLUDED.owner, display_name=COALESCE(EXCLUDED.display_name, ${table}.display_name), tokens=EXCLUDED.tokens, updated_at=EXCLUDED.updated_at, revision=GREATEST(COALESCE(${table}.revision, 0) + 1, EXCLUDED.revision) WHERE ${table}.owner = EXCLUDED.owner OR (LOWER(${table}.owner) = LOWER(EXCLUDED.owner) AND LOWER(${table}.owner) LIKE 'user:%' AND LOWER(EXCLUDED.owner) LIKE 'user:%')`
@@ -12,6 +12,18 @@
12
12
  * PostHog's `$session_id`: the latter is the browser session used for session
13
13
  * replay, and the two are different lifetimes.
14
14
  *
15
+ * PostHog DERIVES a trace's latency, tokens and cost from its children — its
16
+ * trace query sums `$ai_latency` over every event whose `$ai_parent_id` is the
17
+ * trace or absent, and sums tokens/cost over `$ai_generation` / `$ai_embedding`
18
+ * only. So the `$ai_trace` event carries none of those: an `$ai_latency` here
19
+ * was counted *in addition to* the generation's and reported roughly twice the
20
+ * real duration. Run totals ride along under plain names for the non-PostHog
21
+ * backends, which have no such aggregation.
22
+ *
23
+ * Custom properties do NOT take an `$ai_` prefix. That namespace is PostHog's
24
+ * schema, and a name it does not define today it may define tomorrow with
25
+ * different meaning — `input_truncated` / `spans_dropped` cannot collide.
26
+ *
15
27
  * Content (`$ai_input` / `$ai_output_choices` / `$ai_input_state` /
16
28
  * `$ai_output_state`) is gated on config and always OMITTED when disabled.
17
29
  * Sending `[]` instead would be indistinguishable from a run that genuinely had
@@ -49,7 +61,9 @@ export interface AiTraceEventInput {
49
61
  spanName: string;
50
62
  model: string;
51
63
  provider: string;
52
- latencySeconds: number;
64
+ /** Wall-clock duration of the whole run. Reported under `duration_ms`, not
65
+ * `$ai_latency` — see the aggregation note at the top of this file. */
66
+ durationMs: number;
53
67
  isError: boolean;
54
68
  error?: AiErrorDetail;
55
69
  inputTokens?: number;
@@ -12,6 +12,18 @@
12
12
  * PostHog's `$session_id`: the latter is the browser session used for session
13
13
  * replay, and the two are different lifetimes.
14
14
  *
15
+ * PostHog DERIVES a trace's latency, tokens and cost from its children — its
16
+ * trace query sums `$ai_latency` over every event whose `$ai_parent_id` is the
17
+ * trace or absent, and sums tokens/cost over `$ai_generation` / `$ai_embedding`
18
+ * only. So the `$ai_trace` event carries none of those: an `$ai_latency` here
19
+ * was counted *in addition to* the generation's and reported roughly twice the
20
+ * real duration. Run totals ride along under plain names for the non-PostHog
21
+ * backends, which have no such aggregation.
22
+ *
23
+ * Custom properties do NOT take an `$ai_` prefix. That namespace is PostHog's
24
+ * schema, and a name it does not define today it may define tomorrow with
25
+ * different meaning — `input_truncated` / `spans_dropped` cannot collide.
26
+ *
15
27
  * Content (`$ai_input` / `$ai_output_choices` / `$ai_input_state` /
16
28
  * `$ai_output_state`) is gated on config and always OMITTED when disabled.
17
29
  * Sending `[]` instead would be indistinguishable from a run that genuinely had
@@ -26,7 +38,7 @@ import { boundedText } from "../tracking/redaction.js";
26
38
  export const MAX_AI_CONTENT_BYTES = 128 * 1024;
27
39
  /** Hard ceiling on emitted `$ai_span` events per run. */
28
40
  export const MAX_AI_SPANS_PER_RUN = 100;
29
- function trackAiEvent(name, properties, userId) {
41
+ function trackAiEvent(name, properties, userId, occurredAt) {
30
42
  for (const key of Object.keys(properties)) {
31
43
  if (properties[key] === undefined)
32
44
  delete properties[key];
@@ -34,7 +46,7 @@ function trackAiEvent(name, properties, userId) {
34
46
  try {
35
47
  void import("../tracking/registry.js")
36
48
  .then(({ track }) => {
37
- track(name, properties, { userId: userId ?? undefined });
49
+ track(name, properties, { userId: userId ?? undefined, occurredAt });
38
50
  })
39
51
  .catch(() => { });
40
52
  // coercion-ok: a throw here would break the run it is observing
@@ -84,19 +96,19 @@ export function emitAiTraceEvent(input) {
84
96
  $ai_span_name: input.spanName,
85
97
  $ai_model: input.model,
86
98
  $ai_provider: input.provider,
87
- $ai_latency: input.latencySeconds,
88
99
  $ai_is_error: input.isError,
89
100
  $ai_error: input.error,
90
- $ai_input_tokens: input.inputTokens,
91
- $ai_output_tokens: input.outputTokens,
92
- $ai_total_cost_usd: input.costUsd,
101
+ duration_ms: Math.round(input.durationMs),
102
+ input_tokens: input.inputTokens,
103
+ output_tokens: input.outputTokens,
104
+ cost_usd: input.costUsd,
93
105
  $ai_input_state: inputContent?.value,
94
106
  $ai_output_state: outputContent?.value,
95
- $ai_input_truncated: inputContent?.truncated || undefined,
96
- $ai_output_truncated: outputContent?.truncated || undefined,
107
+ input_truncated: inputContent?.truncated || undefined,
108
+ output_truncated: outputContent?.truncated || undefined,
97
109
  $session_id: input.browserSessionId,
98
110
  created_at: new Date(input.createdAt).toISOString(),
99
- }, input.userId);
111
+ }, input.userId, input.createdAt);
100
112
  }
101
113
  export function emitAiSpanEvent(input) {
102
114
  const inputContent = input.inputState === undefined
@@ -117,11 +129,11 @@ export function emitAiSpanEvent(input) {
117
129
  $ai_error: input.error,
118
130
  $ai_input_state: inputContent?.value,
119
131
  $ai_output_state: outputContent?.value,
120
- $ai_input_truncated: inputContent?.truncated || undefined,
121
- $ai_output_truncated: outputContent?.truncated || undefined,
132
+ input_truncated: inputContent?.truncated || undefined,
133
+ output_truncated: outputContent?.truncated || undefined,
122
134
  $session_id: input.browserSessionId,
123
135
  created_at: new Date(input.createdAt).toISOString(),
124
- }, input.userId);
136
+ }, input.userId, input.createdAt);
125
137
  }
126
138
  /**
127
139
  * Emit PostHog's documented manual feedback event for an LLM trace.
@@ -24,6 +24,37 @@ function llmProviderFromEngine(engineName, model) {
24
24
  function costUsdFromCenticents(value) {
25
25
  return Math.round((value / 10_000) * 1_000_000) / 1_000_000;
26
26
  }
27
+ /**
28
+ * Wall-clock time covered by these intervals, counting overlap once.
29
+ *
30
+ * Tools run concurrently, so summing durations reports more elapsed time than
31
+ * actually passed — enough to drive a derived remainder to zero on a parallel
32
+ * fan-out.
33
+ */
34
+ function coveredDurationMs(intervals) {
35
+ if (intervals.length === 0)
36
+ return 0;
37
+ const sorted = [...intervals].sort((a, b) => a.start - b.start);
38
+ let covered = 0;
39
+ let { start: openStart, end: openEnd } = sorted[0];
40
+ for (const { start, end } of sorted.slice(1)) {
41
+ if (start > openEnd) {
42
+ covered += openEnd - openStart;
43
+ openStart = start;
44
+ openEnd = end;
45
+ }
46
+ else if (end > openEnd) {
47
+ openEnd = end;
48
+ }
49
+ }
50
+ return covered + (openEnd - openStart);
51
+ }
52
+ function spanIntervals(spans) {
53
+ return spans.map((s) => ({
54
+ start: s.createdAt,
55
+ end: s.createdAt + Math.max(0, s.durationMs),
56
+ }));
57
+ }
27
58
  /**
28
59
  * Project run metadata onto flat PostHog trace properties.
29
60
  *
@@ -144,7 +175,7 @@ function emitLlmGenerationTrackingEvent(args) {
144
175
  $ai_provider: provider,
145
176
  $ai_input_tokens: args.inputTokens,
146
177
  $ai_output_tokens: args.outputTokens,
147
- $ai_latency: Math.round((args.durationMs / 1000) * 1000) / 1000,
178
+ $ai_latency: Math.round(args.llmDurationMs) / 1000,
148
179
  $ai_is_error: args.status === "error",
149
180
  $ai_error: args.status === "error"
150
181
  ? toAiErrorDetail(error, {
@@ -153,16 +184,24 @@ function emitLlmGenerationTrackingEvent(args) {
153
184
  retryable: terminalRetryable,
154
185
  })
155
186
  : undefined,
187
+ // Every engine here streams (`messages.stream`, `streamText`, gateway SSE),
188
+ // which is also what makes `$ai_time_to_first_token` meaningful.
189
+ $ai_stream: true,
156
190
  $ai_cache_read_input_tokens: args.cacheReadTokens,
157
191
  $ai_cache_creation_input_tokens: args.cacheWriteTokens,
158
- $ai_request_count: 1,
192
+ $ai_request_count: args.llmCallCount,
159
193
  $ai_total_cost_usd: costUsd,
160
194
  $ai_input: args.aiInput,
161
195
  $ai_output_choices: args.aiOutputChoices,
162
196
  $ai_tools: args.aiTools,
163
- $ai_input_truncated: args.aiInputTruncated || undefined,
164
- $ai_output_truncated: args.aiOutputTruncated || undefined,
165
- $ai_time_to_first_token: args.firstTokenMs,
197
+ input_truncated: args.aiInputTruncated || undefined,
198
+ output_truncated: args.aiOutputTruncated || undefined,
199
+ latency_source: args.llmDurationMeasured ? "measured" : "derived",
200
+ // Seconds, per PostHog's schema — `time_to_first_token_ms` above is the
201
+ // millisecond field this framework's own dashboards read.
202
+ $ai_time_to_first_token: args.firstTokenMs === undefined
203
+ ? undefined
204
+ : Math.round(args.firstTokenMs) / 1000,
166
205
  $session_id: args.browserSessionId,
167
206
  };
168
207
  if (args.experimentAssignments?.length) {
@@ -188,6 +227,7 @@ function emitLlmGenerationTrackingEvent(args) {
188
227
  .then(({ track }) => {
189
228
  track("$ai_generation", properties, {
190
229
  userId: args.userId ?? undefined,
230
+ occurredAt: args.createdAt,
191
231
  });
192
232
  })
193
233
  .catch(() => { });
@@ -212,6 +252,10 @@ function emitLlmGenerationTrackingEvent(args) {
212
252
  */
213
253
  function buildGenerationContent(args) {
214
254
  const { config } = args;
255
+ // `$ai_input` is the conversation, not the system prompt. PostHog accepts a
256
+ // `system` role, but the prompt is app configuration rather than content and
257
+ // is near-identical on every run — shipping it would repeat kilobytes on each
258
+ // generation for no analytical gain.
215
259
  const input = config.capturePrompts
216
260
  ? boundAiContent(redactSensitiveFields(args.messages))
217
261
  : undefined;
@@ -364,6 +408,13 @@ export async function instrumentAgentLoop(opts) {
364
408
  let toolCallCount = 0;
365
409
  let successfulTools = 0;
366
410
  let failedTools = 0;
411
+ // One `model_stream` start/end bracket is emitted per LLM round-trip, and it
412
+ // closes before any tool of that turn is started — so these intervals ARE the
413
+ // model's wall clock, not an estimate of it. Recording them is what lets the
414
+ // generation report a measured `$ai_latency` instead of backing tool time out
415
+ // of the run duration.
416
+ const modelStreamIntervals = [];
417
+ let modelStreamOpenedAt = null;
367
418
  // Track in-flight OTel tool spans so they're all ended even if the loop
368
419
  // throws before a matching `tool_done` arrives.
369
420
  const openOtelToolSpans = new Set();
@@ -447,6 +498,20 @@ export async function instrumentAgentLoop(opts) {
447
498
  runStatus = "error";
448
499
  errorMessage = "Missing API key";
449
500
  }
501
+ if (event.type === "model_stream") {
502
+ // The emitter brackets these itself, so a repeated start or an
503
+ // unmatched end is a no-op here rather than a fabricated interval.
504
+ if (event.status === "start") {
505
+ modelStreamOpenedAt ??= Date.now();
506
+ }
507
+ else if (modelStreamOpenedAt !== null) {
508
+ modelStreamIntervals.push({
509
+ start: modelStreamOpenedAt,
510
+ end: Date.now(),
511
+ });
512
+ modelStreamOpenedAt = null;
513
+ }
514
+ }
450
515
  if (event.type === "tool_start") {
451
516
  const counter = toolInvocationCounter++;
452
517
  const sid = spanId();
@@ -563,6 +628,25 @@ export async function instrumentAgentLoop(opts) {
563
628
  else if (pending) {
564
629
  pending.endResult = otelEndResult;
565
630
  }
631
+ const spanMetadataFields = {};
632
+ if (config.captureToolArgs && pending) {
633
+ // Strip Authorization/api-key/token-shaped values before persisting
634
+ // (M14 in the MCP/A2A audit). Tool-runtime execution still sees the
635
+ // unredacted input — only the long-lived span row is sanitized.
636
+ spanMetadataFields.input = redactSensitiveFields(pending.input);
637
+ }
638
+ // A failed tool's content reaches the span through `errorMessage`; a
639
+ // successful one had nowhere to go, so every healthy tool span shipped
640
+ // an input and no output — indistinguishable from a tool that returned
641
+ // nothing. Same redaction and truncation as the error path.
642
+ if (!isError &&
643
+ config.captureToolResults &&
644
+ typeof event.result === "string") {
645
+ spanMetadataFields.output = truncateToolErrorMessage(redactToolErrorMessage(event.result));
646
+ }
647
+ const spanMetadata = Object.keys(spanMetadataFields).length
648
+ ? spanMetadataFields
649
+ : null;
566
650
  const span = {
567
651
  id: pending?.spanId ?? spanId(),
568
652
  runId,
@@ -579,16 +663,11 @@ export async function instrumentAgentLoop(opts) {
579
663
  durationMs: pending ? Math.max(0, finishedAt - pending.startMs) : 0,
580
664
  status: isError ? "error" : "success",
581
665
  errorMessage: isError ? event.result : null,
582
- metadata: config.captureToolArgs && pending
583
- ? // Strip Authorization/api-key/token-shaped values before
584
- // persisting (M14 in the MCP/A2A audit). Tool-runtime
585
- // execution still sees the unredacted input — only the
586
- // long-lived span row is sanitized.
587
- {
588
- input: redactSensitiveFields(pending.input),
589
- }
590
- : null,
591
- createdAt: Date.now(),
666
+ metadata: spanMetadata,
667
+ // The span's start, not its completion: `durationMs` is measured from
668
+ // here, so stamping the end instead places the tool after the run
669
+ // ended in any timeline that plots start + duration.
670
+ createdAt: pending?.startMs ?? finishedAt,
592
671
  };
593
672
  spans.push(span);
594
673
  }
@@ -629,6 +708,19 @@ export async function instrumentAgentLoop(opts) {
629
708
  try {
630
709
  const runEnd = Date.now();
631
710
  const totalDurationMs = runEnd - runStart;
711
+ // The loop threw or was killed mid-stream, so no `end` ever arrived. The
712
+ // model was still running when the run stopped, so the interval closes at
713
+ // the run's end rather than being dropped.
714
+ if (modelStreamOpenedAt !== null) {
715
+ modelStreamIntervals.push({ start: modelStreamOpenedAt, end: runEnd });
716
+ modelStreamOpenedAt = null;
717
+ }
718
+ // Undefined means the engine never bracketed its model calls, NOT that
719
+ // the model took no time — the two must stay distinguishable, because
720
+ // only the first may fall back to backing tool time out of the run.
721
+ const measuredModelDurationMs = modelStreamIntervals.length
722
+ ? coveredDurationMs(modelStreamIntervals)
723
+ : undefined;
632
724
  if (pendingTools.size > 0) {
633
725
  if (runStatus === "success") {
634
726
  runStatus = "error";
@@ -681,7 +773,7 @@ export async function instrumentAgentLoop(opts) {
681
773
  status: "error",
682
774
  errorMessage: interruptedMessage,
683
775
  metadata: null,
684
- createdAt: runEnd,
776
+ createdAt: pending.startMs,
685
777
  });
686
778
  }
687
779
  pendingTools.clear();
@@ -712,6 +804,15 @@ export async function instrumentAgentLoop(opts) {
712
804
  message: `Agent run was cut off before finishing (${cutOffReason}).`,
713
805
  }
714
806
  : undefined);
807
+ const collectedToolSpans = spans.filter((s) => s.spanType === "tool_call");
808
+ // Resolved before the generation event, not just before the span events:
809
+ // the generation's latency is the run minus the tool time PostHog will
810
+ // actually see, so it has to be computed against the same set. Tools
811
+ // dropped by `captureLlmSpans` or the per-run cap have no sibling span to
812
+ // hold their time, and subtracting them would lose it from the trace.
813
+ const emittedToolSpans = (config.captureLlmSpans ? collectedToolSpans : []).slice(0, MAX_AI_SPANS_PER_RUN);
814
+ const droppedToolSpans = (config.captureLlmSpans ? collectedToolSpans.length : 0) -
815
+ emittedToolSpans.length;
715
816
  let llmCallCount = 0;
716
817
  if (usage || runStatus === "error") {
717
818
  llmCallCount =
@@ -736,12 +837,23 @@ export async function instrumentAgentLoop(opts) {
736
837
  ? Math.max(0, usage.firstEngineEventAtMs - runStart)
737
838
  : undefined;
738
839
  const llmSpanId = spanId();
840
+ const generationToolSpans = collectedToolSpans;
841
+ // Measured model time when the engine bracketed its round-trips.
842
+ //
843
+ // The fallback backs tool time out of the run instead, which is an
844
+ // estimate and behaves like one: it has to net out overlapping tools,
845
+ // skip tools PostHog will not receive, and clamp at zero. Engines that
846
+ // report `model_stream` need none of that, so `latency_source` records
847
+ // which of the two a given `$ai_latency` came from.
848
+ const llmDurationMs = measuredModelDurationMs ??
849
+ Math.max(0, totalDurationMs -
850
+ coveredDurationMs(spanIntervals(emittedToolSpans)));
739
851
  const generationContent = buildGenerationContent({
740
852
  config,
741
853
  messages: loopOpts.messages,
742
854
  tools: loopOpts.tools,
743
855
  assistantText: assistantTextParts.join(""),
744
- toolSpans: spans.filter((s) => s.spanType === "tool_call"),
856
+ toolSpans: generationToolSpans,
745
857
  });
746
858
  const llmSpan = {
747
859
  id: llmSpanId,
@@ -785,6 +897,9 @@ export async function instrumentAgentLoop(opts) {
785
897
  : undefined,
786
898
  costCentsX100: usageReported ? costCentsX100 : undefined,
787
899
  durationMs: totalDurationMs,
900
+ llmDurationMs,
901
+ llmDurationMeasured: measuredModelDurationMs !== undefined,
902
+ llmCallCount,
788
903
  firstTokenMs,
789
904
  status: runStatus,
790
905
  errorMessage,
@@ -844,11 +959,22 @@ export async function instrumentAgentLoop(opts) {
844
959
  const provider = llmProviderFromEngine(typeof loopOpts.engine?.name === "string"
845
960
  ? loopOpts.engine.name
846
961
  : undefined, usage?.model ?? loopOpts.model);
847
- const toolSpans = config.captureLlmSpans
848
- ? spans.filter((s) => s.spanType === "tool_call")
849
- : [];
850
- const emittedToolSpans = toolSpans.slice(0, MAX_AI_SPANS_PER_RUN);
851
- const droppedToolSpans = toolSpans.length - emittedToolSpans.length;
962
+ // PostHog reads a trace's input/output state ONLY from the `$ai_trace`
963
+ // event — never from its children — so a trace whose detail view should
964
+ // show what the run was asked and what it answered has to carry them
965
+ // here. Gated on `capturePrompts` and omitted, not emptied, when off.
966
+ const traceInputState = config.capturePrompts
967
+ ? redactSensitiveFields(loopOpts.messages)
968
+ : undefined;
969
+ const traceAssistantText = assistantTextParts.join("");
970
+ const traceOutputState = config.capturePrompts && traceAssistantText
971
+ ? [
972
+ {
973
+ role: "assistant",
974
+ content: redactToolErrorMessage(traceAssistantText),
975
+ },
976
+ ]
977
+ : undefined;
852
978
  emitAiTraceEvent({
853
979
  runId,
854
980
  threadId,
@@ -856,7 +982,7 @@ export async function instrumentAgentLoop(opts) {
856
982
  spanName,
857
983
  model: usage?.model ?? loopOpts.model,
858
984
  provider,
859
- latencySeconds: Math.round(totalDurationMs) / 1000,
985
+ durationMs: totalDurationMs,
860
986
  isError: runStatus === "error",
861
987
  error: aiError,
862
988
  inputTokens: usage?.usageReported ? usage.inputTokens : undefined,
@@ -866,6 +992,8 @@ export async function instrumentAgentLoop(opts) {
866
992
  : undefined,
867
993
  createdAt: runStart,
868
994
  browserSessionId,
995
+ inputState: traceInputState,
996
+ outputState: traceOutputState,
869
997
  extraProperties: {
870
998
  ...trackingIdentityProperties(),
871
999
  source: "agent_observability",
@@ -879,8 +1007,8 @@ export async function instrumentAgentLoop(opts) {
879
1007
  // A truncated run must not read as a complete one.
880
1008
  ...(droppedToolSpans > 0
881
1009
  ? {
882
- $ai_spans_dropped: droppedToolSpans,
883
- $ai_spans_emitted: emittedToolSpans.length,
1010
+ spans_dropped: droppedToolSpans,
1011
+ spans_emitted: emittedToolSpans.length,
884
1012
  }
885
1013
  : {}),
886
1014
  },
@@ -911,10 +1039,12 @@ export async function instrumentAgentLoop(opts) {
911
1039
  : undefined,
912
1040
  createdAt: span.createdAt,
913
1041
  browserSessionId,
914
- // `metadata.input` is already redacted and only present when
915
- // `captureToolArgs` is on; absent stays absent.
1042
+ // `metadata.input` / `metadata.output` are already redacted and
1043
+ // only present when `captureToolArgs` / `captureToolResults` are
1044
+ // on; absent stays absent.
916
1045
  inputState: span.metadata?.input,
917
- outputState: toolErrorMessage,
1046
+ outputState: toolErrorMessage ??
1047
+ span.metadata?.output,
918
1048
  extraProperties: {
919
1049
  ...trackingIdentityProperties(),
920
1050
  source: "agent_observability",
@@ -292,8 +292,8 @@ const PROFILES = {
292
292
  label: "Gmail",
293
293
  required: true,
294
294
  builderIncluded: false,
295
- keySummary: "Google OAuth client ID and secret",
296
- why: "Mail needs OAuth access to read, send, and organize the mailbox.",
295
+ keySummary: "Connect Gmail with OAuth",
296
+ why: "Mail uses the workspace's managed Google connection; no key is pasted here.",
297
297
  },
298
298
  {
299
299
  id: "attachment-storage",
@@ -13,6 +13,7 @@ import { deleteCookie, defineEventHandler, getCookie, getMethod, getQuery, setRe
13
13
  import { appStateGet, appStatePut } from "../application-state/store.js";
14
14
  import { getOrgContext } from "../org/context.js";
15
15
  import { getSession } from "../server/auth.js";
16
+ import { CredentialStoreUnavailableError } from "../server/credential-provider.js";
16
17
  import { awaitBootstrap, getH3App, markDefaultPluginProvided, } from "../server/framework-request-handler.js";
17
18
  import { runWithRequestContext } from "../server/request-context.js";
18
19
  import { FIRST_RUN_ONBOARDING_COMPLETED_KEY, FIRST_RUN_ONBOARDING_COOKIE, FIRST_RUN_ONBOARDING_ELIGIBLE_KEY, } from "../shared/first-run-onboarding.js";
@@ -57,7 +58,11 @@ async function serializeSteps(context, options = {}) {
57
58
  // chain of credential/settings reads — walking them one at a time made this
58
59
  // route cost the SUM of every step's round trips against a remote database
59
60
  // instead of the slowest one. `Promise.all` preserves `steps` order.
60
- return Promise.all(steps.map(async (step) => {
61
+ const serialized = await Promise.all(steps.map(async (step) => {
62
+ if (!options.preview && step.isAvailable) {
63
+ if (!(await step.isAvailable(context)))
64
+ return null;
65
+ }
61
66
  let complete = false;
62
67
  if (!options.preview) {
63
68
  try {
@@ -80,6 +85,7 @@ async function serializeSteps(context, options = {}) {
80
85
  methods: step.methods,
81
86
  };
82
87
  }));
88
+ return serialized.filter((step) => step !== null);
83
89
  }
84
90
  function withOnboardingRequestContext(context, fn) {
85
91
  return runWithRequestContext({
@@ -180,7 +186,9 @@ export function createOnboardingPlugin(options = {}) {
180
186
  };
181
187
  });
182
188
  }
183
- catch {
189
+ catch (error) {
190
+ if (error instanceof CredentialStoreUnavailableError)
191
+ throw error;
184
192
  return { dismissed: false, allComplete: false };
185
193
  }
186
194
  }));
@@ -66,6 +66,8 @@ export interface OnboardingStep {
66
66
  /** Required steps block onboarding dismissal when incomplete. */
67
67
  required?: boolean;
68
68
  methods: OnboardingMethod[];
69
+ /** Hide the step when its backing capability is not configured. */
70
+ isAvailable?: (context?: OnboardingResolveContext) => boolean | Promise<boolean>;
69
71
  /** Resolver — called on every `GET /_agent-native/onboarding/steps` request. */
70
72
  isComplete: (context?: OnboardingResolveContext) => boolean | Promise<boolean>;
71
73
  }
@@ -93,8 +93,8 @@ export declare function createCustomProviderRegistrationAction<TSchema extends Z
93
93
  label?: undefined;
94
94
  message?: undefined;
95
95
  } | {
96
- id?: undefined;
97
96
  count?: undefined;
97
+ id?: undefined;
98
98
  deleted?: undefined;
99
99
  providers?: undefined;
100
100
  found: boolean;