@qvac/sdk 0.9.2 → 0.10.1
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 +42 -95
- package/dist/client/api/cancel.d.ts +1 -1
- package/dist/client/api/cancel.js +1 -1
- package/dist/client/api/completion-stream.d.ts +51 -12
- package/dist/client/api/completion-stream.js +129 -56
- package/dist/client/api/delete-cache.d.ts +1 -0
- package/dist/client/api/delete-cache.js +1 -0
- package/dist/client/api/diffusion.d.ts +17 -2
- package/dist/client/api/diffusion.js +21 -4
- package/dist/client/api/embed.d.ts +4 -0
- package/dist/client/api/finetune.d.ts +21 -0
- package/dist/client/api/get-loaded-model-info.d.ts +25 -0
- package/dist/client/api/get-loaded-model-info.js +36 -0
- package/dist/client/api/get-model-info.d.ts +9 -1
- package/dist/client/api/get-model-info.js +8 -0
- package/dist/client/api/heartbeat.d.ts +2 -2
- package/dist/client/api/heartbeat.js +2 -2
- package/dist/client/api/index.d.ts +3 -1
- package/dist/client/api/index.js +3 -1
- package/dist/client/api/invoke-plugin.d.ts +16 -0
- package/dist/client/api/invoke-plugin.js +16 -0
- package/dist/client/api/load-model.d.ts +36 -3
- package/dist/client/api/load-model.js +31 -10
- package/dist/client/api/provide.d.ts +11 -5
- package/dist/client/api/provide.js +11 -6
- package/dist/client/api/rag.d.ts +9 -0
- package/dist/client/api/rag.js +9 -0
- package/dist/client/api/registry.d.ts +26 -0
- package/dist/client/api/registry.js +26 -0
- package/dist/client/api/resume.d.ts +20 -4
- package/dist/client/api/resume.js +20 -4
- package/dist/client/api/state.d.ts +23 -0
- package/dist/client/api/state.js +29 -0
- package/dist/client/api/stop-provider.d.ts +11 -5
- package/dist/client/api/stop-provider.js +11 -5
- package/dist/client/api/suspend.d.ts +21 -3
- package/dist/client/api/suspend.js +21 -3
- package/dist/client/api/text-to-speech.d.ts +64 -6
- package/dist/client/api/text-to-speech.js +423 -47
- package/dist/client/api/transcribe.d.ts +29 -4
- package/dist/client/api/transcribe.js +86 -28
- package/dist/client/api/translate.d.ts +1 -0
- package/dist/client/api/translate.js +1 -0
- package/dist/client/rpc/bare-client.js +22 -1
- package/dist/client/rpc/expo-rpc-client.d.ts +1 -1
- package/dist/client/rpc/expo-rpc-client.js +96 -4
- package/dist/client/rpc/node-rpc-client.js +36 -0
- package/dist/examples/audio/mic-input.d.ts +9 -0
- package/dist/examples/audio/mic-input.js +111 -0
- package/dist/examples/completion-events.d.ts +18 -0
- package/dist/examples/completion-events.js +79 -0
- package/dist/examples/delegated-inference/composite.js +12 -18
- package/dist/examples/delegated-inference/consumer-profiled.js +4 -11
- package/dist/examples/delegated-inference/consumer.js +8 -13
- package/dist/examples/delegated-inference/provider.js +11 -16
- package/dist/examples/diffusion-flux2-klein-img2img.d.ts +2 -0
- package/dist/examples/diffusion-flux2-klein-img2img.js +60 -0
- package/dist/examples/diffusion-flux2-klein.js +1 -0
- package/dist/examples/diffusion-img2img.d.ts +2 -0
- package/dist/examples/diffusion-img2img.js +49 -0
- package/dist/examples/diffusion-txt2img.js +2 -1
- package/dist/examples/kv-cache-example.js +11 -12
- package/dist/examples/llamacpp-cache.d.ts +2 -0
- package/dist/examples/llamacpp-cache.js +107 -0
- package/dist/examples/llamacpp-dynamic-tools.d.ts +2 -0
- package/dist/examples/llamacpp-dynamic-tools.js +144 -0
- package/dist/examples/llamacpp-structured-output.d.ts +2 -0
- package/dist/examples/llamacpp-structured-output.js +106 -0
- package/dist/examples/plugins.js +4 -4
- package/dist/examples/suspend-resume.js +21 -4
- package/dist/examples/{llamacpp-native-tools.js → tools/llamacpp-native-tools.js} +6 -55
- package/dist/examples/tools/llamacpp-tools-harmony-multiturn.d.ts +2 -0
- package/dist/examples/tools/llamacpp-tools-harmony-multiturn.js +81 -0
- package/dist/examples/tools/llamacpp-tools-pythonic.d.ts +2 -0
- package/dist/examples/tools/llamacpp-tools-pythonic.js +50 -0
- package/dist/examples/tools/shared.d.ts +21 -0
- package/dist/examples/tools/shared.js +42 -0
- package/dist/examples/transcription/parakeet-microphone-record.js +6 -33
- package/dist/examples/transcription/whispercpp-filesystem-streaming.js +7 -5
- package/dist/examples/transcription/whispercpp-filesystem.js +12 -3
- package/dist/examples/transcription/whispercpp-microphone-record.js +6 -29
- package/dist/examples/translation/translation-stream.js +5 -5
- package/dist/examples/tts/llm-to-tts-streaming.d.ts +16 -0
- package/dist/examples/tts/llm-to-tts-streaming.js +143 -0
- package/dist/examples/tts/supertonic-multilingual.js +3 -3
- package/dist/examples/tts/supertonic.js +3 -3
- package/dist/examples/tts/utils.d.ts +11 -1
- package/dist/examples/tts/utils.js +70 -17
- package/dist/examples/voice-assistant/voice-assistant.d.ts +2 -0
- package/dist/examples/voice-assistant/voice-assistant.js +207 -0
- package/dist/expo/plugins/withMobileBundle.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/logging/logger.d.ts +11 -0
- package/dist/logging/logger.js +11 -0
- package/dist/logging/types.d.ts +18 -0
- package/dist/models/registry/models.d.ts +6973 -7457
- package/dist/models/registry/models.js +6889 -6855
- package/dist/models/update-models/codegen.js +84 -23
- package/dist/models/update-models/companions.d.ts +18 -0
- package/dist/models/update-models/companions.js +175 -0
- package/dist/models/update-models/naming.js +0 -25
- package/dist/models/update-models/registry.d.ts +1 -0
- package/dist/models/update-models/registry.js +23 -3
- package/dist/models/update-models/types.d.ts +37 -9
- package/dist/profiling/index.d.ts +49 -0
- package/dist/profiling/index.js +49 -0
- package/dist/schemas/cancel.d.ts +6 -2
- package/dist/schemas/cancel.js +14 -7
- package/dist/schemas/common.d.ts +354 -271
- package/dist/schemas/common.js +26 -5
- package/dist/schemas/completion-event.d.ts +225 -0
- package/dist/schemas/completion-event.js +79 -0
- package/dist/schemas/completion-stream.d.ts +126 -31
- package/dist/schemas/completion-stream.js +138 -36
- package/dist/schemas/delegate.d.ts +0 -2
- package/dist/schemas/delegate.js +25 -6
- package/dist/schemas/download-asset.d.ts +5 -5
- package/dist/schemas/embed.js +21 -9
- package/dist/schemas/engine-addon-map.d.ts +11 -1
- package/dist/schemas/engine-addon-map.js +2 -2
- package/dist/schemas/get-loaded-model-info.d.ts +52 -0
- package/dist/schemas/get-loaded-model-info.js +44 -0
- package/dist/schemas/get-model-info.d.ts +2 -2
- package/dist/schemas/get-model-info.js +103 -32
- package/dist/schemas/heartbeat.d.ts +0 -1
- package/dist/schemas/index.d.ts +4 -1
- package/dist/schemas/index.js +4 -1
- package/dist/schemas/llamacpp-config.d.ts +14 -4
- package/dist/schemas/llamacpp-config.js +5 -0
- package/dist/schemas/load-model.d.ts +3233 -1260
- package/dist/schemas/load-model.js +23 -16
- package/dist/schemas/model-src-utils.d.ts +7 -6
- package/dist/schemas/model-src-utils.js +27 -1
- package/dist/schemas/model-types.d.ts +4 -4
- package/dist/schemas/ocr.d.ts +1 -1
- package/dist/schemas/plugin.d.ts +27 -3
- package/dist/schemas/plugin.js +27 -2
- package/dist/schemas/profiling.js +11 -3
- package/dist/schemas/provide.d.ts +1 -3
- package/dist/schemas/provide.js +0 -3
- package/dist/schemas/rag.d.ts +4 -4
- package/dist/schemas/registry.d.ts +10 -10
- package/dist/schemas/registry.js +36 -14
- package/dist/schemas/reload-config.d.ts +73 -7
- package/dist/schemas/sdcpp-config.d.ts +16 -8
- package/dist/schemas/sdcpp-config.js +118 -25
- package/dist/schemas/sdk-config.d.ts +116 -90
- package/dist/schemas/sdk-config.js +16 -0
- package/dist/schemas/sdk-errors-client.d.ts +3 -0
- package/dist/schemas/sdk-errors-client.js +16 -1
- package/dist/schemas/sdk-errors-server.d.ts +3 -0
- package/dist/schemas/sdk-errors-server.js +23 -0
- package/dist/schemas/state.d.ts +23 -0
- package/dist/schemas/state.js +14 -0
- package/dist/schemas/stop-provide.d.ts +0 -5
- package/dist/schemas/stop-provide.js +2 -6
- package/dist/schemas/text-to-speech.d.ts +93 -27
- package/dist/schemas/text-to-speech.js +27 -0
- package/dist/schemas/tools.d.ts +16 -0
- package/dist/schemas/tools.js +15 -0
- package/dist/schemas/transcription-config.d.ts +8 -8
- package/dist/schemas/transcription.d.ts +33 -0
- package/dist/schemas/transcription.js +9 -0
- package/dist/schemas/translate.js +59 -19
- package/dist/schemas/translation-config.d.ts +157 -133
- package/dist/schemas/translation-config.js +34 -11
- package/dist/server/bare/delegate-rpc-client.d.ts +1 -1
- package/dist/server/bare/delegate-rpc-client.js +131 -122
- package/dist/server/bare/hyperswarm.d.ts +2 -2
- package/dist/server/bare/hyperswarm.js +12 -7
- package/dist/server/bare/ops/cancel.js +7 -0
- package/dist/server/bare/ops/kv-cache-utils.d.ts +7 -10
- package/dist/server/bare/ops/kv-cache-utils.js +31 -40
- package/dist/server/bare/ops/load-model.js +0 -1
- package/dist/server/bare/ops/transcribe.d.ts +11 -4
- package/dist/server/bare/ops/transcribe.js +25 -4
- package/dist/server/bare/ops/translate.js +42 -4
- package/dist/server/bare/ops/unload-model.js +21 -19
- package/dist/server/bare/plugins/llamacpp-completion/ops/cache-logger.js +1 -2
- package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.d.ts +13 -8
- package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.js +257 -85
- package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-state.d.ts +101 -0
- package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-state.js +135 -0
- package/dist/server/bare/plugins/llamacpp-completion/plugin.d.ts +80 -22
- package/dist/server/bare/plugins/llamacpp-completion/plugin.js +57 -32
- package/dist/server/bare/plugins/llamacpp-embedding/plugin.js +10 -16
- package/dist/server/bare/plugins/nmtcpp-translation/plugin.d.ts +69 -44
- package/dist/server/bare/plugins/nmtcpp-translation/plugin.js +54 -116
- package/dist/server/bare/plugins/nmtcpp-translation/resolve-vocab.d.ts +32 -0
- package/dist/server/bare/plugins/nmtcpp-translation/resolve-vocab.js +117 -0
- package/dist/server/bare/plugins/onnx-ocr/plugin.d.ts +1 -1
- package/dist/server/bare/plugins/onnx-ocr/plugin.js +1 -2
- package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech-stream.d.ts +7 -0
- package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech-stream.js +116 -0
- package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech.d.ts +2 -3
- package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech.js +71 -9
- package/dist/server/bare/plugins/onnx-tts/plugin.d.ts +41 -13
- package/dist/server/bare/plugins/onnx-tts/plugin.js +48 -3
- package/dist/server/bare/plugins/parakeet-transcription/plugin.d.ts +15 -7
- package/dist/server/bare/plugins/parakeet-transcription/plugin.js +5 -6
- package/dist/server/bare/plugins/sdcpp-generation/ops/diffusion.js +6 -0
- package/dist/server/bare/plugins/sdcpp-generation/plugin.d.ts +8 -5
- package/dist/server/bare/plugins/sdcpp-generation/plugin.js +13 -13
- package/dist/server/bare/plugins/whispercpp-transcription/plugin.d.ts +17 -1
- package/dist/server/bare/plugins/whispercpp-transcription/plugin.js +40 -17
- package/dist/server/bare/registry/config-registry.js +14 -3
- package/dist/server/bare/registry/model-registry.d.ts +8 -10
- package/dist/server/bare/registry/model-registry.js +17 -12
- package/dist/server/bare/registry/registry-client.js +79 -19
- package/dist/server/bare/runtime-lifecycle.d.ts +2 -1
- package/dist/server/bare/runtime-lifecycle.js +13 -2
- package/dist/server/bare/types/addon-responses.d.ts +8 -3
- package/dist/server/bare/utils/transcribe-metadata.d.ts +21 -0
- package/dist/server/bare/utils/transcribe-metadata.js +28 -0
- package/dist/server/bare/utils/tts-stats.d.ts +22 -0
- package/dist/server/bare/utils/tts-stats.js +10 -0
- package/dist/server/rpc/create-server.d.ts +4 -1
- package/dist/server/rpc/create-server.js +5 -1
- package/dist/server/rpc/delegate-transport.js +36 -29
- package/dist/server/rpc/handle-request.js +28 -3
- package/dist/server/rpc/handler-registry.js +7 -1
- package/dist/server/rpc/handler-utils.d.ts +5 -0
- package/dist/server/rpc/handler-utils.js +22 -0
- package/dist/server/rpc/handlers/cancel-delegated.js +3 -5
- package/dist/server/rpc/handlers/cancelHandler.js +4 -5
- package/dist/server/rpc/handlers/completion-stream-delegated.js +14 -5
- package/dist/server/rpc/handlers/delete-cache.js +8 -3
- package/dist/server/rpc/handlers/download-asset.js +3 -24
- package/dist/server/rpc/handlers/get-loaded-model-info.d.ts +3 -0
- package/dist/server/rpc/handlers/get-loaded-model-info.js +39 -0
- package/dist/server/rpc/handlers/get-model-info.js +93 -84
- package/dist/server/rpc/handlers/heartbeat-delegated.js +2 -2
- package/dist/server/rpc/handlers/index.d.ts +6 -0
- package/dist/server/rpc/handlers/index.js +6 -0
- package/dist/server/rpc/handlers/load-model/download-manager.d.ts +35 -9
- package/dist/server/rpc/handlers/load-model/download-manager.js +142 -38
- package/dist/server/rpc/handlers/load-model/download-stats.d.ts +5 -4
- package/dist/server/rpc/handlers/load-model/download-stats.js +49 -8
- package/dist/server/rpc/handlers/load-model/handler.js +31 -50
- package/dist/server/rpc/handlers/load-model/http.d.ts +2 -2
- package/dist/server/rpc/handlers/load-model/http.js +97 -142
- package/dist/server/rpc/handlers/load-model/hyperdrive.d.ts +2 -2
- package/dist/server/rpc/handlers/load-model/hyperdrive.js +55 -74
- package/dist/server/rpc/handlers/load-model/index.d.ts +0 -1
- package/dist/server/rpc/handlers/load-model/index.js +0 -1
- package/dist/server/rpc/handlers/load-model/registry-client-options.d.ts +27 -0
- package/dist/server/rpc/handlers/load-model/registry-client-options.js +19 -0
- package/dist/server/rpc/handlers/load-model/registry-companion-set.d.ts +22 -0
- package/dist/server/rpc/handlers/load-model/registry-companion-set.js +208 -0
- package/dist/server/rpc/handlers/load-model/registry-download-utils.d.ts +24 -0
- package/dist/server/rpc/handlers/load-model/registry-download-utils.js +114 -0
- package/dist/server/rpc/handlers/load-model/registry.d.ts +2 -20
- package/dist/server/rpc/handlers/load-model/registry.js +109 -381
- package/dist/server/rpc/handlers/load-model/resolve-session.d.ts +15 -0
- package/dist/server/rpc/handlers/load-model/resolve-session.js +61 -0
- package/dist/server/rpc/handlers/load-model/resolve.d.ts +3 -3
- package/dist/server/rpc/handlers/load-model/resolve.js +14 -23
- package/dist/server/rpc/handlers/load-model/types.d.ts +11 -4
- package/dist/server/rpc/handlers/load-model/types.js +28 -1
- package/dist/server/rpc/handlers/load-model-delegated.js +2 -4
- package/dist/server/rpc/handlers/plugin-dispatch.js +9 -5
- package/dist/server/rpc/handlers/plugin-invoke.js +1 -1
- package/dist/server/rpc/handlers/provideHandler/connection.js +13 -2
- package/dist/server/rpc/handlers/provideHandler/handler.js +42 -29
- package/dist/server/rpc/handlers/state.d.ts +3 -0
- package/dist/server/rpc/handlers/state.js +7 -0
- package/dist/server/rpc/handlers/stopProvideHandler.d.ts +2 -2
- package/dist/server/rpc/handlers/stopProvideHandler.js +12 -7
- package/dist/server/rpc/handlers/text-to-speech-stream.d.ts +3 -0
- package/dist/server/rpc/handlers/text-to-speech-stream.js +4 -0
- package/dist/server/rpc/handlers/unload-model-delegated.js +3 -3
- package/dist/server/rpc/profiling/operation-metrics.js +20 -0
- package/dist/server/rpc/rpc-utils.js +1 -1
- package/dist/server/rpc/transport-selector.d.ts +3 -0
- package/dist/server/rpc/transport-selector.js +18 -0
- package/dist/server/utils/cache/auto-history.d.ts +4 -0
- package/dist/server/utils/cache/auto-history.js +22 -0
- package/dist/server/utils/{cache.d.ts → cache/paths.d.ts} +22 -5
- package/dist/server/utils/{cache.js → cache/paths.js} +36 -20
- package/dist/server/utils/cache/types.d.ts +8 -0
- package/dist/server/utils/cache/types.js +1 -0
- package/dist/server/utils/checksum.d.ts +2 -2
- package/dist/server/utils/checksum.js +1 -1
- package/dist/server/utils/clear-storage.d.ts +5 -0
- package/dist/server/utils/clear-storage.js +17 -0
- package/dist/server/utils/completion-normalizer.d.ts +17 -0
- package/dist/server/utils/completion-normalizer.js +413 -0
- package/dist/server/utils/expand-gguf-shards.d.ts +3 -0
- package/dist/server/utils/expand-gguf-shards.js +22 -0
- package/dist/server/utils/formatting.js +1 -1
- package/dist/server/utils/index.d.ts +4 -2
- package/dist/server/utils/index.js +4 -2
- package/dist/server/utils/qvac-paths.d.ts +2 -0
- package/dist/server/utils/qvac-paths.js +5 -0
- package/dist/server/utils/response-format.d.ts +3 -0
- package/dist/server/utils/response-format.js +20 -0
- package/dist/server/utils/tool-integration.d.ts +15 -4
- package/dist/server/utils/tool-integration.js +21 -41
- package/dist/server/utils/tools/dialect.d.ts +8 -0
- package/dist/server/utils/tools/dialect.js +14 -0
- package/dist/server/utils/tools/index.d.ts +3 -0
- package/dist/server/utils/tools/index.js +2 -0
- package/dist/server/utils/tools/parser.d.ts +6 -0
- package/dist/server/utils/tools/parser.js +46 -0
- package/dist/server/utils/tools/parsers/harmony.d.ts +4 -0
- package/dist/server/utils/tools/parsers/harmony.js +59 -0
- package/dist/server/utils/tools/parsers/hermes.d.ts +4 -0
- package/dist/server/utils/tools/parsers/hermes.js +100 -0
- package/dist/server/utils/tools/parsers/json.d.ts +6 -0
- package/dist/server/utils/tools/parsers/json.js +115 -0
- package/dist/server/utils/tools/parsers/pythonic.d.ts +4 -0
- package/dist/server/utils/tools/parsers/pythonic.js +267 -0
- package/dist/server/utils/tools/shared.d.ts +18 -0
- package/dist/server/utils/tools/shared.js +54 -0
- package/dist/server/utils/worker-lock.d.ts +3 -0
- package/dist/server/utils/worker-lock.js +67 -0
- package/dist/server/worker-core.d.ts +16 -1
- package/dist/server/worker-core.js +114 -14
- package/dist/utils/aggregate-events.d.ts +16 -0
- package/dist/utils/aggregate-events.js +52 -0
- package/dist/utils/cache-normalize.d.ts +10 -0
- package/dist/utils/cache-normalize.js +23 -0
- package/dist/utils/encoding.d.ts +8 -0
- package/dist/utils/encoding.js +13 -0
- package/dist/utils/errors-client.d.ts +12 -0
- package/dist/utils/errors-client.js +20 -0
- package/dist/utils/errors-server.d.ts +14 -0
- package/dist/utils/errors-server.js +31 -0
- package/dist/utils/load-model-validation.d.ts +7 -0
- package/dist/utils/load-model-validation.js +18 -0
- package/expo/plugins/patches/android-link.mjs +1 -1
- package/expo/plugins/patches/ios-link.mjs +1 -1
- package/package.json +14 -18
- package/dist/examples/translation/translation-opus.d.ts +0 -2
- package/dist/examples/translation/translation-opus.js +0 -33
- package/dist/server/bare/utils/loader-adapter.d.ts +0 -7
- package/dist/server/bare/utils/loader-adapter.js +0 -9
- package/dist/server/utils/model-path.d.ts +0 -5
- package/dist/server/utils/model-path.js +0 -7
- package/dist/server/utils/tool-parser.d.ts +0 -7
- package/dist/server/utils/tool-parser.js +0 -248
- /package/dist/examples/{llamacpp-native-tools.d.ts → tools/llamacpp-native-tools.d.ts} +0 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure state + decision helpers for kv-cache bookkeeping used by
|
|
3
|
+
* `completion-stream.ts`.
|
|
4
|
+
*
|
|
5
|
+
* This module intentionally has **no** `bare-*` imports so it can be
|
|
6
|
+
* exercised directly from unit tests running under `bun` without pulling
|
|
7
|
+
* in the Bare runtime (which is not available in that environment).
|
|
8
|
+
* The file-system-dependent pieces (e.g. `recordCacheSaveCount`) live in
|
|
9
|
+
* `completion-stream.ts` and consume the state exported here.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Number of chat messages the kv-cache file on disk is known to cover, keyed
|
|
13
|
+
* by cache path. Written after a successful completion records a save, read
|
|
14
|
+
* by `prepareMessagesForCache` to slice the history on the next turn so a
|
|
15
|
+
* consumer can stage multiple messages between completions (e.g. an
|
|
16
|
+
* `[assistant, user]` recovery sequence) without resending the whole history.
|
|
17
|
+
*
|
|
18
|
+
* INVARIANT: an entry is only present if the corresponding kv-cache file is
|
|
19
|
+
* considered trustworthy. On any turn where the SDK cannot prove the saved
|
|
20
|
+
* count reflects the on-disk state (cancellation mid-decode, zero-token
|
|
21
|
+
* reply, cache file missing after a save attempt), the entry MUST be
|
|
22
|
+
* deleted; a stale entry causes the next turn to slice its history down to
|
|
23
|
+
* an empty payload and the model returns zero tokens.
|
|
24
|
+
*
|
|
25
|
+
* Mode notes:
|
|
26
|
+
* - Static-mode turns are the only readers of this map. `clearStaleCount`
|
|
27
|
+
* in `decideCachedHistorySlice` exists so a stale-but-non-zero entry
|
|
28
|
+
* can be detected and dropped on the next read.
|
|
29
|
+
* - Dynamic-mode turns do NOT consume this map — the addon trims tools
|
|
30
|
+
* and the chain output from the kv-cache after each round, so the
|
|
31
|
+
* SDK falls back to role-based dispatch in `prepareMessagesForCache`.
|
|
32
|
+
* Writes still happen on dynamic-mode turns, but the recorded count
|
|
33
|
+
* reflects the messages the SDK shipped, not the (possibly trimmed)
|
|
34
|
+
* on-disk cache shape. The map is internally consistent within a
|
|
35
|
+
* single mode; a `kvCache` key should not be reused across modes.
|
|
36
|
+
*/
|
|
37
|
+
export const cachedMessageCounts = new Map();
|
|
38
|
+
/**
|
|
39
|
+
* Monotonic counter of cancel requests per model. `completion()` snapshots
|
|
40
|
+
* the value before running the model and compares afterward to decide
|
|
41
|
+
* whether the turn was cancelled mid-decode. A counter (not a boolean) is
|
|
42
|
+
* used deliberately: a cancel that lands near a turn boundary cannot bleed
|
|
43
|
+
* into the next turn because we always compare snapshots, not values.
|
|
44
|
+
*/
|
|
45
|
+
const modelCancelCounters = new Map();
|
|
46
|
+
/**
|
|
47
|
+
* Clear bookkeeping entries. With no argument, clears the whole map. With a
|
|
48
|
+
* `prefix`, removes any entry whose path is equal to it OR sits beneath it
|
|
49
|
+
* as a directory (i.e. `key.startsWith(prefix + sep)`).
|
|
50
|
+
*
|
|
51
|
+
* Runtime callers MUST pass the platform path separator (e.g. `path.sep`
|
|
52
|
+
* from `bare-path`) so directory-prefix matches are correct on every
|
|
53
|
+
* target. The "/" default exists only for unit tests under `bun`, where
|
|
54
|
+
* cache paths are POSIX-shaped and importing `bare-path` would pull in
|
|
55
|
+
* the Bare runtime. The exported wrapper in `completion-stream.ts`
|
|
56
|
+
* injects the real separator for in-process use.
|
|
57
|
+
*/
|
|
58
|
+
export function clearCachedMessageCounts(prefix, sep = "/") {
|
|
59
|
+
if (!prefix) {
|
|
60
|
+
cachedMessageCounts.clear();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
for (const key of cachedMessageCounts.keys()) {
|
|
64
|
+
if (key === prefix) {
|
|
65
|
+
cachedMessageCounts.delete(key);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (!key.startsWith(prefix + sep))
|
|
69
|
+
continue;
|
|
70
|
+
cachedMessageCounts.delete(key);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Called from `server/bare/ops/cancel.ts` right before `addon.cancel()` so
|
|
75
|
+
* that the in-flight `completion()` for this model can detect that its
|
|
76
|
+
* current turn is being cancelled and skip poisoning `cachedMessageCounts`
|
|
77
|
+
* with a `history.length + 1` entry that does not correspond to a real
|
|
78
|
+
* assistant reply.
|
|
79
|
+
*/
|
|
80
|
+
export function noteCancelRequested(modelId) {
|
|
81
|
+
modelCancelCounters.set(modelId, (modelCancelCounters.get(modelId) ?? 0) + 1);
|
|
82
|
+
}
|
|
83
|
+
export function snapshotCancelCount(modelId) {
|
|
84
|
+
return modelCancelCounters.get(modelId) ?? 0;
|
|
85
|
+
}
|
|
86
|
+
/** Test-only. */
|
|
87
|
+
export function _resetCancelCountersForTest() {
|
|
88
|
+
modelCancelCounters.clear();
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* A completion's `savedCount` should only be recorded when the turn ran to
|
|
92
|
+
* completion AND produced at least one token. Any other outcome —
|
|
93
|
+
* cancelled mid-decode, legitimate zero-token reply, or an early EOS — must
|
|
94
|
+
* clear the entry instead, because there is no guarantee that the kv-cache
|
|
95
|
+
* file on disk matches the `history.length + 1` boundary the SDK would
|
|
96
|
+
* otherwise record.
|
|
97
|
+
*/
|
|
98
|
+
export function shouldRecordSavedCount(wasCancelled, producedTokens) {
|
|
99
|
+
return !wasCancelled && producedTokens;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Pure slice decision for `prepareMessagesForCache`.
|
|
103
|
+
*
|
|
104
|
+
* Mirrors the shape of the logic in `completion-stream.ts` but without
|
|
105
|
+
* calling `transformMessages` (which depends on `bare-fs` for attachment
|
|
106
|
+
* probing). Kept here so the decision can be unit-tested in isolation.
|
|
107
|
+
*
|
|
108
|
+
* The key regression guard: when a non-zero `savedCount` would slice the
|
|
109
|
+
* history down to an empty array, it is treated as stale — the caller
|
|
110
|
+
* falls back to sending the system-stripped full history rather than
|
|
111
|
+
* handing the model an empty payload.
|
|
112
|
+
*/
|
|
113
|
+
export function decideCachedHistorySlice(savedCount, cacheExists, history) {
|
|
114
|
+
if (!cacheExists || history.length === 0) {
|
|
115
|
+
return {
|
|
116
|
+
messages: history.filter((msg) => msg.role !== "system"),
|
|
117
|
+
clearStaleCount: false,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const canSlice = savedCount > 0 && savedCount <= history.length;
|
|
121
|
+
const sliced = canSlice ? history.slice(savedCount) : null;
|
|
122
|
+
// A non-null slice that is empty means the saved count is stale: the
|
|
123
|
+
// cached turn boundary is claiming the entire current history is
|
|
124
|
+
// already cached, which happens when a previous turn was cancelled
|
|
125
|
+
// mid-decode and still recorded `history.length + 1`. Treat it as a
|
|
126
|
+
// bad state and resend the full (system-stripped) history.
|
|
127
|
+
const useSlice = sliced !== null && sliced.length > 0;
|
|
128
|
+
const messages = useSlice
|
|
129
|
+
? sliced
|
|
130
|
+
: history.filter((msg) => msg.role !== "system");
|
|
131
|
+
return {
|
|
132
|
+
messages,
|
|
133
|
+
clearStaleCount: !useSlice && savedCount > 0,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
@@ -22,6 +22,10 @@ export declare const llmPlugin: {
|
|
|
22
22
|
stop_sequences: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
|
|
23
23
|
n_discarded: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
24
24
|
tools: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
25
|
+
toolsMode: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
26
|
+
static: "static";
|
|
27
|
+
dynamic: "dynamic";
|
|
28
|
+
}>>;
|
|
25
29
|
"cache-type-k": import("zod").ZodOptional<import("zod").ZodString>;
|
|
26
30
|
"cache-type-v": import("zod").ZodOptional<import("zod").ZodString>;
|
|
27
31
|
openclCacheDir: import("zod").ZodOptional<import("zod").ZodString>;
|
|
@@ -37,6 +41,7 @@ export declare const llmPlugin: {
|
|
|
37
41
|
expectedSize: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
38
42
|
sha256Checksum: import("zod").ZodOptional<import("zod").ZodString>;
|
|
39
43
|
addon: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodEnum<{
|
|
44
|
+
embeddings: "embeddings";
|
|
40
45
|
"llamacpp-completion": "llamacpp-completion";
|
|
41
46
|
"whispercpp-transcription": "whispercpp-transcription";
|
|
42
47
|
"llamacpp-embedding": "llamacpp-embedding";
|
|
@@ -47,7 +52,6 @@ export declare const llmPlugin: {
|
|
|
47
52
|
"sdcpp-generation": "sdcpp-generation";
|
|
48
53
|
llm: "llm";
|
|
49
54
|
whisper: "whisper";
|
|
50
|
-
embeddings: "embeddings";
|
|
51
55
|
nmt: "nmt";
|
|
52
56
|
parakeet: "parakeet";
|
|
53
57
|
tts: "tts";
|
|
@@ -76,6 +80,7 @@ export declare const llmPlugin: {
|
|
|
76
80
|
stop_sequences?: string[] | undefined;
|
|
77
81
|
n_discarded?: number | undefined;
|
|
78
82
|
tools?: boolean | undefined;
|
|
83
|
+
toolsMode?: "static" | "dynamic" | undefined;
|
|
79
84
|
"cache-type-k"?: string | undefined;
|
|
80
85
|
"cache-type-v"?: string | undefined;
|
|
81
86
|
openclCacheDir?: string | undefined;
|
|
@@ -101,6 +106,7 @@ export declare const llmPlugin: {
|
|
|
101
106
|
stop_sequences?: string[] | undefined;
|
|
102
107
|
n_discarded?: number | undefined;
|
|
103
108
|
tools?: boolean | undefined;
|
|
109
|
+
toolsMode?: "static" | "dynamic" | undefined;
|
|
104
110
|
"cache-type-k"?: string | undefined;
|
|
105
111
|
"cache-type-v"?: string | undefined;
|
|
106
112
|
openclCacheDir?: string | undefined;
|
|
@@ -153,22 +159,46 @@ export declare const llmPlugin: {
|
|
|
153
159
|
presence_penalty: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
154
160
|
repeat_penalty: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
155
161
|
}, import("zod/v4/core").$strict>>;
|
|
162
|
+
captureThinking: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
163
|
+
emitRawDeltas: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
164
|
+
toolDialect: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
165
|
+
hermes: "hermes";
|
|
166
|
+
pythonic: "pythonic";
|
|
167
|
+
json: "json";
|
|
168
|
+
harmony: "harmony";
|
|
169
|
+
}>>;
|
|
170
|
+
responseFormat: import("zod").ZodOptional<import("zod").ZodDiscriminatedUnion<[import("zod").ZodObject<{
|
|
171
|
+
type: import("zod").ZodLiteral<"text">;
|
|
172
|
+
}, import("zod/v4/core").$strict>, import("zod").ZodObject<{
|
|
173
|
+
type: import("zod").ZodLiteral<"json_object">;
|
|
174
|
+
}, import("zod/v4/core").$strict>, import("zod").ZodObject<{
|
|
175
|
+
type: import("zod").ZodLiteral<"json_schema">;
|
|
176
|
+
json_schema: import("zod").ZodObject<{
|
|
177
|
+
name: import("zod").ZodString;
|
|
178
|
+
description: import("zod").ZodOptional<import("zod").ZodString>;
|
|
179
|
+
schema: import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>;
|
|
180
|
+
strict: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
181
|
+
}, import("zod/v4/core").$strict>;
|
|
182
|
+
}, import("zod/v4/core").$strict>], "type">>;
|
|
156
183
|
type: import("zod").ZodLiteral<"completionStream">;
|
|
157
184
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
158
185
|
type: import("zod").ZodLiteral<"completionStream">;
|
|
159
|
-
token: import("zod").ZodString;
|
|
160
186
|
done: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}, import("zod/v4/core").$strip
|
|
170
|
-
|
|
187
|
+
events: import("zod").ZodArray<import("zod").ZodUnion<readonly [import("zod").ZodObject<{
|
|
188
|
+
type: import("zod").ZodLiteral<"contentDelta">;
|
|
189
|
+
seq: import("zod").ZodNumber;
|
|
190
|
+
text: import("zod").ZodString;
|
|
191
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
192
|
+
type: import("zod").ZodLiteral<"rawDelta">;
|
|
193
|
+
seq: import("zod").ZodNumber;
|
|
194
|
+
text: import("zod").ZodString;
|
|
195
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
196
|
+
type: import("zod").ZodLiteral<"thinkingDelta">;
|
|
197
|
+
seq: import("zod").ZodNumber;
|
|
198
|
+
text: import("zod").ZodString;
|
|
199
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
171
200
|
type: import("zod").ZodLiteral<"toolCall">;
|
|
201
|
+
seq: import("zod").ZodNumber;
|
|
172
202
|
call: import("zod").ZodObject<{
|
|
173
203
|
id: import("zod").ZodString;
|
|
174
204
|
name: import("zod").ZodString;
|
|
@@ -176,7 +206,8 @@ export declare const llmPlugin: {
|
|
|
176
206
|
raw: import("zod").ZodOptional<import("zod").ZodString>;
|
|
177
207
|
}, import("zod/v4/core").$strip>;
|
|
178
208
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
179
|
-
type: import("zod").ZodLiteral<"
|
|
209
|
+
type: import("zod").ZodLiteral<"toolError">;
|
|
210
|
+
seq: import("zod").ZodNumber;
|
|
180
211
|
error: import("zod").ZodObject<{
|
|
181
212
|
code: import("zod").ZodEnum<{
|
|
182
213
|
PARSE_ERROR: "PARSE_ERROR";
|
|
@@ -186,15 +217,42 @@ export declare const llmPlugin: {
|
|
|
186
217
|
message: import("zod").ZodString;
|
|
187
218
|
raw: import("zod").ZodOptional<import("zod").ZodString>;
|
|
188
219
|
}, import("zod/v4/core").$strip>;
|
|
189
|
-
}, import("zod/v4/core").$strip
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
220
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
221
|
+
type: import("zod").ZodLiteral<"completionStats">;
|
|
222
|
+
seq: import("zod").ZodNumber;
|
|
223
|
+
stats: import("zod").ZodObject<{
|
|
224
|
+
timeToFirstToken: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
225
|
+
tokensPerSecond: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
226
|
+
cacheTokens: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
227
|
+
generatedTokens: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
228
|
+
backendDevice: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
229
|
+
cpu: "cpu";
|
|
230
|
+
gpu: "gpu";
|
|
231
|
+
}>>;
|
|
232
|
+
}, import("zod/v4/core").$strip>;
|
|
233
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
234
|
+
type: import("zod").ZodLiteral<"completionDone">;
|
|
235
|
+
seq: import("zod").ZodNumber;
|
|
236
|
+
stopReason: import("zod").ZodLiteral<"error">;
|
|
237
|
+
error: import("zod").ZodObject<{
|
|
238
|
+
message: import("zod").ZodString;
|
|
239
|
+
}, import("zod/v4/core").$strip>;
|
|
240
|
+
raw: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
241
|
+
fullText: import("zod").ZodString;
|
|
242
|
+
}, import("zod/v4/core").$strip>>;
|
|
243
|
+
}, import("zod/v4/core").$strict>, import("zod").ZodObject<{
|
|
244
|
+
type: import("zod").ZodLiteral<"completionDone">;
|
|
245
|
+
seq: import("zod").ZodNumber;
|
|
246
|
+
stopReason: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
247
|
+
eos: "eos";
|
|
248
|
+
length: "length";
|
|
249
|
+
stopSequence: "stopSequence";
|
|
250
|
+
}>>;
|
|
251
|
+
raw: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
252
|
+
fullText: import("zod").ZodString;
|
|
253
|
+
}, import("zod/v4/core").$strip>>;
|
|
254
|
+
}, import("zod/v4/core").$strict>]>>;
|
|
255
|
+
}, import("zod/v4/core").$strict>>;
|
|
198
256
|
finetune: import("../../../../schemas/index").PluginHandlerDefinition<import("zod").ZodUnion<readonly [import("zod").ZodObject<{
|
|
199
257
|
modelId: import("zod").ZodString;
|
|
200
258
|
options: import("zod").ZodObject<{
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import LlmLlamacpp
|
|
1
|
+
import LlmLlamacpp from "@qvac/llm-llamacpp";
|
|
2
2
|
import llmAddonLogging from "@qvac/llm-llamacpp/addonLogging.js";
|
|
3
|
-
import { definePlugin, defineHandler, finetuneRequestSchema, completionStreamRequestSchema, completionStreamResponseSchema, finetuneResponseSchema, translateRequestSchema, translateResponseSchema, ModelType, llmConfigBaseSchema, ADDON_LLM, } from "../../../../schemas/index.js";
|
|
3
|
+
import { definePlugin, defineHandler, finetuneRequestSchema, completionStreamRequestSchema, completionStreamResponseSchema, finetuneResponseSchema, translateRequestSchema, translateResponseSchema, ModelType, llmConfigBaseSchema, ADDON_LLM, TOOLS_MODE, } from "../../../../schemas/index.js";
|
|
4
4
|
import { createStreamLogger, registerAddonLogger } from "../../../../logging/index.js";
|
|
5
|
-
import {
|
|
6
|
-
import FilesystemDL from "@qvac/dl-filesystem";
|
|
7
|
-
import { asLoader } from "../../utils/loader-adapter.js";
|
|
5
|
+
import { expandGGUFIntoShards } from "../../../utils/index.js";
|
|
8
6
|
import { completion } from "./ops/completion-stream.js";
|
|
9
7
|
import { finetune } from "./ops/finetune.js";
|
|
10
8
|
import { translate } from "../../ops/translate.js";
|
|
11
9
|
import { attachModelExecutionMs } from "../../../../profiling/model-execution.js";
|
|
10
|
+
import { getModelConfig } from "../../registry/model-registry.js";
|
|
11
|
+
import { createCompletionNormalizer } from "../../../utils/completion-normalizer.js";
|
|
12
|
+
import { detectToolDialect } from "../../../utils/tool-integration.js";
|
|
12
13
|
function transformLlmConfig(llmConfig) {
|
|
13
14
|
const transformed = JSON.parse(JSON.stringify(llmConfig, (key, v) => key === "modelType"
|
|
14
15
|
? undefined
|
|
@@ -27,28 +28,29 @@ function transformLlmConfig(llmConfig) {
|
|
|
27
28
|
transformed["openclCacheDir"] = transformed["opencl_cache_dir"];
|
|
28
29
|
delete transformed["opencl_cache_dir"];
|
|
29
30
|
}
|
|
31
|
+
if ("tools_mode" in transformed) {
|
|
32
|
+
if (transformed["tools_mode"] === TOOLS_MODE.dynamic) {
|
|
33
|
+
transformed["tools_compact"] = "true";
|
|
34
|
+
}
|
|
35
|
+
delete transformed["tools_mode"];
|
|
36
|
+
}
|
|
30
37
|
return transformed;
|
|
31
38
|
}
|
|
32
39
|
function createLlmModel(modelId, modelPath, llmConfig, projectionModelPath) {
|
|
33
|
-
const { dirPath, basePath } = parseModelPath(modelPath);
|
|
34
|
-
const loader = new FilesystemDL({ dirPath });
|
|
35
40
|
const logger = createStreamLogger(modelId, ModelType.llamacppCompletion);
|
|
36
41
|
registerAddonLogger(modelId, ModelType.llamacppCompletion, logger);
|
|
37
42
|
const llmConfigStrings = transformLlmConfig(llmConfig);
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
const modelFiles = expandGGUFIntoShards(modelPath);
|
|
44
|
+
const model = new LlmLlamacpp({
|
|
45
|
+
files: {
|
|
46
|
+
model: modelFiles,
|
|
47
|
+
...(projectionModelPath && { projectionModel: projectionModelPath }),
|
|
48
|
+
},
|
|
49
|
+
config: llmConfigStrings,
|
|
41
50
|
logger,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
? parseModelPath(projectionModelPath).basePath
|
|
46
|
-
: "",
|
|
47
|
-
modelPath,
|
|
48
|
-
modelConfig: llmConfigStrings,
|
|
49
|
-
};
|
|
50
|
-
const model = new LlmLlamacpp(args, llmConfigStrings);
|
|
51
|
-
return { model, loader };
|
|
51
|
+
opts: { stats: true },
|
|
52
|
+
});
|
|
53
|
+
return { model };
|
|
52
54
|
}
|
|
53
55
|
export const llmPlugin = definePlugin({
|
|
54
56
|
modelType: ModelType.llamacppCompletion,
|
|
@@ -68,8 +70,8 @@ export const llmPlugin = definePlugin({
|
|
|
68
70
|
},
|
|
69
71
|
createModel(params) {
|
|
70
72
|
const llmConfig = (params.modelConfig ?? {});
|
|
71
|
-
const { model
|
|
72
|
-
return { model
|
|
73
|
+
const { model } = createLlmModel(params.modelId, params.modelPath, llmConfig, params.artifacts?.["projectionModelPath"]);
|
|
74
|
+
return { model };
|
|
73
75
|
},
|
|
74
76
|
handlers: {
|
|
75
77
|
completionStream: defineHandler({
|
|
@@ -82,38 +84,61 @@ export const llmPlugin = definePlugin({
|
|
|
82
84
|
content,
|
|
83
85
|
attachments: attachments ?? [],
|
|
84
86
|
}));
|
|
87
|
+
const modelCfg = getModelConfig(request.modelId);
|
|
88
|
+
const toolsActive = (request.tools?.length ?? 0) > 0 &&
|
|
89
|
+
modelCfg.tools === true;
|
|
90
|
+
const capabilities = {
|
|
91
|
+
toolCalling: toolsActive ? "textParse" : "none",
|
|
92
|
+
thinkingFraming: request.captureThinking ? "thinkTags" : "none",
|
|
93
|
+
};
|
|
94
|
+
// Dialect runs regardless of tool availability — thinking/content
|
|
95
|
+
// stripping is needed even on plain completions.
|
|
96
|
+
const dialect = request.toolDialect ?? detectToolDialect(request.modelId);
|
|
97
|
+
const normalizer = createCompletionNormalizer({
|
|
98
|
+
capabilities,
|
|
99
|
+
tools: request.tools ?? [],
|
|
100
|
+
captureThinking: request.captureThinking ?? false,
|
|
101
|
+
emitRawDeltas: request.emitRawDeltas ?? false,
|
|
102
|
+
toolDialect: dialect,
|
|
103
|
+
});
|
|
85
104
|
const stream = completion({
|
|
86
105
|
history: filteredHistory,
|
|
87
106
|
modelId: request.modelId,
|
|
88
107
|
kvCache: request.kvCache,
|
|
89
|
-
...(request.tools && { tools: request.tools }),
|
|
108
|
+
...(toolsActive && request.tools && { tools: request.tools }),
|
|
90
109
|
...(request.generationParams && { generationParams: request.generationParams }),
|
|
110
|
+
...(toolsActive && { toolDialect: dialect }),
|
|
111
|
+
...(request.responseFormat && { responseFormat: request.responseFormat }),
|
|
91
112
|
});
|
|
92
113
|
try {
|
|
93
|
-
|
|
114
|
+
const batchedEvents = [];
|
|
94
115
|
let result = await stream.next();
|
|
95
116
|
while (!result.done) {
|
|
117
|
+
const events = normalizer.push(result.value.token);
|
|
96
118
|
if (request.stream) {
|
|
97
119
|
yield {
|
|
98
120
|
type: "completionStream",
|
|
99
|
-
|
|
100
|
-
...(result.value.toolCallEvent && {
|
|
101
|
-
toolCallEvent: result.value.toolCallEvent,
|
|
102
|
-
}),
|
|
121
|
+
events,
|
|
103
122
|
};
|
|
104
123
|
}
|
|
105
124
|
else {
|
|
106
|
-
|
|
125
|
+
batchedEvents.push(...events);
|
|
107
126
|
}
|
|
108
127
|
result = await stream.next();
|
|
109
128
|
}
|
|
110
129
|
const { modelExecutionMs, stats, toolCalls } = result.value;
|
|
130
|
+
const terminalEvents = normalizer.finish({
|
|
131
|
+
...(stats && { stats }),
|
|
132
|
+
...(toolCalls.length > 0 && { toolCalls }),
|
|
133
|
+
});
|
|
134
|
+
if (!request.stream) {
|
|
135
|
+
batchedEvents.push(...terminalEvents);
|
|
136
|
+
}
|
|
137
|
+
const finalEvents = request.stream ? terminalEvents : batchedEvents;
|
|
111
138
|
yield attachModelExecutionMs({
|
|
112
139
|
type: "completionStream",
|
|
113
|
-
token: request.stream ? "" : buffer,
|
|
114
140
|
done: true,
|
|
115
|
-
|
|
116
|
-
...(toolCalls.length > 0 && { toolCalls }),
|
|
141
|
+
events: finalEvents,
|
|
117
142
|
}, modelExecutionMs);
|
|
118
143
|
}
|
|
119
144
|
finally {
|
|
@@ -2,9 +2,7 @@ import EmbedLlamacpp, {} from "@qvac/embed-llamacpp";
|
|
|
2
2
|
import embedAddonLogging from "@qvac/embed-llamacpp/addonLogging.js";
|
|
3
3
|
import { definePlugin, defineHandler, embedRequestSchema, embedResponseSchema, ModelType, embedConfigBaseSchema, ADDON_EMBEDDING, } from "../../../../schemas/index.js";
|
|
4
4
|
import { createStreamLogger, registerAddonLogger } from "../../../../logging/index.js";
|
|
5
|
-
import {
|
|
6
|
-
import FilesystemDL from "@qvac/dl-filesystem";
|
|
7
|
-
import { asLoader } from "../../utils/loader-adapter.js";
|
|
5
|
+
import { expandGGUFIntoShards } from "../../../utils/index.js";
|
|
8
6
|
import { embed } from "../../ops/embed.js";
|
|
9
7
|
import { forwardModelExecution } from "../../../../profiling/model-execution.js";
|
|
10
8
|
function transformEmbedConfig(embedConfig) {
|
|
@@ -40,21 +38,17 @@ function transformEmbedConfig(embedConfig) {
|
|
|
40
38
|
return config;
|
|
41
39
|
}
|
|
42
40
|
function createEmbeddingsModel(modelId, modelPath, embedConfig) {
|
|
43
|
-
const { dirPath, basePath } = parseModelPath(modelPath);
|
|
44
|
-
const loader = new FilesystemDL({ dirPath });
|
|
45
41
|
const logger = createStreamLogger(modelId, ModelType.llamacppEmbedding);
|
|
46
42
|
registerAddonLogger(modelId, ModelType.llamacppEmbedding, logger);
|
|
47
43
|
const config = transformEmbedConfig(embedConfig);
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
const modelFiles = expandGGUFIntoShards(modelPath);
|
|
45
|
+
const model = new EmbedLlamacpp({
|
|
46
|
+
files: { model: modelFiles },
|
|
47
|
+
config,
|
|
51
48
|
logger,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
};
|
|
56
|
-
const model = new EmbedLlamacpp(args, config);
|
|
57
|
-
return { model, loader };
|
|
49
|
+
opts: { stats: true },
|
|
50
|
+
});
|
|
51
|
+
return { model };
|
|
58
52
|
}
|
|
59
53
|
export const embeddingsPlugin = definePlugin({
|
|
60
54
|
modelType: ModelType.llamacppEmbedding,
|
|
@@ -63,8 +57,8 @@ export const embeddingsPlugin = definePlugin({
|
|
|
63
57
|
loadConfigSchema: embedConfigBaseSchema,
|
|
64
58
|
createModel(params) {
|
|
65
59
|
const embedConfig = (params.modelConfig ?? {});
|
|
66
|
-
const { model
|
|
67
|
-
return { model
|
|
60
|
+
const { model } = createEmbeddingsModel(params.modelId, params.modelPath, embedConfig);
|
|
61
|
+
return { model };
|
|
68
62
|
},
|
|
69
63
|
handlers: {
|
|
70
64
|
embed: defineHandler({
|