dsh-data-domain-knowledge 0.1.0-alpha.9 → 0.1.1-alpha.2
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/README.md +118 -567
- package/cordis.patch.yml +5 -418
- package/eval/README.md +19 -8
- package/eval/benchmark-extraction-format.mjs +20 -0
- package/eval/evaluate-retrieval.mjs +17 -8
- package/eval/queries.example.jsonl +1 -0
- package/lib/client.js +4181 -3239
- package/lib/contract-envelope.d.ts +91 -0
- package/lib/contract-envelope.js +106 -0
- package/lib/contract-layout.d.ts +130 -0
- package/lib/contract-layout.js +138 -0
- package/lib/contract-refs.d.ts +39 -0
- package/lib/contract-refs.js +9 -0
- package/lib/contract-version.d.ts +311 -0
- package/lib/contract-version.js +270 -0
- package/lib/contract-wire.d.ts +147 -0
- package/lib/contract-wire.js +99 -0
- package/lib/contracts.d.ts +12 -0
- package/lib/contracts.js +12 -0
- package/lib/doc-page.js +2 -2
- package/lib/pages.js +3329 -1296
- package/lib/types/agent-behavior-rules.d.ts +10 -0
- package/lib/types/agent-behavior-rules.d.ts.map +1 -0
- package/lib/types/agent-behavior-rules.js +28 -0
- package/lib/types/agent-behavior-rules.js.map +1 -0
- package/lib/types/axis-registry.d.ts +37 -5
- package/lib/types/axis-registry.d.ts.map +1 -1
- package/lib/types/axis-registry.js +234 -26
- package/lib/types/axis-registry.js.map +1 -1
- package/lib/types/card-organize.d.ts +27 -12
- package/lib/types/card-organize.d.ts.map +1 -1
- package/lib/types/card-organize.js +58 -73
- package/lib/types/card-organize.js.map +1 -1
- package/lib/types/compiler/embedding-identity.d.ts +3 -0
- package/lib/types/compiler/embedding-identity.d.ts.map +1 -0
- package/lib/types/compiler/embedding-identity.js +24 -0
- package/lib/types/compiler/embedding-identity.js.map +1 -0
- package/lib/types/compiler/snapshot.d.ts +16 -0
- package/lib/types/compiler/snapshot.d.ts.map +1 -0
- package/lib/types/compiler/snapshot.js +2 -0
- package/lib/types/compiler/snapshot.js.map +1 -0
- package/lib/types/config-schema.d.ts +6 -3
- package/lib/types/config-schema.d.ts.map +1 -1
- package/lib/types/config-schema.js +6 -2
- package/lib/types/config-schema.js.map +1 -1
- package/lib/types/convert/host.d.ts +6 -5
- package/lib/types/convert/host.d.ts.map +1 -1
- package/lib/types/convert/host.js +58 -18
- package/lib/types/convert/host.js.map +1 -1
- package/lib/types/convert/ingest.d.ts +10 -1
- package/lib/types/convert/ingest.d.ts.map +1 -1
- package/lib/types/convert/ingest.js +68 -9
- package/lib/types/convert/ingest.js.map +1 -1
- package/lib/types/derive-contract.d.ts +3 -0
- package/lib/types/derive-contract.d.ts.map +1 -0
- package/lib/types/derive-contract.js +15 -0
- package/lib/types/derive-contract.js.map +1 -0
- package/lib/types/diagnosis/cards.d.ts +7 -3
- package/lib/types/diagnosis/cards.d.ts.map +1 -1
- package/lib/types/diagnosis/cards.js +13 -8
- package/lib/types/diagnosis/cards.js.map +1 -1
- package/lib/types/diagnosis/run.d.ts +4 -13
- package/lib/types/diagnosis/run.d.ts.map +1 -1
- package/lib/types/diagnosis/run.js +26 -16
- package/lib/types/diagnosis/run.js.map +1 -1
- package/lib/types/diagnosis/schema.js +2 -2
- package/lib/types/diagnosis/schema.js.map +1 -1
- package/lib/types/diagnosis/seed-source.d.ts +1 -1
- package/lib/types/diagnosis/seed-source.d.ts.map +1 -1
- package/lib/types/diagnosis/seed-source.js +5 -4
- package/lib/types/diagnosis/seed-source.js.map +1 -1
- package/lib/types/diagnosis/seed.d.ts +4 -4
- package/lib/types/diagnosis/seed.d.ts.map +1 -1
- package/lib/types/diagnosis/seed.js +6 -8
- package/lib/types/diagnosis/seed.js.map +1 -1
- package/lib/types/diagnosis/store.d.ts +24 -18
- package/lib/types/diagnosis/store.d.ts.map +1 -1
- package/lib/types/diagnosis/store.js +130 -65
- package/lib/types/diagnosis/store.js.map +1 -1
- package/lib/types/diagnosis/types.d.ts +47 -15
- package/lib/types/diagnosis/types.d.ts.map +1 -1
- package/lib/types/diagnosis/types.js.map +1 -1
- package/lib/types/environment/dsh-python.d.ts +77 -0
- package/lib/types/environment/dsh-python.d.ts.map +1 -0
- package/lib/types/environment/dsh-python.js +139 -0
- package/lib/types/environment/dsh-python.js.map +1 -0
- package/lib/types/environment/install.d.ts +15 -0
- package/lib/types/environment/install.d.ts.map +1 -0
- package/lib/types/environment/install.js +297 -0
- package/lib/types/environment/install.js.map +1 -0
- package/lib/types/environment/manifest.d.ts +208 -0
- package/lib/types/environment/manifest.d.ts.map +1 -0
- package/lib/types/environment/manifest.js +26 -0
- package/lib/types/environment/manifest.js.map +1 -0
- package/lib/types/environment/model-catalog.d.ts +223 -0
- package/lib/types/environment/model-catalog.d.ts.map +1 -0
- package/lib/types/environment/model-catalog.js +129 -0
- package/lib/types/environment/model-catalog.js.map +1 -0
- package/lib/types/environment/process.d.ts +10 -0
- package/lib/types/environment/process.d.ts.map +1 -0
- package/lib/types/environment/process.js +54 -0
- package/lib/types/environment/process.js.map +1 -0
- package/lib/types/environment/selection.d.ts +9 -0
- package/lib/types/environment/selection.d.ts.map +1 -0
- package/lib/types/environment/selection.js +29 -0
- package/lib/types/environment/selection.js.map +1 -0
- package/lib/types/environment/service.d.ts +64 -0
- package/lib/types/environment/service.d.ts.map +1 -0
- package/lib/types/environment/service.js +424 -0
- package/lib/types/environment/service.js.map +1 -0
- package/lib/types/environment/types.d.ts +56 -0
- package/lib/types/environment/types.d.ts.map +1 -0
- package/lib/types/environment/types.js +2 -0
- package/lib/types/environment/types.js.map +1 -0
- package/lib/types/events.d.ts +76 -0
- package/lib/types/events.d.ts.map +1 -0
- package/lib/types/events.js +52 -0
- package/lib/types/events.js.map +1 -0
- package/lib/types/extract-contract.d.ts +3 -0
- package/lib/types/extract-contract.d.ts.map +1 -0
- package/lib/types/extract-contract.js +41 -0
- package/lib/types/extract-contract.js.map +1 -0
- package/lib/types/extract-model.d.ts +5 -0
- package/lib/types/extract-model.d.ts.map +1 -1
- package/lib/types/extract-model.js.map +1 -1
- package/lib/types/extract-table-contract.d.ts +3 -0
- package/lib/types/extract-table-contract.d.ts.map +1 -0
- package/lib/types/extract-table-contract.js +27 -0
- package/lib/types/extract-table-contract.js.map +1 -0
- package/lib/types/extract-table.d.ts +8 -0
- package/lib/types/extract-table.d.ts.map +1 -0
- package/lib/types/extract-table.js +158 -0
- package/lib/types/extract-table.js.map +1 -0
- package/lib/types/extraction-runs.d.ts +30 -6
- package/lib/types/extraction-runs.d.ts.map +1 -1
- package/lib/types/extraction-runs.js +69 -8
- package/lib/types/extraction-runs.js.map +1 -1
- package/lib/types/fs-atomic.d.ts +0 -7
- package/lib/types/fs-atomic.d.ts.map +1 -1
- package/lib/types/fs-atomic.js +17 -2
- package/lib/types/fs-atomic.js.map +1 -1
- package/lib/types/images.d.ts +26 -0
- package/lib/types/images.d.ts.map +1 -0
- package/lib/types/images.js +196 -0
- package/lib/types/images.js.map +1 -0
- package/lib/types/index.d.ts +2 -2
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js +598 -209
- package/lib/types/index.js.map +1 -1
- package/lib/types/intent/engine.d.ts +12 -4
- package/lib/types/intent/engine.d.ts.map +1 -1
- package/lib/types/intent/engine.js +43 -5
- package/lib/types/intent/engine.js.map +1 -1
- package/lib/types/intent/host.d.ts +5 -8
- package/lib/types/intent/host.d.ts.map +1 -1
- package/lib/types/intent/host.js +56 -11
- package/lib/types/intent/host.js.map +1 -1
- package/lib/types/intent/scope.d.ts +25 -0
- package/lib/types/intent/scope.d.ts.map +1 -0
- package/lib/types/intent/scope.js +116 -0
- package/lib/types/intent/scope.js.map +1 -0
- package/lib/types/intent/tools.d.ts +24 -20
- package/lib/types/intent/tools.d.ts.map +1 -1
- package/lib/types/intent/tools.js +65 -23
- package/lib/types/intent/tools.js.map +1 -1
- package/lib/types/intent/types.d.ts +11 -4
- package/lib/types/intent/types.d.ts.map +1 -1
- package/lib/types/knowledge-bases.d.ts +11 -5
- package/lib/types/knowledge-bases.d.ts.map +1 -1
- package/lib/types/knowledge-bases.js +52 -20
- package/lib/types/knowledge-bases.js.map +1 -1
- package/lib/types/knowledge-contract.d.ts +32 -0
- package/lib/types/knowledge-contract.d.ts.map +1 -0
- package/lib/types/knowledge-contract.js +116 -0
- package/lib/types/knowledge-contract.js.map +1 -0
- package/lib/types/knowledge.d.ts +31 -9
- package/lib/types/knowledge.d.ts.map +1 -1
- package/lib/types/knowledge.js +137 -60
- package/lib/types/knowledge.js.map +1 -1
- package/lib/types/layout.d.ts +10 -29
- package/lib/types/layout.d.ts.map +1 -1
- package/lib/types/layout.js +17 -36
- package/lib/types/layout.js.map +1 -1
- package/lib/types/materialize-snapshot.d.ts +49 -0
- package/lib/types/materialize-snapshot.d.ts.map +1 -0
- package/lib/types/materialize-snapshot.js +2 -0
- package/lib/types/materialize-snapshot.js.map +1 -0
- package/lib/types/migrate.d.ts +11 -0
- package/lib/types/migrate.d.ts.map +1 -1
- package/lib/types/migrate.js +83 -2
- package/lib/types/migrate.js.map +1 -1
- package/lib/types/model-text.d.ts +58 -1
- package/lib/types/model-text.d.ts.map +1 -1
- package/lib/types/model-text.js +85 -30
- package/lib/types/model-text.js.map +1 -1
- package/lib/types/oplog.d.ts.map +1 -1
- package/lib/types/oplog.js +7 -0
- package/lib/types/oplog.js.map +1 -1
- package/lib/types/organize-contract.d.ts +18 -0
- package/lib/types/organize-contract.d.ts.map +1 -0
- package/lib/types/organize-contract.js +82 -0
- package/lib/types/organize-contract.js.map +1 -0
- package/lib/types/pipeline/engine.d.ts +66 -0
- package/lib/types/pipeline/engine.d.ts.map +1 -0
- package/lib/types/pipeline/engine.js +352 -0
- package/lib/types/pipeline/engine.js.map +1 -0
- package/lib/types/pipeline/store.d.ts +73 -0
- package/lib/types/pipeline/store.d.ts.map +1 -0
- package/lib/types/pipeline/store.js +143 -0
- package/lib/types/pipeline/store.js.map +1 -0
- package/lib/types/pipeline/types.d.ts +102 -0
- package/lib/types/pipeline/types.d.ts.map +1 -0
- package/lib/types/pipeline/types.js +5 -0
- package/lib/types/pipeline/types.js.map +1 -0
- package/lib/types/present.d.ts +2 -0
- package/lib/types/present.d.ts.map +1 -1
- package/lib/types/present.js +9 -4
- package/lib/types/present.js.map +1 -1
- package/lib/types/preset-ids.d.ts +4 -0
- package/lib/types/preset-ids.d.ts.map +1 -0
- package/lib/types/preset-ids.js +6 -0
- package/lib/types/preset-ids.js.map +1 -0
- package/lib/types/query-analysis.d.ts +13 -1
- package/lib/types/query-analysis.d.ts.map +1 -1
- package/lib/types/query-analysis.js +62 -6
- package/lib/types/query-analysis.js.map +1 -1
- package/lib/types/recall-rank.d.ts +3 -3
- package/lib/types/recall-rank.d.ts.map +1 -1
- package/lib/types/recall-rank.js +4 -4
- package/lib/types/recall-rank.js.map +1 -1
- package/lib/types/retention.d.ts +39 -0
- package/lib/types/retention.d.ts.map +1 -0
- package/lib/types/retention.js +42 -0
- package/lib/types/retention.js.map +1 -0
- package/lib/types/retrieval/vector-index.d.ts +32 -0
- package/lib/types/retrieval/vector-index.d.ts.map +1 -0
- package/lib/types/retrieval/vector-index.js +15 -0
- package/lib/types/retrieval/vector-index.js.map +1 -0
- package/lib/types/retrieval/visibility.d.ts +6 -0
- package/lib/types/retrieval/visibility.d.ts.map +1 -0
- package/lib/types/retrieval/visibility.js +11 -0
- package/lib/types/retrieval/visibility.js.map +1 -0
- package/lib/types/runtime.d.ts +272 -27
- package/lib/types/runtime.d.ts.map +1 -1
- package/lib/types/runtime.js +2751 -537
- package/lib/types/runtime.js.map +1 -1
- package/lib/types/settings-schema.d.ts +17 -15
- package/lib/types/settings-schema.d.ts.map +1 -1
- package/lib/types/settings-schema.js +50 -47
- package/lib/types/settings-schema.js.map +1 -1
- package/lib/types/settings-volatile.d.ts +4 -4
- package/lib/types/settings-volatile.js +4 -4
- package/lib/types/source-evidence.d.ts +14 -0
- package/lib/types/source-evidence.d.ts.map +1 -0
- package/lib/types/source-evidence.js +36 -0
- package/lib/types/source-evidence.js.map +1 -0
- package/lib/types/store/axis-references.d.ts +5 -0
- package/lib/types/store/axis-references.d.ts.map +1 -0
- package/lib/types/store/axis-references.js +106 -0
- package/lib/types/store/axis-references.js.map +1 -0
- package/lib/types/store/derived.d.ts +12 -1
- package/lib/types/store/derived.d.ts.map +1 -1
- package/lib/types/store/derived.js +71 -12
- package/lib/types/store/derived.js.map +1 -1
- package/lib/types/store/knowledge-db.d.ts +31 -1
- package/lib/types/store/knowledge-db.d.ts.map +1 -1
- package/lib/types/store/knowledge-db.js +252 -18
- package/lib/types/store/knowledge-db.js.map +1 -1
- package/lib/types/store/migrate.d.ts.map +1 -1
- package/lib/types/store/migrate.js +17 -6
- package/lib/types/store/migrate.js.map +1 -1
- package/lib/types/trajectory-types.d.ts +172 -0
- package/lib/types/trajectory-types.d.ts.map +1 -0
- package/lib/types/trajectory-types.js +36 -0
- package/lib/types/trajectory-types.js.map +1 -0
- package/lib/types/types.d.ts +59 -27
- package/lib/types/types.d.ts.map +1 -1
- package/lib/types/types.js +6 -15
- package/lib/types/types.js.map +1 -1
- package/lib/types/wiki-finalize.d.ts +16 -0
- package/lib/types/wiki-finalize.d.ts.map +1 -1
- package/lib/types/wiki-finalize.js +26 -0
- package/lib/types/wiki-finalize.js.map +1 -1
- package/lib/types/wiki-materialize.d.ts +4 -0
- package/lib/types/wiki-materialize.d.ts.map +1 -1
- package/lib/types/wiki-materialize.js +21 -7
- package/lib/types/wiki-materialize.js.map +1 -1
- package/lib/types/wiki-trial-types.d.ts +87 -0
- package/lib/types/wiki-trial-types.d.ts.map +1 -1
- package/lib/types/wiki-trial-types.js +0 -16
- package/lib/types/wiki-trial-types.js.map +1 -1
- package/lib/types/wiki-trial.d.ts +40 -16
- package/lib/types/wiki-trial.d.ts.map +1 -1
- package/lib/types/wiki-trial.js +337 -224
- package/lib/types/wiki-trial.js.map +1 -1
- package/package.json +29 -20
- package/python/prepare-models.py +19 -0
- package/python/requirements.txt +8 -6
- package/scripts/doctor.mjs +13 -19
- package/scripts/environment.mjs +29 -0
- package/scripts/setup-embedding.sh +15 -5
- package/src/agent-behavior-rules.ts +37 -0
- package/src/axis-registry.ts +234 -27
- package/src/card-organize.ts +69 -75
- package/src/client/AgentBehaviorRulesCard.tsx +65 -0
- package/src/client/AttributionEventGuide.tsx +41 -39
- package/src/client/AxisRegistrySection.tsx +204 -164
- package/src/client/CompileDialogs.tsx +44 -29
- package/src/client/DeleteDocumentDialog.tsx +36 -5
- package/src/client/DirectoryPicker.tsx +0 -10
- package/src/client/EnvironmentSetup.tsx +243 -0
- package/src/client/ExpansionGraph.tsx +13 -7
- package/src/client/ExtractionTasksPage.tsx +578 -0
- package/src/client/GuideArchitectureCanvas.tsx +470 -0
- package/src/client/ImportFilesDialog.tsx +2 -13
- package/src/client/IntentLogic.tsx +2 -2
- package/src/client/IntentTab.tsx +118 -47
- package/src/client/KnowledgeBaseTab.tsx +277 -197
- package/src/client/KnowledgeLayerSection.tsx +24 -6
- package/src/client/KnowledgePanel.tsx +58 -93
- package/src/client/KnowledgeSettingsDrawer.tsx +90 -0
- package/src/client/ListPager.tsx +15 -5
- package/src/client/MaterializeTrajectoryView.tsx +124 -0
- package/src/client/NodeSettings.tsx +210 -89
- package/src/client/NormalizeTrajectoryView.tsx +136 -0
- package/src/client/PipelineNotice.tsx +26 -0
- package/src/client/PreviewSections.tsx +118 -51
- package/src/client/RecallPanel.tsx +89 -85
- package/src/client/TabGuide.tsx +159 -184
- package/src/client/TrialReportView.tsx +391 -214
- package/src/client/TypeDefinitionDrawer.tsx +150 -23
- package/src/client/WikiCardPreview.tsx +62 -16
- package/src/client/WikiFlowPanel.tsx +4 -4
- package/src/client/arch/NodeLogicPanel.tsx +3 -4
- package/src/client/arch/model.ts +6 -9
- package/src/client/architecture.tsx +23 -33
- package/src/client/attribution/AttributionGraph.tsx +10 -6
- package/src/client/attribution/AttributionTab.tsx +136 -84
- package/src/client/attribution/CaseView.tsx +3 -1
- package/src/client/attribution/EventView.tsx +108 -0
- package/src/client/attribution/RunView.tsx +2 -2
- package/src/client/attribution/StageChrome.tsx +34 -3
- package/src/client/attribution/ViewSwitch.tsx +20 -5
- package/src/client/attribution/graph-options.ts +47 -39
- package/src/client/attribution/model.ts +17 -10
- package/src/client/config-scope.ts +3 -3
- package/src/client/graph/palette.ts +165 -0
- package/src/client/index.ts +49 -42
- package/src/client/pages.css +459 -135
- package/src/client/pages.tsx +37 -9
- package/src/client/problem-domains.ts +1 -1
- package/src/client/session-remote.ts +9 -0
- package/src/client/styles.css +205 -62
- package/src/client/wiki-trial.ts +44 -3
- package/src/compiler/embedding-identity.ts +21 -0
- package/src/compiler/snapshot.ts +17 -0
- package/src/config-schema.ts +8 -3
- package/src/convert/host.ts +56 -21
- package/src/convert/ingest.ts +74 -10
- package/src/derive-contract.ts +14 -0
- package/src/diagnosis/cards.ts +13 -8
- package/src/diagnosis/run.ts +27 -17
- package/src/diagnosis/schema.ts +2 -2
- package/src/diagnosis/seed-source.ts +5 -4
- package/src/diagnosis/seed.ts +6 -8
- package/src/diagnosis/store.ts +138 -69
- package/src/diagnosis/types.ts +34 -15
- package/src/environment/dsh-python.ts +156 -0
- package/src/environment/install.ts +244 -0
- package/src/environment/manifest.ts +28 -0
- package/src/environment/model-catalog.ts +147 -0
- package/src/environment/process.ts +54 -0
- package/src/environment/selection.ts +29 -0
- package/src/environment/service.ts +348 -0
- package/src/environment/types.ts +45 -0
- package/src/events.ts +108 -0
- package/src/extract-contract.ts +42 -0
- package/src/extract-model.ts +10 -1
- package/src/extract-table-contract.ts +26 -0
- package/src/extract-table.ts +132 -0
- package/src/extraction-runs.ts +70 -11
- package/src/fs-atomic.ts +19 -2
- package/src/images.ts +203 -0
- package/src/index.ts +553 -205
- package/src/intent/README.md +8 -6
- package/src/intent/engine.ts +44 -6
- package/src/intent/host.ts +59 -18
- package/src/intent/scope.ts +125 -0
- package/src/intent/tools.ts +70 -28
- package/src/intent/types.ts +11 -4
- package/src/knowledge-bases.ts +56 -20
- package/src/knowledge-contract.ts +114 -0
- package/src/knowledge.ts +138 -69
- package/src/layout.ts +17 -37
- package/src/materialize-snapshot.ts +46 -0
- package/src/migrate.ts +75 -2
- package/src/model-text.ts +109 -4
- package/src/oplog.ts +7 -0
- package/src/organize-contract.ts +83 -0
- package/src/pipeline/engine.ts +323 -0
- package/src/pipeline/store.ts +147 -0
- package/src/pipeline/types.ts +93 -0
- package/src/present.ts +10 -4
- package/src/preset-ids.ts +6 -0
- package/src/python/embedding_worker.py +66 -2
- package/src/query-analysis.ts +68 -8
- package/src/recall-rank.ts +5 -5
- package/src/retention.ts +76 -0
- package/src/retrieval/vector-index.ts +45 -0
- package/src/retrieval/visibility.ts +14 -0
- package/src/runtime.ts +2708 -567
- package/src/settings-schema.ts +11 -8
- package/src/settings-volatile.ts +4 -4
- package/src/source-evidence.ts +37 -0
- package/src/store/axis-references.ts +96 -0
- package/src/store/derived.ts +70 -12
- package/src/store/knowledge-db.ts +248 -17
- package/src/store/migrate.ts +16 -6
- package/src/trajectory-types.ts +142 -0
- package/src/types.ts +61 -35
- package/src/wiki-finalize.ts +28 -0
- package/src/wiki-materialize.ts +25 -6
- package/src/wiki-trial-types.ts +83 -1
- package/src/wiki-trial.ts +357 -185
- package/lib/types/intent/preset-tools.d.ts +0 -37
- package/lib/types/intent/preset-tools.d.ts.map +0 -1
- package/lib/types/intent/preset-tools.js +0 -45
- package/lib/types/intent/preset-tools.js.map +0 -1
- package/preset/tita-data-agent/agent.cordis.yml +0 -394
- package/preset/tita-data-agent/preset.yml +0 -3
- package/scripts/install-agent-preset.mjs +0 -92
- package/scripts/sync-agent-preset.mjs +0 -188
- package/src/client/AgentPresetCard.tsx +0 -247
- package/src/client/agent-preset.ts +0 -121
- package/src/client/convert/ConvertPanel.tsx +0 -583
- package/src/client/convert/styles.css +0 -138
- package/src/client/convert/styles.ts +0 -49
- package/src/intent/preset-tools.ts +0 -48
package/src/knowledge-bases.ts
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
* 挑一个目录 —— 见 `layout.ts` 的三条原理。
|
|
12
12
|
*
|
|
13
13
|
* 注册表本身只持久化**配置**(id / name / description / rootDir),
|
|
14
|
-
* 落到 `<
|
|
15
|
-
*
|
|
14
|
+
* 落到 `<agentRoot>/resource/knowledge-bases.json`。插件运行时会显式传入这个注册表
|
|
15
|
+
* 位置;没有传入时也使用固定的 DSH/Tita Agent 目录,不再回退到旧的用户目录。
|
|
16
16
|
* `sourceCount` / `cardCount` / `noteCount` / `buildVersion` 都是**计算字段**,缓存在同一个 JSON 里,由 `refresh()` 从真实
|
|
17
17
|
* runtime 重新统计;这样 `list()` / `get()` 保持同步签名(前端首屏直接用),
|
|
18
18
|
* 路由在返回前 `await refresh()` 拿到准确值。
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
|
|
25
25
|
import { existsSync, readFileSync } from 'node:fs'
|
|
26
26
|
import { mkdir, rename, unlink, writeFile } from 'node:fs/promises'
|
|
27
|
-
import { homedir } from 'node:os'
|
|
28
27
|
import { dirname, join, resolve } from 'node:path'
|
|
29
28
|
import {
|
|
30
|
-
type Envelope, type KnowledgeBase, type KnowledgeConfig,
|
|
29
|
+
DEFAULT_COMPILE_MODEL, type CompileModelSelection, type Envelope, type KnowledgeBase, type KnowledgeConfig,
|
|
31
30
|
} from './types.js'
|
|
32
31
|
import { defaultKnowledgeRoot, failure, KnowledgeRuntime, success, type KnowledgeRuntimeOptions } from './runtime.js'
|
|
33
|
-
import { knowledgeBaseRoot, memoryRoot } from './layout.js'
|
|
32
|
+
import { defaultAgentRoot, knowledgeBaseRoot, memoryRoot, resourceRoot } from './layout.js'
|
|
33
|
+
import { writeTextAtomic } from './fs-atomic.js'
|
|
34
34
|
|
|
35
35
|
/** 持久化形态:配置 + 计算字段缓存分区。 */
|
|
36
36
|
interface KnowledgeBaseRecord {
|
|
@@ -47,6 +47,8 @@ interface KnowledgeBaseRecord {
|
|
|
47
47
|
* 这个库自己的判断。
|
|
48
48
|
*/
|
|
49
49
|
extractionNote: string
|
|
50
|
+
/** 编译模型路由;它是注册表配置,不属于知识正文。 */
|
|
51
|
+
compileModel: CompileModelSelection
|
|
50
52
|
createdAt: string
|
|
51
53
|
updatedAt: string
|
|
52
54
|
}
|
|
@@ -69,7 +71,7 @@ interface BaseStats {
|
|
|
69
71
|
export const DEFAULT_KB_ID = 'default'
|
|
70
72
|
|
|
71
73
|
export interface KnowledgeBasesOptions {
|
|
72
|
-
/**
|
|
74
|
+
/** 注册表的备用数据目录;生产运行时使用 `registryFile` 指向 Agent 的 resource。 */
|
|
73
75
|
dataHome?: string
|
|
74
76
|
/** 默认库的根目录来源;插件传入由 `agentRoot` 推出来的那一格。 */
|
|
75
77
|
defaultRootDir?: () => string
|
|
@@ -96,7 +98,7 @@ export interface KnowledgeBasesOptions {
|
|
|
96
98
|
* `index.ts` 里直接 new),新建的库一律退回规则抽取:正文按 `##` 小节切,
|
|
97
99
|
* 界面上只留一句「运行时没有注入模型接缝」。这跟写库 id 无关,纯粹是构造点漏了。
|
|
98
100
|
*/
|
|
99
|
-
runtimeOptions?: () => Partial<KnowledgeRuntimeOptions>
|
|
101
|
+
runtimeOptions?: (baseId: string) => Partial<KnowledgeRuntimeOptions>
|
|
100
102
|
/**
|
|
101
103
|
* 覆盖注册表文件位置(默认 `<dataHome>/knowledge-bases.json`)。
|
|
102
104
|
*
|
|
@@ -115,6 +117,17 @@ function textOr(input: unknown, fallback: string): string {
|
|
|
115
117
|
return typeof input === 'string' && input.trim() ? input.trim() : fallback
|
|
116
118
|
}
|
|
117
119
|
|
|
120
|
+
function compileModelOf(input: unknown): CompileModelSelection {
|
|
121
|
+
const value = record(input)
|
|
122
|
+
const effort = typeof value.reasoningEffort === 'string' && value.reasoningEffort.trim() ? { reasoningEffort: value.reasoningEffort.trim() } : {}
|
|
123
|
+
if (value.mode !== 'fixed') return { ...DEFAULT_COMPILE_MODEL, ...effort }
|
|
124
|
+
const provider = typeof value.provider === 'string' ? value.provider.trim() : ''
|
|
125
|
+
const model = typeof value.model === 'string' ? value.model.trim() : ''
|
|
126
|
+
// 旧版本没有这个字段,或留下了半截配置时,安全地回到 DSH 默认模型。
|
|
127
|
+
if (!provider || !model) return { ...DEFAULT_COMPILE_MODEL }
|
|
128
|
+
return { mode: 'fixed', provider, model, ...effort }
|
|
129
|
+
}
|
|
130
|
+
|
|
118
131
|
function normalizeExt(value: unknown, fallback: string): string {
|
|
119
132
|
const text = typeof value === 'string' ? value.trim().toLowerCase() : ''
|
|
120
133
|
const ext = text || fallback
|
|
@@ -126,22 +139,13 @@ function emptyBase(id: string): KnowledgeBase {
|
|
|
126
139
|
return {
|
|
127
140
|
id, name: id, description: '', rootDir: '', isDefault: false,
|
|
128
141
|
extractionNote: '',
|
|
142
|
+
compileModel: { ...DEFAULT_COMPILE_MODEL },
|
|
129
143
|
createdAt: '', updatedAt: '', sourceCount: 0, cardCount: 0, noteCount: 0, buildVersion: 0,
|
|
130
144
|
}
|
|
131
145
|
}
|
|
132
146
|
|
|
133
|
-
async function writeTextAtomic(path: string, content: string): Promise<void> {
|
|
134
|
-
const temporary = `${path}.${process.pid}.${Date.now().toString(36)}.tmp`
|
|
135
|
-
try {
|
|
136
|
-
await writeFile(temporary, content, 'utf8')
|
|
137
|
-
await rename(temporary, path)
|
|
138
|
-
} finally {
|
|
139
|
-
try { await unlink(temporary) } catch { /* rename already consumed it */ }
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
147
|
export function defaultDataHome(): string {
|
|
144
|
-
return
|
|
148
|
+
return resourceRoot(defaultAgentRoot())
|
|
145
149
|
}
|
|
146
150
|
|
|
147
151
|
export class KnowledgeBases {
|
|
@@ -243,7 +247,7 @@ export class KnowledgeBases {
|
|
|
243
247
|
// 逻辑的单元测试)留空,runtime 会退回知识树里的 `04_memory`。
|
|
244
248
|
...(this.options.agentRoot ? { memoryRoot: memoryRoot(this.options.agentRoot(), base.id) } : {}),
|
|
245
249
|
// 0044:宿主级能力(模型接缝)必须一起带过来,否则非默认库静默退回规则抽取。
|
|
246
|
-
...(this.options.runtimeOptions?.() ?? {}),
|
|
250
|
+
...(this.options.runtimeOptions?.(base.id) ?? {}),
|
|
247
251
|
})
|
|
248
252
|
runtime.baseId = base.id
|
|
249
253
|
this.runtimes.set(key, runtime)
|
|
@@ -268,6 +272,15 @@ export class KnowledgeBases {
|
|
|
268
272
|
this.runtimes.clear()
|
|
269
273
|
}
|
|
270
274
|
|
|
275
|
+
/** Volatile settings apply to every cached base, including non-default bases. */
|
|
276
|
+
updateRuntimeConfig(config: Partial<import('./types.js').RuntimeKnowledgeConfig>): void {
|
|
277
|
+
for (const runtime of this.runtimes.values()) runtime.updateConfig(config)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
reloadResources(): void {
|
|
281
|
+
for (const runtime of this.runtimes.values()) runtime.reloadResources()
|
|
282
|
+
}
|
|
283
|
+
|
|
271
284
|
// ------------------------------------------------------------- 统计刷新
|
|
272
285
|
|
|
273
286
|
/**
|
|
@@ -324,6 +337,7 @@ export class KnowledgeBases {
|
|
|
324
337
|
rootDir,
|
|
325
338
|
isDefault: false,
|
|
326
339
|
extractionNote: '',
|
|
340
|
+
compileModel: { ...DEFAULT_COMPILE_MODEL },
|
|
327
341
|
createdAt: now,
|
|
328
342
|
updatedAt: now,
|
|
329
343
|
}
|
|
@@ -337,12 +351,23 @@ export class KnowledgeBases {
|
|
|
337
351
|
* 更新名称 / 描述 / 坐标提取备注。
|
|
338
352
|
*
|
|
339
353
|
*/
|
|
340
|
-
async update(id: string, patch: { name?: string; description?: string; extractionNote?: string }): Promise<Envelope<KnowledgeBase>> {
|
|
354
|
+
async update(id: string, patch: { name?: string; description?: string; extractionNote?: string; compileModel?: CompileModelSelection }): Promise<Envelope<KnowledgeBase>> {
|
|
341
355
|
this.ensureLoaded()
|
|
342
356
|
const base = this.records.find(item => item.id === id)
|
|
343
357
|
if (!base) return failure(emptyBase(id), 'BASE_NOT_FOUND', `知识库不存在: ${id}`, true)
|
|
344
358
|
// 守卫必须基于精确的实时计数,不能用可能过期的缓存。
|
|
345
359
|
await this.refreshOne(base)
|
|
360
|
+
let nextCompileModel = base.compileModel
|
|
361
|
+
if (patch.compileModel !== undefined) {
|
|
362
|
+
if (patch.compileModel.mode !== 'default' && patch.compileModel.mode !== 'fixed') {
|
|
363
|
+
return failure(this.view(base), 'COMPILE_MODEL_INVALID', '编译模型 mode 只能是 default 或 fixed', false, '从编译模型选择项中选择“跟随 DSH 默认模型”或一个固定模型。')
|
|
364
|
+
}
|
|
365
|
+
const selected = compileModelOf(patch.compileModel)
|
|
366
|
+
if (patch.compileModel.mode === 'fixed' && selected.mode !== 'fixed') {
|
|
367
|
+
return failure(this.view(base), 'COMPILE_MODEL_INVALID', '固定编译模型必须同时提供 provider 和 model', false, '从当前 DSH 模型目录中选择一个可用模型。')
|
|
368
|
+
}
|
|
369
|
+
nextCompileModel = selected
|
|
370
|
+
}
|
|
346
371
|
if (patch.name !== undefined) {
|
|
347
372
|
const name = String(patch.name).trim()
|
|
348
373
|
if (!name) return failure(this.view(base), 'NAME_REQUIRED', 'name 不能为空', false)
|
|
@@ -351,6 +376,7 @@ export class KnowledgeBases {
|
|
|
351
376
|
if (patch.description !== undefined) base.description = String(patch.description)
|
|
352
377
|
// 长度上限不是配额,是防呆:这条备注逐字进每一次抽取的提示词,几万字会把文档挤出去。
|
|
353
378
|
if (patch.extractionNote !== undefined) base.extractionNote = String(patch.extractionNote).slice(0, 4000)
|
|
379
|
+
base.compileModel = nextCompileModel
|
|
354
380
|
base.updatedAt = new Date().toISOString()
|
|
355
381
|
await this.refreshOne(base)
|
|
356
382
|
await this.persist()
|
|
@@ -366,6 +392,12 @@ export class KnowledgeBases {
|
|
|
366
392
|
return this.records.find(item => item.id === id)?.extractionNote ?? ''
|
|
367
393
|
}
|
|
368
394
|
|
|
395
|
+
/** 当前知识库的编译模型路由。不存在的库回到默认路由,避免读路径抛错。 */
|
|
396
|
+
compileModelOf(id: string): CompileModelSelection {
|
|
397
|
+
this.ensureLoaded()
|
|
398
|
+
return { ...(this.records.find(item => item.id === id)?.compileModel ?? DEFAULT_COMPILE_MODEL) }
|
|
399
|
+
}
|
|
400
|
+
|
|
369
401
|
/**
|
|
370
402
|
* 删除知识库。
|
|
371
403
|
*
|
|
@@ -410,6 +442,7 @@ export class KnowledgeBases {
|
|
|
410
442
|
rootDir: base.isDefault ? this.defaultRootDir() : base.rootDir,
|
|
411
443
|
isDefault: base.isDefault,
|
|
412
444
|
extractionNote: base.extractionNote,
|
|
445
|
+
compileModel: { ...base.compileModel },
|
|
413
446
|
createdAt: base.createdAt,
|
|
414
447
|
updatedAt: base.updatedAt,
|
|
415
448
|
sourceCount: stats?.sourceCount ?? 0,
|
|
@@ -428,6 +461,7 @@ export class KnowledgeBases {
|
|
|
428
461
|
rootDir: this.defaultRootDir(),
|
|
429
462
|
isDefault: true,
|
|
430
463
|
extractionNote: '',
|
|
464
|
+
compileModel: { ...DEFAULT_COMPILE_MODEL },
|
|
431
465
|
createdAt: now,
|
|
432
466
|
updatedAt: now,
|
|
433
467
|
}
|
|
@@ -468,6 +502,7 @@ export class KnowledgeBases {
|
|
|
468
502
|
isDefault: true,
|
|
469
503
|
rootDir: seed.rootDir,
|
|
470
504
|
name: existing.name || seed.name,
|
|
505
|
+
compileModel: existing.compileModel ?? seed.compileModel,
|
|
471
506
|
}
|
|
472
507
|
}
|
|
473
508
|
}
|
|
@@ -488,6 +523,7 @@ export class KnowledgeBases {
|
|
|
488
523
|
isDefault: value.isDefault === true || id === this.defaultId,
|
|
489
524
|
// 0068 之前存下来的注册表里没有这个键:算空串,不报错,也不影响别的字段。
|
|
490
525
|
extractionNote: typeof value.extractionNote === 'string' ? value.extractionNote : '',
|
|
526
|
+
compileModel: compileModelOf(value.compileModel),
|
|
491
527
|
createdAt: typeof value.createdAt === 'string' && value.createdAt ? value.createdAt : now,
|
|
492
528
|
updatedAt: typeof value.updatedAt === 'string' && value.updatedAt ? value.updatedAt : now,
|
|
493
529
|
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/** Browser-safe Knowledge contracts. Axis semantics remain in axis-contract.ts. */
|
|
2
|
+
export type KnowledgeKind = 'fact' | 'procedure' | 'case'
|
|
3
|
+
export type WikiKind = 'fact' | 'way'
|
|
4
|
+
|
|
5
|
+
export interface ProcedureContent {
|
|
6
|
+
question: string
|
|
7
|
+
appliesWhen: string[]
|
|
8
|
+
method: string[]
|
|
9
|
+
resultChecks: string[]
|
|
10
|
+
limitations: string[]
|
|
11
|
+
completeness: 'complete' | 'partial' | 'reference_only'
|
|
12
|
+
caseRefs: Array<{ id: string; version: number }>
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface KnowledgeContent {
|
|
16
|
+
conditions?: string[]
|
|
17
|
+
procedure?: ProcedureContent
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function wikiProjection(kind: KnowledgeKind, coordinate: { objectId: string; actionId: string; sceneId: string }): { objectId: string; actionId: string; sceneId: string } | undefined {
|
|
21
|
+
if (kind === 'case' || !coordinate.objectId || (kind === 'procedure' && !coordinate.actionId)) return undefined
|
|
22
|
+
return { objectId: coordinate.objectId, actionId: kind === 'procedure' ? coordinate.actionId : '', sceneId: '' }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function procedureText(value: ProcedureContent): string {
|
|
26
|
+
return [value.question, value.appliesWhen.length ? `适用条件:${value.appliesWhen.join(';')}` : '',
|
|
27
|
+
value.method.map((step, index) => { const prefix = `${index + 1}. `; return prefix + step.replace(/\n/g, `\n${' '.repeat(prefix.length)}`) }).join('\n'),
|
|
28
|
+
value.resultChecks.length ? `结果检查:${value.resultChecks.join(';')}` : '',
|
|
29
|
+
value.limitations.length ? `边界:${value.limitations.join(';')}` : ''].filter(Boolean).join('\n\n')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type Row = Record<string, unknown>
|
|
33
|
+
const row = (v: unknown): Row => v !== null && typeof v === 'object' && !Array.isArray(v) ? v as Row : {}
|
|
34
|
+
const rows = (v: unknown): Row[] => Array.isArray(v) ? v.map(row) : []
|
|
35
|
+
function list(v: unknown): unknown[] {
|
|
36
|
+
if (typeof v === 'string') { const p: unknown = JSON.parse(v || '[]'); if (!Array.isArray(p)) throw new Error('列表字段必须为数组'); return p }
|
|
37
|
+
if (v === null || v === undefined) return []
|
|
38
|
+
if (!Array.isArray(v)) throw new Error('列表字段必须为数组')
|
|
39
|
+
return v
|
|
40
|
+
}
|
|
41
|
+
const strings = (v: unknown): string[] => list(v).map(x => { if (typeof x === 'string') return x; if (typeof row(x).text === 'string') return row(x).text as string; throw new Error('列表项必须为字符串或包含 text 的对象') }).map(x => x.trim()).filter(Boolean)
|
|
42
|
+
|
|
43
|
+
/** Adapt v2 wire records to the existing evidence/axis resolver; legacy reports remain readable. */
|
|
44
|
+
export function normalizeKnowledgeExtraction(value: unknown): unknown {
|
|
45
|
+
const input = row(value)
|
|
46
|
+
if (!('facts' in input) && !('procedures' in input) && !('cases' in input)) return value
|
|
47
|
+
for (const key of ['facts', 'procedures', 'cases']) if (!Array.isArray(input[key])) throw new Error(`抽取缺少 ${key} 数组`)
|
|
48
|
+
const evidence = new Map<string, Row>()
|
|
49
|
+
for (const entry of rows(input.evidence)) {
|
|
50
|
+
const id = typeof entry.id === 'string' ? entry.id.trim() : ''
|
|
51
|
+
if (!id || evidence.has(id) || typeof entry.quote !== 'string' || !entry.quote.trim()) throw new Error('引文 ID 重复、为空或缺少 quote')
|
|
52
|
+
evidence.set(id, entry)
|
|
53
|
+
}
|
|
54
|
+
const refs = (item: Row): Row[] => {
|
|
55
|
+
if (Array.isArray(item.sources)) {
|
|
56
|
+
const sources = rows(item.sources)
|
|
57
|
+
if (!sources.length || sources.some(source => typeof source.quote !== 'string' || !source.quote.trim())) throw new Error('记录缺少有效来源引文')
|
|
58
|
+
return sources
|
|
59
|
+
}
|
|
60
|
+
const ids = typeof item.evidence === 'string' ? item.evidence.trim().split(/\s+/).filter(Boolean) : list(item.evidence)
|
|
61
|
+
if (!ids.length) throw new Error('记录缺少 evidence 引用')
|
|
62
|
+
return ids.map(id => {
|
|
63
|
+
const e = evidence.get(String(id))
|
|
64
|
+
if (!e || typeof e.quote !== 'string' || !e.quote.trim()) throw new Error(`引文 ${String(id)} 不存在或为空`)
|
|
65
|
+
return { quote: e.quote, heading_path: strings(e.heading_path) }
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
const seen = new Set<string>()
|
|
69
|
+
const checkId = (v: Row): void => {
|
|
70
|
+
const id = String(v.id ?? '').trim()
|
|
71
|
+
if (!id || seen.has(id)) throw new Error('Knowledge 局部 ID 为空或重复')
|
|
72
|
+
seen.add(id)
|
|
73
|
+
}
|
|
74
|
+
const knowledge = rows(input.facts).map(f => {
|
|
75
|
+
checkId(f)
|
|
76
|
+
return { ...f, scope_identity: true, kind: 'fact', data: strings(f.conditions).length ? { conditions: strings(f.conditions) } : {}, sources: refs(f) }
|
|
77
|
+
})
|
|
78
|
+
for (const p of rows(input.procedures)) {
|
|
79
|
+
checkId(p)
|
|
80
|
+
const completeness = p.completeness
|
|
81
|
+
if (!['complete', 'partial', 'reference_only'].includes(String(completeness))) throw new Error(`Procedure ${p.id} completeness 不合法`)
|
|
82
|
+
if (list(p.case_refs).length) throw new Error('抽取阶段不能生成 Case 版本引用,请使用独立提炼阶段')
|
|
83
|
+
const method = list(p.method)
|
|
84
|
+
const stepSources = method.flatMap(step => typeof step === 'string' ? [] : refs(row(step)))
|
|
85
|
+
const procedure: ProcedureContent = {
|
|
86
|
+
question: String(p.question ?? '').trim(), appliesWhen: strings(p.applies_when), method: strings(method),
|
|
87
|
+
resultChecks: strings(p.result_checks), limitations: [...strings(p.limitations), ...strings(p.missing)],
|
|
88
|
+
completeness: completeness as ProcedureContent['completeness'],
|
|
89
|
+
caseRefs: list(p.case_refs).map(ref => ({ id: String(row(ref).id ?? ''), version: Number(row(ref).version ?? 0) })),
|
|
90
|
+
}
|
|
91
|
+
if (!procedure.question || (procedure.completeness === 'complete' && procedure.method.length === 0)) throw new Error(`Procedure ${p.id} 缺少问题或完整方法`)
|
|
92
|
+
knowledge.push({ ...p, scope_identity: true, kind: 'procedure', text: procedureText(procedure), data: { procedure }, sources: [...refs(p), ...stepSources] } as typeof knowledge[number])
|
|
93
|
+
}
|
|
94
|
+
const caseIds = new Set(rows(input.cases).map(c => c.id))
|
|
95
|
+
const timelineKeys = new Set<string>()
|
|
96
|
+
for (const step of rows(input.timeline)) {
|
|
97
|
+
if (!caseIds.has(step.case_id)) throw new Error('时间线引用不存在的 Case')
|
|
98
|
+
const key = `${step.case_id}:${step.order}`
|
|
99
|
+
if (!Number.isInteger(step.order) || Number(step.order) < 1 || timelineKeys.has(key)) throw new Error('时间线顺序必须为不重复的正整数')
|
|
100
|
+
timelineKeys.add(key)
|
|
101
|
+
}
|
|
102
|
+
const events = rows(input.cases).map(c => {
|
|
103
|
+
checkId(c)
|
|
104
|
+
const timeline = Array.isArray(c.timeline) ? rows(c.timeline) : rows(input.timeline).filter(step => step.case_id === c.id)
|
|
105
|
+
if (timeline.some(step => !['observation', 'check', 'action', 'result', 'conclusion'].includes(String(step.type)))) throw new Error('Case 时间线类型不合法')
|
|
106
|
+
const rootCause = typeof c.root_cause === 'string' ? c.root_cause ? { text: c.root_cause, status: c.root_cause_status } : null : c.root_cause
|
|
107
|
+
return { ...c, coordinate: c.coordinate ?? { object_mention: c.object, action_mention: c.action, scene_mention: c.scene },
|
|
108
|
+
missing: strings(c.missing), root_cause: rootCause, sources: refs(c),
|
|
109
|
+
timeline: timeline.map(step => ({ ...step, sources: refs(step) })) }
|
|
110
|
+
})
|
|
111
|
+
return { ...input, knowledge, events,
|
|
112
|
+
...Object.fromEntries(['objects', 'actions', 'scenes'].map(key => [key, rows(input[key]).map(a => ({ ...a,
|
|
113
|
+
parent_mention: a.parent_mention ?? a.parent, evidence: typeof a.evidence === 'string' && !evidence.has(a.evidence) ? a.evidence : refs(a).map(e => e.quote).join('\n') }))])) }
|
|
114
|
+
}
|