@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
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentRegistry — Agent 注册与发现契约(L2 委派契约层)
|
|
3
|
+
*
|
|
4
|
+
* @layer harness/collaboration/delegation
|
|
5
|
+
* 设计权威:`arch/delegation.md` §12.1。
|
|
6
|
+
*
|
|
7
|
+
* **迁移说明**:本契约原居 `collaboration/multi-agent/agent-registry-types.ts`,
|
|
8
|
+
* 随旧 multi-agent 实现(`swarm.ts` / `process.ts`)一并重构。契约**保留**并扩展:
|
|
9
|
+
* `arch/agent-runtime.md` 多 Agent 模型规划的 v2 `CapabilityRouter` 对接
|
|
10
|
+
* `AgentRegistry.findByTrait`,删掉会堵死 Runtime 的路由扩展。
|
|
11
|
+
*
|
|
12
|
+
* 设计原则(沿用原契约):
|
|
13
|
+
* - 契约与实现分离:本文件只有类型与常量,不含实现
|
|
14
|
+
* - 跨域只 import 本文件 types,不 import 实现
|
|
15
|
+
* - 支持按能力(capability)发现 Agent
|
|
16
|
+
* - 支持 Agent 上下线通知
|
|
17
|
+
* - 支持 Agent 拓扑描述
|
|
18
|
+
*
|
|
19
|
+
* 新增(`arch/delegation.md` §9.2):
|
|
20
|
+
* - `AgentInfo.delegation` — 委派策略(可否被委派、递归深度、权利天花板、预算)
|
|
21
|
+
*/
|
|
22
|
+
import type { SessionRights } from '../../governance/session-acl/types.js';
|
|
23
|
+
import type { DelegationBudget } from './types.js';
|
|
24
|
+
/**
|
|
25
|
+
* Agent 的委派策略。
|
|
26
|
+
*
|
|
27
|
+
* 静态可审计:工具面/权限面由 AgentConfig 固定,父 agent 不得现场改写(§9.3 不做 ad-hoc)。
|
|
28
|
+
*
|
|
29
|
+
* **缺省语义**:未声明 `delegation` 的 agent 等价于 `DEFAULT_DELEGATION_POLICY`
|
|
30
|
+
* ——**缺省默认具备委派能力**(可被委派、可发委派、限一层)。
|
|
31
|
+
* 要关闭必须显式写 `callable: false` / `canDelegate: false`。
|
|
32
|
+
* 一律经 `effectiveDelegationPolicy()` 取生效值,不要直接读字段。
|
|
33
|
+
*/
|
|
34
|
+
export interface AgentDelegationPolicy {
|
|
35
|
+
/** 能否被委派(默认 **true**;显式 false = 只能被用户直接对话) */
|
|
36
|
+
callable: boolean;
|
|
37
|
+
/** 允许哪些 agentId 调我(缺省 = 任意) */
|
|
38
|
+
callableBy?: string[];
|
|
39
|
+
/** 我能不能再委派(默认 **true**) */
|
|
40
|
+
canDelegate: boolean;
|
|
41
|
+
/** 递归上限(缺省 = **1**,即子不能再派;§10.4 成本/爆炸半径兜底) */
|
|
42
|
+
maxDepth?: number;
|
|
43
|
+
/** 被委派时的权利天花板(D3:只能收紧不能放宽) */
|
|
44
|
+
rightsCeiling?: SessionRights;
|
|
45
|
+
/** 委派预算上限(请求预算与此取交集) */
|
|
46
|
+
budget?: DelegationBudget;
|
|
47
|
+
}
|
|
48
|
+
/** Agent 注册信息 */
|
|
49
|
+
export interface AgentInfo {
|
|
50
|
+
/** Agent 唯一 ID */
|
|
51
|
+
id: string;
|
|
52
|
+
/** Agent 名称(人类可读) */
|
|
53
|
+
name: string;
|
|
54
|
+
/** Agent 描述 */
|
|
55
|
+
description?: string;
|
|
56
|
+
/** Agent 特质标签(供按特质发现;`AgentConfig.traits` 落点);无权限语义 */
|
|
57
|
+
traits: string[];
|
|
58
|
+
/** 委派策略(§9.2);整段可省略 = 用 DEFAULT_DELEGATION_POLICY(委派默认开启)*/
|
|
59
|
+
delegation?: AgentDelegationPolicy;
|
|
60
|
+
/** Agent 元数据(必须可序列化) */
|
|
61
|
+
metadata?: Record<string, unknown>;
|
|
62
|
+
/** 注册时间 */
|
|
63
|
+
registeredAt: number;
|
|
64
|
+
/** 最后活跃时间 */
|
|
65
|
+
lastActiveAt: number;
|
|
66
|
+
/** Agent 状态 */
|
|
67
|
+
status: 'active' | 'idle' | 'busy' | 'offline';
|
|
68
|
+
}
|
|
69
|
+
/** Agent 查询条件 */
|
|
70
|
+
export interface AgentQuery {
|
|
71
|
+
/** 按特质过滤 */
|
|
72
|
+
traits?: string[];
|
|
73
|
+
/** 按状态过滤 */
|
|
74
|
+
status?: AgentInfo['status'];
|
|
75
|
+
/** 按元数据过滤 */
|
|
76
|
+
metadata?: Record<string, unknown>;
|
|
77
|
+
/** 仅返回可被委派的 Agent(delegation.callable === true) */
|
|
78
|
+
callableOnly?: boolean;
|
|
79
|
+
/** 按可被指定 caller 委派过滤(校验 delegation.callableBy) */
|
|
80
|
+
callableBy?: string;
|
|
81
|
+
}
|
|
82
|
+
/** Agent 间关系类型 */
|
|
83
|
+
export type AgentRelationType = 'peer' | 'superior' | 'subordinate' | 'pipeline' | 'depends';
|
|
84
|
+
/** Agent 间关系 */
|
|
85
|
+
export interface AgentRelation {
|
|
86
|
+
/** 关系来源 Agent */
|
|
87
|
+
from: string;
|
|
88
|
+
/** 关系目标 Agent */
|
|
89
|
+
to: string;
|
|
90
|
+
/** 关系类型 */
|
|
91
|
+
type: AgentRelationType;
|
|
92
|
+
/** 关系元数据 */
|
|
93
|
+
metadata?: Record<string, unknown>;
|
|
94
|
+
}
|
|
95
|
+
export declare const AgentRegistryEvents: {
|
|
96
|
+
/** Agent 注册 */
|
|
97
|
+
readonly AGENT_REGISTERED: "registry.agent.registered";
|
|
98
|
+
/** Agent 注销 */
|
|
99
|
+
readonly AGENT_UNREGISTERED: "registry.agent.unregistered";
|
|
100
|
+
/** Agent 状态变更 */
|
|
101
|
+
readonly AGENT_STATUS_CHANGED: "registry.agent.status_changed";
|
|
102
|
+
/** 关系添加 */
|
|
103
|
+
readonly RELATION_ADDED: "registry.relation.added";
|
|
104
|
+
/** 关系移除 */
|
|
105
|
+
readonly RELATION_REMOVED: "registry.relation.removed";
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* AgentRegistry 接口
|
|
109
|
+
*
|
|
110
|
+
* Agent 注册与发现的核心契约。
|
|
111
|
+
*/
|
|
112
|
+
export interface AgentRegistry {
|
|
113
|
+
/**
|
|
114
|
+
* 注册 Agent
|
|
115
|
+
*
|
|
116
|
+
* @param info - Agent 信息
|
|
117
|
+
*/
|
|
118
|
+
register(info: Omit<AgentInfo, 'registeredAt' | 'lastActiveAt'>): void;
|
|
119
|
+
/**
|
|
120
|
+
* 注销 Agent
|
|
121
|
+
*
|
|
122
|
+
* @param agentId - Agent ID
|
|
123
|
+
* @returns 是否成功注销
|
|
124
|
+
*/
|
|
125
|
+
unregister(agentId: string): boolean;
|
|
126
|
+
/**
|
|
127
|
+
* 获取 Agent 信息
|
|
128
|
+
*
|
|
129
|
+
* @param agentId - Agent ID
|
|
130
|
+
* @returns Agent 信息,不存在返回 undefined
|
|
131
|
+
*/
|
|
132
|
+
get(agentId: string): AgentInfo | undefined;
|
|
133
|
+
/**
|
|
134
|
+
* 查询 Agent
|
|
135
|
+
*
|
|
136
|
+
* @param query - 查询条件
|
|
137
|
+
* @returns 匹配的 Agent 列表
|
|
138
|
+
*/
|
|
139
|
+
query(query: AgentQuery): AgentInfo[];
|
|
140
|
+
/**
|
|
141
|
+
* 列出所有已注册 Agent
|
|
142
|
+
*/
|
|
143
|
+
list(): AgentInfo[];
|
|
144
|
+
/**
|
|
145
|
+
* 更新 Agent 状态
|
|
146
|
+
*
|
|
147
|
+
* @param agentId - Agent ID
|
|
148
|
+
* @param status - 新状态
|
|
149
|
+
*/
|
|
150
|
+
updateStatus(agentId: string, status: AgentInfo['status']): void;
|
|
151
|
+
/**
|
|
152
|
+
* 更新 Agent 活跃时间
|
|
153
|
+
*
|
|
154
|
+
* @param agentId - Agent ID
|
|
155
|
+
*/
|
|
156
|
+
touch(agentId: string): void;
|
|
157
|
+
/**
|
|
158
|
+
* 添加 Agent 间关系
|
|
159
|
+
*
|
|
160
|
+
* @param relation - 关系描述
|
|
161
|
+
*/
|
|
162
|
+
addRelation(relation: AgentRelation): void;
|
|
163
|
+
/**
|
|
164
|
+
* 移除 Agent 间关系
|
|
165
|
+
*
|
|
166
|
+
* @param from - 来源 Agent ID
|
|
167
|
+
* @param to - 目标 Agent ID
|
|
168
|
+
* @param type - 关系类型(不传则移除所有关系)
|
|
169
|
+
*/
|
|
170
|
+
removeRelation(from: string, to: string, type?: AgentRelationType): void;
|
|
171
|
+
/**
|
|
172
|
+
* 获取 Agent 的所有关系
|
|
173
|
+
*
|
|
174
|
+
* @param agentId - Agent ID
|
|
175
|
+
* @returns 关系列表
|
|
176
|
+
*/
|
|
177
|
+
getRelations(agentId: string): AgentRelation[];
|
|
178
|
+
/**
|
|
179
|
+
* 查找具有特定特质的 Agent
|
|
180
|
+
*
|
|
181
|
+
* @param trait - 特质标签
|
|
182
|
+
* @returns 具备该特质的 Agent 列表
|
|
183
|
+
*/
|
|
184
|
+
findByTrait(trait: string): AgentInfo[];
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* 缺省委派策略(`arch/delegation.md` §9.2)。
|
|
188
|
+
*
|
|
189
|
+
* agent **缺省默认具备委派能力**:可被委派、可发委派,但**只准一层**
|
|
190
|
+
* (`maxDepth: 1` = 我能派子,子不能再派)。默认开启委派时,
|
|
191
|
+
* 递归层数是唯一能自动限住 runaway 的旋钮,故这里必须收紧。
|
|
192
|
+
*/
|
|
193
|
+
export declare const DEFAULT_DELEGATION_POLICY: AgentDelegationPolicy;
|
|
194
|
+
/**
|
|
195
|
+
* 取 agent 的**生效**委派策略(未声明即用缺省)
|
|
196
|
+
*
|
|
197
|
+
* @param delegation - agent 声明的策略,可缺省
|
|
198
|
+
* @returns 生效策略(永远不是 undefined)
|
|
199
|
+
*/
|
|
200
|
+
export declare function effectiveDelegationPolicy(delegation: AgentDelegationPolicy | undefined): AgentDelegationPolicy;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentRegistry — Agent 注册与发现契约(L2 委派契约层)
|
|
3
|
+
*
|
|
4
|
+
* @layer harness/collaboration/delegation
|
|
5
|
+
* 设计权威:`arch/delegation.md` §12.1。
|
|
6
|
+
*
|
|
7
|
+
* **迁移说明**:本契约原居 `collaboration/multi-agent/agent-registry-types.ts`,
|
|
8
|
+
* 随旧 multi-agent 实现(`swarm.ts` / `process.ts`)一并重构。契约**保留**并扩展:
|
|
9
|
+
* `arch/agent-runtime.md` 多 Agent 模型规划的 v2 `CapabilityRouter` 对接
|
|
10
|
+
* `AgentRegistry.findByTrait`,删掉会堵死 Runtime 的路由扩展。
|
|
11
|
+
*
|
|
12
|
+
* 设计原则(沿用原契约):
|
|
13
|
+
* - 契约与实现分离:本文件只有类型与常量,不含实现
|
|
14
|
+
* - 跨域只 import 本文件 types,不 import 实现
|
|
15
|
+
* - 支持按能力(capability)发现 Agent
|
|
16
|
+
* - 支持 Agent 上下线通知
|
|
17
|
+
* - 支持 Agent 拓扑描述
|
|
18
|
+
*
|
|
19
|
+
* 新增(`arch/delegation.md` §9.2):
|
|
20
|
+
* - `AgentInfo.delegation` — 委派策略(可否被委派、递归深度、权利天花板、预算)
|
|
21
|
+
*/
|
|
22
|
+
// ── 事件 ──
|
|
23
|
+
export const AgentRegistryEvents = {
|
|
24
|
+
/** Agent 注册 */
|
|
25
|
+
AGENT_REGISTERED: 'registry.agent.registered',
|
|
26
|
+
/** Agent 注销 */
|
|
27
|
+
AGENT_UNREGISTERED: 'registry.agent.unregistered',
|
|
28
|
+
/** Agent 状态变更 */
|
|
29
|
+
AGENT_STATUS_CHANGED: 'registry.agent.status_changed',
|
|
30
|
+
/** 关系添加 */
|
|
31
|
+
RELATION_ADDED: 'registry.relation.added',
|
|
32
|
+
/** 关系移除 */
|
|
33
|
+
RELATION_REMOVED: 'registry.relation.removed',
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* 缺省委派策略(`arch/delegation.md` §9.2)。
|
|
37
|
+
*
|
|
38
|
+
* agent **缺省默认具备委派能力**:可被委派、可发委派,但**只准一层**
|
|
39
|
+
* (`maxDepth: 1` = 我能派子,子不能再派)。默认开启委派时,
|
|
40
|
+
* 递归层数是唯一能自动限住 runaway 的旋钮,故这里必须收紧。
|
|
41
|
+
*/
|
|
42
|
+
export const DEFAULT_DELEGATION_POLICY = {
|
|
43
|
+
callable: true,
|
|
44
|
+
canDelegate: true,
|
|
45
|
+
maxDepth: 1,
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* 取 agent 的**生效**委派策略(未声明即用缺省)
|
|
49
|
+
*
|
|
50
|
+
* @param delegation - agent 声明的策略,可缺省
|
|
51
|
+
* @returns 生效策略(永远不是 undefined)
|
|
52
|
+
*/
|
|
53
|
+
export function effectiveDelegationPolicy(delegation) {
|
|
54
|
+
if (!delegation)
|
|
55
|
+
return { ...DEFAULT_DELEGATION_POLICY };
|
|
56
|
+
return {
|
|
57
|
+
...DEFAULT_DELEGATION_POLICY,
|
|
58
|
+
...delegation,
|
|
59
|
+
maxDepth: delegation.maxDepth ?? DEFAULT_DELEGATION_POLICY.maxDepth,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DefaultAgentRegistry — Agent 注册与发现的默认实现
|
|
3
|
+
*
|
|
4
|
+
* @layer harness/collaboration/delegation
|
|
5
|
+
* 实现本域 `registry-types.ts` 的 `AgentRegistry`(`arch/delegation.md` §12.1 重写)。
|
|
6
|
+
*
|
|
7
|
+
* 设计原则(沿用旧实现并修正):
|
|
8
|
+
* - 不依赖外部存储(v1 内存;跨进程 Registry 归 L3/L4)
|
|
9
|
+
* - 事件驱动:所有变更经 EventBus 通知
|
|
10
|
+
* - 同步操作,适合单进程场景
|
|
11
|
+
* - **委派策略一等**:`query` 支持 `callableOnly` / `callableBy`(§9.2)
|
|
12
|
+
*
|
|
13
|
+
* 与旧 `multi-agent/registry.ts` 的差异:
|
|
14
|
+
* - 新增 `AgentInfo.delegation` 策略字段
|
|
15
|
+
* - `query` 增 `callableOnly` / `callableBy` 过滤
|
|
16
|
+
* - 契约与实现同域(旧版分居两文件)
|
|
17
|
+
*/
|
|
18
|
+
import type { EventBus } from '@octopi-agent/core/primitives/event-bus.js';
|
|
19
|
+
import type { AgentInfo, AgentQuery, AgentRegistry, AgentRelation, AgentRelationType } from './registry-types.js';
|
|
20
|
+
/**
|
|
21
|
+
* DefaultAgentRegistry
|
|
22
|
+
*
|
|
23
|
+
* 基于内存的 Agent 注册表实现。
|
|
24
|
+
*/
|
|
25
|
+
export declare class DefaultAgentRegistry implements AgentRegistry {
|
|
26
|
+
private readonly events?;
|
|
27
|
+
private readonly agents;
|
|
28
|
+
private relations;
|
|
29
|
+
/**
|
|
30
|
+
* @param events - 可选 EventBus;提供时发射 `registry.*` 事件
|
|
31
|
+
*/
|
|
32
|
+
constructor(events?: EventBus | undefined);
|
|
33
|
+
/**
|
|
34
|
+
* 注册 Agent
|
|
35
|
+
*
|
|
36
|
+
* @param info - Agent 信息(不含时间戳,服务端补)
|
|
37
|
+
*/
|
|
38
|
+
register(info: Omit<AgentInfo, 'registeredAt' | 'lastActiveAt'>): void;
|
|
39
|
+
/**
|
|
40
|
+
* 注销 Agent(同时清理其关系)
|
|
41
|
+
*
|
|
42
|
+
* @param agentId - Agent ID
|
|
43
|
+
* @returns 是否成功注销
|
|
44
|
+
*/
|
|
45
|
+
unregister(agentId: string): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* 获取 Agent 信息
|
|
48
|
+
*
|
|
49
|
+
* @param agentId - Agent ID
|
|
50
|
+
* @returns Agent 信息;不存在返回 undefined
|
|
51
|
+
*/
|
|
52
|
+
get(agentId: string): AgentInfo | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* 查询 Agent
|
|
55
|
+
*
|
|
56
|
+
* @param query - 查询条件(traits 为 **任一**命中)
|
|
57
|
+
* @returns 匹配的 Agent 列表
|
|
58
|
+
*/
|
|
59
|
+
query(query: AgentQuery): AgentInfo[];
|
|
60
|
+
/**
|
|
61
|
+
* 列出所有已注册 Agent
|
|
62
|
+
*
|
|
63
|
+
* @returns Agent 列表
|
|
64
|
+
*/
|
|
65
|
+
list(): AgentInfo[];
|
|
66
|
+
/**
|
|
67
|
+
* 查找具有特定特质的 Agent
|
|
68
|
+
*
|
|
69
|
+
* @param trait - 特质标签
|
|
70
|
+
* @returns 具备该特质的 Agent 列表
|
|
71
|
+
*/
|
|
72
|
+
findByTrait(trait: string): AgentInfo[];
|
|
73
|
+
/**
|
|
74
|
+
* 更新 Agent 状态
|
|
75
|
+
*
|
|
76
|
+
* @param agentId - Agent ID
|
|
77
|
+
* @param status - 新状态
|
|
78
|
+
*/
|
|
79
|
+
updateStatus(agentId: string, status: AgentInfo['status']): void;
|
|
80
|
+
/**
|
|
81
|
+
* 更新 Agent 活跃时间
|
|
82
|
+
*
|
|
83
|
+
* @param agentId - Agent ID
|
|
84
|
+
*/
|
|
85
|
+
touch(agentId: string): void;
|
|
86
|
+
/**
|
|
87
|
+
* 添加 Agent 间关系(同 from/to/type 去重)
|
|
88
|
+
*
|
|
89
|
+
* @param relation - 关系描述
|
|
90
|
+
*/
|
|
91
|
+
addRelation(relation: AgentRelation): void;
|
|
92
|
+
/**
|
|
93
|
+
* 移除 Agent 间关系
|
|
94
|
+
*
|
|
95
|
+
* @param from - 来源 Agent ID
|
|
96
|
+
* @param to - 目标 Agent ID
|
|
97
|
+
* @param type - 关系类型(不传则移除两者的全部关系)
|
|
98
|
+
*/
|
|
99
|
+
removeRelation(from: string, to: string, type?: AgentRelationType): void;
|
|
100
|
+
/**
|
|
101
|
+
* 获取 Agent 的所有关系
|
|
102
|
+
*
|
|
103
|
+
* @param agentId - Agent ID
|
|
104
|
+
* @returns 关系列表(含 from 与 to 两侧)
|
|
105
|
+
*/
|
|
106
|
+
getRelations(agentId: string): AgentRelation[];
|
|
107
|
+
/** callableBy 白名单校验(缺省 = 任意) */
|
|
108
|
+
private isCallableBy;
|
|
109
|
+
private emit;
|
|
110
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DefaultAgentRegistry — Agent 注册与发现的默认实现
|
|
3
|
+
*
|
|
4
|
+
* @layer harness/collaboration/delegation
|
|
5
|
+
* 实现本域 `registry-types.ts` 的 `AgentRegistry`(`arch/delegation.md` §12.1 重写)。
|
|
6
|
+
*
|
|
7
|
+
* 设计原则(沿用旧实现并修正):
|
|
8
|
+
* - 不依赖外部存储(v1 内存;跨进程 Registry 归 L3/L4)
|
|
9
|
+
* - 事件驱动:所有变更经 EventBus 通知
|
|
10
|
+
* - 同步操作,适合单进程场景
|
|
11
|
+
* - **委派策略一等**:`query` 支持 `callableOnly` / `callableBy`(§9.2)
|
|
12
|
+
*
|
|
13
|
+
* 与旧 `multi-agent/registry.ts` 的差异:
|
|
14
|
+
* - 新增 `AgentInfo.delegation` 策略字段
|
|
15
|
+
* - `query` 增 `callableOnly` / `callableBy` 过滤
|
|
16
|
+
* - 契约与实现同域(旧版分居两文件)
|
|
17
|
+
*/
|
|
18
|
+
import { AgentRegistryEvents, effectiveDelegationPolicy } from './registry-types.js';
|
|
19
|
+
/**
|
|
20
|
+
* DefaultAgentRegistry
|
|
21
|
+
*
|
|
22
|
+
* 基于内存的 Agent 注册表实现。
|
|
23
|
+
*/
|
|
24
|
+
export class DefaultAgentRegistry {
|
|
25
|
+
events;
|
|
26
|
+
agents = new Map();
|
|
27
|
+
relations = [];
|
|
28
|
+
/**
|
|
29
|
+
* @param events - 可选 EventBus;提供时发射 `registry.*` 事件
|
|
30
|
+
*/
|
|
31
|
+
constructor(events) {
|
|
32
|
+
this.events = events;
|
|
33
|
+
}
|
|
34
|
+
// ── 注册 / 注销 ──
|
|
35
|
+
/**
|
|
36
|
+
* 注册 Agent
|
|
37
|
+
*
|
|
38
|
+
* @param info - Agent 信息(不含时间戳,服务端补)
|
|
39
|
+
*/
|
|
40
|
+
register(info) {
|
|
41
|
+
const timestamp = Date.now();
|
|
42
|
+
const record = {
|
|
43
|
+
...info,
|
|
44
|
+
traits: [...info.traits],
|
|
45
|
+
// 归一化为生效策略(缺省默认具备委派能力,arch/delegation.md §9.2);
|
|
46
|
+
// 此后所有消费方读到的都是完整策略,无需各自兜底。
|
|
47
|
+
delegation: effectiveDelegationPolicy(info.delegation),
|
|
48
|
+
registeredAt: timestamp,
|
|
49
|
+
lastActiveAt: timestamp,
|
|
50
|
+
};
|
|
51
|
+
this.agents.set(record.id, record);
|
|
52
|
+
this.emit(AgentRegistryEvents.AGENT_REGISTERED, {
|
|
53
|
+
agentId: record.id,
|
|
54
|
+
name: record.name,
|
|
55
|
+
traits: record.traits,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 注销 Agent(同时清理其关系)
|
|
60
|
+
*
|
|
61
|
+
* @param agentId - Agent ID
|
|
62
|
+
* @returns 是否成功注销
|
|
63
|
+
*/
|
|
64
|
+
unregister(agentId) {
|
|
65
|
+
const existed = this.agents.delete(agentId);
|
|
66
|
+
if (existed) {
|
|
67
|
+
this.relations = this.relations.filter((r) => r.from !== agentId && r.to !== agentId);
|
|
68
|
+
this.emit(AgentRegistryEvents.AGENT_UNREGISTERED, { agentId });
|
|
69
|
+
}
|
|
70
|
+
return existed;
|
|
71
|
+
}
|
|
72
|
+
// ── 查询 ──
|
|
73
|
+
/**
|
|
74
|
+
* 获取 Agent 信息
|
|
75
|
+
*
|
|
76
|
+
* @param agentId - Agent ID
|
|
77
|
+
* @returns Agent 信息;不存在返回 undefined
|
|
78
|
+
*/
|
|
79
|
+
get(agentId) {
|
|
80
|
+
return this.agents.get(agentId);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 查询 Agent
|
|
84
|
+
*
|
|
85
|
+
* @param query - 查询条件(traits 为 **任一**命中)
|
|
86
|
+
* @returns 匹配的 Agent 列表
|
|
87
|
+
*/
|
|
88
|
+
query(query) {
|
|
89
|
+
let results = Array.from(this.agents.values());
|
|
90
|
+
if (query.traits && query.traits.length > 0) {
|
|
91
|
+
results = results.filter((agent) => query.traits.some((t) => agent.traits.includes(t)));
|
|
92
|
+
}
|
|
93
|
+
if (query.status) {
|
|
94
|
+
results = results.filter((agent) => agent.status === query.status);
|
|
95
|
+
}
|
|
96
|
+
if (query.metadata) {
|
|
97
|
+
results = results.filter((agent) => {
|
|
98
|
+
if (!agent.metadata)
|
|
99
|
+
return false;
|
|
100
|
+
return Object.entries(query.metadata).every(([key, value]) => agent.metadata[key] === value);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
if (query.callableOnly) {
|
|
104
|
+
results = results.filter((agent) => effectiveDelegationPolicy(agent.delegation).callable);
|
|
105
|
+
}
|
|
106
|
+
if (query.callableBy !== undefined) {
|
|
107
|
+
results = results.filter((agent) => this.isCallableBy(agent, query.callableBy));
|
|
108
|
+
}
|
|
109
|
+
return results;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 列出所有已注册 Agent
|
|
113
|
+
*
|
|
114
|
+
* @returns Agent 列表
|
|
115
|
+
*/
|
|
116
|
+
list() {
|
|
117
|
+
return Array.from(this.agents.values());
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* 查找具有特定特质的 Agent
|
|
121
|
+
*
|
|
122
|
+
* @param trait - 特质标签
|
|
123
|
+
* @returns 具备该特质的 Agent 列表
|
|
124
|
+
*/
|
|
125
|
+
findByTrait(trait) {
|
|
126
|
+
return Array.from(this.agents.values()).filter((agent) => agent.traits.includes(trait));
|
|
127
|
+
}
|
|
128
|
+
// ── 状态管理 ──
|
|
129
|
+
/**
|
|
130
|
+
* 更新 Agent 状态
|
|
131
|
+
*
|
|
132
|
+
* @param agentId - Agent ID
|
|
133
|
+
* @param status - 新状态
|
|
134
|
+
*/
|
|
135
|
+
updateStatus(agentId, status) {
|
|
136
|
+
const agent = this.agents.get(agentId);
|
|
137
|
+
if (!agent)
|
|
138
|
+
return;
|
|
139
|
+
const oldStatus = agent.status;
|
|
140
|
+
agent.status = status;
|
|
141
|
+
agent.lastActiveAt = Date.now();
|
|
142
|
+
if (oldStatus !== status) {
|
|
143
|
+
this.emit(AgentRegistryEvents.AGENT_STATUS_CHANGED, {
|
|
144
|
+
agentId,
|
|
145
|
+
oldStatus,
|
|
146
|
+
newStatus: status,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* 更新 Agent 活跃时间
|
|
152
|
+
*
|
|
153
|
+
* @param agentId - Agent ID
|
|
154
|
+
*/
|
|
155
|
+
touch(agentId) {
|
|
156
|
+
const agent = this.agents.get(agentId);
|
|
157
|
+
if (agent) {
|
|
158
|
+
agent.lastActiveAt = Date.now();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
// ── 关系管理 ──
|
|
162
|
+
/**
|
|
163
|
+
* 添加 Agent 间关系(同 from/to/type 去重)
|
|
164
|
+
*
|
|
165
|
+
* @param relation - 关系描述
|
|
166
|
+
*/
|
|
167
|
+
addRelation(relation) {
|
|
168
|
+
const exists = this.relations.some((r) => r.from === relation.from && r.to === relation.to && r.type === relation.type);
|
|
169
|
+
if (exists)
|
|
170
|
+
return;
|
|
171
|
+
this.relations.push(relation);
|
|
172
|
+
this.emit(AgentRegistryEvents.RELATION_ADDED, {
|
|
173
|
+
from: relation.from,
|
|
174
|
+
to: relation.to,
|
|
175
|
+
type: relation.type,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* 移除 Agent 间关系
|
|
180
|
+
*
|
|
181
|
+
* @param from - 来源 Agent ID
|
|
182
|
+
* @param to - 目标 Agent ID
|
|
183
|
+
* @param type - 关系类型(不传则移除两者的全部关系)
|
|
184
|
+
*/
|
|
185
|
+
removeRelation(from, to, type) {
|
|
186
|
+
const before = this.relations.length;
|
|
187
|
+
this.relations = this.relations.filter((r) => {
|
|
188
|
+
if (r.from !== from || r.to !== to)
|
|
189
|
+
return true;
|
|
190
|
+
if (type && r.type !== type)
|
|
191
|
+
return true;
|
|
192
|
+
return false;
|
|
193
|
+
});
|
|
194
|
+
if (this.relations.length < before) {
|
|
195
|
+
this.emit(AgentRegistryEvents.RELATION_REMOVED, { from, to, type });
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* 获取 Agent 的所有关系
|
|
200
|
+
*
|
|
201
|
+
* @param agentId - Agent ID
|
|
202
|
+
* @returns 关系列表(含 from 与 to 两侧)
|
|
203
|
+
*/
|
|
204
|
+
getRelations(agentId) {
|
|
205
|
+
return this.relations.filter((r) => r.from === agentId || r.to === agentId);
|
|
206
|
+
}
|
|
207
|
+
// ── 内部 ──
|
|
208
|
+
/** callableBy 白名单校验(缺省 = 任意) */
|
|
209
|
+
isCallableBy(agent, callerAgentId) {
|
|
210
|
+
const allowed = agent.delegation?.callableBy;
|
|
211
|
+
if (!allowed || allowed.length === 0)
|
|
212
|
+
return true;
|
|
213
|
+
return allowed.includes(callerAgentId);
|
|
214
|
+
}
|
|
215
|
+
emit(type, data) {
|
|
216
|
+
if (!this.events)
|
|
217
|
+
return;
|
|
218
|
+
this.events.emit({ type, timestamp: Date.now(), data });
|
|
219
|
+
}
|
|
220
|
+
}
|