@atomic-chat/core 0.5.1 → 0.13.6

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