bazilion 0.51.0 → 0.53.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 (205) hide show
  1. package/dist/cli.js +74 -28
  2. package/dist/cli.js.map +1 -1
  3. package/dist/daemon.js +547 -187
  4. package/dist/daemon.js.map +1 -1
  5. package/dist/web/client/assets/AddProviderDialog-CO_uijWF.js +1 -0
  6. package/dist/web/client/assets/AgentTemplateParts-Dl35c-Ux.js +1 -0
  7. package/dist/web/client/assets/ConfigPage-DiQiJXP6.js +1 -0
  8. package/dist/web/client/assets/ConfirmDialog-BVytx3kN.js +1 -0
  9. package/dist/web/client/assets/ConnectionsView-DDrBaiLg.js +1 -0
  10. package/dist/web/client/assets/Dialog-BTDzv3J5.js +1 -0
  11. package/dist/web/client/assets/ManagePage-xlePXXx5.js +1 -0
  12. package/dist/web/client/assets/SectionTabs-BMiRKFfb.js +1 -0
  13. package/dist/web/client/assets/Segmented-Co4n2C5X.js +1 -0
  14. package/dist/web/client/assets/SpawnDialog-ejwXnyxy.js +1 -0
  15. package/dist/web/client/assets/SpawnTeamModal-Cp-nAvIC.js +1 -0
  16. package/dist/web/client/assets/TeamForm-Cz9uDVvb.js +1 -0
  17. package/dist/web/client/assets/TeamThread-D8xqE_gb.js +1 -0
  18. package/dist/web/client/assets/UnsavedChangesGuard-DmT4nBQU.js +1 -0
  19. package/dist/web/client/assets/_id-DEQxwq2v.js +1 -0
  20. package/dist/web/client/assets/_id-DSRgpxEc.js +1 -0
  21. package/dist/web/client/assets/access-34_ShgHU.js +1 -0
  22. package/dist/web/client/assets/agent-actions--EO4yJ4Q.js +1 -0
  23. package/dist/web/client/assets/agents-C87yBHaR.js +1 -0
  24. package/dist/web/client/assets/agents-DvCSl1Ro.js +1 -0
  25. package/dist/web/client/assets/api-CoLs57oO.js +1 -0
  26. package/dist/web/client/assets/arrow-right-BhTWtC9z.js +1 -0
  27. package/dist/web/client/assets/attention-CteEeRvX.js +1 -0
  28. package/dist/web/client/assets/chevron-right-BqOIX9UM.js +1 -0
  29. package/dist/web/client/assets/config-XJuQeEP4.js +1 -0
  30. package/dist/web/client/assets/createLucideIcon-dN8ooBD1.js +1 -0
  31. package/dist/web/client/assets/download-Dj-1ltZb.js +1 -0
  32. package/dist/web/client/assets/file-text-DiP-LaEg.js +1 -0
  33. package/dist/web/client/assets/form-Bvr_f9lR.js +1 -0
  34. package/dist/web/client/assets/images-BKjyhYUc.js +1 -0
  35. package/dist/web/client/assets/index-J_Uqj4md.js +54 -0
  36. package/dist/web/client/assets/key-round-QpqZklz6.js +1 -0
  37. package/dist/web/client/assets/list-checks-BeyG5SVQ.js +1 -0
  38. package/dist/web/client/assets/login-076Bc601.js +1 -0
  39. package/dist/web/client/assets/manage-CsrV2hhK.js +1 -0
  40. package/dist/web/client/assets/mcp-8N0BqZ0G.js +1 -0
  41. package/dist/web/client/assets/message-square-DnpSOYv4.js +1 -0
  42. package/dist/web/client/assets/model-facts-DoB6QD5y.js +1 -0
  43. package/dist/web/client/assets/network-BC7rNaOC.js +1 -0
  44. package/dist/web/client/assets/parts-B0JBolvG.js +1 -0
  45. package/dist/web/client/assets/plus-DZ3KVo7E.js +1 -0
  46. package/dist/web/client/assets/routes-3HkZZOOe.js +76 -0
  47. package/dist/web/client/assets/skills-DiaqZRXT.js +1 -0
  48. package/dist/web/client/assets/square-terminal-hQZ6pexU.js +1 -0
  49. package/dist/web/client/assets/style-BtcFIkOS.js +7 -0
  50. package/dist/web/client/assets/styles-C7Ztw15K.css +2 -0
  51. package/dist/web/client/assets/system-YWlJ8ogO.js +1 -0
  52. package/dist/web/client/assets/teams-DQwceMvk.js +1 -0
  53. package/dist/web/client/assets/teams-DTC3plIH.js +1 -0
  54. package/dist/web/client/assets/telegram-D4wINntt.js +1 -0
  55. package/dist/web/client/assets/tools-CZeQ9pDx.js +1 -0
  56. package/dist/web/client/assets/use-resource-BaTkTGvG.js +1 -0
  57. package/dist/web/client/assets/welcome-CnxP_RCk.js +1 -0
  58. package/dist/web/client/assets/wrench-BrwBswfo.js +1 -0
  59. package/dist/web/server/assets/{AddProviderDialog-CR6TRYdZ.js → AddProviderDialog-Di5crZUB.js} +9 -205
  60. package/dist/web/server/assets/AgentTemplateParts-Cqy7kSzx.js +269 -0
  61. package/dist/web/server/assets/{ConfigPage-CIh3ohea.js → ConfigPage-oXM3wyOU.js} +2 -2
  62. package/dist/web/server/assets/{ConfirmDialog-B79K2KEW.js → ConfirmDialog-DfaJ--A6.js} +2 -2
  63. package/dist/web/server/assets/{ConnectionsView-BIMYdp9C.js → ConnectionsView-DZrLoNoW.js} +7 -7
  64. package/dist/web/server/assets/{Dialog-CVqpXxuN.js → Dialog-aup_yJv5.js} +1 -1
  65. package/dist/web/server/assets/ManagePage-0LKHEcT_.js +29 -0
  66. package/dist/web/server/assets/ModelMenu-BAZeARx6.js +138 -0
  67. package/dist/web/server/assets/{Rail-Cg-efcpA.js → Rail-7JU6ly2O.js} +17 -107
  68. package/dist/web/server/assets/{SectionTabs-DrcgVeZd.js → SectionTabs-CWQ5orUW.js} +12 -5
  69. package/dist/web/server/assets/SpawnDialog-CYkwzETs.js +124 -0
  70. package/dist/web/server/assets/SpawnTeamModal-CCe6P82H.js +127 -0
  71. package/dist/web/server/assets/TeamForm-BzQmdhVi.js +141 -0
  72. package/dist/web/server/assets/{TeamThread-5CjVPcDr.js → TeamThread-SyQpUvz5.js} +3 -3
  73. package/dist/web/server/assets/{UnsavedChangesGuard-CyF2Z9p1.js → UnsavedChangesGuard-DrOvPV14.js} +1 -1
  74. package/dist/web/server/assets/_id-AcyGvFrE.js +400 -0
  75. package/dist/web/server/assets/{_id-8bsYEcGg.js → _id-BGTgqsWm.js} +8 -4
  76. package/dist/web/server/assets/{_id-TVruGcOd.js → _id-BKzOw78O.js} +11 -3
  77. package/dist/web/server/assets/{_id-0fEWiVZX.js → _id-DPGzfmjG.js} +258 -206
  78. package/dist/web/server/assets/_id-DXm9W55C.js +16 -0
  79. package/dist/web/server/assets/_id-DojvxRZn.js +39 -0
  80. package/dist/web/server/assets/_tanstack-start-manifest_v-D7RvKGRH.js +285 -0
  81. package/dist/web/server/assets/{tokens-C-oDTqnp.js → access-BJe-NduL.js} +5 -5
  82. package/dist/web/server/assets/access-CKSW7MFH.js +297 -0
  83. package/dist/web/server/assets/{tokens-CEdl8puR.js → access-WWspT0v4.js} +5 -4
  84. package/dist/web/server/assets/agent-actions-CUDMCG0F.js +20 -0
  85. package/dist/web/server/assets/agents-1sjSvp5p.js +12 -0
  86. package/dist/web/server/assets/{agents-BnWgFo6o.js → agents-6d9WxbYF.js} +9 -6
  87. package/dist/web/server/assets/agents-DKVGUwD1.js +31 -0
  88. package/dist/web/server/assets/agents-DUI4Yjtg.js +13 -0
  89. package/dist/web/server/assets/agents-DsHeRaLq.js +327 -0
  90. package/dist/web/server/assets/agents-DtLDoZ_u.js +136 -0
  91. package/dist/web/server/assets/{attention-Cr7puThv.js → attention-B6sSDR_4.js} +2 -1
  92. package/dist/web/server/assets/{attention-CHQEQiZl.js → attention-DefKwvgm.js} +2 -2
  93. package/dist/web/server/assets/attention-johfkM0_.js +203 -0
  94. package/dist/web/server/assets/{config-DOp28gcy.js → config-Clz57LuN.js} +186 -87
  95. package/dist/web/server/assets/{config-DzgkbBoD.js → config-DYAaaE9Z.js} +2 -2
  96. package/dist/web/server/assets/{createSsrRpc-CcLbajrF.js → createSsrRpc-BijMHgqE.js} +2 -46
  97. package/dist/web/server/assets/form-BRQAsKKq.js +319 -0
  98. package/dist/web/server/assets/manage-Ppyi3Y5y.js +230 -0
  99. package/dist/web/server/assets/mcp-Ce6O8Qs2.js +378 -0
  100. package/dist/web/server/assets/{mcp-D3OCoHtO.js → mcp-DB38leWS.js} +2 -2
  101. package/dist/web/server/assets/model-facts-mrfrWQne.js +136 -0
  102. package/dist/web/server/assets/parts-mabERIJZ.js +380 -0
  103. package/dist/web/server/assets/{router-Cs2Ak4II.js → router-C97bwlXi.js} +55 -50
  104. package/dist/web/server/assets/{routes-BSNOKE-C.js → routes-C4aGqXfr.js} +65 -17
  105. package/dist/web/server/assets/{routes-CO4l-GJ0.js → routes-DuOShl4q.js} +2 -2
  106. package/dist/web/server/assets/{routes-BVwqgZGI.js → routes-IHMVKpDK.js} +3 -3
  107. package/dist/web/server/assets/{skills-CggQJk6a.js → skills-B7sg0QKS.js} +2 -2
  108. package/dist/web/server/assets/{skills-h5aHa7Q8.js → skills-DWzlT_hC.js} +9 -1
  109. package/dist/web/server/assets/skills-hfTSwqsG.js +353 -0
  110. package/dist/web/server/assets/{style-GYDODk2F.js → style-BR7ufS6Z.js} +1 -1
  111. package/dist/web/server/assets/system-CNQpt3JB.js +145 -0
  112. package/dist/web/server/assets/{system-DtswhLW62.js → system-D3th6n2E.js} +4 -2
  113. package/dist/web/server/assets/{system-DsJfpBPl.js → system-DaP0ol67.js} +2 -2
  114. package/dist/web/server/assets/{teams-B6lBhvdL.js → teams-4cEZ4_rw.js} +4 -2
  115. package/dist/web/server/assets/{teams-BxnvFTyn.js → teams-70u1XQTr.js} +1 -3
  116. package/dist/web/server/assets/teams-BKHe67f3.js +176 -0
  117. package/dist/web/server/assets/{teams-YrmyutM4.js → teams-BopOP4x7.js} +8 -1
  118. package/dist/web/server/assets/teams-C3xwTz8-.js +219 -0
  119. package/dist/web/server/assets/{teams-Bp2tERZe.js → teams-CuKE5iAK.js} +2 -2
  120. package/dist/web/server/assets/{telegram-D2RZriz_.js → telegram-BnQADwnj.js} +5 -5
  121. package/dist/web/server/assets/telegram-BpmK-HHV.js +1059 -0
  122. package/dist/web/server/assets/{telegram-Gy7_9yih.js → telegram-CGol0CKX.js} +3 -3
  123. package/dist/web/server/assets/tools-BQeWn7Tj.js +12 -0
  124. package/dist/web/server/assets/tools-C-wwWjLI.js +12 -0
  125. package/dist/web/server/assets/tools-CURTfG2q.js +341 -0
  126. package/dist/web/server/assets/{use-resource-ChQozXVI.js → use-resource-DVzK0toP.js} +1 -1
  127. package/dist/web/server/assets/utils-C_uf36nf.js +8 -0
  128. package/dist/web/server/assets/{welcome-BLw1G6SS.js → welcome-OiZCAIHZ.js} +5 -5
  129. package/dist/web/server/assets/{welcome-ByAkvHSP.js → welcome-SNsE49JO.js} +2 -2
  130. package/dist/web/server/assets/{workspace-DeEYMPDX.js → workspace-DaitCM0t.js} +1 -8
  131. package/dist/web/server/server.js +30 -30
  132. package/dist/worker.js +202 -120
  133. package/dist/worker.js.map +1 -1
  134. package/package.json +1 -1
  135. package/dist/web/client/assets/AddProviderDialog-Diic36c_.js +0 -1
  136. package/dist/web/client/assets/ConfigPage-pupvtSCX.js +0 -1
  137. package/dist/web/client/assets/ConfirmDialog-GFDcHI1L.js +0 -1
  138. package/dist/web/client/assets/ConnectionsView-y1CeY-6U.js +0 -1
  139. package/dist/web/client/assets/Dialog-bg86_x4v.js +0 -1
  140. package/dist/web/client/assets/FieldRow-B8eIni5r.js +0 -1
  141. package/dist/web/client/assets/ModelSelect-DvCLUmkW.js +0 -1
  142. package/dist/web/client/assets/SectionTabs-D4ezA6U4.js +0 -1
  143. package/dist/web/client/assets/Segmented-Dh77vmpp.js +0 -1
  144. package/dist/web/client/assets/SkillFindings-BzLO1lNA.js +0 -1
  145. package/dist/web/client/assets/SkillsPicker-hI3YXvib.js +0 -1
  146. package/dist/web/client/assets/SpawnDialog-YJX6UMBC.js +0 -1
  147. package/dist/web/client/assets/Tabs-f6bHvCGn.js +0 -1
  148. package/dist/web/client/assets/TeamForm-kda1HYZG.js +0 -1
  149. package/dist/web/client/assets/TeamThread-DFvbakHo.js +0 -1
  150. package/dist/web/client/assets/UnsavedChangesGuard-DBJikVgc.js +0 -1
  151. package/dist/web/client/assets/_id-BjNtLwak.js +0 -1
  152. package/dist/web/client/assets/_id-BklaQf3z.js +0 -1
  153. package/dist/web/client/assets/agents-D9cUF2d9.js +0 -1
  154. package/dist/web/client/assets/agents-wuBlzx4e.js +0 -1
  155. package/dist/web/client/assets/api-HC_YzjBy.js +0 -1
  156. package/dist/web/client/assets/arrow-right-Gm_FDWJ_.js +0 -1
  157. package/dist/web/client/assets/attention-8ZkSLl2e.js +0 -1
  158. package/dist/web/client/assets/check-BjgKoGvU.js +0 -1
  159. package/dist/web/client/assets/config-Con_BbSh.js +0 -1
  160. package/dist/web/client/assets/createLucideIcon-C6gOo8sD.js +0 -1
  161. package/dist/web/client/assets/index-Br9qkGM-.js +0 -54
  162. package/dist/web/client/assets/link-Cbztlp_R.js +0 -1
  163. package/dist/web/client/assets/login-llnOKSJc.js +0 -1
  164. package/dist/web/client/assets/mcp-zIUguMSI.js +0 -1
  165. package/dist/web/client/assets/plus-CWrKMtvA.js +0 -1
  166. package/dist/web/client/assets/routes-BY5uqJ2n.js +0 -76
  167. package/dist/web/client/assets/save-f9O-CQia.js +0 -1
  168. package/dist/web/client/assets/services-esLrcTwe.js +0 -1
  169. package/dist/web/client/assets/skills-DzYXksM0.js +0 -1
  170. package/dist/web/client/assets/style-Cdzqt_TJ.js +0 -7
  171. package/dist/web/client/assets/styles-BRSS6yrm.css +0 -2
  172. package/dist/web/client/assets/system-CsI66nyZ.js +0 -1
  173. package/dist/web/client/assets/teams-CHE_zpxS.js +0 -1
  174. package/dist/web/client/assets/teams-dxG9OESG.js +0 -1
  175. package/dist/web/client/assets/telegram-C3dGndJV.js +0 -1
  176. package/dist/web/client/assets/tokens-CNNH-Wr9.js +0 -1
  177. package/dist/web/client/assets/use-resource-BjnxgGvh.js +0 -1
  178. package/dist/web/client/assets/welcome-C8EOtc8P.js +0 -1
  179. package/dist/web/server/assets/FieldRow-CHVhX2rS.js +0 -173
  180. package/dist/web/server/assets/ModelSelect-DrZrdndo.js +0 -43
  181. package/dist/web/server/assets/SkillFindings-DSDiL6hn.js +0 -46
  182. package/dist/web/server/assets/SkillsPicker-DlqEfRWh.js +0 -67
  183. package/dist/web/server/assets/SpawnDialog-BUUlLxE9.js +0 -129
  184. package/dist/web/server/assets/Tabs-BhF41MfQ.js +0 -20
  185. package/dist/web/server/assets/TeamForm-CvQAs2FA.js +0 -96
  186. package/dist/web/server/assets/_id-BvAaRSUW.js +0 -18
  187. package/dist/web/server/assets/_id-Dg6M_qfr.js +0 -383
  188. package/dist/web/server/assets/_id-Dji7xr9C.js +0 -28
  189. package/dist/web/server/assets/_tanstack-start-manifest_v-sxiIH4M7.js +0 -214
  190. package/dist/web/server/assets/agents-BDA5yYZ2.js +0 -130
  191. package/dist/web/server/assets/agents-BTDxmp-F.js +0 -12
  192. package/dist/web/server/assets/agents-DM7guWF2.js +0 -14
  193. package/dist/web/server/assets/agents-DktqUffG.js +0 -327
  194. package/dist/web/server/assets/agents-xgZ9rsac.js +0 -27
  195. package/dist/web/server/assets/attention-De3-ehuf.js +0 -216
  196. package/dist/web/server/assets/mcp-CO_tycXU.js +0 -250
  197. package/dist/web/server/assets/services-DZLxUSG8.js +0 -13
  198. package/dist/web/server/assets/services-DsHRLL8q.js +0 -12
  199. package/dist/web/server/assets/services-DsvpaF3L.js +0 -74
  200. package/dist/web/server/assets/skills-DKYV7PTk.js +0 -275
  201. package/dist/web/server/assets/system-CZ2qzBz3.js +0 -138
  202. package/dist/web/server/assets/teams-B6PzNcoy.js +0 -88
  203. package/dist/web/server/assets/teams-C-8iz-uV.js +0 -108
  204. package/dist/web/server/assets/telegram-CXrP3hMp.js +0 -984
  205. package/dist/web/server/assets/tokens-DSLwQ1Pw.js +0 -232
@@ -0,0 +1,1059 @@
1
+ import { C as api, T as errorMessage, u as Button } from "./workspace-DaitCM0t.js";
2
+ import { r as useResource } from "./use-resource-DVzK0toP.js";
3
+ import { t as ConfirmDialog } from "./ConfirmDialog-DfaJ--A6.js";
4
+ import { t as ago } from "./model-facts-mrfrWQne.js";
5
+ import { a as CardForm, d as Chip, f as Fact, g as Notice, h as ListRow, l as CheckItem, o as CardList, p as Facts, r as CardBody, s as CardRow, t as Banner, u as CheckList, x as Waiting, y as SetupCard } from "./parts-mabERIJZ.js";
6
+ import { a as SaveBar, c as SwitchRow, i as Problem, l as TextField, o as SecretField, t as CheckboxRow, u as saveStatus } from "./form-BRQAsKKq.js";
7
+ import { t as Route } from "./telegram-BnQADwnj.js";
8
+ import { t as ConfigPage } from "./ConfigPage-oXM3wyOU.js";
9
+ import { useEffect, useState } from "react";
10
+ import { useRouter } from "@tanstack/react-router";
11
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
12
+ import { BellRing, Bot, ListChecks, ShieldCheck, Users } from "lucide-react";
13
+ //#region src/lib/telegram-setup.ts
14
+ var RUNNING = {
15
+ label: "Running",
16
+ tone: "success"
17
+ };
18
+ var NOT_RUNNING = {
19
+ label: "Not running",
20
+ tone: "warning"
21
+ };
22
+ /**
23
+ * Whether the bot runs. A preflight run on this page knows best; before one, the daemon says
24
+ * whether the bot is up and has set up its group. Null until either is known.
25
+ */
26
+ function botState({ configured, restarting, health, ready }) {
27
+ if (!configured) return {
28
+ label: "Not connected",
29
+ tone: "neutral"
30
+ };
31
+ if (restarting) return {
32
+ label: "Restarting…",
33
+ tone: "neutral"
34
+ };
35
+ if (health) {
36
+ const polling = health.polling;
37
+ if (!polling?.running) return NOT_RUNNING;
38
+ if (health.error || polling.error) return {
39
+ label: "Failing",
40
+ tone: "warning"
41
+ };
42
+ return polling.activated ? RUNNING : {
43
+ label: "Setting up the group",
44
+ tone: "warning"
45
+ };
46
+ }
47
+ if (ready === void 0) return null;
48
+ return ready ? RUNNING : NOT_RUNNING;
49
+ }
50
+ /** The preflight as a list: each thing the bot needs, and whether it is so. */
51
+ function preflightChecks(preflight) {
52
+ const checks = [
53
+ {
54
+ ok: preflight.botUsername.length > 0,
55
+ label: "Bot identity",
56
+ detail: `@${preflight.botUsername}`
57
+ },
58
+ {
59
+ ok: preflight.chatTitle.length > 0,
60
+ label: "Supergroup reachable",
61
+ detail: preflight.chatTitle
62
+ },
63
+ {
64
+ ok: preflight.isForum,
65
+ label: "Forum topics enabled",
66
+ detail: preflight.isForum ? "is_forum: true" : "is_forum: false — the supergroup owner must enable Topics in group settings"
67
+ },
68
+ {
69
+ ok: preflight.hasManageTopics,
70
+ label: "Bot has can_manage_topics",
71
+ detail: preflight.hasManageTopics ? "admin with can_manage_topics" : "promote the bot to admin in the supergroup with the \"Manage topics\" permission"
72
+ },
73
+ {
74
+ ok: preflight.privacyModeOff,
75
+ label: "Privacy Mode is OFF",
76
+ detail: preflight.privacyModeOff ? "can_read_all_group_messages: true" : "BotFather → /mybots → select bot → Bot Settings → Group Privacy → Turn off"
77
+ },
78
+ {
79
+ ok: preflight.chatIsPrivate,
80
+ label: "Supergroup is private",
81
+ detail: preflight.chatIsPrivate ? "no public @username" : "public groups expose topic content to readers"
82
+ }
83
+ ];
84
+ if (preflight.ownerPresent !== null) checks.push({
85
+ ok: preflight.ownerPresent,
86
+ label: "Paired owner is present",
87
+ detail: preflight.ownerPresent ? "owner membership confirmed" : "owner missing — Telegram ingress is degraded"
88
+ });
89
+ return checks;
90
+ }
91
+ /** What to do when the preflight could not get past one of its calls. */
92
+ function preflightHint(step) {
93
+ switch (step) {
94
+ case "getMe": return "The token is invalid or revoked. Re-issue it with @BotFather → /token, or paste a fresh one above.";
95
+ case "getChat": return "The chat id either does not exist, points at a basic group (not a supergroup), or the bot is not a member. Forward any message from the supergroup to the bot to double-check the id, then add the bot to the group.";
96
+ case "getChatMember": return "The bot is in the chat but the membership lookup failed. This usually means the bot was removed or the chat id was migrated: confirm the bot is still in the supergroup.";
97
+ }
98
+ }
99
+ /** The outcome of the last preflight run on this page; null before one. */
100
+ function preflightState(health) {
101
+ if (!health) return null;
102
+ if (health.error) return {
103
+ label: "Failed",
104
+ tone: "warning"
105
+ };
106
+ if (!health.preflight) return null;
107
+ const failed = preflightChecks(health.preflight).filter((check) => !check.ok).length;
108
+ if (failed === 0) return {
109
+ label: "All passed",
110
+ tone: "success"
111
+ };
112
+ return {
113
+ label: failed === 1 ? "1 to put right" : `${failed} to put right`,
114
+ tone: "warning"
115
+ };
116
+ }
117
+ function pairingState(status) {
118
+ if (!status) return null;
119
+ if (status.paired) return {
120
+ label: "Paired",
121
+ tone: "success"
122
+ };
123
+ return {
124
+ label: status.challengeActive ? "Waiting for the code" : "Not paired",
125
+ tone: "warning"
126
+ };
127
+ }
128
+ /** The bot has an owner: the first of the allowed users, made by pairing. */
129
+ function hasOwner(users) {
130
+ return users.some((user) => user.role === "owner");
131
+ }
132
+ /** Without an owner nobody gets through, whoever is on the list. */
133
+ function allowedState(users) {
134
+ if (!users) return null;
135
+ if (!hasOwner(users)) return {
136
+ label: "Closed",
137
+ tone: "warning"
138
+ };
139
+ return {
140
+ label: users.length === 1 ? "1 person" : `${users.length} people`,
141
+ tone: "neutral"
142
+ };
143
+ }
144
+ /** Who an allowed user is: the label given to them, their @username, or else their id. */
145
+ function allowedName(user) {
146
+ return user.label ?? (user.username ? `@${user.username}` : String(user.userId));
147
+ }
148
+ function notificationsState(settings) {
149
+ if (!settings) return null;
150
+ if (!settings.enabled) return {
151
+ label: "Off",
152
+ tone: "neutral"
153
+ };
154
+ return settings.telegramReady ? {
155
+ label: "On",
156
+ tone: "success"
157
+ } : {
158
+ label: "Waiting for the bot",
159
+ tone: "warning"
160
+ };
161
+ }
162
+ var TOKEN = /^\d+:[A-Za-z0-9_-]+$/;
163
+ var CHAT_ID = /^-?\d+$/;
164
+ /**
165
+ * The credentials form against what is stored. The daemon takes the token and the group together
166
+ * and never hands the token back, so a new group needs the token again.
167
+ */
168
+ function credentialsForm(stored, draft) {
169
+ const token = draft.token.trim();
170
+ const chatId = draft.chatId.trim();
171
+ const chatChanged = chatId !== stored.chatId;
172
+ const problems = {};
173
+ if (token && !TOKEN.test(token)) problems.token = "A token from @BotFather looks like 1234567890:ABC…";
174
+ if (chatId && !CHAT_ID.test(chatId)) problems.chatId = "A supergroup’s id is a number, like -1001234567890.";
175
+ else if (!chatId && stored.configured) problems.chatId = "The bot needs a group. To remove Telegram, disconnect it below.";
176
+ const sound = !problems.token && !problems.chatId;
177
+ const dirty = token !== "" || chatChanged;
178
+ const tokenOpen = hasToken(stored) && chatChanged;
179
+ const needsToken = tokenOpen && chatId !== "" && token === "" && sound;
180
+ const complete = token !== "" && chatId !== "";
181
+ return {
182
+ dirty,
183
+ problems,
184
+ needsToken,
185
+ tokenOpen,
186
+ incomplete: dirty && sound && !complete && !needsToken,
187
+ body: sound && complete ? {
188
+ botToken: token,
189
+ chatId
190
+ } : null
191
+ };
192
+ }
193
+ /** A bot token is stored, with or without its group. */
194
+ function hasToken(stored) {
195
+ return stored.botTokenPreview !== "";
196
+ }
197
+ /**
198
+ * The notifications form as stored. A home that never saved them reports UTC, where the
199
+ * browser's own zone is the better start.
200
+ */
201
+ function notificationsDraft(settings, browserZone) {
202
+ return {
203
+ enabled: settings.enabled,
204
+ kinds: settings.kinds,
205
+ quiet: settings.quietHours !== null,
206
+ start: settings.quietHours?.start ?? "22:00",
207
+ end: settings.quietHours?.end ?? "07:00",
208
+ timezone: settings.enabled || settings.quietHours ? settings.timezone : browserZone
209
+ };
210
+ }
211
+ function notificationsBody(draft) {
212
+ return {
213
+ enabled: draft.enabled,
214
+ kinds: draft.kinds,
215
+ timezone: draft.timezone.trim(),
216
+ quietHours: draft.quiet ? {
217
+ start: draft.start,
218
+ end: draft.end
219
+ } : null
220
+ };
221
+ }
222
+ /** Whether saving would change anything; the order of the kinds is not a change. */
223
+ function sameNotifications(a, b) {
224
+ const body = (draft) => {
225
+ const { kinds, ...rest } = notificationsBody(draft);
226
+ return JSON.stringify({
227
+ ...rest,
228
+ kinds: [...kinds].sort()
229
+ });
230
+ };
231
+ return body(a) === body(b);
232
+ }
233
+ //#endregion
234
+ //#region src/components/setup/NotificationsCard.tsx
235
+ var KINDS = {
236
+ lesson_proposal: "Lesson proposals",
237
+ review_failure: "Review failures",
238
+ trigger_failure: "Scheduled trigger failures",
239
+ agent_loop_break: "Agent message loop breaks",
240
+ queue_interrupted: "Queues paused after restart"
241
+ };
242
+ function browserZone() {
243
+ try {
244
+ return Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";
245
+ } catch {
246
+ return "UTC";
247
+ }
248
+ }
249
+ function NotificationsCard({ settings, error, onSaved }) {
250
+ const [saves, setSaves] = useState(0);
251
+ const state = notificationsState(settings);
252
+ return /* @__PURE__ */ jsx(SetupCard, {
253
+ labelledBy: "telegram-notifications",
254
+ icon: /* @__PURE__ */ jsx(BellRing, { className: "size-5" }),
255
+ title: "Attention notifications",
256
+ description: "Posts each new Attention item of the kinds you choose to the bot’s service topic, once. Items that were already open when you switch this on are not sent.",
257
+ action: state && /* @__PURE__ */ jsx(Chip, {
258
+ tone: state.tone,
259
+ children: state.label
260
+ }),
261
+ children: settings ? /* @__PURE__ */ jsx(NotificationsForm, {
262
+ settings,
263
+ justSaved: saves > 0,
264
+ onSaved: async () => {
265
+ await onSaved();
266
+ setSaves((count) => count + 1);
267
+ }
268
+ }, saves) : /* @__PURE__ */ jsx(CardBody, { children: error ? /* @__PURE__ */ jsx(Notice, {
269
+ tone: "warning",
270
+ role: "alert",
271
+ title: "The settings could not be loaded.",
272
+ children: error
273
+ }) : /* @__PURE__ */ jsx(Waiting, { children: "Loading…" }) })
274
+ });
275
+ }
276
+ function NotificationsForm({ settings, justSaved, onSaved }) {
277
+ const [stored] = useState(() => notificationsDraft(settings, browserZone()));
278
+ const [draft, setDraft] = useState(stored);
279
+ const [busy, setBusy] = useState(false);
280
+ const [error, setError] = useState(null);
281
+ const [touched, setTouched] = useState(false);
282
+ const dirty = !sameNotifications(stored, draft);
283
+ const noKinds = draft.kinds.length === 0;
284
+ const noZone = draft.quiet && draft.timezone.trim() === "";
285
+ const edit = (change) => {
286
+ setTouched(true);
287
+ setError(null);
288
+ setDraft((current) => ({
289
+ ...current,
290
+ ...change
291
+ }));
292
+ };
293
+ async function save(event) {
294
+ event.preventDefault();
295
+ if (!dirty || noKinds || noZone || busy) return;
296
+ setBusy(true);
297
+ setError(null);
298
+ try {
299
+ await api("/api/notifications", {
300
+ method: "PUT",
301
+ body: notificationsBody(draft)
302
+ });
303
+ await onSaved();
304
+ } catch (cause) {
305
+ setError(errorMessage(cause));
306
+ } finally {
307
+ setBusy(false);
308
+ }
309
+ }
310
+ return /* @__PURE__ */ jsxs(CardForm, {
311
+ onSubmit: save,
312
+ children: [
313
+ !settings.telegramReady && /* @__PURE__ */ jsx(Notice, {
314
+ tone: "neutral",
315
+ children: "The bot is not running yet; notices go out once it is connected and activated."
316
+ }),
317
+ /* @__PURE__ */ jsx(SwitchRow, {
318
+ label: "Send Attention notifications to Telegram",
319
+ checked: draft.enabled,
320
+ disabled: busy,
321
+ onChange: (enabled) => edit({ enabled })
322
+ }),
323
+ /* @__PURE__ */ jsxs("fieldset", {
324
+ className: "m-0 min-w-0 border-0 p-0",
325
+ disabled: busy,
326
+ children: [
327
+ /* @__PURE__ */ jsx("legend", {
328
+ className: "mb-2 p-0 text-sm font-semibold text-foreground",
329
+ children: "Kinds"
330
+ }),
331
+ /* @__PURE__ */ jsx("div", {
332
+ className: "grid gap-x-6 gap-y-2.5 sm:grid-cols-2",
333
+ children: Object.keys(KINDS).map((kind) => /* @__PURE__ */ jsx(CheckboxRow, {
334
+ label: KINDS[kind],
335
+ checked: draft.kinds.includes(kind),
336
+ onChange: (checked) => edit({ kinds: checked ? [...draft.kinds, kind] : draft.kinds.filter((value) => value !== kind) })
337
+ }, kind))
338
+ }),
339
+ noKinds && /* @__PURE__ */ jsx(Problem, { children: "Choose at least one kind." })
340
+ ]
341
+ }),
342
+ /* @__PURE__ */ jsx(SwitchRow, {
343
+ label: "Quiet hours",
344
+ description: "Notices wait until they end.",
345
+ checked: draft.quiet,
346
+ disabled: busy,
347
+ onChange: (quiet) => edit({ quiet })
348
+ }),
349
+ draft.quiet && /* @__PURE__ */ jsxs("div", {
350
+ className: "grid items-start gap-x-3 gap-y-4 sm:grid-cols-[8.5rem_8.5rem_minmax(0,18rem)]",
351
+ children: [
352
+ /* @__PURE__ */ jsx(TextField, {
353
+ label: "From",
354
+ type: "time",
355
+ value: draft.start,
356
+ disabled: busy,
357
+ required: true,
358
+ onChange: (start) => edit({ start })
359
+ }),
360
+ /* @__PURE__ */ jsx(TextField, {
361
+ label: "To",
362
+ type: "time",
363
+ value: draft.end,
364
+ disabled: busy,
365
+ required: true,
366
+ onChange: (end) => edit({ end })
367
+ }),
368
+ /* @__PURE__ */ jsx(TextField, {
369
+ label: "Timezone",
370
+ value: draft.timezone,
371
+ disabled: busy,
372
+ required: true,
373
+ placeholder: "Europe/Warsaw",
374
+ problem: noZone ? "Quiet hours need a timezone." : void 0,
375
+ onChange: (timezone) => edit({ timezone })
376
+ })
377
+ ]
378
+ }),
379
+ /* @__PURE__ */ jsx(SaveBar, {
380
+ busy,
381
+ disabled: !dirty || noKinds || noZone,
382
+ status: saveStatus({
383
+ error,
384
+ dirty,
385
+ saved: justSaved && !touched
386
+ })
387
+ })
388
+ ]
389
+ });
390
+ }
391
+ //#endregion
392
+ //#region src/components/setup/TelegramCards.tsx
393
+ var TELEGRAM_PATH = "/api/config/telegram";
394
+ function StateChip({ state }) {
395
+ return state && /* @__PURE__ */ jsx(Chip, {
396
+ tone: state.tone,
397
+ children: state.label
398
+ });
399
+ }
400
+ /** Telegram moved the group to a new id, and the bot still points at the old one. */
401
+ function MigrationBanner({ toChatId, onReconnected }) {
402
+ const [busy, setBusy] = useState(false);
403
+ const [error, setError] = useState(null);
404
+ async function reconnect() {
405
+ setBusy(true);
406
+ setError(null);
407
+ try {
408
+ await api(`${TELEGRAM_PATH}/reconnect`, { method: "POST" });
409
+ await onReconnected();
410
+ } catch (cause) {
411
+ setError(errorMessage(cause));
412
+ } finally {
413
+ setBusy(false);
414
+ }
415
+ }
416
+ return /* @__PURE__ */ jsxs("div", {
417
+ className: "grid gap-2",
418
+ children: [/* @__PURE__ */ jsxs(Banner, {
419
+ tone: "warning",
420
+ lead: /* @__PURE__ */ jsxs(Fragment$1, { children: [
421
+ "Telegram moved this group to a new chat id, ",
422
+ /* @__PURE__ */ jsx("code", { children: toChatId }),
423
+ "."
424
+ ] }),
425
+ action: /* @__PURE__ */ jsx(Button, {
426
+ variant: "primary",
427
+ disabled: busy,
428
+ onClick: () => void reconnect(),
429
+ children: busy ? "Reconnecting…" : "Reconnect"
430
+ }),
431
+ children: [
432
+ "The bot still points at the old id. Reconnecting moves it over and creates the",
433
+ " ",
434
+ /* @__PURE__ */ jsx("code", { children: "⚙ bazilion" }),
435
+ " service topic again in the new group; each Agent’s topic follows when it is next used."
436
+ ]
437
+ }), error && /* @__PURE__ */ jsx(Banner, {
438
+ tone: "warning",
439
+ role: "alert",
440
+ lead: "The bot was not reconnected.",
441
+ children: error
442
+ })]
443
+ });
444
+ }
445
+ /** The bot's token and the group it works in, saved together. */
446
+ function BotCard({ stored, state, justSaved, onSaved, onDisconnected }) {
447
+ const [draft, setDraft] = useState({
448
+ token: "",
449
+ chatId: stored.chatId
450
+ });
451
+ const [busy, setBusy] = useState(false);
452
+ const [error, setError] = useState(null);
453
+ const [touched, setTouched] = useState(false);
454
+ const [confirmDisconnect, setConfirmDisconnect] = useState(false);
455
+ const form = credentialsForm(stored, draft);
456
+ const edit = (change) => {
457
+ setTouched(true);
458
+ setError(null);
459
+ setDraft((current) => ({
460
+ ...current,
461
+ ...change
462
+ }));
463
+ };
464
+ async function save(event) {
465
+ event.preventDefault();
466
+ if (!form.body || busy) return;
467
+ setBusy(true);
468
+ setError(null);
469
+ try {
470
+ await api(TELEGRAM_PATH, {
471
+ method: "PUT",
472
+ body: form.body
473
+ });
474
+ await onSaved();
475
+ } catch (cause) {
476
+ setError(errorMessage(cause));
477
+ } finally {
478
+ setBusy(false);
479
+ }
480
+ }
481
+ const status = form.incomplete ? {
482
+ text: "The token and the group’s id are saved together: fill in both.",
483
+ tone: "warning"
484
+ } : saveStatus({
485
+ error,
486
+ dirty: form.dirty,
487
+ saved: justSaved && !touched,
488
+ savedText: "Saved. A new token or group restarts the bot: run the preflight in a few seconds.",
489
+ footnote: stored.configured ? "A new token or group restarts the bot and starts pairing over: the owner and the allowed users are forgotten." : "Saving starts the bot."
490
+ });
491
+ return /* @__PURE__ */ jsxs(SetupCard, {
492
+ labelledBy: "telegram-bot",
493
+ icon: /* @__PURE__ */ jsx(Bot, { className: "size-5" }),
494
+ title: "Bot",
495
+ description: "The bot your Agents speak through, and the forum supergroup it works in.",
496
+ action: /* @__PURE__ */ jsx(StateChip, { state }),
497
+ children: [
498
+ /* @__PURE__ */ jsxs(CardForm, {
499
+ onSubmit: save,
500
+ children: [
501
+ /* @__PURE__ */ jsx(SecretField, {
502
+ label: "Bot token",
503
+ saved: hasToken(stored),
504
+ preview: stored.botTokenPreview,
505
+ value: draft.token,
506
+ open: form.tokenOpen,
507
+ disabled: busy,
508
+ placeholder: "1234567890:ABC…",
509
+ hint: /* @__PURE__ */ jsxs(Fragment$1, { children: [
510
+ "From @BotFather → /newbot. Disable Privacy Mode in",
511
+ " ",
512
+ /* @__PURE__ */ jsx("em", { children: "Bot Settings → Group Privacy → Turn off" }),
513
+ "."
514
+ ] }),
515
+ notes: form.problems.token ? /* @__PURE__ */ jsx(Problem, { children: form.problems.token }) : form.needsToken && /* @__PURE__ */ jsx(Problem, { children: "Type the bot token again: a new group is saved together with it." }),
516
+ onChange: (token) => edit({ token })
517
+ }),
518
+ /* @__PURE__ */ jsx(TextField, {
519
+ label: "Supergroup chat ID",
520
+ value: draft.chatId,
521
+ disabled: busy,
522
+ placeholder: "-1001234567890",
523
+ mono: true,
524
+ hint: /* @__PURE__ */ jsxs(Fragment$1, { children: [
525
+ "Forum-enabled supergroup the bot is admin in (with ",
526
+ /* @__PURE__ */ jsx("code", { children: "can_manage_topics" }),
527
+ ")."
528
+ ] }),
529
+ problem: form.problems.chatId,
530
+ onChange: (chatId) => edit({ chatId })
531
+ }),
532
+ /* @__PURE__ */ jsx(SaveBar, {
533
+ busy,
534
+ disabled: !form.body,
535
+ status
536
+ })
537
+ ]
538
+ }),
539
+ stored.configured && /* @__PURE__ */ jsxs(CardRow, {
540
+ className: "py-3",
541
+ children: [/* @__PURE__ */ jsx("span", {
542
+ className: "min-w-0 flex-1 basis-64 text-sm text-muted-foreground",
543
+ children: "Disconnecting removes the token and the group, and stops the bot."
544
+ }), /* @__PURE__ */ jsx(Button, {
545
+ variant: "danger",
546
+ disabled: busy,
547
+ onClick: () => setConfirmDisconnect(true),
548
+ children: "Disconnect Telegram"
549
+ })]
550
+ }),
551
+ /* @__PURE__ */ jsx(ConfirmDialog, {
552
+ open: confirmDisconnect,
553
+ onOpenChange: setConfirmDisconnect,
554
+ title: "Disconnect Telegram?",
555
+ description: /* @__PURE__ */ jsx("p", {
556
+ className: "m-0",
557
+ children: "This permanently removes the saved bot token and supergroup ID. Telegram polling, ingress, and outbound delivery stop until new credentials are saved and pairing is completed again."
558
+ }),
559
+ confirmLabel: "Disconnect Telegram",
560
+ onConfirm: async () => {
561
+ await api(TELEGRAM_PATH, { method: "DELETE" });
562
+ await onDisconnected();
563
+ }
564
+ })
565
+ ]
566
+ });
567
+ }
568
+ /** What Telegram answers about the bot and its group, and how the running bot is doing. */
569
+ function PreflightCard({ configured, health, working, note, error, now, onRun, onRestart }) {
570
+ return /* @__PURE__ */ jsxs(SetupCard, {
571
+ labelledBy: "telegram-preflight",
572
+ icon: /* @__PURE__ */ jsx(ListChecks, { className: "size-5" }),
573
+ title: "Preflight checks",
574
+ description: "Asks Telegram whether the bot and its group are set up the way Bazilion needs.",
575
+ action: /* @__PURE__ */ jsx(StateChip, { state: preflightState(health) }),
576
+ children: [/* @__PURE__ */ jsxs(CardBody, { children: [
577
+ configured ? /* @__PURE__ */ jsxs("div", {
578
+ className: "flex flex-wrap items-center gap-2",
579
+ children: [/* @__PURE__ */ jsx(Button, {
580
+ variant: "primary",
581
+ disabled: working !== null,
582
+ onClick: onRun,
583
+ children: working === "check" ? "Checking…" : "Run preflight"
584
+ }), /* @__PURE__ */ jsx(Button, {
585
+ variant: "ghost",
586
+ disabled: working !== null,
587
+ onClick: onRestart,
588
+ children: working === "restart" ? "Restarting…" : "Restart bot"
589
+ })]
590
+ }) : /* @__PURE__ */ jsx("p", {
591
+ className: "m-0 text-sm text-muted-foreground",
592
+ children: "Save the bot’s credentials above first."
593
+ }),
594
+ working === "check" && /* @__PURE__ */ jsx(Waiting, { children: "Asking Telegram…" }),
595
+ note && /* @__PURE__ */ jsx(Notice, {
596
+ tone: "neutral",
597
+ children: note
598
+ }),
599
+ error && /* @__PURE__ */ jsx(Notice, {
600
+ tone: "warning",
601
+ role: "alert",
602
+ title: "That did not work.",
603
+ children: error
604
+ }),
605
+ health?.error && /* @__PURE__ */ jsxs(Notice, {
606
+ tone: "warning",
607
+ role: "alert",
608
+ title: /* @__PURE__ */ jsxs(Fragment$1, { children: ["Failed at ", /* @__PURE__ */ jsx("code", { children: health.error.step })] }),
609
+ children: [/* @__PURE__ */ jsx("p", {
610
+ className: "m-0",
611
+ children: health.error.message
612
+ }), /* @__PURE__ */ jsx("p", {
613
+ className: "m-0 mt-1 text-muted-foreground",
614
+ children: preflightHint(health.error.step)
615
+ })]
616
+ }),
617
+ health?.preflight && /* @__PURE__ */ jsxs("div", {
618
+ role: "status",
619
+ "aria-live": "polite",
620
+ "aria-atomic": "true",
621
+ className: "grid gap-3",
622
+ children: [/* @__PURE__ */ jsx(CheckList, { children: preflightChecks(health.preflight).map((check) => /* @__PURE__ */ jsx(CheckItem, {
623
+ ok: check.ok,
624
+ label: check.label,
625
+ children: check.detail
626
+ }, check.label)) }), /* @__PURE__ */ jsxs("p", {
627
+ className: "m-0 text-sm text-muted-foreground",
628
+ children: [
629
+ "Group members: ",
630
+ health.preflight.memberCount ?? "unknown",
631
+ ". Everyone in the group can read the Agents’ replies."
632
+ ]
633
+ })]
634
+ }),
635
+ health && !health.error && !health.preflight && /* @__PURE__ */ jsx("p", {
636
+ role: "status",
637
+ className: "m-0 text-sm text-muted-foreground",
638
+ children: "No preflight data."
639
+ })
640
+ ] }), health?.polling && /* @__PURE__ */ jsx(PollingFacts, {
641
+ polling: health.polling,
642
+ now
643
+ })]
644
+ });
645
+ }
646
+ function PollingFacts({ polling, now }) {
647
+ const moment = (at) => /* @__PURE__ */ jsx("time", {
648
+ dateTime: new Date(at).toISOString(),
649
+ children: ago(at, now)
650
+ });
651
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(CardRow, {
652
+ className: "bg-muted/50 py-2 text-[0.7rem] font-bold uppercase tracking-[0.08em] text-muted-foreground",
653
+ children: "The running bot"
654
+ }), /* @__PURE__ */ jsxs(Facts, {
655
+ className: "border-t-0",
656
+ children: [
657
+ /* @__PURE__ */ jsx(Fact, {
658
+ label: "Polling",
659
+ tone: polling.running ? "success" : "warning",
660
+ children: polling.running ? "Running" : "Stopped"
661
+ }),
662
+ /* @__PURE__ */ jsx(Fact, {
663
+ label: "Group setup",
664
+ tone: polling.activated ? "success" : "warning",
665
+ children: polling.activated ? "Activated" : "Awaiting activation"
666
+ }),
667
+ polling.startedAt !== null && /* @__PURE__ */ jsx(Fact, {
668
+ label: "Started",
669
+ children: moment(polling.startedAt)
670
+ }),
671
+ polling.lastSuccessfulPollAt !== null && /* @__PURE__ */ jsx(Fact, {
672
+ label: "Last poll",
673
+ children: moment(polling.lastSuccessfulPollAt)
674
+ }),
675
+ polling.lastUpdateId !== null && /* @__PURE__ */ jsx(Fact, {
676
+ label: "Last update",
677
+ children: /* @__PURE__ */ jsx("span", {
678
+ className: "font-mono text-[0.9em]",
679
+ children: polling.lastUpdateId
680
+ })
681
+ }),
682
+ polling.error && /* @__PURE__ */ jsx(Fact, {
683
+ label: "Error",
684
+ tone: "warning",
685
+ children: polling.error
686
+ })
687
+ ]
688
+ })] });
689
+ }
690
+ /** The one person the bot belongs to: paired with a code sent in the group. */
691
+ function PairingCard({ onOwnerChange }) {
692
+ const [status, setStatus] = useState(null);
693
+ const [code, setCode] = useState(null);
694
+ const [error, setError] = useState(null);
695
+ const [busy, setBusy] = useState(false);
696
+ const [confirmReset, setConfirmReset] = useState(false);
697
+ const path = `${TELEGRAM_PATH}/pairing`;
698
+ const load = async () => setStatus(await api(path));
699
+ useEffect(() => {
700
+ load().catch((cause) => setError(errorMessage(cause)));
701
+ }, []);
702
+ const waiting = status !== null && !status.paired && status.challengeActive;
703
+ useEffect(() => {
704
+ if (!waiting) return;
705
+ const timer = window.setInterval(() => {
706
+ api(path).then((next) => {
707
+ setStatus(next);
708
+ if (next.paired) {
709
+ setCode(null);
710
+ onOwnerChange();
711
+ }
712
+ }).catch(() => {});
713
+ }, 4e3);
714
+ return () => window.clearInterval(timer);
715
+ }, [waiting]);
716
+ async function run(work) {
717
+ setBusy(true);
718
+ setError(null);
719
+ try {
720
+ await work();
721
+ } catch (cause) {
722
+ setError(errorMessage(cause));
723
+ } finally {
724
+ setBusy(false);
725
+ }
726
+ }
727
+ const createCode = () => run(async () => {
728
+ const challenge = await api(`${path}/challenge`, { method: "POST" });
729
+ setCode(challenge.code);
730
+ setStatus(challenge);
731
+ });
732
+ const cancelCode = () => run(async () => {
733
+ await api(`${path}/challenge`, { method: "DELETE" });
734
+ setCode(null);
735
+ await load();
736
+ });
737
+ return /* @__PURE__ */ jsxs(SetupCard, {
738
+ labelledBy: "telegram-pairing",
739
+ icon: /* @__PURE__ */ jsx(ShieldCheck, { className: "size-5" }),
740
+ title: "Owner pairing",
741
+ description: /* @__PURE__ */ jsxs(Fragment$1, { children: [
742
+ "Telegram stays closed until one owner sends a short-lived code in the",
743
+ " ",
744
+ /* @__PURE__ */ jsx("code", { children: "⚙ bazilion" }),
745
+ " service topic."
746
+ ] }),
747
+ action: /* @__PURE__ */ jsx(StateChip, { state: pairingState(status) }),
748
+ children: [/* @__PURE__ */ jsxs(CardBody, { children: [
749
+ status === null && !error && /* @__PURE__ */ jsx(Waiting, { children: "Loading…" }),
750
+ status?.paired && /* @__PURE__ */ jsxs("div", {
751
+ className: "flex flex-wrap items-center gap-x-4 gap-y-2",
752
+ children: [/* @__PURE__ */ jsxs("p", {
753
+ className: "m-0 min-w-0 flex-1 basis-64 text-sm text-foreground",
754
+ children: [
755
+ "The owner is paired",
756
+ status.ownerUserId !== null && /* @__PURE__ */ jsxs(Fragment$1, { children: [": Telegram user ", /* @__PURE__ */ jsx("span", {
757
+ className: "font-mono",
758
+ children: status.ownerUserId
759
+ })] }),
760
+ "."
761
+ ]
762
+ }), /* @__PURE__ */ jsx(Button, {
763
+ variant: "danger",
764
+ disabled: busy,
765
+ onClick: () => setConfirmReset(true),
766
+ children: "Reset owner"
767
+ })]
768
+ }),
769
+ status && !status.paired && /* @__PURE__ */ jsxs(Fragment$1, { children: [
770
+ /* @__PURE__ */ jsx("p", {
771
+ className: "m-0 text-sm text-warning",
772
+ children: "Unpaired: nothing sent to the bot is accepted."
773
+ }),
774
+ code && /* @__PURE__ */ jsxs(Notice, {
775
+ tone: "neutral",
776
+ title: "Send this in the service topic",
777
+ children: [/* @__PURE__ */ jsxs("code", {
778
+ className: "text-[0.95em]",
779
+ children: ["/pair ", code]
780
+ }), /* @__PURE__ */ jsx("p", {
781
+ className: "m-0 mt-1 text-muted-foreground",
782
+ children: "The code is shown once and expires in ten minutes."
783
+ })]
784
+ }),
785
+ /* @__PURE__ */ jsxs("div", {
786
+ className: "flex flex-wrap gap-2",
787
+ children: [/* @__PURE__ */ jsx(Button, {
788
+ variant: "primary",
789
+ disabled: busy,
790
+ onClick: () => void createCode(),
791
+ children: code || status.challengeActive ? "Generate a new pairing code" : "Generate pairing code"
792
+ }), status.challengeActive && /* @__PURE__ */ jsx(Button, {
793
+ variant: "ghost",
794
+ disabled: busy,
795
+ onClick: () => void cancelCode(),
796
+ children: "Cancel code"
797
+ })]
798
+ })
799
+ ] }),
800
+ error && /* @__PURE__ */ jsx(Notice, {
801
+ tone: "warning",
802
+ role: "alert",
803
+ title: "That did not work.",
804
+ children: error
805
+ })
806
+ ] }), /* @__PURE__ */ jsx(ConfirmDialog, {
807
+ open: confirmReset,
808
+ onOpenChange: setConfirmReset,
809
+ title: "Revoke the paired Telegram owner?",
810
+ description: /* @__PURE__ */ jsx("p", {
811
+ className: "m-0",
812
+ children: "This immediately revokes the current owner, removes everyone else from the allowed users and closes all Telegram ingress. No one can use the bot until a new one-time pairing code is generated and consumed."
813
+ }),
814
+ confirmLabel: "Revoke owner and close ingress",
815
+ onConfirm: async () => {
816
+ await api(`${path}/reset`, { body: { confirm: true } });
817
+ setCode(null);
818
+ await load();
819
+ onOwnerChange();
820
+ }
821
+ })]
822
+ });
823
+ }
824
+ /** The Telegram users who may use the bot besides its owner. */
825
+ function AllowedUsersCard() {
826
+ const [users, setUsers] = useState(null);
827
+ const [userId, setUserId] = useState("");
828
+ const [label, setLabel] = useState("");
829
+ const [busy, setBusy] = useState(false);
830
+ const [error, setError] = useState(null);
831
+ const [removing, setRemoving] = useState(null);
832
+ const path = `${TELEGRAM_PATH}/acl`;
833
+ const load = async () => setUsers(await api(path));
834
+ useEffect(() => {
835
+ load().catch((cause) => setError(errorMessage(cause)));
836
+ }, []);
837
+ const id = userId.trim();
838
+ const idProblem = id !== "" && !/^\d+$/.test(id) ? "A Telegram user id is a number, like 123456789." : void 0;
839
+ async function add(event) {
840
+ event.preventDefault();
841
+ if (id === "" || idProblem || busy) return;
842
+ setBusy(true);
843
+ setError(null);
844
+ try {
845
+ await api(path, { body: {
846
+ userId: Number(id),
847
+ label: label.trim() || null
848
+ } });
849
+ setUserId("");
850
+ setLabel("");
851
+ await load();
852
+ } catch (cause) {
853
+ setError(errorMessage(cause));
854
+ } finally {
855
+ setBusy(false);
856
+ }
857
+ }
858
+ return /* @__PURE__ */ jsxs(SetupCard, {
859
+ labelledBy: "telegram-allowed",
860
+ icon: /* @__PURE__ */ jsx(Users, { className: "size-5" }),
861
+ title: "Allowed users",
862
+ description: /* @__PURE__ */ jsxs(Fragment$1, { children: [
863
+ "The Telegram users who can use the bot, for commands and chat. Anyone finds their id by sending ",
864
+ /* @__PURE__ */ jsx("code", { children: "/whoami" }),
865
+ "."
866
+ ] }),
867
+ action: /* @__PURE__ */ jsx(StateChip, { state: allowedState(users) }),
868
+ children: [
869
+ users === null && !error && /* @__PURE__ */ jsx(CardRow, {
870
+ className: "py-4",
871
+ children: /* @__PURE__ */ jsx(Waiting, { children: "Loading…" })
872
+ }),
873
+ users && !hasOwner(users) && /* @__PURE__ */ jsx(CardRow, {
874
+ className: "py-4 text-sm text-muted-foreground",
875
+ children: "Closed: the bot has no owner yet. Others can be added once the owner is paired above."
876
+ }),
877
+ users && users.length > 0 && /* @__PURE__ */ jsx(CardList, { children: users.map((user) => {
878
+ const name = allowedName(user);
879
+ return /* @__PURE__ */ jsx(ListRow, {
880
+ title: name,
881
+ meta: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", { children: user.role === "owner" ? "Owner" : "Member" }), name !== String(user.userId) && /* @__PURE__ */ jsx("code", { children: user.userId })] }),
882
+ actions: user.role !== "owner" && /* @__PURE__ */ jsx(Button, {
883
+ variant: "danger",
884
+ disabled: busy,
885
+ "aria-label": `Remove ${name}`,
886
+ onClick: () => setRemoving(user),
887
+ children: "Remove"
888
+ })
889
+ }, user.userId);
890
+ }) }),
891
+ users && hasOwner(users) && /* @__PURE__ */ jsxs(CardForm, {
892
+ onSubmit: add,
893
+ children: [/* @__PURE__ */ jsxs("div", {
894
+ className: "grid items-start gap-x-3 gap-y-4 sm:grid-cols-[minmax(0,14rem)_minmax(0,18rem)]",
895
+ children: [/* @__PURE__ */ jsx(TextField, {
896
+ label: "Telegram user ID",
897
+ value: userId,
898
+ disabled: busy,
899
+ placeholder: "123456789",
900
+ mono: true,
901
+ inputMode: "numeric",
902
+ problem: idProblem,
903
+ onChange: setUserId
904
+ }), /* @__PURE__ */ jsx(TextField, {
905
+ label: "Label (optional)",
906
+ value: label,
907
+ disabled: busy,
908
+ placeholder: "e.g. Pat",
909
+ onChange: setLabel
910
+ })]
911
+ }), /* @__PURE__ */ jsx("div", {
912
+ className: "flex flex-wrap items-center gap-x-4 gap-y-2",
913
+ children: /* @__PURE__ */ jsx(Button, {
914
+ variant: "primary",
915
+ type: "submit",
916
+ disabled: busy || id === "" || idProblem !== void 0,
917
+ children: busy ? "Adding…" : "Add user"
918
+ })
919
+ })]
920
+ }),
921
+ error && /* @__PURE__ */ jsx(CardBody, { children: /* @__PURE__ */ jsx(Notice, {
922
+ tone: "warning",
923
+ role: "alert",
924
+ title: "That did not work.",
925
+ children: error
926
+ }) }),
927
+ /* @__PURE__ */ jsx(ConfirmDialog, {
928
+ open: removing !== null,
929
+ onOpenChange: (open) => {
930
+ if (!open) setRemoving(null);
931
+ },
932
+ title: `Remove ${removing ? allowedName(removing) : ""}?`,
933
+ description: /* @__PURE__ */ jsxs("p", {
934
+ className: "m-0",
935
+ children: [
936
+ "Telegram user ",
937
+ /* @__PURE__ */ jsx("code", { children: removing?.userId }),
938
+ " immediately loses command and chat access. Their Telegram account is not changed, and they can be allowed again later."
939
+ ]
940
+ }),
941
+ confirmLabel: "Remove Telegram access",
942
+ onConfirm: async () => {
943
+ if (!removing) return;
944
+ await api(`${path}/${removing.userId}`, { method: "DELETE" });
945
+ await load();
946
+ }
947
+ })
948
+ ]
949
+ });
950
+ }
951
+ //#endregion
952
+ //#region src/routes/config/telegram.tsx?tsr-split=component
953
+ function TelegramPage() {
954
+ const stored = Route.useLoaderData();
955
+ const router = useRouter();
956
+ const notifications = useResource((signal) => api("/api/notifications", { signal }), []);
957
+ const [check, setCheck] = useState(null);
958
+ const [working, setWorking] = useState(null);
959
+ const [restarting, setRestarting] = useState(false);
960
+ const [note, setNote] = useState(null);
961
+ const [error, setError] = useState(null);
962
+ const [changes, setChanges] = useState(0);
963
+ const [justSaved, setJustSaved] = useState(false);
964
+ const [ownerResets, setOwnerResets] = useState(0);
965
+ async function runPreflight() {
966
+ setWorking("check");
967
+ setCheck(null);
968
+ setNote(null);
969
+ setError(null);
970
+ try {
971
+ setCheck({
972
+ health: await api(`${TELEGRAM_PATH}/health`),
973
+ at: Date.now()
974
+ });
975
+ setRestarting(false);
976
+ notifications.reload();
977
+ } catch (cause) {
978
+ setError(errorMessage(cause));
979
+ } finally {
980
+ setWorking(null);
981
+ }
982
+ }
983
+ async function restartBot() {
984
+ setWorking("restart");
985
+ setCheck(null);
986
+ setNote(null);
987
+ setError(null);
988
+ try {
989
+ await api(`${TELEGRAM_PATH}/restart`, { method: "POST" });
990
+ setRestarting(true);
991
+ setNote("Restarting. Run the preflight in a few seconds to see how the bot is doing.");
992
+ } catch (cause) {
993
+ setError(errorMessage(cause));
994
+ } finally {
995
+ setWorking(null);
996
+ }
997
+ }
998
+ /** The credentials changed: what was known about the old bot no longer holds. */
999
+ async function changed(now) {
1000
+ await router.invalidate({ sync: true });
1001
+ setCheck(null);
1002
+ setNote(null);
1003
+ setError(null);
1004
+ setRestarting(now.restarting);
1005
+ setJustSaved(now.saved);
1006
+ setChanges((count) => count + 1);
1007
+ notifications.reload();
1008
+ }
1009
+ return /* @__PURE__ */ jsxs(ConfigPage, {
1010
+ title: "Telegram",
1011
+ description: "Connect one forum-supergroup bot with one topic per Agent, so conversations stay reachable from your phone.",
1012
+ children: [
1013
+ stored.migratedChatId && /* @__PURE__ */ jsx(MigrationBanner, {
1014
+ toChatId: stored.migratedChatId,
1015
+ onReconnected: () => changed({
1016
+ saved: false,
1017
+ restarting: true
1018
+ })
1019
+ }),
1020
+ /* @__PURE__ */ jsx(BotCard, {
1021
+ stored,
1022
+ state: botState({
1023
+ configured: stored.configured,
1024
+ restarting,
1025
+ health: check?.health ?? null,
1026
+ ready: notifications.data?.telegramReady
1027
+ }),
1028
+ justSaved,
1029
+ onSaved: () => changed({
1030
+ saved: true,
1031
+ restarting: false
1032
+ }),
1033
+ onDisconnected: () => changed({
1034
+ saved: false,
1035
+ restarting: false
1036
+ })
1037
+ }, `bot:${changes}`),
1038
+ /* @__PURE__ */ jsx(PreflightCard, {
1039
+ configured: stored.configured,
1040
+ health: check?.health ?? null,
1041
+ now: check?.at ?? 0,
1042
+ working,
1043
+ note,
1044
+ error,
1045
+ onRun: () => void runPreflight(),
1046
+ onRestart: () => void restartBot()
1047
+ }),
1048
+ stored.configured && /* @__PURE__ */ jsx(PairingCard, { onOwnerChange: () => setOwnerResets((count) => count + 1) }, `pairing:${changes}`),
1049
+ /* @__PURE__ */ jsx(NotificationsCard, {
1050
+ settings: notifications.data,
1051
+ error: notifications.error,
1052
+ onSaved: notifications.reload
1053
+ }),
1054
+ stored.configured && /* @__PURE__ */ jsx(AllowedUsersCard, {}, `allowed:${changes}:${ownerResets}`)
1055
+ ]
1056
+ });
1057
+ }
1058
+ //#endregion
1059
+ export { TelegramPage as component };