@atomic-chat/core 0.5.1 → 0.13.2

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 (970) hide show
  1. package/README.md +22 -0
  2. package/dist/app-daemon.js +20 -67
  3. package/dist/app-daemon.js.map +1 -1
  4. package/dist/backend/advisor/advisor.d.ts +132 -0
  5. package/dist/backend/advisor/advisor.js +537 -0
  6. package/dist/backend/advisor/advisor.js.map +1 -0
  7. package/dist/backend/advisor/index.d.ts +6 -0
  8. package/dist/backend/advisor/index.js +7 -0
  9. package/dist/backend/advisor/index.js.map +1 -0
  10. package/dist/backend/advisor/policy.d.ts +81 -0
  11. package/dist/backend/advisor/policy.js +154 -0
  12. package/dist/backend/advisor/policy.js.map +1 -0
  13. package/dist/backend/catalog/archive.d.ts +21 -7
  14. package/dist/backend/catalog/archive.js +57 -17
  15. package/dist/backend/catalog/archive.js.map +1 -1
  16. package/dist/backend/catalog/bundled-manifest-baseline.js +42 -26
  17. package/dist/backend/catalog/bundled-manifest-baseline.js.map +1 -1
  18. package/dist/backend/catalog/cuda-family.d.ts +12 -2
  19. package/dist/backend/catalog/cuda-family.js +30 -7
  20. package/dist/backend/catalog/cuda-family.js.map +1 -1
  21. package/dist/backend/catalog/index.d.ts +5 -0
  22. package/dist/backend/catalog/index.js +5 -0
  23. package/dist/backend/catalog/index.js.map +1 -1
  24. package/dist/backend/catalog/manifest.d.ts +5 -3
  25. package/dist/backend/catalog/manifest.js +12 -9
  26. package/dist/backend/catalog/manifest.js.map +1 -1
  27. package/dist/backend/catalog/migrate.d.ts +8 -6
  28. package/dist/backend/catalog/migrate.js +26 -15
  29. package/dist/backend/catalog/migrate.js.map +1 -1
  30. package/dist/backend/catalog/prism-catalog.d.ts +42 -0
  31. package/dist/backend/catalog/prism-catalog.js +101 -0
  32. package/dist/backend/catalog/prism-catalog.js.map +1 -0
  33. package/dist/backend/catalog/prism-manifest-baseline.d.ts +2 -0
  34. package/dist/backend/catalog/prism-manifest-baseline.js +11 -0
  35. package/dist/backend/catalog/prism-manifest-baseline.js.map +1 -0
  36. package/dist/backend/catalog/prism-manifest-baseline.json +134 -0
  37. package/dist/backend/catalog/prism-manifest.d.ts +90 -0
  38. package/dist/backend/catalog/prism-manifest.js +171 -0
  39. package/dist/backend/catalog/prism-manifest.js.map +1 -0
  40. package/dist/backend/catalog/turboquant-catalog.d.ts +60 -0
  41. package/dist/backend/catalog/turboquant-catalog.js +162 -0
  42. package/dist/backend/catalog/turboquant-catalog.js.map +1 -0
  43. package/dist/backend/catalog/turboquant-index.d.ts +104 -0
  44. package/dist/backend/catalog/turboquant-index.js +260 -0
  45. package/dist/backend/catalog/turboquant-index.js.map +1 -0
  46. package/dist/backend/index.d.ts +1 -0
  47. package/dist/backend/index.js +1 -0
  48. package/dist/backend/index.js.map +1 -1
  49. package/dist/backend/install/runtime-backend.d.ts +6 -6
  50. package/dist/backend/install/runtime-backend.js +23 -20
  51. package/dist/backend/install/runtime-backend.js.map +1 -1
  52. package/dist/backend/install/service.d.ts +106 -5
  53. package/dist/backend/install/service.js +247 -21
  54. package/dist/backend/install/service.js.map +1 -1
  55. package/dist/backend/installed/bundled.d.ts +19 -0
  56. package/dist/backend/installed/bundled.js +45 -0
  57. package/dist/backend/installed/bundled.js.map +1 -0
  58. package/dist/backend/installed/index.d.ts +1 -0
  59. package/dist/backend/installed/index.js +1 -0
  60. package/dist/backend/installed/index.js.map +1 -1
  61. package/dist/backend/installed/installed.js +3 -0
  62. package/dist/backend/installed/installed.js.map +1 -1
  63. package/dist/backend/optimal/optimal-cache.d.ts +27 -8
  64. package/dist/backend/optimal/optimal-cache.js +38 -19
  65. package/dist/backend/optimal/optimal-cache.js.map +1 -1
  66. package/dist/backend/optimal/optimal-store.js +1 -1
  67. package/dist/backend/optimal/optimal-store.js.map +1 -1
  68. package/dist/backend/select/categories.d.ts +2 -1
  69. package/dist/backend/select/categories.js +8 -1
  70. package/dist/backend/select/categories.js.map +1 -1
  71. package/dist/backend/select/features.d.ts +13 -5
  72. package/dist/backend/select/features.js +36 -6
  73. package/dist/backend/select/features.js.map +1 -1
  74. package/dist/backend/select/index.d.ts +2 -0
  75. package/dist/backend/select/index.js +2 -0
  76. package/dist/backend/select/index.js.map +1 -1
  77. package/dist/backend/select/prism.d.ts +54 -0
  78. package/dist/backend/select/prism.js +212 -0
  79. package/dist/backend/select/prism.js.map +1 -0
  80. package/dist/backend/select/recovery.d.ts +4 -2
  81. package/dist/backend/select/recovery.js +17 -5
  82. package/dist/backend/select/recovery.js.map +1 -1
  83. package/dist/backend/select/tiers.d.ts +20 -11
  84. package/dist/backend/select/tiers.js +49 -11
  85. package/dist/backend/select/tiers.js.map +1 -1
  86. package/dist/backend/select/turboquant-tiers.d.ts +45 -0
  87. package/dist/backend/select/turboquant-tiers.js +114 -0
  88. package/dist/backend/select/turboquant-tiers.js.map +1 -0
  89. package/dist/backend/types.d.ts +6 -69
  90. package/dist/cli/commands/backends.d.ts +10 -0
  91. package/dist/cli/commands/backends.js +142 -0
  92. package/dist/cli/commands/backends.js.map +1 -0
  93. package/dist/cli/commands/hardware.d.ts +13 -0
  94. package/dist/cli/commands/hardware.js +71 -0
  95. package/dist/cli/commands/hardware.js.map +1 -0
  96. package/dist/cli/commands/host-step.d.ts +28 -0
  97. package/dist/cli/commands/host-step.js +67 -0
  98. package/dist/cli/commands/host-step.js.map +1 -0
  99. package/dist/cli/commands/index.d.ts +4 -1
  100. package/dist/cli/commands/index.js +4 -1
  101. package/dist/cli/commands/index.js.map +1 -1
  102. package/dist/cli/commands/serve.js +4 -4
  103. package/dist/cli/commands/serve.js.map +1 -1
  104. package/dist/cli/commands/shared.d.ts +6 -1
  105. package/dist/cli/commands/shared.js +7 -0
  106. package/dist/cli/commands/shared.js.map +1 -1
  107. package/dist/cli/io.d.ts +11 -0
  108. package/dist/cli/io.js +28 -3
  109. package/dist/cli/io.js.map +1 -1
  110. package/dist/cli/launch.js +2 -2
  111. package/dist/cli/launch.js.map +1 -1
  112. package/dist/cli/main.d.ts +1 -1
  113. package/dist/cli/main.js +11 -1
  114. package/dist/cli/main.js.map +1 -1
  115. package/dist/client/control-client.d.ts +128 -7
  116. package/dist/client/control-client.js +211 -12
  117. package/dist/client/control-client.js.map +1 -1
  118. package/dist/cloud/registry.js +9 -1
  119. package/dist/cloud/registry.js.map +1 -1
  120. package/dist/config/paths.d.ts +137 -0
  121. package/dist/config/paths.js +163 -0
  122. package/dist/config/paths.js.map +1 -1
  123. package/dist/contracts/backend-advisor.d.ts +225 -0
  124. package/dist/contracts/backend-advisor.js +14 -0
  125. package/dist/contracts/backend-advisor.js.map +1 -0
  126. package/dist/contracts/control-api.d.ts +7 -1
  127. package/dist/contracts/control-api.js +7 -1
  128. package/dist/contracts/control-api.js.map +1 -1
  129. package/dist/contracts/decision.d.ts +394 -0
  130. package/dist/contracts/decision.js +69 -0
  131. package/dist/contracts/decision.js.map +1 -0
  132. package/dist/contracts/diffusion.d.ts +62 -9
  133. package/dist/contracts/embedding.d.ts +103 -0
  134. package/dist/contracts/embedding.js +24 -0
  135. package/dist/contracts/embedding.js.map +1 -0
  136. package/dist/contracts/engine-builds.d.ts +108 -0
  137. package/dist/contracts/engine-builds.js +11 -0
  138. package/dist/contracts/engine-builds.js.map +1 -0
  139. package/dist/contracts/engines.d.ts +157 -0
  140. package/dist/contracts/engines.js +50 -0
  141. package/dist/contracts/engines.js.map +1 -0
  142. package/dist/contracts/environment.d.ts +774 -0
  143. package/dist/contracts/environment.js +116 -0
  144. package/dist/contracts/environment.js.map +1 -0
  145. package/dist/contracts/errors.d.ts +43 -2
  146. package/dist/contracts/errors.js +41 -0
  147. package/dist/contracts/errors.js.map +1 -1
  148. package/dist/contracts/events.d.ts +82 -4
  149. package/dist/contracts/hardware.d.ts +79 -6
  150. package/dist/contracts/hardware.js +9 -5
  151. package/dist/contracts/hardware.js.map +1 -1
  152. package/dist/contracts/index.d.ts +8 -0
  153. package/dist/contracts/index.js +8 -0
  154. package/dist/contracts/index.js.map +1 -1
  155. package/dist/contracts/model-compatibility.d.ts +97 -0
  156. package/dist/contracts/model-compatibility.js +6 -0
  157. package/dist/contracts/model-compatibility.js.map +1 -0
  158. package/dist/contracts/model-setup.d.ts +115 -0
  159. package/dist/contracts/model-setup.js +33 -0
  160. package/dist/contracts/model-setup.js.map +1 -0
  161. package/dist/contracts/model-yml.d.ts +14 -0
  162. package/dist/contracts/model-yml.js +1 -0
  163. package/dist/contracts/model-yml.js.map +1 -1
  164. package/dist/contracts/session.d.ts +45 -2
  165. package/dist/contracts/session.js +14 -1
  166. package/dist/contracts/session.js.map +1 -1
  167. package/dist/contracts/settings.d.ts +44 -1
  168. package/dist/contracts/settings.js.map +1 -1
  169. package/dist/core/atomic-core.d.ts +44 -5
  170. package/dist/core/atomic-core.js +24 -0
  171. package/dist/core/atomic-core.js.map +1 -1
  172. package/dist/core/create.js +517 -23
  173. package/dist/core/create.js.map +1 -1
  174. package/dist/core/gpu/index.d.ts +6 -0
  175. package/dist/core/gpu/index.js +7 -0
  176. package/dist/core/gpu/index.js.map +1 -0
  177. package/dist/core/gpu/policy.d.ts +68 -0
  178. package/dist/core/gpu/policy.js +99 -0
  179. package/dist/core/gpu/policy.js.map +1 -0
  180. package/dist/core/gpu/residency.d.ts +44 -0
  181. package/dist/core/gpu/residency.js +101 -0
  182. package/dist/core/gpu/residency.js.map +1 -0
  183. package/dist/core/gpu-residency.d.ts +39 -0
  184. package/dist/core/gpu-residency.js +32 -0
  185. package/dist/core/gpu-residency.js.map +1 -0
  186. package/dist/core/index.d.ts +1 -1
  187. package/dist/core/managed-engines.d.ts +207 -0
  188. package/dist/core/managed-engines.js +579 -0
  189. package/dist/core/managed-engines.js.map +1 -0
  190. package/dist/core/managed-environment.d.ts +72 -0
  191. package/dist/core/managed-environment.js +218 -0
  192. package/dist/core/managed-environment.js.map +1 -0
  193. package/dist/core/model-setup/index.d.ts +4 -0
  194. package/dist/core/model-setup/index.js +5 -0
  195. package/dist/core/model-setup/index.js.map +1 -0
  196. package/dist/core/model-setup/plan.d.ts +56 -0
  197. package/dist/core/model-setup/plan.js +158 -0
  198. package/dist/core/model-setup/plan.js.map +1 -0
  199. package/dist/core/model-setup/service.d.ts +92 -0
  200. package/dist/core/model-setup/service.js +329 -0
  201. package/dist/core/model-setup/service.js.map +1 -0
  202. package/dist/core/model-setup/store.d.ts +29 -0
  203. package/dist/core/model-setup/store.js +116 -0
  204. package/dist/core/model-setup/store.js.map +1 -0
  205. package/dist/core/model-setup/wiring.d.ts +59 -0
  206. package/dist/core/model-setup/wiring.js +132 -0
  207. package/dist/core/model-setup/wiring.js.map +1 -0
  208. package/dist/core/prism.d.ts +36 -0
  209. package/dist/core/prism.js +42 -0
  210. package/dist/core/prism.js.map +1 -0
  211. package/dist/core/public-server.d.ts +7 -0
  212. package/dist/core/public-server.js +2 -0
  213. package/dist/core/public-server.js.map +1 -1
  214. package/dist/core/sessions.d.ts +6 -1
  215. package/dist/core/sessions.js +18 -14
  216. package/dist/core/sessions.js.map +1 -1
  217. package/dist/core/types.d.ts +27 -1
  218. package/dist/core/types.js.map +1 -1
  219. package/dist/decision/args.d.ts +110 -0
  220. package/dist/decision/args.js +126 -0
  221. package/dist/decision/args.js.map +1 -0
  222. package/dist/decision/backoff.d.ts +25 -0
  223. package/dist/decision/backoff.js +33 -0
  224. package/dist/decision/backoff.js.map +1 -0
  225. package/dist/decision/engine-candidates.d.ts +52 -0
  226. package/dist/decision/engine-candidates.js +138 -0
  227. package/dist/decision/engine-candidates.js.map +1 -0
  228. package/dist/decision/engine-fallback.d.ts +41 -0
  229. package/dist/decision/engine-fallback.js +57 -0
  230. package/dist/decision/engine-fallback.js.map +1 -0
  231. package/dist/decision/engine-version.d.ts +27 -0
  232. package/dist/decision/engine-version.js +54 -0
  233. package/dist/decision/engine-version.js.map +1 -0
  234. package/dist/decision/engine.d.ts +114 -0
  235. package/dist/decision/engine.js +253 -0
  236. package/dist/decision/engine.js.map +1 -0
  237. package/dist/decision/http.d.ts +36 -0
  238. package/dist/decision/http.js +73 -0
  239. package/dist/decision/http.js.map +1 -0
  240. package/dist/decision/index.d.ts +20 -0
  241. package/dist/decision/index.js +21 -0
  242. package/dist/decision/index.js.map +1 -0
  243. package/dist/decision/model-facts.d.ts +32 -0
  244. package/dist/decision/model-facts.js +40 -0
  245. package/dist/decision/model-facts.js.map +1 -0
  246. package/dist/decision/outcome.d.ts +35 -0
  247. package/dist/decision/outcome.js +105 -0
  248. package/dist/decision/outcome.js.map +1 -0
  249. package/dist/decision/process.d.ts +67 -0
  250. package/dist/decision/process.js +133 -0
  251. package/dist/decision/process.js.map +1 -0
  252. package/dist/decision/readiness.d.ts +74 -0
  253. package/dist/decision/readiness.js +165 -0
  254. package/dist/decision/readiness.js.map +1 -0
  255. package/dist/decision/request.d.ts +11 -0
  256. package/dist/decision/request.js +56 -0
  257. package/dist/decision/request.js.map +1 -0
  258. package/dist/decision/service.d.ts +202 -0
  259. package/dist/decision/service.js +711 -0
  260. package/dist/decision/service.js.map +1 -0
  261. package/dist/decision/upstream-version.d.ts +23 -0
  262. package/dist/decision/upstream-version.js +34 -0
  263. package/dist/decision/upstream-version.js.map +1 -0
  264. package/dist/decision/wiring.d.ts +67 -0
  265. package/dist/decision/wiring.js +101 -0
  266. package/dist/decision/wiring.js.map +1 -0
  267. package/dist/diffusion/args.d.ts +4 -2
  268. package/dist/diffusion/args.js +10 -3
  269. package/dist/diffusion/args.js.map +1 -1
  270. package/dist/diffusion/image-job.js +1 -1
  271. package/dist/diffusion/image-job.js.map +1 -1
  272. package/dist/diffusion/install.d.ts +35 -11
  273. package/dist/diffusion/install.js +74 -49
  274. package/dist/diffusion/install.js.map +1 -1
  275. package/dist/diffusion/job-kind.d.ts +33 -7
  276. package/dist/diffusion/jobs.d.ts +6 -1
  277. package/dist/diffusion/jobs.js +60 -18
  278. package/dist/diffusion/jobs.js.map +1 -1
  279. package/dist/diffusion/parse.d.ts +1 -2
  280. package/dist/diffusion/parse.js +1 -13
  281. package/dist/diffusion/parse.js.map +1 -1
  282. package/dist/diffusion/progress.js +3 -0
  283. package/dist/diffusion/progress.js.map +1 -1
  284. package/dist/diffusion/server-process.d.ts +6 -0
  285. package/dist/diffusion/server-process.js +3 -2
  286. package/dist/diffusion/server-process.js.map +1 -1
  287. package/dist/diffusion/service.d.ts +52 -6
  288. package/dist/diffusion/service.js +215 -40
  289. package/dist/diffusion/service.js.map +1 -1
  290. package/dist/diffusion/session.d.ts +27 -3
  291. package/dist/diffusion/session.js +108 -17
  292. package/dist/diffusion/session.js.map +1 -1
  293. package/dist/diffusion/state.d.ts +19 -1
  294. package/dist/diffusion/state.js +10 -0
  295. package/dist/diffusion/state.js.map +1 -1
  296. package/dist/diffusion/tracker.d.ts +15 -1
  297. package/dist/diffusion/tracker.js +32 -6
  298. package/dist/diffusion/tracker.js.map +1 -1
  299. package/dist/diffusion/types.d.ts +7 -0
  300. package/dist/diffusion/types.js +11 -0
  301. package/dist/diffusion/types.js.map +1 -1
  302. package/dist/diffusion/video-estimate.d.ts +214 -0
  303. package/dist/diffusion/video-estimate.js +402 -0
  304. package/dist/diffusion/video-estimate.js.map +1 -0
  305. package/dist/diffusion/video-eta.d.ts +90 -0
  306. package/dist/diffusion/video-eta.js +248 -0
  307. package/dist/diffusion/video-eta.js.map +1 -0
  308. package/dist/diffusion/video-history.d.ts +45 -0
  309. package/dist/diffusion/video-history.js +121 -0
  310. package/dist/diffusion/video-history.js.map +1 -0
  311. package/dist/diffusion/video-job.d.ts +13 -5
  312. package/dist/diffusion/video-job.js +42 -15
  313. package/dist/diffusion/video-job.js.map +1 -1
  314. package/dist/diffusion/video-recipe.js +3 -0
  315. package/dist/diffusion/video-recipe.js.map +1 -1
  316. package/dist/diffusion/video-tiling.d.ts +54 -0
  317. package/dist/diffusion/video-tiling.js +70 -0
  318. package/dist/diffusion/video-tiling.js.map +1 -0
  319. package/dist/diffusion/wiring.d.ts +14 -1
  320. package/dist/diffusion/wiring.js +7 -0
  321. package/dist/diffusion/wiring.js.map +1 -1
  322. package/dist/downloads/protocol.d.ts +3 -8
  323. package/dist/downloads/protocol.js.map +1 -1
  324. package/dist/embedding/args.d.ts +39 -0
  325. package/dist/embedding/args.js +46 -0
  326. package/dist/embedding/args.js.map +1 -0
  327. package/dist/embedding/engine.d.ts +50 -0
  328. package/dist/embedding/engine.js +100 -0
  329. package/dist/embedding/engine.js.map +1 -0
  330. package/dist/embedding/ffmpeg.d.ts +18 -0
  331. package/dist/embedding/ffmpeg.js +63 -0
  332. package/dist/embedding/ffmpeg.js.map +1 -0
  333. package/dist/embedding/index.d.ts +16 -0
  334. package/dist/embedding/index.js +17 -0
  335. package/dist/embedding/index.js.map +1 -0
  336. package/dist/embedding/model-facts.d.ts +51 -0
  337. package/dist/embedding/model-facts.js +84 -0
  338. package/dist/embedding/model-facts.js.map +1 -0
  339. package/dist/embedding/process.d.ts +66 -0
  340. package/dist/embedding/process.js +131 -0
  341. package/dist/embedding/process.js.map +1 -0
  342. package/dist/embedding/readiness.d.ts +56 -0
  343. package/dist/embedding/readiness.js +114 -0
  344. package/dist/embedding/readiness.js.map +1 -0
  345. package/dist/embedding/request.d.ts +43 -0
  346. package/dist/embedding/request.js +285 -0
  347. package/dist/embedding/request.js.map +1 -0
  348. package/dist/embedding/service.d.ts +152 -0
  349. package/dist/embedding/service.js +602 -0
  350. package/dist/embedding/service.js.map +1 -0
  351. package/dist/embedding/wiring.d.ts +51 -0
  352. package/dist/embedding/wiring.js +79 -0
  353. package/dist/embedding/wiring.js.map +1 -0
  354. package/dist/engine-builds/builds.d.ts +54 -0
  355. package/dist/engine-builds/builds.js +151 -0
  356. package/dist/engine-builds/builds.js.map +1 -0
  357. package/dist/engine-builds/index.d.ts +10 -0
  358. package/dist/engine-builds/index.js +11 -0
  359. package/dist/engine-builds/index.js.map +1 -0
  360. package/dist/engine-builds/install.d.ts +42 -0
  361. package/dist/engine-builds/install.js +100 -0
  362. package/dist/engine-builds/install.js.map +1 -0
  363. package/dist/engine-builds/manifest.d.ts +121 -0
  364. package/dist/engine-builds/manifest.js +254 -0
  365. package/dist/engine-builds/manifest.js.map +1 -0
  366. package/dist/engine-builds/order.d.ts +24 -0
  367. package/dist/engine-builds/order.js +44 -0
  368. package/dist/engine-builds/order.js.map +1 -0
  369. package/dist/engine-builds/select.d.ts +123 -0
  370. package/dist/engine-builds/select.js +223 -0
  371. package/dist/engine-builds/select.js.map +1 -0
  372. package/dist/engine-builds/service.d.ts +123 -0
  373. package/dist/engine-builds/service.js +392 -0
  374. package/dist/engine-builds/service.js.map +1 -0
  375. package/dist/engines/descriptor-order.d.ts +28 -0
  376. package/dist/engines/descriptor-order.js +60 -0
  377. package/dist/engines/descriptor-order.js.map +1 -0
  378. package/dist/engines/engine-build.d.ts +23 -0
  379. package/dist/engines/engine-build.js +58 -0
  380. package/dist/engines/engine-build.js.map +1 -0
  381. package/dist/engines/index.d.ts +10 -0
  382. package/dist/engines/index.js +11 -0
  383. package/dist/engines/index.js.map +1 -0
  384. package/dist/engines/llamacpp.d.ts +71 -0
  385. package/dist/engines/llamacpp.js +176 -0
  386. package/dist/engines/llamacpp.js.map +1 -0
  387. package/dist/engines/managed.d.ts +49 -0
  388. package/dist/engines/managed.js +88 -0
  389. package/dist/engines/managed.js.map +1 -0
  390. package/dist/engines/service.d.ts +46 -0
  391. package/dist/engines/service.js +61 -0
  392. package/dist/engines/service.js.map +1 -0
  393. package/dist/engines/versions.d.ts +65 -0
  394. package/dist/engines/versions.js +259 -0
  395. package/dist/engines/versions.js.map +1 -0
  396. package/dist/hardware/cpu-flags.d.ts +44 -0
  397. package/dist/hardware/cpu-flags.js +206 -0
  398. package/dist/hardware/cpu-flags.js.map +1 -0
  399. package/dist/hardware/drm-sysfs.d.ts +51 -0
  400. package/dist/hardware/drm-sysfs.js +67 -0
  401. package/dist/hardware/drm-sysfs.js.map +1 -0
  402. package/dist/hardware/facts.d.ts +42 -0
  403. package/dist/hardware/facts.js +92 -0
  404. package/dist/hardware/facts.js.map +1 -0
  405. package/dist/hardware/index.d.ts +19 -3
  406. package/dist/hardware/index.js +19 -3
  407. package/dist/hardware/index.js.map +1 -1
  408. package/dist/hardware/merge.d.ts +55 -0
  409. package/dist/hardware/merge.js +141 -0
  410. package/dist/hardware/merge.js.map +1 -0
  411. package/dist/hardware/nvidia-smi.d.ts +43 -0
  412. package/dist/hardware/nvidia-smi.js +118 -0
  413. package/dist/hardware/nvidia-smi.js.map +1 -0
  414. package/dist/hardware/probe-common.d.ts +72 -0
  415. package/dist/hardware/probe-common.js +106 -0
  416. package/dist/hardware/probe-common.js.map +1 -0
  417. package/dist/hardware/probe-darwin.d.ts +20 -0
  418. package/dist/hardware/probe-darwin.js +76 -0
  419. package/dist/hardware/probe-darwin.js.map +1 -0
  420. package/dist/hardware/probe-linux.d.ts +9 -0
  421. package/dist/hardware/probe-linux.js +133 -0
  422. package/dist/hardware/probe-linux.js.map +1 -0
  423. package/dist/hardware/probe-windows.d.ts +7 -0
  424. package/dist/hardware/probe-windows.js +50 -0
  425. package/dist/hardware/probe-windows.js.map +1 -0
  426. package/dist/hardware/probe.d.ts +16 -0
  427. package/dist/hardware/probe.js +65 -0
  428. package/dist/hardware/probe.js.map +1 -0
  429. package/dist/hardware/service.d.ts +60 -0
  430. package/dist/hardware/service.js +114 -0
  431. package/dist/hardware/service.js.map +1 -0
  432. package/dist/hardware/vulkan.d.ts +47 -0
  433. package/dist/hardware/vulkan.js +148 -0
  434. package/dist/hardware/vulkan.js.map +1 -0
  435. package/dist/hardware/windows-video.d.ts +97 -0
  436. package/dist/hardware/windows-video.js +214 -0
  437. package/dist/hardware/windows-video.js.map +1 -0
  438. package/dist/host/app-daemon.d.ts +47 -0
  439. package/dist/host/app-daemon.js +146 -0
  440. package/dist/host/app-daemon.js.map +1 -0
  441. package/dist/host/index.d.ts +5 -3
  442. package/dist/host/index.js +5 -3
  443. package/dist/host/index.js.map +1 -1
  444. package/dist/host/log-file.d.ts +74 -0
  445. package/dist/host/log-file.js +214 -0
  446. package/dist/host/log-file.js.map +1 -0
  447. package/dist/host/recipes/enable-wsl.d.ts +63 -0
  448. package/dist/host/recipes/enable-wsl.js +73 -0
  449. package/dist/host/recipes/enable-wsl.js.map +1 -0
  450. package/dist/host/recipes/executor-io-windows.d.ts +69 -0
  451. package/dist/host/recipes/executor-io-windows.js +235 -0
  452. package/dist/host/recipes/executor-io-windows.js.map +1 -0
  453. package/dist/host/recipes/executor-io.d.ts +80 -0
  454. package/dist/host/recipes/executor-io.js +211 -0
  455. package/dist/host/recipes/executor-io.js.map +1 -0
  456. package/dist/host/recipes/executor.d.ts +81 -0
  457. package/dist/host/recipes/executor.js +678 -0
  458. package/dist/host/recipes/executor.js.map +1 -0
  459. package/dist/host/recipes/guest-executor.d.ts +29 -0
  460. package/dist/host/recipes/guest-executor.js +76 -0
  461. package/dist/host/recipes/guest-executor.js.map +1 -0
  462. package/dist/host/recipes/index.d.ts +16 -0
  463. package/dist/host/recipes/index.js +17 -0
  464. package/dist/host/recipes/index.js.map +1 -0
  465. package/dist/host/recipes/install-container-runtime.d.ts +389 -0
  466. package/dist/host/recipes/install-container-runtime.js +796 -0
  467. package/dist/host/recipes/install-container-runtime.js.map +1 -0
  468. package/dist/host/recipes/openpgp.d.ts +23 -0
  469. package/dist/host/recipes/openpgp.js +153 -0
  470. package/dist/host/recipes/openpgp.js.map +1 -0
  471. package/dist/host/recipes/request-file.d.ts +96 -0
  472. package/dist/host/recipes/request-file.js +103 -0
  473. package/dist/host/recipes/request-file.js.map +1 -0
  474. package/dist/lock/process-journal.d.ts +5 -2
  475. package/dist/lock/process-journal.js.map +1 -1
  476. package/dist/models/capabilities.d.ts +7 -0
  477. package/dist/models/capabilities.js +17 -1
  478. package/dist/models/capabilities.js.map +1 -1
  479. package/dist/models/compatibility/index.d.ts +10 -0
  480. package/dist/models/compatibility/index.js +11 -0
  481. package/dist/models/compatibility/index.js.map +1 -0
  482. package/dist/models/compatibility/inspect.d.ts +19 -0
  483. package/dist/models/compatibility/inspect.js +59 -0
  484. package/dist/models/compatibility/inspect.js.map +1 -0
  485. package/dist/models/compatibility/resolve.d.ts +59 -0
  486. package/dist/models/compatibility/resolve.js +219 -0
  487. package/dist/models/compatibility/resolve.js.map +1 -0
  488. package/dist/models/compatibility/rules-baseline.d.ts +2 -0
  489. package/dist/models/compatibility/rules-baseline.js +10 -0
  490. package/dist/models/compatibility/rules-baseline.js.map +1 -0
  491. package/dist/models/compatibility/rules-baseline.json +292 -0
  492. package/dist/models/compatibility/rules-service.d.ts +36 -0
  493. package/dist/models/compatibility/rules-service.js +109 -0
  494. package/dist/models/compatibility/rules-service.js.map +1 -0
  495. package/dist/models/compatibility/rules.d.ts +81 -0
  496. package/dist/models/compatibility/rules.js +164 -0
  497. package/dist/models/compatibility/rules.js.map +1 -0
  498. package/dist/models/compatibility/service.d.ts +59 -0
  499. package/dist/models/compatibility/service.js +137 -0
  500. package/dist/models/compatibility/service.js.map +1 -0
  501. package/dist/models/decision-checkpoint.d.ts +22 -0
  502. package/dist/models/decision-checkpoint.js +33 -0
  503. package/dist/models/decision-checkpoint.js.map +1 -0
  504. package/dist/models/gguf/classify.d.ts +27 -1
  505. package/dist/models/gguf/classify.js +78 -2
  506. package/dist/models/gguf/classify.js.map +1 -1
  507. package/dist/models/gguf/index.d.ts +1 -0
  508. package/dist/models/gguf/index.js +1 -0
  509. package/dist/models/gguf/index.js.map +1 -1
  510. package/dist/models/gguf/tensors.d.ts +56 -0
  511. package/dist/models/gguf/tensors.js +236 -0
  512. package/dist/models/gguf/tensors.js.map +1 -0
  513. package/dist/models/index.d.ts +2 -0
  514. package/dist/models/index.js +2 -0
  515. package/dist/models/index.js.map +1 -1
  516. package/dist/router/resolve.d.ts +7 -1
  517. package/dist/router/resolve.js +14 -1
  518. package/dist/router/resolve.js.map +1 -1
  519. package/dist/runtime/container/argv.d.ts +88 -0
  520. package/dist/runtime/container/argv.js +406 -0
  521. package/dist/runtime/container/argv.js.map +1 -0
  522. package/dist/runtime/container/docker-binary.d.ts +4 -0
  523. package/dist/runtime/container/docker-binary.js +34 -0
  524. package/dist/runtime/container/docker-binary.js.map +1 -0
  525. package/dist/runtime/container/env.d.ts +17 -0
  526. package/dist/runtime/container/env.js +52 -0
  527. package/dist/runtime/container/env.js.map +1 -0
  528. package/dist/runtime/container/exec.d.ts +27 -0
  529. package/dist/runtime/container/exec.js +79 -0
  530. package/dist/runtime/container/exec.js.map +1 -0
  531. package/dist/runtime/container/execution-journal.d.ts +55 -0
  532. package/dist/runtime/container/execution-journal.js +167 -0
  533. package/dist/runtime/container/execution-journal.js.map +1 -0
  534. package/dist/runtime/container/heartbeat.d.ts +47 -0
  535. package/dist/runtime/container/heartbeat.js +78 -0
  536. package/dist/runtime/container/heartbeat.js.map +1 -0
  537. package/dist/runtime/container/index.d.ts +30 -0
  538. package/dist/runtime/container/index.js +31 -0
  539. package/dist/runtime/container/index.js.map +1 -0
  540. package/dist/runtime/container/operations.d.ts +40 -0
  541. package/dist/runtime/container/operations.js +233 -0
  542. package/dist/runtime/container/operations.js.map +1 -0
  543. package/dist/runtime/container/pull.d.ts +48 -0
  544. package/dist/runtime/container/pull.js +280 -0
  545. package/dist/runtime/container/pull.js.map +1 -0
  546. package/dist/runtime/container/reconcile.d.ts +34 -0
  547. package/dist/runtime/container/reconcile.js +79 -0
  548. package/dist/runtime/container/reconcile.js.map +1 -0
  549. package/dist/runtime/container/types.d.ts +124 -0
  550. package/dist/runtime/container/types.js +2 -0
  551. package/dist/runtime/container/types.js.map +1 -0
  552. package/dist/runtime/container/watchdog.d.ts +114 -0
  553. package/dist/runtime/container/watchdog.js +418 -0
  554. package/dist/runtime/container/watchdog.js.map +1 -0
  555. package/dist/runtime/container/wiring.d.ts +78 -0
  556. package/dist/runtime/container/wiring.js +92 -0
  557. package/dist/runtime/container/wiring.js.map +1 -0
  558. package/dist/runtime/container/wsl-exec.d.ts +13 -0
  559. package/dist/runtime/container/wsl-exec.js +18 -0
  560. package/dist/runtime/container/wsl-exec.js.map +1 -0
  561. package/dist/runtime/environment/cached-document.d.ts +128 -0
  562. package/dist/runtime/environment/cached-document.js +218 -0
  563. package/dist/runtime/environment/cached-document.js.map +1 -0
  564. package/dist/runtime/environment/canonical-json.d.ts +78 -0
  565. package/dist/runtime/environment/canonical-json.js +86 -0
  566. package/dist/runtime/environment/canonical-json.js.map +1 -0
  567. package/dist/runtime/environment/descriptor-provider.d.ts +121 -0
  568. package/dist/runtime/environment/descriptor-provider.js +159 -0
  569. package/dist/runtime/environment/descriptor-provider.js.map +1 -0
  570. package/dist/runtime/environment/descriptor.d.ts +35 -0
  571. package/dist/runtime/environment/descriptor.js +239 -0
  572. package/dist/runtime/environment/descriptor.js.map +1 -0
  573. package/dist/runtime/environment/diagnostics.d.ts +50 -0
  574. package/dist/runtime/environment/diagnostics.js +114 -0
  575. package/dist/runtime/environment/diagnostics.js.map +1 -0
  576. package/dist/runtime/environment/document-fields.d.ts +39 -0
  577. package/dist/runtime/environment/document-fields.js +96 -0
  578. package/dist/runtime/environment/document-fields.js.map +1 -0
  579. package/dist/runtime/environment/environment-manifest-provider.d.ts +65 -0
  580. package/dist/runtime/environment/environment-manifest-provider.js +89 -0
  581. package/dist/runtime/environment/environment-manifest-provider.js.map +1 -0
  582. package/dist/runtime/environment/environment-manifest.d.ts +35 -0
  583. package/dist/runtime/environment/environment-manifest.js +131 -0
  584. package/dist/runtime/environment/environment-manifest.js.map +1 -0
  585. package/dist/runtime/environment/guest-host.d.ts +43 -0
  586. package/dist/runtime/environment/guest-host.js +88 -0
  587. package/dist/runtime/environment/guest-host.js.map +1 -0
  588. package/dist/runtime/environment/host-exec.d.ts +38 -0
  589. package/dist/runtime/environment/host-exec.js +145 -0
  590. package/dist/runtime/environment/host-exec.js.map +1 -0
  591. package/dist/runtime/environment/host-step-failure.d.ts +33 -0
  592. package/dist/runtime/environment/host-step-failure.js +34 -0
  593. package/dist/runtime/environment/host-step-failure.js.map +1 -0
  594. package/dist/runtime/environment/index.d.ts +56 -0
  595. package/dist/runtime/environment/index.js +57 -0
  596. package/dist/runtime/environment/index.js.map +1 -0
  597. package/dist/runtime/environment/installations.d.ts +25 -0
  598. package/dist/runtime/environment/installations.js +70 -0
  599. package/dist/runtime/environment/installations.js.map +1 -0
  600. package/dist/runtime/environment/inventory.d.ts +42 -0
  601. package/dist/runtime/environment/inventory.js +57 -0
  602. package/dist/runtime/environment/inventory.js.map +1 -0
  603. package/dist/runtime/environment/linux-blockers.d.ts +130 -0
  604. package/dist/runtime/environment/linux-blockers.js +251 -0
  605. package/dist/runtime/environment/linux-blockers.js.map +1 -0
  606. package/dist/runtime/environment/linux-docker-facts.d.ts +200 -0
  607. package/dist/runtime/environment/linux-docker-facts.js +342 -0
  608. package/dist/runtime/environment/linux-docker-facts.js.map +1 -0
  609. package/dist/runtime/environment/linux-docker-network.d.ts +80 -0
  610. package/dist/runtime/environment/linux-docker-network.js +195 -0
  611. package/dist/runtime/environment/linux-docker-network.js.map +1 -0
  612. package/dist/runtime/environment/linux-host.d.ts +22 -0
  613. package/dist/runtime/environment/linux-host.js +98 -0
  614. package/dist/runtime/environment/linux-host.js.map +1 -0
  615. package/dist/runtime/environment/linux-plan.d.ts +126 -0
  616. package/dist/runtime/environment/linux-plan.js +392 -0
  617. package/dist/runtime/environment/linux-plan.js.map +1 -0
  618. package/dist/runtime/environment/linux-probe.d.ts +245 -0
  619. package/dist/runtime/environment/linux-probe.js +315 -0
  620. package/dist/runtime/environment/linux-probe.js.map +1 -0
  621. package/dist/runtime/environment/linux-provisioner.d.ts +102 -0
  622. package/dist/runtime/environment/linux-provisioner.js +734 -0
  623. package/dist/runtime/environment/linux-provisioner.js.map +1 -0
  624. package/dist/runtime/environment/provisioner-descriptors.d.ts +17 -0
  625. package/dist/runtime/environment/provisioner-descriptors.js +62 -0
  626. package/dist/runtime/environment/provisioner-descriptors.js.map +1 -0
  627. package/dist/runtime/environment/recovery.d.ts +74 -0
  628. package/dist/runtime/environment/recovery.js +121 -0
  629. package/dist/runtime/environment/recovery.js.map +1 -0
  630. package/dist/runtime/environment/rootfs-download.d.ts +2 -0
  631. package/dist/runtime/environment/rootfs-download.js +47 -0
  632. package/dist/runtime/environment/rootfs-download.js.map +1 -0
  633. package/dist/runtime/environment/service.d.ts +280 -0
  634. package/dist/runtime/environment/service.js +776 -0
  635. package/dist/runtime/environment/service.js.map +1 -0
  636. package/dist/runtime/environment/state.d.ts +163 -0
  637. package/dist/runtime/environment/state.js +479 -0
  638. package/dist/runtime/environment/state.js.map +1 -0
  639. package/dist/runtime/environment/store-models.d.ts +19 -0
  640. package/dist/runtime/environment/store-models.js +30 -0
  641. package/dist/runtime/environment/store-models.js.map +1 -0
  642. package/dist/runtime/environment/store.d.ts +210 -0
  643. package/dist/runtime/environment/store.js +438 -0
  644. package/dist/runtime/environment/store.js.map +1 -0
  645. package/dist/runtime/environment/windows-environment-record.d.ts +48 -0
  646. package/dist/runtime/environment/windows-environment-record.js +89 -0
  647. package/dist/runtime/environment/windows-environment-record.js.map +1 -0
  648. package/dist/runtime/environment/windows-forwarding.d.ts +27 -0
  649. package/dist/runtime/environment/windows-forwarding.js +84 -0
  650. package/dist/runtime/environment/windows-forwarding.js.map +1 -0
  651. package/dist/runtime/environment/windows-guest-setup.d.ts +48 -0
  652. package/dist/runtime/environment/windows-guest-setup.js +157 -0
  653. package/dist/runtime/environment/windows-guest-setup.js.map +1 -0
  654. package/dist/runtime/environment/windows-host.d.ts +46 -0
  655. package/dist/runtime/environment/windows-host.js +163 -0
  656. package/dist/runtime/environment/windows-host.js.map +1 -0
  657. package/dist/runtime/environment/windows-plan.d.ts +78 -0
  658. package/dist/runtime/environment/windows-plan.js +216 -0
  659. package/dist/runtime/environment/windows-plan.js.map +1 -0
  660. package/dist/runtime/environment/windows-probe.d.ts +135 -0
  661. package/dist/runtime/environment/windows-probe.js +261 -0
  662. package/dist/runtime/environment/windows-probe.js.map +1 -0
  663. package/dist/runtime/environment/windows-provisioner.d.ts +113 -0
  664. package/dist/runtime/environment/windows-provisioner.js +782 -0
  665. package/dist/runtime/environment/windows-provisioner.js.map +1 -0
  666. package/dist/runtime/environment/wiring.d.ts +117 -0
  667. package/dist/runtime/environment/wiring.js +354 -0
  668. package/dist/runtime/environment/wiring.js.map +1 -0
  669. package/dist/runtime/foundation-models/runtime.d.ts +8 -0
  670. package/dist/runtime/foundation-models/runtime.js +5 -2
  671. package/dist/runtime/foundation-models/runtime.js.map +1 -1
  672. package/dist/runtime/llamacpp/args.d.ts +10 -1
  673. package/dist/runtime/llamacpp/args.js +43 -7
  674. package/dist/runtime/llamacpp/args.js.map +1 -1
  675. package/dist/runtime/llamacpp/fit-margin.d.ts +46 -0
  676. package/dist/runtime/llamacpp/fit-margin.js +47 -0
  677. package/dist/runtime/llamacpp/fit-margin.js.map +1 -0
  678. package/dist/runtime/llamacpp/index.d.ts +1 -0
  679. package/dist/runtime/llamacpp/index.js +1 -0
  680. package/dist/runtime/llamacpp/index.js.map +1 -1
  681. package/dist/runtime/llamacpp/load-plan.d.ts +23 -1
  682. package/dist/runtime/llamacpp/load-plan.js +82 -1
  683. package/dist/runtime/llamacpp/load-plan.js.map +1 -1
  684. package/dist/runtime/llamacpp/policy.d.ts +16 -0
  685. package/dist/runtime/llamacpp/policy.js +20 -0
  686. package/dist/runtime/llamacpp/policy.js.map +1 -1
  687. package/dist/runtime/llamacpp/probe.d.ts +21 -1
  688. package/dist/runtime/llamacpp/probe.js +32 -6
  689. package/dist/runtime/llamacpp/probe.js.map +1 -1
  690. package/dist/runtime/llamacpp/runtime.d.ts +56 -1
  691. package/dist/runtime/llamacpp/runtime.js +142 -15
  692. package/dist/runtime/llamacpp/runtime.js.map +1 -1
  693. package/dist/runtime/managed-engines/index.d.ts +8 -0
  694. package/dist/runtime/managed-engines/index.js +9 -0
  695. package/dist/runtime/managed-engines/index.js.map +1 -0
  696. package/dist/runtime/managed-engines/runtime.d.ts +140 -0
  697. package/dist/runtime/managed-engines/runtime.js +402 -0
  698. package/dist/runtime/managed-engines/runtime.js.map +1 -0
  699. package/dist/runtime/managed-engines/spec.d.ts +70 -0
  700. package/dist/runtime/managed-engines/spec.js +39 -0
  701. package/dist/runtime/managed-engines/spec.js.map +1 -0
  702. package/dist/runtime/managed-models/check.d.ts +50 -0
  703. package/dist/runtime/managed-models/check.js +157 -0
  704. package/dist/runtime/managed-models/check.js.map +1 -0
  705. package/dist/runtime/managed-models/compatibility.d.ts +256 -0
  706. package/dist/runtime/managed-models/compatibility.js +594 -0
  707. package/dist/runtime/managed-models/compatibility.js.map +1 -0
  708. package/dist/runtime/managed-models/delete.d.ts +15 -0
  709. package/dist/runtime/managed-models/delete.js +60 -0
  710. package/dist/runtime/managed-models/delete.js.map +1 -0
  711. package/dist/runtime/managed-models/guest-files.d.ts +8 -0
  712. package/dist/runtime/managed-models/guest-files.js +49 -0
  713. package/dist/runtime/managed-models/guest-files.js.map +1 -0
  714. package/dist/runtime/managed-models/index.d.ts +17 -0
  715. package/dist/runtime/managed-models/index.js +18 -0
  716. package/dist/runtime/managed-models/index.js.map +1 -0
  717. package/dist/runtime/managed-models/location.d.ts +22 -0
  718. package/dist/runtime/managed-models/location.js +53 -0
  719. package/dist/runtime/managed-models/location.js.map +1 -0
  720. package/dist/runtime/managed-models/migrate.d.ts +30 -0
  721. package/dist/runtime/managed-models/migrate.js +119 -0
  722. package/dist/runtime/managed-models/migrate.js.map +1 -0
  723. package/dist/runtime/managed-models/model-dir.d.ts +36 -0
  724. package/dist/runtime/managed-models/model-dir.js +136 -0
  725. package/dist/runtime/managed-models/model-dir.js.map +1 -0
  726. package/dist/runtime/managed-models/quant-format.d.ts +71 -0
  727. package/dist/runtime/managed-models/quant-format.js +299 -0
  728. package/dist/runtime/managed-models/quant-format.js.map +1 -0
  729. package/dist/runtime/managed-models/registry.d.ts +26 -0
  730. package/dist/runtime/managed-models/registry.js +66 -0
  731. package/dist/runtime/managed-models/registry.js.map +1 -0
  732. package/dist/runtime/managed-text/adapter.d.ts +266 -0
  733. package/dist/runtime/managed-text/adapter.js +96 -0
  734. package/dist/runtime/managed-text/adapter.js.map +1 -0
  735. package/dist/runtime/managed-text/backend-target.d.ts +3 -0
  736. package/dist/runtime/managed-text/backend-target.js +52 -0
  737. package/dist/runtime/managed-text/backend-target.js.map +1 -0
  738. package/dist/runtime/managed-text/deployment.d.ts +14 -0
  739. package/dist/runtime/managed-text/deployment.js +32 -0
  740. package/dist/runtime/managed-text/deployment.js.map +1 -0
  741. package/dist/runtime/managed-text/engine-cache.d.ts +15 -0
  742. package/dist/runtime/managed-text/engine-cache.js +64 -0
  743. package/dist/runtime/managed-text/engine-cache.js.map +1 -0
  744. package/dist/runtime/managed-text/gateway.d.ts +158 -0
  745. package/dist/runtime/managed-text/gateway.js +535 -0
  746. package/dist/runtime/managed-text/gateway.js.map +1 -0
  747. package/dist/runtime/managed-text/generation-defaults.d.ts +23 -0
  748. package/dist/runtime/managed-text/generation-defaults.js +51 -0
  749. package/dist/runtime/managed-text/generation-defaults.js.map +1 -0
  750. package/dist/runtime/managed-text/index.d.ts +26 -0
  751. package/dist/runtime/managed-text/index.js +27 -0
  752. package/dist/runtime/managed-text/index.js.map +1 -0
  753. package/dist/runtime/managed-text/lifecycle.d.ts +276 -0
  754. package/dist/runtime/managed-text/lifecycle.js +859 -0
  755. package/dist/runtime/managed-text/lifecycle.js.map +1 -0
  756. package/dist/runtime/managed-text/load-policy.d.ts +47 -0
  757. package/dist/runtime/managed-text/load-policy.js +111 -0
  758. package/dist/runtime/managed-text/load-policy.js.map +1 -0
  759. package/dist/runtime/managed-text/mount-source.d.ts +14 -0
  760. package/dist/runtime/managed-text/mount-source.js +18 -0
  761. package/dist/runtime/managed-text/mount-source.js.map +1 -0
  762. package/dist/runtime/managed-text/readiness.d.ts +13 -0
  763. package/dist/runtime/managed-text/readiness.js +24 -0
  764. package/dist/runtime/managed-text/readiness.js.map +1 -0
  765. package/dist/runtime/managed-text/request-rules.d.ts +18 -0
  766. package/dist/runtime/managed-text/request-rules.js +62 -0
  767. package/dist/runtime/managed-text/request-rules.js.map +1 -0
  768. package/dist/runtime/managed-text/types.d.ts +88 -0
  769. package/dist/runtime/managed-text/types.js +12 -0
  770. package/dist/runtime/managed-text/types.js.map +1 -0
  771. package/dist/runtime/managed-text/wsl-deployment.d.ts +24 -0
  772. package/dist/runtime/managed-text/wsl-deployment.js +70 -0
  773. package/dist/runtime/managed-text/wsl-deployment.js.map +1 -0
  774. package/dist/runtime/mlx/errors.d.ts +6 -1
  775. package/dist/runtime/mlx/errors.js +7 -2
  776. package/dist/runtime/mlx/errors.js.map +1 -1
  777. package/dist/runtime/mlx/runtime.d.ts +36 -1
  778. package/dist/runtime/mlx/runtime.js +85 -4
  779. package/dist/runtime/mlx/runtime.js.map +1 -1
  780. package/dist/runtime/shared/backend-output.d.ts +23 -0
  781. package/dist/runtime/shared/backend-output.js +32 -0
  782. package/dist/runtime/shared/backend-output.js.map +1 -0
  783. package/dist/runtime/shared/bounded-output.d.ts +24 -0
  784. package/dist/runtime/shared/bounded-output.js +63 -0
  785. package/dist/runtime/shared/bounded-output.js.map +1 -0
  786. package/dist/runtime/shared/external-sessions.js +9 -1
  787. package/dist/runtime/shared/external-sessions.js.map +1 -1
  788. package/dist/runtime/shared/gpu-occupancy.d.ts +60 -0
  789. package/dist/runtime/shared/gpu-occupancy.js +10 -0
  790. package/dist/runtime/shared/gpu-occupancy.js.map +1 -0
  791. package/dist/runtime/shared/index.d.ts +4 -0
  792. package/dist/runtime/shared/index.js +4 -0
  793. package/dist/runtime/shared/index.js.map +1 -1
  794. package/dist/runtime/shared/local-runtime.d.ts +35 -0
  795. package/dist/runtime/shared/ports.d.ts +6 -0
  796. package/dist/runtime/shared/ports.js +12 -1
  797. package/dist/runtime/shared/ports.js.map +1 -1
  798. package/dist/runtime/shared/process.d.ts +11 -0
  799. package/dist/runtime/shared/process.js +20 -0
  800. package/dist/runtime/shared/process.js.map +1 -1
  801. package/dist/runtime/shared/redact-args.d.ts +7 -0
  802. package/dist/runtime/shared/redact-args.js +26 -0
  803. package/dist/runtime/shared/redact-args.js.map +1 -0
  804. package/dist/runtime/shared/sidecar.d.ts +15 -0
  805. package/dist/runtime/shared/sidecar.js +43 -8
  806. package/dist/runtime/shared/sidecar.js.map +1 -1
  807. package/dist/runtime/tensorrt-llm/adapter.d.ts +250 -0
  808. package/dist/runtime/tensorrt-llm/adapter.js +1011 -0
  809. package/dist/runtime/tensorrt-llm/adapter.js.map +1 -0
  810. package/dist/runtime/tensorrt-llm/check.d.ts +12 -0
  811. package/dist/runtime/tensorrt-llm/check.js +21 -0
  812. package/dist/runtime/tensorrt-llm/check.js.map +1 -0
  813. package/dist/runtime/tensorrt-llm/compatibility.d.ts +100 -0
  814. package/dist/runtime/tensorrt-llm/compatibility.js +181 -0
  815. package/dist/runtime/tensorrt-llm/compatibility.js.map +1 -0
  816. package/dist/runtime/tensorrt-llm/engine.d.ts +3 -0
  817. package/dist/runtime/tensorrt-llm/engine.js +24 -0
  818. package/dist/runtime/tensorrt-llm/engine.js.map +1 -0
  819. package/dist/runtime/tensorrt-llm/host-facts.d.ts +55 -0
  820. package/dist/runtime/tensorrt-llm/host-facts.js +87 -0
  821. package/dist/runtime/tensorrt-llm/host-facts.js.map +1 -0
  822. package/dist/runtime/tensorrt-llm/index.d.ts +30 -0
  823. package/dist/runtime/tensorrt-llm/index.js +31 -0
  824. package/dist/runtime/tensorrt-llm/index.js.map +1 -0
  825. package/dist/runtime/tensorrt-llm/installation.d.ts +23 -0
  826. package/dist/runtime/tensorrt-llm/installation.js +53 -0
  827. package/dist/runtime/tensorrt-llm/installation.js.map +1 -0
  828. package/dist/runtime/tensorrt-llm/kv-cache.d.ts +25 -0
  829. package/dist/runtime/tensorrt-llm/kv-cache.js +28 -0
  830. package/dist/runtime/tensorrt-llm/kv-cache.js.map +1 -0
  831. package/dist/runtime/tensorrt-llm/prelaunch.d.ts +20 -0
  832. package/dist/runtime/tensorrt-llm/prelaunch.js +168 -0
  833. package/dist/runtime/tensorrt-llm/prelaunch.js.map +1 -0
  834. package/dist/runtime/tensorrt-llm/route-policy.d.ts +19 -0
  835. package/dist/runtime/tensorrt-llm/route-policy.js +17 -0
  836. package/dist/runtime/tensorrt-llm/route-policy.js.map +1 -0
  837. package/dist/runtime/tensorrt-llm/settings.d.ts +7 -0
  838. package/dist/runtime/tensorrt-llm/settings.js +48 -0
  839. package/dist/runtime/tensorrt-llm/settings.js.map +1 -0
  840. package/dist/runtime/vllm/adapter.d.ts +46 -0
  841. package/dist/runtime/vllm/adapter.js +425 -0
  842. package/dist/runtime/vllm/adapter.js.map +1 -0
  843. package/dist/runtime/vllm/engine.d.ts +16 -0
  844. package/dist/runtime/vllm/engine.js +37 -0
  845. package/dist/runtime/vllm/engine.js.map +1 -0
  846. package/dist/runtime/vllm/index.d.ts +11 -0
  847. package/dist/runtime/vllm/index.js +12 -0
  848. package/dist/runtime/vllm/index.js.map +1 -0
  849. package/dist/runtime/vllm/memory.d.ts +69 -0
  850. package/dist/runtime/vllm/memory.js +123 -0
  851. package/dist/runtime/vllm/memory.js.map +1 -0
  852. package/dist/runtime/vllm/settings.d.ts +52 -0
  853. package/dist/runtime/vllm/settings.js +151 -0
  854. package/dist/runtime/vllm/settings.js.map +1 -0
  855. package/dist/runtime/wsl/guest-paths.d.ts +33 -0
  856. package/dist/runtime/wsl/guest-paths.js +83 -0
  857. package/dist/runtime/wsl/guest-paths.js.map +1 -0
  858. package/dist/runtime/wsl/guest-scope.d.ts +14 -0
  859. package/dist/runtime/wsl/guest-scope.js +98 -0
  860. package/dist/runtime/wsl/guest-scope.js.map +1 -0
  861. package/dist/runtime/wsl/index.d.ts +12 -0
  862. package/dist/runtime/wsl/index.js +13 -0
  863. package/dist/runtime/wsl/index.js.map +1 -0
  864. package/dist/runtime/wsl/keeper.d.ts +29 -0
  865. package/dist/runtime/wsl/keeper.js +48 -0
  866. package/dist/runtime/wsl/keeper.js.map +1 -0
  867. package/dist/runtime/wsl/transport.d.ts +106 -0
  868. package/dist/runtime/wsl/transport.js +181 -0
  869. package/dist/runtime/wsl/transport.js.map +1 -0
  870. package/dist/server/control/index.d.ts +1 -1
  871. package/dist/server/control/router.js +15 -0
  872. package/dist/server/control/router.js.map +1 -1
  873. package/dist/server/control/routes/backends.js +26 -0
  874. package/dist/server/control/routes/backends.js.map +1 -1
  875. package/dist/server/control/routes/decision.d.ts +10 -0
  876. package/dist/server/control/routes/decision.js +43 -0
  877. package/dist/server/control/routes/decision.js.map +1 -0
  878. package/dist/server/control/routes/diffusion-video.js +4 -0
  879. package/dist/server/control/routes/diffusion-video.js.map +1 -1
  880. package/dist/server/control/routes/diffusion.d.ts +1 -1
  881. package/dist/server/control/routes/diffusion.js +4 -9
  882. package/dist/server/control/routes/diffusion.js.map +1 -1
  883. package/dist/server/control/routes/embedding.d.ts +9 -0
  884. package/dist/server/control/routes/embedding.js +43 -0
  885. package/dist/server/control/routes/embedding.js.map +1 -0
  886. package/dist/server/control/routes/engine-builds.d.ts +14 -0
  887. package/dist/server/control/routes/engine-builds.js +82 -0
  888. package/dist/server/control/routes/engine-builds.js.map +1 -0
  889. package/dist/server/control/routes/engines.d.ts +17 -0
  890. package/dist/server/control/routes/engines.js +152 -0
  891. package/dist/server/control/routes/engines.js.map +1 -0
  892. package/dist/server/control/routes/environments.d.ts +16 -0
  893. package/dist/server/control/routes/environments.js +207 -0
  894. package/dist/server/control/routes/environments.js.map +1 -0
  895. package/dist/server/control/routes/hardware.d.ts +1 -1
  896. package/dist/server/control/routes/hardware.js +11 -6
  897. package/dist/server/control/routes/hardware.js.map +1 -1
  898. package/dist/server/control/routes/model-setups.d.ts +11 -0
  899. package/dist/server/control/routes/model-setups.js +55 -0
  900. package/dist/server/control/routes/model-setups.js.map +1 -0
  901. package/dist/server/control/routes/models.d.ts +3 -2
  902. package/dist/server/control/routes/models.js +45 -2
  903. package/dist/server/control/routes/models.js.map +1 -1
  904. package/dist/server/control/types.d.ts +167 -9
  905. package/dist/server/control/types.js.map +1 -1
  906. package/dist/server/http.d.ts +9 -1
  907. package/dist/server/http.js +51 -1
  908. package/dist/server/http.js.map +1 -1
  909. package/dist/server/public/decision-preview.d.ts +17 -0
  910. package/dist/server/public/decision-preview.js +119 -0
  911. package/dist/server/public/decision-preview.js.map +1 -0
  912. package/dist/server/public/decision.d.ts +32 -0
  913. package/dist/server/public/decision.js +135 -0
  914. package/dist/server/public/decision.js.map +1 -0
  915. package/dist/server/public/embedding.d.ts +31 -0
  916. package/dist/server/public/embedding.js +126 -0
  917. package/dist/server/public/embedding.js.map +1 -0
  918. package/dist/server/public/errors.d.ts +2 -1
  919. package/dist/server/public/errors.js +5 -2
  920. package/dist/server/public/errors.js.map +1 -1
  921. package/dist/server/public/forward.js +75 -3
  922. package/dist/server/public/forward.js.map +1 -1
  923. package/dist/server/public/gates.d.ts +13 -0
  924. package/dist/server/public/gates.js +37 -14
  925. package/dist/server/public/gates.js.map +1 -1
  926. package/dist/server/public/index.d.ts +5 -2
  927. package/dist/server/public/index.js +14 -1
  928. package/dist/server/public/index.js.map +1 -1
  929. package/dist/server/public/listing.d.ts +13 -2
  930. package/dist/server/public/listing.js +33 -9
  931. package/dist/server/public/listing.js.map +1 -1
  932. package/dist/server/public/policy.d.ts +9 -0
  933. package/dist/server/public/policy.js +68 -0
  934. package/dist/server/public/policy.js.map +1 -0
  935. package/dist/server/public/responses.js +10 -0
  936. package/dist/server/public/responses.js.map +1 -1
  937. package/dist/server/public/trace.d.ts +2 -2
  938. package/dist/server/public/trace.js +6 -2
  939. package/dist/server/public/trace.js.map +1 -1
  940. package/dist/server/public/types.d.ts +84 -1
  941. package/dist/settings/decision.d.ts +15 -0
  942. package/dist/settings/decision.js +88 -0
  943. package/dist/settings/decision.js.map +1 -0
  944. package/dist/settings/embedding.d.ts +12 -0
  945. package/dist/settings/embedding.js +82 -0
  946. package/dist/settings/embedding.js.map +1 -0
  947. package/dist/settings/index.d.ts +2 -0
  948. package/dist/settings/index.js +2 -0
  949. package/dist/settings/index.js.map +1 -1
  950. package/dist/settings/schema/atomic-prism.json +433 -0
  951. package/dist/settings/schema/tensorrt-llm.json +253 -0
  952. package/dist/settings/schema/vllm.json +273 -0
  953. package/dist/settings/schema.js +58 -0
  954. package/dist/settings/schema.js.map +1 -1
  955. package/dist/settings/store.d.ts +13 -2
  956. package/dist/settings/store.js +44 -0
  957. package/dist/settings/store.js.map +1 -1
  958. package/dist/util/index.d.ts +1 -0
  959. package/dist/util/index.js +1 -0
  960. package/dist/util/index.js.map +1 -1
  961. package/dist/util/result.d.ts +19 -0
  962. package/dist/util/result.js +15 -0
  963. package/dist/util/result.js.map +1 -0
  964. package/dist/version.d.ts +1 -1
  965. package/dist/version.js +1 -1
  966. package/dist/version.js.map +1 -1
  967. package/package.json +1 -1
  968. package/src/settings/schema/atomic-prism.json +433 -0
  969. package/src/settings/schema/tensorrt-llm.json +253 -0
  970. package/src/settings/schema/vllm.json +273 -0
@@ -0,0 +1,1011 @@
1
+ /**
2
+ * The `tensorrt-llm` `ManagedTextAdapter` (task 2.13, spec `tensorrt-llm-runtime`, design D8/D9):
3
+ * settings validation, the `trtllm-serve` argv, readiness, log stage markers, the readiness
4
+ * timeout, exit classification (OOM etc.), declared capabilities and routes, request-body
5
+ * rewriting for the output-length setting, and the context-length-overflow error mapping. Plugs
6
+ * into the engine-neutral load lifecycle (task 2.12, `../managed-text/`) through
7
+ * `ManagedTextAdapter`; nothing here does I/O.
8
+ *
9
+ * Fix round 1 (`findings-2.13-r1.md`): the first pass sourced its CLI/error evidence from a mix of
10
+ * the pytorch and legacy `tensorrt` backends without checking which one this descriptor actually
11
+ * launches (`serve.py`'s `--backend` defaults to `pytorch`, and nothing here ever passes
12
+ * `--backend`), and got `--max_num_tokens`'s meaning on that backend wrong.
13
+ *
14
+ * Fix round 2 (`findings-2.13-r2.md`): round 1's own ruling for enforcing the output-length setting
15
+ * — write both `max_tokens` and `max_completion_tokens` on `/v1/chat/completions` — was itself
16
+ * wrong: TRT-LLM 1.2.1's `ChatCompletionRequest` (`openai_protocol.py`, `extra="forbid"`) has a
17
+ * *single* Python field, `max_completion_tokens`, whose `validation_alias` is `max_tokens`, so a
18
+ * body carrying both as separate top-level keys makes pydantic reject the whole request with `400
19
+ * extra_forbidden` — every chat request `tensorrtLlmRewriteRequestBody` touched would have failed.
20
+ * The corrected rule (see `tensorrtLlmRewriteRequestBody` below) writes exactly one of the two keys.
21
+ * This round also added the gateway-level route declaration/rewrite-route split
22
+ * (`routes`/`rewritableRoutes` below) and moved the request-body-size cap to be enforced while the
23
+ * body streams in rather than after it is fully buffered — both are `../managed-text/gateway.ts`
24
+ * changes this file's `routes`/`rewritableRoutes`/`rewriteRequestBody` feed into, not changes to
25
+ * this file's own logic beyond declaring the two route lists.
26
+ *
27
+ * Every source citation below was re-verified, read-only, against the pinned tag's actual sources
28
+ * (`nvcr.io/nvidia/tensorrt-llm/release` `descriptor_id: tensorrt-llm-1.2.1-r1` builds from
29
+ * `v1.2.1`, https://github.com/NVIDIA/TensorRT-LLM/tree/v1.2.1), specifically checking which backend
30
+ * each path belongs to:
31
+ * - `tensorrt_llm/commands/serve.py`: the flags this file builds argv from (`--host`, `--port`,
32
+ * `--max_seq_len`, `--max_num_tokens`, `--kv_cache_free_gpu_memory_fraction` — the long spelling
33
+ * of the `--free_gpu_memory_fraction` alias — `--tool_parser`, `--reasoning_parser`), and that
34
+ * `--backend` defaults to `pytorch` (`DefaultGroup` + `@click.command("serve")`). No
35
+ * `--cache_dir`/engine-cache flag exists on `serve` in this tag (the unifying `TRTLLM_CACHE_DIR`
36
+ * env var, NVIDIA/TensorRT-LLM#18897, was still an open PR as of this reading); the engine cache
37
+ * directory is instead wired through the individual upstream PyTorch/Triton/CUDA JIT-cache env
38
+ * vars `#18897` itself names as the caches it would unify (`TORCHINDUCTOR_CACHE_DIR`,
39
+ * `TRITON_CACHE_DIR`, `CUDA_CACHE_PATH`) — those already exist independently of that PR.
40
+ * - `tensorrt_llm/serve/openai_protocol.py`: `OpenAIBaseModel`'s `model_config = ConfigDict(extra=
41
+ * "forbid", populate_by_name=True)` (lines 71-73); `ChatCompletionRequest.max_completion_tokens:
42
+ * Optional[int] = Field(default=None, validation_alias='max_tokens')` (lines 546-547) — the single
43
+ * field, two-name situation `tensorrtLlmRewriteRequestBody` writes around (reproduced failing with
44
+ * `pydantic` directly against this exact model in round 2's review).
45
+ * - `tensorrt_llm/llmapi/llm.py`'s `_check_arguments`: on the pytorch backend, and only when
46
+ * `enable_chunked_prefill` is off (its own default — `llm_args.py`'s `enable_chunked_prefill: bool
47
+ * = Field(default=False, ...)`, and nothing here ever passes `--enable_chunked_prefill`) and the
48
+ * request is not gen-only, it compares `prompt_len/cp_size + query_len` against
49
+ * `args.max_num_tokens` alone — **never the output** — raising `RequestError(f"The sum of prompt
50
+ * length ({promptLen}), query length ({queryLen}) should not exceed max_num_tokens ({limit})")`.
51
+ * Since this check is unconditional by default, and `--max_num_tokens` now equals
52
+ * `context_length` (see `buildTensorrtLlmLaunch`), it catches *every* request whose prompt and
53
+ * query alone already exceed the context window — the common overflow case, not an edge case
54
+ * (`findings-2.13-r2.md` item 6 correcting round 1's "an extreme case" wording).
55
+ * `--max_num_tokens` therefore caps the *prompt*, not a reply's length; the ruling in
56
+ * `findings-2.13-r1.md` item 1 responds by pointing it at `context_length` (a correct, if generic,
57
+ * prompt-side guard) and enforcing the output setting elsewhere — see `rewriteRequestBody` below
58
+ * and `docs/decisions/2026-09-28-tensorrt-llm-output-cap-enforced-by-the-session-gateway.md`. The
59
+ * `tensorrt`-backend branch of the same method (comparing prompt+query+`max_tokens` against
60
+ * `max_seq_len`) is real but unreachable from this adapter's launch, which never passes
61
+ * `--backend`; it is not implemented here (round 1 had a copy of it that could never fire).
62
+ * - `tensorrt_llm/_torch/pyexecutor/base_worker.py`'s `_deduce_max_tokens`: the pytorch backend's
63
+ * *other* per-request overflow signal, now that `--max_num_tokens` no longer doubles as an output
64
+ * cap — `default_max_tokens = max_seq_len - splited_prompt_len - query_token_len`, and once that
65
+ * is `<= 0` it raises `ValueError(f"\`default_max_tokens\` ({default_max_tokens}) must be greater
66
+ * than 0, \`default_max_tokens\` ({default_max_tokens}) = max_seq_len ({max_seq_len}) -
67
+ * \`splited_prompt_len\` ({splited_prompt_len}) - \`query_token_len\` ({query_token_len})")`.
68
+ * Unlike `_check_arguments` above, this one is narrow: since `_check_arguments` already guarantees
69
+ * `prompt + query <= max_num_tokens == max_seq_len` before this ever runs, `default_max_tokens`
70
+ * can only be `<= 0` at the single boundary point where `prompt + query` lands *exactly* on
71
+ * `max_seq_len` (`findings-2.13-r2.md` item 6 — round 1's header called this "the case that
72
+ * actually fires now", which had the relative weight of the two checks backwards).
73
+ * `mapTensorrtLlmContextLengthError` matches this alongside the `_check_arguments` message above.
74
+ * - `tensorrt_llm/serve/openai_server.py`: `GET /health` answers 200 only once
75
+ * `self.llm._check_health()` passes and 503 otherwise (not merely "the HTTP server is up"), and
76
+ * `create_error_response`/the generic `except Exception` handler wrap any exception raised while
77
+ * handling a request as
78
+ * `{"object":"error","message":<str(exc)>,"type":"BadRequestError","param":null,"code":400}`, a
79
+ * flat envelope with an HTTP-status `code`, not OpenAI's `context_length_exceeded` string (that
80
+ * OpenAI-style remap is NVIDIA/TensorRT-LLM#19457, also still open, so this tag needs its own).
81
+ * - `tensorrt_llm/_torch/models/modeling_auto.py`'s `AutoModelForCausalLM.from_config` — the
82
+ * pytorch backend's model class lookup (`_torch/pyexecutor/model_loader.py` imports
83
+ * `AutoModelForCausalLM` from exactly this module) — raises `ValueError(f"Unknown architecture
84
+ * for AutoModelForCausalLM: {config.pretrained_config.architectures[0]}")` for an architecture it
85
+ * has no class for. `tensorrt_llm/models/automodel.py`'s `TopModelMixin.from_hugging_face`
86
+ * ("...is not supported in TRT-LLM yet", round 1's source, matching NVIDIA/TensorRT-LLM issue
87
+ * #2845's older report) belongs to the legacy `tensorrt`-backend model loader, not the pytorch one
88
+ * — dropped here for the same reason as the `max_seq_len` overflow branch above.
89
+ * - `tensorrt_llm/_torch/modules/linear.py`: two real `quant_mode`/`quant mode` rejections —
90
+ * `raise NotImplementedError(f"Unsupported quant_mode: {module.quant_config.layer_quant_mode}")`
91
+ * (line 292, weight-only int4/int8 dispatch) and `raise ValueError(f'unsupported quant mode:
92
+ * {quant_config.quant_mode}')` (line 2066, the general per-layer quant-method dispatch). Round 1
93
+ * matched a *warning* string ("Unsupported quant algo") that these modules never raise as an
94
+ * exception at all.
95
+ * - The CUDA/PyTorch out-of-memory wording ("CUDA out of memory. Tried to allocate X GiB. GPU 0 has
96
+ * a total capacity of Y GiB of which Z GiB/MiB/KiB/bytes is free.") is PyTorch's own allocator
97
+ * message, unrelated to any TensorRT-LLM release; quoted from real `trtllm-serve` crash reports in
98
+ * NVIDIA/TensorRT-LLM issues #7818 (mid-size allocation, `MiB`) and #8642 (`0 bytes` free, the KV
99
+ * cache size estimation case). `tensorrt_llm/_torch/pyexecutor/py_executor_creator.py`'s
100
+ * `_maybe_explain_if_oom` additionally treats any exception whose text contains the lowercase
101
+ * substring `"out of memory"` as OOM regardless of its own wording — covering the executor's own
102
+ * C++-side allocator failure, which this adapter matches as `CUDA runtime error in .*: out of
103
+ * memory` (the shape that class of error takes; no single tag-pinned verbatim capture of the full
104
+ * C++ message was found, so the fixture for it is labelled as a constructed line around that
105
+ * confirmed substring, not a captured console transcript — see
106
+ * `test/helpers/tensorrt-llm-log-fixtures.ts`).
107
+ * - Startup log lines: `stageMarkers` now uses three lines read directly from the pinned tag's
108
+ * pytorch-backend source rather than search results —
109
+ * `tensorrt_llm/_torch/pyexecutor/weight_loader.py`'s `HfWeightLoader.load_weights` (tqdm
110
+ * descriptions `"Loading safetensors weights in parallel"`/`"Loading bin weights in parallel"`,
111
+ * and `logger.info(f"Prefetching {prefetch_size / (1024**3):.2f}GB checkpoint files.")` when
112
+ * prefetch is enabled) and `tensorrt_llm/_torch/pyexecutor/model_engine.py`'s
113
+ * `_capture_generation_cuda_graphs` (`logger.info(f"Creating CUDA graph instances for {n} batch
114
+ * sizes.")`). Round 1's two markers (`Loading checkpoint shards`, `Capturing CUDA graphs`) do not
115
+ * appear anywhere in this tag's pytorch-backend source; dropped.
116
+ * - The readiness-timeout coefficients are explicitly placeholders (see the constants below):
117
+ * design D8's open question defers their real values to live test 2.19 on real hardware. The
118
+ * chosen numbers only have to satisfy the spec scenario headroom this file's own test checks
119
+ * ("Долгий первый старт": a 30 GB model starting in three minutes must not time out).
120
+ */
121
+ import { AtomicCoreError } from '../../contracts/index.js';
122
+ import { readGenerationDefaults, withGenerationDefaults, } from '../managed-text/generation-defaults.js';
123
+ import { MANAGED_TEXT_ADAPTER_CONTRACT_VERSION, ManagedRequestRefusal, asksForStructuredOutput, asksForTools, reasoningIntoContent, thinkingRequested, } from '../managed-text/index.js';
124
+ import { TENSORRT_LLM_DEFAULT_KV_CACHE_FREE_FRACTION, tensorrtLlmUnifiedKvMaxTokens } from './kv-cache.js';
125
+ const GiB = 1024 ** 3;
126
+ // ---------------------------------------------------------------------------------------------
127
+ // Settings
128
+ // ---------------------------------------------------------------------------------------------
129
+ /** `nvidia-smi -L`'s two UUID spellings, mirroring `assertGpuUuid` in `../container/argv.ts` — this
130
+ * module cannot import that internal (cross-module imports go through `index.ts` only, and it is
131
+ * not exported there), so the same shape is asserted again here, for the settings value rather
132
+ * than the docker argv token it eventually becomes. */
133
+ const GPU_UUID_PATTERN = /^(GPU|MIG)-[0-9A-Fa-f-]+$/;
134
+ export const TENSORRT_LLM_MIN_CONTEXT_LENGTH = 512;
135
+ export const TENSORRT_LLM_MAX_CONTEXT_LENGTH = 1_048_576;
136
+ export const TENSORRT_LLM_DEFAULT_CONTEXT_LENGTH = 8192;
137
+ export const TENSORRT_LLM_MIN_MAX_OUTPUT_TOKENS = 1;
138
+ export const TENSORRT_LLM_MAX_MAX_OUTPUT_TOKENS = 1_048_576;
139
+ export const TENSORRT_LLM_DEFAULT_MAX_OUTPUT_TOKENS = 4096;
140
+ /** Same bounds `trtllm-serve`'s own `--kv_cache_free_gpu_memory_fraction` documents as sane: never
141
+ * the whole of free memory (nothing left for the engine's own workspace) and never a sliver. */
142
+ export const TENSORRT_LLM_MIN_KV_CACHE_FREE_FRACTION = 0.1;
143
+ export const TENSORRT_LLM_MAX_KV_CACHE_FREE_FRACTION = 0.95;
144
+ export const TENSORRT_LLM_MIN_LOAD_TIMEOUT_SECONDS = 1;
145
+ export const TENSORRT_LLM_MAX_LOAD_TIMEOUT_SECONDS = 3600;
146
+ function invalid(message, value) {
147
+ throw new AtomicCoreError('INVALID_ARGUMENT', message, String(value));
148
+ }
149
+ function validateGpuId(value) {
150
+ if (value === undefined || value === null)
151
+ return null;
152
+ if (typeof value !== 'string' || !GPU_UUID_PATTERN.test(value)) {
153
+ invalid('tensorrt-llm gpu_id must be a GPU-<uuid>/MIG-<uuid> value, or null.', value);
154
+ }
155
+ return value;
156
+ }
157
+ function validateBoundedInt(value, label, fallback, min, max) {
158
+ if (value === undefined || value === null)
159
+ return fallback;
160
+ if (typeof value !== 'number' || !Number.isInteger(value) || value < min || value > max) {
161
+ invalid(`tensorrt-llm ${label} must be an integer between ${min} and ${max}.`, value);
162
+ }
163
+ return value;
164
+ }
165
+ function validateFraction(value) {
166
+ if (value === undefined || value === null)
167
+ return TENSORRT_LLM_DEFAULT_KV_CACHE_FREE_FRACTION;
168
+ const min = TENSORRT_LLM_MIN_KV_CACHE_FREE_FRACTION;
169
+ const max = TENSORRT_LLM_MAX_KV_CACHE_FREE_FRACTION;
170
+ if (typeof value !== 'number' || !Number.isFinite(value) || value < min || value > max) {
171
+ invalid(`tensorrt-llm kv_cache_free_gpu_memory_fraction must be between ${min} and ${max}.`, value);
172
+ }
173
+ return value;
174
+ }
175
+ function validateChoice(value, label, choices, fallback) {
176
+ if (value === undefined || value === null || value === '')
177
+ return fallback;
178
+ if (typeof value !== 'string' || !choices.includes(value)) {
179
+ invalid(`tensorrt-llm ${label} must be one of ${choices.join(', ')}.`, value);
180
+ }
181
+ return value;
182
+ }
183
+ function validateFlag(value, label, fallback) {
184
+ if (value === undefined || value === null)
185
+ return fallback;
186
+ if (value === true || value === 'true')
187
+ return true;
188
+ if (value === false || value === 'false')
189
+ return false;
190
+ return invalid(`tensorrt-llm ${label} must be true or false.`, value);
191
+ }
192
+ function validateLoadTimeoutOverride(value) {
193
+ if (value === undefined || value === null)
194
+ return null;
195
+ const min = TENSORRT_LLM_MIN_LOAD_TIMEOUT_SECONDS;
196
+ const max = TENSORRT_LLM_MAX_LOAD_TIMEOUT_SECONDS;
197
+ if (typeof value !== 'number' || !Number.isInteger(value) || value < min || value > max) {
198
+ invalid(`tensorrt-llm load_timeout_seconds must be an integer between ${min} and ${max}, or null.`, value);
199
+ }
200
+ return value;
201
+ }
202
+ /** Throws `AtomicCoreError('INVALID_ARGUMENT', ...)` before any container exists (adapter contract). */
203
+ export function validateTensorrtLlmSettings(raw) {
204
+ if (raw !== undefined && (typeof raw !== 'object' || raw === null || Array.isArray(raw))) {
205
+ invalid('tensorrt-llm settings must be an object.', raw);
206
+ }
207
+ const r = (raw ?? {});
208
+ const context_length = validateBoundedInt(r['context_length'], 'context_length', TENSORRT_LLM_DEFAULT_CONTEXT_LENGTH, TENSORRT_LLM_MIN_CONTEXT_LENGTH, TENSORRT_LLM_MAX_CONTEXT_LENGTH);
209
+ const max_output_tokens = validateBoundedInt(r['max_output_tokens'], 'max_output_tokens', TENSORRT_LLM_DEFAULT_MAX_OUTPUT_TOKENS, TENSORRT_LLM_MIN_MAX_OUTPUT_TOKENS, TENSORRT_LLM_MAX_MAX_OUTPUT_TOKENS);
210
+ // A setting that could never leave room for a prompt is rejected here, not discovered later as
211
+ // every request failing the gateway's own clamp (findings-2.13-r1.md item 1's cross-field rule;
212
+ // see docs/decisions/2026-09-28-tensorrt-llm-output-cap-enforced-by-the-session-gateway.md).
213
+ if (max_output_tokens >= context_length) {
214
+ invalid(`tensorrt-llm max_output_tokens (${max_output_tokens}) must be less than context_length (${context_length}).`, max_output_tokens);
215
+ }
216
+ return {
217
+ gpu_id: validateGpuId(r['gpu_id']),
218
+ context_length,
219
+ max_output_tokens,
220
+ kv_cache_free_gpu_memory_fraction: validateFraction(r['kv_cache_free_gpu_memory_fraction']),
221
+ max_batch_size: validateBoundedInt(r['max_batch_size'], 'max_batch_size', TENSORRT_LLM_MAX_BATCH_SIZE, 1, TENSORRT_LLM_MAX_MAX_BATCH_SIZE),
222
+ kv_cache_max_tokens: r['kv_cache_max_tokens'] === undefined || r['kv_cache_max_tokens'] === null
223
+ ? null
224
+ : validateBoundedInt(r['kv_cache_max_tokens'], 'kv_cache_max_tokens', 0, 1, TENSORRT_LLM_MAX_KV_CACHE_MAX_TOKENS),
225
+ cuda_graphs: validateChoice(r['cuda_graphs'], 'cuda_graphs', ['auto', 'on', 'off'], 'auto'),
226
+ kv_cache_dtype: validateChoice(r['kv_cache_dtype'], 'kv_cache_dtype', ['auto', 'fp8'], 'auto'),
227
+ load_timeout_seconds: validateLoadTimeoutOverride(r['load_timeout_seconds']),
228
+ enable_prefix_caching: validateFlag(r['enable_prefix_caching'], 'enable_prefix_caching', true),
229
+ overlap_scheduler: validateFlag(r['overlap_scheduler'], 'overlap_scheduler', true),
230
+ capacity_scheduler_policy: validateChoice(r['capacity_scheduler_policy'], 'capacity_scheduler_policy', ['guaranteed_no_evict', 'max_utilization'], 'guaranteed_no_evict'),
231
+ dtype: validateChoice(r['dtype'], 'dtype', ['auto', 'float16', 'bfloat16', 'float32'], 'auto'),
232
+ generation: readGenerationDefaults('tensorrt-llm', r),
233
+ };
234
+ }
235
+ // ---------------------------------------------------------------------------------------------
236
+ // Launch
237
+ // ---------------------------------------------------------------------------------------------
238
+ /** `trtllm-serve serve`'s own default `--port`. */
239
+ export const TENSORRT_LLM_CONTAINER_PORT = 8000;
240
+ /**
241
+ * The LLM API option file a launch passes to `trtllm-serve serve --extra_llm_api_options`
242
+ * (`commands/serve.py` in v1.2.1: `--config`/`--extra_llm_api_options`, a YAML file whose keys
243
+ * overwrite the LLM API arguments), written when either of two keys applies:
244
+ *
245
+ * - `guided_decoding_backend: xgrammar`, for a family that declares structured output
246
+ * (`llmapi/llm_args.py`'s `guided_decoding_backend: Optional[Literal["xgrammar", "llguidance"]]`,
247
+ * default `None`). Without it, `openai_protocol.py` still turns `response_format` into
248
+ * guided-decoding parameters, but no backend exists to enforce them. `xgrammar` is the backend both
249
+ * the PyTorch and TensorRT backends implement.
250
+ * - `kv_cache_config: {max_tokens: N}`, on a unified-memory card (`tensorrtLlmUnifiedKvMaxTokens`,
251
+ * `kv-cache.ts`).
252
+ * `llm_args.py` `KvCacheConfig.max_tokens` (1.2.1, line 1636): "If both `max_tokens` and
253
+ * `free_gpu_memory_fraction` are specified, memory corresponding to the minimum will be used."
254
+ * The fraction the argv passes survives the YAML: `serve.py`'s `get_llm_args` builds
255
+ * `KvCacheConfig(free_gpu_memory_fraction=...)` (line 125), and `update_llm_args_with_extra_dict`
256
+ * (`llm_args.py` line 3312) deep-merges a YAML `kv_cache_config` over it
257
+ * (`model_dump(exclude_unset=True) | yaml`), so the fraction stays the upper bound.
258
+ */
259
+ export const TENSORRT_LLM_API_OPTIONS_FILE = 'llm-api-options.yaml';
260
+ export const TENSORRT_LLM_GUIDED_DECODING_OPTIONS = 'guided_decoding_backend: xgrammar\n';
261
+ /**
262
+ * The option file's text, or `null` when no key applies (no file, no flag). The settings' further
263
+ * options are written only when they differ from the engine's own default, so a launch with the
264
+ * defaults stays what it was (`llm_args.py`: `KvCacheConfig.enable_block_reuse` default `True`,
265
+ * `TorchLlmArgs.disable_overlap_scheduler` default `False`, `SchedulerConfig.capacity_scheduler_policy`
266
+ * default `GUARANTEED_NO_EVICT`, `dtype` default `"auto"`).
267
+ */
268
+ function llmApiOptions(guided, kvMaxTokens, kvFp8 = false, cudaGraphsOff = false, settings) {
269
+ const lines = [];
270
+ if (guided)
271
+ lines.push(TENSORRT_LLM_GUIDED_DECODING_OPTIONS.trimEnd());
272
+ const noBlockReuse = settings?.enable_prefix_caching === false;
273
+ if (kvMaxTokens !== null || kvFp8 || noBlockReuse) {
274
+ lines.push('kv_cache_config:');
275
+ if (kvMaxTokens !== null)
276
+ lines.push(` max_tokens: ${kvMaxTokens}`);
277
+ if (kvFp8)
278
+ lines.push(' dtype: fp8');
279
+ if (noBlockReuse)
280
+ lines.push(' enable_block_reuse: false');
281
+ }
282
+ // `null` turns CUDA graphs off on the PyTorch backend (`llm_args.py`, `cuda_graph_config`).
283
+ if (cudaGraphsOff)
284
+ lines.push('cuda_graph_config: null');
285
+ if (settings?.overlap_scheduler === false)
286
+ lines.push('disable_overlap_scheduler: true');
287
+ if (settings?.capacity_scheduler_policy === 'max_utilization') {
288
+ lines.push('scheduler_config:', ' capacity_scheduler_policy: MAX_UTILIZATION');
289
+ }
290
+ if (settings !== undefined && settings.dtype !== 'auto')
291
+ lines.push(`dtype: ${settings.dtype}`);
292
+ return lines.length === 0 ? null : `${lines.join('\n')}\n`;
293
+ }
294
+ /** Below this much card memory `cuda_graphs: auto` leaves CUDA graphs off: they took about 2 GB on
295
+ * an 8 GB card in the Windows live acceptance (Qwen3.5-2B, "Memory used outside torch … 2.12 GiB").
296
+ * A card that reports no size of its own is a unified-memory one (GB10): it keeps them. */
297
+ export const TENSORRT_LLM_CUDA_GRAPHS_MIN_VRAM_BYTES = 12 * 1024 ** 3;
298
+ /** FP8 KV cache needs compute capability 8.9 (Ada) or newer. */
299
+ function supportsFp8Kv(computeCapability) {
300
+ if (computeCapability === null || computeCapability === undefined)
301
+ return false;
302
+ const [major, minor] = computeCapability.split('.').map((part) => Number(part));
303
+ if (major === undefined || Number.isNaN(major))
304
+ return false;
305
+ return major > 8 || (major === 8 && (minor ?? 0) >= 9);
306
+ }
307
+ /**
308
+ * `--max_batch_size`: how many sequences the engine serves at once. `trtllm-serve` defaults to 2048, a
309
+ * server's number; a desktop runs a chat, an agent turn and a few API calls at most. For a model with
310
+ * recurrent layers (Qwen3.5, hybrid Mamba) the engine reserves the recurrent state for every one of
311
+ * those sequences up front: on an 8 GB card Qwen3.5-2B failed with "The V2 Mamba GPU cache quota is
312
+ * too small … need at least 20696801280 bytes" (Windows live acceptance, 1.3.0rc29). Attention-only
313
+ * models only lose queueing beyond this many concurrent requests. One by default (owner's decision,
314
+ * change `add-vllm-runtime`): the KV cache is then sized for one full context, which is what fits a
315
+ * desktop card; a person who runs agents in parallel raises it.
316
+ */
317
+ export const TENSORRT_LLM_MAX_BATCH_SIZE = 1;
318
+ export const TENSORRT_LLM_MAX_MAX_BATCH_SIZE = 256;
319
+ export const TENSORRT_LLM_MAX_KV_CACHE_MAX_TOKENS = 16_777_216;
320
+ /** The container binds every interface; only the host-side publication (design D1/D11) is
321
+ * loopback-restricted, by the executor, not by the engine's own bind address. */
322
+ const CONTAINER_BIND_HOST = '0.0.0.0';
323
+ /** Builds `trtllm-serve serve <model-dir> ...` (task 2.13; flags sourced from `serve.py`, see the
324
+ * file header). `serve` is named explicitly rather than relying on the CLI's default-command
325
+ * resolution (`DefaultGroup.resolve_command`, `commands/serve.py`) — that quirk keeps `trtllm-serve
326
+ * MODEL` working when a user types it by hand, but a generated argv should not depend on undocumented
327
+ * fallback dispatch. The tool/reasoning parser flags are appended only when the pinned descriptor's
328
+ * `model_families` entry for this model's architecture names them (spec "Возможности модели
329
+ * объявляются, а не угадываются", design D9); the descriptor's own regex already validated those
330
+ * names, so they are passed through verbatim.
331
+ *
332
+ * `--max_num_tokens` is set to `context_length`, not `max_output_tokens` (findings-2.13-r1.md item
333
+ * 1's ruling): on the pytorch backend this flag caps the *prompt* alone
334
+ * (`llmapi/llm.py`'s `_check_arguments`, file header), so pointing it at the output-length setting
335
+ * was wrong from the start — it silently shrank the usable prompt window to whatever the output
336
+ * setting happened to be. `max_output_tokens` is enforced per request instead, by
337
+ * `tensorrtLlmRewriteRequestBody` through the session gateway (below; see
338
+ * `docs/decisions/2026-09-28-tensorrt-llm-output-cap-enforced-by-the-session-gateway.md`), because
339
+ * this engine release has no server-side flag that caps a reply's length at all. */
340
+ export function buildTensorrtLlmLaunch(context) {
341
+ const { settings, modelPath, engineCachePath, generationFilesPath, family } = context;
342
+ const argv = [
343
+ 'trtllm-serve',
344
+ 'serve',
345
+ modelPath,
346
+ '--host',
347
+ CONTAINER_BIND_HOST,
348
+ '--port',
349
+ String(TENSORRT_LLM_CONTAINER_PORT),
350
+ '--max_seq_len',
351
+ String(settings.context_length),
352
+ '--max_num_tokens',
353
+ String(settings.context_length),
354
+ '--max_batch_size',
355
+ String(settings.max_batch_size),
356
+ '--kv_cache_free_gpu_memory_fraction',
357
+ String(settings.kv_cache_free_gpu_memory_fraction),
358
+ ];
359
+ if (family?.tool_parser != null)
360
+ argv.push('--tool_parser', family.tool_parser);
361
+ if (family?.reasoning_parser != null)
362
+ argv.push('--reasoning_parser', family.reasoning_parser);
363
+ // Guided decoding is off in trtllm-serve unless an LLM API option turns it on (final review I-2):
364
+ // `response_format` is otherwise ignored or refused, so a family that declares structured output
365
+ // gets `guided_decoding_backend: xgrammar` through the option file, written read-only per generation.
366
+ // On a unified-memory card the same file bounds the KV cache by tokens (`kv-cache.ts`).
367
+ // The KV cache is always bounded in tokens too: a hybrid (Mamba) model on 1.3.0rc29 refuses to start
368
+ // without it ("Quota not set. Check kv_cache_config.max_tokens or kv_cache_config.max_gpu_total_bytes",
369
+ // Windows live acceptance with Qwen3.5-2B). Room for every sequence the batch admits at full context;
370
+ // the engine takes the smaller of this and the free-memory fraction, so attention-only models keep
371
+ // the memory they had. A unified-memory card keeps its own, tighter bound.
372
+ const vram = context.gpuTotalVramBytes ?? null;
373
+ const cudaGraphsOff = settings.cuda_graphs === 'off' ||
374
+ (settings.cuda_graphs === 'auto' && vram !== null && vram < TENSORRT_LLM_CUDA_GRAPHS_MIN_VRAM_BYTES);
375
+ const kvFp8 = settings.kv_cache_dtype === 'fp8' && supportsFp8Kv(context.gpuComputeCapability);
376
+ const options = llmApiOptions(family?.structured_output === true, settings.kv_cache_max_tokens ??
377
+ (context.unifiedMemory
378
+ ? tensorrtLlmUnifiedKvMaxTokens(settings.context_length)
379
+ : settings.context_length * settings.max_batch_size), kvFp8, cudaGraphsOff, settings);
380
+ if (options !== null) {
381
+ argv.push('--extra_llm_api_options', `${generationFilesPath}/${TENSORRT_LLM_API_OPTIONS_FILE}`);
382
+ }
383
+ return {
384
+ engine: { container_port: TENSORRT_LLM_CONTAINER_PORT },
385
+ argv,
386
+ ...(options !== null ? { files: { [TENSORRT_LLM_API_OPTIONS_FILE]: options } } : {}),
387
+ // No `--cache_dir`/`TRTLLM_CACHE_DIR` in this pinned tag (file header) — these are the
388
+ // individual upstream PyTorch/Triton/CUDA JIT caches whose warm state make a repeat start on
389
+ // the same model faster, redirected onto the read-write engine cache mount (design D8) so they
390
+ // survive past this container's lifetime instead of vanishing with it.
391
+ env: {
392
+ TORCHINDUCTOR_CACHE_DIR: `${engineCachePath}/inductor`,
393
+ TRITON_CACHE_DIR: `${engineCachePath}/triton`,
394
+ CUDA_CACHE_PATH: `${engineCachePath}/nvcc`,
395
+ // From 1.3 `trtllm-serve` reports anonymous usage to NVIDIA by default; a local app does not.
396
+ TRTLLM_NO_USAGE_STATS: '1',
397
+ },
398
+ };
399
+ }
400
+ // ---------------------------------------------------------------------------------------------
401
+ // Readiness timeout
402
+ // ---------------------------------------------------------------------------------------------
403
+ /**
404
+ * Placeholder coefficients (design D8's own open question: "Точные... коэффициенты таймаута
405
+ * загрузки — измеряются в live-тесте core", i.e. live test 2.19 replaces these). Until then they
406
+ * only have to clear the spec's own acceptance scenario ("Долгий первый старт": a 30 GB model
407
+ * starting in three minutes must not time out) with real headroom, not cut it close.
408
+ *
409
+ * Raised from 60 s + 6 s/GiB (2026-10-06): on an NVIDIA RTX Spark (Windows on Arm, WSL) Qwen3.5-2B
410
+ * spent 62 s in executor profiling alone and was still sizing its KV cache, with no error, when the
411
+ * 128 s that formula gave ran out. A healthy slow start must not fail; a stuck one still ends.
412
+ */
413
+ export const TENSORRT_LLM_READINESS_BASE_MS = 240_000;
414
+ /** Budgeted per GiB of checkpoint weights, before the margin multiplier — to be measured in live test 2.19. */
415
+ export const TENSORRT_LLM_READINESS_PER_GIB_MS = 12_000;
416
+ /** Applied to the whole base-plus-per-GiB estimate — to be measured in live test 2.19. */
417
+ export const TENSORRT_LLM_READINESS_MARGIN = 1.5;
418
+ /** Base plus time-per-GiB-of-weights, with margin (spec "Этапы и таймаут загрузки", design D8) —
419
+ * unless `settings.load_timeout_seconds` is set, which wins outright (findings-2.13-r1.md item 4:
420
+ * round 1 validated this setting but never read it back, so it was accepted and then silently
421
+ * ignored). The lifecycle's own `resolveReadinessTimeoutMs` (`../managed-text/load-policy.ts`)
422
+ * still applies a *second*, load-request-level override on top of whatever this returns — that
423
+ * path exists for a caller that computes its own override outside the settings object entirely; a
424
+ * `tensorrt-llm` load never populates it, so this function's return value is what actually wins. */
425
+ export function tensorrtLlmReadinessTimeoutMs(weightBytes, settings) {
426
+ if (settings.load_timeout_seconds !== null)
427
+ return settings.load_timeout_seconds * 1000;
428
+ const weightGiB = Math.max(weightBytes, 0) / GiB;
429
+ const estimate = TENSORRT_LLM_READINESS_BASE_MS + TENSORRT_LLM_READINESS_PER_GIB_MS * weightGiB;
430
+ return Math.ceil(estimate * TENSORRT_LLM_READINESS_MARGIN);
431
+ }
432
+ // ---------------------------------------------------------------------------------------------
433
+ // Exit classification
434
+ // ---------------------------------------------------------------------------------------------
435
+ /** `torch`'s own CUDA allocator wording (not TensorRT-LLM-specific), both the modern
436
+ * `torch.OutOfMemoryError` subclass and the plain `RuntimeError` older/lower call sites still
437
+ * raise, plus the executor's own C++-side allocator failure — `py_executor_creator.py`'s
438
+ * `_maybe_explain_if_oom` treats any exception whose text contains `"out of memory"` (lowercase)
439
+ * as OOM regardless of its own wording, which is why this also matches a generic `CUDA runtime
440
+ * error in ...: out of memory` shape rather than only `torch`'s own message (file header).
441
+ *
442
+ * Added after the 2026-09-29 VM run (docs/decisions/2026-09-29-tensorrt-llm-kv-cache-fraction-0-8-
443
+ * and-oom-read-from-the-whole-log.md), whose log carried these alongside `CUDA out of memory`:
444
+ * `torch.AcceleratorError: CUDA error: out of memory` (a CUDA call's own error string, raised
445
+ * through torch's CUDA check rather than its allocator); `_maybe_explain_if_oom`'s own "Executor
446
+ * creation failed due to insufficient GPU memory." (v1.2.1 `py_executor_creator.py`); and "The GPU
447
+ * ran out of memory", as the run reported it, source not pinned. */
448
+ const OOM_MARKER = new RegExp([
449
+ /torch\.(?:cuda\.)?OutOfMemoryError/.source,
450
+ /CUDA out of memory/.source,
451
+ /CUDA runtime error in .*: out of memory/.source,
452
+ /CUDA error: out of memory/.source,
453
+ /Executor creation failed due to insufficient GPU memory/.source,
454
+ /The GPU ran out of memory/.source,
455
+ ].join('|'));
456
+ /** How much of the log an out-of-memory classification carries as its `excerpt`. */
457
+ const OOM_EXCERPT_MAX_LINES = 8;
458
+ const OOM_EXCERPT_MAX_LINE_CHARS = 500;
459
+ const OOM_TRIED_TO_ALLOCATE = /Tried to allocate ([\d.]+)\s*(GiB|MiB|KiB)/;
460
+ const OOM_FREE = /of which ([\d.]+)\s*(GiB|MiB|KiB|bytes) is free/;
461
+ /**
462
+ * The numbers of one allocation failure, never mixed across two: `torch`'s message carries "Tried to
463
+ * allocate X" and "of which Y is free" on one line. The last line that reports both wins — the most
464
+ * recent complete account of a failure; failing that, the last request alone (no free figure borrowed
465
+ * from another failure); failing that, the last free figure alone.
466
+ */
467
+ function oomNumbers(log) {
468
+ let complete = null;
469
+ let lastTried = null;
470
+ let lastFree = null;
471
+ for (const line of log.split('\n')) {
472
+ const tried = OOM_TRIED_TO_ALLOCATE.exec(line);
473
+ const free = OOM_FREE.exec(line);
474
+ if (tried && free)
475
+ complete = { tried, free };
476
+ if (tried)
477
+ lastTried = tried;
478
+ if (free)
479
+ lastFree = free;
480
+ }
481
+ if (complete !== null)
482
+ return complete;
483
+ return lastTried !== null ? { tried: lastTried, free: null } : { tried: null, free: lastFree };
484
+ }
485
+ /** `tensorrt_llm/_torch/models/modeling_auto.py`'s `AutoModelForCausalLM.from_config` — the
486
+ * pytorch backend's model class lookup (file header); not the legacy `tensorrt`-backend loader's
487
+ * wording, which this adapter's launch never reaches. */
488
+ const UNSUPPORTED_ARCHITECTURE = /Unknown architecture for AutoModelForCausalLM: (\S+)/;
489
+ /** `tensorrt_llm/_torch/modules/linear.py`'s two real `quant_mode`/`quant mode` rejections (file
490
+ * header, lines 292 and 2066); deliberately not the `"Unsupported quant algo"` *warning* those
491
+ * modules also log, which is never raised as an exception. */
492
+ const UNSUPPORTED_QUANTIZATION = /unsupported quant[_ ]mode:/i;
493
+ function toGiB(amount, unit) {
494
+ if (unit === 'GiB')
495
+ return amount;
496
+ if (unit === 'MiB')
497
+ return amount / 1024;
498
+ if (unit === 'KiB')
499
+ return amount / (1024 * 1024);
500
+ return amount / GiB; // 'bytes'
501
+ }
502
+ /** Every line naming the out-of-memory failure, once each, in log order, bounded in count and width
503
+ * (a tqdm progress line can run to kilobytes): the lines a user needs, kept even after a long
504
+ * traceback has pushed them out of the log tail the error details otherwise show. */
505
+ function oomExcerpt(log) {
506
+ const lines = [];
507
+ for (const raw of log.split('\n')) {
508
+ if (!OOM_MARKER.test(raw))
509
+ continue;
510
+ const trimmed = raw.trim();
511
+ const line = trimmed.length > OOM_EXCERPT_MAX_LINE_CHARS
512
+ ? `${trimmed.slice(0, OOM_EXCERPT_MAX_LINE_CHARS - 1)}…`
513
+ : trimmed;
514
+ if (lines.includes(line))
515
+ continue;
516
+ lines.push(line);
517
+ if (lines.length === OOM_EXCERPT_MAX_LINES)
518
+ break;
519
+ }
520
+ return lines.join('\n');
521
+ }
522
+ function classifyOom(log) {
523
+ if (!OOM_MARKER.test(log))
524
+ return null;
525
+ // One failure's numbers, the last complete one: with the whole log in play the first match could be
526
+ // an earlier, handled failure, and two independent last matches could mix two failures.
527
+ const { tried, free } = oomNumbers(log);
528
+ const numbers = {};
529
+ let requestedText = 'an unknown amount of';
530
+ let freeText = '';
531
+ if (tried) {
532
+ const requestedGiB = toGiB(Number(tried[1]), tried[2]);
533
+ numbers['requested_gib'] = requestedGiB;
534
+ requestedText = `${requestedGiB} GiB`;
535
+ }
536
+ if (free) {
537
+ const freeGiB = toGiB(Number(free[1]), free[2]);
538
+ numbers['free_gib'] = freeGiB;
539
+ freeText = ` (${freeGiB} GiB free)`;
540
+ }
541
+ return {
542
+ kind: 'out-of-memory',
543
+ message: `The GPU ran out of memory: trtllm-serve tried to allocate ${requestedText} memory${freeText}.`,
544
+ ...(Object.keys(numbers).length > 0 ? { numbers } : {}),
545
+ excerpt: oomExcerpt(log),
546
+ };
547
+ }
548
+ function classifyUnsupportedArchitecture(log) {
549
+ const arch = UNSUPPORTED_ARCHITECTURE.exec(log);
550
+ return arch
551
+ ? {
552
+ kind: 'unsupported-model',
553
+ message: `The model architecture ${arch[1]} is not supported by this TensorRT-LLM release.`,
554
+ }
555
+ : null;
556
+ }
557
+ function classifyUnsupportedQuantization(log) {
558
+ return UNSUPPORTED_QUANTIZATION.test(log)
559
+ ? {
560
+ kind: 'unsupported-model',
561
+ message: 'This model is quantized in a format this TensorRT-LLM release does not load.',
562
+ }
563
+ : null;
564
+ }
565
+ /** Reads a container's log and exit code into why it exited (spec "Этапы и таймаут загрузки": a
566
+ * container that exits before readiness fails the load immediately with this classification and
567
+ * the log tail, instead of waiting out the full timeout). Before readiness the lifecycle hands over
568
+ * the container's whole log, not its tail, and every line of it is searched: the out-of-memory line
569
+ * can sit above a worker traceback longer than the tail, ending in "RuntimeError: Executor worker
570
+ * returned error" (2026-09-29 VM run). Checked in order: an unsupported architecture first — the
571
+ * model class lookup raises it before anything is allocated, so it is decisive even when a handled
572
+ * out-of-memory line appears earlier in the whole log — then an out-of-memory message, with the
573
+ * lines that said so as `excerpt` and the numbers of the last allocation failure, then an
574
+ * unsupported quantization, otherwise `other`. */
575
+ /** The KV-cache manager's own capacity line: `[batchmgr][RANK 0] Max KV cache blocks per sequence: … max sequence length=224`. */
576
+ const KV_CAPACITY_LINE = /^.*\bmax sequence length=(\d+).*$/gm;
577
+ /**
578
+ * Whether a `trtllm-serve` that answered `/health` can hold one sequence of the context it was
579
+ * launched with: the KV-cache manager logs how long a sequence it can keep (the last line wins — the
580
+ * engine logs one for its memory-profiling pass and one for the final allocation). Shorter than the
581
+ * context length is an out-of-memory refusal with both numbers — Ministral-3b bf16 on an RTX 4070
582
+ * Laptop started with room for 224 tokens of a 4096-token context and answered every request with an
583
+ * empty, failed stream. No such line (another engine build) is not a refusal.
584
+ */
585
+ export function classifyTensorrtLlmReady(log, settings) {
586
+ const lines = [...log.matchAll(KV_CAPACITY_LINE)];
587
+ const last = lines.at(-1);
588
+ if (last === undefined)
589
+ return null;
590
+ const capacity = Number.parseInt(last[1], 10);
591
+ const context = settings.context_length;
592
+ if (!Number.isFinite(capacity) || capacity >= context)
593
+ return null;
594
+ return {
595
+ kind: 'out-of-memory',
596
+ message: `The model loaded, but this GPU has room for a KV cache of only ${capacity} tokens, less than the ` +
597
+ `context length of ${context}. Lower the context length in the TensorRT-LLM settings, or use a ` +
598
+ `smaller or quantized model.`,
599
+ numbers: { kv_capacity_tokens: capacity, context_length: context },
600
+ excerpt: last[0].trim(),
601
+ };
602
+ }
603
+ /** `tensorrt_llm.executor.utils.RequestError: KV_CACHE_MANAGER requires 67 KV cache blocks …` and the like. */
604
+ const REQUEST_ERROR_LINE = /^.*\bRequestError:\s*(.+?)\s*$/gm;
605
+ /**
606
+ * The engine's own words for the request it failed mid-stream: the last `RequestError` in the log
607
+ * tail. `trtllm-serve` raises it inside the streaming generator after `200 OK` and only logs it, so
608
+ * the client otherwise saw an empty answer (Ministral-3b on an 8 GB card: "KV_CACHE_MANAGER requires
609
+ * 67 KV cache blocks to complete the request, which exceeds its GPU-primary capacity of 7 blocks").
610
+ */
611
+ export function describeTensorrtLlmStreamFailure(logTail) {
612
+ const last = [...logTail.matchAll(REQUEST_ERROR_LINE)].at(-1);
613
+ return last === undefined ? null : `TensorRT-LLM failed the request: ${last[1]}`;
614
+ }
615
+ export function classifyTensorrtLlmExit(log, exitCode) {
616
+ const classification = classifyUnsupportedArchitecture(log) ?? classifyOom(log) ?? classifyUnsupportedQuantization(log);
617
+ if (classification)
618
+ return classification;
619
+ const codeText = exitCode === null ? 'with no exit code' : `with exit code ${exitCode}`;
620
+ return { kind: 'other', message: `trtllm-serve exited unexpectedly ${codeText} before it became ready.` };
621
+ }
622
+ // ---------------------------------------------------------------------------------------------
623
+ // Capabilities
624
+ // ---------------------------------------------------------------------------------------------
625
+ /** What a loaded model can do (spec "Возможности модели объявляются, а не угадываются", design D9):
626
+ * tool calling and reasoning only when the pinned descriptor's `model_families` entry for this
627
+ * model's architecture names the parser the launch was actually started with; structured output
628
+ * only when that same entry declares it; vision, embeddings and the Responses API are unsupported
629
+ * in this slice regardless of family. `settings` plays no part in this — capabilities are read
630
+ * entirely off the descriptor, never guessed the way the llama.cpp provider does — but the
631
+ * parameter stays because `ManagedTextAdapter.capabilities` always hands both through. */
632
+ export function tensorrtLlmCapabilities(context) {
633
+ const { family } = context;
634
+ return {
635
+ tools: family?.tool_parser != null,
636
+ reasoning: family?.reasoning_parser != null,
637
+ structured_output: family?.structured_output ?? false,
638
+ vision: false,
639
+ embeddings: false,
640
+ responses: false,
641
+ };
642
+ }
643
+ // ---------------------------------------------------------------------------------------------
644
+ // Declared routes
645
+ // ---------------------------------------------------------------------------------------------
646
+ /** The OpenAI method+path routes this adapter's engine actually serves (`openai_server.py`
647
+ * registers exactly these three for text; task 2.14 refuses any other public route for a
648
+ * `tensorrt-llm` model — spec: "Публичный сервер MUST отвечать понятной ошибкой на маршрут,
649
+ * который провайдер не объявил"). Also `ManagedTextAdapter.routes` below: the session gateway
650
+ * 404s a path not listed here at all, and 405s a listed path used with a method not listed for
651
+ * it (findings-2.13-r3.md item 1) — either way before it ever reaches the container. This closes
652
+ * off `trtllm-serve`'s own undeclared routes — its `/health` (probed directly by the lifecycle,
653
+ * never through the gateway), its administrative routes this adapter never wanted reachable at
654
+ * all (`/update_weights`, `/release_memory`, `/resume_memory`, `/kv_cache_events`,
655
+ * `/steady_clock_offset`), `/v1/responses` (real in `openai_server.py`, unsupported in this
656
+ * slice) — and a wrong method on a route that is otherwise real, e.g. `GET
657
+ * /v1/chat/completions` or `POST /v1/models` (findings-2.13-r2.md item 3, keyed on method+path
658
+ * since findings-2.13-r3.md item 1). No route here declares `HEAD`; a `HEAD /v1/models` request
659
+ * gets the same `405` as any other undeclared method for a declared path — this engine's `GET
660
+ * /v1/models` has no dedicated `HEAD` handler to serve it from. */
661
+ export const TENSORRT_LLM_ROUTES = [
662
+ { method: 'POST', path: '/v1/chat/completions' },
663
+ { method: 'POST', path: '/v1/completions' },
664
+ { method: 'GET', path: '/v1/models' },
665
+ ];
666
+ /** The subset of `TENSORRT_LLM_ROUTES` `tensorrtLlmRewriteRequestBody` may rewrite: both POST
667
+ * routes, never `GET /v1/models` (no request body to rewrite in the first place). */
668
+ export const TENSORRT_LLM_REWRITABLE_ROUTES = [
669
+ { method: 'POST', path: '/v1/chat/completions' },
670
+ { method: 'POST', path: '/v1/completions' },
671
+ ];
672
+ const NUM = '(-?[\\d.]+)';
673
+ /** pytorch backend `_check_arguments` (`llmapi/llm.py`, file header): fires unconditionally by
674
+ * default (chunked prefill is off unless explicitly enabled, which this adapter never does) for
675
+ * *every* prompt whose length alone (now that `--max_num_tokens` == `context_length`, see
676
+ * `buildTensorrtLlmLaunch`) exceeds the context — the common overflow case, not an edge case
677
+ * (findings-2.13-r2.md item 6). */
678
+ const OVERFLOW_VS_MAX_NUM_TOKENS = new RegExp(`sum of prompt length \\(${NUM}\\), query length \\(${NUM}\\) should not exceed max_num_tokens \\(${NUM}\\)`);
679
+ /** The same check in 1.3.0rc29 (`llmapi/llm.py:1578`): the query length is gone from the message. */
680
+ const OVERFLOW_PROMPT_VS_MAX_NUM_TOKENS = new RegExp(`The prompt length \\(${NUM}\\) should not exceed max_num_tokens \\(${NUM}\\)`);
681
+ /** pytorch backend `_deduce_max_tokens` (`base_worker.py`, file header): a narrow boundary case, not
682
+ * the common one — since `_check_arguments` above already guarantees `prompt + query <=
683
+ * max_seq_len` before this ever runs, this only fires when `prompt + query` lands *exactly* on
684
+ * `max_seq_len`, leaving zero room for any output (findings-2.13-r2.md item 6 corrects round 1's
685
+ * claim that this was "the case that actually fires now"). `default_max_tokens` itself repeats in
686
+ * the message (`(-?[\\d.]+)` because it is the quantity that is `<= 0`); only the second copy is
687
+ * used, for clarity, in `mapTensorrtLlmContextLengthError`. */
688
+ const OVERFLOW_VIA_DEDUCE_MAX_TOKENS = new RegExp('`default_max_tokens` \\(' +
689
+ NUM +
690
+ '\\) must be greater than 0, `default_max_tokens` \\(' +
691
+ NUM +
692
+ '\\) = max_seq_len \\(' +
693
+ NUM +
694
+ '\\) - `splited_prompt_len` \\(' +
695
+ NUM +
696
+ '\\) - `query_token_len` \\(' +
697
+ NUM +
698
+ '\\)');
699
+ /** The same boundary case in 1.3.0rc29 (`base_worker.py:456-458`): no `query_token_len` term. */
700
+ const OVERFLOW_VIA_DEDUCE_MAX_TOKENS_NO_QUERY = new RegExp('`default_max_tokens` \\(' +
701
+ NUM +
702
+ '\\) must be greater than 0, `default_max_tokens` \\(' +
703
+ NUM +
704
+ '\\) = max_seq_len \\(' +
705
+ NUM +
706
+ '\\) - `splited_prompt_len` \\(' +
707
+ NUM +
708
+ '\\)');
709
+ /** `trtllm-serve`'s own `ErrorResponse` (`openai_server.py`'s `create_error_response`) is
710
+ * `{"object":"error","message":...,"type":...,"param":...,"code":<http status int>}` — this reads
711
+ * its `message` field when the body parses as that shape, and falls back to the raw body text
712
+ * otherwise, so an already-unwrapped message (e.g. a caller that stripped the envelope) still
713
+ * matches. */
714
+ function messageOf(body) {
715
+ try {
716
+ const parsed = JSON.parse(body);
717
+ if (parsed !== null &&
718
+ typeof parsed === 'object' &&
719
+ typeof parsed.message === 'string') {
720
+ return parsed.message;
721
+ }
722
+ }
723
+ catch {
724
+ // Not JSON at all: fall through and match against the raw body text.
725
+ }
726
+ return body;
727
+ }
728
+ function contextLengthExceeded(requestedTokens, maxTokens) {
729
+ const requested = Math.round(requestedTokens);
730
+ const limit = Math.round(maxTokens);
731
+ return {
732
+ error: {
733
+ message: `This model's maximum context length is ${limit} tokens. However, your messages resulted in ` +
734
+ `${requested} tokens. Please reduce the length of the messages.`,
735
+ type: 'invalid_request_error',
736
+ param: null,
737
+ code: 'context_length_exceeded',
738
+ },
739
+ };
740
+ }
741
+ /**
742
+ * Maps `trtllm-serve` 1.2.1's context-overflow errors — the pytorch backend's two real, reachable
743
+ * shapes, see the file header — to an OpenAI-compatible `context_length_exceeded` envelope with
744
+ * both numbers. `null` for any other `400` (a different validation failure, e.g. a bad sampling
745
+ * parameter) or any other status — 2.14 falls back to its own generic error wrapping for those, the
746
+ * same way `server/public/errors.ts` already does for llama.cpp/MLX. This is a pure text mapping;
747
+ * wiring it into the public `/v1/*` route handler is task 2.14's.
748
+ */
749
+ export function mapTensorrtLlmContextLengthError(status, body) {
750
+ if (status !== 400)
751
+ return null;
752
+ const message = messageOf(body);
753
+ const viaMaxNumTokens = OVERFLOW_VS_MAX_NUM_TOKENS.exec(message);
754
+ if (viaMaxNumTokens) {
755
+ const [, promptLen, queryLen, limit] = viaMaxNumTokens;
756
+ return contextLengthExceeded(Number(promptLen) + Number(queryLen), Number(limit));
757
+ }
758
+ const viaDeduceMaxTokens = OVERFLOW_VIA_DEDUCE_MAX_TOKENS.exec(message);
759
+ if (viaDeduceMaxTokens) {
760
+ const [, , , maxSeqLen, splitedPromptLen, queryTokenLen] = viaDeduceMaxTokens;
761
+ return contextLengthExceeded(Number(splitedPromptLen) + Number(queryTokenLen), Number(maxSeqLen));
762
+ }
763
+ const viaPromptVsMaxNumTokens = OVERFLOW_PROMPT_VS_MAX_NUM_TOKENS.exec(message);
764
+ if (viaPromptVsMaxNumTokens) {
765
+ const [, promptLen, limit] = viaPromptVsMaxNumTokens;
766
+ return contextLengthExceeded(Number(promptLen), Number(limit));
767
+ }
768
+ const viaDeduceNoQuery = OVERFLOW_VIA_DEDUCE_MAX_TOKENS_NO_QUERY.exec(message);
769
+ if (viaDeduceNoQuery) {
770
+ const [, , , maxSeqLen, splitedPromptLen] = viaDeduceNoQuery;
771
+ return contextLengthExceeded(Number(splitedPromptLen), Number(maxSeqLen));
772
+ }
773
+ return null;
774
+ }
775
+ // ---------------------------------------------------------------------------------------------
776
+ // Output-length enforcement (session gateway request rewrite)
777
+ // ---------------------------------------------------------------------------------------------
778
+ /** The paths whose request body `tensorrtLlmRewriteRequestBody` touches — both are POST-only in
779
+ * `TENSORRT_LLM_REWRITABLE_ROUTES`, and `route` here is always a path the gateway already matched
780
+ * by method too, so path alone is enough to key this `Set` on. Every other route (including the
781
+ * third declared one, `GET /v1/models`, which has no body at all) passes its body through
782
+ * completely unchanged. */
783
+ const OUTPUT_CAP_ROUTES = new Set(TENSORRT_LLM_REWRITABLE_ROUTES.map((r) => r.path));
784
+ function readCandidateField(body, key) {
785
+ if (!(key in body) || body[key] === null)
786
+ return { present: false, valid: false, value: 0 };
787
+ const value = body[key];
788
+ const valid = typeof value === 'number' && Number.isInteger(value) && value > 0;
789
+ return { present: true, valid, value: valid ? value : 0 };
790
+ }
791
+ /**
792
+ * Refuses, on the session gateway itself, what this session cannot do (findings-2.14-r1.md item 1;
793
+ * spec "запрос с `tools` к этой модели получает ошибку о неподдерживаемой возможности, а не молча
794
+ * игнорируется"): tool calls without a tool-call parser, JSON output without structured-output support
795
+ * for the family. `trtllm-serve` would otherwise accept the request and answer without honouring it.
796
+ * The wording and code are `:1337`'s own (`server/public/policy.ts`), so a client sees one error
797
+ * whichever port it talks to.
798
+ */
799
+ function refuseUnsupported(body, capabilities) {
800
+ const model = typeof body['model'] === 'string' ? `The model '${body['model']}'` : 'This model';
801
+ if (!capabilities.tools && asksForTools(body)) {
802
+ throw new ManagedRequestRefusal(`${model} does not support tool calling.`, 'unsupported_capability');
803
+ }
804
+ if (!capabilities.structured_output && asksForStructuredOutput(body)) {
805
+ throw new ManagedRequestRefusal(`${model} does not support structured output.`, 'unsupported_capability');
806
+ }
807
+ }
808
+ /** `AtomicCoreError('INVALID_ARGUMENT', ...)`, not a plain `Error`: the gateway
809
+ * (`../managed-text/gateway.ts`) only surfaces a rewrite-time throw's own message to the client
810
+ * when it is this exact shape — proof the message was actually written to reject something the
811
+ * client itself sent, not an arbitrary internal error message (findings-2.13-r3.md item 3). */
812
+ function invalidMaxTokens(field) {
813
+ throw new AtomicCoreError('INVALID_ARGUMENT', `${field} must be a positive integer.`);
814
+ }
815
+ function isPlainObject(value) {
816
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
817
+ }
818
+ /** Same shape and reason as `invalidMaxTokens`: the gateway surfaces this message as a `400`. */
819
+ function invalidJsonSchema() {
820
+ throw new AtomicCoreError('INVALID_ARGUMENT', "response_format.json_schema must be an object when response_format.type is 'json_schema'.");
821
+ }
822
+ /** A wrapper (`name`/`strict`) with no object `schema`: OpenAI refuses it too, and so must we. */
823
+ function invalidJsonSchemaWrapper() {
824
+ throw new AtomicCoreError('INVALID_ARGUMENT', 'response_format.json_schema.schema must be an object when response_format.json_schema carries name or strict.');
825
+ }
826
+ /**
827
+ * Translates OpenAI's `json_schema` wrapper into what `trtllm-serve` 1.2.1 actually reads (ADR
828
+ * `docs/decisions/2026-09-29-tensorrt-llm-json-schema-wrapper-unwrapped-by-the-session-gateway.md`).
829
+ * `openai_protocol.py`'s `_response_format_to_guided_decoding_params` hands the WHOLE `json_schema`
830
+ * field to `GuidedDecodingParams(json=...)` as the schema, so an OpenAI client's
831
+ * `{"name", "strict", "schema": S}` becomes a grammar for a schema with no real constraint, and the
832
+ * model answers with any JSON value (a bare string, on the live run). Here `json_schema` becomes the
833
+ * inner `S`, dropping `name`/`strict`/`description`. A `json_schema` that looks like the wrapper (it
834
+ * has `name` or `strict`, which are not JSON Schema keywords) but has no object `schema` is refused,
835
+ * as OpenAI does; one without those keys and without an object `schema` is taken to be the bare
836
+ * schema already and passes unchanged. One that is missing or not an object is refused too (the
837
+ * engine would answer a `400` or a `500` of its own). Every other format type passes unchanged. Returns `format` itself when nothing changes.
838
+ */
839
+ function unwrapJsonSchemaFormat(format) {
840
+ if (!isPlainObject(format) || format['type'] !== 'json_schema')
841
+ return format;
842
+ const wrapper = format['json_schema'];
843
+ if (!isPlainObject(wrapper))
844
+ invalidJsonSchema();
845
+ const inner = wrapper['schema'];
846
+ if (!isPlainObject(inner)) {
847
+ if ('name' in wrapper || 'strict' in wrapper)
848
+ invalidJsonSchemaWrapper();
849
+ return format;
850
+ }
851
+ return { ...format, json_schema: inner };
852
+ }
853
+ /**
854
+ * Reasoning parsers that assume every reply starts inside the reasoning, because the chat template
855
+ * opens `<think>` in the prompt when thinking is on. `qwen3_5` (Qwen3.5, 1.3.0rc29) is one: with
856
+ * thinking off the template closes an empty `<think></think>` in the prompt instead, the model
857
+ * answers with no tags at all, and the parser still files the whole answer under
858
+ * `reasoning_content`, leaving `content` empty (Windows live acceptance, Qwen3.5-2B). The parser is
859
+ * fixed per container; only the request says whether thinking was on.
860
+ */
861
+ export const TENSORRT_LLM_REASONING_AT_START_PARSERS = new Set(['qwen3_5']);
862
+ /** Moves a no-thinking reply filed as reasoning back into `content` (the shared rule, `request-rules.ts`). */
863
+ export const tensorrtLlmReasoningIntoContent = reasoningIntoContent;
864
+ /** The response rewrite for a chat request with thinking off on a reasoning-at-start parser. */
865
+ export function tensorrtLlmRewriteResponseFor(route, requestBody, family) {
866
+ if (route !== '/v1/chat/completions')
867
+ return null;
868
+ const parser = family?.reasoning_parser ?? null;
869
+ if (parser === null || !TENSORRT_LLM_REASONING_AT_START_PARSERS.has(parser))
870
+ return null;
871
+ return thinkingRequested(requestBody) ? null : reasoningIntoContent;
872
+ }
873
+ /**
874
+ * Enforces `settings.max_output_tokens` per request, since `trtllm-serve` 1.2.1 has no server-side
875
+ * flag that does it (`buildTensorrtLlmLaunch`'s doc comment; ADR
876
+ * `docs/decisions/2026-09-28-tensorrt-llm-output-cap-enforced-by-the-session-gateway.md`). Only
877
+ * `TENSORRT_LLM_REWRITABLE_ROUTES` are touched; every other route's body returns unchanged, as does
878
+ * a body that is not a plain JSON object (an array, a primitive, `null`) — the gateway's own JSON
879
+ * parse already rejected anything that is not valid JSON at all before this ever runs.
880
+ *
881
+ * `/v1/completions` only ever had `max_tokens`: a present value is clamped to
882
+ * `min(value, settings.max_output_tokens)`; absent, the setting is written outright.
883
+ *
884
+ * `/v1/chat/completions` writes exactly ONE of `max_tokens`/`max_completion_tokens` — never both —
885
+ * because TRT-LLM 1.2.1's `ChatCompletionRequest` (`openai_protocol.py`, `extra="forbid"`) has a
886
+ * single Python field, `max_completion_tokens`, whose `validation_alias` is `max_tokens`; sending
887
+ * both as separate top-level keys makes pydantic reject the whole request with `400
888
+ * extra_forbidden` (findings-2.13-r2.md item 1, reproduced by the reviewer with `pydantic` against
889
+ * this exact model — round 1's own ruling did exactly this and broke every chat request). If the
890
+ * client sent `max_completion_tokens`, the rewritten body keeps that key; else if it sent
891
+ * `max_tokens`, that key; else `max_tokens` (this route's own default when nothing was sent at
892
+ * all). If the client sent both, the lower of the two (each still capped) wins, under the
893
+ * `max_completion_tokens` key.
894
+ *
895
+ * A present value that is not a positive integer (a string, `0`, a negative number — `null` counts
896
+ * as not sent, matching how OpenAI clients omit a field) throws rather than silently substituting
897
+ * the setting, so the client sees why its request was refused instead of one that silently used a
898
+ * different limit than it asked for. The gateway (`../managed-text/gateway.ts`) turns that throw
899
+ * into an OpenAI-shaped `400` using this function's own `Error.message`.
900
+ *
901
+ * `n` (multiple choices) is untouched: the cap is a per-choice output limit — the same as
902
+ * `max_output_tokens` is documented to mean — not a budget shared across `n` completions.
903
+ *
904
+ * With the session's `capabilities` (the lifecycle always passes them; task 2.14 fix round 1), a
905
+ * request asking for what the model cannot do — tool calls without a parser, JSON output without
906
+ * structured-output support — is refused first (`refuseUnsupported`), before anything is rewritten.
907
+ *
908
+ * On both routes (`CompletionRequest` and `ChatCompletionRequest` share one `ResponseFormat` in
909
+ * 1.2.1), an OpenAI `json_schema` wrapper in `response_format` is unwrapped to the bare schema the
910
+ * engine reads (`unwrapJsonSchemaFormat`).
911
+ */
912
+ export function tensorrtLlmRewriteRequestBody(route, body, settings, capabilities) {
913
+ if (!OUTPUT_CAP_ROUTES.has(route))
914
+ return body;
915
+ if (typeof body !== 'object' || body === null || Array.isArray(body))
916
+ return body;
917
+ const client = body;
918
+ if (capabilities !== undefined)
919
+ refuseUnsupported(client, capabilities);
920
+ let obj = 'response_format' in client
921
+ ? { ...client, response_format: unwrapJsonSchemaFormat(client['response_format']) }
922
+ : client;
923
+ const cap = settings.max_output_tokens;
924
+ // trtllm-serve has no launch option for sampling defaults; a request that sets none gets them here.
925
+ obj = withGenerationDefaults(obj, settings.generation);
926
+ if (route === '/v1/completions') {
927
+ const field = readCandidateField(obj, 'max_tokens');
928
+ if (field.present && !field.valid)
929
+ invalidMaxTokens('max_tokens');
930
+ return { ...obj, max_tokens: field.present ? Math.min(field.value, cap) : cap };
931
+ }
932
+ // /v1/chat/completions
933
+ const legacy = readCandidateField(obj, 'max_tokens');
934
+ const modern = readCandidateField(obj, 'max_completion_tokens');
935
+ if ((legacy.present && !legacy.valid) || (modern.present && !modern.valid)) {
936
+ invalidMaxTokens('max_tokens/max_completion_tokens');
937
+ }
938
+ const values = [];
939
+ if (legacy.valid)
940
+ values.push(legacy.value);
941
+ if (modern.valid)
942
+ values.push(modern.value);
943
+ const value = values.length > 0 ? Math.min(cap, ...values) : cap;
944
+ const outKey = modern.present ? 'max_completion_tokens' : 'max_tokens';
945
+ const rest = { ...obj };
946
+ delete rest['max_tokens'];
947
+ delete rest['max_completion_tokens'];
948
+ rest[outKey] = value;
949
+ return rest;
950
+ }
951
+ // ---------------------------------------------------------------------------------------------
952
+ // The adapter
953
+ // ---------------------------------------------------------------------------------------------
954
+ /**
955
+ * Stage markers refining `initializing-engine` (spec "Этапы и таймаут загрузки": "уточняется по
956
+ * маркерам логов адаптера, если они есть"). With no markers the lifecycle would move straight from
957
+ * `starting-container` to `initializing-engine` the instant the container starts; these keep a load
958
+ * in `starting-container` — Python/CUDA-context bring-up, not yet touching the checkpoint — until
959
+ * one of them shows the engine is actually reading weights or building itself. All three are read
960
+ * directly from the pinned tag's pytorch-backend source (file header: `weight_loader.py`,
961
+ * `model_engine.py`), not search results. Live test 2.19 is expected to add to or replace this set
962
+ * from a real container.
963
+ */
964
+ const STAGE_MARKERS = [
965
+ { stage: 'initializing-engine', pattern: /Loading (?:safetensors|bin) weights in parallel/ },
966
+ { stage: 'initializing-engine', pattern: /Prefetching [\d.]+GB checkpoint files/ },
967
+ { stage: 'initializing-engine', pattern: /Creating CUDA graph instances/ },
968
+ // 1.3.0rc29 (`model_engine.py:2709`) logs the capture as "Running CUDA graph capture|warmup for N batch sizes."
969
+ {
970
+ stage: 'initializing-engine',
971
+ pattern: /Running CUDA graph (?:capture|warmup) for \d+ batch sizes/,
972
+ },
973
+ ];
974
+ /** The `tensorrt-llm` engine's `ManagedTextAdapter` (task 2.13). Registered against the pinned
975
+ * descriptor's `adapter_id`/`adapter_contract_version` by whatever wires the registry up (task 2.14). */
976
+ export const tensorrtLlmAdapter = {
977
+ id: 'tensorrt-llm',
978
+ contractVersion: MANAGED_TEXT_ADAPTER_CONTRACT_VERSION,
979
+ readiness: { path: '/health', expectedStatus: 200 },
980
+ routes: TENSORRT_LLM_ROUTES,
981
+ rewritableRoutes: TENSORRT_LLM_REWRITABLE_ROUTES,
982
+ stageMarkers: STAGE_MARKERS,
983
+ validateSettings: validateTensorrtLlmSettings,
984
+ buildLaunch: buildTensorrtLlmLaunch,
985
+ readinessTimeoutMs: tensorrtLlmReadinessTimeoutMs,
986
+ classifyExit: classifyTensorrtLlmExit,
987
+ classifyReady: classifyTensorrtLlmReady,
988
+ describeStreamFailure: describeTensorrtLlmStreamFailure,
989
+ capabilities: tensorrtLlmCapabilities,
990
+ rewriteRequestBody: tensorrtLlmRewriteRequestBody,
991
+ rewriteResponseFor: tensorrtLlmRewriteResponseFor,
992
+ // The session port answers `trtllm-serve`'s context overflow the way `:1337` does
993
+ // (findings-2.14-r1.md item 1): OpenAI's `context_length_exceeded`, with both numbers.
994
+ mapErrorResponse: (_route, status, body) => mapTensorrtLlmContextLengthError(status, body),
995
+ // Only these are `trtllm-serve` flags; the output cap is the gateway's and the load timeout only a
996
+ // load's, so changing either never restarts a container (findings-2.14-r1.md item 3). The card is
997
+ // part of the lifecycle's own key already, as the one the load actually picked.
998
+ restartKey: (settings) => [
999
+ settings.context_length,
1000
+ settings.kv_cache_free_gpu_memory_fraction,
1001
+ settings.max_batch_size,
1002
+ settings.kv_cache_max_tokens,
1003
+ settings.cuda_graphs,
1004
+ settings.kv_cache_dtype,
1005
+ settings.enable_prefix_caching,
1006
+ settings.overlap_scheduler,
1007
+ settings.capacity_scheduler_policy,
1008
+ settings.dtype,
1009
+ ],
1010
+ };
1011
+ //# sourceMappingURL=adapter.js.map