@alexsun-top/opencode-chat-room 0.6.7 → 0.6.9

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 (62) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +6 -3
  3. package/README.zh-CN.md +7 -3
  4. package/docs/administrator-rooms.md +7 -2
  5. package/package.json +4 -1
  6. package/plugin.ts +38 -8
  7. package/server/assets/base.css +222 -28
  8. package/server/assets/chat/admin-badge.js +28 -6
  9. package/server/assets/chat/admin.js +7 -1
  10. package/server/assets/chat/announcements.js +1 -1
  11. package/server/assets/chat/attachment-store.js +106 -0
  12. package/server/assets/chat/attachments.js +201 -21
  13. package/server/assets/chat/confirm-dialog.js +28 -0
  14. package/server/assets/chat/events.js +37 -9
  15. package/server/assets/chat/image-zoom.js +86 -2
  16. package/server/assets/chat/index.js +10 -0
  17. package/server/assets/chat/install-prompt.js +82 -0
  18. package/server/assets/chat/join-requests.js +355 -0
  19. package/server/assets/chat/markdown.js +55 -7
  20. package/server/assets/chat/members.js +5 -3
  21. package/server/assets/chat/message-polling.js +24 -3
  22. package/server/assets/chat/messages.js +6 -4
  23. package/server/assets/chat/questions.js +10 -6
  24. package/server/assets/chat/recall.js +267 -0
  25. package/server/assets/chat/reminders.js +53 -9
  26. package/server/assets/chat/replies.js +1 -1
  27. package/server/assets/chat/room-list.js +14 -5
  28. package/server/assets/chat/room-watcher.js +5 -1
  29. package/server/assets/chat/rooms.js +17 -5
  30. package/server/assets/chat/shortcuts.js +40 -0
  31. package/server/assets/chat/state.js +69 -16
  32. package/server/assets/chat/system-messages.js +4 -0
  33. package/server/assets/conversation.css +2 -2
  34. package/server/assets/recall.css +29 -0
  35. package/server/assets/responsive.css +41 -13
  36. package/server/chat-server.ts +55 -66
  37. package/server/chat.html +139 -16
  38. package/server/inbox.ts +1 -1
  39. package/server/join-requests.ts +106 -0
  40. package/server/message-recall-routes.ts +37 -0
  41. package/server/newrooms.ts +9 -0
  42. package/server/room-join.ts +59 -0
  43. package/server/room-owner.ts +3 -20
  44. package/server/room-payload.ts +2 -0
  45. package/server/sw.js +1 -0
  46. package/server/wake.ts +45 -16
  47. package/skills/chatroom/SKILL.md +32 -0
  48. package/src/README.md +5 -3
  49. package/src/agent/admin-client.ts +28 -4
  50. package/src/center/center-client.ts +81 -4
  51. package/src/center/center-inbox.ts +35 -10
  52. package/src/center/center-wake.ts +25 -12
  53. package/src/center/message-ids.ts +7 -0
  54. package/src/center/notification-budget.ts +16 -0
  55. package/src/center/queue.ts +14 -4
  56. package/src/rooms/room-service.ts +10 -1
  57. package/src/runtime/plugin-notifications.ts +37 -11
  58. package/src/runtime/v2-plugin.ts +1 -1
  59. package/src/state/roles.ts +34 -0
  60. package/src/state/sqlite-state.ts +197 -27
  61. package/src/state/store.ts +22 -3
  62. package/src/tests/announcement-board.ts +12 -2
@@ -9,7 +9,8 @@ import RoomService, {
9
9
  type Message,
10
10
  type Room,
11
11
  } from "../src/rooms/room-service.ts";
12
- import { acknowledgeQueued, answerQuestion, appendRoomMessage, sendReply, readQuestions, readState, writeState, type Registry, type RegistryEntry } from "../src/state/store.ts";
12
+ import { acknowledgeQueued, answerQuestion, appendRoomMessage, databasePath, sendReply, readQuestions, readState, writeState, type Registry, type RegistryEntry } from "../src/state/store.ts";
13
+ import { saveJoinRequest, writeSqliteStateWithDatabase } from "../src/state/sqlite-state.ts";
13
14
  import {
14
15
  admissionMatches,
15
16
  clearPendingAdmission,
@@ -18,14 +19,17 @@ import { readInbox } from "./inbox";
18
19
  import { isReceiverOwnerID } from "../src/state/receiver-owner.ts";
19
20
  import { claimWake, touchActive, wakeMentionedSessions } from "./wake";
20
21
  import { historyRoute } from "./history-route";
22
+ import { messageRecallRoutes } from "./message-recall-routes";
21
23
  import { roomPayload } from "./room-payload";
22
- import { bindOwner, isUser, settleAdmins, settleOwner } from "./room-owner";
24
+ import { isUser, settleAdmins, settleOwner } from "./room-owner";
23
25
  import { jsonObject } from "./json-body";
24
26
  import { roomManagement } from "./newrooms";
25
27
  import { memberRoutes } from "./member-routes";
26
28
  import { resourceRoutes } from "./resource-routes";
27
29
  import { maxResourceBytes } from "../src/rooms/resources.ts";
28
30
  import { adminRoutes } from "./admin-routes";
31
+ import { joinRequestRoutes } from "./join-requests";
32
+ import { joinRoomMember } from "./room-join";
29
33
  import { roomReminderRoutes, startRoomReminderScheduler } from "./room-reminders";
30
34
 
31
35
  // The chat page shows this next to the app title; a missing package must not
@@ -148,6 +152,8 @@ async function handle(req: Request): Promise<Response> {
148
152
  if (resource) return resource;
149
153
  const history = await historyRoute(url);
150
154
  if (history) return history;
155
+ const recall = await messageRecallRoutes(req, url);
156
+ if (recall) return recall;
151
157
  if (req.method === "GET" && p === "/rooms/summary") {
152
158
  // ponytail: 轻量房间摘要(不含消息)——wakeSessions 每 10s 用它计算
153
159
  // latest,避免下载全部房间历史(orc-1 #5)
@@ -184,6 +190,8 @@ async function handle(req: Request): Promise<Response> {
184
190
  }
185
191
  const members = await memberRoutes(req, url);
186
192
  if (members) return members;
193
+ const joinRequests = await joinRequestRoutes(req, url);
194
+ if (joinRequests) return joinRequests;
187
195
  const management = await roomManagement(req, url);
188
196
  if (management) return management;
189
197
  if (req.method === "POST" && p === "/rooms") {
@@ -203,8 +211,12 @@ async function handle(req: Request): Promise<Response> {
203
211
  if (owner.length > 64) {
204
212
  return json({ error: "ownerId too long (max 64)" }, 400);
205
213
  }
214
+ if (body.joinPolicy !== undefined && body.joinPolicy !== "open" && body.joinPolicy !== "approval") {
215
+ return json({ error: "joinPolicy must be open or approval" }, 400);
216
+ }
217
+ const joinPolicy = body.joinPolicy === "approval" ? "approval" : body.joinPolicy === "open" ? "open" : undefined;
206
218
  const room = await mutate((svc, reg) => {
207
- const created = svc.createRoom(name, owner);
219
+ const created = svc.createRoom(name, owner, joinPolicy);
208
220
  if (body.sessionID) {
209
221
  const regRoom = (reg[created.id] =
210
222
  reg[created.id] ?? Object.create(null) as Record<string, RegistryEntry>);
@@ -236,6 +248,12 @@ async function handle(req: Request): Promise<Response> {
236
248
  const roomFilter = url.searchParams.get("roomId");
237
249
  const afterValue = url.searchParams.get("afterTs");
238
250
  const afterTs = afterValue === null ? undefined : Number(afterValue);
251
+ const recallVersionValue = url.searchParams.get("recallVersion");
252
+ if (url.searchParams.has("recallVersion") && (recallVersionValue === "" || !/^\d+$/.test(recallVersionValue ?? "") ||
253
+ !Number.isSafeInteger(Number(recallVersionValue)))) {
254
+ return json({ error: "recallVersion must be a non-negative safe integer" }, 400);
255
+ }
256
+ const clientRecallVersion = recallVersionValue === null ? undefined : Number(recallVersionValue);
239
257
  if (url.searchParams.has("afterTs") && (afterValue === "" || !/^\d+$/.test(afterValue ?? "") ||
240
258
  !Number.isSafeInteger(afterTs) || afterTs! < 0 || !roomFilter || url.searchParams.get("excludeSelf") !== "0")) {
241
259
  return json({ error: "afterTs requires a roomId and excludeSelf=0, with a non-negative safe integer value" }, 400);
@@ -252,7 +270,12 @@ async function handle(req: Request): Promise<Response> {
252
270
  );
253
271
  const deadline = Date.now() + timeout;
254
272
  let result = await readInbox(sessionID, roomFilter, excludeSelf, afterTs);
255
- while (result.items.length === 0 && Date.now() < deadline) {
273
+ // The client's rendered snapshot version is the baseline; using the first
274
+ // read instead would hide a recall that landed before this request started.
275
+ const initialRecallVersion = clientRecallVersion ?? result.recallVersion;
276
+ // A recall bumps the version without creating a message; wake the poll so
277
+ // the client can refetch the room snapshot (reliable version compare).
278
+ while (result.items.length === 0 && result.recallVersion === initialRecallVersion && Date.now() < deadline) {
256
279
  // ponytail: 2s between disk scans (orc-1 #7) — 1s × 25 iterations
257
280
  // doubles the file reads on shared-mount deployments
258
281
  await sleep(Math.max(1, Math.min(2000, deadline - Date.now())));
@@ -324,71 +347,37 @@ async function handle(req: Request): Promise<Response> {
324
347
  if (id.length > 64 || name.length > 64) {
325
348
  return json({ error: "name too long (max 64)" }, 400);
326
349
  }
327
- const room = await mutate((svc, reg) => {
350
+ const result = await writeSqliteStateWithDatabase(databasePath(), (svc, reg, db) => {
328
351
  const currentRoom = svc.getRoom(roomId);
329
- const participantId = currentRoom.kind === "direct" ? sessionID : id;
330
- const regRoom = (reg[roomId] =
331
- reg[roomId] ?? Object.create(null) as Record<string, RegistryEntry>);
332
- // retire the participant this session previously held, if renamed
333
- // — skipped when another session still uses the old name
334
- const prevEntry = regRoom[sessionID];
335
- if (currentRoom.kind !== "direct" && prevEntry && prevEntry.name !== name) {
336
- const shared = Object.entries(regRoom).some(
337
- ([sid, e]) => sid !== sessionID && e.name === prevEntry.name,
338
- );
339
- if (!shared && svc.containsParticipant(roomId, prevEntry.name)) {
340
- svc.leaveRoom(roomId, prevEntry.name);
341
- }
352
+ // A restricted room treats a new identity as a pending request; no
353
+ // participant or registry entry exists until a reviewer approves.
354
+ if (currentRoom.joinPolicy === "approval" && currentRoom.kind !== "direct" && !reg[roomId]?.[sessionID]) {
355
+ if (svc.containsParticipant(roomId, id)) return { status: 409 as const, error: "participant name is already in use in this room" };
356
+ const duplicate = db.query("SELECT 1 FROM room_join_requests WHERE room_id=? AND session_id<>? AND (participant_id=? OR name=?)").get(roomId, sessionID, id, name);
357
+ if (duplicate) return { status: 409 as const, error: "participant name is already in use in this room" };
358
+ saveJoinRequest(db, {
359
+ roomID: roomId, sessionID, participantId: id, name,
360
+ isAgent: Boolean(body.protocol || body.receiverOwnerID || body.host),
361
+ createdAt: Date.now(),
362
+ ...(body.protocol === "v2" ? { protocol: "v2" as const } : {}),
363
+ ...(body.protocol === "v2" && isReceiverOwnerID(body.receiverOwnerID) ? { receiverOwnerID: body.receiverOwnerID } : {}),
364
+ ...(body.directory ? { directory: body.directory } : {}),
365
+ ...(body.host ? { host: body.host } : {}),
366
+ });
367
+ return { pending: true as const };
342
368
  }
343
- const already = svc.containsParticipant(roomId, participantId);
344
- // ponytail: prune a stale registry entry for the same participant
345
- // name from another session (closed tab / cleared localStorage) —
346
- // but only when the identity is NOT already present, otherwise two
347
- // live sessions sharing a nickname would evict each other forever
348
- if (!already && currentRoom.kind !== "direct") {
349
- for (const [sid, e] of Object.entries(regRoom)) {
350
- if (sid !== sessionID && e.name === name) {
351
- delete regRoom[sid];
352
- }
353
- }
354
- }
355
- svc.joinRoom(roomId, { id: participantId, name });
356
- if (!already) {
357
- svc.addEvent(roomId, `${name} joined the room`);
358
- }
359
-
360
- const latestMessageTs =
361
- svc.getMessages(roomId).at(-1)?.createdAt ?? 0;
362
- regRoom[sessionID] = {
363
- // ponytail: central mode self-pulls the inbox; no cross-host URL.
364
- // Re-join must not rewind the read watermark (unread messages
365
- // would be silently dropped); a first join starts at join time.
366
- serverUrl: "",
367
- apiPrefix: "/api",
369
+ return { room: joinRoomMember(svc, reg, roomId, {
370
+ sessionID, participantId: id, name,
368
371
  ...(body.protocol === "v2" ? { protocol: "v2" as const } : {}),
369
372
  ...(body.protocol === "v2" && isReceiverOwnerID(body.receiverOwnerID) ? { receiverOwnerID: body.receiverOwnerID } : {}),
370
- name,
371
- membershipID: prevEntry?.membershipID ?? randomUUID(),
372
- directory: body.directory || undefined,
373
- // ora-1 #2: 归属主机——跨机 @-wake 只由所属机器执行
373
+ ...(body.directory ? { directory: body.directory } : {}),
374
374
  host: body.host ?? "",
375
- lastQueuedTs: regRoom[sessionID]?.lastQueuedTs,
376
- lastReadTs:
377
- regRoom[sessionID]?.lastReadTs ??
378
- Math.max(Date.now(), latestMessageTs),
379
- };
380
- // An ownerless room is claimed by the first person who arrives; agents never are.
381
- const joinedRoom = svc.getRoom(roomId);
382
- if (!joinedRoom.ownerId && isUser(regRoom[sessionID])) {
383
- joinedRoom.ownerId = name;
384
- joinedRoom.ownerMembershipID = regRoom[sessionID]!.membershipID;
385
- } else {
386
- bindOwner(joinedRoom, regRoom);
387
- }
388
- return svc.getRoom(roomId);
375
+ }) };
389
376
  });
377
+ if ("status" in result) return json({ error: result.error }, result.status);
378
+ if ("pending" in result) return json({ status: "pending" }, 202);
390
379
  touchActive(sessionID); // join = active
391
- return json(await roomPayload(room), 201);
380
+ return json(await roomPayload(result.room), 201);
392
381
  }
393
382
  if (req.method === "POST" && m[2] === "leave") {
394
383
  await mutate((svc, reg) => {
@@ -437,8 +426,8 @@ async function handle(req: Request): Promise<Response> {
437
426
  if (!text) {
438
427
  return json({ error: "text is required" }, 400);
439
428
  }
440
- if (text.length > 2000) {
441
- return json({ error: "text too long (max 2000)" }, 400);
429
+ if (text.length > 5000) {
430
+ return json({ error: "text too long (max 5000)" }, 400);
442
431
  }
443
432
  const replyTo = (body as Record<string, unknown>).replyToMessageID;
444
433
  if (replyTo !== undefined && (typeof replyTo !== "string" || !replyTo)) return json({ error: "replyToMessageID must be a non-empty message ID" }, 400);
@@ -479,9 +468,9 @@ async function handle(req: Request): Promise<Response> {
479
468
  const roomId = decodeURIComponent(answer[1]!);
480
469
  const questionID = decodeURIComponent(answer[2]!);
481
470
  const body: unknown = await req.json();
482
- if (!body || typeof body !== "object" || Array.isArray(body)) return json({ error: "sessionID and non-empty text (max 2000) are required" }, 400);
471
+ if (!body || typeof body !== "object" || Array.isArray(body)) return json({ error: "sessionID and non-empty text (max 5000) are required" }, 400);
483
472
  const input = body as Record<string, unknown>;
484
- if (typeof input.sessionID !== "string" || !input.sessionID || typeof input.text !== "string" || !input.text.trim() || input.text.trim().length > 2000) return json({ error: "sessionID and non-empty text (max 2000) are required" }, 400);
473
+ if (typeof input.sessionID !== "string" || !input.sessionID || typeof input.text !== "string" || !input.text.trim() || input.text.trim().length > 5000) return json({ error: "sessionID and non-empty text (max 5000) are required" }, 400);
485
474
  const result = await answerQuestion(roomId, questionID, input.sessionID, input.text.trim());
486
475
  if (result.status === "missing") return json({ error: "room not found" }, 404);
487
476
  if (result.status === "question") return json({ error: "question not found" }, 404);
package/server/chat.html CHANGED
@@ -9,9 +9,12 @@
9
9
  <link rel="manifest" href="/manifest.webmanifest">
10
10
  <link rel="apple-touch-icon" href="/assets/icons/apple-touch-icon.png">
11
11
  <meta name="theme-color" content="#22695c">
12
+ <meta name="mobile-web-app-capable" content="yes">
12
13
  <meta name="apple-mobile-web-app-capable" content="yes">
13
14
  <link rel="stylesheet" href="/assets/base.css">
15
+
14
16
  <link rel="stylesheet" href="/assets/conversation.css">
17
+ <link rel="stylesheet" href="/assets/recall.css">
15
18
  <link rel="stylesheet" href="/assets/attachments.css">
16
19
  <link rel="stylesheet" href="/assets/responsive.css">
17
20
  </head>
@@ -27,22 +30,35 @@
27
30
  <!-- Join or create a room. -->
28
31
  <section id="joinView" class="view" hidden>
29
32
  <div class="join-shell">
30
- <div class="join-side">
33
+ <header class="join-head">
34
+ <div class="wordmark-row"><span class="brand-mark" aria-hidden="true">OC</span><p class="wordmark" data-i18n="brand">OC Chat</p><span class="version-tag">{{version}}</span></div>
31
35
  <div class="locale-control">
32
- <label for="localeSelectJoin" data-i18n="languageLabel">Language</label>
36
+ <label for="localeSelectJoin" class="locale-label"><svg class="locale-icon" aria-hidden="true" viewBox="0 0 24 24"><circle cx="12" cy="12" r="9"/><path d="M3 12h18M12 3c2.5 2.7 3.8 5.7 3.8 9S14.5 18.3 12 21M12 3C9.5 5.7 8.2 8.7 8.2 12s1.3 6.3 3.8 9"/></svg><span data-i18n="languageLabel">Language</span></label>
33
37
  <select id="localeSelectJoin" class="locale-select" aria-label="Language" data-i18n-aria-label="languageLabel">
34
38
  <option value="en">English</option>
35
39
  <option value="zh-CN">中文</option>
36
40
  </select>
41
+ <button id="btnKeysJoin" class="keys-hint" type="button" data-shortcuts aria-haspopup="dialog" aria-controls="shortcutsDialog" aria-label="Keyboard hints" data-i18n-aria-label="keyboardHints" title="Keyboard hints" data-i18n-title="keyboardHints" aria-keyshortcuts="Alt+/"><span class="keys-label" data-i18n="shortcutsLabel">Shortcuts</span></button>
37
42
  </div>
38
- <div class="wordmark-row"><p class="wordmark" data-i18n="brand">OC Chat</p><span class="version-tag">{{version}}</span></div>
39
43
  <p class="tagline" data-i18n="tagline">A lightweight chat room. Enter a room ID to join, or create a new one.</p>
40
- <label class="field join-name">
41
- <span class="field-label" data-i18n="nameLabel">Your name</span>
44
+ </header>
45
+ <section id="installPrompt" class="install-prompt" aria-labelledby="installPromptTitle" hidden>
46
+ <div class="install-prompt-copy">
47
+ <strong id="installPromptTitle" data-i18n="installTitle">Install OC Chat</strong>
48
+ <p data-i18n="installBody">Add it to your home screen for a full-screen chat.</p>
49
+ </div>
50
+ <div class="install-prompt-actions">
51
+ <button id="btnInstallApp" class="btn primary small" type="button" data-i18n="installAction">Install</button>
52
+ <button id="btnInstallGuide" class="btn ghost small" type="button" data-i18n="installHow" aria-controls="installGuide" aria-expanded="false" hidden>How to install</button>
53
+ <button id="btnDismissInstall" class="btn ghost small" type="button" data-i18n="installNotNow">Not now</button>
54
+ </div>
55
+ <p id="installGuide" class="install-guide" data-i18n="installIosGuide" hidden>Tap Share, then Add to Home Screen.</p>
56
+ </section>
57
+ <div class="join-entries">
58
+ <label class="entry-card identity-card field join-name">
59
+ <span class="field-label identity-title" data-i18n="nameLabel">Your name</span>
42
60
  <input id="inName" class="input" placeholder="What should we call you?" data-i18n-placeholder="namePlaceholder" autocomplete="nickname" maxlength="24">
43
61
  </label>
44
- </div>
45
- <div class="join-entries">
46
62
  <form id="joinForm" class="entry-card" novalidate>
47
63
  <h2 data-i18n="joinRoomTitle">Join a room</h2>
48
64
  <p class="entry-hint" data-i18n="joinRoomHint">Someone shared a room ID with you? Paste it here.</p>
@@ -59,10 +75,28 @@
59
75
  <span class="field-label" data-i18n="newRoomNameLabel">New room name</span>
60
76
  <input id="inRoomName" class="input" placeholder="e.g. Weekend movie night" data-i18n-placeholder="newRoomNamePlaceholder" maxlength="40">
61
77
  </label>
78
+ <div class="join-policy">
79
+ <input id="inApprovalRequired" type="checkbox" role="switch" aria-describedby="inApprovalRequiredHint">
80
+ <label for="inApprovalRequired" class="join-policy-label" data-i18n="requireApproval">Require approval to join</label>
81
+ </div>
82
+ <p id="inApprovalRequiredHint" class="hint join-policy-hint" data-i18n="requireApprovalHint">New members need a human administrator's approval. Agents may also be approved by the administrator agent.</p>
62
83
  <button class="btn ghost" type="submit" id="btnCreate" data-i18n="createRoom">Create room</button>
63
84
  </form>
64
85
  <div id="joinError" class="alert" role="alert" hidden></div>
65
86
  </div>
87
+ <section id="joinPending" class="join-pending" hidden aria-labelledby="joinPendingTitle">
88
+ <span class="join-pending-mark" aria-hidden="true"><svg viewBox="0 0 24 24"><rect x="5" y="10" width="14" height="10" rx="2"/><path d="M8 10V7a4 4 0 0 1 8 0v3"/></svg></span>
89
+ <div class="join-pending-copy">
90
+ <h2 id="joinPendingTitle" tabindex="-1" data-i18n="joinPendingTitle">Waiting for approval</h2>
91
+ <p id="joinPendingBody" role="status" aria-live="polite"></p>
92
+ <p id="joinPendingHint" class="hint"></p>
93
+ </div>
94
+ <div class="join-pending-actions">
95
+ <button id="btnJoinPendingCheck" class="btn ghost small" type="button" data-i18n="joinPendingCheck">Check again</button>
96
+ <button id="btnJoinPendingAgain" class="btn primary small" type="button" data-i18n="joinPendingAgain" hidden>Request again</button>
97
+ <button id="btnJoinPendingStop" class="btn ghost small" type="button" data-i18n="joinPendingStop">Stop waiting</button>
98
+ </div>
99
+ </section>
66
100
  <section class="room-list">
67
101
  <h2 data-i18n="existingRooms">Existing rooms</h2>
68
102
  <ul id="roomList"></ul>
@@ -94,10 +128,20 @@
94
128
  <div class="rail-label"><span data-i18n="existingRooms">Rooms</span><span class="rail-tools"><button id="btnNewRoom" class="icon-btn" type="button" aria-label="Create a room" data-i18n-aria-label="newRoom"><svg aria-hidden="true" viewBox="0 0 24 24"><path d="M12 5v14M5 12h14"/></svg></button><button id="btnRefreshRooms" class="icon-btn" type="button" aria-label="Refresh rooms" data-i18n-aria-label="refreshRooms"><svg aria-hidden="true" viewBox="0 0 24 24"><path d="M20 7v5h-5M4 17v-5h5"/><path d="M5.6 9a7 7 0 0 1 11.8-2L20 12M4 12l2.6 5a7 7 0 0 0 11.8-2"/></svg></button></span></div>
95
129
  <form id="railRoomForm" class="rail-composer" hidden>
96
130
  <label class="field"><span class="field-label" data-i18n="newRoomNameLabel">New room name</span><input id="inRoomNameChat" class="input" maxlength="40" data-i18n-placeholder="newRoomNamePlaceholder" placeholder="e.g. Weekend movie night"></label>
131
+ <div class="join-policy rail-join-policy">
132
+ <input id="inApprovalRequiredChat" type="checkbox" role="switch" aria-describedby="inApprovalRequiredChatHint">
133
+ <label for="inApprovalRequiredChat" class="join-policy-label" data-i18n="requireApproval">Require approval to join</label>
134
+ </div>
135
+ <p id="inApprovalRequiredChatHint" class="hint join-policy-hint rail-join-policy-hint" data-i18n="requireApprovalHint">New members need a human administrator's approval. Agents may also be approved by the administrator agent.</p>
97
136
  <button id="btnCreateChatRoom" class="btn primary small" type="submit" data-i18n="createRoom">Create room</button>
98
137
  </form>
99
138
  <ul id="roomListChat" class="rail-rooms"></ul>
100
139
  <p id="roomListChatEmpty" class="hint" data-i18n="noRooms" hidden></p>
140
+
141
+ <div id="railInstall" class="rail-install" hidden>
142
+ <button id="btnRailInstall" class="btn ghost small rail-install-btn" type="button"><svg aria-hidden="true" viewBox="0 0 24 24"><path d="M12 4v10M8 10l4 4 4-4M5 19h14"/></svg><span data-i18n="installAction">Install</span></button>
143
+ <p id="railInstallGuide" class="hint" data-i18n="installIosGuide" hidden>Tap Share, then Add to Home Screen.</p>
144
+ </div>
101
145
  <div class="rail-foot">
102
146
  <div class="anchor user-menu-anchor">
103
147
  <button id="btnSettings" class="user-menu-trigger" type="button" aria-label="Your profile and settings" data-i18n-aria-label="profileMenu" aria-haspopup="dialog" aria-expanded="false" aria-controls="chatSettings">
@@ -105,7 +149,7 @@
105
149
  </button>
106
150
  <div class="panel user-menu-panel" id="chatSettings" role="dialog" aria-modal="false" aria-labelledby="settingsHeading" hidden>
107
151
  <h3 id="settingsHeading" data-i18n="settings">Settings</h3>
108
- <label class="field"><span class="field-label" data-i18n="languageLabel">Language</span><select id="localeSelectSettings" class="locale-select"><option value="en">English</option><option value="zh-CN">中文</option></select></label>
152
+ <label class="field"><span class="field-label locale-label"><svg class="locale-icon" aria-hidden="true" viewBox="0 0 24 24"><circle cx="12" cy="12" r="9"/><path d="M3 12h18M12 3c2.5 2.7 3.8 5.7 3.8 9S14.5 18.3 12 21M12 3C9.5 5.7 8.2 8.7 8.2 12s1.3 6.3 3.8 9"/></svg><span data-i18n="languageLabel">Language</span></span><select id="localeSelectSettings" class="locale-select"><option value="en">English</option><option value="zh-CN">中文</option></select></label>
109
153
  <label class="field"><span class="field-label" data-i18n="tokenOptional">Access token (optional)</span><input id="inTokenChat" class="input" type="password" placeholder="Enter if the server requires it" data-i18n-placeholder="tokenPlaceholder" autocomplete="off" spellcheck="false"></label>
110
154
  <button class="btn ghost small" type="button" data-token-save="inTokenChat" data-i18n="save">Save</button>
111
155
  <p id="tokenHint" class="hint" data-i18n="tokenRequired" hidden>The server requires an access token (401).</p>
@@ -120,6 +164,11 @@
120
164
  <form id="editRoomForm" class="admin-guide">
121
165
  <label class="field"><span class="field-label" data-i18n="roomNameLabel">Room name</span><input id="editRoomName" class="input" maxlength="64" autocomplete="off" required></label>
122
166
  <label class="field"><span class="field-label" data-i18n="roomDescriptionLabel">Description</span><textarea id="editRoomDescription" class="input" rows="3" maxlength="2000"></textarea></label>
167
+ <div class="join-policy admin-join-policy">
168
+ <input id="editRoomJoinPolicy" type="checkbox" role="switch" aria-describedby="editRoomJoinPolicyHint">
169
+ <label for="editRoomJoinPolicy" class="join-policy-label" data-i18n="requireApproval">Require approval to join</label>
170
+ </div>
171
+ <p id="editRoomJoinPolicyHint" class="hint join-policy-hint" data-i18n="joinPolicyEditHint">New members need a human administrator's approval. Turning this off clears all pending requests.</p>
123
172
  <fieldset class="admin-fieldset"><legend class="field-label" data-i18n="adminIdsLabel">Human administrators</legend><div id="editRoomAdminIds" class="admin-checklist"></div><p id="editRoomAdminIdsEmpty" class="hint" data-i18n="adminIdsEmpty" hidden>No other members are in this room yet.</p><p class="hint" data-i18n="adminIdsHint">These members can edit room details, manage members, delete files, and choose a successor. The owner always has the same powers.</p></fieldset>
124
173
  <label class="field"><span class="field-label" data-i18n="successorLabel">Successor if the owner leaves</span><select id="editRoomSuccessor" class="admin-select"></select></label>
125
174
  <p class="hint" data-i18n="successorHint">If the owner leaves, this person becomes owner. If an administrator leaves, this person takes that role. Leave empty to use the longest-present member.</p>
@@ -141,17 +190,17 @@
141
190
  <div id="reminderCronFields" hidden><label class="field"><span class="field-label" data-i18n="reminderCron">5-field CRON expression</span><input id="reminderCron" class="input" placeholder="0 9 * * 1-5" autocomplete="off"></label></div>
142
191
  <label class="field"><span class="field-label" data-i18n="reminderTimezone">Timezone override (optional)</span><input id="reminderTimezone" class="input" autocomplete="off"></label>
143
192
  <p class="hint" data-i18n="reminderTimezoneHint">Leave blank to use the server timezone. Enter an IANA timezone to override it.</p>
144
- <label class="field"><span class="field-label" data-i18n="reminderText">Reminder text</span><textarea id="reminderText" class="input" rows="3" maxlength="1000" required></textarea></label>
193
+ <label class="field"><span class="field-label" data-i18n="reminderText">Reminder text</span><textarea id="reminderText" class="input" rows="3" maxlength="2000" required aria-describedby="reminderTemplateHint"></textarea></label>
145
194
  <p id="reminderTemplateHint" class="hint" data-i18n="reminderTemplateHint">Use {{time}}, {{initiator}}, and {{room}} in your message.</p>
146
195
  <p id="reminderDialogStatus" class="hint" role="status" aria-live="polite"></p>
147
- <div class="announcement-actions"><button class="btn primary small" type="submit" data-i18n="reminderCreate">Create reminder</button><button id="btnCancelReminder" class="btn ghost small" type="button" data-i18n="close">Close</button></div>
196
+ <div class="announcement-actions"><button id="btnSubmitReminder" class="btn primary small" type="submit" data-i18n="reminderCreate">Create reminder</button><button id="btnCancelReminder" class="btn ghost small" type="button" data-i18n="close">Close</button></div>
148
197
  </form>
149
198
  </dialog>
150
199
  <dialog id="announcementDialog" class="admin-dialog announcement-dialog" aria-labelledby="announcementDialogHeading">
151
200
  <header class="admin-dialog-head"><h2 id="announcementDialogHeading" data-i18n="announcementNew">New announcement</h2><div class="admin-dialog-actions"><button id="btnCloseAnnouncement" class="reader-close" type="button" aria-label="Close" data-i18n-aria-label="close"><svg class="close-icon" aria-hidden="true" viewBox="0 0 24 24"><path d="M6 6l12 12M18 6 6 18"/></svg></button></div></header>
152
201
  <form id="announcementForm" class="admin-guide announcement-form">
153
- <label class="field"><span class="field-label" data-i18n="announcementName">Name</span><input id="announcementName" class="input" maxlength="128" autocomplete="off" required></label>
154
- <label class="field"><span class="field-label" data-i18n="announcementContent">Content</span><textarea id="announcementContent" class="input" rows="4" maxlength="10000"></textarea></label>
202
+ <label class="field"><span class="field-label" data-i18n="announcementName">Name</span><input id="announcementName" class="input" maxlength="64" autocomplete="off" required></label>
203
+ <label class="field"><span class="field-label" data-i18n="announcementContent">Content</span><textarea id="announcementContent" class="input" rows="4" maxlength="5000" aria-describedby="announcementCount"></textarea></label>
155
204
  <p id="announcementCount" class="hint">0 / 5000</p>
156
205
  <p id="announcementDialogStatus" class="hint" role="status" aria-live="polite"></p>
157
206
  <div class="announcement-actions"><button id="btnSaveAnnouncement" class="btn primary small" type="submit" data-i18n="save">Save</button><button id="btnDeleteAnnouncement" class="btn ghost small danger-text" type="button" data-i18n="announcementDelete" hidden>Delete</button><button id="btnCancelAnnouncement" class="btn ghost small" type="button" data-i18n="close">Close</button></div>
@@ -165,6 +214,7 @@
165
214
  <button type="button" id="btnCopyId" class="copy-id" aria-label="Copy room ID" data-i18n-aria-label="copyRoomId" title="Click to copy the full room ID" data-i18n-title="copyRoomIdTitle">
166
215
  <span class="mono" id="roomIdShort"></span><span class="copy-ok" data-i18n="copied">Copied</span>
167
216
  </button>
217
+ <span id="roomPolicy" class="room-policy" data-i18n="approvalRequired" hidden>Approval required</span>
168
218
  </p>
169
219
  <p id="roomDescription" class="room-description" hidden></p>
170
220
  </div>
@@ -197,9 +247,19 @@
197
247
  </section>
198
248
  </div>
199
249
  <div class="anchor">
200
- <button class="chip" type="button" id="btnMembers" aria-label="Members" data-i18n-aria-label="members" aria-haspopup="true" aria-expanded="false"><svg class="action-icon" aria-hidden="true" viewBox="0 0 24 24"><circle cx="9" cy="8" r="3"/><path d="M3.5 19v-1.5a5.5 5.5 0 0 1 11 0V19zM16 5.5a3 3 0 0 1 0 5.8M17 14a4.5 4.5 0 0 1 3.5 4.4V19h-3"/></svg><span class="action-label" data-i18n="members">Members</span></button>
250
+ <button class="chip" type="button" id="btnMembers" aria-label="Members" data-i18n-aria-label="members" aria-haspopup="true" aria-expanded="false"><svg class="action-icon" aria-hidden="true" viewBox="0 0 24 24"><circle cx="9" cy="8" r="3"/><path d="M3.5 19v-1.5a5.5 5.5 0 0 1 11 0V19zM16 5.5a3 3 0 0 1 0 5.8M17 14a4.5 4.5 0 0 1 3.5 4.4V19h-3"/></svg><span class="action-label" data-i18n="members">Members</span><span id="joinRequestBadge" class="question-badge join-request-badge" aria-hidden="true" hidden><span id="joinRequestBadgeCount"></span><span id="joinRequestBadgeWord" class="join-request-badge-word"></span></span></button>
201
251
  <div class="panel" id="memberPanel" hidden>
202
252
  <h3 data-i18n="members">Members</h3>
253
+ <section id="joinRequests" class="join-requests" hidden aria-labelledby="joinRequestsTitle">
254
+ <div class="join-requests-head">
255
+ <h4 id="joinRequestsTitle" tabindex="-1" data-i18n="joinRequestsTitle">Join requests</h4>
256
+ <span id="joinRequestsCount" class="join-requests-count" hidden></span>
257
+ </div>
258
+ <p id="joinRequestsHint" class="hint" data-i18n="joinRequestsHint" hidden>Agent requests can also be approved by the administrator agent.</p>
259
+ <p id="joinRequestsStatus" class="hint" role="status" aria-live="polite"></p>
260
+ <ul id="joinRequestList" class="join-request-list" aria-label="Join requests" data-i18n-aria-label="joinRequestsTitle"></ul>
261
+ <p id="joinRequestsEmpty" class="hint" data-i18n="joinRequestsEmpty" hidden>No pending requests.</p>
262
+ </section>
203
263
  <ul id="memberList"></ul>
204
264
  <p id="memberEmpty" class="hint" data-i18n="noMembers" hidden>No members yet.</p>
205
265
  </div>
@@ -239,22 +299,31 @@
239
299
  </aside>
240
300
 
241
301
  <footer class="composer">
302
+ <section id="joinNotice" class="join-notice" role="status" aria-live="polite" hidden>
303
+ <span id="joinNoticeText" class="join-notice-text"></span>
304
+ <span class="join-notice-actions">
305
+ <button id="btnJoinNoticeCheck" class="btn ghost small" type="button" data-i18n="joinPendingCheck">Check again</button>
306
+ <button id="btnJoinNoticeAgain" class="btn primary small" type="button" data-i18n="joinPendingAgain" hidden>Request again</button>
307
+ <button id="btnJoinNoticeStop" class="btn ghost small" type="button" data-i18n="joinPendingStop">Stop waiting</button>
308
+ </span>
309
+ </section>
242
310
  <p id="sendError" class="send-error" role="alert" hidden></p>
243
311
  <section id="replyPreview" class="reply-preview" aria-label="Replying to" data-i18n-aria-label="replyingTo" hidden><div><span data-i18n="replyingTo">Replying to</span> <strong id="replyPreviewName"></strong><p id="replyPreviewText"></p></div><button id="replyCancel" type="button" class="reply-cancel" aria-label="Cancel reply" data-i18n-aria-label="cancelReply">×</button></section>
244
312
  <div id="mentionPicker" class="mention-picker" role="listbox" aria-label="Choose a member to mention" data-i18n-aria-label="mentionMembers" hidden></div>
245
313
  <section id="attachmentTray" class="attachment-tray" aria-label="Attachments" data-i18n-aria-label="attachments" hidden>
246
- <p id="attachmentVolatile" class="attachment-volatile" data-i18n="attachmentVolatile" hidden></p>
314
+ <p id="attachmentVolatile" class="attachment-volatile" data-i18n="attachmentVolatile" hidden>Pasted files are recovered after reload; picked files stay in this tab.</p>
247
315
  <ul id="attachmentList" class="attachment-list"></ul>
248
316
  <p id="attachmentStatus" class="attachment-status" role="status" aria-live="polite"></p>
249
317
  </section>
250
318
  <div class="composer-row">
251
319
  <button class="attachment-button" type="button" id="btnAddAttachments" aria-label="Add files" data-i18n-aria-label="addFiles" aria-controls="attachmentPicker" disabled><svg aria-hidden="true" viewBox="0 0 24 24"><path d="m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.82-2.83l8.49-8.48"/></svg></button>
252
320
  <input id="attachmentPicker" type="file" multiple hidden>
253
- <div id="msgInput" class="input message-editor" role="textbox" aria-multiline="true" aria-label="Message" data-i18n-aria-label="messagePlaceholder" aria-placeholder="Type a message, Enter to send, Shift+Enter for a new line" data-i18n-aria-placeholder="messagePlaceholder" aria-autocomplete="list" aria-controls="mentionPicker" aria-expanded="false" contenteditable="false" aria-disabled="true" tabindex="-1"></div>
321
+ <div id="msgInput" class="input message-editor" role="textbox" aria-multiline="true" aria-label="Message" data-i18n-aria-label="messagePlaceholder" aria-placeholder="Type a message, Enter to send, Shift+Enter for a new line" data-i18n-aria-placeholder="messagePlaceholder" aria-autocomplete="list" aria-controls="mentionPicker" aria-expanded="false" aria-keyshortcuts="Enter Shift+Enter" contenteditable="false" aria-disabled="true" tabindex="-1"></div>
254
322
  <button class="btn primary" type="button" id="btnSend" data-i18n="send" disabled>Send</button>
255
323
  </div>
256
324
  <div class="composer-meta">
257
- <p id="draftCount" class="draft-count">0 / 2000</p>
325
+ <button id="btnKeysChat" class="keys-hint composer-keys" type="button" data-shortcuts aria-haspopup="dialog" aria-controls="shortcutsDialog" aria-label="Keyboard hints" data-i18n-aria-label="keyboardHints" title="Keyboard hints" data-i18n-title="keyboardHints" aria-keyshortcuts="Alt+/"><span class="keys-label" data-i18n="shortcutsLabel">Shortcuts</span></button>
326
+ <p id="draftCount" class="draft-count">0 / 5000</p>
258
327
  </div>
259
328
  </footer>
260
329
  <div id="attachmentDropOverlay" class="attachment-drop-overlay" role="status" aria-live="polite" data-i18n="dropFilesHere" hidden></div>
@@ -263,6 +332,11 @@
263
332
  <!-- Full-screen view of an image already loaded in the message list. -->
264
333
  <dialog id="imageDialog" class="image-dialog" aria-label="Image preview" data-i18n-aria-label="imagePreviewTitle">
265
334
  <button id="btnCloseImage" class="image-dialog-close" type="button" aria-label="Close" data-i18n-aria-label="close"><svg class="close-icon" aria-hidden="true" viewBox="0 0 24 24"><path d="M6 6l12 12M18 6 6 18"/></svg></button>
335
+ <div class="image-dialog-tools" role="group" aria-label="Image zoom" data-i18n-aria-label="imageZoomControls">
336
+ <button id="btnZoomOut" class="image-dialog-tool" type="button" aria-label="Zoom out" data-i18n-aria-label="zoomOut">−</button>
337
+ <button id="btnZoomReset" class="image-dialog-tool image-dialog-reset" type="button" aria-label="Reset zoom" data-i18n-aria-label="zoomReset"><span id="zoomLevel">100%</span></button>
338
+ <button id="btnZoomIn" class="image-dialog-tool" type="button" aria-label="Zoom in" data-i18n-aria-label="zoomIn">+</button>
339
+ </div>
266
340
  <img id="imageDialogImage" alt="">
267
341
  </dialog>
268
342
 
@@ -273,6 +347,55 @@
273
347
  <button id="btnOwnerOnlyOk" class="btn ghost small" type="button" data-i18n="close">Close</button>
274
348
  </dialog>
275
349
 
350
+ <dialog id="confirmDialog" class="admin-dialog confirm-dialog" aria-labelledby="confirmHeading">
351
+ <header class="admin-dialog-head"><h2 id="confirmHeading" data-i18n="confirmTitle">Please confirm</h2></header>
352
+ <p id="confirmMessage" class="hint"></p>
353
+ <div class="confirm-actions">
354
+ <button id="btnCancelConfirm" class="btn ghost small" type="button" data-i18n="cancel">Cancel</button>
355
+ <button id="btnAcceptConfirm" class="btn primary small" type="button" data-i18n="confirmAction">Confirm</button>
356
+ </div>
357
+ </dialog>
358
+
359
+ <!-- The visible contract that every control works from the keyboard. -->
360
+ <dialog id="shortcutsDialog" class="keys-dialog" aria-labelledby="shortcutsHeading">
361
+ <header class="keys-dialog-head">
362
+ <h2 id="shortcutsHeading" tabindex="-1" data-i18n="shortcutsTitle">Keyboard shortcuts</h2>
363
+ <button id="btnCloseShortcuts" class="reader-close" type="button" aria-label="Close" data-i18n-aria-label="close"><svg class="close-icon" aria-hidden="true" viewBox="0 0 24 24"><path d="M6 6l12 12M18 6 6 18"/></svg></button>
364
+ </header>
365
+ <p class="keys-lead" data-i18n="shortcutsLead">Every control works from the keyboard. Tags show the keys that work.</p>
366
+
367
+ <section class="keys-section">
368
+ <h3 data-i18n="shortcutsWriting">Writing</h3>
369
+ <ul class="keys-list">
370
+ <li><span class="keys-combo"><kbd class="keys-key">Enter</kbd></span><span data-i18n="shortcutsSend">Send the message</span></li>
371
+ <li><span class="keys-combo"><kbd class="keys-key">Shift</kbd><span class="keys-sep">+</span><kbd class="keys-key">Enter</kbd></span><span data-i18n="shortcutsNewline">Start a new line</span></li>
372
+ <li><span class="keys-combo"><kbd class="keys-key">↑</kbd><kbd class="keys-key">↓</kbd><span class="keys-sep">·</span><kbd class="keys-key">Enter</kbd></span><span data-i18n="shortcutsMention">Choose a member to mention</span></li>
373
+ </ul>
374
+ </section>
375
+ <section class="keys-section">
376
+ <h3 data-i18n="shortcutsRooms">Rooms</h3>
377
+ <ul class="keys-list">
378
+ <li><span class="keys-combo"><kbd class="keys-key">Alt</kbd><span class="keys-sep">+</span><kbd class="keys-key">↑</kbd><span class="keys-sep">/</span><kbd class="keys-key">↓</kbd></span><span data-i18n="shortcutsSwitchRoom">Switch to the previous or next room</span></li>
379
+ </ul>
380
+ </section>
381
+ <section class="keys-section">
382
+ <h3 data-i18n="shortcutsReading">Reading</h3>
383
+ <ul class="keys-list">
384
+ <li><span class="keys-combo"><kbd class="keys-key">PageUp</kbd><span class="keys-sep">/</span><kbd class="keys-key">PageDown</kbd></span><span data-i18n="shortcutsScroll">Scroll messages while typing</span></li>
385
+ <li><span class="keys-combo"><kbd class="keys-key">Alt</kbd><span class="keys-sep">+</span><kbd class="keys-key">Home</kbd><span class="keys-sep">/</span><kbd class="keys-key">End</kbd></span><span data-i18n="shortcutsJump">Jump to the start or end of the conversation</span></li>
386
+ </ul>
387
+ </section>
388
+ <section class="keys-section">
389
+ <h3 data-i18n="shortcutsMenus">Menus and dialogs</h3>
390
+ <ul class="keys-list">
391
+ <li><span class="keys-combo"><kbd class="keys-key">Esc</kbd></span><span data-i18n="shortcutsClose">Close the open menu, panel, or dialog</span></li>
392
+ </ul>
393
+ </section>
394
+
395
+ </dialog>
396
+
397
+
398
+
276
399
  </main>
277
400
 
278
401
  <script src="/assets/marked-18.0.4.js"></script>
package/server/inbox.ts CHANGED
@@ -6,7 +6,7 @@ export type InboxItem = Pick<Message, "id" | "roomId" | "senderId" | "senderSess
6
6
  roomKind?: "group" | "direct";
7
7
  answerQuestionExcerpt?: string;
8
8
  };
9
- export type InboxResult = { member: boolean; items: InboxItem[]; queuedTs: Record<string, number>; hasMore: boolean };
9
+ export type InboxResult = { member: boolean; items: InboxItem[]; queuedTs: Record<string, number>; hasMore: boolean; recallVersion: number };
10
10
 
11
11
  export async function readInbox(sessionID: string, roomFilter: string | null, excludeSelf: boolean, afterTs?: number): Promise<InboxResult> {
12
12
  return readInboxMessages(sessionID, roomFilter, excludeSelf, excludeSelf ? 20 : 100, afterTs);