@agent-native/core 0.132.2 → 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 (436) hide show
  1. package/corpus/README.md +2 -2
  2. package/corpus/core/CHANGELOG.md +161 -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/cli/templates-meta.ts +13 -0
  19. package/corpus/core/src/cli/workspace-dev.ts +1 -0
  20. package/corpus/core/src/client/error-format.ts +12 -0
  21. package/corpus/core/src/credentials/index.ts +51 -12
  22. package/corpus/core/src/extensions/url-safety.ts +46 -12
  23. package/corpus/core/src/integrations/adapters/slack.ts +32 -10
  24. package/corpus/core/src/integrations/google-docs-poller.ts +12 -1
  25. package/corpus/core/src/integrations/installations-store.ts +30 -0
  26. package/corpus/core/src/integrations/plugin.ts +5 -5
  27. package/corpus/core/src/integrations/types.ts +7 -0
  28. package/corpus/core/src/integrations/webhook-handler.ts +24 -1
  29. package/corpus/core/src/jobs/background-automation-runner.ts +38 -1
  30. package/corpus/core/src/provider-api/index.ts +8 -2
  31. package/corpus/core/src/scripts/call-agent.ts +6 -0
  32. package/corpus/core/src/server/agent-chat-plugin.ts +30 -9
  33. package/corpus/core/src/server/agent-discovery.ts +2 -0
  34. package/corpus/core/src/server/builder-design-systems.ts +21 -0
  35. package/corpus/core/src/server/credential-provider.ts +51 -12
  36. package/corpus/core/src/server/index.ts +1 -0
  37. package/corpus/core/src/server/onboarding-html.ts +37 -2
  38. package/corpus/core/src/shared/reasoning-effort.ts +1 -1
  39. package/corpus/core/src/templates/workspace-core/.agents/skills/a2a-protocol/SKILL.md +11 -0
  40. package/corpus/templates/analytics/app/components/layout/Sidebar.tsx +6 -2
  41. package/corpus/templates/assets/app/components/layout/Sidebar.tsx +39 -19
  42. package/corpus/templates/assets/changelog/2026-07-31-the-agent-native-logo-stays-visible-when-the-sidebar-is-coll.md +6 -0
  43. package/corpus/templates/brain/app/components/layout/Sidebar.tsx +30 -3
  44. package/corpus/templates/brain/changelog/2026-07-31-clicking-the-agent-native-logo-now-toggles-the-app-sidebar.md +6 -0
  45. package/corpus/templates/calendar/app/components/layout/AppLayout.tsx +1 -1
  46. package/corpus/templates/calendar/app/components/layout/Sidebar.tsx +54 -25
  47. package/corpus/templates/calendar/changelog/2026-07-31-the-agent-native-logo-stays-visible-when-the-sidebar-is-coll.md +6 -0
  48. package/corpus/templates/chat/app/components/layout/Sidebar.tsx +30 -3
  49. package/corpus/templates/chat/changelog/2026-07-31-clicking-the-agent-native-logo-now-toggles-the-app-sidebar.md +6 -0
  50. package/corpus/templates/clips/app/components/library/library-layout.tsx +37 -21
  51. package/corpus/templates/clips/changelog/2026-07-31-the-agent-native-logo-stays-visible-when-the-sidebar-is-coll.md +6 -0
  52. package/corpus/templates/clips/desktop/src/hooks/useMediaDevices.ts +1 -1
  53. package/corpus/templates/clips/desktop/src/lib/media-capture-constraints.ts +1 -1
  54. package/corpus/templates/content/app/components/sidebar/DocumentSidebar.tsx +34 -17
  55. package/corpus/templates/content/changelog/2026-07-31-the-agent-native-logo-stays-visible-when-the-sidebar-is-coll.md +6 -0
  56. package/corpus/templates/design/.agents/skills/design-systems/SKILL.md +6 -2
  57. package/corpus/templates/design/actions/create-design-system.ts +1 -0
  58. package/corpus/templates/design/actions/set-default-design-system.ts +34 -26
  59. package/corpus/templates/design/app/components/layout/Sidebar.tsx +21 -4
  60. package/corpus/templates/design/app/i18n-data.ts +39 -0
  61. package/corpus/templates/design/app/pages/DesignSystemSetup.tsx +229 -12
  62. package/corpus/templates/design/app/pages/DesignSystems.tsx +10 -4
  63. package/corpus/templates/design/changelog/2026-07-31-clicking-the-agent-native-logo-now-toggles-the-app-sidebar.md +6 -0
  64. package/corpus/templates/design/changelog/2026-07-31-design-system-indexing-keeps-your-chosen-name-when-you-uploa.md +6 -0
  65. package/corpus/templates/design/server/lib/builder-design-system-proxy.ts +19 -4
  66. package/corpus/templates/dispatch/AGENTS.md +4 -0
  67. package/corpus/templates/factory/.agents/skills/actions/SKILL.md +562 -0
  68. package/corpus/templates/factory/.agents/skills/adding-a-feature/SKILL.md +198 -0
  69. package/corpus/templates/factory/.agents/skills/agent-native-docs/SKILL.md +115 -0
  70. package/corpus/templates/factory/.agents/skills/agent-native-toolkit/SKILL.md +182 -0
  71. package/corpus/templates/factory/.agents/skills/capture-learnings/SKILL.md +89 -0
  72. package/corpus/templates/factory/.agents/skills/create-skill/SKILL.md +221 -0
  73. package/corpus/templates/factory/.agents/skills/customizing-agent-native/SKILL.md +220 -0
  74. package/corpus/templates/factory/.agents/skills/delegate-to-agent/SKILL.md +263 -0
  75. package/corpus/templates/factory/.agents/skills/factory-graphs/SKILL.md +52 -0
  76. package/corpus/templates/factory/.agents/skills/feature-flags/SKILL.md +169 -0
  77. package/corpus/templates/factory/.agents/skills/frontend-design/SKILL.md +174 -0
  78. package/corpus/templates/factory/.agents/skills/real-time-sync/SKILL.md +232 -0
  79. package/corpus/templates/factory/.agents/skills/security/SKILL.md +324 -0
  80. package/corpus/templates/factory/.agents/skills/self-modifying-code/SKILL.md +119 -0
  81. package/corpus/templates/factory/.agents/skills/shadcn-ui/SKILL.md +123 -0
  82. package/corpus/templates/factory/.agents/skills/sharing/SKILL.md +232 -0
  83. package/corpus/templates/factory/.agents/skills/storing-data/SKILL.md +178 -0
  84. package/corpus/templates/factory/.agents/skills/upgrade-agent-native/SKILL.md +122 -0
  85. package/corpus/templates/factory/.env.example +24 -0
  86. package/corpus/templates/factory/.ignore +0 -0
  87. package/corpus/templates/factory/.oxfmtrc.json +8 -0
  88. package/corpus/templates/factory/AGENTS.md +90 -0
  89. package/corpus/templates/factory/CHANGELOG.md +10 -0
  90. package/corpus/templates/factory/DEVELOPING.md +185 -0
  91. package/corpus/templates/factory/README.md +64 -0
  92. package/corpus/templates/factory/_gitignore +42 -0
  93. package/corpus/templates/factory/actions/add-factory-comment.ts +55 -0
  94. package/corpus/templates/factory/actions/approve-factory-item.ts +214 -0
  95. package/corpus/templates/factory/actions/babysit-pull-request.ts +126 -0
  96. package/corpus/templates/factory/actions/evaluate-triage-item.ts +172 -0
  97. package/corpus/templates/factory/actions/get-factory-graph.ts +62 -0
  98. package/corpus/templates/factory/actions/get-triage-config.ts +42 -0
  99. package/corpus/templates/factory/actions/get-triage-item.ts +74 -0
  100. package/corpus/templates/factory/actions/hello.ts +13 -0
  101. package/corpus/templates/factory/actions/ingest-github-observation.ts +100 -0
  102. package/corpus/templates/factory/actions/list-factories.ts +40 -0
  103. package/corpus/templates/factory/actions/list-factory-comments.ts +40 -0
  104. package/corpus/templates/factory/actions/list-triage-items.ts +85 -0
  105. package/corpus/templates/factory/actions/list-triage-rules.ts +44 -0
  106. package/corpus/templates/factory/actions/navigate.ts +41 -0
  107. package/corpus/templates/factory/actions/poll-slack-channel.ts +118 -0
  108. package/corpus/templates/factory/actions/reconcile-triage-run.ts +179 -0
  109. package/corpus/templates/factory/actions/record-triage-feedback.ts +58 -0
  110. package/corpus/templates/factory/actions/run.ts +2 -0
  111. package/corpus/templates/factory/actions/save-factory-graph.ts +129 -0
  112. package/corpus/templates/factory/actions/save-triage-config.ts +67 -0
  113. package/corpus/templates/factory/actions/save-triage-rule.ts +89 -0
  114. package/corpus/templates/factory/actions/suggest-factory-rules.ts +70 -0
  115. package/corpus/templates/factory/actions/view-screen.ts +73 -0
  116. package/corpus/templates/factory/app/components/factory/FactoryCanvas.tsx +441 -0
  117. package/corpus/templates/factory/app/components/factory/FactoryInspector.tsx +388 -0
  118. package/corpus/templates/factory/app/components/layout/Header.tsx +60 -0
  119. package/corpus/templates/factory/app/components/layout/Layout.tsx +190 -0
  120. package/corpus/templates/factory/app/components/layout/Sidebar.tsx +538 -0
  121. package/corpus/templates/factory/app/components/triage/triage-status-pill.tsx +28 -0
  122. package/corpus/templates/factory/app/components/ui/button.tsx +1 -0
  123. package/corpus/templates/factory/app/components/ui/card.tsx +1 -0
  124. package/corpus/templates/factory/app/components/ui/dropdown-menu.tsx +1 -0
  125. package/corpus/templates/factory/app/components/ui/input.tsx +1 -0
  126. package/corpus/templates/factory/app/components/ui/label.tsx +1 -0
  127. package/corpus/templates/factory/app/components/ui/sheet.tsx +1 -0
  128. package/corpus/templates/factory/app/components/ui/textarea.tsx +1 -0
  129. package/corpus/templates/factory/app/components/ui/toolkit-provider.tsx +17 -0
  130. package/corpus/templates/factory/app/components/ui/tooltip.tsx +1 -0
  131. package/corpus/templates/factory/app/design-system.ts +3 -0
  132. package/corpus/templates/factory/app/entry.client.tsx +22 -0
  133. package/corpus/templates/factory/app/entry.server.tsx +10 -0
  134. package/corpus/templates/factory/app/global.css +93 -0
  135. package/corpus/templates/factory/app/hooks/use-navigation-state.ts +113 -0
  136. package/corpus/templates/factory/app/i18n/en-US.ts +211 -0
  137. package/corpus/templates/factory/app/i18n/index.ts +34 -0
  138. package/corpus/templates/factory/app/i18n-data.ts +556 -0
  139. package/corpus/templates/factory/app/lib/agent-page.tsx +49 -0
  140. package/corpus/templates/factory/app/lib/app-config.ts +11 -0
  141. package/corpus/templates/factory/app/lib/tab-id.ts +1 -0
  142. package/corpus/templates/factory/app/lib/utils.ts +1 -0
  143. package/corpus/templates/factory/app/root.tsx +175 -0
  144. package/corpus/templates/factory/app/routes/_index.tsx +94 -0
  145. package/corpus/templates/factory/app/routes/agent.tsx +24 -0
  146. package/corpus/templates/factory/app/routes/chat.$threadId.tsx +1 -0
  147. package/corpus/templates/factory/app/routes/database.tsx +17 -0
  148. package/corpus/templates/factory/app/routes/extensions.$id.$slug.tsx +2 -0
  149. package/corpus/templates/factory/app/routes/extensions.$id.tsx +11 -0
  150. package/corpus/templates/factory/app/routes/extensions._index.tsx +11 -0
  151. package/corpus/templates/factory/app/routes/extensions.tsx +5 -0
  152. package/corpus/templates/factory/app/routes/factory.tsx +1003 -0
  153. package/corpus/templates/factory/app/routes/observability.tsx +19 -0
  154. package/corpus/templates/factory/app/routes/settings.tsx +89 -0
  155. package/corpus/templates/factory/app/routes/team.tsx +11 -0
  156. package/corpus/templates/factory/app/routes.ts +4 -0
  157. package/corpus/templates/factory/app/vite-env.d.ts +6 -0
  158. package/corpus/templates/factory/changelog/2026-06-24-a-new-settings-page-gives-quick-access-to-language-workspace.md +6 -0
  159. package/corpus/templates/factory/changelog/2026-06-24-added-a-language-picker-and-localized-app-chrome-for-support.md +6 -0
  160. package/corpus/templates/factory/changelog/2026-06-27-traditional-chinese-copy-uses-taiwan-terminology.md +6 -0
  161. package/corpus/templates/factory/changelog/2026-06-28-left-sidebar-collapse-motion-and-footer-chrome-are-quieter.md +6 -0
  162. package/corpus/templates/factory/changelog/2026-06-29-chat-layouts-adapt-when-the-agent-sidebar-is-open.md +6 -0
  163. package/corpus/templates/factory/changelog/2026-07-08-settings-are-cleaner-and-searchable.md +5 -0
  164. package/corpus/templates/factory/changelog/2026-07-10-chat-now-makes-ai-connection-setup-clear-without-shifting-th.md +6 -0
  165. package/corpus/templates/factory/changelog/2026-07-13-a-full-agent-page-now-brings-context-files-connections-jobs-.md +6 -0
  166. package/corpus/templates/factory/changelog/2026-07-14-chat-opens-reliably-on-hosted-deployments-instead-of-failing.md +6 -0
  167. package/corpus/templates/factory/changelog/2026-07-14-fixed-chat-template-startup-with-older-core-versions.md +6 -0
  168. package/corpus/templates/factory/changelog/2026-07-15-chat-navigation-focuses-on-chat-and-agent.md +6 -0
  169. package/corpus/templates/factory/changelog/2026-07-17-the-agent-chat-sidebar-stays-closed-until-you-open-it-or-sta.md +6 -0
  170. package/corpus/templates/factory/changelog/2026-07-22-compact-sidebar-footer.md +6 -0
  171. package/corpus/templates/factory/changelog/2026-07-22-full-page-chat-keeps-the-active-conversation-when-moving-to-.md +6 -0
  172. package/corpus/templates/factory/changelog/2026-07-22-manage-agent-navigation-now-uses-the-connected-nodes-icon.md +6 -0
  173. package/corpus/templates/factory/changelog/2026-07-22-recent-chats-are-easier-to-scan-and-expand.md +6 -0
  174. package/corpus/templates/factory/changelog/2026-07-23-full-page-chat-is-better-centered-with-quieter-chat-history-.md +6 -0
  175. package/corpus/templates/factory/changelog/2026-07-24-borderless-secondary-surfaces.md +6 -0
  176. package/corpus/templates/factory/changelog/2026-07-24-sidebar-footer-controls-follow-a-consistent-order.md +6 -0
  177. package/corpus/templates/factory/changelog/2026-07-25-settings-navigation-now-keeps-manage-agent-as-a-dedicated-li.md +6 -0
  178. package/corpus/templates/factory/changelog/2026-07-29-sidebar-footers-now-keep-feedback-search-and-collapse-togeth.md +6 -0
  179. package/corpus/templates/factory/changelog/2026-07-31-added-an-inspectable-observe-only-factory-queue-for-slack-.md +6 -0
  180. package/corpus/templates/factory/changelog/2026-07-31-clicking-the-agent-native-logo-now-toggles-the-app-sidebar.md +6 -0
  181. package/corpus/templates/factory/components.json +20 -0
  182. package/corpus/templates/factory/data/sync-config.json +1 -0
  183. package/corpus/templates/factory/learnings.defaults.md +5 -0
  184. package/corpus/templates/factory/netlify.toml +10 -0
  185. package/corpus/templates/factory/package.json +105 -0
  186. package/corpus/templates/factory/public/agent-native-icon-dark.svg +10 -0
  187. package/corpus/templates/factory/public/agent-native-icon-light.svg +10 -0
  188. package/corpus/templates/factory/public/agent-native-logo-dark.svg +21 -0
  189. package/corpus/templates/factory/public/agent-native-logo-light.svg +21 -0
  190. package/corpus/templates/factory/public/favicon.svg +1 -0
  191. package/corpus/templates/factory/public/icon-180.svg +1 -0
  192. package/corpus/templates/factory/public/icon-192.svg +1 -0
  193. package/corpus/templates/factory/public/icon-512.svg +1 -0
  194. package/corpus/templates/factory/public/manifest.json +21 -0
  195. package/corpus/templates/factory/react-router.config.ts +7 -0
  196. package/corpus/templates/factory/server/connectors/credentials.ts +129 -0
  197. package/corpus/templates/factory/server/connectors/slack.ts +129 -0
  198. package/corpus/templates/factory/server/db/index.ts +6 -0
  199. package/corpus/templates/factory/server/db/schema.ts +193 -0
  200. package/corpus/templates/factory/server/factory-graph/contracts.ts +212 -0
  201. package/corpus/templates/factory/server/factory-graph/store.ts +121 -0
  202. package/corpus/templates/factory/server/lib/require-workspace-member.ts +55 -0
  203. package/corpus/templates/factory/server/middleware/auth.ts +15 -0
  204. package/corpus/templates/factory/server/plugins/agent-chat.ts +58 -0
  205. package/corpus/templates/factory/server/plugins/auth.ts +14 -0
  206. package/corpus/templates/factory/server/plugins/factory-migrations.ts +247 -0
  207. package/corpus/templates/factory/server/plugins/factory-scheduler-job.ts +116 -0
  208. package/corpus/templates/factory/server/plugins/integrations.ts +46 -0
  209. package/corpus/templates/factory/server/routes/[...page].get.ts +5 -0
  210. package/corpus/templates/factory/server/routes/_agent-native/factory/builder-callback.post.ts +116 -0
  211. package/corpus/templates/factory/server/triage/ai-services-git.ts +197 -0
  212. package/corpus/templates/factory/server/triage/builder-executor.ts +118 -0
  213. package/corpus/templates/factory/server/triage/contracts.ts +164 -0
  214. package/corpus/templates/factory/server/triage/github-ingestion.ts +35 -0
  215. package/corpus/templates/factory/server/triage/guards.ts +121 -0
  216. package/corpus/templates/factory/server/triage/ids.ts +27 -0
  217. package/corpus/templates/factory/server/triage/pr-babysit.ts +100 -0
  218. package/corpus/templates/factory/server/triage/pr-monitor.ts +220 -0
  219. package/corpus/templates/factory/server/triage/slack-client.ts +55 -0
  220. package/corpus/templates/factory/server/triage/slack-poller.ts +152 -0
  221. package/corpus/templates/factory/ssr-entry.ts +15 -0
  222. package/corpus/templates/factory/tsconfig.json +21 -0
  223. package/corpus/templates/factory/vite.config.ts +19 -0
  224. package/corpus/templates/forms/app/components/layout/Sidebar.tsx +55 -5
  225. package/corpus/templates/forms/changelog/2026-07-31-the-agent-native-logo-stays-visible-when-the-sidebar-is-coll.md +6 -0
  226. package/corpus/templates/macros/app/components/layout/AppLayout.tsx +6 -2
  227. package/corpus/templates/plan/app/components/layout/Sidebar.tsx +21 -6
  228. package/corpus/templates/plan/changelog/2026-07-31-clicking-the-agent-native-logo-now-toggles-the-app-sidebar.md +6 -0
  229. package/corpus/templates/slides/.agents/skills/create-deck/SKILL.md +12 -0
  230. package/corpus/templates/slides/.agents/skills/design-systems/SKILL.md +9 -0
  231. package/corpus/templates/slides/.agents/skills/slide-editing/SKILL.md +11 -0
  232. package/corpus/templates/slides/AGENTS.md +5 -6
  233. package/corpus/templates/slides/actions/_await-fit-check.ts +20 -10
  234. package/corpus/templates/slides/actions/add-slide.ts +17 -4
  235. package/corpus/templates/slides/actions/create-design-system.ts +16 -4
  236. package/corpus/templates/slides/actions/delete-design-system.ts +18 -2
  237. package/corpus/templates/slides/actions/get-layout-overflows.ts +88 -0
  238. package/corpus/templates/slides/actions/import-file.ts +1 -0
  239. package/corpus/templates/slides/actions/index-design-system-with-builder.ts +8 -0
  240. package/corpus/templates/slides/actions/patch-deck.ts +48 -16
  241. package/corpus/templates/slides/actions/set-default-design-system.ts +49 -19
  242. package/corpus/templates/slides/actions/update-slide.ts +13 -3
  243. package/corpus/templates/slides/actions/view-screen.ts +87 -10
  244. package/corpus/templates/slides/app/components/deck/SlideRenderer.tsx +155 -28
  245. package/corpus/templates/slides/app/components/design-system/DesignSystemCard.tsx +21 -17
  246. package/corpus/templates/slides/app/components/design-system/DesignSystemSetup.tsx +849 -341
  247. package/corpus/templates/slides/app/components/editor/EditorSidebar.tsx +102 -2
  248. package/corpus/templates/slides/app/components/editor/PromptDialog.tsx +13 -16
  249. package/corpus/templates/slides/app/components/editor/SlideEditor.tsx +60 -12
  250. package/corpus/templates/slides/app/components/editor/SlideOverflowWarning.tsx +11 -1
  251. package/corpus/templates/slides/app/components/layout/Sidebar.tsx +66 -19
  252. package/corpus/templates/slides/app/i18n/en-US.ts +23 -0
  253. package/corpus/templates/slides/app/lib/normalize-slide-padding.ts +8 -15
  254. package/corpus/templates/slides/app/pages/DeckEditor.tsx +4 -3
  255. package/corpus/templates/slides/app/pages/DesignSystems.tsx +4 -3
  256. package/corpus/templates/slides/app/pages/Index.tsx +1 -1
  257. package/corpus/templates/slides/changelog/2026-07-31-design-system-details-now-show-their-source-and-indexing-sta.md +6 -0
  258. package/corpus/templates/slides/changelog/2026-07-31-design-system-indexing-keeps-your-chosen-name-when-you-uploa.md +6 -0
  259. package/corpus/templates/slides/changelog/2026-07-31-design-system-setup-keeps-focus-rings-visible-and-uses-a-sim.md +6 -0
  260. package/corpus/templates/slides/changelog/2026-07-31-skip-prompt-is-now-available-in-the-new-deck-prompt-header.md +6 -0
  261. package/corpus/templates/slides/changelog/2026-07-31-slides-now-detect-real-text-and-box-overflow-across-the-deck.md +6 -0
  262. package/corpus/templates/slides/changelog/2026-07-31-the-agent-native-logo-stays-visible-when-the-sidebar-is-coll.md +6 -0
  263. package/corpus/templates/slides/server/handlers/design-systems.ts +1 -0
  264. package/corpus/templates/slides/server/handlers/index-design-system-sources.ts +1 -0
  265. package/corpus/templates/slides/server/lib/builder-design-system-proxy.ts +23 -4
  266. package/corpus/templates/slides/server/plugins/agent-chat.ts +5 -0
  267. package/corpus/templates/slides/server/plugins/creative-context.ts +16 -3
  268. package/corpus/templates/slides/server/workspace-defaults.ts +5 -1
  269. package/corpus/templates/slides/shared/slide-fit.ts +26 -0
  270. package/corpus/templates/tasks/app/components/layout/Sidebar.tsx +30 -3
  271. package/corpus/templates/tasks/changelog/2026-07-31-clicking-the-agent-native-logo-now-toggles-the-app-sidebar.md +6 -0
  272. package/dist/a2a/correlation.d.ts +4 -1
  273. package/dist/a2a/correlation.d.ts.map +1 -1
  274. package/dist/a2a/correlation.js +8 -1
  275. package/dist/a2a/correlation.js.map +1 -1
  276. package/dist/a2a/types.d.ts +11 -3
  277. package/dist/a2a/types.d.ts.map +1 -1
  278. package/dist/a2a/types.js.map +1 -1
  279. package/dist/agent/engine/ai-sdk-engine.d.ts.map +1 -1
  280. package/dist/agent/engine/ai-sdk-engine.js +27 -41
  281. package/dist/agent/engine/ai-sdk-engine.js.map +1 -1
  282. package/dist/agent/engine/builder-engine.d.ts.map +1 -1
  283. package/dist/agent/engine/builder-engine.js +18 -8
  284. package/dist/agent/engine/builder-engine.js.map +1 -1
  285. package/dist/agent/engine/error-detail.d.ts +61 -0
  286. package/dist/agent/engine/error-detail.d.ts.map +1 -1
  287. package/dist/agent/engine/error-detail.js +145 -3
  288. package/dist/agent/engine/error-detail.js.map +1 -1
  289. package/dist/agent/engine/failure-taxonomy.d.ts +24 -0
  290. package/dist/agent/engine/failure-taxonomy.d.ts.map +1 -0
  291. package/dist/agent/engine/failure-taxonomy.js +88 -0
  292. package/dist/agent/engine/failure-taxonomy.js.map +1 -0
  293. package/dist/agent/engine/index.d.ts +2 -1
  294. package/dist/agent/engine/index.d.ts.map +1 -1
  295. package/dist/agent/engine/index.js +2 -1
  296. package/dist/agent/engine/index.js.map +1 -1
  297. package/dist/agent/engine/registry.d.ts +16 -0
  298. package/dist/agent/engine/registry.d.ts.map +1 -1
  299. package/dist/agent/engine/registry.js +71 -6
  300. package/dist/agent/engine/registry.js.map +1 -1
  301. package/dist/agent/engine/translate-ai-sdk.d.ts.map +1 -1
  302. package/dist/agent/engine/translate-ai-sdk.js +14 -2
  303. package/dist/agent/engine/translate-ai-sdk.js.map +1 -1
  304. package/dist/agent/production-agent.d.ts.map +1 -1
  305. package/dist/agent/production-agent.js +13 -24
  306. package/dist/agent/production-agent.js.map +1 -1
  307. package/dist/agent/run-loop-with-resume.js +1 -1
  308. package/dist/agent/run-loop-with-resume.js.map +1 -1
  309. package/dist/agent/run-manager.d.ts.map +1 -1
  310. package/dist/agent/run-manager.js +39 -10
  311. package/dist/agent/run-manager.js.map +1 -1
  312. package/dist/agent/run-store.d.ts +10 -0
  313. package/dist/agent/run-store.d.ts.map +1 -1
  314. package/dist/agent/run-store.js +20 -3
  315. package/dist/agent/run-store.js.map +1 -1
  316. package/dist/agent/thread-data-builder.d.ts.map +1 -1
  317. package/dist/agent/thread-data-builder.js +28 -4
  318. package/dist/agent/thread-data-builder.js.map +1 -1
  319. package/dist/cli/templates-meta.d.ts.map +1 -1
  320. package/dist/cli/templates-meta.js +13 -0
  321. package/dist/cli/templates-meta.js.map +1 -1
  322. package/dist/cli/workspace-dev.d.ts.map +1 -1
  323. package/dist/cli/workspace-dev.js +1 -0
  324. package/dist/cli/workspace-dev.js.map +1 -1
  325. package/dist/client/error-format.d.ts.map +1 -1
  326. package/dist/client/error-format.js +10 -0
  327. package/dist/client/error-format.js.map +1 -1
  328. package/dist/collab/awareness.d.ts +2 -2
  329. package/dist/collab/awareness.d.ts.map +1 -1
  330. package/dist/credentials/index.d.ts +9 -2
  331. package/dist/credentials/index.d.ts.map +1 -1
  332. package/dist/credentials/index.js +50 -8
  333. package/dist/credentials/index.js.map +1 -1
  334. package/dist/extensions/url-safety.d.ts.map +1 -1
  335. package/dist/extensions/url-safety.js +38 -12
  336. package/dist/extensions/url-safety.js.map +1 -1
  337. package/dist/integrations/adapters/slack.d.ts.map +1 -1
  338. package/dist/integrations/adapters/slack.js +25 -8
  339. package/dist/integrations/adapters/slack.js.map +1 -1
  340. package/dist/integrations/google-docs-poller.d.ts.map +1 -1
  341. package/dist/integrations/google-docs-poller.js +13 -1
  342. package/dist/integrations/google-docs-poller.js.map +1 -1
  343. package/dist/integrations/installations-store.d.ts +10 -0
  344. package/dist/integrations/installations-store.d.ts.map +1 -1
  345. package/dist/integrations/installations-store.js +24 -0
  346. package/dist/integrations/installations-store.js.map +1 -1
  347. package/dist/integrations/plugin.d.ts.map +1 -1
  348. package/dist/integrations/plugin.js +6 -5
  349. package/dist/integrations/plugin.js.map +1 -1
  350. package/dist/integrations/types.d.ts +7 -0
  351. package/dist/integrations/types.d.ts.map +1 -1
  352. package/dist/integrations/types.js.map +1 -1
  353. package/dist/integrations/webhook-handler.d.ts.map +1 -1
  354. package/dist/integrations/webhook-handler.js +16 -1
  355. package/dist/integrations/webhook-handler.js.map +1 -1
  356. package/dist/jobs/background-automation-runner.d.ts.map +1 -1
  357. package/dist/jobs/background-automation-runner.js +35 -2
  358. package/dist/jobs/background-automation-runner.js.map +1 -1
  359. package/dist/mcp/screen-memory-stdio.d.ts +7 -7
  360. package/dist/mcp/screen-memory-stdio.d.ts.map +1 -1
  361. package/dist/notifications/routes.d.ts +3 -3
  362. package/dist/observability/routes.d.ts +3 -3
  363. package/dist/provider-api/actions/custom-provider-registration.d.ts +14 -14
  364. package/dist/provider-api/actions/provider-api.d.ts +8 -8
  365. package/dist/provider-api/index.js +7 -3
  366. package/dist/provider-api/index.js.map +1 -1
  367. package/dist/scripts/call-agent.d.ts.map +1 -1
  368. package/dist/scripts/call-agent.js +6 -1
  369. package/dist/scripts/call-agent.js.map +1 -1
  370. package/dist/server/agent-chat-plugin.d.ts.map +1 -1
  371. package/dist/server/agent-chat-plugin.js +25 -7
  372. package/dist/server/agent-chat-plugin.js.map +1 -1
  373. package/dist/server/agent-discovery.d.ts +2 -0
  374. package/dist/server/agent-discovery.d.ts.map +1 -1
  375. package/dist/server/agent-discovery.js.map +1 -1
  376. package/dist/server/builder-design-systems.d.ts +4 -1
  377. package/dist/server/builder-design-systems.d.ts.map +1 -1
  378. package/dist/server/builder-design-systems.js +11 -1
  379. package/dist/server/builder-design-systems.js.map +1 -1
  380. package/dist/server/credential-provider.d.ts.map +1 -1
  381. package/dist/server/credential-provider.js +49 -12
  382. package/dist/server/credential-provider.js.map +1 -1
  383. package/dist/server/index.d.ts +1 -1
  384. package/dist/server/index.d.ts.map +1 -1
  385. package/dist/server/index.js.map +1 -1
  386. package/dist/server/onboarding-html.d.ts.map +1 -1
  387. package/dist/server/onboarding-html.js +37 -2
  388. package/dist/server/onboarding-html.js.map +1 -1
  389. package/dist/server/transcribe-voice.d.ts +1 -1
  390. package/dist/shared/reasoning-effort.d.ts +1 -0
  391. package/dist/shared/reasoning-effort.d.ts.map +1 -1
  392. package/dist/shared/reasoning-effort.js +1 -1
  393. package/dist/shared/reasoning-effort.js.map +1 -1
  394. package/dist/templates/chat/app/components/layout/Sidebar.tsx +30 -3
  395. package/dist/templates/chat/changelog/2026-07-31-clicking-the-agent-native-logo-now-toggles-the-app-sidebar.md +6 -0
  396. package/dist/templates/workspace-core/.agents/skills/a2a-protocol/SKILL.md +11 -0
  397. package/package.json +1 -1
  398. package/src/a2a/correlation.ts +11 -1
  399. package/src/a2a/types.ts +11 -3
  400. package/src/agent/engine/ai-sdk-engine.ts +33 -46
  401. package/src/agent/engine/builder-engine.ts +22 -10
  402. package/src/agent/engine/error-detail.ts +184 -3
  403. package/src/agent/engine/failure-taxonomy.ts +123 -0
  404. package/src/agent/engine/index.ts +8 -0
  405. package/src/agent/engine/registry.ts +92 -8
  406. package/src/agent/engine/translate-ai-sdk.ts +17 -2
  407. package/src/agent/production-agent.ts +13 -33
  408. package/src/agent/run-loop-with-resume.ts +1 -1
  409. package/src/agent/run-manager.ts +43 -14
  410. package/src/agent/run-store.ts +30 -3
  411. package/src/agent/thread-data-builder.ts +36 -4
  412. package/src/cli/templates-meta.ts +13 -0
  413. package/src/cli/workspace-dev.ts +1 -0
  414. package/src/client/error-format.ts +12 -0
  415. package/src/credentials/index.ts +51 -12
  416. package/src/extensions/url-safety.ts +46 -12
  417. package/src/integrations/adapters/slack.ts +32 -10
  418. package/src/integrations/google-docs-poller.ts +12 -1
  419. package/src/integrations/installations-store.ts +30 -0
  420. package/src/integrations/plugin.ts +5 -5
  421. package/src/integrations/types.ts +7 -0
  422. package/src/integrations/webhook-handler.ts +24 -1
  423. package/src/jobs/background-automation-runner.ts +38 -1
  424. package/src/provider-api/index.ts +8 -2
  425. package/src/scripts/call-agent.ts +6 -0
  426. package/src/server/agent-chat-plugin.ts +30 -9
  427. package/src/server/agent-discovery.ts +2 -0
  428. package/src/server/builder-design-systems.ts +21 -0
  429. package/src/server/credential-provider.ts +51 -12
  430. package/src/server/index.ts +1 -0
  431. package/src/server/onboarding-html.ts +37 -2
  432. package/src/shared/reasoning-effort.ts +1 -1
  433. package/src/templates/chat/app/components/layout/Sidebar.tsx +30 -3
  434. package/src/templates/chat/changelog/2026-07-31-clicking-the-agent-native-logo-now-toggles-the-app-sidebar.md +6 -0
  435. package/src/templates/workspace-core/.agents/skills/a2a-protocol/SKILL.md +11 -0
  436. 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,U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AE,MAAM,CAAA;CAAE,CAAC;AAElC;;;;;GAKG;AACH,wBAAsB,6BAA6B,CACjD,UAAU,EAAE,MAAM,EAClB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,4BAA4B,CAAC,CA0DvC;AAED,wBAAsB,mCAAmC,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,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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AK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAElC,MAAM,MAAM,kCAAkC,GAC1C;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,2BAA2B,CAAA;CAAE,GACnD;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAElC;;;;;GAKG;AACH,wBAAsB,6BAA6B,CACjD,UAAU,EAAE,MAAM,EAClB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,4BAA4B,CAAC,CA0DvC;AAED,wBAAsB,mCAAmC,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,m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O,GAAG,iBAAiB,CAAC,UAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;YACpE,IAAI,CAAC,OAAO,EAAE,mBAAmB,EAAE,CAAC;gBAClC,MAAM,IAAI,KAAK,CACb,4CAA4C,UAAU,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAC/E,CAAC;YACJ,CAAC;YACD,MAAM,OAAO,CAAC,mBAAmB,CAC/B,OAAO,CAAC,mBAAmB,CAAC,YAAY,CAAC,EACzC;gBACE,WAAW,EAAE,UAAU,CAAC,IAAI,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 { 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,yBAA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M,CAAC,mCAAmC,CAAC,CAAC;YACpD,MAAM,OAAO,GAAG,iBAAiB,CAAC,UAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;YACpE,IAAI,CAAC,OAAO,EAAE,mBAAmB,EAAE,CAAC;gBAClC,MAAM,IAAI,KAAK,CACb,4CAA4C,UAAU,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAC/E,CAAC;YACJ,CAAC;YACD,MAAM,OAAO,CAAC,mBAAmB,CAC/B,OAAO,CAAC,mBAAmB,CAAC,YAAY,CAAC,EACzC;gBACE,WAAW,EAAE,UAAU,CAAC,IAAI,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"]}
@@ -137,13 +137,13 @@ export declare function screenMemoryMcpToolDefinitions(): ({
137
137
  inputSchema: {
138
138
  type: string;
139
139
  properties: {
140
- count?: undefined;
141
140
  query?: undefined;
142
141
  minutes?: undefined;
143
142
  limit?: undefined;
144
143
  clientHint?: undefined;
145
144
  timestamp?: undefined;
146
145
  chapterId?: undefined;
146
+ count?: undefined;
147
147
  startAt?: undefined;
148
148
  endAt?: undefined;
149
149
  reason?: undefined;
@@ -159,7 +159,6 @@ export declare function screenMemoryMcpToolDefinitions(): ({
159
159
  inputSchema: {
160
160
  type: string;
161
161
  properties: {
162
- count?: undefined;
163
162
  query: {
164
163
  type: string;
165
164
  description: string;
@@ -175,6 +174,7 @@ export declare function screenMemoryMcpToolDefinitions(): ({
175
174
  clientHint?: undefined;
176
175
  timestamp?: undefined;
177
176
  chapterId?: undefined;
177
+ count?: undefined;
178
178
  startAt?: undefined;
179
179
  endAt?: undefined;
180
180
  reason?: undefined;
@@ -190,7 +190,6 @@ export declare function screenMemoryMcpToolDefinitions(): ({
190
190
  inputSchema: {
191
191
  type: string;
192
192
  properties: {
193
- count?: undefined;
194
193
  minutes: {
195
194
  type: string;
196
195
  description: string;
@@ -200,6 +199,7 @@ export declare function screenMemoryMcpToolDefinitions(): ({
200
199
  clientHint?: undefined;
201
200
  timestamp?: undefined;
202
201
  chapterId?: undefined;
202
+ count?: undefined;
203
203
  startAt?: undefined;
204
204
  endAt?: undefined;
205
205
  reason?: undefined;
@@ -216,7 +216,6 @@ export declare function screenMemoryMcpToolDefinitions(): ({
216
216
  type: string;
217
217
  required: string[];
218
218
  properties: {
219
- count?: undefined;
220
219
  query: {
221
220
  type: string;
222
221
  description: string;
@@ -235,6 +234,7 @@ export declare function screenMemoryMcpToolDefinitions(): ({
235
234
  };
236
235
  timestamp?: undefined;
237
236
  chapterId?: undefined;
237
+ count?: undefined;
238
238
  startAt?: undefined;
239
239
  endAt?: undefined;
240
240
  reason?: undefined;
@@ -250,7 +250,6 @@ export declare function screenMemoryMcpToolDefinitions(): ({
250
250
  type: string;
251
251
  required: string[];
252
252
  properties: {
253
- count?: undefined;
254
253
  query?: undefined;
255
254
  minutes?: undefined;
256
255
  limit?: undefined;
@@ -264,6 +263,7 @@ export declare function screenMemoryMcpToolDefinitions(): ({
264
263
  description: string;
265
264
  };
266
265
  chapterId?: undefined;
266
+ count?: undefined;
267
267
  startAt?: undefined;
268
268
  endAt?: undefined;
269
269
  includeMicrophone?: undefined;
@@ -314,13 +314,13 @@ export declare function screenMemoryMcpToolDefinitions(): ({
314
314
  type: string;
315
315
  required: string[];
316
316
  properties: {
317
- count?: undefined;
318
317
  query?: undefined;
319
318
  minutes?: undefined;
320
319
  limit?: undefined;
321
320
  clientHint?: undefined;
322
321
  timestamp?: undefined;
323
322
  chapterId?: undefined;
323
+ count?: undefined;
324
324
  startAt: {
325
325
  type: string;
326
326
  description: string;
@@ -349,13 +349,13 @@ export declare function screenMemoryMcpToolDefinitions(): ({
349
349
  type: string;
350
350
  required: string[];
351
351
  properties: {
352
- count?: undefined;
353
352
  query?: undefined;
354
353
  minutes?: undefined;
355
354
  limit?: undefined;
356
355
  clientHint?: undefined;
357
356
  timestamp?: undefined;
358
357
  chapterId?: undefined;
358
+ count?: undefined;
359
359
  startAt?: undefined;
360
360
  endAt?: undefined;
361
361
  reason?: undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"screen-memory-stdio.d.ts","sourceRoot":"","sources":["../../src/mcp/screen-memory-stdio.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAiBhF,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,mEAAmE;IACnE,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,qBAAqB,EAAE,MAAM,EAAE,CAAC;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACvE,SAAS,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM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,QAAQ,EAAE,KAAK,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,GACxD,IAAI,CAgBN;AAkDD,wBAAgB,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBAgBlC,IAAI;gBACJ,WAAW;;;gBAGX,IAAI;gBACJ,WAAW;;;gBAGX,IAAI;gBACJ,WAAW;;;;;;;;;;;;;;;;;;;;;;gBAaX,IAAI;gBACJ,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;gBAcX,IAAI;gBACJ,WAAW;;;gBAIX,IAAI;gBACJ,WAAW;;;gBAGX,IAAI;gBACJ,WAAW;;;gBAGX,IAAI;gBACJ,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;gBAeX,IAAI;gBACJ,WAAW;;;gBAGX,IAAI;gBACJ,WAAW;;;;;;;;;;;;;;;;;;;;;;;gBAYA,IAAI;;;;;;;;;;;gBAIf,IAAI;gBACJ,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;gBAcF,IAAI;gBAAY,WAAW;;;gBAC7B,IAAI;gBAAY,WAAW;;;gBAElC,IAAI;gBACJ,WAAW;;;gBAEQ,IAAI;;;gBACH,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;gBAWD,IAAI;;;;KAItC;AAED,wBAAsB,gCAAgC,CACpD,IAAI,EAAE,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAAC,CAAC,CAAC,EACpD,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,CAAC,UAAU,mFAavB;AAED,wBAAsB,uBAAuB,CAC3C,IAAI,GAAE,8BAAmC,GACxC,OAAO,CAAC,IAAI,CAAC,CAkaf"}
@@ -11,14 +11,14 @@
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
+ error?: undefined;
19
20
  count?: undefined;
20
21
  updated: number;
21
- error?: undefined;
22
22
  ok?: undefined;
23
23
  } | {
24
24
  count?: undefined;
@@ -26,9 +26,9 @@ export declare function createNotificationsHandler(): import("h3").EventHandlerW
26
26
  error: string;
27
27
  ok?: undefined;
28
28
  } | {
29
+ error?: undefined;
29
30
  count?: undefined;
30
31
  updated?: undefined;
31
- error?: undefined;
32
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
- error?: undefined;
66
66
  ok: boolean;
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";