@qvac/inference 0.18.1 → 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,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { modelSrcInputSchema } from '../schemas/model-src-utils.js';
2
+ import { modelSrcInputSchema } from './model-src-utils.js';
3
3
  const BASE64_PATTERN = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
4
4
  const ABSOLUTE_PATH_PATTERN = /^(\/|[A-Za-z]:[\\/]|\\\\)/;
5
5
  const base64StringSchema = z.string().min(1).regex(BASE64_PATTERN);
@@ -32,6 +32,7 @@ const scheduleTypeSchema = z.enum([
32
32
  'kl_optimal',
33
33
  'bong_tangent'
34
34
  ]);
35
+ const videoScheduleTypeSchema = z.enum([...scheduleTypeSchema.options, 'ltx2']);
35
36
  const cacheModeSchema = z.enum([
36
37
  'disabled',
37
38
  'easycache',
@@ -42,7 +43,7 @@ const cacheModeSchema = z.enum([
42
43
  ]);
43
44
  export const sdcppConfigSchema = z.object({
44
45
  mode: z
45
- .enum(['diffusion', 'upscale', 'video'])
46
+ .enum(['diffusion', 'upscale', 'video', 'world'])
46
47
  .default('diffusion')
47
48
  .describe('Operation mode for the diffusion plugin. ' +
48
49
  "`'diffusion'` (default) builds a full SD / SDXL / SD3 / FLUX pipeline from " +
@@ -59,10 +60,18 @@ export const sdcppConfigSchema = z.object({
59
60
  'via `t5XxlModelSrc` + VAE). ' +
60
61
  'On React Native, loading the video model on-device will likely fail ' +
61
62
  'because the video diffusion models currently ' +
62
- 'shipped by QVAC are too large to load on typical mobile devices; ' +
63
- 'pass a `delegate` to `loadModel(...)` to run generation on a desktop peer instead.'),
64
- threads: z.number().optional(),
65
- device: z.enum(['gpu', 'cpu']).optional(),
63
+ 'shipped by QVAC are too large to load on typical mobile devices. ' +
64
+ "`'world'` builds an ABot-World interactive world session and exposes " +
65
+ 'worldCreateScene({ ... }) and worldStep({ ... }). It requires ' +
66
+ '`taehvModelSrc`, plus `t5XxlModelSrc` + `vaeModelSrc` to create scenes ' +
67
+ 'and/or `sceneSrc` to walk a pre-built one. World sessions run only on ' +
68
+ 'the machine hosting the worker and need a dedicated GPU with at least ' +
69
+ '20 GB free VRAM.'),
70
+ threads: z.number().optional().describe('CPU threads for loading and CPU ops. Default: auto.'),
71
+ device: z
72
+ .enum(['gpu', 'cpu'])
73
+ .optional()
74
+ .describe("Prefer GPU backends (`'gpu'`, default) or force CPU (`'cpu'`)."),
66
75
  'main-gpu': z
67
76
  .union([z.number().int().min(0), z.enum(['integrated', 'dedicated'])])
68
77
  .optional()
@@ -98,10 +107,26 @@ export const sdcppConfigSchema = z.object({
98
107
  ])
99
108
  .optional()
100
109
  .describe('Weight quantization type override; auto-detected when omitted'),
101
- rng: z.enum(['cpu', 'cuda', 'std_default']).optional(),
102
- sampler_rng: z.enum(['cpu', 'cuda', 'std_default']).optional(),
110
+ rng: z
111
+ .enum(['cpu', 'cuda', 'std_default'])
112
+ .optional()
113
+ .describe("Context RNG type: `'cpu'`, `'cuda'` (default; Philox, not GPU-specific), or `'std_default'`."),
114
+ sampler_rng: z
115
+ .enum(['cpu', 'cuda', 'std_default'])
116
+ .optional()
117
+ .describe('Sampler RNG type override. Default: auto (follows `rng`).'),
103
118
  clip_on_cpu: z.boolean().optional().describe('Force CLIP text encoder to run on CPU'),
104
119
  vae_on_cpu: z.boolean().optional().describe('Force VAE decoder to run on CPU'),
120
+ vae_auto_cpu_fallback: z
121
+ .boolean()
122
+ .optional()
123
+ .describe('Automatically move the VAE to CPU when GPU memory is insufficient'),
124
+ vae_auto_cpu_fallback_memory_ratio: z
125
+ .number()
126
+ .gt(0)
127
+ .max(1)
128
+ .optional()
129
+ .describe('GPU-memory threshold for automatic VAE CPU fallback as a ratio in (0, 1]'),
105
130
  vae_tiling: z.boolean().optional().describe('Enable VAE tiling for large images on limited VRAM'),
106
131
  offload_to_cpu: z
107
132
  .boolean()
@@ -115,14 +140,18 @@ export const sdcppConfigSchema = z.object({
115
140
  lora_apply_mode: z
116
141
  .enum(['auto', 'immediately', 'at_runtime'])
117
142
  .optional()
118
- .describe('How LoRA adapters passed via diffusion({ lora }) are applied. ' +
143
+ .describe('How LoRA adapters passed via diffusion({ lora }) or video({ lora }) are applied. ' +
119
144
  "'auto' (default): picked based on weight type — 'at_runtime' for " +
120
145
  "quantized weights, 'immediately' for full-precision. " +
121
146
  "'immediately': adapter is fused into the model on first use and " +
122
- 'persists across subsequent diffusion() calls until the model is ' +
147
+ 'persists across subsequent generation calls until the model is ' +
123
148
  'unloaded. ' +
124
- "'at_runtime': adapter is applied per-call and not persisted."),
125
- verbosity: z.number().optional(),
149
+ "'at_runtime': adapter is applied per-call and not persisted; use this mode " +
150
+ 'for the LTX Ingredients workflow.'),
151
+ verbosity: z
152
+ .number()
153
+ .optional()
154
+ .describe('Native log verbosity: `0`=ERROR, `1`=WARN, `2`=INFO, `3`=DEBUG. Default 0.'),
126
155
  clipLModelSrc: modelSrcInputSchema
127
156
  .optional()
128
157
  .describe('CLIP-L text encoder model — required for SD3'),
@@ -168,6 +197,85 @@ export const sdcppConfigSchema = z.object({
168
197
  'presence selects the LTX-2 video layout (Gemma text encoder via ' +
169
198
  '`llmModelSrc` + video VAE via `vaeModelSrc` + these connectors) instead ' +
170
199
  'of the Wan layout.'),
200
+ taehvModelSrc: modelSrcInputSchema
201
+ .optional()
202
+ .describe('taew2_2 streaming pixel decoder (`taew2_2_f16.gguf`) — required for ' +
203
+ "mode: 'world'. Decodes each generated block's latents to RGB frames. " +
204
+ 'Rejected in every other mode.'),
205
+ sceneSrc: modelSrcInputSchema
206
+ .optional()
207
+ .describe("Pre-built ABot-World scene pack (`.safetensors`) — mode: 'world' only. " +
208
+ 'Supplying it loads the walk session eagerly at loadModel time, so a ' +
209
+ 'bad pack fails fast. Omit it to start with no world and build one with ' +
210
+ 'worldCreateScene({ ... }), in which case the session activates on the ' +
211
+ 'first worldStep. Scene packs are produced by worldCreateScene and are ' +
212
+ 'specific to the resolution they were created at.'),
213
+ world: z
214
+ .object({
215
+ seed: z.number().int().optional().describe('Walk RNG seed.'),
216
+ // Mirrors parseAutoOrPositiveInt in the addon's WorldSessionHandlers.cpp:
217
+ // -1 or > 0. Zero and other negatives throw natively at load, after the
218
+ // multi-gigabyte artifacts have already been resolved.
219
+ threads: z
220
+ .union([z.literal(-1), z.number().int().positive()])
221
+ .optional()
222
+ .describe('CPU threads for the session. -1 = auto-detect (default).'),
223
+ backend: z
224
+ .string()
225
+ .min(1)
226
+ .optional()
227
+ .describe('Per-module backend override, e.g. "diffusion=cuda0,vae=cuda1" to keep ' +
228
+ 'scene creation off the walk GPU on a multi-GPU host.'),
229
+ // Both are parseIntInRange(..., 0, 1 << 10) natively.
230
+ numFramePerBlock: z
231
+ .number()
232
+ .int()
233
+ .min(0)
234
+ .max(64)
235
+ .optional()
236
+ .describe('Latent frames denoised per step. 0 = model default (3), and 64 is the ' +
237
+ 'ceiling. The native parser accepts up to 1024, but that is a range ' +
238
+ 'check rather than a memory budget: a block delivers roughly 4x this ' +
239
+ 'many decoded frames, so 1024 is ~4096 frames and several GB of raw ' +
240
+ 'pixels at 832x480 before any of it is encoded. 64 is ~20x the default ' +
241
+ 'and bounds a block at a few hundred MB.'),
242
+ localAttnSize: z
243
+ .number()
244
+ .int()
245
+ .min(0)
246
+ .max(1024)
247
+ .optional()
248
+ .describe('History attention window in latent frames. 0 = engine default (8). ' +
249
+ 'With `kvCache` the engine validates this against the compiled KV ' +
250
+ 'ring and fails at load on an unsupported combination.'),
251
+ offloadParamsToCpu: z
252
+ .boolean()
253
+ .optional()
254
+ .describe('Keep weights in CPU memory and offload during GPU compute.'),
255
+ frameJpegQuality: z
256
+ .number()
257
+ .int()
258
+ .min(0)
259
+ .max(100)
260
+ .optional()
261
+ .describe('Frame encoding. 0 (default) emits lossless PNG; 1..100 emits JPEG at ' +
262
+ 'that quality on the standard scale (higher = better quality and ' +
263
+ 'larger frames). A block is roughly 14 MB of raw pixels at 832x480 and ' +
264
+ 'the default numFramePerBlock — more at a higher resolution or a larger ' +
265
+ 'block — so 85 is a good choice whenever frames cross a process or ' +
266
+ 'network boundary.'),
267
+ kvCache: z
268
+ .boolean()
269
+ .optional()
270
+ .describe('Per-layer history KV cache (~3.7x fewer frame-passes per block). ' +
271
+ 'Costs ~1.2 GB more VRAM but keeps block times flat; without it they ' +
272
+ 'ramp from ~1.8 s to ~7.5 s as the recompute window fills.'),
273
+ profile: z.boolean().optional().describe('Per-stage timing logs from the native session.')
274
+ })
275
+ .strict()
276
+ .optional()
277
+ .describe("ABot-World session tuning — mode: 'world' only, rejected in every other " +
278
+ 'mode. Forwarded to the native session as-is.'),
171
279
  upscaler: z
172
280
  .object({
173
281
  type: z
@@ -451,9 +559,8 @@ const videoGenerationBaseSchema = z.object({
451
559
  modelId: z
452
560
  .string()
453
561
  .describe('The identifier of the loaded video model to use for generation. ' +
454
- 'On React Native, prefer a `modelId` loaded with a `delegate` because ' +
455
- 'the video diffusion models currently shipped by QVAC are too ' +
456
- 'large to load on typical mobile devices.'),
562
+ 'On React Native, the video diffusion models currently shipped by ' +
563
+ 'QVAC are too large to load on typical mobile devices.'),
457
564
  requestId: z
458
565
  .string()
459
566
  .min(1)
@@ -464,6 +571,32 @@ const videoGenerationBaseSchema = z.object({
464
571
  .string()
465
572
  .optional()
466
573
  .describe('Optional negative prompt describing what to avoid.'),
574
+ lora: z
575
+ .string()
576
+ .min(1)
577
+ .regex(ABSOLUTE_PATH_PATTERN, {
578
+ message: 'lora must be an absolute path'
579
+ })
580
+ .optional()
581
+ .describe('LTX video only. Worker-local absolute path to a LoRA adapter.'),
582
+ lora_strength: z
583
+ .number()
584
+ .min(0)
585
+ .max(10)
586
+ .optional()
587
+ .describe('LTX video only. Runtime LoRA multiplier in [0, 10]; requires lora.'),
588
+ stg_scale: z
589
+ .number()
590
+ .min(0)
591
+ .max(10)
592
+ .optional()
593
+ .describe('LTX video only. Spatiotemporal guidance scale in [0, 10].'),
594
+ stg_block: z
595
+ .number()
596
+ .int()
597
+ .nonnegative()
598
+ .optional()
599
+ .describe('LTX video only. Transformer block skipped for spatiotemporal guidance.'),
467
600
  width: z
468
601
  .number()
469
602
  .int()
@@ -514,7 +647,7 @@ const videoGenerationBaseSchema = z.object({
514
647
  sampling_method: samplingMethodSchema
515
648
  .optional()
516
649
  .describe('Sampling algorithm used by the low-noise diffusion scheduler.'),
517
- scheduler: scheduleTypeSchema
650
+ scheduler: videoScheduleTypeSchema
518
651
  .optional()
519
652
  .describe('Noise schedule to apply for the low-noise diffusion path.'),
520
653
  cfg_scale: z.number().optional().describe('Classifier-free guidance scale.'),
@@ -597,7 +730,22 @@ const videoRequestObjectSchema = videoGenerationBaseSchema.extend({
597
730
  .min(0)
598
731
  .max(1)
599
732
  .optional()
600
- .describe('img2vid denoise strength in [0, 1]; rejected for txt2vid.')
733
+ .describe('img2vid denoise strength in [0, 1]; rejected for txt2vid.'),
734
+ reference_images: z
735
+ .array(base64StringSchema)
736
+ .length(1)
737
+ .optional()
738
+ .describe('LTX txt2vid only. Exactly one base64-encoded composite reference sheet; requires lora.'),
739
+ reference_attention_strength: z
740
+ .number()
741
+ .min(0)
742
+ .max(1)
743
+ .optional()
744
+ .describe('LTX txt2vid only. Reference denoise-mask strength in [0, 1]; requires reference_images.'),
745
+ reference_downscale_factor: z
746
+ .literal(1)
747
+ .optional()
748
+ .describe('LTX txt2vid only. Reference-image spatial factor; currently exactly 1.')
601
749
  });
602
750
  function refineVideoMode(data, ctx) {
603
751
  if (data.mode === 'img2vid' && data.init_image === undefined) {
@@ -623,6 +771,22 @@ function refineVideoMode(data, ctx) {
623
771
  });
624
772
  }
625
773
  }
774
+ if (data.mode === 'img2vid') {
775
+ const referenceFields = [
776
+ 'reference_images',
777
+ 'reference_attention_strength',
778
+ 'reference_downscale_factor'
779
+ ];
780
+ for (const field of referenceFields) {
781
+ if (data[field] === undefined)
782
+ continue;
783
+ ctx.addIssue({
784
+ code: 'custom',
785
+ path: [field],
786
+ message: `${field} is only valid for txt2vid.`
787
+ });
788
+ }
789
+ }
626
790
  }
627
791
  export const videoRequestSchema = videoRequestObjectSchema.superRefine(refineVideoMode);
628
792
  function refineLtxVideoRequest(data, ctx) {
@@ -648,8 +812,81 @@ function refineLtxVideoRequest(data, ctx) {
648
812
  message: 'LTX-2 video_frames must be at most 257 and satisfy (8*k + 1), where k>=1.'
649
813
  });
650
814
  }
815
+ if (data.lora_strength !== undefined && data.lora === undefined) {
816
+ ctx.addIssue({
817
+ code: 'custom',
818
+ path: ['lora_strength'],
819
+ message: 'lora_strength requires lora.'
820
+ });
821
+ }
822
+ if (data.reference_images !== undefined) {
823
+ if (data.lora === undefined) {
824
+ ctx.addIssue({
825
+ code: 'custom',
826
+ path: ['reference_images'],
827
+ message: 'reference_images requires lora.'
828
+ });
829
+ }
830
+ if (data.video_frames === undefined || data.video_frames < 121) {
831
+ ctx.addIssue({
832
+ code: 'custom',
833
+ path: ['video_frames'],
834
+ message: 'LTX reference conditioning requires video_frames to be explicitly set to at least 121.'
835
+ });
836
+ }
837
+ }
838
+ else {
839
+ for (const field of ['reference_attention_strength', 'reference_downscale_factor']) {
840
+ if (data[field] === undefined)
841
+ continue;
842
+ ctx.addIssue({
843
+ code: 'custom',
844
+ path: [field],
845
+ message: `${field} requires reference_images.`
846
+ });
847
+ }
848
+ }
651
849
  }
652
850
  export const ltxVideoRequestSchema = videoRequestSchema.superRefine(refineLtxVideoRequest);
851
+ const nonLtxVideoMask = {
852
+ lora: true,
853
+ lora_strength: true,
854
+ stg_scale: true,
855
+ stg_block: true,
856
+ reference_images: true,
857
+ reference_attention_strength: true,
858
+ reference_downscale_factor: true,
859
+ scheduler: true
860
+ };
861
+ const nonLtxVideoSchema = videoRequestObjectSchema.pick(nonLtxVideoMask);
862
+ const nonLtxVideoFields = [
863
+ 'lora',
864
+ 'lora_strength',
865
+ 'stg_scale',
866
+ 'stg_block',
867
+ 'reference_images',
868
+ 'reference_attention_strength',
869
+ 'reference_downscale_factor'
870
+ ];
871
+ function refineNonLtxVideoRequest(data, ctx) {
872
+ for (const field of nonLtxVideoFields) {
873
+ if (data[field] === undefined)
874
+ continue;
875
+ ctx.addIssue({
876
+ code: 'custom',
877
+ path: [field],
878
+ message: `${field} is only supported by LTX video models.`
879
+ });
880
+ }
881
+ if (data.scheduler === 'ltx2') {
882
+ ctx.addIssue({
883
+ code: 'custom',
884
+ path: ['scheduler'],
885
+ message: "scheduler 'ltx2' is only supported by LTX video models."
886
+ });
887
+ }
888
+ }
889
+ export const nonLtxVideoRequestSchema = nonLtxVideoSchema.superRefine(refineNonLtxVideoRequest);
653
890
  const wan22MoeMask = {
654
891
  high_noise_steps: true,
655
892
  high_noise_sampler: true,
@@ -746,3 +983,253 @@ export const upscaleStreamResponseSchema = z.object({
746
983
  done: z.boolean().optional(),
747
984
  stats: upscaleStatsSchema.optional()
748
985
  });
986
+ // ============================================
987
+ // ABot-World interactive world sessions (mode: "world")
988
+ // ============================================
989
+ export const walkKeySchema = z.enum(['W', 'A', 'S', 'D', 'I', 'J', 'K', 'L']);
990
+ export const worldStepStatsSchema = z.object({
991
+ modelLoadMs: z
992
+ .number()
993
+ .optional()
994
+ .describe('Time in milliseconds spent loading the DiT, decoder and scene pack.'),
995
+ stepMs: z
996
+ .number()
997
+ .optional()
998
+ .describe('Generation time in milliseconds for this block, excluding frame encoding.'),
999
+ totalStepMs: z
1000
+ .number()
1001
+ .optional()
1002
+ .describe('Cumulative generation time in milliseconds across the session.'),
1003
+ totalSteps: z
1004
+ .number()
1005
+ .int()
1006
+ .optional()
1007
+ .describe('Number of blocks generated so far in this session; resets when the session reloads.'),
1008
+ totalFrames: z
1009
+ .number()
1010
+ .int()
1011
+ .optional()
1012
+ .describe('Cumulative frames delivered across the session.'),
1013
+ frames: z
1014
+ .number()
1015
+ .int()
1016
+ .optional()
1017
+ .describe('Frames delivered for this block — 9 for the first block after a load ' +
1018
+ '(decoder warmup), 12 thereafter at the default numFramePerBlock.'),
1019
+ width: z.number().int().optional().describe('Frame width in pixels.'),
1020
+ height: z.number().int().optional().describe('Frame height in pixels.'),
1021
+ actionMask: z
1022
+ .number()
1023
+ .int()
1024
+ .optional()
1025
+ .describe('The 8-bit key mask this block was generated under (bit 0..7 = W,A,S,D,I,J,K,L).')
1026
+ });
1027
+ export const worldSceneStatsSchema = z.object({
1028
+ sceneCreateMs: z
1029
+ .number()
1030
+ .optional()
1031
+ .describe('Wall-clock time in milliseconds for the scene pack: loading the prompt ' +
1032
+ 'and image encoders, encoding both, and writing the pack.'),
1033
+ width: z.number().int().optional().describe('Scene width in pixels, baked into the pack.'),
1034
+ height: z.number().int().optional().describe('Scene height in pixels, baked into the pack.')
1035
+ });
1036
+ export const worldStepRequestSchema = z.object({
1037
+ modelId: z
1038
+ .string()
1039
+ .describe("Identifier of a model loaded with modelConfig.mode: 'world'. The session " +
1040
+ 'activates on the first step when no sceneSrc was supplied at load.'),
1041
+ requestId: z
1042
+ .string()
1043
+ .min(1)
1044
+ .optional()
1045
+ .describe('Stable identifier for this in-flight block, for cancel(). Optional on the ' +
1046
+ 'wire — the server generates one when the field is missing.'),
1047
+ keys: z
1048
+ .array(walkKeySchema)
1049
+ .optional()
1050
+ .describe('Keys held for this block. WASD move, IJKL steer the camera; duplicates are ' +
1051
+ 'collapsed. Omit or pass an empty array to idle.')
1052
+ });
1053
+ export const worldStepStreamRequestSchema = worldStepRequestSchema.extend({
1054
+ type: z.literal('worldStepStream')
1055
+ });
1056
+ export const worldStepStreamResponseSchema = z.object({
1057
+ type: z.literal('worldStepStream'),
1058
+ // Same three fields, same names, as diffusionStream and videoStream: the
1059
+ // engine's own tick, forwarded rather than dropped.
1060
+ //
1061
+ // It is NOT mid-block liveness, and cannot be. WorldSessionModel.cpp runs
1062
+ // sd_abot_session_step() to completion, delivers every frame, and only then
1063
+ // fires its progress callback — exactly once per block, after the frames.
1064
+ // So this arrives as an end-of-block summary. A caller wanting a "still
1065
+ // working" signal during the 1.8-7.5s a block takes needs an addon change;
1066
+ // do not build a hang detector on this.
1067
+ step: z
1068
+ .number()
1069
+ .int()
1070
+ .optional()
1071
+ .describe("The engine's own `step` counter, forwarded verbatim: blocks completed on " +
1072
+ 'this session. One tick is emitted per block, after its frames, so this ' +
1073
+ 'is not progress within a block.'),
1074
+ totalSteps: z
1075
+ .number()
1076
+ .int()
1077
+ .optional()
1078
+ .describe('Frames DELIVERED by the block that just finished — a final count, not a ' +
1079
+ 'running one, because the engine emits this after the frames rather than ' +
1080
+ 'during. Named `totalSteps` only so the wire shape matches videoStream ' +
1081
+ 'and diffusionStream, where that slot holds a sampler-step total.'),
1082
+ elapsedMs: z.number().optional().describe('Milliseconds elapsed within this block so far.'),
1083
+ data: z
1084
+ .string()
1085
+ .optional()
1086
+ .describe('Base64 of one decoded frame — PNG, or JPEG when world.frameJpegQuality is 1..100.'),
1087
+ frameIndex: z
1088
+ .number()
1089
+ .int()
1090
+ .optional()
1091
+ .describe('Zero-based index of this frame within the block.'),
1092
+ done: z.boolean().optional(),
1093
+ stats: worldStepStatsSchema.optional()
1094
+ });
1095
+ /**
1096
+ * Per-axis ceiling for a generated world. Neither the SDK nor the addon bounded
1097
+ * these before: the addon checks only "positive multiple of 32", and the pack
1098
+ * ceiling in ops/world.ts runs after native generation has already allocated the
1099
+ * GPU buffers and written the file, so it cannot prevent the OOM.
1100
+ */
1101
+ export const MAX_SCENE_DIMENSION = 4096;
1102
+ /**
1103
+ * Total pixel budget, ~1080p rounded onto the 32 grid. Bounds the product as
1104
+ * well as each axis, so 4096x4096 is refused even though both axes pass. The
1105
+ * validated 832x480 tier sits 5x under it.
1106
+ */
1107
+ export const MAX_SCENE_PIXELS = 1920 * 1088;
1108
+ /**
1109
+ * Ceiling on the ENCODED first frame — what crosses the wire, not what the
1110
+ * decoder allocates. Those differ by orders of magnitude for a compressed
1111
+ * format, so this is not the decompression-bomb guard; the declared-dimension
1112
+ * check in `ops/world.ts` is. This one keeps a multi-megabyte base64 string off
1113
+ * the worker in the first place.
1114
+ *
1115
+ * 3 MB is generous for a frame that ends up at most 1920x1088 — and it is also
1116
+ * the largest value this can be *enforced* at today. `BASE64_PATTERN` is a
1117
+ * starred quad group that both engines give up on a little above this ceiling,
1118
+ * but differently, and the difference matters: measured at 4.8M characters, JSC
1119
+ * (Bun) returns `false`, while **V8 — which is what Bare runs — THROWS
1120
+ * `RangeError: Maximum call stack size exceeded`**. Since Zod runs every string
1121
+ * check regardless of order, a larger image reaches the pattern even after
1122
+ * `.max()` fails, so `safeParse` throws instead of reporting `too_big`.
1123
+ * 3 MB decodes to 4194304 characters, inside the range that still matches on
1124
+ * both. The client guards the raw byte length before encoding for the same
1125
+ * reason (see `createWorldSceneResult`). The pattern is shared with the
1126
+ * diffusion, upscale and VLA image fields, so fixing it belongs in its own
1127
+ * change.
1128
+ */
1129
+ export const MAX_SCENE_IMAGE_BYTES = 3 * 1024 * 1024;
1130
+ /**
1131
+ * Base64 characters for `MAX_SCENE_IMAGE_BYTES`, four per three bytes. The
1132
+ * ceiling is enforced on the encoded length rather than the decoded one so it
1133
+ * costs a string compare instead of a decode — and, since padding only ever
1134
+ * shortens the payload, a string within this many characters can never exceed
1135
+ * `MAX_SCENE_IMAGE_BYTES` once decoded.
1136
+ */
1137
+ export const MAX_SCENE_IMAGE_BASE64_CHARS = (MAX_SCENE_IMAGE_BYTES / 3) * 4;
1138
+ /**
1139
+ * Cross-field ceilings for a scene request. Kept as a named function because
1140
+ * both the plain and the stream request schema have to enforce it, and because
1141
+ * the pixel budget is a contract worth testing directly.
1142
+ */
1143
+ export function refineWorldSceneBudget(value, ctx) {
1144
+ const width = value.width ?? 832;
1145
+ const height = value.height ?? 480;
1146
+ if (width * height > MAX_SCENE_PIXELS) {
1147
+ ctx.addIssue({
1148
+ code: 'custom',
1149
+ path: ['width'],
1150
+ message: `A ${width}x${height} world is ${width * height} pixels, over the ` +
1151
+ `${MAX_SCENE_PIXELS}-pixel ceiling. Scene creation allocates for the full ` +
1152
+ 'frame before anything can check the result, so this is refused up front.'
1153
+ });
1154
+ }
1155
+ // The encoded-size ceiling is a `.max()` on the field rather than a check here.
1156
+ // Note Zod runs every check on a string regardless of order, so an oversized
1157
+ // image collects the `too_big` issue AND whatever BASE64_PATTERN reports — the
1158
+ // ordering only decides which reads first, it does not short-circuit. See
1159
+ // MAX_SCENE_IMAGE_BYTES for why the pattern cannot be relied on at that size.
1160
+ }
1161
+ const worldSceneRequestShape = {
1162
+ modelId: z.string().describe("Identifier of a model loaded with modelConfig.mode: 'world'."),
1163
+ requestId: z
1164
+ .string()
1165
+ .min(1)
1166
+ .optional()
1167
+ .describe('Stable identifier for this scene creation. Note that scene creation cannot ' +
1168
+ 'be interrupted — the engine exposes no abort hook — so cancelling it stops ' +
1169
+ 'the SDK from yielding, but the encode runs to completion.'),
1170
+ prompt: z
1171
+ .string()
1172
+ .min(1)
1173
+ .describe('Scene prompt, encoded verbatim by umT5-XXL. The reference pipeline prefixes ' +
1174
+ 'prompts with "| unknown | ".'),
1175
+ image: z
1176
+ .string()
1177
+ .min(1)
1178
+ // Declared before the pattern so an oversized frame reports its size instead
1179
+ // of failing as malformed base64.
1180
+ .max(MAX_SCENE_IMAGE_BASE64_CHARS)
1181
+ .regex(BASE64_PATTERN)
1182
+ .describe('Base64 PNG/JPEG bytes of the first frame, up to 3 MB decoded and 8192x8192 ' +
1183
+ 'pixels. It is cover-scaled and center-cropped to width x height, so a ' +
1184
+ 'frame larger than the target resolution buys nothing. The pixel ceiling ' +
1185
+ 'is read from the image header and enforced by the worker before anything ' +
1186
+ 'decodes it, so a compressed image that expands to gigabytes is refused ' +
1187
+ 'rather than allocated.'),
1188
+ width: z
1189
+ .number()
1190
+ .int()
1191
+ .positive()
1192
+ .multipleOf(32)
1193
+ .max(MAX_SCENE_DIMENSION)
1194
+ .optional()
1195
+ .describe('Scene width in pixels, a multiple of 32, at most 4096. Defaults to 832. ' +
1196
+ 'width x height must also stay within 2088960 pixels (1920x1088). That ' +
1197
+ 'product rule is a cross-field constraint, so it is NOT expressed in the ' +
1198
+ 'generated JSON Schema or Python client — those validate each axis only, ' +
1199
+ 'and the combined limit is enforced by the worker, which rejects the ' +
1200
+ 'request before any GPU memory is allocated.'),
1201
+ height: z
1202
+ .number()
1203
+ .int()
1204
+ .positive()
1205
+ .multipleOf(32)
1206
+ .max(MAX_SCENE_DIMENSION)
1207
+ .optional()
1208
+ .describe('Scene height in pixels, a multiple of 32, at most 4096. Defaults to 480. ' +
1209
+ 'See `width` for the total-pixel ceiling, which bounds the product as ' +
1210
+ 'well as each axis and is enforced server-side.'),
1211
+ returnPack: z
1212
+ .boolean()
1213
+ .optional()
1214
+ .describe('Return the generated scene pack in the response. Off by default: the pack ' +
1215
+ 'is 10+ MB (a third larger again as base64) and the common ' +
1216
+ 'create-then-walk-now flow never touches the bytes — the world is already ' +
1217
+ 'live on the session. Turn it on to persist a world, then pass the saved ' +
1218
+ 'file back as modelConfig.sceneSrc on a later load to walk it again.')
1219
+ };
1220
+ export const worldSceneRequestSchema = z
1221
+ .object(worldSceneRequestShape)
1222
+ .superRefine(refineWorldSceneBudget);
1223
+ export const worldSceneStreamRequestSchema = z
1224
+ .object({ ...worldSceneRequestShape, type: z.literal('worldSceneStream') })
1225
+ .superRefine(refineWorldSceneBudget);
1226
+ export const worldSceneStreamResponseSchema = z.object({
1227
+ type: z.literal('worldSceneStream'),
1228
+ data: z
1229
+ .string()
1230
+ .optional()
1231
+ .describe('Base64 of the finished scene pack (~10 MB). Persist it and pass it back as ' +
1232
+ 'modelConfig.sceneSrc to walk the same world again later.'),
1233
+ done: z.boolean().optional(),
1234
+ stats: worldSceneStatsSchema.optional()
1235
+ });