@alexsun-top/opencode-chat-room 0.6.4 → 0.6.6
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 +11 -0
- package/README.md +4 -0
- package/README.zh-CN.md +4 -0
- package/package.json +3 -1
- package/server/assets/chat/events.js +27 -9
- package/server/assets/chat/index.js +2 -0
- package/server/assets/chat/messages.js +1 -0
- package/server/assets/chat/pwa.js +18 -0
- package/server/assets/chat/replies.js +2 -0
- package/server/assets/chat/state.js +1 -1
- package/server/assets/icons/apple-touch-icon.png +0 -0
- package/server/assets/icons/icon-192.png +0 -0
- package/server/assets/icons/icon-512.png +0 -0
- package/server/chat-server.ts +20 -0
- package/server/chat.html +5 -1
- package/server/manifest.webmanifest +15 -0
- package/server/sw.js +72 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.6 — 2026-11-16
|
|
4
|
+
|
|
5
|
+
- Install the chat as an app: `/manifest.webmanifest` carries the name, icons, theme colour and `standalone` display, so a phone can add it to the home screen and open it without browser chrome.
|
|
6
|
+
- Start from the cached shell when the network is gone. A service worker precaches `/chat`, its styles, icons and the module graph it imports. Chat data is never cached: a room cannot show a deleted message or a stale unread count.
|
|
7
|
+
- Replace the worker on release: `/sw.js` carries the package version, so an upgrade installs a fresh cache, drops the old one, and the page reloads once into it.
|
|
8
|
+
|
|
9
|
+
## 0.6.5 — 2026-11-15
|
|
10
|
+
|
|
11
|
+
- Keep a room at the bottom while the reader is following it: any growth of the message list pins the view, instead of deciding from scroll events that arrive in an unpredictable order. Only the reader's own wheel, touch, key, or scrollbar drag ends following, and the view stays still while a pointer gesture or a text selection is in progress. Opening a room, jumping to the latest message, and landing after a resize still end at the bottom.
|
|
12
|
+
Known issue: the render window sometimes trims while a room is open, which opens a one-frame gap of a few hundred pixels before the next growth pins the view back. Measured once in 26 entries; the jump button never appears and the view recovers on the next frame.
|
|
13
|
+
|
|
3
14
|
## 0.6.4 — 2026-11-15
|
|
4
15
|
|
|
5
16
|
- Forbid the host's built-in question, confirmation, and approval dialogs for any agent that belongs to a room: every question and every manual step goes into the room, even when the person who must answer is the operator of the current session. Native dialogs leave no room record and only reach one human.
|
package/README.md
CHANGED
|
@@ -60,6 +60,10 @@ Pin a release with `ghcr.io/agentsyaml/opencode-chat-room:v0.5.5`. Rooms, messag
|
|
|
60
60
|
- Attach files, drag them in, or paste images. The default limit is 500 MiB per file.
|
|
61
61
|
- Agents can use the `room` tool's `read_resource` action to save an attachment to a temporary file before opening it.
|
|
62
62
|
|
|
63
|
+
### Install as an app
|
|
64
|
+
|
|
65
|
+
The web interface ships a web app manifest and a service worker, so a phone can add it to the home screen and open it without browser chrome. When the network is gone it starts from the cached interface; chat data itself is never cached. Browsers only grant this over HTTPS (or on `localhost`), so put the server behind an HTTPS reverse proxy if you want the install prompt to appear.
|
|
66
|
+
|
|
63
67
|
For OpenCode sessions on one machine, no server or environment variables are needed. The web interface and multi-machine chat require the central server.
|
|
64
68
|
|
|
65
69
|
## More help
|
package/README.zh-CN.md
CHANGED
|
@@ -59,6 +59,10 @@ docker run --rm -p 4399:4399 -v chat-room-data:/data \
|
|
|
59
59
|
- 点击附件按钮、拖入文件或粘贴图片即可分享;默认单文件上限为 500 MiB。
|
|
60
60
|
- Agent 收到附件后可通过 `room` 的 `read_resource` 操作保存到临时文件,再打开查看。
|
|
61
61
|
|
|
62
|
+
### 安装为应用
|
|
63
|
+
|
|
64
|
+
网页端带 Web App Manifest 与 Service Worker:手机可以「添加到主屏幕」,以独立窗口打开,断网时从本地缓存的界面启动。聊天数据本身不进缓存,所以不会看到过期消息。浏览器只在 HTTPS(或 `localhost`)下允许这项能力,想让安装入口出现,需要给服务端套一层 HTTPS 反向代理。
|
|
65
|
+
|
|
62
66
|
只在同一台机器的 OpenCode 会话之间聊天时,无需启动服务器或设置环境变量。网页聊天和跨机器聊天需要中心服务器。
|
|
63
67
|
|
|
64
68
|
## 更多帮助
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alexsun-top/opencode-chat-room",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
4
4
|
"description": "A chat-room plugin and central server for OpenCode.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -40,6 +40,8 @@
|
|
|
40
40
|
"server/room-reminders.ts",
|
|
41
41
|
"server/wake.ts",
|
|
42
42
|
"server/chat.html",
|
|
43
|
+
"server/manifest.webmanifest",
|
|
44
|
+
"server/sw.js",
|
|
43
45
|
"server/assets",
|
|
44
46
|
"CHANGELOG.md",
|
|
45
47
|
"docs/administrator-rooms.md",
|
|
@@ -27,15 +27,19 @@ export function initEvents(app) {
|
|
|
27
27
|
const thread = $("#thread");
|
|
28
28
|
app.state.listMetrics = { height: messageList.offsetHeight, top: thread.scrollTop, client: thread.clientHeight };
|
|
29
29
|
};
|
|
30
|
-
const wasAtBottom = () => {
|
|
31
|
-
const previous = app.state.listMetrics;
|
|
32
|
-
return previous.height - previous.top - previous.client <= 80;
|
|
33
|
-
};
|
|
34
30
|
new ResizeObserver(() => {
|
|
35
|
-
const thread = $("#thread"),
|
|
36
|
-
|
|
37
|
-
//
|
|
38
|
-
|
|
31
|
+
const thread = $("#thread"), previous = app.state.listMetrics;
|
|
32
|
+
const grew = messageList.offsetHeight > previous.height, sameBox = thread.clientHeight === previous.client;
|
|
33
|
+
// Rows arrive in bursts, so judging each burst on its own loses the reader after the
|
|
34
|
+
// first one. Follow while the reader has not scrolled away: then every growth pins.
|
|
35
|
+
// A changed viewport height (composer, window) is not list growth and keeps its anchor.
|
|
36
|
+
const selection = getSelection(), selecting = Boolean(selection && !selection.isCollapsed && messageList.contains(selection.anchorNode));
|
|
37
|
+
// A pointer held over the list is mid-gesture: dragging a selection or a click that
|
|
38
|
+
// must land where it started. Moving the content under it loses both.
|
|
39
|
+
if (grew && sameBox && app.state.followBottom && !selecting && !app.state.threadPointerDown
|
|
40
|
+
&& thread.scrollHeight - thread.scrollTop - thread.clientHeight > 1) {
|
|
41
|
+
thread.scrollTop = thread.scrollHeight;
|
|
42
|
+
}
|
|
39
43
|
rememberListMetrics();
|
|
40
44
|
}).observe(messageList);
|
|
41
45
|
app.showRestoreFailure = (message) => {
|
|
@@ -95,6 +99,7 @@ export function initEvents(app) {
|
|
|
95
99
|
// Entering a room always shows the newest messages. Restoring an old anchor
|
|
96
100
|
// leaves the reader above messages that already arrived or grew afterwards.
|
|
97
101
|
thread.scrollTop = thread.scrollHeight;
|
|
102
|
+
app.state.followBottom = true;
|
|
98
103
|
captureReadingPosition();
|
|
99
104
|
return { messageId: readingPosition?.messageId, atBottom: true };
|
|
100
105
|
};
|
|
@@ -247,11 +252,24 @@ export function initEvents(app) {
|
|
|
247
252
|
});
|
|
248
253
|
thread.addEventListener("pointerdown", (event) => {
|
|
249
254
|
if (event.clientX >= thread.getBoundingClientRect().right - 18) markScrollIntent();
|
|
255
|
+
app.state.threadPointerDown = true;
|
|
250
256
|
});
|
|
257
|
+
const releasePointer = () => { app.state.threadPointerDown = false; };
|
|
258
|
+
window.addEventListener("pointerup", releasePointer);
|
|
259
|
+
window.addEventListener("pointercancel", releasePointer);
|
|
260
|
+
window.addEventListener("blur", releasePointer);
|
|
251
261
|
thread.addEventListener("scroll", () => {
|
|
252
262
|
const adjusting = (app.state.resizeScrollAdjusting || app.state.layoutScrollAdjusting)
|
|
253
263
|
&& performance.now() > app.state.userScrollIntentUntil;
|
|
254
|
-
if (!adjusting)
|
|
264
|
+
if (!adjusting) {
|
|
265
|
+
// The growth baseline belongs to the observer alone. A scroll caused by the growth
|
|
266
|
+
// itself arrives before the observer sees the new height, and refreshing the
|
|
267
|
+
// baseline here would make that growth look like no growth at all.
|
|
268
|
+
// Only a scroll the reader started ends following; layout shifts do not.
|
|
269
|
+
const gap = thread.scrollHeight - thread.scrollTop - thread.clientHeight;
|
|
270
|
+
if (gap <= 80) app.state.followBottom = true;
|
|
271
|
+
else if (performance.now() <= app.state.userScrollIntentUntil) app.state.followBottom = false;
|
|
272
|
+
}
|
|
255
273
|
if (!adjusting || performance.now() <= app.state.userScrollIntentUntil) captureReadingPosition();
|
|
256
274
|
if (!adjusting && thread.scrollHeight - thread.scrollTop - thread.clientHeight < 80) void app.markActiveRoomRead(performance.now() <= app.state.userScrollIntentUntil);
|
|
257
275
|
app.queueReceiptRefresh();
|
|
@@ -12,6 +12,7 @@ import { initAttachments } from "./attachments.js";
|
|
|
12
12
|
import { initReplies } from "./replies.js";
|
|
13
13
|
import { initHistoryLoader } from "./history-loader.js";
|
|
14
14
|
import { initReminders } from "./reminders.js";
|
|
15
|
+
import { initPwa } from "./pwa.js";
|
|
15
16
|
|
|
16
17
|
initMentions(app);
|
|
17
18
|
initMessages(app);
|
|
@@ -26,3 +27,4 @@ initEvents(app);
|
|
|
26
27
|
initAnnouncements(app);
|
|
27
28
|
initReminders(app);
|
|
28
29
|
initAdmin(app);
|
|
30
|
+
initPwa();
|
|
@@ -98,6 +98,7 @@ export function initMessages(app) {
|
|
|
98
98
|
};
|
|
99
99
|
app.jumpToBottom = () => {
|
|
100
100
|
app.state.readAnchorGuard = null;
|
|
101
|
+
app.state.followBottom = true;
|
|
101
102
|
$("#thread").scrollTop = $("#thread").scrollHeight;
|
|
102
103
|
const entry = app.state.room && app.state.rooms.get(app.state.room.id);
|
|
103
104
|
app.state.unread = entry ? entry.unreadIds.size + (entry.unreadOverflow ? 100 : 0) : 0;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function initPwa() {
|
|
2
|
+
if (!("serviceWorker" in navigator) || !window.isSecureContext) return;
|
|
3
|
+
// Automated browsers do not model a worker's cache or its extra requests, so the browser
|
|
4
|
+
// tests would measure a page that no longer matches the code under test.
|
|
5
|
+
if (navigator.webdriver) return;
|
|
6
|
+
// Only a worker that replaced an older one means a new release is ready; the first
|
|
7
|
+
// install takes control too, and reloading then would throw away what the page just did.
|
|
8
|
+
const replacing = Boolean(navigator.serviceWorker.controller);
|
|
9
|
+
let reloaded = false;
|
|
10
|
+
navigator.serviceWorker.addEventListener("controllerchange", () => {
|
|
11
|
+
if (!replacing || reloaded) return;
|
|
12
|
+
reloaded = true;
|
|
13
|
+
location.reload();
|
|
14
|
+
});
|
|
15
|
+
window.addEventListener("load", () => {
|
|
16
|
+
navigator.serviceWorker.register("/sw.js").catch(() => {});
|
|
17
|
+
});
|
|
18
|
+
}
|
|
@@ -134,6 +134,8 @@ async function jumpToOriginal(roomId, messageId, app) {
|
|
|
134
134
|
} catch { return; }
|
|
135
135
|
if (!original) return markUnavailable(messageId, roomId, app);
|
|
136
136
|
app.state.positions.set(roomId, { messageId, offset: 0, atBottom: false }); app.savePosition(roomId, { messageId, offset: 0, atBottom: false });
|
|
137
|
+
// Jumping to an older message is the reader choosing history.
|
|
138
|
+
app.state.followBottom = false;
|
|
137
139
|
if (app.state.room?.id === roomId && app.state.navigationGeneration === generation) {
|
|
138
140
|
app.state.room = app.state.rooms.get(roomId)?.room || room; app.rerenderMessages();
|
|
139
141
|
const row = document.querySelector(`[data-msg-id="${CSS.escape(messageId)}"]`), thread = app.$("#thread");
|
|
@@ -11,7 +11,7 @@ export const app = {
|
|
|
11
11
|
memberApiUnavailable: new Set(), receiptApiUnavailable: new Set(),
|
|
12
12
|
receipts: new Map(), acknowledgedMessages: new Map(), pendingAcknowledgements: new Map(),
|
|
13
13
|
pendingAction: null, watcherTimer: 0, restored: false, resizeScrollAdjusting: false, layoutScrollAdjusting: false,
|
|
14
|
-
readAnchorGuard: null, userScrollIntentUntil: 0, listMetrics: { height: 0, top: 0, client: 0 },
|
|
14
|
+
readAnchorGuard: null, userScrollIntentUntil: 0, listMetrics: { height: 0, top: 0, client: 0 }, followBottom: true, threadPointerDown: false,
|
|
15
15
|
},
|
|
16
16
|
rendered: 0,
|
|
17
17
|
firstMessageId: null,
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/server/chat-server.ts
CHANGED
|
@@ -94,6 +94,26 @@ async function handle(req: Request): Promise<Response> {
|
|
|
94
94
|
},
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
|
+
// The install surface lives at the origin root so the worker controls /chat, not /assets.
|
|
98
|
+
if (req.method === "GET" && p === "/manifest.webmanifest") {
|
|
99
|
+
const body = await fs.readFile(path.join(import.meta.dir, "manifest.webmanifest"), "utf8").catch(() => null);
|
|
100
|
+
if (body === null) return json({ error: "manifest not found" }, 404);
|
|
101
|
+
return new Response(body, {
|
|
102
|
+
headers: { "Content-Type": "application/manifest+json; charset=utf-8", "Cache-Control": "no-store" },
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
if (req.method === "GET" && p === "/sw.js") {
|
|
106
|
+
const body = await fs.readFile(path.join(import.meta.dir, "sw.js"), "utf8").catch(() => null);
|
|
107
|
+
if (body === null) return json({ error: "service worker not found" }, 404);
|
|
108
|
+
const version = (await chatVersionTag()) || "dev";
|
|
109
|
+
return new Response(body.replaceAll("{{version}}", version), {
|
|
110
|
+
headers: {
|
|
111
|
+
"Content-Type": "text/javascript; charset=utf-8",
|
|
112
|
+
"Cache-Control": "no-store",
|
|
113
|
+
"Service-Worker-Allowed": "/",
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
}
|
|
97
117
|
if (req.method === "GET" && p.startsWith("/assets/")) {
|
|
98
118
|
let relative: string;
|
|
99
119
|
try { relative = decodeURIComponent(p.slice("/assets/".length)); }
|
package/server/chat.html
CHANGED
|
@@ -5,7 +5,11 @@
|
|
|
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
7
|
<title data-i18n="documentTitle">OC Chat</title>
|
|
8
|
-
<link rel="icon" href="
|
|
8
|
+
<link rel="icon" href="/assets/icons/icon-192.png">
|
|
9
|
+
<link rel="manifest" href="/manifest.webmanifest">
|
|
10
|
+
<link rel="apple-touch-icon" href="/assets/icons/apple-touch-icon.png">
|
|
11
|
+
<meta name="theme-color" content="#22695c">
|
|
12
|
+
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
9
13
|
<link rel="stylesheet" href="/assets/base.css">
|
|
10
14
|
<link rel="stylesheet" href="/assets/conversation.css">
|
|
11
15
|
<link rel="stylesheet" href="/assets/responsive.css">
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "OC Chat",
|
|
3
|
+
"short_name": "OC Chat",
|
|
4
|
+
"description": "Rooms where people and agents talk to each other.",
|
|
5
|
+
"start_url": "/chat",
|
|
6
|
+
"scope": "/",
|
|
7
|
+
"display": "standalone",
|
|
8
|
+
"background_color": "#f3f1ea",
|
|
9
|
+
"theme_color": "#22695c",
|
|
10
|
+
"icons": [
|
|
11
|
+
{ "src": "/assets/icons/icon-192.png", "sizes": "192x192", "type": "image/png", "purpose": "any" },
|
|
12
|
+
{ "src": "/assets/icons/icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "any" },
|
|
13
|
+
{ "src": "/assets/icons/icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable" }
|
|
14
|
+
]
|
|
15
|
+
}
|
package/server/sw.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// The server fills in {{version}} so a release installs a worker that replaces the old cache.
|
|
2
|
+
const VERSION = "{{version}}";
|
|
3
|
+
const CACHE = `oc-chat-${VERSION}`;
|
|
4
|
+
const SHELL = "/chat";
|
|
5
|
+
const STATIC = [
|
|
6
|
+
"/assets/base.css",
|
|
7
|
+
"/assets/conversation.css",
|
|
8
|
+
"/assets/responsive.css",
|
|
9
|
+
"/assets/icons/icon-192.png",
|
|
10
|
+
"/assets/icons/icon-512.png",
|
|
11
|
+
"/manifest.webmanifest",
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
self.addEventListener("install", (event) => {
|
|
15
|
+
event.waitUntil((async () => {
|
|
16
|
+
const cache = await caches.open(CACHE);
|
|
17
|
+
await cache.addAll([SHELL, ...STATIC]);
|
|
18
|
+
// The shell is a module graph, so an offline start needs the imports too. Walk them
|
|
19
|
+
// from the entry point instead of keeping a list that drifts with every new module.
|
|
20
|
+
const pending = ["/assets/chat/index.js"], seen = new Set();
|
|
21
|
+
while (pending.length) {
|
|
22
|
+
const url = pending.pop();
|
|
23
|
+
if (seen.has(url)) continue;
|
|
24
|
+
seen.add(url);
|
|
25
|
+
const response = await fetch(url).catch(() => null);
|
|
26
|
+
if (!response?.ok) continue;
|
|
27
|
+
const source = await response.clone().text();
|
|
28
|
+
await cache.put(url, response);
|
|
29
|
+
for (const match of source.matchAll(/from\s+"(\.\/[\w.-]+\.js)"/g)) {
|
|
30
|
+
pending.push(new URL(match[1], `https://chat.invalid${url}`).pathname);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
await self.skipWaiting();
|
|
34
|
+
})());
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
self.addEventListener("activate", (event) => {
|
|
38
|
+
event.waitUntil((async () => {
|
|
39
|
+
for (const key of await caches.keys()) if (key !== CACHE) await caches.delete(key);
|
|
40
|
+
await self.clients.claim();
|
|
41
|
+
})());
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
self.addEventListener("fetch", (event) => {
|
|
45
|
+
const request = event.request;
|
|
46
|
+
if (request.method !== "GET") return;
|
|
47
|
+
const url = new URL(request.url);
|
|
48
|
+
if (url.origin !== self.location.origin) return;
|
|
49
|
+
// Chat data never comes from a cache: a stale answer would show a room that was deleted
|
|
50
|
+
// and messages that were already read.
|
|
51
|
+
if (url.pathname !== SHELL && !url.pathname.startsWith("/assets/")) return;
|
|
52
|
+
if (url.pathname === SHELL) {
|
|
53
|
+
event.respondWith((async () => {
|
|
54
|
+
try {
|
|
55
|
+
const response = await fetch(request);
|
|
56
|
+
if (response.ok) await (await caches.open(CACHE)).put(SHELL, response.clone());
|
|
57
|
+
return response;
|
|
58
|
+
} catch {
|
|
59
|
+
return (await caches.match(SHELL)) || Response.error();
|
|
60
|
+
}
|
|
61
|
+
})());
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
event.respondWith((async () => {
|
|
65
|
+
const cached = await caches.match(request);
|
|
66
|
+
const network = fetch(request).then(async (response) => {
|
|
67
|
+
if (response.ok) await (await caches.open(CACHE)).put(request, response.clone());
|
|
68
|
+
return response;
|
|
69
|
+
}).catch(() => cached || Response.error());
|
|
70
|
+
return cached || network;
|
|
71
|
+
})());
|
|
72
|
+
});
|