@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
|
@@ -63,20 +63,6 @@ async function resolveLocalOrCachedFile(modelIdOrPath) {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
function selectDownloaders(mode) {
|
|
67
|
-
if (mode === "stats") {
|
|
68
|
-
return {
|
|
69
|
-
http: downloadModelFromHttpWithStats,
|
|
70
|
-
registry: downloadModelFromRegistryWithStats,
|
|
71
|
-
hyperdrive: downloadModelFromHyperdriveWithStats,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
return {
|
|
75
|
-
http: downloadModelFromHttp,
|
|
76
|
-
registry: downloadModelFromRegistry,
|
|
77
|
-
hyperdrive: downloadModelFromHyperdrive,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
66
|
function isDownloadResult(value) {
|
|
81
67
|
return value !== null && typeof value === "object" && "path" in value;
|
|
82
68
|
}
|
|
@@ -88,9 +74,8 @@ function buildResult(pathOrResult, sourceType) {
|
|
|
88
74
|
}
|
|
89
75
|
return { path: pathOrResult, sourceType };
|
|
90
76
|
}
|
|
91
|
-
async function resolveModelPathCore(modelSrc, progressCallback, seed, mode) {
|
|
77
|
+
async function resolveModelPathCore(modelSrc, progressCallback, seed, mode, hooks) {
|
|
92
78
|
const srcString = modelInputToSrcSchema.parse(modelSrc);
|
|
93
|
-
const downloaders = selectDownloaders(mode);
|
|
94
79
|
// Parse hyperdrive URLs if present
|
|
95
80
|
let hyperdriveKey;
|
|
96
81
|
let actualModelSrc = srcString;
|
|
@@ -106,7 +91,9 @@ async function resolveModelPathCore(modelSrc, progressCallback, seed, mode) {
|
|
|
106
91
|
// Look up model metadata for checksum validation
|
|
107
92
|
const modelMetadata = getModelByPath(registryPath);
|
|
108
93
|
const expectedChecksum = modelMetadata?.sha256Checksum;
|
|
109
|
-
const result =
|
|
94
|
+
const result = mode === "stats"
|
|
95
|
+
? await downloadModelFromRegistryWithStats(registryPath, registrySource, progressCallback, expectedChecksum, hooks)
|
|
96
|
+
: await downloadModelFromRegistry(registryPath, registrySource, progressCallback, expectedChecksum, hooks);
|
|
110
97
|
logger.info(`Loaded Model to ${isDownloadResult(result) ? result.path : result}`);
|
|
111
98
|
return buildResult(result, "registry");
|
|
112
99
|
}
|
|
@@ -118,14 +105,18 @@ async function resolveModelPathCore(modelSrc, progressCallback, seed, mode) {
|
|
|
118
105
|
if (actualModelSrc.startsWith("http://") ||
|
|
119
106
|
actualModelSrc.startsWith("https://")) {
|
|
120
107
|
logger.info(`Loading from HTTP URL: ${actualModelSrc}`);
|
|
121
|
-
const result =
|
|
108
|
+
const result = mode === "stats"
|
|
109
|
+
? await downloadModelFromHttpWithStats(actualModelSrc, progressCallback, hooks)
|
|
110
|
+
: await downloadModelFromHttp(actualModelSrc, progressCallback, hooks);
|
|
122
111
|
logger.info(`Loaded Model to ${isDownloadResult(result) ? result.path : result}`);
|
|
123
112
|
return buildResult(result, "http");
|
|
124
113
|
}
|
|
125
114
|
// Hyperdrive source
|
|
126
115
|
if (hyperdriveKey) {
|
|
127
116
|
logger.info(`Loading from hyperdrive: ${hyperdriveKey}`);
|
|
128
|
-
const result =
|
|
117
|
+
const result = mode === "stats"
|
|
118
|
+
? await downloadModelFromHyperdriveWithStats(hyperdriveKey, actualModelSrc, seed, progressCallback, hooks)
|
|
119
|
+
: await downloadModelFromHyperdrive(hyperdriveKey, actualModelSrc, seed, progressCallback, hooks);
|
|
129
120
|
return buildResult(result, "hyperdrive");
|
|
130
121
|
}
|
|
131
122
|
// Filesystem source (local files, cached files)
|
|
@@ -146,10 +137,10 @@ async function resolveModelPathCore(modelSrc, progressCallback, seed, mode) {
|
|
|
146
137
|
}
|
|
147
138
|
return { path: resolvedPath, sourceType: "filesystem" };
|
|
148
139
|
}
|
|
149
|
-
export async function resolveModelPath(modelSrc, progressCallback, seed) {
|
|
150
|
-
const result = await resolveModelPathCore(modelSrc, progressCallback, seed, "base");
|
|
140
|
+
export async function resolveModelPath(modelSrc, progressCallback, seed, hooks) {
|
|
141
|
+
const result = await resolveModelPathCore(modelSrc, progressCallback, seed, "base", hooks);
|
|
151
142
|
return result.path;
|
|
152
143
|
}
|
|
153
|
-
export async function resolveModelPathWithStats(modelSrc, progressCallback, seed) {
|
|
154
|
-
return resolveModelPathCore(modelSrc, progressCallback, seed, "stats");
|
|
144
|
+
export async function resolveModelPathWithStats(modelSrc, progressCallback, seed, hooks) {
|
|
145
|
+
return resolveModelPathCore(modelSrc, progressCallback, seed, "stats", hooks);
|
|
155
146
|
}
|
|
@@ -5,6 +5,7 @@ export interface DownloadStats {
|
|
|
5
5
|
downloadSpeedBps?: number;
|
|
6
6
|
checksumValidationTimeMs?: number;
|
|
7
7
|
cacheHit?: boolean;
|
|
8
|
+
sharedTransfer?: boolean;
|
|
8
9
|
}
|
|
9
10
|
export interface ResolveResult {
|
|
10
11
|
path: string;
|
|
@@ -15,10 +16,12 @@ export interface DownloadResult {
|
|
|
15
16
|
path: string;
|
|
16
17
|
stats?: DownloadStats;
|
|
17
18
|
}
|
|
18
|
-
export interface
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
export interface DownloadHooks {
|
|
20
|
+
onDownloadKey?: (key: string) => void;
|
|
21
|
+
markCacheHit?: () => void;
|
|
22
|
+
markCacheMiss?: () => void;
|
|
23
|
+
markSharedTransfer?: () => void;
|
|
24
|
+
addChecksumValidationTimeMs?: (durationMs: number) => void;
|
|
22
25
|
}
|
|
23
26
|
export interface LoadModelProfilingMeta {
|
|
24
27
|
sourceType?: string;
|
|
@@ -26,4 +29,8 @@ export interface LoadModelProfilingMeta {
|
|
|
26
29
|
modelInitializationTimeMs?: number;
|
|
27
30
|
totalLoadTimeMs?: number;
|
|
28
31
|
}
|
|
32
|
+
export declare function buildDownloadProfilingFields(downloadStats: DownloadStats | undefined, sourceType?: string): {
|
|
33
|
+
gauges: Record<string, number>;
|
|
34
|
+
tags: Record<string, string>;
|
|
35
|
+
};
|
|
29
36
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1,28 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export function buildDownloadProfilingFields(downloadStats, sourceType) {
|
|
2
|
+
const gauges = {};
|
|
3
|
+
const tags = {};
|
|
4
|
+
if (downloadStats) {
|
|
5
|
+
if (downloadStats.downloadTimeMs !== undefined) {
|
|
6
|
+
gauges["downloadTime"] = downloadStats.downloadTimeMs;
|
|
7
|
+
}
|
|
8
|
+
if (downloadStats.totalBytesDownloaded !== undefined) {
|
|
9
|
+
gauges["totalBytesDownloaded"] = downloadStats.totalBytesDownloaded;
|
|
10
|
+
}
|
|
11
|
+
if (downloadStats.downloadSpeedBps !== undefined) {
|
|
12
|
+
gauges["downloadSpeedBps"] = downloadStats.downloadSpeedBps;
|
|
13
|
+
}
|
|
14
|
+
if (downloadStats.checksumValidationTimeMs !== undefined) {
|
|
15
|
+
gauges["checksumValidationTime"] = downloadStats.checksumValidationTimeMs;
|
|
16
|
+
}
|
|
17
|
+
if (downloadStats.cacheHit !== undefined) {
|
|
18
|
+
tags["cacheHit"] = downloadStats.cacheHit ? "true" : "false";
|
|
19
|
+
}
|
|
20
|
+
if (downloadStats.sharedTransfer) {
|
|
21
|
+
tags["sharedTransfer"] = "true";
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (sourceType) {
|
|
25
|
+
tags["sourceType"] = sourceType;
|
|
26
|
+
}
|
|
27
|
+
return { gauges, tags };
|
|
28
|
+
}
|
|
@@ -12,11 +12,10 @@ export async function handleLoadModelDelegated(request, options) {
|
|
|
12
12
|
throw new ModelLoadFailedError("Delegate information is required for delegated load model");
|
|
13
13
|
}
|
|
14
14
|
const { delegate } = request;
|
|
15
|
-
const {
|
|
15
|
+
const { providerPublicKey, timeout, healthCheckTimeout, fallbackToLocal, forceNewConnection, } = delegate;
|
|
16
16
|
try {
|
|
17
17
|
logger.info(`📤 Sending delegated loadModel request to provider: ${providerPublicKey}${timeout ? `, timeout: ${timeout}ms` : ""}${forceNewConnection ? " (forcing new connection)" : ""}`);
|
|
18
|
-
|
|
19
|
-
const rpc = await getRPC(topic, providerPublicKey, {
|
|
18
|
+
const rpc = await getRPC(providerPublicKey, {
|
|
20
19
|
timeout,
|
|
21
20
|
healthCheckTimeout,
|
|
22
21
|
forceNewConnection,
|
|
@@ -77,7 +76,6 @@ export async function handleLoadModelDelegated(request, options) {
|
|
|
77
76
|
modelInputToSrcSchema.parse(request.modelSrc) ||
|
|
78
77
|
`delegated-${Date.now()}`;
|
|
79
78
|
const delegateOptions = {
|
|
80
|
-
topic,
|
|
81
79
|
providerPublicKey,
|
|
82
80
|
};
|
|
83
81
|
if (timeout !== undefined) {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { getModelEntry } from "../../bare/registry/model-registry.js";
|
|
2
|
-
import { getPlugin } from "../../plugins/index.js";
|
|
2
|
+
import { getAllPlugins, getPlugin } from "../../plugins/index.js";
|
|
3
3
|
import { profileReplyHandler, profileStreamHandler, } from "../profiling/index.js";
|
|
4
|
-
import { ModelNotFoundError, ModelIsDelegatedError,
|
|
4
|
+
import { ModelNotFoundError, ModelIsDelegatedError, ModelOperationNotSupportedError, PluginNotFoundError, PluginHandlerTypeMismatchError, } from "../../../utils/errors-server.js";
|
|
5
5
|
function resolvePluginHandlerDef(modelId, handlerName) {
|
|
6
6
|
const entry = getModelEntry(modelId);
|
|
7
7
|
if (!entry) {
|
|
8
8
|
throw new ModelNotFoundError(modelId);
|
|
9
9
|
}
|
|
10
|
-
if (entry.isDelegated
|
|
10
|
+
if (entry.isDelegated) {
|
|
11
11
|
throw new ModelIsDelegatedError(modelId);
|
|
12
12
|
}
|
|
13
13
|
const plugin = getPlugin(entry.local.modelType);
|
|
@@ -16,8 +16,12 @@ function resolvePluginHandlerDef(modelId, handlerName) {
|
|
|
16
16
|
}
|
|
17
17
|
const handlerDef = plugin.handlers[handlerName];
|
|
18
18
|
if (!handlerDef) {
|
|
19
|
-
const
|
|
20
|
-
|
|
19
|
+
const loadedModelType = entry.local.modelType;
|
|
20
|
+
const supportedOperations = Object.keys(plugin.handlers);
|
|
21
|
+
const suggestedModelTypes = getAllPlugins()
|
|
22
|
+
.filter((p) => p.modelType !== loadedModelType && handlerName in p.handlers)
|
|
23
|
+
.map((p) => p.modelType);
|
|
24
|
+
throw new ModelOperationNotSupportedError(modelId, loadedModelType, handlerName, supportedOperations, suggestedModelTypes);
|
|
21
25
|
}
|
|
22
26
|
return handlerDef;
|
|
23
27
|
}
|
|
@@ -9,7 +9,7 @@ function resolvePluginHandler(modelId, handlerName) {
|
|
|
9
9
|
if (!modelEntry) {
|
|
10
10
|
throw new ModelNotFoundError(modelId);
|
|
11
11
|
}
|
|
12
|
-
if (modelEntry.isDelegated
|
|
12
|
+
if (modelEntry.isDelegated) {
|
|
13
13
|
throw new ModelIsDelegatedError(modelId);
|
|
14
14
|
}
|
|
15
15
|
const modelType = modelEntry.local.modelType;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import RPC from "bare-rpc";
|
|
2
2
|
import { createRpcProxy } from "./proxy.js";
|
|
3
|
+
import { hasActiveProviders } from "../../../bare/hyperswarm.js";
|
|
3
4
|
import { getServerLogger } from "../../../../logging/index.js";
|
|
4
5
|
const logger = getServerLogger();
|
|
5
6
|
export function setupConnectionHandlers(swarm) {
|
|
@@ -8,11 +9,21 @@ export function setupConnectionHandlers(swarm) {
|
|
|
8
9
|
logger.debug("🔗 Connection closed!");
|
|
9
10
|
});
|
|
10
11
|
swarm.on("connection", (conn) => {
|
|
11
|
-
logger.debug("🔗 Connection event triggered!");
|
|
12
12
|
const peerPubkey = conn.remotePublicKey?.toString("hex");
|
|
13
|
+
// The swarm is shared between consumer and provider sides, and once
|
|
14
|
+
// `swarm.listen()` has bound our keyPair on the DHT we cannot un-bind
|
|
15
|
+
// it without destroying the swarm. To honor `stopQVACProvider()` —
|
|
16
|
+
// which decrements `activeProviderCount` to 0 — we drop incoming
|
|
17
|
+
// connections at the RPC layer when there's no active provider, so
|
|
18
|
+
// peers can no longer dispatch delegated requests at us.
|
|
19
|
+
if (!hasActiveProviders()) {
|
|
20
|
+
logger.debug(`🚪 Dropping inbound connection from ${peerPubkey?.substring(0, 16)}... — provider is stopped`);
|
|
21
|
+
conn.destroy();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
logger.debug("🔗 Connection event triggered!");
|
|
13
25
|
logger.info(`📡 New connection established from: ${peerPubkey?.substring(0, 16)}...`);
|
|
14
26
|
logger.debug("🔐 Full peer public key:", peerPubkey);
|
|
15
|
-
// Create RPC instance for this connection (as server)
|
|
16
27
|
logger.debug("⚙️ Creating RPC instance for connection...");
|
|
17
28
|
new RPC(conn, createRpcProxy());
|
|
18
29
|
logger.debug("✅ RPC instance created successfully");
|
|
@@ -1,53 +1,66 @@
|
|
|
1
|
-
import { getSwarm,
|
|
1
|
+
import { getSwarm, hasActiveProviders, registerProvider, } from "../../../bare/hyperswarm.js";
|
|
2
2
|
import { setupConnectionHandlers } from "./connection.js";
|
|
3
3
|
import { getServerLogger } from "../../../../logging/index.js";
|
|
4
4
|
const logger = getServerLogger();
|
|
5
|
+
// Tracks whether the connection listener has been attached on this swarm
|
|
6
|
+
// instance. `swarm.listen()` and `swarm.on("connection", ...)` cannot be
|
|
7
|
+
// undone without destroying the swarm (which is shared with consumers), so
|
|
8
|
+
// we only ever set them up once per process and gate inbound RPC mounting
|
|
9
|
+
// inside the listener on `hasActiveProviders()`.
|
|
10
|
+
let listenerAttached = false;
|
|
11
|
+
// Consumers reach the provider by calling `dht.connect(publicKey)` directly,
|
|
12
|
+
// so the provider only needs its DHT server bound on its keyPair — no topic
|
|
13
|
+
// announce required. `swarm.listen()` is the minimal operation that makes
|
|
14
|
+
// the keyPair reachable on the DHT.
|
|
15
|
+
//
|
|
16
|
+
// This handler is idempotent: a second `startQVACProvider()` call returns
|
|
17
|
+
// success without re-listening, re-attaching listeners, or double-counting
|
|
18
|
+
// the active-provider counter (which would prevent a single `stopQVACProvider`
|
|
19
|
+
// from cleanly shutting things down).
|
|
5
20
|
export async function provideHandler(request) {
|
|
6
21
|
const swarm = getSwarm({
|
|
7
22
|
firewallConfig: request.firewall,
|
|
8
23
|
});
|
|
9
24
|
logger.debug("🚀 Provide request received:", request);
|
|
10
|
-
logger.debug("🔍 Swarm keyPair exists:", !!swarm.keyPair);
|
|
11
|
-
logger.debug("🔍 Swarm publicKey:", swarm.keyPair?.publicKey?.toString("hex")?.substring(0, 16));
|
|
12
25
|
try {
|
|
13
|
-
logger.debug("⚡ Starting provide handler execution");
|
|
14
26
|
const pubKey = swarm.keyPair.publicKey;
|
|
15
|
-
logger.debug("🔑
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
logger.info(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
logger.
|
|
34
|
-
|
|
27
|
+
logger.debug("🔑 Provider public key:", pubKey.toString("hex"));
|
|
28
|
+
if (hasActiveProviders()) {
|
|
29
|
+
logger.info("ℹ️ Provider already running, returning existing identity");
|
|
30
|
+
return {
|
|
31
|
+
type: "provide",
|
|
32
|
+
success: true,
|
|
33
|
+
publicKey: pubKey.toString("hex"),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
// We must wait for the DHT routing table to populate BEFORE announcing.
|
|
37
|
+
// `swarm.listen()` only does a single initial announce using whatever
|
|
38
|
+
// peers are in the routing table at that moment — if the DHT isn't
|
|
39
|
+
// bootstrapped yet, that announce reaches very few nodes and consumers
|
|
40
|
+
// won't be able to find us via dht.connect(publicKey).
|
|
41
|
+
logger.info("🌐 Waiting for DHT to fully bootstrap...");
|
|
42
|
+
await swarm.dht.fullyBootstrapped();
|
|
43
|
+
logger.info("🌐 Announcing provider on DHT (binding keyPair)...");
|
|
44
|
+
await swarm.listen();
|
|
45
|
+
logger.info("🎯 Provider is listening and ready to accept connections");
|
|
46
|
+
if (!listenerAttached) {
|
|
47
|
+
setupConnectionHandlers(swarm);
|
|
48
|
+
listenerAttached = true;
|
|
49
|
+
}
|
|
50
|
+
registerProvider();
|
|
51
|
+
return {
|
|
35
52
|
type: "provide",
|
|
36
53
|
success: true,
|
|
37
54
|
publicKey: pubKey.toString("hex"),
|
|
38
55
|
};
|
|
39
|
-
logger.debug("📤 Returning response:", response);
|
|
40
|
-
return response;
|
|
41
56
|
}
|
|
42
57
|
catch (error) {
|
|
43
58
|
logger.error("❌ Error in provide handler:", error);
|
|
44
59
|
logger.error("❌ Error stack:", error instanceof Error ? error.stack : "No stack trace");
|
|
45
|
-
|
|
60
|
+
return {
|
|
46
61
|
type: "provide",
|
|
47
62
|
success: false,
|
|
48
63
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
49
64
|
};
|
|
50
|
-
logger.debug("📤 Returning error response:", errorResponse);
|
|
51
|
-
return errorResponse;
|
|
52
65
|
}
|
|
53
66
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function stopProvideHandler(
|
|
1
|
+
import type { StopProvideResponse } from "../../../schemas/stop-provide";
|
|
2
|
+
export declare function stopProvideHandler(): StopProvideResponse;
|
|
3
3
|
//# sourceMappingURL=stopProvideHandler.d.ts.map
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { unregisterProvider } from "../../bare/hyperswarm.js";
|
|
2
2
|
import { getServerLogger } from "../../../logging/index.js";
|
|
3
3
|
const logger = getServerLogger();
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
// Decrements the active-provider counter. The shared connection listener
|
|
5
|
+
// (set up once in `provideHandler` per process) checks `hasActiveProviders()`
|
|
6
|
+
// before mounting an RPC server on incoming sockets, so once the counter
|
|
7
|
+
// reaches 0 inbound peers are dropped and remote calls stop being served.
|
|
8
|
+
//
|
|
9
|
+
// We deliberately do NOT destroy the swarm or unbind the keyPair from the
|
|
10
|
+
// DHT here, because the same swarm is also used by this SDK instance as a
|
|
11
|
+
// consumer (delegate-rpc-client.ts). Stopping the provider role must not
|
|
12
|
+
// kill outgoing delegation connections.
|
|
13
|
+
export function stopProvideHandler() {
|
|
6
14
|
try {
|
|
7
|
-
|
|
8
|
-
const topicHex = request.topic;
|
|
9
|
-
swarm.leave(topic);
|
|
10
|
-
unregisterProviderTopic(topicHex);
|
|
15
|
+
unregisterProvider();
|
|
11
16
|
return {
|
|
12
17
|
type: "stopProvide",
|
|
13
18
|
success: true,
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { TextToSpeechStreamRequest, TextToSpeechStreamResponse } from "../../../schemas/index";
|
|
2
|
+
export declare function handleTextToSpeechStream(request: TextToSpeechStreamRequest, inputStream: AsyncIterable<Buffer>): AsyncGenerator<TextToSpeechStreamResponse>;
|
|
3
|
+
//# sourceMappingURL=text-to-speech-stream.d.ts.map
|
|
@@ -8,14 +8,14 @@ import { getServerLogger } from "../../../logging/index.js";
|
|
|
8
8
|
const logger = getServerLogger();
|
|
9
9
|
export async function handleUnloadModelDelegated(request) {
|
|
10
10
|
const entry = getModelEntry(request.modelId);
|
|
11
|
-
if (!entry?.isDelegated
|
|
11
|
+
if (!entry?.isDelegated) {
|
|
12
12
|
throw new ModelIsDelegatedError(request.modelId);
|
|
13
13
|
}
|
|
14
|
-
const {
|
|
14
|
+
const { providerPublicKey, timeout, healthCheckTimeout } = entry.delegated;
|
|
15
15
|
unregisterModel(request.modelId);
|
|
16
16
|
try {
|
|
17
17
|
logger.info(`Sending delegated unload for model ${request.modelId} to provider: ${providerPublicKey}`);
|
|
18
|
-
const rpc = await getRPC(
|
|
18
|
+
const rpc = await getRPC(providerPublicKey, { timeout, healthCheckTimeout });
|
|
19
19
|
await send({ type: "unloadModel", modelId: request.modelId, clearStorage: false }, rpc, { timeout, peerKey: providerPublicKey });
|
|
20
20
|
logger.info(`Delegated model ${request.modelId} unloaded on provider`);
|
|
21
21
|
}
|
|
@@ -167,6 +167,26 @@ registerOperationMetrics({
|
|
|
167
167
|
return Object.keys(gauges).length > 0 ? gauges : undefined;
|
|
168
168
|
},
|
|
169
169
|
});
|
|
170
|
+
// Duplex sibling of `textToSpeech`. Server emits the same `TtsStats` on the
|
|
171
|
+
// final chunk (via `collectTtsStats`), so the gauge set mirrors the
|
|
172
|
+
// non-streaming path; without registering here, sessions would silently
|
|
173
|
+
// skip `modelExecutionTime` / `audioDuration` / `totalSamples` metrics.
|
|
174
|
+
registerOperationMetrics({
|
|
175
|
+
op: "textToSpeechStream",
|
|
176
|
+
kind: "handler",
|
|
177
|
+
getTags: (req) => (req.modelId ? { modelId: req.modelId } : {}),
|
|
178
|
+
fromFinalChunk: (res) => {
|
|
179
|
+
const gauges = {};
|
|
180
|
+
const modelExecMs = readModelExecutionMs(res);
|
|
181
|
+
if (modelExecMs !== undefined)
|
|
182
|
+
gauges["modelExecutionTime"] = modelExecMs;
|
|
183
|
+
if (res.stats?.audioDuration !== undefined)
|
|
184
|
+
gauges["audioDuration"] = res.stats.audioDuration;
|
|
185
|
+
if (res.stats?.totalSamples !== undefined)
|
|
186
|
+
gauges["totalSamples"] = res.stats.totalSamples;
|
|
187
|
+
return Object.keys(gauges).length > 0 ? gauges : undefined;
|
|
188
|
+
},
|
|
189
|
+
});
|
|
170
190
|
registerOperationMetrics({
|
|
171
191
|
op: "embed",
|
|
172
192
|
kind: "handler",
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function shouldUseStreamErrorTransport(entry, rawRequest) {
|
|
2
|
+
if (!entry)
|
|
3
|
+
return false;
|
|
4
|
+
if (entry.type === "stream")
|
|
5
|
+
return true;
|
|
6
|
+
if (entry.type !== "reply")
|
|
7
|
+
return false;
|
|
8
|
+
if (rawRequest?.["withProgress"] !== true)
|
|
9
|
+
return false;
|
|
10
|
+
try {
|
|
11
|
+
return typeof entry.supportsProgress === "function"
|
|
12
|
+
? entry.supportsProgress(rawRequest)
|
|
13
|
+
: !!entry.supportsProgress;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return !!entry.supportsProgress;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CacheMessage } from "./types";
|
|
2
|
+
export declare function getAutoCacheLookupHistory(currentHistory: CacheMessage[]): CacheMessage[];
|
|
3
|
+
export declare function buildAutoCacheSaveHistory(currentHistory: CacheMessage[], assistantResponse: string): CacheMessage[];
|
|
4
|
+
//# sourceMappingURL=auto-history.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { normalizeAssistantCacheContent } from "../../../utils/cache-normalize.js";
|
|
2
|
+
function normalizeAssistantMessage(message) {
|
|
3
|
+
if (message.role !== "assistant") {
|
|
4
|
+
return message;
|
|
5
|
+
}
|
|
6
|
+
return { ...message, content: normalizeAssistantCacheContent(message.content) };
|
|
7
|
+
}
|
|
8
|
+
export function getAutoCacheLookupHistory(currentHistory) {
|
|
9
|
+
if (currentHistory.length <= 1) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
return currentHistory.slice(0, -1).map(normalizeAssistantMessage);
|
|
13
|
+
}
|
|
14
|
+
export function buildAutoCacheSaveHistory(currentHistory, assistantResponse) {
|
|
15
|
+
return [
|
|
16
|
+
...currentHistory,
|
|
17
|
+
{
|
|
18
|
+
role: "assistant",
|
|
19
|
+
content: normalizeAssistantCacheContent(assistantResponse),
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ShardFileMetadata } from "
|
|
1
|
+
import type { ShardFileMetadata } from "../../../schemas/index";
|
|
2
2
|
export declare function getCacheDir(subDir: string): string;
|
|
3
3
|
export declare function getModelsCacheDir(): string;
|
|
4
4
|
export declare function getKVCacheDir(): string;
|
|
@@ -8,19 +8,36 @@ export declare function getKVCacheDir(): string;
|
|
|
8
8
|
*/
|
|
9
9
|
export declare function getShardedModelCacheDir(hyperdriveKey: string): string;
|
|
10
10
|
/**
|
|
11
|
-
* Get
|
|
12
|
-
* Returns: cache/
|
|
11
|
+
* Get cache directory for a companion set.
|
|
12
|
+
* Returns: cache/sets/<setKey>/
|
|
13
13
|
*/
|
|
14
|
-
export declare function
|
|
14
|
+
export declare function getCompanionSetCacheDir(setKey: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Get full path to a file within a companion set cache.
|
|
17
|
+
* Returns: cache/sets/<setKey>/<targetName>
|
|
18
|
+
*/
|
|
19
|
+
export declare function getCompanionSetPath(setKey: string, targetName: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Get cache path for a single (non-sharded, non-companion) registry model.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getSingleFileCachePath(registryPath: string): string;
|
|
15
24
|
/**
|
|
16
25
|
* Get full path to specific shard file
|
|
17
26
|
* Returns: cache/sharded/<hyperdriveKey>/<shardFilename>
|
|
18
27
|
*/
|
|
19
28
|
export declare function getShardPath(hyperdriveKey: string, shardFilename: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Returns the deletion target for `clearStorage`. Scoped to the SDK cache
|
|
31
|
+
* directory — companion set and legacy ONNX paths delete the parent directory.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getClearStorageTarget(modelPath: string): {
|
|
34
|
+
path: string;
|
|
35
|
+
kind: "file" | "directory";
|
|
36
|
+
};
|
|
20
37
|
/**
|
|
21
38
|
* Check if all shards exist and are valid (size + checksum check)
|
|
22
39
|
* Returns array of missing/invalid shard indices (0-based)
|
|
23
40
|
* @param onChecksumTimeMs - Optional callback to report checksum validation time
|
|
24
41
|
*/
|
|
25
42
|
export declare function checkShardCompleteness(hyperdriveKey: string, shardFilenames: readonly string[], shardMetadata: readonly ShardFileMetadata[], onChecksumTimeMs?: (ms: number) => void): Promise<number[]>;
|
|
26
|
-
//# sourceMappingURL=
|
|
43
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import fs, { promises as fsPromises } from "bare-fs";
|
|
2
2
|
import path from "bare-path";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { calculateFileChecksum } from "
|
|
6
|
-
import { validateAndJoinPath } from "
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
3
|
+
import { getConfiguredCacheDir } from "../../bare/registry/config-registry.js";
|
|
4
|
+
import { getQvacPath } from "../qvac-paths.js";
|
|
5
|
+
import { calculateFileChecksum } from "../checksum.js";
|
|
6
|
+
import { validateAndJoinPath } from "../path-security.js";
|
|
7
|
+
import { generateShortHash } from "../formatting.js";
|
|
8
|
+
import { getServerLogger } from "../../../logging/index.js";
|
|
9
|
+
import { nowMs } from "../../../profiling/index.js";
|
|
10
|
+
import { resolveClearStorageTarget } from "../clear-storage.js";
|
|
9
11
|
const logger = getServerLogger();
|
|
10
12
|
export function getCacheDir(subDir) {
|
|
11
|
-
const
|
|
12
|
-
const cacheDir = path.join(homeDir, ".qvac", subDir);
|
|
13
|
+
const cacheDir = getQvacPath(subDir);
|
|
13
14
|
try {
|
|
14
15
|
fs.mkdirSync(cacheDir, { recursive: true });
|
|
15
16
|
}
|
|
@@ -47,27 +48,35 @@ export function getShardedModelCacheDir(hyperdriveKey) {
|
|
|
47
48
|
return shardDir;
|
|
48
49
|
}
|
|
49
50
|
/**
|
|
50
|
-
* Get cache directory for
|
|
51
|
-
* Returns: cache/
|
|
51
|
+
* Get cache directory for a companion set.
|
|
52
|
+
* Returns: cache/sets/<setKey>/
|
|
52
53
|
*/
|
|
53
|
-
function
|
|
54
|
+
export function getCompanionSetCacheDir(setKey) {
|
|
54
55
|
const baseCache = getModelsCacheDir();
|
|
55
|
-
const
|
|
56
|
+
const setDir = validateAndJoinPath(baseCache, "sets", setKey);
|
|
56
57
|
try {
|
|
57
|
-
fs.mkdirSync(
|
|
58
|
+
fs.mkdirSync(setDir, { recursive: true });
|
|
58
59
|
}
|
|
59
60
|
catch (error) {
|
|
60
|
-
logger.error(`Error creating
|
|
61
|
+
logger.error(`Error creating companion set cache directory:`, error instanceof Error ? error.message : String(error));
|
|
61
62
|
}
|
|
62
|
-
return
|
|
63
|
+
return setDir;
|
|
63
64
|
}
|
|
64
65
|
/**
|
|
65
|
-
* Get full path to
|
|
66
|
-
* Returns: cache/
|
|
66
|
+
* Get full path to a file within a companion set cache.
|
|
67
|
+
* Returns: cache/sets/<setKey>/<targetName>
|
|
67
68
|
*/
|
|
68
|
-
export function
|
|
69
|
-
const
|
|
70
|
-
return validateAndJoinPath(
|
|
69
|
+
export function getCompanionSetPath(setKey, targetName) {
|
|
70
|
+
const setDir = getCompanionSetCacheDir(setKey);
|
|
71
|
+
return validateAndJoinPath(setDir, targetName);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get cache path for a single (non-sharded, non-companion) registry model.
|
|
75
|
+
*/
|
|
76
|
+
export function getSingleFileCachePath(registryPath) {
|
|
77
|
+
const filename = registryPath.split("/").pop() || registryPath;
|
|
78
|
+
const sourceHash = generateShortHash(registryPath);
|
|
79
|
+
return path.join(getModelsCacheDir(), `${sourceHash}_${filename}`);
|
|
71
80
|
}
|
|
72
81
|
/**
|
|
73
82
|
* Get full path to specific shard file
|
|
@@ -77,6 +86,13 @@ export function getShardPath(hyperdriveKey, shardFilename) {
|
|
|
77
86
|
const shardDir = getShardedModelCacheDir(hyperdriveKey);
|
|
78
87
|
return validateAndJoinPath(shardDir, shardFilename);
|
|
79
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Returns the deletion target for `clearStorage`. Scoped to the SDK cache
|
|
91
|
+
* directory — companion set and legacy ONNX paths delete the parent directory.
|
|
92
|
+
*/
|
|
93
|
+
export function getClearStorageTarget(modelPath) {
|
|
94
|
+
return resolveClearStorageTarget(modelPath, getModelsCacheDir());
|
|
95
|
+
}
|
|
80
96
|
/**
|
|
81
97
|
* Check if all shards exist and are valid (size + checksum check)
|
|
82
98
|
* Returns array of missing/invalid shard indices (0-based)
|