@qvac/sdk 0.9.2 → 0.10.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 +15 -68
- package/dist/client/api/cancel.d.ts +1 -1
- package/dist/client/api/cancel.js +1 -1
- package/dist/client/api/completion-stream.d.ts +51 -12
- package/dist/client/api/completion-stream.js +129 -56
- package/dist/client/api/delete-cache.d.ts +1 -0
- package/dist/client/api/delete-cache.js +1 -0
- package/dist/client/api/diffusion.d.ts +17 -2
- package/dist/client/api/diffusion.js +21 -4
- package/dist/client/api/embed.d.ts +4 -0
- package/dist/client/api/finetune.d.ts +21 -0
- package/dist/client/api/get-loaded-model-info.d.ts +25 -0
- package/dist/client/api/get-loaded-model-info.js +36 -0
- package/dist/client/api/get-model-info.d.ts +9 -1
- package/dist/client/api/get-model-info.js +8 -0
- package/dist/client/api/heartbeat.d.ts +2 -2
- package/dist/client/api/heartbeat.js +2 -2
- package/dist/client/api/index.d.ts +3 -1
- package/dist/client/api/index.js +3 -1
- package/dist/client/api/invoke-plugin.d.ts +16 -0
- package/dist/client/api/invoke-plugin.js +16 -0
- package/dist/client/api/load-model.d.ts +36 -3
- package/dist/client/api/load-model.js +31 -10
- package/dist/client/api/provide.d.ts +11 -5
- package/dist/client/api/provide.js +11 -6
- package/dist/client/api/rag.d.ts +9 -0
- package/dist/client/api/rag.js +9 -0
- package/dist/client/api/registry.d.ts +26 -0
- package/dist/client/api/registry.js +26 -0
- package/dist/client/api/resume.d.ts +20 -4
- package/dist/client/api/resume.js +20 -4
- package/dist/client/api/state.d.ts +23 -0
- package/dist/client/api/state.js +29 -0
- package/dist/client/api/stop-provider.d.ts +11 -5
- package/dist/client/api/stop-provider.js +11 -5
- package/dist/client/api/suspend.d.ts +21 -3
- package/dist/client/api/suspend.js +21 -3
- package/dist/client/api/text-to-speech.d.ts +64 -6
- package/dist/client/api/text-to-speech.js +423 -47
- package/dist/client/api/transcribe.d.ts +29 -4
- package/dist/client/api/transcribe.js +86 -28
- package/dist/client/api/translate.d.ts +1 -0
- package/dist/client/api/translate.js +1 -0
- package/dist/client/rpc/bare-client.js +22 -1
- package/dist/client/rpc/expo-rpc-client.d.ts +1 -1
- package/dist/client/rpc/expo-rpc-client.js +96 -4
- package/dist/client/rpc/node-rpc-client.js +36 -0
- package/dist/examples/audio/mic-input.d.ts +9 -0
- package/dist/examples/audio/mic-input.js +111 -0
- package/dist/examples/completion-events.d.ts +18 -0
- package/dist/examples/completion-events.js +79 -0
- package/dist/examples/delegated-inference/composite.js +12 -18
- package/dist/examples/delegated-inference/consumer-profiled.js +4 -11
- package/dist/examples/delegated-inference/consumer.js +8 -13
- package/dist/examples/delegated-inference/provider.js +11 -16
- package/dist/examples/diffusion-flux2-klein-img2img.d.ts +2 -0
- package/dist/examples/diffusion-flux2-klein-img2img.js +60 -0
- package/dist/examples/diffusion-flux2-klein.js +1 -0
- package/dist/examples/diffusion-img2img.d.ts +2 -0
- package/dist/examples/diffusion-img2img.js +49 -0
- package/dist/examples/diffusion-txt2img.js +2 -1
- package/dist/examples/kv-cache-example.js +11 -12
- package/dist/examples/llamacpp-cache.d.ts +2 -0
- package/dist/examples/llamacpp-cache.js +107 -0
- package/dist/examples/llamacpp-dynamic-tools.d.ts +2 -0
- package/dist/examples/llamacpp-dynamic-tools.js +144 -0
- package/dist/examples/llamacpp-native-tools.js +2 -8
- package/dist/examples/llamacpp-structured-output.d.ts +2 -0
- package/dist/examples/llamacpp-structured-output.js +106 -0
- package/dist/examples/llamacpp-tools-pythonic.d.ts +2 -0
- package/dist/examples/llamacpp-tools-pythonic.js +69 -0
- package/dist/examples/plugins.js +4 -4
- package/dist/examples/suspend-resume.js +21 -4
- package/dist/examples/transcription/parakeet-microphone-record.js +6 -33
- package/dist/examples/transcription/whispercpp-filesystem-streaming.js +7 -5
- package/dist/examples/transcription/whispercpp-filesystem.js +12 -3
- package/dist/examples/transcription/whispercpp-microphone-record.js +6 -29
- package/dist/examples/translation/translation-stream.js +5 -5
- package/dist/examples/tts/llm-to-tts-streaming.d.ts +16 -0
- package/dist/examples/tts/llm-to-tts-streaming.js +143 -0
- package/dist/examples/tts/supertonic-multilingual.js +3 -3
- package/dist/examples/tts/supertonic.js +3 -3
- package/dist/examples/tts/utils.d.ts +11 -1
- package/dist/examples/tts/utils.js +70 -17
- package/dist/examples/voice-assistant/voice-assistant.d.ts +2 -0
- package/dist/examples/voice-assistant/voice-assistant.js +207 -0
- package/dist/expo/plugins/withMobileBundle.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/logging/logger.d.ts +11 -0
- package/dist/logging/logger.js +11 -0
- package/dist/logging/types.d.ts +18 -0
- package/dist/models/registry/models.d.ts +6620 -6185
- package/dist/models/registry/models.js +6296 -5318
- package/dist/models/update-models/codegen.js +84 -23
- package/dist/models/update-models/companions.d.ts +18 -0
- package/dist/models/update-models/companions.js +175 -0
- package/dist/models/update-models/naming.js +0 -25
- package/dist/models/update-models/registry.js +4 -2
- package/dist/models/update-models/types.d.ts +37 -9
- package/dist/profiling/index.d.ts +49 -0
- package/dist/profiling/index.js +49 -0
- package/dist/schemas/cancel.d.ts +6 -2
- package/dist/schemas/cancel.js +14 -7
- package/dist/schemas/common.d.ts +353 -271
- package/dist/schemas/common.js +26 -5
- package/dist/schemas/completion-event.d.ts +225 -0
- package/dist/schemas/completion-event.js +79 -0
- package/dist/schemas/completion-stream.d.ts +122 -31
- package/dist/schemas/completion-stream.js +137 -36
- package/dist/schemas/delegate.d.ts +0 -2
- package/dist/schemas/delegate.js +25 -6
- package/dist/schemas/download-asset.d.ts +5 -5
- package/dist/schemas/embed.js +21 -9
- package/dist/schemas/engine-addon-map.d.ts +11 -1
- package/dist/schemas/engine-addon-map.js +2 -2
- package/dist/schemas/get-loaded-model-info.d.ts +52 -0
- package/dist/schemas/get-loaded-model-info.js +44 -0
- package/dist/schemas/get-model-info.d.ts +2 -2
- package/dist/schemas/get-model-info.js +103 -32
- package/dist/schemas/heartbeat.d.ts +0 -1
- package/dist/schemas/index.d.ts +4 -1
- package/dist/schemas/index.js +4 -1
- package/dist/schemas/llamacpp-config.d.ts +14 -4
- package/dist/schemas/llamacpp-config.js +5 -0
- package/dist/schemas/load-model.d.ts +3233 -1260
- package/dist/schemas/load-model.js +23 -16
- package/dist/schemas/model-src-utils.d.ts +7 -6
- package/dist/schemas/model-src-utils.js +27 -1
- package/dist/schemas/model-types.d.ts +4 -4
- package/dist/schemas/ocr.d.ts +1 -1
- package/dist/schemas/plugin.d.ts +27 -3
- package/dist/schemas/plugin.js +27 -2
- package/dist/schemas/profiling.js +11 -3
- package/dist/schemas/provide.d.ts +1 -3
- package/dist/schemas/provide.js +0 -3
- package/dist/schemas/rag.d.ts +4 -4
- package/dist/schemas/registry.d.ts +10 -10
- package/dist/schemas/registry.js +36 -14
- package/dist/schemas/reload-config.d.ts +73 -7
- package/dist/schemas/sdcpp-config.d.ts +16 -8
- package/dist/schemas/sdcpp-config.js +118 -25
- package/dist/schemas/sdk-config.d.ts +116 -90
- package/dist/schemas/sdk-config.js +16 -0
- package/dist/schemas/sdk-errors-client.d.ts +3 -0
- package/dist/schemas/sdk-errors-client.js +16 -1
- package/dist/schemas/sdk-errors-server.d.ts +3 -0
- package/dist/schemas/sdk-errors-server.js +23 -0
- package/dist/schemas/state.d.ts +23 -0
- package/dist/schemas/state.js +14 -0
- package/dist/schemas/stop-provide.d.ts +0 -5
- package/dist/schemas/stop-provide.js +2 -6
- package/dist/schemas/text-to-speech.d.ts +93 -27
- package/dist/schemas/text-to-speech.js +27 -0
- package/dist/schemas/tools.d.ts +16 -0
- package/dist/schemas/tools.js +15 -0
- package/dist/schemas/transcription-config.d.ts +8 -8
- package/dist/schemas/transcription.d.ts +33 -0
- package/dist/schemas/transcription.js +9 -0
- package/dist/schemas/translate.js +59 -19
- package/dist/schemas/translation-config.d.ts +157 -133
- package/dist/schemas/translation-config.js +34 -11
- package/dist/server/bare/delegate-rpc-client.d.ts +1 -1
- package/dist/server/bare/delegate-rpc-client.js +131 -122
- package/dist/server/bare/hyperswarm.d.ts +2 -2
- package/dist/server/bare/hyperswarm.js +12 -7
- package/dist/server/bare/ops/cancel.js +7 -0
- package/dist/server/bare/ops/kv-cache-utils.d.ts +7 -10
- package/dist/server/bare/ops/kv-cache-utils.js +31 -40
- package/dist/server/bare/ops/load-model.js +0 -1
- package/dist/server/bare/ops/transcribe.d.ts +11 -4
- package/dist/server/bare/ops/transcribe.js +25 -4
- package/dist/server/bare/ops/translate.js +42 -4
- package/dist/server/bare/ops/unload-model.js +21 -19
- package/dist/server/bare/plugins/llamacpp-completion/ops/cache-logger.js +1 -2
- package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.d.ts +13 -8
- package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.js +257 -85
- package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-state.d.ts +101 -0
- package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-state.js +135 -0
- package/dist/server/bare/plugins/llamacpp-completion/plugin.d.ts +79 -22
- package/dist/server/bare/plugins/llamacpp-completion/plugin.js +57 -32
- package/dist/server/bare/plugins/llamacpp-embedding/plugin.js +10 -16
- package/dist/server/bare/plugins/nmtcpp-translation/plugin.d.ts +69 -44
- package/dist/server/bare/plugins/nmtcpp-translation/plugin.js +113 -94
- package/dist/server/bare/plugins/onnx-ocr/plugin.d.ts +1 -1
- package/dist/server/bare/plugins/onnx-ocr/plugin.js +1 -2
- package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech-stream.d.ts +7 -0
- package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech-stream.js +116 -0
- package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech.d.ts +2 -3
- package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech.js +71 -9
- package/dist/server/bare/plugins/onnx-tts/plugin.d.ts +41 -13
- package/dist/server/bare/plugins/onnx-tts/plugin.js +48 -3
- package/dist/server/bare/plugins/parakeet-transcription/plugin.d.ts +15 -7
- package/dist/server/bare/plugins/parakeet-transcription/plugin.js +5 -6
- package/dist/server/bare/plugins/sdcpp-generation/ops/diffusion.js +6 -0
- package/dist/server/bare/plugins/sdcpp-generation/plugin.d.ts +8 -5
- package/dist/server/bare/plugins/sdcpp-generation/plugin.js +13 -13
- package/dist/server/bare/plugins/whispercpp-transcription/plugin.d.ts +17 -1
- package/dist/server/bare/plugins/whispercpp-transcription/plugin.js +40 -17
- package/dist/server/bare/registry/config-registry.js +14 -3
- package/dist/server/bare/registry/model-registry.d.ts +8 -10
- package/dist/server/bare/registry/model-registry.js +17 -12
- package/dist/server/bare/registry/registry-client.js +79 -19
- package/dist/server/bare/runtime-lifecycle.d.ts +2 -1
- package/dist/server/bare/runtime-lifecycle.js +13 -2
- package/dist/server/bare/types/addon-responses.d.ts +8 -3
- package/dist/server/bare/utils/transcribe-metadata.d.ts +21 -0
- package/dist/server/bare/utils/transcribe-metadata.js +28 -0
- package/dist/server/bare/utils/tts-stats.d.ts +22 -0
- package/dist/server/bare/utils/tts-stats.js +10 -0
- package/dist/server/rpc/create-server.d.ts +4 -1
- package/dist/server/rpc/create-server.js +5 -1
- package/dist/server/rpc/delegate-transport.js +36 -29
- package/dist/server/rpc/handle-request.js +28 -3
- package/dist/server/rpc/handler-registry.js +7 -1
- package/dist/server/rpc/handler-utils.d.ts +5 -0
- package/dist/server/rpc/handler-utils.js +22 -0
- package/dist/server/rpc/handlers/cancel-delegated.js +3 -5
- package/dist/server/rpc/handlers/cancelHandler.js +4 -5
- package/dist/server/rpc/handlers/completion-stream-delegated.js +14 -5
- package/dist/server/rpc/handlers/delete-cache.js +8 -3
- package/dist/server/rpc/handlers/download-asset.js +3 -24
- package/dist/server/rpc/handlers/get-loaded-model-info.d.ts +3 -0
- package/dist/server/rpc/handlers/get-loaded-model-info.js +39 -0
- package/dist/server/rpc/handlers/get-model-info.js +93 -84
- package/dist/server/rpc/handlers/heartbeat-delegated.js +2 -2
- package/dist/server/rpc/handlers/index.d.ts +6 -0
- package/dist/server/rpc/handlers/index.js +6 -0
- package/dist/server/rpc/handlers/load-model/download-manager.d.ts +35 -9
- package/dist/server/rpc/handlers/load-model/download-manager.js +142 -38
- package/dist/server/rpc/handlers/load-model/download-stats.d.ts +5 -4
- package/dist/server/rpc/handlers/load-model/download-stats.js +49 -8
- package/dist/server/rpc/handlers/load-model/handler.js +31 -50
- package/dist/server/rpc/handlers/load-model/http.d.ts +2 -2
- package/dist/server/rpc/handlers/load-model/http.js +97 -142
- package/dist/server/rpc/handlers/load-model/hyperdrive.d.ts +2 -2
- package/dist/server/rpc/handlers/load-model/hyperdrive.js +55 -74
- package/dist/server/rpc/handlers/load-model/index.d.ts +0 -1
- package/dist/server/rpc/handlers/load-model/index.js +0 -1
- package/dist/server/rpc/handlers/load-model/registry-client-options.d.ts +27 -0
- package/dist/server/rpc/handlers/load-model/registry-client-options.js +19 -0
- package/dist/server/rpc/handlers/load-model/registry-companion-set.d.ts +22 -0
- package/dist/server/rpc/handlers/load-model/registry-companion-set.js +208 -0
- package/dist/server/rpc/handlers/load-model/registry-download-utils.d.ts +24 -0
- package/dist/server/rpc/handlers/load-model/registry-download-utils.js +114 -0
- package/dist/server/rpc/handlers/load-model/registry.d.ts +2 -20
- package/dist/server/rpc/handlers/load-model/registry.js +109 -381
- package/dist/server/rpc/handlers/load-model/resolve-session.d.ts +15 -0
- package/dist/server/rpc/handlers/load-model/resolve-session.js +61 -0
- package/dist/server/rpc/handlers/load-model/resolve.d.ts +3 -3
- package/dist/server/rpc/handlers/load-model/resolve.js +14 -23
- package/dist/server/rpc/handlers/load-model/types.d.ts +11 -4
- package/dist/server/rpc/handlers/load-model/types.js +28 -1
- package/dist/server/rpc/handlers/load-model-delegated.js +2 -4
- package/dist/server/rpc/handlers/plugin-dispatch.js +9 -5
- package/dist/server/rpc/handlers/plugin-invoke.js +1 -1
- package/dist/server/rpc/handlers/provideHandler/connection.js +13 -2
- package/dist/server/rpc/handlers/provideHandler/handler.js +42 -29
- package/dist/server/rpc/handlers/state.d.ts +3 -0
- package/dist/server/rpc/handlers/state.js +7 -0
- package/dist/server/rpc/handlers/stopProvideHandler.d.ts +2 -2
- package/dist/server/rpc/handlers/stopProvideHandler.js +12 -7
- package/dist/server/rpc/handlers/text-to-speech-stream.d.ts +3 -0
- package/dist/server/rpc/handlers/text-to-speech-stream.js +4 -0
- package/dist/server/rpc/handlers/unload-model-delegated.js +3 -3
- package/dist/server/rpc/profiling/operation-metrics.js +20 -0
- package/dist/server/rpc/rpc-utils.js +1 -1
- package/dist/server/rpc/transport-selector.d.ts +3 -0
- package/dist/server/rpc/transport-selector.js +18 -0
- package/dist/server/utils/cache/auto-history.d.ts +4 -0
- package/dist/server/utils/cache/auto-history.js +22 -0
- package/dist/server/utils/{cache.d.ts → cache/paths.d.ts} +22 -5
- package/dist/server/utils/{cache.js → cache/paths.js} +36 -20
- package/dist/server/utils/cache/types.d.ts +8 -0
- package/dist/server/utils/cache/types.js +1 -0
- package/dist/server/utils/checksum.d.ts +2 -2
- package/dist/server/utils/checksum.js +1 -1
- package/dist/server/utils/clear-storage.d.ts +5 -0
- package/dist/server/utils/clear-storage.js +17 -0
- package/dist/server/utils/completion-normalizer.d.ts +17 -0
- package/dist/server/utils/completion-normalizer.js +301 -0
- package/dist/server/utils/expand-gguf-shards.d.ts +3 -0
- package/dist/server/utils/expand-gguf-shards.js +22 -0
- package/dist/server/utils/formatting.js +1 -1
- package/dist/server/utils/index.d.ts +4 -2
- package/dist/server/utils/index.js +4 -2
- package/dist/server/utils/qvac-paths.d.ts +2 -0
- package/dist/server/utils/qvac-paths.js +5 -0
- package/dist/server/utils/response-format.d.ts +3 -0
- package/dist/server/utils/response-format.js +20 -0
- package/dist/server/utils/tool-integration.d.ts +15 -4
- package/dist/server/utils/tool-integration.js +21 -41
- package/dist/server/utils/tools/dialect.d.ts +8 -0
- package/dist/server/utils/tools/dialect.js +12 -0
- package/dist/server/utils/tools/index.d.ts +3 -0
- package/dist/server/utils/tools/index.js +2 -0
- package/dist/server/utils/tools/parser.d.ts +6 -0
- package/dist/server/utils/tools/parser.js +40 -0
- package/dist/server/utils/tools/parsers/hermes.d.ts +4 -0
- package/dist/server/utils/tools/parsers/hermes.js +100 -0
- package/dist/server/utils/tools/parsers/json.d.ts +6 -0
- package/dist/server/utils/tools/parsers/json.js +115 -0
- package/dist/server/utils/tools/parsers/pythonic.d.ts +4 -0
- package/dist/server/utils/tools/parsers/pythonic.js +267 -0
- package/dist/server/utils/tools/shared.d.ts +18 -0
- package/dist/server/utils/tools/shared.js +54 -0
- package/dist/server/utils/worker-lock.d.ts +3 -0
- package/dist/server/utils/worker-lock.js +67 -0
- package/dist/server/worker-core.d.ts +16 -1
- package/dist/server/worker-core.js +114 -14
- package/dist/utils/aggregate-events.d.ts +16 -0
- package/dist/utils/aggregate-events.js +52 -0
- package/dist/utils/cache-normalize.d.ts +10 -0
- package/dist/utils/cache-normalize.js +23 -0
- package/dist/utils/encoding.d.ts +8 -0
- package/dist/utils/encoding.js +13 -0
- package/dist/utils/errors-client.d.ts +12 -0
- package/dist/utils/errors-client.js +20 -0
- package/dist/utils/errors-server.d.ts +14 -0
- package/dist/utils/errors-server.js +31 -0
- package/dist/utils/load-model-validation.d.ts +7 -0
- package/dist/utils/load-model-validation.js +18 -0
- package/expo/plugins/patches/android-link.mjs +1 -1
- package/expo/plugins/patches/ios-link.mjs +1 -1
- package/package.json +14 -18
- package/dist/examples/translation/translation-opus.d.ts +0 -2
- package/dist/examples/translation/translation-opus.js +0 -33
- package/dist/server/bare/utils/loader-adapter.d.ts +0 -7
- package/dist/server/bare/utils/loader-adapter.js +0 -9
- package/dist/server/utils/model-path.d.ts +0 -5
- package/dist/server/utils/model-path.js +0 -7
- package/dist/server/utils/tool-parser.d.ts +0 -7
- package/dist/server/utils/tool-parser.js +0 -248
|
@@ -1,22 +1,4 @@
|
|
|
1
1
|
import type { ModelProgressUpdate } from "../../../../schemas/index";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Find companion ONNX data file in registry.
|
|
6
|
-
* ONNX models with external data may use either .onnx_data or .onnx.data.
|
|
7
|
-
*/
|
|
8
|
-
export declare function findOnnxCompanionDataFile(registryPath: string): RegistryItem | undefined;
|
|
9
|
-
/**
|
|
10
|
-
* Resolve the main ONNX registry path from a companion data registry path.
|
|
11
|
-
* Supports both .onnx_data and .onnx.data naming conventions.
|
|
12
|
-
*/
|
|
13
|
-
export declare function getPairedOnnxRegistryPath(registryPath: string): string | undefined;
|
|
14
|
-
/**
|
|
15
|
-
* Download a model from the QVAC Registry.
|
|
16
|
-
*
|
|
17
|
-
* For known models (present in models.ts), uses direct blob download which
|
|
18
|
-
* skips the registry metadata sync entirely. Falls back to metadata-based
|
|
19
|
-
* download for unknown models.
|
|
20
|
-
*/
|
|
21
|
-
export declare function downloadModelFromRegistry(registryPath: string, registrySource: string, progressCallback?: (progress: ModelProgressUpdate) => void, expectedChecksum?: string, hooks?: DownloadMetricsHooks): Promise<string>;
|
|
2
|
+
import type { DownloadHooks } from "./types";
|
|
3
|
+
export declare function downloadModelFromRegistry(registryPath: string, registrySource: string, progressCallback?: (progress: ModelProgressUpdate) => void, expectedChecksum?: string, hooks?: DownloadHooks): Promise<string>;
|
|
22
4
|
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -1,124 +1,14 @@
|
|
|
1
1
|
import { promises as fsPromises } from "bare-fs";
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { getModelsCacheDir, generateShortHash, detectShardedModel, getShardedModelCacheDir, getShardPath, getOnnxModelPath, measureChecksum, extractTensorsFromShards, calculatePercentage, } from "../../../utils/index.js";
|
|
2
|
+
import { generateShortHash, detectShardedModel, getShardedModelCacheDir, getShardPath, extractTensorsFromShards, calculatePercentage, } from "../../../utils/index.js";
|
|
3
|
+
import { getSingleFileCachePath } from "../../../utils/cache/paths.js";
|
|
5
4
|
import { getModelByPath } from "../../../../models/registry/index.js";
|
|
6
5
|
import { getRegistryClient } from "../../../bare/registry/registry-client.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
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
|
+
import { DownloadCancelledError, ModelNotFoundError, RegistryDownloadFailedError, } from "../../../../utils/errors-server.js";
|
|
9
10
|
import { getServerLogger } from "../../../../logging/index.js";
|
|
10
11
|
const logger = getServerLogger();
|
|
11
|
-
const REGISTRY_STREAM_TIMEOUT_MS = 60_000;
|
|
12
|
-
function buildBlobBinding(meta) {
|
|
13
|
-
return {
|
|
14
|
-
coreKey: meta.blobCoreKey,
|
|
15
|
-
blockOffset: meta.blobBlockOffset,
|
|
16
|
-
blockLength: meta.blobBlockLength,
|
|
17
|
-
byteOffset: meta.blobByteOffset,
|
|
18
|
-
byteLength: meta.expectedSize,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Validate a cached file against expected size and checksum.
|
|
23
|
-
*/
|
|
24
|
-
async function validateCachedFile(modelPath, modelFileName, expectedSize, expectedChecksum, hooks) {
|
|
25
|
-
try {
|
|
26
|
-
await fsPromises.access(modelPath);
|
|
27
|
-
const localStats = await fsPromises.stat(modelPath);
|
|
28
|
-
const localSize = localStats.size;
|
|
29
|
-
if (localSize === expectedSize) {
|
|
30
|
-
logger.info(`✅ Model cached with correct size: ${modelPath}`);
|
|
31
|
-
// Validate checksum if provided
|
|
32
|
-
if (expectedChecksum && expectedChecksum.length === 64) {
|
|
33
|
-
const checksum = await measureChecksum(modelPath, hooks);
|
|
34
|
-
if (checksum !== expectedChecksum) {
|
|
35
|
-
throw new ChecksumValidationFailedError(`${modelFileName}. Expected: ${expectedChecksum}. Actual: ${checksum}. File may be corrupted`);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
logger.info(`✅ Model already cached and validated: ${modelPath}`);
|
|
39
|
-
return modelPath;
|
|
40
|
-
}
|
|
41
|
-
// File exists but wrong size (incomplete/corrupted) - remove it
|
|
42
|
-
logger.warn(`🗑️ Removing incomplete cached file (expected ${expectedSize}, got ${localSize}): ${modelPath}`);
|
|
43
|
-
await fsPromises.unlink(modelPath);
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
if (error instanceof ChecksumValidationFailedError) {
|
|
48
|
-
// Corrupted file - remove it so next download starts fresh
|
|
49
|
-
logger.warn(`🗑️ Removing corrupted cached file: ${modelPath}`);
|
|
50
|
-
await fsPromises.unlink(modelPath).catch(() => { });
|
|
51
|
-
}
|
|
52
|
-
// File doesn't exist or was cleaned up - need to download
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Download a single file from the registry to filesystem.
|
|
58
|
-
* When blobBinding is provided, uses direct blob download (skips metadata sync).
|
|
59
|
-
* Otherwise falls back to metadata-based downloadModel.
|
|
60
|
-
*/
|
|
61
|
-
async function downloadSingleFileFromRegistry(registryPath, registrySource, modelPath, modelFileName, downloadKey, expectedSize, expectedChecksum, progressCallback, signal, blobBinding, hooks) {
|
|
62
|
-
if (signal?.aborted) {
|
|
63
|
-
throw new DownloadCancelledError();
|
|
64
|
-
}
|
|
65
|
-
const client = await getRegistryClient();
|
|
66
|
-
const dir = path.dirname(modelPath);
|
|
67
|
-
await fsPromises.mkdir(dir, { recursive: true });
|
|
68
|
-
// Adapt registry client's core.on("download") progress to SDK ModelProgressUpdate.
|
|
69
|
-
// This reports network-layer bytes, decoupled from disk I/O backpressure.
|
|
70
|
-
const onProgress = progressCallback
|
|
71
|
-
? (progress) => {
|
|
72
|
-
const total = progress.total || expectedSize || progress.downloaded;
|
|
73
|
-
progressCallback({
|
|
74
|
-
type: "modelProgress",
|
|
75
|
-
downloaded: progress.downloaded,
|
|
76
|
-
total,
|
|
77
|
-
percentage: total > 0
|
|
78
|
-
? calculatePercentage(progress.downloaded, total)
|
|
79
|
-
: 0,
|
|
80
|
-
downloadKey,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
: undefined;
|
|
84
|
-
const clientOptions = {
|
|
85
|
-
timeout: REGISTRY_STREAM_TIMEOUT_MS,
|
|
86
|
-
outputFile: modelPath,
|
|
87
|
-
...(onProgress && { onProgress }),
|
|
88
|
-
...(signal && { signal: signal }),
|
|
89
|
-
};
|
|
90
|
-
if (blobBinding) {
|
|
91
|
-
logger.info(`📥 Downloading blob directly: ${modelFileName}`);
|
|
92
|
-
await client.downloadBlob(blobBinding, clientOptions);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
logger.info(`📥 Downloading from registry: ${registryPath}`);
|
|
96
|
-
await client.downloadModel(registryPath, registrySource, clientOptions);
|
|
97
|
-
}
|
|
98
|
-
logger.info(`✅ Downloaded to ${modelPath}`);
|
|
99
|
-
const stats = await fsPromises.stat(modelPath);
|
|
100
|
-
if (expectedSize && stats.size !== expectedSize) {
|
|
101
|
-
await fsPromises.unlink(modelPath).catch(() => { });
|
|
102
|
-
throw new ChecksumValidationFailedError(`${modelFileName}. File size mismatch: expected ${expectedSize}, got ${stats.size}`);
|
|
103
|
-
}
|
|
104
|
-
if (expectedChecksum && expectedChecksum.length === 64) {
|
|
105
|
-
const checksum = await measureChecksum(modelPath, hooks);
|
|
106
|
-
if (checksum !== expectedChecksum) {
|
|
107
|
-
await fsPromises.unlink(modelPath);
|
|
108
|
-
throw new ChecksumValidationFailedError(`${modelFileName}. Expected: ${expectedChecksum}. Actual: ${checksum}`);
|
|
109
|
-
}
|
|
110
|
-
logger.info(`✅ Checksum validated for ${modelFileName}`);
|
|
111
|
-
}
|
|
112
|
-
if (progressCallback) {
|
|
113
|
-
progressCallback({
|
|
114
|
-
type: "modelProgress",
|
|
115
|
-
downloaded: stats.size,
|
|
116
|
-
total: stats.size,
|
|
117
|
-
percentage: 100,
|
|
118
|
-
downloadKey,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
12
|
/**
|
|
123
13
|
* Find all shards for a model using path prefix query.
|
|
124
14
|
*/
|
|
@@ -126,7 +16,7 @@ async function findModelShards(registryPath) {
|
|
|
126
16
|
const client = await getRegistryClient();
|
|
127
17
|
const shardInfo = detectShardedModel(registryPath.split("/").pop() || "");
|
|
128
18
|
if (!shardInfo.isSharded) {
|
|
129
|
-
throw new
|
|
19
|
+
throw new RegistryDownloadFailedError(`Not a sharded model path: ${registryPath}`);
|
|
130
20
|
}
|
|
131
21
|
const pathPrefix = registryPath.replace(/-\d{5}-of-\d{5}\./, ".");
|
|
132
22
|
const basePath = pathPrefix.substring(0, pathPrefix.lastIndexOf("."));
|
|
@@ -198,7 +88,7 @@ async function downloadShardedFilesFromRegistry(registryPath, registrySource, ca
|
|
|
198
88
|
}));
|
|
199
89
|
}
|
|
200
90
|
const shardDir = getShardedModelCacheDir(cacheKey);
|
|
201
|
-
const downloadKey = createRegistryDownloadKey(registryPath);
|
|
91
|
+
const downloadKey = createRegistryDownloadKey(registrySource, registryPath);
|
|
202
92
|
logger.info(`📥 Downloading sharded model: ${shards.length} shards to ${shardDir}`);
|
|
203
93
|
const overallTotal = shards.reduce((sum, s) => sum + s.size, 0);
|
|
204
94
|
let overallDownloaded = 0;
|
|
@@ -275,209 +165,35 @@ async function downloadShardedFilesFromRegistry(registryPath, registrySource, ca
|
|
|
275
165
|
}
|
|
276
166
|
return getShardPath(cacheKey, firstShardFilename);
|
|
277
167
|
}
|
|
278
|
-
/**
|
|
279
|
-
* Find companion ONNX data file in registry.
|
|
280
|
-
* ONNX models with external data may use either .onnx_data or .onnx.data.
|
|
281
|
-
*/
|
|
282
|
-
export function findOnnxCompanionDataFile(registryPath) {
|
|
283
|
-
if (!registryPath.endsWith(".onnx"))
|
|
284
|
-
return undefined;
|
|
285
|
-
return (getModelByPath(`${registryPath}_data`) ??
|
|
286
|
-
getModelByPath(`${registryPath}.data`));
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* Resolve the main ONNX registry path from a companion data registry path.
|
|
290
|
-
* Supports both .onnx_data and .onnx.data naming conventions.
|
|
291
|
-
*/
|
|
292
|
-
export function getPairedOnnxRegistryPath(registryPath) {
|
|
293
|
-
if (registryPath.endsWith(".onnx_data")) {
|
|
294
|
-
return registryPath.slice(0, -"_data".length);
|
|
295
|
-
}
|
|
296
|
-
if (registryPath.endsWith(".onnx.data")) {
|
|
297
|
-
return registryPath.slice(0, -".data".length);
|
|
298
|
-
}
|
|
299
|
-
return undefined;
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* Download ONNX model with companion data file from registry.
|
|
303
|
-
* Both files are placed in the same directory to satisfy ONNX Runtime requirements.
|
|
304
|
-
* When blob bindings are provided, uses direct blob download (skips metadata sync).
|
|
305
|
-
*/
|
|
306
|
-
async function downloadOnnxWithDataFromRegistry(registryPath, registrySource, companionDataFile, cacheKey, progressCallback, signal, mainBlobBinding, dataBlobBinding, hooks) {
|
|
307
|
-
if (signal?.aborted) {
|
|
308
|
-
throw new DownloadCancelledError();
|
|
309
|
-
}
|
|
310
|
-
const mainFilename = registryPath.split("/").pop() || registryPath;
|
|
311
|
-
const dataFilename = companionDataFile.registryPath.split("/").pop() || "";
|
|
312
|
-
const downloadKey = createRegistryDownloadKey(registryPath);
|
|
313
|
-
const mainModelMetadata = getModelByPath(registryPath);
|
|
314
|
-
const mainPath = getOnnxModelPath(cacheKey, mainFilename);
|
|
315
|
-
const dataPath = getOnnxModelPath(cacheKey, dataFilename);
|
|
316
|
-
logger.info(`📥 Downloading ONNX model with external data: ${mainFilename} + ${dataFilename}`);
|
|
317
|
-
const mainExpectedSize = mainModelMetadata?.expectedSize || 0;
|
|
318
|
-
const mainChecksum = mainModelMetadata?.sha256Checksum || "";
|
|
319
|
-
const dataExpectedSize = companionDataFile.expectedSize || 0;
|
|
320
|
-
const dataChecksum = companionDataFile.sha256Checksum || "";
|
|
321
|
-
const overallTotal = mainExpectedSize + dataExpectedSize;
|
|
322
|
-
let overallDownloaded = 0;
|
|
323
|
-
// Check if main file already cached
|
|
324
|
-
const cachedMainPath = await validateCachedFile(mainPath, mainFilename, mainExpectedSize, mainChecksum, hooks);
|
|
325
|
-
if (cachedMainPath) {
|
|
326
|
-
logger.info(`✅ Main ONNX file already cached: ${mainFilename}`);
|
|
327
|
-
overallDownloaded += mainExpectedSize;
|
|
328
|
-
}
|
|
329
|
-
else {
|
|
330
|
-
// Download main ONNX file
|
|
331
|
-
const mainProgressCallback = progressCallback
|
|
332
|
-
? (progress) => {
|
|
333
|
-
const currentOverall = overallDownloaded + progress.downloaded;
|
|
334
|
-
progressCallback({
|
|
335
|
-
...progress,
|
|
336
|
-
downloadKey,
|
|
337
|
-
onnxInfo: {
|
|
338
|
-
currentFile: mainFilename,
|
|
339
|
-
fileIndex: 1,
|
|
340
|
-
totalFiles: 2,
|
|
341
|
-
overallDownloaded: currentOverall,
|
|
342
|
-
overallTotal,
|
|
343
|
-
overallPercentage: calculatePercentage(currentOverall, overallTotal),
|
|
344
|
-
},
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
: undefined;
|
|
348
|
-
await downloadSingleFileFromRegistry(registryPath, registrySource, mainPath, mainFilename, downloadKey, mainExpectedSize, mainChecksum, mainProgressCallback, signal, mainBlobBinding, hooks);
|
|
349
|
-
overallDownloaded += mainExpectedSize;
|
|
350
|
-
logger.info(`✅ Main ONNX file downloaded: ${mainFilename}`);
|
|
351
|
-
}
|
|
352
|
-
// Check if data file already cached
|
|
353
|
-
const cachedDataPath = await validateCachedFile(dataPath, dataFilename, dataExpectedSize, dataChecksum, hooks);
|
|
354
|
-
if (cachedDataPath) {
|
|
355
|
-
logger.info(`✅ ONNX data file already cached: ${dataFilename}`);
|
|
356
|
-
overallDownloaded = overallTotal;
|
|
357
|
-
}
|
|
358
|
-
else {
|
|
359
|
-
// Download companion data file
|
|
360
|
-
const dataProgressCallback = progressCallback
|
|
361
|
-
? (progress) => {
|
|
362
|
-
const currentOverall = overallDownloaded + progress.downloaded;
|
|
363
|
-
progressCallback({
|
|
364
|
-
...progress,
|
|
365
|
-
downloadKey,
|
|
366
|
-
onnxInfo: {
|
|
367
|
-
currentFile: dataFilename,
|
|
368
|
-
fileIndex: 2,
|
|
369
|
-
totalFiles: 2,
|
|
370
|
-
overallDownloaded: currentOverall,
|
|
371
|
-
overallTotal,
|
|
372
|
-
overallPercentage: calculatePercentage(currentOverall, overallTotal),
|
|
373
|
-
},
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
: undefined;
|
|
377
|
-
await downloadSingleFileFromRegistry(companionDataFile.registryPath, companionDataFile.registrySource, dataPath, dataFilename, downloadKey, dataExpectedSize, dataChecksum, dataProgressCallback, signal, dataBlobBinding, hooks);
|
|
378
|
-
logger.info(`✅ ONNX data file downloaded: ${dataFilename}`);
|
|
379
|
-
}
|
|
380
|
-
// Send final 100% progress
|
|
381
|
-
if (progressCallback) {
|
|
382
|
-
progressCallback({
|
|
383
|
-
type: "modelProgress",
|
|
384
|
-
downloaded: overallTotal,
|
|
385
|
-
total: overallTotal,
|
|
386
|
-
percentage: 100,
|
|
387
|
-
downloadKey,
|
|
388
|
-
onnxInfo: {
|
|
389
|
-
currentFile: dataFilename,
|
|
390
|
-
fileIndex: 2,
|
|
391
|
-
totalFiles: 2,
|
|
392
|
-
overallDownloaded: overallTotal,
|
|
393
|
-
overallTotal,
|
|
394
|
-
overallPercentage: 100,
|
|
395
|
-
},
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
return mainPath;
|
|
399
|
-
}
|
|
400
|
-
/**
|
|
401
|
-
* Create a managed download with abort controller support.
|
|
402
|
-
*/
|
|
403
|
-
function createManagedDownload(downloadKey, registryPath, downloadFn, progressCallback) {
|
|
404
|
-
const abortController = new AbortController();
|
|
405
|
-
const downloadPromise = (async () => {
|
|
406
|
-
try {
|
|
407
|
-
return await downloadFn(abortController.signal);
|
|
408
|
-
}
|
|
409
|
-
finally {
|
|
410
|
-
unregisterDownload(downloadKey);
|
|
411
|
-
clearClearCacheFlag(downloadKey);
|
|
412
|
-
}
|
|
413
|
-
})();
|
|
414
|
-
const downloadEntry = {
|
|
415
|
-
key: downloadKey,
|
|
416
|
-
promise: downloadPromise,
|
|
417
|
-
abortController,
|
|
418
|
-
startTime: Date.now(),
|
|
419
|
-
type: "registry",
|
|
420
|
-
registryPath,
|
|
421
|
-
...(progressCallback && { onProgress: progressCallback }),
|
|
422
|
-
};
|
|
423
|
-
registerDownload(downloadKey, downloadEntry);
|
|
424
|
-
return downloadPromise;
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* Download a model from the QVAC Registry.
|
|
428
|
-
*
|
|
429
|
-
* For known models (present in models.ts), uses direct blob download which
|
|
430
|
-
* skips the registry metadata sync entirely. Falls back to metadata-based
|
|
431
|
-
* download for unknown models.
|
|
432
|
-
*/
|
|
433
168
|
export async function downloadModelFromRegistry(registryPath, registrySource, progressCallback, expectedChecksum, hooks) {
|
|
434
|
-
const downloadKey = createRegistryDownloadKey(registryPath);
|
|
435
|
-
|
|
436
|
-
const existing = getActiveDownload(downloadKey);
|
|
437
|
-
if (existing) {
|
|
438
|
-
logger.info(`📥 Reusing existing download for: ${downloadKey}`);
|
|
439
|
-
hooks?.markCacheMiss();
|
|
440
|
-
return existing.promise;
|
|
441
|
-
}
|
|
169
|
+
const downloadKey = createRegistryDownloadKey(registrySource, registryPath);
|
|
170
|
+
hooks?.onDownloadKey?.(downloadKey);
|
|
442
171
|
const filename = registryPath.split("/").pop() || registryPath;
|
|
443
172
|
const shardInfo = detectShardedModel(filename);
|
|
444
173
|
// Look up model metadata from our generated models.ts
|
|
445
174
|
const modelMetadata = getModelByPath(registryPath);
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
if (shardInfo.isSharded) {
|
|
461
|
-
const cacheKey = generateShortHash(registryPath);
|
|
462
|
-
const localShardMeta = modelMetadata?.shardMetadata;
|
|
463
|
-
// FS pre-check for known models: if all shards cached, return immediately
|
|
464
|
-
if (localShardMeta?.length) {
|
|
465
|
-
let allCached = true;
|
|
466
|
-
for (const shard of localShardMeta) {
|
|
467
|
-
const shardPath = getShardPath(cacheKey, shard.filename);
|
|
468
|
-
const cached = await validateCachedFile(shardPath, shard.filename, shard.expectedSize, shard.sha256Checksum, hooks);
|
|
469
|
-
if (!cached) {
|
|
470
|
-
allCached = false;
|
|
471
|
-
break;
|
|
175
|
+
const result = startOrJoinDownload(downloadKey, async (ctx) => {
|
|
176
|
+
if (shardInfo.isSharded) {
|
|
177
|
+
const cacheKey = generateShortHash(registryPath);
|
|
178
|
+
const localShardMeta = modelMetadata?.shardMetadata;
|
|
179
|
+
// FS pre-check for known models: if all shards cached, return immediately
|
|
180
|
+
if (localShardMeta?.length) {
|
|
181
|
+
let allCached = true;
|
|
182
|
+
for (const shard of localShardMeta) {
|
|
183
|
+
const shardPath = getShardPath(cacheKey, shard.filename);
|
|
184
|
+
const cached = await validateCachedFile(shardPath, shard.filename, shard.expectedSize, shard.sha256Checksum, hooks);
|
|
185
|
+
if (!cached) {
|
|
186
|
+
allCached = false;
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
472
189
|
}
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
if (progressCallback) {
|
|
190
|
+
if (allCached) {
|
|
191
|
+
const firstShardFilename = localShardMeta[0].filename;
|
|
192
|
+
logger.info(`✅ All ${localShardMeta.length} shards cached`);
|
|
193
|
+
hooks?.markCacheHit?.();
|
|
194
|
+
ctx.setCacheHit(true);
|
|
479
195
|
const overallTotal = localShardMeta.reduce((sum, s) => sum + s.expectedSize, 0);
|
|
480
|
-
|
|
196
|
+
ctx.broadcastProgress({
|
|
481
197
|
type: "modelProgress",
|
|
482
198
|
downloaded: overallTotal,
|
|
483
199
|
total: overallTotal,
|
|
@@ -492,84 +208,96 @@ export async function downloadModelFromRegistry(registryPath, registrySource, pr
|
|
|
492
208
|
overallPercentage: 100,
|
|
493
209
|
},
|
|
494
210
|
});
|
|
211
|
+
return getShardPath(cacheKey, firstShardFilename);
|
|
495
212
|
}
|
|
496
|
-
return getShardPath(cacheKey, firstShardFilename);
|
|
497
213
|
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
downloaded: total,
|
|
521
|
-
total,
|
|
522
|
-
percentage: 100,
|
|
523
|
-
downloadKey,
|
|
524
|
-
onnxInfo: {
|
|
525
|
-
currentFile: dataFilename,
|
|
526
|
-
fileIndex: 2,
|
|
527
|
-
totalFiles: 2,
|
|
528
|
-
overallDownloaded: total,
|
|
529
|
-
overallTotal: total,
|
|
530
|
-
overallPercentage: 100,
|
|
531
|
-
},
|
|
532
|
-
});
|
|
214
|
+
hooks?.markCacheMiss?.();
|
|
215
|
+
ctx.setCacheHit(false);
|
|
216
|
+
try {
|
|
217
|
+
return await downloadShardedFilesFromRegistry(registryPath, registrySource, cacheKey, ctx.broadcastProgress, ctx.signal, localShardMeta, hooks);
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
if (error instanceof DownloadCancelledError &&
|
|
221
|
+
ctx.shouldClearCache()) {
|
|
222
|
+
try {
|
|
223
|
+
await fsPromises.rm(getShardedModelCacheDir(cacheKey), {
|
|
224
|
+
recursive: true,
|
|
225
|
+
force: true,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
catch (cleanupError) {
|
|
229
|
+
logger.debug("Failed to delete shard cache dir during cleanup", {
|
|
230
|
+
cacheKey,
|
|
231
|
+
error: cleanupError,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
throw error;
|
|
533
236
|
}
|
|
534
|
-
return mainCached;
|
|
535
237
|
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
238
|
+
// Generic companion set via generated metadata
|
|
239
|
+
if (modelMetadata?.companionSet) {
|
|
240
|
+
const companionHooks = {
|
|
241
|
+
...hooks,
|
|
242
|
+
markCacheHit: () => {
|
|
243
|
+
hooks?.markCacheHit?.();
|
|
244
|
+
ctx.setCacheHit(true);
|
|
245
|
+
},
|
|
246
|
+
markCacheMiss: () => {
|
|
247
|
+
hooks?.markCacheMiss?.();
|
|
248
|
+
ctx.setCacheHit(false);
|
|
249
|
+
},
|
|
250
|
+
};
|
|
251
|
+
return await downloadCompanionSetFromRegistry({
|
|
252
|
+
companionSet: modelMetadata.companionSet,
|
|
253
|
+
downloadKey,
|
|
254
|
+
progressCallback: ctx.broadcastProgress,
|
|
255
|
+
signal: ctx.signal,
|
|
256
|
+
hooks: companionHooks,
|
|
257
|
+
shouldClearCache: ctx.shouldClearCache,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
const modelPath = getSingleFileCachePath(registryPath);
|
|
261
|
+
const expectedSize = modelMetadata?.expectedSize || 0;
|
|
262
|
+
const checksum = expectedChecksum || modelMetadata?.sha256Checksum || "";
|
|
263
|
+
const cachedPath = await validateCachedFile(modelPath, filename, expectedSize, checksum, hooks);
|
|
264
|
+
if (cachedPath) {
|
|
265
|
+
logger.info(`✅ Using cached model: ${cachedPath}`);
|
|
266
|
+
hooks?.markCacheHit?.();
|
|
267
|
+
ctx.setCacheHit(true);
|
|
268
|
+
ctx.broadcastProgress({
|
|
558
269
|
type: "modelProgress",
|
|
559
270
|
downloaded: expectedSize,
|
|
560
271
|
total: expectedSize,
|
|
561
272
|
percentage: 100,
|
|
562
273
|
downloadKey,
|
|
563
274
|
});
|
|
275
|
+
return cachedPath;
|
|
276
|
+
}
|
|
277
|
+
const blobBinding = modelMetadata
|
|
278
|
+
? buildBlobBinding(modelMetadata)
|
|
279
|
+
: undefined;
|
|
280
|
+
hooks?.markCacheMiss?.();
|
|
281
|
+
ctx.setCacheHit(false);
|
|
282
|
+
try {
|
|
283
|
+
await downloadSingleFileFromRegistry(registryPath, registrySource, modelPath, filename, downloadKey, expectedSize, checksum, ctx.broadcastProgress, ctx.signal, blobBinding, hooks);
|
|
284
|
+
}
|
|
285
|
+
catch (error) {
|
|
286
|
+
if (error instanceof DownloadCancelledError &&
|
|
287
|
+
ctx.shouldClearCache()) {
|
|
288
|
+
try {
|
|
289
|
+
await fsPromises.unlink(modelPath);
|
|
290
|
+
}
|
|
291
|
+
catch (cleanupError) {
|
|
292
|
+
logger.debug("Failed to delete model file during cleanup", {
|
|
293
|
+
path: modelPath,
|
|
294
|
+
error: cleanupError,
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
throw error;
|
|
564
299
|
}
|
|
565
|
-
return cachedPath;
|
|
566
|
-
}
|
|
567
|
-
const blobBinding = modelMetadata
|
|
568
|
-
? buildBlobBinding(modelMetadata)
|
|
569
|
-
: undefined;
|
|
570
|
-
hooks?.markCacheMiss();
|
|
571
|
-
return createManagedDownload(downloadKey, registryPath, async (signal) => {
|
|
572
|
-
await downloadSingleFileFromRegistry(registryPath, registrySource, modelPath, filename, downloadKey, expectedSize, checksum, progressCallback, signal, blobBinding, hooks);
|
|
573
300
|
return modelPath;
|
|
574
301
|
}, progressCallback);
|
|
302
|
+
return applyJoinedDownloadStats(result, hooks);
|
|
575
303
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ModelProgressUpdate, ResolveContext } from "../../../../schemas/index";
|
|
2
|
+
import type { ResolveResult } from "./types";
|
|
3
|
+
export interface ResolveSessionOptions {
|
|
4
|
+
progressCallback?: ((update: ModelProgressUpdate) => void) | undefined;
|
|
5
|
+
seed?: boolean | undefined;
|
|
6
|
+
profilingEnabled: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface ResolveSession {
|
|
9
|
+
resolvePrimaryModelPath(modelSrc: unknown): Promise<string>;
|
|
10
|
+
createResolveContext(modelSrc: string, modelType: string, modelName?: string): ResolveContext;
|
|
11
|
+
getAggregateResult(): ResolveResult | undefined;
|
|
12
|
+
cancelAll(): void;
|
|
13
|
+
}
|
|
14
|
+
export declare function createResolveSession(options: ResolveSessionOptions): ResolveSession;
|
|
15
|
+
//# sourceMappingURL=resolve-session.d.ts.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { resolveModelPath, resolveModelPathWithStats, } from "./resolve.js";
|
|
2
|
+
import { cancelTransfer } from "./download-manager.js";
|
|
3
|
+
import { mergeDownloadStats } from "./download-stats.js";
|
|
4
|
+
export function createResolveSession(options) {
|
|
5
|
+
const { progressCallback, seed, profilingEnabled } = options;
|
|
6
|
+
let primaryResult;
|
|
7
|
+
const resolveResults = [];
|
|
8
|
+
const activeDownloadKeys = new Set();
|
|
9
|
+
const downloadHooks = {
|
|
10
|
+
onDownloadKey(key) {
|
|
11
|
+
activeDownloadKeys.add(key);
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
async function resolvePrimaryModelPath(modelSrc) {
|
|
15
|
+
if (profilingEnabled) {
|
|
16
|
+
const result = await resolveModelPathWithStats(modelSrc, progressCallback, seed, downloadHooks);
|
|
17
|
+
primaryResult = result;
|
|
18
|
+
resolveResults.push(result);
|
|
19
|
+
return result.path;
|
|
20
|
+
}
|
|
21
|
+
return resolveModelPath(modelSrc, progressCallback, seed, downloadHooks);
|
|
22
|
+
}
|
|
23
|
+
async function resolveForPlugin(src) {
|
|
24
|
+
if (profilingEnabled) {
|
|
25
|
+
const result = await resolveModelPathWithStats(src, progressCallback, seed, downloadHooks);
|
|
26
|
+
resolveResults.push(result);
|
|
27
|
+
return result.path;
|
|
28
|
+
}
|
|
29
|
+
return resolveModelPath(src, progressCallback, seed, downloadHooks);
|
|
30
|
+
}
|
|
31
|
+
function createResolveContext(modelSrc, modelType, modelName) {
|
|
32
|
+
return {
|
|
33
|
+
resolveModelPath: resolveForPlugin,
|
|
34
|
+
modelSrc,
|
|
35
|
+
modelType,
|
|
36
|
+
...(modelName !== undefined && { modelName }),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function getAggregateResult() {
|
|
40
|
+
if (!profilingEnabled || resolveResults.length === 0)
|
|
41
|
+
return undefined;
|
|
42
|
+
const downloadStats = mergeDownloadStats(resolveResults);
|
|
43
|
+
return {
|
|
44
|
+
path: primaryResult?.path ?? resolveResults[0].path,
|
|
45
|
+
sourceType: primaryResult?.sourceType ?? resolveResults[0].sourceType,
|
|
46
|
+
...(downloadStats !== undefined && { downloadStats }),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function cancelAll() {
|
|
50
|
+
for (const key of activeDownloadKeys) {
|
|
51
|
+
cancelTransfer(key);
|
|
52
|
+
}
|
|
53
|
+
activeDownloadKeys.clear();
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
resolvePrimaryModelPath,
|
|
57
|
+
createResolveContext,
|
|
58
|
+
getAggregateResult,
|
|
59
|
+
cancelAll,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ModelProgressUpdate } from "../../../../schemas/index";
|
|
2
|
-
import type { ResolveResult } from "./types";
|
|
3
|
-
export declare function resolveModelPath(modelSrc: unknown, progressCallback?: (progress: ModelProgressUpdate) => void, seed?: boolean): Promise<string>;
|
|
4
|
-
export declare function resolveModelPathWithStats(modelSrc: unknown, progressCallback?: (progress: ModelProgressUpdate) => void, seed?: boolean): Promise<ResolveResult>;
|
|
2
|
+
import type { ResolveResult, DownloadHooks } from "./types";
|
|
3
|
+
export declare function resolveModelPath(modelSrc: unknown, progressCallback?: (progress: ModelProgressUpdate) => void, seed?: boolean, hooks?: DownloadHooks): Promise<string>;
|
|
4
|
+
export declare function resolveModelPathWithStats(modelSrc: unknown, progressCallback?: (progress: ModelProgressUpdate) => void, seed?: boolean, hooks?: DownloadHooks): Promise<ResolveResult>;
|
|
5
5
|
//# sourceMappingURL=resolve.d.ts.map
|