@xopcai/xopc 0.0.312 → 0.0.314

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 (497) hide show
  1. package/dist/browser-ext/dist/assets/{auth-C3yV1y_l.js → auth-DKo-NMUY.js} +18 -1
  2. package/dist/browser-ext/dist/background.js +68 -2
  3. package/dist/browser-ext/dist/sidepanel.html +1 -1
  4. package/dist/browser-ext/dist/sidepanel.js +1 -1
  5. package/dist/browser-ext/manifest.json +1 -1
  6. package/dist/extensions/feishu/src/outbound/media-load.js +1 -1
  7. package/dist/extensions/telegram/src/inbound-processor.js +1 -1
  8. package/dist/extensions/telegram/src/plugin.js +2 -2
  9. package/dist/extensions/telegram/xopc.extension.json +1 -1
  10. package/dist/gateway/static/root/assets/{agent-avatar-dicebear-BVIJMP8w.js → agent-avatar-dicebear-BFkjfurL.js} +1 -1
  11. package/dist/gateway/static/root/assets/agent-defaults-settings-panel-BdOZ6q8Z.js +1 -0
  12. package/dist/gateway/static/root/assets/{agents-D6g_SeWI.js → agents-CCcavsHq.js} +1 -1
  13. package/dist/gateway/static/root/assets/{api-_aHQA8bd.js → api-BYhRsTAc.js} +1 -1
  14. package/dist/gateway/static/root/assets/{app-link-CKueEVbT.js → app-link-nL8iPwEr.js} +1 -1
  15. package/dist/gateway/static/root/assets/{app-management-settings-panel-CLg_aXYG.js → app-management-settings-panel-B4kihr-A.js} +1 -1
  16. package/dist/gateway/static/root/assets/appearance-settings-N9sYmNOx.js +1 -0
  17. package/dist/gateway/static/root/assets/apps-page-BMcy10_s.js +1 -0
  18. package/dist/gateway/static/root/assets/{archive-plugin-CHO3heHX.js → archive-plugin-k_SuYWyV.js} +1 -1
  19. package/dist/gateway/static/root/assets/{attachment-load-BsmsBCI2.js → attachment-load-DRv5QWUK.js} +1 -1
  20. package/dist/gateway/static/root/assets/{automations-page-CftigJlf.js → automations-page-CkJV3DN0.js} +1 -1
  21. package/dist/gateway/static/root/assets/automations-workspace-BEa2doeR.js +7 -0
  22. package/dist/gateway/static/root/assets/{binary-plugins-CRCLWBo2.js → binary-plugins-Dg3h3TA7.js} +1 -1
  23. package/dist/gateway/static/root/assets/{block-editor-D0LDiOTT.js → block-editor-DVhdHntT.js} +29 -29
  24. package/dist/gateway/static/root/assets/{browser-automation-inputs-C611KRBx.js → browser-automation-inputs-BMRYUW8_.js} +1 -1
  25. package/dist/gateway/static/root/assets/{browser-automations-page-Djyv3vy-.js → browser-automations-page-Byv6-FY2.js} +2 -2
  26. package/dist/gateway/static/root/assets/browser-settings-page-DRCHGFpO.js +3 -0
  27. package/dist/gateway/static/root/assets/capabilities-D0S3DuAD.js +1 -0
  28. package/dist/gateway/static/root/assets/capabilities-settings-panel-mxRP0gl0.js +8 -0
  29. package/dist/gateway/static/root/assets/channels-settings-DBt_6GsB.js +1 -0
  30. package/dist/gateway/static/root/assets/{chat-terminal-dock-CIsKqdET.js → chat-terminal-dock-D4AHa51o.js} +2 -2
  31. package/dist/gateway/static/root/assets/{computer-settings-page-C0YL9J7m.js → computer-settings-page-eXPe500D.js} +1 -1
  32. package/dist/gateway/static/root/assets/connector-service-page-BQTFlq_k.js +1 -0
  33. package/dist/gateway/static/root/assets/connectors-page-BKeBWwcI.js +2 -0
  34. package/dist/gateway/static/root/assets/conversation-identity-Cw0n9uzK.js +1 -0
  35. package/dist/gateway/static/root/assets/{date-picker-CDsfv8R0.js → date-picker-7MtovynY.js} +1 -1
  36. package/dist/gateway/static/root/assets/{dependency-picker-DvhPj3CZ.js → dependency-picker-Bj_xkXID.js} +1 -1
  37. package/dist/gateway/static/root/assets/{desktop-pet-Cyg8XMpL.js → desktop-pet-CTmba9zH.js} +1 -1
  38. package/dist/gateway/static/root/assets/desktop-pet-settings-DNM_BlWN.js +1 -0
  39. package/dist/gateway/static/root/assets/device-pairing-wizard-C2XE0QhT.js +1 -0
  40. package/dist/gateway/static/root/assets/{extension-debug-page-D-AVJU3q.js → extension-debug-page-J_olaL7e.js} +1 -1
  41. package/dist/gateway/static/root/assets/{extension-page-DrFoQ9xt.js → extension-page-pK5RvqN8.js} +1 -1
  42. package/dist/gateway/static/root/assets/{extension-settings-page-DxWjESC1.js → extension-settings-page-BwroEN08.js} +1 -1
  43. package/dist/gateway/static/root/assets/files-BK6enEvD.js +1 -0
  44. package/dist/gateway/static/root/assets/{gateway-config-swr-DUDX42qY.js → gateway-config-swr-FuJTIg_a.js} +1 -1
  45. package/dist/gateway/static/root/assets/gateway-settings-CLLDp23J.js +1 -0
  46. package/dist/gateway/static/root/assets/{gateway-startup-retry-Cf8OxlvY.js → gateway-startup-retry-CKg_gu8_.js} +1 -1
  47. package/dist/gateway/static/root/assets/home-page-B5Epb1PH.js +1 -0
  48. package/dist/gateway/static/root/assets/{image-generation-api-D2YorS--.js → image-generation-api-Bo6NZ7zb.js} +1 -1
  49. package/dist/gateway/static/root/assets/{imports-page-BKucJlXI.js → imports-page-C8-hX8gS.js} +1 -1
  50. package/dist/gateway/static/root/assets/index-14F1yGJI.js +89 -0
  51. package/dist/gateway/static/root/assets/index-cB7rWIDY.css +1 -0
  52. package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-BxLXD-yU.js → keyboard-shortcuts-settings-BkBEjUZD.js} +1 -1
  53. package/dist/gateway/static/root/assets/local-app-workbench-page-6jC3vQpY.js +2 -0
  54. package/dist/gateway/static/root/assets/{local-apps-page-BAsQJQKJ.js → local-apps-page-CrbKIixo.js} +1 -1
  55. package/dist/gateway/static/root/assets/{locale-store-DA0Z5jM_.js → locale-store-CvGwNbml.js} +1 -1
  56. package/dist/gateway/static/root/assets/logs-page-DBHlZts9.js +2 -0
  57. package/dist/gateway/static/root/assets/management-settings-DsUWLu5m.js +1 -0
  58. package/dist/gateway/static/root/assets/{markdown-view-DYGPxPee.js → markdown-view-nXo5nrsv.js} +1 -1
  59. package/dist/gateway/static/root/assets/{media-plugins-CQtQzLyg.js → media-plugins-upxXJ-4l.js} +1 -1
  60. package/dist/gateway/static/root/assets/messages-B_AwRroN.js +3 -0
  61. package/dist/gateway/static/root/assets/note-detail-panel-0Q9TOtJG.js +5 -0
  62. package/dist/gateway/static/root/assets/notes-page-D0NmcwNw.js +8 -0
  63. package/dist/gateway/static/root/assets/page-context-capture-button-DUyA-K4L.js +1 -0
  64. package/dist/gateway/static/root/assets/{page-tabs-B6DjkyMM.js → page-tabs-Cl-NFPNr.js} +1 -1
  65. package/dist/gateway/static/root/assets/{preview-open-alternatives-Dn57uLhr.js → preview-open-alternatives-DX81PwJ3.js} +1 -1
  66. package/dist/gateway/static/root/assets/product-delivery-chCjIpvu.js +1 -0
  67. package/dist/gateway/static/root/assets/{product-open-page-H2YMk8TY.js → product-open-page-CrfIGwm8.js} +1 -1
  68. package/dist/gateway/static/root/assets/project-detail-page-BVfVrYmn.js +1 -0
  69. package/dist/gateway/static/root/assets/projects-page-nM9a9XNS.js +1 -0
  70. package/dist/gateway/static/root/assets/{registry-api-C0DCx3wv.js → registry-api-CHxgohY0.js} +1 -1
  71. package/dist/gateway/static/root/assets/remote-access-hub-C8b_k88G.js +1 -0
  72. package/dist/gateway/static/root/assets/runtime-tools-settings-panel-D3dLOW04.js +5 -0
  73. package/dist/gateway/static/root/assets/scenes-page-DEowreZV.js +2 -0
  74. package/dist/gateway/static/root/assets/{schema-form-CblI9WUA.js → schema-form-ZxuIvD2_.js} +1 -1
  75. package/dist/gateway/static/root/assets/schemas-88fK3zzl.js +64 -0
  76. package/dist/gateway/static/root/assets/sessions-page-B_nPhera.js +1 -0
  77. package/dist/gateway/static/root/assets/settings-advanced-gate-BqhIOuus.js +1 -0
  78. package/dist/gateway/static/root/assets/{settings-form-section-BAaVyxJH.js → settings-form-section-TZRfg4yo.js} +1 -1
  79. package/dist/gateway/static/root/assets/{settings-page-CKNPbm5q.js → settings-page-a8qcJpdZ.js} +1 -1
  80. package/dist/gateway/static/root/assets/{settings-page-layout-DqNCGKxQ.js → settings-page-layout-BfvlRT9q.js} +1 -1
  81. package/dist/gateway/static/root/assets/setup-status-panel-CRj5Ruqn.js +1 -0
  82. package/dist/gateway/static/root/assets/{share-preview-page-BzMfp_HM.js → share-preview-page-DCt1pTWB.js} +1 -1
  83. package/dist/gateway/static/root/assets/shares-settings-BNbXPk--.js +1 -0
  84. package/dist/gateway/static/root/assets/skill-reload-api-CNMCLbav.js +1 -0
  85. package/dist/gateway/static/root/assets/{skills-page-DIht92q6.js → skills-page-BIOcg44X.js} +1 -1
  86. package/dist/gateway/static/root/assets/{skills-page.utils-DLYRiEn3.js → skills-page.utils-CgZdzT4I.js} +1 -1
  87. package/dist/gateway/static/root/assets/{system-settings-panel-yYs4YgYk.js → system-settings-panel-_YaRncA6.js} +1 -1
  88. package/dist/gateway/static/root/assets/task-detail-page-CAcfAG-c.js +1 -0
  89. package/dist/gateway/static/root/assets/tasks-CDR_RVbQ.js +1 -0
  90. package/dist/gateway/static/root/assets/{tunnel-api-BasDYxvx.js → tunnel-api-uOupJOoS.js} +1 -1
  91. package/dist/gateway/static/root/assets/turn-outcome-D0SnyZ3Z.js +1 -0
  92. package/dist/gateway/static/root/assets/{use-autosave-CWAUHhcb.js → use-autosave-BezzHBLE.js} +1 -1
  93. package/dist/gateway/static/root/assets/user-model-page-BFFeneDq.js +2 -0
  94. package/dist/gateway/static/root/assets/{voice-api-key-field-Kc4UlxZs.js → voice-api-key-field-BmYifdwL.js} +1 -1
  95. package/dist/gateway/static/root/assets/{voice-config-api-DTyMdGOR.js → voice-config-api-D_5Q2_A3.js} +1 -1
  96. package/dist/gateway/static/root/assets/{work-discovery-overlay-BPC_c9dO.js → work-discovery-overlay-4DmyEckJ.js} +1 -1
  97. package/dist/gateway/static/root/assets/{workflow-run-setup-panel-DBTciOrq.js → workflow-run-setup-panel-DeZe8bTZ.js} +2 -2
  98. package/dist/gateway/static/root/assets/workflows-page-Sv4hEc6W.js +6 -0
  99. package/dist/gateway/static/root/index.html +16 -16
  100. package/dist/package.js +1 -1
  101. package/dist/packages/computer-control-contract/src/index.js +10 -1
  102. package/dist/packages/gateway-contract/src/app-context.js +55 -0
  103. package/dist/packages/gateway-contract/src/automations.js +16 -17
  104. package/dist/packages/gateway-contract/src/capabilities.js +1078 -0
  105. package/dist/packages/gateway-contract/src/extension-capabilities.js +26 -0
  106. package/dist/packages/gateway-contract/src/home.js +3 -3
  107. package/dist/packages/gateway-contract/src/index.js +8 -0
  108. package/dist/packages/gateway-contract/src/product-delivery.js +19 -4
  109. package/dist/packages/gateway-contract/src/scenes.js +199 -0
  110. package/dist/packages/gateway-contract/src/task-runs.js +8 -4
  111. package/dist/packages/gateway-contract/src/tasks.js +5 -4
  112. package/dist/packages/realtime-client/src/index.js +17 -4
  113. package/dist/src/agent/agent-manager.d.ts +1 -0
  114. package/dist/src/agent/agent-manager.js +1 -0
  115. package/dist/src/agent/child-agent-factory.d.ts +2 -0
  116. package/dist/src/agent/child-agent-factory.js +5 -0
  117. package/dist/src/agent/commands/approved-verification.d.ts +14 -0
  118. package/dist/src/agent/commands/approved-verification.js +48 -0
  119. package/dist/src/agent/context/execution-scope.js +2 -1
  120. package/dist/src/agent/context/project-context.js +2 -1
  121. package/dist/src/agent/external-tools/cliProvider.js +123 -75
  122. package/dist/src/agent/external-tools/composio-provider.d.ts +1 -1
  123. package/dist/src/agent/external-tools/composio-provider.js +70 -12
  124. package/dist/src/agent/external-tools/endpoint-provider.js +14 -1
  125. package/dist/src/agent/inbound/turn-dispatcher.d.ts +2 -0
  126. package/dist/src/agent/inbound/turn-dispatcher.js +2 -1
  127. package/dist/src/agent/memory/compaction-chunks.d.ts +6 -1
  128. package/dist/src/agent/memory/compaction-chunks.js +16 -3
  129. package/dist/src/agent/memory/compaction-ledger.d.ts +3 -1
  130. package/dist/src/agent/memory/compaction-ledger.js +31 -18
  131. package/dist/src/agent/memory/compaction-request.d.ts +2 -0
  132. package/dist/src/agent/memory/compaction-request.js +6 -1
  133. package/dist/src/agent/memory/compaction.d.ts +19 -1
  134. package/dist/src/agent/memory/compaction.js +112 -30
  135. package/dist/src/agent/service/process-direct-streaming.d.ts +3 -0
  136. package/dist/src/agent/service/process-direct-streaming.js +19 -10
  137. package/dist/src/agent/service.js +1 -0
  138. package/dist/src/agent/service.types.d.ts +1 -0
  139. package/dist/src/agent/skills/config.js +2 -0
  140. package/dist/src/agent/skills/format-skills-prompt.js +14 -1
  141. package/dist/src/agent/skills/index.js +16 -8
  142. package/dist/src/agent/skills/types.d.ts +1 -1
  143. package/dist/src/agent/source-context/app-context.d.ts +4 -0
  144. package/dist/src/agent/source-context/app-context.js +36 -0
  145. package/dist/src/agent/source-context/injector.js +1 -0
  146. package/dist/src/agent/source-context/types.d.ts +5 -1
  147. package/dist/src/agent/tasks/task-judge-service.js +2 -1
  148. package/dist/src/agent/tool-manuals/computer.d.ts +1 -1
  149. package/dist/src/agent/tool-manuals/computer.js +1 -1
  150. package/dist/src/agent/tools/automation-tool.d.ts +12 -1
  151. package/dist/src/agent/tools/automation-tool.js +106 -32
  152. package/dist/src/agent/tools/factory.d.ts +1 -0
  153. package/dist/src/agent/tools/factory.js +6 -1
  154. package/dist/src/agent/tools/scoped-workspace-tools.d.ts +8 -0
  155. package/dist/src/agent/tools/scoped-workspace-tools.js +81 -0
  156. package/dist/src/agent/tools/xopc-use-tool.d.ts +6 -3
  157. package/dist/src/agent/tools/xopc-use-tool.js +997 -908
  158. package/dist/src/agent/workflow/subagent-runner.js +1 -0
  159. package/dist/src/agent-config/index.js +2 -2
  160. package/dist/src/agent-config/schema.d.ts +5 -0
  161. package/dist/src/agent-config/schema.js +14 -10
  162. package/dist/src/automations/api/routes.js +244 -164
  163. package/dist/src/automations/capabilities/drafts.d.ts +4 -0
  164. package/dist/src/automations/capabilities/drafts.js +95 -0
  165. package/dist/src/automations/capabilities/read.d.ts +4 -0
  166. package/dist/src/automations/capabilities/read.js +119 -0
  167. package/dist/src/automations/capabilities/write.d.ts +349 -0
  168. package/dist/src/automations/capabilities/write.js +172 -0
  169. package/dist/src/automations/domain/index.js +2 -2
  170. package/dist/src/automations/domain/validation.d.ts +77 -77
  171. package/dist/src/automations/domain/validation.js +9 -6
  172. package/dist/src/automations/draft/automation-draft-validator.d.ts +2 -2
  173. package/dist/src/automations/index.js +6 -6
  174. package/dist/src/automations/service/automation-service.d.ts +31 -0
  175. package/dist/src/automations/service/automation-service.js +213 -75
  176. package/dist/src/automations/service/index.js +2 -2
  177. package/dist/src/automations/storage/automation-repository.d.ts +2 -0
  178. package/dist/src/automations/storage/automation-repository.js +9 -1
  179. package/dist/src/automations/storage/automation-run-repository.d.ts +4 -1
  180. package/dist/src/automations/storage/automation-run-repository.js +16 -3
  181. package/dist/src/automations/storage/index.js +3 -3
  182. package/dist/src/browser/automations/schema.d.ts +1 -1
  183. package/dist/src/browser/automations/service.d.ts +1 -1
  184. package/dist/src/browser/observation/format.js +4 -0
  185. package/dist/src/capabilities/adapters/http.d.ts +4 -0
  186. package/dist/src/capabilities/adapters/http.js +44 -0
  187. package/dist/src/capabilities/readiness/from-config.js +11 -7
  188. package/dist/src/capabilities/runtime/app-context.d.ts +3 -0
  189. package/dist/src/capabilities/runtime/app-context.js +72 -0
  190. package/dist/src/capabilities/runtime/atomic-operations.d.ts +11 -0
  191. package/dist/src/capabilities/runtime/atomic-operations.js +34 -0
  192. package/dist/src/capabilities/runtime/dispatcher.d.ts +67 -0
  193. package/dist/src/capabilities/runtime/dispatcher.js +170 -0
  194. package/dist/src/capabilities/runtime/errors.d.ts +6 -0
  195. package/dist/src/capabilities/runtime/errors.js +11 -0
  196. package/dist/src/capabilities/runtime/external-operations.d.ts +16 -0
  197. package/dist/src/capabilities/runtime/external-operations.js +92 -0
  198. package/dist/src/capabilities/runtime/product.d.ts +12 -0
  199. package/dist/src/capabilities/runtime/product.js +69 -0
  200. package/dist/src/capabilities/runtime/settings.d.ts +3 -0
  201. package/dist/src/capabilities/runtime/settings.js +27 -0
  202. package/dist/src/channels/index.js +2 -2
  203. package/dist/src/channels/manager.js +1 -1
  204. package/dist/src/cli/cli-log-level-preset.d.ts +2 -0
  205. package/dist/src/cli/cli-log-level-preset.js +4 -0
  206. package/dist/src/cli/command-catalog.js +4 -0
  207. package/dist/src/cli/command-loaders.js +1 -0
  208. package/dist/src/cli/command-manifest.js +4 -0
  209. package/dist/src/cli/commands/channels.js +1 -1
  210. package/dist/src/cli/commands/connectors.js +1 -1
  211. package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
  212. package/dist/src/cli/commands/extension-marketplace.js +1 -1
  213. package/dist/src/cli/commands/mcp.d.ts +1 -0
  214. package/dist/src/cli/commands/mcp.js +51 -0
  215. package/dist/src/cli/commands/models.js +1 -1
  216. package/dist/src/cli/commands/onboard.js +1 -1
  217. package/dist/src/cli/commands/project.js +1 -1
  218. package/dist/src/computer/broker.d.ts +0 -1
  219. package/dist/src/computer/broker.js +4 -6
  220. package/dist/src/computer/evaluation-harness.d.ts +45 -0
  221. package/dist/src/computer/evaluation-harness.js +108 -0
  222. package/dist/src/computer/model-adapter.d.ts +37 -2
  223. package/dist/src/computer/model-adapter.js +333 -42
  224. package/dist/src/computer/model-policy.d.ts +4 -1
  225. package/dist/src/computer/model-policy.js +11 -3
  226. package/dist/src/computer/release-gate.d.ts +22 -0
  227. package/dist/src/computer/release-gate.js +19 -0
  228. package/dist/src/computer/runtime.js +14 -10
  229. package/dist/src/computer/task-state.d.ts +1 -0
  230. package/dist/src/computer/task-state.js +1 -0
  231. package/dist/src/config/models-json.d.ts +14 -8
  232. package/dist/src/config/models-json.js +1 -1
  233. package/dist/src/config/schema.d.ts +4 -0
  234. package/dist/src/config/schema.js +3 -9
  235. package/dist/src/connectors/composio-sessions.d.ts +4 -2
  236. package/dist/src/connectors/composio-sessions.js +10 -9
  237. package/dist/src/connectors/composio.js +10 -8
  238. package/dist/src/discussions/action-tasks.js +2 -1
  239. package/dist/src/discussions/recording.js +1 -1
  240. package/dist/src/execution-environments/local-worktree-manager.d.ts +1 -0
  241. package/dist/src/execution-environments/local-worktree-manager.js +13 -2
  242. package/dist/src/extensions/activation-context.js +3 -3
  243. package/dist/src/extensions/api.js +1 -1
  244. package/dist/src/extensions/normalize-manifest.js +6 -1
  245. package/dist/src/extensions/sdk/index.js +1 -1
  246. package/dist/src/extensions/sdk/media.js +1 -1
  247. package/dist/src/extensions/types/manifest.d.ts +3 -0
  248. package/dist/src/gateway/agent-builtin-tools.d.ts +1 -1
  249. package/dist/src/gateway/hono/lib/config-payload.d.ts +1 -0
  250. package/dist/src/gateway/hono/middleware/scopes.js +1 -1
  251. package/dist/src/gateway/hono/routes/auth-registry-extensions.js +5 -2
  252. package/dist/src/gateway/hono/routes/capability-operations.d.ts +3 -0
  253. package/dist/src/gateway/hono/routes/capability-operations.js +52 -0
  254. package/dist/src/gateway/hono/routes/lazy-bundles.js +16 -0
  255. package/dist/src/gateway/hono/routes/local-app-capabilities.d.ts +4 -0
  256. package/dist/src/gateway/hono/routes/local-app-capabilities.js +41 -0
  257. package/dist/src/gateway/hono/routes/local-apps.js +41 -9
  258. package/dist/src/gateway/hono/routes/models.js +2 -2
  259. package/dist/src/gateway/hono/routes/notes.js +215 -146
  260. package/dist/src/gateway/hono/routes/projects.js +217 -374
  261. package/dist/src/gateway/hono/routes/scenes.js +188 -75
  262. package/dist/src/gateway/hono/routes/session-input-handler.d.ts +60 -16
  263. package/dist/src/gateway/hono/routes/session-input-handler.js +43 -1
  264. package/dist/src/gateway/hono/routes/sessions.js +17 -0
  265. package/dist/src/gateway/hono/routes/status.js +1 -1
  266. package/dist/src/gateway/hono/routes/tasks.js +182 -326
  267. package/dist/src/gateway/hono/routes/user-model-refresh.js +1 -1
  268. package/dist/src/gateway/hono/routes/voice.js +4 -4
  269. package/dist/src/gateway/hono/routes/workflows.js +1 -1
  270. package/dist/src/gateway/media-access.js +2 -1
  271. package/dist/src/gateway/mobile-privacy.js +2 -2
  272. package/dist/src/gateway/scenes/host.js +14 -3
  273. package/dist/src/gateway/scenes/mailContext.js +1 -1
  274. package/dist/src/gateway/scenes/slackThreadSource.d.ts +41 -0
  275. package/dist/src/gateway/scenes/slackThreadSource.js +168 -0
  276. package/dist/src/gateway/security/gateway-scopes.d.ts +1 -1
  277. package/dist/src/gateway/security/gateway-scopes.js +5 -0
  278. package/dist/src/gateway/service/app-context-access.d.ts +11 -0
  279. package/dist/src/gateway/service/app-context-access.js +70 -0
  280. package/dist/src/gateway/service/run-gateway-agent.js +11 -2
  281. package/dist/src/gateway/service/session-input-coordinator.js +54 -15
  282. package/dist/src/gateway/service/sessions-api.d.ts +1 -0
  283. package/dist/src/gateway/service/sessions-api.js +3 -0
  284. package/dist/src/gateway/service/task-conversation-query-service.d.ts +3 -1
  285. package/dist/src/gateway/service/task-conversation-query-service.js +32 -3
  286. package/dist/src/gateway/service.d.ts +3 -0
  287. package/dist/src/gateway/service.js +69 -15
  288. package/dist/src/gateway/session-context-summary.js +2 -1
  289. package/dist/src/{tasks/task-outbox-dispatcher.d.ts → infra/domain-outbox-dispatcher.d.ts} +2 -2
  290. package/dist/src/{tasks/task-outbox-dispatcher.js → infra/domain-outbox-dispatcher.js} +10 -9
  291. package/dist/src/infra/operation-context.d.ts +2 -0
  292. package/dist/src/infra/operation-context.js +16 -0
  293. package/dist/src/local-apps/capabilities/contracts.d.ts +2 -0
  294. package/dist/src/local-apps/capabilities/contracts.js +32 -0
  295. package/dist/src/local-apps/capabilities/read.d.ts +3 -0
  296. package/dist/src/local-apps/capabilities/read.js +48 -0
  297. package/dist/src/local-apps/capabilities/runtime.d.ts +16 -0
  298. package/dist/src/local-apps/capabilities/runtime.js +66 -0
  299. package/dist/src/local-apps/capabilities/write.d.ts +3 -0
  300. package/dist/src/local-apps/capabilities/write.js +35 -0
  301. package/dist/src/local-apps/release-lock.d.ts +2 -0
  302. package/dist/src/local-apps/release-lock.js +20 -0
  303. package/dist/src/local-apps/runtime-entry.d.ts +0 -2
  304. package/dist/src/local-apps/runtime-entry.js +1 -14
  305. package/dist/src/local-apps/scaffold.js +4 -1
  306. package/dist/src/local-apps/service.d.ts +24 -1
  307. package/dist/src/local-apps/service.js +186 -43
  308. package/dist/src/local-apps/store.js +0 -2
  309. package/dist/src/mcp/capability-server.d.ts +4 -0
  310. package/dist/src/mcp/capability-server.js +96 -0
  311. package/dist/src/mcp/channel-bridge.js +1 -1
  312. package/dist/src/mcp/gateway-http-client.d.ts +7 -0
  313. package/dist/src/mcp/gateway-http-client.js +27 -5
  314. package/dist/src/media-understanding/openai-compatible-audio.js +1 -1
  315. package/dist/src/notes/agent-context.js +1 -1
  316. package/dist/src/notes/capabilities/read.d.ts +3 -0
  317. package/dist/src/notes/capabilities/read.js +96 -0
  318. package/dist/src/notes/capabilities/write.d.ts +7 -0
  319. package/dist/src/notes/capabilities/write.js +152 -0
  320. package/dist/src/notes/index.js +1 -1
  321. package/dist/src/notes/service.d.ts +12 -4
  322. package/dist/src/notes/service.js +188 -175
  323. package/dist/src/notes/store.d.ts +14 -9
  324. package/dist/src/notes/store.js +81 -21
  325. package/dist/src/notifications/service.d.ts +1 -0
  326. package/dist/src/notifications/service.js +5 -0
  327. package/dist/src/platform/client.d.ts +1 -1
  328. package/dist/src/platform/contracts.d.ts +1 -1
  329. package/dist/src/projects/capabilities/read.d.ts +3 -0
  330. package/dist/src/projects/capabilities/read.js +81 -0
  331. package/dist/src/projects/capabilities/write.d.ts +9 -0
  332. package/dist/src/projects/capabilities/write.js +260 -0
  333. package/dist/src/projects/index.js +2 -2
  334. package/dist/src/projects/project-change-events.d.ts +2 -0
  335. package/dist/src/projects/project-change-events.js +18 -0
  336. package/dist/src/projects/project-service.d.ts +11 -0
  337. package/dist/src/projects/project-service.js +121 -42
  338. package/dist/src/projects/project-store.js +12 -2
  339. package/dist/src/projects/project-workspace-creation.d.ts +3 -0
  340. package/dist/src/projects/project-workspace-creation.js +45 -0
  341. package/dist/src/projects/workspace-project.js +6 -0
  342. package/dist/src/providers/model-catalog-types.d.ts +2 -1
  343. package/dist/src/providers/model-reference-auditor.js +4 -4
  344. package/dist/src/providers/model-supplements.js +13 -3
  345. package/dist/src/providers/presentation.js +3 -3
  346. package/dist/src/providers/xopc-cloud-model-source.js +4 -2
  347. package/dist/src/realtime/runtime.js +4 -0
  348. package/dist/src/scenes/capabilities/read.d.ts +3 -0
  349. package/dist/src/scenes/capabilities/read.js +187 -0
  350. package/dist/src/scenes/capabilities/write.d.ts +3 -0
  351. package/dist/src/scenes/capabilities/write.js +151 -0
  352. package/dist/src/scenes/contracts.d.ts +2 -105
  353. package/dist/src/scenes/contracts.js +3 -88
  354. package/dist/src/scenes/execution.d.ts +1 -1
  355. package/dist/src/scenes/httpServices.d.ts +2 -0
  356. package/dist/src/scenes/inbox.d.ts +1 -0
  357. package/dist/src/scenes/inbox.js +7 -7
  358. package/dist/src/scenes/preferences.d.ts +3 -24
  359. package/dist/src/scenes/preferences.js +8 -30
  360. package/dist/src/scenes/repository.d.ts +1 -0
  361. package/dist/src/scenes/repository.js +7 -3
  362. package/dist/src/scenes/resultNotifications.js +2 -2
  363. package/dist/src/scenes/schedule.d.ts +1 -8
  364. package/dist/src/scenes/schedule.js +3 -15
  365. package/dist/src/scenes/service.d.ts +6 -0
  366. package/dist/src/scenes/service.js +29 -25
  367. package/dist/src/scenes/taskFollowUp/agentExecutor.d.ts +36 -0
  368. package/dist/src/scenes/taskFollowUp/agentExecutor.js +149 -0
  369. package/dist/src/scenes/taskFollowUp/branchInventory.d.ts +38 -0
  370. package/dist/src/scenes/taskFollowUp/branchInventory.js +70 -0
  371. package/dist/src/scenes/taskFollowUp/contracts.d.ts +91 -0
  372. package/dist/src/scenes/taskFollowUp/contracts.js +100 -0
  373. package/dist/src/scenes/taskFollowUp/resources.d.ts +19 -0
  374. package/dist/src/scenes/taskFollowUp/resources.js +97 -0
  375. package/dist/src/scenes/taskFollowUp/service.d.ts +810 -0
  376. package/dist/src/scenes/taskFollowUp/service.js +710 -0
  377. package/dist/src/scenes/taskFollowUp/workspaceFingerprint.d.ts +2 -0
  378. package/dist/src/scenes/taskFollowUp/workspaceFingerprint.js +46 -0
  379. package/dist/src/scenes/templates.d.ts +2 -2
  380. package/dist/src/scenes/templates.js +1 -1
  381. package/dist/src/session/session-find.d.ts +17 -0
  382. package/dist/src/session/session-find.js +56 -0
  383. package/dist/src/session/store.d.ts +4 -0
  384. package/dist/src/session/store.js +43 -7
  385. package/dist/src/share/note-share-revocation.d.ts +3 -0
  386. package/dist/src/share/note-share-revocation.js +26 -0
  387. package/dist/src/storage/sqlite/migrations/190_scene_development.sql +37 -0
  388. package/dist/src/storage/sqlite/migrations/191_scene_task_follow_up.sql +27 -0
  389. package/dist/src/storage/sqlite/migrations/192_capability_operations.sql +20 -0
  390. package/dist/src/storage/sqlite/migrations/193_note_file_cleanup.sql +8 -0
  391. package/dist/src/storage/sqlite/migrations/194_capability_external_outcomes.sql +11 -0
  392. package/dist/src/storage/sqlite/migrations/195_automation_deleted_revisions.sql +4 -0
  393. package/dist/src/storage/sqlite/migrations/196_automation_run_requests.sql +23 -0
  394. package/dist/src/storage/sqlite/migrations/197_note_deletion_cleanup.sql +8 -0
  395. package/dist/src/storage/sqlite/migrations/198_project_workspace_creation.sql +7 -0
  396. package/dist/src/storage/sqlite/migrations/199_scene_resource_events.sql +488 -0
  397. package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
  398. package/dist/src/storage/sqlite/migrations/runner.js +6 -3
  399. package/dist/src/storage/sqlite/schema.js +1 -1
  400. package/dist/src/storage/sqlite/transaction.d.ts +5 -0
  401. package/dist/src/storage/sqlite/transaction.js +34 -3
  402. package/dist/src/tasks/capabilities/management.d.ts +195 -0
  403. package/dist/src/tasks/capabilities/management.js +111 -0
  404. package/dist/src/tasks/capabilities/read.d.ts +2 -0
  405. package/dist/src/tasks/capabilities/read.js +141 -0
  406. package/dist/src/tasks/capabilities/relations.d.ts +204 -0
  407. package/dist/src/tasks/capabilities/relations.js +140 -0
  408. package/dist/src/tasks/capabilities/runs.d.ts +2 -0
  409. package/dist/src/tasks/capabilities/runs.js +89 -0
  410. package/dist/src/tasks/capabilities/write.d.ts +207 -0
  411. package/dist/src/tasks/capabilities/write.js +107 -0
  412. package/dist/src/tasks/home-query-service.js +3 -2
  413. package/dist/src/tasks/index.d.ts +0 -1
  414. package/dist/src/tasks/index.js +9 -9
  415. package/dist/src/tasks/project-operating-view-service.js +2 -1
  416. package/dist/src/tasks/task-application-service.d.ts +1 -0
  417. package/dist/src/tasks/task-application-service.js +3 -2
  418. package/dist/src/tasks/task-change-events.js +5 -3
  419. package/dist/src/tasks/task-context-assembler.js +2 -1
  420. package/dist/src/tasks/task-deletion-service.js +2 -1
  421. package/dist/src/tasks/task-dependency-service.js +2 -1
  422. package/dist/src/tasks/task-handoff-service.js +2 -1
  423. package/dist/src/tasks/task-read-model-projector.js +2 -1
  424. package/dist/src/tasks/task-repository.d.ts +12 -7
  425. package/dist/src/tasks/task-repository.js +175 -154
  426. package/dist/src/tasks/task-run-coordinator.js +2 -1
  427. package/dist/src/tasks/task-run-dispatcher.js +2 -1
  428. package/dist/src/tasks/task-run-repository.d.ts +1 -0
  429. package/dist/src/tasks/task-run-repository.js +29 -14
  430. package/dist/src/tasks/task-signal-service.js +2 -1
  431. package/dist/src/tui/backends/embedded-backend.js +1 -1
  432. package/dist/src/tui/backends/gateway-realtime-backend.js +1 -1
  433. package/dist/src/tui/tui-commands.js +1 -1
  434. package/dist/src/user-context/config.d.ts +13 -0
  435. package/dist/src/user-context/config.js +2 -0
  436. package/dist/src/voice/platform-catalog.d.ts +1 -1
  437. package/dist/src/voice/realtime/runtime.js +3 -3
  438. package/dist/src/voice/stt/providers/alibaba-transcription.js +1 -1
  439. package/dist/src/voice/stt/providers/xopc-cloud-transcription.js +1 -1
  440. package/dist/src/voice/tts/providers/xopc-cloud-speech.js +1 -1
  441. package/dist/src/work-discovery/incremental-repository.js +1 -1
  442. package/dist/src/work-discovery/index.js +1 -1
  443. package/dist/src/work-discovery/repository.d.ts +1 -1
  444. package/dist/src/work-discovery/repository.js +3 -2
  445. package/dist/src/work-discovery/service.d.ts +4 -0
  446. package/dist/src/work-discovery/service.js +36 -11
  447. package/dist/src/workflows/context/workflow-context.js +3 -2
  448. package/dist/src/workflows/service/workflow-run-service.js +2 -1
  449. package/package.json +6 -2
  450. package/skills/THIRD_PARTY_NOTICES.md +2 -2
  451. package/skills/documents/xlsx/SKILL.md +5 -0
  452. package/skills/engineering/build-xopc-local-app/SKILL.md +2 -0
  453. package/skills/tools/find-skills/SKILL.md +3 -0
  454. package/dist/gateway/static/root/assets/activity-store-DVUTs1fk.js +0 -1
  455. package/dist/gateway/static/root/assets/agent-defaults-settings-panel-K3hTmu9d.js +0 -1
  456. package/dist/gateway/static/root/assets/appearance-settings-CU52MfIT.js +0 -1
  457. package/dist/gateway/static/root/assets/apps-page-ZpA1-6ad.js +0 -1
  458. package/dist/gateway/static/root/assets/automations-workspace-IEAxKRME.js +0 -7
  459. package/dist/gateway/static/root/assets/browser-settings-page-CU4VWsmX.js +0 -3
  460. package/dist/gateway/static/root/assets/capabilities-settings-panel-C9XQk3HL.js +0 -8
  461. package/dist/gateway/static/root/assets/channels-settings-Bqlhjooi.js +0 -1
  462. package/dist/gateway/static/root/assets/connector-service-page-BmH17JnO.js +0 -1
  463. package/dist/gateway/static/root/assets/connectors-page-zkx8Q-e6.js +0 -2
  464. package/dist/gateway/static/root/assets/desktop-pet-settings-CE4GOlMM.js +0 -1
  465. package/dist/gateway/static/root/assets/device-pairing-wizard-CdKJqnnw.js +0 -1
  466. package/dist/gateway/static/root/assets/files-Be5viEFY.js +0 -1
  467. package/dist/gateway/static/root/assets/gateway-realtime-CGOW0-b4.js +0 -1
  468. package/dist/gateway/static/root/assets/gateway-realtime-store-D4um_sV7.js +0 -1
  469. package/dist/gateway/static/root/assets/gateway-settings-CgXp2zq4.js +0 -1
  470. package/dist/gateway/static/root/assets/home-page-D6Idk732.js +0 -1
  471. package/dist/gateway/static/root/assets/index-1wIKA-kM.css +0 -1
  472. package/dist/gateway/static/root/assets/index-PFQHPGgi.js +0 -79
  473. package/dist/gateway/static/root/assets/local-app-workbench-page-BmAqTRb4.js +0 -2
  474. package/dist/gateway/static/root/assets/logs-page-ZjVYXXyM.js +0 -2
  475. package/dist/gateway/static/root/assets/management-settings-CSTkYVOZ.js +0 -1
  476. package/dist/gateway/static/root/assets/messages-4BtQKYlM.js +0 -3
  477. package/dist/gateway/static/root/assets/note-detail-panel-DuXCt-MM.js +0 -5
  478. package/dist/gateway/static/root/assets/notes-page-BjOgBVq5.js +0 -8
  479. package/dist/gateway/static/root/assets/product-delivery-CrAI8ZEa.js +0 -1
  480. package/dist/gateway/static/root/assets/project-detail-page-0zi4-i9X.js +0 -1
  481. package/dist/gateway/static/root/assets/projects-page-B18OxmJj.js +0 -1
  482. package/dist/gateway/static/root/assets/remote-access-hub-z-DxbuaE.js +0 -1
  483. package/dist/gateway/static/root/assets/runtime-tools-settings-panel-DGsBTbo6.js +0 -5
  484. package/dist/gateway/static/root/assets/scenes-page-Bgba03B_.js +0 -1
  485. package/dist/gateway/static/root/assets/schemas-BaskVM5g.js +0 -64
  486. package/dist/gateway/static/root/assets/sessions-page-B1t3bMsm.js +0 -1
  487. package/dist/gateway/static/root/assets/settings-advanced-gate-CBX0Ezhf.js +0 -1
  488. package/dist/gateway/static/root/assets/setup-status-panel-Bw71C2X3.js +0 -1
  489. package/dist/gateway/static/root/assets/shares-settings-BoVDQolc.js +0 -1
  490. package/dist/gateway/static/root/assets/skill-reload-api-DtTptpAt.js +0 -1
  491. package/dist/gateway/static/root/assets/task-detail-page-vgkiGo-D.js +0 -1
  492. package/dist/gateway/static/root/assets/theme-store-CegIlB8d.js +0 -1
  493. package/dist/gateway/static/root/assets/user-model-page-CAGafNfP.js +0 -2
  494. package/dist/gateway/static/root/assets/workflows-page-CSxHVs1p.js +0 -6
  495. package/skills/creative/algorithmic-art/SKILL.md +0 -44
  496. package/skills/creative/algorithmic-art/templates/generator-template.js +0 -27
  497. package/skills/creative/algorithmic-art/templates/viewer.html +0 -27
@@ -5,6 +5,9 @@ import { getConnectorAccount, init_connector_account_repository } from "../../st
5
5
  import { appendConnectorExecutionAudit, consumeConnectorApproval, createConnectorApproval, getConnectorApproval, getConnectorConnection, getConnectorInstallation, init_connector_repository } from "../../storage/sqlite/connector-repository.js";
6
6
  import { connectorObjectiveScope, init_connection_wait_repository, publishConnectionWait, requireSessionConnection } from "../../storage/sqlite/connection-wait-repository.js";
7
7
  import "../../storage/sqlite/index.js";
8
+ import { CapabilityError } from "../../capabilities/runtime/errors.js";
9
+ import { ExternalEffectNotAppliedError, executeExternalOperation } from "../../capabilities/runtime/external-operations.js";
10
+ import "../../capabilities/runtime/dispatcher.js";
8
11
  import { connectorArgumentsHash, connectorArgumentsPreview } from "../../connectors/approval.js";
9
12
  import { selectConnectorAccount } from "../../connectors/account-selection.js";
10
13
  import { cliContextPath } from "../../connectors/cli/process.js";
@@ -163,15 +166,18 @@ var CliToolProvider = class {
163
166
  validateActionInput(action, input);
164
167
  const scopes = Array.isArray(connection.metadata.scopes) ? connection.metadata.scopes : [];
165
168
  if (action.requiredScopes.some((scope) => !scopes.includes(scope))) throw new Error("CLI account is missing required scopes. Reauthorize this account.");
169
+ const descriptorDigest = connectorArgumentsHash({
170
+ action,
171
+ adapterVersion: item.adapter.version,
172
+ binaryVersion: item.adapter.binaryVersion
173
+ });
166
174
  const argumentsHash = () => connectorArgumentsHash({
167
175
  args: input,
168
176
  exportResult,
169
177
  instanceId: item.instance.instanceId,
170
178
  accountId: connection.accountId,
171
179
  connectionId: connection.id,
172
- actionRevision: action.revision,
173
- binaryVersion: item.adapter.binaryVersion,
174
- adapterVersion: item.adapter.version,
180
+ descriptorDigest,
175
181
  principalId: item.principal.principalId,
176
182
  agentId: item.agentId,
177
183
  conversationId,
@@ -230,87 +236,129 @@ var CliToolProvider = class {
230
236
  instruction: "Approve this exact action in xopc, then retry with unchanged arguments and approvalId."
231
237
  });
232
238
  }
233
- const executionId = randomUUID();
234
- let authorized = false;
235
- const beforeExecute = () => {
236
- runSqliteWriteTransaction((db) => {
237
- const hash = argumentsHash();
238
- const freshPolicy = getConnectorInstallation(item.policy.id);
239
- const freshConnection = getConnectorConnection(connection.id);
240
- if (!freshPolicy || freshConnection?.status !== "active" || getConnectorAccount(connection.accountId)?.currentConnectionId !== connection.id || !selectConnectorAccount({
241
- installation: freshPolicy,
242
- agentId: item.agentId,
243
- conversationId,
244
- requestedAccountId: connection.accountId
245
- }).connection || evaluateConnectorExecutionPolicy({
246
- installation: freshPolicy,
247
- action: {
248
- scope: action.scope,
249
- curated: true
250
- },
251
- accountId: connection.accountId,
252
- agentId: item.agentId,
253
- confirmed: Boolean(approvalId)
254
- }).decision !== "allowed") throw new Error("Connector permission changed.");
255
- if (approvalId) {
256
- const approval = getConnectorApproval(approvalId);
257
- if (!approval || approval.argumentsHash !== hash || !consumeConnectorApproval(approvalId, hash)) throw new Error("Approval is invalid, expired or already consumed.");
239
+ if (approvalId) {
240
+ const approval = getConnectorApproval(approvalId);
241
+ if (!approval || approval.argumentsHash !== argumentsHash() || !["approved", "consumed"].includes(approval.status) || approval.status === "approved" && Date.parse(approval.expiresAt) <= Date.now()) return result({
242
+ outcome: "failed",
243
+ error: {
244
+ kind: "approval",
245
+ message: "Approval is invalid, expired or belongs to a different operation."
258
246
  }
259
- db.prepare(`INSERT INTO connector_cli_executions (id,instance_id,account_id,connection_id,action_id,revision,arguments_hash,status,owner_id,started_at)
260
- VALUES (?,?,?,?,?,?,?,'running',?,?)`).run(executionId, item.instance.instanceId, connection.accountId, connection.id, action.id, action.revision, hash, cliOwnerId, Date.now());
261
247
  });
262
- authorized = true;
248
+ }
249
+ const acceptedArgumentsHash = argumentsHash();
250
+ const authorizeCurrent = () => {
251
+ const freshPolicy = getConnectorInstallation(item.policy.id);
252
+ const freshConnection = getConnectorConnection(connection.id);
253
+ const currentConfig = this.deps.getConfig();
254
+ const enabled = currentConfig && listConnectorInstances(currentConfig).some((instance) => instance.instanceId === item.instance.instanceId && instance.enabled && instance.materialized.type === "cli");
255
+ const currentScopes = Array.isArray(freshConnection?.metadata.scopes) ? freshConnection.metadata.scopes : [];
256
+ if (!enabled || !freshPolicy || freshConnection?.status !== "active" || getConnectorAccount(connection.accountId)?.currentConnectionId !== connection.id || action.requiredScopes.some((scope) => !currentScopes.includes(scope)) || action.anyScopes?.length && !action.anyScopes.some((scope) => currentScopes.includes(scope)) || !selectConnectorAccount({
257
+ installation: freshPolicy,
258
+ agentId: item.agentId,
259
+ conversationId,
260
+ requestedAccountId: connection.accountId
261
+ }).connection || evaluateConnectorExecutionPolicy({
262
+ installation: freshPolicy,
263
+ action: {
264
+ scope: action.scope,
265
+ curated: true
266
+ },
267
+ accountId: connection.accountId,
268
+ agentId: item.agentId,
269
+ confirmed: Boolean(approvalId)
270
+ }).decision !== "allowed") throw new CapabilityError("FORBIDDEN", "Connector permission changed.");
271
+ if (argumentsHash() !== acceptedArgumentsHash) throw new CapabilityError("REVISION_CONFLICT", "Connector objective changed.");
263
272
  };
264
- const started = Date.now();
265
- let output;
266
- try {
267
- output = await executeCliAction(item.config, item.instance.instanceId, connection, action, input, context.signal, beforeExecute);
268
- } catch (error) {
269
- output = {
270
- outcome: authorized && action.scope !== "read" ? "unknown" : "failed",
271
- error: {
272
- kind: "runtime",
273
- message: error instanceof Error ? error.message : "CLI failed."
274
- }
273
+ const execute = async (executionId) => {
274
+ let authorized = false;
275
+ const beforeExecute = () => {
276
+ runSqliteWriteTransaction((db) => {
277
+ const hash = argumentsHash();
278
+ authorizeCurrent();
279
+ if (approvalId) {
280
+ const approval = getConnectorApproval(approvalId);
281
+ if (!approval || approval.argumentsHash !== hash || !consumeConnectorApproval(approvalId, hash)) throw new Error("Approval is invalid, expired or already consumed.");
282
+ }
283
+ db.prepare(`INSERT INTO connector_cli_executions (id,instance_id,account_id,connection_id,action_id,revision,arguments_hash,status,owner_id,started_at)
284
+ VALUES (?,?,?,?,?,?,?,'running',?,?)`).run(executionId, item.instance.instanceId, connection.accountId, connection.id, action.id, action.revision, hash, cliOwnerId, Date.now());
285
+ });
286
+ authorized = true;
275
287
  };
276
- }
277
- getSqliteDatabase().prepare("UPDATE connector_cli_executions SET status = ?, error_kind = ?, finished_at = ? WHERE id = ?").run(output.outcome, output.error?.kind ?? null, Date.now(), executionId);
278
- appendConnectorExecutionAudit({
279
- installationId: item.policy.id,
280
- connectionId: connection.id,
281
- connectorId: item.instance.connectorId,
282
- principalId: item.principal.principalId,
283
- agentId: item.agentId,
284
- conversationId,
285
- actionId: action.id,
286
- scope: action.scope,
287
- decision: authorized ? "allowed" : "denied",
288
- resultStatus: output.outcome === "success" ? "success" : "error",
289
- errorCode: output.outcome === "unknown" ? "outcome_unknown" : output.error?.kind,
290
- durationMs: Date.now() - started
291
- });
292
- let artifact;
293
- if (exportResult && output.outcome === "success") try {
294
- await writeFile(join(cliContextPath(String(connection.metadata.contextId)), "files", `${executionId}.json`), JSON.stringify(output.data ?? null, null, 2), {
295
- mode: 384,
296
- flag: "wx"
288
+ const started = Date.now();
289
+ let output;
290
+ try {
291
+ output = await executeCliAction(item.config, item.instance.instanceId, connection, action, input, context.signal, beforeExecute);
292
+ } catch (error) {
293
+ output = {
294
+ outcome: authorized && action.scope !== "read" ? "unknown" : "failed",
295
+ error: {
296
+ kind: "runtime",
297
+ message: error instanceof Error ? error.message : "CLI failed."
298
+ }
299
+ };
300
+ }
301
+ if (authorized && action.scope !== "read" && output.outcome === "failed" && output.error?.kind !== "startup") output = {
302
+ ...output,
303
+ outcome: "unknown"
304
+ };
305
+ getSqliteDatabase().prepare("UPDATE connector_cli_executions SET status = ?, error_kind = ?, finished_at = ? WHERE id = ?").run(output.outcome, output.error?.kind ?? null, Date.now(), executionId);
306
+ appendConnectorExecutionAudit({
307
+ installationId: item.policy.id,
308
+ connectionId: connection.id,
309
+ connectorId: item.instance.connectorId,
310
+ principalId: item.principal.principalId,
311
+ agentId: item.agentId,
312
+ conversationId,
313
+ actionId: action.id,
314
+ scope: action.scope,
315
+ decision: authorized ? "allowed" : "denied",
316
+ resultStatus: output.outcome === "success" ? "success" : "error",
317
+ errorCode: output.outcome === "unknown" ? "outcome_unknown" : output.error?.kind,
318
+ durationMs: Date.now() - started
297
319
  });
298
- artifact = `/api/connectors/executions/${executionId}/artifact`;
299
- } catch {
320
+ if (action.scope !== "read" && output.outcome !== "success") {
321
+ if (!authorized || output.error?.kind === "startup") throw new ExternalEffectNotAppliedError(output.error?.message ?? "CLI execution was rejected before spawning");
322
+ throw new Error(output.error?.message ?? "CLI write outcome could not be confirmed");
323
+ }
324
+ let artifact;
325
+ if (exportResult && output.outcome === "success") try {
326
+ await writeFile(join(cliContextPath(String(connection.metadata.contextId)), "files", `${executionId}.json`), JSON.stringify(output.data ?? null, null, 2), {
327
+ mode: 384,
328
+ flag: "wx"
329
+ });
330
+ artifact = `/api/connectors/executions/${executionId}/artifact`;
331
+ } catch {
332
+ return result({
333
+ executionId,
334
+ accountId: connection.accountId,
335
+ ...output,
336
+ artifactError: "The action succeeded, but its JSON export could not be saved. Do not repeat the action to retry export."
337
+ });
338
+ }
300
339
  return result({
301
- executionId,
340
+ ...authorized ? { executionId } : {},
341
+ artifact,
302
342
  accountId: connection.accountId,
303
343
  ...output,
304
- artifactError: "The action succeeded, but its JSON export could not be saved. Do not repeat the action to retry export."
344
+ ...output.outcome === "unknown" ? { instruction: "The write may have succeeded. Inspect the provider using a read action; do not retry automatically." } : {}
305
345
  });
306
- }
307
- return result({
308
- ...authorized ? { executionId } : {},
309
- artifact,
310
- accountId: connection.accountId,
311
- ...output,
312
- ...output.outcome === "unknown" ? { instruction: "The write may have succeeded. Inspect the provider using a read action; do not retry automatically." } : {}
313
- });
346
+ };
347
+ context.signal?.throwIfAborted();
348
+ authorizeCurrent();
349
+ if (action.scope === "read") return execute(randomUUID());
350
+ return executeExternalOperation({
351
+ principalId: item.principal.principalId,
352
+ capabilityId: toolRef,
353
+ idempotencyKey: connectorArgumentsHash(approvalId ? { approvalId } : {
354
+ conversationId,
355
+ toolCallId: context.toolCallId
356
+ }),
357
+ requestDigest: acceptedArgumentsHash,
358
+ descriptorDigest,
359
+ surface: "agent",
360
+ recovery: "manual"
361
+ }, execute);
314
362
  }
315
363
  };
316
364
  //#endregion
@@ -23,7 +23,7 @@ export declare class ComposioToolProvider implements ExternalToolProvider {
23
23
  constructor(deps: ComposioToolProviderDeps);
24
24
  search(query: string): Promise<ExternalToolSearchHit[]>;
25
25
  describe(toolRef: string): Promise<ExternalToolDescriptor | undefined>;
26
- execute(toolRef: string, args: Record<string, unknown>, approvalId: string | undefined, _context: ExternalToolExecutionContext): Promise<AgentToolResult<Record<string, unknown>>>;
26
+ execute(toolRef: string, args: Record<string, unknown>, approvalId: string | undefined, context: ExternalToolExecutionContext): Promise<AgentToolResult<Record<string, unknown>>>;
27
27
  private availableInstallations;
28
28
  private resolve;
29
29
  }
@@ -5,9 +5,12 @@ import { getConnectorAccount } from "../../storage/sqlite/connector-account-repo
5
5
  import { consumeConnectorApproval, createConnectorApproval, getConnectorApproval, getConnectorConnection, getConnectorInstallation, listConnectorActionMetadata, listConnectorConnections, listConnectorInstallations, upsertConnectorActionMetadata, upsertConnectorInstallation } from "../../storage/sqlite/connector-repository.js";
6
6
  import { bindObjectiveAccount, connectionBinding, connectionBindings, connectorObjectiveScope, init_connection_wait_repository, publishConnectionWait, requireSessionConnection } from "../../storage/sqlite/connection-wait-repository.js";
7
7
  import "../../storage/sqlite/index.js";
8
+ import { CapabilityError } from "../../capabilities/runtime/errors.js";
9
+ import { ExternalEffectNotAppliedError, executeExternalOperation } from "../../capabilities/runtime/external-operations.js";
8
10
  import { connectorArgumentsHash, connectorArgumentsPreview } from "../../connectors/approval.js";
9
11
  import { canAccessConnectorAccount, currentAccountConnections } from "../../connectors/account-access.js";
10
12
  import { connectorIdentitySummary } from "../../connectors/connector-identity.js";
13
+ import { evaluateConnectorExecutionPolicy } from "../../connectors/policy.js";
11
14
  import { ComposioSessionsAdapter } from "../../connectors/composio-sessions.js";
12
15
  import { getComposioToolkitScope, getConfiguredComposioAuthConfigs, isComposioActionAllowedByCatalog, scopeForComposioAction } from "../../connectors/composio.js";
13
16
  import { getConnectorDefinition } from "../../connectors/catalog.js";
@@ -41,6 +44,10 @@ function textResult(value) {
41
44
  details: {}
42
45
  };
43
46
  }
47
+ function actionDigest(action) {
48
+ const { cachedAt: _cachedAt, ...contract } = action;
49
+ return connectorArgumentsHash(contract);
50
+ }
44
51
  function installedConfigToolkits(config) {
45
52
  return Object.values(config?.connectors?.instances ?? {}).flatMap((record) => {
46
53
  if (!record || typeof record !== "object" || Array.isArray(record)) return [];
@@ -227,7 +234,7 @@ var ComposioToolProvider = class {
227
234
  batchRead: accounts.length > 0 && action.scope === "read" && action.curated && BATCH_READ_ACTIONS.has(action.actionId)
228
235
  };
229
236
  }
230
- async execute(toolRef, args, approvalId, _context) {
237
+ async execute(toolRef, args, approvalId, context) {
231
238
  const available = this.availableInstallations();
232
239
  const resolved = this.resolve(toolRef, available.installations);
233
240
  if (!resolved) return textResult("This connected app tool is not allowed for this user and agent.");
@@ -283,21 +290,47 @@ var ComposioToolProvider = class {
283
290
  if (available.context && connection.accountId) bindObjectiveAccount(available.context.conversationId, resolved.installation.connectorId, connection.accountId);
284
291
  const actionArgs = { ...executionArgs };
285
292
  delete actionArgs[CONNECTION_ARGUMENT];
286
- const argsHash = connectorArgumentsHash({
293
+ const descriptorDigest = actionDigest(action);
294
+ const argumentIdentity = () => connectorArgumentsHash({
287
295
  args: actionArgs,
288
296
  accountId: connection.accountId,
297
+ connectionId: connection.id,
298
+ descriptorDigest,
299
+ principalId: available.principalId,
300
+ agentId: available.agentId,
301
+ conversationId: available.context?.conversationId,
289
302
  objective: available.context ? connectorObjectiveScope(available.context.conversationId) : void 0
290
303
  });
304
+ const argsHash = argumentIdentity();
291
305
  let confirmed = false;
292
306
  if (approvalId) {
293
307
  const pending = getConnectorApproval(approvalId);
294
- if (!pending || pending.principalId !== available.principalId || pending.connectorId !== resolved.installation.connectorId || pending.actionId !== action.actionId || pending.conversationId !== available.context?.conversationId || pending.agentId !== available.agentId || !pending.connectionId || getConnectorConnection(pending.connectionId)?.accountId !== connection.accountId) return textResult("The connector approval is invalid for this session or action.");
295
- confirmed = Boolean(consumeConnectorApproval(approvalId, argsHash));
296
- if (!confirmed) return textResult("The connector approval is not approved, has expired, or was already used.");
308
+ if (!pending || pending.principalId !== available.principalId || pending.connectorId !== resolved.installation.connectorId || pending.actionId !== action.actionId || pending.conversationId !== available.context?.conversationId || pending.agentId !== available.agentId || pending.connectionId !== connection.id || pending.argumentsHash !== argsHash || !["approved", "consumed"].includes(pending.status) || pending.status === "approved" && Date.parse(pending.expiresAt) <= Date.now()) return textResult("The connector approval is invalid for this session or action.");
309
+ confirmed = true;
297
310
  }
311
+ const authorizeCurrent = () => {
312
+ context.signal?.throwIfAborted();
313
+ const current = this.availableInstallations();
314
+ const installation = this.resolve(toolRef, current.installations)?.installation;
315
+ const active = getConnectorConnection(connection.id);
316
+ const contract = listConnectorActionMetadata(resolved.installation.connectorId).find((item) => item.actionId === action.actionId);
317
+ if (!installation || current.principalId !== available.principalId || current.agentId !== available.agentId || current.context?.conversationId !== available.context?.conversationId || !active || active.status !== "active" || active.accountId !== connection.accountId || active.providerConnectionId !== connection.providerConnectionId || getConnectorAccount(active.accountId)?.currentConnectionId !== active.id || !canAccessConnectorAccount(active, installation, current.agentId)) throw new CapabilityError("FORBIDDEN", "Connected account authorization changed");
318
+ if (!contract || actionDigest(contract) !== descriptorDigest || argumentIdentity() !== argsHash) throw new CapabilityError("REVISION_CONFLICT", "Action contract or objective changed");
319
+ const evaluation = evaluateConnectorExecutionPolicy({
320
+ installation,
321
+ action: contract,
322
+ agentId: current.agentId,
323
+ accountId: active.accountId,
324
+ confirmed
325
+ });
326
+ if (evaluation.decision === "denied") throw new CapabilityError("FORBIDDEN", evaluation.reason);
327
+ return evaluation;
328
+ };
329
+ const evaluation = authorizeCurrent();
298
330
  let result;
299
331
  try {
300
- result = await this.adapter.executeWithPolicy({
332
+ const execute = async () => this.adapter.executeWithPolicy({
333
+ signal: context.signal,
301
334
  context: {
302
335
  principalId: available.principalId,
303
336
  toolkits: [toolkit],
@@ -309,7 +342,36 @@ var ComposioToolProvider = class {
309
342
  args: actionArgs,
310
343
  agentId: available.agentId,
311
344
  conversationId: available.context?.conversationId,
312
- confirmed
345
+ confirmed,
346
+ beforeExecute: () => {
347
+ const current = authorizeCurrent();
348
+ if (current.decision !== "allowed") throw new ExternalEffectNotAppliedError(current.reason);
349
+ if (approvalId && !consumeConnectorApproval(approvalId, argsHash)) throw new ExternalEffectNotAppliedError("Approval is no longer available");
350
+ }
351
+ });
352
+ if (evaluation.decision === "confirmation_required") result = {
353
+ decision: "confirmation_required",
354
+ reason: evaluation.reason
355
+ };
356
+ else if (action.scope === "read") result = await execute();
357
+ else result = await executeExternalOperation({
358
+ principalId: available.principalId,
359
+ capabilityId: toolRef,
360
+ idempotencyKey: connectorArgumentsHash(approvalId ? { approvalId } : {
361
+ conversationId: available.context?.conversationId,
362
+ toolCallId: context.toolCallId
363
+ }),
364
+ requestDigest: argsHash,
365
+ descriptorDigest,
366
+ surface: "agent",
367
+ recovery: "manual"
368
+ }, async () => {
369
+ const outcome = await execute();
370
+ if (outcome.decision !== "allowed") throw new ExternalEffectNotAppliedError(outcome.reason);
371
+ return outcome;
372
+ }, (outcome) => {
373
+ if (outcome.result && typeof outcome.result === "object" && "successful" in outcome.result && outcome.result.successful === false) throw new Error("Provider reported an unsuccessful action without proving that no effect was applied");
374
+ return outcome;
313
375
  });
314
376
  } catch (error) {
315
377
  if (action.scope === "read") {
@@ -342,11 +404,7 @@ var ComposioToolProvider = class {
342
404
  conversationId: available.context?.conversationId,
343
405
  actionId: action.actionId,
344
406
  scope: action.scope,
345
- argumentsHash: connectorArgumentsHash({
346
- args: actionArgs,
347
- accountId: connection.accountId,
348
- objective: available.context ? connectorObjectiveScope(available.context.conversationId) : void 0
349
- }),
407
+ argumentsHash: argumentIdentity(),
350
408
  argumentsPreview: {
351
409
  account: {
352
410
  id: connection.accountId,
@@ -1,6 +1,9 @@
1
1
  import { COMPUTER_CONTROL_TOOL, init_src } from "../../../packages/computer-control-contract/src/index.js";
2
2
  import { BROWSER_CONTROL_ENDPOINT_TOOL_NAME } from "../../../packages/browser-control-contract/src/index.js";
3
+ import { executeExternalOperation } from "../../capabilities/runtime/external-operations.js";
4
+ import { canonicalCapabilityJson } from "../../capabilities/runtime/dispatcher.js";
3
5
  import { externalToolRef, parseExternalToolRef } from "./refs.js";
6
+ import { createHash } from "node:crypto";
4
7
  //#region src/agent/external-tools/endpoint-provider.ts
5
8
  init_src();
6
9
  function contentText(content) {
@@ -40,7 +43,7 @@ var EndpointToolProvider = class {
40
43
  async execute(toolRef, args, _approvalId, context) {
41
44
  const resolved = this.resolve(toolRef);
42
45
  if (!resolved) throw new Error(`Endpoint tool is unavailable for this turn: ${toolRef}`);
43
- const result = await this.deps.runtime.invocations.invoke({
46
+ const invoke = () => this.deps.runtime.invocations.invoke({
44
47
  endpointId: resolved.endpointId,
45
48
  toolCallId: context.toolCallId,
46
49
  toolName: resolved.tool.descriptor.name,
@@ -60,6 +63,15 @@ var EndpointToolProvider = class {
60
63
  });
61
64
  }
62
65
  });
66
+ const result = resolved.tool.descriptor.effect === "read" ? await invoke() : await executeExternalOperation({
67
+ principalId: resolved.principalId,
68
+ capabilityId: toolRef,
69
+ idempotencyKey: createHash("sha256").update(`${this.deps.getCurrentContext()?.conversationId}:${context.toolCallId}`).digest("hex"),
70
+ requestDigest: createHash("sha256").update(canonicalCapabilityJson(args)).digest("hex"),
71
+ descriptorDigest: resolved.tool.revision,
72
+ surface: "agent",
73
+ recovery: "manual"
74
+ }, invoke);
63
75
  const files = result.content.filter((item) => item.type === "file");
64
76
  return {
65
77
  content: result.content.map((item) => ({
@@ -92,6 +104,7 @@ var EndpointToolProvider = class {
92
104
  if (tool && ["browser.control", "desktop.computer.control"].includes(tool.descriptor.name)) return void 0;
93
105
  return tool ? {
94
106
  endpointId: endpoint.endpointId,
107
+ principalId: endpoint.principalId,
95
108
  displayName: endpoint.displayName,
96
109
  tool
97
110
  } : void 0;
@@ -25,6 +25,7 @@ import type { SessionStore } from '../../session/store.js';
25
25
  import type { SessionContext, SessionHydrator, SessionStateBag } from '../session/index.js';
26
26
  import type { InboundAttachmentInput, MediaRef } from '../../channels/attachments/inbound-persist.js';
27
27
  import { type ProcessDirectStreamEvent } from '../service/process-direct-streaming.js';
28
+ import { type WebchatTtsResult } from '../service/webchat-tts.js';
28
29
  import type { AgentSourceContext, AgentSourceContextResolver } from '../source-context/types.js';
29
30
  export interface TurnDispatcherConfig {
30
31
  log: ContextualLogger;
@@ -76,6 +77,7 @@ export declare class TurnDispatcher {
76
77
  runId?: string;
77
78
  sourceContexts?: AgentSourceContext[];
78
79
  presentation?: 'voice';
80
+ onDeferredAudio?: (audio: WebchatTtsResult) => void;
79
81
  }): AsyncGenerator<ProcessDirectStreamEvent, void, unknown>;
80
82
  /** Push an out-of-band event into the live webchat stream for a session. */
81
83
  enqueueWebchatStreamEvent(conversationId: string, event: {
@@ -35,7 +35,8 @@ var TurnDispatcher = class {
35
35
  signal: options?.signal,
36
36
  runId: options?.runId,
37
37
  sourceContexts: options?.sourceContexts,
38
- presentation: options?.presentation
38
+ presentation: options?.presentation,
39
+ onDeferredAudio: options?.onDeferredAudio
39
40
  });
40
41
  }
41
42
  /** Push an out-of-band event into the live webchat stream for a session. */
@@ -7,12 +7,17 @@ export interface HandoverChunk {
7
7
  text: string;
8
8
  sourceThroughSeq: number;
9
9
  }
10
+ export interface CompactionChunkCursorState {
11
+ index: number;
12
+ offset: number;
13
+ }
10
14
  /** Consume source text in order, fitting each chunk against the current ledger. */
11
15
  export declare class CompactionChunkCursor {
12
16
  private readonly sources;
13
17
  private index;
14
18
  private offset;
15
- constructor(sources: readonly CompactionSourceText[]);
19
+ constructor(sources: readonly CompactionSourceText[], state?: CompactionChunkCursorState);
16
20
  get done(): boolean;
21
+ checkpoint(): CompactionChunkCursorState;
17
22
  next(maxTokens: number, fits: (text: string) => boolean): HandoverChunk;
18
23
  }
@@ -2,14 +2,27 @@ import { estimateTextTokens } from "./context-budget.js";
2
2
  //#region src/agent/memory/compaction-chunks.ts
3
3
  /** Consume source text in order, fitting each chunk against the current ledger. */
4
4
  var CompactionChunkCursor = class {
5
- index = 0;
6
- offset = 0;
7
- constructor(sources) {
5
+ index;
6
+ offset;
7
+ constructor(sources, state = {
8
+ index: 0,
9
+ offset: 0
10
+ }) {
8
11
  this.sources = sources;
12
+ const source = sources[state.index];
13
+ if (!Number.isInteger(state.index) || state.index < 0 || state.index > sources.length || !Number.isInteger(state.offset) || state.offset < 0 || (state.index === sources.length ? state.offset !== 0 : state.offset > source.text.length)) throw new Error("Invalid compaction chunk checkpoint");
14
+ this.index = state.index;
15
+ this.offset = state.offset;
9
16
  }
10
17
  get done() {
11
18
  return this.index >= this.sources.length;
12
19
  }
20
+ checkpoint() {
21
+ return {
22
+ index: this.index,
23
+ offset: this.offset
24
+ };
25
+ }
13
26
  next(maxTokens, fits) {
14
27
  const parts = [];
15
28
  let sourceThroughSeq = 0;
@@ -1,11 +1,13 @@
1
1
  import { type CompactionHandover } from '../../session/compaction-types.js';
2
2
  import type { TranscriptSourceEntry } from '../../storage/sqlite/transcript-repository.js';
3
3
  export type { CompactionAudit, CompactionHandover, CompactionHandoverItem, HandoverItemKind, } from '../../session/compaction-types.js';
4
- export declare function parseCompactionHandover(params: {
4
+ /** Apply a bounded model-produced delta to the trusted local handover. */
5
+ export declare function applyCompactionHandoverDelta(params: {
5
6
  text: string;
6
7
  sourceThroughSeq: number;
7
8
  previousBoundaryId?: string;
8
9
  allowedSources: readonly TranscriptSourceEntry[];
10
+ current?: CompactionHandover;
9
11
  }): CompactionHandover;
10
12
  export declare function renderCompactionHandover(handover: CompactionHandover): string;
11
13
  export declare function handoverForPrompt(handover: CompactionHandover | undefined): object;
@@ -3,18 +3,20 @@ import { createHash } from "node:crypto";
3
3
  import { z } from "zod";
4
4
  //#region src/agent/memory/compaction-ledger.ts
5
5
  init_compaction_types();
6
- const RawHandoverItemSchema = z.object({
6
+ const MAX_HANDOVER_ITEMS = 120;
7
+ const RawHandoverUpsertSchema = z.object({
8
+ id: z.string().min(1).max(64).optional(),
7
9
  kind: z.enum(HANDOVER_ITEM_KINDS),
8
- text: z.string().min(1),
10
+ text: z.string().trim().min(1).max(2e3),
9
11
  status: z.enum([
10
12
  "active",
11
13
  "completed",
12
14
  "superseded"
13
15
  ]),
14
16
  sourceSeqs: z.array(z.number().int().positive()).min(1),
15
- identifiers: z.array(z.string()).default([])
17
+ identifiers: z.array(z.string().max(256)).max(20).default([])
16
18
  }).strict();
17
- const RawHandoverSchema = z.object({ items: z.array(RawHandoverItemSchema).max(120) }).strict();
19
+ const RawHandoverDeltaSchema = z.object({ upserts: z.array(RawHandoverUpsertSchema).max(MAX_HANDOVER_ITEMS) }).strict();
18
20
  function extractJsonObject(text) {
19
21
  const fenced = text.match(/```(?:json)?\s*([\s\S]*?)```/i)?.[1]?.trim();
20
22
  if (fenced) return fenced;
@@ -26,34 +28,44 @@ function extractJsonObject(text) {
26
28
  function itemId(kind, text, seqs) {
27
29
  return createHash("sha256").update(`${kind}\0${text.trim()}\0${[...seqs].sort((a, b) => a - b).join(",")}`).digest("hex").slice(0, 20);
28
30
  }
29
- function parseCompactionHandover(params) {
30
- const parsed = RawHandoverSchema.parse(JSON.parse(extractJsonObject(params.text)));
31
- const sourceBySeq = new Map(params.allowedSources.map((source) => [source.seq, source]));
32
- const items = parsed.items.map((item) => {
31
+ /** Apply a bounded model-produced delta to the trusted local handover. */
32
+ function applyCompactionHandoverDelta(params) {
33
+ const parsed = RawHandoverDeltaSchema.parse(JSON.parse(extractJsonObject(params.text)));
34
+ const sourceBySeq = new Map(params.allowedSources.map((source) => [source.seq, {
35
+ entryId: source.entryId,
36
+ seq: source.seq
37
+ }]));
38
+ for (const item of params.current?.items ?? []) for (const source of item.sources) sourceBySeq.set(source.seq, source);
39
+ const items = new Map((params.current?.items ?? []).map((item) => [item.id, item]));
40
+ const seenIds = /* @__PURE__ */ new Set();
41
+ for (const item of parsed.upserts) {
33
42
  const seqs = [...new Set(item.sourceSeqs)].sort((a, b) => a - b);
34
43
  const sources = seqs.map((seq) => {
35
44
  const source = sourceBySeq.get(seq);
36
45
  if (!source || seq > params.sourceThroughSeq) throw new Error(`Compaction handover references unavailable source seq ${seq}`);
37
- return {
38
- entryId: source.entryId,
39
- seq
40
- };
46
+ return source;
41
47
  });
42
48
  const text = item.text.trim();
43
- return {
44
- id: itemId(item.kind, text, seqs),
49
+ const id = item.id ?? itemId(item.kind, text, seqs);
50
+ if (item.id && !items.has(item.id)) throw new Error(`Compaction handover updates unknown item ${item.id}`);
51
+ if (seenIds.has(id)) throw new Error(`Compaction handover repeats item ${id}`);
52
+ seenIds.add(id);
53
+ items.set(id, {
54
+ id,
45
55
  kind: item.kind,
46
56
  text,
47
57
  status: item.status,
48
58
  sources,
49
59
  identifiers: [...new Set(item.identifiers.map((value) => value.trim()).filter(Boolean))]
50
- };
51
- });
60
+ });
61
+ }
62
+ const retained = [...items.values()].filter((item) => item.status !== "superseded");
63
+ if (retained.length > MAX_HANDOVER_ITEMS) throw new Error(`Compaction handover exceeds ${MAX_HANDOVER_ITEMS} durable items`);
52
64
  return {
53
65
  version: 1,
54
66
  sourceThroughSeq: params.sourceThroughSeq,
55
67
  ...params.previousBoundaryId ? { previousBoundaryId: params.previousBoundaryId } : {},
56
- items: [...new Map(items.map((item) => [item.id, item])).values()]
68
+ items: retained
57
69
  };
58
70
  }
59
71
  const SUMMARY_GROUPS = [
@@ -104,6 +116,7 @@ function renderCompactionHandover(handover) {
104
116
  }
105
117
  function handoverForPrompt(handover) {
106
118
  return { items: handover?.items.map((item) => ({
119
+ id: item.id,
107
120
  kind: item.kind,
108
121
  text: item.text,
109
122
  status: item.status,
@@ -112,4 +125,4 @@ function handoverForPrompt(handover) {
112
125
  })) ?? [] };
113
126
  }
114
127
  //#endregion
115
- export { handoverForPrompt, parseCompactionHandover, renderCompactionHandover };
128
+ export { applyCompactionHandoverDelta, handoverForPrompt, renderCompactionHandover };
@@ -6,6 +6,8 @@ export declare class CompactionRequestError extends Error {
6
6
  constructor(kind: 'length' | 'empty' | 'budget' | 'provider' | 'timeout', message: string);
7
7
  }
8
8
  export declare function compactionOutputLimit(model: Model<Api>, configured: number): number;
9
+ /** Start large prompts closer to their likely delta size while retaining room to double on truncation. */
10
+ export declare function initialCompactionOutputLimit(systemPrompt: string, prompt: string, outputLimit: number): number;
9
11
  export declare function compactionPromptFits(model: Model<Api>, systemPrompt: string, prompt: string, outputLimit: number): boolean;
10
12
  /** Bound the final provider payload, including adapters that add a thinking budget. */
11
13
  export declare function compactionPayloadGuard(limit: number, onBudget: (actual: number) => void): NonNullable<SimpleStreamOptions['onPayload']>;
@@ -12,6 +12,11 @@ var CompactionRequestError = class extends Error {
12
12
  function compactionOutputLimit(model, configured) {
13
13
  return Math.min(configured, model.maxTokens > 0 ? model.maxTokens : configured);
14
14
  }
15
+ /** Start large prompts closer to their likely delta size while retaining room to double on truncation. */
16
+ function initialCompactionOutputLimit(systemPrompt, prompt, outputLimit) {
17
+ const estimated = Math.ceil((estimateTextTokens(systemPrompt) + estimateTextTokens(prompt)) * .2);
18
+ return Math.min(outputLimit, estimated > 4e3 ? 8e3 : 4e3);
19
+ }
15
20
  function compactionPromptFits(model, systemPrompt, prompt, outputLimit) {
16
21
  return estimateTextTokens(systemPrompt) + estimateTextTokens(prompt) + 32 + outputLimit + COMPACTION_CONTEXT_MARGIN <= (model.contextWindow || 128e3);
17
22
  }
@@ -69,4 +74,4 @@ function isPermanentCompactionError(error) {
69
74
  return /(?:\b(?:400|401|403|404|422)\b|unauthorized|forbidden|invalid api key|no api key|token expired|context (?:length|window)|maximum context|unsupported parameter|budget cannot fit)/i.test(message);
70
75
  }
71
76
  //#endregion
72
- export { COMPACTION_CONTEXT_MARGIN, COMPACTION_REPAIR_RESERVE, CompactionRequestError, compactionOutputLimit, compactionPayloadGuard, compactionPromptFits, isPermanentCompactionError };
77
+ export { COMPACTION_CONTEXT_MARGIN, COMPACTION_REPAIR_RESERVE, CompactionRequestError, compactionOutputLimit, compactionPayloadGuard, compactionPromptFits, initialCompactionOutputLimit, isPermanentCompactionError };