@qvac/inference 0.18.1 → 0.19.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 +11 -2
- package/README.md +1 -5
- package/dist/api/assess-model-fit.d.ts +16 -0
- package/dist/api/assess-model-fit.js +27 -0
- package/dist/api/audio-gen.d.ts +4 -4
- package/dist/api/audio-gen.js +17 -6
- package/dist/api/completion-stream.d.ts +1 -1
- package/dist/api/completion-stream.js +1 -1
- package/dist/api/download-asset.d.ts +1 -1
- package/dist/api/download-asset.js +2 -2
- package/dist/api/finetune.js +1 -1
- package/dist/api/get-loaded-model-info.d.ts +6 -10
- package/dist/api/get-loaded-model-info.js +6 -10
- package/dist/api/heartbeat.d.ts +5 -22
- package/dist/api/heartbeat.js +6 -23
- package/dist/api/index.d.ts +36 -35
- package/dist/api/index.js +35 -35
- package/dist/api/load-model.d.ts +5 -1
- package/dist/api/load-model.js +3 -5
- package/dist/api/logging-stream-registry.js +1 -1
- package/dist/api/resume.d.ts +0 -3
- package/dist/api/resume.js +0 -3
- package/dist/api/subscribe-logs.js +1 -1
- package/dist/api/suspend.d.ts +0 -4
- package/dist/api/suspend.js +0 -4
- package/dist/api/translate.d.ts +3 -1
- package/dist/api/translate.js +16 -8
- package/dist/api/unload-model.js +3 -5
- package/dist/api/video-request.d.ts +207 -0
- package/dist/api/video-request.js +18 -0
- package/dist/api/video.d.ts +22 -2
- package/dist/api/video.js +25 -15
- package/dist/api/vla-helpers.d.ts +1 -2
- package/dist/api/vla-helpers.js +1 -2
- package/dist/api/vla.js +1 -1
- package/dist/api/world-result.d.ts +71 -0
- package/dist/api/world-result.js +293 -0
- package/dist/api/world.d.ts +143 -0
- package/dist/api/world.js +71 -0
- 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.js +15 -28
- package/dist/errors/index.d.ts +35 -31
- package/dist/errors/index.js +66 -56
- package/dist/handlers/assess-model-fit.d.ts +10 -0
- package/dist/handlers/assess-model-fit.js +75 -0
- package/dist/handlers/cancelHandler.js +1 -1
- package/dist/handlers/completion-orchestrate.js +1 -1
- package/dist/handlers/download-asset.js +6 -5
- package/dist/handlers/finetune.js +1 -1
- package/dist/handlers/get-loaded-model-info.js +0 -12
- package/dist/handlers/get-model-info.js +1 -1
- package/dist/handlers/get-system-resources.js +8 -0
- package/dist/handlers/load-model/download-manager.d.ts +1 -1
- package/dist/handlers/load-model/download-stats.d.ts +3 -3
- package/dist/handlers/load-model/download-stats.js +5 -5
- package/dist/handlers/load-model/handler.js +6 -8
- package/dist/handlers/load-model/http-verify.d.ts +20 -0
- package/dist/handlers/load-model/http-verify.js +54 -0
- package/dist/handlers/load-model/http.d.ts +12 -2
- package/dist/handlers/load-model/http.js +119 -230
- package/dist/handlers/load-model/hyperdrive.d.ts +1 -1
- package/dist/handlers/load-model/hyperdrive.js +1 -1
- 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 +4 -4
- package/dist/handlers/load-model/resolve-session.d.ts +8 -1
- package/dist/handlers/load-model/resolve-session.js +12 -9
- package/dist/handlers/load-model/resolve.d.ts +4 -4
- package/dist/handlers/load-model/resolve.js +18 -16
- package/dist/handlers/load-model/safe-fetch.d.ts +44 -0
- package/dist/handlers/load-model/safe-fetch.js +143 -0
- package/dist/handlers/load-model/types.d.ts +9 -0
- package/dist/handlers/plugin-dispatch.js +1 -4
- package/dist/handlers/plugin-invoke.js +1 -4
- package/dist/handlers/types.d.ts +0 -2
- package/dist/handlers/unload-model.js +1 -4
- 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/models/registry/index.d.ts +1 -1
- package/dist/models/registry/index.js +2 -2
- package/dist/models/registry/models.d.ts +250 -0
- package/dist/models/registry/models.js +2071 -1806
- package/dist/models/registry/resource-profiles.d.ts +18 -0
- package/dist/models/registry/resource-profiles.js +4934 -0
- package/dist/plugins/builtin/audiogen-ggml/config.d.ts +14 -0
- package/dist/plugins/builtin/audiogen-ggml/config.js +23 -0
- package/dist/plugins/builtin/audiogen-ggml/ops/audio-gen-stream.js +47 -5
- package/dist/plugins/builtin/audiogen-ggml/plugin.d.ts +134 -4
- package/dist/plugins/builtin/audiogen-ggml/plugin.js +47 -28
- package/dist/plugins/builtin/bci-whispercpp-transcription/plugin.d.ts +1 -1
- 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/plugin.js +2 -2
- package/dist/plugins/builtin/ggml-vla/plugin.d.ts +1 -1
- package/dist/plugins/builtin/ggml-vla/plugin.js +3 -3
- package/dist/plugins/builtin/index.d.ts +12 -12
- package/dist/plugins/builtin/index.js +12 -12
- package/dist/plugins/builtin/llamacpp-completion/ops/batch-completion-stream.js +2 -2
- package/dist/plugins/builtin/llamacpp-completion/ops/completion-stream.js +37 -26
- package/dist/plugins/builtin/llamacpp-completion/ops/context-overflow.d.ts +12 -11
- package/dist/plugins/builtin/llamacpp-completion/ops/context-overflow.js +133 -41
- package/dist/plugins/builtin/llamacpp-completion/ops/kv-cache-session.d.ts +7 -1
- package/dist/plugins/builtin/llamacpp-completion/ops/kv-cache-session.js +26 -4
- package/dist/plugins/builtin/llamacpp-completion/plugin.d.ts +19 -8
- package/dist/plugins/builtin/llamacpp-completion/plugin.js +10 -13
- package/dist/plugins/builtin/llamacpp-embedding/plugin.d.ts +4 -0
- package/dist/plugins/builtin/llamacpp-embedding/plugin.js +13 -2
- package/dist/plugins/builtin/nmtcpp-translation/plugin.js +2 -2
- package/dist/plugins/builtin/parakeet-transcription/plugin.d.ts +2 -2
- package/dist/plugins/builtin/parakeet-transcription/plugin.js +3 -3
- package/dist/plugins/builtin/sdcpp-generation/ops/upscale.js +1 -1
- package/dist/plugins/builtin/sdcpp-generation/ops/video.js +32 -2
- package/dist/plugins/builtin/sdcpp-generation/ops/world.d.ts +126 -0
- package/dist/plugins/builtin/sdcpp-generation/ops/world.js +820 -0
- package/dist/plugins/builtin/sdcpp-generation/plugin.d.ts +153 -4
- package/dist/plugins/builtin/sdcpp-generation/plugin.js +134 -13
- package/dist/plugins/builtin/tts-ggml/ops/text-to-speech-stream.js +1 -1
- package/dist/plugins/builtin/tts-ggml/ops/text-to-speech.js +1 -1
- package/dist/plugins/builtin/tts-ggml/plugin.js +2 -2
- package/dist/plugins/builtin/whispercpp-transcription/plugin.d.ts +2 -2
- package/dist/plugins/builtin/whispercpp-transcription/plugin.js +3 -3
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.js +2 -2
- package/dist/plugins/ops/kv-cache-utils.js +1 -1
- package/dist/plugins/ops/load-model.js +1 -1
- package/dist/plugins/ops/transcribe.js +2 -2
- package/dist/plugins/ops/translate.js +4 -12
- package/dist/plugins/ops/unload-model.js +19 -21
- package/dist/plugins/registry.d.ts +1 -0
- package/dist/plugins/registry.js +12 -0
- 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/envelope.d.ts +0 -1
- package/dist/profiling/envelope.js +0 -10
- package/dist/profiling/events.d.ts +2 -3
- package/dist/profiling/events.js +2 -9
- package/dist/profiling/exporters.d.ts +1 -1
- package/dist/profiling/exporters.js +3 -3
- package/dist/profiling/index.d.ts +13 -14
- package/dist/profiling/index.js +12 -13
- package/dist/profiling/operation-metrics.d.ts +1 -1
- package/dist/profiling/operation-metrics.js +35 -2
- package/dist/profiling/operation-wrappers.js +12 -15
- package/dist/profiling/profiler.d.ts +1 -2
- package/dist/profiling/profiler.js +7 -26
- package/dist/profiling/types.d.ts +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 +2 -6
- 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.d.ts +4 -2
- package/dist/rag/rag-workspace-manager.js +268 -15
- package/dist/registry.js +8 -58
- package/dist/resources/collector.d.ts +3 -1
- package/dist/resources/collector.js +91 -9
- package/dist/resources/instance.d.ts +1 -1
- package/dist/resources/instance.js +1 -1
- package/dist/resources/model-fit/assess.d.ts +36 -0
- package/dist/resources/model-fit/assess.js +578 -0
- package/dist/resources/model-fit/calibration/darwin-arm64.d.ts +8 -0
- package/dist/resources/model-fit/calibration/darwin-arm64.js +36 -0
- package/dist/resources/model-fit/calibration/darwin-x64.d.ts +8 -0
- package/dist/resources/model-fit/calibration/darwin-x64.js +38 -0
- package/dist/resources/model-fit/calibration/fit.d.ts +73 -0
- package/dist/resources/model-fit/calibration/fit.js +152 -0
- package/dist/resources/model-fit/calibration/index.d.ts +37 -0
- package/dist/resources/model-fit/calibration/index.js +75 -0
- package/dist/resources/model-fit/calibration/linux-arm64.d.ts +8 -0
- package/dist/resources/model-fit/calibration/linux-arm64.js +38 -0
- package/dist/resources/model-fit/calibration/linux-x64-vulkan.d.ts +8 -0
- package/dist/resources/model-fit/calibration/linux-x64-vulkan.js +39 -0
- package/dist/resources/model-fit/calibration/linux-x64.d.ts +8 -0
- package/dist/resources/model-fit/calibration/linux-x64.js +38 -0
- package/dist/resources/model-fit/calibration/win32-x64-vulkan-shared.d.ts +8 -0
- package/dist/resources/model-fit/calibration/win32-x64-vulkan-shared.js +39 -0
- package/dist/resources/model-fit/calibration/win32-x64-vulkan.d.ts +8 -0
- package/dist/resources/model-fit/calibration/win32-x64-vulkan.js +36 -0
- package/dist/resources/model-fit/calibration/win32-x64.d.ts +8 -0
- package/dist/resources/model-fit/calibration/win32-x64.js +38 -0
- package/dist/resources/model-fit/estimators/llm.d.ts +45 -0
- package/dist/resources/model-fit/estimators/llm.js +220 -0
- package/dist/resources/model-fit/estimators/whisper.d.ts +10 -0
- package/dist/resources/model-fit/estimators/whisper.js +77 -0
- package/dist/resources/model-fit/types.d.ts +120 -0
- package/dist/resources/model-fit/types.js +1 -0
- package/dist/resources/native.d.ts +1 -1
- package/dist/resources/native.js +14 -0
- package/dist/resources/normalize.d.ts +1 -1
- package/dist/resources/types.d.ts +16 -0
- package/dist/runtime/index.d.ts +5 -5
- package/dist/runtime/index.js +2 -2
- package/dist/runtime/lifecycle.js +5 -7
- package/dist/runtime/model-registry.d.ts +0 -14
- package/dist/runtime/model-registry.js +17 -40
- package/dist/runtime/registry-client.js +1 -1
- package/dist/runtime/request-context.d.ts +3 -3
- package/dist/runtime/request-context.js +13 -1
- package/dist/runtime/request-registry.d.ts +1 -1
- package/dist/runtime/request-registry.js +4 -5
- package/dist/runtime/state.d.ts +1 -1
- package/dist/runtime/state.js +18 -3
- package/dist/schemas/assess-model-fit.d.ts +271 -0
- package/dist/schemas/assess-model-fit.js +153 -0
- package/dist/schemas/audio-gen.d.ts +434 -4
- package/dist/schemas/audio-gen.js +131 -19
- package/dist/schemas/batch-completion-stream.d.ts +2 -2
- package/dist/schemas/batch-completion-stream.js +3 -3
- package/dist/schemas/bci-config.js +73 -27
- package/dist/schemas/bci.d.ts +2 -2
- package/dist/schemas/bci.js +5 -5
- package/dist/schemas/cancel.d.ts +5 -0
- package/dist/schemas/cancel.js +1 -0
- package/dist/schemas/classification.js +13 -6
- package/dist/schemas/common.d.ts +662 -331
- package/dist/schemas/common.js +33 -31
- package/dist/schemas/completion-event.d.ts +2 -2
- package/dist/schemas/completion-event.js +1 -1
- package/dist/schemas/completion-stream.d.ts +1 -5
- package/dist/schemas/completion-stream.js +4 -8
- package/dist/schemas/config.d.ts +640 -18
- package/dist/schemas/config.js +50 -8
- package/dist/schemas/download-asset.d.ts +19 -1
- package/dist/schemas/download-asset.js +20 -4
- package/dist/schemas/engine-addon-map.d.ts +1 -1
- package/dist/schemas/engine-addon-map.js +3 -3
- package/dist/schemas/error.d.ts +2 -2
- package/dist/schemas/error.js +2 -2
- package/dist/schemas/errors.d.ts +2 -6
- package/dist/schemas/errors.js +30 -40
- package/dist/schemas/heartbeat.d.ts +10 -0
- package/dist/schemas/heartbeat.js +8 -0
- package/dist/schemas/index.d.ts +46 -44
- package/dist/schemas/index.js +45 -43
- package/dist/schemas/llamacpp-config.d.ts +32 -10
- package/dist/schemas/llamacpp-config.js +11 -8
- package/dist/schemas/load-model.d.ts +2933 -1948
- package/dist/schemas/load-model.js +52 -52
- package/dist/schemas/mcp-adapter.d.ts +1 -1
- package/dist/schemas/model-config-schemas.d.ts +2354 -0
- package/dist/schemas/model-config-schemas.js +46 -0
- package/dist/schemas/model-info.d.ts +10 -20
- package/dist/schemas/model-info.js +4 -25
- package/dist/schemas/model-ops.d.ts +0 -1
- package/dist/schemas/model-ops.js +1 -2
- package/dist/schemas/model-resource-profile.d.ts +109 -0
- package/dist/schemas/model-resource-profile.js +83 -0
- package/dist/schemas/model-src-utils.d.ts +1 -0
- package/dist/schemas/model-src-utils.js +33 -13
- package/dist/schemas/ocr.js +48 -13
- package/dist/schemas/path-validation.js +8 -2
- package/dist/schemas/plugin.d.ts +14 -1
- package/dist/schemas/plugin.js +11 -0
- package/dist/schemas/profiling.d.ts +138 -43
- package/dist/schemas/profiling.js +1 -22
- package/dist/schemas/rag.js +1 -1
- package/dist/schemas/registry.js +1 -1
- package/dist/schemas/reload-config.d.ts +0 -2
- package/dist/schemas/reload-config.js +2 -3
- package/dist/schemas/sdcpp-config.d.ts +344 -4
- package/dist/schemas/sdcpp-config.js +504 -17
- package/dist/schemas/system-resources.d.ts +138 -0
- package/dist/schemas/system-resources.js +3 -1
- package/dist/schemas/text-to-speech.js +183 -76
- package/dist/schemas/transcription-config.js +253 -85
- package/dist/schemas/transcription.d.ts +3 -3
- package/dist/schemas/translate.d.ts +2 -2
- package/dist/schemas/translate.js +1 -1
- package/dist/schemas/translation-config.js +53 -25
- package/dist/schemas/vla.d.ts +1 -1
- package/dist/selection.d.ts +1 -5
- package/dist/selection.js +2 -6
- package/dist/surface.d.ts +1 -1
- 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/audio-input.js +1 -1
- package/dist/utils/cache/auto-history.d.ts +1 -1
- package/dist/utils/cache/auto-history.js +1 -1
- package/dist/utils/cache/paths.js +5 -5
- package/dist/utils/completion-normalizer.js +1 -1
- package/dist/utils/gguf-tensor-extractor.js +1 -1
- package/dist/utils/image-dimensions.d.ts +26 -0
- package/dist/utils/image-dimensions.js +46 -0
- package/dist/utils/index.d.ts +13 -10
- package/dist/utils/index.js +13 -10
- package/dist/utils/mcp-adapter.d.ts +1 -1
- package/dist/utils/mcp-adapter.js +1 -1
- package/dist/utils/path-sanitize.d.ts +7 -0
- package/dist/utils/path-sanitize.js +36 -0
- package/dist/utils/path-security.d.ts +0 -7
- package/dist/utils/path-security.js +1 -36
- package/dist/utils/shard-utils.js +3 -3
- package/dist/utils/tool-integration.js +1 -1
- package/dist/utils/tools/dialect.js +1 -1
- package/dist/utils/tools/index.d.ts +2 -2
- package/dist/utils/tools/index.js +2 -2
- 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 +1 -1
- 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 +3 -3
- package/dist/utils/url-security.d.ts +17 -0
- package/dist/utils/url-security.js +75 -0
- package/package.json +31 -26
- package/dist/api/provide.d.ts +0 -23
- package/dist/api/provide.js +0 -32
- package/dist/api/stop-provider.d.ts +0 -20
- package/dist/api/stop-provider.js +0 -30
- package/dist/p2p/cancel-delegated.d.ts +0 -3
- package/dist/p2p/cancel-delegated.js +0 -64
- package/dist/p2p/completion-stream-delegated.d.ts +0 -4
- package/dist/p2p/completion-stream-delegated.js +0 -51
- package/dist/p2p/delegate-client.d.ts +0 -9
- package/dist/p2p/delegate-client.js +0 -219
- package/dist/p2p/delegate-connect-diagnostics.d.ts +0 -8
- package/dist/p2p/delegate-connect-diagnostics.js +0 -38
- package/dist/p2p/delegate-transport.d.ts +0 -18
- package/dist/p2p/delegate-transport.js +0 -237
- package/dist/p2p/error-handlers.d.ts +0 -4
- package/dist/p2p/error-handlers.js +0 -31
- package/dist/p2p/handle-request.d.ts +0 -2
- package/dist/p2p/handle-request.js +0 -171
- package/dist/p2p/handler-utils.d.ts +0 -19
- package/dist/p2p/handler-utils.js +0 -180
- package/dist/p2p/heartbeat-delegated.d.ts +0 -3
- package/dist/p2p/heartbeat-delegated.js +0 -32
- package/dist/p2p/load-model-delegated.d.ts +0 -6
- package/dist/p2p/load-model-delegated.js +0 -132
- package/dist/p2p/progress-throttle.d.ts +0 -7
- package/dist/p2p/progress-throttle.js +0 -47
- package/dist/p2p/provideHandler/connection.d.ts +0 -2
- package/dist/p2p/provideHandler/connection.js +0 -38
- package/dist/p2p/provideHandler/handler.d.ts +0 -2
- package/dist/p2p/provideHandler/handler.js +0 -66
- package/dist/p2p/provideHandler/proxy.d.ts +0 -2
- package/dist/p2p/provideHandler/proxy.js +0 -24
- package/dist/p2p/provideHandler.d.ts +0 -1
- package/dist/p2p/provideHandler.js +0 -2
- package/dist/p2p/rpc-utils.d.ts +0 -4
- package/dist/p2p/rpc-utils.js +0 -8
- package/dist/p2p/stopProvideHandler.d.ts +0 -2
- package/dist/p2p/stopProvideHandler.js +0 -29
- package/dist/p2p/swarm.d.ts +0 -9
- package/dist/p2p/swarm.js +0 -103
- package/dist/p2p/transport-selector.d.ts +0 -2
- package/dist/p2p/transport-selector.js +0 -18
- package/dist/p2p/unload-model-delegated.d.ts +0 -2
- package/dist/p2p/unload-model-delegated.js +0 -31
- package/dist/profiling/delegation-profiler.d.ts +0 -31
- package/dist/profiling/delegation-profiler.js +0 -155
- package/dist/schemas/delegate.d.ts +0 -29
- package/dist/schemas/delegate.js +0 -40
- package/dist/schemas/provide.d.ts +0 -50
- package/dist/schemas/provide.js +0 -32
|
@@ -6,7 +6,7 @@ import Hyperdrive from 'hyperdrive';
|
|
|
6
6
|
import { getQvacPath } from '../../utils/qvac-paths.js';
|
|
7
7
|
import { getModelsCacheDir, generateShortHash, detectShardedModel, getShardedModelCacheDir, getShardPath, checkShardCompleteness, measureChecksum, extractTensorsFromShards, calculatePercentage } from '../../utils/index.js';
|
|
8
8
|
import { getModelBySrc } from '../../models/registry/index.js';
|
|
9
|
-
import { createHyperdriveDownloadKey, startOrJoinDownload, applyJoinedDownloadStats } from '
|
|
9
|
+
import { createHyperdriveDownloadKey, startOrJoinDownload, applyJoinedDownloadStats } from './download-manager.js';
|
|
10
10
|
import { getConfig } from '../../runtime/state.js';
|
|
11
11
|
import { FileNotFoundError, ChecksumValidationFailedError, DownloadCancelledError, HyperdriveDownloadFailedError, ModelLoadFailedError, NoBlobFoundError } from '../../errors/index.js';
|
|
12
12
|
import { getEngineLogger } from '../../logging/index.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { handleLoadModel } from '
|
|
2
|
-
export { resolveModelPath } from '
|
|
1
|
+
export { handleLoadModel } from './handler.js';
|
|
2
|
+
export { resolveModelPath } from './resolve.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { handleLoadModel } from '
|
|
2
|
-
export { resolveModelPath } from '
|
|
1
|
+
export { handleLoadModel } from './handler.js';
|
|
2
|
+
export { resolveModelPath } from './resolve.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ModelProgressUpdate } from '../../schemas/index.js';
|
|
2
2
|
import type { RegistryItem } from '../../models/registry/index.js';
|
|
3
3
|
import type { AbortSignal } from 'bare-abort-controller';
|
|
4
|
-
import type { DownloadHooks } from '
|
|
4
|
+
import type { DownloadHooks } from './types.js';
|
|
5
5
|
type CompanionSetMetadata = NonNullable<RegistryItem['companionSet']>;
|
|
6
6
|
export interface DownloadCompanionSetOptions {
|
|
7
7
|
companionSet: CompanionSetMetadata;
|
|
@@ -2,7 +2,7 @@ import { promises as fsPromises } from 'bare-fs';
|
|
|
2
2
|
import { getModelsCacheDir, getCompanionSetPath, getCompanionSetCacheDir, getSingleFileCachePath, generateShortHash, calculatePercentage } from '../../utils/index.js';
|
|
3
3
|
import { measureChecksum } from '../../utils/checksum.js';
|
|
4
4
|
import { validateAndJoinPath } from '../../utils/path-security.js';
|
|
5
|
-
import { buildBlobBinding, downloadSingleFileFromRegistry, validateCachedFile } from '
|
|
5
|
+
import { buildBlobBinding, downloadSingleFileFromRegistry, validateCachedFile } from './registry-download-utils.js';
|
|
6
6
|
import { DownloadCancelledError, RegistryDownloadFailedError } from '../../errors/index.js';
|
|
7
7
|
import { getEngineLogger } from '../../logging/index.js';
|
|
8
8
|
const logger = getEngineLogger();
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { ModelProgressUpdate } from '../../schemas/index.js';
|
|
2
2
|
import type { QVACBlobBinding } from '@qvac/registry-client';
|
|
3
3
|
import type { AbortSignal } from 'bare-abort-controller';
|
|
4
|
-
import type { DownloadHooks } from '
|
|
5
|
-
export { DEFAULT_REGISTRY_STREAM_TIMEOUT_MS, buildRegistryClientOptions } from '
|
|
6
|
-
export type { RegistryClientDownloadOptions } from '
|
|
4
|
+
import type { DownloadHooks } from './types.js';
|
|
5
|
+
export { DEFAULT_REGISTRY_STREAM_TIMEOUT_MS, buildRegistryClientOptions } from './registry-client-options.js';
|
|
6
|
+
export type { RegistryClientDownloadOptions } from './registry-client-options.js';
|
|
7
7
|
export declare function buildBlobBinding(meta: {
|
|
8
8
|
blobCoreKey: string;
|
|
9
9
|
blobBlockOffset: number;
|
|
@@ -3,11 +3,11 @@ import path from 'bare-path';
|
|
|
3
3
|
import { measureChecksum, calculatePercentage } from '../../utils/index.js';
|
|
4
4
|
import { getRegistryClient } from '../../runtime/registry-client.js';
|
|
5
5
|
import { getConfig } from '../../runtime/state.js';
|
|
6
|
-
import { buildRegistryClientOptions } from '
|
|
6
|
+
import { buildRegistryClientOptions } from './registry-client-options.js';
|
|
7
7
|
import { ChecksumValidationFailedError, DownloadCancelledError } from '../../errors/index.js';
|
|
8
8
|
import { getEngineLogger } from '../../logging/index.js';
|
|
9
9
|
const logger = getEngineLogger();
|
|
10
|
-
export { DEFAULT_REGISTRY_STREAM_TIMEOUT_MS, buildRegistryClientOptions } from '
|
|
10
|
+
export { DEFAULT_REGISTRY_STREAM_TIMEOUT_MS, buildRegistryClientOptions } from './registry-client-options.js';
|
|
11
11
|
export function buildBlobBinding(meta) {
|
|
12
12
|
return {
|
|
13
13
|
coreKey: meta.blobCoreKey,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ModelProgressUpdate } from '../../schemas/index.js';
|
|
2
|
-
import type { DownloadHooks } from '
|
|
3
|
-
import { type ExplicitRegistryMetadata } from '
|
|
2
|
+
import type { DownloadHooks } from './types.js';
|
|
3
|
+
import { type ExplicitRegistryMetadata } from './registry-metadata.js';
|
|
4
4
|
export declare function downloadModelFromRegistry(registryPath: string, registrySource: string, progressCallback?: (progress: ModelProgressUpdate) => void, expectedChecksum?: string, hooks?: DownloadHooks, explicitMetadata?: ExplicitRegistryMetadata): Promise<string>;
|
|
@@ -3,12 +3,12 @@ import { generateShortHash, detectShardedModel, getShardedModelCacheDir, getShar
|
|
|
3
3
|
import { getSingleFileCachePath } from '../../utils/cache/paths.js';
|
|
4
4
|
import { getModelByPath } from '../../models/registry/index.js';
|
|
5
5
|
import { getRegistryClient } from '../../runtime/registry-client.js';
|
|
6
|
-
import { createRegistryDownloadKey, startOrJoinDownload, applyJoinedDownloadStats } from '
|
|
7
|
-
import { buildBlobBinding, validateCachedFile, downloadSingleFileFromRegistry } from '
|
|
8
|
-
import { downloadCompanionSetFromRegistry } from '
|
|
6
|
+
import { createRegistryDownloadKey, startOrJoinDownload, applyJoinedDownloadStats } from './download-manager.js';
|
|
7
|
+
import { buildBlobBinding, validateCachedFile, downloadSingleFileFromRegistry } from './registry-download-utils.js';
|
|
8
|
+
import { downloadCompanionSetFromRegistry } from './registry-companion-set.js';
|
|
9
9
|
import { DownloadCancelledError, ModelNotFoundError, RegistryDownloadFailedError } from '../../errors/index.js';
|
|
10
10
|
import { getEngineLogger } from '../../logging/index.js';
|
|
11
|
-
import { resolveRegistryDownloadMetadata } from '
|
|
11
|
+
import { resolveRegistryDownloadMetadata } from './registry-metadata.js';
|
|
12
12
|
const logger = getEngineLogger();
|
|
13
13
|
/**
|
|
14
14
|
* Find all shards for a model using path prefix query.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AbortSignal } from 'bare-abort-controller';
|
|
2
2
|
import type { ModelProgressUpdate, ResolveContext } from '../../schemas/index.js';
|
|
3
|
-
import type { DownloadRequestBinding, ResolveResult } from '
|
|
3
|
+
import type { DownloadRequestBinding, ResolveResult, DownloadSecurityOptions } from './types.js';
|
|
4
4
|
export interface ResolveSessionOptions {
|
|
5
5
|
progressCallback?: ((update: ModelProgressUpdate) => void) | undefined;
|
|
6
6
|
seed?: boolean | undefined;
|
|
@@ -23,6 +23,13 @@ export interface ResolveSessionOptions {
|
|
|
23
23
|
* `registry.cancel({ requestId })`.
|
|
24
24
|
*/
|
|
25
25
|
requestBinding?: DownloadRequestBinding | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Per-call HTTP download security overrides, applied to every resolve in this
|
|
28
|
+
* session — the primary model and every companion asset resolved by a plugin
|
|
29
|
+
* — so an explicit `requireSecureTransport` / `requireHttpChecksum` covers the
|
|
30
|
+
* whole load, not just the main file.
|
|
31
|
+
*/
|
|
32
|
+
security?: DownloadSecurityOptions | undefined;
|
|
26
33
|
}
|
|
27
34
|
export interface ResolveSession {
|
|
28
35
|
resolvePrimaryModelPath(modelSrc: unknown, fallbackSrc?: string): Promise<string>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { resolveModelPath, resolveModelPathWithStats } from '
|
|
2
|
-
import { cancelTransfer } from '
|
|
3
|
-
import { mergeDownloadStats } from '
|
|
1
|
+
import { resolveModelPath, resolveModelPathWithStats } from './resolve.js';
|
|
2
|
+
import { cancelTransfer } from './download-manager.js';
|
|
3
|
+
import { mergeDownloadStats } from './download-stats.js';
|
|
4
|
+
import { getRuntimeContext } from '../../runtime/state.js';
|
|
4
5
|
export function createResolveSession(options) {
|
|
5
|
-
const { progressCallback, seed, profilingEnabled, signal, requestBinding } = options;
|
|
6
|
+
const { progressCallback, seed, profilingEnabled, signal, requestBinding, security } = options;
|
|
6
7
|
let primaryResult;
|
|
7
8
|
const resolveResults = [];
|
|
8
9
|
const activeDownloadKeys = new Set();
|
|
@@ -14,27 +15,29 @@ export function createResolveSession(options) {
|
|
|
14
15
|
};
|
|
15
16
|
async function resolvePrimaryModelPath(modelSrc, fallbackSrc) {
|
|
16
17
|
if (profilingEnabled) {
|
|
17
|
-
const result = await resolveModelPathWithStats(modelSrc, progressCallback, seed, signal, downloadHooks, fallbackSrc);
|
|
18
|
+
const result = await resolveModelPathWithStats(modelSrc, progressCallback, seed, signal, downloadHooks, fallbackSrc, security);
|
|
18
19
|
primaryResult = result;
|
|
19
20
|
resolveResults.push(result);
|
|
20
21
|
return result.path;
|
|
21
22
|
}
|
|
22
|
-
return resolveModelPath(modelSrc, progressCallback, seed, signal, downloadHooks, fallbackSrc);
|
|
23
|
+
return resolveModelPath(modelSrc, progressCallback, seed, signal, downloadHooks, fallbackSrc, security);
|
|
23
24
|
}
|
|
24
25
|
async function resolveForPlugin(src) {
|
|
25
26
|
if (profilingEnabled) {
|
|
26
|
-
const result = await resolveModelPathWithStats(src, progressCallback, seed, signal, downloadHooks);
|
|
27
|
+
const result = await resolveModelPathWithStats(src, progressCallback, seed, signal, downloadHooks, undefined, security);
|
|
27
28
|
resolveResults.push(result);
|
|
28
29
|
return result.path;
|
|
29
30
|
}
|
|
30
|
-
return resolveModelPath(src, progressCallback, seed, signal, downloadHooks);
|
|
31
|
+
return resolveModelPath(src, progressCallback, seed, signal, downloadHooks, undefined, security);
|
|
31
32
|
}
|
|
32
33
|
function createResolveContext(modelSrc, modelType, modelName) {
|
|
34
|
+
const platform = getRuntimeContext().platform;
|
|
33
35
|
return {
|
|
34
36
|
resolveModelPath: resolveForPlugin,
|
|
35
37
|
modelSrc,
|
|
36
38
|
modelType,
|
|
37
|
-
...(modelName !== undefined && { modelName })
|
|
39
|
+
...(modelName !== undefined && { modelName }),
|
|
40
|
+
...(platform !== undefined && { platform })
|
|
38
41
|
};
|
|
39
42
|
}
|
|
40
43
|
function getAggregateResult() {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type ModelProgressUpdate } from '../../schemas/index.js';
|
|
2
|
-
import type { ResolveResult, DownloadHooks } from '
|
|
2
|
+
import type { ResolveResult, DownloadHooks, DownloadSecurityOptions } from './types.js';
|
|
3
3
|
import type { AbortSignal } from 'bare-abort-controller';
|
|
4
4
|
type ResolveMode = 'base' | 'stats';
|
|
5
|
-
export declare function resolveFallbackModel(fallbackSrc: string, expectedChecksum: string | undefined, progressCallback: ((progress: ModelProgressUpdate) => void) | undefined, mode: ResolveMode, signal: AbortSignal | undefined, hooks: DownloadHooks | undefined): Promise<ResolveResult>;
|
|
5
|
+
export declare function resolveFallbackModel(fallbackSrc: string, expectedChecksum: string | undefined, progressCallback: ((progress: ModelProgressUpdate) => void) | undefined, mode: ResolveMode, signal: AbortSignal | undefined, hooks: DownloadHooks | undefined, security?: DownloadSecurityOptions): Promise<ResolveResult>;
|
|
6
6
|
export declare function resolveRegistryModel(params: {
|
|
7
7
|
hasFallback: boolean;
|
|
8
8
|
isKnownModel: boolean;
|
|
@@ -10,6 +10,6 @@ export declare function resolveRegistryModel(params: {
|
|
|
10
10
|
resolveFallback: () => Promise<ResolveResult>;
|
|
11
11
|
buildUnreachableError: (cause: unknown) => Error;
|
|
12
12
|
}): Promise<ResolveResult>;
|
|
13
|
-
export declare function resolveModelPath(modelSrc: unknown, progressCallback?: (progress: ModelProgressUpdate) => void, seed?: boolean, signal?: AbortSignal, hooks?: DownloadHooks, fallbackSrc?: string): Promise<string>;
|
|
14
|
-
export declare function resolveModelPathWithStats(modelSrc: unknown, progressCallback?: (progress: ModelProgressUpdate) => void, seed?: boolean, signal?: AbortSignal, hooks?: DownloadHooks, fallbackSrc?: string): Promise<ResolveResult>;
|
|
13
|
+
export declare function resolveModelPath(modelSrc: unknown, progressCallback?: (progress: ModelProgressUpdate) => void, seed?: boolean, signal?: AbortSignal, hooks?: DownloadHooks, fallbackSrc?: string, security?: DownloadSecurityOptions): Promise<string>;
|
|
14
|
+
export declare function resolveModelPathWithStats(modelSrc: unknown, progressCallback?: (progress: ModelProgressUpdate) => void, seed?: boolean, signal?: AbortSignal, hooks?: DownloadHooks, fallbackSrc?: string, security?: DownloadSecurityOptions): Promise<ResolveResult>;
|
|
15
15
|
export {};
|
|
@@ -3,11 +3,11 @@ import { hyperdriveUrlSchema, registryUrlSchema, SUPPORTED_ARCHIVE_EXTENSIONS, m
|
|
|
3
3
|
import { getModelsCacheDir, getShardedModelCacheDir, generateShortHash, extractAndValidateShardedArchive, measureChecksum } from '../../utils/index.js';
|
|
4
4
|
import { promises as fsPromises } from 'bare-fs';
|
|
5
5
|
import path from 'bare-path';
|
|
6
|
-
import { downloadModelFromHttp } from '
|
|
7
|
-
import { downloadModelFromHyperdrive } from '
|
|
8
|
-
import { downloadModelFromRegistry } from '
|
|
9
|
-
import { getExplicitRegistryMetadata } from '
|
|
10
|
-
import { downloadModelFromHttpWithStats, downloadModelFromHyperdriveWithStats, downloadModelFromRegistryWithStats } from '
|
|
6
|
+
import { downloadModelFromHttp } from './http.js';
|
|
7
|
+
import { downloadModelFromHyperdrive } from './hyperdrive.js';
|
|
8
|
+
import { downloadModelFromRegistry } from './registry.js';
|
|
9
|
+
import { getExplicitRegistryMetadata } from './registry-metadata.js';
|
|
10
|
+
import { downloadModelFromHttpWithStats, downloadModelFromHyperdriveWithStats, downloadModelFromRegistryWithStats } from './download-stats.js';
|
|
11
11
|
import { ChecksumValidationFailedError, DownloadCancelledError, InferenceCancelledError, ModelFileNotFoundError, ModelLoadFailedError, ModelNotFoundError, SeedingNotSupportedError } from '../../errors/index.js';
|
|
12
12
|
import { validateAndJoinPath } from '../../utils/path-security.js';
|
|
13
13
|
import { getEngineLogger } from '../../logging/index.js';
|
|
@@ -76,12 +76,12 @@ function buildResult(pathOrResult, sourceType) {
|
|
|
76
76
|
}
|
|
77
77
|
// A fallback is a non-P2P source: only HTTP URLs and file paths are valid.
|
|
78
78
|
// registry:// and pear:// are rejected.
|
|
79
|
-
export async function resolveFallbackModel(fallbackSrc, expectedChecksum, progressCallback, mode, signal, hooks) {
|
|
79
|
+
export async function resolveFallbackModel(fallbackSrc, expectedChecksum, progressCallback, mode, signal, hooks, security) {
|
|
80
80
|
if (fallbackSrc.startsWith('registry://') || fallbackSrc.startsWith('pear://')) {
|
|
81
81
|
throw new ModelLoadFailedError('fallbackSrc must be an HTTP URL or a local file path.');
|
|
82
82
|
}
|
|
83
83
|
// seed applies only to hyperdrive sources, which a fallback can never be.
|
|
84
|
-
const result = await resolveModelPathInner(fallbackSrc, progressCallback, false, mode, signal, hooks);
|
|
84
|
+
const result = await resolveModelPathInner(fallbackSrc, progressCallback, false, mode, signal, hooks, undefined, security);
|
|
85
85
|
// Report a missing fallback file as a not-found error before checksumming.
|
|
86
86
|
try {
|
|
87
87
|
await fsPromises.access(result.path);
|
|
@@ -124,7 +124,7 @@ export async function resolveRegistryModel(params) {
|
|
|
124
124
|
throw error;
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
async function resolveModelPathInner(modelSrc, progressCallback, seed, mode, signal, hooks, fallbackSrc) {
|
|
127
|
+
async function resolveModelPathInner(modelSrc, progressCallback, seed, mode, signal, hooks, fallbackSrc, security) {
|
|
128
128
|
if (signal?.aborted) {
|
|
129
129
|
throw new InferenceCancelledError(hooks?.requestBinding?.requestId ?? 'unknown');
|
|
130
130
|
}
|
|
@@ -180,7 +180,7 @@ async function resolveModelPathInner(modelSrc, progressCallback, seed, mode, sig
|
|
|
180
180
|
},
|
|
181
181
|
resolveFallback: () => {
|
|
182
182
|
logger.info(`Registry download failed for ${registryPath}; trying fallbackSrc: ${fallbackSrc}`);
|
|
183
|
-
return resolveFallbackModel(fallbackSrc, expectedChecksum, progressCallback, mode, signal, hooks);
|
|
183
|
+
return resolveFallbackModel(fallbackSrc, expectedChecksum, progressCallback, mode, signal, hooks, security);
|
|
184
184
|
},
|
|
185
185
|
buildUnreachableError: (cause) => new ModelLoadFailedError(`Could not download "${modelMetadata?.modelId}" from the registry on this network ` +
|
|
186
186
|
`(${cause instanceof Error ? cause.message : String(cause)}). ` +
|
|
@@ -192,12 +192,14 @@ async function resolveModelPathInner(modelSrc, progressCallback, seed, mode, sig
|
|
|
192
192
|
if (seed && !hyperdriveKey) {
|
|
193
193
|
throw new SeedingNotSupportedError();
|
|
194
194
|
}
|
|
195
|
-
// HTTP source
|
|
195
|
+
// HTTP source. Bring-your-own HTTP (any domain, plaintext included) is left
|
|
196
|
+
// as-is and unverified; Hugging Face downloads are verified against the Hub
|
|
197
|
+
// SHA-256 and their transport is hardened inside the download path.
|
|
196
198
|
if (actualModelSrc.startsWith('http://') || actualModelSrc.startsWith('https://')) {
|
|
197
199
|
logger.info(`Loading from HTTP URL: ${actualModelSrc}`);
|
|
198
200
|
const result = mode === 'stats'
|
|
199
|
-
? await downloadModelFromHttpWithStats(actualModelSrc, progressCallback, hooks)
|
|
200
|
-
: await downloadModelFromHttp(actualModelSrc, progressCallback, hooks);
|
|
201
|
+
? await downloadModelFromHttpWithStats(actualModelSrc, progressCallback, hooks, security)
|
|
202
|
+
: await downloadModelFromHttp(actualModelSrc, progressCallback, hooks, security);
|
|
201
203
|
logger.info(`Loaded Model to ${isDownloadResult(result) ? result.path : result}`);
|
|
202
204
|
return buildResult(result, 'http');
|
|
203
205
|
}
|
|
@@ -227,10 +229,10 @@ async function resolveModelPathInner(modelSrc, progressCallback, seed, mode, sig
|
|
|
227
229
|
}
|
|
228
230
|
return { path: resolvedPath, sourceType: 'filesystem' };
|
|
229
231
|
}
|
|
230
|
-
export async function resolveModelPath(modelSrc, progressCallback, seed, signal, hooks, fallbackSrc) {
|
|
231
|
-
const result = await resolveModelPathInner(modelSrc, progressCallback, seed, 'base', signal, hooks, fallbackSrc);
|
|
232
|
+
export async function resolveModelPath(modelSrc, progressCallback, seed, signal, hooks, fallbackSrc, security) {
|
|
233
|
+
const result = await resolveModelPathInner(modelSrc, progressCallback, seed, 'base', signal, hooks, fallbackSrc, security);
|
|
232
234
|
return result.path;
|
|
233
235
|
}
|
|
234
|
-
export async function resolveModelPathWithStats(modelSrc, progressCallback, seed, signal, hooks, fallbackSrc) {
|
|
235
|
-
return resolveModelPathInner(modelSrc, progressCallback, seed, 'stats', signal, hooks, fallbackSrc);
|
|
236
|
+
export async function resolveModelPathWithStats(modelSrc, progressCallback, seed, signal, hooks, fallbackSrc, security) {
|
|
237
|
+
return resolveModelPathInner(modelSrc, progressCallback, seed, 'stats', signal, hooks, fallbackSrc, security);
|
|
236
238
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Readable } from 'bare-stream';
|
|
2
|
+
import type { AbortSignal } from 'bare-abort-controller';
|
|
3
|
+
import { type HeaderBag } from '../../utils/url-security.js';
|
|
4
|
+
export interface SafeFetchResponse {
|
|
5
|
+
status: number;
|
|
6
|
+
statusText: string;
|
|
7
|
+
headers: HeaderBag;
|
|
8
|
+
/** Terminal response body. Consume or destroy it to free the socket. */
|
|
9
|
+
body: Readable;
|
|
10
|
+
/** URL of the final (non-redirect) response. */
|
|
11
|
+
finalUrl: string;
|
|
12
|
+
redirected: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* SHA-256 captured from a Hugging Face hop's `X-Linked-Etag`, if the chain
|
|
15
|
+
* passed through huggingface.co / hf.co and exposed a SHA-256-shaped hash.
|
|
16
|
+
*/
|
|
17
|
+
hubSha256?: string | undefined;
|
|
18
|
+
}
|
|
19
|
+
export interface SafeFetchOptions {
|
|
20
|
+
method?: 'GET' | 'HEAD';
|
|
21
|
+
headers?: Record<string, string>;
|
|
22
|
+
signal?: AbortSignal;
|
|
23
|
+
/** Per-hop connection timeout. */
|
|
24
|
+
timeoutMs?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Reject plaintext HTTP (non-loopback) and HTTPS→HTTP downgrade hops. Off by
|
|
27
|
+
* default: a bring-your-own HTTP server on any domain, plaintext included, is
|
|
28
|
+
* allowed. Callers turn this on for a strict, verified-only posture.
|
|
29
|
+
*/
|
|
30
|
+
enforceSecureTransport?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Which hop hosts are trusted to publish the integrity hash we read from
|
|
33
|
+
* `X-Linked-Etag`. Defaults to Hugging Face; overridable for tests.
|
|
34
|
+
*/
|
|
35
|
+
captureHashFromHost?: (host: string) => boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Fetch a model URL, walking redirects ourselves so every hop is checked:
|
|
39
|
+
* plaintext HTTP (non-loopback) and HTTPS→HTTP downgrades are refused before a
|
|
40
|
+
* request is issued to the insecure hop, and the Hugging Face Hub SHA-256 is
|
|
41
|
+
* captured from the pre-redirect resolve response (bare-fetch's auto-follow
|
|
42
|
+
* would discard it). The returned body is the terminal response stream.
|
|
43
|
+
*/
|
|
44
|
+
export declare function safeFetch(input: string, options?: SafeFetchOptions): Promise<SafeFetchResponse>;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import http from 'bare-http1';
|
|
2
|
+
import https from 'bare-https';
|
|
3
|
+
import { extractHubSha256, isHuggingFaceHost, isSecureDownloadUrl } from '../../utils/url-security.js';
|
|
4
|
+
import { DownloadCancelledError, InsecureModelSourceError } from '../../errors/index.js';
|
|
5
|
+
import { getEngineLogger } from '../../logging/index.js';
|
|
6
|
+
const logger = getEngineLogger();
|
|
7
|
+
const MAX_REDIRECTS = 20;
|
|
8
|
+
const REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);
|
|
9
|
+
function protocolFor(url) {
|
|
10
|
+
return url.protocol === 'https:' ? https : http;
|
|
11
|
+
}
|
|
12
|
+
function assertSecureHop(url, previous) {
|
|
13
|
+
if (isSecureDownloadUrl(url))
|
|
14
|
+
return;
|
|
15
|
+
const reason = previous
|
|
16
|
+
? `${previous.protocol}//${previous.host} redirected to plaintext HTTP, which is only allowed for loopback`
|
|
17
|
+
: 'plaintext HTTP is only allowed for loopback hosts';
|
|
18
|
+
throw new InsecureModelSourceError(url.href, reason);
|
|
19
|
+
}
|
|
20
|
+
// Issue a single request and resolve with the raw response (redirects NOT
|
|
21
|
+
// followed). Aborts on `signal` and destroys the socket on timeout so a stalled
|
|
22
|
+
// connect can't leak.
|
|
23
|
+
function requestOnce(url, method, headers, timeoutMs, signal) {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
const protocol = protocolFor(url);
|
|
26
|
+
let settled = false;
|
|
27
|
+
let timer;
|
|
28
|
+
const cleanup = () => {
|
|
29
|
+
if (timer)
|
|
30
|
+
clearTimeout(timer);
|
|
31
|
+
if (signal)
|
|
32
|
+
signal.removeEventListener('abort', onAbort);
|
|
33
|
+
};
|
|
34
|
+
const fail = (error) => {
|
|
35
|
+
if (settled)
|
|
36
|
+
return;
|
|
37
|
+
settled = true;
|
|
38
|
+
cleanup();
|
|
39
|
+
try {
|
|
40
|
+
req.destroy();
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
/* best effort */
|
|
44
|
+
}
|
|
45
|
+
reject(error);
|
|
46
|
+
};
|
|
47
|
+
const onAbort = () => fail(new DownloadCancelledError());
|
|
48
|
+
const req = protocol.request(url, { method, headers }, (res) => {
|
|
49
|
+
if (settled) {
|
|
50
|
+
res.destroy();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
settled = true;
|
|
54
|
+
cleanup();
|
|
55
|
+
resolve(res);
|
|
56
|
+
});
|
|
57
|
+
req.on('error', (error) => fail(error));
|
|
58
|
+
if (signal) {
|
|
59
|
+
if (signal.aborted) {
|
|
60
|
+
fail(new DownloadCancelledError());
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
64
|
+
}
|
|
65
|
+
if (timeoutMs !== undefined) {
|
|
66
|
+
timer = setTimeout(() => fail(new Error(`HTTP connection timeout after ${timeoutMs}ms`)), timeoutMs);
|
|
67
|
+
}
|
|
68
|
+
req.end();
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Fetch a model URL, walking redirects ourselves so every hop is checked:
|
|
73
|
+
* plaintext HTTP (non-loopback) and HTTPS→HTTP downgrades are refused before a
|
|
74
|
+
* request is issued to the insecure hop, and the Hugging Face Hub SHA-256 is
|
|
75
|
+
* captured from the pre-redirect resolve response (bare-fetch's auto-follow
|
|
76
|
+
* would discard it). The returned body is the terminal response stream.
|
|
77
|
+
*/
|
|
78
|
+
export async function safeFetch(input, options = {}) {
|
|
79
|
+
const method = options.method ?? 'GET';
|
|
80
|
+
const headers = { ...(options.headers ?? {}) };
|
|
81
|
+
const { signal, timeoutMs } = options;
|
|
82
|
+
const enforceSecureTransport = options.enforceSecureTransport ?? false;
|
|
83
|
+
const captureHashFromHost = options.captureHashFromHost ?? isHuggingFaceHost;
|
|
84
|
+
let current;
|
|
85
|
+
try {
|
|
86
|
+
current = new URL(input);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
throw new InsecureModelSourceError(input, 'invalid URL', error);
|
|
90
|
+
}
|
|
91
|
+
let previous = null;
|
|
92
|
+
let hubSha256;
|
|
93
|
+
let redirects = 0;
|
|
94
|
+
for (;;) {
|
|
95
|
+
if (signal?.aborted)
|
|
96
|
+
throw new DownloadCancelledError();
|
|
97
|
+
if (enforceSecureTransport)
|
|
98
|
+
assertSecureHop(current, previous);
|
|
99
|
+
const res = await requestOnce(current, method, headers, timeoutMs, signal);
|
|
100
|
+
if (hubSha256 === undefined && captureHashFromHost(current.hostname)) {
|
|
101
|
+
hubSha256 = extractHubSha256(res.headers);
|
|
102
|
+
}
|
|
103
|
+
const status = res.statusCode;
|
|
104
|
+
const location = res.headers['location'];
|
|
105
|
+
if (location !== undefined && REDIRECT_STATUSES.has(status)) {
|
|
106
|
+
// Drain the redirect body so the socket can be reused/closed.
|
|
107
|
+
res.resume();
|
|
108
|
+
if (redirects >= MAX_REDIRECTS) {
|
|
109
|
+
throw new InsecureModelSourceError(current.href, 'too many redirects');
|
|
110
|
+
}
|
|
111
|
+
redirects++;
|
|
112
|
+
let next;
|
|
113
|
+
try {
|
|
114
|
+
next = new URL(String(location), current);
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
throw new InsecureModelSourceError(current.href, 'invalid redirect location', error);
|
|
118
|
+
}
|
|
119
|
+
// Strip credentials when crossing origins.
|
|
120
|
+
if (next.protocol !== current.protocol || next.host !== current.host) {
|
|
121
|
+
delete headers['authorization'];
|
|
122
|
+
delete headers['Authorization'];
|
|
123
|
+
delete headers['cookie'];
|
|
124
|
+
delete headers['Cookie'];
|
|
125
|
+
}
|
|
126
|
+
previous = current;
|
|
127
|
+
current = next;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (hubSha256 === undefined && captureHashFromHost(previous?.hostname ?? current.hostname)) {
|
|
131
|
+
logger.debug('No Hub SHA-256 found in resolve headers', { url: current.href });
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
status,
|
|
135
|
+
statusText: res.statusMessage,
|
|
136
|
+
headers: res.headers,
|
|
137
|
+
body: res,
|
|
138
|
+
finalUrl: current.href,
|
|
139
|
+
redirected: redirects > 0,
|
|
140
|
+
hubSha256
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import type { SourceType } from '../../schemas/index.js';
|
|
2
2
|
import type { AbortSignal } from 'bare-abort-controller';
|
|
3
3
|
import type { DisposableScope } from '../../runtime/disposable-scope.js';
|
|
4
|
+
/**
|
|
5
|
+
* Per-call overrides for HTTP download security. Each field, when set, takes
|
|
6
|
+
* precedence over the engine config; when unset it falls back to the config
|
|
7
|
+
* value (default false).
|
|
8
|
+
*/
|
|
9
|
+
export interface DownloadSecurityOptions {
|
|
10
|
+
requireHttpChecksum?: boolean | undefined;
|
|
11
|
+
requireSecureTransport?: boolean | undefined;
|
|
12
|
+
}
|
|
4
13
|
export interface DownloadStats {
|
|
5
14
|
downloadTimeMs?: number;
|
|
6
15
|
totalBytesDownloaded?: number;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { getModelEntry } from '../runtime/model-registry.js';
|
|
2
2
|
import { getAllPlugins, getPlugin } from '../plugins/index.js';
|
|
3
3
|
import { profileReplyHandler, profileStreamHandler } from '../profiling/index.js';
|
|
4
|
-
import { ModelNotFoundError,
|
|
4
|
+
import { ModelNotFoundError, ModelOperationNotSupportedError, PluginNotFoundError, PluginHandlerTypeMismatchError } from '../errors/index.js';
|
|
5
5
|
function resolvePluginHandlerDef(modelId, handlerName) {
|
|
6
6
|
const entry = getModelEntry(modelId);
|
|
7
7
|
if (!entry) {
|
|
8
8
|
throw new ModelNotFoundError(modelId);
|
|
9
9
|
}
|
|
10
|
-
if (entry.isDelegated) {
|
|
11
|
-
throw new ModelIsDelegatedError(modelId);
|
|
12
|
-
}
|
|
13
10
|
const plugin = getPlugin(entry.local.modelType);
|
|
14
11
|
if (!plugin) {
|
|
15
12
|
throw new PluginNotFoundError(entry.local.modelType);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getModelEntry } from '../runtime/model-registry.js';
|
|
2
2
|
import { getPlugin, getPluginHandler } from '../plugins/index.js';
|
|
3
3
|
import { profileReplyHandler, profileStreamHandler } from '../profiling/index.js';
|
|
4
|
-
import { PluginNotFoundError, PluginHandlerNotFoundError, PluginHandlerTypeMismatchError, PluginRequestValidationFailedError, PluginResponseValidationFailedError,
|
|
4
|
+
import { PluginNotFoundError, PluginHandlerNotFoundError, PluginHandlerTypeMismatchError, PluginRequestValidationFailedError, PluginResponseValidationFailedError, ModelNotFoundError } from '../errors/index.js';
|
|
5
5
|
import { getEngineLogger } from '../logging/index.js';
|
|
6
6
|
import { formatZodError } from '../utils/zod-error.js';
|
|
7
7
|
const logger = getEngineLogger();
|
|
@@ -10,9 +10,6 @@ function resolvePluginHandler(modelId, handlerName) {
|
|
|
10
10
|
if (!modelEntry) {
|
|
11
11
|
throw new ModelNotFoundError(modelId);
|
|
12
12
|
}
|
|
13
|
-
if (modelEntry.isDelegated) {
|
|
14
|
-
throw new ModelIsDelegatedError(modelId);
|
|
15
|
-
}
|
|
16
13
|
const modelType = modelEntry.local.modelType;
|
|
17
14
|
const plugin = getPlugin(modelType);
|
|
18
15
|
if (!plugin) {
|
package/dist/handlers/types.d.ts
CHANGED
|
@@ -6,8 +6,6 @@ export type DuplexStreamHandler = (request: any, inputStream: any) => AsyncGener
|
|
|
6
6
|
export type HandlerEntry = {
|
|
7
7
|
type: 'reply' | 'stream' | 'duplex';
|
|
8
8
|
handler: ReplyHandler | StreamHandler | ProgressHandler | DuplexStreamHandler;
|
|
9
|
-
delegatedHandler?: ReplyHandler | StreamHandler | ProgressHandler | DuplexStreamHandler;
|
|
10
|
-
isDelegated?: (request: Request) => boolean;
|
|
11
9
|
supportsProgress?: boolean | ((request: Request) => boolean);
|
|
12
10
|
pluginOp?: boolean;
|
|
13
11
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { unloadModel } from '../plugins/ops/unload-model.js';
|
|
2
2
|
import { getRegistryStats } from '../runtime/model-registry.js';
|
|
3
|
-
import { hasActiveProviders } from '../p2p/swarm.js';
|
|
4
3
|
import { getEngineLogger } from '../logging/index.js';
|
|
5
4
|
const logger = getEngineLogger();
|
|
6
5
|
export async function handleUnloadModel(request) {
|
|
@@ -10,12 +9,10 @@ export async function handleUnloadModel(request) {
|
|
|
10
9
|
await unloadModel({ modelId, clearStorage });
|
|
11
10
|
const stats = getRegistryStats();
|
|
12
11
|
const modelsActive = stats.totalModels > 0;
|
|
13
|
-
const providersActive = hasActiveProviders();
|
|
14
12
|
return {
|
|
15
13
|
type: 'unloadModel',
|
|
16
14
|
success: true,
|
|
17
|
-
hasActiveModels: modelsActive
|
|
18
|
-
hasActiveProviders: providersActive
|
|
15
|
+
hasActiveModels: modelsActive
|
|
19
16
|
};
|
|
20
17
|
}
|
|
21
18
|
catch (error) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { batchCompletion, completion, deleteCache, loadModel, downloadAsset, heartbeat,
|
|
1
|
+
export { batchCompletion, completion, deleteCache, loadModel, downloadAsset, heartbeat, unloadModel, transcribe, transcribeStream, bciTranscribe, bciTranscribeStream, embed, finetune, translate, cancel, ragChunk, ragIngest, ragSaveEmbeddings, ragSearch, ragDeleteEmbeddings, ragReindex, ragListWorkspaces, ragCloseWorkspace, ragDeleteWorkspace, textToSpeech, textToSpeechStream, getModelInfo, getLoadedModelInfo, getSystemResources, assessModelFit, loggingStream, subscribeServerLogs, type ServerLogHandler, ocr, invokePlugin, invokePluginStream, diffusion, type DiffusionProgressTick, audioGen, classify, video, type VideoProgressTick, upscale, worldCreateScene, worldStep, type WorldStepResult, type WorldStepProgressTick, type WorldSceneResult, type WorldSceneResultWithPack, modelRegistryList, modelRegistrySearch, modelRegistryGetModel, type ModelRegistrySearchParams, suspend, resume, state, vla, vlaHparams, vlaSetEmbodiment, vlaPreprocessImage, vlaPadState, VLA_DEFAULT_IMAGE_SIZE, type FinetuneHandle } from './api/index.js';
|
|
2
2
|
export { close } from './dispatch.js';
|
|
3
3
|
export { plugins, registerPlugin, registerPlugins, getPlugin, hasPlugin, getAllPlugins, unregisterPlugin } from './plugins/index.js';
|
|
4
4
|
export * from './surface.js';
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Public API: the operations, engine lifecycle and explicit plugin assembly, and
|
|
3
3
|
// the value-clean surface (schemas / types / consts / errors / model registry)
|
|
4
4
|
// re-exported from `./surface`.
|
|
5
|
-
export { batchCompletion, completion, deleteCache, loadModel, downloadAsset, heartbeat,
|
|
5
|
+
export { batchCompletion, completion, deleteCache, loadModel, downloadAsset, heartbeat, unloadModel, transcribe, transcribeStream, bciTranscribe, bciTranscribeStream, embed, finetune, translate, cancel, ragChunk, ragIngest, ragSaveEmbeddings, ragSearch, ragDeleteEmbeddings, ragReindex, ragListWorkspaces, ragCloseWorkspace, ragDeleteWorkspace, textToSpeech, textToSpeechStream, getModelInfo, getLoadedModelInfo, getSystemResources, assessModelFit, loggingStream, subscribeServerLogs, ocr, invokePlugin, invokePluginStream, diffusion, audioGen, classify, video, upscale, worldCreateScene, worldStep, modelRegistryList, modelRegistrySearch, modelRegistryGetModel, suspend, resume, state, vla, vlaHparams, vlaSetEmbodiment, vlaPreprocessImage, vlaPadState, VLA_DEFAULT_IMAGE_SIZE } from './api/index.js';
|
|
6
6
|
// Engine lifecycle and explicit plugin assembly. No plugins are registered by
|
|
7
7
|
// default: an app assembles the engines it needs via `plugins([...])` or the
|
|
8
8
|
// `registerPlugin`/`registerPlugins` primitives, then calls the operations.
|
package/dist/logging/addon.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Logger } from '
|
|
1
|
+
import type { Logger } from './types.js';
|
|
2
2
|
export declare function registerAddonLogger(modelId: string, namespace: string, logger: Logger): void;
|
|
3
3
|
export declare function unregisterAddonLogger(modelId: string): void;
|
|
4
4
|
export declare function createAddonLoggerCallback(namespace: string): (priority: number, message: string) => void;
|
package/dist/logging/addon.js
CHANGED
package/dist/logging/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { getLogger, getEngineLogger, getAppLogger, createStreamLogger, setGlobalLogLevel, setGlobalConsoleOutput, registerLogger, unregisterLogger } from '
|
|
2
|
-
export type { Logger, LoggerOptions, LogTransport } from '
|
|
3
|
-
export { RAG_NAMESPACE, LOG_ID, ALL_LOG_ID, LOG_NAMESPACE, type AddonNamespace } from '
|
|
4
|
-
export { registerAddonLogger, unregisterAddonLogger, createAddonLoggerCallback, clearAllAddonLoggers } from '
|
|
5
|
-
export { summarizeRequest } from '
|
|
1
|
+
export { getLogger, getEngineLogger, getAppLogger, createStreamLogger, setGlobalLogLevel, setGlobalConsoleOutput, registerLogger, unregisterLogger } from './logger.js';
|
|
2
|
+
export type { Logger, LoggerOptions, LogTransport } from './types.js';
|
|
3
|
+
export { RAG_NAMESPACE, LOG_ID, ALL_LOG_ID, LOG_NAMESPACE, type AddonNamespace } from './namespaces.js';
|
|
4
|
+
export { registerAddonLogger, unregisterAddonLogger, createAddonLoggerCallback, clearAllAddonLoggers } from './addon.js';
|
|
5
|
+
export { summarizeRequest } from './utils.js';
|
package/dist/logging/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { getLogger, getEngineLogger, getAppLogger, createStreamLogger, setGlobalLogLevel, setGlobalConsoleOutput, registerLogger, unregisterLogger } from '
|
|
2
|
-
export { RAG_NAMESPACE, LOG_ID, ALL_LOG_ID, LOG_NAMESPACE } from '
|
|
3
|
-
export { registerAddonLogger, unregisterAddonLogger, createAddonLoggerCallback, clearAllAddonLoggers } from '
|
|
4
|
-
export { summarizeRequest } from '
|
|
1
|
+
export { getLogger, getEngineLogger, getAppLogger, createStreamLogger, setGlobalLogLevel, setGlobalConsoleOutput, registerLogger, unregisterLogger } from './logger.js';
|
|
2
|
+
export { RAG_NAMESPACE, LOG_ID, ALL_LOG_ID, LOG_NAMESPACE } from './namespaces.js';
|
|
3
|
+
export { registerAddonLogger, unregisterAddonLogger, createAddonLoggerCallback, clearAllAddonLoggers } from './addon.js';
|
|
4
|
+
export { summarizeRequest } from './utils.js';
|
package/dist/logging/logger.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type LogLevel } from '@qvac/logging';
|
|
2
|
-
import type { Logger, LoggerOptions } from '
|
|
2
|
+
import type { Logger, LoggerOptions } from './types.js';
|
|
3
3
|
export declare function registerLogger(logger: Logger): void;
|
|
4
4
|
export declare function unregisterLogger(logger: Logger): void;
|
|
5
5
|
export declare function setGlobalLogLevel(level: LogLevel): void;
|