@alexsun-top/opencode-chat-room 0.6.5 → 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 +7 -0
- package/README.md +4 -0
- package/README.zh-CN.md +4 -0
- package/package.json +3 -1
- package/server/assets/chat/index.js +2 -0
- package/server/assets/chat/pwa.js +18 -0
- 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,8 +1,15 @@
|
|
|
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
|
+
|
|
3
9
|
## 0.6.5 — 2026-11-15
|
|
4
10
|
|
|
5
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.
|
|
6
13
|
|
|
7
14
|
## 0.6.4 — 2026-11-15
|
|
8
15
|
|
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",
|
|
@@ -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();
|
|
@@ -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
|
+
}
|
|
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
|
+
});
|