@qvac/sdk 0.9.2 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (333) hide show
  1. package/NOTICE +15 -68
  2. package/dist/client/api/cancel.d.ts +1 -1
  3. package/dist/client/api/cancel.js +1 -1
  4. package/dist/client/api/completion-stream.d.ts +51 -12
  5. package/dist/client/api/completion-stream.js +129 -56
  6. package/dist/client/api/delete-cache.d.ts +1 -0
  7. package/dist/client/api/delete-cache.js +1 -0
  8. package/dist/client/api/diffusion.d.ts +17 -2
  9. package/dist/client/api/diffusion.js +21 -4
  10. package/dist/client/api/embed.d.ts +4 -0
  11. package/dist/client/api/finetune.d.ts +21 -0
  12. package/dist/client/api/get-loaded-model-info.d.ts +25 -0
  13. package/dist/client/api/get-loaded-model-info.js +36 -0
  14. package/dist/client/api/get-model-info.d.ts +9 -1
  15. package/dist/client/api/get-model-info.js +8 -0
  16. package/dist/client/api/heartbeat.d.ts +2 -2
  17. package/dist/client/api/heartbeat.js +2 -2
  18. package/dist/client/api/index.d.ts +3 -1
  19. package/dist/client/api/index.js +3 -1
  20. package/dist/client/api/invoke-plugin.d.ts +16 -0
  21. package/dist/client/api/invoke-plugin.js +16 -0
  22. package/dist/client/api/load-model.d.ts +36 -3
  23. package/dist/client/api/load-model.js +31 -10
  24. package/dist/client/api/provide.d.ts +11 -5
  25. package/dist/client/api/provide.js +11 -6
  26. package/dist/client/api/rag.d.ts +9 -0
  27. package/dist/client/api/rag.js +9 -0
  28. package/dist/client/api/registry.d.ts +26 -0
  29. package/dist/client/api/registry.js +26 -0
  30. package/dist/client/api/resume.d.ts +20 -4
  31. package/dist/client/api/resume.js +20 -4
  32. package/dist/client/api/state.d.ts +23 -0
  33. package/dist/client/api/state.js +29 -0
  34. package/dist/client/api/stop-provider.d.ts +11 -5
  35. package/dist/client/api/stop-provider.js +11 -5
  36. package/dist/client/api/suspend.d.ts +21 -3
  37. package/dist/client/api/suspend.js +21 -3
  38. package/dist/client/api/text-to-speech.d.ts +64 -6
  39. package/dist/client/api/text-to-speech.js +423 -47
  40. package/dist/client/api/transcribe.d.ts +29 -4
  41. package/dist/client/api/transcribe.js +86 -28
  42. package/dist/client/api/translate.d.ts +1 -0
  43. package/dist/client/api/translate.js +1 -0
  44. package/dist/client/rpc/bare-client.js +22 -1
  45. package/dist/client/rpc/expo-rpc-client.d.ts +1 -1
  46. package/dist/client/rpc/expo-rpc-client.js +96 -4
  47. package/dist/client/rpc/node-rpc-client.js +36 -0
  48. package/dist/examples/audio/mic-input.d.ts +9 -0
  49. package/dist/examples/audio/mic-input.js +111 -0
  50. package/dist/examples/completion-events.d.ts +18 -0
  51. package/dist/examples/completion-events.js +79 -0
  52. package/dist/examples/delegated-inference/composite.js +12 -18
  53. package/dist/examples/delegated-inference/consumer-profiled.js +4 -11
  54. package/dist/examples/delegated-inference/consumer.js +8 -13
  55. package/dist/examples/delegated-inference/provider.js +11 -16
  56. package/dist/examples/diffusion-flux2-klein-img2img.d.ts +2 -0
  57. package/dist/examples/diffusion-flux2-klein-img2img.js +60 -0
  58. package/dist/examples/diffusion-flux2-klein.js +1 -0
  59. package/dist/examples/diffusion-img2img.d.ts +2 -0
  60. package/dist/examples/diffusion-img2img.js +49 -0
  61. package/dist/examples/diffusion-txt2img.js +2 -1
  62. package/dist/examples/kv-cache-example.js +11 -12
  63. package/dist/examples/llamacpp-cache.d.ts +2 -0
  64. package/dist/examples/llamacpp-cache.js +107 -0
  65. package/dist/examples/llamacpp-dynamic-tools.d.ts +2 -0
  66. package/dist/examples/llamacpp-dynamic-tools.js +144 -0
  67. package/dist/examples/llamacpp-native-tools.js +2 -8
  68. package/dist/examples/llamacpp-structured-output.d.ts +2 -0
  69. package/dist/examples/llamacpp-structured-output.js +106 -0
  70. package/dist/examples/llamacpp-tools-pythonic.d.ts +2 -0
  71. package/dist/examples/llamacpp-tools-pythonic.js +69 -0
  72. package/dist/examples/plugins.js +4 -4
  73. package/dist/examples/suspend-resume.js +21 -4
  74. package/dist/examples/transcription/parakeet-microphone-record.js +6 -33
  75. package/dist/examples/transcription/whispercpp-filesystem-streaming.js +7 -5
  76. package/dist/examples/transcription/whispercpp-filesystem.js +12 -3
  77. package/dist/examples/transcription/whispercpp-microphone-record.js +6 -29
  78. package/dist/examples/translation/translation-stream.js +5 -5
  79. package/dist/examples/tts/llm-to-tts-streaming.d.ts +16 -0
  80. package/dist/examples/tts/llm-to-tts-streaming.js +143 -0
  81. package/dist/examples/tts/supertonic-multilingual.js +3 -3
  82. package/dist/examples/tts/supertonic.js +3 -3
  83. package/dist/examples/tts/utils.d.ts +11 -1
  84. package/dist/examples/tts/utils.js +70 -17
  85. package/dist/examples/voice-assistant/voice-assistant.d.ts +2 -0
  86. package/dist/examples/voice-assistant/voice-assistant.js +207 -0
  87. package/dist/expo/plugins/withMobileBundle.js +1 -1
  88. package/dist/index.d.ts +2 -2
  89. package/dist/index.js +2 -2
  90. package/dist/logging/logger.d.ts +11 -0
  91. package/dist/logging/logger.js +11 -0
  92. package/dist/logging/types.d.ts +18 -0
  93. package/dist/models/registry/models.d.ts +6620 -6185
  94. package/dist/models/registry/models.js +6296 -5318
  95. package/dist/models/update-models/codegen.js +84 -23
  96. package/dist/models/update-models/companions.d.ts +18 -0
  97. package/dist/models/update-models/companions.js +175 -0
  98. package/dist/models/update-models/naming.js +0 -25
  99. package/dist/models/update-models/registry.js +4 -2
  100. package/dist/models/update-models/types.d.ts +37 -9
  101. package/dist/profiling/index.d.ts +49 -0
  102. package/dist/profiling/index.js +49 -0
  103. package/dist/schemas/cancel.d.ts +6 -2
  104. package/dist/schemas/cancel.js +14 -7
  105. package/dist/schemas/common.d.ts +353 -271
  106. package/dist/schemas/common.js +26 -5
  107. package/dist/schemas/completion-event.d.ts +225 -0
  108. package/dist/schemas/completion-event.js +79 -0
  109. package/dist/schemas/completion-stream.d.ts +122 -31
  110. package/dist/schemas/completion-stream.js +137 -36
  111. package/dist/schemas/delegate.d.ts +0 -2
  112. package/dist/schemas/delegate.js +25 -6
  113. package/dist/schemas/download-asset.d.ts +5 -5
  114. package/dist/schemas/embed.js +21 -9
  115. package/dist/schemas/engine-addon-map.d.ts +11 -1
  116. package/dist/schemas/engine-addon-map.js +2 -2
  117. package/dist/schemas/get-loaded-model-info.d.ts +52 -0
  118. package/dist/schemas/get-loaded-model-info.js +44 -0
  119. package/dist/schemas/get-model-info.d.ts +2 -2
  120. package/dist/schemas/get-model-info.js +103 -32
  121. package/dist/schemas/heartbeat.d.ts +0 -1
  122. package/dist/schemas/index.d.ts +4 -1
  123. package/dist/schemas/index.js +4 -1
  124. package/dist/schemas/llamacpp-config.d.ts +14 -4
  125. package/dist/schemas/llamacpp-config.js +5 -0
  126. package/dist/schemas/load-model.d.ts +3233 -1260
  127. package/dist/schemas/load-model.js +23 -16
  128. package/dist/schemas/model-src-utils.d.ts +7 -6
  129. package/dist/schemas/model-src-utils.js +27 -1
  130. package/dist/schemas/model-types.d.ts +4 -4
  131. package/dist/schemas/ocr.d.ts +1 -1
  132. package/dist/schemas/plugin.d.ts +27 -3
  133. package/dist/schemas/plugin.js +27 -2
  134. package/dist/schemas/profiling.js +11 -3
  135. package/dist/schemas/provide.d.ts +1 -3
  136. package/dist/schemas/provide.js +0 -3
  137. package/dist/schemas/rag.d.ts +4 -4
  138. package/dist/schemas/registry.d.ts +10 -10
  139. package/dist/schemas/registry.js +36 -14
  140. package/dist/schemas/reload-config.d.ts +73 -7
  141. package/dist/schemas/sdcpp-config.d.ts +16 -8
  142. package/dist/schemas/sdcpp-config.js +118 -25
  143. package/dist/schemas/sdk-config.d.ts +116 -90
  144. package/dist/schemas/sdk-config.js +16 -0
  145. package/dist/schemas/sdk-errors-client.d.ts +3 -0
  146. package/dist/schemas/sdk-errors-client.js +16 -1
  147. package/dist/schemas/sdk-errors-server.d.ts +3 -0
  148. package/dist/schemas/sdk-errors-server.js +23 -0
  149. package/dist/schemas/state.d.ts +23 -0
  150. package/dist/schemas/state.js +14 -0
  151. package/dist/schemas/stop-provide.d.ts +0 -5
  152. package/dist/schemas/stop-provide.js +2 -6
  153. package/dist/schemas/text-to-speech.d.ts +93 -27
  154. package/dist/schemas/text-to-speech.js +27 -0
  155. package/dist/schemas/tools.d.ts +16 -0
  156. package/dist/schemas/tools.js +15 -0
  157. package/dist/schemas/transcription-config.d.ts +8 -8
  158. package/dist/schemas/transcription.d.ts +33 -0
  159. package/dist/schemas/transcription.js +9 -0
  160. package/dist/schemas/translate.js +59 -19
  161. package/dist/schemas/translation-config.d.ts +157 -133
  162. package/dist/schemas/translation-config.js +34 -11
  163. package/dist/server/bare/delegate-rpc-client.d.ts +1 -1
  164. package/dist/server/bare/delegate-rpc-client.js +131 -122
  165. package/dist/server/bare/hyperswarm.d.ts +2 -2
  166. package/dist/server/bare/hyperswarm.js +12 -7
  167. package/dist/server/bare/ops/cancel.js +7 -0
  168. package/dist/server/bare/ops/kv-cache-utils.d.ts +7 -10
  169. package/dist/server/bare/ops/kv-cache-utils.js +31 -40
  170. package/dist/server/bare/ops/load-model.js +0 -1
  171. package/dist/server/bare/ops/transcribe.d.ts +11 -4
  172. package/dist/server/bare/ops/transcribe.js +25 -4
  173. package/dist/server/bare/ops/translate.js +42 -4
  174. package/dist/server/bare/ops/unload-model.js +21 -19
  175. package/dist/server/bare/plugins/llamacpp-completion/ops/cache-logger.js +1 -2
  176. package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.d.ts +13 -8
  177. package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.js +257 -85
  178. package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-state.d.ts +101 -0
  179. package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-state.js +135 -0
  180. package/dist/server/bare/plugins/llamacpp-completion/plugin.d.ts +79 -22
  181. package/dist/server/bare/plugins/llamacpp-completion/plugin.js +57 -32
  182. package/dist/server/bare/plugins/llamacpp-embedding/plugin.js +10 -16
  183. package/dist/server/bare/plugins/nmtcpp-translation/plugin.d.ts +69 -44
  184. package/dist/server/bare/plugins/nmtcpp-translation/plugin.js +113 -94
  185. package/dist/server/bare/plugins/onnx-ocr/plugin.d.ts +1 -1
  186. package/dist/server/bare/plugins/onnx-ocr/plugin.js +1 -2
  187. package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech-stream.d.ts +7 -0
  188. package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech-stream.js +116 -0
  189. package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech.d.ts +2 -3
  190. package/dist/server/bare/plugins/onnx-tts/ops/text-to-speech.js +71 -9
  191. package/dist/server/bare/plugins/onnx-tts/plugin.d.ts +41 -13
  192. package/dist/server/bare/plugins/onnx-tts/plugin.js +48 -3
  193. package/dist/server/bare/plugins/parakeet-transcription/plugin.d.ts +15 -7
  194. package/dist/server/bare/plugins/parakeet-transcription/plugin.js +5 -6
  195. package/dist/server/bare/plugins/sdcpp-generation/ops/diffusion.js +6 -0
  196. package/dist/server/bare/plugins/sdcpp-generation/plugin.d.ts +8 -5
  197. package/dist/server/bare/plugins/sdcpp-generation/plugin.js +13 -13
  198. package/dist/server/bare/plugins/whispercpp-transcription/plugin.d.ts +17 -1
  199. package/dist/server/bare/plugins/whispercpp-transcription/plugin.js +40 -17
  200. package/dist/server/bare/registry/config-registry.js +14 -3
  201. package/dist/server/bare/registry/model-registry.d.ts +8 -10
  202. package/dist/server/bare/registry/model-registry.js +17 -12
  203. package/dist/server/bare/registry/registry-client.js +79 -19
  204. package/dist/server/bare/runtime-lifecycle.d.ts +2 -1
  205. package/dist/server/bare/runtime-lifecycle.js +13 -2
  206. package/dist/server/bare/types/addon-responses.d.ts +8 -3
  207. package/dist/server/bare/utils/transcribe-metadata.d.ts +21 -0
  208. package/dist/server/bare/utils/transcribe-metadata.js +28 -0
  209. package/dist/server/bare/utils/tts-stats.d.ts +22 -0
  210. package/dist/server/bare/utils/tts-stats.js +10 -0
  211. package/dist/server/rpc/create-server.d.ts +4 -1
  212. package/dist/server/rpc/create-server.js +5 -1
  213. package/dist/server/rpc/delegate-transport.js +36 -29
  214. package/dist/server/rpc/handle-request.js +28 -3
  215. package/dist/server/rpc/handler-registry.js +7 -1
  216. package/dist/server/rpc/handler-utils.d.ts +5 -0
  217. package/dist/server/rpc/handler-utils.js +22 -0
  218. package/dist/server/rpc/handlers/cancel-delegated.js +3 -5
  219. package/dist/server/rpc/handlers/cancelHandler.js +4 -5
  220. package/dist/server/rpc/handlers/completion-stream-delegated.js +14 -5
  221. package/dist/server/rpc/handlers/delete-cache.js +8 -3
  222. package/dist/server/rpc/handlers/download-asset.js +3 -24
  223. package/dist/server/rpc/handlers/get-loaded-model-info.d.ts +3 -0
  224. package/dist/server/rpc/handlers/get-loaded-model-info.js +39 -0
  225. package/dist/server/rpc/handlers/get-model-info.js +93 -84
  226. package/dist/server/rpc/handlers/heartbeat-delegated.js +2 -2
  227. package/dist/server/rpc/handlers/index.d.ts +6 -0
  228. package/dist/server/rpc/handlers/index.js +6 -0
  229. package/dist/server/rpc/handlers/load-model/download-manager.d.ts +35 -9
  230. package/dist/server/rpc/handlers/load-model/download-manager.js +142 -38
  231. package/dist/server/rpc/handlers/load-model/download-stats.d.ts +5 -4
  232. package/dist/server/rpc/handlers/load-model/download-stats.js +49 -8
  233. package/dist/server/rpc/handlers/load-model/handler.js +31 -50
  234. package/dist/server/rpc/handlers/load-model/http.d.ts +2 -2
  235. package/dist/server/rpc/handlers/load-model/http.js +97 -142
  236. package/dist/server/rpc/handlers/load-model/hyperdrive.d.ts +2 -2
  237. package/dist/server/rpc/handlers/load-model/hyperdrive.js +55 -74
  238. package/dist/server/rpc/handlers/load-model/index.d.ts +0 -1
  239. package/dist/server/rpc/handlers/load-model/index.js +0 -1
  240. package/dist/server/rpc/handlers/load-model/registry-client-options.d.ts +27 -0
  241. package/dist/server/rpc/handlers/load-model/registry-client-options.js +19 -0
  242. package/dist/server/rpc/handlers/load-model/registry-companion-set.d.ts +22 -0
  243. package/dist/server/rpc/handlers/load-model/registry-companion-set.js +208 -0
  244. package/dist/server/rpc/handlers/load-model/registry-download-utils.d.ts +24 -0
  245. package/dist/server/rpc/handlers/load-model/registry-download-utils.js +114 -0
  246. package/dist/server/rpc/handlers/load-model/registry.d.ts +2 -20
  247. package/dist/server/rpc/handlers/load-model/registry.js +109 -381
  248. package/dist/server/rpc/handlers/load-model/resolve-session.d.ts +15 -0
  249. package/dist/server/rpc/handlers/load-model/resolve-session.js +61 -0
  250. package/dist/server/rpc/handlers/load-model/resolve.d.ts +3 -3
  251. package/dist/server/rpc/handlers/load-model/resolve.js +14 -23
  252. package/dist/server/rpc/handlers/load-model/types.d.ts +11 -4
  253. package/dist/server/rpc/handlers/load-model/types.js +28 -1
  254. package/dist/server/rpc/handlers/load-model-delegated.js +2 -4
  255. package/dist/server/rpc/handlers/plugin-dispatch.js +9 -5
  256. package/dist/server/rpc/handlers/plugin-invoke.js +1 -1
  257. package/dist/server/rpc/handlers/provideHandler/connection.js +13 -2
  258. package/dist/server/rpc/handlers/provideHandler/handler.js +42 -29
  259. package/dist/server/rpc/handlers/state.d.ts +3 -0
  260. package/dist/server/rpc/handlers/state.js +7 -0
  261. package/dist/server/rpc/handlers/stopProvideHandler.d.ts +2 -2
  262. package/dist/server/rpc/handlers/stopProvideHandler.js +12 -7
  263. package/dist/server/rpc/handlers/text-to-speech-stream.d.ts +3 -0
  264. package/dist/server/rpc/handlers/text-to-speech-stream.js +4 -0
  265. package/dist/server/rpc/handlers/unload-model-delegated.js +3 -3
  266. package/dist/server/rpc/profiling/operation-metrics.js +20 -0
  267. package/dist/server/rpc/rpc-utils.js +1 -1
  268. package/dist/server/rpc/transport-selector.d.ts +3 -0
  269. package/dist/server/rpc/transport-selector.js +18 -0
  270. package/dist/server/utils/cache/auto-history.d.ts +4 -0
  271. package/dist/server/utils/cache/auto-history.js +22 -0
  272. package/dist/server/utils/{cache.d.ts → cache/paths.d.ts} +22 -5
  273. package/dist/server/utils/{cache.js → cache/paths.js} +36 -20
  274. package/dist/server/utils/cache/types.d.ts +8 -0
  275. package/dist/server/utils/cache/types.js +1 -0
  276. package/dist/server/utils/checksum.d.ts +2 -2
  277. package/dist/server/utils/checksum.js +1 -1
  278. package/dist/server/utils/clear-storage.d.ts +5 -0
  279. package/dist/server/utils/clear-storage.js +17 -0
  280. package/dist/server/utils/completion-normalizer.d.ts +17 -0
  281. package/dist/server/utils/completion-normalizer.js +301 -0
  282. package/dist/server/utils/expand-gguf-shards.d.ts +3 -0
  283. package/dist/server/utils/expand-gguf-shards.js +22 -0
  284. package/dist/server/utils/formatting.js +1 -1
  285. package/dist/server/utils/index.d.ts +4 -2
  286. package/dist/server/utils/index.js +4 -2
  287. package/dist/server/utils/qvac-paths.d.ts +2 -0
  288. package/dist/server/utils/qvac-paths.js +5 -0
  289. package/dist/server/utils/response-format.d.ts +3 -0
  290. package/dist/server/utils/response-format.js +20 -0
  291. package/dist/server/utils/tool-integration.d.ts +15 -4
  292. package/dist/server/utils/tool-integration.js +21 -41
  293. package/dist/server/utils/tools/dialect.d.ts +8 -0
  294. package/dist/server/utils/tools/dialect.js +12 -0
  295. package/dist/server/utils/tools/index.d.ts +3 -0
  296. package/dist/server/utils/tools/index.js +2 -0
  297. package/dist/server/utils/tools/parser.d.ts +6 -0
  298. package/dist/server/utils/tools/parser.js +40 -0
  299. package/dist/server/utils/tools/parsers/hermes.d.ts +4 -0
  300. package/dist/server/utils/tools/parsers/hermes.js +100 -0
  301. package/dist/server/utils/tools/parsers/json.d.ts +6 -0
  302. package/dist/server/utils/tools/parsers/json.js +115 -0
  303. package/dist/server/utils/tools/parsers/pythonic.d.ts +4 -0
  304. package/dist/server/utils/tools/parsers/pythonic.js +267 -0
  305. package/dist/server/utils/tools/shared.d.ts +18 -0
  306. package/dist/server/utils/tools/shared.js +54 -0
  307. package/dist/server/utils/worker-lock.d.ts +3 -0
  308. package/dist/server/utils/worker-lock.js +67 -0
  309. package/dist/server/worker-core.d.ts +16 -1
  310. package/dist/server/worker-core.js +114 -14
  311. package/dist/utils/aggregate-events.d.ts +16 -0
  312. package/dist/utils/aggregate-events.js +52 -0
  313. package/dist/utils/cache-normalize.d.ts +10 -0
  314. package/dist/utils/cache-normalize.js +23 -0
  315. package/dist/utils/encoding.d.ts +8 -0
  316. package/dist/utils/encoding.js +13 -0
  317. package/dist/utils/errors-client.d.ts +12 -0
  318. package/dist/utils/errors-client.js +20 -0
  319. package/dist/utils/errors-server.d.ts +14 -0
  320. package/dist/utils/errors-server.js +31 -0
  321. package/dist/utils/load-model-validation.d.ts +7 -0
  322. package/dist/utils/load-model-validation.js +18 -0
  323. package/expo/plugins/patches/android-link.mjs +1 -1
  324. package/expo/plugins/patches/ios-link.mjs +1 -1
  325. package/package.json +14 -18
  326. package/dist/examples/translation/translation-opus.d.ts +0 -2
  327. package/dist/examples/translation/translation-opus.js +0 -33
  328. package/dist/server/bare/utils/loader-adapter.d.ts +0 -7
  329. package/dist/server/bare/utils/loader-adapter.js +0 -9
  330. package/dist/server/utils/model-path.d.ts +0 -5
  331. package/dist/server/utils/model-path.js +0 -7
  332. package/dist/server/utils/tool-parser.d.ts +0 -7
  333. package/dist/server/utils/tool-parser.js +0 -248
@@ -1,7 +1,5 @@
1
1
  import { z } from "zod";
2
2
  import { modelSrcInputSchema } from "./model-src-utils.js";
3
- // Marian/Opus model languages
4
- export const MARIAN_LANGUAGES = ["en", "de", "es", "it", "ru", "ja"];
5
3
  // Bergamot supports many more language pairs
6
4
  export const BERGAMOT_LANGUAGES = [
7
5
  "en",
@@ -29,6 +27,39 @@ export const BERGAMOT_LANGUAGES = [
29
27
  "sl",
30
28
  "uk",
31
29
  "zh",
30
+ "az",
31
+ "be",
32
+ "bn",
33
+ "bs",
34
+ "da",
35
+ "el",
36
+ "fa",
37
+ "gu",
38
+ "he",
39
+ "hi",
40
+ "hr",
41
+ "id",
42
+ "kn",
43
+ "ml",
44
+ "ms",
45
+ "mt",
46
+ "nb",
47
+ "nn",
48
+ "re",
49
+ "ro",
50
+ "sq",
51
+ "sr",
52
+ "sv",
53
+ "ta",
54
+ "te",
55
+ "tr",
56
+ "vi",
57
+ ];
58
+ export const BERGAMOT_MODEL_RE = /^(.+\/)model\.([a-z]+)\.intgemm\.alphas\.bin$/;
59
+ export const BERGAMOT_CJK_LANG_PAIRS = [
60
+ "enja",
61
+ "enko",
62
+ "enzh",
32
63
  ];
33
64
  // IndicTrans2 model languages
34
65
  export const INDICTRANS_LANGUAGES = [
@@ -83,11 +114,10 @@ export const AFRICAN_LANGUAGES_MAP = new Map([
83
114
  ]);
84
115
  // Union of all NMT languages (for general type usage)
85
116
  export const NMT_LANGUAGES = [
86
- ...MARIAN_LANGUAGES,
87
117
  ...BERGAMOT_LANGUAGES,
88
118
  ...INDICTRANS_LANGUAGES,
89
119
  ];
90
- export const NMT_ENGINES = ["Opus", "Bergamot", "IndicTrans"];
120
+ export const NMT_ENGINES = ["Bergamot", "IndicTrans"];
91
121
  // Common generation parameters (without language fields)
92
122
  const nmtGenerationParamsSchema = z.object({
93
123
  mode: z.enum(["full"]).optional(),
@@ -100,12 +130,6 @@ const nmtGenerationParamsSchema = z.object({
100
130
  topk: z.number().optional(),
101
131
  topp: z.number().optional(),
102
132
  });
103
- // Opus engine config (Marian-based) - supports MARIAN_LANGUAGES
104
- const opusConfigSchema = nmtGenerationParamsSchema.extend({
105
- engine: z.literal("Opus"),
106
- from: z.enum(MARIAN_LANGUAGES),
107
- to: z.enum(MARIAN_LANGUAGES),
108
- });
109
133
  // Pivot model configuration for Bergamot (for translation via intermediate language)
110
134
  const bergamotPivotModelSchema = nmtGenerationParamsSchema
111
135
  .extend({
@@ -133,7 +157,6 @@ const indicTransConfigSchema = nmtGenerationParamsSchema.extend({
133
157
  });
134
158
  // Discriminated union of all engine configs
135
159
  export const nmtConfigBaseSchema = z.discriminatedUnion("engine", [
136
- opusConfigSchema,
137
160
  bergamotConfigSchema,
138
161
  indicTransConfigSchema,
139
162
  ]);
@@ -1,6 +1,6 @@
1
1
  import RPC from "bare-rpc";
2
2
  import type { RPCOptions } from "../../schemas/index";
3
- export declare function getRPC(topic: string, publicKey: string, options?: RPCOptions): Promise<RPC>;
3
+ export declare function getRPC(publicKey: string, options?: RPCOptions): Promise<RPC>;
4
4
  /**
5
5
  * Remove a stale RPC connection for a peer.
6
6
  * Called when a delegation request fails (e.g., timeout) so the next
@@ -7,12 +7,13 @@ import { nowMs } from "../../profiling/index.js";
7
7
  import { cacheDelegationConnectionTime, clearPeerConnectionTracking, } from "../rpc/profiling/delegation-profiler.js";
8
8
  import { getNextCommandId } from "../rpc/rpc-utils.js";
9
9
  const logger = getServerLogger();
10
- // Map of active RPC instances by public key
11
10
  const activeRPCs = new Map();
12
- // Map to store underlying connections for cleanup
13
11
  const activeConnections = new Map();
14
- // Track whether the global connection handler has been registered
15
- let connectionHandlerRegistered = false;
12
+ // In-flight `ensureRPCConnection` promises keyed by peer. Concurrent
13
+ // `getRPC(publicKey)` callers (without `forceNewConnection`) join the same
14
+ // promise instead of each running their own bootstrap+connect, which would
15
+ // open multiple sockets, clobber the active maps, and leak the loser.
16
+ const inflightConnections = new Map();
16
17
  const HEALTH_CHECK_TIMEOUT_MS = 1500;
17
18
  function isHeartbeatResponse(payload) {
18
19
  return (typeof payload === "object" &&
@@ -32,72 +33,92 @@ async function isRPCConnectionHealthy(rpc, timeout = HEALTH_CHECK_TIMEOUT_MS) {
32
33
  return false;
33
34
  }
34
35
  }
35
- /**
36
- * Register the swarm "connection" handler once (not per getRPC call).
37
- * This fixes the event listener leak where each getRPC() call added
38
- * a new listener, causing duplicate RPC instances on the same stream.
39
- */
40
- function ensureConnectionHandler() {
41
- if (connectionHandlerRegistered)
42
- return;
43
- connectionHandlerRegistered = true;
44
- const swarm = getSwarm();
45
- swarm.on("connection", (conn) => {
46
- const peerPubkey = conn.remotePublicKey?.toString("hex");
47
- if (!peerPubkey)
48
- return;
49
- logger.info(`🍺 New peer connection established: ${peerPubkey}`);
50
- // Create RPC instance for this connection (as client)
51
- const rpc = new RPC(conn, () => {
52
- // No-op handler since we're only sending requests, not receiving them
53
- });
54
- // Store RPC instance and connection by peer ID for lookup
55
- activeRPCs.set(peerPubkey, rpc);
56
- activeConnections.set(peerPubkey, conn);
57
- conn.on("close", () => {
58
- logger.debug(`Connection closed for peer: ${peerPubkey}`);
59
- activeRPCs.delete(peerPubkey);
60
- activeConnections.delete(peerPubkey);
61
- clearPeerConnectionTracking(peerPubkey);
62
- });
63
- conn.on("error", (err) => {
64
- logger.error(`Connection error for peer ${peerPubkey}:`, err);
65
- activeRPCs.delete(peerPubkey);
66
- activeConnections.delete(peerPubkey);
67
- clearPeerConnectionTracking(peerPubkey);
68
- });
36
+ function trackConnection(publicKey, conn, rpc) {
37
+ activeRPCs.set(publicKey, rpc);
38
+ activeConnections.set(publicKey, conn);
39
+ conn.on("close", () => {
40
+ logger.debug(`Connection closed for peer: ${publicKey}`);
41
+ if (activeConnections.get(publicKey) === conn) {
42
+ activeConnections.delete(publicKey);
43
+ activeRPCs.delete(publicKey);
44
+ clearPeerConnectionTracking(publicKey);
45
+ }
46
+ });
47
+ conn.on("error", (err) => {
48
+ logger.error(`Connection error for peer ${publicKey}:`, err);
49
+ if (activeConnections.get(publicKey) === conn) {
50
+ activeConnections.delete(publicKey);
51
+ activeRPCs.delete(publicKey);
52
+ clearPeerConnectionTracking(publicKey);
53
+ }
69
54
  });
70
55
  }
71
56
  async function closeConnection(publicKey) {
72
57
  const existingConnection = activeConnections.get(publicKey);
73
- if (existingConnection) {
74
- logger.info(`🔌 Closing existing connection for peer: ${publicKey}`);
75
- // Wait for the close event before returning so Hyperswarm's internal
76
- // _allConnections is cleaned up before we attempt to rejoin/flush.
77
- await new Promise((resolve) => {
78
- existingConnection.on("close", () => {
79
- resolve();
80
- });
81
- existingConnection.destroy();
82
- });
83
- if (activeConnections.get(publicKey) !== existingConnection)
84
- return;
58
+ if (!existingConnection)
59
+ return;
60
+ logger.info(`🔌 Closing existing connection for peer: ${publicKey}`);
61
+ // Wait for the close event before returning so any pending cleanup
62
+ // in the underlying DHT stream completes before we reconnect.
63
+ await new Promise((resolve) => {
64
+ existingConnection.once("close", () => resolve());
65
+ existingConnection.destroy();
66
+ });
67
+ if (activeConnections.get(publicKey) === existingConnection) {
85
68
  activeConnections.delete(publicKey);
86
69
  activeRPCs.delete(publicKey);
87
70
  clearPeerConnectionTracking(publicKey);
88
71
  }
89
72
  }
90
- // Establish RPC connection to a peer if not already connected
91
- async function ensureRPCConnection(topic, publicKey, timeout, healthCheckTimeout) {
73
+ // Open a direct DHT connection to a peer by public key. Bypasses topic
74
+ // discovery entirely — we already know who we're talking to, so we skip
75
+ // swarm.join()/flush() and let the DHT route by public key.
76
+ function openDhtConnection(publicKey) {
77
+ const swarm = getSwarm();
78
+ const relayThrough = swarm.relayThrough
79
+ ? swarm.relayThrough(false, swarm)
80
+ : null;
81
+ return swarm.dht.connect(Buffer.from(publicKey, "hex"), {
82
+ keyPair: swarm.keyPair,
83
+ relayThrough,
84
+ });
85
+ }
86
+ // Resolve when the DHT connection emits "open"; reject promptly on "error"
87
+ // or "close" so firewall-rejected / abruptly-closed connects fail fast
88
+ // instead of dragging out the full delegate timeout (60s on cold paths).
89
+ function waitForOpen(conn, timeout) {
90
+ const opened = new Promise((resolve, reject) => {
91
+ const cleanup = () => {
92
+ conn.removeListener("open", onOpen);
93
+ conn.removeListener("error", onError);
94
+ conn.removeListener("close", onClose);
95
+ };
96
+ const onOpen = () => {
97
+ cleanup();
98
+ resolve();
99
+ };
100
+ const onError = (err) => {
101
+ cleanup();
102
+ reject(err);
103
+ };
104
+ const onClose = () => {
105
+ cleanup();
106
+ reject(new DelegateConnectionFailedError("Connection closed before open (peer unreachable or rejected by firewall)"));
107
+ };
108
+ conn.once("open", onOpen);
109
+ conn.once("error", onError);
110
+ conn.once("close", onClose);
111
+ });
112
+ return withTimeout(opened, timeout);
113
+ }
114
+ async function ensureRPCConnection(publicKey, timeout, healthCheckTimeout) {
92
115
  const healthCheckCap = healthCheckTimeout ?? HEALTH_CHECK_TIMEOUT_MS;
93
116
  const operationStart = nowMs();
94
117
  const getRemainingTimeout = () => {
95
- if (timeout === undefined) {
118
+ if (timeout === undefined)
96
119
  return undefined;
97
- }
98
120
  return Math.max(timeout - (nowMs() - operationStart), 0);
99
121
  };
100
- // Check if we already have an RPC instance for this peer
101
122
  const existingRpc = activeRPCs.get(publicKey);
102
123
  if (existingRpc) {
103
124
  const remainingTimeout = getRemainingTimeout();
@@ -111,89 +132,77 @@ async function ensureRPCConnection(topic, publicKey, timeout, healthCheckTimeout
111
132
  logger.info(`🧹 Cached RPC failed health check for peer ${publicKey}, reconnecting`);
112
133
  cleanupStaleConnection(publicKey);
113
134
  }
114
- const swarm = getSwarm();
115
135
  const connectionStart = nowMs();
116
- // Track the listener so we can clean it up on timeout
117
- let onConnection = () => { };
136
+ let conn;
118
137
  try {
119
- logger.info(`🔗 Establishing RPC connection to topic: ${topic}, peer: ${publicKey}, timeout: ${timeout}ms`);
120
- const connectionPromise = new Promise((resolve, reject) => {
121
- const topicBuffer = Buffer.from(topic, "hex");
122
- swarm.join(topicBuffer, {
123
- server: false,
124
- client: true,
125
- });
126
- // Wait for the specific peer's connection event instead of just
127
- // checking after flush. This handles the case where flush resolves
128
- // (discovery done) but the P2P connection is still being established
129
- // via holepunching or relays.
130
- onConnection = (conn) => {
131
- const peerPubkey = conn.remotePublicKey?.toString("hex");
132
- if (peerPubkey === publicKey) {
133
- swarm.removeListener("connection", onConnection);
134
- // The global handler (ensureConnectionHandler) will create the RPC
135
- // and store it in activeRPCs. Give it a tick to run first.
136
- const rpc = activeRPCs.get(publicKey);
137
- if (rpc) {
138
- resolve(rpc);
139
- }
140
- else {
141
- // Global handler runs synchronously before us in the same event,
142
- // so this shouldn't happen, but handle it just in case
143
- setTimeout(() => {
144
- const delayedRpc = activeRPCs.get(publicKey);
145
- if (delayedRpc) {
146
- resolve(delayedRpc);
147
- }
148
- else {
149
- reject(new DelegateConnectionFailedError(`Connection established but RPC not created for peer ${publicKey}`));
150
- }
151
- }, 100);
152
- }
153
- }
154
- };
155
- swarm.on("connection", onConnection);
156
- // Also flush to trigger discovery. After flush, check if the connection
157
- // was already established (the global handler may have caught it).
158
- void swarm.flush().then(() => {
159
- logger.info(`✅ Flush completed for topic: ${topic}`);
160
- logger.debug(`📊 Active RPC connections: ${activeRPCs.size}`);
161
- const rpc = activeRPCs.get(publicKey);
162
- if (rpc) {
163
- swarm.removeListener("connection", onConnection);
164
- resolve(rpc);
165
- }
166
- // If not connected after flush, the onConnection listener keeps
167
- // waiting until the timeout from withTimeout kicks in.
168
- // Hyperswarm may still establish the connection via retries/relays.
169
- logger.debug(`⏳ Peer not connected after flush, waiting for connection event...`);
170
- });
138
+ logger.info(`🔗 Establishing direct DHT connection to peer: ${publicKey}${timeout ? `, timeout: ${timeout}ms` : ""}`);
139
+ // Ensure the DHT routing table is populated before attempting to look up
140
+ // the peer. On a cold swarm the table is nearly empty and findPeer can
141
+ // return PEER_NOT_FOUND immediately even when the provider is reachable.
142
+ const bootstrapStart = nowMs();
143
+ const swarm = getSwarm();
144
+ logger.info(`⏳ Waiting for DHT to fully bootstrap before connect...`);
145
+ await withTimeout(swarm.dht.fullyBootstrapped(), getRemainingTimeout());
146
+ logger.info(`✅ DHT bootstrapped in ${(nowMs() - bootstrapStart).toFixed(0)}ms`);
147
+ conn = openDhtConnection(publicKey);
148
+ await waitForOpen(conn, getRemainingTimeout());
149
+ logger.info(`🍺 Peer connection opened: ${publicKey}`);
150
+ const rpc = new RPC(conn, () => {
151
+ // No-op handler since we're only sending requests, not receiving them
171
152
  });
172
- const rpc = await withTimeout(connectionPromise, getRemainingTimeout());
153
+ trackConnection(publicKey, conn, rpc);
173
154
  const connectionDuration = nowMs() - connectionStart;
174
155
  cacheDelegationConnectionTime(publicKey, connectionDuration);
175
156
  return rpc;
176
157
  }
177
158
  catch (error) {
178
- // Clean up the per-request connection listener
179
- swarm.removeListener("connection", onConnection);
180
- // Remove stale connection so next attempt creates a fresh one
181
- // instead of reusing a dead RPC
159
+ if (conn && !conn.destroyed) {
160
+ conn.destroy();
161
+ }
182
162
  cleanupStaleConnection(publicKey);
183
163
  logger.error("Failed to establish RPC connection:", error);
184
164
  throw new DelegateConnectionFailedError(`RPC connection failed: ${error instanceof Error ? error.message : String(error)}`, error);
185
165
  }
186
166
  }
187
- // Create an RPC instance for a specific HyperSwarm peer
188
- export async function getRPC(topic, publicKey, options = {}) {
189
- // Ensure the global connection handler is registered (once)
190
- ensureConnectionHandler();
191
- // Close existing connection if forceNewConnection is true
192
- // Await the close to avoid racing with the subsequent join/flush
167
+ // Create an RPC instance for a specific HyperSwarm peer.
168
+ // Connects directly via the DHT using the peer's public key — no topic
169
+ // discovery required.
170
+ //
171
+ // Concurrent calls for the same peer share a single in-flight bootstrap +
172
+ // connect operation, but each caller still gets its own `timeout` enforced
173
+ // against the shared promise (via `withTimeout`) — so a fast caller that
174
+ // gives up at 5s does not block a slow caller waiting up to 60s.
175
+ //
176
+ // `forceNewConnection` always tears down the existing socket first and
177
+ // starts a fresh attempt outside the shared promise.
178
+ export async function getRPC(publicKey, options = {}) {
193
179
  if (options.forceNewConnection) {
194
180
  await closeConnection(publicKey);
181
+ return await ensureRPCConnection(publicKey, options.timeout, options.healthCheckTimeout);
182
+ }
183
+ let inflight = inflightConnections.get(publicKey);
184
+ if (!inflight) {
185
+ inflight = ensureRPCConnection(publicKey, options.timeout, options.healthCheckTimeout);
186
+ const tracked = inflight;
187
+ inflightConnections.set(publicKey, tracked);
188
+ // Clear the inflight entry on settle. We register a single combined
189
+ // settle handler via `then(handler, handler)` so that on rejection the
190
+ // failure is *observed* on `tracked` itself — using `tracked.finally(...)`
191
+ // returns a fresh promise that re-rejects with the original error, and
192
+ // since nothing awaits that fresh promise it would surface as an
193
+ // unhandled rejection. The worker treats unhandled rejections as fatal
194
+ // and tears down the swarm + cancels all in-flight downloads, which then
195
+ // breaks the legitimate fallback-to-local path that the caller awaits via
196
+ // `withTimeout(inflight, ...)` below. Caller still observes the original
197
+ // rejection through `await withTimeout(inflight, ...)`.
198
+ const clearInflight = () => {
199
+ if (inflightConnections.get(publicKey) === tracked) {
200
+ inflightConnections.delete(publicKey);
201
+ }
202
+ };
203
+ tracked.then(clearInflight, clearInflight);
195
204
  }
196
- return await ensureRPCConnection(topic, publicKey, options.timeout, options.healthCheckTimeout);
205
+ return await withTimeout(inflight, options.timeout);
197
206
  }
198
207
  /**
199
208
  * Remove a stale RPC connection for a peer.
@@ -3,8 +3,8 @@ import { type FirewallConfig } from "../../schemas/provide";
3
3
  export declare function getSwarm({ firewallConfig, }?: {
4
4
  firewallConfig?: FirewallConfig | undefined;
5
5
  }): Hyperswarm;
6
- export declare function registerProviderTopic(topic: string): void;
7
- export declare function unregisterProviderTopic(topic: string): void;
6
+ export declare function registerProvider(): void;
7
+ export declare function unregisterProvider(): void;
8
8
  export declare function hasActiveProviders(): boolean;
9
9
  export declare function destroySwarm(): Promise<void>;
10
10
  //# sourceMappingURL=hyperswarm.d.ts.map
@@ -61,7 +61,11 @@ function createSwarm(firewallConfig) {
61
61
  return new Hyperswarm(swarmOptions);
62
62
  }
63
63
  let swarm = null;
64
- const activeProviderTopics = new Set();
64
+ // Delegation is always 1:1 (single provider service per SDK instance), but we
65
+ // still use a counter to be resilient against duplicate provide/stopProvide
66
+ // calls and to avoid ever reporting "no active providers" while one is still
67
+ // running.
68
+ let activeProviderCount = 0;
65
69
  export function getSwarm({ firewallConfig, } = {}) {
66
70
  if (swarm) {
67
71
  return swarm;
@@ -70,14 +74,15 @@ export function getSwarm({ firewallConfig, } = {}) {
70
74
  registerSwarm(swarm, { label: "shared-swarm", createdAt: Date.now() });
71
75
  return swarm;
72
76
  }
73
- export function registerProviderTopic(topic) {
74
- activeProviderTopics.add(topic);
77
+ export function registerProvider() {
78
+ activeProviderCount++;
75
79
  }
76
- export function unregisterProviderTopic(topic) {
77
- activeProviderTopics.delete(topic);
80
+ export function unregisterProvider() {
81
+ if (activeProviderCount > 0)
82
+ activeProviderCount--;
78
83
  }
79
84
  export function hasActiveProviders() {
80
- return activeProviderTopics.size > 0;
85
+ return activeProviderCount > 0;
81
86
  }
82
87
  export async function destroySwarm() {
83
88
  if (!swarm)
@@ -87,7 +92,7 @@ export async function destroySwarm() {
87
92
  try {
88
93
  await ref.destroy();
89
94
  unregisterSwarm(ref);
90
- activeProviderTopics.clear();
95
+ activeProviderCount = 0;
91
96
  }
92
97
  catch (error) {
93
98
  if (swarm === null)
@@ -1,12 +1,19 @@
1
1
  import { getModel } from "../registry/model-registry.js";
2
2
  import { cancelInferenceBaseSchema, } from "../../../schemas/index.js";
3
3
  import { ModelNotLoadedError } from "../../../utils/errors-server.js";
4
+ import { noteCancelRequested } from "../plugins/llamacpp-completion/ops/kv-cache-state.js";
4
5
  export async function cancel(params) {
5
6
  const { modelId } = cancelInferenceBaseSchema.parse(params);
6
7
  const model = getModel(modelId);
7
8
  if (!model) {
8
9
  throw new ModelNotLoadedError(modelId);
9
10
  }
11
+ // Must be recorded *before* `addon.cancel()` so the in-flight
12
+ // `completion()` for this model sees the bumped counter when it
13
+ // snapshots after `processModelResponse` returns. This is the signal
14
+ // that tells `completion()` not to record a `savedCount` for the
15
+ // kv-cache on a cancelled turn.
16
+ noteCancelRequested(modelId);
10
17
  if (model.addon && model.addon.cancel) {
11
18
  await model.addon.cancel();
12
19
  }
@@ -1,13 +1,10 @@
1
+ import { type CacheMessage } from "../../utils/index";
1
2
  export declare function markCacheInitialized(modelId: string, configHash: string, cacheKey: string): void;
2
3
  export declare function isCacheInitialized(modelId: string, configHash: string, cacheKey: string): boolean;
3
- export declare function clearCacheRegistry(cacheKey?: string): void;
4
- export interface CacheMessage {
5
- role: string;
6
- content: string;
7
- attachments?: {
8
- path: string;
9
- }[] | undefined;
10
- }
4
+ export declare function clearCacheRegistry(scope?: {
5
+ cacheKey?: string | undefined;
6
+ modelId?: string | undefined;
7
+ }): void;
11
8
  export declare function extractSystemPrompt(messages: CacheMessage[]): string | null;
12
9
  export declare function generateConfigHash(systemPrompt: string | null, tools?: unknown): string;
13
10
  export declare function generateCacheKey(messages: CacheMessage[]): string;
@@ -20,12 +17,12 @@ export declare function getCurrentCacheInfo(modelId: string, configHash: string,
20
17
  cacheKey: string;
21
18
  cachePath: string;
22
19
  }>;
23
- export declare function renameCacheFile(oldPath: string, newPath: string): Promise<void>;
20
+ export declare function renameCacheFile(oldPath: string, newPath: string): Promise<boolean>;
24
21
  export declare function customCacheExists(modelId: string, configHash: string, cacheKey: string): Promise<boolean>;
25
22
  export declare function deleteCache(options: {
26
23
  all: true;
27
24
  } | {
28
25
  kvCacheKey: string;
29
26
  modelId?: string;
30
- }): Promise<void>;
27
+ }): Promise<string>;
31
28
  //# sourceMappingURL=kv-cache-utils.d.ts.map
@@ -1,7 +1,7 @@
1
1
  import crypto from "bare-crypto";
2
2
  import { promises as fsPromises } from "bare-fs";
3
3
  import path from "bare-path";
4
- import { getKVCacheDir, validateAndJoinPath } from "../../utils/index.js";
4
+ import { getAutoCacheLookupHistory, getKVCacheDir, validateAndJoinPath, } from "../../utils/index.js";
5
5
  import { getServerLogger } from "../../../logging/index.js";
6
6
  const logger = getServerLogger();
7
7
  // In-memory registry tracks caches initialized this session (addon defers disk writes)
@@ -15,16 +15,24 @@ export function markCacheInitialized(modelId, configHash, cacheKey) {
15
15
  export function isCacheInitialized(modelId, configHash, cacheKey) {
16
16
  return initializedCaches.has(getCacheRegistryKey(modelId, configHash, cacheKey));
17
17
  }
18
- export function clearCacheRegistry(cacheKey) {
19
- if (cacheKey) {
20
- for (const key of initializedCaches) {
21
- if (key.includes(`:${cacheKey}`)) {
22
- initializedCaches.delete(key);
23
- }
24
- }
25
- }
26
- else {
18
+ export function clearCacheRegistry(scope) {
19
+ if (!scope || (scope.cacheKey === undefined && scope.modelId === undefined)) {
27
20
  initializedCaches.clear();
21
+ return;
22
+ }
23
+ // key format: "modelId:configHash:cacheKey"
24
+ for (const key of initializedCaches) {
25
+ const firstSep = key.indexOf(":");
26
+ const secondSep = key.indexOf(":", firstSep + 1);
27
+ if (firstSep === -1 || secondSep === -1)
28
+ continue;
29
+ const modelId = key.slice(0, firstSep);
30
+ const cacheKey = key.slice(secondSep + 1);
31
+ if (scope.cacheKey !== undefined && cacheKey !== scope.cacheKey)
32
+ continue;
33
+ if (scope.modelId !== undefined && modelId !== scope.modelId)
34
+ continue;
35
+ initializedCaches.delete(key);
28
36
  }
29
37
  }
30
38
  export function extractSystemPrompt(messages) {
@@ -73,8 +81,7 @@ export async function findMatchingCache(modelId, configHash, currentHistory) {
73
81
  if (currentHistory.length <= 1) {
74
82
  return null;
75
83
  }
76
- // Generate cache key for history minus the last message
77
- const previousHistory = currentHistory.slice(0, -1);
84
+ const previousHistory = getAutoCacheLookupHistory(currentHistory);
78
85
  const cacheKey = generateCacheKey(previousHistory);
79
86
  const cachePath = await getCacheFilePath(modelId, configHash, cacheKey);
80
87
  try {
@@ -93,9 +100,11 @@ export async function getCurrentCacheInfo(modelId, configHash, currentHistory) {
93
100
  export async function renameCacheFile(oldPath, newPath) {
94
101
  try {
95
102
  await fsPromises.rename(oldPath, newPath);
103
+ return true;
96
104
  }
97
105
  catch (error) {
98
106
  logger.error("Error renaming cache file:", error instanceof Error ? error.message : String(error));
107
+ return false;
99
108
  }
100
109
  }
101
110
  export async function customCacheExists(modelId, configHash, cacheKey) {
@@ -116,33 +125,15 @@ export async function customCacheExists(modelId, configHash, cacheKey) {
116
125
  }
117
126
  export async function deleteCache(options) {
118
127
  const cacheDir = getKVCacheDir();
119
- if ("all" in options && options.all) {
120
- try {
121
- await fsPromises.rm(cacheDir, { recursive: true });
122
- await fsPromises.mkdir(cacheDir, { recursive: true });
123
- }
124
- catch (error) {
125
- logger.error("Error deleting all caches:", error instanceof Error ? error.message : String(error));
126
- }
127
- }
128
- else if ("kvCacheKey" in options) {
129
- const kvCacheDir = validateAndJoinPath(cacheDir, options.kvCacheKey);
130
- if (options.modelId) {
131
- const modelCacheDir = validateAndJoinPath(kvCacheDir, options.modelId);
132
- try {
133
- await fsPromises.rm(modelCacheDir, { recursive: true });
134
- }
135
- catch (error) {
136
- logger.error(`Error deleting model cache ${options.kvCacheKey}/${options.modelId}:`, error instanceof Error ? error.message : String(error));
137
- }
138
- }
139
- else {
140
- try {
141
- await fsPromises.rm(kvCacheDir, { recursive: true });
142
- }
143
- catch (error) {
144
- logger.error(`Error deleting cache ${options.kvCacheKey}:`, error instanceof Error ? error.message : String(error));
145
- }
146
- }
128
+ if ("all" in options) {
129
+ await fsPromises.rm(cacheDir, { recursive: true, force: true });
130
+ await fsPromises.mkdir(cacheDir, { recursive: true });
131
+ return cacheDir;
147
132
  }
133
+ const kvCacheDir = validateAndJoinPath(cacheDir, options.kvCacheKey);
134
+ const targetDir = options.modelId !== undefined
135
+ ? validateAndJoinPath(kvCacheDir, options.modelId)
136
+ : kvCacheDir;
137
+ await fsPromises.rm(targetDir, { recursive: true, force: true });
138
+ return targetDir;
148
139
  }
@@ -73,7 +73,6 @@ export async function loadModel(params, options) {
73
73
  config: modelConfig,
74
74
  modelType: modelType,
75
75
  name: modelName,
76
- loader: result.loader,
77
76
  });
78
77
  return modelInitializationTimeMs !== undefined
79
78
  ? { timing: { modelInitializationTimeMs } }
@@ -1,7 +1,14 @@
1
- import { type TranscribeParams, type TranscribeStats } from "../../../schemas/index";
2
- export declare function transcribe(params: TranscribeParams): AsyncGenerator<string, {
1
+ import { type TranscribeParams, type TranscribeSegment, type TranscribeStats } from "../../../schemas/index";
2
+ import { assertMetadataSupported, toTranscribeSegment, type WhisperAddonSegment } from "../utils/transcribe-metadata";
3
+ export { assertMetadataSupported, toTranscribeSegment, type WhisperAddonSegment, };
4
+ type TranscribeReturn = {
3
5
  modelExecutionMs: number;
4
6
  stats?: TranscribeStats;
5
- }, void>;
6
- export declare function transcribeStream(modelId: string, audioInputStream: AsyncIterable<Buffer>, prompt?: string): AsyncGenerator<string, void, void>;
7
+ };
8
+ export declare function transcribe(params: TranscribeParams & {
9
+ metadata: true;
10
+ }): AsyncGenerator<TranscribeSegment, TranscribeReturn, void>;
11
+ export declare function transcribe(params: TranscribeParams): AsyncGenerator<string, TranscribeReturn, void>;
12
+ export declare function transcribeStream(modelId: string, audioInputStream: AsyncIterable<Buffer>, prompt: string | undefined, metadata: true): AsyncGenerator<TranscribeSegment, void, void>;
13
+ export declare function transcribeStream(modelId: string, audioInputStream: AsyncIterable<Buffer>, prompt?: string, metadata?: boolean): AsyncGenerator<string, void, void>;
7
14
  //# sourceMappingURL=transcribe.d.ts.map