@octopi-agent/engine 0.98.4 → 0.121.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/builtin-model-info.js +28 -7
- package/dist/config-admin/agent-presets.d.ts +32 -0
- package/dist/config-admin/agent-presets.js +133 -0
- package/dist/config-admin/discover.d.ts +33 -4
- package/dist/config-admin/discover.js +101 -6
- package/dist/config-admin/env.d.ts +11 -0
- package/dist/config-admin/env.js +41 -0
- package/dist/config-admin/error-copy.d.ts +106 -0
- package/dist/config-admin/error-copy.js +287 -0
- package/dist/config-admin/i18n.d.ts +21 -0
- package/dist/config-admin/i18n.js +19 -0
- package/dist/config-admin/index.d.ts +6 -2
- package/dist/config-admin/index.js +3 -1
- package/dist/config-admin/model-presets.d.ts +14 -0
- package/dist/config-admin/model-presets.js +595 -70
- package/dist/config-admin/onboarding-apply.d.ts +71 -0
- package/dist/config-admin/onboarding-apply.js +235 -0
- package/dist/config-admin/onboarding.d.ts +154 -0
- package/dist/config-admin/onboarding.js +270 -0
- package/dist/config-admin/redact.d.ts +42 -9
- package/dist/config-admin/redact.js +69 -5
- package/dist/config-schema/agent.d.ts +40 -6
- package/dist/config-schema/agent.js +44 -6
- package/dist/config-schema/browser.d.ts +62 -0
- package/dist/config-schema/browser.js +89 -0
- package/dist/config-schema/context.d.ts +12 -37
- package/dist/config-schema/context.js +10 -31
- package/dist/config-schema/engine.d.ts +140 -164
- package/dist/config-schema/engine.js +10 -7
- package/dist/config-schema/governance.d.ts +20 -2
- package/dist/config-schema/governance.js +18 -3
- package/dist/config-schema/models.d.ts +10 -12
- package/dist/config-schema/models.js +16 -3
- package/dist/config-schema/run.d.ts +6 -2
- package/dist/config-schema/run.js +12 -2
- package/dist/config-schema/shared.d.ts +1 -3
- package/dist/config-schema/shared.js +4 -4
- package/dist/config-schema/substrate.d.ts +19 -88
- package/dist/config-schema/substrate.js +30 -107
- package/dist/config.d.ts +161 -123
- package/dist/config.js +109 -7
- package/dist/file-mode.d.ts +67 -0
- package/dist/file-mode.js +182 -0
- package/dist/fork-child.d.ts +82 -0
- package/dist/fork-child.js +123 -0
- package/dist/harness/activation/delegated-run.d.ts +42 -0
- package/dist/harness/activation/delegated-run.js +71 -0
- package/dist/harness/activation/dispatcher.js +11 -0
- package/dist/harness/activation/inbox.d.ts +3 -3
- package/dist/harness/activation/inbox.js +3 -3
- package/dist/harness/activation/index.d.ts +1 -0
- package/dist/harness/activation/run-backend.d.ts +92 -0
- package/dist/harness/activation/run-backend.js +16 -0
- package/dist/harness/activation/run-protocol.d.ts +392 -0
- package/dist/harness/activation/run-protocol.js +19 -0
- package/dist/harness/activation/runtime.d.ts +33 -0
- package/dist/harness/activation/runtime.js +130 -31
- package/dist/harness/activation/types.d.ts +20 -3
- package/dist/harness/agent/builder.d.ts +36 -3
- package/dist/harness/agent/builder.js +206 -46
- package/dist/harness/agent/config-bridge.d.ts +10 -1
- package/dist/harness/agent/config-bridge.js +24 -5
- package/dist/harness/agent/config-integrity.js +19 -2
- package/dist/harness/agent/registered-tool-adapter.d.ts +27 -0
- package/dist/harness/agent/registered-tool-adapter.js +67 -0
- package/dist/harness/agent/wire-agent-builder.d.ts +13 -3
- package/dist/harness/agent/wire-agent-builder.js +35 -9
- package/dist/harness/capabilities/document/backends/plain.js +2 -1
- package/dist/harness/capabilities/document/factory.d.ts +5 -0
- package/dist/harness/capabilities/document/factory.js +1 -0
- package/dist/harness/capabilities/document/legacy/factory.js +3 -2
- 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/audit/reader.d.ts +17 -0
- package/dist/harness/collaboration/autonomous-subsystem/audit/reader.js +66 -36
- package/dist/harness/collaboration/autonomous-subsystem/audit/writer.d.ts +6 -2
- package/dist/harness/collaboration/autonomous-subsystem/audit/writer.js +27 -7
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.js +13 -0
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +2 -1
- package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +11 -0
- package/dist/harness/collaboration/autonomous-subsystem/runtime.js +17 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.d.ts +14 -4
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +50 -41
- 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/executor.js +4 -1
- package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +7 -3
- package/dist/harness/collaboration/delegation/child-run.d.ts +10 -1
- package/dist/harness/collaboration/delegation/child-run.js +38 -6
- 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/registry-types.d.ts +2 -0
- package/dist/harness/collaboration/delegation/service.d.ts +11 -4
- package/dist/harness/collaboration/delegation/service.js +35 -13
- package/dist/harness/collaboration/delegation/store.d.ts +4 -0
- package/dist/harness/collaboration/delegation/store.js +3 -1
- package/dist/harness/collaboration/delegation/types.d.ts +34 -2
- package/dist/harness/collaboration/delegation/types.js +22 -0
- package/dist/harness/collaboration/delegation/wiring.d.ts +2 -0
- package/dist/harness/collaboration/delegation/wiring.js +12 -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 +44 -11
- package/dist/harness/context/capabilities/compact/engine.js +296 -160
- 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 +7 -2
- package/dist/harness/context/capabilities/compact/index.js +5 -1
- 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 +134 -19
- 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/gate.d.ts +19 -2
- package/dist/harness/context/capabilities/summary/gate.js +53 -6
- package/dist/harness/context/capabilities/summary/port.js +0 -1
- package/dist/harness/context/capabilities/summary/registry.js +20 -0
- package/dist/harness/context/capabilities/summary/resolver.d.ts +1 -1
- package/dist/harness/context/capabilities/summary/resolver.js +1 -6
- package/dist/harness/context/capabilities/summary/tool-binding.d.ts +1 -1
- package/dist/harness/context/capabilities/summary/tool-binding.js +16 -12
- package/dist/harness/context/capabilities/summary/tool-bindings.d.ts +13 -0
- package/dist/harness/context/capabilities/summary/tool-bindings.js +22 -0
- package/dist/harness/context/capabilities/summary/types.d.ts +19 -6
- package/dist/harness/context/constitution/default-agents.md +85 -0
- package/dist/harness/context/context-size-ledger.d.ts +143 -0
- package/dist/harness/context/context-size-ledger.js +243 -0
- package/dist/harness/context/default-context-engine.d.ts +290 -120
- package/dist/harness/context/default-context-engine.js +1555 -764
- package/dist/harness/context/index.d.ts +3 -2
- package/dist/harness/context/index.js +2 -1
- package/dist/harness/context/layer-health.d.ts +4 -0
- package/dist/harness/context/layer-health.js +4 -0
- package/dist/harness/context/layer-types.d.ts +72 -0
- package/dist/harness/context/layer-types.js +87 -2
- package/dist/harness/context/layers.d.ts +17 -15
- package/dist/harness/context/layers.js +54 -17
- package/dist/harness/context/message-selector.d.ts +10 -8
- package/dist/harness/context/message-selector.js +49 -27
- package/dist/harness/context/prefix-fingerprint.d.ts +46 -0
- package/dist/harness/context/prefix-fingerprint.js +52 -0
- package/dist/harness/context/summarize.d.ts +2 -2
- package/dist/harness/context/summarize.js +27 -2
- package/dist/harness/context/system-prompt-assembler.d.ts +4 -0
- package/dist/harness/context/system-prompt-assembler.js +7 -3
- 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 +109 -16
- package/dist/harness/context/tool-result-aging.js +220 -55
- 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 +196 -119
- package/dist/harness/context/types.js +25 -1
- package/dist/harness/extension/execution-environment/effect-policy.d.ts +4 -3
- package/dist/harness/extension/execution-environment/effect-policy.js +2 -2
- package/dist/harness/extension/execution-environment/ops-audit.d.ts +1 -1
- package/dist/harness/extension/execution-environment/privileged-exec.js +4 -1
- 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/workspace.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +28 -2
- package/dist/harness/extension/plugin-ecosystem/channel-types.js +11 -2
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.d.ts +12 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.js +25 -0
- package/dist/harness/extension/plugin-ecosystem/commands/builtin.js +28 -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/index.d.ts +1 -0
- package/dist/harness/extension/plugin-ecosystem/index.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +223 -222
- package/dist/harness/extension/plugin-ecosystem/plugins/api.js +218 -203
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-instances.d.ts +95 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-instances.js +170 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-kinds.d.ts +178 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-kinds.js +314 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.d.ts +78 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.js +80 -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 +57 -114
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +279 -282
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +46 -484
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +123 -345
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +50 -223
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +144 -20
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.d.ts +17 -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/browser-types.d.ts +333 -0
- package/dist/harness/extension/plugin-ecosystem/tools/browser-types.js +16 -0
- package/dist/harness/extension/plugin-ecosystem/tools/browser.d.ts +64 -0
- package/dist/harness/extension/plugin-ecosystem/tools/browser.js +692 -0
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +0 -37
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +108 -4
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +36 -8
- package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +34 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.d.ts +0 -6
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +57 -4
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +81 -13
- package/dist/harness/extension/plugin-ecosystem/tools/http.js +5 -0
- package/dist/harness/extension/plugin-ecosystem/tools/knowledge.js +13 -7
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +126 -14
- package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/platform.js +44 -5
- 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 +19 -24
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.d.ts +7 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.js +4 -0
- 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/credentials/db.d.ts +9 -0
- package/dist/harness/governance/credentials/db.js +122 -31
- package/dist/harness/governance/credentials/store.d.ts +68 -7
- package/dist/harness/governance/credentials/store.js +177 -64
- package/dist/harness/governance/credentials/types.d.ts +13 -2
- 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/index.d.ts +1 -0
- package/dist/harness/governance/index.js +1 -0
- package/dist/harness/governance/registry/db.d.ts +32 -0
- package/dist/harness/governance/registry/db.js +142 -0
- package/dist/harness/governance/registry/index.d.ts +9 -0
- package/dist/harness/governance/registry/index.js +9 -0
- package/dist/harness/governance/registry/service.d.ts +381 -0
- package/dist/harness/governance/registry/service.js +825 -0
- package/dist/harness/governance/registry/types.d.ts +77 -0
- package/dist/harness/governance/registry/types.js +7 -0
- package/dist/harness/governance/security/capability-enforcer.js +1 -2
- package/dist/harness/governance/security/default-security-guard.d.ts +3 -0
- package/dist/harness/governance/security/default-security-guard.js +12 -1
- package/dist/harness/governance/security/risk-evaluator.d.ts +13 -3
- package/dist/harness/governance/security/risk-evaluator.js +307 -21
- package/dist/harness/governance/security/shell-parser-treesitter.js +12 -4
- package/dist/harness/governance/session-acl/tool-rights.d.ts +1 -0
- package/dist/harness/index.d.ts +17 -15
- package/dist/harness/index.js +9 -9
- package/dist/harness/knowledge/boot-config.d.ts +57 -0
- package/dist/harness/knowledge/boot-config.js +52 -0
- package/dist/harness/knowledge/catalog-types.d.ts +2 -0
- package/dist/harness/knowledge/client.d.ts +77 -9
- package/dist/harness/knowledge/client.js +95 -24
- package/dist/harness/knowledge/db.d.ts +16 -0
- package/dist/harness/knowledge/db.js +112 -41
- 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 +11 -7
- package/dist/harness/knowledge/grounding.js +7 -2
- package/dist/harness/knowledge/http-app.d.ts +15 -0
- package/dist/harness/knowledge/http-app.js +117 -25
- package/dist/harness/knowledge/http-bridge.d.ts +15 -0
- package/dist/harness/knowledge/http-bridge.js +19 -0
- 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 +5 -3
- package/dist/harness/knowledge/purge.js +5 -2
- package/dist/harness/knowledge/query-service.d.ts +25 -4
- package/dist/harness/knowledge/query-service.js +79 -43
- package/dist/harness/knowledge/query-worker-client.d.ts +14 -2
- package/dist/harness/knowledge/query-worker-client.js +8 -3
- package/dist/harness/knowledge/query-worker.js +9 -5
- package/dist/harness/knowledge/read-http.d.ts +2 -0
- package/dist/harness/knowledge/read-http.js +14 -3
- package/dist/harness/knowledge/retriever.d.ts +1 -1
- package/dist/harness/knowledge/retriever.js +1 -2
- package/dist/harness/knowledge/serve.d.ts +14 -8
- package/dist/harness/knowledge/serve.js +14 -6
- package/dist/harness/knowledge/source-store.d.ts +101 -5
- package/dist/harness/knowledge/source-store.js +323 -74
- package/dist/harness/knowledge/start-service-process.d.ts +41 -14
- package/dist/harness/knowledge/start-service-process.js +67 -96
- package/dist/harness/knowledge/tenant-gate.d.ts +81 -0
- package/dist/harness/knowledge/tenant-gate.js +167 -0
- package/dist/harness/knowledge/types.d.ts +7 -0
- package/dist/harness/knowledge/writer-service.d.ts +55 -11
- package/dist/harness/knowledge/writer-service.js +200 -30
- package/dist/harness/knowledge/writer-worker-client.d.ts +19 -11
- package/dist/harness/knowledge/writer-worker-client.js +40 -5
- package/dist/harness/knowledge/writer-worker.js +20 -5
- package/dist/harness/memory/backfill-trigger.d.ts +10 -3
- package/dist/harness/memory/backfill-trigger.js +19 -19
- package/dist/harness/memory/cognition-seeds.d.ts +45 -0
- package/dist/harness/memory/cognition-seeds.js +67 -0
- package/dist/harness/memory/cognition.d.ts +12 -3
- package/dist/harness/memory/cognition.js +55 -35
- package/dist/harness/memory/conceptualizer.d.ts +11 -1
- package/dist/harness/memory/conceptualizer.js +10 -1
- package/dist/harness/memory/context-slice.d.ts +42 -0
- package/dist/harness/memory/context-slice.js +197 -0
- package/dist/harness/memory/health-probe.d.ts +8 -2
- package/dist/harness/memory/health-probe.js +10 -13
- package/dist/harness/memory/index.d.ts +5 -1
- package/dist/harness/memory/index.js +3 -1
- package/dist/harness/memory/sqlite/agent-db.d.ts +1 -0
- package/dist/harness/memory/sqlite/agent-db.js +9 -8
- package/dist/harness/memory/sqlite/cognition-store.d.ts +26 -3
- package/dist/harness/memory/sqlite/cognition-store.js +103 -45
- package/dist/harness/memory/sqlite/memory-store.js +4 -0
- package/dist/harness/memory/sqlite/sqlite-vec.d.ts +24 -1
- package/dist/harness/memory/sqlite/sqlite-vec.js +37 -1
- package/dist/harness/memory/sqlite/wisdom-store.js +35 -10
- package/dist/harness/memory/types.d.ts +24 -6
- package/dist/harness/memory/wisdom-formation.d.ts +14 -3
- package/dist/harness/memory/wisdom-formation.js +85 -22
- package/dist/harness/memory/wisdom-gates.d.ts +14 -0
- package/dist/harness/memory/wisdom-gates.js +59 -19
- package/dist/harness/memory/wisdom.js +9 -0
- package/dist/harness/observability/observer/hub.d.ts +10 -0
- package/dist/harness/observability/observer/hub.js +120 -17
- 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 +67 -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/concurrency/tool-validator.js +4 -3
- 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 +32 -4
- package/dist/harness/run/reliability/run-agent.js +216 -63
- 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-host.d.ts +302 -0
- package/dist/harness/run/run-host.js +978 -0
- package/dist/harness/run/run-scope.d.ts +48 -4
- package/dist/harness/run/run-scope.js +19 -1
- package/dist/harness/run/runner.d.ts +181 -39
- package/dist/harness/run/runner.js +654 -119
- 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/in-memory-store.js +13 -1
- package/dist/harness/session/schedules/service.d.ts +10 -2
- package/dist/harness/session/schedules/service.js +13 -2
- package/dist/harness/session/tasks/tools.js +12 -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 +11 -15
- package/dist/harness/shared/events/agent-event-map.d.ts +75 -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/types/agent-definition.d.ts +7 -2
- package/dist/index.d.ts +16 -18
- package/dist/index.js +9 -10
- package/dist/integration/agent-runtime/channel-message-source.d.ts +3 -1
- package/dist/integration/agent-runtime/channel-message-source.js +4 -3
- package/dist/integration/browser/camoufox.d.ts +40 -0
- package/dist/integration/browser/camoufox.js +80 -0
- package/dist/integration/browser/index.d.ts +91 -0
- package/dist/integration/browser/index.js +110 -0
- package/dist/integration/browser/install.d.ts +47 -0
- package/dist/integration/browser/install.js +214 -0
- package/dist/integration/browser/playwright.d.ts +224 -0
- package/dist/integration/browser/playwright.js +925 -0
- package/dist/integration/browser/service.d.ts +41 -0
- package/dist/integration/browser/service.js +181 -0
- package/dist/integration/browser/stealth.d.ts +42 -0
- package/dist/integration/browser/stealth.js +104 -0
- 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-message-normalize.d.ts +20 -0
- package/dist/integration/providers/anthropic-message-normalize.js +48 -0
- package/dist/integration/providers/anthropic.js +41 -3
- package/dist/integration/providers/fetch-timeout.d.ts +17 -0
- package/dist/integration/providers/fetch-timeout.js +24 -0
- package/dist/integration/providers/openai.d.ts +8 -0
- package/dist/integration/providers/openai.js +48 -2
- package/dist/integration/providers/usage.d.ts +1 -1
- package/dist/integration/providers/wire-dump-diff.js +2 -1
- package/dist/integration/providers/wire-dump.d.ts +57 -3
- package/dist/integration/providers/wire-dump.js +119 -6
- package/dist/integration/storage/archive-manager.d.ts +20 -2
- package/dist/integration/storage/archive-manager.js +34 -8
- package/dist/integration/storage/atomic-tmp.d.ts +12 -0
- package/dist/integration/storage/atomic-tmp.js +36 -0
- package/dist/integration/storage/jsonl.d.ts +10 -1
- package/dist/integration/storage/jsonl.js +155 -54
- package/dist/integration/storage/session-index.d.ts +5 -0
- package/dist/integration/storage/session-index.js +25 -4
- package/dist/integration/tools/assemble.d.ts +50 -0
- package/dist/integration/tools/assemble.js +137 -0
- package/dist/paths.d.ts +18 -0
- package/dist/paths.js +36 -0
- package/dist/subsystems/cognition-steward/conceptualize/config.yaml +3 -1
- package/dist/subsystems/cognition-steward/conceptualize/handler.js +74 -5
- package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +3 -2
- package/dist/subsystems/cognition-steward/consolidate/config.yaml +11 -2
- package/dist/subsystems/cognition-steward/consolidate/handler.d.ts +6 -3
- package/dist/subsystems/cognition-steward/consolidate/handler.js +266 -28
- package/dist/subsystems/memory-steward/backfill/handler.js +3 -2
- package/dist/subsystems/memory-steward/govern/config.yaml +6 -1
- package/dist/subsystems/wisdom-steward/attribute/config.yaml +5 -1
- package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +8 -1
- package/dist/subsystems/wisdom-steward/formation/config.yaml +4 -0
- package/dist/subsystems/wisdom-steward/formation/handler.js +27 -5
- package/dist/subsystems/wisdom-steward/govern/config.yaml +6 -1
- package/package.json +14 -15
- 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
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
* KnowledgeSourceStore — 源注册 + 可见性 + catalog 投影
|
|
3
3
|
*/
|
|
4
4
|
import { randomUUID, createHash } from 'node:crypto';
|
|
5
|
+
import { PLATFORM_TENANT_ID } from '@octopi-agent/core/types.js';
|
|
5
6
|
import { KnowledgeDatabase } from './db.js';
|
|
7
|
+
import { ownerFunnelAllows, projectGateAllows, projectGateSql, tenantGateAllows, tenantGateSql, tenantOwnGateSql, tenantPrecedenceOrder, } from './tenant-gate.js';
|
|
6
8
|
import { deriveTopicsFromPaths } from './topics.js';
|
|
7
9
|
import { asSourceId } from './types.js';
|
|
8
10
|
const DEFAULT_SYNC = { strategy: 'watch', debounceMs: 2000, enabled: true };
|
|
@@ -60,12 +62,22 @@ function deriveDisplayName(location) {
|
|
|
60
62
|
return parts[parts.length - 1] || location || 'source';
|
|
61
63
|
}
|
|
62
64
|
function toCatalogItem(source, extras) {
|
|
65
|
+
const human = source.description?.trim();
|
|
66
|
+
const generated = source.generatedDescription?.trim();
|
|
63
67
|
return {
|
|
64
68
|
id: source.id,
|
|
65
69
|
displayName: source.displayName,
|
|
66
70
|
kind: source.kind,
|
|
67
71
|
status: statusBucket(source.status),
|
|
68
|
-
description:
|
|
72
|
+
description: human || generated || undefined,
|
|
73
|
+
// 信任分级(human > llm > heuristic);blocked_secret 的文本是启发式,归 heuristic 档
|
|
74
|
+
...(human
|
|
75
|
+
? { descriptionSource: 'human' }
|
|
76
|
+
: generated
|
|
77
|
+
? {
|
|
78
|
+
descriptionSource: source.generatedDescriptionSource === 'llm' ? 'llm' : 'heuristic',
|
|
79
|
+
}
|
|
80
|
+
: {}),
|
|
69
81
|
scopeLevel: source.scopeRef.level,
|
|
70
82
|
scaleLabel: scaleLabel(source, extras?.fileCount),
|
|
71
83
|
location: source.location,
|
|
@@ -93,6 +105,9 @@ function rowToSource(row) {
|
|
|
93
105
|
displayName: String(row.display_name),
|
|
94
106
|
description: row.description == null ? undefined : String(row.description),
|
|
95
107
|
generatedDescription: row.generated_description == null ? undefined : String(row.generated_description),
|
|
108
|
+
generatedDescriptionSource: row.generated_description_source == null
|
|
109
|
+
? undefined
|
|
110
|
+
: String(row.generated_description_source),
|
|
96
111
|
catalogPriority: row.catalog_priority == null ? undefined : Number(row.catalog_priority),
|
|
97
112
|
hiddenFromCatalog: Number(row.hidden_from_catalog) === 1,
|
|
98
113
|
authRef: row.auth_ref == null ? undefined : String(row.auth_ref),
|
|
@@ -107,6 +122,10 @@ function rowToSource(row) {
|
|
|
107
122
|
}
|
|
108
123
|
export class KnowledgeSourceStore {
|
|
109
124
|
db;
|
|
125
|
+
/** listVisible 批处理期的 source 行同步缓存(filter 无 await,无并发窗口;平时为 null) */
|
|
126
|
+
rowCache = null;
|
|
127
|
+
/** 项目行批处理缓存(评审 m6:防逐源 N+1;与 rowCache 同模式,批次内同步读) */
|
|
128
|
+
projectRowCache = null;
|
|
110
129
|
constructor(db) {
|
|
111
130
|
this.db = db;
|
|
112
131
|
}
|
|
@@ -123,7 +142,7 @@ export class KnowledgeSourceStore {
|
|
|
123
142
|
/**
|
|
124
143
|
* 注册知识源
|
|
125
144
|
*/
|
|
126
|
-
register(input) {
|
|
145
|
+
register(input, opts) {
|
|
127
146
|
const now = Date.now();
|
|
128
147
|
const id = input.id ?? `ks_${randomUUID().slice(0, 12)}`;
|
|
129
148
|
const displayName = input.displayName?.trim() || deriveDisplayName(input.location);
|
|
@@ -138,6 +157,7 @@ export class KnowledgeSourceStore {
|
|
|
138
157
|
displayName,
|
|
139
158
|
description: input.description,
|
|
140
159
|
generatedDescription: input.generatedDescription,
|
|
160
|
+
generatedDescriptionSource: input.generatedDescriptionSource,
|
|
141
161
|
catalogPriority: input.catalogPriority,
|
|
142
162
|
hiddenFromCatalog: input.hiddenFromCatalog ?? false,
|
|
143
163
|
authRef: input.authRef,
|
|
@@ -147,7 +167,12 @@ export class KnowledgeSourceStore {
|
|
|
147
167
|
updatedAt: now,
|
|
148
168
|
};
|
|
149
169
|
if (scopeRef.level === 'project') {
|
|
150
|
-
|
|
170
|
+
// 项目行必须与源同域登记(归属打标在写路径;同 key 可跨域各一行)。
|
|
171
|
+
// platform 域隐式登记 = 隐式共享库(评审 M2):显式 createProject 才能造 private 平台项目
|
|
172
|
+
this.createProject(scopeRef.key, undefined, {
|
|
173
|
+
...opts,
|
|
174
|
+
visibility: opts?.tenantId === PLATFORM_TENANT_ID ? 'public' : opts?.visibility,
|
|
175
|
+
});
|
|
151
176
|
}
|
|
152
177
|
this.upsertRow(source);
|
|
153
178
|
return source;
|
|
@@ -181,6 +206,13 @@ export class KnowledgeSourceStore {
|
|
|
181
206
|
: patch.generatedDescription,
|
|
182
207
|
}
|
|
183
208
|
: {}),
|
|
209
|
+
...(patch.generatedDescriptionSource !== undefined
|
|
210
|
+
? {
|
|
211
|
+
generatedDescriptionSource: patch.generatedDescriptionSource === null
|
|
212
|
+
? undefined
|
|
213
|
+
: patch.generatedDescriptionSource,
|
|
214
|
+
}
|
|
215
|
+
: {}),
|
|
184
216
|
...(patch.catalogPriority !== undefined ? { catalogPriority: patch.catalogPriority } : {}),
|
|
185
217
|
...(patch.hiddenFromCatalog !== undefined
|
|
186
218
|
? { hiddenFromCatalog: patch.hiddenFromCatalog }
|
|
@@ -192,8 +224,16 @@ export class KnowledgeSourceStore {
|
|
|
192
224
|
? {
|
|
193
225
|
scopeRef: (() => {
|
|
194
226
|
const scope = normalizeScope(patch.scopeRef);
|
|
195
|
-
if (scope.level === 'project')
|
|
196
|
-
|
|
227
|
+
if (scope.level === 'project') {
|
|
228
|
+
// 项目行与源同域登记(评审 m2:否则固定落 default 域成跨域幻影行);
|
|
229
|
+
// platform 域隐式登记 = 隐式共享库(评审 M2),显式 createProject 才能造 private 平台项目
|
|
230
|
+
const row = this.sourceRow(id);
|
|
231
|
+
this.createProject(scope.key, undefined, {
|
|
232
|
+
tenantId: row?.tenant_id,
|
|
233
|
+
registeredBy: row?.registered_by,
|
|
234
|
+
visibility: row?.tenant_id === PLATFORM_TENANT_ID ? 'public' : undefined,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
197
237
|
return scope;
|
|
198
238
|
})(),
|
|
199
239
|
}
|
|
@@ -218,7 +258,7 @@ export class KnowledgeSourceStore {
|
|
|
218
258
|
*/
|
|
219
259
|
remove(id) {
|
|
220
260
|
const res = this.db.raw.prepare('DELETE FROM knowledge_sources WHERE id = ?').run(id);
|
|
221
|
-
this.db.raw.prepare('DELETE FROM
|
|
261
|
+
this.db.raw.prepare('DELETE FROM knowledge_agent_visibility WHERE source_id = ?').run(id);
|
|
222
262
|
this.db.raw
|
|
223
263
|
.prepare("DELETE FROM knowledge_session_visibility WHERE target_type = 'source' AND target_id = ?")
|
|
224
264
|
.run(id);
|
|
@@ -273,11 +313,12 @@ export class KnowledgeSourceStore {
|
|
|
273
313
|
.run(opts?.tenantId ?? 'default', opts?.gatewayId ?? 'default', projectKey, agentId);
|
|
274
314
|
}
|
|
275
315
|
listProjectAgents(projectKey, opts) {
|
|
316
|
+
const gate = tenantOwnGateSql('tenant_id', opts ?? {});
|
|
276
317
|
const rows = this.db.raw
|
|
277
318
|
.prepare(`SELECT local_agent_id AS agent_id FROM knowledge_project_agents
|
|
278
|
-
WHERE
|
|
319
|
+
WHERE ${gate.sql} AND gateway_id = ? AND project_key = ?
|
|
279
320
|
ORDER BY local_agent_id`)
|
|
280
|
-
.all(
|
|
321
|
+
.all(...gate.params, opts?.gatewayId ?? 'default', projectKey);
|
|
281
322
|
return rows.map((r) => r.agent_id);
|
|
282
323
|
}
|
|
283
324
|
/**
|
|
@@ -288,28 +329,69 @@ export class KnowledgeSourceStore {
|
|
|
288
329
|
if (source && source.scopeRef.level !== 'global') {
|
|
289
330
|
throw new Error(`hide is only valid for global sources (got scope ${source.scopeRef.level})`);
|
|
290
331
|
}
|
|
332
|
+
// 一表两向(T3b):hide=exclude 覆盖(含翻转既有挂载 include)
|
|
291
333
|
this.db.raw
|
|
292
|
-
.prepare(`INSERT OR
|
|
293
|
-
(tenant_id, gateway_id, local_agent_id, source_id, created_at)
|
|
294
|
-
VALUES (?, ?, ?, ?, ?)`)
|
|
334
|
+
.prepare(`INSERT OR REPLACE INTO knowledge_agent_visibility
|
|
335
|
+
(tenant_id, gateway_id, local_agent_id, source_id, op, created_at)
|
|
336
|
+
VALUES (?, ?, ?, ?, 'exclude', ?)`)
|
|
295
337
|
.run(opts?.tenantId ?? 'default', opts?.gatewayId ?? 'default', agentId, sourceId, Date.now());
|
|
296
338
|
}
|
|
297
339
|
unhideSource(agentId, sourceId, opts) {
|
|
340
|
+
// 只撤 exclude(挂载 include 行不受影响)
|
|
341
|
+
this.db.raw
|
|
342
|
+
.prepare(`DELETE FROM knowledge_agent_visibility
|
|
343
|
+
WHERE tenant_id = ? AND gateway_id = ? AND local_agent_id = ? AND source_id = ? AND op = 'exclude'`)
|
|
344
|
+
.run(opts?.tenantId ?? 'default', opts?.gatewayId ?? 'default', agentId, sourceId);
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* 挂载(T3b,arch/multi-tenancy.md §6 挂载库):include 覆盖基础可见性(含翻转既有隐藏)。
|
|
348
|
+
* 租户闸不受影响——挂载不出租户(registry 侧另有 guard)。
|
|
349
|
+
*/
|
|
350
|
+
mountSource(agentId, sourceId, opts) {
|
|
351
|
+
this.db.raw
|
|
352
|
+
.prepare(`INSERT OR REPLACE INTO knowledge_agent_visibility
|
|
353
|
+
(tenant_id, gateway_id, local_agent_id, source_id, op, created_at)
|
|
354
|
+
VALUES (?, ?, ?, ?, 'include', ?)`)
|
|
355
|
+
.run(opts?.tenantId ?? 'default', opts?.gatewayId ?? 'default', agentId, sourceId, Date.now());
|
|
356
|
+
}
|
|
357
|
+
/** 卸载:只撤 include(隐藏 exclude 行不受影响);回基础可见性 */
|
|
358
|
+
unmountSource(agentId, sourceId, opts) {
|
|
298
359
|
this.db.raw
|
|
299
|
-
.prepare(
|
|
360
|
+
.prepare(`DELETE FROM knowledge_agent_visibility
|
|
361
|
+
WHERE tenant_id = ? AND gateway_id = ? AND local_agent_id = ? AND source_id = ? AND op = 'include'`)
|
|
300
362
|
.run(opts?.tenantId ?? 'default', opts?.gatewayId ?? 'default', agentId, sourceId);
|
|
301
363
|
}
|
|
302
364
|
listHidden(agentId, opts) {
|
|
365
|
+
return this.listAgentOp(agentId, 'exclude', opts);
|
|
366
|
+
}
|
|
367
|
+
/** 已挂载源(include) */
|
|
368
|
+
listMounted(agentId, opts) {
|
|
369
|
+
return this.listAgentOp(agentId, 'include', opts);
|
|
370
|
+
}
|
|
371
|
+
listAgentOp(agentId, op, opts) {
|
|
372
|
+
const gate = tenantOwnGateSql('tenant_id', opts ?? {});
|
|
303
373
|
const rows = this.db.raw
|
|
304
|
-
.prepare(
|
|
305
|
-
|
|
374
|
+
.prepare(`SELECT source_id FROM knowledge_agent_visibility
|
|
375
|
+
WHERE ${gate.sql} AND gateway_id = ? AND local_agent_id = ? AND op = ?
|
|
376
|
+
ORDER BY source_id`)
|
|
377
|
+
.all(...gate.params, opts?.gatewayId ?? 'default', agentId, op);
|
|
306
378
|
return rows.map((r) => r.source_id);
|
|
307
379
|
}
|
|
308
380
|
/** 哪些 agent 对该 global 源做了隐藏 */
|
|
309
381
|
listAgentsHidingSource(sourceId, opts) {
|
|
382
|
+
return this.listAgentsOp(sourceId, 'exclude', opts);
|
|
383
|
+
}
|
|
384
|
+
/** 哪些 agent 挂载了该源 */
|
|
385
|
+
listAgentsMountingSource(sourceId, opts) {
|
|
386
|
+
return this.listAgentsOp(sourceId, 'include', opts);
|
|
387
|
+
}
|
|
388
|
+
listAgentsOp(sourceId, op, opts) {
|
|
389
|
+
const gate = tenantOwnGateSql('tenant_id', opts ?? {});
|
|
310
390
|
const rows = this.db.raw
|
|
311
|
-
.prepare(
|
|
312
|
-
|
|
391
|
+
.prepare(`SELECT local_agent_id FROM knowledge_agent_visibility
|
|
392
|
+
WHERE ${gate.sql} AND gateway_id = ? AND source_id = ? AND op = ?
|
|
393
|
+
ORDER BY local_agent_id`)
|
|
394
|
+
.all(...gate.params, opts?.gatewayId ?? 'default', sourceId, op);
|
|
313
395
|
return rows.map((r) => r.local_agent_id);
|
|
314
396
|
}
|
|
315
397
|
/**
|
|
@@ -338,15 +420,18 @@ export class KnowledgeSourceStore {
|
|
|
338
420
|
for (const item of items)
|
|
339
421
|
this.setSessionVisibility(sessionId, item, identity);
|
|
340
422
|
}
|
|
341
|
-
clearSessionVisibility(sessionId, target, identity) {
|
|
423
|
+
clearSessionVisibility(sessionId, target, identity, op) {
|
|
342
424
|
const tenant = identity?.tenantId ?? 'default';
|
|
343
425
|
const gateway = identity?.gatewayId ?? 'default';
|
|
344
426
|
if (target) {
|
|
427
|
+
// op 过滤(T3b unmount 对称):只撤指定向的 override,不误删用户反向显式设置
|
|
345
428
|
this.db.raw
|
|
346
429
|
.prepare(`DELETE FROM knowledge_session_visibility
|
|
347
430
|
WHERE tenant_id = ? AND gateway_id = ? AND local_session_id = ?
|
|
348
|
-
AND target_type = ? AND target_id =
|
|
349
|
-
.run(
|
|
431
|
+
AND target_type = ? AND target_id = ?${op ? ' AND op = ?' : ''}`)
|
|
432
|
+
.run(...(op
|
|
433
|
+
? [tenant, gateway, sessionId, target.targetType, target.targetId, op]
|
|
434
|
+
: [tenant, gateway, sessionId, target.targetType, target.targetId]));
|
|
350
435
|
return;
|
|
351
436
|
}
|
|
352
437
|
this.db.raw
|
|
@@ -355,12 +440,13 @@ export class KnowledgeSourceStore {
|
|
|
355
440
|
.run(tenant, gateway, sessionId);
|
|
356
441
|
}
|
|
357
442
|
listSessionVisibility(sessionId, identity) {
|
|
443
|
+
const gate = tenantOwnGateSql('tenant_id', identity ?? {});
|
|
358
444
|
const rows = this.db.raw
|
|
359
445
|
.prepare(`SELECT local_session_id AS session_id, target_type, target_id, op, created_at
|
|
360
446
|
FROM knowledge_session_visibility
|
|
361
|
-
WHERE
|
|
447
|
+
WHERE ${gate.sql} AND gateway_id = ? AND local_session_id = ?
|
|
362
448
|
ORDER BY created_at`)
|
|
363
|
-
.all(
|
|
449
|
+
.all(...gate.params, identity?.gatewayId ?? 'default', sessionId);
|
|
364
450
|
return rows.map((r) => ({
|
|
365
451
|
sessionId: r.session_id,
|
|
366
452
|
targetType: r.target_type,
|
|
@@ -371,38 +457,62 @@ export class KnowledgeSourceStore {
|
|
|
371
457
|
}
|
|
372
458
|
/** 项目登记视图(管理面:先建项目再挂源;**不**用孤儿源计数复活已删项目) */
|
|
373
459
|
listProjects(opts) {
|
|
374
|
-
|
|
460
|
+
// 读身份:无 opts / 字段缺省均按 DEFAULT 域(MAJ-2 fail-closed);平台域=全量视图
|
|
461
|
+
const identity = opts ?? {};
|
|
462
|
+
const projectGate = projectGateSql('tenant_id', 'visibility', identity);
|
|
463
|
+
const tenantGate = tenantGateSql('tenant_id', identity);
|
|
464
|
+
const mountGate = tenantOwnGateSql('tenant_id', identity);
|
|
375
465
|
const gateway = opts?.gatewayId ?? 'default';
|
|
466
|
+
const ownTenant = opts?.tenantId ?? 'default';
|
|
376
467
|
const registered = this.db.raw
|
|
377
|
-
.prepare(`SELECT project_key, display_name FROM knowledge_projects
|
|
378
|
-
WHERE
|
|
379
|
-
.all(
|
|
468
|
+
.prepare(`SELECT tenant_id, project_key, display_name FROM knowledge_projects
|
|
469
|
+
WHERE ${projectGate.sql} ORDER BY project_key`)
|
|
470
|
+
.all(...projectGate.params);
|
|
471
|
+
// 同 key 可跨域各登记一行(评审 M3):按域优先级择一输出(本域 > platform > 其它,
|
|
472
|
+
// 同级按域名字典序),禁止重复 key 进 UI、禁止跨域混计
|
|
473
|
+
const rank = (t) => (t === ownTenant ? 0 : t === PLATFORM_TENANT_ID ? 1 : 2);
|
|
474
|
+
const chosen = new Map();
|
|
475
|
+
for (const row of registered) {
|
|
476
|
+
const prev = chosen.get(row.project_key);
|
|
477
|
+
if (!prev ||
|
|
478
|
+
rank(row.tenant_id) < rank(prev.tenant_id) ||
|
|
479
|
+
(rank(row.tenant_id) === rank(prev.tenant_id) && row.tenant_id < prev.tenant_id)) {
|
|
480
|
+
chosen.set(row.project_key, row);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
380
483
|
const counts = this.db.raw
|
|
381
|
-
.prepare(`SELECT scope_key AS project_key, COUNT(*) AS source_count
|
|
484
|
+
.prepare(`SELECT tenant_id, scope_key AS project_key, COUNT(*) AS source_count
|
|
382
485
|
FROM knowledge_sources
|
|
383
|
-
WHERE scope_level = 'project' AND status != 'removed' AND
|
|
384
|
-
GROUP BY scope_key`)
|
|
385
|
-
.all(
|
|
386
|
-
const countMap = new Map(counts.map((c) => [c.project_key
|
|
387
|
-
// 一次拉齐 project→agents,禁止每项目一条 N+1
|
|
486
|
+
WHERE scope_level = 'project' AND status != 'removed' AND ${tenantGate.sql}
|
|
487
|
+
GROUP BY tenant_id, scope_key`)
|
|
488
|
+
.all(...tenantGate.params);
|
|
489
|
+
const countMap = new Map(counts.map((c) => [`${c.tenant_id}\u0000${c.project_key}`, c.source_count]));
|
|
490
|
+
// 一次拉齐 project→agents,禁止每项目一条 N+1;挂载行=写入物,按本域闸不跨域扩散
|
|
388
491
|
const agentRows = this.db.raw
|
|
389
|
-
.prepare(`SELECT project_key, local_agent_id FROM knowledge_project_agents
|
|
390
|
-
WHERE
|
|
492
|
+
.prepare(`SELECT tenant_id, project_key, local_agent_id FROM knowledge_project_agents
|
|
493
|
+
WHERE ${mountGate.sql} AND gateway_id = ?
|
|
391
494
|
ORDER BY project_key, local_agent_id`)
|
|
392
|
-
.all(
|
|
495
|
+
.all(...mountGate.params, gateway);
|
|
393
496
|
const agentsByProject = new Map();
|
|
394
497
|
for (const row of agentRows) {
|
|
498
|
+
// 挂载行 = 读方域的写入物(本域闸已过滤):回答「我的哪些 agent 可见」,按 key 聚合
|
|
395
499
|
const list = agentsByProject.get(row.project_key) ?? [];
|
|
396
500
|
list.push(row.local_agent_id);
|
|
397
501
|
agentsByProject.set(row.project_key, list);
|
|
398
502
|
}
|
|
399
503
|
// 只列已登记项目;孤儿源(项目已删)不再“复活”项目行
|
|
400
|
-
return
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
504
|
+
return [...chosen.values()]
|
|
505
|
+
.map((r) => {
|
|
506
|
+
const domainKey = `${r.tenant_id}\u0000${r.project_key}`;
|
|
507
|
+
return {
|
|
508
|
+
tenantId: r.tenant_id,
|
|
509
|
+
projectKey: r.project_key,
|
|
510
|
+
displayName: r.display_name ?? undefined,
|
|
511
|
+
sourceCount: countMap.get(domainKey) ?? 0,
|
|
512
|
+
assignedAgentIds: agentsByProject.get(r.project_key) ?? [],
|
|
513
|
+
};
|
|
514
|
+
})
|
|
515
|
+
.sort((a, b) => (a.projectKey < b.projectKey ? -1 : a.projectKey > b.projectKey ? 1 : 0));
|
|
406
516
|
}
|
|
407
517
|
/** 登记空项目(先建项目再挂源) */
|
|
408
518
|
createProject(projectKey, displayName, opts) {
|
|
@@ -414,11 +524,11 @@ export class KnowledgeSourceStore {
|
|
|
414
524
|
this.db.raw
|
|
415
525
|
.prepare(`INSERT INTO knowledge_projects
|
|
416
526
|
(tenant_id, project_key, display_name, registered_by, visibility, created_at, updated_at)
|
|
417
|
-
VALUES (?, ?, ?, ?,
|
|
527
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
418
528
|
ON CONFLICT(tenant_id, project_key) DO UPDATE SET
|
|
419
529
|
display_name = COALESCE(excluded.display_name, knowledge_projects.display_name),
|
|
420
530
|
updated_at = excluded.updated_at`)
|
|
421
|
-
.run(tenant, key, displayName ?? null, opts?.registeredBy ?? 'default', now, now);
|
|
531
|
+
.run(tenant, key, displayName ?? null, opts?.registeredBy ?? 'default', opts?.visibility ?? 'private', now, now);
|
|
422
532
|
}
|
|
423
533
|
/**
|
|
424
534
|
* 删除项目登记。非空项目拒绝(先卸载/删除项目下源),避免孤儿源与静默收养。
|
|
@@ -432,50 +542,67 @@ export class KnowledgeSourceStore {
|
|
|
432
542
|
if (sourceCount > 0) {
|
|
433
543
|
throw new Error(`project "${projectKey}" still has ${sourceCount} source(s); remove or reassign them first`);
|
|
434
544
|
}
|
|
545
|
+
// 同 key 可跨域各登记一行(评审 B1):删除只作用于调用方域内的行——跨域删除既是越权
|
|
546
|
+
// 破坏,又会把「无登记行=孤儿不设闸」变成跨域读旁路
|
|
435
547
|
const res = this.db.raw
|
|
436
|
-
.prepare('DELETE FROM knowledge_projects WHERE project_key = ?')
|
|
437
|
-
.run(projectKey);
|
|
548
|
+
.prepare('DELETE FROM knowledge_projects WHERE project_key = ? AND tenant_id = ?')
|
|
549
|
+
.run(projectKey, tenant);
|
|
438
550
|
this.db.raw
|
|
439
|
-
.prepare('DELETE FROM knowledge_project_agents WHERE project_key = ?')
|
|
440
|
-
.run(projectKey);
|
|
551
|
+
.prepare('DELETE FROM knowledge_project_agents WHERE project_key = ? AND tenant_id = ?')
|
|
552
|
+
.run(projectKey, tenant);
|
|
441
553
|
this.db.raw
|
|
442
|
-
.prepare("DELETE FROM knowledge_session_visibility WHERE target_type = 'project' AND target_id = ?")
|
|
443
|
-
.run(projectKey);
|
|
554
|
+
.prepare("DELETE FROM knowledge_session_visibility WHERE target_type = 'project' AND target_id = ? AND tenant_id = ?")
|
|
555
|
+
.run(projectKey, tenant);
|
|
444
556
|
return Number(res.changes ?? 0) > 0;
|
|
445
557
|
}
|
|
446
558
|
/**
|
|
447
|
-
* 源是否对 (agent, session)
|
|
559
|
+
* 源是否对 (agent, session) 可见(租户闸 ⊕ 网关漏斗 ⊕ base ⊕ session overlay)
|
|
448
560
|
*/
|
|
449
561
|
isVisible(source, agentId, sessionId, identity) {
|
|
450
562
|
if (source.status === 'removed' || source.status === 'disabled')
|
|
451
563
|
return false;
|
|
564
|
+
if (!this.isTenantVisible(source, identity))
|
|
565
|
+
return false;
|
|
452
566
|
if (!this.isGatewayVisible(source, identity))
|
|
453
567
|
return false;
|
|
568
|
+
// 项目跨域闸(收紧):project 域源还须其项目行对本身份可见(base 与 session overlay
|
|
569
|
+
// 两路 grant 都不得绕过;写侧另有 fail-loud 防线)
|
|
570
|
+
if (source.scopeRef.level === 'project' &&
|
|
571
|
+
!this.isProjectVisible(source, source.scopeRef.key, identity)) {
|
|
572
|
+
return false;
|
|
573
|
+
}
|
|
454
574
|
return this.applySessionOverlay(source, this.isBaseVisible(source, agentId, sessionId, identity), sessionId, identity);
|
|
455
575
|
}
|
|
456
|
-
/**
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
576
|
+
/**
|
|
577
|
+
* 租户闸(arch/multi-tenancy.md §4/§6):有归属租户即生效(不依赖 gatewayId)。
|
|
578
|
+
* platform 域(PLATFORM_TENANT_ID)= broker/运维面,全量可见;其余只见本域 ∪ platform;
|
|
579
|
+
* 无归属 = DEFAULT 域(fail-closed,评审 MAJ-2:不做全量放行——存量语义即 default 域)。
|
|
580
|
+
*/
|
|
581
|
+
isTenantVisible(source, identity) {
|
|
582
|
+
const row = this.sourceRow(source.id);
|
|
583
|
+
if (!row)
|
|
460
584
|
return true;
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
585
|
+
return tenantGateAllows(row.tenant_id, identity ?? {});
|
|
586
|
+
}
|
|
587
|
+
/** 网关漏斗:registered_by=己方 ∪ public(租户闸已由 isTenantVisible 独立收口) */
|
|
588
|
+
isGatewayVisible(source, identity) {
|
|
589
|
+
const row = this.sourceRow(source.id);
|
|
464
590
|
if (!row)
|
|
465
591
|
return true;
|
|
466
|
-
|
|
467
|
-
if (row.tenant_id && row.tenant_id !== tenant)
|
|
468
|
-
return false;
|
|
469
|
-
if (row.registered_by && row.registered_by !== gw && row.visibility !== 'public') {
|
|
470
|
-
return false;
|
|
471
|
-
}
|
|
472
|
-
return true;
|
|
592
|
+
return ownerFunnelAllows(row.registered_by, row.visibility, identity ?? {});
|
|
473
593
|
}
|
|
474
594
|
/** Agent 级 base 可见(不含会话 overlay;排查用) */
|
|
475
595
|
isBaseVisible(source, agentId, sessionId, identity) {
|
|
476
596
|
if (source.status === 'removed' || source.status === 'disabled')
|
|
477
597
|
return false;
|
|
478
598
|
const { level, key } = source.scopeRef;
|
|
599
|
+
// 项目跨域闸(收紧):project 域源的任何 grant(挂载库/项目分配/session overlay)
|
|
600
|
+
// 都不得绕过项目行可见性
|
|
601
|
+
if (level === 'project' && !this.isProjectVisible(source, key, identity))
|
|
602
|
+
return false;
|
|
603
|
+
// 挂载库(T3b,§6 并集):显式挂载覆盖基础可见性(租户闸仍在其上)
|
|
604
|
+
if (this.isMounted(agentId, source.id, identity))
|
|
605
|
+
return true;
|
|
479
606
|
if (level === 'global') {
|
|
480
607
|
return !this.isHidden(agentId, source.id, identity);
|
|
481
608
|
}
|
|
@@ -502,23 +629,39 @@ export class KnowledgeSourceStore {
|
|
|
502
629
|
return base;
|
|
503
630
|
}
|
|
504
631
|
sessionOp(sessionId, targetType, targetId, identity) {
|
|
632
|
+
const gate = tenantOwnGateSql('tenant_id', identity ?? {});
|
|
633
|
+
const order = tenantPrecedenceOrder('tenant_id', identity ?? {});
|
|
505
634
|
const row = this.db.raw
|
|
506
635
|
.prepare(`SELECT op FROM knowledge_session_visibility
|
|
507
|
-
WHERE
|
|
508
|
-
AND target_type = ? AND target_id =
|
|
509
|
-
|
|
636
|
+
WHERE ${gate.sql} AND gateway_id = ? AND local_session_id = ?
|
|
637
|
+
AND target_type = ? AND target_id = ?
|
|
638
|
+
ORDER BY ${order.sql} LIMIT 1`)
|
|
639
|
+
.get(...gate.params, identity?.gatewayId ?? 'default', sessionId, targetType, targetId, ...order.params);
|
|
510
640
|
return row?.op ?? null;
|
|
511
641
|
}
|
|
512
642
|
isHidden(agentId, sourceId, identity) {
|
|
643
|
+
return this.agentOp(agentId, sourceId, identity) === 'exclude';
|
|
644
|
+
}
|
|
645
|
+
/** 挂载(T3b):include 覆盖 = 挂载库(§6 命中=挂载库∪本租户公共∪platform 公共) */
|
|
646
|
+
isMounted(agentId, sourceId, identity) {
|
|
647
|
+
return this.agentOp(agentId, sourceId, identity) === 'include';
|
|
648
|
+
}
|
|
649
|
+
/** (agent, source) 的可见性 override(单 op:include=挂载 / exclude=隐藏;无行=基础语义) */
|
|
650
|
+
agentOp(agentId, sourceId, identity) {
|
|
651
|
+
const gate = tenantOwnGateSql('tenant_id', identity ?? {});
|
|
652
|
+
const order = tenantPrecedenceOrder('tenant_id', identity ?? {});
|
|
513
653
|
const row = this.db.raw
|
|
514
|
-
.prepare(
|
|
515
|
-
|
|
516
|
-
|
|
654
|
+
.prepare(`SELECT op FROM knowledge_agent_visibility
|
|
655
|
+
WHERE ${gate.sql} AND gateway_id = ? AND local_agent_id = ? AND source_id = ?
|
|
656
|
+
ORDER BY ${order.sql} LIMIT 1`)
|
|
657
|
+
.get(...gate.params, identity?.gatewayId ?? 'default', agentId, sourceId, ...order.params);
|
|
658
|
+
return row?.op ?? null;
|
|
517
659
|
}
|
|
518
660
|
isProjectAssigned(projectKey, agentId, identity) {
|
|
661
|
+
const gate = tenantOwnGateSql('tenant_id', identity ?? {});
|
|
519
662
|
const row = this.db.raw
|
|
520
|
-
.prepare(
|
|
521
|
-
.get(
|
|
663
|
+
.prepare(`SELECT 1 AS ok FROM knowledge_project_agents WHERE ${gate.sql} AND gateway_id = ? AND project_key = ? AND local_agent_id = ?`)
|
|
664
|
+
.get(...gate.params, identity?.gatewayId ?? 'default', projectKey, agentId);
|
|
522
665
|
return Boolean(row);
|
|
523
666
|
}
|
|
524
667
|
// ── Catalog ──
|
|
@@ -606,7 +749,111 @@ export class KnowledgeSourceStore {
|
|
|
606
749
|
* 可见源列表(effective = base ⊕ session overlay;含 hiddenFromCatalog)
|
|
607
750
|
*/
|
|
608
751
|
listVisible(agentId, sessionId, identity) {
|
|
609
|
-
|
|
752
|
+
// 2N 优化(T3b):一次批量装载 source 行进同步缓存(filter 全程无 await,无并发窗口),
|
|
753
|
+
// isTenantVisible/isGatewayVisible 走缓存,不再每源一查
|
|
754
|
+
const rows = this.db.raw
|
|
755
|
+
.prepare('SELECT id, tenant_id, registered_by, visibility FROM knowledge_sources')
|
|
756
|
+
.all();
|
|
757
|
+
this.rowCache = new Map(rows.map((r) => [r.id, r]));
|
|
758
|
+
try {
|
|
759
|
+
return this.withProjectRowCache(() => this.list().filter((s) => this.isVisible(s, agentId, sessionId, identity)));
|
|
760
|
+
}
|
|
761
|
+
finally {
|
|
762
|
+
this.rowCache = null;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* 批量判定期的项目行缓存(评审 m6):一次装载全部项目行,批次内逐源判定走缓存;
|
|
767
|
+
* 可嵌套(外层已开则复用),finally 必须还原(防缓存外泄到批次外的读路径)。
|
|
768
|
+
*/
|
|
769
|
+
withProjectRowCache(fn) {
|
|
770
|
+
if (this.projectRowCache)
|
|
771
|
+
return fn();
|
|
772
|
+
const rows = this.db.raw
|
|
773
|
+
.prepare('SELECT tenant_id, project_key, display_name, visibility FROM knowledge_projects')
|
|
774
|
+
.all();
|
|
775
|
+
const map = new Map();
|
|
776
|
+
for (const r of rows) {
|
|
777
|
+
const list = map.get(r.project_key) ?? [];
|
|
778
|
+
list.push({ tenant_id: r.tenant_id, display_name: r.display_name, visibility: r.visibility });
|
|
779
|
+
map.set(r.project_key, list);
|
|
780
|
+
}
|
|
781
|
+
this.projectRowCache = map;
|
|
782
|
+
try {
|
|
783
|
+
return fn();
|
|
784
|
+
}
|
|
785
|
+
finally {
|
|
786
|
+
this.projectRowCache = null;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
/** source 行读取(listVisible 批处理期走同步缓存) */
|
|
790
|
+
sourceRow(id) {
|
|
791
|
+
if (this.rowCache)
|
|
792
|
+
return this.rowCache.get(id);
|
|
793
|
+
return this.db.raw
|
|
794
|
+
.prepare('SELECT tenant_id, registered_by, visibility FROM knowledge_sources WHERE id = ?')
|
|
795
|
+
.get(id);
|
|
796
|
+
}
|
|
797
|
+
/** 项目行按 key 批量缓存读取(缓存期一次装载;否则按 key 单查——idx_knowledge_projects_key) */
|
|
798
|
+
projectRowsByKey(projectKey) {
|
|
799
|
+
if (this.projectRowCache)
|
|
800
|
+
return this.projectRowCache.get(projectKey) ?? [];
|
|
801
|
+
return this.db.raw
|
|
802
|
+
.prepare('SELECT tenant_id, display_name, visibility FROM knowledge_projects WHERE project_key = ?')
|
|
803
|
+
.all(projectKey);
|
|
804
|
+
}
|
|
805
|
+
/** 项目行按源归属域解析(同一 project_key 可在多个租户域各登记一行,必须按域取行) */
|
|
806
|
+
projectRow(projectKey, sourceTenant) {
|
|
807
|
+
const norm = (t) => (t ? t : null);
|
|
808
|
+
return this.projectRowsByKey(projectKey).find((r) => norm(r.tenant_id) === norm(sourceTenant ?? null));
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* 项目跨域闸(arch/multi-tenancy.md §6):本域项目可见;platform 项目仅
|
|
812
|
+
* `visibility='public'` 才对租户可见(跨租户共享唯一合法形态 = platform 公共);
|
|
813
|
+
* 项目行按**源自身归属域**解析;无登记行(孤儿挂载)= 无归属,不设闸。
|
|
814
|
+
*/
|
|
815
|
+
isProjectVisible(source, projectKey, identity) {
|
|
816
|
+
const row = this.projectRow(projectKey, this.sourceRow(source.id)?.tenant_id);
|
|
817
|
+
if (!row)
|
|
818
|
+
return true;
|
|
819
|
+
return projectGateAllows(row.tenant_id, row.visibility, identity ?? {});
|
|
820
|
+
}
|
|
821
|
+
/**
|
|
822
|
+
* 项目跨域闸(写侧防绕过用):key 必须存在**对写者可见**的登记行(任一域命中即放行);
|
|
823
|
+
* 完全无登记行 = 孤儿挂载,不设闸(既有语义)。
|
|
824
|
+
*/
|
|
825
|
+
isProjectVisibleTo(projectKey, identity) {
|
|
826
|
+
const count = this.db.raw
|
|
827
|
+
.prepare('SELECT COUNT(*) AS n FROM knowledge_projects WHERE project_key = ?')
|
|
828
|
+
.get(projectKey).n;
|
|
829
|
+
// 完全无登记行 = 孤儿挂载,不设闸(既有语义)
|
|
830
|
+
if (count === 0)
|
|
831
|
+
return true;
|
|
832
|
+
return this.resolveProjectRow(projectKey, identity) !== undefined;
|
|
833
|
+
}
|
|
834
|
+
/**
|
|
835
|
+
* 项目行解析(管理面域继承用):返回对 identity 可见的项目行(同 key 跨域多行时
|
|
836
|
+
* 本域优先,其次 platform,再按域名字典序);无可见行 = null。
|
|
837
|
+
*/
|
|
838
|
+
getProject(projectKey, identity) {
|
|
839
|
+
const row = this.resolveProjectRow(projectKey, identity);
|
|
840
|
+
if (!row)
|
|
841
|
+
return null;
|
|
842
|
+
return {
|
|
843
|
+
tenantId: row.tenant_id ?? 'default',
|
|
844
|
+
projectKey,
|
|
845
|
+
displayName: row.display_name ?? undefined,
|
|
846
|
+
visibility: row.visibility === 'public' ? 'public' : 'private',
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
resolveProjectRow(projectKey, identity) {
|
|
850
|
+
const rows = this.projectRowsByKey(projectKey);
|
|
851
|
+
const visible = rows.filter((r) => projectGateAllows(r.tenant_id, r.visibility, identity ?? {}));
|
|
852
|
+
if (visible.length === 0)
|
|
853
|
+
return undefined;
|
|
854
|
+
const own = identity?.tenantId ?? 'default';
|
|
855
|
+
const rank = (t) => t === own ? 0 : t === PLATFORM_TENANT_ID ? 1 : 2;
|
|
856
|
+
return [...visible].sort((a, b) => rank(a.tenant_id) - rank(b.tenant_id) || String(a.tenant_id).localeCompare(String(b.tenant_id)))[0];
|
|
610
857
|
}
|
|
611
858
|
/** Agent 级 base 可见源(不含会话 overlay) */
|
|
612
859
|
listBaseVisible(agentId, sessionId, identity) {
|
|
@@ -617,9 +864,10 @@ export class KnowledgeSourceStore {
|
|
|
617
864
|
.prepare(`INSERT INTO knowledge_sources (
|
|
618
865
|
id, kind, location, scope_level, scope_key, sync_json, status, coverage,
|
|
619
866
|
errors_json, display_name, description, generated_description,
|
|
867
|
+
generated_description_source,
|
|
620
868
|
catalog_priority, hidden_from_catalog, auth_ref, network_json, discover_json,
|
|
621
869
|
last_polled_at, created_at, updated_at
|
|
622
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
870
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
623
871
|
ON CONFLICT(id) DO UPDATE SET
|
|
624
872
|
kind=excluded.kind,
|
|
625
873
|
location=excluded.location,
|
|
@@ -632,6 +880,7 @@ export class KnowledgeSourceStore {
|
|
|
632
880
|
display_name=excluded.display_name,
|
|
633
881
|
description=excluded.description,
|
|
634
882
|
generated_description=excluded.generated_description,
|
|
883
|
+
generated_description_source=excluded.generated_description_source,
|
|
635
884
|
catalog_priority=excluded.catalog_priority,
|
|
636
885
|
hidden_from_catalog=excluded.hidden_from_catalog,
|
|
637
886
|
auth_ref=excluded.auth_ref,
|
|
@@ -639,6 +888,6 @@ export class KnowledgeSourceStore {
|
|
|
639
888
|
discover_json=excluded.discover_json,
|
|
640
889
|
last_polled_at=excluded.last_polled_at,
|
|
641
890
|
updated_at=excluded.updated_at`)
|
|
642
|
-
.run(source.id, source.kind, source.location, source.scopeRef.level, source.scopeRef.key, JSON.stringify(source.sync), source.status, source.coverage ?? null, JSON.stringify(source.errors ?? []), source.displayName, source.description ?? null, source.generatedDescription ?? null, source.catalogPriority ?? null, source.hiddenFromCatalog ? 1 : 0, source.authRef ?? null, source.network ? JSON.stringify(source.network) : null, source.discover ? JSON.stringify(source.discover) : null, source.lastPolledAt ?? null, source.createdAt, source.updatedAt);
|
|
891
|
+
.run(source.id, source.kind, source.location, source.scopeRef.level, source.scopeRef.key, JSON.stringify(source.sync), source.status, source.coverage ?? null, JSON.stringify(source.errors ?? []), source.displayName, source.description ?? null, source.generatedDescription ?? null, source.generatedDescriptionSource ?? null, source.catalogPriority ?? null, source.hiddenFromCatalog ? 1 : 0, source.authRef ?? null, source.network ? JSON.stringify(source.network) : null, source.discover ? JSON.stringify(source.discover) : null, source.lastPolledAt ?? null, source.createdAt, source.updatedAt);
|
|
643
892
|
}
|
|
644
893
|
}
|