@kingsleyasher/dsh-knowledge-base 0.0.0-stage → 3.1.5
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/ARCHITECTURE.en.md +35 -0
- package/ARCHITECTURE.md +40 -0
- package/BETA4.md +31 -0
- package/BETA7.md +35 -0
- package/BETA8.md +39 -0
- package/BETA9.md +38 -0
- package/CONTRIBUTING.md +5 -0
- package/DEVELOPMENT.en.md +26 -0
- package/DEVELOPMENT.md +27 -0
- package/EXISTING-FRAMEWORK-OPTIMIZATION.md +101 -0
- package/LICENSE +21 -0
- package/MONOREPO.md +34 -0
- package/NPM-EDITION.md +12 -0
- package/PARSING-PREVIEW.md +84 -0
- package/PERFORMANCE.md +43 -0
- package/PRIVACY.md +7 -0
- package/PROJECT-RECORD.en.md +782 -0
- package/PROJECT-RECORD.md +793 -0
- package/README.md +109 -3
- package/README.zh-CN.md +117 -0
- package/RELEASE.en.md +559 -0
- package/RELEASE.md +570 -0
- package/RETRIEVAL.md +93 -0
- package/SECURITY.md +7 -0
- package/THIRD-PARTY-NOTICES.md +5 -0
- package/VERSIONING.en.md +51 -0
- package/VERSIONING.md +50 -0
- package/WORKBENCH.en.md +201 -0
- package/WORKBENCH.md +195 -0
- package/browser-extension/background.js +146 -0
- package/browser-extension/icons/knowledge-base-128.png +0 -0
- package/browser-extension/icons/knowledge-base-16.png +0 -0
- package/browser-extension/icons/knowledge-base-32.png +0 -0
- package/browser-extension/icons/knowledge-base-48.png +0 -0
- package/browser-extension/manifest.json +25 -0
- package/browser-extension/options.html +22 -0
- package/browser-extension/options.js +41 -0
- package/browser-extension/popup.html +17 -0
- package/browser-extension/popup.js +58 -0
- package/browser-extension/style.css +11 -0
- package/cordis.patch.yml +88 -0
- package/docs/LEGACY-246-BOOTSTRAP.md +21 -0
- package/docs/LIBRARY-FRAMEWORK-MIGRATION.md +45 -0
- package/docs/ORIGINAL-FILE-INDEX-ARCHITECTURE.md +43 -0
- package/docs/TODO-LIFECYCLE-VALIDATION.md +42 -0
- package/docs/UPDATE-RECOVERY.en.md +18 -0
- package/docs/UPDATE-RECOVERY.md +70 -0
- package/docs/WINDOWS-SIGNING.md +30 -0
- package/docs/client/ARCHITECTURE.en.md +17 -0
- package/docs/client/ARCHITECTURE.md +17 -0
- package/docs/client/CONTRIBUTING.md +5 -0
- package/docs/client/CROSS-VOLUME-TRASH.md +13 -0
- package/docs/client/DEVELOPMENT.en.md +33 -0
- package/docs/client/DEVELOPMENT.md +33 -0
- package/docs/client/EXISTING-FRAMEWORK-OPTIMIZATION.md +3 -0
- package/docs/client/PERFORMANCE.md +3 -0
- package/docs/client/PRIVACY.md +7 -0
- package/docs/client/PROJECT-RECORD.en.md +199 -0
- package/docs/client/PROJECT-RECORD.md +219 -0
- package/docs/client/README.md +55 -0
- package/docs/client/README.zh-CN.md +45 -0
- package/docs/client/RELEASE.en.md +148 -0
- package/docs/client/RELEASE.md +149 -0
- package/docs/client/RETRIEVAL.md +3 -0
- package/docs/client/SECURITY.md +7 -0
- package/docs/client/THIRD-PARTY-NOTICES.md +5 -0
- package/docs/client/VERSIONING.en.md +9 -0
- package/docs/client/VERSIONING.md +9 -0
- package/docs/client/WORKBENCH.en.md +24 -0
- package/docs/client/WORKBENCH.md +24 -0
- package/docs/client/skills/personal-knowledge-base/SKILL.md +38 -0
- package/docs/releases/client-1.0.1.md +32 -0
- package/docs/releases/client-1.0.2.md +32 -0
- package/docs/releases/client-1.0.3.md +31 -0
- package/docs/releases/client-1.1.1.md +28 -0
- package/docs/releases/client-1.1.2.md +16 -0
- package/docs/releases/client-1.1.4.md +7 -0
- package/docs/releases/client-2.0.0.en.md +13 -0
- package/docs/releases/client-2.0.0.md +13 -0
- package/docs/releases/client-2.0.1.en.md +10 -0
- package/docs/releases/client-2.0.1.md +10 -0
- package/docs/releases/client-2.0.3.en.md +8 -0
- package/docs/releases/client-2.0.3.md +8 -0
- package/docs/releases/plugin-2.4.1.md +24 -0
- package/docs/releases/plugin-2.4.10.md +22 -0
- package/docs/releases/plugin-2.4.11.md +14 -0
- package/docs/releases/plugin-2.4.12.md +14 -0
- package/docs/releases/plugin-2.4.13.md +27 -0
- package/docs/releases/plugin-2.4.14.md +18 -0
- package/docs/releases/plugin-2.4.2.md +31 -0
- package/docs/releases/plugin-2.4.3.md +25 -0
- package/docs/releases/plugin-2.4.4.md +31 -0
- package/docs/releases/plugin-2.4.5.md +23 -0
- package/docs/releases/plugin-2.4.6.md +23 -0
- package/docs/releases/plugin-2.4.7.md +14 -0
- package/docs/releases/plugin-2.4.8.md +14 -0
- package/docs/releases/plugin-2.4.9.md +18 -0
- package/docs/releases/plugin-2.5.10.md +11 -0
- package/docs/releases/plugin-2.5.13.en.md +11 -0
- package/docs/releases/plugin-2.5.13.md +11 -0
- package/docs/releases/plugin-2.5.3.md +28 -0
- package/docs/releases/plugin-2.5.4.md +14 -0
- package/docs/releases/plugin-2.5.5.md +16 -0
- package/docs/releases/plugin-2.5.6.md +3 -0
- package/docs/releases/plugin-2.5.7.md +7 -0
- package/docs/releases/plugin-2.5.8.md +7 -0
- package/docs/releases/plugin-2.5.9.md +7 -0
- package/docs/releases/plugin-3.0.0.en.md +13 -0
- package/docs/releases/plugin-3.0.0.md +13 -0
- package/docs/releases/plugin-3.0.1.en.md +10 -0
- package/docs/releases/plugin-3.0.1.md +10 -0
- package/docs/releases/plugin-3.1.3.en.md +11 -0
- package/docs/releases/plugin-3.1.3.md +11 -0
- package/docs/validation/windows-auto-update-2.4.13.md +31 -0
- package/docs/validation/windows-direct-246-to-2413.md +32 -0
- package/package.json +78 -6
- package/packages/kb-contracts/desktop.js +29 -0
- package/packages/kb-contracts/index.js +132 -0
- package/packages/kb-contracts/node.js +3 -0
- package/packages/kb-contracts/package.json +17 -0
- package/packages/kb-contracts/schema.js +42 -0
- package/packages/kb-contracts/tools.js +1 -0
- package/packages/kb-contracts/version-policy.js +45 -0
- package/packages/kb-core/index.js +9 -0
- package/packages/kb-core/package.json +15 -0
- package/packages/kb-core/src/capture-surface.js +22 -0
- package/packages/kb-core/src/documents.js +105 -0
- package/packages/kb-core/src/embedded.js +29 -0
- package/packages/kb-core/src/file-catalog.js +151 -0
- package/packages/kb-core/src/file-classification.js +60 -0
- package/packages/kb-core/src/flow-workspace.js +66 -0
- package/packages/kb-core/src/flows.js +1136 -0
- package/packages/kb-core/src/fsindex.js +293 -0
- package/packages/kb-core/src/import-service.js +486 -0
- package/packages/kb-core/src/importer.js +909 -0
- package/packages/kb-core/src/inbox-flow.js +2 -0
- package/packages/kb-core/src/index-architecture.js +48 -0
- package/packages/kb-core/src/index-maintenance.js +81 -0
- package/packages/kb-core/src/index-policy-service.js +191 -0
- package/packages/kb-core/src/index-policy.js +121 -0
- package/packages/kb-core/src/kbcore.js +2519 -0
- package/packages/kb-core/src/library-framework.js +186 -0
- package/packages/kb-core/src/library-state.js +68 -0
- package/packages/kb-core/src/managed-files.js +69 -0
- package/packages/kb-core/src/map.js +171 -0
- package/packages/kb-core/src/parse-credentials.js +49 -0
- package/packages/kb-core/src/parse-discovery.js +119 -0
- package/packages/kb-core/src/parse-job-storage.js +40 -0
- package/packages/kb-core/src/parse-native.js +87 -0
- package/packages/kb-core/src/parse-presets.js +46 -0
- package/packages/kb-core/src/parse-source-authority.js +72 -0
- package/packages/kb-core/src/parsing.js +2307 -0
- package/packages/kb-core/src/relation-name-lookup.js +43 -0
- package/packages/kb-core/src/retrieval-api.js +79 -0
- package/packages/kb-core/src/retrieval-cache.js +22 -0
- package/packages/kb-core/src/retrieval-chunks.js +128 -0
- package/packages/kb-core/src/retrieval-pool.js +102 -0
- package/packages/kb-core/src/retrieval-worker.js +190 -0
- package/packages/kb-core/src/retrieval.js +618 -0
- package/packages/kb-core/src/runtime-resources.js +73 -0
- package/packages/kb-core/src/service-ownership.js +18 -0
- package/packages/kb-core/src/source-references.js +61 -0
- package/packages/kb-core/src/storage-io.js +121 -0
- package/packages/kb-core/src/system-upgrades.js +104 -0
- package/packages/kb-core/src/workbench-backup.js +219 -0
- package/packages/kb-core/src/workbench-deliverables.js +73 -0
- package/packages/kb-core/src/workbench-files.js +25 -0
- package/packages/kb-core/src/workbench-inbox.js +57 -0
- package/packages/kb-core/src/workbench-links.js +236 -0
- package/packages/kb-core/src/workbench-question.js +131 -0
- package/packages/kb-core/src/workbench-relation-index.js +110 -0
- package/packages/kb-core/src/workbench-state.js +102 -0
- package/packages/kb-core/src/workbench-trash.js +213 -0
- package/packages/kb-core/src/workbench.js +936 -0
- package/packages/kb-service/auth.js +39 -0
- package/packages/kb-service/build.js +18 -0
- package/packages/kb-service/cli.js +26 -0
- package/packages/kb-service/client.js +64 -0
- package/packages/kb-service/clipper.js +15 -0
- package/packages/kb-service/compatibility.js +34 -0
- package/packages/kb-service/desktop-files.js +514 -0
- package/packages/kb-service/desktop-host-links.js +39 -0
- package/packages/kb-service/dsh-broker.js +64 -0
- package/packages/kb-service/dsh-host.js +168 -0
- package/packages/kb-service/dsh-stream-relay.js +32 -0
- package/packages/kb-service/engines.js +32 -0
- package/packages/kb-service/extension.js +8 -0
- package/packages/kb-service/first-library-handoff.js +28 -0
- package/packages/kb-service/handoff-api.js +22 -0
- package/packages/kb-service/host-adapter.js +151 -0
- package/packages/kb-service/host-assets.js +9 -0
- package/packages/kb-service/host-python.js +30 -0
- package/packages/kb-service/host-updates.js +97 -0
- package/packages/kb-service/inbox-host.js +47 -0
- package/packages/kb-service/inbox-jobs.js +54 -0
- package/packages/kb-service/index.js +3 -0
- package/packages/kb-service/io.js +24 -0
- package/packages/kb-service/launch-lock.js +27 -0
- package/packages/kb-service/launcher.js +18 -0
- package/packages/kb-service/legacy-handoff.js +27 -0
- package/packages/kb-service/legacy-ports.js +18 -0
- package/packages/kb-service/main.js +13 -0
- package/packages/kb-service/memory-channel.js +57 -0
- package/packages/kb-service/memory-sync.js +42 -0
- package/packages/kb-service/migration.js +131 -0
- package/packages/kb-service/native.py +216 -0
- package/packages/kb-service/operations.js +19 -0
- package/packages/kb-service/package.json +1 -0
- package/packages/kb-service/runtime.js +185 -0
- package/packages/kb-service/safe-update.js +104 -0
- package/packages/kb-service/service.js +494 -0
- package/packages/kb-service/tool-definitions.json +934 -0
- package/packages/kb-service/tool-router.js +45 -0
- package/packages/kb-service/vector-profiles.js +41 -0
- package/presets/01-knowledge-agent.patch.yml +347 -0
- package/runtime/python/LICENSE.txt +676 -0
- package/runtime/python/_asyncio.pyd +0 -0
- package/runtime/python/_bz2.pyd +0 -0
- package/runtime/python/_ctypes.pyd +0 -0
- package/runtime/python/_decimal.pyd +0 -0
- package/runtime/python/_elementtree.pyd +0 -0
- package/runtime/python/_hashlib.pyd +0 -0
- package/runtime/python/_lzma.pyd +0 -0
- package/runtime/python/_multiprocessing.pyd +0 -0
- package/runtime/python/_overlapped.pyd +0 -0
- package/runtime/python/_queue.pyd +0 -0
- package/runtime/python/_remote_debugging.pyd +0 -0
- package/runtime/python/_socket.pyd +0 -0
- package/runtime/python/_sqlite3.pyd +0 -0
- package/runtime/python/_ssl.pyd +0 -0
- package/runtime/python/_uuid.pyd +0 -0
- package/runtime/python/_wmi.pyd +0 -0
- package/runtime/python/_zoneinfo.pyd +0 -0
- package/runtime/python/_zstd.pyd +0 -0
- package/runtime/python/libcrypto-3.dll +0 -0
- package/runtime/python/libffi-8.dll +0 -0
- package/runtime/python/libssl-3.dll +0 -0
- package/runtime/python/libtommath.dll +0 -0
- package/runtime/python/pyexpat.pyd +0 -0
- package/runtime/python/python.cat +0 -0
- package/runtime/python/python.exe +0 -0
- package/runtime/python/python3.dll +0 -0
- package/runtime/python/python314._pth +5 -0
- package/runtime/python/python314.dll +0 -0
- package/runtime/python/python314.zip +0 -0
- package/runtime/python/pythonw.exe +0 -0
- package/runtime/python/select.pyd +0 -0
- package/runtime/python/sqlite3.dll +0 -0
- package/runtime/python/unicodedata.pyd +0 -0
- package/runtime/python/vcruntime140.dll +0 -0
- package/runtime/python/vcruntime140_1.dll +0 -0
- package/runtime/python/winsound.pyd +0 -0
- package/skills/personal-knowledge-base/SKILL.md +38 -0
- package/src/client/capture-icon-192.png +0 -0
- package/src/client/capture-icon-512.png +0 -0
- package/src/client/capture-icon.svg +12 -0
- package/src/client/capture-sw.js +10 -0
- package/src/client/capture.css +1 -0
- package/src/client/capture.html +1 -0
- package/src/client/capture.js +37 -0
- package/src/client/capture.webmanifest +1 -0
- package/src/client/inbox-organize-bridge.js +22 -0
- package/src/client/index.js +4975 -0
- package/src/client/knowledge-ui.css +255 -0
- package/src/client/pdfjs/LICENSE +177 -0
- package/src/client/pdfjs/cmaps/78-EUC-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/78-EUC-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/78-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/78-RKSJ-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/78-RKSJ-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/78-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/78ms-RKSJ-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/78ms-RKSJ-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/83pv-RKSJ-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/90ms-RKSJ-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/90ms-RKSJ-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/90msp-RKSJ-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/90msp-RKSJ-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/90pv-RKSJ-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/90pv-RKSJ-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Add-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Add-RKSJ-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Add-RKSJ-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Add-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-CNS1-0.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-CNS1-1.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-CNS1-2.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-CNS1-3.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-CNS1-4.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-CNS1-5.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-CNS1-6.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-CNS1-UCS2.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-GB1-0.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-GB1-1.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-GB1-2.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-GB1-3.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-GB1-4.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-GB1-5.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-GB1-UCS2.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-Japan1-0.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-Japan1-1.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-Japan1-2.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-Japan1-3.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-Japan1-4.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-Japan1-5.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-Japan1-6.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-Japan1-UCS2.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-Korea1-0.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-Korea1-1.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-Korea1-2.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Adobe-Korea1-UCS2.bcmap +0 -0
- package/src/client/pdfjs/cmaps/B5-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/B5-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/B5pc-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/B5pc-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/CNS-EUC-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/CNS-EUC-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/CNS1-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/CNS1-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/CNS2-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/CNS2-V.bcmap +3 -0
- package/src/client/pdfjs/cmaps/ETHK-B5-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/ETHK-B5-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/ETen-B5-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/ETen-B5-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/ETenms-B5-H.bcmap +3 -0
- package/src/client/pdfjs/cmaps/ETenms-B5-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/EUC-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/EUC-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Ext-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Ext-RKSJ-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Ext-RKSJ-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Ext-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GB-EUC-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GB-EUC-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GB-H.bcmap +4 -0
- package/src/client/pdfjs/cmaps/GB-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBK-EUC-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBK-EUC-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBK2K-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBK2K-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBKp-EUC-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBKp-EUC-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBT-EUC-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBT-EUC-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBT-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBT-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBTpc-EUC-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBTpc-EUC-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBpc-EUC-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/GBpc-EUC-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/HKdla-B5-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/HKdla-B5-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/HKdlb-B5-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/HKdlb-B5-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/HKgccs-B5-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/HKgccs-B5-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/HKm314-B5-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/HKm314-B5-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/HKm471-B5-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/HKm471-B5-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/HKscs-B5-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/HKscs-B5-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Hankaku.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Hiragana.bcmap +0 -0
- package/src/client/pdfjs/cmaps/KSC-EUC-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/KSC-EUC-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/KSC-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/KSC-Johab-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/KSC-Johab-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/KSC-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/KSCms-UHC-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/KSCms-UHC-HW-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/KSCms-UHC-HW-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/KSCms-UHC-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/KSCpc-EUC-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/KSCpc-EUC-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Katakana.bcmap +0 -0
- package/src/client/pdfjs/cmaps/LICENSE +36 -0
- package/src/client/pdfjs/cmaps/NWP-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/NWP-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/RKSJ-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/RKSJ-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/Roman.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniCNS-UCS2-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniCNS-UCS2-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniCNS-UTF16-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniCNS-UTF16-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniCNS-UTF32-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniCNS-UTF32-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniCNS-UTF8-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniCNS-UTF8-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniGB-UCS2-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniGB-UCS2-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniGB-UTF16-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniGB-UTF16-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniGB-UTF32-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniGB-UTF32-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniGB-UTF8-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniGB-UTF8-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS-UCS2-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS-UCS2-HW-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS-UCS2-HW-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS-UCS2-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS-UTF16-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS-UTF16-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS-UTF32-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS-UTF32-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS-UTF8-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS-UTF8-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS2004-UTF16-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS2004-UTF16-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS2004-UTF32-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS2004-UTF32-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS2004-UTF8-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJIS2004-UTF8-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJISPro-UCS2-HW-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJISPro-UCS2-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJISPro-UTF8-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJISX0213-UTF32-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJISX0213-UTF32-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJISX02132004-UTF32-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniJISX02132004-UTF32-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniKS-UCS2-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniKS-UCS2-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniKS-UTF16-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniKS-UTF16-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniKS-UTF32-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniKS-UTF32-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniKS-UTF8-H.bcmap +0 -0
- package/src/client/pdfjs/cmaps/UniKS-UTF8-V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/V.bcmap +0 -0
- package/src/client/pdfjs/cmaps/WP-Symbol.bcmap +0 -0
- package/src/client/pdfjs/pdf.mjs +26779 -0
- package/src/client/pdfjs/pdf.worker.mjs +63420 -0
- package/src/client/pdfjs/standard_fonts/FoxitDingbats.pfb +0 -0
- package/src/client/pdfjs/standard_fonts/FoxitFixed.pfb +0 -0
- package/src/client/pdfjs/standard_fonts/FoxitFixedBold.pfb +0 -0
- package/src/client/pdfjs/standard_fonts/FoxitFixedBoldItalic.pfb +0 -0
- package/src/client/pdfjs/standard_fonts/FoxitFixedItalic.pfb +0 -0
- package/src/client/pdfjs/standard_fonts/FoxitSerif.pfb +0 -0
- package/src/client/pdfjs/standard_fonts/FoxitSerifBold.pfb +0 -0
- package/src/client/pdfjs/standard_fonts/FoxitSerifBoldItalic.pfb +0 -0
- package/src/client/pdfjs/standard_fonts/FoxitSerifItalic.pfb +0 -0
- package/src/client/pdfjs/standard_fonts/FoxitSymbol.pfb +0 -0
- package/src/client/pdfjs/standard_fonts/LICENSE_FOXIT +27 -0
- package/src/client/pdfjs/standard_fonts/LICENSE_LIBERATION +102 -0
- package/src/client/pdfjs/standard_fonts/LiberationSans-Bold.ttf +0 -0
- package/src/client/pdfjs/standard_fonts/LiberationSans-BoldItalic.ttf +0 -0
- package/src/client/pdfjs/standard_fonts/LiberationSans-Italic.ttf +0 -0
- package/src/client/pdfjs/standard_fonts/LiberationSans-Regular.ttf +0 -0
- package/src/client/pdfjs/wasm/LICENSE_JBIG2 +196 -0
- package/src/client/pdfjs/wasm/LICENSE_OPENJPEG +39 -0
- package/src/client/pdfjs/wasm/LICENSE_PDFJS_JBIG2 +13 -0
- package/src/client/pdfjs/wasm/LICENSE_PDFJS_OPENJPEG +22 -0
- package/src/client/pdfjs/wasm/LICENSE_PDFJS_QCMS +22 -0
- package/src/client/pdfjs/wasm/LICENSE_QCMS +21 -0
- package/src/client/pdfjs/wasm/jbig2.wasm +0 -0
- package/src/client/pdfjs/wasm/openjpeg.wasm +0 -0
- package/src/client/pdfjs/wasm/openjpeg_nowasm_fallback.js +17 -0
- package/src/client/pdfjs/wasm/qcms_bg.wasm +0 -0
- package/src/client/todo-lifecycle-ui.js +58 -0
- package/src/client/workbench-features.js +148 -0
- package/src/client/workbench-relations.js +86 -0
- package/src/client/workbench-theme.css +81 -0
- package/src/client/workbench-ui.js +1761 -0
- package/src/host/capture-surface.js +2 -0
- package/src/host/citation-guard.js +40 -0
- package/src/host/command-description.js +43 -0
- package/src/host/flow-workspace.js +62 -0
- package/src/host/flows.js +2 -0
- package/src/host/fsindex.js +2 -0
- package/src/host/gateway.js +916 -0
- package/src/host/import-service.js +2 -0
- package/src/host/importer.js +2 -0
- package/src/host/index-maintenance.js +2 -0
- package/src/host/index-policy-service.js +2 -0
- package/src/host/index-policy.js +2 -0
- package/src/host/index.js +2220 -0
- package/src/host/kbcore.js +2 -0
- package/src/host/managed-files.js +2 -0
- package/src/host/map.js +2 -0
- package/src/host/parse-credentials.js +2 -0
- package/src/host/parse-discovery.js +2 -0
- package/src/host/parse-native.js +2 -0
- package/src/host/parse-presets.js +2 -0
- package/src/host/parse-source-authority.js +2 -0
- package/src/host/parsing.js +7 -0
- package/src/host/relation-name-lookup.js +2 -0
- package/src/host/retrieval-api.js +2 -0
- package/src/host/retrieval-cache.js +2 -0
- package/src/host/retrieval-chunks.js +2 -0
- package/src/host/retrieval-pool.js +2 -0
- package/src/host/retrieval-worker.js +2 -0
- package/src/host/retrieval.js +2 -0
- package/src/host/runtime-resources.js +2 -0
- package/src/host/selftest.js +747 -0
- package/src/host/storage-io.js +2 -0
- package/src/host/system-upgrades.js +2 -0
- package/src/host/todo-lifecycle.js +66 -0
- package/src/host/updates.js +281 -0
- package/src/host/versioning.js +2 -0
- package/src/host/workbench-backup.js +2 -0
- package/src/host/workbench-deliverables.js +2 -0
- package/src/host/workbench-files.js +2 -0
- package/src/host/workbench-inbox.js +2 -0
- package/src/host/workbench-links.js +2 -0
- package/src/host/workbench-question.js +2 -0
- package/src/host/workbench-relation-index.js +2 -0
- package/src/host/workbench-state.js +2 -0
- package/src/host/workbench-trash.js +2 -0
- package/src/host/workbench.js +5 -0
- package/tools/kb-local-model.py +141 -0
- package/tools/kb-pdf-pages.py +78 -0
- package/tools/kb-transactional-update.py +292 -0
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
// 导入服务(R1):UI(设置页 /kb-core/api)与模型工具(kb_import)共用的**唯一**执行入口。
|
|
2
|
+
//
|
|
3
|
+
// 关键不变量(对应审查意见 R1 与复核意见第 1 点):
|
|
4
|
+
// 1. 任务清单自带目标身份:{target, targetKbId, taskStateDir};执行方用**独立 core** 写到目标库,
|
|
5
|
+
// 不读、不改共享的「当前绑定」。
|
|
6
|
+
// 2. 独立 core 不等于目标已固定:它的状态目录里可能残留旧 config.json(kbPath 指向别的库),
|
|
7
|
+
// 所以创建后必须 loadConfig + status,核对**实际根目录**与 kbId;不一致立即拒绝(不写一个字节)。
|
|
8
|
+
// 3. 切库(commit)放在导入完成且核验通过之后;且只在「当前绑定仍是开始时那一个」时提交,
|
|
9
|
+
// 用户中途换库不会被覆盖。
|
|
10
|
+
// 4. 失败 / 取消 / 异常一律不碰当前绑定(没有"先切再恢复"这一步)。
|
|
11
|
+
import path from 'node:path'
|
|
12
|
+
import { mkdir } from 'node:fs/promises'
|
|
13
|
+
import { createCore } from './kbcore.js'
|
|
14
|
+
import { inspectFolder, planImport, runImport, readManifest, saveManifest, cancelImport, listImports, isValidImportId, resolveImportDir } from './importer.js'
|
|
15
|
+
|
|
16
|
+
export const TERMINAL_STAGES = new Set(['done', 'partial', 'failed', 'canceled', 'conflict'])
|
|
17
|
+
const norm = (p) => String(p ?? '').replace(/\\/g, '/').toLowerCase()
|
|
18
|
+
// All service instances for one profile share admission and running state.
|
|
19
|
+
const serviceStates = new Map()
|
|
20
|
+
|
|
21
|
+
export function createImportService({ stateDir, getBaseConfig, getCurrentCore = null, log = () => {}, coreFactory = createCore, commitBinding = null, getParsingService = null }) {
|
|
22
|
+
const stateKey = process.platform === 'win32' ? path.resolve(stateDir).toLowerCase() : path.resolve(stateDir)
|
|
23
|
+
if (!serviceStates.has(stateKey)) serviceStates.set(stateKey, { jobs: new Map(), starting: new Map() })
|
|
24
|
+
const { jobs, starting } = serviceStates.get(stateKey)
|
|
25
|
+
const taskStateDirOf = (importId) => path.join(stateDir, 'imports', importId, 'core-state')
|
|
26
|
+
const isActive = (importId) => Boolean(jobs.get(importId) && jobs.get(importId).running)
|
|
27
|
+
|
|
28
|
+
const currentCoreSafe = async () => (typeof getCurrentCore === 'function' ? await getCurrentCore() : null)
|
|
29
|
+
const currentStatus = async () => {
|
|
30
|
+
const c = await currentCoreSafe().catch(() => null)
|
|
31
|
+
if (!c) return null
|
|
32
|
+
return await c.status().catch(() => null)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** R2:任务目录在解析阶段就要判(读清单会把"越界"错报成 not-found) */
|
|
36
|
+
async function taskDirError(importId) {
|
|
37
|
+
if (!isValidImportId(importId)) return { reason: 'bad-import-id', error: 'importId 非法(必须形如 imp-xxxxxxxxxx)' }
|
|
38
|
+
const r = await resolveImportDir(stateDir, importId)
|
|
39
|
+
if (!r.ok) return { reason: r.reason, error: '导入任务目录非法:' + r.reason }
|
|
40
|
+
return null
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function baseConf() {
|
|
44
|
+
try {
|
|
45
|
+
return (await getBaseConfig()) ?? {}
|
|
46
|
+
} catch {
|
|
47
|
+
return {}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** 为任务创建一个**只指向 manifest.target** 的独立 core,并核对它真实落到的位置。 */
|
|
52
|
+
async function makeTaskCore(manifest) {
|
|
53
|
+
const base = await baseConf()
|
|
54
|
+
const taskStateDir = manifest.taskStateDir || taskStateDirOf(manifest.importId)
|
|
55
|
+
const cfg = { ...base, kbPath: manifest.target, stateDir: taskStateDir }
|
|
56
|
+
const core = coreFactory(cfg, log)
|
|
57
|
+
if (typeof core.loadConfig === 'function') await core.loadConfig()
|
|
58
|
+
const st = await core.status()
|
|
59
|
+
const gotRoot = st && st.kbPath ? path.resolve(st.kbPath) : null
|
|
60
|
+
if (!gotRoot || norm(gotRoot) !== norm(manifest.target)) {
|
|
61
|
+
return {
|
|
62
|
+
ok: false,
|
|
63
|
+
reason: 'target-root-mismatch',
|
|
64
|
+
error: `任务目标的独立 core 实际绑定在 ${st && st.kbPath ? st.kbPath : '(未绑定)'},与清单目标 ${manifest.target} 不一致;已拒绝执行(任务状态目录里可能有旧配置)`,
|
|
65
|
+
actualRoot: st && st.kbPath ? st.kbPath : null,
|
|
66
|
+
taskStateDir,
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (manifest.targetKbId && st.kbId && manifest.targetKbId !== st.kbId) {
|
|
70
|
+
return {
|
|
71
|
+
ok: false,
|
|
72
|
+
reason: 'target-kbid-mismatch',
|
|
73
|
+
error: `任务目标 kbId=${manifest.targetKbId},独立 core 读到的 kbId=${st.kbId};已拒绝执行(目标库被替换过)`,
|
|
74
|
+
actualKbId: st.kbId,
|
|
75
|
+
taskStateDir,
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return { ok: true, core, status: st, taskStateDir }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function stampTarget(manifest) {
|
|
82
|
+
let changed = false
|
|
83
|
+
if (!manifest.taskStateDir) {
|
|
84
|
+
manifest.taskStateDir = taskStateDirOf(manifest.importId)
|
|
85
|
+
changed = true
|
|
86
|
+
}
|
|
87
|
+
if (!manifest.targetKbId) {
|
|
88
|
+
const base = await baseConf()
|
|
89
|
+
const probe = coreFactory({ ...base, kbPath: manifest.target, stateDir: taskStateDirOf(manifest.importId) }, log)
|
|
90
|
+
if (typeof probe.loadConfig === 'function') await probe.loadConfig()
|
|
91
|
+
const st = await probe.status().catch(() => null)
|
|
92
|
+
const sameRoot = st && st.kbPath && norm(st.kbPath) === norm(manifest.target)
|
|
93
|
+
if (sameRoot && st.kbId) {
|
|
94
|
+
manifest.targetKbId = st.kbId
|
|
95
|
+
changed = true
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (changed) await saveManifest(stateDir, manifest)
|
|
99
|
+
return manifest
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** 冻结清单(只读;R3:必须在建标准结构之前调用)。 */
|
|
103
|
+
async function plan({ source, mode: modeIn, current }) {
|
|
104
|
+
const srcRaw = String(source ?? '').trim()
|
|
105
|
+
if (srcRaw === '') return { ok: false, reason: 'empty-source', error: 'plan 需要 source(绝对路径)' }
|
|
106
|
+
const mode = modeIn === 'copy' ? 'copy' : 'attach'
|
|
107
|
+
const cur = current ?? (await currentStatus())
|
|
108
|
+
if (mode === 'copy' && !(cur && cur.kbPath)) return { ok: false, reason: 'unbound', error: '复制导入需要先绑定目标知识库' }
|
|
109
|
+
const target = mode === 'copy' ? cur.kbPath : path.resolve(srcRaw)
|
|
110
|
+
const manifest = await planImport({ stateDir, source: srcRaw, target, mode, log, isActive: id => isActive(id) || starting.has(id) })
|
|
111
|
+
if (manifest && manifest.error) return { ok: false, reason: manifest.reason ?? 'plan-failed', error: manifest.error }
|
|
112
|
+
if (manifest.running) {
|
|
113
|
+
return { ok: true, running: true, importId: manifest.importId, mode: manifest.mode, source: manifest.source, target: manifest.target, stage: manifest.stage, counts: manifest.counts, note: manifest.note }
|
|
114
|
+
}
|
|
115
|
+
await stampTarget(manifest)
|
|
116
|
+
return {
|
|
117
|
+
ok: true,
|
|
118
|
+
importId: manifest.importId,
|
|
119
|
+
mode: manifest.mode,
|
|
120
|
+
source: manifest.source,
|
|
121
|
+
target: manifest.target,
|
|
122
|
+
targetKbId: manifest.targetKbId ?? null,
|
|
123
|
+
stage: manifest.stage,
|
|
124
|
+
taskStateDir: manifest.taskStateDir ?? null,
|
|
125
|
+
counts: manifest.counts,
|
|
126
|
+
scan: manifest.scan,
|
|
127
|
+
skippedDirs: manifest.skippedDirs,
|
|
128
|
+
skippedFiles: (manifest.skippedFiles ?? []).length,
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** 启动(后台执行)。校验顺序:id → 清单 → 目标初始化 → 独立 core 实际身份 → 运行。 */
|
|
133
|
+
async function start({ importId }) {
|
|
134
|
+
const pending = starting.get(importId)
|
|
135
|
+
if (pending) {
|
|
136
|
+
const result = await pending
|
|
137
|
+
return result.ok && result.started
|
|
138
|
+
? { ...result, started: false, running: isActive(importId), reason: 'already-running' }
|
|
139
|
+
: result
|
|
140
|
+
}
|
|
141
|
+
// Reserve synchronously, before directory/configuration I/O can yield.
|
|
142
|
+
const admission = Promise.resolve().then(() => startLocked({ importId }))
|
|
143
|
+
starting.set(importId, admission)
|
|
144
|
+
try { return await admission } finally { if (starting.get(importId) === admission) starting.delete(importId) }
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async function startLocked({ importId }) {
|
|
148
|
+
const dirError = await taskDirError(importId)
|
|
149
|
+
if (dirError) return { ok: false, ...dirError }
|
|
150
|
+
const manifest = await readManifest(stateDir, importId)
|
|
151
|
+
if (manifest === null) return { ok: false, reason: 'not-found', error: '找不到导入任务:' + importId }
|
|
152
|
+
if (isActive(importId)) return { ok: true, started: false, running: true, reason: 'already-running', importId, stage: manifest.stage }
|
|
153
|
+
if (manifest.stage === 'done') return { ok: true, started: false, alreadyDone: true, importId, stage: 'done', counts: manifest.counts }
|
|
154
|
+
if (manifest.stage === 'conflict') return { ok: false, reason: 'conflict', error: '上次执行发现源文件在计划后发生变化:请重新 plan 再 run', conflicts: manifest.conflicts ?? [] }
|
|
155
|
+
|
|
156
|
+
// 目标库必须已初始化:没有 kbId 就在目标处初始化(**不切换当前绑定**)
|
|
157
|
+
if (!manifest.targetKbId) {
|
|
158
|
+
const initCore = await currentCoreSafe()
|
|
159
|
+
if (!initCore || typeof initCore.initializeLibrary !== 'function') return { ok: false, reason: 'no-current-core', error: '缺少当前 core,无法初始化任务目标' }
|
|
160
|
+
const init = await initCore.initializeLibrary(manifest.target, { rebuildIndex: true })
|
|
161
|
+
if (!init.ok) return { ok: false, reason: 'target-init-failed', error: '任务目标初始化失败:' + (init.error ?? init.reason ?? 'unknown'), init }
|
|
162
|
+
manifest.targetKbId = init.kbId
|
|
163
|
+
await saveManifest(stateDir, manifest)
|
|
164
|
+
}
|
|
165
|
+
if (!manifest.taskStateDir) {
|
|
166
|
+
manifest.taskStateDir = taskStateDirOf(importId)
|
|
167
|
+
await saveManifest(stateDir, manifest)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const made = await makeTaskCore(manifest)
|
|
171
|
+
if (!made.ok) {
|
|
172
|
+
log('error', `导入 ${importId} 拒绝执行:${made.error}`)
|
|
173
|
+
return { ok: false, reason: made.reason, error: made.error, actualRoot: made.actualRoot ?? null, target: manifest.target }
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const before = await currentStatus()
|
|
177
|
+
const job = { running: true, lastError: null, result: null, target: manifest.target, targetKbId: manifest.targetKbId, startedAt: new Date().toISOString() }
|
|
178
|
+
jobs.set(importId, job)
|
|
179
|
+
job.promise = (async () => {
|
|
180
|
+
let r = null
|
|
181
|
+
try {
|
|
182
|
+
r = await runImport({ core: made.core, stateDir, importId, log })
|
|
183
|
+
} catch (error) {
|
|
184
|
+
job.running = false
|
|
185
|
+
job.lastError = String((error && error.message) ?? error)
|
|
186
|
+
log('error', `导入任务异常:${job.lastError}`)
|
|
187
|
+
// 异常不能让任务永远停在 importing:落一个明确的终态,并把原因写进清单
|
|
188
|
+
try {
|
|
189
|
+
const m = await readManifest(stateDir, importId)
|
|
190
|
+
if (m && !TERMINAL_STAGES.has(m.stage)) {
|
|
191
|
+
m.stage = 'partial'
|
|
192
|
+
m.terminalReasons = [...(m.terminalReasons ?? []), '执行异常:' + job.lastError.slice(0, 160)]
|
|
193
|
+
await saveManifest(stateDir, m)
|
|
194
|
+
}
|
|
195
|
+
} catch {
|
|
196
|
+
/* 清单也写不了时,status() 会用 job.lastError 报 failed(不假装 done) */
|
|
197
|
+
}
|
|
198
|
+
return
|
|
199
|
+
}
|
|
200
|
+
job.result = {
|
|
201
|
+
ok: r.ok === true,
|
|
202
|
+
stage: r.manifest ? r.manifest.stage : null,
|
|
203
|
+
counts: r.manifest ? r.manifest.counts : null,
|
|
204
|
+
canceled: Boolean(r.canceled),
|
|
205
|
+
conflict: Boolean(r.conflict),
|
|
206
|
+
reasons: (r.manifest && r.manifest.terminalReasons) || [],
|
|
207
|
+
}
|
|
208
|
+
if (r.ok !== true) {
|
|
209
|
+
job.running = false
|
|
210
|
+
return
|
|
211
|
+
}
|
|
212
|
+
// running 覆盖到"提交切库"完成:否则轮询会看到 running=false 而 committed 还没写(可观察的竞态)
|
|
213
|
+
try {
|
|
214
|
+
// R1:提交切库只在导入完成且核验通过之后;且当前绑定必须仍是开始时那一个
|
|
215
|
+
const now = await currentStatus()
|
|
216
|
+
if (!now) {
|
|
217
|
+
job.committed = false
|
|
218
|
+
job.commitReason = 'no-status'
|
|
219
|
+
return
|
|
220
|
+
}
|
|
221
|
+
if (norm(now.kbPath) === norm(manifest.target)) {
|
|
222
|
+
job.committed = true
|
|
223
|
+
job.commitReason = 'already-bound'
|
|
224
|
+
return
|
|
225
|
+
}
|
|
226
|
+
const samePath = Boolean(before) && norm(before.kbPath) === norm(now.kbPath)
|
|
227
|
+
const sameKb = Boolean(before) && String(before.kbId ?? '') === String(now.kbId ?? '')
|
|
228
|
+
const beforeRev = before && before.config ? before.config.revision ?? null : null
|
|
229
|
+
const nowRev = now.config ? now.config.revision ?? null : null
|
|
230
|
+
const sameRev = beforeRev === nowRev
|
|
231
|
+
if (!samePath || !sameKb || !sameRev) {
|
|
232
|
+
job.committed = false
|
|
233
|
+
job.commitReason = samePath && sameKb ? 'config-changed' : 'binding-changed'
|
|
234
|
+
log('warn', `导入完成但当前绑定/配置已被用户改动(path=${now.kbPath} rev=${String(beforeRev)}→${String(nowRev)}):不覆盖,保留为待提交(目标 ${manifest.target})`)
|
|
235
|
+
return
|
|
236
|
+
}
|
|
237
|
+
if (typeof commitBinding !== 'function') {
|
|
238
|
+
job.committed = false
|
|
239
|
+
job.commitReason = 'no-commit-hook'
|
|
240
|
+
return
|
|
241
|
+
}
|
|
242
|
+
try {
|
|
243
|
+
const c = await commitBinding(manifest.target, {
|
|
244
|
+
expectedConfigRevision: beforeRev,
|
|
245
|
+
expectedCurrentKbPath: before ? before.kbPath : null,
|
|
246
|
+
expectedCurrentKbId: before ? before.kbId ?? null : null,
|
|
247
|
+
expectedTargetKbId: manifest.targetKbId ?? null,
|
|
248
|
+
})
|
|
249
|
+
job.committed = c && c.ok === true
|
|
250
|
+
job.commitReason = job.committed ? 'committed' : String((c && (c.reason || c.note)) || 'commit-failed')
|
|
251
|
+
job.commit = c
|
|
252
|
+
if (!job.committed) log('warn', `导入完成但切库未成功:${job.commitReason}`)
|
|
253
|
+
} catch (error) {
|
|
254
|
+
job.committed = false
|
|
255
|
+
job.commitReason = 'commit-threw'
|
|
256
|
+
job.commitError = String((error && error.message) ?? error)
|
|
257
|
+
}
|
|
258
|
+
} finally {
|
|
259
|
+
job.running = false
|
|
260
|
+
}
|
|
261
|
+
})()
|
|
262
|
+
return { ok: true, started: true, importId, stage: 'running', mode: manifest.mode, source: manifest.source, target: manifest.target, targetKbId: manifest.targetKbId, taskStateDir: made.taskStateDir }
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
async function status({ importId } = {}) {
|
|
266
|
+
if (importId === undefined || importId === null || String(importId) === '') {
|
|
267
|
+
const imports = await listImports(stateDir)
|
|
268
|
+
return { ok: true, imports: imports.map((m) => ({ ...m, running: isActive(m.importId), terminal: TERMINAL_STAGES.has(m.stage) })) }
|
|
269
|
+
}
|
|
270
|
+
const dirError = await taskDirError(importId)
|
|
271
|
+
if (dirError) return { ok: false, ...dirError }
|
|
272
|
+
const manifest = await readManifest(stateDir, importId)
|
|
273
|
+
if (manifest === null) return { ok: false, reason: 'not-found', error: '找不到导入任务:' + importId }
|
|
274
|
+
const job = jobs.get(importId) ?? null
|
|
275
|
+
const counts = manifest.counts
|
|
276
|
+
// 异常中断(job 已停但清单还写着 importing)→ 如实报 failed,不冒充"仍在跑"也不冒充 done
|
|
277
|
+
const endedByError = Boolean(job && !job.running && job.lastError)
|
|
278
|
+
const stage = endedByError ? 'failed' : manifest.stage
|
|
279
|
+
const terminalReasons = endedByError ? [...(manifest.terminalReasons ?? []), '执行异常:' + String(job.lastError).slice(0, 160)] : manifest.terminalReasons ?? []
|
|
280
|
+
return {
|
|
281
|
+
ok: true,
|
|
282
|
+
importId,
|
|
283
|
+
running: Boolean(job && job.running),
|
|
284
|
+
stage,
|
|
285
|
+
manifestStage: manifest.stage,
|
|
286
|
+
mode: manifest.mode,
|
|
287
|
+
source: manifest.source,
|
|
288
|
+
target: manifest.target,
|
|
289
|
+
targetKbId: manifest.targetKbId ?? null,
|
|
290
|
+
taskStateDir: manifest.taskStateDir ?? null,
|
|
291
|
+
counts,
|
|
292
|
+
scan: manifest.scan,
|
|
293
|
+
verify: manifest.verify ?? null,
|
|
294
|
+
terminalReasons,
|
|
295
|
+
conflicts: (manifest.conflicts ?? []).slice(0, 20),
|
|
296
|
+
lastError: job ? job.lastError : null,
|
|
297
|
+
committed: job ? job.committed === true : false,
|
|
298
|
+
commitReason: job ? job.commitReason ?? null : null,
|
|
299
|
+
recent: manifest.items.filter((it) => it.status === 'failed').slice(0, 10).map((it) => ({ rel: it.rel, error: it.error })),
|
|
300
|
+
samples: manifest.items.filter((it) => it.status === 'done').slice(0, 8).map((it) => ({ rel: it.rel, entryPath: it.entryPath })),
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
async function cancel({ importId } = {}) {
|
|
305
|
+
const dirError = await taskDirError(importId)
|
|
306
|
+
if (dirError) return { ok: false, ...dirError }
|
|
307
|
+
return await cancelImport(stateDir, importId)
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// ── 第二轮:待解析项 → 解析任务(与工具/设置页/流程同一个任务服务)───────────
|
|
311
|
+
/** 列出导入清单里"待解析/待识别"的项,并标出解析是否可用。 */
|
|
312
|
+
async function waiting({ importId } = {}) {
|
|
313
|
+
const dirError = await taskDirError(importId)
|
|
314
|
+
if (dirError) return { ok: false, ...dirError }
|
|
315
|
+
const manifest = await readManifest(stateDir, importId)
|
|
316
|
+
if (!manifest) return { ok: false, reason: 'not-found', error: '没有这个导入任务' }
|
|
317
|
+
const cur = await currentStatus()
|
|
318
|
+
const sameKb = Boolean(cur && cur.kbId && manifest.targetKbId && cur.kbId === manifest.targetKbId)
|
|
319
|
+
const parsing = typeof getParsingService === 'function' ? getParsingService() : null
|
|
320
|
+
const items = (manifest.items ?? [])
|
|
321
|
+
.filter((it) => ['doc', 'media', 'other'].includes(it.class))
|
|
322
|
+
.slice(0, 200)
|
|
323
|
+
.map((it) => ({
|
|
324
|
+
rel: it.rel,
|
|
325
|
+
class: it.class,
|
|
326
|
+
bytes: it.bytes,
|
|
327
|
+
suggestedKind: suggestParseKind(it),
|
|
328
|
+
parseJobId: it.parseJobId ?? null,
|
|
329
|
+
parseStatus: it.parseStatus ?? null,
|
|
330
|
+
entryId: it.entryId ?? null,
|
|
331
|
+
}))
|
|
332
|
+
return {
|
|
333
|
+
ok: true,
|
|
334
|
+
importId,
|
|
335
|
+
stage: manifest.stage,
|
|
336
|
+
targetKbId: manifest.targetKbId ?? null,
|
|
337
|
+
currentKbId: (cur && cur.kbId) || null,
|
|
338
|
+
parseAvailable: Boolean(parsing) && sameKb,
|
|
339
|
+
note: sameKb
|
|
340
|
+
? parsing
|
|
341
|
+
? '可以解析:解析结果落隔离底稿,落库另一步'
|
|
342
|
+
: '解析服务未就绪'
|
|
343
|
+
: '该导入任务的目标库不是当前绑定的库:解析只对当前绑定库内的原件开放(不提供任意路径解析)',
|
|
344
|
+
items,
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/** 把一个待解析项交给解析服务(不直接落库;落库仍是显式一步)。 */
|
|
349
|
+
async function parseItem({ importId, rel, kind, providerId } = {}, { requestedBy } = {}) {
|
|
350
|
+
const dirError = await taskDirError(importId)
|
|
351
|
+
if (dirError) return { ok: false, ...dirError }
|
|
352
|
+
const manifest = await readManifest(stateDir, importId)
|
|
353
|
+
if (!manifest) return { ok: false, reason: 'not-found', error: '没有这个导入任务' }
|
|
354
|
+
const item = (manifest.items ?? []).find((it) => norm(it.rel) === norm(rel))
|
|
355
|
+
if (!item) return { ok: false, reason: 'item-not-found', error: '导入清单里没有这一项:' + String(rel) }
|
|
356
|
+
const cur = await currentStatus()
|
|
357
|
+
if (!cur || !cur.kbId || !manifest.targetKbId || cur.kbId !== manifest.targetKbId) {
|
|
358
|
+
return { ok: false, reason: 'PARSE_TARGET_NOT_BOUND', error: '该导入任务的目标库不是当前绑定的库:拒绝对非当前绑定库的路径发起解析' }
|
|
359
|
+
}
|
|
360
|
+
const parsing = typeof getParsingService === 'function' ? getParsingService() : null
|
|
361
|
+
if (!parsing) return { ok: false, reason: 'PARSE_NOT_ENABLED', error: '解析服务未就绪' }
|
|
362
|
+
const sourceRel = String(item.originalPath || item.rel)
|
|
363
|
+
const kindUse = kind || suggestParseKind(item)
|
|
364
|
+
const submitted = await parsing.submit(
|
|
365
|
+
{ sourceRel, kind: kindUse, providerId, purpose: 'import-item' },
|
|
366
|
+
{ requestedBy: requestedBy?.via === 'tool'
|
|
367
|
+
? { via: 'tool', origin: 'import', importId, gate: requestedBy.gate ?? null, session: requestedBy.session ?? null, agent: requestedBy.agent ?? null }
|
|
368
|
+
: { via: 'import', importId } },
|
|
369
|
+
)
|
|
370
|
+
if (submitted.ok !== true) return { ...submitted, rel: item.rel }
|
|
371
|
+
item.parseJobId = submitted.jobId
|
|
372
|
+
item.parseStatus = submitted.status
|
|
373
|
+
await saveManifest(stateDir, manifest)
|
|
374
|
+
return { ok: true, importId, rel: item.rel, kind: kindUse, sourceRel, jobId: submitted.jobId, status: submitted.status, deduped: submitted.deduped === true }
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function suggestParseKind(item) {
|
|
378
|
+
const ext = String(item.rel ?? '').split('.').pop().toLowerCase()
|
|
379
|
+
if (['wav', 'mp3', 'm4a', 'flac', 'ogg', 'aac', 'mp4'].includes(ext)) return 'asr'
|
|
380
|
+
return 'ocr'
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* 「自动建库 / 识别」一次点击(S4 的两个主动作之二)。
|
|
385
|
+
* R3 的关键顺序:**先冻结清单,再建标准结构**;R1:导入完成并通过核验后才切换当前库。
|
|
386
|
+
*/
|
|
387
|
+
async function setupFolder(folderRaw, modeIn) {
|
|
388
|
+
const raw = String(folderRaw ?? '').trim()
|
|
389
|
+
if (raw === '') return { ok: false, blocked: true, action: 'blocked', note: '路径为空:请先选择或粘贴一个文件夹绝对路径' }
|
|
390
|
+
const mode = modeIn === 'copy' ? 'copy' : 'attach'
|
|
391
|
+
let info = await inspectFolder(raw)
|
|
392
|
+
const base = { ok: false, folder: info.path, kind: info.kind, reasons: info.reasons, info }
|
|
393
|
+
if (info.kind === 'missing') {
|
|
394
|
+
if (info.creatable !== true) return { ...base, blocked: true, action: 'blocked', note: info.reasons.join(';') || '目录不存在且上级不可写' }
|
|
395
|
+
try {
|
|
396
|
+
await mkdir(path.resolve(raw), { recursive: true })
|
|
397
|
+
} catch (error) {
|
|
398
|
+
return { ...base, blocked: true, action: 'create-failed', note: '创建目录失败:' + String((error && (error.code || error.message)) ?? error) }
|
|
399
|
+
}
|
|
400
|
+
info = await inspectFolder(raw)
|
|
401
|
+
if (!info.exists) return { ...base, blocked: true, action: 'create-failed', note: '创建后仍无法识别目录' }
|
|
402
|
+
}
|
|
403
|
+
const base2 = { ok: false, folder: info.path, kind: info.kind, reasons: info.reasons, info }
|
|
404
|
+
if (['not-a-directory', 'incompatible', 'corrupt'].includes(info.kind)) {
|
|
405
|
+
return { ...base2, blocked: true, action: 'blocked', note: info.kind === 'incompatible' || info.kind === 'corrupt' ? '元数据不兼容或已损坏:已拒绝初始化,未改动任何文件' : info.reasons.join(';') }
|
|
406
|
+
}
|
|
407
|
+
if (!info.writable) return { ...base2, blocked: true, action: 'blocked', note: info.reasons.join(';') || '目录不可写' }
|
|
408
|
+
|
|
409
|
+
const cur = await currentStatus()
|
|
410
|
+
const prev = cur && cur.kbPath && norm(cur.kbPath) !== norm(info.path) ? cur : null
|
|
411
|
+
const restore = async () => {
|
|
412
|
+
if (!prev || typeof commitBinding !== 'function') return false
|
|
413
|
+
const now = await currentStatus()
|
|
414
|
+
// 只在「当前绑定仍是那次失败的候选」时回退,不覆盖用户后来的选择
|
|
415
|
+
if (!now || norm(now.kbPath) !== norm(info.path)) return false
|
|
416
|
+
const r = await commitBinding(prev.kbPath, { expectedKbId: prev.kbId ?? null })
|
|
417
|
+
return Boolean(r && r.ok)
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
if (info.kind === 'ours' || info.kind === 'ours-partial') {
|
|
421
|
+
let init = null
|
|
422
|
+
if (info.kind === 'ours-partial') {
|
|
423
|
+
init = await (await currentCoreSafe()).initializeLibrary(info.path, { rebuildIndex: true }).catch((error) => ({ ok: false, reason: 'init-threw', error: String((error && error.message) ?? error) }))
|
|
424
|
+
if (!init.ok) return { ...base2, ok: false, action: 'attach-failed', failed: '初始化未完成:' + (init.error ?? init.reason ?? '') }
|
|
425
|
+
}
|
|
426
|
+
const bound = await (await currentCoreSafe()).bind(info.path, { confirmInit: false })
|
|
427
|
+
if (!bound || bound.ok !== true) return { ...base2, ok: false, action: 'attach-failed', failed: (bound && (bound.note || bound.reason)) || '绑定失败' }
|
|
428
|
+
const after = await currentStatus()
|
|
429
|
+
if (!after || after.healthy !== true) {
|
|
430
|
+
const restored = await restore()
|
|
431
|
+
return { ...base2, ok: false, action: 'attach-failed', failed: '库结构仍不健康:' + ((after && after.healthReason) || 'unknown'), init, bindingRestored: restored }
|
|
432
|
+
}
|
|
433
|
+
return { ...base2, ok: true, action: info.kind === 'ours' ? 'attached' : 'attached-repaired', kbId: after.kbId ?? null, init, after: { kbPath: after.kbPath, kbId: after.kbId ?? null, healthy: after.healthy } }
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
if (info.kind === 'empty') {
|
|
437
|
+
const currentCore = await currentCoreSafe()
|
|
438
|
+
const init = await currentCore.initializeLibrary(info.path, { rebuildIndex: true })
|
|
439
|
+
if (!init.ok) return { ...base2, ok: false, action: 'create-failed', failed: '建库失败:' + (init.error ?? init.reason ?? '') }
|
|
440
|
+
const bound = await currentCore.bind(info.path, { confirmInit: false })
|
|
441
|
+
if (!bound || bound.ok !== true) {
|
|
442
|
+
const restored = await restore()
|
|
443
|
+
return { ...base2, ok: false, action: 'create-failed', failed: (bound && (bound.note || bound.reason)) || '绑定失败', bindingRestored: restored }
|
|
444
|
+
}
|
|
445
|
+
const after = await currentCore.status()
|
|
446
|
+
if (after.healthy !== true) {
|
|
447
|
+
const restored = await restore()
|
|
448
|
+
return { ...base2, ok: false, action: 'create-failed', failed: '建库后库结构仍不健康:' + (after.healthReason || 'unknown'), bindingRestored: restored }
|
|
449
|
+
}
|
|
450
|
+
return { ...base2, ok: true, action: 'created', kbId: init.kbId ?? null, index: { rebuilt: true, entries: after.counts ? after.counts.entries : 0 }, after: { kbPath: after.kbPath, kbId: after.kbId ?? null, healthy: after.healthy } }
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// foreign:先冻结清单(此时还没有标准结构),再建库结构,再后台导入
|
|
454
|
+
if (mode === 'copy') {
|
|
455
|
+
if (!cur || !cur.kbPath) return { ...base2, blocked: true, action: 'blocked', note: '复制导入需要先绑定目标知识库' }
|
|
456
|
+
const planned = await plan({ source: info.path, mode, current: cur })
|
|
457
|
+
if (!planned.ok) return { ...base2, ok: false, action: 'plan-failed', failed: planned.error ?? planned.reason }
|
|
458
|
+
const started = await start({ importId: planned.importId })
|
|
459
|
+
return { ...base2, ok: started.ok === true, action: started.ok ? 'import-started' : 'import-failed', importId: planned.importId, mode, counts: planned.counts, scan: planned.scan, skippedDirs: planned.skippedDirs, started, note: started.ok ? '复制导入已开始(目标 = 当前库);完成后按状态查看' : started.error }
|
|
460
|
+
}
|
|
461
|
+
const planned = await plan({ source: info.path, mode: 'attach', current: cur })
|
|
462
|
+
if (!planned.ok) return { ...base2, ok: false, action: 'plan-failed', failed: planned.error ?? planned.reason }
|
|
463
|
+
const currentCore = await currentCoreSafe()
|
|
464
|
+
const init = await currentCore.initializeLibrary(info.path, { rebuildIndex: false })
|
|
465
|
+
if (!init.ok) return { ...base2, ok: false, action: 'create-failed', failed: '建标准结构失败:' + (init.error ?? init.reason ?? '') }
|
|
466
|
+
const manifest = await readManifest(stateDir, planned.importId)
|
|
467
|
+
manifest.targetKbId = init.kbId
|
|
468
|
+
await saveManifest(stateDir, manifest)
|
|
469
|
+
const started = await start({ importId: planned.importId })
|
|
470
|
+
return {
|
|
471
|
+
...base2,
|
|
472
|
+
ok: started.ok === true,
|
|
473
|
+
action: started.ok ? 'import-started' : 'import-failed',
|
|
474
|
+
importId: planned.importId,
|
|
475
|
+
mode,
|
|
476
|
+
targetKbId: init.kbId,
|
|
477
|
+
counts: planned.counts,
|
|
478
|
+
scan: planned.scan,
|
|
479
|
+
skippedDirs: planned.skippedDirs,
|
|
480
|
+
started,
|
|
481
|
+
note: started.ok ? '已建标准结构并开始导入;导入完成且核验通过后才切换当前库' : started.error,
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
return { plan, start, status, cancel, setupFolder, isActive, jobs, waiting, parseItem }
|
|
486
|
+
}
|