@qvac/inference 0.18.2 → 0.19.1

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 (396) hide show
  1. package/NOTICE +69 -36
  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/delete-cache.d.ts +7 -1
  10. package/dist/api/delete-cache.js +11 -1
  11. package/dist/api/download-asset.d.ts +1 -1
  12. package/dist/api/download-asset.js +2 -2
  13. package/dist/api/finetune.js +1 -1
  14. package/dist/api/get-loaded-model-info.d.ts +6 -10
  15. package/dist/api/get-loaded-model-info.js +6 -10
  16. package/dist/api/heartbeat.d.ts +5 -22
  17. package/dist/api/heartbeat.js +6 -23
  18. package/dist/api/index.d.ts +36 -35
  19. package/dist/api/index.js +35 -35
  20. package/dist/api/load-model.d.ts +5 -1
  21. package/dist/api/load-model.js +3 -5
  22. package/dist/api/logging-stream-registry.js +1 -1
  23. package/dist/api/resume.d.ts +0 -3
  24. package/dist/api/resume.js +0 -3
  25. package/dist/api/subscribe-logs.js +1 -1
  26. package/dist/api/suspend.d.ts +0 -4
  27. package/dist/api/suspend.js +0 -4
  28. package/dist/api/translate.d.ts +3 -1
  29. package/dist/api/translate.js +16 -8
  30. package/dist/api/unload-model.js +3 -5
  31. package/dist/api/video-request.d.ts +207 -0
  32. package/dist/api/video-request.js +18 -0
  33. package/dist/api/video.d.ts +22 -2
  34. package/dist/api/video.js +25 -15
  35. package/dist/api/vla-helpers.d.ts +1 -2
  36. package/dist/api/vla-helpers.js +1 -2
  37. package/dist/api/vla.js +1 -1
  38. package/dist/api/world-result.d.ts +71 -0
  39. package/dist/api/world-result.js +293 -0
  40. package/dist/api/world.d.ts +143 -0
  41. package/dist/api/world.js +71 -0
  42. package/dist/config/resolve-config.d.ts +1 -1
  43. package/dist/config/resolve-config.js +1 -1
  44. package/dist/constants/index.d.ts +2 -2
  45. package/dist/constants/index.js +2 -2
  46. package/dist/dispatch.js +15 -28
  47. package/dist/errors/index.d.ts +35 -31
  48. package/dist/errors/index.js +66 -56
  49. package/dist/handlers/assess-model-fit.d.ts +10 -0
  50. package/dist/handlers/assess-model-fit.js +75 -0
  51. package/dist/handlers/cancelHandler.js +1 -1
  52. package/dist/handlers/completion-orchestrate.js +1 -1
  53. package/dist/handlers/delete-cache.js +3 -0
  54. package/dist/handlers/download-asset.js +6 -5
  55. package/dist/handlers/finetune.js +1 -1
  56. package/dist/handlers/get-loaded-model-info.js +0 -12
  57. package/dist/handlers/get-model-info.js +1 -1
  58. package/dist/handlers/get-system-resources.js +8 -0
  59. package/dist/handlers/load-model/download-manager.d.ts +1 -1
  60. package/dist/handlers/load-model/download-stats.d.ts +3 -3
  61. package/dist/handlers/load-model/download-stats.js +5 -5
  62. package/dist/handlers/load-model/handler.js +6 -8
  63. package/dist/handlers/load-model/http-verify.d.ts +20 -0
  64. package/dist/handlers/load-model/http-verify.js +54 -0
  65. package/dist/handlers/load-model/http.d.ts +12 -2
  66. package/dist/handlers/load-model/http.js +119 -230
  67. package/dist/handlers/load-model/hyperdrive.d.ts +1 -1
  68. package/dist/handlers/load-model/hyperdrive.js +1 -1
  69. package/dist/handlers/load-model/index.d.ts +2 -2
  70. package/dist/handlers/load-model/index.js +2 -2
  71. package/dist/handlers/load-model/registry-companion-set.d.ts +1 -1
  72. package/dist/handlers/load-model/registry-companion-set.js +1 -1
  73. package/dist/handlers/load-model/registry-download-utils.d.ts +3 -3
  74. package/dist/handlers/load-model/registry-download-utils.js +2 -2
  75. package/dist/handlers/load-model/registry.d.ts +2 -2
  76. package/dist/handlers/load-model/registry.js +4 -4
  77. package/dist/handlers/load-model/resolve-session.d.ts +8 -1
  78. package/dist/handlers/load-model/resolve-session.js +12 -9
  79. package/dist/handlers/load-model/resolve.d.ts +4 -4
  80. package/dist/handlers/load-model/resolve.js +18 -16
  81. package/dist/handlers/load-model/safe-fetch.d.ts +44 -0
  82. package/dist/handlers/load-model/safe-fetch.js +143 -0
  83. package/dist/handlers/load-model/types.d.ts +9 -0
  84. package/dist/handlers/plugin-dispatch.js +1 -4
  85. package/dist/handlers/plugin-invoke.js +1 -4
  86. package/dist/handlers/types.d.ts +0 -2
  87. package/dist/handlers/unload-model.js +1 -4
  88. package/dist/index.d.ts +1 -1
  89. package/dist/index.js +1 -1
  90. package/dist/logging/addon.d.ts +1 -1
  91. package/dist/logging/addon.js +1 -1
  92. package/dist/logging/index.d.ts +5 -5
  93. package/dist/logging/index.js +4 -4
  94. package/dist/logging/logger.d.ts +1 -1
  95. package/dist/logging/logger.js +2 -2
  96. package/dist/models/registry/index.d.ts +1 -1
  97. package/dist/models/registry/index.js +2 -2
  98. package/dist/models/registry/models.d.ts +250 -0
  99. package/dist/models/registry/models.js +2071 -1806
  100. package/dist/models/registry/resource-profiles.d.ts +18 -0
  101. package/dist/models/registry/resource-profiles.js +4934 -0
  102. package/dist/plugins/builtin/audiogen-ggml/config.d.ts +14 -0
  103. package/dist/plugins/builtin/audiogen-ggml/config.js +23 -0
  104. package/dist/plugins/builtin/audiogen-ggml/ops/audio-gen-stream.js +47 -5
  105. package/dist/plugins/builtin/audiogen-ggml/plugin.d.ts +134 -4
  106. package/dist/plugins/builtin/audiogen-ggml/plugin.js +47 -28
  107. package/dist/plugins/builtin/bci-whispercpp-transcription/plugin.d.ts +1 -1
  108. package/dist/plugins/builtin/bci-whispercpp-transcription/plugin.js +3 -3
  109. package/dist/plugins/builtin/ggml-classification/plugin.js +1 -1
  110. package/dist/plugins/builtin/ggml-ocr/plugin.js +2 -2
  111. package/dist/plugins/builtin/ggml-vla/plugin.d.ts +1 -1
  112. package/dist/plugins/builtin/ggml-vla/plugin.js +3 -3
  113. package/dist/plugins/builtin/index.d.ts +12 -12
  114. package/dist/plugins/builtin/index.js +12 -12
  115. package/dist/plugins/builtin/llamacpp-completion/ops/batch-completion-stream.js +2 -2
  116. package/dist/plugins/builtin/llamacpp-completion/ops/completion-stats.d.ts +1 -0
  117. package/dist/plugins/builtin/llamacpp-completion/ops/completion-stats.js +3 -0
  118. package/dist/plugins/builtin/llamacpp-completion/ops/completion-stream.js +37 -26
  119. package/dist/plugins/builtin/llamacpp-completion/ops/context-overflow.d.ts +12 -11
  120. package/dist/plugins/builtin/llamacpp-completion/ops/context-overflow.js +133 -41
  121. package/dist/plugins/builtin/llamacpp-completion/ops/kv-cache-session.d.ts +15 -4
  122. package/dist/plugins/builtin/llamacpp-completion/ops/kv-cache-session.js +79 -17
  123. package/dist/plugins/builtin/llamacpp-completion/plugin.d.ts +22 -8
  124. package/dist/plugins/builtin/llamacpp-completion/plugin.js +10 -13
  125. package/dist/plugins/builtin/llamacpp-embedding/plugin.d.ts +4 -0
  126. package/dist/plugins/builtin/llamacpp-embedding/plugin.js +13 -2
  127. package/dist/plugins/builtin/nmtcpp-translation/plugin.js +2 -2
  128. package/dist/plugins/builtin/parakeet-transcription/plugin.d.ts +2 -2
  129. package/dist/plugins/builtin/parakeet-transcription/plugin.js +3 -3
  130. package/dist/plugins/builtin/sdcpp-generation/ops/upscale.js +1 -1
  131. package/dist/plugins/builtin/sdcpp-generation/ops/video.js +32 -2
  132. package/dist/plugins/builtin/sdcpp-generation/ops/world.d.ts +126 -0
  133. package/dist/plugins/builtin/sdcpp-generation/ops/world.js +820 -0
  134. package/dist/plugins/builtin/sdcpp-generation/plugin.d.ts +153 -4
  135. package/dist/plugins/builtin/sdcpp-generation/plugin.js +134 -13
  136. package/dist/plugins/builtin/tts-ggml/ops/text-to-speech-stream.js +1 -1
  137. package/dist/plugins/builtin/tts-ggml/ops/text-to-speech.js +1 -1
  138. package/dist/plugins/builtin/tts-ggml/plugin.js +2 -2
  139. package/dist/plugins/builtin/whispercpp-transcription/plugin.d.ts +2 -2
  140. package/dist/plugins/builtin/whispercpp-transcription/plugin.js +3 -3
  141. package/dist/plugins/index.d.ts +1 -1
  142. package/dist/plugins/index.js +2 -2
  143. package/dist/plugins/ops/kv-cache-utils.js +1 -1
  144. package/dist/plugins/ops/load-model.js +1 -1
  145. package/dist/plugins/ops/transcribe.js +2 -2
  146. package/dist/plugins/ops/translate.js +4 -12
  147. package/dist/plugins/ops/unload-model.js +19 -21
  148. package/dist/plugins/registry.d.ts +1 -0
  149. package/dist/plugins/registry.js +12 -0
  150. package/dist/profiling/aggregator.d.ts +1 -1
  151. package/dist/profiling/aggregator.js +1 -1
  152. package/dist/profiling/controller.d.ts +1 -1
  153. package/dist/profiling/controller.js +2 -2
  154. package/dist/profiling/envelope.d.ts +0 -1
  155. package/dist/profiling/envelope.js +0 -10
  156. package/dist/profiling/events.d.ts +2 -3
  157. package/dist/profiling/events.js +2 -9
  158. package/dist/profiling/exporters.d.ts +1 -1
  159. package/dist/profiling/exporters.js +3 -3
  160. package/dist/profiling/index.d.ts +13 -14
  161. package/dist/profiling/index.js +12 -13
  162. package/dist/profiling/operation-metrics.d.ts +1 -1
  163. package/dist/profiling/operation-metrics.js +35 -2
  164. package/dist/profiling/operation-wrappers.js +12 -15
  165. package/dist/profiling/profiler.d.ts +1 -2
  166. package/dist/profiling/profiler.js +7 -26
  167. package/dist/profiling/types.d.ts +1 -1
  168. package/dist/rag/handler.js +1 -1
  169. package/dist/rag/handlers/close-workspace.js +1 -1
  170. package/dist/rag/handlers/delete-embeddings.js +1 -1
  171. package/dist/rag/handlers/delete-workspace.js +2 -6
  172. package/dist/rag/handlers/ingest.js +1 -1
  173. package/dist/rag/handlers/list-workspaces.d.ts +1 -1
  174. package/dist/rag/handlers/list-workspaces.js +1 -1
  175. package/dist/rag/handlers/reindex.js +1 -1
  176. package/dist/rag/handlers/save-embeddings.js +1 -1
  177. package/dist/rag/handlers/search.js +1 -1
  178. package/dist/rag/index.d.ts +11 -11
  179. package/dist/rag/index.js +11 -11
  180. package/dist/rag/rag-workspace-manager.d.ts +4 -2
  181. package/dist/rag/rag-workspace-manager.js +268 -15
  182. package/dist/registry.js +8 -58
  183. package/dist/resources/collector.d.ts +3 -1
  184. package/dist/resources/collector.js +91 -9
  185. package/dist/resources/instance.d.ts +1 -1
  186. package/dist/resources/instance.js +1 -1
  187. package/dist/resources/model-fit/assess.d.ts +36 -0
  188. package/dist/resources/model-fit/assess.js +679 -0
  189. package/dist/resources/model-fit/calibration/darwin-arm64.d.ts +8 -0
  190. package/dist/resources/model-fit/calibration/darwin-arm64.js +36 -0
  191. package/dist/resources/model-fit/calibration/darwin-x64.d.ts +8 -0
  192. package/dist/resources/model-fit/calibration/darwin-x64.js +38 -0
  193. package/dist/resources/model-fit/calibration/fit.d.ts +73 -0
  194. package/dist/resources/model-fit/calibration/fit.js +152 -0
  195. package/dist/resources/model-fit/calibration/index.d.ts +37 -0
  196. package/dist/resources/model-fit/calibration/index.js +75 -0
  197. package/dist/resources/model-fit/calibration/linux-arm64.d.ts +8 -0
  198. package/dist/resources/model-fit/calibration/linux-arm64.js +38 -0
  199. package/dist/resources/model-fit/calibration/linux-x64-vulkan.d.ts +8 -0
  200. package/dist/resources/model-fit/calibration/linux-x64-vulkan.js +39 -0
  201. package/dist/resources/model-fit/calibration/linux-x64.d.ts +8 -0
  202. package/dist/resources/model-fit/calibration/linux-x64.js +38 -0
  203. package/dist/resources/model-fit/calibration/win32-x64-vulkan-shared.d.ts +8 -0
  204. package/dist/resources/model-fit/calibration/win32-x64-vulkan-shared.js +39 -0
  205. package/dist/resources/model-fit/calibration/win32-x64-vulkan.d.ts +8 -0
  206. package/dist/resources/model-fit/calibration/win32-x64-vulkan.js +36 -0
  207. package/dist/resources/model-fit/calibration/win32-x64.d.ts +8 -0
  208. package/dist/resources/model-fit/calibration/win32-x64.js +38 -0
  209. package/dist/resources/model-fit/estimators/llm.d.ts +46 -0
  210. package/dist/resources/model-fit/estimators/llm.js +222 -0
  211. package/dist/resources/model-fit/estimators/whisper.d.ts +10 -0
  212. package/dist/resources/model-fit/estimators/whisper.js +77 -0
  213. package/dist/resources/model-fit/floor.d.ts +31 -0
  214. package/dist/resources/model-fit/floor.js +65 -0
  215. package/dist/resources/model-fit/types.d.ts +120 -0
  216. package/dist/resources/model-fit/types.js +1 -0
  217. package/dist/resources/native.d.ts +1 -1
  218. package/dist/resources/native.js +15 -0
  219. package/dist/resources/normalize.d.ts +1 -1
  220. package/dist/resources/types.d.ts +14 -0
  221. package/dist/runtime/index.d.ts +5 -5
  222. package/dist/runtime/index.js +2 -2
  223. package/dist/runtime/lifecycle.js +5 -7
  224. package/dist/runtime/model-registry.d.ts +0 -14
  225. package/dist/runtime/model-registry.js +17 -40
  226. package/dist/runtime/registry-client.js +1 -1
  227. package/dist/runtime/request-context.d.ts +3 -3
  228. package/dist/runtime/request-context.js +13 -1
  229. package/dist/runtime/request-registry.d.ts +1 -1
  230. package/dist/runtime/request-registry.js +4 -5
  231. package/dist/runtime/state.d.ts +1 -1
  232. package/dist/runtime/state.js +18 -3
  233. package/dist/schemas/assess-model-fit.d.ts +311 -0
  234. package/dist/schemas/assess-model-fit.js +182 -0
  235. package/dist/schemas/audio-gen.d.ts +437 -7
  236. package/dist/schemas/audio-gen.js +131 -19
  237. package/dist/schemas/batch-completion-stream.d.ts +5 -2
  238. package/dist/schemas/batch-completion-stream.js +3 -3
  239. package/dist/schemas/bci-config.js +73 -27
  240. package/dist/schemas/bci.d.ts +3 -3
  241. package/dist/schemas/bci.js +5 -5
  242. package/dist/schemas/cancel.d.ts +5 -0
  243. package/dist/schemas/cancel.js +1 -0
  244. package/dist/schemas/classification.js +13 -6
  245. package/dist/schemas/common.d.ts +695 -335
  246. package/dist/schemas/common.js +33 -31
  247. package/dist/schemas/completion-event.d.ts +5 -2
  248. package/dist/schemas/completion-event.js +2 -1
  249. package/dist/schemas/completion-stream.d.ts +3 -5
  250. package/dist/schemas/completion-stream.js +4 -8
  251. package/dist/schemas/config.d.ts +640 -18
  252. package/dist/schemas/config.js +50 -8
  253. package/dist/schemas/download-asset.d.ts +19 -1
  254. package/dist/schemas/download-asset.js +20 -4
  255. package/dist/schemas/engine-addon-map.d.ts +1 -1
  256. package/dist/schemas/engine-addon-map.js +3 -3
  257. package/dist/schemas/error.d.ts +2 -2
  258. package/dist/schemas/error.js +2 -2
  259. package/dist/schemas/errors.d.ts +2 -6
  260. package/dist/schemas/errors.js +30 -40
  261. package/dist/schemas/heartbeat.d.ts +10 -0
  262. package/dist/schemas/heartbeat.js +8 -0
  263. package/dist/schemas/index.d.ts +46 -44
  264. package/dist/schemas/index.js +45 -43
  265. package/dist/schemas/llamacpp-config.d.ts +32 -10
  266. package/dist/schemas/llamacpp-config.js +11 -8
  267. package/dist/schemas/load-model.d.ts +2902 -1857
  268. package/dist/schemas/load-model.js +52 -52
  269. package/dist/schemas/mcp-adapter.d.ts +1 -1
  270. package/dist/schemas/model-config-schemas.d.ts +2354 -0
  271. package/dist/schemas/model-config-schemas.js +46 -0
  272. package/dist/schemas/model-info.d.ts +10 -20
  273. package/dist/schemas/model-info.js +4 -25
  274. package/dist/schemas/model-ops.d.ts +3 -1
  275. package/dist/schemas/model-ops.js +7 -2
  276. package/dist/schemas/model-resource-profile.d.ts +109 -0
  277. package/dist/schemas/model-resource-profile.js +83 -0
  278. package/dist/schemas/model-src-utils.d.ts +1 -0
  279. package/dist/schemas/model-src-utils.js +33 -13
  280. package/dist/schemas/ocr.js +48 -13
  281. package/dist/schemas/path-validation.js +8 -2
  282. package/dist/schemas/plugin.d.ts +23 -10
  283. package/dist/schemas/plugin.js +11 -0
  284. package/dist/schemas/profiling.d.ts +138 -43
  285. package/dist/schemas/profiling.js +1 -22
  286. package/dist/schemas/rag.js +1 -1
  287. package/dist/schemas/registry.js +1 -1
  288. package/dist/schemas/reload-config.d.ts +0 -2
  289. package/dist/schemas/reload-config.js +2 -3
  290. package/dist/schemas/sdcpp-config.d.ts +344 -4
  291. package/dist/schemas/sdcpp-config.js +504 -17
  292. package/dist/schemas/system-resources.d.ts +138 -0
  293. package/dist/schemas/system-resources.js +3 -1
  294. package/dist/schemas/text-to-speech.js +183 -76
  295. package/dist/schemas/transcription-config.js +253 -85
  296. package/dist/schemas/transcription.d.ts +3 -3
  297. package/dist/schemas/translate.d.ts +2 -2
  298. package/dist/schemas/translate.js +1 -1
  299. package/dist/schemas/translation-config.js +53 -25
  300. package/dist/schemas/vla.d.ts +1 -1
  301. package/dist/selection.d.ts +1 -5
  302. package/dist/selection.js +2 -6
  303. package/dist/surface.d.ts +1 -1
  304. package/dist/utils/addon-responses.d.ts +1 -0
  305. package/dist/utils/aggregate-events.d.ts +1 -1
  306. package/dist/utils/aggregate-events.js +2 -2
  307. package/dist/utils/archive.js +2 -2
  308. package/dist/utils/audio-input.js +1 -1
  309. package/dist/utils/cache/auto-history.d.ts +1 -1
  310. package/dist/utils/cache/auto-history.js +1 -1
  311. package/dist/utils/cache/paths.js +5 -5
  312. package/dist/utils/completion-normalizer.js +1 -1
  313. package/dist/utils/gguf-tensor-extractor.js +1 -1
  314. package/dist/utils/image-dimensions.d.ts +26 -0
  315. package/dist/utils/image-dimensions.js +46 -0
  316. package/dist/utils/index.d.ts +13 -10
  317. package/dist/utils/index.js +13 -10
  318. package/dist/utils/mcp-adapter.d.ts +1 -1
  319. package/dist/utils/mcp-adapter.js +1 -1
  320. package/dist/utils/path-sanitize.d.ts +7 -0
  321. package/dist/utils/path-sanitize.js +36 -0
  322. package/dist/utils/path-security.d.ts +0 -7
  323. package/dist/utils/path-security.js +1 -36
  324. package/dist/utils/shard-utils.js +3 -3
  325. package/dist/utils/tool-integration.js +1 -1
  326. package/dist/utils/tools/dialect.js +1 -1
  327. package/dist/utils/tools/index.d.ts +2 -2
  328. package/dist/utils/tools/index.js +2 -2
  329. package/dist/utils/tools/parser.js +8 -8
  330. package/dist/utils/tools/parsers/dsml.d.ts +1 -1
  331. package/dist/utils/tools/parsers/dsml.js +1 -1
  332. package/dist/utils/tools/parsers/gemma4native.d.ts +1 -1
  333. package/dist/utils/tools/parsers/gemma4native.js +1 -1
  334. package/dist/utils/tools/parsers/harmony.d.ts +1 -1
  335. package/dist/utils/tools/parsers/harmony.js +1 -1
  336. package/dist/utils/tools/parsers/hermes.d.ts +1 -1
  337. package/dist/utils/tools/parsers/hermes.js +1 -1
  338. package/dist/utils/tools/parsers/json.d.ts +1 -1
  339. package/dist/utils/tools/parsers/json.js +1 -1
  340. package/dist/utils/tools/parsers/pythonic.d.ts +1 -1
  341. package/dist/utils/tools/parsers/pythonic.js +1 -1
  342. package/dist/utils/tools/parsers/qwen35.d.ts +1 -1
  343. package/dist/utils/tools/parsers/qwen35.js +3 -3
  344. package/dist/utils/url-security.d.ts +17 -0
  345. package/dist/utils/url-security.js +75 -0
  346. package/package.json +31 -26
  347. package/dist/api/provide.d.ts +0 -23
  348. package/dist/api/provide.js +0 -32
  349. package/dist/api/stop-provider.d.ts +0 -20
  350. package/dist/api/stop-provider.js +0 -30
  351. package/dist/p2p/cancel-delegated.d.ts +0 -3
  352. package/dist/p2p/cancel-delegated.js +0 -64
  353. package/dist/p2p/completion-stream-delegated.d.ts +0 -4
  354. package/dist/p2p/completion-stream-delegated.js +0 -51
  355. package/dist/p2p/delegate-client.d.ts +0 -9
  356. package/dist/p2p/delegate-client.js +0 -219
  357. package/dist/p2p/delegate-connect-diagnostics.d.ts +0 -8
  358. package/dist/p2p/delegate-connect-diagnostics.js +0 -38
  359. package/dist/p2p/delegate-transport.d.ts +0 -18
  360. package/dist/p2p/delegate-transport.js +0 -237
  361. package/dist/p2p/error-handlers.d.ts +0 -4
  362. package/dist/p2p/error-handlers.js +0 -31
  363. package/dist/p2p/handle-request.d.ts +0 -2
  364. package/dist/p2p/handle-request.js +0 -171
  365. package/dist/p2p/handler-utils.d.ts +0 -19
  366. package/dist/p2p/handler-utils.js +0 -180
  367. package/dist/p2p/heartbeat-delegated.d.ts +0 -3
  368. package/dist/p2p/heartbeat-delegated.js +0 -32
  369. package/dist/p2p/load-model-delegated.d.ts +0 -6
  370. package/dist/p2p/load-model-delegated.js +0 -132
  371. package/dist/p2p/progress-throttle.d.ts +0 -7
  372. package/dist/p2p/progress-throttle.js +0 -47
  373. package/dist/p2p/provideHandler/connection.d.ts +0 -2
  374. package/dist/p2p/provideHandler/connection.js +0 -38
  375. package/dist/p2p/provideHandler/handler.d.ts +0 -2
  376. package/dist/p2p/provideHandler/handler.js +0 -66
  377. package/dist/p2p/provideHandler/proxy.d.ts +0 -2
  378. package/dist/p2p/provideHandler/proxy.js +0 -24
  379. package/dist/p2p/provideHandler.d.ts +0 -1
  380. package/dist/p2p/provideHandler.js +0 -2
  381. package/dist/p2p/rpc-utils.d.ts +0 -4
  382. package/dist/p2p/rpc-utils.js +0 -8
  383. package/dist/p2p/stopProvideHandler.d.ts +0 -2
  384. package/dist/p2p/stopProvideHandler.js +0 -29
  385. package/dist/p2p/swarm.d.ts +0 -9
  386. package/dist/p2p/swarm.js +0 -103
  387. package/dist/p2p/transport-selector.d.ts +0 -2
  388. package/dist/p2p/transport-selector.js +0 -18
  389. package/dist/p2p/unload-model-delegated.d.ts +0 -2
  390. package/dist/p2p/unload-model-delegated.js +0 -31
  391. package/dist/profiling/delegation-profiler.d.ts +0 -31
  392. package/dist/profiling/delegation-profiler.js +0 -155
  393. package/dist/schemas/delegate.d.ts +0 -29
  394. package/dist/schemas/delegate.js +0 -40
  395. package/dist/schemas/provide.d.ts +0 -50
  396. package/dist/schemas/provide.js +0 -32
@@ -1,13 +1,13 @@
1
1
  import fs, { promises as fsPromises } from 'bare-fs';
2
2
  import path from 'bare-path';
3
3
  import { getConfiguredCacheDir } from '../../runtime/state.js';
4
- import { getQvacPath } from '../../utils/qvac-paths.js';
5
- import { calculateFileChecksum } from '../../utils/checksum.js';
6
- import { validateAndJoinPath } from '../../utils/path-security.js';
7
- import { generateShortHash } from '../../utils/formatting.js';
4
+ import { getQvacPath } from '../qvac-paths.js';
5
+ import { calculateFileChecksum } from '../checksum.js';
6
+ import { validateAndJoinPath } from '../path-security.js';
7
+ import { generateShortHash } from '../formatting.js';
8
8
  import { getEngineLogger } from '../../logging/index.js';
9
9
  import { nowMs } from '../../profiling/index.js';
10
- import { resolveClearStorageTarget } from '../../utils/clear-storage.js';
10
+ import { resolveClearStorageTarget } from '../clear-storage.js';
11
11
  const logger = getEngineLogger();
12
12
  export function getCacheDir(subDir) {
13
13
  const cacheDir = getQvacPath(subDir);
@@ -1,4 +1,4 @@
1
- import { parseToolCalls } from '../utils/tools/index.js';
1
+ import { parseToolCalls } from './tools/index.js';
2
2
  export const MAX_TOOL_FRAME_CHARS = 1_048_576;
3
3
  const DSML_INVOKE_FRAMES = [' ', '\n', '\t', '\r'].map((sep) => ({
4
4
  open: `<|DSML|invoke${sep}`,
@@ -2,7 +2,7 @@ import { promises as fsPromises, createReadStream } from 'bare-fs';
2
2
  import Buffer from 'bare-buffer';
3
3
  import { getEngineLogger } from '../logging/index.js';
4
4
  import { ModelLoadFailedError } from '../errors/index.js';
5
- import { validateAndJoinPath } from '../utils/path-security.js';
5
+ import { validateAndJoinPath } from './path-security.js';
6
6
  const logger = getEngineLogger();
7
7
  // GGUF value types
8
8
  const GGUF_TYPE = {
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Declared pixel dimensions of a PNG or JPEG, read from its header.
3
+ *
4
+ * Exists so a caller-supplied image can be size-checked BEFORE anything decodes
5
+ * it. A compressed format's transfer size says nothing about its decoded size —
6
+ * a 1.5 MB PNG of uniform scanlines can declare 40000x40000, which is 1.6
7
+ * gigapixels and several GB in one native allocation. Bounding the encoded bytes
8
+ * does not prevent that; bounding the declared dimensions does.
9
+ *
10
+ * Returns `null` when the dimensions cannot be read. A size guard MUST treat that
11
+ * as a refusal, not as a pass: the sender chooses the format, so failing open on
12
+ * an unreadable header means a bomb only has to arrive as a BMP to skip the
13
+ * check entirely. `worldSceneRequestSchema` documents PNG/JPEG, so refusing
14
+ * anything this cannot size enforces the contract that is already published.
15
+ *
16
+ * `@qvac/diffusion-cpp` ships its own copy of this, and so does the world e2e
17
+ * suite. Deliberately independent of both: the addon's is exported only from
18
+ * `./addon.js`, which is absent from its `exports` map and carries no types, so
19
+ * depending on it would bind the SDK to an addon internal that can change
20
+ * without a semver signal. Keep them in sync only in behaviour, not by import.
21
+ */
22
+ export interface ImageDimensions {
23
+ width: number;
24
+ height: number;
25
+ }
26
+ export declare function readImageDimensions(buf: Uint8Array): ImageDimensions | null;
@@ -0,0 +1,46 @@
1
+ export function readImageDimensions(buf) {
2
+ if (buf.length < 4)
3
+ return null;
4
+ // PNG: the IHDR chunk puts width and height as big-endian uint32 at 16..23.
5
+ if (buf[0] === 0x89 && buf[1] === 0x50 && buf[2] === 0x4e && buf[3] === 0x47) {
6
+ if (buf.length < 24)
7
+ return null;
8
+ const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
9
+ return { width: view.getUint32(16, false), height: view.getUint32(20, false) };
10
+ }
11
+ // JPEG: walk the segment chain to the first start-of-frame, which carries
12
+ // height at +5 and width at +7. 0xC4 (DHT), 0xC8 and 0xCC share the 0xCn range
13
+ // without being frame headers, hence the three separate ranges.
14
+ if (buf[0] === 0xff && buf[1] === 0xd8) {
15
+ const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
16
+ let offset = 2;
17
+ while (offset + 9 < buf.length) {
18
+ if (buf[offset] !== 0xff)
19
+ return null;
20
+ // A marker may be preceded by any number of 0xFF fill bytes (ITU-T T.81
21
+ // B.1.1.2). Skipping them matters for more than tidiness: reading the fill
22
+ // byte AS the marker desynchronises the walk, the next getUint16 reads
23
+ // payload as a segment length, and the whole thing returns null — which,
24
+ // for a size guard, is a bypass rather than a parse failure.
25
+ while (offset + 1 < buf.length && buf[offset + 1] === 0xff)
26
+ offset++;
27
+ if (offset + 9 >= buf.length)
28
+ return null;
29
+ const marker = buf[offset + 1];
30
+ const length = view.getUint16(offset + 2, false);
31
+ if (length < 2)
32
+ return null;
33
+ if ((marker >= 0xc0 && marker <= 0xc3) ||
34
+ (marker >= 0xc5 && marker <= 0xc7) ||
35
+ (marker >= 0xc9 && marker <= 0xcb) ||
36
+ (marker >= 0xcd && marker <= 0xcf)) {
37
+ return {
38
+ width: view.getUint16(offset + 7, false),
39
+ height: view.getUint16(offset + 5, false)
40
+ };
41
+ }
42
+ offset += 2 + length;
43
+ }
44
+ }
45
+ return null;
46
+ }
@@ -1,10 +1,13 @@
1
- export * from '../utils/archive.js';
2
- export * from '../utils/cache/types.js';
3
- export * from '../utils/cache/auto-history.js';
4
- export * from '../utils/cache/paths.js';
5
- export * from '../utils/checksum.js';
6
- export * from '../utils/config-transform.js';
7
- export * from '../utils/formatting.js';
8
- export * from '../utils/gguf-tensor-extractor.js';
9
- export * from '../utils/path-security.js';
10
- export * from '../utils/shard-utils.js';
1
+ export * from './archive.js';
2
+ export * from './cache/types.js';
3
+ export * from './cache/auto-history.js';
4
+ export * from './cache/paths.js';
5
+ export * from './checksum.js';
6
+ export * from './config-transform.js';
7
+ export * from './formatting.js';
8
+ export * from './gguf-tensor-extractor.js';
9
+ export * from './image-dimensions.js';
10
+ export * from './path-sanitize.js';
11
+ export * from './path-security.js';
12
+ export * from './shard-utils.js';
13
+ export * from './url-security.js';
@@ -1,10 +1,13 @@
1
- export * from '../utils/archive.js';
2
- export * from '../utils/cache/types.js';
3
- export * from '../utils/cache/auto-history.js';
4
- export * from '../utils/cache/paths.js';
5
- export * from '../utils/checksum.js';
6
- export * from '../utils/config-transform.js';
7
- export * from '../utils/formatting.js';
8
- export * from '../utils/gguf-tensor-extractor.js';
9
- export * from '../utils/path-security.js';
10
- export * from '../utils/shard-utils.js';
1
+ export * from './archive.js';
2
+ export * from './cache/types.js';
3
+ export * from './cache/auto-history.js';
4
+ export * from './cache/paths.js';
5
+ export * from './checksum.js';
6
+ export * from './config-transform.js';
7
+ export * from './formatting.js';
8
+ export * from './gguf-tensor-extractor.js';
9
+ export * from './image-dimensions.js';
10
+ export * from './path-sanitize.js';
11
+ export * from './path-security.js';
12
+ export * from './shard-utils.js';
13
+ export * from './url-security.js';
@@ -1,6 +1,6 @@
1
1
  import type { Tool } from '../schemas/tools.js';
2
2
  import type { McpClientInput } from '../schemas/mcp-adapter.js';
3
- import type { ToolHandler } from '../utils/tool-helpers.js';
3
+ import type { ToolHandler } from './tool-helpers.js';
4
4
  export type { McpClient, McpClientInput } from '../schemas/mcp-adapter.js';
5
5
  export type ToolHandlerMap = Map<string, ToolHandler>;
6
6
  export type McpToolsResult = {
@@ -1,4 +1,4 @@
1
- import { mapValues } from '../utils/object.js';
1
+ import { mapValues } from './object.js';
2
2
  const VALID_TYPES = ['string', 'number', 'integer', 'boolean', 'object', 'array'];
3
3
  function isValidType(value) {
4
4
  return typeof value === 'string' && VALID_TYPES.includes(value);
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Sanitize a path component that will be joined to a base directory.
3
+ * Strips traversal sequences, absolute prefixes, and normalizes separators.
4
+ *
5
+ * Throws on null bytes (literal or URL-encoded).
6
+ */
7
+ export declare function sanitizePathComponent(component: string): string;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Sanitize a path component that will be joined to a base directory.
3
+ * Strips traversal sequences, absolute prefixes, and normalizes separators.
4
+ *
5
+ * Throws on null bytes (literal or URL-encoded).
6
+ */
7
+ export function sanitizePathComponent(component) {
8
+ if (component === '')
9
+ return '';
10
+ // Reject null bytes (literal and URL-encoded)
11
+ if (component.includes('\0') || component.includes('%00')) {
12
+ throw new Error(`Path component contains null byte: ${component}`);
13
+ }
14
+ let sanitized = component;
15
+ // Decode common URL-encoded traversal sequences
16
+ sanitized = sanitized.replace(/%2e/gi, '.').replace(/%2f/gi, '/').replace(/%5c/gi, '\\');
17
+ // Normalize backslashes to forward slashes
18
+ sanitized = sanitized.replace(/\\/g, '/');
19
+ // Strip Windows drive letter prefixes (C:/, D:/, etc.)
20
+ sanitized = sanitized.replace(/^[A-Za-z]:\//, '');
21
+ // Strip leading slashes (absolute path prefixes)
22
+ sanitized = sanitized.replace(/^\/+/, '');
23
+ // Remove all ".." segments (start, middle, end) iteratively until stable
24
+ let prev = '';
25
+ while (prev !== sanitized) {
26
+ prev = sanitized;
27
+ sanitized = sanitized.replace(/^\.\.\//g, '');
28
+ sanitized = sanitized.replace(/\/\.\.$/g, '');
29
+ sanitized = sanitized.replace(/\/\.\.\//g, '/');
30
+ if (sanitized === '..')
31
+ sanitized = '';
32
+ }
33
+ // Strip any remaining leading slashes produced by stripping
34
+ sanitized = sanitized.replace(/^\/+/, '');
35
+ return sanitized;
36
+ }
@@ -1,10 +1,3 @@
1
- /**
2
- * Sanitize a path component that will be joined to a base directory.
3
- * Strips traversal sequences, absolute prefixes, and normalizes separators.
4
- *
5
- * Throws on null bytes (literal or URL-encoded).
6
- */
7
- export declare function sanitizePathComponent(component: string): string;
8
1
  /**
9
2
  * Check whether a resolved target path is contained within a base directory.
10
3
  * Portable — caller provides the resolve function and separator for their runtime.
@@ -1,41 +1,6 @@
1
1
  import path from 'bare-path';
2
2
  import { PathTraversalError } from '../errors/index.js';
3
- /**
4
- * Sanitize a path component that will be joined to a base directory.
5
- * Strips traversal sequences, absolute prefixes, and normalizes separators.
6
- *
7
- * Throws on null bytes (literal or URL-encoded).
8
- */
9
- export function sanitizePathComponent(component) {
10
- if (component === '')
11
- return '';
12
- // Reject null bytes (literal and URL-encoded)
13
- if (component.includes('\0') || component.includes('%00')) {
14
- throw new Error(`Path component contains null byte: ${component}`);
15
- }
16
- let sanitized = component;
17
- // Decode common URL-encoded traversal sequences
18
- sanitized = sanitized.replace(/%2e/gi, '.').replace(/%2f/gi, '/').replace(/%5c/gi, '\\');
19
- // Normalize backslashes to forward slashes
20
- sanitized = sanitized.replace(/\\/g, '/');
21
- // Strip Windows drive letter prefixes (C:/, D:/, etc.)
22
- sanitized = sanitized.replace(/^[A-Za-z]:\//, '');
23
- // Strip leading slashes (absolute path prefixes)
24
- sanitized = sanitized.replace(/^\/+/, '');
25
- // Remove all ".." segments (start, middle, end) iteratively until stable
26
- let prev = '';
27
- while (prev !== sanitized) {
28
- prev = sanitized;
29
- sanitized = sanitized.replace(/^\.\.\//g, '');
30
- sanitized = sanitized.replace(/\/\.\.$/g, '');
31
- sanitized = sanitized.replace(/\/\.\.\//g, '/');
32
- if (sanitized === '..')
33
- sanitized = '';
34
- }
35
- // Strip any remaining leading slashes produced by stripping
36
- sanitized = sanitized.replace(/^\/+/, '');
37
- return sanitized;
38
- }
3
+ import { sanitizePathComponent } from './path-sanitize.js';
39
4
  /**
40
5
  * Check whether a resolved target path is contained within a base directory.
41
6
  * Portable — caller provides the resolve function and separator for their runtime.
@@ -1,7 +1,7 @@
1
1
  import { ModelLoadFailedError, InvalidShardUrlPatternError } from '../errors/index.js';
2
- import { generateShortHash } from '../utils/formatting.js';
3
- import { validateAndJoinPath } from '../utils/path-security.js';
4
- import { extractAndWriteTensorsFile } from '../utils/gguf-tensor-extractor.js';
2
+ import { generateShortHash } from './formatting.js';
3
+ import { validateAndJoinPath } from './path-security.js';
4
+ import { extractAndWriteTensorsFile } from './gguf-tensor-extractor.js';
5
5
  import { promises as fsPromises } from 'bare-fs';
6
6
  /**
7
7
  * Detect if model filename follows shard pattern (00001-of-0000x)
@@ -1,4 +1,4 @@
1
- import { detectToolDialectFromName } from '../utils/tools/index.js';
1
+ import { detectToolDialectFromName } from './tools/index.js';
2
2
  import { getModelInfo } from '../runtime/model-registry.js';
3
3
  /**
4
4
  * Prepend tools right after the system message (or at the very start when no
@@ -6,7 +6,7 @@
6
6
  export function detectToolDialectFromName(name, path) {
7
7
  const basename = path.toLowerCase().split(/[/\\]/).pop() ?? '';
8
8
  const tag = `${(name ?? '').toLowerCase()}|${basename}`;
9
- if (/qwen3[._-]?[56](?![a-z0-9])/.test(tag))
9
+ if (/qwen3[._-]?[568](?![a-z0-9])/.test(tag))
10
10
  return 'qwen35';
11
11
  if (/gemma[-_]?4(?=[^a-z0-9]|$)/.test(tag))
12
12
  return 'gemma4';
@@ -1,2 +1,2 @@
1
- export { detectToolDialectFromName } from '../../utils/tools/dialect.js';
2
- export { parseToolCalls } from '../../utils/tools/parser.js';
1
+ export { detectToolDialectFromName } from './dialect.js';
2
+ export { parseToolCalls } from './parser.js';
@@ -1,2 +1,2 @@
1
- export { detectToolDialectFromName } from '../../utils/tools/dialect.js';
2
- export { parseToolCalls } from '../../utils/tools/parser.js';
1
+ export { detectToolDialectFromName } from './dialect.js';
2
+ export { parseToolCalls } from './parser.js';
@@ -1,11 +1,11 @@
1
- import { stripThinkingBlocks } from '../../utils/tools/shared.js';
2
- import { parseGemmaFormat, parseGenericFormat, parseLlamacppFormat } from '../../utils/tools/parsers/json.js';
3
- import { parseHermesFormat } from '../../utils/tools/parsers/hermes.js';
4
- import { parsePythonicFormat } from '../../utils/tools/parsers/pythonic.js';
5
- import { parseHarmonyFormat } from '../../utils/tools/parsers/harmony.js';
6
- import { parseQwen35Format } from '../../utils/tools/parsers/qwen35.js';
7
- import { parseGemma4NativeFormat } from '../../utils/tools/parsers/gemma4native.js';
8
- import { parseDsmlFormat } from '../../utils/tools/parsers/dsml.js';
1
+ import { stripThinkingBlocks } from './shared.js';
2
+ import { parseGemmaFormat, parseGenericFormat, parseLlamacppFormat } from './parsers/json.js';
3
+ import { parseHermesFormat } from './parsers/hermes.js';
4
+ import { parsePythonicFormat } from './parsers/pythonic.js';
5
+ import { parseHarmonyFormat } from './parsers/harmony.js';
6
+ import { parseQwen35Format } from './parsers/qwen35.js';
7
+ import { parseGemma4NativeFormat } from './parsers/gemma4native.js';
8
+ import { parseDsmlFormat } from './parsers/dsml.js';
9
9
  function pickFormatParsers(dialect) {
10
10
  switch (dialect) {
11
11
  case 'pythonic':
@@ -1,3 +1,3 @@
1
1
  import type { Tool } from '../../../schemas/index.js';
2
- import { type ParserResult } from '../../../utils/tools/shared.js';
2
+ import { type ParserResult } from '../shared.js';
3
3
  export declare function parseDsmlFormat(text: string, tools: Tool[]): ParserResult;
@@ -1,4 +1,4 @@
1
- import { generateStableToolCallId, validateToolArguments } from '../../../utils/tools/shared.js';
1
+ import { generateStableToolCallId, validateToolArguments } from '../shared.js';
2
2
  // DeepSeek marks DSML tags with a fullwidth vertical line (U+FF5C `|`), not
3
3
  // the ASCII pipe used by the visually similar `<|...|>` markers of the harmony
4
4
  // and gemma4 dialects — the two must not be conflated. V4 wraps calls in
@@ -1,3 +1,3 @@
1
1
  import type { Tool } from '../../../schemas/index.js';
2
- import { type ParserResult } from '../../../utils/tools/shared.js';
2
+ import { type ParserResult } from '../shared.js';
3
3
  export declare function parseGemma4NativeFormat(text: string, tools: Tool[]): ParserResult;
@@ -1,4 +1,4 @@
1
- import { generateStableToolCallId, validateToolArguments } from '../../../utils/tools/shared.js';
1
+ import { generateStableToolCallId, validateToolArguments } from '../shared.js';
2
2
  // Transliterates Gemma 4's JS-literal argument body to valid JSON so it can
3
3
  // be parsed with JSON.parse. The body uses:
4
4
  // - <|"|>...<|"|> instead of "..." for string values
@@ -1,3 +1,3 @@
1
1
  import type { Tool } from '../../../schemas/index.js';
2
- import { type ParserResult } from '../../../utils/tools/shared.js';
2
+ import { type ParserResult } from '../shared.js';
3
3
  export declare function parseHarmonyFormat(text: string, tools: Tool[]): ParserResult;
@@ -1,4 +1,4 @@
1
- import { generateStableToolCallId, validateToolArguments } from '../../../utils/tools/shared.js';
1
+ import { generateStableToolCallId, validateToolArguments } from '../shared.js';
2
2
  const HARMONY_FRAME_RE = /to=functions\.([\w-]+)\s+<\|constrain\|>json<\|message\|>([\s\S]*?)(?=<\|call\|>|$)/g;
3
3
  export function parseHarmonyFormat(text, tools) {
4
4
  const toolCalls = [];
@@ -1,3 +1,3 @@
1
1
  import type { Tool } from '../../../schemas/index.js';
2
- import { type ParserResult } from '../../../utils/tools/shared.js';
2
+ import { type ParserResult } from '../shared.js';
3
3
  export declare function parseHermesFormat(text: string, tools: Tool[]): ParserResult;
@@ -1,4 +1,4 @@
1
- import { generateStableToolCallId, isValidToolCall, validateToolArguments } from '../../../utils/tools/shared.js';
1
+ import { generateStableToolCallId, isValidToolCall, validateToolArguments } from '../shared.js';
2
2
  // Qwen3.5/3.6 can fuse its two tool templates into one frame, embedding the
3
3
  // XML `<function=NAME>` token as a bare string key inside the JSON envelope:
4
4
  // {"function=NAME","arguments":{...}} (invalid JSON, not parseable as-is)
@@ -1,5 +1,5 @@
1
1
  import type { Tool } from '../../../schemas/index.js';
2
- import { type ParserResult } from '../../../utils/tools/shared.js';
2
+ import { type ParserResult } from '../shared.js';
3
3
  export declare function parseGemmaFormat(text: string, tools: Tool[]): ParserResult;
4
4
  export declare function parseLlamacppFormat(text: string, tools: Tool[]): ParserResult;
5
5
  export declare function parseGenericFormat(text: string, tools: Tool[]): ParserResult;
@@ -1,4 +1,4 @@
1
- import { generateStableToolCallId, isValidToolCall, validateToolArguments } from '../../../utils/tools/shared.js';
1
+ import { generateStableToolCallId, isValidToolCall, validateToolArguments } from '../shared.js';
2
2
  export function parseGemmaFormat(text, tools) {
3
3
  const toolCalls = [];
4
4
  const errors = [];
@@ -1,3 +1,3 @@
1
1
  import type { Tool } from '../../../schemas/index.js';
2
- import { type ParserResult } from '../../../utils/tools/shared.js';
2
+ import { type ParserResult } from '../shared.js';
3
3
  export declare function parsePythonicFormat(text: string, tools: Tool[]): ParserResult;
@@ -1,4 +1,4 @@
1
- import { generateStableToolCallId, validateToolArguments } from '../../../utils/tools/shared.js';
1
+ import { generateStableToolCallId, validateToolArguments } from '../shared.js';
2
2
  // Pythonic `[name(k=v), ...]` arrays. LFM 2.x is auto-routed; Llama-style
3
3
  // tokens are kept for callers that opt in via `completion({ toolDialect:
4
4
  // "pythonic" })` for a model known to emit Pythonic. Pure string parsing —
@@ -1,3 +1,3 @@
1
1
  import type { Tool } from '../../../schemas/index.js';
2
- import { type ParserResult } from '../../../utils/tools/shared.js';
2
+ import { type ParserResult } from '../shared.js';
3
3
  export declare function parseQwen35Format(text: string, tools: Tool[]): ParserResult;
@@ -1,4 +1,4 @@
1
- import { generateStableToolCallId, validateToolArguments } from '../../../utils/tools/shared.js';
1
+ import { generateStableToolCallId, validateToolArguments } from '../shared.js';
2
2
  // Coerce raw parameter text to the type declared in the tool's JSON schema.
3
3
  // String values are raw (not JSON-quoted); arrays/objects are valid JSON.
4
4
  function coerceParamValue(raw, schema) {
@@ -24,7 +24,7 @@ function coerceParamValue(raw, schema) {
24
24
  return n;
25
25
  }
26
26
  case 'boolean': {
27
- // Qwen3.5/3.6 intermittently emit Python-style capitalised booleans
27
+ // Qwen3.5/3.6/3.8 intermittently emit Python-style capitalised booleans
28
28
  // (`True`/`False`); accept any casing so a valid call isn't dropped.
29
29
  const v = trimmed.toLowerCase();
30
30
  if (v === 'true')
@@ -40,7 +40,7 @@ function coerceParamValue(raw, schema) {
40
40
  return trimmed;
41
41
  }
42
42
  }
43
- // Parses Qwen3.5/3.6 Pythonic-XML tool-call format:
43
+ // Parses Qwen3.5/3.6/3.8 Pythonic-XML tool-call format:
44
44
  // <tool_call>
45
45
  // <function=NAME>
46
46
  // <parameter=KEY>VALUE</parameter>
@@ -0,0 +1,17 @@
1
+ export type HeaderBag = Record<string, string | string[] | number | undefined>;
2
+ export declare function isLoopbackHost(host: string): boolean;
3
+ export declare function isHuggingFaceHost(host: string): boolean;
4
+ /**
5
+ * Whether an HTTP(S) URL may be used for a model download. HTTPS is always
6
+ * allowed; plaintext HTTP only for loopback. Other schemes are out of scope
7
+ * here and return false.
8
+ */
9
+ export declare function isSecureDownloadUrl(url: string | URL): boolean;
10
+ /**
11
+ * Extract the Hugging Face Hub SHA-256 from a response's headers, if present.
12
+ * The Hub publishes it as `X-Linked-Etag` (and `ETag` for LFS files) — the
13
+ * content SHA-256 for LFS-backed files. A non-LFS file yields a git blob
14
+ * SHA-1 (40 hex) or a CDN etag instead; those are not SHA-256 and return
15
+ * undefined so the caller treats the download as unverifiable.
16
+ */
17
+ export declare function extractHubSha256(headers: HeaderBag): string | undefined;
@@ -0,0 +1,75 @@
1
+ // Transport and integrity rules for HTTP model downloads.
2
+ //
3
+ // Unverified bring-your-own HTTP sources are trusted on transport alone, so the
4
+ // transport must actually protect the bytes: plaintext http:// gives a network
5
+ // attacker a silent swap of the model, and an https:// URL that redirects to
6
+ // http:// (SSL-stripping) reopens the same hole. Loopback never touches the
7
+ // network, so it is exempt. Hugging Face is the one source that also ships an
8
+ // integrity hash (the Hub's SHA-256, surfaced as the X-Linked-Etag header on
9
+ // the resolve response before the CDN redirect), which we verify downloads
10
+ // against.
11
+ const HUGGING_FACE_HOSTS = new Set(['huggingface.co', 'hf.co']);
12
+ function stripBrackets(host) {
13
+ return host.startsWith('[') && host.endsWith(']') ? host.slice(1, -1) : host;
14
+ }
15
+ const IPV4_LOOPBACK = /^127\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
16
+ export function isLoopbackHost(host) {
17
+ const h = stripBrackets(host.trim().toLowerCase());
18
+ if (h === 'localhost' || h === '::1')
19
+ return true;
20
+ // Match the 127.0.0.0/8 block as an actual IPv4 address, not a string prefix:
21
+ // `127.0.0.1.evil.com` and `127.example.com` are registrable domains, not loopback.
22
+ const m = IPV4_LOOPBACK.exec(h);
23
+ return m !== null && m.slice(1).every((octet) => Number(octet) <= 255);
24
+ }
25
+ export function isHuggingFaceHost(host) {
26
+ return HUGGING_FACE_HOSTS.has(host.trim().toLowerCase());
27
+ }
28
+ /**
29
+ * Whether an HTTP(S) URL may be used for a model download. HTTPS is always
30
+ * allowed; plaintext HTTP only for loopback. Other schemes are out of scope
31
+ * here and return false.
32
+ */
33
+ export function isSecureDownloadUrl(url) {
34
+ let parsed;
35
+ try {
36
+ parsed = typeof url === 'string' ? new URL(url) : url;
37
+ }
38
+ catch {
39
+ return false;
40
+ }
41
+ if (parsed.protocol === 'https:')
42
+ return true;
43
+ if (parsed.protocol === 'http:')
44
+ return isLoopbackHost(parsed.hostname);
45
+ return false;
46
+ }
47
+ function firstHeaderValue(headers, name) {
48
+ const value = headers[name] ?? headers[name.toLowerCase()];
49
+ const raw = Array.isArray(value) ? value[0] : value;
50
+ return raw === undefined ? undefined : String(raw);
51
+ }
52
+ function normalizeEtag(raw) {
53
+ let value = raw.trim();
54
+ if (value.startsWith('W/'))
55
+ value = value.slice(2).trim();
56
+ if (value.length >= 2 && value.startsWith('"') && value.endsWith('"')) {
57
+ value = value.slice(1, -1);
58
+ }
59
+ return value;
60
+ }
61
+ const SHA256_HEX = /^[0-9a-f]{64}$/i;
62
+ /**
63
+ * Extract the Hugging Face Hub SHA-256 from a response's headers, if present.
64
+ * The Hub publishes it as `X-Linked-Etag` (and `ETag` for LFS files) — the
65
+ * content SHA-256 for LFS-backed files. A non-LFS file yields a git blob
66
+ * SHA-1 (40 hex) or a CDN etag instead; those are not SHA-256 and return
67
+ * undefined so the caller treats the download as unverifiable.
68
+ */
69
+ export function extractHubSha256(headers) {
70
+ const raw = firstHeaderValue(headers, 'x-linked-etag') ?? firstHeaderValue(headers, 'etag');
71
+ if (!raw)
72
+ return undefined;
73
+ const value = normalizeEtag(raw);
74
+ return SHA256_HEX.test(value) ? value.toLowerCase() : undefined;
75
+ }