@qvac/sdk 0.9.2 → 0.10.0

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