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

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 (77) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/cli.ts +1 -1
  3. package/docs/administrator-rooms.md +5 -4
  4. package/index.ts +2 -2
  5. package/package.json +3 -2
  6. package/plugin.ts +21 -20
  7. package/server/admin-routes.ts +15 -7
  8. package/server/admin-state.ts +2 -2
  9. package/server/announcement-routes.ts +2 -2
  10. package/server/assets/attachments.css +25 -0
  11. package/server/assets/base.css +42 -30
  12. package/server/assets/chat/admin-badge.js +27 -0
  13. package/server/assets/chat/admin.js +71 -24
  14. package/server/assets/chat/announcements.js +27 -11
  15. package/server/assets/chat/attachments.js +50 -10
  16. package/server/assets/chat/events.js +31 -7
  17. package/server/assets/chat/image-zoom.js +57 -0
  18. package/server/assets/chat/index.js +2 -0
  19. package/server/assets/chat/markdown.js +33 -4
  20. package/server/assets/chat/members.js +14 -6
  21. package/server/assets/chat/message-polling.js +137 -0
  22. package/server/assets/chat/message-window.js +14 -0
  23. package/server/assets/chat/messages.js +6 -128
  24. package/server/assets/chat/panels.js +37 -0
  25. package/server/assets/chat/receipts.js +3 -1
  26. package/server/assets/chat/reminders.js +19 -5
  27. package/server/assets/chat/room-list.js +51 -0
  28. package/server/assets/chat/rooms.js +20 -80
  29. package/server/assets/chat/state.js +28 -14
  30. package/server/assets/chat/system-messages.js +25 -7
  31. package/server/assets/conversation.css +18 -26
  32. package/server/assets/responsive.css +25 -8
  33. package/server/chat-server.ts +38 -8
  34. package/server/chat.html +103 -67
  35. package/server/history-route.ts +1 -1
  36. package/server/inbox.ts +2 -2
  37. package/server/member-routes.ts +4 -4
  38. package/server/newrooms.ts +96 -13
  39. package/server/resource-routes.ts +19 -5
  40. package/server/room-owner.ts +89 -0
  41. package/server/room-payload.ts +4 -2
  42. package/server/room-reminders.ts +3 -3
  43. package/server/sw.js +1 -0
  44. package/server/wake.ts +5 -5
  45. package/skills/chatroom/SKILL.md +3 -1
  46. package/src/README.md +20 -0
  47. package/src/{admin-client.ts → agent/admin-client.ts} +15 -9
  48. package/src/{admin-credentials.ts → agent/admin-credentials.ts} +1 -1
  49. package/src/{agent-presence.ts → agent/agent-presence.ts} +2 -2
  50. package/src/{agent-receipts.ts → agent/agent-receipts.ts} +2 -2
  51. package/src/{announcement-tool.ts → agent/announcement-tool.ts} +2 -2
  52. package/src/{chatroom-skill.ts → agent/chatroom-skill.ts} +1 -1
  53. package/src/{center-client.ts → center/center-client.ts} +22 -9
  54. package/src/{center-inbox.ts → center/center-inbox.ts} +9 -9
  55. package/src/{center-wake.ts → center/center-wake.ts} +6 -6
  56. package/src/{mentions.ts → center/mentions.ts} +1 -1
  57. package/src/{queue-transport.ts → center/queue-transport.ts} +3 -3
  58. package/src/{queue.ts → center/queue.ts} +2 -2
  59. package/src/{reminder-client.ts → center/reminder-client.ts} +1 -1
  60. package/src/{session-delivery.ts → center/session-delivery.ts} +1 -1
  61. package/src/{announcements.ts → rooms/announcements.ts} +2 -2
  62. package/src/{resource-upload.ts → rooms/resource-upload.ts} +1 -1
  63. package/src/{resources.ts → rooms/resources.ts} +55 -9
  64. package/src/{room-service.ts → rooms/room-service.ts} +12 -1
  65. package/src/{background.ts → runtime/background.ts} +3 -3
  66. package/src/{plugin-notifications.ts → runtime/plugin-notifications.ts} +8 -8
  67. package/src/{v1-plugin.ts → runtime/v1-plugin.ts} +4 -4
  68. package/src/{v2-plugin.ts → runtime/v2-plugin.ts} +9 -9
  69. package/src/{v2-receiver.ts → runtime/v2-receiver.ts} +7 -7
  70. package/src/{watch.ts → runtime/watch.ts} +12 -12
  71. package/src/{member-state.ts → state/member-state.ts} +2 -2
  72. package/src/{sqlite-state.ts → state/sqlite-state.ts} +35 -15
  73. package/src/{store.ts → state/store.ts} +2 -2
  74. package/src/tests/announcement-board.ts +176 -0
  75. /package/src/{resource-read.ts → rooms/resource-read.ts} +0 -0
  76. /package/src/{receiver-owner.ts → state/receiver-owner.ts} +0 -0
  77. /package/src/{receiver-state.ts → state/receiver-state.ts} +0 -0
@@ -15,6 +15,7 @@ export const app = {
15
15
  },
16
16
  rendered: 0,
17
17
  firstMessageId: null,
18
+ locale: "en",
18
19
  pollDelay: 2000,
19
20
  copyTimer: 0,
20
21
  failedRenderIds: new Set(),
@@ -204,12 +205,16 @@ const messages = {
204
205
  languageLabel: "Language", roomIdLabel: "Room ID", roomIdPlaceholder: "Paste or enter a room ID",
205
206
  nameLabel: "Your name", namePlaceholder: "What should we call you?", joinRoom: "Join room",
206
207
  or: "or", newRoomNameLabel: "New room name", newRoomNamePlaceholder: "e.g. Weekend movie night",
207
- createRoom: "Create room", tokenOptional: "Access token (optional)", bearerToken: "Bearer token",
208
+ createRoom: "Create room", joinRoomTitle: "Join a room", joinRoomHint: "Someone shared a room ID with you? Paste it here.",
209
+ createRoomTitle: "Create a room", createRoomHint: "Start a new room and invite people with its ID.",
210
+ accessKeyTitle: "Access key", accessKeyHint: "This server asks for an access key. It stays in this browser and is sent with each request.",
211
+ tokenOptional: "Access token (optional)", bearerToken: "Bearer token",
208
212
  tokenPlaceholder: "Enter if the server requires it", save: "Save",
209
213
  tokenHint: "If the server requires an access token (401), all requests will include it.",
210
214
  existingRooms: "Rooms", noRooms: "No rooms yet. Create one.", copyRoomId: "Copy room ID", loadingHistory: "Loading earlier messages",
211
- editRoom: "Edit room", roomNameLabel: "Room name", roomDescriptionLabel: "Description", adminAgentLabel: "Administrator agent",
212
- adminAgentHint: "The designated agent can inspect all rooms and their history with the admin tool. Leave empty for none.",
215
+ editRoom: "Edit room", roomOwnerOnlyTitle: "Owner or administrator only", roomOwnerOnlyNote: ({ owner }) => `Only the room owner or a room administrator can change these settings. This room belongs to ${owner}.`, roomNameLabel: "Room name", roomDescriptionLabel: "Description", adminAgentLabel: "Administrator agent",
216
+ adminIdsLabel: "Human administrators", adminIdsHint: "These members can edit room details, manage members, delete files, and choose a successor. The owner always has the same powers.", adminIdsEmpty: "No other members are in this room yet.", newOwnerLabel: "New owner", newOwnerHint: "Hand the room to another person who is in it. Only the owner can do this; agents cannot own a room.",
217
+ successorLabel: "Successor if the owner leaves", successorNone: "Longest-present member", 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.", ownerOnlySettingsNote: "Only the owner can change the administrator agent or hand off the room.", adminAgentHint: "The designated agent can use the admin tool to inspect this room and its history. Only the owner can change this; leave empty for none.",
213
218
  noAdminAgent: "None", roomNameRequired: "Room name is required", openQuestions: ({ count }) => `${count} unanswered question${count === 1 ? "" : "s"}`,
214
219
  newRoom: "Create a room",
215
220
  copyRoomIdTitle: ({ id }) => `Click to copy the full room ID: ${id}`, copied: "Copied",
@@ -223,7 +228,7 @@ const messages = {
223
228
  reminderPause: "Pause", reminderResume: "Resume", reminderDelete: "Delete", reminderDeleteConfirm: "Delete this reminder?",
224
229
  reminderCreated: "Reminder created.", reminderUpdated: "Reminder updated.", reminderDeleted: "Reminder deleted.",
225
230
  reminderInvalid: "Check the date, 5-field CRON expression, IANA timezone, and reminder text.", reminderLoadFailed: "Could not load reminders. Your draft is still here.",
226
- diagramLoading: "Rendering diagram…", diagramRenderFailed: "Diagram unavailable; showing its source.", resourceLoading: "Loading file…", resourceFailed: "This file could not be loaded.", resourceDownload: "Download", resourcePreview: "Preview", resourceHide: "Hide preview",
231
+ diagramLoading: "Rendering diagram…", diagramRenderFailed: "Diagram unavailable; showing its source.", resourceLoading: "Loading file…", resourceFailed: "This file could not be loaded.", resourceDownload: "Download", resourcePreview: "Preview", resourceHide: "Hide preview", zoomImage: "Open image", imagePreviewTitle: "Image preview",
227
232
  announcementDelete: "Delete announcement",
228
233
  announcementNew: "New announcement", announcementEmpty: "No announcements yet.", announcementLoading: "Loading announcements…",
229
234
  announcementLoadFailed: "Could not load announcements. Your draft is still here.", announcementSaved: "Announcement saved.", announcementDeleted: "Announcement deleted.",
@@ -241,7 +246,8 @@ const messages = {
241
246
  attachments: "Attachments", addFiles: "Add files", dropFilesHere: "Drop files here to attach",
242
247
  attachmentVolatile: "File attachments are held in this tab and are cleared if you reload.", retryUpload: "Retry", removeFile: "Remove",
243
248
  uploadQueued: "Waiting to upload", uploadReady: "Ready to send", uploadPercent: ({ percent }) => `Uploading ${percent}%`,
244
- uploadFailed: "Upload failed. Retry or remove the file.",
249
+ uploadFailed: ({ reason } = {}) => reason ? `Upload failed (${reason}). Retry or remove the file.` : "Upload failed. Retry or remove the file.",
250
+ fileUnreadable: "This file cannot be read: it may be a temporary file from another app, or still in the cloud. Save it to disk (or take a screenshot) and attach that.",
245
251
  fileTooLarge: "File exceeds the server's current size limit.",
246
252
  send: "Send", roomMeta: ({ members, count }) => `${members} ${members === 1 ? "member" : "members"} · ${count} ${count === 1 ? "message" : "messages"}`,
247
253
  joinArrow: "Join →", joinDirectTitle: "Click to join directly", mentionEmpty: "No matching members",
@@ -260,17 +266,19 @@ const messages = {
260
266
  roomNotFound: "This room is gone, or you no longer have access.",
261
267
  sendAuth: "Send failed: an access token is required", sendNetwork: "Send failed. Your message is saved below.",
262
268
  sendFailed: ({ message }) => `Send failed: ${message}`,
263
- adminRoomDeleteDenied: "This room is designated for administration. Enter the Administration token in Settings to delete it.",
269
+ adminRoomDeleteDenied: "This room is designated for administration. Only the room owner can delete it.",
264
270
  failedMessages: "Messages not sent", retryFailed: "Retry", discardFailed: "Discard",
265
271
  roomListError: "Unable to load rooms. You can enter a room ID directly.", guest: "Guest",
266
272
  roomsLabel: "Rooms", refreshRooms: "Refresh rooms", identityLabel: ({ name }) => `Chatting as ${name}`,
267
273
  roomsMenu: "Open room list", closeRoomList: "Close room list",
268
274
  direct: "Direct", messagePrivately: "Message privately", removeMember: "Remove",
269
- kickConfirm: ({ name, id }) => `Remove ${name} (session ${id}) from this room?`,
275
+ kickConfirm: ({ name }) => `Remove ${name} from this room? They can rejoin with the room ID.`,
270
276
  deleteRoom: "Delete room", deleteConfirm: ({ name }) => `Delete “${name}” and all its messages? This cannot be undone.`,
271
277
  allMembers: "Everyone", messageCount: ({ count }) => `${count} / 2000`,
272
278
  privacyNote: "Anyone with the shared token can read direct messages and manage rooms; the server can read them too.",
279
+ resourceDelete: "Delete file", resourceDeleting: "Deleting…", resourceDeleteConfirm: ({ name }) => `Delete “${name}”? This cannot be undone.`, resourceDeleted: "File deleted.", resourceDeleteFailed: "Could not delete this file.",
273
280
  systemJoined: ({ name }) => `${name} joined the room`, systemLeft: ({ name }) => `${name} left the room`, systemRemoved: ({ name }) => `${name} was removed from the room`,
281
+ systemDesignated: ({ actor, name }) => `${actor} designated ${name} as administrator`, systemRevoked: ({ actor }) => `${actor} revoked the administrator designation`, systemRenamed: ({ actor, from, to }) => `${actor} renamed the room from "${from}" to "${to}"`, systemDescribed: ({ actor }) => `${actor} updated the room description`, systemHanded: ({ actor, name }) => `${actor} handed the room to ${name}`, systemAdminsUpdated: ({ actor }) => `${actor} updated the room administrators`, systemSuccessorNamed: ({ actor, name }) => `${actor} named ${name} as the room successor`, systemSuccessorCleared: ({ actor }) => `${actor} cleared the room successor`,
274
282
  activity_working: "Working", activity_idle: "Foreground idle", activity_waiting: "Waiting", activity_unknown: "Status unknown", activity_offline: "Status stale",
275
283
  activityHint_working: "The agent reports active work.", activityHint_idle: "Foreground is idle; background work may continue.", activityHint_waiting: "The agent reports that it is waiting.", activityHint_unknown: "No activity report is available.", activityHint_offline: "The last status is stale; this does not prove the agent is offline.",
276
284
  receiptCount: ({ count }) => `Read by ${count}`, receiptNone: "No readers yet", receiptNotLoaded: "Read status not loaded", readerPanelTitle: "Message readers", close: "Close", departedMember: "left",
@@ -283,11 +291,15 @@ const messages = {
283
291
  roomIdLabel: "房间 ID", roomIdPlaceholder: "粘贴或输入房间 ID", nameLabel: "你的昵称",
284
292
  namePlaceholder: "怎么称呼你", joinRoom: "加入房间", or: "或", newRoomNameLabel: "新房间名称",
285
293
  newRoomNamePlaceholder: "例如:周末电影夜", createRoom: "创建新房间", tokenOptional: "访问令牌(可选)",
294
+ joinRoomTitle: "加入房间", joinRoomHint: "有人把房间 ID 分享给你?粘贴到这里。",
295
+ createRoomTitle: "创建房间", createRoomHint: "新建一个房间,再把房间 ID 发给别人。",
296
+ accessKeyTitle: "访问密钥", accessKeyHint: "这个服务器需要访问密钥。密钥保存在当前浏览器里,并随每个请求发送。",
286
297
  bearerToken: "Bearer Token", tokenPlaceholder: "服务器要求时填写", save: "保存",
287
298
  tokenHint: "若服务器设置了访问令牌(401),所有请求都会带上它。", existingRooms: "房间",
288
299
  noRooms: "还没有房间,创建一个吧。", copyRoomId: "复制房间 ID", loadingHistory: "正在加载更早的消息",
289
- editRoom: "编辑房间", roomNameLabel: "房间名称", roomDescriptionLabel: "描述", adminAgentLabel: "管理员 Agent",
290
- adminAgentHint: "被指定的 Agent 可用 admin 工具查看所有房间及其历史。留空表示不指定。",
300
+ editRoom: "编辑房间", roomOwnerOnlyTitle: "仅房主或管理员可修改", roomOwnerOnlyNote: ({ owner }) => `只有房主或房间管理员可以修改这些设置。这个房间属于 ${owner}。`, roomNameLabel: "房间名称", roomDescriptionLabel: "描述", adminAgentLabel: "管理员 Agent",
301
+ adminIdsLabel: "成员管理员", adminIdsHint: "这些成员可以修改房间信息、管理成员、删除文件并指定接任者。房主始终拥有这些权限。", adminIdsEmpty: "房间里暂无其他成员。", newOwnerLabel: "新房主", newOwnerHint: "可以把房间交给房间里的另一个人。只有房主可以操作;Agent 不能成为房主。",
302
+ successorLabel: "房主离开后的接任者", successorNone: "最早加入的成员", successorHint: "房主离开后,此人接任房主;管理员离开后,此人接任管理员。留空则最早加入的成员接任房主。", ownerOnlySettingsNote: "只有房主可以更改管理员 Agent 或移交房间。", adminAgentHint: "被指定的 Agent 可用 admin 工具查看此房间及其历史。只有房主可以更改,留空表示不指定。",
291
303
  noAdminAgent: "不指定", roomNameRequired: "房间名称不能为空", openQuestions: ({ count }) => `${count} 个待回答的问题`,
292
304
  newRoom: "创建房间",
293
305
  copyRoomIdTitle: ({ id }) => `点击复制完整房间 ID:${id}`, copied: "已复制", members: "成员",
@@ -301,7 +313,7 @@ const messages = {
301
313
  reminderPause: "暂停", reminderResume: "恢复", reminderDelete: "删除", reminderDeleteConfirm: "确定删除此提醒?",
302
314
  reminderCreated: "提醒已创建。", reminderUpdated: "提醒已更新。", reminderDeleted: "提醒已删除。",
303
315
  reminderInvalid: "请检查日期、5 字段 CRON 表达式、IANA 时区和提醒内容。", reminderLoadFailed: "无法加载提醒,草稿仍已保留。",
304
- diagramLoading: "正在渲染图表…", diagramRenderFailed: "图表无法显示,以下为源代码。", resourceLoading: "正在加载文件…", resourceFailed: "无法加载此文件。", resourceDownload: "下载", resourcePreview: "预览", resourceHide: "收起预览",
316
+ diagramLoading: "正在渲染图表…", diagramRenderFailed: "图表无法显示,以下为源代码。", resourceLoading: "正在加载文件…", resourceFailed: "无法加载此文件。", resourceDownload: "下载", resourcePreview: "预览", resourceHide: "收起预览", zoomImage: "查看大图", imagePreviewTitle: "图片预览",
305
317
  announcementDelete: "删除公告",
306
318
  announcementNew: "新建公告", announcementEmpty: "暂无公告。", announcementLoading: "正在加载公告…",
307
319
  announcementLoadFailed: "无法加载公告,草稿仍已保留。", announcementSaved: "公告已保存。", announcementDeleted: "公告已删除。",
@@ -319,7 +331,8 @@ const messages = {
319
331
  attachments: "附件", addFiles: "添加文件", dropFilesHere: "将文件拖到这里添加",
320
332
  attachmentVolatile: "附件仅保存在当前标签页,刷新页面后会清除。", retryUpload: "重试", removeFile: "移除",
321
333
  uploadQueued: "等待上传", uploadReady: "可以发送", uploadPercent: ({ percent }) => `正在上传 ${percent}%`,
322
- uploadFailed: "上传失败,请重试或移除文件。",
334
+ uploadFailed: ({ reason } = {}) => reason ? `上传失败(${reason}),请重试或移除文件。` : "上传失败,请重试或移除文件。",
335
+ fileUnreadable: "这个文件读不出来:它可能是其他 App 的临时文件,或者还在云端。请先保存到本地(或截图)再发送。",
323
336
  fileTooLarge: "文件超过服务器当前大小限制。",
324
337
  send: "发送", roomMeta: ({ members, count }) => `${members} 人 · ${count} 条消息`, joinArrow: "加入 →",
325
338
  joinDirectTitle: "点击直接加入", mentionEmpty: "没有匹配的成员", mentionHint: "↑↓ 选择 · Enter 确认 · Esc 关闭",
@@ -335,15 +348,16 @@ const messages = {
335
348
  roomNameRequired: "请输入房间名称", createFailed: ({ message }) => `创建失败:${message}`,
336
349
  roomNotFound: "房间不存在,或你已被移出房间", sendAuth: "发送失败:需要访问令牌",
337
350
  sendNetwork: "发送失败,消息已保存在下方", sendFailed: ({ message }) => `发送失败:${message}`,
338
- adminRoomDeleteDenied: "此房间用于管理。请先在设置中输入管理令牌,再删除房间。",
351
+ adminRoomDeleteDenied: "此房间已指定管理员。只有房主可以删除此房间。",
339
352
  failedMessages: "未发送的消息", retryFailed: "重试", discardFailed: "删除",
340
353
  roomListError: "无法加载房间列表,可直接输入房间 ID 加入。", guest: "访客", roomsLabel: "房间列表",
341
354
  refreshRooms: "刷新房间", identityLabel: ({ name }) => `当前昵称:${name}`, roomsMenu: "打开房间列表", closeRoomList: "关闭房间列表", direct: "私聊",
342
- messagePrivately: "私聊", removeMember: "移除", kickConfirm: ({ name, id }) => `确定将 ${name}(会话 ${id})移出此房间?`,
355
+ messagePrivately: "私聊", removeMember: "移除", kickConfirm: ({ name }) => `确定将 ${name} 移出此房间?对方仍可用房间 ID 重新加入。`,
343
356
  deleteRoom: "删除房间", deleteConfirm: ({ name }) => `删除“${name}”及全部聊天记录?此操作无法撤销。`,
344
357
  allMembers: "所有人", messageCount: ({ count }) => `${count} / 2000`,
345
- privacyNote: "持有共享令牌的人都可以读取私聊内容和管理房间;服务器也可以读取私聊内容。",
358
+ privacyNote: "持有共享令牌的人都可以读取私聊内容和管理房间;服务器也可以读取私聊内容。", resourceDelete: "删除文件", resourceDeleting: "正在删除…", resourceDeleteConfirm: ({ name }) => `确定删除“${name}”?此操作无法撤销。`, resourceDeleted: "文件已删除。", resourceDeleteFailed: "无法删除此文件。",
346
359
  systemJoined: ({ name }) => `${name} 加入了房间`, systemLeft: ({ name }) => `${name} 离开了房间`, systemRemoved: ({ name }) => `${name} 被移出了房间`,
360
+ systemDesignated: ({ actor, name }) => `${actor} 指定 ${name} 为管理员`, systemRevoked: ({ actor }) => `${actor} 撤销了管理员指定`, systemRenamed: ({ actor, from, to }) => `${actor} 将房间名称从“${from}”改为“${to}”`, systemDescribed: ({ actor }) => `${actor} 更新了房间描述`, systemHanded: ({ actor, name }) => `${actor} 将房间移交给了 ${name}`, systemAdminsUpdated: ({ actor }) => `${actor} 更新了房间管理员`, systemSuccessorNamed: ({ actor, name }) => `${actor} 指定 ${name} 为房间继任者`, systemSuccessorCleared: ({ actor }) => `${actor} 清除了房间继任者`,
347
361
  activity_working: "工作中", activity_idle: "前台空闲", activity_waiting: "等待中", activity_unknown: "状态未知", activity_offline: "状态已过期",
348
362
  activityHint_working: "Agent 正在报告工作状态。", activityHint_idle: "前台空闲;后台任务仍可能继续。", activityHint_waiting: "Agent 正在报告等待状态。", activityHint_unknown: "暂无活动状态报告。", activityHint_offline: "最近的状态已过期;这不能证明 Agent 已离线。",
349
363
  receiptCount: ({ count }) => `已读 ${count} 人`, receiptNone: "尚无人已读", receiptNotLoaded: "尚未加载已读状态", readerPanelTitle: "消息已读情况", close: "关闭", departedMember: "已离开",
@@ -1,13 +1,31 @@
1
+ const patterns = [
2
+ [/^(.*?) joined the room$/, "systemJoined", (m) => ({ name: m[1] })],
3
+ [/^(.*?) left the room$/, "systemLeft", (m) => ({ name: m[1] })],
4
+ [/^(.*?) was removed from the room$/, "systemRemoved", (m) => ({ name: m[1] })],
5
+ [/^(.*?) designated (.*?) as administrator$/, "systemDesignated", (m) => ({ actor: m[1], name: m[2] })],
6
+ [/^(.*?) updated the room administrators$/, "systemAdminsUpdated", (m) => ({ actor: m[1] })],
7
+ [/^(.*?) named (.*?) as the room successor$/, "systemSuccessorNamed", (m) => ({ actor: m[1], name: m[2] })],
8
+ [/^(.*?) cleared the room successor$/, "systemSuccessorCleared", (m) => ({ actor: m[1] })],
9
+ [/^(.*?) revoked the administrator designation$/, "systemRevoked", (m) => ({ actor: m[1] })],
10
+ [/^(.*?) renamed the room from "(.*)" to "(.*)"$/, "systemRenamed", (m) => ({ actor: m[1], from: m[2], to: m[3] })],
11
+ [/^(.*?) updated the room description$/, "systemDescribed", (m) => ({ actor: m[1] })],
12
+ [/^(.*?) handed the room to (.*)$/, "systemHanded", (m) => ({ actor: m[1], name: m[2] })],
13
+ ];
14
+
15
+ function formatLine(line, app) {
16
+ for (const [pattern, key, values] of patterns) {
17
+ const match = pattern.exec(line);
18
+ if (match) return app.t(key, values(match));
19
+ }
20
+ return line;
21
+ }
22
+
1
23
  export function formatSystemMessage(message, app) {
2
24
  // `<at>@name</at>` is an editor token; system rows and previews show the plain mention.
3
25
  const text = String(message?.text ?? "").replace(/<at>([\s\S]*?)<\/at>/g, "$1");
4
26
  if (message?.senderId !== "system") return text;
5
- const joined = /^(.*?)\s+joined the room$/.exec(text);
6
- if (joined) return app.t("systemJoined", { name: joined[1] });
7
- const left = /^(.*?)\s+left the room$/.exec(text);
8
- if (left) return app.t("systemLeft", { name: left[1] });
9
- const removed = /^(.*?)\s+was removed from the room$/.exec(text);
10
- return removed ? app.t("systemRemoved", { name: removed[1] }) : text;
27
+ // One edit can log several changes joined by "; "; translate each line.
28
+ return text.split("; ").map((line) => formatLine(line, app)).join("; ");
11
29
  }
12
30
 
13
31
  export function setRoomPreview(entry, message) {
@@ -18,4 +36,4 @@ export function setRoomPreview(entry, message) {
18
36
 
19
37
  export function formatRoomPreview(entry, latest, app) {
20
38
  return formatSystemMessage(entry?.preview ? { senderId: entry.previewSenderId, text: entry.preview } : latest, app);
21
- }
39
+ }
@@ -105,6 +105,8 @@
105
105
  font-size: 14px;
106
106
  }
107
107
  #memberList li > span:first-child { grid-column: 1 / -1; min-width: 0; overflow-wrap: anywhere; }
108
+ #memberList .member-identity { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; min-width: 0; }
109
+ #memberList .member-identity > span:first-child { min-width: 0; overflow-wrap: anywhere; }
108
110
  #memberList .member-actions { grid-column: 1 / -1; justify-content: flex-end; flex-wrap: wrap; }
109
111
  #memberList .member-activity + .member-actions { grid-column: 2; grid-row: 2; }
110
112
  #memberList .member-action { white-space: normal; }
@@ -200,11 +202,12 @@
200
202
  .msg.in, .sys.in, .day-sep.in { animation: msg-in .25s ease both; }
201
203
  .msg.own { align-items: flex-end; }
202
204
  .msg.repeat { margin-bottom: 8px; }
203
- .msg-meta { display: flex; align-items: baseline; gap: 8px; margin-bottom: 3px; }
205
+ .msg-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; margin-bottom: 3px; }
204
206
  .msg-name { font-size: 13px; font-weight: 650; color: var(--ink-2); }
205
207
  .msg.own .msg-name { color: var(--accent); }
206
208
  .question-mark { padding: 1px 6px; border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); border-radius: 999px; color: var(--accent); background: var(--accent-soft); font-size: 10px; line-height: 1.5; }
207
209
  .msg.repeat .msg-name { display: none; }
210
+ .msg.repeat .admin-agent-badge { display: none; }
208
211
  .msg-time { font-size: 12px; color: var(--ink-2); }
209
212
  .msg-text {
210
213
  display: inline-block;
@@ -281,8 +284,19 @@
281
284
  .reader-panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
282
285
  .reader-panel-head h2 { margin: 0; font-family: var(--font-sans); font-size: 18px; font-weight: 650; letter-spacing: -.01em; }
283
286
  .reader-panel-head .hint { margin: 0 0 4px; }
284
- .reader-close { flex: none; width: 32px; height: 32px; border: 1px solid var(--line); border-radius: 50%; color: var(--ink-2); background: var(--surface); font: inherit; font-size: 21px; cursor: pointer; }
287
+ .reader-close { display: grid; place-items: center; flex: none; width: 44px; height: 44px; padding: 0; border: 1px solid transparent; border-radius: 10px; color: var(--ink-2); background: transparent; font: inherit; cursor: pointer; transition: background .14s, border-color .14s, color .14s; }
288
+ .reader-close:hover { border-color: var(--line); color: var(--ink); background: var(--surface-2); }
289
+ .close-icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-width: 1.8; }
285
290
  .reader-panel .receipt-reader-list li { display: grid; gap: 3px; padding: 10px 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
291
+ .image-dialog { width: 100vw; max-width: none; height: 100dvh; max-height: none; margin: 0; padding: 20px; border: 0; background: transparent; }
292
+ .image-dialog[open] { display: grid; place-items: center; }
293
+ .image-dialog::backdrop { background: rgb(9 16 22 / .84); backdrop-filter: blur(3px); }
294
+ .image-dialog img { display: block; max-width: 100%; max-height: calc(100dvh - 40px); width: auto; height: auto; object-fit: contain; border-radius: 8px; animation: image-zoom-in .16s ease both; }
295
+ @keyframes image-zoom-in { from { opacity: 0; transform: scale(.97); } }
296
+ .image-dialog-close { position: fixed; top: 14px; right: 14px; display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 1px solid rgb(255 255 255 / .34); border-radius: 50%; color: #fff; background: rgb(9 16 22 / .58); font: inherit; line-height: 1; cursor: pointer; }
297
+ .image-dialog-close .close-icon { width: 22px; height: 22px; }
298
+ .image-dialog-close:hover, .image-dialog-close:focus-visible { background: rgb(9 16 22 / .82); outline: 2px solid #fff; outline-offset: 2px; }
299
+ .msg-text img, .chat-resource img, .attachment-preview img { cursor: zoom-in; }
286
300
  .chat-resource { display: grid; gap: 9px; min-width: 0; margin: 10px 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: color-mix(in srgb, var(--surface-2) 76%, var(--surface)); }
287
301
  .resource-info, .resource-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
288
302
  .resource-name { min-width: 0; overflow-wrap: anywhere; font-weight: 600; }
@@ -333,6 +347,8 @@
333
347
  text-underline-offset: 2px;
334
348
  }
335
349
  .msg-text a:hover { text-decoration: none; }
350
+ /* Inline images stay inside the bubble; the overlay is where they get big. */
351
+ .msg-text img { display: block; max-width: 100%; height: auto; border-radius: 7px; }
336
352
 
337
353
  /* Mention picker */
338
354
  /* Inactive names stay quiet; current members use the accent color. */
@@ -481,27 +497,3 @@
481
497
  .failed-reply-context { flex: 0 0 100%; overflow: hidden; color: var(--accent); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
482
498
  .failed-message button { flex: none; border: 1px solid var(--line); border-radius: 7px; padding: 4px 8px; background: var(--surface); color: var(--ink-2); font: inherit; font-size: 12px; cursor: pointer; }
483
499
  .failed-message button:disabled { opacity: .5; cursor: default; }
484
- .attachment-button { flex: none; display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 1px solid var(--line); border-radius: 12px; color: var(--ink-2); background: var(--surface); font: inherit; font-size: 24px; cursor: pointer; }
485
- .attachment-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
486
- .attachment-button:hover { color: var(--accent); border-color: var(--accent); }
487
- .attachment-button:disabled { opacity: .5; cursor: default; }
488
- .attachment-tray { width: min(940px, 100%); margin: 0 auto; }
489
- .attachment-volatile { margin: 0 0 3px; color: var(--ink-3); font-size: 10.5px; }
490
- .attachment-status { display: inline-flex; width: fit-content; margin: 5px 0 0; padding: 3px 8px; border-radius: 999px; color: var(--accent); background: var(--accent-soft); font-size: 10.5px; }
491
- .attachment-status.danger-text { color: var(--danger); background: var(--danger-soft); }
492
- .attachment-status:empty { display: none; }
493
- .attachment-list { display: grid; gap: 6px; max-height: 132px; overflow: auto; margin: 0; padding: 0; list-style: none; }
494
- .attachment-item { display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; align-items: center; gap: 9px; min-width: 0; padding: 7px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); box-shadow: 0 1px 2px rgb(20 40 32 / .035); }
495
- .attachment-preview { display: grid; place-items: center; width: 38px; height: 38px; overflow: hidden; border: 1px solid color-mix(in srgb, var(--ink) 5%, transparent); border-radius: 8px; background: var(--surface-2); color: var(--ink-3); font-size: 11px; font-weight: 700; }
496
- .attachment-preview img { width: 100%; height: 100%; object-fit: cover; }
497
- .attachment-file { min-width: 0; }
498
- .attachment-name { overflow: hidden; margin: 0; color: var(--ink); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
499
- .attachment-detail { margin: 0; color: var(--ink-3); font-size: 10px; }
500
- .attachment-item progress { display: block; width: 100%; height: 5px; accent-color: var(--accent); }
501
- .attachment-actions { display: flex; gap: 4px; }
502
- .attachment-actions button { min-width: 44px; min-height: 44px; padding: 5px 9px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink-2); background: var(--surface); font: inherit; font-size: 11px; cursor: pointer; }
503
- .attachment-actions button:hover { border-color: var(--accent); color: var(--accent); }
504
- .attachment-over-limit { color: var(--danger); }
505
- #draftCount.over-limit { color: var(--danger); font-weight: 700; }
506
- .attachment-drop-overlay { position: fixed; inset: 12px; z-index: 100; place-items: center; border: 2px dashed var(--accent); border-radius: 18px; color: var(--accent); background: color-mix(in srgb, var(--accent-soft) 88%, transparent); font-size: clamp(18px, 4vw, 28px); font-weight: 700; pointer-events: none; }
507
- #chatView.drag-over .attachment-drop-overlay { display: grid; }
@@ -1,11 +1,16 @@
1
1
 
2
2
  @media (max-width: 560px) {
3
3
  #joinView { padding: 20px 14px; }
4
- .join-card { padding: 28px 22px 24px; }
4
+ .entry-card { padding: 20px 18px 18px; }
5
5
  .chat-head { padding: 12px 16px; }
6
6
  .thread { padding: 16px 16px 4px; }
7
7
  .jump { right: 12px; bottom: 10px; }
8
8
  }
9
+ /* One column below the two-column composition width: brand, then the two entries,
10
+ then the rooms already on this server. */
11
+ @media (max-width: 860px) {
12
+ .join-shell { grid-template-columns: minmax(0, 1fr); grid-template-areas: "side" "entries" "rooms"; grid-template-rows: auto; gap: 20px; }
13
+ }
9
14
 
10
15
  /* Room workspace */
11
16
  #app { max-width: 1440px; }
@@ -29,7 +34,7 @@
29
34
  display: flex;
30
35
  flex-direction: column;
31
36
  min-height: 0;
32
- padding: 22px 14px 14px;
37
+ padding: 22px 14px 0;
33
38
  color: var(--ink);
34
39
  background: radial-gradient(320px 260px at 0% 0%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 72%), linear-gradient(160deg, var(--surface), color-mix(in srgb, var(--accent-soft) 25%, var(--surface)));
35
40
  border-right: 1px solid var(--line);
@@ -53,7 +58,9 @@
53
58
  .r-preview { overflow: hidden; color: var(--ink-3); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
54
59
  .r-badge { position: absolute; top: 8px; right: 9px; display: grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: 10px; font-weight: 700; }
55
60
  .r-badge-question { background: var(--warning); color: var(--warning-ink); font-size: 12px; }
56
- .rail-foot { display: flex; align-items: center; gap: 8px; margin-top: auto; padding: 12px 4px 0; border-top: 1px solid color-mix(in srgb, var(--line) 80%, transparent); font-size: 12px; color: var(--ink-3); }
61
+ /* The rail footer divider and the composer divider share one height: the footer
62
+ takes the composer's measured height, so both lines stay flush as it grows. */
63
+ .rail-foot { display: flex; flex-direction: column; justify-content: center; align-items: stretch; gap: 8px; margin-top: auto; min-height: var(--composer-block, 104px); padding: 12px 4px 14px; border-top: 1px solid color-mix(in srgb, var(--line) 80%, transparent); font-size: 12px; color: var(--ink-3); }
57
64
  .rail-foot .anchor { width: 100%; }
58
65
  .user-menu-trigger { display: flex; align-items: center; gap: 10px; width: 100%; min-width: 0; padding: 7px; border: 1px solid transparent; border-radius: 12px; color: var(--ink); background: transparent; font: inherit; text-align: left; cursor: pointer; transition: border-color .16s, background .16s, box-shadow .16s; }
59
66
  .user-menu-trigger:hover, .user-menu-trigger[aria-expanded="true"] { border-color: color-mix(in srgb, var(--accent) 20%, var(--line)); background: color-mix(in srgb, var(--surface) 84%, var(--accent-soft)); box-shadow: 0 2px 8px rgb(25 50 42 / .06); }
@@ -65,6 +72,9 @@
65
72
  .room-options-panel { display: grid; gap: 4px; width: 190px; }
66
73
  .menu-action { width: 100%; padding: 9px 10px; border: 0; border-radius: 8px; color: var(--ink); background: transparent; font: inherit; text-align: left; cursor: pointer; }
67
74
  .menu-action:hover { background: var(--surface-2); }
75
+ /* A non-owner still sees the entry; it reads as secondary and explains itself. */
76
+ .menu-action.menu-secondary { color: var(--ink-3); }
77
+ .menu-action.menu-secondary:hover { color: var(--ink-2); }
68
78
  .restore-view { display: none; flex: 1; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 20px; color: var(--ink-2); text-align: center; }
69
79
  .session-restore #joinView { display: none; }
70
80
  .session-restore .restore-view { display: flex; }
@@ -74,20 +84,27 @@
74
84
  @keyframes spin { to { transform: rotate(360deg); } }
75
85
  .admin-access { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--line); }
76
86
  .admin-access summary { margin: 0 0 8px; font-size: 13px; font-weight: 600; cursor: pointer; }
77
- .admin-badge, .room-admin-badge { display: inline-flex; align-items: center; width: fit-content; border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line)); border-radius: 999px; color: var(--accent); background: var(--accent-soft); font-size: 10px; font-weight: 700; letter-spacing: .04em; line-height: 1.4; }
87
+ .admin-badge, .admin-agent-badge { display: inline-flex; align-items: center; width: fit-content; border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--line)); border-radius: 999px; color: var(--accent); background: var(--accent-soft); font-size: 10px; font-weight: 700; letter-spacing: .04em; line-height: 1.4; white-space: nowrap; }
78
88
  .admin-badge { padding: 3px 8px; }
79
- .room-admin-badge { padding: 1px 6px; vertical-align: middle; }
89
+ .admin-agent-badge { padding: 1px 6px; vertical-align: middle; }
80
90
  .admin-scope-note { margin: 0 0 14px; padding: 10px 11px; border-left: 2px solid var(--accent); border-radius: 0 8px 8px 0; background: color-mix(in srgb, var(--accent-soft) 58%, transparent); line-height: 1.5; }
81
91
  .admin-dialog { width: min(560px, calc(100vw - 32px)); max-width: none; max-height: 90dvh; overflow: auto; padding: 24px; color: var(--ink); background: linear-gradient(145deg, var(--surface), color-mix(in srgb, var(--accent-soft) 16%, var(--surface))); border: 1px solid color-mix(in srgb, var(--accent) 18%, var(--line)); border-radius: 20px; box-shadow: 0 24px 80px rgb(10 25 20 / .2); }
82
92
  .admin-dialog::backdrop { background: rgb(9 22 18 / .52); backdrop-filter: blur(4px); }
83
93
  .admin-dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
84
94
  .admin-dialog-actions { display: flex; align-items: center; gap: 10px; }
85
- .admin-dialog #btnCloseAdmin { width: 36px; height: 36px; margin: 0; }
86
- .admin-dialog-head h2 { margin: 0; font-family: var(--font-display); font-size: 25px; font-weight: 600; letter-spacing: -.02em; }
95
+ .admin-dialog-head h2 { min-width: 0; margin: 0; font-family: var(--font-display); font-size: 25px; font-weight: 600; letter-spacing: -.02em; overflow-wrap: anywhere; }
87
96
  .admin-dialog h3 { margin: 20px 0 9px; font-size: 14px; font-weight: 700; letter-spacing: .01em; }
88
97
  .admin-guide { padding: 16px; border: 1px solid color-mix(in srgb, var(--line) 82%, transparent); border-radius: 14px; background: color-mix(in srgb, var(--surface) 84%, var(--accent-soft)); }
89
98
  .admin-guide .field { margin-bottom: 12px; }
99
+ .admin-fieldset { margin: 0 0 14px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; }
100
+ .admin-fieldset legend { padding: 0 4px; }
101
+ .admin-checklist { display: grid; gap: 1px; max-height: 160px; overflow: auto; }
102
+ .admin-check { display: flex; align-items: center; gap: 8px; padding: 4px 2px; border-radius: 6px; font-size: 14px; cursor: pointer; }
103
+ .admin-check span { min-width: 0; overflow-wrap: anywhere; }
104
+ .admin-check:hover { background: var(--surface-2); }
105
+ .admin-check input { flex: none; width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
90
106
  .admin-dialog .admin-select { display: block; box-sizing: border-box; width: 100%; min-width: 0; min-height: 40px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: var(--surface); font: inherit; }
107
+ .admin-dialog .admin-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
91
108
  .admin-enrollment { display: grid; gap: 8px; margin-top: 12px; padding: 12px; border-radius: 10px; background: var(--accent-soft); }
92
109
  @media (max-width: 620px) { .admin-dialog { padding: 15px; } }
93
110
  .rail-avatar { display: grid; place-items: center; width: 25px; height: 25px; border-radius: 50%; color: var(--accent); background: var(--accent-soft); }
@@ -134,7 +151,7 @@
134
151
 
135
152
  @media (max-width: 760px) {
136
153
  #chatView { width: 100%; height: 100%; margin: 0; border: 0; border-radius: 0; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr) auto; }
137
- .room-rail { display: none; position: fixed; inset: 0 auto 0 0; z-index: 50; width: min(300px, 88vw); height: 100dvh; min-height: 0; padding: 20px 14px 14px; background: var(--surface); border-right: 1px solid var(--line); box-shadow: var(--shadow); }
154
+ .room-rail { display: none; position: fixed; inset: 0 auto 0 0; z-index: 50; width: min(300px, 88vw); height: 100dvh; min-height: 0; padding: 20px 14px 0; background: var(--surface); border-right: 1px solid var(--line); box-shadow: var(--shadow); }
138
155
  .room-rail.drawer-open { display: flex; }
139
156
  .rail-brand { display: flex; margin-bottom: 22px; }
140
157
  .rail-foot { display: flex; }
@@ -3,26 +3,28 @@
3
3
  // via CHAT_ROOM_SERVER_URL. Optional bearer token (CHAT_ROOM_SERVER_TOKEN).
4
4
  import { promises as fs } from "node:fs";
5
5
  import path from "node:path";
6
+ import { randomUUID } from "node:crypto";
6
7
  import RoomService, {
7
8
  RoomError,
8
9
  type Message,
9
10
  type Room,
10
- } from "../src/room-service";
11
- import { acknowledgeQueued, answerQuestion, appendRoomMessage, sendReply, readQuestions, readState, writeState, type Registry, type RegistryEntry } from "../src/store";
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
13
  import {
13
14
  admissionMatches,
14
15
  clearPendingAdmission,
15
- } from "../src/queue";
16
+ } from "../src/center/queue.ts";
16
17
  import { readInbox } from "./inbox";
17
- import { isReceiverOwnerID } from "../src/receiver-owner";
18
+ import { isReceiverOwnerID } from "../src/state/receiver-owner.ts";
18
19
  import { claimWake, touchActive, wakeMentionedSessions } from "./wake";
19
20
  import { historyRoute } from "./history-route";
20
21
  import { roomPayload } from "./room-payload";
22
+ import { bindOwner, isUser, settleAdmins, settleOwner } from "./room-owner";
21
23
  import { jsonObject } from "./json-body";
22
24
  import { roomManagement } from "./newrooms";
23
25
  import { memberRoutes } from "./member-routes";
24
26
  import { resourceRoutes } from "./resource-routes";
25
- import { maxResourceBytes } from "../src/resources";
27
+ import { maxResourceBytes } from "../src/rooms/resources.ts";
26
28
  import { adminRoutes } from "./admin-routes";
27
29
  import { roomReminderRoutes, startRoomReminderScheduler } from "./room-reminders";
28
30
 
@@ -210,6 +212,7 @@ async function handle(req: Request): Promise<Response> {
210
212
  // ponytail: central mode self-pulls the inbox; no cross-host URL
211
213
  serverUrl: "",
212
214
  apiPrefix: "/api",
215
+ membershipID: randomUUID(),
213
216
  ...(body.protocol === "v2" ? { protocol: "v2" as const } : {}),
214
217
  ...(body.protocol === "v2" && isReceiverOwnerID(body.receiverOwnerID) ? { receiverOwnerID: body.receiverOwnerID } : {}),
215
218
  name: owner,
@@ -222,6 +225,7 @@ async function handle(req: Request): Promise<Response> {
222
225
  ),
223
226
  lastQueuedTs: 0,
224
227
  };
228
+ created.ownerMembershipID = regRoom[body.sessionID]!.membershipID;
225
229
  }
226
230
  return created;
227
231
  });
@@ -352,6 +356,7 @@ async function handle(req: Request): Promise<Response> {
352
356
  if (!already) {
353
357
  svc.addEvent(roomId, `${name} joined the room`);
354
358
  }
359
+
355
360
  const latestMessageTs =
356
361
  svc.getMessages(roomId).at(-1)?.createdAt ?? 0;
357
362
  regRoom[sessionID] = {
@@ -363,7 +368,7 @@ async function handle(req: Request): Promise<Response> {
363
368
  ...(body.protocol === "v2" ? { protocol: "v2" as const } : {}),
364
369
  ...(body.protocol === "v2" && isReceiverOwnerID(body.receiverOwnerID) ? { receiverOwnerID: body.receiverOwnerID } : {}),
365
370
  name,
366
- ...(prevEntry?.membershipID ? { membershipID: prevEntry.membershipID } : {}),
371
+ membershipID: prevEntry?.membershipID ?? randomUUID(),
367
372
  directory: body.directory || undefined,
368
373
  // ora-1 #2: 归属主机——跨机 @-wake 只由所属机器执行
369
374
  host: body.host ?? "",
@@ -372,6 +377,14 @@ async function handle(req: Request): Promise<Response> {
372
377
  regRoom[sessionID]?.lastReadTs ??
373
378
  Math.max(Date.now(), latestMessageTs),
374
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
+ }
375
388
  return svc.getRoom(roomId);
376
389
  });
377
390
  touchActive(sessionID); // join = active
@@ -379,8 +392,9 @@ async function handle(req: Request): Promise<Response> {
379
392
  }
380
393
  if (req.method === "POST" && m[2] === "leave") {
381
394
  await mutate((svc, reg) => {
395
+ const room = svc.getRoom(roomId);
382
396
  const entry = reg[roomId]?.[sessionID];
383
- const participantId = svc.getRoom(roomId).kind === "direct" ? sessionID : entry?.name ?? sessionID;
397
+ const participantId = room.kind === "direct" ? sessionID : entry?.name ?? sessionID;
384
398
  // ponytail: orc-2 #2——共享名守卫:还有别的 session 持有同名时,
385
399
  // 只移除本 entry,不移除参与者(否则兄弟 tab 发送会 NOT_JOINED)
386
400
  const shared = Object.entries(reg[roomId] ?? {}).some(
@@ -396,6 +410,22 @@ async function handle(req: Request): Promise<Response> {
396
410
  delete reg[roomId];
397
411
  }
398
412
  }
413
+ // A departing delegated admin passes the role to the room's explicit successor.
414
+ if (entry?.name && room.ownerId && (room.adminIds ?? []).includes(entry.name)) {
415
+ const successor = Object.values(reg[roomId] ?? {}).find((candidate) =>
416
+ isUser(candidate) && (room.successorMembershipID ? candidate.membershipID === room.successorMembershipID : candidate.name === room.successorId));
417
+ if (successor?.name && successor.name !== room.ownerId) {
418
+ room.adminIds = [...new Set([...(room.adminIds ?? []).filter((name) => name !== successor.name), successor.name])];
419
+ if (successor.membershipID) room.adminMembershipIDs = [...new Set([...(room.adminMembershipIDs ?? []).filter((id) => id !== successor.membershipID), successor.membershipID])];
420
+ }
421
+ }
422
+ if (entry && (room.successorMembershipID ? entry.membershipID === room.successorMembershipID : entry.name === room.successorId)) {
423
+ delete room.successorId;
424
+ delete room.successorMembershipID;
425
+ }
426
+ // A departing owner hands the room to the next person; the last one leaves it open.
427
+ settleAdmins(svc.getRoom(roomId), reg[roomId] ?? {});
428
+ settleOwner(svc.getRoom(roomId), reg[roomId] ?? {});
399
429
  });
400
430
  return json({ ok: true });
401
431
  }
@@ -503,7 +533,7 @@ async function handle(req: Request): Promise<Response> {
503
533
  if (err instanceof RoomError) {
504
534
  return json(
505
535
  { error: err.message },
506
- err.code === "ROOM_NOT_FOUND" ? 404 : 409,
536
+ err.code === "ROOM_NOT_FOUND" ? 404 : err.code === "NOT_OWNER" ? 403 : 409,
507
537
  );
508
538
  }
509
539
  return json({ error: err instanceof Error ? err.message : String(err) }, 500);