@songsid/agend 2.4.0-alpha.3 → 2.4.0-beta.1

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 (426) hide show
  1. package/dist/agent-cli-instructions.md +8 -4
  2. package/dist/agent-whats-new.js +8 -8
  3. package/dist/agent-whats-new.js.map +1 -1
  4. package/dist/auth-api.js +8 -1
  5. package/dist/auth-api.js.map +1 -1
  6. package/dist/backend/claude-code.d.ts +8 -0
  7. package/dist/backend/claude-code.js +11 -4
  8. package/dist/backend/claude-code.js.map +1 -1
  9. package/dist/backend/codex.js +7 -3
  10. package/dist/backend/codex.js.map +1 -1
  11. package/dist/backend/grok.d.ts +19 -0
  12. package/dist/backend/grok.js +112 -1
  13. package/dist/backend/grok.js.map +1 -1
  14. package/dist/backend/types.d.ts +10 -0
  15. package/dist/backend/types.js.map +1 -1
  16. package/dist/build-provenance.json +1 -1
  17. package/dist/channel/mcp-tools.js +2 -2
  18. package/dist/channel/mcp-tools.js.map +1 -1
  19. package/dist/child-process.d.ts +1 -0
  20. package/dist/child-process.js.map +1 -1
  21. package/dist/claude-model-observation.d.ts +71 -0
  22. package/dist/claude-model-observation.js +169 -0
  23. package/dist/claude-model-observation.js.map +1 -0
  24. package/dist/cross-instance-envelope.d.ts +4 -1
  25. package/dist/cross-instance-envelope.js +12 -7
  26. package/dist/cross-instance-envelope.js.map +1 -1
  27. package/dist/daemon.d.ts +24 -2
  28. package/dist/daemon.js +263 -35
  29. package/dist/daemon.js.map +1 -1
  30. package/dist/delivery-consumed-watch.d.ts +24 -0
  31. package/dist/delivery-consumed-watch.js +21 -10
  32. package/dist/delivery-consumed-watch.js.map +1 -1
  33. package/dist/delivery-outbox.d.ts +5 -1
  34. package/dist/delivery-outbox.js +5 -0
  35. package/dist/delivery-outbox.js.map +1 -1
  36. package/dist/fleet-manager.d.ts +11 -1
  37. package/dist/fleet-manager.js +80 -2
  38. package/dist/fleet-manager.js.map +1 -1
  39. package/dist/general-knowledge/skills/concepts/SKILL.md +16 -3
  40. package/dist/general-knowledge/skills/credential-profiles/SKILL.md +8 -2
  41. package/dist/general-knowledge/skills/cross-instance-messaging/SKILL.md +5 -3
  42. package/dist/general-knowledge/skills/hub/SKILL.md +203 -10
  43. package/dist/general-knowledge/skills/multi-channel/SKILL.md +1 -1
  44. package/dist/general-knowledge/skills/web-dashboard/SKILL.md +18 -7
  45. package/dist/general-knowledge/skills/worker-collaboration/SKILL.md +1 -1
  46. package/dist/grok-delivery-proof.d.ts +24 -0
  47. package/dist/grok-delivery-proof.js +124 -0
  48. package/dist/grok-delivery-proof.js.map +1 -0
  49. package/dist/hub/assistant/admin-types.d.ts +43 -0
  50. package/dist/hub/assistant/admin-types.js +2 -0
  51. package/dist/hub/assistant/admin-types.js.map +1 -0
  52. package/dist/hub/assistant/claude-host.d.ts +17 -0
  53. package/dist/hub/assistant/claude-host.js +300 -0
  54. package/dist/hub/assistant/claude-host.js.map +1 -0
  55. package/dist/hub/assistant/context.d.ts +3 -0
  56. package/dist/hub/assistant/context.js +7 -0
  57. package/dist/hub/assistant/context.js.map +1 -0
  58. package/dist/hub/assistant/fleet-host.d.ts +19 -0
  59. package/dist/hub/assistant/fleet-host.js +28 -0
  60. package/dist/hub/assistant/fleet-host.js.map +1 -0
  61. package/dist/hub/assistant/runner.d.ts +64 -0
  62. package/dist/hub/assistant/runner.js +239 -0
  63. package/dist/hub/assistant/runner.js.map +1 -0
  64. package/dist/hub/assistant/service.d.ts +51 -0
  65. package/dist/hub/assistant/service.js +143 -0
  66. package/dist/hub/assistant/service.js.map +1 -0
  67. package/dist/hub/assistant/store.d.ts +3 -0
  68. package/dist/hub/assistant/store.js +65 -0
  69. package/dist/hub/assistant/store.js.map +1 -0
  70. package/dist/hub/assistant/types.d.ts +60 -0
  71. package/dist/hub/assistant/types.js +2 -0
  72. package/dist/hub/assistant/types.js.map +1 -0
  73. package/dist/hub/catalog.d.ts +1 -1
  74. package/dist/hub/catalog.js +55 -12
  75. package/dist/hub/catalog.js.map +1 -1
  76. package/dist/hub/client.d.ts +10 -0
  77. package/dist/hub/client.js +48 -8
  78. package/dist/hub/client.js.map +1 -1
  79. package/dist/hub/compose/member.d.ts +8 -1
  80. package/dist/hub/compose/member.js +224 -58
  81. package/dist/hub/compose/member.js.map +1 -1
  82. package/dist/hub/compose/server.d.ts +12 -1
  83. package/dist/hub/compose/server.js +74 -11
  84. package/dist/hub/compose/server.js.map +1 -1
  85. package/dist/hub/directory/admission.d.ts +15 -0
  86. package/dist/hub/directory/admission.js +56 -0
  87. package/dist/hub/directory/admission.js.map +1 -0
  88. package/dist/hub/directory/directory.d.ts +1 -1
  89. package/dist/hub/directory/directory.js +63 -0
  90. package/dist/hub/directory/directory.js.map +1 -1
  91. package/dist/hub/directory/types.d.ts +13 -0
  92. package/dist/hub/directory/types.js.map +1 -1
  93. package/dist/hub/grant-access.js +23 -3
  94. package/dist/hub/grant-access.js.map +1 -1
  95. package/dist/hub/grant-search.js +13 -1
  96. package/dist/hub/grant-search.js.map +1 -1
  97. package/dist/hub/group-policy/admin-control.d.ts +1 -0
  98. package/dist/hub/group-policy/admin-control.js +4 -2
  99. package/dist/hub/group-policy/admin-control.js.map +1 -1
  100. package/dist/hub/group-policy/admin-facts.d.ts +1 -0
  101. package/dist/hub/group-policy/admin-facts.js +2 -1
  102. package/dist/hub/group-policy/admin-facts.js.map +1 -1
  103. package/dist/hub/group-policy/admin-read.d.ts +1 -0
  104. package/dist/hub/group-policy/admin-read.js +3 -2
  105. package/dist/hub/group-policy/admin-read.js.map +1 -1
  106. package/dist/hub/group-policy/errors.d.ts +9 -0
  107. package/dist/hub/group-policy/errors.js +13 -0
  108. package/dist/hub/group-policy/errors.js.map +1 -0
  109. package/dist/hub/group-policy/impact-inventory.js +18 -2
  110. package/dist/hub/group-policy/impact-inventory.js.map +1 -1
  111. package/dist/hub/group-policy/store.d.ts +3 -9
  112. package/dist/hub/group-policy/store.js +5 -29
  113. package/dist/hub/group-policy/store.js.map +1 -1
  114. package/dist/hub/http/compose.d.ts +1 -0
  115. package/dist/hub/http/compose.js +482 -15
  116. package/dist/hub/http/compose.js.map +1 -1
  117. package/dist/hub/http/core.d.ts +6 -5
  118. package/dist/hub/http/core.js +74 -48
  119. package/dist/hub/http/core.js.map +1 -1
  120. package/dist/hub/http/deps.d.ts +20 -0
  121. package/dist/hub/http/schema.js +8 -0
  122. package/dist/hub/http/schema.js.map +1 -1
  123. package/dist/hub/init/member-certificate.d.ts +1 -0
  124. package/dist/hub/init/member-certificate.js +39 -0
  125. package/dist/hub/init/member-certificate.js.map +1 -0
  126. package/dist/hub/init/plan-digest.js +1 -0
  127. package/dist/hub/init/plan-digest.js.map +1 -1
  128. package/dist/hub/invitations.d.ts +96 -0
  129. package/dist/hub/invitations.js +292 -0
  130. package/dist/hub/invitations.js.map +1 -0
  131. package/dist/hub/join/certificate-trust.d.ts +13 -0
  132. package/dist/hub/join/certificate-trust.js +41 -0
  133. package/dist/hub/join/certificate-trust.js.map +1 -0
  134. package/dist/hub/join/certificate.d.ts +11 -0
  135. package/dist/hub/join/certificate.js +67 -0
  136. package/dist/hub/join/certificate.js.map +1 -0
  137. package/dist/hub/join/client.d.ts +5 -0
  138. package/dist/hub/join/client.js +30 -3
  139. package/dist/hub/join/client.js.map +1 -1
  140. package/dist/hub/join/http.js +5 -3
  141. package/dist/hub/join/http.js.map +1 -1
  142. package/dist/hub/join/local.d.ts +32 -1
  143. package/dist/hub/join/local.js +116 -11
  144. package/dist/hub/join/local.js.map +1 -1
  145. package/dist/hub/join/service.d.ts +17 -0
  146. package/dist/hub/join/service.js +12 -0
  147. package/dist/hub/join/service.js.map +1 -1
  148. package/dist/hub/join/store.d.ts +5 -0
  149. package/dist/hub/join/store.js +12 -2
  150. package/dist/hub/join/store.js.map +1 -1
  151. package/dist/hub/join/trust.d.ts +9 -0
  152. package/dist/hub/join/trust.js +35 -0
  153. package/dist/hub/join/trust.js.map +1 -1
  154. package/dist/hub/member/pairing-api.js +9 -1
  155. package/dist/hub/member/pairing-api.js.map +1 -1
  156. package/dist/hub/member/room-ask.d.ts +137 -0
  157. package/dist/hub/member/room-ask.js +358 -0
  158. package/dist/hub/member/room-ask.js.map +1 -0
  159. package/dist/hub/member-journal.d.ts +18 -1
  160. package/dist/hub/member-journal.js +76 -3
  161. package/dist/hub/member-journal.js.map +1 -1
  162. package/dist/hub/member-origin.d.ts +177 -0
  163. package/dist/hub/member-origin.js +314 -0
  164. package/dist/hub/member-origin.js.map +1 -0
  165. package/dist/hub/pairing-notices.d.ts +1 -0
  166. package/dist/hub/pairing-notices.js +2 -1
  167. package/dist/hub/pairing-notices.js.map +1 -1
  168. package/dist/hub/pairing.d.ts +8 -0
  169. package/dist/hub/pairing.js +32 -5
  170. package/dist/hub/pairing.js.map +1 -1
  171. package/dist/hub/protocol.d.ts +159 -0
  172. package/dist/hub/protocol.js +19 -1
  173. package/dist/hub/protocol.js.map +1 -1
  174. package/dist/hub/roles/clock.d.ts +18 -0
  175. package/dist/hub/roles/clock.js +58 -0
  176. package/dist/hub/roles/clock.js.map +1 -0
  177. package/dist/hub/roles/cutover-marker.d.ts +57 -0
  178. package/dist/hub/roles/cutover-marker.js +26 -0
  179. package/dist/hub/roles/cutover-marker.js.map +1 -0
  180. package/dist/hub/roles/cutover.js +3 -17
  181. package/dist/hub/roles/cutover.js.map +1 -1
  182. package/dist/hub/roles/read.d.ts +7 -3
  183. package/dist/hub/roles/read.js +9 -1
  184. package/dist/hub/roles/read.js.map +1 -1
  185. package/dist/hub/rooms/admin.d.ts +45 -0
  186. package/dist/hub/rooms/admin.js +105 -0
  187. package/dist/hub/rooms/admin.js.map +1 -0
  188. package/dist/hub/rooms/agents.d.ts +74 -0
  189. package/dist/hub/rooms/agents.js +333 -0
  190. package/dist/hub/rooms/agents.js.map +1 -0
  191. package/dist/hub/rooms/assistant.d.ts +44 -0
  192. package/dist/hub/rooms/assistant.js +179 -0
  193. package/dist/hub/rooms/assistant.js.map +1 -0
  194. package/dist/hub/rooms/context.d.ts +10 -0
  195. package/dist/hub/rooms/context.js +24 -0
  196. package/dist/hub/rooms/context.js.map +1 -0
  197. package/dist/hub/rooms/direct-view.d.ts +39 -0
  198. package/dist/hub/rooms/direct-view.js +38 -0
  199. package/dist/hub/rooms/direct-view.js.map +1 -0
  200. package/dist/hub/rooms/directory.d.ts +35 -0
  201. package/dist/hub/rooms/directory.js +98 -0
  202. package/dist/hub/rooms/directory.js.map +1 -0
  203. package/dist/hub/rooms/schema.d.ts +11 -0
  204. package/dist/hub/rooms/schema.js +73 -0
  205. package/dist/hub/rooms/schema.js.map +1 -0
  206. package/dist/hub/rooms/service.d.ts +449 -0
  207. package/dist/hub/rooms/service.js +581 -0
  208. package/dist/hub/rooms/service.js.map +1 -0
  209. package/dist/hub/rooms/types.d.ts +79 -0
  210. package/dist/hub/rooms/types.js +2 -0
  211. package/dist/hub/rooms/types.js.map +1 -0
  212. package/dist/hub/rooms.d.ts +7 -1
  213. package/dist/hub/rooms.js +30 -5
  214. package/dist/hub/rooms.js.map +1 -1
  215. package/dist/hub/runtime.d.ts +8 -0
  216. package/dist/hub/runtime.js +57 -3
  217. package/dist/hub/runtime.js.map +1 -1
  218. package/dist/hub/server.d.ts +25 -0
  219. package/dist/hub/server.js +63 -5
  220. package/dist/hub/server.js.map +1 -1
  221. package/dist/hub/sessions.js +1 -1
  222. package/dist/hub/sessions.js.map +1 -1
  223. package/dist/hub/settings-commit.d.ts +6 -1
  224. package/dist/hub/settings-commit.js +15 -0
  225. package/dist/hub/settings-commit.js.map +1 -1
  226. package/dist/hub/settings-directory-recovery.d.ts +5 -0
  227. package/dist/hub/settings-directory-recovery.js +11 -1
  228. package/dist/hub/settings-directory-recovery.js.map +1 -1
  229. package/dist/hub/settings-member-address-control.d.ts +84 -0
  230. package/dist/hub/settings-member-address-control.js +150 -0
  231. package/dist/hub/settings-member-address-control.js.map +1 -0
  232. package/dist/hub/settings-member-address-decision.d.ts +229 -0
  233. package/dist/hub/settings-member-address-decision.js +320 -0
  234. package/dist/hub/settings-member-address-decision.js.map +1 -0
  235. package/dist/hub/settings-member-address-http.d.ts +9 -0
  236. package/dist/hub/settings-member-address-http.js +79 -0
  237. package/dist/hub/settings-member-address-http.js.map +1 -0
  238. package/dist/hub/settings-member-address-network.d.ts +2 -0
  239. package/dist/hub/settings-member-address-network.js +22 -0
  240. package/dist/hub/settings-member-address-network.js.map +1 -0
  241. package/dist/hub/settings-member-address-notices.d.ts +22 -0
  242. package/dist/hub/settings-member-address-notices.js +21 -0
  243. package/dist/hub/settings-member-address-notices.js.map +1 -0
  244. package/dist/hub/settings-member-address-policy.d.ts +22 -0
  245. package/dist/hub/settings-member-address-policy.js +36 -0
  246. package/dist/hub/settings-member-address-policy.js.map +1 -0
  247. package/dist/hub/settings-member-address.d.ts +64 -0
  248. package/dist/hub/settings-member-address.js +239 -0
  249. package/dist/hub/settings-member-address.js.map +1 -0
  250. package/dist/hub/settings-web-address-decision.js +3 -1
  251. package/dist/hub/settings-web-address-decision.js.map +1 -1
  252. package/dist/hub/settings-web-address-http.js +3 -2
  253. package/dist/hub/settings-web-address-http.js.map +1 -1
  254. package/dist/hub/settings-web-address-policy.d.ts +3 -2
  255. package/dist/hub/settings-web-address-policy.js +3 -1
  256. package/dist/hub/settings-web-address-policy.js.map +1 -1
  257. package/dist/hub/socket.d.ts +2 -0
  258. package/dist/hub/socket.js +2 -0
  259. package/dist/hub/socket.js.map +1 -1
  260. package/dist/hub/teams/grant-schema.d.ts +2 -0
  261. package/dist/hub/teams/grant-schema.js +13 -0
  262. package/dist/hub/teams/grant-schema.js.map +1 -0
  263. package/dist/hub/teams/index.d.ts +7 -0
  264. package/dist/hub/teams/index.js +273 -0
  265. package/dist/hub/teams/index.js.map +1 -0
  266. package/dist/hub/teams/store.d.ts +34 -0
  267. package/dist/hub/teams/store.js +57 -0
  268. package/dist/hub/teams/store.js.map +1 -0
  269. package/dist/hub/teams/types.d.ts +98 -0
  270. package/dist/hub/teams/types.js +2 -0
  271. package/dist/hub/teams/types.js.map +1 -0
  272. package/dist/hub/tls.d.ts +47 -0
  273. package/dist/hub/tls.js +23 -6
  274. package/dist/hub/tls.js.map +1 -1
  275. package/dist/hub/types.d.ts +54 -3
  276. package/dist/hub/validation.d.ts +1 -1
  277. package/dist/hub/validation.js +2 -2
  278. package/dist/hub/validation.js.map +1 -1
  279. package/dist/hub/web-origin.d.ts +20 -7
  280. package/dist/hub/web-origin.js +26 -15
  281. package/dist/hub/web-origin.js.map +1 -1
  282. package/dist/hub-pilot-trust-settings.d.ts +4 -0
  283. package/dist/hub-pilot-trust-settings.js +13 -0
  284. package/dist/hub-pilot-trust-settings.js.map +1 -0
  285. package/dist/human-delivery-receipts.d.ts +4 -2
  286. package/dist/human-delivery-receipts.js +20 -13
  287. package/dist/human-delivery-receipts.js.map +1 -1
  288. package/dist/inbound-presentation.d.ts +28 -0
  289. package/dist/inbound-presentation.js +48 -0
  290. package/dist/inbound-presentation.js.map +1 -0
  291. package/dist/instance-lifecycle.js +1 -0
  292. package/dist/instance-lifecycle.js.map +1 -1
  293. package/dist/instructions.d.ts +4 -2
  294. package/dist/instructions.js +7 -4
  295. package/dist/instructions.js.map +1 -1
  296. package/dist/locale.js +16 -0
  297. package/dist/locale.js.map +1 -1
  298. package/dist/log-service.d.ts +3 -0
  299. package/dist/log-service.js +39 -22
  300. package/dist/log-service.js.map +1 -1
  301. package/dist/log-steps.d.ts +56 -1
  302. package/dist/log-steps.js +318 -56
  303. package/dist/log-steps.js.map +1 -1
  304. package/dist/needs-you-hub.js +6 -2
  305. package/dist/needs-you-hub.js.map +1 -1
  306. package/dist/needs-you.d.ts +5 -1
  307. package/dist/needs-you.js +4 -8
  308. package/dist/needs-you.js.map +1 -1
  309. package/dist/office-share-page.js +1 -1
  310. package/dist/office-share-page.js.map +1 -1
  311. package/dist/outbound-handlers.d.ts +1 -0
  312. package/dist/outbound-handlers.js +6 -0
  313. package/dist/outbound-handlers.js.map +1 -1
  314. package/dist/outbound-schemas.d.ts +1 -0
  315. package/dist/outbound-schemas.js +1 -0
  316. package/dist/outbound-schemas.js.map +1 -1
  317. package/dist/queued-handoffs.d.ts +3 -1
  318. package/dist/queued-handoffs.js +1 -1
  319. package/dist/queued-handoffs.js.map +1 -1
  320. package/dist/runtime-transcript-source.d.ts +2 -0
  321. package/dist/runtime-transcript-source.js +23 -1
  322. package/dist/runtime-transcript-source.js.map +1 -1
  323. package/dist/settings-api.d.ts +1 -0
  324. package/dist/settings-api.js +15 -8
  325. package/dist/settings-api.js.map +1 -1
  326. package/dist/settings-baseline.d.ts +3 -0
  327. package/dist/settings-baseline.js +2 -2
  328. package/dist/settings-baseline.js.map +1 -1
  329. package/dist/settings-effect.d.ts +3 -0
  330. package/dist/settings-effect.js +12 -2
  331. package/dist/settings-effect.js.map +1 -1
  332. package/dist/topic-commands.js +2 -1
  333. package/dist/topic-commands.js.map +1 -1
  334. package/dist/transcript-jsonl.d.ts +24 -0
  335. package/dist/transcript-jsonl.js +72 -22
  336. package/dist/transcript-jsonl.js.map +1 -1
  337. package/dist/transcript-monitor.d.ts +5 -1
  338. package/dist/transcript-monitor.js +65 -3
  339. package/dist/transcript-monitor.js.map +1 -1
  340. package/dist/transcript-needles.d.ts +1 -1
  341. package/dist/transcript-needles.js +1 -1
  342. package/dist/transcript-records.d.ts +2 -1
  343. package/dist/transcript-records.js.map +1 -1
  344. package/dist/transcript-sources.d.ts +4 -0
  345. package/dist/transcript-sources.js +2 -0
  346. package/dist/transcript-sources.js.map +1 -1
  347. package/dist/ui/agent-details-settings.js +10 -1
  348. package/dist/ui/chat-activity.js +2 -2
  349. package/dist/ui/fleet-canvas.js +5 -2
  350. package/dist/ui/fleet-office-card.js +4 -2
  351. package/dist/ui/fleet-org.js +2 -0
  352. package/dist/ui/hub-admin-rooms-strings.js +28 -0
  353. package/dist/ui/hub-admin-rooms.js +77 -0
  354. package/dist/ui/hub-assistant-admin-strings.js +26 -0
  355. package/dist/ui/hub-assistant-admin.js +85 -0
  356. package/dist/ui/hub-client.js +178 -14
  357. package/dist/ui/hub-grant-picker.js +14 -5
  358. package/dist/ui/hub-group-strings.js +3 -3
  359. package/dist/ui/hub-invitations-strings.js +30 -0
  360. package/dist/ui/hub-invitations.js +108 -0
  361. package/dist/ui/hub-join-one-strings.js +2 -0
  362. package/dist/ui/hub-pairing-form-strings.js +48 -0
  363. package/dist/ui/hub-pilot-trust-strings.js +27 -0
  364. package/dist/ui/hub-pilot-trust.js +41 -0
  365. package/dist/ui/hub-room-composer.js +123 -0
  366. package/dist/ui/hub-room-favorites.js +90 -0
  367. package/dist/ui/hub-room-list.js +152 -0
  368. package/dist/ui/hub-room-members-strings.js +12 -0
  369. package/dist/ui/hub-room-members.js +104 -0
  370. package/dist/ui/hub-room-new-strings.js +46 -0
  371. package/dist/ui/hub-room-new.js +135 -0
  372. package/dist/ui/hub-room-presence.js +123 -0
  373. package/dist/ui/hub-room-settings-strings.js +26 -0
  374. package/dist/ui/hub-room-settings.js +134 -0
  375. package/dist/ui/hub-room-strings.js +224 -0
  376. package/dist/ui/hub-room-thread.js +288 -0
  377. package/dist/ui/hub-room-unread.js +51 -0
  378. package/dist/ui/hub-room-working.js +29 -0
  379. package/dist/ui/hub-strings.js +2 -0
  380. package/dist/ui/hub-teams-strings.js +34 -0
  381. package/dist/ui/hub-teams.js +169 -0
  382. package/dist/ui/log-row.js +14 -5
  383. package/dist/ui/panel-details.js +6 -1
  384. package/dist/ui/panel-hub.js +115 -57
  385. package/dist/ui/panel-needs.js +2 -0
  386. package/dist/ui/settings-hub-company-join.js +31 -11
  387. package/dist/ui/settings-hub-connection.js +9 -3
  388. package/dist/ui/settings-hub-member-address.js +220 -0
  389. package/dist/ui/settings-hub-section.js +4 -2
  390. package/dist/ui/settings-hub-web-address.js +21 -5
  391. package/dist/ui/settings-hub.js +10 -4
  392. package/dist/ui/settings-layout.js +5 -1
  393. package/dist/ui/shared/app-i18n.js +2 -2
  394. package/dist/ui/shared/app-needs.js +3 -0
  395. package/dist/ui/shared/app-shell.js +7 -4
  396. package/dist/ui/shared/app.css +8 -0
  397. package/dist/ui/shared/chat-render.js +10 -0
  398. package/dist/ui/shared/chat-thread.js +15 -5
  399. package/dist/ui/shared/hub-chat.css +22 -0
  400. package/dist/ui/shared/hub-rooms-u2.css +42 -0
  401. package/dist/ui/shared/hub-signin.css +2 -0
  402. package/dist/ui/shared/hub-teams.css +31 -0
  403. package/dist/ui/shared/model-observation.js +16 -0
  404. package/dist/ui/shared/page-head.js +3 -2
  405. package/dist/ui/shared/stale-tab.css +6 -0
  406. package/dist/ui/shared/stale-tab.js +50 -0
  407. package/dist/ui/shared/usage-dialog.js +2 -1
  408. package/dist/ui/shared/view-strings.js +2 -0
  409. package/dist/usage/agent-output.js +1 -0
  410. package/dist/usage/agent-output.js.map +1 -1
  411. package/dist/usage/i18n-keys.d.ts +1 -1
  412. package/dist/usage/i18n-keys.js +1 -1
  413. package/dist/usage/i18n-keys.js.map +1 -1
  414. package/dist/usage/i18n.d.ts +1 -1
  415. package/dist/usage/i18n.js +2 -1
  416. package/dist/usage/i18n.js.map +1 -1
  417. package/dist/usage/providers.d.ts +4 -1
  418. package/dist/usage/providers.js +25 -10
  419. package/dist/usage/providers.js.map +1 -1
  420. package/dist/usage/usage-api.d.ts +1 -1
  421. package/dist/usage/usage-api.js +4 -4
  422. package/dist/usage/usage-api.js.map +1 -1
  423. package/dist/web-api.d.ts +2 -0
  424. package/dist/web-api.js +6 -2
  425. package/dist/web-api.js.map +1 -1
  426. package/package.json +1 -1
@@ -0,0 +1,288 @@
1
+ // M-3092 PR 2 (Hub rooms, track U): one room of a Hub with rooms, on the Fleet chat's own thread (/assets/chat-thread.js
2
+ // through panel-hub.js's HubThread). docs/design/hub-rooms-ux.md §3 says only where a room differs from the Fleet chat:
3
+ // - every message says who wrote it — a person by name (mine: on the right, no name), an agent as 「name · owner 的 Agent」,
4
+ // the room assistant as 「房間助理 · Hub 提供」; the room's own lines (created, joined …) are the thread's status rows;
5
+ // - an answer is a reply to the message that asked for it (the thread's own quote, jumping to it);
6
+ // - under a message that asked several agents, one line of progress, live: 「已回答 7 · 處理中 2 · 稍後回覆 3」 → 「12 個
7
+ // 都回答了」; one agent: the Fleet's delivery marks on my own message; an answer still to come is not a row of its own.
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
+ // an idempotency key, and answers HubThread's store interface.
10
+ import { html, useEffect, useMemo, useRef, useState } from "/assets/app-html.js";
11
+ import { WorkBarView } from "/assets/chat-composer.js";
12
+ import { RailFrame } from "/assets/side-rail.js";
13
+ import { Icon } from "/assets/ui-icons.js";
14
+ import { Empty } from "/assets/ui-states.js";
15
+ import { Dialog } from "/assets/ui-dialog.js";
16
+ import { Menu } from "/assets/ui-menu.js";
17
+ import { t } from "/assets/app-i18n.js";
18
+ import "./hub-strings.js";
19
+ import { firstCharacter } from "/assets/instance-nav.js";
20
+ import { hroom } from "./hub-room-strings.js";
21
+ import { RoomComposer } from "./hub-room-composer.js";
22
+ import { workingLine } from "./hub-room-working.js";
23
+ import { countsLine } from "./hub-room-list.js";
24
+
25
+ const iso = (ms) => (Number.isFinite(ms) && ms > 0 ? new Date(ms).toISOString() : undefined);
26
+ const BOOT = "room";
27
+
28
+ /**
29
+ * One room message's author line (spec §3). `mine`: no name (the thread puts it on the right). The assistant is named by
30
+ * its flag, never by its stored name (Ridge: that is an older renderer's fallback): 「房間助理 · Hub 提供」 in a room,
31
+ * 「Hub 助理」 in its own one-to-one (`direct`).
32
+ */
33
+ export function authorLine(author, mine = false, direct = false) {
34
+ if (!author || mine) return "";
35
+ if (author.kind === "assistant") return direct ? hroom("hubAssistant") : hroom("authorAssistant");
36
+ if (author.kind === "agent") {
37
+ if (!author.owner?.name) return String(author.name || "");
38
+ // 「Alex 的 Agent」: a Latin owner name keeps a space before a CJK word that follows it (Lumen); 「林小華的 Agent」 none.
39
+ const owner = String(author.owner.name), plain = hroom("authorAgent", "\u0001", "\u0002");
40
+ return hroom("authorAgent", String(author.name || ""), /[A-Za-z0-9)]$/.test(owner) && /\u0002[\u3400-\u9fff]/.test(plain) ? `${owner} ` : owner);
41
+ }
42
+ return String(author.name || "");
43
+ }
44
+ /**
45
+ * A room's own line in this viewer's words (Ridge: `system` { kind, name } beside the stored text): a kind this page does
46
+ * not know, or an older row without `system`, keeps the stored text.
47
+ */
48
+ const SYSTEM = { "room-created": "createdSys", "member-joined": "sysJoined", "admin-joined": "sysAdminJoined" };
49
+ export function systemText(m) {
50
+ const key = m && m.system && SYSTEM[m.system.kind];
51
+ return key && typeof m.system.name === "string" ? hroom(key, m.system.name) : String((m && m.text) || "");
52
+ }
53
+ /**
54
+ * 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.
56
+ */
57
+ export function askState(ask) {
58
+ 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(" · ") };
62
+ }
63
+ /** How many answers of one question show when they are folded, and from how many they fold (Lumen: all up to 5). */
64
+ export const ANSWERS_SHOWN = 3, FOLD_FROM = 6;
65
+
66
+ /**
67
+ * Seam-1 messages (newest last) → the thread's messages. `ids`: a Map from a message id to its number in this thread
68
+ * (the thread's keys and quotes are numbers), extended here in arrival order and kept by the caller.
69
+ */
70
+ export function toThreadMessages(messages, { meId, ids, direct = false, expanded = new Set(), summarise = false }) {
71
+ const out = [], byId = new Map(messages.map((m) => [m.id, m]));
72
+ // Each question's answers that have text, in arrival order: past ANSWERS_SHOWN they wait behind one 「展開其餘 N 則」.
73
+ 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)
75
+ for (const m of messages) if (m && m.answerTo && drawn(m)) answersOf.set(m.answerTo, [...(answersOf.get(m.answerTo) || []), m.id]);
76
+ const num = (id) => { if (!ids.has(id)) ids.set(id, ids.size * 2 + 2); return ids.get(id); };
77
+ for (const m of messages) {
78
+ if (!m || typeof m.id !== "string") continue;
79
+ const author = m.author || {}, kind = author.kind;
80
+ // An answer still to come (queued, or being worked on: the working bar says who) is never an empty bubble.
81
+ if (m.answerTo && !m.text && (m.stage === "queued" || m.stage === "working")) continue;
82
+ // A question with FOLD_FROM answers or more shows its first ANSWERS_SHOWN; the rest wait behind one link right under the
83
+ // last one shown (until it is opened). Fewer than FOLD_FROM: every answer shows.
84
+ let foldAfter = null, lastShown = false;
85
+ if (m.answerTo) {
86
+ const list = answersOf.get(m.answerTo) || [], at = list.indexOf(m.id);
87
+ const folded = !direct && !expanded.has(m.answerTo) && list.length >= FOLD_FROM;
88
+ if (folded && at >= ANSWERS_SHOWN) continue;
89
+ if (folded && at === ANSWERS_SHOWN - 1) foldAfter = { label: hroom("expandRest", String(list.length - ANSWERS_SHOWN)), arg: m.answerTo };
90
+ lastShown = at >= 0 && at === (folded ? ANSWERS_SHOWN - 1 : list.length - 1);
91
+ }
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; }
94
+ // 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) } } : {}),
101
+ ...(m.stage === "not-answered" ? { text: hroom("noAnswer") } : {}) });
102
+ if (foldAfter) out.push({ boot: BOOT, id: num(`expand:${foldAfter.arg}`), role: "status", sender: "", text: "", bare: true, fold: true, action: foldAfter });
103
+ // Spec §10: once an @所有 Agent has answers, under the last one shown, 「請房間助理整理」 (it sends 「@房間助理 整理上面的回答」).
104
+ if (summarise && lastShown && byId.get(m.answerTo)?.mentions?.includes("all"))
105
+ 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;
107
+ // Its status, not an event: under it, without a time of its own.
108
+ if (line) out.push({ boot: BOOT, id: id + 1, role: "status", sender: "", text: line, progressOf: m.id, bare: true });
109
+ 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
+ }
111
+ return out;
112
+ }
113
+
114
+ /**
115
+ * One room's store: `subscribe(fn)` → unsubscribe; `detail()` (the room GET: room, me, members, settings), `messages()`
116
+ * (the thread's), `raw()` (seam-1 messages), `loaded()`, `error()`, `closed()` (archived, or I am no longer in it), `room()`;
117
+ * `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.
119
+ */
120
+ export function createRoomStore(roomId, { client, meId = "" } = {}) {
121
+ const subs = new Set(), ids = new Map(), expanded = new Set();
122
+ const st = { live: true, detail: null, messages: [], loaded: false, error: null, removed: false, more: false, view: [] };
123
+ // The room's committed order (Ridge: `sequence`, from the stored row): a waiting answer replaced in place, or an event that
124
+ // arrives out of order, is drawn where the room has it. Rows without it (a direct chat, an older Hub) keep arrival order.
125
+ const closedNow = () => st.removed || st.detail?.room?.archived === true;
126
+ const ordered = () => { if (st.messages.length && st.messages.every((m) => Number.isSafeInteger(m.sequence))) st.messages.sort((a, b) => a.sequence - b.sequence); };
127
+ 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 */ } } };
129
+ const upsert = (m) => {
130
+ if (!m || m.roomId !== roomId || typeof m.id !== "string") return;
131
+ 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);
133
+ };
134
+ 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
+ async function refresh() {
136
+ const [d, page] = await Promise.all([client.room(roomId), client.roomMessages(roomId, { limit: 50 })]);
137
+ if (!st.live) return;
138
+ if (d.ok) st.detail = d; else st.error = d.code || "failed";
139
+ if (page.ok) { for (const m of page.messages || []) upsert(m); st.more = page.more === true; st.loaded = true; if (d.ok) st.error = null; }
140
+ else st.error = page.code || "failed";
141
+ changed();
142
+ }
143
+ const on = (fn) => (data) => { if (st.live && data && data.roomId === roomId) { fn(data); changed(); } };
144
+ const unsubscribe = typeof client.subscribeRooms === "function" ? client.subscribeRooms({
145
+ "message.added": on((d) => upsert(d.message)),
146
+ "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; } }),
147
+ // The member's live state as sent: presence, and its note and reason only while the event carries them (a reason
148
+ // alone updates it; an event without one clears it — never a stale reason).
149
+ "presence.changed": on((d) => { const m = st.detail?.members?.find((x) => x.id === d.memberId); if (m) { m.presence = d.presence;
150
+ for (const k of ["presenceNote", "presenceReason"]) { if (d[k]) m[k] = d[k]; else delete m[k]; } } }),
151
+ "member.changed": on(() => { void readDetail().then(changed); }),
152
+ "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
+ }) : () => {};
154
+ void refresh();
155
+ return {
156
+ subscribe(fn) { subs.add(fn); return () => subs.delete(fn); },
157
+ detail: () => st.detail, raw: () => st.messages, messages: () => st.view, loaded: () => st.loaded, error: () => st.error,
158
+ closed: closedNow, removed: () => st.removed, more: () => st.more,
159
+ room: () => ({ ...(st.detail?.room || {}), ownerName: "" }),
160
+ async send(text, { mentions = [], replyTo } = {}) {
161
+ 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 });
163
+ // The stored message, as the Hub answers it: `{ message }`, or the message itself (Ridge's server) — drawn at once,
164
+ // whether or not the stream is up yet (a first send after opening the room must not vanish).
165
+ const { ok, ...bare } = r || {};
166
+ const sent = r && r.message ? r.message : ok && typeof bare.id === "string" && typeof bare.roomId === "string" ? bare : null;
167
+ if (ok && sent) { upsert(sent); changed(); }
168
+ return r;
169
+ },
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();
175
+ },
176
+ /** 「展開其餘 N 則」: show every answer of that question. */
177
+ expand(messageId) { if (typeof messageId === "string" && !expanded.has(messageId)) { expanded.add(messageId); changed(); } },
178
+ /** Who is working on an answer in this room now (its answer row has no text yet): their names, in arrival order. */
179
+ working() { return this.workers().map((w) => w.name); },
180
+ /** The same, as members ({ kind, name }) — what workingLine() words (the room assistant by its own name). */
181
+ 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) })); },
182
+ 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(); },
185
+ };
186
+ }
187
+
188
+ /**
189
+ * Wide enough for the side rail: the shared stylesheet hides `.u-rail` below 1200 px (app.css), so a narrower page shows
190
+ * the members panel in a sheet instead (spec §2: on a phone, a bottom drawer) — the Fleet's rail rule itself unchanged.
191
+ */
192
+ const RAIL_QUERY = "(min-width: 1200px)";
193
+ function useRailWide() {
194
+ const q = typeof matchMedia === "function" ? matchMedia(RAIL_QUERY) : null;
195
+ const [wide, setWide] = useState(() => !!q?.matches);
196
+ useEffect(() => { if (!q) return undefined; const on = () => setWide(!!q.matches); q.addEventListener?.("change", on); return () => q.removeEventListener?.("change", on); }, []);
197
+ return wide;
198
+ }
199
+ /** dev-claude2's members panel (hub-room-members.js), when this Hub serves it; otherwise the rail stays closed. */
200
+ function useMembersPanel() {
201
+ const [Panel, setPanel] = useState(null);
202
+ useEffect(() => { let live = true; import("./hub-room-members.js").then((m) => { if (live && typeof m.RoomMembersPanel === "function") setPanel(() => m.RoomMembersPanel); }, () => {}); return () => { live = false; }; }, []);
203
+ return Panel;
204
+ }
205
+
206
+ /**
207
+ * A room of a Hub with rooms (spec §3–§5): its header (a square avatar, its name, "3 人 · 12 個 Agent · 房間助理"), the
208
+ * Fleet chat's thread (panel-hub.js's HubThread, given as `Thread`: the thread wiring is one), the room's composer, and
209
+ * the members panel on the right. `client`: the Hub client; `me`: { id } from the session.
210
+ */
211
+ export function HubRoomPage({ roomId, listed = null, Thread, client, meId = "", rooms = [], openRoom = () => {}, goList = () => {}, onLeft = () => {} }) {
212
+ const store = useMemo(() => createRoomStore(roomId, { client, meId }), [roomId]);
213
+ useEffect(() => () => store.stop(), [store]);
214
+ const [, tick] = useState(0);
215
+ // The first read may land before this subscribes: read once more on subscribing.
216
+ useEffect(() => { const off = store.subscribe(() => tick((n) => n + 1)); tick((n) => n + 1); return off; }, [store]);
217
+ const [reply, setReply] = useState(null), [rail, setRail] = useState(true), [sheet, setSheet] = useState(false);
218
+ const wide = useRailWide();
219
+ const input = useRef(null), threadRef = useRef(null), insert = useRef(null);
220
+ const Panel = useMembersPanel();
221
+ // dev-claude2's room settings (hub-room-settings.js), opened from the header or the members panel.
222
+ const [settings, setSettings] = useState(null);
223
+ const openSettings = () => { import("./hub-room-settings.js").then((m) => { if (typeof m.RoomSettings === "function") setSettings(() => m.RoomSettings); }, () => {}); };
224
+ // Lumen (spec §3, §7): 「離開房間」 for everyone in a group room, through U2's leaveRoom (the last manager is told why not).
225
+ const [leaveError, setLeaveError] = useState("");
226
+ const leave = async () => {
227
+ setLeaveError("");
228
+ const m = await import("./hub-room-settings.js").catch(() => null);
229
+ if (typeof m?.leaveRoom !== "function") return;
230
+ const r = await m.leaveRoom(client, roomId, store.detail()?.me?.id || meId);
231
+ if (r.ok) onLeft(); else setLeaveError(r.text);
232
+ };
233
+ const detail = store.detail(), room = detail?.room || listed || {}, group = room.kind === "group";
234
+ // The Hub assistant's one-to-one is named by its flag, in this viewer's words (its stored name is a fallback).
235
+ const title = room.assistant ? hroom("hubAssistant") : String(room.name || "");
236
+ const hasAssistant = (detail?.members || []).some((m) => m.kind === "assistant");
237
+ // Read when shown: the latest message once loaded and again as messages arrive while the page is visible.
238
+ const count = store.raw().length;
239
+ useEffect(() => { if (store.loaded() && (typeof document === "undefined" || !document.hidden)) void store.markRead(); }, [store.loaded(), count]);
240
+ // The room's own mention labels, accented in every bubble as 「@Notes」 is (Lumen): @所有 Agent, the assistant, each member —
241
+ // read when the thread draws (the thread keeps its options from its first render, before the room's members are known).
242
+ const labels = () => [hroom("mentionAll"), hroom("mentionAssistant"), ...(store.detail()?.members || []).filter((m) => m.kind !== "assistant").map((m) => `@${m.name}`)];
243
+ const extra = {
244
+ isUser: (x) => x.mine === true, canReply: () => !store.closed(),
245
+ mentionLabels: labels,
246
+ // A line's one action: 「展開其餘 N 則」, or 「請房間助理整理」 (spec §10: the same as sending 「@房間助理 整理上面的回答」).
247
+ statusAction: (arg) => { if (String(arg).startsWith("summarise:")) { if (!store.closed()) void store.send(hroom("summarisePrompt"), { mentions: ["assistant"] }); } else store.expand(arg); },
248
+ startReply: (x) => { setReply(x); setTimeout(() => input.current?.focus(), 0); },
249
+ findQuoted: async () => { await store.older(); return false; },
250
+ };
251
+ const line2 = group ? `${countsLine(room.people, room.agents)}${hasAssistant ? ` · ${hroom("roomAssistant")}` : ""}`
252
+ : room.assistant ? hroom("providedByHub") : String(room.agent?.owner?.name || "");
253
+ const showRail = wide && rail && Panel && group && detail;
254
+ // The Fleet chat's working bar (Lumen): 「Notes 正在處理」, or 「2 個 Agent 正在處理」 — the answer row only when it arrives.
255
+ // Who: this room's answers being worked on; the words: workingLine() (#3857), the one place that says it.
256
+ const working = workingLine({ members: store.workers().map((w) => ({ ...w, presence: "working" })) });
257
+ const panel = Panel && detail ? html`<${Panel} client=${client} roomId=${roomId} detail=${detail}
258
+ onMention=${(m) => { setSheet(false); insert.current?.(`@${m.name}`); }}
259
+ onOpenChat=${(m) => { const direct = rooms.find((r) => r.kind === "direct" && r.agent?.exposureId === m.id); if (direct) openRoom(direct.id); }}
260
+ onSettings=${() => { setSheet(false); openSettings(); }} />` : null;
261
+ return html`<div class=${`hub-chat hub-room-page${showRail ? " with-rail" : ""}`} data-room=${roomId}>
262
+ <section class="hub-chat-main">
263
+ <header class="hub-chat-head" data-trust="panel-content">
264
+ ${/* Lumen (spec §2): on a phone the header starts with the Fleet chat's back to the list. */ ""}
265
+ <a class="icon-btn hub-back only-narrow" href="/ui/hub" aria-label=${t("hub.back")} title=${t("hub.back")}
266
+ onClick=${(e) => { if (e.metaKey || e.ctrlKey) return; e.preventDefault(); goList(); }}><${Icon} name="back" /></a>
267
+ <span class=${`av${group ? " av-square" : ""}`} aria-hidden="true"><span class="av-text">${firstCharacter(title || "?") || "?"}</span></span>
268
+ <span class="hub-chat-title"><strong>${title}</strong><span class="s">${line2}</span></span>
269
+ ${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
+ onClick=${() => (wide ? setRail(!rail) : setSheet(true))}><${Icon} name="team" size=${18} /></button>` : null}
271
+ ${group && detail?.me ? html`<${Menu} cls="hub-room-menu" label=${hroom("menu")} fit=${true} ownerKey=${roomId} items=${[
272
+ detail.me.role === "manager" ? { key: "settings", label: hroom("roomSettings"), icon: "settings", onSelect: openSettings } : null,
273
+ { key: "leave", label: hroom("leaveRoom"), icon: "close", onSelect: () => { void leave(); } },
274
+ ].filter(Boolean)} />` : null}
275
+ </header>
276
+ ${leaveError ? html`<p class="err hub-room-leave-err" role="alert">${leaveError}</p>` : null}
277
+ <${Thread} store=${store} name=${title} panelKey=${`hub-room:${roomId}`} threadRef=${threadRef} extra=${extra}
278
+ emptyView=${room.assistant ? html`<div class="hub-assistant-empty"><${Empty} icon="bot" title=${hroom("hubAssistant")} hint=${hroom("hubAssistantEmpty")} /></div>`
279
+ : 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} />
282
+ </section>
283
+ ${showRail ? html`<${RailFrame} trust="hub-context" label=${hroom("members")} title=${hroom("members")} closeLabel=${hroom("cancel")} onClose=${() => setRail(false)}>${panel}</${RailFrame}>` : null}
284
+ ${!wide && sheet && panel && group ? html`<${Dialog} title=${hroom("members")} label=${hroom("members")} onClose=${() => setSheet(false)}><div class="hub-rail-sheet">${panel}</div></${Dialog}>` : null}
285
+ ${settings && detail ? html`<${settings} client=${client} roomId=${roomId} detail=${detail} assistant=${hasAssistant}
286
+ onClose=${() => setSettings(null)} onChanged=${() => { void store.refresh(); }} />` : null}
287
+ </div>`;
288
+ }
@@ -0,0 +1,51 @@
1
+ // Hub rooms unread and desktop notifications (hub-rooms-ux.md §12). Pure: one live event in, counts out.
2
+ // The Fleet desktop-notify rule is notifyOn in app-needs.js — imported, never copied. Tab title is this
3
+ // helper; the Needs-you prefix in app-shell.js is a different count.
4
+ import { notifyOn } from "/assets/app-needs.js";
5
+
6
+ const NONE = { unread: 0, mentioned: false, invitation: false, id: null };
7
+
8
+ /** Browser tab title: "(3) base" while there is unread; `base` itself when the total is 0. */
9
+ export function tabTitle(base, total) {
10
+ const n = Number(total);
11
+ return n > 0 && Number.isFinite(n) ? `(${Math.trunc(n)}) ${base}` : base;
12
+ }
13
+
14
+ function countable(message, me) {
15
+ const author = message && message.author;
16
+ if (!author || !me) return false;
17
+ if (author.id === me.id || author.kind === "system") return false;
18
+ return !!(message.text || message.stage !== "queued");
19
+ }
20
+
21
+ /**
22
+ * Per-event §12 counts: others' messages, an @ to me, answers from agents I @-ed, new invitations.
23
+ * Own messages and system rows are 0. A live invitation.changed with no invitation object is a
24
+ * removal (accept/decline) and does not count.
25
+ * `id` is the message (or invitation) identity so a caller that sums unread keeps a Set of ids
26
+ * rather than adding every message.updated of the same row.
27
+ */
28
+ export function counts(event, me) {
29
+ if (!event || typeof event !== "object") return NONE;
30
+ if (event.type === "invitation.changed") {
31
+ const inv = event.invitation;
32
+ return inv && typeof inv === "object" && (inv.id || inv.room)
33
+ ? { unread: 1, mentioned: false, invitation: true, id: inv.id || null }
34
+ : NONE;
35
+ }
36
+ if (event.type !== "message.added" && event.type !== "message.updated") return NONE;
37
+ const message = event.message;
38
+ if (!countable(message, me)) return NONE;
39
+ const mentions = Array.isArray(message.mentions) ? message.mentions : [];
40
+ return { unread: 1, mentioned: mentions.includes(me.id), invitation: false, id: message.id || null };
41
+ }
42
+
43
+ /** Desktop notify only for a row counts() treats as unread, and only while the tab is unfocused. */
44
+ export function shouldNotify(event, me, focus, env = globalThis) {
45
+ return !focus && counts(event, me).unread > 0 && notifyOn(env);
46
+ }
47
+
48
+ /** Open room + scrolled to the bottom → mark read (spec §12). */
49
+ export function readWhen(atBottom, open) {
50
+ return Boolean(open && atBottom);
51
+ }
@@ -0,0 +1,29 @@
1
+ // Hub rooms WorkBar line and assistant footnote (hub-rooms-ux.md §3 處理中). Pure: a room GET
2
+ // answer or a message in, words out. Words come from hub-room-strings.js (hroom), never copied.
3
+ import { hroom } from "./hub-room-strings.js";
4
+
5
+ function workingOf(detail) {
6
+ const members = detail && Array.isArray(detail.members) ? detail.members : [];
7
+ return members.filter((m) => m && (m.kind === "agent" || m.kind === "assistant") && m.presence === "working");
8
+ }
9
+
10
+ function displayName(member) {
11
+ return member.kind === "assistant" ? hroom("roomAssistant") : member.name;
12
+ }
13
+
14
+ /** One / several agents (and the room assistant) currently working; people never count. */
15
+ export function workingLine(detail) {
16
+ const working = workingOf(detail);
17
+ if (!working.length) return null;
18
+ const names = working.map(displayName);
19
+ const count = working.length;
20
+ const text = count === 1 ? hroom("workingOne", names[0]) : hroom("workingMany", count);
21
+ return { text, names, count };
22
+ }
23
+
24
+ /** Footnote under an assistant's answer; empty for anyone else. */
25
+ export function assistantFootnote(message) {
26
+ const author = message && message.author;
27
+ if (author && author.kind === "assistant" && message.answerTo) return hroom("basedOnRecent");
28
+ return "";
29
+ }
@@ -17,6 +17,7 @@ register("hub", {
17
17
  // The Hub workspace (S3b): sign-in, Ask, My shared agents, Administration
18
18
  signedOutHub: "Not signed in", signOut: "Sign out", signInTitle: "Sign in to the Hub",
19
19
  signInLead: "Use your company account. Your password goes to the directory only and is never kept.",
20
+ signInPreview: "This Hub is a preview. Its screens and features may still change.",
20
21
  login: "Account", password: "Password", signIn: "Sign in",
21
22
  errSignIn: "That account and password didn't work.", errDirectory: "The directory can't be reached right now. Try again later.",
22
23
  errBusyHub: "Too many requests just now. Wait a moment and try again.", errConflictHub: "This changed meanwhile. It has been reloaded; check it and try again.",
@@ -91,6 +92,7 @@ register("hub", {
91
92
  adminTitle: "管理",
92
93
  signedOutHub: "尚未登入", signOut: "登出", signInTitle: "登入 Hub",
93
94
  signInLead: "請使用公司帳號登入。密碼只送給目錄服務驗證,不會被保存。",
95
+ signInPreview: "這個 Hub 是預覽版,畫面與功能可能還會變動。",
94
96
  login: "帳號", password: "密碼", signIn: "登入",
95
97
  errSignIn: "帳號或密碼不正確。", errDirectory: "目前無法連到目錄服務,請稍後再試。",
96
98
  errBusyHub: "請求太頻繁,請稍候再試。", errConflictHub: "這個項目剛剛有變更,已重新載入,請確認後再試一次。",
@@ -0,0 +1,34 @@
1
+ import { register, t } from "/assets/app-i18n.js";
2
+ register("hubTeam", {
3
+ en: {
4
+ title: "Teams", mine: "My teams", manage: "Manage teams", lead: "AD groups stop at departments. A team is a list you pick, usable for rooms and for who may ask.",
5
+ pageLead: "Pick the people in each team. Rooms keep the people added at that moment; asking permissions and room-creation rights follow the current roster.",
6
+ myLead: "Manage the members of the teams you lead. A Hub administrator manages the name, department and lead.",
7
+ create: "New team", edit: "Edit {0}", empty: "No teams yet.", noMine: "You do not lead any teams.", loading: "Loading teams…", retry: "Try again", refresh: "Refresh", back: "All teams",
8
+ name: "Team name", department: "Department", departmentLine: "Department: {0}", chooseDepartment: "Choose a department", departmentQuery: "Search AD departments", leadPerson: "Lead", chooseLead: "Choose a lead",
9
+ members: "Members", role: "Role", roleLead: "Lead", roleMember: "Member", signedIn: "Joined Hub", agents: "Shared agents", yes: "Yes", notYet: "Not yet", unobserved: "Not checked yet", none: "None",
10
+ add: "Add member", remove: "Remove", search: "Search", personQuery: "Search everyone by name", searchHint: "Type 2 to 64 characters. People in any department can be selected.", groupHint: "Type 2 to 64 characters of the department name.",
11
+ searching: "Searching…", noMatches: "No matches. Try more of the name.", choose: "Choose {0}", pick: "Choose", cancel: "Cancel", change: "Change", save: "Save", saving: "Saving…", saved: "Saved.", unsaved: "Unsaved changes",
12
+ limit: "Up to 200 members, including the lead.", count: "{0} members", leadRequired: "The lead is always a member. Choose another lead before removing this person.",
13
+ disabledLead: "The lead's directory account is disabled. Choose a new lead.",
14
+ failed: "Teams could not be loaded. Try again.", searchFailed: "The directory could not be searched. Try again.", busy: "The Hub is busy. Try again shortly.", denied: "Your access changed. Refresh to check the current team.", saveFailed: "Your changes could not be saved. They are still here; refresh if someone else changed the team.",
15
+ delete: "Delete team", deleteTitle: "Delete {0}?", deleteLead: "These team-based permissions will stop applying. Existing room members and agents already accepted into rooms stay.", noImpact: "No active team grants or room-creation entry.", creators: "May create rooms", grantExpiry: "May ask {0} · until {1}",
16
+ styleLoading: "Loading the team editor…", styleFailed: "The team editor could not be loaded. Try again.",
17
+ },
18
+ "zh-TW": {
19
+ title: "團隊", mine: "我的團隊", manage: "管理團隊", lead: "AD 群組只到部門。團隊是你自己挑的一份名單,可以用在房間與提問權限。",
20
+ pageLead: "選擇各團隊的成員。加入房間時會保留當下的名單;提問權限與建立房間的權限則依團隊目前的成員判斷。",
21
+ myLead: "管理你負責的團隊成員。名稱、所屬部門與負責人由 Hub 管理員設定。",
22
+ create: "新增團隊", edit: "編輯 {0}", empty: "還沒有團隊。", noMine: "你目前沒有負責的團隊。", loading: "正在讀取團隊…", retry: "再試一次", refresh: "重新整理", back: "所有團隊",
23
+ name: "團隊名稱", department: "所屬部門", departmentLine: "所屬部門:{0}", chooseDepartment: "選擇部門", departmentQuery: "搜尋 AD 部門", leadPerson: "負責人", chooseLead: "選擇負責人",
24
+ members: "成員", role: "身分", roleLead: "負責人", roleMember: "成員", signedIn: "已加入 Hub", agents: "分享的 Agent", yes: "已加入", notYet: "尚未加入", unobserved: "尚未確認", none: "無",
25
+ add: "加入成員", remove: "移除", search: "搜尋", personQuery: "輸入姓名搜尋所有人", searchHint: "請輸入 2 到 64 個字,可以選擇其他部門的同仁。", groupHint: "請輸入部門名稱的 2 到 64 個字。",
26
+ searching: "搜尋中…", noMatches: "找不到符合的對象,請多輸入幾個姓名的字。", choose: "選擇 {0}", pick: "選擇", cancel: "取消", change: "變更", save: "儲存", saving: "儲存中…", saved: "已儲存。", unsaved: "尚未儲存",
27
+ limit: "最多 200 位成員,包含負責人。", count: "{0} 位成員", leadRequired: "負責人一定是成員,請先指定另一位負責人才能移除。",
28
+ disabledLead: "負責人的帳號已停用,請指定新的負責人。",
29
+ failed: "無法讀取團隊,請再試一次。", searchFailed: "目前無法搜尋目錄,請再試一次。", busy: "Hub 目前忙碌,請稍後再試。", denied: "你的權限已變更,請重新整理確認目前的團隊。", saveFailed: "無法儲存變更,編輯內容仍保留;若團隊已被其他人變更,請重新整理。",
30
+ delete: "刪除團隊", deleteTitle: "刪除「{0}」?", deleteLead: "以下以團隊授予的權限將停止適用。已加入房間的成員與已同意加入的 Agent 都會保留。", noImpact: "沒有有效的團隊授權或建立房間權限。", creators: "可以建立房間", grantExpiry: "可以問 {0} · 到 {1}",
31
+ styleLoading: "正在載入團隊編輯器…", styleFailed: "無法載入團隊編輯器,請再試一次。",
32
+ },
33
+ });
34
+ export const ht = (key, ...args) => t(`hubTeam.${key}`, ...args);
@@ -0,0 +1,169 @@
1
+ /** Teams share one roster editor between Administration and the lead's My teams page. */
2
+ import { html, useEffect, useRef, useState } from "/assets/app-html.js";
3
+ import { Icon } from "/assets/ui-icons.js";
4
+ import { navigate } from "/assets/app-nav.js";
5
+ import { ht } from "./hub-teams-strings.js";
6
+
7
+ const changes = new Set();
8
+ const changed = () => { for (const fn of changes) fn(); };
9
+ // Only a fallback for older/fixture servers without isLead; real sessions omit person.
10
+ const personId = person => typeof person === "string" ? person : person?.realm && person?.objectId ? `${person.realm}/${person.objectId}` : person?.id || "";
11
+ const leads = (row, me) => row.isLead === true || row.isLead === undefined && !!me && row.lead === me;
12
+ const errorText = (out, writing = false) => out?.status === 429 ? ht("busy") : out?.status === 401 || out?.status === 403 ? ht("denied") : ht(writing ? "saveFailed" : "failed");
13
+ const date = value => new Date(value).toLocaleDateString();
14
+ const cssLoads = new WeakMap();
15
+ /** No new editor controls draw before their fresh feature stylesheet has loaded. */
16
+ export function linkHubTeamsCss(doc = typeof document === "undefined" ? null : document) {
17
+ if (!doc?.head) return Promise.resolve(false);
18
+ if (cssLoads.has(doc)) return cssLoads.get(doc);
19
+ const promise = new Promise(resolve => {
20
+ const link = doc.createElement("link"); link.setAttribute("rel", "stylesheet"); link.setAttribute("href", "/assets/hub-teams.css");
21
+ link.setAttribute("data-hub-teams-css", "1");
22
+ link.addEventListener("load", () => resolve(true), { once: true });
23
+ link.addEventListener("error", () => { link.remove(); cssLoads.delete(doc); resolve(false); }, { once: true });
24
+ doc.head.appendChild(link);
25
+ });
26
+ cssLoads.set(doc, promise); return promise;
27
+ }
28
+ function useStyle() {
29
+ const [ready, setReady] = useState(null), [retry, setRetry] = useState(0);
30
+ useEffect(() => { let live = true; linkHubTeamsCss().then(value => { if (live) setReady(value); }); return () => { live = false; }; }, [retry]);
31
+ return [ready, () => { setReady(null); setRetry(n => n + 1); }];
32
+ }
33
+ function StyleWait({ ready, retry }) {
34
+ return html`<p role="status">${ht(ready === false ? "styleFailed" : "styleLoading")}</p>${ready === false ? html`<button type="button" class="btn" onClick=${retry}>${ht("retry")}</button>` : null}`;
35
+ }
36
+ function useTeams(client) {
37
+ const [rows, setRows] = useState(null), [error, setError] = useState(null), [revision, setRevision] = useState(0), epoch = useRef(0);
38
+ useEffect(() => {
39
+ let live = true; const mine = ++epoch.current;
40
+ Promise.resolve().then(() => client.teams()).then(out => { if (!live || mine !== epoch.current) return;
41
+ if (out.ok) { setRows(Array.isArray(out.teams) ? out.teams : []); setError(null); } else setError(errorText(out));
42
+ }, () => { if (live && mine === epoch.current) setError(ht("failed")); });
43
+ const end = client.onSignedOut?.(() => { epoch.current++; setRows([]); setError(ht("denied")); });
44
+ const refresh = () => setRevision(n => n + 1); changes.add(refresh);
45
+ return () => { live = false; epoch.current++; changes.delete(refresh); end?.(); };
46
+ }, [client, revision]);
47
+ return { rows, error, refresh: () => setRevision(n => n + 1) };
48
+ }
49
+ export function HubTeamsEntry() {
50
+ const [ready, retry] = useStyle();
51
+ return html`<section class="card hub-teams"><h3>${ht("title")}</h3><p class="note">${ht("lead")}</p>
52
+ ${ready ? html`<a class="btn hub-team-button" href="/ui/hub/admin?view=teams" onClick=${e => { if (!e.metaKey && !e.ctrlKey) { e.preventDefault(); navigate("/ui/hub/admin?view=teams"); } }}>${ht("manage")}</a>` : html`<${StyleWait} ready=${ready} retry=${retry} />`}</section>`;
53
+ }
54
+ export function HubMyTeamsEntry({ client, person, active, onPick }) {
55
+ const { rows } = useTeams(client), me = personId(person);
56
+ if (!rows?.some(row => leads(row, me))) return null;
57
+ const href = "/ui/hub?view=teams";
58
+ return html`<a class=${`side-row${active ? " active" : ""}`} href=${href} aria-current=${active ? "page" : undefined}
59
+ onClick=${e => { if (e.metaKey || e.ctrlKey) return; e.preventDefault(); onPick?.(); navigate(href); }}><${Icon} name="user" /><span class="grow">${ht("mine")}</span></a>`;
60
+ }
61
+
62
+ /** Feedback is cancellable and never applies a result from a previous query or team. */
63
+ export function TeamSuggestions({ client, kind = "person", teamId, disabled, onPick }) {
64
+ const [query, setQuery] = useState(""), [answer, setAnswer] = useState(null), [busy, setBusy] = useState(false), epoch = useRef(0), controller = useRef(null);
65
+ useEffect(() => { epoch.current++; controller.current?.abort(); setAnswer(null); setBusy(false);
66
+ return () => { epoch.current++; controller.current?.abort(); }; }, [client, kind, teamId]);
67
+ const search = async () => {
68
+ const q = query.trim(); if (disabled || q.length < 2 || q.length > 64) return;
69
+ const mine = ++epoch.current; controller.current?.abort(); const current = controller.current = new AbortController(); setBusy(true); setAnswer(null);
70
+ let out; try { out = await client.teamSuggestions(kind, q, teamId, current.signal); } catch { out = { ok: false }; }
71
+ if (mine !== epoch.current || current.signal.aborted) return;
72
+ setBusy(false); setAnswer(out);
73
+ };
74
+ const hits = answer?.ok && Array.isArray(answer.candidates) ? answer.candidates.slice(0, 20).filter(row => row.kind === kind) : [];
75
+ return html`<div class="hub-team-search">
76
+ <div class="hub-team-search-line"><label class="field grow"><span>${ht(kind === "group" ? "department" : "members")}</span><input type="search" maxlength="64" autocomplete="off" spellcheck=${false}
77
+ placeholder=${ht(kind === "group" ? "departmentQuery" : "personQuery")} value=${query} disabled=${disabled}
78
+ onInput=${e => { epoch.current++; controller.current?.abort(); setQuery(e.target.value); setAnswer(null); setBusy(false); }}
79
+ onKeyDown=${e => { if (e.key === "Enter") { e.preventDefault(); void search(); } }} /></label>
80
+ <button type="button" class="btn hub-team-button" disabled=${disabled || busy || query.trim().length < 2 || query.trim().length > 64} onClick=${search}>${ht("search")}</button></div>
81
+ <p class="note" role="status">${busy ? ht("searching") : !answer ? ht(kind === "group" ? "groupHint" : "searchHint") : !answer.ok ? answer.status === 429 ? ht("busy") : ht("searchFailed") : hits.length ? "" : ht("noMatches")}</p>
82
+ ${hits.length ? html`<ul class="hub-team-hits">${hits.map(row => html`<li key=${row.id}><span class="grow"><strong>${row.name}</strong>${row.login ? html`<small class="note"> · ${row.login}</small>` : null}</span>
83
+ <button type="button" class="btn hub-team-button" disabled=${disabled} aria-label=${ht("choose", row.name)} onClick=${() => { epoch.current++; controller.current?.abort(); onPick(row); setQuery(""); setAnswer(null); }}>${ht("pick")}</button></li>`)}</ul>` : null}
84
+ </div>`;
85
+ }
86
+ const draftFrom = team => ({ name: team?.name || "", department: team?.department || "", departmentName: team?.departmentName || "", lead: team?.lead || "",
87
+ members: (team?.memberInfo || (team?.members || []).map(id => ({ id, name: id }))).map(row => ({ ...row })) });
88
+ const editableImage = draft => JSON.stringify([draft.name.trim(), draft.department, draft.lead, draft.members.map(row => row.id).sort()]);
89
+ function TeamEditor({ client, id, mode, onSaved, onBack }) {
90
+ const [view, setView] = useState(null), [draft, setDraft] = useState(draftFrom(null)), [error, setError] = useState(null), [busy, setBusy] = useState(false), [picker, setPicker] = useState(id ? null : "department"), [deleting, setDeleting] = useState(false), [reload, setReload] = useState(0), [saved, setSaved] = useState(false);
91
+ const epoch = useRef(0), writing = useRef(false), admin = mode === "admin";
92
+ useEffect(() => {
93
+ let live = true; const mine = ++epoch.current;
94
+ if (id) Promise.resolve().then(() => client.team(id)).then(out => {
95
+ if (!live || mine !== epoch.current) return;
96
+ if (out.ok && out.team) { setView(out.team); setDraft(draftFrom(out.team)); setError(null); setPicker(null); }
97
+ else setError(errorText(out));
98
+ }, () => { if (live && mine === epoch.current) setError(ht("failed")); });
99
+ const end = client.onSignedOut?.(() => { epoch.current++; setView(null); setError(ht("denied")); });
100
+ return () => { live = false; epoch.current++; end?.(); };
101
+ }, [client, id, reload]);
102
+ const allowed = !id || view?.canManage === true;
103
+ const dirty = editableImage(draft) !== editableImage(draftFrom(view));
104
+ const save = async e => {
105
+ e?.preventDefault?.(); if (writing.current || !allowed || !draft.lead || !draft.department || !draft.name.trim()) return;
106
+ writing.current = true; setBusy(true); setError(null); setSaved(false); const mine = ++epoch.current;
107
+ const members = [...new Set([...draft.members.map(row => row.id), draft.lead])];
108
+ const value = admin ? { name: draft.name.trim(), department: draft.department, lead: draft.lead, members } : { members };
109
+ let out; try { out = id ? await client.updateTeam(id, { ...value, revision: view.revision }) : await client.createTeam(value); } catch { out = { ok: false }; }
110
+ if (mine !== epoch.current) return;
111
+ writing.current = false; setBusy(false);
112
+ if (out.ok && out.team) {
113
+ // Writes may return only the stored Team. Keep known display metadata until
114
+ // the fenced detail read supplies current names, permissions and status.
115
+ const detailed = Array.isArray(out.team.memberInfo);
116
+ const next = detailed ? out.team : { ...view, ...out.team, departmentName: draft.departmentName,
117
+ memberInfo: out.team.members.map(id => draft.members.find(row => row.id === id) || { id, name: id }) };
118
+ setView(next); setDraft(draftFrom(next)); setSaved(true); setPicker(null); changed(); onSaved(out.team);
119
+ if (id && !detailed) setReload(n => n + 1);
120
+ }
121
+ else setError(errorText(out, true));
122
+ };
123
+ const remove = async () => {
124
+ if (writing.current || !admin || !id) return;
125
+ writing.current = true; setBusy(true); setError(null); const mine = ++epoch.current;
126
+ let out; try { out = await client.deleteTeam(id); } catch { out = { ok: false }; }
127
+ if (mine !== epoch.current) return; writing.current = false; setBusy(false);
128
+ if (out.ok) { changed(); onBack(); } else setError(errorText(out, true));
129
+ };
130
+ const pick = row => {
131
+ setSaved(false);
132
+ if (picker === "department") setDraft(old => ({ ...old, department: row.id, departmentName: row.name }));
133
+ else setDraft(old => ({ ...old, ...(picker === "lead" ? { lead: row.id } : {}), members: old.members.some(member => member.id === row.id) ? old.members : [...old.members, row] }));
134
+ setPicker(null);
135
+ };
136
+ return html`<section class="card hub-team-editor"><div class="hub-team-head"><h3>${ht(id ? "edit" : "create", view?.name || draft.name)}</h3><button type="button" class="btn hub-team-button" disabled=${busy} onClick=${onBack}>${ht("back")}</button></div>
137
+ ${error ? html`<p class="err" role="alert">${error}</p><button type="button" class="btn hub-team-button" disabled=${busy} onClick=${() => setReload(n => n + 1)}>${ht("refresh")}</button>` : null}
138
+ ${id && !view ? html`<p role="status">${ht("loading")}</p>` : html`<form class="form" onSubmit=${save}>
139
+ ${admin ? html`<label class="field"><span>${ht("name")}</span><input data-team-name maxlength="100" required value=${draft.name} disabled=${busy || !allowed} onInput=${e => { setDraft(old => ({ ...old, name: e.target.value })); setSaved(false); }} /></label>` : null}
140
+ <div class="hub-team-head"><p class="note">${ht("departmentLine", draft.departmentName || ht("chooseDepartment"))}</p>${admin ? html`<button type="button" class="btn hub-team-button" disabled=${busy || !allowed} onClick=${() => setPicker("department")}>${ht("change")}</button>` : null}</div>
141
+ ${view?.leadEligible === false ? html`<p class="warn" role="status">${ht("disabledLead")}</p>` : null}
142
+ ${admin ? html`<div class="hub-team-head"><p>${ht("leadPerson")}: <strong>${draft.members.find(row => row.id === draft.lead)?.name || ht("chooseLead")}</strong></p><button type="button" class="btn hub-team-button" disabled=${busy || !allowed} onClick=${() => setPicker("lead")}>${ht("chooseLead")}</button></div>` : null}
143
+ ${picker ? html`<div class="hub-team-picker"><${TeamSuggestions} key=${picker} client=${client} kind=${picker === "department" ? "group" : "person"} teamId=${id || undefined} disabled=${busy || !allowed} onPick=${pick} /><button type="button" class="btn hub-team-button" onClick=${() => setPicker(null)}>${ht("cancel")}</button></div>` : null}
144
+ <div class="hub-team-head"><h4>${ht("members")} · ${draft.members.length}</h4><button type="button" class="btn hub-team-button" disabled=${busy || !allowed || draft.members.length >= 200} onClick=${() => setPicker("member")}>${ht("add")}</button></div>
145
+ <p class="note">${ht("limit")} ${ht("leadRequired")}</p>
146
+ <div class="hub-team-table-wrap"><table class="hub-team-table"><thead><tr><th>${ht("members")}</th><th>${ht("role")}</th><th>${ht("signedIn")}</th><th>${ht("agents")}</th><th><span class="sr-only">${ht("remove")}</span></th></tr></thead><tbody>
147
+ ${draft.members.map(row => html`<tr key=${row.id}><td><strong>${row.name}</strong>${row.login ? html`<small class="note hub-team-detail">${row.login}</small>` : null}${row.department ? html`<small class="note hub-team-detail">${row.department}</small>` : null}</td><td data-label=${ht("role")}>${ht(row.id === draft.lead ? "roleLead" : "roleMember")}</td>
148
+ <td data-label=${ht("signedIn")}>${row.signedIn === true ? ht("yes") : row.signedIn === false ? ht("notYet") : ht("unobserved")}</td><td data-label=${ht("agents")}>${row.agents?.length ? row.agents.map(agent => agent.name).join(", ") : ht("none")}</td><td><button type="button" class="btn hub-team-button" disabled=${busy || !allowed || row.id === draft.lead || row.id === view?.lead} aria-label=${`${ht("remove")} ${row.name}`} onClick=${() => { setDraft(old => ({ ...old, members: old.members.filter(member => member.id !== row.id) })); setSaved(false); }}>${ht("remove")}</button></td></tr>`)}
149
+ </tbody></table></div>
150
+ <div class="hub-team-actions"><button type="submit" class="btn btn-primary hub-team-button" disabled=${busy || !allowed || !draft.name.trim() || !draft.department || !draft.lead}>${ht(busy ? "saving" : "save")}</button>${dirty || saved ? html`<span role="status">${ht(dirty ? "unsaved" : "saved")}</span>` : null}
151
+ ${admin && id ? html`<button type="button" class="btn btn-danger hub-team-button" disabled=${busy || !allowed} onClick=${() => setDeleting(true)}>${ht("delete")}</button>` : null}</div>
152
+ </form>`}
153
+ ${deleting ? html`<div class="hub-team-delete" role="region" aria-label=${ht("deleteTitle", view.name)}><h4>${ht("deleteTitle", view.name)}</h4><p>${ht("deleteLead")}</p>
154
+ ${view.impact?.grants?.length || view.impact?.roomCreator ? html`<ul>${view.impact.grants.map(grant => html`<li>${ht("grantExpiry", grant.name, date(grant.expiresAt))}</li>`)}${view.impact.roomCreator ? html`<li>${ht("creators")}</li>` : null}</ul>` : html`<p class="note">${ht("noImpact")}</p>`}
155
+ <div class="hub-team-actions"><button type="button" class="btn hub-team-button" disabled=${busy} onClick=${() => setDeleting(false)}>${ht("cancel")}</button><button type="button" class="btn btn-danger hub-team-button" disabled=${busy} onClick=${remove}>${ht("delete")}</button></div></div>` : null}
156
+ </section>`;
157
+ }
158
+ export function HubTeamsPage({ client, mode = "lead", person }) {
159
+ const [ready, retry] = useStyle(), { rows, error, refresh } = useTeams(client), [selected, setSelected] = useState(null), me = personId(person);
160
+ const shown = (rows || []).filter(row => mode === "admin" || leads(row, me));
161
+ return html`<div class="hub-teams"><p class="s-page-lead hub-page-lead">${ht(mode === "admin" ? "pageLead" : "myLead")}</p>
162
+ ${!ready ? html`<${StyleWait} ready=${ready} retry=${retry} />` : html`<div class="s-section-layout">
163
+ ${selected !== null ? html`<${TeamEditor} key=${selected} client=${client} id=${selected || null} mode=${mode} onBack=${() => { setSelected(null); refresh(); }} onSaved=${team => { setSelected(team.id); refresh(); }} />`
164
+ : html`<section class="card"><div class="hub-team-head"><h3>${ht(mode === "admin" ? "title" : "mine")}</h3>${mode === "admin" ? html`<button type="button" class="btn btn-primary hub-team-button" onClick=${() => setSelected("")}>${ht("create")}</button>` : null}</div>
165
+ ${error ? html`<p class="err" role="alert">${error}</p><button type="button" class="btn hub-team-button" onClick=${refresh}>${ht("retry")}</button>` : null}
166
+ ${rows === null ? html`<p role="status">${ht("loading")}</p>` : shown.length ? html`<ul class="hub-team-list">${shown.map(row => html`<li key=${row.id}><span class="grow"><strong>${row.name}</strong><small class="note hub-team-detail">${ht("departmentLine", row.departmentName)} · ${ht("count", row.members.length)}</small></span><button type="button" class="btn hub-team-button" aria-label=${ht("edit", row.name)} onClick=${() => setSelected(row.id)}>${ht("manage")}</button></li>`)}</ul>` : html`<p class="note">${ht(mode === "admin" ? "empty" : "noMine")}</p>`}
167
+ </section>`}
168
+ </div>`}</div>`;
169
+ }