@ggml-org/llama-chat 0.0.1-stage → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (298) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +210 -0
  3. package/bin/cli.js +5 -0
  4. package/cli/server.js +443 -0
  5. package/dist/_app/immutable/assets/0.B8jAyHFu.css +2 -0
  6. package/dist/_app/immutable/assets/LlamaMono.7z2dnkpH.woff2 +0 -0
  7. package/dist/_app/immutable/assets/LlamaSans.C2rXtH67.woff2 +0 -0
  8. package/dist/_app/immutable/assets/app.BU-NzFXm.css +1 -0
  9. package/dist/_app/immutable/assets/nerdamer.Cl-GVG6T.js +24 -0
  10. package/dist/_app/immutable/assets/pdf.worker.min.DbR_HJhJ.mjs +29 -0
  11. package/dist/_app/immutable/chunks/1CIrbR2Q.js +1 -0
  12. package/dist/_app/immutable/chunks/1l-8ymtB.js +1 -0
  13. package/dist/_app/immutable/chunks/26Y1-4rB.js +1 -0
  14. package/dist/_app/immutable/chunks/3SQ5KT5a.js +2 -0
  15. package/dist/_app/immutable/chunks/3ymKbqSp.js +1 -0
  16. package/dist/_app/immutable/chunks/531-IPPG.js +1 -0
  17. package/dist/_app/immutable/chunks/5I1j5qRd.js +1 -0
  18. package/dist/_app/immutable/chunks/5k5YNuRS.js +2 -0
  19. package/dist/_app/immutable/chunks/73P-F8U9.js +1 -0
  20. package/dist/_app/immutable/chunks/73lFXAp6.js +1 -0
  21. package/dist/_app/immutable/chunks/8u8Pml-P.js +1 -0
  22. package/dist/_app/immutable/chunks/B-P1Uyq8.js +1 -0
  23. package/dist/_app/immutable/chunks/B-PCS5zA.js +1 -0
  24. package/dist/_app/immutable/chunks/B1CroMsf.js +1 -0
  25. package/dist/_app/immutable/chunks/B1F_0bnw.js +1 -0
  26. package/dist/_app/immutable/chunks/B1pH5dXO.js +1 -0
  27. package/dist/_app/immutable/chunks/B2IDuH-V.js +1 -0
  28. package/dist/_app/immutable/chunks/B3koHNzP.js +1 -0
  29. package/dist/_app/immutable/chunks/B4bepPhE.js +1 -0
  30. package/dist/_app/immutable/chunks/BCEr2jAI.js +1 -0
  31. package/dist/_app/immutable/chunks/BCRbq8jp.js +1 -0
  32. package/dist/_app/immutable/chunks/BD9AMQkN.js +1 -0
  33. package/dist/_app/immutable/chunks/BECLvyNb.js +1 -0
  34. package/dist/_app/immutable/chunks/BGBfXPIx.js +1 -0
  35. package/dist/_app/immutable/chunks/BGRQnnF2.js +1 -0
  36. package/dist/_app/immutable/chunks/BGfA2oQG.js +1 -0
  37. package/dist/_app/immutable/chunks/BHHhacaR.js +1 -0
  38. package/dist/_app/immutable/chunks/BI2r-hyN.js +1 -0
  39. package/dist/_app/immutable/chunks/BJ2OcN8V.js +1 -0
  40. package/dist/_app/immutable/chunks/BLbzjUaV.js +1 -0
  41. package/dist/_app/immutable/chunks/BMhS-uq9.js +1 -0
  42. package/dist/_app/immutable/chunks/BNjRHcgO.js +1 -0
  43. package/dist/_app/immutable/chunks/BOkolQqs.js +1 -0
  44. package/dist/_app/immutable/chunks/BQvSqJrQ.js +1 -0
  45. package/dist/_app/immutable/chunks/BSf_7YOu.js +1 -0
  46. package/dist/_app/immutable/chunks/BUe16zE4.js +1 -0
  47. package/dist/_app/immutable/chunks/BW462adD.js +1 -0
  48. package/dist/_app/immutable/chunks/BWVYCPTK.js +1 -0
  49. package/dist/_app/immutable/chunks/BWaJ3C7D.js +1 -0
  50. package/dist/_app/immutable/chunks/BX-o3EIz.js +1 -0
  51. package/dist/_app/immutable/chunks/BXgVOBG5.js +1 -0
  52. package/dist/_app/immutable/chunks/BaXwJpWq.js +1 -0
  53. package/dist/_app/immutable/chunks/BahAjTwm.js +1 -0
  54. package/dist/_app/immutable/chunks/BakFZ2ml.js +3 -0
  55. package/dist/_app/immutable/chunks/BcBB30ub.js +1 -0
  56. package/dist/_app/immutable/chunks/BiMsFFN_.js +1 -0
  57. package/dist/_app/immutable/chunks/BjYI8dhz.js +1 -0
  58. package/dist/_app/immutable/chunks/Bjg1FiVd.js +1 -0
  59. package/dist/_app/immutable/chunks/Bjy-W4x2.js +81 -0
  60. package/dist/_app/immutable/chunks/BkW-mzl-.js +1 -0
  61. package/dist/_app/immutable/chunks/BmerogBf.js +1 -0
  62. package/dist/_app/immutable/chunks/Boj4HSji.js +1 -0
  63. package/dist/_app/immutable/chunks/BpsPHbGc.js +1 -0
  64. package/dist/_app/immutable/chunks/Bqj0DVIt.js +1 -0
  65. package/dist/_app/immutable/chunks/BqpFWvKu.js +1 -0
  66. package/dist/_app/immutable/chunks/BsbfJrTt.js +1 -0
  67. package/dist/_app/immutable/chunks/BzWcX1gm.js +1 -0
  68. package/dist/_app/immutable/chunks/C0zufGsU.js +1 -0
  69. package/dist/_app/immutable/chunks/C3EegiWg.js +1 -0
  70. package/dist/_app/immutable/chunks/C5TQXDMb.js +1 -0
  71. package/dist/_app/immutable/chunks/C8bVcNXx.js +1 -0
  72. package/dist/_app/immutable/chunks/C9Z__FYS.js +1 -0
  73. package/dist/_app/immutable/chunks/C9lP4FWY.js +1 -0
  74. package/dist/_app/immutable/chunks/CA93Z2eM.js +1 -0
  75. package/dist/_app/immutable/chunks/CBFuTPWj.js +1 -0
  76. package/dist/_app/immutable/chunks/CDc1Vb3D.js +1 -0
  77. package/dist/_app/immutable/chunks/CEFdYGQ4.js +1 -0
  78. package/dist/_app/immutable/chunks/CElFSg8P.js +1 -0
  79. package/dist/_app/immutable/chunks/CHTJ6C4a.js +1 -0
  80. package/dist/_app/immutable/chunks/CJ1TLoQF.js +1 -0
  81. package/dist/_app/immutable/chunks/CJH3ep_3.js +1 -0
  82. package/dist/_app/immutable/chunks/CJb8JxGC.js +1 -0
  83. package/dist/_app/immutable/chunks/CP1rWjpH.js +1 -0
  84. package/dist/_app/immutable/chunks/CPLFVNxS.js +1 -0
  85. package/dist/_app/immutable/chunks/CR1Ogma7.js +1 -0
  86. package/dist/_app/immutable/chunks/CR3yefiA.js +1 -0
  87. package/dist/_app/immutable/chunks/CR7dvLJ4.js +1 -0
  88. package/dist/_app/immutable/chunks/CR9tZ93c.js +1 -0
  89. package/dist/_app/immutable/chunks/CRcZGluc.js +1 -0
  90. package/dist/_app/immutable/chunks/CSRnPoYO.js +1 -0
  91. package/dist/_app/immutable/chunks/CSrFSEx0.js +1 -0
  92. package/dist/_app/immutable/chunks/CVYb4e6m.js +1 -0
  93. package/dist/_app/immutable/chunks/CWGByNpv.js +1 -0
  94. package/dist/_app/immutable/chunks/CXP1cmYR.js +11 -0
  95. package/dist/_app/immutable/chunks/CXnZM-Nf.js +1 -0
  96. package/dist/_app/immutable/chunks/C_5_0OWv.js +1 -0
  97. package/dist/_app/immutable/chunks/C_EjVcnO.js +1 -0
  98. package/dist/_app/immutable/chunks/C_UcIgej.js +1 -0
  99. package/dist/_app/immutable/chunks/C_mGJ3Jy.js +1 -0
  100. package/dist/_app/immutable/chunks/CaM3tfvi.js +1 -0
  101. package/dist/_app/immutable/chunks/CaU6e6N4.js +1 -0
  102. package/dist/_app/immutable/chunks/Cb2OgvrR.js +1 -0
  103. package/dist/_app/immutable/chunks/CcGrHbps.js +3 -0
  104. package/dist/_app/immutable/chunks/Cgnqi5KA.js +1 -0
  105. package/dist/_app/immutable/chunks/CiO3JXx7.js +1 -0
  106. package/dist/_app/immutable/chunks/CjhsRFLe.js +1 -0
  107. package/dist/_app/immutable/chunks/CkSV9Luo.js +1 -0
  108. package/dist/_app/immutable/chunks/ClNaFHRt.js +1 -0
  109. package/dist/_app/immutable/chunks/CpIe18ku.js +1 -0
  110. package/dist/_app/immutable/chunks/CpMp0mBm.js +1 -0
  111. package/dist/_app/immutable/chunks/CpiLaDrO.js +1 -0
  112. package/dist/_app/immutable/chunks/CsXD8KHm.js +411 -0
  113. package/dist/_app/immutable/chunks/Cu9sx8W2.js +1 -0
  114. package/dist/_app/immutable/chunks/CvqMZYuf.js +1 -0
  115. package/dist/_app/immutable/chunks/CxTKDHeA.js +1 -0
  116. package/dist/_app/immutable/chunks/D-4KA1m9.js +1 -0
  117. package/dist/_app/immutable/chunks/D3oKByup.js +1 -0
  118. package/dist/_app/immutable/chunks/D463B8d-.js +1 -0
  119. package/dist/_app/immutable/chunks/D5D75dXm.js +1 -0
  120. package/dist/_app/immutable/chunks/D5l_8KUR.js +1 -0
  121. package/dist/_app/immutable/chunks/D5uGO-jm.js +1 -0
  122. package/dist/_app/immutable/chunks/D6zc0cUO.js +1 -0
  123. package/dist/_app/immutable/chunks/D8SR3GGH.js +1 -0
  124. package/dist/_app/immutable/chunks/DC-R59BF.js +1 -0
  125. package/dist/_app/immutable/chunks/DEWZKVv3.js +1 -0
  126. package/dist/_app/immutable/chunks/DEdPwm2c.js +1 -0
  127. package/dist/_app/immutable/chunks/DGOW1qT8.js +1 -0
  128. package/dist/_app/immutable/chunks/DGokiC3s.js +1 -0
  129. package/dist/_app/immutable/chunks/DGs-X5Vp.js +1 -0
  130. package/dist/_app/immutable/chunks/DJFrA4nv.js +1 -0
  131. package/dist/_app/immutable/chunks/DJqXWVRL.js +1 -0
  132. package/dist/_app/immutable/chunks/DLXDdhyK.js +1 -0
  133. package/dist/_app/immutable/chunks/DMzbk8qN.js +1 -0
  134. package/dist/_app/immutable/chunks/DNWPCnjT.js +1 -0
  135. package/dist/_app/immutable/chunks/DO8eeo3I.js +1 -0
  136. package/dist/_app/immutable/chunks/DOTrSD3H.js +1 -0
  137. package/dist/_app/immutable/chunks/DQKGwi3G.js +1 -0
  138. package/dist/_app/immutable/chunks/DRbqW1u4.js +1 -0
  139. package/dist/_app/immutable/chunks/DS4EA3dC.js +1 -0
  140. package/dist/_app/immutable/chunks/DSQwiuj1.js +1 -0
  141. package/dist/_app/immutable/chunks/DTzUSEH8.js +1 -0
  142. package/dist/_app/immutable/chunks/DV7smCjo.js +3 -0
  143. package/dist/_app/immutable/chunks/DVi5cKOT.js +1 -0
  144. package/dist/_app/immutable/chunks/DWRKyvJ-.js +1 -0
  145. package/dist/_app/immutable/chunks/DZJEcL8n.js +1 -0
  146. package/dist/_app/immutable/chunks/D_ESCULk.js +2 -0
  147. package/dist/_app/immutable/chunks/Da8STgqx.js +1 -0
  148. package/dist/_app/immutable/chunks/DasnpDVC.js +1 -0
  149. package/dist/_app/immutable/chunks/DclECHGd.js +1 -0
  150. package/dist/_app/immutable/chunks/DdjbPXam.js +1 -0
  151. package/dist/_app/immutable/chunks/DeCngaqu.js +1 -0
  152. package/dist/_app/immutable/chunks/Dfm-WMeA.js +1 -0
  153. package/dist/_app/immutable/chunks/Dg6dmf5K.js +1 -0
  154. package/dist/_app/immutable/chunks/Dh71fdD_.js +1 -0
  155. package/dist/_app/immutable/chunks/Dh9PJFmJ.js +1 -0
  156. package/dist/_app/immutable/chunks/DhWmV0s1.js +1 -0
  157. package/dist/_app/immutable/chunks/Dhhcn_CA.js +1 -0
  158. package/dist/_app/immutable/chunks/DjOhhVLG.js +1 -0
  159. package/dist/_app/immutable/chunks/DkTKhn5C.js +1 -0
  160. package/dist/_app/immutable/chunks/DoVWcw3Q.js +1 -0
  161. package/dist/_app/immutable/chunks/DptdJbGO.js +1 -0
  162. package/dist/_app/immutable/chunks/DqHi-6vF.js +1 -0
  163. package/dist/_app/immutable/chunks/Dr9rmg8t.js +1 -0
  164. package/dist/_app/immutable/chunks/Dv0yWYFF.js +1 -0
  165. package/dist/_app/immutable/chunks/DvbP7u24.js +1 -0
  166. package/dist/_app/immutable/chunks/DwUuKi_Q.js +1 -0
  167. package/dist/_app/immutable/chunks/DwhXSSGr.js +1 -0
  168. package/dist/_app/immutable/chunks/Dxj7e8BX.js +1 -0
  169. package/dist/_app/immutable/chunks/Eeu3jWSz.js +4 -0
  170. package/dist/_app/immutable/chunks/F90s6HK_.js +1 -0
  171. package/dist/_app/immutable/chunks/FGVCSpsQ.js +1 -0
  172. package/dist/_app/immutable/chunks/GZmu99Fo.js +1 -0
  173. package/dist/_app/immutable/chunks/Hak9sRVf.js +1 -0
  174. package/dist/_app/immutable/chunks/Hj_vmM07.js +1 -0
  175. package/dist/_app/immutable/chunks/JVA7wRWo.js +1 -0
  176. package/dist/_app/immutable/chunks/KNgW1fZo.js +1 -0
  177. package/dist/_app/immutable/chunks/Ke-GOEW9.js +1 -0
  178. package/dist/_app/immutable/chunks/LZCIum1w.js +1 -0
  179. package/dist/_app/immutable/chunks/NqH9ctA4.js +1 -0
  180. package/dist/_app/immutable/chunks/PZYq2RVY.js +259 -0
  181. package/dist/_app/immutable/chunks/PigSugnL.js +1 -0
  182. package/dist/_app/immutable/chunks/Qa3iLJWP.js +1 -0
  183. package/dist/_app/immutable/chunks/V0F2hNk9.js +1 -0
  184. package/dist/_app/immutable/chunks/Vgr6fxPS.js +1 -0
  185. package/dist/_app/immutable/chunks/Wu2ux-Fn.js +1 -0
  186. package/dist/_app/immutable/chunks/YB8mb-y7.js +1 -0
  187. package/dist/_app/immutable/chunks/YlWmQdSJ.js +1 -0
  188. package/dist/_app/immutable/chunks/YlzcZYWN.js +1 -0
  189. package/dist/_app/immutable/chunks/ZpNubZZ_.js +1 -0
  190. package/dist/_app/immutable/chunks/aGu1RaYf.js +1 -0
  191. package/dist/_app/immutable/chunks/aHBM9jLK.js +1 -0
  192. package/dist/_app/immutable/chunks/aZNm1DXx.js +1 -0
  193. package/dist/_app/immutable/chunks/bShcHfOZ.js +1 -0
  194. package/dist/_app/immutable/chunks/bYSlyn-W.js +1 -0
  195. package/dist/_app/immutable/chunks/cD8rF-Vw.js +1 -0
  196. package/dist/_app/immutable/chunks/dTiwAriW.js +1 -0
  197. package/dist/_app/immutable/chunks/hBR4I1od.js +1 -0
  198. package/dist/_app/immutable/chunks/hKzGh-52.js +1 -0
  199. package/dist/_app/immutable/chunks/iLCLl-5n.js +1 -0
  200. package/dist/_app/immutable/chunks/ifxXhTOO.js +1 -0
  201. package/dist/_app/immutable/chunks/jK6vAkqq.js +1 -0
  202. package/dist/_app/immutable/chunks/lM-YLvZH.js +1 -0
  203. package/dist/_app/immutable/chunks/nSe0mzJm.js +1 -0
  204. package/dist/_app/immutable/chunks/oUUdvLrs.js +1 -0
  205. package/dist/_app/immutable/chunks/p0dfWXuO.js +1 -0
  206. package/dist/_app/immutable/chunks/p0pDTEuW.js +1 -0
  207. package/dist/_app/immutable/chunks/p7Fa3A78.js +1 -0
  208. package/dist/_app/immutable/chunks/qGz9CBa_.js +1 -0
  209. package/dist/_app/immutable/chunks/rqf_V7Lc.js +1 -0
  210. package/dist/_app/immutable/chunks/tFw2_zZo.js +150 -0
  211. package/dist/_app/immutable/chunks/tYyfRjr6.js +1 -0
  212. package/dist/_app/immutable/chunks/tnVFwE0j.js +1 -0
  213. package/dist/_app/immutable/chunks/tuAJdZsI.js +1 -0
  214. package/dist/_app/immutable/chunks/upDuL0ca.js +1 -0
  215. package/dist/_app/immutable/chunks/wv2tBZQi.js +1 -0
  216. package/dist/_app/immutable/chunks/xylFSQAW.js +1 -0
  217. package/dist/_app/immutable/chunks/zdpkyKaR.js +1 -0
  218. package/dist/_app/immutable/entry/app.CJeUTekO.js +2 -0
  219. package/dist/_app/immutable/entry/payload.DSmR2FwN.js +1 -0
  220. package/dist/_app/immutable/entry/start.w7WNk0if.js +2 -0
  221. package/dist/_app/immutable/nodes/0.ByEG0zmr.js +1 -0
  222. package/dist/_app/immutable/nodes/1.BkvpGVa6.js +1 -0
  223. package/dist/_app/immutable/nodes/2.D57n0Bjk.js +1 -0
  224. package/dist/_app/immutable/nodes/3.CVWu7-If.js +1 -0
  225. package/dist/_app/immutable/nodes/4.CW-xYf3I.js +1 -0
  226. package/dist/_app/immutable/nodes/5.C1B-poWf.js +1 -0
  227. package/dist/_app/immutable/nodes/6.CXZYjXfl.js +1 -0
  228. package/dist/_app/immutable/nodes/7.1WeECGN4.js +1 -0
  229. package/dist/_app/version.json +1 -0
  230. package/dist/apple-splash-landscape-1136x640.png +0 -0
  231. package/dist/apple-splash-landscape-1334x750.png +0 -0
  232. package/dist/apple-splash-landscape-2266x1488.png +0 -0
  233. package/dist/apple-splash-landscape-2360x1640.png +0 -0
  234. package/dist/apple-splash-landscape-2388x1668.png +0 -0
  235. package/dist/apple-splash-landscape-2532x1170.png +0 -0
  236. package/dist/apple-splash-landscape-2556x1179.png +0 -0
  237. package/dist/apple-splash-landscape-2622x1206.png +0 -0
  238. package/dist/apple-splash-landscape-2732x2048.png +0 -0
  239. package/dist/apple-splash-landscape-2778x1284.png +0 -0
  240. package/dist/apple-splash-landscape-2796x1290.png +0 -0
  241. package/dist/apple-splash-landscape-2868x1320.png +0 -0
  242. package/dist/apple-splash-landscape-dark-1136x640.png +0 -0
  243. package/dist/apple-splash-landscape-dark-1334x750.png +0 -0
  244. package/dist/apple-splash-landscape-dark-2266x1488.png +0 -0
  245. package/dist/apple-splash-landscape-dark-2360x1640.png +0 -0
  246. package/dist/apple-splash-landscape-dark-2388x1668.png +0 -0
  247. package/dist/apple-splash-landscape-dark-2532x1170.png +0 -0
  248. package/dist/apple-splash-landscape-dark-2556x1179.png +0 -0
  249. package/dist/apple-splash-landscape-dark-2622x1206.png +0 -0
  250. package/dist/apple-splash-landscape-dark-2732x2048.png +0 -0
  251. package/dist/apple-splash-landscape-dark-2778x1284.png +0 -0
  252. package/dist/apple-splash-landscape-dark-2796x1290.png +0 -0
  253. package/dist/apple-splash-landscape-dark-2868x1320.png +0 -0
  254. package/dist/apple-splash-portrait-1170x2532.png +0 -0
  255. package/dist/apple-splash-portrait-1179x2556.png +0 -0
  256. package/dist/apple-splash-portrait-1206x2622.png +0 -0
  257. package/dist/apple-splash-portrait-1284x2778.png +0 -0
  258. package/dist/apple-splash-portrait-1290x2796.png +0 -0
  259. package/dist/apple-splash-portrait-1320x2868.png +0 -0
  260. package/dist/apple-splash-portrait-1488x2266.png +0 -0
  261. package/dist/apple-splash-portrait-1640x2360.png +0 -0
  262. package/dist/apple-splash-portrait-1668x2388.png +0 -0
  263. package/dist/apple-splash-portrait-2048x2732.png +0 -0
  264. package/dist/apple-splash-portrait-640x1136.png +0 -0
  265. package/dist/apple-splash-portrait-750x1334.png +0 -0
  266. package/dist/apple-splash-portrait-dark-1170x2532.png +0 -0
  267. package/dist/apple-splash-portrait-dark-1179x2556.png +0 -0
  268. package/dist/apple-splash-portrait-dark-1206x2622.png +0 -0
  269. package/dist/apple-splash-portrait-dark-1284x2778.png +0 -0
  270. package/dist/apple-splash-portrait-dark-1290x2796.png +0 -0
  271. package/dist/apple-splash-portrait-dark-1320x2868.png +0 -0
  272. package/dist/apple-splash-portrait-dark-1488x2266.png +0 -0
  273. package/dist/apple-splash-portrait-dark-1640x2360.png +0 -0
  274. package/dist/apple-splash-portrait-dark-1668x2388.png +0 -0
  275. package/dist/apple-splash-portrait-dark-2048x2732.png +0 -0
  276. package/dist/apple-splash-portrait-dark-640x1136.png +0 -0
  277. package/dist/apple-splash-portrait-dark-750x1334.png +0 -0
  278. package/dist/apple-touch-icon-180x180.png +0 -0
  279. package/dist/build.json +1 -0
  280. package/dist/config.json +1 -0
  281. package/dist/favicon-dark.ico +0 -0
  282. package/dist/favicon-dark.svg +3 -0
  283. package/dist/favicon.ico +0 -0
  284. package/dist/favicon.svg +3 -0
  285. package/dist/index.html +108 -0
  286. package/dist/manifest.webmanifest +1 -0
  287. package/dist/maskable-icon-512x512.png +0 -0
  288. package/dist/pwa-192x192.png +0 -0
  289. package/dist/pwa-512x512.png +0 -0
  290. package/dist/pwa-64x64.png +0 -0
  291. package/dist/recommended-mcp/context7.png +0 -0
  292. package/dist/recommended-mcp/exa.ico +0 -0
  293. package/dist/recommended-mcp/github-dark.png +0 -0
  294. package/dist/recommended-mcp/github-light.png +0 -0
  295. package/dist/recommended-mcp/huggingface.ico +0 -0
  296. package/dist/service-worker.js +1 -0
  297. package/dist/sw.js +12 -0
  298. package/package.json +166 -2
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) ggml
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,210 @@
1
+ # Llama Chat
2
+
3
+ Llama Chat is the chat app for llama.cpp: a web interface for llama-server, built with SvelteKit on [Llama UI](../../lib/ui/README.md) (`@ggml-org/llama-ui`), the design system in `ui/lib/ui`. llama-server embeds it, and `npx llama-chat` runs it anywhere.
4
+
5
+ It works with a llama-server in either mode: **MODEL** (one model) or **ROUTER** (many models, loaded and unloaded on demand).
6
+
7
+ ## Contents
8
+
9
+ - [Run it with npx](#run-it-with-npx)
10
+ - [Self-hosting](#self-hosting)
11
+ - [Features](#features)
12
+ - [Development](#development)
13
+ - [Architecture](#architecture)
14
+ - [Build and embedding](#build-and-embedding)
15
+ - [Publishing to npm](#publishing-to-npm)
16
+
17
+ ## Run it with npx
18
+
19
+ Llama Chat is published to npm as [`@ggml-org/llama-chat`](https://www.npmjs.com/package/@ggml-org/llama-chat), with [`llama-chat`](https://www.npmjs.com/package/llama-chat) as its short name. It serves the prebuilt app as static files on localhost, or writes them to a folder for any static file server (see [Self-hosting](#self-hosting)); it brings no server and no models of its own. It needs Node.js 20 or later.
20
+
21
+ ```bash
22
+ npx @ggml-org/llama-chat --server http://localhost:8080 # serve it on http://127.0.0.1:3000 for that llama-server
23
+ npx llama-chat --host 0.0.0.0 --no-open # by its short name, reachable from other devices
24
+ npx llama-chat build # write the static app to ./llama-chat instead
25
+ ```
26
+
27
+ | Flag | Default | What it does |
28
+ | --------------------------------- | ----------- | ------------------------------------------------------------------------------------------- |
29
+ | `--server <url>` | | The llama-server the app talks to, e.g. `http://localhost:8080`; also for `build` |
30
+ | `--port <n>` | `3000` | Fixed, so the origin, and the chats the browser stores under it, stay the same between runs |
31
+ | `--host <addr>` | `127.0.0.1` | `0.0.0.0` to open it to the LAN |
32
+ | `--open` / `--no-open` | open | Opens the default browser once it listens |
33
+ | `-v`, `--version`, `-h`, `--help` | | As usual |
34
+
35
+ The bare command is the documented form; `start` is accepted as an alias for it. `build` takes `--out <dir>` (default `./llama-chat`) and `--force`, which lets it write into a folder that is not empty.
36
+
37
+ How it works: the CLI only serves the files of `dist`, with llama-server's headers for the UI (`index.html` cross-origin isolated, the PWA files revalidated, hashed assets cached for good), and forwards nothing. The browser talks to the llama-server named with `--server` directly, so llama-server's own rules apply: start it with `--cors-origins http://127.0.0.1:3000` (the address you open) when it restricts origins, as it does with tools or MCP enabled, and with `--api-key` when it is reachable from the LAN. An `http://` page like this one can reach a plain `http://` llama-server on the LAN, which an `https://` page cannot.
38
+
39
+ ## Self-hosting
40
+
41
+ The app is static and uses relative paths and a hash router, so any static host can serve it at any path. `npx @ggml-org/llama-chat build --out <dir>` writes the files (as does `npm run build` here, to `dist`); serve them with any static file server, for example `npx http-server llama-chat -p 3000`. Send the headers listed above with `index.html` and the PWA files, so the app behaves as it does under llama-server (see [Cross-origin isolation](#cross-origin-isolation)).
42
+
43
+ The app reaches the llama-server on its own origin by default (llama-server serves it with `--path`, or your reverse proxy puts the API next to the files). To host it apart from llama-server, name the server in `config.json`, the file next to `index.html`:
44
+
45
+ ```json
46
+ { "server": "http://localhost:8080" }
47
+ ```
48
+
49
+ `npx llama-chat build --server <url>` writes that file, and `npx llama-chat --server <url>` answers it without one. The app reads it on every start, past its caches, so a host can change it without a new build. That llama-server needs `--cors-origins` for the app's address when it restricts origins.
50
+
51
+ ## Features
52
+
53
+ - **Chat** - streaming replies, reasoning blocks, branching by edit or regenerate, tabs, search, import and export
54
+ - **Attachments** - images, PDFs (as text or as pages for vision models), audio and text files, by drag and drop or paste
55
+ - **Rendering** - Markdown (GFM), code highlighting, KaTeX math and Mermaid diagrams
56
+ - **Models** - in ROUTER mode, a selector and a models manager: load and unload, downloads, Discover from the Hugging Face Hub, favorites and hidden models
57
+ - **Tools** - built-in browser tools, llama-server's tools and MCP servers, each behind a permission prompt
58
+ - **Everywhere** - light and dark themes, phone layouts, installable as a PWA, keyboard shortcuts (`Ctrl/Cmd+K` search, `Shift+Ctrl/Cmd+O` new chat, `Ctrl/Cmd+B` sidebar, `Esc` stop the reply)
59
+
60
+ ## Development
61
+
62
+ You need Node.js 20 or later and a llama-server to talk to.
63
+
64
+ ```bash
65
+ cd ui/apps/chat
66
+ npm ci
67
+ npm run dev # the app on http://localhost:5173, Storybook on http://localhost:6006
68
+ ```
69
+
70
+ The dev server forwards the API (`/v1`, `/props`, `/models`, `/tools`, `/slots`, `/cors-proxy`) to llama-server on `http://localhost:9931`, or to `VITE_PUBLIC_SERVER_ORIGIN` when it is set.
71
+
72
+ | Command | What it does |
73
+ | --------------------- | --------------------------------------------------------------- |
74
+ | `npm run build` | The production build, in `dist/` |
75
+ | `npm run check` | Type checking with svelte-check |
76
+ | `npm run lint` | Prettier and ESLint; `npm run format` fixes what they can |
77
+ | `npm run test:unit` | Unit tests (Vitest, `tests/unit`) |
78
+ | `npm run test:client` | Component tests in the browser (Vitest, `tests/client`) |
79
+ | `npm run test:ui` | Storybook stories run as tests (`tests/stories`) |
80
+ | `npm run test:e2e` | End-to-end tests (Playwright, `tests/e2e`), with a llama-server |
81
+ | `npm run storybook` | Storybook on its own |
82
+
83
+ Locally the browser tests run in your installed Google Chrome; CI uses Playwright's bundled Chromium.
84
+
85
+ ## Architecture
86
+
87
+ Llama Chat is the first app on Llama UI, and the reference for the line between library and app: **Llama UI draws and handles interaction, the app decides what happens.**
88
+
89
+ - **In Llama UI:** components, design tokens, fonts and surfaces, and the logic inside them (keyboard navigation, validation as you type, formatting a file size). Components take data in and report what the user did out.
90
+ - **In Llama Chat:** talking to llama-server, storing conversations, the agentic loop and its tool permissions, MCP servers, managing models, settings.
91
+
92
+ The app imports the library as `@ggml-org/llama-ui/ui/<name>` and compiles its sources in its own build, with no install of the library (see `scripts/vite-plugin-llama-ui.ts`). Data flows one way, through these layers:
93
+
94
+ | Layer | Lives in | What it holds |
95
+ | -------------- | ------------------------- | ---------------------------------------------------------------------------------------------------- |
96
+ | Routes | `src/routes` | `/`, `/chat/[id]`, `/models`, `/mcp-servers`, `/settings`, `/search` |
97
+ | App components | `src/lib/components/app` | Chat, navigation, models, MCP, settings and dialogs, grouped by area |
98
+ | UI components | `ui/lib/ui` | shadcn-svelte on bits-ui, from Llama UI |
99
+ | Voice | `ui/lib/voice` | Microphone capture, transcription and dictation, from Llama Voice (`@ggml-org/llama-voice`) |
100
+ | Hooks | `src/lib/hooks` | View logic between components and stores: scroll, drag and drop, pickers, keyboard |
101
+ | Stores | `src/lib/stores` | Application state as Svelte 5 runes: chat, conversations, the agentic loop, tools, models, settings |
102
+ | Agentic loop | `ui/lib/harness` | Llama Harness: streams a turn, runs the tools the model called, repeats until it answers without one |
103
+ | Services | `src/lib/services` | Stateless I/O: the llama-server API, IndexedDB, MCP, the Hugging Face Hub, the tool sandbox |
104
+ | Storage + API | the browser, llama-server | IndexedDB and localStorage; llama-server's `/v1`, `/props`, `/models`, `/tools`, `/slots` |
105
+
106
+ ```mermaid
107
+ flowchart LR
108
+ Routes --> Components["App components"]
109
+ Components --> Hooks
110
+ Components --> Stores
111
+ Hooks --> Stores
112
+ Stores --> Services
113
+ Services --> DB[("IndexedDB, localStorage")]
114
+ Services --> API["llama-server"]
115
+ Components -. "imports" .-> UI["Llama UI"]
116
+ Stores -. "reactive state" .-> Components
117
+ ```
118
+
119
+ ### Sending a message
120
+
121
+ ```mermaid
122
+ sequenceDiagram
123
+ participant User
124
+ participant Stores
125
+ participant DB as IndexedDB
126
+ participant API as llama-server
127
+
128
+ Note over Stores,API: on start
129
+ Stores->>API: GET /props, then the model list
130
+ User->>Stores: send a message
131
+ opt ROUTER mode, model not loaded
132
+ Stores->>API: POST /models/load, then poll GET /models
133
+ end
134
+ Stores->>DB: save the user message
135
+ Stores->>API: POST /v1/chat/completions (stream)
136
+ loop streaming
137
+ API-->>Stores: SSE chunks, shown as they arrive
138
+ end
139
+ opt the model called tools
140
+ Stores->>Stores: run them (after permission), send the results, stream again
141
+ end
142
+ Stores->>DB: save the assistant message
143
+ ```
144
+
145
+ ### Patterns worth knowing
146
+
147
+ - **Stores** hold state as Svelte 5 runes (`$state`, `$derived`); larger ones live in folders and compose focused sub-stores. **Services** are stateless and do all I/O.
148
+ - **Per-conversation state**: streaming, loading and abort controllers are kept per conversation, so several chats can stream at once.
149
+ - **Messages form a tree**: each message knows its parent and children, and a conversation points at the branch tip it shows, so editing or regenerating branches without losing history.
150
+ - **Server role**: one codebase serves MODEL and ROUTER mode; `serverStore` reads the role from `/props`, and ROUTER-only UI shows only there.
151
+ - **Modalities**: attachments a model cannot read (images for a text-only model, say) are refused before sending, from the model's `/props`.
152
+ - **Storage**: conversations and messages in IndexedDB (Dexie), settings and model preferences in localStorage, server state and Hub details in memory only.
153
+
154
+ ### Cross-origin isolation
155
+
156
+ llama-server serves the UI with `Cross-Origin-Embedder-Policy: require-corp` and `Cross-Origin-Opener-Policy: same-origin`, so every cross-origin asset needs the other origin's consent. Hugging Face Hub avatars and metadata are requested in CORS mode, which the Hub allows. MCP server icons and search-result favicons go through llama-server's `/cors-proxy` when it runs with `--ui-mcp-proxy`, and fall back to a bundled icon otherwise.
157
+
158
+ ## Build and embedding
159
+
160
+ `npm run build` generates the PWA icons, bundles the app with Vite and writes it to `dist/` (or to `LLAMA_UI_OUT_DIR`) as static files: `index.html`, one JS and one CSS bundle under `_app/`, the service worker, the web manifest and `build.json` with the version (`LLAMA_BUILD_NUMBER`, `b0000` locally). Paths are relative and routing uses the URL hash, so `dist` works from any path.
161
+
162
+ llama-server embeds it: when llama-server is built, `scripts/ui-assets.cmake` takes `ui/apps/chat/dist` if it exists, runs `npm run build` if `LLAMA_BUILD_UI` is on, or downloads the release's prebuilt `dist.tar.gz` from Hugging Face, and compiles every file into the binary. The same `dist` is what `npx @ggml-org/llama-chat` serves.
163
+
164
+ **Plain chat and agent mode.** Llama Chat is a plain chat, a message and its reply with reasoning when the model gives it, unless llama-server offers the agentic features: its built-in tools or its proxy, which `llama-server --agent` turns on together. `llama-server --ui-agent` turns agent mode on with neither: the model gets only the tools that run in the browser, and MCP servers the browser reaches itself. The app reads this from `/props` and `/tools`. With them it shows the tools menu, the working folder, MCP and the Tools and Agentic settings, and runs the agentic loop; without them it shows none of these and sends the classic request. Tool calls in earlier conversations still display.
165
+
166
+ **Chat-only build.** `VITE_PUBLIC_AGENTIC=false npm run build` builds an app that is a plain chat for every server, and `npm run dev:chat-only` runs the dev server the same way. Llama Harness's loop is left out of its bundle.
167
+
168
+ ```text
169
+ ui/apps/chat/
170
+ ├── src/
171
+ │ ├── lib/ # components, hooks, stores, services, types, utils, constants, enums
172
+ │ ├── routes/ # SvelteKit routes
173
+ │ └── service-worker/ # the PWA's service worker
174
+ ├── bin/, cli/ # the npx llama-chat command and its server
175
+ ├── alias/ # the llama-chat npm package, the short name
176
+ ├── scripts/ # Vite plugins and build scripts
177
+ ├── static/ # static assets
178
+ └── tests/ # unit, client and end-to-end tests, and the Storybook stories
179
+ ```
180
+
181
+ ## Publishing to npm
182
+
183
+ Two packages go out with the same version: `@ggml-org/llama-chat`, which carries the app and the CLI, and `llama-chat` (in `alias/`), which depends on it and only forwards to its CLI so that `npx llama-chat` works. A unit test (`tests/unit/cli.test.ts`) fails when their versions drift apart.
184
+
185
+ The version is set by hand and CI publishes it, as for `@ggml-org/llama-ui` (see [Releases](../../README.md#releases)). To release, bump the version in the PR that should ship it:
186
+
187
+ ```bash
188
+ cd ui/apps/chat
189
+ npm version <version> --no-git-tag-version
190
+ # then set the same version, and the same @ggml-org/llama-chat dependency, in alias/package.json
191
+ ```
192
+
193
+ Once that reaches `master`, [`ui-chat-publish.yml`](../../../.github/workflows/ui-chat-publish.yml) builds `dist`, checks that the package holds `dist/index.html` and no source maps, and publishes both packages with npm trusted publishing. A version npm already has publishes nothing, and a PR that changes the packages gets a dry run.
194
+
195
+ To try a package before it is published:
196
+
197
+ ```bash
198
+ npm run build
199
+ npm pack
200
+ npx ./ggml-org-llama-chat-<version>.tgz
201
+ ```
202
+
203
+ Build right before packing: the package carries whatever is in `dist`, and this folder's `.npmrc` sets `ignore-scripts`, so npm runs no lifecycle script such as `prepack` that could build it for you.
204
+
205
+ ## Related documentation
206
+
207
+ - [llama.cpp server](../../../tools/server/README.md)
208
+ - [Multimodal input](../../../docs/multimodal.md)
209
+ - [Function calling](../../../docs/function-calling.md)
210
+ - [`DESIGN.md`](DESIGN.md), the design rules, and [`AGENTS.md`](AGENTS.md), the conventions for agents
package/bin/cli.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ // `npx @ggml-org/llama-chat` and `llama-chat`, see cli/server.js
3
+ import { main } from '../cli/server.js';
4
+
5
+ await main(process.argv.slice(2));
package/cli/server.js ADDED
@@ -0,0 +1,443 @@
1
+ /**
2
+ * `npx @ggml-org/llama-chat`: serves the prebuilt Llama Chat (`dist`) as static files on
3
+ * localhost. `npx @ggml-org/llama-chat build` writes the same files to a folder instead, for any
4
+ * static file server. Node built-ins only, so the published package has no dependencies: no
5
+ * llama-server, no models, no Vite or SvelteKit.
6
+ *
7
+ * It only serves files and forwards nothing: the browser calls each llama-server the app is
8
+ * pointed at directly, so llama-server's own rules (--cors-origins, --api-key) apply as they do
9
+ * to any other page.
10
+ */
11
+
12
+ import { spawn } from 'node:child_process';
13
+ import { createReadStream, readFileSync } from 'node:fs';
14
+ import { cp, readdir, stat, writeFile } from 'node:fs/promises';
15
+ import http from 'node:http';
16
+ import { extname, isAbsolute, join, normalize, relative, resolve, sep } from 'node:path';
17
+ import { fileURLToPath } from 'node:url';
18
+ import { parseArgs } from 'node:util';
19
+
20
+ export const PACKAGE_ROOT = fileURLToPath(new URL('..', import.meta.url));
21
+ export const DIST_DIR = join(PACKAGE_ROOT, 'dist');
22
+
23
+ export const DEFAULTS = Object.freeze({
24
+ host: '127.0.0.1',
25
+ // the folder `build` writes to, in the current directory
26
+ out: 'llama-chat',
27
+ // fixed, so the origin, and the chats the browser stores under it, stay the same between runs
28
+ port: 3000
29
+ });
30
+
31
+ // The same caching llama-server applies to the UI it embeds (tools/server/server-http.cpp):
32
+ // index.html and the PWA's update checks are revalidated, hashed assets are cached for good.
33
+ const NO_CACHE = new Set([
34
+ '/index.html',
35
+ '/service-worker.js',
36
+ '/sw.js',
37
+ '/manifest.webmanifest',
38
+ '/_app/version.json',
39
+ '/build.json',
40
+ '/config.json'
41
+ ]);
42
+ // the file next to index.html that tells the app where llama-server is
43
+ const CONFIG_PATH = '/config.json';
44
+ const CACHE_IMMUTABLE = 'public, max-age=31536000, immutable';
45
+ const CACHE_REVALIDATE = 'no-cache';
46
+ /** @type {Record<string, string>} */
47
+ const MIME_TYPES = {
48
+ '.css': 'text/css; charset=utf-8',
49
+ '.gif': 'image/gif',
50
+ '.html': 'text/html; charset=utf-8',
51
+ '.ico': 'image/x-icon',
52
+ '.jpg': 'image/jpeg',
53
+ '.js': 'text/javascript; charset=utf-8',
54
+ '.json': 'application/json; charset=utf-8',
55
+ '.map': 'application/json; charset=utf-8',
56
+ '.mjs': 'text/javascript; charset=utf-8',
57
+ '.png': 'image/png',
58
+ '.svg': 'image/svg+xml',
59
+ '.ttf': 'font/ttf',
60
+ '.txt': 'text/plain; charset=utf-8',
61
+ '.wasm': 'application/wasm',
62
+ '.webmanifest': 'application/manifest+json; charset=utf-8',
63
+ '.webp': 'image/webp',
64
+ '.woff': 'font/woff',
65
+ '.woff2': 'font/woff2'
66
+ };
67
+ const SERVE_OPTIONS = ['host', 'open', 'port'];
68
+ const BUILD_OPTIONS = ['force', 'out'];
69
+
70
+ export const USAGE = `Usage: llama-chat [options]
71
+ llama-chat build [--out <dir>] [--force]
72
+
73
+ Serves Llama Chat on localhost as static files, or, with build, writes them to
74
+ a folder for any HTTP server. The browser talks to llama-server directly: name
75
+ it with --server, and start it with --cors-origins set to this page's address
76
+ when it restricts origins.
77
+
78
+ Options:
79
+ --server <url> the llama-server the app talks to, e.g. http://localhost:8080
80
+ (also for build; default: the address the app is served on)
81
+ --port <n> port to listen on (default: ${DEFAULTS.port})
82
+ --host <addr> address to listen on, 0.0.0.0 for the LAN (default: ${DEFAULTS.host})
83
+ --open open the browser once it listens (default)
84
+ --no-open do not open the browser
85
+ -v, --version print the version
86
+ -h, --help print this help
87
+
88
+ Build options:
89
+ --out <dir> folder to write to (default: ./${DEFAULTS.out})
90
+ --force write into a folder that is not empty
91
+
92
+ Examples:
93
+ npx @ggml-org/llama-chat --server http://localhost:8080
94
+ npx @ggml-org/llama-chat --host 0.0.0.0 --port 3000 --no-open
95
+ npx @ggml-org/llama-chat build --out ./public --server https://llm.example.com`;
96
+
97
+ /** The version in this package's package.json. */
98
+ export function packageVersion() {
99
+ return JSON.parse(readFileSync(join(PACKAGE_ROOT, 'package.json'), 'utf8')).version;
100
+ }
101
+
102
+ /**
103
+ * Reads the command line. No verb serves the app, `start` means the same, and `build` writes it
104
+ * to a folder.
105
+ * @param {string[]} argv the arguments after the command
106
+ * @returns {{ command: 'build' | 'serve', force: boolean, help: boolean, host: string, open: boolean, out: string, port: number, server: string, version: boolean }}
107
+ */
108
+ export function parseCliArgs(argv) {
109
+ const { positionals, values } = parseArgs({
110
+ allowNegative: true,
111
+ allowPositionals: true,
112
+ args: argv,
113
+ options: {
114
+ force: { type: 'boolean' },
115
+ help: { short: 'h', type: 'boolean' },
116
+ host: { type: 'string' },
117
+ open: { type: 'boolean' },
118
+ out: { type: 'string' },
119
+ port: { type: 'string' },
120
+ server: { type: 'string' },
121
+ version: { short: 'v', type: 'boolean' }
122
+ },
123
+ strict: true
124
+ });
125
+ const [verb, ...rest] = positionals;
126
+
127
+ if ((verb !== undefined && verb !== 'start' && verb !== 'build') || rest.length > 0) {
128
+ throw new Error(`unknown command: ${positionals.join(' ')}`);
129
+ }
130
+
131
+ const command = verb === 'build' ? 'build' : 'serve';
132
+ const misplaced = (command === 'build' ? SERVE_OPTIONS : BUILD_OPTIONS).find(
133
+ (name) => name in values
134
+ );
135
+
136
+ if (misplaced) {
137
+ throw new Error(
138
+ `--${misplaced} does not apply to ${command === 'build' ? 'build' : 'serving'}`
139
+ );
140
+ }
141
+
142
+ const port = Number(values.port ?? DEFAULTS.port);
143
+
144
+ if (!Number.isInteger(port) || port < 0 || port > 65535) {
145
+ throw new Error(`invalid --port: ${values.port}`);
146
+ }
147
+
148
+ let server = '';
149
+
150
+ if (values.server !== undefined) {
151
+ let parsed;
152
+
153
+ try {
154
+ parsed = new URL(values.server);
155
+ } catch {
156
+ parsed = null;
157
+ }
158
+
159
+ if (!parsed || (parsed.protocol !== 'http:' && parsed.protocol !== 'https:')) {
160
+ throw new Error(`invalid --server, expected an http(s) URL: ${values.server}`);
161
+ }
162
+
163
+ server = `${parsed.origin}${parsed.pathname.replace(/\/+$/, '')}`;
164
+ }
165
+
166
+ return {
167
+ command,
168
+ force: values.force ?? false,
169
+ help: values.help ?? false,
170
+ host: values.host ?? DEFAULTS.host,
171
+ open: values.open ?? true,
172
+ out: values.out ?? DEFAULTS.out,
173
+ port,
174
+ server,
175
+ version: values.version ?? false
176
+ };
177
+ }
178
+
179
+ /**
180
+ * Maps a request path to a file under `root`, or null when it falls outside it.
181
+ * @param {string} root
182
+ * @param {string} pathname
183
+ */
184
+ function resolveStatic(root, pathname) {
185
+ let decoded;
186
+
187
+ try {
188
+ decoded = decodeURIComponent(pathname);
189
+ } catch {
190
+ return null;
191
+ }
192
+
193
+ if (decoded.includes('\0')) return null;
194
+
195
+ const file = normalize(join(root, decoded === '/' ? '/index.html' : decoded));
196
+
197
+ return file === root || file.startsWith(root.endsWith(sep) ? root : root + sep) ? file : null;
198
+ }
199
+
200
+ /**
201
+ * Sends a file from `dist`, with llama-server's caching and cross-origin isolation headers.
202
+ * @param {http.IncomingMessage} req
203
+ * @param {http.ServerResponse} res
204
+ * @param {string} file
205
+ * @param {string} pathname
206
+ * @param {import('node:fs').Stats} stats
207
+ */
208
+ function sendFile(req, res, file, pathname, stats) {
209
+ const name = pathname === '/' ? '/index.html' : pathname;
210
+ const etag = `W/"${stats.size.toString(16)}-${Math.floor(stats.mtimeMs).toString(16)}"`;
211
+
212
+ res.setHeader('ETag', etag);
213
+ res.setHeader('Cache-Control', NO_CACHE.has(name) ? CACHE_REVALIDATE : CACHE_IMMUTABLE);
214
+
215
+ if (name === '/index.html') {
216
+ res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp');
217
+ res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
218
+ }
219
+
220
+ if (req.headers['if-none-match'] === etag) {
221
+ res.writeHead(304).end();
222
+
223
+ return;
224
+ }
225
+
226
+ res.setHeader(
227
+ 'Content-Type',
228
+ MIME_TYPES[extname(file).toLowerCase()] ?? 'application/octet-stream'
229
+ );
230
+ res.setHeader('Content-Length', stats.size);
231
+ res.writeHead(200);
232
+
233
+ if (req.method === 'HEAD') {
234
+ res.end();
235
+
236
+ return;
237
+ }
238
+
239
+ createReadStream(file).pipe(res);
240
+ }
241
+
242
+ /**
243
+ * @param {http.ServerResponse} res
244
+ * @param {number} status
245
+ * @param {string} message
246
+ */
247
+ function sendError(res, status, message) {
248
+ res.writeHead(status, { 'Content-Type': 'text/plain; charset=utf-8' });
249
+ res.end(`${message}\n`);
250
+ }
251
+
252
+ /**
253
+ * The app's config.json for a llama-server at `server`.
254
+ * @param {string} server
255
+ */
256
+ function configJson(server) {
257
+ return `${JSON.stringify({ server })}\n`;
258
+ }
259
+
260
+ /**
261
+ * The HTTP server: the files of `dist`, read-only. With `server`, it answers config.json
262
+ * itself, so the app talks to that llama-server instead of this address.
263
+ * @param {{ distDir?: string, server?: string }} [options]
264
+ */
265
+ export function createChatServer({ distDir = DIST_DIR, server = '' } = {}) {
266
+ const root = normalize(distDir);
267
+
268
+ return http.createServer(async (req, res) => {
269
+ const { pathname } = new URL(req.url ?? '/', 'http://localhost');
270
+
271
+ if (req.method !== 'GET' && req.method !== 'HEAD') {
272
+ res.setHeader('Allow', 'GET, HEAD');
273
+ sendError(res, 405, 'Method Not Allowed');
274
+
275
+ return;
276
+ }
277
+
278
+ if (server && pathname === CONFIG_PATH) {
279
+ const body = configJson(server);
280
+
281
+ res.writeHead(200, {
282
+ 'Cache-Control': CACHE_REVALIDATE,
283
+ 'Content-Length': Buffer.byteLength(body),
284
+ 'Content-Type': MIME_TYPES['.json']
285
+ });
286
+ res.end(req.method === 'HEAD' ? undefined : body);
287
+
288
+ return;
289
+ }
290
+
291
+ const file = resolveStatic(root, pathname);
292
+ const stats = file ? await stat(file).catch(() => null) : null;
293
+
294
+ if (file && stats?.isFile()) {
295
+ sendFile(req, res, file, pathname, stats);
296
+
297
+ return;
298
+ }
299
+
300
+ sendError(res, 404, 'Not Found');
301
+ });
302
+ }
303
+
304
+ /**
305
+ * Writes the app to a folder: the files of `dist` without source maps, ready for any static
306
+ * file server. Refuses a folder that is not empty unless `force` is set, and a folder in `dist`.
307
+ * With `server`, its config.json names that llama-server.
308
+ * @param {{ distDir?: string, force?: boolean, out: string, server?: string }} options
309
+ * @returns {Promise<string>} the absolute path of the folder
310
+ */
311
+ export async function buildStatic({ distDir = DIST_DIR, force = false, out, server = '' }) {
312
+ const source = resolve(distDir);
313
+ const target = resolve(out);
314
+ const inside = relative(source, target);
315
+
316
+ if (inside === '' || !(inside.startsWith('..') || isAbsolute(inside))) {
317
+ throw new Error(`cannot build into ${target}, it is inside the app's own files`);
318
+ }
319
+
320
+ const entries = await readdir(target).catch(() => []);
321
+
322
+ if (entries.length > 0 && !force) {
323
+ throw new Error(`${target} is not empty, pick another --out or add --force`);
324
+ }
325
+
326
+ await cp(source, target, { filter: (file) => !file.endsWith('.map'), recursive: true });
327
+
328
+ if (server) await writeFile(join(target, CONFIG_PATH), configJson(server));
329
+
330
+ return target;
331
+ }
332
+
333
+ /**
334
+ * Opens a URL in the default browser, quietly doing nothing where that fails.
335
+ * @param {string} url
336
+ */
337
+ function openBrowser(url) {
338
+ const [command, args] =
339
+ process.platform === 'darwin'
340
+ ? ['open', [url]]
341
+ : process.platform === 'win32'
342
+ ? ['cmd', ['/c', 'start', '""', url]]
343
+ : ['xdg-open', [url]];
344
+
345
+ try {
346
+ // verbatim, or Node quotes the empty title of `start` into one cmd.exe misreads
347
+ spawn(command, args, { detached: true, stdio: 'ignore', windowsVerbatimArguments: true })
348
+ .on('error', () => {})
349
+ .unref();
350
+ } catch {
351
+ // no browser to open, e.g. on a headless machine
352
+ }
353
+ }
354
+
355
+ /**
356
+ * Runs the command.
357
+ * @param {string[]} argv the arguments after the command
358
+ * @returns {Promise<http.Server | undefined>} the server, once it listens
359
+ */
360
+ export async function main(argv) {
361
+ let options;
362
+
363
+ try {
364
+ options = parseCliArgs(argv);
365
+ } catch (error) {
366
+ console.error(`llama-chat: ${error instanceof Error ? error.message : error}\n\n${USAGE}`);
367
+ process.exitCode = 2;
368
+
369
+ return;
370
+ }
371
+
372
+ if (options.help) {
373
+ console.log(USAGE);
374
+
375
+ return;
376
+ }
377
+
378
+ if (options.version) {
379
+ console.log(packageVersion());
380
+
381
+ return;
382
+ }
383
+
384
+ if (!(await stat(join(DIST_DIR, 'index.html')).catch(() => null))) {
385
+ console.error(`llama-chat: no build found in ${DIST_DIR}, run \`npm run build\` first`);
386
+ process.exitCode = 1;
387
+
388
+ return;
389
+ }
390
+
391
+ if (options.command === 'build') {
392
+ try {
393
+ const target = await buildStatic({
394
+ force: options.force,
395
+ out: options.out,
396
+ server: options.server
397
+ });
398
+ const shown = relative(process.cwd(), target) || '.';
399
+
400
+ console.log(`Llama Chat ${packageVersion()} written to ${target}`);
401
+ console.log(`Serve it with any static file server, e.g.: npx http-server ${shown}`);
402
+ } catch (error) {
403
+ console.error(`llama-chat: ${error instanceof Error ? error.message : error}`);
404
+ process.exitCode = 1;
405
+ }
406
+
407
+ return;
408
+ }
409
+
410
+ const server = createChatServer({ server: options.server });
411
+
412
+ return new Promise((resolve) => {
413
+ server.on('error', (error) => {
414
+ const busy = /** @type {NodeJS.ErrnoException} */ (error).code === 'EADDRINUSE';
415
+
416
+ console.error(
417
+ busy
418
+ ? `llama-chat: port ${options.port} is in use, pick another with --port`
419
+ : `llama-chat: ${error.message}`
420
+ );
421
+ process.exitCode = 1;
422
+ resolve(undefined);
423
+ });
424
+
425
+ server.listen(options.port, options.host, () => {
426
+ const address = /** @type {import('node:net').AddressInfo} */ (server.address());
427
+ const shown = ['0.0.0.0', '::'].includes(options.host) ? 'localhost' : options.host;
428
+ const url = `http://${shown.includes(':') ? `[${shown}]` : shown}:${address.port}/`;
429
+
430
+ console.log(`Llama Chat ${packageVersion()} on ${url}`);
431
+
432
+ if (options.server) console.log(`Talking to llama-server on ${options.server}`);
433
+
434
+ console.log(
435
+ `If llama-server restricts origins (tools or MCP on), start it with --cors-origins ${url.slice(0, -1)}`
436
+ );
437
+
438
+ if (options.open) openBrowser(url);
439
+
440
+ resolve(server);
441
+ });
442
+ });
443
+ }