@qvac/sdk 0.10.2 → 0.12.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 (326) hide show
  1. package/NOTICE +1455 -29
  2. package/README.md +2 -0
  3. package/dist/client/api/cancel.d.ts +24 -32
  4. package/dist/client/api/cancel.js +58 -31
  5. package/dist/client/api/classify.d.ts +23 -0
  6. package/dist/client/api/classify.js +43 -0
  7. package/dist/client/api/client-request-id.d.ts +17 -0
  8. package/dist/client/api/client-request-id.js +27 -0
  9. package/dist/client/api/completion-stream.d.ts +1 -1
  10. package/dist/client/api/completion-stream.js +34 -3
  11. package/dist/client/api/diffusion.d.ts +46 -0
  12. package/dist/client/api/diffusion.js +50 -1
  13. package/dist/client/api/download-asset.d.ts +12 -2
  14. package/dist/client/api/download-asset.js +21 -3
  15. package/dist/client/api/embed.d.ts +8 -4
  16. package/dist/client/api/embed.js +14 -1
  17. package/dist/client/api/get-model-info.d.ts +1 -1
  18. package/dist/client/api/index.d.ts +5 -0
  19. package/dist/client/api/index.js +5 -0
  20. package/dist/client/api/load-model.d.ts +12 -4
  21. package/dist/client/api/load-model.js +49 -2
  22. package/dist/client/api/rag.d.ts +9 -3
  23. package/dist/client/api/rag.js +23 -3
  24. package/dist/client/api/transcribe.d.ts +23 -8
  25. package/dist/client/api/transcribe.js +69 -4
  26. package/dist/client/api/unload-model.d.ts +5 -2
  27. package/dist/client/api/unload-model.js +9 -4
  28. package/dist/client/api/upscale.d.ts +45 -0
  29. package/dist/client/api/upscale.js +99 -0
  30. package/dist/client/api/video.d.ts +64 -0
  31. package/dist/client/api/video.js +147 -0
  32. package/dist/client/api/vla-helpers.d.ts +45 -0
  33. package/dist/client/api/vla-helpers.js +130 -0
  34. package/dist/client/api/vla.d.ts +65 -0
  35. package/dist/client/api/vla.js +109 -0
  36. package/dist/client/config-loader/resolve-config.node.d.ts +16 -0
  37. package/dist/client/config-loader/resolve-config.node.js +77 -23
  38. package/dist/client/plugins-factory.d.ts +8 -0
  39. package/dist/client/plugins-factory.js +10 -0
  40. package/dist/client/rpc/bare-client.js +62 -66
  41. package/dist/client/rpc/ensure-worker-ready.d.ts +9 -0
  42. package/dist/client/rpc/ensure-worker-ready.js +17 -0
  43. package/dist/client/rpc/expo-rpc-client.js +2 -1
  44. package/dist/client/rpc/node-rpc-client.js +22 -8
  45. package/dist/client/rpc/rpc-client.d.ts +2 -2
  46. package/dist/client/rpc/rpc-client.js +10 -4
  47. package/dist/client/rpc/rpc-error.d.ts +9 -0
  48. package/dist/client/rpc/rpc-error.js +105 -0
  49. package/dist/commands/bundle/bare-pack.d.ts +13 -0
  50. package/dist/commands/bundle/bare-pack.js +54 -0
  51. package/dist/commands/bundle/constants.d.ts +7 -0
  52. package/dist/commands/bundle/constants.js +23 -0
  53. package/dist/commands/bundle/entry-gen.d.ts +2 -0
  54. package/dist/commands/bundle/entry-gen.js +48 -0
  55. package/dist/commands/bundle/index.d.ts +20 -0
  56. package/dist/commands/bundle/index.js +141 -0
  57. package/dist/commands/bundle/manifest.d.ts +21 -0
  58. package/dist/commands/bundle/manifest.js +193 -0
  59. package/dist/commands/bundle/plugins.d.ts +9 -0
  60. package/dist/commands/bundle/plugins.js +51 -0
  61. package/dist/commands/index.d.ts +5 -0
  62. package/dist/commands/index.js +2 -0
  63. package/dist/commands/verify/abi.d.ts +52 -0
  64. package/dist/commands/verify/abi.js +125 -0
  65. package/dist/commands/verify/addon-source.d.ts +43 -0
  66. package/dist/commands/verify/addon-source.js +75 -0
  67. package/dist/commands/verify/bundle-source.d.ts +12 -0
  68. package/dist/commands/verify/bundle-source.js +53 -0
  69. package/dist/commands/verify/index.d.ts +59 -0
  70. package/dist/commands/verify/index.js +371 -0
  71. package/dist/commands/verify/node-modules-source.d.ts +11 -0
  72. package/dist/commands/verify/node-modules-source.js +76 -0
  73. package/dist/commands/verify/prebuilds.d.ts +15 -0
  74. package/dist/commands/verify/prebuilds.js +39 -0
  75. package/dist/examples/cancel-by-request-id.d.ts +38 -0
  76. package/dist/examples/cancel-by-request-id.js +103 -0
  77. package/dist/examples/classification/classify-image.d.ts +2 -0
  78. package/dist/examples/classification/classify-image.js +23 -0
  79. package/dist/examples/diffusion-esrgan-upscale.d.ts +2 -0
  80. package/dist/examples/diffusion-esrgan-upscale.js +78 -0
  81. package/dist/examples/diffusion-txt2vid.d.ts +2 -0
  82. package/dist/examples/diffusion-txt2vid.js +81 -0
  83. package/dist/examples/download-with-cancel.js +10 -10
  84. package/dist/examples/embed-multi-gpu.d.ts +2 -0
  85. package/dist/examples/embed-multi-gpu.js +46 -0
  86. package/dist/examples/llamacpp-multi-gpu.d.ts +2 -0
  87. package/dist/examples/llamacpp-multi-gpu.js +57 -0
  88. package/dist/examples/plugins.js +3 -7
  89. package/dist/examples/rag/rag-hyperdb/cancellation.js +20 -17
  90. package/dist/examples/tools/llamacpp-tools-gemma4.d.ts +2 -0
  91. package/dist/examples/tools/llamacpp-tools-gemma4.js +73 -0
  92. package/dist/examples/tools/llamacpp-tools-qwen35.d.ts +2 -0
  93. package/dist/examples/tools/llamacpp-tools-qwen35.js +69 -0
  94. package/dist/examples/transcription/parakeet-ctc-filesystem.js +18 -12
  95. package/dist/examples/transcription/parakeet-microphone-record.js +7 -12
  96. package/dist/examples/transcription/parakeet-microphone-stream.d.ts +2 -0
  97. package/dist/examples/transcription/parakeet-microphone-stream.js +79 -0
  98. package/dist/examples/transcription/parakeet-sortformer-streaming.d.ts +2 -0
  99. package/dist/examples/transcription/parakeet-sortformer-streaming.js +121 -0
  100. package/dist/examples/transcription/parakeet-sortformer.js +58 -55
  101. package/dist/examples/transcription/parakeet-tdt-filesystem.js +18 -15
  102. package/dist/examples/transcription/whispercpp-microphone-conversation.d.ts +2 -0
  103. package/dist/examples/transcription/whispercpp-microphone-conversation.js +107 -0
  104. package/dist/examples/tts/chatterbox.js +7 -16
  105. package/dist/examples/tts/llm-to-tts-streaming.js +3 -10
  106. package/dist/examples/tts/supertonic-multilingual.js +4 -12
  107. package/dist/examples/tts/supertonic.js +5 -12
  108. package/dist/examples/vla-smolvla.d.ts +2 -0
  109. package/dist/examples/vla-smolvla.js +75 -0
  110. package/dist/examples/voice-assistant/voice-assistant.js +3 -10
  111. package/dist/expo/plugins/find-in-ancestor-node-modules.d.ts +14 -0
  112. package/dist/expo/plugins/find-in-ancestor-node-modules.js +24 -0
  113. package/dist/expo/plugins/get-project-root.d.ts +22 -0
  114. package/dist/expo/plugins/get-project-root.js +23 -0
  115. package/dist/expo/plugins/index.d.ts +4 -0
  116. package/dist/expo/plugins/index.js +4 -0
  117. package/dist/expo/plugins/resolve-sdk-package-dir.d.ts +9 -2
  118. package/dist/expo/plugins/resolve-sdk-package-dir.js +38 -11
  119. package/dist/expo/plugins/withDeviceInfo.js +2 -1
  120. package/dist/expo/plugins/withMobileBundle.d.ts +5 -4
  121. package/dist/expo/plugins/withMobileBundle.js +42 -58
  122. package/dist/index.d.ts +6 -2
  123. package/dist/index.js +23 -2
  124. package/dist/models/registry/models.d.ts +3725 -514
  125. package/dist/models/registry/models.js +7269 -3910
  126. package/dist/models/update-models/naming.js +22 -8
  127. package/dist/pear/pre.d.ts +3 -0
  128. package/dist/pear/pre.js +9 -2
  129. package/dist/schemas/cancel.d.ts +172 -28
  130. package/dist/schemas/cancel.js +120 -19
  131. package/dist/schemas/classification.d.ts +53 -0
  132. package/dist/schemas/classification.js +33 -0
  133. package/dist/schemas/common.d.ts +860 -1379
  134. package/dist/schemas/common.js +8 -1
  135. package/dist/schemas/completion-event.d.ts +17 -0
  136. package/dist/schemas/completion-event.js +12 -1
  137. package/dist/schemas/completion-stream.d.ts +16 -1
  138. package/dist/schemas/completion-stream.js +25 -7
  139. package/dist/schemas/download-asset.d.ts +25 -9
  140. package/dist/schemas/download-asset.js +17 -6
  141. package/dist/schemas/embed.d.ts +1 -0
  142. package/dist/schemas/embed.js +5 -0
  143. package/dist/schemas/engine-addon-map.d.ts +3 -0
  144. package/dist/schemas/engine-addon-map.js +18 -5
  145. package/dist/schemas/error.d.ts +31 -0
  146. package/dist/schemas/error.js +29 -1
  147. package/dist/schemas/finetune.d.ts +2 -0
  148. package/dist/schemas/finetune.js +5 -0
  149. package/dist/schemas/get-model-info.d.ts +10 -6
  150. package/dist/schemas/get-model-info.js +2 -0
  151. package/dist/schemas/index.d.ts +3 -0
  152. package/dist/schemas/index.js +3 -0
  153. package/dist/schemas/llamacpp-config.d.ts +64 -8
  154. package/dist/schemas/llamacpp-config.js +12 -0
  155. package/dist/schemas/load-model.d.ts +4644 -8605
  156. package/dist/schemas/load-model.js +90 -7
  157. package/dist/schemas/model-src-utils.d.ts +34 -14
  158. package/dist/schemas/model-types.d.ts +54 -14
  159. package/dist/schemas/model-types.js +28 -5
  160. package/dist/schemas/ocr.d.ts +8 -3
  161. package/dist/schemas/plugin.d.ts +60 -6
  162. package/dist/schemas/plugin.js +31 -5
  163. package/dist/schemas/rag.d.ts +9 -0
  164. package/dist/schemas/rag.js +17 -9
  165. package/dist/schemas/registry.d.ts +74 -30
  166. package/dist/schemas/registry.js +5 -0
  167. package/dist/schemas/reload-config.d.ts +34 -14
  168. package/dist/schemas/sdcpp-config.d.ts +445 -16
  169. package/dist/schemas/sdcpp-config.js +387 -26
  170. package/dist/schemas/sdk-config.d.ts +2431 -2723
  171. package/dist/schemas/sdk-config.js +16 -1
  172. package/dist/schemas/sdk-errors-client.d.ts +6 -0
  173. package/dist/schemas/sdk-errors-client.js +31 -1
  174. package/dist/schemas/sdk-errors-server.d.ts +8 -1
  175. package/dist/schemas/sdk-errors-server.js +45 -5
  176. package/dist/schemas/text-to-speech.d.ts +81 -698
  177. package/dist/schemas/text-to-speech.js +46 -19
  178. package/dist/schemas/transcription-config.d.ts +40 -229
  179. package/dist/schemas/transcription-config.js +76 -15
  180. package/dist/schemas/transcription.d.ts +108 -2
  181. package/dist/schemas/transcription.js +81 -0
  182. package/dist/schemas/translate.d.ts +2 -0
  183. package/dist/schemas/translate.js +13 -2
  184. package/dist/schemas/translation-config.d.ts +90 -40
  185. package/dist/schemas/unload-model.d.ts +2 -1
  186. package/dist/schemas/unload-model.js +4 -1
  187. package/dist/schemas/vla.d.ts +87 -0
  188. package/dist/schemas/vla.js +108 -0
  189. package/dist/scripts/run-unit-tests.js +22 -3
  190. package/dist/server/bare/ops/cancel.d.ts +27 -1
  191. package/dist/server/bare/ops/cancel.js +36 -10
  192. package/dist/server/bare/ops/embed.d.ts +3 -3
  193. package/dist/server/bare/ops/embed.js +144 -28
  194. package/dist/server/bare/ops/kv-cache-utils.d.ts +0 -7
  195. package/dist/server/bare/ops/kv-cache-utils.js +8 -47
  196. package/dist/server/bare/ops/transcribe.d.ts +11 -5
  197. package/dist/server/bare/ops/transcribe.js +230 -50
  198. package/dist/server/bare/ops/translate.d.ts +1 -1
  199. package/dist/server/bare/ops/translate.js +197 -88
  200. package/dist/server/bare/plugins/ggml-classification/ops/classify.d.ts +6 -0
  201. package/dist/server/bare/plugins/ggml-classification/ops/classify.js +30 -0
  202. package/dist/server/bare/plugins/ggml-classification/plugin.d.ts +32 -0
  203. package/dist/server/bare/plugins/ggml-classification/plugin.js +55 -0
  204. package/dist/server/bare/plugins/ggml-vla/ops/vla-hparams.d.ts +3 -0
  205. package/dist/server/bare/plugins/ggml-vla/ops/vla-hparams.js +12 -0
  206. package/dist/server/bare/plugins/ggml-vla/ops/vla-run.d.ts +3 -0
  207. package/dist/server/bare/plugins/ggml-vla/ops/vla-run.js +75 -0
  208. package/dist/server/bare/plugins/ggml-vla/plugin.d.ts +54 -0
  209. package/dist/server/bare/plugins/ggml-vla/plugin.js +57 -0
  210. package/dist/server/bare/plugins/index.d.ts +3 -1
  211. package/dist/server/bare/plugins/index.js +3 -1
  212. package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.d.ts +12 -3
  213. package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.js +173 -172
  214. package/dist/server/bare/plugins/llamacpp-completion/ops/context-overflow.d.ts +29 -0
  215. package/dist/server/bare/plugins/llamacpp-completion/ops/context-overflow.js +65 -0
  216. package/dist/server/bare/plugins/llamacpp-completion/ops/finetune.js +125 -21
  217. package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-session.d.ts +154 -0
  218. package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-session.js +448 -0
  219. package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-state.d.ts +21 -73
  220. package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-state.js +18 -101
  221. package/dist/server/bare/plugins/llamacpp-completion/plugin.d.ts +36 -3
  222. package/dist/server/bare/plugins/llamacpp-completion/plugin.js +183 -85
  223. package/dist/server/bare/plugins/llamacpp-completion/transform.d.ts +10 -0
  224. package/dist/server/bare/plugins/llamacpp-completion/transform.js +34 -0
  225. package/dist/server/bare/plugins/llamacpp-embedding/plugin.d.ts +7 -0
  226. package/dist/server/bare/plugins/llamacpp-embedding/plugin.js +10 -1
  227. package/dist/server/bare/plugins/nmtcpp-translation/plugin.d.ts +42 -15
  228. package/dist/server/bare/plugins/nmtcpp-translation/plugin.js +5 -1
  229. package/dist/server/bare/plugins/onnx-ocr/plugin.d.ts +8 -3
  230. package/dist/server/bare/plugins/onnx-ocr/plugin.js +3 -0
  231. package/dist/server/bare/plugins/parakeet-transcription/plugin.d.ts +73 -244
  232. package/dist/server/bare/plugins/parakeet-transcription/plugin.js +68 -96
  233. package/dist/server/bare/plugins/sdcpp-generation/ops/diffusion.js +8 -0
  234. package/dist/server/bare/plugins/sdcpp-generation/ops/upscale.d.ts +3 -0
  235. package/dist/server/bare/plugins/sdcpp-generation/ops/upscale.js +40 -0
  236. package/dist/server/bare/plugins/sdcpp-generation/ops/video.d.ts +3 -0
  237. package/dist/server/bare/plugins/sdcpp-generation/ops/video.js +199 -0
  238. package/dist/server/bare/plugins/sdcpp-generation/plugin.d.ts +288 -15
  239. package/dist/server/bare/plugins/sdcpp-generation/plugin.js +150 -7
  240. package/dist/server/bare/plugins/{onnx-tts → tts-ggml}/ops/text-to-speech-stream.js +2 -15
  241. package/dist/server/bare/plugins/{onnx-tts → tts-ggml}/ops/text-to-speech.js +2 -1
  242. package/dist/server/bare/plugins/tts-ggml/plugin.d.ts +75 -0
  243. package/dist/server/bare/plugins/tts-ggml/plugin.js +189 -0
  244. package/dist/server/bare/plugins/whispercpp-transcription/plugin.d.ts +47 -3
  245. package/dist/server/bare/plugins/whispercpp-transcription/plugin.js +61 -14
  246. package/dist/server/bare/rag-hyperdb/index.d.ts +1 -1
  247. package/dist/server/bare/rag-hyperdb/index.js +1 -1
  248. package/dist/server/bare/rag-hyperdb/rag-operation-manager.d.ts +26 -4
  249. package/dist/server/bare/rag-hyperdb/rag-operation-manager.js +65 -28
  250. package/dist/server/bare/registry/model-config-utils.js +7 -0
  251. package/dist/server/bare/runtime/disposable-scope.d.ts +36 -0
  252. package/dist/server/bare/runtime/disposable-scope.js +69 -0
  253. package/dist/server/bare/runtime/index.d.ts +8 -0
  254. package/dist/server/bare/runtime/index.js +3 -0
  255. package/dist/server/bare/runtime/request-context.d.ts +49 -0
  256. package/dist/server/bare/runtime/request-context.js +1 -0
  257. package/dist/server/bare/runtime/request-id.d.ts +12 -0
  258. package/dist/server/bare/runtime/request-id.js +14 -0
  259. package/dist/server/bare/runtime/request-registry-singleton.d.ts +4 -0
  260. package/dist/server/bare/runtime/request-registry-singleton.js +27 -0
  261. package/dist/server/bare/runtime/request-registry.d.ts +136 -0
  262. package/dist/server/bare/runtime/request-registry.js +297 -0
  263. package/dist/server/bare/runtime/with-request-context.d.ts +22 -0
  264. package/dist/server/bare/runtime/with-request-context.js +53 -0
  265. package/dist/server/bare/runtime-lifecycle.js +9 -9
  266. package/dist/server/bare/types/addon-responses.d.ts +12 -1
  267. package/dist/server/env.js +4 -1
  268. package/dist/server/plugins/index.d.ts +1 -1
  269. package/dist/server/plugins/index.js +1 -1
  270. package/dist/server/plugins/registry.d.ts +1 -0
  271. package/dist/server/plugins/registry.js +5 -0
  272. package/dist/server/rpc/handler-registry.js +30 -7
  273. package/dist/server/rpc/handler-selection.d.ts +9 -0
  274. package/dist/server/rpc/handler-selection.js +14 -0
  275. package/dist/server/rpc/handler-utils.js +5 -13
  276. package/dist/server/rpc/handlers/cancel-delegated.js +28 -31
  277. package/dist/server/rpc/handlers/cancelHandler.d.ts +30 -1
  278. package/dist/server/rpc/handlers/cancelHandler.js +54 -22
  279. package/dist/server/rpc/handlers/classify.d.ts +3 -0
  280. package/dist/server/rpc/handlers/classify.js +4 -0
  281. package/dist/server/rpc/handlers/delete-cache.d.ts +9 -0
  282. package/dist/server/rpc/handlers/delete-cache.js +13 -15
  283. package/dist/server/rpc/handlers/download-asset.js +133 -40
  284. package/dist/server/rpc/handlers/index.d.ts +4 -0
  285. package/dist/server/rpc/handlers/index.js +4 -0
  286. package/dist/server/rpc/handlers/load-model/download-manager.d.ts +60 -2
  287. package/dist/server/rpc/handlers/load-model/download-manager.js +141 -8
  288. package/dist/server/rpc/handlers/load-model/handler.js +216 -98
  289. package/dist/server/rpc/handlers/load-model/http.js +3 -3
  290. package/dist/server/rpc/handlers/load-model/hyperdrive.js +1 -1
  291. package/dist/server/rpc/handlers/load-model/registry.js +1 -1
  292. package/dist/server/rpc/handlers/load-model/resolve-session.d.ts +20 -1
  293. package/dist/server/rpc/handlers/load-model/resolve-session.js +6 -5
  294. package/dist/server/rpc/handlers/load-model/resolve.d.ts +3 -2
  295. package/dist/server/rpc/handlers/load-model/resolve.js +18 -6
  296. package/dist/server/rpc/handlers/load-model/types.d.ts +24 -0
  297. package/dist/server/rpc/handlers/rag.js +133 -15
  298. package/dist/server/rpc/handlers/upscale-stream.d.ts +3 -0
  299. package/dist/server/rpc/handlers/upscale-stream.js +4 -0
  300. package/dist/server/rpc/handlers/video-stream.d.ts +3 -0
  301. package/dist/server/rpc/handlers/video-stream.js +4 -0
  302. package/dist/server/rpc/profiling/operation-metrics.js +23 -0
  303. package/dist/server/utils/completion-normalizer.js +8 -0
  304. package/dist/server/utils/config-transform.js +1 -1
  305. package/dist/server/utils/tools/dialect.js +4 -0
  306. package/dist/server/utils/tools/parser.js +16 -1
  307. package/dist/server/utils/tools/parsers/gemma4native.d.ts +4 -0
  308. package/dist/server/utils/tools/parsers/gemma4native.js +60 -0
  309. package/dist/server/utils/tools/parsers/qwen35.d.ts +4 -0
  310. package/dist/server/utils/tools/parsers/qwen35.js +120 -0
  311. package/dist/server/worker.js +14 -11
  312. package/dist/utils/aggregate-events.d.ts +9 -0
  313. package/dist/utils/aggregate-events.js +18 -3
  314. package/dist/utils/decorate-promise.d.ts +34 -0
  315. package/dist/utils/decorate-promise.js +35 -0
  316. package/dist/utils/errors-client.d.ts +18 -0
  317. package/dist/utils/errors-client.js +31 -0
  318. package/dist/utils/errors-server.d.ts +115 -2
  319. package/dist/utils/errors-server.js +148 -3
  320. package/package.json +68 -77
  321. package/dist/server/bare/plugins/onnx-tts/plugin.d.ts +0 -490
  322. package/dist/server/bare/plugins/onnx-tts/plugin.js +0 -266
  323. package/dist/server/bare/plugins/onnx-tts/wav-helper.d.ts +0 -14
  324. package/dist/server/bare/plugins/onnx-tts/wav-helper.js +0 -107
  325. /package/dist/server/bare/plugins/{onnx-tts → tts-ggml}/ops/text-to-speech-stream.d.ts +0 -0
  326. /package/dist/server/bare/plugins/{onnx-tts → tts-ggml}/ops/text-to-speech.d.ts +0 -0
@@ -1,39 +1,76 @@
1
- import { AbortController } from "bare-abort-controller";
2
- import { DEFAULT_WORKSPACE } from "./rag-workspace-manager.js";
3
- // Map of workspace -> active operation
4
- const activeOperations = new Map();
1
+ import { getRequestRegistry } from "../runtime/index.js";
2
+ // Sentinel for "no workspace specified". Mirrors the value re-exported
3
+ // from `rag-workspace-manager.ts`; redeclared locally so this module is
4
+ // safely importable in environments that don't have the Bare runtime
5
+ // (unit tests, doc generators) — `rag-workspace-manager` pulls in
6
+ // `bare-fs` / `bare-path` at module load.
7
+ const DEFAULT_WORKSPACE = "default";
8
+ /**
9
+ * RAG operation tracking — workspace-level admission bookkeeping.
10
+ *
11
+ * In 0.11.0 the cancel surface for in-flight RAG operations consolidates
12
+ * onto the request registry (`getRequestRegistry().cancel({ requestId })`).
13
+ * The historical workspace-level pre-emption rule — "starting a new
14
+ * `ingest` / `reindex` / `saveEmbeddings` on a workspace cancels any prior
15
+ * op on the same workspace" — is preserved by the dispatcher in
16
+ * `server/rpc/handlers/rag.ts`: the dispatcher cancels the workspace's
17
+ * prior `requestId` (if any) and then begins a new registry context.
18
+ * Workspace-level admission lives in the dispatcher rather than as a
19
+ * registry policy primitive — it's a dispatch concern, not part of the
20
+ * registry's per-`kind` admission rules.
21
+ *
22
+ * This module owns the small workspace → requestId map that makes that
23
+ * pre-emption decision routable from the dispatcher. The map is module-
24
+ * scoped (one per Bare worker) so the dispatcher, the shutdown sweep
25
+ * (`cancelAllRagOperations`), and the workspace-close sweep (which
26
+ * delegates to it via `rag-workspace-manager.ts`) all see the same state.
27
+ */
28
+ // workspace key → requestId of the in-flight RAG operation on that workspace.
29
+ const activeRagRequestByWorkspace = new Map();
5
30
  export function getWorkspaceKey(workspace) {
6
31
  return workspace ?? DEFAULT_WORKSPACE;
7
32
  }
8
- export function registerRagOperation(workspace, operation) {
9
- const key = getWorkspaceKey(workspace);
10
- // Cancel any existing operation on this workspace
11
- cancelRagOperation(workspace);
12
- const abortController = new AbortController();
13
- activeOperations.set(key, {
14
- abortController,
15
- operation,
16
- startTime: Date.now(),
17
- });
18
- return abortController.signal;
33
+ /**
34
+ * Returns the `requestId` of any in-flight RAG operation on the workspace
35
+ * (or `undefined` if none). The dispatcher uses this to decide whether to
36
+ * pre-empt before calling `registry.begin(...)`.
37
+ */
38
+ export function getActiveRagRequest(workspace) {
39
+ return activeRagRequestByWorkspace.get(getWorkspaceKey(workspace));
19
40
  }
20
- export function unregisterRagOperation(workspace) {
21
- const key = getWorkspaceKey(workspace);
22
- activeOperations.delete(key);
41
+ /**
42
+ * Records the `requestId` of a freshly-begun RAG operation. Called by the
43
+ * dispatcher in `rag.ts` after `registry.begin(...)` succeeds; paired with
44
+ * `clearActiveRagRequest` via the request scope's deferred cleanup so the
45
+ * map never outlives the request.
46
+ */
47
+ export function setActiveRagRequest(workspace, requestId) {
48
+ activeRagRequestByWorkspace.set(getWorkspaceKey(workspace), requestId);
23
49
  }
24
- export function cancelRagOperation(workspace) {
50
+ /**
51
+ * Clears the workspace's mapping iff it still belongs to `requestId`. The
52
+ * conditional guard handles the natural race between two ingest calls on
53
+ * the same workspace: the older context's scope unwind must not stomp the
54
+ * newer context's mapping installed by the pre-emption sequence.
55
+ */
56
+ export function clearActiveRagRequest(workspace, requestId) {
25
57
  const key = getWorkspaceKey(workspace);
26
- const entry = activeOperations.get(key);
27
- if (!entry) {
28
- return false;
58
+ if (activeRagRequestByWorkspace.get(key) === requestId) {
59
+ activeRagRequestByWorkspace.delete(key);
29
60
  }
30
- entry.abortController.abort();
31
- activeOperations.delete(key);
32
- return true;
33
61
  }
62
+ /**
63
+ * Shutdown / workspace-close sweep. Cancels every tracked RAG request via
64
+ * the registry and clears the workspace map. Idempotent — callers that
65
+ * re-invoke during a teardown (workspace-close fired twice, shutdown
66
+ * racing with `close-all`) get a no-op on the second pass.
67
+ */
34
68
  export function cancelAllRagOperations() {
35
- for (const [key, entry] of activeOperations.entries()) {
36
- entry.abortController.abort();
37
- activeOperations.delete(key);
69
+ if (activeRagRequestByWorkspace.size === 0)
70
+ return;
71
+ const registry = getRequestRegistry();
72
+ for (const [key, requestId] of activeRagRequestByWorkspace) {
73
+ registry.cancel({ requestId, reason: "rag-shutdown" });
74
+ activeRagRequestByWorkspace.delete(key);
38
75
  }
39
76
  }
@@ -3,6 +3,8 @@ import { llmConfigSchema, embedConfigSchema } from "../../../schemas/llamacpp-co
3
3
  import { whisperConfigSchema, parakeetRuntimeConfigSchema, } from "../../../schemas/transcription-config.js";
4
4
  import { ocrConfigSchema } from "../../../schemas/ocr.js";
5
5
  import { sdcppConfigSchema } from "../../../schemas/sdcpp-config.js";
6
+ import { vlaConfigSchema } from "../../../schemas/vla.js";
7
+ import { classificationConfigSchema } from "../../../schemas/classification.js";
6
8
  export const CANONICAL_TO_ALIAS = {
7
9
  [ModelType.llamacppCompletion]: "llm",
8
10
  [ModelType.llamacppEmbedding]: "embeddings",
@@ -10,8 +12,11 @@ export const CANONICAL_TO_ALIAS = {
10
12
  [ModelType.parakeetTranscription]: "parakeet",
11
13
  [ModelType.nmtcppTranslation]: "nmt",
12
14
  [ModelType.onnxTts]: "tts",
15
+ [ModelType.ttsGgml]: "tts",
13
16
  [ModelType.onnxOcr]: "ocr",
14
17
  [ModelType.sdcppGeneration]: "diffusion",
18
+ [ModelType.ggmlVla]: "vla",
19
+ [ModelType.ggmlClassification]: "classification",
15
20
  };
16
21
  export const MODEL_CONFIG_SCHEMAS = {
17
22
  [ModelType.llamacppCompletion]: llmConfigSchema,
@@ -20,6 +25,8 @@ export const MODEL_CONFIG_SCHEMAS = {
20
25
  [ModelType.parakeetTranscription]: parakeetRuntimeConfigSchema.passthrough(),
21
26
  [ModelType.onnxOcr]: ocrConfigSchema,
22
27
  [ModelType.sdcppGeneration]: sdcppConfigSchema,
28
+ [ModelType.ggmlVla]: vlaConfigSchema,
29
+ [ModelType.ggmlClassification]: classificationConfigSchema,
23
30
  };
24
31
  // Ordered general → specific (later patterns override earlier)
25
32
  export const BUILTIN_DEVICE_PATTERNS = [
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Bounded-lifetime cleanup scope for an in-flight request.
3
+ *
4
+ * Callers register cleanup callbacks via `defer(...)` while a handler runs.
5
+ * On `[Symbol.asyncDispose]()` (used implicitly by `await using` or
6
+ * explicitly) every registered callback is awaited in **LIFO** order — the
7
+ * mirror of how `try/finally` blocks would unwind in a sequential write-up
8
+ * of the same handler.
9
+ *
10
+ * Guarantees:
11
+ *
12
+ * - **Idempotent.** A scope can be disposed once. Subsequent disposes are
13
+ * no-ops; subsequent `defer` calls run the cleanup eagerly so callers
14
+ * never silently leak a deferred resource if they hand a deferred
15
+ * callback to an already-disposed scope.
16
+ * - **Error aggregation.** Every deferred cleanup runs even when an
17
+ * earlier one throws. If a single cleanup throws, that error is
18
+ * rethrown verbatim. If two or more throw, an `AggregateError` is
19
+ * rethrown carrying every failure in the order it occurred. The
20
+ * handler unwinding the scope can therefore see _all_ cleanup
21
+ * failures, not just the first one.
22
+ */
23
+ export interface DisposableScope {
24
+ /**
25
+ * Register a cleanup callback. Cleanups run on dispose in LIFO order.
26
+ * Calling `defer` after the scope has been disposed runs the cleanup
27
+ * eagerly so resources never leak silently.
28
+ */
29
+ defer(cleanup: () => Promise<void> | void): void;
30
+ /** Run all registered cleanups. Idempotent. */
31
+ [Symbol.asyncDispose](): Promise<void>;
32
+ /** True after the first dispose has been initiated. */
33
+ readonly disposed: boolean;
34
+ }
35
+ export declare function createDisposableScope(): DisposableScope;
36
+ //# sourceMappingURL=disposable-scope.d.ts.map
@@ -0,0 +1,69 @@
1
+ import { AsyncDisposeUnavailableError } from "../../../utils/errors-server.js";
2
+ /**
3
+ * Module-load guard. The whole request-lifecycle primitive stack (scopes,
4
+ * the registry's `ManagedRequestContext`, `await using ctx = ...`) is
5
+ * built on `Symbol.asyncDispose`, which is an ES2024 feature. If the host
6
+ * runtime doesn't expose it (older Bare/Expo build, missing polyfill),
7
+ * the `[Symbol.asyncDispose]:` property key in this file's `dispose`
8
+ * function would coerce to the string `"undefined"` and silently produce
9
+ * objects that look async-disposable but are not — handlers would leak
10
+ * registry entries forever. Better to fail loudly at import time with a
11
+ * clear error than to debug a slow registry leak in production.
12
+ */
13
+ if (typeof Symbol.asyncDispose !== "symbol") {
14
+ throw new AsyncDisposeUnavailableError();
15
+ }
16
+ export function createDisposableScope() {
17
+ const cleanups = [];
18
+ let disposed = false;
19
+ let disposing = false;
20
+ function defer(cleanup) {
21
+ if (disposed || disposing) {
22
+ void runEagerly(cleanup);
23
+ return;
24
+ }
25
+ cleanups.push(cleanup);
26
+ }
27
+ async function runEagerly(cleanup) {
28
+ try {
29
+ await cleanup();
30
+ }
31
+ catch {
32
+ // Late-deferred cleanups have no caller waiting on them; the
33
+ // unwinding path that disposed the scope already returned its own
34
+ // errors. Swallowing here matches the user's intent of registering
35
+ // a fire-and-forget cleanup.
36
+ }
37
+ }
38
+ async function dispose() {
39
+ if (disposed || disposing)
40
+ return;
41
+ disposing = true;
42
+ const errors = [];
43
+ while (cleanups.length > 0) {
44
+ const cleanup = cleanups.pop();
45
+ if (!cleanup)
46
+ continue;
47
+ try {
48
+ await cleanup();
49
+ }
50
+ catch (err) {
51
+ errors.push(err);
52
+ }
53
+ }
54
+ disposed = true;
55
+ disposing = false;
56
+ if (errors.length === 1)
57
+ throw errors[0];
58
+ if (errors.length > 1) {
59
+ throw new AggregateError(errors, `DisposableScope: ${errors.length} cleanups failed`);
60
+ }
61
+ }
62
+ return {
63
+ defer,
64
+ [Symbol.asyncDispose]: dispose,
65
+ get disposed() {
66
+ return disposed;
67
+ },
68
+ };
69
+ }
@@ -0,0 +1,8 @@
1
+ export { createDisposableScope } from "./disposable-scope";
2
+ export type { DisposableScope } from "./disposable-scope";
3
+ export type { RequestContext, RequestKind, RequestState, } from "./request-context";
4
+ export { createRequestRegistry, getRequestRegistry, } from "./request-registry-singleton";
5
+ export type { BeginOpts, CancelByModelId, CancelByRequestId, CancelTarget, ConcurrencyPolicy, ManagedRequestContext, RequestOutcome, RequestRegistry, } from "./request-registry";
6
+ export { withRequestContext } from "./with-request-context";
7
+ export type { RequestLogContext } from "./with-request-context";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,3 @@
1
+ export { createDisposableScope } from "./disposable-scope.js";
2
+ export { createRequestRegistry, getRequestRegistry, } from "./request-registry-singleton.js";
3
+ export { withRequestContext } from "./with-request-context.js";
@@ -0,0 +1,49 @@
1
+ import type { AbortSignal } from "bare-abort-controller";
2
+ import type { DisposableScope } from "./disposable-scope";
3
+ /**
4
+ * Coarse classification of a long-running request. Used by
5
+ * `RequestRegistry.cancel({ modelId, kind })` so a broad cancel can target
6
+ * just one operation kind on a given model (e.g. cancel an in-flight
7
+ * completion without touching a finetune running on the same model).
8
+ *
9
+ * The set is intentionally open-coded — adding a new kind is a one-line
10
+ * change and the union surfaces in editor autocomplete at every call site.
11
+ */
12
+ export type RequestKind = "completion" | "embeddings" | "transcribe" | "translate" | "diffusion" | "tts" | "ocr" | "vla" | "finetune" | "loadModel" | "downloadAsset" | "rag";
13
+ /**
14
+ * Lifecycle states a request transitions through. A new context starts in
15
+ * `"running"`. `cancel(...)` flips it to `"cancelling"` and aborts the
16
+ * signal; `end({ outcome: "completed" | "failed" | "cancelled" })` flips
17
+ * it to a terminal state and removes it from the registry.
18
+ *
19
+ * Kept as a string union (not a state machine) on purpose — handlers read
20
+ * `state` defensively at most a couple of points and a flat enum is easier
21
+ * to log/assert than a transition table.
22
+ */
23
+ export type RequestState = "running" | "cancelling" | "completed" | "failed" | "cancelled";
24
+ /**
25
+ * Per-request lifecycle handle. Created by `RequestRegistry.begin(...)`
26
+ * and consumed by long-running handlers as the single owner of:
27
+ *
28
+ * - `requestId` — stable identity; visible to the client so it can
29
+ * target this exact request with `cancel({ requestId })`.
30
+ * - `signal` — `AbortSignal` that fires when the request is cancelled.
31
+ * Composes with addon-level cancellation through a single
32
+ * `signal.addEventListener("abort", ...)` hook installed by the
33
+ * handler.
34
+ * - `scope` — `DisposableScope` for `await using` / `Symbol.asyncDispose`
35
+ * cleanup. The scope unwinds whether the handler returns, throws, or
36
+ * is cancelled — there is no manual cleanup path for handlers to
37
+ * forget on the cancel branch.
38
+ * - `state` — current lifecycle state. Treat as read-mostly; the
39
+ * registry mutates it.
40
+ */
41
+ export interface RequestContext {
42
+ readonly requestId: string;
43
+ readonly kind: RequestKind;
44
+ readonly modelId: string | undefined;
45
+ readonly signal: AbortSignal;
46
+ readonly scope: DisposableScope;
47
+ state: RequestState;
48
+ }
49
+ //# sourceMappingURL=request-context.d.ts.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Server-side fallback for `requestId`. The new wire contract is that
3
+ * the client generates the id (UUIDv4) at call time so it's surfaced
4
+ * synchronously on the `CompletionRun` for use with `cancel({ requestId })`.
5
+ * To keep older clients working, the request schema marks `requestId`
6
+ * optional and the server fills it in here when it's missing.
7
+ *
8
+ * `bare-crypto.randomUUID()` mirrors Node's `crypto.randomUUID()` and is
9
+ * Bare-runtime safe. Returns a v4 UUID.
10
+ */
11
+ export declare function generateServerRequestId(): string;
12
+ //# sourceMappingURL=request-id.d.ts.map
@@ -0,0 +1,14 @@
1
+ import { randomUUID } from "bare-crypto";
2
+ /**
3
+ * Server-side fallback for `requestId`. The new wire contract is that
4
+ * the client generates the id (UUIDv4) at call time so it's surfaced
5
+ * synchronously on the `CompletionRun` for use with `cancel({ requestId })`.
6
+ * To keep older clients working, the request schema marks `requestId`
7
+ * optional and the server fills it in here when it's missing.
8
+ *
9
+ * `bare-crypto.randomUUID()` mirrors Node's `crypto.randomUUID()` and is
10
+ * Bare-runtime safe. Returns a v4 UUID.
11
+ */
12
+ export function generateServerRequestId() {
13
+ return randomUUID();
14
+ }
@@ -0,0 +1,4 @@
1
+ import { createRequestRegistry as createRegistry, type RequestRegistry } from "./request-registry";
2
+ export declare function getRequestRegistry(): RequestRegistry;
3
+ export { createRegistry as createRequestRegistry };
4
+ //# sourceMappingURL=request-registry-singleton.d.ts.map
@@ -0,0 +1,27 @@
1
+ import { createRequestRegistry as createRegistry, } from "./request-registry.js";
2
+ /**
3
+ * Worker-process singleton. Every long-running request in this Bare
4
+ * worker registers under this registry, so a `cancel({ requestId })` RPC
5
+ * can find its target without the caller needing to know which plugin /
6
+ * handler owns the request.
7
+ *
8
+ * Exposed alongside `createRequestRegistry()` rather than replacing it so
9
+ * unit tests can spin up isolated registries without contaminating the
10
+ * shared instance. On first use the singleton registers the SDK's
11
+ * baseline concurrency policies.
12
+ */
13
+ let registry = null;
14
+ function installDefaultPolicies(r) {
15
+ // The llama.cpp addon owns one KV-cache + one decode loop per model,
16
+ // so two concurrent `completionStream` requests on the same model
17
+ // would interleave their token streams on the same logical session.
18
+ r.policy({ kind: "completion", oneAtATimePerModel: true });
19
+ }
20
+ export function getRequestRegistry() {
21
+ if (!registry) {
22
+ registry = createRegistry();
23
+ installDefaultPolicies(registry);
24
+ }
25
+ return registry;
26
+ }
27
+ export { createRegistry as createRequestRegistry };
@@ -0,0 +1,136 @@
1
+ import { type AbortSignal } from "bare-abort-controller";
2
+ import type { RequestContext, RequestKind } from "./request-context";
3
+ import type { Logger } from "../../../logging/types";
4
+ /**
5
+ * Outcome the caller declares when terminating a request through
6
+ * `registry.end(...)`. The registry maps it to a terminal `RequestState`
7
+ * before disposing the scope so observers see a coherent final state.
8
+ */
9
+ export type RequestOutcome = "completed" | "failed" | "cancelled";
10
+ export interface BeginOpts {
11
+ /** Stable identity. Caller-provided so the client and server agree. */
12
+ requestId: string;
13
+ kind: RequestKind;
14
+ modelId?: string;
15
+ /**
16
+ * Optional parent abort signal — typically the worker-level "shutdown"
17
+ * signal. When the parent aborts, the request's own signal aborts too.
18
+ * Composes through a `addEventListener("abort", ...)` hook so cancelling
19
+ * the parent does not require iterating the registry.
20
+ */
21
+ parentSignal?: AbortSignal;
22
+ }
23
+ export interface CancelByRequestId {
24
+ requestId: string;
25
+ reason?: string;
26
+ }
27
+ export interface CancelByModelId {
28
+ modelId: string;
29
+ kind?: RequestKind;
30
+ reason?: string;
31
+ }
32
+ export type CancelTarget = CancelByRequestId | CancelByModelId;
33
+ /**
34
+ * Per-kind admission rule. Kinds without a registered policy have no
35
+ * admission control (every `begin(...)` is accepted as long as the
36
+ * request id is unique).
37
+ */
38
+ export interface ConcurrencyPolicy {
39
+ kind: RequestKind;
40
+ /**
41
+ * When true, at most one in-flight request per `(kind, modelId)`
42
+ * tuple — a second `begin(...)` rejects with
43
+ * `RequestRejectedByPolicyError`. Requests without a `modelId` are
44
+ * unaffected.
45
+ */
46
+ oneAtATimePerModel: boolean;
47
+ }
48
+ /**
49
+ * `ManagedRequestContext` is the value `begin(...)` returns. It extends
50
+ * `RequestContext` with an async-dispose method so handlers can write:
51
+ *
52
+ * await using ctx = registry.begin({ ... });
53
+ *
54
+ * On dispose the scope unwinds (LIFO cleanup) and the registry slot is
55
+ * freed. If the handler doesn't override `ctx.state` before unwinding,
56
+ * the registry derives the terminal state from `signal.aborted` —
57
+ * `"cancelled"` when an abort was recorded, `"completed"` otherwise.
58
+ */
59
+ export interface ManagedRequestContext extends RequestContext {
60
+ [Symbol.asyncDispose](): Promise<void>;
61
+ }
62
+ export interface RequestRegistry {
63
+ /**
64
+ * Open a new request. Throws:
65
+ * - `RequestIdConflictError` if `requestId` is already present
66
+ * (UUIDv4 collision is astronomically unlikely; the guard exists
67
+ * so a buggy client retry sending the same id can't silently
68
+ * overwrite an in-flight request).
69
+ * - `RequestRejectedByPolicyError` if a concurrency policy was
70
+ * registered for `opts.kind` and the new request would violate
71
+ * it (e.g. `oneAtATimePerModel` rejects when another request
72
+ * with the same `(kind, modelId)` pair is already in flight).
73
+ */
74
+ begin(opts: BeginOpts): ManagedRequestContext;
75
+ /**
76
+ * Register or replace the concurrency policy for a `RequestKind`.
77
+ * Subsequent `begin(...)` calls for that kind run the policy before
78
+ * allocating a controller / scope. One policy per kind — calling
79
+ * twice replaces the previous declaration.
80
+ *
81
+ * @example
82
+ * r.policy({ kind: "completion", oneAtATimePerModel: true });
83
+ * await using a = r.begin({ requestId: "r-1", kind: "completion", modelId: "m1" });
84
+ * r.begin({ requestId: "r-2", kind: "completion", modelId: "m1" });
85
+ * // → throws RequestRejectedByPolicyError (code 52420)
86
+ */
87
+ policy(opts: ConcurrencyPolicy): void;
88
+ /** Look up an in-flight request by id. */
89
+ get(requestId: string): RequestContext | null;
90
+ /**
91
+ * Snapshot of currently-tracked requests. Useful for diagnostics /
92
+ * structured logs ("which requests are in flight right now?"). Returns
93
+ * a fresh array; mutations on it are not observed by the registry.
94
+ */
95
+ list(): RequestContext[];
96
+ /**
97
+ * Cancel matching requests. Returns the number of contexts whose abort
98
+ * was triggered by *this* call (already-cancelled contexts are skipped
99
+ * so callers can rely on the count to log "n requests cancelled" once).
100
+ *
101
+ * For `{ modelId }` and an optional `kind`, cancels every active
102
+ * request that matches the predicate. This is the broad-cancel path
103
+ * the pre-registry `cancel({ modelId })` API maps to.
104
+ */
105
+ cancel(target: CancelTarget): number;
106
+ /**
107
+ * Cancel every active request — the worker-shutdown / model-unload
108
+ * sweep. The reason is forwarded to each request as the abort reason
109
+ * so handler logs can distinguish a normal cancel from a sweep.
110
+ * Resolves once all targeted contexts have flipped to `"cancelling"`;
111
+ * scope unwinding still happens on each handler's own dispose path.
112
+ */
113
+ cancelAll(reason: "shutdown" | "modelUnload"): Promise<void>;
114
+ /**
115
+ * Mark a request finished and dispose its scope. Equivalent to
116
+ * `await ctx[Symbol.asyncDispose]()` with an explicit outcome.
117
+ * Idempotent — calling `end` after a scope dispose is a no-op.
118
+ */
119
+ end(requestId: string, outcome: RequestOutcome): Promise<void>;
120
+ }
121
+ export declare function createRequestRegistry(options?: {
122
+ /** Defaults to `getServerLogger()`. Tests inject a stub. */
123
+ logger?: Logger;
124
+ }): RequestRegistry;
125
+ /**
126
+ * Test-only knobs exported for `request-registry.test.ts` so the bound
127
+ * assertions can pin the documented limits without re-reading them via
128
+ * fragile string comparison. **Not part of the public SDK surface.**
129
+ *
130
+ * @internal
131
+ */
132
+ export declare const __requestRegistryTestHooks: {
133
+ cancelBeforeBeginMaxEntries: number;
134
+ cancelBeforeBeginTtlMs: number;
135
+ };
136
+ //# sourceMappingURL=request-registry.d.ts.map