@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,167 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LLMPlanner — LLM 驱动的规划器
|
|
3
|
-
*
|
|
4
|
-
* 用 LLM 分析事件和状态,决定下一步行动。
|
|
5
|
-
* 比规则驱动更灵活,但更慢、更贵。
|
|
6
|
-
*
|
|
7
|
-
* 适用场景:
|
|
8
|
-
* - 复杂的用户请求(需要理解意图)
|
|
9
|
-
* - 目标分解(大任务拆成小步骤)
|
|
10
|
-
* - 异常情况处理(规则没覆盖的场景)
|
|
11
|
-
*/
|
|
12
|
-
import { randomUUID } from 'node:crypto';
|
|
13
|
-
// ── LLMPlanner ──
|
|
14
|
-
/**
|
|
15
|
-
* LLM 驱动的规划器
|
|
16
|
-
*
|
|
17
|
-
* 将事件和状态序列化为 prompt,让 LLM 返回结构化的计划。
|
|
18
|
-
*/
|
|
19
|
-
export class LLMPlanner {
|
|
20
|
-
name = 'llm-planner';
|
|
21
|
-
_model;
|
|
22
|
-
_modelName;
|
|
23
|
-
_systemPrompt;
|
|
24
|
-
_temperature;
|
|
25
|
-
_maxTokens;
|
|
26
|
-
constructor(config) {
|
|
27
|
-
this._model = config.model;
|
|
28
|
-
this._modelName = config.modelName;
|
|
29
|
-
this._systemPrompt = config.systemPrompt ?? DEFAULT_PLANNER_PROMPT;
|
|
30
|
-
this._temperature = config.temperature ?? 0.3;
|
|
31
|
-
this._maxTokens = config.maxTokens ?? 2000;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* 分析事件,让 LLM 决定下一步
|
|
35
|
-
*/
|
|
36
|
-
async decide(events, state) {
|
|
37
|
-
const prompt = this._buildDecidePrompt(events, state);
|
|
38
|
-
const response = await this._callLLM(prompt);
|
|
39
|
-
return this._parsePlan(response, 'decide events');
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* 将目标分解为可执行步骤
|
|
43
|
-
*/
|
|
44
|
-
async decompose(goal, state) {
|
|
45
|
-
const prompt = this._buildDecomposePrompt(goal, state);
|
|
46
|
-
const response = await this._callLLM(prompt);
|
|
47
|
-
return this._parsePlan(response, goal);
|
|
48
|
-
}
|
|
49
|
-
// ── 内部方法 ──
|
|
50
|
-
_buildDecidePrompt(events, state) {
|
|
51
|
-
const eventSummary = events.map(e => `- [${e.type}] ${e.data?.content ?? e.data?.description ?? JSON.stringify(e.data ?? {}).slice(0, 200)}`).join('\n');
|
|
52
|
-
return `你是一个 Agent 规划器。分析以下事件,决定下一步行动。
|
|
53
|
-
|
|
54
|
-
## 待处理事件
|
|
55
|
-
${eventSummary}
|
|
56
|
-
|
|
57
|
-
## Agent 状态
|
|
58
|
-
- 活跃计划: ${state.activePlan ? state.activePlan.goal : '无'}
|
|
59
|
-
- 最近执行次数: ${state.stats.totalExecutions}
|
|
60
|
-
- 最近错误次数: ${state.stats.totalErrors}
|
|
61
|
-
|
|
62
|
-
## 输出格式
|
|
63
|
-
返回 JSON,格式如下:
|
|
64
|
-
{
|
|
65
|
-
"goal": "计划目标",
|
|
66
|
-
"steps": [
|
|
67
|
-
{
|
|
68
|
-
"description": "步骤描述",
|
|
69
|
-
"type": "llm_call | tool_call | wait | custom",
|
|
70
|
-
"params": {}
|
|
71
|
-
}
|
|
72
|
-
]
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
如果不需要任何行动,返回空 steps 数组。
|
|
76
|
-
只返回 JSON,不要其他文字。`;
|
|
77
|
-
}
|
|
78
|
-
_buildDecomposePrompt(goal, state) {
|
|
79
|
-
return `你是一个 Agent 规划器。将以下目标分解为可执行的步骤。
|
|
80
|
-
|
|
81
|
-
## 目标
|
|
82
|
-
${goal}
|
|
83
|
-
|
|
84
|
-
## Agent 状态
|
|
85
|
-
- 最近执行次数: ${state.stats.totalExecutions}
|
|
86
|
-
|
|
87
|
-
## 输出格式
|
|
88
|
-
返回 JSON,格式如下:
|
|
89
|
-
{
|
|
90
|
-
"goal": "${goal}",
|
|
91
|
-
"steps": [
|
|
92
|
-
{
|
|
93
|
-
"description": "步骤描述",
|
|
94
|
-
"type": "llm_call | tool_call | wait | custom",
|
|
95
|
-
"params": {}
|
|
96
|
-
}
|
|
97
|
-
]
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
步骤应该具体、可执行、有序。
|
|
101
|
-
只返回 JSON,不要其他文字。`;
|
|
102
|
-
}
|
|
103
|
-
async _callLLM(prompt) {
|
|
104
|
-
const request = {
|
|
105
|
-
messages: [
|
|
106
|
-
{ role: 'system', content: this._systemPrompt },
|
|
107
|
-
{ role: 'user', content: prompt },
|
|
108
|
-
],
|
|
109
|
-
temperature: this._temperature,
|
|
110
|
-
maxTokens: this._maxTokens,
|
|
111
|
-
model: this._modelName,
|
|
112
|
-
};
|
|
113
|
-
const response = await this._model.chat(request);
|
|
114
|
-
return response.content;
|
|
115
|
-
}
|
|
116
|
-
_parsePlan(response, goal) {
|
|
117
|
-
try {
|
|
118
|
-
// 尝试从响应中提取 JSON
|
|
119
|
-
const jsonMatch = response.match(/\{[\s\S]*\}/);
|
|
120
|
-
if (!jsonMatch) {
|
|
121
|
-
return this._emptyPlan(goal, 'No JSON in response');
|
|
122
|
-
}
|
|
123
|
-
const parsed = JSON.parse(jsonMatch[0]);
|
|
124
|
-
const steps = (parsed.steps ?? []).map((s, i) => ({
|
|
125
|
-
id: `step-${randomUUID().slice(0, 8)}`,
|
|
126
|
-
description: s.description ?? `Step ${i + 1}`,
|
|
127
|
-
type: this._validateStepType(s.type),
|
|
128
|
-
params: s.params ?? {},
|
|
129
|
-
status: 'pending',
|
|
130
|
-
}));
|
|
131
|
-
return {
|
|
132
|
-
id: `plan-${randomUUID().slice(0, 8)}`,
|
|
133
|
-
goal: parsed.goal ?? goal,
|
|
134
|
-
steps,
|
|
135
|
-
currentStepIndex: 0,
|
|
136
|
-
status: 'pending',
|
|
137
|
-
createdAt: Date.now(),
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
catch {
|
|
141
|
-
return this._emptyPlan(goal, 'Failed to parse LLM response');
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
_validateStepType(type) {
|
|
145
|
-
const valid = ['llm_call', 'tool_call', 'spawn_agent', 'wait', 'custom'];
|
|
146
|
-
return valid.includes(type) ? type : 'llm_call';
|
|
147
|
-
}
|
|
148
|
-
_emptyPlan(goal, reason) {
|
|
149
|
-
return {
|
|
150
|
-
id: `plan-${randomUUID().slice(0, 8)}`,
|
|
151
|
-
goal,
|
|
152
|
-
steps: [],
|
|
153
|
-
currentStepIndex: 0,
|
|
154
|
-
status: 'completed',
|
|
155
|
-
createdAt: Date.now(),
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
// ── 默认系统提示 ──
|
|
160
|
-
const DEFAULT_PLANNER_PROMPT = `你是一个 Agent 规划器。你的任务是分析事件并决定 Agent 应该做什么。
|
|
161
|
-
|
|
162
|
-
规则:
|
|
163
|
-
1. 只生成必要的步骤,避免冗余
|
|
164
|
-
2. 每个步骤应该是独立可执行的
|
|
165
|
-
3. 优先使用已有的工具和能力
|
|
166
|
-
4. 遇到不确定的情况,倾向于询问用户而不是猜测
|
|
167
|
-
5. 安全事件需要立即响应`;
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* RulePlanner — 规则驱动的规划器
|
|
3
|
-
*
|
|
4
|
-
* 用 if-then 规则处理常见事件,不需要 LLM 调用。
|
|
5
|
-
* 快速、低成本、可预测。
|
|
6
|
-
*
|
|
7
|
-
* 适用场景:
|
|
8
|
-
* - 用户消息 → 转发给 LLM 引擎处理
|
|
9
|
-
* - 定时事件 → 执行预定义任务
|
|
10
|
-
* - 安全事件 → 立即响应
|
|
11
|
-
* - 子进程回报 → 更新状态
|
|
12
|
-
*
|
|
13
|
-
* 复杂场景 fallback 到 LLMPlanner。
|
|
14
|
-
*/
|
|
15
|
-
import type { Planner, Plan, PlanStep, AgentState } from '../cognitive-loop.js';
|
|
16
|
-
import type { EventBusAgentEvent as AgentEvent } from '@octopi-agent/core/index.js';
|
|
17
|
-
/** 规则匹配条件 */
|
|
18
|
-
export interface RuleCondition {
|
|
19
|
-
/** 事件类型(支持前缀匹配:'user.*' 匹配所有 user 开头的事件) */
|
|
20
|
-
eventType?: string | string[];
|
|
21
|
-
/** 自定义条件函数 */
|
|
22
|
-
custom?: (event: AgentEvent, state: AgentState) => boolean;
|
|
23
|
-
}
|
|
24
|
-
/** 规则动作 */
|
|
25
|
-
export interface RuleAction {
|
|
26
|
-
/** 步骤类型 */
|
|
27
|
-
type: PlanStep['type'];
|
|
28
|
-
/** 步骤描述 */
|
|
29
|
-
description: string;
|
|
30
|
-
/** 步骤参数 */
|
|
31
|
-
params?: Record<string, unknown>;
|
|
32
|
-
}
|
|
33
|
-
/** 规则 */
|
|
34
|
-
export interface Rule {
|
|
35
|
-
/** 规则 ID */
|
|
36
|
-
id: string;
|
|
37
|
-
/** 规则名称 */
|
|
38
|
-
name: string;
|
|
39
|
-
/** 优先级(数字越大越先执行) */
|
|
40
|
-
priority: number;
|
|
41
|
-
/** 匹配条件 */
|
|
42
|
-
when: RuleCondition;
|
|
43
|
-
/** 匹配后生成的步骤 */
|
|
44
|
-
then: RuleAction[];
|
|
45
|
-
/** 是否只匹配一次 */
|
|
46
|
-
once?: boolean;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* 规则驱动的规划器
|
|
50
|
-
*
|
|
51
|
-
* 按优先级遍历规则,第一个匹配的规则生成计划。
|
|
52
|
-
*/
|
|
53
|
-
export declare class RulePlanner implements Planner {
|
|
54
|
-
readonly name = "rule-planner";
|
|
55
|
-
private _rules;
|
|
56
|
-
private _firedOnce;
|
|
57
|
-
constructor(rules?: Rule[]);
|
|
58
|
-
/**
|
|
59
|
-
* 添加规则
|
|
60
|
-
*/
|
|
61
|
-
addRule(rule: Rule): void;
|
|
62
|
-
/**
|
|
63
|
-
* 移除规则
|
|
64
|
-
*/
|
|
65
|
-
removeRule(ruleId: string): void;
|
|
66
|
-
/**
|
|
67
|
-
* 分析事件,按规则生成计划
|
|
68
|
-
*/
|
|
69
|
-
decide(events: AgentEvent[], state: AgentState): Promise<Plan>;
|
|
70
|
-
/**
|
|
71
|
-
* 目标分解 — 规则驱动的规划器不支持目标分解
|
|
72
|
-
* 返回单步骤计划,由调用方决定如何处理
|
|
73
|
-
*/
|
|
74
|
-
decompose(goal: string, _state: AgentState): Promise<Plan>;
|
|
75
|
-
private _matchRule;
|
|
76
|
-
private _matchCondition;
|
|
77
|
-
}
|
|
78
|
-
/** 用户消息规则:转发给 LLM 引擎 */
|
|
79
|
-
export declare const USER_MESSAGE_RULE: Rule;
|
|
80
|
-
/** 安全事件规则:立即标记 */
|
|
81
|
-
export declare const SECURITY_EVENT_RULE: Rule;
|
|
82
|
-
/** 空闲事件规则:无操作 */
|
|
83
|
-
export declare const IDLE_RULE: Rule;
|
|
84
|
-
/** 获取默认规则集 */
|
|
85
|
-
export declare function getDefaultRules(): Rule[];
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* RulePlanner — 规则驱动的规划器
|
|
3
|
-
*
|
|
4
|
-
* 用 if-then 规则处理常见事件,不需要 LLM 调用。
|
|
5
|
-
* 快速、低成本、可预测。
|
|
6
|
-
*
|
|
7
|
-
* 适用场景:
|
|
8
|
-
* - 用户消息 → 转发给 LLM 引擎处理
|
|
9
|
-
* - 定时事件 → 执行预定义任务
|
|
10
|
-
* - 安全事件 → 立即响应
|
|
11
|
-
* - 子进程回报 → 更新状态
|
|
12
|
-
*
|
|
13
|
-
* 复杂场景 fallback 到 LLMPlanner。
|
|
14
|
-
*/
|
|
15
|
-
import { randomUUID } from 'node:crypto';
|
|
16
|
-
// ── RulePlanner ──
|
|
17
|
-
/**
|
|
18
|
-
* 规则驱动的规划器
|
|
19
|
-
*
|
|
20
|
-
* 按优先级遍历规则,第一个匹配的规则生成计划。
|
|
21
|
-
*/
|
|
22
|
-
export class RulePlanner {
|
|
23
|
-
name = 'rule-planner';
|
|
24
|
-
_rules = [];
|
|
25
|
-
_firedOnce = new Set();
|
|
26
|
-
constructor(rules) {
|
|
27
|
-
if (rules) {
|
|
28
|
-
this._rules = [...rules].sort((a, b) => b.priority - a.priority);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* 添加规则
|
|
33
|
-
*/
|
|
34
|
-
addRule(rule) {
|
|
35
|
-
this._rules.push(rule);
|
|
36
|
-
this._rules.sort((a, b) => b.priority - a.priority);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* 移除规则
|
|
40
|
-
*/
|
|
41
|
-
removeRule(ruleId) {
|
|
42
|
-
this._rules = this._rules.filter(r => r.id !== ruleId);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* 分析事件,按规则生成计划
|
|
46
|
-
*/
|
|
47
|
-
async decide(events, state) {
|
|
48
|
-
const steps = [];
|
|
49
|
-
for (const event of events) {
|
|
50
|
-
const rule = this._matchRule(event, state);
|
|
51
|
-
if (rule) {
|
|
52
|
-
// 标记 once 规则已触发
|
|
53
|
-
if (rule.once) {
|
|
54
|
-
this._firedOnce.add(rule.id);
|
|
55
|
-
}
|
|
56
|
-
// 生成步骤
|
|
57
|
-
for (const action of rule.then) {
|
|
58
|
-
steps.push({
|
|
59
|
-
id: `step-${randomUUID().slice(0, 8)}`,
|
|
60
|
-
description: action.description,
|
|
61
|
-
type: action.type,
|
|
62
|
-
params: {
|
|
63
|
-
...action.params,
|
|
64
|
-
triggerEvent: event,
|
|
65
|
-
},
|
|
66
|
-
status: 'pending',
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return {
|
|
72
|
-
id: `plan-${randomUUID().slice(0, 8)}`,
|
|
73
|
-
goal: steps.length > 0 ? 'handle events by rules' : 'no matching rule',
|
|
74
|
-
steps,
|
|
75
|
-
currentStepIndex: 0,
|
|
76
|
-
status: 'pending',
|
|
77
|
-
createdAt: Date.now(),
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* 目标分解 — 规则驱动的规划器不支持目标分解
|
|
82
|
-
* 返回单步骤计划,由调用方决定如何处理
|
|
83
|
-
*/
|
|
84
|
-
async decompose(goal, _state) {
|
|
85
|
-
return {
|
|
86
|
-
id: `plan-${randomUUID().slice(0, 8)}`,
|
|
87
|
-
goal,
|
|
88
|
-
steps: [{
|
|
89
|
-
id: `step-${randomUUID().slice(0, 8)}`,
|
|
90
|
-
description: goal,
|
|
91
|
-
type: 'llm_call',
|
|
92
|
-
params: { prompt: goal },
|
|
93
|
-
status: 'pending',
|
|
94
|
-
}],
|
|
95
|
-
currentStepIndex: 0,
|
|
96
|
-
status: 'pending',
|
|
97
|
-
createdAt: Date.now(),
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
// ── 内部方法 ──
|
|
101
|
-
_matchRule(event, state) {
|
|
102
|
-
for (const rule of this._rules) {
|
|
103
|
-
// 跳过已触发的 once 规则
|
|
104
|
-
if (rule.once && this._firedOnce.has(rule.id))
|
|
105
|
-
continue;
|
|
106
|
-
if (this._matchCondition(rule.when, event, state)) {
|
|
107
|
-
return rule;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
_matchCondition(condition, event, state) {
|
|
113
|
-
// 事件类型匹配
|
|
114
|
-
if (condition.eventType) {
|
|
115
|
-
const types = Array.isArray(condition.eventType) ? condition.eventType : [condition.eventType];
|
|
116
|
-
const matched = types.some(t => {
|
|
117
|
-
if (t.endsWith('*')) {
|
|
118
|
-
return event.type.startsWith(t.slice(0, -1));
|
|
119
|
-
}
|
|
120
|
-
return event.type === t;
|
|
121
|
-
});
|
|
122
|
-
if (!matched)
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
// 自定义条件
|
|
126
|
-
if (condition.custom) {
|
|
127
|
-
if (!condition.custom(event, state))
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
return true;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
// ── 内置规则 ──
|
|
134
|
-
/** 用户消息规则:转发给 LLM 引擎 */
|
|
135
|
-
export const USER_MESSAGE_RULE = {
|
|
136
|
-
id: 'builtin:user-message',
|
|
137
|
-
name: 'User Message → LLM',
|
|
138
|
-
priority: 100,
|
|
139
|
-
when: {
|
|
140
|
-
eventType: 'user.message',
|
|
141
|
-
},
|
|
142
|
-
then: [{
|
|
143
|
-
type: 'llm_call',
|
|
144
|
-
description: 'Process user message with LLM',
|
|
145
|
-
params: {},
|
|
146
|
-
}],
|
|
147
|
-
};
|
|
148
|
-
/** 安全事件规则:立即标记 */
|
|
149
|
-
export const SECURITY_EVENT_RULE = {
|
|
150
|
-
id: 'builtin:security',
|
|
151
|
-
name: 'Security Event → Alert',
|
|
152
|
-
priority: 200,
|
|
153
|
-
when: {
|
|
154
|
-
eventType: ['injection.*', 'policy.*', 'sensitive.*'],
|
|
155
|
-
},
|
|
156
|
-
then: [{
|
|
157
|
-
type: 'custom',
|
|
158
|
-
description: 'Handle security event',
|
|
159
|
-
params: { action: 'alert' },
|
|
160
|
-
}],
|
|
161
|
-
};
|
|
162
|
-
/** 空闲事件规则:无操作 */
|
|
163
|
-
export const IDLE_RULE = {
|
|
164
|
-
id: 'builtin:idle',
|
|
165
|
-
name: 'Idle → No-op',
|
|
166
|
-
priority: 0,
|
|
167
|
-
when: {
|
|
168
|
-
eventType: 'supervisor.idle',
|
|
169
|
-
},
|
|
170
|
-
then: [],
|
|
171
|
-
};
|
|
172
|
-
/** 获取默认规则集 */
|
|
173
|
-
export function getDefaultRules() {
|
|
174
|
-
return [SECURITY_EVENT_RULE, USER_MESSAGE_RULE, IDLE_RULE];
|
|
175
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Output Error Classifier - 异常分类器
|
|
3
|
-
*
|
|
4
|
-
* 根据质量检测结果和上下文信息,分类异常类型并推荐恢复策略
|
|
5
|
-
*/
|
|
6
|
-
import type { ErrorClassification, RecoveryConfig } from './types.js';
|
|
7
|
-
/**
|
|
8
|
-
* Output 异常分类器
|
|
9
|
-
*/
|
|
10
|
-
export declare class OutputErrorClassifier {
|
|
11
|
-
private config;
|
|
12
|
-
constructor(config?: RecoveryConfig);
|
|
13
|
-
/**
|
|
14
|
-
* 分类异常
|
|
15
|
-
*/
|
|
16
|
-
classify(qualityResult: unknown, context: unknown): ErrorClassification;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* 创建 Output 异常分类器
|
|
20
|
-
*/
|
|
21
|
-
export declare function createOutputErrorClassifier(config?: RecoveryConfig): OutputErrorClassifier;
|
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Output Error Classifier - 异常分类器
|
|
3
|
-
*
|
|
4
|
-
* 根据质量检测结果和上下文信息,分类异常类型并推荐恢复策略
|
|
5
|
-
*/
|
|
6
|
-
// ================================================================
|
|
7
|
-
// 辅助函数
|
|
8
|
-
// ================================================================
|
|
9
|
-
/**
|
|
10
|
-
* 验证质量检测结果
|
|
11
|
-
*/
|
|
12
|
-
function validateQualityResult(result) {
|
|
13
|
-
if (typeof result !== 'object' || result === null) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
const r = result;
|
|
17
|
-
return (typeof r.isAnomalous === 'boolean' &&
|
|
18
|
-
typeof r.qualityScore === 'number' &&
|
|
19
|
-
Array.isArray(r.anomalyHints) &&
|
|
20
|
-
typeof r.details === 'object' && r.details !== null);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* 验证分类上下文
|
|
24
|
-
*/
|
|
25
|
-
function validateContext(context) {
|
|
26
|
-
if (typeof context !== 'object' || context === null) {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
const c = context;
|
|
30
|
-
if (typeof c.iterationCount !== 'number' || c.iterationCount < 0) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
if (!Array.isArray(c.previousErrors)) {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* 创建默认分类结果
|
|
40
|
-
*/
|
|
41
|
-
function createDefaultClassification() {
|
|
42
|
-
return {
|
|
43
|
-
type: 'unknown',
|
|
44
|
-
confidence: 0,
|
|
45
|
-
severity: 'minor',
|
|
46
|
-
recommendedStrategy: 'retry',
|
|
47
|
-
evidence: ['Invalid input'],
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
// ================================================================
|
|
51
|
-
// 核心分类函数
|
|
52
|
-
// ================================================================
|
|
53
|
-
/**
|
|
54
|
-
* 判断异常严重程度
|
|
55
|
-
*
|
|
56
|
-
* 基于质量评分和异常提示数量
|
|
57
|
-
*/
|
|
58
|
-
function determineSeverity(qualityScore, anomalyHints) {
|
|
59
|
-
// 评分极低或多个崩溃提示 → severe
|
|
60
|
-
if (qualityScore < 0.3 || anomalyHints.filter(h => h.type === 'model_collapse').length >= 2) {
|
|
61
|
-
return 'severe';
|
|
62
|
-
}
|
|
63
|
-
// 评分中等或有崩溃提示 → moderate
|
|
64
|
-
if (qualityScore < 0.5 || anomalyHints.some(h => h.type === 'model_collapse')) {
|
|
65
|
-
return 'moderate';
|
|
66
|
-
}
|
|
67
|
-
// 其他 → minor
|
|
68
|
-
return 'minor';
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* 根据异常提示确定主要异常类型
|
|
72
|
-
*/
|
|
73
|
-
function determineAnomalyType(anomalyHints, finishReason) {
|
|
74
|
-
// finish_reason 为 length → truncation
|
|
75
|
-
if (finishReason === 'length') {
|
|
76
|
-
return 'truncation';
|
|
77
|
-
}
|
|
78
|
-
// 按置信度排序异常提示
|
|
79
|
-
const sortedHints = [...anomalyHints].sort((a, b) => b.confidence - a.confidence);
|
|
80
|
-
// 最高置信度的提示类型
|
|
81
|
-
if (sortedHints.length > 0) {
|
|
82
|
-
const topHint = sortedHints[0];
|
|
83
|
-
if (topHint && topHint.confidence >= 0.5) {
|
|
84
|
-
return topHint.type;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
// 默认未知
|
|
88
|
-
return 'unknown';
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* 推荐恢复策略
|
|
92
|
-
*
|
|
93
|
-
* 基于异常类型和严重程度
|
|
94
|
-
*/
|
|
95
|
-
function recommendStrategy(type, severity, config, previousErrors) {
|
|
96
|
-
// 获取策略优先级配置
|
|
97
|
-
const priorityList = config.strategyPriority[type] ?? ['retry', 'abort'];
|
|
98
|
-
// 如果之前已经多次失败,直接 abort 或 degrade
|
|
99
|
-
const sameTypeErrors = previousErrors.filter(e => e.type === type);
|
|
100
|
-
if (sameTypeErrors.length >= config.maxRetries) {
|
|
101
|
-
return severity === 'severe' ? 'abort' : 'degrade';
|
|
102
|
-
}
|
|
103
|
-
// 根据严重程度调整策略
|
|
104
|
-
if (severity === 'severe') {
|
|
105
|
-
// 严重崩溃优先 fallback 或 abort
|
|
106
|
-
if (priorityList.includes('fallback') && config.fallbackModels.length > 0) {
|
|
107
|
-
return 'fallback';
|
|
108
|
-
}
|
|
109
|
-
return 'abort';
|
|
110
|
-
}
|
|
111
|
-
// moderate 崩溃:如果有 fallback 模型,优先 fallback
|
|
112
|
-
if (severity === 'moderate' &&
|
|
113
|
-
priorityList.includes('fallback') &&
|
|
114
|
-
config.fallbackModels.length > 0) {
|
|
115
|
-
return 'fallback';
|
|
116
|
-
}
|
|
117
|
-
// 其他情况按优先级选择
|
|
118
|
-
return priorityList[0] ?? 'retry';
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* 收集分类依据
|
|
122
|
-
*/
|
|
123
|
-
function collectEvidence(qualityResult, context) {
|
|
124
|
-
const evidence = [];
|
|
125
|
-
// 质量评分
|
|
126
|
-
evidence.push(`Quality score: ${qualityResult.qualityScore.toFixed(2)}`);
|
|
127
|
-
// 检测详情
|
|
128
|
-
if (qualityResult.details.syntaxFragmentDensity > 0) {
|
|
129
|
-
evidence.push(`Syntax fragment density: ${qualityResult.details.syntaxFragmentDensity.toFixed(2)}`);
|
|
130
|
-
}
|
|
131
|
-
if (qualityResult.details.entropy > 0) {
|
|
132
|
-
evidence.push(`Entropy: ${qualityResult.details.entropy.toFixed(2)}`);
|
|
133
|
-
}
|
|
134
|
-
if (qualityResult.details.repetitionRatio > 0) {
|
|
135
|
-
evidence.push(`Repetition ratio: ${qualityResult.details.repetitionRatio.toFixed(2)}`);
|
|
136
|
-
}
|
|
137
|
-
// 异常提示
|
|
138
|
-
for (const hint of qualityResult.anomalyHints) {
|
|
139
|
-
if (hint.evidence) {
|
|
140
|
-
evidence.push(`[${hint.type}] ${hint.evidence.slice(0, 50)}`);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
// finish_reason
|
|
144
|
-
if (context.finishReason) {
|
|
145
|
-
evidence.push(`Finish reason: ${context.finishReason}`);
|
|
146
|
-
}
|
|
147
|
-
// 工具调用
|
|
148
|
-
if (context.toolCalls && context.toolCalls.length > 0) {
|
|
149
|
-
evidence.push(`Tool calls: ${context.toolCalls.length}`);
|
|
150
|
-
}
|
|
151
|
-
// 迭代次数
|
|
152
|
-
evidence.push(`Iteration: ${context.iterationCount}`);
|
|
153
|
-
// 之前的错误
|
|
154
|
-
if (context.previousErrors.length > 0) {
|
|
155
|
-
evidence.push(`Previous errors: ${context.previousErrors.length}`);
|
|
156
|
-
}
|
|
157
|
-
return evidence;
|
|
158
|
-
}
|
|
159
|
-
// ================================================================
|
|
160
|
-
// ErrorClassifier 实现
|
|
161
|
-
// ================================================================
|
|
162
|
-
/**
|
|
163
|
-
* Output 异常分类器
|
|
164
|
-
*/
|
|
165
|
-
export class OutputErrorClassifier {
|
|
166
|
-
config;
|
|
167
|
-
constructor(config) {
|
|
168
|
-
this.config = config ?? {
|
|
169
|
-
maxRetries: 2,
|
|
170
|
-
fallbackModels: [],
|
|
171
|
-
strategyPriority: {
|
|
172
|
-
model_collapse: ['fallback', 'retry', 'abort'],
|
|
173
|
-
truncation: ['retry', 'abort'],
|
|
174
|
-
repetition_loop: ['retry', 'fallback', 'degrade'],
|
|
175
|
-
format_error: ['retry', 'abort'],
|
|
176
|
-
},
|
|
177
|
-
degradeConfig: {
|
|
178
|
-
disableTools: true,
|
|
179
|
-
maxTokens: 500,
|
|
180
|
-
},
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* 分类异常
|
|
185
|
-
*/
|
|
186
|
-
classify(qualityResult, context) {
|
|
187
|
-
// 输入验证
|
|
188
|
-
if (!validateQualityResult(qualityResult)) {
|
|
189
|
-
return createDefaultClassification();
|
|
190
|
-
}
|
|
191
|
-
if (!validateContext(context)) {
|
|
192
|
-
return createDefaultClassification();
|
|
193
|
-
}
|
|
194
|
-
// 如果不是异常,返回默认分类
|
|
195
|
-
if (!qualityResult.isAnomalous) {
|
|
196
|
-
return {
|
|
197
|
-
type: 'unknown',
|
|
198
|
-
confidence: 0,
|
|
199
|
-
severity: 'minor',
|
|
200
|
-
recommendedStrategy: 'retry',
|
|
201
|
-
evidence: collectEvidence(qualityResult, context),
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
// 确定异常类型
|
|
205
|
-
const type = determineAnomalyType(qualityResult.anomalyHints, context.finishReason);
|
|
206
|
-
// 确定严重程度
|
|
207
|
-
const severity = determineSeverity(qualityResult.qualityScore, qualityResult.anomalyHints);
|
|
208
|
-
// 计算置信度(基于异常提示和评分)
|
|
209
|
-
let confidence = 1 - qualityResult.qualityScore;
|
|
210
|
-
if (qualityResult.anomalyHints.length > 0) {
|
|
211
|
-
const maxHintConfidence = Math.max(...qualityResult.anomalyHints.map(h => h.confidence));
|
|
212
|
-
confidence = Math.max(confidence, maxHintConfidence);
|
|
213
|
-
}
|
|
214
|
-
// 推荐恢复策略
|
|
215
|
-
const recommendedStrategy = recommendStrategy(type, severity, this.config, context.previousErrors);
|
|
216
|
-
// 收集依据
|
|
217
|
-
const evidence = collectEvidence(qualityResult, context);
|
|
218
|
-
return {
|
|
219
|
-
type,
|
|
220
|
-
confidence: Math.min(1, confidence),
|
|
221
|
-
severity,
|
|
222
|
-
recommendedStrategy,
|
|
223
|
-
evidence,
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
// ================================================================
|
|
228
|
-
// 工厂函数
|
|
229
|
-
// ================================================================
|
|
230
|
-
/**
|
|
231
|
-
* 创建 Output 异常分类器
|
|
232
|
-
*/
|
|
233
|
-
export function createOutputErrorClassifier(config) {
|
|
234
|
-
return new OutputErrorClassifier(config);
|
|
235
|
-
}
|