@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 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DownloadHooks } from "../rpc/handlers/load-model/types";
|
|
2
2
|
export declare function calculateFileChecksum(filePath: string): Promise<string>;
|
|
3
|
-
export declare function measureChecksum(filePath: string, hooks?:
|
|
3
|
+
export declare function measureChecksum(filePath: string, hooks?: DownloadHooks): Promise<string>;
|
|
4
4
|
//# sourceMappingURL=checksum.d.ts.map
|
|
@@ -26,6 +26,6 @@ export async function calculateFileChecksum(filePath) {
|
|
|
26
26
|
export async function measureChecksum(filePath, hooks) {
|
|
27
27
|
const start = nowMs();
|
|
28
28
|
const checksum = await calculateFileChecksum(filePath);
|
|
29
|
-
hooks?.addChecksumValidationTimeMs(nowMs() - start);
|
|
29
|
+
hooks?.addChecksumValidationTimeMs?.(nowMs() - start);
|
|
30
30
|
return checksum;
|
|
31
31
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function resolveClearStorageTarget(modelPath, modelsCacheDir) {
|
|
2
|
+
const normalizedCache = modelsCacheDir.replace(/\\/g, "/").replace(/\/+$/, "");
|
|
3
|
+
const normalizedPath = modelPath.replace(/\\/g, "/");
|
|
4
|
+
if (!normalizedPath.startsWith(`${normalizedCache}/`)) {
|
|
5
|
+
return { path: modelPath, kind: "file" };
|
|
6
|
+
}
|
|
7
|
+
const relativePath = normalizedPath.slice(normalizedCache.length + 1);
|
|
8
|
+
const parts = relativePath.split("/");
|
|
9
|
+
if (parts.length === 3 &&
|
|
10
|
+
(parts[0] === "sets" || parts[0] === "onnx") &&
|
|
11
|
+
parts[1] &&
|
|
12
|
+
parts[2]) {
|
|
13
|
+
const lastSlash = normalizedPath.lastIndexOf("/");
|
|
14
|
+
return { path: normalizedPath.slice(0, lastSlash), kind: "directory" };
|
|
15
|
+
}
|
|
16
|
+
return { path: modelPath, kind: "file" };
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CompletionEvent, CompletionError, CompletionStats, NormalizerConfig, StopReason, ToolCall } from "../../schemas/index";
|
|
2
|
+
export type CompletionNormalizer = ReturnType<typeof createCompletionNormalizer>;
|
|
3
|
+
export declare function createCompletionNormalizer(config: NormalizerConfig): {
|
|
4
|
+
push: (token: string) => CompletionEvent[];
|
|
5
|
+
finish: (opts?: {
|
|
6
|
+
stats?: CompletionStats;
|
|
7
|
+
toolCalls?: ToolCall[];
|
|
8
|
+
error?: CompletionError;
|
|
9
|
+
stopReason?: StopReason;
|
|
10
|
+
}) => CompletionEvent[];
|
|
11
|
+
getAccumulated: () => {
|
|
12
|
+
rawText: string;
|
|
13
|
+
contentText: string;
|
|
14
|
+
thinkingText: string | undefined;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=completion-normalizer.d.ts.map
|
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
import { parseToolCalls } from "./tools/index.js";
|
|
2
|
+
const DIALECT_SPECS = {
|
|
3
|
+
hermes: {
|
|
4
|
+
toolFrames: [{ open: "<tool_call>", close: "</tool_call>" }],
|
|
5
|
+
},
|
|
6
|
+
// No streaming framing — tool calls are only recovered at finalization.
|
|
7
|
+
json: {
|
|
8
|
+
toolFrames: [],
|
|
9
|
+
},
|
|
10
|
+
pythonic: {
|
|
11
|
+
toolFrames: [
|
|
12
|
+
{ open: "<|tool_call_start|>", close: "<|tool_call_end|>" },
|
|
13
|
+
{
|
|
14
|
+
open: "<|start_header_id|>tool_call<|end_header_id|>",
|
|
15
|
+
close: "<|eot_id|>",
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
harmony: {
|
|
20
|
+
toolFrames: [
|
|
21
|
+
{ open: "<|channel|>commentary to=functions.", close: "<|call|>" },
|
|
22
|
+
],
|
|
23
|
+
thinkingFrames: [
|
|
24
|
+
{ open: "<|channel|>analysis<|message|>", close: "<|end|>" },
|
|
25
|
+
],
|
|
26
|
+
contentFrames: [
|
|
27
|
+
{ open: "<|channel|>final<|message|>", close: "<|return|>" },
|
|
28
|
+
],
|
|
29
|
+
// Role headers between channel frames + stray `<|return|>` closes.
|
|
30
|
+
dropTokens: [
|
|
31
|
+
"<|start|>assistant",
|
|
32
|
+
"<|start|>system",
|
|
33
|
+
"<|start|>user",
|
|
34
|
+
"<|return|>",
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
// Capture-gated reasoning marker — the generic `<think>...</think>`
|
|
39
|
+
// convention used by reasoning-tuned models. When the gate is off the
|
|
40
|
+
// markers pass through into `contentDelta` unchanged (preserves the
|
|
41
|
+
// pre-dialect behavior).
|
|
42
|
+
const BUILTIN_THINKING = { open: "<think>", close: "</think>" };
|
|
43
|
+
export function createCompletionNormalizer(config) {
|
|
44
|
+
let seq = 0;
|
|
45
|
+
let state = "content";
|
|
46
|
+
let rawText = "";
|
|
47
|
+
const contentParts = [];
|
|
48
|
+
const thinkingParts = [];
|
|
49
|
+
// Tool frame: buffer keeps the open + close markers in place so
|
|
50
|
+
// `parseToolCalls` can match its own dialect markers.
|
|
51
|
+
let toolCallBuffer = "";
|
|
52
|
+
let activeToolFrame = null;
|
|
53
|
+
// Thinking frame: tracks which frame's close marker we're scanning for
|
|
54
|
+
// (could be the built-in `<think>` or a dialect-specific frame like
|
|
55
|
+
// Harmony's `<|channel|>analysis<|message|>...<|end|>`).
|
|
56
|
+
let activeThinkingFrame = null;
|
|
57
|
+
// Content frame: inner streamed as it arrives; partial close tail buffered.
|
|
58
|
+
let activeContentFrame = null;
|
|
59
|
+
// Trailing chars that could be a prefix of a watched marker, so markers
|
|
60
|
+
// split across token pushes aren't missed by indexOf.
|
|
61
|
+
let contentTail = "";
|
|
62
|
+
let toolFramingTail = "";
|
|
63
|
+
let thinkingFramingTail = "";
|
|
64
|
+
let contentFramingTail = "";
|
|
65
|
+
const streamedToolCallKeys = new Set();
|
|
66
|
+
const toolsEnabled = config.tools.length > 0 && config.capabilities.toolCalling !== "none";
|
|
67
|
+
const useToolFraming = toolsEnabled && config.capabilities.toolCalling === "textParse";
|
|
68
|
+
// Register `<think>` only when both capability + capture opt in.
|
|
69
|
+
// Dialect protocol markers always register; capture only gates emission.
|
|
70
|
+
const useBuiltinThinkTags = config.captureThinking &&
|
|
71
|
+
config.capabilities.thinkingFraming === "thinkTags";
|
|
72
|
+
const dialect = config.toolDialect ?? "hermes";
|
|
73
|
+
const dialectSpec = DIALECT_SPECS[dialect];
|
|
74
|
+
const toolFrames = useToolFraming
|
|
75
|
+
? dialectSpec.toolFrames
|
|
76
|
+
: [];
|
|
77
|
+
const thinkingFrames = [
|
|
78
|
+
...(useBuiltinThinkTags ? [BUILTIN_THINKING] : []),
|
|
79
|
+
...(dialectSpec.thinkingFrames ?? []),
|
|
80
|
+
];
|
|
81
|
+
const contentFrames = dialectSpec.contentFrames ?? [];
|
|
82
|
+
const dropTokens = dialectSpec.dropTokens ?? [];
|
|
83
|
+
const markerToEntry = new Map();
|
|
84
|
+
const dropTokenSet = new Set();
|
|
85
|
+
const contentMarkers = [];
|
|
86
|
+
function registerFrames(frames, kind) {
|
|
87
|
+
for (const f of frames) {
|
|
88
|
+
if (markerToEntry.has(f.open))
|
|
89
|
+
continue;
|
|
90
|
+
markerToEntry.set(f.open, { kind, spec: f });
|
|
91
|
+
contentMarkers.push(f.open);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
registerFrames(toolFrames, "tool");
|
|
95
|
+
registerFrames(thinkingFrames, "thinking");
|
|
96
|
+
registerFrames(contentFrames, "content");
|
|
97
|
+
for (const t of dropTokens) {
|
|
98
|
+
if (markerToEntry.has(t) || dropTokenSet.has(t))
|
|
99
|
+
continue;
|
|
100
|
+
dropTokenSet.add(t);
|
|
101
|
+
contentMarkers.push(t);
|
|
102
|
+
}
|
|
103
|
+
function nextSeq() {
|
|
104
|
+
return seq++;
|
|
105
|
+
}
|
|
106
|
+
function emitContent(events, text) {
|
|
107
|
+
if (!text)
|
|
108
|
+
return;
|
|
109
|
+
contentParts.push(text);
|
|
110
|
+
events.push({ type: "contentDelta", seq: nextSeq(), text });
|
|
111
|
+
}
|
|
112
|
+
// Capture-gated: thinking frames may register even when `captureThinking`
|
|
113
|
+
// is false (e.g. harmony's analysis channel, to strip markers from
|
|
114
|
+
// `contentDelta`) — drop the inner here instead of buffering it.
|
|
115
|
+
function emitThinking(events, text) {
|
|
116
|
+
if (!text)
|
|
117
|
+
return;
|
|
118
|
+
if (config.captureThinking) {
|
|
119
|
+
thinkingParts.push(text);
|
|
120
|
+
events.push({ type: "thinkingDelta", seq: nextSeq(), text });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function getToolCallKey(call) {
|
|
124
|
+
return `${call.name}:${JSON.stringify(call.arguments)}`;
|
|
125
|
+
}
|
|
126
|
+
function emitStreamedToolCall(events, call) {
|
|
127
|
+
streamedToolCallKeys.add(getToolCallKey(call));
|
|
128
|
+
events.push({ type: "toolCall", seq: nextSeq(), call });
|
|
129
|
+
}
|
|
130
|
+
function emitFinalToolCall(events, call) {
|
|
131
|
+
if (streamedToolCallKeys.has(getToolCallKey(call)))
|
|
132
|
+
return;
|
|
133
|
+
events.push({ type: "toolCall", seq: nextSeq(), call });
|
|
134
|
+
}
|
|
135
|
+
// Length of the longest suffix of `buf` that is also a prefix of any marker.
|
|
136
|
+
function trailingPartialMarkerLen(buf, markers) {
|
|
137
|
+
if (markers.length === 0 || buf.length === 0)
|
|
138
|
+
return 0;
|
|
139
|
+
const maxLen = Math.min(buf.length, markers.reduce((m, s) => Math.max(m, s.length), 0) - 1);
|
|
140
|
+
for (let len = maxLen; len > 0; len--) {
|
|
141
|
+
const suffix = buf.slice(buf.length - len);
|
|
142
|
+
for (const m of markers) {
|
|
143
|
+
if (m.startsWith(suffix))
|
|
144
|
+
return len;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return 0;
|
|
148
|
+
}
|
|
149
|
+
function findEarliestMarker(buf, markers) {
|
|
150
|
+
let best = null;
|
|
151
|
+
for (const m of markers) {
|
|
152
|
+
const i = buf.indexOf(m);
|
|
153
|
+
if (i < 0)
|
|
154
|
+
continue;
|
|
155
|
+
if (best === null || i < best.idx)
|
|
156
|
+
best = { idx: i, marker: m };
|
|
157
|
+
}
|
|
158
|
+
return best;
|
|
159
|
+
}
|
|
160
|
+
function flushToolBuffer(events, closed) {
|
|
161
|
+
const raw = toolCallBuffer;
|
|
162
|
+
const frame = activeToolFrame;
|
|
163
|
+
toolCallBuffer = "";
|
|
164
|
+
activeToolFrame = null;
|
|
165
|
+
toolFramingTail = "";
|
|
166
|
+
if (!frame)
|
|
167
|
+
return;
|
|
168
|
+
// Empty-payload guard. Strip frame markers and check the inner is
|
|
169
|
+
// non-empty; surface a toolError on empty payloads so the literal
|
|
170
|
+
// markers don't leak into contentDelta.
|
|
171
|
+
let inner = raw;
|
|
172
|
+
if (inner.startsWith(frame.open))
|
|
173
|
+
inner = inner.slice(frame.open.length);
|
|
174
|
+
if (inner.endsWith(frame.close)) {
|
|
175
|
+
inner = inner.slice(0, inner.length - frame.close.length);
|
|
176
|
+
}
|
|
177
|
+
if (inner.trim().length === 0) {
|
|
178
|
+
events.push({
|
|
179
|
+
type: "toolError",
|
|
180
|
+
seq: nextSeq(),
|
|
181
|
+
error: { code: "PARSE_ERROR", message: "Empty tool_call frame" },
|
|
182
|
+
});
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const { toolCalls, errors } = parseToolCalls(raw, config.tools, dialect);
|
|
186
|
+
for (const call of toolCalls)
|
|
187
|
+
emitStreamedToolCall(events, call);
|
|
188
|
+
if (toolCalls.length === 0) {
|
|
189
|
+
if (errors.length > 0) {
|
|
190
|
+
for (const error of errors) {
|
|
191
|
+
events.push({ type: "toolError", seq: nextSeq(), error });
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
events.push({
|
|
196
|
+
type: "toolError",
|
|
197
|
+
seq: nextSeq(),
|
|
198
|
+
error: {
|
|
199
|
+
code: "PARSE_ERROR",
|
|
200
|
+
message: closed
|
|
201
|
+
? "Failed to parse tool call from framed region"
|
|
202
|
+
: "Incomplete tool call frame at stream end",
|
|
203
|
+
raw,
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
emitContent(events, raw);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
function getStateTail() {
|
|
211
|
+
switch (state) {
|
|
212
|
+
case "content":
|
|
213
|
+
return contentTail;
|
|
214
|
+
case "thinkingFraming":
|
|
215
|
+
return thinkingFramingTail;
|
|
216
|
+
case "toolFraming":
|
|
217
|
+
return toolFramingTail;
|
|
218
|
+
case "contentFraming":
|
|
219
|
+
return contentFramingTail;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
function processSegment(events, text) {
|
|
223
|
+
let buf = getStateTail() + text;
|
|
224
|
+
contentTail = "";
|
|
225
|
+
thinkingFramingTail = "";
|
|
226
|
+
toolFramingTail = "";
|
|
227
|
+
contentFramingTail = "";
|
|
228
|
+
while (buf.length > 0) {
|
|
229
|
+
if (state === "toolFraming") {
|
|
230
|
+
if (!activeToolFrame) {
|
|
231
|
+
state = "content";
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
const hit = buf.indexOf(activeToolFrame.close);
|
|
235
|
+
if (hit >= 0) {
|
|
236
|
+
toolCallBuffer += buf.slice(0, hit + activeToolFrame.close.length);
|
|
237
|
+
buf = buf.slice(hit + activeToolFrame.close.length);
|
|
238
|
+
state = "content";
|
|
239
|
+
flushToolBuffer(events, true);
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
const tailLen = trailingPartialMarkerLen(buf, [activeToolFrame.close]);
|
|
243
|
+
const safeLen = buf.length - tailLen;
|
|
244
|
+
toolCallBuffer += buf.slice(0, safeLen);
|
|
245
|
+
toolFramingTail = buf.slice(safeLen);
|
|
246
|
+
buf = "";
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
if (state === "thinkingFraming") {
|
|
250
|
+
if (!activeThinkingFrame) {
|
|
251
|
+
state = "content";
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
const closeMarker = activeThinkingFrame.close;
|
|
255
|
+
const closeIdx = buf.indexOf(closeMarker);
|
|
256
|
+
if (closeIdx >= 0) {
|
|
257
|
+
emitThinking(events, buf.slice(0, closeIdx));
|
|
258
|
+
buf = buf.slice(closeIdx + closeMarker.length);
|
|
259
|
+
activeThinkingFrame = null;
|
|
260
|
+
state = "content";
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
const tailLen = trailingPartialMarkerLen(buf, [closeMarker]);
|
|
264
|
+
const safeLen = buf.length - tailLen;
|
|
265
|
+
emitThinking(events, buf.slice(0, safeLen));
|
|
266
|
+
thinkingFramingTail = buf.slice(safeLen);
|
|
267
|
+
buf = "";
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
if (state === "contentFraming") {
|
|
271
|
+
if (!activeContentFrame) {
|
|
272
|
+
state = "content";
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
const closeMarker = activeContentFrame.close;
|
|
276
|
+
const closeIdx = buf.indexOf(closeMarker);
|
|
277
|
+
if (closeIdx >= 0) {
|
|
278
|
+
emitContent(events, buf.slice(0, closeIdx));
|
|
279
|
+
activeContentFrame = null;
|
|
280
|
+
contentFramingTail = "";
|
|
281
|
+
buf = buf.slice(closeIdx + closeMarker.length);
|
|
282
|
+
state = "content";
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
const tailLen = trailingPartialMarkerLen(buf, [closeMarker]);
|
|
286
|
+
const safeLen = buf.length - tailLen;
|
|
287
|
+
emitContent(events, buf.slice(0, safeLen));
|
|
288
|
+
contentFramingTail = buf.slice(safeLen);
|
|
289
|
+
buf = "";
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
const hit = findEarliestMarker(buf, contentMarkers);
|
|
293
|
+
if (hit) {
|
|
294
|
+
emitContent(events, buf.slice(0, hit.idx));
|
|
295
|
+
buf = buf.slice(hit.idx + hit.marker.length);
|
|
296
|
+
if (dropTokenSet.has(hit.marker)) {
|
|
297
|
+
// Glue token between frames — strip and stay in content state.
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
const entry = markerToEntry.get(hit.marker);
|
|
301
|
+
if (entry.kind === "tool") {
|
|
302
|
+
toolCallBuffer = hit.marker;
|
|
303
|
+
activeToolFrame = entry.spec;
|
|
304
|
+
state = "toolFraming";
|
|
305
|
+
}
|
|
306
|
+
else if (entry.kind === "thinking") {
|
|
307
|
+
activeThinkingFrame = entry.spec;
|
|
308
|
+
state = "thinkingFraming";
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
activeContentFrame = entry.spec;
|
|
312
|
+
state = "contentFraming";
|
|
313
|
+
}
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
const tailLen = trailingPartialMarkerLen(buf, contentMarkers);
|
|
317
|
+
const safeLen = buf.length - tailLen;
|
|
318
|
+
emitContent(events, buf.slice(0, safeLen));
|
|
319
|
+
contentTail = buf.slice(safeLen);
|
|
320
|
+
buf = "";
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
function push(token) {
|
|
324
|
+
const events = [];
|
|
325
|
+
rawText += token;
|
|
326
|
+
if (config.emitRawDeltas) {
|
|
327
|
+
events.push({ type: "rawDelta", seq: nextSeq(), text: token });
|
|
328
|
+
}
|
|
329
|
+
processSegment(events, token);
|
|
330
|
+
return events;
|
|
331
|
+
}
|
|
332
|
+
function finish(opts) {
|
|
333
|
+
const events = [];
|
|
334
|
+
// Drain pending tail bytes so we don't lose trailing chars when the
|
|
335
|
+
// stream ends mid-marker.
|
|
336
|
+
if (state === "content" && contentTail) {
|
|
337
|
+
emitContent(events, contentTail);
|
|
338
|
+
contentTail = "";
|
|
339
|
+
}
|
|
340
|
+
else if (state === "thinkingFraming" && thinkingFramingTail) {
|
|
341
|
+
emitThinking(events, thinkingFramingTail);
|
|
342
|
+
thinkingFramingTail = "";
|
|
343
|
+
}
|
|
344
|
+
else if (state === "toolFraming" && toolFramingTail) {
|
|
345
|
+
toolCallBuffer += toolFramingTail;
|
|
346
|
+
toolFramingTail = "";
|
|
347
|
+
}
|
|
348
|
+
else if (state === "contentFraming" && contentFramingTail) {
|
|
349
|
+
// Cutoff inside a partial close marker — emit tail as content.
|
|
350
|
+
emitContent(events, contentFramingTail);
|
|
351
|
+
contentFramingTail = "";
|
|
352
|
+
}
|
|
353
|
+
if (state === "toolFraming" && activeToolFrame) {
|
|
354
|
+
if (opts?.error) {
|
|
355
|
+
emitContent(events, toolCallBuffer);
|
|
356
|
+
toolCallBuffer = "";
|
|
357
|
+
activeToolFrame = null;
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
flushToolBuffer(events, false);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
else if (state === "contentFraming") {
|
|
364
|
+
activeContentFrame = null;
|
|
365
|
+
}
|
|
366
|
+
activeThinkingFrame = null;
|
|
367
|
+
state = "content";
|
|
368
|
+
if (!opts?.error) {
|
|
369
|
+
if (opts?.toolCalls) {
|
|
370
|
+
for (const call of opts.toolCalls) {
|
|
371
|
+
emitFinalToolCall(events, call);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
if (opts?.stats) {
|
|
376
|
+
events.push({
|
|
377
|
+
type: "completionStats",
|
|
378
|
+
seq: nextSeq(),
|
|
379
|
+
stats: opts.stats,
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
const raw = { fullText: rawText };
|
|
383
|
+
if (opts?.error) {
|
|
384
|
+
events.push({
|
|
385
|
+
type: "completionDone",
|
|
386
|
+
seq: nextSeq(),
|
|
387
|
+
stopReason: "error",
|
|
388
|
+
error: opts.error,
|
|
389
|
+
raw,
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
else if (opts?.stopReason) {
|
|
393
|
+
events.push({
|
|
394
|
+
type: "completionDone",
|
|
395
|
+
seq: nextSeq(),
|
|
396
|
+
stopReason: opts.stopReason,
|
|
397
|
+
raw,
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
else {
|
|
401
|
+
events.push({ type: "completionDone", seq: nextSeq(), raw });
|
|
402
|
+
}
|
|
403
|
+
return events;
|
|
404
|
+
}
|
|
405
|
+
function getAccumulated() {
|
|
406
|
+
return {
|
|
407
|
+
rawText,
|
|
408
|
+
contentText: contentParts.join(""),
|
|
409
|
+
thinkingText: thinkingParts.length > 0 ? thinkingParts.join("") : undefined,
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
return { push, finish, getAccumulated };
|
|
413
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const SHARD_PATTERN = /^(.+)-(\d{5})-of-(\d{5})\.gguf$/;
|
|
2
|
+
/** Expand a sharded GGUF path into `.tensors.txt` plus all shards. */
|
|
3
|
+
export function expandGGUFIntoShards(modelPath) {
|
|
4
|
+
const lastSep = Math.max(modelPath.lastIndexOf("/"), modelPath.lastIndexOf("\\"));
|
|
5
|
+
const dir = lastSep >= 0 ? modelPath.slice(0, lastSep) : "";
|
|
6
|
+
const sep = lastSep >= 0 ? modelPath.charAt(lastSep) : "/";
|
|
7
|
+
const filename = lastSep >= 0 ? modelPath.slice(lastSep + 1) : modelPath;
|
|
8
|
+
const match = filename.match(SHARD_PATTERN);
|
|
9
|
+
if (!match || !match[1] || !match[3])
|
|
10
|
+
return [modelPath];
|
|
11
|
+
const baseFilename = match[1];
|
|
12
|
+
const totalDigits = match[3];
|
|
13
|
+
const totalShards = Number.parseInt(totalDigits, 10);
|
|
14
|
+
if (totalShards <= 0)
|
|
15
|
+
return [modelPath];
|
|
16
|
+
const join = (name) => (dir ? `${dir}${sep}${name}` : name);
|
|
17
|
+
const shards = [join(`${baseFilename}.tensors.txt`)];
|
|
18
|
+
for (let i = 1; i <= totalShards; i++) {
|
|
19
|
+
shards.push(join(`${baseFilename}-${String(i).padStart(5, "0")}-of-${totalDigits}.gguf`));
|
|
20
|
+
}
|
|
21
|
+
return shards;
|
|
22
|
+
}
|
|
@@ -13,7 +13,7 @@ function isModelDescriptor(value) {
|
|
|
13
13
|
return (typeof value === "object" &&
|
|
14
14
|
value !== null &&
|
|
15
15
|
"src" in value &&
|
|
16
|
-
typeof value.src === "string");
|
|
16
|
+
typeof (value).src === "string");
|
|
17
17
|
}
|
|
18
18
|
function normalizeValue(value) {
|
|
19
19
|
if (isModelDescriptor(value)) {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
export * from "./archive";
|
|
2
|
-
export * from "./cache";
|
|
2
|
+
export * from "./cache/types";
|
|
3
|
+
export * from "./cache/auto-history";
|
|
4
|
+
export * from "./cache/paths";
|
|
3
5
|
export * from "./checksum";
|
|
4
6
|
export * from "./config-transform";
|
|
7
|
+
export * from "./expand-gguf-shards";
|
|
5
8
|
export * from "./formatting";
|
|
6
9
|
export * from "./gguf-tensor-extractor";
|
|
7
|
-
export * from "./model-path";
|
|
8
10
|
export * from "./path-security";
|
|
9
11
|
export * from "./shard-utils";
|
|
10
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export * from "./archive.js";
|
|
2
|
-
export * from "./cache.js";
|
|
2
|
+
export * from "./cache/types.js";
|
|
3
|
+
export * from "./cache/auto-history.js";
|
|
4
|
+
export * from "./cache/paths.js";
|
|
3
5
|
export * from "./checksum.js";
|
|
4
6
|
export * from "./config-transform.js";
|
|
7
|
+
export * from "./expand-gguf-shards.js";
|
|
5
8
|
export * from "./formatting.js";
|
|
6
9
|
export * from "./gguf-tensor-extractor.js";
|
|
7
|
-
export * from "./model-path.js";
|
|
8
10
|
export * from "./path-security.js";
|
|
9
11
|
export * from "./shard-utils.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Translates the request-level `responseFormat` into the JSON Schema string
|
|
2
|
+
// that the llama.cpp addon's per-request `generationParams.json_schema`
|
|
3
|
+
// expects. Returns `undefined` for `{ type: "text" }` (no constraint).
|
|
4
|
+
//
|
|
5
|
+
// The addon converts the schema to GBNF natively via
|
|
6
|
+
// `json_schema_to_grammar()` and applies it for the duration of the request
|
|
7
|
+
// only, restoring the prior sampling block afterwards — so this surface is
|
|
8
|
+
// safe to use under concurrent completions on the same model. (Tool calling
|
|
9
|
+
// still goes through `setupToolGrammar` / `modelConfig.grammar`; see the
|
|
10
|
+
// mutual-exclusion check in `completionClientParamsSchema`.)
|
|
11
|
+
export function getResponseFormatJsonSchema(responseFormat) {
|
|
12
|
+
switch (responseFormat.type) {
|
|
13
|
+
case "text":
|
|
14
|
+
return undefined;
|
|
15
|
+
case "json_object":
|
|
16
|
+
return JSON.stringify({ type: "object" });
|
|
17
|
+
case "json_schema":
|
|
18
|
+
return JSON.stringify(responseFormat.json_schema.schema);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Tool,
|
|
1
|
+
import type { Tool, ToolDialect } from "../../schemas/index";
|
|
2
2
|
interface HistoryMessage {
|
|
3
3
|
role: string;
|
|
4
4
|
content: string;
|
|
@@ -6,8 +6,19 @@ interface HistoryMessage {
|
|
|
6
6
|
path: string;
|
|
7
7
|
}[] | undefined;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Static tools mode: prepend tools right after the system message (or at the
|
|
11
|
+
* very start when no system message is present). The tool block stays in the
|
|
12
|
+
* kv-cache for the whole chat session.
|
|
13
|
+
*/
|
|
14
|
+
export declare function prependToolsToHistory(history: HistoryMessage[], tools: Tool[]): Array<HistoryMessage | Tool>;
|
|
15
|
+
/**
|
|
16
|
+
* Dynamic tools mode: append tools after the last history message. The
|
|
17
|
+
* addon's compact-tools mode anchors the block after the last user message
|
|
18
|
+
* and trims it from the kv-cache once the tool-call chain resolves, so a
|
|
19
|
+
* subsequent turn can ship a different tool set without poisoning the cache.
|
|
20
|
+
*/
|
|
21
|
+
export declare function appendToolsToHistory(history: HistoryMessage[], tools: Tool[]): Array<HistoryMessage | Tool>;
|
|
22
|
+
export declare function detectToolDialect(modelId: string): ToolDialect;
|
|
12
23
|
export {};
|
|
13
24
|
//# sourceMappingURL=tool-integration.d.ts.map
|