@alexsun-top/opencode-chat-room 0.3.3 → 0.4.0

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.
@@ -0,0 +1,112 @@
1
+ export function initReceipts(app) {
2
+ const $ = app.$, panel = $("#readerPanel");
3
+ let selectedID = "", trigger = null;
4
+ app.createReceiptButton = (message, own) => {
5
+ const button = document.createElement("button");
6
+ button.type = "button";
7
+ button.className = "message-readers";
8
+ button.dataset.messageId = message.id;
9
+ button.dataset.ownMessage = String(own);
10
+ button.setAttribute("aria-haspopup", "true");
11
+ button.setAttribute("aria-controls", "readerPanel");
12
+ updateButton(button, message, own);
13
+ return button;
14
+ };
15
+ app.renderReceiptData = (roomId, receipts) => {
16
+ const thread = $("#thread"), edge = thread.getBoundingClientRect();
17
+ const atBottom = thread.scrollHeight - thread.scrollTop - thread.clientHeight <= 2;
18
+ const anchor = [...$("#msgList").querySelectorAll("[data-msg-id]")].find((node) => node.getBoundingClientRect().bottom > edge.top);
19
+ const anchorId = anchor?.dataset.msgId, anchorTop = anchor ? anchor.getBoundingClientRect().top - edge.top : 0;
20
+ for (const receipt of receipts) app.state.receipts.set(`${roomId}\0${receipt.messageID}`, receipt.readers);
21
+ for (const button of $("#msgList").querySelectorAll(".message-readers")) {
22
+ const message = app.state.room?.messages.find((item) => item.id === button.dataset.messageId);
23
+ if (message) updateButton(button, message);
24
+ }
25
+ if (atBottom) thread.scrollTop = thread.scrollHeight;
26
+ else if (anchorId) {
27
+ const next = $("#msgList").querySelector(`[data-msg-id="${CSS.escape(anchorId)}"]`);
28
+ if (next) thread.scrollTop += next.getBoundingClientRect().top - thread.getBoundingClientRect().top - anchorTop;
29
+ }
30
+ if (selectedID) renderPanel();
31
+ };
32
+ $("#msgList").addEventListener("click", (event) => {
33
+ const button = event.target.closest(".message-readers");
34
+ if (!button) return;
35
+ if (selectedID === button.dataset.messageId) close(true);
36
+ else open(button.dataset.messageId, button);
37
+ });
38
+ $("#btnCloseReaders").addEventListener("click", () => close(true));
39
+ document.addEventListener("click", (event) => {
40
+ if (selectedID && !event.target.closest("#readerPanel, .message-readers")) close(false);
41
+ });
42
+ document.addEventListener("keydown", (event) => {
43
+ if (event.key === "Escape" && selectedID) { event.preventDefault(); close(true); }
44
+ });
45
+
46
+ function open(id, button) {
47
+ selectedID = id; trigger = button;
48
+ button.setAttribute("aria-expanded", "true");
49
+ preservePosition(() => {
50
+ $("#chatView").classList.add("reader-open"); panel.hidden = false; renderPanel();
51
+ }, () => $("#btnCloseReaders").focus());
52
+ }
53
+ function close(restoreFocus) {
54
+ if (!selectedID) return;
55
+ const previous = trigger;
56
+ selectedID = ""; trigger = null;
57
+ previous?.setAttribute("aria-expanded", "false");
58
+ preservePosition(() => {
59
+ panel.hidden = true; $("#chatView").classList.remove("reader-open");
60
+ }, () => { if (restoreFocus && previous?.isConnected) previous.focus({ preventScroll: true }); });
61
+ }
62
+ function preservePosition(change, after) {
63
+ const thread = $("#thread"), edge = thread.getBoundingClientRect();
64
+ const anchor = [...$("#msgList").querySelectorAll("[data-msg-id]")].find((node) => node.getBoundingClientRect().bottom > edge.top);
65
+ const id = anchor?.dataset.msgId, top = anchor?.getBoundingClientRect().top;
66
+ change();
67
+ requestAnimationFrame(() => {
68
+ const next = id && $("#msgList").querySelector(`[data-msg-id="${CSS.escape(id)}"]`);
69
+ if (next) thread.scrollTop += next.getBoundingClientRect().top - top;
70
+ after();
71
+ });
72
+ }
73
+ function renderPanel() {
74
+ const message = app.state.room?.messages.find((item) => item.id === selectedID);
75
+ if (!message) return close(false);
76
+ const readers = readersFor(message);
77
+ $("#readerHeading").textContent = app.t("readerPanelTitle");
78
+ $("#readerCount").textContent = readerStatus(message, readers);
79
+ $("#readerExcerpt").textContent = message.text;
80
+ const list = $("#readerList"); list.textContent = "";
81
+ const members = app.state.memberSessions.get(app.state.room.id) || [];
82
+ for (const reader of readers) {
83
+ const row = document.createElement("li"), name = document.createElement("span"), evidence = document.createElement("span");
84
+ const duplicates = members.filter((member) => member.name === reader.name).length > 1 || readers.filter((item) => item.name === reader.name).length > 1;
85
+ name.textContent = `${reader.name}${duplicates ? ` · ${reader.sessionID.slice(0, 8)}` : ""}${reader.currentMember === false ? ` · ${app.t("departedMember")}` : ""}`;
86
+ evidence.textContent = app.t(`receiptEvidence_${reader.evidence}`);
87
+ row.dataset.readerSessionId = reader.sessionID;
88
+ row.append(name, evidence); list.append(row);
89
+ }
90
+ }
91
+ function updateButton(button, message, own = button.dataset.ownMessage === "true") {
92
+ const readers = readersFor(message), count = readers.length, known = hasReceiptData(message);
93
+ const label = readerStatus(message, readers);
94
+ button.hidden = !own && count === 0;
95
+ button.textContent = String(count || (known ? 0 : "…"));
96
+ button.dataset.readerState = count ? "read" : known ? "empty" : "unknown";
97
+ button.setAttribute("aria-label", label);
98
+ button.setAttribute("aria-expanded", String(selectedID === message.id));
99
+ button.title = label;
100
+ }
101
+ function readersFor(message) {
102
+ const key = receiptKey(message);
103
+ const senderID = message.senderSessionID || (app.state.room?.kind === "direct" ? message.senderId : "");
104
+ return (app.state.receipts.get(key) || []).filter((reader) => reader.sessionID !== senderID);
105
+ }
106
+ function hasReceiptData(message) { return app.state.receipts.has(receiptKey(message)); }
107
+ function receiptKey(message) { return `${app.state.room?.id || message.roomId || ""}\0${message.id}`; }
108
+ function readerStatus(message, readers) {
109
+ if (readers.length) return app.t("receiptCount", { count: readers.length });
110
+ return app.t(hasReceiptData(message) ? "receiptNone" : "receiptNotLoaded");
111
+ }
112
+ }
@@ -180,8 +180,8 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
180
180
 
181
181
  const messages = {
182
182
  en: {
183
- brand: "Casual Chat", documentTitle: "Casual Chat · Lightweight Chatroom",
184
- roomTitle: ({ name }) => `${name} · Casual Chat`,
183
+ brand: "OC Chat", documentTitle: "OC Chat",
184
+ roomTitle: ({ name }) => `${name} · OC Chat`,
185
185
  tagline: "A lightweight chat room. Enter a room ID to join, or create a new one.",
186
186
  languageLabel: "Language", roomIdLabel: "Room ID", roomIdPlaceholder: "Paste or enter a room ID",
187
187
  nameLabel: "Your name", namePlaceholder: "What should we call you?", joinRoom: "Join room",
@@ -193,6 +193,12 @@ const messages = {
193
193
  newRoom: "Create a room",
194
194
  copyRoomIdTitle: ({ id }) => `Click to copy the full room ID: ${id}`, copied: "Copied",
195
195
  members: "Members", membersCount: ({ count }) => `Members (${count})`, noMembers: "No members yet.",
196
+ questions: "Questions", pendingQuestions: "Pending questions", refreshQuestions: "Refresh",
197
+ questionsLoading: "Loading questions…", questionsEmpty: "No unanswered questions.",
198
+ questionsFailed: "Could not load questions. Try again.", questionLabel: "Question",
199
+ answerQuestion: "Reply", answerPlaceholder: "Write a reply…", sendAnswer: "Send reply",
200
+ answerFailed: "Reply failed. Your draft is still here.", questionAlreadyAnswered: "This question was answered elsewhere.",
201
+ sendAsQuestion: "Send as a question",
196
202
  settings: "Settings", tokenRequired: "The server requires an access token (401).",
197
203
  leave: "Leave", reconnecting: "Connection lost. Retrying…", messageList: "Message list",
198
204
  noMessages: "No messages yet. Say something.", latestMessages: "Back to latest messages",
@@ -225,11 +231,11 @@ const messages = {
225
231
  systemJoined: ({ name }) => `${name} joined the room`, systemLeft: ({ name }) => `${name} left the room`, systemRemoved: ({ name }) => `${name} was removed from the room`,
226
232
  activity_working: "Working", activity_idle: "Foreground idle", activity_waiting: "Waiting", activity_unknown: "Status unknown", activity_offline: "Status stale",
227
233
  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.",
228
- receiptCount: ({ count }) => `Read by ${count}`, departedMember: "left",
234
+ receiptCount: ({ count }) => `Read by ${count}`, receiptNone: "No readers yet", receiptNotLoaded: "Read status not loaded", readerPanelTitle: "Message readers", close: "Close", departedMember: "left",
229
235
  receiptEvidence_displayed: "Shown on screen", receiptEvidence_tool: "Fetched with room tool", receiptEvidence_context: "Full message reached agent context preparation (not proof of understanding)",
230
236
  },
231
237
  "zh-CN": {
232
- brand: "闲叙", documentTitle: "闲叙 · 轻量聊天室", roomTitle: ({ name }) => `${name} · 闲叙`,
238
+ brand: "OC Chat", documentTitle: "OC Chat", roomTitle: ({ name }) => `${name} · OC Chat`,
233
239
  tagline: "一个轻量的聊天房间。输入房间 ID 加入,或直接新建一个。", languageLabel: "语言",
234
240
  roomIdLabel: "房间 ID", roomIdPlaceholder: "粘贴或输入房间 ID", nameLabel: "你的昵称",
235
241
  namePlaceholder: "怎么称呼你", joinRoom: "加入房间", or: "或", newRoomNameLabel: "新房间名称",
@@ -240,6 +246,12 @@ const messages = {
240
246
  newRoom: "创建房间",
241
247
  copyRoomIdTitle: ({ id }) => `点击复制完整房间 ID:${id}`, copied: "已复制", members: "成员",
242
248
  membersCount: ({ count }) => `成员 ${count}`, noMembers: "暂无成员", settings: "设置",
249
+ questions: "提问", pendingQuestions: "待回答的问题", refreshQuestions: "刷新",
250
+ questionsLoading: "正在加载问题…", questionsEmpty: "没有待回答的问题。",
251
+ questionsFailed: "无法加载问题,请重试。", questionLabel: "问题",
252
+ answerQuestion: "回复", answerPlaceholder: "写下回复…", sendAnswer: "发送回复",
253
+ answerFailed: "回复失败,草稿仍已保留。", questionAlreadyAnswered: "此问题已由其他人回答。",
254
+ sendAsQuestion: "作为问题发送",
243
255
  tokenRequired: "服务器要求访问令牌(401)。", leave: "离开", reconnecting: "连接中断,正在重试…",
244
256
  messageList: "消息列表", noMessages: "还没有消息,说点什么吧。", latestMessages: "回到最新消息",
245
257
  mentionMembers: "选择要提及的成员", messagePlaceholder: "输入消息,Enter 发送,Shift+Enter 换行",
@@ -267,7 +279,7 @@ const messages = {
267
279
  systemJoined: ({ name }) => `${name} 加入了房间`, systemLeft: ({ name }) => `${name} 离开了房间`, systemRemoved: ({ name }) => `${name} 被移出了房间`,
268
280
  activity_working: "工作中", activity_idle: "前台空闲", activity_waiting: "等待中", activity_unknown: "状态未知", activity_offline: "状态已过期",
269
281
  activityHint_working: "Agent 正在报告工作状态。", activityHint_idle: "前台空闲;后台任务仍可能继续。", activityHint_waiting: "Agent 正在报告等待状态。", activityHint_unknown: "暂无活动状态报告。", activityHint_offline: "最近的状态已过期;这不能证明 Agent 已离线。",
270
- receiptCount: ({ count }) => `已读 ${count} 人`, departedMember: "已离开",
282
+ receiptCount: ({ count }) => `已读 ${count} 人`, receiptNone: "尚无人已读", receiptNotLoaded: "尚未加载已读状态", readerPanelTitle: "消息已读情况", close: "关闭", departedMember: "已离开",
271
283
  receiptEvidence_displayed: "已显示在屏幕上", receiptEvidence_tool: "通过房间工具读取", receiptEvidence_context: "完整消息已进入 Agent 上下文准备阶段(不代表已理解)",
272
284
  },
273
285
  };
@@ -8,8 +8,8 @@
8
8
  border-bottom: 1px solid var(--line);
9
9
  background: var(--surface);
10
10
  }
11
- .chat-head-main h1 { margin: 0; font-family: var(--font-serif); font-size: 19px; letter-spacing: .02em; }
12
- .room-meta { margin: 2px 0 0; font-size: 12px; color: var(--ink-3); }
11
+ .chat-head-main h1 { margin: 0; font-family: var(--font-sans); font-size: 20px; font-weight: 650; line-height: 1.25; letter-spacing: -.02em; }
12
+ .room-meta { margin: 2px 0 0; font-size: 13px; color: var(--ink-2); }
13
13
  .mono { font-family: var(--font-mono); }
14
14
  .copy-id {
15
15
  appearance: none;
@@ -29,10 +29,25 @@
29
29
  .copy-id.copied .copy-ok { display: inline; color: var(--accent); }
30
30
 
31
31
  .chat-head-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
32
+ .question-panel { width: min(390px, calc(100vw - 32px)); max-height: min(70vh, 620px); overflow: auto; }
33
+ .questions-trigger { position: relative; }
34
+ .question-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
35
+ .question-panel-head h3 { margin-bottom: 0; }
36
+ .question-refresh { border: 0; padding: 4px 7px; color: var(--accent); background: transparent; font: inherit; font-size: 12px; cursor: pointer; }
37
+ .question-list { list-style: none; max-height: 260px; overflow: auto; margin: 10px 0 0; padding: 0; }
38
+ .question-item { width: 100%; padding: 9px 10px; border: 1px solid transparent; border-radius: 9px; color: var(--ink); background: transparent; font: inherit; font-size: 13px; line-height: 1.5; text-align: left; overflow-wrap: anywhere; cursor: pointer; }
39
+ .question-item:hover, .question-item[aria-pressed="true"] { border-color: color-mix(in srgb, var(--accent) 30%, var(--line)); background: var(--accent-soft); }
40
+ .question-reply { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
41
+ .question-reply-quote { max-height: 72px; overflow: auto; margin: 0 0 8px; padding: 8px 10px; border-left: 3px solid var(--accent); border-radius: 4px; background: var(--surface-2); font-size: 12px; overflow-wrap: anywhere; }
42
+ .question-reply-form { display: grid; gap: 8px; }
43
+ .question-reply-form textarea { min-height: 62px; resize: vertical; }
44
+ .question-reply-form .btn { justify-self: end; }
45
+ .question-badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; margin-left: 5px; padding: 0 4px; border-radius: 99px; background: var(--accent); color: var(--accent-ink); font-size: 10px; }
32
46
  .chip {
33
47
  appearance: none;
34
48
  font: inherit;
35
49
  font-size: 13px;
50
+ line-height: 1.25;
36
51
  font-weight: 600;
37
52
  color: var(--ink-2);
38
53
  background: var(--surface);
@@ -77,6 +92,7 @@
77
92
  #memberList .member-activity + .member-actions { grid-column: 2; grid-row: 2; }
78
93
  #memberList .member-action { white-space: normal; }
79
94
  #memberList li:last-child { border-bottom: none; }
95
+ #chatSettings [data-i18n="privacyNote"] { min-height: 63px; line-height: 21px; }
80
96
  .m-time { font-size: 11.5px; color: var(--ink-3); }
81
97
  .member-activity { flex: none; padding: 2px 6px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); font-size: 10px; }
82
98
  .member-activity.working { color: var(--accent); background: var(--accent-soft); }
@@ -164,24 +180,26 @@
164
180
  .msg.own { align-items: flex-end; }
165
181
  .msg.repeat { margin-bottom: 8px; }
166
182
  .msg-meta { display: flex; align-items: baseline; gap: 8px; margin-bottom: 3px; }
167
- .msg-name { font-size: 13px; font-weight: 600; color: var(--ink); }
183
+ .msg-name { font-size: 14px; font-weight: 600; color: var(--ink); }
168
184
  .msg.own .msg-name { color: var(--accent); }
185
+ .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; }
169
186
  .msg.repeat .msg-name { display: none; }
170
- .msg-time { font-size: 11.5px; color: var(--ink-3); }
187
+ .msg-time { font-size: 12px; color: var(--ink-2); }
171
188
  .msg-text {
172
189
  display: inline-block;
190
+ width: max-content;
173
191
  max-width: min(86%, 540px);
174
192
  padding: 8px 12px;
175
193
  border-radius: 14px;
176
194
  background: var(--surface-2);
177
195
  border-bottom-left-radius: 4px;
178
- font-size: 15px;
179
- line-height: 1.65;
196
+ font-size: 16px;
197
+ line-height: 1.6;
180
198
  white-space: normal;
181
199
  overflow-wrap: anywhere;
182
200
  }
183
201
  .msg.own .msg-text { background: var(--accent-soft); border-bottom-left-radius: 14px; border-bottom-right-radius: 4px; }
184
- .msg-content { position: relative; display: flex; align-items: flex-end; gap: 6px; width: fit-content; max-width: 100%; }
202
+ .msg-content { position: relative; display: flex; align-items: flex-end; gap: 6px; width: 100%; max-width: 100%; }
185
203
  .msg.own .msg-content { flex-direction: row-reverse; }
186
204
  .message-copy {
187
205
  align-self: flex-start;
@@ -198,15 +216,21 @@
198
216
  .msg.own .message-copy { align-self: flex-end; margin-right: 4px; }
199
217
  .message-copy:hover, .message-copy:focus-visible { color: var(--ink); background: var(--surface-2); }
200
218
  .message-copy:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
201
- .message-readers { position: static; flex: 0 0 22px; margin: 0 0 4px; color: var(--ink-3); font-size: 11px; }
202
- .message-readers summary { display: grid; place-items: center; width: 22px; height: 22px; box-sizing: border-box; border: 1px solid var(--line); border-radius: 50%; background: var(--surface); cursor: pointer; list-style: none; }
203
- .message-readers summary::-webkit-details-marker { display: none; }
204
- .message-readers summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
205
- .receipt-reader-list { position: absolute; z-index: 5; left: 0; top: 100%; min-width: min(210px, calc(100vw - 32px)); max-width: calc(100vw - 24px); box-sizing: border-box; margin: 4px 0 0; padding: 5px 8px; list-style: none; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
206
- .msg.own .receipt-reader-list { right: 0; left: auto; }
219
+ .message-readers { flex: 0 0 22px; align-self: flex-end; margin: 0 0 4px; padding: 0; width: 22px; height: 22px; border: 1px solid var(--line); border-radius: 50%; color: var(--ink-3); background: var(--surface); font: inherit; font-size: 10px; cursor: pointer; }
220
+ .message-readers[data-reader-state="empty"], .message-readers[data-reader-state="unknown"] { background: var(--surface-2); }
221
+ .message-readers:hover, .message-readers[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }
222
+ .message-readers:focus-visible, .reader-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
223
+ .receipt-reader-list { margin: 0; padding: 0; list-style: none; }
207
224
  .receipt-reader-list li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; }
208
225
  .receipt-reader-list li + li { margin-top: 4px; }
209
226
  .receipt-reader-list li span:last-child { color: var(--ink-3); }
227
+ .reader-panel { min-width: 0; grid-column: 3; grid-row: 2 / 5; overflow: auto; padding: 20px 16px; border-left: 1px solid var(--line); background: var(--surface); }
228
+ .reader-panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
229
+ .reader-panel-head h2 { margin: 0; font-family: var(--font-sans); font-size: 18px; font-weight: 650; letter-spacing: -.01em; }
230
+ .reader-panel-head .hint { margin: 0 0 4px; }
231
+ .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; }
232
+ .reader-excerpt { max-height: 110px; overflow: auto; margin: 16px 0; padding: 10px 12px; border-left: 3px solid var(--accent); background: var(--surface-2); font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; }
233
+ .reader-panel .receipt-reader-list li { display: grid; gap: 3px; padding: 10px 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
210
234
 
211
235
  /* Markdown content */
212
236
  .msg-text p, .msg-text pre, .msg-text blockquote, .msg-text ul, .msg-text ol { margin: 0; }
@@ -366,6 +390,8 @@
366
390
  background: var(--surface);
367
391
  }
368
392
  .composer-row { display: flex; gap: 10px; align-items: flex-end; }
393
+ .question-toggle { width: min(940px, 100%); margin: -2px auto 0; color: var(--ink-2); font-size: 12px; }
394
+ .question-toggle input { accent-color: var(--accent); vertical-align: -1px; }
369
395
  .composer .input { flex: 1; }
370
396
  .composer .input:disabled { opacity: .5; }
371
397
  #msgInput {
@@ -34,8 +34,8 @@
34
34
  background: linear-gradient(155deg, color-mix(in srgb, var(--accent) 11%, var(--surface)) 0%, var(--surface) 52%);
35
35
  border-right: 1px solid var(--line);
36
36
  }
37
- .rail-brand { display: flex; align-items: center; gap: 10px; margin: 0 0 35px 5px; font-family: var(--font-serif); font-size: 18px; font-weight: 700; letter-spacing: .04em; }
38
- .brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 11px 11px 11px 4px; background: var(--accent); color: var(--accent-ink); font: 700 17px var(--font-serif); }
37
+ .rail-brand { display: flex; align-items: center; gap: 10px; margin: 0 0 35px 5px; font-family: var(--font-sans); font-size: 18px; font-weight: 700; letter-spacing: -.02em; }
38
+ .brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 11px 11px 11px 4px; background: var(--accent); color: var(--accent-ink); font: 700 11px var(--font-sans); }
39
39
  .rail-label { display: flex; align-items: center; justify-content: space-between; margin: 0 8px 10px; color: var(--ink-3); font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
40
40
  .rail-tools { display: flex; align-items: center; gap: 7px; }
41
41
  .icon-btn { border: 0; background: transparent; color: var(--ink-2); font: inherit; font-size: 20px; cursor: pointer; }
@@ -63,6 +63,8 @@
63
63
  .msg-text { max-width: min(82%, 680px); padding: 10px 14px; }
64
64
  .composer { padding: 14px 24px calc(14px + env(safe-area-inset-bottom)); }
65
65
  .composer-row { max-width: 940px; width: 100%; margin: 0 auto; }
66
+ #chatView.reader-open { grid-template-columns: 252px minmax(0, 1fr) 320px; }
67
+ #chatView.reader-open > .chat-head { grid-column: 2 / 4; }
66
68
  .member-actions { display: flex; gap: 6px; }
67
69
  .member-action { border: 0; background: transparent; padding: 2px 4px; color: var(--accent); font: inherit; font-size: 11px; cursor: pointer; white-space: nowrap; }
68
70
  .member-action:hover { text-decoration: underline; }
@@ -94,18 +96,25 @@
94
96
  #chatView > .conn-bar { grid-column: 1; grid-row: 3; }
95
97
  #chatView > .msg-scroll { grid-column: 1; grid-row: 4; }
96
98
  #chatView > .composer { grid-column: 1; grid-row: 5; }
99
+ #chatView.reader-open { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto auto minmax(0, 1fr) minmax(140px, 34dvh) auto; }
100
+ #chatView.reader-open > .chat-head { grid-column: 1; }
101
+ #chatView.reader-open > .composer { grid-row: 6; }
102
+ .reader-panel { grid-column: 1; grid-row: 5; padding: 10px 14px; border-top: 1px solid var(--line); border-left: 0; }
103
+ .reader-excerpt { max-height: 46px; margin: 8px 0; padding: 6px 9px; }
97
104
  .chat-head-actions { flex: none; flex-wrap: nowrap; gap: 4px; }
98
105
  .chat-head-actions > .locale-control { display: none; }
99
106
  .chat-head-main { flex: 1; min-width: 0; }
100
107
  .chat-head-main h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 18px; }
101
108
  .chat-head .chip { display: grid; place-items: center; width: 34px; height: 34px; padding: 0; font-size: 0; }
109
+ #btnQuestions::before { content: "?"; font-size: 17px; }
110
+ #btnQuestions .question-badge { position: absolute; top: -5px; right: -5px; margin: 0; font-size: 10px; }
102
111
  #btnMembers::before { content: "♧"; font-size: 18px; }
103
112
  #btnSettings::before { content: "⋯"; font-size: 21px; }
104
113
  #btnDeleteRoom::before { content: "×"; font-size: 20px; }
105
114
  #btnLeave::before { content: "↪"; font-size: 17px; }
106
115
  .mobile-locale { display: block; }
107
116
  .thread { padding: 14px 12px 6px; }
108
- .msg-text { max-width: 92%; font-size: 14px; }
117
+ .msg-text { max-width: 92%; font-size: 15px; }
109
118
  .composer { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
110
119
  #msgInput { min-height: 70px; padding: 9px 11px; line-height: 1.45; }
111
120
  #btnSend { padding: 12px 15px; }
@@ -117,3 +126,8 @@
117
126
  .chat-head-actions .panel { position: fixed; top: calc(env(safe-area-inset-top) + 196px); left: 12px; right: 12px; width: auto; max-height: min(55dvh, 420px); overflow: auto; }
118
127
  .room-meta { max-width: 100px; overflow: hidden; }
119
128
  }
129
+ @media (max-width: 220px) {
130
+ #chatView > .chat-head { padding: 8px; gap: 4px; }
131
+ .chat-head-actions { gap: 2px; }
132
+ .chat-head-actions .chip { width: 28px; height: 28px; }
133
+ }
@@ -8,7 +8,7 @@ import RoomService, {
8
8
  type Message,
9
9
  type Room,
10
10
  } from "../src/room-service";
11
- import { readState, writeState, type Registry, type RegistryEntry } from "../src/store";
11
+ import { answerQuestion, readQuestions, readState, writeState, type Registry, type RegistryEntry } from "../src/store";
12
12
  import {
13
13
  admissionMatches,
14
14
  clearPendingAdmission,
@@ -273,15 +273,15 @@ async function handle(req: Request): Promise<Response> {
273
273
  if (m) {
274
274
  const roomId = decodeURIComponent(m[1]!);
275
275
  const body = (await req.json()) as Record<string, string>;
276
- const sessionID = body.sessionID ?? "";
276
+ const sessionID = typeof body.sessionID === "string" ? body.sessionID : "";
277
277
  if (req.method === "POST" && m[2] === "join") {
278
278
  if (body.protocol !== undefined && body.protocol !== "v2" || body.receiverOwnerID !== undefined && !isReceiverOwnerID(body.receiverOwnerID)) {
279
279
  return json({ error: "invalid receiver ownership" }, 400);
280
280
  }
281
281
  // ponytail: F4/F5 — names must be non-empty, and re-joining under a
282
282
  // new name must retire the old participant (no ghost members)
283
- const id = (body.participantId ?? "").trim();
284
- const name = (body.participantName ?? "").trim();
283
+ const id = typeof body.participantId === "string" ? body.participantId.trim() : "";
284
+ const name = typeof body.participantName === "string" ? body.participantName.trim() : "";
285
285
  if (!id || !name || !sessionID) {
286
286
  return json(
287
287
  { error: "participantId/participantName/sessionID are required" },
@@ -371,6 +371,8 @@ async function handle(req: Request): Promise<Response> {
371
371
  return json({ ok: true });
372
372
  }
373
373
  if (req.method === "POST" && m[2] === "messages") {
374
+ const isQuestion = (body as Record<string, unknown>).isQuestion;
375
+ if (isQuestion !== undefined && typeof isQuestion !== "boolean") return json({ error: "isQuestion must be a boolean" }, 400);
374
376
  // ponytail: F3 — mirror the plugin's zod limit at the HTTP boundary
375
377
  const text = (body.text ?? "").trim();
376
378
  if (!text) {
@@ -383,7 +385,7 @@ async function handle(req: Request): Promise<Response> {
383
385
  const senderEntry = reg[roomId]?.[sessionID];
384
386
  if (!senderEntry) throw new RoomError("NOT_JOINED", "session is not a room member");
385
387
  const sender = svc.getRoom(roomId).kind === "direct" ? sessionID : senderEntry.name;
386
- svc.sendMessage(roomId, sender, text, sessionID);
388
+ svc.sendMessage(roomId, sender, text, sessionID, isQuestion === true);
387
389
  return svc.getRoom(roomId);
388
390
  });
389
391
  touchActive(sessionID); // 发送者活跃
@@ -402,6 +404,32 @@ async function handle(req: Request): Promise<Response> {
402
404
  return json(serializeRoom(room), 201);
403
405
  }
404
406
  }
407
+ const questions = p.match(/^\/rooms\/([^/]+)\/questions$/);
408
+ if (req.method === "GET" && questions) {
409
+ const roomId = decodeURIComponent(questions[1]!);
410
+ const exists = await read((svc) => svc.listRooms().some((room) => room.id === roomId));
411
+ if (!exists) return json({ error: "room not found" }, 404);
412
+ return json({ questions: await readQuestions(roomId) });
413
+ }
414
+ const answer = p.match(/^\/rooms\/([^/]+)\/questions\/([^/]+)\/answers$/);
415
+ if (req.method === "POST" && answer) {
416
+ const roomId = decodeURIComponent(answer[1]!);
417
+ const questionID = decodeURIComponent(answer[2]!);
418
+ const body: unknown = await req.json();
419
+ if (!body || typeof body !== "object" || Array.isArray(body)) return json({ error: "sessionID and non-empty text (max 2000) are required" }, 400);
420
+ const input = body as Record<string, unknown>;
421
+ 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);
422
+ const result = await answerQuestion(roomId, questionID, input.sessionID, input.text.trim());
423
+ if (result.status === "missing") return json({ error: "room not found" }, 404);
424
+ if (result.status === "question") return json({ error: "question not found" }, 404);
425
+ if (result.status === "member") return json({ error: "session is not a room member" }, 409);
426
+ if (result.status === "answered") return json({ error: "question already answered" }, 409);
427
+ if (result.status !== "ok") return json({ error: "question not found" }, 404);
428
+ touchActive(input.sessionID);
429
+ const room = await read((svc) => svc.getRoom(roomId));
430
+ void wakeMentionedSessions(serveWakeUrl, roomId, room.name, result.answer.text, input.sessionID, result.answer);
431
+ return json({ questionID, answer: result.answer }, 201);
432
+ }
405
433
  const g = p.match(/^\/rooms\/([^/]+)$/);
406
434
  if (g && req.method === "GET") {
407
435
  const room = await read((svc) =>
package/server/chat.html CHANGED
@@ -4,7 +4,7 @@
4
4
  <meta charset="utf-8">
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
6
6
  <meta name="color-scheme" content="light dark">
7
- <title data-i18n="documentTitle">Casual Chat · Lightweight Chatroom</title>
7
+ <title data-i18n="documentTitle">OC Chat</title>
8
8
  <link rel="stylesheet" href="/assets/base.css">
9
9
  <link rel="stylesheet" href="/assets/conversation.css">
10
10
  <link rel="stylesheet" href="/assets/responsive.css">
@@ -23,7 +23,7 @@
23
23
  <option value="zh-CN">中文</option>
24
24
  </select>
25
25
  </div>
26
- <p class="wordmark" data-i18n="brand">Casual Chat</p>
26
+ <p class="wordmark" data-i18n="brand">OC Chat</p>
27
27
  <p class="tagline" data-i18n="tagline">A lightweight chat room. Enter a room ID to join, or create a new one.</p>
28
28
 
29
29
  <form id="joinForm" novalidate>
@@ -73,7 +73,7 @@
73
73
  <!-- Shared room workspace. -->
74
74
  <section id="chatView" class="view" hidden>
75
75
  <aside class="room-rail" aria-label="Rooms" data-i18n-aria-label="roomsLabel">
76
- <div class="rail-brand"><span class="brand-mark">C</span><span data-i18n="brand">Casual Chat</span></div>
76
+ <div class="rail-brand"><span class="brand-mark">OC</span><span data-i18n="brand">OC Chat</span></div>
77
77
  <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">+</button><button id="btnRefreshRooms" class="icon-btn" type="button" aria-label="Refresh rooms" data-i18n-aria-label="refreshRooms">↻</button></span></div>
78
78
  <form id="railRoomForm" class="rail-composer" hidden>
79
79
  <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>
@@ -100,6 +100,18 @@
100
100
  <option value="zh-CN">中文</option>
101
101
  </select>
102
102
  </div>
103
+ <div class="anchor questions-anchor">
104
+ <button class="chip questions-trigger" type="button" id="btnQuestions" aria-haspopup="true" aria-expanded="false" aria-controls="questionPanel">
105
+ <span data-i18n="questions">Questions</span><span id="questionBadge" class="question-badge" hidden></span>
106
+ </button>
107
+ <section class="panel question-panel" id="questionPanel" aria-labelledby="questionHeading" hidden>
108
+ <div class="question-panel-head"><h3 id="questionHeading" tabindex="-1" data-i18n="pendingQuestions">Pending questions</h3>
109
+ <button class="question-refresh" type="button" id="btnRefreshQuestions" data-i18n="refreshQuestions">Refresh</button></div>
110
+ <p id="questionStatus" class="hint" role="status" aria-live="polite" data-i18n="questionsLoading">Loading questions…</p>
111
+ <ul id="questionList" class="question-list" aria-label="Pending questions" data-i18n-aria-label="pendingQuestions"></ul>
112
+ <div id="questionReply" class="question-reply" hidden></div>
113
+ </section>
114
+ </div>
103
115
  <div class="anchor">
104
116
  <button class="chip" type="button" id="btnMembers" aria-label="Members" data-i18n-aria-label="members" aria-haspopup="true" aria-expanded="false" data-i18n="members">Members</button>
105
117
  <div class="panel" id="memberPanel" hidden>
@@ -142,6 +154,15 @@
142
154
  </button>
143
155
  </div>
144
156
 
157
+ <aside id="readerPanel" class="reader-panel" aria-labelledby="readerHeading" hidden>
158
+ <div class="reader-panel-head">
159
+ <div><p id="readerCount" class="hint"></p><h2 id="readerHeading" tabindex="-1" data-i18n="readerPanelTitle">Message readers</h2></div>
160
+ <button type="button" id="btnCloseReaders" class="reader-close" data-i18n-aria-label="close" aria-label="Close">×</button>
161
+ </div>
162
+ <blockquote id="readerExcerpt" class="reader-excerpt"></blockquote>
163
+ <ul id="readerList" class="receipt-reader-list" aria-label="Message readers" data-i18n-aria-label="readerPanelTitle"></ul>
164
+ </aside>
165
+
145
166
  <footer class="composer">
146
167
  <p id="sendError" class="send-error" role="alert" hidden></p>
147
168
  <div id="mentionPicker" class="mention-picker" role="listbox" aria-label="Choose a member to mention" data-i18n-aria-label="mentionMembers" hidden></div>
@@ -149,6 +170,7 @@
149
170
  <textarea id="msgInput" class="input" rows="1" maxlength="2000" placeholder="Type a message, Enter to send, Shift+Enter for a new line" data-i18n-placeholder="messagePlaceholder" autocomplete="off" aria-autocomplete="list" aria-controls="mentionPicker" aria-expanded="false" disabled></textarea>
150
171
  <button class="btn primary" type="button" id="btnSend" data-i18n="send" disabled>Send</button>
151
172
  </div>
173
+ <label class="question-toggle"><input id="questionToggle" type="checkbox"><span data-i18n="sendAsQuestion">Send as a question</span></label>
152
174
  <p id="draftCount" class="draft-count">0 / 2000</p>
153
175
  </footer>
154
176
  </section>
@@ -97,6 +97,7 @@ export async function centerAction(
97
97
  name?: string;
98
98
  roomId?: string;
99
99
  text?: string;
100
+ isQuestion?: boolean;
100
101
  receiverOwnerID?: string;
101
102
  protocol?: "v1" | "v2";
102
103
  },
@@ -134,10 +135,13 @@ export async function centerAction(
134
135
  return formatRoom(svcOf(room), toRoom(room));
135
136
  }
136
137
  case "join": {
138
+ if (!args.name?.trim()) {
139
+ return "error: name is required to join a room";
140
+ }
137
141
  if (!args.roomId) {
138
142
  return "error: roomId is required";
139
143
  }
140
- const me = identity(args.name?.trim());
144
+ const me = identity(args.name.trim());
141
145
  const room = await request(
142
146
  opts,
143
147
  `/rooms/${encodeURIComponent(args.roomId)}/join`,
@@ -192,7 +196,7 @@ export async function centerAction(
192
196
  opts,
193
197
  `/rooms/${encodeURIComponent(args.roomId)}/messages`,
194
198
  "POST",
195
- { sessionID, text: args.text.trim() },
199
+ { sessionID, text: args.text.trim(), ...(args.isQuestion ? { isQuestion: true } : {}) },
196
200
  );
197
201
  const svc = svcOf(room);
198
202
  return `sent: ${args.text.trim()}\n${formatRoom(svc, toRoom(room))}`;
@@ -13,6 +13,9 @@ export type Message = {
13
13
  senderSessionID?: string;
14
14
  text: string;
15
15
  createdAt: number;
16
+ isQuestion?: boolean;
17
+ answerToMessageID?: string;
18
+ answeredByMessageID?: string;
16
19
  };
17
20
 
18
21
  export type Room = {
@@ -129,6 +132,7 @@ export default class RoomService {
129
132
  senderId: string,
130
133
  text: string,
131
134
  senderSessionID?: string,
135
+ isQuestion = false,
132
136
  ): Message {
133
137
  const room = this.getRoom(roomId);
134
138
  if (!room.participants.has(senderId)) {
@@ -145,6 +149,7 @@ export default class RoomService {
145
149
  ...(senderSessionID ? { senderSessionID } : {}),
146
150
  text: trimmed,
147
151
  createdAt: Math.max(Date.now(), (room.messages.at(-1)?.createdAt ?? 0) + 1),
152
+ ...(isQuestion ? { isQuestion: true } : {}),
148
153
  };
149
154
  room.messages.push(message);
150
155
  this.trimMessages(room);