@qvac/sdk 0.16.0 → 0.17.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 +118 -96
- package/README.md +65 -0
- package/dist/client/api/audio-gen-result.d.ts +4 -0
- package/dist/client/api/audio-gen-result.js +132 -0
- package/dist/client/api/audio-gen.d.ts +29 -0
- package/dist/client/api/audio-gen.js +31 -0
- package/dist/client/api/batch-completion.d.ts +2 -2
- package/dist/client/api/batch-completion.js +2 -2
- package/dist/client/api/bci-transcribe.d.ts +1 -1
- package/dist/client/api/bci-transcribe.js +3 -3
- package/dist/client/api/cancel.d.ts +1 -1
- package/dist/client/api/cancel.js +1 -1
- package/dist/client/api/classify.d.ts +1 -1
- package/dist/client/api/classify.js +1 -1
- package/dist/client/api/completion-stream.d.ts +3 -3
- package/dist/client/api/completion-stream.js +3 -3
- package/dist/client/api/delete-cache.js +1 -1
- package/dist/client/api/diffusion.d.ts +1 -1
- package/dist/client/api/diffusion.js +1 -1
- package/dist/client/api/download-asset.d.ts +1 -1
- package/dist/client/api/download-asset.js +3 -3
- package/dist/client/api/embed.d.ts +1 -1
- package/dist/client/api/embed.js +2 -2
- package/dist/client/api/finetune.d.ts +1 -1
- package/dist/client/api/finetune.js +2 -2
- package/dist/client/api/get-loaded-model-info.d.ts +2 -2
- package/dist/client/api/get-loaded-model-info.js +1 -1
- package/dist/client/api/get-model-info.d.ts +2 -2
- package/dist/client/api/get-model-info.js +1 -1
- package/dist/client/api/get-system-resources.d.ts +3 -0
- package/dist/client/api/get-system-resources.js +16 -0
- package/dist/client/api/heartbeat.d.ts +2 -2
- package/dist/client/api/heartbeat.js +1 -1
- package/dist/client/api/index.d.ts +35 -33
- package/dist/client/api/index.js +2 -0
- package/dist/client/api/invoke-plugin.d.ts +1 -1
- package/dist/client/api/invoke-plugin.js +1 -1
- package/dist/client/api/load-model.d.ts +2 -2
- package/dist/client/api/load-model.js +4 -4
- package/dist/client/api/logging-stream.d.ts +1 -1
- package/dist/client/api/logging-stream.js +1 -1
- package/dist/client/api/ocr.d.ts +1 -1
- package/dist/client/api/ocr.js +1 -1
- package/dist/client/api/provide.d.ts +1 -1
- package/dist/client/api/provide.js +1 -1
- package/dist/client/api/rag.d.ts +1 -1
- package/dist/client/api/rag.js +2 -2
- package/dist/client/api/registry.d.ts +1 -1
- package/dist/client/api/registry.js +1 -1
- package/dist/client/api/resume.js +1 -1
- package/dist/client/api/state.d.ts +1 -1
- package/dist/client/api/state.js +1 -1
- package/dist/client/api/stop-provider.js +1 -1
- package/dist/client/api/subscribe-logs.d.ts +1 -1
- package/dist/client/api/suspend.js +1 -1
- package/dist/client/api/text-to-speech.d.ts +3 -2
- package/dist/client/api/text-to-speech.js +31 -9
- package/dist/client/api/transcribe.d.ts +1 -1
- package/dist/client/api/transcribe.js +2 -2
- package/dist/client/api/translate.d.ts +3 -3
- package/dist/client/api/translate.js +3 -3
- package/dist/client/api/unload-model.d.ts +1 -1
- package/dist/client/api/unload-model.js +2 -2
- package/dist/client/api/upscale.d.ts +1 -1
- package/dist/client/api/upscale.js +1 -1
- package/dist/client/api/video.d.ts +1 -1
- package/dist/client/api/video.js +2 -2
- package/dist/client/api/vla.d.ts +1 -1
- package/dist/client/config-loader/config-utils.d.ts +1 -1
- package/dist/client/config-loader/resolve-config.bare.d.ts +1 -1
- package/dist/client/config-loader/resolve-config.expo.d.ts +1 -1
- package/dist/client/config-loader/resolve-config.node.d.ts +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/init-hooks.d.ts +1 -1
- package/dist/client/logging-stream-registry.d.ts +1 -1
- package/dist/client/plugins-factory.d.ts +2 -2
- package/dist/client/plugins-factory.js +1 -1
- package/dist/client/rpc/bare-client.d.ts +1 -1
- package/dist/client/rpc/bare-client.js +3 -3
- package/dist/client/rpc/expo-rpc-client.js +3 -3
- package/dist/client/rpc/node-rpc-client.js +2 -2
- package/dist/client/rpc/profiling/index.d.ts +1 -1
- package/dist/client/rpc/profiling/profiler.d.ts +2 -2
- package/dist/client/rpc/profiling/profiler.js +4 -0
- package/dist/client/rpc/rpc-client.d.ts +1 -1
- package/dist/client/rpc/rpc-client.js +7 -4
- package/dist/client/rpc/rpc-error.d.ts +1 -1
- package/dist/commands/bundle/bare-pack.d.ts +1 -1
- package/dist/commands/bundle/constants.js +1 -0
- package/dist/commands/bundle/entry-gen.js +1 -1
- package/dist/commands/bundle/index.js +6 -6
- package/dist/commands/bundle/manifest.d.ts +1 -1
- package/dist/commands/bundle/plugins.d.ts +2 -2
- package/dist/commands/bundle/plugins.js +1 -1
- package/dist/commands/index.d.ts +4 -4
- package/dist/commands/index.js +2 -2
- package/dist/commands/verify/abi.d.ts +1 -1
- package/dist/commands/verify/abi.js +1 -1
- package/dist/commands/verify/bundle-source.d.ts +1 -1
- package/dist/commands/verify/bundle-source.js +2 -2
- package/dist/commands/verify/index.d.ts +3 -3
- package/dist/commands/verify/index.js +5 -5
- package/dist/commands/verify/node-modules-source.d.ts +1 -1
- package/dist/commands/verify/node-modules-source.js +1 -1
- package/dist/commands/verify/prebuilds.d.ts +2 -1
- package/dist/commands/verify/prebuilds.js +8 -11
- package/dist/commands/verify/resource-collectors.d.ts +88 -0
- package/dist/commands/verify/resource-collectors.js +261 -0
- package/dist/constants/audio.js +1 -1
- package/dist/constants/index.d.ts +2 -2
- package/dist/examples/{transcription → asr}/parakeet-ctc-filesystem.js +2 -3
- package/dist/examples/{transcription → asr}/parakeet-microphone-record.js +2 -2
- package/dist/examples/{transcription → asr}/parakeet-microphone-stream.js +2 -2
- package/dist/examples/{transcription → asr}/parakeet-sortformer-streaming.js +2 -2
- package/dist/examples/{transcription → asr}/parakeet-sortformer.js +1 -1
- package/dist/examples/{transcription → asr}/parakeet-tdt-filesystem-chunked.js +2 -2
- package/dist/examples/{transcription → asr}/parakeet-tdt-filesystem.js +2 -2
- package/dist/examples/{transcription → asr}/whispercpp-filesystem-streaming.js +1 -1
- package/dist/examples/{transcription → asr}/whispercpp-filesystem.js +1 -1
- package/dist/examples/{transcription → asr}/whispercpp-microphone-conversation.js +1 -1
- package/dist/examples/{transcription → asr}/whispercpp-microphone-record.js +2 -2
- package/dist/examples/{transcription → asr}/whispercpp-prompt.js +1 -1
- package/dist/examples/audiogen/generate-music.d.ts +2 -0
- package/dist/examples/audiogen/generate-music.js +112 -0
- package/dist/examples/cache-management.js +1 -1
- package/dist/examples/config-reload.js +1 -1
- package/dist/examples/diffusion-txt2vid-wan22.d.ts +2 -0
- package/dist/examples/diffusion-txt2vid-wan22.js +96 -0
- package/dist/examples/quickstart.bare.js +1 -1
- package/dist/examples/rag/rag-mongodb.d.ts +2 -0
- package/dist/examples/rag/rag-mongodb.js +180 -0
- package/dist/examples/tools/llamacpp-tools-auto-dialect.d.ts +2 -0
- package/dist/examples/tools/llamacpp-tools-auto-dialect.js +77 -0
- package/dist/examples/tts/parler.d.ts +2 -0
- package/dist/examples/tts/parler.js +51 -0
- package/dist/examples/vla-groot.js +6 -4
- package/dist/examples/voice-assistant/voice-assistant.js +2 -2
- package/dist/expo/plugins/index.d.ts +11 -11
- package/dist/expo/plugins/withDeviceInfo.js +2 -2
- package/dist/expo/plugins/withMobileBundle.js +3 -3
- package/dist/index.d.ts +16 -16
- package/dist/index.js +4 -4
- package/dist/logging/addon.d.ts +1 -1
- package/dist/logging/base-logger.d.ts +1 -1
- package/dist/logging/base-logger.js +1 -1
- package/dist/logging/client-logger.d.ts +1 -1
- package/dist/logging/index.d.ts +9 -9
- package/dist/logging/logger.d.ts +1 -1
- package/dist/logging/namespaces.d.ts +1 -1
- package/dist/logging/registry.d.ts +1 -1
- package/dist/logging/server-logger.d.ts +1 -1
- package/dist/logging/stream-logger.d.ts +1 -1
- package/dist/logging/transport.d.ts +1 -1
- package/dist/logging/utils.d.ts +1 -1
- package/dist/logging/utils.js +1 -1
- package/dist/models/registry/index.d.ts +1 -1
- package/dist/models/registry/models.d.ts +1226 -689
- package/dist/models/registry/models.js +3114 -2557
- package/dist/models/update-models/codegen.d.ts +1 -1
- package/dist/models/update-models/companions.d.ts +1 -1
- package/dist/models/update-models/history.d.ts +1 -1
- package/dist/models/update-models/history.js +4 -4
- package/dist/models/update-models/naming.d.ts +1 -1
- package/dist/models/update-models/naming.js +7 -1
- package/dist/models/update-models/processing.d.ts +1 -1
- package/dist/models/update-models/processing.js +1 -1
- package/dist/models/update-models/registry.d.ts +2 -2
- package/dist/models/update-models/shards.d.ts +1 -1
- package/dist/models/update-models/types.d.ts +1 -1
- package/dist/pear/pre.js +2 -0
- package/dist/profiling/aggregator.d.ts +1 -1
- package/dist/profiling/backend-diagnostics.d.ts +8 -0
- package/dist/profiling/backend-diagnostics.js +21 -0
- package/dist/profiling/controller.d.ts +4 -2
- package/dist/profiling/controller.js +8 -0
- package/dist/profiling/envelope.d.ts +3 -2
- package/dist/profiling/envelope.js +13 -2
- package/dist/profiling/events.d.ts +2 -2
- package/dist/profiling/exporters.d.ts +1 -1
- package/dist/profiling/index.d.ts +9 -8
- package/dist/profiling/index.js +3 -2
- package/dist/profiling/types.d.ts +6 -0
- package/dist/schemas/audio-gen.d.ts +253 -0
- package/dist/schemas/audio-gen.js +69 -0
- package/dist/schemas/batch-completion-stream.d.ts +7 -2
- package/dist/schemas/bci-config.d.ts +2 -0
- package/dist/schemas/bci.d.ts +1 -1
- package/dist/schemas/cancel.d.ts +5 -0
- package/dist/schemas/cancel.js +1 -0
- package/dist/schemas/common.d.ts +1553 -54
- package/dist/schemas/common.js +6 -0
- package/dist/schemas/completion-event.d.ts +5 -2
- package/dist/schemas/completion-event.js +3 -0
- package/dist/schemas/completion-stream.d.ts +9 -1
- package/dist/schemas/completion-stream.js +5 -2
- package/dist/schemas/constants-registry.d.ts +2 -0
- package/dist/schemas/constants-registry.js +2 -1
- package/dist/schemas/download-asset.d.ts +8 -4
- package/dist/schemas/engine-addon-map.d.ts +2 -1
- package/dist/schemas/engine-addon-map.js +5 -1
- package/dist/schemas/get-loaded-model-info.d.ts +2 -0
- package/dist/schemas/get-model-info.d.ts +2 -0
- package/dist/schemas/get-model-info.js +1 -0
- package/dist/schemas/index.d.ts +53 -51
- package/dist/schemas/index.js +4 -2
- package/dist/schemas/llamacpp-config.d.ts +6 -2
- package/dist/schemas/load-model.d.ts +6178 -2763
- package/dist/schemas/load-model.js +39 -3
- package/dist/schemas/mcp-adapter.d.ts +1 -1
- package/dist/schemas/model-src-utils.d.ts +10 -2
- package/dist/schemas/model-types.d.ts +19 -1
- package/dist/schemas/model-types.js +11 -0
- package/dist/schemas/ocr.d.ts +2 -0
- package/dist/schemas/plugin.d.ts +13 -4
- package/dist/schemas/plugin.js +12 -2
- package/dist/schemas/profiling.d.ts +587 -0
- package/dist/schemas/profiling.js +22 -0
- package/dist/schemas/registry.d.ts +18 -0
- package/dist/schemas/registry.js +2 -0
- package/dist/schemas/reload-config.d.ts +10 -2
- package/dist/schemas/sdcpp-config.d.ts +57 -0
- package/dist/schemas/sdcpp-config.js +53 -11
- package/dist/schemas/sdk-config.d.ts +168 -0
- package/dist/schemas/system-resources.d.ts +3967 -0
- package/dist/schemas/system-resources.js +149 -0
- package/dist/schemas/text-to-speech.d.ts +326 -6
- package/dist/schemas/text-to-speech.js +126 -13
- package/dist/schemas/transcription-config.d.ts +2 -0
- package/dist/schemas/translate.d.ts +2 -2
- package/dist/schemas/translation-config.d.ts +30 -10
- package/dist/scripts/check-resource-collectors-packaging.d.ts +33 -0
- package/dist/scripts/check-resource-collectors-packaging.js +136 -0
- package/dist/scripts/contract/build-contract.d.ts +1 -1
- package/dist/scripts/contract/build-models-registry.d.ts +1 -1
- package/dist/scripts/contract/plugin-contract.d.ts +1 -1
- package/dist/scripts/contract/plugin-contract.js +1 -1
- package/dist/scripts/export-contract.js +1 -1
- package/dist/scripts/export-plugin-contract.js +1 -1
- package/dist/server/bare/delegate-rpc-client.d.ts +1 -1
- package/dist/server/bare/delegate-rpc-client.js +3 -3
- package/dist/server/bare/hyperswarm.d.ts +1 -1
- package/dist/server/bare/hyperswarm.js +2 -2
- package/dist/server/bare/ops/bci-transcribe.d.ts +1 -1
- package/dist/server/bare/ops/bci-transcribe.js +4 -4
- package/dist/server/bare/ops/cancel.d.ts +2 -2
- package/dist/server/bare/ops/cancel.js +2 -2
- package/dist/server/bare/ops/embed.d.ts +1 -1
- package/dist/server/bare/ops/embed.js +3 -3
- package/dist/server/bare/ops/kv-cache-retention.d.ts +12 -0
- package/dist/server/bare/ops/kv-cache-retention.js +121 -0
- package/dist/server/bare/ops/kv-cache-utils.d.ts +2 -1
- package/dist/server/bare/ops/kv-cache-utils.js +26 -5
- package/dist/server/bare/ops/load-model.d.ts +2 -2
- package/dist/server/bare/ops/load-model.js +7 -5
- package/dist/server/bare/ops/transcribe.d.ts +2 -2
- package/dist/server/bare/ops/transcribe.js +20 -40
- package/dist/server/bare/ops/translate.d.ts +1 -1
- package/dist/server/bare/ops/translate.js +5 -9
- package/dist/server/bare/ops/unload-model.d.ts +1 -1
- package/dist/server/bare/ops/unload-model.js +5 -5
- package/dist/server/bare/plugins/asr-ggml/config.d.ts +32 -0
- package/dist/server/bare/plugins/asr-ggml/config.js +46 -0
- package/dist/server/bare/plugins/asr-ggml/logging.d.ts +11 -0
- package/dist/server/bare/plugins/asr-ggml/logging.js +12 -0
- package/dist/server/bare/plugins/audiogen-ggml/config.d.ts +18 -0
- package/dist/server/bare/plugins/audiogen-ggml/config.js +23 -0
- package/dist/server/bare/plugins/audiogen-ggml/ops/audio-gen-stream.d.ts +3 -0
- package/dist/server/bare/plugins/audiogen-ggml/ops/audio-gen-stream.js +162 -0
- package/dist/server/bare/plugins/audiogen-ggml/plugin.d.ts +213 -0
- package/dist/server/bare/plugins/audiogen-ggml/plugin.js +58 -0
- package/dist/server/bare/plugins/bci-whispercpp-transcription/plugin.d.ts +6 -4
- package/dist/server/bare/plugins/bci-whispercpp-transcription/plugin.js +4 -4
- package/dist/server/bare/plugins/bci-whispercpp-transcription/resolve-config.d.ts +1 -1
- package/dist/server/bare/plugins/ggml-classification/ops/classify.d.ts +1 -1
- package/dist/server/bare/plugins/ggml-classification/ops/classify.js +1 -1
- package/dist/server/bare/plugins/ggml-classification/plugin.d.ts +2 -2
- package/dist/server/bare/plugins/ggml-classification/plugin.js +1 -1
- package/dist/server/bare/plugins/ggml-ocr/ops/ocr-stream.d.ts +1 -1
- package/dist/server/bare/plugins/ggml-ocr/ops/ocr-stream.js +2 -2
- package/dist/server/bare/plugins/ggml-ocr/plugin.d.ts +4 -2
- package/dist/server/bare/plugins/ggml-ocr/plugin.js +3 -3
- package/dist/server/bare/plugins/ggml-ocr/resolve-config.d.ts +1 -1
- package/dist/server/bare/plugins/ggml-vla/ops/vla-hparams.d.ts +1 -1
- package/dist/server/bare/plugins/ggml-vla/ops/vla-hparams.js +1 -1
- package/dist/server/bare/plugins/ggml-vla/ops/vla-run.d.ts +1 -1
- package/dist/server/bare/plugins/ggml-vla/ops/vla-run.js +1 -1
- package/dist/server/bare/plugins/ggml-vla/plugin.d.ts +3 -3
- package/dist/server/bare/plugins/index.d.ts +12 -11
- package/dist/server/bare/plugins/index.js +1 -0
- package/dist/server/bare/plugins/llamacpp-completion/ops/batch-completion-stream.d.ts +3 -3
- package/dist/server/bare/plugins/llamacpp-completion/ops/batch-completion-stream.js +5 -5
- package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stats.d.ts +11 -1
- package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stats.js +16 -0
- package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.d.ts +3 -3
- package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.js +16 -14
- package/dist/server/bare/plugins/llamacpp-completion/ops/finetune.d.ts +1 -1
- package/dist/server/bare/plugins/llamacpp-completion/ops/finetune.js +3 -3
- package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-session.d.ts +20 -10
- package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-session.js +217 -80
- package/dist/server/bare/plugins/llamacpp-completion/plugin.d.ts +12 -5
- package/dist/server/bare/plugins/llamacpp-completion/plugin.js +16 -16
- package/dist/server/bare/plugins/llamacpp-completion/transform.d.ts +1 -1
- package/dist/server/bare/plugins/llamacpp-embedding/plugin.d.ts +2 -2
- package/dist/server/bare/plugins/llamacpp-embedding/plugin.js +5 -5
- package/dist/server/bare/plugins/nmtcpp-translation/plugin.d.ts +12 -2
- package/dist/server/bare/plugins/nmtcpp-translation/plugin.js +3 -3
- package/dist/server/bare/plugins/nmtcpp-translation/resolve-vocab.d.ts +1 -1
- package/dist/server/bare/plugins/parakeet-transcription/plugin.d.ts +6 -6
- package/dist/server/bare/plugins/parakeet-transcription/plugin.js +13 -20
- package/dist/server/bare/plugins/sdcpp-generation/ops/diffusion.d.ts +1 -1
- package/dist/server/bare/plugins/sdcpp-generation/ops/diffusion.js +1 -1
- package/dist/server/bare/plugins/sdcpp-generation/ops/upscale.d.ts +1 -1
- package/dist/server/bare/plugins/sdcpp-generation/ops/upscale.js +1 -1
- package/dist/server/bare/plugins/sdcpp-generation/ops/video.d.ts +2 -1
- package/dist/server/bare/plugins/sdcpp-generation/ops/video.js +13 -7
- package/dist/server/bare/plugins/sdcpp-generation/plugin.d.ts +26 -4
- package/dist/server/bare/plugins/sdcpp-generation/plugin.js +18 -4
- package/dist/server/bare/plugins/tts-ggml/ops/parler-options.d.ts +7 -0
- package/dist/server/bare/plugins/tts-ggml/ops/parler-options.js +30 -0
- package/dist/server/bare/plugins/tts-ggml/ops/text-to-speech-stream.d.ts +2 -2
- package/dist/server/bare/plugins/tts-ggml/ops/text-to-speech-stream.js +8 -5
- package/dist/server/bare/plugins/tts-ggml/ops/text-to-speech.d.ts +2 -2
- package/dist/server/bare/plugins/tts-ggml/ops/text-to-speech.js +14 -6
- package/dist/server/bare/plugins/tts-ggml/plugin.d.ts +114 -5
- package/dist/server/bare/plugins/tts-ggml/plugin.js +61 -5
- package/dist/server/bare/plugins/whispercpp-transcription/plugin.d.ts +8 -6
- package/dist/server/bare/plugins/whispercpp-transcription/plugin.js +17 -25
- package/dist/server/bare/rag-hyperdb/handlers/chunk.d.ts +1 -1
- package/dist/server/bare/rag-hyperdb/handlers/close-workspace.d.ts +1 -1
- package/dist/server/bare/rag-hyperdb/handlers/close-workspace.js +1 -1
- package/dist/server/bare/rag-hyperdb/handlers/delete-embeddings.d.ts +1 -1
- package/dist/server/bare/rag-hyperdb/handlers/delete-embeddings.js +1 -1
- package/dist/server/bare/rag-hyperdb/handlers/delete-workspace.d.ts +1 -1
- package/dist/server/bare/rag-hyperdb/handlers/delete-workspace.js +1 -1
- package/dist/server/bare/rag-hyperdb/handlers/ingest.d.ts +1 -1
- package/dist/server/bare/rag-hyperdb/handlers/ingest.js +2 -2
- package/dist/server/bare/rag-hyperdb/handlers/list-workspaces.d.ts +1 -1
- package/dist/server/bare/rag-hyperdb/handlers/list-workspaces.js +1 -1
- package/dist/server/bare/rag-hyperdb/handlers/reindex.d.ts +1 -1
- package/dist/server/bare/rag-hyperdb/handlers/reindex.js +1 -1
- package/dist/server/bare/rag-hyperdb/handlers/save-embeddings.d.ts +1 -1
- package/dist/server/bare/rag-hyperdb/handlers/save-embeddings.js +1 -1
- package/dist/server/bare/rag-hyperdb/handlers/search.d.ts +1 -1
- package/dist/server/bare/rag-hyperdb/handlers/search.js +2 -2
- package/dist/server/bare/rag-hyperdb/index.d.ts +11 -11
- package/dist/server/bare/rag-hyperdb/index.js +11 -11
- package/dist/server/bare/rag-hyperdb/rag-operation-manager.js +1 -1
- package/dist/server/bare/rag-hyperdb/rag-workspace-manager.js +4 -4
- package/dist/server/bare/registry/config-registry.d.ts +1 -1
- package/dist/server/bare/registry/config-registry.js +1 -1
- package/dist/server/bare/registry/model-config-registry.d.ts +2 -2
- package/dist/server/bare/registry/model-config-registry.js +4 -4
- package/dist/server/bare/registry/model-config-utils.d.ts +1 -1
- package/dist/server/bare/registry/model-config-utils.js +3 -0
- package/dist/server/bare/registry/model-registry.d.ts +15 -4
- package/dist/server/bare/registry/registry-client.js +2 -2
- package/dist/server/bare/registry/runtime-context-registry.d.ts +1 -1
- package/dist/server/bare/resources/collector.d.ts +644 -0
- package/dist/server/bare/resources/collector.js +226 -0
- package/dist/server/bare/resources/native.d.ts +3 -0
- package/dist/server/bare/resources/native.js +35 -0
- package/dist/server/bare/resources/normalize.d.ts +13 -0
- package/dist/server/bare/resources/normalize.js +73 -0
- package/dist/server/bare/resources/types.d.ts +66 -0
- package/dist/server/bare/resources/types.js +1 -0
- package/dist/server/bare/resources/worker-collector.d.ts +5 -0
- package/dist/server/bare/resources/worker-collector.js +15 -0
- package/dist/server/bare/runtime/index.d.ts +7 -7
- package/dist/server/bare/runtime/index.js +3 -3
- package/dist/server/bare/runtime/request-context.d.ts +2 -2
- package/dist/server/bare/runtime/request-registry-singleton.d.ts +1 -1
- package/dist/server/bare/runtime/request-registry-singleton.js +11 -1
- package/dist/server/bare/runtime/request-registry.d.ts +2 -2
- package/dist/server/bare/runtime/request-registry.js +1 -1
- package/dist/server/bare/runtime/with-request-context.d.ts +1 -1
- package/dist/server/bare/runtime-lifecycle.d.ts +1 -1
- package/dist/server/bare/types/addon-responses.d.ts +6 -34
- package/dist/server/bare/utils/asr-events.d.ts +15 -0
- package/dist/server/bare/utils/asr-events.js +30 -0
- package/dist/server/bare/utils/audio-input.d.ts +1 -1
- package/dist/server/bare/utils/audio-input.js +1 -1
- package/dist/server/bare/utils/transcribe-metadata.d.ts +1 -1
- package/dist/server/bare/utils/tts-stats.d.ts +1 -1
- package/dist/server/error-handlers.d.ts +1 -1
- package/dist/server/plugins/index.d.ts +1 -1
- package/dist/server/plugins/registry.d.ts +1 -1
- package/dist/server/plugins/registry.js +35 -8
- package/dist/server/rpc/delegate-transport.d.ts +2 -2
- package/dist/server/rpc/delegate-transport.js +5 -10
- package/dist/server/rpc/handle-request.js +3 -3
- package/dist/server/rpc/handler-registry.d.ts +1 -1
- package/dist/server/rpc/handler-registry.js +41 -37
- package/dist/server/rpc/handler-selection.d.ts +2 -2
- package/dist/server/rpc/handler-utils.d.ts +2 -2
- package/dist/server/rpc/handler-utils.js +5 -5
- package/dist/server/rpc/handlers/audio-gen-stream.d.ts +3 -0
- package/dist/server/rpc/handlers/audio-gen-stream.js +4 -0
- package/dist/server/rpc/handlers/batch-completion-stream.d.ts +3 -1
- package/dist/server/rpc/handlers/batch-completion-stream.js +1 -1
- package/dist/server/rpc/handlers/bci-transcribe-stream.d.ts +1 -1
- package/dist/server/rpc/handlers/bci-transcribe-stream.js +1 -1
- package/dist/server/rpc/handlers/bci-transcribe.d.ts +1 -1
- package/dist/server/rpc/handlers/bci-transcribe.js +1 -1
- package/dist/server/rpc/handlers/cancel-delegated.d.ts +2 -2
- package/dist/server/rpc/handlers/cancel-delegated.js +3 -3
- package/dist/server/rpc/handlers/cancelHandler.d.ts +1 -1
- package/dist/server/rpc/handlers/cancelHandler.js +3 -3
- package/dist/server/rpc/handlers/classify.d.ts +1 -1
- package/dist/server/rpc/handlers/classify.js +1 -1
- package/dist/server/rpc/handlers/completion-orchestrate.d.ts +2 -2
- package/dist/server/rpc/handlers/completion-orchestrate.js +1 -1
- package/dist/server/rpc/handlers/completion-stream-delegated.d.ts +2 -2
- package/dist/server/rpc/handlers/completion-stream-delegated.js +3 -3
- package/dist/server/rpc/handlers/completion-stream.d.ts +1 -1
- package/dist/server/rpc/handlers/completion-stream.js +1 -1
- package/dist/server/rpc/handlers/delete-cache.d.ts +1 -1
- package/dist/server/rpc/handlers/delete-cache.js +1 -1
- package/dist/server/rpc/handlers/diffusion-stream.d.ts +1 -1
- package/dist/server/rpc/handlers/diffusion-stream.js +1 -1
- package/dist/server/rpc/handlers/download-asset.d.ts +1 -1
- package/dist/server/rpc/handlers/download-asset.js +4 -4
- package/dist/server/rpc/handlers/embed.d.ts +1 -1
- package/dist/server/rpc/handlers/embed.js +1 -1
- package/dist/server/rpc/handlers/finetune.d.ts +1 -1
- package/dist/server/rpc/handlers/finetune.js +2 -2
- package/dist/server/rpc/handlers/get-loaded-model-info.d.ts +1 -1
- package/dist/server/rpc/handlers/get-loaded-model-info.js +3 -3
- package/dist/server/rpc/handlers/get-model-info.d.ts +1 -1
- package/dist/server/rpc/handlers/get-model-info.js +4 -4
- package/dist/server/rpc/handlers/get-system-resources.d.ts +3 -0
- package/dist/server/rpc/handlers/get-system-resources.js +53 -0
- package/dist/server/rpc/handlers/heartbeat-delegated.d.ts +2 -2
- package/dist/server/rpc/handlers/heartbeat-delegated.js +2 -2
- package/dist/server/rpc/handlers/heartbeat.d.ts +1 -1
- package/dist/server/rpc/handlers/index.d.ts +37 -33
- package/dist/server/rpc/handlers/index.js +4 -0
- package/dist/server/rpc/handlers/load-model/download-manager.d.ts +3 -3
- package/dist/server/rpc/handlers/load-model/download-manager.js +1 -1
- package/dist/server/rpc/handlers/load-model/download-stats.d.ts +3 -3
- package/dist/server/rpc/handlers/load-model/handler.d.ts +1 -1
- package/dist/server/rpc/handlers/load-model/handler.js +12 -8
- package/dist/server/rpc/handlers/load-model/http.d.ts +2 -2
- package/dist/server/rpc/handlers/load-model/http.js +4 -4
- package/dist/server/rpc/handlers/load-model/hyperdrive.d.ts +2 -2
- package/dist/server/rpc/handlers/load-model/hyperdrive.js +5 -5
- package/dist/server/rpc/handlers/load-model/index.d.ts +2 -2
- package/dist/server/rpc/handlers/load-model/registry-client-options.d.ts +1 -1
- package/dist/server/rpc/handlers/load-model/registry-companion-set.d.ts +3 -3
- package/dist/server/rpc/handlers/load-model/registry-companion-set.js +3 -3
- package/dist/server/rpc/handlers/load-model/registry-download-utils.d.ts +4 -4
- package/dist/server/rpc/handlers/load-model/registry-download-utils.js +3 -3
- package/dist/server/rpc/handlers/load-model/registry-metadata.d.ts +1 -1
- package/dist/server/rpc/handlers/load-model/registry.d.ts +3 -3
- package/dist/server/rpc/handlers/load-model/registry.js +6 -6
- package/dist/server/rpc/handlers/load-model/resolve-session.d.ts +2 -2
- package/dist/server/rpc/handlers/load-model/resolve-session.js +3 -3
- package/dist/server/rpc/handlers/load-model/resolve.d.ts +2 -2
- package/dist/server/rpc/handlers/load-model/resolve.js +2 -2
- package/dist/server/rpc/handlers/load-model/types.d.ts +2 -2
- package/dist/server/rpc/handlers/load-model-delegated.d.ts +2 -2
- package/dist/server/rpc/handlers/load-model-delegated.js +3 -3
- package/dist/server/rpc/handlers/logging-stream.d.ts +1 -1
- package/dist/server/rpc/handlers/logging-stream.js +1 -1
- package/dist/server/rpc/handlers/ocr-stream.d.ts +1 -1
- package/dist/server/rpc/handlers/ocr-stream.js +1 -1
- package/dist/server/rpc/handlers/plugin-dispatch.js +3 -3
- package/dist/server/rpc/handlers/plugin-invoke.d.ts +1 -1
- package/dist/server/rpc/handlers/plugin-invoke.js +3 -3
- package/dist/server/rpc/handlers/provideHandler/connection.js +1 -1
- package/dist/server/rpc/handlers/provideHandler/handler.d.ts +1 -1
- package/dist/server/rpc/handlers/provideHandler/handler.js +1 -1
- package/dist/server/rpc/handlers/provideHandler/proxy.js +1 -1
- package/dist/server/rpc/handlers/provideHandler.d.ts +1 -1
- package/dist/server/rpc/handlers/rag.d.ts +1 -1
- package/dist/server/rpc/handlers/rag.js +4 -4
- package/dist/server/rpc/handlers/registry.d.ts +1 -1
- package/dist/server/rpc/handlers/registry.js +1 -1
- package/dist/server/rpc/handlers/resume.d.ts +1 -1
- package/dist/server/rpc/handlers/resume.js +1 -1
- package/dist/server/rpc/handlers/state.d.ts +1 -1
- package/dist/server/rpc/handlers/state.js +1 -1
- package/dist/server/rpc/handlers/stopProvideHandler.d.ts +1 -1
- package/dist/server/rpc/handlers/stopProvideHandler.js +1 -1
- package/dist/server/rpc/handlers/suspend.d.ts +1 -1
- package/dist/server/rpc/handlers/suspend.js +1 -1
- package/dist/server/rpc/handlers/text-to-speech-stream.d.ts +1 -1
- package/dist/server/rpc/handlers/text-to-speech-stream.js +1 -1
- package/dist/server/rpc/handlers/text-to-speech.d.ts +1 -1
- package/dist/server/rpc/handlers/text-to-speech.js +1 -1
- package/dist/server/rpc/handlers/transcribe-stream.d.ts +1 -1
- package/dist/server/rpc/handlers/transcribe-stream.js +1 -1
- package/dist/server/rpc/handlers/transcribe.d.ts +1 -1
- package/dist/server/rpc/handlers/transcribe.js +1 -1
- package/dist/server/rpc/handlers/translate.d.ts +1 -1
- package/dist/server/rpc/handlers/translate.js +1 -1
- package/dist/server/rpc/handlers/unload-model-delegated.d.ts +1 -1
- package/dist/server/rpc/handlers/unload-model-delegated.js +5 -5
- package/dist/server/rpc/handlers/unload-model.d.ts +1 -1
- package/dist/server/rpc/handlers/unload-model.js +3 -3
- package/dist/server/rpc/handlers/upscale-stream.d.ts +1 -1
- package/dist/server/rpc/handlers/upscale-stream.js +1 -1
- package/dist/server/rpc/handlers/video-stream.d.ts +1 -1
- package/dist/server/rpc/handlers/video-stream.js +1 -1
- package/dist/server/rpc/index.d.ts +2 -2
- package/dist/server/rpc/method-shapes.d.ts +2 -0
- package/dist/server/rpc/method-shapes.js +2 -0
- package/dist/server/rpc/profiling/backend-diagnostics.d.ts +3 -0
- package/dist/server/rpc/profiling/backend-diagnostics.js +16 -0
- package/dist/server/rpc/profiling/context.d.ts +1 -1
- package/dist/server/rpc/profiling/delegation-profiler.d.ts +2 -2
- package/dist/server/rpc/profiling/index.d.ts +4 -4
- package/dist/server/rpc/profiling/operation-metrics.d.ts +2 -2
- package/dist/server/rpc/profiling/operation-metrics.js +9 -1
- package/dist/server/rpc/profiling/operation-wrappers.d.ts +1 -1
- package/dist/server/rpc/profiling/operation-wrappers.js +51 -13
- package/dist/server/rpc/profiling/profiler.d.ts +2 -2
- package/dist/server/rpc/transport-selector.d.ts +1 -1
- package/dist/server/utils/archive.js +1 -1
- package/dist/server/utils/audio/decoder.d.ts +1 -1
- package/dist/server/utils/audio/decoder.js +1 -1
- package/dist/server/utils/cache/auto-history.d.ts +1 -1
- package/dist/server/utils/cache/paths.d.ts +1 -1
- package/dist/server/utils/cache/paths.js +6 -6
- package/dist/server/utils/checksum.d.ts +1 -1
- package/dist/server/utils/completion-normalizer.d.ts +2 -1
- package/dist/server/utils/completion-normalizer.js +31 -1
- package/dist/server/utils/config-transform.d.ts +1 -1
- package/dist/server/utils/config-transform.js +5 -7
- package/dist/server/utils/index.d.ts +11 -11
- package/dist/server/utils/path-security.d.ts +1 -1
- package/dist/server/utils/qvac-paths.js +1 -1
- package/dist/server/utils/response-format.d.ts +1 -1
- package/dist/server/utils/shard-utils.d.ts +1 -1
- package/dist/server/utils/tool-integration.d.ts +1 -1
- package/dist/server/utils/tool-integration.js +2 -2
- package/dist/server/utils/tools/dialect.d.ts +1 -1
- package/dist/server/utils/tools/dialect.js +2 -0
- package/dist/server/utils/tools/index.d.ts +2 -2
- package/dist/server/utils/tools/parser.d.ts +1 -1
- package/dist/server/utils/tools/parser.js +16 -8
- package/dist/server/utils/tools/parsers/dsml.d.ts +4 -0
- package/dist/server/utils/tools/parsers/dsml.js +176 -0
- package/dist/server/utils/tools/parsers/gemma4native.d.ts +2 -2
- package/dist/server/utils/tools/parsers/gemma4native.js +1 -1
- package/dist/server/utils/tools/parsers/harmony.d.ts +2 -2
- package/dist/server/utils/tools/parsers/harmony.js +1 -1
- package/dist/server/utils/tools/parsers/hermes.d.ts +2 -2
- package/dist/server/utils/tools/parsers/hermes.js +1 -1
- package/dist/server/utils/tools/parsers/json.d.ts +2 -2
- package/dist/server/utils/tools/parsers/json.js +1 -1
- package/dist/server/utils/tools/parsers/pythonic.d.ts +2 -2
- package/dist/server/utils/tools/parsers/pythonic.js +1 -1
- package/dist/server/utils/tools/parsers/qwen35.d.ts +2 -2
- package/dist/server/utils/tools/parsers/qwen35.js +1 -1
- package/dist/server/utils/tools/shared.d.ts +1 -1
- package/dist/server/utils/worker-lock.js +1 -1
- package/dist/server/worker-core.js +14 -10
- package/dist/server/worker.js +4 -3
- package/dist/utils/aggregate-events.d.ts +2 -2
- package/dist/utils/aggregate-events.js +2 -2
- package/dist/utils/errors-client.d.ts +0 -3
- package/dist/utils/errors-client.js +0 -5
- package/dist/utils/errors-server.d.ts +1 -1
- package/dist/utils/mcp-adapter.d.ts +4 -4
- package/dist/utils/mcp-adapter.js +1 -1
- package/dist/utils/tool-helpers.d.ts +1 -1
- package/dist/utils/tool-helpers.js +1 -1
- package/docs/system-resources-support-matrix.md +103 -0
- package/package.json +33 -18
- /package/dist/examples/{transcription → asr}/parakeet-ctc-filesystem.d.ts +0 -0
- /package/dist/examples/{transcription → asr}/parakeet-microphone-record.d.ts +0 -0
- /package/dist/examples/{transcription → asr}/parakeet-microphone-stream.d.ts +0 -0
- /package/dist/examples/{transcription → asr}/parakeet-sortformer-streaming.d.ts +0 -0
- /package/dist/examples/{transcription → asr}/parakeet-sortformer.d.ts +0 -0
- /package/dist/examples/{transcription → asr}/parakeet-tdt-filesystem-chunked.d.ts +0 -0
- /package/dist/examples/{transcription → asr}/parakeet-tdt-filesystem.d.ts +0 -0
- /package/dist/examples/{transcription → asr}/whispercpp-filesystem-streaming.d.ts +0 -0
- /package/dist/examples/{transcription → asr}/whispercpp-filesystem.d.ts +0 -0
- /package/dist/examples/{transcription → asr}/whispercpp-microphone-conversation.d.ts +0 -0
- /package/dist/examples/{transcription → asr}/whispercpp-microphone-record.d.ts +0 -0
- /package/dist/examples/{transcription → asr}/whispercpp-prompt.d.ts +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AbortSignal } from 'bare-abort-controller';
|
|
2
|
-
import type { CompletionParams, CompletionStats, GenerationParams, ResponseFormat, Tool, ToolCall, ToolDialect } from '../../../../../schemas/index';
|
|
3
|
-
import type { DisposableScope } from '
|
|
4
|
-
import type { Logger } from '../../../../../logging/types';
|
|
2
|
+
import type { CompletionParams, CompletionStats, GenerationParams, ResponseFormat, Tool, ToolCall, ToolDialect } from '../../../../../schemas/index.js';
|
|
3
|
+
import type { DisposableScope } from '../../../../../server/bare/runtime/disposable-scope.js';
|
|
4
|
+
import type { Logger } from '../../../../../logging/types.js';
|
|
5
5
|
interface CompletionResult {
|
|
6
6
|
modelExecutionMs: number;
|
|
7
7
|
stats?: CompletionStats;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { TOOLS_MODE } from '../../../../../schemas/tools.js';
|
|
2
|
-
import { logCacheDisabled, logCacheInit, logCacheSave, logMessagesToAddon } from '
|
|
3
|
-
import { extractSystemPrompt, getCurrentCacheInfo } from '
|
|
4
|
-
import { getModel, getModelConfig } from '
|
|
5
|
-
import { decideCachedHistorySlice, shouldCommitCachedTurn } from '
|
|
6
|
-
import { createKvCacheSession, generateConfigHash } from '
|
|
7
|
-
import { appendToolsToHistory, detectToolDialect, prependToolsToHistory } from '
|
|
8
|
-
import { parseToolCalls } from '
|
|
9
|
-
import { getResponseFormatJsonSchema } from '
|
|
10
|
-
import { buildAutoCacheSaveHistory } from '
|
|
2
|
+
import { logCacheDisabled, logCacheInit, logCacheSave, logMessagesToAddon } from '../../../../../server/bare/plugins/llamacpp-completion/ops/cache-logger.js';
|
|
3
|
+
import { extractSystemPrompt, getCurrentCacheInfo } from '../../../../../server/bare/ops/kv-cache-utils.js';
|
|
4
|
+
import { getModel, getModelConfig } from '../../../../../server/bare/registry/model-registry.js';
|
|
5
|
+
import { decideCachedHistorySlice, shouldCommitCachedTurn } from '../../../../../server/bare/plugins/llamacpp-completion/ops/kv-cache-state.js';
|
|
6
|
+
import { createKvCacheSession, generateConfigHash } from '../../../../../server/bare/plugins/llamacpp-completion/ops/kv-cache-session.js';
|
|
7
|
+
import { appendToolsToHistory, detectToolDialect, prependToolsToHistory } from '../../../../../server/utils/tool-integration.js';
|
|
8
|
+
import { parseToolCalls } from '../../../../../server/utils/tools/index.js';
|
|
9
|
+
import { getResponseFormatJsonSchema } from '../../../../../server/utils/response-format.js';
|
|
10
|
+
import { buildAutoCacheSaveHistory } from '../../../../../server/utils/index.js';
|
|
11
11
|
import { getServerLogger } from '../../../../../logging/index.js';
|
|
12
12
|
import { AttachmentNotFoundError } from '../../../../../utils/errors-server.js';
|
|
13
13
|
import { nowMs } from '../../../../../profiling/index.js';
|
|
14
14
|
import { buildStreamResult } from '../../../../../profiling/model-execution.js';
|
|
15
|
-
import { normalizeCompletionStats } from '
|
|
15
|
+
import { normalizeCompletionStats, withEmittedTokens } from '../../../../../server/bare/plugins/llamacpp-completion/ops/completion-stats.js';
|
|
16
16
|
import fs from 'bare-fs';
|
|
17
17
|
const logger = getServerLogger();
|
|
18
18
|
function transformMessage(message) {
|
|
@@ -47,8 +47,7 @@ function transformMessage(message) {
|
|
|
47
47
|
return transformed;
|
|
48
48
|
}
|
|
49
49
|
function runModel(model, prompt, opts) {
|
|
50
|
-
|
|
51
|
-
return run(prompt, opts);
|
|
50
|
+
return model.run(prompt, opts);
|
|
52
51
|
}
|
|
53
52
|
export function transformMessages(messages) {
|
|
54
53
|
const transformed = [];
|
|
@@ -161,11 +160,14 @@ async function* processModelResponse(model, messagesToSend, tools, generationPar
|
|
|
161
160
|
const response = await runModel(model, messagesToSend, hasRunOptions ? runOptions : undefined);
|
|
162
161
|
let accumulatedText = '';
|
|
163
162
|
let producedTokens = false;
|
|
163
|
+
let emittedPieces = 0;
|
|
164
164
|
let toolCallsResult = [];
|
|
165
165
|
for await (const token of response.iterate()) {
|
|
166
166
|
const tokenStr = token;
|
|
167
|
-
if (tokenStr.length > 0)
|
|
167
|
+
if (tokenStr.length > 0) {
|
|
168
168
|
producedTokens = true;
|
|
169
|
+
emittedPieces++;
|
|
170
|
+
}
|
|
169
171
|
accumulatedText += tokenStr;
|
|
170
172
|
yield { token: tokenStr };
|
|
171
173
|
}
|
|
@@ -178,7 +180,7 @@ async function* processModelResponse(model, messagesToSend, tools, generationPar
|
|
|
178
180
|
toolCallsResult = toolCalls;
|
|
179
181
|
}
|
|
180
182
|
const responseWithStats = response;
|
|
181
|
-
const stats = normalizeCompletionStats(responseWithStats.stats);
|
|
183
|
+
const stats = withEmittedTokens(normalizeCompletionStats(responseWithStats.stats), emittedPieces);
|
|
182
184
|
return {
|
|
183
185
|
...buildStreamResult(modelExecutionMs, stats),
|
|
184
186
|
toolCalls: toolCallsResult,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FinetuneRunParams, FinetuneRunRequest, FinetuneProgress, FinetuneRequest, FinetuneResult, FinetuneStatus, FinetuneGetStateRequest } from '../../../../../schemas/index';
|
|
1
|
+
import type { FinetuneRunParams, FinetuneRunRequest, FinetuneProgress, FinetuneRequest, FinetuneResult, FinetuneStatus, FinetuneGetStateRequest } from '../../../../../schemas/index.js';
|
|
2
2
|
type FinetuneOptions = FinetuneRunParams['options'];
|
|
3
3
|
export declare function clearFinetuneRuntimeState(modelId: string): void;
|
|
4
4
|
export declare function getFinetuneStateFromCheckpoints(options: FinetuneOptions): FinetuneStatus;
|
|
@@ -51,10 +51,10 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
51
51
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
52
|
});
|
|
53
53
|
import fs from 'bare-fs';
|
|
54
|
-
import { getModel } from '
|
|
54
|
+
import { getModel } from '../../../../../server/bare/registry/model-registry.js';
|
|
55
55
|
import { CompletionFailedError } from '../../../../../utils/errors-server.js';
|
|
56
|
-
import { getRequestRegistry, withRequestContext } from '
|
|
57
|
-
import { generateServerRequestId } from '
|
|
56
|
+
import { getRequestRegistry, withRequestContext } from '../../../../../server/bare/runtime/index.js';
|
|
57
|
+
import { generateServerRequestId } from '../../../../../server/bare/runtime/request-id.js';
|
|
58
58
|
import { getServerLogger } from '../../../../../logging/index.js';
|
|
59
59
|
const PAUSE_CHECKPOINT_PREFIX = 'pause_checkpoint_step_';
|
|
60
60
|
const finetuneRuntimeState = new Set();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { generateConfigHash } from '
|
|
2
|
-
import type
|
|
3
|
-
import type { Logger } from '../../../../../logging/types';
|
|
1
|
+
import { generateConfigHash } from '../../../../../server/bare/ops/kv-cache-utils.js';
|
|
2
|
+
import { type CacheMessage } from '../../../../../server/utils/index.js';
|
|
3
|
+
import type { Logger } from '../../../../../logging/types.js';
|
|
4
4
|
export interface TurnHandle {
|
|
5
5
|
/** Resolved on-disk cache file path the addon will read from / write to. */
|
|
6
6
|
readonly cachePath: string;
|
|
@@ -59,7 +59,8 @@ export interface KvCacheSession {
|
|
|
59
59
|
* primes the system-prompt cache if needed (delegated to
|
|
60
60
|
* `input.primeIfMissing`), marks the cache initialized, and returns a
|
|
61
61
|
* `TurnHandle` the handler attaches to `ctx.scope.defer(...)` for the
|
|
62
|
-
* rollback hook.
|
|
62
|
+
* rollback hook. Auto-cache path resolution is serialized with
|
|
63
|
+
* retention deletion before the handle is returned.
|
|
63
64
|
*/
|
|
64
65
|
beginTurn(input: BeginTurnInput): Promise<TurnHandle>;
|
|
65
66
|
/**
|
|
@@ -72,12 +73,13 @@ export interface KvCacheSession {
|
|
|
72
73
|
commitTurn(turn: TurnHandle, result: CommitResult): Promise<void>;
|
|
73
74
|
/**
|
|
74
75
|
* Roll back an in-flight turn — atomically deletes the on-disk cache
|
|
75
|
-
* file, clears the in-memory `initializedCaches` entry,
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* or rolled back is a no-op on subsequent
|
|
79
|
-
* this via `ctx.scope.defer(...)` so it
|
|
80
|
-
* handler exits (success branch removes
|
|
76
|
+
* file, clears the in-memory `initializedCaches` entry, forgets the
|
|
77
|
+
* `cachedMessageCounts` entry, releases the active-path ref, and
|
|
78
|
+
* removes orphaned marker metadata. Idempotent: a turn that has
|
|
79
|
+
* already been committed or rolled back is a no-op on subsequent
|
|
80
|
+
* calls. Handlers register this via `ctx.scope.defer(...)` so it
|
|
81
|
+
* runs regardless of how the handler exits (success branch removes
|
|
82
|
+
* itself via `commitTurn`).
|
|
81
83
|
*/
|
|
82
84
|
rollback(turn: TurnHandle): Promise<void>;
|
|
83
85
|
/**
|
|
@@ -148,7 +150,15 @@ export declare const __kvCacheSessionTestHooks: {
|
|
|
148
150
|
setSavedCountForTest(cachePath: string, count: number): void;
|
|
149
151
|
hasInitializedKey(modelId: string, configHash: string, cacheKey: string): boolean;
|
|
150
152
|
markInitializedForTest(modelId: string, configHash: string, cacheKey: string): void;
|
|
153
|
+
getLastAutoCacheSweepMsForTest(): number;
|
|
154
|
+
setLastAutoCacheSweepMsForTest(value: number): void;
|
|
151
155
|
resetForTest(): void;
|
|
156
|
+
waitForAutoCacheSweepForTest(): Promise<void>;
|
|
157
|
+
sweepAutoCachesForTest(options: {
|
|
158
|
+
maxBytes: number;
|
|
159
|
+
maxIdleMs: number;
|
|
160
|
+
nowMs: number;
|
|
161
|
+
}): Promise<void>;
|
|
152
162
|
};
|
|
153
163
|
export { generateConfigHash };
|
|
154
164
|
//# sourceMappingURL=kv-cache-session.d.ts.map
|
|
@@ -1,54 +1,27 @@
|
|
|
1
1
|
import { promises as fsPromises } from 'bare-fs';
|
|
2
2
|
import path from 'bare-path';
|
|
3
|
-
import { findMatchingCache, generateConfigHash, getCacheFilePath, getCurrentCacheInfo, renameCacheFile, deleteCache as deleteCacheUtil } from '
|
|
4
|
-
import {
|
|
3
|
+
import { findMatchingCache, generateConfigHash, getCacheFilePath, getCurrentCacheInfo, pruneEmptyCacheDirectories, renameCacheFile, deleteCache as deleteCacheUtil } from '../../../../../server/bare/ops/kv-cache-utils.js';
|
|
4
|
+
import { isCachePathWithinDirectory, markAutoCacheKey, planAutoCacheEvictions, removeAutoCacheMarker, removeAutoCacheMarkerIfMissing } from '../../../../../server/bare/ops/kv-cache-retention.js';
|
|
5
|
+
import { isMobile } from '../../../../../server/bare/registry/runtime-context-registry.js';
|
|
6
|
+
import { getKVCacheDir } from '../../../../../server/utils/index.js';
|
|
7
|
+
import { logCacheSaveError, logCacheStatus } from '../../../../../server/bare/plugins/llamacpp-completion/ops/cache-logger.js';
|
|
5
8
|
import { getServerLogger } from '../../../../../logging/index.js';
|
|
6
9
|
// Used by cross-model paths that have no `RequestContext` (e.g.
|
|
7
10
|
// `deleteKvCacheState`). Per-session call sites receive a logger from
|
|
8
11
|
// the caller — typically `withRequestContext(...)`.
|
|
9
12
|
const moduleLogger = getServerLogger();
|
|
10
13
|
/**
|
|
11
|
-
*
|
|
14
|
+
* Coordinates five KV-cache state layers:
|
|
12
15
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
16
|
+
* 1. `cachedMessageCounts` — saved message boundaries.
|
|
17
|
+
* 2. `initializedCaches` — caches primed in this worker.
|
|
18
|
+
* 3. On-disk `.bin` files written by the addon.
|
|
19
|
+
* 4. `activeCachePaths` — per-path refs that block in-flight eviction.
|
|
20
|
+
* 5. `.auto-cache-<key>` markers — SDK-generated cache ownership.
|
|
15
21
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* we know this cache is primed" tracker.
|
|
20
|
-
* 3. On-disk `.bin` files written by the addon.
|
|
21
|
-
*
|
|
22
|
-
* Without a single owner, every cancel / zero-token / rename-failed /
|
|
23
|
-
* tool-call exit would need to touch all three; any branch that forgets
|
|
24
|
-
* a layer produces three-layer drift bugs.
|
|
25
|
-
*
|
|
26
|
-
* `KvCacheSession` collapses the three layers behind one object with
|
|
27
|
-
* three operations:
|
|
28
|
-
*
|
|
29
|
-
* - `beginTurn` — resolves the cache file path, primes the system
|
|
30
|
-
* prompt cache if missing (delegated to a caller-supplied closure
|
|
31
|
-
* so the session doesn't depend on the model addon), marks the
|
|
32
|
-
* cache initialized, and returns a `TurnHandle` carrying the
|
|
33
|
-
* resolved path + the snapshot of the on-disk saved count.
|
|
34
|
-
* - `commitTurn` — records the new saved count (for custom-key
|
|
35
|
-
* turns) or renames the addon's pre-response file to the
|
|
36
|
-
* post-response path and records the count there (for auto-cache
|
|
37
|
-
* turns). Flips the turn's internal `committed` flag so the
|
|
38
|
-
* deferred `rollback` becomes a no-op on the happy path.
|
|
39
|
-
* - `rollback` — atomically deletes the on-disk file, clears the
|
|
40
|
-
* in-memory init entry, and forgets the saved count. **All three
|
|
41
|
-
* layers, always, in one place.** Handlers call it once via
|
|
42
|
-
* `ctx.scope.defer(() => session.rollback(turn))`; `commitTurn`
|
|
43
|
-
* short-circuits it on success.
|
|
44
|
-
*
|
|
45
|
-
* The module-level `deleteKvCacheState(...)` function (below) provides
|
|
46
|
-
* an administrative cross-model delete API for the
|
|
47
|
-
* `handleDeleteCache` RPC handler.
|
|
48
|
-
*
|
|
49
|
-
* The module-scoped `cachedMessageCounts` and `initializedCaches` maps
|
|
50
|
-
* are *private* to this file — no other module reaches into them.
|
|
51
|
-
* Callers that need cache-status info do so through the session API.
|
|
22
|
+
* Every turn must finish through `commitTurn` or `rollback` so all
|
|
23
|
+
* inference state stays aligned, the active-path ref is released, and
|
|
24
|
+
* marker metadata follows the cache directory lifecycle.
|
|
52
25
|
*/
|
|
53
26
|
// ----- module-scoped state. The session is the single mutation point
|
|
54
27
|
// for the in-memory KV-cache bookkeeping. -----
|
|
@@ -70,9 +43,101 @@ const cachedMessageCounts = new Map();
|
|
|
70
43
|
* older worker runs still hit the lazy-load path in `beginTurn`.
|
|
71
44
|
*/
|
|
72
45
|
const initializedCaches = new Set();
|
|
46
|
+
const activeCachePaths = new Map();
|
|
47
|
+
const DESKTOP_AUTO_CACHE_MAX_BYTES = 4 * 1024 * 1024 * 1024;
|
|
48
|
+
const MOBILE_AUTO_CACHE_MAX_BYTES = 512 * 1024 * 1024;
|
|
49
|
+
const AUTO_CACHE_MAX_IDLE_MS = 24 * 60 * 60 * 1000;
|
|
50
|
+
const AUTO_CACHE_SWEEP_INTERVAL_MS = 5 * 60 * 1000;
|
|
51
|
+
let lastAutoCacheSweepMs = 0;
|
|
52
|
+
let autoCacheSweepInFlight = null;
|
|
53
|
+
let cacheStateLockTail = Promise.resolve();
|
|
73
54
|
function initRegistryKey(modelId, configHash, cacheKey) {
|
|
74
55
|
return `${modelId}:${configHash}:${cacheKey}`;
|
|
75
56
|
}
|
|
57
|
+
function markCachePathActive(cachePath) {
|
|
58
|
+
activeCachePaths.set(cachePath, (activeCachePaths.get(cachePath) ?? 0) + 1);
|
|
59
|
+
}
|
|
60
|
+
function releaseCachePath(cachePath) {
|
|
61
|
+
const count = activeCachePaths.get(cachePath);
|
|
62
|
+
if (count === undefined)
|
|
63
|
+
return;
|
|
64
|
+
if (count === 1) {
|
|
65
|
+
activeCachePaths.delete(cachePath);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
activeCachePaths.set(cachePath, count - 1);
|
|
69
|
+
}
|
|
70
|
+
function isCacheKeyActive(cacheKey) {
|
|
71
|
+
const cacheDirectory = path.join(getKVCacheDir(), cacheKey);
|
|
72
|
+
return Array.from(activeCachePaths.keys()).some((cachePath) => isCachePathWithinDirectory(cacheDirectory, cachePath));
|
|
73
|
+
}
|
|
74
|
+
function getAutoCacheMaxBytes() {
|
|
75
|
+
return isMobile() ? MOBILE_AUTO_CACHE_MAX_BYTES : DESKTOP_AUTO_CACHE_MAX_BYTES;
|
|
76
|
+
}
|
|
77
|
+
async function withCacheStateLock(operation) {
|
|
78
|
+
const previous = cacheStateLockTail;
|
|
79
|
+
let releaseLock = () => { };
|
|
80
|
+
cacheStateLockTail = new Promise((resolve) => {
|
|
81
|
+
releaseLock = resolve;
|
|
82
|
+
});
|
|
83
|
+
await previous;
|
|
84
|
+
try {
|
|
85
|
+
return await operation();
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
releaseLock();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async function maybeSweepAutoCaches(logger, overrides) {
|
|
92
|
+
const nowMs = overrides?.nowMs ?? Date.now();
|
|
93
|
+
if (autoCacheSweepInFlight !== null) {
|
|
94
|
+
await autoCacheSweepInFlight;
|
|
95
|
+
if (!overrides?.force)
|
|
96
|
+
return;
|
|
97
|
+
return maybeSweepAutoCaches(logger, overrides);
|
|
98
|
+
}
|
|
99
|
+
if (!overrides?.force && nowMs - lastAutoCacheSweepMs < AUTO_CACHE_SWEEP_INTERVAL_MS)
|
|
100
|
+
return;
|
|
101
|
+
lastAutoCacheSweepMs = nowMs;
|
|
102
|
+
const sweep = async () => {
|
|
103
|
+
try {
|
|
104
|
+
const cacheKeys = await planAutoCacheEvictions({
|
|
105
|
+
activeCachePaths: Array.from(activeCachePaths.keys()),
|
|
106
|
+
maxBytes: overrides?.maxBytes ?? getAutoCacheMaxBytes(),
|
|
107
|
+
maxIdleMs: overrides?.maxIdleMs ?? AUTO_CACHE_MAX_IDLE_MS,
|
|
108
|
+
nowMs
|
|
109
|
+
});
|
|
110
|
+
let evictionCount = 0;
|
|
111
|
+
await withCacheStateLock(async () => {
|
|
112
|
+
for (const cacheKey of cacheKeys) {
|
|
113
|
+
if (isCacheKeyActive(cacheKey))
|
|
114
|
+
continue;
|
|
115
|
+
await deleteKvCacheState({ kvCacheKey: cacheKey });
|
|
116
|
+
evictionCount++;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
if (evictionCount > 0) {
|
|
120
|
+
logger.debug(`[kv-cache] Evicted ${evictionCount} inactive auto-cache entries`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
logger.warn(`[kv-cache] Auto-cache retention sweep failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
const sweepPromise = sweep();
|
|
128
|
+
autoCacheSweepInFlight = sweepPromise;
|
|
129
|
+
try {
|
|
130
|
+
await sweepPromise;
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
autoCacheSweepInFlight = null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function scheduleAutoCacheSweep(logger) {
|
|
137
|
+
void maybeSweepAutoCaches(logger).catch((error) => {
|
|
138
|
+
logger.warn(`[kv-cache] Failed to schedule auto-cache retention sweep: ${error instanceof Error ? error.message : String(error)}`);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
76
141
|
// ----- factory -----
|
|
77
142
|
/**
|
|
78
143
|
* Construct a session bound to one `(modelId, turn-owning request)`
|
|
@@ -86,7 +151,7 @@ export function createKvCacheSession(modelId, options) {
|
|
|
86
151
|
// WeakMap so handles drop their state once the handler scope releases
|
|
87
152
|
// the reference; the module-scoped maps above survive.
|
|
88
153
|
const turnState = new WeakMap();
|
|
89
|
-
function makeHandle(cachePath, registryKey) {
|
|
154
|
+
function makeHandle(cachePath, registryKey, autoCacheKey) {
|
|
90
155
|
const handle = {
|
|
91
156
|
cachePath,
|
|
92
157
|
savedCount: cachedMessageCounts.get(cachePath) ?? 0
|
|
@@ -94,36 +159,45 @@ export function createKvCacheSession(modelId, options) {
|
|
|
94
159
|
turnState.set(handle, {
|
|
95
160
|
cachePath,
|
|
96
161
|
registryKey,
|
|
162
|
+
...(autoCacheKey !== undefined && { autoCacheKey }),
|
|
97
163
|
committed: false,
|
|
98
164
|
rolledBack: false
|
|
99
165
|
});
|
|
166
|
+
markCachePathActive(cachePath);
|
|
100
167
|
return handle;
|
|
101
168
|
}
|
|
102
169
|
async function beginCustom(input) {
|
|
103
170
|
const cachePath = await getCacheFilePath(modelId, input.configHash, input.customKey);
|
|
104
171
|
const registryKey = initRegistryKey(modelId, input.configHash, input.customKey);
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
172
|
+
const handle = makeHandle(cachePath, registryKey);
|
|
173
|
+
try {
|
|
174
|
+
// In-memory registry check first — the addon defers disk writes, so
|
|
175
|
+
// a freshly-primed cache may not yet exist on disk. If the
|
|
176
|
+
// in-memory flag isn't set, fall back to a filesystem probe so
|
|
177
|
+
// caches surviving across worker restarts still hit the reuse path.
|
|
178
|
+
let exists = initializedCaches.has(registryKey);
|
|
179
|
+
if (!exists) {
|
|
180
|
+
try {
|
|
181
|
+
await fsPromises.access(cachePath);
|
|
182
|
+
exists = true;
|
|
183
|
+
initializedCaches.add(registryKey);
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
exists = false;
|
|
187
|
+
}
|
|
115
188
|
}
|
|
116
|
-
|
|
117
|
-
|
|
189
|
+
logCacheStatus(input.customKey, exists);
|
|
190
|
+
if (!exists) {
|
|
191
|
+
await input.primeIfMissing(cachePath);
|
|
192
|
+
await verifyPrimedFile(cachePath, logger);
|
|
193
|
+
initializedCaches.add(registryKey);
|
|
118
194
|
}
|
|
195
|
+
return handle;
|
|
119
196
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
await verifyPrimedFile(cachePath, logger);
|
|
124
|
-
initializedCaches.add(registryKey);
|
|
197
|
+
catch (error) {
|
|
198
|
+
releaseCachePath(cachePath);
|
|
199
|
+
throw error;
|
|
125
200
|
}
|
|
126
|
-
return makeHandle(cachePath, registryKey);
|
|
127
201
|
}
|
|
128
202
|
async function beginAuto(input) {
|
|
129
203
|
// The pre-response cache key is derived from
|
|
@@ -131,19 +205,34 @@ export function createKvCacheSession(modelId, options) {
|
|
|
131
205
|
// internally. The post-response key (used after a successful turn)
|
|
132
206
|
// is computed by the caller and passed to `commitTurn` as
|
|
133
207
|
// `targetCachePath`.
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
208
|
+
const setup = await withCacheStateLock(async () => {
|
|
209
|
+
const existingCache = await findMatchingCache(modelId, input.configHash, input.history);
|
|
210
|
+
const cacheInfo = existingCache ?? (await getCurrentCacheInfo(modelId, input.configHash, input.history));
|
|
211
|
+
const registryKey = initRegistryKey(modelId, input.configHash, cacheInfo.cacheKey);
|
|
212
|
+
return {
|
|
213
|
+
cacheExists: existingCache !== null,
|
|
214
|
+
cachePath: cacheInfo.cachePath,
|
|
215
|
+
cacheKey: cacheInfo.cacheKey,
|
|
216
|
+
registryKey,
|
|
217
|
+
handle: makeHandle(cacheInfo.cachePath, registryKey, cacheInfo.cacheKey)
|
|
218
|
+
};
|
|
219
|
+
});
|
|
220
|
+
const { cacheExists, cachePath, cacheKey, registryKey, handle } = setup;
|
|
140
221
|
logCacheStatus('auto', cacheExists);
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
222
|
+
try {
|
|
223
|
+
if (!cacheExists) {
|
|
224
|
+
await input.primeIfMissing(cachePath);
|
|
225
|
+
await verifyPrimedFile(cachePath, logger);
|
|
226
|
+
initializedCaches.add(registryKey);
|
|
227
|
+
}
|
|
228
|
+
return handle;
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
releaseCachePath(cachePath);
|
|
232
|
+
await pruneEmptyCacheDirectories(cachePath);
|
|
233
|
+
await removeAutoCacheMarkerIfMissing(cacheKey);
|
|
234
|
+
throw error;
|
|
145
235
|
}
|
|
146
|
-
return makeHandle(cachePath, registryKey);
|
|
147
236
|
}
|
|
148
237
|
async function beginTurn(input) {
|
|
149
238
|
if (input.kind === 'custom')
|
|
@@ -174,24 +263,42 @@ export function createKvCacheSession(modelId, options) {
|
|
|
174
263
|
return;
|
|
175
264
|
}
|
|
176
265
|
state.committed = true;
|
|
266
|
+
releaseCachePath(state.cachePath);
|
|
177
267
|
return;
|
|
178
268
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
269
|
+
const sourceCachePath = state.cachePath;
|
|
270
|
+
const sourceCacheKey = state.autoCacheKey;
|
|
271
|
+
const targetCacheKey = path.basename(path.dirname(path.dirname(result.targetCachePath)));
|
|
272
|
+
const renamed = await withCacheStateLock(async () => {
|
|
273
|
+
markCachePathActive(result.targetCachePath);
|
|
274
|
+
await fsPromises.mkdir(path.dirname(result.targetCachePath), { recursive: true });
|
|
275
|
+
await markAutoCacheKey(targetCacheKey);
|
|
276
|
+
if (!(await renameCacheFile(sourceCachePath, result.targetCachePath))) {
|
|
277
|
+
releaseCachePath(result.targetCachePath);
|
|
278
|
+
await pruneEmptyCacheDirectories(result.targetCachePath);
|
|
279
|
+
await removeAutoCacheMarkerIfMissing(targetCacheKey);
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
releaseCachePath(sourceCachePath);
|
|
283
|
+
state.cachePath = result.targetCachePath;
|
|
284
|
+
state.autoCacheKey = targetCacheKey;
|
|
285
|
+
await pruneEmptyCacheDirectories(sourceCachePath);
|
|
286
|
+
if (sourceCacheKey !== undefined) {
|
|
287
|
+
await removeAutoCacheMarkerIfMissing(sourceCacheKey);
|
|
288
|
+
}
|
|
289
|
+
cachedMessageCounts.delete(sourceCachePath);
|
|
290
|
+
initializedCaches.delete(state.registryKey);
|
|
291
|
+
return true;
|
|
292
|
+
});
|
|
293
|
+
if (!renamed) {
|
|
294
|
+
logger.warn(`[kv-cache] Auto cache rename failed; rolling back. from=${sourceCachePath} to=${result.targetCachePath}`);
|
|
184
295
|
await runRollback(state);
|
|
185
296
|
return;
|
|
186
297
|
}
|
|
187
|
-
// The source path's entry is gone (the file moved). Drop it and
|
|
188
|
-
// record the new count at the rename target.
|
|
189
|
-
cachedMessageCounts.delete(state.cachePath);
|
|
190
298
|
const ok = await verifySaveAndRecord(result.targetCachePath, result.messageCount);
|
|
191
299
|
if (!ok) {
|
|
192
300
|
// Rename succeeded but the file isn't where we expected. Roll
|
|
193
301
|
// back via the target path instead of the (now-empty) source.
|
|
194
|
-
state.cachePath = result.targetCachePath;
|
|
195
302
|
await runRollback(state);
|
|
196
303
|
return;
|
|
197
304
|
}
|
|
@@ -200,6 +307,8 @@ export function createKvCacheSession(modelId, options) {
|
|
|
200
307
|
// is committed and won't roll back. Future turns compute fresh
|
|
201
308
|
// paths.
|
|
202
309
|
state.committed = true;
|
|
310
|
+
releaseCachePath(state.cachePath);
|
|
311
|
+
scheduleAutoCacheSweep(logger);
|
|
203
312
|
}
|
|
204
313
|
async function rollback(turn) {
|
|
205
314
|
const state = turnState.get(turn);
|
|
@@ -220,9 +329,16 @@ export function createKvCacheSession(modelId, options) {
|
|
|
220
329
|
catch (unlinkError) {
|
|
221
330
|
logger.warn(`[kv-cache] Failed to remove cache file during rollback; next turn may load stale KV state. path=${state.cachePath} error=${unlinkError instanceof Error ? unlinkError.message : String(unlinkError)}`);
|
|
222
331
|
}
|
|
332
|
+
await pruneEmptyCacheDirectories(state.cachePath);
|
|
333
|
+
if (state.autoCacheKey !== undefined) {
|
|
334
|
+
await removeAutoCacheMarkerIfMissing(state.autoCacheKey);
|
|
335
|
+
}
|
|
223
336
|
initializedCaches.delete(state.registryKey);
|
|
224
337
|
cachedMessageCounts.delete(state.cachePath);
|
|
338
|
+
releaseCachePath(state.cachePath);
|
|
225
339
|
state.rolledBack = true;
|
|
340
|
+
if (state.autoCacheKey !== undefined)
|
|
341
|
+
scheduleAutoCacheSweep(logger);
|
|
226
342
|
}
|
|
227
343
|
function dropStaleSavedCount(turn) {
|
|
228
344
|
const state = turnState.get(turn);
|
|
@@ -282,6 +398,9 @@ export async function deleteKvCacheState(target) {
|
|
|
282
398
|
kvCacheKey: target.kvCacheKey,
|
|
283
399
|
...(target.modelId !== undefined && { modelId: target.modelId })
|
|
284
400
|
});
|
|
401
|
+
if (target.modelId === undefined) {
|
|
402
|
+
await removeAutoCacheMarker(target.kvCacheKey);
|
|
403
|
+
}
|
|
285
404
|
// Prefix-cleanup the in-memory counts. The on-disk directory tree
|
|
286
405
|
// is `{kvCacheRoot}/{kvCacheKey}[/{modelId}]/`, so every entry in
|
|
287
406
|
// `cachedMessageCounts` whose key is the removed directory itself
|
|
@@ -335,6 +454,7 @@ async function verifyPrimedFile(cachePath, logger) {
|
|
|
335
454
|
catch (statError) {
|
|
336
455
|
// ENOENT is the common case here — addon prime returned without
|
|
337
456
|
// calling save (most often: signal abort during prefill).
|
|
457
|
+
await pruneEmptyCacheDirectories(cachePath);
|
|
338
458
|
throw new Error(`[kv-cache] prime closure resolved but no cache file was written. path=${cachePath} cause=${statError instanceof Error ? statError.message : String(statError)}`);
|
|
339
459
|
}
|
|
340
460
|
if (stats.size === 0) {
|
|
@@ -343,6 +463,7 @@ async function verifyPrimedFile(cachePath, logger) {
|
|
|
343
463
|
// primary "prime didn't persist" condition.
|
|
344
464
|
try {
|
|
345
465
|
await fsPromises.unlink(cachePath);
|
|
466
|
+
await pruneEmptyCacheDirectories(cachePath);
|
|
346
467
|
}
|
|
347
468
|
catch (unlinkError) {
|
|
348
469
|
logger.warn(`[kv-cache] Failed to remove empty primed cache file. path=${cachePath} error=${unlinkError instanceof Error ? unlinkError.message : String(unlinkError)}`);
|
|
@@ -432,9 +553,25 @@ export const __kvCacheSessionTestHooks = {
|
|
|
432
553
|
markInitializedForTest(modelId, configHash, cacheKey) {
|
|
433
554
|
initializedCaches.add(initRegistryKey(modelId, configHash, cacheKey));
|
|
434
555
|
},
|
|
556
|
+
getLastAutoCacheSweepMsForTest() {
|
|
557
|
+
return lastAutoCacheSweepMs;
|
|
558
|
+
},
|
|
559
|
+
setLastAutoCacheSweepMsForTest(value) {
|
|
560
|
+
lastAutoCacheSweepMs = value;
|
|
561
|
+
},
|
|
435
562
|
resetForTest() {
|
|
436
563
|
cachedMessageCounts.clear();
|
|
437
564
|
initializedCaches.clear();
|
|
565
|
+
activeCachePaths.clear();
|
|
566
|
+
lastAutoCacheSweepMs = 0;
|
|
567
|
+
autoCacheSweepInFlight = null;
|
|
568
|
+
cacheStateLockTail = Promise.resolve();
|
|
569
|
+
},
|
|
570
|
+
waitForAutoCacheSweepForTest() {
|
|
571
|
+
return autoCacheSweepInFlight ?? Promise.resolve();
|
|
572
|
+
},
|
|
573
|
+
sweepAutoCachesForTest(options) {
|
|
574
|
+
return maybeSweepAutoCaches(moduleLogger, { ...options, force: true });
|
|
438
575
|
}
|
|
439
576
|
};
|
|
440
577
|
// Re-export `generateConfigHash` from the path utilities so callers of
|