@dikolab/kbdb 0.1.0
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/LICENSE +15 -0
- package/README.md +270 -0
- package/dist/chunk-QCCN7OZH.mjs +82 -0
- package/dist/chunk-QCCN7OZH.mjs.map +7 -0
- package/dist/cli.cjs +3598 -0
- package/dist/cli.cjs.map +7 -0
- package/dist/cli.mjs +3537 -0
- package/dist/cli.mjs.map +7 -0
- package/dist/kbdb-worker.cjs +1659 -0
- package/dist/kbdb-worker.cjs.map +7 -0
- package/dist/mod.cjs +538 -0
- package/dist/mod.cjs.map +7 -0
- package/dist/mod.d.ts +3 -0
- package/dist/mod.mjs +507 -0
- package/dist/mod.mjs.map +7 -0
- package/dist/src/cli.d.ts +1 -0
- package/dist/src/shared/cli/constants/defaults.constant.d.ts +11 -0
- package/dist/src/shared/cli/constants/help-text.constant.d.ts +2 -0
- package/dist/src/shared/cli/functions/dispatch-command.function.d.ts +37 -0
- package/dist/src/shared/cli/functions/ensure-db.function.d.ts +11 -0
- package/dist/src/shared/cli/functions/error-to-message.function.d.ts +7 -0
- package/dist/src/shared/cli/functions/find-db.function.d.ts +13 -0
- package/dist/src/shared/cli/functions/format-output.function.d.ts +15 -0
- package/dist/src/shared/cli/functions/generate-help.function.d.ts +31 -0
- package/dist/src/shared/cli/functions/is-stdin-tty.function.d.ts +7 -0
- package/dist/src/shared/cli/functions/parse-args.function.d.ts +25 -0
- package/dist/src/shared/cli/functions/prompt-user.function.d.ts +13 -0
- package/dist/src/shared/cli/functions/run-agent-create.function.d.ts +58 -0
- package/dist/src/shared/cli/functions/run-agent-delete.function.d.ts +32 -0
- package/dist/src/shared/cli/functions/run-agent-get.function.d.ts +46 -0
- package/dist/src/shared/cli/functions/run-agent-list.function.d.ts +45 -0
- package/dist/src/shared/cli/functions/run-check.function.d.ts +64 -0
- package/dist/src/shared/cli/functions/run-cli.function.d.ts +39 -0
- package/dist/src/shared/cli/functions/run-content.function.d.ts +40 -0
- package/dist/src/shared/cli/functions/run-db-init.function.d.ts +23 -0
- package/dist/src/shared/cli/functions/run-db-migrate.function.d.ts +32 -0
- package/dist/src/shared/cli/functions/run-gc.function.d.ts +38 -0
- package/dist/src/shared/cli/functions/run-init.function.d.ts +27 -0
- package/dist/src/shared/cli/functions/run-learn.function.d.ts +46 -0
- package/dist/src/shared/cli/functions/run-migrate.function.d.ts +57 -0
- package/dist/src/shared/cli/functions/run-rebuild.function.d.ts +40 -0
- package/dist/src/shared/cli/functions/run-search.function.d.ts +39 -0
- package/dist/src/shared/cli/functions/run-skill-delete.function.d.ts +30 -0
- package/dist/src/shared/cli/functions/run-skill-get.function.d.ts +49 -0
- package/dist/src/shared/cli/functions/run-skill-learn.function.d.ts +36 -0
- package/dist/src/shared/cli/functions/run-skill-list.function.d.ts +43 -0
- package/dist/src/shared/cli/functions/run-status.function.d.ts +22 -0
- package/dist/src/shared/cli/functions/run-unlearn.function.d.ts +45 -0
- package/dist/src/shared/cli/index.d.ts +35 -0
- package/dist/src/shared/cli/typings/cli-options.interface.d.ts +53 -0
- package/dist/src/shared/cli/typings/command-result.model.d.ts +15 -0
- package/dist/src/shared/cli/typings/learn-result.model.d.ts +11 -0
- package/dist/src/shared/cli/typings/search-display.model.d.ts +17 -0
- package/dist/src/shared/dir-resolver/functions/resolve-base-dir.function.d.ts +3 -0
- package/dist/src/shared/dir-resolver/functions/resolve-wasm-dir.function.d.ts +1 -0
- package/dist/src/shared/dir-resolver/functions/resolve-worker-script.function.d.ts +2 -0
- package/dist/src/shared/dir-resolver/index.d.ts +4 -0
- package/dist/src/shared/dir-resolver/typings/base-dir.interface.d.ts +4 -0
- package/dist/src/shared/hash/functions/compute-sha256.d.ts +10 -0
- package/dist/src/shared/hash/index.d.ts +1 -0
- package/dist/src/shared/mcp/classes/mcp-server.class.d.ts +55 -0
- package/dist/src/shared/mcp/constants/mcp-error-codes.constant.d.ts +26 -0
- package/dist/src/shared/mcp/functions/create-mcp-server.function.d.ts +11 -0
- package/dist/src/shared/mcp/functions/create-prompt-definitions.function.d.ts +41 -0
- package/dist/src/shared/mcp/functions/create-resource-templates.function.d.ts +7 -0
- package/dist/src/shared/mcp/functions/create-tool-definitions.function.d.ts +7 -0
- package/dist/src/shared/mcp/functions/extract-skill-arguments.function.d.ts +13 -0
- package/dist/src/shared/mcp/functions/handle-agent-create.function.d.ts +29 -0
- package/dist/src/shared/mcp/functions/handle-agent-delete.function.d.ts +28 -0
- package/dist/src/shared/mcp/functions/handle-agent-get.function.d.ts +29 -0
- package/dist/src/shared/mcp/functions/handle-agent-list.function.d.ts +31 -0
- package/dist/src/shared/mcp/functions/handle-completion.function.d.ts +58 -0
- package/dist/src/shared/mcp/functions/handle-prompt-get.function.d.ts +23 -0
- package/dist/src/shared/mcp/functions/handle-resource-read.function.d.ts +26 -0
- package/dist/src/shared/mcp/functions/handle-roots-list.function.d.ts +21 -0
- package/dist/src/shared/mcp/functions/handle-tool-call.function.d.ts +26 -0
- package/dist/src/shared/mcp/functions/parse-skill-content.function.d.ts +15 -0
- package/dist/src/shared/mcp/functions/serialize-skill-content.function.d.ts +9 -0
- package/dist/src/shared/mcp/functions/should-emit-log.function.d.ts +20 -0
- package/dist/src/shared/mcp/index.d.ts +9 -0
- package/dist/src/shared/mcp/typings/agent-types.interface.d.ts +38 -0
- package/dist/src/shared/mcp/typings/log-types.interface.d.ts +17 -0
- package/dist/src/shared/mcp/typings/mcp-client.interface.d.ts +217 -0
- package/dist/src/shared/mcp/typings/mcp-types.interface.d.ts +149 -0
- package/dist/src/shared/mcp/typings/prompt-types.interface.d.ts +37 -0
- package/dist/src/shared/mcp/typings/remove-section-result.model.d.ts +10 -0
- package/dist/src/shared/mcp/typings/sampling-types.interface.d.ts +46 -0
- package/dist/src/shared/mcp/typings/skill-types.interface.d.ts +28 -0
- package/dist/src/shared/mod.d.ts +1 -0
- package/dist/src/shared/platform/functions/get-ipc-path.function.d.ts +11 -0
- package/dist/src/shared/platform/functions/get-tmpdir.function.d.ts +4 -0
- package/dist/src/shared/platform/functions/is-process-alive.function.d.ts +10 -0
- package/dist/src/shared/platform/index.d.ts +3 -0
- package/dist/src/shared/runtime/functions/detect-runtime.d.ts +8 -0
- package/dist/src/shared/runtime/functions/get-args.d.ts +7 -0
- package/dist/src/shared/runtime/index.d.ts +3 -0
- package/dist/src/shared/runtime/typings/runtime.d.ts +2 -0
- package/dist/src/shared/version/constants/version.constant.d.ts +2 -0
- package/dist/src/shared/version/index.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/decode-compose-output.function.d.ts +5 -0
- package/dist/src/shared/wasm-codec/functions/decode-document-manifest-list.function.d.ts +14 -0
- package/dist/src/shared/wasm-codec/functions/decode-document-manifest.function.d.ts +40 -0
- package/dist/src/shared/wasm-codec/functions/decode-f32.function.d.ts +2 -0
- package/dist/src/shared/wasm-codec/functions/decode-key-value-text.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/decode-remove-flag.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/decode-scored-results.function.d.ts +10 -0
- package/dist/src/shared/wasm-codec/functions/decode-section-record-list.function.d.ts +13 -0
- package/dist/src/shared/wasm-codec/functions/decode-section-records.function.d.ts +50 -0
- package/dist/src/shared/wasm-codec/functions/decode-string.function.d.ts +5 -0
- package/dist/src/shared/wasm-codec/functions/decode-u32.function.d.ts +2 -0
- package/dist/src/shared/wasm-codec/functions/decode-u64.function.d.ts +2 -0
- package/dist/src/shared/wasm-codec/functions/encode-add-section-params.function.d.ts +10 -0
- package/dist/src/shared/wasm-codec/functions/encode-group-params.function.d.ts +10 -0
- package/dist/src/shared/wasm-codec/functions/encode-identifier-list.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-kbid-list.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-option-string.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-search-params.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-section-type.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-string.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-type-filter-param.function.d.ts +11 -0
- package/dist/src/shared/wasm-codec/functions/encode-u32.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-update-section-params.function.d.ts +2 -0
- package/dist/src/shared/wasm-codec/index.d.ts +29 -0
- package/dist/src/shared/worker-client/classes/worker-client.class.d.ts +230 -0
- package/dist/src/shared/worker-client/functions/compute-context-id.function.d.ts +11 -0
- package/dist/src/shared/worker-client/functions/create-worker-client.function.d.ts +18 -0
- package/dist/src/shared/worker-client/functions/discover-daemon.function.d.ts +14 -0
- package/dist/src/shared/worker-client/functions/resolve-db-path.function.d.ts +11 -0
- package/dist/src/shared/worker-client/functions/spawn-daemon.function.d.ts +11 -0
- package/dist/src/shared/worker-client/functions/wait-for-daemon.function.d.ts +13 -0
- package/dist/src/shared/worker-client/index.d.ts +22 -0
- package/dist/src/shared/worker-client/typings/add-section-result.model.d.ts +22 -0
- package/dist/src/shared/worker-client/typings/content-result.model.d.ts +12 -0
- package/dist/src/shared/worker-client/typings/daemon-info.model.d.ts +7 -0
- package/dist/src/shared/worker-client/typings/gc-result.model.d.ts +12 -0
- package/dist/src/shared/worker-client/typings/integrity-check-result.model.d.ts +36 -0
- package/dist/src/shared/worker-client/typings/migrate-result.model.d.ts +11 -0
- package/dist/src/shared/worker-client/typings/rebuild-result.model.d.ts +12 -0
- package/dist/src/shared/worker-client/typings/remove-section-result.model.d.ts +7 -0
- package/dist/src/shared/worker-client/typings/search-params.model.d.ts +12 -0
- package/dist/src/shared/worker-client/typings/search-result.model.d.ts +14 -0
- package/dist/src/shared/worker-client/typings/section.model.d.ts +26 -0
- package/dist/src/shared/worker-client/typings/status-result.model.d.ts +14 -0
- package/dist/src/shared/worker-client/typings/version-status.model.d.ts +24 -0
- package/dist/src/shared/worker-client/typings/worker-client-error.interface.d.ts +8 -0
- package/dist/src/shared/worker-client/typings/worker-client-options.interface.d.ts +30 -0
- package/dist/src/shared/worker-daemon/classes/worker-daemon.class.d.ts +147 -0
- package/dist/src/shared/worker-daemon/constants/daemon-defaults.constant.d.ts +24 -0
- package/dist/src/shared/worker-daemon/functions/create-host-imports.function.d.ts +68 -0
- package/dist/src/shared/worker-daemon/functions/create-ipc-server.function.d.ts +18 -0
- package/dist/src/shared/worker-daemon/functions/load-wasm-modules.function.d.ts +19 -0
- package/dist/src/shared/worker-daemon/functions/read-config.function.d.ts +12 -0
- package/dist/src/shared/worker-daemon/functions/run-worker.function.d.ts +26 -0
- package/dist/src/shared/worker-daemon/functions/start-daemon.function.d.ts +13 -0
- package/dist/src/shared/worker-daemon/index.d.ts +9 -0
- package/dist/src/shared/worker-daemon/typings/daemon-config.interface.d.ts +13 -0
- package/dist/src/shared/worker-daemon/typings/ipc-handler.interface.d.ts +36 -0
- package/dist/src/shared/worker-daemon/typings/wasm-modules.interface.d.ts +7 -0
- package/dist/src/worker.d.ts +1 -0
- package/dist/vitest.config.d.ts +2 -0
- package/dist/worker.mjs +1615 -0
- package/dist/worker.mjs.map +7 -0
- package/mod.ts +17 -0
- package/package.json +85 -0
- package/src/cli.ts +62 -0
- package/src/shared/cli/constants/defaults.constant.ts +19 -0
- package/src/shared/cli/constants/help-text.constant.ts +4 -0
- package/src/shared/cli/functions/dispatch-command.function.ts +338 -0
- package/src/shared/cli/functions/ensure-db.function.ts +21 -0
- package/src/shared/cli/functions/error-to-message.function.ts +9 -0
- package/src/shared/cli/functions/find-db.function.ts +20 -0
- package/src/shared/cli/functions/format-output.function.ts +64 -0
- package/src/shared/cli/functions/generate-help.function.ts +599 -0
- package/src/shared/cli/functions/is-stdin-tty.function.ts +12 -0
- package/src/shared/cli/functions/parse-args.function.ts +133 -0
- package/src/shared/cli/functions/prompt-user.function.ts +36 -0
- package/src/shared/cli/functions/run-agent-create.function.ts +114 -0
- package/src/shared/cli/functions/run-agent-delete.function.ts +47 -0
- package/src/shared/cli/functions/run-agent-get.function.ts +166 -0
- package/src/shared/cli/functions/run-agent-list.function.ts +58 -0
- package/src/shared/cli/functions/run-check.function.ts +78 -0
- package/src/shared/cli/functions/run-cli.function.ts +299 -0
- package/src/shared/cli/functions/run-content.function.ts +47 -0
- package/src/shared/cli/functions/run-db-init.function.ts +44 -0
- package/src/shared/cli/functions/run-db-migrate.function.ts +40 -0
- package/src/shared/cli/functions/run-gc.function.ts +45 -0
- package/src/shared/cli/functions/run-init.function.ts +91 -0
- package/src/shared/cli/functions/run-learn.function.ts +171 -0
- package/src/shared/cli/functions/run-migrate.function.ts +85 -0
- package/src/shared/cli/functions/run-rebuild.function.ts +47 -0
- package/src/shared/cli/functions/run-search.function.ts +62 -0
- package/src/shared/cli/functions/run-skill-delete.function.ts +47 -0
- package/src/shared/cli/functions/run-skill-get.function.ts +90 -0
- package/src/shared/cli/functions/run-skill-learn.function.ts +70 -0
- package/src/shared/cli/functions/run-skill-list.function.ts +74 -0
- package/src/shared/cli/functions/run-status.function.ts +29 -0
- package/src/shared/cli/functions/run-unlearn.function.ts +58 -0
- package/src/shared/cli/index.ts +48 -0
- package/src/shared/cli/typings/cli-options.interface.ts +55 -0
- package/src/shared/cli/typings/command-result.model.ts +15 -0
- package/src/shared/cli/typings/learn-result.model.ts +11 -0
- package/src/shared/cli/typings/search-display.model.ts +17 -0
- package/src/shared/dir-resolver/functions/resolve-base-dir.function.ts +25 -0
- package/src/shared/dir-resolver/functions/resolve-wasm-dir.function.ts +5 -0
- package/src/shared/dir-resolver/functions/resolve-worker-script.function.ts +13 -0
- package/src/shared/dir-resolver/index.ts +7 -0
- package/src/shared/dir-resolver/typings/base-dir.interface.ts +4 -0
- package/src/shared/hash/functions/compute-sha256.ts +17 -0
- package/src/shared/hash/index.ts +1 -0
- package/src/shared/mcp/classes/mcp-server.class.ts +448 -0
- package/src/shared/mcp/constants/mcp-error-codes.constant.ts +30 -0
- package/src/shared/mcp/functions/create-mcp-server.function.ts +14 -0
- package/src/shared/mcp/functions/create-prompt-definitions.function.ts +102 -0
- package/src/shared/mcp/functions/create-resource-templates.function.ts +23 -0
- package/src/shared/mcp/functions/create-tool-definitions.function.ts +401 -0
- package/src/shared/mcp/functions/extract-skill-arguments.function.ts +27 -0
- package/src/shared/mcp/functions/handle-agent-create.function.ts +116 -0
- package/src/shared/mcp/functions/handle-agent-delete.function.ts +50 -0
- package/src/shared/mcp/functions/handle-agent-get.function.ts +160 -0
- package/src/shared/mcp/functions/handle-agent-list.function.ts +50 -0
- package/src/shared/mcp/functions/handle-completion.function.ts +114 -0
- package/src/shared/mcp/functions/handle-prompt-get.function.ts +214 -0
- package/src/shared/mcp/functions/handle-resource-read.function.ts +56 -0
- package/src/shared/mcp/functions/handle-roots-list.function.ts +29 -0
- package/src/shared/mcp/functions/handle-tool-call.function.ts +464 -0
- package/src/shared/mcp/functions/parse-skill-content.function.ts +38 -0
- package/src/shared/mcp/functions/serialize-skill-content.function.ts +12 -0
- package/src/shared/mcp/functions/should-emit-log.function.ts +38 -0
- package/src/shared/mcp/index.ts +28 -0
- package/src/shared/mcp/typings/agent-types.interface.ts +39 -0
- package/src/shared/mcp/typings/log-types.interface.ts +26 -0
- package/src/shared/mcp/typings/mcp-client.interface.ts +252 -0
- package/src/shared/mcp/typings/mcp-types.interface.ts +158 -0
- package/src/shared/mcp/typings/prompt-types.interface.ts +39 -0
- package/src/shared/mcp/typings/remove-section-result.model.ts +10 -0
- package/src/shared/mcp/typings/sampling-types.interface.ts +48 -0
- package/src/shared/mcp/typings/skill-types.interface.ts +29 -0
- package/src/shared/mod.ts +1 -0
- package/src/shared/platform/functions/get-ipc-path.function.ts +19 -0
- package/src/shared/platform/functions/get-tmpdir.function.ts +8 -0
- package/src/shared/platform/functions/is-process-alive.function.ts +17 -0
- package/src/shared/platform/index.ts +3 -0
- package/src/shared/runtime/functions/detect-runtime.ts +14 -0
- package/src/shared/runtime/functions/get-args.ts +16 -0
- package/src/shared/runtime/index.ts +3 -0
- package/src/shared/runtime/typings/runtime.ts +2 -0
- package/src/shared/version/constants/version.constant.ts +2 -0
- package/src/shared/version/index.ts +1 -0
- package/src/shared/wasm-codec/functions/decode-compose-output.function.ts +16 -0
- package/src/shared/wasm-codec/functions/decode-document-manifest-list.function.ts +70 -0
- package/src/shared/wasm-codec/functions/decode-document-manifest.function.ts +87 -0
- package/src/shared/wasm-codec/functions/decode-f32.function.ts +16 -0
- package/src/shared/wasm-codec/functions/decode-key-value-text.function.ts +15 -0
- package/src/shared/wasm-codec/functions/decode-remove-flag.function.ts +3 -0
- package/src/shared/wasm-codec/functions/decode-scored-results.function.ts +54 -0
- package/src/shared/wasm-codec/functions/decode-section-record-list.function.ts +20 -0
- package/src/shared/wasm-codec/functions/decode-section-records.function.ts +162 -0
- package/src/shared/wasm-codec/functions/decode-string.function.ts +22 -0
- package/src/shared/wasm-codec/functions/decode-u32.function.ts +16 -0
- package/src/shared/wasm-codec/functions/decode-u64.function.ts +16 -0
- package/src/shared/wasm-codec/functions/encode-add-section-params.function.ts +34 -0
- package/src/shared/wasm-codec/functions/encode-group-params.function.ts +28 -0
- package/src/shared/wasm-codec/functions/encode-identifier-list.function.ts +17 -0
- package/src/shared/wasm-codec/functions/encode-kbid-list.function.ts +17 -0
- package/src/shared/wasm-codec/functions/encode-option-string.function.ts +14 -0
- package/src/shared/wasm-codec/functions/encode-search-params.function.ts +9 -0
- package/src/shared/wasm-codec/functions/encode-section-type.function.ts +18 -0
- package/src/shared/wasm-codec/functions/encode-string.function.ts +9 -0
- package/src/shared/wasm-codec/functions/encode-type-filter-param.function.ts +13 -0
- package/src/shared/wasm-codec/functions/encode-u32.function.ts +5 -0
- package/src/shared/wasm-codec/functions/encode-update-section-params.function.ts +16 -0
- package/src/shared/wasm-codec/index.ts +36 -0
- package/src/shared/worker-client/classes/worker-client.class.ts +427 -0
- package/src/shared/worker-client/functions/compute-context-id.function.ts +18 -0
- package/src/shared/worker-client/functions/create-worker-client.function.ts +70 -0
- package/src/shared/worker-client/functions/discover-daemon.function.ts +47 -0
- package/src/shared/worker-client/functions/resolve-db-path.function.ts +21 -0
- package/src/shared/worker-client/functions/spawn-daemon.function.ts +35 -0
- package/src/shared/worker-client/functions/wait-for-daemon.function.ts +34 -0
- package/src/shared/worker-client/index.ts +31 -0
- package/src/shared/worker-client/typings/add-section-result.model.ts +22 -0
- package/src/shared/worker-client/typings/content-result.model.ts +12 -0
- package/src/shared/worker-client/typings/daemon-info.model.ts +7 -0
- package/src/shared/worker-client/typings/gc-result.model.ts +12 -0
- package/src/shared/worker-client/typings/integrity-check-result.model.ts +43 -0
- package/src/shared/worker-client/typings/migrate-result.model.ts +11 -0
- package/src/shared/worker-client/typings/rebuild-result.model.ts +12 -0
- package/src/shared/worker-client/typings/remove-section-result.model.ts +7 -0
- package/src/shared/worker-client/typings/search-params.model.ts +12 -0
- package/src/shared/worker-client/typings/search-result.model.ts +14 -0
- package/src/shared/worker-client/typings/section.model.ts +27 -0
- package/src/shared/worker-client/typings/status-result.model.ts +14 -0
- package/src/shared/worker-client/typings/version-status.model.ts +28 -0
- package/src/shared/worker-client/typings/worker-client-error.interface.ts +8 -0
- package/src/shared/worker-client/typings/worker-client-options.interface.ts +30 -0
- package/src/shared/worker-daemon/classes/worker-daemon.class.ts +1001 -0
- package/src/shared/worker-daemon/constants/daemon-defaults.constant.ts +29 -0
- package/src/shared/worker-daemon/functions/create-host-imports.function.ts +312 -0
- package/src/shared/worker-daemon/functions/create-ipc-server.function.ts +83 -0
- package/src/shared/worker-daemon/functions/load-wasm-modules.function.ts +98 -0
- package/src/shared/worker-daemon/functions/read-config.function.ts +83 -0
- package/src/shared/worker-daemon/functions/run-worker.function.ts +57 -0
- package/src/shared/worker-daemon/functions/start-daemon.function.ts +74 -0
- package/src/shared/worker-daemon/index.ts +16 -0
- package/src/shared/worker-daemon/typings/daemon-config.interface.ts +13 -0
- package/src/shared/worker-daemon/typings/ipc-handler.interface.ts +39 -0
- package/src/shared/worker-daemon/typings/wasm-modules.interface.ts +7 -0
- package/src/worker.ts +34 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single section record decoded from WASM binary output.
|
|
3
|
+
*
|
|
4
|
+
* Represents a stored knowledge-base section with all its metadata
|
|
5
|
+
* and token counts as returned by `worker_read_sections` or
|
|
6
|
+
* `worker_list_by_type`.
|
|
7
|
+
*/
|
|
8
|
+
export interface SectionRecord {
|
|
9
|
+
/** Unique knowledge-base identifier for this section. */
|
|
10
|
+
kbid: string;
|
|
11
|
+
/** Document identifier this section belongs to, or `null`. */
|
|
12
|
+
docid: string | null;
|
|
13
|
+
/** Semantic type discriminant: `'text'`, `'code'`, or `'image'`. */
|
|
14
|
+
sectionType: string;
|
|
15
|
+
/** MIME type string, present only for `'code'` and `'image'` types. */
|
|
16
|
+
mimeType?: string;
|
|
17
|
+
/** Human-readable title for the section, or `null`. */
|
|
18
|
+
title: string | null;
|
|
19
|
+
/** Optional description of the section content, or `null`. */
|
|
20
|
+
description: string | null;
|
|
21
|
+
/** Raw text or base64-encoded content of the section. */
|
|
22
|
+
content: string;
|
|
23
|
+
/** Byte size of the stored content. */
|
|
24
|
+
size: number;
|
|
25
|
+
/** Section creation timestamp as a Unix epoch value. */
|
|
26
|
+
createdAt: bigint;
|
|
27
|
+
/** Integrity checksum of the stored content. */
|
|
28
|
+
checksum: string;
|
|
29
|
+
/** Total number of tokens in the section. */
|
|
30
|
+
tokenCount: number;
|
|
31
|
+
/** Number of heading tokens in the section. */
|
|
32
|
+
headingTokenCount: number;
|
|
33
|
+
/** Number of body tokens in the section. */
|
|
34
|
+
bodyTokenCount: number;
|
|
35
|
+
/** Number of code tokens in the section. */
|
|
36
|
+
codeTokenCount: number;
|
|
37
|
+
/** Application-level type name assigned to this section. */
|
|
38
|
+
typeName: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Decodes a list of `SectionRecord` values from WASM binary output.
|
|
42
|
+
*
|
|
43
|
+
* Reads a leading u32 count followed by that many encoded records.
|
|
44
|
+
* Each record is decoded in field order as produced by the Rust
|
|
45
|
+
* `SectionRecord::encode` implementation.
|
|
46
|
+
*
|
|
47
|
+
* @param bytes - raw bytes returned by a WASM section-list export
|
|
48
|
+
* @returns decoded array of section records, empty when count is zero
|
|
49
|
+
*/
|
|
50
|
+
export declare function decodeSectionRecords(bytes: Uint8Array): SectionRecord[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface AddSectionInput {
|
|
2
|
+
sectionType: 'text' | 'code' | 'image';
|
|
3
|
+
mimeType?: string;
|
|
4
|
+
content: string;
|
|
5
|
+
title?: string | null;
|
|
6
|
+
description?: string | null;
|
|
7
|
+
docid?: string | null;
|
|
8
|
+
typeName?: string | null;
|
|
9
|
+
}
|
|
10
|
+
export declare function encodeAddSectionParams(params: AddSectionInput): Uint8Array;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encodes parameters for the `worker_group_sections` WASM call into
|
|
3
|
+
* a single byte buffer: title, kbid list, then doc type tag.
|
|
4
|
+
*
|
|
5
|
+
* @param title - human-readable document title
|
|
6
|
+
* @param kbids - identifiers of the sections to group
|
|
7
|
+
* @param docType - application-level document type tag; defaults to
|
|
8
|
+
* empty string when not specified
|
|
9
|
+
*/
|
|
10
|
+
export declare function encodeGroupParams(title: string, kbids: string[], docType?: string): Uint8Array;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function encodeIdentifierList(ids: string[]): Uint8Array;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function encodeKbidList(kbids: string[]): Uint8Array;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function encodeOptionString(value: string | null | undefined): Uint8Array;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function encodeSearchParams(query: string, mode?: string, limit?: number): Uint8Array;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function encodeSectionType(kind: 'text' | 'code' | 'image', mimeType?: string): Uint8Array;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function encodeString(value: string): Uint8Array;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encodes a type filter string as raw UTF-8 bytes for WASM input.
|
|
3
|
+
*
|
|
4
|
+
* Used to pass a type name to WASM exports such as
|
|
5
|
+
* `worker_list_by_type` and `worker_list_docs_by_type`, which accept
|
|
6
|
+
* a plain UTF-8 byte slice without a length prefix.
|
|
7
|
+
*
|
|
8
|
+
* @param typeStr - the type name to filter by (e.g. `'article'`)
|
|
9
|
+
* @returns UTF-8 encoded bytes ready to pass to the WASM export
|
|
10
|
+
*/
|
|
11
|
+
export declare function encodeTypeFilterParam(typeStr: string): Uint8Array;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function encodeU32(value: number): Uint8Array;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export { encodeString } from './functions/encode-string.function.ts';
|
|
2
|
+
export { encodeU32 } from './functions/encode-u32.function.ts';
|
|
3
|
+
export { encodeOptionString } from './functions/encode-option-string.function.ts';
|
|
4
|
+
export { encodeSectionType } from './functions/encode-section-type.function.ts';
|
|
5
|
+
export { encodeAddSectionParams } from './functions/encode-add-section-params.function.ts';
|
|
6
|
+
export { encodeUpdateSectionParams } from './functions/encode-update-section-params.function.ts';
|
|
7
|
+
export { encodeKbidList } from './functions/encode-kbid-list.function.ts';
|
|
8
|
+
export { encodeGroupParams } from './functions/encode-group-params.function.ts';
|
|
9
|
+
export { encodeIdentifierList } from './functions/encode-identifier-list.function.ts';
|
|
10
|
+
export { encodeSearchParams } from './functions/encode-search-params.function.ts';
|
|
11
|
+
export { encodeTypeFilterParam } from './functions/encode-type-filter-param.function.ts';
|
|
12
|
+
export { decodeString } from './functions/decode-string.function.ts';
|
|
13
|
+
export { decodeU32 } from './functions/decode-u32.function.ts';
|
|
14
|
+
export { decodeF32 } from './functions/decode-f32.function.ts';
|
|
15
|
+
export { decodeU64 } from './functions/decode-u64.function.ts';
|
|
16
|
+
export { decodeScoredResults } from './functions/decode-scored-results.function.ts';
|
|
17
|
+
export { decodeSectionRecords } from './functions/decode-section-records.function.ts';
|
|
18
|
+
export { decodeSectionRecordList } from './functions/decode-section-record-list.function.ts';
|
|
19
|
+
export { decodeDocumentManifest } from './functions/decode-document-manifest.function.ts';
|
|
20
|
+
export { decodeDocumentManifestList } from './functions/decode-document-manifest-list.function.ts';
|
|
21
|
+
export { decodeComposeOutput } from './functions/decode-compose-output.function.ts';
|
|
22
|
+
export { decodeKeyValueText } from './functions/decode-key-value-text.function.ts';
|
|
23
|
+
export { decodeRemoveFlag } from './functions/decode-remove-flag.function.ts';
|
|
24
|
+
export type { DecodeResult } from './functions/decode-string.function.ts';
|
|
25
|
+
export type { AddSectionInput } from './functions/encode-add-section-params.function.ts';
|
|
26
|
+
export type { ScoredResult, TermMatch, } from './functions/decode-scored-results.function.ts';
|
|
27
|
+
export type { SectionRecord } from './functions/decode-section-records.function.ts';
|
|
28
|
+
export type { DocumentManifest, DocumentSection, } from './functions/decode-document-manifest.function.ts';
|
|
29
|
+
export type { ComposeOutput } from './functions/decode-compose-output.function.ts';
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import type { SearchParams } from '../typings/search-params.model.ts';
|
|
2
|
+
import type { SearchResult } from '../typings/search-result.model.ts';
|
|
3
|
+
import type { AddSectionParams, Section } from '../typings/section.model.ts';
|
|
4
|
+
import type { StatusResult } from '../typings/status-result.model.ts';
|
|
5
|
+
import type { AddSectionResult } from '../typings/add-section-result.model.ts';
|
|
6
|
+
import type { RemoveSectionResult } from '../typings/remove-section-result.model.ts';
|
|
7
|
+
import type { ContentResult } from '../typings/content-result.model.ts';
|
|
8
|
+
import type { IntegrityCheckResult } from '../typings/integrity-check-result.model.ts';
|
|
9
|
+
import type { GcResult } from '../typings/gc-result.model.ts';
|
|
10
|
+
import type { RebuildResult } from '../typings/rebuild-result.model.ts';
|
|
11
|
+
import type { MigrateResult } from '../typings/migrate-result.model.ts';
|
|
12
|
+
import type { VersionStatus } from '../typings/version-status.model.ts';
|
|
13
|
+
import type { SectionRecord } from '../../wasm-codec/functions/decode-section-records.function.ts';
|
|
14
|
+
import type { DocumentManifest } from '../../wasm-codec/functions/decode-document-manifest.function.ts';
|
|
15
|
+
/**
|
|
16
|
+
* IPC client that communicates with the worker daemon over a Unix
|
|
17
|
+
* domain socket (or Windows named pipe) using JSON-RPC 2.0 with
|
|
18
|
+
* newline-delimited message framing.
|
|
19
|
+
*
|
|
20
|
+
* Call `connect()` before any other method and `disconnect()` when
|
|
21
|
+
* done to release the underlying socket.
|
|
22
|
+
*/
|
|
23
|
+
export declare class WorkerClient {
|
|
24
|
+
private readonly socketPath;
|
|
25
|
+
private readonly contextId;
|
|
26
|
+
/** Underlying socket; `null` when not connected. */
|
|
27
|
+
private socket;
|
|
28
|
+
/** Monotonically increasing request ID counter. */
|
|
29
|
+
private nextId;
|
|
30
|
+
/** Map of outstanding request IDs to their resolve/reject pairs. */
|
|
31
|
+
private readonly pending;
|
|
32
|
+
/** Partial line buffer for split TCP/IPC frames. */
|
|
33
|
+
private buffer;
|
|
34
|
+
/**
|
|
35
|
+
* @param socketPath - absolute path to the daemon's IPC socket
|
|
36
|
+
* (or Windows named pipe path)
|
|
37
|
+
* @param contextId - 16-character context identifier sent as
|
|
38
|
+
* `ctx` in every JSON-RPC request
|
|
39
|
+
*/
|
|
40
|
+
constructor(socketPath: string, contextId: string);
|
|
41
|
+
/**
|
|
42
|
+
* Establishes the IPC connection to the worker daemon.
|
|
43
|
+
*
|
|
44
|
+
* @throws {Error} if the connection cannot be established
|
|
45
|
+
*/
|
|
46
|
+
connect(): Promise<void>;
|
|
47
|
+
/** Destroys the IPC socket and clears the connection state. */
|
|
48
|
+
disconnect(): void;
|
|
49
|
+
/**
|
|
50
|
+
* Searches the knowledge base.
|
|
51
|
+
*
|
|
52
|
+
* @param params - query parameters including the search string
|
|
53
|
+
* @returns ranked list of matching sections
|
|
54
|
+
*/
|
|
55
|
+
search(params: SearchParams): Promise<SearchResult[]>;
|
|
56
|
+
/**
|
|
57
|
+
* Adds a new section to the knowledge base.
|
|
58
|
+
*
|
|
59
|
+
* @param params - section content and metadata
|
|
60
|
+
* @returns the result including the assigned knowledge-base
|
|
61
|
+
* identifier and indexing statistics
|
|
62
|
+
*/
|
|
63
|
+
addSection(params: AddSectionParams): Promise<AddSectionResult>;
|
|
64
|
+
/**
|
|
65
|
+
* Replaces an existing section's content and metadata.
|
|
66
|
+
*
|
|
67
|
+
* @param kbid - identifier of the section to update
|
|
68
|
+
* @param params - new content and metadata
|
|
69
|
+
* @returns the knowledge-base identifier of the updated section
|
|
70
|
+
*/
|
|
71
|
+
updateSection(kbid: string, params: AddSectionParams): Promise<string>;
|
|
72
|
+
/**
|
|
73
|
+
* Removes a section from the knowledge base.
|
|
74
|
+
*
|
|
75
|
+
* @param kbid - identifier of the section to remove
|
|
76
|
+
* @returns removal result with `removed` flag and elapsed time
|
|
77
|
+
*/
|
|
78
|
+
removeSection(kbid: string): Promise<RemoveSectionResult>;
|
|
79
|
+
/**
|
|
80
|
+
* Retrieves multiple sections by their identifiers.
|
|
81
|
+
*
|
|
82
|
+
* @param kbids - list of knowledge-base identifiers to fetch
|
|
83
|
+
* @returns sections in the order their IDs were requested
|
|
84
|
+
*/
|
|
85
|
+
readSections(kbids: string[]): Promise<Section[]>;
|
|
86
|
+
/**
|
|
87
|
+
* Groups a set of sections under a named document.
|
|
88
|
+
*
|
|
89
|
+
* @param title - human-readable document title
|
|
90
|
+
* @param kbids - identifiers of the sections to group
|
|
91
|
+
* @param docType - application-level document type tag; omit or
|
|
92
|
+
* pass an empty string for untagged documents
|
|
93
|
+
* @returns the assigned document identifier
|
|
94
|
+
*/
|
|
95
|
+
groupSections(title: string, kbids: string[], docType?: string): Promise<string>;
|
|
96
|
+
/**
|
|
97
|
+
* Removes the document grouping for the given document.
|
|
98
|
+
*
|
|
99
|
+
* The sections themselves are not deleted; only the grouping
|
|
100
|
+
* record is removed.
|
|
101
|
+
*
|
|
102
|
+
* @param docid - identifier of the document grouping to remove
|
|
103
|
+
*/
|
|
104
|
+
removeGrouping(docid: string): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Retrieves a full document record including its sections.
|
|
107
|
+
*
|
|
108
|
+
* @param docid - identifier of the document to retrieve
|
|
109
|
+
* @returns the document record as returned by the daemon
|
|
110
|
+
*/
|
|
111
|
+
retrieveDocument(docid: string): Promise<unknown>;
|
|
112
|
+
/**
|
|
113
|
+
* Composes a rendered Markdown document from one or more kbid
|
|
114
|
+
* or docid identifiers.
|
|
115
|
+
*
|
|
116
|
+
* @param ids - list of kbid or docid identifiers (may be mixed)
|
|
117
|
+
* @returns composed Markdown result with character count
|
|
118
|
+
*/
|
|
119
|
+
content(ids: string[]): Promise<ContentResult>;
|
|
120
|
+
/**
|
|
121
|
+
* Runs an integrity check on the knowledge-base database.
|
|
122
|
+
*
|
|
123
|
+
* @returns a report of all issues found; `ok` is `true` when
|
|
124
|
+
* no errors were detected
|
|
125
|
+
*/
|
|
126
|
+
integrityCheck(): Promise<IntegrityCheckResult>;
|
|
127
|
+
/**
|
|
128
|
+
* Removes unreferenced sections from the database.
|
|
129
|
+
*
|
|
130
|
+
* @returns a report of sections removed and bytes freed
|
|
131
|
+
*/
|
|
132
|
+
gc(): Promise<GcResult>;
|
|
133
|
+
/**
|
|
134
|
+
* Reconstructs all index files from section files and document
|
|
135
|
+
* manifests on disk. Text and code sections are re-tokenized;
|
|
136
|
+
* image sections are skipped.
|
|
137
|
+
*
|
|
138
|
+
* @returns a report of sections and terms re-indexed
|
|
139
|
+
*/
|
|
140
|
+
rebuildIndexes(): Promise<RebuildResult>;
|
|
141
|
+
/**
|
|
142
|
+
* Invalidates the in-memory cache entry for a single section.
|
|
143
|
+
*
|
|
144
|
+
* @param kbid - identifier of the section to evict from cache
|
|
145
|
+
*/
|
|
146
|
+
invalidate(kbid: string): Promise<void>;
|
|
147
|
+
/** Clears all entries from the daemon's in-memory cache. */
|
|
148
|
+
invalidateAll(): Promise<void>;
|
|
149
|
+
/**
|
|
150
|
+
* Retrieves diagnostic status information from the daemon.
|
|
151
|
+
*
|
|
152
|
+
* @returns current initialization state and cache statistics
|
|
153
|
+
*/
|
|
154
|
+
status(): Promise<StatusResult>;
|
|
155
|
+
/**
|
|
156
|
+
* Returns database metadata and status from the daemon,
|
|
157
|
+
* including document count, section count, index size, and
|
|
158
|
+
* cache statistics.
|
|
159
|
+
*
|
|
160
|
+
* @returns database metadata from the daemon's cached state
|
|
161
|
+
*/
|
|
162
|
+
dbStatus(): Promise<StatusResult>;
|
|
163
|
+
/**
|
|
164
|
+
* Initialises a new `.kbdb` database directory at the given path
|
|
165
|
+
* by sending an init request to the worker daemon.
|
|
166
|
+
*
|
|
167
|
+
* The daemon creates all required subdirectories and seed files via
|
|
168
|
+
* the `worker_init_directory` WASM export.
|
|
169
|
+
*
|
|
170
|
+
* @param targetPath - absolute path to the directory that will
|
|
171
|
+
* contain the new `.kbdb` database
|
|
172
|
+
* @throws {Error} if the `.kbdb` directory already exists or the
|
|
173
|
+
* daemon cannot create the layout
|
|
174
|
+
*/
|
|
175
|
+
initDirectory(targetPath: string): Promise<void>;
|
|
176
|
+
/**
|
|
177
|
+
* Runs all pending database migrations for the `.kbdb` directory
|
|
178
|
+
* at the given path.
|
|
179
|
+
*
|
|
180
|
+
* Delegates to the `worker_migrate` WASM export on the daemon.
|
|
181
|
+
* Each migration step updates `catalog.toml` on success, so
|
|
182
|
+
* retrying after a partial failure is safe.
|
|
183
|
+
*
|
|
184
|
+
* @param targetPath - absolute path to the `.kbdb` database root
|
|
185
|
+
* @returns migration report with old version, new version, and
|
|
186
|
+
* number of migration steps applied
|
|
187
|
+
*/
|
|
188
|
+
migrateDatabase(targetPath: string): Promise<MigrateResult>;
|
|
189
|
+
/**
|
|
190
|
+
* Checks the format version of the `.kbdb` database at the given
|
|
191
|
+
* path against the version required by the current WASM engine.
|
|
192
|
+
*
|
|
193
|
+
* This is a read-only operation: it reads `catalog.toml` and
|
|
194
|
+
* returns the compatibility status without making any changes.
|
|
195
|
+
*
|
|
196
|
+
* @param targetPath - absolute path to the `.kbdb` database root
|
|
197
|
+
* @returns version compatibility report
|
|
198
|
+
*/
|
|
199
|
+
checkVersion(targetPath: string): Promise<VersionStatus>;
|
|
200
|
+
/**
|
|
201
|
+
* Retrieves all sections whose type name matches the given string.
|
|
202
|
+
*
|
|
203
|
+
* @param sectionType - the application-level type name to filter by
|
|
204
|
+
* @returns all section records with a matching type name
|
|
205
|
+
*/
|
|
206
|
+
listByType(sectionType: string): Promise<SectionRecord[]>;
|
|
207
|
+
/**
|
|
208
|
+
* Retrieves all documents whose type name matches the given string.
|
|
209
|
+
*
|
|
210
|
+
* @param docType - the application-level document type to filter by
|
|
211
|
+
* @returns all document manifests with a matching type name
|
|
212
|
+
*/
|
|
213
|
+
listDocumentsByType(docType: string): Promise<DocumentManifest[]>;
|
|
214
|
+
/**
|
|
215
|
+
* Sends a JSON-RPC 2.0 request and awaits the response.
|
|
216
|
+
*
|
|
217
|
+
* @param method - the RPC method name
|
|
218
|
+
* @param params - parameters to include in the request
|
|
219
|
+
* @throws {Error} if not connected
|
|
220
|
+
* @throws {Error} when the daemon returns an error response
|
|
221
|
+
*/
|
|
222
|
+
private call;
|
|
223
|
+
/**
|
|
224
|
+
* Processes incoming data from the socket, splitting on newlines
|
|
225
|
+
* and dispatching complete JSON-RPC response objects.
|
|
226
|
+
*
|
|
227
|
+
* @param data - raw string chunk received from the socket
|
|
228
|
+
*/
|
|
229
|
+
private handleData;
|
|
230
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes a short context identifier for an absolute path.
|
|
3
|
+
*
|
|
4
|
+
* Hashes the path with SHA-256 and returns the first 16 hex
|
|
5
|
+
* characters. The result is stable for the same input and unique
|
|
6
|
+
* enough to avoid accidental collisions across typical path sets.
|
|
7
|
+
*
|
|
8
|
+
* @param absolutePath - the absolute filesystem path to identify
|
|
9
|
+
* @returns a 16-character lowercase hex string
|
|
10
|
+
*/
|
|
11
|
+
export declare function computeContextId(absolutePath: string): Promise<string>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { WorkerClient } from '../classes/worker-client.class.ts';
|
|
2
|
+
import type { WorkerClientOptions } from '../typings/worker-client-options.interface.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Creates and connects a `WorkerClient` to the worker daemon.
|
|
5
|
+
*
|
|
6
|
+
* Resolves the context path, derives a stable context identifier,
|
|
7
|
+
* and checks whether a daemon is already running. If no daemon is
|
|
8
|
+
* found and `autoSpawn` is not `false`, a new daemon process is
|
|
9
|
+
* spawned and the factory waits for its PID file to appear before
|
|
10
|
+
* connecting.
|
|
11
|
+
*
|
|
12
|
+
* @param options - optional configuration for path resolution,
|
|
13
|
+
* auto-spawn behaviour, and connection timeout
|
|
14
|
+
* @returns a connected `WorkerClient` ready to send requests
|
|
15
|
+
* @throws {Error} if the `.kbdb` directory cannot be found
|
|
16
|
+
* @throws {Error} if the socket connection cannot be established
|
|
17
|
+
*/
|
|
18
|
+
export declare function createWorkerClient(options?: WorkerClientOptions): Promise<WorkerClient>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DaemonInfo } from '../typings/daemon-info.model.ts';
|
|
2
|
+
export type { DaemonInfo };
|
|
3
|
+
/**
|
|
4
|
+
* Discovers a running worker daemon for the given context.
|
|
5
|
+
*
|
|
6
|
+
* Reads the PID file at `<tmpdir>/kbdb-<contextId>.pid`. If the
|
|
7
|
+
* file exists and the process is alive, returns its PID and the
|
|
8
|
+
* expected socket path. If the file is stale (process dead or PID
|
|
9
|
+
* unparseable), removes the PID file and returns `null`.
|
|
10
|
+
*
|
|
11
|
+
* @param contextId - the 16-character context identifier
|
|
12
|
+
* @returns daemon location info, or `null` if no live daemon found
|
|
13
|
+
*/
|
|
14
|
+
export declare function discoverDaemon(contextId: string): DaemonInfo | null;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves the absolute path to the `.kbdb` database directory.
|
|
3
|
+
*
|
|
4
|
+
* Searches for a `.kbdb` sub-directory inside `targetDir`. When
|
|
5
|
+
* `targetDir` is omitted, `process.cwd()` is used as the base.
|
|
6
|
+
*
|
|
7
|
+
* @param targetDir - directory to search in; defaults to cwd
|
|
8
|
+
* @throws {Error} if no `.kbdb` directory exists at the resolved
|
|
9
|
+
* path
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveDbPath(targetDir?: string): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Runtime } from '../../runtime/typings/runtime.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Spawns a detached worker daemon process for the given context.
|
|
4
|
+
*
|
|
5
|
+
* @param contextPath - absolute path to the context directory the
|
|
6
|
+
* daemon should serve
|
|
7
|
+
* @param runtime - the current JavaScript runtime environment
|
|
8
|
+
* @param workerScript - absolute path to the worker daemon script,
|
|
9
|
+
* resolved at the entry point by `resolveWorkerScript`
|
|
10
|
+
*/
|
|
11
|
+
export declare function spawnDaemon(contextPath: string, runtime: Runtime, workerScript?: string): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Waits for the worker daemon's PID file to appear on disk.
|
|
3
|
+
*
|
|
4
|
+
* Polls every 100 ms until the PID file at
|
|
5
|
+
* `<tmpdir>/kbdb-<contextId>.pid` exists or the timeout elapses.
|
|
6
|
+
*
|
|
7
|
+
* @param contextId - the 16-character context identifier
|
|
8
|
+
* @param timeoutMs - maximum wait time in milliseconds; defaults
|
|
9
|
+
* to 10 000 ms
|
|
10
|
+
* @returns `true` if the PID file appeared before the timeout,
|
|
11
|
+
* `false` otherwise
|
|
12
|
+
*/
|
|
13
|
+
export declare function waitForDaemon(contextId: string, timeoutMs?: number): Promise<boolean>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { WorkerClient } from './classes/worker-client.class.ts';
|
|
2
|
+
export { createWorkerClient } from './functions/create-worker-client.function.ts';
|
|
3
|
+
export { resolveDbPath } from './functions/resolve-db-path.function.ts';
|
|
4
|
+
export { computeContextId } from './functions/compute-context-id.function.ts';
|
|
5
|
+
export { discoverDaemon } from './functions/discover-daemon.function.ts';
|
|
6
|
+
export { spawnDaemon } from './functions/spawn-daemon.function.ts';
|
|
7
|
+
export { waitForDaemon } from './functions/wait-for-daemon.function.ts';
|
|
8
|
+
export type { WorkerClientOptions } from './typings/worker-client-options.interface.ts';
|
|
9
|
+
export type { SearchParams } from './typings/search-params.model.ts';
|
|
10
|
+
export type { SearchResult } from './typings/search-result.model.ts';
|
|
11
|
+
export type { Section, AddSectionParams, } from './typings/section.model.ts';
|
|
12
|
+
export type { StatusResult } from './typings/status-result.model.ts';
|
|
13
|
+
export type { WorkerClientError } from './typings/worker-client-error.interface.ts';
|
|
14
|
+
export type { DaemonInfo } from './typings/daemon-info.model.ts';
|
|
15
|
+
export type { AddSectionResult } from './typings/add-section-result.model.ts';
|
|
16
|
+
export type { RemoveSectionResult } from './typings/remove-section-result.model.ts';
|
|
17
|
+
export type { ContentResult } from './typings/content-result.model.ts';
|
|
18
|
+
export type { IntegrityCheckResult, IntegrityError, } from './typings/integrity-check-result.model.ts';
|
|
19
|
+
export type { GcResult } from './typings/gc-result.model.ts';
|
|
20
|
+
export type { RebuildResult } from './typings/rebuild-result.model.ts';
|
|
21
|
+
export type { MigrateResult } from './typings/migrate-result.model.ts';
|
|
22
|
+
export type { VersionCompatibility, VersionStatus, } from './typings/version-status.model.ts';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Result returned by the daemon after adding a new section. */
|
|
2
|
+
export interface AddSectionResult {
|
|
3
|
+
/** Knowledge-base identifier assigned to the section. */
|
|
4
|
+
readonly kbid: string;
|
|
5
|
+
/** MIME type of the stored section. */
|
|
6
|
+
readonly type: string;
|
|
7
|
+
/** Section title, if provided. */
|
|
8
|
+
readonly title?: string;
|
|
9
|
+
/** Section description, if provided. */
|
|
10
|
+
readonly description?: string;
|
|
11
|
+
/** Total token count for the section. */
|
|
12
|
+
readonly token_count: number;
|
|
13
|
+
/** Number of unique terms indexed for this section. */
|
|
14
|
+
readonly indexed_terms_count: number;
|
|
15
|
+
/** Time taken to process and store the section, in milliseconds. */
|
|
16
|
+
readonly elapsed_ms: number;
|
|
17
|
+
/**
|
|
18
|
+
* `true` when the content already existed and the provided docid
|
|
19
|
+
* was added to the existing section's `docids` list.
|
|
20
|
+
*/
|
|
21
|
+
readonly attached: boolean;
|
|
22
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result returned by the daemon after composing a Markdown document
|
|
3
|
+
* from one or more kbid or docid identifiers.
|
|
4
|
+
*/
|
|
5
|
+
export interface ContentResult {
|
|
6
|
+
/** MIME type of the composed output, always `'text/markdown'`. */
|
|
7
|
+
readonly type: 'text/markdown';
|
|
8
|
+
/** The composed Markdown string. */
|
|
9
|
+
readonly data: string;
|
|
10
|
+
/** Character count of `data` (not byte count). */
|
|
11
|
+
readonly total: number;
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Report returned by the daemon after running garbage collection
|
|
3
|
+
* on the knowledge-base database.
|
|
4
|
+
*/
|
|
5
|
+
export interface GcResult {
|
|
6
|
+
/** Number of unreferenced sections removed. */
|
|
7
|
+
readonly removed_sections: number;
|
|
8
|
+
/** Total bytes freed by removing unreferenced sections. */
|
|
9
|
+
readonly removed_bytes: number;
|
|
10
|
+
/** Time taken to complete garbage collection, in milliseconds. */
|
|
11
|
+
readonly elapsed_ms: number;
|
|
12
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** A single integrity error found during a database check. */
|
|
2
|
+
export interface IntegrityError {
|
|
3
|
+
/**
|
|
4
|
+
* The category of integrity violation detected.
|
|
5
|
+
*
|
|
6
|
+
* - `'checksum_mismatch'` -- stored content does not match its hash
|
|
7
|
+
* - `'orphan_section'` -- section not referenced by any document
|
|
8
|
+
* - `'orphan_document'` -- document references no existing sections
|
|
9
|
+
* - `'broken_reference'` -- a marker references a non-existent entity
|
|
10
|
+
* - `'type_mismatch'` -- stored MIME type conflicts with content
|
|
11
|
+
* - `'circular_reference'` -- marker chain contains a cycle
|
|
12
|
+
*/
|
|
13
|
+
readonly type: 'checksum_mismatch' | 'orphan_section' | 'orphan_document' | 'broken_reference' | 'type_mismatch' | 'circular_reference';
|
|
14
|
+
/** Identifier of the entity (kbid or docid) that has the issue. */
|
|
15
|
+
readonly entity: string;
|
|
16
|
+
/** Human-readable description of the specific problem. */
|
|
17
|
+
readonly detail: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Report returned by the daemon after running an integrity check
|
|
21
|
+
* on the knowledge-base database.
|
|
22
|
+
*/
|
|
23
|
+
export interface IntegrityCheckResult {
|
|
24
|
+
/** `true` when all checks passed and no errors were found. */
|
|
25
|
+
readonly ok: boolean;
|
|
26
|
+
/** All integrity errors found; empty when `ok` is `true`. */
|
|
27
|
+
readonly errors: IntegrityError[];
|
|
28
|
+
/** Total number of sections examined. */
|
|
29
|
+
readonly sections_checked: number;
|
|
30
|
+
/** Total number of documents examined. */
|
|
31
|
+
readonly documents_checked: number;
|
|
32
|
+
/** Total number of marker references checked. */
|
|
33
|
+
readonly references_checked: number;
|
|
34
|
+
/** Time taken to complete the check, in milliseconds. */
|
|
35
|
+
readonly elapsed_ms: number;
|
|
36
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Report returned by the daemon after running database migrations.
|
|
3
|
+
*/
|
|
4
|
+
export interface MigrateResult {
|
|
5
|
+
/** The database format version before migration. */
|
|
6
|
+
readonly oldVersion: number;
|
|
7
|
+
/** The database format version after migration. */
|
|
8
|
+
readonly newVersion: number;
|
|
9
|
+
/** Number of individual migration steps that were applied. */
|
|
10
|
+
readonly migrationsRun: number;
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Report returned by the daemon after rebuilding all database indexes
|
|
3
|
+
* from section files and document manifests.
|
|
4
|
+
*/
|
|
5
|
+
export interface RebuildResult {
|
|
6
|
+
/** Number of text and code sections that were re-indexed. */
|
|
7
|
+
readonly sections_reindexed: number;
|
|
8
|
+
/** Total number of unique terms written to the rebuilt indexes. */
|
|
9
|
+
readonly terms_indexed: number;
|
|
10
|
+
/** Time taken to complete the rebuild, in milliseconds. */
|
|
11
|
+
readonly elapsed_ms: number;
|
|
12
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Result returned by the daemon after removing a section. */
|
|
2
|
+
export interface RemoveSectionResult {
|
|
3
|
+
/** `true` when the section was found and successfully removed. */
|
|
4
|
+
readonly removed: boolean;
|
|
5
|
+
/** Time taken to perform the removal, in milliseconds. */
|
|
6
|
+
readonly elapsed_ms: number;
|
|
7
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Parameters for a search query sent to the worker daemon. */
|
|
2
|
+
export interface SearchParams {
|
|
3
|
+
/** The search query string. */
|
|
4
|
+
readonly query: string;
|
|
5
|
+
/**
|
|
6
|
+
* Controls what entity type is returned.
|
|
7
|
+
* Defaults to `'sections'` when omitted.
|
|
8
|
+
*/
|
|
9
|
+
readonly mode?: 'sections' | 'documents' | 'stats';
|
|
10
|
+
/** Maximum number of results to return. */
|
|
11
|
+
readonly limit?: number;
|
|
12
|
+
}
|