@songsid/agend 2.4.0-beta.13 → 2.4.0-beta.15

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 (183) hide show
  1. package/dist/agent-endpoint.js +28 -6
  2. package/dist/agent-endpoint.js.map +1 -1
  3. package/dist/auth-api.js +1 -0
  4. package/dist/auth-api.js.map +1 -1
  5. package/dist/backend/claude-code.d.ts +9 -0
  6. package/dist/backend/claude-code.js +60 -4
  7. package/dist/backend/claude-code.js.map +1 -1
  8. package/dist/backend/grok.js +11 -0
  9. package/dist/backend/grok.js.map +1 -1
  10. package/dist/backend/types.d.ts +3 -0
  11. package/dist/backend/types.js.map +1 -1
  12. package/dist/backend-availability.d.ts +1 -16
  13. package/dist/backend-availability.js +2 -91
  14. package/dist/backend-availability.js.map +1 -1
  15. package/dist/backend-version-static.d.ts +15 -0
  16. package/dist/backend-version-static.js +95 -0
  17. package/dist/backend-version-static.js.map +1 -0
  18. package/dist/build-provenance.json +1 -1
  19. package/dist/channel/adapters/telegram.js +3 -1
  20. package/dist/channel/adapters/telegram.js.map +1 -1
  21. package/dist/channel/mcp-server.js +18 -1
  22. package/dist/channel/mcp-server.js.map +1 -1
  23. package/dist/channel/tool-router.d.ts +4 -0
  24. package/dist/channel/tool-router.js +43 -19
  25. package/dist/channel/tool-router.js.map +1 -1
  26. package/dist/classic-channel-manager.d.ts +3 -0
  27. package/dist/classic-channel-manager.js +18 -0
  28. package/dist/classic-channel-manager.js.map +1 -1
  29. package/dist/classic-cli-guard.d.ts +66 -0
  30. package/dist/classic-cli-guard.js +209 -0
  31. package/dist/classic-cli-guard.js.map +1 -0
  32. package/dist/cli-audited.js +7 -5
  33. package/dist/cli-audited.js.map +1 -1
  34. package/dist/config-validator.js +3 -0
  35. package/dist/config-validator.js.map +1 -1
  36. package/dist/contact-auth-api.d.ts +17 -0
  37. package/dist/contact-auth-api.js +88 -0
  38. package/dist/contact-auth-api.js.map +1 -0
  39. package/dist/contact-auth-files.d.ts +6 -0
  40. package/dist/contact-auth-files.js +29 -0
  41. package/dist/contact-auth-files.js.map +1 -0
  42. package/dist/contact-auth-policy.d.ts +80 -0
  43. package/dist/contact-auth-policy.js +25 -0
  44. package/dist/contact-auth-policy.js.map +1 -0
  45. package/dist/contact-auth-service.d.ts +32 -0
  46. package/dist/contact-auth-service.js +99 -0
  47. package/dist/contact-auth-service.js.map +1 -0
  48. package/dist/contact-auth-store.d.ts +86 -0
  49. package/dist/contact-auth-store.js +357 -0
  50. package/dist/contact-auth-store.js.map +1 -0
  51. package/dist/contact-auth-types.d.ts +196 -0
  52. package/dist/contact-auth-types.js +7 -0
  53. package/dist/contact-auth-types.js.map +1 -0
  54. package/dist/daemon.d.ts +8 -0
  55. package/dist/daemon.js +93 -4
  56. package/dist/daemon.js.map +1 -1
  57. package/dist/delivery-outbox.d.ts +6 -0
  58. package/dist/delivery-outbox.js +19 -0
  59. package/dist/delivery-outbox.js.map +1 -1
  60. package/dist/fleet-manager.d.ts +48 -0
  61. package/dist/fleet-manager.js +484 -22
  62. package/dist/fleet-manager.js.map +1 -1
  63. package/dist/general-knowledge/skills/concepts/SKILL.md +18 -0
  64. package/dist/general-knowledge/skills/credential-profiles/SKILL.md +5 -0
  65. package/dist/general-knowledge/skills/cross-instance-messaging/SKILL.md +38 -0
  66. package/dist/general-knowledge/skills/hub/SKILL.md +6 -0
  67. package/dist/general-knowledge/skills/web-dashboard/SKILL.md +5 -0
  68. package/dist/hub/audit/index.d.ts +3 -1
  69. package/dist/hub/audit/index.js +35 -3
  70. package/dist/hub/audit/index.js.map +1 -1
  71. package/dist/hub/catalog.d.ts +8 -0
  72. package/dist/hub/catalog.js +39 -4
  73. package/dist/hub/catalog.js.map +1 -1
  74. package/dist/hub/compose/server.d.ts +2 -0
  75. package/dist/hub/compose/server.js +11 -1
  76. package/dist/hub/compose/server.js.map +1 -1
  77. package/dist/hub/directory/directory.js +5 -2
  78. package/dist/hub/directory/directory.js.map +1 -1
  79. package/dist/hub/directory/types.d.ts +5 -1
  80. package/dist/hub/directory/types.js.map +1 -1
  81. package/dist/hub/group-policy/resources.d.ts +1 -1
  82. package/dist/hub/http/compose.d.ts +2 -0
  83. package/dist/hub/http/compose.js +123 -6
  84. package/dist/hub/http/compose.js.map +1 -1
  85. package/dist/hub/http/deps.d.ts +2 -0
  86. package/dist/hub/http/schema.js +6 -1
  87. package/dist/hub/http/schema.js.map +1 -1
  88. package/dist/hub/invitations.js +15 -7
  89. package/dist/hub/invitations.js.map +1 -1
  90. package/dist/hub/roles/cutover-inventory.d.ts +3 -0
  91. package/dist/hub/roles/cutover-inventory.js +20 -4
  92. package/dist/hub/roles/cutover-inventory.js.map +1 -1
  93. package/dist/hub/roles/cutover-marker.d.ts +18 -2
  94. package/dist/hub/roles/cutover-marker.js +6 -2
  95. package/dist/hub/roles/cutover-marker.js.map +1 -1
  96. package/dist/hub/room-agent-discovery-model.d.ts +29 -0
  97. package/dist/hub/room-agent-discovery-model.js +33 -0
  98. package/dist/hub/room-agent-discovery-model.js.map +1 -0
  99. package/dist/hub/room-agent-discovery.d.ts +14 -0
  100. package/dist/hub/room-agent-discovery.js +65 -0
  101. package/dist/hub/room-agent-discovery.js.map +1 -0
  102. package/dist/hub/room-agent-requests.d.ts +71 -0
  103. package/dist/hub/room-agent-requests.js +377 -0
  104. package/dist/hub/room-agent-requests.js.map +1 -0
  105. package/dist/hub/rooms/directory.d.ts +13 -0
  106. package/dist/hub/rooms/directory.js +12 -3
  107. package/dist/hub/rooms/directory.js.map +1 -1
  108. package/dist/hub/rooms/schema.d.ts +5 -0
  109. package/dist/hub/rooms/schema.js +9 -0
  110. package/dist/hub/rooms/schema.js.map +1 -1
  111. package/dist/hub/rooms/service.d.ts +43 -19
  112. package/dist/hub/rooms/service.js +67 -11
  113. package/dist/hub/rooms/service.js.map +1 -1
  114. package/dist/hub/rooms/types.d.ts +1 -1
  115. package/dist/instance-lifecycle.d.ts +3 -1
  116. package/dist/instance-lifecycle.js +4 -1
  117. package/dist/instance-lifecycle.js.map +1 -1
  118. package/dist/locale.js +34 -4
  119. package/dist/locale.js.map +1 -1
  120. package/dist/needs-you-hub.d.ts +1 -0
  121. package/dist/needs-you-hub.js +9 -0
  122. package/dist/needs-you-hub.js.map +1 -1
  123. package/dist/needs-you.d.ts +12 -2
  124. package/dist/needs-you.js.map +1 -1
  125. package/dist/outbound-handlers.d.ts +9 -0
  126. package/dist/outbound-handlers.js +46 -10
  127. package/dist/outbound-handlers.js.map +1 -1
  128. package/dist/runtime-cli-install.js +7 -7
  129. package/dist/runtime-cli-install.js.map +1 -1
  130. package/dist/topic-commands.d.ts +1 -1
  131. package/dist/topic-commands.js +4 -6
  132. package/dist/topic-commands.js.map +1 -1
  133. package/dist/ui/agent-details-settings.js +7 -5
  134. package/dist/ui/contact-auth-client.js +50 -0
  135. package/dist/ui/contact-auth-strings.js +195 -0
  136. package/dist/ui/contact-authorizations.js +125 -0
  137. package/dist/ui/contact-needs.js +100 -0
  138. package/dist/ui/contact-permissions.js +238 -0
  139. package/dist/ui/contact-ticket-badge.js +54 -0
  140. package/dist/ui/contact-tool-groups.js +39 -0
  141. package/dist/ui/hub-client.js +30 -7
  142. package/dist/ui/hub-invitations.js +5 -1
  143. package/dist/ui/hub-room-new.js +10 -3
  144. package/dist/ui/hub-room-owner-requests-strings.js +114 -0
  145. package/dist/ui/hub-room-owner-requests.js +264 -0
  146. package/dist/ui/hub-room-pins.js +43 -0
  147. package/dist/ui/hub-room-settings.js +11 -2
  148. package/dist/ui/hub-room-strings.js +3 -0
  149. package/dist/ui/hub-room-thread.js +47 -5
  150. package/dist/ui/panel-chat.js +2 -0
  151. package/dist/ui/panel-details.js +2 -0
  152. package/dist/ui/panel-fleet.js +3 -2
  153. package/dist/ui/panel-hub.js +7 -1
  154. package/dist/ui/panel-needs.js +11 -4
  155. package/dist/ui/panel-settings.js +3 -0
  156. package/dist/ui/settings-appearance.js +6 -1
  157. package/dist/ui/settings-registry.js +1 -1
  158. package/dist/ui/shared/app-i18n.js +4 -0
  159. package/dist/ui/shared/app-route.js +1 -1
  160. package/dist/ui/shared/app-shell.js +18 -7
  161. package/dist/ui/shared/app-stream.js +3 -1
  162. package/dist/ui/shared/app.css +86 -0
  163. package/dist/ui/shared/chat-quote.js +26 -2
  164. package/dist/ui/shared/chat-thread.js +6 -2
  165. package/dist/ui/shared/hub-rooms-u2.css +22 -0
  166. package/dist/ui/shared/text-undo.js +17 -3
  167. package/dist/ui/shared/theme-picker.js +46 -0
  168. package/dist/ui/shared/theme.js +36 -3
  169. package/dist/ui/shared/tokens.css +273 -0
  170. package/dist/ui/shared/ui-confirm.js +5 -2
  171. package/dist/web-api.d.ts +10 -0
  172. package/dist/web-api.js +55 -3
  173. package/dist/web-api.js.map +1 -1
  174. package/dist/web-chat-history.d.ts +5 -0
  175. package/dist/web-chat-history.js +26 -0
  176. package/dist/web-chat-history.js.map +1 -1
  177. package/dist/web-reply-files.d.ts +1 -0
  178. package/dist/web-reply-files.js +2 -0
  179. package/dist/web-reply-files.js.map +1 -1
  180. package/dist/web-shell-routes.d.ts +1 -1
  181. package/dist/web-shell-routes.js +2 -1
  182. package/dist/web-shell-routes.js.map +1 -1
  183. package/package.json +1 -1
@@ -0,0 +1,114 @@
1
+ import { register, t } from "/assets/app-i18n.js";
2
+ register("hubOwnerRequests", {
3
+ en: {
4
+ missing: "Can't find someone's agent? It may not be shared with you.",
5
+ ask: "Ask its owner",
6
+ chooseTitle: "Ask an agent's owner",
7
+ choose: "Who owns it?",
8
+ owner: "Owner",
9
+ search: "Search for a person",
10
+ title: 'Ask {0} to add an agent to "{1}"',
11
+ lead: "{0} will see who is asking and which room. You will only learn about an agent if {0} adds one.",
12
+ note: "Which agent, if you know (optional)",
13
+ send: "Send request",
14
+ cancel: "Cancel",
15
+ waiting: "Asked {0} for an agent · waiting",
16
+ cancelRequest: "Cancel request",
17
+ declined: "{0} didn't add an agent.",
18
+ expired: "{0} didn't answer.",
19
+ accepted: "{0} added an agent.",
20
+ ownerOff: "{0} isn't taking requests for agents.",
21
+ already: "A request to {0} is already open for this room.",
22
+ limit: "You have sent 5 requests today. You can send more after {0}.",
23
+ failed: "That was not sent. Try again.",
24
+ more: "Load more",
25
+ requestsTitle: "Requests for agents",
26
+ requestLead: '{0} asks you to add one of your agents to the room "{1}"',
27
+ requestBody: "People in the room can @ it there, and everyone in the room sees its answers. When @-ed, it reads the room's recent messages. They cannot ask it one-to-one. {0} people are in the room now; the room's managers can add more.",
28
+ requestBodyOne: "People in the room can @ it there, and everyone in the room sees its answers. When @-ed, it reads the room's recent messages. They cannot ask it one-to-one. 1 person is in the room now; the room's managers can add more.",
29
+ which: "Which agent",
30
+ chooseAgent: "Choose an agent",
31
+ quotedNote: '"{0}"',
32
+ notShared: "Not shared yet. Share it first on My agents.",
33
+ paused: "Sharing is paused. Resume it on My agents.",
34
+ unavailable: "This agent can't be added right now. Check My agents.",
35
+ inRoom: "Already in this room.",
36
+ myAgents: "My agents",
37
+ noAgents: "You have no shared agent to add. Share one on My agents first, or decline this request.",
38
+ add: "Add to this room",
39
+ decline: "Decline",
40
+ gone: "This request is no longer open.",
41
+ loadFailed: "Requests could not be loaded.",
42
+ retry: "Try again",
43
+ actionFailed: "That did not go through. Try again.",
44
+ added: 'Agent added to "{0}".',
45
+ declinedNotice: "Request declined.",
46
+ stopRequests: "Don't let room managers ask me for agents",
47
+ stopHint: "Requests already waiting stay open. You can still add an agent or decline them.",
48
+ saved: "Saved.",
49
+ discoveryLabel: "Room managers can find this agent",
50
+ discoveryHint: "Managers of any room can find it by name and ask you to add it to their room. They see its name, its introduction and your name. You still decide each time, and this lets nobody ask it one-to-one.",
51
+ discoveryPaused: "Hidden while sharing is paused.",
52
+ discoveryUnshared: "Share this agent first.",
53
+ discoveryOptOut: "Off while \"Don't let room managers ask me for agents\" is on.",
54
+ askOwner: "Ask {0}",
55
+ askOwnerLabel: "Ask {0} to add {1} to this room",
56
+ classic: "ClassicBot room",
57
+ },
58
+ "zh-TW": {
59
+ missing: "找不到某位同仁的 Agent 嗎?它可能沒有分享給你。",
60
+ ask: "請擁有者加入",
61
+ chooseTitle: "請擁有者加入 Agent",
62
+ choose: "擁有者是誰?",
63
+ owner: "擁有者",
64
+ search: "搜尋同仁",
65
+ title: "請 {0} 把 Agent 加入「{1}」",
66
+ lead: "{0} 會看到是誰提出、是哪個房間。只有在 {0} 加入之後,你才會知道是哪個 Agent。",
67
+ note: "如果知道是哪個 Agent,可以寫在這裡(選填)",
68
+ send: "送出請求",
69
+ cancel: "取消",
70
+ waiting: "已請 {0} 加入 Agent · 等待中",
71
+ cancelRequest: "取消請求",
72
+ declined: "{0} 沒有加入 Agent。",
73
+ expired: "{0} 沒有回應。",
74
+ accepted: "{0} 已加入 Agent。",
75
+ ownerOff: "{0} 目前不接受加入 Agent 的請求。",
76
+ already: "這個房間已經向 {0} 送出請求,仍在等待回應。",
77
+ limit: "你今天已送出 5 個請求,{0} 之後可以再送。",
78
+ failed: "沒有送出,請再試一次。",
79
+ more: "載入更多",
80
+ requestsTitle: "加入 Agent 的請求",
81
+ requestLead: "{0} 請你把一個 Agent 加入房間「{1}」",
82
+ requestBody: "房間裡的人可以在房間裡 @ 它,所有人都看得到它的回答。被 @ 時,它會讀到房間最近的訊息。他們不能一對一問它。房間現在有 {0} 個人,房間管理員之後可以再加人。",
83
+ requestBodyOne: "房間裡的人可以在房間裡 @ 它,所有人都看得到它的回答。被 @ 時,它會讀到房間最近的訊息。他們不能一對一問它。房間現在有 1 個人,房間管理員之後可以再加人。",
84
+ which: "要加入哪一個",
85
+ chooseAgent: "選擇要加入的 Agent",
86
+ quotedNote: "「{0}」",
87
+ notShared: "還沒有分享。請先到「我的 Agent」分享。",
88
+ paused: "已暫停分享。請到「我的 Agent」恢復分享。",
89
+ unavailable: "目前無法加入這個 Agent,請到「我的 Agent」確認。",
90
+ inRoom: "已經在這個房間。",
91
+ myAgents: "我的 Agent",
92
+ noAgents: "目前沒有可以加入的已分享 Agent。請先到「我的 Agent」分享,或選擇不加入。",
93
+ add: "加入這個房間",
94
+ decline: "不加入",
95
+ gone: "這個請求已經結束。",
96
+ loadFailed: "無法載入請求。",
97
+ retry: "再試一次",
98
+ actionFailed: "沒有送出,請再試一次。",
99
+ added: "已把 Agent 加入「{0}」。",
100
+ declinedNotice: "已選擇不加入。",
101
+ stopRequests: "不要讓房間管理員請我加入 Agent",
102
+ stopHint: "已經收到的請求仍然有效,你還是可以加入 Agent 或選擇不加入。",
103
+ saved: "已儲存。",
104
+ discoveryLabel: "房間管理員可以找到這個 Agent",
105
+ discoveryHint: "任何房間的管理員都能用名稱找到它,並請你把它加入他們的房間。他們會看到它的名稱、介紹和你的名字。每次仍由你決定,而且這不會讓任何人可以一對一問它。",
106
+ discoveryPaused: "暫停分享期間不會顯示。",
107
+ discoveryUnshared: "請先分享這個 Agent。",
108
+ discoveryOptOut: "已開啟「不要讓房間管理員請我加入 Agent」,所以目前無法使用。",
109
+ askOwner: "請 {0} 加入",
110
+ askOwnerLabel: "請 {0} 把 {1} 加入這個房間",
111
+ classic: "ClassicBot 房間",
112
+ },
113
+ });
114
+ export const hrq = (key, ...args) => t("hubOwnerRequests." + key, ...args);
@@ -0,0 +1,264 @@
1
+ import { html, useEffect, useLayoutEffect, useRef, useState } from "/assets/app-html.js";
2
+ import { Dialog } from "/assets/ui-dialog.js";
3
+ import { RoomPicker } from "./hub-room-new.js";
4
+ import { hrq } from "./hub-room-owner-requests-strings.js";
5
+ import { hn } from "./hub-room-new-strings.js";
6
+
7
+ export function ownerRequestError(result, owner) {
8
+ if (result?.code === "owner-not-taking-requests") return hrq("ownerOff", owner);
9
+ if (result?.code === "request-open") return hrq("already", owner);
10
+ if (result?.code === "request-limit" && Number.isSafeInteger(result.resetsAt) && result.resetsAt > 0 && result.resetsAt <= 8.64e15) {
11
+ const time = new Date(result.resetsAt).toLocaleString(undefined, { month: "numeric", day: "numeric", hour: "2-digit", minute: "2-digit" });
12
+ return hrq("limit", time);
13
+ }
14
+ return hrq("failed");
15
+ }
16
+
17
+ /** The selection is a person, never evidence that the person owns any agent. */
18
+ export function OwnerAgentRequestDialog({ client, roomId, roomName, onClose, onSent } = {}) {
19
+ const [picked, setPicked] = useState([]), [note, setNote] = useState(""), [busy, setBusy] = useState(false), [error, setError] = useState("");
20
+ const [scope] = useState(() => client.roomAgentRequestScope?.());
21
+ const live = useRef(true), sending = useRef(false), attempt = useRef(null);
22
+ useEffect(() => { live.current = true; return () => { live.current = false; }; }, []);
23
+ const owner = picked[0] ?? null;
24
+ const send = async event => {
25
+ event?.preventDefault?.();
26
+ if (sending.current || !owner || note.length > 100) return;
27
+ const frozen = { owner: owner.id, note: note.trim() };
28
+ if (!attempt.current || attempt.current.owner !== frozen.owner || attempt.current.note !== frozen.note)
29
+ attempt.current = { ...frozen, idempotencyKey: crypto.randomUUID() };
30
+ sending.current = true; setBusy(true); setError("");
31
+ let result;
32
+ try { result = await client.requestRoomAgent(scope, roomId, { ...attempt.current }); }
33
+ catch { result = null; }
34
+ if (!live.current) return;
35
+ sending.current = false; setBusy(false);
36
+ if (result?.ok) { onSent?.(result.request); onClose?.(); }
37
+ else setError(ownerRequestError(result, owner.name));
38
+ };
39
+ const actions = html`
40
+ <button type="button" class="btn btn-ghost" disabled=${busy} onClick=${onClose}>${hrq("cancel")}</button>
41
+ ${owner ? html`<button type="submit" form="hubOwnerAgentRequestForm" class="btn btn-primary" disabled=${busy}>${hrq("send")}</button>` : null}`;
42
+ return html`<${Dialog} cls="hub-owner-request" title=${owner ? hrq("title", owner.name, roomName) : hrq("chooseTitle")}
43
+ onClose=${onClose} busy=${busy} actions=${actions}>
44
+ <form id="hubOwnerAgentRequestForm" class="form" onSubmit=${send}>
45
+ <fieldset disabled=${busy}>
46
+ ${owner ? html`<div class="field"><span id="hubRequestOwnerLabel">${hrq("owner")}</span>
47
+ <ul class="hub-room-tags" aria-labelledby="hubRequestOwnerLabel"><li class="tag">${owner.name}
48
+ <button type="button" class="chip-btn" aria-label=${hn("remove", owner.name)} onClick=${() => { setPicked([]); setError(""); }}>×</button>
49
+ </li></ul></div>`
50
+ : html`<${RoomPicker} client=${client} id="hubRequestOwner" kinds=${["person"]} label=${hrq("choose")} placeholder=${hrq("search")}
51
+ picked=${picked} onChange=${next => { setPicked(next.slice(-1)); setError(""); }} />`}
52
+ ${owner ? html`<p class="note">${hrq("lead", owner.name)}</p>
53
+ <label class="field" for="hubOwnerAgentNote"><span>${hrq("note")}</span>
54
+ <input id="hubOwnerAgentNote" type="text" maxlength="100" value=${note} onInput=${event => setNote(event.target.value.slice(0, 100))} />
55
+ <small class="note">${note.length} / 100</small>
56
+ </label>` : null}
57
+ </fieldset>
58
+ ${error ? html`<p class="note" role="alert">${error}</p>` : null}
59
+ </form>
60
+ </${Dialog}>`;
61
+ }
62
+
63
+ const valid = row => row && typeof row.id === "string" && typeof row.owner?.name === "string"
64
+ && ["pending", "declined", "expired", "accepted"].includes(row.state);
65
+ export function OwnerAgentRequestRows({ client, roomId, page, onChanged, busy = false } = {}) {
66
+ const [scope] = useState(() => client.roomAgentRequestScope?.());
67
+ const [extra, setExtra] = useState([]), [next, setNext] = useState(page?.next ?? null), [error, setError] = useState(""), [working, setWorking] = useState(false);
68
+ const live = useRef(true), pending = useRef(false);
69
+ const view = useRef({ page, roomId });
70
+ // Retire old responses at render, before the reset effect or a later operation can run.
71
+ if (view.current.page !== page || view.current.roomId !== roomId) view.current = { page, roomId };
72
+ useEffect(() => { live.current = true; return () => { live.current = false; }; }, []);
73
+ useLayoutEffect(() => {
74
+ setExtra([]); setNext(page?.next ?? null); setError(""); setWorking(false); pending.current = false;
75
+ }, [page, roomId]);
76
+ useEffect(() => client.subscribeRooms?.({ "invitation.changed": () => onChanged?.() }) ?? (() => {}), [client, roomId, onChanged]);
77
+ const rows = [...(Array.isArray(page?.requests) ? page.requests : []), ...extra].filter(valid);
78
+ const act = async (id, more = false) => {
79
+ if (pending.current) return;
80
+ const mine = view.current;
81
+ pending.current = true; setWorking(true); setError("");
82
+ let result;
83
+ try { result = await (more ? client.roomAgentRequests(scope, roomId, next) : client.cancelRoomAgentRequest(scope, roomId, id)); }
84
+ catch { result = null; }
85
+ if (!live.current || mine !== view.current) return;
86
+ pending.current = false; setWorking(false);
87
+ if (result?.ok) {
88
+ if (more) { setExtra(old => [...old, ...(Array.isArray(result.requests) ? result.requests : [])]); setNext(result.next ?? null); }
89
+ else onChanged?.();
90
+ } else setError(hrq("failed"));
91
+ };
92
+ return html`<div class="hub-room-owner-requests">
93
+ ${rows.length ? html`<ul class="hub-settings-invited">${rows.map(row => html`<li class="hub-settings-row" key=${row.id} data-owner-request=${row.id}>
94
+ <span>${hrq(row.state === "pending" ? "waiting" : row.state, row.owner.name)}</span>
95
+ ${row.state === "pending" ? html`<button type="button" class="btn btn-link" disabled=${busy || working} onClick=${() => { void act(row.id); }}>${hrq("cancelRequest")}</button>` : null}
96
+ </li>`)}</ul>` : null}
97
+ ${next ? html`<button type="button" class="btn btn-ghost" disabled=${busy || working} onClick=${() => { void act(null, true); }}>${hrq("more")}</button>` : null}
98
+ ${error ? html`<p class="note" role="alert">${error}</p>` : null}
99
+ </div>`;
100
+ }
101
+
102
+ const validOwnerRequest = row => row && row.kind === "owner-request" && typeof row.id === "string"
103
+ && typeof row.room?.name === "string" && typeof row.by?.name === "string";
104
+ const choiceReason = row => hrq(({ "not-shared": "notShared", paused: "paused", "already-in-room": "inRoom" })[row.reason] || "unavailable");
105
+ function myAgentsHint(text) {
106
+ const label = hrq("myAgents"), at = text.indexOf(label);
107
+ return at < 0 ? text : html`${text.slice(0, at)}<a href="/ui/hub/exposures">${label}</a>${text.slice(at + label.length)}`;
108
+ }
109
+
110
+ /** Feature-gated separately from legacy invitations, so cached readers keep their original API shape. */
111
+ export function OwnerAgentRequestsList({ client, heading = true } = {}) {
112
+ if (client.ownerRequestsLive?.() !== true) return null;
113
+ return html`<${OwnerRequestList} key=${client.roomAgentRequestScope?.()} client=${client} heading=${heading} />`;
114
+ }
115
+ function OwnerRequestList({ client, heading }) {
116
+ const [scope] = useState(() => client.roomAgentRequestScope());
117
+ const [page, setPage] = useState(null), [error, setError] = useState(false), [loading, setLoading] = useState(false);
118
+ const [busy, setBusy] = useState(false), [notice, setNotice] = useState("");
119
+ const live = useRef(true), generation = useRef(0), readingMore = useRef(false), writing = useRef(false);
120
+ const reload = async () => {
121
+ const mine = ++generation.current; readingMore.current = false; setLoading(false);
122
+ let result; try { result = await client.ownerAgentRequests(scope); } catch { result = null; }
123
+ if (!live.current || mine !== generation.current) return;
124
+ if (result?.ok && Array.isArray(result.requests)) { setPage({ requests: result.requests.filter(validOwnerRequest), next: result.next || null }); setError(false); }
125
+ else setError(true);
126
+ };
127
+ useEffect(() => {
128
+ live.current = true; void reload();
129
+ const off = client.subscribeRooms?.({ "invitation.changed": () => { void reload(); } }) ?? (() => {});
130
+ return () => { live.current = false; generation.current++; off(); };
131
+ }, [client, scope]);
132
+ const more = async () => {
133
+ if (readingMore.current || !page?.next) return;
134
+ const mine = generation.current; readingMore.current = true; setLoading(true); setError(false);
135
+ let result; try { result = await client.ownerAgentRequests(scope, page.next); } catch { result = null; }
136
+ if (!live.current || mine !== generation.current) return;
137
+ readingMore.current = false; setLoading(false);
138
+ if (result?.ok && Array.isArray(result.requests)) setPage(old => ({ requests: [...new Map([...old.requests, ...result.requests.filter(validOwnerRequest)].map(row => [row.id, row])).values()], next: result.next || null }));
139
+ else setError(true);
140
+ };
141
+ const answer = async (item, choice) => {
142
+ if (writing.current) return { ok: false, ignored: true };
143
+ writing.current = true; setBusy(true); setNotice("");
144
+ let result;
145
+ try { result = await (choice ? client.acceptOwnerAgentRequest(scope, item.id, { exposureId: choice.exposureId, revision: choice.revision })
146
+ : client.declineOwnerAgentRequest(scope, item.id)); } catch { result = null; }
147
+ if (!live.current) return result;
148
+ writing.current = false; setBusy(false);
149
+ if (result?.ok || result?.status === 404) {
150
+ generation.current++; readingMore.current = false; setLoading(false);
151
+ setPage(old => old ? { ...old, requests: old.requests.filter(row => row.id !== item.id) } : old);
152
+ setNotice(result?.ok ? hrq(choice ? "added" : "declinedNotice", item.room.name) : hrq("gone"));
153
+ void reload();
154
+ }
155
+ return result;
156
+ };
157
+ return html`<section class="hub-owner-agent-requests" aria-label=${hrq("requestsTitle")}>
158
+ ${page?.requests.length && heading ? html`<h3>${hrq("requestsTitle")}</h3>` : null}
159
+ ${page?.requests.map(item => html`<${OwnerRequestCard} key=${item.id} client=${client} scope=${scope} item=${item} busy=${busy} onAnswer=${answer} />`)}
160
+ ${page?.next ? html`<button class="btn btn-ghost" disabled=${loading || busy} onClick=${() => { void more(); }}>${hrq("more")}</button>` : null}
161
+ ${error ? html`<p class="note" role="alert">${hrq("loadFailed")} <button class="btn btn-link" onClick=${() => { void reload(); }}>${hrq("retry")}</button></p>` : null}
162
+ ${notice ? html`<p class="note" role="status">${notice}</p>` : null}
163
+ </section>`;
164
+ }
165
+ function OwnerRequestCard({ client, scope, item, busy, onAnswer }) {
166
+ const [view, setView] = useState(null), [selected, setSelected] = useState(null), [error, setError] = useState("");
167
+ const live = useRef(true), generation = useRef(0);
168
+ const load = async () => {
169
+ const mine = ++generation.current;
170
+ let result; try { result = await client.ownerAgentRequest(scope, item.id); } catch { result = null; }
171
+ if (!live.current || mine !== generation.current) return;
172
+ if (result?.ok && Array.isArray(result.choices)) {
173
+ const choices = result.choices.filter(row => row && typeof row.key === "string" && typeof row.name === "string")
174
+ .sort((a, b) => Number(b.canAdd === true) - Number(a.canAdd === true));
175
+ setView({ request: result.request, choices });
176
+ const available = choices.filter(row => row.canAdd === true && typeof row.exposureId === "string" && Number.isSafeInteger(row.revision));
177
+ setSelected(old => available.some(row => row.key === old) ? old : available.length === 1 ? available[0].key : null);
178
+ } else setError(hrq(result?.status === 404 ? "gone" : "loadFailed"));
179
+ };
180
+ useEffect(() => { live.current = true; void load(); return () => { live.current = false; generation.current++; }; }, [client, scope, item.id]);
181
+ const chosen = view?.choices.find(row => row.key === selected && row.canAdd === true);
182
+ const available = view?.choices.filter(row => row.canAdd === true) || [];
183
+ const act = async choice => {
184
+ setError(""); const result = await onAnswer(item, choice);
185
+ if (!live.current || result?.ignored || result?.ok || result?.status === 404) return;
186
+ setError(hrq("actionFailed")); if (result?.status === 409) void load();
187
+ };
188
+ const request = view?.request || item;
189
+ return html`<article class="hub-invitation" data-owner-request-card=${item.id}>
190
+ <p class="hub-owner-request-title">${hrq("requestLead", request.by?.name || "", request.room.name)}</p>
191
+ ${request.note ? html`<blockquote>${hrq("quotedNote", request.note)}</blockquote>` : null}
192
+ <p class="note">${hrq(request.room.people === 1 ? "requestBodyOne" : "requestBody", Number(request.room.people) || 0)}</p>
193
+ ${view && !available.length ? html`<p class="note">${myAgentsHint(hrq("noAgents"))}</p>` : null}
194
+ ${view ? html`<fieldset class="hub-owner-agent-choices" disabled=${busy}><legend>${hrq(available.length > 1 && !chosen ? "chooseAgent" : "which")}</legend>
195
+ ${view.choices.length ? view.choices.map(row => html`<label class="check" key=${row.key}>
196
+ <input type="radio" name=${"owner-request-" + item.id} value=${row.key} disabled=${!row.canAdd} checked=${selected === row.key} onChange=${() => setSelected(row.key)} />
197
+ <span><strong>${row.name}</strong>${row.kind === "classic-room" ? html` <small class="tag">${hrq("classic")}</small>` : null}
198
+ ${row.intro ? html`<small class="note">${row.intro}</small>` : null}
199
+ ${!row.canAdd ? html`<small class="note">${myAgentsHint(choiceReason(row))}</small>` : null}</span>
200
+ </label>`) : null}
201
+ </fieldset>` : null}
202
+ ${error ? html`<p class="note" role="alert">${error} <button class="btn btn-link" onClick=${() => { void load(); }}>${hrq("retry")}</button></p>` : null}
203
+ <div class="field-row">${available.length ? html`<button type="button" class="btn btn-primary" disabled=${busy || !chosen} onClick=${() => { void act(chosen); }}>${hrq("add")}</button>` : null}
204
+ <button type="button" class="btn" disabled=${busy} onClick=${() => { void act(null); }}>${hrq("decline")}</button></div>
205
+ </article>`;
206
+ }
207
+
208
+ export function OwnerAgentRequestSetting({ client, scope } = {}) {
209
+ if (typeof client?.agentRequestSettings !== "function" || !scope) return null;
210
+ return html`<${OwnerRequestSetting} key=${scope} client=${client} scope=${scope} />`;
211
+ }
212
+ function OwnerRequestSetting({ client, scope }) {
213
+ const [accepting, setAccepting] = useState(null), [busy, setBusy] = useState(false), [message, setMessage] = useState("");
214
+ const live = useRef(true), writing = useRef(false);
215
+ useEffect(() => {
216
+ live.current = true;
217
+ void client.agentRequestSettings(scope).then(result => { if (live.current) { if (result?.ok && typeof result.accepting === "boolean") setAccepting(result.accepting); else setMessage(hrq("loadFailed")); } }, () => { if (live.current) setMessage(hrq("loadFailed")); });
218
+ return () => { live.current = false; };
219
+ }, [client, scope]);
220
+ const change = async event => {
221
+ if (writing.current || typeof accepting !== "boolean") return;
222
+ const value = !event.target.checked; writing.current = true; setBusy(true); setMessage("");
223
+ let result; try { result = await client.agentRequestSettings(scope, { accepting: value }); } catch { result = null; }
224
+ if (!live.current) return;
225
+ writing.current = false; setBusy(false);
226
+ if (result?.ok) { setAccepting(result.accepting); setMessage(hrq("saved")); } else setMessage(hrq("actionFailed"));
227
+ };
228
+ return html`<section class="card hub-owner-request-setting"><label class="check">
229
+ <input type="checkbox" checked=${accepting === false} disabled=${busy || accepting === null} onChange=${change} />
230
+ <span>${hrq("stopRequests")}</span></label><p class="note">${hrq("stopHint")}</p>
231
+ ${message ? html`<p class="note" role="status">${message}</p>` : null}</section>`;
232
+ }
233
+
234
+ export function OwnerAgentDiscoverySetting({ client, scope, exposure } = {}) {
235
+ if (!scope || !exposure?.id || typeof client?.agentRoomDiscovery !== "function") return null;
236
+ return html`<${AgentDiscoverySetting} key=${scope + ":" + exposure.id + ":" + exposure.revision + ":" + (exposure.sharingEpoch || 0)} client=${client} scope=${scope} exposure=${exposure} />`;
237
+ }
238
+ function AgentDiscoverySetting({ client, scope, exposure }) {
239
+ const [view, setView] = useState(null), [busy, setBusy] = useState(false), [error, setError] = useState("");
240
+ const live = useRef(true), writing = useRef(false), generation = useRef(0);
241
+ const load = async () => {
242
+ if (writing.current) return;
243
+ const mine = ++generation.current;
244
+ let r; try { r = await client.agentRoomDiscovery(scope, exposure.id); } catch { r = null; }
245
+ if (!live.current || mine !== generation.current) return;
246
+ if (r?.ok && typeof r.findable === "boolean" && typeof r.available === "boolean") { setView(r); setError(""); }
247
+ else setError(hrq("loadFailed"));
248
+ };
249
+ useEffect(() => { live.current = true; writing.current = false; setBusy(false); setView(null); void load(); return () => { live.current = false; generation.current++; }; }, [client, scope, exposure.id]);
250
+ const change = async event => {
251
+ if (writing.current || !view?.available) return;
252
+ const findable = event.target.checked; writing.current = true; setBusy(true); setError("");
253
+ const mine = ++generation.current;
254
+ let r; try { r = await client.agentRoomDiscovery(scope, exposure.id, { findable, ifRevision: view.revision, exposureRevision: view.exposureRevision }); } catch { r = null; }
255
+ if (!live.current || mine !== generation.current) return;
256
+ writing.current = false; setBusy(false);
257
+ if (r?.ok) setView(r); else { setError(hrq("actionFailed")); if (r?.status === 403 || r?.status === 409) void load(); }
258
+ };
259
+ return html`<section class="card hub-room-discovery-setting"><label class="check"><input type="checkbox" checked=${view?.findable === true} disabled=${busy || !view?.available} onChange=${change} /><span>${hrq("discoveryLabel")}</span></label>
260
+ <p class="note">${hrq("discoveryHint")}</p>
261
+ ${view?.reason ? html`<p class="note">${hrq(view.reason === "owner-disabled" ? "discoveryOptOut" : view.reason === "paused" ? "discoveryPaused" : "discoveryUnshared")}</p>` : null}
262
+ ${error ? html`<p class="note" role="alert">${error} <button class="btn btn-link" onClick=${() => { void load(); }}>${hrq("retry")}</button></p>` : null}
263
+ </section>`;
264
+ }
@@ -0,0 +1,43 @@
1
+ // M-3340 (the user: personal pins): a Hub room's pinned messages — each person's own, kept on the Hub per person per room
2
+ // (GET/PUT/DELETE /hub/v1/rooms/<id>/pins; room-pins-v1), never shown to anyone else in the room. The Fleet chat's pin UX
3
+ // (#4095, chat-pins.js — its look, its words): Pin / Unpin in a message's menu, the header's 📌 with the count, and the
4
+ // list (newest first; a row shows its message in the room, flashed; × unpins it). At most 50 per room.
5
+ // A Hub module: imports only the shared /assets/ (never the Fleet's chat-pins.js); the room store (hub-room-thread.js)
6
+ // holds the list and answers pin/unpin.
7
+ import { html } from "/assets/app-html.js";
8
+ import { lang, t } from "/assets/app-i18n.js";
9
+ import { Dialog } from "/assets/ui-dialog.js";
10
+ import { Icon } from "/assets/ui-icons.js";
11
+ import { hroom } from "./hub-room-strings.js";
12
+
13
+ /** The Hub's limit per person per room (src/hub/rooms/service.ts ROOM_PINS_MAX). */
14
+ export const ROOM_PINS_MAX = 50;
15
+
16
+ const when = (ms) => { const d = new Date(ms); return Number.isFinite(d.getTime()) ? d.toLocaleString(lang(), { dateStyle: "medium", timeStyle: "short" }) : ""; };
17
+ const snippet = (s, n = 40) => { const one = String(s || "").replace(/\s+/g, " ").trim(); return one.length > n ? `${one.slice(0, n - 1)}…` : one; };
18
+ const textOf = (m) => String(m?.text || "");
19
+ const filesOf = (m) => (Array.isArray(m?.files) ? m.files.map((f) => f && f.name).filter(Boolean) : []);
20
+
21
+ /** The header's 📌 with the count: only when I have a pin in this room. */
22
+ export function RoomPinsButton({ count, onOpen }) {
23
+ if (!count) return null;
24
+ const label = t("chat.pinsButton", String(count));
25
+ return html`<button type="button" class="btn btn-ghost btn-sm chat-pins-btn hub-room-pins-btn" title=${label} aria-label=${label} onClick=${() => onOpen?.()}>
26
+ <${Icon} name="pin" size=${16} /><span class="chat-pins-count" aria-hidden="true">${count}</span></button>`;
27
+ }
28
+
29
+ /** The list: newest pin first; a row shows its message (`onJump(pin)`), its × unpins it (`onUnpin(pin)`). Only mine. */
30
+ export function RoomPinsDialog({ pins, onClose, onJump, onUnpin }) {
31
+ return html`<${Dialog} title=${`${t("chat.pinsTitle")} · ${pins.length}`} onClose=${onClose} cls="chat-pins-dlg hub-room-pins-dlg">
32
+ <p class="note hub-room-pins-only">${hroom("pinsOnlyYou")}</p>
33
+ ${pins.length ? html`<ul class="chat-pins">${pins.map((p) => html`<li key=${p.messageId} class="chat-pin" data-message=${p.messageId}>
34
+ <button type="button" class="chat-pin-go" title=${t("chat.pinShow")} onClick=${() => onJump?.(p)}>
35
+ <span class="chat-pin-meta"><strong>${String(p.message?.author?.name || "")}</strong><time datetime=${new Date(p.message?.at || 0).toISOString()}>${when(p.message?.at)}</time></span>
36
+ <span class="chat-pin-text">${textOf(p.message)}</span>
37
+ ${filesOf(p.message).length ? html`<span class="chat-pin-files">${t("chat.pinFiles", filesOf(p.message).join(", "))}</span>` : null}
38
+ </button>
39
+ <button type="button" class="icon-btn chat-pin-x" title=${t("chat.unpin")} aria-label=${t("chat.pinUnpin", snippet(textOf(p.message)))}
40
+ onClick=${() => onUnpin?.(p)}><${Icon} name="close" size=${14} /></button>
41
+ </li>`)}</ul>` : html`<p class="note">${t("chat.pinsEmpty")}</p>`}
42
+ </${Dialog}>`;
43
+ }
@@ -17,6 +17,8 @@ import { hroom } from "./hub-room-strings.js";
17
17
  import { hs } from "./hub-room-settings-strings.js";
18
18
  import {ha} from "./hub-ai-apps-strings.js";
19
19
  import { RoomPicker } from "./hub-room-new.js";
20
+ import { OwnerAgentRequestDialog, OwnerAgentRequestRows } from "./hub-room-owner-requests.js";
21
+ import { hrq } from "./hub-room-owner-requests-strings.js";
20
22
  import { hn, linkRoomsU2Css } from "./hub-room-new-strings.js";
21
23
 
22
24
  linkRoomsU2Css();
@@ -42,6 +44,8 @@ export function invitedLabel(row) {
42
44
  export function RoomSettings({ client = hubClient(), roomId, detail, onClose, onChanged, assistant } = {}) {
43
45
  const room = detail?.room ?? {}, settings = detail?.settings ?? {}, members = Array.isArray(detail?.members) ? detail.members : [];
44
46
  const invited = Array.isArray(detail?.invited) ? detail.invited : [];
47
+ const [askOwner, setAskOwner] = useState(false);
48
+ const ownerRequestsLive = settings.ownerAgentRequests === true && typeof client.requestRoomAgent === "function";
45
49
  const [purpose,setPurpose]=useState(room.purpose??"");
46
50
  useEffect(()=>setPurpose(room.purpose??""),[roomId,room.purpose]);
47
51
  const purposeSupported=client.roomPurposeV1===true&&typeof room.purpose==="string"&&detail?.me?.role==="manager";
@@ -138,12 +142,17 @@ export function RoomSettings({ client = hubClient(), roomId, detail, onClose, on
138
142
  ? html`<button type="button" class="btn btn-link" disabled=${busy} onClick=${() => { void act(async () => { const r = await client.inviteToRoom(roomId, { agents: [row.exposureId] }); if (r?.ok) await client.cancelRoomInvitation(roomId, row.id); return r; }); }}>${hs("inviteAgain")}</button>`
139
143
  : html`<button type="button" class="btn btn-link" disabled=${busy} onClick=${() => { void act(() => client.cancelRoomInvitation(roomId, row.id)); }}>${hroom("cancelInvite")}</button>`}</li>`)}</ul>` : null}
140
144
  <${RoomPicker} client=${client} id="hubRoomAddAgents" kinds=${["agent", "team"]} label=${hroom("addOrInviteAgents")} placeholder=${hroom("addAgents")}
141
- picked=${addAgents} exclude=${taken} onChange=${(next) => { void add(next, setAddAgents); }} />
145
+ picked=${addAgents} exclude=${taken} onChange=${(next) => { void add(next, setAddAgents); }}
146
+ searchHelp=${ownerRequestsLive ? html`<p class="note hub-owner-request-entry">${hrq("missing")}
147
+ <button type="button" class="btn btn-link" disabled=${busy} onClick=${() => setAskOwner(true)}>${hrq("ask")}</button></p>` : null} />
148
+ ${ownerRequestsLive ? html`<${OwnerAgentRequestRows} client=${client} roomId=${roomId} page=${detail.agentRequests} onChanged=${onChanged} busy=${busy} />` : null}
142
149
  ${offered || hasAssistant ? html`<label class="check"><input id="hubRoomSettingsAssistant" class="s-ui-toggle" type="checkbox" role="switch" checked=${hasAssistant} disabled=${busy}
143
150
  onChange=${(e) => { const v = e.target.checked, id = members.find(m => m.kind === "assistant")?.id; void act(() => v ? client.addRoomMember(roomId, { kind: "assistant" }) : client.removeRoomMember(roomId, id)); }} /><span>${hs("assistantSwitch")}</span></label>` : null}
144
151
  </section>
145
152
  <section class="form"><h4>${hroom("other")}</h4>
146
153
  <button type="button" class="btn btn-danger" disabled=${busy || room.archived === true} onClick=${() => { void archive(); }}>${hroom("archiveRoom")}</button>
147
154
  </section>
148
- </${Dialog}>`;
155
+ </${Dialog}>
156
+ ${askOwner && ownerRequestsLive ? html`<${OwnerAgentRequestDialog} key=${roomId} client=${client} roomId=${roomId} roomName=${room.name}
157
+ onClose=${() => setAskOwner(false)} onSent=${() => onChanged?.()} />` : null}`;
149
158
  }
@@ -27,6 +27,8 @@ register("hubRoom", {
27
27
  // M-3127 reactions: who reacted ("Alex, Bob and 3 others reacted with 👍"), the add button, the picker
28
28
  reactAdd: "Add reaction", reactPick: "Reactions", reactedWith: "{0} reacted with {1}", reactMore: "{0} and {1} others",
29
29
  reactYou: "You", listSep: ", ", reactFailed: "Couldn't add the reaction. Try again.",
30
+ // M-3340: personal pins (the Fleet chat's words for the rest: chat.pin…)
31
+ pinsOnlyYou: "Only you see your pins.", pinsFull: "You already have {0} pinned messages in this room — unpin one first.",
30
32
  // M-3127 B: an agent's buttons (its asker's) and polls (everyone's)
31
33
  onlyAsker: "Only {0} can answer", sysPollClosed: "{0}'s poll closed", buttonFailed: "That didn't go through. Try again.",
32
34
  buttonNotAsker: "Only the person who asked can answer these buttons.", buttonExpired: "These buttons are no longer open.",
@@ -163,6 +165,7 @@ register("hubRoom", {
163
165
  allAnswered: "{0} 個都回答了", expandRest: "展開其餘 {0} 則",
164
166
  reactAdd: "加上表情", reactPick: "表情回應", reactedWith: "{0} 回應了 {1}", reactMore: "{0} 和其他 {1} 人",
165
167
  reactYou: "你", listSep: "、", reactFailed: "表情沒加上,請再試一次。",
168
+ pinsOnlyYou: "只有你看得到你的釘選。", pinsFull: "你在這個房間已有 {0} 則釘選訊息——請先取消一則。",
166
169
  onlyAsker: "只有 {0} 能回答", sysPollClosed: "{0} 的投票已結束", buttonFailed: "沒有送出,請再試一次。",
167
170
  buttonNotAsker: "只有提問的人能按這些按鈕。", buttonExpired: "這些按鈕已經關閉。",
168
171
  searchLabel: "搜尋", searchPlaceholder: "搜尋房間、聊天與訊息…", searchClose: "關閉",
@@ -36,6 +36,7 @@ import { roomSource, mountSourceAuthor } from "./hub-room-source.js";
36
36
  import { countsLine } from "./hub-room-list.js";
37
37
  import { DropOverlay, MAX_FILES, PendingFiles, hf, hubFileAttachment, pageCarriesFiles, putBackText, roomTakesFiles, uploadChosen, useFileDrop } from "./hub-attachments.js";
38
38
  import { LightboxHost, openLightbox } from "/assets/image-lightbox.js";
39
+ import { ROOM_PINS_MAX, RoomPinsButton, RoomPinsDialog } from "./hub-room-pins.js";
39
40
  // M-3125 PR3: the one quote target an annotated room picture has (here, so a page with an older dictionary has the words).
40
41
  register("hubRoomAnnotate", { en: { quote: "Quote in this room" }, "zh-TW": { quote: "引用到這個房間" } });
41
42
 
@@ -220,9 +221,10 @@ export function toThreadMessages(messages, { meId, ids, direct = false, expanded
220
221
  * `send(text, { mentions, replyTo })` → the client's answer (a refusal's code is the caller's to word; a soft warning is
221
222
  * 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.
222
223
  */
223
- export function createRoomStore(roomId, { client, meId = "" } = {}) {
224
+ export function createRoomStore(roomId, { client, meId = "", pinsOn = false } = {}) {
224
225
  const subs = new Set(), ids = new Map(), expanded = new Set();
225
- const st = { live: true, detail: null, messages: [], loaded: false, error: null, removed: false, more: false, view: [] };
226
+ // M-3340: `pins` — my own pins in this group room (null: this Hub offers none, or not read yet); nobody else's, ever.
227
+ const st = { live: true, detail: null, messages: [], loaded: false, error: null, removed: false, more: false, view: [], pins: null };
226
228
  let loadingOlder = false;
227
229
  // The room's committed order (Ridge: `sequence`, from the stored row): a waiting answer replaced in place, or an event that
228
230
  // arrives out of order, is drawn where the room has it. Rows without it (a direct chat, an older Hub) keep arrival order.
@@ -245,6 +247,14 @@ export function createRoomStore(roomId, { client, meId = "" } = {}) {
245
247
  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; }
246
248
  else st.error = page.code || "failed";
247
249
  changed();
250
+ void readPins();
251
+ }
252
+ /** M-3340: my pins, read again (opening the room; my other tab or device changed them: pins.changed). A group room only. */
253
+ async function readPins() {
254
+ if (!pinsOn || typeof client.roomPins !== "function" || st.detail?.room?.kind !== "group") return;
255
+ const r = await client.roomPins(roomId);
256
+ if (!st.live) return;
257
+ if (r?.ok && Array.isArray(r.pins)) { st.pins = r.pins.filter((p) => p && typeof p.messageId === "string"); changed(); }
248
258
  }
249
259
  const on = (fn) => (data) => { if (st.live && data && data.roomId === roomId) { fn(data); changed(); } };
250
260
  // 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),
@@ -260,6 +270,7 @@ export function createRoomStore(roomId, { client, meId = "" } = {}) {
260
270
  "presence.changed": on((d) => { const m = st.detail?.members?.find((x) => x.id === d.memberId); if (m) { m.presence = d.presence;
261
271
  for (const k of ["presenceNote", "presenceReason"]) { if (d[k]) m[k] = d[k]; else delete m[k]; } } }),
262
272
  "member.changed": on(() => { void readDetail().then(changed); }),
273
+ "pins.changed": on(() => { void readPins(); }),
263
274
  "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 } }; }),
264
275
  }) : () => {};
265
276
  /** One page older than what is held (the server's `before=`). False when there was nothing to fetch. */
@@ -349,6 +360,17 @@ export function createRoomStore(roomId, { client, meId = "" } = {}) {
349
360
  if (st.live && r?.ok && m && Array.isArray(r.reactions)) { if (r.reactions.length) m.reactions = r.reactions; else delete m.reactions; changed(); }
350
361
  return r;
351
362
  },
363
+ /** M-3340: my pins (newest first: { messageId, pinnedAt, message }); offered when this Hub keeps them for me. */
364
+ pins: () => st.pins || [],
365
+ pinsOffered: () => Array.isArray(st.pins),
366
+ isPinned: (messageId) => (st.pins || []).some((p) => p.messageId === messageId),
367
+ /** Pin (on) or unpin a message for me only; the Hub answers with my pins → the client's answer (pins-full past 50). */
368
+ async setPin(messageId, on) {
369
+ if (!Array.isArray(st.pins) || typeof client.pinRoomMessage !== "function") return { ok: false, code: "unavailable" };
370
+ const r = await client.pinRoomMessage(roomId, messageId, on);
371
+ if (st.live && r?.ok && Array.isArray(r.pins)) { st.pins = r.pins.filter((p) => p && typeof p.messageId === "string"); changed(); }
372
+ return r;
373
+ },
352
374
  markRead() { const last = st.messages.at(-1); return last ? client.markRoomRead(roomId, last.id) : Promise.resolve({ ok: true }); },
353
375
  refresh, clickButton: actions.clickButton, vote: actions.vote, busy: actions.busy, mine: actions.mine,
354
376
  stop() { st.live = false; subs.clear(); unsubscribe(); actions.stop(); },
@@ -378,8 +400,9 @@ function useMembersPanel() {
378
400
  * Fleet chat's thread (panel-hub.js's HubThread, given as `Thread`: the thread wiring is one), the room's composer, and
379
401
  * the members panel on the right. `client`: the Hub client; `me`: { id } from the session.
380
402
  */
381
- export function HubRoomPage({ roomId, listed = null, Thread, client, meId = "", rooms = [], openRoom = () => {}, goList = () => {}, onLeft = () => {}, onMe = () => {} }) {
382
- const store = useMemo(() => createRoomStore(roomId, { client, meId }), [roomId]);
403
+ export function HubRoomPage({ roomId, listed = null, Thread, client, meId = "", rooms = [], openRoom = () => {}, goList = () => {}, onLeft = () => {}, onMe = () => {}, pinsOn = false }) {
404
+ const store = useMemo(() => createRoomStore(roomId, { client, meId, pinsOn }), [roomId]);
405
+ const [pinsOpen, setPinsOpen] = useState(false);
383
406
  useEffect(() => () => store.stop(), [store]);
384
407
  const [, tick] = useState(0);
385
408
  // The first read may land before this subscribes: read once more on subscribing.
@@ -506,13 +529,31 @@ export function HubRoomPage({ roomId, listed = null, Thread, client, meId = "",
506
529
  quote: { field: () => input.current, can: () => !store.closed() },
507
530
  // M-3311 (3): the Fleet chat's Copy link — a room message's address (opening it shows that message).
508
531
  linkOf: roomLinkOf(roomId),
532
+ // M-3340: the Fleet chat's Pin / Unpin — mine only (read when the menu opens: the pins arrive after the first render).
533
+ pin: (x) => { void togglePin(x.roomMessage); },
534
+ pinned: (x) => store.isPinned(x.roomMessage),
535
+ canPin: (x) => store.pinsOffered() && !!x.roomMessage && x.role !== "status",
509
536
  };
537
+ // M-3340: pin or unpin a message for me; said in a toast either way (as the Fleet chat says it).
538
+ async function togglePin(messageId) {
539
+ const on = !store.isPinned(messageId), r = await store.setPin(messageId, on);
540
+ if (r?.ok) toast(t(on ? "chat.pinned" : "chat.unpinned"));
541
+ else toast(r?.code === "pins-full" ? hroom("pinsFull", String(ROOM_PINS_MAX)) : t("chat.pinFailed"), false);
542
+ }
543
+ const pinCount = store.pinsOffered() ? store.pins().length : 0;
544
+ // M-3340: a pin's message in the room — loaded back to it, scrolled to and flashed (the search hit's way); gone: said.
545
+ async function showPin(pin) {
546
+ setPinsOpen(false);
547
+ const key = await store.find(pin.messageId);
548
+ if (key) setTimeout(() => threadRef.current?.reveal(key), 60); else toast(hroom("jumpMissing"), false);
549
+ }
510
550
  // M-3311 (3): the header's menu — a group room's Room settings and Leave, and on a desk the Fleet chat's 「全寬」 for any room.
511
551
  const [fullWidth, setFullWidth] = useState(hubChatWide);
512
552
  const textSize = useStore(textSizeStore), notify = useStore(notifyStore), narrow = useNarrowScreen();
513
553
  const menuItems = [
514
554
  group && detail?.me?.role === "manager" ? { key: "settings", label: hroom("roomSettings"), icon: "settings", onSelect: openSettings } : null,
515
555
  group && detail?.me ? { key: "leave", label: hroom("leaveRoom"), icon: "close", onSelect: () => { void leave(); } } : null,
556
+ pinCount ? { key: "pins", label: `${t("chat.pinsTitle")} · ${pinCount}`, icon: "pin", onSelect: () => setPinsOpen(true) } : null,
516
557
  !narrow && detail?.me ? { key: "fullWidth", checkbox: true, checked: fullWidth, label: t("chat.fullWidth"), onSelect: () => { setHubChatWide(!fullWidth); setFullWidth(!fullWidth); } } : null,
517
558
  // M-3311 (4): a phone's header is one row (back, the room, members, ⋯) as the Fleet chat's — its text size and Notify
518
559
  // move into ⋯ there (hub-chat.css hides the two buttons at the same width).
@@ -533,6 +574,7 @@ export function HubRoomPage({ roomId, listed = null, Thread, client, meId = "",
533
574
  onSettings=${() => { setSheet(false); openSettings(); }} />` : null;
534
575
  return html`<div class=${`hub-chat hub-room-page${showRail ? " with-rail" : ""}`} data-room=${roomId} data-width=${fullWidth ? "full" : undefined}>
535
576
  <${LightboxHost} />
577
+ ${pinsOpen ? html`<${RoomPinsDialog} pins=${store.pins()} onClose=${() => setPinsOpen(false)} onJump=${(p) => void showPin(p)} onUnpin=${(p) => void togglePin(p.messageId)} />` : null}
536
578
  <section class="hub-chat-main" ref=${mainRef}>
537
579
  ${attach ? html`<${DropOverlay} />` : null}
538
580
  <header class=${`hub-chat-head${room.agent?.answerOnly?" hub-answer-only-head":""}`} data-trust="panel-content">
@@ -541,7 +583,7 @@ export function HubRoomPage({ roomId, listed = null, Thread, client, meId = "",
541
583
  onClick=${(e) => { if (e.metaKey || e.ctrlKey) return; e.preventDefault(); goList(); }}><${Icon} name="back" /></a>
542
584
  <span class=${`av${group ? " av-square" : ""}`} aria-hidden="true"><span class="av-text">${firstCharacter(title || "?") || "?"}</span></span>
543
585
  <span class="hub-chat-title"><strong>${title}</strong>${group&&typeof room.purpose==="string"?html`<${RoomPurposeHeader} purpose=${room.purpose} onEdit=${detail?.me?.role==="manager"&&client.roomPurposeV1===true?openSettings:undefined} />`:null}<span class=${`s${room.agent?.answerOnly?" hub-answer-only-note":""}`}>${line2}</span>${room.assistant||room.agent?.intro?html`<span class="s hub-agent-intro-line">${room.assistant?hi("assistant"):room.agent.intro}</span>`:null}</span>
544
- <span class="hub-head-tools"><${TextSizeButton} /><${HubNotifyToggle} /></span>
586
+ <span class="hub-head-tools"><${RoomPinsButton} count=${pinCount} onOpen=${() => setPinsOpen(true)} /><${TextSizeButton} /><${HubNotifyToggle} /></span>
545
587
  ${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")}
546
588
  onClick=${() => (wide ? setRail(!rail) : setSheet(true))}><${Icon} name="team" size=${18} /></button>` : null}
547
589
  ${menuItems.length ? html`<${Menu} cls="hub-room-menu" label=${hroom("menu")} fit=${true} ownerKey=${roomId} items=${menuItems} />` : null}