@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,8 @@
1
+ export interface CacheMessage {
2
+ role: string;
3
+ content: string;
4
+ attachments?: {
5
+ path: string;
6
+ }[] | undefined;
7
+ }
8
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
- import type { DownloadMetricsHooks } from "../rpc/handlers/load-model/types";
1
+ import type { DownloadHooks } from "../rpc/handlers/load-model/types";
2
2
  export declare function calculateFileChecksum(filePath: string): Promise<string>;
3
- export declare function measureChecksum(filePath: string, hooks?: DownloadMetricsHooks): Promise<string>;
3
+ export declare function measureChecksum(filePath: string, hooks?: DownloadHooks): Promise<string>;
4
4
  //# sourceMappingURL=checksum.d.ts.map
@@ -26,6 +26,6 @@ export async function calculateFileChecksum(filePath) {
26
26
  export async function measureChecksum(filePath, hooks) {
27
27
  const start = nowMs();
28
28
  const checksum = await calculateFileChecksum(filePath);
29
- hooks?.addChecksumValidationTimeMs(nowMs() - start);
29
+ hooks?.addChecksumValidationTimeMs?.(nowMs() - start);
30
30
  return checksum;
31
31
  }
@@ -0,0 +1,5 @@
1
+ export declare function resolveClearStorageTarget(modelPath: string, modelsCacheDir: string): {
2
+ path: string;
3
+ kind: "file" | "directory";
4
+ };
5
+ //# sourceMappingURL=clear-storage.d.ts.map
@@ -0,0 +1,17 @@
1
+ export function resolveClearStorageTarget(modelPath, modelsCacheDir) {
2
+ const normalizedCache = modelsCacheDir.replace(/\\/g, "/").replace(/\/+$/, "");
3
+ const normalizedPath = modelPath.replace(/\\/g, "/");
4
+ if (!normalizedPath.startsWith(`${normalizedCache}/`)) {
5
+ return { path: modelPath, kind: "file" };
6
+ }
7
+ const relativePath = normalizedPath.slice(normalizedCache.length + 1);
8
+ const parts = relativePath.split("/");
9
+ if (parts.length === 3 &&
10
+ (parts[0] === "sets" || parts[0] === "onnx") &&
11
+ parts[1] &&
12
+ parts[2]) {
13
+ const lastSlash = normalizedPath.lastIndexOf("/");
14
+ return { path: normalizedPath.slice(0, lastSlash), kind: "directory" };
15
+ }
16
+ return { path: modelPath, kind: "file" };
17
+ }
@@ -0,0 +1,17 @@
1
+ import type { CompletionEvent, CompletionError, CompletionStats, NormalizerConfig, StopReason, ToolCall } from "../../schemas/index";
2
+ export type CompletionNormalizer = ReturnType<typeof createCompletionNormalizer>;
3
+ export declare function createCompletionNormalizer(config: NormalizerConfig): {
4
+ push: (token: string) => CompletionEvent[];
5
+ finish: (opts?: {
6
+ stats?: CompletionStats;
7
+ toolCalls?: ToolCall[];
8
+ error?: CompletionError;
9
+ stopReason?: StopReason;
10
+ }) => CompletionEvent[];
11
+ getAccumulated: () => {
12
+ rawText: string;
13
+ contentText: string;
14
+ thinkingText: string | undefined;
15
+ };
16
+ };
17
+ //# sourceMappingURL=completion-normalizer.d.ts.map
@@ -0,0 +1,301 @@
1
+ import { parseToolCalls } from "./tools/index.js";
2
+ const DIALECT_SPECS = {
3
+ hermes: {
4
+ frames: [{ open: "<tool_call>", close: "</tool_call>" }],
5
+ },
6
+ // No streaming framing — tool calls are only recovered at finalization.
7
+ json: {
8
+ frames: [],
9
+ },
10
+ pythonic: {
11
+ frames: [
12
+ { open: "<|tool_call_start|>", close: "<|tool_call_end|>" },
13
+ {
14
+ open: "<|start_header_id|>tool_call<|end_header_id|>",
15
+ close: "<|eot_id|>",
16
+ },
17
+ ],
18
+ },
19
+ };
20
+ const THINK_OPEN = "<think>";
21
+ const THINK_CLOSE = "</think>";
22
+ export function createCompletionNormalizer(config) {
23
+ let seq = 0;
24
+ let state = "content";
25
+ let rawText = "";
26
+ const contentParts = [];
27
+ const thinkingParts = [];
28
+ // Frame buffer keeps the open + close markers in place so parseToolCalls
29
+ // can match its own dialect markers.
30
+ let toolCallBuffer = "";
31
+ let activeFrame = null;
32
+ // Trailing chars that could be a prefix of a watched marker, so markers
33
+ // split across token pushes aren't missed by indexOf.
34
+ let contentTail = "";
35
+ let toolTail = "";
36
+ let thinkingTail = "";
37
+ const streamedToolCallKeys = new Set();
38
+ const toolsEnabled = config.tools.length > 0 && config.capabilities.toolCalling !== "none";
39
+ const useFramedParsing = toolsEnabled && config.capabilities.toolCalling === "textParse";
40
+ const useThinkingParsing = config.captureThinking && config.capabilities.thinkingFraming === "thinkTags";
41
+ const dialect = config.toolDialect ?? "hermes";
42
+ const dialectSpec = DIALECT_SPECS[dialect];
43
+ const frameSpecs = useFramedParsing ? dialectSpec.frames : [];
44
+ const contentMarkers = [];
45
+ if (useThinkingParsing)
46
+ contentMarkers.push(THINK_OPEN);
47
+ for (const f of frameSpecs)
48
+ contentMarkers.push(f.open);
49
+ function nextSeq() {
50
+ return seq++;
51
+ }
52
+ function emitContent(events, text) {
53
+ if (!text)
54
+ return;
55
+ contentParts.push(text);
56
+ events.push({ type: "contentDelta", seq: nextSeq(), text });
57
+ }
58
+ function emitThinking(events, text) {
59
+ if (!text)
60
+ return;
61
+ thinkingParts.push(text);
62
+ if (config.captureThinking) {
63
+ events.push({ type: "thinkingDelta", seq: nextSeq(), text });
64
+ }
65
+ }
66
+ function getToolCallKey(call) {
67
+ return `${call.name}:${JSON.stringify(call.arguments)}`;
68
+ }
69
+ function emitStreamedToolCall(events, call) {
70
+ streamedToolCallKeys.add(getToolCallKey(call));
71
+ events.push({ type: "toolCall", seq: nextSeq(), call });
72
+ }
73
+ function emitFinalToolCall(events, call) {
74
+ if (streamedToolCallKeys.has(getToolCallKey(call)))
75
+ return;
76
+ events.push({ type: "toolCall", seq: nextSeq(), call });
77
+ }
78
+ // Length of the longest suffix of `buf` that is also a prefix of any marker.
79
+ function trailingPartialMarkerLen(buf, markers) {
80
+ if (markers.length === 0 || buf.length === 0)
81
+ return 0;
82
+ const maxLen = Math.min(buf.length, markers.reduce((m, s) => Math.max(m, s.length), 0) - 1);
83
+ for (let len = maxLen; len > 0; len--) {
84
+ const suffix = buf.slice(buf.length - len);
85
+ for (const m of markers) {
86
+ if (m.startsWith(suffix))
87
+ return len;
88
+ }
89
+ }
90
+ return 0;
91
+ }
92
+ function findEarliestMarker(buf, markers) {
93
+ let best = null;
94
+ for (const m of markers) {
95
+ const i = buf.indexOf(m);
96
+ if (i < 0)
97
+ continue;
98
+ if (best === null || i < best.idx)
99
+ best = { idx: i, marker: m };
100
+ }
101
+ return best;
102
+ }
103
+ function flushToolBuffer(events, closed) {
104
+ const raw = toolCallBuffer;
105
+ const frame = activeFrame;
106
+ toolCallBuffer = "";
107
+ activeFrame = null;
108
+ toolTail = "";
109
+ if (!frame)
110
+ return;
111
+ // Empty-payload guard. Strip frame markers and check the inner is
112
+ // non-empty; surface a toolError on empty payloads so the literal
113
+ // markers don't leak into contentDelta.
114
+ let inner = raw;
115
+ if (inner.startsWith(frame.open))
116
+ inner = inner.slice(frame.open.length);
117
+ if (inner.endsWith(frame.close)) {
118
+ inner = inner.slice(0, inner.length - frame.close.length);
119
+ }
120
+ if (inner.trim().length === 0) {
121
+ events.push({
122
+ type: "toolError",
123
+ seq: nextSeq(),
124
+ error: { code: "PARSE_ERROR", message: "Empty tool_call frame" },
125
+ });
126
+ return;
127
+ }
128
+ const { toolCalls, errors } = parseToolCalls(raw, config.tools, dialect);
129
+ for (const call of toolCalls)
130
+ emitStreamedToolCall(events, call);
131
+ if (toolCalls.length === 0) {
132
+ if (errors.length > 0) {
133
+ for (const error of errors) {
134
+ events.push({ type: "toolError", seq: nextSeq(), error });
135
+ }
136
+ }
137
+ else {
138
+ events.push({
139
+ type: "toolError",
140
+ seq: nextSeq(),
141
+ error: {
142
+ code: "PARSE_ERROR",
143
+ message: closed
144
+ ? "Failed to parse tool call from framed region"
145
+ : "Incomplete tool call frame at stream end",
146
+ raw,
147
+ },
148
+ });
149
+ }
150
+ emitContent(events, raw);
151
+ }
152
+ }
153
+ function processSegment(events, text) {
154
+ let buf = (state === "content"
155
+ ? contentTail
156
+ : state === "thinking"
157
+ ? thinkingTail
158
+ : toolTail) + text;
159
+ contentTail = "";
160
+ thinkingTail = "";
161
+ toolTail = "";
162
+ while (buf.length > 0) {
163
+ if (state === "toolBuffering") {
164
+ if (!activeFrame) {
165
+ state = "content";
166
+ continue;
167
+ }
168
+ const hit = buf.indexOf(activeFrame.close);
169
+ if (hit >= 0) {
170
+ toolCallBuffer += buf.slice(0, hit + activeFrame.close.length);
171
+ buf = buf.slice(hit + activeFrame.close.length);
172
+ state = "content";
173
+ flushToolBuffer(events, true);
174
+ continue;
175
+ }
176
+ const tailLen = trailingPartialMarkerLen(buf, [activeFrame.close]);
177
+ const safeLen = buf.length - tailLen;
178
+ toolCallBuffer += buf.slice(0, safeLen);
179
+ toolTail = buf.slice(safeLen);
180
+ buf = "";
181
+ continue;
182
+ }
183
+ if (state === "thinking") {
184
+ const closeIdx = buf.indexOf(THINK_CLOSE);
185
+ if (closeIdx >= 0) {
186
+ emitThinking(events, buf.slice(0, closeIdx));
187
+ buf = buf.slice(closeIdx + THINK_CLOSE.length);
188
+ state = "content";
189
+ continue;
190
+ }
191
+ const tailLen = trailingPartialMarkerLen(buf, [THINK_CLOSE]);
192
+ const safeLen = buf.length - tailLen;
193
+ emitThinking(events, buf.slice(0, safeLen));
194
+ thinkingTail = buf.slice(safeLen);
195
+ buf = "";
196
+ continue;
197
+ }
198
+ const hit = findEarliestMarker(buf, contentMarkers);
199
+ if (hit) {
200
+ emitContent(events, buf.slice(0, hit.idx));
201
+ if (hit.marker === THINK_OPEN) {
202
+ buf = buf.slice(hit.idx + hit.marker.length);
203
+ state = "thinking";
204
+ continue;
205
+ }
206
+ const spec = frameSpecs.find((f) => f.open === hit.marker);
207
+ toolCallBuffer = hit.marker;
208
+ activeFrame = spec;
209
+ buf = buf.slice(hit.idx + hit.marker.length);
210
+ state = "toolBuffering";
211
+ continue;
212
+ }
213
+ const tailLen = trailingPartialMarkerLen(buf, contentMarkers);
214
+ const safeLen = buf.length - tailLen;
215
+ emitContent(events, buf.slice(0, safeLen));
216
+ contentTail = buf.slice(safeLen);
217
+ buf = "";
218
+ }
219
+ }
220
+ function push(token) {
221
+ const events = [];
222
+ rawText += token;
223
+ if (config.emitRawDeltas) {
224
+ events.push({ type: "rawDelta", seq: nextSeq(), text: token });
225
+ }
226
+ processSegment(events, token);
227
+ return events;
228
+ }
229
+ function finish(opts) {
230
+ const events = [];
231
+ // Drain pending tail bytes so we don't lose trailing chars when the
232
+ // stream ends mid-marker.
233
+ if (state === "content" && contentTail) {
234
+ emitContent(events, contentTail);
235
+ contentTail = "";
236
+ }
237
+ else if (state === "thinking" && thinkingTail) {
238
+ emitThinking(events, thinkingTail);
239
+ thinkingTail = "";
240
+ }
241
+ else if (state === "toolBuffering" && toolTail) {
242
+ toolCallBuffer += toolTail;
243
+ toolTail = "";
244
+ }
245
+ if (state === "toolBuffering" && activeFrame) {
246
+ if (opts?.error) {
247
+ emitContent(events, toolCallBuffer);
248
+ toolCallBuffer = "";
249
+ activeFrame = null;
250
+ }
251
+ else {
252
+ flushToolBuffer(events, false);
253
+ }
254
+ }
255
+ state = "content";
256
+ if (!opts?.error) {
257
+ if (opts?.toolCalls) {
258
+ for (const call of opts.toolCalls) {
259
+ emitFinalToolCall(events, call);
260
+ }
261
+ }
262
+ }
263
+ if (opts?.stats) {
264
+ events.push({
265
+ type: "completionStats",
266
+ seq: nextSeq(),
267
+ stats: opts.stats,
268
+ });
269
+ }
270
+ const raw = { fullText: rawText };
271
+ if (opts?.error) {
272
+ events.push({
273
+ type: "completionDone",
274
+ seq: nextSeq(),
275
+ stopReason: "error",
276
+ error: opts.error,
277
+ raw,
278
+ });
279
+ }
280
+ else if (opts?.stopReason) {
281
+ events.push({
282
+ type: "completionDone",
283
+ seq: nextSeq(),
284
+ stopReason: opts.stopReason,
285
+ raw,
286
+ });
287
+ }
288
+ else {
289
+ events.push({ type: "completionDone", seq: nextSeq(), raw });
290
+ }
291
+ return events;
292
+ }
293
+ function getAccumulated() {
294
+ return {
295
+ rawText,
296
+ contentText: contentParts.join(""),
297
+ thinkingText: thinkingParts.length > 0 ? thinkingParts.join("") : undefined,
298
+ };
299
+ }
300
+ return { push, finish, getAccumulated };
301
+ }
@@ -0,0 +1,3 @@
1
+ /** Expand a sharded GGUF path into `.tensors.txt` plus all shards. */
2
+ export declare function expandGGUFIntoShards(modelPath: string): string[];
3
+ //# sourceMappingURL=expand-gguf-shards.d.ts.map
@@ -0,0 +1,22 @@
1
+ const SHARD_PATTERN = /^(.+)-(\d{5})-of-(\d{5})\.gguf$/;
2
+ /** Expand a sharded GGUF path into `.tensors.txt` plus all shards. */
3
+ export function expandGGUFIntoShards(modelPath) {
4
+ const lastSep = Math.max(modelPath.lastIndexOf("/"), modelPath.lastIndexOf("\\"));
5
+ const dir = lastSep >= 0 ? modelPath.slice(0, lastSep) : "";
6
+ const sep = lastSep >= 0 ? modelPath.charAt(lastSep) : "/";
7
+ const filename = lastSep >= 0 ? modelPath.slice(lastSep + 1) : modelPath;
8
+ const match = filename.match(SHARD_PATTERN);
9
+ if (!match || !match[1] || !match[3])
10
+ return [modelPath];
11
+ const baseFilename = match[1];
12
+ const totalDigits = match[3];
13
+ const totalShards = Number.parseInt(totalDigits, 10);
14
+ if (totalShards <= 0)
15
+ return [modelPath];
16
+ const join = (name) => (dir ? `${dir}${sep}${name}` : name);
17
+ const shards = [join(`${baseFilename}.tensors.txt`)];
18
+ for (let i = 1; i <= totalShards; i++) {
19
+ shards.push(join(`${baseFilename}-${String(i).padStart(5, "0")}-of-${totalDigits}.gguf`));
20
+ }
21
+ return shards;
22
+ }
@@ -13,7 +13,7 @@ function isModelDescriptor(value) {
13
13
  return (typeof value === "object" &&
14
14
  value !== null &&
15
15
  "src" in value &&
16
- typeof value.src === "string");
16
+ typeof (value).src === "string");
17
17
  }
18
18
  function normalizeValue(value) {
19
19
  if (isModelDescriptor(value)) {
@@ -1,10 +1,12 @@
1
1
  export * from "./archive";
2
- export * from "./cache";
2
+ export * from "./cache/types";
3
+ export * from "./cache/auto-history";
4
+ export * from "./cache/paths";
3
5
  export * from "./checksum";
4
6
  export * from "./config-transform";
7
+ export * from "./expand-gguf-shards";
5
8
  export * from "./formatting";
6
9
  export * from "./gguf-tensor-extractor";
7
- export * from "./model-path";
8
10
  export * from "./path-security";
9
11
  export * from "./shard-utils";
10
12
  //# sourceMappingURL=index.d.ts.map
@@ -1,9 +1,11 @@
1
1
  export * from "./archive.js";
2
- export * from "./cache.js";
2
+ export * from "./cache/types.js";
3
+ export * from "./cache/auto-history.js";
4
+ export * from "./cache/paths.js";
3
5
  export * from "./checksum.js";
4
6
  export * from "./config-transform.js";
7
+ export * from "./expand-gguf-shards.js";
5
8
  export * from "./formatting.js";
6
9
  export * from "./gguf-tensor-extractor.js";
7
- export * from "./model-path.js";
8
10
  export * from "./path-security.js";
9
11
  export * from "./shard-utils.js";
@@ -0,0 +1,2 @@
1
+ export declare function getQvacPath(...subPaths: string[]): string;
2
+ //# sourceMappingURL=qvac-paths.d.ts.map
@@ -0,0 +1,5 @@
1
+ import path from "bare-path";
2
+ import { getEnv } from "../env.js";
3
+ export function getQvacPath(...subPaths) {
4
+ return path.join(getEnv().HOME_DIR, ".qvac", ...subPaths);
5
+ }
@@ -0,0 +1,3 @@
1
+ import type { ResponseFormat } from "../../schemas/index";
2
+ export declare function getResponseFormatJsonSchema(responseFormat: ResponseFormat): string | undefined;
3
+ //# sourceMappingURL=response-format.d.ts.map
@@ -0,0 +1,20 @@
1
+ // Translates the request-level `responseFormat` into the JSON Schema string
2
+ // that the llama.cpp addon's per-request `generationParams.json_schema`
3
+ // expects. Returns `undefined` for `{ type: "text" }` (no constraint).
4
+ //
5
+ // The addon converts the schema to GBNF natively via
6
+ // `json_schema_to_grammar()` and applies it for the duration of the request
7
+ // only, restoring the prior sampling block afterwards — so this surface is
8
+ // safe to use under concurrent completions on the same model. (Tool calling
9
+ // still goes through `setupToolGrammar` / `modelConfig.grammar`; see the
10
+ // mutual-exclusion check in `completionClientParamsSchema`.)
11
+ export function getResponseFormatJsonSchema(responseFormat) {
12
+ switch (responseFormat.type) {
13
+ case "text":
14
+ return undefined;
15
+ case "json_object":
16
+ return JSON.stringify({ type: "object" });
17
+ case "json_schema":
18
+ return JSON.stringify(responseFormat.json_schema.schema);
19
+ }
20
+ }
@@ -1,4 +1,4 @@
1
- import type { Tool, ToolCallEvent } from "../../schemas/index";
1
+ import type { Tool, ToolDialect } from "../../schemas/index";
2
2
  interface HistoryMessage {
3
3
  role: string;
4
4
  content: string;
@@ -6,8 +6,19 @@ interface HistoryMessage {
6
6
  path: string;
7
7
  }[] | undefined;
8
8
  }
9
- export declare function insertToolsIntoHistory(history: HistoryMessage[], tools: Tool[]): Array<HistoryMessage | Tool>;
10
- export declare function setupToolGrammar(modelConfig: Record<string, unknown>, tools: Tool[]): void;
11
- export declare function checkForToolEvents(accumulatedText: string, currentToken: string, tools: Tool[], emittedToolCallPositions: Set<number>): ToolCallEvent[];
9
+ /**
10
+ * Static tools mode: prepend tools right after the system message (or at the
11
+ * very start when no system message is present). The tool block stays in the
12
+ * kv-cache for the whole chat session.
13
+ */
14
+ export declare function prependToolsToHistory(history: HistoryMessage[], tools: Tool[]): Array<HistoryMessage | Tool>;
15
+ /**
16
+ * Dynamic tools mode: append tools after the last history message. The
17
+ * addon's compact-tools mode anchors the block after the last user message
18
+ * and trims it from the kv-cache once the tool-call chain resolves, so a
19
+ * subsequent turn can ship a different tool set without poisoning the cache.
20
+ */
21
+ export declare function appendToolsToHistory(history: HistoryMessage[], tools: Tool[]): Array<HistoryMessage | Tool>;
22
+ export declare function detectToolDialect(modelId: string): ToolDialect;
12
23
  export {};
13
24
  //# sourceMappingURL=tool-integration.d.ts.map
@@ -1,5 +1,11 @@
1
- import { parseToolCalls, convertToolsToGrammar, } from "./tool-parser.js";
2
- export function insertToolsIntoHistory(history, tools) {
1
+ import { detectToolDialectFromName } from "./tools/index.js";
2
+ import { getModelInfo } from "../bare/registry/model-registry.js";
3
+ /**
4
+ * Static tools mode: prepend tools right after the system message (or at the
5
+ * very start when no system message is present). The tool block stays in the
6
+ * kv-cache for the whole chat session.
7
+ */
8
+ export function prependToolsToHistory(history, tools) {
3
9
  const systemMsgIndex = history.findIndex((msg) => msg.role === "system");
4
10
  if (systemMsgIndex >= 0) {
5
11
  return [
@@ -10,44 +16,18 @@ export function insertToolsIntoHistory(history, tools) {
10
16
  }
11
17
  return [...tools, ...history];
12
18
  }
13
- export function setupToolGrammar(modelConfig, tools) {
14
- const grammar = convertToolsToGrammar(tools);
15
- modelConfig["grammar"] = grammar;
19
+ /**
20
+ * Dynamic tools mode: append tools after the last history message. The
21
+ * addon's compact-tools mode anchors the block after the last user message
22
+ * and trims it from the kv-cache once the tool-call chain resolves, so a
23
+ * subsequent turn can ship a different tool set without poisoning the cache.
24
+ */
25
+ export function appendToolsToHistory(history, tools) {
26
+ return [...history, ...tools];
16
27
  }
17
- function isInsideThinkBlock(text) {
18
- const lastOpen = text.lastIndexOf("<think>");
19
- if (lastOpen === -1)
20
- return false;
21
- const lastClose = text.lastIndexOf("</think>");
22
- return lastClose < lastOpen;
23
- }
24
- export function checkForToolEvents(accumulatedText, currentToken, tools, emittedToolCallPositions) {
25
- const events = [];
26
- if (isInsideThinkBlock(accumulatedText)) {
27
- return events;
28
- }
29
- if (currentToken.includes("</tool_call>") || currentToken.includes("}")) {
30
- const { toolCalls, errors } = parseToolCalls(accumulatedText, tools);
31
- for (const call of toolCalls) {
32
- const callPosition = accumulatedText.indexOf(call.raw || "");
33
- if (callPosition >= 0 && !emittedToolCallPositions.has(callPosition)) {
34
- emittedToolCallPositions.add(callPosition);
35
- events.push({
36
- type: "toolCall",
37
- call,
38
- });
39
- }
40
- }
41
- for (const error of errors) {
42
- const errorPosition = accumulatedText.indexOf(error.raw || "");
43
- if (errorPosition >= 0 && !emittedToolCallPositions.has(errorPosition)) {
44
- emittedToolCallPositions.add(errorPosition);
45
- events.push({
46
- type: "toolCallError",
47
- error,
48
- });
49
- }
50
- }
51
- }
52
- return events;
28
+ export function detectToolDialect(modelId) {
29
+ const info = getModelInfo(modelId);
30
+ if (!info)
31
+ return "hermes";
32
+ return detectToolDialectFromName(info.name, info.path);
53
33
  }
@@ -0,0 +1,8 @@
1
+ import type { ToolDialect } from "../../../schemas/index";
2
+ /**
3
+ * Detects the tool-call dialect from a model's registry name and file path.
4
+ * Defaults to "hermes" (its parser chain also covers unknown JSON-payload
5
+ * models). Bypass with `completion({ toolDialect })`.
6
+ */
7
+ export declare function detectToolDialectFromName(name: string | undefined, path: string): ToolDialect;
8
+ //# sourceMappingURL=dialect.d.ts.map
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Detects the tool-call dialect from a model's registry name and file path.
3
+ * Defaults to "hermes" (its parser chain also covers unknown JSON-payload
4
+ * models). Bypass with `completion({ toolDialect })`.
5
+ */
6
+ export function detectToolDialectFromName(name, path) {
7
+ const basename = path.toLowerCase().split(/[/\\]/).pop() ?? "";
8
+ const tag = `${(name ?? "").toLowerCase()}|${basename}`;
9
+ if (/lfm[_-]?\d/.test(tag))
10
+ return "pythonic";
11
+ return "hermes";
12
+ }
@@ -0,0 +1,3 @@
1
+ export { detectToolDialectFromName } from "./dialect";
2
+ export { parseToolCalls } from "./parser";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,2 @@
1
+ export { detectToolDialectFromName } from "./dialect.js";
2
+ export { parseToolCalls } from "./parser.js";
@@ -0,0 +1,6 @@
1
+ import type { Tool, ToolCall, ToolCallError, ToolDialect } from "../../../schemas/index";
2
+ export declare function parseToolCalls(text: string, tools: Tool[], dialect?: ToolDialect): {
3
+ toolCalls: ToolCall[];
4
+ errors: ToolCallError[];
5
+ };
6
+ //# sourceMappingURL=parser.d.ts.map
@@ -0,0 +1,40 @@
1
+ import { stripThinkingBlocks, } from "./shared.js";
2
+ import { parseGemmaFormat, parseGenericFormat, parseLlamacppFormat, } from "./parsers/json.js";
3
+ import { parseHermesFormat } from "./parsers/hermes.js";
4
+ import { parsePythonicFormat } from "./parsers/pythonic.js";
5
+ function pickFormatParsers(dialect) {
6
+ switch (dialect) {
7
+ case "pythonic":
8
+ return [parsePythonicFormat];
9
+ case "hermes":
10
+ // Hermes first so frame errors surface; JSON fallbacks then cover
11
+ // unknown JSON-payload models.
12
+ return [parseHermesFormat, parseGemmaFormat, parseLlamacppFormat];
13
+ case "json":
14
+ return [parseGemmaFormat, parseLlamacppFormat];
15
+ default:
16
+ // Pythonic last: its bare `[name(...)]` form can match payloads that
17
+ // look like other dialects.
18
+ return [
19
+ parseHermesFormat,
20
+ parseGemmaFormat,
21
+ parseLlamacppFormat,
22
+ parsePythonicFormat,
23
+ ];
24
+ }
25
+ }
26
+ export function parseToolCalls(text, tools, dialect) {
27
+ if (!tools || tools.length === 0) {
28
+ return { toolCalls: [], errors: [] };
29
+ }
30
+ const cleaned = stripThinkingBlocks(text);
31
+ const formatParsers = pickFormatParsers(dialect);
32
+ for (const parser of formatParsers) {
33
+ const result = parser(cleaned, tools);
34
+ if (result.matched) {
35
+ return { toolCalls: result.toolCalls, errors: result.errors };
36
+ }
37
+ }
38
+ const generic = parseGenericFormat(cleaned, tools);
39
+ return { toolCalls: generic.toolCalls, errors: generic.errors };
40
+ }