@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
@@ -1,237 +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 { requestSchema, responseSchema, PROFILING_KEY, PROFILING_TRAILER_KEY, DELEGATION_BREAKDOWN_KEY, OPERATION_EVENT_KEY } from '../schemas/index.js';
8
- import { nowMs, extractProfilingMeta, stripProfilingMeta, recordFailure, generateId, createDelegatedProfilingMeta } from '../profiling/index.js';
9
- import { withTimeout, withTimeoutStream } from '../utils/withTimeout.js';
10
- import { getEngineLogger } from '../logging/index.js';
11
- import { DelegateProviderError } from '../errors/index.js';
12
- import { cleanupStaleConnection } from '../p2p/delegate-client.js';
13
- import { shouldProfileDelegation, createDelegationTimings, createDelegationStreamTimings, recordDelegationEvents, recordDelegationStreamEvents, buildDelegationStreamBreakdown, flushServerConnectionEvent, consumeBreakdownConnectionTime } from '../profiling/delegation-profiler.js';
14
- const logger = getEngineLogger();
15
- import { getNextCommandId } from '../p2p/rpc-utils.js';
16
- function checkAndThrowError(response) {
17
- if (response.type === 'error') {
18
- throw new DelegateProviderError(response.message || 'Unknown provider error', response.code);
19
- }
20
- }
21
- function isConnectionError(error) {
22
- return !(error instanceof DelegateProviderError);
23
- }
24
- function cleanupDelegationPeer(options, error) {
25
- if (!options?.peerKey)
26
- return;
27
- if (error !== undefined && !isConnectionError(error))
28
- return;
29
- cleanupStaleConnection(options.peerKey);
30
- }
31
- export async function send(request, rpc, options) {
32
- const { profilingMeta } = options ?? {};
33
- const shouldProfile = shouldProfileDelegation(request.type, profilingMeta);
34
- if (!shouldProfile) {
35
- return sendBase(request, rpc, options, profilingMeta);
36
- }
37
- return sendProfiled(request, rpc, options, profilingMeta);
38
- }
39
- async function sendBase(request, rpc, options, profilingMeta) {
40
- try {
41
- const parsedRequest = requestSchema.parse(request);
42
- const req = rpc.request(getNextCommandId());
43
- logger.debug('[delegate-transport] Sending:', { type: request.type });
44
- // Propagate per-call disable signal to delegated provider
45
- const finalRequest = profilingMeta?.enabled === false
46
- ? { ...parsedRequest, [PROFILING_KEY]: { enabled: false } }
47
- : parsedRequest;
48
- const payload = JSON.stringify(finalRequest);
49
- req.send(payload, 'utf-8');
50
- const response = await withTimeout(req.reply('utf-8'), options?.timeout);
51
- const rawPayload = JSON.parse(response?.toString() || '{}');
52
- const resPayload = responseSchema.parse(stripProfilingMeta(rawPayload));
53
- logger.debug('[delegate-transport] Response:', { type: resPayload.type });
54
- checkAndThrowError(resPayload);
55
- return resPayload;
56
- }
57
- catch (error) {
58
- cleanupDelegationPeer(options, error);
59
- throw error;
60
- }
61
- }
62
- async function sendProfiled(request, rpc, options, profilingMeta) {
63
- const profileId = profilingMeta?.id ?? generateId();
64
- const timings = createDelegationTimings(profileId, request.type);
65
- try {
66
- if (options?.peerKey) {
67
- flushServerConnectionEvent(options.peerKey);
68
- }
69
- const connectionMs = options?.peerKey
70
- ? consumeBreakdownConnectionTime(options.peerKey)
71
- : undefined;
72
- const parsedRequest = requestSchema.parse(request);
73
- const req = rpc.request(getNextCommandId());
74
- logger.debug('[delegate-transport] Sending (profiled):', {
75
- type: request.type
76
- });
77
- const stringifyStart = nowMs();
78
- const requestWithProfiling = {
79
- ...parsedRequest,
80
- [PROFILING_KEY]: createDelegatedProfilingMeta(profileId, profilingMeta)
81
- };
82
- const payload = JSON.stringify(requestWithProfiling);
83
- timings.requestStringifyMs = nowMs() - stringifyStart;
84
- timings.sendStart = nowMs();
85
- req.send(payload, 'utf-8');
86
- const response = await withTimeout(req.reply('utf-8'), options?.timeout);
87
- timings.firstResponseAt = nowMs();
88
- const parseStart = nowMs();
89
- const rawPayload = JSON.parse(response?.toString() || '{}');
90
- timings.responseJsonParseMs = nowMs() - parseStart;
91
- const serverMeta = extractProfilingMeta(rawPayload);
92
- const cleanPayload = stripProfilingMeta(rawPayload);
93
- const resPayload = responseSchema.parse(cleanPayload);
94
- logger.debug('[delegate-transport] Response (profiled):', {
95
- type: resPayload.type
96
- });
97
- checkAndThrowError(resPayload);
98
- const delegationBreakdown = recordDelegationEvents(timings, serverMeta, connectionMs);
99
- resPayload[DELEGATION_BREAKDOWN_KEY] = delegationBreakdown;
100
- if (serverMeta?.operation) {
101
- resPayload[OPERATION_EVENT_KEY] = serverMeta.operation;
102
- }
103
- return resPayload;
104
- }
105
- catch (error) {
106
- cleanupDelegationPeer(options, error);
107
- const base = {
108
- ts: nowMs(),
109
- op: timings.requestType,
110
- kind: 'delegation',
111
- profileId: timings.profileId
112
- };
113
- recordFailure(base, timings.requestStart, error);
114
- throw error;
115
- }
116
- }
117
- export async function* stream(request, rpc, options = {}) {
118
- const { profilingMeta } = options;
119
- const shouldProfile = shouldProfileDelegation(request.type, profilingMeta);
120
- if (!shouldProfile) {
121
- yield* streamBase(request, rpc, options, profilingMeta);
122
- return;
123
- }
124
- yield* streamProfiled(request, rpc, options, profilingMeta);
125
- }
126
- async function* streamBase(request, rpc, options = {}, profilingMeta) {
127
- try {
128
- const parsedRequest = requestSchema.parse(request);
129
- const req = rpc.request(getNextCommandId());
130
- logger.debug('[delegate-transport] Streaming:', { type: request.type });
131
- // Propagate per-call disable signal to delegated provider
132
- const finalRequest = profilingMeta?.enabled === false
133
- ? { ...parsedRequest, [PROFILING_KEY]: { enabled: false } }
134
- : parsedRequest;
135
- req.send(JSON.stringify(finalRequest), 'utf-8');
136
- const responseStream = req.createResponseStream({ encoding: 'utf-8' });
137
- let buffer = '';
138
- async function* processStream() {
139
- for await (const chunk of responseStream) {
140
- yield chunk;
141
- }
142
- }
143
- const streamWithTimeout = withTimeoutStream(processStream(), options?.timeout);
144
- for await (const chunk of streamWithTimeout) {
145
- buffer += chunk.toString();
146
- // Process complete lines (newline-delimited JSON)
147
- const lines = buffer.split('\n');
148
- buffer = lines.pop() || ''; // Keep incomplete line in buffer
149
- for (const line of lines) {
150
- if (!line.trim())
151
- continue;
152
- const rawPayload = JSON.parse(line);
153
- if (rawPayload[PROFILING_TRAILER_KEY] === true)
154
- continue;
155
- const response = responseSchema.parse(stripProfilingMeta(rawPayload));
156
- checkAndThrowError(response);
157
- yield response;
158
- }
159
- }
160
- }
161
- catch (error) {
162
- cleanupDelegationPeer(options, error);
163
- throw error;
164
- }
165
- }
166
- async function* streamProfiled(request, rpc, options = {}, profilingMeta) {
167
- const profileId = profilingMeta?.id ?? generateId();
168
- const timings = createDelegationStreamTimings(profileId, request.type);
169
- try {
170
- if (options.peerKey) {
171
- flushServerConnectionEvent(options.peerKey);
172
- }
173
- const parsedRequest = requestSchema.parse(request);
174
- const req = rpc.request(getNextCommandId());
175
- logger.debug('[delegate-transport] Streaming (profiled):', {
176
- type: request.type
177
- });
178
- const stringifyStart = nowMs();
179
- const requestWithProfiling = {
180
- ...parsedRequest,
181
- [PROFILING_KEY]: createDelegatedProfilingMeta(profileId, profilingMeta)
182
- };
183
- const payload = JSON.stringify(requestWithProfiling);
184
- timings.requestStringifyMs = nowMs() - stringifyStart;
185
- timings.sendStart = nowMs();
186
- req.send(payload, 'utf-8');
187
- const responseStream = req.createResponseStream({ encoding: 'utf-8' });
188
- let buffer = '';
189
- async function* processStream() {
190
- for await (const chunk of responseStream) {
191
- yield chunk;
192
- }
193
- }
194
- const streamWithTimeout = withTimeoutStream(processStream(), options?.timeout);
195
- let lastServerMeta;
196
- for await (const chunk of streamWithTimeout) {
197
- buffer += chunk.toString();
198
- const lines = buffer.split('\n');
199
- buffer = lines.pop() || '';
200
- for (const line of lines) {
201
- if (!line.trim())
202
- continue;
203
- const rawPayload = JSON.parse(line);
204
- const serverMeta = extractProfilingMeta(rawPayload);
205
- if (serverMeta) {
206
- lastServerMeta = serverMeta;
207
- }
208
- if (rawPayload[PROFILING_TRAILER_KEY] === true)
209
- continue;
210
- const response = responseSchema.parse(stripProfilingMeta(rawPayload));
211
- checkAndThrowError(response);
212
- timings.chunkCount++;
213
- if (timings.firstChunkAt === undefined) {
214
- timings.firstChunkAt = nowMs();
215
- }
216
- timings.lastChunkAt = nowMs();
217
- if (serverMeta?.operation) {
218
- response[OPERATION_EVENT_KEY] = serverMeta.operation;
219
- }
220
- response[DELEGATION_BREAKDOWN_KEY] = buildDelegationStreamBreakdown(timings);
221
- yield response;
222
- }
223
- }
224
- recordDelegationStreamEvents(timings, lastServerMeta);
225
- }
226
- catch (error) {
227
- cleanupDelegationPeer(options, error);
228
- const base = {
229
- ts: nowMs(),
230
- op: timings.requestType,
231
- kind: 'delegation',
232
- profileId: timings.profileId
233
- };
234
- recordFailure(base, timings.requestStart, error);
235
- throw error;
236
- }
237
- }
@@ -1,4 +0,0 @@
1
- import type RPC from 'bare-rpc';
2
- import { type ServerProfiler } from '../profiling/index.js';
3
- export declare function sendErrorResponse(req: RPC.IncomingRequest, error: unknown, profiler?: ServerProfiler): void;
4
- export declare function sendStreamErrorResponse(stream: ReturnType<RPC.IncomingRequest['createResponseStream']>, error: unknown, profiler?: ServerProfiler): void;
@@ -1,31 +0,0 @@
1
- import { createErrorResponse, responseSchema } from '../schemas/index.js';
2
- import { getEngineLogger } from '../logging/index.js';
3
- const logger = getEngineLogger();
4
- function buildErrorResponseData(error, profiler) {
5
- const errorResponse = createErrorResponse(error);
6
- const validated = responseSchema.parse(errorResponse);
7
- const json = JSON.stringify(validated);
8
- return profiler ? profiler.serializeError(json) : json;
9
- }
10
- export function sendErrorResponse(req, error, profiler) {
11
- try {
12
- req.reply(buildErrorResponseData(error, profiler), 'utf-8');
13
- }
14
- catch (responseError) {
15
- logger.error('Failed to create error response:', responseError);
16
- const fallbackError = createErrorResponse(new Error('Internal server error'));
17
- req.reply(JSON.stringify(fallbackError), 'utf-8');
18
- }
19
- }
20
- export function sendStreamErrorResponse(stream, error, profiler) {
21
- try {
22
- stream.write(buildErrorResponseData(error, profiler) + '\n', 'utf-8');
23
- stream.end();
24
- }
25
- catch (responseError) {
26
- logger.error('Failed to create stream error response:', responseError);
27
- const fallbackError = createErrorResponse(new Error('Internal server error'));
28
- stream.write(JSON.stringify(fallbackError) + '\n', 'utf-8');
29
- stream.end();
30
- }
31
- }
@@ -1,2 +0,0 @@
1
- import type RPC from 'bare-rpc';
2
- export declare function handleRequest(req: RPC.IncomingRequest): Promise<void>;
@@ -1,171 +0,0 @@
1
- import { requestSchema, normalizeModelType, PROFILING_KEY } from '../schemas/index.js';
2
- import { nowMs, createServerProfiler } from '../profiling/index.js';
3
- import { resolveModelConfig } from '../runtime/state.js';
4
- import { sendErrorResponse, sendStreamErrorResponse } from '../p2p/error-handlers.js';
5
- import { RPCUnknownRequestTypeError, PluginHandlerTypeMismatchError } from '../errors/index.js';
6
- import { registry } from '../registry.js';
7
- import { executeHandler, executeDuplexHandler, handleInitConfig, isInitConfigMessage, handleShutdown, isShutdownMessage } from '../p2p/handler-utils.js';
8
- import { assertLifecycleAllowed } from '../runtime/runtime-lifecycle.js';
9
- import { shouldUseStreamErrorTransport } from '../p2p/transport-selector.js';
10
- export async function handleRequest(req) {
11
- let profiler;
12
- let validationStart = 0;
13
- let rawRequest;
14
- let entry;
15
- try {
16
- const rawData = req.data?.toString();
17
- // Duplex stream request: metadata arrives as the first chunk on the
18
- // request stream (client used createRequestStream instead of send).
19
- if (!rawData) {
20
- await handleDuplexRequest(req);
21
- return;
22
- }
23
- // Timing runs unconditionally since we can't know if client
24
- // requested profiling until after parsing.
25
- const parseStart = nowMs();
26
- const jsonData = JSON.parse(rawData);
27
- const jsonParseMs = nowMs() - parseStart;
28
- // Handle internal config initialization (bypasses schema)
29
- if (isInitConfigMessage(jsonData)) {
30
- handleInitConfig(req, jsonData);
31
- return;
32
- }
33
- // Handle internal pre-terminate cleanup signal (bypasses schema). Lets
34
- // the host tear addons down while the JS env is still alive so static
35
- // js_ref_t state doesn't survive into the next isolate.
36
- if (isShutdownMessage(jsonData)) {
37
- await handleShutdown(req);
38
- return;
39
- }
40
- const { data: cleanData, profilingMeta } = extractProfilingMeta(jsonData);
41
- if (cleanData && typeof cleanData === 'object') {
42
- rawRequest = cleanData;
43
- const rawType = rawRequest['type'];
44
- if (typeof rawType === 'string') {
45
- entry = registry[rawType];
46
- }
47
- }
48
- profiler = createServerProfiler(profilingMeta);
49
- profiler.markRequestParsed(jsonParseMs);
50
- validationStart = nowMs();
51
- const processedData = applyDeviceDefaultsToRequest(cleanData);
52
- const request = requestSchema.parse(processedData);
53
- attachProfilingMetaToRequest(request, profilingMeta);
54
- profiler.markRequestValidated(nowMs() - validationStart);
55
- validationStart = 0;
56
- assertLifecycleAllowed(request);
57
- entry = registry[request.type];
58
- if (!entry) {
59
- throw new RPCUnknownRequestTypeError(request.type);
60
- }
61
- await executeHandler(req, request, entry, profiler);
62
- }
63
- catch (error) {
64
- if (profiler && validationStart > 0) {
65
- profiler.markRequestValidated(nowMs() - validationStart);
66
- }
67
- if (shouldUseStreamErrorTransport(entry, rawRequest)) {
68
- sendStreamErrorResponse(req.createResponseStream(), error, profiler);
69
- }
70
- else {
71
- sendErrorResponse(req, error, profiler);
72
- }
73
- }
74
- }
75
- function attachProfilingMetaToRequest(request, profilingMeta) {
76
- if (!profilingMeta)
77
- return;
78
- Object.defineProperty(request, PROFILING_KEY, {
79
- value: profilingMeta,
80
- enumerable: false,
81
- configurable: true,
82
- writable: false
83
- });
84
- }
85
- function extractProfilingMeta(data) {
86
- if (!data || typeof data !== 'object' || !(PROFILING_KEY in data)) {
87
- return { data, profilingMeta: undefined };
88
- }
89
- const obj = data;
90
- const { [PROFILING_KEY]: meta, ...rest } = obj;
91
- return {
92
- data: rest,
93
- profilingMeta: meta
94
- };
95
- }
96
- async function handleDuplexRequest(req) {
97
- const inputStream = req.createRequestStream();
98
- const outputStream = req.createResponseStream();
99
- let profiler;
100
- try {
101
- const firstChunk = await new Promise((resolve, reject) => {
102
- const onData = (data) => {
103
- inputStream.off('error', onError);
104
- inputStream.pause();
105
- resolve(data);
106
- };
107
- const onError = (err) => {
108
- inputStream.off('data', onData);
109
- reject(err instanceof Error ? err : new Error(String(err)));
110
- };
111
- inputStream.once('data', onData);
112
- inputStream.once('error', onError);
113
- });
114
- const parseStart = nowMs();
115
- const jsonData = JSON.parse(firstChunk.toString());
116
- const jsonParseMs = nowMs() - parseStart;
117
- const { data: cleanData, profilingMeta } = extractProfilingMeta(jsonData);
118
- profiler = createServerProfiler(profilingMeta);
119
- profiler.markRequestParsed(jsonParseMs);
120
- const validationStart = nowMs();
121
- const processedData = applyDeviceDefaultsToRequest(cleanData);
122
- const request = requestSchema.parse(processedData);
123
- attachProfilingMetaToRequest(request, profilingMeta);
124
- profiler.markRequestValidated(nowMs() - validationStart);
125
- assertLifecycleAllowed(request);
126
- const entry = registry[request.type];
127
- if (!entry) {
128
- throw new RPCUnknownRequestTypeError(request.type);
129
- }
130
- if (entry.type !== 'duplex') {
131
- throw new PluginHandlerTypeMismatchError(request.type, 'duplex', entry.type);
132
- }
133
- await executeDuplexHandler(req, request, entry, inputStream, outputStream, profiler);
134
- }
135
- catch (error) {
136
- inputStream.destroy();
137
- sendStreamErrorResponse(outputStream, error, profiler);
138
- }
139
- }
140
- /**
141
- * Apply device-specific config defaults to loadModel requests before schema parsing.
142
- * This ensures device defaults are applied before schema defaults.
143
- *
144
- * Priority: User config > Device defaults > Schema defaults
145
- */
146
- function applyDeviceDefaultsToRequest(data) {
147
- if (!data || typeof data !== 'object')
148
- return data;
149
- const obj = data;
150
- const requestType = obj['type'];
151
- // Only process loadModel requests (not reload config which uses modelId)
152
- if (requestType !== 'loadModel' || !obj['modelType'] || !('modelSrc' in obj)) {
153
- return data;
154
- }
155
- // Normalize model type to canonical form
156
- let canonicalType;
157
- try {
158
- canonicalType = normalizeModelType(obj['modelType']);
159
- }
160
- catch {
161
- // Invalid model type, let schema validation handle it
162
- return data;
163
- }
164
- // Apply device defaults and full schema defaults to modelConfig
165
- const rawConfig = obj['modelConfig'] ?? {};
166
- const configWithDefaults = resolveModelConfig(canonicalType, rawConfig);
167
- return {
168
- ...obj,
169
- modelConfig: configWithDefaults
170
- };
171
- }
@@ -1,19 +0,0 @@
1
- import { type QvacConfig, type Request, type RuntimeContext } from '../schemas/index.js';
2
- import type RPC from 'bare-rpc';
3
- import { type ServerProfiler } from '../profiling/index.js';
4
- import type { HandlerEntry } from '../handlers/types.js';
5
- export declare function executeDuplexHandler(_req: RPC.IncomingRequest, request: Request, entry: HandlerEntry, inputStream: ReturnType<RPC.IncomingRequest['createRequestStream']>, outputStream: ReturnType<RPC.IncomingRequest['createResponseStream']>, profiler: ServerProfiler): Promise<void>;
6
- export declare function executeHandler(req: RPC.IncomingRequest, request: Request, entry: HandlerEntry, profiler: ServerProfiler): Promise<void>;
7
- type InitConfigMessage = {
8
- type: '__init_config';
9
- config: QvacConfig;
10
- runtimeContext?: RuntimeContext;
11
- };
12
- export declare function isInitConfigMessage(data: unknown): data is InitConfigMessage;
13
- export declare function handleInitConfig(req: RPC.IncomingRequest, data: InitConfigMessage): void;
14
- type ShutdownMessage = {
15
- type: '__shutdown__';
16
- };
17
- export declare function isShutdownMessage(data: unknown): data is ShutdownMessage;
18
- export declare function handleShutdown(req: RPC.IncomingRequest): Promise<void>;
19
- export {};
@@ -1,180 +0,0 @@
1
- import { PROFILING_KEY } from '../schemas/index.js';
2
- import { sendErrorResponse, sendStreamErrorResponse } from '../p2p/error-handlers.js';
3
- import { PluginHandlerTypeMismatchError } from '../errors/index.js';
4
- import { setConfig, setRuntimeContext } from '../runtime/state.js';
5
- import { isTerminalChunk } from '../p2p/rpc-utils.js';
6
- import { createProgressThrottle } from '../p2p/progress-throttle.js';
7
- import { handlerSupportsProgress, selectHandler } from '../selection.js';
8
- function getProfilingMetaFromRequest(request) {
9
- if (PROFILING_KEY in request) {
10
- return request[PROFILING_KEY];
11
- }
12
- return undefined;
13
- }
14
- async function executeReplyHandler(req, request, handler, profiler, isDelegated) {
15
- profiler.startHandler();
16
- try {
17
- let response;
18
- if (isDelegated) {
19
- const profilingMeta = getProfilingMetaFromRequest(request);
20
- response = await handler(request, profilingMeta ? { profilingMeta } : undefined);
21
- }
22
- else {
23
- response = await handler(request);
24
- }
25
- profiler.endHandler();
26
- req.reply(profiler.serialize(response, true), 'utf-8');
27
- }
28
- catch (error) {
29
- profiler.endHandler();
30
- sendErrorResponse(req, error, profiler);
31
- }
32
- }
33
- async function executeStreamHandler(req, request, handler, profiler, isDelegated) {
34
- const stream = req.createResponseStream();
35
- profiler.startHandler();
36
- let sentFinalChunk = false;
37
- try {
38
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
- let generator;
40
- if (isDelegated) {
41
- const profilingMeta = getProfilingMetaFromRequest(request);
42
- generator = handler(request, profilingMeta ? { profilingMeta } : undefined);
43
- }
44
- else {
45
- generator = handler(request);
46
- }
47
- for await (const response of generator) {
48
- if (isTerminalChunk(response)) {
49
- profiler.endHandler();
50
- stream.write(profiler.serialize(response, true) + '\n', 'utf-8');
51
- sentFinalChunk = true;
52
- }
53
- else {
54
- stream.write(profiler.serialize(response, false) + '\n', 'utf-8');
55
- }
56
- }
57
- // Fallback
58
- if (!sentFinalChunk) {
59
- profiler.endHandler();
60
- const trailer = profiler.serialize();
61
- if (trailer) {
62
- stream.write(trailer + '\n', 'utf-8');
63
- }
64
- }
65
- stream.end();
66
- }
67
- catch (error) {
68
- profiler.endHandler();
69
- sendStreamErrorResponse(stream, error, profiler);
70
- }
71
- }
72
- async function executeProgressHandler(req, request, handler, profiler, isDelegated) {
73
- const stream = req.createResponseStream();
74
- profiler.startHandler();
75
- const writeBatch = (updates) => {
76
- const payload = updates.map((u) => profiler.serialize(u, false)).join('\n');
77
- stream.write(payload + '\n', 'utf-8');
78
- };
79
- const throttle = createProgressThrottle(writeBatch);
80
- try {
81
- let response;
82
- if (isDelegated) {
83
- const profilingMeta = getProfilingMetaFromRequest(request);
84
- const options = { progressCallback: throttle.push };
85
- if (profilingMeta) {
86
- options.profilingMeta = profilingMeta;
87
- }
88
- response = await handler(request, options);
89
- }
90
- else {
91
- response = await handler(request, throttle.push);
92
- }
93
- throttle.flush();
94
- profiler.endHandler();
95
- stream.write(profiler.serialize(response, true) + '\n', 'utf-8');
96
- stream.end();
97
- }
98
- catch (error) {
99
- throttle.flush();
100
- profiler.endHandler();
101
- sendStreamErrorResponse(stream, error, profiler);
102
- }
103
- }
104
- export async function executeDuplexHandler(_req, request, entry, inputStream, outputStream, profiler) {
105
- const { handler } = selectHandler(entry, request);
106
- profiler.startHandler();
107
- try {
108
- for await (const response of handler(request, inputStream)) {
109
- outputStream.write(profiler.serialize(response, false) + '\n', 'utf-8');
110
- }
111
- profiler.endHandler();
112
- const trailer = profiler.serialize();
113
- if (trailer) {
114
- outputStream.write(trailer + '\n', 'utf-8');
115
- }
116
- outputStream.end();
117
- }
118
- catch (error) {
119
- profiler.endHandler();
120
- sendStreamErrorResponse(outputStream, error, profiler);
121
- }
122
- }
123
- // Unified handler executor with delegation and progress support
124
- export async function executeHandler(req, request, entry, profiler) {
125
- const { handler, isDelegated } = selectHandler(entry, request);
126
- const wantsProgress = handlerSupportsProgress(entry, request);
127
- if (entry.type === 'duplex') {
128
- throw new PluginHandlerTypeMismatchError(request.type, 'reply or stream', 'duplex');
129
- }
130
- if (entry.type === 'stream') {
131
- await executeStreamHandler(req, request, handler, profiler, isDelegated);
132
- }
133
- else if (wantsProgress) {
134
- await executeProgressHandler(req, request, handler, profiler, isDelegated);
135
- }
136
- else {
137
- await executeReplyHandler(req, request, handler, profiler, isDelegated);
138
- }
139
- }
140
- export function isInitConfigMessage(data) {
141
- return (typeof data === 'object' && data !== null && 'type' in data && data.type === '__init_config');
142
- }
143
- export function handleInitConfig(req, data) {
144
- try {
145
- if (data.config) {
146
- setConfig(data.config);
147
- }
148
- if (data.runtimeContext) {
149
- setRuntimeContext(data.runtimeContext);
150
- }
151
- req.reply(JSON.stringify({ success: true }), 'utf-8');
152
- }
153
- catch (error) {
154
- req.reply(JSON.stringify({
155
- success: false,
156
- error: error instanceof Error ? error.message : String(error)
157
- }), 'utf-8');
158
- }
159
- }
160
- export function isShutdownMessage(data) {
161
- return (typeof data === 'object' &&
162
- data !== null &&
163
- 'type' in data &&
164
- data.type === '__shutdown__');
165
- }
166
- export async function handleShutdown(req) {
167
- try {
168
- // Lazy import to avoid an import cycle with `./lifecycle`. By the time
169
- // this runs, all modules are loaded.
170
- const { cleanupForTerminate } = await import('../runtime/lifecycle.js');
171
- await cleanupForTerminate();
172
- req.reply(JSON.stringify({ success: true }), 'utf-8');
173
- }
174
- catch (error) {
175
- req.reply(JSON.stringify({
176
- success: false,
177
- error: error instanceof Error ? error.message : String(error)
178
- }), 'utf-8');
179
- }
180
- }
@@ -1,3 +0,0 @@
1
- import type { HeartbeatRequest, HeartbeatResponse } from '../schemas/index.js';
2
- import type { DelegatedHandlerOptions } from '../profiling/index.js';
3
- export declare function handleHeartbeatDelegated(request: HeartbeatRequest, options?: DelegatedHandlerOptions): Promise<HeartbeatResponse>;