@xopcai/xopc 0.0.118 → 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 (468) hide show
  1. package/README.md +2 -1
  2. package/README.zh-CN.md +2 -1
  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-dzUrQoeZ.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--wMEL00f.js → apps-page-DU0dz9Zo.js} +1 -1
  10. package/dist/gateway/static/root/assets/{archive-plugin-Cki4SfU2.js → archive-plugin-BkVIgZzA.js} +1 -1
  11. package/dist/gateway/static/root/assets/{attachment-load-D-KnS2Do.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-D2sgvJja.js → binary-plugins-B4TO_bsn.js} +1 -1
  15. package/dist/gateway/static/root/assets/{block-editor-DIq-4Gvb.js → block-editor-DJRWwWNI.js} +28 -28
  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-DYu1KaFQ.js → extension-debug-page-DYh402XV.js} +1 -1
  26. package/dist/gateway/static/root/assets/{extension-page-B3W6QwlZ.js → extension-page-Cr_TizrN.js} +1 -1
  27. package/dist/gateway/static/root/assets/{extension-settings-page-D7VQ-cxE.js → extension-settings-page-BU1KoKRj.js} +1 -1
  28. package/dist/gateway/static/root/assets/{fetch-B7xDPu-R.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-BTBLSeUu.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-CYj9FWCp.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-CQQgzPr3.js → goals-config-api-DqxVi0p5.js} +1 -1
  35. package/dist/gateway/static/root/assets/{goals-page-BHitvJAv.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-C2Uqvae9.js → logs-page-DLXPcksQ.js} +2 -2
  42. package/dist/gateway/static/root/assets/{markdown-split-BwOFrJ2E.js → markdown-split-CpHxbtWJ.js} +1 -1
  43. package/dist/gateway/static/root/assets/{media-plugins-Cnz6Q5G6.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-B-Svpmza.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-Bss4TiwP.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-BRNjdgKq.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-Dub9sy8r.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-BeFLavGi.js → settings-collapsible-section-BouO6JTi.js} +1 -1
  57. package/dist/gateway/static/root/assets/{settings-form-section-dmyaPOTG.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-C8glrdqe.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-DqlWTsDb.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-C73IVZeC.js → voice-api-key-field-CeEevm7z.js} +1 -1
  71. package/dist/gateway/static/root/assets/{voice-player-store-C_ArLJPM.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 +4 -8
  78. package/dist/src/agent/agent-manager.js.map +1 -1
  79. package/dist/src/agent/embedded/run-for-session.js +102 -14
  80. package/dist/src/agent/embedded/run-for-session.js.map +1 -1
  81. package/dist/src/agent/fallback/candidates.d.ts +0 -8
  82. package/dist/src/agent/fallback/candidates.js.map +1 -1
  83. package/dist/src/agent/index.js +1 -1
  84. package/dist/src/agent/lifecycle/handlers/compaction.d.ts +1 -3
  85. package/dist/src/agent/lifecycle/handlers/compaction.js +1 -16
  86. package/dist/src/agent/lifecycle/handlers/compaction.js.map +1 -1
  87. package/dist/src/agent/lifecycle/progress.d.ts +0 -1
  88. package/dist/src/agent/lifecycle/progress.js +1 -6
  89. package/dist/src/agent/lifecycle/progress.js.map +1 -1
  90. package/dist/src/agent/lifecycle/timeout-wrapper.d.ts +1 -2
  91. package/dist/src/agent/lifecycle/timeout-wrapper.js +1 -7
  92. package/dist/src/agent/lifecycle/timeout-wrapper.js.map +1 -1
  93. package/dist/src/agent/middleware/self-verify.d.ts +0 -1
  94. package/dist/src/agent/middleware/self-verify.js +0 -2
  95. package/dist/src/agent/middleware/self-verify.js.map +1 -1
  96. package/dist/src/agent/models/index.d.ts +1 -1
  97. package/dist/src/agent/models/manager.d.ts +4 -20
  98. package/dist/src/agent/models/manager.js +9 -126
  99. package/dist/src/agent/models/manager.js.map +1 -1
  100. package/dist/src/agent/orchestration/agent-orchestrator.d.ts +0 -4
  101. package/dist/src/agent/orchestration/agent-orchestrator.js +1 -9
  102. package/dist/src/agent/orchestration/agent-orchestrator.js.map +1 -1
  103. package/dist/src/agent/prompt/sections/tooling.js +2 -2
  104. package/dist/src/agent/prompt/sections/tooling.js.map +1 -1
  105. package/dist/src/agent/prompt/service-prompt-builder.d.ts +0 -1
  106. package/dist/src/agent/prompt/service-prompt-builder.js +0 -12
  107. package/dist/src/agent/prompt/service-prompt-builder.js.map +1 -1
  108. package/dist/src/agent/prompt/subagent-context.js +1 -1
  109. package/dist/src/agent/prompt/subagent-context.js.map +1 -1
  110. package/dist/src/agent/prompt/types.d.ts +1 -1
  111. package/dist/src/agent/service.d.ts +1 -9
  112. package/dist/src/agent/service.js +3 -40
  113. package/dist/src/agent/service.js.map +1 -1
  114. package/dist/src/agent/service.types.d.ts +2 -2
  115. package/dist/src/agent/session/session-config-service.d.ts +11 -11
  116. package/dist/src/agent/session/session-config-service.js +14 -14
  117. package/dist/src/agent/session/session-config-service.js.map +1 -1
  118. package/dist/src/agent/session/session-inspector.js +3 -2
  119. package/dist/src/agent/session/session-inspector.js.map +1 -1
  120. package/dist/src/agent/starter-agents.js +12 -12
  121. package/dist/src/agent/starter-agents.js.map +1 -1
  122. package/dist/src/agent/tools/automation-tool.d.ts +14 -0
  123. package/dist/src/agent/tools/automation-tool.js +102 -0
  124. package/dist/src/agent/tools/automation-tool.js.map +1 -0
  125. package/dist/src/agent/tools/delegate-tool.js +1 -1
  126. package/dist/src/agent/tools/delegate-tool.js.map +1 -1
  127. package/dist/src/agent/tools/factory.d.ts +3 -3
  128. package/dist/src/agent/tools/factory.js +2 -2
  129. package/dist/src/agent/tools/factory.js.map +1 -1
  130. package/dist/src/agent/tools/index.d.ts +1 -1
  131. package/dist/src/agent/tools/index.js +2 -2
  132. package/dist/src/agent-manifest/resolver.d.ts +1 -0
  133. package/dist/src/agent-manifest/resolver.js +1 -0
  134. package/dist/src/agent-manifest/resolver.js.map +1 -1
  135. package/dist/src/agent-manifest/schema.d.ts +6 -0
  136. package/dist/src/agent-manifest/schema.js +12 -3
  137. package/dist/src/agent-manifest/schema.js.map +1 -1
  138. package/dist/src/ai-assist/text-assist.d.ts +1 -1
  139. package/dist/src/ai-assist/text-assist.js +56 -0
  140. package/dist/src/ai-assist/text-assist.js.map +1 -1
  141. package/dist/src/auth/profiles/store.js.map +1 -1
  142. package/dist/src/automations/api/routes.d.ts +3 -0
  143. package/dist/src/automations/api/routes.js +193 -0
  144. package/dist/src/automations/api/routes.js.map +1 -0
  145. package/dist/src/automations/domain/index.d.ts +3 -0
  146. package/dist/src/automations/domain/index.js +3 -0
  147. package/dist/src/automations/domain/schedule.d.ts +4 -0
  148. package/dist/src/automations/domain/schedule.js +37 -0
  149. package/dist/src/automations/domain/schedule.js.map +1 -0
  150. package/dist/src/automations/domain/types.d.ts +160 -0
  151. package/dist/src/automations/domain/validation.d.ts +370 -0
  152. package/dist/src/automations/domain/validation.js +149 -0
  153. package/dist/src/automations/domain/validation.js.map +1 -0
  154. package/dist/src/automations/draft/automation-draft-prompt.d.ts +26 -0
  155. package/dist/src/automations/draft/automation-draft-prompt.js +127 -0
  156. package/dist/src/automations/draft/automation-draft-prompt.js.map +1 -0
  157. package/dist/src/automations/draft/automation-draft-service.d.ts +12 -0
  158. package/dist/src/automations/draft/automation-draft-service.js +135 -0
  159. package/dist/src/automations/draft/automation-draft-service.js.map +1 -0
  160. package/dist/src/automations/draft/automation-draft-validator.d.ts +99 -0
  161. package/dist/src/automations/draft/automation-draft-validator.js +105 -0
  162. package/dist/src/automations/draft/automation-draft-validator.js.map +1 -0
  163. package/dist/src/automations/draft/automation-draft.types.d.ts +40 -0
  164. package/dist/src/automations/draft/index.d.ts +3 -0
  165. package/dist/src/automations/draft/index.js +3 -0
  166. package/dist/src/automations/index.d.ts +3 -0
  167. package/dist/src/automations/index.js +8 -0
  168. package/dist/src/automations/product-events.d.ts +5 -0
  169. package/dist/src/automations/product-events.js +21 -0
  170. package/dist/src/automations/product-events.js.map +1 -0
  171. package/dist/src/automations/service/action-executor.d.ts +9 -0
  172. package/dist/src/automations/service/action-executor.js +157 -0
  173. package/dist/src/automations/service/action-executor.js.map +1 -0
  174. package/dist/src/automations/service/automation-service.d.ts +54 -0
  175. package/dist/src/automations/service/automation-service.js +404 -0
  176. package/dist/src/automations/service/automation-service.js.map +1 -0
  177. package/dist/src/automations/service/index.d.ts +2 -0
  178. package/dist/src/automations/service/index.js +3 -0
  179. package/dist/src/automations/storage/automation-repository.d.ts +6 -0
  180. package/dist/src/automations/storage/automation-repository.js +61 -0
  181. package/dist/src/automations/storage/automation-repository.js.map +1 -0
  182. package/dist/src/automations/storage/automation-run-repository.d.ts +17 -0
  183. package/dist/src/automations/storage/automation-run-repository.js +130 -0
  184. package/dist/src/automations/storage/automation-run-repository.js.map +1 -0
  185. package/dist/src/automations/storage/index.d.ts +2 -0
  186. package/dist/src/automations/storage/index.js +3 -0
  187. package/dist/src/channels/plugin-types.d.ts +3 -0
  188. package/dist/src/chat-commands/builtins/thinking.js.map +1 -1
  189. package/dist/src/cli/command-catalog.js +0 -39
  190. package/dist/src/cli/command-catalog.js.map +1 -1
  191. package/dist/src/cli/command-loaders.js +0 -1
  192. package/dist/src/cli/command-loaders.js.map +1 -1
  193. package/dist/src/cli/command-manifest.js +0 -4
  194. package/dist/src/cli/command-manifest.js.map +1 -1
  195. package/dist/src/cli/commands/agents.js +7 -6
  196. package/dist/src/cli/commands/agents.js.map +1 -1
  197. package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
  198. package/dist/src/cli/commands/doctor/checks/{cron-health.d.ts → migrations.d.ts} +1 -1
  199. package/dist/src/cli/commands/doctor/checks/migrations.js +40 -0
  200. package/dist/src/cli/commands/doctor/checks/migrations.js.map +1 -0
  201. package/dist/src/cli/commands/doctor/flow.js +2 -2
  202. package/dist/src/cli/commands/doctor/flow.js.map +1 -1
  203. package/dist/src/cli/commands/gateway/call.js +2 -2
  204. package/dist/src/cli/commands/gateway/call.js.map +1 -1
  205. package/dist/src/cli/commands/gateway/lifecycle.js +1 -1
  206. package/dist/src/cli/commands/gateway/run-foreground.js +4 -2
  207. package/dist/src/cli/commands/gateway/run-foreground.js.map +1 -1
  208. package/dist/src/cli/commands/init.js +26 -8
  209. package/dist/src/cli/commands/init.js.map +1 -1
  210. package/dist/src/cli/commands/tui.js +24 -2
  211. package/dist/src/cli/commands/tui.js.map +1 -1
  212. package/dist/src/cli/utils/init-workspace-core.js +2 -0
  213. package/dist/src/cli/utils/init-workspace-core.js.map +1 -1
  214. package/dist/src/commands/agents.config.d.ts +9 -0
  215. package/dist/src/commands/agents.config.js +40 -2
  216. package/dist/src/commands/agents.config.js.map +1 -1
  217. package/dist/src/config/agent-profile.js +4 -3
  218. package/dist/src/config/agent-profile.js.map +1 -1
  219. package/dist/src/config/agent-typed-models.js.map +1 -1
  220. package/dist/src/config/config-surface.d.ts +3 -0
  221. package/dist/src/config/index.d.ts +0 -1
  222. package/dist/src/config/index.js +3 -3
  223. package/dist/src/config/index.js.map +1 -1
  224. package/dist/src/config/paths.d.ts +0 -9
  225. package/dist/src/config/paths.js +1 -14
  226. package/dist/src/config/paths.js.map +1 -1
  227. package/dist/src/config/profile.js +0 -1
  228. package/dist/src/config/profile.js.map +1 -1
  229. package/dist/src/config/rules.js +0 -5
  230. package/dist/src/config/rules.js.map +1 -1
  231. package/dist/src/config/schema.d.ts +13 -12
  232. package/dist/src/config/schema.js +22 -26
  233. package/dist/src/config/schema.js.map +1 -1
  234. package/dist/src/config/web-patch.d.ts +0 -12
  235. package/dist/src/config/web-patch.js +2 -29
  236. package/dist/src/config/web-patch.js.map +1 -1
  237. package/dist/src/extensions/api.d.ts +2 -0
  238. package/dist/src/extensions/api.js +10 -0
  239. package/dist/src/extensions/api.js.map +1 -1
  240. package/dist/src/extensions/extension-registry-impl.d.ts +4 -1
  241. package/dist/src/extensions/extension-registry-impl.js +8 -0
  242. package/dist/src/extensions/extension-registry-impl.js.map +1 -1
  243. package/dist/src/extensions/loader.d.ts +3 -3
  244. package/dist/src/extensions/loader.js +3 -3
  245. package/dist/src/extensions/loader.js.map +1 -1
  246. package/dist/src/extensions/sdk/testing.d.ts +2 -0
  247. package/dist/src/extensions/sdk/testing.js +7 -0
  248. package/dist/src/extensions/sdk/testing.js.map +1 -1
  249. package/dist/src/extensions/types/core.d.ts +10 -1
  250. package/dist/src/extensions/types/index.d.ts +1 -1
  251. package/dist/src/extensions/types/{phase4.d.ts → registration.d.ts} +2 -2
  252. package/dist/src/gateway/agent-builtin-tools.d.ts +1 -1
  253. package/dist/src/gateway/agent-builtin-tools.js +1 -1
  254. package/dist/src/gateway/agent-builtin-tools.js.map +1 -1
  255. package/dist/src/gateway/agents-admin.d.ts +1 -0
  256. package/dist/src/gateway/agents-admin.js +13 -15
  257. package/dist/src/gateway/agents-admin.js.map +1 -1
  258. package/dist/src/gateway/capability-presets-admin.d.ts +1 -0
  259. package/dist/src/gateway/capability-presets-admin.js +19 -10
  260. package/dist/src/gateway/capability-presets-admin.js.map +1 -1
  261. package/dist/src/gateway/dreaming-automation-reconciler.d.ts +11 -0
  262. package/dist/src/gateway/dreaming-automation-reconciler.js +105 -0
  263. package/dist/src/gateway/dreaming-automation-reconciler.js.map +1 -0
  264. package/dist/src/gateway/heartbeat/service.d.ts +0 -2
  265. package/dist/src/gateway/heartbeat/service.js +0 -7
  266. package/dist/src/gateway/heartbeat/service.js.map +1 -1
  267. package/dist/src/gateway/hono/lib/config-payload.d.ts +5 -6
  268. package/dist/src/gateway/hono/lib/config-payload.js +2 -2
  269. package/dist/src/gateway/hono/lib/config-payload.js.map +1 -1
  270. package/dist/src/gateway/hono/routes/agents.js.map +1 -1
  271. package/dist/src/gateway/hono/routes/config-patch/misc.d.ts +1 -1
  272. package/dist/src/gateway/hono/routes/config-patch/misc.js +12 -6
  273. package/dist/src/gateway/hono/routes/config-patch/misc.js.map +1 -1
  274. package/dist/src/gateway/hono/routes/dreaming.js +27 -37
  275. package/dist/src/gateway/hono/routes/dreaming.js.map +1 -1
  276. package/dist/src/gateway/hono/routes/home.d.ts +2 -2
  277. package/dist/src/gateway/hono/routes/home.js +34 -25
  278. package/dist/src/gateway/hono/routes/home.js.map +1 -1
  279. package/dist/src/gateway/hono/routes/lazy-bundles.js +10 -6
  280. package/dist/src/gateway/hono/routes/lazy-bundles.js.map +1 -1
  281. package/dist/src/gateway/hono/routes/migrations.d.ts +3 -0
  282. package/dist/src/gateway/hono/routes/migrations.js +35 -0
  283. package/dist/src/gateway/hono/routes/migrations.js.map +1 -0
  284. package/dist/src/gateway/hono/routes/public-gateway.js +2 -1
  285. package/dist/src/gateway/hono/routes/public-gateway.js.map +1 -1
  286. package/dist/src/gateway/hono/routes/sessions.js +14 -0
  287. package/dist/src/gateway/hono/routes/sessions.js.map +1 -1
  288. package/dist/src/gateway/run-loop.js +2 -0
  289. package/dist/src/gateway/run-loop.js.map +1 -1
  290. package/dist/src/gateway/security/operator-scopes.js +5 -1
  291. package/dist/src/gateway/security/operator-scopes.js.map +1 -1
  292. package/dist/src/gateway/service/config-coordinator.d.ts +4 -4
  293. package/dist/src/gateway/service/config-coordinator.js +14 -8
  294. package/dist/src/gateway/service/config-coordinator.js.map +1 -1
  295. package/dist/src/gateway/service/sessions-api.d.ts +2 -1
  296. package/dist/src/gateway/service/sessions-api.js +6 -1
  297. package/dist/src/gateway/service/sessions-api.js.map +1 -1
  298. package/dist/src/gateway/service.d.ts +7 -3
  299. package/dist/src/gateway/service.js +61 -27
  300. package/dist/src/gateway/service.js.map +1 -1
  301. package/dist/src/goals/goal-service.js +45 -4
  302. package/dist/src/goals/goal-service.js.map +1 -1
  303. package/dist/src/infra/update-restart.js +1 -1
  304. package/dist/src/migrations/config/default-capability-preset.d.ts +10 -0
  305. package/dist/src/migrations/config/default-capability-preset.js +135 -0
  306. package/dist/src/migrations/config/default-capability-preset.js.map +1 -0
  307. package/dist/src/migrations/index.d.ts +4 -0
  308. package/dist/src/migrations/index.js +4 -0
  309. package/dist/src/migrations/registry.d.ts +8 -0
  310. package/dist/src/migrations/registry.js +18 -0
  311. package/dist/src/migrations/registry.js.map +1 -0
  312. package/dist/src/migrations/runner.d.ts +17 -0
  313. package/dist/src/migrations/runner.js +191 -0
  314. package/dist/src/migrations/runner.js.map +1 -0
  315. package/dist/src/migrations/types.d.ts +34 -0
  316. package/dist/src/notes/service.js +24 -1
  317. package/dist/src/notes/service.js.map +1 -1
  318. package/dist/src/providers/model-registry.d.ts +0 -1
  319. package/dist/src/providers/model-registry.js +0 -3
  320. package/dist/src/providers/model-registry.js.map +1 -1
  321. package/dist/src/routing/resolve-tui-session-key.d.ts +3 -0
  322. package/dist/src/routing/resolve-tui-session-key.js +14 -3
  323. package/dist/src/routing/resolve-tui-session-key.js.map +1 -1
  324. package/dist/src/session/transcript-outline.d.ts +47 -0
  325. package/dist/src/session/transcript-outline.js +481 -0
  326. package/dist/src/session/transcript-outline.js.map +1 -0
  327. package/dist/src/storage/sqlite/index.d.ts +0 -2
  328. package/dist/src/storage/sqlite/index.js +1 -3
  329. package/dist/src/storage/sqlite/migrations/016_automations.sql +47 -0
  330. package/dist/src/storage/sqlite/migrations/017_automation_run_events.sql +14 -0
  331. package/dist/src/storage/sqlite/migrations/018_automation_safety.sql +1 -0
  332. package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
  333. package/dist/src/storage/sqlite/migrations/runner.js +3 -3
  334. package/dist/src/storage/sqlite/migrations/runner.js.map +1 -1
  335. package/dist/src/storage/sqlite/migrations/runner.ts +1 -1
  336. package/dist/src/storage/sqlite/schema.js +1 -1
  337. package/dist/src/storage/sqlite/schema.sql +56 -46
  338. package/dist/src/tui/backends/embedded-backend.d.ts +6 -0
  339. package/dist/src/tui/backends/embedded-backend.js +18 -7
  340. package/dist/src/tui/backends/embedded-backend.js.map +1 -1
  341. package/dist/src/tui/backends/gateway-sse-backend.d.ts +3 -0
  342. package/dist/src/tui/backends/gateway-sse-backend.js +14 -0
  343. package/dist/src/tui/backends/gateway-sse-backend.js.map +1 -1
  344. package/dist/src/tui/tui-backend.d.ts +4 -0
  345. package/dist/src/tui/tui-commands.d.ts +5 -0
  346. package/dist/src/tui/tui-commands.js +43 -0
  347. package/dist/src/tui/tui-commands.js.map +1 -1
  348. package/dist/src/tui/tui-transcript-tree.d.ts +1 -1
  349. package/dist/src/tui/tui-transcript-tree.js +17 -257
  350. package/dist/src/tui/tui-transcript-tree.js.map +1 -1
  351. package/dist/src/tui/tui-types.d.ts +2 -0
  352. package/dist/src/tui/tui-types.js.map +1 -1
  353. package/dist/src/tui/tui.js +7 -2
  354. package/dist/src/tui/tui.js.map +1 -1
  355. package/dist/src/workflows/domain/index.js +1 -1
  356. package/dist/src/workflows/domain/run.d.ts +7 -7
  357. package/dist/src/workflows/domain/run.js.map +1 -1
  358. package/dist/src/workflows/index.js +2 -2
  359. package/dist/src/workflows/service/workflow-run-service.d.ts +2 -0
  360. package/dist/src/workflows/service/workflow-run-service.js +31 -9
  361. package/dist/src/workflows/service/workflow-run-service.js.map +1 -1
  362. package/dist/src/workflows/service/workflow-run-service.types.d.ts +1 -1
  363. package/package.json +4 -2
  364. package/dist/gateway/static/root/assets/agents-BCxZbkOw.js +0 -2
  365. package/dist/gateway/static/root/assets/app-management-settings-panel-bxYJVJpx.js +0 -1
  366. package/dist/gateway/static/root/assets/appearance-settings-BCIykXlI.js +0 -1
  367. package/dist/gateway/static/root/assets/browser-settings-page-DRhKdn81.js +0 -8
  368. package/dist/gateway/static/root/assets/capability-presets-api-CorhiHlg.js +0 -1
  369. package/dist/gateway/static/root/assets/capability-presets-settings-panel-qFx9Jtce.js +0 -1
  370. package/dist/gateway/static/root/assets/channels-settings-BAwAkqIA.js +0 -1
  371. package/dist/gateway/static/root/assets/cn-JdwAhgNB.js +0 -1
  372. package/dist/gateway/static/root/assets/connectors-page-BQLcfitM.js +0 -2
  373. package/dist/gateway/static/root/assets/createLucideIcon-DPHK1VkS.js +0 -1
  374. package/dist/gateway/static/root/assets/cron-api-qGwmL-24.js +0 -1
  375. package/dist/gateway/static/root/assets/cron-dreaming-jobs-nCMWCf0p.js +0 -1
  376. package/dist/gateway/static/root/assets/cron-page-BBWMAj8-.js +0 -3
  377. package/dist/gateway/static/root/assets/dreaming-settings-Dw89Obml.js +0 -1
  378. package/dist/gateway/static/root/assets/format-cron-label-BsotZDO5.js +0 -2
  379. package/dist/gateway/static/root/assets/format-interval-label-BzxafKxR.js +0 -1
  380. package/dist/gateway/static/root/assets/gateway-settings-Cmwy58rS.js +0 -1
  381. package/dist/gateway/static/root/assets/goal-detail-page-l7mu5GWX.js +0 -1
  382. package/dist/gateway/static/root/assets/goals-settings-CYVY4NGp.js +0 -1
  383. package/dist/gateway/static/root/assets/heartbeat-config-api-DriO_CN9.js +0 -1
  384. package/dist/gateway/static/root/assets/heartbeat-settings-CUQTKxg7.js +0 -1
  385. package/dist/gateway/static/root/assets/index-C17Tsd_b.css +0 -1
  386. package/dist/gateway/static/root/assets/index-Cc41r16l.js +0 -191
  387. package/dist/gateway/static/root/assets/interval-presets-DFPCKW_W.js +0 -1
  388. package/dist/gateway/static/root/assets/keyboard-shortcuts-settings-CcVcqstx.js +0 -1
  389. package/dist/gateway/static/root/assets/messages-B1iSKjiw.js +0 -3
  390. package/dist/gateway/static/root/assets/models-hub-panel-BfLfcta8.js +0 -2
  391. package/dist/gateway/static/root/assets/note-detail-page-BjwOQBfT.js +0 -2
  392. package/dist/gateway/static/root/assets/notes-page-DktdBiwB.js +0 -1
  393. package/dist/gateway/static/root/assets/remote-access-hub-rfVx96fq.js +0 -1
  394. package/dist/gateway/static/root/assets/schedule-field-CUCKODde.js +0 -1
  395. package/dist/gateway/static/root/assets/sessions-page-DbtMFuuH.js +0 -1
  396. package/dist/gateway/static/root/assets/settings-advanced-gate-5re5gAnP.js +0 -1
  397. package/dist/gateway/static/root/assets/settings-page-D-WMyLlj.js +0 -1
  398. package/dist/gateway/static/root/assets/setup-status-panel-Cl-DEJAU.js +0 -1
  399. package/dist/gateway/static/root/assets/shares-settings-CyPVvbLt.js +0 -1
  400. package/dist/gateway/static/root/assets/skill-reload-api-CleTH1oz.js +0 -1
  401. package/dist/gateway/static/root/assets/skills-page-Ck8hdXqR.js +0 -2
  402. package/dist/gateway/static/root/assets/system-settings-panel-DI-LN_8G.js +0 -1
  403. package/dist/gateway/static/root/assets/typed-models-lib-kX9duch4.js +0 -1
  404. package/dist/gateway/static/root/assets/user-profile-settings-panel-B-UFPMXy.js +0 -1
  405. package/dist/gateway/static/root/assets/utils-Dm0hKalR.js +0 -1
  406. package/dist/gateway/static/root/assets/workflows-page-BtFGp2y_.js +0 -18
  407. package/dist/src/agent/fallback/error.d.ts +0 -22
  408. package/dist/src/agent/fallback/error.js +0 -32
  409. package/dist/src/agent/fallback/error.js.map +0 -1
  410. package/dist/src/agent/fallback/index.d.ts +0 -5
  411. package/dist/src/agent/fallback/index.js +0 -9
  412. package/dist/src/agent/fallback/index.js.map +0 -1
  413. package/dist/src/agent/orchestration/run-agent-turn-with-fallbacks.d.ts +0 -29
  414. package/dist/src/agent/orchestration/run-agent-turn-with-fallbacks.js +0 -76
  415. package/dist/src/agent/orchestration/run-agent-turn-with-fallbacks.js.map +0 -1
  416. package/dist/src/agent/service/reconcile-dreaming-cron.d.ts +0 -6
  417. package/dist/src/agent/service/reconcile-dreaming-cron.js +0 -84
  418. package/dist/src/agent/service/reconcile-dreaming-cron.js.map +0 -1
  419. package/dist/src/agent/tools/cronjob-tool.d.ts +0 -29
  420. package/dist/src/agent/tools/cronjob-tool.js +0 -274
  421. package/dist/src/agent/tools/cronjob-tool.js.map +0 -1
  422. package/dist/src/cli/commands/cron-cli.d.ts +0 -2
  423. package/dist/src/cli/commands/cron-cli.js +0 -15
  424. package/dist/src/cli/commands/cron-cli.js.map +0 -1
  425. package/dist/src/cli/commands/cron.d.ts +0 -4
  426. package/dist/src/cli/commands/cron.js +0 -188
  427. package/dist/src/cli/commands/cron.js.map +0 -1
  428. package/dist/src/cli/commands/doctor/checks/cron-health.js +0 -35
  429. package/dist/src/cli/commands/doctor/checks/cron-health.js.map +0 -1
  430. package/dist/src/cron/execution-types.d.ts +0 -42
  431. package/dist/src/cron/executor.d.ts +0 -67
  432. package/dist/src/cron/executor.js +0 -669
  433. package/dist/src/cron/executor.js.map +0 -1
  434. package/dist/src/cron/index.d.ts +0 -7
  435. package/dist/src/cron/index.js +0 -7
  436. package/dist/src/cron/job-content.d.ts +0 -5
  437. package/dist/src/cron/job-content.js +0 -15
  438. package/dist/src/cron/job-content.js.map +0 -1
  439. package/dist/src/cron/run-log-store.d.ts +0 -12
  440. package/dist/src/cron/run-log-store.js +0 -58
  441. package/dist/src/cron/run-log-store.js.map +0 -1
  442. package/dist/src/cron/schedule.d.ts +0 -10
  443. package/dist/src/cron/schedule.js +0 -85
  444. package/dist/src/cron/schedule.js.map +0 -1
  445. package/dist/src/cron/service.d.ts +0 -58
  446. package/dist/src/cron/service.js +0 -419
  447. package/dist/src/cron/service.js.map +0 -1
  448. package/dist/src/cron/types.d.ts +0 -183
  449. package/dist/src/cron/validation.d.ts +0 -500
  450. package/dist/src/cron/validation.js +0 -192
  451. package/dist/src/cron/validation.js.map +0 -1
  452. package/dist/src/cron/workflow-run-completion.d.ts +0 -23
  453. package/dist/src/cron/workflow-run-completion.js +0 -72
  454. package/dist/src/cron/workflow-run-completion.js.map +0 -1
  455. package/dist/src/extensions/types/phase4.js +0 -1
  456. package/dist/src/gateway/hono/routes/cron.d.ts +0 -3
  457. package/dist/src/gateway/hono/routes/cron.js +0 -109
  458. package/dist/src/gateway/hono/routes/cron.js.map +0 -1
  459. package/dist/src/storage/sqlite/cron-job-repository.d.ts +0 -6
  460. package/dist/src/storage/sqlite/cron-job-repository.js +0 -70
  461. package/dist/src/storage/sqlite/cron-job-repository.js.map +0 -1
  462. package/dist/src/storage/sqlite/cron-run-repository.d.ts +0 -5
  463. package/dist/src/storage/sqlite/cron-run-repository.js +0 -96
  464. package/dist/src/storage/sqlite/cron-run-repository.js.map +0 -1
  465. /package/dist/src/{cron → automations/domain}/types.js +0 -0
  466. /package/dist/src/{config/defaults.d.ts → automations/draft/automation-draft.types.js} +0 -0
  467. /package/dist/src/{config/defaults.js → extensions/types/registration.js} +0 -0
  468. /package/dist/src/{cron/execution-types.js → migrations/types.js} +0 -0
@@ -0,0 +1,149 @@
1
+ import { z } from "zod";
2
+ import { CronExpressionParser } from "cron-parser";
3
+ //#region src/automations/domain/validation.ts
4
+ const nonEmptyString = z.string().trim().min(1);
5
+ const optionalTrimmedString = (max) => z.preprocess((value) => {
6
+ if (value == null) return void 0;
7
+ if (typeof value !== "string") return value;
8
+ const trimmed = value.trim();
9
+ return trimmed.length === 0 ? void 0 : trimmed;
10
+ }, z.string().min(1).max(max).optional());
11
+ const AutomationScheduleSchema = z.discriminatedUnion("kind", [
12
+ z.object({
13
+ kind: z.literal("once"),
14
+ at: nonEmptyString
15
+ }).strict(),
16
+ z.object({
17
+ kind: z.literal("interval"),
18
+ everyMs: z.number().int().min(1),
19
+ anchorMs: z.number().int().nonnegative().optional()
20
+ }).strict(),
21
+ z.object({
22
+ kind: z.literal("cron"),
23
+ expr: nonEmptyString.superRefine((expr, ctx) => {
24
+ try {
25
+ CronExpressionParser.parse(expr);
26
+ } catch {
27
+ ctx.addIssue({
28
+ code: z.ZodIssueCode.custom,
29
+ message: `Invalid cron expression: ${expr}`
30
+ });
31
+ }
32
+ }),
33
+ tz: optionalTrimmedString(100)
34
+ }).strict()
35
+ ]);
36
+ const AutomationTriggerSchema = z.discriminatedUnion("kind", [
37
+ z.object({ kind: z.literal("manual") }).strict(),
38
+ z.object({
39
+ kind: z.literal("schedule"),
40
+ schedule: AutomationScheduleSchema
41
+ }).strict(),
42
+ z.object({
43
+ kind: z.literal("webhook"),
44
+ secretId: optionalTrimmedString(200)
45
+ }).strict(),
46
+ z.object({
47
+ kind: z.literal("event"),
48
+ eventType: nonEmptyString.max(200),
49
+ source: optionalTrimmedString(200),
50
+ payloadMatch: z.record(z.string(), z.union([
51
+ z.string(),
52
+ z.number(),
53
+ z.boolean(),
54
+ z.null()
55
+ ])).optional()
56
+ }).strict()
57
+ ]);
58
+ const WorkflowRunInputEnvelopeSchema = z.object({
59
+ payload: z.unknown(),
60
+ goal: optionalTrimmedString(5e3),
61
+ variables: z.record(z.string(), z.unknown()).optional(),
62
+ context: z.record(z.string(), z.unknown()).optional()
63
+ }).strict();
64
+ const AutomationActionSchema = z.discriminatedUnion("kind", [z.object({
65
+ kind: z.literal("agent"),
66
+ agentId: optionalTrimmedString(64),
67
+ instruction: nonEmptyString.max(5e4),
68
+ workingDirectory: optionalTrimmedString(4096),
69
+ model: optionalTrimmedString(100),
70
+ timeoutSeconds: z.number().int().min(1).max(86400).optional()
71
+ }).strict(), z.object({
72
+ kind: z.literal("workflow"),
73
+ workflowId: nonEmptyString.max(200),
74
+ agentId: optionalTrimmedString(64),
75
+ input: z.unknown().optional(),
76
+ inputEnvelope: WorkflowRunInputEnvelopeSchema.optional(),
77
+ goal: optionalTrimmedString(5e3),
78
+ concurrency: z.number().int().min(1).max(50).optional(),
79
+ maxSubagents: z.number().int().min(1).max(100).optional(),
80
+ timeoutSeconds: z.number().int().min(1).max(86400).optional()
81
+ }).strict()]);
82
+ const AutomationAfterRunSchema = z.discriminatedUnion("kind", [
83
+ z.object({ kind: z.literal("none") }).strict(),
84
+ z.object({ kind: z.literal("saveToSession") }).strict(),
85
+ z.object({
86
+ kind: z.literal("webhook"),
87
+ url: nonEmptyString.max(2e3)
88
+ }).strict()
89
+ ]);
90
+ const AutomationReliabilitySchema = z.object({
91
+ timeoutSeconds: z.number().int().min(1).max(86400).optional(),
92
+ retryCount: z.number().int().min(0).max(10).optional(),
93
+ maxConcurrentRuns: z.number().int().min(1).max(20).optional(),
94
+ disableAfterConsecutiveFailures: z.number().int().min(1).max(100).optional()
95
+ }).strict();
96
+ const AutomationSafetyPolicySchema = z.object({ mode: z.enum([
97
+ "suggest_only",
98
+ "ask_before_apply",
99
+ "auto_apply"
100
+ ]) }).strict();
101
+ const AutomationStateSchema = z.object({
102
+ nextRunAtMs: z.number().int().nonnegative().optional(),
103
+ runningRunId: optionalTrimmedString(100),
104
+ lastRunAtMs: z.number().int().nonnegative().optional(),
105
+ lastRunStatus: z.enum([
106
+ "queued",
107
+ "running",
108
+ "succeeded",
109
+ "failed",
110
+ "cancelled",
111
+ "timeout"
112
+ ]).optional(),
113
+ lastError: z.string().optional(),
114
+ consecutiveFailures: z.number().int().nonnegative().optional()
115
+ }).strict();
116
+ const AutomationSchema = z.object({
117
+ id: nonEmptyString.max(100),
118
+ name: nonEmptyString.max(200),
119
+ description: z.string().max(2e3).optional(),
120
+ enabled: z.boolean(),
121
+ trigger: AutomationTriggerSchema,
122
+ action: AutomationActionSchema,
123
+ safety: AutomationSafetyPolicySchema.optional(),
124
+ afterRun: AutomationAfterRunSchema.optional(),
125
+ reliability: AutomationReliabilitySchema.optional(),
126
+ state: AutomationStateSchema.default({}),
127
+ createdAtMs: z.number().int().nonnegative(),
128
+ updatedAtMs: z.number().int().nonnegative()
129
+ }).strict();
130
+ const CreateAutomationSchema = AutomationSchema.omit({
131
+ id: true,
132
+ enabled: true,
133
+ state: true,
134
+ createdAtMs: true,
135
+ updatedAtMs: true
136
+ }).extend({
137
+ id: optionalTrimmedString(100),
138
+ enabled: z.boolean().optional(),
139
+ state: AutomationStateSchema.partial().optional()
140
+ });
141
+ const UpdateAutomationSchema = AutomationSchema.omit({
142
+ id: true,
143
+ createdAtMs: true,
144
+ updatedAtMs: true
145
+ }).partial().refine((data) => Object.keys(data).length > 0, { message: "At least one field must be provided" });
146
+ //#endregion
147
+ export { AutomationActionSchema, AutomationAfterRunSchema, AutomationReliabilitySchema, AutomationSafetyPolicySchema, AutomationScheduleSchema, AutomationSchema, AutomationStateSchema, AutomationTriggerSchema, CreateAutomationSchema, UpdateAutomationSchema };
148
+
149
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.js","names":[],"sources":["../../../../src/automations/domain/validation.ts"],"sourcesContent":["import { CronExpressionParser } from 'cron-parser';\nimport { z } from 'zod';\n\nconst nonEmptyString = z.string().trim().min(1);\n\nconst optionalTrimmedString = (max: number) =>\n z.preprocess((value) => {\n if (value == null) return undefined;\n if (typeof value !== 'string') return value;\n const trimmed = value.trim();\n return trimmed.length === 0 ? undefined : trimmed;\n }, z.string().min(1).max(max).optional());\n\nexport const AutomationScheduleSchema = z.discriminatedUnion('kind', [\n z.object({\n kind: z.literal('once'),\n at: nonEmptyString,\n }).strict(),\n z.object({\n kind: z.literal('interval'),\n everyMs: z.number().int().min(1),\n anchorMs: z.number().int().nonnegative().optional(),\n }).strict(),\n z.object({\n kind: z.literal('cron'),\n expr: nonEmptyString.superRefine((expr, ctx) => {\n try {\n CronExpressionParser.parse(expr);\n } catch {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: `Invalid cron expression: ${expr}`,\n });\n }\n }),\n tz: optionalTrimmedString(100),\n }).strict(),\n]);\n\nexport const AutomationTriggerSchema = z.discriminatedUnion('kind', [\n z.object({ kind: z.literal('manual') }).strict(),\n z.object({\n kind: z.literal('schedule'),\n schedule: AutomationScheduleSchema,\n }).strict(),\n z.object({\n kind: z.literal('webhook'),\n secretId: optionalTrimmedString(200),\n }).strict(),\n z.object({\n kind: z.literal('event'),\n eventType: nonEmptyString.max(200),\n source: optionalTrimmedString(200),\n payloadMatch: z.record(\n z.string(),\n z.union([z.string(), z.number(), z.boolean(), z.null()]),\n ).optional(),\n }).strict(),\n]);\n\nconst WorkflowRunInputEnvelopeSchema = z.object({\n payload: z.unknown(),\n goal: optionalTrimmedString(5000),\n variables: z.record(z.string(), z.unknown()).optional(),\n context: z.record(z.string(), z.unknown()).optional(),\n}).strict();\n\nexport const AutomationActionSchema = z.discriminatedUnion('kind', [\n z.object({\n kind: z.literal('agent'),\n agentId: optionalTrimmedString(64),\n instruction: nonEmptyString.max(50000),\n workingDirectory: optionalTrimmedString(4096),\n model: optionalTrimmedString(100),\n timeoutSeconds: z.number().int().min(1).max(86400).optional(),\n }).strict(),\n z.object({\n kind: z.literal('workflow'),\n workflowId: nonEmptyString.max(200),\n agentId: optionalTrimmedString(64),\n input: z.unknown().optional(),\n inputEnvelope: WorkflowRunInputEnvelopeSchema.optional(),\n goal: optionalTrimmedString(5000),\n concurrency: z.number().int().min(1).max(50).optional(),\n maxSubagents: z.number().int().min(1).max(100).optional(),\n timeoutSeconds: z.number().int().min(1).max(86400).optional(),\n }).strict(),\n]);\n\nexport const AutomationAfterRunSchema = z.discriminatedUnion('kind', [\n z.object({ kind: z.literal('none') }).strict(),\n z.object({ kind: z.literal('saveToSession') }).strict(),\n z.object({\n kind: z.literal('webhook'),\n url: nonEmptyString.max(2000),\n }).strict(),\n]);\n\nexport const AutomationReliabilitySchema = z.object({\n timeoutSeconds: z.number().int().min(1).max(86400).optional(),\n retryCount: z.number().int().min(0).max(10).optional(),\n maxConcurrentRuns: z.number().int().min(1).max(20).optional(),\n disableAfterConsecutiveFailures: z.number().int().min(1).max(100).optional(),\n}).strict();\n\nexport const AutomationSafetyPolicySchema = z.object({\n mode: z.enum(['suggest_only', 'ask_before_apply', 'auto_apply']),\n}).strict();\n\nexport const AutomationStateSchema = z.object({\n nextRunAtMs: z.number().int().nonnegative().optional(),\n runningRunId: optionalTrimmedString(100),\n lastRunAtMs: z.number().int().nonnegative().optional(),\n lastRunStatus: z.enum(['queued', 'running', 'succeeded', 'failed', 'cancelled', 'timeout']).optional(),\n lastError: z.string().optional(),\n consecutiveFailures: z.number().int().nonnegative().optional(),\n}).strict();\n\nexport const AutomationSchema = z.object({\n id: nonEmptyString.max(100),\n name: nonEmptyString.max(200),\n description: z.string().max(2000).optional(),\n enabled: z.boolean(),\n trigger: AutomationTriggerSchema,\n action: AutomationActionSchema,\n safety: AutomationSafetyPolicySchema.optional(),\n afterRun: AutomationAfterRunSchema.optional(),\n reliability: AutomationReliabilitySchema.optional(),\n state: AutomationStateSchema.default({}),\n createdAtMs: z.number().int().nonnegative(),\n updatedAtMs: z.number().int().nonnegative(),\n}).strict();\n\nexport const CreateAutomationSchema = AutomationSchema.omit({\n id: true,\n enabled: true,\n state: true,\n createdAtMs: true,\n updatedAtMs: true,\n}).extend({\n id: optionalTrimmedString(100),\n enabled: z.boolean().optional(),\n state: AutomationStateSchema.partial().optional(),\n});\n\nexport const UpdateAutomationSchema = AutomationSchema.omit({\n id: true,\n createdAtMs: true,\n updatedAtMs: true,\n}).partial().refine(\n (data) => Object.keys(data).length > 0,\n { message: 'At least one field must be provided' },\n);\n\nexport type CreateAutomationInput = z.infer<typeof CreateAutomationSchema>;\nexport type UpdateAutomationInput = z.infer<typeof UpdateAutomationSchema>;\n"],"mappings":";;;AAGA,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE;AAE/C,MAAM,yBAAyB,QAC7B,EAAE,YAAY,UAAU;AACtB,KAAI,SAAS,KAAM,QAAO,KAAA;AAC1B,KAAI,OAAO,UAAU,SAAU,QAAO;CACtC,MAAM,UAAU,MAAM,MAAM;AAC5B,QAAO,QAAQ,WAAW,IAAI,KAAA,IAAY;GACzC,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC;AAE3C,MAAa,2BAA2B,EAAE,mBAAmB,QAAQ;CACnE,EAAE,O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,aAAa,4BAA4B,UAAU;CACnD,OAAO,sBAAsB,QAAQ,EAAE,CAAC;CACxC,aAAa,EAAE,QAAQ,CAAC,KAAK,CAAC,aAAa;CAC3C,aAAa,EAAE,QAAQ,CAAC,KAAK,CAAC,aAAa;CAC5C,CAAC,CAAC,QAAQ;AAEX,MAAa,yBAAyB,iBAAiB,KAAK;CAC1D,IAAI;CACJ,SAAS;CACT,OAAO;CACP,aAAa;CACb,aAAa;CACd,CAAC,CAAC,OAAO;CACR,IAAI,sBAAsB,IAAI;CAC9B,SAAS,EAAE,SAAS,CAAC,UAAU;CAC/B,OAAO,sBAAsB,SAAS,CAAC,UAAU;CAClD,CAAC;AAEF,MAAa,yBAAyB,iBAAiB,KAAK;CAC1D,IAAI;CACJ,aAAa;CACb,aAAa;CACd,CAAC,CAAC,SAAS,CAAC,QACV,SAAS,OAAO,KAAK,KAAK,CAAC,SAAS,GACrC,EAAE,SAAS,uCAAuC,CACnD"}
@@ -0,0 +1,26 @@
1
+ export interface AutomationDraftRepairIssue {
2
+ source: 'parse' | 'validation';
3
+ severity: 'error';
4
+ message: string;
5
+ }
6
+ export declare function buildAutomationDraftPrompt(params: {
7
+ prompt: string;
8
+ language?: 'en' | 'zh';
9
+ }): string;
10
+ export declare function buildAutomationDraftRepairPrompt(params: {
11
+ prompt: string;
12
+ language?: 'en' | 'zh';
13
+ previousOutput: string;
14
+ issues: AutomationDraftRepairIssue[];
15
+ }): string;
16
+ export declare function buildAutomationRunRepairPrompt(params: {
17
+ language?: 'en' | 'zh';
18
+ automation: unknown;
19
+ run: unknown;
20
+ events: unknown[];
21
+ }): string;
22
+ export declare function buildAutomationRunRepairRetryPrompt(params: {
23
+ language?: 'en' | 'zh';
24
+ previousOutput: string;
25
+ issues: AutomationDraftRepairIssue[];
26
+ }): string;
@@ -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":";;;;;;;;gBAGwD;aACH;AAqBrD,MAAM,MAAM,aAAa,kBAAkB;AAC3C,MAAM,8BAA8B;AAOpC,IAAa,yBAAb,MAAoC;CAClC,YAAY,SAAyD;AAAxC,OAAA,UAAA;;CAE7B,MAAM,YAAY,SAAuC,QAAwD;EAC/G,MAAM,SAAS,QAAQ,OAAO,MAAM;AACpC,MAAI,CAAC,OAAQ,OAAM,IAAI,MAAM,qBAAqB;EAElD,MAAM,WAAW,qBAAqB,KAAK,QAAQ,QAAQ,QAAQ,QAAQ;EAC3E,MAAM,QAAQ,aAAa,SAAS;EACpC,MAAM,oBAAoB,KAAK,QAAQ,qBAAqB;EAC5D,IAAI,iBAAiB,2BAA2B;GAAE;GAAQ,UAAU,QAAQ;GAAU,CAAC;EACvF,IAAI,WAAW;EACf,IAAI,aA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Y,MALF,SACnB,OACA,EAAE,UAAU,CAAC;IANb,MAAM;IACN,SAAS;IACT,WAAW,KAAK,KAAK;IAID,CAAC,EAAE,EACvB;IAAE,WAAW;IAAM,aAAa,YAAY,IAAI,MAAO;IAAM;IAAQ,CACtE,CAC6B;AAC9B,OAAI;AACF,WAAO,oCAAoC,UAAU,QAAQ;YACtD,KAAK;AACZ,iBAAa,CAAC;KACZ,QAAQ;KACR,UAAU;KACV,SAAS,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI;KAC1D,CAAC;;AAGJ,OAAI,WAAW,kBAAmB;AAClC,OAAI,KACF;IAAE;IAAU,SAAS,UAAU;IAAG,YAAY,WAAW;IAAQ,SAAS,SAAS,MAAM,GAAG,IAAI;IAAE,EAClG,oEACD;AACD,oBAAiB,oCAAoC;IACnD,UAAU,QAAQ;IAClB,gBAAgB;IAChB,QAAQ;IACT,CAAC;;EAGJ,MAAM,UAAU,4DAA4D,oBAAoB,EAAE;AAClG,MAAI,KAAK;GAAE;GAAU,QAAQ;GAAY,SAAS,SAAS,MAAM,GAAG,IAAI;GAAE,EAAE,QAAQ;AACpF,QAAM,IAAI,MAAM,QAAQ;;;AAI5B,SAAS,YAAY,QAAyB;CAC5C,MAAM,UAAW,OAAiC;AAClD,KAAI,OAAO,YAAY,SAAU,QAAO;AACxC,KAAI,MAAM,QAAQ,QAAQ,CACxB,QAAO,QAAQ,KAAK,SAAS;AAC3B,MAAI,QAAQ,OAAO,SAAS,YAAa,KAA2B,SAAS,OAC3E,QAAO,OAAQ,KAA2B,QAAQ,GAAG;AAEvD,SAAO;GACP,CAAC,KAAK,GAAG;AAEb,QAAO"}
@@ -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 {};