@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,464 @@
|
|
|
1
|
+
import type { McpWorkerClient } from '../typings/mcp-client.interface.ts';
|
|
2
|
+
import { extractSkillArguments } from './extract-skill-arguments.function.ts';
|
|
3
|
+
import { parseSkillContent } from './parse-skill-content.function.ts';
|
|
4
|
+
import { serializeSkillContent } from './serialize-skill-content.function.ts';
|
|
5
|
+
import { handleAgentCreate } from './handle-agent-create.function.ts';
|
|
6
|
+
import { handleAgentList } from './handle-agent-list.function.ts';
|
|
7
|
+
import { handleAgentGet } from './handle-agent-get.function.ts';
|
|
8
|
+
import { handleAgentDelete } from './handle-agent-delete.function.ts';
|
|
9
|
+
|
|
10
|
+
/** Shape of a content item in an MCP tool call response. */
|
|
11
|
+
interface ToolContent {
|
|
12
|
+
/** Content type identifier, typically 'text'. */
|
|
13
|
+
readonly type: string;
|
|
14
|
+
/** The text payload. */
|
|
15
|
+
readonly text: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Result returned by a tool call handler. */
|
|
19
|
+
interface ToolCallResult {
|
|
20
|
+
/** One or more content items describing the result. */
|
|
21
|
+
readonly content: ToolContent[];
|
|
22
|
+
/** Set to `true` when the tool encountered an error. */
|
|
23
|
+
readonly isError?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Narrows an `unknown` value to a string, returning the fallback
|
|
28
|
+
* when the value is not already a string.
|
|
29
|
+
*/
|
|
30
|
+
function asString(value: unknown, fallback: string): string {
|
|
31
|
+
return typeof value === 'string' ? value : fallback;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Narrows an `unknown` value to a `string[]`, returning an empty
|
|
36
|
+
* array when the value is not an array of strings.
|
|
37
|
+
*/
|
|
38
|
+
function asStringArray(value: unknown): string[] {
|
|
39
|
+
if (
|
|
40
|
+
Array.isArray(value) &&
|
|
41
|
+
value.every((item) => typeof item === 'string')
|
|
42
|
+
) {
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Dispatches an MCP tool call to the appropriate knowledge-base
|
|
50
|
+
* operation and returns the result formatted as MCP content.
|
|
51
|
+
*
|
|
52
|
+
* @param client - the worker client used to execute operations
|
|
53
|
+
* @param name - the tool name to invoke
|
|
54
|
+
* @param args - tool arguments from the MCP request
|
|
55
|
+
* @returns content items with optional isError flag
|
|
56
|
+
*/
|
|
57
|
+
export async function handleToolCall(
|
|
58
|
+
client: McpWorkerClient,
|
|
59
|
+
name: string,
|
|
60
|
+
args: Record<string, unknown>,
|
|
61
|
+
): Promise<ToolCallResult> {
|
|
62
|
+
try {
|
|
63
|
+
switch (name) {
|
|
64
|
+
case 'search':
|
|
65
|
+
return await handleSearch(client, args);
|
|
66
|
+
case 'learn':
|
|
67
|
+
return await handleLearn(client, args);
|
|
68
|
+
case 'unlearn':
|
|
69
|
+
return await handleUnlearn(client, args);
|
|
70
|
+
case 'retrieve':
|
|
71
|
+
return await handleRetrieve(client, args);
|
|
72
|
+
case 'status':
|
|
73
|
+
return await handleStatus(client);
|
|
74
|
+
case 'content':
|
|
75
|
+
return await handleContent(client, args);
|
|
76
|
+
case 'check':
|
|
77
|
+
return await handleCheck(client);
|
|
78
|
+
case 'gc':
|
|
79
|
+
return await handleGc(client);
|
|
80
|
+
case 'rebuild':
|
|
81
|
+
return await handleRebuild(client);
|
|
82
|
+
case 'skill-learn':
|
|
83
|
+
return await handleSkillLearn(client, args);
|
|
84
|
+
case 'skill-list':
|
|
85
|
+
return await handleSkillList(client);
|
|
86
|
+
case 'skill-get':
|
|
87
|
+
return await handleSkillGet(client, args);
|
|
88
|
+
case 'skill-delete':
|
|
89
|
+
return await handleSkillDelete(client, args);
|
|
90
|
+
case 'agent-create':
|
|
91
|
+
return await handleAgentCreate(client, args);
|
|
92
|
+
case 'agent-list':
|
|
93
|
+
return await handleAgentList(client);
|
|
94
|
+
case 'agent-get':
|
|
95
|
+
return await handleAgentGet(client, args);
|
|
96
|
+
case 'agent-delete':
|
|
97
|
+
return await handleAgentDelete(client, args);
|
|
98
|
+
default:
|
|
99
|
+
return {
|
|
100
|
+
content: [
|
|
101
|
+
{
|
|
102
|
+
type: 'text',
|
|
103
|
+
text: `Unknown tool: ${name}`,
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
isError: true,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
} catch (err) {
|
|
110
|
+
return {
|
|
111
|
+
content: [
|
|
112
|
+
{
|
|
113
|
+
type: 'text',
|
|
114
|
+
text: err instanceof Error ? err.message : String(err),
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
isError: true,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function handleSearch(
|
|
123
|
+
client: McpWorkerClient,
|
|
124
|
+
args: Record<string, unknown>,
|
|
125
|
+
): Promise<ToolCallResult> {
|
|
126
|
+
const results = await client.search({
|
|
127
|
+
query: asString(args['query'], ''),
|
|
128
|
+
mode: args['mode'] as string | undefined,
|
|
129
|
+
limit: args['limit'] as number | undefined,
|
|
130
|
+
});
|
|
131
|
+
return {
|
|
132
|
+
content: [
|
|
133
|
+
{
|
|
134
|
+
type: 'text',
|
|
135
|
+
text: JSON.stringify(results, null, 2),
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async function handleLearn(
|
|
142
|
+
client: McpWorkerClient,
|
|
143
|
+
args: Record<string, unknown>,
|
|
144
|
+
): Promise<ToolCallResult> {
|
|
145
|
+
const sectionType = asString(args['type'], 'text/markdown');
|
|
146
|
+
const title =
|
|
147
|
+
typeof args['title'] === 'string' ? args['title'] : undefined;
|
|
148
|
+
const description =
|
|
149
|
+
typeof args['description'] === 'string'
|
|
150
|
+
? args['description']
|
|
151
|
+
: undefined;
|
|
152
|
+
const docid =
|
|
153
|
+
typeof args['docid'] === 'string' ? args['docid'] : undefined;
|
|
154
|
+
if (sectionType.startsWith('image/') && !title) {
|
|
155
|
+
return {
|
|
156
|
+
content: [
|
|
157
|
+
{
|
|
158
|
+
type: 'text',
|
|
159
|
+
text: 'title is required for image/* types',
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
isError: true,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
const result = await client.addSection({
|
|
166
|
+
sectionType,
|
|
167
|
+
content: asString(args['content'], ''),
|
|
168
|
+
title,
|
|
169
|
+
description,
|
|
170
|
+
docid,
|
|
171
|
+
});
|
|
172
|
+
return {
|
|
173
|
+
content: [
|
|
174
|
+
{
|
|
175
|
+
type: 'text',
|
|
176
|
+
text: JSON.stringify(result),
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
async function handleUnlearn(
|
|
183
|
+
client: McpWorkerClient,
|
|
184
|
+
args: Record<string, unknown>,
|
|
185
|
+
): Promise<ToolCallResult> {
|
|
186
|
+
const result = await client.removeSection(
|
|
187
|
+
asString(args['kbid'], ''),
|
|
188
|
+
);
|
|
189
|
+
return {
|
|
190
|
+
content: [
|
|
191
|
+
{
|
|
192
|
+
type: 'text',
|
|
193
|
+
text: JSON.stringify(result),
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async function handleRetrieve(
|
|
200
|
+
client: McpWorkerClient,
|
|
201
|
+
args: Record<string, unknown>,
|
|
202
|
+
): Promise<ToolCallResult> {
|
|
203
|
+
if (typeof args['kbid'] === 'string') {
|
|
204
|
+
const sections = await client.readSections([args['kbid']]);
|
|
205
|
+
return {
|
|
206
|
+
content: [
|
|
207
|
+
{
|
|
208
|
+
type: 'text',
|
|
209
|
+
text: JSON.stringify(sections, null, 2),
|
|
210
|
+
},
|
|
211
|
+
],
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
if (typeof args['docid'] === 'string') {
|
|
215
|
+
const doc = await client.retrieveDocument(args['docid']);
|
|
216
|
+
return {
|
|
217
|
+
content: [
|
|
218
|
+
{
|
|
219
|
+
type: 'text',
|
|
220
|
+
text: JSON.stringify(doc, null, 2),
|
|
221
|
+
},
|
|
222
|
+
],
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
return {
|
|
226
|
+
content: [
|
|
227
|
+
{
|
|
228
|
+
type: 'text',
|
|
229
|
+
text: 'Provide kbid or docid',
|
|
230
|
+
},
|
|
231
|
+
],
|
|
232
|
+
isError: true,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async function handleStatus(
|
|
237
|
+
client: McpWorkerClient,
|
|
238
|
+
): Promise<ToolCallResult> {
|
|
239
|
+
const status = await client.dbStatus();
|
|
240
|
+
return {
|
|
241
|
+
content: [
|
|
242
|
+
{
|
|
243
|
+
type: 'text',
|
|
244
|
+
text: JSON.stringify(status, null, 2),
|
|
245
|
+
},
|
|
246
|
+
],
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
async function handleContent(
|
|
251
|
+
client: McpWorkerClient,
|
|
252
|
+
args: Record<string, unknown>,
|
|
253
|
+
): Promise<ToolCallResult> {
|
|
254
|
+
const ids = asStringArray(args['ids']);
|
|
255
|
+
const result = await client.content(ids);
|
|
256
|
+
return {
|
|
257
|
+
content: [
|
|
258
|
+
{
|
|
259
|
+
type: 'text',
|
|
260
|
+
text: JSON.stringify(result),
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
async function handleCheck(
|
|
267
|
+
client: McpWorkerClient,
|
|
268
|
+
): Promise<ToolCallResult> {
|
|
269
|
+
const report = await client.integrityCheck();
|
|
270
|
+
return {
|
|
271
|
+
content: [
|
|
272
|
+
{
|
|
273
|
+
type: 'text',
|
|
274
|
+
text: JSON.stringify(report, null, 2),
|
|
275
|
+
},
|
|
276
|
+
],
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
async function handleGc(
|
|
281
|
+
client: McpWorkerClient,
|
|
282
|
+
): Promise<ToolCallResult> {
|
|
283
|
+
const report = await client.gc();
|
|
284
|
+
return {
|
|
285
|
+
content: [
|
|
286
|
+
{
|
|
287
|
+
type: 'text',
|
|
288
|
+
text: JSON.stringify(report, null, 2),
|
|
289
|
+
},
|
|
290
|
+
],
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
async function handleRebuild(
|
|
295
|
+
client: McpWorkerClient,
|
|
296
|
+
): Promise<ToolCallResult> {
|
|
297
|
+
const report = await client.rebuildIndexes();
|
|
298
|
+
return {
|
|
299
|
+
content: [
|
|
300
|
+
{
|
|
301
|
+
type: 'text',
|
|
302
|
+
text: JSON.stringify(report, null, 2),
|
|
303
|
+
},
|
|
304
|
+
],
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
async function handleSkillLearn(
|
|
309
|
+
client: McpWorkerClient,
|
|
310
|
+
args: Record<string, unknown>,
|
|
311
|
+
): Promise<ToolCallResult> {
|
|
312
|
+
const name = asString(args['name'], '');
|
|
313
|
+
if (!name) {
|
|
314
|
+
return {
|
|
315
|
+
content: [{ type: 'text', text: 'name is required' }],
|
|
316
|
+
isError: true,
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
const body = asString(args['body'], '');
|
|
320
|
+
if (!body) {
|
|
321
|
+
return {
|
|
322
|
+
content: [{ type: 'text', text: 'body is required' }],
|
|
323
|
+
isError: true,
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
const description =
|
|
327
|
+
typeof args['description'] === 'string'
|
|
328
|
+
? args['description']
|
|
329
|
+
: undefined;
|
|
330
|
+
const skillArgs = extractSkillArguments(body);
|
|
331
|
+
const skill = {
|
|
332
|
+
name,
|
|
333
|
+
description,
|
|
334
|
+
arguments: skillArgs.length > 0 ? skillArgs : undefined,
|
|
335
|
+
body,
|
|
336
|
+
};
|
|
337
|
+
const json = serializeSkillContent(skill);
|
|
338
|
+
const result = await client.addSection({
|
|
339
|
+
sectionType: 'skill',
|
|
340
|
+
content: json,
|
|
341
|
+
title: name,
|
|
342
|
+
description,
|
|
343
|
+
});
|
|
344
|
+
return {
|
|
345
|
+
content: [
|
|
346
|
+
{
|
|
347
|
+
type: 'text',
|
|
348
|
+
text: JSON.stringify({ kbid: result.kbid, name }),
|
|
349
|
+
},
|
|
350
|
+
],
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
async function handleSkillList(
|
|
355
|
+
client: McpWorkerClient,
|
|
356
|
+
): Promise<ToolCallResult> {
|
|
357
|
+
const records = await client.listByType('skill');
|
|
358
|
+
const items = records.map((r) => {
|
|
359
|
+
let argumentCount = 0;
|
|
360
|
+
try {
|
|
361
|
+
const parsed = JSON.parse(r.content) as Record<
|
|
362
|
+
string,
|
|
363
|
+
unknown
|
|
364
|
+
>;
|
|
365
|
+
if (Array.isArray(parsed['arguments'])) {
|
|
366
|
+
argumentCount = parsed['arguments'].length;
|
|
367
|
+
}
|
|
368
|
+
} catch {
|
|
369
|
+
// ignore parse errors
|
|
370
|
+
}
|
|
371
|
+
return {
|
|
372
|
+
kbid: r.kbid,
|
|
373
|
+
name: r.title,
|
|
374
|
+
description: r.description,
|
|
375
|
+
argumentCount,
|
|
376
|
+
};
|
|
377
|
+
});
|
|
378
|
+
return {
|
|
379
|
+
content: [
|
|
380
|
+
{
|
|
381
|
+
type: 'text',
|
|
382
|
+
text: JSON.stringify(items, null, 2),
|
|
383
|
+
},
|
|
384
|
+
],
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
async function handleSkillGet(
|
|
389
|
+
client: McpWorkerClient,
|
|
390
|
+
args: Record<string, unknown>,
|
|
391
|
+
): Promise<ToolCallResult> {
|
|
392
|
+
const kbid =
|
|
393
|
+
typeof args['kbid'] === 'string' ? args['kbid'] : undefined;
|
|
394
|
+
const name =
|
|
395
|
+
typeof args['name'] === 'string' ? args['name'] : undefined;
|
|
396
|
+
if (!kbid && !name) {
|
|
397
|
+
return {
|
|
398
|
+
content: [
|
|
399
|
+
{
|
|
400
|
+
type: 'text',
|
|
401
|
+
text: 'name or kbid is required',
|
|
402
|
+
},
|
|
403
|
+
],
|
|
404
|
+
isError: true,
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
let content: string | undefined;
|
|
408
|
+
if (kbid) {
|
|
409
|
+
const sections = await client.readSections([kbid]);
|
|
410
|
+
if (sections.length > 0) {
|
|
411
|
+
content = sections[0]?.content;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
if (content === undefined && name) {
|
|
415
|
+
const records = await client.listByType('skill');
|
|
416
|
+
const match = records.filter((r) => r.title === name).pop();
|
|
417
|
+
if (match) {
|
|
418
|
+
content = match.content;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
if (content === undefined) {
|
|
422
|
+
const identifier = kbid ?? name ?? '';
|
|
423
|
+
return {
|
|
424
|
+
content: [
|
|
425
|
+
{
|
|
426
|
+
type: 'text',
|
|
427
|
+
text: `skill not found: ${identifier}`,
|
|
428
|
+
},
|
|
429
|
+
],
|
|
430
|
+
isError: true,
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
const skill = parseSkillContent(content);
|
|
434
|
+
return {
|
|
435
|
+
content: [
|
|
436
|
+
{
|
|
437
|
+
type: 'text',
|
|
438
|
+
text: JSON.stringify(skill, null, 2),
|
|
439
|
+
},
|
|
440
|
+
],
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
async function handleSkillDelete(
|
|
445
|
+
client: McpWorkerClient,
|
|
446
|
+
args: Record<string, unknown>,
|
|
447
|
+
): Promise<ToolCallResult> {
|
|
448
|
+
const kbid = asString(args['kbid'], '');
|
|
449
|
+
if (!kbid) {
|
|
450
|
+
return {
|
|
451
|
+
content: [{ type: 'text', text: 'kbid is required' }],
|
|
452
|
+
isError: true,
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
const result = await client.removeSection(kbid);
|
|
456
|
+
return {
|
|
457
|
+
content: [
|
|
458
|
+
{
|
|
459
|
+
type: 'text',
|
|
460
|
+
text: JSON.stringify({ kbid, removed: result.removed }),
|
|
461
|
+
},
|
|
462
|
+
],
|
|
463
|
+
};
|
|
464
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SkillArgument,
|
|
3
|
+
SkillDefinition,
|
|
4
|
+
} from '../typings/skill-types.interface.ts';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Parses a JSON string into a `SkillDefinition`.
|
|
8
|
+
*
|
|
9
|
+
* Validates that the required `name` and `body` fields are present
|
|
10
|
+
* and are non-empty strings, then returns the full definition
|
|
11
|
+
* including optional `description` and `arguments`.
|
|
12
|
+
*
|
|
13
|
+
* @param json - JSON string representing a serialized skill
|
|
14
|
+
* @returns the parsed skill definition
|
|
15
|
+
* @throws {SyntaxError} when `json` is not valid JSON
|
|
16
|
+
* @throws {Error} when `name` is missing or empty
|
|
17
|
+
* @throws {Error} when `body` is missing or not a string
|
|
18
|
+
*/
|
|
19
|
+
export function parseSkillContent(json: string): SkillDefinition {
|
|
20
|
+
const raw = JSON.parse(json) as Record<string, unknown>;
|
|
21
|
+
if (typeof raw['name'] !== 'string' || !raw['name']) {
|
|
22
|
+
throw new Error('skill name is required');
|
|
23
|
+
}
|
|
24
|
+
if (typeof raw['body'] !== 'string') {
|
|
25
|
+
throw new Error('skill body is required');
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
name: raw['name'],
|
|
29
|
+
description:
|
|
30
|
+
typeof raw['description'] === 'string'
|
|
31
|
+
? raw['description']
|
|
32
|
+
: undefined,
|
|
33
|
+
arguments: Array.isArray(raw['arguments'])
|
|
34
|
+
? (raw['arguments'] as SkillArgument[])
|
|
35
|
+
: undefined,
|
|
36
|
+
body: raw['body'],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SkillDefinition } from '../typings/skill-types.interface.ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Serializes a `SkillDefinition` to a JSON string suitable for
|
|
5
|
+
* storage as a knowledge-base section's `content` field.
|
|
6
|
+
*
|
|
7
|
+
* @param skill - skill definition to serialize
|
|
8
|
+
* @returns JSON string representation of the skill
|
|
9
|
+
*/
|
|
10
|
+
export function serializeSkillContent(skill: SkillDefinition): string {
|
|
11
|
+
return JSON.stringify(skill);
|
|
12
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { McpLogLevel } from '../typings/log-types.interface.ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Ordered list of MCP log severity levels, from least severe
|
|
5
|
+
* (`debug`) to most severe (`emergency`). Used to compare levels
|
|
6
|
+
* when filtering log output.
|
|
7
|
+
*/
|
|
8
|
+
export const LOG_LEVEL_ORDER: McpLogLevel[] = [
|
|
9
|
+
'debug',
|
|
10
|
+
'info',
|
|
11
|
+
'notice',
|
|
12
|
+
'warning',
|
|
13
|
+
'error',
|
|
14
|
+
'critical',
|
|
15
|
+
'alert',
|
|
16
|
+
'emergency',
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Determines whether a log message at `messageLevel` should be
|
|
21
|
+
* emitted when the server's log threshold is `threshold`.
|
|
22
|
+
*
|
|
23
|
+
* Returns `true` when `messageLevel` is at the same severity as
|
|
24
|
+
* `threshold` or higher. Returns `false` when the message level is
|
|
25
|
+
* below the threshold.
|
|
26
|
+
*
|
|
27
|
+
* @param messageLevel - severity of the log message to evaluate
|
|
28
|
+
* @param threshold - minimum severity level required to emit
|
|
29
|
+
* @returns `true` if the message meets or exceeds the threshold
|
|
30
|
+
*/
|
|
31
|
+
export function shouldEmitLog(
|
|
32
|
+
messageLevel: McpLogLevel,
|
|
33
|
+
threshold: McpLogLevel,
|
|
34
|
+
): boolean {
|
|
35
|
+
const messageIndex = LOG_LEVEL_ORDER.indexOf(messageLevel);
|
|
36
|
+
const thresholdIndex = LOG_LEVEL_ORDER.indexOf(threshold);
|
|
37
|
+
return messageIndex >= thresholdIndex;
|
|
38
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export { McpServer } from './classes/mcp-server.class.ts';
|
|
2
|
+
export { createMcpServer } from './functions/create-mcp-server.function.ts';
|
|
3
|
+
export { createToolDefinitions } from './functions/create-tool-definitions.function.ts';
|
|
4
|
+
export { createResourceTemplates } from './functions/create-resource-templates.function.ts';
|
|
5
|
+
export { handleToolCall } from './functions/handle-tool-call.function.ts';
|
|
6
|
+
export { handleResourceRead } from './functions/handle-resource-read.function.ts';
|
|
7
|
+
export {
|
|
8
|
+
PARSE_ERROR,
|
|
9
|
+
METHOD_NOT_FOUND,
|
|
10
|
+
INVALID_PARAMS,
|
|
11
|
+
INTERNAL_ERROR,
|
|
12
|
+
RESOURCE_NOT_FOUND,
|
|
13
|
+
} from './constants/mcp-error-codes.constant.ts';
|
|
14
|
+
export type {
|
|
15
|
+
McpRequest,
|
|
16
|
+
McpResponse,
|
|
17
|
+
McpNotification,
|
|
18
|
+
McpToolDefinition,
|
|
19
|
+
McpResourceTemplate,
|
|
20
|
+
McpServerInfo,
|
|
21
|
+
McpCapabilities,
|
|
22
|
+
McpToolResult,
|
|
23
|
+
McpResourceResult,
|
|
24
|
+
} from './typings/mcp-types.interface.ts';
|
|
25
|
+
export type {
|
|
26
|
+
McpWorkerClient,
|
|
27
|
+
RemoveSectionResult,
|
|
28
|
+
} from './typings/mcp-client.interface.ts';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A reference from an agent document to a skill section,
|
|
3
|
+
* carrying the skill's position within the agent's ordered
|
|
4
|
+
* skill list.
|
|
5
|
+
*/
|
|
6
|
+
export interface AgentSkillRef {
|
|
7
|
+
/** Knowledge-base identifier of the referenced skill section. */
|
|
8
|
+
readonly kbid: string;
|
|
9
|
+
/**
|
|
10
|
+
* Human-readable name of the skill, or `null` when the
|
|
11
|
+
* referenced section no longer exists (dangling reference).
|
|
12
|
+
*/
|
|
13
|
+
readonly name: string | null;
|
|
14
|
+
/** Zero-based position of this skill within the agent's list. */
|
|
15
|
+
readonly position: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Full definition of an agent, including its persona text and
|
|
20
|
+
* ordered list of skill references.
|
|
21
|
+
*/
|
|
22
|
+
export interface AgentDefinition {
|
|
23
|
+
/** Unique document identifier for the agent. */
|
|
24
|
+
readonly docid: string;
|
|
25
|
+
/** Human-readable name of the agent. */
|
|
26
|
+
readonly name: string;
|
|
27
|
+
/**
|
|
28
|
+
* Short description of what the agent does, used for discovery
|
|
29
|
+
* and disambiguation.
|
|
30
|
+
*/
|
|
31
|
+
readonly description: string;
|
|
32
|
+
/**
|
|
33
|
+
* Persona text that governs how the agent behaves when
|
|
34
|
+
* executing tasks.
|
|
35
|
+
*/
|
|
36
|
+
readonly persona: string;
|
|
37
|
+
/** Ordered list of skill references the agent can delegate to. */
|
|
38
|
+
readonly skills: readonly AgentSkillRef[];
|
|
39
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Severity levels for MCP log messages, ordered from least severe
|
|
3
|
+
* (`debug`) to most severe (`emergency`).
|
|
4
|
+
*/
|
|
5
|
+
export type McpLogLevel =
|
|
6
|
+
| 'debug'
|
|
7
|
+
| 'info'
|
|
8
|
+
| 'notice'
|
|
9
|
+
| 'warning'
|
|
10
|
+
| 'error'
|
|
11
|
+
| 'critical'
|
|
12
|
+
| 'alert'
|
|
13
|
+
| 'emergency';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A structured log message emitted by the MCP server via the
|
|
17
|
+
* `notifications/message` notification method.
|
|
18
|
+
*/
|
|
19
|
+
export interface McpLogMessage {
|
|
20
|
+
/** Severity level of the log entry. */
|
|
21
|
+
readonly level: McpLogLevel;
|
|
22
|
+
/** Optional logger name identifying the source component. */
|
|
23
|
+
readonly logger?: string;
|
|
24
|
+
/** Optional structured payload associated with the log entry. */
|
|
25
|
+
readonly data?: unknown;
|
|
26
|
+
}
|