@qvac/sdk 0.6.0 → 0.7.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/LICENSE +1 -24
- package/NOTICE +632 -0
- package/README.md +2 -1
- package/dist/client/api/embed.js +1 -4
- package/dist/client/api/get-model-info.d.ts +10 -3
- package/dist/client/api/index.d.ts +2 -0
- package/dist/client/api/index.js +2 -0
- package/dist/client/api/invoke-plugin.d.ts +14 -0
- package/dist/client/api/invoke-plugin.js +38 -0
- package/dist/client/api/registry.d.ts +14 -0
- package/dist/client/api/registry.js +37 -0
- package/dist/client/api/transcribe.js +0 -4
- package/dist/client/api/unload-model.js +1 -1
- package/dist/client/config-loader/resolve-config.node.d.ts +3 -2
- package/dist/client/config-loader/resolve-config.node.js +31 -4
- package/dist/client/init-hooks.js +2 -1
- package/dist/client/rpc/bare-client.d.ts +2 -0
- package/dist/client/rpc/bare-client.js +48 -7
- package/dist/client/rpc/expo-device-info.d.ts +6 -0
- package/dist/client/rpc/expo-device-info.js +32 -0
- package/dist/client/rpc/expo-rpc-client.js +9 -32
- package/dist/client/rpc/node-rpc-client.d.ts +1 -1
- package/dist/client/rpc/node-rpc-client.js +201 -28
- package/dist/client/rpc/rpc-client.d.ts +1 -1
- package/dist/client/rpc/rpc-client.js +2 -2
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.js +1 -0
- package/dist/constants/registry.d.ts +2 -0
- package/dist/constants/registry.js +1 -0
- package/dist/examples/cache-management.js +2 -2
- package/dist/examples/config/plugins/plugins.config.d.ts +5 -0
- package/dist/examples/config/plugins/plugins.config.js +4 -0
- package/dist/examples/download-with-blind-relays.js +1 -1
- package/dist/examples/llamacpp-multimodal.js +3 -3
- package/dist/examples/llamacpp-native-tools.js +2 -2
- package/dist/examples/mcp-websearch.js +2 -2
- package/dist/examples/multi-model-demo.js +2 -2
- package/dist/examples/ocr-fasttext.js +4 -4
- package/dist/examples/parallel-download.js +2 -2
- package/dist/examples/plugins.d.ts +14 -0
- package/dist/examples/plugins.js +129 -0
- package/dist/examples/registry-query.d.ts +2 -0
- package/dist/examples/registry-query.js +87 -0
- package/dist/examples/translation/translation-bergamot-batch.js +2 -2
- package/dist/examples/translation/translation-bergamot.js +4 -4
- package/dist/examples/translation/translation-opus.js +2 -2
- package/dist/examples/translation/translation-stream.js +2 -2
- package/dist/examples/tts/chatterbox.d.ts +2 -0
- package/dist/examples/tts/chatterbox.js +59 -0
- package/dist/examples/tts/supertonic.d.ts +2 -0
- package/dist/examples/tts/supertonic.js +51 -0
- package/dist/examples/tts/utils.d.ts +17 -0
- package/dist/examples/tts/utils.js +93 -0
- package/dist/examples/whispercpp-filesystem.js +2 -3
- package/dist/examples/whispercpp-microphone-record.js +1 -2
- package/dist/examples/whispercpp-prompt.js +2 -3
- package/dist/expo/plugins/index.d.ts +3 -0
- package/dist/expo/plugins/index.js +3 -0
- package/dist/expo/plugins/resolve-sdk-package-dir.d.ts +15 -0
- package/dist/expo/plugins/resolve-sdk-package-dir.js +31 -0
- package/dist/expo/plugins/withAndroidArchitecture.d.ts +8 -0
- package/dist/expo/plugins/withAndroidArchitecture.js +52 -0
- package/dist/expo/plugins/withAndroidNdkVersion.d.ts +8 -0
- package/dist/expo/plugins/withAndroidNdkVersion.js +31 -0
- package/dist/expo/plugins/withDeviceInfo.d.ts +10 -0
- package/dist/expo/plugins/withDeviceInfo.js +48 -0
- package/dist/expo/plugins/withMobileBundle.d.ts +5 -2
- package/dist/expo/plugins/withMobileBundle.js +121 -65
- package/dist/expo/plugins/withQvacSDK.d.ts +4 -0
- package/dist/expo/plugins/withQvacSDK.js +26 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +5 -5
- package/dist/models/{hyperdrive → registry}/index.js +1 -1
- package/dist/models/registry/models.d.ts +9056 -0
- package/dist/models/registry/models.js +9351 -0
- package/dist/models/update-models/codegen.d.ts +3 -0
- package/dist/models/update-models/codegen.js +135 -0
- package/dist/models/update-models/history.d.ts +13 -0
- package/dist/models/update-models/history.js +88 -0
- package/dist/models/update-models/index.d.ts +2 -0
- package/dist/models/update-models/index.js +124 -0
- package/dist/models/update-models/naming.d.ts +4 -0
- package/dist/models/update-models/naming.js +314 -0
- package/dist/models/update-models/processing.d.ts +8 -0
- package/dist/models/update-models/processing.js +67 -0
- package/dist/models/update-models/registry.d.ts +4 -0
- package/dist/models/update-models/registry.js +67 -0
- package/dist/models/update-models/shards.d.ts +4 -0
- package/dist/models/update-models/shards.js +57 -0
- package/dist/models/update-models/types.d.ts +60 -0
- package/dist/models/update-models/types.js +1 -0
- package/dist/models/update-models/utils.d.ts +3 -0
- package/dist/models/update-models/utils.js +21 -0
- package/dist/pear/pre.d.ts +18 -0
- package/dist/pear/pre.js +433 -0
- package/dist/schemas/common.d.ts +286 -32
- package/dist/schemas/common.js +12 -0
- package/dist/schemas/download-asset.d.ts +35 -11
- package/dist/schemas/download-asset.js +5 -1
- package/dist/schemas/engine-addon-map.d.ts +5 -0
- package/dist/schemas/engine-addon-map.js +49 -0
- package/dist/schemas/get-model-info.d.ts +32 -16
- package/dist/schemas/get-model-info.js +17 -8
- package/dist/schemas/index.d.ts +4 -1
- package/dist/schemas/index.js +4 -4
- package/dist/schemas/load-model.d.ts +2224 -900
- package/dist/schemas/load-model.js +130 -25
- package/dist/schemas/model-src-utils.d.ts +30 -12
- package/dist/schemas/model-src-utils.js +5 -2
- package/dist/schemas/model-types.d.ts +15 -4
- package/dist/schemas/model-types.js +21 -4
- package/dist/schemas/path-validation.d.ts +10 -0
- package/dist/schemas/path-validation.js +22 -0
- package/dist/schemas/plugin.d.ts +180 -0
- package/dist/schemas/plugin.js +132 -0
- package/dist/schemas/rag.d.ts +2 -2
- package/dist/schemas/rag.js +7 -3
- package/dist/schemas/registry.d.ts +338 -0
- package/dist/schemas/registry.js +91 -0
- package/dist/schemas/sdk-errors-client.d.ts +6 -6
- package/dist/schemas/sdk-errors-client.js +15 -15
- package/dist/schemas/sdk-errors-registry.d.ts +6 -0
- package/dist/schemas/sdk-errors-registry.js +8 -0
- package/dist/schemas/sdk-errors-server.d.ts +16 -2
- package/dist/schemas/sdk-errors-server.js +90 -10
- package/dist/schemas/text-to-speech.d.ts +670 -1
- package/dist/schemas/text-to-speech.js +51 -2
- package/dist/schemas/translate.d.ts +2 -2
- package/dist/scripts/run-security-tests-bare.d.ts +2 -0
- package/dist/scripts/run-security-tests-bare.js +78 -0
- package/dist/scripts/run-security-tests.d.ts +2 -0
- package/dist/scripts/run-security-tests.js +22 -0
- package/dist/server/bare/delegate-rpc-client.d.ts +6 -0
- package/dist/server/bare/delegate-rpc-client.js +136 -56
- package/dist/server/bare/{addons/llamacpp-embedding/handlers → ops}/embed.d.ts +1 -1
- package/dist/server/bare/{addons/llamacpp-embedding/handlers → ops}/embed.js +3 -3
- package/dist/server/bare/{addons/llamacpp-completion → ops}/kv-cache-utils.js +6 -6
- package/dist/server/bare/{addons → ops}/load-model.js +32 -42
- package/dist/server/bare/{addons/nmtcpp-translation/handlers → ops}/translate.d.ts +1 -1
- package/dist/server/bare/{addons/nmtcpp-translation/handlers → ops}/translate.js +5 -4
- package/dist/server/bare/plugins/index.d.ts +7 -0
- package/dist/server/bare/plugins/index.js +6 -0
- package/dist/server/bare/{addons/llamacpp-completion → plugins/llamacpp-completion/ops}/cache-logger.js +1 -1
- package/dist/server/bare/{addons/llamacpp-completion/handlers → plugins/llamacpp-completion/ops}/completion-stream.d.ts +1 -1
- package/dist/server/bare/{addons/llamacpp-completion/handlers → plugins/llamacpp-completion/ops}/completion-stream.js +2 -3
- package/dist/server/bare/plugins/llamacpp-completion/plugin.d.ts +115 -0
- package/dist/server/bare/plugins/llamacpp-completion/plugin.js +142 -0
- package/dist/server/bare/plugins/llamacpp-embedding/plugin.d.ts +24 -0
- package/dist/server/bare/plugins/llamacpp-embedding/plugin.js +73 -0
- package/dist/server/bare/plugins/nmtcpp-translation/plugin.d.ts +45 -0
- package/dist/server/bare/plugins/nmtcpp-translation/plugin.js +97 -0
- package/dist/server/bare/{addons/onnx-ocr/handlers → plugins/onnx-ocr/ops}/ocr-stream.js +2 -1
- package/dist/server/bare/plugins/onnx-ocr/plugin.d.ts +38 -0
- package/dist/server/bare/{addons/onnx-ocr/create-model.js → plugins/onnx-ocr/plugin.js} +39 -2
- package/dist/server/bare/{addons/onnx-tts/handlers → plugins/onnx-tts/ops}/text-to-speech.js +23 -1
- package/dist/server/bare/plugins/onnx-tts/plugin.d.ts +26 -0
- package/dist/server/bare/plugins/onnx-tts/plugin.js +162 -0
- package/dist/server/bare/plugins/onnx-tts/wav-helper.d.ts +14 -0
- package/dist/server/bare/plugins/onnx-tts/wav-helper.js +107 -0
- package/dist/server/bare/plugins/whispercpp-transcription/ops/transcribe-stream.d.ts +3 -0
- package/dist/server/bare/{addons/whispercpp-transcription/handlers → plugins/whispercpp-transcription/ops}/transcribe-stream.js +1 -2
- package/dist/server/bare/plugins/whispercpp-transcription/plugin.d.ts +31 -0
- package/dist/server/bare/plugins/whispercpp-transcription/plugin.js +74 -0
- package/dist/server/bare/rag-hyperdb/handlers/ingest.js +1 -1
- package/dist/server/bare/rag-hyperdb/handlers/search.js +1 -1
- package/dist/server/bare/rag-hyperdb/rag-workspace-manager.js +2 -1
- package/dist/server/bare/registry/config-registry.js +1 -1
- package/dist/server/bare/registry/model-config-utils.js +0 -11
- package/dist/server/bare/registry/registry-client.d.ts +5 -0
- package/dist/server/bare/registry/registry-client.js +37 -0
- package/dist/server/env.d.ts +22 -0
- package/dist/server/env.js +57 -0
- package/dist/server/plugins/index.d.ts +2 -0
- package/dist/server/plugins/index.js +1 -0
- package/dist/server/plugins/registry.d.ts +9 -0
- package/dist/server/plugins/registry.js +75 -0
- package/dist/server/rpc/delegate-transport.d.ts +11 -0
- package/dist/server/rpc/delegate-transport.js +60 -0
- package/dist/server/rpc/handle-request.d.ts +0 -9
- package/dist/server/rpc/handle-request.js +13 -321
- package/dist/server/rpc/handler-registry.d.ts +3 -0
- package/dist/server/rpc/handler-registry.js +84 -0
- package/dist/server/rpc/handler-utils.d.ts +22 -0
- package/dist/server/rpc/handler-utils.js +87 -0
- package/dist/server/rpc/handlers/cancelHandler.js +1 -1
- package/dist/server/rpc/handlers/completion-stream-delegated.js +1 -1
- package/dist/server/rpc/handlers/completion-stream.js +2 -43
- package/dist/server/rpc/handlers/delete-cache.js +1 -1
- package/dist/server/rpc/handlers/embed.js +2 -21
- package/dist/server/rpc/handlers/get-model-info.js +19 -15
- package/dist/server/rpc/handlers/index.d.ts +9 -0
- package/dist/server/rpc/handlers/index.js +9 -0
- package/dist/server/rpc/handlers/load-model/download-manager.d.ts +1 -0
- package/dist/server/rpc/handlers/load-model/download-manager.js +3 -0
- package/dist/server/rpc/handlers/load-model/handler.js +47 -24
- package/dist/server/rpc/handlers/load-model/http.js +3 -2
- package/dist/server/rpc/handlers/load-model/hyperdrive.js +14 -10
- package/dist/server/rpc/handlers/load-model/registry.d.ts +10 -0
- package/dist/server/rpc/handlers/load-model/registry.js +571 -0
- package/dist/server/rpc/handlers/load-model/resolve.js +18 -5
- package/dist/server/rpc/handlers/load-model-delegated.js +4 -2
- package/dist/server/rpc/handlers/ocr-stream.js +2 -37
- package/dist/server/rpc/handlers/ping.d.ts +3 -0
- package/dist/server/rpc/handlers/ping.js +3 -0
- package/dist/server/rpc/handlers/plugin-dispatch.d.ts +15 -0
- package/dist/server/rpc/handlers/plugin-dispatch.js +54 -0
- package/dist/server/rpc/handlers/plugin-invoke.d.ts +4 -0
- package/dist/server/rpc/handlers/plugin-invoke.js +87 -0
- package/dist/server/rpc/handlers/registry.d.ts +5 -0
- package/dist/server/rpc/handlers/registry.js +157 -0
- package/dist/server/rpc/handlers/text-to-speech.js +2 -5
- package/dist/server/rpc/handlers/transcribe-stream.js +2 -30
- package/dist/server/rpc/handlers/translate.js +2 -42
- package/dist/server/rpc/handlers/unload-model.js +1 -1
- package/dist/server/rpc/index.d.ts +1 -1
- package/dist/server/utils/archive.d.ts +1 -0
- package/dist/server/utils/archive.js +10 -2
- package/dist/server/utils/cache.d.ts +5 -0
- package/dist/server/utils/cache.js +26 -2
- package/dist/server/utils/gguf-tensor-extractor.js +3 -3
- package/dist/server/utils/index.d.ts +1 -1
- package/dist/server/utils/index.js +1 -1
- package/dist/server/utils/path-security.d.ts +12 -0
- package/dist/server/utils/path-security.js +25 -0
- package/dist/server/utils/shard-utils.js +3 -3
- package/dist/server/worker-core.d.ts +6 -0
- package/dist/server/worker-core.js +88 -0
- package/dist/server/worker.d.ts +4 -5
- package/dist/server/worker.js +18 -116
- package/dist/utils/errors-client.d.ts +9 -6
- package/dist/utils/errors-client.js +19 -11
- package/dist/utils/errors-server.d.ts +44 -5
- package/dist/utils/errors-server.js +82 -9
- package/dist/utils/path-sanitize.d.ts +17 -0
- package/dist/utils/path-sanitize.js +54 -0
- package/expo/plugins/patches/android-link.mjs +63 -0
- package/expo/plugins/patches/ios-link.mjs +63 -0
- package/package.json +74 -12
- package/dist/examples/text-to-speech.d.ts +0 -3
- package/dist/examples/text-to-speech.js +0 -137
- package/dist/models/hyperdrive/models.d.ts +0 -4003
- package/dist/models/hyperdrive/models.js +0 -4282
- package/dist/server/bare/addons/index.d.ts +0 -4
- package/dist/server/bare/addons/index.js +0 -3
- package/dist/server/bare/addons/llamacpp-completion/create-model.d.ts +0 -8
- package/dist/server/bare/addons/llamacpp-completion/create-model.js +0 -43
- package/dist/server/bare/addons/llamacpp-completion/index.d.ts +0 -4
- package/dist/server/bare/addons/llamacpp-completion/index.js +0 -3
- package/dist/server/bare/addons/llamacpp-embedding/create-model.d.ts +0 -8
- package/dist/server/bare/addons/llamacpp-embedding/create-model.js +0 -38
- package/dist/server/bare/addons/llamacpp-embedding/index.d.ts +0 -3
- package/dist/server/bare/addons/llamacpp-embedding/index.js +0 -2
- package/dist/server/bare/addons/nmtcpp-translation/create-model.d.ts +0 -8
- package/dist/server/bare/addons/nmtcpp-translation/create-model.js +0 -52
- package/dist/server/bare/addons/nmtcpp-translation/index.d.ts +0 -3
- package/dist/server/bare/addons/nmtcpp-translation/index.js +0 -2
- package/dist/server/bare/addons/onnx-ocr/create-model.d.ts +0 -10
- package/dist/server/bare/addons/onnx-ocr/index.d.ts +0 -3
- package/dist/server/bare/addons/onnx-ocr/index.js +0 -2
- package/dist/server/bare/addons/onnx-tts/create-model.d.ts +0 -10
- package/dist/server/bare/addons/onnx-tts/create-model.js +0 -25
- package/dist/server/bare/addons/onnx-tts/index.d.ts +0 -3
- package/dist/server/bare/addons/onnx-tts/index.js +0 -2
- package/dist/server/bare/addons/whispercpp-transcription/create-model.d.ts +0 -10
- package/dist/server/bare/addons/whispercpp-transcription/create-model.js +0 -37
- package/dist/server/bare/addons/whispercpp-transcription/handlers/transcribe-stream.d.ts +0 -3
- package/dist/server/bare/addons/whispercpp-transcription/index.d.ts +0 -3
- package/dist/server/bare/addons/whispercpp-transcription/index.js +0 -2
- /package/dist/models/{hyperdrive → registry}/index.d.ts +0 -0
- /package/dist/server/bare/{addons → ops}/cancel.d.ts +0 -0
- /package/dist/server/bare/{addons → ops}/cancel.js +0 -0
- /package/dist/server/bare/{addons/llamacpp-completion → ops}/kv-cache-utils.d.ts +0 -0
- /package/dist/server/bare/{addons → ops}/load-model.d.ts +0 -0
- /package/dist/server/bare/{addons → ops}/unload-model.d.ts +0 -0
- /package/dist/server/bare/{addons → ops}/unload-model.js +0 -0
- /package/dist/server/bare/{addons/llamacpp-completion → plugins/llamacpp-completion/ops}/cache-logger.d.ts +0 -0
- /package/dist/server/bare/{addons/onnx-ocr/handlers → plugins/onnx-ocr/ops}/ocr-stream.d.ts +0 -0
- /package/dist/server/bare/{addons/onnx-tts/handlers → plugins/onnx-tts/ops}/text-to-speech.d.ts +0 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { responseSchema, } from "../../schemas/index.js";
|
|
2
|
+
import { sendErrorResponse, sendStreamErrorResponse, } from "../error-handlers.js";
|
|
3
|
+
import { setSDKConfig } from "../bare/registry/config-registry.js";
|
|
4
|
+
import { setRuntimeContext } from "../bare/registry/runtime-context-registry.js";
|
|
5
|
+
function writeToStream(stream, response) {
|
|
6
|
+
stream.write(JSON.stringify(responseSchema.parse(response)) + "\n", "utf-8");
|
|
7
|
+
}
|
|
8
|
+
async function executeReplyHandler(req, request, handler) {
|
|
9
|
+
try {
|
|
10
|
+
const response = await handler(request);
|
|
11
|
+
req.reply(JSON.stringify(responseSchema.parse(response)), "utf-8");
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
sendErrorResponse(req, error);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async function executeStreamHandler(req, request, handler) {
|
|
18
|
+
const stream = req.createResponseStream();
|
|
19
|
+
try {
|
|
20
|
+
for await (const response of handler(request)) {
|
|
21
|
+
stream.write(JSON.stringify(responseSchema.parse(response)) + "\n", "utf-8");
|
|
22
|
+
}
|
|
23
|
+
stream.end();
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
sendStreamErrorResponse(stream, error);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async function executeProgressHandler(req, request, handler) {
|
|
30
|
+
const stream = req.createResponseStream();
|
|
31
|
+
try {
|
|
32
|
+
const response = await handler(request, (update) => writeToStream(stream, update));
|
|
33
|
+
writeToStream(stream, response);
|
|
34
|
+
stream.end();
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
sendStreamErrorResponse(stream, error);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// Unified handler executor with delegation and progress support
|
|
41
|
+
export async function executeHandler(req, request, entry) {
|
|
42
|
+
const handler = entry.delegatedHandler && entry.isDelegated?.(request)
|
|
43
|
+
? entry.delegatedHandler
|
|
44
|
+
: entry.handler;
|
|
45
|
+
const wantsProgress = "withProgress" in request &&
|
|
46
|
+
request.withProgress &&
|
|
47
|
+
(typeof entry.supportsProgress === "function"
|
|
48
|
+
? entry.supportsProgress(request)
|
|
49
|
+
: entry.supportsProgress);
|
|
50
|
+
try {
|
|
51
|
+
if (entry.type === "stream") {
|
|
52
|
+
await executeStreamHandler(req, request, handler);
|
|
53
|
+
}
|
|
54
|
+
else if (wantsProgress) {
|
|
55
|
+
await executeProgressHandler(req, request, handler);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
await executeReplyHandler(req, request, handler);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
sendErrorResponse(req, error);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export function isInitConfigMessage(data) {
|
|
66
|
+
return (typeof data === "object" &&
|
|
67
|
+
data !== null &&
|
|
68
|
+
"type" in data &&
|
|
69
|
+
data.type === "__init_config");
|
|
70
|
+
}
|
|
71
|
+
export function handleInitConfig(req, data) {
|
|
72
|
+
try {
|
|
73
|
+
if (data.config) {
|
|
74
|
+
setSDKConfig(data.config);
|
|
75
|
+
}
|
|
76
|
+
if (data.runtimeContext) {
|
|
77
|
+
setRuntimeContext(data.runtimeContext);
|
|
78
|
+
}
|
|
79
|
+
req.reply(JSON.stringify({ success: true }), "utf-8");
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
req.reply(JSON.stringify({
|
|
83
|
+
success: false,
|
|
84
|
+
error: error instanceof Error ? error.message : String(error),
|
|
85
|
+
}), "utf-8");
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { cancel } from "../../bare/
|
|
1
|
+
import { cancel } from "../../bare/ops/cancel.js";
|
|
2
2
|
import { createCancelFunction } from "./load-model/download-manager.js";
|
|
3
3
|
import { cancelRagOperation, DEFAULT_WORKSPACE, } from "../../bare/rag-hyperdb/index.js";
|
|
4
4
|
import { getServerLogger } from "../../../logging/index.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getModelEntry } from "../../bare/registry/model-registry.js";
|
|
2
2
|
import { getRPC } from "../../bare/delegate-rpc-client.js";
|
|
3
|
-
import { stream } from "
|
|
3
|
+
import { stream } from "../delegate-transport.js";
|
|
4
4
|
import { ModelIsDelegatedError } from "../../../utils/errors-server.js";
|
|
5
5
|
import { getServerLogger } from "../../../logging/index.js";
|
|
6
6
|
const logger = getServerLogger();
|
|
@@ -1,45 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { dispatchPluginStream } from "./plugin-dispatch.js";
|
|
2
2
|
export async function* handleCompletionStream(request) {
|
|
3
|
-
|
|
4
|
-
role,
|
|
5
|
-
content,
|
|
6
|
-
attachments: attachments ?? [],
|
|
7
|
-
}));
|
|
8
|
-
const stream = completion({
|
|
9
|
-
history: filteredHistory,
|
|
10
|
-
modelId: request.modelId,
|
|
11
|
-
kvCache: request.kvCache,
|
|
12
|
-
...(request.tools && { tools: request.tools }),
|
|
13
|
-
});
|
|
14
|
-
let stats;
|
|
15
|
-
let toolCalls = [];
|
|
16
|
-
let done = false;
|
|
17
|
-
let buffer = "";
|
|
18
|
-
while (!done) {
|
|
19
|
-
const result = await stream.next();
|
|
20
|
-
if (result.done) {
|
|
21
|
-
stats = result.value.stats;
|
|
22
|
-
toolCalls = result.value.toolCalls;
|
|
23
|
-
done = true;
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
if (request.stream) {
|
|
27
|
-
yield {
|
|
28
|
-
type: "completionStream",
|
|
29
|
-
token: result.value.token,
|
|
30
|
-
toolCallEvent: result.value.toolCallEvent,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
buffer += result.value.token;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
yield {
|
|
39
|
-
type: "completionStream",
|
|
40
|
-
token: request.stream ? "" : buffer,
|
|
41
|
-
done: true,
|
|
42
|
-
stats,
|
|
43
|
-
toolCalls,
|
|
44
|
-
};
|
|
3
|
+
yield* dispatchPluginStream(request.modelId, "completionStream", request);
|
|
45
4
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { deleteCache as deleteCacheUtil } from "../../bare/
|
|
1
|
+
import { deleteCache as deleteCacheUtil } from "../../bare/ops/kv-cache-utils.js";
|
|
2
2
|
import { getServerLogger } from "../../../logging/index.js";
|
|
3
3
|
const logger = getServerLogger();
|
|
4
4
|
export async function handleDeleteCache(request) {
|
|
@@ -1,23 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getServerLogger } from "../../../logging/index.js";
|
|
3
|
-
const logger = getServerLogger();
|
|
1
|
+
import { dispatchPluginReply } from "./plugin-dispatch.js";
|
|
4
2
|
export async function handleEmbed(request) {
|
|
5
|
-
|
|
6
|
-
try {
|
|
7
|
-
const embedding = await embed({ modelId, text });
|
|
8
|
-
return {
|
|
9
|
-
type: "embed",
|
|
10
|
-
success: true,
|
|
11
|
-
embedding,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
catch (error) {
|
|
15
|
-
logger.error("Error during embedding:", error);
|
|
16
|
-
return {
|
|
17
|
-
type: "embed",
|
|
18
|
-
success: false,
|
|
19
|
-
embedding: [],
|
|
20
|
-
error: error instanceof Error ? error.message : "Unknown error",
|
|
21
|
-
};
|
|
22
|
-
}
|
|
3
|
+
return dispatchPluginReply(request.modelId, "embed", request);
|
|
23
4
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { models } from "../../../models/
|
|
1
|
+
import { models } from "../../../models/registry/models.js";
|
|
2
2
|
import { getAllModelIds, getModelEntry, } from "../../bare/registry/model-registry.js";
|
|
3
3
|
import { getConfiguredCacheDir } from "../../bare/registry/config-registry.js";
|
|
4
4
|
import { generateShortHash } from "../../utils/index.js";
|
|
@@ -6,16 +6,16 @@ import { promises as fsPromises } from "bare-fs";
|
|
|
6
6
|
import path from "bare-path";
|
|
7
7
|
import { getShardPath } from "../../utils/cache.js";
|
|
8
8
|
import { ModelNotFoundError } from "../../../utils/errors-server.js";
|
|
9
|
-
import { normalizeModelType } from "../../../schemas/model-types.js";
|
|
10
9
|
export async function handleGetModelInfo(request) {
|
|
11
10
|
const { name } = request;
|
|
12
11
|
const catalogEntry = models.find((m) => m.name === name);
|
|
13
12
|
if (!catalogEntry) {
|
|
14
13
|
throw new ModelNotFoundError(`${name}" not found in catalog. Use model names from the catalog (e.g., "WHISPER_TINY", "EMBEDDINGGEMMA_300M_Q4_0")`);
|
|
15
14
|
}
|
|
15
|
+
const cacheKey = generateShortHash(catalogEntry.registryPath);
|
|
16
16
|
const cacheStatus = catalogEntry.shardMetadata && catalogEntry.shardMetadata.length > 0
|
|
17
|
-
? await handleShardedModel(
|
|
18
|
-
: await handleSingleFileModel(catalogEntry.
|
|
17
|
+
? await handleShardedModel(cacheKey, catalogEntry.shardMetadata)
|
|
18
|
+
: await handleSingleFileModel(catalogEntry.registryPath, catalogEntry.modelId, catalogEntry.expectedSize, catalogEntry.sha256Checksum);
|
|
19
19
|
const { cacheFiles, isCached, actualSize, cachedAt } = cacheStatus;
|
|
20
20
|
const loadedModelIds = getAllModelIds();
|
|
21
21
|
const loadedInstances = [];
|
|
@@ -35,18 +35,21 @@ export async function handleGetModelInfo(request) {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
const isLoaded = loadedInstances.length > 0;
|
|
38
|
-
// Normalize addon from alias to canonical (vad passes through as-is)
|
|
39
|
-
const normalizedAddon = catalogEntry.addon === "vad"
|
|
40
|
-
? "vad"
|
|
41
|
-
: normalizeModelType(catalogEntry.addon);
|
|
42
38
|
const modelInfo = {
|
|
43
39
|
name: catalogEntry.name,
|
|
44
40
|
modelId: catalogEntry.modelId,
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
registryPath: catalogEntry.registryPath,
|
|
42
|
+
registrySource: catalogEntry.registrySource,
|
|
43
|
+
blobCoreKey: catalogEntry.blobCoreKey,
|
|
44
|
+
blobBlockOffset: catalogEntry.blobBlockOffset,
|
|
45
|
+
blobBlockLength: catalogEntry.blobBlockLength,
|
|
46
|
+
blobByteOffset: catalogEntry.blobByteOffset,
|
|
47
|
+
engine: catalogEntry.engine,
|
|
48
|
+
quantization: catalogEntry.quantization,
|
|
49
|
+
params: catalogEntry.params,
|
|
47
50
|
expectedSize: catalogEntry.expectedSize,
|
|
48
51
|
sha256Checksum: catalogEntry.sha256Checksum,
|
|
49
|
-
addon:
|
|
52
|
+
addon: catalogEntry.addon,
|
|
50
53
|
isCached,
|
|
51
54
|
isLoaded,
|
|
52
55
|
cacheFiles,
|
|
@@ -59,13 +62,13 @@ export async function handleGetModelInfo(request) {
|
|
|
59
62
|
modelInfo,
|
|
60
63
|
};
|
|
61
64
|
}
|
|
62
|
-
async function handleShardedModel(
|
|
65
|
+
async function handleShardedModel(cacheKey, shardMetadata) {
|
|
63
66
|
const cacheFiles = [];
|
|
64
67
|
let allShardsCached = true;
|
|
65
68
|
let totalActualSize = 0;
|
|
66
69
|
let latestCachedAt;
|
|
67
70
|
for (const shard of shardMetadata) {
|
|
68
|
-
const shardPath = getShardPath(
|
|
71
|
+
const shardPath = getShardPath(cacheKey, shard.filename);
|
|
69
72
|
let shardIsCached = false;
|
|
70
73
|
let shardActualSize;
|
|
71
74
|
let shardCachedAt;
|
|
@@ -116,9 +119,10 @@ async function handleShardedModel(hyperdriveKey, shardMetadata) {
|
|
|
116
119
|
}
|
|
117
120
|
return result;
|
|
118
121
|
}
|
|
119
|
-
async function handleSingleFileModel(
|
|
122
|
+
async function handleSingleFileModel(registryPath, modelId, expectedSize, sha256Checksum) {
|
|
120
123
|
const cacheDir = getConfiguredCacheDir();
|
|
121
|
-
|
|
124
|
+
// Use registryPath for hash to match download logic in registry.ts
|
|
125
|
+
const sourceHash = generateShortHash(registryPath);
|
|
122
126
|
const filePath = path.join(cacheDir, `${sourceHash}_${modelId}`);
|
|
123
127
|
let fileIsCached = false;
|
|
124
128
|
let fileActualSize;
|
|
@@ -14,7 +14,11 @@ import { handleDeleteCache } from "./delete-cache";
|
|
|
14
14
|
import { handleTextToSpeech } from "./text-to-speech";
|
|
15
15
|
import { handleGetModelInfo } from "./get-model-info";
|
|
16
16
|
import { handleOCRStream } from "./ocr-stream";
|
|
17
|
+
import { handlePing } from "./ping";
|
|
18
|
+
import { handlePluginInvoke, handlePluginInvokeStream } from "./plugin-invoke";
|
|
19
|
+
import { handleModelRegistryList, handleModelRegistrySearch, handleModelRegistryGetModel } from "./registry";
|
|
17
20
|
export declare const handlers: {
|
|
21
|
+
ping: typeof handlePing;
|
|
18
22
|
completionStream: typeof handleCompletionStream;
|
|
19
23
|
downloadAsset: typeof handleDownloadAsset;
|
|
20
24
|
deleteCache: typeof handleDeleteCache;
|
|
@@ -31,5 +35,10 @@ export declare const handlers: {
|
|
|
31
35
|
textToSpeech: typeof handleTextToSpeech;
|
|
32
36
|
getModelInfo: typeof handleGetModelInfo;
|
|
33
37
|
ocrStream: typeof handleOCRStream;
|
|
38
|
+
pluginInvoke: typeof handlePluginInvoke;
|
|
39
|
+
pluginInvokeStream: typeof handlePluginInvokeStream;
|
|
40
|
+
modelRegistryList: typeof handleModelRegistryList;
|
|
41
|
+
modelRegistrySearch: typeof handleModelRegistrySearch;
|
|
42
|
+
modelRegistryGetModel: typeof handleModelRegistryGetModel;
|
|
34
43
|
};
|
|
35
44
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -14,7 +14,11 @@ import { handleDeleteCache } from "./delete-cache.js";
|
|
|
14
14
|
import { handleTextToSpeech } from "./text-to-speech.js";
|
|
15
15
|
import { handleGetModelInfo } from "./get-model-info.js";
|
|
16
16
|
import { handleOCRStream } from "./ocr-stream.js";
|
|
17
|
+
import { handlePing } from "./ping.js";
|
|
18
|
+
import { handlePluginInvoke, handlePluginInvokeStream } from "./plugin-invoke.js";
|
|
19
|
+
import { handleModelRegistryList, handleModelRegistrySearch, handleModelRegistryGetModel, } from "./registry.js";
|
|
17
20
|
export const handlers = {
|
|
21
|
+
ping: handlePing,
|
|
18
22
|
completionStream: handleCompletionStream,
|
|
19
23
|
downloadAsset: handleDownloadAsset,
|
|
20
24
|
deleteCache: handleDeleteCache,
|
|
@@ -31,4 +35,9 @@ export const handlers = {
|
|
|
31
35
|
textToSpeech: handleTextToSpeech,
|
|
32
36
|
getModelInfo: handleGetModelInfo,
|
|
33
37
|
ocrStream: handleOCRStream,
|
|
38
|
+
pluginInvoke: handlePluginInvoke,
|
|
39
|
+
pluginInvokeStream: handlePluginInvokeStream,
|
|
40
|
+
modelRegistryList: handleModelRegistryList,
|
|
41
|
+
modelRegistrySearch: handleModelRegistrySearch,
|
|
42
|
+
modelRegistryGetModel: handleModelRegistryGetModel,
|
|
34
43
|
};
|
|
@@ -4,6 +4,7 @@ export declare function registerDownload(key: string, entry: DownloadEntry): voi
|
|
|
4
4
|
export declare function unregisterDownload(key: string): void;
|
|
5
5
|
export declare function createHyperdriveDownloadKey(hyperdriveKey: string, modelFileName: string): string;
|
|
6
6
|
export declare function createHttpDownloadKey(url: string): string;
|
|
7
|
+
export declare function createRegistryDownloadKey(registryPath: string): string;
|
|
7
8
|
export declare function setClearCacheFlag(downloadKey: string, clearCache: boolean): void;
|
|
8
9
|
export declare function shouldClearCache(downloadKey: string): boolean;
|
|
9
10
|
export declare function clearClearCacheFlag(downloadKey: string): void;
|
|
@@ -18,6 +18,9 @@ export function createHyperdriveDownloadKey(hyperdriveKey, modelFileName) {
|
|
|
18
18
|
export function createHttpDownloadKey(url) {
|
|
19
19
|
return `http:${url}`;
|
|
20
20
|
}
|
|
21
|
+
export function createRegistryDownloadKey(registryPath) {
|
|
22
|
+
return `registry:${registryPath}`;
|
|
23
|
+
}
|
|
21
24
|
export function setClearCacheFlag(downloadKey, clearCache) {
|
|
22
25
|
if (clearCache) {
|
|
23
26
|
clearCacheFlags.set(downloadKey, true);
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { normalizeModelType, ModelType } from "../../../../schemas/index.js";
|
|
2
2
|
import { hyperdriveUrlSchema } from "../../../../schemas/load-model.js";
|
|
3
|
-
import { loadModel } from "../../../bare/
|
|
3
|
+
import { loadModel } from "../../../bare/ops/load-model.js";
|
|
4
4
|
import { resolveModelPath } from "./resolve.js";
|
|
5
5
|
import { getModelEntry, updateModelConfig, } from "../../../bare/registry/model-registry.js";
|
|
6
6
|
import { generateShortHash, transformConfigForReload } from "../../../utils/index.js";
|
|
7
|
-
import {
|
|
7
|
+
import { ConfigReloadNotSupportedError, ModelTypeMismatchError, ModelIsDelegatedError, ModelNotFoundError, } from "../../../../utils/errors-server.js";
|
|
8
8
|
import { getServerLogger } from "../../../../logging/index.js";
|
|
9
|
+
import { OCR_CRAFT_DETECTOR } from "../../../../models/registry/index.js";
|
|
10
|
+
import { getPlugin } from "../../../plugins/index.js";
|
|
9
11
|
const logger = getServerLogger();
|
|
10
12
|
const OCR_DETECTOR_FILENAME = "detector_craft.onnx";
|
|
11
13
|
export async function handleLoadModel(request, progressCallback) {
|
|
@@ -14,7 +16,7 @@ export async function handleLoadModel(request, progressCallback) {
|
|
|
14
16
|
return handleConfigReload(request);
|
|
15
17
|
}
|
|
16
18
|
// Handle load new model from source
|
|
17
|
-
const { modelSrc, modelName, seed, projectionModelSrc, vadModelSrc
|
|
19
|
+
const { modelSrc, modelName, seed, projectionModelSrc, vadModelSrc } = request;
|
|
18
20
|
const canonicalModelType = normalizeModelType(request.modelType);
|
|
19
21
|
const srcVocabSrc = canonicalModelType === ModelType.nmtcppTranslation
|
|
20
22
|
? request.srcVocabSrc
|
|
@@ -22,9 +24,6 @@ export async function handleLoadModel(request, progressCallback) {
|
|
|
22
24
|
const dstVocabSrc = canonicalModelType === ModelType.nmtcppTranslation
|
|
23
25
|
? request.dstVocabSrc
|
|
24
26
|
: undefined;
|
|
25
|
-
const eSpeakDataPath = canonicalModelType === ModelType.onnxTts
|
|
26
|
-
? request.eSpeakDataPath
|
|
27
|
-
: undefined;
|
|
28
27
|
const detectorModelSrc = canonicalModelType === ModelType.onnxOcr
|
|
29
28
|
? request.detectorModelSrc
|
|
30
29
|
: undefined;
|
|
@@ -38,11 +37,7 @@ export async function handleLoadModel(request, progressCallback) {
|
|
|
38
37
|
if (vadModelSrc) {
|
|
39
38
|
vadModelPath = await resolveModelPath(vadModelSrc, progressCallback, seed);
|
|
40
39
|
}
|
|
41
|
-
|
|
42
|
-
if (configSrc) {
|
|
43
|
-
ttsConfigModelPath = await resolveModelPath(configSrc, progressCallback, seed);
|
|
44
|
-
}
|
|
45
|
-
// For OCR models: use provided detectorModelSrc or auto-derive from same hyperdrive key
|
|
40
|
+
// For OCR models: use provided detectorModelSrc or auto-derive
|
|
46
41
|
let detectorModelPath;
|
|
47
42
|
if (canonicalModelType === ModelType.onnxOcr) {
|
|
48
43
|
if (detectorModelSrc) {
|
|
@@ -53,13 +48,9 @@ export async function handleLoadModel(request, progressCallback) {
|
|
|
53
48
|
const derivedDetectorSrc = `pear://${key}/${OCR_DETECTOR_FILENAME}`;
|
|
54
49
|
detectorModelPath = await resolveModelPath(derivedDetectorSrc, progressCallback, seed);
|
|
55
50
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
throw new TTSConfigModelRequiredError();
|
|
60
|
-
}
|
|
61
|
-
if (canonicalModelType === ModelType.onnxTts && !eSpeakDataPath) {
|
|
62
|
-
throw new ESpeakDataPathRequiredError();
|
|
51
|
+
else if (modelSrc.startsWith("registry://")) {
|
|
52
|
+
detectorModelPath = await resolveModelPath(OCR_CRAFT_DETECTOR, progressCallback, seed);
|
|
53
|
+
}
|
|
63
54
|
}
|
|
64
55
|
// For Bergamot models, resolve vocabulary sources to local paths
|
|
65
56
|
if (canonicalModelType === ModelType.nmtcppTranslation &&
|
|
@@ -68,8 +59,12 @@ export async function handleLoadModel(request, progressCallback) {
|
|
|
68
59
|
if (nmtConfig.engine === "Bergamot") {
|
|
69
60
|
let resolvedSrcVocabSrc = srcVocabSrc;
|
|
70
61
|
let resolvedDstVocabSrc = dstVocabSrc;
|
|
71
|
-
if (
|
|
72
|
-
const derivedVocabSrcs =
|
|
62
|
+
if (!srcVocabSrc || !dstVocabSrc) {
|
|
63
|
+
const derivedVocabSrcs = modelSrc.startsWith("pear://")
|
|
64
|
+
? deriveBergamotVocabSources(modelSrc)
|
|
65
|
+
: modelSrc.startsWith("registry://")
|
|
66
|
+
? deriveBergamotRegistryVocabSources(modelSrc)
|
|
67
|
+
: null;
|
|
73
68
|
if (derivedVocabSrcs) {
|
|
74
69
|
resolvedSrcVocabSrc = srcVocabSrc ?? derivedVocabSrcs.srcVocabSrc;
|
|
75
70
|
resolvedDstVocabSrc = dstVocabSrc ?? derivedVocabSrcs.dstVocabSrc;
|
|
@@ -83,18 +78,27 @@ export async function handleLoadModel(request, progressCallback) {
|
|
|
83
78
|
}
|
|
84
79
|
}
|
|
85
80
|
}
|
|
86
|
-
//
|
|
81
|
+
// Use plugin's resolveConfig hook if available to resolve model sources
|
|
82
|
+
let resolvedModelConfig = request.modelConfig;
|
|
83
|
+
const plugin = getPlugin(canonicalModelType);
|
|
84
|
+
if (plugin?.resolveConfig && resolvedModelConfig) {
|
|
85
|
+
const resolve = (src) => resolveModelPath(src, progressCallback, seed);
|
|
86
|
+
resolvedModelConfig = await plugin.resolveConfig(resolvedModelConfig, resolve);
|
|
87
|
+
}
|
|
88
|
+
// Generate hash-based modelId from modelConfig (includes all sources for TTS)
|
|
87
89
|
const configStr = JSON.stringify(request.modelConfig, Object.keys(request.modelConfig).sort());
|
|
88
90
|
const modelHashInput = `${request.modelType}:${modelSrc}:${configStr}`;
|
|
89
91
|
const modelId = generateShortHash(modelHashInput);
|
|
92
|
+
const loadModelOptions = {
|
|
93
|
+
...request,
|
|
94
|
+
modelConfig: resolvedModelConfig,
|
|
95
|
+
};
|
|
90
96
|
await loadModel({
|
|
91
97
|
modelId,
|
|
92
98
|
modelPath,
|
|
93
|
-
options:
|
|
99
|
+
options: loadModelOptions,
|
|
94
100
|
projectionModelPath,
|
|
95
101
|
vadModelPath,
|
|
96
|
-
ttsConfigModelPath,
|
|
97
|
-
eSpeakDataPath,
|
|
98
102
|
detectorModelPath,
|
|
99
103
|
modelName,
|
|
100
104
|
});
|
|
@@ -177,3 +181,22 @@ function deriveBergamotVocabSources(modelSrc) {
|
|
|
177
181
|
dstVocabSrc: sharedVocab,
|
|
178
182
|
};
|
|
179
183
|
}
|
|
184
|
+
function deriveBergamotRegistryVocabSources(modelSrc) {
|
|
185
|
+
// registry://s3/path/to/model.enfr.intgemm.alphas.bin
|
|
186
|
+
const match = modelSrc.match(/^(registry:\/\/.+\/)model\.([a-z]+)\.intgemm\.alphas\.bin$/);
|
|
187
|
+
if (!match || !match[1] || !match[2])
|
|
188
|
+
return null;
|
|
189
|
+
const basePath = match[1];
|
|
190
|
+
const langPair = match[2];
|
|
191
|
+
if (BERGAMOT_CJK_LANG_PAIRS.includes(langPair)) {
|
|
192
|
+
return {
|
|
193
|
+
srcVocabSrc: `${basePath}srcvocab.${langPair}.spm`,
|
|
194
|
+
dstVocabSrc: `${basePath}trgvocab.${langPair}.spm`,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
const sharedVocab = `${basePath}vocab.${langPair}.spm`;
|
|
198
|
+
return {
|
|
199
|
+
srcVocabSrc: sharedVocab,
|
|
200
|
+
dstVocabSrc: sharedVocab,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
@@ -4,7 +4,7 @@ import { Readable } from "bare-stream";
|
|
|
4
4
|
import fetch from "bare-fetch";
|
|
5
5
|
import { AbortController } from "bare-abort-controller";
|
|
6
6
|
import { withTimeout } from "../../../../utils/withTimeout.js";
|
|
7
|
-
import { getModelsCacheDir, getShardedModelCacheDir, generateShortHash, detectShardedModel, parsePatternBasedShardUrl, extractTensorsFromShards, calculatePercentage, isArchiveUrl, extractAndValidateShardedArchive, validateShardedModelCache, checkAllShardsExist, generateShardFilenames, hasValidGGUFHeader, } from "../../../utils/index.js";
|
|
7
|
+
import { getModelsCacheDir, getShardedModelCacheDir, generateShortHash, detectShardedModel, parsePatternBasedShardUrl, extractTensorsFromShards, calculatePercentage, isArchiveUrl, sanitizePathComponent, extractAndValidateShardedArchive, validateShardedModelCache, checkAllShardsExist, generateShardFilenames, hasValidGGUFHeader, } from "../../../utils/index.js";
|
|
8
8
|
import { getSDKConfig } from "../../../bare/registry/config-registry.js";
|
|
9
9
|
import { getActiveDownload, registerDownload, unregisterDownload, createHttpDownloadKey, shouldClearCache, clearClearCacheFlag, } from "./download-manager.js";
|
|
10
10
|
import { DownloadCancelledError, HTTPError, NoResponseBodyError, PartialDownloadOfflineError, ResponseBodyNotReadableError, } from "../../../../utils/errors-server.js";
|
|
@@ -18,7 +18,8 @@ function extractFilenameFromUrl(url) {
|
|
|
18
18
|
const filename = urlParts[urlParts.length - 1] || "model.gguf";
|
|
19
19
|
// Remove query parameters if present
|
|
20
20
|
const cleanFilename = filename.split("?")[0] || "model.gguf";
|
|
21
|
-
|
|
21
|
+
// Sanitize to prevent path traversal via crafted URLs
|
|
22
|
+
return sanitizePathComponent(cleanFilename);
|
|
22
23
|
}
|
|
23
24
|
async function validateCachedFile(modelPath, url, signal) {
|
|
24
25
|
try {
|
|
@@ -5,9 +5,9 @@ import Hyperswarm, {} from "hyperswarm";
|
|
|
5
5
|
import Hyperdrive from "hyperdrive";
|
|
6
6
|
import {} from "bare-stream";
|
|
7
7
|
import { AbortController } from "bare-abort-controller";
|
|
8
|
-
import { getEnv } from "../../../
|
|
8
|
+
import { getEnv } from "../../../env.js";
|
|
9
9
|
import { getModelsCacheDir, generateShortHash, detectShardedModel, getShardedModelCacheDir, getShardPath, checkShardCompleteness, calculateFileChecksum, extractTensorsFromShards, calculatePercentage, } from "../../../utils/index.js";
|
|
10
|
-
import { getModelBySrc } from "../../../../models/
|
|
10
|
+
import { getModelBySrc } from "../../../../models/registry/index.js";
|
|
11
11
|
import { getActiveDownload, registerDownload, unregisterDownload, createHyperdriveDownloadKey, shouldClearCache, clearClearCacheFlag, } from "./download-manager.js";
|
|
12
12
|
import { getSDKConfig } from "../../../bare/registry/config-registry.js";
|
|
13
13
|
import { FileNotFoundError, ChecksumValidationFailedError, DownloadCancelledError, HyperdriveDownloadFailedError, ModelLoadFailedError, NoBlobFoundError, } from "../../../../utils/errors-server.js";
|
|
@@ -185,6 +185,7 @@ async function downloadSingleFileToFilesystem(modelPath, modelFileName, hyperdri
|
|
|
185
185
|
});
|
|
186
186
|
};
|
|
187
187
|
signal?.addEventListener("abort", cleanup);
|
|
188
|
+
let downloadSucceeded = false;
|
|
188
189
|
try {
|
|
189
190
|
const progressContext = progressCallback
|
|
190
191
|
? {
|
|
@@ -211,10 +212,7 @@ async function downloadSingleFileToFilesystem(modelPath, modelFileName, hyperdri
|
|
|
211
212
|
// Ignore stat errors
|
|
212
213
|
}
|
|
213
214
|
}
|
|
214
|
-
|
|
215
|
-
if (!seed) {
|
|
216
|
-
await deleteCorestoreDirectory(setup.corestoreDir);
|
|
217
|
-
}
|
|
215
|
+
downloadSucceeded = true;
|
|
218
216
|
}
|
|
219
217
|
catch (error) {
|
|
220
218
|
logger.error("❌ Error during hyperdrive download:", error instanceof Error ? error.message : String(error));
|
|
@@ -228,6 +226,10 @@ async function downloadSingleFileToFilesystem(modelPath, modelFileName, hyperdri
|
|
|
228
226
|
signal?.removeEventListener("abort", cleanup);
|
|
229
227
|
if (!seed) {
|
|
230
228
|
await cleanupHyperdrive(setup);
|
|
229
|
+
// Delete only after close - Windows EBUSY on LOCK if deleted before corestore.close()
|
|
230
|
+
if (downloadSucceeded) {
|
|
231
|
+
await deleteCorestoreDirectory(corestoreDir);
|
|
232
|
+
}
|
|
231
233
|
}
|
|
232
234
|
// Only delete corestore and partial file if user explicitly requested clearCache
|
|
233
235
|
if (signal?.aborted && shouldClearCache(downloadKey)) {
|
|
@@ -409,6 +411,7 @@ async function downloadShardedFilesToFilesystem(hyperdriveKey, firstShardFileNam
|
|
|
409
411
|
});
|
|
410
412
|
};
|
|
411
413
|
signal?.addEventListener("abort", cleanup);
|
|
414
|
+
let downloadSucceeded = false;
|
|
412
415
|
try {
|
|
413
416
|
// Calculate overall progress
|
|
414
417
|
const overallTotal = shardMetadata.reduce((sum, shard) => sum + shard.expectedSize, 0);
|
|
@@ -485,10 +488,7 @@ async function downloadShardedFilesToFilesystem(hyperdriveKey, firstShardFileNam
|
|
|
485
488
|
});
|
|
486
489
|
}
|
|
487
490
|
await extractTensorsFromShards(shardDir, firstShardFileName);
|
|
488
|
-
|
|
489
|
-
if (!seed) {
|
|
490
|
-
await deleteCorestoreDirectory(corestoreDir);
|
|
491
|
-
}
|
|
491
|
+
downloadSucceeded = true;
|
|
492
492
|
}
|
|
493
493
|
catch (error) {
|
|
494
494
|
logger.error("❌ Error during sharded hyperdrive download:", error instanceof Error ? error.message : String(error));
|
|
@@ -502,6 +502,10 @@ async function downloadShardedFilesToFilesystem(hyperdriveKey, firstShardFileNam
|
|
|
502
502
|
signal?.removeEventListener("abort", cleanup);
|
|
503
503
|
if (!seed) {
|
|
504
504
|
await cleanupHyperdrive(setup);
|
|
505
|
+
// Delete only after close - Windows EBUSY on LOCK if deleted before corestore.close()
|
|
506
|
+
if (downloadSucceeded) {
|
|
507
|
+
await deleteCorestoreDirectory(corestoreDir);
|
|
508
|
+
}
|
|
505
509
|
}
|
|
506
510
|
// Only delete corestore and partial files if user explicitly requested clearCache
|
|
507
511
|
const downloadKey = createHyperdriveDownloadKey(hyperdriveKey, firstShardFileName);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ModelProgressUpdate } from "../../../../schemas/index";
|
|
2
|
+
/**
|
|
3
|
+
* Download a model from the QVAC Registry.
|
|
4
|
+
*
|
|
5
|
+
* For known models (present in models.ts), uses direct blob download which
|
|
6
|
+
* skips the registry metadata sync entirely. Falls back to metadata-based
|
|
7
|
+
* download for unknown models.
|
|
8
|
+
*/
|
|
9
|
+
export declare function downloadModelFromRegistry(registryPath: string, registrySource: string, progressCallback?: (progress: ModelProgressUpdate) => void, expectedChecksum?: string): Promise<string>;
|
|
10
|
+
//# sourceMappingURL=registry.d.ts.map
|