bazilion 0.27.0 → 0.51.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 (234) hide show
  1. package/dist/cli.js +651 -309
  2. package/dist/cli.js.map +1 -1
  3. package/dist/daemon.js +2105 -997
  4. package/dist/daemon.js.map +1 -1
  5. package/dist/web/client/assets/AddProviderDialog-Diic36c_.js +1 -0
  6. package/dist/web/client/assets/ConfigPage-pupvtSCX.js +1 -0
  7. package/dist/web/client/assets/ConfirmDialog-GFDcHI1L.js +1 -0
  8. package/dist/web/client/assets/ConnectionsView-y1CeY-6U.js +1 -0
  9. package/dist/web/client/assets/Dialog-bg86_x4v.js +1 -0
  10. package/dist/web/client/assets/FieldRow-B8eIni5r.js +1 -0
  11. package/dist/web/client/assets/ModelSelect-DvCLUmkW.js +1 -0
  12. package/dist/web/client/assets/SectionTabs-D4ezA6U4.js +1 -0
  13. package/dist/web/client/assets/Segmented-Dh77vmpp.js +1 -0
  14. package/dist/web/client/assets/SkillFindings-BzLO1lNA.js +1 -0
  15. package/dist/web/client/assets/SkillsPicker-hI3YXvib.js +1 -0
  16. package/dist/web/client/assets/SpawnDialog-YJX6UMBC.js +1 -0
  17. package/dist/web/client/assets/Tabs-f6bHvCGn.js +1 -0
  18. package/dist/web/client/assets/TeamForm-kda1HYZG.js +1 -0
  19. package/dist/web/client/assets/TeamThread-DFvbakHo.js +1 -0
  20. package/dist/web/client/assets/UnsavedChangesGuard-DBJikVgc.js +1 -0
  21. package/dist/web/client/assets/_id-BjNtLwak.js +1 -0
  22. package/dist/web/client/assets/_id-BklaQf3z.js +1 -0
  23. package/dist/web/client/assets/agents-D9cUF2d9.js +1 -0
  24. package/dist/web/client/assets/agents-wuBlzx4e.js +1 -0
  25. package/dist/web/client/assets/api-HC_YzjBy.js +1 -0
  26. package/dist/web/client/assets/arrow-right-Gm_FDWJ_.js +1 -0
  27. package/dist/web/client/assets/attention-8ZkSLl2e.js +1 -0
  28. package/dist/web/client/assets/check-BjgKoGvU.js +1 -0
  29. package/dist/web/client/assets/config-Con_BbSh.js +1 -0
  30. package/dist/web/client/assets/createLucideIcon-C6gOo8sD.js +1 -0
  31. package/dist/web/client/assets/index-Br9qkGM-.js +54 -0
  32. package/dist/web/client/assets/link-Cbztlp_R.js +1 -0
  33. package/dist/web/client/assets/login-llnOKSJc.js +1 -0
  34. package/dist/web/client/assets/mcp-zIUguMSI.js +1 -0
  35. package/dist/web/client/assets/plus-CWrKMtvA.js +1 -0
  36. package/dist/web/client/assets/routes-BY5uqJ2n.js +76 -0
  37. package/dist/web/client/assets/save-f9O-CQia.js +1 -0
  38. package/dist/web/client/assets/services-esLrcTwe.js +1 -0
  39. package/dist/web/client/assets/skills-DzYXksM0.js +1 -0
  40. package/dist/web/client/assets/style-Cdzqt_TJ.js +7 -0
  41. package/dist/web/client/assets/styles-BRSS6yrm.css +2 -0
  42. package/dist/web/client/assets/system-CsI66nyZ.js +1 -0
  43. package/dist/web/client/assets/teams-CHE_zpxS.js +1 -0
  44. package/dist/web/client/assets/teams-dxG9OESG.js +1 -0
  45. package/dist/web/client/assets/telegram-C3dGndJV.js +1 -0
  46. package/dist/web/client/assets/tokens-CNNH-Wr9.js +1 -0
  47. package/dist/web/client/assets/use-resource-BjnxgGvh.js +1 -0
  48. package/dist/web/client/assets/welcome-C8EOtc8P.js +1 -0
  49. package/dist/web/server/assets/AddProviderDialog-CR6TRYdZ.js +910 -0
  50. package/dist/web/server/assets/{ConfigPage-CGld_wCK.js → ConfigPage-CIh3ohea.js} +4 -4
  51. package/dist/web/server/assets/ConfirmDialog-B79K2KEW.js +52 -0
  52. package/dist/web/server/assets/ConnectionsView-BIMYdp9C.js +710 -0
  53. package/dist/web/server/assets/{ConfirmDialog-LdVlEanK.js → Dialog-CVqpXxuN.js} +3 -50
  54. package/dist/web/server/assets/{FieldRow-Dah2KKqo.js → FieldRow-CHVhX2rS.js} +4 -4
  55. package/dist/web/server/assets/{ModelSelect-Vwro6OkL.js → ModelSelect-DrZrdndo.js} +7 -7
  56. package/dist/web/server/assets/Rail-Cg-efcpA.js +698 -0
  57. package/dist/web/server/assets/{SectionTabs-CqFg9Vwx.js → SectionTabs-DrcgVeZd.js} +4 -18
  58. package/dist/web/server/assets/Segmented-3ZLdqa5U.js +18 -0
  59. package/dist/web/server/assets/{SkillFindings-Bd6e81Wu.js → SkillFindings-DSDiL6hn.js} +1 -1
  60. package/dist/web/server/assets/{SpawnDialog-BGNaMfFb.js → SpawnDialog-BUUlLxE9.js} +25 -7
  61. package/dist/web/server/assets/{TeamForm-C93tpn9r.js → TeamForm-CvQAs2FA.js} +1 -1
  62. package/dist/web/server/assets/TeamThread-5CjVPcDr.js +190 -0
  63. package/dist/web/server/assets/{UnsavedChangesGuard-Dm4a27_5.js → UnsavedChangesGuard-CyF2Z9p1.js} +8 -4
  64. package/dist/web/server/assets/{TeamPolicyEditor-BHS3J0R9.js → _id-0fEWiVZX.js} +114 -263
  65. package/dist/web/server/assets/{_id-B0x1ffz3.js → _id-8bsYEcGg.js} +2 -2
  66. package/dist/web/server/assets/{_id-sW6zXrTP.js → _id-BvAaRSUW.js} +2 -2
  67. package/dist/web/server/assets/{_id-lOVnT5sS.js → _id-Dg6M_qfr.js} +6 -6
  68. package/dist/web/server/assets/{_id-ByiXeIPS.js → _id-Dji7xr9C.js} +2 -2
  69. package/dist/web/server/assets/{_id-Bdf_Rg62.js → _id-TVruGcOd.js} +1 -1
  70. package/dist/web/server/assets/_tanstack-start-manifest_v-sxiIH4M7.js +214 -0
  71. package/dist/web/server/assets/{agents-D4tqK1kH.js → agents-BDA5yYZ2.js} +14 -15
  72. package/dist/web/server/assets/{agents-Cn9GkXFX.js → agents-BTDxmp-F.js} +2 -2
  73. package/dist/web/server/assets/{agents-BNPkidbH.js → agents-BnWgFo6o.js} +1 -1
  74. package/dist/web/server/assets/{agents-lOqc6VGd.js → agents-DM7guWF2.js} +2 -2
  75. package/dist/web/server/assets/{agents-DycxHDt8.js → agents-DktqUffG.js} +10 -10
  76. package/dist/web/server/assets/{agents-BK8OmB8g.js → agents-xgZ9rsac.js} +2 -2
  77. package/dist/web/server/assets/{attention-DULVjdmF.js → attention-CHQEQiZl.js} +2 -2
  78. package/dist/web/server/assets/{attention-YWnLKA2E.js → attention-Cr7puThv.js} +1 -1
  79. package/dist/web/server/assets/{attention-BIm455bC.js → attention-De3-ehuf.js} +6 -6
  80. package/dist/web/server/assets/{auth-DiN92ydD.js → auth-dJnrFW6y.js} +1 -1
  81. package/dist/web/server/assets/config-DOp28gcy.js +1067 -0
  82. package/dist/web/server/assets/config-DzgkbBoD.js +17 -0
  83. package/dist/web/server/assets/config-X7qWbbpH.js +20 -0
  84. package/dist/web/server/assets/{Page-CMSYKXWJ.js → createSsrRpc-CcLbajrF.js} +17 -2
  85. package/dist/web/server/assets/{daemon-client-DL2ik2Em.js → daemon-client-B_ZRIIrT.js} +2 -1
  86. package/dist/web/server/assets/{mcp-BwmpNQPN.js → mcp-C97uAZe1.js} +1 -1
  87. package/dist/web/server/assets/{mcp-B09_O05r.js → mcp-CO_tycXU.js} +9 -9
  88. package/dist/web/server/assets/{mcp-CqdTfXcn.js → mcp-D3OCoHtO.js} +2 -2
  89. package/dist/web/server/assets/router-Cs2Ak4II.js +892 -0
  90. package/dist/web/server/assets/routes-BSNOKE-C.js +7647 -0
  91. package/dist/web/server/assets/routes-BVwqgZGI.js +16 -0
  92. package/dist/web/server/assets/routes-CO4l-GJ0.js +57 -0
  93. package/dist/web/server/assets/{services-Q9HYQXXB.js → services-DZLxUSG8.js} +2 -2
  94. package/dist/web/server/assets/{services-BLvAvb8g.js → services-DsHRLL8q.js} +1 -1
  95. package/dist/web/server/assets/{services-tCfB1B83.js → services-DsvpaF3L.js} +4 -4
  96. package/dist/web/server/assets/{skills-BZg_txbf.js → skills-CggQJk6a.js} +2 -2
  97. package/dist/web/server/assets/{skills-C7fqRPna.js → skills-DKYV7PTk.js} +11 -11
  98. package/dist/web/server/assets/{skills-C_g8IKag.js → skills-h5aHa7Q8.js} +1 -1
  99. package/dist/web/server/assets/style-GYDODk2F.js +178 -0
  100. package/dist/web/server/assets/system-CZ2qzBz3.js +138 -0
  101. package/dist/web/server/assets/system-DsJfpBPl.js +12 -0
  102. package/dist/web/server/assets/system-DtswhLW62.js +18 -0
  103. package/dist/web/server/assets/{teams-BS-oweRl.js → teams-B6PzNcoy.js} +23 -15
  104. package/dist/web/server/assets/{teams-D4CaU76n.js → teams-B6lBhvdL.js} +2 -2
  105. package/dist/web/server/assets/{teams-BHkhnt6b.js → teams-Bp2tERZe.js} +2 -2
  106. package/dist/web/server/assets/{teams-DX2HmKqi.js → teams-BxnvFTyn.js} +1 -1
  107. package/dist/web/server/assets/{teams-BSflKBP8.js → teams-C-8iz-uV.js} +6 -6
  108. package/dist/web/server/assets/{teams-CNyB5nM9.js → teams-YrmyutM4.js} +1 -1
  109. package/dist/web/server/assets/{telegram-CrJiygCX.js → telegram-CXrP3hMp.js} +6 -6
  110. package/dist/web/server/assets/{telegram-BUdnc8oF.js → telegram-D2RZriz_.js} +2 -2
  111. package/dist/web/server/assets/{telegram-C4v1HhyJ.js → telegram-Gy7_9yih.js} +1 -1
  112. package/dist/web/server/assets/{tokens-DqldzPUq.js → tokens-C-oDTqnp.js} +2 -2
  113. package/dist/web/server/assets/{tokens-B1twAJdd.js → tokens-CEdl8puR.js} +1 -1
  114. package/dist/web/server/assets/{tokens-DdjEyALj.js → tokens-DSLwQ1Pw.js} +10 -10
  115. package/dist/web/server/assets/use-resource-ChQozXVI.js +63 -0
  116. package/dist/web/server/assets/welcome-BLw1G6SS.js +318 -0
  117. package/dist/web/server/assets/welcome-ByAkvHSP.js +26 -0
  118. package/dist/web/server/assets/welcome-CxXMI4HI.js +15 -0
  119. package/dist/web/server/assets/workspace-DeEYMPDX.js +658 -0
  120. package/dist/web/server/server.js +30 -74
  121. package/dist/worker.js +78 -36
  122. package/dist/worker.js.map +1 -1
  123. package/package.json +1 -1
  124. package/dist/web/client/assets/AgentAvatar-DWx-bM6n.js +0 -1
  125. package/dist/web/client/assets/ChatPane-DOV_HJg-.js +0 -72
  126. package/dist/web/client/assets/ConfigPage-Dfu9DzFX.js +0 -1
  127. package/dist/web/client/assets/ConfirmDialog-536ziJ5P.js +0 -1
  128. package/dist/web/client/assets/FieldRow-z1JqCdqn.js +0 -1
  129. package/dist/web/client/assets/ModelSelect-CvOHjUyB.js +0 -1
  130. package/dist/web/client/assets/ResultCard-X4nTbjYY.js +0 -1
  131. package/dist/web/client/assets/SectionTabs-DXHzXmmb.js +0 -1
  132. package/dist/web/client/assets/SkillFindings-8LX6bYf_.js +0 -1
  133. package/dist/web/client/assets/SkillsPicker-Cr87y_W-.js +0 -1
  134. package/dist/web/client/assets/SpawnDialog-DoZl-yes.js +0 -1
  135. package/dist/web/client/assets/SpawnTeamModal-C638hEoN.js +0 -1
  136. package/dist/web/client/assets/Tabs-D0LgBNIk.js +0 -1
  137. package/dist/web/client/assets/TeamForm-C-WzvOl4.js +0 -1
  138. package/dist/web/client/assets/TeamPolicyEditor-CSKBx0oK.js +0 -7
  139. package/dist/web/client/assets/UnsavedChangesGuard-GC-vzw7h.js +0 -1
  140. package/dist/web/client/assets/_id-BKLynswT.js +0 -1
  141. package/dist/web/client/assets/_id-BYM_NORr.js +0 -1
  142. package/dist/web/client/assets/_id-Cxa98a9m.js +0 -1
  143. package/dist/web/client/assets/_id-D4hV1U1t.js +0 -1
  144. package/dist/web/client/assets/agent-actions-CXQCoxKO.js +0 -1
  145. package/dist/web/client/assets/agents-BxPS1_Bp.js +0 -1
  146. package/dist/web/client/assets/agents-GozAWW-l.js +0 -1
  147. package/dist/web/client/assets/attention-Cz9rZcrr.js +0 -1
  148. package/dist/web/client/assets/chevron-right-CPAb1zac.js +0 -1
  149. package/dist/web/client/assets/config-9vv9Lipb.js +0 -3
  150. package/dist/web/client/assets/inbox-DHLArXxl.js +0 -1
  151. package/dist/web/client/assets/index-1YXquAq8.js +0 -52
  152. package/dist/web/client/assets/jsx-runtime-bzQ4Vb5N.js +0 -1
  153. package/dist/web/client/assets/learning-PvtXm8Ne.js +0 -1
  154. package/dist/web/client/assets/login-DIJpNQFo.js +0 -1
  155. package/dist/web/client/assets/mcp-pKBL0xIf.js +0 -1
  156. package/dist/web/client/assets/members-DHWsgsEs.js +0 -1
  157. package/dist/web/client/assets/memory-CEVppPyU.js +0 -1
  158. package/dist/web/client/assets/plus-BaIRdB10.js +0 -1
  159. package/dist/web/client/assets/policy-DEh4BLSw.js +0 -1
  160. package/dist/web/client/assets/preload-helper-eUUcpe2S.js +0 -1
  161. package/dist/web/client/assets/results-DgJPjEZF.js +0 -1
  162. package/dist/web/client/assets/review-BbshafTQ.js +0 -1
  163. package/dist/web/client/assets/route-Ccb8v41z.js +0 -1
  164. package/dist/web/client/assets/route-D1d6kCEV.js +0 -1
  165. package/dist/web/client/assets/routes-g7V4ru7T.js +0 -1
  166. package/dist/web/client/assets/services-B2f7e5jV.js +0 -1
  167. package/dist/web/client/assets/settings-B6elpcYm.js +0 -1
  168. package/dist/web/client/assets/skills-CngE7TF8.js +0 -1
  169. package/dist/web/client/assets/styles-xUnZ-ep_.css +0 -2
  170. package/dist/web/client/assets/teams-BdJZXOan.js +0 -1
  171. package/dist/web/client/assets/teams-c496ISsT.js +0 -1
  172. package/dist/web/client/assets/telegram-B_-hK6EC.js +0 -1
  173. package/dist/web/client/assets/tokens-CKz8gx4-.js +0 -1
  174. package/dist/web/client/assets/triggers-DCEPciGW.js +0 -1
  175. package/dist/web/client/assets/welcome-D-zVOLGA.js +0 -1
  176. package/dist/web/server/assets/AgentAvatar-8gTAy_tP.js +0 -37
  177. package/dist/web/server/assets/ChatPane-De_FPEoD.js +0 -1887
  178. package/dist/web/server/assets/ResultCard-CZn1w4KA.js +0 -97
  179. package/dist/web/server/assets/Sidebar-puq47KyR.js +0 -430
  180. package/dist/web/server/assets/SpawnTeamModal-C6GbfScI.js +0 -97
  181. package/dist/web/server/assets/_id-BR6tnR6I.js +0 -23
  182. package/dist/web/server/assets/_id-Bm611NQz.js +0 -13
  183. package/dist/web/server/assets/_id-D5UCoyES.js +0 -359
  184. package/dist/web/server/assets/_id-DHx5UmmL.js +0 -12
  185. package/dist/web/server/assets/_id-DLpGmOVm.js +0 -19
  186. package/dist/web/server/assets/_id-Y5ctILG2.js +0 -13
  187. package/dist/web/server/assets/_id-dDA0pdVo.js +0 -54
  188. package/dist/web/server/assets/_tanstack-start-manifest_v-B8u80HjK.js +0 -292
  189. package/dist/web/server/assets/agent-actions-BBdFVdoa.js +0 -20
  190. package/dist/web/server/assets/api-WWxPqx67.js +0 -85
  191. package/dist/web/server/assets/config-BNEgu7WG.js +0 -798
  192. package/dist/web/server/assets/config-C1VB28se.js +0 -12
  193. package/dist/web/server/assets/config-TdVqnqNL.js +0 -25
  194. package/dist/web/server/assets/createSsrRpc-6LHNEsSK.js +0 -16
  195. package/dist/web/server/assets/inbox-4Vj5jTT8.js +0 -245
  196. package/dist/web/server/assets/inbox-D4IqUv3l.js +0 -38
  197. package/dist/web/server/assets/inbox-Dle24AfV.js +0 -23
  198. package/dist/web/server/assets/learning-BScq7VbO.js +0 -12
  199. package/dist/web/server/assets/learning-CBWFEnhg.js +0 -263
  200. package/dist/web/server/assets/learning-DWAKevhF.js +0 -25
  201. package/dist/web/server/assets/members-B8QBF6TF.js +0 -12
  202. package/dist/web/server/assets/members-DsF02Wp7.js +0 -12
  203. package/dist/web/server/assets/members-tWZA9b15.js +0 -36
  204. package/dist/web/server/assets/memory-BNN0b-0x.js +0 -12
  205. package/dist/web/server/assets/memory-CTl1E1Rm.js +0 -267
  206. package/dist/web/server/assets/memory-CV5uCBb2.js +0 -12
  207. package/dist/web/server/assets/policy-C9M6zV6w.js +0 -79
  208. package/dist/web/server/assets/policy-h-6NpU3m.js +0 -19
  209. package/dist/web/server/assets/policy-xEw9X0DK.js +0 -12
  210. package/dist/web/server/assets/results-D3A3UA4d.js +0 -182
  211. package/dist/web/server/assets/results-D6Ui5S8D.js +0 -12
  212. package/dist/web/server/assets/results-DWmxvfyn.js +0 -15
  213. package/dist/web/server/assets/review-CyQky-WQ.js +0 -40
  214. package/dist/web/server/assets/review-Sq0GGcPV.js +0 -322
  215. package/dist/web/server/assets/review-XWbSF8cF.js +0 -12
  216. package/dist/web/server/assets/route-BErtkz6t.js +0 -19
  217. package/dist/web/server/assets/route-CLoV-An_.js +0 -48
  218. package/dist/web/server/assets/route-WQ19JkBa.js +0 -19
  219. package/dist/web/server/assets/route-dEK_2GLj.js +0 -203
  220. package/dist/web/server/assets/route-iHTkhO81.js +0 -16
  221. package/dist/web/server/assets/route-zs8uUQtB.js +0 -16
  222. package/dist/web/server/assets/router-BI9gmY3S.js +0 -751
  223. package/dist/web/server/assets/routes-081s4n24.js +0 -45
  224. package/dist/web/server/assets/routes-CWo5WPsr.js +0 -15
  225. package/dist/web/server/assets/routes-Cqp1ufHm.js +0 -56
  226. package/dist/web/server/assets/settings-CVaGv-xF.js +0 -12
  227. package/dist/web/server/assets/settings-D9viV-86.js +0 -561
  228. package/dist/web/server/assets/settings-DaZNZ_CC.js +0 -27
  229. package/dist/web/server/assets/triggers-B7LW784F.js +0 -214
  230. package/dist/web/server/assets/triggers-C5sMCZXv2.js +0 -12
  231. package/dist/web/server/assets/triggers-DMfVdImD.js +0 -12
  232. package/dist/web/server/assets/welcome-D0d38Pzx.js +0 -93
  233. package/dist/web/client/assets/{TeamPolicyEditor-DLioOiRN.css → style-DLioOiRN.css} +0 -0
  234. package/dist/web/server/assets/{start-DTX6aKCi.js → start-DhW7sy23.js} +1 -1
@@ -0,0 +1,910 @@
1
+ import { E as errorMessage, d as Button, u as cn, w as api } from "./workspace-DeEYMPDX.js";
2
+ import { r as useResource } from "./use-resource-ChQozXVI.js";
3
+ import { n as DialogActions, t as Dialog } from "./Dialog-CVqpXxuN.js";
4
+ import { useEffect, useMemo, useRef, useState } from "react";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ import { AlertTriangle, ArrowLeft, Check, ChevronRight, Images, Search, X } from "lucide-react";
7
+ //#region src/lib/model-facts.ts
8
+ function modelName(model) {
9
+ return model.name ?? model.id;
10
+ }
11
+ /** A context window in the units people say: `1M`, `272K`. */
12
+ function formatContext(tokens) {
13
+ if (!tokens || tokens <= 0) return null;
14
+ if (tokens >= 1e6) return `${(tokens / 1e6).toFixed(1).replace(/\.0$/, "")}M`;
15
+ return `${Math.round(tokens / 1e3)}K`;
16
+ }
17
+ /** A dollar amount with cents, and the third decimal only when it carries something. */
18
+ function formatUsd(value) {
19
+ if (Number.isInteger(value)) return `$${value}`;
20
+ const fixed = value.toFixed(3);
21
+ return `$${fixed.endsWith("0") ? fixed.slice(0, -1) : fixed}`;
22
+ }
23
+ /** What a model can do, in one line. A model the catalog does not know has nothing to say. */
24
+ function factsLine(model, connect) {
25
+ const context = formatContext(model.contextWindow);
26
+ if (!model.name && !context) return connect === "local" ? "Loaded on the server" : "Not in the bundled catalog";
27
+ return [
28
+ context ? `${context} context` : null,
29
+ model.images ? "sees images" : "text only",
30
+ model.reasoning ? "reasoning" : null
31
+ ].filter(Boolean).join(" · ");
32
+ }
33
+ /** What a model costs: the list price per million tokens, or who pays instead. */
34
+ function priceLine(model, connect) {
35
+ if (connect === "signin") return "Included in your plan";
36
+ if (connect === "local") return "Runs on your hardware";
37
+ if (!model.price) return "No list price";
38
+ return `${formatUsd(model.price.input)} in · ${formatUsd(model.price.output)} out`;
39
+ }
40
+ function usedByLine(usedBy) {
41
+ const parts = [...usedBy.templates.map((name) => `${name} template`), usedBy.agents === 1 ? "1 Agent" : usedBy.agents > 1 ? `${usedBy.agents} Agents` : null].filter(Boolean);
42
+ return parts.length > 0 ? parts.join(", ") : "Not used yet";
43
+ }
44
+ /** Whether a model matches what was typed: every word, in its name or id. */
45
+ function matchesModel(model, query) {
46
+ const haystack = `${model.name ?? ""} ${model.id}`.toLowerCase();
47
+ return query.toLowerCase().split(/\s+/).filter(Boolean).every((word) => haystack.includes(word));
48
+ }
49
+ /** "2 minutes ago", for something that happened at `at`. */
50
+ function ago(at, now) {
51
+ const seconds = Math.max(0, Math.round((now - at) / 1e3));
52
+ if (seconds < 45) return "just now";
53
+ const minutes = Math.round(seconds / 60);
54
+ if (minutes < 60) return minutes === 1 ? "1 minute ago" : `${minutes} minutes ago`;
55
+ const hours = Math.round(minutes / 60);
56
+ if (hours < 24) return hours === 1 ? "1 hour ago" : `${hours} hours ago`;
57
+ const days = Math.round(hours / 24);
58
+ if (days < 30) return days === 1 ? "yesterday" : `${days} days ago`;
59
+ return `on ${new Date(at).toISOString().slice(0, 10)}`;
60
+ }
61
+ var FAILURE_LABEL = {
62
+ credentials: "Key rejected",
63
+ unreachable: "Not answering",
64
+ model: "Model unavailable",
65
+ limit: "Limit reached",
66
+ other: "Failing"
67
+ };
68
+ /** A provider's state as a chip: a few words and how loud they are. */
69
+ function providerStatus(provider, now) {
70
+ switch (provider.state) {
71
+ case "working": return {
72
+ label: provider.check ? `Working · tested ${ago(provider.check.at, now)}` : "Working",
73
+ tone: "success"
74
+ };
75
+ case "failing": {
76
+ const kind = provider.check?.failure?.kind ?? "other";
77
+ const label = kind === "credentials" && provider.connect === "signin" ? "Sign-in rejected" : FAILURE_LABEL[kind];
78
+ return {
79
+ label: provider.check ? `${label} · tried ${ago(provider.check.at, now)}` : label,
80
+ tone: "warning"
81
+ };
82
+ }
83
+ case "incomplete": return {
84
+ label: provider.connect === "signin" ? "Not signed in" : provider.fields.some((field) => field.kind === "secret") ? "Needs a key" : "Needs credentials",
85
+ tone: "warning"
86
+ };
87
+ case "off": return {
88
+ label: provider.models.length === 0 ? "Saved, not in use" : "Turned off",
89
+ tone: "neutral"
90
+ };
91
+ default: return {
92
+ label: "Not tested yet",
93
+ tone: "neutral"
94
+ };
95
+ }
96
+ }
97
+ /** How a provider is connected, in a few words, for its row. */
98
+ function credentialLine(provider) {
99
+ if (provider.connect === "signin") return provider.configured ? "Signed in with your ChatGPT account" : "Not signed in";
100
+ if (provider.connect === "local") return provider.address ?? "A model server on this network";
101
+ const key = provider.fields.find((field) => field.kind === "secret" && field.set);
102
+ if (key) return `${key.label} ${key.preview ?? "saved"}`;
103
+ if (provider.configured) return "Credentials from the daemon’s environment";
104
+ return "No credentials saved";
105
+ }
106
+ /** The models to ask first: suggested ones, then the ones already in use. */
107
+ function initialPicks(models) {
108
+ const selected = models.filter((model) => model.selected).map((model) => model.id);
109
+ if (selected.length > 0) return selected;
110
+ return models.filter((model) => model.suggested).map((model) => model.id);
111
+ }
112
+ /** The cheapest of the given models by list price; unpriced ones come last, in order. */
113
+ function cheapest(models) {
114
+ const cost = (model) => model.price ? model.price.input + model.price.output : Number.POSITIVE_INFINITY;
115
+ return models.map((model, index) => ({
116
+ model,
117
+ index
118
+ })).sort((a, b) => cost(a.model) - cost(b.model) || a.index - b.index)[0]?.model;
119
+ }
120
+ //#endregion
121
+ //#region src/components/setup/parts.tsx
122
+ /** A provider's initial on a tile: no logos, they are other companies' marks. */
123
+ function ProviderAvatar({ name, tone = "neutral", className }) {
124
+ return /* @__PURE__ */ jsx("span", {
125
+ "aria-hidden": "true",
126
+ className: cn("flex size-9 shrink-0 items-center justify-center rounded-xl text-[0.95rem] font-bold", tone === "success" && "bg-success/10 text-success", tone === "warning" && "bg-warning/10 text-warning", tone === "accent" && "bg-accent text-accent-foreground", tone === "neutral" && "bg-muted text-muted-foreground", className),
127
+ children: name.replace(/[^\p{L}\p{N}]/gu, "").slice(0, 1) || "?"
128
+ });
129
+ }
130
+ var CHIP = {
131
+ success: "bg-success/10 text-success",
132
+ warning: "bg-warning/10 text-warning",
133
+ neutral: "bg-muted text-muted-foreground"
134
+ };
135
+ function Chip({ tone, children }) {
136
+ return /* @__PURE__ */ jsxs("span", {
137
+ className: cn("inline-flex min-h-7 items-center gap-1.5 rounded-full px-3 text-xs font-semibold", CHIP[tone]),
138
+ children: [/* @__PURE__ */ jsx("span", {
139
+ "aria-hidden": "true",
140
+ className: "size-1.5 shrink-0 rounded-full bg-current"
141
+ }), children]
142
+ });
143
+ }
144
+ /** What a provider is doing for Agents, as a chip. */
145
+ function StateChip({ provider, now }) {
146
+ const status = providerStatus(provider, now);
147
+ return /* @__PURE__ */ jsx(Chip, {
148
+ tone: status.tone,
149
+ children: status.label
150
+ });
151
+ }
152
+ /** A failed test: what happened, what to do, and the provider's own words one click away. */
153
+ function FailureBox({ failure, children }) {
154
+ return /* @__PURE__ */ jsxs("div", {
155
+ role: "alert",
156
+ className: "rounded-2xl border border-warning/35 bg-warning/10 p-4 text-sm",
157
+ children: [/* @__PURE__ */ jsxs("div", {
158
+ className: "flex items-start gap-3",
159
+ children: [/* @__PURE__ */ jsx(AlertTriangle, {
160
+ className: "mt-0.5 size-5 shrink-0 text-warning",
161
+ "aria-hidden": "true"
162
+ }), /* @__PURE__ */ jsxs("div", {
163
+ className: "min-w-0 flex-1",
164
+ children: [
165
+ /* @__PURE__ */ jsx("div", {
166
+ className: "font-semibold text-foreground",
167
+ children: failure.title
168
+ }),
169
+ /* @__PURE__ */ jsx("div", {
170
+ className: "mt-0.5 text-muted-foreground",
171
+ children: failure.hint
172
+ }),
173
+ failure.detail && /* @__PURE__ */ jsxs("details", {
174
+ className: "mt-2 text-xs text-muted-foreground",
175
+ children: [/* @__PURE__ */ jsx("summary", {
176
+ className: "cursor-pointer font-semibold",
177
+ children: "Details"
178
+ }), /* @__PURE__ */ jsx("div", {
179
+ className: "mt-1 break-words font-mono",
180
+ children: failure.detail
181
+ })]
182
+ })
183
+ ]
184
+ })]
185
+ }), children && /* @__PURE__ */ jsx("div", {
186
+ className: "mt-3 flex flex-wrap justify-end gap-2",
187
+ children
188
+ })]
189
+ });
190
+ }
191
+ /** A search box: the magnifier and the input are one field, with one focus ring. */
192
+ function SearchField({ label, placeholder, value, onChange, className }) {
193
+ return /* @__PURE__ */ jsxs("label", {
194
+ className: cn("m-0 flex min-w-0 items-center gap-2 rounded-xl border border-border bg-muted/40 px-3 transition-shadow focus-within:border-primary focus-within:bg-card focus-within:shadow-[0_0_0_3px_var(--color-sapphire-glow)]", className),
195
+ children: [/* @__PURE__ */ jsx(Search, {
196
+ className: "size-4 shrink-0 text-muted-foreground",
197
+ "aria-hidden": "true"
198
+ }), /* @__PURE__ */ jsx("input", {
199
+ type: "search",
200
+ "aria-label": label,
201
+ placeholder,
202
+ value,
203
+ onChange: (event) => onChange(event.target.value),
204
+ className: "min-h-10 border-0 bg-transparent px-0 shadow-none focus:bg-transparent focus:shadow-none",
205
+ style: { outline: "none" }
206
+ })]
207
+ });
208
+ }
209
+ /**
210
+ * One model in a list to tick: its name and id, what it can do, what it costs. On a narrow screen
211
+ * the facts sit under the name instead of beside it.
212
+ */
213
+ function ModelRow({ model, connect, checked, disabled, onToggle, className }) {
214
+ return /* @__PURE__ */ jsxs("label", {
215
+ className: cn("m-0 grid cursor-pointer grid-cols-[auto_minmax(0,1fr)] items-center gap-x-3 gap-y-0.5 border-b border-border py-2.5 sm:grid-cols-[auto_minmax(0,1.5fr)_minmax(0,1.2fr)_9.5rem]", className),
216
+ children: [
217
+ /* @__PURE__ */ jsx("input", {
218
+ type: "checkbox",
219
+ checked,
220
+ disabled,
221
+ onChange: onToggle,
222
+ className: "m-0 size-[18px]"
223
+ }),
224
+ /* @__PURE__ */ jsxs("span", {
225
+ className: "min-w-0",
226
+ children: [
227
+ /* @__PURE__ */ jsx("span", {
228
+ className: "text-sm font-semibold text-foreground",
229
+ children: modelName(model)
230
+ }),
231
+ model.suggested && /* @__PURE__ */ jsx("span", {
232
+ className: "ml-2 rounded-full bg-accent px-2 py-0.5 text-[0.7rem] font-semibold text-accent-foreground",
233
+ children: "Suggested"
234
+ }),
235
+ model.name && /* @__PURE__ */ jsx("span", {
236
+ className: "block break-all font-mono text-[0.72rem] text-muted-foreground",
237
+ children: model.id
238
+ })
239
+ ]
240
+ }),
241
+ /* @__PURE__ */ jsx("span", {
242
+ className: "col-start-2 text-xs text-muted-foreground sm:col-start-auto",
243
+ children: factsLine(model, connect)
244
+ }),
245
+ /* @__PURE__ */ jsx("span", {
246
+ className: "col-start-2 text-xs text-foreground sm:col-start-auto sm:text-right",
247
+ children: priceLine(model, connect)
248
+ })
249
+ ]
250
+ });
251
+ }
252
+ /** A yes/no setting. */
253
+ function Switch({ checked, label, disabled = false, onChange }) {
254
+ return /* @__PURE__ */ jsx("button", {
255
+ type: "button",
256
+ role: "switch",
257
+ "aria-checked": checked,
258
+ "aria-label": label,
259
+ disabled,
260
+ onClick: () => onChange(!checked),
261
+ className: cn("relative h-7 w-[46px] shrink-0 rounded-full transition-colors disabled:opacity-50", checked ? "bg-primary" : "bg-fawn"),
262
+ children: /* @__PURE__ */ jsx("span", { className: cn("absolute top-[3px] size-[22px] rounded-full bg-white shadow transition-[left]", checked ? "left-[21px]" : "left-[3px]") })
263
+ });
264
+ }
265
+ /** Something is being waited for. */
266
+ function Waiting({ children }) {
267
+ return /* @__PURE__ */ jsxs("div", {
268
+ role: "status",
269
+ className: "flex items-center gap-3 text-sm font-semibold text-foreground",
270
+ children: [/* @__PURE__ */ jsx("span", {
271
+ "aria-hidden": "true",
272
+ className: "flex size-5 shrink-0 items-center justify-center",
273
+ children: /* @__PURE__ */ jsx("span", { className: "size-2.5 animate-pulse rounded-full bg-primary" })
274
+ }), /* @__PURE__ */ jsx("span", { children })]
275
+ });
276
+ }
277
+ /** A card of the Models page: an icon, what it holds, an action, then its rows. */
278
+ function SetupCard({ icon, title, description, action, labelledBy, children }) {
279
+ return /* @__PURE__ */ jsxs("section", {
280
+ "aria-labelledby": labelledBy,
281
+ className: "min-w-0 overflow-hidden rounded-2xl border border-border bg-card shadow-baziu-sm",
282
+ children: [/* @__PURE__ */ jsxs("div", {
283
+ className: "flex flex-wrap items-center gap-x-4 gap-y-3 px-4 py-4 sm:px-5",
284
+ children: [/* @__PURE__ */ jsxs("div", {
285
+ className: "flex min-w-0 flex-1 basis-64 items-center gap-4",
286
+ children: [/* @__PURE__ */ jsx("span", {
287
+ "aria-hidden": "true",
288
+ className: "flex size-10 shrink-0 items-center justify-center rounded-xl bg-accent text-accent-foreground",
289
+ children: icon
290
+ }), /* @__PURE__ */ jsxs("div", {
291
+ className: "min-w-0",
292
+ children: [/* @__PURE__ */ jsx("h2", {
293
+ id: labelledBy,
294
+ className: "m-0 font-body text-[1.05rem] font-semibold text-foreground",
295
+ children: title
296
+ }), /* @__PURE__ */ jsx("div", {
297
+ className: "text-sm text-muted-foreground",
298
+ children: description
299
+ })]
300
+ })]
301
+ }), action]
302
+ }), children]
303
+ });
304
+ }
305
+ //#endregion
306
+ //#region src/components/setup/ProviderConnect.tsx
307
+ /** Rows of a long catalog shown at once; typing narrows it down. */
308
+ var MAX_ROWS = 60;
309
+ function initialValues(provider) {
310
+ const values = {};
311
+ for (const field of provider.fields) values[field.envVar] = field.kind === "config" ? field.value ?? "" : "";
312
+ const address = provider.fields.find((field) => field.kind === "config" && !field.advanced);
313
+ if (provider.connect === "local" && address && !address.set) values[address.envVar] = provider.address ?? "";
314
+ return values;
315
+ }
316
+ /** The fields whose value is not what is stored: only those are sent. */
317
+ function changedFields(provider, values) {
318
+ const changed = {};
319
+ for (const field of provider.fields) {
320
+ const value = (values[field.envVar] ?? "").trim();
321
+ if (field.kind === "secret") {
322
+ if (value) changed[field.envVar] = value;
323
+ } else if (value !== (field.value ?? "")) {
324
+ if (!field.set && provider.connect === "local" && value === provider.address) continue;
325
+ changed[field.envVar] = value;
326
+ }
327
+ }
328
+ return changed;
329
+ }
330
+ /**
331
+ * Connect a provider in one step: its key, sign-in or address, the models Agents may use, and one
332
+ * button that tests before anything is saved. Used by "Add a provider" and by the first run.
333
+ */
334
+ function ProviderConnect({ provider, imageRoutes = [], onConnected }) {
335
+ const [values, setValues] = useState(() => initialValues(provider));
336
+ const [lookup, setLookup] = useState(() => changedLookup(provider, initialValues(provider)));
337
+ const [picked, setPicked] = useState(null);
338
+ const [extra, setExtra] = useState([]);
339
+ const [typedModel, setTypedModel] = useState("");
340
+ const [showAll, setShowAll] = useState(null);
341
+ const [showMore, setShowMore] = useState(false);
342
+ const [query, setQuery] = useState("");
343
+ const [phase, setPhase] = useState("idle");
344
+ const [signedIn, setSignedIn] = useState(provider.configured);
345
+ const [failure, setFailure] = useState(null);
346
+ const [error, setError] = useState(null);
347
+ const request = useRef(null);
348
+ useEffect(() => () => request.current?.abort(), []);
349
+ const outcome = useRef(null);
350
+ useEffect(() => {
351
+ if (failure || error) outcome.current?.scrollIntoView({
352
+ block: "nearest",
353
+ behavior: "smooth"
354
+ });
355
+ }, [failure, error]);
356
+ const catalog = useResource((signal) => api(`/api/config/providers/${encodeURIComponent(provider.id)}/catalog`, {
357
+ body: { fields: lookup },
358
+ signal
359
+ }), [provider.id, JSON.stringify(lookup)]);
360
+ const models = useMemo(() => {
361
+ const rank = (model) => {
362
+ const at = provider.suggested.indexOf(model.id);
363
+ return at === -1 ? provider.suggested.length : at;
364
+ };
365
+ const listed = [...catalog.data?.models ?? []].sort((a, b) => rank(a) - rank(b));
366
+ const known = new Set(listed.map((model) => model.id));
367
+ return [...listed, ...extra.filter((id) => !known.has(id)).map((id) => ({
368
+ id,
369
+ selected: false,
370
+ suggested: false
371
+ }))];
372
+ }, [
373
+ catalog.data,
374
+ extra,
375
+ provider.suggested
376
+ ]);
377
+ useEffect(() => {
378
+ const listed = catalog.data?.models;
379
+ if (!listed) return;
380
+ setPicked((current) => {
381
+ if (current && [...current].some((id) => listed.some((model) => model.id === id))) return current;
382
+ return new Set(initialPicks(listed));
383
+ });
384
+ setShowAll((current) => current ?? (listed.length <= 6 || initialPicks(listed).length === 0));
385
+ }, [catalog.data]);
386
+ const picks = picked ?? /* @__PURE__ */ new Set();
387
+ const chosen = models.filter((model) => picks.has(model.id));
388
+ const asked = cheapest(chosen);
389
+ const busy = phase !== "idle";
390
+ const local = provider.connect === "local";
391
+ const signin = provider.connect === "signin";
392
+ const mainFields = provider.fields.filter((field) => !field.advanced);
393
+ const advancedFields = provider.fields.filter((field) => field.advanced);
394
+ const credentialsReady = signin || provider.configured || mainFields.every((field) => field.set || (values[field.envVar] ?? "").trim().length > 0);
395
+ const shortlist = models.filter((model) => model.suggested || model.selected || picks.has(model.id));
396
+ const browsing = showAll === true;
397
+ const matching = browsing ? models.filter((model) => query ? matchesModel(model, query) : !model.dated || picks.has(model.id)) : shortlist;
398
+ const rows = matching.slice(0, MAX_ROWS);
399
+ function toggle(id) {
400
+ setPicked((current) => {
401
+ const next = new Set(current);
402
+ if (next.has(id)) next.delete(id);
403
+ else next.add(id);
404
+ return next;
405
+ });
406
+ }
407
+ function addTyped() {
408
+ const id = typedModel.trim();
409
+ if (!id) return;
410
+ setExtra((current) => current.includes(id) ? current : [...current, id]);
411
+ setPicked((current) => new Set(current).add(id));
412
+ setTypedModel("");
413
+ }
414
+ async function submit(test) {
415
+ request.current?.abort();
416
+ const controller = new AbortController();
417
+ request.current = controller;
418
+ setFailure(null);
419
+ setError(null);
420
+ try {
421
+ if (signin && !signedIn) {
422
+ setPhase("signin");
423
+ await api("/api/auth/openai/login", {
424
+ method: "POST",
425
+ signal: controller.signal
426
+ });
427
+ setSignedIn(true);
428
+ }
429
+ setPhase("connecting");
430
+ const body = {
431
+ fields: changedFields(provider, values),
432
+ models: chosen.map((model) => model.id),
433
+ ...test && chosen.length > 0 ? {} : { test: false }
434
+ };
435
+ const result = await api(`/api/config/providers/${encodeURIComponent(provider.id)}/connect`, {
436
+ body,
437
+ signal: controller.signal
438
+ });
439
+ if (controller.signal.aborted) return;
440
+ if (result.connected) await onConnected(result);
441
+ else setFailure(result.failure);
442
+ } catch (cause) {
443
+ if (!controller.signal.aborted) setError(errorMessage(cause));
444
+ } finally {
445
+ if (request.current === controller) setPhase("idle");
446
+ }
447
+ }
448
+ let testNote = "No chat model is ticked, so nothing is tested.";
449
+ if (chosen.length > 0) {
450
+ const target = asked ? modelName(asked) : "a model";
451
+ const rank = asked?.price ? "cheapest" : "first";
452
+ const which = chosen.length > 1 ? `${target}, the ${rank} one ticked` : target;
453
+ testNote = signin && !signedIn ? `After the sign-in, one short message goes to ${which}.` : `The test sends one short message to ${which}.`;
454
+ if (asked?.price && !signin) testNote += " It costs a fraction of a cent.";
455
+ }
456
+ return /* @__PURE__ */ jsxs("form", {
457
+ onSubmit: (event) => {
458
+ event.preventDefault();
459
+ submit(true);
460
+ },
461
+ className: "grid gap-4",
462
+ children: [
463
+ provider.hint && /* @__PURE__ */ jsx("p", {
464
+ className: "m-0 text-sm text-muted-foreground",
465
+ children: provider.hint
466
+ }),
467
+ signin && /* @__PURE__ */ jsx("p", {
468
+ className: "m-0 rounded-xl border border-border bg-muted/40 p-3 text-sm text-muted-foreground",
469
+ children: signedIn ? "You are signed in with ChatGPT. Bazilion renews the sign-in by itself." : "A browser tab opens on the machine Bazilion runs on, and you sign in with your ChatGPT account there. On another machine, run bazilion auth openai login --device-code on it instead."
470
+ }),
471
+ mainFields.map((field, index) => /* @__PURE__ */ jsx(FieldInput, {
472
+ field,
473
+ value: values[field.envVar] ?? "",
474
+ disabled: busy,
475
+ autoFocus: index === 0 && !local,
476
+ onChange: (value) => setValues((current) => ({
477
+ ...current,
478
+ [field.envVar]: value
479
+ })),
480
+ onCommit: local ? () => setLookup(changedLookup(provider, values)) : void 0
481
+ }, field.envVar)),
482
+ advancedFields.length > 0 && /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs("button", {
483
+ type: "button",
484
+ "aria-expanded": showMore,
485
+ onClick: () => setShowMore((open) => !open),
486
+ className: "flex items-center gap-1.5 text-sm font-semibold text-foreground",
487
+ children: [/* @__PURE__ */ jsx(ChevronRight, {
488
+ className: `size-4 text-muted-foreground transition-transform ${showMore ? "rotate-90" : ""}`,
489
+ "aria-hidden": "true"
490
+ }), "More settings"]
491
+ }), showMore && /* @__PURE__ */ jsx("div", {
492
+ className: "mt-2 grid gap-3 rounded-xl border border-border bg-muted/40 p-3",
493
+ children: advancedFields.map((field) => /* @__PURE__ */ jsx(FieldInput, {
494
+ field,
495
+ value: values[field.envVar] ?? "",
496
+ disabled: busy,
497
+ onChange: (value) => setValues((current) => ({
498
+ ...current,
499
+ [field.envVar]: value
500
+ }))
501
+ }, field.envVar))
502
+ })] }),
503
+ /* @__PURE__ */ jsxs("fieldset", {
504
+ className: "m-0 min-w-0 border-0 p-0",
505
+ children: [
506
+ /* @__PURE__ */ jsxs("legend", {
507
+ className: "mb-2 flex w-full flex-wrap items-baseline gap-x-2 p-0",
508
+ children: [/* @__PURE__ */ jsx("span", {
509
+ className: "text-sm font-semibold text-foreground",
510
+ children: "Models your Agents can use"
511
+ }), /* @__PURE__ */ jsx("span", {
512
+ className: "text-xs text-muted-foreground",
513
+ children: local ? "What the server reports. You can change this later." : `${models.length} available. You can change this later.`
514
+ })]
515
+ }),
516
+ local && catalog.data?.listError && /* @__PURE__ */ jsxs("div", {
517
+ className: "mb-2 flex flex-wrap items-center gap-3 rounded-xl border border-warning/35 bg-warning/10 px-3 py-2 text-sm",
518
+ children: [/* @__PURE__ */ jsxs("span", {
519
+ className: "min-w-0 flex-1",
520
+ children: [
521
+ "Nothing answers at ",
522
+ values[mainFields[0]?.envVar ?? ""] || "that address",
523
+ ". Start",
524
+ " ",
525
+ provider.displayName,
526
+ " and switch its server on."
527
+ ]
528
+ }), /* @__PURE__ */ jsx(Button, {
529
+ variant: "ghost",
530
+ disabled: catalog.loading,
531
+ onClick: () => {
532
+ setLookup(changedLookup(provider, values));
533
+ catalog.reload();
534
+ },
535
+ children: catalog.loading ? "Looking…" : "Look again"
536
+ })]
537
+ }),
538
+ browsing && models.length > 8 && /* @__PURE__ */ jsx(SearchField, {
539
+ label: `Search ${provider.displayName} models`,
540
+ placeholder: "Search by name",
541
+ value: query,
542
+ onChange: setQuery,
543
+ className: "mb-2"
544
+ }),
545
+ browsing && models.length > 8 && chosen.length > 0 && /* @__PURE__ */ jsxs("div", {
546
+ className: "mb-2 flex flex-wrap items-center gap-1.5 text-xs",
547
+ children: [/* @__PURE__ */ jsx("span", {
548
+ className: "text-muted-foreground",
549
+ children: "Ticked:"
550
+ }), chosen.map((model) => /* @__PURE__ */ jsxs("button", {
551
+ type: "button",
552
+ disabled: busy,
553
+ onClick: () => toggle(model.id),
554
+ "aria-label": `Untick ${modelName(model)}`,
555
+ className: "inline-flex items-center gap-1 rounded-full bg-accent px-2.5 py-1 font-semibold text-accent-foreground",
556
+ children: [modelName(model), /* @__PURE__ */ jsx(X, {
557
+ className: "size-3",
558
+ "aria-hidden": "true"
559
+ })]
560
+ }, model.id))]
561
+ }),
562
+ /* @__PURE__ */ jsxs("div", {
563
+ className: "max-h-72 overflow-y-auto rounded-xl border border-border",
564
+ children: [
565
+ catalog.loading && !catalog.data && /* @__PURE__ */ jsx("div", {
566
+ className: "p-3 text-sm text-muted-foreground",
567
+ children: "Reading the model list…"
568
+ }),
569
+ catalog.error && /* @__PURE__ */ jsx("div", {
570
+ className: "p-3 text-sm text-danger",
571
+ children: catalog.error
572
+ }),
573
+ catalog.data && rows.length === 0 && /* @__PURE__ */ jsx("div", {
574
+ className: "p-3 text-sm text-muted-foreground",
575
+ children: query ? "No model matches." : local ? "The server lists no model yet." : "No models are listed for this provider. Add one by its id below."
576
+ }),
577
+ rows.map((model) => /* @__PURE__ */ jsx(ModelRow, {
578
+ model,
579
+ connect: provider.connect,
580
+ checked: picks.has(model.id),
581
+ disabled: busy,
582
+ onToggle: () => toggle(model.id),
583
+ className: "px-3 last:border-b-0"
584
+ }, model.id)),
585
+ matching.length > rows.length && /* @__PURE__ */ jsxs("div", {
586
+ className: "p-3 text-xs text-muted-foreground",
587
+ children: [matching.length - rows.length, " more: search to narrow them down."]
588
+ })
589
+ ]
590
+ }),
591
+ /* @__PURE__ */ jsxs("div", {
592
+ className: "mt-2 flex flex-wrap items-center gap-x-4 gap-y-2",
593
+ children: [!browsing && models.length > shortlist.length && /* @__PURE__ */ jsxs("button", {
594
+ type: "button",
595
+ onClick: () => setShowAll(true),
596
+ className: "text-sm font-semibold text-primary",
597
+ children: ["See all ", models.length]
598
+ }), browsing && !local && /* @__PURE__ */ jsxs("span", {
599
+ className: "flex min-w-0 flex-1 basis-64 items-center gap-2",
600
+ children: [/* @__PURE__ */ jsx("input", {
601
+ type: "text",
602
+ "aria-label": "A model id that is not listed",
603
+ placeholder: "A model id that is not listed",
604
+ value: typedModel,
605
+ disabled: busy,
606
+ onChange: (event) => setTypedModel(event.target.value),
607
+ onKeyDown: (event) => {
608
+ if (event.key === "Enter") {
609
+ event.preventDefault();
610
+ addTyped();
611
+ }
612
+ },
613
+ className: "min-h-10 font-mono text-sm"
614
+ }), /* @__PURE__ */ jsx(Button, {
615
+ variant: "ghost",
616
+ disabled: busy || !typedModel.trim(),
617
+ onClick: addTyped,
618
+ children: "Add"
619
+ })]
620
+ })]
621
+ })
622
+ ]
623
+ }),
624
+ imageRoutes.length > 0 && /* @__PURE__ */ jsxs("p", {
625
+ className: "m-0 flex items-start gap-2 text-sm text-muted-foreground",
626
+ children: [/* @__PURE__ */ jsx(Images, {
627
+ className: "mt-0.5 size-4 shrink-0 text-accent-foreground",
628
+ "aria-hidden": "true"
629
+ }), /* @__PURE__ */ jsxs("span", { children: [
630
+ signin ? "The same sign-in" : "The same key",
631
+ " makes",
632
+ " ",
633
+ [...new Set(imageRoutes.map((route) => route.model))].join(" and "),
634
+ " available under Images."
635
+ ] })]
636
+ }),
637
+ /* @__PURE__ */ jsxs("div", {
638
+ ref: outcome,
639
+ className: "grid gap-3 empty:hidden",
640
+ children: [failure && /* @__PURE__ */ jsx(FailureBox, { failure }), error && /* @__PURE__ */ jsx("p", {
641
+ role: "alert",
642
+ className: "m-0 rounded-xl bg-danger/10 px-3 py-2 text-sm text-danger",
643
+ children: error
644
+ })]
645
+ }),
646
+ busy ? /* @__PURE__ */ jsx(Waiting, { children: phase === "signin" ? "Waiting for the ChatGPT sign-in in the browser…" : asked ? `Asking ${modelName(asked)} for a short reply…` : "Saving…" }) : /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs("div", {
647
+ className: "flex flex-wrap items-center gap-x-4 gap-y-2",
648
+ children: [/* @__PURE__ */ jsx(Button, {
649
+ variant: "primary",
650
+ type: "submit",
651
+ disabled: !credentialsReady || local && chosen.length === 0,
652
+ children: signin && !signedIn ? "Sign in with ChatGPT" : chosen.length === 0 ? "Connect" : "Connect and test"
653
+ }), chosen.length > 0 && !(signin && !signedIn) && /* @__PURE__ */ jsx("button", {
654
+ type: "button",
655
+ disabled: !credentialsReady,
656
+ onClick: () => void submit(false),
657
+ className: "text-sm font-semibold text-primary disabled:opacity-50",
658
+ children: "Save without testing"
659
+ })]
660
+ }), /* @__PURE__ */ jsx("p", {
661
+ className: "m-0 mt-2 text-xs text-muted-foreground",
662
+ children: testNote
663
+ })] })
664
+ ]
665
+ });
666
+ }
667
+ /** The config fields being typed, for asking a local server at an address that is not saved. */
668
+ function changedLookup(provider, values) {
669
+ if (provider.connect !== "local") return {};
670
+ const changed = changedFields(provider, values);
671
+ return Object.fromEntries(Object.entries(changed).filter(([name]) => provider.fields.some((field) => field.envVar === name && field.kind === "config")));
672
+ }
673
+ function FieldInput({ field, value, disabled, autoFocus = false, onChange, onCommit }) {
674
+ const secret = field.kind === "secret";
675
+ return /* @__PURE__ */ jsxs("label", {
676
+ className: "m-0 text-sm font-semibold text-foreground",
677
+ children: [
678
+ field.label,
679
+ /* @__PURE__ */ jsx("input", {
680
+ type: secret ? "password" : "text",
681
+ value,
682
+ disabled,
683
+ autoFocus,
684
+ autoComplete: "off",
685
+ spellCheck: false,
686
+ placeholder: secret && field.set ? "Saved. Paste another to replace it." : field.placeholder ?? "",
687
+ onChange: (event) => onChange(event.target.value),
688
+ onBlur: onCommit,
689
+ onKeyDown: (event) => {
690
+ if (event.key === "Enter" && onCommit) {
691
+ event.preventDefault();
692
+ onCommit();
693
+ }
694
+ },
695
+ className: "mt-1.5 font-mono font-normal"
696
+ }),
697
+ (field.description || secret) && /* @__PURE__ */ jsx("span", {
698
+ className: "mt-1 block text-xs font-normal text-muted-foreground",
699
+ children: field.description ?? "Stored encrypted on the machine Bazilion runs on. It is never shown again."
700
+ })
701
+ ]
702
+ });
703
+ }
704
+ //#endregion
705
+ //#region src/components/setup/AddProviderDialog.tsx
706
+ /** A local server's address without the scheme and path: what a person recognises. */
707
+ function hostOf(address) {
708
+ try {
709
+ return new URL(address).host;
710
+ } catch {
711
+ return address;
712
+ }
713
+ }
714
+ function localLine(server, looking) {
715
+ if (!server) return looking ? "Looking…" : "A model server on this computer";
716
+ if (!server.found) return `Nothing at ${hostOf(server.address)}`;
717
+ const count = server.models.length;
718
+ return `Running at ${hostOf(server.address)}, ${count === 1 ? "1 model" : `${count} models`}`;
719
+ }
720
+ function matches(provider, query) {
721
+ const needle = query.trim().toLowerCase();
722
+ if (!needle) return true;
723
+ return [
724
+ provider.displayName,
725
+ provider.id,
726
+ provider.hint ?? ""
727
+ ].some((text) => text.toLowerCase().includes(needle));
728
+ }
729
+ /** Every provider, the most used and the local ones first; `onPick` opens the next step. */
730
+ function ProviderChooser({ providers, expanded = false, onPick }) {
731
+ const [query, setQuery] = useState("");
732
+ const [showMore, setShowMore] = useState(expanded);
733
+ const local = useResource((signal) => api("/api/config/providers/local", { signal }), []);
734
+ const now = useMemo(() => Date.now(), []);
735
+ const visible = providers.filter((provider) => matches(provider, query));
736
+ const group = (name) => visible.filter((provider) => provider.group === name);
737
+ const more = group("more");
738
+ const searching = query.trim().length > 0;
739
+ const tile = (provider) => {
740
+ const server = local.data?.servers.find((entry) => entry.id === provider.id);
741
+ const found = provider.group === "local" && server?.found;
742
+ const sub = provider.listed ? providerStatus(provider, now).label : provider.group === "local" ? localLine(server, local.loading) : provider.hint ?? provider.id;
743
+ return /* @__PURE__ */ jsxs("button", {
744
+ type: "button",
745
+ onClick: () => onPick(provider),
746
+ className: "flex min-h-16 min-w-0 items-center gap-3 rounded-2xl border border-border bg-card px-3.5 py-2.5 text-left transition-colors hover:border-primary/40 hover:bg-accent/40",
747
+ children: [
748
+ /* @__PURE__ */ jsx(ProviderAvatar, {
749
+ name: provider.displayName,
750
+ tone: provider.listed || found ? "success" : "neutral"
751
+ }),
752
+ /* @__PURE__ */ jsxs("span", {
753
+ className: "min-w-0 flex-1",
754
+ children: [/* @__PURE__ */ jsx("span", {
755
+ className: "block truncate text-sm font-semibold text-foreground",
756
+ children: provider.displayName
757
+ }), /* @__PURE__ */ jsx("span", {
758
+ className: `line-clamp-2 text-xs leading-snug ${provider.listed || found ? "text-success" : "text-muted-foreground"}`,
759
+ children: sub
760
+ })]
761
+ }),
762
+ provider.listed ? /* @__PURE__ */ jsx(Check, {
763
+ className: "size-4 shrink-0 text-success",
764
+ "aria-hidden": "true"
765
+ }) : /* @__PURE__ */ jsx(ChevronRight, {
766
+ className: "size-4 shrink-0 text-muted-foreground",
767
+ "aria-hidden": "true"
768
+ })
769
+ ]
770
+ }, provider.id);
771
+ };
772
+ const section = (title, entries) => entries.length > 0 && /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h3", {
773
+ className: "m-0 mb-2 font-body text-[0.72rem] font-bold uppercase tracking-[0.08em] text-muted-foreground",
774
+ children: title
775
+ }), /* @__PURE__ */ jsx("div", {
776
+ className: "grid gap-2 sm:grid-cols-2",
777
+ children: entries.map(tile)
778
+ })] });
779
+ return /* @__PURE__ */ jsxs("div", {
780
+ className: "grid gap-4",
781
+ children: [
782
+ /* @__PURE__ */ jsx(SearchField, {
783
+ label: "Search providers",
784
+ placeholder: `Search ${providers.length} providers`,
785
+ value: query,
786
+ onChange: setQuery
787
+ }),
788
+ section("Most used", group("popular")),
789
+ section("On this computer", group("local")),
790
+ (searching || showMore) && section("More", more),
791
+ visible.length === 0 && /* @__PURE__ */ jsxs("p", {
792
+ className: "m-0 text-sm text-muted-foreground",
793
+ children: [
794
+ "No provider matches “",
795
+ query,
796
+ "”."
797
+ ]
798
+ }),
799
+ !searching && !showMore && more.length > 0 && /* @__PURE__ */ jsxs("button", {
800
+ type: "button",
801
+ onClick: () => setShowMore(true),
802
+ className: "justify-self-start text-sm font-semibold text-primary",
803
+ children: [
804
+ "Show ",
805
+ more.length,
806
+ " more:",
807
+ " ",
808
+ more.slice(0, 4).map((provider) => provider.displayName).join(", "),
809
+ "…"
810
+ ]
811
+ })
812
+ ]
813
+ });
814
+ }
815
+ /** What a finished connect says: who answered, what was added, what was left out. */
816
+ function ConnectedSummary({ result, imageRoutes }) {
817
+ const { provider, check, dropped, movedTemplates } = result;
818
+ const count = provider.models.length;
819
+ const images = [...new Set(imageRoutes.map((route) => route.model))];
820
+ return /* @__PURE__ */ jsxs("div", {
821
+ role: "status",
822
+ className: "flex items-start gap-4",
823
+ children: [/* @__PURE__ */ jsx("span", {
824
+ "aria-hidden": "true",
825
+ className: `flex size-11 shrink-0 items-center justify-center rounded-full ${check ? "bg-success/10 text-success" : "bg-muted text-muted-foreground"}`,
826
+ children: /* @__PURE__ */ jsx(Check, { className: "size-6" })
827
+ }), /* @__PURE__ */ jsxs("div", {
828
+ className: "min-w-0 flex-1 text-sm",
829
+ children: [/* @__PURE__ */ jsx("div", {
830
+ className: "text-base font-semibold text-foreground",
831
+ children: check ? `${provider.displayName} is connected` : `${provider.displayName} is saved, not tested`
832
+ }), /* @__PURE__ */ jsxs("ul", {
833
+ className: "m-0 mt-1 list-none space-y-0.5 p-0 text-muted-foreground",
834
+ children: [
835
+ check && /* @__PURE__ */ jsxs("li", { children: [
836
+ check.modelName ?? check.model,
837
+ " answered in ",
838
+ ((check.ms ?? 0) / 1e3).toFixed(1),
839
+ " s."
840
+ ] }),
841
+ /* @__PURE__ */ jsxs("li", { children: [count === 0 ? "No chat model is in use from it." : count === 1 ? "1 model is in Chat." : `${count} models are in Chat.`, !check && count > 0 && " Test it from its row before you rely on it."] }),
842
+ dropped.map((entry) => /* @__PURE__ */ jsxs("li", {
843
+ className: "text-warning",
844
+ children: [entry.model, " was left out: this account cannot use it."]
845
+ }, entry.model)),
846
+ images.length > 0 && /* @__PURE__ */ jsxs("li", { children: [images.join(" and "), " can now be chosen under Images."] }),
847
+ movedTemplates.map((template) => /* @__PURE__ */ jsxs("li", { children: [
848
+ "The ",
849
+ template.name,
850
+ " template now uses ",
851
+ template.model,
852
+ "."
853
+ ] }, template.id))
854
+ ]
855
+ })]
856
+ })]
857
+ });
858
+ }
859
+ /** "Add a provider": choose one, connect it, see that it answered. */
860
+ function AddProviderDialog({ providers, imageRoutes, start, onClose, onConnected, onOpenProvider }) {
861
+ const [chosen, setChosen] = useState(start && providers.some((provider) => provider.id === start) ? start : null);
862
+ const [done, setDone] = useState(null);
863
+ const provider = providers.find((entry) => entry.id === chosen) ?? null;
864
+ const routesOf = (id) => imageRoutes.filter((route) => route.provider === id);
865
+ if (done) return /* @__PURE__ */ jsxs(Dialog, {
866
+ title: done.provider.displayName,
867
+ onClose,
868
+ className: "max-w-xl",
869
+ children: [/* @__PURE__ */ jsx(ConnectedSummary, {
870
+ result: done,
871
+ imageRoutes: routesOf(done.provider.id)
872
+ }), /* @__PURE__ */ jsx(DialogActions, { children: /* @__PURE__ */ jsx(Button, {
873
+ variant: "primary",
874
+ onClick: onClose,
875
+ children: "Done"
876
+ }) })]
877
+ });
878
+ if (provider) return /* @__PURE__ */ jsxs(Dialog, {
879
+ title: `Connect ${provider.displayName}`,
880
+ onClose,
881
+ className: "top-[6dvh] max-h-[88dvh] max-w-2xl translate-y-0 content-start",
882
+ children: [!start && /* @__PURE__ */ jsxs("button", {
883
+ type: "button",
884
+ onClick: () => setChosen(null),
885
+ className: "-mt-1 flex items-center gap-1 justify-self-start text-sm font-semibold text-primary",
886
+ children: [/* @__PURE__ */ jsx(ArrowLeft, {
887
+ className: "size-4",
888
+ "aria-hidden": "true"
889
+ }), "All providers"]
890
+ }), /* @__PURE__ */ jsx(ProviderConnect, {
891
+ provider,
892
+ imageRoutes: routesOf(provider.id).filter((route) => !route.ready),
893
+ onConnected: async (result) => {
894
+ await onConnected();
895
+ setDone(result);
896
+ }
897
+ }, provider.id)]
898
+ });
899
+ return /* @__PURE__ */ jsx(Dialog, {
900
+ title: "Add a provider",
901
+ onClose,
902
+ className: "top-[6dvh] max-h-[88dvh] max-w-2xl translate-y-0 content-start",
903
+ children: /* @__PURE__ */ jsx(ProviderChooser, {
904
+ providers,
905
+ onPick: (picked) => picked.listed ? onOpenProvider(picked.id) : setChosen(picked.id)
906
+ })
907
+ });
908
+ }
909
+ //#endregion
910
+ export { usedByLine as S, factsLine as _, ProviderConnect as a, priceLine as b, ModelRow as c, SetupCard as d, StateChip as f, credentialLine as g, ago as h, hostOf as i, ProviderAvatar as l, Waiting as m, ConnectedSummary as n, Chip as o, Switch as p, ProviderChooser as r, FailureBox as s, AddProviderDialog as t, SearchField as u, matchesModel as v, providerStatus as x, modelName as y };