@qvac/inference 0.21.1 → 0.23.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/NOTICE +89 -41
- package/README.md +44 -1
- package/dist/api/assess-model-fit.d.ts +4 -4
- package/dist/api/assess-model-fit.js +4 -4
- package/dist/api/audio-gen.d.ts +4 -1
- package/dist/api/audio-gen.js +5 -2
- package/dist/api/batch-completion.js +1 -1
- package/dist/api/completion-stream.d.ts +2 -1
- package/dist/api/completion-stream.js +4 -2
- package/dist/api/decide.d.ts +26 -0
- package/dist/api/decide.js +26 -0
- package/dist/api/diffusion.d.ts +18 -1
- package/dist/api/diffusion.js +18 -1
- package/dist/api/download-asset.js +1 -1
- package/dist/api/finetune.js +1 -1
- package/dist/api/get-model-info.d.ts +1 -1
- package/dist/api/index.d.ts +39 -37
- package/dist/api/index.js +38 -36
- package/dist/api/load-model.js +2 -2
- package/dist/api/logging-stream-registry.js +11 -7
- package/dist/api/logging-stream.d.ts +11 -1
- package/dist/api/logging-stream.js +11 -2
- package/dist/api/registry.d.ts +2 -1
- package/dist/api/registry.js +5 -4
- package/dist/api/rerank.d.ts +17 -0
- package/dist/api/rerank.js +36 -0
- package/dist/api/subscribe-logs.js +5 -3
- package/dist/api/text-to-speech.d.ts +1 -0
- package/dist/api/text-to-speech.js +15 -19
- package/dist/api/transcribe.js +5 -2
- package/dist/api/unload-model.js +1 -1
- package/dist/api/video-request.d.ts +5 -5
- package/dist/api/video.d.ts +5 -4
- package/dist/api/video.js +6 -5
- package/dist/api/vla.js +1 -1
- package/dist/api/world-result.js +1 -1
- package/dist/api/world.d.ts +1 -1
- package/dist/api/world.js +1 -1
- package/dist/config/resolve-config.d.ts +1 -1
- package/dist/config/resolve-config.js +1 -1
- package/dist/constants/index.d.ts +2 -2
- package/dist/constants/index.js +2 -2
- package/dist/dispatch.d.ts +3 -2
- package/dist/dispatch.js +16 -4
- package/dist/errors/index.d.ts +9 -0
- package/dist/errors/index.js +18 -1
- package/dist/handlers/assess-model-fit.d.ts +5 -3
- package/dist/handlers/assess-model-fit.js +84 -32
- package/dist/handlers/cancelHandler.js +1 -1
- package/dist/handlers/completion-orchestrate.js +2 -2
- package/dist/handlers/download-asset.js +2 -2
- package/dist/handlers/finetune.js +1 -1
- package/dist/handlers/get-loaded-model-info.js +3 -5
- package/dist/handlers/get-model-info.js +1 -1
- package/dist/handlers/load-model/coreml-sidecars.d.ts +15 -0
- package/dist/handlers/load-model/coreml-sidecars.js +71 -8
- package/dist/handlers/load-model/download-manager.d.ts +1 -1
- package/dist/handlers/load-model/download-stats.d.ts +2 -2
- package/dist/handlers/load-model/download-stats.js +3 -3
- package/dist/handlers/load-model/handler.js +10 -7
- package/dist/handlers/load-model/http-verify.d.ts +1 -1
- package/dist/handlers/load-model/http.d.ts +1 -1
- package/dist/handlers/load-model/http.js +3 -3
- package/dist/handlers/load-model/hyperdrive.d.ts +1 -1
- package/dist/handlers/load-model/hyperdrive.js +2 -2
- package/dist/handlers/load-model/index.d.ts +2 -2
- package/dist/handlers/load-model/index.js +2 -2
- package/dist/handlers/load-model/registry-companion-set.d.ts +1 -1
- package/dist/handlers/load-model/registry-companion-set.js +1 -1
- package/dist/handlers/load-model/registry-download-utils.d.ts +3 -3
- package/dist/handlers/load-model/registry-download-utils.js +2 -2
- package/dist/handlers/load-model/registry.d.ts +2 -2
- package/dist/handlers/load-model/registry.js +5 -5
- package/dist/handlers/load-model/resolve-session.d.ts +1 -1
- package/dist/handlers/load-model/resolve-session.js +11 -3
- package/dist/handlers/load-model/resolve.d.ts +1 -1
- package/dist/handlers/load-model/resolve.js +5 -5
- package/dist/handlers/load-model/safe-fetch.js +5 -6
- package/dist/handlers/logging-stream.d.ts +2 -1
- package/dist/handlers/logging-stream.js +23 -7
- package/dist/handlers/registry.d.ts +3 -1
- package/dist/handlers/registry.js +7 -5
- package/dist/handlers/types.d.ts +7 -1
- package/dist/handlers/vector-index.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/logging/addon.d.ts +1 -1
- package/dist/logging/addon.js +1 -1
- package/dist/logging/index.d.ts +5 -5
- package/dist/logging/index.js +4 -4
- package/dist/logging/logger.d.ts +1 -1
- package/dist/logging/logger.js +2 -2
- package/dist/{resources/model-fit → model-fit}/assess.d.ts +18 -26
- package/dist/{resources/model-fit → model-fit}/assess.js +210 -274
- package/dist/{resources/model-fit/native-probe/classify-fit.d.ts → model-fit/classify.d.ts} +2 -2
- package/dist/{resources/model-fit/native-probe/classify-fit.js → model-fit/classify.js} +36 -5
- package/dist/{resources/model-fit/fit-stub/fetch-fit-stub.d.ts → model-fit/description/fetch.d.ts} +4 -2
- package/dist/{resources/model-fit/fit-stub/fetch-fit-stub.js → model-fit/description/fetch.js} +11 -6
- package/dist/{resources/model-fit/fit-stub/project-fit-from-load.d.ts → model-fit/description/project.d.ts} +3 -3
- package/dist/{resources/model-fit/fit-stub/project-fit-from-load.js → model-fit/description/project.js} +4 -2
- package/dist/{resources/model-fit/fit-stub/resolve-load-from-stubs.d.ts → model-fit/description/resolve-load.d.ts} +6 -4
- package/dist/{resources/model-fit/fit-stub/resolve-load-from-stubs.js → model-fit/description/resolve-load.js} +14 -6
- package/dist/model-fit/floor.d.ts +31 -0
- package/dist/{resources/model-fit → model-fit}/floor.js +13 -13
- package/dist/model-fit/kv-cache.d.ts +23 -0
- package/dist/model-fit/kv-cache.js +85 -0
- package/dist/{resources/model-fit/native-probe/advisory-fit.d.ts → model-fit/load-check.d.ts} +17 -14
- package/dist/{resources/model-fit/native-probe/advisory-fit.js → model-fit/load-check.js} +23 -64
- package/dist/model-fit/platform.d.ts +14 -0
- package/dist/model-fit/platform.js +26 -0
- package/dist/{resources/model-fit/native-probe/create-fit-request.d.ts → model-fit/request/create.d.ts} +5 -2
- package/dist/model-fit/request/create.js +61 -0
- package/dist/{resources/model-fit/native-probe → model-fit/request}/engines/asr.d.ts +5 -1
- package/dist/{resources/model-fit/native-probe → model-fit/request}/engines/asr.js +32 -1
- package/dist/{resources/model-fit/native-probe → model-fit/request}/engines/audiogen.d.ts +1 -1
- package/dist/model-fit/request/engines/audiogen.js +63 -0
- package/dist/{resources/model-fit/native-probe → model-fit/request}/engines/diffusion.d.ts +1 -1
- package/dist/model-fit/request/engines/diffusion.js +93 -0
- package/dist/{resources/model-fit/native-probe → model-fit/request}/engines/llama.d.ts +2 -3
- package/dist/model-fit/request/engines/llama.js +44 -0
- package/dist/model-fit/request/engines/nmt.d.ts +8 -0
- package/dist/model-fit/request/engines/nmt.js +11 -0
- package/dist/model-fit/request/engines/ocr.d.ts +9 -0
- package/dist/model-fit/request/engines/ocr.js +13 -0
- package/dist/{resources/model-fit/native-probe → model-fit/request}/engines/tts.d.ts +3 -1
- package/dist/{resources/model-fit/native-probe → model-fit/request}/engines/tts.js +50 -4
- package/dist/{resources/model-fit/native-probe/engine-fit.d.ts → model-fit/run/engine.d.ts} +17 -4
- package/dist/{resources/model-fit/native-probe/engine-fit.js → model-fit/run/engine.js} +2 -2
- package/dist/model-fit/run/run.d.ts +43 -0
- package/dist/model-fit/run/run.js +204 -0
- package/dist/models/registry/index.d.ts +1 -1
- package/dist/models/registry/index.js +2 -2
- package/dist/models/registry/models.d.ts +1072 -815
- package/dist/models/registry/models.js +3704 -3405
- package/dist/models/registry/resource-profiles.d.ts +1 -2
- package/dist/models/registry/resource-profiles.js +406 -3
- package/dist/plugins/builtin/asr-ggml/config.d.ts +7 -1
- package/dist/plugins/builtin/asr-ggml/config.js +6 -0
- package/dist/plugins/builtin/asr-ggml/logging.d.ts +1 -1
- package/dist/plugins/builtin/audiogen-ggml/config.d.ts +1 -0
- package/dist/plugins/builtin/audiogen-ggml/ops/audio-edit-stream.js +29 -11
- package/dist/plugins/builtin/audiogen-ggml/ops/audio-gen-input.d.ts +27 -0
- package/dist/plugins/builtin/audiogen-ggml/ops/audio-gen-input.js +23 -0
- package/dist/plugins/builtin/audiogen-ggml/ops/audio-gen-stream.js +7 -28
- package/dist/plugins/builtin/audiogen-ggml/ops/audio-understand.js +2 -2
- package/dist/plugins/builtin/audiogen-ggml/plugin.d.ts +106 -13
- package/dist/plugins/builtin/audiogen-ggml/plugin.js +5 -4
- package/dist/plugins/builtin/bci-whispercpp-transcription/plugin.d.ts +20 -3
- package/dist/plugins/builtin/bci-whispercpp-transcription/plugin.js +3 -3
- package/dist/plugins/builtin/ggml-classification/plugin.js +1 -1
- package/dist/plugins/builtin/ggml-ocr/params.d.ts +18 -0
- package/dist/plugins/builtin/ggml-ocr/params.js +37 -0
- package/dist/plugins/builtin/ggml-ocr/plugin.d.ts +9 -0
- package/dist/plugins/builtin/ggml-ocr/plugin.js +17 -39
- package/dist/plugins/builtin/ggml-vla/plugin.d.ts +9 -2
- package/dist/plugins/builtin/ggml-vla/plugin.js +4 -4
- package/dist/plugins/builtin/index.d.ts +15 -12
- package/dist/plugins/builtin/index.js +15 -12
- package/dist/plugins/builtin/llamacpp-completion/ops/batch-completion-stream.js +5 -7
- package/dist/plugins/builtin/llamacpp-completion/ops/completion-stats.d.ts +2 -0
- package/dist/plugins/builtin/llamacpp-completion/ops/completion-stats.js +6 -0
- package/dist/plugins/builtin/llamacpp-completion/ops/completion-stream.d.ts +10 -7
- package/dist/plugins/builtin/llamacpp-completion/ops/completion-stream.js +141 -204
- package/dist/plugins/builtin/llamacpp-completion/ops/kv-cache-session.d.ts +36 -92
- package/dist/plugins/builtin/llamacpp-completion/ops/kv-cache-session.js +67 -216
- package/dist/plugins/builtin/llamacpp-completion/ops/kv-cache-state.d.ts +2 -49
- package/dist/plugins/builtin/llamacpp-completion/ops/kv-cache-state.js +2 -46
- package/dist/plugins/builtin/llamacpp-completion/plugin.d.ts +208 -19
- package/dist/plugins/builtin/llamacpp-completion/plugin.js +28 -20
- package/dist/plugins/builtin/llamacpp-completion/transform.js +5 -1
- package/dist/plugins/builtin/llamacpp-decision/helpers.d.ts +5 -0
- package/dist/plugins/builtin/llamacpp-decision/helpers.js +89 -0
- package/dist/plugins/builtin/llamacpp-decision/ops/decide.d.ts +91 -0
- package/dist/plugins/builtin/llamacpp-decision/ops/decide.js +129 -0
- package/dist/plugins/builtin/llamacpp-decision/plugin.d.ts +222 -0
- package/dist/plugins/builtin/llamacpp-decision/plugin.js +44 -0
- package/dist/plugins/builtin/llamacpp-embedding/plugin.d.ts +9 -1
- package/dist/plugins/builtin/llamacpp-embedding/plugin.js +15 -5
- package/dist/plugins/builtin/llamacpp-embedding/transform.js +9 -0
- package/dist/plugins/builtin/llamacpp-rerank/helpers.d.ts +3 -0
- package/dist/plugins/builtin/llamacpp-rerank/helpers.js +16 -0
- package/dist/plugins/builtin/llamacpp-rerank/ops/rerank.d.ts +5 -0
- package/dist/plugins/builtin/llamacpp-rerank/ops/rerank.js +117 -0
- package/dist/plugins/builtin/llamacpp-rerank/plugin.d.ts +91 -0
- package/dist/plugins/builtin/llamacpp-rerank/plugin.js +45 -0
- package/dist/plugins/builtin/moss-transcribe/plugin.d.ts +143 -0
- package/dist/plugins/builtin/moss-transcribe/plugin.js +96 -0
- package/dist/plugins/builtin/nmtcpp-translation/load-files.d.ts +6 -0
- package/dist/plugins/builtin/nmtcpp-translation/load-files.js +70 -0
- package/dist/plugins/builtin/nmtcpp-translation/plugin.d.ts +17 -0
- package/dist/plugins/builtin/nmtcpp-translation/plugin.js +10 -74
- package/dist/plugins/builtin/parakeet-transcription/plugin.d.ts +25 -4
- package/dist/plugins/builtin/parakeet-transcription/plugin.js +20 -5
- package/dist/plugins/builtin/sdcpp-generation/ops/diffusion.d.ts +5 -2
- package/dist/plugins/builtin/sdcpp-generation/ops/diffusion.js +168 -52
- package/dist/plugins/builtin/sdcpp-generation/ops/video.d.ts +5 -2
- package/dist/plugins/builtin/sdcpp-generation/ops/video.js +28 -13
- package/dist/plugins/builtin/sdcpp-generation/plugin.d.ts +83 -1
- package/dist/plugins/builtin/sdcpp-generation/plugin.js +55 -52
- package/dist/plugins/builtin/sdcpp-generation/upscaler-config.d.ts +15 -0
- package/dist/plugins/builtin/sdcpp-generation/upscaler-config.js +19 -0
- package/dist/plugins/builtin/sdcpp-generation/world-config.d.ts +8 -0
- package/dist/plugins/builtin/sdcpp-generation/world-config.js +9 -0
- package/dist/plugins/builtin/tts-ggml/ops/moss-options.d.ts +22 -0
- package/dist/plugins/builtin/tts-ggml/ops/moss-options.js +79 -0
- package/dist/plugins/builtin/tts-ggml/ops/text-to-speech-stream.d.ts +1 -1
- package/dist/plugins/builtin/tts-ggml/ops/text-to-speech-stream.js +5 -2
- package/dist/plugins/builtin/tts-ggml/ops/text-to-speech.js +19 -7
- package/dist/plugins/builtin/tts-ggml/plugin.d.ts +151 -1
- package/dist/plugins/builtin/tts-ggml/plugin.js +39 -2
- package/dist/plugins/builtin/whispercpp-transcription/plugin.d.ts +28 -4
- package/dist/plugins/builtin/whispercpp-transcription/plugin.js +8 -4
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.js +2 -2
- package/dist/plugins/ops/kv-cache-utils.d.ts +5 -4
- package/dist/plugins/ops/kv-cache-utils.js +25 -33
- package/dist/plugins/ops/load-model.d.ts +8 -2
- package/dist/plugins/ops/load-model.js +33 -19
- package/dist/plugins/ops/transcribe.js +18 -2
- package/dist/plugins/ops/translate.js +3 -3
- package/dist/plugins/ops/unload-model.js +1 -1
- package/dist/plugins/turbovec-backend.js +5 -5
- package/dist/profiling/aggregator.d.ts +1 -1
- package/dist/profiling/aggregator.js +1 -1
- package/dist/profiling/controller.d.ts +1 -1
- package/dist/profiling/controller.js +2 -2
- package/dist/profiling/events.d.ts +1 -1
- package/dist/profiling/events.js +2 -2
- package/dist/profiling/exporters.d.ts +1 -1
- package/dist/profiling/exporters.js +3 -3
- package/dist/profiling/index.d.ts +13 -13
- package/dist/profiling/index.js +12 -12
- package/dist/profiling/operation-metrics.d.ts +1 -1
- package/dist/profiling/operation-metrics.js +2 -2
- package/dist/profiling/operation-wrappers.js +3 -3
- package/dist/profiling/profiler.js +1 -1
- package/dist/rag/handler.js +1 -1
- package/dist/rag/handlers/close-workspace.js +1 -1
- package/dist/rag/handlers/delete-embeddings.js +1 -1
- package/dist/rag/handlers/delete-workspace.js +1 -1
- package/dist/rag/handlers/ingest.js +1 -1
- package/dist/rag/handlers/list-workspaces.d.ts +1 -1
- package/dist/rag/handlers/list-workspaces.js +1 -1
- package/dist/rag/handlers/reindex.js +1 -1
- package/dist/rag/handlers/save-embeddings.js +1 -1
- package/dist/rag/handlers/search.js +1 -1
- package/dist/rag/index.d.ts +11 -11
- package/dist/rag/index.js +11 -11
- package/dist/rag/rag-workspace-manager.js +1 -1
- package/dist/registry.js +3 -1
- package/dist/resources/collector.d.ts +1 -1
- package/dist/resources/collector.js +1 -1
- package/dist/resources/instance.d.ts +1 -1
- package/dist/resources/instance.js +1 -1
- package/dist/resources/native.d.ts +1 -1
- package/dist/resources/normalize.d.ts +1 -1
- package/dist/rpc/inventory.js +5 -7
- package/dist/runtime/env.d.ts +0 -2
- package/dist/runtime/env.js +2 -9
- package/dist/runtime/index.d.ts +5 -5
- package/dist/runtime/index.js +2 -2
- package/dist/runtime/lifecycle.js +7 -7
- package/dist/runtime/model-config-utils.js +9 -1
- package/dist/runtime/model-registry.d.ts +3 -1
- package/dist/runtime/model-registry.js +2 -1
- package/dist/runtime/registry-client.js +1 -1
- package/dist/runtime/request-context.d.ts +3 -3
- package/dist/runtime/request-context.js +22 -1
- package/dist/runtime/request-registry.d.ts +1 -1
- package/dist/runtime/request-registry.js +1 -1
- package/dist/runtime/state.d.ts +1 -1
- package/dist/runtime/state.js +7 -2
- package/dist/runtime/vector-index-backend.d.ts +2 -2
- package/dist/runtime/vector-index-registry.d.ts +5 -5
- package/dist/runtime/vector-index-registry.js +36 -13
- package/dist/schemas/assess-model-fit.d.ts +106 -43
- package/dist/schemas/assess-model-fit.js +69 -32
- package/dist/schemas/audio-gen.d.ts +199 -19
- package/dist/schemas/audio-gen.js +183 -51
- package/dist/schemas/batch-completion-stream.d.ts +210 -36
- package/dist/schemas/batch-completion-stream.js +3 -3
- package/dist/schemas/bci-config.d.ts +3 -0
- package/dist/schemas/bci-config.js +2 -2
- package/dist/schemas/bci.d.ts +24 -3
- package/dist/schemas/bci.js +2 -2
- package/dist/schemas/cancel.d.ts +10 -0
- package/dist/schemas/cancel.js +2 -0
- package/dist/schemas/common.d.ts +1465 -162
- package/dist/schemas/common.js +37 -31
- package/dist/schemas/completion-event.d.ts +8 -2
- package/dist/schemas/completion-event.js +4 -1
- package/dist/schemas/completion-stream.d.ts +243 -39
- package/dist/schemas/completion-stream.js +100 -29
- package/dist/schemas/config.d.ts +1326 -18
- package/dist/schemas/config.js +30 -8
- package/dist/schemas/decision.d.ts +610 -0
- package/dist/schemas/decision.js +219 -0
- package/dist/schemas/download-asset.d.ts +10 -4
- package/dist/schemas/download-asset.js +1 -1
- package/dist/schemas/engine-addon-map.d.ts +9 -1
- package/dist/schemas/engine-addon-map.js +26 -5
- package/dist/schemas/errors.d.ts +2 -0
- package/dist/schemas/errors.js +11 -1
- package/dist/schemas/index.d.ts +51 -48
- package/dist/schemas/index.js +50 -47
- package/dist/schemas/llamacpp-config.d.ts +222 -6
- package/dist/schemas/llamacpp-config.js +129 -7
- package/dist/schemas/load-model.d.ts +7960 -1492
- package/dist/schemas/load-model.js +122 -10
- package/dist/schemas/mcp-adapter.d.ts +1 -1
- package/dist/schemas/model-config-schemas.d.ts +428 -9
- package/dist/schemas/model-config-schemas.js +16 -11
- package/dist/schemas/model-fit-policy.d.ts +17 -0
- package/dist/schemas/model-fit-policy.js +17 -0
- package/dist/schemas/model-info.d.ts +20 -2
- package/dist/schemas/model-info.js +4 -3
- package/dist/schemas/model-resource-profile.d.ts +4 -4
- package/dist/schemas/model-resource-profile.js +2 -5
- package/dist/schemas/model-src-utils.d.ts +14 -2
- package/dist/schemas/model-src-utils.js +2 -2
- package/dist/schemas/model-types.d.ts +14 -1
- package/dist/schemas/model-types.js +4 -0
- package/dist/schemas/ocr.d.ts +76 -0
- package/dist/schemas/ocr.js +43 -1
- package/dist/schemas/plugin.d.ts +16 -4
- package/dist/schemas/plugin.js +12 -0
- package/dist/schemas/profiling.d.ts +4 -4
- package/dist/schemas/profiling.js +1 -1
- package/dist/schemas/rag.js +1 -1
- package/dist/schemas/registry.d.ts +34 -0
- package/dist/schemas/registry.js +5 -1
- package/dist/schemas/reload-config.d.ts +14 -2
- package/dist/schemas/reload-config.js +2 -2
- package/dist/schemas/rerank.d.ts +131 -0
- package/dist/schemas/rerank.js +102 -0
- package/dist/schemas/rpc-server.js +3 -3
- package/dist/schemas/sdcpp-config.d.ts +82 -0
- package/dist/schemas/sdcpp-config.js +41 -22
- package/dist/schemas/system-resources.d.ts +4 -4
- package/dist/schemas/text-to-speech.d.ts +463 -3
- package/dist/schemas/text-to-speech.js +129 -11
- package/dist/schemas/tools.d.ts +13 -4
- package/dist/schemas/tools.js +18 -6
- package/dist/schemas/transcription-config.d.ts +20 -0
- package/dist/schemas/transcription-config.js +54 -4
- package/dist/schemas/transcription.d.ts +47 -5
- package/dist/schemas/transcription.js +52 -5
- package/dist/schemas/translate.d.ts +2 -2
- package/dist/schemas/translate.js +1 -1
- package/dist/schemas/translation-config.d.ts +40 -10
- package/dist/schemas/translation-config.js +1 -1
- package/dist/schemas/vla.d.ts +9 -2
- package/dist/schemas/vla.js +9 -5
- package/dist/surface.d.ts +3 -2
- package/dist/surface.js +3 -2
- package/dist/utils/addon-responses.d.ts +3 -0
- package/dist/utils/aggregate-events.d.ts +1 -1
- package/dist/utils/aggregate-events.js +2 -2
- package/dist/utils/archive.js +2 -2
- package/dist/utils/asr-events.d.ts +1 -0
- package/dist/utils/asr-events.js +2 -1
- package/dist/utils/audio/decoder.js +3 -1
- package/dist/utils/audio-input.js +1 -1
- package/dist/utils/cache/auto-history.d.ts +2 -1
- package/dist/utils/cache/auto-history.js +2 -2
- package/dist/utils/cache/paths.js +6 -6
- package/dist/utils/cache/types.d.ts +7 -0
- package/dist/utils/checksum.d.ts +2 -0
- package/dist/utils/checksum.js +41 -2
- package/dist/utils/completion-normalizer.js +1 -1
- package/dist/utils/gguf-architecture.d.ts +7 -0
- package/dist/utils/gguf-architecture.js +142 -0
- package/dist/utils/gguf-tensor-extractor.js +1 -1
- package/dist/utils/index.d.ts +13 -13
- package/dist/utils/index.js +13 -13
- package/dist/utils/mcp-adapter.d.ts +1 -1
- package/dist/utils/mcp-adapter.js +13 -9
- package/dist/utils/path-security.js +1 -1
- package/dist/utils/shard-utils.d.ts +5 -0
- package/dist/utils/shard-utils.js +19 -3
- package/dist/utils/tool-helpers.d.ts +1 -1
- package/dist/utils/tool-helpers.js +20 -52
- package/dist/utils/tool-integration.d.ts +1 -0
- package/dist/utils/tool-integration.js +3 -6
- package/dist/utils/tools/defer.d.ts +16 -26
- package/dist/utils/tools/defer.js +50 -41
- package/dist/utils/tools/dialect.d.ts +15 -4
- package/dist/utils/tools/dialect.js +34 -5
- package/dist/utils/tools/index.d.ts +3 -3
- package/dist/utils/tools/index.js +3 -3
- package/dist/utils/tools/parser.js +8 -8
- package/dist/utils/tools/parsers/dsml.d.ts +1 -1
- package/dist/utils/tools/parsers/dsml.js +8 -5
- package/dist/utils/tools/parsers/gemma4native.d.ts +1 -1
- package/dist/utils/tools/parsers/gemma4native.js +1 -1
- package/dist/utils/tools/parsers/harmony.d.ts +1 -1
- package/dist/utils/tools/parsers/harmony.js +1 -1
- package/dist/utils/tools/parsers/hermes.d.ts +1 -1
- package/dist/utils/tools/parsers/hermes.js +1 -1
- package/dist/utils/tools/parsers/json.d.ts +1 -1
- package/dist/utils/tools/parsers/json.js +1 -1
- package/dist/utils/tools/parsers/pythonic.d.ts +1 -1
- package/dist/utils/tools/parsers/pythonic.js +1 -1
- package/dist/utils/tools/parsers/qwen35.d.ts +1 -1
- package/dist/utils/tools/parsers/qwen35.js +7 -4
- package/dist/utils/tools/shared.d.ts +3 -0
- package/dist/utils/tools/shared.js +62 -0
- package/dist/utils/transcribe-metadata.d.ts +8 -1
- package/dist/utils/transcribe-metadata.js +13 -3
- package/dist/utils/tts-stats.d.ts +2 -1
- package/dist/utils/until-aborted.d.ts +7 -0
- package/dist/utils/until-aborted.js +34 -0
- package/package.json +68 -51
- package/dist/resources/model-fit/calibration/darwin-arm64.d.ts +0 -8
- package/dist/resources/model-fit/calibration/darwin-arm64.js +0 -36
- package/dist/resources/model-fit/calibration/darwin-x64.d.ts +0 -8
- package/dist/resources/model-fit/calibration/darwin-x64.js +0 -38
- package/dist/resources/model-fit/calibration/fit.d.ts +0 -73
- package/dist/resources/model-fit/calibration/fit.js +0 -152
- package/dist/resources/model-fit/calibration/index.d.ts +0 -37
- package/dist/resources/model-fit/calibration/index.js +0 -75
- package/dist/resources/model-fit/calibration/linux-arm64.d.ts +0 -8
- package/dist/resources/model-fit/calibration/linux-arm64.js +0 -38
- package/dist/resources/model-fit/calibration/linux-x64-vulkan.d.ts +0 -8
- package/dist/resources/model-fit/calibration/linux-x64-vulkan.js +0 -39
- package/dist/resources/model-fit/calibration/linux-x64.d.ts +0 -8
- package/dist/resources/model-fit/calibration/linux-x64.js +0 -38
- package/dist/resources/model-fit/calibration/win32-x64-vulkan-shared.d.ts +0 -8
- package/dist/resources/model-fit/calibration/win32-x64-vulkan-shared.js +0 -39
- package/dist/resources/model-fit/calibration/win32-x64-vulkan.d.ts +0 -8
- package/dist/resources/model-fit/calibration/win32-x64-vulkan.js +0 -36
- package/dist/resources/model-fit/calibration/win32-x64.d.ts +0 -8
- package/dist/resources/model-fit/calibration/win32-x64.js +0 -38
- package/dist/resources/model-fit/estimators/llm.d.ts +0 -46
- package/dist/resources/model-fit/estimators/llm.js +0 -222
- package/dist/resources/model-fit/estimators/whisper.d.ts +0 -10
- package/dist/resources/model-fit/estimators/whisper.js +0 -76
- package/dist/resources/model-fit/floor.d.ts +0 -31
- package/dist/resources/model-fit/native-probe/child-engine-fit.d.ts +0 -2
- package/dist/resources/model-fit/native-probe/child-engine-fit.js +0 -41
- package/dist/resources/model-fit/native-probe/create-fit-request.js +0 -51
- package/dist/resources/model-fit/native-probe/engines/audiogen.js +0 -35
- package/dist/resources/model-fit/native-probe/engines/diffusion.js +0 -55
- package/dist/resources/model-fit/native-probe/engines/llama.js +0 -145
- package/dist/resources/model-fit/native-probe/fit-outcome.d.ts +0 -16
- package/dist/resources/model-fit/native-probe/fit-outcome.js +0 -1
- package/dist/resources/model-fit/native-probe/fit-process.d.ts +0 -27
- package/dist/resources/model-fit/native-probe/fit-process.js +0 -55
- package/dist/resources/model-fit/native-probe/fit-runner.d.ts +0 -1
- package/dist/resources/model-fit/native-probe/fit-runner.js +0 -58
- package/dist/resources/model-fit/native-probe/run-fit.d.ts +0 -24
- package/dist/resources/model-fit/native-probe/run-fit.js +0 -20
- package/dist/resources/model-fit/native-probe/run-in-process-fit.d.ts +0 -22
- package/dist/resources/model-fit/native-probe/run-in-process-fit.js +0 -108
- package/dist/resources/model-fit/native-probe/run-isolated-fit.d.ts +0 -63
- package/dist/resources/model-fit/native-probe/run-isolated-fit.js +0 -377
- package/dist/resources/model-fit/platform.d.ts +0 -9
- package/dist/resources/model-fit/platform.js +0 -28
- package/dist/resources/model-fit/types.d.ts +0 -120
- package/dist/resources/model-fit/types.js +0 -1
- /package/dist/{resources/model-fit/native-probe/engines → model-fit/request}/gpu.d.ts +0 -0
- /package/dist/{resources/model-fit/native-probe/engines → model-fit/request}/gpu.js +0 -0
|
@@ -4,4 +4,11 @@ export interface CacheMessage {
|
|
|
4
4
|
attachments?: {
|
|
5
5
|
path: string;
|
|
6
6
|
}[] | undefined;
|
|
7
|
+
toolCalls?: {
|
|
8
|
+
id?: string | undefined;
|
|
9
|
+
name: string;
|
|
10
|
+
arguments: Record<string, unknown>;
|
|
11
|
+
}[] | undefined;
|
|
12
|
+
toolCallId?: string | undefined;
|
|
13
|
+
toolName?: string | undefined;
|
|
7
14
|
}
|
package/dist/utils/checksum.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { DownloadHooks } from '../handlers/load-model/types.js';
|
|
2
2
|
export declare function calculateFileChecksum(filePath: string): Promise<string>;
|
|
3
|
+
/** Reuse a digest only while the file's identity and change metadata match. */
|
|
4
|
+
export declare function calculateCachedFileChecksum(filePath: string): Promise<string>;
|
|
3
5
|
export declare function measureChecksum(filePath: string, hooks?: DownloadHooks): Promise<string>;
|
package/dist/utils/checksum.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'bare-fs';
|
|
2
2
|
import crypto from 'bare-crypto';
|
|
3
|
-
import
|
|
3
|
+
import path from 'bare-path';
|
|
4
|
+
import { nowMs } from '../profiling/clock.js';
|
|
4
5
|
export async function calculateFileChecksum(filePath) {
|
|
5
6
|
return new Promise((resolve, reject) => {
|
|
6
7
|
try {
|
|
@@ -21,9 +22,47 @@ export async function calculateFileChecksum(filePath) {
|
|
|
21
22
|
}
|
|
22
23
|
});
|
|
23
24
|
}
|
|
25
|
+
// Process-local only: a new engine process must establish its own verification.
|
|
26
|
+
// Bound retention so applications visiting many model paths do not grow forever.
|
|
27
|
+
const checksumCache = new Map();
|
|
28
|
+
const MAX_CACHED_CHECKSUMS = 256;
|
|
29
|
+
async function fileFingerprint(filePath) {
|
|
30
|
+
const stats = await fs.promises.stat(filePath);
|
|
31
|
+
const fields = [stats.dev, stats.ino, stats.size, stats.mtimeMs, stats.ctimeMs];
|
|
32
|
+
// Runtimes/filesystems without usable identity metadata always hash the file.
|
|
33
|
+
if (!stats.isFile() || !stats.ino || !fields.every(Number.isFinite))
|
|
34
|
+
return undefined;
|
|
35
|
+
return fields.join(':');
|
|
36
|
+
}
|
|
37
|
+
/** Reuse a digest only while the file's identity and change metadata match. */
|
|
38
|
+
export async function calculateCachedFileChecksum(filePath) {
|
|
39
|
+
const key = path.resolve(filePath);
|
|
40
|
+
try {
|
|
41
|
+
const before = await fileFingerprint(key);
|
|
42
|
+
const cached = checksumCache.get(key);
|
|
43
|
+
if (before !== undefined && cached?.fingerprint === before)
|
|
44
|
+
return cached.checksum;
|
|
45
|
+
checksumCache.delete(key);
|
|
46
|
+
const checksum = await calculateFileChecksum(key);
|
|
47
|
+
const after = await fileFingerprint(key);
|
|
48
|
+
if (before !== after)
|
|
49
|
+
throw new Error(`File changed during checksum calculation: ${key}`);
|
|
50
|
+
if (after !== undefined) {
|
|
51
|
+
if (checksumCache.size >= MAX_CACHED_CHECKSUMS) {
|
|
52
|
+
checksumCache.delete(checksumCache.keys().next().value);
|
|
53
|
+
}
|
|
54
|
+
checksumCache.set(key, { fingerprint: after, checksum });
|
|
55
|
+
}
|
|
56
|
+
return checksum;
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
checksumCache.delete(key);
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
24
63
|
export async function measureChecksum(filePath, hooks) {
|
|
25
64
|
const start = nowMs();
|
|
26
|
-
const checksum = await
|
|
65
|
+
const checksum = await calculateCachedFileChecksum(filePath);
|
|
27
66
|
hooks?.addChecksumValidationTimeMs?.(nowMs() - start);
|
|
28
67
|
return checksum;
|
|
29
68
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const ARCHITECTURE_SCAN_BYTES: number;
|
|
2
|
+
/**
|
|
3
|
+
* The `general.architecture` value from a GGUF header, read from at most the
|
|
4
|
+
* first `ARCHITECTURE_SCAN_BYTES` of the file. Undefined when the file is
|
|
5
|
+
* unreadable, is not GGUF, or does not name an architecture in that range.
|
|
6
|
+
*/
|
|
7
|
+
export declare function readGgufArchitecture(filePath: string): Promise<string | undefined>;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import fs from 'bare-fs';
|
|
2
|
+
import Buffer from 'bare-buffer';
|
|
3
|
+
const GGUF_MAGIC = 0x46554747;
|
|
4
|
+
const STRING_TYPE = 8;
|
|
5
|
+
const ARRAY_TYPE = 9;
|
|
6
|
+
const FIXED_SIZES = {
|
|
7
|
+
0: 1,
|
|
8
|
+
1: 1,
|
|
9
|
+
2: 2,
|
|
10
|
+
3: 2,
|
|
11
|
+
4: 4,
|
|
12
|
+
5: 4,
|
|
13
|
+
6: 4,
|
|
14
|
+
7: 1,
|
|
15
|
+
10: 8,
|
|
16
|
+
11: 8,
|
|
17
|
+
12: 8
|
|
18
|
+
};
|
|
19
|
+
// GGUF writers put `general.architecture` first, ahead of the tokenizer arrays
|
|
20
|
+
// that make a header large, so a key past this point is not worth the read.
|
|
21
|
+
export const ARCHITECTURE_SCAN_BYTES = 1024 * 1024;
|
|
22
|
+
/**
|
|
23
|
+
* Walks the header in the first `end` bytes of `buffer` to
|
|
24
|
+
* `general.architecture`. Undefined when the header is not GGUF, holds a value
|
|
25
|
+
* type it cannot skip, or does not reach the key within those bytes.
|
|
26
|
+
*/
|
|
27
|
+
function scanForArchitecture(buffer, end) {
|
|
28
|
+
let offset = 0;
|
|
29
|
+
let bigEndian = false;
|
|
30
|
+
const fits = (bytes) => offset + bytes <= end;
|
|
31
|
+
function u32() {
|
|
32
|
+
if (!fits(4))
|
|
33
|
+
return undefined;
|
|
34
|
+
const value = bigEndian ? buffer.readUInt32BE(offset) : buffer.readUInt32LE(offset);
|
|
35
|
+
offset += 4;
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
function u64() {
|
|
39
|
+
if (!fits(8))
|
|
40
|
+
return undefined;
|
|
41
|
+
const value = bigEndian ? buffer.readBigUInt64BE(offset) : buffer.readBigUInt64LE(offset);
|
|
42
|
+
offset += 8;
|
|
43
|
+
return Number(value);
|
|
44
|
+
}
|
|
45
|
+
function skip(bytes) {
|
|
46
|
+
if (!fits(bytes))
|
|
47
|
+
return false;
|
|
48
|
+
offset += bytes;
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
function string() {
|
|
52
|
+
const length = u64();
|
|
53
|
+
if (length === undefined || !fits(length))
|
|
54
|
+
return undefined;
|
|
55
|
+
const value = buffer.toString('utf8', offset, offset + length);
|
|
56
|
+
offset += length;
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
function skipString() {
|
|
60
|
+
const length = u64();
|
|
61
|
+
return length !== undefined && skip(length);
|
|
62
|
+
}
|
|
63
|
+
function skipValue(type) {
|
|
64
|
+
const size = FIXED_SIZES[type];
|
|
65
|
+
if (size !== undefined)
|
|
66
|
+
return skip(size);
|
|
67
|
+
if (type === STRING_TYPE)
|
|
68
|
+
return skipString();
|
|
69
|
+
if (type !== ARRAY_TYPE)
|
|
70
|
+
return false;
|
|
71
|
+
const elementType = u32();
|
|
72
|
+
const count = u64();
|
|
73
|
+
if (elementType === undefined || count === undefined)
|
|
74
|
+
return false;
|
|
75
|
+
const elementSize = FIXED_SIZES[elementType];
|
|
76
|
+
if (elementSize !== undefined)
|
|
77
|
+
return skip(count * elementSize);
|
|
78
|
+
if (elementType !== STRING_TYPE)
|
|
79
|
+
return false;
|
|
80
|
+
for (let i = 0; i < count; i++) {
|
|
81
|
+
if (!skipString())
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
if (u32() !== GGUF_MAGIC)
|
|
87
|
+
return undefined;
|
|
88
|
+
// The magic is the same bytes in both byte orders. A big-endian header is
|
|
89
|
+
// told apart by its version, whose low 16 bits read 0 as little-endian.
|
|
90
|
+
let version = u32();
|
|
91
|
+
if (version === undefined)
|
|
92
|
+
return undefined;
|
|
93
|
+
if ((version & 0xffff) === 0) {
|
|
94
|
+
bigEndian = true;
|
|
95
|
+
version = buffer.readUInt32BE(4);
|
|
96
|
+
}
|
|
97
|
+
if (version !== 2 && version !== 3)
|
|
98
|
+
return undefined;
|
|
99
|
+
if (!skip(8))
|
|
100
|
+
return undefined;
|
|
101
|
+
const kvCount = u64();
|
|
102
|
+
if (kvCount === undefined)
|
|
103
|
+
return undefined;
|
|
104
|
+
for (let i = 0; i < kvCount; i++) {
|
|
105
|
+
const key = string();
|
|
106
|
+
const type = u32();
|
|
107
|
+
if (key === undefined || type === undefined)
|
|
108
|
+
return undefined;
|
|
109
|
+
if (key === 'general.architecture' && type === STRING_TYPE)
|
|
110
|
+
return string();
|
|
111
|
+
if (!skipValue(type))
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The `general.architecture` value from a GGUF header, read from at most the
|
|
118
|
+
* first `ARCHITECTURE_SCAN_BYTES` of the file. Undefined when the file is
|
|
119
|
+
* unreadable, is not GGUF, or does not name an architecture in that range.
|
|
120
|
+
*/
|
|
121
|
+
export async function readGgufArchitecture(filePath) {
|
|
122
|
+
let fd;
|
|
123
|
+
try {
|
|
124
|
+
fd = await fs.open(filePath, 'r');
|
|
125
|
+
const buffer = Buffer.alloc(ARCHITECTURE_SCAN_BYTES);
|
|
126
|
+
let length = 0;
|
|
127
|
+
while (length < buffer.length) {
|
|
128
|
+
const read = await fs.read(fd, buffer, length, buffer.length - length, length);
|
|
129
|
+
if (read === 0)
|
|
130
|
+
break;
|
|
131
|
+
length += read;
|
|
132
|
+
}
|
|
133
|
+
return scanForArchitecture(buffer, length);
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
finally {
|
|
139
|
+
if (fd !== undefined)
|
|
140
|
+
await fs.close(fd).catch(() => { });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -2,7 +2,7 @@ import { promises as fsPromises, createReadStream } from 'bare-fs';
|
|
|
2
2
|
import Buffer from 'bare-buffer';
|
|
3
3
|
import { getEngineLogger } from '../logging/index.js';
|
|
4
4
|
import { ModelLoadFailedError } from '../errors/index.js';
|
|
5
|
-
import { validateAndJoinPath } from '
|
|
5
|
+
import { validateAndJoinPath } from '../utils/path-security.js';
|
|
6
6
|
const logger = getEngineLogger();
|
|
7
7
|
// GGUF value types
|
|
8
8
|
const GGUF_TYPE = {
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export * from '
|
|
2
|
-
export * from '
|
|
3
|
-
export * from '
|
|
4
|
-
export * from '
|
|
5
|
-
export * from '
|
|
6
|
-
export * from '
|
|
7
|
-
export * from '
|
|
8
|
-
export * from '
|
|
9
|
-
export * from '
|
|
10
|
-
export * from '
|
|
11
|
-
export * from '
|
|
12
|
-
export * from '
|
|
13
|
-
export * from '
|
|
1
|
+
export * from '../utils/archive.js';
|
|
2
|
+
export * from '../utils/cache/types.js';
|
|
3
|
+
export * from '../utils/cache/auto-history.js';
|
|
4
|
+
export * from '../utils/cache/paths.js';
|
|
5
|
+
export * from '../utils/checksum.js';
|
|
6
|
+
export * from '../utils/config-transform.js';
|
|
7
|
+
export * from '../utils/formatting.js';
|
|
8
|
+
export * from '../utils/gguf-tensor-extractor.js';
|
|
9
|
+
export * from '../utils/image-dimensions.js';
|
|
10
|
+
export * from '../utils/path-sanitize.js';
|
|
11
|
+
export * from '../utils/path-security.js';
|
|
12
|
+
export * from '../utils/shard-utils.js';
|
|
13
|
+
export * from '../utils/url-security.js';
|
package/dist/utils/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export * from '
|
|
2
|
-
export * from '
|
|
3
|
-
export * from '
|
|
4
|
-
export * from '
|
|
5
|
-
export * from '
|
|
6
|
-
export * from '
|
|
7
|
-
export * from '
|
|
8
|
-
export * from '
|
|
9
|
-
export * from '
|
|
10
|
-
export * from '
|
|
11
|
-
export * from '
|
|
12
|
-
export * from '
|
|
13
|
-
export * from '
|
|
1
|
+
export * from '../utils/archive.js';
|
|
2
|
+
export * from '../utils/cache/types.js';
|
|
3
|
+
export * from '../utils/cache/auto-history.js';
|
|
4
|
+
export * from '../utils/cache/paths.js';
|
|
5
|
+
export * from '../utils/checksum.js';
|
|
6
|
+
export * from '../utils/config-transform.js';
|
|
7
|
+
export * from '../utils/formatting.js';
|
|
8
|
+
export * from '../utils/gguf-tensor-extractor.js';
|
|
9
|
+
export * from '../utils/image-dimensions.js';
|
|
10
|
+
export * from '../utils/path-sanitize.js';
|
|
11
|
+
export * from '../utils/path-security.js';
|
|
12
|
+
export * from '../utils/shard-utils.js';
|
|
13
|
+
export * from '../utils/url-security.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Tool } from '../schemas/tools.js';
|
|
2
2
|
import type { McpClientInput } from '../schemas/mcp-adapter.js';
|
|
3
|
-
import type { ToolHandler } from '
|
|
3
|
+
import type { ToolHandler } from '../utils/tool-helpers.js';
|
|
4
4
|
export type { McpClient, McpClientInput } from '../schemas/mcp-adapter.js';
|
|
5
5
|
export type ToolHandlerMap = Map<string, ToolHandler>;
|
|
6
6
|
export type McpToolsResult = {
|
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
import { mapValues } from '
|
|
2
|
-
const VALID_TYPES = ['string', 'number', 'integer', 'boolean', 'object', 'array'];
|
|
1
|
+
import { mapValues } from '../utils/object.js';
|
|
2
|
+
const VALID_TYPES = ['string', 'number', 'integer', 'boolean', 'object', 'array', 'null'];
|
|
3
3
|
function isValidType(value) {
|
|
4
|
+
if (Array.isArray(value))
|
|
5
|
+
return value.length > 0 && value.every(isValidType);
|
|
4
6
|
return typeof value === 'string' && VALID_TYPES.includes(value);
|
|
5
7
|
}
|
|
6
8
|
function convertMcpToolToTool(mcpTool) {
|
|
7
|
-
|
|
9
|
+
// `$defs` and other top-level keywords stay, so a nested `$ref` still resolves.
|
|
10
|
+
const { $schema: _schema, title: _title, ...inputSchema } = mcpTool.inputSchema;
|
|
8
11
|
const properties = inputSchema.properties ?? {};
|
|
9
12
|
const required = inputSchema.required ?? [];
|
|
13
|
+
// Only an unrecognised `type` is replaced; a missing one is left alone because
|
|
14
|
+
// `anyOf`/`oneOf` properties carry their types in the branches.
|
|
10
15
|
const convertedProperties = mapValues(properties, (prop) => {
|
|
11
|
-
const { type
|
|
12
|
-
return
|
|
13
|
-
|
|
14
|
-
...
|
|
15
|
-
...(enumVal && { enum: enumVal })
|
|
16
|
-
};
|
|
16
|
+
const { type } = prop;
|
|
17
|
+
return type === undefined || isValidType(type)
|
|
18
|
+
? prop
|
|
19
|
+
: { ...prop, type: 'string' };
|
|
17
20
|
});
|
|
18
21
|
return {
|
|
19
22
|
type: 'function',
|
|
20
23
|
name: mcpTool.name,
|
|
21
24
|
description: mcpTool.description ?? '',
|
|
22
25
|
parameters: {
|
|
26
|
+
...inputSchema,
|
|
23
27
|
type: 'object',
|
|
24
28
|
properties: convertedProperties,
|
|
25
29
|
required: required.length > 0 ? required : undefined
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'bare-path';
|
|
2
2
|
import { PathTraversalError } from '../errors/index.js';
|
|
3
|
-
import { sanitizePathComponent } from '
|
|
3
|
+
import { sanitizePathComponent } from '../utils/path-sanitize.js';
|
|
4
4
|
/**
|
|
5
5
|
* Check whether a resolved target path is contained within a base directory.
|
|
6
6
|
* Portable — caller provides the resolve function and separator for their runtime.
|
|
@@ -12,6 +12,11 @@ export declare function getFirstShardPath(modelPath: string): string;
|
|
|
12
12
|
* @returns Array of all numbered shard filenames
|
|
13
13
|
*/
|
|
14
14
|
export declare function generateShardFilenames(shardName: string): string[];
|
|
15
|
+
/**
|
|
16
|
+
* List the files a model path loads: the path itself, or for a sharded model
|
|
17
|
+
* its tensors file followed by every shard in order
|
|
18
|
+
*/
|
|
19
|
+
export declare function getModelShardFiles(modelPath: string): string[];
|
|
15
20
|
/**
|
|
16
21
|
* Parse pattern-based shard URL and generate all shard URLs with cache key
|
|
17
22
|
* Works with patterns like: https://example.com/path/model-00002-of-00005.gguf
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ModelLoadFailedError, InvalidShardUrlPatternError } from '../errors/index.js';
|
|
2
|
-
import { generateShortHash } from '
|
|
3
|
-
import { validateAndJoinPath } from '
|
|
4
|
-
import { extractAndWriteTensorsFile } from '
|
|
2
|
+
import { generateShortHash } from '../utils/formatting.js';
|
|
3
|
+
import { validateAndJoinPath } from '../utils/path-security.js';
|
|
4
|
+
import { extractAndWriteTensorsFile } from '../utils/gguf-tensor-extractor.js';
|
|
5
5
|
import { promises as fsPromises } from 'bare-fs';
|
|
6
|
+
import path from 'bare-path';
|
|
6
7
|
/**
|
|
7
8
|
* Detect if model filename follows shard pattern (00001-of-0000x)
|
|
8
9
|
*/
|
|
@@ -55,6 +56,21 @@ export function generateShardFilenames(shardName) {
|
|
|
55
56
|
}
|
|
56
57
|
return filenames;
|
|
57
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* List the files a model path loads: the path itself, or for a sharded model
|
|
61
|
+
* its tensors file followed by every shard in order
|
|
62
|
+
*/
|
|
63
|
+
export function getModelShardFiles(modelPath) {
|
|
64
|
+
const filename = path.basename(modelPath);
|
|
65
|
+
const info = detectShardedModel(filename);
|
|
66
|
+
if (!info.isSharded)
|
|
67
|
+
return [modelPath];
|
|
68
|
+
const directory = path.dirname(modelPath);
|
|
69
|
+
return [
|
|
70
|
+
path.join(directory, `${info.baseFilename}.tensors.txt`),
|
|
71
|
+
...generateShardFilenames(filename).map((shard) => path.join(directory, shard))
|
|
72
|
+
];
|
|
73
|
+
}
|
|
58
74
|
/**
|
|
59
75
|
* Parse pattern-based shard URL and generate all shard URLs with cache key
|
|
60
76
|
* Works with patterns like: https://example.com/path/model-00002-of-00005.gguf
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { z } from 'zod';
|
|
2
2
|
import { type Tool, type ToolCall, type ToolCallWithCall } from '../schemas/tools.js';
|
|
3
3
|
type ZodObjectType = z.ZodObject<z.ZodRawShape>;
|
|
4
4
|
export type ToolHandler = (args: Record<string, unknown>) => Promise<unknown>;
|
|
@@ -1,66 +1,34 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
1
2
|
import { toolSchema } from '../schemas/tools.js';
|
|
2
3
|
import { InvalidToolsArrayError, InvalidToolSchemaError } from '../errors/index.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
default:
|
|
17
|
-
return 'string';
|
|
4
|
+
// Zod's integer bounds; they add nothing a tool grammar needs.
|
|
5
|
+
const SAFE_INTEGER_BOUNDS = new Set([Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]);
|
|
6
|
+
function dropSafeIntegerBounds(node) {
|
|
7
|
+
if (Array.isArray(node))
|
|
8
|
+
return node.map(dropSafeIntegerBounds);
|
|
9
|
+
if (!node || typeof node !== 'object')
|
|
10
|
+
return node;
|
|
11
|
+
const out = {};
|
|
12
|
+
for (const [key, value] of Object.entries(node)) {
|
|
13
|
+
if ((key === 'minimum' || key === 'maximum') && SAFE_INTEGER_BOUNDS.has(value)) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
out[key] = dropSafeIntegerBounds(value);
|
|
18
17
|
}
|
|
18
|
+
return out;
|
|
19
|
+
}
|
|
20
|
+
function zodToToolParameters(schema) {
|
|
21
|
+
const { $schema: _schema, ...json } = dropSafeIntegerBounds(z.toJSONSchema(schema, { io: 'input', unrepresentable: 'any' }));
|
|
22
|
+
return { ...json, type: 'object', properties: json['properties'] ?? {} };
|
|
19
23
|
}
|
|
20
24
|
export function convertToolInput(input) {
|
|
21
|
-
const zodSchema = input.parameters;
|
|
22
|
-
// Try both shape and def.shape for Zod v4 compatibility
|
|
23
|
-
const shape = zodSchema.shape || (typeof zodSchema.def?.shape === 'object' ? zodSchema.def.shape : {});
|
|
24
|
-
const properties = {};
|
|
25
|
-
const required = [];
|
|
26
|
-
for (const [key, value] of Object.entries(shape)) {
|
|
27
|
-
const field = value;
|
|
28
|
-
const fieldType = field.type || field.def?.type || 'string';
|
|
29
|
-
const isOptional = fieldType === 'optional';
|
|
30
|
-
let actualType = isOptional ? 'string' : fieldType;
|
|
31
|
-
let actualDescription = field.description;
|
|
32
|
-
if (isOptional && field.def?.innerType) {
|
|
33
|
-
const innerType = field.def.innerType;
|
|
34
|
-
actualType = innerType.type || innerType.def?.type || 'string';
|
|
35
|
-
// Get description from inner type if not on wrapper
|
|
36
|
-
if (!actualDescription && innerType.description) {
|
|
37
|
-
actualDescription = innerType.description;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
properties[key] = {
|
|
41
|
-
type: zodTypeToJsonSchemaType(actualType)
|
|
42
|
-
};
|
|
43
|
-
if (actualDescription) {
|
|
44
|
-
properties[key].description = actualDescription;
|
|
45
|
-
}
|
|
46
|
-
if (field.def?.values) {
|
|
47
|
-
properties[key].enum = field.def.values;
|
|
48
|
-
}
|
|
49
|
-
if (!isOptional) {
|
|
50
|
-
required.push(key);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
25
|
const tool = {
|
|
54
26
|
type: 'function',
|
|
55
27
|
name: input.name,
|
|
56
28
|
description: input.description,
|
|
57
29
|
...(input.deferLoading !== undefined && { deferLoading: input.deferLoading }),
|
|
58
30
|
...(input.group !== undefined && { group: input.group }),
|
|
59
|
-
parameters:
|
|
60
|
-
type: 'object',
|
|
61
|
-
properties,
|
|
62
|
-
required: required.length > 0 ? required : undefined
|
|
63
|
-
}
|
|
31
|
+
parameters: zodToToolParameters(input.parameters)
|
|
64
32
|
};
|
|
65
33
|
return toolSchema.parse(tool);
|
|
66
34
|
}
|
|
@@ -12,5 +12,6 @@ interface HistoryMessage {
|
|
|
12
12
|
* whole chat session.
|
|
13
13
|
*/
|
|
14
14
|
export declare function prependToolsToHistory(history: HistoryMessage[], tools: Tool[]): Array<HistoryMessage | Tool>;
|
|
15
|
+
/** The tool-call dialect resolved when the model loaded. */
|
|
15
16
|
export declare function detectToolDialect(modelId: string): ToolDialect;
|
|
16
17
|
export {};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getModelInfo } from '../runtime/model-registry.js';
|
|
1
|
+
import { getModelEntry } from '../runtime/model-registry.js';
|
|
3
2
|
/**
|
|
4
3
|
* Prepend tools right after the system message (or at the very start when no
|
|
5
4
|
* system message is present). The tool block stays in the kv-cache for the
|
|
@@ -12,9 +11,7 @@ export function prependToolsToHistory(history, tools) {
|
|
|
12
11
|
}
|
|
13
12
|
return [...tools, ...history];
|
|
14
13
|
}
|
|
14
|
+
/** The tool-call dialect resolved when the model loaded. */
|
|
15
15
|
export function detectToolDialect(modelId) {
|
|
16
|
-
|
|
17
|
-
if (!info)
|
|
18
|
-
return 'hermes';
|
|
19
|
-
return detectToolDialectFromName(info.name, info.path);
|
|
16
|
+
return getModelEntry(modelId)?.local.toolDialect ?? 'hermes';
|
|
20
17
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Tool } from '../../schemas/tools.js';
|
|
2
|
-
import { type ToolInput } from '
|
|
2
|
+
import { type ToolInput } from '../../utils/tool-helpers.js';
|
|
3
3
|
/**
|
|
4
4
|
* Reserved name of the built-in search tool. A caller cannot register a tool
|
|
5
5
|
* under this name, and it is never itself deferred — the model needs one
|
|
@@ -50,44 +50,34 @@ export declare function buildToolSearchResult(query: string, matches: readonly T
|
|
|
50
50
|
*/
|
|
51
51
|
export declare function loadedToolNames(history: readonly HistoryMessage[]): Set<string>;
|
|
52
52
|
export type DeferredResolution = {
|
|
53
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Definitions that go into the prompt and the parser: always-loaded tools,
|
|
55
|
+
* `tool_search`, and whatever history has loaded.
|
|
56
|
+
*/
|
|
54
57
|
toolsToRender: Tool[];
|
|
55
|
-
/**
|
|
56
|
-
callableTools: Tool[];
|
|
57
|
-
/** The full deferred inventory, for `tool_search` to search over. */
|
|
58
|
+
/** The deferred tools `tool_search` searches over. */
|
|
58
59
|
deferred: Tool[];
|
|
59
60
|
};
|
|
60
61
|
/**
|
|
61
|
-
* Split a registered tool list into what the prompt carries and what
|
|
62
|
-
*
|
|
62
|
+
* Split a registered tool list into what the prompt carries and what
|
|
63
|
+
* `tool_search` searches over.
|
|
63
64
|
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
65
|
+
* A loaded definition is declared in the tools block like any other tool, in
|
|
66
|
+
* registration order. A schema that sits only in a `tool` result, outside the
|
|
67
|
+
* block and the tool-call grammar, is not reliably called by small models: they
|
|
68
|
+
* search for it again instead. Declaring it changes the block at the front of
|
|
69
|
+
* the prompt, so the turn after a search re-prefills from there.
|
|
68
70
|
*
|
|
69
71
|
* Returns `null` when nothing defers, so the existing path is untouched.
|
|
70
72
|
*/
|
|
71
73
|
export declare function resolveDeferredTools(tools: readonly Tool[] | undefined, history: readonly HistoryMessage[]): DeferredResolution | null;
|
|
72
|
-
/**
|
|
73
|
-
* Generation params for a turn whose history may have loaded deferred definitions.
|
|
74
|
-
*
|
|
75
|
-
* The addon builds its tool-call grammar from the rendered tools only, and a
|
|
76
|
-
* loaded definition lives in the history rather than that block, so under the
|
|
77
|
-
* default grammar the model can never produce the name it just loaded. Unless
|
|
78
|
-
* the caller asked for more than the default, those turns run with the grammar
|
|
79
|
-
* off and the parser, which does accept loaded names, validates the call.
|
|
80
|
-
*/
|
|
81
|
-
export declare function withDeferredToolChoice<T extends {
|
|
82
|
-
tool_choice?: string | undefined;
|
|
83
|
-
}>(generationParams: T | undefined, resolution: DeferredResolution | null): T | undefined;
|
|
84
74
|
/**
|
|
85
75
|
* Run a `tool_search` call and produce the `tool` message that carries its
|
|
86
76
|
* result. Pure over the history it is given; the caller appends the message.
|
|
87
77
|
*
|
|
88
78
|
* Takes either wire `Tool`s or the Zod-schema `ToolInput` form, because what a
|
|
89
|
-
* caller holds is whatever they passed to `completion()`.
|
|
90
|
-
*
|
|
91
|
-
*
|
|
79
|
+
* caller holds is whatever they passed to `completion()`. Both are converted
|
|
80
|
+
* to wire form first, so the size cap measures the JSON schemas the prompt
|
|
81
|
+
* will declare, not Zod objects.
|
|
92
82
|
*/
|
|
93
83
|
export declare function executeToolSearch(tools: readonly Tool[] | readonly ToolInput[], args: Record<string, unknown>, history: readonly HistoryMessage[]): string;
|