@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.
- package/README.md +2 -1
- package/README.zh-CN.md +2 -1
- package/dist/browser-ext/manifest.json +1 -1
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-dzUrQoeZ.js → agent-avatar-dicebear-CU8J6zou.js} +1 -1
- package/dist/gateway/static/root/assets/agents-B0hkpLhP.js +2 -0
- package/dist/gateway/static/root/assets/app-management-settings-panel-B9vfYoEr.js +1 -0
- package/dist/gateway/static/root/assets/appearance-settings-ClOzIO24.js +1 -0
- package/dist/gateway/static/root/assets/{apps-page--wMEL00f.js → apps-page-DU0dz9Zo.js} +1 -1
- package/dist/gateway/static/root/assets/{archive-plugin-Cki4SfU2.js → archive-plugin-BkVIgZzA.js} +1 -1
- package/dist/gateway/static/root/assets/{attachment-load-D-KnS2Do.js → attachment-load-CaCMWh1D.js} +1 -1
- package/dist/gateway/static/root/assets/automation-suggestion-card-DhGDpKP3.js +1 -0
- package/dist/gateway/static/root/assets/automations-page-CTedroVo.js +1 -0
- package/dist/gateway/static/root/assets/{binary-plugins-D2sgvJja.js → binary-plugins-B4TO_bsn.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-DIq-4Gvb.js → block-editor-DJRWwWNI.js} +28 -28
- package/dist/gateway/static/root/assets/browser-settings-page-FCDwOOBK.js +8 -0
- package/dist/gateway/static/root/assets/capability-presets-api-Befi89CL.js +1 -0
- package/dist/gateway/static/root/assets/capability-presets-settings-panel-_G8eb2vJ.js +1 -0
- package/dist/gateway/static/root/assets/channel-recipient-api-BNSuJb5f.js +1 -0
- package/dist/gateway/static/root/assets/channels-settings-C3d5JBJX.js +1 -0
- package/dist/gateway/static/root/assets/cn-BQ_8x0bT.js +1 -0
- package/dist/gateway/static/root/assets/connectors-page-yaUNvt5u.js +2 -0
- package/dist/gateway/static/root/assets/cron-expression-B3B1eqnr.js +2 -0
- package/dist/gateway/static/root/assets/dreaming-settings-DNrdg1Ve.js +1 -0
- package/dist/gateway/static/root/assets/{extension-debug-page-DYu1KaFQ.js → extension-debug-page-DYh402XV.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-B3W6QwlZ.js → extension-page-Cr_TizrN.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-D7VQ-cxE.js → extension-settings-page-BU1KoKRj.js} +1 -1
- package/dist/gateway/static/root/assets/{fetch-B7xDPu-R.js → fetch-Y7AEX4H3.js} +1 -1
- package/dist/gateway/static/root/assets/format-cron-label-arqgGlVV.js +1 -0
- package/dist/gateway/static/root/assets/{gateway-config-api-BTBLSeUu.js → gateway-config-api-RbMmAOpX.js} +1 -1
- package/dist/gateway/static/root/assets/gateway-settings-C79wkXef.js +1 -0
- package/dist/gateway/static/root/assets/{gateway-startup-retry-CYj9FWCp.js → gateway-startup-retry-DiD_Tx4N.js} +1 -1
- package/dist/gateway/static/root/assets/goal-detail-page-9paXuHdo.js +1 -0
- package/dist/gateway/static/root/assets/{goals-config-api-CQQgzPr3.js → goals-config-api-DqxVi0p5.js} +1 -1
- package/dist/gateway/static/root/assets/{goals-page-BHitvJAv.js → goals-page-CS0R-Af2.js} +2 -2
- package/dist/gateway/static/root/assets/goals-settings-CSuzZ8Ae.js +1 -0
- package/dist/gateway/static/root/assets/heartbeat-settings-DXPaYJm3.js +1 -0
- package/dist/gateway/static/root/assets/index-BoKafJIZ.js +191 -0
- package/dist/gateway/static/root/assets/index-CArhCcYn.css +1 -0
- package/dist/gateway/static/root/assets/keyboard-shortcuts-settings-Dvg53qnd.js +1 -0
- package/dist/gateway/static/root/assets/{logs-page-C2Uqvae9.js → logs-page-DLXPcksQ.js} +2 -2
- package/dist/gateway/static/root/assets/{markdown-split-BwOFrJ2E.js → markdown-split-CpHxbtWJ.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-Cnz6Q5G6.js → media-plugins-SFPQRSxq.js} +1 -1
- package/dist/gateway/static/root/assets/messages-CrDHEbss.js +3 -0
- package/dist/gateway/static/root/assets/models-hub-panel-BDF2iyRk.js +2 -0
- package/dist/gateway/static/root/assets/note-detail-page-CSb_hwig.js +2 -0
- package/dist/gateway/static/root/assets/{note-image-lightbox-B-Svpmza.js → note-image-lightbox-BUYURRgn.js} +1 -1
- package/dist/gateway/static/root/assets/notes-page-BsIBSFyZ.js +1 -0
- package/dist/gateway/static/root/assets/{preview-open-alternatives-Bss4TiwP.js → preview-open-alternatives-BHz9iWYA.js} +1 -1
- package/dist/gateway/static/root/assets/remote-access-hub-CwzSovcS.js +1 -0
- package/dist/gateway/static/root/assets/{save-bar-controls-BRNjdgKq.js → save-bar-controls-CefkOlRg.js} +1 -1
- package/dist/gateway/static/root/assets/schedule-field-CmTRoOcE.js +1 -0
- package/dist/gateway/static/root/assets/{schema-form-Dub9sy8r.js → schema-form-FMKv1vGu.js} +1 -1
- package/dist/gateway/static/root/assets/sessions-page-PHmX-NmA.js +1 -0
- package/dist/gateway/static/root/assets/settings-advanced-gate-BRAeKJN4.js +1 -0
- package/dist/gateway/static/root/assets/{settings-collapsible-section-BeFLavGi.js → settings-collapsible-section-BouO6JTi.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-form-section-dmyaPOTG.js → settings-form-section-D-4lBl6X.js} +1 -1
- package/dist/gateway/static/root/assets/settings-page-KKrbFjy8.js +1 -0
- package/dist/gateway/static/root/assets/settings-page-layout-BJ4Gsef5.js +1 -0
- package/dist/gateway/static/root/assets/setup-status-panel-CrUjHPQo.js +1 -0
- package/dist/gateway/static/root/assets/{share-preview-page-C8glrdqe.js → share-preview-page-BDy2btRN.js} +1 -1
- package/dist/gateway/static/root/assets/shares-settings-B18OBmH5.js +1 -0
- package/dist/gateway/static/root/assets/skill-reload-api-C28-2uKQ.js +1 -0
- package/dist/gateway/static/root/assets/skills-page-Bm2ebkwl.js +2 -0
- package/dist/gateway/static/root/assets/system-settings-panel-CRngrlnZ.js +1 -0
- package/dist/gateway/static/root/assets/typed-models-lib-BltBc0b-.js +1 -0
- package/dist/gateway/static/root/assets/{use-channel-catalog-DqlWTsDb.js → use-channel-catalog-CjN-51e6.js} +1 -1
- package/dist/gateway/static/root/assets/user-profile-settings-panel-DJ1dKwZy.js +1 -0
- package/dist/gateway/static/root/assets/utils-B5M5-YvK.js +1 -0
- package/dist/gateway/static/root/assets/{voice-api-key-field-C73IVZeC.js → voice-api-key-field-CeEevm7z.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-player-store-C_ArLJPM.js → voice-player-store-B7ykUlHM.js} +1 -1
- package/dist/gateway/static/root/assets/workflow-run-setup-panel-C4PzUQjB.js +3 -0
- package/dist/gateway/static/root/assets/workflows-page-BL84_-Ky.js +18 -0
- package/dist/gateway/static/root/index.html +6 -7
- package/dist/package.js +1 -1
- package/dist/src/agent/agent-manager.d.ts +4 -5
- package/dist/src/agent/agent-manager.js +4 -8
- package/dist/src/agent/agent-manager.js.map +1 -1
- package/dist/src/agent/embedded/run-for-session.js +102 -14
- package/dist/src/agent/embedded/run-for-session.js.map +1 -1
- package/dist/src/agent/fallback/candidates.d.ts +0 -8
- package/dist/src/agent/fallback/candidates.js.map +1 -1
- package/dist/src/agent/index.js +1 -1
- package/dist/src/agent/lifecycle/handlers/compaction.d.ts +1 -3
- package/dist/src/agent/lifecycle/handlers/compaction.js +1 -16
- package/dist/src/agent/lifecycle/handlers/compaction.js.map +1 -1
- package/dist/src/agent/lifecycle/progress.d.ts +0 -1
- package/dist/src/agent/lifecycle/progress.js +1 -6
- package/dist/src/agent/lifecycle/progress.js.map +1 -1
- package/dist/src/agent/lifecycle/timeout-wrapper.d.ts +1 -2
- package/dist/src/agent/lifecycle/timeout-wrapper.js +1 -7
- package/dist/src/agent/lifecycle/timeout-wrapper.js.map +1 -1
- package/dist/src/agent/middleware/self-verify.d.ts +0 -1
- package/dist/src/agent/middleware/self-verify.js +0 -2
- package/dist/src/agent/middleware/self-verify.js.map +1 -1
- package/dist/src/agent/models/index.d.ts +1 -1
- package/dist/src/agent/models/manager.d.ts +4 -20
- package/dist/src/agent/models/manager.js +9 -126
- package/dist/src/agent/models/manager.js.map +1 -1
- package/dist/src/agent/orchestration/agent-orchestrator.d.ts +0 -4
- package/dist/src/agent/orchestration/agent-orchestrator.js +1 -9
- package/dist/src/agent/orchestration/agent-orchestrator.js.map +1 -1
- package/dist/src/agent/prompt/sections/tooling.js +2 -2
- package/dist/src/agent/prompt/sections/tooling.js.map +1 -1
- package/dist/src/agent/prompt/service-prompt-builder.d.ts +0 -1
- package/dist/src/agent/prompt/service-prompt-builder.js +0 -12
- package/dist/src/agent/prompt/service-prompt-builder.js.map +1 -1
- package/dist/src/agent/prompt/subagent-context.js +1 -1
- package/dist/src/agent/prompt/subagent-context.js.map +1 -1
- package/dist/src/agent/prompt/types.d.ts +1 -1
- package/dist/src/agent/service.d.ts +1 -9
- package/dist/src/agent/service.js +3 -40
- package/dist/src/agent/service.js.map +1 -1
- package/dist/src/agent/service.types.d.ts +2 -2
- package/dist/src/agent/session/session-config-service.d.ts +11 -11
- package/dist/src/agent/session/session-config-service.js +14 -14
- package/dist/src/agent/session/session-config-service.js.map +1 -1
- package/dist/src/agent/session/session-inspector.js +3 -2
- package/dist/src/agent/session/session-inspector.js.map +1 -1
- package/dist/src/agent/starter-agents.js +12 -12
- package/dist/src/agent/starter-agents.js.map +1 -1
- package/dist/src/agent/tools/automation-tool.d.ts +14 -0
- package/dist/src/agent/tools/automation-tool.js +102 -0
- package/dist/src/agent/tools/automation-tool.js.map +1 -0
- package/dist/src/agent/tools/delegate-tool.js +1 -1
- package/dist/src/agent/tools/delegate-tool.js.map +1 -1
- package/dist/src/agent/tools/factory.d.ts +3 -3
- package/dist/src/agent/tools/factory.js +2 -2
- package/dist/src/agent/tools/factory.js.map +1 -1
- package/dist/src/agent/tools/index.d.ts +1 -1
- package/dist/src/agent/tools/index.js +2 -2
- package/dist/src/agent-manifest/resolver.d.ts +1 -0
- package/dist/src/agent-manifest/resolver.js +1 -0
- package/dist/src/agent-manifest/resolver.js.map +1 -1
- package/dist/src/agent-manifest/schema.d.ts +6 -0
- package/dist/src/agent-manifest/schema.js +12 -3
- package/dist/src/agent-manifest/schema.js.map +1 -1
- package/dist/src/ai-assist/text-assist.d.ts +1 -1
- package/dist/src/ai-assist/text-assist.js +56 -0
- package/dist/src/ai-assist/text-assist.js.map +1 -1
- package/dist/src/auth/profiles/store.js.map +1 -1
- package/dist/src/automations/api/routes.d.ts +3 -0
- package/dist/src/automations/api/routes.js +193 -0
- package/dist/src/automations/api/routes.js.map +1 -0
- package/dist/src/automations/domain/index.d.ts +3 -0
- package/dist/src/automations/domain/index.js +3 -0
- package/dist/src/automations/domain/schedule.d.ts +4 -0
- package/dist/src/automations/domain/schedule.js +37 -0
- package/dist/src/automations/domain/schedule.js.map +1 -0
- package/dist/src/automations/domain/types.d.ts +160 -0
- package/dist/src/automations/domain/validation.d.ts +370 -0
- package/dist/src/automations/domain/validation.js +149 -0
- package/dist/src/automations/domain/validation.js.map +1 -0
- package/dist/src/automations/draft/automation-draft-prompt.d.ts +26 -0
- package/dist/src/automations/draft/automation-draft-prompt.js +127 -0
- package/dist/src/automations/draft/automation-draft-prompt.js.map +1 -0
- package/dist/src/automations/draft/automation-draft-service.d.ts +12 -0
- package/dist/src/automations/draft/automation-draft-service.js +135 -0
- package/dist/src/automations/draft/automation-draft-service.js.map +1 -0
- package/dist/src/automations/draft/automation-draft-validator.d.ts +99 -0
- package/dist/src/automations/draft/automation-draft-validator.js +105 -0
- package/dist/src/automations/draft/automation-draft-validator.js.map +1 -0
- package/dist/src/automations/draft/automation-draft.types.d.ts +40 -0
- package/dist/src/automations/draft/index.d.ts +3 -0
- package/dist/src/automations/draft/index.js +3 -0
- package/dist/src/automations/index.d.ts +3 -0
- package/dist/src/automations/index.js +8 -0
- package/dist/src/automations/product-events.d.ts +5 -0
- package/dist/src/automations/product-events.js +21 -0
- package/dist/src/automations/product-events.js.map +1 -0
- package/dist/src/automations/service/action-executor.d.ts +9 -0
- package/dist/src/automations/service/action-executor.js +157 -0
- package/dist/src/automations/service/action-executor.js.map +1 -0
- package/dist/src/automations/service/automation-service.d.ts +54 -0
- package/dist/src/automations/service/automation-service.js +404 -0
- package/dist/src/automations/service/automation-service.js.map +1 -0
- package/dist/src/automations/service/index.d.ts +2 -0
- package/dist/src/automations/service/index.js +3 -0
- package/dist/src/automations/storage/automation-repository.d.ts +6 -0
- package/dist/src/automations/storage/automation-repository.js +61 -0
- package/dist/src/automations/storage/automation-repository.js.map +1 -0
- package/dist/src/automations/storage/automation-run-repository.d.ts +17 -0
- package/dist/src/automations/storage/automation-run-repository.js +130 -0
- package/dist/src/automations/storage/automation-run-repository.js.map +1 -0
- package/dist/src/automations/storage/index.d.ts +2 -0
- package/dist/src/automations/storage/index.js +3 -0
- package/dist/src/channels/plugin-types.d.ts +3 -0
- package/dist/src/chat-commands/builtins/thinking.js.map +1 -1
- package/dist/src/cli/command-catalog.js +0 -39
- package/dist/src/cli/command-catalog.js.map +1 -1
- package/dist/src/cli/command-loaders.js +0 -1
- package/dist/src/cli/command-loaders.js.map +1 -1
- package/dist/src/cli/command-manifest.js +0 -4
- package/dist/src/cli/command-manifest.js.map +1 -1
- package/dist/src/cli/commands/agents.js +7 -6
- package/dist/src/cli/commands/agents.js.map +1 -1
- package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
- package/dist/src/cli/commands/doctor/checks/{cron-health.d.ts → migrations.d.ts} +1 -1
- package/dist/src/cli/commands/doctor/checks/migrations.js +40 -0
- package/dist/src/cli/commands/doctor/checks/migrations.js.map +1 -0
- package/dist/src/cli/commands/doctor/flow.js +2 -2
- package/dist/src/cli/commands/doctor/flow.js.map +1 -1
- package/dist/src/cli/commands/gateway/call.js +2 -2
- package/dist/src/cli/commands/gateway/call.js.map +1 -1
- package/dist/src/cli/commands/gateway/lifecycle.js +1 -1
- package/dist/src/cli/commands/gateway/run-foreground.js +4 -2
- package/dist/src/cli/commands/gateway/run-foreground.js.map +1 -1
- package/dist/src/cli/commands/init.js +26 -8
- package/dist/src/cli/commands/init.js.map +1 -1
- package/dist/src/cli/commands/tui.js +24 -2
- package/dist/src/cli/commands/tui.js.map +1 -1
- package/dist/src/cli/utils/init-workspace-core.js +2 -0
- package/dist/src/cli/utils/init-workspace-core.js.map +1 -1
- package/dist/src/commands/agents.config.d.ts +9 -0
- package/dist/src/commands/agents.config.js +40 -2
- package/dist/src/commands/agents.config.js.map +1 -1
- package/dist/src/config/agent-profile.js +4 -3
- package/dist/src/config/agent-profile.js.map +1 -1
- package/dist/src/config/agent-typed-models.js.map +1 -1
- package/dist/src/config/config-surface.d.ts +3 -0
- package/dist/src/config/index.d.ts +0 -1
- package/dist/src/config/index.js +3 -3
- package/dist/src/config/index.js.map +1 -1
- package/dist/src/config/paths.d.ts +0 -9
- package/dist/src/config/paths.js +1 -14
- package/dist/src/config/paths.js.map +1 -1
- package/dist/src/config/profile.js +0 -1
- package/dist/src/config/profile.js.map +1 -1
- package/dist/src/config/rules.js +0 -5
- package/dist/src/config/rules.js.map +1 -1
- package/dist/src/config/schema.d.ts +13 -12
- package/dist/src/config/schema.js +22 -26
- package/dist/src/config/schema.js.map +1 -1
- package/dist/src/config/web-patch.d.ts +0 -12
- package/dist/src/config/web-patch.js +2 -29
- package/dist/src/config/web-patch.js.map +1 -1
- package/dist/src/extensions/api.d.ts +2 -0
- package/dist/src/extensions/api.js +10 -0
- package/dist/src/extensions/api.js.map +1 -1
- package/dist/src/extensions/extension-registry-impl.d.ts +4 -1
- package/dist/src/extensions/extension-registry-impl.js +8 -0
- package/dist/src/extensions/extension-registry-impl.js.map +1 -1
- package/dist/src/extensions/loader.d.ts +3 -3
- package/dist/src/extensions/loader.js +3 -3
- package/dist/src/extensions/loader.js.map +1 -1
- package/dist/src/extensions/sdk/testing.d.ts +2 -0
- package/dist/src/extensions/sdk/testing.js +7 -0
- package/dist/src/extensions/sdk/testing.js.map +1 -1
- package/dist/src/extensions/types/core.d.ts +10 -1
- package/dist/src/extensions/types/index.d.ts +1 -1
- package/dist/src/extensions/types/{phase4.d.ts → registration.d.ts} +2 -2
- package/dist/src/gateway/agent-builtin-tools.d.ts +1 -1
- package/dist/src/gateway/agent-builtin-tools.js +1 -1
- package/dist/src/gateway/agent-builtin-tools.js.map +1 -1
- package/dist/src/gateway/agents-admin.d.ts +1 -0
- package/dist/src/gateway/agents-admin.js +13 -15
- package/dist/src/gateway/agents-admin.js.map +1 -1
- package/dist/src/gateway/capability-presets-admin.d.ts +1 -0
- package/dist/src/gateway/capability-presets-admin.js +19 -10
- package/dist/src/gateway/capability-presets-admin.js.map +1 -1
- package/dist/src/gateway/dreaming-automation-reconciler.d.ts +11 -0
- package/dist/src/gateway/dreaming-automation-reconciler.js +105 -0
- package/dist/src/gateway/dreaming-automation-reconciler.js.map +1 -0
- package/dist/src/gateway/heartbeat/service.d.ts +0 -2
- package/dist/src/gateway/heartbeat/service.js +0 -7
- package/dist/src/gateway/heartbeat/service.js.map +1 -1
- package/dist/src/gateway/hono/lib/config-payload.d.ts +5 -6
- package/dist/src/gateway/hono/lib/config-payload.js +2 -2
- package/dist/src/gateway/hono/lib/config-payload.js.map +1 -1
- package/dist/src/gateway/hono/routes/agents.js.map +1 -1
- package/dist/src/gateway/hono/routes/config-patch/misc.d.ts +1 -1
- package/dist/src/gateway/hono/routes/config-patch/misc.js +12 -6
- package/dist/src/gateway/hono/routes/config-patch/misc.js.map +1 -1
- package/dist/src/gateway/hono/routes/dreaming.js +27 -37
- package/dist/src/gateway/hono/routes/dreaming.js.map +1 -1
- package/dist/src/gateway/hono/routes/home.d.ts +2 -2
- package/dist/src/gateway/hono/routes/home.js +34 -25
- package/dist/src/gateway/hono/routes/home.js.map +1 -1
- package/dist/src/gateway/hono/routes/lazy-bundles.js +10 -6
- package/dist/src/gateway/hono/routes/lazy-bundles.js.map +1 -1
- package/dist/src/gateway/hono/routes/migrations.d.ts +3 -0
- package/dist/src/gateway/hono/routes/migrations.js +35 -0
- package/dist/src/gateway/hono/routes/migrations.js.map +1 -0
- package/dist/src/gateway/hono/routes/public-gateway.js +2 -1
- package/dist/src/gateway/hono/routes/public-gateway.js.map +1 -1
- package/dist/src/gateway/hono/routes/sessions.js +14 -0
- package/dist/src/gateway/hono/routes/sessions.js.map +1 -1
- package/dist/src/gateway/run-loop.js +2 -0
- package/dist/src/gateway/run-loop.js.map +1 -1
- package/dist/src/gateway/security/operator-scopes.js +5 -1
- package/dist/src/gateway/security/operator-scopes.js.map +1 -1
- package/dist/src/gateway/service/config-coordinator.d.ts +4 -4
- package/dist/src/gateway/service/config-coordinator.js +14 -8
- package/dist/src/gateway/service/config-coordinator.js.map +1 -1
- package/dist/src/gateway/service/sessions-api.d.ts +2 -1
- package/dist/src/gateway/service/sessions-api.js +6 -1
- package/dist/src/gateway/service/sessions-api.js.map +1 -1
- package/dist/src/gateway/service.d.ts +7 -3
- package/dist/src/gateway/service.js +61 -27
- package/dist/src/gateway/service.js.map +1 -1
- package/dist/src/goals/goal-service.js +45 -4
- package/dist/src/goals/goal-service.js.map +1 -1
- package/dist/src/infra/update-restart.js +1 -1
- package/dist/src/migrations/config/default-capability-preset.d.ts +10 -0
- package/dist/src/migrations/config/default-capability-preset.js +135 -0
- package/dist/src/migrations/config/default-capability-preset.js.map +1 -0
- package/dist/src/migrations/index.d.ts +4 -0
- package/dist/src/migrations/index.js +4 -0
- package/dist/src/migrations/registry.d.ts +8 -0
- package/dist/src/migrations/registry.js +18 -0
- package/dist/src/migrations/registry.js.map +1 -0
- package/dist/src/migrations/runner.d.ts +17 -0
- package/dist/src/migrations/runner.js +191 -0
- package/dist/src/migrations/runner.js.map +1 -0
- package/dist/src/migrations/types.d.ts +34 -0
- package/dist/src/notes/service.js +24 -1
- package/dist/src/notes/service.js.map +1 -1
- package/dist/src/providers/model-registry.d.ts +0 -1
- package/dist/src/providers/model-registry.js +0 -3
- package/dist/src/providers/model-registry.js.map +1 -1
- package/dist/src/routing/resolve-tui-session-key.d.ts +3 -0
- package/dist/src/routing/resolve-tui-session-key.js +14 -3
- package/dist/src/routing/resolve-tui-session-key.js.map +1 -1
- package/dist/src/session/transcript-outline.d.ts +47 -0
- package/dist/src/session/transcript-outline.js +481 -0
- package/dist/src/session/transcript-outline.js.map +1 -0
- package/dist/src/storage/sqlite/index.d.ts +0 -2
- package/dist/src/storage/sqlite/index.js +1 -3
- package/dist/src/storage/sqlite/migrations/016_automations.sql +47 -0
- package/dist/src/storage/sqlite/migrations/017_automation_run_events.sql +14 -0
- package/dist/src/storage/sqlite/migrations/018_automation_safety.sql +1 -0
- package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
- package/dist/src/storage/sqlite/migrations/runner.js +3 -3
- package/dist/src/storage/sqlite/migrations/runner.js.map +1 -1
- package/dist/src/storage/sqlite/migrations/runner.ts +1 -1
- package/dist/src/storage/sqlite/schema.js +1 -1
- package/dist/src/storage/sqlite/schema.sql +56 -46
- package/dist/src/tui/backends/embedded-backend.d.ts +6 -0
- package/dist/src/tui/backends/embedded-backend.js +18 -7
- package/dist/src/tui/backends/embedded-backend.js.map +1 -1
- package/dist/src/tui/backends/gateway-sse-backend.d.ts +3 -0
- package/dist/src/tui/backends/gateway-sse-backend.js +14 -0
- package/dist/src/tui/backends/gateway-sse-backend.js.map +1 -1
- package/dist/src/tui/tui-backend.d.ts +4 -0
- package/dist/src/tui/tui-commands.d.ts +5 -0
- package/dist/src/tui/tui-commands.js +43 -0
- package/dist/src/tui/tui-commands.js.map +1 -1
- package/dist/src/tui/tui-transcript-tree.d.ts +1 -1
- package/dist/src/tui/tui-transcript-tree.js +17 -257
- package/dist/src/tui/tui-transcript-tree.js.map +1 -1
- package/dist/src/tui/tui-types.d.ts +2 -0
- package/dist/src/tui/tui-types.js.map +1 -1
- package/dist/src/tui/tui.js +7 -2
- package/dist/src/tui/tui.js.map +1 -1
- package/dist/src/workflows/domain/index.js +1 -1
- package/dist/src/workflows/domain/run.d.ts +7 -7
- package/dist/src/workflows/domain/run.js.map +1 -1
- package/dist/src/workflows/index.js +2 -2
- package/dist/src/workflows/service/workflow-run-service.d.ts +2 -0
- package/dist/src/workflows/service/workflow-run-service.js +31 -9
- package/dist/src/workflows/service/workflow-run-service.js.map +1 -1
- package/dist/src/workflows/service/workflow-run-service.types.d.ts +1 -1
- package/package.json +4 -2
- package/dist/gateway/static/root/assets/agents-BCxZbkOw.js +0 -2
- package/dist/gateway/static/root/assets/app-management-settings-panel-bxYJVJpx.js +0 -1
- package/dist/gateway/static/root/assets/appearance-settings-BCIykXlI.js +0 -1
- package/dist/gateway/static/root/assets/browser-settings-page-DRhKdn81.js +0 -8
- package/dist/gateway/static/root/assets/capability-presets-api-CorhiHlg.js +0 -1
- package/dist/gateway/static/root/assets/capability-presets-settings-panel-qFx9Jtce.js +0 -1
- package/dist/gateway/static/root/assets/channels-settings-BAwAkqIA.js +0 -1
- package/dist/gateway/static/root/assets/cn-JdwAhgNB.js +0 -1
- package/dist/gateway/static/root/assets/connectors-page-BQLcfitM.js +0 -2
- package/dist/gateway/static/root/assets/createLucideIcon-DPHK1VkS.js +0 -1
- package/dist/gateway/static/root/assets/cron-api-qGwmL-24.js +0 -1
- package/dist/gateway/static/root/assets/cron-dreaming-jobs-nCMWCf0p.js +0 -1
- package/dist/gateway/static/root/assets/cron-page-BBWMAj8-.js +0 -3
- package/dist/gateway/static/root/assets/dreaming-settings-Dw89Obml.js +0 -1
- package/dist/gateway/static/root/assets/format-cron-label-BsotZDO5.js +0 -2
- package/dist/gateway/static/root/assets/format-interval-label-BzxafKxR.js +0 -1
- package/dist/gateway/static/root/assets/gateway-settings-Cmwy58rS.js +0 -1
- package/dist/gateway/static/root/assets/goal-detail-page-l7mu5GWX.js +0 -1
- package/dist/gateway/static/root/assets/goals-settings-CYVY4NGp.js +0 -1
- package/dist/gateway/static/root/assets/heartbeat-config-api-DriO_CN9.js +0 -1
- package/dist/gateway/static/root/assets/heartbeat-settings-CUQTKxg7.js +0 -1
- package/dist/gateway/static/root/assets/index-C17Tsd_b.css +0 -1
- package/dist/gateway/static/root/assets/index-Cc41r16l.js +0 -191
- package/dist/gateway/static/root/assets/interval-presets-DFPCKW_W.js +0 -1
- package/dist/gateway/static/root/assets/keyboard-shortcuts-settings-CcVcqstx.js +0 -1
- package/dist/gateway/static/root/assets/messages-B1iSKjiw.js +0 -3
- package/dist/gateway/static/root/assets/models-hub-panel-BfLfcta8.js +0 -2
- package/dist/gateway/static/root/assets/note-detail-page-BjwOQBfT.js +0 -2
- package/dist/gateway/static/root/assets/notes-page-DktdBiwB.js +0 -1
- package/dist/gateway/static/root/assets/remote-access-hub-rfVx96fq.js +0 -1
- package/dist/gateway/static/root/assets/schedule-field-CUCKODde.js +0 -1
- package/dist/gateway/static/root/assets/sessions-page-DbtMFuuH.js +0 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-5re5gAnP.js +0 -1
- package/dist/gateway/static/root/assets/settings-page-D-WMyLlj.js +0 -1
- package/dist/gateway/static/root/assets/setup-status-panel-Cl-DEJAU.js +0 -1
- package/dist/gateway/static/root/assets/shares-settings-CyPVvbLt.js +0 -1
- package/dist/gateway/static/root/assets/skill-reload-api-CleTH1oz.js +0 -1
- package/dist/gateway/static/root/assets/skills-page-Ck8hdXqR.js +0 -2
- package/dist/gateway/static/root/assets/system-settings-panel-DI-LN_8G.js +0 -1
- package/dist/gateway/static/root/assets/typed-models-lib-kX9duch4.js +0 -1
- package/dist/gateway/static/root/assets/user-profile-settings-panel-B-UFPMXy.js +0 -1
- package/dist/gateway/static/root/assets/utils-Dm0hKalR.js +0 -1
- package/dist/gateway/static/root/assets/workflows-page-BtFGp2y_.js +0 -18
- package/dist/src/agent/fallback/error.d.ts +0 -22
- package/dist/src/agent/fallback/error.js +0 -32
- package/dist/src/agent/fallback/error.js.map +0 -1
- package/dist/src/agent/fallback/index.d.ts +0 -5
- package/dist/src/agent/fallback/index.js +0 -9
- package/dist/src/agent/fallback/index.js.map +0 -1
- package/dist/src/agent/orchestration/run-agent-turn-with-fallbacks.d.ts +0 -29
- package/dist/src/agent/orchestration/run-agent-turn-with-fallbacks.js +0 -76
- package/dist/src/agent/orchestration/run-agent-turn-with-fallbacks.js.map +0 -1
- package/dist/src/agent/service/reconcile-dreaming-cron.d.ts +0 -6
- package/dist/src/agent/service/reconcile-dreaming-cron.js +0 -84
- package/dist/src/agent/service/reconcile-dreaming-cron.js.map +0 -1
- package/dist/src/agent/tools/cronjob-tool.d.ts +0 -29
- package/dist/src/agent/tools/cronjob-tool.js +0 -274
- package/dist/src/agent/tools/cronjob-tool.js.map +0 -1
- package/dist/src/cli/commands/cron-cli.d.ts +0 -2
- package/dist/src/cli/commands/cron-cli.js +0 -15
- package/dist/src/cli/commands/cron-cli.js.map +0 -1
- package/dist/src/cli/commands/cron.d.ts +0 -4
- package/dist/src/cli/commands/cron.js +0 -188
- package/dist/src/cli/commands/cron.js.map +0 -1
- package/dist/src/cli/commands/doctor/checks/cron-health.js +0 -35
- package/dist/src/cli/commands/doctor/checks/cron-health.js.map +0 -1
- package/dist/src/cron/execution-types.d.ts +0 -42
- package/dist/src/cron/executor.d.ts +0 -67
- package/dist/src/cron/executor.js +0 -669
- package/dist/src/cron/executor.js.map +0 -1
- package/dist/src/cron/index.d.ts +0 -7
- package/dist/src/cron/index.js +0 -7
- package/dist/src/cron/job-content.d.ts +0 -5
- package/dist/src/cron/job-content.js +0 -15
- package/dist/src/cron/job-content.js.map +0 -1
- package/dist/src/cron/run-log-store.d.ts +0 -12
- package/dist/src/cron/run-log-store.js +0 -58
- package/dist/src/cron/run-log-store.js.map +0 -1
- package/dist/src/cron/schedule.d.ts +0 -10
- package/dist/src/cron/schedule.js +0 -85
- package/dist/src/cron/schedule.js.map +0 -1
- package/dist/src/cron/service.d.ts +0 -58
- package/dist/src/cron/service.js +0 -419
- package/dist/src/cron/service.js.map +0 -1
- package/dist/src/cron/types.d.ts +0 -183
- package/dist/src/cron/validation.d.ts +0 -500
- package/dist/src/cron/validation.js +0 -192
- package/dist/src/cron/validation.js.map +0 -1
- package/dist/src/cron/workflow-run-completion.d.ts +0 -23
- package/dist/src/cron/workflow-run-completion.js +0 -72
- package/dist/src/cron/workflow-run-completion.js.map +0 -1
- package/dist/src/extensions/types/phase4.js +0 -1
- package/dist/src/gateway/hono/routes/cron.d.ts +0 -3
- package/dist/src/gateway/hono/routes/cron.js +0 -109
- package/dist/src/gateway/hono/routes/cron.js.map +0 -1
- package/dist/src/storage/sqlite/cron-job-repository.d.ts +0 -6
- package/dist/src/storage/sqlite/cron-job-repository.js +0 -70
- package/dist/src/storage/sqlite/cron-job-repository.js.map +0 -1
- package/dist/src/storage/sqlite/cron-run-repository.d.ts +0 -5
- package/dist/src/storage/sqlite/cron-run-repository.js +0 -96
- package/dist/src/storage/sqlite/cron-run-repository.js.map +0 -1
- /package/dist/src/{cron → automations/domain}/types.js +0 -0
- /package/dist/src/{config/defaults.d.ts → automations/draft/automation-draft.types.js} +0 -0
- /package/dist/src/{config/defaults.js → extensions/types/registration.js} +0 -0
- /package/dist/src/{cron/execution-types.js → migrations/types.js} +0 -0
|
@@ -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":";;;AAaA,SAAS,kBAAkB,KAAqB;CAC9C,MAAM,UAAU,IAAI,MAAM;AAC1B,KAAI,QAAQ,WAAW,IAAI,IAAI,QAAQ,SAAS,IAAI,CAAE,QAAO;CAC7D,MAAM,QAAQ,QAAQ,QAAQ,IAAI;CAClC,MAAM,MAAM,QAAQ,YAAY,IAAI;AACpC,KAAI,SAAS,KAAK,MAAM,MAAO,QAAO,QAAQ,MAAM,OAAO,MAAM,EAAE;AACnE,OAAM,IAAI,MAAM,6CAA6C;;AAG/D,SAAS,YAAY,OAA0B;AAC7C,QAAO,MAAM,QAAQ,MAAM,GAAG,MAAM,KAAK,SAAS,OAAO,KAAK,CAAC,CAAC,OAAO,QAAQ,GAAG,EAAE;;AAGtF,SAAgB,8BAA8B,KAAuC;CACnF,MAAM,OAAO,kBAAkB,IAAI;CACnC,MAAM,SAAS,KAAK,MAAM,KAAK;AAE/B,QAAO;EACL,YAFiB,uBAAuB,MAAM,OAAO,WAE3C;EACV,aAAa,OAAO,OAAO,eAAe,GAAG;EAC7C,aAAa,YAAY,OAAO,YAAY;EAC5C,OAAO,YAAY,OAAO,MAAM;EACjC;;AAGH,SAAgB,6BACd,OACA,gBACA;AACA,QAAO;EACL,SAAS,YAAY;EACrB,YAAY,MAAM;EAClB,aAAa,MAAM;EACnB,aAAa,MAAM;EACnB,OAAO,MAAM;EACb,YAAY,mBAAmB,MAAM,WAAW;EAChD;EACD;;AAGH,SAAgB,oCACd,KACA,gBAC+B;CAC/B,MAAM,OAAO,kBAAkB,IAAI;CACnC,MAAM,SAAS,KAAK,MAAM,KAAK;CAO/B,MAAM,QAAQ,uBAAuB,MAAM,OAAO,MAAM;AACxD,QAAO;EACL,SAAS,YAAY;EACrB;EACA,aAAa,OAAO,OAAO,eAAe,GAAG;EAC7C,gBAAgB,OAAO,OAAO,kBAAkB,GAAG;EACnD,OAAO,YAAY,OAAO,MAAM;EAChC,kBAAkB,OAAO,qBAAqB,SAAS,yBAAyB,MAAM;EACtF;EACD;;AAGH,SAAgB,mBAAmB,OAAoD;CACrF,MAAM,aAAa,uBAAuB,MAAM,MAAM;CACtD,MAAM,cAAwB,EAAE;CAChC,MAAM,wBAAkC,EAAE;CAE1C,MAAM,iBAAiB,iBAAiB,WAAW,QAAQ;CAC3D,MAAM,gBAAgB,gBAAgB,WAAW,OAAO;AAExD,KAAI,WAAW,OAAO,SAAS,WAAW,+CAA+C,KAAK,WAAW,OAAO,YAAY,CAC1H,uBAAsB,KAAK,mEAAmE;AAEhG,KAAI,WAAW,UAAU,SAAS,WAAW;AAC3C,cAAY,KAAK,8DAA8D;AAC/E,wBAAsB,KAAK,8DAA8D;;CAE3F,MAAM,aAAa,WAAW,QAAQ,QAAQ;AAC9C,KAAI,eAAe,eACjB,aAAY,KAAK,mFAAmF;UAC3F,eAAe,mBACxB,aAAY,KAAK,iFAAiF;MAC7F;AACL,cAAY,KAAK,yEAAyE;AAC1F,wBAAsB,KAAK,+DAA+D;;AAE5F,KAAI,WAAW,QAAQ,SAAS,UAC9B,aAAY,KAAK,yEAAyE;AAE5F,KAAI,WAAW,QAAQ,SAAS,QAC9B,aAAY,KAAK,oFAAoF;AAGvG,QAAO;EACL;EACA;EACA;EACA;EACA,WAAW,WAAW,QAAQ,SAAS;EACvC,qBAAqB,WAAW,QAAQ,SAAS,WAAW,KAAA,IAAY;EACzE;;AAGH,SAAS,iBAAiB,SAAmD;AAC3E,KAAI,QAAQ,SAAS,SAAU,QAAO;AACtC,KAAI,QAAQ,SAAS,UAAW,QAAO;AACvC,KAAI,QAAQ,SAAS,SAAS;EAC5B,MAAM,SAAS,QAAQ,SAAS,SAAS,QAAQ,WAAW;AAC5D,SAAO,yBAAyB,QAAQ,YAAY,OAAO;;CAE7D,MAAM,WAAW,QAAQ;AACzB,KAAI,SAAS,SAAS,WAAY,QAAO,cAAc,KAAK,MAAM,SAAS,UAAU,IAAM,CAAC;AAC5F,KAAI,SAAS,SAAS,OAAQ,QAAO,gBAAgB,SAAS,GAAG;AACjE,QAAO,yBAAyB,SAAS,KAAK;;AAGhD,SAAS,gBAAgB,QAAiD;AACxE,KAAI,OAAO,SAAS,WAAY,QAAO,mBAAmB,OAAO,WAAW;AAC5E,QAAO,OAAO,UAAU,cAAc,OAAO,QAAQ,KAAK;;AAG5D,SAAS,yBAAyB,OAAuC;AACvE,KAAI,MAAM,QAAQ,SAAS,aAAc,QAAO;AAChD,KAAI,MAAM,UAAU,SAAS,UAAW,QAAO;AAC/C,KAAI,MAAM,SAAS,SAAS,UAAW,QAAO;AAC9C,KAAI,MAAM,QAAQ,SAAS,QACzB,QAAO,+CAA+C,KAAK,MAAM,OAAO,YAAY;AAEtF,QAAO"}
|
|
@@ -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
|
+
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,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
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { init_agent_scope, normalizeAgentId } from "../../agent/agent-scope.js";
|
|
2
|
+
import { buildSessionKey, init_session_key } from "../../routing/session-key.js";
|
|
3
|
+
import { createLogger } from "../../utils/logger/index.js";
|
|
4
|
+
import { init_logger } from "../../utils/logger.js";
|
|
5
|
+
import crypto from "node:crypto";
|
|
6
|
+
//#region src/automations/service/action-executor.ts
|
|
7
|
+
init_agent_scope();
|
|
8
|
+
init_session_key();
|
|
9
|
+
init_logger();
|
|
10
|
+
const log = createLogger("Automation:ActionExecutor");
|
|
11
|
+
const DEFAULT_TIMEOUT_MS = 18e4;
|
|
12
|
+
function withTimeout(promise, timeoutMs, signal) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
if (signal.aborted) {
|
|
15
|
+
reject(/* @__PURE__ */ new Error("Automation run was cancelled"));
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const timer = setTimeout(() => reject(/* @__PURE__ */ new Error(`Automation timed out after ${timeoutMs}ms`)), timeoutMs);
|
|
19
|
+
const onAbort = () => {
|
|
20
|
+
clearTimeout(timer);
|
|
21
|
+
reject(/* @__PURE__ */ new Error("Automation run was cancelled"));
|
|
22
|
+
};
|
|
23
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
24
|
+
promise.then((value) => {
|
|
25
|
+
clearTimeout(timer);
|
|
26
|
+
signal.removeEventListener("abort", onAbort);
|
|
27
|
+
resolve(value);
|
|
28
|
+
}, (err) => {
|
|
29
|
+
clearTimeout(timer);
|
|
30
|
+
signal.removeEventListener("abort", onAbort);
|
|
31
|
+
reject(err);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
var AutomationActionExecutor = class {
|
|
36
|
+
deps = {};
|
|
37
|
+
setDeps(deps) {
|
|
38
|
+
this.deps = {
|
|
39
|
+
...this.deps,
|
|
40
|
+
...deps
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
async execute(automation, run, signal) {
|
|
44
|
+
const timeoutMs = (automation.action.timeoutSeconds ?? automation.reliability?.timeoutSeconds ?? 0) > 0 ? (automation.action.timeoutSeconds ?? automation.reliability?.timeoutSeconds) * 1e3 : DEFAULT_TIMEOUT_MS;
|
|
45
|
+
return withTimeout(this.executeWithoutTimeout(automation, run, signal), timeoutMs, signal).catch((err) => {
|
|
46
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
47
|
+
return {
|
|
48
|
+
status: message.toLowerCase().includes("cancelled") ? "cancelled" : message.toLowerCase().includes("timed out") ? "timeout" : "failed",
|
|
49
|
+
error: message
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
async executeWithoutTimeout(automation, run, signal) {
|
|
54
|
+
if (signal.aborted) return {
|
|
55
|
+
status: "cancelled",
|
|
56
|
+
error: "Automation run was cancelled"
|
|
57
|
+
};
|
|
58
|
+
if (automation.action.kind === "workflow") return this.executeWorkflow(automation, automation.action, run);
|
|
59
|
+
return this.executeAgent(automation, automation.action);
|
|
60
|
+
}
|
|
61
|
+
async executeAgent(automation, action) {
|
|
62
|
+
const agentService = this.deps.agentService;
|
|
63
|
+
if (!agentService?.turnDispatcher?.processDirect) return {
|
|
64
|
+
status: "failed",
|
|
65
|
+
error: "Agent service is not available"
|
|
66
|
+
};
|
|
67
|
+
const sessionKey = buildSessionKey({
|
|
68
|
+
agentId: normalizeAgentId(action.agentId || this.deps.getDefaultAgentId?.() || "main"),
|
|
69
|
+
source: "automation",
|
|
70
|
+
accountId: "default",
|
|
71
|
+
peerKind: "dm",
|
|
72
|
+
peerId: `${automation.id}-${crypto.randomUUID().slice(0, 8)}`
|
|
73
|
+
});
|
|
74
|
+
await agentService.sessionConfig?.applyAutomationWorkingDirectory?.(sessionKey, action.workingDirectory);
|
|
75
|
+
if (agentService.sessionConfig?.applyAutomationModelOverride) {
|
|
76
|
+
if (!await agentService.sessionConfig.applyAutomationModelOverride(sessionKey, action.model) && action.model) log.warn({
|
|
77
|
+
automationId: automation.id,
|
|
78
|
+
sessionKey,
|
|
79
|
+
model: action.model
|
|
80
|
+
}, "Automation model override invalid; using agent default");
|
|
81
|
+
}
|
|
82
|
+
const response = await agentService.turnDispatcher.processDirect(buildSafetyInstruction(automation, action.instruction), sessionKey);
|
|
83
|
+
const model = agentService.getModelForSession?.(sessionKey);
|
|
84
|
+
return {
|
|
85
|
+
status: "succeeded",
|
|
86
|
+
summary: response.slice(0, 500),
|
|
87
|
+
sessionKey,
|
|
88
|
+
model
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
async executeWorkflow(automation, action, run) {
|
|
92
|
+
const safetyMode = automation.safety?.mode ?? "auto_apply";
|
|
93
|
+
if (safetyMode === "suggest_only") return {
|
|
94
|
+
status: "succeeded",
|
|
95
|
+
summary: `Suggest only: workflow ${action.workflowId} was not started. Review the automation and upgrade safety mode to run it automatically.`
|
|
96
|
+
};
|
|
97
|
+
if (safetyMode === "ask_before_apply") return {
|
|
98
|
+
status: "succeeded",
|
|
99
|
+
summary: `Ask before applying: workflow ${action.workflowId} is ready, but was not started automatically. Upgrade to Auto apply when you trust this automation.`
|
|
100
|
+
};
|
|
101
|
+
const workflowRunService = this.deps.workflowRunService;
|
|
102
|
+
if (!workflowRunService) return {
|
|
103
|
+
status: "failed",
|
|
104
|
+
error: "Workflow service is not available"
|
|
105
|
+
};
|
|
106
|
+
const agentId = normalizeAgentId(action.agentId || this.deps.getDefaultAgentId?.() || "main");
|
|
107
|
+
const idempotencyKey = `automation:${automation.id}:${run.id}`;
|
|
108
|
+
const result = await workflowRunService.startWorkflowRun({
|
|
109
|
+
agentId,
|
|
110
|
+
definitionId: action.workflowId,
|
|
111
|
+
input: action.input,
|
|
112
|
+
inputEnvelope: action.inputEnvelope,
|
|
113
|
+
goal: action.goal,
|
|
114
|
+
concurrency: action.concurrency,
|
|
115
|
+
maxSubagents: action.maxSubagents,
|
|
116
|
+
source: {
|
|
117
|
+
kind: "automation",
|
|
118
|
+
automationId: automation.id,
|
|
119
|
+
runId: run.id
|
|
120
|
+
},
|
|
121
|
+
idempotencyKey
|
|
122
|
+
});
|
|
123
|
+
if (result.ok === false) return {
|
|
124
|
+
status: "failed",
|
|
125
|
+
error: result.message
|
|
126
|
+
};
|
|
127
|
+
return {
|
|
128
|
+
status: "succeeded",
|
|
129
|
+
summary: `Started workflow run ${result.runId}`,
|
|
130
|
+
sessionKey: result.sessionKey,
|
|
131
|
+
workflowRunId: result.runId
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
function buildSafetyInstruction(automation, instruction) {
|
|
136
|
+
const mode = automation.safety?.mode ?? "auto_apply";
|
|
137
|
+
if (mode === "suggest_only") return [
|
|
138
|
+
"Automation safety mode: Suggest only.",
|
|
139
|
+
"Only analyze the situation and produce a concise recommendation.",
|
|
140
|
+
"Do not modify files, notes, goals, workflows, external systems, or persistent state.",
|
|
141
|
+
"If a change seems useful, describe the exact change for the user to review.",
|
|
142
|
+
"",
|
|
143
|
+
instruction
|
|
144
|
+
].join("\n");
|
|
145
|
+
if (mode === "ask_before_apply") return [
|
|
146
|
+
"Automation safety mode: Ask before applying.",
|
|
147
|
+
"Draft the proposed change or action and clearly ask for user confirmation before applying anything.",
|
|
148
|
+
"Do not perform irreversible or external side effects unless the user has explicitly approved them in this run.",
|
|
149
|
+
"",
|
|
150
|
+
instruction
|
|
151
|
+
].join("\n");
|
|
152
|
+
return instruction;
|
|
153
|
+
}
|
|
154
|
+
//#endregion
|
|
155
|
+
export { AutomationActionExecutor };
|
|
156
|
+
|
|
157
|
+
//# sourceMappingURL=action-executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action-executor.js","names":[],"sources":["../../../../src/automations/service/action-executor.ts"],"sourcesContent":["import crypto from 'node:crypto';\n\nimport { DEFAULT_AGENT_ID, normalizeAgentId } from '../../agent/agent-scope.js';\nimport { buildSessionKey } from '../../routing/session-key.js';\nimport { createLogger } from '../../utils/logger.js';\nimport type {\n Automation,\n AutomationAction,\n AutomationActionOutcome,\n AutomationDeps,\n AutomationRun,\n} from '../domain/types.js';\n\nconst log = createLogger('Automation:ActionExecutor');\n\nconst DEFAULT_TIMEOUT_MS = 180_000;\n\nfunction withTimeout<T>(promise: Promise<T>, timeoutMs: number, signal: AbortSignal): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n if (signal.aborted) {\n reject(new Error('Automation run was cancelled'));\n return;\n }\n const timer = setTimeout(() => reject(new Error(`Automation timed out after ${timeoutMs}ms`)), timeoutMs);\n const onAbort = () => {\n clearTimeout(timer);\n reject(new Error('Automation run was cancelled'));\n };\n signal.addEventListener('abort', onAbort, { once: true });\n promise.then(\n (value) => {\n clearTimeout(timer);\n signal.removeEventListener('abort', onAbort);\n resolve(value);\n },\n (err) => {\n clearTimeout(timer);\n signal.removeEventListener('abort', onAbort);\n reject(err);\n },\n );\n });\n}\n\nexport class AutomationActionExecutor {\n private deps: AutomationDeps = {};\n\n setDeps(deps: AutomationDeps): void {\n this.deps = { ...this.deps, ...deps };\n }\n\n async execute(\n automation: Automation,\n run: AutomationRun,\n signal: AbortSignal,\n ): Promise<AutomationActionOutcome> {\n const timeoutMs =\n (automation.action.timeoutSeconds ?? automation.reliability?.timeoutSeconds ?? 0) > 0\n ? (automation.action.timeoutSeconds ?? automation.reliability?.timeoutSeconds)! * 1000\n : DEFAULT_TIMEOUT_MS;\n\n return withTimeout(this.executeWithoutTimeout(automation, run, signal), timeoutMs, signal).catch((err) => {\n const message = err instanceof Error ? err.message : String(err);\n return {\n status: message.toLowerCase().includes('cancelled')\n ? 'cancelled'\n : message.toLowerCase().includes('timed out')\n ? 'timeout'\n : 'failed',\n error: message,\n };\n });\n }\n\n private async executeWithoutTimeout(\n automation: Automation,\n run: AutomationRun,\n signal: AbortSignal,\n ): Promise<AutomationActionOutcome> {\n if (signal.aborted) {\n return { status: 'cancelled', error: 'Automation run was cancelled' };\n }\n if (automation.action.kind === 'workflow') {\n return this.executeWorkflow(automation, automation.action, run);\n }\n return this.executeAgent(automation, automation.action);\n }\n\n private async executeAgent(\n automation: Automation,\n action: Extract<AutomationAction, { kind: 'agent' }>,\n ): Promise<AutomationActionOutcome> {\n const agentService = this.deps.agentService;\n if (!agentService?.turnDispatcher?.processDirect) {\n return { status: 'failed', error: 'Agent service is not available' };\n }\n const agentId = normalizeAgentId(\n action.agentId || this.deps.getDefaultAgentId?.() || DEFAULT_AGENT_ID,\n );\n const sessionKey = buildSessionKey({\n agentId,\n source: 'automation',\n accountId: 'default',\n peerKind: 'dm',\n peerId: `${automation.id}-${crypto.randomUUID().slice(0, 8)}`,\n });\n\n await agentService.sessionConfig?.applyAutomationWorkingDirectory?.(\n sessionKey,\n action.workingDirectory,\n );\n if (agentService.sessionConfig?.applyAutomationModelOverride) {\n const ok = await agentService.sessionConfig.applyAutomationModelOverride(sessionKey, action.model);\n if (!ok && action.model) {\n log.warn(\n { automationId: automation.id, sessionKey, model: action.model },\n 'Automation model override invalid; using agent default',\n );\n }\n }\n\n const response = await agentService.turnDispatcher.processDirect(\n buildSafetyInstruction(automation, action.instruction),\n sessionKey,\n );\n const model = agentService.getModelForSession?.(sessionKey);\n return {\n status: 'succeeded',\n summary: response.slice(0, 500),\n sessionKey,\n model,\n };\n }\n\n private async executeWorkflow(\n automation: Automation,\n action: Extract<AutomationAction, { kind: 'workflow' }>,\n run: AutomationRun,\n ): Promise<AutomationActionOutcome> {\n const safetyMode = automation.safety?.mode ?? 'auto_apply';\n if (safetyMode === 'suggest_only') {\n return {\n status: 'succeeded',\n summary: `Suggest only: workflow ${action.workflowId} was not started. Review the automation and upgrade safety mode to run it automatically.`,\n };\n }\n if (safetyMode === 'ask_before_apply') {\n return {\n status: 'succeeded',\n summary: `Ask before applying: workflow ${action.workflowId} is ready, but was not started automatically. Upgrade to Auto apply when you trust this automation.`,\n };\n }\n const workflowRunService = this.deps.workflowRunService;\n if (!workflowRunService) {\n return { status: 'failed', error: 'Workflow service is not available' };\n }\n const agentId = normalizeAgentId(\n action.agentId || this.deps.getDefaultAgentId?.() || DEFAULT_AGENT_ID,\n );\n const idempotencyKey = `automation:${automation.id}:${run.id}`;\n const result = await workflowRunService.startWorkflowRun({\n agentId,\n definitionId: action.workflowId,\n input: action.input,\n inputEnvelope: action.inputEnvelope,\n goal: action.goal,\n concurrency: action.concurrency,\n maxSubagents: action.maxSubagents,\n source: { kind: 'automation', automationId: automation.id, runId: run.id },\n idempotencyKey,\n });\n if (result.ok === false) {\n return { status: 'failed', error: result.message };\n }\n return {\n status: 'succeeded',\n summary: `Started workflow run ${result.runId}`,\n sessionKey: result.sessionKey,\n workflowRunId: result.runId,\n };\n }\n}\n\nfunction buildSafetyInstruction(automation: Automation, instruction: string): string {\n const mode = automation.safety?.mode ?? 'auto_apply';\n if (mode === 'suggest_only') {\n return [\n 'Automation safety mode: Suggest only.',\n 'Only analyze the situation and produce a concise recommendation.',\n 'Do not modify files, notes, goals, workflows, external systems, or persistent state.',\n 'If a change seems useful, describe the exact change for the user to review.',\n '',\n instruction,\n ].join('\\n');\n }\n if (mode === 'ask_before_apply') {\n return [\n 'Automation safety mode: Ask before applying.',\n 'Draft the proposed change or action and clearly ask for user confirmation before applying anything.',\n 'Do not perform irreversible or external side effects unless the user has explicitly approved them in this run.',\n '',\n instruction,\n ].join('\\n');\n }\n return instruction;\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Automation, AutomationDeps, AutomationEvent, AutomationMetrics, AutomationProductEventRun, AutomationRun, AutomationRunEvent } from '../domain/types.js';
|
|
2
|
+
import { type CreateAutomationInput, type UpdateAutomationInput } from '../domain/validation.js';
|
|
3
|
+
export declare class AutomationAlreadyRunningError extends Error {
|
|
4
|
+
readonly automationId: string;
|
|
5
|
+
readonly runningRunId?: string;
|
|
6
|
+
constructor(automationId: string, runningRunId?: string);
|
|
7
|
+
}
|
|
8
|
+
export declare class AutomationService {
|
|
9
|
+
private readonly executor;
|
|
10
|
+
private timer;
|
|
11
|
+
private stopped;
|
|
12
|
+
private runningScheduler;
|
|
13
|
+
private deps;
|
|
14
|
+
private maxConcurrentRuns;
|
|
15
|
+
private readonly activeRuns;
|
|
16
|
+
setDeps(deps: AutomationDeps): void;
|
|
17
|
+
initialize(options?: {
|
|
18
|
+
maxConcurrentRuns?: number;
|
|
19
|
+
}): Promise<void>;
|
|
20
|
+
stop(): Promise<void>;
|
|
21
|
+
create(input: CreateAutomationInput): Promise<Automation>;
|
|
22
|
+
list(): Promise<Automation[]>;
|
|
23
|
+
get(id: string): Promise<Automation | null>;
|
|
24
|
+
update(id: string, patch: UpdateAutomationInput): Promise<Automation | null>;
|
|
25
|
+
remove(id: string): Promise<boolean>;
|
|
26
|
+
pause(id: string): Promise<Automation | null>;
|
|
27
|
+
resume(id: string): Promise<Automation | null>;
|
|
28
|
+
runNow(id: string): Promise<AutomationRun>;
|
|
29
|
+
rerunFromRun(runId: string): Promise<AutomationRun>;
|
|
30
|
+
triggerEvent(event: AutomationEvent): Promise<AutomationRun[]>;
|
|
31
|
+
listRuns(options?: {
|
|
32
|
+
automationId?: string;
|
|
33
|
+
limit?: number;
|
|
34
|
+
}): Promise<AutomationRun[]>;
|
|
35
|
+
listRunsForProductEvent(options: {
|
|
36
|
+
eventType: string;
|
|
37
|
+
source?: string;
|
|
38
|
+
payloadKey?: string;
|
|
39
|
+
payloadValue?: string;
|
|
40
|
+
limit?: number;
|
|
41
|
+
}): Promise<AutomationProductEventRun[]>;
|
|
42
|
+
getRun(runId: string): Promise<AutomationRun | null>;
|
|
43
|
+
listRunEvents(runId: string): Promise<AutomationRunEvent[]>;
|
|
44
|
+
cancelRun(runId: string): Promise<boolean>;
|
|
45
|
+
getMetrics(): Promise<AutomationMetrics>;
|
|
46
|
+
private recomputeNextRuns;
|
|
47
|
+
private armTimer;
|
|
48
|
+
private onTimer;
|
|
49
|
+
private startRun;
|
|
50
|
+
private executeRun;
|
|
51
|
+
private appendRunEvent;
|
|
52
|
+
private finishAutomationRun;
|
|
53
|
+
private postAfterRunWebhook;
|
|
54
|
+
}
|