@qvac/sdk 0.9.1 → 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 +361 -279
- 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/finetune.d.ts +16 -16
- package/dist/schemas/finetune.js +8 -8
- 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 +83 -26
- 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 +15 -19
- 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,10 +1,9 @@
|
|
|
1
1
|
import { models } from "../../../models/registry/models.js";
|
|
2
2
|
import { getAllModelIds, getModelEntry, } from "../../bare/registry/model-registry.js";
|
|
3
|
-
import { getConfiguredCacheDir } from "../../bare/registry/config-registry.js";
|
|
4
3
|
import { generateShortHash } from "../../utils/index.js";
|
|
5
4
|
import { promises as fsPromises } from "bare-fs";
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
5
|
+
import { getShardPath, getModelsCacheDir, getSingleFileCachePath, } from "../../utils/cache/paths.js";
|
|
6
|
+
import { validateAndJoinPath } from "../../utils/path-security.js";
|
|
8
7
|
import { ModelNotFoundError } from "../../../utils/errors-server.js";
|
|
9
8
|
export async function handleGetModelInfo(request) {
|
|
10
9
|
const { name } = request;
|
|
@@ -15,16 +14,19 @@ export async function handleGetModelInfo(request) {
|
|
|
15
14
|
const cacheKey = generateShortHash(catalogEntry.registryPath);
|
|
16
15
|
const cacheStatus = catalogEntry.shardMetadata && catalogEntry.shardMetadata.length > 0
|
|
17
16
|
? await handleShardedModel(cacheKey, catalogEntry.shardMetadata)
|
|
18
|
-
:
|
|
19
|
-
|
|
17
|
+
: catalogEntry.companionSet
|
|
18
|
+
? await handleCompanionSetModel(catalogEntry.companionSet, catalogEntry.registryPath)
|
|
19
|
+
: await handleSingleFileModel(catalogEntry.registryPath, catalogEntry.expectedSize, catalogEntry.sha256Checksum);
|
|
20
|
+
const { cacheFiles, isCached, actualSize, cachedAt, primaryPath } = cacheStatus;
|
|
20
21
|
const loadedModelIds = getAllModelIds();
|
|
22
|
+
const matchPath = primaryPath ?? cacheFiles[0]?.path;
|
|
21
23
|
const loadedInstances = [];
|
|
22
24
|
for (const id of loadedModelIds) {
|
|
23
25
|
const entry = getModelEntry(id);
|
|
24
|
-
if (!entry
|
|
26
|
+
if (!entry || entry.isDelegated)
|
|
25
27
|
continue;
|
|
26
28
|
const matchesByName = entry.local.name && entry.local.name === name;
|
|
27
|
-
const matchesByPath =
|
|
29
|
+
const matchesByPath = !!matchPath && entry.local.path === matchPath;
|
|
28
30
|
if (matchesByName || matchesByPath) {
|
|
29
31
|
const instance = {
|
|
30
32
|
registryId: id,
|
|
@@ -63,55 +65,100 @@ export async function handleGetModelInfo(request) {
|
|
|
63
65
|
};
|
|
64
66
|
}
|
|
65
67
|
async function handleShardedModel(cacheKey, shardMetadata) {
|
|
68
|
+
const fileEntries = shardMetadata.map((s) => ({
|
|
69
|
+
filename: s.filename,
|
|
70
|
+
expectedSize: s.expectedSize,
|
|
71
|
+
sha256Checksum: s.sha256Checksum,
|
|
72
|
+
}));
|
|
73
|
+
const paths = shardMetadata.map((s) => getShardPath(cacheKey, s.filename));
|
|
74
|
+
return checkCacheStatus(fileEntries, paths);
|
|
75
|
+
}
|
|
76
|
+
async function handleCompanionSetModel(companionSet, primaryRegistryPath) {
|
|
77
|
+
const { setKey, primaryKey, files } = companionSet;
|
|
78
|
+
const baseCache = getModelsCacheDir();
|
|
79
|
+
const fileEntries = files.map((f) => ({
|
|
80
|
+
filename: f.targetName,
|
|
81
|
+
expectedSize: f.expectedSize,
|
|
82
|
+
sha256Checksum: f.sha256Checksum,
|
|
83
|
+
key: f.key,
|
|
84
|
+
}));
|
|
85
|
+
const canonicalPaths = files.map((f) => validateAndJoinPath(baseCache, "sets", setKey, f.targetName));
|
|
86
|
+
const canonicalResult = await checkCacheStatus(fileEntries, canonicalPaths, primaryKey);
|
|
87
|
+
if (canonicalResult.isCached)
|
|
88
|
+
return canonicalResult;
|
|
89
|
+
const isOnnxSet = files.some((f) => f.primary === true && f.targetName.endsWith(".onnx"));
|
|
90
|
+
if (isOnnxSet) {
|
|
91
|
+
const legacyCacheKey = generateShortHash(primaryRegistryPath);
|
|
92
|
+
const legacyPaths = files.map((f) => validateAndJoinPath(baseCache, "onnx", legacyCacheKey, f.targetName));
|
|
93
|
+
const legacyResult = await checkCacheStatus(fileEntries, legacyPaths, primaryKey);
|
|
94
|
+
if (legacyResult.isCached)
|
|
95
|
+
return legacyResult;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
// Legacy flat-cache compatibility for Bergamot-style companion sets.
|
|
99
|
+
// This is valid only for families whose runtime still works with explicit
|
|
100
|
+
// per-file absolute paths; it is not a generic rule for all companion sets.
|
|
101
|
+
const flatPaths = files.map((f) => getSingleFileCachePath(f.registryPath));
|
|
102
|
+
const flatResult = await checkCacheStatus(fileEntries, flatPaths, primaryKey);
|
|
103
|
+
if (flatResult.isCached)
|
|
104
|
+
return flatResult;
|
|
105
|
+
}
|
|
106
|
+
return canonicalResult;
|
|
107
|
+
}
|
|
108
|
+
async function checkCacheStatus(files, paths, primaryKey) {
|
|
66
109
|
const cacheFiles = [];
|
|
67
|
-
let
|
|
110
|
+
let allCached = true;
|
|
68
111
|
let totalActualSize = 0;
|
|
69
112
|
let latestCachedAt;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
let
|
|
113
|
+
let primaryPath;
|
|
114
|
+
for (let i = 0; i < files.length; i++) {
|
|
115
|
+
const file = files[i];
|
|
116
|
+
const filePath = paths[i];
|
|
117
|
+
let fileCached = false;
|
|
118
|
+
let fileActualSize;
|
|
119
|
+
let fileCachedAt;
|
|
75
120
|
try {
|
|
76
|
-
const stats = await fsPromises.stat(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
shardIsCached = stats.size === shard.expectedSize;
|
|
82
|
-
if (shardIsCached) {
|
|
83
|
-
totalActualSize += stats.size;
|
|
84
|
-
if (!latestCachedAt || stats.mtime > latestCachedAt) {
|
|
85
|
-
latestCachedAt = stats.mtime;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
allShardsCached = false;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
allShardsCached = false;
|
|
121
|
+
const stats = await fsPromises.stat(filePath);
|
|
122
|
+
if (stats.isFile()) {
|
|
123
|
+
fileActualSize = stats.size;
|
|
124
|
+
fileCachedAt = stats.mtime;
|
|
125
|
+
fileCached = stats.size === file.expectedSize;
|
|
94
126
|
}
|
|
95
127
|
}
|
|
96
128
|
catch {
|
|
97
|
-
|
|
98
|
-
|
|
129
|
+
// file does not exist
|
|
130
|
+
}
|
|
131
|
+
if (primaryKey && file.key === primaryKey) {
|
|
132
|
+
primaryPath = filePath;
|
|
133
|
+
}
|
|
134
|
+
if (fileCached) {
|
|
135
|
+
totalActualSize += fileActualSize;
|
|
136
|
+
if (!latestCachedAt || fileCachedAt > latestCachedAt) {
|
|
137
|
+
latestCachedAt = fileCachedAt;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
allCached = false;
|
|
99
142
|
}
|
|
100
143
|
cacheFiles.push({
|
|
101
|
-
filename:
|
|
102
|
-
path:
|
|
103
|
-
expectedSize:
|
|
104
|
-
sha256Checksum:
|
|
105
|
-
isCached:
|
|
106
|
-
actualSize:
|
|
107
|
-
cachedAt:
|
|
144
|
+
filename: file.filename,
|
|
145
|
+
path: filePath,
|
|
146
|
+
expectedSize: file.expectedSize,
|
|
147
|
+
sha256Checksum: file.sha256Checksum,
|
|
148
|
+
isCached: fileCached,
|
|
149
|
+
actualSize: fileActualSize,
|
|
150
|
+
cachedAt: fileCachedAt,
|
|
108
151
|
});
|
|
109
152
|
}
|
|
153
|
+
if (!primaryPath && cacheFiles.length > 0) {
|
|
154
|
+
primaryPath = cacheFiles[0].path;
|
|
155
|
+
}
|
|
110
156
|
const result = {
|
|
111
157
|
cacheFiles,
|
|
112
|
-
isCached:
|
|
158
|
+
isCached: allCached,
|
|
159
|
+
primaryPath,
|
|
113
160
|
};
|
|
114
|
-
if (
|
|
161
|
+
if (allCached) {
|
|
115
162
|
result.actualSize = totalActualSize;
|
|
116
163
|
if (latestCachedAt) {
|
|
117
164
|
result.cachedAt = latestCachedAt;
|
|
@@ -119,46 +166,8 @@ async function handleShardedModel(cacheKey, shardMetadata) {
|
|
|
119
166
|
}
|
|
120
167
|
return result;
|
|
121
168
|
}
|
|
122
|
-
async function handleSingleFileModel(registryPath,
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const filePath = path.join(cacheDir, `${sourceHash}_${modelId}`);
|
|
127
|
-
let fileIsCached = false;
|
|
128
|
-
let fileActualSize;
|
|
129
|
-
let fileCachedAt;
|
|
130
|
-
try {
|
|
131
|
-
const stats = await fsPromises.stat(filePath);
|
|
132
|
-
const fileExists = stats.isFile();
|
|
133
|
-
if (fileExists) {
|
|
134
|
-
fileActualSize = stats.size;
|
|
135
|
-
fileCachedAt = stats.mtime;
|
|
136
|
-
fileIsCached = stats.size === expectedSize;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
catch {
|
|
140
|
-
fileIsCached = false;
|
|
141
|
-
}
|
|
142
|
-
const cacheFiles = [
|
|
143
|
-
{
|
|
144
|
-
filename: modelId,
|
|
145
|
-
path: filePath,
|
|
146
|
-
expectedSize,
|
|
147
|
-
sha256Checksum,
|
|
148
|
-
isCached: fileIsCached,
|
|
149
|
-
actualSize: fileActualSize,
|
|
150
|
-
cachedAt: fileCachedAt,
|
|
151
|
-
},
|
|
152
|
-
];
|
|
153
|
-
const result = {
|
|
154
|
-
cacheFiles,
|
|
155
|
-
isCached: fileIsCached,
|
|
156
|
-
};
|
|
157
|
-
if (fileActualSize !== undefined) {
|
|
158
|
-
result.actualSize = fileActualSize;
|
|
159
|
-
}
|
|
160
|
-
if (fileCachedAt !== undefined) {
|
|
161
|
-
result.cachedAt = fileCachedAt;
|
|
162
|
-
}
|
|
163
|
-
return result;
|
|
169
|
+
async function handleSingleFileModel(registryPath, expectedSize, sha256Checksum) {
|
|
170
|
+
const filename = registryPath.split("/").pop() || registryPath;
|
|
171
|
+
const filePath = getSingleFileCachePath(registryPath);
|
|
172
|
+
return checkCacheStatus([{ filename, expectedSize, sha256Checksum }], [filePath]);
|
|
164
173
|
}
|
|
@@ -8,9 +8,9 @@ export async function handleHeartbeatDelegated(request, options) {
|
|
|
8
8
|
if (!delegate) {
|
|
9
9
|
throw new DelegateConnectionFailedError("Delegated heartbeat handler called without delegate info");
|
|
10
10
|
}
|
|
11
|
-
const {
|
|
11
|
+
const { providerPublicKey, timeout } = delegate;
|
|
12
12
|
try {
|
|
13
|
-
const rpc = await getRPC(
|
|
13
|
+
const rpc = await getRPC(providerPublicKey, { timeout });
|
|
14
14
|
const delegateOpts = {
|
|
15
15
|
peerKey: providerPublicKey,
|
|
16
16
|
};
|
|
@@ -13,7 +13,9 @@ import { handleRag } from "./rag";
|
|
|
13
13
|
import { cancelHandler } from "./cancelHandler";
|
|
14
14
|
import { handleDeleteCache } from "./delete-cache";
|
|
15
15
|
import { handleTextToSpeech } from "./text-to-speech";
|
|
16
|
+
import { handleTextToSpeechStream } from "./text-to-speech-stream";
|
|
16
17
|
import { handleGetModelInfo } from "./get-model-info";
|
|
18
|
+
import { handleGetLoadedModelInfo } from "./get-loaded-model-info";
|
|
17
19
|
import { handleFinetune } from "./finetune";
|
|
18
20
|
import { handleOCRStream } from "./ocr-stream";
|
|
19
21
|
import { handleHeartbeat } from "./heartbeat";
|
|
@@ -22,6 +24,7 @@ import { handlePluginInvoke, handlePluginInvokeStream } from "./plugin-invoke";
|
|
|
22
24
|
import { handleModelRegistryList, handleModelRegistrySearch, handleModelRegistryGetModel } from "./registry";
|
|
23
25
|
import { handleSuspend } from "./suspend";
|
|
24
26
|
import { handleResume } from "./resume";
|
|
27
|
+
import { handleState } from "./state";
|
|
25
28
|
export declare const handlers: {
|
|
26
29
|
heartbeat: typeof handleHeartbeat;
|
|
27
30
|
completionStream: typeof handleCompletionStream;
|
|
@@ -39,7 +42,9 @@ export declare const handlers: {
|
|
|
39
42
|
rag: typeof handleRag;
|
|
40
43
|
cancel: typeof cancelHandler;
|
|
41
44
|
textToSpeech: typeof handleTextToSpeech;
|
|
45
|
+
textToSpeechStream: typeof handleTextToSpeechStream;
|
|
42
46
|
getModelInfo: typeof handleGetModelInfo;
|
|
47
|
+
getLoadedModelInfo: typeof handleGetLoadedModelInfo;
|
|
43
48
|
finetune: typeof handleFinetune;
|
|
44
49
|
ocrStream: typeof handleOCRStream;
|
|
45
50
|
diffusionStream: typeof handleDiffusionStream;
|
|
@@ -50,5 +55,6 @@ export declare const handlers: {
|
|
|
50
55
|
modelRegistryGetModel: typeof handleModelRegistryGetModel;
|
|
51
56
|
suspend: typeof handleSuspend;
|
|
52
57
|
resume: typeof handleResume;
|
|
58
|
+
state: typeof handleState;
|
|
53
59
|
};
|
|
54
60
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -13,7 +13,9 @@ import { handleRag } from "./rag.js";
|
|
|
13
13
|
import { cancelHandler } from "./cancelHandler.js";
|
|
14
14
|
import { handleDeleteCache } from "./delete-cache.js";
|
|
15
15
|
import { handleTextToSpeech } from "./text-to-speech.js";
|
|
16
|
+
import { handleTextToSpeechStream } from "./text-to-speech-stream.js";
|
|
16
17
|
import { handleGetModelInfo } from "./get-model-info.js";
|
|
18
|
+
import { handleGetLoadedModelInfo } from "./get-loaded-model-info.js";
|
|
17
19
|
import { handleFinetune } from "./finetune.js";
|
|
18
20
|
import { handleOCRStream } from "./ocr-stream.js";
|
|
19
21
|
import { handleHeartbeat } from "./heartbeat.js";
|
|
@@ -22,6 +24,7 @@ import { handlePluginInvoke, handlePluginInvokeStream } from "./plugin-invoke.js
|
|
|
22
24
|
import { handleModelRegistryList, handleModelRegistrySearch, handleModelRegistryGetModel, } from "./registry.js";
|
|
23
25
|
import { handleSuspend } from "./suspend.js";
|
|
24
26
|
import { handleResume } from "./resume.js";
|
|
27
|
+
import { handleState } from "./state.js";
|
|
25
28
|
export const handlers = {
|
|
26
29
|
heartbeat: handleHeartbeat,
|
|
27
30
|
completionStream: handleCompletionStream,
|
|
@@ -39,7 +42,9 @@ export const handlers = {
|
|
|
39
42
|
rag: handleRag,
|
|
40
43
|
cancel: cancelHandler,
|
|
41
44
|
textToSpeech: handleTextToSpeech,
|
|
45
|
+
textToSpeechStream: handleTextToSpeechStream,
|
|
42
46
|
getModelInfo: handleGetModelInfo,
|
|
47
|
+
getLoadedModelInfo: handleGetLoadedModelInfo,
|
|
43
48
|
finetune: handleFinetune,
|
|
44
49
|
ocrStream: handleOCRStream,
|
|
45
50
|
diffusionStream: handleDiffusionStream,
|
|
@@ -50,4 +55,5 @@ export const handlers = {
|
|
|
50
55
|
modelRegistryGetModel: handleModelRegistryGetModel,
|
|
51
56
|
suspend: handleSuspend,
|
|
52
57
|
resume: handleResume,
|
|
58
|
+
state: handleState,
|
|
53
59
|
};
|
|
@@ -1,14 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
1
|
+
import type { ModelProgressUpdate } from "../../../../schemas/index";
|
|
2
|
+
import { AbortController } from "bare-abort-controller";
|
|
3
|
+
import type { DownloadHooks } from "./types";
|
|
4
|
+
export interface Subscriber {
|
|
5
|
+
id: string;
|
|
6
|
+
onProgress?: ((progress: ModelProgressUpdate) => void) | undefined;
|
|
7
|
+
settled: boolean;
|
|
8
|
+
resolve: (path: string) => void;
|
|
9
|
+
reject: (error: unknown) => void;
|
|
10
|
+
promise: Promise<string>;
|
|
11
|
+
}
|
|
12
|
+
export interface Transfer {
|
|
13
|
+
downloadKey: string;
|
|
14
|
+
abortController: AbortController;
|
|
15
|
+
subscribers: Map<string, Subscriber>;
|
|
16
|
+
lastProgress?: ModelProgressUpdate | undefined;
|
|
17
|
+
downloadPromise?: Promise<string> | undefined;
|
|
18
|
+
clearCache: boolean;
|
|
19
|
+
cacheHit?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface DownloadContext {
|
|
22
|
+
broadcastProgress: (progress: ModelProgressUpdate) => void;
|
|
23
|
+
signal: AbortSignal;
|
|
24
|
+
shouldClearCache: () => boolean;
|
|
25
|
+
setCacheHit: (cacheHit: boolean) => void;
|
|
26
|
+
}
|
|
27
|
+
export interface StartOrJoinResult {
|
|
28
|
+
promise: Promise<string>;
|
|
29
|
+
joined: boolean;
|
|
30
|
+
getCacheHit: () => boolean | undefined;
|
|
31
|
+
}
|
|
32
|
+
export declare function startOrJoinDownload(downloadKey: string, startDownload: (ctx: DownloadContext) => Promise<string>, onProgress?: (progress: ModelProgressUpdate) => void): StartOrJoinResult;
|
|
33
|
+
export declare function cancelTransfer(downloadKey: string, clearCache?: boolean): void;
|
|
5
34
|
export declare function createHyperdriveDownloadKey(hyperdriveKey: string, modelFileName: string): string;
|
|
6
35
|
export declare function createHttpDownloadKey(url: string): string;
|
|
7
|
-
export declare function createRegistryDownloadKey(registryPath: string): string;
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function shouldClearCache(downloadKey: string): boolean;
|
|
10
|
-
export declare function clearClearCacheFlag(downloadKey: string): void;
|
|
11
|
-
export declare function createCancelFunction(downloadKey: string, clearCache?: boolean): () => void;
|
|
36
|
+
export declare function createRegistryDownloadKey(registrySource: string, registryPath: string): string;
|
|
37
|
+
export declare function applyJoinedDownloadStats(result: StartOrJoinResult, hooks?: DownloadHooks): Promise<string>;
|
|
12
38
|
export declare function cancelAllDownloads(): void;
|
|
13
39
|
export declare function cleanupDownloads(): Promise<void>;
|
|
14
40
|
//# sourceMappingURL=download-manager.d.ts.map
|
|
@@ -1,16 +1,124 @@
|
|
|
1
|
-
import {} from "
|
|
1
|
+
import { AbortController } from "bare-abort-controller";
|
|
2
|
+
import { DownloadCancelledError } from "../../../../utils/errors-server.js";
|
|
2
3
|
import { getServerLogger } from "../../../../logging/index.js";
|
|
3
4
|
const logger = getServerLogger();
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const activeTransfers = new Map();
|
|
6
|
+
let nextSubscriberId = 0;
|
|
7
|
+
function createSubscriber(onProgress) {
|
|
8
|
+
let resolve;
|
|
9
|
+
let reject;
|
|
10
|
+
const promise = new Promise((res, rej) => {
|
|
11
|
+
resolve = res;
|
|
12
|
+
reject = rej;
|
|
13
|
+
});
|
|
14
|
+
return {
|
|
15
|
+
id: String(nextSubscriberId++),
|
|
16
|
+
onProgress,
|
|
17
|
+
settled: false,
|
|
18
|
+
resolve,
|
|
19
|
+
reject,
|
|
20
|
+
promise,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function settleSubscriber(subscriber, result) {
|
|
24
|
+
if (subscriber.settled)
|
|
25
|
+
return;
|
|
26
|
+
subscriber.settled = true;
|
|
27
|
+
if (result instanceof Error) {
|
|
28
|
+
subscriber.reject(result);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
subscriber.resolve(result);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function deliverProgress(transfer, subscriber, progress) {
|
|
35
|
+
if (subscriber.settled || !subscriber.onProgress)
|
|
36
|
+
return;
|
|
37
|
+
try {
|
|
38
|
+
subscriber.onProgress(progress);
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
42
|
+
logger.warn("Progress callback threw; detaching subscriber", {
|
|
43
|
+
downloadKey: transfer.downloadKey,
|
|
44
|
+
subscriberId: subscriber.id,
|
|
45
|
+
error,
|
|
46
|
+
});
|
|
47
|
+
settleSubscriber(subscriber, error);
|
|
48
|
+
transfer.subscribers.delete(subscriber.id);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function broadcastTransferProgress(transfer, progress) {
|
|
52
|
+
transfer.lastProgress = progress;
|
|
53
|
+
for (const sub of Array.from(transfer.subscribers.values())) {
|
|
54
|
+
deliverProgress(transfer, sub, progress);
|
|
55
|
+
}
|
|
8
56
|
}
|
|
9
|
-
export function
|
|
10
|
-
|
|
57
|
+
export function startOrJoinDownload(downloadKey, startDownload, onProgress) {
|
|
58
|
+
const existing = activeTransfers.get(downloadKey);
|
|
59
|
+
if (existing && !existing.abortController.signal.aborted) {
|
|
60
|
+
logger.info(`📥 Reusing existing download for: ${downloadKey}`);
|
|
61
|
+
const subscriber = createSubscriber(onProgress);
|
|
62
|
+
existing.subscribers.set(subscriber.id, subscriber);
|
|
63
|
+
if (existing.lastProgress) {
|
|
64
|
+
deliverProgress(existing, subscriber, existing.lastProgress);
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
promise: subscriber.promise,
|
|
68
|
+
joined: true,
|
|
69
|
+
getCacheHit: () => existing.cacheHit,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const abortController = new AbortController();
|
|
73
|
+
const transfer = {
|
|
74
|
+
downloadKey,
|
|
75
|
+
abortController,
|
|
76
|
+
subscribers: new Map(),
|
|
77
|
+
clearCache: false,
|
|
78
|
+
};
|
|
79
|
+
const initialSubscriber = createSubscriber(onProgress);
|
|
80
|
+
transfer.subscribers.set(initialSubscriber.id, initialSubscriber);
|
|
81
|
+
activeTransfers.set(downloadKey, transfer);
|
|
82
|
+
const downloadPromise = startDownload({
|
|
83
|
+
broadcastProgress: (progress) => {
|
|
84
|
+
broadcastTransferProgress(transfer, progress);
|
|
85
|
+
},
|
|
86
|
+
signal: abortController.signal,
|
|
87
|
+
shouldClearCache: () => transfer.clearCache,
|
|
88
|
+
setCacheHit: (cacheHit) => {
|
|
89
|
+
transfer.cacheHit = cacheHit;
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
transfer.downloadPromise = downloadPromise;
|
|
93
|
+
downloadPromise.then((path) => {
|
|
94
|
+
for (const sub of transfer.subscribers.values()) {
|
|
95
|
+
settleSubscriber(sub, path);
|
|
96
|
+
}
|
|
97
|
+
}, (error) => {
|
|
98
|
+
const rejection = error instanceof Error ? error : new Error(String(error));
|
|
99
|
+
for (const sub of transfer.subscribers.values()) {
|
|
100
|
+
settleSubscriber(sub, rejection);
|
|
101
|
+
}
|
|
102
|
+
}).finally(() => {
|
|
103
|
+
if (activeTransfers.get(downloadKey) === transfer) {
|
|
104
|
+
activeTransfers.delete(downloadKey);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
promise: initialSubscriber.promise,
|
|
109
|
+
joined: false,
|
|
110
|
+
getCacheHit: () => transfer.cacheHit,
|
|
111
|
+
};
|
|
11
112
|
}
|
|
12
|
-
export function
|
|
13
|
-
|
|
113
|
+
export function cancelTransfer(downloadKey, clearCache = false) {
|
|
114
|
+
const transfer = activeTransfers.get(downloadKey);
|
|
115
|
+
if (!transfer)
|
|
116
|
+
return;
|
|
117
|
+
transfer.clearCache = clearCache;
|
|
118
|
+
transfer.abortController.abort();
|
|
119
|
+
for (const sub of transfer.subscribers.values()) {
|
|
120
|
+
settleSubscriber(sub, new DownloadCancelledError());
|
|
121
|
+
}
|
|
14
122
|
}
|
|
15
123
|
export function createHyperdriveDownloadKey(hyperdriveKey, modelFileName) {
|
|
16
124
|
return `${hyperdriveKey}:${modelFileName}`;
|
|
@@ -18,38 +126,32 @@ export function createHyperdriveDownloadKey(hyperdriveKey, modelFileName) {
|
|
|
18
126
|
export function createHttpDownloadKey(url) {
|
|
19
127
|
return `http:${url}`;
|
|
20
128
|
}
|
|
21
|
-
export function createRegistryDownloadKey(registryPath) {
|
|
22
|
-
return `registry:${registryPath}`;
|
|
23
|
-
}
|
|
24
|
-
export function setClearCacheFlag(downloadKey, clearCache) {
|
|
25
|
-
if (clearCache) {
|
|
26
|
-
clearCacheFlags.set(downloadKey, true);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
clearCacheFlags.delete(downloadKey);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
export function shouldClearCache(downloadKey) {
|
|
33
|
-
return clearCacheFlags.get(downloadKey) ?? false;
|
|
34
|
-
}
|
|
35
|
-
export function clearClearCacheFlag(downloadKey) {
|
|
36
|
-
clearCacheFlags.delete(downloadKey);
|
|
129
|
+
export function createRegistryDownloadKey(registrySource, registryPath) {
|
|
130
|
+
return `registry:${registrySource}:${registryPath}`;
|
|
37
131
|
}
|
|
38
|
-
export function
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
132
|
+
export function applyJoinedDownloadStats(result, hooks) {
|
|
133
|
+
if (!result.joined)
|
|
134
|
+
return result.promise;
|
|
135
|
+
return result.promise.then((path) => {
|
|
136
|
+
const cacheHit = result.getCacheHit();
|
|
137
|
+
if (cacheHit === true) {
|
|
138
|
+
hooks?.markCacheHit?.();
|
|
43
139
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
140
|
+
else if (cacheHit === false) {
|
|
141
|
+
hooks?.markCacheMiss?.();
|
|
142
|
+
hooks?.markSharedTransfer?.();
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
hooks?.markSharedTransfer?.();
|
|
146
|
+
}
|
|
147
|
+
return path;
|
|
148
|
+
});
|
|
49
149
|
}
|
|
50
150
|
export function cancelAllDownloads() {
|
|
51
|
-
logger.info(`🧹 Cancelling ${
|
|
52
|
-
Array.from(
|
|
151
|
+
logger.info(`🧹 Cancelling ${activeTransfers.size} active downloads`);
|
|
152
|
+
for (const key of Array.from(activeTransfers.keys())) {
|
|
153
|
+
cancelTransfer(key);
|
|
154
|
+
}
|
|
53
155
|
}
|
|
54
156
|
let isCleaningUp = false;
|
|
55
157
|
export async function cleanupDownloads() {
|
|
@@ -57,7 +159,9 @@ export async function cleanupDownloads() {
|
|
|
57
159
|
return;
|
|
58
160
|
isCleaningUp = true;
|
|
59
161
|
try {
|
|
60
|
-
const downloadPromises = Array.from(
|
|
162
|
+
const downloadPromises = Array.from(activeTransfers.values())
|
|
163
|
+
.filter((t) => t.downloadPromise !== undefined)
|
|
164
|
+
.map((t) => t.downloadPromise.catch(() => { }));
|
|
61
165
|
cancelAllDownloads();
|
|
62
166
|
if (downloadPromises.length > 0) {
|
|
63
167
|
await Promise.allSettled(downloadPromises);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ModelProgressUpdate } from "../../../../schemas/index";
|
|
2
|
-
import type { DownloadResult } from "./types";
|
|
3
|
-
export declare function downloadModelFromHttpWithStats(url: string, progressCallback?: (progress: ModelProgressUpdate) => void): Promise<DownloadResult>;
|
|
4
|
-
export declare function downloadModelFromRegistryWithStats(registryPath: string, registrySource: string, progressCallback?: (progress: ModelProgressUpdate) => void, expectedChecksum?: string): Promise<DownloadResult>;
|
|
5
|
-
export declare function downloadModelFromHyperdriveWithStats(hyperdriveKey: string, modelFileName: string, seed?: boolean, progressCallback?: (progress: ModelProgressUpdate) => void): Promise<DownloadResult>;
|
|
2
|
+
import type { DownloadStats, DownloadResult, DownloadHooks, ResolveResult } from "./types";
|
|
3
|
+
export declare function downloadModelFromHttpWithStats(url: string, progressCallback?: (progress: ModelProgressUpdate) => void, downloadHooks?: DownloadHooks): Promise<DownloadResult>;
|
|
4
|
+
export declare function downloadModelFromRegistryWithStats(registryPath: string, registrySource: string, progressCallback?: (progress: ModelProgressUpdate) => void, expectedChecksum?: string, downloadHooks?: DownloadHooks): Promise<DownloadResult>;
|
|
5
|
+
export declare function downloadModelFromHyperdriveWithStats(hyperdriveKey: string, modelFileName: string, seed?: boolean, progressCallback?: (progress: ModelProgressUpdate) => void, downloadHooks?: DownloadHooks): Promise<DownloadResult>;
|
|
6
|
+
export declare function mergeDownloadStats(results: ResolveResult[]): DownloadStats | undefined;
|
|
6
7
|
//# sourceMappingURL=download-stats.d.ts.map
|