@octopi-agent/engine 0.70.7 → 0.86.38
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 +69 -0
- package/dist/config-schema/context.d.ts +23 -4
- package/dist/config-schema/context.js +28 -1
- package/dist/config-schema/engine.d.ts +201 -9
- package/dist/config-schema/engine.js +31 -2
- package/dist/config-schema/governance.d.ts +95 -0
- package/dist/config-schema/governance.js +91 -0
- package/dist/config-schema/models.d.ts +1 -1
- 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 +10 -0
- package/dist/config-schema/shared.js +10 -0
- package/dist/config-schema/substrate.d.ts +1 -1
- package/dist/config-schema/subsystems.d.ts +1 -1
- package/dist/config-schema/subsystems.js +2 -1
- package/dist/config.d.ts +178 -7
- package/dist/config.js +113 -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 +47 -3
- package/dist/harness/agent/builder.js +180 -54
- package/dist/harness/agent/config-bridge.d.ts +33 -25
- package/dist/harness/agent/config-bridge.js +81 -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 +38 -0
- package/dist/harness/agent/tool-purpose.js +118 -0
- package/dist/harness/agent/wire-agent-builder.d.ts +133 -0
- package/dist/harness/agent/wire-agent-builder.js +363 -0
- package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +4 -1
- package/dist/harness/collaboration/autonomous-subsystem/runtime.js +14 -8
- 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 +49 -1
- package/dist/harness/context/layer-types.js +72 -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 +67 -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 +248 -0
- package/dist/harness/extension/execution-environment/effect-policy.js +334 -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/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 +493 -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 +45 -0
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.js +136 -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 +239 -61
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.d.ts +27 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +554 -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 +2 -0
- package/dist/harness/extension/plugin-ecosystem/tools/index.js +2 -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 +14 -12
- package/dist/harness/index.js +9 -6
- 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 +6 -3
- package/dist/harness/knowledge/index.d.ts +2 -2
- package/dist/harness/knowledge/index.js +1 -1
- package/dist/harness/knowledge/ingest.js +4 -1
- package/dist/harness/knowledge/job-control-state.js +4 -4
- package/dist/harness/knowledge/job-control.js +11 -11
- 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/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-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 +23 -1
- 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 +57 -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 +101 -16
- package/dist/harness/run/runner.js +556 -158
- package/dist/harness/session/attachments/llm-intent.js +17 -17
- package/dist/harness/session/history/port.js +1 -0
- package/dist/harness/session/in-memory-store.d.ts +1 -0
- package/dist/harness/session/in-memory-store.js +22 -1
- 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/types.d.ts +35 -0
- package/dist/harness/shared/events/agent-event-map.d.ts +13 -0
- package/dist/harness/shared/types/agent-definition.d.ts +23 -0
- package/dist/index.d.ts +23 -9
- package/dist/index.js +10 -2
- 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 +11 -0
- package/dist/integration/storage/jsonl.js +148 -39
- package/dist/integration/storage/session-index.js +63 -8
- 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/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,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
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* StrategyRouter 类型定义
|
|
3
|
-
*/
|
|
4
|
-
/** 任务复杂度 */
|
|
5
|
-
export type TaskComplexity = 'simple' | 'moderate' | 'complex';
|
|
6
|
-
/** 任务类型 */
|
|
7
|
-
export type TaskCategory = 'question' | 'lookup' | 'analysis' | 'creation' | 'coding' | 'planning' | 'conversation' | 'unknown';
|
|
8
|
-
/** 任务分类结果 */
|
|
9
|
-
export interface TaskClassification {
|
|
10
|
-
/** 任务类型 */
|
|
11
|
-
category: TaskCategory;
|
|
12
|
-
/** 复杂度 */
|
|
13
|
-
complexity: TaskComplexity;
|
|
14
|
-
/** 置信度 0-1 */
|
|
15
|
-
confidence: number;
|
|
16
|
-
/** 是否需要工具 */
|
|
17
|
-
needsTools: boolean;
|
|
18
|
-
/** 是否需要规划 */
|
|
19
|
-
needsPlanning: boolean;
|
|
20
|
-
/** 推理 */
|
|
21
|
-
reasoning?: string;
|
|
22
|
-
}
|
|
23
|
-
/** 推理策略类型 */
|
|
24
|
-
export type StrategyKind = 'direct' | 'chain_of_thought' | 'plan_and_execute' | 'tool_use' | 'reflect' | 'multi_agent';
|
|
25
|
-
/** 推理策略 */
|
|
26
|
-
export interface Strategy {
|
|
27
|
-
/** 策略类型 */
|
|
28
|
-
kind: StrategyKind;
|
|
29
|
-
/** 策略名称 */
|
|
30
|
-
name: string;
|
|
31
|
-
/** 策略描述 */
|
|
32
|
-
description: string;
|
|
33
|
-
/** 系统提示词补充 */
|
|
34
|
-
systemPromptAddition?: string;
|
|
35
|
-
/** 最大迭代次数 */
|
|
36
|
-
maxIterations?: number;
|
|
37
|
-
/** 是否需要反思 */
|
|
38
|
-
needsReflection?: boolean;
|
|
39
|
-
/** 温度调整 */
|
|
40
|
-
temperature?: number;
|
|
41
|
-
}
|
|
42
|
-
export interface TaskClassifier {
|
|
43
|
-
readonly name: string;
|
|
44
|
-
classify(input: string, context?: Record<string, unknown>): Promise<TaskClassification>;
|
|
45
|
-
}
|
|
46
|
-
export interface StrategyRouter {
|
|
47
|
-
readonly name: string;
|
|
48
|
-
select(classification: TaskClassification): Strategy;
|
|
49
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WorkflowEngine — Workflow 执行引擎
|
|
3
|
-
*
|
|
4
|
-
* 确定性多步骤编排(experimental)。
|
|
5
|
-
* 支持顺序执行、条件分支、循环、并行、错误处理。
|
|
6
|
-
* 与 SessionTask 状态机无关;长流水线如需用户可见任务,经 SessionTaskService 单向登记。
|
|
7
|
-
*/
|
|
8
|
-
import type { WorkflowDefinition, WorkflowStep, WorkflowInstance, WorkflowContext, WorkflowEvent, StepExecutor } from './types.js';
|
|
9
|
-
/** WorkflowEngine 配置 */
|
|
10
|
-
export interface WorkflowEngineConfig {
|
|
11
|
-
/** 步骤执行器 */
|
|
12
|
-
stepExecutor: StepExecutor;
|
|
13
|
-
/** 最大并发步骤数(用于并行) */
|
|
14
|
-
maxConcurrency?: number;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* WorkflowEngine
|
|
18
|
-
*
|
|
19
|
-
* 执行 Workflow 定义,管理实例生命周期。
|
|
20
|
-
*/
|
|
21
|
-
export declare class WorkflowEngine {
|
|
22
|
-
private config;
|
|
23
|
-
private definitions;
|
|
24
|
-
private instances;
|
|
25
|
-
constructor(config: WorkflowEngineConfig);
|
|
26
|
-
/**
|
|
27
|
-
* 注册 Workflow 定义
|
|
28
|
-
*/
|
|
29
|
-
register(definition: WorkflowDefinition): void;
|
|
30
|
-
/**
|
|
31
|
-
* 获取 Workflow 定义
|
|
32
|
-
*/
|
|
33
|
-
getDefinition(id: string): WorkflowDefinition | undefined;
|
|
34
|
-
/**
|
|
35
|
-
* 列出所有已注册的 Workflow
|
|
36
|
-
*/
|
|
37
|
-
listDefinitions(): WorkflowDefinition[];
|
|
38
|
-
/**
|
|
39
|
-
* 创建执行实例
|
|
40
|
-
*/
|
|
41
|
-
createInstance(workflowId: string, variables?: Record<string, unknown>): WorkflowInstance;
|
|
42
|
-
/**
|
|
43
|
-
* 获取实例
|
|
44
|
-
*/
|
|
45
|
-
getInstance(id: string): WorkflowInstance | undefined;
|
|
46
|
-
/**
|
|
47
|
-
* 列出所有实例
|
|
48
|
-
*/
|
|
49
|
-
listInstances(): WorkflowInstance[];
|
|
50
|
-
/**
|
|
51
|
-
* 执行 Workflow
|
|
52
|
-
*
|
|
53
|
-
* @param instanceId - 实例 ID
|
|
54
|
-
* @yields WorkflowEvent 事件流
|
|
55
|
-
*/
|
|
56
|
-
execute(instanceId: string): AsyncGenerator<WorkflowEvent>;
|
|
57
|
-
/**
|
|
58
|
-
* 暂停实例
|
|
59
|
-
*/
|
|
60
|
-
pause(instanceId: string): void;
|
|
61
|
-
/**
|
|
62
|
-
* 恢复实例
|
|
63
|
-
*/
|
|
64
|
-
resume(instanceId: string): void;
|
|
65
|
-
/**
|
|
66
|
-
* 取消实例
|
|
67
|
-
*/
|
|
68
|
-
cancel(instanceId: string): void;
|
|
69
|
-
/**
|
|
70
|
-
* 执行步骤(带重试)
|
|
71
|
-
*/
|
|
72
|
-
private executeWithRetry;
|
|
73
|
-
/**
|
|
74
|
-
* 解析下一步
|
|
75
|
-
*/
|
|
76
|
-
private resolveNext;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* 简单步骤执行器
|
|
80
|
-
*
|
|
81
|
-
* 用于测试和简单场景。
|
|
82
|
-
* 实际使用时应替换为集成 Agent 的执行器。
|
|
83
|
-
*/
|
|
84
|
-
export declare class SimpleStepExecutor implements StepExecutor {
|
|
85
|
-
execute(step: WorkflowStep, context: WorkflowContext): Promise<unknown>;
|
|
86
|
-
}
|
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WorkflowEngine — Workflow 执行引擎
|
|
3
|
-
*
|
|
4
|
-
* 确定性多步骤编排(experimental)。
|
|
5
|
-
* 支持顺序执行、条件分支、循环、并行、错误处理。
|
|
6
|
-
* 与 SessionTask 状态机无关;长流水线如需用户可见任务,经 SessionTaskService 单向登记。
|
|
7
|
-
*/
|
|
8
|
-
import { randomUUID } from 'node:crypto';
|
|
9
|
-
/**
|
|
10
|
-
* WorkflowEngine
|
|
11
|
-
*
|
|
12
|
-
* 执行 Workflow 定义,管理实例生命周期。
|
|
13
|
-
*/
|
|
14
|
-
export class WorkflowEngine {
|
|
15
|
-
config;
|
|
16
|
-
definitions = new Map();
|
|
17
|
-
instances = new Map();
|
|
18
|
-
constructor(config) {
|
|
19
|
-
this.config = config;
|
|
20
|
-
}
|
|
21
|
-
// ================================================================
|
|
22
|
-
// 定义管理
|
|
23
|
-
// ================================================================
|
|
24
|
-
/**
|
|
25
|
-
* 注册 Workflow 定义
|
|
26
|
-
*/
|
|
27
|
-
register(definition) {
|
|
28
|
-
this.definitions.set(definition.id, definition);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* 获取 Workflow 定义
|
|
32
|
-
*/
|
|
33
|
-
getDefinition(id) {
|
|
34
|
-
return this.definitions.get(id);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* 列出所有已注册的 Workflow
|
|
38
|
-
*/
|
|
39
|
-
listDefinitions() {
|
|
40
|
-
return Array.from(this.definitions.values());
|
|
41
|
-
}
|
|
42
|
-
// ================================================================
|
|
43
|
-
// 实例管理
|
|
44
|
-
// ================================================================
|
|
45
|
-
/**
|
|
46
|
-
* 创建执行实例
|
|
47
|
-
*/
|
|
48
|
-
createInstance(workflowId, variables) {
|
|
49
|
-
const def = this.definitions.get(workflowId);
|
|
50
|
-
if (!def) {
|
|
51
|
-
throw new Error(`Workflow "${workflowId}" not found`);
|
|
52
|
-
}
|
|
53
|
-
const instance = {
|
|
54
|
-
id: `wf-${randomUUID().slice(0, 8)}`,
|
|
55
|
-
definitionId: workflowId,
|
|
56
|
-
status: 'pending',
|
|
57
|
-
currentStep: def.startStep,
|
|
58
|
-
variables: new Map(Object.entries(def.variables ?? {})),
|
|
59
|
-
history: [],
|
|
60
|
-
startedAt: Date.now(),
|
|
61
|
-
};
|
|
62
|
-
// 合并调用方提供的变量
|
|
63
|
-
if (variables) {
|
|
64
|
-
for (const [key, value] of Object.entries(variables)) {
|
|
65
|
-
instance.variables.set(key, value);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
this.instances.set(instance.id, instance);
|
|
69
|
-
return instance;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* 获取实例
|
|
73
|
-
*/
|
|
74
|
-
getInstance(id) {
|
|
75
|
-
return this.instances.get(id);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* 列出所有实例
|
|
79
|
-
*/
|
|
80
|
-
listInstances() {
|
|
81
|
-
return Array.from(this.instances.values());
|
|
82
|
-
}
|
|
83
|
-
// ================================================================
|
|
84
|
-
// 执行
|
|
85
|
-
// ================================================================
|
|
86
|
-
/**
|
|
87
|
-
* 执行 Workflow
|
|
88
|
-
*
|
|
89
|
-
* @param instanceId - 实例 ID
|
|
90
|
-
* @yields WorkflowEvent 事件流
|
|
91
|
-
*/
|
|
92
|
-
async *execute(instanceId) {
|
|
93
|
-
const instance = this.instances.get(instanceId);
|
|
94
|
-
if (!instance) {
|
|
95
|
-
throw new Error(`Workflow instance "${instanceId}" not found`);
|
|
96
|
-
}
|
|
97
|
-
const def = this.definitions.get(instance.definitionId);
|
|
98
|
-
if (!def) {
|
|
99
|
-
throw new Error(`Workflow definition "${instance.definitionId}" not found`);
|
|
100
|
-
}
|
|
101
|
-
instance.status = 'running';
|
|
102
|
-
while (instance.currentStep) {
|
|
103
|
-
const step = def.steps.find(s => s.id === instance.currentStep);
|
|
104
|
-
if (!step) {
|
|
105
|
-
yield { type: 'workflow.fail', instanceId, data: { error: `Step "${instance.currentStep}" not found` } };
|
|
106
|
-
instance.status = 'failed';
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
yield { type: 'step.start', instanceId, stepId: step.id };
|
|
110
|
-
const startTime = Date.now();
|
|
111
|
-
step.status = 'running';
|
|
112
|
-
try {
|
|
113
|
-
// 创建执行上下文
|
|
114
|
-
const context = {
|
|
115
|
-
variables: instance.variables,
|
|
116
|
-
history: instance.history,
|
|
117
|
-
};
|
|
118
|
-
// 执行步骤(支持重试)
|
|
119
|
-
const result = await this.executeWithRetry(step, context);
|
|
120
|
-
// 记录执行历史
|
|
121
|
-
const execution = {
|
|
122
|
-
stepId: step.id,
|
|
123
|
-
taskId: step.taskId,
|
|
124
|
-
status: 'completed',
|
|
125
|
-
output: result,
|
|
126
|
-
duration: Date.now() - startTime,
|
|
127
|
-
};
|
|
128
|
-
instance.history.push(execution);
|
|
129
|
-
step.status = 'completed';
|
|
130
|
-
yield { type: 'step.complete', instanceId, stepId: step.id, data: result };
|
|
131
|
-
// 确定下一步
|
|
132
|
-
const nextStep = this.resolveNext(step, result, { variables: instance.variables, history: instance.history });
|
|
133
|
-
instance.currentStep = nextStep ?? '';
|
|
134
|
-
}
|
|
135
|
-
catch (error) {
|
|
136
|
-
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
137
|
-
// 记录失败
|
|
138
|
-
const execution = {
|
|
139
|
-
stepId: step.id,
|
|
140
|
-
taskId: step.taskId,
|
|
141
|
-
status: 'failed',
|
|
142
|
-
error: errorMsg,
|
|
143
|
-
duration: Date.now() - startTime,
|
|
144
|
-
};
|
|
145
|
-
instance.history.push(execution);
|
|
146
|
-
step.status = 'failed';
|
|
147
|
-
yield { type: 'step.fail', instanceId, stepId: step.id, data: { error: errorMsg } };
|
|
148
|
-
// 错误处理
|
|
149
|
-
if (step.onError === 'skip') {
|
|
150
|
-
// 跳过当前步骤,继续下一步
|
|
151
|
-
const nextStep = this.resolveNext(step, undefined, { variables: instance.variables, history: instance.history });
|
|
152
|
-
instance.currentStep = nextStep ?? '';
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
else if (step.onError === 'abort' || !step.onError) {
|
|
156
|
-
// 中止 Workflow
|
|
157
|
-
instance.status = 'failed';
|
|
158
|
-
instance.completedAt = Date.now();
|
|
159
|
-
yield { type: 'workflow.fail', instanceId, data: { error: errorMsg } };
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
// 跳转到指定步骤
|
|
164
|
-
instance.currentStep = step.onError;
|
|
165
|
-
continue;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
// 所有步骤完成
|
|
170
|
-
instance.status = 'completed';
|
|
171
|
-
instance.completedAt = Date.now();
|
|
172
|
-
yield { type: 'workflow.complete', instanceId };
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* 暂停实例
|
|
176
|
-
*/
|
|
177
|
-
pause(instanceId) {
|
|
178
|
-
const instance = this.instances.get(instanceId);
|
|
179
|
-
if (!instance)
|
|
180
|
-
throw new Error(`Instance "${instanceId}" not found`);
|
|
181
|
-
if (instance.status !== 'running') {
|
|
182
|
-
throw new Error(`Instance "${instanceId}" is not running`);
|
|
183
|
-
}
|
|
184
|
-
instance.status = 'paused';
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* 恢复实例
|
|
188
|
-
*/
|
|
189
|
-
resume(instanceId) {
|
|
190
|
-
const instance = this.instances.get(instanceId);
|
|
191
|
-
if (!instance)
|
|
192
|
-
throw new Error(`Instance "${instanceId}" not found`);
|
|
193
|
-
if (instance.status !== 'paused') {
|
|
194
|
-
throw new Error(`Instance "${instanceId}" is not paused`);
|
|
195
|
-
}
|
|
196
|
-
instance.status = 'running';
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* 取消实例
|
|
200
|
-
*/
|
|
201
|
-
cancel(instanceId) {
|
|
202
|
-
const instance = this.instances.get(instanceId);
|
|
203
|
-
if (!instance)
|
|
204
|
-
throw new Error(`Instance "${instanceId}" not found`);
|
|
205
|
-
instance.status = 'cancelled';
|
|
206
|
-
instance.completedAt = Date.now();
|
|
207
|
-
}
|
|
208
|
-
// ================================================================
|
|
209
|
-
// 内部方法
|
|
210
|
-
// ================================================================
|
|
211
|
-
/**
|
|
212
|
-
* 执行步骤(带重试)
|
|
213
|
-
*/
|
|
214
|
-
async executeWithRetry(step, context) {
|
|
215
|
-
const maxRetries = step.retryPolicy?.maxRetries ?? 0;
|
|
216
|
-
const delayMs = step.retryPolicy?.delayMs ?? 0;
|
|
217
|
-
let lastError;
|
|
218
|
-
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
219
|
-
try {
|
|
220
|
-
return await this.config.stepExecutor.execute(step, context);
|
|
221
|
-
}
|
|
222
|
-
catch (error) {
|
|
223
|
-
lastError = error instanceof Error ? error : new Error(String(error));
|
|
224
|
-
if (attempt < maxRetries && delayMs > 0) {
|
|
225
|
-
await new Promise(r => setTimeout(r, delayMs));
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
throw lastError;
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* 解析下一步
|
|
233
|
-
*/
|
|
234
|
-
resolveNext(step, result, context) {
|
|
235
|
-
if (!step.next)
|
|
236
|
-
return undefined;
|
|
237
|
-
// 顺序执行
|
|
238
|
-
if (typeof step.next === 'string')
|
|
239
|
-
return step.next;
|
|
240
|
-
// 条件分支
|
|
241
|
-
for (const branch of step.next) {
|
|
242
|
-
let conditionResult = false;
|
|
243
|
-
if (typeof branch.condition === 'function') {
|
|
244
|
-
conditionResult = branch.condition({ ...context, currentResult: result });
|
|
245
|
-
}
|
|
246
|
-
else if (typeof branch.condition === 'string') {
|
|
247
|
-
// 简单表达式求值(安全限制)
|
|
248
|
-
try {
|
|
249
|
-
const fn = new Function('context', `return ${branch.condition}`);
|
|
250
|
-
conditionResult = fn({ ...context, currentResult: result });
|
|
251
|
-
}
|
|
252
|
-
catch {
|
|
253
|
-
conditionResult = false;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
if (conditionResult) {
|
|
257
|
-
return branch.target;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
return undefined;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
// ================================================================
|
|
264
|
-
// 内置步骤执行器
|
|
265
|
-
// ================================================================
|
|
266
|
-
/**
|
|
267
|
-
* 简单步骤执行器
|
|
268
|
-
*
|
|
269
|
-
* 用于测试和简单场景。
|
|
270
|
-
* 实际使用时应替换为集成 Agent 的执行器。
|
|
271
|
-
*/
|
|
272
|
-
export class SimpleStepExecutor {
|
|
273
|
-
async execute(step, context) {
|
|
274
|
-
switch (step.type) {
|
|
275
|
-
case 'agent':
|
|
276
|
-
return { type: 'agent', result: `Agent executed: ${step.config.prompt ?? step.name}` };
|
|
277
|
-
case 'tool':
|
|
278
|
-
return { type: 'tool', result: `Tool executed: ${step.config.toolName}` };
|
|
279
|
-
case 'condition':
|
|
280
|
-
if (typeof step.config.expression === 'string') {
|
|
281
|
-
try {
|
|
282
|
-
const fn = new Function('context', `return ${step.config.expression}`);
|
|
283
|
-
return { type: 'condition', result: fn(context) };
|
|
284
|
-
}
|
|
285
|
-
catch {
|
|
286
|
-
return { type: 'condition', result: false };
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
return { type: 'condition', result: false };
|
|
290
|
-
case 'loop':
|
|
291
|
-
return { type: 'loop', result: 'Loop completed' };
|
|
292
|
-
case 'human':
|
|
293
|
-
return { type: 'human', result: 'Human approval required' };
|
|
294
|
-
default:
|
|
295
|
-
return { type: step.type, result: 'Executed' };
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Workflow 引擎
|
|
3
|
-
*
|
|
4
|
-
* 确定性多步骤编排(experimental)。
|
|
5
|
-
* 支持顺序执行、条件分支、循环、并行、错误处理。
|
|
6
|
-
*/
|
|
7
|
-
export { WorkflowEngine, SimpleStepExecutor } from './engine.js';
|
|
8
|
-
export type { WorkflowEngineConfig } from './engine.js';
|
|
9
|
-
export type { WorkflowDefinition, WorkflowStep, WorkflowInstance, WorkflowContext, WorkflowEvent, WorkflowStatus, StepType, StepStatus, StepExecution, StepExecutor, StepConfig, ConditionalNext, RetryPolicy, } from './types.js';
|