@xopcai/xopc 0.0.117 → 0.0.119

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 (590) hide show
  1. package/README.md +26 -24
  2. package/README.zh-CN.md +46 -42
  3. package/dist/browser-ext/manifest.json +1 -1
  4. package/dist/extensions/telegram/xopc.extension.json +1 -1
  5. package/dist/gateway/static/root/assets/{agent-avatar-dicebear-BBLhJ2C6.js → agent-avatar-dicebear-CU8J6zou.js} +1 -1
  6. package/dist/gateway/static/root/assets/agents-B0hkpLhP.js +2 -0
  7. package/dist/gateway/static/root/assets/app-management-settings-panel-B9vfYoEr.js +1 -0
  8. package/dist/gateway/static/root/assets/appearance-settings-ClOzIO24.js +1 -0
  9. package/dist/gateway/static/root/assets/{apps-page-DdDx0V4z.js → apps-page-DU0dz9Zo.js} +1 -1
  10. package/dist/gateway/static/root/assets/{archive-plugin-DZsVqMhU.js → archive-plugin-BkVIgZzA.js} +1 -1
  11. package/dist/gateway/static/root/assets/{attachment-load-CIol6JWX.js → attachment-load-CaCMWh1D.js} +1 -1
  12. package/dist/gateway/static/root/assets/automation-suggestion-card-DhGDpKP3.js +1 -0
  13. package/dist/gateway/static/root/assets/automations-page-CTedroVo.js +1 -0
  14. package/dist/gateway/static/root/assets/{binary-plugins-B3UauMfp.js → binary-plugins-B4TO_bsn.js} +1 -1
  15. package/dist/gateway/static/root/assets/{block-editor-2HJoFchH.js → block-editor-DJRWwWNI.js} +6 -6
  16. package/dist/gateway/static/root/assets/browser-settings-page-FCDwOOBK.js +8 -0
  17. package/dist/gateway/static/root/assets/capability-presets-api-Befi89CL.js +1 -0
  18. package/dist/gateway/static/root/assets/capability-presets-settings-panel-_G8eb2vJ.js +1 -0
  19. package/dist/gateway/static/root/assets/channel-recipient-api-BNSuJb5f.js +1 -0
  20. package/dist/gateway/static/root/assets/channels-settings-C3d5JBJX.js +1 -0
  21. package/dist/gateway/static/root/assets/cn-BQ_8x0bT.js +1 -0
  22. package/dist/gateway/static/root/assets/connectors-page-yaUNvt5u.js +2 -0
  23. package/dist/gateway/static/root/assets/cron-expression-B3B1eqnr.js +2 -0
  24. package/dist/gateway/static/root/assets/dreaming-settings-DNrdg1Ve.js +1 -0
  25. package/dist/gateway/static/root/assets/{extension-debug-page-DX5WRE_t.js → extension-debug-page-DYh402XV.js} +1 -1
  26. package/dist/gateway/static/root/assets/{extension-page-Buah7Bw-.js → extension-page-Cr_TizrN.js} +1 -1
  27. package/dist/gateway/static/root/assets/{extension-settings-page-DuroLVnf.js → extension-settings-page-BU1KoKRj.js} +1 -1
  28. package/dist/gateway/static/root/assets/{fetch-B5zdl27C.js → fetch-Y7AEX4H3.js} +1 -1
  29. package/dist/gateway/static/root/assets/format-cron-label-arqgGlVV.js +1 -0
  30. package/dist/gateway/static/root/assets/{gateway-config-api-gT4ZhE7h.js → gateway-config-api-RbMmAOpX.js} +1 -1
  31. package/dist/gateway/static/root/assets/gateway-settings-C79wkXef.js +1 -0
  32. package/dist/gateway/static/root/assets/{gateway-startup-retry-B3kL8KGY.js → gateway-startup-retry-DiD_Tx4N.js} +1 -1
  33. package/dist/gateway/static/root/assets/goal-detail-page-9paXuHdo.js +1 -0
  34. package/dist/gateway/static/root/assets/{goals-config-api-AR-fVh0P.js → goals-config-api-DqxVi0p5.js} +1 -1
  35. package/dist/gateway/static/root/assets/{goals-page-Cpb21ezg.js → goals-page-CS0R-Af2.js} +2 -2
  36. package/dist/gateway/static/root/assets/goals-settings-CSuzZ8Ae.js +1 -0
  37. package/dist/gateway/static/root/assets/heartbeat-settings-DXPaYJm3.js +1 -0
  38. package/dist/gateway/static/root/assets/index-BoKafJIZ.js +191 -0
  39. package/dist/gateway/static/root/assets/index-CArhCcYn.css +1 -0
  40. package/dist/gateway/static/root/assets/keyboard-shortcuts-settings-Dvg53qnd.js +1 -0
  41. package/dist/gateway/static/root/assets/{logs-page-DefCgF4o.js → logs-page-DLXPcksQ.js} +2 -2
  42. package/dist/gateway/static/root/assets/{markdown-split-ChbR9LGO.js → markdown-split-CpHxbtWJ.js} +1 -1
  43. package/dist/gateway/static/root/assets/{media-plugins-B82oP80n.js → media-plugins-SFPQRSxq.js} +1 -1
  44. package/dist/gateway/static/root/assets/messages-CrDHEbss.js +3 -0
  45. package/dist/gateway/static/root/assets/models-hub-panel-BDF2iyRk.js +2 -0
  46. package/dist/gateway/static/root/assets/note-detail-page-CSb_hwig.js +2 -0
  47. package/dist/gateway/static/root/assets/{note-image-lightbox-CDknITM3.js → note-image-lightbox-BUYURRgn.js} +1 -1
  48. package/dist/gateway/static/root/assets/notes-page-BsIBSFyZ.js +1 -0
  49. package/dist/gateway/static/root/assets/{preview-open-alternatives-DV3xQsWB.js → preview-open-alternatives-BHz9iWYA.js} +1 -1
  50. package/dist/gateway/static/root/assets/remote-access-hub-CwzSovcS.js +1 -0
  51. package/dist/gateway/static/root/assets/{save-bar-controls-BODCXnvY.js → save-bar-controls-CefkOlRg.js} +1 -1
  52. package/dist/gateway/static/root/assets/schedule-field-CmTRoOcE.js +1 -0
  53. package/dist/gateway/static/root/assets/{schema-form-qtfEI6QM.js → schema-form-FMKv1vGu.js} +1 -1
  54. package/dist/gateway/static/root/assets/sessions-page-PHmX-NmA.js +1 -0
  55. package/dist/gateway/static/root/assets/settings-advanced-gate-BRAeKJN4.js +1 -0
  56. package/dist/gateway/static/root/assets/{settings-collapsible-section-BHZKjVcS.js → settings-collapsible-section-BouO6JTi.js} +1 -1
  57. package/dist/gateway/static/root/assets/{settings-form-section-5i35D-J1.js → settings-form-section-D-4lBl6X.js} +1 -1
  58. package/dist/gateway/static/root/assets/settings-page-KKrbFjy8.js +1 -0
  59. package/dist/gateway/static/root/assets/settings-page-layout-BJ4Gsef5.js +1 -0
  60. package/dist/gateway/static/root/assets/setup-status-panel-CrUjHPQo.js +1 -0
  61. package/dist/gateway/static/root/assets/{share-preview-page-B0H63tDv.js → share-preview-page-BDy2btRN.js} +1 -1
  62. package/dist/gateway/static/root/assets/shares-settings-B18OBmH5.js +1 -0
  63. package/dist/gateway/static/root/assets/skill-reload-api-C28-2uKQ.js +1 -0
  64. package/dist/gateway/static/root/assets/skills-page-Bm2ebkwl.js +2 -0
  65. package/dist/gateway/static/root/assets/system-settings-panel-CRngrlnZ.js +1 -0
  66. package/dist/gateway/static/root/assets/typed-models-lib-BltBc0b-.js +1 -0
  67. package/dist/gateway/static/root/assets/{use-channel-catalog-BCjP_VHb.js → use-channel-catalog-CjN-51e6.js} +1 -1
  68. package/dist/gateway/static/root/assets/user-profile-settings-panel-DJ1dKwZy.js +1 -0
  69. package/dist/gateway/static/root/assets/utils-B5M5-YvK.js +1 -0
  70. package/dist/gateway/static/root/assets/voice-api-key-field-CeEevm7z.js +1 -0
  71. package/dist/gateway/static/root/assets/{voice-player-store-BlF9V05n.js → voice-player-store-B7ykUlHM.js} +1 -1
  72. package/dist/gateway/static/root/assets/workflow-run-setup-panel-C4PzUQjB.js +3 -0
  73. package/dist/gateway/static/root/assets/workflows-page-BL84_-Ky.js +18 -0
  74. package/dist/gateway/static/root/index.html +6 -7
  75. package/dist/package.js +1 -1
  76. package/dist/src/agent/agent-manager.d.ts +4 -5
  77. package/dist/src/agent/agent-manager.js +6 -9
  78. package/dist/src/agent/agent-manager.js.map +1 -1
  79. package/dist/src/agent/agent-scope.js +0 -2
  80. package/dist/src/agent/agent-scope.js.map +1 -1
  81. package/dist/src/agent/background-review/prompts.d.ts +2 -2
  82. package/dist/src/agent/background-review/prompts.js +2 -2
  83. package/dist/src/agent/background-review/prompts.js.map +1 -1
  84. package/dist/src/agent/background-review/settings.d.ts +1 -1
  85. package/dist/src/agent/background-review/settings.js +7 -8
  86. package/dist/src/agent/background-review/settings.js.map +1 -1
  87. package/dist/src/agent/bootstrap/bootstrap-cache.d.ts +1 -0
  88. package/dist/src/agent/bootstrap/bootstrap-cache.js +4 -3
  89. package/dist/src/agent/bootstrap/bootstrap-cache.js.map +1 -1
  90. package/dist/src/agent/bootstrap/bootstrap-files.d.ts +4 -0
  91. package/dist/src/agent/bootstrap/bootstrap-files.js +4 -3
  92. package/dist/src/agent/bootstrap/bootstrap-files.js.map +1 -1
  93. package/dist/src/agent/bootstrap/filter-bootstrap-files.js +4 -2
  94. package/dist/src/agent/bootstrap/filter-bootstrap-files.js.map +1 -1
  95. package/dist/src/agent/bootstrap/load-bootstrap-files.d.ts +2 -1
  96. package/dist/src/agent/bootstrap/load-bootstrap-files.js +17 -16
  97. package/dist/src/agent/bootstrap/load-bootstrap-files.js.map +1 -1
  98. package/dist/src/agent/bootstrap/types.d.ts +1 -1
  99. package/dist/src/agent/context/workspace-templates/AGENTS.md +1 -1
  100. package/dist/src/agent/context/workspace.d.ts +4 -2
  101. package/dist/src/agent/context/workspace.js +5 -4
  102. package/dist/src/agent/context/workspace.js.map +1 -1
  103. package/dist/src/agent/embedded/run-for-session.js +106 -15
  104. package/dist/src/agent/embedded/run-for-session.js.map +1 -1
  105. package/dist/src/agent/fallback/candidates.d.ts +0 -8
  106. package/dist/src/agent/fallback/candidates.js +10 -11
  107. package/dist/src/agent/fallback/candidates.js.map +1 -1
  108. package/dist/src/agent/index.js +1 -1
  109. package/dist/src/agent/lifecycle/handlers/compaction.d.ts +1 -3
  110. package/dist/src/agent/lifecycle/handlers/compaction.js +1 -16
  111. package/dist/src/agent/lifecycle/handlers/compaction.js.map +1 -1
  112. package/dist/src/agent/lifecycle/progress.d.ts +0 -1
  113. package/dist/src/agent/lifecycle/progress.js +1 -6
  114. package/dist/src/agent/lifecycle/progress.js.map +1 -1
  115. package/dist/src/agent/lifecycle/timeout-wrapper.d.ts +1 -2
  116. package/dist/src/agent/lifecycle/timeout-wrapper.js +1 -7
  117. package/dist/src/agent/lifecycle/timeout-wrapper.js.map +1 -1
  118. package/dist/src/agent/memory/builtin-memory-store.d.ts +4 -2
  119. package/dist/src/agent/memory/builtin-memory-store.js +11 -6
  120. package/dist/src/agent/memory/builtin-memory-store.js.map +1 -1
  121. package/dist/src/agent/memory/builtin-provider.js +36 -7
  122. package/dist/src/agent/memory/builtin-provider.js.map +1 -1
  123. package/dist/src/agent/memory/candidate-extractor.d.ts +6 -0
  124. package/dist/src/agent/memory/candidate-extractor.js +60 -0
  125. package/dist/src/agent/memory/candidate-extractor.js.map +1 -0
  126. package/dist/src/agent/memory/manager.d.ts +2 -1
  127. package/dist/src/agent/memory/manager.js +27 -3
  128. package/dist/src/agent/memory/manager.js.map +1 -1
  129. package/dist/src/agent/memory/memory-config.js +3 -0
  130. package/dist/src/agent/memory/memory-config.js.map +1 -1
  131. package/dist/src/agent/memory/prefetch-coordinator.js.map +1 -1
  132. package/dist/src/agent/memory/types.d.ts +27 -4
  133. package/dist/src/agent/middleware/self-verify.d.ts +0 -1
  134. package/dist/src/agent/middleware/self-verify.js +0 -2
  135. package/dist/src/agent/middleware/self-verify.js.map +1 -1
  136. package/dist/src/agent/models/index.d.ts +1 -1
  137. package/dist/src/agent/models/manager.d.ts +4 -20
  138. package/dist/src/agent/models/manager.js +9 -126
  139. package/dist/src/agent/models/manager.js.map +1 -1
  140. package/dist/src/agent/orchestration/agent-orchestrator.d.ts +0 -4
  141. package/dist/src/agent/orchestration/agent-orchestrator.js +1 -9
  142. package/dist/src/agent/orchestration/agent-orchestrator.js.map +1 -1
  143. package/dist/src/agent/prompt/memory/index.d.ts +4 -2
  144. package/dist/src/agent/prompt/memory/index.js +18 -12
  145. package/dist/src/agent/prompt/memory/index.js.map +1 -1
  146. package/dist/src/agent/prompt/sections/memory-skills.js +1 -1
  147. package/dist/src/agent/prompt/sections/memory-skills.js.map +1 -1
  148. package/dist/src/agent/prompt/sections/tooling.js +2 -2
  149. package/dist/src/agent/prompt/sections/tooling.js.map +1 -1
  150. package/dist/src/agent/prompt/service-prompt-builder.d.ts +0 -1
  151. package/dist/src/agent/prompt/service-prompt-builder.js +4 -31
  152. package/dist/src/agent/prompt/service-prompt-builder.js.map +1 -1
  153. package/dist/src/agent/prompt/subagent-context.js +1 -1
  154. package/dist/src/agent/prompt/subagent-context.js.map +1 -1
  155. package/dist/src/agent/prompt/types.d.ts +1 -1
  156. package/dist/src/agent/reply/post-compaction-context.js +1 -3
  157. package/dist/src/agent/reply/post-compaction-context.js.map +1 -1
  158. package/dist/src/agent/reply/startup-context.js +1 -5
  159. package/dist/src/agent/reply/startup-context.js.map +1 -1
  160. package/dist/src/agent/service.d.ts +4 -12
  161. package/dist/src/agent/service.js +10 -48
  162. package/dist/src/agent/service.js.map +1 -1
  163. package/dist/src/agent/service.types.d.ts +2 -2
  164. package/dist/src/agent/session/session-config-service.d.ts +11 -11
  165. package/dist/src/agent/session/session-config-service.js +14 -14
  166. package/dist/src/agent/session/session-config-service.js.map +1 -1
  167. package/dist/src/agent/session/session-inspector.js +3 -2
  168. package/dist/src/agent/session/session-inspector.js.map +1 -1
  169. package/dist/src/agent/starter-agents.js +12 -12
  170. package/dist/src/agent/starter-agents.js.map +1 -1
  171. package/dist/src/agent/tools/automation-tool.d.ts +14 -0
  172. package/dist/src/agent/tools/automation-tool.js +102 -0
  173. package/dist/src/agent/tools/automation-tool.js.map +1 -0
  174. package/dist/src/agent/tools/curated-memory-tool.js +57 -2
  175. package/dist/src/agent/tools/curated-memory-tool.js.map +1 -1
  176. package/dist/src/agent/tools/delegate-tool.js +1 -1
  177. package/dist/src/agent/tools/delegate-tool.js.map +1 -1
  178. package/dist/src/agent/tools/factory.d.ts +3 -3
  179. package/dist/src/agent/tools/factory.js +2 -2
  180. package/dist/src/agent/tools/factory.js.map +1 -1
  181. package/dist/src/agent/tools/index.d.ts +1 -1
  182. package/dist/src/agent/tools/index.js +2 -2
  183. package/dist/src/agent/tools/web-extract.js +6 -8
  184. package/dist/src/agent/tools/web-extract.js.map +1 -1
  185. package/dist/src/agent-manifest/index.js +2 -2
  186. package/dist/src/agent-manifest/resolver.d.ts +4 -2
  187. package/dist/src/agent-manifest/resolver.js +6 -3
  188. package/dist/src/agent-manifest/resolver.js.map +1 -1
  189. package/dist/src/agent-manifest/schema.d.ts +238 -0
  190. package/dist/src/agent-manifest/schema.js +16 -5
  191. package/dist/src/agent-manifest/schema.js.map +1 -1
  192. package/dist/src/agent-manifest/validator.d.ts +3 -2
  193. package/dist/src/agent-manifest/validator.js +2 -1
  194. package/dist/src/agent-manifest/validator.js.map +1 -1
  195. package/dist/src/ai-assist/text-assist.d.ts +1 -1
  196. package/dist/src/ai-assist/text-assist.js +56 -0
  197. package/dist/src/ai-assist/text-assist.js.map +1 -1
  198. package/dist/src/auth/profiles/store.js.map +1 -1
  199. package/dist/src/automations/api/routes.d.ts +3 -0
  200. package/dist/src/automations/api/routes.js +193 -0
  201. package/dist/src/automations/api/routes.js.map +1 -0
  202. package/dist/src/automations/domain/index.d.ts +3 -0
  203. package/dist/src/automations/domain/index.js +3 -0
  204. package/dist/src/automations/domain/schedule.d.ts +4 -0
  205. package/dist/src/automations/domain/schedule.js +37 -0
  206. package/dist/src/automations/domain/schedule.js.map +1 -0
  207. package/dist/src/automations/domain/types.d.ts +160 -0
  208. package/dist/src/automations/domain/validation.d.ts +370 -0
  209. package/dist/src/automations/domain/validation.js +149 -0
  210. package/dist/src/automations/domain/validation.js.map +1 -0
  211. package/dist/src/automations/draft/automation-draft-prompt.d.ts +26 -0
  212. package/dist/src/automations/draft/automation-draft-prompt.js +127 -0
  213. package/dist/src/automations/draft/automation-draft-prompt.js.map +1 -0
  214. package/dist/src/automations/draft/automation-draft-service.d.ts +12 -0
  215. package/dist/src/automations/draft/automation-draft-service.js +135 -0
  216. package/dist/src/automations/draft/automation-draft-service.js.map +1 -0
  217. package/dist/src/automations/draft/automation-draft-validator.d.ts +99 -0
  218. package/dist/src/automations/draft/automation-draft-validator.js +105 -0
  219. package/dist/src/automations/draft/automation-draft-validator.js.map +1 -0
  220. package/dist/src/automations/draft/automation-draft.types.d.ts +40 -0
  221. package/dist/src/automations/draft/index.d.ts +3 -0
  222. package/dist/src/automations/draft/index.js +3 -0
  223. package/dist/src/automations/index.d.ts +3 -0
  224. package/dist/src/automations/index.js +8 -0
  225. package/dist/src/automations/product-events.d.ts +5 -0
  226. package/dist/src/automations/product-events.js +21 -0
  227. package/dist/src/automations/product-events.js.map +1 -0
  228. package/dist/src/automations/service/action-executor.d.ts +9 -0
  229. package/dist/src/automations/service/action-executor.js +157 -0
  230. package/dist/src/automations/service/action-executor.js.map +1 -0
  231. package/dist/src/automations/service/automation-service.d.ts +54 -0
  232. package/dist/src/automations/service/automation-service.js +404 -0
  233. package/dist/src/automations/service/automation-service.js.map +1 -0
  234. package/dist/src/automations/service/index.d.ts +2 -0
  235. package/dist/src/automations/service/index.js +3 -0
  236. package/dist/src/automations/storage/automation-repository.d.ts +6 -0
  237. package/dist/src/automations/storage/automation-repository.js +61 -0
  238. package/dist/src/automations/storage/automation-repository.js.map +1 -0
  239. package/dist/src/automations/storage/automation-run-repository.d.ts +17 -0
  240. package/dist/src/automations/storage/automation-run-repository.js +130 -0
  241. package/dist/src/automations/storage/automation-run-repository.js.map +1 -0
  242. package/dist/src/automations/storage/index.d.ts +2 -0
  243. package/dist/src/automations/storage/index.js +3 -0
  244. package/dist/src/channels/pipeline.d.ts +1 -1
  245. package/dist/src/channels/pipeline.js.map +1 -1
  246. package/dist/src/channels/plugin-types.d.ts +3 -0
  247. package/dist/src/chat-commands/agent-edit.js +0 -1
  248. package/dist/src/chat-commands/agent-edit.js.map +1 -1
  249. package/dist/src/chat-commands/builtins/model.js +2 -2
  250. package/dist/src/chat-commands/builtins/model.js.map +1 -1
  251. package/dist/src/chat-commands/builtins/thinking.js.map +1 -1
  252. package/dist/src/cli/command-catalog.js +0 -39
  253. package/dist/src/cli/command-catalog.js.map +1 -1
  254. package/dist/src/cli/command-loaders.js +0 -1
  255. package/dist/src/cli/command-loaders.js.map +1 -1
  256. package/dist/src/cli/command-manifest.d.ts +1 -1
  257. package/dist/src/cli/command-manifest.js +1 -5
  258. package/dist/src/cli/command-manifest.js.map +1 -1
  259. package/dist/src/cli/commands/agents.js +7 -6
  260. package/dist/src/cli/commands/agents.js.map +1 -1
  261. package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
  262. package/dist/src/cli/commands/doctor/checks/{cron-health.d.ts → migrations.d.ts} +1 -1
  263. package/dist/src/cli/commands/doctor/checks/migrations.js +40 -0
  264. package/dist/src/cli/commands/doctor/checks/migrations.js.map +1 -0
  265. package/dist/src/cli/commands/doctor/checks/provider-auth.js +1 -0
  266. package/dist/src/cli/commands/doctor/checks/provider-auth.js.map +1 -1
  267. package/dist/src/cli/commands/doctor/checks/workspace-status.js +0 -1
  268. package/dist/src/cli/commands/doctor/checks/workspace-status.js.map +1 -1
  269. package/dist/src/cli/commands/doctor/flow.js +2 -2
  270. package/dist/src/cli/commands/doctor/flow.js.map +1 -1
  271. package/dist/src/cli/commands/gateway/call.js +2 -2
  272. package/dist/src/cli/commands/gateway/call.js.map +1 -1
  273. package/dist/src/cli/commands/gateway/lifecycle.js +1 -1
  274. package/dist/src/cli/commands/gateway/run-foreground.js +4 -2
  275. package/dist/src/cli/commands/gateway/run-foreground.js.map +1 -1
  276. package/dist/src/cli/commands/init.js +33 -14
  277. package/dist/src/cli/commands/init.js.map +1 -1
  278. package/dist/src/cli/commands/models.js +13 -31
  279. package/dist/src/cli/commands/models.js.map +1 -1
  280. package/dist/src/cli/commands/onboard/model.js +17 -10
  281. package/dist/src/cli/commands/onboard/model.js.map +1 -1
  282. package/dist/src/cli/commands/onboard.js +2 -2
  283. package/dist/src/cli/commands/onboard.js.map +1 -1
  284. package/dist/src/cli/commands/tui.js +26 -4
  285. package/dist/src/cli/commands/tui.js.map +1 -1
  286. package/dist/src/cli/index.d.ts +1 -0
  287. package/dist/src/cli/index.js +10 -5
  288. package/dist/src/cli/index.js.map +1 -1
  289. package/dist/src/cli/registry.js +1 -1
  290. package/dist/src/cli/registry.js.map +1 -1
  291. package/dist/src/cli/templates.d.ts +1 -1
  292. package/dist/src/cli/templates.js +1 -11
  293. package/dist/src/cli/templates.js.map +1 -1
  294. package/dist/src/cli/utils/init-workspace-core.js +2 -0
  295. package/dist/src/cli/utils/init-workspace-core.js.map +1 -1
  296. package/dist/src/commands/agents.config.d.ts +9 -0
  297. package/dist/src/commands/agents.config.js +42 -12
  298. package/dist/src/commands/agents.config.js.map +1 -1
  299. package/dist/src/config/agent-profile.js +5 -3
  300. package/dist/src/config/agent-profile.js.map +1 -1
  301. package/dist/src/config/agent-typed-models.js +3 -5
  302. package/dist/src/config/agent-typed-models.js.map +1 -1
  303. package/dist/src/config/config-surface.d.ts +3 -0
  304. package/dist/src/config/index.d.ts +0 -1
  305. package/dist/src/config/index.js +3 -3
  306. package/dist/src/config/index.js.map +1 -1
  307. package/dist/src/config/paths.d.ts +8 -10
  308. package/dist/src/config/paths.js +16 -16
  309. package/dist/src/config/paths.js.map +1 -1
  310. package/dist/src/config/profile.js +0 -1
  311. package/dist/src/config/profile.js.map +1 -1
  312. package/dist/src/config/rules.js +0 -5
  313. package/dist/src/config/rules.js.map +1 -1
  314. package/dist/src/config/schema.d.ts +45 -44
  315. package/dist/src/config/schema.js +68 -52
  316. package/dist/src/config/schema.js.map +1 -1
  317. package/dist/src/config/web-patch.d.ts +0 -12
  318. package/dist/src/config/web-patch.js +2 -29
  319. package/dist/src/config/web-patch.js.map +1 -1
  320. package/dist/src/extensions/api.d.ts +2 -0
  321. package/dist/src/extensions/api.js +10 -0
  322. package/dist/src/extensions/api.js.map +1 -1
  323. package/dist/src/extensions/extension-registry-impl.d.ts +4 -1
  324. package/dist/src/extensions/extension-registry-impl.js +8 -0
  325. package/dist/src/extensions/extension-registry-impl.js.map +1 -1
  326. package/dist/src/extensions/loader.d.ts +3 -3
  327. package/dist/src/extensions/loader.js +3 -3
  328. package/dist/src/extensions/loader.js.map +1 -1
  329. package/dist/src/extensions/sdk/testing.d.ts +2 -0
  330. package/dist/src/extensions/sdk/testing.js +7 -0
  331. package/dist/src/extensions/sdk/testing.js.map +1 -1
  332. package/dist/src/extensions/types/core.d.ts +10 -1
  333. package/dist/src/extensions/types/index.d.ts +1 -1
  334. package/dist/src/extensions/types/{phase4.d.ts → registration.d.ts} +2 -2
  335. package/dist/src/gateway/agent-builtin-tools.d.ts +1 -1
  336. package/dist/src/gateway/agent-builtin-tools.js +1 -1
  337. package/dist/src/gateway/agent-builtin-tools.js.map +1 -1
  338. package/dist/src/gateway/agents-admin.d.ts +8 -0
  339. package/dist/src/gateway/agents-admin.js +63 -34
  340. package/dist/src/gateway/agents-admin.js.map +1 -1
  341. package/dist/src/gateway/capability-presets-admin.d.ts +1 -0
  342. package/dist/src/gateway/capability-presets-admin.js +19 -10
  343. package/dist/src/gateway/capability-presets-admin.js.map +1 -1
  344. package/dist/src/gateway/chat-stream/mapper.js +9 -2
  345. package/dist/src/gateway/chat-stream/mapper.js.map +1 -1
  346. package/dist/src/gateway/dreaming-automation-reconciler.d.ts +11 -0
  347. package/dist/src/gateway/dreaming-automation-reconciler.js +105 -0
  348. package/dist/src/gateway/dreaming-automation-reconciler.js.map +1 -0
  349. package/dist/src/gateway/global-defaults-admin.d.ts +36 -0
  350. package/dist/src/gateway/global-defaults-admin.js +146 -0
  351. package/dist/src/gateway/global-defaults-admin.js.map +1 -0
  352. package/dist/src/gateway/heartbeat/service.d.ts +0 -2
  353. package/dist/src/gateway/heartbeat/service.js +0 -7
  354. package/dist/src/gateway/heartbeat/service.js.map +1 -1
  355. package/dist/src/gateway/hono/lib/config-payload.d.ts +5 -6
  356. package/dist/src/gateway/hono/lib/config-payload.js +2 -2
  357. package/dist/src/gateway/hono/lib/config-payload.js.map +1 -1
  358. package/dist/src/gateway/hono/routes/agents.js +33 -1
  359. package/dist/src/gateway/hono/routes/agents.js.map +1 -1
  360. package/dist/src/gateway/hono/routes/commands-skills.js +4 -5
  361. package/dist/src/gateway/hono/routes/commands-skills.js.map +1 -1
  362. package/dist/src/gateway/hono/routes/config-patch/misc.d.ts +1 -1
  363. package/dist/src/gateway/hono/routes/config-patch/misc.js +12 -6
  364. package/dist/src/gateway/hono/routes/config-patch/misc.js.map +1 -1
  365. package/dist/src/gateway/hono/routes/dreaming.js +27 -37
  366. package/dist/src/gateway/hono/routes/dreaming.js.map +1 -1
  367. package/dist/src/gateway/hono/routes/global-defaults.d.ts +3 -0
  368. package/dist/src/gateway/hono/routes/global-defaults.js +61 -0
  369. package/dist/src/gateway/hono/routes/global-defaults.js.map +1 -0
  370. package/dist/src/gateway/hono/routes/home.d.ts +2 -2
  371. package/dist/src/gateway/hono/routes/home.js +34 -25
  372. package/dist/src/gateway/hono/routes/home.js.map +1 -1
  373. package/dist/src/gateway/hono/routes/lazy-bundles.js +21 -9
  374. package/dist/src/gateway/hono/routes/lazy-bundles.js.map +1 -1
  375. package/dist/src/gateway/hono/routes/memory.js +75 -4
  376. package/dist/src/gateway/hono/routes/memory.js.map +1 -1
  377. package/dist/src/gateway/hono/routes/migrations.d.ts +3 -0
  378. package/dist/src/gateway/hono/routes/migrations.js +35 -0
  379. package/dist/src/gateway/hono/routes/migrations.js.map +1 -0
  380. package/dist/src/gateway/hono/routes/models.js +1 -1
  381. package/dist/src/gateway/hono/routes/public-gateway.js +2 -1
  382. package/dist/src/gateway/hono/routes/public-gateway.js.map +1 -1
  383. package/dist/src/gateway/hono/routes/sessions.js +14 -0
  384. package/dist/src/gateway/hono/routes/sessions.js.map +1 -1
  385. package/dist/src/gateway/run-loop.js +2 -0
  386. package/dist/src/gateway/run-loop.js.map +1 -1
  387. package/dist/src/gateway/security/operator-scopes.js +5 -1
  388. package/dist/src/gateway/security/operator-scopes.js.map +1 -1
  389. package/dist/src/gateway/service/config-coordinator.d.ts +4 -4
  390. package/dist/src/gateway/service/config-coordinator.js +14 -8
  391. package/dist/src/gateway/service/config-coordinator.js.map +1 -1
  392. package/dist/src/gateway/service/marketplace-service.d.ts +4 -4
  393. package/dist/src/gateway/service/marketplace-service.js +11 -7
  394. package/dist/src/gateway/service/marketplace-service.js.map +1 -1
  395. package/dist/src/gateway/service/sessions-api.d.ts +2 -1
  396. package/dist/src/gateway/service/sessions-api.js +6 -1
  397. package/dist/src/gateway/service/sessions-api.js.map +1 -1
  398. package/dist/src/gateway/service.d.ts +7 -3
  399. package/dist/src/gateway/service.js +61 -27
  400. package/dist/src/gateway/service.js.map +1 -1
  401. package/dist/src/goals/goal-service.js +45 -4
  402. package/dist/src/goals/goal-service.js.map +1 -1
  403. package/dist/src/infra/update-restart.js +1 -1
  404. package/dist/src/migrations/config/default-capability-preset.d.ts +10 -0
  405. package/dist/src/migrations/config/default-capability-preset.js +135 -0
  406. package/dist/src/migrations/config/default-capability-preset.js.map +1 -0
  407. package/dist/src/migrations/index.d.ts +4 -0
  408. package/dist/src/migrations/index.js +4 -0
  409. package/dist/src/migrations/registry.d.ts +8 -0
  410. package/dist/src/migrations/registry.js +18 -0
  411. package/dist/src/migrations/registry.js.map +1 -0
  412. package/dist/src/migrations/runner.d.ts +17 -0
  413. package/dist/src/migrations/runner.js +191 -0
  414. package/dist/src/migrations/runner.js.map +1 -0
  415. package/dist/src/migrations/types.d.ts +34 -0
  416. package/dist/src/notes/service.js +27 -2
  417. package/dist/src/notes/service.js.map +1 -1
  418. package/dist/src/providers/index.d.ts +4 -5
  419. package/dist/src/providers/index.js +16 -16
  420. package/dist/src/providers/index.js.map +1 -1
  421. package/dist/src/providers/model-registry.d.ts +0 -1
  422. package/dist/src/providers/model-registry.js +0 -3
  423. package/dist/src/providers/model-registry.js.map +1 -1
  424. package/dist/src/routing/resolve-tui-session-key.d.ts +3 -0
  425. package/dist/src/routing/resolve-tui-session-key.js +14 -3
  426. package/dist/src/routing/resolve-tui-session-key.js.map +1 -1
  427. package/dist/src/session/session-workspace.js +2 -7
  428. package/dist/src/session/session-workspace.js.map +1 -1
  429. package/dist/src/session/store.js +0 -5
  430. package/dist/src/session/store.js.map +1 -1
  431. package/dist/src/session/transcript-outline.d.ts +47 -0
  432. package/dist/src/session/transcript-outline.js +481 -0
  433. package/dist/src/session/transcript-outline.js.map +1 -0
  434. package/dist/src/storage/sqlite/index.d.ts +1 -3
  435. package/dist/src/storage/sqlite/index.js +2 -4
  436. package/dist/src/storage/sqlite/memory-index-repository.d.ts +1 -0
  437. package/dist/src/storage/sqlite/memory-index-repository.js +15 -14
  438. package/dist/src/storage/sqlite/memory-index-repository.js.map +1 -1
  439. package/dist/src/storage/sqlite/memory-records-repository.d.ts +44 -1
  440. package/dist/src/storage/sqlite/memory-records-repository.js +164 -20
  441. package/dist/src/storage/sqlite/memory-records-repository.js.map +1 -1
  442. package/dist/src/storage/sqlite/migrations/014_memory_record_governance.sql +10 -0
  443. package/dist/src/storage/sqlite/migrations/015_memory_trace_feedback.sql +4 -0
  444. package/dist/src/storage/sqlite/migrations/016_automations.sql +47 -0
  445. package/dist/src/storage/sqlite/migrations/017_automation_run_events.sql +14 -0
  446. package/dist/src/storage/sqlite/migrations/018_automation_safety.sql +1 -0
  447. package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
  448. package/dist/src/storage/sqlite/migrations/runner.js +3 -3
  449. package/dist/src/storage/sqlite/migrations/runner.js.map +1 -1
  450. package/dist/src/storage/sqlite/migrations/runner.ts +1 -1
  451. package/dist/src/storage/sqlite/schema.js +1 -1
  452. package/dist/src/storage/sqlite/schema.sql +56 -46
  453. package/dist/src/tui/backends/embedded-backend.d.ts +9 -0
  454. package/dist/src/tui/backends/embedded-backend.js +55 -27
  455. package/dist/src/tui/backends/embedded-backend.js.map +1 -1
  456. package/dist/src/tui/backends/gateway-sse-backend.d.ts +4 -0
  457. package/dist/src/tui/backends/gateway-sse-backend.js +30 -3
  458. package/dist/src/tui/backends/gateway-sse-backend.js.map +1 -1
  459. package/dist/src/tui/components/tui-header.d.ts +0 -1
  460. package/dist/src/tui/components/tui-header.js +3 -8
  461. package/dist/src/tui/components/tui-header.js.map +1 -1
  462. package/dist/src/tui/tui-backend.d.ts +4 -0
  463. package/dist/src/tui/tui-commands.d.ts +5 -0
  464. package/dist/src/tui/tui-commands.js +43 -0
  465. package/dist/src/tui/tui-commands.js.map +1 -1
  466. package/dist/src/tui/tui-startup-resources.js +2 -1
  467. package/dist/src/tui/tui-startup-resources.js.map +1 -1
  468. package/dist/src/tui/tui-startup-text.js +12 -12
  469. package/dist/src/tui/tui-startup-text.js.map +1 -1
  470. package/dist/src/tui/tui-transcript-tree.d.ts +1 -1
  471. package/dist/src/tui/tui-transcript-tree.js +17 -257
  472. package/dist/src/tui/tui-transcript-tree.js.map +1 -1
  473. package/dist/src/tui/tui-types.d.ts +2 -0
  474. package/dist/src/tui/tui-types.js.map +1 -1
  475. package/dist/src/tui/tui.js +11 -3
  476. package/dist/src/tui/tui.js.map +1 -1
  477. package/dist/src/workflows/domain/index.js +1 -1
  478. package/dist/src/workflows/domain/run.d.ts +7 -7
  479. package/dist/src/workflows/domain/run.js.map +1 -1
  480. package/dist/src/workflows/index.js +2 -2
  481. package/dist/src/workflows/service/workflow-run-service.d.ts +2 -0
  482. package/dist/src/workflows/service/workflow-run-service.js +31 -9
  483. package/dist/src/workflows/service/workflow-run-service.js.map +1 -1
  484. package/dist/src/workflows/service/workflow-run-service.types.d.ts +1 -1
  485. package/package.json +4 -2
  486. package/dist/gateway/static/root/assets/agents-C6xgagZd.js +0 -71
  487. package/dist/gateway/static/root/assets/app-management-settings-panel-CBpLONvG.js +0 -1
  488. package/dist/gateway/static/root/assets/appearance-settings-CGcc54yj.js +0 -1
  489. package/dist/gateway/static/root/assets/browser-settings-page-CUOO-PQk.js +0 -8
  490. package/dist/gateway/static/root/assets/capability-presets-api-XQoMTI0A.js +0 -1
  491. package/dist/gateway/static/root/assets/capability-presets-settings-panel-CfqF-kGr.js +0 -1
  492. package/dist/gateway/static/root/assets/channels-settings-BYyRzsex.js +0 -1
  493. package/dist/gateway/static/root/assets/cn-JdwAhgNB.js +0 -1
  494. package/dist/gateway/static/root/assets/connectors-page-DIvEz4NX.js +0 -2
  495. package/dist/gateway/static/root/assets/createLucideIcon-DPHK1VkS.js +0 -1
  496. package/dist/gateway/static/root/assets/cron-api-R41aQCX9.js +0 -1
  497. package/dist/gateway/static/root/assets/cron-dreaming-jobs-nCMWCf0p.js +0 -1
  498. package/dist/gateway/static/root/assets/cron-page-D97nFqQD.js +0 -3
  499. package/dist/gateway/static/root/assets/dreaming-settings-Bceaw1PG.js +0 -1
  500. package/dist/gateway/static/root/assets/format-cron-label-BsotZDO5.js +0 -2
  501. package/dist/gateway/static/root/assets/format-interval-label-Dn_QKIqb.js +0 -1
  502. package/dist/gateway/static/root/assets/gateway-settings-iISWAZRm.js +0 -1
  503. package/dist/gateway/static/root/assets/goal-detail-page-DCUROLMQ.js +0 -1
  504. package/dist/gateway/static/root/assets/goals-settings-CPAuFwoD.js +0 -1
  505. package/dist/gateway/static/root/assets/heartbeat-config-api-D7bKFEeO.js +0 -1
  506. package/dist/gateway/static/root/assets/heartbeat-settings-CC69vNx0.js +0 -1
  507. package/dist/gateway/static/root/assets/index-CwhK8qCh.js +0 -122
  508. package/dist/gateway/static/root/assets/index-CyfhARL-.css +0 -1
  509. package/dist/gateway/static/root/assets/interval-presets-0DtsnxE0.js +0 -1
  510. package/dist/gateway/static/root/assets/keyboard-shortcuts-settings-BPREtN8B.js +0 -1
  511. package/dist/gateway/static/root/assets/messages-Cf1O9JB0.js +0 -3
  512. package/dist/gateway/static/root/assets/models-hub-panel-DmKiIihT.js +0 -2
  513. package/dist/gateway/static/root/assets/note-detail-page-CxxfLRJZ.js +0 -2
  514. package/dist/gateway/static/root/assets/notes-page-X2slSx7V.js +0 -1
  515. package/dist/gateway/static/root/assets/remote-access-hub-BvmUWqgu.js +0 -1
  516. package/dist/gateway/static/root/assets/schedule-field-CgJSCD3B.js +0 -1
  517. package/dist/gateway/static/root/assets/sessions-page-B0yESuuL.js +0 -1
  518. package/dist/gateway/static/root/assets/settings-advanced-gate-q2M8RKOo.js +0 -1
  519. package/dist/gateway/static/root/assets/settings-page-CGozabLD.js +0 -1
  520. package/dist/gateway/static/root/assets/setup-status-panel-FoOSe6nU.js +0 -1
  521. package/dist/gateway/static/root/assets/shares-settings-Cy5zWyYQ.js +0 -1
  522. package/dist/gateway/static/root/assets/skill-reload-api-DaZNFro9.js +0 -1
  523. package/dist/gateway/static/root/assets/skills-page-CnwtUzvw.js +0 -2
  524. package/dist/gateway/static/root/assets/system-settings-panel-DXs2VmBt.js +0 -1
  525. package/dist/gateway/static/root/assets/typed-models-lib-4gPuydz_.js +0 -1
  526. package/dist/gateway/static/root/assets/voice-api-key-field-DvKiOglO.js +0 -1
  527. package/dist/gateway/static/root/assets/workflows-page-CAVZcONQ.js +0 -18
  528. package/dist/src/agent/context/workspace-templates/USER.md +0 -24
  529. package/dist/src/agent/fallback/error.d.ts +0 -22
  530. package/dist/src/agent/fallback/error.js +0 -32
  531. package/dist/src/agent/fallback/error.js.map +0 -1
  532. package/dist/src/agent/fallback/index.d.ts +0 -5
  533. package/dist/src/agent/fallback/index.js +0 -9
  534. package/dist/src/agent/fallback/index.js.map +0 -1
  535. package/dist/src/agent/orchestration/run-agent-turn-with-fallbacks.d.ts +0 -29
  536. package/dist/src/agent/orchestration/run-agent-turn-with-fallbacks.js +0 -76
  537. package/dist/src/agent/orchestration/run-agent-turn-with-fallbacks.js.map +0 -1
  538. package/dist/src/agent/service/reconcile-dreaming-cron.d.ts +0 -6
  539. package/dist/src/agent/service/reconcile-dreaming-cron.js +0 -84
  540. package/dist/src/agent/service/reconcile-dreaming-cron.js.map +0 -1
  541. package/dist/src/agent/tools/cronjob-tool.d.ts +0 -29
  542. package/dist/src/agent/tools/cronjob-tool.js +0 -274
  543. package/dist/src/agent/tools/cronjob-tool.js.map +0 -1
  544. package/dist/src/cli/commands/cron-cli.d.ts +0 -2
  545. package/dist/src/cli/commands/cron-cli.js +0 -15
  546. package/dist/src/cli/commands/cron-cli.js.map +0 -1
  547. package/dist/src/cli/commands/cron.d.ts +0 -4
  548. package/dist/src/cli/commands/cron.js +0 -188
  549. package/dist/src/cli/commands/cron.js.map +0 -1
  550. package/dist/src/cli/commands/doctor/checks/cron-health.js +0 -35
  551. package/dist/src/cli/commands/doctor/checks/cron-health.js.map +0 -1
  552. package/dist/src/cron/execution-types.d.ts +0 -42
  553. package/dist/src/cron/executor.d.ts +0 -67
  554. package/dist/src/cron/executor.js +0 -669
  555. package/dist/src/cron/executor.js.map +0 -1
  556. package/dist/src/cron/index.d.ts +0 -7
  557. package/dist/src/cron/index.js +0 -7
  558. package/dist/src/cron/job-content.d.ts +0 -5
  559. package/dist/src/cron/job-content.js +0 -15
  560. package/dist/src/cron/job-content.js.map +0 -1
  561. package/dist/src/cron/run-log-store.d.ts +0 -12
  562. package/dist/src/cron/run-log-store.js +0 -58
  563. package/dist/src/cron/run-log-store.js.map +0 -1
  564. package/dist/src/cron/schedule.d.ts +0 -10
  565. package/dist/src/cron/schedule.js +0 -85
  566. package/dist/src/cron/schedule.js.map +0 -1
  567. package/dist/src/cron/service.d.ts +0 -58
  568. package/dist/src/cron/service.js +0 -419
  569. package/dist/src/cron/service.js.map +0 -1
  570. package/dist/src/cron/types.d.ts +0 -183
  571. package/dist/src/cron/validation.d.ts +0 -500
  572. package/dist/src/cron/validation.js +0 -192
  573. package/dist/src/cron/validation.js.map +0 -1
  574. package/dist/src/cron/workflow-run-completion.d.ts +0 -23
  575. package/dist/src/cron/workflow-run-completion.js +0 -72
  576. package/dist/src/cron/workflow-run-completion.js.map +0 -1
  577. package/dist/src/extensions/types/phase4.js +0 -1
  578. package/dist/src/gateway/hono/routes/cron.d.ts +0 -3
  579. package/dist/src/gateway/hono/routes/cron.js +0 -109
  580. package/dist/src/gateway/hono/routes/cron.js.map +0 -1
  581. package/dist/src/storage/sqlite/cron-job-repository.d.ts +0 -6
  582. package/dist/src/storage/sqlite/cron-job-repository.js +0 -70
  583. package/dist/src/storage/sqlite/cron-job-repository.js.map +0 -1
  584. package/dist/src/storage/sqlite/cron-run-repository.d.ts +0 -5
  585. package/dist/src/storage/sqlite/cron-run-repository.js +0 -96
  586. package/dist/src/storage/sqlite/cron-run-repository.js.map +0 -1
  587. /package/dist/src/{cron → automations/domain}/types.js +0 -0
  588. /package/dist/src/{config/defaults.d.ts → automations/draft/automation-draft.types.js} +0 -0
  589. /package/dist/src/{config/defaults.js → extensions/types/registration.js} +0 -0
  590. /package/dist/src/{cron/execution-types.js → migrations/types.js} +0 -0
@@ -0,0 +1,127 @@
1
+ //#region src/automations/draft/automation-draft-prompt.ts
2
+ function buildAutomationDraftPrompt(params) {
3
+ return `You generate xopc automation drafts. Return ONLY a JSON object, no markdown.
4
+
5
+ JSON shape:
6
+ {
7
+ "automation": {
8
+ "name": "Short human name",
9
+ "description": "What this automation does",
10
+ "trigger": { "kind": "manual" },
11
+ "action": { "kind": "agent", "instruction": "clear instruction for the agent" },
12
+ "safety": { "mode": "suggest_only" },
13
+ "afterRun": { "kind": "none" },
14
+ "reliability": { "timeoutSeconds": 300, "disableAfterConsecutiveFailures": 3 }
15
+ },
16
+ "explanation": "Short explanation",
17
+ "assumptions": ["..."],
18
+ "risks": ["..."]
19
+ }
20
+
21
+ Allowed triggers:
22
+ - Manual: { "kind": "manual" }
23
+ - Schedule interval: { "kind": "schedule", "schedule": { "kind": "interval", "everyMs": 3600000 } }
24
+ - Schedule cron: { "kind": "schedule", "schedule": { "kind": "cron", "expr": "0 9 * * *" } }
25
+ - Webhook: { "kind": "webhook", "secretId": "optional-short-id" }
26
+ - Product event: { "kind": "event", "eventType": "goal.status_changed", "source": "goals", "payloadMatch": { "status": "blocked" } }
27
+
28
+ Useful product events:
29
+ - session.message.created
30
+ - session.transcript.updated
31
+ - note.created
32
+ - note.updated
33
+ - goal.created
34
+ - goal.status_changed
35
+ - workflow.run.completed
36
+ - channel.message.received
37
+
38
+ Allowed actions:
39
+ - Agent: { "kind": "agent", "agentId": "optional", "instruction": "what to do", "timeoutSeconds": 300 }
40
+ - Workflow: { "kind": "workflow", "workflowId": "known_workflow_id", "input": {}, "goal": "optional", "timeoutSeconds": 300 }
41
+
42
+ Safety modes:
43
+ - { "mode": "suggest_only" }: safest default, generate recommendations only.
44
+ - { "mode": "ask_before_apply" }: draft actions and require user confirmation before applying.
45
+ - { "mode": "auto_apply" }: trusted automation may act automatically.
46
+
47
+ Rules:
48
+ - Prefer agent actions unless the user names a specific existing workflow id.
49
+ - Default to safety { "mode": "suggest_only" } unless the user explicitly asks for fully automatic execution.
50
+ - Do not invent destructive actions. For deletion, external sending, or irreversible changes, include a risk and make the instruction ask for confirmation.
51
+ - Use cron for daily/weekly schedules. Use standard 5-field cron.
52
+ - Keep timeoutSeconds between 60 and 1800.
53
+ - afterRun should usually be { "kind": "none" }.
54
+ - Language for user-facing copy: ${params.language ?? "en"}.
55
+
56
+ User request:
57
+ ${params.prompt.slice(0, 8e3)}
58
+ `;
59
+ }
60
+ function buildAutomationDraftRepairPrompt(params) {
61
+ return `Repair the xopc automation draft. Return ONLY a JSON object with the same shape.
62
+
63
+ Original user request:
64
+ ${params.prompt.slice(0, 8e3)}
65
+
66
+ Language for user-facing copy: ${params.language ?? "en"}
67
+
68
+ Previous output:
69
+ ${params.previousOutput.slice(0, 12e3)}
70
+
71
+ Issues:
72
+ ${params.issues.map((issue) => `- ${issue.source}: ${issue.message}`).join("\n")}
73
+ `;
74
+ }
75
+ function buildAutomationRunRepairPrompt(params) {
76
+ return `You suggest safe repair patches for xopc automations. Return ONLY a JSON object, no markdown.
77
+
78
+ JSON shape:
79
+ {
80
+ "patch": {
81
+ "description": "optional improved description",
82
+ "trigger": "optional complete trigger object",
83
+ "action": "optional complete action object",
84
+ "safety": "optional complete safety object",
85
+ "afterRun": "optional complete afterRun object",
86
+ "reliability": "optional complete reliability object",
87
+ "enabled": true
88
+ },
89
+ "explanation": "Why this patch should fix the failed run",
90
+ "expectedEffect": "What changes after applying it",
91
+ "risks": ["..."],
92
+ "requiresApproval": true
93
+ }
94
+
95
+ Rules:
96
+ - Return a PATCH only. Do not include id, state, createdAtMs, or updatedAtMs.
97
+ - Keep the patch minimal. Prefer reliability/action/input fixes over broad rewrites.
98
+ - If the failure is unclear, propose only a safer timeout/retry/description patch and explain uncertainty.
99
+ - Never add destructive or external behavior. If the existing automation has risky external behavior, keep requiresApproval true.
100
+ - Language for user-facing copy: ${params.language ?? "en"}.
101
+
102
+ Current automation:
103
+ ${JSON.stringify(params.automation, null, 2).slice(0, 12e3)}
104
+
105
+ Failed run:
106
+ ${JSON.stringify(params.run, null, 2).slice(0, 8e3)}
107
+
108
+ Timeline events:
109
+ ${JSON.stringify(params.events, null, 2).slice(0, 12e3)}
110
+ `;
111
+ }
112
+ function buildAutomationRunRepairRetryPrompt(params) {
113
+ return `Repair the automation repair patch. Return ONLY a JSON object with the same shape.
114
+
115
+ Language for user-facing copy: ${params.language ?? "en"}
116
+
117
+ Previous output:
118
+ ${params.previousOutput.slice(0, 12e3)}
119
+
120
+ Issues:
121
+ ${params.issues.map((issue) => `- ${issue.source}: ${issue.message}`).join("\n")}
122
+ `;
123
+ }
124
+ //#endregion
125
+ export { buildAutomationDraftPrompt, buildAutomationDraftRepairPrompt, buildAutomationRunRepairPrompt, buildAutomationRunRepairRetryPrompt };
126
+
127
+ //# sourceMappingURL=automation-draft-prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"automation-draft-prompt.js","names":[],"sources":["../../../../src/automations/draft/automation-draft-prompt.ts"],"sourcesContent":["export interface AutomationDraftRepairIssue {\n source: 'parse' | 'validation';\n severity: 'error';\n message: string;\n}\n\nexport function buildAutomationDraftPrompt(params: {\n prompt: string;\n language?: 'en' | 'zh';\n}): string {\n return `You generate xopc automation drafts. Return ONLY a JSON object, no markdown.\n\nJSON shape:\n{\n \"automation\": {\n \"name\": \"Short human name\",\n \"description\": \"What this automation does\",\n \"trigger\": { \"kind\": \"manual\" },\n \"action\": { \"kind\": \"agent\", \"instruction\": \"clear instruction for the agent\" },\n \"safety\": { \"mode\": \"suggest_only\" },\n \"afterRun\": { \"kind\": \"none\" },\n \"reliability\": { \"timeoutSeconds\": 300, \"disableAfterConsecutiveFailures\": 3 }\n },\n \"explanation\": \"Short explanation\",\n \"assumptions\": [\"...\"],\n \"risks\": [\"...\"]\n}\n\nAllowed triggers:\n- Manual: { \"kind\": \"manual\" }\n- Schedule interval: { \"kind\": \"schedule\", \"schedule\": { \"kind\": \"interval\", \"everyMs\": 3600000 } }\n- Schedule cron: { \"kind\": \"schedule\", \"schedule\": { \"kind\": \"cron\", \"expr\": \"0 9 * * *\" } }\n- Webhook: { \"kind\": \"webhook\", \"secretId\": \"optional-short-id\" }\n- Product event: { \"kind\": \"event\", \"eventType\": \"goal.status_changed\", \"source\": \"goals\", \"payloadMatch\": { \"status\": \"blocked\" } }\n\nUseful product events:\n- session.message.created\n- session.transcript.updated\n- note.created\n- note.updated\n- goal.created\n- goal.status_changed\n- workflow.run.completed\n- channel.message.received\n\nAllowed actions:\n- Agent: { \"kind\": \"agent\", \"agentId\": \"optional\", \"instruction\": \"what to do\", \"timeoutSeconds\": 300 }\n- Workflow: { \"kind\": \"workflow\", \"workflowId\": \"known_workflow_id\", \"input\": {}, \"goal\": \"optional\", \"timeoutSeconds\": 300 }\n\nSafety modes:\n- { \"mode\": \"suggest_only\" }: safest default, generate recommendations only.\n- { \"mode\": \"ask_before_apply\" }: draft actions and require user confirmation before applying.\n- { \"mode\": \"auto_apply\" }: trusted automation may act automatically.\n\nRules:\n- Prefer agent actions unless the user names a specific existing workflow id.\n- Default to safety { \"mode\": \"suggest_only\" } unless the user explicitly asks for fully automatic execution.\n- Do not invent destructive actions. For deletion, external sending, or irreversible changes, include a risk and make the instruction ask for confirmation.\n- Use cron for daily/weekly schedules. Use standard 5-field cron.\n- Keep timeoutSeconds between 60 and 1800.\n- afterRun should usually be { \"kind\": \"none\" }.\n- Language for user-facing copy: ${params.language ?? 'en'}.\n\nUser request:\n${params.prompt.slice(0, 8000)}\n`;\n}\n\nexport function buildAutomationDraftRepairPrompt(params: {\n prompt: string;\n language?: 'en' | 'zh';\n previousOutput: string;\n issues: AutomationDraftRepairIssue[];\n}): string {\n return `Repair the xopc automation draft. Return ONLY a JSON object with the same shape.\n\nOriginal user request:\n${params.prompt.slice(0, 8000)}\n\nLanguage for user-facing copy: ${params.language ?? 'en'}\n\nPrevious output:\n${params.previousOutput.slice(0, 12000)}\n\nIssues:\n${params.issues.map((issue) => `- ${issue.source}: ${issue.message}`).join('\\n')}\n`;\n}\n\nexport function buildAutomationRunRepairPrompt(params: {\n language?: 'en' | 'zh';\n automation: unknown;\n run: unknown;\n events: unknown[];\n}): string {\n return `You suggest safe repair patches for xopc automations. Return ONLY a JSON object, no markdown.\n\nJSON shape:\n{\n \"patch\": {\n \"description\": \"optional improved description\",\n \"trigger\": \"optional complete trigger object\",\n \"action\": \"optional complete action object\",\n \"safety\": \"optional complete safety object\",\n \"afterRun\": \"optional complete afterRun object\",\n \"reliability\": \"optional complete reliability object\",\n \"enabled\": true\n },\n \"explanation\": \"Why this patch should fix the failed run\",\n \"expectedEffect\": \"What changes after applying it\",\n \"risks\": [\"...\"],\n \"requiresApproval\": true\n}\n\nRules:\n- Return a PATCH only. Do not include id, state, createdAtMs, or updatedAtMs.\n- Keep the patch minimal. Prefer reliability/action/input fixes over broad rewrites.\n- If the failure is unclear, propose only a safer timeout/retry/description patch and explain uncertainty.\n- Never add destructive or external behavior. If the existing automation has risky external behavior, keep requiresApproval true.\n- Language for user-facing copy: ${params.language ?? 'en'}.\n\nCurrent automation:\n${JSON.stringify(params.automation, null, 2).slice(0, 12000)}\n\nFailed run:\n${JSON.stringify(params.run, null, 2).slice(0, 8000)}\n\nTimeline events:\n${JSON.stringify(params.events, null, 2).slice(0, 12000)}\n`;\n}\n\nexport function buildAutomationRunRepairRetryPrompt(params: {\n language?: 'en' | 'zh';\n previousOutput: string;\n issues: AutomationDraftRepairIssue[];\n}): string {\n return `Repair the automation repair patch. Return ONLY a JSON object with the same shape.\n\nLanguage for user-facing copy: ${params.language ?? 'en'}\n\nPrevious output:\n${params.previousOutput.slice(0, 12000)}\n\nIssues:\n${params.issues.map((issue) => `- ${issue.source}: ${issue.message}`).join('\\n')}\n`;\n}\n"],"mappings":";AAMA,SAAgB,2BAA2B,QAGhC;AACT,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mCAmD0B,OAAO,YAAY,KAAK;;;EAGzD,OAAO,OAAO,MAAM,GAAG,IAAK,CAAC;;;AAI/B,SAAgB,iCAAiC,QAKtC;AACT,QAAO;;;EAGP,OAAO,OAAO,MAAM,GAAG,IAAK,CAAC;;iCAEE,OAAO,YAAY,KAAK;;;EAGvD,OAAO,eAAe,MAAM,GAAG,KAAM,CAAC;;;EAGtC,OAAO,OAAO,KAAK,UAAU,KAAK,MAAM,OAAO,IAAI,MAAM,UAAU,CAAC,KAAK,KAAK,CAAC;;;AAIjF,SAAgB,+BAA+B,QAKpC;AACT,QAAO;;;;;;;;;;;;;;;;;;;;;;;;mCAwB0B,OAAO,YAAY,KAAK;;;EAGzD,KAAK,UAAU,OAAO,YAAY,MAAM,EAAE,CAAC,MAAM,GAAG,KAAM,CAAC;;;EAG3D,KAAK,UAAU,OAAO,KAAK,MAAM,EAAE,CAAC,MAAM,GAAG,IAAK,CAAC;;;EAGnD,KAAK,UAAU,OAAO,QAAQ,MAAM,EAAE,CAAC,MAAM,GAAG,KAAM,CAAC;;;AAIzD,SAAgB,oCAAoC,QAIzC;AACT,QAAO;;iCAEwB,OAAO,YAAY,KAAK;;;EAGvD,OAAO,eAAe,MAAM,GAAG,KAAM,CAAC;;;EAGtC,OAAO,OAAO,KAAK,UAAU,KAAK,MAAM,OAAO,IAAI,MAAM,UAAU,CAAC,KAAK,KAAK,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { Config } from '../../config/schema.js';
2
+ import type { AutomationDraftResponse, AutomationRepairDraftResponse, CreateAutomationDraftRequest, CreateAutomationRepairDraftRequest } from './automation-draft.types.js';
3
+ export interface AutomationDraftServiceOptions {
4
+ config: Config;
5
+ maxRepairAttempts?: number;
6
+ }
7
+ export declare class AutomationDraftService {
8
+ private readonly options;
9
+ constructor(options: AutomationDraftServiceOptions);
10
+ createDraft(request: CreateAutomationDraftRequest, signal?: AbortSignal): Promise<AutomationDraftResponse>;
11
+ createRepairDraft(request: CreateAutomationRepairDraftRequest, signal?: AbortSignal): Promise<AutomationRepairDraftResponse>;
12
+ }
@@ -0,0 +1,135 @@
1
+ import { createLogger } from "../../utils/logger/index.js";
2
+ import { init_logger } from "../../utils/logger.js";
3
+ import { init_providers, resolveModel } from "../../providers/index.js";
4
+ import { resolveDraftModelRef } from "../../workflows/draft/workflow-draft-service.js";
5
+ import { buildAutomationDraftPrompt, buildAutomationDraftRepairPrompt, buildAutomationRunRepairPrompt, buildAutomationRunRepairRetryPrompt } from "./automation-draft-prompt.js";
6
+ import { buildAutomationDraftResponse, parseGeneratedAutomationDraft, parseGeneratedAutomationRepairDraft } from "./automation-draft-validator.js";
7
+ import { complete } from "@earendil-works/pi-ai";
8
+ //#region src/automations/draft/automation-draft-service.ts
9
+ init_providers();
10
+ init_logger();
11
+ const log = createLogger("AutomationDraft");
12
+ const DEFAULT_MAX_REPAIR_ATTEMPTS = 2;
13
+ var AutomationDraftService = class {
14
+ constructor(options) {
15
+ this.options = options;
16
+ }
17
+ async createDraft(request, signal) {
18
+ const prompt = request.prompt.trim();
19
+ if (!prompt) throw new Error("prompt is required");
20
+ const modelRef = resolveDraftModelRef(this.options.config, request.agentId);
21
+ const model = resolveModel(modelRef);
22
+ const maxRepairAttempts = this.options.maxRepairAttempts ?? DEFAULT_MAX_REPAIR_ATTEMPTS;
23
+ let messageContent = buildAutomationDraftPrompt({
24
+ prompt,
25
+ language: request.language
26
+ });
27
+ let lastText = "";
28
+ let lastIssues = [];
29
+ for (let attempt = 0; attempt <= maxRepairAttempts; attempt += 1) {
30
+ lastText = extractText(await complete(model, { messages: [{
31
+ role: "user",
32
+ content: messageContent,
33
+ timestamp: Date.now()
34
+ }] }, {
35
+ maxTokens: 2048,
36
+ temperature: attempt === 0 ? .2 : .1,
37
+ signal
38
+ }));
39
+ try {
40
+ return buildAutomationDraftResponse(parseGeneratedAutomationDraft(lastText), attempt);
41
+ } catch (err) {
42
+ lastIssues = [{
43
+ source: "validation",
44
+ severity: "error",
45
+ message: err instanceof Error ? err.message : String(err)
46
+ }];
47
+ }
48
+ if (attempt >= maxRepairAttempts) break;
49
+ log.warn({
50
+ modelRef,
51
+ attempt: attempt + 1,
52
+ issueCount: lastIssues.length,
53
+ preview: lastText.slice(0, 500)
54
+ }, "Automation draft validation failed; asking model to repair");
55
+ messageContent = buildAutomationDraftRepairPrompt({
56
+ prompt,
57
+ language: request.language,
58
+ previousOutput: lastText,
59
+ issues: lastIssues
60
+ });
61
+ }
62
+ const message = `Unable to generate a valid automation draft after ${maxRepairAttempts + 1} attempts`;
63
+ log.warn({
64
+ modelRef,
65
+ issues: lastIssues,
66
+ preview: lastText.slice(0, 500)
67
+ }, message);
68
+ throw new Error(message);
69
+ }
70
+ async createRepairDraft(request, signal) {
71
+ const modelRef = resolveDraftModelRef(this.options.config, request.agentId);
72
+ const model = resolveModel(modelRef);
73
+ const maxRepairAttempts = this.options.maxRepairAttempts ?? DEFAULT_MAX_REPAIR_ATTEMPTS;
74
+ let messageContent = buildAutomationRunRepairPrompt({
75
+ language: request.language,
76
+ automation: request.automation,
77
+ run: request.run,
78
+ events: request.events
79
+ });
80
+ let lastText = "";
81
+ let lastIssues = [];
82
+ for (let attempt = 0; attempt <= maxRepairAttempts; attempt += 1) {
83
+ lastText = extractText(await complete(model, { messages: [{
84
+ role: "user",
85
+ content: messageContent,
86
+ timestamp: Date.now()
87
+ }] }, {
88
+ maxTokens: 2048,
89
+ temperature: attempt === 0 ? .15 : .05,
90
+ signal
91
+ }));
92
+ try {
93
+ return parseGeneratedAutomationRepairDraft(lastText, attempt);
94
+ } catch (err) {
95
+ lastIssues = [{
96
+ source: "validation",
97
+ severity: "error",
98
+ message: err instanceof Error ? err.message : String(err)
99
+ }];
100
+ }
101
+ if (attempt >= maxRepairAttempts) break;
102
+ log.warn({
103
+ modelRef,
104
+ attempt: attempt + 1,
105
+ issueCount: lastIssues.length,
106
+ preview: lastText.slice(0, 500)
107
+ }, "Automation repair draft validation failed; asking model to repair");
108
+ messageContent = buildAutomationRunRepairRetryPrompt({
109
+ language: request.language,
110
+ previousOutput: lastText,
111
+ issues: lastIssues
112
+ });
113
+ }
114
+ const message = `Unable to generate a valid automation repair draft after ${maxRepairAttempts + 1} attempts`;
115
+ log.warn({
116
+ modelRef,
117
+ issues: lastIssues,
118
+ preview: lastText.slice(0, 500)
119
+ }, message);
120
+ throw new Error(message);
121
+ }
122
+ };
123
+ function extractText(result) {
124
+ const content = result.content;
125
+ if (typeof content === "string") return content;
126
+ if (Array.isArray(content)) return content.map((item) => {
127
+ if (item && typeof item === "object" && item.type === "text") return String(item.text ?? "");
128
+ return "";
129
+ }).join("");
130
+ return "";
131
+ }
132
+ //#endregion
133
+ export { AutomationDraftService };
134
+
135
+ //# sourceMappingURL=automation-draft-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"automation-draft-service.js","names":[],"sources":["../../../../src/automations/draft/automation-draft-service.ts"],"sourcesContent":["import { complete, type UserMessage } from '@earendil-works/pi-ai';\n\nimport type { Config } from '../../config/schema.js';\nimport { resolveModel } from '../../providers/index.js';\nimport { createLogger } from '../../utils/logger.js';\nimport { resolveDraftModelRef } from '../../workflows/draft/workflow-draft-service.js';\nimport {\n buildAutomationDraftPrompt,\n buildAutomationDraftRepairPrompt,\n buildAutomationRunRepairPrompt,\n buildAutomationRunRepairRetryPrompt,\n type AutomationDraftRepairIssue,\n} from './automation-draft-prompt.js';\nimport type {\n AutomationDraftResponse,\n AutomationRepairDraftResponse,\n CreateAutomationDraftRequest,\n CreateAutomationRepairDraftRequest,\n} from './automation-draft.types.js';\nimport {\n buildAutomationDraftResponse,\n parseGeneratedAutomationDraft,\n parseGeneratedAutomationRepairDraft,\n} from './automation-draft-validator.js';\n\nconst log = createLogger('AutomationDraft');\nconst DEFAULT_MAX_REPAIR_ATTEMPTS = 2;\n\nexport interface AutomationDraftServiceOptions {\n config: Config;\n maxRepairAttempts?: number;\n}\n\nexport class AutomationDraftService {\n constructor(private readonly options: AutomationDraftServiceOptions) {}\n\n async createDraft(request: CreateAutomationDraftRequest, signal?: AbortSignal): Promise<AutomationDraftResponse> {\n const prompt = request.prompt.trim();\n if (!prompt) throw new Error('prompt is required');\n\n const modelRef = resolveDraftModelRef(this.options.config, request.agentId);\n const model = resolveModel(modelRef);\n const maxRepairAttempts = this.options.maxRepairAttempts ?? DEFAULT_MAX_REPAIR_ATTEMPTS;\n let messageContent = buildAutomationDraftPrompt({ prompt, language: request.language });\n let lastText = '';\n let lastIssues: AutomationDraftRepairIssue[] = [];\n\n for (let attempt = 0; attempt <= maxRepairAttempts; attempt += 1) {\n const userMsg: UserMessage = {\n role: 'user',\n content: messageContent,\n timestamp: Date.now(),\n };\n const result = await complete(\n model,\n { messages: [userMsg] },\n { maxTokens: 2048, temperature: attempt === 0 ? 0.2 : 0.1, signal },\n );\n lastText = extractText(result);\n try {\n const draft = parseGeneratedAutomationDraft(lastText);\n return buildAutomationDraftResponse(draft, attempt);\n } catch (err) {\n lastIssues = [{\n source: 'validation',\n severity: 'error',\n message: err instanceof Error ? err.message : String(err),\n }];\n }\n\n if (attempt >= maxRepairAttempts) break;\n log.warn(\n { modelRef, attempt: attempt + 1, issueCount: lastIssues.length, preview: lastText.slice(0, 500) },\n 'Automation draft validation failed; asking model to repair',\n );\n messageContent = buildAutomationDraftRepairPrompt({\n prompt,\n language: request.language,\n previousOutput: lastText,\n issues: lastIssues,\n });\n }\n\n const message = `Unable to generate a valid automation draft after ${maxRepairAttempts + 1} attempts`;\n log.warn({ modelRef, issues: lastIssues, preview: lastText.slice(0, 500) }, message);\n throw new Error(message);\n }\n\n async createRepairDraft(\n request: CreateAutomationRepairDraftRequest,\n signal?: AbortSignal,\n ): Promise<AutomationRepairDraftResponse> {\n const modelRef = resolveDraftModelRef(this.options.config, request.agentId);\n const model = resolveModel(modelRef);\n const maxRepairAttempts = this.options.maxRepairAttempts ?? DEFAULT_MAX_REPAIR_ATTEMPTS;\n let messageContent = buildAutomationRunRepairPrompt({\n language: request.language,\n automation: request.automation,\n run: request.run,\n events: request.events,\n });\n let lastText = '';\n let lastIssues: AutomationDraftRepairIssue[] = [];\n\n for (let attempt = 0; attempt <= maxRepairAttempts; attempt += 1) {\n const userMsg: UserMessage = {\n role: 'user',\n content: messageContent,\n timestamp: Date.now(),\n };\n const result = await complete(\n model,\n { messages: [userMsg] },\n { maxTokens: 2048, temperature: attempt === 0 ? 0.15 : 0.05, signal },\n );\n lastText = extractText(result);\n try {\n return parseGeneratedAutomationRepairDraft(lastText, attempt);\n } catch (err) {\n lastIssues = [{\n source: 'validation',\n severity: 'error',\n message: err instanceof Error ? err.message : String(err),\n }];\n }\n\n if (attempt >= maxRepairAttempts) break;\n log.warn(\n { modelRef, attempt: attempt + 1, issueCount: lastIssues.length, preview: lastText.slice(0, 500) },\n 'Automation repair draft validation failed; asking model to repair',\n );\n messageContent = buildAutomationRunRepairRetryPrompt({\n language: request.language,\n previousOutput: lastText,\n issues: lastIssues,\n });\n }\n\n const message = `Unable to generate a valid automation repair draft after ${maxRepairAttempts + 1} attempts`;\n log.warn({ modelRef, issues: lastIssues, preview: lastText.slice(0, 500) }, message);\n throw new Error(message);\n }\n}\n\nfunction extractText(result: unknown): string {\n const content = (result as { content?: unknown }).content;\n if (typeof content === 'string') return content;\n if (Array.isArray(content)) {\n return content.map((item) => {\n if (item && typeof item === 'object' && (item as { type?: string }).type === 'text') {\n return String((item as { text?: string }).text ?? '');\n }\n return '';\n }).join('');\n }\n return '';\n}\n"],"mappings":"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"}
@@ -0,0 +1,99 @@
1
+ import type { CreateAutomationInput } from '../domain/validation.js';
2
+ import type { AutomationRepairDraftResponse, AutomationSimulation } from './automation-draft.types.js';
3
+ interface GeneratedAutomationDraft {
4
+ automation: CreateAutomationInput;
5
+ explanation: string;
6
+ assumptions: string[];
7
+ risks: string[];
8
+ }
9
+ export declare function parseGeneratedAutomationDraft(raw: string): GeneratedAutomationDraft;
10
+ export declare function buildAutomationDraftResponse(draft: GeneratedAutomationDraft, repairAttempts: number): {
11
+ draftId: `${string}-${string}-${string}-${string}-${string}`;
12
+ automation: {
13
+ name: string;
14
+ description?: string;
15
+ trigger?: {
16
+ kind: "manual";
17
+ } | {
18
+ kind: "schedule";
19
+ schedule?: {
20
+ kind: "once";
21
+ at: string;
22
+ } | {
23
+ kind: "interval";
24
+ everyMs: number;
25
+ anchorMs?: number;
26
+ } | {
27
+ kind: "cron";
28
+ expr: string;
29
+ tz?: string;
30
+ };
31
+ } | {
32
+ kind: "webhook";
33
+ secretId?: string;
34
+ } | {
35
+ kind: "event";
36
+ eventType: string;
37
+ source?: string;
38
+ payloadMatch?: Record<string, string | number | boolean>;
39
+ };
40
+ action?: {
41
+ kind: "agent";
42
+ instruction: string;
43
+ agentId?: string;
44
+ workingDirectory?: string;
45
+ model?: string;
46
+ timeoutSeconds?: number;
47
+ } | {
48
+ kind: "workflow";
49
+ workflowId: string;
50
+ agentId?: string;
51
+ input?: unknown;
52
+ inputEnvelope?: {
53
+ payload: unknown;
54
+ goal?: string;
55
+ variables?: Record<string, unknown>;
56
+ context?: Record<string, unknown>;
57
+ };
58
+ goal?: string;
59
+ concurrency?: number;
60
+ maxSubagents?: number;
61
+ timeoutSeconds?: number;
62
+ };
63
+ safety?: {
64
+ mode: "suggest_only" | "ask_before_apply" | "auto_apply";
65
+ };
66
+ afterRun?: {
67
+ kind: "none";
68
+ } | {
69
+ kind: "saveToSession";
70
+ } | {
71
+ kind: "webhook";
72
+ url: string;
73
+ };
74
+ reliability?: {
75
+ timeoutSeconds?: number;
76
+ retryCount?: number;
77
+ maxConcurrentRuns?: number;
78
+ disableAfterConsecutiveFailures?: number;
79
+ };
80
+ id?: string;
81
+ enabled?: boolean;
82
+ state?: {
83
+ nextRunAtMs?: number;
84
+ runningRunId?: string;
85
+ lastRunAtMs?: number;
86
+ lastRunStatus?: "timeout" | "failed" | "queued" | "running" | "succeeded" | "cancelled";
87
+ lastError?: string;
88
+ consecutiveFailures?: number;
89
+ };
90
+ };
91
+ explanation: string;
92
+ assumptions: string[];
93
+ risks: string[];
94
+ simulation: AutomationSimulation;
95
+ repairAttempts: number;
96
+ };
97
+ export declare function parseGeneratedAutomationRepairDraft(raw: string, repairAttempts: number): AutomationRepairDraftResponse;
98
+ export declare function simulateAutomation(input: CreateAutomationInput): AutomationSimulation;
99
+ export {};
@@ -0,0 +1,105 @@
1
+ import { CreateAutomationSchema, UpdateAutomationSchema } from "../domain/validation.js";
2
+ import { randomUUID } from "node:crypto";
3
+ //#region src/automations/draft/automation-draft-validator.ts
4
+ function extractJsonObject(raw) {
5
+ const trimmed = raw.trim();
6
+ if (trimmed.startsWith("{") && trimmed.endsWith("}")) return trimmed;
7
+ const start = trimmed.indexOf("{");
8
+ const end = trimmed.lastIndexOf("}");
9
+ if (start >= 0 && end > start) return trimmed.slice(start, end + 1);
10
+ throw new Error("Model output did not contain a JSON object");
11
+ }
12
+ function stringArray(value) {
13
+ return Array.isArray(value) ? value.map((item) => String(item)).filter(Boolean) : [];
14
+ }
15
+ function parseGeneratedAutomationDraft(raw) {
16
+ const json = extractJsonObject(raw);
17
+ const parsed = JSON.parse(json);
18
+ return {
19
+ automation: CreateAutomationSchema.parse(parsed.automation),
20
+ explanation: String(parsed.explanation ?? ""),
21
+ assumptions: stringArray(parsed.assumptions),
22
+ risks: stringArray(parsed.risks)
23
+ };
24
+ }
25
+ function buildAutomationDraftResponse(draft, repairAttempts) {
26
+ return {
27
+ draftId: randomUUID(),
28
+ automation: draft.automation,
29
+ explanation: draft.explanation,
30
+ assumptions: draft.assumptions,
31
+ risks: draft.risks,
32
+ simulation: simulateAutomation(draft.automation),
33
+ repairAttempts
34
+ };
35
+ }
36
+ function parseGeneratedAutomationRepairDraft(raw, repairAttempts) {
37
+ const json = extractJsonObject(raw);
38
+ const parsed = JSON.parse(json);
39
+ const patch = UpdateAutomationSchema.parse(parsed.patch);
40
+ return {
41
+ draftId: randomUUID(),
42
+ patch,
43
+ explanation: String(parsed.explanation ?? ""),
44
+ expectedEffect: String(parsed.expectedEffect ?? ""),
45
+ risks: stringArray(parsed.risks),
46
+ requiresApproval: parsed.requiresApproval !== false || repairPatchNeedsApproval(patch),
47
+ repairAttempts
48
+ };
49
+ }
50
+ function simulateAutomation(input) {
51
+ const automation = CreateAutomationSchema.parse(input);
52
+ const safetyNotes = [];
53
+ const requiredConfirmations = [];
54
+ const triggerSummary = summarizeTrigger(automation.trigger);
55
+ const actionSummary = summarizeAction(automation.action);
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.afterRun?.kind === "webhook") {
58
+ safetyNotes.push("After-run webhook will call an external URL after each run.");
59
+ requiredConfirmations.push("External webhook call should be reviewed before publishing.");
60
+ }
61
+ const safetyMode = automation.safety?.mode ?? "auto_apply";
62
+ if (safetyMode === "suggest_only") safetyNotes.push("Suggest-only safety mode will generate recommendations without applying changes.");
63
+ else if (safetyMode === "ask_before_apply") safetyNotes.push("Ask-before-applying safety mode requires confirmation before applying changes.");
64
+ else {
65
+ safetyNotes.push("Auto-apply safety mode may act automatically when the trigger matches.");
66
+ requiredConfirmations.push("Auto-apply mode should only be used for trusted automations.");
67
+ }
68
+ if (automation.trigger.kind === "webhook") safetyNotes.push("Webhook trigger can be invoked externally; keep its secret id private.");
69
+ if (automation.trigger.kind === "event") safetyNotes.push("Product-event trigger runs automatically when matching xopc events are published.");
70
+ return {
71
+ triggerSummary,
72
+ actionSummary,
73
+ safetyNotes,
74
+ requiredConfirmations,
75
+ canRunNow: automation.trigger.kind === "manual",
76
+ runNowBlockedReason: automation.trigger.kind === "manual" ? void 0 : "Only manual automations can be run immediately from the draft."
77
+ };
78
+ }
79
+ function summarizeTrigger(trigger) {
80
+ if (trigger.kind === "manual") return "Runs only when started manually.";
81
+ if (trigger.kind === "webhook") return "Runs when the automation webhook is called.";
82
+ if (trigger.kind === "event") {
83
+ const source = trigger.source ? ` from ${trigger.source}` : "";
84
+ return `Runs on product event ${trigger.eventType}${source}.`;
85
+ }
86
+ const schedule = trigger.schedule;
87
+ if (schedule.kind === "interval") return `Runs every ${Math.round(schedule.everyMs / 6e4)} minutes.`;
88
+ if (schedule.kind === "once") return `Runs once at ${schedule.at}.`;
89
+ return `Runs on cron schedule ${schedule.expr}.`;
90
+ }
91
+ function summarizeAction(action) {
92
+ if (action.kind === "workflow") return `Starts workflow ${action.workflowId}.`;
93
+ return action.agentId ? `Runs agent ${action.agentId}.` : "Runs the default agent.";
94
+ }
95
+ function repairPatchNeedsApproval(patch) {
96
+ if (patch.safety?.mode === "auto_apply") return true;
97
+ if (patch.afterRun?.kind === "webhook") return true;
98
+ if (patch.trigger?.kind === "webhook") return true;
99
+ if (patch.action?.kind === "agent") return /delete|remove|send|post|publish|付款|删除|发送|发布/i.test(patch.action.instruction);
100
+ return false;
101
+ }
102
+ //#endregion
103
+ export { buildAutomationDraftResponse, parseGeneratedAutomationDraft, parseGeneratedAutomationRepairDraft, simulateAutomation };
104
+
105
+ //# sourceMappingURL=automation-draft-validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"automation-draft-validator.js","names":[],"sources":["../../../../src/automations/draft/automation-draft-validator.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\nimport type { CreateAutomationInput, UpdateAutomationInput } from '../domain/validation.js';\nimport { CreateAutomationSchema, UpdateAutomationSchema } from '../domain/validation.js';\nimport type { AutomationRepairDraftResponse, AutomationSimulation } from './automation-draft.types.js';\n\ninterface GeneratedAutomationDraft {\n automation: CreateAutomationInput;\n explanation: string;\n assumptions: string[];\n risks: string[];\n}\n\nfunction extractJsonObject(raw: string): string {\n const trimmed = raw.trim();\n if (trimmed.startsWith('{') && trimmed.endsWith('}')) return trimmed;\n const start = trimmed.indexOf('{');\n const end = trimmed.lastIndexOf('}');\n if (start >= 0 && end > start) return trimmed.slice(start, end + 1);\n throw new Error('Model output did not contain a JSON object');\n}\n\nfunction stringArray(value: unknown): string[] {\n return Array.isArray(value) ? value.map((item) => String(item)).filter(Boolean) : [];\n}\n\nexport function parseGeneratedAutomationDraft(raw: string): GeneratedAutomationDraft {\n const json = extractJsonObject(raw);\n const parsed = JSON.parse(json) as { automation?: unknown; explanation?: unknown; assumptions?: unknown; risks?: unknown };\n const automation = CreateAutomationSchema.parse(parsed.automation) as CreateAutomationInput;\n return {\n automation,\n explanation: String(parsed.explanation ?? ''),\n assumptions: stringArray(parsed.assumptions),\n risks: stringArray(parsed.risks),\n };\n}\n\nexport function buildAutomationDraftResponse(\n draft: GeneratedAutomationDraft,\n repairAttempts: number,\n) {\n return {\n draftId: randomUUID(),\n automation: draft.automation,\n explanation: draft.explanation,\n assumptions: draft.assumptions,\n risks: draft.risks,\n simulation: simulateAutomation(draft.automation),\n repairAttempts,\n };\n}\n\nexport function parseGeneratedAutomationRepairDraft(\n raw: string,\n repairAttempts: number,\n): AutomationRepairDraftResponse {\n const json = extractJsonObject(raw);\n const parsed = JSON.parse(json) as {\n patch?: unknown;\n explanation?: unknown;\n expectedEffect?: unknown;\n risks?: unknown;\n requiresApproval?: unknown;\n };\n const patch = UpdateAutomationSchema.parse(parsed.patch) as UpdateAutomationInput;\n return {\n draftId: randomUUID(),\n patch,\n explanation: String(parsed.explanation ?? ''),\n expectedEffect: String(parsed.expectedEffect ?? ''),\n risks: stringArray(parsed.risks),\n requiresApproval: parsed.requiresApproval !== false || repairPatchNeedsApproval(patch),\n repairAttempts,\n };\n}\n\nexport function simulateAutomation(input: CreateAutomationInput): AutomationSimulation {\n const automation = CreateAutomationSchema.parse(input) as CreateAutomationInput;\n const safetyNotes: string[] = [];\n const requiredConfirmations: string[] = [];\n\n const triggerSummary = summarizeTrigger(automation.trigger);\n const actionSummary = summarizeAction(automation.action);\n\n if (automation.action.kind === 'agent' && /delete|remove|send|post|publish|付款|删除|发送|发布/i.test(automation.action.instruction)) {\n requiredConfirmations.push('Agent instruction may perform an external or destructive action.');\n }\n if (automation.afterRun?.kind === 'webhook') {\n safetyNotes.push('After-run webhook will call an external URL after each run.');\n requiredConfirmations.push('External webhook call should be reviewed before publishing.');\n }\n const safetyMode = automation.safety?.mode ?? 'auto_apply';\n if (safetyMode === 'suggest_only') {\n safetyNotes.push('Suggest-only safety mode will generate recommendations without applying changes.');\n } else if (safetyMode === 'ask_before_apply') {\n safetyNotes.push('Ask-before-applying safety mode requires confirmation before applying changes.');\n } else {\n safetyNotes.push('Auto-apply safety mode may act automatically when the trigger matches.');\n requiredConfirmations.push('Auto-apply mode should only be used for trusted automations.');\n }\n if (automation.trigger.kind === 'webhook') {\n safetyNotes.push('Webhook trigger can be invoked externally; keep its secret id private.');\n }\n if (automation.trigger.kind === 'event') {\n safetyNotes.push('Product-event trigger runs automatically when matching xopc events are published.');\n }\n\n return {\n triggerSummary,\n actionSummary,\n safetyNotes,\n requiredConfirmations,\n canRunNow: automation.trigger.kind === 'manual',\n runNowBlockedReason: automation.trigger.kind === 'manual' ? undefined : 'Only manual automations can be run immediately from the draft.',\n };\n}\n\nfunction summarizeTrigger(trigger: CreateAutomationInput['trigger']): string {\n if (trigger.kind === 'manual') return 'Runs only when started manually.';\n if (trigger.kind === 'webhook') return 'Runs when the automation webhook is called.';\n if (trigger.kind === 'event') {\n const source = trigger.source ? ` from ${trigger.source}` : '';\n return `Runs on product event ${trigger.eventType}${source}.`;\n }\n const schedule = trigger.schedule;\n if (schedule.kind === 'interval') return `Runs every ${Math.round(schedule.everyMs / 60000)} minutes.`;\n if (schedule.kind === 'once') return `Runs once at ${schedule.at}.`;\n return `Runs on cron schedule ${schedule.expr}.`;\n}\n\nfunction summarizeAction(action: CreateAutomationInput['action']): string {\n if (action.kind === 'workflow') return `Starts workflow ${action.workflowId}.`;\n return action.agentId ? `Runs agent ${action.agentId}.` : 'Runs the default agent.';\n}\n\nfunction repairPatchNeedsApproval(patch: UpdateAutomationInput): boolean {\n if (patch.safety?.mode === 'auto_apply') return true;\n if (patch.afterRun?.kind === 'webhook') return true;\n if (patch.trigger?.kind === 'webhook') return true;\n if (patch.action?.kind === 'agent') {\n return /delete|remove|send|post|publish|付款|删除|发送|发布/i.test(patch.action.instruction);\n }\n return false;\n}\n"],"mappings":"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"}
@@ -0,0 +1,40 @@
1
+ import type { AutomationRun, AutomationRunEvent } from '../domain/types.js';
2
+ import type { CreateAutomationInput, UpdateAutomationInput } from '../domain/validation.js';
3
+ export interface CreateAutomationDraftRequest {
4
+ prompt: string;
5
+ agentId: string;
6
+ language?: 'en' | 'zh';
7
+ }
8
+ export interface AutomationDraftResponse {
9
+ draftId: string;
10
+ automation: CreateAutomationInput;
11
+ explanation: string;
12
+ assumptions: string[];
13
+ risks: string[];
14
+ simulation: AutomationSimulation;
15
+ repairAttempts: number;
16
+ }
17
+ export interface AutomationSimulation {
18
+ triggerSummary: string;
19
+ actionSummary: string;
20
+ safetyNotes: string[];
21
+ requiredConfirmations: string[];
22
+ canRunNow: boolean;
23
+ runNowBlockedReason?: string;
24
+ }
25
+ export interface CreateAutomationRepairDraftRequest {
26
+ agentId: string;
27
+ automation: CreateAutomationInput;
28
+ run: AutomationRun;
29
+ events: AutomationRunEvent[];
30
+ language?: 'en' | 'zh';
31
+ }
32
+ export interface AutomationRepairDraftResponse {
33
+ draftId: string;
34
+ patch: UpdateAutomationInput;
35
+ explanation: string;
36
+ expectedEffect: string;
37
+ risks: string[];
38
+ requiresApproval: boolean;
39
+ repairAttempts: number;
40
+ }
@@ -0,0 +1,3 @@
1
+ export * from './automation-draft-service.js';
2
+ export * from './automation-draft.types.js';
3
+ export * from './automation-draft-validator.js';
@@ -0,0 +1,3 @@
1
+ import { buildAutomationDraftResponse, parseGeneratedAutomationDraft, parseGeneratedAutomationRepairDraft, simulateAutomation } from "./automation-draft-validator.js";
2
+ import { AutomationDraftService } from "./automation-draft-service.js";
3
+ export { AutomationDraftService, buildAutomationDraftResponse, parseGeneratedAutomationDraft, parseGeneratedAutomationRepairDraft, simulateAutomation };
@@ -0,0 +1,3 @@
1
+ export * from './domain/index.js';
2
+ export * from './service/index.js';
3
+ export * from './product-events.js';
@@ -0,0 +1,8 @@
1
+ import { onAutomationProductEvent, publishAutomationProductEvent } from "./product-events.js";
2
+ import { computeNextAutomationRunAtMs, computeNextScheduleRunAtMs, timerDelayUntil } from "./domain/schedule.js";
3
+ import { AutomationActionSchema, AutomationAfterRunSchema, AutomationReliabilitySchema, AutomationSafetyPolicySchema, AutomationScheduleSchema, AutomationSchema, AutomationStateSchema, AutomationTriggerSchema, CreateAutomationSchema, UpdateAutomationSchema } from "./domain/validation.js";
4
+ import "./domain/index.js";
5
+ import { AutomationActionExecutor } from "./service/action-executor.js";
6
+ import { AutomationAlreadyRunningError, AutomationService } from "./service/automation-service.js";
7
+ import "./service/index.js";
8
+ export { AutomationActionExecutor, AutomationActionSchema, AutomationAfterRunSchema, AutomationAlreadyRunningError, AutomationReliabilitySchema, AutomationSafetyPolicySchema, AutomationScheduleSchema, AutomationSchema, AutomationService, AutomationStateSchema, AutomationTriggerSchema, CreateAutomationSchema, UpdateAutomationSchema, computeNextAutomationRunAtMs, computeNextScheduleRunAtMs, onAutomationProductEvent, publishAutomationProductEvent, timerDelayUntil };
@@ -0,0 +1,5 @@
1
+ import type { AutomationEvent } from './domain/types.js';
2
+ type AutomationProductEventListener = (event: AutomationEvent) => void | Promise<void>;
3
+ export declare function onAutomationProductEvent(listener: AutomationProductEventListener): () => void;
4
+ export declare function publishAutomationProductEvent(event: AutomationEvent): void;
5
+ export {};
@@ -0,0 +1,21 @@
1
+ //#region src/automations/product-events.ts
2
+ const AUTOMATION_PRODUCT_EVENT_LISTENERS = /* @__PURE__ */ new Set();
3
+ function onAutomationProductEvent(listener) {
4
+ AUTOMATION_PRODUCT_EVENT_LISTENERS.add(listener);
5
+ return () => {
6
+ AUTOMATION_PRODUCT_EVENT_LISTENERS.delete(listener);
7
+ };
8
+ }
9
+ function publishAutomationProductEvent(event) {
10
+ const normalized = {
11
+ ...event,
12
+ occurredAtMs: event.occurredAtMs ?? Date.now()
13
+ };
14
+ for (const listener of AUTOMATION_PRODUCT_EVENT_LISTENERS) try {
15
+ listener(normalized);
16
+ } catch {}
17
+ }
18
+ //#endregion
19
+ export { onAutomationProductEvent, publishAutomationProductEvent };
20
+
21
+ //# sourceMappingURL=product-events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"product-events.js","names":[],"sources":["../../../src/automations/product-events.ts"],"sourcesContent":["import type { AutomationEvent } from './domain/types.js';\n\ntype AutomationProductEventListener = (event: AutomationEvent) => void | Promise<void>;\n\nconst AUTOMATION_PRODUCT_EVENT_LISTENERS = new Set<AutomationProductEventListener>();\n\nexport function onAutomationProductEvent(listener: AutomationProductEventListener): () => void {\n AUTOMATION_PRODUCT_EVENT_LISTENERS.add(listener);\n return () => {\n AUTOMATION_PRODUCT_EVENT_LISTENERS.delete(listener);\n };\n}\n\nexport function publishAutomationProductEvent(event: AutomationEvent): void {\n const normalized: AutomationEvent = {\n ...event,\n occurredAtMs: event.occurredAtMs ?? Date.now(),\n };\n for (const listener of AUTOMATION_PRODUCT_EVENT_LISTENERS) {\n try {\n void listener(normalized);\n } catch {\n /* listeners isolate publisher paths */\n }\n }\n}\n"],"mappings":";AAIA,MAAM,qDAAqC,IAAI,KAAqC;AAEpF,SAAgB,yBAAyB,UAAsD;AAC7F,oCAAmC,IAAI,SAAS;AAChD,cAAa;AACX,qCAAmC,OAAO,SAAS;;;AAIvD,SAAgB,8BAA8B,OAA8B;CAC1E,MAAM,aAA8B;EAClC,GAAG;EACH,cAAc,MAAM,gBAAgB,KAAK,KAAK;EAC/C;AACD,MAAK,MAAM,YAAY,mCACrB,KAAI;AACG,WAAS,WAAW;SACnB"}
@@ -0,0 +1,9 @@
1
+ import type { Automation, AutomationActionOutcome, AutomationDeps, AutomationRun } from '../domain/types.js';
2
+ export declare class AutomationActionExecutor {
3
+ private deps;
4
+ setDeps(deps: AutomationDeps): void;
5
+ execute(automation: Automation, run: AutomationRun, signal: AbortSignal): Promise<AutomationActionOutcome>;
6
+ private executeWithoutTimeout;
7
+ private executeAgent;
8
+ private executeWorkflow;
9
+ }