@dikolab/kbdb 0.3.1 → 0.4.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/README.md +108 -126
- package/dist/chunk-BJPSPNGX.mjs +223 -0
- package/dist/chunk-BJPSPNGX.mjs.map +7 -0
- package/dist/cli.cjs +956 -319
- package/dist/cli.cjs.map +4 -4
- package/dist/cli.d.ts +9 -0
- package/dist/cli.mjs +840 -321
- package/dist/cli.mjs.map +4 -4
- package/dist/kbdb-worker.cjs +714 -94
- package/dist/kbdb-worker.cjs.map +4 -4
- package/dist/mod.cjs +122 -16
- package/dist/mod.cjs.map +3 -3
- package/dist/mod.d.ts +23 -2
- package/dist/mod.mjs +121 -16
- package/dist/mod.mjs.map +3 -3
- package/dist/src/shared/cli/functions/dispatch-command.function.d.ts +2 -1
- package/dist/src/shared/cli/functions/find-db.function.d.ts +7 -8
- package/dist/src/shared/cli/functions/handle-mcp.function.d.ts +1 -1
- package/dist/src/shared/cli/functions/parse-args.function.d.ts +4 -3
- package/dist/src/shared/cli/functions/resolve-kbid-prefix.function.d.ts +27 -0
- package/dist/src/shared/cli/functions/resolve-raw-db-path.function.d.ts +10 -0
- package/dist/src/shared/cli/functions/run-cli.function.d.ts +3 -1
- package/dist/src/shared/cli/functions/run-content.function.d.ts +8 -3
- package/dist/src/shared/cli/functions/run-import.function.d.ts +27 -0
- package/dist/src/shared/cli/functions/run-recall.function.d.ts +10 -4
- package/dist/src/shared/cli/functions/run-search.function.d.ts +7 -0
- package/dist/src/shared/cli/functions/run-unlearn.function.d.ts +9 -4
- package/dist/src/shared/cli/functions/run-worker-restart.function.d.ts +11 -0
- package/dist/src/shared/cli/functions/run-worker-stop.function.d.ts +11 -0
- package/dist/src/shared/cli/index.d.ts +2 -0
- package/dist/src/shared/cli/typings/cli-deps.interface.d.ts +4 -1
- package/dist/src/shared/cli/typings/cli-options.interface.d.ts +17 -0
- package/dist/src/shared/cli/typings/dispatch-client.type.d.ts +2 -1
- package/dist/src/shared/cli/typings/search-display.model.d.ts +6 -0
- package/dist/src/shared/embedding/classes/api-embedding-provider.class.d.ts +33 -0
- package/dist/src/shared/embedding/classes/onnx-embedding-provider.class.d.ts +33 -0
- package/dist/src/shared/embedding/functions/append-vector-entry.function.d.ts +14 -0
- package/dist/src/shared/embedding/functions/create-embedding-provider.function.d.ts +12 -0
- package/dist/src/shared/embedding/functions/detect-stale-vectors.function.d.ts +16 -0
- package/dist/src/shared/embedding/functions/parse-api-embedding-response.function.d.ts +11 -0
- package/dist/src/shared/embedding/functions/rebuild-vectors.function.d.ts +15 -0
- package/dist/src/shared/embedding/functions/scan-semantic-contradictions.function.d.ts +13 -0
- package/dist/src/shared/embedding/index.d.ts +7 -0
- package/dist/src/shared/embedding/typings/semantic-contradiction.model.d.ts +21 -0
- package/dist/src/shared/embedding/typings/stale-vectors-report.model.d.ts +16 -0
- package/dist/src/shared/mcp/classes/mcp-server.class.d.ts +22 -2
- package/dist/src/shared/mcp/functions/create-mcp-server.function.d.ts +6 -1
- package/dist/src/shared/mcp/functions/has-sampling-capability.function.d.ts +8 -0
- package/dist/src/shared/mcp/functions/run-auto-capture.function.d.ts +26 -0
- package/dist/src/shared/mcp/typings/mcp-client.interface.d.ts +2 -0
- package/dist/src/shared/mcp/typings/mcp-integrity-check-result.model.d.ts +24 -0
- package/dist/src/shared/mcp/typings/mcp-worker-client.interface.d.ts +3 -1
- package/dist/src/shared/version/constants/version.constant.d.ts +1 -1
- package/dist/src/shared/wasm-codec/typings/paged-search-result.model.d.ts +2 -0
- package/dist/src/shared/worker-client/classes/worker-client.class.d.ts +31 -1
- package/dist/src/shared/worker-client/constants/request-timeout.constant.d.ts +2 -0
- package/dist/src/shared/worker-client/constants/retry-defaults.constant.d.ts +2 -0
- package/dist/src/shared/worker-client/functions/get-or-create-client.function.d.ts +20 -0
- package/dist/src/shared/worker-client/functions/retry-on-timeout.function.d.ts +17 -0
- package/dist/src/shared/worker-client/index.d.ts +4 -1
- package/dist/src/shared/worker-client/typings/import-result.model.d.ts +16 -0
- package/dist/src/shared/worker-client/typings/integrity-check-result.model.d.ts +24 -0
- package/dist/src/shared/worker-client/typings/search-params.model.d.ts +4 -0
- package/dist/src/shared/worker-client/typings/search-result.model.d.ts +6 -0
- package/dist/src/shared/worker-client/typings/worker-client-options.interface.d.ts +7 -0
- package/dist/src/shared/worker-daemon/classes/worker-daemon.class.d.ts +5 -0
- package/dist/src/shared/worker-daemon/functions/create-ipc-server.function.d.ts +11 -11
- package/dist/src/shared/worker-daemon/functions/embed-after-learn.function.d.ts +13 -0
- package/dist/src/shared/worker-daemon/functions/handle-hybrid-search.function.d.ts +44 -0
- package/dist/src/shared/worker-daemon/functions/handle-import.function.d.ts +14 -0
- package/dist/src/shared/worker-daemon/functions/handle-read-ops.function.d.ts +7 -1
- package/dist/src/shared/worker-daemon/functions/handle-write-ops.function.d.ts +9 -4
- package/dist/src/shared/worker-daemon/typings/handler-context.interface.d.ts +3 -0
- package/dist/wasm/fs-database/kbdb_fs_database.d.ts +16 -85
- package/dist/wasm/fs-database/kbdb_fs_database.js +16 -85
- package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
- package/dist/wasm/kb-worker/kbdb_worker.d.ts +20 -115
- package/dist/wasm/kb-worker/kbdb_worker.js +20 -115
- package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
- package/dist/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
- package/dist/worker.d.ts +8 -0
- package/dist/worker.mjs +606 -102
- package/dist/worker.mjs.map +4 -4
- package/docs/details/README.md +4 -0
- package/docs/details/agent-tooling.md +122 -0
- package/docs/details/cli.md +78 -12
- package/docs/details/knowledge-base.md +173 -0
- package/docs/details/library-api.md +42 -2
- package/docs/details/mcp-server.md +39 -8
- package/docs/details/search-and-ranking.md +56 -0
- package/docs/goals/cli.md +110 -34
- package/docs/goals/mcp.md +22 -19
- package/docs/goals/query-parser.md +8 -0
- package/docs/goals/worker-client.md +62 -1
- package/docs/goals/worker-daemon.md +52 -10
- package/docs/modules/typescript/cli.md +1 -1
- package/docs/modules/typescript/shared/cli/functions.md +116 -13
- package/docs/modules/typescript/shared/cli/module.md +33 -20
- package/docs/modules/typescript/shared/cli/typings.md +4 -0
- package/docs/modules/typescript/shared/embedding/functions.md +104 -25
- package/docs/modules/typescript/shared/mcp/module.md +1 -1
- package/docs/modules/typescript/shared/mcp/typings.md +8 -1
- package/docs/modules/typescript/shared/worker-client/module.md +9 -1
- package/docs/modules/typescript/shared/worker-client/typings.md +3 -0
- package/docs/modules/typescript/shared/worker-daemon/module.md +6 -3
- package/docs/overview.md +43 -22
- package/docs/release-notes/0.3.1.md +10 -0
- package/docs/release-notes/0.3.2.md +64 -0
- package/docs/release-notes/0.4.0.md +80 -0
- package/docs/release-notes/README.md +2 -0
- package/mod.ts +33 -15
- package/package.json +11 -10
- package/dist/chunk-JG2UCKLI.mjs +0 -95
- package/dist/chunk-JG2UCKLI.mjs.map +0 -7
- package/src/cli.ts +0 -71
- package/src/shared/auto-capture/classes/auto-capture-controller.class.ts +0 -62
- package/src/shared/auto-capture/constants/auto-capture-defaults.constant.ts +0 -15
- package/src/shared/auto-capture/functions/build-capture-prompt.function.ts +0 -27
- package/src/shared/auto-capture/functions/evaluate-trigger.function.ts +0 -50
- package/src/shared/auto-capture/index.ts +0 -7
- package/src/shared/auto-capture/typings/auto-capture-config.interface.ts +0 -13
- package/src/shared/auto-capture/typings/auto-capture-state.interface.ts +0 -13
- package/src/shared/auto-capture/typings/auto-capture-trigger.interface.ts +0 -7
- package/src/shared/cli/constants/defaults.constant.ts +0 -19
- package/src/shared/cli/constants/global-help.constant.ts +0 -73
- package/src/shared/cli/constants/help-text.constant.ts +0 -4
- package/src/shared/cli/constants/leaf-help.constant.ts +0 -219
- package/src/shared/cli/constants/memory-protocol-body.constant.ts +0 -39
- package/src/shared/cli/constants/query-guidance-body.constant.ts +0 -37
- package/src/shared/cli/constants/subcommand-help.constant.ts +0 -195
- package/src/shared/cli/functions/collect-files.function.ts +0 -55
- package/src/shared/cli/functions/compute-section-kbid.function.ts +0 -49
- package/src/shared/cli/functions/dispatch-command.function.ts +0 -390
- package/src/shared/cli/functions/ensure-db.function.ts +0 -21
- package/src/shared/cli/functions/error-to-message.function.ts +0 -9
- package/src/shared/cli/functions/find-db.function.ts +0 -20
- package/src/shared/cli/functions/format-mcp-output.function.ts +0 -41
- package/src/shared/cli/functions/format-output.function.ts +0 -95
- package/src/shared/cli/functions/format-text-output.function.ts +0 -42
- package/src/shared/cli/functions/generate-group-help.function.ts +0 -41
- package/src/shared/cli/functions/generate-help.function.ts +0 -654
- package/src/shared/cli/functions/handle-data-command.function.ts +0 -67
- package/src/shared/cli/functions/handle-mcp.function.ts +0 -56
- package/src/shared/cli/functions/handle-migrate.function.ts +0 -64
- package/src/shared/cli/functions/hydrate-search-previews.function.ts +0 -29
- package/src/shared/cli/functions/install-default-skills.function.ts +0 -296
- package/src/shared/cli/functions/is-stdin-tty.function.ts +0 -12
- package/src/shared/cli/functions/parse-args.function.ts +0 -156
- package/src/shared/cli/functions/prompt-user.function.ts +0 -36
- package/src/shared/cli/functions/resolve-skill-names.function.ts +0 -43
- package/src/shared/cli/functions/run-agent-create.function.ts +0 -114
- package/src/shared/cli/functions/run-agent-delete.function.ts +0 -47
- package/src/shared/cli/functions/run-agent-get.function.ts +0 -166
- package/src/shared/cli/functions/run-agent-list.function.ts +0 -58
- package/src/shared/cli/functions/run-check.function.ts +0 -159
- package/src/shared/cli/functions/run-cli.function.ts +0 -299
- package/src/shared/cli/functions/run-content.function.ts +0 -47
- package/src/shared/cli/functions/run-db-init.function.ts +0 -44
- package/src/shared/cli/functions/run-db-migrate.function.ts +0 -40
- package/src/shared/cli/functions/run-export.function.ts +0 -40
- package/src/shared/cli/functions/run-gc.function.ts +0 -51
- package/src/shared/cli/functions/run-init.function.ts +0 -93
- package/src/shared/cli/functions/run-learn.function.ts +0 -223
- package/src/shared/cli/functions/run-migrate.function.ts +0 -85
- package/src/shared/cli/functions/run-rebuild.function.ts +0 -47
- package/src/shared/cli/functions/run-recall.function.ts +0 -66
- package/src/shared/cli/functions/run-search.function.ts +0 -133
- package/src/shared/cli/functions/run-skill-delete.function.ts +0 -47
- package/src/shared/cli/functions/run-skill-get.function.ts +0 -90
- package/src/shared/cli/functions/run-skill-learn.function.ts +0 -70
- package/src/shared/cli/functions/run-skill-list.function.ts +0 -74
- package/src/shared/cli/functions/run-status.function.ts +0 -29
- package/src/shared/cli/functions/run-unlearn.function.ts +0 -58
- package/src/shared/cli/functions/version-gate.function.ts +0 -44
- package/src/shared/cli/functions/wrap-command.function.ts +0 -34
- package/src/shared/cli/index.ts +0 -55
- package/src/shared/cli/typings/agent-create-client.interface.ts +0 -47
- package/src/shared/cli/typings/agent-get-client.interface.ts +0 -39
- package/src/shared/cli/typings/check-client.interface.ts +0 -66
- package/src/shared/cli/typings/cli-deps.interface.ts +0 -54
- package/src/shared/cli/typings/cli-options.interface.ts +0 -72
- package/src/shared/cli/typings/command-result.model.ts +0 -15
- package/src/shared/cli/typings/disconnectable-client.interface.ts +0 -29
- package/src/shared/cli/typings/dispatch-client.type.ts +0 -46
- package/src/shared/cli/typings/learn-client.interface.ts +0 -53
- package/src/shared/cli/typings/learn-io.interface.ts +0 -5
- package/src/shared/cli/typings/learn-result.model.ts +0 -27
- package/src/shared/cli/typings/search-client.interface.ts +0 -73
- package/src/shared/cli/typings/search-display.model.ts +0 -54
- package/src/shared/dir-resolver/functions/join-path.function.ts +0 -13
- package/src/shared/dir-resolver/functions/resolve-base-dir.function.ts +0 -25
- package/src/shared/dir-resolver/functions/resolve-wasm-dir.function.ts +0 -5
- package/src/shared/dir-resolver/functions/resolve-worker-script.function.ts +0 -13
- package/src/shared/dir-resolver/index.ts +0 -11
- package/src/shared/dir-resolver/typings/base-dir.interface.ts +0 -4
- package/src/shared/embedding/classes/null-embedding-provider.class.ts +0 -29
- package/src/shared/embedding/constants/near-duplicate-thresholds.constant.ts +0 -17
- package/src/shared/embedding/functions/build-vector-index.function.ts +0 -79
- package/src/shared/embedding/functions/cosine-similarity.function.ts +0 -31
- package/src/shared/embedding/functions/detect-near-duplicates.function.ts +0 -69
- package/src/shared/embedding/functions/jaccard-coefficient.function.ts +0 -26
- package/src/shared/embedding/functions/read-vector-index-meta.function.ts +0 -44
- package/src/shared/embedding/functions/rrf-fuse.function.ts +0 -33
- package/src/shared/embedding/functions/search-vectors.function.ts +0 -59
- package/src/shared/embedding/index.ts +0 -20
- package/src/shared/embedding/typings/embedding-config.interface.ts +0 -23
- package/src/shared/embedding/typings/embedding-provider.interface.ts +0 -25
- package/src/shared/embedding/typings/near-duplicate-candidate.model.ts +0 -25
- package/src/shared/embedding/typings/near-duplicate-result.model.ts +0 -26
- package/src/shared/embedding/typings/vector-index-entry.model.ts +0 -13
- package/src/shared/embedding/typings/vector-index-meta.model.ts +0 -14
- package/src/shared/embedding/typings/vector-search-result.model.ts +0 -8
- package/src/shared/hash/functions/compute-sha256.ts +0 -17
- package/src/shared/hash/index.ts +0 -1
- package/src/shared/mcp/classes/mcp-server.class.ts +0 -480
- package/src/shared/mcp/constants/mcp-error-codes.constant.ts +0 -30
- package/src/shared/mcp/constants/tool-agent-create.constant.ts +0 -39
- package/src/shared/mcp/constants/tool-agent-delete.constant.ts +0 -26
- package/src/shared/mcp/constants/tool-agent-get.constant.ts +0 -24
- package/src/shared/mcp/constants/tool-agent-list.constant.ts +0 -18
- package/src/shared/mcp/constants/tool-auto-capture-review.constant.ts +0 -32
- package/src/shared/mcp/constants/tool-check.constant.ts +0 -21
- package/src/shared/mcp/constants/tool-content.constant.ts +0 -29
- package/src/shared/mcp/constants/tool-export.constant.ts +0 -27
- package/src/shared/mcp/constants/tool-gc.constant.ts +0 -21
- package/src/shared/mcp/constants/tool-learn.constant.ts +0 -58
- package/src/shared/mcp/constants/tool-rebuild.constant.ts +0 -21
- package/src/shared/mcp/constants/tool-recall.constant.ts +0 -36
- package/src/shared/mcp/constants/tool-retrieve.constant.ts +0 -31
- package/src/shared/mcp/constants/tool-search.constant.ts +0 -51
- package/src/shared/mcp/constants/tool-skill-delete.constant.ts +0 -24
- package/src/shared/mcp/constants/tool-skill-get.constant.ts +0 -27
- package/src/shared/mcp/constants/tool-skill-learn.constant.ts +0 -37
- package/src/shared/mcp/constants/tool-skill-list.constant.ts +0 -18
- package/src/shared/mcp/constants/tool-status.constant.ts +0 -20
- package/src/shared/mcp/constants/tool-unlearn.constant.ts +0 -25
- package/src/shared/mcp/functions/as-boolean-or-undefined.function.ts +0 -11
- package/src/shared/mcp/functions/as-string-array-or-undefined.function.ts +0 -17
- package/src/shared/mcp/functions/as-string-array.function.ts +0 -15
- package/src/shared/mcp/functions/as-string.function.ts +0 -10
- package/src/shared/mcp/functions/build-skills-text.function.ts +0 -43
- package/src/shared/mcp/functions/create-mcp-server.function.ts +0 -14
- package/src/shared/mcp/functions/create-prompt-definitions.function.ts +0 -102
- package/src/shared/mcp/functions/create-resource-templates.function.ts +0 -23
- package/src/shared/mcp/functions/create-tool-definitions.function.ts +0 -530
- package/src/shared/mcp/functions/extract-skill-arguments.function.ts +0 -27
- package/src/shared/mcp/functions/handle-agent-create.function.ts +0 -116
- package/src/shared/mcp/functions/handle-agent-delete.function.ts +0 -50
- package/src/shared/mcp/functions/handle-agent-get.function.ts +0 -160
- package/src/shared/mcp/functions/handle-agent-list.function.ts +0 -50
- package/src/shared/mcp/functions/handle-agent-prompt.function.ts +0 -68
- package/src/shared/mcp/functions/handle-completion.function.ts +0 -114
- package/src/shared/mcp/functions/handle-mcp-request.function.ts +0 -202
- package/src/shared/mcp/functions/handle-prompt-get.function.ts +0 -220
- package/src/shared/mcp/functions/handle-recall.function.ts +0 -66
- package/src/shared/mcp/functions/handle-resource-read.function.ts +0 -56
- package/src/shared/mcp/functions/handle-roots-list.function.ts +0 -29
- package/src/shared/mcp/functions/handle-skill-prompt.function.ts +0 -44
- package/src/shared/mcp/functions/handle-tool-auto-capture-review.function.ts +0 -24
- package/src/shared/mcp/functions/handle-tool-call.function.ts +0 -560
- package/src/shared/mcp/functions/handle-tool-check.function.ts +0 -21
- package/src/shared/mcp/functions/handle-tool-content.function.ts +0 -23
- package/src/shared/mcp/functions/handle-tool-export.function.ts +0 -25
- package/src/shared/mcp/functions/handle-tool-gc.function.ts +0 -21
- package/src/shared/mcp/functions/handle-tool-learn.function.ts +0 -69
- package/src/shared/mcp/functions/handle-tool-rebuild.function.ts +0 -21
- package/src/shared/mcp/functions/handle-tool-retrieve.function.ts +0 -40
- package/src/shared/mcp/functions/handle-tool-search.function.ts +0 -47
- package/src/shared/mcp/functions/handle-tool-skill-delete.function.ts +0 -34
- package/src/shared/mcp/functions/handle-tool-skill-get.function.ts +0 -59
- package/src/shared/mcp/functions/handle-tool-skill-learn.function.ts +0 -61
- package/src/shared/mcp/functions/handle-tool-skill-list.function.ts +0 -39
- package/src/shared/mcp/functions/handle-tool-status.function.ts +0 -21
- package/src/shared/mcp/functions/handle-tool-unlearn.function.ts +0 -24
- package/src/shared/mcp/functions/parse-agent-meta.function.ts +0 -27
- package/src/shared/mcp/functions/parse-skill-arguments.function.ts +0 -36
- package/src/shared/mcp/functions/parse-skill-content.function.ts +0 -38
- package/src/shared/mcp/functions/read-agent-meta.function.ts +0 -41
- package/src/shared/mcp/functions/resolve-skill-refs.function.ts +0 -50
- package/src/shared/mcp/functions/run-startup-health-check.function.ts +0 -34
- package/src/shared/mcp/functions/serialize-skill-content.function.ts +0 -12
- package/src/shared/mcp/functions/should-emit-log.function.ts +0 -38
- package/src/shared/mcp/index.ts +0 -28
- package/src/shared/mcp/typings/agent-types.interface.ts +0 -39
- package/src/shared/mcp/typings/log-types.interface.ts +0 -26
- package/src/shared/mcp/typings/mcp-capabilities.interface.ts +0 -16
- package/src/shared/mcp/typings/mcp-client.interface.ts +0 -317
- package/src/shared/mcp/typings/mcp-completion.interface.ts +0 -45
- package/src/shared/mcp/typings/mcp-content-result.model.ts +0 -9
- package/src/shared/mcp/typings/mcp-export-result.model.ts +0 -11
- package/src/shared/mcp/typings/mcp-gc-result.model.ts +0 -15
- package/src/shared/mcp/typings/mcp-integrity-check-result.model.ts +0 -17
- package/src/shared/mcp/typings/mcp-integrity-error.model.ts +0 -15
- package/src/shared/mcp/typings/mcp-notification.interface.ts +0 -9
- package/src/shared/mcp/typings/mcp-rebuild-result.model.ts +0 -9
- package/src/shared/mcp/typings/mcp-request.interface.ts +0 -11
- package/src/shared/mcp/typings/mcp-resource-result.interface.ts +0 -12
- package/src/shared/mcp/typings/mcp-resource-template.interface.ts +0 -11
- package/src/shared/mcp/typings/mcp-response.interface.ts +0 -18
- package/src/shared/mcp/typings/mcp-server-info.interface.ts +0 -7
- package/src/shared/mcp/typings/mcp-server-state.interface.ts +0 -17
- package/src/shared/mcp/typings/mcp-tool-annotations.interface.ts +0 -32
- package/src/shared/mcp/typings/mcp-tool-definition.interface.ts +0 -16
- package/src/shared/mcp/typings/mcp-tool-result.interface.ts +0 -19
- package/src/shared/mcp/typings/mcp-types.interface.ts +0 -158
- package/src/shared/mcp/typings/mcp-worker-client.interface.ts +0 -243
- package/src/shared/mcp/typings/prompt-types.interface.ts +0 -39
- package/src/shared/mcp/typings/remove-section-result.model.ts +0 -10
- package/src/shared/mcp/typings/sampling-types.interface.ts +0 -48
- package/src/shared/mcp/typings/skill-types.interface.ts +0 -29
- package/src/shared/mcp/typings/tool-call-result.model.ts +0 -18
- package/src/shared/mod.ts +0 -1
- package/src/shared/platform/functions/get-ipc-path.function.ts +0 -19
- package/src/shared/platform/functions/get-tmpdir.function.ts +0 -8
- package/src/shared/platform/functions/is-process-alive.function.ts +0 -17
- package/src/shared/platform/index.ts +0 -3
- package/src/shared/runtime/functions/detect-runtime.ts +0 -14
- package/src/shared/runtime/functions/get-args.ts +0 -16
- package/src/shared/runtime/index.ts +0 -3
- package/src/shared/runtime/typings/runtime.ts +0 -2
- package/src/shared/sync/functions/build-import-report.function.ts +0 -40
- package/src/shared/sync/functions/parse-export-entry.function.ts +0 -45
- package/src/shared/sync/functions/resolve-conflict.function.ts +0 -31
- package/src/shared/sync/functions/serialize-export-entry.function.ts +0 -18
- package/src/shared/sync/index.ts +0 -9
- package/src/shared/sync/typings/conflict-resolution.type.ts +0 -8
- package/src/shared/sync/typings/export-entry.interface.ts +0 -13
- package/src/shared/sync/typings/export-options.interface.ts +0 -9
- package/src/shared/sync/typings/import-options.interface.ts +0 -7
- package/src/shared/sync/typings/import-report.interface.ts +0 -15
- package/src/shared/version/constants/version.constant.ts +0 -2
- package/src/shared/version/index.ts +0 -1
- package/src/shared/wasm-codec/functions/decode-add-section-result.function.ts +0 -112
- package/src/shared/wasm-codec/functions/decode-compose-output.function.ts +0 -16
- package/src/shared/wasm-codec/functions/decode-document-manifest-list.function.ts +0 -70
- package/src/shared/wasm-codec/functions/decode-document-manifest.function.ts +0 -87
- package/src/shared/wasm-codec/functions/decode-f32.function.ts +0 -16
- package/src/shared/wasm-codec/functions/decode-key-value-text.function.ts +0 -15
- package/src/shared/wasm-codec/functions/decode-one-recall-result.function.ts +0 -86
- package/src/shared/wasm-codec/functions/decode-option-string.function.ts +0 -24
- package/src/shared/wasm-codec/functions/decode-recall-document.function.ts +0 -59
- package/src/shared/wasm-codec/functions/decode-recall-reference.function.ts +0 -52
- package/src/shared/wasm-codec/functions/decode-recall-result.function.ts +0 -267
- package/src/shared/wasm-codec/functions/decode-recall-sibling.function.ts +0 -43
- package/src/shared/wasm-codec/functions/decode-remove-flag.function.ts +0 -3
- package/src/shared/wasm-codec/functions/decode-scored-results.function.ts +0 -194
- package/src/shared/wasm-codec/functions/decode-section-match.function.ts +0 -80
- package/src/shared/wasm-codec/functions/decode-section-record-list.function.ts +0 -20
- package/src/shared/wasm-codec/functions/decode-section-record-trailing.function.ts +0 -75
- package/src/shared/wasm-codec/functions/decode-section-record.function.ts +0 -85
- package/src/shared/wasm-codec/functions/decode-section-records.function.ts +0 -249
- package/src/shared/wasm-codec/functions/decode-section-type.function.ts +0 -30
- package/src/shared/wasm-codec/functions/decode-string.function.ts +0 -22
- package/src/shared/wasm-codec/functions/decode-u32.function.ts +0 -16
- package/src/shared/wasm-codec/functions/decode-u64.function.ts +0 -16
- package/src/shared/wasm-codec/functions/decode-wasm-list.function.ts +0 -31
- package/src/shared/wasm-codec/functions/encode-add-section-params.function.ts +0 -102
- package/src/shared/wasm-codec/functions/encode-group-params.function.ts +0 -28
- package/src/shared/wasm-codec/functions/encode-identifier-list.function.ts +0 -17
- package/src/shared/wasm-codec/functions/encode-kbid-list.function.ts +0 -17
- package/src/shared/wasm-codec/functions/encode-option-string.function.ts +0 -14
- package/src/shared/wasm-codec/functions/encode-recall-params.function.ts +0 -68
- package/src/shared/wasm-codec/functions/encode-search-params.function.ts +0 -12
- package/src/shared/wasm-codec/functions/encode-section-type.function.ts +0 -18
- package/src/shared/wasm-codec/functions/encode-string.function.ts +0 -9
- package/src/shared/wasm-codec/functions/encode-type-filter-param.function.ts +0 -13
- package/src/shared/wasm-codec/functions/encode-u32.function.ts +0 -5
- package/src/shared/wasm-codec/functions/encode-update-section-params.function.ts +0 -16
- package/src/shared/wasm-codec/index.ts +0 -49
- package/src/shared/wasm-codec/typings/add-section-input.model.ts +0 -45
- package/src/shared/wasm-codec/typings/add-section-result.model.ts +0 -28
- package/src/shared/wasm-codec/typings/document-manifest.model.ts +0 -20
- package/src/shared/wasm-codec/typings/document-section.model.ts +0 -12
- package/src/shared/wasm-codec/typings/item-decoder.type.ts +0 -10
- package/src/shared/wasm-codec/typings/near-duplicate.model.ts +0 -16
- package/src/shared/wasm-codec/typings/paged-search-result.model.ts +0 -22
- package/src/shared/wasm-codec/typings/section-match.model.ts +0 -31
- package/src/shared/wasm-codec/typings/section-record-trailing.model.ts +0 -38
- package/src/shared/wasm-codec/typings/section-record.model.ts +0 -66
- package/src/shared/wasm-codec/typings/section-type-result.model.ts +0 -12
- package/src/shared/worker-client/classes/worker-client.class.ts +0 -466
- package/src/shared/worker-client/functions/compute-context-id.function.ts +0 -18
- package/src/shared/worker-client/functions/create-worker-client.function.ts +0 -70
- package/src/shared/worker-client/functions/discover-daemon.function.ts +0 -47
- package/src/shared/worker-client/functions/handle-ipc-data.function.ts +0 -49
- package/src/shared/worker-client/functions/resolve-db-path.function.ts +0 -21
- package/src/shared/worker-client/functions/send-ipc-request.function.ts +0 -39
- package/src/shared/worker-client/functions/spawn-daemon.function.ts +0 -35
- package/src/shared/worker-client/functions/wait-for-daemon.function.ts +0 -34
- package/src/shared/worker-client/index.ts +0 -44
- package/src/shared/worker-client/typings/add-section-result.model.ts +0 -39
- package/src/shared/worker-client/typings/content-result.model.ts +0 -12
- package/src/shared/worker-client/typings/daemon-info.model.ts +0 -7
- package/src/shared/worker-client/typings/export-result.model.ts +0 -14
- package/src/shared/worker-client/typings/gc-result.model.ts +0 -18
- package/src/shared/worker-client/typings/integrity-check-result.model.ts +0 -43
- package/src/shared/worker-client/typings/json-rpc-response.interface.ts +0 -17
- package/src/shared/worker-client/typings/migrate-result.model.ts +0 -11
- package/src/shared/worker-client/typings/pending-call.interface.ts +0 -7
- package/src/shared/worker-client/typings/rebuild-result.model.ts +0 -12
- package/src/shared/worker-client/typings/recall-document.model.ts +0 -16
- package/src/shared/worker-client/typings/recall-params.model.ts +0 -15
- package/src/shared/worker-client/typings/recall-reference.model.ts +0 -32
- package/src/shared/worker-client/typings/recall-result.model.ts +0 -98
- package/src/shared/worker-client/typings/recall-sibling.model.ts +0 -11
- package/src/shared/worker-client/typings/recall-single-result.model.ts +0 -41
- package/src/shared/worker-client/typings/remove-section-result.model.ts +0 -7
- package/src/shared/worker-client/typings/search-params.model.ts +0 -14
- package/src/shared/worker-client/typings/search-result.model.ts +0 -43
- package/src/shared/worker-client/typings/section.model.ts +0 -43
- package/src/shared/worker-client/typings/status-result.model.ts +0 -14
- package/src/shared/worker-client/typings/version-status.model.ts +0 -28
- package/src/shared/worker-client/typings/worker-client-error.interface.ts +0 -8
- package/src/shared/worker-client/typings/worker-client-options.interface.ts +0 -30
- package/src/shared/worker-daemon/classes/ipc-error.class.ts +0 -22
- package/src/shared/worker-daemon/classes/worker-daemon.class.ts +0 -1291
- package/src/shared/worker-daemon/constants/daemon-defaults.constant.ts +0 -29
- package/src/shared/worker-daemon/constants/wasm-method-map.constant.ts +0 -69
- package/src/shared/worker-daemon/functions/build-ipc-error-response.function.ts +0 -16
- package/src/shared/worker-daemon/functions/check-catalog-version.function.ts +0 -54
- package/src/shared/worker-daemon/functions/check-preconditions.function.ts +0 -28
- package/src/shared/worker-daemon/functions/create-host-imports.function.ts +0 -328
- package/src/shared/worker-daemon/functions/create-ipc-server.function.ts +0 -87
- package/src/shared/worker-daemon/functions/detect-stale-pid.function.ts +0 -33
- package/src/shared/worker-daemon/functions/dispatch-request.function.ts +0 -190
- package/src/shared/worker-daemon/functions/handle-check-version.function.ts +0 -74
- package/src/shared/worker-daemon/functions/handle-config-method.function.ts +0 -27
- package/src/shared/worker-daemon/functions/handle-read-ops.function.ts +0 -236
- package/src/shared/worker-daemon/functions/handle-write-ops.function.ts +0 -257
- package/src/shared/worker-daemon/functions/load-wasm-modules.function.ts +0 -95
- package/src/shared/worker-daemon/functions/parse-auto-capture-section.function.ts +0 -51
- package/src/shared/worker-daemon/functions/parse-catalog-version.function.ts +0 -20
- package/src/shared/worker-daemon/functions/parse-embedding-section.function.ts +0 -38
- package/src/shared/worker-daemon/functions/parse-worker-toml.function.ts +0 -104
- package/src/shared/worker-daemon/functions/read-config.function.ts +0 -83
- package/src/shared/worker-daemon/functions/run-startup-integrity-check.function.ts +0 -55
- package/src/shared/worker-daemon/functions/run-worker.function.ts +0 -57
- package/src/shared/worker-daemon/functions/scan-near-duplicates.function.ts +0 -92
- package/src/shared/worker-daemon/functions/start-daemon.function.ts +0 -74
- package/src/shared/worker-daemon/functions/wasm-bridge.function.ts +0 -144
- package/src/shared/worker-daemon/functions/wasm-memory-helpers.function.ts +0 -41
- package/src/shared/worker-daemon/functions/write-lock.function.ts +0 -49
- package/src/shared/worker-daemon/index.ts +0 -16
- package/src/shared/worker-daemon/typings/allocator-ref.interface.ts +0 -16
- package/src/shared/worker-daemon/typings/daemon-config.interface.ts +0 -20
- package/src/shared/worker-daemon/typings/fs-adapter.interface.ts +0 -22
- package/src/shared/worker-daemon/typings/handler-context.interface.ts +0 -19
- package/src/shared/worker-daemon/typings/ipc-handler.interface.ts +0 -39
- package/src/shared/worker-daemon/typings/memory-ref.interface.ts +0 -13
- package/src/shared/worker-daemon/typings/wasm-fn.type.ts +0 -2
- package/src/shared/worker-daemon/typings/wasm-modules.interface.ts +0 -7
- package/src/shared/worker-daemon/typings/write-lock.interface.ts +0 -13
- package/src/wasm/fs-database/kbdb_fs_database.d.ts +0 -259
- package/src/wasm/fs-database/kbdb_fs_database.js +0 -515
- package/src/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
- package/src/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +0 -35
- package/src/wasm/fs-database/package.json +0 -13
- package/src/wasm/kb-worker/kbdb_worker.d.ts +0 -650
- package/src/wasm/kb-worker/kbdb_worker.js +0 -1181
- package/src/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
- package/src/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +0 -77
- package/src/wasm/kb-worker/package.json +0 -13
- package/src/wasm/query-parser/kbdb_query_parser.d.ts +0 -195
- package/src/wasm/query-parser/kbdb_query_parser.js +0 -403
- package/src/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
- package/src/wasm/query-parser/kbdb_query_parser_bg.wasm.d.ts +0 -25
- package/src/wasm/query-parser/package.json +0 -13
- package/src/worker.ts +0 -42
package/dist/kbdb-worker.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
4
|
// src/worker.ts
|
|
5
|
-
var
|
|
5
|
+
var import_node_fs10 = require("node:fs");
|
|
6
6
|
|
|
7
7
|
// src/shared/runtime/functions/detect-runtime.ts
|
|
8
8
|
function detectRuntime() {
|
|
@@ -66,62 +66,139 @@ var DEFAULT_ITEM_TTL_MS = 6e4;
|
|
|
66
66
|
var WORKER_TOML_FILENAME = "worker.toml";
|
|
67
67
|
var DB_FORMAT_VERSION = 1;
|
|
68
68
|
|
|
69
|
-
// src/shared/worker-daemon/functions/
|
|
70
|
-
function
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
69
|
+
// src/shared/worker-daemon/functions/parse-embedding-section.function.ts
|
|
70
|
+
function parseEmbeddingSection(entries) {
|
|
71
|
+
const provider = entries.get("provider");
|
|
72
|
+
if (!provider) {
|
|
73
|
+
return void 0;
|
|
74
|
+
}
|
|
75
|
+
const model = entries.get("model");
|
|
76
|
+
const endpoint = entries.get("endpoint");
|
|
77
|
+
const dimensionsRaw = entries.get("dimensions");
|
|
78
|
+
const dimensions = dimensionsRaw ? parseInt(dimensionsRaw, 10) || void 0 : void 0;
|
|
79
|
+
return {
|
|
80
|
+
provider,
|
|
81
|
+
...model !== void 0 ? { model } : {},
|
|
82
|
+
...endpoint !== void 0 ? { endpoint } : {},
|
|
83
|
+
...dimensions !== void 0 ? { dimensions } : {}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/shared/auto-capture/constants/auto-capture-defaults.constant.ts
|
|
88
|
+
var AUTO_CAPTURE_DEFAULTS = {
|
|
89
|
+
enabled: false,
|
|
90
|
+
triggerAfterToolCalls: 5,
|
|
91
|
+
minIntervalMs: 6e4,
|
|
92
|
+
maxCapturesPerSession: 10,
|
|
93
|
+
dryRun: false
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// src/shared/worker-daemon/functions/parse-auto-capture-section.function.ts
|
|
97
|
+
function parseAutoCaptureSection(entries) {
|
|
98
|
+
const enabled = entries.has("enabled") ? entries.get("enabled") === "true" : AUTO_CAPTURE_DEFAULTS.enabled;
|
|
99
|
+
const dryRun = entries.has("dry_run") ? entries.get("dry_run") === "true" : AUTO_CAPTURE_DEFAULTS.dryRun;
|
|
100
|
+
const triggerRaw = entries.get("trigger_after_tool_calls");
|
|
101
|
+
const triggerAfterToolCalls = triggerRaw ? parseInt(triggerRaw, 10) || AUTO_CAPTURE_DEFAULTS.triggerAfterToolCalls : AUTO_CAPTURE_DEFAULTS.triggerAfterToolCalls;
|
|
102
|
+
const intervalRaw = entries.get("min_interval_ms");
|
|
103
|
+
const minIntervalMs = intervalRaw ? parseInt(intervalRaw, 10) || AUTO_CAPTURE_DEFAULTS.minIntervalMs : AUTO_CAPTURE_DEFAULTS.minIntervalMs;
|
|
104
|
+
const capRaw = entries.get("max_captures_per_session");
|
|
105
|
+
const maxCapturesPerSession = capRaw ? parseInt(capRaw, 10) || AUTO_CAPTURE_DEFAULTS.maxCapturesPerSession : AUTO_CAPTURE_DEFAULTS.maxCapturesPerSession;
|
|
106
|
+
return {
|
|
107
|
+
enabled,
|
|
108
|
+
triggerAfterToolCalls,
|
|
109
|
+
minIntervalMs,
|
|
110
|
+
maxCapturesPerSession,
|
|
111
|
+
dryRun
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// src/shared/worker-daemon/functions/parse-worker-toml.function.ts
|
|
116
|
+
function applyRootKey(acc, key, value) {
|
|
117
|
+
switch (key) {
|
|
118
|
+
case "item_limit":
|
|
119
|
+
acc.itemLimit = parseInt(value, 10) || DEFAULT_ITEM_LIMIT;
|
|
120
|
+
break;
|
|
121
|
+
case "index_limit":
|
|
122
|
+
acc.indexLimit = parseInt(value, 10) || DEFAULT_INDEX_LIMIT;
|
|
123
|
+
break;
|
|
124
|
+
case "timeout_ms":
|
|
125
|
+
acc.timeoutMs = parseInt(value, 10) || DEFAULT_TIMEOUT_MS;
|
|
126
|
+
break;
|
|
127
|
+
case "item_ttl_ms":
|
|
128
|
+
acc.itemTtlMs = parseInt(value, 10) || DEFAULT_ITEM_TTL_MS;
|
|
129
|
+
break;
|
|
130
|
+
default:
|
|
131
|
+
break;
|
|
83
132
|
}
|
|
84
133
|
}
|
|
85
134
|
function parseWorkerToml(text, contextPath) {
|
|
86
|
-
|
|
87
|
-
|
|
135
|
+
let section = "";
|
|
136
|
+
const embeddingEntries = /* @__PURE__ */ new Map();
|
|
137
|
+
const autoCaptureEntries = /* @__PURE__ */ new Map();
|
|
138
|
+
const acc = {
|
|
88
139
|
itemLimit: DEFAULT_ITEM_LIMIT,
|
|
89
140
|
indexLimit: DEFAULT_INDEX_LIMIT,
|
|
90
141
|
timeoutMs: DEFAULT_TIMEOUT_MS,
|
|
91
142
|
itemTtlMs: DEFAULT_ITEM_TTL_MS
|
|
92
143
|
};
|
|
93
|
-
const result = { ...config };
|
|
94
144
|
for (const line of text.split("\n")) {
|
|
95
145
|
const trimmed = line.trim();
|
|
96
|
-
if (trimmed
|
|
146
|
+
if (trimmed === "[embedding]") {
|
|
147
|
+
section = "embedding";
|
|
97
148
|
continue;
|
|
98
149
|
}
|
|
150
|
+
if (trimmed === "[auto_capture]") {
|
|
151
|
+
section = "auto_capture";
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (trimmed.startsWith("[")) {
|
|
155
|
+
section = "";
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (trimmed.startsWith("#") || !trimmed.includes("=")) continue;
|
|
99
159
|
const eqIdx = trimmed.indexOf("=");
|
|
100
160
|
const key = trimmed.slice(0, eqIdx).trim();
|
|
101
161
|
const value = trimmed.slice(eqIdx + 1).trim();
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
case "timeout_ms":
|
|
110
|
-
result.timeoutMs = parseInt(value, 10) || DEFAULT_TIMEOUT_MS;
|
|
111
|
-
break;
|
|
112
|
-
case "item_ttl_ms":
|
|
113
|
-
result.itemTtlMs = parseInt(value, 10) || DEFAULT_ITEM_TTL_MS;
|
|
114
|
-
break;
|
|
115
|
-
default:
|
|
116
|
-
break;
|
|
162
|
+
if (section === "embedding") {
|
|
163
|
+
embeddingEntries.set(key, value);
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
if (section === "auto_capture") {
|
|
167
|
+
autoCaptureEntries.set(key, value);
|
|
168
|
+
continue;
|
|
117
169
|
}
|
|
170
|
+
applyRootKey(acc, key, value);
|
|
171
|
+
}
|
|
172
|
+
const embedding = parseEmbeddingSection(embeddingEntries);
|
|
173
|
+
const autoCapture = autoCaptureEntries.size > 0 ? parseAutoCaptureSection(autoCaptureEntries) : void 0;
|
|
174
|
+
return {
|
|
175
|
+
contextPath,
|
|
176
|
+
...acc,
|
|
177
|
+
...embedding !== void 0 ? { embedding } : {},
|
|
178
|
+
...autoCapture !== void 0 ? { autoCapture } : {}
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// src/shared/worker-daemon/functions/read-config.function.ts
|
|
183
|
+
function readConfig(contextPath) {
|
|
184
|
+
const configPath = (0, import_node_path3.join)(contextPath, WORKER_TOML_FILENAME);
|
|
185
|
+
try {
|
|
186
|
+
const text = (0, import_node_fs.readFileSync)(configPath, "utf-8");
|
|
187
|
+
return parseWorkerToml(text, contextPath);
|
|
188
|
+
} catch {
|
|
189
|
+
return {
|
|
190
|
+
contextPath,
|
|
191
|
+
itemLimit: DEFAULT_ITEM_LIMIT,
|
|
192
|
+
indexLimit: DEFAULT_INDEX_LIMIT,
|
|
193
|
+
timeoutMs: DEFAULT_TIMEOUT_MS,
|
|
194
|
+
itemTtlMs: DEFAULT_ITEM_TTL_MS
|
|
195
|
+
};
|
|
118
196
|
}
|
|
119
|
-
return result;
|
|
120
197
|
}
|
|
121
198
|
|
|
122
199
|
// src/shared/worker-daemon/functions/start-daemon.function.ts
|
|
123
|
-
var
|
|
124
|
-
var
|
|
200
|
+
var import_node_fs9 = require("node:fs");
|
|
201
|
+
var import_node_path10 = require("node:path");
|
|
125
202
|
var import_node_os3 = require("node:os");
|
|
126
203
|
|
|
127
204
|
// src/shared/hash/functions/compute-sha256.ts
|
|
@@ -133,8 +210,8 @@ async function computeSha256(input) {
|
|
|
133
210
|
}
|
|
134
211
|
|
|
135
212
|
// src/shared/worker-daemon/classes/worker-daemon.class.ts
|
|
136
|
-
var
|
|
137
|
-
var
|
|
213
|
+
var import_node_fs8 = require("node:fs");
|
|
214
|
+
var import_node_path9 = require("node:path");
|
|
138
215
|
var import_node_os2 = require("node:os");
|
|
139
216
|
|
|
140
217
|
// src/shared/worker-daemon/functions/load-wasm-modules.function.ts
|
|
@@ -388,8 +465,11 @@ function rethrow(stage, label, err, path) {
|
|
|
388
465
|
|
|
389
466
|
// src/shared/worker-daemon/functions/create-ipc-server.function.ts
|
|
390
467
|
var import_node_net = require("node:net");
|
|
468
|
+
var LISTEN_BACKLOG = 256;
|
|
469
|
+
var KEEPALIVE_MS = 3e4;
|
|
391
470
|
function createIpcServer(socketPath, handler) {
|
|
392
471
|
const server = (0, import_node_net.createServer)((socket) => {
|
|
472
|
+
socket.setKeepAlive(true, KEEPALIVE_MS);
|
|
393
473
|
let buffer = "";
|
|
394
474
|
let processingQueue = Promise.resolve();
|
|
395
475
|
socket.on("data", (chunk) => {
|
|
@@ -409,11 +489,21 @@ function createIpcServer(socketPath, handler) {
|
|
|
409
489
|
);
|
|
410
490
|
});
|
|
411
491
|
});
|
|
412
|
-
|
|
413
|
-
|
|
492
|
+
return new Promise((resolve2, reject) => {
|
|
493
|
+
server.once("error", reject);
|
|
494
|
+
server.listen(
|
|
495
|
+
{ path: socketPath, backlog: LISTEN_BACKLOG },
|
|
496
|
+
() => {
|
|
497
|
+
server.removeListener("error", reject);
|
|
498
|
+
server.on("error", (err) => {
|
|
499
|
+
console.error(
|
|
500
|
+
`kbdb-worker: ipc server error: ${err.message}`
|
|
501
|
+
);
|
|
502
|
+
});
|
|
503
|
+
resolve2(server);
|
|
504
|
+
}
|
|
505
|
+
);
|
|
414
506
|
});
|
|
415
|
-
server.listen(socketPath);
|
|
416
|
-
return server;
|
|
417
507
|
}
|
|
418
508
|
function bigintReplacer(_key, value) {
|
|
419
509
|
return typeof value === "bigint" ? Number(value) : value;
|
|
@@ -453,6 +543,454 @@ function getIpcPath(ctx) {
|
|
|
453
543
|
return (0, import_node_path5.join)(getTmpdir(), `kbdb-${ctx}.sock`);
|
|
454
544
|
}
|
|
455
545
|
|
|
546
|
+
// src/shared/embedding/classes/null-embedding-provider.class.ts
|
|
547
|
+
var NullEmbeddingProvider = class {
|
|
548
|
+
/**
|
|
549
|
+
* Returns an empty `Float32Array` for each input text.
|
|
550
|
+
*
|
|
551
|
+
* @param texts - input strings (contents are ignored)
|
|
552
|
+
*/
|
|
553
|
+
embed(texts) {
|
|
554
|
+
return Promise.resolve(texts.map(() => new Float32Array(0)));
|
|
555
|
+
}
|
|
556
|
+
/** Always returns 0 -- no dimensions when disabled. */
|
|
557
|
+
dimensions() {
|
|
558
|
+
return 0;
|
|
559
|
+
}
|
|
560
|
+
/** Always returns `'none'`. */
|
|
561
|
+
modelName() {
|
|
562
|
+
return "none";
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
// src/shared/embedding/classes/onnx-embedding-provider.class.ts
|
|
567
|
+
var OnnxEmbeddingProvider = class {
|
|
568
|
+
/** Path to the ONNX model file. */
|
|
569
|
+
model;
|
|
570
|
+
/** Number of embedding dimensions the model produces. */
|
|
571
|
+
dims;
|
|
572
|
+
/**
|
|
573
|
+
* @param model - filesystem path to the ONNX model file
|
|
574
|
+
* @param dimensions - number of dimensions the model produces
|
|
575
|
+
*/
|
|
576
|
+
constructor(model, dimensions) {
|
|
577
|
+
this.model = model;
|
|
578
|
+
this.dims = dimensions;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Not yet implemented.
|
|
582
|
+
*
|
|
583
|
+
* @throws {Error} always -- ONNX Runtime is an optional peer
|
|
584
|
+
* dependency not yet wired
|
|
585
|
+
*/
|
|
586
|
+
embed(_texts) {
|
|
587
|
+
return Promise.reject(
|
|
588
|
+
new Error(
|
|
589
|
+
"ONNX Runtime not available; install onnxruntime-node"
|
|
590
|
+
)
|
|
591
|
+
);
|
|
592
|
+
}
|
|
593
|
+
/** Returns the configured number of embedding dimensions. */
|
|
594
|
+
dimensions() {
|
|
595
|
+
return this.dims;
|
|
596
|
+
}
|
|
597
|
+
/** Returns the configured model file path. */
|
|
598
|
+
modelName() {
|
|
599
|
+
return this.model;
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
// src/shared/embedding/functions/parse-api-embedding-response.function.ts
|
|
604
|
+
function parseApiEmbeddingResponse(raw) {
|
|
605
|
+
if (!isEmbeddingApiResponse(raw)) {
|
|
606
|
+
throw new Error("Unexpected embedding API response shape");
|
|
607
|
+
}
|
|
608
|
+
return raw.data.map((entry) => new Float32Array(entry.embedding));
|
|
609
|
+
}
|
|
610
|
+
function isEmbeddingApiResponse(value) {
|
|
611
|
+
if (typeof value !== "object" || value === null) {
|
|
612
|
+
return false;
|
|
613
|
+
}
|
|
614
|
+
const candidate = value;
|
|
615
|
+
if (!Array.isArray(candidate["data"])) {
|
|
616
|
+
return false;
|
|
617
|
+
}
|
|
618
|
+
return candidate["data"].every(isEmbeddingEntry);
|
|
619
|
+
}
|
|
620
|
+
function isEmbeddingEntry(value) {
|
|
621
|
+
if (typeof value !== "object" || value === null) {
|
|
622
|
+
return false;
|
|
623
|
+
}
|
|
624
|
+
const candidate = value;
|
|
625
|
+
return Array.isArray(candidate["embedding"]);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// src/shared/embedding/classes/api-embedding-provider.class.ts
|
|
629
|
+
var ApiEmbeddingProvider = class {
|
|
630
|
+
/** Remote endpoint URL for embedding requests. */
|
|
631
|
+
endpoint;
|
|
632
|
+
/** Number of dimensions in the returned vectors. */
|
|
633
|
+
dims;
|
|
634
|
+
/** Model name sent in the request body. */
|
|
635
|
+
model;
|
|
636
|
+
/**
|
|
637
|
+
* @param endpoint - URL to POST embedding requests to
|
|
638
|
+
* @param dimensions - number of vector dimensions expected
|
|
639
|
+
* @param model - optional model name; defaults to `'api'`
|
|
640
|
+
*/
|
|
641
|
+
constructor(endpoint, dimensions, model) {
|
|
642
|
+
this.endpoint = endpoint;
|
|
643
|
+
this.dims = dimensions;
|
|
644
|
+
this.model = model ?? "api";
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* Posts texts to the endpoint and returns one `Float32Array`
|
|
648
|
+
* per input.
|
|
649
|
+
*
|
|
650
|
+
* @throws {Error} when the HTTP response status is not 2xx
|
|
651
|
+
*/
|
|
652
|
+
async embed(texts) {
|
|
653
|
+
const response = await fetch(this.endpoint, {
|
|
654
|
+
method: "POST",
|
|
655
|
+
headers: { "Content-Type": "application/json" },
|
|
656
|
+
body: JSON.stringify({ input: texts, model: this.model })
|
|
657
|
+
});
|
|
658
|
+
if (!response.ok) {
|
|
659
|
+
throw new Error(
|
|
660
|
+
`Embedding API error: ${String(response.status)}`
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
const json = await response.json();
|
|
664
|
+
return parseApiEmbeddingResponse(json);
|
|
665
|
+
}
|
|
666
|
+
/** Returns the configured number of embedding dimensions. */
|
|
667
|
+
dimensions() {
|
|
668
|
+
return this.dims;
|
|
669
|
+
}
|
|
670
|
+
/** Returns the configured model name, defaulting to `'api'`. */
|
|
671
|
+
modelName() {
|
|
672
|
+
return this.model;
|
|
673
|
+
}
|
|
674
|
+
};
|
|
675
|
+
|
|
676
|
+
// src/shared/embedding/functions/create-embedding-provider.function.ts
|
|
677
|
+
function createEmbeddingProvider(config) {
|
|
678
|
+
if (!config || config.provider === "none") {
|
|
679
|
+
return new NullEmbeddingProvider();
|
|
680
|
+
}
|
|
681
|
+
if (config.provider === "onnx") {
|
|
682
|
+
return new OnnxEmbeddingProvider(
|
|
683
|
+
config.model ?? "",
|
|
684
|
+
config.dimensions ?? 0
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
return new ApiEmbeddingProvider(
|
|
688
|
+
config.endpoint ?? "",
|
|
689
|
+
config.dimensions ?? 0,
|
|
690
|
+
config.model
|
|
691
|
+
);
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
// src/shared/worker-daemon/functions/handle-hybrid-search.function.ts
|
|
695
|
+
var import_node_fs5 = require("node:fs");
|
|
696
|
+
var import_node_path6 = require("node:path");
|
|
697
|
+
|
|
698
|
+
// src/shared/embedding/functions/search-vectors.function.ts
|
|
699
|
+
var import_node_fs4 = require("node:fs");
|
|
700
|
+
|
|
701
|
+
// src/shared/embedding/functions/cosine-similarity.function.ts
|
|
702
|
+
function cosineSimilarity(a, b) {
|
|
703
|
+
let dot = 0;
|
|
704
|
+
let magA = 0;
|
|
705
|
+
let magB = 0;
|
|
706
|
+
for (let i = 0; i < a.length; i++) {
|
|
707
|
+
const ai = a[i] ?? 0;
|
|
708
|
+
const bi = b[i] ?? 0;
|
|
709
|
+
dot += ai * bi;
|
|
710
|
+
magA += ai * ai;
|
|
711
|
+
magB += bi * bi;
|
|
712
|
+
}
|
|
713
|
+
if (magA === 0 || magB === 0) {
|
|
714
|
+
return 0;
|
|
715
|
+
}
|
|
716
|
+
return dot / (Math.sqrt(magA) * Math.sqrt(magB));
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
// src/shared/embedding/functions/search-vectors.function.ts
|
|
720
|
+
var HEADER_SIZE = 32;
|
|
721
|
+
var KBID_WIDTH = 64;
|
|
722
|
+
function searchVectors(filePath, queryVector, topN) {
|
|
723
|
+
const buf = (0, import_node_fs4.readFileSync)(filePath);
|
|
724
|
+
if (buf.length < HEADER_SIZE) {
|
|
725
|
+
return [];
|
|
726
|
+
}
|
|
727
|
+
const dimensions = buf.readUInt32LE(8);
|
|
728
|
+
const count = buf.readUInt32LE(12);
|
|
729
|
+
const modelLen = buf.readUInt32LE(16);
|
|
730
|
+
const dataStart = HEADER_SIZE + modelLen;
|
|
731
|
+
const recordSize = KBID_WIDTH + dimensions * 4;
|
|
732
|
+
const results = [];
|
|
733
|
+
for (let i = 0; i < count; i++) {
|
|
734
|
+
const recOffset = dataStart + i * recordSize;
|
|
735
|
+
const kbid = buf.toString("utf-8", recOffset, recOffset + KBID_WIDTH).replace(/\0/g, "");
|
|
736
|
+
const vector = new Float32Array(dimensions);
|
|
737
|
+
for (let d = 0; d < dimensions; d++) {
|
|
738
|
+
vector[d] = buf.readFloatLE(recOffset + KBID_WIDTH + d * 4);
|
|
739
|
+
}
|
|
740
|
+
const score = cosineSimilarity(queryVector, vector);
|
|
741
|
+
results.push({ kbid, score });
|
|
742
|
+
}
|
|
743
|
+
results.sort((a, b) => b.score - a.score);
|
|
744
|
+
return results.slice(0, topN);
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// src/shared/embedding/functions/rrf-fuse.function.ts
|
|
748
|
+
var DEFAULT_K = 60;
|
|
749
|
+
function rrfFuse(lexicalRanks, vectorRanks, k = DEFAULT_K) {
|
|
750
|
+
const scores = /* @__PURE__ */ new Map();
|
|
751
|
+
for (const [kbid, rank] of lexicalRanks) {
|
|
752
|
+
scores.set(kbid, (scores.get(kbid) ?? 0) + 1 / (k + rank));
|
|
753
|
+
}
|
|
754
|
+
for (const [kbid, rank] of vectorRanks) {
|
|
755
|
+
scores.set(kbid, (scores.get(kbid) ?? 0) + 1 / (k + rank));
|
|
756
|
+
}
|
|
757
|
+
return scores;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
// src/shared/worker-daemon/classes/ipc-error.class.ts
|
|
761
|
+
var IpcError = class extends Error {
|
|
762
|
+
/** JSON-RPC error code. */
|
|
763
|
+
code;
|
|
764
|
+
/**
|
|
765
|
+
* @param code - JSON-RPC error code (e.g. `-32601` for
|
|
766
|
+
* method-not-found, `-32000` for application errors)
|
|
767
|
+
* @param message - human-readable error description
|
|
768
|
+
*/
|
|
769
|
+
constructor(code, message) {
|
|
770
|
+
super(message);
|
|
771
|
+
this.code = code;
|
|
772
|
+
this.name = "IpcError";
|
|
773
|
+
}
|
|
774
|
+
};
|
|
775
|
+
|
|
776
|
+
// src/shared/worker-daemon/functions/handle-hybrid-search.function.ts
|
|
777
|
+
async function fuseSearchResults(lexical, algo, query, provider, targetDir) {
|
|
778
|
+
if (algo === "lexical") {
|
|
779
|
+
return {
|
|
780
|
+
...lexical,
|
|
781
|
+
search_mode: "lexical",
|
|
782
|
+
retrieval_method: "lexical"
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
assertProvider(provider);
|
|
786
|
+
const embeddings = await provider.embed([query]);
|
|
787
|
+
if (embeddings.length === 0 || embeddings[0].length === 0) {
|
|
788
|
+
return {
|
|
789
|
+
...lexical,
|
|
790
|
+
search_mode: algo,
|
|
791
|
+
retrieval_method: "lexical"
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
const queryVec = embeddings[0];
|
|
795
|
+
const vectorPath = (0, import_node_path6.join)(targetDir, "vectors.idx");
|
|
796
|
+
const vectorResults = (0, import_node_fs5.existsSync)(vectorPath) ? searchVectors(vectorPath, queryVec, lexical.limit) : [];
|
|
797
|
+
if (algo === "vector") {
|
|
798
|
+
return buildVectorOnly(vectorResults, lexical);
|
|
799
|
+
}
|
|
800
|
+
return buildHybrid(lexical, vectorResults);
|
|
801
|
+
}
|
|
802
|
+
function assertProvider(provider) {
|
|
803
|
+
if (!provider || provider.dimensions() === 0) {
|
|
804
|
+
throw new IpcError(
|
|
805
|
+
-32e3,
|
|
806
|
+
"embedding provider not configured; set [embedding] in worker.toml"
|
|
807
|
+
);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
function buildVectorOnly(vectorResults, lexical) {
|
|
811
|
+
const lookup = new Map(
|
|
812
|
+
lexical.items.map((item) => [item.kbid, item])
|
|
813
|
+
);
|
|
814
|
+
const items = vectorResults.map((vr) => {
|
|
815
|
+
const existing = lookup.get(vr.kbid);
|
|
816
|
+
if (existing) {
|
|
817
|
+
return { ...existing, score: vr.score };
|
|
818
|
+
}
|
|
819
|
+
return emptyItem(vr.kbid, vr.score);
|
|
820
|
+
});
|
|
821
|
+
return {
|
|
822
|
+
items,
|
|
823
|
+
total: items.length,
|
|
824
|
+
offset: lexical.offset,
|
|
825
|
+
limit: lexical.limit,
|
|
826
|
+
has_more: false,
|
|
827
|
+
relaxed: lexical.relaxed,
|
|
828
|
+
search_mode: "vector",
|
|
829
|
+
retrieval_method: "vector"
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
function buildHybrid(lexical, vectorResults) {
|
|
833
|
+
const lexRanks = /* @__PURE__ */ new Map();
|
|
834
|
+
lexical.items.forEach((item, i) => {
|
|
835
|
+
lexRanks.set(item.kbid, i + 1);
|
|
836
|
+
});
|
|
837
|
+
const vecRanks = /* @__PURE__ */ new Map();
|
|
838
|
+
vectorResults.forEach((vr, i) => {
|
|
839
|
+
vecRanks.set(vr.kbid, i + 1);
|
|
840
|
+
});
|
|
841
|
+
const fused = rrfFuse(lexRanks, vecRanks);
|
|
842
|
+
const sorted = [...fused.entries()].sort((a, b) => b[1] - a[1]);
|
|
843
|
+
const lookup = new Map(
|
|
844
|
+
lexical.items.map((item) => [item.kbid, item])
|
|
845
|
+
);
|
|
846
|
+
const items = sorted.slice(0, lexical.limit).map(([kbid, score]) => {
|
|
847
|
+
const existing = lookup.get(kbid);
|
|
848
|
+
if (existing) {
|
|
849
|
+
return { ...existing, score };
|
|
850
|
+
}
|
|
851
|
+
return emptyItem(kbid, score);
|
|
852
|
+
});
|
|
853
|
+
return {
|
|
854
|
+
items,
|
|
855
|
+
total: sorted.length,
|
|
856
|
+
offset: lexical.offset,
|
|
857
|
+
limit: lexical.limit,
|
|
858
|
+
has_more: sorted.length > lexical.limit,
|
|
859
|
+
relaxed: lexical.relaxed,
|
|
860
|
+
search_mode: "hybrid",
|
|
861
|
+
retrieval_method: "rrf"
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
function emptyItem(kbid, score) {
|
|
865
|
+
return {
|
|
866
|
+
kbid,
|
|
867
|
+
heading: null,
|
|
868
|
+
type: "",
|
|
869
|
+
docids: [],
|
|
870
|
+
score,
|
|
871
|
+
confidence: 0,
|
|
872
|
+
snippet: "",
|
|
873
|
+
matched_terms: [],
|
|
874
|
+
matched_fields: [],
|
|
875
|
+
created_at: ""
|
|
876
|
+
};
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
// src/shared/embedding/functions/rebuild-vectors.function.ts
|
|
880
|
+
var import_node_fs7 = require("node:fs");
|
|
881
|
+
var import_node_path8 = require("node:path");
|
|
882
|
+
|
|
883
|
+
// src/shared/embedding/functions/build-vector-index.function.ts
|
|
884
|
+
var import_node_fs6 = require("node:fs");
|
|
885
|
+
var import_node_path7 = require("node:path");
|
|
886
|
+
var MAGIC = "KBVX";
|
|
887
|
+
var VERSION = 1;
|
|
888
|
+
var KBID_WIDTH2 = 64;
|
|
889
|
+
var HEADER_SIZE2 = 32;
|
|
890
|
+
function writeHeader(buf, dimensions, count, modelLen) {
|
|
891
|
+
buf.write(MAGIC, 0, "ascii");
|
|
892
|
+
buf.writeUInt32LE(VERSION, 4);
|
|
893
|
+
buf.writeUInt32LE(dimensions, 8);
|
|
894
|
+
buf.writeUInt32LE(count, 12);
|
|
895
|
+
buf.writeUInt32LE(modelLen, 16);
|
|
896
|
+
}
|
|
897
|
+
function writeRecord(buf, offset, entry, dimensions, encoder3) {
|
|
898
|
+
const kbidBytes = encoder3.encode(entry.kbid);
|
|
899
|
+
kbidBytes.forEach((b, i) => {
|
|
900
|
+
if (i < KBID_WIDTH2) buf.writeUInt8(b, offset + i);
|
|
901
|
+
});
|
|
902
|
+
for (let d = 0; d < dimensions; d++) {
|
|
903
|
+
buf.writeFloatLE(
|
|
904
|
+
entry.vector[d] ?? 0,
|
|
905
|
+
offset + KBID_WIDTH2 + d * 4
|
|
906
|
+
);
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
function buildVectorIndex(dirPath, modelName, dimensions, entries) {
|
|
910
|
+
const encoder3 = new TextEncoder();
|
|
911
|
+
const modelBytes = encoder3.encode(modelName);
|
|
912
|
+
const modelLen = modelBytes.length;
|
|
913
|
+
const recordSize = KBID_WIDTH2 + dimensions * 4;
|
|
914
|
+
const totalSize = HEADER_SIZE2 + modelLen + entries.length * recordSize;
|
|
915
|
+
const buf = Buffer.alloc(totalSize, 0);
|
|
916
|
+
writeHeader(buf, dimensions, entries.length, modelLen);
|
|
917
|
+
modelBytes.forEach((b, i) => buf.writeUInt8(b, HEADER_SIZE2 + i));
|
|
918
|
+
let recOffset = HEADER_SIZE2 + modelLen;
|
|
919
|
+
for (const entry of entries) {
|
|
920
|
+
writeRecord(buf, recOffset, entry, dimensions, encoder3);
|
|
921
|
+
recOffset += recordSize;
|
|
922
|
+
}
|
|
923
|
+
(0, import_node_fs6.writeFileSync)((0, import_node_path7.join)(dirPath, "vectors.idx"), buf);
|
|
924
|
+
return Promise.resolve();
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
// src/shared/embedding/functions/rebuild-vectors.function.ts
|
|
928
|
+
var SECTION_SEPARATOR = "\n---\n";
|
|
929
|
+
function extractBody(raw) {
|
|
930
|
+
const sep = raw.indexOf(SECTION_SEPARATOR);
|
|
931
|
+
return sep >= 0 ? raw.slice(sep + SECTION_SEPARATOR.length) : raw;
|
|
932
|
+
}
|
|
933
|
+
function collectSections(sectionsDir) {
|
|
934
|
+
let shards;
|
|
935
|
+
try {
|
|
936
|
+
shards = (0, import_node_fs7.readdirSync)(sectionsDir);
|
|
937
|
+
} catch {
|
|
938
|
+
return [];
|
|
939
|
+
}
|
|
940
|
+
const result = [];
|
|
941
|
+
for (const shard of shards) {
|
|
942
|
+
let files;
|
|
943
|
+
try {
|
|
944
|
+
files = (0, import_node_fs7.readdirSync)((0, import_node_path8.join)(sectionsDir, shard));
|
|
945
|
+
} catch {
|
|
946
|
+
continue;
|
|
947
|
+
}
|
|
948
|
+
for (const file of files) {
|
|
949
|
+
if (!file.endsWith(".section")) continue;
|
|
950
|
+
const kbid = file.slice(0, -8);
|
|
951
|
+
try {
|
|
952
|
+
const raw = (0, import_node_fs7.readFileSync)(
|
|
953
|
+
(0, import_node_path8.join)(sectionsDir, shard, file),
|
|
954
|
+
"utf-8"
|
|
955
|
+
);
|
|
956
|
+
const body = extractBody(raw);
|
|
957
|
+
if (body.length > 0) {
|
|
958
|
+
result.push({ kbid, body });
|
|
959
|
+
}
|
|
960
|
+
} catch {
|
|
961
|
+
continue;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
return result;
|
|
966
|
+
}
|
|
967
|
+
async function rebuildVectors(targetDir, provider) {
|
|
968
|
+
if (provider.dimensions() === 0) {
|
|
969
|
+
return 0;
|
|
970
|
+
}
|
|
971
|
+
const sectionsDir = (0, import_node_path8.join)(targetDir, "sections");
|
|
972
|
+
if (!(0, import_node_fs7.existsSync)(sectionsDir)) {
|
|
973
|
+
return 0;
|
|
974
|
+
}
|
|
975
|
+
const sections = collectSections(sectionsDir);
|
|
976
|
+
if (sections.length === 0) {
|
|
977
|
+
return 0;
|
|
978
|
+
}
|
|
979
|
+
const texts = sections.map((s) => s.body);
|
|
980
|
+
const vectors = await provider.embed(texts);
|
|
981
|
+
const entries = sections.map((s, i) => ({
|
|
982
|
+
kbid: s.kbid,
|
|
983
|
+
vector: vectors[i] ?? new Float32Array(provider.dimensions())
|
|
984
|
+
}));
|
|
985
|
+
await buildVectorIndex(
|
|
986
|
+
targetDir,
|
|
987
|
+
provider.modelName(),
|
|
988
|
+
provider.dimensions(),
|
|
989
|
+
entries
|
|
990
|
+
);
|
|
991
|
+
return sections.length;
|
|
992
|
+
}
|
|
993
|
+
|
|
456
994
|
// src/shared/wasm-codec/functions/encode-string.function.ts
|
|
457
995
|
var encoder = new TextEncoder();
|
|
458
996
|
function encodeString(value) {
|
|
@@ -1270,7 +1808,9 @@ var WASM_METHOD_MAP = {
|
|
|
1270
1808
|
list_docs_by_type: "worker_list_docs_by_type",
|
|
1271
1809
|
recall: "worker_recall",
|
|
1272
1810
|
export: "worker_export",
|
|
1273
|
-
exportDb: "worker_export"
|
|
1811
|
+
exportDb: "worker_export",
|
|
1812
|
+
importDb: "worker_import",
|
|
1813
|
+
import_db: "worker_import"
|
|
1274
1814
|
};
|
|
1275
1815
|
var CONFIG_PREFIX = "config_";
|
|
1276
1816
|
var CONFIG_KEY_MAP = {
|
|
@@ -1279,7 +1819,7 @@ var CONFIG_KEY_MAP = {
|
|
|
1279
1819
|
item_limit: "itemLimit",
|
|
1280
1820
|
index_limit: "indexLimit"
|
|
1281
1821
|
};
|
|
1282
|
-
var
|
|
1822
|
+
var IpcError2 = class extends Error {
|
|
1283
1823
|
/** JSON-RPC error code. */
|
|
1284
1824
|
code;
|
|
1285
1825
|
constructor(code, message) {
|
|
@@ -1301,6 +1841,7 @@ var WorkerDaemon = class {
|
|
|
1301
1841
|
}
|
|
1302
1842
|
_connectionCount = 0;
|
|
1303
1843
|
_wasmModules = null;
|
|
1844
|
+
_embeddingProvider = null;
|
|
1304
1845
|
_idleAt = 0;
|
|
1305
1846
|
_idleTimer = null;
|
|
1306
1847
|
_server = null;
|
|
@@ -1339,15 +1880,15 @@ var WorkerDaemon = class {
|
|
|
1339
1880
|
* catches this, prints to stderr, and exits with code 1
|
|
1340
1881
|
*/
|
|
1341
1882
|
checkPreconditions() {
|
|
1342
|
-
if (!(0,
|
|
1883
|
+
if (!(0, import_node_fs8.existsSync)(this.targetDir)) {
|
|
1343
1884
|
throw new Error(
|
|
1344
1885
|
`database directory not found: ${this.targetDir}`
|
|
1345
1886
|
);
|
|
1346
1887
|
}
|
|
1347
1888
|
try {
|
|
1348
|
-
(0,
|
|
1889
|
+
(0, import_node_fs8.accessSync)(
|
|
1349
1890
|
this.targetDir,
|
|
1350
|
-
|
|
1891
|
+
import_node_fs8.constants.R_OK | import_node_fs8.constants.W_OK
|
|
1351
1892
|
);
|
|
1352
1893
|
} catch {
|
|
1353
1894
|
throw new Error(
|
|
@@ -1373,19 +1914,20 @@ var WorkerDaemon = class {
|
|
|
1373
1914
|
this._wasmDir
|
|
1374
1915
|
);
|
|
1375
1916
|
this._wasmModules = wasmModules;
|
|
1917
|
+
this._embeddingProvider = createEmbeddingProvider(
|
|
1918
|
+
this.config.embedding
|
|
1919
|
+
);
|
|
1376
1920
|
this.initWorkerContext();
|
|
1377
1921
|
this.runStartupIntegrityCheck();
|
|
1378
|
-
const pidPath = (0, import_node_path6.join)((0, import_node_os2.tmpdir)(), `kbdb-${this.ctx}.pid`);
|
|
1379
|
-
(0, import_node_fs4.writeFileSync)(pidPath, process.pid.toString());
|
|
1380
1922
|
const ipcPath = getIpcPath(this.ctx);
|
|
1381
|
-
if ((0,
|
|
1923
|
+
if ((0, import_node_fs8.existsSync)(ipcPath)) {
|
|
1382
1924
|
try {
|
|
1383
|
-
(0,
|
|
1925
|
+
(0, import_node_fs8.unlinkSync)(ipcPath);
|
|
1384
1926
|
} catch {
|
|
1385
1927
|
}
|
|
1386
1928
|
}
|
|
1387
1929
|
const handler = (req) => this.handleRequest(req);
|
|
1388
|
-
this._server = createIpcServer(ipcPath, handler);
|
|
1930
|
+
this._server = await createIpcServer(ipcPath, handler);
|
|
1389
1931
|
this._server.on("connection", () => {
|
|
1390
1932
|
this.incrementConnections();
|
|
1391
1933
|
this.resetIdleTimer();
|
|
@@ -1396,6 +1938,8 @@ var WorkerDaemon = class {
|
|
|
1396
1938
|
this.resetIdleTimer();
|
|
1397
1939
|
}
|
|
1398
1940
|
});
|
|
1941
|
+
const pidPath = (0, import_node_path9.join)((0, import_node_os2.tmpdir)(), `kbdb-${this.ctx}.pid`);
|
|
1942
|
+
(0, import_node_fs8.writeFileSync)(pidPath, process.pid.toString());
|
|
1399
1943
|
this.resetIdleTimer();
|
|
1400
1944
|
}
|
|
1401
1945
|
/**
|
|
@@ -1415,19 +1959,19 @@ var WorkerDaemon = class {
|
|
|
1415
1959
|
this._server = null;
|
|
1416
1960
|
}
|
|
1417
1961
|
this._wasmModules = null;
|
|
1418
|
-
const pidPath = (0,
|
|
1962
|
+
const pidPath = (0, import_node_path9.join)((0, import_node_os2.tmpdir)(), `kbdb-${this.ctx}.pid`);
|
|
1419
1963
|
try {
|
|
1420
|
-
(0,
|
|
1964
|
+
(0, import_node_fs8.unlinkSync)(pidPath);
|
|
1421
1965
|
} catch {
|
|
1422
1966
|
}
|
|
1423
1967
|
const ipcPath = getIpcPath(this.ctx);
|
|
1424
1968
|
try {
|
|
1425
|
-
(0,
|
|
1969
|
+
(0, import_node_fs8.unlinkSync)(ipcPath);
|
|
1426
1970
|
} catch {
|
|
1427
1971
|
}
|
|
1428
|
-
const crashPath = (0,
|
|
1972
|
+
const crashPath = (0, import_node_path9.join)((0, import_node_os2.tmpdir)(), `kbdb-${this.ctx}.crash`);
|
|
1429
1973
|
try {
|
|
1430
|
-
(0,
|
|
1974
|
+
(0, import_node_fs8.unlinkSync)(crashPath);
|
|
1431
1975
|
} catch {
|
|
1432
1976
|
}
|
|
1433
1977
|
process.exit(0);
|
|
@@ -1462,7 +2006,7 @@ var WorkerDaemon = class {
|
|
|
1462
2006
|
};
|
|
1463
2007
|
} catch (err) {
|
|
1464
2008
|
this._idleAt = Math.floor(Date.now() / 1e3);
|
|
1465
|
-
if (err instanceof
|
|
2009
|
+
if (err instanceof IpcError2) {
|
|
1466
2010
|
return this.errorResponse(
|
|
1467
2011
|
request.id,
|
|
1468
2012
|
err.code,
|
|
@@ -1520,10 +2064,10 @@ var WorkerDaemon = class {
|
|
|
1520
2064
|
}
|
|
1521
2065
|
/** Reads catalog.toml and validates the version field. */
|
|
1522
2066
|
checkCatalogVersion() {
|
|
1523
|
-
const catalogPath = (0,
|
|
2067
|
+
const catalogPath = (0, import_node_path9.join)(this.targetDir, "catalog.toml");
|
|
1524
2068
|
let text;
|
|
1525
2069
|
try {
|
|
1526
|
-
text = (0,
|
|
2070
|
+
text = (0, import_node_fs8.readFileSync)(catalogPath, "utf-8");
|
|
1527
2071
|
} catch {
|
|
1528
2072
|
throw new Error(
|
|
1529
2073
|
`cannot read database directory: ${this.targetDir} -- permission denied`
|
|
@@ -1582,7 +2126,7 @@ var WorkerDaemon = class {
|
|
|
1582
2126
|
if (wasmMethod !== void 0) {
|
|
1583
2127
|
return this.dispatchWasm(method, wasmMethod, params);
|
|
1584
2128
|
}
|
|
1585
|
-
throw new
|
|
2129
|
+
throw new IpcError2(-32601, `Method not found: ${method}`);
|
|
1586
2130
|
}
|
|
1587
2131
|
async dispatchWasm(method, wasmExport, params) {
|
|
1588
2132
|
if (method === "search" || method === "query") {
|
|
@@ -1648,13 +2192,16 @@ var WorkerDaemon = class {
|
|
|
1648
2192
|
return this.handleGc();
|
|
1649
2193
|
}
|
|
1650
2194
|
if (method === "rebuildIndexes" || method === "rebuild_indexes") {
|
|
1651
|
-
return this.handleRebuild();
|
|
2195
|
+
return await this.handleRebuild();
|
|
1652
2196
|
}
|
|
1653
2197
|
if (method === "initDirectory" || method === "init_directory") {
|
|
1654
2198
|
return this.handleInitDirectory(params);
|
|
1655
2199
|
}
|
|
2200
|
+
if (method === "importDb" || method === "import_db") {
|
|
2201
|
+
return await this.handleImport(params);
|
|
2202
|
+
}
|
|
1656
2203
|
if (method === "migrateDatabase") {
|
|
1657
|
-
throw new
|
|
2204
|
+
throw new IpcError2(
|
|
1658
2205
|
-32601,
|
|
1659
2206
|
"migrateDatabase is not yet supported"
|
|
1660
2207
|
);
|
|
@@ -1665,12 +2212,25 @@ var WorkerDaemon = class {
|
|
|
1665
2212
|
}
|
|
1666
2213
|
}
|
|
1667
2214
|
// -- Search/query (token-based async) --
|
|
1668
|
-
handleSearch(params) {
|
|
2215
|
+
async handleSearch(params) {
|
|
1669
2216
|
const query = params["query"] ?? "";
|
|
1670
2217
|
const mode = params["mode"] ?? "and";
|
|
1671
2218
|
const limit = Number(params["limit"] ?? 20);
|
|
1672
2219
|
const offset = Number(params["offset"] ?? 0);
|
|
2220
|
+
const algo = params["algo"] ?? "lexical";
|
|
1673
2221
|
const encoded = encodeSearchParams(query, mode, limit, offset);
|
|
2222
|
+
const start = Date.now();
|
|
2223
|
+
const lexical = this.runLexicalSearch(encoded);
|
|
2224
|
+
const fused = await fuseSearchResults(
|
|
2225
|
+
lexical,
|
|
2226
|
+
algo,
|
|
2227
|
+
query,
|
|
2228
|
+
this._embeddingProvider ?? void 0,
|
|
2229
|
+
this.targetDir
|
|
2230
|
+
);
|
|
2231
|
+
return { ...fused, elapsed_ms: Date.now() - start };
|
|
2232
|
+
}
|
|
2233
|
+
runLexicalSearch(encoded) {
|
|
1674
2234
|
const searchFn = this.getExport("worker_search");
|
|
1675
2235
|
const ptr = this.wasmAlloc(encoded.length);
|
|
1676
2236
|
this.wasmWrite(ptr, encoded);
|
|
@@ -1679,20 +2239,17 @@ var WorkerDaemon = class {
|
|
|
1679
2239
|
const statusFn = this.getExport("worker_result_status");
|
|
1680
2240
|
const status = statusFn(token);
|
|
1681
2241
|
if (status === 3) {
|
|
1682
|
-
|
|
1683
|
-
getResultFn2(token);
|
|
2242
|
+
this.getExport("worker_get_result")(token);
|
|
1684
2243
|
const errBytes = this.readReturnSlot();
|
|
1685
|
-
|
|
1686
|
-
throw new IpcError(-32e3, errMsg);
|
|
2244
|
+
throw new IpcError2(-32e3, new TextDecoder().decode(errBytes));
|
|
1687
2245
|
}
|
|
1688
2246
|
const getResultFn = this.getExport("worker_get_result");
|
|
1689
2247
|
const rc = getResultFn(token);
|
|
1690
2248
|
if (rc === -1) {
|
|
1691
2249
|
const errBytes = this.readReturnSlot();
|
|
1692
|
-
throw new
|
|
2250
|
+
throw new IpcError2(-32e3, new TextDecoder().decode(errBytes));
|
|
1693
2251
|
}
|
|
1694
|
-
|
|
1695
|
-
return decodePagedSearchResult(resultBytes);
|
|
2252
|
+
return decodePagedSearchResult(this.readReturnSlot());
|
|
1696
2253
|
}
|
|
1697
2254
|
// -- Token status/result (u32 direct params) --
|
|
1698
2255
|
handleResultStatus(params) {
|
|
@@ -1707,7 +2264,7 @@ var WorkerDaemon = class {
|
|
|
1707
2264
|
const rc = fn(token);
|
|
1708
2265
|
if (rc === -1) {
|
|
1709
2266
|
const errBytes = this.readReturnSlot();
|
|
1710
|
-
throw new
|
|
2267
|
+
throw new IpcError2(-32e3, new TextDecoder().decode(errBytes));
|
|
1711
2268
|
}
|
|
1712
2269
|
const bytes = this.readReturnSlot();
|
|
1713
2270
|
return decodePagedSearchResult(bytes);
|
|
@@ -1734,7 +2291,11 @@ var WorkerDaemon = class {
|
|
|
1734
2291
|
const encoded = encodeAddSectionParams(input);
|
|
1735
2292
|
const bytes = this.callWasmSync("worker_add_section", encoded);
|
|
1736
2293
|
const decoded = decodeAddSectionResult(bytes);
|
|
1737
|
-
const
|
|
2294
|
+
const wasmDups = decoded.nearDuplicates;
|
|
2295
|
+
const tsDups = wasmDups.length > 0 ? [] : this.scanNearDuplicates(input.content, decoded.kbid);
|
|
2296
|
+
const nearDups = (wasmDups.length > 0 ? wasmDups : tsDups).map(
|
|
2297
|
+
(d) => ({ ...d, method: "jaccard" })
|
|
2298
|
+
);
|
|
1738
2299
|
return {
|
|
1739
2300
|
kbid: decoded.kbid,
|
|
1740
2301
|
indexed_terms_count: decoded.indexedTermsCount,
|
|
@@ -1823,7 +2384,7 @@ var WorkerDaemon = class {
|
|
|
1823
2384
|
this.wasmFree(ptr, encoded.length);
|
|
1824
2385
|
if (rc === -1) {
|
|
1825
2386
|
const errBytes = this.readReturnSlot();
|
|
1826
|
-
throw new
|
|
2387
|
+
throw new IpcError2(
|
|
1827
2388
|
-32e3,
|
|
1828
2389
|
new TextDecoder().decode(errBytes) || "invalidate failed"
|
|
1829
2390
|
);
|
|
@@ -1862,7 +2423,12 @@ var WorkerDaemon = class {
|
|
|
1862
2423
|
this.callWasmZeroArg("worker_status");
|
|
1863
2424
|
const bytes = this.readReturnSlot();
|
|
1864
2425
|
const text = new TextDecoder().decode(bytes);
|
|
1865
|
-
|
|
2426
|
+
const kv = decodeKeyValueText(text);
|
|
2427
|
+
const mem = this._wasmModules?.memory;
|
|
2428
|
+
if (mem) {
|
|
2429
|
+
kv["wasm_memory_bytes"] = String(mem.buffer.byteLength);
|
|
2430
|
+
}
|
|
2431
|
+
return kv;
|
|
1866
2432
|
}
|
|
1867
2433
|
handleIntegrityCheck() {
|
|
1868
2434
|
this.callWasmZeroArg("worker_check_integrity");
|
|
@@ -1885,13 +2451,13 @@ var WorkerDaemon = class {
|
|
|
1885
2451
|
stale_sources: staleSources
|
|
1886
2452
|
};
|
|
1887
2453
|
}
|
|
1888
|
-
handleRebuild() {
|
|
2454
|
+
async handleRebuild() {
|
|
1889
2455
|
const fn = this.getExport("worker_rebuild_indexes");
|
|
1890
2456
|
const rc = fn();
|
|
1891
2457
|
if (rc === -1) {
|
|
1892
2458
|
const errBytes = this.readReturnSlot();
|
|
1893
2459
|
const errMsg = new TextDecoder().decode(errBytes);
|
|
1894
|
-
throw new
|
|
2460
|
+
throw new IpcError2(-32e3, errMsg || "rebuild failed");
|
|
1895
2461
|
}
|
|
1896
2462
|
const resultBytes = this.readReturnSlot();
|
|
1897
2463
|
const reindexed = resultBytes.length >= 4 ? new DataView(
|
|
@@ -1899,7 +2465,18 @@ var WorkerDaemon = class {
|
|
|
1899
2465
|
resultBytes.byteOffset,
|
|
1900
2466
|
resultBytes.byteLength
|
|
1901
2467
|
).getUint32(0, true) : 0;
|
|
1902
|
-
|
|
2468
|
+
let vectorsRebuilt = 0;
|
|
2469
|
+
if (this._embeddingProvider !== null) {
|
|
2470
|
+
vectorsRebuilt = await rebuildVectors(
|
|
2471
|
+
this.targetDir,
|
|
2472
|
+
this._embeddingProvider
|
|
2473
|
+
);
|
|
2474
|
+
}
|
|
2475
|
+
return {
|
|
2476
|
+
ok: true,
|
|
2477
|
+
sections_reindexed: reindexed,
|
|
2478
|
+
vectors_rebuilt: vectorsRebuilt
|
|
2479
|
+
};
|
|
1903
2480
|
}
|
|
1904
2481
|
// -- Export (read operation, no lock required) --
|
|
1905
2482
|
handleExport(params) {
|
|
@@ -1917,14 +2494,57 @@ var WorkerDaemon = class {
|
|
|
1917
2494
|
elapsed_ms: elapsed
|
|
1918
2495
|
};
|
|
1919
2496
|
}
|
|
2497
|
+
async handleImport(params) {
|
|
2498
|
+
const sourcePath = params["sourcePath"] ?? "";
|
|
2499
|
+
const dryRun = params["dryRun"] === true;
|
|
2500
|
+
const start = Date.now();
|
|
2501
|
+
const sectionCount = this.countFiles(
|
|
2502
|
+
(0, import_node_path9.join)(sourcePath, "sections"),
|
|
2503
|
+
".section"
|
|
2504
|
+
);
|
|
2505
|
+
const documentCount = this.countFiles(
|
|
2506
|
+
(0, import_node_path9.join)(sourcePath, "documents"),
|
|
2507
|
+
".toml"
|
|
2508
|
+
);
|
|
2509
|
+
let rebuilt = false;
|
|
2510
|
+
if (!dryRun && sectionCount > 0) {
|
|
2511
|
+
await this.handleRebuild();
|
|
2512
|
+
rebuilt = true;
|
|
2513
|
+
}
|
|
2514
|
+
return {
|
|
2515
|
+
sections_imported: sectionCount,
|
|
2516
|
+
documents_imported: documentCount,
|
|
2517
|
+
rebuilt,
|
|
2518
|
+
dry_run: dryRun,
|
|
2519
|
+
elapsed_ms: Date.now() - start
|
|
2520
|
+
};
|
|
2521
|
+
}
|
|
2522
|
+
countFiles(dir, ext) {
|
|
2523
|
+
if (!(0, import_node_fs8.existsSync)(dir)) return 0;
|
|
2524
|
+
return this.collectFiles(dir, ext).length;
|
|
2525
|
+
}
|
|
2526
|
+
collectFiles(dir, ext) {
|
|
2527
|
+
const result = [];
|
|
2528
|
+
for (const entry of (0, import_node_fs8.readdirSync)(dir, {
|
|
2529
|
+
withFileTypes: true
|
|
2530
|
+
})) {
|
|
2531
|
+
const full = (0, import_node_path9.join)(dir, entry.name);
|
|
2532
|
+
if (entry.isDirectory()) {
|
|
2533
|
+
result.push(...this.collectFiles(full, ext));
|
|
2534
|
+
} else if (entry.name.endsWith(ext)) {
|
|
2535
|
+
result.push(full);
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
return result;
|
|
2539
|
+
}
|
|
1920
2540
|
// -- Near-duplicate detection --
|
|
1921
2541
|
scanNearDuplicates(content, newKbid) {
|
|
1922
2542
|
const newTerms = this.extractTermSet(content);
|
|
1923
2543
|
if (newTerms.size === 0) return [];
|
|
1924
|
-
const sectionsDir = (0,
|
|
2544
|
+
const sectionsDir = (0, import_node_path9.join)(this.targetDir, "sections");
|
|
1925
2545
|
let shards;
|
|
1926
2546
|
try {
|
|
1927
|
-
shards = (0,
|
|
2547
|
+
shards = (0, import_node_fs8.readdirSync)(sectionsDir);
|
|
1928
2548
|
} catch {
|
|
1929
2549
|
return [];
|
|
1930
2550
|
}
|
|
@@ -1932,7 +2552,7 @@ var WorkerDaemon = class {
|
|
|
1932
2552
|
for (const shard of shards) {
|
|
1933
2553
|
let files;
|
|
1934
2554
|
try {
|
|
1935
|
-
files = (0,
|
|
2555
|
+
files = (0, import_node_fs8.readdirSync)((0, import_node_path9.join)(sectionsDir, shard));
|
|
1936
2556
|
} catch {
|
|
1937
2557
|
continue;
|
|
1938
2558
|
}
|
|
@@ -1941,8 +2561,8 @@ var WorkerDaemon = class {
|
|
|
1941
2561
|
const kbid = file.slice(0, -8);
|
|
1942
2562
|
if (kbid === newKbid) continue;
|
|
1943
2563
|
try {
|
|
1944
|
-
const data = (0,
|
|
1945
|
-
(0,
|
|
2564
|
+
const data = (0, import_node_fs8.readFileSync)(
|
|
2565
|
+
(0, import_node_path9.join)(sectionsDir, shard, file),
|
|
1946
2566
|
"utf-8"
|
|
1947
2567
|
);
|
|
1948
2568
|
const sep = data.indexOf("\n---\n");
|
|
@@ -2098,7 +2718,7 @@ var WorkerDaemon = class {
|
|
|
2098
2718
|
if (rc === -1) {
|
|
2099
2719
|
const errBytes = this.readReturnSlot();
|
|
2100
2720
|
const errMsg = new TextDecoder().decode(errBytes);
|
|
2101
|
-
throw new
|
|
2721
|
+
throw new IpcError2(-32e3, errMsg || exportName + " failed");
|
|
2102
2722
|
}
|
|
2103
2723
|
return this.readReturnSlot();
|
|
2104
2724
|
}
|
|
@@ -2108,7 +2728,7 @@ var WorkerDaemon = class {
|
|
|
2108
2728
|
if (rc === -1) {
|
|
2109
2729
|
const errBytes = this.readReturnSlot();
|
|
2110
2730
|
const errMsg = new TextDecoder().decode(errBytes);
|
|
2111
|
-
throw new
|
|
2731
|
+
throw new IpcError2(-32e3, errMsg || exportName + " failed");
|
|
2112
2732
|
}
|
|
2113
2733
|
}
|
|
2114
2734
|
invokeWasmRaw(exportName, input) {
|
|
@@ -2116,10 +2736,10 @@ var WorkerDaemon = class {
|
|
|
2116
2736
|
}
|
|
2117
2737
|
handleCheckVersion(params) {
|
|
2118
2738
|
const targetPath = typeof params.targetPath === "string" ? params.targetPath : this.targetDir;
|
|
2119
|
-
const catalogPath = (0,
|
|
2739
|
+
const catalogPath = (0, import_node_path9.join)(targetPath, "catalog.toml");
|
|
2120
2740
|
let text;
|
|
2121
2741
|
try {
|
|
2122
|
-
text = (0,
|
|
2742
|
+
text = (0, import_node_fs8.readFileSync)(catalogPath, "utf-8");
|
|
2123
2743
|
} catch {
|
|
2124
2744
|
return {
|
|
2125
2745
|
status: "needs_migration",
|
|
@@ -2160,7 +2780,7 @@ var WorkerDaemon = class {
|
|
|
2160
2780
|
const key = method.slice(CONFIG_PREFIX.length);
|
|
2161
2781
|
const prop = CONFIG_KEY_MAP[key];
|
|
2162
2782
|
if (prop === void 0) {
|
|
2163
|
-
throw new
|
|
2783
|
+
throw new IpcError2(-32601, `Method not found: ${method}`);
|
|
2164
2784
|
}
|
|
2165
2785
|
return this.config[prop];
|
|
2166
2786
|
}
|
|
@@ -2213,18 +2833,18 @@ async function startDaemon(contextPath, wasmDir2) {
|
|
|
2213
2833
|
}
|
|
2214
2834
|
function writeCrashLog(contextId, message) {
|
|
2215
2835
|
try {
|
|
2216
|
-
const crashPath = (0,
|
|
2836
|
+
const crashPath = (0, import_node_path10.join)((0, import_node_os3.tmpdir)(), `kbdb-${contextId}.crash`);
|
|
2217
2837
|
const payload = JSON.stringify({
|
|
2218
2838
|
error: message,
|
|
2219
2839
|
timestamp: Date.now()
|
|
2220
2840
|
});
|
|
2221
|
-
(0,
|
|
2841
|
+
(0, import_node_fs9.writeFileSync)(crashPath, payload);
|
|
2222
2842
|
} catch {
|
|
2223
2843
|
}
|
|
2224
2844
|
}
|
|
2225
2845
|
|
|
2226
2846
|
// src/shared/worker-daemon/functions/run-worker.function.ts
|
|
2227
|
-
var
|
|
2847
|
+
var import_node_path11 = require("node:path");
|
|
2228
2848
|
async function runWorker(argv, deps) {
|
|
2229
2849
|
const contextPath = argv[0];
|
|
2230
2850
|
if (!contextPath) {
|
|
@@ -2233,7 +2853,7 @@ async function runWorker(argv, deps) {
|
|
|
2233
2853
|
exitCode: 1
|
|
2234
2854
|
};
|
|
2235
2855
|
}
|
|
2236
|
-
const resolved = (0,
|
|
2856
|
+
const resolved = (0, import_node_path11.resolve)(contextPath);
|
|
2237
2857
|
if (!deps.existsSync(resolved)) {
|
|
2238
2858
|
return {
|
|
2239
2859
|
error: `error: path not found: ${resolved}`,
|
|
@@ -2250,7 +2870,7 @@ var baseDir = resolveBaseDir(import_meta.url, import_meta.dirname);
|
|
|
2250
2870
|
var wasmDir = resolveWasmDir(baseDir.scriptDir);
|
|
2251
2871
|
async function main() {
|
|
2252
2872
|
const result = await runWorker(getArgs(), {
|
|
2253
|
-
existsSync:
|
|
2873
|
+
existsSync: import_node_fs10.existsSync,
|
|
2254
2874
|
startDaemon,
|
|
2255
2875
|
wasmDir
|
|
2256
2876
|
});
|