@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,160 @@
|
|
|
1
|
+
import type { McpWorkerClient } from '../typings/mcp-client.interface.ts';
|
|
2
|
+
import type { AgentDefinition } from '../typings/agent-types.interface.ts';
|
|
3
|
+
|
|
4
|
+
/** Shape of a content item in an MCP tool call response. */
|
|
5
|
+
interface ToolContent {
|
|
6
|
+
/** Content type identifier, typically `'text'`. */
|
|
7
|
+
readonly type: string;
|
|
8
|
+
/** The text payload. */
|
|
9
|
+
readonly text: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Result returned by the agent-get tool handler. */
|
|
13
|
+
interface ToolCallResult {
|
|
14
|
+
/** One or more content items describing the result. */
|
|
15
|
+
readonly content: ToolContent[];
|
|
16
|
+
/** Set to `true` when the tool encountered an error. */
|
|
17
|
+
readonly isError?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Parsed shape of an agent document section list entry. */
|
|
21
|
+
interface DocumentSection {
|
|
22
|
+
/** Knowledge-base identifier of the section. */
|
|
23
|
+
readonly kbid: string;
|
|
24
|
+
/** Zero-based position of the section within the document. */
|
|
25
|
+
readonly position: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Parsed shape of a retrieved agent document. */
|
|
29
|
+
interface AgentDocument {
|
|
30
|
+
/** Document identifier. */
|
|
31
|
+
readonly docid: string;
|
|
32
|
+
/** Document title used as agent name fallback. */
|
|
33
|
+
readonly title: string;
|
|
34
|
+
/** Ordered list of sections in the document. */
|
|
35
|
+
readonly sections: DocumentSection[];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Reads the metadata JSON stored in the first section of an agent
|
|
40
|
+
* document and extracts `name`, `description`, and `persona`.
|
|
41
|
+
*/
|
|
42
|
+
async function readAgentMeta(
|
|
43
|
+
client: McpWorkerClient,
|
|
44
|
+
metaKbid: string,
|
|
45
|
+
fallbackName: string,
|
|
46
|
+
): Promise<{ name: string; description: string; persona: string }> {
|
|
47
|
+
const metaSections = await client.readSections([metaKbid]);
|
|
48
|
+
const first = metaSections.at(0);
|
|
49
|
+
if (!first) {
|
|
50
|
+
return { name: fallbackName, description: '', persona: '' };
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
const meta = JSON.parse(first.content) as Record<string, unknown>;
|
|
54
|
+
return {
|
|
55
|
+
name:
|
|
56
|
+
typeof meta['name'] === 'string'
|
|
57
|
+
? meta['name']
|
|
58
|
+
: fallbackName,
|
|
59
|
+
description:
|
|
60
|
+
typeof meta['description'] === 'string'
|
|
61
|
+
? meta['description']
|
|
62
|
+
: '',
|
|
63
|
+
persona:
|
|
64
|
+
typeof meta['persona'] === 'string' ? meta['persona'] : '',
|
|
65
|
+
};
|
|
66
|
+
} catch {
|
|
67
|
+
return { name: fallbackName, description: '', persona: '' };
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Resolves skill names for a list of section references by reading
|
|
73
|
+
* each section's JSON content and extracting the `name` field.
|
|
74
|
+
* Returns `null` for skill references where the section no longer
|
|
75
|
+
* exists (dangling references).
|
|
76
|
+
*/
|
|
77
|
+
async function resolveSkillRefs(
|
|
78
|
+
client: McpWorkerClient,
|
|
79
|
+
skillRefs: DocumentSection[],
|
|
80
|
+
): Promise<{ kbid: string; name: string | null; position: number }[]> {
|
|
81
|
+
if (skillRefs.length === 0) {
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
const skillKbids = skillRefs.map((s) => s.kbid);
|
|
85
|
+
const skillSections = await client.readSections(skillKbids);
|
|
86
|
+
const sectionMap = new Map(skillSections.map((s) => [s.kbid, s]));
|
|
87
|
+
return skillRefs.map((ref) => {
|
|
88
|
+
const sec = sectionMap.get(ref.kbid);
|
|
89
|
+
if (!sec) {
|
|
90
|
+
return { kbid: ref.kbid, name: null, position: ref.position };
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
const parsed = JSON.parse(sec.content) as Record<
|
|
94
|
+
string,
|
|
95
|
+
unknown
|
|
96
|
+
>;
|
|
97
|
+
const skillName =
|
|
98
|
+
typeof parsed['name'] === 'string' ? parsed['name'] : null;
|
|
99
|
+
return {
|
|
100
|
+
kbid: ref.kbid,
|
|
101
|
+
name: skillName,
|
|
102
|
+
position: ref.position,
|
|
103
|
+
};
|
|
104
|
+
} catch {
|
|
105
|
+
return { kbid: ref.kbid, name: null, position: ref.position };
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Handles the `agent:get` MCP tool call.
|
|
112
|
+
*
|
|
113
|
+
* Retrieves an agent document by its `docid`, reads the metadata
|
|
114
|
+
* section and skill references, and returns a full `AgentDefinition`.
|
|
115
|
+
* Dangling skill references (sections that no longer exist) appear
|
|
116
|
+
* with `name: null` in the skills list.
|
|
117
|
+
*
|
|
118
|
+
* @param client - the worker client used to execute operations
|
|
119
|
+
* @param args - tool arguments; must include a `docid` string
|
|
120
|
+
* @returns content items containing the serialised `AgentDefinition`
|
|
121
|
+
*/
|
|
122
|
+
export async function handleAgentGet(
|
|
123
|
+
client: McpWorkerClient,
|
|
124
|
+
args: Record<string, unknown>,
|
|
125
|
+
): Promise<ToolCallResult> {
|
|
126
|
+
const docid = typeof args['docid'] === 'string' ? args['docid'] : '';
|
|
127
|
+
if (!docid) {
|
|
128
|
+
return {
|
|
129
|
+
content: [{ type: 'text', text: 'docid is required' }],
|
|
130
|
+
isError: true,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const doc = (await client.retrieveDocument(docid)) as AgentDocument;
|
|
135
|
+
const metaKbid = doc.sections[0]?.kbid;
|
|
136
|
+
const skillRefs = doc.sections.slice(1);
|
|
137
|
+
|
|
138
|
+
const { name, description, persona } = metaKbid
|
|
139
|
+
? await readAgentMeta(client, metaKbid, doc.title)
|
|
140
|
+
: { name: doc.title, description: '', persona: '' };
|
|
141
|
+
|
|
142
|
+
const skills = await resolveSkillRefs(client, skillRefs);
|
|
143
|
+
|
|
144
|
+
const agent: AgentDefinition = {
|
|
145
|
+
docid,
|
|
146
|
+
name,
|
|
147
|
+
description,
|
|
148
|
+
persona,
|
|
149
|
+
skills,
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
return {
|
|
153
|
+
content: [
|
|
154
|
+
{
|
|
155
|
+
type: 'text',
|
|
156
|
+
text: JSON.stringify(agent, null, 2),
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
};
|
|
160
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { McpWorkerClient } from '../typings/mcp-client.interface.ts';
|
|
2
|
+
|
|
3
|
+
/** Shape of a content item in an MCP tool call response. */
|
|
4
|
+
interface ToolContent {
|
|
5
|
+
/** Content type identifier, typically `'text'`. */
|
|
6
|
+
readonly type: string;
|
|
7
|
+
/** The text payload. */
|
|
8
|
+
readonly text: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Result returned by the agent-list tool handler. */
|
|
12
|
+
interface ToolCallResult {
|
|
13
|
+
/** One or more content items describing the result. */
|
|
14
|
+
readonly content: ToolContent[];
|
|
15
|
+
/** Set to `true` when the tool encountered an error. */
|
|
16
|
+
readonly isError?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Handles the `agent:list` MCP tool call.
|
|
21
|
+
*
|
|
22
|
+
* Retrieves all documents with `doc_type: 'agent'` and returns a
|
|
23
|
+
* summary list containing each agent's document identifier, name,
|
|
24
|
+
* and skill count.
|
|
25
|
+
*
|
|
26
|
+
* The `skillCount` is `Math.max(0, sections.length - 1)` because
|
|
27
|
+
* the first section of an agent document always holds the metadata
|
|
28
|
+
* JSON and does not count as a skill reference.
|
|
29
|
+
*
|
|
30
|
+
* @param client - the worker client used to execute operations
|
|
31
|
+
* @returns content items with the serialised agent list
|
|
32
|
+
*/
|
|
33
|
+
export async function handleAgentList(
|
|
34
|
+
client: McpWorkerClient,
|
|
35
|
+
): Promise<ToolCallResult> {
|
|
36
|
+
const docs = await client.listDocumentsByType('agent');
|
|
37
|
+
const items = docs.map((d) => ({
|
|
38
|
+
docid: d.docid,
|
|
39
|
+
name: d.title,
|
|
40
|
+
skillCount: Math.max(0, d.sections.length - 1),
|
|
41
|
+
}));
|
|
42
|
+
return {
|
|
43
|
+
content: [
|
|
44
|
+
{
|
|
45
|
+
type: 'text',
|
|
46
|
+
text: JSON.stringify(items, null, 2),
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { McpWorkerClient } from '../typings/mcp-client.interface.ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Discriminated reference used in MCP completion requests.
|
|
5
|
+
* Identifies whether the completion target is a prompt or a resource.
|
|
6
|
+
*/
|
|
7
|
+
export interface McpCompletionRef {
|
|
8
|
+
/**
|
|
9
|
+
* The reference type: `'ref/prompt'` for named prompts (skills
|
|
10
|
+
* and agents) or `'ref/resource'` for resource URIs.
|
|
11
|
+
*/
|
|
12
|
+
readonly type: 'ref/prompt' | 'ref/resource';
|
|
13
|
+
/** Prompt name, present when `type` is `'ref/prompt'`. */
|
|
14
|
+
readonly name?: string;
|
|
15
|
+
/** Resource URI, present when `type` is `'ref/resource'`. */
|
|
16
|
+
readonly uri?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Completion argument supplied by the client, describing which
|
|
21
|
+
* argument is being completed and the current partial value.
|
|
22
|
+
*/
|
|
23
|
+
export interface McpCompletionArgument {
|
|
24
|
+
/** The argument name being completed. */
|
|
25
|
+
readonly name: string;
|
|
26
|
+
/** The partial value typed so far; used for prefix filtering. */
|
|
27
|
+
readonly value: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Result returned by `handleCompletion`, containing the list of
|
|
32
|
+
* matching completion values and pagination metadata.
|
|
33
|
+
*/
|
|
34
|
+
export interface McpCompletionResult {
|
|
35
|
+
/** Completion payload. */
|
|
36
|
+
readonly completion: {
|
|
37
|
+
/** Matching completion strings for the given prefix. */
|
|
38
|
+
readonly values: string[];
|
|
39
|
+
/**
|
|
40
|
+
* Whether more results are available beyond what is returned.
|
|
41
|
+
* Always `false` in this implementation.
|
|
42
|
+
*/
|
|
43
|
+
readonly hasMore: boolean;
|
|
44
|
+
/** Total number of values returned. */
|
|
45
|
+
readonly total: number;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Handles an MCP `completion/complete` request.
|
|
51
|
+
*
|
|
52
|
+
* For `ref/prompt` references, builds a list of all skill titles and
|
|
53
|
+
* agent titles (prefixed with `agent:`) and filters by the supplied
|
|
54
|
+
* argument value prefix. For `ref/resource` references, returns an
|
|
55
|
+
* empty result — resource completion is not implemented.
|
|
56
|
+
*
|
|
57
|
+
* @param ref - discriminated reference identifying the completion target
|
|
58
|
+
* @param argument - current argument name and partial value
|
|
59
|
+
* @param client - worker client used to fetch skills and agents
|
|
60
|
+
* @returns matching completion values with pagination metadata
|
|
61
|
+
*/
|
|
62
|
+
export async function handleCompletion(
|
|
63
|
+
ref: McpCompletionRef,
|
|
64
|
+
argument: McpCompletionArgument,
|
|
65
|
+
client: McpWorkerClient,
|
|
66
|
+
): Promise<McpCompletionResult> {
|
|
67
|
+
if (ref.type !== 'ref/prompt') {
|
|
68
|
+
return { completion: { values: [], hasMore: false, total: 0 } };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const [skills, agents] = await Promise.all([
|
|
72
|
+
client.listByType('skill'),
|
|
73
|
+
client.listDocumentsByType('agent'),
|
|
74
|
+
]);
|
|
75
|
+
|
|
76
|
+
const names: string[] = [];
|
|
77
|
+
|
|
78
|
+
for (const skill of skills) {
|
|
79
|
+
if (skill.title !== null) {
|
|
80
|
+
names.push(skill.title);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
for (const agent of agents) {
|
|
85
|
+
names.push(`agent:${agent.title}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const prefix = argument.value;
|
|
89
|
+
|
|
90
|
+
function matchesPrefix(candidate: string): boolean {
|
|
91
|
+
if (prefix.length === 0) {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
if (candidate.startsWith(prefix)) {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
// For agent-prefixed names, also match against the title portion.
|
|
98
|
+
const AGENT_PREFIX = 'agent:';
|
|
99
|
+
if (candidate.startsWith(AGENT_PREFIX)) {
|
|
100
|
+
return candidate.slice(AGENT_PREFIX.length).startsWith(prefix);
|
|
101
|
+
}
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const values = names.filter(matchesPrefix);
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
completion: {
|
|
109
|
+
values,
|
|
110
|
+
hasMore: false,
|
|
111
|
+
total: values.length,
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import type { McpWorkerClient } from '../typings/mcp-client.interface.ts';
|
|
2
|
+
import type { McpPromptMessage } from '../typings/prompt-types.interface.ts';
|
|
3
|
+
|
|
4
|
+
/** Parsed shape of an agent metadata section. */
|
|
5
|
+
interface AgentMeta {
|
|
6
|
+
/** Agent persona text. */
|
|
7
|
+
readonly persona: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Minimal section shape returned by readSections. */
|
|
11
|
+
interface ReadSection {
|
|
12
|
+
/** Knowledge-base identifier. */
|
|
13
|
+
readonly kbid: string;
|
|
14
|
+
/** Raw text content. */
|
|
15
|
+
readonly content: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Minimal agent document shape returned by retrieveDocument. */
|
|
19
|
+
interface AgentDocument {
|
|
20
|
+
/** Document identifier. */
|
|
21
|
+
readonly docid: string;
|
|
22
|
+
/** Document title. */
|
|
23
|
+
readonly title: string;
|
|
24
|
+
/** Ordered section references. */
|
|
25
|
+
readonly sections: readonly {
|
|
26
|
+
readonly kbid: string;
|
|
27
|
+
readonly position: number;
|
|
28
|
+
}[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Parses agent metadata from a raw JSON content string.
|
|
33
|
+
*
|
|
34
|
+
* Returns default values when parsing fails or required fields are
|
|
35
|
+
* absent.
|
|
36
|
+
*/
|
|
37
|
+
function parseAgentMeta(content: string): AgentMeta {
|
|
38
|
+
try {
|
|
39
|
+
const parsed = JSON.parse(content) as Record<string, unknown>;
|
|
40
|
+
return {
|
|
41
|
+
persona:
|
|
42
|
+
typeof parsed['persona'] === 'string'
|
|
43
|
+
? parsed['persona']
|
|
44
|
+
: '',
|
|
45
|
+
};
|
|
46
|
+
} catch {
|
|
47
|
+
return { persona: '' };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Builds the skills listing user message text from an array of
|
|
53
|
+
* skill section content strings. Sections whose JSON is not parseable
|
|
54
|
+
* or whose name cannot be determined are omitted silently.
|
|
55
|
+
*
|
|
56
|
+
* Returns `null` when no valid skills remain after filtering.
|
|
57
|
+
*/
|
|
58
|
+
function buildSkillsText(skillSections: ReadSection[]): string | null {
|
|
59
|
+
const lines: string[] = [];
|
|
60
|
+
for (const sec of skillSections) {
|
|
61
|
+
try {
|
|
62
|
+
const parsed = JSON.parse(sec.content) as Record<
|
|
63
|
+
string,
|
|
64
|
+
unknown
|
|
65
|
+
>;
|
|
66
|
+
const name =
|
|
67
|
+
typeof parsed['name'] === 'string' ? parsed['name'] : null;
|
|
68
|
+
if (name === null) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const description =
|
|
72
|
+
typeof parsed['description'] === 'string'
|
|
73
|
+
? parsed['description']
|
|
74
|
+
: '';
|
|
75
|
+
lines.push(`- ${name}: ${description}`);
|
|
76
|
+
} catch {
|
|
77
|
+
// skip unparseable sections
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (lines.length === 0) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
return `Available skills:\n${lines.join('\n')}`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Handles an MCP `prompts/get` request for an agent prompt.
|
|
88
|
+
*
|
|
89
|
+
* Reads the agent document, extracts its persona from the metadata
|
|
90
|
+
* section, then reads all skill sections and composes the response.
|
|
91
|
+
* Returns an assistant message with the persona and, when skills
|
|
92
|
+
* exist, a user message listing them.
|
|
93
|
+
*/
|
|
94
|
+
async function handleAgentPrompt(
|
|
95
|
+
name: string,
|
|
96
|
+
client: McpWorkerClient,
|
|
97
|
+
): Promise<McpPromptMessage[]> {
|
|
98
|
+
const docid = name.slice(6);
|
|
99
|
+
const doc = (await client.retrieveDocument(docid)) as AgentDocument;
|
|
100
|
+
const sections = doc.sections;
|
|
101
|
+
|
|
102
|
+
const metaSection = sections.at(0);
|
|
103
|
+
const skillRefs = sections.slice(1);
|
|
104
|
+
|
|
105
|
+
let persona = '';
|
|
106
|
+
if (metaSection !== undefined) {
|
|
107
|
+
const metaSections = await client.readSections([
|
|
108
|
+
metaSection.kbid,
|
|
109
|
+
]);
|
|
110
|
+
const metaContent = metaSections.at(0);
|
|
111
|
+
if (metaContent !== undefined) {
|
|
112
|
+
persona = parseAgentMeta(metaContent.content).persona;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const messages: McpPromptMessage[] = [
|
|
117
|
+
{
|
|
118
|
+
role: 'assistant',
|
|
119
|
+
content: { type: 'text', text: persona },
|
|
120
|
+
},
|
|
121
|
+
];
|
|
122
|
+
|
|
123
|
+
if (skillRefs.length === 0) {
|
|
124
|
+
return messages;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const skillKbids = skillRefs.map((s) => s.kbid);
|
|
128
|
+
const skillSections = await client.readSections(skillKbids);
|
|
129
|
+
const skillsText = buildSkillsText(skillSections);
|
|
130
|
+
|
|
131
|
+
if (skillsText !== null) {
|
|
132
|
+
messages.push({
|
|
133
|
+
role: 'user',
|
|
134
|
+
content: { type: 'text', text: skillsText },
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return messages;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Handles an MCP `prompts/get` request for a skill prompt.
|
|
143
|
+
*
|
|
144
|
+
* Looks up the skill by name in the `listByType('skill')` results,
|
|
145
|
+
* picks the most recent match (last occurrence), parses its body,
|
|
146
|
+
* and substitutes `{{argName}}` placeholders from `promptArgs`.
|
|
147
|
+
* Unresolved placeholders are left as-is.
|
|
148
|
+
*
|
|
149
|
+
* @throws {Error} when no skill with the given name is found
|
|
150
|
+
*/
|
|
151
|
+
async function handleSkillPrompt(
|
|
152
|
+
name: string,
|
|
153
|
+
promptArgs: Record<string, string>,
|
|
154
|
+
client: McpWorkerClient,
|
|
155
|
+
): Promise<McpPromptMessage[]> {
|
|
156
|
+
const sections = await client.listByType('skill');
|
|
157
|
+
let matchContent: string | undefined;
|
|
158
|
+
for (const sec of sections) {
|
|
159
|
+
if (sec.title === name) {
|
|
160
|
+
matchContent = sec.content;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (matchContent === undefined) {
|
|
164
|
+
throw new Error(`Prompt not found: ${name}`);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const parsed = JSON.parse(matchContent) as Record<string, unknown>;
|
|
168
|
+
const body =
|
|
169
|
+
typeof parsed['body'] === 'string' ? parsed['body'] : '';
|
|
170
|
+
|
|
171
|
+
const rendered = body.replace(
|
|
172
|
+
/\{\{(\w+)\}\}/g,
|
|
173
|
+
(_match, key: string) =>
|
|
174
|
+
key in promptArgs ? (promptArgs[key] ?? _match) : _match,
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
return [
|
|
178
|
+
{
|
|
179
|
+
role: 'user',
|
|
180
|
+
content: { type: 'text', text: rendered },
|
|
181
|
+
},
|
|
182
|
+
];
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Handles an MCP `prompts/get` request.
|
|
187
|
+
*
|
|
188
|
+
* Dispatches to the agent handler when `name` starts with `"agent:"`,
|
|
189
|
+
* otherwise treats the name as a skill prompt.
|
|
190
|
+
*
|
|
191
|
+
* For skill prompts: looks up by title using `listByType('skill')`,
|
|
192
|
+
* substitutes `{{argName}}` placeholders in the body, and returns a
|
|
193
|
+
* single user message.
|
|
194
|
+
*
|
|
195
|
+
* For agent prompts: reads the agent document via `retrieveDocument`,
|
|
196
|
+
* builds an assistant message from the persona section, and (when
|
|
197
|
+
* skills exist) a user message listing their names and descriptions.
|
|
198
|
+
*
|
|
199
|
+
* @param name - prompt name from the MCP request
|
|
200
|
+
* @param promptArgs - argument key-value map from the MCP request
|
|
201
|
+
* @param client - worker client used to access the knowledge base
|
|
202
|
+
* @returns ordered list of prompt messages to return to the caller
|
|
203
|
+
* @throws {Error} when a skill prompt name is not found in the store
|
|
204
|
+
*/
|
|
205
|
+
export async function handlePromptGet(
|
|
206
|
+
name: string,
|
|
207
|
+
promptArgs: Record<string, string>,
|
|
208
|
+
client: McpWorkerClient,
|
|
209
|
+
): Promise<McpPromptMessage[]> {
|
|
210
|
+
if (name.startsWith('agent:')) {
|
|
211
|
+
return handleAgentPrompt(name, client);
|
|
212
|
+
}
|
|
213
|
+
return handleSkillPrompt(name, promptArgs, client);
|
|
214
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { McpWorkerClient } from '../typings/mcp-client.interface.ts';
|
|
2
|
+
|
|
3
|
+
/** A single content item in an MCP resource read response. */
|
|
4
|
+
interface ResourceContent {
|
|
5
|
+
/** The resource URI that was read. */
|
|
6
|
+
readonly uri: string;
|
|
7
|
+
/** MIME type of the content body. */
|
|
8
|
+
readonly mimeType: string;
|
|
9
|
+
/** Text body of the resource. */
|
|
10
|
+
readonly text: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Result returned by a resource read operation. */
|
|
14
|
+
interface ResourceReadResult {
|
|
15
|
+
/** One or more content items for the requested URI. */
|
|
16
|
+
readonly contents: ResourceContent[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Handles an MCP `resources/read` request by dispatching to the
|
|
21
|
+
* appropriate knowledge-base operation based on the resource URI.
|
|
22
|
+
*
|
|
23
|
+
* @param client - the worker client used to fetch the resource
|
|
24
|
+
* @param uri - the resource URI from the MCP request
|
|
25
|
+
* @returns contents array for the MCP response
|
|
26
|
+
* @throws {Error} when the URI does not match any known pattern
|
|
27
|
+
*/
|
|
28
|
+
export async function handleResourceRead(
|
|
29
|
+
client: McpWorkerClient,
|
|
30
|
+
uri: string,
|
|
31
|
+
): Promise<ResourceReadResult> {
|
|
32
|
+
const sectionMatch = uri.match(/^kbdb:\/\/section\/(.+)$/);
|
|
33
|
+
if (sectionMatch) {
|
|
34
|
+
const sections = await client.readSections([sectionMatch[1]]);
|
|
35
|
+
const text = sections.length > 0 ? sections[0].content : '';
|
|
36
|
+
return {
|
|
37
|
+
contents: [{ uri, mimeType: 'text/plain', text }],
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const docMatch = uri.match(/^kbdb:\/\/document\/(.+)$/);
|
|
42
|
+
if (docMatch) {
|
|
43
|
+
const doc = await client.retrieveDocument(docMatch[1]);
|
|
44
|
+
return {
|
|
45
|
+
contents: [
|
|
46
|
+
{
|
|
47
|
+
uri,
|
|
48
|
+
mimeType: 'application/json',
|
|
49
|
+
text: JSON.stringify(doc, null, 2),
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
throw new Error(`Unknown resource URI: ${uri}`);
|
|
56
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a single file-system root entry advertised to MCP
|
|
3
|
+
* clients via the `roots/list` response.
|
|
4
|
+
*/
|
|
5
|
+
export interface McpRoot {
|
|
6
|
+
/** Absolute file URI for the root directory. */
|
|
7
|
+
readonly uri: string;
|
|
8
|
+
/** Human-readable label for the root. */
|
|
9
|
+
readonly name: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Returns the list of MCP roots for the given database context path.
|
|
14
|
+
*
|
|
15
|
+
* Produces a single root entry whose URI is `file://` concatenated
|
|
16
|
+
* with the supplied `contextPath`. This tells MCP clients which
|
|
17
|
+
* file-system directory the server is authoritative for.
|
|
18
|
+
*
|
|
19
|
+
* @param contextPath - absolute path to the kbdb database directory
|
|
20
|
+
* @returns array containing a single root for the context path
|
|
21
|
+
*/
|
|
22
|
+
export function handleRootsList(contextPath: string): McpRoot[] {
|
|
23
|
+
return [
|
|
24
|
+
{
|
|
25
|
+
uri: `file://${contextPath}`,
|
|
26
|
+
name: 'kbdb database',
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
}
|