@qvac/sdk 0.10.2 → 0.12.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 +1455 -29
- package/README.md +2 -0
- package/dist/client/api/cancel.d.ts +24 -32
- package/dist/client/api/cancel.js +58 -31
- package/dist/client/api/classify.d.ts +23 -0
- package/dist/client/api/classify.js +43 -0
- package/dist/client/api/client-request-id.d.ts +17 -0
- package/dist/client/api/client-request-id.js +27 -0
- package/dist/client/api/completion-stream.d.ts +1 -1
- package/dist/client/api/completion-stream.js +34 -3
- package/dist/client/api/diffusion.d.ts +46 -0
- package/dist/client/api/diffusion.js +50 -1
- package/dist/client/api/download-asset.d.ts +12 -2
- package/dist/client/api/download-asset.js +21 -3
- package/dist/client/api/embed.d.ts +8 -4
- package/dist/client/api/embed.js +14 -1
- package/dist/client/api/get-model-info.d.ts +1 -1
- package/dist/client/api/index.d.ts +5 -0
- package/dist/client/api/index.js +5 -0
- package/dist/client/api/load-model.d.ts +12 -4
- package/dist/client/api/load-model.js +49 -2
- package/dist/client/api/rag.d.ts +9 -3
- package/dist/client/api/rag.js +23 -3
- package/dist/client/api/transcribe.d.ts +23 -8
- package/dist/client/api/transcribe.js +69 -4
- package/dist/client/api/unload-model.d.ts +5 -2
- package/dist/client/api/unload-model.js +9 -4
- package/dist/client/api/upscale.d.ts +45 -0
- package/dist/client/api/upscale.js +99 -0
- package/dist/client/api/video.d.ts +64 -0
- package/dist/client/api/video.js +147 -0
- package/dist/client/api/vla-helpers.d.ts +45 -0
- package/dist/client/api/vla-helpers.js +130 -0
- package/dist/client/api/vla.d.ts +65 -0
- package/dist/client/api/vla.js +109 -0
- package/dist/client/config-loader/resolve-config.node.d.ts +16 -0
- package/dist/client/config-loader/resolve-config.node.js +77 -23
- package/dist/client/plugins-factory.d.ts +8 -0
- package/dist/client/plugins-factory.js +10 -0
- package/dist/client/rpc/bare-client.js +62 -66
- package/dist/client/rpc/ensure-worker-ready.d.ts +9 -0
- package/dist/client/rpc/ensure-worker-ready.js +17 -0
- package/dist/client/rpc/expo-rpc-client.js +2 -1
- package/dist/client/rpc/node-rpc-client.js +22 -8
- package/dist/client/rpc/rpc-client.d.ts +2 -2
- package/dist/client/rpc/rpc-client.js +10 -4
- package/dist/client/rpc/rpc-error.d.ts +9 -0
- package/dist/client/rpc/rpc-error.js +105 -0
- package/dist/commands/bundle/bare-pack.d.ts +13 -0
- package/dist/commands/bundle/bare-pack.js +54 -0
- package/dist/commands/bundle/constants.d.ts +7 -0
- package/dist/commands/bundle/constants.js +23 -0
- package/dist/commands/bundle/entry-gen.d.ts +2 -0
- package/dist/commands/bundle/entry-gen.js +48 -0
- package/dist/commands/bundle/index.d.ts +20 -0
- package/dist/commands/bundle/index.js +141 -0
- package/dist/commands/bundle/manifest.d.ts +21 -0
- package/dist/commands/bundle/manifest.js +193 -0
- package/dist/commands/bundle/plugins.d.ts +9 -0
- package/dist/commands/bundle/plugins.js +51 -0
- package/dist/commands/index.d.ts +5 -0
- package/dist/commands/index.js +2 -0
- package/dist/commands/verify/abi.d.ts +52 -0
- package/dist/commands/verify/abi.js +125 -0
- package/dist/commands/verify/addon-source.d.ts +43 -0
- package/dist/commands/verify/addon-source.js +75 -0
- package/dist/commands/verify/bundle-source.d.ts +12 -0
- package/dist/commands/verify/bundle-source.js +53 -0
- package/dist/commands/verify/index.d.ts +59 -0
- package/dist/commands/verify/index.js +371 -0
- package/dist/commands/verify/node-modules-source.d.ts +11 -0
- package/dist/commands/verify/node-modules-source.js +76 -0
- package/dist/commands/verify/prebuilds.d.ts +15 -0
- package/dist/commands/verify/prebuilds.js +39 -0
- package/dist/examples/cancel-by-request-id.d.ts +38 -0
- package/dist/examples/cancel-by-request-id.js +103 -0
- package/dist/examples/classification/classify-image.d.ts +2 -0
- package/dist/examples/classification/classify-image.js +23 -0
- package/dist/examples/diffusion-esrgan-upscale.d.ts +2 -0
- package/dist/examples/diffusion-esrgan-upscale.js +78 -0
- package/dist/examples/diffusion-txt2vid.d.ts +2 -0
- package/dist/examples/diffusion-txt2vid.js +81 -0
- package/dist/examples/download-with-cancel.js +10 -10
- package/dist/examples/embed-multi-gpu.d.ts +2 -0
- package/dist/examples/embed-multi-gpu.js +46 -0
- package/dist/examples/llamacpp-multi-gpu.d.ts +2 -0
- package/dist/examples/llamacpp-multi-gpu.js +57 -0
- package/dist/examples/plugins.js +3 -7
- package/dist/examples/rag/rag-hyperdb/cancellation.js +20 -17
- package/dist/examples/tools/llamacpp-tools-gemma4.d.ts +2 -0
- package/dist/examples/tools/llamacpp-tools-gemma4.js +73 -0
- package/dist/examples/tools/llamacpp-tools-qwen35.d.ts +2 -0
- package/dist/examples/tools/llamacpp-tools-qwen35.js +69 -0
- package/dist/examples/transcription/parakeet-ctc-filesystem.js +18 -12
- package/dist/examples/transcription/parakeet-microphone-record.js +7 -12
- package/dist/examples/transcription/parakeet-microphone-stream.d.ts +2 -0
- package/dist/examples/transcription/parakeet-microphone-stream.js +79 -0
- package/dist/examples/transcription/parakeet-sortformer-streaming.d.ts +2 -0
- package/dist/examples/transcription/parakeet-sortformer-streaming.js +121 -0
- package/dist/examples/transcription/parakeet-sortformer.js +58 -55
- package/dist/examples/transcription/parakeet-tdt-filesystem.js +18 -15
- package/dist/examples/transcription/whispercpp-microphone-conversation.d.ts +2 -0
- package/dist/examples/transcription/whispercpp-microphone-conversation.js +107 -0
- package/dist/examples/tts/chatterbox.js +7 -16
- package/dist/examples/tts/llm-to-tts-streaming.js +3 -10
- package/dist/examples/tts/supertonic-multilingual.js +4 -12
- package/dist/examples/tts/supertonic.js +5 -12
- package/dist/examples/vla-smolvla.d.ts +2 -0
- package/dist/examples/vla-smolvla.js +75 -0
- package/dist/examples/voice-assistant/voice-assistant.js +3 -10
- package/dist/expo/plugins/find-in-ancestor-node-modules.d.ts +14 -0
- package/dist/expo/plugins/find-in-ancestor-node-modules.js +24 -0
- package/dist/expo/plugins/get-project-root.d.ts +22 -0
- package/dist/expo/plugins/get-project-root.js +23 -0
- package/dist/expo/plugins/index.d.ts +4 -0
- package/dist/expo/plugins/index.js +4 -0
- package/dist/expo/plugins/resolve-sdk-package-dir.d.ts +9 -2
- package/dist/expo/plugins/resolve-sdk-package-dir.js +38 -11
- package/dist/expo/plugins/withDeviceInfo.js +2 -1
- package/dist/expo/plugins/withMobileBundle.d.ts +5 -4
- package/dist/expo/plugins/withMobileBundle.js +42 -58
- package/dist/index.d.ts +6 -2
- package/dist/index.js +23 -2
- package/dist/models/registry/models.d.ts +3725 -514
- package/dist/models/registry/models.js +7269 -3910
- package/dist/models/update-models/naming.js +22 -8
- package/dist/pear/pre.d.ts +3 -0
- package/dist/pear/pre.js +9 -2
- package/dist/schemas/cancel.d.ts +172 -28
- package/dist/schemas/cancel.js +120 -19
- package/dist/schemas/classification.d.ts +53 -0
- package/dist/schemas/classification.js +33 -0
- package/dist/schemas/common.d.ts +860 -1379
- package/dist/schemas/common.js +8 -1
- package/dist/schemas/completion-event.d.ts +17 -0
- package/dist/schemas/completion-event.js +12 -1
- package/dist/schemas/completion-stream.d.ts +16 -1
- package/dist/schemas/completion-stream.js +25 -7
- package/dist/schemas/download-asset.d.ts +25 -9
- package/dist/schemas/download-asset.js +17 -6
- package/dist/schemas/embed.d.ts +1 -0
- package/dist/schemas/embed.js +5 -0
- package/dist/schemas/engine-addon-map.d.ts +3 -0
- package/dist/schemas/engine-addon-map.js +18 -5
- package/dist/schemas/error.d.ts +31 -0
- package/dist/schemas/error.js +29 -1
- package/dist/schemas/finetune.d.ts +2 -0
- package/dist/schemas/finetune.js +5 -0
- package/dist/schemas/get-model-info.d.ts +10 -6
- package/dist/schemas/get-model-info.js +2 -0
- package/dist/schemas/index.d.ts +3 -0
- package/dist/schemas/index.js +3 -0
- package/dist/schemas/llamacpp-config.d.ts +64 -8
- package/dist/schemas/llamacpp-config.js +12 -0
- package/dist/schemas/load-model.d.ts +4644 -8605
- package/dist/schemas/load-model.js +90 -7
- package/dist/schemas/model-src-utils.d.ts +34 -14
- package/dist/schemas/model-types.d.ts +54 -14
- package/dist/schemas/model-types.js +28 -5
- package/dist/schemas/ocr.d.ts +8 -3
- package/dist/schemas/plugin.d.ts +60 -6
- package/dist/schemas/plugin.js +31 -5
- package/dist/schemas/rag.d.ts +9 -0
- package/dist/schemas/rag.js +17 -9
- package/dist/schemas/registry.d.ts +74 -30
- package/dist/schemas/registry.js +5 -0
- package/dist/schemas/reload-config.d.ts +34 -14
- package/dist/schemas/sdcpp-config.d.ts +445 -16
- package/dist/schemas/sdcpp-config.js +387 -26
- package/dist/schemas/sdk-config.d.ts +2431 -2723
- package/dist/schemas/sdk-config.js +16 -1
- package/dist/schemas/sdk-errors-client.d.ts +6 -0
- package/dist/schemas/sdk-errors-client.js +31 -1
- package/dist/schemas/sdk-errors-server.d.ts +8 -1
- package/dist/schemas/sdk-errors-server.js +45 -5
- package/dist/schemas/text-to-speech.d.ts +81 -698
- package/dist/schemas/text-to-speech.js +46 -19
- package/dist/schemas/transcription-config.d.ts +40 -229
- package/dist/schemas/transcription-config.js +76 -15
- package/dist/schemas/transcription.d.ts +108 -2
- package/dist/schemas/transcription.js +81 -0
- package/dist/schemas/translate.d.ts +2 -0
- package/dist/schemas/translate.js +13 -2
- package/dist/schemas/translation-config.d.ts +90 -40
- package/dist/schemas/unload-model.d.ts +2 -1
- package/dist/schemas/unload-model.js +4 -1
- package/dist/schemas/vla.d.ts +87 -0
- package/dist/schemas/vla.js +108 -0
- package/dist/scripts/run-unit-tests.js +22 -3
- package/dist/server/bare/ops/cancel.d.ts +27 -1
- package/dist/server/bare/ops/cancel.js +36 -10
- package/dist/server/bare/ops/embed.d.ts +3 -3
- package/dist/server/bare/ops/embed.js +144 -28
- package/dist/server/bare/ops/kv-cache-utils.d.ts +0 -7
- package/dist/server/bare/ops/kv-cache-utils.js +8 -47
- package/dist/server/bare/ops/transcribe.d.ts +11 -5
- package/dist/server/bare/ops/transcribe.js +230 -50
- package/dist/server/bare/ops/translate.d.ts +1 -1
- package/dist/server/bare/ops/translate.js +197 -88
- package/dist/server/bare/plugins/ggml-classification/ops/classify.d.ts +6 -0
- package/dist/server/bare/plugins/ggml-classification/ops/classify.js +30 -0
- package/dist/server/bare/plugins/ggml-classification/plugin.d.ts +32 -0
- package/dist/server/bare/plugins/ggml-classification/plugin.js +55 -0
- package/dist/server/bare/plugins/ggml-vla/ops/vla-hparams.d.ts +3 -0
- package/dist/server/bare/plugins/ggml-vla/ops/vla-hparams.js +12 -0
- package/dist/server/bare/plugins/ggml-vla/ops/vla-run.d.ts +3 -0
- package/dist/server/bare/plugins/ggml-vla/ops/vla-run.js +75 -0
- package/dist/server/bare/plugins/ggml-vla/plugin.d.ts +54 -0
- package/dist/server/bare/plugins/ggml-vla/plugin.js +57 -0
- package/dist/server/bare/plugins/index.d.ts +3 -1
- package/dist/server/bare/plugins/index.js +3 -1
- package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.d.ts +12 -3
- package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.js +173 -172
- package/dist/server/bare/plugins/llamacpp-completion/ops/context-overflow.d.ts +29 -0
- package/dist/server/bare/plugins/llamacpp-completion/ops/context-overflow.js +65 -0
- package/dist/server/bare/plugins/llamacpp-completion/ops/finetune.js +125 -21
- package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-session.d.ts +154 -0
- package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-session.js +448 -0
- package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-state.d.ts +21 -73
- package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-state.js +18 -101
- package/dist/server/bare/plugins/llamacpp-completion/plugin.d.ts +36 -3
- package/dist/server/bare/plugins/llamacpp-completion/plugin.js +183 -85
- package/dist/server/bare/plugins/llamacpp-completion/transform.d.ts +10 -0
- package/dist/server/bare/plugins/llamacpp-completion/transform.js +34 -0
- package/dist/server/bare/plugins/llamacpp-embedding/plugin.d.ts +7 -0
- package/dist/server/bare/plugins/llamacpp-embedding/plugin.js +10 -1
- package/dist/server/bare/plugins/nmtcpp-translation/plugin.d.ts +42 -15
- package/dist/server/bare/plugins/nmtcpp-translation/plugin.js +5 -1
- package/dist/server/bare/plugins/onnx-ocr/plugin.d.ts +8 -3
- package/dist/server/bare/plugins/onnx-ocr/plugin.js +3 -0
- package/dist/server/bare/plugins/parakeet-transcription/plugin.d.ts +73 -244
- package/dist/server/bare/plugins/parakeet-transcription/plugin.js +68 -96
- package/dist/server/bare/plugins/sdcpp-generation/ops/diffusion.js +8 -0
- package/dist/server/bare/plugins/sdcpp-generation/ops/upscale.d.ts +3 -0
- package/dist/server/bare/plugins/sdcpp-generation/ops/upscale.js +40 -0
- package/dist/server/bare/plugins/sdcpp-generation/ops/video.d.ts +3 -0
- package/dist/server/bare/plugins/sdcpp-generation/ops/video.js +199 -0
- package/dist/server/bare/plugins/sdcpp-generation/plugin.d.ts +288 -15
- package/dist/server/bare/plugins/sdcpp-generation/plugin.js +150 -7
- package/dist/server/bare/plugins/{onnx-tts → tts-ggml}/ops/text-to-speech-stream.js +2 -15
- package/dist/server/bare/plugins/{onnx-tts → tts-ggml}/ops/text-to-speech.js +2 -1
- package/dist/server/bare/plugins/tts-ggml/plugin.d.ts +75 -0
- package/dist/server/bare/plugins/tts-ggml/plugin.js +189 -0
- package/dist/server/bare/plugins/whispercpp-transcription/plugin.d.ts +47 -3
- package/dist/server/bare/plugins/whispercpp-transcription/plugin.js +61 -14
- package/dist/server/bare/rag-hyperdb/index.d.ts +1 -1
- package/dist/server/bare/rag-hyperdb/index.js +1 -1
- package/dist/server/bare/rag-hyperdb/rag-operation-manager.d.ts +26 -4
- package/dist/server/bare/rag-hyperdb/rag-operation-manager.js +65 -28
- package/dist/server/bare/registry/model-config-utils.js +7 -0
- package/dist/server/bare/runtime/disposable-scope.d.ts +36 -0
- package/dist/server/bare/runtime/disposable-scope.js +69 -0
- package/dist/server/bare/runtime/index.d.ts +8 -0
- package/dist/server/bare/runtime/index.js +3 -0
- package/dist/server/bare/runtime/request-context.d.ts +49 -0
- package/dist/server/bare/runtime/request-context.js +1 -0
- package/dist/server/bare/runtime/request-id.d.ts +12 -0
- package/dist/server/bare/runtime/request-id.js +14 -0
- package/dist/server/bare/runtime/request-registry-singleton.d.ts +4 -0
- package/dist/server/bare/runtime/request-registry-singleton.js +27 -0
- package/dist/server/bare/runtime/request-registry.d.ts +136 -0
- package/dist/server/bare/runtime/request-registry.js +297 -0
- package/dist/server/bare/runtime/with-request-context.d.ts +22 -0
- package/dist/server/bare/runtime/with-request-context.js +53 -0
- package/dist/server/bare/runtime-lifecycle.js +9 -9
- package/dist/server/bare/types/addon-responses.d.ts +12 -1
- package/dist/server/env.js +4 -1
- package/dist/server/plugins/index.d.ts +1 -1
- package/dist/server/plugins/index.js +1 -1
- package/dist/server/plugins/registry.d.ts +1 -0
- package/dist/server/plugins/registry.js +5 -0
- package/dist/server/rpc/handler-registry.js +30 -7
- package/dist/server/rpc/handler-selection.d.ts +9 -0
- package/dist/server/rpc/handler-selection.js +14 -0
- package/dist/server/rpc/handler-utils.js +5 -13
- package/dist/server/rpc/handlers/cancel-delegated.js +28 -31
- package/dist/server/rpc/handlers/cancelHandler.d.ts +30 -1
- package/dist/server/rpc/handlers/cancelHandler.js +54 -22
- package/dist/server/rpc/handlers/classify.d.ts +3 -0
- package/dist/server/rpc/handlers/classify.js +4 -0
- package/dist/server/rpc/handlers/delete-cache.d.ts +9 -0
- package/dist/server/rpc/handlers/delete-cache.js +13 -15
- package/dist/server/rpc/handlers/download-asset.js +133 -40
- package/dist/server/rpc/handlers/index.d.ts +4 -0
- package/dist/server/rpc/handlers/index.js +4 -0
- package/dist/server/rpc/handlers/load-model/download-manager.d.ts +60 -2
- package/dist/server/rpc/handlers/load-model/download-manager.js +141 -8
- package/dist/server/rpc/handlers/load-model/handler.js +216 -98
- package/dist/server/rpc/handlers/load-model/http.js +3 -3
- package/dist/server/rpc/handlers/load-model/hyperdrive.js +1 -1
- package/dist/server/rpc/handlers/load-model/registry.js +1 -1
- package/dist/server/rpc/handlers/load-model/resolve-session.d.ts +20 -1
- package/dist/server/rpc/handlers/load-model/resolve-session.js +6 -5
- package/dist/server/rpc/handlers/load-model/resolve.d.ts +3 -2
- package/dist/server/rpc/handlers/load-model/resolve.js +18 -6
- package/dist/server/rpc/handlers/load-model/types.d.ts +24 -0
- package/dist/server/rpc/handlers/rag.js +133 -15
- package/dist/server/rpc/handlers/upscale-stream.d.ts +3 -0
- package/dist/server/rpc/handlers/upscale-stream.js +4 -0
- package/dist/server/rpc/handlers/video-stream.d.ts +3 -0
- package/dist/server/rpc/handlers/video-stream.js +4 -0
- package/dist/server/rpc/profiling/operation-metrics.js +23 -0
- package/dist/server/utils/completion-normalizer.js +8 -0
- package/dist/server/utils/config-transform.js +1 -1
- package/dist/server/utils/tools/dialect.js +4 -0
- package/dist/server/utils/tools/parser.js +16 -1
- package/dist/server/utils/tools/parsers/gemma4native.d.ts +4 -0
- package/dist/server/utils/tools/parsers/gemma4native.js +60 -0
- package/dist/server/utils/tools/parsers/qwen35.d.ts +4 -0
- package/dist/server/utils/tools/parsers/qwen35.js +120 -0
- package/dist/server/worker.js +14 -11
- package/dist/utils/aggregate-events.d.ts +9 -0
- package/dist/utils/aggregate-events.js +18 -3
- package/dist/utils/decorate-promise.d.ts +34 -0
- package/dist/utils/decorate-promise.js +35 -0
- package/dist/utils/errors-client.d.ts +18 -0
- package/dist/utils/errors-client.js +31 -0
- package/dist/utils/errors-server.d.ts +115 -2
- package/dist/utils/errors-server.js +148 -3
- package/package.json +68 -77
- package/dist/server/bare/plugins/onnx-tts/plugin.d.ts +0 -490
- package/dist/server/bare/plugins/onnx-tts/plugin.js +0 -266
- package/dist/server/bare/plugins/onnx-tts/wav-helper.d.ts +0 -14
- package/dist/server/bare/plugins/onnx-tts/wav-helper.js +0 -107
- /package/dist/server/bare/plugins/{onnx-tts → tts-ggml}/ops/text-to-speech-stream.d.ts +0 -0
- /package/dist/server/bare/plugins/{onnx-tts → tts-ggml}/ops/text-to-speech.d.ts +0 -0
|
@@ -1,3 +1,55 @@
|
|
|
1
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
+
}
|
|
18
|
+
else if (async) {
|
|
19
|
+
env.stack.push({ async: true });
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
+
return function (env) {
|
|
25
|
+
function fail(e) {
|
|
26
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
+
env.hasError = true;
|
|
28
|
+
}
|
|
29
|
+
var r, s = 0;
|
|
30
|
+
function next() {
|
|
31
|
+
while (r = env.stack.pop()) {
|
|
32
|
+
try {
|
|
33
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
+
if (r.dispose) {
|
|
35
|
+
var result = r.dispose.call(r.value);
|
|
36
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
+
}
|
|
38
|
+
else s |= 1;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
fail(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
+
if (env.hasError) throw env.error;
|
|
46
|
+
}
|
|
47
|
+
return next();
|
|
48
|
+
};
|
|
49
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
+
var e = new Error(message);
|
|
51
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
+
});
|
|
1
53
|
import { getModel, getModelConfig, getModelEntry, } from "../registry/model-registry.js";
|
|
2
54
|
import { ModelType, } from "../../../schemas/index.js";
|
|
3
55
|
import { createAudioStream } from "../utils/audio-input.js";
|
|
@@ -6,8 +58,9 @@ import { TranscriptionFailedError } from "../../../utils/errors-server.js";
|
|
|
6
58
|
import { nowMs } from "../../../profiling/index.js";
|
|
7
59
|
import { buildStreamResult } from "../../../profiling/model-execution.js";
|
|
8
60
|
import { assertMetadataSupported, toTranscribeSegment, } from "../utils/transcribe-metadata.js";
|
|
61
|
+
import { getRequestRegistry, withRequestContext, } from "../runtime/index.js";
|
|
62
|
+
import { generateServerRequestId } from "../runtime/request-id.js";
|
|
9
63
|
export { assertMetadataSupported, toTranscribeSegment, };
|
|
10
|
-
const logger = getServerLogger();
|
|
11
64
|
function hasRunStreaming(model) {
|
|
12
65
|
return "runStreaming" in model && typeof model.runStreaming === "function";
|
|
13
66
|
}
|
|
@@ -56,23 +109,60 @@ async function restorePrompt(modelId, originalConfig) {
|
|
|
56
109
|
...(miscConfig && { miscConfig }),
|
|
57
110
|
});
|
|
58
111
|
}
|
|
59
|
-
export async function* transcribe(params) {
|
|
60
|
-
const {
|
|
61
|
-
const engineType = getEngineModelType(modelId);
|
|
62
|
-
assertMetadataSupported(modelId, engineType, metadata);
|
|
63
|
-
const silenceMarker = SILENCE_MARKERS[engineType] ?? "";
|
|
64
|
-
const audioFormat = getAudioFormat(modelId, engineType);
|
|
65
|
-
const originalConfig = await applyPrompt(modelId, params.prompt, engineType);
|
|
66
|
-
let modelExecutionMs = 0;
|
|
67
|
-
let response;
|
|
112
|
+
export async function* transcribe(params, requestId) {
|
|
113
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
68
114
|
try {
|
|
115
|
+
const { modelId, metadata } = params;
|
|
116
|
+
// Open a request-scoped lifecycle. The registry routes
|
|
117
|
+
// `cancel({ requestId })` and `cancel({ modelId, kind: "transcribe" })`
|
|
118
|
+
// through this context. Falls back to a server-generated id if the
|
|
119
|
+
// client didn't send one.
|
|
120
|
+
const ctx = __addDisposableResource(env_1, getRequestRegistry().begin({
|
|
121
|
+
requestId: requestId ?? generateServerRequestId(),
|
|
122
|
+
kind: "transcribe",
|
|
123
|
+
modelId,
|
|
124
|
+
}), true);
|
|
125
|
+
const requestLogger = withRequestContext(getServerLogger(), ctx);
|
|
126
|
+
const engineType = getEngineModelType(modelId);
|
|
127
|
+
assertMetadataSupported(modelId, engineType, metadata);
|
|
128
|
+
const silenceMarker = SILENCE_MARKERS[engineType] ?? "";
|
|
129
|
+
const audioFormat = getAudioFormat(modelId, engineType);
|
|
130
|
+
const originalConfig = await applyPrompt(modelId, params.prompt, engineType);
|
|
131
|
+
if (originalConfig) {
|
|
132
|
+
// `restorePrompt` runs on every exit path — happy, throw, cancel —
|
|
133
|
+
// via the scope. LIFO unwinding pairs with the addon-cancel detach
|
|
134
|
+
// below.
|
|
135
|
+
ctx.scope.defer(() => restorePrompt(modelId, originalConfig));
|
|
136
|
+
}
|
|
69
137
|
const model = getModel(modelId);
|
|
138
|
+
// Hard-cancel wiring: whisper.cpp / parakeet expose model-wide
|
|
139
|
+
// `addon.cancel()`. The listener forwards an abort so the
|
|
140
|
+
// currently-running transcription stops decoding ASAP. The
|
|
141
|
+
// `if (ctx.signal.aborted) break` guard inside the iterate loop is
|
|
142
|
+
// the soft-cancel safety net for the case where the abort fires
|
|
143
|
+
// between the addon flag flipping and the iterator's next pull.
|
|
144
|
+
const onAbort = () => {
|
|
145
|
+
const addon = model.addon;
|
|
146
|
+
if (addon?.cancel) {
|
|
147
|
+
addon.cancel.call(addon).catch((err) => {
|
|
148
|
+
requestLogger.warn(`[cancel] addon.cancel() rejected during abort for modelId=${modelId}: ${err instanceof Error ? err.message : String(err)}`);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
ctx.signal.addEventListener("abort", onAbort, { once: true });
|
|
153
|
+
if (ctx.signal.aborted)
|
|
154
|
+
onAbort();
|
|
155
|
+
ctx.scope.defer(() => {
|
|
156
|
+
ctx.signal.removeEventListener("abort", onAbort);
|
|
157
|
+
});
|
|
70
158
|
const audioStream = await createAudioStream(params.audioChunk, audioFormat);
|
|
71
159
|
const modelStart = nowMs();
|
|
72
|
-
response = (await model.run(audioStream));
|
|
160
|
+
const response = (await model.run(audioStream));
|
|
73
161
|
for await (const output of response.iterate()) {
|
|
74
|
-
|
|
75
|
-
|
|
162
|
+
if (ctx.signal.aborted)
|
|
163
|
+
break;
|
|
164
|
+
requestLogger.debug("Streaming Transcription Update:", output);
|
|
165
|
+
const chunks = (Array.isArray(output) ? output : [output]);
|
|
76
166
|
if (metadata) {
|
|
77
167
|
for (const chunk of chunks) {
|
|
78
168
|
if (!chunk.text)
|
|
@@ -91,58 +181,148 @@ export async function* transcribe(params) {
|
|
|
91
181
|
yield text;
|
|
92
182
|
}
|
|
93
183
|
}
|
|
94
|
-
modelExecutionMs = nowMs() - modelStart;
|
|
184
|
+
const modelExecutionMs = nowMs() - modelStart;
|
|
185
|
+
const stats = {
|
|
186
|
+
...(response.stats?.audioDurationMs !== undefined && { audioDuration: response.stats.audioDurationMs }),
|
|
187
|
+
...(response.stats?.realTimeFactor !== undefined && { realTimeFactor: response.stats.realTimeFactor }),
|
|
188
|
+
...(response.stats?.tokensPerSecond !== undefined && { tokensPerSecond: response.stats.tokensPerSecond }),
|
|
189
|
+
...(response.stats?.totalTokens !== undefined && { totalTokens: response.stats.totalTokens }),
|
|
190
|
+
...(response.stats?.totalSegments !== undefined && { totalSegments: response.stats.totalSegments }),
|
|
191
|
+
...(response.stats?.whisperEncodeMs !== undefined && { whisperEncodeTime: response.stats.whisperEncodeMs }),
|
|
192
|
+
...(response.stats?.whisperDecodeMs !== undefined && { whisperDecodeTime: response.stats.whisperDecodeMs }),
|
|
193
|
+
...(response.stats?.encoderMs !== undefined && { encoderTime: response.stats.encoderMs }),
|
|
194
|
+
...(response.stats?.decoderMs !== undefined && { decoderTime: response.stats.decoderMs }),
|
|
195
|
+
...(response.stats?.melSpecMs !== undefined && { melSpecTime: response.stats.melSpecMs }),
|
|
196
|
+
};
|
|
197
|
+
return buildStreamResult(modelExecutionMs, stats);
|
|
198
|
+
}
|
|
199
|
+
catch (e_1) {
|
|
200
|
+
env_1.error = e_1;
|
|
201
|
+
env_1.hasError = true;
|
|
95
202
|
}
|
|
96
203
|
finally {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
204
|
+
const result_1 = __disposeResources(env_1);
|
|
205
|
+
if (result_1)
|
|
206
|
+
await result_1;
|
|
100
207
|
}
|
|
101
|
-
const stats = {
|
|
102
|
-
...(response?.stats?.audioDurationMs !== undefined && { audioDuration: response.stats.audioDurationMs }),
|
|
103
|
-
...(response?.stats?.realTimeFactor !== undefined && { realTimeFactor: response.stats.realTimeFactor }),
|
|
104
|
-
...(response?.stats?.tokensPerSecond !== undefined && { tokensPerSecond: response.stats.tokensPerSecond }),
|
|
105
|
-
...(response?.stats?.totalTokens !== undefined && { totalTokens: response.stats.totalTokens }),
|
|
106
|
-
...(response?.stats?.totalSegments !== undefined && { totalSegments: response.stats.totalSegments }),
|
|
107
|
-
...(response?.stats?.whisperEncodeMs !== undefined && { whisperEncodeTime: response.stats.whisperEncodeMs }),
|
|
108
|
-
...(response?.stats?.whisperDecodeMs !== undefined && { whisperDecodeTime: response.stats.whisperDecodeMs }),
|
|
109
|
-
...(response?.stats?.encoderMs !== undefined && { encoderTime: response.stats.encoderMs }),
|
|
110
|
-
...(response?.stats?.decoderMs !== undefined && { decoderTime: response.stats.decoderMs }),
|
|
111
|
-
...(response?.stats?.melSpecMs !== undefined && { melSpecTime: response.stats.melSpecMs }),
|
|
112
|
-
};
|
|
113
|
-
return buildStreamResult(modelExecutionMs, stats);
|
|
114
208
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const
|
|
209
|
+
function buildRunStreamingOpts(engineType, opts) {
|
|
210
|
+
if (engineType === ModelType.parakeetTranscription) {
|
|
211
|
+
return opts?.parakeetStreamingConfig;
|
|
212
|
+
}
|
|
213
|
+
const runOpts = {};
|
|
214
|
+
if (opts?.emitVadEvents)
|
|
215
|
+
runOpts.emitVadEvents = true;
|
|
216
|
+
if (opts?.endOfTurnSilenceMs !== undefined) {
|
|
217
|
+
runOpts.endOfTurnSilenceMs = opts.endOfTurnSilenceMs;
|
|
218
|
+
}
|
|
219
|
+
if (opts?.vadRunIntervalMs !== undefined) {
|
|
220
|
+
runOpts.vadRunIntervalMs = opts.vadRunIntervalMs;
|
|
221
|
+
}
|
|
222
|
+
return runOpts;
|
|
223
|
+
}
|
|
224
|
+
export async function* transcribeStream(modelId, audioInputStream, prompt, metadata, opts, requestId) {
|
|
225
|
+
const env_2 = { stack: [], error: void 0, hasError: false };
|
|
120
226
|
try {
|
|
227
|
+
// Same `kind: "transcribe"` as the unary variant — the registry
|
|
228
|
+
// doesn't distinguish streaming vs non-streaming variants of the same
|
|
229
|
+
// operation, so `cancel({ modelId, kind: "transcribe" })` cancels
|
|
230
|
+
// either shape.
|
|
231
|
+
const ctx = __addDisposableResource(env_2, getRequestRegistry().begin({
|
|
232
|
+
requestId: requestId ?? generateServerRequestId(),
|
|
233
|
+
kind: "transcribe",
|
|
234
|
+
modelId,
|
|
235
|
+
}), true);
|
|
236
|
+
const requestLogger = withRequestContext(getServerLogger(), ctx);
|
|
237
|
+
const engineType = getEngineModelType(modelId);
|
|
238
|
+
assertMetadataSupported(modelId, engineType, metadata);
|
|
239
|
+
const silenceMarker = SILENCE_MARKERS[engineType] ?? "";
|
|
240
|
+
const originalConfig = await applyPrompt(modelId, prompt, engineType);
|
|
241
|
+
if (originalConfig) {
|
|
242
|
+
ctx.scope.defer(() => restorePrompt(modelId, originalConfig));
|
|
243
|
+
}
|
|
121
244
|
const model = getModel(modelId);
|
|
122
245
|
if (!hasRunStreaming(model)) {
|
|
123
246
|
throw new TranscriptionFailedError(`Model ${modelId} does not support streaming transcription`);
|
|
124
247
|
}
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
248
|
+
const onAbort = () => {
|
|
249
|
+
const addon = model.addon;
|
|
250
|
+
if (addon?.cancel) {
|
|
251
|
+
addon.cancel.call(addon).catch((err) => {
|
|
252
|
+
requestLogger.warn(`[cancel] addon.cancel() rejected during abort for modelId=${modelId}: ${err instanceof Error ? err.message : String(err)}`);
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
ctx.signal.addEventListener("abort", onAbort, { once: true });
|
|
257
|
+
if (ctx.signal.aborted)
|
|
258
|
+
onAbort();
|
|
259
|
+
ctx.scope.defer(() => {
|
|
260
|
+
ctx.signal.removeEventListener("abort", onAbort);
|
|
261
|
+
});
|
|
262
|
+
const runOpts = buildRunStreamingOpts(engineType, opts);
|
|
263
|
+
const response = await model.runStreaming(audioInputStream, runOpts);
|
|
264
|
+
for await (const output of response.iterate()) {
|
|
265
|
+
if (ctx.signal.aborted)
|
|
266
|
+
break;
|
|
267
|
+
requestLogger.debug("Live Transcription Update:", output);
|
|
268
|
+
if (!Array.isArray(output)) {
|
|
269
|
+
if ("type" in output) {
|
|
270
|
+
if (output.type === "vad") {
|
|
271
|
+
yield {
|
|
272
|
+
type: "vad",
|
|
273
|
+
speaking: output.speaking,
|
|
274
|
+
probability: output.probability,
|
|
275
|
+
};
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
if (output.type === "endOfTurn") {
|
|
279
|
+
yield {
|
|
280
|
+
type: "endOfTurn",
|
|
281
|
+
source: "whisper",
|
|
282
|
+
silenceDurationMs: output.silenceDurationMs,
|
|
283
|
+
};
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
135
286
|
continue;
|
|
136
287
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
288
|
+
yield* emitSegment(output, metadata, silenceMarker);
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
for (const segment of output) {
|
|
292
|
+
yield* emitSegment(segment, metadata, silenceMarker);
|
|
140
293
|
}
|
|
141
294
|
}
|
|
142
295
|
}
|
|
296
|
+
catch (e_2) {
|
|
297
|
+
env_2.error = e_2;
|
|
298
|
+
env_2.hasError = true;
|
|
299
|
+
}
|
|
143
300
|
finally {
|
|
144
|
-
|
|
145
|
-
|
|
301
|
+
const result_2 = __disposeResources(env_2);
|
|
302
|
+
if (result_2)
|
|
303
|
+
await result_2;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
function* emitSegment(segment, metadata, silenceMarker) {
|
|
307
|
+
if (!segment.text) {
|
|
308
|
+
if (segment.isEndOfTurn) {
|
|
309
|
+
yield { type: "endOfTurn", source: "parakeet" };
|
|
146
310
|
}
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
if (silenceMarker && segment.text.includes(silenceMarker)) {
|
|
314
|
+
if (segment.isEndOfTurn) {
|
|
315
|
+
yield { type: "endOfTurn", source: "parakeet" };
|
|
316
|
+
}
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
if (metadata) {
|
|
320
|
+
yield toTranscribeSegment(segment);
|
|
321
|
+
}
|
|
322
|
+
else if (segment.text.trim()) {
|
|
323
|
+
yield segment.text;
|
|
324
|
+
}
|
|
325
|
+
if (segment.isEndOfTurn) {
|
|
326
|
+
yield { type: "endOfTurn", source: "parakeet" };
|
|
147
327
|
}
|
|
148
328
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type TranslateParams, type TranslationStats } from "../../../schemas/index";
|
|
2
2
|
export declare function getLanguage(code: string | undefined): string;
|
|
3
3
|
export declare function isAfrican(code: string | undefined): boolean;
|
|
4
|
-
export declare function translate(params: TranslateParams): AsyncGenerator<string, {
|
|
4
|
+
export declare function translate(params: TranslateParams, requestId?: string): AsyncGenerator<string, {
|
|
5
5
|
modelExecutionMs: number;
|
|
6
6
|
stats?: TranslationStats;
|
|
7
7
|
}, unknown>;
|
|
@@ -1,9 +1,64 @@
|
|
|
1
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
+
}
|
|
18
|
+
else if (async) {
|
|
19
|
+
env.stack.push({ async: true });
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
+
return function (env) {
|
|
25
|
+
function fail(e) {
|
|
26
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
+
env.hasError = true;
|
|
28
|
+
}
|
|
29
|
+
var r, s = 0;
|
|
30
|
+
function next() {
|
|
31
|
+
while (r = env.stack.pop()) {
|
|
32
|
+
try {
|
|
33
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
+
if (r.dispose) {
|
|
35
|
+
var result = r.dispose.call(r.value);
|
|
36
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
+
}
|
|
38
|
+
else s |= 1;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
fail(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
+
if (env.hasError) throw env.error;
|
|
46
|
+
}
|
|
47
|
+
return next();
|
|
48
|
+
};
|
|
49
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
+
var e = new Error(message);
|
|
51
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
+
});
|
|
1
53
|
import { getModelEntry } from "../registry/model-registry.js";
|
|
2
54
|
import { translateServerParamsSchema, normalizeModelType, ModelType, AFRICAN_LANGUAGES_MAP, } from "../../../schemas/index.js";
|
|
3
55
|
import { getLangName } from "@qvac/langdetect-text";
|
|
4
56
|
import { nowMs } from "../../../profiling/index.js";
|
|
5
57
|
import { buildStreamResult } from "../../../profiling/model-execution.js";
|
|
6
58
|
import { ModelIsDelegatedError, ModelNotFoundError, ModelTypeMismatchError, } from "../../../utils/errors-server.js";
|
|
59
|
+
import { getRequestRegistry, withRequestContext, } from "../runtime/index.js";
|
|
60
|
+
import { generateServerRequestId } from "../runtime/request-id.js";
|
|
61
|
+
import { getServerLogger } from "../../../logging/index.js";
|
|
7
62
|
export function getLanguage(code) {
|
|
8
63
|
if (!code)
|
|
9
64
|
return "";
|
|
@@ -26,104 +81,158 @@ const LLM_TRANSLATE_GENERATION_PARAMS = {
|
|
|
26
81
|
function shouldSkipPerCallSampling(modelName) {
|
|
27
82
|
return !!modelName && modelName.startsWith("AFRICAN_");
|
|
28
83
|
}
|
|
29
|
-
export async function* translate(params) {
|
|
30
|
-
const {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
throw new ModelIsDelegatedError(modelId);
|
|
37
|
-
}
|
|
38
|
-
const canonicalModelType = entry.local.modelType;
|
|
39
|
-
const model = entry.local.model;
|
|
40
|
-
if (inputModelType !== undefined) {
|
|
41
|
-
const requestedCanonical = normalizeModelType(inputModelType);
|
|
42
|
-
if (requestedCanonical !== canonicalModelType) {
|
|
43
|
-
throw new ModelTypeMismatchError(canonicalModelType, requestedCanonical);
|
|
84
|
+
export async function* translate(params, requestId) {
|
|
85
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
86
|
+
try {
|
|
87
|
+
const { modelId, text, modelType: inputModelType } = params;
|
|
88
|
+
const entry = getModelEntry(modelId);
|
|
89
|
+
if (!entry) {
|
|
90
|
+
throw new ModelNotFoundError(modelId);
|
|
44
91
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
canonicalModelType === ModelType.
|
|
57
|
-
|
|
92
|
+
if (entry.isDelegated) {
|
|
93
|
+
throw new ModelIsDelegatedError(modelId);
|
|
94
|
+
}
|
|
95
|
+
const canonicalModelType = entry.local.modelType;
|
|
96
|
+
const model = entry.local.model;
|
|
97
|
+
if (inputModelType !== undefined) {
|
|
98
|
+
const requestedCanonical = normalizeModelType(inputModelType);
|
|
99
|
+
if (requestedCanonical !== canonicalModelType) {
|
|
100
|
+
throw new ModelTypeMismatchError(canonicalModelType, requestedCanonical);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const isLlm = canonicalModelType === ModelType.llamacppCompletion;
|
|
104
|
+
const from = isLlm ? params.from : undefined;
|
|
105
|
+
const to = isLlm ? params.to : undefined;
|
|
106
|
+
const context = isLlm ? params.context : undefined;
|
|
107
|
+
const afriquePrompt = isLlm && (isAfrican(from) || isAfrican(to));
|
|
108
|
+
translateServerParamsSchema.parse(params);
|
|
109
|
+
const fromLanguage = getLanguage(from);
|
|
110
|
+
const toLanguage = getLanguage(to);
|
|
111
|
+
// Open a request-scoped lifecycle for both engine branches. LLM-
|
|
112
|
+
// translate inherits llamacpp-completion's `{ scope: "model",
|
|
113
|
+
// hard: true }` cancel surface; NMT-translate inherits nmtcpp's
|
|
114
|
+
// `{ scope: "none" }` — so the addon-cancel wiring below only
|
|
115
|
+
// engages on the LLM path. NMT cancel is purely soft: the loop
|
|
116
|
+
// exits on `signal.aborted`, scope unwinds, and the addon may run
|
|
117
|
+
// to completion in the background — acceptable because the result
|
|
118
|
+
// is dropped either way.
|
|
119
|
+
const ctx = __addDisposableResource(env_1, getRequestRegistry().begin({
|
|
120
|
+
requestId: requestId ?? generateServerRequestId(),
|
|
121
|
+
kind: "translate",
|
|
122
|
+
modelId,
|
|
123
|
+
}), true);
|
|
124
|
+
const requestLogger = withRequestContext(getServerLogger(), ctx);
|
|
125
|
+
if (isLlm) {
|
|
126
|
+
const onAbort = () => {
|
|
127
|
+
const addon = model.addon;
|
|
128
|
+
if (addon?.cancel) {
|
|
129
|
+
addon.cancel.call(addon).catch((err) => {
|
|
130
|
+
requestLogger.warn(`[cancel] addon.cancel() rejected during abort for modelId=${modelId}: ${err instanceof Error ? err.message : String(err)}`);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
ctx.signal.addEventListener("abort", onAbort, { once: true });
|
|
135
|
+
if (ctx.signal.aborted)
|
|
136
|
+
onAbort();
|
|
137
|
+
ctx.scope.defer(() => {
|
|
138
|
+
ctx.signal.removeEventListener("abort", onAbort);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
// Check if input is an array and model type is NMT
|
|
142
|
+
if (Array.isArray(text) &&
|
|
143
|
+
canonicalModelType === ModelType.nmtcppTranslation) {
|
|
144
|
+
// Use runBatch for batch processing
|
|
145
|
+
const modelStart = nowMs();
|
|
146
|
+
const translations = await model.runBatch(text);
|
|
147
|
+
const modelExecutionMs = nowMs() - modelStart;
|
|
148
|
+
// Soft-cancel boundary: if `cancel({ requestId })` landed while
|
|
149
|
+
// the addon was running the batch, bail before yielding anything.
|
|
150
|
+
// The addon may have completed its work; the result is dropped.
|
|
151
|
+
if (ctx.signal.aborted) {
|
|
152
|
+
return { modelExecutionMs };
|
|
153
|
+
}
|
|
154
|
+
// Yield each translation with a newline separator
|
|
155
|
+
for (let i = 0; i < translations.length; i++) {
|
|
156
|
+
if (ctx.signal.aborted)
|
|
157
|
+
break;
|
|
158
|
+
const translation = translations[i];
|
|
159
|
+
yield translation;
|
|
160
|
+
if (i < translations.length - 1) {
|
|
161
|
+
yield "\n";
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return { modelExecutionMs };
|
|
165
|
+
}
|
|
166
|
+
// Single text processing (for NMT or LLM)
|
|
167
|
+
const singleText = Array.isArray(text) ? text[0] : text;
|
|
168
|
+
// Prepare input based on model type
|
|
169
|
+
const input = canonicalModelType === ModelType.nmtcppTranslation
|
|
170
|
+
? singleText
|
|
171
|
+
: [
|
|
172
|
+
{
|
|
173
|
+
role: afriquePrompt ? "user" : "system",
|
|
174
|
+
content: afriquePrompt
|
|
175
|
+
? `Translate ${fromLanguage} to ${toLanguage}.\n${fromLanguage}: ${singleText}\n${toLanguage}:`
|
|
176
|
+
: `${context ? `${context}. ` : ""}Translate the following text from ${fromLanguage} into ${toLanguage}. Only output the translation, nothing else.\n\n${fromLanguage}: ${singleText}\n${toLanguage}:`,
|
|
177
|
+
},
|
|
178
|
+
];
|
|
58
179
|
const modelStart = nowMs();
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
180
|
+
let response;
|
|
181
|
+
if (canonicalModelType === ModelType.llamacppCompletion &&
|
|
182
|
+
!shouldSkipPerCallSampling(entry.local.name)) {
|
|
183
|
+
// AnyModel.run is intentionally erased to a single-arg signature in the
|
|
184
|
+
// registry layer (Omit<BaseInference, "addon">). Re-narrow to the engine
|
|
185
|
+
// shape so we get the same typing as @qvac/llm-llamacpp.run().
|
|
186
|
+
const llmRun = model.run.bind(model);
|
|
187
|
+
response = await llmRun(input, {
|
|
188
|
+
generationParams: LLM_TRANSLATE_GENERATION_PARAMS,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
response = await model.run(input);
|
|
193
|
+
}
|
|
194
|
+
// Check if the response has an iterate method (like LLM models)
|
|
195
|
+
if (canonicalModelType === ModelType.llamacppCompletion &&
|
|
196
|
+
typeof response.iterate === "function") {
|
|
197
|
+
const llmResponse = response;
|
|
198
|
+
for await (const token of llmResponse.iterate()) {
|
|
199
|
+
if (ctx.signal.aborted)
|
|
200
|
+
break;
|
|
201
|
+
yield token;
|
|
67
202
|
}
|
|
203
|
+
const modelExecutionMs = nowMs() - modelStart;
|
|
204
|
+
const stats = {
|
|
205
|
+
...(llmResponse.stats?.TPS !== undefined && { tokensPerSecond: llmResponse.stats.TPS }),
|
|
206
|
+
...(llmResponse.stats?.TTFT !== undefined && { timeToFirstToken: llmResponse.stats.TTFT }),
|
|
207
|
+
...(llmResponse.stats?.CacheTokens !== undefined && { cacheTokens: llmResponse.stats.CacheTokens }),
|
|
208
|
+
...(llmResponse.stats?.generatedTokens !== undefined && { totalTokens: llmResponse.stats.generatedTokens }),
|
|
209
|
+
};
|
|
210
|
+
return buildStreamResult(modelExecutionMs, stats);
|
|
68
211
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
// Prepare input based on model type
|
|
74
|
-
const input = canonicalModelType === ModelType.nmtcppTranslation
|
|
75
|
-
? singleText
|
|
76
|
-
: [
|
|
77
|
-
{
|
|
78
|
-
role: afriquePrompt ? "user" : "system",
|
|
79
|
-
content: afriquePrompt
|
|
80
|
-
? `Translate ${fromLanguage} to ${toLanguage}.\n${fromLanguage}: ${singleText}\n${toLanguage}:`
|
|
81
|
-
: `${context ? `${context}. ` : ""}Translate the following text from ${fromLanguage} into ${toLanguage}. Only output the translation, nothing else.\n\n${fromLanguage}: ${singleText}\n${toLanguage}:`,
|
|
82
|
-
},
|
|
83
|
-
];
|
|
84
|
-
const modelStart = nowMs();
|
|
85
|
-
let response;
|
|
86
|
-
if (canonicalModelType === ModelType.llamacppCompletion &&
|
|
87
|
-
!shouldSkipPerCallSampling(entry.local.name)) {
|
|
88
|
-
// AnyModel.run is intentionally erased to a single-arg signature in the
|
|
89
|
-
// registry layer (Omit<BaseInference, "addon">). Re-narrow to the engine
|
|
90
|
-
// shape so we get the same typing as @qvac/llm-llamacpp.run().
|
|
91
|
-
const llmRun = model.run.bind(model);
|
|
92
|
-
response = await llmRun(input, {
|
|
93
|
-
generationParams: LLM_TRANSLATE_GENERATION_PARAMS,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
response = await model.run(input);
|
|
98
|
-
}
|
|
99
|
-
// Check if the response has an iterate method (like LLM models)
|
|
100
|
-
if (canonicalModelType === ModelType.llamacppCompletion &&
|
|
101
|
-
typeof response.iterate === "function") {
|
|
102
|
-
const llmResponse = response;
|
|
103
|
-
for await (const token of llmResponse.iterate()) {
|
|
212
|
+
const nmtResponse = response;
|
|
213
|
+
for await (const token of nmtResponse.iterate()) {
|
|
214
|
+
if (ctx.signal.aborted)
|
|
215
|
+
break;
|
|
104
216
|
yield token;
|
|
105
217
|
}
|
|
106
218
|
const modelExecutionMs = nowMs() - modelStart;
|
|
107
219
|
const stats = {
|
|
108
|
-
...(
|
|
109
|
-
...(
|
|
110
|
-
...(
|
|
111
|
-
...(
|
|
220
|
+
...(nmtResponse.stats?.totalTime !== undefined && { totalTime: nmtResponse.stats.totalTime }),
|
|
221
|
+
...(nmtResponse.stats?.totalTokens !== undefined && { totalTokens: nmtResponse.stats.totalTokens }),
|
|
222
|
+
...(nmtResponse.stats?.decodeTime !== undefined && { decodeTime: nmtResponse.stats.decodeTime }),
|
|
223
|
+
...(nmtResponse.stats?.encodeTime !== undefined && { encodeTime: nmtResponse.stats.encodeTime }),
|
|
224
|
+
...(nmtResponse.stats?.TPS !== undefined && { tokensPerSecond: nmtResponse.stats.TPS }),
|
|
225
|
+
...(nmtResponse.stats?.TTFT !== undefined && { timeToFirstToken: nmtResponse.stats.TTFT }),
|
|
112
226
|
};
|
|
113
227
|
return buildStreamResult(modelExecutionMs, stats);
|
|
114
228
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
229
|
+
catch (e_1) {
|
|
230
|
+
env_1.error = e_1;
|
|
231
|
+
env_1.hasError = true;
|
|
232
|
+
}
|
|
233
|
+
finally {
|
|
234
|
+
const result_1 = __disposeResources(env_1);
|
|
235
|
+
if (result_1)
|
|
236
|
+
await result_1;
|
|
118
237
|
}
|
|
119
|
-
const modelExecutionMs = nowMs() - modelStart;
|
|
120
|
-
const stats = {
|
|
121
|
-
...(nmtResponse.stats?.totalTime !== undefined && { totalTime: nmtResponse.stats.totalTime }),
|
|
122
|
-
...(nmtResponse.stats?.totalTokens !== undefined && { totalTokens: nmtResponse.stats.totalTokens }),
|
|
123
|
-
...(nmtResponse.stats?.decodeTime !== undefined && { decodeTime: nmtResponse.stats.decodeTime }),
|
|
124
|
-
...(nmtResponse.stats?.encodeTime !== undefined && { encodeTime: nmtResponse.stats.encodeTime }),
|
|
125
|
-
...(nmtResponse.stats?.TPS !== undefined && { tokensPerSecond: nmtResponse.stats.TPS }),
|
|
126
|
-
...(nmtResponse.stats?.TTFT !== undefined && { timeToFirstToken: nmtResponse.stats.TTFT }),
|
|
127
|
-
};
|
|
128
|
-
return buildStreamResult(modelExecutionMs, stats);
|
|
129
238
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ClassifyRequest, type ClassificationResult } from "../../../../../schemas/index";
|
|
2
|
+
export declare function classify(params: ClassifyRequest): Promise<{
|
|
3
|
+
results: ClassificationResult[];
|
|
4
|
+
modelExecutionMs: number;
|
|
5
|
+
}>;
|
|
6
|
+
//# sourceMappingURL=classify.d.ts.map
|