@agent-native/core 0.132.1 → 0.133.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 (456) hide show
  1. package/corpus/README.md +2 -2
  2. package/corpus/core/CHANGELOG.md +198 -0
  3. package/corpus/core/package.json +1 -1
  4. package/corpus/core/src/a2a/correlation.ts +11 -1
  5. package/corpus/core/src/a2a/types.ts +11 -3
  6. package/corpus/core/src/agent/engine/ai-sdk-engine.ts +33 -46
  7. package/corpus/core/src/agent/engine/builder-engine.ts +22 -10
  8. package/corpus/core/src/agent/engine/error-detail.ts +184 -3
  9. package/corpus/core/src/agent/engine/failure-taxonomy.ts +123 -0
  10. package/corpus/core/src/agent/engine/index.ts +8 -0
  11. package/corpus/core/src/agent/engine/registry.ts +92 -8
  12. package/corpus/core/src/agent/engine/translate-ai-sdk.ts +17 -2
  13. package/corpus/core/src/agent/production-agent.ts +13 -33
  14. package/corpus/core/src/agent/run-loop-with-resume.ts +1 -1
  15. package/corpus/core/src/agent/run-manager.ts +43 -14
  16. package/corpus/core/src/agent/run-store.ts +30 -3
  17. package/corpus/core/src/agent/thread-data-builder.ts +36 -4
  18. package/corpus/core/src/chat-threads/store.ts +42 -0
  19. package/corpus/core/src/cli/templates-meta.ts +13 -0
  20. package/corpus/core/src/cli/workspace-dev.ts +1 -0
  21. package/corpus/core/src/client/error-format.ts +12 -0
  22. package/corpus/core/src/client/use-chat-threads.ts +76 -16
  23. package/corpus/core/src/credentials/index.ts +51 -12
  24. package/corpus/core/src/extensions/url-safety.ts +46 -12
  25. package/corpus/core/src/integrations/adapters/slack.ts +32 -10
  26. package/corpus/core/src/integrations/google-docs-poller.ts +12 -1
  27. package/corpus/core/src/integrations/installations-store.ts +30 -0
  28. package/corpus/core/src/integrations/plugin.ts +5 -5
  29. package/corpus/core/src/integrations/types.ts +7 -0
  30. package/corpus/core/src/integrations/webhook-handler.ts +24 -1
  31. package/corpus/core/src/jobs/background-automation-runner.ts +38 -1
  32. package/corpus/core/src/provider-api/index.ts +8 -2
  33. package/corpus/core/src/scripts/call-agent.ts +6 -0
  34. package/corpus/core/src/server/agent-chat-plugin.ts +46 -10
  35. package/corpus/core/src/server/agent-discovery.ts +2 -0
  36. package/corpus/core/src/server/builder-design-systems.ts +21 -0
  37. package/corpus/core/src/server/credential-provider.ts +51 -12
  38. package/corpus/core/src/server/index.ts +1 -0
  39. package/corpus/core/src/server/onboarding-html.ts +37 -2
  40. package/corpus/core/src/shared/reasoning-effort.ts +1 -1
  41. package/corpus/core/src/templates/workspace-core/.agents/skills/a2a-protocol/SKILL.md +11 -0
  42. package/corpus/templates/analytics/app/components/layout/Sidebar.tsx +6 -2
  43. package/corpus/templates/assets/app/components/layout/Sidebar.tsx +39 -19
  44. package/corpus/templates/assets/changelog/2026-07-31-the-agent-native-logo-stays-visible-when-the-sidebar-is-coll.md +6 -0
  45. package/corpus/templates/brain/app/components/layout/Sidebar.tsx +30 -3
  46. package/corpus/templates/brain/changelog/2026-07-31-clicking-the-agent-native-logo-now-toggles-the-app-sidebar.md +6 -0
  47. package/corpus/templates/calendar/app/components/layout/AppLayout.tsx +1 -1
  48. package/corpus/templates/calendar/app/components/layout/Sidebar.tsx +54 -25
  49. package/corpus/templates/calendar/changelog/2026-07-31-the-agent-native-logo-stays-visible-when-the-sidebar-is-coll.md +6 -0
  50. package/corpus/templates/chat/app/components/layout/Sidebar.tsx +30 -3
  51. package/corpus/templates/chat/changelog/2026-07-31-clicking-the-agent-native-logo-now-toggles-the-app-sidebar.md +6 -0
  52. package/corpus/templates/clips/app/components/library/library-layout.tsx +37 -21
  53. package/corpus/templates/clips/changelog/2026-07-30-meeting-microphone-transcription-works-reliably-from-the-fir.md +6 -0
  54. package/corpus/templates/clips/changelog/2026-07-31-the-agent-native-logo-stays-visible-when-the-sidebar-is-coll.md +6 -0
  55. package/corpus/templates/clips/desktop/src/hooks/useMediaDevices.ts +1 -1
  56. package/corpus/templates/clips/desktop/src/lib/media-capture-constraints.ts +1 -1
  57. package/corpus/templates/clips/desktop/src-tauri/src/native_screen/custom_capture.rs +13 -0
  58. package/corpus/templates/clips/desktop/src-tauri/src/native_screen.rs +2 -0
  59. package/corpus/templates/clips/desktop/src-tauri/src/system_audio.rs +25 -132
  60. package/corpus/templates/content/app/components/sidebar/DocumentSidebar.tsx +34 -17
  61. package/corpus/templates/content/changelog/2026-07-31-the-agent-native-logo-stays-visible-when-the-sidebar-is-coll.md +6 -0
  62. package/corpus/templates/design/.agents/skills/design-systems/SKILL.md +6 -2
  63. package/corpus/templates/design/.generated/bridge/editor-chrome.generated.ts +5 -0
  64. package/corpus/templates/design/actions/create-design-system.ts +1 -0
  65. package/corpus/templates/design/actions/set-default-design-system.ts +34 -26
  66. package/corpus/templates/design/app/components/design/KeyboardShortcutsPanel.tsx +5 -3
  67. package/corpus/templates/design/app/components/design/bridge/editor-chrome.bridge.ts +23 -0
  68. package/corpus/templates/design/app/components/design/keyboard-shortcuts.ts +3 -0
  69. package/corpus/templates/design/app/components/layout/Sidebar.tsx +21 -4
  70. package/corpus/templates/design/app/hooks/useDesignHotkeys.ts +11 -7
  71. package/corpus/templates/design/app/i18n-data.ts +39 -0
  72. package/corpus/templates/design/app/pages/DesignSystemSetup.tsx +229 -12
  73. package/corpus/templates/design/app/pages/DesignSystems.tsx +10 -4
  74. package/corpus/templates/design/changelog/2026-07-30-fixed-the-keyboard-shortcuts-panel-not-opening-with-ctrl-shi.md +6 -0
  75. package/corpus/templates/design/changelog/2026-07-31-clicking-the-agent-native-logo-now-toggles-the-app-sidebar.md +6 -0
  76. package/corpus/templates/design/changelog/2026-07-31-design-system-indexing-keeps-your-chosen-name-when-you-uploa.md +6 -0
  77. package/corpus/templates/design/server/lib/builder-design-system-proxy.ts +19 -4
  78. package/corpus/templates/dispatch/AGENTS.md +4 -0
  79. package/corpus/templates/factory/.agents/skills/actions/SKILL.md +562 -0
  80. package/corpus/templates/factory/.agents/skills/adding-a-feature/SKILL.md +198 -0
  81. package/corpus/templates/factory/.agents/skills/agent-native-docs/SKILL.md +115 -0
  82. package/corpus/templates/factory/.agents/skills/agent-native-toolkit/SKILL.md +182 -0
  83. package/corpus/templates/factory/.agents/skills/capture-learnings/SKILL.md +89 -0
  84. package/corpus/templates/factory/.agents/skills/create-skill/SKILL.md +221 -0
  85. package/corpus/templates/factory/.agents/skills/customizing-agent-native/SKILL.md +220 -0
  86. package/corpus/templates/factory/.agents/skills/delegate-to-agent/SKILL.md +263 -0
  87. package/corpus/templates/factory/.agents/skills/factory-graphs/SKILL.md +52 -0
  88. package/corpus/templates/factory/.agents/skills/feature-flags/SKILL.md +169 -0
  89. package/corpus/templates/factory/.agents/skills/frontend-design/SKILL.md +174 -0
  90. package/corpus/templates/factory/.agents/skills/real-time-sync/SKILL.md +232 -0
  91. package/corpus/templates/factory/.agents/skills/security/SKILL.md +324 -0
  92. package/corpus/templates/factory/.agents/skills/self-modifying-code/SKILL.md +119 -0
  93. package/corpus/templates/factory/.agents/skills/shadcn-ui/SKILL.md +123 -0
  94. package/corpus/templates/factory/.agents/skills/sharing/SKILL.md +232 -0
  95. package/corpus/templates/factory/.agents/skills/storing-data/SKILL.md +178 -0
  96. package/corpus/templates/factory/.agents/skills/upgrade-agent-native/SKILL.md +122 -0
  97. package/corpus/templates/factory/.env.example +24 -0
  98. package/corpus/templates/factory/.ignore +0 -0
  99. package/corpus/templates/factory/.oxfmtrc.json +8 -0
  100. package/corpus/templates/factory/AGENTS.md +90 -0
  101. package/corpus/templates/factory/CHANGELOG.md +10 -0
  102. package/corpus/templates/factory/DEVELOPING.md +185 -0
  103. package/corpus/templates/factory/README.md +64 -0
  104. package/corpus/templates/factory/_gitignore +42 -0
  105. package/corpus/templates/factory/actions/add-factory-comment.ts +55 -0
  106. package/corpus/templates/factory/actions/approve-factory-item.ts +214 -0
  107. package/corpus/templates/factory/actions/babysit-pull-request.ts +126 -0
  108. package/corpus/templates/factory/actions/evaluate-triage-item.ts +172 -0
  109. package/corpus/templates/factory/actions/get-factory-graph.ts +62 -0
  110. package/corpus/templates/factory/actions/get-triage-config.ts +42 -0
  111. package/corpus/templates/factory/actions/get-triage-item.ts +74 -0
  112. package/corpus/templates/factory/actions/hello.ts +13 -0
  113. package/corpus/templates/factory/actions/ingest-github-observation.ts +100 -0
  114. package/corpus/templates/factory/actions/list-factories.ts +40 -0
  115. package/corpus/templates/factory/actions/list-factory-comments.ts +40 -0
  116. package/corpus/templates/factory/actions/list-triage-items.ts +85 -0
  117. package/corpus/templates/factory/actions/list-triage-rules.ts +44 -0
  118. package/corpus/templates/factory/actions/navigate.ts +41 -0
  119. package/corpus/templates/factory/actions/poll-slack-channel.ts +118 -0
  120. package/corpus/templates/factory/actions/reconcile-triage-run.ts +179 -0
  121. package/corpus/templates/factory/actions/record-triage-feedback.ts +58 -0
  122. package/corpus/templates/factory/actions/run.ts +2 -0
  123. package/corpus/templates/factory/actions/save-factory-graph.ts +129 -0
  124. package/corpus/templates/factory/actions/save-triage-config.ts +67 -0
  125. package/corpus/templates/factory/actions/save-triage-rule.ts +89 -0
  126. package/corpus/templates/factory/actions/suggest-factory-rules.ts +70 -0
  127. package/corpus/templates/factory/actions/view-screen.ts +73 -0
  128. package/corpus/templates/factory/app/components/factory/FactoryCanvas.tsx +441 -0
  129. package/corpus/templates/factory/app/components/factory/FactoryInspector.tsx +388 -0
  130. package/corpus/templates/factory/app/components/layout/Header.tsx +60 -0
  131. package/corpus/templates/factory/app/components/layout/Layout.tsx +190 -0
  132. package/corpus/templates/factory/app/components/layout/Sidebar.tsx +538 -0
  133. package/corpus/templates/factory/app/components/triage/triage-status-pill.tsx +28 -0
  134. package/corpus/templates/factory/app/components/ui/button.tsx +1 -0
  135. package/corpus/templates/factory/app/components/ui/card.tsx +1 -0
  136. package/corpus/templates/factory/app/components/ui/dropdown-menu.tsx +1 -0
  137. package/corpus/templates/factory/app/components/ui/input.tsx +1 -0
  138. package/corpus/templates/factory/app/components/ui/label.tsx +1 -0
  139. package/corpus/templates/factory/app/components/ui/sheet.tsx +1 -0
  140. package/corpus/templates/factory/app/components/ui/textarea.tsx +1 -0
  141. package/corpus/templates/factory/app/components/ui/toolkit-provider.tsx +17 -0
  142. package/corpus/templates/factory/app/components/ui/tooltip.tsx +1 -0
  143. package/corpus/templates/factory/app/design-system.ts +3 -0
  144. package/corpus/templates/factory/app/entry.client.tsx +22 -0
  145. package/corpus/templates/factory/app/entry.server.tsx +10 -0
  146. package/corpus/templates/factory/app/global.css +93 -0
  147. package/corpus/templates/factory/app/hooks/use-navigation-state.ts +113 -0
  148. package/corpus/templates/factory/app/i18n/en-US.ts +211 -0
  149. package/corpus/templates/factory/app/i18n/index.ts +34 -0
  150. package/corpus/templates/factory/app/i18n-data.ts +556 -0
  151. package/corpus/templates/factory/app/lib/agent-page.tsx +49 -0
  152. package/corpus/templates/factory/app/lib/app-config.ts +11 -0
  153. package/corpus/templates/factory/app/lib/tab-id.ts +1 -0
  154. package/corpus/templates/factory/app/lib/utils.ts +1 -0
  155. package/corpus/templates/factory/app/root.tsx +175 -0
  156. package/corpus/templates/factory/app/routes/_index.tsx +94 -0
  157. package/corpus/templates/factory/app/routes/agent.tsx +24 -0
  158. package/corpus/templates/factory/app/routes/chat.$threadId.tsx +1 -0
  159. package/corpus/templates/factory/app/routes/database.tsx +17 -0
  160. package/corpus/templates/factory/app/routes/extensions.$id.$slug.tsx +2 -0
  161. package/corpus/templates/factory/app/routes/extensions.$id.tsx +11 -0
  162. package/corpus/templates/factory/app/routes/extensions._index.tsx +11 -0
  163. package/corpus/templates/factory/app/routes/extensions.tsx +5 -0
  164. package/corpus/templates/factory/app/routes/factory.tsx +1003 -0
  165. package/corpus/templates/factory/app/routes/observability.tsx +19 -0
  166. package/corpus/templates/factory/app/routes/settings.tsx +89 -0
  167. package/corpus/templates/factory/app/routes/team.tsx +11 -0
  168. package/corpus/templates/factory/app/routes.ts +4 -0
  169. package/corpus/templates/factory/app/vite-env.d.ts +6 -0
  170. package/corpus/templates/factory/changelog/2026-06-24-a-new-settings-page-gives-quick-access-to-language-workspace.md +6 -0
  171. package/corpus/templates/factory/changelog/2026-06-24-added-a-language-picker-and-localized-app-chrome-for-support.md +6 -0
  172. package/corpus/templates/factory/changelog/2026-06-27-traditional-chinese-copy-uses-taiwan-terminology.md +6 -0
  173. package/corpus/templates/factory/changelog/2026-06-28-left-sidebar-collapse-motion-and-footer-chrome-are-quieter.md +6 -0
  174. package/corpus/templates/factory/changelog/2026-06-29-chat-layouts-adapt-when-the-agent-sidebar-is-open.md +6 -0
  175. package/corpus/templates/factory/changelog/2026-07-08-settings-are-cleaner-and-searchable.md +5 -0
  176. package/corpus/templates/factory/changelog/2026-07-10-chat-now-makes-ai-connection-setup-clear-without-shifting-th.md +6 -0
  177. package/corpus/templates/factory/changelog/2026-07-13-a-full-agent-page-now-brings-context-files-connections-jobs-.md +6 -0
  178. package/corpus/templates/factory/changelog/2026-07-14-chat-opens-reliably-on-hosted-deployments-instead-of-failing.md +6 -0
  179. package/corpus/templates/factory/changelog/2026-07-14-fixed-chat-template-startup-with-older-core-versions.md +6 -0
  180. package/corpus/templates/factory/changelog/2026-07-15-chat-navigation-focuses-on-chat-and-agent.md +6 -0
  181. package/corpus/templates/factory/changelog/2026-07-17-the-agent-chat-sidebar-stays-closed-until-you-open-it-or-sta.md +6 -0
  182. package/corpus/templates/factory/changelog/2026-07-22-compact-sidebar-footer.md +6 -0
  183. package/corpus/templates/factory/changelog/2026-07-22-full-page-chat-keeps-the-active-conversation-when-moving-to-.md +6 -0
  184. package/corpus/templates/factory/changelog/2026-07-22-manage-agent-navigation-now-uses-the-connected-nodes-icon.md +6 -0
  185. package/corpus/templates/factory/changelog/2026-07-22-recent-chats-are-easier-to-scan-and-expand.md +6 -0
  186. package/corpus/templates/factory/changelog/2026-07-23-full-page-chat-is-better-centered-with-quieter-chat-history-.md +6 -0
  187. package/corpus/templates/factory/changelog/2026-07-24-borderless-secondary-surfaces.md +6 -0
  188. package/corpus/templates/factory/changelog/2026-07-24-sidebar-footer-controls-follow-a-consistent-order.md +6 -0
  189. package/corpus/templates/factory/changelog/2026-07-25-settings-navigation-now-keeps-manage-agent-as-a-dedicated-li.md +6 -0
  190. package/corpus/templates/factory/changelog/2026-07-29-sidebar-footers-now-keep-feedback-search-and-collapse-togeth.md +6 -0
  191. package/corpus/templates/factory/changelog/2026-07-31-added-an-inspectable-observe-only-factory-queue-for-slack-.md +6 -0
  192. package/corpus/templates/factory/changelog/2026-07-31-clicking-the-agent-native-logo-now-toggles-the-app-sidebar.md +6 -0
  193. package/corpus/templates/factory/components.json +20 -0
  194. package/corpus/templates/factory/data/sync-config.json +1 -0
  195. package/corpus/templates/factory/learnings.defaults.md +5 -0
  196. package/corpus/templates/factory/netlify.toml +10 -0
  197. package/corpus/templates/factory/package.json +105 -0
  198. package/corpus/templates/factory/public/agent-native-icon-dark.svg +10 -0
  199. package/corpus/templates/factory/public/agent-native-icon-light.svg +10 -0
  200. package/corpus/templates/factory/public/agent-native-logo-dark.svg +21 -0
  201. package/corpus/templates/factory/public/agent-native-logo-light.svg +21 -0
  202. package/corpus/templates/factory/public/favicon.svg +1 -0
  203. package/corpus/templates/factory/public/icon-180.svg +1 -0
  204. package/corpus/templates/factory/public/icon-192.svg +1 -0
  205. package/corpus/templates/factory/public/icon-512.svg +1 -0
  206. package/corpus/templates/factory/public/manifest.json +21 -0
  207. package/corpus/templates/factory/react-router.config.ts +7 -0
  208. package/corpus/templates/factory/server/connectors/credentials.ts +129 -0
  209. package/corpus/templates/factory/server/connectors/slack.ts +129 -0
  210. package/corpus/templates/factory/server/db/index.ts +6 -0
  211. package/corpus/templates/factory/server/db/schema.ts +193 -0
  212. package/corpus/templates/factory/server/factory-graph/contracts.ts +212 -0
  213. package/corpus/templates/factory/server/factory-graph/store.ts +121 -0
  214. package/corpus/templates/factory/server/lib/require-workspace-member.ts +55 -0
  215. package/corpus/templates/factory/server/middleware/auth.ts +15 -0
  216. package/corpus/templates/factory/server/plugins/agent-chat.ts +58 -0
  217. package/corpus/templates/factory/server/plugins/auth.ts +14 -0
  218. package/corpus/templates/factory/server/plugins/factory-migrations.ts +247 -0
  219. package/corpus/templates/factory/server/plugins/factory-scheduler-job.ts +116 -0
  220. package/corpus/templates/factory/server/plugins/integrations.ts +46 -0
  221. package/corpus/templates/factory/server/routes/[...page].get.ts +5 -0
  222. package/corpus/templates/factory/server/routes/_agent-native/factory/builder-callback.post.ts +116 -0
  223. package/corpus/templates/factory/server/triage/ai-services-git.ts +197 -0
  224. package/corpus/templates/factory/server/triage/builder-executor.ts +118 -0
  225. package/corpus/templates/factory/server/triage/contracts.ts +164 -0
  226. package/corpus/templates/factory/server/triage/github-ingestion.ts +35 -0
  227. package/corpus/templates/factory/server/triage/guards.ts +121 -0
  228. package/corpus/templates/factory/server/triage/ids.ts +27 -0
  229. package/corpus/templates/factory/server/triage/pr-babysit.ts +100 -0
  230. package/corpus/templates/factory/server/triage/pr-monitor.ts +220 -0
  231. package/corpus/templates/factory/server/triage/slack-client.ts +55 -0
  232. package/corpus/templates/factory/server/triage/slack-poller.ts +152 -0
  233. package/corpus/templates/factory/ssr-entry.ts +15 -0
  234. package/corpus/templates/factory/tsconfig.json +21 -0
  235. package/corpus/templates/factory/vite.config.ts +19 -0
  236. package/corpus/templates/forms/app/components/layout/Sidebar.tsx +55 -5
  237. package/corpus/templates/forms/changelog/2026-07-31-the-agent-native-logo-stays-visible-when-the-sidebar-is-coll.md +6 -0
  238. package/corpus/templates/macros/app/components/layout/AppLayout.tsx +6 -2
  239. package/corpus/templates/plan/app/components/layout/Sidebar.tsx +21 -6
  240. package/corpus/templates/plan/changelog/2026-07-31-clicking-the-agent-native-logo-now-toggles-the-app-sidebar.md +6 -0
  241. package/corpus/templates/slides/.agents/skills/create-deck/SKILL.md +12 -0
  242. package/corpus/templates/slides/.agents/skills/design-systems/SKILL.md +9 -0
  243. package/corpus/templates/slides/.agents/skills/slide-editing/SKILL.md +11 -0
  244. package/corpus/templates/slides/AGENTS.md +5 -6
  245. package/corpus/templates/slides/actions/_await-fit-check.ts +20 -10
  246. package/corpus/templates/slides/actions/add-slide.ts +17 -4
  247. package/corpus/templates/slides/actions/create-design-system.ts +16 -4
  248. package/corpus/templates/slides/actions/delete-design-system.ts +18 -2
  249. package/corpus/templates/slides/actions/get-layout-overflows.ts +88 -0
  250. package/corpus/templates/slides/actions/import-file.ts +1 -0
  251. package/corpus/templates/slides/actions/index-design-system-with-builder.ts +8 -0
  252. package/corpus/templates/slides/actions/patch-deck.ts +48 -16
  253. package/corpus/templates/slides/actions/set-default-design-system.ts +49 -19
  254. package/corpus/templates/slides/actions/update-slide.ts +13 -3
  255. package/corpus/templates/slides/actions/view-screen.ts +87 -10
  256. package/corpus/templates/slides/app/components/deck/SlideRenderer.tsx +155 -28
  257. package/corpus/templates/slides/app/components/design-system/DesignSystemCard.tsx +21 -17
  258. package/corpus/templates/slides/app/components/design-system/DesignSystemSetup.tsx +849 -341
  259. package/corpus/templates/slides/app/components/editor/EditorSidebar.tsx +102 -2
  260. package/corpus/templates/slides/app/components/editor/PromptDialog.tsx +13 -16
  261. package/corpus/templates/slides/app/components/editor/SlideEditor.tsx +60 -12
  262. package/corpus/templates/slides/app/components/editor/SlideOverflowWarning.tsx +11 -1
  263. package/corpus/templates/slides/app/components/layout/Sidebar.tsx +66 -19
  264. package/corpus/templates/slides/app/i18n/en-US.ts +23 -0
  265. package/corpus/templates/slides/app/lib/normalize-slide-padding.ts +8 -15
  266. package/corpus/templates/slides/app/pages/DeckEditor.tsx +4 -3
  267. package/corpus/templates/slides/app/pages/DesignSystems.tsx +4 -3
  268. package/corpus/templates/slides/app/pages/Index.tsx +1 -1
  269. package/corpus/templates/slides/changelog/2026-07-31-design-system-details-now-show-their-source-and-indexing-sta.md +6 -0
  270. package/corpus/templates/slides/changelog/2026-07-31-design-system-indexing-keeps-your-chosen-name-when-you-uploa.md +6 -0
  271. package/corpus/templates/slides/changelog/2026-07-31-design-system-setup-keeps-focus-rings-visible-and-uses-a-sim.md +6 -0
  272. package/corpus/templates/slides/changelog/2026-07-31-skip-prompt-is-now-available-in-the-new-deck-prompt-header.md +6 -0
  273. package/corpus/templates/slides/changelog/2026-07-31-slides-now-detect-real-text-and-box-overflow-across-the-deck.md +6 -0
  274. package/corpus/templates/slides/changelog/2026-07-31-the-agent-native-logo-stays-visible-when-the-sidebar-is-coll.md +6 -0
  275. package/corpus/templates/slides/server/handlers/design-systems.ts +1 -0
  276. package/corpus/templates/slides/server/handlers/index-design-system-sources.ts +1 -0
  277. package/corpus/templates/slides/server/lib/builder-design-system-proxy.ts +23 -4
  278. package/corpus/templates/slides/server/plugins/agent-chat.ts +5 -0
  279. package/corpus/templates/slides/server/plugins/creative-context.ts +16 -3
  280. package/corpus/templates/slides/server/workspace-defaults.ts +5 -1
  281. package/corpus/templates/slides/shared/slide-fit.ts +26 -0
  282. package/corpus/templates/tasks/app/components/layout/Sidebar.tsx +30 -3
  283. package/corpus/templates/tasks/changelog/2026-07-31-clicking-the-agent-native-logo-now-toggles-the-app-sidebar.md +6 -0
  284. package/dist/a2a/correlation.d.ts +4 -1
  285. package/dist/a2a/correlation.d.ts.map +1 -1
  286. package/dist/a2a/correlation.js +8 -1
  287. package/dist/a2a/correlation.js.map +1 -1
  288. package/dist/a2a/types.d.ts +11 -3
  289. package/dist/a2a/types.d.ts.map +1 -1
  290. package/dist/a2a/types.js.map +1 -1
  291. package/dist/agent/engine/ai-sdk-engine.d.ts.map +1 -1
  292. package/dist/agent/engine/ai-sdk-engine.js +27 -41
  293. package/dist/agent/engine/ai-sdk-engine.js.map +1 -1
  294. package/dist/agent/engine/builder-engine.d.ts.map +1 -1
  295. package/dist/agent/engine/builder-engine.js +18 -8
  296. package/dist/agent/engine/builder-engine.js.map +1 -1
  297. package/dist/agent/engine/error-detail.d.ts +61 -0
  298. package/dist/agent/engine/error-detail.d.ts.map +1 -1
  299. package/dist/agent/engine/error-detail.js +145 -3
  300. package/dist/agent/engine/error-detail.js.map +1 -1
  301. package/dist/agent/engine/failure-taxonomy.d.ts +24 -0
  302. package/dist/agent/engine/failure-taxonomy.d.ts.map +1 -0
  303. package/dist/agent/engine/failure-taxonomy.js +88 -0
  304. package/dist/agent/engine/failure-taxonomy.js.map +1 -0
  305. package/dist/agent/engine/index.d.ts +2 -1
  306. package/dist/agent/engine/index.d.ts.map +1 -1
  307. package/dist/agent/engine/index.js +2 -1
  308. package/dist/agent/engine/index.js.map +1 -1
  309. package/dist/agent/engine/registry.d.ts +16 -0
  310. package/dist/agent/engine/registry.d.ts.map +1 -1
  311. package/dist/agent/engine/registry.js +71 -6
  312. package/dist/agent/engine/registry.js.map +1 -1
  313. package/dist/agent/engine/translate-ai-sdk.d.ts.map +1 -1
  314. package/dist/agent/engine/translate-ai-sdk.js +14 -2
  315. package/dist/agent/engine/translate-ai-sdk.js.map +1 -1
  316. package/dist/agent/production-agent.d.ts.map +1 -1
  317. package/dist/agent/production-agent.js +13 -24
  318. package/dist/agent/production-agent.js.map +1 -1
  319. package/dist/agent/run-loop-with-resume.js +1 -1
  320. package/dist/agent/run-loop-with-resume.js.map +1 -1
  321. package/dist/agent/run-manager.d.ts.map +1 -1
  322. package/dist/agent/run-manager.js +39 -10
  323. package/dist/agent/run-manager.js.map +1 -1
  324. package/dist/agent/run-store.d.ts +10 -0
  325. package/dist/agent/run-store.d.ts.map +1 -1
  326. package/dist/agent/run-store.js +20 -3
  327. package/dist/agent/run-store.js.map +1 -1
  328. package/dist/agent/thread-data-builder.d.ts.map +1 -1
  329. package/dist/agent/thread-data-builder.js +28 -4
  330. package/dist/agent/thread-data-builder.js.map +1 -1
  331. package/dist/chat-threads/store.d.ts +13 -0
  332. package/dist/chat-threads/store.d.ts.map +1 -1
  333. package/dist/chat-threads/store.js +35 -0
  334. package/dist/chat-threads/store.js.map +1 -1
  335. package/dist/cli/templates-meta.d.ts.map +1 -1
  336. package/dist/cli/templates-meta.js +13 -0
  337. package/dist/cli/templates-meta.js.map +1 -1
  338. package/dist/cli/workspace-dev.d.ts.map +1 -1
  339. package/dist/cli/workspace-dev.js +1 -0
  340. package/dist/cli/workspace-dev.js.map +1 -1
  341. package/dist/client/error-format.d.ts.map +1 -1
  342. package/dist/client/error-format.js +10 -0
  343. package/dist/client/error-format.js.map +1 -1
  344. package/dist/client/use-chat-threads.d.ts.map +1 -1
  345. package/dist/client/use-chat-threads.js +66 -16
  346. package/dist/client/use-chat-threads.js.map +1 -1
  347. package/dist/collab/awareness.d.ts +2 -2
  348. package/dist/collab/awareness.d.ts.map +1 -1
  349. package/dist/collab/struct-routes.d.ts +1 -1
  350. package/dist/credentials/index.d.ts +9 -2
  351. package/dist/credentials/index.d.ts.map +1 -1
  352. package/dist/credentials/index.js +50 -8
  353. package/dist/credentials/index.js.map +1 -1
  354. package/dist/extensions/url-safety.d.ts.map +1 -1
  355. package/dist/extensions/url-safety.js +38 -12
  356. package/dist/extensions/url-safety.js.map +1 -1
  357. package/dist/integrations/adapters/slack.d.ts.map +1 -1
  358. package/dist/integrations/adapters/slack.js +25 -8
  359. package/dist/integrations/adapters/slack.js.map +1 -1
  360. package/dist/integrations/google-docs-poller.d.ts.map +1 -1
  361. package/dist/integrations/google-docs-poller.js +13 -1
  362. package/dist/integrations/google-docs-poller.js.map +1 -1
  363. package/dist/integrations/installations-store.d.ts +10 -0
  364. package/dist/integrations/installations-store.d.ts.map +1 -1
  365. package/dist/integrations/installations-store.js +24 -0
  366. package/dist/integrations/installations-store.js.map +1 -1
  367. package/dist/integrations/plugin.d.ts.map +1 -1
  368. package/dist/integrations/plugin.js +6 -5
  369. package/dist/integrations/plugin.js.map +1 -1
  370. package/dist/integrations/types.d.ts +7 -0
  371. package/dist/integrations/types.d.ts.map +1 -1
  372. package/dist/integrations/types.js.map +1 -1
  373. package/dist/integrations/webhook-handler.d.ts.map +1 -1
  374. package/dist/integrations/webhook-handler.js +16 -1
  375. package/dist/integrations/webhook-handler.js.map +1 -1
  376. package/dist/jobs/background-automation-runner.d.ts.map +1 -1
  377. package/dist/jobs/background-automation-runner.js +35 -2
  378. package/dist/jobs/background-automation-runner.js.map +1 -1
  379. package/dist/notifications/routes.d.ts +6 -6
  380. package/dist/observability/routes.d.ts +3 -3
  381. package/dist/provider-api/actions/custom-provider-registration.d.ts +14 -14
  382. package/dist/provider-api/actions/provider-api.d.ts +8 -8
  383. package/dist/provider-api/index.js +7 -3
  384. package/dist/provider-api/index.js.map +1 -1
  385. package/dist/scripts/call-agent.d.ts.map +1 -1
  386. package/dist/scripts/call-agent.js +6 -1
  387. package/dist/scripts/call-agent.js.map +1 -1
  388. package/dist/server/agent-chat-plugin.d.ts.map +1 -1
  389. package/dist/server/agent-chat-plugin.js +38 -9
  390. package/dist/server/agent-chat-plugin.js.map +1 -1
  391. package/dist/server/agent-discovery.d.ts +2 -0
  392. package/dist/server/agent-discovery.d.ts.map +1 -1
  393. package/dist/server/agent-discovery.js.map +1 -1
  394. package/dist/server/builder-design-systems.d.ts +4 -1
  395. package/dist/server/builder-design-systems.d.ts.map +1 -1
  396. package/dist/server/builder-design-systems.js +11 -1
  397. package/dist/server/builder-design-systems.js.map +1 -1
  398. package/dist/server/credential-provider.d.ts.map +1 -1
  399. package/dist/server/credential-provider.js +49 -12
  400. package/dist/server/credential-provider.js.map +1 -1
  401. package/dist/server/index.d.ts +1 -1
  402. package/dist/server/index.d.ts.map +1 -1
  403. package/dist/server/index.js.map +1 -1
  404. package/dist/server/onboarding-html.d.ts.map +1 -1
  405. package/dist/server/onboarding-html.js +37 -2
  406. package/dist/server/onboarding-html.js.map +1 -1
  407. package/dist/server/transcribe-voice.d.ts +1 -1
  408. package/dist/shared/reasoning-effort.d.ts +1 -0
  409. package/dist/shared/reasoning-effort.d.ts.map +1 -1
  410. package/dist/shared/reasoning-effort.js +1 -1
  411. package/dist/shared/reasoning-effort.js.map +1 -1
  412. package/dist/templates/chat/app/components/layout/Sidebar.tsx +30 -3
  413. package/dist/templates/chat/changelog/2026-07-31-clicking-the-agent-native-logo-now-toggles-the-app-sidebar.md +6 -0
  414. package/dist/templates/workspace-core/.agents/skills/a2a-protocol/SKILL.md +11 -0
  415. package/package.json +1 -1
  416. package/src/a2a/correlation.ts +11 -1
  417. package/src/a2a/types.ts +11 -3
  418. package/src/agent/engine/ai-sdk-engine.ts +33 -46
  419. package/src/agent/engine/builder-engine.ts +22 -10
  420. package/src/agent/engine/error-detail.ts +184 -3
  421. package/src/agent/engine/failure-taxonomy.ts +123 -0
  422. package/src/agent/engine/index.ts +8 -0
  423. package/src/agent/engine/registry.ts +92 -8
  424. package/src/agent/engine/translate-ai-sdk.ts +17 -2
  425. package/src/agent/production-agent.ts +13 -33
  426. package/src/agent/run-loop-with-resume.ts +1 -1
  427. package/src/agent/run-manager.ts +43 -14
  428. package/src/agent/run-store.ts +30 -3
  429. package/src/agent/thread-data-builder.ts +36 -4
  430. package/src/chat-threads/store.ts +42 -0
  431. package/src/cli/templates-meta.ts +13 -0
  432. package/src/cli/workspace-dev.ts +1 -0
  433. package/src/client/error-format.ts +12 -0
  434. package/src/client/use-chat-threads.ts +76 -16
  435. package/src/credentials/index.ts +51 -12
  436. package/src/extensions/url-safety.ts +46 -12
  437. package/src/integrations/adapters/slack.ts +32 -10
  438. package/src/integrations/google-docs-poller.ts +12 -1
  439. package/src/integrations/installations-store.ts +30 -0
  440. package/src/integrations/plugin.ts +5 -5
  441. package/src/integrations/types.ts +7 -0
  442. package/src/integrations/webhook-handler.ts +24 -1
  443. package/src/jobs/background-automation-runner.ts +38 -1
  444. package/src/provider-api/index.ts +8 -2
  445. package/src/scripts/call-agent.ts +6 -0
  446. package/src/server/agent-chat-plugin.ts +46 -10
  447. package/src/server/agent-discovery.ts +2 -0
  448. package/src/server/builder-design-systems.ts +21 -0
  449. package/src/server/credential-provider.ts +51 -12
  450. package/src/server/index.ts +1 -0
  451. package/src/server/onboarding-html.ts +37 -2
  452. package/src/shared/reasoning-effort.ts +1 -1
  453. package/src/templates/chat/app/components/layout/Sidebar.tsx +30 -3
  454. package/src/templates/chat/changelog/2026-07-31-clicking-the-agent-native-logo-now-toggles-the-app-sidebar.md +6 -0
  455. package/src/templates/workspace-core/.agents/skills/a2a-protocol/SKILL.md +11 -0
  456. package/corpus/templates/clips/desktop/src/lib/media-device-selection.ts +0 -157
@@ -1 +1 @@
1
- {"version":3,"file":"background-automation-runner.d.ts","sourceRoot":"","sources":["../../src/jobs/background-automation-runner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAM1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAKL,KAAK,WAAW,EACjB,MAAM,8BAA8B,CAAC;AAItC,OAAO,EAEL,KAAK,2BAA2B,EACjC,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAEL,KAAK,QAAQ,EACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAKvD,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,cAAc,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED,MAAM,WAAW,wBAAwB;IACvC,UAAU,EAAE,CACV,UAAU,CAAC,EAAE,2BAA2B,KACrC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACjC,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACpD,mBAAmB,CAAC,EAAE,CACpB,UAAU,CAAC,EAAE,2BAA2B,KACrC,MAAM,EAAE,GAAG,SAAS,CAAC;IAC1B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MA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GAIG;AACH,wBAAgB,yBAAyB,CAAC,GAAG,EAAE;IAC7C,MAAM,CAAC,EAAE,SAAS;QAAE,KAAK,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,MAAM,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,EAAE,CAAC;CAClE,GAAG,MAAM,GAAG,IAAI,CAYhB;AAwBD,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,8BAA8B,EACvC,IAAI,EAAE,wBAAwB,GAC7B,OAAO,CAAC,6BAA6B,CAAC,CA2LxC"}
1
+ {"version":3,"file":"background-automation-runner.d.ts","sourceRoot":"","sources":["../../src/jobs/background-automation-runner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAM1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAKL,KAAK,WAAW,EACjB,MAAM,8BAA8B,CAAC;AAKtC,OAAO,EAEL,KAAK,2BAA2B,EACjC,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAEL,KAAK,QAAQ,EACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAKvD,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,cAAc,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED,MAAM,WAAW,wBAAwB;IACvC,UAAU,EAAE,CACV,UAAU,CAAC,EAAE,2BAA2B,KACrC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACjC,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACpD,mBAAmB,CAAC,EAA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AAmC,CACvD,UAAU,EAAE,2BAA2B,GACtC,OAAO,CAAC,kCAAkC,CAAC,CAgC7C;AAED,wBAAgB,+BAA+B,CAC7C,IAAI,EAAE,IAAI,CAAC,cAAc,EAAE,SAAS,GAAG,YAAY,CAAC,EACpD,GAAG,OAAa,GACf,OAAO,CAQT;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,GAAG,EAAE;IAC7C,MAAM,CAAC,EAAE,SAAS;QAAE,KAAK,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,MAAM,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,EAAE,CAAC;CAClE,GAAG,MAAM,GAAG,IAAI,CAYhB;AAwBD,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,8BAA8B,EACvC,IAAI,EAAE,wBAAwB,GAC7B,OAAO,CAAC,6BAA6B,CAAC,CA+NxC"}
@@ -3,6 +3,7 @@ import { getStoredModelForEngine, normalizeModelForEngine, resolveEngine, } from
3
3
  import { actionsToEngineTools, filterInitialEngineTools, getOwnerActiveApiKey, } from "../agent/production-agent.js";
4
4
  import { runAgentLoopDirectWithSoftTimeout } from "../agent/run-loop-with-resume.js";
5
5
  import { resolveRunSoftTimeoutMs, startRun } from "../agent/run-manager.js";
6
+ import { claimBackgroundRun, insertRun } from "../agent/run-store.js";
6
7
  import { attachToolSearch } from "../agent/tool-search.js";
7
8
  import { resolveAutomationExecutionIdentity, } from "../automations/service.js";
8
9
  import { createThread } from "../chat-threads/store.js";
@@ -179,12 +180,44 @@ export async function runBackgroundAutomation(options, deps) {
179
180
  const systemPrompt = await deps.getSystemPrompt(ownerEmail);
180
181
  const thread = await createThread(ownerEmail, { title: threadTitle });
181
182
  const runId = createRunId(options.runIdPrefix);
183
+ // Scheduled work is background work: it has no synchronous serverless
184
+ // caller waiting on it, so it must not inherit the interactive clamp
185
+ // (40s soft timeout, a 30s no-progress backstop at 0.75x that, and 6
186
+ // continuations). A dashboard render or digest legitimately spends
187
+ // minutes across many tool calls, and dies the first time any gap
188
+ // between two of them exceeds 30s — recorded as `no_progress` after
189
+ // several minutes of real work, because the backstop is suspended
190
+ // while a tool is in flight but not between tools.
191
+ //
192
+ // Hardcoded rather than `isInBackgroundFunctionRuntime()` (what
193
+ // webhook-handler.ts uses): a webhook can arrive on either runtime, but
194
+ // a scheduler tick never serves a synchronous request, so the
195
+ // interactive clamp never applies to it. The wider soft ceiling stays
196
+ // bounded by this runner's own BACKGROUND_RUN_HARD_TIMEOUT_MS abort.
182
197
  const softTimeoutMs = resolveRunSoftTimeoutMs(undefined, {
183
198
  useHostedDefault: true,
199
+ backgroundFunction: true,
184
200
  });
185
201
  const usageRef = { current: null };
186
202
  let responseText = "";
187
203
  let hardAbortTimer = null;
204
+ // This runner executes in-process, synchronously — there is no HTTP
205
+ // self-dispatch to a separate worker. Self-claim the row into
206
+ // 'background-processing' right away, exactly like a genuine HTTP
207
+ // background worker does immediately after its own insert (see
208
+ // production-agent.ts's `claimBackgroundWorkerRunEarly`). Without this,
209
+ // the row sits at dispatch_mode='background' for its whole life with no
210
+ // worker ever claiming it, which is indistinguishable from a lost HTTP
211
+ // handoff to the unclaimed-background-run sweep — it gets reaped as
212
+ // "background_worker_never_started" out from under a still-executing
213
+ // job the moment any single tool call runs past the 25s grace window.
214
+ await insertRun(runId, thread.id, undefined, {
215
+ dispatchMode: "background",
216
+ });
217
+ const claimedOwnRun = await claimBackgroundRun(runId);
218
+ if (!claimedOwnRun) {
219
+ throw new Error(`Background automation "${automation.name}" (run "${runId}") could not claim its own freshly-inserted run row`);
220
+ }
188
221
  await new Promise((resolve, reject) => {
189
222
  const activeRun = startRun(runId, thread.id, async (send, signal) => {
190
223
  usageRef.current = await runAgentLoopDirectWithSoftTimeout({
@@ -208,7 +241,7 @@ export async function runBackgroundAutomation(options, deps) {
208
241
  actionCaller: options.actionCaller,
209
242
  automation: options.actionAutomation,
210
243
  runId,
211
- }, softTimeoutMs);
244
+ }, softTimeoutMs, { backgroundFunction: true });
212
245
  }, async (run) => {
213
246
  if (hardAbortTimer) {
214
247
  clearTimeout(hardAbortTimer);
@@ -227,7 +260,7 @@ export async function runBackgroundAutomation(options, deps) {
227
260
  resolve();
228
261
  }, {
229
262
  softTimeoutMs,
230
- dispatchMode: "background",
263
+ backgroundFunction: true,
231
264
  model,
232
265
  engineName: engine.name,
233
266
  });
@@ -1 +1 @@
1
- {"version":3,"file":"background-automation-runner.js","sourceRoot":"","sources":["../../src/jobs/background-automation-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uCAAuC,EAAE,MAAM,yBAAyB,CAAC;AAElF,OAAO,EACL,uBAAuB,EACvB,uBAAuB,EACvB,aAAa,GACd,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,oBAAoB,GAGrB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,iCAAiC,EAAE,MAAM,kCAAkC,CAAC;AACrF,OAAO,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EACL,kCAAkC,GAEnC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EACL,+BAA+B,GAEhC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,qBAAqB,GAEtB,MAAM,8BAA8B,CAAC;AAGtC,MAAM,uBAAuB,GAAG,EAAE,GAAG,MAAM,CAAC;AAC5C,MAAM,8BAA8B,GAAG,CAAC,GAAG,MAAM,CAAC;AAkDlD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,6BAA6B,CACjD,UAAkB,EAClB,KAAc;IAEd,IACE,UAAU,KAAK,YAAY;QAC3B,+BAA+B,CAAC,UAAU,CAAC,EAC3C,CAAC;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AC,IAAI,CAAC,iBAAiB,IAAI,IAAI;gBACpD,QAAQ,EAAE,UAAU,CAAC,IAAI,CAAC,gBAAgB;aAC3C,CACF,CAAC;QACJ,CAAC;QAED,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;IACjC,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { collectFinalResponseTextFromAgentEvents } from \"../a2a/response-text.js\";\nimport type { ActionAutomationContext, ActionCaller } from \"../action.js\";\nimport {\n getStoredModelForEngine,\n normalizeModelForEngine,\n resolveEngine,\n} from \"../agent/engine/index.js\";\nimport type { AgentEngine } from \"../agent/engine/types.js\";\nimport {\n actionsToEngineTools,\n filterInitialEngineTools,\n getOwnerActiveApiKey,\n runAgentLoop,\n type ActionEntry,\n} from \"../agent/production-agent.js\";\nimport { runAgentLoopDirectWithSoftTimeout } from \"../agent/run-loop-with-resume.js\";\nimport { resolveRunSoftTimeoutMs, startRun } from \"../agent/run-manager.js\";\nimport { attachToolSearch } from \"../agent/tool-search.js\";\nimport {\n resolveAutomationExecutionIdentity,\n type AutomationExecutionIdentity,\n} from \"../automations/service.js\";\nimport { createThread } from \"../chat-threads/store.js\";\nimport { queryOrgMembers } from \"../org/context.js\";\nimport {\n organizationIdFromResourceOwner,\n type Resource,\n} from \"../resources/store.js\";\nimport {\n runWithRequestContext,\n type RequestContext,\n} from \"../server/request-context.js\";\nimport type { JobFrontmatter } from \"./frontmatter.js\";\n\nconst BACKGROUND_RUN_STUCK_MS = 10 * 60_000;\nconst BACKGROUND_RUN_HARD_TIMEOUT_MS = 5 * 60_000;\n\nexport interface BackgroundAutomationContext {\n name: string;\n meta: JobFrontmatter;\n body: string;\n resource: Resource;\n}\n\nexport interface BackgroundAutomationDeps {\n getActions: (\n automation?: BackgroundAutomationContext,\n ) => Record<string, ActionEntry>;\n getSystemPrompt: (owner: string) => Promise<string>;\n getInitialToolNames?: (\n automation?: BackgroundAutomationContext,\n ) => string[] | undefined;\n engine?: AgentEngine;\n apiKey?: string;\n model?: string;\n appId?: string;\n}\n\nexport interface BackgroundAutomationRunOptions {\n automation: BackgroundAutomationContext;\n ownerEmail: string;\n orgId?: string;\n prompt: string;\n threadTitle: string;\n runIdPrefix: string;\n usageLabel: string;\n usageRefId?: string;\n requestContext?: Omit<RequestContext, \"userEmail\" | \"orgId\">;\n actionCaller?: ActionCaller;\n actionAutomation?: ActionAutomationContext;\n}\n\nexport interface BackgroundAutomationRunResult {\n responseText: string;\n runId: string;\n}\n\nexport type AutomationIdentityValidation =\n | { ok: true }\n | { ok: false; reason: string };\n\nexport type BackgroundAutomationIdentityResult =\n | { ok: true; identity: AutomationExecutionIdentity }\n | { ok: false; reason: string };\n\n/**\n * A persisted background run must not outlive its execution identity.\n * Organization runs fail closed when membership state cannot be read. A\n * brand-new personal install without auth tables remains a distinct\n * not-applicable case so local/CLI jobs keep working before auth is configured.\n */\nexport async function validateAutomationRunIdentity(\n ownerEmail: string,\n orgId?: string,\n): Promise<AutomationIdentityValidation> {\n if (\n ownerEmail === \"__shared__\" ||\n organizationIdFromResourceOwner(ownerEmail)\n ) {\n return { ok: true };\n }\n\n try {\n const { getDbExec } = await import(\"../db/client.js\");\n const userResult = await getDbExec().execute({\n sql: `SELECT 1 FROM \"user\" WHERE email = ? LIMIT 1`,\n args: [ownerEmail],\n });\n if (!userResult.rows || userResult.rows.length === 0) {\n return { ok: false, reason: `user \"${ownerEmail}\" no longer exists` };\n }\n } catch (error) {\n const message =\n error instanceof Error ? error.message.toLowerCase() : String(error);\n const authTablesAreUnconfigured =\n !orgId &&\n (message.includes(\"does not exist\") ||\n message.includes(\"no such table\") ||\n message.includes(\"undefined table\"));\n if (authTablesAreUnconfigured) return { ok: true };\n return {\n ok: false,\n reason: `could not verify user \"${ownerEmail}\" for this run`,\n };\n }\n\n if (!orgId) return { ok: true };\n\n try {\n const memberRows = await queryOrgMembers({\n sql: `SELECT 1 FROM org_members WHERE org_id = ? AND LOWER(email) = LOWER(?) LIMIT 1`,\n args: [orgId, ownerEmail],\n });\n if (memberRows === null) {\n return {\n ok: false,\n reason: `could not verify membership in org \"${orgId}\"`,\n };\n }\n if (memberRows.length === 0) {\n return {\n ok: false,\n reason: `user \"${ownerEmail}\" is no longer a member of org \"${orgId}\"`,\n };\n }\n return { ok: true };\n } catch {\n return {\n ok: false,\n reason: `could not verify membership in org \"${orgId}\"`,\n };\n }\n}\n\nexport async function resolveBackgroundAutomationIdentity(\n automation: BackgroundAutomationContext,\n): Promise<BackgroundAutomationIdentityResult> {\n if (automation.meta.triggerType) {\n try {\n return await resolveAutomationExecutionIdentity(\n automation.resource.owner,\n automation.meta,\n );\n } catch {\n return {\n ok: false,\n reason: \"Could not verify the automation execution identity.\",\n };\n }\n }\n\n const effectiveRunAs = automation.meta.runAs ?? \"creator\";\n const userEmail =\n effectiveRunAs === \"creator\"\n ? automation.meta.createdBy || automation.resource.owner\n : automation.resource.owner;\n const orgId = automation.meta.orgId ?? undefined;\n const validity = await validateAutomationRunIdentity(userEmail, orgId);\n return validity.ok\n ? {\n ok: true,\n identity: {\n userEmail,\n orgId,\n eventOwner: userEmail.toLowerCase(),\n },\n }\n : validity;\n}\n\nexport function isBackgroundAutomationRunActive(\n meta: Pick<JobFrontmatter, \"lastRun\" | \"lastStatus\">,\n now = new Date(),\n): boolean {\n if (meta.lastStatus !== \"running\") return false;\n if (!meta.lastRun) return false;\n const startedAt = new Date(meta.lastRun).getTime();\n return (\n Number.isFinite(startedAt) &&\n now.getTime() - startedAt < BACKGROUND_RUN_STUCK_MS\n );\n}\n\n/**\n * A soft-timeout/no-progress checkpoint is a continuation boundary, not a\n * successful finish. Only the last terminal event decides whether an\n * in-invocation resume recovered from the boundary.\n */\nexport function backgroundRunCutOffReason(run: {\n events?: readonly { event: { type: string; reason?: string } }[];\n}): string | null {\n const events = run.events ?? [];\n for (let i = events.length - 1; i >= 0; i--) {\n const event = events[i].event;\n if (event.type === \"auto_continue\") {\n return event.reason === \"run_timeout\" || event.reason === \"no_progress\"\n ? event.reason\n : null;\n }\n if (event.type === \"done\" || event.type === \"error\") return null;\n }\n return null;\n}\n\nfunction uniqueToolNames(names: readonly string[]): string[] {\n return [...new Set(names)];\n}\n\nfunction assertRequestedMcpToolsAvailable(\n automation: BackgroundAutomationContext,\n actions: Record<string, ActionEntry>,\n): void {\n const requested = automation.meta.mcpTools ?? [];\n const missing = requested.filter((toolName) => !actions[toolName]);\n if (missing.length > 0) {\n throw new Error(\n `Configured MCP tools are unavailable in this run: ${missing.join(\", \")}. Reconnect the MCP server or update the automation's capability list.`,\n );\n }\n}\n\nfunction createRunId(prefix: string): string {\n const safePrefix = prefix.replace(/[^a-zA-Z0-9._-]/g, \"-\");\n return `${safePrefix}-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;\n}\n\nexport async function runBackgroundAutomation(\n options: BackgroundAutomationRunOptions,\n deps: BackgroundAutomationDeps,\n): Promise<BackgroundAutomationRunResult> {\n const { automation, ownerEmail, orgId, prompt, threadTitle, usageLabel } =\n options;\n\n return runWithRequestContext(\n {\n ...options.requestContext,\n userEmail: ownerEmail,\n orgId,\n },\n async () => {\n const baseActions = deps.getActions(automation);\n assertRequestedMcpToolsAvailable(automation, baseActions);\n\n const configuredInitialTools = deps.getInitialToolNames?.(automation);\n const initialToolNames = configuredInitialTools\n ? uniqueToolNames([\n ...configuredInitialTools,\n ...(automation.meta.mcpTools ?? []),\n ])\n : undefined;\n const actions = initialToolNames\n ? attachToolSearch({ ...baseActions })\n : baseActions;\n const availableTools = actionsToEngineTools(actions);\n const tools = filterInitialEngineTools(availableTools, initialToolNames);\n\n const userApiKey = await getOwnerActiveApiKey(ownerEmail);\n const engine =\n deps.engine ??\n (await resolveEngine({\n apiKey: userApiKey ?? deps.apiKey,\n appId: deps.appId,\n }));\n const modelCandidate =\n automation.meta.model ??\n deps.model ??\n (await getStoredModelForEngine(engine, { appId: deps.appId })) ??\n engine.defaultModel;\n const model = normalizeModelForEngine(engine, modelCandidate);\n const systemPrompt = await deps.getSystemPrompt(ownerEmail);\n const thread = await createThread(ownerEmail, { title: threadTitle });\n const runId = createRunId(options.runIdPrefix);\n const softTimeoutMs = resolveRunSoftTimeoutMs(undefined, {\n useHostedDefault: true,\n });\n\n const usageRef: {\n current: Awaited<ReturnType<typeof runAgentLoop>> | null;\n } = { current: null };\n let responseText = \"\";\n let hardAbortTimer: ReturnType<typeof setTimeout> | null = null;\n\n await new Promise<void>((resolve, reject) => {\n const activeRun = startRun(\n runId,\n thread.id,\n async (send, signal) => {\n usageRef.current = await runAgentLoopDirectWithSoftTimeout(\n {\n engine,\n model,\n systemPrompt,\n tools,\n availableTools,\n messages: [\n {\n role: \"user\",\n content: [{ type: \"text\", text: prompt }],\n },\n ],\n actions,\n send,\n signal,\n threadId: thread.id,\n ownerEmail,\n orgId,\n actionCaller: options.actionCaller,\n automation: options.actionAutomation,\n runId,\n },\n softTimeoutMs,\n );\n },\n async (run) => {\n if (hardAbortTimer) {\n clearTimeout(hardAbortTimer);\n hardAbortTimer = null;\n }\n const cutOffReason = backgroundRunCutOffReason(run);\n if (cutOffReason) {\n reject(\n new Error(\n `Background automation was cut off before finishing (${cutOffReason})`,\n ),\n );\n return;\n }\n if (run.status !== \"completed\") {\n reject(\n new Error(\n `Background automation ended with status: ${run.status}`,\n ),\n );\n return;\n }\n responseText = collectFinalResponseTextFromAgentEvents(\n (run.events ?? []).map((entry) => entry.event),\n );\n resolve();\n },\n {\n softTimeoutMs,\n dispatchMode: \"background\",\n model,\n engineName: engine.name,\n },\n );\n\n hardAbortTimer = setTimeout(() => {\n hardAbortTimer = null;\n if (activeRun.status === \"running\") {\n activeRun.abort.abort(\"background_automation_hard_timeout\");\n reject(\n new Error(\"Background automation timed out after 5 minutes\"),\n );\n }\n }, BACKGROUND_RUN_HARD_TIMEOUT_MS);\n }).finally(() => {\n if (hardAbortTimer) {\n clearTimeout(hardAbortTimer);\n hardAbortTimer = null;\n }\n });\n\n const usage = usageRef.current;\n if (\n usage &&\n (usage.inputTokens > 0 ||\n usage.outputTokens > 0 ||\n usage.cacheReadTokens > 0 ||\n usage.cacheWriteTokens > 0)\n ) {\n try {\n const { recordUsage } = await import(\"../usage/store.js\");\n await recordUsage({\n ownerEmail,\n inputTokens: usage.inputTokens,\n outputTokens: usage.outputTokens,\n cacheReadTokens: usage.cacheReadTokens,\n cacheWriteTokens: usage.cacheWriteTokens,\n model: usage.model,\n label: usageLabel,\n app: deps.appId,\n refId: options.usageRefId ?? runId,\n });\n } catch {\n // Usage attribution must not break an otherwise successful run.\n }\n }\n\n if (\n responseText.trim() &&\n automation.meta.deliveryPlatform &&\n automation.meta.deliveryDestination\n ) {\n const { getDefaultAdapter } =\n await import(\"../integrations/adapters/index.js\");\n const adapter = getDefaultAdapter(automation.meta.deliveryPlatform);\n if (!adapter?.sendMessageToTarget) {\n throw new Error(\n `Automation delivery is not supported for ${automation.meta.deliveryPlatform}`,\n );\n }\n await adapter.sendMessageToTarget(\n adapter.formatAgentResponse(responseText),\n {\n destination: automation.meta.deliveryDestination,\n threadRef: automation.meta.deliveryThreadRef ?? null,\n tenantId: automation.meta.deliveryTenantId,\n },\n );\n }\n\n return { responseText, runId };\n },\n );\n}\n"]}
1
+ {"version":3,"file":"background-automation-runner.js","sourceRoot":"","sources":["../../src/jobs/background-automation-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uCAAuC,EAAE,MAAM,yBAAyB,CAAC;AAElF,OAAO,EACL,uBAAuB,EACvB,uBAAuB,EACvB,aAAa,GACd,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,oBAAoB,GAGrB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,iCAAiC,EAAE,MAAM,kCAAkC,CAAC;AACrF,OAAO,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,gBAAgB,E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I,CAAC,mBAAmB;gBAChD,SAAS,EAAE,UAAU,CAAC,IAAI,CAAC,iBAAiB,IAAI,IAAI;gBACpD,QAAQ,EAAE,UAAU,CAAC,IAAI,CAAC,gBAAgB;aAC3C,CACF,CAAC;QACJ,CAAC;QAED,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;IACjC,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { collectFinalResponseTextFromAgentEvents } from \"../a2a/response-text.js\";\nimport type { ActionAutomationContext, ActionCaller } from \"../action.js\";\nimport {\n getStoredModelForEngine,\n normalizeModelForEngine,\n resolveEngine,\n} from \"../agent/engine/index.js\";\nimport type { AgentEngine } from \"../agent/engine/types.js\";\nimport {\n actionsToEngineTools,\n filterInitialEngineTools,\n getOwnerActiveApiKey,\n runAgentLoop,\n type ActionEntry,\n} from \"../agent/production-agent.js\";\nimport { runAgentLoopDirectWithSoftTimeout } from \"../agent/run-loop-with-resume.js\";\nimport { resolveRunSoftTimeoutMs, startRun } from \"../agent/run-manager.js\";\nimport { claimBackgroundRun, insertRun } from \"../agent/run-store.js\";\nimport { attachToolSearch } from \"../agent/tool-search.js\";\nimport {\n resolveAutomationExecutionIdentity,\n type AutomationExecutionIdentity,\n} from \"../automations/service.js\";\nimport { createThread } from \"../chat-threads/store.js\";\nimport { queryOrgMembers } from \"../org/context.js\";\nimport {\n organizationIdFromResourceOwner,\n type Resource,\n} from \"../resources/store.js\";\nimport {\n runWithRequestContext,\n type RequestContext,\n} from \"../server/request-context.js\";\nimport type { JobFrontmatter } from \"./frontmatter.js\";\n\nconst BACKGROUND_RUN_STUCK_MS = 10 * 60_000;\nconst BACKGROUND_RUN_HARD_TIMEOUT_MS = 5 * 60_000;\n\nexport interface BackgroundAutomationContext {\n name: string;\n meta: JobFrontmatter;\n body: string;\n resource: Resource;\n}\n\nexport interface BackgroundAutomationDeps {\n getActions: (\n automation?: BackgroundAutomationContext,\n ) => Record<string, ActionEntry>;\n getSystemPrompt: (owner: string) => Promise<string>;\n getInitialToolNames?: (\n automation?: BackgroundAutomationContext,\n ) => string[] | undefined;\n engine?: AgentEngine;\n apiKey?: string;\n model?: string;\n appId?: string;\n}\n\nexport interface BackgroundAutomationRunOptions {\n automation: BackgroundAutomationContext;\n ownerEmail: string;\n orgId?: string;\n prompt: string;\n threadTitle: string;\n runIdPrefix: string;\n usageLabel: string;\n usageRefId?: string;\n requestContext?: Omit<RequestContext, \"userEmail\" | \"orgId\">;\n actionCaller?: ActionCaller;\n actionAutomation?: ActionAutomationContext;\n}\n\nexport interface BackgroundAutomationRunResult {\n responseText: string;\n runId: string;\n}\n\nexport type AutomationIdentityValidation =\n | { ok: true }\n | { ok: false; reason: string };\n\nexport type BackgroundAutomationIdentityResult =\n | { ok: true; identity: AutomationExecutionIdentity }\n | { ok: false; reason: string };\n\n/**\n * A persisted background run must not outlive its execution identity.\n * Organization runs fail closed when membership state cannot be read. A\n * brand-new personal install without auth tables remains a distinct\n * not-applicable case so local/CLI jobs keep working before auth is configured.\n */\nexport async function validateAutomationRunIdentity(\n ownerEmail: string,\n orgId?: string,\n): Promise<AutomationIdentityValidation> {\n if (\n ownerEmail === \"__shared__\" ||\n organizationIdFromResourceOwner(ownerEmail)\n ) {\n return { ok: true };\n }\n\n try {\n const { getDbExec } = await import(\"../db/client.js\");\n const userResult = await getDbExec().execute({\n sql: `SELECT 1 FROM \"user\" WHERE email = ? LIMIT 1`,\n args: [ownerEmail],\n });\n if (!userResult.rows || userResult.rows.length === 0) {\n return { ok: false, reason: `user \"${ownerEmail}\" no longer exists` };\n }\n } catch (error) {\n const message =\n error instanceof Error ? error.message.toLowerCase() : String(error);\n const authTablesAreUnconfigured =\n !orgId &&\n (message.includes(\"does not exist\") ||\n message.includes(\"no such table\") ||\n message.includes(\"undefined table\"));\n if (authTablesAreUnconfigured) return { ok: true };\n return {\n ok: false,\n reason: `could not verify user \"${ownerEmail}\" for this run`,\n };\n }\n\n if (!orgId) return { ok: true };\n\n try {\n const memberRows = await queryOrgMembers({\n sql: `SELECT 1 FROM org_members WHERE org_id = ? AND LOWER(email) = LOWER(?) LIMIT 1`,\n args: [orgId, ownerEmail],\n });\n if (memberRows === null) {\n return {\n ok: false,\n reason: `could not verify membership in org \"${orgId}\"`,\n };\n }\n if (memberRows.length === 0) {\n return {\n ok: false,\n reason: `user \"${ownerEmail}\" is no longer a member of org \"${orgId}\"`,\n };\n }\n return { ok: true };\n } catch {\n return {\n ok: false,\n reason: `could not verify membership in org \"${orgId}\"`,\n };\n }\n}\n\nexport async function resolveBackgroundAutomationIdentity(\n automation: BackgroundAutomationContext,\n): Promise<BackgroundAutomationIdentityResult> {\n if (automation.meta.triggerType) {\n try {\n return await resolveAutomationExecutionIdentity(\n automation.resource.owner,\n automation.meta,\n );\n } catch {\n return {\n ok: false,\n reason: \"Could not verify the automation execution identity.\",\n };\n }\n }\n\n const effectiveRunAs = automation.meta.runAs ?? \"creator\";\n const userEmail =\n effectiveRunAs === \"creator\"\n ? automation.meta.createdBy || automation.resource.owner\n : automation.resource.owner;\n const orgId = automation.meta.orgId ?? undefined;\n const validity = await validateAutomationRunIdentity(userEmail, orgId);\n return validity.ok\n ? {\n ok: true,\n identity: {\n userEmail,\n orgId,\n eventOwner: userEmail.toLowerCase(),\n },\n }\n : validity;\n}\n\nexport function isBackgroundAutomationRunActive(\n meta: Pick<JobFrontmatter, \"lastRun\" | \"lastStatus\">,\n now = new Date(),\n): boolean {\n if (meta.lastStatus !== \"running\") return false;\n if (!meta.lastRun) return false;\n const startedAt = new Date(meta.lastRun).getTime();\n return (\n Number.isFinite(startedAt) &&\n now.getTime() - startedAt < BACKGROUND_RUN_STUCK_MS\n );\n}\n\n/**\n * A soft-timeout/no-progress checkpoint is a continuation boundary, not a\n * successful finish. Only the last terminal event decides whether an\n * in-invocation resume recovered from the boundary.\n */\nexport function backgroundRunCutOffReason(run: {\n events?: readonly { event: { type: string; reason?: string } }[];\n}): string | null {\n const events = run.events ?? [];\n for (let i = events.length - 1; i >= 0; i--) {\n const event = events[i].event;\n if (event.type === \"auto_continue\") {\n return event.reason === \"run_timeout\" || event.reason === \"no_progress\"\n ? event.reason\n : null;\n }\n if (event.type === \"done\" || event.type === \"error\") return null;\n }\n return null;\n}\n\nfunction uniqueToolNames(names: readonly string[]): string[] {\n return [...new Set(names)];\n}\n\nfunction assertRequestedMcpToolsAvailable(\n automation: BackgroundAutomationContext,\n actions: Record<string, ActionEntry>,\n): void {\n const requested = automation.meta.mcpTools ?? [];\n const missing = requested.filter((toolName) => !actions[toolName]);\n if (missing.length > 0) {\n throw new Error(\n `Configured MCP tools are unavailable in this run: ${missing.join(\", \")}. Reconnect the MCP server or update the automation's capability list.`,\n );\n }\n}\n\nfunction createRunId(prefix: string): string {\n const safePrefix = prefix.replace(/[^a-zA-Z0-9._-]/g, \"-\");\n return `${safePrefix}-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;\n}\n\nexport async function runBackgroundAutomation(\n options: BackgroundAutomationRunOptions,\n deps: BackgroundAutomationDeps,\n): Promise<BackgroundAutomationRunResult> {\n const { automation, ownerEmail, orgId, prompt, threadTitle, usageLabel } =\n options;\n\n return runWithRequestContext(\n {\n ...options.requestContext,\n userEmail: ownerEmail,\n orgId,\n },\n async () => {\n const baseActions = deps.getActions(automation);\n assertRequestedMcpToolsAvailable(automation, baseActions);\n\n const configuredInitialTools = deps.getInitialToolNames?.(automation);\n const initialToolNames = configuredInitialTools\n ? uniqueToolNames([\n ...configuredInitialTools,\n ...(automation.meta.mcpTools ?? []),\n ])\n : undefined;\n const actions = initialToolNames\n ? attachToolSearch({ ...baseActions })\n : baseActions;\n const availableTools = actionsToEngineTools(actions);\n const tools = filterInitialEngineTools(availableTools, initialToolNames);\n\n const userApiKey = await getOwnerActiveApiKey(ownerEmail);\n const engine =\n deps.engine ??\n (await resolveEngine({\n apiKey: userApiKey ?? deps.apiKey,\n appId: deps.appId,\n }));\n const modelCandidate =\n automation.meta.model ??\n deps.model ??\n (await getStoredModelForEngine(engine, { appId: deps.appId })) ??\n engine.defaultModel;\n const model = normalizeModelForEngine(engine, modelCandidate);\n const systemPrompt = await deps.getSystemPrompt(ownerEmail);\n const thread = await createThread(ownerEmail, { title: threadTitle });\n const runId = createRunId(options.runIdPrefix);\n // Scheduled work is background work: it has no synchronous serverless\n // caller waiting on it, so it must not inherit the interactive clamp\n // (40s soft timeout, a 30s no-progress backstop at 0.75x that, and 6\n // continuations). A dashboard render or digest legitimately spends\n // minutes across many tool calls, and dies the first time any gap\n // between two of them exceeds 30s — recorded as `no_progress` after\n // several minutes of real work, because the backstop is suspended\n // while a tool is in flight but not between tools.\n //\n // Hardcoded rather than `isInBackgroundFunctionRuntime()` (what\n // webhook-handler.ts uses): a webhook can arrive on either runtime, but\n // a scheduler tick never serves a synchronous request, so the\n // interactive clamp never applies to it. The wider soft ceiling stays\n // bounded by this runner's own BACKGROUND_RUN_HARD_TIMEOUT_MS abort.\n const softTimeoutMs = resolveRunSoftTimeoutMs(undefined, {\n useHostedDefault: true,\n backgroundFunction: true,\n });\n\n const usageRef: {\n current: Awaited<ReturnType<typeof runAgentLoop>> | null;\n } = { current: null };\n let responseText = \"\";\n let hardAbortTimer: ReturnType<typeof setTimeout> | null = null;\n\n // This runner executes in-process, synchronously — there is no HTTP\n // self-dispatch to a separate worker. Self-claim the row into\n // 'background-processing' right away, exactly like a genuine HTTP\n // background worker does immediately after its own insert (see\n // production-agent.ts's `claimBackgroundWorkerRunEarly`). Without this,\n // the row sits at dispatch_mode='background' for its whole life with no\n // worker ever claiming it, which is indistinguishable from a lost HTTP\n // handoff to the unclaimed-background-run sweep — it gets reaped as\n // \"background_worker_never_started\" out from under a still-executing\n // job the moment any single tool call runs past the 25s grace window.\n await insertRun(runId, thread.id, undefined, {\n dispatchMode: \"background\",\n });\n const claimedOwnRun = await claimBackgroundRun(runId);\n if (!claimedOwnRun) {\n throw new Error(\n `Background automation \"${automation.name}\" (run \"${runId}\") could not claim its own freshly-inserted run row`,\n );\n }\n\n await new Promise<void>((resolve, reject) => {\n const activeRun = startRun(\n runId,\n thread.id,\n async (send, signal) => {\n usageRef.current = await runAgentLoopDirectWithSoftTimeout(\n {\n engine,\n model,\n systemPrompt,\n tools,\n availableTools,\n messages: [\n {\n role: \"user\",\n content: [{ type: \"text\", text: prompt }],\n },\n ],\n actions,\n send,\n signal,\n threadId: thread.id,\n ownerEmail,\n orgId,\n actionCaller: options.actionCaller,\n automation: options.actionAutomation,\n runId,\n },\n softTimeoutMs,\n { backgroundFunction: true },\n );\n },\n async (run) => {\n if (hardAbortTimer) {\n clearTimeout(hardAbortTimer);\n hardAbortTimer = null;\n }\n const cutOffReason = backgroundRunCutOffReason(run);\n if (cutOffReason) {\n reject(\n new Error(\n `Background automation was cut off before finishing (${cutOffReason})`,\n ),\n );\n return;\n }\n if (run.status !== \"completed\") {\n reject(\n new Error(\n `Background automation ended with status: ${run.status}`,\n ),\n );\n return;\n }\n responseText = collectFinalResponseTextFromAgentEvents(\n (run.events ?? []).map((entry) => entry.event),\n );\n resolve();\n },\n {\n softTimeoutMs,\n backgroundFunction: true,\n model,\n engineName: engine.name,\n },\n );\n\n hardAbortTimer = setTimeout(() => {\n hardAbortTimer = null;\n if (activeRun.status === \"running\") {\n activeRun.abort.abort(\"background_automation_hard_timeout\");\n reject(\n new Error(\"Background automation timed out after 5 minutes\"),\n );\n }\n }, BACKGROUND_RUN_HARD_TIMEOUT_MS);\n }).finally(() => {\n if (hardAbortTimer) {\n clearTimeout(hardAbortTimer);\n hardAbortTimer = null;\n }\n });\n\n const usage = usageRef.current;\n if (\n usage &&\n (usage.inputTokens > 0 ||\n usage.outputTokens > 0 ||\n usage.cacheReadTokens > 0 ||\n usage.cacheWriteTokens > 0)\n ) {\n try {\n const { recordUsage } = await import(\"../usage/store.js\");\n await recordUsage({\n ownerEmail,\n inputTokens: usage.inputTokens,\n outputTokens: usage.outputTokens,\n cacheReadTokens: usage.cacheReadTokens,\n cacheWriteTokens: usage.cacheWriteTokens,\n model: usage.model,\n label: usageLabel,\n app: deps.appId,\n refId: options.usageRefId ?? runId,\n });\n } catch {\n // Usage attribution must not break an otherwise successful run.\n }\n }\n\n if (\n responseText.trim() &&\n automation.meta.deliveryPlatform &&\n automation.meta.deliveryDestination\n ) {\n const { getDefaultAdapter } =\n await import(\"../integrations/adapters/index.js\");\n const adapter = getDefaultAdapter(automation.meta.deliveryPlatform);\n if (!adapter?.sendMessageToTarget) {\n throw new Error(\n `Automation delivery is not supported for ${automation.meta.deliveryPlatform}`,\n );\n }\n await adapter.sendMessageToTarget(\n adapter.formatAgentResponse(responseText),\n {\n destination: automation.meta.deliveryDestination,\n threadRef: automation.meta.deliveryThreadRef ?? null,\n tenantId: automation.meta.deliveryTenantId,\n },\n );\n }\n\n return { responseText, runId };\n },\n );\n}\n"]}
@@ -11,24 +11,24 @@
11
11
  * DELETE /_agent-native/notifications/:id — delete
12
12
  */
13
13
  export declare function createNotificationsHandler(): import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<"" | import("./types.js").Notification[] | {
14
+ error?: undefined;
14
15
  count: number;
15
16
  updated?: undefined;
16
- error?: undefined;
17
17
  ok?: undefined;
18
18
  } | {
19
- updated: number;
20
19
  error?: undefined;
21
- ok?: undefined;
22
20
  count?: undefined;
21
+ updated: number;
22
+ ok?: undefined;
23
23
  } | {
24
+ count?: undefined;
24
25
  updated?: undefined;
25
26
  error: string;
26
27
  ok?: undefined;
27
- count?: undefined;
28
28
  } | {
29
- updated?: undefined;
30
29
  error?: undefined;
31
- ok: boolean;
32
30
  count?: undefined;
31
+ updated?: undefined;
32
+ ok: boolean;
33
33
  }>>;
34
34
  //# sourceMappingURL=routes.d.ts.map
@@ -41,16 +41,16 @@ export declare function createObservabilityHandler(): import("h3").EventHandlerW
41
41
  thumbsUpRate: number;
42
42
  avgEvalScore: number;
43
43
  } | {
44
+ error?: undefined;
44
45
  summary: import("./types.js").TraceSummary;
45
46
  spans: import("./types.js").TraceSpan[];
46
47
  id?: undefined;
47
- error?: undefined;
48
48
  ok?: undefined;
49
49
  } | {
50
+ error?: undefined;
50
51
  summary?: undefined;
51
52
  spans?: undefined;
52
53
  id: string;
53
- error?: undefined;
54
54
  ok?: undefined;
55
55
  } | {
56
56
  summary?: undefined;
@@ -59,10 +59,10 @@ export declare function createObservabilityHandler(): import("h3").EventHandlerW
59
59
  error: any;
60
60
  ok?: undefined;
61
61
  } | {
62
+ error?: undefined;
62
63
  summary?: undefined;
63
64
  spans?: undefined;
64
65
  id?: undefined;
65
66
  ok: boolean;
66
- error?: undefined;
67
67
  }>>;
68
68
  //# sourceMappingURL=routes.d.ts.map
@@ -75,10 +75,10 @@ export declare function createCustomProviderRegistrationAction<TSchema extends Z
75
75
  user: "user";
76
76
  }>>;
77
77
  }, z.core.$strip>>, {
78
+ deleted?: undefined;
78
79
  id?: undefined;
79
- message?: undefined;
80
80
  provider?: undefined;
81
- deleted?: undefined;
81
+ found?: undefined;
82
82
  providers: {
83
83
  id: string;
84
84
  label: string;
@@ -89,45 +89,45 @@ export declare function createCustomProviderRegistrationAction<TSchema extends Z
89
89
  updatedAt: number;
90
90
  }[];
91
91
  count: number;
92
- found?: undefined;
93
92
  registered?: undefined;
94
93
  label?: undefined;
95
- } | {
96
- id?: undefined;
97
94
  message?: undefined;
95
+ } | {
98
96
  deleted?: undefined;
99
- providers?: undefined;
100
97
  count?: undefined;
98
+ id?: undefined;
99
+ providers?: undefined;
101
100
  found: boolean;
102
101
  provider: import("../custom-registry.js").CustomProviderConfig;
103
102
  registered?: undefined;
104
103
  label?: undefined;
105
- } | {
106
104
  message?: undefined;
107
- provider?: undefined;
105
+ } | {
108
106
  deleted?: undefined;
109
- providers?: undefined;
110
107
  count?: undefined;
108
+ provider?: undefined;
109
+ providers?: undefined;
111
110
  found: boolean;
112
111
  id: string;
113
112
  registered?: undefined;
114
113
  label?: undefined;
115
- } | {
116
114
  message?: undefined;
117
- provider?: undefined;
118
- providers?: undefined;
115
+ } | {
119
116
  count?: undefined;
117
+ provider?: undefined;
120
118
  found?: undefined;
119
+ providers?: undefined;
121
120
  deleted: boolean;
122
121
  id: string;
123
122
  registered?: undefined;
124
123
  label?: undefined;
124
+ message?: undefined;
125
125
  } | {
126
- provider?: undefined;
127
126
  deleted?: undefined;
128
- providers?: undefined;
129
127
  count?: undefined;
128
+ provider?: undefined;
130
129
  found?: undefined;
130
+ providers?: undefined;
131
131
  registered: boolean;
132
132
  id: string;
133
133
  label: string;
@@ -312,6 +312,8 @@ export declare function createProviderApiActions(runtime: Pick<ProviderApiRuntim
312
312
  scope?: "org" | "user" | undefined;
313
313
  }, {
314
314
  id?: undefined;
315
+ deleted?: undefined;
316
+ found?: undefined;
315
317
  providers: {
316
318
  id: string;
317
319
  label: string;
@@ -323,47 +325,45 @@ export declare function createProviderApiActions(runtime: Pick<ProviderApiRuntim
323
325
  }[];
324
326
  count: number;
325
327
  provider?: undefined;
326
- found?: undefined;
327
- deleted?: undefined;
328
328
  registered?: undefined;
329
329
  label?: undefined;
330
330
  message?: undefined;
331
331
  } | {
332
- count?: undefined;
333
332
  id?: undefined;
333
+ deleted?: undefined;
334
+ count?: undefined;
334
335
  providers?: undefined;
335
336
  found: boolean;
336
337
  provider: import("../custom-registry.js").CustomProviderConfig;
337
- deleted?: undefined;
338
338
  registered?: undefined;
339
339
  label?: undefined;
340
340
  message?: undefined;
341
341
  } | {
342
+ deleted?: undefined;
342
343
  count?: undefined;
343
344
  providers?: undefined;
344
345
  provider?: undefined;
345
346
  found: boolean;
346
347
  id: string;
347
- deleted?: undefined;
348
348
  registered?: undefined;
349
349
  label?: undefined;
350
350
  message?: undefined;
351
351
  } | {
352
+ found?: undefined;
352
353
  count?: undefined;
353
354
  providers?: undefined;
354
355
  provider?: undefined;
355
- found?: undefined;
356
356
  deleted: boolean;
357
357
  id: string;
358
358
  registered?: undefined;
359
359
  label?: undefined;
360
360
  message?: undefined;
361
361
  } | {
362
+ deleted?: undefined;
363
+ found?: undefined;
362
364
  count?: undefined;
363
365
  providers?: undefined;
364
366
  provider?: undefined;
365
- found?: undefined;
366
- deleted?: undefined;
367
367
  registered: boolean;
368
368
  id: string;
369
369
  label: string;
@@ -2951,9 +2951,13 @@ async function resolveAnyCredential(options) {
2951
2951
  }
2952
2952
  async function resolveRequiredCredential(options) {
2953
2953
  const credential = await resolveOptionalCredential(options);
2954
- if (!credential?.value)
2955
- throw new Error(`${options.key} not configured`);
2956
- return credential;
2954
+ if (credential?.value)
2955
+ return credential;
2956
+ const scopeGap = await describeCredentialScopeGap([options.key], options.ctx)
2957
+ // coercion-ok: only enriches an error we throw either way — losing the scope
2958
+ // hint still surfaces the real "not configured" failure, never a success.
2959
+ .catch(() => null);
2960
+ throw new Error(`${options.key} not configured${scopeGap ? `. ${scopeGap}` : ""}`);
2957
2961
  }
2958
2962
  async function resolveOptionalCredential(options) {
2959
2963
  const localCredentialSource = options.runtime.localCredentialSource ?? "app_local";