@octopi-agent/engine 0.70.7 → 0.90.11
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/LICENSE +201 -201
- package/NOTICE +7 -7
- package/README.md +64 -26
- package/dist/config-schema/agent.d.ts +89 -1
- package/dist/config-schema/agent.js +81 -5
- package/dist/config-schema/context.d.ts +24 -5
- package/dist/config-schema/context.js +28 -1
- package/dist/config-schema/engine.d.ts +205 -13
- package/dist/config-schema/engine.js +31 -2
- package/dist/config-schema/governance.d.ts +95 -0
- package/dist/config-schema/governance.js +93 -1
- package/dist/config-schema/models.d.ts +3 -3
- package/dist/config-schema/observability.d.ts +6 -0
- package/dist/config-schema/observability.js +16 -0
- package/dist/config-schema/run.d.ts +10 -0
- package/dist/config-schema/run.js +18 -0
- package/dist/config-schema/shared.d.ts +13 -0
- package/dist/config-schema/shared.js +22 -0
- package/dist/config-schema/substrate.d.ts +2 -2
- package/dist/config-schema/subsystems.d.ts +1 -1
- package/dist/config-schema/subsystems.js +2 -1
- package/dist/config.d.ts +201 -8
- package/dist/config.js +105 -3
- package/dist/harness/activation/compiler.js +3 -0
- package/dist/harness/activation/runtime.d.ts +7 -0
- package/dist/harness/activation/runtime.js +60 -2
- package/dist/harness/activation/sources/agent-signal.d.ts +11 -0
- package/dist/harness/activation/sources/agent-signal.js +33 -0
- package/dist/harness/activation/types.d.ts +6 -1
- package/dist/harness/agent/builder.d.ts +50 -5
- package/dist/harness/agent/builder.js +189 -59
- package/dist/harness/agent/config-bridge.d.ts +33 -25
- package/dist/harness/agent/config-bridge.js +84 -291
- package/dist/harness/agent/index.d.ts +3 -1
- package/dist/harness/agent/index.js +2 -1
- package/dist/harness/agent/tool-purpose.d.ts +46 -0
- package/dist/harness/agent/tool-purpose.js +127 -0
- package/dist/harness/agent/wire-agent-builder.d.ts +133 -0
- package/dist/harness/agent/wire-agent-builder.js +370 -0
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.d.ts +11 -1
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.js +11 -1
- package/dist/harness/collaboration/autonomous-subsystem/loader.d.ts +13 -0
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +16 -1
- package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +8 -1
- package/dist/harness/collaboration/autonomous-subsystem/runtime.js +17 -9
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.d.ts +12 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.js +19 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/session-lifecycle-bridge.d.ts +6 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/session-lifecycle-bridge.js +24 -7
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.d.ts +5 -2
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +11 -3
- package/dist/harness/collaboration/autonomous-subsystem/think/index.d.ts +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/think/index.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/think/llm-port.d.ts +7 -4
- package/dist/harness/collaboration/autonomous-subsystem/think/llm-port.js +8 -9
- package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.d.ts +36 -10
- package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.js +60 -7
- package/dist/harness/collaboration/delegation/child-run.d.ts +144 -0
- package/dist/harness/collaboration/delegation/child-run.js +241 -0
- package/dist/harness/collaboration/delegation/index.d.ts +26 -0
- package/dist/harness/collaboration/delegation/index.js +25 -0
- package/dist/harness/collaboration/delegation/notifier.d.ts +46 -0
- package/dist/harness/collaboration/delegation/notifier.js +84 -0
- package/dist/harness/collaboration/delegation/registry-types.d.ts +200 -0
- package/dist/harness/collaboration/delegation/registry-types.js +61 -0
- package/dist/harness/collaboration/delegation/registry.d.ts +110 -0
- package/dist/harness/collaboration/delegation/registry.js +220 -0
- package/dist/harness/collaboration/delegation/service.d.ts +249 -0
- package/dist/harness/collaboration/delegation/service.js +499 -0
- package/dist/harness/collaboration/delegation/store.d.ts +155 -0
- package/dist/harness/collaboration/delegation/store.js +271 -0
- package/dist/harness/collaboration/delegation/transport.d.ts +73 -0
- package/dist/harness/collaboration/delegation/transport.js +61 -0
- package/dist/harness/collaboration/delegation/types.d.ts +231 -0
- package/dist/harness/collaboration/delegation/types.js +70 -0
- package/dist/harness/collaboration/delegation/wiring.d.ts +111 -0
- package/dist/harness/collaboration/delegation/wiring.js +145 -0
- package/dist/harness/collaboration/orchestration/index.d.ts +11 -13
- package/dist/harness/collaboration/orchestration/index.js +11 -11
- package/dist/harness/context/assembler.d.ts +2 -2
- package/dist/harness/context/assembler.js +12 -7
- package/dist/harness/context/capabilities/compact/engine.js +80 -38
- package/dist/harness/context/capabilities/compact/types.d.ts +12 -1
- package/dist/harness/context/capabilities/summary/registry.js +10 -0
- package/dist/harness/context/constitution/default-agents.md +230 -228
- package/dist/harness/context/default-context-engine.d.ts +101 -23
- package/dist/harness/context/default-context-engine.js +483 -172
- package/dist/harness/context/hybrid-compressor.d.ts +3 -3
- package/dist/harness/context/hybrid-compressor.js +18 -23
- package/dist/harness/context/index.d.ts +5 -1
- package/dist/harness/context/index.js +2 -0
- package/dist/harness/context/layer-snapshot.d.ts +4 -0
- package/dist/harness/context/layer-snapshot.js +30 -18
- package/dist/harness/context/layer-types.d.ts +85 -1
- package/dist/harness/context/layer-types.js +110 -4
- package/dist/harness/context/layers.d.ts +5 -2
- package/dist/harness/context/layers.js +11 -5
- package/dist/harness/context/llm-summarizer.d.ts +15 -1
- package/dist/harness/context/llm-summarizer.js +107 -56
- package/dist/harness/context/message-selector.js +6 -2
- package/dist/harness/context/root-instructions.d.ts +72 -0
- package/dist/harness/context/root-instructions.js +227 -0
- package/dist/harness/context/runtime-datetime.d.ts +34 -7
- package/dist/harness/context/runtime-datetime.js +66 -10
- package/dist/harness/context/smart-router.d.ts +1 -1
- package/dist/harness/context/smart-router.js +1 -1
- package/dist/harness/context/system-prompt-assembler.d.ts +30 -0
- package/dist/harness/context/system-prompt-assembler.js +73 -6
- package/dist/harness/context/token-constants.d.ts +2 -2
- package/dist/harness/context/token-constants.js +2 -2
- package/dist/harness/context/token-estimate-fns.d.ts +1 -3
- package/dist/harness/context/token-estimate-fns.js +2 -4
- package/dist/harness/context/token-estimator.d.ts +1 -1
- package/dist/harness/context/token-estimator.js +14 -6
- package/dist/harness/context/tool-result-aging.d.ts +140 -0
- package/dist/harness/context/tool-result-aging.js +331 -0
- package/dist/harness/context/tool-result-body.d.ts +10 -0
- package/dist/harness/context/tool-result-body.js +27 -0
- package/dist/harness/context/turn-envelope.d.ts +123 -0
- package/dist/harness/context/turn-envelope.js +188 -0
- package/dist/harness/context/types.d.ts +35 -47
- package/dist/harness/extension/execution-environment/effect-policy.d.ts +258 -0
- package/dist/harness/extension/execution-environment/effect-policy.js +358 -0
- package/dist/harness/extension/execution-environment/index.d.ts +18 -2
- package/dist/harness/extension/execution-environment/index.js +11 -2
- package/dist/harness/extension/execution-environment/isolation.js +5 -1
- package/dist/harness/extension/execution-environment/memory-undo.d.ts +101 -0
- package/dist/harness/extension/execution-environment/memory-undo.js +192 -0
- package/dist/harness/extension/execution-environment/process-isolation.d.ts +84 -0
- package/dist/harness/extension/execution-environment/process-isolation.js +315 -0
- package/dist/harness/extension/execution-environment/resource-limits.d.ts +36 -0
- package/dist/harness/extension/execution-environment/resource-limits.js +84 -0
- package/dist/harness/extension/execution-environment/sandbox.d.ts +125 -4
- package/dist/harness/extension/execution-environment/sandbox.js +521 -51
- package/dist/harness/extension/execution-environment/shell-journal.d.ts +100 -0
- package/dist/harness/extension/execution-environment/shell-journal.js +299 -0
- package/dist/harness/extension/execution-environment/tool-capabilities.d.ts +45 -0
- package/dist/harness/extension/execution-environment/tool-capabilities.js +126 -0
- package/dist/harness/extension/execution-environment/types.d.ts +67 -39
- package/dist/harness/extension/execution-environment/types.js +2 -2
- package/dist/harness/extension/execution-environment/undo-log.d.ts +203 -0
- package/dist/harness/extension/execution-environment/undo-log.js +627 -0
- package/dist/harness/extension/execution-environment/undo-merge.d.ts +40 -0
- package/dist/harness/extension/execution-environment/undo-merge.js +167 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/index.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/client-tools/types.d.ts +9 -0
- package/dist/harness/extension/plugin-ecosystem/mcp/bridge.js +2 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +1 -6
- package/dist/harness/extension/plugin-ecosystem/plugins/api.js +3 -8
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.d.ts +0 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.js +0 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.d.ts +2 -10
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.js +2 -9
- package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +1 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/index.js +1 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +2 -4
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +4 -21
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +3 -9
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +4 -8
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +1 -4
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +1 -3
- package/dist/harness/extension/plugin-ecosystem/skills/manager.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/skills/manager.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.d.ts +51 -0
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.js +153 -0
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +18 -3
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +277 -81
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.d.ts +31 -0
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +291 -0
- package/dist/harness/extension/plugin-ecosystem/tools/document-tools.js +10 -2
- package/dist/harness/extension/plugin-ecosystem/tools/env-info.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/tools/eol.d.ts +35 -0
- package/dist/harness/extension/plugin-ecosystem/tools/eol.js +43 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +40 -9
- package/dist/harness/extension/plugin-ecosystem/tools/file-ops.d.ts +33 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-ops.js +376 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.d.ts +12 -2
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +241 -70
- package/dist/harness/extension/plugin-ecosystem/tools/git-runner.d.ts +31 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-runner.js +104 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-status-snapshot.d.ts +111 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-status-snapshot.js +197 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.d.ts +27 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +463 -0
- package/dist/harness/extension/plugin-ecosystem/tools/http.d.ts +10 -6
- package/dist/harness/extension/plugin-ecosystem/tools/http.js +41 -47
- package/dist/harness/extension/plugin-ecosystem/tools/index.d.ts +6 -0
- package/dist/harness/extension/plugin-ecosystem/tools/index.js +4 -0
- package/dist/harness/extension/plugin-ecosystem/tools/knowledge.js +4 -0
- package/dist/harness/extension/plugin-ecosystem/tools/memory.js +25 -1
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.d.ts +13 -0
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +391 -0
- package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +51 -2
- package/dist/harness/extension/plugin-ecosystem/tools/platform.js +151 -12
- package/dist/harness/extension/plugin-ecosystem/tools/session-history.js +2 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.d.ts +10 -1
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +35 -19
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.d.ts +8 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.js +5 -0
- package/dist/harness/extension/plugin-ecosystem/tools/web-search.js +1 -0
- package/dist/harness/governance/credentials/index.d.ts +1 -1
- package/dist/harness/governance/credentials/store.d.ts +16 -4
- package/dist/harness/governance/credentials/store.js +33 -6
- package/dist/harness/governance/credentials/types.d.ts +11 -0
- package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +105 -0
- package/dist/harness/governance/human-in-the-loop/decision-cache.js +184 -0
- package/dist/harness/governance/human-in-the-loop/index.d.ts +5 -5
- package/dist/harness/governance/human-in-the-loop/index.js +3 -3
- package/dist/harness/governance/human-in-the-loop/types.d.ts +7 -62
- package/dist/harness/governance/human-in-the-loop/types.js +6 -2
- package/dist/harness/governance/security/capability-enforcer.d.ts +9 -1
- package/dist/harness/governance/security/capability-enforcer.js +31 -8
- package/dist/harness/governance/security/degradation.js +5 -7
- package/dist/harness/governance/security/risk-evaluator.d.ts +1 -1
- package/dist/harness/governance/security/risk-evaluator.js +4 -82
- package/dist/harness/governance/security/temp-path.d.ts +41 -0
- package/dist/harness/governance/security/temp-path.js +117 -0
- package/dist/harness/governance/session-acl/index.d.ts +1 -0
- package/dist/harness/governance/session-acl/index.js +1 -0
- package/dist/harness/governance/session-acl/rights.d.ts +12 -0
- package/dist/harness/governance/session-acl/rights.js +89 -7
- package/dist/harness/governance/session-acl/seed-roles.js +9 -1
- package/dist/harness/governance/session-acl/service.js +21 -29
- package/dist/harness/governance/session-acl/tool-rights.d.ts +81 -0
- package/dist/harness/governance/session-acl/tool-rights.js +238 -0
- package/dist/harness/governance/session-acl/types.d.ts +22 -0
- package/dist/harness/index.d.ts +16 -12
- package/dist/harness/index.js +10 -6
- package/dist/harness/knowledge/file-identity.d.ts +8 -0
- package/dist/harness/knowledge/file-identity.js +26 -1
- package/dist/harness/knowledge/file-index-store.js +11 -11
- package/dist/harness/knowledge/grounding.d.ts +2 -1
- package/dist/harness/knowledge/grounding.js +8 -5
- package/dist/harness/knowledge/index-store.d.ts +31 -4
- package/dist/harness/knowledge/index-store.js +121 -39
- package/dist/harness/knowledge/index.d.ts +2 -2
- package/dist/harness/knowledge/index.js +1 -1
- package/dist/harness/knowledge/ingest.d.ts +115 -115
- package/dist/harness/knowledge/ingest.js +154 -151
- package/dist/harness/knowledge/job-control-state.js +4 -4
- package/dist/harness/knowledge/job-control.js +11 -11
- package/dist/harness/knowledge/knowledge-serve-child.js +1 -1
- package/dist/harness/knowledge/membership-store.js +11 -11
- package/dist/harness/knowledge/network-guard.d.ts +61 -4
- package/dist/harness/knowledge/network-guard.js +390 -113
- package/dist/harness/knowledge/purge.js +4 -1
- package/dist/harness/knowledge/query-service.js +3 -3
- package/dist/harness/knowledge/writer-service.d.ts +2 -0
- package/dist/harness/knowledge/writer-service.js +14 -13
- package/dist/harness/memory/backfill-coverage.js +3 -1
- package/dist/harness/memory/backfill-trigger.d.ts +2 -2
- package/dist/harness/memory/backfill-trigger.js +4 -4
- package/dist/harness/memory/index.d.ts +1 -0
- package/dist/harness/memory/index.js +1 -0
- package/dist/harness/memory/sqlite/agent-db.js +2 -0
- package/dist/harness/memory/sqlite/memory-store.d.ts +1 -0
- package/dist/harness/memory/sqlite/memory-store.js +14 -4
- package/dist/harness/memory/sqlite/wisdom-store.js +9 -9
- package/dist/harness/memory/store.d.ts +1 -0
- package/dist/harness/memory/store.js +3 -0
- package/dist/harness/memory/time-format.d.ts +28 -0
- package/dist/harness/memory/time-format.js +52 -0
- package/dist/harness/memory/types.d.ts +12 -0
- package/dist/harness/observability/observer/hub.js +53 -2
- package/dist/harness/observability/observer/index.d.ts +2 -2
- package/dist/harness/observability/observer/index.js +1 -1
- package/dist/harness/observability/observer/types.d.ts +80 -0
- package/dist/harness/observability/observer/types.js +118 -9
- package/dist/harness/run/agent/agent.d.ts +18 -0
- package/dist/harness/run/agent/agent.js +26 -0
- package/dist/harness/run/concurrency/tool-loop-detection-core.d.ts +1 -1
- package/dist/harness/run/concurrency/tool-loop-detection-core.js +1 -1
- package/dist/harness/run/reliability/harness-events.d.ts +4 -0
- package/dist/harness/run/reliability/run-agent.js +110 -18
- package/dist/harness/run/reliability/run-metrics-collector.d.ts +28 -2
- package/dist/harness/run/reliability/run-metrics-collector.js +92 -2
- package/dist/harness/run/run-guard/default-run-guard.d.ts +0 -5
- package/dist/harness/run/run-guard/default-run-guard.js +104 -44
- package/dist/harness/run/run-scope.d.ts +52 -0
- package/dist/harness/run/runner.d.ts +117 -16
- package/dist/harness/run/runner.js +668 -157
- package/dist/harness/session/attachments/llm-intent.js +17 -17
- package/dist/harness/session/history/port.js +16 -5
- package/dist/harness/session/in-memory-store.d.ts +6 -0
- package/dist/harness/session/in-memory-store.js +55 -3
- package/dist/harness/session/schedules/index.d.ts +10 -0
- package/dist/harness/session/schedules/index.js +10 -0
- package/dist/harness/session/schedules/render.d.ts +13 -0
- package/dist/harness/session/schedules/render.js +63 -0
- package/dist/harness/session/schedules/service.d.ts +179 -0
- package/dist/harness/session/schedules/service.js +695 -0
- package/dist/harness/session/schedules/store.d.ts +119 -0
- package/dist/harness/session/schedules/store.js +323 -0
- package/dist/harness/session/schedules/tools.d.ts +39 -0
- package/dist/harness/session/schedules/tools.js +442 -0
- package/dist/harness/session/schedules/types.d.ts +104 -0
- package/dist/harness/session/schedules/types.js +97 -0
- package/dist/harness/session/tasks/tools.js +22 -0
- package/dist/harness/session/title.js +25 -9
- package/dist/harness/session/types.d.ts +35 -0
- package/dist/harness/shared/events/agent-event-map.d.ts +39 -0
- package/dist/harness/shared/events/agent-event-map.js +2 -0
- package/dist/harness/shared/types/agent-definition.d.ts +23 -0
- package/dist/index.d.ts +25 -9
- package/dist/index.js +11 -2
- package/dist/integration/observability/run-telemetry.d.ts +8 -0
- package/dist/integration/observability/run-telemetry.js +31 -8
- package/dist/integration/observability/trace-collector.js +26 -4
- package/dist/integration/observability/trace-events.d.ts +1 -0
- package/dist/integration/observability/trace-events.js +2 -0
- package/dist/integration/observability/trace-logger.js +27 -17
- package/dist/integration/providers/anthropic.d.ts +10 -0
- package/dist/integration/providers/anthropic.js +44 -1
- package/dist/integration/providers/openai.d.ts +10 -0
- package/dist/integration/providers/openai.js +58 -2
- package/dist/integration/providers/wire-dump-diff.d.ts +191 -0
- package/dist/integration/providers/wire-dump-diff.js +351 -0
- package/dist/integration/providers/wire-dump.d.ts +178 -0
- package/dist/integration/providers/wire-dump.js +396 -0
- package/dist/integration/storage/jsonl.d.ts +29 -0
- package/dist/integration/storage/jsonl.js +243 -41
- package/dist/integration/storage/session-index.js +63 -8
- package/dist/paths.d.ts +19 -0
- package/dist/paths.js +38 -1
- package/dist/subsystems/cognition-steward/conceptualize/SUBSYSTEM.md +43 -43
- package/dist/subsystems/cognition-steward/conceptualize/config.yaml +50 -50
- package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +6 -6
- package/dist/subsystems/cognition-steward/consolidate/config.yaml +54 -54
- package/dist/subsystems/memory-steward/backfill/handler.js +9 -0
- package/dist/subsystems/safety-guard/config.yaml +3 -1
- package/dist/subsystems/wisdom-steward/evaluate/config.yaml +50 -50
- package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +42 -42
- package/dist/subsystems/wisdom-steward/formation/config.yaml +54 -54
- package/dist/subsystems/wisdom-steward/govern/config.yaml +55 -55
- package/package.json +115 -115
- package/dist/harness/collaboration/multi-agent/agent-registry-types.d.ts +0 -144
- package/dist/harness/collaboration/multi-agent/agent-registry-types.js +0 -25
- package/dist/harness/collaboration/multi-agent/index.d.ts +0 -17
- package/dist/harness/collaboration/multi-agent/index.js +0 -15
- package/dist/harness/collaboration/multi-agent/process.d.ts +0 -167
- package/dist/harness/collaboration/multi-agent/process.js +0 -256
- package/dist/harness/collaboration/multi-agent/registry.d.ts +0 -36
- package/dist/harness/collaboration/multi-agent/registry.js +0 -137
- package/dist/harness/collaboration/multi-agent/swarm.d.ts +0 -135
- package/dist/harness/collaboration/multi-agent/swarm.js +0 -317
- package/dist/harness/collaboration/multi-agent/types.d.ts +0 -66
- package/dist/harness/collaboration/multi-agent/types.js +0 -15
- package/dist/harness/collaboration/orchestration/async-task-store.d.ts +0 -107
- package/dist/harness/collaboration/orchestration/async-task-store.js +0 -12
- package/dist/harness/collaboration/orchestration/async-task.d.ts +0 -156
- package/dist/harness/collaboration/orchestration/async-task.js +0 -359
- package/dist/harness/collaboration/orchestration/planner/hybrid-planner.d.ts +0 -47
- package/dist/harness/collaboration/orchestration/planner/hybrid-planner.js +0 -61
- package/dist/harness/collaboration/orchestration/planner/index.d.ts +0 -9
- package/dist/harness/collaboration/orchestration/planner/index.js +0 -6
- package/dist/harness/collaboration/orchestration/planner/llm-planner.d.ts +0 -54
- package/dist/harness/collaboration/orchestration/planner/llm-planner.js +0 -167
- package/dist/harness/collaboration/orchestration/planner/rule-planner.d.ts +0 -85
- package/dist/harness/collaboration/orchestration/planner/rule-planner.js +0 -175
- package/dist/harness/collaboration/orchestration/quality/classifier.d.ts +0 -21
- package/dist/harness/collaboration/orchestration/quality/classifier.js +0 -235
- package/dist/harness/collaboration/orchestration/quality/gate.d.ts +0 -29
- package/dist/harness/collaboration/orchestration/quality/gate.js +0 -409
- package/dist/harness/collaboration/orchestration/quality/index.d.ts +0 -9
- package/dist/harness/collaboration/orchestration/quality/index.js +0 -8
- package/dist/harness/collaboration/orchestration/quality/types.d.ts +0 -159
- package/dist/harness/collaboration/orchestration/quality/types.js +0 -33
- package/dist/harness/collaboration/orchestration/scheduler/index.d.ts +0 -5
- package/dist/harness/collaboration/orchestration/scheduler/index.js +0 -4
- package/dist/harness/collaboration/orchestration/scheduler/task-scheduler.d.ts +0 -143
- package/dist/harness/collaboration/orchestration/scheduler/task-scheduler.js +0 -297
- package/dist/harness/collaboration/orchestration/strategy/classifier.d.ts +0 -12
- package/dist/harness/collaboration/orchestration/strategy/classifier.js +0 -81
- package/dist/harness/collaboration/orchestration/strategy/index.d.ts +0 -3
- package/dist/harness/collaboration/orchestration/strategy/index.js +0 -2
- package/dist/harness/collaboration/orchestration/strategy/router.d.ts +0 -28
- package/dist/harness/collaboration/orchestration/strategy/router.js +0 -105
- package/dist/harness/collaboration/orchestration/strategy/types.d.ts +0 -49
- package/dist/harness/collaboration/orchestration/strategy/types.js +0 -4
- package/dist/harness/collaboration/orchestration/workflow/engine.d.ts +0 -86
- package/dist/harness/collaboration/orchestration/workflow/engine.js +0 -298
- package/dist/harness/collaboration/orchestration/workflow/index.d.ts +0 -9
- package/dist/harness/collaboration/orchestration/workflow/index.js +0 -7
- package/dist/harness/collaboration/orchestration/workflow/types.d.ts +0 -143
- package/dist/harness/collaboration/orchestration/workflow/types.js +0 -7
- package/dist/harness/governance/human-in-the-loop/approval-manager.d.ts +0 -32
- package/dist/harness/governance/human-in-the-loop/approval-manager.js +0 -93
- /package/dist/harness/collaboration/{multi-agent → delegation}/message-channel-types.d.ts +0 -0
- /package/dist/harness/collaboration/{multi-agent → delegation}/message-channel-types.js +0 -0
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TaskScheduler — 任务调度器
|
|
3
|
-
*
|
|
4
|
-
* 支持定时任务、延迟任务、循环任务。
|
|
5
|
-
* 基于 AsyncTask 实现,通过 EventBus 发射事件。
|
|
6
|
-
*
|
|
7
|
-
* 设计要点:
|
|
8
|
-
* - cron 时间数学走 `core/primitives/cron.ts`(禁止本地再解析)
|
|
9
|
-
* - 进程退出时自动清理所有任务
|
|
10
|
-
* - 所有调度事件通过 EventBus 发射
|
|
11
|
-
*/
|
|
12
|
-
import type { EventBus } from '@octopi-agent/core/index.js';
|
|
13
|
-
/** 调度任务类型 */
|
|
14
|
-
export type ScheduleKind = 'once' | 'cron' | 'interval' | 'delay';
|
|
15
|
-
/** 调度任务 */
|
|
16
|
-
export interface ScheduledTask {
|
|
17
|
-
/** 任务 ID */
|
|
18
|
-
id: string;
|
|
19
|
-
/** 任务名称 */
|
|
20
|
-
name: string;
|
|
21
|
-
/** 任务类型 */
|
|
22
|
-
kind: ScheduleKind;
|
|
23
|
-
/** 任务处理函数 */
|
|
24
|
-
handler: () => Promise<void> | void;
|
|
25
|
-
/** cron 表达式(kind=cron 时使用) */
|
|
26
|
-
cron?: string;
|
|
27
|
-
/** 间隔毫秒(kind=interval/delay 时使用) */
|
|
28
|
-
intervalMs?: number;
|
|
29
|
-
/** 执行时间戳(kind=once 时使用) */
|
|
30
|
-
executeAt?: number;
|
|
31
|
-
/** 是否启用 */
|
|
32
|
-
enabled: boolean;
|
|
33
|
-
/** 已执行次数 */
|
|
34
|
-
runCount: number;
|
|
35
|
-
/** 最大执行次数(0=不限) */
|
|
36
|
-
maxRuns: number;
|
|
37
|
-
/** 创建时间 */
|
|
38
|
-
createdAt: number;
|
|
39
|
-
/** 下次执行时间 */
|
|
40
|
-
nextRunAt: number;
|
|
41
|
-
/** 上次执行时间 */
|
|
42
|
-
lastRunAt?: number;
|
|
43
|
-
/** 最后一次 AsyncTask */
|
|
44
|
-
_timer?: ReturnType<typeof setTimeout>;
|
|
45
|
-
_intervalTimer?: ReturnType<typeof setInterval>;
|
|
46
|
-
}
|
|
47
|
-
export declare const SchedulerEvents: {
|
|
48
|
-
readonly TASK_ADDED: "scheduler.task.added";
|
|
49
|
-
readonly TASK_REMOVED: "scheduler.task.removed";
|
|
50
|
-
readonly TASK_STARTED: "scheduler.task.started";
|
|
51
|
-
readonly TASK_COMPLETED: "scheduler.task.completed";
|
|
52
|
-
readonly TASK_FAILED: "scheduler.task.failed";
|
|
53
|
-
readonly TASK_SKIPPED: "scheduler.task.skipped";
|
|
54
|
-
};
|
|
55
|
-
export interface TaskSchedulerConfig {
|
|
56
|
-
/** 检查间隔(毫秒,默认 1000) */
|
|
57
|
-
checkIntervalMs?: number;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* 任务调度器
|
|
61
|
-
*/
|
|
62
|
-
export declare class TaskScheduler {
|
|
63
|
-
private _tasks;
|
|
64
|
-
private _events?;
|
|
65
|
-
private _checkTimer?;
|
|
66
|
-
private _checkIntervalMs;
|
|
67
|
-
private _running;
|
|
68
|
-
constructor(config?: TaskSchedulerConfig, events?: EventBus);
|
|
69
|
-
/**
|
|
70
|
-
* 启动调度器
|
|
71
|
-
*/
|
|
72
|
-
start(): void;
|
|
73
|
-
/**
|
|
74
|
-
* 停止调度器
|
|
75
|
-
*/
|
|
76
|
-
stop(): void;
|
|
77
|
-
/**
|
|
78
|
-
* 调度器是否正在运行
|
|
79
|
-
*/
|
|
80
|
-
get running(): boolean;
|
|
81
|
-
/**
|
|
82
|
-
* 任务数量
|
|
83
|
-
*/
|
|
84
|
-
get taskCount(): number;
|
|
85
|
-
/**
|
|
86
|
-
* 添加一次性延迟任务
|
|
87
|
-
*
|
|
88
|
-
* @param name - 任务名称
|
|
89
|
-
* @param delayMs - 延迟毫秒
|
|
90
|
-
* @param handler - 任务处理函数
|
|
91
|
-
*/
|
|
92
|
-
scheduleOnce(name: string, delayMs: number, handler: () => Promise<void> | void): ScheduledTask;
|
|
93
|
-
/**
|
|
94
|
-
* 添加循环任务
|
|
95
|
-
*
|
|
96
|
-
* @param name - 任务名称
|
|
97
|
-
* @param intervalMs - 间隔毫秒
|
|
98
|
-
* @param handler - 任务处理函数
|
|
99
|
-
* @param maxRuns - 最大执行次数(0=不限)
|
|
100
|
-
*/
|
|
101
|
-
scheduleInterval(name: string, intervalMs: number, handler: () => Promise<void> | void, maxRuns?: number): ScheduledTask;
|
|
102
|
-
/**
|
|
103
|
-
* 添加 cron 任务
|
|
104
|
-
*
|
|
105
|
-
* @param name - 任务名称
|
|
106
|
-
* @param cronExpr - cron 表达式(简化版:分 时 日 月 周)
|
|
107
|
-
* @param handler - 任务处理函数
|
|
108
|
-
* @throws 表达式非法时抛错(禁止静默延后)
|
|
109
|
-
*/
|
|
110
|
-
scheduleCron(name: string, cronExpr: string, handler: () => Promise<void> | void): ScheduledTask;
|
|
111
|
-
/**
|
|
112
|
-
* 添加定时任务(指定时间执行)
|
|
113
|
-
*
|
|
114
|
-
* @param name - 任务名称
|
|
115
|
-
* @param executeAt - 执行时间戳
|
|
116
|
-
* @param handler - 任务处理函数
|
|
117
|
-
*/
|
|
118
|
-
scheduleAt(name: string, executeAt: number, handler: () => Promise<void> | void): ScheduledTask;
|
|
119
|
-
/**
|
|
120
|
-
* 取消任务
|
|
121
|
-
*/
|
|
122
|
-
cancel(taskId: string): boolean;
|
|
123
|
-
/**
|
|
124
|
-
* 暂停任务
|
|
125
|
-
*/
|
|
126
|
-
pause(taskId: string): boolean;
|
|
127
|
-
/**
|
|
128
|
-
* 恢复任务
|
|
129
|
-
*/
|
|
130
|
-
resume(taskId: string): boolean;
|
|
131
|
-
/**
|
|
132
|
-
* 获取所有任务
|
|
133
|
-
*/
|
|
134
|
-
list(): ScheduledTask[];
|
|
135
|
-
/**
|
|
136
|
-
* 获取单个任务
|
|
137
|
-
*/
|
|
138
|
-
get(taskId: string): ScheduledTask | undefined;
|
|
139
|
-
private _addTask;
|
|
140
|
-
private _tick;
|
|
141
|
-
private _executeTask;
|
|
142
|
-
private _emit;
|
|
143
|
-
}
|
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TaskScheduler — 任务调度器
|
|
3
|
-
*
|
|
4
|
-
* 支持定时任务、延迟任务、循环任务。
|
|
5
|
-
* 基于 AsyncTask 实现,通过 EventBus 发射事件。
|
|
6
|
-
*
|
|
7
|
-
* 设计要点:
|
|
8
|
-
* - cron 时间数学走 `core/primitives/cron.ts`(禁止本地再解析)
|
|
9
|
-
* - 进程退出时自动清理所有任务
|
|
10
|
-
* - 所有调度事件通过 EventBus 发射
|
|
11
|
-
*/
|
|
12
|
-
import { randomUUID } from 'node:crypto';
|
|
13
|
-
import { parseCron, nextFireTime } from '@octopi-agent/core/primitives/cron.js';
|
|
14
|
-
// ── 事件类型 ──
|
|
15
|
-
export const SchedulerEvents = {
|
|
16
|
-
TASK_ADDED: 'scheduler.task.added',
|
|
17
|
-
TASK_REMOVED: 'scheduler.task.removed',
|
|
18
|
-
TASK_STARTED: 'scheduler.task.started',
|
|
19
|
-
TASK_COMPLETED: 'scheduler.task.completed',
|
|
20
|
-
TASK_FAILED: 'scheduler.task.failed',
|
|
21
|
-
TASK_SKIPPED: 'scheduler.task.skipped',
|
|
22
|
-
};
|
|
23
|
-
// ── TaskScheduler ──
|
|
24
|
-
/**
|
|
25
|
-
* 任务调度器
|
|
26
|
-
*/
|
|
27
|
-
export class TaskScheduler {
|
|
28
|
-
_tasks = new Map();
|
|
29
|
-
_events;
|
|
30
|
-
_checkTimer;
|
|
31
|
-
_checkIntervalMs;
|
|
32
|
-
_running = false;
|
|
33
|
-
constructor(config, events) {
|
|
34
|
-
this._checkIntervalMs = config?.checkIntervalMs ?? 1000;
|
|
35
|
-
this._events = events;
|
|
36
|
-
}
|
|
37
|
-
// ── 生命周期 ──
|
|
38
|
-
/**
|
|
39
|
-
* 启动调度器
|
|
40
|
-
*/
|
|
41
|
-
start() {
|
|
42
|
-
if (this._running)
|
|
43
|
-
return;
|
|
44
|
-
this._running = true;
|
|
45
|
-
// 定期检查待执行任务
|
|
46
|
-
this._checkTimer = setInterval(() => {
|
|
47
|
-
this._tick();
|
|
48
|
-
}, this._checkIntervalMs);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* 停止调度器
|
|
52
|
-
*/
|
|
53
|
-
stop() {
|
|
54
|
-
this._running = false;
|
|
55
|
-
if (this._checkTimer) {
|
|
56
|
-
clearInterval(this._checkTimer);
|
|
57
|
-
this._checkTimer = undefined;
|
|
58
|
-
}
|
|
59
|
-
// 清理所有定时器
|
|
60
|
-
for (const task of this._tasks.values()) {
|
|
61
|
-
if (task._timer)
|
|
62
|
-
clearTimeout(task._timer);
|
|
63
|
-
if (task._intervalTimer)
|
|
64
|
-
clearInterval(task._intervalTimer);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* 调度器是否正在运行
|
|
69
|
-
*/
|
|
70
|
-
get running() { return this._running; }
|
|
71
|
-
/**
|
|
72
|
-
* 任务数量
|
|
73
|
-
*/
|
|
74
|
-
get taskCount() { return this._tasks.size; }
|
|
75
|
-
// ── 添加任务 ──
|
|
76
|
-
/**
|
|
77
|
-
* 添加一次性延迟任务
|
|
78
|
-
*
|
|
79
|
-
* @param name - 任务名称
|
|
80
|
-
* @param delayMs - 延迟毫秒
|
|
81
|
-
* @param handler - 任务处理函数
|
|
82
|
-
*/
|
|
83
|
-
scheduleOnce(name, delayMs, handler) {
|
|
84
|
-
const task = {
|
|
85
|
-
id: randomUUID(),
|
|
86
|
-
name,
|
|
87
|
-
kind: 'once',
|
|
88
|
-
handler,
|
|
89
|
-
intervalMs: delayMs,
|
|
90
|
-
enabled: true,
|
|
91
|
-
runCount: 0,
|
|
92
|
-
maxRuns: 1,
|
|
93
|
-
createdAt: Date.now(),
|
|
94
|
-
nextRunAt: Date.now() + delayMs,
|
|
95
|
-
};
|
|
96
|
-
this._addTask(task);
|
|
97
|
-
return task;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* 添加循环任务
|
|
101
|
-
*
|
|
102
|
-
* @param name - 任务名称
|
|
103
|
-
* @param intervalMs - 间隔毫秒
|
|
104
|
-
* @param handler - 任务处理函数
|
|
105
|
-
* @param maxRuns - 最大执行次数(0=不限)
|
|
106
|
-
*/
|
|
107
|
-
scheduleInterval(name, intervalMs, handler, maxRuns = 0) {
|
|
108
|
-
const task = {
|
|
109
|
-
id: randomUUID(),
|
|
110
|
-
name,
|
|
111
|
-
kind: 'interval',
|
|
112
|
-
handler,
|
|
113
|
-
intervalMs,
|
|
114
|
-
enabled: true,
|
|
115
|
-
runCount: 0,
|
|
116
|
-
maxRuns,
|
|
117
|
-
createdAt: Date.now(),
|
|
118
|
-
nextRunAt: Date.now() + intervalMs,
|
|
119
|
-
};
|
|
120
|
-
this._addTask(task);
|
|
121
|
-
return task;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* 添加 cron 任务
|
|
125
|
-
*
|
|
126
|
-
* @param name - 任务名称
|
|
127
|
-
* @param cronExpr - cron 表达式(简化版:分 时 日 月 周)
|
|
128
|
-
* @param handler - 任务处理函数
|
|
129
|
-
* @throws 表达式非法时抛错(禁止静默延后)
|
|
130
|
-
*/
|
|
131
|
-
scheduleCron(name, cronExpr, handler) {
|
|
132
|
-
const parsed = parseCron(cronExpr);
|
|
133
|
-
if (!parsed.ok) {
|
|
134
|
-
throw new Error(`invalid cron "${cronExpr}": ${parsed.error}`);
|
|
135
|
-
}
|
|
136
|
-
const nextRun = nextFireTime(parsed.spec, Date.now());
|
|
137
|
-
const task = {
|
|
138
|
-
id: randomUUID(),
|
|
139
|
-
name,
|
|
140
|
-
kind: 'cron',
|
|
141
|
-
handler,
|
|
142
|
-
cron: cronExpr,
|
|
143
|
-
enabled: true,
|
|
144
|
-
runCount: 0,
|
|
145
|
-
maxRuns: 0,
|
|
146
|
-
createdAt: Date.now(),
|
|
147
|
-
nextRunAt: nextRun,
|
|
148
|
-
};
|
|
149
|
-
this._addTask(task);
|
|
150
|
-
return task;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* 添加定时任务(指定时间执行)
|
|
154
|
-
*
|
|
155
|
-
* @param name - 任务名称
|
|
156
|
-
* @param executeAt - 执行时间戳
|
|
157
|
-
* @param handler - 任务处理函数
|
|
158
|
-
*/
|
|
159
|
-
scheduleAt(name, executeAt, handler) {
|
|
160
|
-
const task = {
|
|
161
|
-
id: randomUUID(),
|
|
162
|
-
name,
|
|
163
|
-
kind: 'once',
|
|
164
|
-
handler,
|
|
165
|
-
executeAt,
|
|
166
|
-
enabled: true,
|
|
167
|
-
runCount: 0,
|
|
168
|
-
maxRuns: 1,
|
|
169
|
-
createdAt: Date.now(),
|
|
170
|
-
nextRunAt: executeAt,
|
|
171
|
-
};
|
|
172
|
-
this._addTask(task);
|
|
173
|
-
return task;
|
|
174
|
-
}
|
|
175
|
-
// ── 管理任务 ──
|
|
176
|
-
/**
|
|
177
|
-
* 取消任务
|
|
178
|
-
*/
|
|
179
|
-
cancel(taskId) {
|
|
180
|
-
const task = this._tasks.get(taskId);
|
|
181
|
-
if (!task)
|
|
182
|
-
return false;
|
|
183
|
-
task.enabled = false;
|
|
184
|
-
if (task._timer)
|
|
185
|
-
clearTimeout(task._timer);
|
|
186
|
-
if (task._intervalTimer)
|
|
187
|
-
clearInterval(task._intervalTimer);
|
|
188
|
-
this._tasks.delete(taskId);
|
|
189
|
-
this._emit(SchedulerEvents.TASK_REMOVED, { taskId, name: task.name });
|
|
190
|
-
return true;
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* 暂停任务
|
|
194
|
-
*/
|
|
195
|
-
pause(taskId) {
|
|
196
|
-
const task = this._tasks.get(taskId);
|
|
197
|
-
if (!task)
|
|
198
|
-
return false;
|
|
199
|
-
task.enabled = false;
|
|
200
|
-
return true;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* 恢复任务
|
|
204
|
-
*/
|
|
205
|
-
resume(taskId) {
|
|
206
|
-
const task = this._tasks.get(taskId);
|
|
207
|
-
if (!task)
|
|
208
|
-
return false;
|
|
209
|
-
task.enabled = true;
|
|
210
|
-
return true;
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* 获取所有任务
|
|
214
|
-
*/
|
|
215
|
-
list() {
|
|
216
|
-
return Array.from(this._tasks.values()).map(t => ({
|
|
217
|
-
...t,
|
|
218
|
-
_timer: undefined,
|
|
219
|
-
_intervalTimer: undefined,
|
|
220
|
-
}));
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* 获取单个任务
|
|
224
|
-
*/
|
|
225
|
-
get(taskId) {
|
|
226
|
-
const task = this._tasks.get(taskId);
|
|
227
|
-
if (!task)
|
|
228
|
-
return undefined;
|
|
229
|
-
return { ...task, _timer: undefined, _intervalTimer: undefined };
|
|
230
|
-
}
|
|
231
|
-
// ── 内部方法 ──
|
|
232
|
-
_addTask(task) {
|
|
233
|
-
this._tasks.set(task.id, task);
|
|
234
|
-
this._emit(SchedulerEvents.TASK_ADDED, { taskId: task.id, name: task.name, kind: task.kind });
|
|
235
|
-
// 如果是一次性延迟任务且调度器未启动,直接用 setTimeout
|
|
236
|
-
if (task.kind === 'once' && !this._running) {
|
|
237
|
-
const delay = Math.max(0, task.nextRunAt - Date.now());
|
|
238
|
-
task._timer = setTimeout(() => {
|
|
239
|
-
this._executeTask(task);
|
|
240
|
-
}, delay);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
_tick() {
|
|
244
|
-
const now = Date.now();
|
|
245
|
-
for (const task of this._tasks.values()) {
|
|
246
|
-
if (!task.enabled)
|
|
247
|
-
continue;
|
|
248
|
-
if (task.nextRunAt > now)
|
|
249
|
-
continue;
|
|
250
|
-
this._executeTask(task);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
async _executeTask(task) {
|
|
254
|
-
if (!task.enabled)
|
|
255
|
-
return;
|
|
256
|
-
if (task.maxRuns > 0 && task.runCount >= task.maxRuns) {
|
|
257
|
-
this._emit(SchedulerEvents.TASK_SKIPPED, { taskId: task.id, reason: 'max runs reached' });
|
|
258
|
-
this.cancel(task.id);
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
task.runCount++;
|
|
262
|
-
task.lastRunAt = Date.now();
|
|
263
|
-
this._emit(SchedulerEvents.TASK_STARTED, { taskId: task.id, name: task.name, runCount: task.runCount });
|
|
264
|
-
try {
|
|
265
|
-
await task.handler();
|
|
266
|
-
this._emit(SchedulerEvents.TASK_COMPLETED, { taskId: task.id, name: task.name, runCount: task.runCount });
|
|
267
|
-
}
|
|
268
|
-
catch (err) {
|
|
269
|
-
this._emit(SchedulerEvents.TASK_FAILED, {
|
|
270
|
-
taskId: task.id,
|
|
271
|
-
name: task.name,
|
|
272
|
-
error: err instanceof Error ? err.message : String(err),
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
// 更新下次执行时间
|
|
276
|
-
if (task.kind === 'interval' && task.intervalMs) {
|
|
277
|
-
task.nextRunAt = Date.now() + task.intervalMs;
|
|
278
|
-
}
|
|
279
|
-
else if (task.kind === 'cron' && task.cron) {
|
|
280
|
-
const parsed = parseCron(task.cron);
|
|
281
|
-
if (!parsed.ok) {
|
|
282
|
-
this.cancel(task.id);
|
|
283
|
-
return;
|
|
284
|
-
}
|
|
285
|
-
task.nextRunAt = nextFireTime(parsed.spec, Date.now());
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
// once 任务执行完毕,删除
|
|
289
|
-
this._tasks.delete(task.id);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
_emit(type, data) {
|
|
293
|
-
if (this._events) {
|
|
294
|
-
this._events.emit({ type, timestamp: Date.now(), data });
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* RuleTaskClassifier — 规则驱动的任务分类器
|
|
3
|
-
*
|
|
4
|
-
* 用关键词和规则快速分类,不需要 LLM 调用。
|
|
5
|
-
*/
|
|
6
|
-
import type { TaskClassifier, TaskClassification } from './types.js';
|
|
7
|
-
export declare class RuleTaskClassifier implements TaskClassifier {
|
|
8
|
-
readonly name = "rule-classifier";
|
|
9
|
-
classify(input: string, context?: Record<string, unknown>): Promise<TaskClassification>;
|
|
10
|
-
private _classifyCategory;
|
|
11
|
-
private _classifyComplexity;
|
|
12
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* RuleTaskClassifier — 规则驱动的任务分类器
|
|
3
|
-
*
|
|
4
|
-
* 用关键词和规则快速分类,不需要 LLM 调用。
|
|
5
|
-
*/
|
|
6
|
-
/** 关键词 → 类型映射 */
|
|
7
|
-
const CATEGORY_KEYWORDS = {
|
|
8
|
-
question: ['什么', '怎么', '如何', '为什么', '吗', '?', '?', 'what', 'how', 'why', 'is', 'are', 'do', 'does'],
|
|
9
|
-
lookup: ['查', '搜索', '找', 'search', 'find', 'look up', '查询', '告诉我'],
|
|
10
|
-
analysis: ['分析', '评估', '对比', '比较', 'analyze', 'evaluate', 'compare', '审查', 'review'],
|
|
11
|
-
creation: ['写', '生成', '创作', '设计', '写一个', 'create', 'generate', 'write', 'design', '帮我写'],
|
|
12
|
-
coding: ['代码', '函数', 'bug', '重构', '实现', 'code', 'function', 'refactor', 'implement', 'debug', '修复', 'fix'],
|
|
13
|
-
planning: ['计划', '规划', '安排', '拆解', '分解', 'plan', 'schedule', 'break down', '步骤'],
|
|
14
|
-
conversation: ['你好', 'hi', 'hello', '谢谢', 'thanks', '好的', 'ok', '嗯'],
|
|
15
|
-
unknown: [],
|
|
16
|
-
};
|
|
17
|
-
/** 复杂度信号 */
|
|
18
|
-
const COMPLEXITY_SIGNALS = {
|
|
19
|
-
simple: {
|
|
20
|
-
maxWords: 20,
|
|
21
|
-
keywords: ['谢谢', '好的', 'ok', 'hi', 'hello', '是', '不是', '对', '不对', '你好', '嗨', '吗', '呢', '嗯', '哈哈', '早上好', '晚安', '怎么样', '是什么', '多少', '几天'],
|
|
22
|
-
},
|
|
23
|
-
complex: {
|
|
24
|
-
keywords: ['重构', '设计', '架构', '系统', '完整', '全面', '详细', 'refactor', 'design', 'architecture', 'system', '所有'],
|
|
25
|
-
minWords: 30,
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
export class RuleTaskClassifier {
|
|
29
|
-
name = 'rule-classifier';
|
|
30
|
-
async classify(input, context) {
|
|
31
|
-
const lower = input.toLowerCase();
|
|
32
|
-
const words = input.split(/\s+/).length;
|
|
33
|
-
// 分类
|
|
34
|
-
const category = this._classifyCategory(lower);
|
|
35
|
-
// 复杂度
|
|
36
|
-
const complexity = this._classifyComplexity(lower, words);
|
|
37
|
-
// 是否需要工具
|
|
38
|
-
const needsTools = category === 'lookup' || category === 'coding' || lower.includes('文件') || lower.includes('file');
|
|
39
|
-
// 是否需要规划
|
|
40
|
-
const needsPlanning = complexity === 'complex' && (category === 'planning' || category === 'coding' || category === 'creation');
|
|
41
|
-
// 置信度
|
|
42
|
-
const confidence = category === 'unknown' ? 0.3 : (complexity === 'moderate' ? 0.6 : 0.8);
|
|
43
|
-
return {
|
|
44
|
-
category,
|
|
45
|
-
complexity,
|
|
46
|
-
confidence,
|
|
47
|
-
needsTools,
|
|
48
|
-
needsPlanning,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
_classifyCategory(input) {
|
|
52
|
-
let bestCategory = 'unknown';
|
|
53
|
-
let bestScore = 0;
|
|
54
|
-
for (const [category, keywords] of Object.entries(CATEGORY_KEYWORDS)) {
|
|
55
|
-
const score = keywords.filter(kw => input.includes(kw)).length;
|
|
56
|
-
if (score > bestScore) {
|
|
57
|
-
bestScore = score;
|
|
58
|
-
bestCategory = category;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return bestCategory;
|
|
62
|
-
}
|
|
63
|
-
_classifyComplexity(input, words) {
|
|
64
|
-
const charCount = input.length;
|
|
65
|
-
// 短问题(<=30字符)且有问号 → simple
|
|
66
|
-
if (charCount <= 30 && (input.includes('?') || input.includes('?') || input.includes('吗') || input.includes('呢'))) {
|
|
67
|
-
return 'simple';
|
|
68
|
-
}
|
|
69
|
-
// 简单关键词命中 → simple
|
|
70
|
-
if (charCount <= 50) {
|
|
71
|
-
const simpleHits = COMPLEXITY_SIGNALS.simple.keywords.filter(kw => input.includes(kw)).length;
|
|
72
|
-
if (simpleHits > 0)
|
|
73
|
-
return 'simple';
|
|
74
|
-
}
|
|
75
|
-
// 复杂信号
|
|
76
|
-
const complexHits = COMPLEXITY_SIGNALS.complex.keywords.filter(kw => input.includes(kw)).length;
|
|
77
|
-
if (complexHits >= 2 || words >= COMPLEXITY_SIGNALS.complex.minWords)
|
|
78
|
-
return 'complex';
|
|
79
|
-
return 'moderate';
|
|
80
|
-
}
|
|
81
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DefaultStrategyRouter — 默认策略路由器
|
|
3
|
-
*
|
|
4
|
-
* 根据任务分类选择最合适的推理策略。
|
|
5
|
-
*/
|
|
6
|
-
import type { StrategyRouter, Strategy, TaskClassification, StrategyKind } from './types.js';
|
|
7
|
-
interface RouteRule {
|
|
8
|
-
match: (c: TaskClassification) => boolean;
|
|
9
|
-
strategy: StrategyKind;
|
|
10
|
-
}
|
|
11
|
-
export declare class DefaultStrategyRouter implements StrategyRouter {
|
|
12
|
-
readonly name = "default-router";
|
|
13
|
-
private _customStrategies;
|
|
14
|
-
private _rules;
|
|
15
|
-
constructor(options?: {
|
|
16
|
-
strategies?: Partial<Record<StrategyKind, Strategy>>;
|
|
17
|
-
rules?: RouteRule[];
|
|
18
|
-
});
|
|
19
|
-
/**
|
|
20
|
-
* 根据分类选择策略
|
|
21
|
-
*/
|
|
22
|
-
select(classification: TaskClassification): Strategy;
|
|
23
|
-
/**
|
|
24
|
-
* 获取所有可用策略
|
|
25
|
-
*/
|
|
26
|
-
listStrategies(): Strategy[];
|
|
27
|
-
}
|
|
28
|
-
export {};
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DefaultStrategyRouter — 默认策略路由器
|
|
3
|
-
*
|
|
4
|
-
* 根据任务分类选择最合适的推理策略。
|
|
5
|
-
*/
|
|
6
|
-
// ── 默认策略集 ──
|
|
7
|
-
const STRATEGIES = {
|
|
8
|
-
direct: {
|
|
9
|
-
kind: 'direct',
|
|
10
|
-
name: '直接回答',
|
|
11
|
-
description: '简单问题,直接回答不需要推理链',
|
|
12
|
-
maxIterations: 1,
|
|
13
|
-
temperature: 0.3,
|
|
14
|
-
},
|
|
15
|
-
chain_of_thought: {
|
|
16
|
-
kind: 'chain_of_thought',
|
|
17
|
-
name: '思维链',
|
|
18
|
-
description: '需要逐步推理的问题',
|
|
19
|
-
systemPromptAddition: '请一步步思考,展示你的推理过程。',
|
|
20
|
-
maxIterations: 1,
|
|
21
|
-
temperature: 0.5,
|
|
22
|
-
},
|
|
23
|
-
plan_and_execute: {
|
|
24
|
-
kind: 'plan_and_execute',
|
|
25
|
-
name: '规划执行',
|
|
26
|
-
description: '复杂任务,先规划再执行',
|
|
27
|
-
systemPromptAddition: '先制定计划,分解为步骤,然后逐步执行。',
|
|
28
|
-
maxIterations: 10,
|
|
29
|
-
needsReflection: true,
|
|
30
|
-
temperature: 0.4,
|
|
31
|
-
},
|
|
32
|
-
tool_use: {
|
|
33
|
-
kind: 'tool_use',
|
|
34
|
-
name: '工具优先',
|
|
35
|
-
description: '需要外部信息或执行操作',
|
|
36
|
-
systemPromptAddition: '优先使用工具获取信息和执行操作。',
|
|
37
|
-
maxIterations: 5,
|
|
38
|
-
temperature: 0.3,
|
|
39
|
-
},
|
|
40
|
-
reflect: {
|
|
41
|
-
kind: 'reflect',
|
|
42
|
-
name: '反思循环',
|
|
43
|
-
description: '需要高质量输出,执行后反思改进',
|
|
44
|
-
systemPromptAddition: '完成任务后,检查输出质量,必要时改进。',
|
|
45
|
-
maxIterations: 3,
|
|
46
|
-
needsReflection: true,
|
|
47
|
-
temperature: 0.5,
|
|
48
|
-
},
|
|
49
|
-
multi_agent: {
|
|
50
|
-
kind: 'multi_agent',
|
|
51
|
-
name: '多 Agent 协作',
|
|
52
|
-
description: '超复杂任务,分派给多个子 Agent',
|
|
53
|
-
systemPromptAddition: '将任务分解,分配给专门的子 Agent 处理。',
|
|
54
|
-
maxIterations: 15,
|
|
55
|
-
needsReflection: true,
|
|
56
|
-
temperature: 0.4,
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
const ROUTE_RULES = [
|
|
60
|
-
// 简单对话 → 直接回答
|
|
61
|
-
{ match: c => c.complexity === 'simple' && c.category === 'conversation', strategy: 'direct' },
|
|
62
|
-
{ match: c => c.complexity === 'simple' && c.category === 'question', strategy: 'direct' },
|
|
63
|
-
// 查询 → 工具优先
|
|
64
|
-
{ match: c => c.category === 'lookup' || c.needsTools, strategy: 'tool_use' },
|
|
65
|
-
// 分析 → 思维链
|
|
66
|
-
{ match: c => c.category === 'analysis', strategy: 'chain_of_thought' },
|
|
67
|
-
// 规划 → 规划执行
|
|
68
|
-
{ match: c => c.needsPlanning || c.category === 'planning', strategy: 'plan_and_execute' },
|
|
69
|
-
// 复杂编码 → 规划执行
|
|
70
|
-
{ match: c => c.complexity === 'complex' && c.category === 'coding', strategy: 'plan_and_execute' },
|
|
71
|
-
// 复杂创作 → 反思循环
|
|
72
|
-
{ match: c => c.complexity === 'complex' && c.category === 'creation', strategy: 'reflect' },
|
|
73
|
-
// 中等复杂度 → 思维链
|
|
74
|
-
{ match: c => c.complexity === 'moderate', strategy: 'chain_of_thought' },
|
|
75
|
-
// 默认 → 直接回答
|
|
76
|
-
{ match: () => true, strategy: 'direct' },
|
|
77
|
-
];
|
|
78
|
-
// ── DefaultStrategyRouter ──
|
|
79
|
-
export class DefaultStrategyRouter {
|
|
80
|
-
name = 'default-router';
|
|
81
|
-
_customStrategies;
|
|
82
|
-
_rules;
|
|
83
|
-
constructor(options) {
|
|
84
|
-
this._customStrategies = new Map(Object.entries(options?.strategies ?? []));
|
|
85
|
-
this._rules = options?.rules ?? ROUTE_RULES;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* 根据分类选择策略
|
|
89
|
-
*/
|
|
90
|
-
select(classification) {
|
|
91
|
-
for (const rule of this._rules) {
|
|
92
|
-
if (rule.match(classification)) {
|
|
93
|
-
const custom = this._customStrategies.get(rule.strategy);
|
|
94
|
-
return custom ?? STRATEGIES[rule.strategy];
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return STRATEGIES.direct;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* 获取所有可用策略
|
|
101
|
-
*/
|
|
102
|
-
listStrategies() {
|
|
103
|
-
return Object.values(STRATEGIES);
|
|
104
|
-
}
|
|
105
|
-
}
|