@octopi-agent/engine 0.97.15 → 0.102.10
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/dist/config-schema/agent.d.ts +37 -5
- package/dist/config-schema/agent.js +24 -4
- package/dist/config-schema/context.d.ts +6 -36
- package/dist/config-schema/context.js +4 -28
- package/dist/config-schema/engine.d.ts +61 -160
- package/dist/config-schema/engine.js +1 -5
- package/dist/config-schema/governance.d.ts +10 -1
- package/dist/config-schema/governance.js +38 -1
- package/dist/config-schema/models.d.ts +2 -8
- package/dist/config-schema/models.js +0 -2
- package/dist/config-schema/run.d.ts +2 -2
- package/dist/config-schema/run.js +2 -2
- package/dist/config-schema/shared.d.ts +0 -3
- package/dist/config-schema/shared.js +0 -2
- package/dist/config-schema/substrate.d.ts +14 -88
- package/dist/config-schema/substrate.js +22 -107
- package/dist/config.d.ts +45 -113
- package/dist/config.js +8 -2
- package/dist/harness/activation/dispatcher.js +7 -0
- package/dist/harness/activation/inbox.d.ts +3 -3
- package/dist/harness/activation/inbox.js +3 -3
- package/dist/harness/activation/runtime.js +13 -5
- package/dist/harness/activation/types.d.ts +2 -2
- package/dist/harness/agent/builder.d.ts +34 -2
- package/dist/harness/agent/builder.js +189 -58
- package/dist/harness/agent/config-bridge.js +9 -2
- package/dist/harness/agent/config-integrity.d.ts +66 -0
- package/dist/harness/agent/config-integrity.js +108 -2
- package/dist/harness/agent/wire-agent-builder.d.ts +11 -3
- package/dist/harness/agent/wire-agent-builder.js +31 -7
- package/dist/harness/capabilities/document/factory.d.ts +5 -0
- package/dist/harness/capabilities/document/factory.js +1 -0
- package/dist/harness/capabilities/document/port.js +6 -3
- package/dist/harness/capabilities/document/types.d.ts +5 -0
- package/dist/harness/collaboration/autonomous-subsystem/index.d.ts +2 -2
- package/dist/harness/collaboration/autonomous-subsystem/index.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +4 -1
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.d.ts +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +21 -4
- package/dist/harness/collaboration/autonomous-subsystem/sense/input-builder.js +4 -4
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.d.ts +2 -2
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.js +2 -2
- package/dist/harness/collaboration/autonomous-subsystem/signal/bus.d.ts +6 -0
- package/dist/harness/collaboration/autonomous-subsystem/signal/bus.js +25 -4
- package/dist/harness/collaboration/autonomous-subsystem/think/completion-guard.d.ts +40 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/completion-guard.js +59 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/think/index.d.ts +2 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/index.js +1 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +12 -3
- package/dist/harness/collaboration/delegation/child-run.d.ts +1 -1
- package/dist/harness/collaboration/delegation/child-run.js +4 -4
- package/dist/harness/collaboration/delegation/index.d.ts +1 -1
- package/dist/harness/collaboration/delegation/index.js +1 -1
- package/dist/harness/collaboration/delegation/notifier.d.ts +6 -1
- package/dist/harness/collaboration/delegation/notifier.js +8 -1
- package/dist/harness/collaboration/delegation/service.d.ts +2 -0
- package/dist/harness/collaboration/delegation/service.js +2 -1
- package/dist/harness/collaboration/delegation/store.d.ts +2 -0
- package/dist/harness/collaboration/delegation/store.js +2 -1
- package/dist/harness/collaboration/delegation/types.d.ts +23 -2
- package/dist/harness/collaboration/delegation/types.js +22 -0
- package/dist/harness/collaboration/delegation/wiring.js +11 -1
- package/dist/harness/context/budget-allocator.d.ts +26 -18
- package/dist/harness/context/budget-allocator.js +67 -32
- package/dist/harness/context/capabilities/compact/engine.d.ts +0 -6
- package/dist/harness/context/capabilities/compact/engine.js +169 -121
- package/dist/harness/context/capabilities/compact/handover.d.ts +5 -3
- package/dist/harness/context/capabilities/compact/handover.js +7 -5
- package/dist/harness/context/capabilities/compact/index.d.ts +5 -1
- package/dist/harness/context/capabilities/compact/index.js +4 -0
- package/dist/harness/context/capabilities/compact/mechanical.d.ts +130 -0
- package/dist/harness/context/capabilities/compact/mechanical.js +268 -0
- package/dist/harness/context/capabilities/compact/messages.d.ts +60 -0
- package/dist/harness/context/capabilities/compact/messages.js +91 -0
- package/dist/harness/context/capabilities/compact/types.d.ts +76 -11
- package/dist/harness/context/capabilities/compact/types.js +11 -1
- package/dist/harness/context/capabilities/compact/view-split.d.ts +36 -0
- package/dist/harness/context/capabilities/compact/view-split.js +72 -0
- package/dist/harness/context/capabilities/summary/port.js +0 -1
- package/dist/harness/context/capabilities/summary/resolver.d.ts +1 -1
- package/dist/harness/context/capabilities/summary/resolver.js +4 -9
- package/dist/harness/context/capabilities/summary/tool-binding.d.ts +1 -1
- package/dist/harness/context/capabilities/summary/types.d.ts +4 -7
- package/dist/harness/context/context-size-ledger.d.ts +143 -0
- package/dist/harness/context/context-size-ledger.js +236 -0
- package/dist/harness/context/default-context-engine.d.ts +195 -119
- package/dist/harness/context/default-context-engine.js +1241 -743
- package/dist/harness/context/index.d.ts +2 -2
- package/dist/harness/context/index.js +1 -1
- package/dist/harness/context/layer-types.d.ts +15 -0
- package/dist/harness/context/layer-types.js +14 -1
- package/dist/harness/context/layers.d.ts +16 -19
- package/dist/harness/context/layers.js +42 -14
- package/dist/harness/context/message-selector.d.ts +10 -8
- package/dist/harness/context/message-selector.js +49 -27
- package/dist/harness/context/summarize.d.ts +3 -3
- package/dist/harness/context/summarize.js +11 -4
- package/dist/harness/context/system-prompt-assembler.d.ts +4 -0
- package/dist/harness/context/system-prompt-assembler.js +3 -1
- package/dist/harness/context/token-constants.d.ts +8 -6
- package/dist/harness/context/token-constants.js +8 -7
- package/dist/harness/context/token-estimate-fns.d.ts +37 -27
- package/dist/harness/context/token-estimate-fns.js +85 -66
- package/dist/harness/context/token-estimator.d.ts +27 -12
- package/dist/harness/context/token-estimator.js +120 -66
- package/dist/harness/context/token-segments.d.ts +88 -0
- package/dist/harness/context/token-segments.js +103 -0
- package/dist/harness/context/tool-result-aging.d.ts +6 -1
- package/dist/harness/context/tool-result-aging.js +16 -5
- package/dist/harness/context/tool-result-body.js +2 -0
- package/dist/harness/context/transform/anchors.d.ts +66 -0
- package/dist/harness/context/transform/anchors.js +125 -0
- package/dist/harness/context/transform/fold.d.ts +56 -0
- package/dist/harness/context/transform/fold.js +135 -0
- package/dist/harness/context/transform/migrate.d.ts +41 -0
- package/dist/harness/context/transform/migrate.js +69 -0
- package/dist/harness/context/transform/types.d.ts +129 -0
- package/dist/harness/context/transform/types.js +19 -0
- package/dist/harness/context/turn-envelope.d.ts +6 -3
- package/dist/harness/context/types.d.ts +127 -117
- package/dist/harness/extension/execution-environment/effect-policy.d.ts +24 -2
- package/dist/harness/extension/execution-environment/effect-policy.js +30 -0
- package/dist/harness/extension/execution-environment/ops-audit.d.ts +7 -3
- package/dist/harness/extension/execution-environment/ops-audit.js +11 -12
- package/dist/harness/extension/execution-environment/resource-limits.d.ts +1 -1
- package/dist/harness/extension/execution-environment/resource-limits.js +1 -1
- package/dist/harness/extension/execution-environment/undo-log.d.ts +6 -2
- package/dist/harness/extension/execution-environment/undo-log.js +31 -10
- package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/commands/index.d.ts +3 -1
- package/dist/harness/extension/plugin-ecosystem/commands/index.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/commands/plugin-bridge.d.ts +12 -1
- package/dist/harness/extension/plugin-ecosystem/commands/plugin-bridge.js +14 -4
- package/dist/harness/extension/plugin-ecosystem/commands/router.d.ts +5 -4
- package/dist/harness/extension/plugin-ecosystem/commands/router.js +23 -14
- package/dist/harness/extension/plugin-ecosystem/commands/types.d.ts +8 -1
- package/dist/harness/extension/plugin-ecosystem/commands/types.js +2 -1
- package/dist/harness/extension/plugin-ecosystem/hooks/adapter.d.ts +54 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/adapter.js +397 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/compaction-integration.d.ts +16 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/compaction-integration.js +66 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/index.d.ts +4 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/index.js +2 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/iteration-snapshot.d.ts +11 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/iteration-snapshot.js +54 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/journal.d.ts +9 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/journal.js +22 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/policy-error.d.ts +12 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/policy-error.js +19 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/run-integration.d.ts +36 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/run-integration.js +338 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/services.d.ts +24 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/services.js +139 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/types.d.ts +229 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/types.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +83 -249
- package/dist/harness/extension/plugin-ecosystem/plugins/api.js +88 -214
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.d.ts +43 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.js +61 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/engine-compatibility.d.ts +4 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/engine-compatibility.js +18 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.d.ts +7 -85
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.js +8 -50
- package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +6 -23
- package/dist/harness/extension/plugin-ecosystem/plugins/index.js +3 -23
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +50 -117
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +316 -285
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +23 -490
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +85 -353
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +41 -223
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +138 -19
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.d.ts +15 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.js +15 -0
- package/dist/harness/extension/plugin-ecosystem/skills/manager.d.ts +6 -1
- package/dist/harness/extension/plugin-ecosystem/skills/manager.js +17 -1
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.d.ts +3 -0
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +46 -21
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +17 -24
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +18 -8
- package/dist/harness/extension/plugin-ecosystem/tools/document-tools.js +3 -9
- package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +3 -6
- package/dist/harness/extension/plugin-ecosystem/tools/file-ops.js +9 -5
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +9 -130
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +122 -14
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +4 -13
- package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +25 -11
- package/dist/harness/extension/plugin-ecosystem/tools/platform.js +168 -62
- package/dist/harness/extension/plugin-ecosystem/tools/plugin-tool.d.ts +11 -0
- package/dist/harness/extension/plugin-ecosystem/tools/plugin-tool.js +39 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +11 -2
- package/dist/harness/governance/accounting/usage-ledger.d.ts +13 -1
- package/dist/harness/governance/accounting/usage-ledger.js +23 -1
- package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +3 -3
- package/dist/harness/governance/human-in-the-loop/decision-cache.js +2 -2
- package/dist/harness/governance/security/capability-enforcer.js +1 -2
- package/dist/harness/governance/security/default-risk-policy.d.ts +1 -0
- package/dist/harness/governance/security/default-risk-policy.js +1 -0
- package/dist/harness/governance/security/default-security-guard.js +9 -0
- package/dist/harness/governance/security/index.d.ts +1 -0
- package/dist/harness/governance/security/index.js +2 -0
- package/dist/harness/governance/security/risk-evaluator.js +13 -0
- package/dist/harness/governance/security/risk-types.d.ts +12 -0
- package/dist/harness/governance/security/shell-parser-fallback.d.ts +29 -0
- package/dist/harness/governance/security/shell-parser-fallback.js +410 -0
- package/dist/harness/governance/security/shell-parser-shared.d.ts +83 -0
- package/dist/harness/governance/security/shell-parser-shared.js +188 -0
- package/dist/harness/governance/security/shell-parser-treesitter.d.ts +52 -0
- package/dist/harness/governance/security/shell-parser-treesitter.js +370 -0
- package/dist/harness/governance/security/shell-parser.d.ts +23 -10
- package/dist/harness/governance/security/shell-parser.js +37 -496
- package/dist/harness/governance/security/vendor/README.md +24 -0
- package/dist/harness/governance/security/vendor/tree-sitter-bash.LICENSE.txt +21 -0
- package/dist/harness/governance/security/vendor/tree-sitter-bash.wasm +0 -0
- package/dist/harness/index.d.ts +12 -12
- package/dist/harness/index.js +7 -7
- package/dist/harness/knowledge/boot-config.d.ts +55 -0
- package/dist/harness/knowledge/boot-config.js +50 -0
- package/dist/harness/knowledge/catalog-types.d.ts +2 -0
- package/dist/harness/knowledge/client.d.ts +24 -2
- package/dist/harness/knowledge/client.js +19 -5
- package/dist/harness/knowledge/db.js +5 -0
- package/dist/harness/knowledge/describe-sample.d.ts +23 -0
- package/dist/harness/knowledge/describe-sample.js +58 -0
- package/dist/harness/knowledge/describe.d.ts +8 -0
- package/dist/harness/knowledge/describe.js +18 -2
- package/dist/harness/knowledge/engine-thread.js +6 -0
- package/dist/harness/knowledge/grounding.js +3 -1
- package/dist/harness/knowledge/http-app.js +35 -4
- package/dist/harness/knowledge/http-params.d.ts +18 -0
- package/dist/harness/knowledge/http-params.js +24 -0
- package/dist/harness/knowledge/index.d.ts +2 -0
- package/dist/harness/knowledge/index.js +1 -0
- package/dist/harness/knowledge/knowledge-serve-child.js +3 -0
- package/dist/harness/knowledge/purge.js +5 -2
- package/dist/harness/knowledge/query-service.d.ts +13 -2
- package/dist/harness/knowledge/query-service.js +4 -2
- package/dist/harness/knowledge/query-worker-client.d.ts +9 -1
- package/dist/harness/knowledge/query-worker-client.js +4 -2
- package/dist/harness/knowledge/query-worker.js +4 -2
- package/dist/harness/knowledge/read-http.js +5 -1
- package/dist/harness/knowledge/serve.d.ts +8 -7
- package/dist/harness/knowledge/serve.js +9 -0
- package/dist/harness/knowledge/source-store.js +26 -3
- package/dist/harness/knowledge/start-service-process.d.ts +15 -7
- package/dist/harness/knowledge/start-service-process.js +21 -9
- package/dist/harness/knowledge/types.d.ts +7 -0
- package/dist/harness/knowledge/writer-service.d.ts +37 -9
- package/dist/harness/knowledge/writer-service.js +120 -14
- package/dist/harness/knowledge/writer-worker-client.d.ts +10 -9
- package/dist/harness/knowledge/writer-worker-client.js +20 -2
- package/dist/harness/knowledge/writer-worker.js +9 -1
- package/dist/harness/memory/index.d.ts +6 -2
- package/dist/harness/memory/index.js +4 -1
- package/dist/harness/memory/memory-events.d.ts +25 -0
- package/dist/harness/memory/memory-events.js +38 -0
- package/dist/harness/memory/sqlite/agent-db.js +15 -0
- package/dist/harness/memory/sqlite/wisdom-store.d.ts +7 -2
- package/dist/harness/memory/sqlite/wisdom-store.js +86 -12
- package/dist/harness/memory/steward-policy.d.ts +3 -0
- package/dist/harness/memory/steward-policy.js +1 -1
- package/dist/harness/memory/types.d.ts +47 -7
- package/dist/harness/memory/wisdom-attribution.d.ts +136 -0
- package/dist/harness/memory/wisdom-attribution.js +287 -0
- package/dist/harness/memory/wisdom-events.d.ts +37 -0
- package/dist/harness/memory/wisdom-events.js +61 -0
- package/dist/harness/memory/wisdom-formation.d.ts +31 -1
- package/dist/harness/memory/wisdom-formation.js +130 -33
- package/dist/harness/memory/wisdom-gates.d.ts +14 -0
- package/dist/harness/memory/wisdom-gates.js +59 -19
- package/dist/harness/memory/wisdom.d.ts +7 -2
- package/dist/harness/memory/wisdom.js +49 -2
- package/dist/harness/observability/observer/hub.js +25 -15
- package/dist/harness/observability/observer/types.d.ts +10 -6
- package/dist/harness/run/agent/agent.d.ts +40 -21
- package/dist/harness/run/agent/agent.js +66 -13
- package/dist/harness/run/agent/index.d.ts +1 -1
- package/dist/harness/run/budget/budget.d.ts +28 -10
- package/dist/harness/run/budget/budget.js +38 -15
- package/dist/harness/run/model/index.d.ts +3 -1
- package/dist/harness/run/model/index.js +2 -1
- package/dist/harness/run/model/resolver.d.ts +4 -1
- package/dist/harness/run/model/resolver.js +36 -2
- package/dist/harness/run/model/run-scope.d.ts +2 -0
- package/dist/harness/run/model/run-scope.js +7 -0
- package/dist/harness/run/model/types.d.ts +22 -5
- package/dist/harness/run/model/types.js +3 -2
- package/dist/harness/run/model/window-truth.d.ts +37 -0
- package/dist/harness/run/model/window-truth.js +39 -0
- package/dist/harness/run/reliability/context-length-feedback.d.ts +77 -0
- package/dist/harness/run/reliability/context-length-feedback.js +128 -0
- package/dist/harness/run/reliability/harness-events.d.ts +3 -3
- package/dist/harness/run/reliability/model-error-policy.js +4 -0
- package/dist/harness/run/reliability/run-agent.d.ts +10 -4
- package/dist/harness/run/reliability/run-agent.js +137 -53
- package/dist/harness/run/reliability/run-metrics-collector.d.ts +19 -8
- package/dist/harness/run/reliability/run-metrics-collector.js +38 -23
- package/dist/harness/run/run-guard/default-run-guard.js +8 -8
- package/dist/harness/run/run-scope.d.ts +41 -4
- package/dist/harness/run/runner.d.ts +71 -31
- package/dist/harness/run/runner.js +368 -106
- package/dist/harness/session/attachments/index.d.ts +1 -0
- package/dist/harness/session/attachments/index.js +1 -0
- package/dist/harness/session/attachments/inject.d.ts +21 -10
- package/dist/harness/session/attachments/inject.js +76 -24
- package/dist/harness/session/attachments/recall-index.d.ts +70 -0
- package/dist/harness/session/attachments/recall-index.js +219 -0
- package/dist/harness/session/attachments/service.d.ts +21 -0
- package/dist/harness/session/attachments/service.js +258 -139
- package/dist/harness/session/attachments/types.d.ts +6 -0
- package/dist/harness/session/transform-store.d.ts +136 -0
- package/dist/harness/session/transform-store.js +302 -0
- package/dist/harness/session/types.d.ts +2 -2
- package/dist/harness/shared/events/agent-event-map.d.ts +46 -13
- package/dist/harness/shared/events/agent-event-map.js +3 -2
- package/dist/harness/shared/events/scenario-events.d.ts +6 -6
- package/dist/harness/shared/paths/glob.d.ts +52 -0
- package/dist/harness/shared/paths/glob.js +218 -0
- package/dist/harness/shared/paths/index.d.ts +84 -0
- package/dist/harness/shared/paths/index.js +179 -0
- package/dist/harness/shared/types/agent-definition.d.ts +1 -2
- package/dist/index.d.ts +14 -17
- package/dist/index.js +7 -9
- package/dist/integration/observability/metrics.d.ts +6 -6
- package/dist/integration/observability/metrics.js +13 -13
- package/dist/integration/observability/observer-bridge.js +2 -2
- package/dist/integration/observability/trace-collector.d.ts +5 -5
- package/dist/integration/observability/trace-collector.js +34 -35
- package/dist/integration/observability/trace-events.d.ts +3 -3
- package/dist/integration/observability/trace-events.js +3 -3
- package/dist/integration/providers/anthropic.js +14 -1
- package/dist/integration/providers/openai.js +7 -1
- package/dist/integration/providers/usage.d.ts +1 -1
- package/dist/integration/providers/wire-dump.d.ts +1 -1
- package/dist/integration/storage/archive-manager.d.ts +6 -0
- package/dist/integration/storage/archive-manager.js +10 -0
- package/dist/integration/storage/jsonl.d.ts +1 -1
- package/dist/integration/storage/jsonl.js +18 -16
- package/dist/subsystems/cognition-steward/conceptualize/config.yaml +4 -2
- package/dist/subsystems/cognition-steward/conceptualize/handler.js +12 -20
- package/dist/subsystems/memory-steward/backfill/config.yaml +4 -2
- package/dist/subsystems/memory-steward/backfill/handler.js +44 -52
- package/dist/subsystems/wisdom-steward/attribute/SUBSYSTEM.md +24 -0
- package/dist/subsystems/wisdom-steward/attribute/config.yaml +60 -0
- package/dist/subsystems/wisdom-steward/attribute/handler.d.ts +23 -0
- package/dist/subsystems/wisdom-steward/attribute/handler.js +167 -0
- package/dist/subsystems/wisdom-steward/evaluate/handler.js +3 -1
- package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +8 -1
- package/dist/subsystems/wisdom-steward/formation/config.yaml +13 -5
- package/dist/subsystems/wisdom-steward/formation/handler.js +39 -23
- package/dist/subsystems/wisdom-steward/govern/config.yaml +1 -1
- package/dist/subsystems/wisdom-steward/govern/handler.js +4 -0
- package/package.json +16 -14
- package/dist/harness/context/hybrid-compressor.d.ts +0 -41
- package/dist/harness/context/hybrid-compressor.js +0 -159
- package/dist/harness/context/llm-summarizer.d.ts +0 -46
- package/dist/harness/context/llm-summarizer.js +0 -249
- package/dist/harness/context/smart-router.d.ts +0 -75
- package/dist/harness/context/smart-router.js +0 -118
- package/dist/harness/context/truncate-compressor.d.ts +0 -28
- package/dist/harness/context/truncate-compressor.js +0 -107
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.d.ts +0 -97
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.js +0 -155
- package/dist/harness/extension/plugin-ecosystem/plugins/hooks.d.ts +0 -7
- package/dist/harness/extension/plugin-ecosystem/plugins/hooks.js +0 -7
- package/dist/harness/extension/plugin-ecosystem/plugins/lifecycle.d.ts +0 -86
- package/dist/harness/extension/plugin-ecosystem/plugins/lifecycle.js +0 -139
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SmartRouter — 智能路由器
|
|
3
|
-
*
|
|
4
|
-
* 预判性压缩策略:构建 prompt 前判断是否主动压缩。
|
|
5
|
-
*
|
|
6
|
-
* 四种路由:
|
|
7
|
-
* 1. fits — 消息在预算内,不需要压缩
|
|
8
|
-
* 2. truncate_tool_results_only — 只截断工具输出
|
|
9
|
-
* 3. compact_only — 只做 LLM 摘要
|
|
10
|
-
* 4. compact_then_truncate — 先 LLM 摘要,再截断
|
|
11
|
-
*
|
|
12
|
-
* 路由决策基于:
|
|
13
|
-
* - 溢出 token 数(含 1.2x 安全余量)
|
|
14
|
-
* - 工具结果可压缩空间(用 TOOL_RESULT_CHARS_PER_TOKEN=2 估算)
|
|
15
|
-
* - 摘要函数是否可用
|
|
16
|
-
*/
|
|
17
|
-
import { HeuristicTokenEstimator } from './token-estimator.js';
|
|
18
|
-
import { SAFETY_MARGIN } from './token-constants.js';
|
|
19
|
-
// ── 路由器实现 ──
|
|
20
|
-
export class SmartRouter {
|
|
21
|
-
estimator;
|
|
22
|
-
truncateOnlyThresholdChars;
|
|
23
|
-
toolResultMaxLength;
|
|
24
|
-
constructor(config) {
|
|
25
|
-
this.estimator = config?.tokenEstimator ?? new HeuristicTokenEstimator();
|
|
26
|
-
this.truncateOnlyThresholdChars = config?.truncateOnlyThresholdChars ?? 2000;
|
|
27
|
-
this.toolResultMaxLength = config?.toolResultMaxLength ?? 200;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* 决定路由
|
|
31
|
-
*
|
|
32
|
-
* @param messages - 消息历史
|
|
33
|
-
* @param messagesBudget - 消息 token 预算
|
|
34
|
-
* @param hasSummarize - 是否有摘要函数可用
|
|
35
|
-
* @returns 路由决策
|
|
36
|
-
*/
|
|
37
|
-
evaluate(messages, messagesBudget, hasSummarize) {
|
|
38
|
-
// 估算当前 token 数(含安全余量)
|
|
39
|
-
const rawEstimatedTokens = this.estimator.estimateMessages(messages);
|
|
40
|
-
const estimatedTokens = Math.ceil(rawEstimatedTokens * SAFETY_MARGIN);
|
|
41
|
-
// 计算溢出
|
|
42
|
-
const overflowTokens = Math.max(0, estimatedTokens - messagesBudget);
|
|
43
|
-
// 如果没有溢出,fits
|
|
44
|
-
if (overflowTokens <= 0) {
|
|
45
|
-
return {
|
|
46
|
-
route: 'fits',
|
|
47
|
-
shouldCompact: false,
|
|
48
|
-
overflowTokens: 0,
|
|
49
|
-
toolResultReducibleChars: 0,
|
|
50
|
-
truncateOnlyThresholdChars: this.truncateOnlyThresholdChars,
|
|
51
|
-
estimatedTokens,
|
|
52
|
-
messagesBudget,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
// 计算工具结果可压缩空间(用正确的 TOOL_RESULT_CHARS_PER_TOKEN 比率)
|
|
56
|
-
const toolResultReducibleChars = this.calculateToolResultReducibleChars(messages);
|
|
57
|
-
// 决定路由
|
|
58
|
-
let route;
|
|
59
|
-
if (!hasSummarize) {
|
|
60
|
-
// 没有摘要函数:只能截断
|
|
61
|
-
if (toolResultReducibleChars > 0) {
|
|
62
|
-
route = 'truncate_tool_results_only';
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
route = 'compact_only'; // 会回退到截断
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
// 有摘要函数:智能路由
|
|
70
|
-
if (toolResultReducibleChars <= 0) {
|
|
71
|
-
// 没有可压缩的工具结果
|
|
72
|
-
route = 'compact_only';
|
|
73
|
-
}
|
|
74
|
-
else if (toolResultReducibleChars >= this.truncateOnlyThresholdChars) {
|
|
75
|
-
// 工具结果可压缩空间足够大,只截断就够了
|
|
76
|
-
route = 'truncate_tool_results_only';
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
// 工具结果可压缩空间不够,需要先摘要再截断
|
|
80
|
-
route = 'compact_then_truncate';
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return {
|
|
84
|
-
route,
|
|
85
|
-
shouldCompact: true,
|
|
86
|
-
overflowTokens,
|
|
87
|
-
toolResultReducibleChars,
|
|
88
|
-
truncateOnlyThresholdChars: this.truncateOnlyThresholdChars,
|
|
89
|
-
estimatedTokens,
|
|
90
|
-
messagesBudget,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* 计算工具结果可压缩字符数
|
|
95
|
-
*
|
|
96
|
-
* 扫描所有工具结果消息,计算超过阈值的字符数。
|
|
97
|
-
* 注意:这里用原始字符数(非 CJK 加权),因为截断操作是按字符进行的。
|
|
98
|
-
*/
|
|
99
|
-
calculateToolResultReducibleChars(messages) {
|
|
100
|
-
let reducibleChars = 0;
|
|
101
|
-
for (const msg of messages) {
|
|
102
|
-
if (msg.role === 'tool' && msg.toolResults) {
|
|
103
|
-
for (const tr of msg.toolResults) {
|
|
104
|
-
// 失败结果载荷在 error 字段,不能只看 result
|
|
105
|
-
const body = tr.error !== undefined
|
|
106
|
-
? JSON.stringify({ error: tr.error })
|
|
107
|
-
: typeof tr.result === 'string'
|
|
108
|
-
? tr.result
|
|
109
|
-
: JSON.stringify(tr.result ?? null);
|
|
110
|
-
if (body.length > this.toolResultMaxLength) {
|
|
111
|
-
reducibleChars += body.length - this.toolResultMaxLength;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return reducibleChars;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TruncateCompressor — 截断压缩器
|
|
3
|
-
*
|
|
4
|
-
* 最简单的压缩策略:直接截断早期消息,保留最近消息。
|
|
5
|
-
* 不需要 LLM,零成本,但信息损失最大。
|
|
6
|
-
*
|
|
7
|
-
* 作为兜底方案,当 LLM 摘要不可用时使用。
|
|
8
|
-
*/
|
|
9
|
-
import type { Compressor, CompressParams, CompressResult } from './types.js';
|
|
10
|
-
export declare class TruncateCompressor implements Compressor {
|
|
11
|
-
/**
|
|
12
|
-
* 压缩消息
|
|
13
|
-
*
|
|
14
|
-
* 策略:
|
|
15
|
-
* 1. 从头部开始移除消息,直到达到目标 token 数
|
|
16
|
-
* 2. 插入一条摘要消息说明被移除的内容
|
|
17
|
-
* 3. 保持边界对齐(不拆分 tool_call/tool_result 对)
|
|
18
|
-
*/
|
|
19
|
-
compress(params: CompressParams): Promise<CompressResult>;
|
|
20
|
-
/**
|
|
21
|
-
* 检查消息是否包含工具调用
|
|
22
|
-
*/
|
|
23
|
-
private hasToolCall;
|
|
24
|
-
/**
|
|
25
|
-
* 检查消息是否是工具结果
|
|
26
|
-
*/
|
|
27
|
-
private isToolResult;
|
|
28
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TruncateCompressor — 截断压缩器
|
|
3
|
-
*
|
|
4
|
-
* 最简单的压缩策略:直接截断早期消息,保留最近消息。
|
|
5
|
-
* 不需要 LLM,零成本,但信息损失最大。
|
|
6
|
-
*
|
|
7
|
-
* 作为兜底方案,当 LLM 摘要不可用时使用。
|
|
8
|
-
*/
|
|
9
|
-
import { HeuristicTokenEstimator } from './token-estimator.js';
|
|
10
|
-
export class TruncateCompressor {
|
|
11
|
-
/**
|
|
12
|
-
* 压缩消息
|
|
13
|
-
*
|
|
14
|
-
* 策略:
|
|
15
|
-
* 1. 从头部开始移除消息,直到达到目标 token 数
|
|
16
|
-
* 2. 插入一条摘要消息说明被移除的内容
|
|
17
|
-
* 3. 保持边界对齐(不拆分 tool_call/tool_result 对)
|
|
18
|
-
*/
|
|
19
|
-
async compress(params) {
|
|
20
|
-
const { messages, targetTokens, tokenEstimator } = params;
|
|
21
|
-
const estimator = tokenEstimator ?? new HeuristicTokenEstimator();
|
|
22
|
-
// 如果没有消息需要压缩
|
|
23
|
-
if (messages.length === 0) {
|
|
24
|
-
return {
|
|
25
|
-
result: [],
|
|
26
|
-
estimatedTokens: 0,
|
|
27
|
-
fresh: false,
|
|
28
|
-
summarizeAttempted: false,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
// 计算当前 token 数
|
|
32
|
-
const currentTokens = estimator.estimateMessages(messages);
|
|
33
|
-
// 如果已经在预算内,不需要压缩
|
|
34
|
-
if (currentTokens <= targetTokens) {
|
|
35
|
-
return {
|
|
36
|
-
result: [...messages],
|
|
37
|
-
estimatedTokens: currentTokens,
|
|
38
|
-
fresh: false,
|
|
39
|
-
summarizeAttempted: false,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
// 需要压缩的 token 数
|
|
43
|
-
const excessTokens = currentTokens - targetTokens;
|
|
44
|
-
// 从头部开始移除消息
|
|
45
|
-
const remaining = [...messages];
|
|
46
|
-
let removedCount = 0;
|
|
47
|
-
let removedTokens = 0;
|
|
48
|
-
while (remaining.length > 0 && removedTokens < excessTokens) {
|
|
49
|
-
const msg = remaining[0];
|
|
50
|
-
const msgTokens = estimator.estimateMessage(msg);
|
|
51
|
-
// 边界对齐:如果下一条是 tool_result,一起移除
|
|
52
|
-
if (this.hasToolCall(msg) && remaining.length > 1 && this.isToolResult(remaining[1])) {
|
|
53
|
-
const nextTokens = estimator.estimateMessage(remaining[1]);
|
|
54
|
-
remaining.splice(0, 2);
|
|
55
|
-
removedTokens += msgTokens + nextTokens;
|
|
56
|
-
removedCount += 2;
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
remaining.shift();
|
|
60
|
-
removedTokens += msgTokens;
|
|
61
|
-
removedCount++;
|
|
62
|
-
}
|
|
63
|
-
// 至少保留最后 2 条消息
|
|
64
|
-
if (remaining.length <= 2) {
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
// 如果没有移除任何消息,强制移除最早的一条
|
|
69
|
-
if (removedCount === 0 && remaining.length > 2) {
|
|
70
|
-
const removed = remaining.shift();
|
|
71
|
-
removedCount = 1;
|
|
72
|
-
removedTokens = estimator.estimateMessage(removed);
|
|
73
|
-
}
|
|
74
|
-
// 生成摘要消息(user 角色,避免中段 system)
|
|
75
|
-
const summaryMessage = {
|
|
76
|
-
role: 'user',
|
|
77
|
-
content: `[Context compressed: ${removedCount} earlier messages removed to fit context window. ` +
|
|
78
|
-
`Approximately ${removedTokens} tokens saved. ` +
|
|
79
|
-
`The conversation continues from here.]`,
|
|
80
|
-
timestamp: Date.now(),
|
|
81
|
-
metadata: { source: 'contextSummary' },
|
|
82
|
-
};
|
|
83
|
-
// 组装结果
|
|
84
|
-
const result = [summaryMessage, ...remaining];
|
|
85
|
-
const estimatedTokens = estimator.estimateMessages(result);
|
|
86
|
-
return {
|
|
87
|
-
result,
|
|
88
|
-
estimatedTokens,
|
|
89
|
-
droppedSummary: `${removedCount} messages removed (~${removedTokens} tokens)`,
|
|
90
|
-
// 纯截断不是语义摘要(F8R-01 显式契约);调用方冷却语义:截断未发起 LLM
|
|
91
|
-
fresh: false,
|
|
92
|
-
summarizeAttempted: false,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* 检查消息是否包含工具调用
|
|
97
|
-
*/
|
|
98
|
-
hasToolCall(msg) {
|
|
99
|
-
return msg.role === 'assistant' && msg.toolCalls !== undefined && msg.toolCalls.length > 0;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* 检查消息是否是工具结果
|
|
103
|
-
*/
|
|
104
|
-
isToolResult(msg) {
|
|
105
|
-
return msg.role === 'tool' || (msg.toolResults !== undefined && msg.toolResults.length > 0);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Capability Registry — 能力注册中心
|
|
3
|
-
*
|
|
4
|
-
* 每种能力类型有独立的注册表,plugin 是能力的所有权边界。
|
|
5
|
-
*
|
|
6
|
-
* 核心原则:
|
|
7
|
-
* - plugin = 所有权边界(一个公司/功能的所有表面)
|
|
8
|
-
* - capability = 核心合约,多个 plugin 可以实现或消费
|
|
9
|
-
* - 冲突检测:同一 capability ID 不能被两个 plugin 注册
|
|
10
|
-
*/
|
|
11
|
-
import type { PluginManifest } from './manifest.js';
|
|
12
|
-
/**
|
|
13
|
-
* 能力类型枚举
|
|
14
|
-
*/
|
|
15
|
-
export type CapabilityType = 'provider' | 'channel' | 'tool' | 'context-engine' | 'embedding-provider' | 'speech-provider' | 'media-understanding-provider' | 'image-generation-provider' | 'video-generation-provider' | 'web-search-provider' | 'web-fetch-provider' | 'service' | 'command';
|
|
16
|
-
/**
|
|
17
|
-
* 能力注册记录
|
|
18
|
-
*/
|
|
19
|
-
export interface CapabilityRecord {
|
|
20
|
-
/** 能力类型 */
|
|
21
|
-
type: CapabilityType;
|
|
22
|
-
/** 能力 ID(如 provider name、tool name、channel id) */
|
|
23
|
-
capabilityId: string;
|
|
24
|
-
/** 拥有者 plugin ID */
|
|
25
|
-
pluginId: string;
|
|
26
|
-
/** 额外元数据 */
|
|
27
|
-
metadata?: Record<string, unknown>;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Capability Registry
|
|
31
|
-
*
|
|
32
|
-
* 中央能力注册中心。所有 plugin 注册的能力都在这里记录,
|
|
33
|
-
* 用于冲突检测、ownership 查询和诊断。
|
|
34
|
-
*/
|
|
35
|
-
export declare class CapabilityRegistry {
|
|
36
|
-
/** 所有能力记录 */
|
|
37
|
-
private records;
|
|
38
|
-
/** 索引:type:capabilityId → record */
|
|
39
|
-
private index;
|
|
40
|
-
/**
|
|
41
|
-
* 注册一个能力
|
|
42
|
-
*
|
|
43
|
-
* @param type - 能力类型
|
|
44
|
-
* @param capabilityId - 能力 ID
|
|
45
|
-
* @param pluginId - 拥有者 plugin ID
|
|
46
|
-
* @param metadata - 额外元数据
|
|
47
|
-
* @throws 如果能力已被另一个 plugin 注册
|
|
48
|
-
*/
|
|
49
|
-
register(type: CapabilityType, capabilityId: string, pluginId: string, metadata?: Record<string, unknown>): void;
|
|
50
|
-
/**
|
|
51
|
-
* 查询能力的拥有者
|
|
52
|
-
*
|
|
53
|
-
* @param type - 能力类型
|
|
54
|
-
* @param capabilityId - 能力 ID
|
|
55
|
-
* @returns 拥有者 plugin ID,未注册返回 null
|
|
56
|
-
*/
|
|
57
|
-
lookup(type: CapabilityType, capabilityId: string): string | null;
|
|
58
|
-
/**
|
|
59
|
-
* 查询指定 plugin 拥有的所有能力
|
|
60
|
-
*
|
|
61
|
-
* @param pluginId - Plugin ID
|
|
62
|
-
* @returns 能力记录列表
|
|
63
|
-
*/
|
|
64
|
-
getCapabilitiesForPlugin(pluginId: string): CapabilityRecord[];
|
|
65
|
-
/**
|
|
66
|
-
* 查询指定类型的所有能力
|
|
67
|
-
*
|
|
68
|
-
* @param type - 能力类型
|
|
69
|
-
* @returns 能力记录列表
|
|
70
|
-
*/
|
|
71
|
-
getCapabilitiesByType(type: CapabilityType): CapabilityRecord[];
|
|
72
|
-
/**
|
|
73
|
-
* 移除指定 plugin 的所有能力
|
|
74
|
-
*
|
|
75
|
-
* @param pluginId - Plugin ID
|
|
76
|
-
*/
|
|
77
|
-
unregisterPlugin(pluginId: string): void;
|
|
78
|
-
/**
|
|
79
|
-
* 获取所有注册记录(用于诊断)
|
|
80
|
-
*/
|
|
81
|
-
getAll(): CapabilityRecord[];
|
|
82
|
-
/**
|
|
83
|
-
* 获取能力总数
|
|
84
|
-
*/
|
|
85
|
-
get size(): number;
|
|
86
|
-
/**
|
|
87
|
-
* 检查能力是否已注册
|
|
88
|
-
*/
|
|
89
|
-
has(type: CapabilityType, capabilityId: string): boolean;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* 从 manifest 提取能力声明并注册到 CapabilityRegistry
|
|
93
|
-
*
|
|
94
|
-
* @param manifest - Plugin manifest
|
|
95
|
-
* @param registry - Capability Registry
|
|
96
|
-
*/
|
|
97
|
-
export declare function registerManifestCapabilities(manifest: PluginManifest, registry: CapabilityRegistry): void;
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Capability Registry — 能力注册中心
|
|
3
|
-
*
|
|
4
|
-
* 每种能力类型有独立的注册表,plugin 是能力的所有权边界。
|
|
5
|
-
*
|
|
6
|
-
* 核心原则:
|
|
7
|
-
* - plugin = 所有权边界(一个公司/功能的所有表面)
|
|
8
|
-
* - capability = 核心合约,多个 plugin 可以实现或消费
|
|
9
|
-
* - 冲突检测:同一 capability ID 不能被两个 plugin 注册
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* Capability Registry
|
|
13
|
-
*
|
|
14
|
-
* 中央能力注册中心。所有 plugin 注册的能力都在这里记录,
|
|
15
|
-
* 用于冲突检测、ownership 查询和诊断。
|
|
16
|
-
*/
|
|
17
|
-
export class CapabilityRegistry {
|
|
18
|
-
/** 所有能力记录 */
|
|
19
|
-
records = [];
|
|
20
|
-
/** 索引:type:capabilityId → record */
|
|
21
|
-
index = new Map();
|
|
22
|
-
/**
|
|
23
|
-
* 注册一个能力
|
|
24
|
-
*
|
|
25
|
-
* @param type - 能力类型
|
|
26
|
-
* @param capabilityId - 能力 ID
|
|
27
|
-
* @param pluginId - 拥有者 plugin ID
|
|
28
|
-
* @param metadata - 额外元数据
|
|
29
|
-
* @throws 如果能力已被另一个 plugin 注册
|
|
30
|
-
*/
|
|
31
|
-
register(type, capabilityId, pluginId, metadata) {
|
|
32
|
-
const key = `${type}:${capabilityId}`;
|
|
33
|
-
const existing = this.index.get(key);
|
|
34
|
-
if (existing && existing.pluginId !== pluginId) {
|
|
35
|
-
throw new Error(`Capability conflict: "${type}:${capabilityId}" is already registered by plugin "${existing.pluginId}", ` +
|
|
36
|
-
`cannot register from plugin "${pluginId}"`);
|
|
37
|
-
}
|
|
38
|
-
if (existing) {
|
|
39
|
-
// 同一 plugin 重复注册,静默忽略
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
const record = { type, capabilityId, pluginId, metadata };
|
|
43
|
-
this.records.push(record);
|
|
44
|
-
this.index.set(key, record);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* 查询能力的拥有者
|
|
48
|
-
*
|
|
49
|
-
* @param type - 能力类型
|
|
50
|
-
* @param capabilityId - 能力 ID
|
|
51
|
-
* @returns 拥有者 plugin ID,未注册返回 null
|
|
52
|
-
*/
|
|
53
|
-
lookup(type, capabilityId) {
|
|
54
|
-
const key = `${type}:${capabilityId}`;
|
|
55
|
-
return this.index.get(key)?.pluginId ?? null;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* 查询指定 plugin 拥有的所有能力
|
|
59
|
-
*
|
|
60
|
-
* @param pluginId - Plugin ID
|
|
61
|
-
* @returns 能力记录列表
|
|
62
|
-
*/
|
|
63
|
-
getCapabilitiesForPlugin(pluginId) {
|
|
64
|
-
return this.records.filter((r) => r.pluginId === pluginId);
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* 查询指定类型的所有能力
|
|
68
|
-
*
|
|
69
|
-
* @param type - 能力类型
|
|
70
|
-
* @returns 能力记录列表
|
|
71
|
-
*/
|
|
72
|
-
getCapabilitiesByType(type) {
|
|
73
|
-
return this.records.filter((r) => r.type === type);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* 移除指定 plugin 的所有能力
|
|
77
|
-
*
|
|
78
|
-
* @param pluginId - Plugin ID
|
|
79
|
-
*/
|
|
80
|
-
unregisterPlugin(pluginId) {
|
|
81
|
-
this.records = this.records.filter((r) => {
|
|
82
|
-
if (r.pluginId === pluginId) {
|
|
83
|
-
const key = `${r.type}:${r.capabilityId}`;
|
|
84
|
-
this.index.delete(key);
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
return true;
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* 获取所有注册记录(用于诊断)
|
|
92
|
-
*/
|
|
93
|
-
getAll() {
|
|
94
|
-
return [...this.records];
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* 获取能力总数
|
|
98
|
-
*/
|
|
99
|
-
get size() {
|
|
100
|
-
return this.records.length;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* 检查能力是否已注册
|
|
104
|
-
*/
|
|
105
|
-
has(type, capabilityId) {
|
|
106
|
-
return this.index.has(`${type}:${capabilityId}`);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* 从 manifest 提取能力声明并注册到 CapabilityRegistry
|
|
111
|
-
*
|
|
112
|
-
* @param manifest - Plugin manifest
|
|
113
|
-
* @param registry - Capability Registry
|
|
114
|
-
*/
|
|
115
|
-
export function registerManifestCapabilities(manifest, registry) {
|
|
116
|
-
const pluginId = manifest.id;
|
|
117
|
-
// 注册 providers
|
|
118
|
-
if (manifest.providers) {
|
|
119
|
-
for (const providerId of manifest.providers) {
|
|
120
|
-
registry.register('provider', providerId, pluginId);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
// 注册 channels
|
|
124
|
-
if (manifest.channels) {
|
|
125
|
-
for (const channelId of manifest.channels) {
|
|
126
|
-
registry.register('channel', channelId, pluginId);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
// 注册 contracts.tools
|
|
130
|
-
if (manifest.contracts?.tools) {
|
|
131
|
-
for (const toolName of manifest.contracts.tools) {
|
|
132
|
-
registry.register('tool', toolName, pluginId);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
// 注册 contracts 中的其他能力
|
|
136
|
-
const contractTypes = [
|
|
137
|
-
{ key: 'embeddingProviders', type: 'embedding-provider' },
|
|
138
|
-
{ key: 'speechProviders', type: 'speech-provider' },
|
|
139
|
-
{ key: 'mediaUnderstandingProviders', type: 'media-understanding-provider' },
|
|
140
|
-
{ key: 'imageGenerationProviders', type: 'image-generation-provider' },
|
|
141
|
-
{ key: 'videoGenerationProviders', type: 'video-generation-provider' },
|
|
142
|
-
{ key: 'webFetchProviders', type: 'web-fetch-provider' },
|
|
143
|
-
{ key: 'webSearchProviders', type: 'web-search-provider' },
|
|
144
|
-
];
|
|
145
|
-
if (manifest.contracts) {
|
|
146
|
-
for (const { key, type } of contractTypes) {
|
|
147
|
-
const ids = manifest.contracts[key];
|
|
148
|
-
if (ids) {
|
|
149
|
-
for (const id of ids) {
|
|
150
|
-
registry.register(type, id, pluginId);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Plugin 生命周期管理 — 扩展 PluginManager
|
|
3
|
-
*
|
|
4
|
-
* 为 PluginManager 添加完整的生命周期管理能力:
|
|
5
|
-
* - PluginState 状态机
|
|
6
|
-
* - activate / suspend / resume / unload 方法
|
|
7
|
-
* - 状态查询
|
|
8
|
-
*/
|
|
9
|
-
/** Plugin 状态 */
|
|
10
|
-
export type PluginState = 'discovered' | 'loaded' | 'activated' | 'suspended' | 'deactivated' | 'unloaded' | 'error';
|
|
11
|
-
/** Plugin 条目(带状态) */
|
|
12
|
-
export interface PluginEntry {
|
|
13
|
-
/** Plugin ID */
|
|
14
|
-
id: string;
|
|
15
|
-
/** 当前状态 */
|
|
16
|
-
state: PluginState;
|
|
17
|
-
/** 加载时间 */
|
|
18
|
-
loadedAt?: number;
|
|
19
|
-
/** 激活时间 */
|
|
20
|
-
activatedAt?: number;
|
|
21
|
-
/** 错误信息 */
|
|
22
|
-
error?: Error;
|
|
23
|
-
/** 扩展元数据 */
|
|
24
|
-
metadata: Record<string, unknown>;
|
|
25
|
-
}
|
|
26
|
-
/** Plugin 生命周期管理器 */
|
|
27
|
-
export declare class PluginLifecycleManager {
|
|
28
|
-
/** Plugin 状态映射 */
|
|
29
|
-
private states;
|
|
30
|
-
/**
|
|
31
|
-
* 注册 Plugin(发现后调用)
|
|
32
|
-
*/
|
|
33
|
-
register(pluginId: string): void;
|
|
34
|
-
/**
|
|
35
|
-
* 标记为已加载
|
|
36
|
-
*/
|
|
37
|
-
markLoaded(pluginId: string): void;
|
|
38
|
-
/**
|
|
39
|
-
* 激活 Plugin
|
|
40
|
-
*/
|
|
41
|
-
activate(pluginId: string): void;
|
|
42
|
-
/**
|
|
43
|
-
* 暂停 Plugin
|
|
44
|
-
*/
|
|
45
|
-
suspend(pluginId: string): void;
|
|
46
|
-
/**
|
|
47
|
-
* 恢复 Plugin
|
|
48
|
-
*/
|
|
49
|
-
resume(pluginId: string): void;
|
|
50
|
-
/**
|
|
51
|
-
* 停用 Plugin
|
|
52
|
-
*/
|
|
53
|
-
deactivate(pluginId: string): void;
|
|
54
|
-
/**
|
|
55
|
-
* 卸载 Plugin
|
|
56
|
-
*/
|
|
57
|
-
unload(pluginId: string): void;
|
|
58
|
-
/**
|
|
59
|
-
* 标记错误
|
|
60
|
-
*/
|
|
61
|
-
markError(pluginId: string, error: Error): void;
|
|
62
|
-
/**
|
|
63
|
-
* 获取 Plugin 状态
|
|
64
|
-
*/
|
|
65
|
-
getState(pluginId: string): PluginState;
|
|
66
|
-
/**
|
|
67
|
-
* 获取 Plugin 条目
|
|
68
|
-
*/
|
|
69
|
-
getEntry(pluginId: string): PluginEntry | undefined;
|
|
70
|
-
/**
|
|
71
|
-
* 获取所有 Plugin 状态
|
|
72
|
-
*/
|
|
73
|
-
listStates(): PluginEntry[];
|
|
74
|
-
/**
|
|
75
|
-
* 检查 Plugin 是否激活
|
|
76
|
-
*/
|
|
77
|
-
isActivated(pluginId: string): boolean;
|
|
78
|
-
/**
|
|
79
|
-
* 获取已激活的 Plugin ID 列表
|
|
80
|
-
*/
|
|
81
|
-
getActivatedIds(): string[];
|
|
82
|
-
/**
|
|
83
|
-
* 获取或创建条目
|
|
84
|
-
*/
|
|
85
|
-
private getOrCreate;
|
|
86
|
-
}
|