@xopcai/xopc 0.0.331 → 0.0.333

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 (388) hide show
  1. package/dist/browser-ext/manifest.json +1 -1
  2. package/dist/extensions/telegram/xopc.extension.json +1 -1
  3. package/dist/gateway/static/root/assets/{agent-avatar-dicebear-B0BtF24E.js → agent-avatar-dicebear-DiI2O7lC.js} +1 -1
  4. package/dist/gateway/static/root/assets/agent-defaults-settings-panel-CVp3J969.js +1 -0
  5. package/dist/gateway/static/root/assets/{agent-plugin-dialog-DbvLXQO2.js → agent-plugin-dialog-CacyndrS.js} +1 -1
  6. package/dist/gateway/static/root/assets/agents-DXYZSuUV.js +70 -0
  7. package/dist/gateway/static/root/assets/{app-management-settings-panel-fwzTRJfP.js → app-management-settings-panel-BcszTlqr.js} +1 -1
  8. package/dist/gateway/static/root/assets/{appearance-settings-v_GGe8UZ.js → appearance-settings-B1XPe8qz.js} +1 -1
  9. package/dist/gateway/static/root/assets/{apps-page-C9ZMEuuA.js → apps-page-ZqANbUZv.js} +1 -1
  10. package/dist/gateway/static/root/assets/{archive-plugin-B6EgADeH.js → archive-plugin-MjUsJcNb.js} +1 -1
  11. package/dist/gateway/static/root/assets/{attachment-load-B4H_IFeX.js → attachment-load-DHa-BI9a.js} +1 -1
  12. package/dist/gateway/static/root/assets/{automations-page-UlVCvg4r.js → automations-page-Dsjivdxs.js} +1 -1
  13. package/dist/gateway/static/root/assets/automations-workspace-B37vs5tk.js +7 -0
  14. package/dist/gateway/static/root/assets/{binary-plugins-BxTSx30f.js → binary-plugins-DQYcuBHP.js} +1 -1
  15. package/dist/gateway/static/root/assets/{block-editor-CVzdrpjl.js → block-editor-Bx0uXbJP.js} +3 -3
  16. package/dist/gateway/static/root/assets/{browser-automation-inputs-C5s1yHOu.js → browser-automation-inputs-1ZIPGDeq.js} +1 -1
  17. package/dist/gateway/static/root/assets/{browser-automations-page-CBVD8k6O.js → browser-automations-page-CCjYipHc.js} +2 -2
  18. package/dist/gateway/static/root/assets/browser-settings-page-CSv4rvmx.js +3 -0
  19. package/dist/gateway/static/root/assets/capabilities-BnO9LV7U.js +1 -0
  20. package/dist/gateway/static/root/assets/{capabilities-page-BAT7Vvb8.js → capabilities-page-BfvDvIY1.js} +2 -2
  21. package/dist/gateway/static/root/assets/capabilities-settings-panel-CoW7-ESq.js +8 -0
  22. package/dist/gateway/static/root/assets/{capability-header-actions-EETjXmkG.js → capability-header-actions-D_hbWRRF.js} +1 -1
  23. package/dist/gateway/static/root/assets/channels-BhMaRh1x.js +1 -0
  24. package/dist/gateway/static/root/assets/{chat-terminal-dock-DCqm9j9W.js → chat-terminal-dock-Fnum_IEm.js} +1 -1
  25. package/dist/gateway/static/root/assets/{computer-settings-page-CxFWdovV.js → computer-settings-page-DI1zfCTA.js} +1 -1
  26. package/dist/gateway/static/root/assets/{connector-service-page-wxsEhmlU.js → connector-service-page-CiGDAubm.js} +1 -1
  27. package/dist/gateway/static/root/assets/connectors-page-Ono0Pha1.js +2 -0
  28. package/dist/gateway/static/root/assets/{date-picker-h_OS6uBR.js → date-picker-D-JhzZyW.js} +1 -1
  29. package/dist/gateway/static/root/assets/{dependency-picker-DNgSSH3z.js → dependency-picker-DpD3xaEB.js} +1 -1
  30. package/dist/gateway/static/root/assets/{desktop-pet-CflvPnB-.js → desktop-pet-CCoDxKqh.js} +1 -1
  31. package/dist/gateway/static/root/assets/{desktop-pet-settings-CXy0X5Js.js → desktop-pet-settings-GxndKfCx.js} +1 -1
  32. package/dist/gateway/static/root/assets/{device-pairing-wizard-BDMiJcsK.js → device-pairing-wizard-B71w3ptm.js} +1 -1
  33. package/dist/gateway/static/root/assets/{directory-picker-path-field-BqkOh13m.js → directory-picker-path-field-CUzjJvjs.js} +1 -1
  34. package/dist/gateway/static/root/assets/{extension-debug-page-VT4s-9pK.js → extension-debug-page-BtDY8ntX.js} +1 -1
  35. package/dist/gateway/static/root/assets/{extension-page-CBSeGhGA.js → extension-page-D9_XF-XC.js} +1 -1
  36. package/dist/gateway/static/root/assets/{extension-settings-page-DRB6uOo8.js → extension-settings-page-CjhUFAaC.js} +1 -1
  37. package/dist/gateway/static/root/assets/{gateway-config-swr-cR-tz7-Q.js → gateway-config-swr-CgIjCxM8.js} +1 -1
  38. package/dist/gateway/static/root/assets/{gateway-settings-lF-FpnZy.js → gateway-settings-BWaCnwT1.js} +1 -1
  39. package/dist/gateway/static/root/assets/{gateway-startup-retry-6jLRcQsu.js → gateway-startup-retry-i-1lTrwY.js} +1 -1
  40. package/dist/gateway/static/root/assets/home-page-BTjGLngn.js +1 -0
  41. package/dist/gateway/static/root/assets/{image-generation-api-CSSkwsyC.js → image-generation-api-gilc-u7M.js} +1 -1
  42. package/dist/gateway/static/root/assets/{imports-page-DGkOijwE.js → imports-page-BEtq5BRU.js} +1 -1
  43. package/dist/gateway/static/root/assets/index-DHL16aYZ.js +121 -0
  44. package/dist/gateway/static/root/assets/index-N1e6PDwx.css +1 -0
  45. package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-iU6c2zg1.js → keyboard-shortcuts-settings-JUYY_18v.js} +1 -1
  46. package/dist/gateway/static/root/assets/local-app-workbench-page-uI7mtoVz.js +1 -0
  47. package/dist/gateway/static/root/assets/{local-apps-page-C0BWC8D2.js → local-apps-page-BlYESNqz.js} +1 -1
  48. package/dist/gateway/static/root/assets/{locale-store-wNXWkWu5.js → locale-store-BY30D6tg.js} +1 -1
  49. package/dist/gateway/static/root/assets/{logs-page-Dpoi-r-_.js → logs-page-BbLQreeN.js} +2 -2
  50. package/dist/gateway/static/root/assets/management-settings-c4krhYU7.js +1 -0
  51. package/dist/gateway/static/root/assets/{markdown-view-DlT9KqwF.js → markdown-view-BEeXMfDw.js} +1 -1
  52. package/dist/gateway/static/root/assets/{media-plugins-C8E_F2F_.js → media-plugins-DEFN1I73.js} +1 -1
  53. package/dist/gateway/static/root/assets/messages-_6IXbP2u.js +3 -0
  54. package/dist/gateway/static/root/assets/note-detail-panel--09xGxyE.js +5 -0
  55. package/dist/gateway/static/root/assets/notes-page-DsxcVBXF.js +8 -0
  56. package/dist/gateway/static/root/assets/{page-context-capture-button-qqWG_gs_.js → page-context-capture-button-D43aVpCj.js} +1 -1
  57. package/dist/gateway/static/root/assets/{page-tabs-b3lheKy4.js → page-tabs-BhYBCqls.js} +1 -1
  58. package/dist/gateway/static/root/assets/{preview-open-alternatives-0Q4rTfGX.js → preview-open-alternatives-CP8agNlc.js} +1 -1
  59. package/dist/gateway/static/root/assets/{product-open-page-jnJZCrKQ.js → product-open-page-CU7fRhfT.js} +1 -1
  60. package/dist/gateway/static/root/assets/project-detail-page-U-EdDfAW.js +1 -0
  61. package/dist/gateway/static/root/assets/{projects-page-r96k_2wB.js → projects-page-DUOKZLt7.js} +1 -1
  62. package/dist/gateway/static/root/assets/{registry-api-BIpltJ47.js → registry-api-BvVx0G1o.js} +1 -1
  63. package/dist/gateway/static/root/assets/{remote-access-hub-B1d8pB_y.js → remote-access-hub-fVPQe5YS.js} +1 -1
  64. package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-Do_iF13W.js → runtime-tools-settings-panel-Czvzsuj_.js} +2 -2
  65. package/dist/gateway/static/root/assets/scenes-page-C0-WHOY3.js +2 -0
  66. package/dist/gateway/static/root/assets/{schema-form-Cfft26Je.js → schema-form-B9Ni5O93.js} +1 -1
  67. package/dist/gateway/static/root/assets/sessions-page-DdXvW09N.js +1 -0
  68. package/dist/gateway/static/root/assets/settings-advanced-gate-BtF83fBY.js +1 -0
  69. package/dist/gateway/static/root/assets/{settings-form-section-iI0MTyuU.js → settings-form-section-jquf1P7n.js} +1 -1
  70. package/dist/gateway/static/root/assets/{settings-page-C2Ka9oJm.js → settings-page-DPomsvba.js} +1 -1
  71. package/dist/gateway/static/root/assets/{setup-status-panel-nnmS_p5h.js → setup-status-panel-BvVlqpHf.js} +1 -1
  72. package/dist/gateway/static/root/assets/{share-preview-page-D0Knvtlp.js → share-preview-page-b9DI0N1J.js} +1 -1
  73. package/dist/gateway/static/root/assets/shares-settings-R_qwc4DN.js +1 -0
  74. package/dist/gateway/static/root/assets/{skill-api-BuZKcy9b.js → skill-api-Bu7-3w-L.js} +1 -1
  75. package/dist/gateway/static/root/assets/skill-reload-api-CNJAQ_e-.js +1 -0
  76. package/dist/gateway/static/root/assets/{skills-page-DcxWxIrR.js → skills-page-D7XPEQu_.js} +1 -1
  77. package/dist/gateway/static/root/assets/{system-settings-panel-CMG0ZAsd.js → system-settings-panel-BwFR0Uci.js} +1 -1
  78. package/dist/gateway/static/root/assets/task-detail-page-PFjGW2g1.js +1 -0
  79. package/dist/gateway/static/root/assets/{tunnel-api-DGYA6GyO.js → tunnel-api-PfucxMP3.js} +1 -1
  80. package/dist/gateway/static/root/assets/usage-page-t_zdQHcy.js +1 -0
  81. package/dist/gateway/static/root/assets/{use-autosave-CDemMoSX.js → use-autosave-DLyy2wHz.js} +1 -1
  82. package/dist/gateway/static/root/assets/user-model-page-OyfPVfB9.js +2 -0
  83. package/dist/gateway/static/root/assets/{voice-api-key-field-CXArY4t5.js → voice-api-key-field-CQDY5EBK.js} +1 -1
  84. package/dist/gateway/static/root/assets/{voice-config-api-ujEySjyc.js → voice-config-api-Bwy3Al3J.js} +1 -1
  85. package/dist/gateway/static/root/assets/{work-discovery-overlay-Dk5KsKOm.js → work-discovery-overlay-CJzqJ47I.js} +1 -1
  86. package/dist/gateway/static/root/assets/{workflow-run-setup-panel-DNpdaI-2.js → workflow-run-setup-panel-sCOk-esV.js} +2 -2
  87. package/dist/gateway/static/root/assets/workflows-page-DYBGjN7C.js +6 -0
  88. package/dist/gateway/static/root/index.html +9 -9
  89. package/dist/package.js +1 -1
  90. package/dist/packages/gateway-contract/src/automations.js +59 -14
  91. package/dist/packages/gateway-contract/src/capabilities.js +106 -8
  92. package/dist/packages/gateway-contract/src/index.js +2 -0
  93. package/dist/packages/gateway-contract/src/scenes.js +7 -6
  94. package/dist/packages/gateway-contract/src/sessions.js +2 -1
  95. package/dist/packages/gateway-contract/src/usage.js +6 -0
  96. package/dist/src/agent/agent-manager.js +13 -7
  97. package/dist/src/agent/background-review/run-background-review.js +7 -2
  98. package/dist/src/agent/bootstrap/filter-bootstrap-files.js +1 -1
  99. package/dist/src/agent/embedded/run-turn.js +7 -1
  100. package/dist/src/agent/external-tools/endpoint-provider.js +2 -2
  101. package/dist/src/agent/external-tools/gateway-tools.d.ts +2 -1
  102. package/dist/src/agent/external-tools/gateway-tools.js +44 -11
  103. package/dist/src/agent/external-tools/index.js +1 -1
  104. package/dist/src/agent/image/tool-model-config.js +1 -1
  105. package/dist/src/agent/image/understanding/pi-ai-provider.js +1 -1
  106. package/dist/src/agent/memory/compaction.js +4 -0
  107. package/dist/src/agent/orchestration/agent-orchestrator.js +0 -21
  108. package/dist/src/agent/service/btw-query.js +8 -2
  109. package/dist/src/agent/service.js +3 -3
  110. package/dist/src/agent/skills/filesystem-watcher.js +1 -1
  111. package/dist/src/agent/skills/hub-pull.js +2 -2
  112. package/dist/src/agent/skills/marketplace/adapters/store/adapter.js +1 -1
  113. package/dist/src/agent/skills/marketplace/adapters/store/store-api-client.js +1 -1
  114. package/dist/src/agent/tasks/task-judge-service.js +4 -0
  115. package/dist/src/agent/tool-manuals/xopc-use.d.ts +1 -1
  116. package/dist/src/agent/tool-manuals/xopc-use.js +5 -4
  117. package/dist/src/agent/tools/automation-tool.d.ts +4 -1
  118. package/dist/src/agent/tools/automation-tool.js +42 -4
  119. package/dist/src/agent/tools/session-search-tool.js +1 -1
  120. package/dist/src/agent/tools/web-extract.js +1 -1
  121. package/dist/src/agent/tools/xopc-use-tool.js +50 -9
  122. package/dist/src/agent-catalog/capabilities.js +2 -2
  123. package/dist/src/ai-assist/text-assist.js +5 -1
  124. package/dist/src/auth/credentials.js +1 -1
  125. package/dist/src/auth/oauth-provider-lock.js +1 -1
  126. package/dist/src/auth/sync-provider-auth.js +1 -1
  127. package/dist/src/automations/api/routes.js +65 -0
  128. package/dist/src/automations/capabilities/drafts.js +1 -1
  129. package/dist/src/automations/capabilities/read.js +24 -0
  130. package/dist/src/automations/capabilities/write.d.ts +69 -14
  131. package/dist/src/automations/capabilities/write.js +78 -5
  132. package/dist/src/automations/delivery/delivery-router.d.ts +50 -0
  133. package/dist/src/automations/delivery/delivery-router.js +318 -0
  134. package/dist/src/automations/delivery/index.d.ts +1 -0
  135. package/dist/src/automations/delivery/index.js +2 -0
  136. package/dist/src/automations/domain/defaults.d.ts +0 -1
  137. package/dist/src/automations/domain/defaults.js +2 -2
  138. package/dist/src/automations/domain/index.js +2 -2
  139. package/dist/src/automations/domain/types.d.ts +180 -7
  140. package/dist/src/automations/domain/validation.d.ts +172 -22
  141. package/dist/src/automations/domain/validation.js +82 -13
  142. package/dist/src/automations/draft/automation-draft-prompt.js +3 -4
  143. package/dist/src/automations/draft/automation-draft-service.js +6 -0
  144. package/dist/src/automations/draft/automation-draft-validator.d.ts +31 -3
  145. package/dist/src/automations/draft/automation-draft-validator.js +5 -4
  146. package/dist/src/automations/events/event-catalog.d.ts +14 -0
  147. package/dist/src/automations/events/event-catalog.js +117 -0
  148. package/dist/src/automations/events/event-dispatcher.d.ts +27 -0
  149. package/dist/src/automations/events/event-dispatcher.js +140 -0
  150. package/dist/src/automations/events/event-repository.d.ts +59 -0
  151. package/dist/src/automations/events/event-repository.js +361 -0
  152. package/dist/src/automations/events/index.d.ts +3 -0
  153. package/dist/src/automations/events/index.js +4 -0
  154. package/dist/src/automations/index.d.ts +3 -1
  155. package/dist/src/automations/index.js +9 -3
  156. package/dist/src/automations/service/action-executor.d.ts +20 -1
  157. package/dist/src/automations/service/action-executor.js +80 -24
  158. package/dist/src/automations/service/automation-service.d.ts +21 -4
  159. package/dist/src/automations/service/automation-service.js +150 -100
  160. package/dist/src/automations/storage/automation-repository.js +7 -7
  161. package/dist/src/automations/storage/automation-run-repository.d.ts +1 -0
  162. package/dist/src/automations/storage/automation-run-repository.js +26 -1
  163. package/dist/src/automations/storage/index.js +2 -2
  164. package/dist/src/automations/webhook-secrets.d.ts +1 -0
  165. package/dist/src/automations/webhook-secrets.js +16 -0
  166. package/dist/src/bootstrap/application-state.js +1 -1
  167. package/dist/src/capabilities/runtime/dispatcher.js +1 -1
  168. package/dist/src/capabilities/runtime/product.js +1 -1
  169. package/dist/src/capabilities/store-connector.d.ts +17 -1
  170. package/dist/src/capabilities/store-connector.js +69 -3
  171. package/dist/src/chat-commands/agent-edit.js +1 -1
  172. package/dist/src/chat-commands/builtins/config.js +1 -1
  173. package/dist/src/cli/commands/agent.js +1 -1
  174. package/dist/src/cli/commands/agents.js +1 -1
  175. package/dist/src/cli/commands/connectors.js +4 -3
  176. package/dist/src/cli/commands/doctor/checks/automation-integrity.d.ts +2 -0
  177. package/dist/src/cli/commands/doctor/checks/automation-integrity.js +55 -0
  178. package/dist/src/cli/commands/doctor/checks/database-relations.d.ts +2 -0
  179. package/dist/src/cli/commands/doctor/checks/database-relations.js +81 -0
  180. package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
  181. package/dist/src/cli/commands/doctor/flow.js +5 -1
  182. package/dist/src/cli/commands/extension-marketplace.js +1 -1
  183. package/dist/src/cli/commands/models.js +1 -1
  184. package/dist/src/cli/commands/onboard/model.js +2 -2
  185. package/dist/src/cli/commands/skills.js +1 -1
  186. package/dist/src/cli/utils/init-workspace-core.js +1 -1
  187. package/dist/src/config/index.js +4 -4
  188. package/dist/src/config/loader.js +2 -2
  189. package/dist/src/config/models-json.js +1 -1
  190. package/dist/src/config/schema.d.ts +4 -0
  191. package/dist/src/config/schema.js +5 -1
  192. package/dist/src/connectors/approval-resume.js +1 -1
  193. package/dist/src/connectors/cli/store.js +1 -1
  194. package/dist/src/connectors/composio-backends.js +14 -4
  195. package/dist/src/connectors/composio-managed-events.d.ts +5 -2
  196. package/dist/src/connectors/composio-managed-events.js +4 -1
  197. package/dist/src/connectors/connection-recovery-service.d.ts +2 -1
  198. package/dist/src/connectors/connection-recovery-service.js +89 -4
  199. package/dist/src/discussions/analyzer.js +4 -4
  200. package/dist/src/extensions/agent-plugins/validation.js +1 -1
  201. package/dist/src/extensions/update.js +1 -1
  202. package/dist/src/gateway/agent-builtin-tools.d.ts +1 -1
  203. package/dist/src/gateway/agents-admin.js +2 -2
  204. package/dist/src/gateway/file-path-classifier.js +1 -1
  205. package/dist/src/gateway/home-intelligence-automation-reconciler.d.ts +3 -0
  206. package/dist/src/gateway/home-intelligence-automation-reconciler.js +52 -0
  207. package/dist/src/gateway/hono/lib/config-payload.js +1 -1
  208. package/dist/src/gateway/hono/routes/capabilities.js +1 -1
  209. package/dist/src/gateway/hono/routes/config-patch/misc.js +18 -4
  210. package/dist/src/gateway/hono/routes/connection-waits.js +3 -2
  211. package/dist/src/gateway/hono/routes/home.js +0 -1
  212. package/dist/src/gateway/hono/routes/lazy-bundles.js +14 -1
  213. package/dist/src/gateway/hono/routes/notes.js +2 -2
  214. package/dist/src/gateway/hono/routes/projects.js +2 -2
  215. package/dist/src/gateway/hono/routes/public-gateway.js +93 -3
  216. package/dist/src/gateway/hono/routes/scenes.js +57 -41
  217. package/dist/src/gateway/hono/routes/session-input-handler.js +1 -1
  218. package/dist/src/gateway/hono/routes/sessions.js +15 -0
  219. package/dist/src/gateway/hono/routes/tasks.js +1 -1
  220. package/dist/src/gateway/hono/routes/update.js +6 -1
  221. package/dist/src/gateway/hono/routes/usage.d.ts +3 -0
  222. package/dist/src/gateway/hono/routes/usage.js +61 -0
  223. package/dist/src/gateway/hono/routes/voice.js +1 -1
  224. package/dist/src/gateway/image-generation-setup.js +2 -2
  225. package/dist/src/gateway/lock.js +1 -1
  226. package/dist/src/gateway/memory-maintenance-automation-reconciler.js +21 -15
  227. package/dist/src/gateway/scenes/host.js +27 -14
  228. package/dist/src/gateway/scenes/slackThreadSource.d.ts +2 -2
  229. package/dist/src/gateway/security/gateway-scopes.js +1 -0
  230. package/dist/src/gateway/service/active-execution.d.ts +19 -0
  231. package/dist/src/gateway/service/active-execution.js +16 -0
  232. package/dist/src/gateway/service/agent-runner.d.ts +4 -0
  233. package/dist/src/gateway/service/agent-runner.js +19 -1
  234. package/dist/src/gateway/service/marketplace-service.js +2 -2
  235. package/dist/src/gateway/service/run-gateway-agent.d.ts +2 -0
  236. package/dist/src/gateway/service/run-gateway-agent.js +9 -1
  237. package/dist/src/gateway/service/sessions-api.d.ts +13 -0
  238. package/dist/src/gateway/service/sessions-api.js +23 -0
  239. package/dist/src/gateway/service.d.ts +7 -3
  240. package/dist/src/gateway/service.js +108 -89
  241. package/dist/src/gateway/side-chat/run-service.js +10 -7
  242. package/dist/src/gateway/xopc-cloud-capability-setup.js +1 -1
  243. package/dist/src/home-intelligence/generator.js +4 -1
  244. package/dist/src/home-intelligence/host.d.ts +1 -1
  245. package/dist/src/home-intelligence/host.js +2 -10
  246. package/dist/src/home-intelligence/notification.js +1 -1
  247. package/dist/src/home-intelligence/repository.d.ts +1 -1
  248. package/dist/src/infra/domain-outbox-dispatcher.d.ts +0 -3
  249. package/dist/src/infra/domain-outbox-dispatcher.js +15 -7
  250. package/dist/src/infra/update-check.d.ts +8 -4
  251. package/dist/src/infra/update-check.js +43 -41
  252. package/dist/src/infra/update-startup.d.ts +7 -1
  253. package/dist/src/infra/update-startup.js +15 -6
  254. package/dist/src/local-apps/service.js +2 -2
  255. package/dist/src/memory-maintenance/index.js +2 -2
  256. package/dist/src/memory-maintenance/schedule.d.ts +0 -3
  257. package/dist/src/memory-maintenance/schedule.js +1 -8
  258. package/dist/src/notes/service.js +2 -3
  259. package/dist/src/projects/project-service.js +1 -2
  260. package/dist/src/projects/project-skill-service.js +2 -2
  261. package/dist/src/providers/model-call.d.ts +3 -2
  262. package/dist/src/providers/model-call.js +30 -5
  263. package/dist/src/providers/model-catalog-persistence.js +1 -1
  264. package/dist/src/scenes/activationAdapter.d.ts +19 -0
  265. package/dist/src/scenes/activationAdapter.js +1 -0
  266. package/dist/src/scenes/agentExecutor.js +3 -10
  267. package/dist/src/scenes/contracts.d.ts +3 -9
  268. package/dist/src/scenes/contracts.js +1 -0
  269. package/dist/src/scenes/execution.d.ts +9 -3
  270. package/dist/src/scenes/execution.js +12 -11
  271. package/dist/src/scenes/httpServices.d.ts +5 -2
  272. package/dist/src/scenes/mailContext.d.ts +4 -0
  273. package/dist/src/scenes/mailContext.js +9 -0
  274. package/dist/src/scenes/maintenance.js +1 -5
  275. package/dist/src/scenes/metrics.d.ts +0 -6
  276. package/dist/src/scenes/metrics.js +0 -11
  277. package/dist/src/scenes/registry.d.ts +11 -0
  278. package/dist/src/scenes/registry.js +28 -0
  279. package/dist/src/scenes/repository.d.ts +6 -3
  280. package/dist/src/scenes/repository.js +43 -5
  281. package/dist/src/scenes/service.d.ts +2 -1
  282. package/dist/src/scenes/service.js +9 -7
  283. package/dist/src/scenes/taskFollowUp/contracts.d.ts +37 -7
  284. package/dist/src/scenes/taskFollowUp/contracts.js +36 -17
  285. package/dist/src/scenes/taskFollowUp/service.d.ts +35 -7
  286. package/dist/src/scenes/taskFollowUp/service.js +86 -28
  287. package/dist/src/scenes/templates.d.ts +2 -2
  288. package/dist/src/scenes/userNotes.d.ts +3 -0
  289. package/dist/src/scenes/userNotes.js +6 -0
  290. package/dist/src/session/client-history.d.ts +3 -0
  291. package/dist/src/session/client-history.js +10 -5
  292. package/dist/src/session/manager.d.ts +1 -0
  293. package/dist/src/session/resolve-session.js +4 -3
  294. package/dist/src/session/session-title.js +1 -1
  295. package/dist/src/session/store.d.ts +1 -0
  296. package/dist/src/session/store.js +3 -2
  297. package/dist/src/storage/sqlite/ai-usage-repository.d.ts +137 -0
  298. package/dist/src/storage/sqlite/ai-usage-repository.js +175 -0
  299. package/dist/src/storage/sqlite/connector-account-repository.js +7 -5
  300. package/dist/src/storage/sqlite/connector-repository.js +36 -34
  301. package/dist/src/storage/sqlite/index.d.ts +2 -2
  302. package/dist/src/storage/sqlite/index.js +3 -3
  303. package/dist/src/storage/sqlite/migrations/208_automation_management.sql +2 -0
  304. package/dist/src/storage/sqlite/migrations/209_automation_event_hub.sql +48 -0
  305. package/dist/src/storage/sqlite/migrations/210_remove_legacy_automation_timeout.sql +14 -0
  306. package/dist/src/storage/sqlite/migrations/211_automation_result_deliveries.sql +16 -0
  307. package/dist/src/storage/sqlite/migrations/212_automation_delivery_policy.sql +30 -0
  308. package/dist/src/storage/sqlite/migrations/213_automation_reliability_contract.sql +188 -0
  309. package/dist/src/storage/sqlite/migrations/214_ai_usage_ledger.sql +41 -0
  310. package/dist/src/storage/sqlite/migrations/215_scene_execution_adapters.sql +6 -0
  311. package/dist/src/storage/sqlite/migrations/216_remove_scene_model_usage.sql +1 -0
  312. package/dist/src/storage/sqlite/migrations/217_remove_legacy_memory_tables.sql +4 -0
  313. package/dist/src/storage/sqlite/migrations/218_core_relation_indexes.sql +26 -0
  314. package/dist/src/storage/sqlite/migrations/219_json_contracts.sql +123 -0
  315. package/dist/src/storage/sqlite/migrations/220_normalize_timestamps.sql +339 -0
  316. package/dist/src/storage/sqlite/migrations/221_ai_usage_retention_index.sql +2 -0
  317. package/dist/src/storage/sqlite/migrations/222_session_config_authority.sql +13 -0
  318. package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
  319. package/dist/src/storage/sqlite/migrations/runner.js +4 -4
  320. package/dist/src/storage/sqlite/row-mappers.d.ts +3 -7
  321. package/dist/src/storage/sqlite/row-mappers.js +6 -6
  322. package/dist/src/storage/sqlite/scenes-schema.d.ts +1 -1
  323. package/dist/src/storage/sqlite/scenes-schema.js +0 -1
  324. package/dist/src/storage/sqlite/schema.js +1 -1
  325. package/dist/src/storage/sqlite/schema.sql +0 -52
  326. package/dist/src/storage/sqlite/schemas/scenes.sql +0 -7
  327. package/dist/src/storage/sqlite/session-input-repository.d.ts +8 -0
  328. package/dist/src/storage/sqlite/session-input-repository.js +18 -1
  329. package/dist/src/storage/sqlite/session-read-repository.d.ts +1 -1
  330. package/dist/src/storage/sqlite/session-read-repository.js +0 -1
  331. package/dist/src/storage/sqlite/session-repository.d.ts +0 -4
  332. package/dist/src/storage/sqlite/session-repository.js +8 -18
  333. package/dist/src/storage/sqlite/timestamps.d.ts +4 -0
  334. package/dist/src/storage/sqlite/timestamps.js +20 -0
  335. package/dist/src/storage/sqlite/transcript-repository.d.ts +1 -0
  336. package/dist/src/storage/sqlite/transcript-repository.js +23 -15
  337. package/dist/src/storage/sqlite/user-trust-repository.js +4 -2
  338. package/dist/src/tasks/capabilities/read.js +2 -2
  339. package/dist/src/tasks/capabilities/write.d.ts +1 -1
  340. package/dist/src/tasks/home-query-service.js +4 -3
  341. package/dist/src/tasks/task-contract-planner.js +1 -1
  342. package/dist/src/tui/backends/embedded-backend.js +2 -2
  343. package/dist/src/tui/tui-commands.js +1 -1
  344. package/dist/src/tui/tui-startup-resources.js +1 -1
  345. package/dist/src/tui/tui.js +1 -1
  346. package/dist/src/usage/cost.d.ts +4 -0
  347. package/dist/src/usage/cost.js +28 -0
  348. package/dist/src/usage/recorder.d.ts +13 -0
  349. package/dist/src/usage/recorder.js +117 -0
  350. package/dist/src/usage/scenario-registry.d.ts +8 -0
  351. package/dist/src/usage/scenario-registry.js +117 -0
  352. package/dist/src/usage/types.d.ts +55 -0
  353. package/dist/src/usage/types.js +1 -0
  354. package/dist/src/user-context/config.d.ts +9 -0
  355. package/dist/src/user-context/config.js +13 -4
  356. package/dist/src/voice/realtime/persona-context.js +1 -1
  357. package/dist/src/voice/tts/summarize.js +1 -1
  358. package/dist/src/work-discovery/analyzer.js +2 -2
  359. package/dist/src/work-discovery/investigator.js +1 -1
  360. package/dist/src/workflows/service/workflow-run-service.js +15 -2
  361. package/package.json +6 -6
  362. package/dist/gateway/static/root/assets/agent-defaults-settings-panel-DgP5DEJF.js +0 -1
  363. package/dist/gateway/static/root/assets/agents-Bh4XNLyk.js +0 -70
  364. package/dist/gateway/static/root/assets/automations-workspace-C7VS-yb7.js +0 -7
  365. package/dist/gateway/static/root/assets/browser-settings-page-CC43CC43.js +0 -3
  366. package/dist/gateway/static/root/assets/capabilities-sAZT4brT.js +0 -1
  367. package/dist/gateway/static/root/assets/capabilities-settings-panel-DPETQOfF.js +0 -8
  368. package/dist/gateway/static/root/assets/channels-CwA619os.js +0 -1
  369. package/dist/gateway/static/root/assets/connectors-page-l7goF6QS.js +0 -2
  370. package/dist/gateway/static/root/assets/home-page-DSaXXoLm.js +0 -1
  371. package/dist/gateway/static/root/assets/index-BEw0xrde.css +0 -1
  372. package/dist/gateway/static/root/assets/index-D99vN3es.js +0 -121
  373. package/dist/gateway/static/root/assets/local-app-workbench-page-rH33N8I9.js +0 -1
  374. package/dist/gateway/static/root/assets/management-settings-RFDLaquR.js +0 -1
  375. package/dist/gateway/static/root/assets/messages-fmf0dnr4.js +0 -3
  376. package/dist/gateway/static/root/assets/note-detail-panel-DI7CIjmM.js +0 -5
  377. package/dist/gateway/static/root/assets/notes-page-BkqnU-Jh.js +0 -8
  378. package/dist/gateway/static/root/assets/project-detail-page-BvvcTH2F.js +0 -1
  379. package/dist/gateway/static/root/assets/scenes-page-DK316w9a.js +0 -2
  380. package/dist/gateway/static/root/assets/sessions-page-EIk8iJTK.js +0 -1
  381. package/dist/gateway/static/root/assets/settings-advanced-gate-DcOsdz78.js +0 -1
  382. package/dist/gateway/static/root/assets/shares-settings-BcaxGQLC.js +0 -1
  383. package/dist/gateway/static/root/assets/skill-reload-api-Cb_CUL-U.js +0 -1
  384. package/dist/gateway/static/root/assets/task-detail-page-Cvr1qUTW.js +0 -1
  385. package/dist/gateway/static/root/assets/user-model-page-VXfz3rE7.js +0 -2
  386. package/dist/gateway/static/root/assets/workflows-page-DDNDLdId.js +0 -6
  387. package/dist/src/automations/product-events.d.ts +0 -5
  388. package/dist/src/automations/product-events.js +0 -19
@@ -11,7 +11,7 @@ JSON shape:
11
11
  "action": { "kind": "agent", "instruction": "clear instruction for the agent" },
12
12
  "safety": { "mode": "suggest_only" },
13
13
  "conversationMode": "new_session",
14
- "notificationPolicy": "attention",
14
+ "delivery": { "notificationPolicy": "attention" },
15
15
  "reliability": { "executionTimeoutSeconds": 300, "disableAfterConsecutiveFailures": 3 }
16
16
  },
17
17
  "explanation": "Short explanation",
@@ -52,7 +52,7 @@ Rules:
52
52
  - Use cron for daily/weekly schedules. Use standard 5-field cron.
53
53
  - Keep executionTimeoutSeconds between 60 and 1800.
54
54
  - Use conversationMode "new_session" unless the user explicitly wants each run to continue the same conversation.
55
- - Use notificationPolicy "attention" unless the user explicitly requests every-run notifications or no notifications.
55
+ - Use delivery.notificationPolicy "attention" unless the user explicitly requests every-run notifications or no notifications.
56
56
  - Language for user-facing copy: ${params.language ?? "en"}.
57
57
 
58
58
  User request:
@@ -85,8 +85,7 @@ JSON shape:
85
85
  "action": "optional complete action object",
86
86
  "safety": "optional complete safety object",
87
87
  "conversationMode": "optional new_session or continuous",
88
- "notificationPolicy": "optional attention, all, or none",
89
- "completionWebhookUrl": "optional HTTPS URL",
88
+ "delivery": { "notificationPolicy": "optional attention, all, or none", "destinations": [{ "key": "stable key", "kind": "gateway_event or webhook", "endpoint": "HTTPS URL for webhook", "secretId": "outbound secret id for webhook" }] },
90
89
  "reliability": "optional complete reliability object",
91
90
  "enabled": true
92
91
  },
@@ -37,6 +37,9 @@ var AutomationDraftService = class {
37
37
  maxTokens: 2048,
38
38
  temperature: attempt === 0 ? .2 : .1,
39
39
  signal
40
+ }, void 0, {
41
+ operation: "automation.generate_draft",
42
+ trigger: attempt === 0 ? "user" : "retry"
40
43
  }));
41
44
  try {
42
45
  return buildAutomationDraftResponse(parseGeneratedAutomationDraft(lastText), attempt);
@@ -90,6 +93,9 @@ var AutomationDraftService = class {
90
93
  maxTokens: 2048,
91
94
  temperature: attempt === 0 ? .15 : .05,
92
95
  signal
96
+ }, void 0, {
97
+ operation: "automation.generate_draft",
98
+ trigger: attempt === 0 ? "user" : "retry"
93
99
  }));
94
100
  try {
95
101
  return parseGeneratedAutomationRepairDraft(lastText, attempt);
@@ -12,7 +12,28 @@ export declare function buildAutomationDraftResponse(draft: GeneratedAutomationD
12
12
  automation: {
13
13
  name: string;
14
14
  conversationMode: "new_session" | "continuous";
15
- notificationPolicy: "attention" | "all" | "none";
15
+ delivery: {
16
+ notificationPolicy: "attention" | "all" | "none";
17
+ destinations: ({
18
+ key: string;
19
+ kind: "gateway_event";
20
+ } | {
21
+ key: string;
22
+ kind: "webhook";
23
+ secretId: string;
24
+ endpoint?: string;
25
+ } | {
26
+ key: string;
27
+ kind: "file";
28
+ targetId: string;
29
+ pathTemplate: string;
30
+ } | {
31
+ key: string;
32
+ kind: "card";
33
+ channelId: string;
34
+ templateId: string;
35
+ })[];
36
+ };
16
37
  projectId?: string;
17
38
  action?: {
18
39
  kind: "agent";
@@ -102,6 +123,9 @@ export declare function buildAutomationDraftResponse(draft: GeneratedAutomationD
102
123
  outputDestinations: Record<string, unknown>[];
103
124
  };
104
125
  };
126
+ } | {
127
+ kind: "system";
128
+ capability: "home.advisor.refresh" | "memory.temporal_sweep" | "memory.daily_reconciliation" | "memory.weekly_knowledge";
105
129
  };
106
130
  trigger?: {
107
131
  kind: "manual";
@@ -132,14 +156,18 @@ export declare function buildAutomationDraftResponse(draft: GeneratedAutomationD
132
156
  safety?: {
133
157
  mode: "suggest_only" | "ask_before_apply" | "auto_apply";
134
158
  };
135
- completionWebhookUrl?: string;
136
159
  reliability?: {
137
160
  executionTimeoutSeconds?: number;
138
- timeoutSeconds?: number;
139
161
  retryCount?: number;
140
162
  maxConcurrentRuns?: number;
141
163
  disableAfterConsecutiveFailures?: number;
142
164
  };
165
+ management?: {
166
+ owner: string;
167
+ editable: ("enabled" | "trigger")[];
168
+ runnable: boolean;
169
+ deletable: boolean;
170
+ };
143
171
  id?: string;
144
172
  enabled?: boolean;
145
173
  state?: {
@@ -54,9 +54,9 @@ function simulateAutomation(input) {
54
54
  const triggerSummary = summarizeTrigger(automation.trigger);
55
55
  const actionSummary = summarizeAction(automation.action);
56
56
  if (automation.action.kind === "agent" && /delete|remove|send|post|publish|付款|删除|发送|发布/i.test(automation.action.instruction)) requiredConfirmations.push("Agent instruction may perform an external or destructive action.");
57
- if (automation.completionWebhookUrl) {
58
- safetyNotes.push("The completion webhook will call an external URL after each run.");
59
- requiredConfirmations.push("External webhook call should be reviewed before publishing.");
57
+ if (automation.delivery.destinations.some((destination) => destination.kind === "webhook")) {
58
+ safetyNotes.push("The result webhook will call an external URL after each run.");
59
+ requiredConfirmations.push("External result delivery should be reviewed before publishing.");
60
60
  }
61
61
  const safetyMode = automation.safety?.mode ?? "auto_apply";
62
62
  if (safetyMode === "suggest_only") safetyNotes.push("Suggest-only safety mode will generate recommendations without applying changes.");
@@ -92,11 +92,12 @@ function summarizeAction(action) {
92
92
  if (action.kind === "workflow") return `Starts workflow ${action.workflowId}.`;
93
93
  if (action.kind === "browser_automation") return `Runs browser automation ${action.automationId}.`;
94
94
  if (action.kind === "task_command") return `Applies ${action.command?.type ?? "a command"} to task ${action.taskId}.`;
95
+ if (action.kind === "system") return `Runs system capability ${action.capability}.`;
95
96
  return action.agentId ? `Runs agent ${action.agentId}.` : "Runs the default agent.";
96
97
  }
97
98
  function repairPatchNeedsApproval(patch) {
98
99
  if (patch.safety?.mode === "auto_apply") return true;
99
- if (patch.completionWebhookUrl) return true;
100
+ if (patch.delivery?.destinations.some((destination) => destination.kind === "webhook")) return true;
100
101
  if (patch.trigger?.kind === "webhook") return true;
101
102
  if (patch.action?.kind === "agent") return /delete|remove|send|post|publish|付款|删除|发送|发布/i.test(patch.action.instruction);
102
103
  return false;
@@ -0,0 +1,14 @@
1
+ import { type ZodType } from 'zod';
2
+ import type { AutomationEventEnvelope } from '../domain/types.js';
3
+ export interface BusinessEventDefinition<TPayload extends Record<string, unknown> = Record<string, unknown>> {
4
+ type: string;
5
+ source: string;
6
+ schemaVersion: number;
7
+ payloadSchema: ZodType<TPayload>;
8
+ defaultTrust: Extract<AutomationEventEnvelope['trust'], 'system' | 'user' | 'connector'>;
9
+ description: string;
10
+ subjectKind: string;
11
+ }
12
+ export declare function registerBusinessEvent<TPayload extends Record<string, unknown>>(definition: BusinessEventDefinition<TPayload>): void;
13
+ export declare function validateCatalogedBusinessEvent(event: AutomationEventEnvelope): void;
14
+ export declare function listBusinessEventDefinitions(): BusinessEventDefinition[];
@@ -0,0 +1,117 @@
1
+ import { z } from "zod";
2
+ //#region src/automations/events/event-catalog.ts
3
+ const definitions = /* @__PURE__ */ new Map();
4
+ function catalogKey(type, source, schemaVersion) {
5
+ return `${source}\0${type}\0${schemaVersion}`;
6
+ }
7
+ function registerBusinessEvent(definition) {
8
+ const key = catalogKey(definition.type, definition.source, definition.schemaVersion);
9
+ if (definitions.has(key)) throw new Error(`Business event is already registered: ${definition.source}/${definition.type}@${definition.schemaVersion}`);
10
+ definitions.set(key, definition);
11
+ }
12
+ function validateCatalogedBusinessEvent(event) {
13
+ const definition = definitions.get(catalogKey(event.type, event.source, event.schemaVersion));
14
+ if (!definition) return;
15
+ if (event.subject?.kind !== definition.subjectKind) throw new Error(`Business event subject must be ${definition.subjectKind}: ${event.type}`);
16
+ definition.payloadSchema.parse(event.payload);
17
+ }
18
+ function listBusinessEventDefinitions() {
19
+ return [...definitions.values()].toSorted((left, right) => `${left.source}/${left.type}`.localeCompare(`${right.source}/${right.type}`));
20
+ }
21
+ const objectPayload = z.record(z.string(), z.unknown());
22
+ for (const definition of [
23
+ [
24
+ "tasks",
25
+ "task.changed.v2",
26
+ "task",
27
+ "A Task changed."
28
+ ],
29
+ [
30
+ "tasks",
31
+ "task.deleted.v1",
32
+ "task",
33
+ "A Task was deleted."
34
+ ],
35
+ [
36
+ "notes",
37
+ "note.created",
38
+ "note",
39
+ "A Note was created."
40
+ ],
41
+ [
42
+ "notes",
43
+ "note.updated",
44
+ "note",
45
+ "A Note changed."
46
+ ],
47
+ [
48
+ "notes",
49
+ "note.deleted",
50
+ "note",
51
+ "A Note was deleted."
52
+ ],
53
+ [
54
+ "projects",
55
+ "project.created",
56
+ "project",
57
+ "A Project was created."
58
+ ],
59
+ [
60
+ "projects",
61
+ "project.changed",
62
+ "project",
63
+ "A Project changed."
64
+ ],
65
+ [
66
+ "projects",
67
+ "project.deleted",
68
+ "project",
69
+ "A Project was deleted."
70
+ ],
71
+ [
72
+ "scenes",
73
+ "scene.created",
74
+ "scene",
75
+ "A Scene was created."
76
+ ],
77
+ [
78
+ "scenes",
79
+ "scene.changed",
80
+ "scene",
81
+ "A Scene changed."
82
+ ],
83
+ [
84
+ "scenes",
85
+ "scene.deleted",
86
+ "scene",
87
+ "A Scene was deleted."
88
+ ],
89
+ [
90
+ "discussions",
91
+ "discussion.completed",
92
+ "discussion",
93
+ "A Discussion completed."
94
+ ],
95
+ [
96
+ "sessions",
97
+ "session.transcript.updated",
98
+ "session",
99
+ "A Session transcript changed."
100
+ ],
101
+ [
102
+ "workflows",
103
+ "workflow.run.completed",
104
+ "workflow_run",
105
+ "A Workflow run completed."
106
+ ]
107
+ ]) registerBusinessEvent({
108
+ source: definition[0],
109
+ type: definition[1],
110
+ subjectKind: definition[2],
111
+ description: definition[3],
112
+ schemaVersion: 1,
113
+ payloadSchema: objectPayload,
114
+ defaultTrust: "system"
115
+ });
116
+ //#endregion
117
+ export { listBusinessEventDefinitions, registerBusinessEvent, validateCatalogedBusinessEvent };
@@ -0,0 +1,27 @@
1
+ import type { AutomationEventEnvelope, AutomationRun } from '../domain/types.js';
2
+ import type { AutomationService } from '../service/automation-service.js';
3
+ export declare class AutomationEventDispatcher {
4
+ private readonly automationService;
5
+ private readonly options;
6
+ private timer?;
7
+ private active?;
8
+ private stopping;
9
+ private readonly owner;
10
+ private readonly abortController;
11
+ constructor(automationService: AutomationService, options?: {
12
+ onEvent?: (event: AutomationEventEnvelope, signal?: AbortSignal) => void | Promise<void>;
13
+ onDeadLetter?: (input: {
14
+ phase: 'event_projection' | 'event_delivery';
15
+ eventId: string;
16
+ automationId?: string;
17
+ error: string;
18
+ }) => void;
19
+ intervalMs?: number;
20
+ });
21
+ start(): void;
22
+ stop(): Promise<void>;
23
+ dispatch(): Promise<number>;
24
+ runCompleted(run: AutomationRun): void;
25
+ private runDispatch;
26
+ private projectEvents;
27
+ }
@@ -0,0 +1,140 @@
1
+ import { createLogger } from "../../utils/logger/index.js";
2
+ import { init_logger } from "../../utils/logger.js";
3
+ import { init_transaction, runSqliteWriteTransaction } from "../../storage/sqlite/transaction.js";
4
+ import { getAutomation } from "../storage/automation-repository.js";
5
+ import "../storage/index.js";
6
+ import { claimAutomationEventDeliveries, claimAutomationEventsForProjection, completeAutomationEventDelivery, completeAutomationEventProjection, deferAutomationEventDelivery, expireAutomationEventProjectionLeases, failAutomationEventProjection, markAutomationEventDeliveryQueued, reconcileAutomationEventDeliveries, releaseAutomationEventDelivery, releaseAutomationEventProjection, skipAutomationEventDelivery } from "./event-repository.js";
7
+ import { randomUUID } from "node:crypto";
8
+ //#region src/automations/events/event-dispatcher.ts
9
+ init_transaction();
10
+ init_logger();
11
+ const log = createLogger("AutomationEventDispatcher");
12
+ const DELIVERY_SCAN_BUDGET = 500;
13
+ var AutomationEventDispatcher = class {
14
+ timer;
15
+ active;
16
+ stopping = false;
17
+ owner = `automation-event:${process.pid}:${randomUUID()}`;
18
+ abortController = new AbortController();
19
+ constructor(automationService, options = {}) {
20
+ this.automationService = automationService;
21
+ this.options = options;
22
+ }
23
+ start() {
24
+ if (this.timer) return;
25
+ this.stopping = false;
26
+ reconcileAutomationEventDeliveries();
27
+ this.dispatch();
28
+ this.timer = setInterval(() => void this.dispatch(), this.options.intervalMs ?? 1e3);
29
+ this.timer.unref?.();
30
+ }
31
+ async stop() {
32
+ this.stopping = true;
33
+ if (this.timer) clearInterval(this.timer);
34
+ this.timer = void 0;
35
+ this.abortController.abort(/* @__PURE__ */ new Error("Automation event dispatcher stopped"));
36
+ await this.active?.catch(() => void 0);
37
+ }
38
+ dispatch() {
39
+ if (this.stopping) return Promise.resolve(0);
40
+ this.active ??= this.runDispatch().finally(() => {
41
+ this.active = void 0;
42
+ });
43
+ return this.active;
44
+ }
45
+ runCompleted(run) {
46
+ completeAutomationEventDelivery(run.id, run.status);
47
+ if (!this.stopping) this.dispatch();
48
+ }
49
+ async runDispatch() {
50
+ await this.projectEvents();
51
+ const availableSlots = this.automationService.availableRunSlots();
52
+ if (availableSlots <= 0 || this.stopping) return 0;
53
+ let queued = 0;
54
+ const deliveries = claimAutomationEventDeliveries(this.owner, DELIVERY_SCAN_BUDGET);
55
+ for (const [index, delivery] of deliveries.entries()) {
56
+ if (queued >= availableSlots || this.stopping) {
57
+ for (const remaining of deliveries.slice(index)) releaseAutomationEventDelivery(remaining.event.id, remaining.automationId, this.owner, 0);
58
+ break;
59
+ }
60
+ const automation = getAutomation(delivery.automationId);
61
+ if (!automation || !automation.enabled) {
62
+ skipAutomationEventDelivery(delivery.event.id, delivery.automationId, "Automation is unavailable", this.owner);
63
+ continue;
64
+ }
65
+ if (automation.state.runningRunId) {
66
+ releaseAutomationEventDelivery(delivery.event.id, automation.id, this.owner);
67
+ continue;
68
+ }
69
+ try {
70
+ const run = runSqliteWriteTransaction(() => {
71
+ const next = this.automationService.queueRunAtomically(automation.id, {
72
+ manual: false,
73
+ event: delivery.event
74
+ });
75
+ markAutomationEventDeliveryQueued(delivery.event.id, automation.id, next.id, this.owner);
76
+ return next;
77
+ });
78
+ this.automationService.dispatchQueuedRun(run.id);
79
+ queued += 1;
80
+ } catch (error) {
81
+ if (error instanceof Error && error.name === "AutomationAlreadyRunningError") {
82
+ releaseAutomationEventDelivery(delivery.event.id, automation.id, this.owner);
83
+ continue;
84
+ }
85
+ const status = deferAutomationEventDelivery(delivery.event.id, automation.id, this.owner, error);
86
+ if (status === "dead_letter") this.options.onDeadLetter?.({
87
+ phase: "event_delivery",
88
+ eventId: delivery.event.id,
89
+ automationId: automation.id,
90
+ error: error instanceof Error ? error.message : String(error)
91
+ });
92
+ log.warn({
93
+ err: error,
94
+ eventId: delivery.event.id,
95
+ automationId: automation.id,
96
+ status
97
+ }, status === "dead_letter" ? "Automation event delivery moved to dead letter" : "Automation event delivery will retry");
98
+ }
99
+ }
100
+ return queued;
101
+ }
102
+ async projectEvents() {
103
+ for (const expired of expireAutomationEventProjectionLeases()) {
104
+ this.options.onDeadLetter?.({
105
+ phase: "event_projection",
106
+ ...expired
107
+ });
108
+ log.warn(expired, "Automation event projection moved to dead letter after lease expiry");
109
+ }
110
+ for (const event of claimAutomationEventsForProjection(this.owner)) {
111
+ if (this.stopping) {
112
+ releaseAutomationEventProjection(event.id, this.owner);
113
+ continue;
114
+ }
115
+ try {
116
+ await this.options.onEvent?.(event, this.abortController.signal);
117
+ completeAutomationEventProjection(event.id, this.owner);
118
+ } catch (error) {
119
+ if (this.stopping || this.abortController.signal.aborted) {
120
+ releaseAutomationEventProjection(event.id, this.owner);
121
+ continue;
122
+ }
123
+ const status = failAutomationEventProjection(event.id, this.owner, error);
124
+ if (status === "dead_letter") this.options.onDeadLetter?.({
125
+ phase: "event_projection",
126
+ eventId: event.id,
127
+ error: error instanceof Error ? error.message : String(error)
128
+ });
129
+ log.warn({
130
+ err: error,
131
+ eventId: event.id,
132
+ eventType: event.type,
133
+ status
134
+ }, status === "dead_letter" ? "Automation event projection moved to dead letter" : "Automation event projection will retry");
135
+ }
136
+ }
137
+ }
138
+ };
139
+ //#endregion
140
+ export { AutomationEventDispatcher };
@@ -0,0 +1,59 @@
1
+ import type { AutomationEvent, AutomationEventDeliveryStatus, AutomationEventEnvelope, AutomationEventProjectionStatus, AutomationEventRecord, AutomationRunStatus } from '../domain/types.js';
2
+ export interface ClaimedAutomationEventDelivery {
3
+ event: AutomationEventEnvelope;
4
+ automationId: string;
5
+ attempts: number;
6
+ owner: string;
7
+ }
8
+ export interface AutomationEventIngestResult {
9
+ event: AutomationEventEnvelope;
10
+ created: boolean;
11
+ deliveryCount: number;
12
+ }
13
+ export interface AutomationEventIngestOptions {
14
+ targetAutomationIds?: string[];
15
+ }
16
+ export interface AutomationEventPublisher {
17
+ publish(input: AutomationEvent, options?: AutomationEventIngestOptions): AutomationEventIngestResult;
18
+ }
19
+ export declare function ingestAutomationEvent(input: AutomationEvent, options?: AutomationEventIngestOptions): AutomationEventIngestResult;
20
+ export declare const automationEventPublisher: AutomationEventPublisher;
21
+ export declare function listAutomationEvents(input?: {
22
+ type?: string;
23
+ source?: string;
24
+ subjectKind?: string;
25
+ subjectId?: string;
26
+ limit?: number;
27
+ newestFirst?: boolean;
28
+ }): AutomationEventEnvelope[];
29
+ export declare function listAutomationEventRecords(input?: {
30
+ type?: string;
31
+ source?: string;
32
+ limit?: number;
33
+ }): AutomationEventRecord[];
34
+ export declare function claimAutomationEventsForProjection(owner: string, limit?: number, leaseMs?: number): AutomationEventEnvelope[];
35
+ export declare function expireAutomationEventProjectionLeases(): Array<{
36
+ eventId: string;
37
+ error: string;
38
+ }>;
39
+ export declare function completeAutomationEventProjection(eventId: string, owner: string): void;
40
+ export declare function releaseAutomationEventProjection(eventId: string, owner: string): void;
41
+ export declare function failAutomationEventProjection(eventId: string, owner: string, error: unknown): AutomationEventProjectionStatus;
42
+ export declare function claimAutomationEventDeliveries(owner: string, limit: number, leaseMs?: number): ClaimedAutomationEventDelivery[];
43
+ export declare function releaseAutomationEventDelivery(eventId: string, automationId: string, owner: string, delayMs?: number): void;
44
+ export declare function getAutomationEventDeliveryRunId(eventId: string, automationId: string): string | null;
45
+ export declare function getAutomationEventForRun(runId: string): AutomationEventEnvelope | null;
46
+ export declare function markAutomationEventDeliveryQueued(eventId: string, automationId: string, runId: string, owner?: string): void;
47
+ export declare function deferAutomationEventDelivery(eventId: string, automationId: string, owner: string, error: unknown): AutomationEventDeliveryStatus;
48
+ export declare function skipAutomationEventDelivery(eventId: string, automationId: string, reason: string, owner?: string): void;
49
+ export declare function completeAutomationEventDelivery(runId: string, runStatus: AutomationRunStatus): void;
50
+ export declare function reconcileAutomationEventDeliveries(): number;
51
+ export declare function replayAutomationEvent(eventId: string): boolean;
52
+ export declare function getAutomationEventQueueMetrics(): {
53
+ pending: number;
54
+ oldestPendingAgeMs: number;
55
+ projectionDeadLetters: number;
56
+ pendingDeliveries: number;
57
+ deliveryDeadLetters: number;
58
+ activeLeases: number;
59
+ };