@songsid/agend 2.4.0-beta.2 → 2.4.0-beta.4

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 (294) hide show
  1. package/dist/agent-cli.js +1 -1
  2. package/dist/agent-endpoint.d.ts +1 -1
  3. package/dist/agent-endpoint.js +8 -2
  4. package/dist/agent-endpoint.js.map +1 -1
  5. package/dist/agent-token-header.d.ts +1 -1
  6. package/dist/agent-token-header.js +1 -1
  7. package/dist/auth-api.d.ts +3 -0
  8. package/dist/auth-api.js +15 -1
  9. package/dist/auth-api.js.map +1 -1
  10. package/dist/backend/agy-model-switch.d.ts +22 -0
  11. package/dist/backend/agy-model-switch.js +62 -0
  12. package/dist/backend/agy-model-switch.js.map +1 -0
  13. package/dist/backend/antigravity.js +60 -3
  14. package/dist/backend/antigravity.js.map +1 -1
  15. package/dist/backend/cli-runtime-switch.d.ts +71 -0
  16. package/dist/backend/cli-runtime-switch.js +176 -0
  17. package/dist/backend/cli-runtime-switch.js.map +1 -0
  18. package/dist/backend/codex-model-switch.d.ts +41 -0
  19. package/dist/backend/codex-model-switch.js +170 -0
  20. package/dist/backend/codex-model-switch.js.map +1 -0
  21. package/dist/backend/credential-profile.js +1 -1
  22. package/dist/backend/credential-profile.js.map +1 -1
  23. package/dist/backend/grok-model-switch.d.ts +16 -0
  24. package/dist/backend/grok-model-switch.js +45 -0
  25. package/dist/backend/grok-model-switch.js.map +1 -0
  26. package/dist/backend/grok.js +1 -1
  27. package/dist/backend/grok.js.map +1 -1
  28. package/dist/backend/muse.d.ts +2 -0
  29. package/dist/backend/muse.js +7 -3
  30. package/dist/backend/muse.js.map +1 -1
  31. package/dist/build-provenance.json +1 -1
  32. package/dist/channel/mcp-server.js +10 -1
  33. package/dist/channel/mcp-server.js.map +1 -1
  34. package/dist/channel/mcp-tools.js +8 -0
  35. package/dist/channel/mcp-tools.js.map +1 -1
  36. package/dist/classic-channel-manager.d.ts +1 -1
  37. package/dist/classic-channel-manager.js +1 -1
  38. package/dist/cli-audited.js +12 -12
  39. package/dist/cli-audited.js.map +1 -1
  40. package/dist/daemon.d.ts +48 -2
  41. package/dist/daemon.js +302 -21
  42. package/dist/daemon.js.map +1 -1
  43. package/dist/delivery-consumed-watch.js +3 -0
  44. package/dist/delivery-consumed-watch.js.map +1 -1
  45. package/dist/event-log.d.ts +1 -1
  46. package/dist/event-log.js +1 -1
  47. package/dist/fleet-manager.d.ts +104 -2
  48. package/dist/fleet-manager.js +665 -27
  49. package/dist/fleet-manager.js.map +1 -1
  50. package/dist/general-knowledge/skills/credential-profiles/SKILL.md +10 -0
  51. package/dist/general-knowledge/skills/cross-instance-messaging/SKILL.md +2 -0
  52. package/dist/general-knowledge/skills/fleet-health/SKILL.md +18 -0
  53. package/dist/general-knowledge/skills/hub/SKILL.md +154 -0
  54. package/dist/general-knowledge/skills/model-discovery/SKILL.md +4 -0
  55. package/dist/general-knowledge/skills/web-dashboard/SKILL.md +17 -3
  56. package/dist/hub/admin-dashboard.d.ts +85 -0
  57. package/dist/hub/admin-dashboard.js +161 -0
  58. package/dist/hub/admin-dashboard.js.map +1 -0
  59. package/dist/hub/attachments/store.d.ts +2 -0
  60. package/dist/hub/attachments/store.js +6 -0
  61. package/dist/hub/attachments/store.js.map +1 -1
  62. package/dist/hub/client.d.ts +10 -0
  63. package/dist/hub/client.js +72 -10
  64. package/dist/hub/client.js.map +1 -1
  65. package/dist/hub/compose/member.d.ts +20 -0
  66. package/dist/hub/compose/member.js +212 -17
  67. package/dist/hub/compose/member.js.map +1 -1
  68. package/dist/hub/compose/server.d.ts +8 -0
  69. package/dist/hub/compose/server.js +13 -2
  70. package/dist/hub/compose/server.js.map +1 -1
  71. package/dist/hub/display-name.d.ts +10 -0
  72. package/dist/hub/display-name.js +35 -0
  73. package/dist/hub/display-name.js.map +1 -0
  74. package/dist/hub/execution/service.d.ts +1 -0
  75. package/dist/hub/execution/service.js +1 -1
  76. package/dist/hub/execution/service.js.map +1 -1
  77. package/dist/hub/fleet-info.d.ts +12 -0
  78. package/dist/hub/fleet-info.js +14 -0
  79. package/dist/hub/fleet-info.js.map +1 -0
  80. package/dist/hub/fleet-update-model.d.ts +100 -0
  81. package/dist/hub/fleet-update-model.js +15 -0
  82. package/dist/hub/fleet-update-model.js.map +1 -0
  83. package/dist/hub/fleet-updates.d.ts +46 -0
  84. package/dist/hub/fleet-updates.js +282 -0
  85. package/dist/hub/fleet-updates.js.map +1 -0
  86. package/dist/hub/fleet-versions.d.ts +28 -0
  87. package/dist/hub/fleet-versions.js +80 -0
  88. package/dist/hub/fleet-versions.js.map +1 -0
  89. package/dist/hub/http/compose.d.ts +2 -0
  90. package/dist/hub/http/compose.js +192 -16
  91. package/dist/hub/http/compose.js.map +1 -1
  92. package/dist/hub/http/deps.d.ts +1 -0
  93. package/dist/hub/http/schema.js +13 -1
  94. package/dist/hub/http/schema.js.map +1 -1
  95. package/dist/hub/member/display-name.d.ts +9 -0
  96. package/dist/hub/member/display-name.js +71 -0
  97. package/dist/hub/member/display-name.js.map +1 -0
  98. package/dist/hub/member/exposure-api.d.ts +4 -0
  99. package/dist/hub/member/exposure-api.js +8 -3
  100. package/dist/hub/member/exposure-api.js.map +1 -1
  101. package/dist/hub/member/exposures.d.ts +4 -0
  102. package/dist/hub/member/exposures.js +20 -0
  103. package/dist/hub/member/exposures.js.map +1 -1
  104. package/dist/hub/member/pairing-api.js +3 -2
  105. package/dist/hub/member/pairing-api.js.map +1 -1
  106. package/dist/hub/member/recommendations.d.ts +37 -0
  107. package/dist/hub/member/recommendations.js +129 -0
  108. package/dist/hub/member/recommendations.js.map +1 -0
  109. package/dist/hub/member/room-ask.d.ts +60 -1
  110. package/dist/hub/member/room-ask.js +254 -24
  111. package/dist/hub/member/room-ask.js.map +1 -1
  112. package/dist/hub/member/room-post-answers.d.ts +52 -0
  113. package/dist/hub/member/room-post-answers.js +152 -0
  114. package/dist/hub/member/room-post-answers.js.map +1 -0
  115. package/dist/hub/member/room-post-receipt.d.ts +21 -0
  116. package/dist/hub/member/room-post-receipt.js +49 -0
  117. package/dist/hub/member/room-post-receipt.js.map +1 -0
  118. package/dist/hub/member/room-post.d.ts +100 -0
  119. package/dist/hub/member/room-post.js +223 -0
  120. package/dist/hub/member/room-post.js.map +1 -0
  121. package/dist/hub/member/updates.d.ts +92 -0
  122. package/dist/hub/member/updates.js +316 -0
  123. package/dist/hub/member/updates.js.map +1 -0
  124. package/dist/hub/protocol.d.ts +658 -1
  125. package/dist/hub/protocol.js +90 -13
  126. package/dist/hub/protocol.js.map +1 -1
  127. package/dist/hub/published-version.d.ts +3 -0
  128. package/dist/hub/published-version.js +35 -0
  129. package/dist/hub/published-version.js.map +1 -0
  130. package/dist/hub/recommendation-model.d.ts +36 -0
  131. package/dist/hub/recommendation-model.js +9 -0
  132. package/dist/hub/recommendation-model.js.map +1 -0
  133. package/dist/hub/recommendations.d.ts +58 -0
  134. package/dist/hub/recommendations.js +211 -0
  135. package/dist/hub/recommendations.js.map +1 -0
  136. package/dist/hub/representative.d.ts +3 -0
  137. package/dist/hub/representative.js +2 -1
  138. package/dist/hub/representative.js.map +1 -1
  139. package/dist/hub/room-context-model.d.ts +43 -0
  140. package/dist/hub/room-context-model.js +12 -0
  141. package/dist/hub/room-context-model.js.map +1 -0
  142. package/dist/hub/rooms/agents.d.ts +41 -9
  143. package/dist/hub/rooms/agents.js +183 -21
  144. package/dist/hub/rooms/agents.js.map +1 -1
  145. package/dist/hub/rooms/assistant.d.ts +1 -6
  146. package/dist/hub/rooms/assistant.js +7 -2
  147. package/dist/hub/rooms/assistant.js.map +1 -1
  148. package/dist/hub/rooms/automation.d.ts +24 -0
  149. package/dist/hub/rooms/automation.js +66 -0
  150. package/dist/hub/rooms/automation.js.map +1 -0
  151. package/dist/hub/rooms/buttons.d.ts +85 -0
  152. package/dist/hub/rooms/buttons.js +62 -0
  153. package/dist/hub/rooms/buttons.js.map +1 -0
  154. package/dist/hub/rooms/context-cursor.d.ts +18 -0
  155. package/dist/hub/rooms/context-cursor.js +61 -0
  156. package/dist/hub/rooms/context-cursor.js.map +1 -0
  157. package/dist/hub/rooms/context.d.ts +1 -1
  158. package/dist/hub/rooms/context.js +4 -4
  159. package/dist/hub/rooms/context.js.map +1 -1
  160. package/dist/hub/rooms/mentions.d.ts +15 -0
  161. package/dist/hub/rooms/mentions.js +43 -0
  162. package/dist/hub/rooms/mentions.js.map +1 -0
  163. package/dist/hub/rooms/post-replies.d.ts +23 -0
  164. package/dist/hub/rooms/post-replies.js +114 -0
  165. package/dist/hub/rooms/post-replies.js.map +1 -0
  166. package/dist/hub/rooms/schema.d.ts +9 -0
  167. package/dist/hub/rooms/schema.js +43 -0
  168. package/dist/hub/rooms/schema.js.map +1 -1
  169. package/dist/hub/rooms/service.d.ts +136 -1
  170. package/dist/hub/rooms/service.js +727 -18
  171. package/dist/hub/rooms/service.js.map +1 -1
  172. package/dist/hub/rooms/types.d.ts +27 -3
  173. package/dist/hub/rooms.js +1 -1
  174. package/dist/hub/rooms.js.map +1 -1
  175. package/dist/hub/runtime.d.ts +1 -1
  176. package/dist/hub/runtime.js +12 -0
  177. package/dist/hub/runtime.js.map +1 -1
  178. package/dist/hub/server.d.ts +6 -1
  179. package/dist/hub/server.js +75 -5
  180. package/dist/hub/server.js.map +1 -1
  181. package/dist/hub/settings-directory-proof.js +22 -1
  182. package/dist/hub/settings-directory-proof.js.map +1 -1
  183. package/dist/hub/types.d.ts +133 -2
  184. package/dist/hub-contact-windows.d.ts +11 -0
  185. package/dist/hub-contact-windows.js +56 -0
  186. package/dist/hub-contact-windows.js.map +1 -0
  187. package/dist/hub-pairing-summary.d.ts +1 -1
  188. package/dist/hub-room-conversation.d.ts +14 -0
  189. package/dist/hub-room-conversation.js +60 -0
  190. package/dist/hub-room-conversation.js.map +1 -0
  191. package/dist/hub-update-notice.d.ts +12 -0
  192. package/dist/hub-update-notice.js +35 -0
  193. package/dist/hub-update-notice.js.map +1 -0
  194. package/dist/locale.js +58 -2
  195. package/dist/locale.js.map +1 -1
  196. package/dist/native-mcp.js +9 -6
  197. package/dist/native-mcp.js.map +1 -1
  198. package/dist/outbound-handlers.d.ts +14 -4
  199. package/dist/outbound-handlers.js +54 -1
  200. package/dist/outbound-handlers.js.map +1 -1
  201. package/dist/outbound-schemas.d.ts +12 -0
  202. package/dist/outbound-schemas.js +12 -0
  203. package/dist/outbound-schemas.js.map +1 -1
  204. package/dist/pane-port.d.ts +2 -0
  205. package/dist/queued-handoffs.d.ts +16 -4
  206. package/dist/queued-handoffs.js +18 -1
  207. package/dist/queued-handoffs.js.map +1 -1
  208. package/dist/runtime-cli-install.js +13 -10
  209. package/dist/runtime-cli-install.js.map +1 -1
  210. package/dist/settings-api.d.ts +1 -0
  211. package/dist/settings-api.js +87 -0
  212. package/dist/settings-api.js.map +1 -1
  213. package/dist/tmux-manager.d.ts +2 -0
  214. package/dist/tmux-manager.js +2 -0
  215. package/dist/tmux-manager.js.map +1 -1
  216. package/dist/tool-permissions.js +3 -0
  217. package/dist/tool-permissions.js.map +1 -1
  218. package/dist/ui/chat-msg-actions.js +3 -222
  219. package/dist/ui/hub-admin-overview.js +189 -0
  220. package/dist/ui/hub-client.js +36 -4
  221. package/dist/ui/hub-fleet-versions.js +393 -0
  222. package/dist/ui/hub-room-agent-strings.js +28 -0
  223. package/dist/ui/hub-room-composer.js +16 -8
  224. package/dist/ui/hub-room-members-strings.js +2 -2
  225. package/dist/ui/hub-room-members.js +3 -2
  226. package/dist/ui/hub-room-notify.js +161 -0
  227. package/dist/ui/hub-room-search.js +126 -0
  228. package/dist/ui/hub-room-strings.js +47 -1
  229. package/dist/ui/hub-room-thread.js +243 -35
  230. package/dist/ui/hub-room-unread.js +2 -1
  231. package/dist/ui/hub-strings.js +8 -0
  232. package/dist/ui/image-annotate.js +2 -283
  233. package/dist/ui/image-lightbox.js +2 -176
  234. package/dist/ui/image-zoom.js +2 -242
  235. package/dist/ui/notice-hub-update.js +94 -0
  236. package/dist/ui/panel-chat.js +121 -12
  237. package/dist/ui/panel-hub.js +133 -19
  238. package/dist/ui/panel-notices.js +3 -1
  239. package/dist/ui/panel-settings.js +1 -1
  240. package/dist/ui/settings-hub-updates.js +67 -0
  241. package/dist/ui/settings-hub.js +28 -3
  242. package/dist/ui/settings-registry.js +1 -0
  243. package/dist/ui/settings-update.js +11 -5
  244. package/dist/ui/settings-web-authority.js +1 -1
  245. package/dist/ui/shared/app-i18n.js +2 -0
  246. package/dist/ui/shared/app-nav.js +6 -2
  247. package/dist/ui/shared/app-prefs.js +2 -1
  248. package/dist/ui/shared/app-shell.js +29 -4
  249. package/dist/ui/shared/app-update.js +90 -8
  250. package/dist/ui/shared/app.css +33 -0
  251. package/dist/ui/shared/chat-composer.js +6 -3
  252. package/dist/ui/shared/chat-msg-actions.js +225 -0
  253. package/dist/ui/shared/chat-thread.js +70 -5
  254. package/dist/ui/shared/chat-work-bar.css +48 -0
  255. package/dist/ui/shared/hub-chat.css +16 -2
  256. package/dist/ui/shared/hub-owner.css +104 -0
  257. package/dist/ui/shared/hub-rooms-u2.css +16 -0
  258. package/dist/ui/shared/hub.css +5 -0
  259. package/dist/ui/shared/image-annotate.js +306 -0
  260. package/dist/ui/shared/image-lightbox.js +183 -0
  261. package/dist/ui/shared/image-zoom.js +242 -0
  262. package/dist/ui/shared/instance-nav.js +36 -7
  263. package/dist/ui/shared/model-picker.css +4 -3
  264. package/dist/ui/shared/view-strings.js +8 -0
  265. package/dist/ui/shared/web-authorize.js +2 -2
  266. package/dist/update-dispatch.d.ts +8 -1
  267. package/dist/update-dispatch.js +16 -1
  268. package/dist/update-dispatch.js.map +1 -1
  269. package/dist/update-idle.d.ts +65 -0
  270. package/dist/update-idle.js +190 -0
  271. package/dist/update-idle.js.map +1 -0
  272. package/dist/update-launch.d.ts +1 -1
  273. package/dist/update-launch.js +9 -2
  274. package/dist/update-launch.js.map +1 -1
  275. package/dist/usage/i18n-keys.d.ts +1 -1
  276. package/dist/usage/i18n-keys.js +1 -1
  277. package/dist/usage/i18n-keys.js.map +1 -1
  278. package/dist/usage/profile-timeline.d.ts +2 -0
  279. package/dist/usage/profile-timeline.js +4 -0
  280. package/dist/usage/profile-timeline.js.map +1 -1
  281. package/dist/usage/providers.js +4 -4
  282. package/dist/usage/providers.js.map +1 -1
  283. package/dist/usage/quota-history.d.ts +1 -1
  284. package/dist/view-api.js +1 -1
  285. package/dist/view-api.js.map +1 -1
  286. package/dist/web-api.js +19 -2
  287. package/dist/web-api.js.map +1 -1
  288. package/dist/web-notices.d.ts +3 -0
  289. package/dist/web-notices.js +17 -2
  290. package/dist/web-notices.js.map +1 -1
  291. package/dist/web-prefs.js +1 -0
  292. package/dist/web-prefs.js.map +1 -1
  293. package/dist/web-update.d.ts +15 -1
  294. package/package.json +1 -1
@@ -8,20 +8,33 @@
8
8
  // The store reads the room (seam 1 of docs/design/hub-rooms-split.md), keeps it live from the tab's one stream, sends with
9
9
  // an idempotency key, and answers HubThread's store interface.
10
10
  import { html, useEffect, useMemo, useRef, useState } from "/assets/app-html.js";
11
+ import { agentStopText, hra } from "./hub-room-agent-strings.js";
11
12
  import { WorkBarView } from "/assets/chat-composer.js";
12
13
  import { RailFrame } from "/assets/side-rail.js";
13
14
  import { Icon } from "/assets/ui-icons.js";
14
15
  import { Empty } from "/assets/ui-states.js";
15
16
  import { Dialog } from "/assets/ui-dialog.js";
16
17
  import { Menu } from "/assets/ui-menu.js";
17
- import { t } from "/assets/app-i18n.js";
18
+ import { toast } from "/assets/ui-toast.js";
19
+ import { register, t } from "/assets/app-i18n.js";
18
20
  import "./hub-strings.js";
19
21
  import { firstCharacter } from "/assets/instance-nav.js";
20
22
  import { hroom } from "./hub-room-strings.js";
21
23
  import { RoomComposer } from "./hub-room-composer.js";
24
+ import { TextSizeButton } from "/assets/header-tools.js";
25
+ import { HubNotifyToggle } from "./hub-room-notify.js";
26
+ import { createHubButtonActions } from "./hub-button-actions.js";
27
+ import { linkRoomsU2Css } from "./hub-room-new-strings.js";
22
28
  import { workingLine } from "./hub-room-working.js";
23
29
  import { countsLine } from "./hub-room-list.js";
30
+ import { PendingFiles, hf, hubFileAttachment, pageCarriesFiles, roomTakesFiles, uploadChosen } from "./hub-attachments.js";
31
+ import { LightboxHost, openLightbox } from "/assets/image-lightbox.js";
32
+ // M-3125 PR3: the one quote target an annotated room picture has (here, so a page with an older dictionary has the words).
33
+ register("hubRoomAnnotate", { en: { quote: "Quote in this room" }, "zh-TW": { quote: "引用到這個房間" } });
24
34
 
35
+ linkRoomsU2Css(); // M-3127: the reaction chips and picker are drawn from hub-rooms-u2.css (a room opened before any U2 panel)
36
+ /** M-3127 C: the message a search hit opens (`?room=…&m=<id>`), or null. */
37
+ export const jumpParam = () => { try { const v = new URLSearchParams(location.search).get("m"); return v && /^[A-Za-z0-9-]{1,64}$/.test(v) ? v : null; } catch { return null; } };
25
38
  const iso = (ms) => (Number.isFinite(ms) && ms > 0 ? new Date(ms).toISOString() : undefined);
26
39
  const BOOT = "room";
27
40
 
@@ -31,7 +44,9 @@ const BOOT = "room";
31
44
  * 「Hub 助理」 in its own one-to-one (`direct`).
32
45
  */
33
46
  export function authorLine(author, mine = false, direct = false) {
34
- if (!author || mine) return "";
47
+ if (!author) return "";
48
+ if (author.via?.name) return hra("via", String(author.name || ""), String(author.via.name));
49
+ if (mine) return "";
35
50
  if (author.kind === "assistant") return direct ? hroom("hubAssistant") : hroom("authorAssistant");
36
51
  if (author.kind === "agent") {
37
52
  if (!author.owner?.name) return String(author.name || "");
@@ -45,20 +60,66 @@ export function authorLine(author, mine = false, direct = false) {
45
60
  * A room's own line in this viewer's words (Ridge: `system` { kind, name } beside the stored text): a kind this page does
46
61
  * not know, or an older row without `system`, keeps the stored text.
47
62
  */
48
- const SYSTEM = { "room-created": "createdSys", "member-joined": "sysJoined", "admin-joined": "sysAdminJoined" };
63
+ const SYSTEM = { "room-created": "createdSys", "member-joined": "sysJoined", "admin-joined": "sysAdminJoined", "poll-closed": "sysPollClosed" };
49
64
  export function systemText(m) {
65
+ if (m?.system?.kind === "agent-mention-stopped") return agentStopText(m.system) ?? String(m.text || "");
50
66
  const key = m && m.system && SYSTEM[m.system.kind];
51
67
  return key && typeof m.system.name === "string" ? hroom(key, m.system.name) : String((m && m.text) || "");
52
68
  }
53
69
  /**
54
70
  * The progress of a message that asked agents (spec §3, Lumen): one agent → its delivery mark; several → one line, its
55
- * parts without a 0 ("Answered 1 · Working 1"); every one answered → the delivered tick again, no line.
71
+ * parts without a 0 ("Answered 1 · Working 1"); every one answered → the delivered tick again, no line. Failed (!) and
72
+ * blocked (⊘) use the Fleet ticks: `failed` / `blocked` on `ask` when the server sends them, else a `not-answered`
73
+ * child counts as failed.
56
74
  */
75
+ const count = (v) => (Number.isSafeInteger(v) && v > 0 ? v : 0);
76
+ const REASON = { expired: "reasonExpired", unavailable: "reasonUnavailable", interrupted: "reasonInterrupted", retired: "reasonRetired", unknown: "reasonUnknown" };
77
+ export function askReason(code) { return REASON[code] ? hroom(REASON[code]) : ""; }
57
78
  export function askState(ask) {
58
79
  if (!ask || !Number.isSafeInteger(ask.total) || ask.total < 1) return null;
59
- if (ask.total === 1 || ask.answered >= ask.total) return { delivery: ask.answered >= ask.total ? "delivered" : ask.working >= 1 ? "processing" : "queued" };
60
- const parts = [[ask.answered, "progAnswered"], [ask.working, "progWorking"], [ask.later, "progLater"]].filter(([n]) => Number(n) > 0).map(([n, k]) => hroom(k, String(n)));
61
- return { line: parts.join(" · ") };
80
+ const answered = count(ask.answered), working = count(ask.working), later = count(ask.later);
81
+ const failed = count(ask.failed), blocked = count(ask.blocked);
82
+ const reason = typeof ask.reason === "string" && ask.reason ? ask.reason : "";
83
+ const parts = [[answered, "progAnswered"], [working, "progWorking"], [later, "progLater"], [failed, "progFailed"], [blocked, "progBlocked"]]
84
+ .filter(([n]) => n > 0).map(([n, k]) => hroom(k, String(n)));
85
+ const allIn = answered + failed + blocked >= ask.total && working < 1 && later < 1;
86
+ if (ask.total === 1 || (allIn && failed < 1 && blocked < 1)) {
87
+ const delivery = answered >= ask.total ? "delivered" : working >= 1 ? "processing" : failed >= 1 ? "failed" : blocked >= 1 ? "cancelled" : "queued";
88
+ return { delivery, ...(reason && (delivery === "failed" || delivery === "cancelled") ? { reason } : {}) };
89
+ }
90
+ return { line: parts.join(" · "), ...(reason ? { reason } : {}) };
91
+ }
92
+ /** When the server has not yet named failed/blocked, a stored `not-answered` child is failed. */
93
+ function askOf(m, messages) {
94
+ const ask = m && m.ask;
95
+ if (!ask) return ask;
96
+ if (Number.isSafeInteger(ask.failed) || Number.isSafeInteger(ask.blocked)) return ask;
97
+ const notAns = messages.filter((x) => x.answerTo === m.id && x.stage === "not-answered").length;
98
+ return notAns ? { ...ask, failed: notAns } : ask;
99
+ }
100
+ /**
101
+ * M-3127: a message's reactions as the thread's chips — `mine` from my member id, the label naming who (from the room's
102
+ * members; someone no longer listed counts among "others"): 「Alex、Bob 和其他 3 人 回應了 👍」.
103
+ */
104
+ export function reactionBar(reactions, { meId = "", names = new Map() } = {}) {
105
+ if (!Array.isArray(reactions)) return undefined;
106
+ return reactions.filter((r) => r && typeof r.emoji === "string" && Number(r.count) > 0).map((r) => {
107
+ const members = Array.isArray(r.members) ? r.members : [], mine = members.includes(meId);
108
+ const known = members.filter((id) => id !== meId && names.has(id)).map((id) => names.get(id));
109
+ const who = [...(mine ? [hroom("reactYou")] : []), ...known].slice(0, 3), rest = Number(r.count) - who.length;
110
+ const list = who.join(hroom("listSep"));
111
+ return { emoji: r.emoji, count: Number(r.count), mine, label: hroom("reactedWith", rest > 0 ? (who.length ? hroom("reactMore", list, String(rest)) : String(r.count)) : list, r.emoji) };
112
+ });
113
+ }
114
+ /**
115
+ * M-3127 B: an answer's buttons as the thread draws them. A poll is everyone's. Plain buttons answer only the question's
116
+ * asker: anyone else sees them shut, with whose they are (「只有 Alex 能回答」); the asker sees them open.
117
+ */
118
+ export function roomButtons(b, meId = "") {
119
+ if (!b || typeof b.id !== "string" || !Array.isArray(b.labels)) return undefined;
120
+ const { asker, ...view } = b;
121
+ if (view.poll || !asker || asker.id === meId || view.state !== "open") return view;
122
+ return { ...view, state: "locked", note: hroom("onlyAsker", String(asker.name || "")) };
62
123
  }
63
124
  /** How many answers of one question show when they are folded, and from how many they fold (Lumen: all up to 5). */
64
125
  export const ANSWERS_SHOWN = 3, FOLD_FROM = 6;
@@ -67,14 +128,16 @@ export const ANSWERS_SHOWN = 3, FOLD_FROM = 6;
67
128
  * Seam-1 messages (newest last) → the thread's messages. `ids`: a Map from a message id to its number in this thread
68
129
  * (the thread's keys and quotes are numbers), extended here in arrival order and kept by the caller.
69
130
  */
70
- export function toThreadMessages(messages, { meId, ids, direct = false, expanded = new Set(), summarise = false }) {
131
+ export function toThreadMessages(messages, { meId, ids, direct = false, expanded = new Set(), summarise = false, names = new Map() }) {
132
+ const stops = messages.filter(m => m?.system?.kind === "agent-mention-stopped"), ordered = messages.filter(m => !stops.includes(m));
133
+ for (const stop of stops) { const parent = ordered.findIndex(m => m.id === stop.system.sourceId); if (parent < 0) ordered.push(stop); else { let i = parent + 1; while (ordered[i]?.system?.sourceId === stop.system.sourceId) i++; ordered.splice(i, 0, stop); } }
71
134
  const out = [], byId = new Map(messages.map((m) => [m.id, m]));
72
135
  // Each question's answers that have text, in arrival order: past ANSWERS_SHOWN they wait behind one 「展開其餘 N 則」.
73
136
  const answersOf = new Map();
74
- const drawn = (m) => !!m.text || m.stage === "not-answered"; // an answer that shows: its text, or that none came (Ridge)
137
+ const drawn = (m) => !!m.text || (Array.isArray(m.files) && m.files.length > 0) || m.stage === "not-answered"; // its text or files (M-3125), or that none came (Ridge)
75
138
  for (const m of messages) if (m && m.answerTo && drawn(m)) answersOf.set(m.answerTo, [...(answersOf.get(m.answerTo) || []), m.id]);
76
139
  const num = (id) => { if (!ids.has(id)) ids.set(id, ids.size * 2 + 2); return ids.get(id); };
77
- for (const m of messages) {
140
+ for (const m of ordered) {
78
141
  if (!m || typeof m.id !== "string") continue;
79
142
  const author = m.author || {}, kind = author.kind;
80
143
  // An answer still to come (queued, or being worked on: the working bar says who) is never an empty bubble.
@@ -89,23 +152,30 @@ export function toThreadMessages(messages, { meId, ids, direct = false, expanded
89
152
  if (folded && at === ANSWERS_SHOWN - 1) foldAfter = { label: hroom("expandRest", String(list.length - ANSWERS_SHOWN)), arg: m.answerTo };
90
153
  lastShown = at >= 0 && at === (folded ? ANSWERS_SHOWN - 1 : list.length - 1);
91
154
  }
92
- const id = num(m.id), mine = kind === "person" && author.id === meId;
93
- if (kind === "system") { out.push({ boot: BOOT, id, role: "status", sender: "", ts: iso(m.at), text: systemText(m), bare: true }); continue; }
155
+ const id = num(m.id), mine = kind === "person" && !author.via && author.id === meId;
156
+ if (kind === "system") { out.push({ boot: BOOT, id, role: "status", sender: "", ...(m.system?.kind === "agent-mention-stopped" ? { wrap: true } : { ts: iso(m.at) }), text: systemText(m), bare: true }); continue; }
94
157
  // An answer is a reply to the message that asked for it (the Fleet's reply reference): replyTo, else answerTo.
95
- const quoted = m.replyTo ? byId.get(m.replyTo) : m.answerTo ? byId.get(m.answerTo) : null;
96
- const state = mine ? askState(m.ask) : null;
97
- out.push({ boot: BOOT, id, role: kind === "person" ? "user" : "agent", sender: authorLine(author, mine, direct), ts: iso(m.at), text: String(m.text || ""), mine,
98
- ...(kind === "person" && !mine ? { person: true } : {}), // Lumen (spec §3): someone else's words, a bubble on the left
99
- roomMessage: m.id, ...(state?.delivery ? { delivery: state.delivery } : {}),
100
- ...(quoted ? { replyTo: { boot: BOOT, id: num(quoted.id), sender: authorLine(quoted.author, quoted.author?.id === meId, direct), text: String(quoted.text || "").slice(0, 120) } } : {}),
158
+ // The quote chip keeps a stable key even when that original is not in this page (scroll-up / findQuoted loads it).
159
+ const quotedId = m.replyTo || m.answerTo || "";
160
+ const quoted = quotedId ? byId.get(quotedId) : null;
161
+ const state = askState(askOf(m, messages));
162
+ out.push({ boot: BOOT, id, role: kind === "person" && !author.via ? "user" : "agent", sender: authorLine(author, mine, direct), ts: iso(m.at), text: String(m.text || ""), mine,
163
+ ...(kind === "person" && !mine && !author.via ? { person: true } : {}), // Lumen (spec §3): someone else's words, a bubble on the left
164
+ roomMessage: m.id, ...(mine && state?.delivery ? { delivery: state.delivery } : {}),
165
+ // M-3125: a post's files, as the 1:1 chat maps them (images inline through the Hub's own route; HTML gets its preview card).
166
+ ...(() => { const files = Array.isArray(m.files) ? m.files.map(hubFileAttachment).filter(Boolean) : []; return files.length ? { attachments: files } : {}; })(),
167
+ ...(!direct && Array.isArray(m.reactions) && m.reactions.length ? { reactionBar: reactionBar(m.reactions, { meId, names }) } : {}),
168
+ ...(!direct && kind !== "person" && m.buttons ? { buttons: roomButtons(m.buttons, meId) } : {}),
169
+ ...(quotedId ? { replyTo: { boot: BOOT, id: num(quotedId), sender: quoted ? authorLine(quoted.author, quoted.author?.id === meId, direct) : "", text: quoted ? String(quoted.text || "").slice(0, 120) : "" } } : {}),
101
170
  ...(m.stage === "not-answered" ? { text: hroom("noAnswer") } : {}) });
102
171
  if (foldAfter) out.push({ boot: BOOT, id: num(`expand:${foldAfter.arg}`), role: "status", sender: "", text: "", bare: true, fold: true, action: foldAfter });
103
172
  // Spec §10: once an @所有 Agent has answers, under the last one shown, 「請房間助理整理」 (it sends 「@房間助理 整理上面的回答」).
104
173
  if (summarise && lastShown && byId.get(m.answerTo)?.mentions?.includes("all"))
105
174
  out.push({ boot: BOOT, id: num(`summarise:${m.answerTo}`), role: "status", sender: "", text: "", bare: true, action: { label: hroom("askSummarise"), arg: `summarise:${m.answerTo}` } });
106
- const line = askState(m.ask)?.line;
175
+ const line = state?.line, why = !line && mine ? askReason(state?.reason) : "";
107
176
  // Its status, not an event: under it, without a time of its own.
108
177
  if (line) out.push({ boot: BOOT, id: id + 1, role: "status", sender: "", text: line, progressOf: m.id, bare: true });
178
+ else if (why) out.push({ boot: BOOT, id: id + 1, role: "status", sender: "", text: why, progressOf: m.id, bare: true });
109
179
  if (mine && m.warning === "assistant-unavailable") out.push({ boot: BOOT, id: id + 1, role: "status", sender: "", ts: iso(m.at), text: hroom("errAssistant"), bare: true });
110
180
  }
111
181
  return out;
@@ -115,21 +185,24 @@ export function toThreadMessages(messages, { meId, ids, direct = false, expanded
115
185
  * One room's store: `subscribe(fn)` → unsubscribe; `detail()` (the room GET: room, me, members, settings), `messages()`
116
186
  * (the thread's), `raw()` (seam-1 messages), `loaded()`, `error()`, `closed()` (archived, or I am no longer in it), `room()`;
117
187
  * `send(text, { mentions, replyTo })` → the client's answer (a refusal's code is the caller's to word; a soft warning is
118
- * stored and drawn), `older()`, `markRead()`, `refresh()`, `stop()`. Reply buttons are not part of rooms: their calls are inert.
188
+ * stored and drawn), `older()`, `findQuoted(key)`, `markRead()`, `refresh()`, `stop()`. M-3127 B: `clickButton` / `vote` / `busy` / `mine` are the direct chat's button actions (hub-button-actions.js), on group rooms only.
119
189
  */
120
190
  export function createRoomStore(roomId, { client, meId = "" } = {}) {
121
191
  const subs = new Set(), ids = new Map(), expanded = new Set();
122
192
  const st = { live: true, detail: null, messages: [], loaded: false, error: null, removed: false, more: false, view: [] };
193
+ let loadingOlder = false;
123
194
  // The room's committed order (Ridge: `sequence`, from the stored row): a waiting answer replaced in place, or an event that
124
195
  // arrives out of order, is drawn where the room has it. Rows without it (a direct chat, an older Hub) keep arrival order.
125
196
  const closedNow = () => st.removed || st.detail?.room?.archived === true;
126
197
  const ordered = () => { if (st.messages.length && st.messages.every((m) => Number.isSafeInteger(m.sequence))) st.messages.sort((a, b) => a.sequence - b.sequence); };
127
198
  const changed = () => { ordered(); st.view = toThreadMessages(st.messages, { meId: st.detail?.me?.id || meId, ids, direct: st.detail?.room?.kind === "direct", expanded,
128
- summarise: st.detail?.room?.kind === "group" && (st.detail?.members || []).some((x) => x.kind === "assistant") && !closedNow() }); for (const fn of [...subs]) { try { fn(); } catch { /* a subscriber's own failure */ } } };
199
+ summarise: st.detail?.room?.kind === "group" && (st.detail?.members || []).some((x) => x.kind === "assistant") && !closedNow(),
200
+ names: new Map((st.detail?.members || []).filter((x) => x && typeof x.id === "string").map((x) => [x.id, x.kind === "assistant" ? hroom("roomAssistant") : String(x.name || "")])) }); for (const fn of [...subs]) { try { fn(); } catch { /* a subscriber's own failure */ } } };
129
201
  const upsert = (m) => {
130
202
  if (!m || m.roomId !== roomId || typeof m.id !== "string") return;
131
203
  const i = st.messages.findIndex((x) => x.id === m.id || (m.idempotencyKey && x.idempotencyKey === m.idempotencyKey));
132
- if (i >= 0) st.messages[i] = { ...st.messages[i], ...m }; else st.messages.push(m);
204
+ // The server always sends the whole message: one without reactions has none left (M-3127), never the old ones.
205
+ if (i >= 0) { const next = { ...st.messages[i], ...m }; if (!("reactions" in m)) delete next.reactions; st.messages[i] = next; } else st.messages.push(m);
133
206
  };
134
207
  const readDetail = async () => { const d = await client.room(roomId); if (!st.live) return; if (d.ok) st.detail = d; else if (!st.detail) st.error = d.code || "failed"; };
135
208
  async function refresh() {
@@ -141,6 +214,11 @@ export function createRoomStore(roomId, { client, meId = "" } = {}) {
141
214
  changed();
142
215
  }
143
216
  const on = (fn) => (data) => { if (st.live && data && data.roomId === roomId) { fn(data); changed(); } };
217
+ // M-3127 B: an answer's buttons and polls — the direct chat's own actions (one key per intent, my vote kept in this tab),
218
+ // on this room's messages; the Hub says who may press (403 not-asker) and closes polls.
219
+ const actions = createHubButtonActions({ id: roomId, get features() { return closedNow() || st.detail?.room?.kind !== "group" ? [] : ["buttons-v1"]; } }, {
220
+ client, entries: () => st.view, refresh: () => refresh(), changed: () => { for (const fn of [...subs]) { try { fn(); } catch { /* a subscriber's own failure */ } } },
221
+ });
144
222
  const unsubscribe = typeof client.subscribeRooms === "function" ? client.subscribeRooms({
145
223
  "message.added": on((d) => upsert(d.message)),
146
224
  "message.updated": on((d) => { upsert(d.message); if (d.parent) { const p = st.messages.find((x) => x.id === d.parent.id); if (p) p.ask = d.parent.ask; } }),
@@ -151,15 +229,50 @@ export function createRoomStore(roomId, { client, meId = "" } = {}) {
151
229
  "member.changed": on(() => { void readDetail().then(changed); }),
152
230
  "room.changed": on((d) => { if (d.removed) st.removed = true; else if (d.room && st.detail) st.detail = { ...st.detail, room: { ...st.detail.room, ...d.room } }; }),
153
231
  }) : () => {};
232
+ /** One page older than what is held (the server's `before=`). False when there was nothing to fetch. */
233
+ async function older() {
234
+ if (!st.live || loadingOlder || !st.more) return false;
235
+ const first = st.messages[0]; if (!first) return false;
236
+ loadingOlder = true;
237
+ let did = false;
238
+ try {
239
+ const page = await client.roomMessages(roomId, { before: first.id, limit: 50 });
240
+ if (!st.live || !page.ok) return false;
241
+ const incoming = (page.messages || []).filter((m) => !st.messages.some((x) => x.id === m.id));
242
+ if (!incoming.length) st.more = false;
243
+ else { st.messages = [...incoming, ...st.messages]; st.more = page.more === true; did = true; }
244
+ } finally { loadingOlder = false; }
245
+ changed();
246
+ return did;
247
+ }
248
+ /** The thread's quote key (`room-N`) or a stored message id: load pages until that row is held, then true. */
249
+ async function findQuoted(key) {
250
+ if (typeof key !== "string" || !key) return false;
251
+ const wanted = st.messages.some((m) => m.id === key) ? key : (() => {
252
+ const n = Number(key.startsWith(`${BOOT}-`) ? key.slice(BOOT.length + 1) : key);
253
+ if (!Number.isSafeInteger(n)) return null;
254
+ for (const [id, v] of ids) if (v === n) return id;
255
+ return null;
256
+ })();
257
+ if (!wanted) return false;
258
+ while (st.live && !st.messages.some((m) => m.id === wanted) && st.more) {
259
+ const n = st.messages.length;
260
+ await older();
261
+ if (st.messages.length === n) break;
262
+ }
263
+ return st.messages.some((m) => m.id === wanted);
264
+ }
154
265
  void refresh();
155
266
  return {
156
267
  subscribe(fn) { subs.add(fn); return () => subs.delete(fn); },
157
268
  detail: () => st.detail, raw: () => st.messages, messages: () => st.view, loaded: () => st.loaded, error: () => st.error,
158
269
  closed: closedNow, removed: () => st.removed, more: () => st.more,
159
270
  room: () => ({ ...(st.detail?.room || {}), ownerName: "" }),
160
- async send(text, { mentions = [], replyTo } = {}) {
271
+ // M-3125: this store carries files (pageCarriesFiles reads the mark), sent as the post's `files`.
272
+ filesV1: true,
273
+ async send(text, { mentions = [], replyTo, files } = {}) {
161
274
  const idempotencyKey = (globalThis.crypto?.randomUUID?.() || `${Date.now()}-${Math.random()}`).replace(/[^A-Za-z0-9-]/g, "");
162
- const r = await client.sendRoomMessage(roomId, { text, mentions, replyTo, idempotencyKey });
275
+ const r = await client.sendRoomMessage(roomId, { text, mentions, replyTo, idempotencyKey, ...(files?.length ? { files } : {}) });
163
276
  // The stored message, as the Hub answers it: `{ message }`, or the message itself (Ridge's server) — drawn at once,
164
277
  // whether or not the stream is up yet (a first send after opening the room must not vanish).
165
278
  const { ok, ...bare } = r || {};
@@ -167,11 +280,24 @@ export function createRoomStore(roomId, { client, meId = "" } = {}) {
167
280
  if (ok && sent) { upsert(sent); changed(); }
168
281
  return r;
169
282
  },
170
- async older() {
171
- const first = st.messages[0]; if (!first || !st.more) return;
172
- const page = await client.roomMessages(roomId, { before: first.id, limit: 50 });
173
- if (!st.live || !page.ok) return;
174
- st.messages = [...(page.messages || []).filter((m) => !st.messages.some((x) => x.id === m.id)), ...st.messages]; st.more = page.more === true; changed();
283
+ older, findQuoted,
284
+ /**
285
+ * M-3127 C: the thread key of message `messageId`, loading older pages (at most 40) until it is here, and opening its
286
+ * question's folded answers when it is one of them; null when this room no longer has it (or I may not see it).
287
+ */
288
+ async find(messageId) {
289
+ for (let i = 0; i <= 40 && st.live; i++) {
290
+ const m = st.messages.find((x) => x.id === messageId);
291
+ if (m) {
292
+ if (m.answerTo && !expanded.has(m.answerTo)) { expanded.add(m.answerTo); changed(); }
293
+ const x = st.view.find((v) => v.roomMessage === messageId);
294
+ return x ? `${x.boot}-${x.id}` : null;
295
+ }
296
+ if (!st.more) return null;
297
+ const before = st.messages.length; await older();
298
+ if (st.messages.length === before) return null; // a page that failed or brought nothing new
299
+ }
300
+ return null;
175
301
  },
176
302
  /** 「展開其餘 N 則」: show every answer of that question. */
177
303
  expand(messageId) { if (typeof messageId === "string" && !expanded.has(messageId)) { expanded.add(messageId); changed(); } },
@@ -179,9 +305,20 @@ export function createRoomStore(roomId, { client, meId = "" } = {}) {
179
305
  working() { return this.workers().map((w) => w.name); },
180
306
  /** The same, as members ({ kind, name }) — what workingLine() words (the room assistant by its own name). */
181
307
  workers() { return st.messages.filter((m) => m.answerTo && !m.text && m.stage === "working" && m.author?.name).map((m) => ({ kind: m.author.kind === "assistant" ? "assistant" : "agent", name: String(m.author.name) })); },
308
+ /**
309
+ * M-3127: add or take back my reaction on a message of this group room. The answer's reactions are drawn at once (the
310
+ * stream's message.updated brings the same); a refusal leaves the message as it was → the client's answer.
311
+ */
312
+ async react(messageId, emoji, on) {
313
+ if (closedNow() || st.detail?.room?.kind !== "group" || typeof client.reactRoomMessage !== "function") return { ok: false, code: "closed" };
314
+ const r = await client.reactRoomMessage(roomId, messageId, emoji, on);
315
+ const m = st.messages.find((x) => x.id === messageId);
316
+ if (st.live && r?.ok && m && Array.isArray(r.reactions)) { if (r.reactions.length) m.reactions = r.reactions; else delete m.reactions; changed(); }
317
+ return r;
318
+ },
182
319
  markRead() { const last = st.messages.at(-1); return last ? client.markRoomRead(roomId, last.id) : Promise.resolve({ ok: true }); },
183
- refresh, clickButton: async () => ({ ok: false, code: "stopped" }), vote: async () => ({ ok: false, code: "stopped" }), busy: () => false, mine: () => [],
184
- stop() { st.live = false; subs.clear(); unsubscribe(); },
320
+ refresh, clickButton: actions.clickButton, vote: actions.vote, busy: actions.busy, mine: actions.mine,
321
+ stop() { st.live = false; subs.clear(); unsubscribe(); actions.stop(); },
185
322
  };
186
323
  }
187
324
 
@@ -208,13 +345,19 @@ function useMembersPanel() {
208
345
  * Fleet chat's thread (panel-hub.js's HubThread, given as `Thread`: the thread wiring is one), the room's composer, and
209
346
  * the members panel on the right. `client`: the Hub client; `me`: { id } from the session.
210
347
  */
211
- export function HubRoomPage({ roomId, listed = null, Thread, client, meId = "", rooms = [], openRoom = () => {}, goList = () => {}, onLeft = () => {} }) {
348
+ export function HubRoomPage({ roomId, listed = null, Thread, client, meId = "", rooms = [], openRoom = () => {}, goList = () => {}, onLeft = () => {}, onMe = () => {} }) {
212
349
  const store = useMemo(() => createRoomStore(roomId, { client, meId }), [roomId]);
213
350
  useEffect(() => () => store.stop(), [store]);
214
351
  const [, tick] = useState(0);
215
352
  // The first read may land before this subscribes: read once more on subscribing.
216
353
  useEffect(() => { const off = store.subscribe(() => tick((n) => n + 1)); tick((n) => n + 1); return off; }, [store]);
217
354
  const [reply, setReply] = useState(null), [rail, setRail] = useState(true), [sheet, setSheet] = useState(false);
355
+ // M-3125: the room's pending files, as in a 1:1 chat (hub-attachments.js): Attach left of the box, chips inside it.
356
+ // The ref moves with every set, not on the next render: uploadChosen reads it between its own sets (as panel-hub.js does).
357
+ const [files, setFilesState] = useState([]), filesRef = useRef([]), alive = useRef(true), [fileMsg, setFileMsg] = useState("");
358
+ const setFiles = (next) => { filesRef.current = next; setFilesState(next); };
359
+ useEffect(() => { alive.current = true; return () => { alive.current = false; }; }, []);
360
+ useEffect(() => { setFiles([]); setFileMsg(""); }, [roomId]);
218
361
  const wide = useRailWide();
219
362
  const input = useRef(null), threadRef = useRef(null), insert = useRef(null);
220
363
  const Panel = useMembersPanel();
@@ -231,9 +374,58 @@ export function HubRoomPage({ roomId, listed = null, Thread, client, meId = "",
231
374
  if (r.ok) onLeft(); else setLeaveError(r.text);
232
375
  };
233
376
  const detail = store.detail(), room = detail?.room || listed || {}, group = room.kind === "group";
377
+ // The page-level rooms notifier learns this person's id for this room from its detail (§12; member
378
+ // ids are per room, so the id is kept under this room's id).
379
+ useEffect(() => { const id = detail && detail.me && detail.me.id; if (id) onMe(roomId, id); }, [detail && detail.me && detail.me.id]);
380
+ // M-3125: Attach only where this page and this room carry files and the room is open; chosen files ride the next send.
381
+ const takesFiles = pageCarriesFiles(client, store) && roomTakesFiles(room) && !store.closed();
382
+ const attach = takesFiles ? { title: hf("attach"), onFiles: async (list) => {
383
+ setFileMsg("");
384
+ const refused = await uploadChosen(client, room.id || roomId, list, { current: () => filesRef.current, set: setFiles, alive: () => alive.current });
385
+ if (alive.current && refused.length) setFileMsg(refused.join(" "));
386
+ } } : null;
387
+ const pending = files.length || fileMsg ? html`<${PendingFiles} files=${files} onRemove=${(key) => setFiles(filesRef.current.filter((f) => f.key !== key))}
388
+ formatSize=${(n) => (globalThis.AgendChatRender?.formatSize ? globalThis.AgendChatRender.formatSize(n) : `${n} B`)} />${fileMsg ? html`<p class="note" role="alert">${fileMsg}</p>` : null}` : null;
389
+ // The composer sends through the store; this one adds the ready files, waits for uploads, and clears only what was sent.
390
+ const annotateRef = useRef(null);
391
+ annotateRef.current = (img) => {
392
+ if (!takesFiles || typeof File !== "function") return null;
393
+ const key = img?.closest?.(".msg[data-key]")?.getAttribute("data-key") || "";
394
+ const message = store.messages().find((x) => `${x.boot}-${x.id}` === key) || null;
395
+ return { notice: (text) => setFileMsg(text), targets: [{ key: "self", label: t("hubRoomAnnotate.quote"), quote: (file, live = () => true) => {
396
+ if (!live() || !alive.current || store.closed()) return false;
397
+ void uploadChosen(client, room.id || roomId, [file], { current: () => filesRef.current, set: setFiles, alive: () => alive.current })
398
+ .then((refused) => { if (alive.current && refused.length) setFileMsg(refused.join(" ")); });
399
+ if (message) setReply(message);
400
+ setTimeout(() => input.current?.focus(), 0);
401
+ return true;
402
+ } }] };
403
+ };
404
+ const sendStore = useMemo(() => ({ ...store, send: async (text, opts = {}) => {
405
+ if (filesRef.current.some((f) => f.state === "uploading")) { setFileMsg(hf("waitUpload")); return { ok: false, code: "uploading" }; }
406
+ const chosen = filesRef.current.filter((f) => f.state === "ready");
407
+ const r = await store.send(text, { ...opts, ...(chosen.length ? { files: chosen.map((f) => f.id) } : {}) });
408
+ if (r?.ok && chosen.length) { const sent = new Set(chosen.map((f) => f.key)); setFiles(filesRef.current.filter((f) => !sent.has(f.key))); }
409
+ return r;
410
+ } }), [store]);
234
411
  // The Hub assistant's one-to-one is named by its flag, in this viewer's words (its stored name is a fallback).
235
412
  const title = room.assistant ? hroom("hubAssistant") : String(room.name || "");
236
413
  const hasAssistant = (detail?.members || []).some((m) => m.kind === "assistant");
414
+ // M-3127 C: a search hit opens the room at its message — loaded back to it, scrolled to and flashed (the thread's reveal),
415
+ // then the address loses `m` (a reload does not jump again). Read each render: a hit in the room already open jumps too.
416
+ const jump = jumpParam();
417
+ useEffect(() => {
418
+ if (!jump) return undefined;
419
+ let live = true;
420
+ void (async () => {
421
+ if (!store.loaded()) await new Promise((done) => { const off = store.subscribe(() => { if (store.loaded() || store.error()) { off(); done(); } }); });
422
+ const key = live ? await store.find(jump) : null;
423
+ if (!live) return;
424
+ if (key) setTimeout(() => threadRef.current?.reveal(key), 60); else toast(hroom("jumpMissing"), false);
425
+ try { const u = new URL(location.href); u.searchParams.delete("m"); history.replaceState(history.state, "", `${u.pathname}${u.search}${u.hash}`); } catch { /* the address stays */ }
426
+ })();
427
+ return () => { live = false; };
428
+ }, [store, jump]);
237
429
  // Read when shown: the latest message once loaded and again as messages arrive while the page is visible.
238
430
  const count = store.raw().length;
239
431
  useEffect(() => { if (store.loaded() && (typeof document === "undefined" || !document.hidden)) void store.markRead(); }, [store.loaded(), count]);
@@ -246,7 +438,17 @@ export function HubRoomPage({ roomId, listed = null, Thread, client, meId = "",
246
438
  // A line's one action: 「展開其餘 N 則」, or 「請房間助理整理」 (spec §10: the same as sending 「@房間助理 整理上面的回答」).
247
439
  statusAction: (arg) => { if (String(arg).startsWith("summarise:")) { if (!store.closed()) void store.send(hroom("summarisePrompt"), { mentions: ["assistant"] }); } else store.expand(arg); },
248
440
  startReply: (x) => { setReply(x); setTimeout(() => input.current?.focus(), 0); },
249
- findQuoted: async () => { await store.older(); return false; },
441
+ findQuoted: (key) => store.findQuoted(key),
442
+ // M-3127: people's reactions — a group room's messages (not a room line), while the room is open to me. Read when the
443
+ // thread draws: these options are kept from the first render, before the room's kind is known.
444
+ react: (x, emoji, on) => { void store.react(x.roomMessage, emoji, on).then((r) => { if (!r?.ok && r?.code !== "closed") toast(hroom("reactFailed"), false); }); },
445
+ canReact: () => store.detail()?.room?.kind === "group" && !store.closed(),
446
+ reactText: (k) => (k === "add" ? hroom("reactAdd") : k === "pick" ? hroom("reactPick") : ""),
447
+ reactLabel: hroom("reactAdd"), // the message menu's React (web-claude's HubThread, M-3117 PR 2: phones)
448
+ // M-3125 PR3: a room picture opens full size in the page; 「標註」 then quotes the marked-up copy here — it joins this
449
+ // composer's files (uploaded like any chosen file) and the reply quotes the message it came from. Read at click time
450
+ // (the thread keeps its options from its first render).
451
+ openImage: (links, img) => openLightbox(links, img, annotateRef.current(img)),
250
452
  };
251
453
  const line2 = group ? `${countsLine(room.people, room.agents)}${hasAssistant ? ` · ${hroom("roomAssistant")}` : ""}`
252
454
  : room.assistant ? hroom("providedByHub") : String(room.agent?.owner?.name || "");
@@ -259,6 +461,7 @@ export function HubRoomPage({ roomId, listed = null, Thread, client, meId = "",
259
461
  onOpenChat=${(m) => { const direct = rooms.find((r) => r.kind === "direct" && r.agent?.exposureId === m.id); if (direct) openRoom(direct.id); }}
260
462
  onSettings=${() => { setSheet(false); openSettings(); }} />` : null;
261
463
  return html`<div class=${`hub-chat hub-room-page${showRail ? " with-rail" : ""}`} data-room=${roomId}>
464
+ <${LightboxHost} />
262
465
  <section class="hub-chat-main">
263
466
  <header class="hub-chat-head" data-trust="panel-content">
264
467
  ${/* Lumen (spec §2): on a phone the header starts with the Fleet chat's back to the list. */ ""}
@@ -266,6 +469,7 @@ export function HubRoomPage({ roomId, listed = null, Thread, client, meId = "",
266
469
  onClick=${(e) => { if (e.metaKey || e.ctrlKey) return; e.preventDefault(); goList(); }}><${Icon} name="back" /></a>
267
470
  <span class=${`av${group ? " av-square" : ""}`} aria-hidden="true"><span class="av-text">${firstCharacter(title || "?") || "?"}</span></span>
268
471
  <span class="hub-chat-title"><strong>${title}</strong><span class="s">${line2}</span></span>
472
+ <span class="hub-head-tools"><${TextSizeButton} /><${HubNotifyToggle} /></span>
269
473
  ${group && Panel ? html`<button type="button" class="icon-btn hub-room-rail-toggle" aria-pressed=${(wide ? rail : sheet) ? "true" : "false"} title=${hroom("members")} aria-label=${hroom("members")}
270
474
  onClick=${() => (wide ? setRail(!rail) : setSheet(true))}><${Icon} name="team" size=${18} /></button>` : null}
271
475
  ${group && detail?.me ? html`<${Menu} cls="hub-room-menu" label=${hroom("menu")} fit=${true} ownerKey=${roomId} items=${[
@@ -277,8 +481,12 @@ export function HubRoomPage({ roomId, listed = null, Thread, client, meId = "",
277
481
  <${Thread} store=${store} name=${title} panelKey=${`hub-room:${roomId}`} threadRef=${threadRef} extra=${extra}
278
482
  emptyView=${room.assistant ? html`<div class="hub-assistant-empty"><${Empty} icon="bot" title=${hroom("hubAssistant")} hint=${hroom("hubAssistantEmpty")} /></div>`
279
483
  : group ? html`<p class="note">${hroom("composerHint")}</p>` : null} />
280
- ${working ? html`<${WorkBarView} kind="working" label=${working.text} elapsed="" elapsedTitle="" />` : null}
281
- <${RoomComposer} store=${store} detail=${detail} reply=${reply} onReply=${setReply} closed=${store.closed()} inputRef=${input} insertRef=${insert} />
484
+ ${/* M-3117: under the thread, the Fleet chat's dock — its column, its padding, the working line and the box in it. */ ""}
485
+ <div class="dock hub-dock" data-trust="composer"><div class="dock-col">
486
+ ${working ? html`<${WorkBarView} kind="working" label=${working.text} elapsed="" elapsedTitle="" />` : null}
487
+ <${RoomComposer} store=${sendStore} detail=${detail} reply=${reply} onReply=${setReply} closed=${store.closed()} inputRef=${input} insertRef=${insert}
488
+ attach=${attach} pending=${pending} canSendEmpty=${files.some((f) => f.state === "ready")} />
489
+ </div></div>
282
490
  </section>
283
491
  ${showRail ? html`<${RailFrame} trust="hub-context" label=${hroom("members")} title=${hroom("members")} closeLabel=${hroom("cancel")} onClose=${() => setRail(false)}>${panel}</${RailFrame}>` : null}
284
492
  ${!wide && sheet && panel && group ? html`<${Dialog} title=${hroom("members")} label=${hroom("members")} onClose=${() => setSheet(false)}><div class="hub-rail-sheet">${panel}</div></${Dialog}>` : null}
@@ -42,7 +42,8 @@ export function counts(event, me) {
42
42
 
43
43
  /** Desktop notify only for a row counts() treats as unread, and only while the tab is unfocused. */
44
44
  export function shouldNotify(event, me, focus, env = globalThis) {
45
- return !focus && counts(event, me).unread > 0 && notifyOn(env);
45
+ const c = counts(event, me);
46
+ return !focus && c.unread > 0 && (!event.message?.proactive || c.mentioned) && notifyOn(env);
46
47
  }
47
48
 
48
49
  /** Open room + scrolled to the bottom → mark read (spec §12). */
@@ -67,6 +67,10 @@ register("hub", {
67
67
  offlineRecovery: "A temporary outage reconnects automatically. If the Hub was restored or no longer recognizes this fleet, reconnect.",
68
68
  hold_rejected: "The Hub cannot resume this fleet’s saved connection. It may have been restored to an older state or no longer recognize this fleet. Reconnect it.",
69
69
  hold_refused: "The Hub refused the connection.", hold_revoked: "The Hub revoked this fleet's connection.", hold_other: "The connection is on hold.",
70
+ contactLimit: "While it answers a Hub question, this agent may not contact other agents",
71
+ contactLimitHint: "People on the Hub can ask this agent, but can't reach your other agents through it. Ends when its answer is accepted, or after 30 minutes.",
72
+ contactLimitNotice: "Contact limits are now on for existing shares. To allow agent-to-agent help during Hub answers, turn off ‘While it answers a Hub question, this agent may not contact other agents’ under Settings → Hub → Shared agents.",
73
+ contactNoticeDone: "Got it",
70
74
  sharedTitle: "Shared agents",
71
75
  sharedLead: "Every agent is private unless you share it. Only an agent that can run in a restricted, read-only mode can be shared.",
72
76
  share: "Share {0}", notEnforceable: "Can't be shared yet: restricted mode isn't available for it.", frozen: "Sharing stopped on the Hub",
@@ -141,6 +145,10 @@ register("hub", {
141
145
  offlineRecovery: "暫時離線會自動重新連線。若 Hub 已還原,或不再接受這個 Fleet,請重新連接。",
142
146
  hold_rejected: "Hub 無法繼續使用這個 Fleet 儲存的連接。Hub 可能已還原至較舊的狀態,或不再接受這個 Fleet;請重新連接。",
143
147
  hold_refused: "Hub 拒絕了這次連接。", hold_revoked: "Hub 已撤銷這個 Fleet 的連接。", hold_other: "連接已暫停。",
148
+ contactLimit: "回答 Hub 的提問時,這個 Agent 不能聯絡其他 Agent",
149
+ contactLimitHint: "Hub 上的人可以問這個 Agent,但不能透過它找到你的其他 Agent。回答獲接受或經過 30 分鐘後解除。",
150
+ contactLimitNotice: "現有分享已開啟聯絡限制。若要讓 Agent 在回答 Hub 提問時互相協助,請到「設定 → Hub → 分享的 Agent」取消勾選「回答 Hub 的提問時,這個 Agent 不能聯絡其他 Agent」。",
151
+ contactNoticeDone: "知道了",
144
152
  sharedTitle: "分享的 Agent",
145
153
  sharedLead: "每個 Agent 預設都不分享。只有能在受限、唯讀模式下執行的 Agent 才能分享。",
146
154
  share: "分享 {0}", notEnforceable: "暫時無法分享:這個 Agent 還不能使用受限模式。", frozen: "已在 Hub 停止分享",