@alexsun-top/opencode-chat-room 0.6.1 → 0.6.2
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.
- package/CHANGELOG.md +7 -0
- package/README.md +2 -0
- package/README.zh-CN.md +2 -0
- package/package.json +1 -1
- package/server/assets/chat/events.js +18 -78
- package/server/assets/chat/messages.js +1 -1
- package/server/assets/chat/rooms.js +3 -6
- package/server/assets/responsive.css +4 -4
- package/server/chat.html +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.2 — 2026-11-15
|
|
4
|
+
|
|
5
|
+
- Opening a room always lands on the live bottom, including when the previous visit ended mid-history. The saved-position and first-unread landing are gone; they reopened rooms above messages the reader had already seen.
|
|
6
|
+
- Treat a thread within 80px of the bottom as the bottom when saving the position, following new messages, and restoring layout after an image expands, matching the read and jump-to-latest thresholds.
|
|
7
|
+
- On phones, put the room name and the action buttons on separate header rows so a long title is no longer squeezed to a few characters.
|
|
8
|
+
- Give the Reminders button its bell icon on phones instead of an empty circle, and open every header panel below the header with 12px side margins so no panel runs off screen.
|
|
9
|
+
|
|
3
10
|
## 0.6.1 — 2026-11-14
|
|
4
11
|
|
|
5
12
|
- Keep the thread pinned to the bottom when images finish loading after a room opens, without yanking a reader who scrolled up into history.
|
package/README.md
CHANGED
|
@@ -17,6 +17,8 @@ Install [Bun](https://bun.sh), then add the plugin to `~/.config/opencode/openco
|
|
|
17
17
|
|
|
18
18
|
Restart OpenCode. Ask an agent to create a room named `dev`, or enter `/room create dev`.
|
|
19
19
|
|
|
20
|
+
When upgrading an existing install, quit OpenCode first or use `opencode plugin add @alexsun-top/opencode-chat-room@<version>`. Editing the version in `opencode.json` while the host is running can leave an empty package directory under `~/.cache/opencode/npm/`, which makes the plugin fail to load. Delete that directory and run `opencode plugin add` again to recover.
|
|
21
|
+
|
|
20
22
|
## 2. Connect multiple devices
|
|
21
23
|
|
|
22
24
|
On a machine reachable by the other devices, start the server. Replace `your-password` with a shared password:
|
package/README.zh-CN.md
CHANGED
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
|
|
18
18
|
重启 OpenCode。现在你可以让 Agent「创建一个叫 dev 的聊天室」,或输入 `/room create dev`。
|
|
19
19
|
|
|
20
|
+
升级已有安装时,先退出 OpenCode,或使用 `opencode plugin add @alexsun-top/opencode-chat-room@<版本>`。在宿主运行中直接改 `opencode.json` 里的版本号,可能在 `~/.cache/opencode/npm/` 下留下空目录,导致插件加载失败。遇到时删掉该空目录,再执行一次 `opencode plugin add`。
|
|
21
|
+
|
|
20
22
|
## 2. 多台设备一起使用
|
|
21
23
|
|
|
22
24
|
在一台可被其他设备访问的机器上启动服务器,把 `换成自己的密码` 换成共享密码:
|
package/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { LS } from "./state.js";
|
|
2
2
|
import { copyTextToClipboard } from "./markdown.js";
|
|
3
|
-
import { isUnreadMessage } from "./messages.js";
|
|
4
3
|
|
|
5
4
|
export function initEvents(app) {
|
|
6
5
|
const $ = app.$;
|
|
@@ -13,6 +12,13 @@ export function initEvents(app) {
|
|
|
13
12
|
$("#msgInput").focus({ preventScroll: true });
|
|
14
13
|
};
|
|
15
14
|
document.addEventListener("click", () => requestAnimationFrame(() => app.focusComposer?.()));
|
|
15
|
+
// Mobile panels sit below the header, whose height depends on the title and locale.
|
|
16
|
+
const chatHead = document.querySelector("#chatView > .chat-head");
|
|
17
|
+
if (chatHead) {
|
|
18
|
+
const syncHeadBottom = () => document.documentElement.style.setProperty("--chat-head-bottom", `${Math.round(chatHead.getBoundingClientRect().bottom + 8)}px`);
|
|
19
|
+
new ResizeObserver(syncHeadBottom).observe(chatHead);
|
|
20
|
+
syncHeadBottom();
|
|
21
|
+
}
|
|
16
22
|
app.showRestoreFailure = (message) => {
|
|
17
23
|
document.documentElement.classList.add("session-restore");
|
|
18
24
|
$("#joinView").hidden = $("#chatView").hidden = true;
|
|
@@ -28,7 +34,7 @@ export function initEvents(app) {
|
|
|
28
34
|
const thread = $("#thread"), edge = thread.getBoundingClientRect(), top = edge.top + thread.clientTop;
|
|
29
35
|
const anchor = [...$("#msgList").querySelectorAll("[data-msg-id]")].find((row) => row.getBoundingClientRect().bottom > top);
|
|
30
36
|
readingPosition = { roomId: app.state.room?.id, messageId: anchor?.dataset.msgId, offset: anchor ? anchor.getBoundingClientRect().top - top : 0,
|
|
31
|
-
atBottom: thread.scrollHeight - thread.scrollTop - thread.clientHeight <=
|
|
37
|
+
atBottom: thread.scrollHeight - thread.scrollTop - thread.clientHeight <= 80 };
|
|
32
38
|
const guard = app.state.readAnchorGuard;
|
|
33
39
|
let missing = guard?.roomId === readingPosition.roomId && guard.missing;
|
|
34
40
|
// A failed restore keeps its anchor while the landing stays put; scrolling to a
|
|
@@ -65,29 +71,13 @@ export function initEvents(app) {
|
|
|
65
71
|
layoutQueue = task.catch(() => {});
|
|
66
72
|
return task;
|
|
67
73
|
};
|
|
68
|
-
app.restoreReadingPosition = (
|
|
69
|
-
const thread = $("#thread")
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
captureReadingPosition(); return true;
|
|
76
|
-
};
|
|
77
|
-
if (typeof saved === "number") { thread.scrollTop = saved; captureReadingPosition(); return { messageId: readingPosition?.messageId, atBottom: atBottom() }; }
|
|
78
|
-
const readTs = entry?.readTs || app.state.lastReadTs.get(roomId) || 0;
|
|
79
|
-
// Own messages never form an unread boundary; landing on them hides the newest activity.
|
|
80
|
-
const boundary = readTs && entry?.room.messages.find((message) => message.createdAt > readTs && isUnreadMessage(message, app, entry.room, entry.name));
|
|
81
|
-
// Leaving at the bottom and returning to new messages lands on the first unread;
|
|
82
|
-
// a deliberate scroll position is restored exactly.
|
|
83
|
-
if ((entry?.unreadIds.size || entry?.unreadOverflow) && saved?.atBottom !== false && boundary && align(boundary.id, 0)) return { messageId: boundary.id, atBottom: atBottom() };
|
|
84
|
-
// Left at the bottom with nothing unread: land on the live bottom, not the
|
|
85
|
-
// old anchor — late-loading cards can grow content below the saved row.
|
|
86
|
-
if (saved?.atBottom === true && !entry?.unreadIds.size && !entry?.unreadOverflow) { thread.scrollTop = thread.scrollHeight; captureReadingPosition(); return { messageId: readingPosition?.messageId, atBottom: atBottom() }; }
|
|
87
|
-
if (saved?.messageId && align(saved.messageId, Number(saved.offset) || 0)) return { messageId: saved.messageId, atBottom: atBottom() };
|
|
88
|
-
if (boundary && align(boundary.id, 0)) return { messageId: boundary.id, atBottom: atBottom() };
|
|
89
|
-
if (!saved && !boundary) return false;
|
|
90
|
-
return saved?.messageId || readTs ? { messageId: saved?.messageId || null, missing: true } : false;
|
|
74
|
+
app.restoreReadingPosition = () => {
|
|
75
|
+
const thread = $("#thread");
|
|
76
|
+
// Entering a room always shows the newest messages. Restoring an old anchor
|
|
77
|
+
// leaves the reader above messages that already arrived or grew afterwards.
|
|
78
|
+
thread.scrollTop = thread.scrollHeight;
|
|
79
|
+
captureReadingPosition();
|
|
80
|
+
return { messageId: readingPosition?.messageId, atBottom: true };
|
|
91
81
|
};
|
|
92
82
|
function closeRoomDrawer(restore = true) {
|
|
93
83
|
roomRail.classList.remove("drawer-open"); roomRail.inert = true; roomRail.setAttribute("aria-hidden", "true");
|
|
@@ -136,38 +126,10 @@ export function initEvents(app) {
|
|
|
136
126
|
backdrop.addEventListener("click", () => closeRoomDrawer());
|
|
137
127
|
$("#roomListChat").addEventListener("click", (event) => { if (roomRail.classList.contains("drawer-open") && event.target.closest("[data-room-id]")) closeRoomDrawer(); });
|
|
138
128
|
const activateRoom = app.activateRoom;
|
|
139
|
-
const pendingAnchorLoads = new Map();
|
|
140
|
-
function cancelAnchorLoads() {
|
|
141
|
-
for (const { controller } of pendingAnchorLoads.values()) controller.abort();
|
|
142
|
-
pendingAnchorLoads.clear();
|
|
143
|
-
}
|
|
144
|
-
const showJoin = app.showJoin;
|
|
145
|
-
app.showJoin = (...args) => { cancelAnchorLoads(); return showJoin(...args); };
|
|
146
|
-
const removeJoinedRoom = app.removeJoinedRoom;
|
|
147
|
-
app.removeJoinedRoom = (roomId, options) => {
|
|
148
|
-
if (app.state.room?.id === roomId) cancelAnchorLoads();
|
|
149
|
-
return removeJoinedRoom(roomId, options);
|
|
150
|
-
};
|
|
151
|
-
function activateNow(id, preserveRoomListGeneration = false) {
|
|
152
|
-
activateRoom(id, preserveRoomListGeneration); captureReadingPosition();
|
|
153
|
-
if (roomRail.classList.contains("drawer-open")) closeRoomDrawer();
|
|
154
|
-
}
|
|
155
129
|
app.activateRoom = (id, preserveRoomListGeneration = false) => {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
if (!entry) return activateNow(id, preserveRoomListGeneration);
|
|
160
|
-
const readTs = entry.readTs || app.state.lastReadTs.get(id) || 0;
|
|
161
|
-
const needAnchor = saved?.messageId && !entry.room.messages.some((message) => message.id === saved.messageId);
|
|
162
|
-
const latest = entry.room.messages.at(-1);
|
|
163
|
-
const needBoundary = !saved?.messageId && readTs && (!latest || latest.createdAt > readTs && !entry.room.messages.some((message) => message.createdAt <= readTs));
|
|
164
|
-
if (!needAnchor && !needBoundary) return activateNow(id, preserveRoomListGeneration);
|
|
165
|
-
const controller = new AbortController();
|
|
166
|
-
const task = loadAnchorHistory(id, entry, saved?.messageId, app, needBoundary ? readTs : 0, controller.signal).catch(() => {}).finally(() => {
|
|
167
|
-
if (pendingAnchorLoads.get(id)?.controller === controller) pendingAnchorLoads.delete(id);
|
|
168
|
-
if (intent === app.state.navigationGeneration) activateNow(id, preserveRoomListGeneration);
|
|
169
|
-
});
|
|
170
|
-
pendingAnchorLoads.set(id, { controller, task });
|
|
130
|
+
activateRoom(id, preserveRoomListGeneration);
|
|
131
|
+
captureReadingPosition();
|
|
132
|
+
if (roomRail.classList.contains("drawer-open")) closeRoomDrawer();
|
|
171
133
|
};
|
|
172
134
|
document.querySelectorAll(".locale-select").forEach((select) => {
|
|
173
135
|
select.addEventListener("change", () => {
|
|
@@ -337,28 +299,6 @@ export function initEvents(app) {
|
|
|
337
299
|
if (!$("#joinView").hidden) $("#inRoomId").focus();
|
|
338
300
|
}
|
|
339
301
|
|
|
340
|
-
async function loadAnchorHistory(roomId, entry, messageId, app, readTs = 0, signal) {
|
|
341
|
-
let beforeSeq, reachedStart = false;
|
|
342
|
-
const messages = [];
|
|
343
|
-
while (!signal?.aborted) {
|
|
344
|
-
const query = new URLSearchParams({ limit: "100" });
|
|
345
|
-
if (beforeSeq) query.set("beforeSeq", String(beforeSeq));
|
|
346
|
-
const result = await app.api(`/rooms/${encodeURIComponent(roomId)}/history?${query}`, { signal });
|
|
347
|
-
if (signal?.aborted) return;
|
|
348
|
-
messages.push(...(result.messages || []));
|
|
349
|
-
const found = messageId ? messages.some((message) => message.id === messageId)
|
|
350
|
-
: messages.some((message) => message.createdAt > readTs) && messages.some((message) => message.createdAt <= readTs);
|
|
351
|
-
if (found || !result.hasMore || !result.nextBeforeSeq || result.nextBeforeSeq === beforeSeq) { reachedStart = !result.hasMore; break; }
|
|
352
|
-
beforeSeq = result.nextBeforeSeq;
|
|
353
|
-
}
|
|
354
|
-
if (messageId ? !messages.some((message) => message.id === messageId) : !messages.some((message) => message.createdAt > readTs)) return;
|
|
355
|
-
const merged = new Map([...entry.room.messages, ...messages].map((message) => [message.id, { ...message, roomId }]));
|
|
356
|
-
entry.room.messages = [...merged.values()].sort((left, right) => left.createdAt - right.createdAt);
|
|
357
|
-
// Keep the upward-pagination cursor aligned with what the anchor load fetched.
|
|
358
|
-
if (typeof entry.room.messages[0]?.seq === "number") entry.historyBeforeSeq = entry.room.messages[0].seq;
|
|
359
|
-
if (reachedStart) entry.historyComplete = true;
|
|
360
|
-
}
|
|
361
|
-
|
|
362
302
|
function saveAccessToken(button, app) {
|
|
363
303
|
const input = document.getElementById(button.dataset.tokenSave);
|
|
364
304
|
input.value = app.setToken(input.value);
|
|
@@ -244,7 +244,7 @@ export function initMessages(app) {
|
|
|
244
244
|
|
|
245
245
|
app.renderMessages = (live = false) => {
|
|
246
246
|
const thread = $("#thread"), list = $("#msgList"), messages = app.state.room.messages;
|
|
247
|
-
const nearBottom = thread.scrollHeight - thread.scrollTop - thread.clientHeight <=
|
|
247
|
+
const nearBottom = thread.scrollHeight - thread.scrollTop - thread.clientHeight <= 80;
|
|
248
248
|
let skipped = 0;
|
|
249
249
|
let anchorId = null, anchorOffset = 0, oldTop = thread.scrollTop;
|
|
250
250
|
const viewport = thread.getBoundingClientRect();
|
|
@@ -115,7 +115,6 @@ export function initRooms(app) {
|
|
|
115
115
|
app.stopPolling();
|
|
116
116
|
app.state.room = entry.room;
|
|
117
117
|
app.state.myName = entry.name;
|
|
118
|
-
const savedPosition = app.state.positions.get(roomId);
|
|
119
118
|
app.state.unread = entry.unreadIds.size + (entry.unreadOverflow ? 100 : 0);
|
|
120
119
|
app.rendered = 0;
|
|
121
120
|
app.firstMessageId = null;
|
|
@@ -125,12 +124,10 @@ export function initRooms(app) {
|
|
|
125
124
|
app.renderHead();
|
|
126
125
|
$("#msgList").textContent = "";
|
|
127
126
|
app.renderMessages(false);
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
app.state.readAnchorGuard = restoredPosition && !restoredPosition.atBottom ? { roomId, ...restoredPosition } : null;
|
|
127
|
+
app.restoreReadingPosition?.(roomId);
|
|
128
|
+
app.state.readAnchorGuard = null;
|
|
131
129
|
app.startPolling();
|
|
132
130
|
app.renderMembers();
|
|
133
|
-
if (!restoredPosition) $("#thread").scrollTop = typeof savedPosition === "number" ? savedPosition : entry.position || $("#thread").scrollHeight;
|
|
134
131
|
$("#msgInput").contentEditable = "true";
|
|
135
132
|
$("#msgInput").setAttribute("aria-disabled", "false"); $("#msgInput").tabIndex = 0;
|
|
136
133
|
$("#msgInput").draftValue = app.state.drafts.get(roomId) || ""; app.renderReplyPreview?.();
|
|
@@ -141,7 +138,7 @@ export function initRooms(app) {
|
|
|
141
138
|
app.hideSendError();
|
|
142
139
|
app.updateBadge();
|
|
143
140
|
app.updateJump();
|
|
144
|
-
|
|
141
|
+
app.markActiveRoomRead();
|
|
145
142
|
app.renderRoomOptions($("#roomList"), app.state.availableRooms || []);
|
|
146
143
|
app.renderRoomOptions($("#roomListChat"), app.state.availableRooms || []);
|
|
147
144
|
void app.refreshRoomList();
|
|
@@ -145,20 +145,20 @@
|
|
|
145
145
|
#roomListChat .room-row { height: auto; padding: 10px 12px; }
|
|
146
146
|
#roomListChat .r-meta { font-size: 12px; }
|
|
147
147
|
#roomListChat .r-preview { display: block; }
|
|
148
|
-
#chatView > .chat-head { grid-column: 1; grid-row: 1; flex-wrap:
|
|
148
|
+
#chatView > .chat-head { grid-column: 1; grid-row: 1; flex-wrap: wrap; align-items: center; padding: 9px 12px; gap: 6px; }
|
|
149
149
|
#chatView > .conn-bar { grid-column: 1; grid-row: 2; }
|
|
150
150
|
#chatView > .msg-scroll { grid-column: 1; grid-row: 3; }
|
|
151
151
|
#chatView > .composer { grid-column: 1; grid-row: 4; }
|
|
152
|
-
.chat-head-actions { flex:
|
|
152
|
+
.chat-head-actions { flex: 1 1 100%; flex-wrap: nowrap; justify-content: flex-end; gap: 6px; }
|
|
153
153
|
.chat-head-actions > .locale-control { display: none; }
|
|
154
|
-
.chat-head-main { flex: 1
|
|
154
|
+
.chat-head-main { flex: 1 1 100%; min-width: 0; }
|
|
155
155
|
.room-title-row { gap: 6px; }
|
|
156
156
|
.chat-head-main h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 18px; }
|
|
157
157
|
.chat-head .chip { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; font-size: 0; }
|
|
158
158
|
#chatView > .chat-head .action-icon { display: block; }
|
|
159
159
|
.rooms-drawer-trigger { display: grid; flex: none; }
|
|
160
160
|
#btnQuestions .question-badge { position: absolute; top: -5px; right: -5px; margin: 0; font-size: 10px; }
|
|
161
|
-
#questionPanel, #announcementPanel { position: fixed; top:
|
|
161
|
+
#questionPanel, #announcementPanel, #reminderPanel, #memberPanel, #roomOptions { position: fixed; top: var(--chat-head-bottom, 116px); left: 12px; right: 12px; width: auto; max-height: calc(100dvh - 132px); overflow: auto; }
|
|
162
162
|
.room-options-panel { right: 0; left: auto; }
|
|
163
163
|
.thread { padding: 14px 12px 6px; }
|
|
164
164
|
.msg-text { max-width: 92%; font-size: 15px; }
|
package/server/chat.html
CHANGED
|
@@ -139,7 +139,7 @@
|
|
|
139
139
|
</section>
|
|
140
140
|
</div>
|
|
141
141
|
<div class="anchor">
|
|
142
|
-
<button class="chip" type="button" id="btnReminders" aria-haspopup="true" aria-expanded="false" aria-controls="reminderPanel"><span class="action-label" data-i18n="reminders">Reminders</span></button>
|
|
142
|
+
<button class="chip" type="button" id="btnReminders" aria-haspopup="true" aria-expanded="false" aria-controls="reminderPanel"><svg class="action-icon" aria-hidden="true" viewBox="0 0 24 24"><path d="M18 8a6 6 0 1 0-12 0c0 7-3 7-3 9h18c0-2-3-2-3-9"/><path d="M10 21a2 2 0 0 0 4 0"/></svg><span class="action-label" data-i18n="reminders">Reminders</span></button>
|
|
143
143
|
<section class="panel reminder-panel" id="reminderPanel" aria-labelledby="reminderHeading" hidden>
|
|
144
144
|
<div class="announcement-head"><h3 id="reminderHeading" tabindex="-1" data-i18n="reminders">Reminders</h3><button type="button" id="btnRefreshReminders" class="question-refresh" data-i18n="refreshQuestions">Refresh</button></div>
|
|
145
145
|
<p id="reminderStatus" class="hint" role="status" aria-live="polite"></p><ul id="reminderList" class="reminder-list"></ul>
|