@octopi-agent/engine 0.102.10 → 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 +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
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
* KnowledgeClient — Gateway 侧 RPC(不打开 knowledge.db)
|
|
3
3
|
*/
|
|
4
4
|
import type { KnowledgeSourceKind } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* run 归属租户断言提供者(T3b):run 内 = run 租户(DEFAULT 兜底,fail-closed);
|
|
7
|
+
* run 外 = 不断言(宿主面,broker 全量语义)。实例级挂载,防逐方法漏传断言。
|
|
8
|
+
*/
|
|
9
|
+
export declare function runTenantClaimProvider(): () => string | undefined;
|
|
5
10
|
export interface KnowledgeClientOptions {
|
|
6
11
|
baseUrl: string;
|
|
7
12
|
token: string;
|
|
@@ -18,7 +23,15 @@ export interface KnowledgeClientOptions {
|
|
|
18
23
|
}
|
|
19
24
|
export declare class KnowledgeClient {
|
|
20
25
|
private readonly opts;
|
|
26
|
+
/** 实例级租户断言提供者(T3b):逐方法 opts 缺省时取用——防新增方法漏传断言的结构性漂移 */
|
|
27
|
+
private tenantProvider?;
|
|
21
28
|
constructor(opts: KnowledgeClientOptions);
|
|
29
|
+
/**
|
|
30
|
+
* 设置实例级租户断言提供者(调用时刻求值;逐方法 opts.tenantId 优先)。
|
|
31
|
+
*
|
|
32
|
+
* @param provider - 返回断言租户;undefined = 不断言(宿主面)
|
|
33
|
+
*/
|
|
34
|
+
setTenantProvider(provider: () => string | undefined): void;
|
|
22
35
|
get baseUrl(): string;
|
|
23
36
|
get token(): string;
|
|
24
37
|
private request;
|
|
@@ -37,9 +50,17 @@ export declare class KnowledgeClient {
|
|
|
37
50
|
projectKey?: string;
|
|
38
51
|
sessionId?: string;
|
|
39
52
|
}): Promise<Array<Record<string, unknown>>>;
|
|
40
|
-
createSource(input: Record<string, unknown
|
|
41
|
-
|
|
42
|
-
|
|
53
|
+
createSource(input: Record<string, unknown>, opts?: {
|
|
54
|
+
tenantId?: string;
|
|
55
|
+
}): Promise<Record<string, unknown>>;
|
|
56
|
+
/** 单项目登记行(含归属域/可见性;管理面域继承用)。未登记/不可见 → null */
|
|
57
|
+
getProject(projectKey: string): Promise<Record<string, unknown> | null>;
|
|
58
|
+
patchSource(sourceId: string, patch: Record<string, unknown>, opts?: {
|
|
59
|
+
tenantId?: string;
|
|
60
|
+
}): Promise<Record<string, unknown>>;
|
|
61
|
+
deleteSource(sourceId: string, opts?: {
|
|
62
|
+
tenantId?: string;
|
|
63
|
+
}): Promise<unknown>;
|
|
43
64
|
reindex(sourceId: string): Promise<unknown>;
|
|
44
65
|
/** 按路径 / 筛选强制重解析(中止态自动 resume) */
|
|
45
66
|
reprocess(sourceId: string, opts: {
|
|
@@ -59,6 +80,7 @@ export declare class KnowledgeClient {
|
|
|
59
80
|
search(agentId: string, q: string, opts?: {
|
|
60
81
|
sessionId?: string;
|
|
61
82
|
limit?: number;
|
|
83
|
+
tenantId?: string;
|
|
62
84
|
}): Promise<{
|
|
63
85
|
hits: unknown[];
|
|
64
86
|
keywordHits: number;
|
|
@@ -68,6 +90,7 @@ export declare class KnowledgeClient {
|
|
|
68
90
|
autoGround(agentId: string, q: string, opts?: {
|
|
69
91
|
sessionId?: string;
|
|
70
92
|
limit?: number;
|
|
93
|
+
tenantId?: string;
|
|
71
94
|
recall?: 'off' | 'hint' | 'hybrid' | 'inject';
|
|
72
95
|
}): Promise<{
|
|
73
96
|
mode: 'inject' | 'hint' | 'none';
|
|
@@ -87,7 +110,7 @@ export declare class KnowledgeClient {
|
|
|
87
110
|
projectKey: string;
|
|
88
111
|
displayName?: string;
|
|
89
112
|
visibility?: string;
|
|
90
|
-
}): Promise<Record<string, unknown>>;
|
|
113
|
+
}, tenantId?: string): Promise<Record<string, unknown>>;
|
|
91
114
|
deleteProject(projectKey: string): Promise<unknown>;
|
|
92
115
|
getSource(sourceId: string): Promise<Record<string, unknown>>;
|
|
93
116
|
/** 中止源任务;省略 sourceId = 中止本 Gateway 全部源 */
|
|
@@ -116,7 +139,9 @@ export declare class KnowledgeClient {
|
|
|
116
139
|
n: number;
|
|
117
140
|
}>;
|
|
118
141
|
}>;
|
|
119
|
-
catalog(agentId: string
|
|
142
|
+
catalog(agentId: string, opts?: {
|
|
143
|
+
tenantId?: string;
|
|
144
|
+
}): Promise<unknown[]>;
|
|
120
145
|
promotionCandidates(opts?: {
|
|
121
146
|
minSessions?: number;
|
|
122
147
|
minHits?: number;
|
|
@@ -143,7 +168,9 @@ export declare class KnowledgeClient {
|
|
|
143
168
|
}>;
|
|
144
169
|
/** 待 LLM 升级的源 id(boot sweep 用) */
|
|
145
170
|
listDescribePending(): Promise<string[]>;
|
|
146
|
-
listChunks(agentId: string, sourceId: string, path: string
|
|
171
|
+
listChunks(agentId: string, sourceId: string, path: string, opts?: {
|
|
172
|
+
tenantId?: string;
|
|
173
|
+
}): Promise<Array<{
|
|
147
174
|
id: string;
|
|
148
175
|
text: string;
|
|
149
176
|
startLine: number;
|
|
@@ -155,6 +182,8 @@ export declare class KnowledgeClient {
|
|
|
155
182
|
chunkId?: string;
|
|
156
183
|
sourceId?: string;
|
|
157
184
|
path?: string;
|
|
185
|
+
}, opts?: {
|
|
186
|
+
tenantId?: string;
|
|
158
187
|
}): Promise<{
|
|
159
188
|
found: boolean;
|
|
160
189
|
path?: string;
|
|
@@ -163,16 +192,31 @@ export declare class KnowledgeClient {
|
|
|
163
192
|
text?: string;
|
|
164
193
|
chunkCount?: number;
|
|
165
194
|
}>;
|
|
195
|
+
/** 租户断言头(T3,arch/multi-tenancy.md §6):token=platform 时上行 run 归属域 */
|
|
196
|
+
private tenantHeaders;
|
|
166
197
|
getVisibility(agentId: string): Promise<{
|
|
167
198
|
assignedProjects: string[];
|
|
168
199
|
hiddenSourceIds: string[];
|
|
169
200
|
}>;
|
|
170
201
|
sessionVisibility(agentId: string, sessionId: string): Promise<Array<Record<string, unknown>>>;
|
|
202
|
+
/**
|
|
203
|
+
* agent 级可见性 override(T3b 挂载物化):op=mount|unmount|hide|unhide。
|
|
204
|
+
*
|
|
205
|
+
* @param agentId - 消费 agent
|
|
206
|
+
* @param op - override 操作
|
|
207
|
+
* @param sourceId - 目标知识源
|
|
208
|
+
* @param opts - 租户断言(token=platform 时上行归属域)
|
|
209
|
+
*/
|
|
210
|
+
setAgentVisibility(agentId: string, op: 'mount' | 'unmount' | 'hide' | 'unhide', sourceId: string, opts?: {
|
|
211
|
+
tenantId?: string;
|
|
212
|
+
}): Promise<unknown>;
|
|
171
213
|
setSessionVisibility(agentId: string, item: {
|
|
172
214
|
sessionId: string;
|
|
173
215
|
targetType: 'project' | 'source';
|
|
174
216
|
targetId: string;
|
|
175
217
|
op: 'include' | 'exclude';
|
|
218
|
+
}, opts?: {
|
|
219
|
+
tenantId?: string;
|
|
176
220
|
}): Promise<unknown>;
|
|
177
221
|
replaceSessionVisibility(agentId: string, sessionId: string, items: Array<{
|
|
178
222
|
targetType: 'project' | 'source';
|
|
@@ -182,7 +226,9 @@ export declare class KnowledgeClient {
|
|
|
182
226
|
clearSessionVisibility(agentId: string, sessionId: string, target?: {
|
|
183
227
|
targetType: 'project' | 'source';
|
|
184
228
|
targetId: string;
|
|
185
|
-
}
|
|
229
|
+
}, opts?: {
|
|
230
|
+
tenantId?: string;
|
|
231
|
+
}, op?: 'include' | 'exclude'): Promise<unknown>;
|
|
186
232
|
jobControl(sourceId: string): Promise<{
|
|
187
233
|
aborted: boolean;
|
|
188
234
|
jobsQueued: number;
|
|
@@ -1,11 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* KnowledgeClient — Gateway 侧 RPC(不打开 knowledge.db)
|
|
3
3
|
*/
|
|
4
|
+
import { DEFAULT_TENANT_ID } from '@octopi-agent/core/types.js';
|
|
5
|
+
import { getRunScope } from '../run/run-scope.js';
|
|
6
|
+
/**
|
|
7
|
+
* run 归属租户断言提供者(T3b):run 内 = run 租户(DEFAULT 兜底,fail-closed);
|
|
8
|
+
* run 外 = 不断言(宿主面,broker 全量语义)。实例级挂载,防逐方法漏传断言。
|
|
9
|
+
*/
|
|
10
|
+
export function runTenantClaimProvider() {
|
|
11
|
+
return () => {
|
|
12
|
+
const scope = getRunScope();
|
|
13
|
+
if (!scope)
|
|
14
|
+
return undefined;
|
|
15
|
+
return scope.principal?.tenantId ?? DEFAULT_TENANT_ID;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
4
18
|
export class KnowledgeClient {
|
|
5
19
|
opts;
|
|
20
|
+
/** 实例级租户断言提供者(T3b):逐方法 opts 缺省时取用——防新增方法漏传断言的结构性漂移 */
|
|
21
|
+
tenantProvider;
|
|
6
22
|
constructor(opts) {
|
|
7
23
|
this.opts = opts;
|
|
8
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* 设置实例级租户断言提供者(调用时刻求值;逐方法 opts.tenantId 优先)。
|
|
27
|
+
*
|
|
28
|
+
* @param provider - 返回断言租户;undefined = 不断言(宿主面)
|
|
29
|
+
*/
|
|
30
|
+
setTenantProvider(provider) {
|
|
31
|
+
this.tenantProvider = provider;
|
|
32
|
+
}
|
|
9
33
|
get baseUrl() {
|
|
10
34
|
return this.opts.baseUrl;
|
|
11
35
|
}
|
|
@@ -27,6 +51,9 @@ export class KnowledgeClient {
|
|
|
27
51
|
headers: {
|
|
28
52
|
authorization: `Bearer ${this.opts.token}`,
|
|
29
53
|
...(body != null ? { 'content-type': 'application/json' } : {}),
|
|
54
|
+
// 租户断言单点收口(T3b):实例级 provider 兜底,逐方法显式断言优先——
|
|
55
|
+
// 新增方法不传 opts 也自动带 run 归属,防漏传漂移
|
|
56
|
+
...(this.tenantHeaders(undefined) ?? {}),
|
|
30
57
|
...headers,
|
|
31
58
|
},
|
|
32
59
|
body: body != null ? JSON.stringify(body) : undefined,
|
|
@@ -72,14 +99,23 @@ export class KnowledgeClient {
|
|
|
72
99
|
read: true,
|
|
73
100
|
});
|
|
74
101
|
}
|
|
75
|
-
createSource(input) {
|
|
76
|
-
return this.request('POST', '/v1/sources', input);
|
|
102
|
+
createSource(input, opts) {
|
|
103
|
+
return this.request('POST', '/v1/sources', input, this.tenantHeaders(opts?.tenantId));
|
|
104
|
+
}
|
|
105
|
+
/** 单项目登记行(含归属域/可见性;管理面域继承用)。未登记/不可见 → null */
|
|
106
|
+
async getProject(projectKey) {
|
|
107
|
+
try {
|
|
108
|
+
return await this.request('GET', `/v1/projects/${encodeURIComponent(projectKey)}`, undefined, undefined, { read: true });
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
77
113
|
}
|
|
78
|
-
patchSource(sourceId, patch) {
|
|
79
|
-
return this.request('PATCH', `/v1/sources/${encodeURIComponent(sourceId)}`, patch);
|
|
114
|
+
patchSource(sourceId, patch, opts) {
|
|
115
|
+
return this.request('PATCH', `/v1/sources/${encodeURIComponent(sourceId)}`, patch, this.tenantHeaders(opts?.tenantId));
|
|
80
116
|
}
|
|
81
|
-
deleteSource(sourceId) {
|
|
82
|
-
return this.request('DELETE', `/v1/sources/${encodeURIComponent(sourceId)}
|
|
117
|
+
deleteSource(sourceId, opts) {
|
|
118
|
+
return this.request('DELETE', `/v1/sources/${encodeURIComponent(sourceId)}`, undefined, this.tenantHeaders(opts?.tenantId));
|
|
83
119
|
}
|
|
84
120
|
reindex(sourceId) {
|
|
85
121
|
return this.request('POST', `/v1/sources/${encodeURIComponent(sourceId)}/reindex`);
|
|
@@ -94,7 +130,7 @@ export class KnowledgeClient {
|
|
|
94
130
|
qs.set('sessionId', opts.sessionId);
|
|
95
131
|
if (opts?.limit != null)
|
|
96
132
|
qs.set('limit', String(opts.limit));
|
|
97
|
-
return this.request('GET', `/v1/principals/${encodeURIComponent(agentId)}/search?${qs}`, undefined,
|
|
133
|
+
return this.request('GET', `/v1/principals/${encodeURIComponent(agentId)}/search?${qs}`, undefined, this.tenantHeaders(opts?.tenantId), { read: true });
|
|
98
134
|
}
|
|
99
135
|
/** turn 级自动召回分档(与 Search Worker `autoGround` 同源) */
|
|
100
136
|
autoGround(agentId, q, opts) {
|
|
@@ -105,7 +141,7 @@ export class KnowledgeClient {
|
|
|
105
141
|
qs.set('limit', String(opts.limit));
|
|
106
142
|
if (opts?.recall)
|
|
107
143
|
qs.set('recall', opts.recall);
|
|
108
|
-
return this.request('GET', `/v1/principals/${encodeURIComponent(agentId)}/ground?${qs}`, undefined,
|
|
144
|
+
return this.request('GET', `/v1/principals/${encodeURIComponent(agentId)}/ground?${qs}`, undefined, this.tenantHeaders(opts?.tenantId), { read: true });
|
|
109
145
|
}
|
|
110
146
|
stats(agentId) {
|
|
111
147
|
return this.request('GET', `/v1/principals/${encodeURIComponent(agentId)}/stats`, undefined, undefined, { read: true });
|
|
@@ -119,8 +155,9 @@ export class KnowledgeClient {
|
|
|
119
155
|
listProjects() {
|
|
120
156
|
return this.request('GET', '/v1/projects');
|
|
121
157
|
}
|
|
122
|
-
createProject(input) {
|
|
123
|
-
|
|
158
|
+
createProject(input, tenantId) {
|
|
159
|
+
// 显式 tenantId = 租户断言(如公共项目断言 'platform' 落共享面);缺省走实例 provider
|
|
160
|
+
return this.request('POST', '/v1/projects', input, this.tenantHeaders(tenantId));
|
|
124
161
|
}
|
|
125
162
|
deleteProject(projectKey) {
|
|
126
163
|
return this.request('DELETE', `/v1/projects/${encodeURIComponent(projectKey)}`);
|
|
@@ -158,8 +195,8 @@ export class KnowledgeClient {
|
|
|
158
195
|
const s = qs.toString();
|
|
159
196
|
return this.request('GET', `/v1/sources/${encodeURIComponent(sourceId)}/files${s ? `?${s}` : ''}`, undefined, undefined, { read: true });
|
|
160
197
|
}
|
|
161
|
-
catalog(agentId) {
|
|
162
|
-
return this.request('GET', `/v1/principals/${encodeURIComponent(agentId)}/catalog`, undefined,
|
|
198
|
+
catalog(agentId, opts) {
|
|
199
|
+
return this.request('GET', `/v1/principals/${encodeURIComponent(agentId)}/catalog`, undefined, this.tenantHeaders(opts?.tenantId), { read: true });
|
|
163
200
|
}
|
|
164
201
|
promotionCandidates(opts) {
|
|
165
202
|
const qs = new URLSearchParams();
|
|
@@ -181,12 +218,17 @@ export class KnowledgeClient {
|
|
|
181
218
|
listDescribePending() {
|
|
182
219
|
return this.request('GET', '/v1/describe-pending', undefined, undefined, { read: true });
|
|
183
220
|
}
|
|
184
|
-
listChunks(agentId, sourceId, path) {
|
|
221
|
+
listChunks(agentId, sourceId, path, opts) {
|
|
185
222
|
const qs = new URLSearchParams({ sourceId, path });
|
|
186
|
-
return this.request('GET', `/v1/principals/${encodeURIComponent(agentId)}/chunks?${qs}`, undefined,
|
|
223
|
+
return this.request('GET', `/v1/principals/${encodeURIComponent(agentId)}/chunks?${qs}`, undefined, this.tenantHeaders(opts?.tenantId), { read: true });
|
|
187
224
|
}
|
|
188
|
-
read(agentId, body) {
|
|
189
|
-
return this.request('POST', `/v1/principals/${encodeURIComponent(agentId)}/read`, body);
|
|
225
|
+
read(agentId, body, opts) {
|
|
226
|
+
return this.request('POST', `/v1/principals/${encodeURIComponent(agentId)}/read`, body, this.tenantHeaders(opts?.tenantId));
|
|
227
|
+
}
|
|
228
|
+
/** 租户断言头(T3,arch/multi-tenancy.md §6):token=platform 时上行 run 归属域 */
|
|
229
|
+
tenantHeaders(tenantId) {
|
|
230
|
+
const t = tenantId ?? this.tenantProvider?.();
|
|
231
|
+
return t ? { 'x-octopi-tenant': t } : undefined;
|
|
190
232
|
}
|
|
191
233
|
getVisibility(agentId) {
|
|
192
234
|
return this.request('GET', `/v1/principals/${encodeURIComponent(agentId)}/visibility`, undefined, undefined, { read: true });
|
|
@@ -194,8 +236,19 @@ export class KnowledgeClient {
|
|
|
194
236
|
sessionVisibility(agentId, sessionId) {
|
|
195
237
|
return this.request('GET', `/v1/principals/${encodeURIComponent(agentId)}/session-visibility?sessionId=${encodeURIComponent(sessionId)}`, undefined, undefined, { read: true });
|
|
196
238
|
}
|
|
197
|
-
|
|
198
|
-
|
|
239
|
+
/**
|
|
240
|
+
* agent 级可见性 override(T3b 挂载物化):op=mount|unmount|hide|unhide。
|
|
241
|
+
*
|
|
242
|
+
* @param agentId - 消费 agent
|
|
243
|
+
* @param op - override 操作
|
|
244
|
+
* @param sourceId - 目标知识源
|
|
245
|
+
* @param opts - 租户断言(token=platform 时上行归属域)
|
|
246
|
+
*/
|
|
247
|
+
setAgentVisibility(agentId, op, sourceId, opts) {
|
|
248
|
+
return this.request('POST', `/v1/principals/${encodeURIComponent(agentId)}/visibility`, { op, sourceId }, this.tenantHeaders(opts?.tenantId));
|
|
249
|
+
}
|
|
250
|
+
setSessionVisibility(agentId, item, opts) {
|
|
251
|
+
return this.request('POST', `/v1/principals/${encodeURIComponent(agentId)}/session-visibility`, item, this.tenantHeaders(opts?.tenantId));
|
|
199
252
|
}
|
|
200
253
|
replaceSessionVisibility(agentId, sessionId, items) {
|
|
201
254
|
return this.request('PUT', `/v1/principals/${encodeURIComponent(agentId)}/session-visibility`, {
|
|
@@ -203,13 +256,15 @@ export class KnowledgeClient {
|
|
|
203
256
|
items,
|
|
204
257
|
});
|
|
205
258
|
}
|
|
206
|
-
clearSessionVisibility(agentId, sessionId, target) {
|
|
259
|
+
clearSessionVisibility(agentId, sessionId, target, opts, op) {
|
|
207
260
|
const qs = new URLSearchParams({ sessionId });
|
|
208
261
|
if (target?.targetType && target?.targetId) {
|
|
209
262
|
qs.set('targetType', target.targetType);
|
|
210
263
|
qs.set('targetId', target.targetId);
|
|
211
264
|
}
|
|
212
|
-
|
|
265
|
+
if (op)
|
|
266
|
+
qs.set('op', op);
|
|
267
|
+
return this.request('DELETE', `/v1/principals/${encodeURIComponent(agentId)}/session-visibility?${qs}`, undefined, this.tenantHeaders(opts?.tenantId));
|
|
213
268
|
}
|
|
214
269
|
jobControl(sourceId) {
|
|
215
270
|
return this.request('GET', `/v1/jobs/control?sourceId=${encodeURIComponent(sourceId)}`, undefined, undefined, { read: true });
|
|
@@ -245,6 +300,8 @@ export class ClientKnowledgeGrounding {
|
|
|
245
300
|
return (await this.client.autoGround(opts.agentId, query, {
|
|
246
301
|
...(opts.sessionId != null ? { sessionId: opts.sessionId } : {}),
|
|
247
302
|
...(opts.limit != null ? { limit: opts.limit } : {}),
|
|
303
|
+
// 租户断言(T3):run 归属域上行,服务端按 token 域包含校验
|
|
304
|
+
...(opts.tenantId != null ? { tenantId: opts.tenantId } : {}),
|
|
248
305
|
...(recall ? { recall } : {}),
|
|
249
306
|
}));
|
|
250
307
|
}
|
|
@@ -12,6 +12,7 @@ export interface KnowledgeDatabaseOptions {
|
|
|
12
12
|
/** 尝试加载 sqlite-vec(默认 true;失败则 JS 余弦);可指定扩展路径 */
|
|
13
13
|
sqliteVec?: boolean | {
|
|
14
14
|
extensionPath?: string;
|
|
15
|
+
require?: boolean;
|
|
15
16
|
};
|
|
16
17
|
/**
|
|
17
18
|
* 只读打开(Query Worker / Engine 残留短读):跳过 DDL/升列,不抢写锁。
|
|
@@ -41,6 +42,13 @@ export declare class KnowledgeDatabase {
|
|
|
41
42
|
* (含 tenant/gateway),否则 ON CONFLICT(tenant_id, project_key) 会炸。
|
|
42
43
|
*/
|
|
43
44
|
private rebuildLegacyProjectTables;
|
|
45
|
+
/**
|
|
46
|
+
* knowledge_agent_hidden → knowledge_agent_visibility(T3b:hidden 泛化为 include|exclude,
|
|
47
|
+
* 挂载=include、隐藏=exclude,(agent, source) 单 op 无优先级歧义)。旧行以 op='exclude' 迁入。
|
|
48
|
+
* 幂等(评审 MIN):hidden 在即迁——两表并存(回滚→再升级)也必收编,不因 visibility 已在而静默丢行。
|
|
49
|
+
* 必须在 backfillLegacyAgentColumns 之后跑(legacy 行的 local_agent_id 已回填)。
|
|
50
|
+
*/
|
|
51
|
+
private migrateAgentHiddenToVisibility;
|
|
44
52
|
/** 旧列 agent_id / session_id → local_* 回填(best-effort) */
|
|
45
53
|
private backfillLegacyAgentColumns;
|
|
46
54
|
/**
|
|
@@ -62,4 +70,12 @@ export declare class KnowledgeDatabase {
|
|
|
62
70
|
get raw(): DatabaseSync;
|
|
63
71
|
close(): void;
|
|
64
72
|
stats(): Record<string, number>;
|
|
73
|
+
/**
|
|
74
|
+
* 本视图口径统计(principalStats,评审 m7 拍板 B):只对给定的可见源集合计数。
|
|
75
|
+
* 与 {@link stats} 的全库口径有意区分——全库口径属运维面(doctor/ops),等运维功能
|
|
76
|
+
* 落地后再回接;现阶段 UI 一律本视图,避免「统计有数、列表为空」式误读。
|
|
77
|
+
*
|
|
78
|
+
* @param ids 可见源 id 集合(空集 = 全 0)
|
|
79
|
+
*/
|
|
80
|
+
statsForSourceIds(ids: string[]): Record<string, number>;
|
|
65
81
|
}
|
|
@@ -51,14 +51,9 @@ export class KnowledgeDatabase {
|
|
|
51
51
|
kdb.createTables();
|
|
52
52
|
}
|
|
53
53
|
if (vecOpt !== false) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
kdb._sqliteVec = await tryLoadSqliteVec(db, extensionPath);
|
|
58
|
-
}
|
|
59
|
-
catch {
|
|
60
|
-
kdb._sqliteVec = false;
|
|
61
|
-
}
|
|
54
|
+
const { loadSqliteVecOrDegrade } = await import('../memory/sqlite/sqlite-vec.js');
|
|
55
|
+
// KnowledgeDatabase 缺省 = 尝试加载(见 KnowledgeDatabaseOptions.sqliteVec 注释);agent-db 缺省不同,由各自类归一
|
|
56
|
+
kdb._sqliteVec = await loadSqliteVecOrDegrade(db, vecOpt ?? true, 'knowledge.db');
|
|
62
57
|
}
|
|
63
58
|
return kdb;
|
|
64
59
|
}
|
|
@@ -89,6 +84,9 @@ export class KnowledgeDatabase {
|
|
|
89
84
|
updated_at INTEGER NOT NULL,
|
|
90
85
|
PRIMARY KEY (tenant_id, project_key)
|
|
91
86
|
);
|
|
87
|
+
-- 跨域闸按 project_key 单列解析项目行;主键前缀用不上(评审 m6)
|
|
88
|
+
CREATE INDEX IF NOT EXISTS idx_knowledge_projects_key
|
|
89
|
+
ON knowledge_projects(project_key);
|
|
92
90
|
|
|
93
91
|
CREATE TABLE IF NOT EXISTS knowledge_project_agents (
|
|
94
92
|
tenant_id TEXT NOT NULL DEFAULT 'default',
|
|
@@ -99,11 +97,12 @@ export class KnowledgeDatabase {
|
|
|
99
97
|
PRIMARY KEY (tenant_id, gateway_id, local_agent_id, project_key)
|
|
100
98
|
);
|
|
101
99
|
|
|
102
|
-
CREATE TABLE IF NOT EXISTS
|
|
100
|
+
CREATE TABLE IF NOT EXISTS knowledge_agent_visibility (
|
|
103
101
|
tenant_id TEXT NOT NULL DEFAULT 'default',
|
|
104
102
|
gateway_id TEXT NOT NULL DEFAULT 'default',
|
|
105
103
|
local_agent_id TEXT NOT NULL,
|
|
106
104
|
source_id TEXT NOT NULL,
|
|
105
|
+
op TEXT NOT NULL CHECK (op IN ('include', 'exclude')),
|
|
107
106
|
created_at INTEGER NOT NULL,
|
|
108
107
|
PRIMARY KEY (tenant_id, gateway_id, local_agent_id, source_id)
|
|
109
108
|
);
|
|
@@ -307,6 +306,8 @@ export class KnowledgeDatabase {
|
|
|
307
306
|
this.rebuildLegacyProjectTables();
|
|
308
307
|
// 3) 旧 project_agents/hidden/session:local_agent_id 空则从 agent_id 回填
|
|
309
308
|
this.backfillLegacyAgentColumns();
|
|
309
|
+
// T3b:hidden → visibility(include|exclude)必须在 backfill 之后(local_agent_id 已回填)
|
|
310
|
+
this.migrateAgentHiddenToVisibility();
|
|
310
311
|
this.ensureEmbeddingSchema();
|
|
311
312
|
}
|
|
312
313
|
/**
|
|
@@ -397,40 +398,54 @@ export class KnowledgeDatabase {
|
|
|
397
398
|
throw err;
|
|
398
399
|
}
|
|
399
400
|
}
|
|
400
|
-
//
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
401
|
+
// knowledge_agent_visibility(T3b)转换挪至 upgradeLegacySchema 末尾(backfill 之后)——
|
|
402
|
+
// 旧库 local_agent_id 由 backfillLegacyAgentColumns 先回填,此处不再拷空值
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* knowledge_agent_hidden → knowledge_agent_visibility(T3b:hidden 泛化为 include|exclude,
|
|
406
|
+
* 挂载=include、隐藏=exclude,(agent, source) 单 op 无优先级歧义)。旧行以 op='exclude' 迁入。
|
|
407
|
+
* 幂等(评审 MIN):hidden 在即迁——两表并存(回滚→再升级)也必收编,不因 visibility 已在而静默丢行。
|
|
408
|
+
* 必须在 backfillLegacyAgentColumns 之后跑(legacy 行的 local_agent_id 已回填)。
|
|
409
|
+
*/
|
|
410
|
+
migrateAgentHiddenToVisibility() {
|
|
411
|
+
const tableSql = (name) => {
|
|
412
|
+
const row = this.db
|
|
413
|
+
.prepare(`SELECT sql FROM sqlite_master WHERE type = 'table' AND name = ?`)
|
|
414
|
+
.get(name);
|
|
415
|
+
return row?.sql ?? null;
|
|
416
|
+
};
|
|
417
|
+
if (!tableSql('knowledge_agent_hidden'))
|
|
418
|
+
return;
|
|
419
|
+
this.db.exec('BEGIN');
|
|
420
|
+
try {
|
|
421
|
+
this.db.exec(`
|
|
422
|
+
CREATE TABLE IF NOT EXISTS knowledge_agent_visibility (
|
|
423
|
+
tenant_id TEXT NOT NULL DEFAULT 'default',
|
|
424
|
+
gateway_id TEXT NOT NULL DEFAULT 'default',
|
|
425
|
+
local_agent_id TEXT NOT NULL DEFAULT '',
|
|
426
|
+
source_id TEXT NOT NULL,
|
|
427
|
+
op TEXT NOT NULL CHECK (op IN ('include', 'exclude')),
|
|
428
|
+
created_at INTEGER NOT NULL,
|
|
429
|
+
PRIMARY KEY (tenant_id, gateway_id, local_agent_id, source_id)
|
|
430
|
+
);
|
|
431
|
+
INSERT OR IGNORE INTO knowledge_agent_visibility
|
|
432
|
+
(tenant_id, gateway_id, local_agent_id, source_id, op, created_at)
|
|
433
|
+
SELECT COALESCE(tenant_id, 'default'), COALESCE(gateway_id, 'default'),
|
|
434
|
+
COALESCE(NULLIF(local_agent_id, ''), ''),
|
|
435
|
+
source_id, 'exclude', created_at
|
|
436
|
+
FROM knowledge_agent_hidden;
|
|
437
|
+
DROP TABLE knowledge_agent_hidden;
|
|
438
|
+
`);
|
|
439
|
+
this.db.exec('COMMIT');
|
|
440
|
+
}
|
|
441
|
+
catch (err) {
|
|
404
442
|
try {
|
|
405
|
-
this.db.exec(
|
|
406
|
-
CREATE TABLE knowledge_agent_hidden_v2 (
|
|
407
|
-
tenant_id TEXT NOT NULL DEFAULT 'default',
|
|
408
|
-
gateway_id TEXT NOT NULL DEFAULT 'default',
|
|
409
|
-
local_agent_id TEXT NOT NULL DEFAULT '',
|
|
410
|
-
source_id TEXT NOT NULL,
|
|
411
|
-
created_at INTEGER NOT NULL,
|
|
412
|
-
PRIMARY KEY (tenant_id, gateway_id, local_agent_id, source_id)
|
|
413
|
-
);
|
|
414
|
-
INSERT OR IGNORE INTO knowledge_agent_hidden_v2
|
|
415
|
-
(tenant_id, gateway_id, local_agent_id, source_id, created_at)
|
|
416
|
-
SELECT COALESCE(tenant_id,'default'), COALESCE(gateway_id,'default'),
|
|
417
|
-
COALESCE(NULLIF(local_agent_id,''), COALESCE(agent_id,'')),
|
|
418
|
-
source_id, created_at
|
|
419
|
-
FROM knowledge_agent_hidden;
|
|
420
|
-
DROP TABLE knowledge_agent_hidden;
|
|
421
|
-
ALTER TABLE knowledge_agent_hidden_v2 RENAME TO knowledge_agent_hidden;
|
|
422
|
-
`);
|
|
423
|
-
this.db.exec('COMMIT');
|
|
443
|
+
this.db.exec('ROLLBACK');
|
|
424
444
|
}
|
|
425
|
-
catch
|
|
426
|
-
|
|
427
|
-
this.db.exec('ROLLBACK');
|
|
428
|
-
}
|
|
429
|
-
catch {
|
|
430
|
-
/* ignore */
|
|
431
|
-
}
|
|
432
|
-
throw err;
|
|
445
|
+
catch {
|
|
446
|
+
/* ignore */
|
|
433
447
|
}
|
|
448
|
+
throw err;
|
|
434
449
|
}
|
|
435
450
|
}
|
|
436
451
|
/** 旧列 agent_id / session_id → local_* 回填(best-effort) */
|
|
@@ -594,7 +609,8 @@ export class KnowledgeDatabase {
|
|
|
594
609
|
memberships: 'SELECT COUNT(*) AS count FROM knowledge_memberships',
|
|
595
610
|
files: 'SELECT COUNT(*) AS count FROM knowledge_files',
|
|
596
611
|
projectAgents: 'SELECT COUNT(*) AS count FROM knowledge_project_agents',
|
|
597
|
-
agentHidden:
|
|
612
|
+
agentHidden: "SELECT COUNT(*) AS count FROM knowledge_agent_visibility WHERE op = 'exclude'",
|
|
613
|
+
agentMounted: "SELECT COUNT(*) AS count FROM knowledge_agent_visibility WHERE op = 'include'",
|
|
598
614
|
sessionVisibility: 'SELECT COUNT(*) AS count FROM knowledge_session_visibility',
|
|
599
615
|
chunks: 'SELECT COUNT(*) AS count FROM knowledge_chunks',
|
|
600
616
|
ftsChunks: 'SELECT COUNT(*) AS count FROM knowledge_chunks_fts',
|
|
@@ -620,4 +636,54 @@ export class KnowledgeDatabase {
|
|
|
620
636
|
result.sqliteVec = this._sqliteVec ? 1 : 0;
|
|
621
637
|
return result;
|
|
622
638
|
}
|
|
639
|
+
/**
|
|
640
|
+
* 本视图口径统计(principalStats,评审 m7 拍板 B):只对给定的可见源集合计数。
|
|
641
|
+
* 与 {@link stats} 的全库口径有意区分——全库口径属运维面(doctor/ops),等运维功能
|
|
642
|
+
* 落地后再回接;现阶段 UI 一律本视图,避免「统计有数、列表为空」式误读。
|
|
643
|
+
*
|
|
644
|
+
* @param ids 可见源 id 集合(空集 = 全 0)
|
|
645
|
+
*/
|
|
646
|
+
statsForSourceIds(ids) {
|
|
647
|
+
const result = {
|
|
648
|
+
sources: ids.length,
|
|
649
|
+
memberships: 0,
|
|
650
|
+
files: 0,
|
|
651
|
+
chunks: 0,
|
|
652
|
+
ftsChunks: 0,
|
|
653
|
+
embeddableChunks: 0,
|
|
654
|
+
embeddings: 0,
|
|
655
|
+
hits: 0,
|
|
656
|
+
jobsQueued: 0,
|
|
657
|
+
jobsRunning: 0,
|
|
658
|
+
sqliteVec: this._sqliteVec ? 1 : 0,
|
|
659
|
+
};
|
|
660
|
+
if (ids.length === 0)
|
|
661
|
+
return result;
|
|
662
|
+
// 可见源数远低于 SQLite 变量上限(32766);超限 = fail-loud(禁静默截断计数)
|
|
663
|
+
const ph = ids.map(() => '?').join(',');
|
|
664
|
+
const run = (sql) => {
|
|
665
|
+
const row = this.db.prepare(sql).get(...ids);
|
|
666
|
+
return row.count;
|
|
667
|
+
};
|
|
668
|
+
result.memberships = run(`SELECT COUNT(*) AS count FROM knowledge_memberships WHERE source_id IN (${ph})`);
|
|
669
|
+
// File 本位(v2.1):文件无 source 归属列,经 membership 逻辑认领;同一文件被多源认领时按 distinct 计
|
|
670
|
+
result.files = run(`SELECT COUNT(DISTINCT f.id) AS count FROM knowledge_files f
|
|
671
|
+
JOIN knowledge_memberships m ON m.file_id = f.id WHERE m.source_id IN (${ph})`);
|
|
672
|
+
result.chunks = run(`SELECT COUNT(DISTINCT c.id) AS count FROM knowledge_chunks c
|
|
673
|
+
JOIN knowledge_memberships m ON m.file_id = c.file_id WHERE m.source_id IN (${ph})`);
|
|
674
|
+
result.ftsChunks = run(`SELECT COUNT(DISTINCT t.chunk_id) AS count FROM knowledge_chunks_fts t
|
|
675
|
+
JOIN knowledge_chunks c ON c.id = t.chunk_id
|
|
676
|
+
JOIN knowledge_memberships m ON m.file_id = c.file_id WHERE m.source_id IN (${ph})`);
|
|
677
|
+
result.embeddableChunks = run(`SELECT COUNT(DISTINCT c.id) AS count FROM knowledge_chunks c
|
|
678
|
+
JOIN knowledge_files f ON f.id = c.file_id
|
|
679
|
+
JOIN knowledge_memberships m ON m.file_id = c.file_id
|
|
680
|
+
WHERE m.source_id IN (${ph}) AND (f.adapter_id IS NULL OR f.adapter_id NOT IN ('code-tree'))`);
|
|
681
|
+
result.embeddings = run(`SELECT COUNT(DISTINCT e.chunk_id) AS count FROM knowledge_chunk_embeddings e
|
|
682
|
+
JOIN knowledge_chunks c ON c.id = e.chunk_id
|
|
683
|
+
JOIN knowledge_memberships m ON m.file_id = c.file_id WHERE m.source_id IN (${ph})`);
|
|
684
|
+
result.hits = run(`SELECT COUNT(*) AS count FROM knowledge_hits WHERE source_id IN (${ph})`);
|
|
685
|
+
result.jobsQueued = run(`SELECT COUNT(*) AS count FROM knowledge_jobs WHERE status = 'queued' AND source_id IN (${ph})`);
|
|
686
|
+
result.jobsRunning = run(`SELECT COUNT(*) AS count FROM knowledge_jobs WHERE status = 'running' AND source_id IN (${ph})`);
|
|
687
|
+
return result;
|
|
688
|
+
}
|
|
623
689
|
}
|
|
@@ -154,15 +154,14 @@ async function main() {
|
|
|
154
154
|
// :memory: 无法跨连接共享 → 写/读同连接
|
|
155
155
|
writeDb = await KnowledgeDatabase.create({
|
|
156
156
|
dbPath: boot.dbPath,
|
|
157
|
-
sqliteVec: boot.
|
|
158
|
-
? { extensionPath: boot.sqliteVecExtensionPath }
|
|
159
|
-
: true,
|
|
157
|
+
sqliteVec: boot.sqliteVec ?? true,
|
|
160
158
|
});
|
|
161
159
|
write = new LocalKnowledgeWriteService({
|
|
162
160
|
db: writeDb,
|
|
163
161
|
documentConfig: boot.documentConfig ?? null,
|
|
164
162
|
embeddingProvider: embeddingProvider,
|
|
165
163
|
embed: boot.embed ?? null,
|
|
164
|
+
allowPublic: boot.allowPublic ?? false,
|
|
166
165
|
ingest: boot.ingest ?? null,
|
|
167
166
|
autoDescribe: boot.autoDescribe,
|
|
168
167
|
});
|
|
@@ -188,7 +187,8 @@ async function main() {
|
|
|
188
187
|
write = await WorkerWriteService.start({
|
|
189
188
|
dbPath: boot.dbPath,
|
|
190
189
|
documentConfig: boot.documentConfig ?? null,
|
|
191
|
-
|
|
190
|
+
sqliteVec: boot.sqliteVec,
|
|
191
|
+
allowPublic: boot.allowPublic,
|
|
192
192
|
embeddingModels: boot.testEmbeddingStub ? null : (boot.embeddingModels ?? null),
|
|
193
193
|
embed: boot.embed ?? null,
|
|
194
194
|
ingest: boot.ingest ?? null,
|
|
@@ -200,9 +200,7 @@ async function main() {
|
|
|
200
200
|
dbPath: boot.dbPath,
|
|
201
201
|
readOnly: true,
|
|
202
202
|
skipMigrate: true,
|
|
203
|
-
sqliteVec: boot.
|
|
204
|
-
? { extensionPath: boot.sqliteVecExtensionPath }
|
|
205
|
-
: true,
|
|
203
|
+
sqliteVec: boot.sqliteVec ?? true,
|
|
206
204
|
});
|
|
207
205
|
const sources = new KnowledgeSourceStore(readDb);
|
|
208
206
|
const index = new KnowledgeIndexStore(readDb);
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 不是 ContextLayer(不进 system 预算);产物进 RunScope + 消息插槽。
|
|
5
5
|
*/
|
|
6
|
-
import { getTextContent } from '@octopi-agent/core/types.js';
|
|
6
|
+
import { getTextContent, DEFAULT_TENANT_ID } from '@octopi-agent/core/types.js';
|
|
7
|
+
import { getRunScope } from '../run/run-scope.js';
|
|
7
8
|
/** 消息 metadata.source 标记 */
|
|
8
9
|
export const KNOWLEDGE_GROUNDING_SOURCE = 'knowledgeGrounding';
|
|
9
10
|
/** 真实用户发言判定(载体插槽不是用户发言,query 不采信;谓词见 context/layer-types) */
|
|
@@ -132,6 +133,8 @@ export class GroundingAssembler {
|
|
|
132
133
|
const decision = await this.retriever.autoGround(query, {
|
|
133
134
|
agentId: input.agentId ?? 'default',
|
|
134
135
|
sessionId: input.sessionId,
|
|
136
|
+
// 归属锚(T3,与检索工具同源):turn 级 grounding 注入同样不得跨租户取材
|
|
137
|
+
tenantId: getRunScope()?.principal?.tenantId ?? DEFAULT_TENANT_ID,
|
|
135
138
|
limit: Math.max(8, this.maxChunks * 2),
|
|
136
139
|
});
|
|
137
140
|
if (decision.mode === 'none') {
|
|
@@ -27,6 +27,14 @@ export interface AuthContext {
|
|
|
27
27
|
gatewayId: string;
|
|
28
28
|
agentId?: string;
|
|
29
29
|
sessionId?: string;
|
|
30
|
+
/** 是否携带显式租户断言(x-octopi-tenant);归属打标与越域拒区分「显式」与「回落」 */
|
|
31
|
+
claimed?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* 写路径归属域(arch/multi-tenancy.md §6 / T3a 收尾护栏):
|
|
34
|
+
* 读口 tenantId 可为 platform(broker 全量视图),但写必须落具体租户域——
|
|
35
|
+
* 无 claim 时显式降级 DEFAULT 域,绝不把用户资产写进 platform 共享面。
|
|
36
|
+
*/
|
|
37
|
+
writeTenantId?: string;
|
|
30
38
|
}
|
|
31
39
|
export declare class KnowledgeHttpApp {
|
|
32
40
|
private readonly opts;
|
|
@@ -35,7 +43,14 @@ export declare class KnowledgeHttpApp {
|
|
|
35
43
|
constructor(opts: KnowledgeServiceOptions);
|
|
36
44
|
private get write();
|
|
37
45
|
private query;
|
|
46
|
+
/** 写身份:归属域(platform token 无 claim → DEFAULT,不写 platform 共享面) */
|
|
38
47
|
private identityOf;
|
|
48
|
+
/**
|
|
49
|
+
* 读身份:claim-or-token 域(v0.113.10 语义「读口不受影响」)——platform broker 无 claim
|
|
50
|
+
* = 运维面全量;claim 在场 = 租户收口。写域不得代劳读域(T3b 自审修复:曾共用 identityOf,
|
|
51
|
+
* 把运维读误收窄到 DEFAULT)。
|
|
52
|
+
*/
|
|
53
|
+
private readIdentityOf;
|
|
39
54
|
private route;
|
|
40
55
|
private registerRoutes;
|
|
41
56
|
/** 拉起 ingest 运行时(Service 入口调用一次;实现落在 Writer) */
|