@qvac/inference 0.23.0 → 0.24.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 (426) hide show
  1. package/NOTICE +60 -28
  2. package/README.md +3 -1
  3. package/dist/api/assess-model-fit.d.ts +14 -14
  4. package/dist/api/assess-model-fit.js +14 -14
  5. package/dist/api/audio-gen.d.ts +2 -2
  6. package/dist/api/audio-gen.js +135 -44
  7. package/dist/api/batch-completion.js +2 -1
  8. package/dist/api/calc-tokens.d.ts +30 -0
  9. package/dist/api/calc-tokens.js +41 -0
  10. package/dist/api/classify.d.ts +5 -2
  11. package/dist/api/classify.js +5 -2
  12. package/dist/api/completion-stream.d.ts +1 -1
  13. package/dist/api/completion-stream.js +2 -1
  14. package/dist/api/delete-cache.d.ts +7 -1
  15. package/dist/api/delete-cache.js +11 -1
  16. package/dist/api/diffusion.d.ts +14 -1
  17. package/dist/api/diffusion.js +14 -1
  18. package/dist/api/embed.d.ts +82 -29
  19. package/dist/api/embed.js +64 -18
  20. package/dist/api/get-model-info.d.ts +1 -1
  21. package/dist/api/index.d.ts +2 -1
  22. package/dist/api/index.js +2 -1
  23. package/dist/api/rag.d.ts +1 -1
  24. package/dist/api/rag.js +1 -1
  25. package/dist/api/registry.d.ts +16 -6
  26. package/dist/api/registry.js +32 -9
  27. package/dist/api/text-to-speech.d.ts +14 -5
  28. package/dist/api/text-to-speech.js +83 -29
  29. package/dist/api/transcribe.d.ts +6 -2
  30. package/dist/api/transcribe.js +7 -1
  31. package/dist/api/vector-index.d.ts +25 -3
  32. package/dist/api/vector-index.js +17 -2
  33. package/dist/api/video-request.d.ts +15 -15
  34. package/dist/dispatch.d.ts +10 -4
  35. package/dist/dispatch.js +65 -15
  36. package/dist/engine.d.ts +1 -1
  37. package/dist/errors/index.d.ts +70 -0
  38. package/dist/errors/index.js +128 -0
  39. package/dist/handlers/assess-model-fit.d.ts +3 -21
  40. package/dist/handlers/assess-model-fit.js +4 -303
  41. package/dist/handlers/cancelHandler.d.ts +10 -9
  42. package/dist/handlers/cancelHandler.js +17 -13
  43. package/dist/handlers/completion-orchestrate.d.ts +14 -2
  44. package/dist/handlers/completion-orchestrate.js +164 -22
  45. package/dist/handlers/delete-cache.d.ts +2 -1
  46. package/dist/handlers/delete-cache.js +6 -1
  47. package/dist/handlers/download-asset.js +11 -4
  48. package/dist/handlers/get-loaded-model-info.js +1 -0
  49. package/dist/handlers/get-model-info.js +71 -2
  50. package/dist/handlers/load-model/coreml-sidecars.d.ts +2 -13
  51. package/dist/handlers/load-model/coreml-sidecars.js +16 -119
  52. package/dist/handlers/load-model/download-lock.d.ts +20 -0
  53. package/dist/handlers/load-model/download-lock.js +213 -0
  54. package/dist/handlers/load-model/download-manager.d.ts +10 -2
  55. package/dist/handlers/load-model/download-manager.js +62 -11
  56. package/dist/handlers/load-model/handler.js +88 -35
  57. package/dist/handlers/load-model/http.js +327 -205
  58. package/dist/handlers/load-model/hyperdrive.d.ts +15 -0
  59. package/dist/handlers/load-model/hyperdrive.js +123 -50
  60. package/dist/handlers/load-model/registry-client-options.d.ts +2 -0
  61. package/dist/handlers/load-model/registry-client-options.js +4 -2
  62. package/dist/handlers/load-model/registry-companion-set.d.ts +5 -0
  63. package/dist/handlers/load-model/registry-companion-set.js +19 -1
  64. package/dist/handlers/load-model/registry-delete.d.ts +5 -0
  65. package/dist/handlers/load-model/registry-delete.js +269 -0
  66. package/dist/handlers/load-model/registry-download-utils.d.ts +4 -2
  67. package/dist/handlers/load-model/registry-download-utils.js +93 -22
  68. package/dist/handlers/load-model/registry.d.ts +20 -0
  69. package/dist/handlers/load-model/registry.js +308 -175
  70. package/dist/handlers/load-model/resolve.js +4 -1
  71. package/dist/handlers/load-model/types.d.ts +2 -0
  72. package/dist/handlers/logging-stream.js +17 -5
  73. package/dist/handlers/plugin-invoke.js +152 -39
  74. package/dist/handlers/registry.d.ts +2 -2
  75. package/dist/handlers/registry.js +105 -28
  76. package/dist/handlers/rpc-server.js +7 -7
  77. package/dist/handlers/session.d.ts +11 -0
  78. package/dist/handlers/session.js +40 -0
  79. package/dist/handlers/unload-model.js +8 -3
  80. package/dist/handlers/vector-index.js +118 -19
  81. package/dist/index.d.ts +1 -1
  82. package/dist/index.js +1 -1
  83. package/dist/logging/utils.js +10 -2
  84. package/dist/model-cache-layout.d.ts +1 -0
  85. package/dist/model-cache-layout.js +2 -0
  86. package/dist/model-fit/assess.d.ts +18 -67
  87. package/dist/model-fit/assess.js +96 -665
  88. package/dist/model-fit/describe.d.ts +12 -0
  89. package/dist/model-fit/describe.js +29 -0
  90. package/dist/model-fit/description/fetch.d.ts +1 -1
  91. package/dist/model-fit/description/fetch.js +95 -16
  92. package/dist/model-fit/description/resolve-load.d.ts +5 -3
  93. package/dist/model-fit/description/resolve-load.js +14 -14
  94. package/dist/model-fit/fit-load.d.ts +23 -0
  95. package/dist/model-fit/fit-load.js +29 -0
  96. package/dist/model-fit/load-check.d.ts +15 -33
  97. package/dist/model-fit/load-check.js +50 -195
  98. package/dist/model-fit/run/engine.d.ts +12 -72
  99. package/dist/model-fit/run/engine.js +4 -8
  100. package/dist/model-fit/run/run.d.ts +10 -7
  101. package/dist/model-fit/run/run.js +22 -18
  102. package/dist/model-fit/sum.d.ts +32 -0
  103. package/dist/model-fit/sum.js +60 -0
  104. package/dist/models/registry/models.d.ts +865 -128
  105. package/dist/models/registry/models.js +3737 -2963
  106. package/dist/plugins/builtin/asr-ggml/config.d.ts +19 -4
  107. package/dist/plugins/builtin/asr-ggml/config.js +39 -3
  108. package/dist/plugins/builtin/asr-ggml/fit.d.ts +18 -0
  109. package/dist/{model-fit/request/engines/asr.js → plugins/builtin/asr-ggml/fit.js} +55 -71
  110. package/dist/plugins/builtin/audiogen-ggml/config.d.ts +6 -0
  111. package/dist/plugins/builtin/audiogen-ggml/config.js +9 -0
  112. package/dist/plugins/builtin/audiogen-ggml/fit.d.ts +3 -0
  113. package/dist/{model-fit/request/engines/audiogen.js → plugins/builtin/audiogen-ggml/fit.js} +28 -18
  114. package/dist/plugins/builtin/audiogen-ggml/ops/audio-edit-stream.d.ts +3 -1
  115. package/dist/plugins/builtin/audiogen-ggml/ops/audio-edit-stream.js +2 -1
  116. package/dist/plugins/builtin/audiogen-ggml/ops/audio-gen-encode.d.ts +17 -0
  117. package/dist/plugins/builtin/audiogen-ggml/ops/audio-gen-encode.js +68 -0
  118. package/dist/plugins/builtin/audiogen-ggml/ops/audio-gen-run.d.ts +11 -3
  119. package/dist/plugins/builtin/audiogen-ggml/ops/audio-gen-run.js +47 -11
  120. package/dist/plugins/builtin/audiogen-ggml/ops/audio-gen-stream.d.ts +3 -1
  121. package/dist/plugins/builtin/audiogen-ggml/ops/audio-gen-stream.js +2 -1
  122. package/dist/plugins/builtin/audiogen-ggml/ops/audio-understand.d.ts +3 -1
  123. package/dist/plugins/builtin/audiogen-ggml/ops/audio-understand.js +2 -1
  124. package/dist/plugins/builtin/audiogen-ggml/plugin.d.ts +143 -18
  125. package/dist/plugins/builtin/audiogen-ggml/plugin.js +13 -1
  126. package/dist/plugins/builtin/bci-whispercpp-transcription/fit.d.ts +3 -0
  127. package/dist/plugins/builtin/bci-whispercpp-transcription/fit.js +22 -0
  128. package/dist/plugins/builtin/bci-whispercpp-transcription/plugin.d.ts +45 -4
  129. package/dist/plugins/builtin/bci-whispercpp-transcription/plugin.js +8 -6
  130. package/dist/plugins/builtin/ggml-classification/plugin.d.ts +4 -1
  131. package/dist/plugins/builtin/ggml-classification/plugin.js +88 -8
  132. package/dist/plugins/builtin/ggml-image-embedding/ops/embed.d.ts +24 -0
  133. package/dist/plugins/builtin/ggml-image-embedding/ops/embed.js +184 -0
  134. package/dist/plugins/builtin/ggml-image-embedding/plugin.d.ts +120 -0
  135. package/dist/plugins/builtin/ggml-image-embedding/plugin.js +39 -0
  136. package/dist/plugins/builtin/ggml-ocr/fit.d.ts +6 -0
  137. package/dist/plugins/builtin/ggml-ocr/fit.js +19 -0
  138. package/dist/plugins/builtin/ggml-ocr/params.d.ts +1 -1
  139. package/dist/plugins/builtin/ggml-ocr/plugin.d.ts +9 -3
  140. package/dist/plugins/builtin/ggml-ocr/plugin.js +107 -21
  141. package/dist/plugins/builtin/ggml-vla/ops/vla-run.d.ts +2 -2
  142. package/dist/plugins/builtin/ggml-vla/ops/vla-run.js +18 -2
  143. package/dist/plugins/builtin/ggml-vla/plugin.d.ts +3 -3
  144. package/dist/plugins/builtin/index.d.ts +1 -0
  145. package/dist/plugins/builtin/index.js +1 -0
  146. package/dist/plugins/builtin/llamacpp-completion/fit.d.ts +3 -0
  147. package/dist/plugins/builtin/llamacpp-completion/fit.js +28 -0
  148. package/dist/plugins/builtin/llamacpp-completion/ops/batch-completion-stream.js +1 -1
  149. package/dist/plugins/builtin/llamacpp-completion/ops/cache-logger.js +15 -4
  150. package/dist/plugins/builtin/llamacpp-completion/ops/calc-tokens.d.ts +2 -0
  151. package/dist/plugins/builtin/llamacpp-completion/ops/calc-tokens.js +32 -0
  152. package/dist/plugins/builtin/llamacpp-completion/ops/completion-stats.d.ts +1 -1
  153. package/dist/plugins/builtin/llamacpp-completion/ops/completion-stream.d.ts +17 -3
  154. package/dist/plugins/builtin/llamacpp-completion/ops/completion-stream.js +61 -5
  155. package/dist/plugins/builtin/llamacpp-completion/ops/finetune.d.ts +5 -4
  156. package/dist/plugins/builtin/llamacpp-completion/ops/finetune.js +54 -19
  157. package/dist/plugins/builtin/llamacpp-completion/plugin.d.ts +148 -19
  158. package/dist/plugins/builtin/llamacpp-completion/plugin.js +26 -9
  159. package/dist/plugins/builtin/llamacpp-decision/ops/decide.d.ts +3 -1
  160. package/dist/plugins/builtin/llamacpp-decision/ops/decide.js +5 -2
  161. package/dist/plugins/builtin/llamacpp-decision/plugin.d.ts +4 -2
  162. package/dist/plugins/builtin/llamacpp-decision/plugin.js +2 -2
  163. package/dist/plugins/builtin/llamacpp-embedding/fit.d.ts +3 -0
  164. package/dist/plugins/builtin/llamacpp-embedding/fit.js +23 -0
  165. package/dist/plugins/builtin/llamacpp-embedding/plugin.d.ts +194 -4
  166. package/dist/plugins/builtin/llamacpp-embedding/plugin.js +37 -11
  167. package/dist/plugins/builtin/llamacpp-embedding/transform.d.ts +2 -2
  168. package/dist/plugins/builtin/llamacpp-embedding/transform.js +23 -2
  169. package/dist/plugins/builtin/llamacpp-rerank/ops/rerank.d.ts +3 -1
  170. package/dist/plugins/builtin/llamacpp-rerank/ops/rerank.js +5 -2
  171. package/dist/plugins/builtin/llamacpp-rerank/plugin.d.ts +6 -5
  172. package/dist/plugins/builtin/llamacpp-rerank/plugin.js +2 -3
  173. package/dist/plugins/builtin/moss-transcribe/plugin.d.ts +30 -3
  174. package/dist/plugins/builtin/moss-transcribe/plugin.js +5 -3
  175. package/dist/plugins/builtin/nmtcpp-translation/fit.d.ts +3 -0
  176. package/dist/plugins/builtin/nmtcpp-translation/fit.js +11 -0
  177. package/dist/plugins/builtin/nmtcpp-translation/plugin.d.ts +14 -5
  178. package/dist/plugins/builtin/nmtcpp-translation/plugin.js +4 -2
  179. package/dist/plugins/builtin/parakeet-transcription/plugin.d.ts +205 -9
  180. package/dist/plugins/builtin/parakeet-transcription/plugin.js +39 -13
  181. package/dist/plugins/builtin/sdcpp-generation/fit.d.ts +3 -0
  182. package/dist/plugins/builtin/sdcpp-generation/fit.js +68 -0
  183. package/dist/plugins/builtin/sdcpp-generation/load-files.d.ts +30 -0
  184. package/dist/plugins/builtin/sdcpp-generation/load-files.js +121 -0
  185. package/dist/plugins/builtin/sdcpp-generation/ops/diffusion.d.ts +4 -1
  186. package/dist/plugins/builtin/sdcpp-generation/ops/diffusion.js +8 -3
  187. package/dist/plugins/builtin/sdcpp-generation/ops/upscale.d.ts +4 -1
  188. package/dist/plugins/builtin/sdcpp-generation/ops/upscale.js +107 -22
  189. package/dist/plugins/builtin/sdcpp-generation/ops/video.d.ts +3 -1
  190. package/dist/plugins/builtin/sdcpp-generation/ops/video.js +4 -1
  191. package/dist/plugins/builtin/sdcpp-generation/ops/world.d.ts +4 -2
  192. package/dist/plugins/builtin/sdcpp-generation/ops/world.js +7 -2
  193. package/dist/plugins/builtin/sdcpp-generation/plugin.d.ts +79 -16
  194. package/dist/plugins/builtin/sdcpp-generation/plugin.js +29 -117
  195. package/dist/plugins/builtin/tts-ggml/fit.d.ts +3 -0
  196. package/dist/plugins/builtin/tts-ggml/fit.js +162 -0
  197. package/dist/plugins/builtin/tts-ggml/ops/cancel-binding.d.ts +2 -1
  198. package/dist/plugins/builtin/tts-ggml/ops/cancel-binding.js +4 -1
  199. package/dist/plugins/builtin/tts-ggml/ops/moss-options.d.ts +1 -1
  200. package/dist/plugins/builtin/tts-ggml/ops/text-to-speech-stream.d.ts +2 -1
  201. package/dist/plugins/builtin/tts-ggml/ops/text-to-speech-stream.js +22 -9
  202. package/dist/plugins/builtin/tts-ggml/ops/text-to-speech.d.ts +2 -1
  203. package/dist/plugins/builtin/tts-ggml/ops/text-to-speech.js +51 -16
  204. package/dist/plugins/builtin/tts-ggml/ops/voice-options.d.ts +50 -0
  205. package/dist/plugins/builtin/tts-ggml/ops/voice-options.js +74 -0
  206. package/dist/plugins/builtin/tts-ggml/plugin.d.ts +368 -25
  207. package/dist/plugins/builtin/tts-ggml/plugin.js +180 -31
  208. package/dist/plugins/builtin/whispercpp-transcription/plugin.d.ts +70 -7
  209. package/dist/plugins/builtin/whispercpp-transcription/plugin.js +8 -6
  210. package/dist/plugins/ops/bci-transcribe.d.ts +5 -4
  211. package/dist/plugins/ops/bci-transcribe.js +18 -4
  212. package/dist/plugins/ops/cancel.d.ts +1 -0
  213. package/dist/plugins/ops/cancel.js +11 -2
  214. package/dist/plugins/ops/embed.d.ts +5 -3
  215. package/dist/plugins/ops/embed.js +89 -34
  216. package/dist/plugins/ops/kv-cache-utils.d.ts +1 -0
  217. package/dist/plugins/ops/kv-cache-utils.js +6 -2
  218. package/dist/plugins/ops/load-model.d.ts +2 -0
  219. package/dist/plugins/ops/load-model.js +33 -16
  220. package/dist/plugins/ops/transcribe.d.ts +5 -4
  221. package/dist/plugins/ops/transcribe.js +62 -27
  222. package/dist/plugins/ops/translate.d.ts +2 -1
  223. package/dist/plugins/ops/translate.js +4 -1
  224. package/dist/plugins/ops/unload-model.d.ts +17 -1
  225. package/dist/plugins/ops/unload-model.js +31 -2
  226. package/dist/plugins/turbovec-backend.d.ts +1 -1
  227. package/dist/plugins/turbovec-backend.js +16 -1
  228. package/dist/profiling/operation-metrics.js +22 -19
  229. package/dist/rag/embedding-scope.d.ts +16 -0
  230. package/dist/rag/embedding-scope.js +81 -0
  231. package/dist/rag/handler.d.ts +25 -0
  232. package/dist/rag/handler.js +50 -16
  233. package/dist/rag/handlers/ingest.js +2 -6
  234. package/dist/rag/handlers/search.d.ts +10 -1
  235. package/dist/rag/handlers/search.js +16 -7
  236. package/dist/rag/rag-operation-manager.d.ts +27 -3
  237. package/dist/rag/rag-operation-manager.js +10 -27
  238. package/dist/registry.js +5 -0
  239. package/dist/resources/collector.d.ts +70 -36
  240. package/dist/resources/collector.js +8 -1
  241. package/dist/resources/types.d.ts +2 -0
  242. package/dist/rpc/inventory.js +1 -12
  243. package/dist/runtime/env.d.ts +5 -1
  244. package/dist/runtime/env.js +6 -21
  245. package/dist/runtime/index.d.ts +4 -1
  246. package/dist/runtime/index.js +2 -0
  247. package/dist/runtime/lifecycle.d.ts +6 -4
  248. package/dist/runtime/lifecycle.js +9 -5
  249. package/dist/runtime/model-config-utils.js +5 -1
  250. package/dist/runtime/model-registry.d.ts +28 -4
  251. package/dist/runtime/model-registry.js +46 -1
  252. package/dist/runtime/model-work-lock.d.ts +13 -0
  253. package/dist/runtime/model-work-lock.js +48 -0
  254. package/dist/runtime/registry-client.d.ts +47 -1
  255. package/dist/runtime/registry-client.js +446 -88
  256. package/dist/runtime/request-context.d.ts +9 -1
  257. package/dist/runtime/request-context.js +25 -1
  258. package/dist/runtime/request-registry.d.ts +55 -7
  259. package/dist/runtime/request-registry.js +189 -71
  260. package/dist/runtime/runtime-lifecycle.js +10 -1
  261. package/dist/runtime/session-id.d.ts +18 -0
  262. package/dist/runtime/session-id.js +20 -0
  263. package/dist/runtime/session-registry.d.ts +39 -0
  264. package/dist/runtime/session-registry.js +114 -0
  265. package/dist/runtime/vector-index-backend.d.ts +4 -0
  266. package/dist/runtime/vector-index-registry.d.ts +21 -0
  267. package/dist/runtime/vector-index-registry.js +56 -18
  268. package/dist/schemas/abort-signal.d.ts +8 -0
  269. package/dist/schemas/abort-signal.js +1 -0
  270. package/dist/schemas/assess-model-fit.d.ts +132 -282
  271. package/dist/schemas/assess-model-fit.js +82 -216
  272. package/dist/schemas/audio-gen.d.ts +278 -24
  273. package/dist/schemas/audio-gen.js +127 -23
  274. package/dist/schemas/batch-completion-stream.d.ts +105 -13
  275. package/dist/schemas/batch-completion-stream.js +8 -4
  276. package/dist/schemas/bci-config.d.ts +2 -1
  277. package/dist/schemas/bci.d.ts +54 -3
  278. package/dist/schemas/bci.js +11 -16
  279. package/dist/schemas/calc-tokens.d.ts +141 -0
  280. package/dist/schemas/calc-tokens.js +53 -0
  281. package/dist/schemas/cancel.d.ts +26 -0
  282. package/dist/schemas/cancel.js +10 -2
  283. package/dist/schemas/classification.d.ts +3 -0
  284. package/dist/schemas/classification.js +6 -2
  285. package/dist/schemas/common.d.ts +1831 -348
  286. package/dist/schemas/common.js +18 -2
  287. package/dist/schemas/completion-event.d.ts +3 -0
  288. package/dist/schemas/completion-event.js +1 -1
  289. package/dist/schemas/completion-stream.d.ts +162 -17
  290. package/dist/schemas/completion-stream.js +83 -13
  291. package/dist/schemas/config.d.ts +1212 -169
  292. package/dist/schemas/config.js +9 -13
  293. package/dist/schemas/decision.d.ts +4 -2
  294. package/dist/schemas/decision.js +2 -1
  295. package/dist/schemas/download-asset.d.ts +10 -5
  296. package/dist/schemas/download-asset.js +3 -6
  297. package/dist/schemas/embed.d.ts +286 -3
  298. package/dist/schemas/embed.js +162 -16
  299. package/dist/schemas/engine-addon-map.d.ts +1 -0
  300. package/dist/schemas/engine-addon-map.js +1 -0
  301. package/dist/schemas/errors.d.ts +12 -0
  302. package/dist/schemas/errors.js +66 -1
  303. package/dist/schemas/finetune.d.ts +14 -4
  304. package/dist/schemas/finetune.js +5 -6
  305. package/dist/schemas/heartbeat.d.ts +1 -0
  306. package/dist/schemas/heartbeat.js +5 -2
  307. package/dist/schemas/image-embedding.d.ts +27 -0
  308. package/dist/schemas/image-embedding.js +107 -0
  309. package/dist/schemas/index.d.ts +7 -3
  310. package/dist/schemas/index.js +7 -3
  311. package/dist/schemas/lifecycle.d.ts +3 -0
  312. package/dist/schemas/lifecycle.js +13 -6
  313. package/dist/schemas/llamacpp-config.d.ts +269 -22
  314. package/dist/schemas/llamacpp-config.js +86 -7
  315. package/dist/schemas/load-model.d.ts +6418 -1960
  316. package/dist/schemas/load-model.js +39 -8
  317. package/dist/schemas/logging-stream.d.ts +1 -0
  318. package/dist/schemas/logging-stream.js +5 -2
  319. package/dist/schemas/model-config-schemas.d.ts +542 -116
  320. package/dist/schemas/model-config-schemas.js +2 -0
  321. package/dist/schemas/model-fit-policy.d.ts +2 -2
  322. package/dist/schemas/model-info.d.ts +54 -56
  323. package/dist/schemas/model-info.js +17 -6
  324. package/dist/schemas/model-ops.d.ts +12 -0
  325. package/dist/schemas/model-ops.js +33 -5
  326. package/dist/schemas/model-src-utils.d.ts +10 -6
  327. package/dist/schemas/model-types.d.ts +8 -4
  328. package/dist/schemas/model-types.js +1 -0
  329. package/dist/schemas/ocr.d.ts +9 -4
  330. package/dist/schemas/ocr.js +6 -2
  331. package/dist/schemas/plugin.d.ts +62 -6
  332. package/dist/schemas/plugin.js +26 -4
  333. package/dist/schemas/profiling.d.ts +32 -32
  334. package/dist/schemas/rag.d.ts +9 -0
  335. package/dist/schemas/rag.js +10 -16
  336. package/dist/schemas/registry.d.ts +30 -10
  337. package/dist/schemas/registry.js +14 -6
  338. package/dist/schemas/reload-config.d.ts +41 -6
  339. package/dist/schemas/reload-config.js +11 -4
  340. package/dist/schemas/request-base.d.ts +39 -0
  341. package/dist/schemas/request-base.js +64 -0
  342. package/dist/schemas/rerank.d.ts +8 -7
  343. package/dist/schemas/rerank.js +6 -4
  344. package/dist/schemas/rpc-server.d.ts +3 -0
  345. package/dist/schemas/rpc-server.js +15 -15
  346. package/dist/schemas/sdcpp-config.d.ts +90 -20
  347. package/dist/schemas/sdcpp-config.js +96 -19
  348. package/dist/schemas/session.d.ts +37 -0
  349. package/dist/schemas/session.js +53 -0
  350. package/dist/schemas/system-resources.d.ts +364 -179
  351. package/dist/schemas/system-resources.js +8 -3
  352. package/dist/schemas/text-to-speech.d.ts +1343 -271
  353. package/dist/schemas/text-to-speech.js +547 -33
  354. package/dist/schemas/tools.d.ts +7 -0
  355. package/dist/schemas/tools.js +29 -0
  356. package/dist/schemas/transcription-config.d.ts +262 -2
  357. package/dist/schemas/transcription-config.js +122 -6
  358. package/dist/schemas/transcription.d.ts +93 -6
  359. package/dist/schemas/transcription.js +98 -21
  360. package/dist/schemas/translate.d.ts +2 -0
  361. package/dist/schemas/translate.js +5 -9
  362. package/dist/schemas/translation-config.d.ts +30 -20
  363. package/dist/schemas/tts-pcm.d.ts +35 -0
  364. package/dist/schemas/tts-pcm.js +69 -0
  365. package/dist/schemas/vector-index.d.ts +47 -1
  366. package/dist/schemas/vector-index.js +37 -10
  367. package/dist/schemas/vla.d.ts +3 -3
  368. package/dist/surface.d.ts +3 -3
  369. package/dist/surface.js +3 -3
  370. package/dist/utils/addon-responses.d.ts +69 -2
  371. package/dist/utils/archive.d.ts +7 -0
  372. package/dist/utils/archive.js +88 -29
  373. package/dist/utils/asr-events.d.ts +5 -0
  374. package/dist/utils/asr-events.js +10 -1
  375. package/dist/utils/cache/auto-history.js +3 -1
  376. package/dist/utils/cache/layout.d.ts +48 -0
  377. package/dist/utils/cache/layout.js +190 -0
  378. package/dist/utils/cache/paths.js +2 -4
  379. package/dist/utils/cache/types.d.ts +2 -1
  380. package/dist/utils/checksum.d.ts +5 -0
  381. package/dist/utils/checksum.js +18 -0
  382. package/dist/utils/completion-normalizer.js +286 -87
  383. package/dist/utils/gguf-tensor-extractor.d.ts +0 -6
  384. package/dist/utils/gguf-tensor-extractor.js +1 -50
  385. package/dist/utils/shard-utils.d.ts +0 -21
  386. package/dist/utils/shard-utils.js +12 -62
  387. package/dist/utils/tool-integration.d.ts +2 -2
  388. package/dist/utils/tools/defer.d.ts +39 -10
  389. package/dist/utils/tools/defer.js +72 -17
  390. package/dist/utils/tools/index.d.ts +1 -1
  391. package/dist/utils/tools/index.js +1 -1
  392. package/dist/utils/transcribe-metadata.d.ts +28 -2
  393. package/dist/utils/transcribe-metadata.js +16 -0
  394. package/dist/utils/tts-stats.d.ts +42 -0
  395. package/dist/utils/tts-stats.js +120 -22
  396. package/package.json +43 -39
  397. package/dist/model-fit/classify.d.ts +0 -6
  398. package/dist/model-fit/classify.js +0 -166
  399. package/dist/model-fit/description/project.d.ts +0 -27
  400. package/dist/model-fit/description/project.js +0 -33
  401. package/dist/model-fit/floor.d.ts +0 -31
  402. package/dist/model-fit/floor.js +0 -65
  403. package/dist/model-fit/kv-cache.d.ts +0 -23
  404. package/dist/model-fit/kv-cache.js +0 -85
  405. package/dist/model-fit/platform.d.ts +0 -14
  406. package/dist/model-fit/platform.js +0 -26
  407. package/dist/model-fit/request/create.d.ts +0 -31
  408. package/dist/model-fit/request/create.js +0 -61
  409. package/dist/model-fit/request/engines/asr.d.ts +0 -14
  410. package/dist/model-fit/request/engines/audiogen.d.ts +0 -8
  411. package/dist/model-fit/request/engines/diffusion.d.ts +0 -7
  412. package/dist/model-fit/request/engines/diffusion.js +0 -93
  413. package/dist/model-fit/request/engines/llama.d.ts +0 -12
  414. package/dist/model-fit/request/engines/llama.js +0 -44
  415. package/dist/model-fit/request/engines/nmt.d.ts +0 -8
  416. package/dist/model-fit/request/engines/nmt.js +0 -11
  417. package/dist/model-fit/request/engines/ocr.d.ts +0 -9
  418. package/dist/model-fit/request/engines/ocr.js +0 -13
  419. package/dist/model-fit/request/engines/tts.d.ts +0 -10
  420. package/dist/model-fit/request/engines/tts.js +0 -152
  421. package/dist/models/registry/resource-profiles.d.ts +0 -17
  422. package/dist/models/registry/resource-profiles.js +0 -5859
  423. package/dist/schemas/model-resource-profile.d.ts +0 -109
  424. package/dist/schemas/model-resource-profile.js +0 -80
  425. /package/dist/model-fit/{request/gpu.d.ts → gpu.d.ts} +0 -0
  426. /package/dist/model-fit/{request/gpu.js → gpu.js} +0 -0
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { modelSrcInputSchema } from './model-src-utils.js';
3
+ import { trackedRequestSchema } from './request-base.js';
3
4
  // Chatterbox multilingual supported languages (23). The engines support
4
5
  // different language sets, so the language enum is validated per engine.
5
6
  export const TTS_CHATTERBOX_LANGUAGES = [
@@ -123,6 +124,24 @@ export const TTS_COSYVOICE3_INSTRUCT_DIALECTS = [
123
124
  ];
124
125
  export const TTS_COSYVOICE3_INSTRUCT_VOLUMES = ['loud', 'soft'];
125
126
  export const TTS_COSYVOICE3_INSTRUCT_STYLES = ['peppa', 'robot'];
127
+ // Parler's Core ML compute policy (@qvac/tts-ggml `PARLER_COREML_COMPUTE_UNITS`).
128
+ export const TTS_PARLER_COREML_COMPUTE_UNITS = [
129
+ 'all',
130
+ 'cpu_and_ane',
131
+ 'cpu_and_gpu',
132
+ 'cpu_only'
133
+ ];
134
+ // The LavaSR stages' Core ML compute policy (@qvac/tts-ggml
135
+ // `LavaSRCoreMLComputeUnits`); a different spelling from Parler's because each
136
+ // mirrors its own native enum.
137
+ export const TTS_LAVASR_COREML_COMPUTE_UNITS = [
138
+ 'CPU_ONLY',
139
+ 'CPU_AND_GPU',
140
+ 'CPU_AND_NE',
141
+ 'ALL'
142
+ ];
143
+ // Supertonic weight precision (@qvac/tts-ggml `precision`).
144
+ export const TTS_SUPERTONIC_PRECISIONS = ['auto', 'f32', 'f16', 'q8_0'];
126
145
  // Supertonic languages not already present in the Chatterbox set, used to keep
127
146
  // TTS_LANGUAGES a true union across engines without duplicates.
128
147
  const TTS_SUPERTONIC_ONLY_LANGUAGES = [
@@ -157,6 +176,11 @@ const ttsIntegerSchema = z.number().int();
157
176
  const ttsInt32Schema = ttsIntegerSchema.min(-2147483648).max(2147483647);
158
177
  const ttsNonNegativeInt32Schema = ttsInt32Schema.nonnegative();
159
178
  const ttsPositiveInt32Schema = ttsInt32Schema.positive();
179
+ // A CosyVoice3 speech token travels both ways: the response hands them out as
180
+ // `speechTokenIds`, the load config takes them back as `forceSpeechTokens`.
181
+ // One titled scalar keeps the two interchangeable in every generated client
182
+ // (one shared Python class instead of a differently named wrapper per field).
183
+ const ttsSpeechTokenIdSchema = ttsInt32Schema.meta({ title: 'TtsSpeechTokenId' });
160
184
  // Describe text shared by fields repeated across engine arms.
161
185
  const TTS_USE_GPU_DESC = 'Route inference through a GPU backend (Metal / CUDA / Vulkan / OpenCL) when available. Default false.';
162
186
  const TTS_SEED_DESC = 'RNG seed for the engine’s stochastic stages (e.g. Chatterbox CFM/SineGen, Supertonic latent generation).';
@@ -164,6 +188,7 @@ const TTS_THREADS_DESC = 'CPU thread count; overrides the hardware default.';
164
188
  const TTS_NGPU_LAYERS_DESC = 'Model layers to offload to the GPU backend (99 = all, 0 = CPU). Takes effect on its own and wins over `useGPU`; when both are set they must agree.';
165
189
  const TTS_STREAM_CHUNK_TOKENS_DESC = 'Speech tokens per native streaming chunk; 0 disables native chunk streaming.';
166
190
  const TTS_STREAM_FIRST_CHUNK_TOKENS_DESC = 'Smaller first streaming chunk for lower first-audio latency.';
191
+ const TTS_VULKAN_DEVICE_DESC = 'Vulkan adapter index, also used by the LavaSR enhancer: 0 = the first adapter, N = the Nth, -1 = auto-pick by free VRAM preferring a discrete adapter. Only consulted on Vulkan.';
167
192
  const TTS_TEMPERATURE_DESC = 'Sampling temperature; unset defers to the engine default (Parler 1.0, Audio8 0.7).';
168
193
  const TTS_TOP_K_DESC = 'Top-k sampling cutoff; unset defers to the engine default (50).';
169
194
  const TTS_TOP_P_DESC = 'Top-p (nucleus) sampling cutoff (0 < p ≤ 1); unset defers to the engine default.';
@@ -172,12 +197,27 @@ const TTS_MAX_FRAMES_DESC = 'Generation-length cap in decoder frames; 0 = engine
172
197
  // generic ggml backend-loading knobs, not TTS-specific ones.
173
198
  const TTS_BACKENDS_DIR_DESC = 'Directory scanned as given for dynamically-loaded ggml backend `.so` files. Unset scans the directory the native module was loaded from.';
174
199
  const TTS_OPENCL_CACHE_DIR_DESC = "Persistent directory for ggml-opencl's compiled-program cache (Android only).";
200
+ const TTS_BACKEND_DESC = 'Explicit native backend: `auto`, `cpu`, `opencl`, `webgpu`, or an exact registered device name such as `MTL0`, `CUDA0` or `Vulkan0` (device names depend on the host). An unavailable explicit backend fails the load; unset keeps the `useGPU` policy. WebGPU is available to Supertonic 3, Parler, CosyVoice3 and Audio8 only.';
175
201
  // The ggml backend knobs every engine honours. `openclCacheDir` is added only
176
202
  // on the three engines whose native config reads it (Parler and Audio8 build
177
203
  // their params through the addon's _assignBackendParams, which does not).
178
204
  const ttsBackendDirFieldsShape = {
205
+ backend: z.string().trim().min(1).optional().describe(TTS_BACKEND_DESC),
179
206
  backendsDir: z.string().min(1).optional().describe(TTS_BACKENDS_DIR_DESC)
180
207
  };
208
+ // Mirrors the addon's validateBackendOption: a WebGPU selector is accepted only
209
+ // on the engines whose native library has established WebGPU support
210
+ // (Supertonic 3, Parler, CosyVoice3, Audio8); the others reject it before any
211
+ // weight is loaded, and so does this schema, naming the field.
212
+ function refineNoWebgpuBackend(config, ctx) {
213
+ if (config.backend === undefined || !/^webgpu/i.test(config.backend))
214
+ return;
215
+ ctx.addIssue({
216
+ code: 'custom',
217
+ path: ['backend'],
218
+ message: `WebGPU has no established support for ${config.ttsEngine}; it is available to Supertonic 3, Parler, CosyVoice3 and Audio8 only.`
219
+ });
220
+ }
181
221
  const ttsOpenclCacheFieldShape = {
182
222
  openclCacheDir: z.string().min(1).optional().describe(TTS_OPENCL_CACHE_DIR_DESC)
183
223
  };
@@ -337,6 +377,62 @@ export const ttsChatterboxRuntimeConfigSchema = z
337
377
  .nonnegative()
338
378
  .optional()
339
379
  .describe('Chatterbox S3Gen classifier-free-guidance rate; `0` skips the unconditioned pass, a positive value overrides the model’s baked rate. Omit to keep the baked rate.'),
380
+ streamLeftContextTokens: ttsNonNegativeInt32Schema
381
+ .optional()
382
+ .describe('Already-emitted speech tokens S3Gen keeps as left context per native streaming chunk (typically 25–50), bounding the per-chunk cost on long utterances; 0 = the whole emitted prefix.'),
383
+ batchCfmSteps: ttsNonNegativeInt32Schema
384
+ .optional()
385
+ .describe('CFM Euler step count for batch synthesis; 0 = the library default (2-step meanflow on Turbo, the model’s full schedule on multilingual). The multilingual engine does not floor it, so values well below its schedule under-integrate. `cfmSteps` keeps driving native streaming.'),
386
+ nPredict: ttsPositiveInt32Schema
387
+ .optional()
388
+ .describe('Cap on speech tokens T3 decodes per synthesis (~25 tokens ≈ 1 s); engine default 1000 (~40 s). Longer single calls also need `nCtx` to cover prompt plus generated tokens, or use `maxSentenceChars`.'),
389
+ maxSentenceChars: ttsNonNegativeInt32Schema
390
+ .optional()
391
+ .describe('Sentence auto-split: T3 + S3Gen run per segment of at most this many bytes (the reference CLI uses 180); 0 = off. `nPredict` then applies per segment.'),
392
+ crossfadeMs: ttsNonNegativeInt32Schema
393
+ .optional()
394
+ .describe('Raised-cosine crossfade between auto-split batch segments, in milliseconds (engine default 30). Native streaming stays gapless.'),
395
+ // T3 samples its speech tokens; the defaults are the addon's, not Parler's
396
+ // or Audio8's, so these do not share TTS_TEMPERATURE_DESC and friends.
397
+ temperature: z
398
+ .number()
399
+ .nonnegative()
400
+ .optional()
401
+ .describe('T3 sampling temperature (engine default 0.8); 0 decodes greedily.'),
402
+ topK: ttsNonNegativeInt32Schema
403
+ .optional()
404
+ .describe('T3 top-k sampling cutoff (engine default 1000); 0 disables the cutoff.'),
405
+ topP: z
406
+ .number()
407
+ .positive()
408
+ .max(1)
409
+ .optional()
410
+ .describe('T3 top-p (nucleus) sampling cutoff, 0 < p ≤ 1 (engine default 0.95).'),
411
+ repeatPenalty: z
412
+ .number()
413
+ .positive()
414
+ .optional()
415
+ .describe('T3 repetition penalty (engine default 1.2); 1 = off.'),
416
+ exaggeration: z
417
+ .number()
418
+ .optional()
419
+ .describe('Multilingual only: prosody intensity, above 0 more expressive, below 0 flatter (engine default 0.5). The Turbo variant ignores it.'),
420
+ cfgWeight: z
421
+ .number()
422
+ .nonnegative()
423
+ .optional()
424
+ .describe('Multilingual only: T3 classifier-free-guidance scale (engine default 0.5); 0 disables it. Separate from `cfgRate`, which steers S3Gen.'),
425
+ minP: z
426
+ .number()
427
+ .min(0)
428
+ .max(1)
429
+ .optional()
430
+ .describe('Multilingual only: min-p sampling threshold (engine default 0); 0 = off.'),
431
+ voiceDir: z
432
+ .string()
433
+ .min(1)
434
+ .optional()
435
+ .describe('Directory of pre-baked voice-conditioning tensors (the upstream CLI’s `--save-voice` output), loaded instead of preprocessing a reference recording. With `referenceAudioSrc` too, tensors missing from the directory are backfilled from the recording.'),
340
436
  // Int32 like the other engines: the addon narrows with `| 0`, so a wider
341
437
  // value would wrap silently rather than fail.
342
438
  threads: ttsPositiveInt32Schema.optional().describe(TTS_THREADS_DESC),
@@ -345,12 +441,28 @@ export const ttsChatterboxRuntimeConfigSchema = z
345
441
  ...ttsBackendDirFieldsShape,
346
442
  ...ttsOpenclCacheFieldShape
347
443
  })
348
- .superRefine(refineGpuIntent);
444
+ .superRefine(refineChatterboxRuntimeConfig);
445
+ function refineChatterboxRuntimeConfig(config, ctx) {
446
+ refineGpuIntent(config, ctx);
447
+ refineNoWebgpuBackend(config, ctx);
448
+ }
449
+ // Supertonic's in-memory voice tensors come as a pair: the addon rejects one
450
+ // without the other, so the schema does too, naming the missing half.
451
+ function refineSupertonicVoiceStyle(config, ctx) {
452
+ if ((config.voiceStyleTtl === undefined) === (config.voiceStyleDp === undefined))
453
+ return;
454
+ ctx.addIssue({
455
+ code: 'custom',
456
+ path: [config.voiceStyleTtl === undefined ? 'voiceStyleTtl' : 'voiceStyleDp'],
457
+ message: 'voiceStyleTtl and voiceStyleDp must be supplied together.'
458
+ });
459
+ }
349
460
  // Supertonic drives its duration predictor from either an exact multiplier
350
461
  // (`ttsSpeed`) or the canonical pace vocabulary, never both — the engine
351
462
  // rejects the pair rather than picking a winner.
352
463
  function refineSupertonicRateControls(config, ctx) {
353
464
  refineGpuIntent(config, ctx);
465
+ refineSupertonicVoiceStyle(config, ctx);
354
466
  if (config.ttsSpeed !== undefined && config.pace !== undefined) {
355
467
  ctx.addIssue({
356
468
  code: 'custom',
@@ -359,8 +471,7 @@ function refineSupertonicRateControls(config, ctx) {
359
471
  });
360
472
  }
361
473
  }
362
- export const ttsSupertonicRuntimeConfigSchema = z
363
- .object({
474
+ const ttsSupertonicRuntimeConfigShape = {
364
475
  ttsEngine: z.literal('supertonic').describe('TTS engine: Supertonic.'),
365
476
  language: ttsSupertonicLanguageSchema.describe('Language code. Default `en`.'),
366
477
  voice: z.string().optional().describe('Supertonic baked voice id, e.g. `F1` or `M1`.'),
@@ -390,9 +501,65 @@ export const ttsSupertonicRuntimeConfigSchema = z
390
501
  .min(1)
391
502
  .optional()
392
503
  .describe('Supertonic + `useGPU` only: directory where the Vulkan backend persists its compiled pipeline cache.'),
504
+ vulkanDevice: ttsInt32Schema.min(-1).optional().describe(TTS_VULKAN_DEVICE_DESC),
505
+ prewarmText: z
506
+ .string()
507
+ .trim()
508
+ .min(1)
509
+ .optional()
510
+ .describe('Text synthesized once at load so GPU pipelines (and a Core ML vocoder sidecar) are ready before the first request; skipped on a plain CPU run. Use a sentence of representative length. Wins over the `vulkanCacheDir` default pre-warm.'),
511
+ // Supertonic chunks on text tokens, not speech tokens, so its native
512
+ // streaming controls carry their own wording.
513
+ streamChunkTokens: ttsNonNegativeInt32Schema
514
+ .optional()
515
+ .describe('Text tokens (Unicode code points) per native streaming chunk, about 50 for English and 25–30 for CJK; 0 disables native chunk streaming. Cannot be combined with the LavaSR enhancer or denoiser.'),
516
+ streamFirstChunkTokens: ttsNonNegativeInt32Schema
517
+ .optional()
518
+ .describe(TTS_STREAM_FIRST_CHUNK_TOKENS_DESC),
519
+ streamChunkTolerancePct: ttsNonNegativeInt32Schema
520
+ .optional()
521
+ .describe('Boundary-snap window for clause and whitespace chunk boundaries, as a percentage of the chunk target (engine default 20).'),
522
+ streamMinChunkTokens: ttsNonNegativeInt32Schema
523
+ .optional()
524
+ .describe('Floor on every streamed chunk’s size in text tokens (engine default 30); shorter trailing chunks merge into the previous one.'),
525
+ // Native precision and environment controls, forwarded to the engine as
526
+ // given; -1 on the integer overrides leaves the engine's automatic choice.
527
+ precision: z
528
+ .enum(TTS_SUPERTONIC_PRECISIONS)
529
+ .optional()
530
+ .describe('Weight precision the engine loads at: `auto` keeps the GGUF’s own, `f32` / `f16` / `q8_0` convert on load and change the weight footprint.'),
531
+ f16Attn: ttsInt32Schema
532
+ .optional()
533
+ .describe('Attention precision override: `-1` automatic (default), `0` f32, `1` f16.'),
534
+ f16Weights: ttsInt32Schema
535
+ .optional()
536
+ .describe('Weight precision override: `-1` automatic (default), `0` off, `1` f16.'),
537
+ kvAttnType: ttsInt32Schema
538
+ .optional()
539
+ .describe('Native KV attention type code; `-1` leaves the automatic selection.'),
540
+ f16WeightsDenyList: z
541
+ .array(z.string().min(1))
542
+ .optional()
543
+ .describe('Tensor-name patterns kept at their original precision when `f16Weights` is on.'),
544
+ vulkanEnvOverrides: z
545
+ .record(z.string(), z.string())
546
+ .optional()
547
+ .describe('Vulkan environment overrides (string values) passed to the engine; explicit entries win over the `vulkanCacheDir` convenience setting.'),
548
+ voiceStyleTtl: z
549
+ .array(z.number())
550
+ .min(1)
551
+ .optional()
552
+ .describe('In-memory voice: the flattened `style_ttl` tensor of a cloned voice. Paired with `voiceStyleDp`; the engine checks the sizes against the model, and the pair wins over `voiceJsonSrc` and the baked `voice`.'),
553
+ voiceStyleDp: z
554
+ .array(z.number())
555
+ .min(1)
556
+ .optional()
557
+ .describe('In-memory voice: the flattened `style_dp` tensor, paired with `voiceStyleTtl`.'),
393
558
  ...ttsBackendDirFieldsShape,
394
559
  ...ttsOpenclCacheFieldShape
395
- })
560
+ };
561
+ export const ttsSupertonicRuntimeConfigSchema = z
562
+ .object(ttsSupertonicRuntimeConfigShape)
396
563
  .superRefine(refineSupertonicRateControls);
397
564
  // A shape rather than a schema so the load schema below can be built from it
398
565
  // and carry its own refinement set (the enhancer waiver needs the load-only
@@ -424,6 +591,20 @@ const ttsParlerRuntimeConfigShape = {
424
591
  .boolean()
425
592
  .optional()
426
593
  .describe('Parler prompt digit expansion (engine default: enabled).'),
594
+ // Apple Core ML sidecars (macOS / iOS). The DAC sidecar is presence-driven;
595
+ // these three steer the optional decoder sidecar and the compute policy.
596
+ coremlDecoder: z
597
+ .boolean()
598
+ .optional()
599
+ .describe('macOS / iOS: run the decoder steps on the `<model>-decoder.mlmodelc` sidecar beside the GGUF (the DAC sidecar is picked up by presence); unset keeps the engine default.'),
600
+ coremlComputeUnits: z
601
+ .enum(TTS_PARLER_COREML_COMPUTE_UNITS)
602
+ .optional()
603
+ .describe('macOS / iOS: Core ML compute policy for the Parler sidecars; unset inherits the engine’s environment default.'),
604
+ coremlStrict: z
605
+ .boolean()
606
+ .optional()
607
+ .describe('macOS / iOS: `true` fails the load when a sidecar is unusable instead of falling back to ggml, `false` permits the fallback; unset inherits the engine’s strict mode.'),
427
608
  ...ttsBackendDirFieldsShape
428
609
  };
429
610
  export const ttsParlerRuntimeConfigSchema = z
@@ -502,7 +683,7 @@ const ttsCosyvoice3RuntimeConfigShape = {
502
683
  .describe("Speaking rate: `'slow'`, `'moderate'`, or `'fast'`; `'moderate'` disengages the pace channel."),
503
684
  instruct: ttsCosyvoice3InstructSchema
504
685
  .optional()
505
- .describe('Natural-language control: a structured object (one of dialect / volume / style) or a raw instruction string. One conditioning control per synthesis.'),
686
+ .describe('Natural-language control: a structured object (one of dialect / volume / style) or a raw instruction string. One conditioning control per synthesis; a request-level `instruct` replaces it for that synthesis.'),
506
687
  // Trimmed for the same reason as the instruct string: a whitespace-only
507
688
  // transcript would reach the engine as a non-empty prompt.
508
689
  promptText: z
@@ -511,6 +692,19 @@ const ttsCosyvoice3RuntimeConfigShape = {
511
692
  .min(1)
512
693
  .optional()
513
694
  .describe('Verbatim transcript of `referenceAudioSrc`. Setting it selects zero-shot cloning (best fidelity in the reference’s own language); omitting it selects cross-lingual cloning (timbre only). Without a reference it overrides the baked voice’s transcript metadata.'),
695
+ flowCutPrompt: z
696
+ .boolean()
697
+ .optional()
698
+ .describe('Treat the baked-voice prompt frames as attention-only conditioning in the flow: a faster flow whose output deviates slightly from the reference (engine default off).'),
699
+ vulkanDevice: ttsInt32Schema.min(-1).optional().describe(TTS_VULKAN_DEVICE_DESC),
700
+ greedy: z
701
+ .boolean()
702
+ .optional()
703
+ .describe('Greedy LM decoding: take the argmax speech token instead of sampling (engine default off).'),
704
+ forceSpeechTokens: z
705
+ .array(ttsSpeechTokenIdSchema)
706
+ .optional()
707
+ .describe('Speech-token trajectory of ONE native synthesis to replay instead of generating, as a previous batch run, native chunk stream or single sentence returned it in `speechTokenIds`. Fixed at load: every synthesis of the model replays this same array, so a joined sentence stream cannot be replayed sentence by sentence. An empty array restores generation.'),
514
708
  useGPU: z.boolean().optional().describe(TTS_USE_GPU_DESC),
515
709
  outputSampleRate: ttsOutputSampleRateSchema.optional(),
516
710
  streamChunkTokens: ttsNonNegativeInt32Schema.optional().describe(TTS_STREAM_CHUNK_TOKENS_DESC),
@@ -554,10 +748,70 @@ const ttsAudio8RuntimeConfigShape = {
554
748
  export const ttsAudio8RuntimeConfigSchema = z
555
749
  .object(ttsAudio8RuntimeConfigShape)
556
750
  .superRefine(refineGpuIntent);
557
- // @qvac/tts-ggml's MOSS_MAX_DURATION_TOKENS: the 2048-row generation budget
558
- // less the 31 delay-pattern drain rows and the two termination rows.
559
- const TTS_MOSS_MAX_DURATION_TOKENS = 2015;
751
+ // @qvac/tts-ggml's MOSS generation budget: 2048 rows when `maxNewTokens` is
752
+ // unset, of which 31 delay-pattern drain rows and two termination rows are
753
+ // never audio, so `durationTokens` fits at most `maxNewTokens - 33` (2015 by
754
+ // default).
755
+ const TTS_MOSS_DEFAULT_MAX_NEW_TOKENS = 2048;
756
+ const TTS_MOSS_RESERVED_ROWS = 33;
560
757
  const TTS_MOSS_MAX_DIALOGUE_SPEAKERS = 5;
758
+ // Mirrors the addon's assertMossDurationTokens with the configured budget: a
759
+ // target that does not fit the generation budget is refused at load rather
760
+ // than by the engine.
761
+ function refineMossDurationBudget(config, ctx) {
762
+ if (config.durationTokens === undefined || config.durationTokens === 0)
763
+ return;
764
+ const budget = (config.maxNewTokens ?? TTS_MOSS_DEFAULT_MAX_NEW_TOKENS) - TTS_MOSS_RESERVED_ROWS;
765
+ if (config.durationTokens <= budget)
766
+ return;
767
+ ctx.addIssue({
768
+ code: 'custom',
769
+ path: ['durationTokens'],
770
+ message: `durationTokens must be an integer from 0 to ${Math.max(0, budget)} (maxNewTokens less the 33 delay/EOS rows; 0 = free length).`
771
+ });
772
+ }
773
+ function refineMossRuntimeConfig(config, ctx) {
774
+ refineGpuIntent(config, ctx);
775
+ refineNoWebgpuBackend(config, ctx);
776
+ refineMossDurationBudget(config, ctx);
777
+ }
778
+ // MOSS samples its text and audio channels separately; the defaults are the
779
+ // engine's, so these do not share the Parler / Audio8 sampling descriptions.
780
+ const ttsMossSamplingFieldsShape = {
781
+ textTemperature: z
782
+ .number()
783
+ .nonnegative()
784
+ .optional()
785
+ .describe('Text-channel sampling temperature; unset keeps the engine default.'),
786
+ textTopP: z
787
+ .number()
788
+ .positive()
789
+ .max(1)
790
+ .optional()
791
+ .describe('Text-channel top-p (nucleus) cutoff, 0 < p ≤ 1; unset keeps the engine default.'),
792
+ textTopK: ttsNonNegativeInt32Schema
793
+ .optional()
794
+ .describe('Text-channel top-k cutoff; unset keeps the engine default.'),
795
+ audioTemperature: z
796
+ .number()
797
+ .nonnegative()
798
+ .optional()
799
+ .describe('Audio-channel sampling temperature; unset keeps the engine default.'),
800
+ audioTopP: z
801
+ .number()
802
+ .positive()
803
+ .max(1)
804
+ .optional()
805
+ .describe('Audio-channel top-p (nucleus) cutoff, 0 < p ≤ 1; unset keeps the engine default.'),
806
+ audioTopK: ttsNonNegativeInt32Schema
807
+ .optional()
808
+ .describe('Audio-channel top-k cutoff; unset keeps the engine default.'),
809
+ audioRepetitionPenalty: z
810
+ .number()
811
+ .positive()
812
+ .optional()
813
+ .describe('Audio-channel repetition penalty; 1 = off, unset keeps the engine default.')
814
+ };
561
815
  // MOSS emits its native 24 kHz only (the addon rejects any other
562
816
  // `outputSampleRate`) and supports neither the LavaSR stages nor a smaller
563
817
  // first streaming chunk, so none of those fields exist on this arm.
@@ -573,14 +827,20 @@ const ttsMossRuntimeConfigShape = {
573
827
  .min(1)
574
828
  .optional()
575
829
  .describe('Language hint written into the model prompt, e.g. `en` or `zh`. Default `en`.'),
576
- durationTokens: ttsIntegerSchema
830
+ durationTokens: ttsInt32Schema
577
831
  .min(0)
578
- .max(TTS_MOSS_MAX_DURATION_TOKENS)
579
832
  .optional()
580
- .describe('Target length of each synthesis in codec frames (12.5 per second, so 38 ≈ 3 s), 0–2015; 0 or unset keeps the length free.'),
833
+ .describe('Target length of each synthesis in codec frames (12.5 per second, so 38 ≈ 3 s), at most `maxNewTokens` − 33 (2015 by default); 0 or unset keeps the length free.'),
581
834
  streamChunkTokens: ttsNonNegativeInt32Schema
582
835
  .optional()
583
836
  .describe('Codec frames per native streaming chunk (12.5 per second, so 25 ≈ 2 s); 0 or unset synthesizes the whole text before emitting.'),
837
+ nCtx: ttsPositiveInt32Schema
838
+ .optional()
839
+ .describe('Context capacity of the backbone in rows; unset keeps the native value.'),
840
+ maxNewTokens: ttsPositiveInt32Schema
841
+ .optional()
842
+ .describe('Generation budget in rows (engine default 2048), of which 33 are delay/EOS rows; bounds `durationTokens`.'),
843
+ ...ttsMossSamplingFieldsShape,
584
844
  useGPU: z.boolean().optional().describe(TTS_USE_GPU_DESC),
585
845
  threads: ttsPositiveInt32Schema.optional().describe(TTS_THREADS_DESC),
586
846
  // Not TTS_NGPU_LAYERS_DESC: MOSS does not offload per layer, so a layer
@@ -593,7 +853,7 @@ const ttsMossRuntimeConfigShape = {
593
853
  };
594
854
  export const ttsMossRuntimeConfigSchema = z
595
855
  .object(ttsMossRuntimeConfigShape)
596
- .superRefine(refineGpuIntent);
856
+ .superRefine(refineMossRuntimeConfig);
597
857
  // JSON PCM keeps the client and wire portable; converted to Float32Array at the addon boundary.
598
858
  const ttsSpeechPcmSchema = z.array(z.number().min(-1).max(1)).min(1);
599
859
  const ttsSpeechRateSchema = z.number().int().min(8000).max(192000);
@@ -675,19 +935,23 @@ const ttsBatchBackendShape = {
675
935
  seed: ttsInt32Schema.optional().describe(TTS_SEED_DESC),
676
936
  ...ttsBackendDirFieldsShape
677
937
  };
938
+ function refineMossBatchRuntimeConfig(config, ctx) {
939
+ refineGpuIntent(config, ctx);
940
+ refineNoWebgpuBackend(config, ctx);
941
+ }
678
942
  export const ttsMossSoundEffectRuntimeConfigSchema = z
679
943
  .object({
680
944
  ttsEngine: z.literal('moss-sfx').describe('TTS engine: MOSS-SoundEffect-v2.'),
681
945
  ...ttsBatchBackendShape,
682
946
  ...ttsSoundEffectFieldsShape
683
947
  })
684
- .superRefine(refineGpuIntent);
948
+ .superRefine(refineMossBatchRuntimeConfig);
685
949
  export const ttsMossSpeechRuntimeConfigSchema = z
686
950
  .object({
687
951
  ttsEngine: z.literal('moss-speech').describe('TTS engine: MOSS-Speech.'),
688
952
  ...ttsBatchBackendShape
689
953
  })
690
- .superRefine(refineGpuIntent);
954
+ .superRefine(refineMossBatchRuntimeConfig);
691
955
  export const ttsMossSoundEffectLoadConfigSchema = ttsMossSoundEffectRuntimeConfigSchema;
692
956
  export const ttsMossSpeechLoadConfigSchema = ttsMossSpeechRuntimeConfigSchema.extend({
693
957
  mossSpeechCodecModelSrc: modelSrcInputSchema.describe('MOSS-Speech codec GGUF source; modelSrc is the language model.')
@@ -712,8 +976,56 @@ const ttsLavasrLoadFieldsShape = {
712
976
  .describe('LavaSR enhancer model source; bandwidth-extends the output to 48 kHz.'),
713
977
  lavasrDenoiserModelSrc: modelSrcInputSchema
714
978
  .optional()
715
- .describe('LavaSR denoiser model source; runs before the enhancer, rate-preserving (batch synthesis only).')
979
+ .describe('LavaSR denoiser model source; runs before the enhancer, rate-preserving (batch synthesis only).'),
980
+ // The Core ML models are compiled `.mlmodelc` directories, not single files,
981
+ // so they are host paths rather than model sources. Each stage takes its
982
+ // path and compute policy together, beside its GGUF source.
983
+ lavasrEnhancerCoremlModelPath: z
984
+ .string()
985
+ .min(1)
986
+ .optional()
987
+ .describe('macOS / iOS: compiled Core ML model directory (`.mlmodelc`) on the inference host for the LavaSR enhancer’s neural core; requires `lavasrEnhancerModelSrc` and `lavasrEnhancerCoremlComputeUnits`. A model that cannot load fails the load rather than falling back to ggml.'),
988
+ lavasrEnhancerCoremlComputeUnits: z
989
+ .enum(TTS_LAVASR_COREML_COMPUTE_UNITS)
990
+ .optional()
991
+ .describe('macOS / iOS: Core ML compute policy for the LavaSR enhancer; required with `lavasrEnhancerCoremlModelPath`. Stats then report the stage as device `2` (Core ML-managed), backend `99`.'),
992
+ lavasrDenoiserCoremlModelPath: z
993
+ .string()
994
+ .min(1)
995
+ .optional()
996
+ .describe('macOS / iOS: compiled Core ML model directory (`.mlmodelc`) on the inference host for the LavaSR denoiser’s neural core; requires `lavasrDenoiserModelSrc` and `lavasrDenoiserCoremlComputeUnits`. A model that cannot load fails the load rather than falling back to ggml.'),
997
+ lavasrDenoiserCoremlComputeUnits: z
998
+ .enum(TTS_LAVASR_COREML_COMPUTE_UNITS)
999
+ .optional()
1000
+ .describe('macOS / iOS: Core ML compute policy for the LavaSR denoiser; required with `lavasrDenoiserCoremlModelPath`. Stats then report the stage as device `2` (Core ML-managed), backend `99`.')
716
1001
  };
1002
+ // Mirrors the addon's validateLavaSRCoreML: the path and the policy come as a
1003
+ // pair, and a pair without the stage's GGUF has no stage to attach to.
1004
+ function refineLavasrCoreml(config, ctx) {
1005
+ for (const stage of ['Enhancer', 'Denoiser']) {
1006
+ const pathField = `lavasr${stage}CoremlModelPath`;
1007
+ const unitsField = `lavasr${stage}CoremlComputeUnits`;
1008
+ const srcField = `lavasr${stage}ModelSrc`;
1009
+ const path = config[pathField];
1010
+ const units = config[unitsField];
1011
+ if (path === undefined && units === undefined)
1012
+ continue;
1013
+ if (path === undefined || units === undefined) {
1014
+ ctx.addIssue({
1015
+ code: 'custom',
1016
+ path: [path === undefined ? pathField : unitsField],
1017
+ message: `${pathField} and ${unitsField} must be supplied together.`
1018
+ });
1019
+ }
1020
+ if (config[srcField] === undefined) {
1021
+ ctx.addIssue({
1022
+ code: 'custom',
1023
+ path: [srcField],
1024
+ message: `${srcField} is required when the LavaSR ${stage.toLowerCase()} runs on Core ML (${pathField}).`
1025
+ });
1026
+ }
1027
+ }
1028
+ }
717
1029
  // The denoiser needs the whole utterance, so every engine with native chunk
718
1030
  // streaming rejects the pair at load. Shared so Chatterbox, Parler and
719
1031
  // CosyVoice3 fail the same way with the same message.
@@ -744,11 +1056,46 @@ export const ttsChatterboxLoadConfigSchema = ttsChatterboxRuntimeConfigSchema
744
1056
  .describe('Chatterbox MTL only: Cangjie TSV source for Chinese romanisation (required for language `zh`).'),
745
1057
  ...ttsLavasrLoadFieldsShape
746
1058
  })
747
- .superRefine(refineLavasrDenoiserStreaming);
748
- // Supertonic has no native chunk streaming, so the denoiser is always reachable.
749
- export const ttsSupertonicLoadConfigSchema = ttsSupertonicRuntimeConfigSchema.extend({
750
- ...ttsLavasrLoadFieldsShape
751
- });
1059
+ .superRefine(refineChatterboxLoadConfig);
1060
+ function refineChatterboxLoadConfig(config, ctx) {
1061
+ refineLavasrDenoiserStreaming(config, ctx);
1062
+ refineLavasrCoreml(config, ctx);
1063
+ }
1064
+ // Supertonic native chunk streaming rejects BOTH LavaSR stages, not just the
1065
+ // denoiser: tts-cpp only has one-shot enhance / denoise for this engine, and
1066
+ // it reports no native rate before synthesis. Sentence streaming still works
1067
+ // with either stage loaded.
1068
+ function refineSupertonicLoadConfig(config, ctx) {
1069
+ refineSupertonicRateControls(config, ctx);
1070
+ refineLavasrCoreml(config, ctx);
1071
+ if ((config.streamChunkTokens ?? 0) <= 0)
1072
+ return;
1073
+ for (const field of ['lavasrEnhancerModelSrc', 'lavasrDenoiserModelSrc']) {
1074
+ if (config[field] === undefined)
1075
+ continue;
1076
+ ctx.addIssue({
1077
+ code: 'custom',
1078
+ path: [field],
1079
+ message: 'Supertonic native chunk streaming (streamChunkTokens > 0) cannot be combined with the LavaSR enhancer or denoiser; ' +
1080
+ 'use sentence streaming (stream: true without streamChunkTokens, sentenceStream, or textToSpeechStream) for enhanced output.'
1081
+ });
1082
+ }
1083
+ }
1084
+ // Supertonic's external voice JSON and fixed CFM noise tensor are single files,
1085
+ // so they ride the same source resolution as the LavaSR GGUFs and reach the
1086
+ // addon as `voiceJsonPath` / `noiseNpyPath`.
1087
+ export const ttsSupertonicLoadConfigSchema = z
1088
+ .object({
1089
+ ...ttsSupertonicRuntimeConfigShape,
1090
+ ...ttsLavasrLoadFieldsShape,
1091
+ voiceJsonSrc: modelSrcInputSchema
1092
+ .optional()
1093
+ .describe('External voice JSON source (`{ style_ttl, style_dp }`, e.g. a cloned voice) that overrides the baked `voice` preset; the engine checks the tensor sizes against the loaded model.'),
1094
+ noiseNpySrc: modelSrcInputSchema
1095
+ .optional()
1096
+ .describe('Fixed CFM initial-noise `.npy` tensor source, for reproducible output.')
1097
+ })
1098
+ .superRefine(refineSupertonicLoadConfig);
752
1099
  function refineParlerLoadConfig(config, ctx) {
753
1100
  refineParlerDescriptionFields(config, ctx);
754
1101
  refineGpuIntent(config, ctx);
@@ -758,6 +1105,7 @@ function refineParlerLoadConfig(config, ctx) {
758
1105
  refineParlerNativeStreamingRate(config, ctx);
759
1106
  }
760
1107
  refineLavasrDenoiserStreaming(config, ctx);
1108
+ refineLavasrCoreml(config, ctx);
761
1109
  }
762
1110
  export const ttsParlerLoadConfigSchema = z
763
1111
  .object({
@@ -821,6 +1169,7 @@ function refineCosyvoice3LoadConfig(config, ctx) {
821
1169
  refineCosyvoice3NativeStreamingRate(config, ctx);
822
1170
  }
823
1171
  refineLavasrDenoiserStreaming(config, ctx);
1172
+ refineLavasrCoreml(config, ctx);
824
1173
  refineCosyvoice3Cloning(config, ctx);
825
1174
  }
826
1175
  // CosyVoice3 loads from a model *directory* (LLM/flow/HiFT GGUFs plus
@@ -877,9 +1226,10 @@ export const ttsAudio8LoadConfigSchema = z
877
1226
  })
878
1227
  .superRefine(refineAudio8LoadConfig);
879
1228
  // The addon enforces the same three rules at construction; catching them here
880
- // names the SDK field instead of the addon's `files.*` option.
1229
+ // names the SDK field instead of the addon's `files.*` option. Built from the
1230
+ // runtime *shape*, so the runtime refinements are re-run here too.
881
1231
  function refineMossLoadConfig(config, ctx) {
882
- refineGpuIntent(config, ctx);
1232
+ refineMossRuntimeConfig(config, ctx);
883
1233
  if (config.referenceAudioSrc !== undefined && config.dialogueReferenceSrcs !== undefined) {
884
1234
  ctx.addIssue({
885
1235
  code: 'custom',
@@ -1005,6 +1355,55 @@ const ttsRequestIdSchema = z
1005
1355
  .min(1)
1006
1356
  .optional()
1007
1357
  .describe('Client-generated id for targeting this run with `cancel({ requestId })`.');
1358
+ // Per-request voice controls the addon takes on `run()`, `runStream()` and
1359
+ // `runStreaming()` alike. A request carries only an opaque modelId, so the
1360
+ // engine check (CosyVoice3 for `instruct`, Audio8 for the reference pair)
1361
+ // happens in the op once the model is known; the shape rules below hold on
1362
+ // every engine.
1363
+ const ttsRequestVoiceFieldsShape = {
1364
+ instruct: ttsCosyvoice3InstructSchema
1365
+ .optional()
1366
+ .describe('CosyVoice3 only: natural-language control for this synthesis (a structured object with one of dialect / volume / style, or a raw instruction string), replacing the loaded `instruct`, `emotion` or `pace`. One conditioning control per synthesis.'),
1367
+ referenceAudioSrc: modelSrcInputSchema
1368
+ .optional()
1369
+ .describe('Audio8 only: reference recording to clone for this request, replacing the loaded voice; requires `referenceText` and a loaded codec encoder (`audio8CodecEncoderModelSrc`). A remote source that is not cached yet downloads inside the request, which holds the model until it finishes: pre-fetch it with `downloadAsset()` or pass a local path.'),
1370
+ // Trimmed like the load-time referenceText: a whitespace-only transcript
1371
+ // would reach the engine as a non-empty value.
1372
+ referenceText: z
1373
+ .string()
1374
+ .trim()
1375
+ .min(1)
1376
+ .optional()
1377
+ .describe('Audio8 only: transcript of the reference recording. With `referenceAudioSrc`, what that recording says; alone, it corrects the transcript of the loaded recording.')
1378
+ };
1379
+ // Mirrors the addon's per-call rules that hold regardless of the loaded
1380
+ // engine: a per-call recording must bring its own transcript (the configured
1381
+ // one describes a different recording), and `instruct` is a CosyVoice3
1382
+ // control, so pairing it with an emotion or a non-moderate pace always breaks
1383
+ // the one-instruction rule.
1384
+ function refineTtsRequestVoiceFields(value, ctx) {
1385
+ if (value.referenceAudioSrc !== undefined && value.referenceText === undefined) {
1386
+ ctx.addIssue({
1387
+ code: 'custom',
1388
+ path: ['referenceText'],
1389
+ message: 'referenceText (the transcript of the reference recording) is required with referenceAudioSrc.'
1390
+ });
1391
+ }
1392
+ if (value.instruct === undefined)
1393
+ return;
1394
+ const conflicting = value.emotion !== undefined
1395
+ ? 'emotion'
1396
+ : value.pace !== undefined && value.pace !== 'moderate'
1397
+ ? 'pace'
1398
+ : undefined;
1399
+ if (conflicting !== undefined) {
1400
+ ctx.addIssue({
1401
+ code: 'custom',
1402
+ path: [conflicting],
1403
+ message: `CosyVoice3 accepts one conditioning control per synthesis; got instruct and ${conflicting}. Set exactly one (pace "moderate" disengages the pace channel).`
1404
+ });
1405
+ }
1406
+ }
1008
1407
  const ttsClientParamsShape = {
1009
1408
  modelId: z.string(),
1010
1409
  requestId: ttsRequestIdSchema,
@@ -1015,11 +1414,13 @@ const ttsClientParamsShape = {
1015
1414
  sentenceStreamLocale: z.string().optional(),
1016
1415
  sentenceStreamMaxChunkScalars: z.number().positive().optional(),
1017
1416
  ...ttsParlerDescriptionFieldsShape,
1417
+ ...ttsRequestVoiceFieldsShape,
1018
1418
  ...ttsSoundEffectFieldsShape,
1019
1419
  ...ttsSpeechFieldsShape
1020
1420
  };
1021
1421
  function refineTtsRequest(value, ctx) {
1022
1422
  refineParlerDescriptionFields(value, ctx);
1423
+ refineTtsRequestVoiceFields(value, ctx);
1023
1424
  refineSpeechAudio(value, ctx);
1024
1425
  if ((value.replyVoice !== undefined) !== (value.replyVoiceSampleRate !== undefined)) {
1025
1426
  ctx.addIssue({
@@ -1039,6 +1440,7 @@ export const ttsRequestSchema = z
1039
1440
  ...ttsClientParamsShape,
1040
1441
  type: z.literal('textToSpeech')
1041
1442
  })
1443
+ .extend(trackedRequestSchema.shape)
1042
1444
  .superRefine(refineTtsRequest);
1043
1445
  // Mirrors @qvac/tts-ggml's `RuntimeStats`, using the same field names as the
1044
1446
  // transcription and audio-gen stats so a caller reads one vocabulary across
@@ -1047,15 +1449,22 @@ export const ttsRequestSchema = z
1047
1449
  // `realTimeFactor` = `totalTime` * 1000 / `audioDuration`.
1048
1450
  //
1049
1451
  // The chunked paths (`stream: true`, `sentenceStream`, and the duplex session)
1050
- // run one native job per sentence and the addon's aggregate carries only the
1051
- // four summable fields (totalTime, audioDuration, totalSamples,
1052
- // generatedFrames) and Audio8's two Core ML flags, which keep the value of the
1053
- // last sentence that reported them; the five backend fields below are
1054
- // reported by batch synthesis (`stream: false`) only.
1452
+ // run one native job per sentence. The addon's aggregate sums the four
1453
+ // summable fields (totalTime, audioDuration, totalSamples, generatedFrames)
1454
+ // and keeps the backend fields below and Audio8's two Core ML flags from the
1455
+ // last sentence that reported them, so a chunked run reports where it ran
1456
+ // just as batch synthesis (`stream: false`) does. A field no sentence
1457
+ // reported stays absent.
1458
+ // Milliseconds, like every other `*Ms` field below.
1459
+ const ttsStageMsSchema = (stage) => z.number().optional().describe(`${stage} wall time of the last synthesis, in milliseconds.`);
1055
1460
  export const ttsStatsSchema = z.object({
1056
1461
  audioDuration: z.number().optional(),
1057
1462
  totalTime: z.number().optional(),
1058
1463
  realTimeFactor: z.number().optional(),
1464
+ firstAudioMs: z
1465
+ .number()
1466
+ .optional()
1467
+ .describe('Milliseconds from the start of the run to the first audio, where the engine reports it; a chunked run keeps the first sentence’s value.'),
1059
1468
  tokensPerSecond: z.number().optional(),
1060
1469
  totalSamples: z.number().optional(),
1061
1470
  // Audio8 (on a fixed 46 ms grid) and MOSS (12.5 per second) count codec
@@ -1064,13 +1473,24 @@ export const ttsStatsSchema = z.object({
1064
1473
  generatedFrames: z.number().optional(),
1065
1474
  // Backend selection captured once at model load. `0` CPU / `1` GPU;
1066
1475
  // `backendId` codes the family (0 CPU, 1 Metal, 2 CUDA, 3 Vulkan, 4 OpenCL,
1067
- // 99 other GPU). The enhancer fields report the LavaSR stage separately and
1068
- // are `-1` when no enhancer is loaded.
1476
+ // 5 WebGPU, 99 other GPU). The enhancer and denoiser fields report each
1477
+ // LavaSR stage separately and are `-1` when that stage is not loaded.
1069
1478
  backendDevice: z.number().optional(),
1070
- backendId: z.number().optional(),
1479
+ backendId: z
1480
+ .number()
1481
+ .optional()
1482
+ .describe('Backend family the engine ran on: `0` CPU, `1` Metal, `2` CUDA, `3` Vulkan, `4` OpenCL, `5` WebGPU, `99` other.'),
1071
1483
  gpuUnsupported: z.number().optional(),
1072
1484
  enhancerBackendDevice: z.number().optional(),
1073
1485
  enhancerBackendId: z.number().optional(),
1486
+ denoiserBackendDevice: z
1487
+ .number()
1488
+ .optional()
1489
+ .describe('LavaSR denoiser device: `-1` not loaded, `0` CPU, `1` GPU, `2` Core ML-managed.'),
1490
+ denoiserBackendId: z
1491
+ .number()
1492
+ .optional()
1493
+ .describe('LavaSR denoiser backend family, same codes as `backendId`.'),
1074
1494
  codecSidecarLoaded: z
1075
1495
  .number()
1076
1496
  .optional()
@@ -1078,7 +1498,76 @@ export const ttsStatsSchema = z.object({
1078
1498
  codecOnCoreml: z
1079
1499
  .number()
1080
1500
  .optional()
1081
- .describe('Audio8: `1` when this synthesis ran its codec on the Core ML sidecar, `0` when it ran on the ggml backend `backendId` reports.')
1501
+ .describe('Audio8: `1` when this synthesis ran its codec on the Core ML sidecar, `0` when it ran on the ggml backend `backendId` reports.'),
1502
+ // Parler Core ML sidecars (macOS / iOS): availability flags keep the last
1503
+ // report, the "used" flags are 1 only when every reported sentence used the
1504
+ // stage. None of them says which hardware Core ML scheduled the work on.
1505
+ decoderSidecarLoaded: z
1506
+ .number()
1507
+ .optional()
1508
+ .describe('Parler on macOS / iOS: `1` while the Core ML decoder sidecar is attached, `0` once a fallback retired it.'),
1509
+ dacSidecarLoaded: z
1510
+ .number()
1511
+ .optional()
1512
+ .describe('Parler on macOS / iOS: `1` while the Core ML DAC sidecar is attached, `0` once a fallback retired it.'),
1513
+ decoderOnCoreml: z
1514
+ .number()
1515
+ .optional()
1516
+ .describe('Parler: `1` when this synthesis ran its decoder steps on Core ML, `0` for ggml or a mixed run.'),
1517
+ dacOnCoreml: z
1518
+ .number()
1519
+ .optional()
1520
+ .describe('Parler: `1` when this synthesis ran its DAC on Core ML, `0` for ggml or a mixed run.'),
1521
+ // Chatterbox stage timings and counters.
1522
+ t3Ms: ttsStageMsSchema('Chatterbox T3 decode'),
1523
+ s3genMs: ttsStageMsSchema('Chatterbox S3Gen + HiFT'),
1524
+ t3Tokens: z
1525
+ .number()
1526
+ .optional()
1527
+ .describe('Chatterbox: speech tokens T3 emitted in the last synthesis.'),
1528
+ // CosyVoice3 and Audio8: the engine's own wall time, the sum of its stages.
1529
+ stageTotalMs: z
1530
+ .number()
1531
+ .optional()
1532
+ .describe('CosyVoice3 / Audio8: the engine’s own wall time for the last synthesis in milliseconds (the sum of its stages), excluding the addon’s post-processing.'),
1533
+ // CosyVoice3 stage timings.
1534
+ lmPrefillMs: ttsStageMsSchema('CosyVoice3 LM prefill'),
1535
+ lmDecodeMs: ttsStageMsSchema('CosyVoice3 LM decode'),
1536
+ flowFrontendMs: ttsStageMsSchema('CosyVoice3 flow front-end'),
1537
+ ditEulerMs: ttsStageMsSchema('CosyVoice3 DiT Euler'),
1538
+ hiftF0Ms: ttsStageMsSchema('CosyVoice3 HiFT F0'),
1539
+ hiftSourceMs: ttsStageMsSchema('CosyVoice3 HiFT source'),
1540
+ hiftStftMs: ttsStageMsSchema('CosyVoice3 HiFT STFT'),
1541
+ hiftDecodeMs: ttsStageMsSchema('CosyVoice3 HiFT decode'),
1542
+ // CosyVoice3 work counters.
1543
+ decodeSteps: z.number().optional().describe('CosyVoice3: LM decode steps of the last synthesis.'),
1544
+ speechTokens: z
1545
+ .number()
1546
+ .optional()
1547
+ .describe('CosyVoice3: speech tokens generated in the last synthesis.'),
1548
+ flowFrames: z
1549
+ .number()
1550
+ .optional()
1551
+ .describe('CosyVoice3: flow frames in (prompt + generated) of the last synthesis.'),
1552
+ melFrames: z.number().optional().describe('CosyVoice3: mel frames out of the last synthesis.'),
1553
+ textIds: z
1554
+ .number()
1555
+ .optional()
1556
+ .describe('CosyVoice3: text ids in the LM prefill of the last synthesis.'),
1557
+ promptSpeechTokens: z
1558
+ .number()
1559
+ .optional()
1560
+ .describe('CosyVoice3: prompt speech tokens the LM continued from.'),
1561
+ // Audio8 stage timings.
1562
+ voiceEncodeMs: ttsStageMsSchema('Audio8 reference-voice encode'),
1563
+ promptMs: ttsStageMsSchema('Audio8 prompt build'),
1564
+ prefillMs: ttsStageMsSchema('Audio8 prefill'),
1565
+ sampleMs: ttsStageMsSchema('Audio8 sampling'),
1566
+ fastDecodeMs: ttsStageMsSchema('Audio8 fast (local) decoder'),
1567
+ slowDecodeMs: ttsStageMsSchema('Audio8 slow (global) decoder'),
1568
+ codecLatentMs: ttsStageMsSchema('Audio8 codec latent'),
1569
+ codecSynthMs: ttsStageMsSchema('Audio8 codec synthesis'),
1570
+ resampleMs: ttsStageMsSchema('Audio8 resample')
1082
1571
  });
1083
1572
  // The rate of `buffer`. It is not a constant of the engine: `outputSampleRate`
1084
1573
  // and the LavaSR enhancer both move it, so a caller writing a WAV or feeding
@@ -1089,10 +1578,23 @@ const ttsResponseSampleRateSchema = z
1089
1578
  .positive()
1090
1579
  .optional()
1091
1580
  .describe('Sample rate in Hz of the signed 16-bit mono PCM in `buffer`.');
1581
+ // CosyVoice3 owns its speech-token trajectory and hands it back: with the PCM
1582
+ // in batch synthesis, on a final `isLast` frame with no audio under native
1583
+ // chunk streaming. One frame's array replays that one native synthesis through
1584
+ // the load config's `forceSpeechTokens`; the sentence paths run one synthesis
1585
+ // per sentence, so their arrays replay sentence by sentence, not joined.
1586
+ const ttsResponseSpeechTokenIdsSchema = z
1587
+ .array(ttsSpeechTokenIdSchema)
1588
+ .optional()
1589
+ .describe('CosyVoice3: the speech tokens of this native synthesis. Batch synthesis carries them with the PCM; native chunk streaming on a final `isLast` frame with no audio; the sentence paths once per sentence. Pass one array back as `forceSpeechTokens` to replay that synthesis (a joined sentence stream cannot be replayed as one).');
1092
1590
  export const ttsResponseSchema = z.object({
1093
1591
  type: z.literal('textToSpeech'),
1094
1592
  text: z.string().optional().describe('MOSS-Speech reply text, including text-only replies.'),
1095
1593
  buffer: z.array(z.number()),
1594
+ pcm: z
1595
+ .string()
1596
+ .optional()
1597
+ .describe('Base64 of the little-endian signed 16-bit PCM of this frame. When present, `buffer` is empty and this field carries the samples; decode with `withDecodedTtsPcm`.'),
1096
1598
  done: z.boolean().default(false),
1097
1599
  sampleRate: ttsResponseSampleRateSchema,
1098
1600
  stats: ttsStatsSchema.optional(),
@@ -1102,6 +1604,7 @@ export const ttsResponseSchema = z.object({
1102
1604
  .boolean()
1103
1605
  .optional()
1104
1606
  .describe('True on the final audio-bearing chunk of a pre-chunked synthesis. Absent when the chunk count is not known up front (streamed text in).'),
1607
+ speechTokenIds: ttsResponseSpeechTokenIdsSchema,
1105
1608
  // On the terminal frame only: how the run ended. A run stopped by
1106
1609
  // `cancel()` ends cleanly with `cancelled` rather than as an error.
1107
1610
  stopReason: z.enum(['completed', 'cancelled']).optional()
@@ -1117,17 +1620,27 @@ const textToSpeechStreamRequestBaseShape = {
1117
1620
  sentenceDelimiterPreset: z.enum(TTS_SENTENCE_DELIMITER_PRESETS).optional(),
1118
1621
  maxBufferScalars: z.number().positive().optional(),
1119
1622
  flushAfterMs: z.number().positive().optional(),
1120
- ...ttsParlerDescriptionFieldsShape
1623
+ ...ttsParlerDescriptionFieldsShape,
1624
+ ...ttsRequestVoiceFieldsShape
1121
1625
  };
1626
+ function refineTextToSpeechStreamRequest(value, ctx) {
1627
+ refineParlerDescriptionFields(value, ctx);
1628
+ refineTtsRequestVoiceFields(value, ctx);
1629
+ }
1122
1630
  export const textToSpeechStreamRequestSchema = z
1123
1631
  .object({
1124
1632
  ...textToSpeechStreamRequestBaseShape,
1125
1633
  type: z.literal('textToSpeechStream')
1126
1634
  })
1127
- .superRefine(refineParlerDescriptionFields);
1635
+ .extend(trackedRequestSchema.shape)
1636
+ .superRefine(refineTextToSpeechStreamRequest);
1128
1637
  export const textToSpeechStreamResponseSchema = z.object({
1129
1638
  type: z.literal('textToSpeechStream'),
1130
1639
  buffer: z.array(z.number()),
1640
+ pcm: z
1641
+ .string()
1642
+ .optional()
1643
+ .describe('Base64 of the little-endian signed 16-bit PCM of this frame. When present, `buffer` is empty and this field carries the samples; decode with `withDecodedTtsPcm`.'),
1131
1644
  done: z.boolean().default(false),
1132
1645
  sampleRate: ttsResponseSampleRateSchema,
1133
1646
  stats: ttsStatsSchema.optional(),
@@ -1137,6 +1650,7 @@ export const textToSpeechStreamResponseSchema = z.object({
1137
1650
  .boolean()
1138
1651
  .optional()
1139
1652
  .describe('True on the final audio-bearing chunk of a pre-chunked synthesis. Absent when the chunk count is not known up front (streamed text in).'),
1653
+ speechTokenIds: ttsResponseSpeechTokenIdsSchema,
1140
1654
  // On the terminal frame only: how the run ended. A run stopped by
1141
1655
  // `cancel()` ends cleanly with `cancelled` rather than as an error.
1142
1656
  stopReason: z.enum(['completed', 'cancelled']).optional()