@octopi-agent/engine 0.98.4 → 0.102.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config-schema/agent.d.ts +35 -5
- package/dist/config-schema/agent.js +24 -4
- package/dist/config-schema/context.d.ts +6 -36
- package/dist/config-schema/context.js +4 -28
- package/dist/config-schema/engine.d.ts +57 -160
- package/dist/config-schema/engine.js +1 -5
- package/dist/config-schema/governance.d.ts +8 -1
- package/dist/config-schema/governance.js +8 -1
- package/dist/config-schema/models.d.ts +2 -8
- package/dist/config-schema/models.js +0 -2
- package/dist/config-schema/run.d.ts +2 -2
- package/dist/config-schema/run.js +2 -2
- package/dist/config-schema/shared.d.ts +0 -3
- package/dist/config-schema/shared.js +0 -2
- package/dist/config-schema/substrate.d.ts +14 -88
- package/dist/config-schema/substrate.js +22 -107
- package/dist/config.d.ts +45 -113
- package/dist/config.js +8 -2
- package/dist/harness/activation/dispatcher.js +7 -0
- package/dist/harness/activation/inbox.d.ts +3 -3
- package/dist/harness/activation/inbox.js +3 -3
- package/dist/harness/activation/runtime.js +13 -5
- package/dist/harness/activation/types.d.ts +2 -2
- package/dist/harness/agent/builder.d.ts +24 -3
- package/dist/harness/agent/builder.js +131 -27
- package/dist/harness/agent/config-bridge.js +9 -2
- package/dist/harness/agent/config-integrity.js +19 -2
- package/dist/harness/agent/wire-agent-builder.d.ts +11 -3
- package/dist/harness/agent/wire-agent-builder.js +26 -7
- package/dist/harness/capabilities/document/factory.d.ts +5 -0
- package/dist/harness/capabilities/document/factory.js +1 -0
- package/dist/harness/capabilities/document/port.js +6 -3
- package/dist/harness/capabilities/document/types.d.ts +5 -0
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.d.ts +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +2 -2
- package/dist/harness/collaboration/autonomous-subsystem/sense/input-builder.js +4 -4
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.d.ts +2 -2
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.js +2 -2
- package/dist/harness/collaboration/autonomous-subsystem/signal/bus.d.ts +6 -0
- package/dist/harness/collaboration/autonomous-subsystem/signal/bus.js +25 -4
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +3 -3
- package/dist/harness/collaboration/delegation/child-run.d.ts +1 -1
- package/dist/harness/collaboration/delegation/child-run.js +4 -4
- package/dist/harness/collaboration/delegation/index.d.ts +1 -1
- package/dist/harness/collaboration/delegation/index.js +1 -1
- package/dist/harness/collaboration/delegation/notifier.d.ts +6 -1
- package/dist/harness/collaboration/delegation/notifier.js +8 -1
- package/dist/harness/collaboration/delegation/service.d.ts +2 -0
- package/dist/harness/collaboration/delegation/service.js +2 -1
- package/dist/harness/collaboration/delegation/store.d.ts +2 -0
- package/dist/harness/collaboration/delegation/store.js +2 -1
- package/dist/harness/collaboration/delegation/types.d.ts +23 -2
- package/dist/harness/collaboration/delegation/types.js +22 -0
- package/dist/harness/collaboration/delegation/wiring.js +11 -1
- package/dist/harness/context/budget-allocator.d.ts +26 -18
- package/dist/harness/context/budget-allocator.js +67 -32
- package/dist/harness/context/capabilities/compact/engine.d.ts +0 -6
- package/dist/harness/context/capabilities/compact/engine.js +169 -121
- package/dist/harness/context/capabilities/compact/handover.d.ts +5 -3
- package/dist/harness/context/capabilities/compact/handover.js +7 -5
- package/dist/harness/context/capabilities/compact/index.d.ts +5 -1
- package/dist/harness/context/capabilities/compact/index.js +4 -0
- package/dist/harness/context/capabilities/compact/mechanical.d.ts +130 -0
- package/dist/harness/context/capabilities/compact/mechanical.js +268 -0
- package/dist/harness/context/capabilities/compact/messages.d.ts +60 -0
- package/dist/harness/context/capabilities/compact/messages.js +91 -0
- package/dist/harness/context/capabilities/compact/types.d.ts +76 -11
- package/dist/harness/context/capabilities/compact/types.js +11 -1
- package/dist/harness/context/capabilities/compact/view-split.d.ts +36 -0
- package/dist/harness/context/capabilities/compact/view-split.js +72 -0
- package/dist/harness/context/capabilities/summary/port.js +0 -1
- package/dist/harness/context/capabilities/summary/resolver.d.ts +1 -1
- package/dist/harness/context/capabilities/summary/resolver.js +1 -6
- package/dist/harness/context/capabilities/summary/tool-binding.d.ts +1 -1
- package/dist/harness/context/capabilities/summary/types.d.ts +3 -6
- package/dist/harness/context/context-size-ledger.d.ts +143 -0
- package/dist/harness/context/context-size-ledger.js +236 -0
- package/dist/harness/context/default-context-engine.d.ts +195 -119
- package/dist/harness/context/default-context-engine.js +1241 -743
- package/dist/harness/context/index.d.ts +2 -2
- package/dist/harness/context/index.js +1 -1
- package/dist/harness/context/layer-types.d.ts +15 -0
- package/dist/harness/context/layer-types.js +14 -1
- package/dist/harness/context/layers.d.ts +14 -15
- package/dist/harness/context/layers.js +41 -11
- package/dist/harness/context/message-selector.d.ts +10 -8
- package/dist/harness/context/message-selector.js +49 -27
- package/dist/harness/context/summarize.d.ts +2 -2
- package/dist/harness/context/summarize.js +9 -2
- package/dist/harness/context/system-prompt-assembler.d.ts +2 -0
- package/dist/harness/context/system-prompt-assembler.js +2 -1
- package/dist/harness/context/token-constants.d.ts +8 -6
- package/dist/harness/context/token-constants.js +8 -7
- package/dist/harness/context/token-estimate-fns.d.ts +37 -27
- package/dist/harness/context/token-estimate-fns.js +85 -66
- package/dist/harness/context/token-estimator.d.ts +27 -12
- package/dist/harness/context/token-estimator.js +120 -66
- package/dist/harness/context/token-segments.d.ts +88 -0
- package/dist/harness/context/token-segments.js +103 -0
- package/dist/harness/context/tool-result-aging.d.ts +6 -1
- package/dist/harness/context/tool-result-aging.js +16 -5
- package/dist/harness/context/tool-result-body.js +2 -0
- package/dist/harness/context/transform/anchors.d.ts +66 -0
- package/dist/harness/context/transform/anchors.js +125 -0
- package/dist/harness/context/transform/fold.d.ts +56 -0
- package/dist/harness/context/transform/fold.js +135 -0
- package/dist/harness/context/transform/migrate.d.ts +41 -0
- package/dist/harness/context/transform/migrate.js +69 -0
- package/dist/harness/context/transform/types.d.ts +129 -0
- package/dist/harness/context/transform/types.js +19 -0
- package/dist/harness/context/turn-envelope.d.ts +6 -3
- package/dist/harness/context/types.d.ts +127 -117
- package/dist/harness/extension/execution-environment/ops-audit.d.ts +1 -1
- package/dist/harness/extension/execution-environment/resource-limits.d.ts +1 -1
- package/dist/harness/extension/execution-environment/resource-limits.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/commands/index.d.ts +3 -1
- package/dist/harness/extension/plugin-ecosystem/commands/index.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/commands/plugin-bridge.d.ts +12 -1
- package/dist/harness/extension/plugin-ecosystem/commands/plugin-bridge.js +14 -4
- package/dist/harness/extension/plugin-ecosystem/commands/router.d.ts +5 -4
- package/dist/harness/extension/plugin-ecosystem/commands/router.js +23 -14
- package/dist/harness/extension/plugin-ecosystem/commands/types.d.ts +8 -1
- package/dist/harness/extension/plugin-ecosystem/commands/types.js +2 -1
- package/dist/harness/extension/plugin-ecosystem/hooks/adapter.d.ts +54 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/adapter.js +397 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/compaction-integration.d.ts +16 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/compaction-integration.js +66 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/index.d.ts +4 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/index.js +2 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/iteration-snapshot.d.ts +11 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/iteration-snapshot.js +54 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/journal.d.ts +9 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/journal.js +22 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/policy-error.d.ts +12 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/policy-error.js +19 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/run-integration.d.ts +36 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/run-integration.js +338 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/services.d.ts +24 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/services.js +139 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/types.d.ts +229 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/types.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +83 -249
- package/dist/harness/extension/plugin-ecosystem/plugins/api.js +88 -214
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.d.ts +43 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.js +61 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/engine-compatibility.d.ts +4 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/engine-compatibility.js +18 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.d.ts +7 -85
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.js +8 -50
- package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +6 -23
- package/dist/harness/extension/plugin-ecosystem/plugins/index.js +3 -23
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +50 -117
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +316 -285
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +23 -490
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +85 -353
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +41 -223
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +138 -19
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.d.ts +15 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.js +15 -0
- package/dist/harness/extension/plugin-ecosystem/skills/manager.d.ts +6 -1
- package/dist/harness/extension/plugin-ecosystem/skills/manager.js +17 -1
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.d.ts +3 -0
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +46 -21
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +18 -8
- package/dist/harness/extension/plugin-ecosystem/tools/plugin-tool.d.ts +11 -0
- package/dist/harness/extension/plugin-ecosystem/tools/plugin-tool.js +39 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +11 -2
- package/dist/harness/governance/accounting/usage-ledger.d.ts +13 -1
- package/dist/harness/governance/accounting/usage-ledger.js +23 -1
- package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +3 -3
- package/dist/harness/governance/human-in-the-loop/decision-cache.js +2 -2
- package/dist/harness/governance/security/capability-enforcer.js +1 -2
- package/dist/harness/index.d.ts +12 -12
- package/dist/harness/index.js +7 -7
- package/dist/harness/knowledge/boot-config.d.ts +55 -0
- package/dist/harness/knowledge/boot-config.js +50 -0
- package/dist/harness/knowledge/catalog-types.d.ts +2 -0
- package/dist/harness/knowledge/client.d.ts +24 -2
- package/dist/harness/knowledge/client.js +19 -5
- package/dist/harness/knowledge/db.js +5 -0
- package/dist/harness/knowledge/describe-sample.d.ts +23 -0
- package/dist/harness/knowledge/describe-sample.js +58 -0
- package/dist/harness/knowledge/describe.d.ts +8 -0
- package/dist/harness/knowledge/describe.js +18 -2
- package/dist/harness/knowledge/engine-thread.js +6 -0
- package/dist/harness/knowledge/grounding.js +3 -1
- package/dist/harness/knowledge/http-app.js +35 -4
- package/dist/harness/knowledge/http-params.d.ts +18 -0
- package/dist/harness/knowledge/http-params.js +24 -0
- package/dist/harness/knowledge/index.d.ts +2 -0
- package/dist/harness/knowledge/index.js +1 -0
- package/dist/harness/knowledge/knowledge-serve-child.js +3 -0
- package/dist/harness/knowledge/purge.js +5 -2
- package/dist/harness/knowledge/query-service.d.ts +13 -2
- package/dist/harness/knowledge/query-service.js +4 -2
- package/dist/harness/knowledge/query-worker-client.d.ts +9 -1
- package/dist/harness/knowledge/query-worker-client.js +4 -2
- package/dist/harness/knowledge/query-worker.js +4 -2
- package/dist/harness/knowledge/read-http.js +5 -1
- package/dist/harness/knowledge/serve.d.ts +8 -7
- package/dist/harness/knowledge/serve.js +9 -0
- package/dist/harness/knowledge/source-store.js +26 -3
- package/dist/harness/knowledge/start-service-process.d.ts +15 -7
- package/dist/harness/knowledge/start-service-process.js +21 -9
- package/dist/harness/knowledge/types.d.ts +7 -0
- package/dist/harness/knowledge/writer-service.d.ts +37 -9
- package/dist/harness/knowledge/writer-service.js +120 -14
- package/dist/harness/knowledge/writer-worker-client.d.ts +10 -9
- package/dist/harness/knowledge/writer-worker-client.js +20 -2
- package/dist/harness/knowledge/writer-worker.js +9 -1
- package/dist/harness/memory/sqlite/wisdom-store.js +35 -10
- package/dist/harness/memory/types.d.ts +6 -4
- package/dist/harness/memory/wisdom-formation.d.ts +14 -3
- package/dist/harness/memory/wisdom-formation.js +85 -22
- package/dist/harness/memory/wisdom-gates.d.ts +14 -0
- package/dist/harness/memory/wisdom-gates.js +59 -19
- package/dist/harness/memory/wisdom.js +9 -0
- package/dist/harness/observability/observer/hub.js +25 -15
- package/dist/harness/observability/observer/types.d.ts +10 -6
- package/dist/harness/run/agent/agent.d.ts +40 -21
- package/dist/harness/run/agent/agent.js +66 -13
- package/dist/harness/run/agent/index.d.ts +1 -1
- package/dist/harness/run/budget/budget.d.ts +28 -10
- package/dist/harness/run/budget/budget.js +38 -15
- package/dist/harness/run/model/index.d.ts +3 -1
- package/dist/harness/run/model/index.js +2 -1
- package/dist/harness/run/model/resolver.d.ts +4 -1
- package/dist/harness/run/model/resolver.js +36 -2
- package/dist/harness/run/model/run-scope.d.ts +2 -0
- package/dist/harness/run/model/run-scope.js +7 -0
- package/dist/harness/run/model/types.d.ts +22 -5
- package/dist/harness/run/model/types.js +3 -2
- package/dist/harness/run/model/window-truth.d.ts +37 -0
- package/dist/harness/run/model/window-truth.js +39 -0
- package/dist/harness/run/reliability/context-length-feedback.d.ts +77 -0
- package/dist/harness/run/reliability/context-length-feedback.js +128 -0
- package/dist/harness/run/reliability/harness-events.d.ts +3 -3
- package/dist/harness/run/reliability/model-error-policy.js +4 -0
- package/dist/harness/run/reliability/run-agent.d.ts +10 -4
- package/dist/harness/run/reliability/run-agent.js +137 -53
- package/dist/harness/run/reliability/run-metrics-collector.d.ts +19 -8
- package/dist/harness/run/reliability/run-metrics-collector.js +38 -23
- package/dist/harness/run/run-guard/default-run-guard.js +8 -8
- package/dist/harness/run/run-scope.d.ts +37 -4
- package/dist/harness/run/runner.d.ts +44 -29
- package/dist/harness/run/runner.js +320 -102
- package/dist/harness/session/attachments/index.d.ts +1 -0
- package/dist/harness/session/attachments/index.js +1 -0
- package/dist/harness/session/attachments/inject.d.ts +21 -10
- package/dist/harness/session/attachments/inject.js +76 -24
- package/dist/harness/session/attachments/recall-index.d.ts +70 -0
- package/dist/harness/session/attachments/recall-index.js +219 -0
- package/dist/harness/session/attachments/service.d.ts +21 -0
- package/dist/harness/session/attachments/service.js +258 -139
- package/dist/harness/session/attachments/types.d.ts +6 -0
- package/dist/harness/session/transform-store.d.ts +136 -0
- package/dist/harness/session/transform-store.js +302 -0
- package/dist/harness/session/types.d.ts +2 -2
- package/dist/harness/shared/events/agent-event-map.d.ts +46 -13
- package/dist/harness/shared/events/agent-event-map.js +3 -2
- package/dist/harness/shared/events/scenario-events.d.ts +6 -6
- package/dist/harness/shared/types/agent-definition.d.ts +1 -2
- package/dist/index.d.ts +14 -17
- package/dist/index.js +7 -9
- package/dist/integration/observability/metrics.d.ts +6 -6
- package/dist/integration/observability/metrics.js +13 -13
- package/dist/integration/observability/observer-bridge.js +2 -2
- package/dist/integration/observability/trace-collector.d.ts +5 -5
- package/dist/integration/observability/trace-collector.js +34 -35
- package/dist/integration/observability/trace-events.d.ts +3 -3
- package/dist/integration/observability/trace-events.js +3 -3
- package/dist/integration/providers/anthropic.js +14 -1
- package/dist/integration/providers/openai.js +7 -1
- package/dist/integration/providers/usage.d.ts +1 -1
- package/dist/integration/providers/wire-dump.d.ts +1 -1
- package/dist/integration/storage/archive-manager.d.ts +6 -0
- package/dist/integration/storage/archive-manager.js +10 -0
- package/dist/integration/storage/jsonl.d.ts +1 -1
- package/dist/integration/storage/jsonl.js +18 -16
- package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +8 -1
- package/dist/subsystems/wisdom-steward/formation/config.yaml +1 -0
- package/dist/subsystems/wisdom-steward/formation/handler.js +27 -5
- package/package.json +11 -14
- package/dist/harness/context/hybrid-compressor.d.ts +0 -41
- package/dist/harness/context/hybrid-compressor.js +0 -159
- package/dist/harness/context/llm-summarizer.d.ts +0 -46
- package/dist/harness/context/llm-summarizer.js +0 -249
- package/dist/harness/context/smart-router.d.ts +0 -75
- package/dist/harness/context/smart-router.js +0 -118
- package/dist/harness/context/truncate-compressor.d.ts +0 -28
- package/dist/harness/context/truncate-compressor.js +0 -107
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.d.ts +0 -97
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.js +0 -155
- package/dist/harness/extension/plugin-ecosystem/plugins/hooks.d.ts +0 -7
- package/dist/harness/extension/plugin-ecosystem/plugins/hooks.js +0 -7
- package/dist/harness/extension/plugin-ecosystem/plugins/lifecycle.d.ts +0 -86
- package/dist/harness/extension/plugin-ecosystem/plugins/lifecycle.js +0 -139
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* describe 抽样组装 — auto-describe 素材面(Tier 0)
|
|
3
|
+
*
|
|
4
|
+
* 素材组合(拍板 2026-11-02):
|
|
5
|
+
* ① 源元数据 —— 经 `generateKnowledgeDescription` 的 source 参数单独传给端口,不进 sample;
|
|
6
|
+
* ② logical_path 前 20 条(结构辨识);
|
|
7
|
+
* ③ 路径派生 topics(`deriveTopicsFromPaths`,与关键词索引同词面);
|
|
8
|
+
* ④ 文件头 chunk(ordinal=0)抽样——唯一涉正文素材。
|
|
9
|
+
*
|
|
10
|
+
* 密钥形态扫描由调用边界把关:REST 出口(`describeSample`)与端口出口
|
|
11
|
+
* (`generateKnowledgeDescription` 内部)各自扫描;本组装器不重复扫。
|
|
12
|
+
*/
|
|
13
|
+
import type { KnowledgeDatabase } from './db.js';
|
|
14
|
+
/** 抽样总预算(字符):paths + topics + 文件头共享 */
|
|
15
|
+
export declare const DESCRIBE_SAMPLE_MAX_CHARS = 4000;
|
|
16
|
+
/**
|
|
17
|
+
* 组装 describe 抽样文本(②+③+④;① 由调用方单独携带)。
|
|
18
|
+
*
|
|
19
|
+
* @param db - knowledge.db 读句柄
|
|
20
|
+
* @param sourceId - 源 id
|
|
21
|
+
* @returns 抽样文本(≤ DESCRIBE_SAMPLE_MAX_CHARS;无内容时为空串)
|
|
22
|
+
*/
|
|
23
|
+
export declare function assembleDescribeSample(db: KnowledgeDatabase, sourceId: string): string;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* describe 抽样组装 — auto-describe 素材面(Tier 0)
|
|
3
|
+
*
|
|
4
|
+
* 素材组合(拍板 2026-11-02):
|
|
5
|
+
* ① 源元数据 —— 经 `generateKnowledgeDescription` 的 source 参数单独传给端口,不进 sample;
|
|
6
|
+
* ② logical_path 前 20 条(结构辨识);
|
|
7
|
+
* ③ 路径派生 topics(`deriveTopicsFromPaths`,与关键词索引同词面);
|
|
8
|
+
* ④ 文件头 chunk(ordinal=0)抽样——唯一涉正文素材。
|
|
9
|
+
*
|
|
10
|
+
* 密钥形态扫描由调用边界把关:REST 出口(`describeSample`)与端口出口
|
|
11
|
+
* (`generateKnowledgeDescription` 内部)各自扫描;本组装器不重复扫。
|
|
12
|
+
*/
|
|
13
|
+
import { deriveTopicsFromPaths } from './topics.js';
|
|
14
|
+
/** 抽样总预算(字符):paths + topics + 文件头共享 */
|
|
15
|
+
export const DESCRIBE_SAMPLE_MAX_CHARS = 4000;
|
|
16
|
+
/** ② 展示路径条数 */
|
|
17
|
+
const PATH_SAMPLE_LIMIT = 20;
|
|
18
|
+
/** ③ topics 统计的路径上限(词频稳定性,不追求全量) */
|
|
19
|
+
const TOPIC_PATH_LIMIT = 500;
|
|
20
|
+
/** ④ 文件头抽样的文件数 */
|
|
21
|
+
const HEAD_FILE_LIMIT = 8;
|
|
22
|
+
/** ④ 单文件头字符预算 */
|
|
23
|
+
const HEAD_PER_FILE_CHARS = 400;
|
|
24
|
+
/**
|
|
25
|
+
* 组装 describe 抽样文本(②+③+④;① 由调用方单独携带)。
|
|
26
|
+
*
|
|
27
|
+
* @param db - knowledge.db 读句柄
|
|
28
|
+
* @param sourceId - 源 id
|
|
29
|
+
* @returns 抽样文本(≤ DESCRIBE_SAMPLE_MAX_CHARS;无内容时为空串)
|
|
30
|
+
*/
|
|
31
|
+
export function assembleDescribeSample(db, sourceId) {
|
|
32
|
+
const pathRows = db.raw
|
|
33
|
+
.prepare('SELECT logical_path FROM knowledge_memberships WHERE source_id = ? ORDER BY logical_path LIMIT ?')
|
|
34
|
+
.all(sourceId, TOPIC_PATH_LIMIT);
|
|
35
|
+
const allPaths = pathRows.map((r) => r.logical_path);
|
|
36
|
+
if (allPaths.length === 0)
|
|
37
|
+
return '';
|
|
38
|
+
const shownPaths = allPaths.slice(0, PATH_SAMPLE_LIMIT);
|
|
39
|
+
const topics = deriveTopicsFromPaths(allPaths);
|
|
40
|
+
const headRows = db.raw
|
|
41
|
+
.prepare(`SELECT m.logical_path AS path, c.text AS text
|
|
42
|
+
FROM knowledge_memberships m
|
|
43
|
+
JOIN knowledge_chunks c ON c.file_id = m.file_id AND c.ordinal = 0
|
|
44
|
+
WHERE m.source_id = ?
|
|
45
|
+
ORDER BY m.logical_path
|
|
46
|
+
LIMIT ?`)
|
|
47
|
+
.all(sourceId, HEAD_FILE_LIMIT);
|
|
48
|
+
const parts = [];
|
|
49
|
+
parts.push(`paths (${shownPaths.length} of ${allPaths.length}):\n${shownPaths.join('\n')}`);
|
|
50
|
+
if (topics.length > 0) {
|
|
51
|
+
parts.push(`topics: ${topics.join(', ')}`);
|
|
52
|
+
}
|
|
53
|
+
if (headRows.length > 0) {
|
|
54
|
+
const heads = headRows.map((r) => `--- ${r.path}\n${r.text.slice(0, HEAD_PER_FILE_CHARS)}`);
|
|
55
|
+
parts.push(`file heads:\n${heads.join('\n')}`);
|
|
56
|
+
}
|
|
57
|
+
return parts.join('\n\n').slice(0, DESCRIBE_SAMPLE_MAX_CHARS);
|
|
58
|
+
}
|
|
@@ -30,6 +30,14 @@ export interface KnowledgeDescribeResult {
|
|
|
30
30
|
* @param sampleText - 目录树/文件头抽样(调用方提供;P2 起由 ingest 采集)
|
|
31
31
|
*/
|
|
32
32
|
export declare function generateKnowledgeDescription(source: Pick<KnowledgeSource, 'displayName' | 'kind' | 'location'>, sampleText: string, options?: KnowledgeDescribeOptions): Promise<KnowledgeDescribeResult>;
|
|
33
|
+
/**
|
|
34
|
+
* 描述文本归一:折叠空白为单行、剥行首列表标记,钳 300 字符。
|
|
35
|
+
*
|
|
36
|
+
* generatedDescription 会拼进系统提示的 catalog `purpose:` 行(layers.ts);
|
|
37
|
+
* 多行文本可伪造额外 catalog 行/指令行(内容→LLM→system prompt 间接注入面),
|
|
38
|
+
* 必须在**写入侧**归一,而不是只靠渲染侧。
|
|
39
|
+
*/
|
|
40
|
+
export declare function normalizeGeneratedDescription(text: string): string;
|
|
33
41
|
/**
|
|
34
42
|
* 启发式一行描述(不能当正确描述,仅 fallback)
|
|
35
43
|
*
|
|
@@ -15,6 +15,8 @@ export async function generateKnowledgeDescription(source, sampleText, options)
|
|
|
15
15
|
const sample = (sampleText ?? '').slice(0, options?.sampleChars ?? 2000);
|
|
16
16
|
const secretHits = scanSecretShapes(sample);
|
|
17
17
|
if (secretHits.length > 0) {
|
|
18
|
+
// 封锁现场(仅规则名,不泄密):上线后这是唯一可查的触发线索(评审 P2-4)
|
|
19
|
+
console.warn(`[Knowledge] describe sample blocked by secret scan (rules: ${secretHits.join(', ')}); falling back to heuristic`);
|
|
18
20
|
return {
|
|
19
21
|
description: heuristicDescription(source),
|
|
20
22
|
source: 'blocked_secret',
|
|
@@ -38,12 +40,26 @@ export async function generateKnowledgeDescription(source, sampleText, options)
|
|
|
38
40
|
if (!trimmed) {
|
|
39
41
|
return { description: heuristicDescription(source), source: 'heuristic' };
|
|
40
42
|
}
|
|
41
|
-
return { description: trimmed
|
|
43
|
+
return { description: normalizeGeneratedDescription(trimmed), source: 'llm' };
|
|
42
44
|
}
|
|
43
45
|
catch {
|
|
44
46
|
return { description: heuristicDescription(source), source: 'heuristic' };
|
|
45
47
|
}
|
|
46
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* 描述文本归一:折叠空白为单行、剥行首列表标记,钳 300 字符。
|
|
51
|
+
*
|
|
52
|
+
* generatedDescription 会拼进系统提示的 catalog `purpose:` 行(layers.ts);
|
|
53
|
+
* 多行文本可伪造额外 catalog 行/指令行(内容→LLM→system prompt 间接注入面),
|
|
54
|
+
* 必须在**写入侧**归一,而不是只靠渲染侧。
|
|
55
|
+
*/
|
|
56
|
+
export function normalizeGeneratedDescription(text) {
|
|
57
|
+
return text
|
|
58
|
+
.replace(/\s+/g, ' ')
|
|
59
|
+
.replace(/^[\-*#>·•]+\s*/, '')
|
|
60
|
+
.trim()
|
|
61
|
+
.slice(0, 300);
|
|
62
|
+
}
|
|
47
63
|
/**
|
|
48
64
|
* 启发式一行描述(不能当正确描述,仅 fallback)
|
|
49
65
|
*
|
|
@@ -52,5 +68,5 @@ export async function generateKnowledgeDescription(source, sampleText, options)
|
|
|
52
68
|
export function heuristicDescription(source) {
|
|
53
69
|
const loc = source.location.replace(/[\\/]+$/, '');
|
|
54
70
|
const tail = loc.split(/[\\/]/).filter(Boolean).slice(-2).join('/');
|
|
55
|
-
return `derived: ${source.kind} corpus «${source.displayName}»${tail ? ` (${tail})` : ''}; search when you need what this corpus documents
|
|
71
|
+
return normalizeGeneratedDescription(`derived: ${source.kind} corpus «${source.displayName}»${tail ? ` (${tail})` : ''}; search when you need what this corpus documents`);
|
|
56
72
|
}
|
|
@@ -163,6 +163,8 @@ async function main() {
|
|
|
163
163
|
documentConfig: boot.documentConfig ?? null,
|
|
164
164
|
embeddingProvider: embeddingProvider,
|
|
165
165
|
embed: boot.embed ?? null,
|
|
166
|
+
ingest: boot.ingest ?? null,
|
|
167
|
+
autoDescribe: boot.autoDescribe,
|
|
166
168
|
});
|
|
167
169
|
const sources = new KnowledgeSourceStore(writeDb);
|
|
168
170
|
const index = new KnowledgeIndexStore(writeDb);
|
|
@@ -170,6 +172,7 @@ async function main() {
|
|
|
170
172
|
sourceStore: sources,
|
|
171
173
|
indexStore: index,
|
|
172
174
|
embeddingProvider: embeddingProvider,
|
|
175
|
+
...(boot.retriever ?? {}),
|
|
173
176
|
});
|
|
174
177
|
query = new LocalKnowledgeQueryService({
|
|
175
178
|
db: writeDb,
|
|
@@ -188,6 +191,8 @@ async function main() {
|
|
|
188
191
|
sqliteVecExtensionPath: boot.sqliteVecExtensionPath,
|
|
189
192
|
embeddingModels: boot.testEmbeddingStub ? null : (boot.embeddingModels ?? null),
|
|
190
193
|
embed: boot.embed ?? null,
|
|
194
|
+
ingest: boot.ingest ?? null,
|
|
195
|
+
autoDescribe: boot.autoDescribe,
|
|
191
196
|
testEmbeddingStub: boot.testEmbeddingStub ?? false,
|
|
192
197
|
});
|
|
193
198
|
// 残留写路由上的短读:独立只读连接(WAL)
|
|
@@ -205,6 +210,7 @@ async function main() {
|
|
|
205
210
|
sourceStore: sources,
|
|
206
211
|
indexStore: index,
|
|
207
212
|
embeddingProvider: embeddingProvider,
|
|
213
|
+
...(boot.retriever ?? {}),
|
|
208
214
|
});
|
|
209
215
|
query = new LocalKnowledgeQueryService({
|
|
210
216
|
db: readDb,
|
|
@@ -8,6 +8,7 @@ import { getTextContent } from '@octopi-agent/core/types.js';
|
|
|
8
8
|
export const KNOWLEDGE_GROUNDING_SOURCE = 'knowledgeGrounding';
|
|
9
9
|
/** 真实用户发言判定(载体插槽不是用户发言,query 不采信;谓词见 context/layer-types) */
|
|
10
10
|
import { isHumanSpeech } from '../context/layer-types.js';
|
|
11
|
+
import { estimateTextTokens } from '../context/token-estimate-fns.js';
|
|
11
12
|
/**
|
|
12
13
|
* v1 query:最近 user + 可选前 1–2 条 user;不用 assistant 长文
|
|
13
14
|
*/
|
|
@@ -60,7 +61,8 @@ export function formatKnowledgeGroundingMessage(pack) {
|
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
63
|
function estimateTokens(text) {
|
|
63
|
-
|
|
64
|
+
// P1-c 一把尺:走统一分类查表(旧 ceil(length/4) 对 CJK 高估 4×,装载预算被保守压缩)
|
|
65
|
+
return estimateTextTokens(text);
|
|
64
66
|
}
|
|
65
67
|
/** 最近一条真实用户发言的文本(skipIf 启发式只看本轮;载体插槽不计) */
|
|
66
68
|
function latestUserText(messages) {
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* 纯读 GET 在主线程 `read-http.ts` 直达 Meta/Search,不经本层。
|
|
7
7
|
*/
|
|
8
8
|
import { matchKnowledgeToken } from './http-bridge.js';
|
|
9
|
+
import { promotionThresholdsFromParams } from './http-params.js';
|
|
9
10
|
function json(res, status, payload) {
|
|
10
11
|
const buf = Buffer.from(JSON.stringify(payload), 'utf8');
|
|
11
12
|
res.writeHead(status, {
|
|
@@ -304,9 +305,16 @@ export class KnowledgeHttpApp {
|
|
|
304
305
|
}
|
|
305
306
|
json(res, 200, { ok: true, data: await this.write.resumeSource(params.sid) });
|
|
306
307
|
});
|
|
307
|
-
this.route('POST', '/v1/sources/:sid/describe', async (_req, res, ctx, params) => {
|
|
308
|
+
this.route('POST', '/v1/sources/:sid/describe', async (_req, res, ctx, params, body) => {
|
|
308
309
|
try {
|
|
309
|
-
|
|
310
|
+
// 写入口(B 方案):body {description,source} = gateway 回写 LLM 描述;无 body = 本地启发式生成
|
|
311
|
+
const input = body;
|
|
312
|
+
const data = await this.write.describeSource(this.identityOf(ctx), params.sid, input?.description != null
|
|
313
|
+
? {
|
|
314
|
+
description: String(input.description),
|
|
315
|
+
...(input.source === 'heuristic' ? { source: 'heuristic' } : {}),
|
|
316
|
+
}
|
|
317
|
+
: undefined);
|
|
310
318
|
if (!data)
|
|
311
319
|
return err(res, 404, 'source_not_found', 'source not found');
|
|
312
320
|
json(res, 200, { ok: true, data });
|
|
@@ -317,6 +325,25 @@ export class KnowledgeHttpApp {
|
|
|
317
325
|
}
|
|
318
326
|
}
|
|
319
327
|
});
|
|
328
|
+
this.route('GET', '/v1/sources/:sid/describe-sample', async (req, res, ctx, params) => {
|
|
329
|
+
try {
|
|
330
|
+
const data = await this.write.describeSample(this.identityOf(ctx), params.sid);
|
|
331
|
+
if (!data)
|
|
332
|
+
return err(res, 404, 'source_not_found', 'source not found');
|
|
333
|
+
json(res, 200, { ok: true, data });
|
|
334
|
+
}
|
|
335
|
+
catch (e) {
|
|
336
|
+
if (!mapWriteError(res, e)) {
|
|
337
|
+
err(res, 400, 'bad_request', e instanceof Error ? e.message : String(e));
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
this.route('GET', '/v1/describe-pending', async (req, res, ctx) => {
|
|
342
|
+
json(res, 200, {
|
|
343
|
+
ok: true,
|
|
344
|
+
data: await this.write.listDescribePending(this.identityOf(ctx)),
|
|
345
|
+
});
|
|
346
|
+
});
|
|
320
347
|
this.route('POST', '/v1/jobs/abort', async (_req, res, ctx) => {
|
|
321
348
|
json(res, 200, { ok: true, data: await this.write.abortAllOwned(this.identityOf(ctx)) });
|
|
322
349
|
});
|
|
@@ -575,8 +602,12 @@ export class KnowledgeHttpApp {
|
|
|
575
602
|
return err(res, 404, 'source_not_found', 'source not found');
|
|
576
603
|
json(res, 200, { ok: true, data: detail.jobControl });
|
|
577
604
|
});
|
|
578
|
-
this.route('GET', '/v1/promotion-candidates', async (
|
|
579
|
-
|
|
605
|
+
this.route('GET', '/v1/promotion-candidates', async (req, res) => {
|
|
606
|
+
const url = new URL(req.url ?? '/', 'http://local');
|
|
607
|
+
json(res, 200, {
|
|
608
|
+
ok: true,
|
|
609
|
+
data: await this.query().promotionCandidates(promotionThresholdsFromParams(url.searchParams)),
|
|
610
|
+
});
|
|
580
611
|
});
|
|
581
612
|
}
|
|
582
613
|
/** 拉起 ingest 运行时(Service 入口调用一次;实现落在 Writer) */
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP 查询参数解析(纯函数叶子模块)
|
|
3
|
+
*
|
|
4
|
+
* API 路由(http-app)与纯读路由(read-http)共用;刻意不依赖 query-service
|
|
5
|
+
* 实现,避免 HTTP 层反向依赖服务层。
|
|
6
|
+
*
|
|
7
|
+
* @module harness/knowledge/http-params
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* 解析 promotion 候选阈值查询参数(非法值忽略,回落 hit-log 默认 3/10)。
|
|
11
|
+
*
|
|
12
|
+
* @param searchParams - URL 查询参数(`minSessions` / `minHits`)
|
|
13
|
+
* @returns 有效阈值;未配置或非法的键不出现
|
|
14
|
+
*/
|
|
15
|
+
export declare function promotionThresholdsFromParams(searchParams: URLSearchParams): {
|
|
16
|
+
minSessions?: number;
|
|
17
|
+
minHits?: number;
|
|
18
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP 查询参数解析(纯函数叶子模块)
|
|
3
|
+
*
|
|
4
|
+
* API 路由(http-app)与纯读路由(read-http)共用;刻意不依赖 query-service
|
|
5
|
+
* 实现,避免 HTTP 层反向依赖服务层。
|
|
6
|
+
*
|
|
7
|
+
* @module harness/knowledge/http-params
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* 解析 promotion 候选阈值查询参数(非法值忽略,回落 hit-log 默认 3/10)。
|
|
11
|
+
*
|
|
12
|
+
* @param searchParams - URL 查询参数(`minSessions` / `minHits`)
|
|
13
|
+
* @returns 有效阈值;未配置或非法的键不出现
|
|
14
|
+
*/
|
|
15
|
+
export function promotionThresholdsFromParams(searchParams) {
|
|
16
|
+
const out = {};
|
|
17
|
+
const minSessions = Number(searchParams.get('minSessions'));
|
|
18
|
+
if (Number.isFinite(minSessions) && minSessions > 0)
|
|
19
|
+
out.minSessions = Math.floor(minSessions);
|
|
20
|
+
const minHits = Number(searchParams.get('minHits'));
|
|
21
|
+
if (Number.isFinite(minHits) && minHits > 0)
|
|
22
|
+
out.minHits = Math.floor(minHits);
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
@@ -28,6 +28,8 @@ export { EmbedRunner } from './embed-runner.js';
|
|
|
28
28
|
export type { EmbedSecretPolicy } from './embed-runner.js';
|
|
29
29
|
export { DEFAULT_KNOWLEDGE_FILE_LIMITS, classifyFileKind, decideBySize, formatMaxBytes, isRetryableSkipReason, parseTimeoutForSize, resolveKnowledgeFileLimits, } from './file-limits.js';
|
|
30
30
|
export type { KnowledgeFileKind, KnowledgeFileLimits, KnowledgeFileLimitsInput, OversizePolicy, } from './file-limits.js';
|
|
31
|
+
export { knowledgeTuningFromConfig } from './boot-config.js';
|
|
32
|
+
export type { KnowledgeBootTuning, KnowledgeBootEmbed, KnowledgeBootIngest, KnowledgeBootRetriever, } from './boot-config.js';
|
|
31
33
|
export { LocalFsFetcher, UrlFetcher, } from './fetchers.js';
|
|
32
34
|
export type { SourceFetcher, DiscoveredDocRef, DiscoverResult, VirtualDocument, } from './fetchers.js';
|
|
33
35
|
export { ConnectorRegistry, RestConnector } from './connectors.js';
|
|
@@ -18,6 +18,7 @@ export { KnowledgeJobControl } from './job-control.js';
|
|
|
18
18
|
export { JobQueue } from './job-queue.js';
|
|
19
19
|
export { EmbedRunner } from './embed-runner.js';
|
|
20
20
|
export { DEFAULT_KNOWLEDGE_FILE_LIMITS, classifyFileKind, decideBySize, formatMaxBytes, isRetryableSkipReason, parseTimeoutForSize, resolveKnowledgeFileLimits, } from './file-limits.js';
|
|
21
|
+
export { knowledgeTuningFromConfig } from './boot-config.js';
|
|
21
22
|
export { LocalFsFetcher, UrlFetcher, } from './fetchers.js';
|
|
22
23
|
export { ConnectorRegistry, RestConnector } from './connectors.js';
|
|
23
24
|
export { ConnectorFetcher } from './connector-fetcher.js';
|
|
@@ -48,6 +48,9 @@ async function main() {
|
|
|
48
48
|
documentConfig: boot.documentConfig ?? null,
|
|
49
49
|
embeddingModels: boot.embeddingModels ?? null,
|
|
50
50
|
embed: boot.embed ?? null,
|
|
51
|
+
ingest: boot.ingest ?? null,
|
|
52
|
+
retriever: boot.retriever ?? null,
|
|
53
|
+
autoDescribe: boot.autoDescribe,
|
|
51
54
|
...(boot.sqliteVecExtensionPath
|
|
52
55
|
? { sqliteVecExtensionPath: boot.sqliteVecExtensionPath }
|
|
53
56
|
: {}),
|
|
@@ -47,8 +47,11 @@ export class KnowledgePurger {
|
|
|
47
47
|
return false;
|
|
48
48
|
if (!source.generatedDescription)
|
|
49
49
|
return false;
|
|
50
|
-
// 人工 description
|
|
51
|
-
this.sources.update(sourceId, {
|
|
50
|
+
// 人工 description 权威不动;只清自动描述(含生成方归因),待重生成
|
|
51
|
+
this.sources.update(sourceId, {
|
|
52
|
+
generatedDescription: null,
|
|
53
|
+
generatedDescriptionSource: null,
|
|
54
|
+
});
|
|
52
55
|
return true;
|
|
53
56
|
}
|
|
54
57
|
}
|
|
@@ -14,6 +14,7 @@ import type { KnowledgeSource } from './types.js';
|
|
|
14
14
|
import type { KnowledgeCatalogItem } from './catalog-types.js';
|
|
15
15
|
import { type KnowledgeJobControlState } from './job-control-state.js';
|
|
16
16
|
import { type PromotionCandidate } from './hit-log.js';
|
|
17
|
+
import type { KnowledgeBootRetriever, KnowledgeBootEmbed } from './boot-config.js';
|
|
17
18
|
export interface QueryIdentity {
|
|
18
19
|
tenantId?: string;
|
|
19
20
|
gatewayId?: string;
|
|
@@ -166,7 +167,10 @@ export interface KnowledgeQueryService {
|
|
|
166
167
|
isSourceOwner(sourceId: string, gatewayId: string): Promise<boolean>;
|
|
167
168
|
ready(): Promise<ReadySnapshot>;
|
|
168
169
|
listJobs(query: ListJobsQuery): Promise<Array<Record<string, unknown>>>;
|
|
169
|
-
promotionCandidates(
|
|
170
|
+
promotionCandidates(opts?: {
|
|
171
|
+
minSessions?: number;
|
|
172
|
+
minHits?: number;
|
|
173
|
+
}): Promise<PromotionCandidate[]>;
|
|
170
174
|
dispose(): Promise<void> | void;
|
|
171
175
|
}
|
|
172
176
|
export interface LocalQueryDeps {
|
|
@@ -243,7 +247,10 @@ export declare class LocalKnowledgeQueryService implements KnowledgeQueryService
|
|
|
243
247
|
isSourceOwner(sourceId: string, gatewayId: string): Promise<boolean>;
|
|
244
248
|
ready(): Promise<ReadySnapshot>;
|
|
245
249
|
listJobs(query: ListJobsQuery): Promise<Array<Record<string, unknown>>>;
|
|
246
|
-
promotionCandidates(
|
|
250
|
+
promotionCandidates(opts?: {
|
|
251
|
+
minSessions?: number;
|
|
252
|
+
minHits?: number;
|
|
253
|
+
}): Promise<PromotionCandidate[]>;
|
|
247
254
|
dispose(): void;
|
|
248
255
|
private gatewayVisible;
|
|
249
256
|
}
|
|
@@ -269,4 +276,8 @@ export declare function createKnowledgeQueryService(opts: {
|
|
|
269
276
|
/** Worker 角色:meta=列表/控制面,search=检索/catalog,all=单 Worker 全量 */
|
|
270
277
|
role?: QueryWorkerRole;
|
|
271
278
|
queryTimeoutMs?: number;
|
|
279
|
+
/** 向量化开关(embed.enabled=false 时检索侧不建 embedding provider,不外发 query embed) */
|
|
280
|
+
embed?: KnowledgeBootEmbed | null;
|
|
281
|
+
/** 检索调参(透传进 Worker 的 KnowledgeRetriever) */
|
|
282
|
+
retriever?: KnowledgeBootRetriever | null;
|
|
272
283
|
}): Promise<KnowledgeQueryService>;
|
|
@@ -290,8 +290,8 @@ export class LocalKnowledgeQueryService {
|
|
|
290
290
|
.prepare(`SELECT * FROM knowledge_jobs WHERE ${where.join(' AND ')} ORDER BY created_at DESC LIMIT ?`)
|
|
291
291
|
.all(...args, limit);
|
|
292
292
|
}
|
|
293
|
-
async promotionCandidates() {
|
|
294
|
-
return new KnowledgeHitLog(this.deps.db).promotionCandidates();
|
|
293
|
+
async promotionCandidates(opts) {
|
|
294
|
+
return new KnowledgeHitLog(this.deps.db).promotionCandidates(opts);
|
|
295
295
|
}
|
|
296
296
|
dispose() {
|
|
297
297
|
/* 只读;连接由调用方持有 */
|
|
@@ -322,5 +322,7 @@ export async function createKnowledgeQueryService(opts) {
|
|
|
322
322
|
sqliteVecExtensionPath: opts.sqliteVecExtensionPath,
|
|
323
323
|
role: opts.role ?? 'all',
|
|
324
324
|
queryTimeoutMs: opts.queryTimeoutMs,
|
|
325
|
+
embed: opts.embed ?? null,
|
|
326
|
+
retriever: opts.retriever ?? null,
|
|
325
327
|
});
|
|
326
328
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { KnowledgeQueryService, SearchQuery, AutoGroundQuery, ListSourcesQuery, QueryIdentity, PrincipalStats, ReadChunkResult, SourceStatsBundle, SourceDetail, ListJobsQuery, ReadySnapshot, QueryWorkerRole } from './query-service.js';
|
|
2
2
|
import type { PromotionCandidate } from './hit-log.js';
|
|
3
|
+
import type { KnowledgeBootEmbed, KnowledgeBootRetriever } from './boot-config.js';
|
|
3
4
|
import type { HybridSearchResult, AutoGroundDecision } from './retriever.js';
|
|
4
5
|
import type { KnowledgeSource } from './types.js';
|
|
5
6
|
import type { KnowledgeCatalogItem } from './catalog-types.js';
|
|
@@ -29,6 +30,10 @@ export declare class WorkerQueryService implements KnowledgeQueryService {
|
|
|
29
30
|
providers?: Record<string, unknown>;
|
|
30
31
|
embedding?: unknown;
|
|
31
32
|
} | null;
|
|
33
|
+
/** 向量化开关(embed.enabled=false 时不建 embedding provider) */
|
|
34
|
+
embed?: KnowledgeBootEmbed | null;
|
|
35
|
+
/** 检索调参(透传进 Worker 的 KnowledgeRetriever) */
|
|
36
|
+
retriever?: KnowledgeBootRetriever | null;
|
|
32
37
|
}): Promise<WorkerQueryService>;
|
|
33
38
|
private failAll;
|
|
34
39
|
private call;
|
|
@@ -91,6 +96,9 @@ export declare class WorkerQueryService implements KnowledgeQueryService {
|
|
|
91
96
|
isSourceOwner(sourceId: string, gatewayId: string): Promise<boolean>;
|
|
92
97
|
ready(): Promise<ReadySnapshot>;
|
|
93
98
|
listJobs(query: ListJobsQuery): Promise<Array<Record<string, unknown>>>;
|
|
94
|
-
promotionCandidates(
|
|
99
|
+
promotionCandidates(opts?: {
|
|
100
|
+
minSessions?: number;
|
|
101
|
+
minHits?: number;
|
|
102
|
+
}): Promise<PromotionCandidate[]>;
|
|
95
103
|
dispose(): Promise<void>;
|
|
96
104
|
}
|
|
@@ -75,6 +75,8 @@ export class WorkerQueryService {
|
|
|
75
75
|
sqliteVecExtensionPath: opts.sqliteVecExtensionPath,
|
|
76
76
|
embeddingModels: opts.embeddingModels ?? null,
|
|
77
77
|
role: opts.role ?? 'all',
|
|
78
|
+
embed: opts.embed ?? null,
|
|
79
|
+
retriever: opts.retriever ?? null,
|
|
78
80
|
},
|
|
79
81
|
});
|
|
80
82
|
const client = new WorkerQueryService(worker, opts.queryTimeoutMs ?? 15_000);
|
|
@@ -187,8 +189,8 @@ export class WorkerQueryService {
|
|
|
187
189
|
async listJobs(query) {
|
|
188
190
|
return (await this.call({ method: 'listJobs', query }));
|
|
189
191
|
}
|
|
190
|
-
async promotionCandidates() {
|
|
191
|
-
return (await this.call({ method: 'promotionCandidates' }));
|
|
192
|
+
async promotionCandidates(opts) {
|
|
193
|
+
return (await this.call({ method: 'promotionCandidates', opts }));
|
|
192
194
|
}
|
|
193
195
|
async dispose() {
|
|
194
196
|
if (this.disposed)
|
|
@@ -60,7 +60,8 @@ async function main() {
|
|
|
60
60
|
: true,
|
|
61
61
|
});
|
|
62
62
|
let embeddingProvider = null;
|
|
63
|
-
|
|
63
|
+
// embed.enabled=false:纯关键词索引——检索侧不建 provider,query 不外发 embed(与写侧 resolveEmbedding 同判)
|
|
64
|
+
if (boot.embeddingModels && boot.embed?.enabled !== false) {
|
|
64
65
|
const { resolveEmbeddingRuntime } = await import('../memory/sqlite/embedding-from-models.js');
|
|
65
66
|
const runtime = resolveEmbeddingRuntime(boot.embeddingModels);
|
|
66
67
|
embeddingProvider = runtime?.provider ?? null;
|
|
@@ -71,6 +72,7 @@ async function main() {
|
|
|
71
72
|
sourceStore: sources,
|
|
72
73
|
indexStore: index,
|
|
73
74
|
embeddingProvider: embeddingProvider,
|
|
75
|
+
...(boot.retriever ?? {}),
|
|
74
76
|
});
|
|
75
77
|
const svc = new LocalKnowledgeQueryService({
|
|
76
78
|
db,
|
|
@@ -162,7 +164,7 @@ async function main() {
|
|
|
162
164
|
data = await svc.listJobs(msg.query);
|
|
163
165
|
break;
|
|
164
166
|
case 'promotionCandidates':
|
|
165
|
-
data = await svc.promotionCandidates();
|
|
167
|
+
data = await svc.promotionCandidates(msg.opts);
|
|
166
168
|
break;
|
|
167
169
|
default:
|
|
168
170
|
throw new Error(`unknown_query_method`);
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* ingest 占死写线程时列表/详情仍应答。
|
|
6
6
|
*/
|
|
7
7
|
import { matchKnowledgeToken } from './http-bridge.js';
|
|
8
|
+
import { promotionThresholdsFromParams } from './http-params.js';
|
|
8
9
|
function json(res, status, payload) {
|
|
9
10
|
const buf = Buffer.from(JSON.stringify(payload), 'utf8');
|
|
10
11
|
res.writeHead(status, {
|
|
@@ -337,7 +338,10 @@ export async function handleKnowledgeReadHttp(deps, req, res, auth) {
|
|
|
337
338
|
return true;
|
|
338
339
|
}
|
|
339
340
|
if (path === '/v1/promotion-candidates') {
|
|
340
|
-
json(res, 200, {
|
|
341
|
+
json(res, 200, {
|
|
342
|
+
ok: true,
|
|
343
|
+
data: await meta.promotionCandidates(promotionThresholdsFromParams(url.searchParams)),
|
|
344
|
+
});
|
|
341
345
|
return true;
|
|
342
346
|
}
|
|
343
347
|
err(res, 404, 'not_found', `no route ${method} ${path}`);
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { type Server } from 'node:http';
|
|
14
14
|
import type { KnowledgeServiceToken } from './http-app.js';
|
|
15
|
+
import type { KnowledgeBootEmbed, KnowledgeBootIngest, KnowledgeBootRetriever } from './boot-config.js';
|
|
15
16
|
export interface KnowledgeServeOptions {
|
|
16
17
|
dbPath: string;
|
|
17
18
|
host?: string;
|
|
@@ -21,13 +22,13 @@ export interface KnowledgeServeOptions {
|
|
|
21
22
|
documentConfig?: import('../capabilities/document/factory.js').DocumentCapabilityConfig | null;
|
|
22
23
|
/** 测试 stub(闭包无法进 Worker);生产用 embeddingModels */
|
|
23
24
|
testEmbeddingStub?: boolean;
|
|
24
|
-
embed?:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
embed?: KnowledgeBootEmbed | null;
|
|
26
|
+
/** Ingest 调参(knowledge.load / index.queue / index.files) */
|
|
27
|
+
ingest?: KnowledgeBootIngest | null;
|
|
28
|
+
/** 检索调参(knowledge.keywordWeight / autoInject / hint / index.hybridKeyword) */
|
|
29
|
+
retriever?: KnowledgeBootRetriever | null;
|
|
30
|
+
/** false = 索引稳定后不自动生成 generatedDescription(knowledge.catalog.autoDescribe) */
|
|
31
|
+
autoDescribe?: boolean;
|
|
31
32
|
sqliteVecExtensionPath?: string;
|
|
32
33
|
embeddingModels?: {
|
|
33
34
|
providers?: Record<string, unknown>;
|
|
@@ -35,6 +35,8 @@ async function startQueryWorker(opts) {
|
|
|
35
35
|
mode: 'worker',
|
|
36
36
|
role: opts.role,
|
|
37
37
|
embeddingModels: opts.embeddingModels ?? null,
|
|
38
|
+
embed: opts.embed ?? null,
|
|
39
|
+
retriever: opts.retriever ?? null,
|
|
38
40
|
...(opts.sqliteVecExtensionPath
|
|
39
41
|
? { sqliteVecExtensionPath: opts.sqliteVecExtensionPath }
|
|
40
42
|
: {}),
|
|
@@ -59,6 +61,9 @@ export async function startKnowledgeService(opts) {
|
|
|
59
61
|
sqliteVecExtensionPath: opts.sqliteVecExtensionPath,
|
|
60
62
|
embeddingModels: opts.embeddingModels ?? null,
|
|
61
63
|
embed: opts.embed ?? null,
|
|
64
|
+
ingest: opts.ingest ?? null,
|
|
65
|
+
retriever: opts.retriever ?? null,
|
|
66
|
+
autoDescribe: opts.autoDescribe,
|
|
62
67
|
testEmbeddingStub: opts.testEmbeddingStub ?? false,
|
|
63
68
|
// 文件库:纯读在主线程 Meta/Search;Engine 只做写编排 + 残留短读
|
|
64
69
|
skipQueryWorker: useSplitQuery,
|
|
@@ -100,12 +105,16 @@ export async function startKnowledgeService(opts) {
|
|
|
100
105
|
role: 'meta',
|
|
101
106
|
sqliteVecExtensionPath: opts.sqliteVecExtensionPath,
|
|
102
107
|
embeddingModels: opts.embeddingModels,
|
|
108
|
+
embed: opts.embed,
|
|
109
|
+
retriever: opts.retriever,
|
|
103
110
|
}),
|
|
104
111
|
startQueryWorker({
|
|
105
112
|
dbPath: opts.dbPath,
|
|
106
113
|
role: 'search',
|
|
107
114
|
sqliteVecExtensionPath: opts.sqliteVecExtensionPath,
|
|
108
115
|
embeddingModels: opts.embeddingModels,
|
|
116
|
+
embed: opts.embed,
|
|
117
|
+
retriever: opts.retriever,
|
|
109
118
|
}),
|
|
110
119
|
]);
|
|
111
120
|
}
|