@qvac/inference 0.18.2 → 0.19.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 (388) hide show
  1. package/NOTICE +11 -2
  2. package/README.md +1 -5
  3. package/dist/api/assess-model-fit.d.ts +16 -0
  4. package/dist/api/assess-model-fit.js +27 -0
  5. package/dist/api/audio-gen.d.ts +4 -4
  6. package/dist/api/audio-gen.js +17 -6
  7. package/dist/api/completion-stream.d.ts +1 -1
  8. package/dist/api/completion-stream.js +1 -1
  9. package/dist/api/download-asset.d.ts +1 -1
  10. package/dist/api/download-asset.js +2 -2
  11. package/dist/api/finetune.js +1 -1
  12. package/dist/api/get-loaded-model-info.d.ts +6 -10
  13. package/dist/api/get-loaded-model-info.js +6 -10
  14. package/dist/api/heartbeat.d.ts +5 -22
  15. package/dist/api/heartbeat.js +6 -23
  16. package/dist/api/index.d.ts +36 -35
  17. package/dist/api/index.js +35 -35
  18. package/dist/api/load-model.d.ts +5 -1
  19. package/dist/api/load-model.js +3 -5
  20. package/dist/api/logging-stream-registry.js +1 -1
  21. package/dist/api/resume.d.ts +0 -3
  22. package/dist/api/resume.js +0 -3
  23. package/dist/api/subscribe-logs.js +1 -1
  24. package/dist/api/suspend.d.ts +0 -4
  25. package/dist/api/suspend.js +0 -4
  26. package/dist/api/translate.d.ts +3 -1
  27. package/dist/api/translate.js +16 -8
  28. package/dist/api/unload-model.js +3 -5
  29. package/dist/api/video-request.d.ts +207 -0
  30. package/dist/api/video-request.js +18 -0
  31. package/dist/api/video.d.ts +22 -2
  32. package/dist/api/video.js +25 -15
  33. package/dist/api/vla-helpers.d.ts +1 -2
  34. package/dist/api/vla-helpers.js +1 -2
  35. package/dist/api/vla.js +1 -1
  36. package/dist/api/world-result.d.ts +71 -0
  37. package/dist/api/world-result.js +293 -0
  38. package/dist/api/world.d.ts +143 -0
  39. package/dist/api/world.js +71 -0
  40. package/dist/config/resolve-config.d.ts +1 -1
  41. package/dist/config/resolve-config.js +1 -1
  42. package/dist/constants/index.d.ts +2 -2
  43. package/dist/constants/index.js +2 -2
  44. package/dist/dispatch.js +15 -28
  45. package/dist/errors/index.d.ts +35 -31
  46. package/dist/errors/index.js +66 -56
  47. package/dist/handlers/assess-model-fit.d.ts +10 -0
  48. package/dist/handlers/assess-model-fit.js +75 -0
  49. package/dist/handlers/cancelHandler.js +1 -1
  50. package/dist/handlers/completion-orchestrate.js +1 -1
  51. package/dist/handlers/download-asset.js +6 -5
  52. package/dist/handlers/finetune.js +1 -1
  53. package/dist/handlers/get-loaded-model-info.js +0 -12
  54. package/dist/handlers/get-model-info.js +1 -1
  55. package/dist/handlers/get-system-resources.js +8 -0
  56. package/dist/handlers/load-model/download-manager.d.ts +1 -1
  57. package/dist/handlers/load-model/download-stats.d.ts +3 -3
  58. package/dist/handlers/load-model/download-stats.js +5 -5
  59. package/dist/handlers/load-model/handler.js +6 -8
  60. package/dist/handlers/load-model/http-verify.d.ts +20 -0
  61. package/dist/handlers/load-model/http-verify.js +54 -0
  62. package/dist/handlers/load-model/http.d.ts +12 -2
  63. package/dist/handlers/load-model/http.js +119 -230
  64. package/dist/handlers/load-model/hyperdrive.d.ts +1 -1
  65. package/dist/handlers/load-model/hyperdrive.js +1 -1
  66. package/dist/handlers/load-model/index.d.ts +2 -2
  67. package/dist/handlers/load-model/index.js +2 -2
  68. package/dist/handlers/load-model/registry-companion-set.d.ts +1 -1
  69. package/dist/handlers/load-model/registry-companion-set.js +1 -1
  70. package/dist/handlers/load-model/registry-download-utils.d.ts +3 -3
  71. package/dist/handlers/load-model/registry-download-utils.js +2 -2
  72. package/dist/handlers/load-model/registry.d.ts +2 -2
  73. package/dist/handlers/load-model/registry.js +4 -4
  74. package/dist/handlers/load-model/resolve-session.d.ts +8 -1
  75. package/dist/handlers/load-model/resolve-session.js +12 -9
  76. package/dist/handlers/load-model/resolve.d.ts +4 -4
  77. package/dist/handlers/load-model/resolve.js +18 -16
  78. package/dist/handlers/load-model/safe-fetch.d.ts +44 -0
  79. package/dist/handlers/load-model/safe-fetch.js +143 -0
  80. package/dist/handlers/load-model/types.d.ts +9 -0
  81. package/dist/handlers/plugin-dispatch.js +1 -4
  82. package/dist/handlers/plugin-invoke.js +1 -4
  83. package/dist/handlers/types.d.ts +0 -2
  84. package/dist/handlers/unload-model.js +1 -4
  85. package/dist/index.d.ts +1 -1
  86. package/dist/index.js +1 -1
  87. package/dist/logging/addon.d.ts +1 -1
  88. package/dist/logging/addon.js +1 -1
  89. package/dist/logging/index.d.ts +5 -5
  90. package/dist/logging/index.js +4 -4
  91. package/dist/logging/logger.d.ts +1 -1
  92. package/dist/logging/logger.js +2 -2
  93. package/dist/models/registry/index.d.ts +1 -1
  94. package/dist/models/registry/index.js +2 -2
  95. package/dist/models/registry/models.d.ts +250 -0
  96. package/dist/models/registry/models.js +2071 -1806
  97. package/dist/models/registry/resource-profiles.d.ts +18 -0
  98. package/dist/models/registry/resource-profiles.js +4934 -0
  99. package/dist/plugins/builtin/audiogen-ggml/config.d.ts +14 -0
  100. package/dist/plugins/builtin/audiogen-ggml/config.js +23 -0
  101. package/dist/plugins/builtin/audiogen-ggml/ops/audio-gen-stream.js +47 -5
  102. package/dist/plugins/builtin/audiogen-ggml/plugin.d.ts +134 -4
  103. package/dist/plugins/builtin/audiogen-ggml/plugin.js +47 -28
  104. package/dist/plugins/builtin/bci-whispercpp-transcription/plugin.d.ts +1 -1
  105. package/dist/plugins/builtin/bci-whispercpp-transcription/plugin.js +3 -3
  106. package/dist/plugins/builtin/ggml-classification/plugin.js +1 -1
  107. package/dist/plugins/builtin/ggml-ocr/plugin.js +2 -2
  108. package/dist/plugins/builtin/ggml-vla/plugin.d.ts +1 -1
  109. package/dist/plugins/builtin/ggml-vla/plugin.js +3 -3
  110. package/dist/plugins/builtin/index.d.ts +12 -12
  111. package/dist/plugins/builtin/index.js +12 -12
  112. package/dist/plugins/builtin/llamacpp-completion/ops/batch-completion-stream.js +2 -2
  113. package/dist/plugins/builtin/llamacpp-completion/ops/completion-stream.js +37 -26
  114. package/dist/plugins/builtin/llamacpp-completion/ops/context-overflow.d.ts +12 -11
  115. package/dist/plugins/builtin/llamacpp-completion/ops/context-overflow.js +133 -41
  116. package/dist/plugins/builtin/llamacpp-completion/ops/kv-cache-session.d.ts +7 -1
  117. package/dist/plugins/builtin/llamacpp-completion/ops/kv-cache-session.js +26 -4
  118. package/dist/plugins/builtin/llamacpp-completion/plugin.d.ts +19 -8
  119. package/dist/plugins/builtin/llamacpp-completion/plugin.js +10 -13
  120. package/dist/plugins/builtin/llamacpp-embedding/plugin.d.ts +4 -0
  121. package/dist/plugins/builtin/llamacpp-embedding/plugin.js +13 -2
  122. package/dist/plugins/builtin/nmtcpp-translation/plugin.js +2 -2
  123. package/dist/plugins/builtin/parakeet-transcription/plugin.d.ts +2 -2
  124. package/dist/plugins/builtin/parakeet-transcription/plugin.js +3 -3
  125. package/dist/plugins/builtin/sdcpp-generation/ops/upscale.js +1 -1
  126. package/dist/plugins/builtin/sdcpp-generation/ops/video.js +32 -2
  127. package/dist/plugins/builtin/sdcpp-generation/ops/world.d.ts +126 -0
  128. package/dist/plugins/builtin/sdcpp-generation/ops/world.js +820 -0
  129. package/dist/plugins/builtin/sdcpp-generation/plugin.d.ts +153 -4
  130. package/dist/plugins/builtin/sdcpp-generation/plugin.js +134 -13
  131. package/dist/plugins/builtin/tts-ggml/ops/text-to-speech-stream.js +1 -1
  132. package/dist/plugins/builtin/tts-ggml/ops/text-to-speech.js +1 -1
  133. package/dist/plugins/builtin/tts-ggml/plugin.js +2 -2
  134. package/dist/plugins/builtin/whispercpp-transcription/plugin.d.ts +2 -2
  135. package/dist/plugins/builtin/whispercpp-transcription/plugin.js +3 -3
  136. package/dist/plugins/index.d.ts +1 -1
  137. package/dist/plugins/index.js +2 -2
  138. package/dist/plugins/ops/kv-cache-utils.js +1 -1
  139. package/dist/plugins/ops/load-model.js +1 -1
  140. package/dist/plugins/ops/transcribe.js +2 -2
  141. package/dist/plugins/ops/translate.js +4 -12
  142. package/dist/plugins/ops/unload-model.js +19 -21
  143. package/dist/plugins/registry.d.ts +1 -0
  144. package/dist/plugins/registry.js +12 -0
  145. package/dist/profiling/aggregator.d.ts +1 -1
  146. package/dist/profiling/aggregator.js +1 -1
  147. package/dist/profiling/controller.d.ts +1 -1
  148. package/dist/profiling/controller.js +2 -2
  149. package/dist/profiling/envelope.d.ts +0 -1
  150. package/dist/profiling/envelope.js +0 -10
  151. package/dist/profiling/events.d.ts +2 -3
  152. package/dist/profiling/events.js +2 -9
  153. package/dist/profiling/exporters.d.ts +1 -1
  154. package/dist/profiling/exporters.js +3 -3
  155. package/dist/profiling/index.d.ts +13 -14
  156. package/dist/profiling/index.js +12 -13
  157. package/dist/profiling/operation-metrics.d.ts +1 -1
  158. package/dist/profiling/operation-metrics.js +35 -2
  159. package/dist/profiling/operation-wrappers.js +12 -15
  160. package/dist/profiling/profiler.d.ts +1 -2
  161. package/dist/profiling/profiler.js +7 -26
  162. package/dist/profiling/types.d.ts +1 -1
  163. package/dist/rag/handler.js +1 -1
  164. package/dist/rag/handlers/close-workspace.js +1 -1
  165. package/dist/rag/handlers/delete-embeddings.js +1 -1
  166. package/dist/rag/handlers/delete-workspace.js +2 -6
  167. package/dist/rag/handlers/ingest.js +1 -1
  168. package/dist/rag/handlers/list-workspaces.d.ts +1 -1
  169. package/dist/rag/handlers/list-workspaces.js +1 -1
  170. package/dist/rag/handlers/reindex.js +1 -1
  171. package/dist/rag/handlers/save-embeddings.js +1 -1
  172. package/dist/rag/handlers/search.js +1 -1
  173. package/dist/rag/index.d.ts +11 -11
  174. package/dist/rag/index.js +11 -11
  175. package/dist/rag/rag-workspace-manager.d.ts +4 -2
  176. package/dist/rag/rag-workspace-manager.js +268 -15
  177. package/dist/registry.js +8 -58
  178. package/dist/resources/collector.d.ts +3 -1
  179. package/dist/resources/collector.js +91 -9
  180. package/dist/resources/instance.d.ts +1 -1
  181. package/dist/resources/instance.js +1 -1
  182. package/dist/resources/model-fit/assess.d.ts +36 -0
  183. package/dist/resources/model-fit/assess.js +578 -0
  184. package/dist/resources/model-fit/calibration/darwin-arm64.d.ts +8 -0
  185. package/dist/resources/model-fit/calibration/darwin-arm64.js +36 -0
  186. package/dist/resources/model-fit/calibration/darwin-x64.d.ts +8 -0
  187. package/dist/resources/model-fit/calibration/darwin-x64.js +38 -0
  188. package/dist/resources/model-fit/calibration/fit.d.ts +73 -0
  189. package/dist/resources/model-fit/calibration/fit.js +152 -0
  190. package/dist/resources/model-fit/calibration/index.d.ts +37 -0
  191. package/dist/resources/model-fit/calibration/index.js +75 -0
  192. package/dist/resources/model-fit/calibration/linux-arm64.d.ts +8 -0
  193. package/dist/resources/model-fit/calibration/linux-arm64.js +38 -0
  194. package/dist/resources/model-fit/calibration/linux-x64-vulkan.d.ts +8 -0
  195. package/dist/resources/model-fit/calibration/linux-x64-vulkan.js +39 -0
  196. package/dist/resources/model-fit/calibration/linux-x64.d.ts +8 -0
  197. package/dist/resources/model-fit/calibration/linux-x64.js +38 -0
  198. package/dist/resources/model-fit/calibration/win32-x64-vulkan-shared.d.ts +8 -0
  199. package/dist/resources/model-fit/calibration/win32-x64-vulkan-shared.js +39 -0
  200. package/dist/resources/model-fit/calibration/win32-x64-vulkan.d.ts +8 -0
  201. package/dist/resources/model-fit/calibration/win32-x64-vulkan.js +36 -0
  202. package/dist/resources/model-fit/calibration/win32-x64.d.ts +8 -0
  203. package/dist/resources/model-fit/calibration/win32-x64.js +38 -0
  204. package/dist/resources/model-fit/estimators/llm.d.ts +45 -0
  205. package/dist/resources/model-fit/estimators/llm.js +220 -0
  206. package/dist/resources/model-fit/estimators/whisper.d.ts +10 -0
  207. package/dist/resources/model-fit/estimators/whisper.js +77 -0
  208. package/dist/resources/model-fit/types.d.ts +120 -0
  209. package/dist/resources/model-fit/types.js +1 -0
  210. package/dist/resources/native.d.ts +1 -1
  211. package/dist/resources/native.js +14 -0
  212. package/dist/resources/normalize.d.ts +1 -1
  213. package/dist/resources/types.d.ts +16 -0
  214. package/dist/runtime/index.d.ts +5 -5
  215. package/dist/runtime/index.js +2 -2
  216. package/dist/runtime/lifecycle.js +5 -7
  217. package/dist/runtime/model-registry.d.ts +0 -14
  218. package/dist/runtime/model-registry.js +17 -40
  219. package/dist/runtime/registry-client.js +1 -1
  220. package/dist/runtime/request-context.d.ts +3 -3
  221. package/dist/runtime/request-context.js +13 -1
  222. package/dist/runtime/request-registry.d.ts +1 -1
  223. package/dist/runtime/request-registry.js +4 -5
  224. package/dist/runtime/state.d.ts +1 -1
  225. package/dist/runtime/state.js +18 -3
  226. package/dist/schemas/assess-model-fit.d.ts +271 -0
  227. package/dist/schemas/assess-model-fit.js +153 -0
  228. package/dist/schemas/audio-gen.d.ts +434 -4
  229. package/dist/schemas/audio-gen.js +131 -19
  230. package/dist/schemas/batch-completion-stream.d.ts +2 -2
  231. package/dist/schemas/batch-completion-stream.js +3 -3
  232. package/dist/schemas/bci-config.js +73 -27
  233. package/dist/schemas/bci.d.ts +2 -2
  234. package/dist/schemas/bci.js +5 -5
  235. package/dist/schemas/cancel.d.ts +5 -0
  236. package/dist/schemas/cancel.js +1 -0
  237. package/dist/schemas/classification.js +13 -6
  238. package/dist/schemas/common.d.ts +662 -331
  239. package/dist/schemas/common.js +33 -31
  240. package/dist/schemas/completion-event.d.ts +2 -2
  241. package/dist/schemas/completion-event.js +1 -1
  242. package/dist/schemas/completion-stream.d.ts +1 -5
  243. package/dist/schemas/completion-stream.js +4 -8
  244. package/dist/schemas/config.d.ts +640 -18
  245. package/dist/schemas/config.js +50 -8
  246. package/dist/schemas/download-asset.d.ts +19 -1
  247. package/dist/schemas/download-asset.js +20 -4
  248. package/dist/schemas/engine-addon-map.d.ts +1 -1
  249. package/dist/schemas/engine-addon-map.js +3 -3
  250. package/dist/schemas/error.d.ts +2 -2
  251. package/dist/schemas/error.js +2 -2
  252. package/dist/schemas/errors.d.ts +2 -6
  253. package/dist/schemas/errors.js +30 -40
  254. package/dist/schemas/heartbeat.d.ts +10 -0
  255. package/dist/schemas/heartbeat.js +8 -0
  256. package/dist/schemas/index.d.ts +46 -44
  257. package/dist/schemas/index.js +45 -43
  258. package/dist/schemas/llamacpp-config.d.ts +32 -10
  259. package/dist/schemas/llamacpp-config.js +11 -8
  260. package/dist/schemas/load-model.d.ts +2933 -1948
  261. package/dist/schemas/load-model.js +52 -52
  262. package/dist/schemas/mcp-adapter.d.ts +1 -1
  263. package/dist/schemas/model-config-schemas.d.ts +2354 -0
  264. package/dist/schemas/model-config-schemas.js +46 -0
  265. package/dist/schemas/model-info.d.ts +10 -20
  266. package/dist/schemas/model-info.js +4 -25
  267. package/dist/schemas/model-ops.d.ts +0 -1
  268. package/dist/schemas/model-ops.js +1 -2
  269. package/dist/schemas/model-resource-profile.d.ts +109 -0
  270. package/dist/schemas/model-resource-profile.js +83 -0
  271. package/dist/schemas/model-src-utils.d.ts +1 -0
  272. package/dist/schemas/model-src-utils.js +33 -13
  273. package/dist/schemas/ocr.js +48 -13
  274. package/dist/schemas/path-validation.js +8 -2
  275. package/dist/schemas/plugin.d.ts +14 -1
  276. package/dist/schemas/plugin.js +11 -0
  277. package/dist/schemas/profiling.d.ts +138 -43
  278. package/dist/schemas/profiling.js +1 -22
  279. package/dist/schemas/rag.js +1 -1
  280. package/dist/schemas/registry.js +1 -1
  281. package/dist/schemas/reload-config.d.ts +0 -2
  282. package/dist/schemas/reload-config.js +2 -3
  283. package/dist/schemas/sdcpp-config.d.ts +344 -4
  284. package/dist/schemas/sdcpp-config.js +504 -17
  285. package/dist/schemas/system-resources.d.ts +138 -0
  286. package/dist/schemas/system-resources.js +3 -1
  287. package/dist/schemas/text-to-speech.js +183 -76
  288. package/dist/schemas/transcription-config.js +253 -85
  289. package/dist/schemas/transcription.d.ts +3 -3
  290. package/dist/schemas/translate.d.ts +2 -2
  291. package/dist/schemas/translate.js +1 -1
  292. package/dist/schemas/translation-config.js +53 -25
  293. package/dist/schemas/vla.d.ts +1 -1
  294. package/dist/selection.d.ts +1 -5
  295. package/dist/selection.js +2 -6
  296. package/dist/surface.d.ts +1 -1
  297. package/dist/utils/aggregate-events.d.ts +1 -1
  298. package/dist/utils/aggregate-events.js +2 -2
  299. package/dist/utils/archive.js +2 -2
  300. package/dist/utils/audio-input.js +1 -1
  301. package/dist/utils/cache/auto-history.d.ts +1 -1
  302. package/dist/utils/cache/auto-history.js +1 -1
  303. package/dist/utils/cache/paths.js +5 -5
  304. package/dist/utils/completion-normalizer.js +1 -1
  305. package/dist/utils/gguf-tensor-extractor.js +1 -1
  306. package/dist/utils/image-dimensions.d.ts +26 -0
  307. package/dist/utils/image-dimensions.js +46 -0
  308. package/dist/utils/index.d.ts +13 -10
  309. package/dist/utils/index.js +13 -10
  310. package/dist/utils/mcp-adapter.d.ts +1 -1
  311. package/dist/utils/mcp-adapter.js +1 -1
  312. package/dist/utils/path-sanitize.d.ts +7 -0
  313. package/dist/utils/path-sanitize.js +36 -0
  314. package/dist/utils/path-security.d.ts +0 -7
  315. package/dist/utils/path-security.js +1 -36
  316. package/dist/utils/shard-utils.js +3 -3
  317. package/dist/utils/tool-integration.js +1 -1
  318. package/dist/utils/tools/dialect.js +1 -1
  319. package/dist/utils/tools/index.d.ts +2 -2
  320. package/dist/utils/tools/index.js +2 -2
  321. package/dist/utils/tools/parser.js +8 -8
  322. package/dist/utils/tools/parsers/dsml.d.ts +1 -1
  323. package/dist/utils/tools/parsers/dsml.js +1 -1
  324. package/dist/utils/tools/parsers/gemma4native.d.ts +1 -1
  325. package/dist/utils/tools/parsers/gemma4native.js +1 -1
  326. package/dist/utils/tools/parsers/harmony.d.ts +1 -1
  327. package/dist/utils/tools/parsers/harmony.js +1 -1
  328. package/dist/utils/tools/parsers/hermes.d.ts +1 -1
  329. package/dist/utils/tools/parsers/hermes.js +1 -1
  330. package/dist/utils/tools/parsers/json.d.ts +1 -1
  331. package/dist/utils/tools/parsers/json.js +1 -1
  332. package/dist/utils/tools/parsers/pythonic.d.ts +1 -1
  333. package/dist/utils/tools/parsers/pythonic.js +1 -1
  334. package/dist/utils/tools/parsers/qwen35.d.ts +1 -1
  335. package/dist/utils/tools/parsers/qwen35.js +3 -3
  336. package/dist/utils/url-security.d.ts +17 -0
  337. package/dist/utils/url-security.js +75 -0
  338. package/package.json +31 -26
  339. package/dist/api/provide.d.ts +0 -23
  340. package/dist/api/provide.js +0 -32
  341. package/dist/api/stop-provider.d.ts +0 -20
  342. package/dist/api/stop-provider.js +0 -30
  343. package/dist/p2p/cancel-delegated.d.ts +0 -3
  344. package/dist/p2p/cancel-delegated.js +0 -64
  345. package/dist/p2p/completion-stream-delegated.d.ts +0 -4
  346. package/dist/p2p/completion-stream-delegated.js +0 -51
  347. package/dist/p2p/delegate-client.d.ts +0 -9
  348. package/dist/p2p/delegate-client.js +0 -219
  349. package/dist/p2p/delegate-connect-diagnostics.d.ts +0 -8
  350. package/dist/p2p/delegate-connect-diagnostics.js +0 -38
  351. package/dist/p2p/delegate-transport.d.ts +0 -18
  352. package/dist/p2p/delegate-transport.js +0 -237
  353. package/dist/p2p/error-handlers.d.ts +0 -4
  354. package/dist/p2p/error-handlers.js +0 -31
  355. package/dist/p2p/handle-request.d.ts +0 -2
  356. package/dist/p2p/handle-request.js +0 -171
  357. package/dist/p2p/handler-utils.d.ts +0 -19
  358. package/dist/p2p/handler-utils.js +0 -180
  359. package/dist/p2p/heartbeat-delegated.d.ts +0 -3
  360. package/dist/p2p/heartbeat-delegated.js +0 -32
  361. package/dist/p2p/load-model-delegated.d.ts +0 -6
  362. package/dist/p2p/load-model-delegated.js +0 -132
  363. package/dist/p2p/progress-throttle.d.ts +0 -7
  364. package/dist/p2p/progress-throttle.js +0 -47
  365. package/dist/p2p/provideHandler/connection.d.ts +0 -2
  366. package/dist/p2p/provideHandler/connection.js +0 -38
  367. package/dist/p2p/provideHandler/handler.d.ts +0 -2
  368. package/dist/p2p/provideHandler/handler.js +0 -66
  369. package/dist/p2p/provideHandler/proxy.d.ts +0 -2
  370. package/dist/p2p/provideHandler/proxy.js +0 -24
  371. package/dist/p2p/provideHandler.d.ts +0 -1
  372. package/dist/p2p/provideHandler.js +0 -2
  373. package/dist/p2p/rpc-utils.d.ts +0 -4
  374. package/dist/p2p/rpc-utils.js +0 -8
  375. package/dist/p2p/stopProvideHandler.d.ts +0 -2
  376. package/dist/p2p/stopProvideHandler.js +0 -29
  377. package/dist/p2p/swarm.d.ts +0 -9
  378. package/dist/p2p/swarm.js +0 -103
  379. package/dist/p2p/transport-selector.d.ts +0 -2
  380. package/dist/p2p/transport-selector.js +0 -18
  381. package/dist/p2p/unload-model-delegated.d.ts +0 -2
  382. package/dist/p2p/unload-model-delegated.js +0 -31
  383. package/dist/profiling/delegation-profiler.d.ts +0 -31
  384. package/dist/profiling/delegation-profiler.js +0 -155
  385. package/dist/schemas/delegate.d.ts +0 -29
  386. package/dist/schemas/delegate.js +0 -40
  387. package/dist/schemas/provide.d.ts +0 -50
  388. package/dist/schemas/provide.js +0 -32
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qvac/inference",
3
- "version": "0.18.2",
3
+ "version": "0.19.0",
4
4
  "description": "Bare-only in-process core of the QVAC SDK. Runs inference directly on the Bare runtime with explicit plugin assembly and no RPC, worker, or subprocess layer.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -82,6 +82,10 @@
82
82
  "types": "./dist/models/registry/index.d.ts",
83
83
  "import": "./dist/models/registry/index.js"
84
84
  },
85
+ "./model-resource-profiles": {
86
+ "types": "./dist/models/registry/resource-profiles.d.ts",
87
+ "import": "./dist/models/registry/resource-profiles.js"
88
+ },
85
89
  "./llamacpp-completion/plugin": {
86
90
  "types": "./dist/plugins/builtin/llamacpp-completion/plugin.d.ts",
87
91
  "import": "./dist/plugins/builtin/llamacpp-completion/plugin.js"
@@ -151,7 +155,7 @@
151
155
  "test": "npm run build:test && brittle-bare 'test/dist/test/**/*.test.js'",
152
156
  "test:bare": "npm run test",
153
157
  "check-models": "bare ./dist/models/update-models/index.js --check",
154
- "update-models": "bare ./dist/models/update-models/index.js && prettier --write src/models/registry/models.ts"
158
+ "update-models": "bare ./dist/models/update-models/index.js && prettier --write src/models/registry/models.ts src/models/registry/resource-profiles.ts"
155
159
  },
156
160
  "engines": {
157
161
  "bare": "^1.30.3"
@@ -159,16 +163,17 @@
159
163
  "dependencies": {
160
164
  "@qvac/error": "^0.1.1",
161
165
  "@qvac/logging": "^0.1.1",
162
- "@qvac/rag": "^0.6.4",
166
+ "@qvac/rag": "^0.8.0",
163
167
  "@qvac/registry-client": "^0.6.1",
164
168
  "bare-abort-controller": "^1.1.2",
165
169
  "bare-buffer": "^3.6.2",
166
170
  "bare-cpu-info": "0.1.1",
167
171
  "bare-crypto": "^1.15.3",
168
172
  "bare-env": "^3.0.1",
169
- "bare-fetch": "^3.0.1",
170
173
  "bare-fs": "^4.7.4",
171
174
  "bare-gpu-info": "0.1.1",
175
+ "bare-http1": "^4.5.9",
176
+ "bare-https": "^3.0.0",
172
177
  "bare-os": "^3.9.3",
173
178
  "bare-path": "^3.1.1",
174
179
  "bare-rpc": "^1.3.8",
@@ -185,19 +190,19 @@
185
190
  "zod": "^4.4.3"
186
191
  },
187
192
  "peerDependencies": {
188
- "@qvac/asr-ggml": "^0.3.0",
189
- "@qvac/audiogen-ggml": "^0.2.1",
190
- "@qvac/bci-whispercpp": "^0.7.1",
191
- "@qvac/classification-ggml": "^0.20.0",
193
+ "@qvac/asr-ggml": "^0.3.1",
194
+ "@qvac/audiogen-ggml": "^0.3.2",
195
+ "@qvac/bci-whispercpp": "^0.8.0",
196
+ "@qvac/classification-ggml": "^0.23.0",
192
197
  "@qvac/decoder-audio": "^0.5.0",
193
- "@qvac/diffusion-cpp": "^0.18.0",
194
- "@qvac/embed-llamacpp": "^0.34.0",
198
+ "@qvac/diffusion-cpp": "^0.21.0",
199
+ "@qvac/embed-llamacpp": "^0.37.0",
195
200
  "@qvac/langdetect-text": "^0.1.2",
196
- "@qvac/llm-llamacpp": "^0.45.0",
197
- "@qvac/ocr-ggml": "^0.18.0",
198
- "@qvac/translation-nmtcpp": "^0.10.0",
199
- "@qvac/tts-ggml": "^0.7.4",
200
- "@qvac/vla-ggml": "^0.21.1"
201
+ "@qvac/llm-llamacpp": "^0.49.1",
202
+ "@qvac/ocr-ggml": "^0.21.0",
203
+ "@qvac/translation-nmtcpp": "^0.13.0",
204
+ "@qvac/tts-ggml": "^0.8.0",
205
+ "@qvac/vla-ggml": "^0.24.0"
201
206
  },
202
207
  "peerDependenciesMeta": {
203
208
  "@qvac/asr-ggml": {
@@ -241,19 +246,19 @@
241
246
  }
242
247
  },
243
248
  "devDependencies": {
244
- "@qvac/asr-ggml": "^0.3.0",
245
- "@qvac/audiogen-ggml": "^0.2.1",
246
- "@qvac/bci-whispercpp": "^0.7.1",
247
- "@qvac/classification-ggml": "^0.20.0",
249
+ "@qvac/asr-ggml": "^0.3.1",
250
+ "@qvac/audiogen-ggml": "^0.3.2",
251
+ "@qvac/bci-whispercpp": "^0.8.0",
252
+ "@qvac/classification-ggml": "^0.23.0",
248
253
  "@qvac/decoder-audio": "^0.5.0",
249
- "@qvac/diffusion-cpp": "^0.18.0",
250
- "@qvac/embed-llamacpp": "^0.34.0",
254
+ "@qvac/diffusion-cpp": "^0.21.0",
255
+ "@qvac/embed-llamacpp": "^0.37.0",
251
256
  "@qvac/langdetect-text": "^0.1.2",
252
- "@qvac/llm-llamacpp": "^0.45.0",
253
- "@qvac/ocr-ggml": "^0.18.0",
254
- "@qvac/translation-nmtcpp": "^0.10.0",
255
- "@qvac/tts-ggml": "^0.7.4",
256
- "@qvac/vla-ggml": "^0.21.1",
257
+ "@qvac/llm-llamacpp": "^0.49.1",
258
+ "@qvac/ocr-ggml": "^0.21.0",
259
+ "@qvac/translation-nmtcpp": "^0.13.0",
260
+ "@qvac/tts-ggml": "^0.8.0",
261
+ "@qvac/vla-ggml": "^0.24.0",
257
262
  "@types/brittle": "^3.5.0",
258
263
  "bare": "*",
259
264
  "bare-console": "*",
@@ -1,23 +0,0 @@
1
- import { type ProvideParams } from '../schemas/index.js';
2
- /**
3
- * Starts a provider service that offers QVAC capabilities to remote peers.
4
- *
5
- * Consumers connect directly to the provider via its public key using
6
- * `dht.connect(publicKey)`, so no topic or discovery configuration is needed.
7
- * The provider's keypair (and therefore its public key) can be controlled via
8
- * the `QVAC_HYPERSWARM_SEED` environment variable.
9
- *
10
- * Idempotent: calling more than once while a provider is already running
11
- * returns the same public key without re-listening on the DHT.
12
- *
13
- * @param params - Options object with optional firewall config
14
- * @param params.firewall - Optional firewall configuration to allow/deny specific public keys
15
- * @returns A promise that resolves to the provide response containing success status and public key
16
- * @throws {QvacErrorBase} When the response type is not "provide" or the request fails
17
- */
18
- export declare function startQVACProvider(params?: ProvideParams): Promise<{
19
- type: "provide";
20
- success: boolean;
21
- error?: string | undefined;
22
- publicKey?: string | undefined;
23
- }>;
@@ -1,32 +0,0 @@
1
- import { send } from '../dispatch.js';
2
- import { InvalidResponseError, ProviderStartFailedError } from '../errors/index.js';
3
- /**
4
- * Starts a provider service that offers QVAC capabilities to remote peers.
5
- *
6
- * Consumers connect directly to the provider via its public key using
7
- * `dht.connect(publicKey)`, so no topic or discovery configuration is needed.
8
- * The provider's keypair (and therefore its public key) can be controlled via
9
- * the `QVAC_HYPERSWARM_SEED` environment variable.
10
- *
11
- * Idempotent: calling more than once while a provider is already running
12
- * returns the same public key without re-listening on the DHT.
13
- *
14
- * @param params - Options object with optional firewall config
15
- * @param params.firewall - Optional firewall configuration to allow/deny specific public keys
16
- * @returns A promise that resolves to the provide response containing success status and public key
17
- * @throws {QvacErrorBase} When the response type is not "provide" or the request fails
18
- */
19
- export async function startQVACProvider(params = {}) {
20
- const request = {
21
- type: 'provide',
22
- firewall: params.firewall
23
- };
24
- const response = await send(request);
25
- if (response.type !== 'provide') {
26
- throw new InvalidResponseError('provide');
27
- }
28
- if (response.error) {
29
- throw new ProviderStartFailedError(response.error);
30
- }
31
- return response;
32
- }
@@ -1,20 +0,0 @@
1
- /**
2
- * Stops the running provider service.
3
- *
4
- * After this call returns, incoming peer connections are dropped at the RPC
5
- * layer and remote `loadModel`/`completion`/etc. requests will no longer be
6
- * served. The keyPair stays bound on the DHT (a `swarm.listen()` cannot be
7
- * undone without tearing down the shared swarm), so peers may still open a
8
- * raw socket — but those sockets are immediately destroyed and no RPC server
9
- * is mounted on them.
10
- *
11
- * Idempotent: calling more than once with no provider running is a no-op.
12
- *
13
- * @returns A promise that resolves to the stop provide response containing success status
14
- * @throws {QvacErrorBase} When the response type is not "stopProvide" or the request fails
15
- */
16
- export declare function stopQVACProvider(): Promise<{
17
- type: "stopProvide";
18
- success: boolean;
19
- error?: string | undefined;
20
- }>;
@@ -1,30 +0,0 @@
1
- import { send } from '../dispatch.js';
2
- import { InvalidResponseError, ProviderStopFailedError } from '../errors/index.js';
3
- /**
4
- * Stops the running provider service.
5
- *
6
- * After this call returns, incoming peer connections are dropped at the RPC
7
- * layer and remote `loadModel`/`completion`/etc. requests will no longer be
8
- * served. The keyPair stays bound on the DHT (a `swarm.listen()` cannot be
9
- * undone without tearing down the shared swarm), so peers may still open a
10
- * raw socket — but those sockets are immediately destroyed and no RPC server
11
- * is mounted on them.
12
- *
13
- * Idempotent: calling more than once with no provider running is a no-op.
14
- *
15
- * @returns A promise that resolves to the stop provide response containing success status
16
- * @throws {QvacErrorBase} When the response type is not "stopProvide" or the request fails
17
- */
18
- export async function stopQVACProvider() {
19
- const request = {
20
- type: 'stopProvide'
21
- };
22
- const response = await send(request);
23
- if (response.type !== 'stopProvide') {
24
- throw new InvalidResponseError('stopProvide');
25
- }
26
- if (response.error) {
27
- throw new ProviderStopFailedError(response.error);
28
- }
29
- return response;
30
- }
@@ -1,3 +0,0 @@
1
- import type { CancelRequest, CancelResponse } from '../schemas/cancel.js';
2
- import type { DelegatedHandlerOptions } from '../profiling/index.js';
3
- export declare function handleCancelDelegated(request: CancelRequest, options?: DelegatedHandlerOptions): Promise<CancelResponse>;
@@ -1,64 +0,0 @@
1
- import { getEngineLogger } from '../logging/index.js';
2
- import { getModelEntry } from '../runtime/model-registry.js';
3
- import { getRPC } from '../p2p/delegate-client.js';
4
- import { send } from '../p2p/delegate-transport.js';
5
- const logger = getEngineLogger();
6
- /**
7
- * Resolve the delegated provider for a cancel request, if any.
8
- *
9
- * The cancel envelope has two operations. Only `broad` cancels delegate
10
- * at the cancel layer — see `isCancelDelegated` in `handler-registry.ts`
11
- * for the policy and the rationale.
12
- *
13
- * The targeted `request` arm is handled locally because the registry
14
- * is process-singleton and already holds the entry for delegated
15
- * requests (the delegated handler registers its own context on the
16
- * provider-facing side). To cancel a specific delegated request, hold
17
- * onto the delegated `loadModel(...).requestId` and fire a broad cancel
18
- * against the model id instead.
19
- */
20
- function resolveDelegationTarget(request) {
21
- if (request.operation !== 'broad')
22
- return null;
23
- const entry = getModelEntry(request.modelId);
24
- if (!entry?.isDelegated)
25
- return null;
26
- const target = {
27
- providerPublicKey: entry.delegated.providerPublicKey
28
- };
29
- if (entry.delegated.timeout !== undefined) {
30
- target.timeout = entry.delegated.timeout;
31
- }
32
- return target;
33
- }
34
- export async function handleCancelDelegated(request, options) {
35
- const target = resolveDelegationTarget(request);
36
- if (!target) {
37
- logger.warn(`Delegated cancel skipped (no delegation target): operation=${request.operation}`);
38
- return { type: 'cancel', success: true };
39
- }
40
- try {
41
- const rpc = await getRPC(target.providerPublicKey, {
42
- timeout: target.timeout
43
- });
44
- const delegateOpts = {
45
- peerKey: target.providerPublicKey
46
- };
47
- if (target.timeout !== undefined) {
48
- delegateOpts.timeout = target.timeout;
49
- }
50
- if (options?.profilingMeta) {
51
- delegateOpts.profilingMeta = options.profilingMeta;
52
- }
53
- await send(request, rpc, delegateOpts);
54
- return { type: 'cancel', success: true };
55
- }
56
- catch (error) {
57
- logger.error('Error during delegated cancellation:', error);
58
- return {
59
- type: 'cancel',
60
- success: false,
61
- error: error instanceof Error ? error.message : 'Unknown error'
62
- };
63
- }
64
- }
@@ -1,4 +0,0 @@
1
- import type { CompletionStreamRequest, CompletionStreamResponse } from '../schemas/index.js';
2
- import type { DelegatedHandlerOptions } from '../profiling/index.js';
3
- export type HandleCompletionStreamDelegatedOptions = DelegatedHandlerOptions;
4
- export declare function handleCompletionStreamDelegated(request: CompletionStreamRequest, options?: HandleCompletionStreamDelegatedOptions): AsyncGenerator<CompletionStreamResponse>;
@@ -1,51 +0,0 @@
1
- import { getModelEntry } from '../runtime/model-registry.js';
2
- import { getRPC } from '../p2p/delegate-client.js';
3
- import { stream } from '../p2p/delegate-transport.js';
4
- import { ModelIsDelegatedError } from '../errors/index.js';
5
- import { getEngineLogger } from '../logging/index.js';
6
- const logger = getEngineLogger();
7
- export async function* handleCompletionStreamDelegated(request, options) {
8
- const { profilingMeta } = options ?? {};
9
- // Get delegation info from model registry
10
- const entry = getModelEntry(request.modelId);
11
- if (!entry?.isDelegated) {
12
- throw new ModelIsDelegatedError(request.modelId);
13
- }
14
- const { providerPublicKey, timeout, healthCheckTimeout } = entry.delegated;
15
- try {
16
- logger.debug(`📤 Sending delegated completionStream request to provider: ${providerPublicKey}${timeout ? `, timeout: ${timeout}ms` : ''}`);
17
- const rpc = await getRPC(providerPublicKey, { timeout, healthCheckTimeout });
18
- // Build delegate options with profiling metadata
19
- const delegateOpts = { peerKey: providerPublicKey };
20
- if (profilingMeta) {
21
- delegateOpts.profilingMeta = profilingMeta;
22
- }
23
- if (timeout) {
24
- delegateOpts.timeout = timeout;
25
- }
26
- // Use the regular stream function with the HyperSwarm RPC instance
27
- const responseStream = stream(request, rpc, delegateOpts);
28
- // Yield each response from the stream
29
- for await (const response of responseStream) {
30
- yield response;
31
- }
32
- }
33
- catch (error) {
34
- logger.error('Error in delegated completion stream:', error);
35
- const message = error instanceof Error ? error.message : String(error);
36
- yield {
37
- type: 'completionStream',
38
- done: true,
39
- events: [
40
- {
41
- type: 'completionDone',
42
- seq: 0,
43
- stopReason: 'error',
44
- error: {
45
- message: `Error communicating with provider: ${message}`
46
- }
47
- }
48
- ]
49
- };
50
- }
51
- }
@@ -1,9 +0,0 @@
1
- import RPC from 'bare-rpc';
2
- import type { RPCOptions } from '../schemas/index.js';
3
- export declare function getRPC(publicKey: string, options?: RPCOptions): Promise<RPC>;
4
- /**
5
- * Remove a stale RPC connection for a peer.
6
- * Called when a delegation request fails (e.g., timeout) so the next
7
- * attempt creates a fresh connection instead of reusing a dead RPC.
8
- */
9
- export declare function cleanupStaleConnection(publicKey: string): void;
@@ -1,219 +0,0 @@
1
- import { getSwarm } from '../p2p/swarm.js';
2
- import { getConfig } from '../runtime/state.js';
3
- import { ensureDhtBootstrapped, describeConnectFailure } from '../p2p/delegate-connect-diagnostics.js';
4
- import RPC from 'bare-rpc';
5
- import { withTimeout } from '../utils/withTimeout.js';
6
- import { DelegateConnectionFailedError } from '../errors/index.js';
7
- import { getEngineLogger } from '../logging/index.js';
8
- import { nowMs } from '../profiling/index.js';
9
- import { cacheDelegationConnectionTime, clearPeerConnectionTracking } from '../profiling/delegation-profiler.js';
10
- import { getNextCommandId } from '../p2p/rpc-utils.js';
11
- import { Buffer } from 'bare-buffer';
12
- const logger = getEngineLogger();
13
- const activeRPCs = new Map();
14
- const activeConnections = new Map();
15
- // In-flight `ensureRPCConnection` promises keyed by peer. Concurrent
16
- // `getRPC(publicKey)` callers (without `forceNewConnection`) join the same
17
- // promise instead of each running their own bootstrap+connect, which would
18
- // open multiple sockets, clobber the active maps, and leak the loser.
19
- const inflightConnections = new Map();
20
- const HEALTH_CHECK_TIMEOUT_MS = 1500;
21
- function getConfiguredRelayCount() {
22
- return getConfig().swarmRelays?.length ?? 0;
23
- }
24
- function isHeartbeatResponse(payload) {
25
- return (typeof payload === 'object' &&
26
- payload !== null &&
27
- payload['type'] === 'heartbeat');
28
- }
29
- async function isRPCConnectionHealthy(rpc, timeout = HEALTH_CHECK_TIMEOUT_MS) {
30
- try {
31
- const req = rpc.request(getNextCommandId());
32
- req.send(JSON.stringify({ type: 'heartbeat' }), 'utf-8');
33
- const response = await withTimeout(req.reply('utf-8'), timeout);
34
- const payload = JSON.parse(response?.toString() || '{}');
35
- return isHeartbeatResponse(payload);
36
- }
37
- catch (error) {
38
- logger.debug('RPC health check failed', { error });
39
- return false;
40
- }
41
- }
42
- function trackConnection(publicKey, conn, rpc) {
43
- activeRPCs.set(publicKey, rpc);
44
- activeConnections.set(publicKey, conn);
45
- conn.on('close', () => {
46
- logger.debug(`Connection closed for peer: ${publicKey}`);
47
- if (activeConnections.get(publicKey) === conn) {
48
- activeConnections.delete(publicKey);
49
- activeRPCs.delete(publicKey);
50
- clearPeerConnectionTracking(publicKey);
51
- }
52
- });
53
- conn.on('error', (err) => {
54
- logger.error(`Connection error for peer ${publicKey}:`, err);
55
- if (activeConnections.get(publicKey) === conn) {
56
- activeConnections.delete(publicKey);
57
- activeRPCs.delete(publicKey);
58
- clearPeerConnectionTracking(publicKey);
59
- }
60
- });
61
- }
62
- async function closeConnection(publicKey) {
63
- const existingConnection = activeConnections.get(publicKey);
64
- if (!existingConnection)
65
- return;
66
- logger.info(`🔌 Closing existing connection for peer: ${publicKey}`);
67
- // Wait for the close event before returning so any pending cleanup
68
- // in the underlying DHT stream completes before we reconnect.
69
- await new Promise((resolve) => {
70
- existingConnection.once('close', () => resolve());
71
- existingConnection.destroy();
72
- });
73
- if (activeConnections.get(publicKey) === existingConnection) {
74
- activeConnections.delete(publicKey);
75
- activeRPCs.delete(publicKey);
76
- clearPeerConnectionTracking(publicKey);
77
- }
78
- }
79
- // Open a direct DHT connection to a peer by public key. Bypasses topic
80
- // discovery entirely — we already know who we're talking to, so we skip
81
- // swarm.join()/flush() and let the DHT route by public key.
82
- function openDhtConnection(publicKey) {
83
- const swarm = getSwarm();
84
- const relayThrough = swarm.relayThrough ? swarm.relayThrough(false, swarm) : null;
85
- return swarm.dht.connect(Buffer.from(publicKey, 'hex'), {
86
- keyPair: swarm.keyPair,
87
- relayThrough
88
- });
89
- }
90
- // Resolve when the DHT connection emits "open"; reject promptly on "error"
91
- // or "close" so firewall-rejected / abruptly-closed connects fail fast
92
- // instead of dragging out the full delegate timeout (60s on cold paths).
93
- function waitForOpen(conn, timeout) {
94
- const opened = new Promise((resolve, reject) => {
95
- const cleanup = () => {
96
- conn.removeListener('open', onOpen);
97
- conn.removeListener('error', onError);
98
- conn.removeListener('close', onClose);
99
- };
100
- const onOpen = () => {
101
- cleanup();
102
- resolve();
103
- };
104
- const onError = (err) => {
105
- cleanup();
106
- reject(err);
107
- };
108
- const onClose = () => {
109
- cleanup();
110
- reject(new DelegateConnectionFailedError('Connection closed before open (peer unreachable or rejected by firewall)'));
111
- };
112
- conn.once('open', onOpen);
113
- conn.once('error', onError);
114
- conn.once('close', onClose);
115
- });
116
- return withTimeout(opened, timeout);
117
- }
118
- async function ensureRPCConnection(publicKey, timeout, healthCheckTimeout) {
119
- const healthCheckCap = healthCheckTimeout ?? HEALTH_CHECK_TIMEOUT_MS;
120
- const operationStart = nowMs();
121
- const getRemainingTimeout = () => {
122
- if (timeout === undefined)
123
- return undefined;
124
- return Math.max(timeout - (nowMs() - operationStart), 0);
125
- };
126
- const existingRpc = activeRPCs.get(publicKey);
127
- if (existingRpc) {
128
- const remainingTimeout = getRemainingTimeout();
129
- const probeTimeout = remainingTimeout === undefined
130
- ? healthCheckCap
131
- : Math.min(remainingTimeout / 2, healthCheckCap);
132
- const isHealthy = await isRPCConnectionHealthy(existingRpc, probeTimeout);
133
- if (isHealthy) {
134
- return existingRpc;
135
- }
136
- logger.info(`🧹 Cached RPC failed health check for peer ${publicKey}, reconnecting`);
137
- cleanupStaleConnection(publicKey);
138
- }
139
- const connectionStart = nowMs();
140
- let conn;
141
- const relayCount = getConfiguredRelayCount();
142
- try {
143
- logger.info(`🔗 Establishing direct DHT connection to peer: ${publicKey}${timeout ? `, timeout: ${timeout}ms` : ''} (${relayCount} swarm relay(s) configured)`);
144
- await ensureDhtBootstrapped(getSwarm().dht, getRemainingTimeout());
145
- conn = openDhtConnection(publicKey);
146
- await waitForOpen(conn, getRemainingTimeout());
147
- logger.info(`🍺 Peer connection opened: ${publicKey}`);
148
- const rpc = new RPC(conn, () => {
149
- // No-op handler since we're only sending requests, not receiving them
150
- });
151
- trackConnection(publicKey, conn, rpc);
152
- const connectionDuration = nowMs() - connectionStart;
153
- cacheDelegationConnectionTime(publicKey, connectionDuration);
154
- return rpc;
155
- }
156
- catch (error) {
157
- if (conn && !conn.destroyed) {
158
- conn.destroy();
159
- }
160
- cleanupStaleConnection(publicKey);
161
- logger.error('Failed to establish RPC connection:', error);
162
- throw new DelegateConnectionFailedError(`RPC connection failed: ${describeConnectFailure(error, publicKey, relayCount)}`, error);
163
- }
164
- }
165
- // Create an RPC instance for a specific HyperSwarm peer.
166
- // Connects directly via the DHT using the peer's public key — no topic
167
- // discovery required.
168
- //
169
- // Concurrent calls for the same peer share a single in-flight bootstrap +
170
- // connect operation, but each caller still gets its own `timeout` enforced
171
- // against the shared promise (via `withTimeout`) — so a fast caller that
172
- // gives up at 5s does not block a slow caller waiting up to 60s.
173
- //
174
- // `forceNewConnection` always tears down the existing socket first and
175
- // starts a fresh attempt outside the shared promise.
176
- export async function getRPC(publicKey, options = {}) {
177
- if (options.forceNewConnection) {
178
- await closeConnection(publicKey);
179
- return await ensureRPCConnection(publicKey, options.timeout, options.healthCheckTimeout);
180
- }
181
- let inflight = inflightConnections.get(publicKey);
182
- if (!inflight) {
183
- inflight = ensureRPCConnection(publicKey, options.timeout, options.healthCheckTimeout);
184
- const tracked = inflight;
185
- inflightConnections.set(publicKey, tracked);
186
- // Clear the inflight entry on settle. We register a single combined
187
- // settle handler via `then(handler, handler)` so that on rejection the
188
- // failure is *observed* on `tracked` itself — using `tracked.finally(...)`
189
- // returns a fresh promise that re-rejects with the original error, and
190
- // since nothing awaits that fresh promise it would surface as an
191
- // unhandled rejection. The process treats unhandled rejections as fatal
192
- // and tears down the swarm + cancels all in-flight downloads, which then
193
- // breaks the legitimate fallback-to-local path that the caller awaits via
194
- // `withTimeout(inflight, ...)` below. Caller still observes the original
195
- // rejection through `await withTimeout(inflight, ...)`.
196
- const clearInflight = () => {
197
- if (inflightConnections.get(publicKey) === tracked) {
198
- inflightConnections.delete(publicKey);
199
- }
200
- };
201
- tracked.then(clearInflight, clearInflight);
202
- }
203
- return await withTimeout(inflight, options.timeout);
204
- }
205
- /**
206
- * Remove a stale RPC connection for a peer.
207
- * Called when a delegation request fails (e.g., timeout) so the next
208
- * attempt creates a fresh connection instead of reusing a dead RPC.
209
- */
210
- export function cleanupStaleConnection(publicKey) {
211
- logger.info(`🗑️ Removing stale connection for peer: ${publicKey} after failed delegation`);
212
- activeRPCs.delete(publicKey);
213
- const conn = activeConnections.get(publicKey);
214
- if (conn) {
215
- conn.destroy();
216
- activeConnections.delete(publicKey);
217
- }
218
- clearPeerConnectionTracking(publicKey);
219
- }
@@ -1,8 +0,0 @@
1
- export declare const DHT_BOOTSTRAP_WAIT_CAP_MS = 5000;
2
- interface BootstrappableDht {
3
- bootstrapped: boolean;
4
- fullyBootstrapped(): Promise<void>;
5
- }
6
- export declare function ensureDhtBootstrapped(dht: BootstrappableDht, timeout: number | undefined): Promise<void>;
7
- export declare function describeConnectFailure(error: unknown, publicKey: string, relayCount: number): string;
8
- export {};
@@ -1,38 +0,0 @@
1
- import { withTimeout } from '../utils/withTimeout.js';
2
- import { getEngineLogger } from '../logging/index.js';
3
- const logger = getEngineLogger();
4
- export const DHT_BOOTSTRAP_WAIT_CAP_MS = 5000;
5
- // A cold routing table makes findPeer return empty -> spurious PEER_NOT_FOUND,
6
- // so wait for bootstrap, but only when not yet ready to keep warm-path latency.
7
- export async function ensureDhtBootstrapped(dht, timeout) {
8
- if (dht.bootstrapped)
9
- return;
10
- const cap = timeout === undefined ? DHT_BOOTSTRAP_WAIT_CAP_MS : Math.min(timeout, DHT_BOOTSTRAP_WAIT_CAP_MS);
11
- try {
12
- await withTimeout(dht.fullyBootstrapped(), cap);
13
- }
14
- catch (error) {
15
- logger.warn(`DHT not bootstrapped within ${cap}ms before delegated connect; attempting anyway`, { error });
16
- }
17
- }
18
- // Map an opaque DHT connect error onto why the peer was unreachable: not found
19
- // on the DHT vs found-but-un-holepunchable. Relays only bridge after a peer is
20
- // found, so they can never resolve a PEER_NOT_FOUND.
21
- export function describeConnectFailure(error, publicKey, relayCount) {
22
- const code = typeof error === 'object' && error !== null && 'code' in error ? String(error.code) : undefined;
23
- const relayNote = relayCount > 0 ? `${relayCount} swarm relay(s) configured` : 'no swarm relays configured';
24
- switch (code) {
25
- case 'PEER_NOT_FOUND':
26
- return `provider ${publicKey} was not found on the DHT — it may be offline, still bootstrapping, or unreachable from this network. Relays bridge a connection only after the provider is located, so they cannot find an unannounced provider (${relayNote}).`;
27
- case 'PEER_CONNECTION_FAILED':
28
- case 'CANNOT_HOLEPUNCH':
29
- case 'REMOTE_NOT_HOLEPUNCHABLE':
30
- case 'REMOTE_NOT_HOLEPUNCHING':
31
- case 'HOLEPUNCH_ABORTED':
32
- case 'HOLEPUNCH_PROBE_TIMEOUT':
33
- case 'HOLEPUNCH_DOUBLE_RANDOMIZED_NATS':
34
- return `provider ${publicKey} was found but a connection could not be established (NAT/holepunch failure: ${code}; ${relayNote}).`;
35
- default:
36
- return error instanceof Error ? error.message : String(error);
37
- }
38
- }
@@ -1,18 +0,0 @@
1
- /**
2
- * Server-side RPC transport for delegated requests.
3
- *
4
- * This module provides `send` and `stream` functions for server-side
5
- * delegation to remote peers (via HyperSwarm RPC).
6
- */
7
- import type RPC from 'bare-rpc';
8
- import { DELEGATION_BREAKDOWN_KEY, OPERATION_EVENT_KEY, type Request, type Response, type RPCOptions, type DelegationBreakdown, type OperationEvent } from '../schemas/index.js';
9
- import type { DelegatedHandlerOptions } from '../profiling/index.js';
10
- export interface DelegateOptions extends RPCOptions, DelegatedHandlerOptions {
11
- peerKey?: string;
12
- }
13
- export type ResponseWithDelegation = Response & {
14
- [DELEGATION_BREAKDOWN_KEY]?: DelegationBreakdown;
15
- [OPERATION_EVENT_KEY]?: OperationEvent;
16
- };
17
- export declare function send<T extends Request>(request: T, rpc: RPC, options?: DelegateOptions): Promise<Response>;
18
- export declare function stream<T extends Request>(request: T, rpc: RPC, options?: DelegateOptions): AsyncGenerator<Response>;