@octopi-agent/engine 0.102.10 → 0.121.15
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/console-access-key.d.ts +46 -0
- package/dist/config-admin/console-access-key.js +47 -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 +8 -2
- package/dist/config-admin/index.js +4 -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 +83 -0
- package/dist/config-admin/onboarding-apply.js +259 -0
- package/dist/config-admin/onboarding.d.ts +160 -0
- package/dist/config-admin/onboarding.js +298 -0
- package/dist/config-admin/password-policy.d.ts +24 -0
- package/dist/config-admin/password-policy.js +31 -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 +5 -1
- package/dist/config-schema/agent.js +20 -2
- package/dist/config-schema/browser.d.ts +62 -0
- package/dist/config-schema/browser.js +89 -0
- package/dist/config-schema/context.d.ts +7 -2
- package/dist/config-schema/context.js +6 -3
- package/dist/config-schema/engine.d.ts +86 -7
- package/dist/config-schema/engine.js +9 -2
- package/dist/config-schema/governance.d.ts +12 -1
- package/dist/config-schema/governance.js +10 -2
- package/dist/config-schema/models.d.ts +12 -8
- package/dist/config-schema/models.js +16 -1
- package/dist/config-schema/run.d.ts +4 -0
- package/dist/config-schema/run.js +10 -0
- package/dist/config-schema/shared.d.ts +1 -0
- package/dist/config-schema/shared.js +4 -2
- package/dist/config-schema/substrate.d.ts +5 -0
- package/dist/config-schema/substrate.js +8 -0
- package/dist/config.d.ts +116 -10
- package/dist/config.js +109 -13
- 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 +4 -0
- 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 +119 -28
- package/dist/harness/activation/types.d.ts +19 -2
- package/dist/harness/agent/builder.d.ts +12 -0
- package/dist/harness/agent/builder.js +78 -22
- package/dist/harness/agent/config-bridge.d.ts +10 -1
- package/dist/harness/agent/config-bridge.js +15 -3
- 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 +2 -0
- package/dist/harness/agent/wire-agent-builder.js +9 -2
- package/dist/harness/capabilities/document/backends/plain.js +2 -1
- package/dist/harness/capabilities/document/legacy/factory.js +3 -2
- 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 +1 -0
- 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 +13 -3
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +48 -39
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +3 -0
- package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +4 -0
- package/dist/harness/collaboration/delegation/child-run.d.ts +9 -0
- package/dist/harness/collaboration/delegation/child-run.js +34 -2
- package/dist/harness/collaboration/delegation/registry-types.d.ts +2 -0
- package/dist/harness/collaboration/delegation/service.d.ts +9 -4
- package/dist/harness/collaboration/delegation/service.js +33 -12
- package/dist/harness/collaboration/delegation/store.d.ts +2 -0
- package/dist/harness/collaboration/delegation/store.js +1 -0
- package/dist/harness/collaboration/delegation/types.d.ts +11 -0
- package/dist/harness/collaboration/delegation/wiring.d.ts +2 -0
- package/dist/harness/collaboration/delegation/wiring.js +1 -0
- package/dist/harness/context/capabilities/compact/engine.d.ts +44 -5
- package/dist/harness/context/capabilities/compact/engine.js +127 -39
- package/dist/harness/context/capabilities/compact/index.d.ts +2 -1
- package/dist/harness/context/capabilities/compact/index.js +1 -1
- package/dist/harness/context/capabilities/compact/types.d.ts +59 -9
- 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/registry.js +20 -0
- 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 +16 -0
- package/dist/harness/context/constitution/default-agents.md +85 -0
- package/dist/harness/context/context-size-ledger.js +8 -1
- package/dist/harness/context/default-context-engine.d.ts +100 -6
- package/dist/harness/context/default-context-engine.js +382 -89
- package/dist/harness/context/index.d.ts +2 -1
- package/dist/harness/context/index.js +1 -0
- 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 +57 -0
- package/dist/harness/context/layer-types.js +73 -1
- package/dist/harness/context/layers.d.ts +3 -0
- package/dist/harness/context/layers.js +13 -6
- package/dist/harness/context/prefix-fingerprint.d.ts +46 -0
- package/dist/harness/context/prefix-fingerprint.js +52 -0
- package/dist/harness/context/summarize.js +18 -0
- package/dist/harness/context/system-prompt-assembler.d.ts +2 -0
- package/dist/harness/context/system-prompt-assembler.js +5 -2
- package/dist/harness/context/tool-result-aging.d.ts +104 -16
- package/dist/harness/context/tool-result-aging.js +211 -57
- package/dist/harness/context/types.d.ts +71 -4
- 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/privileged-exec.js +4 -1
- package/dist/harness/extension/execution-environment/workspace.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +27 -1
- 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/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 +168 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/api.js +156 -15
- 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 +40 -5
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.js +45 -26
- package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +11 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +42 -76
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +30 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +46 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +9 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +19 -14
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.d.ts +3 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.js +1 -1
- 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 +18 -0
- 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/tool-bus.js +10 -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/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/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/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 +5 -3
- package/dist/harness/index.js +2 -2
- package/dist/harness/knowledge/boot-config.d.ts +2 -0
- package/dist/harness/knowledge/boot-config.js +2 -0
- package/dist/harness/knowledge/client.d.ts +53 -7
- package/dist/harness/knowledge/client.js +77 -20
- package/dist/harness/knowledge/db.d.ts +16 -0
- package/dist/harness/knowledge/db.js +107 -41
- package/dist/harness/knowledge/engine-thread.js +5 -7
- package/dist/harness/knowledge/grounding.js +4 -1
- package/dist/harness/knowledge/http-app.d.ts +15 -0
- package/dist/harness/knowledge/http-app.js +82 -21
- package/dist/harness/knowledge/http-bridge.d.ts +15 -0
- package/dist/harness/knowledge/http-bridge.js +19 -0
- package/dist/harness/knowledge/knowledge-serve-child.js +2 -3
- package/dist/harness/knowledge/query-service.d.ts +12 -2
- package/dist/harness/knowledge/query-service.js +75 -41
- package/dist/harness/knowledge/query-worker-client.d.ts +5 -1
- package/dist/harness/knowledge/query-worker-client.js +4 -1
- package/dist/harness/knowledge/query-worker.js +5 -3
- package/dist/harness/knowledge/read-http.d.ts +2 -0
- package/dist/harness/knowledge/read-http.js +9 -2
- package/dist/harness/knowledge/retriever.d.ts +1 -1
- package/dist/harness/knowledge/retriever.js +1 -2
- package/dist/harness/knowledge/serve.d.ts +6 -1
- package/dist/harness/knowledge/serve.js +5 -6
- package/dist/harness/knowledge/source-store.d.ts +101 -5
- package/dist/harness/knowledge/source-store.js +297 -71
- package/dist/harness/knowledge/start-service-process.d.ts +27 -8
- package/dist/harness/knowledge/start-service-process.js +49 -90
- package/dist/harness/knowledge/tenant-gate.d.ts +81 -0
- package/dist/harness/knowledge/tenant-gate.js +167 -0
- package/dist/harness/knowledge/writer-service.d.ts +18 -2
- package/dist/harness/knowledge/writer-service.js +80 -16
- package/dist/harness/knowledge/writer-worker-client.d.ts +9 -2
- package/dist/harness/knowledge/writer-worker-client.js +20 -3
- package/dist/harness/knowledge/writer-worker.js +11 -4
- 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/types.d.ts +18 -2
- package/dist/harness/observability/observer/hub.d.ts +10 -0
- package/dist/harness/observability/observer/hub.js +95 -2
- package/dist/harness/run/agent/agent.js +3 -2
- package/dist/harness/run/concurrency/tool-validator.js +4 -3
- package/dist/harness/run/reliability/run-agent.d.ts +22 -0
- package/dist/harness/run/reliability/run-agent.js +79 -10
- 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 +11 -0
- package/dist/harness/run/run-scope.js +19 -1
- package/dist/harness/run/runner.d.ts +149 -22
- package/dist/harness/run/runner.js +352 -35
- 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/types.d.ts +10 -14
- package/dist/harness/shared/events/agent-event-map.d.ts +29 -0
- package/dist/harness/shared/types/agent-definition.d.ts +6 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- 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/providers/anthropic-message-normalize.d.ts +20 -0
- package/dist/integration/providers/anthropic-message-normalize.js +48 -0
- package/dist/integration/providers/anthropic.js +27 -2
- 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 +41 -1
- package/dist/integration/providers/wire-dump-diff.js +2 -1
- package/dist/integration/providers/wire-dump.d.ts +56 -2
- package/dist/integration/providers/wire-dump.js +119 -6
- package/dist/integration/storage/archive-manager.d.ts +14 -2
- package/dist/integration/storage/archive-manager.js +24 -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 +9 -0
- package/dist/integration/storage/jsonl.js +137 -38
- 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/config.yaml +3 -0
- package/dist/subsystems/wisdom-steward/govern/config.yaml +6 -1
- package/package.json +5 -3
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* 读走 KnowledgeQueryService。**禁止**在此打开 knowledge.db。
|
|
6
6
|
* 纯读 GET 在主线程 `read-http.ts` 直达 Meta/Search,不经本层。
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
8
|
+
import { DEFAULT_TENANT_ID, PLATFORM_TENANT_ID } from '@octopi-agent/core/types.js';
|
|
9
|
+
import { matchKnowledgeToken, resolveTenantClaim } from './http-bridge.js';
|
|
9
10
|
import { promotionThresholdsFromParams } from './http-params.js';
|
|
10
11
|
function json(res, status, payload) {
|
|
11
12
|
const buf = Buffer.from(JSON.stringify(payload), 'utf8');
|
|
@@ -29,6 +30,21 @@ function mapWriteError(res, e) {
|
|
|
29
30
|
err(res, 403, 'not_principal_owner', msg);
|
|
30
31
|
return true;
|
|
31
32
|
}
|
|
33
|
+
if (code === 'project_not_visible' ||
|
|
34
|
+
code === 'source_not_visible' ||
|
|
35
|
+
/not visible to writer/i.test(msg)) {
|
|
36
|
+
err(res, 403, code || 'not_visible', msg);
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
if (code === 'visibility_requires_platform_claim' ||
|
|
40
|
+
/requires an explicit platform claim/i.test(msg)) {
|
|
41
|
+
err(res, 403, 'visibility_requires_platform_claim', msg);
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
if (code === 'public_projects_disabled') {
|
|
45
|
+
err(res, 403, 'public_projects_disabled', msg);
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
32
48
|
if (code === 'principal_not_registered' || /principal not registered/i.test(msg)) {
|
|
33
49
|
err(res, 403, 'principal_not_registered', msg);
|
|
34
50
|
return true;
|
|
@@ -73,8 +89,25 @@ export class KnowledgeHttpApp {
|
|
|
73
89
|
query() {
|
|
74
90
|
return this.opts.query;
|
|
75
91
|
}
|
|
92
|
+
/** 写身份:归属域(platform token 无 claim → DEFAULT,不写 platform 共享面) */
|
|
76
93
|
identityOf(ctx) {
|
|
77
|
-
return {
|
|
94
|
+
return {
|
|
95
|
+
tenantId: ctx.writeTenantId ?? ctx.tenantId,
|
|
96
|
+
gatewayId: ctx.gatewayId,
|
|
97
|
+
claimed: ctx.claimed,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* 读身份:claim-or-token 域(v0.113.10 语义「读口不受影响」)——platform broker 无 claim
|
|
102
|
+
* = 运维面全量;claim 在场 = 租户收口。写域不得代劳读域(T3b 自审修复:曾共用 identityOf,
|
|
103
|
+
* 把运维读误收窄到 DEFAULT)。
|
|
104
|
+
*/
|
|
105
|
+
readIdentityOf(ctx) {
|
|
106
|
+
return {
|
|
107
|
+
tenantId: ctx.tenantId,
|
|
108
|
+
gatewayId: ctx.gatewayId,
|
|
109
|
+
claimed: ctx.claimed,
|
|
110
|
+
};
|
|
78
111
|
}
|
|
79
112
|
route(method, pattern, handler) {
|
|
80
113
|
const keys = [];
|
|
@@ -110,7 +143,7 @@ export class KnowledgeHttpApp {
|
|
|
110
143
|
});
|
|
111
144
|
});
|
|
112
145
|
this.route('GET', '/v1/principals/:agentId', async (_req, res, ctx, params) => {
|
|
113
|
-
const row = await this.query().getPrincipal(this.
|
|
146
|
+
const row = await this.query().getPrincipal(this.readIdentityOf(ctx), params.agentId);
|
|
114
147
|
if (!row)
|
|
115
148
|
return err(res, 404, 'principal_not_registered', 'principal not found');
|
|
116
149
|
json(res, 200, { ok: true, data: row });
|
|
@@ -118,7 +151,7 @@ export class KnowledgeHttpApp {
|
|
|
118
151
|
this.route('GET', '/v1/projects', async (_req, res, ctx) => {
|
|
119
152
|
json(res, 200, {
|
|
120
153
|
ok: true,
|
|
121
|
-
data: await this.query().listProjects(this.
|
|
154
|
+
data: await this.query().listProjects(this.readIdentityOf(ctx)),
|
|
122
155
|
});
|
|
123
156
|
});
|
|
124
157
|
this.route('POST', '/v1/projects', async (_req, res, ctx, _p, body) => {
|
|
@@ -139,6 +172,12 @@ export class KnowledgeHttpApp {
|
|
|
139
172
|
}
|
|
140
173
|
}
|
|
141
174
|
});
|
|
175
|
+
this.route('GET', '/v1/projects/:projectKey', async (_req, res, ctx, params) => {
|
|
176
|
+
const row = await this.query().getProject(this.readIdentityOf(ctx), params.projectKey);
|
|
177
|
+
if (!row)
|
|
178
|
+
return err(res, 404, 'project_not_found', 'project not found');
|
|
179
|
+
json(res, 200, { ok: true, data: row });
|
|
180
|
+
});
|
|
142
181
|
this.route('DELETE', '/v1/projects/:projectKey', async (_req, res, ctx, params) => {
|
|
143
182
|
try {
|
|
144
183
|
const data = await this.write.removeProject(this.identityOf(ctx), params.projectKey);
|
|
@@ -199,7 +238,7 @@ export class KnowledgeHttpApp {
|
|
|
199
238
|
: {}),
|
|
200
239
|
...(projectKey != null && projectKey !== '' ? { projectKey } : {}),
|
|
201
240
|
...(sessionId != null && sessionId !== '' ? { sessionId } : {}),
|
|
202
|
-
identity: this.
|
|
241
|
+
identity: this.readIdentityOf(ctx),
|
|
203
242
|
});
|
|
204
243
|
json(res, 200, { ok: true, data: list });
|
|
205
244
|
});
|
|
@@ -218,7 +257,7 @@ export class KnowledgeHttpApp {
|
|
|
218
257
|
}
|
|
219
258
|
});
|
|
220
259
|
this.route('GET', '/v1/sources/:sid', async (_req, res, ctx, params) => {
|
|
221
|
-
const detail = await this.query().getSourceDetail(params.sid, this.
|
|
260
|
+
const detail = await this.query().getSourceDetail(params.sid, this.readIdentityOf(ctx));
|
|
222
261
|
if (!detail) {
|
|
223
262
|
return err(res, 404, 'source_not_found', 'source not found');
|
|
224
263
|
}
|
|
@@ -374,12 +413,12 @@ export class KnowledgeHttpApp {
|
|
|
374
413
|
...(url.searchParams.get('pageSize')
|
|
375
414
|
? { pageSize: Number(url.searchParams.get('pageSize')) }
|
|
376
415
|
: {}),
|
|
377
|
-
}, this.
|
|
416
|
+
}, this.readIdentityOf(ctx));
|
|
378
417
|
return json(res, 200, { ok: true, data });
|
|
379
418
|
}
|
|
380
419
|
json(res, 200, {
|
|
381
420
|
ok: true,
|
|
382
|
-
data: await this.query().listFiles(params.sid, this.
|
|
421
|
+
data: await this.query().listFiles(params.sid, this.readIdentityOf(ctx)),
|
|
383
422
|
});
|
|
384
423
|
});
|
|
385
424
|
this.route('GET', '/v1/principals/:agentId/search', async (req, res, ctx, params) => {
|
|
@@ -390,7 +429,7 @@ export class KnowledgeHttpApp {
|
|
|
390
429
|
q: url.searchParams.get('q') ?? '',
|
|
391
430
|
sessionId: url.searchParams.get('sessionId') ?? undefined,
|
|
392
431
|
limit: Number(url.searchParams.get('limit') ?? 8),
|
|
393
|
-
identity: this.
|
|
432
|
+
identity: this.readIdentityOf(ctx),
|
|
394
433
|
});
|
|
395
434
|
json(res, 200, { ok: true, data: result });
|
|
396
435
|
});
|
|
@@ -407,13 +446,13 @@ export class KnowledgeHttpApp {
|
|
|
407
446
|
sessionId: url.searchParams.get('sessionId') ?? undefined,
|
|
408
447
|
limit: Number(url.searchParams.get('limit') ?? 8),
|
|
409
448
|
...(recall ? { recall } : {}),
|
|
410
|
-
identity: this.
|
|
449
|
+
identity: this.readIdentityOf(ctx),
|
|
411
450
|
});
|
|
412
451
|
json(res, 200, { ok: true, data: result });
|
|
413
452
|
});
|
|
414
453
|
this.route('GET', '/v1/principals/:agentId/stats', async (_req, res, ctx, params) => {
|
|
415
454
|
await this.write.ensurePrincipal(this.identityOf(ctx), params.agentId, this.opts.autoRegisterPrincipals ?? true);
|
|
416
|
-
const principal = await this.query().principalStats(params.agentId, this.
|
|
455
|
+
const principal = await this.query().principalStats(params.agentId, this.readIdentityOf(ctx));
|
|
417
456
|
json(res, 200, {
|
|
418
457
|
ok: true,
|
|
419
458
|
data: {
|
|
@@ -427,7 +466,7 @@ export class KnowledgeHttpApp {
|
|
|
427
466
|
await this.write.ensurePrincipal(this.identityOf(ctx), params.agentId, this.opts.autoRegisterPrincipals ?? true);
|
|
428
467
|
json(res, 200, {
|
|
429
468
|
ok: true,
|
|
430
|
-
data: await this.query().catalog(params.agentId, this.
|
|
469
|
+
data: await this.query().catalog(params.agentId, this.readIdentityOf(ctx)),
|
|
431
470
|
});
|
|
432
471
|
});
|
|
433
472
|
this.route('GET', '/v1/principals/:agentId/chunks', async (req, res, ctx, params) => {
|
|
@@ -438,7 +477,7 @@ export class KnowledgeHttpApp {
|
|
|
438
477
|
if (!sourceId || !path) {
|
|
439
478
|
return err(res, 400, 'bad_request', 'sourceId and path required');
|
|
440
479
|
}
|
|
441
|
-
const data = await this.query().listChunks(params.agentId, sourceId, path, this.
|
|
480
|
+
const data = await this.query().listChunks(params.agentId, sourceId, path, this.readIdentityOf(ctx), ctx.sessionId);
|
|
442
481
|
if (data == null) {
|
|
443
482
|
return err(res, 404, 'file_not_found', 'source not found');
|
|
444
483
|
}
|
|
@@ -451,13 +490,13 @@ export class KnowledgeHttpApp {
|
|
|
451
490
|
return err(res, 400, 'bad_request', 'chunkId or (sourceId+path) required');
|
|
452
491
|
}
|
|
453
492
|
if (b.chunkId) {
|
|
454
|
-
const data = await this.query().read(params.agentId, b, this.
|
|
493
|
+
const data = await this.query().read(params.agentId, b, this.readIdentityOf(ctx), ctx.sessionId);
|
|
455
494
|
if (!data.found) {
|
|
456
495
|
return err(res, 404, 'file_not_found', 'chunk not found');
|
|
457
496
|
}
|
|
458
497
|
return json(res, 200, { ok: true, data });
|
|
459
498
|
}
|
|
460
|
-
const chunks = await this.query().listChunks(params.agentId, b.sourceId, b.path, this.
|
|
499
|
+
const chunks = await this.query().listChunks(params.agentId, b.sourceId, b.path, this.readIdentityOf(ctx), ctx.sessionId);
|
|
461
500
|
if (chunks == null) {
|
|
462
501
|
return err(res, 404, 'source_not_found', 'source not found');
|
|
463
502
|
}
|
|
@@ -476,7 +515,7 @@ export class KnowledgeHttpApp {
|
|
|
476
515
|
await this.write.ensurePrincipal(this.identityOf(ctx), params.agentId, this.opts.autoRegisterPrincipals ?? true);
|
|
477
516
|
json(res, 200, {
|
|
478
517
|
ok: true,
|
|
479
|
-
data: await this.query().visibility(params.agentId, this.
|
|
518
|
+
data: await this.query().visibility(params.agentId, this.readIdentityOf(ctx)),
|
|
480
519
|
});
|
|
481
520
|
});
|
|
482
521
|
this.route('POST', '/v1/principals/:agentId/visibility', async (_req, res, ctx, params, body) => {
|
|
@@ -500,6 +539,12 @@ export class KnowledgeHttpApp {
|
|
|
500
539
|
else if (op === 'unhide' && sourceId) {
|
|
501
540
|
await this.write.unhideSource(identity, agentId, sourceId);
|
|
502
541
|
}
|
|
542
|
+
else if (op === 'mount' && sourceId) {
|
|
543
|
+
await this.write.mountSource(identity, agentId, sourceId);
|
|
544
|
+
}
|
|
545
|
+
else if (op === 'unmount' && sourceId) {
|
|
546
|
+
await this.write.unmountSource(identity, agentId, sourceId);
|
|
547
|
+
}
|
|
503
548
|
else {
|
|
504
549
|
return err(res, 400, 'bad_request', 'unknown visibility op');
|
|
505
550
|
}
|
|
@@ -521,7 +566,7 @@ export class KnowledgeHttpApp {
|
|
|
521
566
|
return err(res, 400, 'session_required', 'sessionId required');
|
|
522
567
|
json(res, 200, {
|
|
523
568
|
ok: true,
|
|
524
|
-
data: await this.query().sessionVisibility(agentId, sessionId, this.
|
|
569
|
+
data: await this.query().sessionVisibility(agentId, sessionId, this.readIdentityOf(ctx)),
|
|
525
570
|
});
|
|
526
571
|
});
|
|
527
572
|
this.route('PUT', '/v1/principals/:agentId/session-visibility', async (_req, res, ctx, params, body) => {
|
|
@@ -567,11 +612,12 @@ export class KnowledgeHttpApp {
|
|
|
567
612
|
return err(res, 400, 'session_required', 'sessionId required');
|
|
568
613
|
const targetType = url.searchParams.get('targetType');
|
|
569
614
|
const targetId = url.searchParams.get('targetId');
|
|
615
|
+
const op = url.searchParams.get('op');
|
|
570
616
|
if (targetType && targetId) {
|
|
571
617
|
await this.write.clearSessionVisibility(this.identityOf(ctx), sessionId, {
|
|
572
618
|
targetType: targetType,
|
|
573
619
|
targetId,
|
|
574
|
-
});
|
|
620
|
+
}, op === 'include' || op === 'exclude' ? op : undefined);
|
|
575
621
|
json(res, 200, { ok: true, data: { sessionId, targetType, targetId } });
|
|
576
622
|
return;
|
|
577
623
|
}
|
|
@@ -583,7 +629,7 @@ export class KnowledgeHttpApp {
|
|
|
583
629
|
json(res, 200, {
|
|
584
630
|
ok: true,
|
|
585
631
|
data: await this.query().listJobs({
|
|
586
|
-
identity: this.
|
|
632
|
+
identity: this.readIdentityOf(ctx),
|
|
587
633
|
sourceId: url.searchParams.get('sourceId') ?? undefined,
|
|
588
634
|
status: url.searchParams.get('status') ?? undefined,
|
|
589
635
|
}),
|
|
@@ -597,7 +643,7 @@ export class KnowledgeHttpApp {
|
|
|
597
643
|
if (!(await this.write.isSourceOwner(sourceId, ctx.gatewayId))) {
|
|
598
644
|
return err(res, 403, 'not_resource_owner', 'not source owner');
|
|
599
645
|
}
|
|
600
|
-
const detail = await this.query().getSourceDetail(sourceId, this.
|
|
646
|
+
const detail = await this.query().getSourceDetail(sourceId, this.readIdentityOf(ctx));
|
|
601
647
|
if (!detail)
|
|
602
648
|
return err(res, 404, 'source_not_found', 'source not found');
|
|
603
649
|
json(res, 200, { ok: true, data: detail.jobControl });
|
|
@@ -672,7 +718,22 @@ export class KnowledgeHttpApp {
|
|
|
672
718
|
const hit = matchKnowledgeToken(this.opts.tokens, req.headers.authorization);
|
|
673
719
|
if (!hit)
|
|
674
720
|
return null;
|
|
675
|
-
|
|
721
|
+
// 租户断言(T3):x-octopi-tenant 上行;重复头/越域断言按未认证拒(fail-loud,不回落)
|
|
722
|
+
const claim = req.headers['x-octopi-tenant'];
|
|
723
|
+
if (Array.isArray(claim))
|
|
724
|
+
return null;
|
|
725
|
+
const resolved = resolveTenantClaim(hit.tenantId, claim ? claim : undefined);
|
|
726
|
+
if ('error' in resolved)
|
|
727
|
+
return null;
|
|
728
|
+
// 写归属域(T3a 收尾护栏):platform 域(broker)无显式 claim 时,写一律降级 DEFAULT 域。
|
|
729
|
+
// 读口不受影响(platform = 全量视图);写绝不能把用户资产落进 platform 共享面。
|
|
730
|
+
const writeTenantId = resolved.tenantId === PLATFORM_TENANT_ID && !claim ? DEFAULT_TENANT_ID : resolved.tenantId;
|
|
731
|
+
return {
|
|
732
|
+
tenantId: resolved.tenantId,
|
|
733
|
+
gatewayId: hit.gatewayId,
|
|
734
|
+
claimed: Boolean(claim),
|
|
735
|
+
writeTenantId,
|
|
736
|
+
};
|
|
676
737
|
}
|
|
677
738
|
}
|
|
678
739
|
/**
|
|
@@ -8,6 +8,21 @@ export interface KnowledgeTokenInfo {
|
|
|
8
8
|
tenantId: string;
|
|
9
9
|
gatewayId: string;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* 租户断言(受信 gateway 上行,arch/multi-tenancy.md T3):
|
|
13
|
+
* `x-octopi-tenant` = 调用方断言的 run 归属租户(与 X-Registry-Token 同族的归属通道)。
|
|
14
|
+
* token 域 = PLATFORM(跨域受信)→ 断言任意域放行;token 域 = 其他 → 只可断言本域。
|
|
15
|
+
* 无断言 = token 域(旧语义)。
|
|
16
|
+
*
|
|
17
|
+
* @param tokenTenantId - token 绑定域
|
|
18
|
+
* @param claimed - 请求断言的租户(可缺省)
|
|
19
|
+
* @returns 生效域;断言越域时 `{ error }`(调用方按 401/403 拒)
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveTenantClaim(tokenTenantId: string, claimed: string | undefined): {
|
|
22
|
+
tenantId: string;
|
|
23
|
+
} | {
|
|
24
|
+
error: 'tenant_mismatch';
|
|
25
|
+
};
|
|
11
26
|
/**
|
|
12
27
|
* Token → (tenant, gateway)。主线程 401 快速拒绝 + Engine 再验(同一实现)。
|
|
13
28
|
*/
|
|
@@ -3,6 +3,25 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 主线程不得跑 Knowledge 业务/SQLite;只转发,保证 /health 在引擎忙时仍可答。
|
|
5
5
|
*/
|
|
6
|
+
import { PLATFORM_TENANT_ID } from '@octopi-agent/core/types.js';
|
|
7
|
+
/**
|
|
8
|
+
* 租户断言(受信 gateway 上行,arch/multi-tenancy.md T3):
|
|
9
|
+
* `x-octopi-tenant` = 调用方断言的 run 归属租户(与 X-Registry-Token 同族的归属通道)。
|
|
10
|
+
* token 域 = PLATFORM(跨域受信)→ 断言任意域放行;token 域 = 其他 → 只可断言本域。
|
|
11
|
+
* 无断言 = token 域(旧语义)。
|
|
12
|
+
*
|
|
13
|
+
* @param tokenTenantId - token 绑定域
|
|
14
|
+
* @param claimed - 请求断言的租户(可缺省)
|
|
15
|
+
* @returns 生效域;断言越域时 `{ error }`(调用方按 401/403 拒)
|
|
16
|
+
*/
|
|
17
|
+
export function resolveTenantClaim(tokenTenantId, claimed) {
|
|
18
|
+
if (!claimed)
|
|
19
|
+
return { tenantId: tokenTenantId };
|
|
20
|
+
if (tokenTenantId === PLATFORM_TENANT_ID || tokenTenantId === claimed) {
|
|
21
|
+
return { tenantId: claimed };
|
|
22
|
+
}
|
|
23
|
+
return { error: 'tenant_mismatch' };
|
|
24
|
+
}
|
|
6
25
|
/**
|
|
7
26
|
* Token → (tenant, gateway)。主线程 401 快速拒绝 + Engine 再验(同一实现)。
|
|
8
27
|
*/
|
|
@@ -51,9 +51,8 @@ async function main() {
|
|
|
51
51
|
ingest: boot.ingest ?? null,
|
|
52
52
|
retriever: boot.retriever ?? null,
|
|
53
53
|
autoDescribe: boot.autoDescribe,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
: {}),
|
|
54
|
+
sqliteVec: boot.sqliteVec,
|
|
55
|
+
allowPublic: boot.allowPublic,
|
|
57
56
|
});
|
|
58
57
|
let closing = false;
|
|
59
58
|
const shutdown = async (code) => {
|
|
@@ -110,6 +110,8 @@ export interface KnowledgeQueryService {
|
|
|
110
110
|
autoGround(query: AutoGroundQuery): Promise<AutoGroundDecision>;
|
|
111
111
|
listSources(query: ListSourcesQuery): Promise<KnowledgeSource[]>;
|
|
112
112
|
listProjects(identity?: QueryIdentity): Promise<Array<Record<string, unknown>>>;
|
|
113
|
+
/** 单项目登记行(含归属域/可见性);未登记/不可见 = null(管理面域继承用) */
|
|
114
|
+
getProject(identity: QueryIdentity, projectKey: string): Promise<Record<string, unknown> | null>;
|
|
113
115
|
getSource(sourceId: string, identity?: QueryIdentity): Promise<{
|
|
114
116
|
source: KnowledgeSource;
|
|
115
117
|
stats: SourceStatsBundle;
|
|
@@ -192,6 +194,7 @@ export declare class LocalKnowledgeQueryService implements KnowledgeQueryService
|
|
|
192
194
|
autoGround(query: AutoGroundQuery): Promise<AutoGroundDecision>;
|
|
193
195
|
listSources(query: ListSourcesQuery): Promise<KnowledgeSource[]>;
|
|
194
196
|
listProjects(identity?: QueryIdentity): Promise<Array<Record<string, unknown>>>;
|
|
197
|
+
getProject(identity: QueryIdentity, projectKey: string): Promise<Record<string, unknown> | null>;
|
|
195
198
|
getSource(sourceId: string, identity?: QueryIdentity): Promise<{
|
|
196
199
|
source: KnowledgeSource;
|
|
197
200
|
stats: SourceStatsBundle;
|
|
@@ -252,7 +255,11 @@ export declare class LocalKnowledgeQueryService implements KnowledgeQueryService
|
|
|
252
255
|
minHits?: number;
|
|
253
256
|
}): Promise<PromotionCandidate[]>;
|
|
254
257
|
dispose(): void;
|
|
255
|
-
|
|
258
|
+
/**
|
|
259
|
+
* 控制面读口域闸(T3b,评审 MAJ-4):租户闸 ⊕ 网关漏斗 ⊕ 项目跨域闸,单源委托 source-store
|
|
260
|
+
* (原为本地第二套 gatewayVisible 实现——无租户检查,跨租户可读;且违反单源律)。
|
|
261
|
+
*/
|
|
262
|
+
private domainVisible;
|
|
256
263
|
}
|
|
257
264
|
/**
|
|
258
265
|
* 组装只读服务。
|
|
@@ -272,7 +279,10 @@ export declare function createKnowledgeQueryService(opts: {
|
|
|
272
279
|
providers?: Record<string, unknown>;
|
|
273
280
|
embedding?: unknown;
|
|
274
281
|
} | null;
|
|
275
|
-
|
|
282
|
+
sqliteVec?: boolean | {
|
|
283
|
+
extensionPath?: string;
|
|
284
|
+
require?: boolean;
|
|
285
|
+
};
|
|
276
286
|
/** Worker 角色:meta=列表/控制面,search=检索/catalog,all=单 Worker 全量 */
|
|
277
287
|
role?: QueryWorkerRole;
|
|
278
288
|
queryTimeoutMs?: number;
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* **禁止**在此接口上实现任何写路径(唯一写者是 Writer Worker / LocalKnowledgeWriteService)。
|
|
8
8
|
*/
|
|
9
9
|
import { readJobControlState, } from './job-control-state.js';
|
|
10
|
+
import { ownerFunnelSql, projectGateSql, tenantGateSql, tenantOwnGateSql, tenantPrecedenceOrder } from './tenant-gate.js';
|
|
10
11
|
import { KnowledgeHitLog } from './hit-log.js';
|
|
11
12
|
/**
|
|
12
13
|
* 进程内只读实现(测试 / 共享 :memory:)。
|
|
@@ -43,7 +44,7 @@ export class LocalKnowledgeQueryService {
|
|
|
43
44
|
const { sources } = this.deps;
|
|
44
45
|
let list = sources.list();
|
|
45
46
|
if (query.identity) {
|
|
46
|
-
list = list.filter((s) => this.
|
|
47
|
+
list = sources.withProjectRowCache(() => list.filter((s) => this.domainVisible(s, query.identity)));
|
|
47
48
|
}
|
|
48
49
|
if (query.scopeLevel === 'global' || query.scopeLevel === 'project' || query.scopeLevel === 'session') {
|
|
49
50
|
list = list.filter((s) => s.scopeRef.level === query.scopeLevel);
|
|
@@ -66,18 +67,21 @@ export class LocalKnowledgeQueryService {
|
|
|
66
67
|
gatewayId: identity?.gatewayId,
|
|
67
68
|
});
|
|
68
69
|
}
|
|
70
|
+
async getProject(identity, projectKey) {
|
|
71
|
+
return this.deps.sources.getProject(projectKey, identity);
|
|
72
|
+
}
|
|
69
73
|
async getSource(sourceId, identity) {
|
|
70
74
|
const src = this.deps.sources.get(sourceId);
|
|
71
75
|
if (!src)
|
|
72
76
|
return null;
|
|
73
|
-
if (identity && !this.
|
|
77
|
+
if (identity && !this.domainVisible(src, identity))
|
|
74
78
|
return null;
|
|
75
79
|
return { source: src, stats: this.deps.index.sourceStats(sourceId) };
|
|
76
80
|
}
|
|
77
81
|
async listFiles(sourceId, identity) {
|
|
78
82
|
if (identity) {
|
|
79
83
|
const src = this.deps.sources.get(sourceId);
|
|
80
|
-
if (!src || !this.
|
|
84
|
+
if (!src || !this.domainVisible(src, identity))
|
|
81
85
|
return [];
|
|
82
86
|
}
|
|
83
87
|
return this.deps.index.listFiles(sourceId);
|
|
@@ -85,7 +89,7 @@ export class LocalKnowledgeQueryService {
|
|
|
85
89
|
async listFilesPaged(sourceId, opts, identity) {
|
|
86
90
|
if (identity) {
|
|
87
91
|
const src = this.deps.sources.get(sourceId);
|
|
88
|
-
if (!src || !this.
|
|
92
|
+
if (!src || !this.domainVisible(src, identity)) {
|
|
89
93
|
return {
|
|
90
94
|
items: [],
|
|
91
95
|
total: 0,
|
|
@@ -100,20 +104,32 @@ export class LocalKnowledgeQueryService {
|
|
|
100
104
|
}
|
|
101
105
|
async principalStats(agentId, identity) {
|
|
102
106
|
const { sources, db } = this.deps;
|
|
103
|
-
const visible = sources.listVisible(agentId, undefined, identity).filter((s) => {
|
|
104
|
-
return !identity || this.
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
+
const visible = sources.withProjectRowCache(() => sources.listVisible(agentId, undefined, identity).filter((s) => {
|
|
108
|
+
return !identity || this.domainVisible(s, identity);
|
|
109
|
+
}));
|
|
110
|
+
// 评审 m7(拍板 B):面板统计=本视图口径(只数可见源);全库口径属运维面
|
|
111
|
+
// (doctor/ops),等运维功能落地后再回接,避免「统计有数、列表为空」式误读
|
|
112
|
+
const stats = db.statsForSourceIds(visible.map((s) => s.id));
|
|
113
|
+
const assignedProjects = sources.withProjectRowCache(() => sources
|
|
114
|
+
.list()
|
|
115
|
+
.filter((s) => s.scopeRef.level === 'project' &&
|
|
116
|
+
sources.isVisible(s, agentId, undefined, identity) &&
|
|
117
|
+
(!identity || this.domainVisible(s, identity)))
|
|
118
|
+
.map((s) => s.scopeRef.key));
|
|
119
|
+
const hiddenSourceIds = sources.listHidden(agentId, identity ?? {});
|
|
120
|
+
// 可见性计数器同口径:报本 agent/本身份自己的行,不报全库注册表规模
|
|
121
|
+
stats.projectAgents = assignedProjects.length;
|
|
122
|
+
stats.agentHidden = hiddenSourceIds.length;
|
|
123
|
+
stats.agentMounted = sources.listMounted(agentId, identity ?? {}).length;
|
|
124
|
+
const sessionGate = tenantOwnGateSql('tenant_id', identity ?? {});
|
|
125
|
+
stats.sessionVisibility = db.raw
|
|
126
|
+
.prepare(`SELECT COUNT(*) AS count FROM knowledge_session_visibility WHERE ${sessionGate.sql}`)
|
|
127
|
+
.get(...sessionGate.params).count;
|
|
107
128
|
return {
|
|
108
129
|
stats,
|
|
109
130
|
visibility: {
|
|
110
|
-
assignedProjects
|
|
111
|
-
|
|
112
|
-
.filter((s) => s.scopeRef.level === 'project' &&
|
|
113
|
-
sources.isVisible(s, agentId, undefined, identity) &&
|
|
114
|
-
(!identity || this.gatewayVisible(s, identity)))
|
|
115
|
-
.map((s) => s.scopeRef.key),
|
|
116
|
-
hiddenSourceIds: sources.listHidden(agentId, identity ?? {}),
|
|
131
|
+
assignedProjects,
|
|
132
|
+
hiddenSourceIds,
|
|
117
133
|
},
|
|
118
134
|
visibleSources: visible.length,
|
|
119
135
|
};
|
|
@@ -122,17 +138,17 @@ export class LocalKnowledgeQueryService {
|
|
|
122
138
|
const items = this.deps.sources.catalogFor(agentId, { identity });
|
|
123
139
|
if (!identity)
|
|
124
140
|
return items;
|
|
125
|
-
return items.filter((item) => {
|
|
141
|
+
return this.deps.sources.withProjectRowCache(() => items.filter((item) => {
|
|
126
142
|
const src = this.deps.sources.get(item.id);
|
|
127
|
-
return !src || this.
|
|
128
|
-
});
|
|
143
|
+
return !src || this.domainVisible(src, identity);
|
|
144
|
+
}));
|
|
129
145
|
}
|
|
130
146
|
async listChunks(agentId, sourceId, path, identity, sessionId) {
|
|
131
147
|
const { sources, index } = this.deps;
|
|
132
148
|
const src = sources.get(sourceId);
|
|
133
149
|
if (!src)
|
|
134
150
|
return null;
|
|
135
|
-
if (identity && !this.
|
|
151
|
+
if (identity && !this.domainVisible(src, identity))
|
|
136
152
|
return null;
|
|
137
153
|
if (!sources.isVisible(src, agentId, sessionId, identity))
|
|
138
154
|
return null;
|
|
@@ -143,7 +159,7 @@ export class LocalKnowledgeQueryService {
|
|
|
143
159
|
const visible = (src) => {
|
|
144
160
|
if (!src)
|
|
145
161
|
return false;
|
|
146
|
-
if (identity && !this.
|
|
162
|
+
if (identity && !this.domainVisible(src, identity))
|
|
147
163
|
return false;
|
|
148
164
|
return sources.isVisible(src, agentId, sessionId, identity);
|
|
149
165
|
};
|
|
@@ -189,7 +205,7 @@ export class LocalKnowledgeQueryService {
|
|
|
189
205
|
.list()
|
|
190
206
|
.filter((s) => s.scopeRef.level === 'project' &&
|
|
191
207
|
sources.isVisible(s, agentId, undefined, identity) &&
|
|
192
|
-
(!identity || this.
|
|
208
|
+
(!identity || this.domainVisible(s, identity)))
|
|
193
209
|
.map((s) => s.scopeRef.key);
|
|
194
210
|
return {
|
|
195
211
|
assignedProjects: [...new Set(assigned)],
|
|
@@ -205,7 +221,7 @@ export class LocalKnowledgeQueryService {
|
|
|
205
221
|
if (item.targetType !== 'source')
|
|
206
222
|
return true;
|
|
207
223
|
const src = this.deps.sources.get(item.targetId);
|
|
208
|
-
return !src || this.
|
|
224
|
+
return !src || this.domainVisible(src, identity);
|
|
209
225
|
});
|
|
210
226
|
}
|
|
211
227
|
async dbStats() {
|
|
@@ -216,7 +232,7 @@ export class LocalKnowledgeQueryService {
|
|
|
216
232
|
const src = sources.get(sourceId);
|
|
217
233
|
if (!src)
|
|
218
234
|
return null;
|
|
219
|
-
if (identity && !this.
|
|
235
|
+
if (identity && !this.domainVisible(src, identity))
|
|
220
236
|
return null;
|
|
221
237
|
const jobControl = readJobControlState(db, index, sourceId, {
|
|
222
238
|
embeddingEnabled: this.deps.embeddingEnabled ?? true,
|
|
@@ -232,18 +248,22 @@ export class LocalKnowledgeQueryService {
|
|
|
232
248
|
};
|
|
233
249
|
}
|
|
234
250
|
async getPrincipal(identity, agentId) {
|
|
251
|
+
const gate = tenantOwnGateSql('tenant_id', identity);
|
|
252
|
+
const order = tenantPrecedenceOrder('tenant_id', identity);
|
|
235
253
|
const row = this.deps.db.raw
|
|
236
254
|
.prepare(`SELECT * FROM knowledge_principals
|
|
237
|
-
WHERE
|
|
238
|
-
|
|
255
|
+
WHERE ${gate.sql} AND gateway_id = ? AND local_agent_id = ?
|
|
256
|
+
ORDER BY ${order.sql} LIMIT 1`)
|
|
257
|
+
.get(...gate.params, identity.gatewayId ?? 'default', agentId, ...order.params);
|
|
239
258
|
return row ?? null;
|
|
240
259
|
}
|
|
241
260
|
async isPrincipalForeign(identity, agentId) {
|
|
261
|
+
const gate = tenantOwnGateSql('tenant_id', identity);
|
|
242
262
|
const row = this.deps.db.raw
|
|
243
263
|
.prepare(`SELECT 1 AS ok FROM knowledge_principals
|
|
244
|
-
WHERE
|
|
264
|
+
WHERE ${gate.sql} AND local_agent_id = ? AND gateway_id != ?
|
|
245
265
|
LIMIT 1`)
|
|
246
|
-
.get(
|
|
266
|
+
.get(...gate.params, agentId, identity.gatewayId ?? 'default');
|
|
247
267
|
return Boolean(row);
|
|
248
268
|
}
|
|
249
269
|
async isSourceOwner(sourceId, gatewayId) {
|
|
@@ -273,10 +293,24 @@ export class LocalKnowledgeQueryService {
|
|
|
273
293
|
};
|
|
274
294
|
}
|
|
275
295
|
async listJobs(query) {
|
|
296
|
+
const tenantGate = tenantGateSql('s.tenant_id', query.identity);
|
|
297
|
+
const funnel = ownerFunnelSql('s.registered_by', 's.visibility', query.identity);
|
|
298
|
+
const projectGate = projectGateSql('p.tenant_id', 'p.visibility', query.identity);
|
|
299
|
+
// 源范围与读侧同口径(评审 m1):租户闸 ⊕ 归属漏斗 ⊕ 项目跨域闸——job 行携带 path/last_error,
|
|
300
|
+
// 不得成为项目闸旁路的元数据泄漏面
|
|
276
301
|
const where = [
|
|
277
|
-
`source_id IN (
|
|
302
|
+
`source_id IN (
|
|
303
|
+
SELECT s.id FROM knowledge_sources s
|
|
304
|
+
WHERE ${tenantGate.sql} AND ${funnel.sql}
|
|
305
|
+
AND (s.scope_level != 'project' OR EXISTS (
|
|
306
|
+
SELECT 1 FROM knowledge_projects p
|
|
307
|
+
WHERE p.project_key = s.scope_key
|
|
308
|
+
AND IFNULL(p.tenant_id, '') = IFNULL(s.tenant_id, '')
|
|
309
|
+
AND ${projectGate.sql}
|
|
310
|
+
))
|
|
311
|
+
)`,
|
|
278
312
|
];
|
|
279
|
-
const args = [
|
|
313
|
+
const args = [...tenantGate.params, ...funnel.params, ...projectGate.params];
|
|
280
314
|
if (query.sourceId) {
|
|
281
315
|
where.push('source_id = ?');
|
|
282
316
|
args.push(query.sourceId);
|
|
@@ -296,17 +330,17 @@ export class LocalKnowledgeQueryService {
|
|
|
296
330
|
dispose() {
|
|
297
331
|
/* 只读;连接由调用方持有 */
|
|
298
332
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
return
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
333
|
+
/**
|
|
334
|
+
* 控制面读口域闸(T3b,评审 MAJ-4):租户闸 ⊕ 网关漏斗 ⊕ 项目跨域闸,单源委托 source-store
|
|
335
|
+
* (原为本地第二套 gatewayVisible 实现——无租户检查,跨租户可读;且违反单源律)。
|
|
336
|
+
*/
|
|
337
|
+
domainVisible(src, identity) {
|
|
338
|
+
if (src.scopeRef.level === 'project' &&
|
|
339
|
+
!this.deps.sources.isProjectVisible(src, src.scopeRef.key, identity)) {
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
return (this.deps.sources.isTenantVisible(src, identity) &&
|
|
343
|
+
this.deps.sources.isGatewayVisible(src, identity));
|
|
310
344
|
}
|
|
311
345
|
}
|
|
312
346
|
export async function createKnowledgeQueryService(opts) {
|
|
@@ -319,7 +353,7 @@ export async function createKnowledgeQueryService(opts) {
|
|
|
319
353
|
return WorkerQueryService.start({
|
|
320
354
|
dbPath: opts.dbPath,
|
|
321
355
|
embeddingModels: opts.embeddingModels ?? null,
|
|
322
|
-
|
|
356
|
+
sqliteVec: opts.sqliteVec,
|
|
323
357
|
role: opts.role ?? 'all',
|
|
324
358
|
queryTimeoutMs: opts.queryTimeoutMs,
|
|
325
359
|
embed: opts.embed ?? null,
|
|
@@ -23,7 +23,10 @@ export declare class WorkerQueryService implements KnowledgeQueryService {
|
|
|
23
23
|
*/
|
|
24
24
|
static start(opts: {
|
|
25
25
|
dbPath: string;
|
|
26
|
-
|
|
26
|
+
sqliteVec?: boolean | {
|
|
27
|
+
extensionPath?: string;
|
|
28
|
+
require?: boolean;
|
|
29
|
+
};
|
|
27
30
|
queryTimeoutMs?: number;
|
|
28
31
|
role?: QueryWorkerRole;
|
|
29
32
|
embeddingModels?: {
|
|
@@ -41,6 +44,7 @@ export declare class WorkerQueryService implements KnowledgeQueryService {
|
|
|
41
44
|
autoGround(query: AutoGroundQuery): Promise<AutoGroundDecision>;
|
|
42
45
|
listSources(query: ListSourcesQuery): Promise<KnowledgeSource[]>;
|
|
43
46
|
listProjects(identity?: QueryIdentity): Promise<Array<Record<string, unknown>>>;
|
|
47
|
+
getProject(identity: QueryIdentity, projectKey: string): Promise<Record<string, unknown> | null>;
|
|
44
48
|
getSource(sourceId: string, identity?: QueryIdentity): Promise<{
|
|
45
49
|
source: KnowledgeSource;
|
|
46
50
|
stats: SourceStatsBundle;
|
|
@@ -72,7 +72,7 @@ export class WorkerQueryService {
|
|
|
72
72
|
const worker = new Worker(resolveWorkerUrl('./query-worker.js', import.meta.url), {
|
|
73
73
|
workerData: {
|
|
74
74
|
dbPath: opts.dbPath,
|
|
75
|
-
|
|
75
|
+
sqliteVec: opts.sqliteVec,
|
|
76
76
|
embeddingModels: opts.embeddingModels ?? null,
|
|
77
77
|
role: opts.role ?? 'all',
|
|
78
78
|
embed: opts.embed ?? null,
|
|
@@ -129,6 +129,9 @@ export class WorkerQueryService {
|
|
|
129
129
|
async listProjects(identity) {
|
|
130
130
|
return (await this.call({ method: 'listProjects', identity }));
|
|
131
131
|
}
|
|
132
|
+
async getProject(identity, projectKey) {
|
|
133
|
+
return (await this.call({ method: 'getProject', identity, projectKey }));
|
|
134
|
+
}
|
|
132
135
|
async getSource(sourceId, identity) {
|
|
133
136
|
return (await this.call({ method: 'getSource', sourceId, identity }));
|
|
134
137
|
}
|