@qvac/sdk 0.9.1 → 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 (335) 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 +361 -279
  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/finetune.d.ts +16 -16
  118. package/dist/schemas/finetune.js +8 -8
  119. package/dist/schemas/get-loaded-model-info.d.ts +52 -0
  120. package/dist/schemas/get-loaded-model-info.js +44 -0
  121. package/dist/schemas/get-model-info.d.ts +2 -2
  122. package/dist/schemas/get-model-info.js +103 -32
  123. package/dist/schemas/heartbeat.d.ts +0 -1
  124. package/dist/schemas/index.d.ts +4 -1
  125. package/dist/schemas/index.js +4 -1
  126. package/dist/schemas/llamacpp-config.d.ts +14 -4
  127. package/dist/schemas/llamacpp-config.js +5 -0
  128. package/dist/schemas/load-model.d.ts +3233 -1260
  129. package/dist/schemas/load-model.js +23 -16
  130. package/dist/schemas/model-src-utils.d.ts +7 -6
  131. package/dist/schemas/model-src-utils.js +27 -1
  132. package/dist/schemas/model-types.d.ts +4 -4
  133. package/dist/schemas/ocr.d.ts +1 -1
  134. package/dist/schemas/plugin.d.ts +27 -3
  135. package/dist/schemas/plugin.js +27 -2
  136. package/dist/schemas/profiling.js +11 -3
  137. package/dist/schemas/provide.d.ts +1 -3
  138. package/dist/schemas/provide.js +0 -3
  139. package/dist/schemas/rag.d.ts +4 -4
  140. package/dist/schemas/registry.d.ts +10 -10
  141. package/dist/schemas/registry.js +36 -14
  142. package/dist/schemas/reload-config.d.ts +73 -7
  143. package/dist/schemas/sdcpp-config.d.ts +16 -8
  144. package/dist/schemas/sdcpp-config.js +118 -25
  145. package/dist/schemas/sdk-config.d.ts +116 -90
  146. package/dist/schemas/sdk-config.js +16 -0
  147. package/dist/schemas/sdk-errors-client.d.ts +3 -0
  148. package/dist/schemas/sdk-errors-client.js +16 -1
  149. package/dist/schemas/sdk-errors-server.d.ts +3 -0
  150. package/dist/schemas/sdk-errors-server.js +23 -0
  151. package/dist/schemas/state.d.ts +23 -0
  152. package/dist/schemas/state.js +14 -0
  153. package/dist/schemas/stop-provide.d.ts +0 -5
  154. package/dist/schemas/stop-provide.js +2 -6
  155. package/dist/schemas/text-to-speech.d.ts +93 -27
  156. package/dist/schemas/text-to-speech.js +27 -0
  157. package/dist/schemas/tools.d.ts +16 -0
  158. package/dist/schemas/tools.js +15 -0
  159. package/dist/schemas/transcription-config.d.ts +8 -8
  160. package/dist/schemas/transcription.d.ts +33 -0
  161. package/dist/schemas/transcription.js +9 -0
  162. package/dist/schemas/translate.js +59 -19
  163. package/dist/schemas/translation-config.d.ts +157 -133
  164. package/dist/schemas/translation-config.js +34 -11
  165. package/dist/server/bare/delegate-rpc-client.d.ts +1 -1
  166. package/dist/server/bare/delegate-rpc-client.js +131 -122
  167. package/dist/server/bare/hyperswarm.d.ts +2 -2
  168. package/dist/server/bare/hyperswarm.js +12 -7
  169. package/dist/server/bare/ops/cancel.js +7 -0
  170. package/dist/server/bare/ops/kv-cache-utils.d.ts +7 -10
  171. package/dist/server/bare/ops/kv-cache-utils.js +31 -40
  172. package/dist/server/bare/ops/load-model.js +0 -1
  173. package/dist/server/bare/ops/transcribe.d.ts +11 -4
  174. package/dist/server/bare/ops/transcribe.js +25 -4
  175. package/dist/server/bare/ops/translate.js +42 -4
  176. package/dist/server/bare/ops/unload-model.js +21 -19
  177. package/dist/server/bare/plugins/llamacpp-completion/ops/cache-logger.js +1 -2
  178. package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.d.ts +13 -8
  179. package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.js +257 -85
  180. package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-state.d.ts +101 -0
  181. package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-state.js +135 -0
  182. package/dist/server/bare/plugins/llamacpp-completion/plugin.d.ts +83 -26
  183. package/dist/server/bare/plugins/llamacpp-completion/plugin.js +57 -32
  184. package/dist/server/bare/plugins/llamacpp-embedding/plugin.js +10 -16
  185. package/dist/server/bare/plugins/nmtcpp-translation/plugin.d.ts +69 -44
  186. package/dist/server/bare/plugins/nmtcpp-translation/plugin.js +113 -94
  187. package/dist/server/bare/plugins/onnx-ocr/plugin.d.ts +1 -1
  188. package/dist/server/bare/plugins/onnx-ocr/plugin.js +1 -2
  189. package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech-stream.d.ts +7 -0
  190. package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech-stream.js +116 -0
  191. package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech.d.ts +2 -3
  192. package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech.js +71 -9
  193. package/dist/server/bare/plugins/onnx-tts/plugin.d.ts +41 -13
  194. package/dist/server/bare/plugins/onnx-tts/plugin.js +48 -3
  195. package/dist/server/bare/plugins/parakeet-transcription/plugin.d.ts +15 -7
  196. package/dist/server/bare/plugins/parakeet-transcription/plugin.js +5 -6
  197. package/dist/server/bare/plugins/sdcpp-generation/ops/diffusion.js +6 -0
  198. package/dist/server/bare/plugins/sdcpp-generation/plugin.d.ts +8 -5
  199. package/dist/server/bare/plugins/sdcpp-generation/plugin.js +13 -13
  200. package/dist/server/bare/plugins/whispercpp-transcription/plugin.d.ts +17 -1
  201. package/dist/server/bare/plugins/whispercpp-transcription/plugin.js +40 -17
  202. package/dist/server/bare/registry/config-registry.js +14 -3
  203. package/dist/server/bare/registry/model-registry.d.ts +8 -10
  204. package/dist/server/bare/registry/model-registry.js +17 -12
  205. package/dist/server/bare/registry/registry-client.js +79 -19
  206. package/dist/server/bare/runtime-lifecycle.d.ts +2 -1
  207. package/dist/server/bare/runtime-lifecycle.js +13 -2
  208. package/dist/server/bare/types/addon-responses.d.ts +8 -3
  209. package/dist/server/bare/utils/transcribe-metadata.d.ts +21 -0
  210. package/dist/server/bare/utils/transcribe-metadata.js +28 -0
  211. package/dist/server/bare/utils/tts-stats.d.ts +22 -0
  212. package/dist/server/bare/utils/tts-stats.js +10 -0
  213. package/dist/server/rpc/create-server.d.ts +4 -1
  214. package/dist/server/rpc/create-server.js +5 -1
  215. package/dist/server/rpc/delegate-transport.js +36 -29
  216. package/dist/server/rpc/handle-request.js +28 -3
  217. package/dist/server/rpc/handler-registry.js +7 -1
  218. package/dist/server/rpc/handler-utils.d.ts +5 -0
  219. package/dist/server/rpc/handler-utils.js +22 -0
  220. package/dist/server/rpc/handlers/cancel-delegated.js +3 -5
  221. package/dist/server/rpc/handlers/cancelHandler.js +4 -5
  222. package/dist/server/rpc/handlers/completion-stream-delegated.js +14 -5
  223. package/dist/server/rpc/handlers/delete-cache.js +8 -3
  224. package/dist/server/rpc/handlers/download-asset.js +3 -24
  225. package/dist/server/rpc/handlers/get-loaded-model-info.d.ts +3 -0
  226. package/dist/server/rpc/handlers/get-loaded-model-info.js +39 -0
  227. package/dist/server/rpc/handlers/get-model-info.js +93 -84
  228. package/dist/server/rpc/handlers/heartbeat-delegated.js +2 -2
  229. package/dist/server/rpc/handlers/index.d.ts +6 -0
  230. package/dist/server/rpc/handlers/index.js +6 -0
  231. package/dist/server/rpc/handlers/load-model/download-manager.d.ts +35 -9
  232. package/dist/server/rpc/handlers/load-model/download-manager.js +142 -38
  233. package/dist/server/rpc/handlers/load-model/download-stats.d.ts +5 -4
  234. package/dist/server/rpc/handlers/load-model/download-stats.js +49 -8
  235. package/dist/server/rpc/handlers/load-model/handler.js +31 -50
  236. package/dist/server/rpc/handlers/load-model/http.d.ts +2 -2
  237. package/dist/server/rpc/handlers/load-model/http.js +97 -142
  238. package/dist/server/rpc/handlers/load-model/hyperdrive.d.ts +2 -2
  239. package/dist/server/rpc/handlers/load-model/hyperdrive.js +55 -74
  240. package/dist/server/rpc/handlers/load-model/index.d.ts +0 -1
  241. package/dist/server/rpc/handlers/load-model/index.js +0 -1
  242. package/dist/server/rpc/handlers/load-model/registry-client-options.d.ts +27 -0
  243. package/dist/server/rpc/handlers/load-model/registry-client-options.js +19 -0
  244. package/dist/server/rpc/handlers/load-model/registry-companion-set.d.ts +22 -0
  245. package/dist/server/rpc/handlers/load-model/registry-companion-set.js +208 -0
  246. package/dist/server/rpc/handlers/load-model/registry-download-utils.d.ts +24 -0
  247. package/dist/server/rpc/handlers/load-model/registry-download-utils.js +114 -0
  248. package/dist/server/rpc/handlers/load-model/registry.d.ts +2 -20
  249. package/dist/server/rpc/handlers/load-model/registry.js +109 -381
  250. package/dist/server/rpc/handlers/load-model/resolve-session.d.ts +15 -0
  251. package/dist/server/rpc/handlers/load-model/resolve-session.js +61 -0
  252. package/dist/server/rpc/handlers/load-model/resolve.d.ts +3 -3
  253. package/dist/server/rpc/handlers/load-model/resolve.js +14 -23
  254. package/dist/server/rpc/handlers/load-model/types.d.ts +11 -4
  255. package/dist/server/rpc/handlers/load-model/types.js +28 -1
  256. package/dist/server/rpc/handlers/load-model-delegated.js +2 -4
  257. package/dist/server/rpc/handlers/plugin-dispatch.js +9 -5
  258. package/dist/server/rpc/handlers/plugin-invoke.js +1 -1
  259. package/dist/server/rpc/handlers/provideHandler/connection.js +13 -2
  260. package/dist/server/rpc/handlers/provideHandler/handler.js +42 -29
  261. package/dist/server/rpc/handlers/state.d.ts +3 -0
  262. package/dist/server/rpc/handlers/state.js +7 -0
  263. package/dist/server/rpc/handlers/stopProvideHandler.d.ts +2 -2
  264. package/dist/server/rpc/handlers/stopProvideHandler.js +12 -7
  265. package/dist/server/rpc/handlers/text-to-speech-stream.d.ts +3 -0
  266. package/dist/server/rpc/handlers/text-to-speech-stream.js +4 -0
  267. package/dist/server/rpc/handlers/unload-model-delegated.js +3 -3
  268. package/dist/server/rpc/profiling/operation-metrics.js +20 -0
  269. package/dist/server/rpc/rpc-utils.js +1 -1
  270. package/dist/server/rpc/transport-selector.d.ts +3 -0
  271. package/dist/server/rpc/transport-selector.js +18 -0
  272. package/dist/server/utils/cache/auto-history.d.ts +4 -0
  273. package/dist/server/utils/cache/auto-history.js +22 -0
  274. package/dist/server/utils/{cache.d.ts → cache/paths.d.ts} +22 -5
  275. package/dist/server/utils/{cache.js → cache/paths.js} +36 -20
  276. package/dist/server/utils/cache/types.d.ts +8 -0
  277. package/dist/server/utils/cache/types.js +1 -0
  278. package/dist/server/utils/checksum.d.ts +2 -2
  279. package/dist/server/utils/checksum.js +1 -1
  280. package/dist/server/utils/clear-storage.d.ts +5 -0
  281. package/dist/server/utils/clear-storage.js +17 -0
  282. package/dist/server/utils/completion-normalizer.d.ts +17 -0
  283. package/dist/server/utils/completion-normalizer.js +301 -0
  284. package/dist/server/utils/expand-gguf-shards.d.ts +3 -0
  285. package/dist/server/utils/expand-gguf-shards.js +22 -0
  286. package/dist/server/utils/formatting.js +1 -1
  287. package/dist/server/utils/index.d.ts +4 -2
  288. package/dist/server/utils/index.js +4 -2
  289. package/dist/server/utils/qvac-paths.d.ts +2 -0
  290. package/dist/server/utils/qvac-paths.js +5 -0
  291. package/dist/server/utils/response-format.d.ts +3 -0
  292. package/dist/server/utils/response-format.js +20 -0
  293. package/dist/server/utils/tool-integration.d.ts +15 -4
  294. package/dist/server/utils/tool-integration.js +21 -41
  295. package/dist/server/utils/tools/dialect.d.ts +8 -0
  296. package/dist/server/utils/tools/dialect.js +12 -0
  297. package/dist/server/utils/tools/index.d.ts +3 -0
  298. package/dist/server/utils/tools/index.js +2 -0
  299. package/dist/server/utils/tools/parser.d.ts +6 -0
  300. package/dist/server/utils/tools/parser.js +40 -0
  301. package/dist/server/utils/tools/parsers/hermes.d.ts +4 -0
  302. package/dist/server/utils/tools/parsers/hermes.js +100 -0
  303. package/dist/server/utils/tools/parsers/json.d.ts +6 -0
  304. package/dist/server/utils/tools/parsers/json.js +115 -0
  305. package/dist/server/utils/tools/parsers/pythonic.d.ts +4 -0
  306. package/dist/server/utils/tools/parsers/pythonic.js +267 -0
  307. package/dist/server/utils/tools/shared.d.ts +18 -0
  308. package/dist/server/utils/tools/shared.js +54 -0
  309. package/dist/server/utils/worker-lock.d.ts +3 -0
  310. package/dist/server/utils/worker-lock.js +67 -0
  311. package/dist/server/worker-core.d.ts +16 -1
  312. package/dist/server/worker-core.js +114 -14
  313. package/dist/utils/aggregate-events.d.ts +16 -0
  314. package/dist/utils/aggregate-events.js +52 -0
  315. package/dist/utils/cache-normalize.d.ts +10 -0
  316. package/dist/utils/cache-normalize.js +23 -0
  317. package/dist/utils/encoding.d.ts +8 -0
  318. package/dist/utils/encoding.js +13 -0
  319. package/dist/utils/errors-client.d.ts +12 -0
  320. package/dist/utils/errors-client.js +20 -0
  321. package/dist/utils/errors-server.d.ts +14 -0
  322. package/dist/utils/errors-server.js +31 -0
  323. package/dist/utils/load-model-validation.d.ts +7 -0
  324. package/dist/utils/load-model-validation.js +18 -0
  325. package/expo/plugins/patches/android-link.mjs +1 -1
  326. package/expo/plugins/patches/ios-link.mjs +1 -1
  327. package/package.json +15 -19
  328. package/dist/examples/translation/translation-opus.d.ts +0 -2
  329. package/dist/examples/translation/translation-opus.js +0 -33
  330. package/dist/server/bare/utils/loader-adapter.d.ts +0 -7
  331. package/dist/server/bare/utils/loader-adapter.js +0 -9
  332. package/dist/server/utils/model-path.d.ts +0 -5
  333. package/dist/server/utils/model-path.js +0 -7
  334. package/dist/server/utils/tool-parser.d.ts +0 -7
  335. package/dist/server/utils/tool-parser.js +0 -248
package/NOTICE CHANGED
@@ -83,46 +83,6 @@ Third-Party Model Licenses
83
83
  https://huggingface.co/personalizedrefrigerator/whisper-base-fr
84
84
  fr-tiny-ggml-model-f16
85
85
  https://huggingface.co/JaepaX/whisper-tiny-fr
86
- ggml-opus-ar-en
87
- https://huggingface.co/Helsinki-NLP/opus-mt-ar-en
88
- ggml-opus-de-en
89
- https://huggingface.co/Helsinki-NLP/opus-mt-de-en
90
- ggml-opus-de-fr
91
- https://huggingface.co/Helsinki-NLP/opus-mt-de-fr
92
- ggml-opus-en-ar
93
- https://huggingface.co/Helsinki-NLP/opus-mt-en-ar
94
- ggml-opus-en-es
95
- https://huggingface.co/Helsinki-NLP/opus-mt-en-es
96
- ggml-opus-en-fr
97
- https://huggingface.co/Helsinki-NLP/opus-mt-en-fr
98
- ggml-opus-en-it
99
- https://huggingface.co/Helsinki-NLP/opus-mt-en-it
100
- ggml-opus-en-roa
101
- https://huggingface.co/Helsinki-NLP/opus-mt-en-roa
102
- ggml-opus-en-ru
103
- https://huggingface.co/Helsinki-NLP/opus-mt-en-ru
104
- ggml-opus-en-zh
105
- https://huggingface.co/Helsinki-NLP/opus-mt-en-zh
106
- ggml-opus-es-en
107
- https://huggingface.co/Helsinki-NLP/opus-mt-es-en
108
- ggml-opus-es-fr
109
- https://huggingface.co/Helsinki-NLP/opus-mt-es-fr
110
- ggml-opus-fr-de
111
- https://huggingface.co/Helsinki-NLP/opus-mt-fr-de
112
- ggml-opus-fr-en
113
- https://huggingface.co/Helsinki-NLP/opus-mt-fr-en
114
- ggml-opus-fr-es
115
- https://huggingface.co/Helsinki-NLP/opus-mt-fr-es
116
- ggml-opus-it-en
117
- https://huggingface.co/Helsinki-NLP/opus-mt-it-en
118
- ggml-opus-ja-en
119
- https://huggingface.co/Helsinki-NLP/opus-mt-ja-en
120
- ggml-opus-mt-en-roa-f16
121
- https://huggingface.co/Helsinki-NLP/opus-mt-en-roa
122
- ggml-opus-mt-roa-en-f16
123
- https://huggingface.co/Helsinki-NLP/opus-mt-roa-en
124
- ggml-opus-roa-en
125
- https://huggingface.co/Helsinki-NLP/opus-mt-roa-en
126
86
  gpt-oss-120b-Q4_K_M-00001-of-00002
127
87
  https://huggingface.co/unsloth/gpt-oss-120b-GGUF
128
88
  gpt-oss-20b-GGUF
@@ -216,14 +176,6 @@ Third-Party Model Licenses
216
176
  https://huggingface.co/nasedkinpv/parakeet-tdt-0.6b-v3-onnx-int8
217
177
  encoder-model
218
178
  https://huggingface.co/istupakov/parakeet-tdt-0.6b-v3-onnx
219
- ggml-opus-en-de
220
- https://huggingface.co/Helsinki-NLP/opus-mt-en-de
221
- ggml-opus-en-pt
222
- https://huggingface.co/Helsinki-NLP/opus-mt-tc-big-en-pt
223
- ggml-opus-ru-en
224
- https://huggingface.co/Helsinki-NLP/opus-mt-ru-en
225
- ggml-opus-zh-en
226
- https://huggingface.co/Helsinki-NLP/opus-mt-zh-en
227
179
  parakeet-ctc-0.6b-ONNX
228
180
  https://huggingface.co/onnx-community/parakeet-ctc-0.6b-ONNX
229
181
  parakeet-rs
@@ -376,7 +328,7 @@ Third-Party Model Licenses
376
328
  model.enis.intgemm.alphas
377
329
  https://github.com/mozilla/firefox-translations-models/tree/main/models/base-memory/enis
378
330
  model.enit.intgemm.alphas
379
- https://github.com/mozilla/firefox-translations-models/tree/main/models/tiny/enit
331
+ https://github.com/mozilla/firefox-translations-models/tree/main/models/base-memory/enit
380
332
  model.enja.intgemm.alphas
381
333
  https://github.com/mozilla/firefox-translations-models/tree/main/models/base-memory/enja
382
334
  model.enkn.intgemm.alphas
@@ -420,7 +372,7 @@ Third-Party Model Licenses
420
372
  model.enzh.intgemm.alphas
421
373
  https://github.com/mozilla/firefox-translations-models/tree/main/models/base-memory/enzh
422
374
  model.esen.intgemm.alphas
423
- https://github.com/mozilla/firefox-translations-models/tree/main/models/tiny/esen
375
+ https://github.com/mozilla/firefox-translations-models/tree/main/models/base-memory/esen
424
376
  model.eten.intgemm.alphas
425
377
  https://github.com/mozilla/firefox-translations-models/tree/main/models/base-memory/eten
426
378
  model.faen.intgemm.alphas
@@ -542,26 +494,21 @@ JavaScript Dependencies
542
494
  @qvac/decoder-audio@0.3.7
543
495
  https://github.com/tetherto/qvac
544
496
  @qvac/diagnostics@0.1.1
545
- @qvac/diffusion-cpp@0.1.3
497
+ @qvac/diffusion-cpp@0.3.0
546
498
  https://github.com/tetherto/qvac
547
- @qvac/dl-base@0.2.1
548
- https://github.com/tetherto/qvac
549
- @qvac/dl-filesystem@0.2.1
550
- https://github.com/tetherto/qvac
551
- @qvac/dl-hyperdrive@0.2.1
552
- https://github.com/tetherto/qvac
553
- @qvac/embed-llamacpp@0.13.4
499
+ @qvac/dl-base@0.1.1
500
+ @qvac/dl-hyperdrive@0.1.1
501
+ @qvac/embed-llamacpp@0.14.0
554
502
  https://github.com/tetherto/qvac
555
503
  @qvac/error@0.1.1
556
504
  @qvac/infer-base@0.1.1
557
- @qvac/infer-base@0.2.2
558
- @qvac/infer-base@0.3.1
559
- https://github.com/tetherto/qvac
560
505
  @qvac/infer-base@0.4.0
561
506
  https://github.com/tetherto/qvac
507
+ @qvac/infer-base@0.4.1
508
+ https://github.com/tetherto/qvac
562
509
  @qvac/langdetect-text@0.1.2
563
510
  https://github.com/tetherto/qvac
564
- @qvac/llm-llamacpp@0.14.4
511
+ @qvac/llm-llamacpp@0.17.3
565
512
  https://github.com/tetherto/qvac
566
513
  @qvac/logging@0.1.0
567
514
  @qvac/ocr-onnx@0.4.2
@@ -570,7 +517,7 @@ JavaScript Dependencies
570
517
  https://github.com/tetherto/qvac
571
518
  @qvac/rag@0.4.4
572
519
  https://github.com/tetherto/qvac
573
- @qvac/registry-client@0.4.0
520
+ @qvac/registry-client@0.4.1
574
521
  https://github.com/tetherto/qvac
575
522
  @qvac/registry-schema@0.1.2
576
523
  @qvac/response@0.1.2
@@ -578,9 +525,9 @@ JavaScript Dependencies
578
525
  https://github.com/tetherto/qvac
579
526
  @qvac/transcription-whispercpp@0.6.1
580
527
  https://github.com/tetherto/qvac
581
- @qvac/translation-nmtcpp@0.6.10
582
- https://github.com/tetherto/qvac-lib-infer-nmtcpp
583
- @qvac/tts-onnx@0.8.2
528
+ @qvac/translation-nmtcpp@2.1.0
529
+ https://github.com/tetherto/qvac
530
+ @qvac/tts-onnx@0.8.5
584
531
  https://github.com/tetherto/qvac
585
532
  adaptive-timeout@1.0.1
586
533
  https://github.com/holepunchto/adaptive-timeout
@@ -630,9 +577,9 @@ JavaScript Dependencies
630
577
  https://github.com/holepunchto/bare-https
631
578
  bare-inspect@3.1.4
632
579
  https://github.com/holepunchto/bare-inspect
633
- bare-lief@0.1.6
580
+ bare-lief@0.2.3
634
581
  https://github.com/holepunchto/bare-lief
635
- bare-link@2.1.10
582
+ bare-link@3.2.1
636
583
  https://github.com/holepunchto/bare-link
637
584
  bare-module@6.1.3
638
585
  https://github.com/holepunchto/bare-module
@@ -28,7 +28,7 @@ import { type CancelParams } from "../../schemas/index";
28
28
  * await cancel({
29
29
  * operation: "downloadAsset",
30
30
  * downloadKey: "download-key",
31
- * delegate: { topic: "topicHex", providerPublicKey: "peerHex" },
31
+ * delegate: { providerPublicKey: "peerHex" },
32
32
  * });
33
33
  *
34
34
  * @example
@@ -30,7 +30,7 @@ import { InvalidResponseError, CancelFailedError } from "../../utils/errors-clie
30
30
  * await cancel({
31
31
  * operation: "downloadAsset",
32
32
  * downloadKey: "download-key",
33
- * delegate: { topic: "topicHex", providerPublicKey: "peerHex" },
33
+ * delegate: { providerPublicKey: "peerHex" },
34
34
  * });
35
35
  *
36
36
  * @example
@@ -1,19 +1,50 @@
1
- import { type CompletionClientParams, type CompletionStats, type McpClientInput, type Tool, type ToolCallEvent, type ToolCallWithCall, type RPCOptions } from "../../schemas/index";
1
+ import { type CompletionClientParams, type CompletionRun, type McpClientInput, type Tool, type RPCOptions } from "../../schemas/index";
2
2
  import { type ToolInput } from "../../utils/tool-helpers";
3
3
  type CompletionParams = Omit<CompletionClientParams, "tools"> & {
4
4
  tools?: Tool[] | ToolInput[];
5
5
  mcp?: McpClientInput[];
6
6
  rpcOptions?: RPCOptions;
7
+ captureThinking?: boolean;
8
+ emitRawDeltas?: boolean;
7
9
  };
8
10
  /**
9
11
  * Generates completion from a language model based on conversation history.
10
12
  *
13
+ * Returns a `CompletionRun` whose canonical surfaces are:
14
+ *
15
+ * - `events` — `AsyncIterable<CompletionEvent>` of ordered, typed events.
16
+ * - `final` — `Promise<CompletionFinal>` with aggregated results once the
17
+ * stream ends (content, thinking, tool calls, stats, raw text).
18
+ *
19
+ * Legacy convenience fields (`tokenStream`, `text`, `toolCallStream`,
20
+ * `toolCalls`, `stats`) are still available but deprecated — they derive
21
+ * from `events` / `final` internally.
22
+ *
11
23
  * @param params - The completion parameters
12
24
  * @param params.modelId - The identifier of the model to use for completion
13
25
  * @param params.history - Array of conversation messages with role, content, and optional attachments
14
26
  * @param params.stream - Whether to stream tokens (true) or return complete response (false). Defaults to true
15
27
  * @param params.tools - Optional array of tools (can be simple ToolInput with Zod schemas or full Tool objects)
16
28
  * @param params.mcp - Optional array of MCP client inputs for tool integration
29
+ * @param params.captureThinking - Best-effort parsing of `<think>` blocks into `thinkingDelta` events; `final.raw.fullText` always preserves the original output
30
+ * @param params.emitRawDeltas - When true, every raw model token is also emitted as a `rawDelta` event
31
+ * @param params.toolDialect - Override the SDK's name-based dialect detection. Use when your model emits a known format (`"hermes"`, `"pythonic"`, or `"json"`) the auto-router doesn't recognise. Drives both streaming frame detection and finalization parsing.
32
+ * Common override case: Llama 3.x tool-calling fine-tunes that emit the native pythonic header (`<|start_header_id|>tool_call<|end_header_id|>...<|eot_id|>`).
33
+ * @param params.responseFormat - Optional structured-output constraint applied to the model's output:
34
+ * - `{ type: "text" }` — no constraint (default behavior)
35
+ * - `{ type: "json_object" }` — output must be a JSON object
36
+ * - `{ type: "json_schema", json_schema: { name, schema, description?, strict? } }` — output must validate against `schema`
37
+ *
38
+ * The schema is converted to GBNF natively by llama.cpp and applied for the
39
+ * duration of the request only. `json_schema.name` and `json_schema.description`
40
+ * are accepted for OpenAI compatibility but only used at the API boundary —
41
+ * they do not affect generation. **`json_schema.strict` is currently accepted
42
+ * for compatibility but does NOT trigger OpenAI's auto-tightening semantics**
43
+ * (implicit `additionalProperties: false`, all properties required). The
44
+ * schema is forwarded to the addon as-is, so callers who want strict
45
+ * validation must encode it explicitly in `schema`.
46
+ *
47
+ * Cannot be combined with `tools` (tools already constrain output via their parameter schema).
17
48
  * @param params.kvCache - Optional KV cache configuration. Cache files are organized hierarchically:
18
49
  * - Structure: `{kvCacheKey}/{modelId}/{configHash}.bin`
19
50
  * - The configHash includes model config + system prompt to ensure cache isolation
@@ -22,17 +53,29 @@ type CompletionParams = Omit<CompletionClientParams, "tools"> & {
22
53
  * - `false` or `undefined`: No caching
23
54
  * - ⚡ Performance: When cache exists, only the last message is sent to the model (includes multimodal attachments)
24
55
  * - 🗑️ Cleanup: Use `deleteCache({ kvCacheKey })` to remove cached sessions
25
- * @returns Object with tokenStream generator, toolCallStream generator, text promise, toolCalls promise (with call() method), and stats promise
56
+ *
57
+ * **Auto-cache (`kvCache: true`) — assistant turn contract.** When
58
+ * pushing the assistant turn back into `history` for the next call,
59
+ * use `(await run.final).cacheableAssistantContent`. That's the exact
60
+ * string the SDK persisted to the cache key on this turn, so re-using
61
+ * it verbatim guarantees the next-turn lookup hits.
62
+ * - Any post-processing of the assistant text (rewriting, summarizing,
63
+ * stripping model stop tokens like `<|im_end|>`) before pushing it
64
+ * back will miss the cache. Push the canonical string unchanged.
65
+ * - `cacheableAssistantContent` is omitted on tool-call turns - those
66
+ * can't be auto-cached today.
67
+ * @returns A CompletionRun — consume via `events` / `final`.
26
68
  * @example
27
69
  * ```typescript
28
70
  * import { z } from "zod";
29
71
  *
30
- * const result = completion({
72
+ * const run = completion({
31
73
  * modelId: "llama-2",
32
74
  * history: [
33
75
  * { role: "user", content: "What's the weather in Tokyo?" }
34
76
  * ],
35
77
  * stream: true,
78
+ * captureThinking: true,
36
79
  * tools: [{
37
80
  * name: "get_weather",
38
81
  * description: "Get current weather",
@@ -45,10 +88,12 @@ type CompletionParams = Omit<CompletionClientParams, "tools"> & {
45
88
  * }]
46
89
  * });
47
90
  *
48
- * for await (const token of result.tokenStream) {
49
- * process.stdout.write(token);
91
+ * for await (const event of run.events) {
92
+ * if (event.type === "contentDelta") process.stdout.write(event.text);
93
+ * if (event.type === "toolCall") console.log(event.call.name, event.call.arguments);
50
94
  * }
51
95
  *
96
+ * const result = await run.final;
52
97
  * for (const toolCall of await result.toolCalls) {
53
98
  * if (toolCall.invoke) {
54
99
  * const toolResult = await toolCall.invoke();
@@ -57,12 +102,6 @@ type CompletionParams = Omit<CompletionClientParams, "tools"> & {
57
102
  * }
58
103
  * ```
59
104
  */
60
- export declare function completion(params: CompletionParams): {
61
- tokenStream: AsyncGenerator<string>;
62
- toolCallStream: AsyncGenerator<ToolCallEvent>;
63
- stats: Promise<CompletionStats | undefined>;
64
- text: Promise<string>;
65
- toolCalls: Promise<ToolCallWithCall[]>;
66
- };
105
+ export declare function completion(params: CompletionParams): CompletionRun;
67
106
  export {};
68
107
  //# sourceMappingURL=completion-stream.d.ts.map
@@ -1,18 +1,49 @@
1
1
  import { stream as streamRpc } from "../rpc/rpc-client.js";
2
2
  import { getClientLogger } from "../../logging/index.js";
3
3
  import { completionStreamResponseSchema, } from "../../schemas/index.js";
4
+ import { CompletionFailedError } from "../../utils/errors-server.js";
4
5
  import { getMcpToolsWithHandlers } from "../../utils/mcp-adapter.js";
5
- import { attachHandlersToToolCalls, validateTools, } from "../../utils/tool-helpers.js";
6
+ import { validateTools, } from "../../utils/tool-helpers.js";
7
+ import { buildFinalFromEvents } from "../../utils/aggregate-events.js";
6
8
  const logger = getClientLogger();
7
9
  /**
8
10
  * Generates completion from a language model based on conversation history.
9
11
  *
12
+ * Returns a `CompletionRun` whose canonical surfaces are:
13
+ *
14
+ * - `events` — `AsyncIterable<CompletionEvent>` of ordered, typed events.
15
+ * - `final` — `Promise<CompletionFinal>` with aggregated results once the
16
+ * stream ends (content, thinking, tool calls, stats, raw text).
17
+ *
18
+ * Legacy convenience fields (`tokenStream`, `text`, `toolCallStream`,
19
+ * `toolCalls`, `stats`) are still available but deprecated — they derive
20
+ * from `events` / `final` internally.
21
+ *
10
22
  * @param params - The completion parameters
11
23
  * @param params.modelId - The identifier of the model to use for completion
12
24
  * @param params.history - Array of conversation messages with role, content, and optional attachments
13
25
  * @param params.stream - Whether to stream tokens (true) or return complete response (false). Defaults to true
14
26
  * @param params.tools - Optional array of tools (can be simple ToolInput with Zod schemas or full Tool objects)
15
27
  * @param params.mcp - Optional array of MCP client inputs for tool integration
28
+ * @param params.captureThinking - Best-effort parsing of `<think>` blocks into `thinkingDelta` events; `final.raw.fullText` always preserves the original output
29
+ * @param params.emitRawDeltas - When true, every raw model token is also emitted as a `rawDelta` event
30
+ * @param params.toolDialect - Override the SDK's name-based dialect detection. Use when your model emits a known format (`"hermes"`, `"pythonic"`, or `"json"`) the auto-router doesn't recognise. Drives both streaming frame detection and finalization parsing.
31
+ * Common override case: Llama 3.x tool-calling fine-tunes that emit the native pythonic header (`<|start_header_id|>tool_call<|end_header_id|>...<|eot_id|>`).
32
+ * @param params.responseFormat - Optional structured-output constraint applied to the model's output:
33
+ * - `{ type: "text" }` — no constraint (default behavior)
34
+ * - `{ type: "json_object" }` — output must be a JSON object
35
+ * - `{ type: "json_schema", json_schema: { name, schema, description?, strict? } }` — output must validate against `schema`
36
+ *
37
+ * The schema is converted to GBNF natively by llama.cpp and applied for the
38
+ * duration of the request only. `json_schema.name` and `json_schema.description`
39
+ * are accepted for OpenAI compatibility but only used at the API boundary —
40
+ * they do not affect generation. **`json_schema.strict` is currently accepted
41
+ * for compatibility but does NOT trigger OpenAI's auto-tightening semantics**
42
+ * (implicit `additionalProperties: false`, all properties required). The
43
+ * schema is forwarded to the addon as-is, so callers who want strict
44
+ * validation must encode it explicitly in `schema`.
45
+ *
46
+ * Cannot be combined with `tools` (tools already constrain output via their parameter schema).
16
47
  * @param params.kvCache - Optional KV cache configuration. Cache files are organized hierarchically:
17
48
  * - Structure: `{kvCacheKey}/{modelId}/{configHash}.bin`
18
49
  * - The configHash includes model config + system prompt to ensure cache isolation
@@ -21,17 +52,29 @@ const logger = getClientLogger();
21
52
  * - `false` or `undefined`: No caching
22
53
  * - ⚡ Performance: When cache exists, only the last message is sent to the model (includes multimodal attachments)
23
54
  * - 🗑️ Cleanup: Use `deleteCache({ kvCacheKey })` to remove cached sessions
24
- * @returns Object with tokenStream generator, toolCallStream generator, text promise, toolCalls promise (with call() method), and stats promise
55
+ *
56
+ * **Auto-cache (`kvCache: true`) — assistant turn contract.** When
57
+ * pushing the assistant turn back into `history` for the next call,
58
+ * use `(await run.final).cacheableAssistantContent`. That's the exact
59
+ * string the SDK persisted to the cache key on this turn, so re-using
60
+ * it verbatim guarantees the next-turn lookup hits.
61
+ * - Any post-processing of the assistant text (rewriting, summarizing,
62
+ * stripping model stop tokens like `<|im_end|>`) before pushing it
63
+ * back will miss the cache. Push the canonical string unchanged.
64
+ * - `cacheableAssistantContent` is omitted on tool-call turns - those
65
+ * can't be auto-cached today.
66
+ * @returns A CompletionRun — consume via `events` / `final`.
25
67
  * @example
26
68
  * ```typescript
27
69
  * import { z } from "zod";
28
70
  *
29
- * const result = completion({
71
+ * const run = completion({
30
72
  * modelId: "llama-2",
31
73
  * history: [
32
74
  * { role: "user", content: "What's the weather in Tokyo?" }
33
75
  * ],
34
76
  * stream: true,
77
+ * captureThinking: true,
35
78
  * tools: [{
36
79
  * name: "get_weather",
37
80
  * description: "Get current weather",
@@ -44,10 +87,12 @@ const logger = getClientLogger();
44
87
  * }]
45
88
  * });
46
89
  *
47
- * for await (const token of result.tokenStream) {
48
- * process.stdout.write(token);
90
+ * for await (const event of run.events) {
91
+ * if (event.type === "contentDelta") process.stdout.write(event.text);
92
+ * if (event.type === "toolCall") console.log(event.call.name, event.call.arguments);
49
93
  * }
50
94
  *
95
+ * const result = await run.final;
51
96
  * for (const toolCall of await result.toolCalls) {
52
97
  * if (toolCall.invoke) {
53
98
  * const toolResult = await toolCall.invoke();
@@ -57,7 +102,6 @@ const logger = getClientLogger();
57
102
  * ```
58
103
  */
59
104
  export function completion(params) {
60
- let stats;
61
105
  let statsResolver = () => { };
62
106
  let statsRejecter = () => { };
63
107
  const statsPromise = new Promise((resolve, reject) => {
@@ -65,7 +109,6 @@ export function completion(params) {
65
109
  statsRejecter = reject;
66
110
  });
67
111
  statsPromise.catch(() => { });
68
- let toolCallsArray = [];
69
112
  let toolCallsResolver = () => { };
70
113
  let toolCallsRejecter = () => { };
71
114
  const toolCallsPromise = new Promise((resolve, reject) => {
@@ -73,14 +116,36 @@ export function completion(params) {
73
116
  toolCallsRejecter = reject;
74
117
  });
75
118
  toolCallsPromise.catch(() => { });
119
+ let finalResolver = () => { };
120
+ let finalRejecter = () => { };
121
+ const finalPromise = new Promise((resolve, reject) => {
122
+ finalResolver = resolve;
123
+ finalRejecter = reject;
124
+ });
125
+ finalPromise.catch(() => { });
76
126
  const tokenQueue = [];
77
127
  const toolEventQueue = [];
78
- let tokenDone = false;
79
- let toolDone = false;
128
+ const eventQueue = [];
129
+ let done = false;
80
130
  let tokenResolve = null;
81
131
  let toolResolve = null;
82
- let textBuffer = "";
132
+ let eventResolve = null;
83
133
  let streamError = null;
134
+ const allEvents = [];
135
+ function notifyWaiters() {
136
+ if (tokenResolve) {
137
+ tokenResolve();
138
+ tokenResolve = null;
139
+ }
140
+ if (toolResolve) {
141
+ toolResolve();
142
+ toolResolve = null;
143
+ }
144
+ if (eventResolve) {
145
+ eventResolve();
146
+ eventResolve = null;
147
+ }
148
+ }
84
149
  const processResponses = async () => {
85
150
  try {
86
151
  let allTools = [];
@@ -113,6 +178,10 @@ export function completion(params) {
113
178
  tools: allTools.length > 0 ? allTools : undefined,
114
179
  stream: params.stream ?? true,
115
180
  generationParams: params.generationParams,
181
+ captureThinking: params.captureThinking,
182
+ emitRawDeltas: params.emitRawDeltas,
183
+ toolDialect: params.toolDialect,
184
+ responseFormat: params.responseFormat,
116
185
  };
117
186
  const responses = streamRpc(request, params.rpcOptions);
118
187
  for await (const response of responses) {
@@ -121,43 +190,32 @@ export function completion(params) {
121
190
  "type" in response &&
122
191
  response.type === "completionStream") {
123
192
  const streamResponse = completionStreamResponseSchema.parse(response);
124
- if (!streamResponse.done) {
125
- const token = streamResponse.token;
126
- if (token) {
127
- textBuffer += token;
128
- tokenQueue.push(token);
129
- if (tokenResolve) {
130
- tokenResolve();
131
- tokenResolve = null;
132
- }
193
+ for (const event of streamResponse.events) {
194
+ allEvents.push(event);
195
+ eventQueue.push(event);
196
+ if (event.type === "contentDelta") {
197
+ tokenQueue.push(event.text);
133
198
  }
134
- if (streamResponse.toolCallEvent) {
135
- toolEventQueue.push(streamResponse.toolCallEvent);
136
- if (toolResolve) {
137
- toolResolve();
138
- toolResolve = null;
139
- }
199
+ else if (event.type === "toolCall") {
200
+ toolEventQueue.push(event);
140
201
  }
141
202
  }
142
- else {
143
- if (streamResponse.token) {
144
- textBuffer += streamResponse.token;
145
- }
146
- stats = streamResponse.stats;
147
- statsResolver(stats);
148
- const rawToolCalls = streamResponse.toolCalls || [];
149
- toolCallsArray = attachHandlersToToolCalls(rawToolCalls, allHandlers);
150
- toolCallsResolver(toolCallsArray);
151
- tokenDone = true;
152
- toolDone = true;
153
- if (tokenResolve) {
154
- tokenResolve();
155
- tokenResolve = null;
203
+ notifyWaiters();
204
+ if (streamResponse.done) {
205
+ const { final, error } = buildFinalFromEvents(allEvents, allHandlers);
206
+ if (error) {
207
+ const err = new CompletionFailedError(error.message, error);
208
+ finalRejecter(err);
209
+ statsRejecter(err);
210
+ toolCallsRejecter(err);
156
211
  }
157
- if (toolResolve) {
158
- toolResolve();
159
- toolResolve = null;
212
+ else {
213
+ finalResolver(final);
214
+ statsResolver(final.stats);
215
+ toolCallsResolver(final.toolCalls);
160
216
  }
217
+ done = true;
218
+ notifyWaiters();
161
219
  }
162
220
  }
163
221
  }
@@ -166,31 +224,42 @@ export function completion(params) {
166
224
  streamError = error instanceof Error ? error : new Error(String(error));
167
225
  statsRejecter(error);
168
226
  toolCallsRejecter(error);
169
- tokenDone = true;
170
- toolDone = true;
171
- if (tokenResolve) {
172
- tokenResolve();
173
- tokenResolve = null;
174
- }
175
- if (toolResolve) {
176
- toolResolve();
177
- toolResolve = null;
178
- }
227
+ finalRejecter(error);
228
+ done = true;
229
+ notifyWaiters();
179
230
  }
180
231
  };
181
232
  void processResponses();
182
233
  const textPromise = (async () => {
183
- await statsPromise;
184
- return textBuffer;
234
+ const final = await finalPromise;
235
+ return final.contentText;
185
236
  })();
186
237
  textPromise.catch(() => { });
238
+ const eventStream = (async function* () {
239
+ while (true) {
240
+ if (eventQueue.length > 0) {
241
+ yield eventQueue.shift();
242
+ }
243
+ else if (done) {
244
+ if (streamError !== null) {
245
+ throw streamError;
246
+ }
247
+ break;
248
+ }
249
+ else {
250
+ await new Promise((resolve) => {
251
+ eventResolve = resolve;
252
+ });
253
+ }
254
+ }
255
+ })();
187
256
  if (params.stream) {
188
257
  const tokenStream = (async function* () {
189
258
  while (true) {
190
259
  if (tokenQueue.length > 0) {
191
260
  yield tokenQueue.shift();
192
261
  }
193
- else if (tokenDone) {
262
+ else if (done) {
194
263
  if (streamError !== null) {
195
264
  throw streamError;
196
265
  }
@@ -208,7 +277,7 @@ export function completion(params) {
208
277
  if (toolEventQueue.length > 0) {
209
278
  yield toolEventQueue.shift();
210
279
  }
211
- else if (toolDone) {
280
+ else if (done) {
212
281
  if (streamError !== null) {
213
282
  throw streamError;
214
283
  }
@@ -222,6 +291,8 @@ export function completion(params) {
222
291
  }
223
292
  })();
224
293
  return {
294
+ events: eventStream,
295
+ final: finalPromise,
225
296
  tokenStream,
226
297
  toolCallStream,
227
298
  text: textPromise,
@@ -237,6 +308,8 @@ export function completion(params) {
237
308
  //Empty generator for non-streaming mode
238
309
  })();
239
310
  return {
311
+ events: eventStream,
312
+ final: finalPromise,
240
313
  tokenStream,
241
314
  toolCallStream,
242
315
  text: textPromise,
@@ -6,6 +6,7 @@
6
6
  * @param params.kvCacheKey - The cache key to delete
7
7
  * @param params.modelId - Optional: specific model ID to delete within the cache key. If not provided, deletes entire cache key.
8
8
  * @returns Promise resolving to success status
9
+ * @throws {QvacErrorBase} When the cache parameters are invalid (`InvalidDeleteCacheParamsError`) or the server reports a delete failure (`DeleteCacheFailedError`).
9
10
  * @example
10
11
  * ```typescript
11
12
  * // Delete all caches
@@ -8,6 +8,7 @@ import { InvalidDeleteCacheParamsError, DeleteCacheFailedError, } from "../../ut
8
8
  * @param params.kvCacheKey - The cache key to delete
9
9
  * @param params.modelId - Optional: specific model ID to delete within the cache key. If not provided, deletes entire cache key.
10
10
  * @returns Promise resolving to success status
11
+ * @throws {QvacErrorBase} When the cache parameters are invalid (`InvalidDeleteCacheParamsError`) or the server reports a delete failure (`DeleteCacheFailedError`).
11
12
  * @example
12
13
  * ```typescript
13
14
  * // Delete all caches
@@ -10,15 +10,30 @@ interface DiffusionResult {
10
10
  stats: Promise<DiffusionStats | undefined>;
11
11
  }
12
12
  /**
13
- * Generate images using a loaded diffusion model.
13
+ * Generates images using a loaded diffusion model.
14
+ *
15
+ * @param params - Diffusion request parameters (model, prompt, dimensions, sampler, seed, etc.).
16
+ * @returns A result object exposing `progressStream` (async iterator of `{ step, totalSteps, elapsedMs }`), `outputs` (promise of the generated image buffers), and `stats` (promise of generation statistics).
17
+ *
18
+ * Supports both txt2img (no `init_image`) and img2img (with `init_image`).
14
19
  *
15
20
  * @example
16
21
  * ```typescript
17
- * // Basic usage
22
+ * // txt2img
18
23
  * const { outputs, stats } = diffusion({ modelId, prompt: "a cat" });
19
24
  * const buffers = await outputs;
20
25
  * fs.writeFileSync("output.png", buffers[0]);
21
26
  *
27
+ * // img2img (SD/SDXL — SDEdit)
28
+ * const initImage = fs.readFileSync("input.png");
29
+ * const { outputs } = diffusion({ modelId, prompt: "oil painting style", init_image: initImage, strength: 0.7 });
30
+ *
31
+ * // img2img (FLUX.2 — in-context conditioning)
32
+ * // IMPORTANT: FLUX img2img requires `prediction: "flux2_flow"` to be set on the
33
+ * // model config at loadModel time (e.g. `loadModel(src, { modelType: "diffusion",
34
+ * // modelConfig: { prediction: "flux2_flow" } })`).
35
+ * const { outputs } = diffusion({ modelId, prompt: "turn into watercolor", init_image: initImage });
36
+ *
22
37
  * // With progress tracking
23
38
  * const { progressStream, outputs } = diffusion({ modelId, prompt: "a cat" });
24
39
  * for await (const { step, totalSteps } of progressStream) {