@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
package/README.md
CHANGED
|
@@ -16,6 +16,8 @@ See [https://docs.qvac.tether.io/sdk/getting-started](https://docs.qvac.tether.i
|
|
|
16
16
|
|
|
17
17
|
For AI/LLM tools, use [https://docs.qvac.tether.io/llms-full.txt](https://docs.qvac.tether.io/llms-full.txt) as the consolidated plaintext documentation export.
|
|
18
18
|
|
|
19
|
+
> **Assembling a custom worker on Bare?** See [`@qvac/bare-sdk`](../bare-sdk/README.md) — the same SDK surface with no built-in plugin addons, designed for consumers wiring their own worker entry (Pear apps, bare-expo apps, direct Bare scripts).
|
|
20
|
+
|
|
19
21
|
## Supported environments and installation
|
|
20
22
|
|
|
21
23
|
See https://docs.qvac.tether.io/sdk/getting-started/installation
|
|
@@ -1,43 +1,35 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type CancelClientInput } from "../../schemas/index";
|
|
2
2
|
/**
|
|
3
3
|
* Cancels an ongoing operation.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
5
|
+
* Two cancel paths are supported:
|
|
6
|
+
* - **By `requestId`** (primary) — pass the `requestId` exposed on
|
|
7
|
+
* the result of a long-running call (`completion(...)`,
|
|
8
|
+
* `loadModel(...)`, `downloadAsset(...)`, `embed(...)`,
|
|
9
|
+
* `transcribe(...)`, `ragIngest(...)`, etc.) to cancel exactly
|
|
10
|
+
* that request. A cancel that races the originating call is
|
|
11
|
+
* recorded and applied retroactively when the begin arrives.
|
|
12
|
+
* - **Broad by `modelId`** (escape hatch) — `{ modelId, kind? }`
|
|
13
|
+
* cancels every in-flight request on that model. Useful for
|
|
14
|
+
* model unload, app shutdown, or admin sweeps where the caller
|
|
15
|
+
* doesn't have a `requestId` to hand.
|
|
13
16
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* // Pause download (preserves partial file for automatic resume)
|
|
20
|
-
* await cancel({ operation: "downloadAsset", downloadKey: "download-key" });
|
|
17
|
+
* The legacy `{ operation: "inference" | "embeddings", modelId }`
|
|
18
|
+
* sugars remain callable for source compatibility. For migration off
|
|
19
|
+
* the removed `{ operation: "downloadAsset" | "rag" }` shapes, see
|
|
20
|
+
* the 0.11.0 changelog / release notes.
|
|
21
21
|
*
|
|
22
|
-
* @
|
|
23
|
-
*
|
|
24
|
-
* await cancel({ operation: "downloadAsset", downloadKey: "download-key", clearCache: true });
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* // Cancel delegated remote download
|
|
28
|
-
* await cancel({
|
|
29
|
-
* operation: "downloadAsset",
|
|
30
|
-
* downloadKey: "download-key",
|
|
31
|
-
* delegate: { providerPublicKey: "peerHex" },
|
|
32
|
-
* });
|
|
22
|
+
* @param params - The cancellation parameters.
|
|
23
|
+
* @throws {QvacErrorBase} When the response type is invalid or the cancellation fails.
|
|
33
24
|
*
|
|
34
25
|
* @example
|
|
35
|
-
* // Cancel
|
|
36
|
-
*
|
|
26
|
+
* // Cancel by requestId (primary path)
|
|
27
|
+
* const run = completion({ ... });
|
|
28
|
+
* await cancel({ requestId: run.requestId });
|
|
37
29
|
*
|
|
38
30
|
* @example
|
|
39
|
-
* //
|
|
40
|
-
* await cancel({
|
|
31
|
+
* // Broad-cancel every inference running on a model
|
|
32
|
+
* await cancel({ modelId: "model-123", kind: "completion" });
|
|
41
33
|
*/
|
|
42
|
-
export declare function cancel(params:
|
|
34
|
+
export declare function cancel(params: CancelClientInput): Promise<void>;
|
|
43
35
|
//# sourceMappingURL=cancel.d.ts.map
|
|
@@ -4,47 +4,40 @@ import { InvalidResponseError, CancelFailedError } from "../../utils/errors-clie
|
|
|
4
4
|
/**
|
|
5
5
|
* Cancels an ongoing operation.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
7
|
+
* Two cancel paths are supported:
|
|
8
|
+
* - **By `requestId`** (primary) — pass the `requestId` exposed on
|
|
9
|
+
* the result of a long-running call (`completion(...)`,
|
|
10
|
+
* `loadModel(...)`, `downloadAsset(...)`, `embed(...)`,
|
|
11
|
+
* `transcribe(...)`, `ragIngest(...)`, etc.) to cancel exactly
|
|
12
|
+
* that request. A cancel that races the originating call is
|
|
13
|
+
* recorded and applied retroactively when the begin arrives.
|
|
14
|
+
* - **Broad by `modelId`** (escape hatch) — `{ modelId, kind? }`
|
|
15
|
+
* cancels every in-flight request on that model. Useful for
|
|
16
|
+
* model unload, app shutdown, or admin sweeps where the caller
|
|
17
|
+
* doesn't have a `requestId` to hand.
|
|
15
18
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* // Pause download (preserves partial file for automatic resume)
|
|
22
|
-
* await cancel({ operation: "downloadAsset", downloadKey: "download-key" });
|
|
19
|
+
* The legacy `{ operation: "inference" | "embeddings", modelId }`
|
|
20
|
+
* sugars remain callable for source compatibility. For migration off
|
|
21
|
+
* the removed `{ operation: "downloadAsset" | "rag" }` shapes, see
|
|
22
|
+
* the 0.11.0 changelog / release notes.
|
|
23
23
|
*
|
|
24
|
-
* @
|
|
25
|
-
*
|
|
26
|
-
* await cancel({ operation: "downloadAsset", downloadKey: "download-key", clearCache: true });
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* // Cancel delegated remote download
|
|
30
|
-
* await cancel({
|
|
31
|
-
* operation: "downloadAsset",
|
|
32
|
-
* downloadKey: "download-key",
|
|
33
|
-
* delegate: { providerPublicKey: "peerHex" },
|
|
34
|
-
* });
|
|
24
|
+
* @param params - The cancellation parameters.
|
|
25
|
+
* @throws {QvacErrorBase} When the response type is invalid or the cancellation fails.
|
|
35
26
|
*
|
|
36
27
|
* @example
|
|
37
|
-
* // Cancel
|
|
38
|
-
*
|
|
28
|
+
* // Cancel by requestId (primary path)
|
|
29
|
+
* const run = completion({ ... });
|
|
30
|
+
* await cancel({ requestId: run.requestId });
|
|
39
31
|
*
|
|
40
32
|
* @example
|
|
41
|
-
* //
|
|
42
|
-
* await cancel({
|
|
33
|
+
* // Broad-cancel every inference running on a model
|
|
34
|
+
* await cancel({ modelId: "model-123", kind: "completion" });
|
|
43
35
|
*/
|
|
44
36
|
export async function cancel(params) {
|
|
37
|
+
const wireParams = normalizeCancelParams(params);
|
|
45
38
|
const request = {
|
|
46
39
|
type: "cancel",
|
|
47
|
-
...
|
|
40
|
+
...wireParams,
|
|
48
41
|
};
|
|
49
42
|
const response = await send(request);
|
|
50
43
|
if (response.type !== "cancel") {
|
|
@@ -54,3 +47,37 @@ export async function cancel(params) {
|
|
|
54
47
|
throw new CancelFailedError(response.error);
|
|
55
48
|
}
|
|
56
49
|
}
|
|
50
|
+
function normalizeCancelParams(params) {
|
|
51
|
+
if ("operation" in params) {
|
|
52
|
+
if (params.operation === "request" || params.operation === "broad") {
|
|
53
|
+
return params;
|
|
54
|
+
}
|
|
55
|
+
// Legacy per-kind sugar: { operation: "inference"|"embeddings", modelId }
|
|
56
|
+
if (params.operation === "inference") {
|
|
57
|
+
return {
|
|
58
|
+
operation: "broad",
|
|
59
|
+
modelId: params.modelId,
|
|
60
|
+
kind: "completion",
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return { operation: "broad", modelId: params.modelId, kind: "embeddings" };
|
|
64
|
+
}
|
|
65
|
+
if ("requestId" in params) {
|
|
66
|
+
const wire = {
|
|
67
|
+
operation: "request",
|
|
68
|
+
requestId: params.requestId,
|
|
69
|
+
};
|
|
70
|
+
if (params.clearCache !== undefined) {
|
|
71
|
+
wire.clearCache = params.clearCache;
|
|
72
|
+
}
|
|
73
|
+
return wire;
|
|
74
|
+
}
|
|
75
|
+
const broad = {
|
|
76
|
+
operation: "broad",
|
|
77
|
+
modelId: params.modelId,
|
|
78
|
+
};
|
|
79
|
+
if (params.kind !== undefined) {
|
|
80
|
+
broad.kind = params.kind;
|
|
81
|
+
}
|
|
82
|
+
return broad;
|
|
83
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type ClassifyClientParams, type ClassificationResult } from "../../schemas/index";
|
|
2
|
+
/**
|
|
3
|
+
* Classifies an image using a loaded classification model.
|
|
4
|
+
*
|
|
5
|
+
* The bundled MobileNetV3-Small model produces 3 labels: `"food"`, `"report"`, `"other"`.
|
|
6
|
+
* Custom models may emit different labels sourced from the GGUF metadata.
|
|
7
|
+
*
|
|
8
|
+
* @param params.modelId - The identifier of the loaded classification model
|
|
9
|
+
* @param params.image - JPEG or PNG buffer; raw RGB bytes also accepted with `width`, `height`, `channels`
|
|
10
|
+
* @param params.topK - Limit results to top-K classes (default: all)
|
|
11
|
+
* @returns Sorted classification results, highest confidence first
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const modelId = await loadModel({ modelType: "ggml-classification" });
|
|
16
|
+
* const jpeg = fs.readFileSync("photo.jpg");
|
|
17
|
+
* const results = await classify({ modelId, image: jpeg });
|
|
18
|
+
* // [ { label: "food", confidence: 0.93 }, { label: "other", confidence: 0.05 }, ... ]
|
|
19
|
+
* await unloadModel({ modelId });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function classify(params: ClassifyClientParams): Promise<ClassificationResult[]>;
|
|
23
|
+
//# sourceMappingURL=classify.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { classifyResponseSchema, } from "../../schemas/index.js";
|
|
2
|
+
import { stream as streamRpc } from "../rpc/rpc-client.js";
|
|
3
|
+
import { encodeBase64 } from "../../utils/encoding.js";
|
|
4
|
+
/**
|
|
5
|
+
* Classifies an image using a loaded classification model.
|
|
6
|
+
*
|
|
7
|
+
* The bundled MobileNetV3-Small model produces 3 labels: `"food"`, `"report"`, `"other"`.
|
|
8
|
+
* Custom models may emit different labels sourced from the GGUF metadata.
|
|
9
|
+
*
|
|
10
|
+
* @param params.modelId - The identifier of the loaded classification model
|
|
11
|
+
* @param params.image - JPEG or PNG buffer; raw RGB bytes also accepted with `width`, `height`, `channels`
|
|
12
|
+
* @param params.topK - Limit results to top-K classes (default: all)
|
|
13
|
+
* @returns Sorted classification results, highest confidence first
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const modelId = await loadModel({ modelType: "ggml-classification" });
|
|
18
|
+
* const jpeg = fs.readFileSync("photo.jpg");
|
|
19
|
+
* const results = await classify({ modelId, image: jpeg });
|
|
20
|
+
* // [ { label: "food", confidence: 0.93 }, { label: "other", confidence: 0.05 }, ... ]
|
|
21
|
+
* await unloadModel({ modelId });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export async function classify(params) {
|
|
25
|
+
const request = {
|
|
26
|
+
type: "classify",
|
|
27
|
+
modelId: params.modelId,
|
|
28
|
+
image: encodeBase64(params.image),
|
|
29
|
+
...(params.topK !== undefined && { topK: params.topK }),
|
|
30
|
+
...(params.width !== undefined && { width: params.width }),
|
|
31
|
+
...(params.height !== undefined && { height: params.height }),
|
|
32
|
+
...(params.channels !== undefined && { channels: params.channels }),
|
|
33
|
+
};
|
|
34
|
+
for await (const response of streamRpc(request)) {
|
|
35
|
+
if (response && typeof response === "object" && "type" in response && response.type === "classify") {
|
|
36
|
+
const parsed = classifyResponseSchema.parse(response);
|
|
37
|
+
if (parsed.done) {
|
|
38
|
+
return parsed.results;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UUIDv4 generator for client-side request ids. The Web Crypto API
|
|
3
|
+
* ships `crypto.randomUUID` everywhere we run today (Bun, modern Node,
|
|
4
|
+
* modern browsers, React Native via the polyfill that the workbench-
|
|
5
|
+
* desktop / RN runtime config injects). The fallback exists so the SDK
|
|
6
|
+
* never crashes in an exotic JS environment without
|
|
7
|
+
* `crypto.randomUUID` — `requestId` semantics still hold (uniqueness,
|
|
8
|
+
* opaque to the caller), just without the UUIDv4 wire shape.
|
|
9
|
+
*
|
|
10
|
+
* Shared with the long-running call sites that decorate their promises
|
|
11
|
+
* with `requestId`: `completion(...)`, `loadModel(...)`,
|
|
12
|
+
* `downloadAsset(...)`. The decorated promise's `op.requestId` and the
|
|
13
|
+
* server's registry entry's `requestId` must match — generating once
|
|
14
|
+
* here keeps that invariant.
|
|
15
|
+
*/
|
|
16
|
+
export declare function generateClientRequestId(): string;
|
|
17
|
+
//# sourceMappingURL=client-request-id.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UUIDv4 generator for client-side request ids. The Web Crypto API
|
|
3
|
+
* ships `crypto.randomUUID` everywhere we run today (Bun, modern Node,
|
|
4
|
+
* modern browsers, React Native via the polyfill that the workbench-
|
|
5
|
+
* desktop / RN runtime config injects). The fallback exists so the SDK
|
|
6
|
+
* never crashes in an exotic JS environment without
|
|
7
|
+
* `crypto.randomUUID` — `requestId` semantics still hold (uniqueness,
|
|
8
|
+
* opaque to the caller), just without the UUIDv4 wire shape.
|
|
9
|
+
*
|
|
10
|
+
* Shared with the long-running call sites that decorate their promises
|
|
11
|
+
* with `requestId`: `completion(...)`, `loadModel(...)`,
|
|
12
|
+
* `downloadAsset(...)`. The decorated promise's `op.requestId` and the
|
|
13
|
+
* server's registry entry's `requestId` must match — generating once
|
|
14
|
+
* here keeps that invariant.
|
|
15
|
+
*/
|
|
16
|
+
export function generateClientRequestId() {
|
|
17
|
+
const c = globalThis.crypto;
|
|
18
|
+
if (c?.randomUUID)
|
|
19
|
+
return c.randomUUID();
|
|
20
|
+
// Fallback: 128 random bits encoded as a hex string. Distinct enough
|
|
21
|
+
// for in-flight cancel targeting; not a wire-spec UUID.
|
|
22
|
+
const bytes = new Uint8Array(16);
|
|
23
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
24
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
25
|
+
}
|
|
26
|
+
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
27
|
+
}
|
|
@@ -28,7 +28,7 @@ type CompletionParams = Omit<CompletionClientParams, "tools"> & {
|
|
|
28
28
|
* @param params.mcp - Optional array of MCP client inputs for tool integration
|
|
29
29
|
* @param params.captureThinking - Best-effort parsing of `<think>` blocks into `thinkingDelta` events; `final.raw.fullText` always preserves the original output
|
|
30
30
|
* @param params.emitRawDeltas - When true, every raw model token is also emitted as a `rawDelta` event
|
|
31
|
-
* @param params.toolDialect - Override the SDK's name-based dialect detection.
|
|
31
|
+
* @param params.toolDialect - Override the SDK's name-based dialect detection. Supported values: `"hermes"`, `"pythonic"`, `"json"`, `"harmony"`, `"qwen35"` (Qwen3.5/3.6), `"gemma4"`. Use when the auto-router doesn't recognise your model name. Drives both streaming frame detection and finalization parsing.
|
|
32
32
|
* Common override case: Llama 3.x tool-calling fine-tunes that emit the native pythonic header (`<|start_header_id|>tool_call<|end_header_id|>...<|eot_id|>`).
|
|
33
33
|
* @param params.responseFormat - Optional structured-output constraint applied to the model's output:
|
|
34
34
|
* - `{ type: "text" }` — no constraint (default behavior)
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { stream as streamRpc } from "../rpc/rpc-client.js";
|
|
2
2
|
import { getClientLogger } from "../../logging/index.js";
|
|
3
3
|
import { completionStreamResponseSchema, } from "../../schemas/index.js";
|
|
4
|
-
import { CompletionFailedError } from "../../utils/errors-server.js";
|
|
4
|
+
import { CompletionFailedError, InferenceCancelledError, } from "../../utils/errors-server.js";
|
|
5
5
|
import { getMcpToolsWithHandlers } from "../../utils/mcp-adapter.js";
|
|
6
6
|
import { validateTools, } from "../../utils/tool-helpers.js";
|
|
7
7
|
import { buildFinalFromEvents } from "../../utils/aggregate-events.js";
|
|
8
|
+
import { generateClientRequestId } from "./client-request-id.js";
|
|
8
9
|
const logger = getClientLogger();
|
|
9
10
|
/**
|
|
10
11
|
* Generates completion from a language model based on conversation history.
|
|
@@ -27,7 +28,7 @@ const logger = getClientLogger();
|
|
|
27
28
|
* @param params.mcp - Optional array of MCP client inputs for tool integration
|
|
28
29
|
* @param params.captureThinking - Best-effort parsing of `<think>` blocks into `thinkingDelta` events; `final.raw.fullText` always preserves the original output
|
|
29
30
|
* @param params.emitRawDeltas - When true, every raw model token is also emitted as a `rawDelta` event
|
|
30
|
-
* @param params.toolDialect - Override the SDK's name-based dialect detection.
|
|
31
|
+
* @param params.toolDialect - Override the SDK's name-based dialect detection. Supported values: `"hermes"`, `"pythonic"`, `"json"`, `"harmony"`, `"qwen35"` (Qwen3.5/3.6), `"gemma4"`. Use when the auto-router doesn't recognise your model name. Drives both streaming frame detection and finalization parsing.
|
|
31
32
|
* Common override case: Llama 3.x tool-calling fine-tunes that emit the native pythonic header (`<|start_header_id|>tool_call<|end_header_id|>...<|eot_id|>`).
|
|
32
33
|
* @param params.responseFormat - Optional structured-output constraint applied to the model's output:
|
|
33
34
|
* - `{ type: "text" }` — no constraint (default behavior)
|
|
@@ -102,6 +103,13 @@ const logger = getClientLogger();
|
|
|
102
103
|
* ```
|
|
103
104
|
*/
|
|
104
105
|
export function completion(params) {
|
|
106
|
+
// Stable identity for this run, generated client-side so it's
|
|
107
|
+
// available synchronously the moment we return — before the first
|
|
108
|
+
// network round-trip and therefore before the user could possibly
|
|
109
|
+
// have a "stop" handler. Surfaced on the returned `CompletionRun`
|
|
110
|
+
// (`run.requestId`) so callers can `cancel({ requestId })` at any
|
|
111
|
+
// point during the stream.
|
|
112
|
+
const requestId = generateClientRequestId();
|
|
105
113
|
let statsResolver = () => { };
|
|
106
114
|
let statsRejecter = () => { };
|
|
107
115
|
const statsPromise = new Promise((resolve, reject) => {
|
|
@@ -182,6 +190,7 @@ export function completion(params) {
|
|
|
182
190
|
emitRawDeltas: params.emitRawDeltas,
|
|
183
191
|
toolDialect: params.toolDialect,
|
|
184
192
|
responseFormat: params.responseFormat,
|
|
193
|
+
requestId,
|
|
185
194
|
};
|
|
186
195
|
const responses = streamRpc(request, params.rpcOptions);
|
|
187
196
|
for await (const response of responses) {
|
|
@@ -202,13 +211,33 @@ export function completion(params) {
|
|
|
202
211
|
}
|
|
203
212
|
notifyWaiters();
|
|
204
213
|
if (streamResponse.done) {
|
|
205
|
-
const { final, error } = buildFinalFromEvents(allEvents, allHandlers);
|
|
214
|
+
const { final, error, cancelled } = buildFinalFromEvents(allEvents, allHandlers);
|
|
206
215
|
if (error) {
|
|
207
216
|
const err = new CompletionFailedError(error.message, error);
|
|
208
217
|
finalRejecter(err);
|
|
209
218
|
statsRejecter(err);
|
|
210
219
|
toolCallsRejecter(err);
|
|
211
220
|
}
|
|
221
|
+
else if (cancelled) {
|
|
222
|
+
// The wire stream ended with `stopReason: "cancelled"` — the
|
|
223
|
+
// run was aborted mid-flight. Cancellation contract: `events`
|
|
224
|
+
// ends normally (consumers iterating `run.events` see the
|
|
225
|
+
// cancelled `completionDone` and exit naturally), and the
|
|
226
|
+
// promise-aggregates reject with `InferenceCancelledError`
|
|
227
|
+
// carrying whatever the aggregator accumulated up to the
|
|
228
|
+
// cancel point. Consumers do `instanceof
|
|
229
|
+
// InferenceCancelledError` and read `.partial.text` /
|
|
230
|
+
// `.partial.toolCalls` / `.partial.stats` if they want the
|
|
231
|
+
// partial output.
|
|
232
|
+
const err = new InferenceCancelledError(requestId, {
|
|
233
|
+
text: final.contentText,
|
|
234
|
+
toolCalls: final.toolCalls,
|
|
235
|
+
...(final.stats && { stats: final.stats }),
|
|
236
|
+
});
|
|
237
|
+
finalRejecter(err);
|
|
238
|
+
statsRejecter(err);
|
|
239
|
+
toolCallsRejecter(err);
|
|
240
|
+
}
|
|
212
241
|
else {
|
|
213
242
|
finalResolver(final);
|
|
214
243
|
statsResolver(final.stats);
|
|
@@ -291,6 +320,7 @@ export function completion(params) {
|
|
|
291
320
|
}
|
|
292
321
|
})();
|
|
293
322
|
return {
|
|
323
|
+
requestId,
|
|
294
324
|
events: eventStream,
|
|
295
325
|
final: finalPromise,
|
|
296
326
|
tokenStream,
|
|
@@ -308,6 +338,7 @@ export function completion(params) {
|
|
|
308
338
|
//Empty generator for non-streaming mode
|
|
309
339
|
})();
|
|
310
340
|
return {
|
|
341
|
+
requestId,
|
|
311
342
|
events: eventStream,
|
|
312
343
|
final: finalPromise,
|
|
313
344
|
tokenStream,
|
|
@@ -34,6 +34,52 @@ interface DiffusionResult {
|
|
|
34
34
|
* // modelConfig: { prediction: "flux2_flow" } })`).
|
|
35
35
|
* const { outputs } = diffusion({ modelId, prompt: "turn into watercolor", init_image: initImage });
|
|
36
36
|
*
|
|
37
|
+
* // FLUX.2 multi-reference fusion
|
|
38
|
+
* // IMPORTANT: requires the model loaded with `modelConfig: { prediction: "flux2_flow" }`
|
|
39
|
+
* // and a Qwen3 text encoder via `llmModelSrc` (same loadModel requirements as the
|
|
40
|
+
* // FLUX.2 img2img example above). `init_image` and `init_images` are mutually
|
|
41
|
+
* // exclusive — pass one or the other, not both.
|
|
42
|
+
* const refA = fs.readFileSync("scientist-a.jpg");
|
|
43
|
+
* const refB = fs.readFileSync("scientist-b.jpg");
|
|
44
|
+
* const { outputs } = diffusion({
|
|
45
|
+
* modelId,
|
|
46
|
+
* prompt: "a portrait using most visual traits from @image1 and the eyes from @image2",
|
|
47
|
+
* init_images: [refA, refB],
|
|
48
|
+
* width: 768,
|
|
49
|
+
* height: 768,
|
|
50
|
+
* });
|
|
51
|
+
*
|
|
52
|
+
* // LoRA adapter for this generation (absolute path required).
|
|
53
|
+
* // Persistence across subsequent diffusion() calls is controlled at
|
|
54
|
+
* // loadModel time via `modelConfig.lora_apply_mode`.
|
|
55
|
+
* const { outputs } = diffusion({
|
|
56
|
+
* modelId,
|
|
57
|
+
* prompt: "a watercolor cat",
|
|
58
|
+
* lora: "/home/user/loras/watercolor.safetensors",
|
|
59
|
+
* });
|
|
60
|
+
*
|
|
61
|
+
* // ESRGAN upscale; requires the model to be loaded with `modelConfig.upscaler.model_src` set.
|
|
62
|
+
* const { outputs: singleOutputs } = diffusion({
|
|
63
|
+
* modelId,
|
|
64
|
+
* prompt: "a fox portrait",
|
|
65
|
+
* width: 128,
|
|
66
|
+
* height: 128,
|
|
67
|
+
* upscale: true, // one native-scale pass
|
|
68
|
+
* });
|
|
69
|
+
* const single = await singleOutputs;
|
|
70
|
+
* fs.writeFileSync("upscaled.png", single[0]);
|
|
71
|
+
*
|
|
72
|
+
* // Repeat upscale passes when needed.
|
|
73
|
+
* const { outputs: hiresOutputs } = diffusion({
|
|
74
|
+
* modelId,
|
|
75
|
+
* prompt: "a fox portrait",
|
|
76
|
+
* width: 128,
|
|
77
|
+
* height: 128,
|
|
78
|
+
* upscale: { repeats: 2 },
|
|
79
|
+
* });
|
|
80
|
+
* const hires = await hiresOutputs;
|
|
81
|
+
* fs.writeFileSync("hires.png", hires[0]);
|
|
82
|
+
*
|
|
37
83
|
* // With progress tracking
|
|
38
84
|
* const { progressStream, outputs } = diffusion({ modelId, prompt: "a cat" });
|
|
39
85
|
* for await (const { step, totalSteps } of progressStream) {
|
|
@@ -26,6 +26,52 @@ import { decodeBase64, encodeBase64 } from "../../utils/encoding.js";
|
|
|
26
26
|
* // modelConfig: { prediction: "flux2_flow" } })`).
|
|
27
27
|
* const { outputs } = diffusion({ modelId, prompt: "turn into watercolor", init_image: initImage });
|
|
28
28
|
*
|
|
29
|
+
* // FLUX.2 multi-reference fusion
|
|
30
|
+
* // IMPORTANT: requires the model loaded with `modelConfig: { prediction: "flux2_flow" }`
|
|
31
|
+
* // and a Qwen3 text encoder via `llmModelSrc` (same loadModel requirements as the
|
|
32
|
+
* // FLUX.2 img2img example above). `init_image` and `init_images` are mutually
|
|
33
|
+
* // exclusive — pass one or the other, not both.
|
|
34
|
+
* const refA = fs.readFileSync("scientist-a.jpg");
|
|
35
|
+
* const refB = fs.readFileSync("scientist-b.jpg");
|
|
36
|
+
* const { outputs } = diffusion({
|
|
37
|
+
* modelId,
|
|
38
|
+
* prompt: "a portrait using most visual traits from @image1 and the eyes from @image2",
|
|
39
|
+
* init_images: [refA, refB],
|
|
40
|
+
* width: 768,
|
|
41
|
+
* height: 768,
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* // LoRA adapter for this generation (absolute path required).
|
|
45
|
+
* // Persistence across subsequent diffusion() calls is controlled at
|
|
46
|
+
* // loadModel time via `modelConfig.lora_apply_mode`.
|
|
47
|
+
* const { outputs } = diffusion({
|
|
48
|
+
* modelId,
|
|
49
|
+
* prompt: "a watercolor cat",
|
|
50
|
+
* lora: "/home/user/loras/watercolor.safetensors",
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* // ESRGAN upscale; requires the model to be loaded with `modelConfig.upscaler.model_src` set.
|
|
54
|
+
* const { outputs: singleOutputs } = diffusion({
|
|
55
|
+
* modelId,
|
|
56
|
+
* prompt: "a fox portrait",
|
|
57
|
+
* width: 128,
|
|
58
|
+
* height: 128,
|
|
59
|
+
* upscale: true, // one native-scale pass
|
|
60
|
+
* });
|
|
61
|
+
* const single = await singleOutputs;
|
|
62
|
+
* fs.writeFileSync("upscaled.png", single[0]);
|
|
63
|
+
*
|
|
64
|
+
* // Repeat upscale passes when needed.
|
|
65
|
+
* const { outputs: hiresOutputs } = diffusion({
|
|
66
|
+
* modelId,
|
|
67
|
+
* prompt: "a fox portrait",
|
|
68
|
+
* width: 128,
|
|
69
|
+
* height: 128,
|
|
70
|
+
* upscale: { repeats: 2 },
|
|
71
|
+
* });
|
|
72
|
+
* const hires = await hiresOutputs;
|
|
73
|
+
* fs.writeFileSync("hires.png", hires[0]);
|
|
74
|
+
*
|
|
29
75
|
* // With progress tracking
|
|
30
76
|
* const { progressStream, outputs } = diffusion({ modelId, prompt: "a cat" });
|
|
31
77
|
* for await (const { step, totalSteps } of progressStream) {
|
|
@@ -35,10 +81,13 @@ import { decodeBase64, encodeBase64 } from "../../utils/encoding.js";
|
|
|
35
81
|
* ```
|
|
36
82
|
*/
|
|
37
83
|
export function diffusion(params) {
|
|
38
|
-
const { init_image, ...rest } = params;
|
|
84
|
+
const { init_image, init_images, ...rest } = params;
|
|
39
85
|
const request = {
|
|
40
86
|
...rest,
|
|
41
87
|
...(init_image !== undefined && { init_image: encodeBase64(init_image) }),
|
|
88
|
+
...(init_images !== undefined && {
|
|
89
|
+
init_images: init_images.map(encodeBase64),
|
|
90
|
+
}),
|
|
42
91
|
type: "diffusionStream",
|
|
43
92
|
};
|
|
44
93
|
let statsResolver = () => { };
|
|
@@ -13,7 +13,9 @@ export type DownloadAssetOptions = BaseDownloadAssetOptions;
|
|
|
13
13
|
* - onProgress: Optional callback for download progress
|
|
14
14
|
* @param rpcOptions - Optional RPC options including per-call profiling configuration
|
|
15
15
|
*
|
|
16
|
-
* @returns Promise that resolves to the asset ID (either the provided assetSrc or a generated ID)
|
|
16
|
+
* @returns Promise that resolves to the asset ID (either the provided assetSrc or a generated ID),
|
|
17
|
+
* decorated with a synchronous `requestId` field for use with
|
|
18
|
+
* `cancel({ requestId: op.requestId })` before the promise resolves.
|
|
17
19
|
*
|
|
18
20
|
* @throws {QvacErrorBase} When asset download fails, with details in the error message
|
|
19
21
|
* @throws {QvacErrorBase} When streaming ends unexpectedly (only when using onProgress)
|
|
@@ -34,7 +36,15 @@ export type DownloadAssetOptions = BaseDownloadAssetOptions;
|
|
|
34
36
|
* console.log(`Downloaded: ${progress.percentage}%`);
|
|
35
37
|
* }
|
|
36
38
|
* });
|
|
39
|
+
*
|
|
40
|
+
* // Targeted cancel by requestId — grab the id synchronously, then
|
|
41
|
+
* // cancel before the download resolves.
|
|
42
|
+
* const op = downloadAsset({ assetSrc: "https://example.com/large.gguf" });
|
|
43
|
+
* setTimeout(() => cancel({ requestId: op.requestId }), 1000);
|
|
44
|
+
* await op; // rejects with `InferenceCancelledError`
|
|
37
45
|
* ```
|
|
38
46
|
*/
|
|
39
|
-
export declare function downloadAsset(options: DownloadAssetOptions, rpcOptions?: RPCOptions): Promise<string
|
|
47
|
+
export declare function downloadAsset(options: DownloadAssetOptions, rpcOptions?: RPCOptions): Promise<string> & {
|
|
48
|
+
requestId: string;
|
|
49
|
+
};
|
|
40
50
|
//# sourceMappingURL=download-asset.d.ts.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { send, stream } from "../rpc/rpc-client.js";
|
|
2
2
|
import { downloadAssetOptionsToRequestSchema, } from "../../schemas/index.js";
|
|
3
3
|
import { DownloadAssetFailedError, StreamEndedError, InvalidResponseError, } from "../../utils/errors-client.js";
|
|
4
|
+
import { decoratePromise } from "../../utils/decorate-promise.js";
|
|
5
|
+
import { generateClientRequestId } from "./client-request-id.js";
|
|
4
6
|
/**
|
|
5
7
|
* Downloads an asset (model file) without loading it into memory.
|
|
6
8
|
*
|
|
@@ -14,7 +16,9 @@ import { DownloadAssetFailedError, StreamEndedError, InvalidResponseError, } fro
|
|
|
14
16
|
* - onProgress: Optional callback for download progress
|
|
15
17
|
* @param rpcOptions - Optional RPC options including per-call profiling configuration
|
|
16
18
|
*
|
|
17
|
-
* @returns Promise that resolves to the asset ID (either the provided assetSrc or a generated ID)
|
|
19
|
+
* @returns Promise that resolves to the asset ID (either the provided assetSrc or a generated ID),
|
|
20
|
+
* decorated with a synchronous `requestId` field for use with
|
|
21
|
+
* `cancel({ requestId: op.requestId })` before the promise resolves.
|
|
18
22
|
*
|
|
19
23
|
* @throws {QvacErrorBase} When asset download fails, with details in the error message
|
|
20
24
|
* @throws {QvacErrorBase} When streaming ends unexpectedly (only when using onProgress)
|
|
@@ -35,10 +39,24 @@ import { DownloadAssetFailedError, StreamEndedError, InvalidResponseError, } fro
|
|
|
35
39
|
* console.log(`Downloaded: ${progress.percentage}%`);
|
|
36
40
|
* }
|
|
37
41
|
* });
|
|
42
|
+
*
|
|
43
|
+
* // Targeted cancel by requestId — grab the id synchronously, then
|
|
44
|
+
* // cancel before the download resolves.
|
|
45
|
+
* const op = downloadAsset({ assetSrc: "https://example.com/large.gguf" });
|
|
46
|
+
* setTimeout(() => cancel({ requestId: op.requestId }), 1000);
|
|
47
|
+
* await op; // rejects with `InferenceCancelledError`
|
|
38
48
|
* ```
|
|
39
49
|
*/
|
|
40
|
-
export
|
|
41
|
-
const
|
|
50
|
+
export function downloadAsset(options, rpcOptions) {
|
|
51
|
+
const requestId = generateClientRequestId();
|
|
52
|
+
const inner = runDownloadAsset(options, requestId, rpcOptions);
|
|
53
|
+
return decoratePromise(inner, { requestId });
|
|
54
|
+
}
|
|
55
|
+
async function runDownloadAsset(options, requestId, rpcOptions) {
|
|
56
|
+
const request = downloadAssetOptionsToRequestSchema.parse({
|
|
57
|
+
...options,
|
|
58
|
+
requestId,
|
|
59
|
+
});
|
|
42
60
|
if (options.onProgress) {
|
|
43
61
|
// Use streaming for progress updates
|
|
44
62
|
for await (const response of stream(request, rpcOptions)) {
|
|
@@ -7,7 +7,7 @@ import { type EmbedStats, type RPCOptions } from "../../schemas/index";
|
|
|
7
7
|
* @param params.modelId - The identifier of the embedding model to use
|
|
8
8
|
* @param params.text - The input text to embed
|
|
9
9
|
* @param options - Optional RPC options including per-call profiling
|
|
10
|
-
* @returns A promise resolving to an object with `embedding` (a single `number[]` vector) and optional `stats` performance data.
|
|
10
|
+
* @returns A promise (decorated with `requestId`) resolving to an object with `embedding` (a single `number[]` vector) and optional `stats` performance data.
|
|
11
11
|
* @throws {QvacErrorBase} When the response type is invalid or when the embedding fails
|
|
12
12
|
*/
|
|
13
13
|
export declare function embed(params: {
|
|
@@ -16,7 +16,9 @@ export declare function embed(params: {
|
|
|
16
16
|
}, options?: RPCOptions): Promise<{
|
|
17
17
|
embedding: number[];
|
|
18
18
|
stats?: EmbedStats;
|
|
19
|
-
}
|
|
19
|
+
}> & {
|
|
20
|
+
requestId: string;
|
|
21
|
+
};
|
|
20
22
|
/**
|
|
21
23
|
* Generates embeddings for multiple texts using a specified model.
|
|
22
24
|
*
|
|
@@ -25,7 +27,7 @@ export declare function embed(params: {
|
|
|
25
27
|
* @param params.modelId - The identifier of the embedding model to use
|
|
26
28
|
* @param params.text - The input texts to embed
|
|
27
29
|
* @param options - Optional RPC options including per-call profiling
|
|
28
|
-
* @returns A promise resolving to an object with `embedding` (one `number[]` vector per input text, i.e. `number[][]`) and optional `stats` performance data.
|
|
30
|
+
* @returns A promise (decorated with `requestId`) resolving to an object with `embedding` (one `number[]` vector per input text, i.e. `number[][]`) and optional `stats` performance data.
|
|
29
31
|
* @throws {QvacErrorBase} When the response type is invalid or when the embedding fails
|
|
30
32
|
*/
|
|
31
33
|
export declare function embed(params: {
|
|
@@ -34,5 +36,7 @@ export declare function embed(params: {
|
|
|
34
36
|
}, options?: RPCOptions): Promise<{
|
|
35
37
|
embedding: number[][];
|
|
36
38
|
stats?: EmbedStats;
|
|
37
|
-
}
|
|
39
|
+
}> & {
|
|
40
|
+
requestId: string;
|
|
41
|
+
};
|
|
38
42
|
//# sourceMappingURL=embed.d.ts.map
|