@qvac/sdk 0.9.1 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +15 -68
- package/dist/client/api/cancel.d.ts +1 -1
- package/dist/client/api/cancel.js +1 -1
- package/dist/client/api/completion-stream.d.ts +51 -12
- package/dist/client/api/completion-stream.js +129 -56
- package/dist/client/api/delete-cache.d.ts +1 -0
- package/dist/client/api/delete-cache.js +1 -0
- package/dist/client/api/diffusion.d.ts +17 -2
- package/dist/client/api/diffusion.js +21 -4
- package/dist/client/api/embed.d.ts +4 -0
- package/dist/client/api/finetune.d.ts +21 -0
- package/dist/client/api/get-loaded-model-info.d.ts +25 -0
- package/dist/client/api/get-loaded-model-info.js +36 -0
- package/dist/client/api/get-model-info.d.ts +9 -1
- package/dist/client/api/get-model-info.js +8 -0
- package/dist/client/api/heartbeat.d.ts +2 -2
- package/dist/client/api/heartbeat.js +2 -2
- package/dist/client/api/index.d.ts +3 -1
- package/dist/client/api/index.js +3 -1
- package/dist/client/api/invoke-plugin.d.ts +16 -0
- package/dist/client/api/invoke-plugin.js +16 -0
- package/dist/client/api/load-model.d.ts +36 -3
- package/dist/client/api/load-model.js +31 -10
- package/dist/client/api/provide.d.ts +11 -5
- package/dist/client/api/provide.js +11 -6
- package/dist/client/api/rag.d.ts +9 -0
- package/dist/client/api/rag.js +9 -0
- package/dist/client/api/registry.d.ts +26 -0
- package/dist/client/api/registry.js +26 -0
- package/dist/client/api/resume.d.ts +20 -4
- package/dist/client/api/resume.js +20 -4
- package/dist/client/api/state.d.ts +23 -0
- package/dist/client/api/state.js +29 -0
- package/dist/client/api/stop-provider.d.ts +11 -5
- package/dist/client/api/stop-provider.js +11 -5
- package/dist/client/api/suspend.d.ts +21 -3
- package/dist/client/api/suspend.js +21 -3
- package/dist/client/api/text-to-speech.d.ts +64 -6
- package/dist/client/api/text-to-speech.js +423 -47
- package/dist/client/api/transcribe.d.ts +29 -4
- package/dist/client/api/transcribe.js +86 -28
- package/dist/client/api/translate.d.ts +1 -0
- package/dist/client/api/translate.js +1 -0
- package/dist/client/rpc/bare-client.js +22 -1
- package/dist/client/rpc/expo-rpc-client.d.ts +1 -1
- package/dist/client/rpc/expo-rpc-client.js +96 -4
- package/dist/client/rpc/node-rpc-client.js +36 -0
- package/dist/examples/audio/mic-input.d.ts +9 -0
- package/dist/examples/audio/mic-input.js +111 -0
- package/dist/examples/completion-events.d.ts +18 -0
- package/dist/examples/completion-events.js +79 -0
- package/dist/examples/delegated-inference/composite.js +12 -18
- package/dist/examples/delegated-inference/consumer-profiled.js +4 -11
- package/dist/examples/delegated-inference/consumer.js +8 -13
- package/dist/examples/delegated-inference/provider.js +11 -16
- package/dist/examples/diffusion-flux2-klein-img2img.d.ts +2 -0
- package/dist/examples/diffusion-flux2-klein-img2img.js +60 -0
- package/dist/examples/diffusion-flux2-klein.js +1 -0
- package/dist/examples/diffusion-img2img.d.ts +2 -0
- package/dist/examples/diffusion-img2img.js +49 -0
- package/dist/examples/diffusion-txt2img.js +2 -1
- package/dist/examples/kv-cache-example.js +11 -12
- package/dist/examples/llamacpp-cache.d.ts +2 -0
- package/dist/examples/llamacpp-cache.js +107 -0
- package/dist/examples/llamacpp-dynamic-tools.d.ts +2 -0
- package/dist/examples/llamacpp-dynamic-tools.js +144 -0
- package/dist/examples/llamacpp-native-tools.js +2 -8
- package/dist/examples/llamacpp-structured-output.d.ts +2 -0
- package/dist/examples/llamacpp-structured-output.js +106 -0
- package/dist/examples/llamacpp-tools-pythonic.d.ts +2 -0
- package/dist/examples/llamacpp-tools-pythonic.js +69 -0
- package/dist/examples/plugins.js +4 -4
- package/dist/examples/suspend-resume.js +21 -4
- package/dist/examples/transcription/parakeet-microphone-record.js +6 -33
- package/dist/examples/transcription/whispercpp-filesystem-streaming.js +7 -5
- package/dist/examples/transcription/whispercpp-filesystem.js +12 -3
- package/dist/examples/transcription/whispercpp-microphone-record.js +6 -29
- package/dist/examples/translation/translation-stream.js +5 -5
- package/dist/examples/tts/llm-to-tts-streaming.d.ts +16 -0
- package/dist/examples/tts/llm-to-tts-streaming.js +143 -0
- package/dist/examples/tts/supertonic-multilingual.js +3 -3
- package/dist/examples/tts/supertonic.js +3 -3
- package/dist/examples/tts/utils.d.ts +11 -1
- package/dist/examples/tts/utils.js +70 -17
- package/dist/examples/voice-assistant/voice-assistant.d.ts +2 -0
- package/dist/examples/voice-assistant/voice-assistant.js +207 -0
- package/dist/expo/plugins/withMobileBundle.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/logging/logger.d.ts +11 -0
- package/dist/logging/logger.js +11 -0
- package/dist/logging/types.d.ts +18 -0
- package/dist/models/registry/models.d.ts +6620 -6185
- package/dist/models/registry/models.js +6296 -5318
- package/dist/models/update-models/codegen.js +84 -23
- package/dist/models/update-models/companions.d.ts +18 -0
- package/dist/models/update-models/companions.js +175 -0
- package/dist/models/update-models/naming.js +0 -25
- package/dist/models/update-models/registry.js +4 -2
- package/dist/models/update-models/types.d.ts +37 -9
- package/dist/profiling/index.d.ts +49 -0
- package/dist/profiling/index.js +49 -0
- package/dist/schemas/cancel.d.ts +6 -2
- package/dist/schemas/cancel.js +14 -7
- package/dist/schemas/common.d.ts +361 -279
- package/dist/schemas/common.js +26 -5
- package/dist/schemas/completion-event.d.ts +225 -0
- package/dist/schemas/completion-event.js +79 -0
- package/dist/schemas/completion-stream.d.ts +122 -31
- package/dist/schemas/completion-stream.js +137 -36
- package/dist/schemas/delegate.d.ts +0 -2
- package/dist/schemas/delegate.js +25 -6
- package/dist/schemas/download-asset.d.ts +5 -5
- package/dist/schemas/embed.js +21 -9
- package/dist/schemas/engine-addon-map.d.ts +11 -1
- package/dist/schemas/engine-addon-map.js +2 -2
- package/dist/schemas/finetune.d.ts +16 -16
- package/dist/schemas/finetune.js +8 -8
- package/dist/schemas/get-loaded-model-info.d.ts +52 -0
- package/dist/schemas/get-loaded-model-info.js +44 -0
- package/dist/schemas/get-model-info.d.ts +2 -2
- package/dist/schemas/get-model-info.js +103 -32
- package/dist/schemas/heartbeat.d.ts +0 -1
- package/dist/schemas/index.d.ts +4 -1
- package/dist/schemas/index.js +4 -1
- package/dist/schemas/llamacpp-config.d.ts +14 -4
- package/dist/schemas/llamacpp-config.js +5 -0
- package/dist/schemas/load-model.d.ts +3233 -1260
- package/dist/schemas/load-model.js +23 -16
- package/dist/schemas/model-src-utils.d.ts +7 -6
- package/dist/schemas/model-src-utils.js +27 -1
- package/dist/schemas/model-types.d.ts +4 -4
- package/dist/schemas/ocr.d.ts +1 -1
- package/dist/schemas/plugin.d.ts +27 -3
- package/dist/schemas/plugin.js +27 -2
- package/dist/schemas/profiling.js +11 -3
- package/dist/schemas/provide.d.ts +1 -3
- package/dist/schemas/provide.js +0 -3
- package/dist/schemas/rag.d.ts +4 -4
- package/dist/schemas/registry.d.ts +10 -10
- package/dist/schemas/registry.js +36 -14
- package/dist/schemas/reload-config.d.ts +73 -7
- package/dist/schemas/sdcpp-config.d.ts +16 -8
- package/dist/schemas/sdcpp-config.js +118 -25
- package/dist/schemas/sdk-config.d.ts +116 -90
- package/dist/schemas/sdk-config.js +16 -0
- package/dist/schemas/sdk-errors-client.d.ts +3 -0
- package/dist/schemas/sdk-errors-client.js +16 -1
- package/dist/schemas/sdk-errors-server.d.ts +3 -0
- package/dist/schemas/sdk-errors-server.js +23 -0
- package/dist/schemas/state.d.ts +23 -0
- package/dist/schemas/state.js +14 -0
- package/dist/schemas/stop-provide.d.ts +0 -5
- package/dist/schemas/stop-provide.js +2 -6
- package/dist/schemas/text-to-speech.d.ts +93 -27
- package/dist/schemas/text-to-speech.js +27 -0
- package/dist/schemas/tools.d.ts +16 -0
- package/dist/schemas/tools.js +15 -0
- package/dist/schemas/transcription-config.d.ts +8 -8
- package/dist/schemas/transcription.d.ts +33 -0
- package/dist/schemas/transcription.js +9 -0
- package/dist/schemas/translate.js +59 -19
- package/dist/schemas/translation-config.d.ts +157 -133
- package/dist/schemas/translation-config.js +34 -11
- package/dist/server/bare/delegate-rpc-client.d.ts +1 -1
- package/dist/server/bare/delegate-rpc-client.js +131 -122
- package/dist/server/bare/hyperswarm.d.ts +2 -2
- package/dist/server/bare/hyperswarm.js +12 -7
- package/dist/server/bare/ops/cancel.js +7 -0
- package/dist/server/bare/ops/kv-cache-utils.d.ts +7 -10
- package/dist/server/bare/ops/kv-cache-utils.js +31 -40
- package/dist/server/bare/ops/load-model.js +0 -1
- package/dist/server/bare/ops/transcribe.d.ts +11 -4
- package/dist/server/bare/ops/transcribe.js +25 -4
- package/dist/server/bare/ops/translate.js +42 -4
- package/dist/server/bare/ops/unload-model.js +21 -19
- package/dist/server/bare/plugins/llamacpp-completion/ops/cache-logger.js +1 -2
- package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.d.ts +13 -8
- package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.js +257 -85
- package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-state.d.ts +101 -0
- package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-state.js +135 -0
- package/dist/server/bare/plugins/llamacpp-completion/plugin.d.ts +83 -26
- package/dist/server/bare/plugins/llamacpp-completion/plugin.js +57 -32
- package/dist/server/bare/plugins/llamacpp-embedding/plugin.js +10 -16
- package/dist/server/bare/plugins/nmtcpp-translation/plugin.d.ts +69 -44
- package/dist/server/bare/plugins/nmtcpp-translation/plugin.js +113 -94
- package/dist/server/bare/plugins/onnx-ocr/plugin.d.ts +1 -1
- package/dist/server/bare/plugins/onnx-ocr/plugin.js +1 -2
- package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech-stream.d.ts +7 -0
- package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech-stream.js +116 -0
- package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech.d.ts +2 -3
- package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech.js +71 -9
- package/dist/server/bare/plugins/onnx-tts/plugin.d.ts +41 -13
- package/dist/server/bare/plugins/onnx-tts/plugin.js +48 -3
- package/dist/server/bare/plugins/parakeet-transcription/plugin.d.ts +15 -7
- package/dist/server/bare/plugins/parakeet-transcription/plugin.js +5 -6
- package/dist/server/bare/plugins/sdcpp-generation/ops/diffusion.js +6 -0
- package/dist/server/bare/plugins/sdcpp-generation/plugin.d.ts +8 -5
- package/dist/server/bare/plugins/sdcpp-generation/plugin.js +13 -13
- package/dist/server/bare/plugins/whispercpp-transcription/plugin.d.ts +17 -1
- package/dist/server/bare/plugins/whispercpp-transcription/plugin.js +40 -17
- package/dist/server/bare/registry/config-registry.js +14 -3
- package/dist/server/bare/registry/model-registry.d.ts +8 -10
- package/dist/server/bare/registry/model-registry.js +17 -12
- package/dist/server/bare/registry/registry-client.js +79 -19
- package/dist/server/bare/runtime-lifecycle.d.ts +2 -1
- package/dist/server/bare/runtime-lifecycle.js +13 -2
- package/dist/server/bare/types/addon-responses.d.ts +8 -3
- package/dist/server/bare/utils/transcribe-metadata.d.ts +21 -0
- package/dist/server/bare/utils/transcribe-metadata.js +28 -0
- package/dist/server/bare/utils/tts-stats.d.ts +22 -0
- package/dist/server/bare/utils/tts-stats.js +10 -0
- package/dist/server/rpc/create-server.d.ts +4 -1
- package/dist/server/rpc/create-server.js +5 -1
- package/dist/server/rpc/delegate-transport.js +36 -29
- package/dist/server/rpc/handle-request.js +28 -3
- package/dist/server/rpc/handler-registry.js +7 -1
- package/dist/server/rpc/handler-utils.d.ts +5 -0
- package/dist/server/rpc/handler-utils.js +22 -0
- package/dist/server/rpc/handlers/cancel-delegated.js +3 -5
- package/dist/server/rpc/handlers/cancelHandler.js +4 -5
- package/dist/server/rpc/handlers/completion-stream-delegated.js +14 -5
- package/dist/server/rpc/handlers/delete-cache.js +8 -3
- package/dist/server/rpc/handlers/download-asset.js +3 -24
- package/dist/server/rpc/handlers/get-loaded-model-info.d.ts +3 -0
- package/dist/server/rpc/handlers/get-loaded-model-info.js +39 -0
- package/dist/server/rpc/handlers/get-model-info.js +93 -84
- package/dist/server/rpc/handlers/heartbeat-delegated.js +2 -2
- package/dist/server/rpc/handlers/index.d.ts +6 -0
- package/dist/server/rpc/handlers/index.js +6 -0
- package/dist/server/rpc/handlers/load-model/download-manager.d.ts +35 -9
- package/dist/server/rpc/handlers/load-model/download-manager.js +142 -38
- package/dist/server/rpc/handlers/load-model/download-stats.d.ts +5 -4
- package/dist/server/rpc/handlers/load-model/download-stats.js +49 -8
- package/dist/server/rpc/handlers/load-model/handler.js +31 -50
- package/dist/server/rpc/handlers/load-model/http.d.ts +2 -2
- package/dist/server/rpc/handlers/load-model/http.js +97 -142
- package/dist/server/rpc/handlers/load-model/hyperdrive.d.ts +2 -2
- package/dist/server/rpc/handlers/load-model/hyperdrive.js +55 -74
- package/dist/server/rpc/handlers/load-model/index.d.ts +0 -1
- package/dist/server/rpc/handlers/load-model/index.js +0 -1
- package/dist/server/rpc/handlers/load-model/registry-client-options.d.ts +27 -0
- package/dist/server/rpc/handlers/load-model/registry-client-options.js +19 -0
- package/dist/server/rpc/handlers/load-model/registry-companion-set.d.ts +22 -0
- package/dist/server/rpc/handlers/load-model/registry-companion-set.js +208 -0
- package/dist/server/rpc/handlers/load-model/registry-download-utils.d.ts +24 -0
- package/dist/server/rpc/handlers/load-model/registry-download-utils.js +114 -0
- package/dist/server/rpc/handlers/load-model/registry.d.ts +2 -20
- package/dist/server/rpc/handlers/load-model/registry.js +109 -381
- package/dist/server/rpc/handlers/load-model/resolve-session.d.ts +15 -0
- package/dist/server/rpc/handlers/load-model/resolve-session.js +61 -0
- package/dist/server/rpc/handlers/load-model/resolve.d.ts +3 -3
- package/dist/server/rpc/handlers/load-model/resolve.js +14 -23
- package/dist/server/rpc/handlers/load-model/types.d.ts +11 -4
- package/dist/server/rpc/handlers/load-model/types.js +28 -1
- package/dist/server/rpc/handlers/load-model-delegated.js +2 -4
- package/dist/server/rpc/handlers/plugin-dispatch.js +9 -5
- package/dist/server/rpc/handlers/plugin-invoke.js +1 -1
- package/dist/server/rpc/handlers/provideHandler/connection.js +13 -2
- package/dist/server/rpc/handlers/provideHandler/handler.js +42 -29
- package/dist/server/rpc/handlers/state.d.ts +3 -0
- package/dist/server/rpc/handlers/state.js +7 -0
- package/dist/server/rpc/handlers/stopProvideHandler.d.ts +2 -2
- package/dist/server/rpc/handlers/stopProvideHandler.js +12 -7
- package/dist/server/rpc/handlers/text-to-speech-stream.d.ts +3 -0
- package/dist/server/rpc/handlers/text-to-speech-stream.js +4 -0
- package/dist/server/rpc/handlers/unload-model-delegated.js +3 -3
- package/dist/server/rpc/profiling/operation-metrics.js +20 -0
- package/dist/server/rpc/rpc-utils.js +1 -1
- package/dist/server/rpc/transport-selector.d.ts +3 -0
- package/dist/server/rpc/transport-selector.js +18 -0
- package/dist/server/utils/cache/auto-history.d.ts +4 -0
- package/dist/server/utils/cache/auto-history.js +22 -0
- package/dist/server/utils/{cache.d.ts → cache/paths.d.ts} +22 -5
- package/dist/server/utils/{cache.js → cache/paths.js} +36 -20
- package/dist/server/utils/cache/types.d.ts +8 -0
- package/dist/server/utils/cache/types.js +1 -0
- package/dist/server/utils/checksum.d.ts +2 -2
- package/dist/server/utils/checksum.js +1 -1
- package/dist/server/utils/clear-storage.d.ts +5 -0
- package/dist/server/utils/clear-storage.js +17 -0
- package/dist/server/utils/completion-normalizer.d.ts +17 -0
- package/dist/server/utils/completion-normalizer.js +301 -0
- package/dist/server/utils/expand-gguf-shards.d.ts +3 -0
- package/dist/server/utils/expand-gguf-shards.js +22 -0
- package/dist/server/utils/formatting.js +1 -1
- package/dist/server/utils/index.d.ts +4 -2
- package/dist/server/utils/index.js +4 -2
- package/dist/server/utils/qvac-paths.d.ts +2 -0
- package/dist/server/utils/qvac-paths.js +5 -0
- package/dist/server/utils/response-format.d.ts +3 -0
- package/dist/server/utils/response-format.js +20 -0
- package/dist/server/utils/tool-integration.d.ts +15 -4
- package/dist/server/utils/tool-integration.js +21 -41
- package/dist/server/utils/tools/dialect.d.ts +8 -0
- package/dist/server/utils/tools/dialect.js +12 -0
- package/dist/server/utils/tools/index.d.ts +3 -0
- package/dist/server/utils/tools/index.js +2 -0
- package/dist/server/utils/tools/parser.d.ts +6 -0
- package/dist/server/utils/tools/parser.js +40 -0
- package/dist/server/utils/tools/parsers/hermes.d.ts +4 -0
- package/dist/server/utils/tools/parsers/hermes.js +100 -0
- package/dist/server/utils/tools/parsers/json.d.ts +6 -0
- package/dist/server/utils/tools/parsers/json.js +115 -0
- package/dist/server/utils/tools/parsers/pythonic.d.ts +4 -0
- package/dist/server/utils/tools/parsers/pythonic.js +267 -0
- package/dist/server/utils/tools/shared.d.ts +18 -0
- package/dist/server/utils/tools/shared.js +54 -0
- package/dist/server/utils/worker-lock.d.ts +3 -0
- package/dist/server/utils/worker-lock.js +67 -0
- package/dist/server/worker-core.d.ts +16 -1
- package/dist/server/worker-core.js +114 -14
- package/dist/utils/aggregate-events.d.ts +16 -0
- package/dist/utils/aggregate-events.js +52 -0
- package/dist/utils/cache-normalize.d.ts +10 -0
- package/dist/utils/cache-normalize.js +23 -0
- package/dist/utils/encoding.d.ts +8 -0
- package/dist/utils/encoding.js +13 -0
- package/dist/utils/errors-client.d.ts +12 -0
- package/dist/utils/errors-client.js +20 -0
- package/dist/utils/errors-server.d.ts +14 -0
- package/dist/utils/errors-server.js +31 -0
- package/dist/utils/load-model-validation.d.ts +7 -0
- package/dist/utils/load-model-validation.js +18 -0
- package/expo/plugins/patches/android-link.mjs +1 -1
- package/expo/plugins/patches/ios-link.mjs +1 -1
- package/package.json +15 -19
- package/dist/examples/translation/translation-opus.d.ts +0 -2
- package/dist/examples/translation/translation-opus.js +0 -33
- package/dist/server/bare/utils/loader-adapter.d.ts +0 -7
- package/dist/server/bare/utils/loader-adapter.js +0 -9
- package/dist/server/utils/model-path.d.ts +0 -5
- package/dist/server/utils/model-path.js +0 -7
- package/dist/server/utils/tool-parser.d.ts +0 -7
- package/dist/server/utils/tool-parser.js +0 -248
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { modelSrcInputSchema } from "./model-src-utils.js";
|
|
3
|
-
// Marian/Opus model languages
|
|
4
|
-
export const MARIAN_LANGUAGES = ["en", "de", "es", "it", "ru", "ja"];
|
|
5
3
|
// Bergamot supports many more language pairs
|
|
6
4
|
export const BERGAMOT_LANGUAGES = [
|
|
7
5
|
"en",
|
|
@@ -29,6 +27,39 @@ export const BERGAMOT_LANGUAGES = [
|
|
|
29
27
|
"sl",
|
|
30
28
|
"uk",
|
|
31
29
|
"zh",
|
|
30
|
+
"az",
|
|
31
|
+
"be",
|
|
32
|
+
"bn",
|
|
33
|
+
"bs",
|
|
34
|
+
"da",
|
|
35
|
+
"el",
|
|
36
|
+
"fa",
|
|
37
|
+
"gu",
|
|
38
|
+
"he",
|
|
39
|
+
"hi",
|
|
40
|
+
"hr",
|
|
41
|
+
"id",
|
|
42
|
+
"kn",
|
|
43
|
+
"ml",
|
|
44
|
+
"ms",
|
|
45
|
+
"mt",
|
|
46
|
+
"nb",
|
|
47
|
+
"nn",
|
|
48
|
+
"re",
|
|
49
|
+
"ro",
|
|
50
|
+
"sq",
|
|
51
|
+
"sr",
|
|
52
|
+
"sv",
|
|
53
|
+
"ta",
|
|
54
|
+
"te",
|
|
55
|
+
"tr",
|
|
56
|
+
"vi",
|
|
57
|
+
];
|
|
58
|
+
export const BERGAMOT_MODEL_RE = /^(.+\/)model\.([a-z]+)\.intgemm\.alphas\.bin$/;
|
|
59
|
+
export const BERGAMOT_CJK_LANG_PAIRS = [
|
|
60
|
+
"enja",
|
|
61
|
+
"enko",
|
|
62
|
+
"enzh",
|
|
32
63
|
];
|
|
33
64
|
// IndicTrans2 model languages
|
|
34
65
|
export const INDICTRANS_LANGUAGES = [
|
|
@@ -83,11 +114,10 @@ export const AFRICAN_LANGUAGES_MAP = new Map([
|
|
|
83
114
|
]);
|
|
84
115
|
// Union of all NMT languages (for general type usage)
|
|
85
116
|
export const NMT_LANGUAGES = [
|
|
86
|
-
...MARIAN_LANGUAGES,
|
|
87
117
|
...BERGAMOT_LANGUAGES,
|
|
88
118
|
...INDICTRANS_LANGUAGES,
|
|
89
119
|
];
|
|
90
|
-
export const NMT_ENGINES = ["
|
|
120
|
+
export const NMT_ENGINES = ["Bergamot", "IndicTrans"];
|
|
91
121
|
// Common generation parameters (without language fields)
|
|
92
122
|
const nmtGenerationParamsSchema = z.object({
|
|
93
123
|
mode: z.enum(["full"]).optional(),
|
|
@@ -100,12 +130,6 @@ const nmtGenerationParamsSchema = z.object({
|
|
|
100
130
|
topk: z.number().optional(),
|
|
101
131
|
topp: z.number().optional(),
|
|
102
132
|
});
|
|
103
|
-
// Opus engine config (Marian-based) - supports MARIAN_LANGUAGES
|
|
104
|
-
const opusConfigSchema = nmtGenerationParamsSchema.extend({
|
|
105
|
-
engine: z.literal("Opus"),
|
|
106
|
-
from: z.enum(MARIAN_LANGUAGES),
|
|
107
|
-
to: z.enum(MARIAN_LANGUAGES),
|
|
108
|
-
});
|
|
109
133
|
// Pivot model configuration for Bergamot (for translation via intermediate language)
|
|
110
134
|
const bergamotPivotModelSchema = nmtGenerationParamsSchema
|
|
111
135
|
.extend({
|
|
@@ -133,7 +157,6 @@ const indicTransConfigSchema = nmtGenerationParamsSchema.extend({
|
|
|
133
157
|
});
|
|
134
158
|
// Discriminated union of all engine configs
|
|
135
159
|
export const nmtConfigBaseSchema = z.discriminatedUnion("engine", [
|
|
136
|
-
opusConfigSchema,
|
|
137
160
|
bergamotConfigSchema,
|
|
138
161
|
indicTransConfigSchema,
|
|
139
162
|
]);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import RPC from "bare-rpc";
|
|
2
2
|
import type { RPCOptions } from "../../schemas/index";
|
|
3
|
-
export declare function getRPC(
|
|
3
|
+
export declare function getRPC(publicKey: string, options?: RPCOptions): Promise<RPC>;
|
|
4
4
|
/**
|
|
5
5
|
* Remove a stale RPC connection for a peer.
|
|
6
6
|
* Called when a delegation request fails (e.g., timeout) so the next
|
|
@@ -7,12 +7,13 @@ import { nowMs } from "../../profiling/index.js";
|
|
|
7
7
|
import { cacheDelegationConnectionTime, clearPeerConnectionTracking, } from "../rpc/profiling/delegation-profiler.js";
|
|
8
8
|
import { getNextCommandId } from "../rpc/rpc-utils.js";
|
|
9
9
|
const logger = getServerLogger();
|
|
10
|
-
// Map of active RPC instances by public key
|
|
11
10
|
const activeRPCs = new Map();
|
|
12
|
-
// Map to store underlying connections for cleanup
|
|
13
11
|
const activeConnections = new Map();
|
|
14
|
-
//
|
|
15
|
-
|
|
12
|
+
// In-flight `ensureRPCConnection` promises keyed by peer. Concurrent
|
|
13
|
+
// `getRPC(publicKey)` callers (without `forceNewConnection`) join the same
|
|
14
|
+
// promise instead of each running their own bootstrap+connect, which would
|
|
15
|
+
// open multiple sockets, clobber the active maps, and leak the loser.
|
|
16
|
+
const inflightConnections = new Map();
|
|
16
17
|
const HEALTH_CHECK_TIMEOUT_MS = 1500;
|
|
17
18
|
function isHeartbeatResponse(payload) {
|
|
18
19
|
return (typeof payload === "object" &&
|
|
@@ -32,72 +33,92 @@ async function isRPCConnectionHealthy(rpc, timeout = HEALTH_CHECK_TIMEOUT_MS) {
|
|
|
32
33
|
return false;
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
});
|
|
54
|
-
// Store RPC instance and connection by peer ID for lookup
|
|
55
|
-
activeRPCs.set(peerPubkey, rpc);
|
|
56
|
-
activeConnections.set(peerPubkey, conn);
|
|
57
|
-
conn.on("close", () => {
|
|
58
|
-
logger.debug(`Connection closed for peer: ${peerPubkey}`);
|
|
59
|
-
activeRPCs.delete(peerPubkey);
|
|
60
|
-
activeConnections.delete(peerPubkey);
|
|
61
|
-
clearPeerConnectionTracking(peerPubkey);
|
|
62
|
-
});
|
|
63
|
-
conn.on("error", (err) => {
|
|
64
|
-
logger.error(`Connection error for peer ${peerPubkey}:`, err);
|
|
65
|
-
activeRPCs.delete(peerPubkey);
|
|
66
|
-
activeConnections.delete(peerPubkey);
|
|
67
|
-
clearPeerConnectionTracking(peerPubkey);
|
|
68
|
-
});
|
|
36
|
+
function trackConnection(publicKey, conn, rpc) {
|
|
37
|
+
activeRPCs.set(publicKey, rpc);
|
|
38
|
+
activeConnections.set(publicKey, conn);
|
|
39
|
+
conn.on("close", () => {
|
|
40
|
+
logger.debug(`Connection closed for peer: ${publicKey}`);
|
|
41
|
+
if (activeConnections.get(publicKey) === conn) {
|
|
42
|
+
activeConnections.delete(publicKey);
|
|
43
|
+
activeRPCs.delete(publicKey);
|
|
44
|
+
clearPeerConnectionTracking(publicKey);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
conn.on("error", (err) => {
|
|
48
|
+
logger.error(`Connection error for peer ${publicKey}:`, err);
|
|
49
|
+
if (activeConnections.get(publicKey) === conn) {
|
|
50
|
+
activeConnections.delete(publicKey);
|
|
51
|
+
activeRPCs.delete(publicKey);
|
|
52
|
+
clearPeerConnectionTracking(publicKey);
|
|
53
|
+
}
|
|
69
54
|
});
|
|
70
55
|
}
|
|
71
56
|
async function closeConnection(publicKey) {
|
|
72
57
|
const existingConnection = activeConnections.get(publicKey);
|
|
73
|
-
if (existingConnection)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (activeConnections.get(publicKey) !== existingConnection)
|
|
84
|
-
return;
|
|
58
|
+
if (!existingConnection)
|
|
59
|
+
return;
|
|
60
|
+
logger.info(`🔌 Closing existing connection for peer: ${publicKey}`);
|
|
61
|
+
// Wait for the close event before returning so any pending cleanup
|
|
62
|
+
// in the underlying DHT stream completes before we reconnect.
|
|
63
|
+
await new Promise((resolve) => {
|
|
64
|
+
existingConnection.once("close", () => resolve());
|
|
65
|
+
existingConnection.destroy();
|
|
66
|
+
});
|
|
67
|
+
if (activeConnections.get(publicKey) === existingConnection) {
|
|
85
68
|
activeConnections.delete(publicKey);
|
|
86
69
|
activeRPCs.delete(publicKey);
|
|
87
70
|
clearPeerConnectionTracking(publicKey);
|
|
88
71
|
}
|
|
89
72
|
}
|
|
90
|
-
//
|
|
91
|
-
|
|
73
|
+
// Open a direct DHT connection to a peer by public key. Bypasses topic
|
|
74
|
+
// discovery entirely — we already know who we're talking to, so we skip
|
|
75
|
+
// swarm.join()/flush() and let the DHT route by public key.
|
|
76
|
+
function openDhtConnection(publicKey) {
|
|
77
|
+
const swarm = getSwarm();
|
|
78
|
+
const relayThrough = swarm.relayThrough
|
|
79
|
+
? swarm.relayThrough(false, swarm)
|
|
80
|
+
: null;
|
|
81
|
+
return swarm.dht.connect(Buffer.from(publicKey, "hex"), {
|
|
82
|
+
keyPair: swarm.keyPair,
|
|
83
|
+
relayThrough,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
// Resolve when the DHT connection emits "open"; reject promptly on "error"
|
|
87
|
+
// or "close" so firewall-rejected / abruptly-closed connects fail fast
|
|
88
|
+
// instead of dragging out the full delegate timeout (60s on cold paths).
|
|
89
|
+
function waitForOpen(conn, timeout) {
|
|
90
|
+
const opened = new Promise((resolve, reject) => {
|
|
91
|
+
const cleanup = () => {
|
|
92
|
+
conn.removeListener("open", onOpen);
|
|
93
|
+
conn.removeListener("error", onError);
|
|
94
|
+
conn.removeListener("close", onClose);
|
|
95
|
+
};
|
|
96
|
+
const onOpen = () => {
|
|
97
|
+
cleanup();
|
|
98
|
+
resolve();
|
|
99
|
+
};
|
|
100
|
+
const onError = (err) => {
|
|
101
|
+
cleanup();
|
|
102
|
+
reject(err);
|
|
103
|
+
};
|
|
104
|
+
const onClose = () => {
|
|
105
|
+
cleanup();
|
|
106
|
+
reject(new DelegateConnectionFailedError("Connection closed before open (peer unreachable or rejected by firewall)"));
|
|
107
|
+
};
|
|
108
|
+
conn.once("open", onOpen);
|
|
109
|
+
conn.once("error", onError);
|
|
110
|
+
conn.once("close", onClose);
|
|
111
|
+
});
|
|
112
|
+
return withTimeout(opened, timeout);
|
|
113
|
+
}
|
|
114
|
+
async function ensureRPCConnection(publicKey, timeout, healthCheckTimeout) {
|
|
92
115
|
const healthCheckCap = healthCheckTimeout ?? HEALTH_CHECK_TIMEOUT_MS;
|
|
93
116
|
const operationStart = nowMs();
|
|
94
117
|
const getRemainingTimeout = () => {
|
|
95
|
-
if (timeout === undefined)
|
|
118
|
+
if (timeout === undefined)
|
|
96
119
|
return undefined;
|
|
97
|
-
}
|
|
98
120
|
return Math.max(timeout - (nowMs() - operationStart), 0);
|
|
99
121
|
};
|
|
100
|
-
// Check if we already have an RPC instance for this peer
|
|
101
122
|
const existingRpc = activeRPCs.get(publicKey);
|
|
102
123
|
if (existingRpc) {
|
|
103
124
|
const remainingTimeout = getRemainingTimeout();
|
|
@@ -111,89 +132,77 @@ async function ensureRPCConnection(topic, publicKey, timeout, healthCheckTimeout
|
|
|
111
132
|
logger.info(`🧹 Cached RPC failed health check for peer ${publicKey}, reconnecting`);
|
|
112
133
|
cleanupStaleConnection(publicKey);
|
|
113
134
|
}
|
|
114
|
-
const swarm = getSwarm();
|
|
115
135
|
const connectionStart = nowMs();
|
|
116
|
-
|
|
117
|
-
let onConnection = () => { };
|
|
136
|
+
let conn;
|
|
118
137
|
try {
|
|
119
|
-
logger.info(`🔗 Establishing
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
swarm.removeListener("connection", onConnection);
|
|
134
|
-
// The global handler (ensureConnectionHandler) will create the RPC
|
|
135
|
-
// and store it in activeRPCs. Give it a tick to run first.
|
|
136
|
-
const rpc = activeRPCs.get(publicKey);
|
|
137
|
-
if (rpc) {
|
|
138
|
-
resolve(rpc);
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
// Global handler runs synchronously before us in the same event,
|
|
142
|
-
// so this shouldn't happen, but handle it just in case
|
|
143
|
-
setTimeout(() => {
|
|
144
|
-
const delayedRpc = activeRPCs.get(publicKey);
|
|
145
|
-
if (delayedRpc) {
|
|
146
|
-
resolve(delayedRpc);
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
reject(new DelegateConnectionFailedError(`Connection established but RPC not created for peer ${publicKey}`));
|
|
150
|
-
}
|
|
151
|
-
}, 100);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
swarm.on("connection", onConnection);
|
|
156
|
-
// Also flush to trigger discovery. After flush, check if the connection
|
|
157
|
-
// was already established (the global handler may have caught it).
|
|
158
|
-
void swarm.flush().then(() => {
|
|
159
|
-
logger.info(`✅ Flush completed for topic: ${topic}`);
|
|
160
|
-
logger.debug(`📊 Active RPC connections: ${activeRPCs.size}`);
|
|
161
|
-
const rpc = activeRPCs.get(publicKey);
|
|
162
|
-
if (rpc) {
|
|
163
|
-
swarm.removeListener("connection", onConnection);
|
|
164
|
-
resolve(rpc);
|
|
165
|
-
}
|
|
166
|
-
// If not connected after flush, the onConnection listener keeps
|
|
167
|
-
// waiting until the timeout from withTimeout kicks in.
|
|
168
|
-
// Hyperswarm may still establish the connection via retries/relays.
|
|
169
|
-
logger.debug(`⏳ Peer not connected after flush, waiting for connection event...`);
|
|
170
|
-
});
|
|
138
|
+
logger.info(`🔗 Establishing direct DHT connection to peer: ${publicKey}${timeout ? `, timeout: ${timeout}ms` : ""}`);
|
|
139
|
+
// Ensure the DHT routing table is populated before attempting to look up
|
|
140
|
+
// the peer. On a cold swarm the table is nearly empty and findPeer can
|
|
141
|
+
// return PEER_NOT_FOUND immediately even when the provider is reachable.
|
|
142
|
+
const bootstrapStart = nowMs();
|
|
143
|
+
const swarm = getSwarm();
|
|
144
|
+
logger.info(`⏳ Waiting for DHT to fully bootstrap before connect...`);
|
|
145
|
+
await withTimeout(swarm.dht.fullyBootstrapped(), getRemainingTimeout());
|
|
146
|
+
logger.info(`✅ DHT bootstrapped in ${(nowMs() - bootstrapStart).toFixed(0)}ms`);
|
|
147
|
+
conn = openDhtConnection(publicKey);
|
|
148
|
+
await waitForOpen(conn, getRemainingTimeout());
|
|
149
|
+
logger.info(`🍺 Peer connection opened: ${publicKey}`);
|
|
150
|
+
const rpc = new RPC(conn, () => {
|
|
151
|
+
// No-op handler since we're only sending requests, not receiving them
|
|
171
152
|
});
|
|
172
|
-
|
|
153
|
+
trackConnection(publicKey, conn, rpc);
|
|
173
154
|
const connectionDuration = nowMs() - connectionStart;
|
|
174
155
|
cacheDelegationConnectionTime(publicKey, connectionDuration);
|
|
175
156
|
return rpc;
|
|
176
157
|
}
|
|
177
158
|
catch (error) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
// instead of reusing a dead RPC
|
|
159
|
+
if (conn && !conn.destroyed) {
|
|
160
|
+
conn.destroy();
|
|
161
|
+
}
|
|
182
162
|
cleanupStaleConnection(publicKey);
|
|
183
163
|
logger.error("Failed to establish RPC connection:", error);
|
|
184
164
|
throw new DelegateConnectionFailedError(`RPC connection failed: ${error instanceof Error ? error.message : String(error)}`, error);
|
|
185
165
|
}
|
|
186
166
|
}
|
|
187
|
-
// Create an RPC instance for a specific HyperSwarm peer
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
167
|
+
// Create an RPC instance for a specific HyperSwarm peer.
|
|
168
|
+
// Connects directly via the DHT using the peer's public key — no topic
|
|
169
|
+
// discovery required.
|
|
170
|
+
//
|
|
171
|
+
// Concurrent calls for the same peer share a single in-flight bootstrap +
|
|
172
|
+
// connect operation, but each caller still gets its own `timeout` enforced
|
|
173
|
+
// against the shared promise (via `withTimeout`) — so a fast caller that
|
|
174
|
+
// gives up at 5s does not block a slow caller waiting up to 60s.
|
|
175
|
+
//
|
|
176
|
+
// `forceNewConnection` always tears down the existing socket first and
|
|
177
|
+
// starts a fresh attempt outside the shared promise.
|
|
178
|
+
export async function getRPC(publicKey, options = {}) {
|
|
193
179
|
if (options.forceNewConnection) {
|
|
194
180
|
await closeConnection(publicKey);
|
|
181
|
+
return await ensureRPCConnection(publicKey, options.timeout, options.healthCheckTimeout);
|
|
182
|
+
}
|
|
183
|
+
let inflight = inflightConnections.get(publicKey);
|
|
184
|
+
if (!inflight) {
|
|
185
|
+
inflight = ensureRPCConnection(publicKey, options.timeout, options.healthCheckTimeout);
|
|
186
|
+
const tracked = inflight;
|
|
187
|
+
inflightConnections.set(publicKey, tracked);
|
|
188
|
+
// Clear the inflight entry on settle. We register a single combined
|
|
189
|
+
// settle handler via `then(handler, handler)` so that on rejection the
|
|
190
|
+
// failure is *observed* on `tracked` itself — using `tracked.finally(...)`
|
|
191
|
+
// returns a fresh promise that re-rejects with the original error, and
|
|
192
|
+
// since nothing awaits that fresh promise it would surface as an
|
|
193
|
+
// unhandled rejection. The worker treats unhandled rejections as fatal
|
|
194
|
+
// and tears down the swarm + cancels all in-flight downloads, which then
|
|
195
|
+
// breaks the legitimate fallback-to-local path that the caller awaits via
|
|
196
|
+
// `withTimeout(inflight, ...)` below. Caller still observes the original
|
|
197
|
+
// rejection through `await withTimeout(inflight, ...)`.
|
|
198
|
+
const clearInflight = () => {
|
|
199
|
+
if (inflightConnections.get(publicKey) === tracked) {
|
|
200
|
+
inflightConnections.delete(publicKey);
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
tracked.then(clearInflight, clearInflight);
|
|
195
204
|
}
|
|
196
|
-
return await
|
|
205
|
+
return await withTimeout(inflight, options.timeout);
|
|
197
206
|
}
|
|
198
207
|
/**
|
|
199
208
|
* Remove a stale RPC connection for a peer.
|
|
@@ -3,8 +3,8 @@ import { type FirewallConfig } from "../../schemas/provide";
|
|
|
3
3
|
export declare function getSwarm({ firewallConfig, }?: {
|
|
4
4
|
firewallConfig?: FirewallConfig | undefined;
|
|
5
5
|
}): Hyperswarm;
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function
|
|
6
|
+
export declare function registerProvider(): void;
|
|
7
|
+
export declare function unregisterProvider(): void;
|
|
8
8
|
export declare function hasActiveProviders(): boolean;
|
|
9
9
|
export declare function destroySwarm(): Promise<void>;
|
|
10
10
|
//# sourceMappingURL=hyperswarm.d.ts.map
|
|
@@ -61,7 +61,11 @@ function createSwarm(firewallConfig) {
|
|
|
61
61
|
return new Hyperswarm(swarmOptions);
|
|
62
62
|
}
|
|
63
63
|
let swarm = null;
|
|
64
|
-
|
|
64
|
+
// Delegation is always 1:1 (single provider service per SDK instance), but we
|
|
65
|
+
// still use a counter to be resilient against duplicate provide/stopProvide
|
|
66
|
+
// calls and to avoid ever reporting "no active providers" while one is still
|
|
67
|
+
// running.
|
|
68
|
+
let activeProviderCount = 0;
|
|
65
69
|
export function getSwarm({ firewallConfig, } = {}) {
|
|
66
70
|
if (swarm) {
|
|
67
71
|
return swarm;
|
|
@@ -70,14 +74,15 @@ export function getSwarm({ firewallConfig, } = {}) {
|
|
|
70
74
|
registerSwarm(swarm, { label: "shared-swarm", createdAt: Date.now() });
|
|
71
75
|
return swarm;
|
|
72
76
|
}
|
|
73
|
-
export function
|
|
74
|
-
|
|
77
|
+
export function registerProvider() {
|
|
78
|
+
activeProviderCount++;
|
|
75
79
|
}
|
|
76
|
-
export function
|
|
77
|
-
|
|
80
|
+
export function unregisterProvider() {
|
|
81
|
+
if (activeProviderCount > 0)
|
|
82
|
+
activeProviderCount--;
|
|
78
83
|
}
|
|
79
84
|
export function hasActiveProviders() {
|
|
80
|
-
return
|
|
85
|
+
return activeProviderCount > 0;
|
|
81
86
|
}
|
|
82
87
|
export async function destroySwarm() {
|
|
83
88
|
if (!swarm)
|
|
@@ -87,7 +92,7 @@ export async function destroySwarm() {
|
|
|
87
92
|
try {
|
|
88
93
|
await ref.destroy();
|
|
89
94
|
unregisterSwarm(ref);
|
|
90
|
-
|
|
95
|
+
activeProviderCount = 0;
|
|
91
96
|
}
|
|
92
97
|
catch (error) {
|
|
93
98
|
if (swarm === null)
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { getModel } from "../registry/model-registry.js";
|
|
2
2
|
import { cancelInferenceBaseSchema, } from "../../../schemas/index.js";
|
|
3
3
|
import { ModelNotLoadedError } from "../../../utils/errors-server.js";
|
|
4
|
+
import { noteCancelRequested } from "../plugins/llamacpp-completion/ops/kv-cache-state.js";
|
|
4
5
|
export async function cancel(params) {
|
|
5
6
|
const { modelId } = cancelInferenceBaseSchema.parse(params);
|
|
6
7
|
const model = getModel(modelId);
|
|
7
8
|
if (!model) {
|
|
8
9
|
throw new ModelNotLoadedError(modelId);
|
|
9
10
|
}
|
|
11
|
+
// Must be recorded *before* `addon.cancel()` so the in-flight
|
|
12
|
+
// `completion()` for this model sees the bumped counter when it
|
|
13
|
+
// snapshots after `processModelResponse` returns. This is the signal
|
|
14
|
+
// that tells `completion()` not to record a `savedCount` for the
|
|
15
|
+
// kv-cache on a cancelled turn.
|
|
16
|
+
noteCancelRequested(modelId);
|
|
10
17
|
if (model.addon && model.addon.cancel) {
|
|
11
18
|
await model.addon.cancel();
|
|
12
19
|
}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
+
import { type CacheMessage } from "../../utils/index";
|
|
1
2
|
export declare function markCacheInitialized(modelId: string, configHash: string, cacheKey: string): void;
|
|
2
3
|
export declare function isCacheInitialized(modelId: string, configHash: string, cacheKey: string): boolean;
|
|
3
|
-
export declare function clearCacheRegistry(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
attachments?: {
|
|
8
|
-
path: string;
|
|
9
|
-
}[] | undefined;
|
|
10
|
-
}
|
|
4
|
+
export declare function clearCacheRegistry(scope?: {
|
|
5
|
+
cacheKey?: string | undefined;
|
|
6
|
+
modelId?: string | undefined;
|
|
7
|
+
}): void;
|
|
11
8
|
export declare function extractSystemPrompt(messages: CacheMessage[]): string | null;
|
|
12
9
|
export declare function generateConfigHash(systemPrompt: string | null, tools?: unknown): string;
|
|
13
10
|
export declare function generateCacheKey(messages: CacheMessage[]): string;
|
|
@@ -20,12 +17,12 @@ export declare function getCurrentCacheInfo(modelId: string, configHash: string,
|
|
|
20
17
|
cacheKey: string;
|
|
21
18
|
cachePath: string;
|
|
22
19
|
}>;
|
|
23
|
-
export declare function renameCacheFile(oldPath: string, newPath: string): Promise<
|
|
20
|
+
export declare function renameCacheFile(oldPath: string, newPath: string): Promise<boolean>;
|
|
24
21
|
export declare function customCacheExists(modelId: string, configHash: string, cacheKey: string): Promise<boolean>;
|
|
25
22
|
export declare function deleteCache(options: {
|
|
26
23
|
all: true;
|
|
27
24
|
} | {
|
|
28
25
|
kvCacheKey: string;
|
|
29
26
|
modelId?: string;
|
|
30
|
-
}): Promise<
|
|
27
|
+
}): Promise<string>;
|
|
31
28
|
//# sourceMappingURL=kv-cache-utils.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import crypto from "bare-crypto";
|
|
2
2
|
import { promises as fsPromises } from "bare-fs";
|
|
3
3
|
import path from "bare-path";
|
|
4
|
-
import { getKVCacheDir, validateAndJoinPath } from "../../utils/index.js";
|
|
4
|
+
import { getAutoCacheLookupHistory, getKVCacheDir, validateAndJoinPath, } from "../../utils/index.js";
|
|
5
5
|
import { getServerLogger } from "../../../logging/index.js";
|
|
6
6
|
const logger = getServerLogger();
|
|
7
7
|
// In-memory registry tracks caches initialized this session (addon defers disk writes)
|
|
@@ -15,16 +15,24 @@ export function markCacheInitialized(modelId, configHash, cacheKey) {
|
|
|
15
15
|
export function isCacheInitialized(modelId, configHash, cacheKey) {
|
|
16
16
|
return initializedCaches.has(getCacheRegistryKey(modelId, configHash, cacheKey));
|
|
17
17
|
}
|
|
18
|
-
export function clearCacheRegistry(
|
|
19
|
-
if (cacheKey) {
|
|
20
|
-
for (const key of initializedCaches) {
|
|
21
|
-
if (key.includes(`:${cacheKey}`)) {
|
|
22
|
-
initializedCaches.delete(key);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
18
|
+
export function clearCacheRegistry(scope) {
|
|
19
|
+
if (!scope || (scope.cacheKey === undefined && scope.modelId === undefined)) {
|
|
27
20
|
initializedCaches.clear();
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
// key format: "modelId:configHash:cacheKey"
|
|
24
|
+
for (const key of initializedCaches) {
|
|
25
|
+
const firstSep = key.indexOf(":");
|
|
26
|
+
const secondSep = key.indexOf(":", firstSep + 1);
|
|
27
|
+
if (firstSep === -1 || secondSep === -1)
|
|
28
|
+
continue;
|
|
29
|
+
const modelId = key.slice(0, firstSep);
|
|
30
|
+
const cacheKey = key.slice(secondSep + 1);
|
|
31
|
+
if (scope.cacheKey !== undefined && cacheKey !== scope.cacheKey)
|
|
32
|
+
continue;
|
|
33
|
+
if (scope.modelId !== undefined && modelId !== scope.modelId)
|
|
34
|
+
continue;
|
|
35
|
+
initializedCaches.delete(key);
|
|
28
36
|
}
|
|
29
37
|
}
|
|
30
38
|
export function extractSystemPrompt(messages) {
|
|
@@ -73,8 +81,7 @@ export async function findMatchingCache(modelId, configHash, currentHistory) {
|
|
|
73
81
|
if (currentHistory.length <= 1) {
|
|
74
82
|
return null;
|
|
75
83
|
}
|
|
76
|
-
|
|
77
|
-
const previousHistory = currentHistory.slice(0, -1);
|
|
84
|
+
const previousHistory = getAutoCacheLookupHistory(currentHistory);
|
|
78
85
|
const cacheKey = generateCacheKey(previousHistory);
|
|
79
86
|
const cachePath = await getCacheFilePath(modelId, configHash, cacheKey);
|
|
80
87
|
try {
|
|
@@ -93,9 +100,11 @@ export async function getCurrentCacheInfo(modelId, configHash, currentHistory) {
|
|
|
93
100
|
export async function renameCacheFile(oldPath, newPath) {
|
|
94
101
|
try {
|
|
95
102
|
await fsPromises.rename(oldPath, newPath);
|
|
103
|
+
return true;
|
|
96
104
|
}
|
|
97
105
|
catch (error) {
|
|
98
106
|
logger.error("Error renaming cache file:", error instanceof Error ? error.message : String(error));
|
|
107
|
+
return false;
|
|
99
108
|
}
|
|
100
109
|
}
|
|
101
110
|
export async function customCacheExists(modelId, configHash, cacheKey) {
|
|
@@ -116,33 +125,15 @@ export async function customCacheExists(modelId, configHash, cacheKey) {
|
|
|
116
125
|
}
|
|
117
126
|
export async function deleteCache(options) {
|
|
118
127
|
const cacheDir = getKVCacheDir();
|
|
119
|
-
if ("all" in options
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
catch (error) {
|
|
125
|
-
logger.error("Error deleting all caches:", error instanceof Error ? error.message : String(error));
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
else if ("kvCacheKey" in options) {
|
|
129
|
-
const kvCacheDir = validateAndJoinPath(cacheDir, options.kvCacheKey);
|
|
130
|
-
if (options.modelId) {
|
|
131
|
-
const modelCacheDir = validateAndJoinPath(kvCacheDir, options.modelId);
|
|
132
|
-
try {
|
|
133
|
-
await fsPromises.rm(modelCacheDir, { recursive: true });
|
|
134
|
-
}
|
|
135
|
-
catch (error) {
|
|
136
|
-
logger.error(`Error deleting model cache ${options.kvCacheKey}/${options.modelId}:`, error instanceof Error ? error.message : String(error));
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
try {
|
|
141
|
-
await fsPromises.rm(kvCacheDir, { recursive: true });
|
|
142
|
-
}
|
|
143
|
-
catch (error) {
|
|
144
|
-
logger.error(`Error deleting cache ${options.kvCacheKey}:`, error instanceof Error ? error.message : String(error));
|
|
145
|
-
}
|
|
146
|
-
}
|
|
128
|
+
if ("all" in options) {
|
|
129
|
+
await fsPromises.rm(cacheDir, { recursive: true, force: true });
|
|
130
|
+
await fsPromises.mkdir(cacheDir, { recursive: true });
|
|
131
|
+
return cacheDir;
|
|
147
132
|
}
|
|
133
|
+
const kvCacheDir = validateAndJoinPath(cacheDir, options.kvCacheKey);
|
|
134
|
+
const targetDir = options.modelId !== undefined
|
|
135
|
+
? validateAndJoinPath(kvCacheDir, options.modelId)
|
|
136
|
+
: kvCacheDir;
|
|
137
|
+
await fsPromises.rm(targetDir, { recursive: true, force: true });
|
|
138
|
+
return targetDir;
|
|
148
139
|
}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import { type TranscribeParams, type TranscribeStats } from "../../../schemas/index";
|
|
2
|
-
|
|
1
|
+
import { type TranscribeParams, type TranscribeSegment, type TranscribeStats } from "../../../schemas/index";
|
|
2
|
+
import { assertMetadataSupported, toTranscribeSegment, type WhisperAddonSegment } from "../utils/transcribe-metadata";
|
|
3
|
+
export { assertMetadataSupported, toTranscribeSegment, type WhisperAddonSegment, };
|
|
4
|
+
type TranscribeReturn = {
|
|
3
5
|
modelExecutionMs: number;
|
|
4
6
|
stats?: TranscribeStats;
|
|
5
|
-
}
|
|
6
|
-
export declare function
|
|
7
|
+
};
|
|
8
|
+
export declare function transcribe(params: TranscribeParams & {
|
|
9
|
+
metadata: true;
|
|
10
|
+
}): AsyncGenerator<TranscribeSegment, TranscribeReturn, void>;
|
|
11
|
+
export declare function transcribe(params: TranscribeParams): AsyncGenerator<string, TranscribeReturn, void>;
|
|
12
|
+
export declare function transcribeStream(modelId: string, audioInputStream: AsyncIterable<Buffer>, prompt: string | undefined, metadata: true): AsyncGenerator<TranscribeSegment, void, void>;
|
|
13
|
+
export declare function transcribeStream(modelId: string, audioInputStream: AsyncIterable<Buffer>, prompt?: string, metadata?: boolean): AsyncGenerator<string, void, void>;
|
|
7
14
|
//# sourceMappingURL=transcribe.d.ts.map
|