@alexsun-top/opencode-chat-room 0.5.4 → 0.6.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.
- package/CHANGELOG.md +40 -0
- package/README.md +13 -1
- package/README.zh-CN.md +13 -1
- package/docs/administrator-rooms.md +7 -16
- package/package.json +3 -1
- package/server/admin-auth.ts +2 -7
- package/server/admin-routes.ts +8 -69
- package/server/assets/base.css +8 -0
- package/server/assets/chat/admin.js +56 -108
- package/server/assets/chat/editor.js +28 -3
- package/server/assets/chat/events.js +40 -13
- package/server/assets/chat/history-loader.js +65 -0
- package/server/assets/chat/index.js +2 -0
- package/server/assets/chat/markdown.js +11 -4
- package/server/assets/chat/message-cache.js +51 -0
- package/server/assets/chat/messages.js +69 -33
- package/server/assets/chat/questions.js +12 -9
- package/server/assets/chat/reminders.js +1 -1
- package/server/assets/chat/replies.js +11 -6
- package/server/assets/chat/room-watcher.js +10 -6
- package/server/assets/chat/rooms.js +59 -16
- package/server/assets/chat/state.js +17 -15
- package/server/assets/chat/system-messages.js +2 -1
- package/server/assets/conversation.css +13 -3
- package/server/assets/responsive.css +1 -0
- package/server/chat-server.ts +22 -19
- package/server/chat.html +14 -18
- package/server/json-body.ts +8 -0
- package/server/newrooms.ts +53 -27
- package/server/room-payload.ts +29 -0
- package/skills/chatroom/SKILL.md +5 -2
- package/src/agent-receipts.ts +3 -3
- package/src/center-inbox.ts +2 -0
- package/src/plugin-notifications.ts +2 -0
- package/src/room-service.ts +1 -0
- package/src/sqlite-state.ts +47 -10
- package/src/store.ts +9 -4
- package/src/v2-plugin.ts +17 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,45 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.0 — 2026-11-13
|
|
4
|
+
|
|
5
|
+
- Open rooms from a local IndexedDB snapshot first and merge the server delta afterwards, so revisiting a room renders instantly instead of re-downloading its history.
|
|
6
|
+
- Fetch only the newest 100 messages when opening a room; scrolling up loads older pages with a loading indicator, like an IM app.
|
|
7
|
+
- Raise the loaded-message window in the browser from 500 to 5,000, with older history available on demand.
|
|
8
|
+
- Keep up to 1,000,000 messages per room on the server, trimming the oldest lazily so writes stay fast.
|
|
9
|
+
- Fix the room ID showing "undefined" after clicking copy.
|
|
10
|
+
- Keep typing after cancelling an IME composition next to an @mention: the caret no longer gets stuck inside the mention chip, and the chip's own name is not mistaken for a mention query that pops the picker.
|
|
11
|
+
- Clicking a reply's quote now aligns the original message's top with the thread's top edge so the following conversation stays visible, and flashes the message bubble twice.
|
|
12
|
+
- Copy a message (or a composer selection) containing @mentions and paste it back to rebuild the mention chips; pasting external text that merely looks like mention markup stays literal.
|
|
13
|
+
- Reopen a room at the live bottom when the previous visit ended at the bottom with nothing unread, and flush the read watermark when the tab hides or closes.
|
|
14
|
+
- Edit a room's name and description from Options → Edit room (owner only); each change posts a system notice to the room and shows the description under the room title.
|
|
15
|
+
- Show a question-mark badge on rooms with unanswered questions, in the same slot as the unread count. Reading to the bottom clears the unread badge; pending questions stay visible in the Questions panel.
|
|
16
|
+
- Let room owners designate the room's administrator agent from the edit dialog and remove the separate operator administration token. Existing designations and claimed capabilities keep working; deleting a room removes its designation.
|
|
17
|
+
|
|
18
|
+
## 0.5.5 — 2026-11-13
|
|
19
|
+
|
|
20
|
+
- Clear own messages and entries older than the read watermark from the unread set, so a badge can no longer stick.
|
|
21
|
+
- Reopen a room at its first unread when the previous visit ended at the bottom; a deliberate scroll position is restored exactly.
|
|
22
|
+
- Show `<at>@name</at>` as `@name` in system rows, room previews, reminder text and notifications, and keep receipt verification aligned.
|
|
23
|
+
- Retry host discovery until the receiver owner resolves instead of staying silent after a slow start.
|
|
24
|
+
- Remove the composer's "Send as a question" toggle. Agents still ask questions through the room tool, and answering them in the room works as before.
|
|
25
|
+
- Clear a question from unread as soon as its answer arrives, even while the room is open.
|
|
26
|
+
- Keep a replied-to message as the saved position instead of jumping to unread on the next open.
|
|
27
|
+
- Show the unread total for all rooms in the browser tab title.
|
|
28
|
+
- Publish a `ghcr.io` container image with every release, so self-hosting no longer needs a local build.
|
|
29
|
+
- Start from a state directory owned by another user, such as a mounted container volume, instead of failing to tighten its permissions.
|
|
30
|
+
- Create the state database file with owner-only permissions from the start, and warn if they cannot be tightened, so chat history is not briefly readable by other users on the host.
|
|
31
|
+
- Show the running version next to the app title.
|
|
32
|
+
- Ship `server/json-body.ts`; 0.5.4 omitted it, so the published standalone server could not start.
|
|
33
|
+
- Start a new tab from the read watermark the server stores for that session, so messages read before the tab opened do not appear as read.
|
|
34
|
+
- Join and leave notices no longer raise unread badges.
|
|
35
|
+
- Show the jump-to-latest button whenever the room is far enough down to count as unread.
|
|
36
|
+
- Stop a position that could not be restored from blocking every later scroll position for that room.
|
|
37
|
+
- Sending from inside the history no longer jumps to the newest message or advances the read watermark.
|
|
38
|
+
- Keep messages whose row failed to render unread instead of advancing the watermark past them.
|
|
39
|
+
- Return the text of a reply to an already answered question to the draft instead of queueing an answer that can never succeed.
|
|
40
|
+
- Log every failed notification delivery with its room and session id.
|
|
41
|
+
- Run a scheduled plan when its reminder fires, without asking for the schedule to be confirmed again.
|
|
42
|
+
|
|
3
43
|
## 0.5.4 — 2026-11-11
|
|
4
44
|
|
|
5
45
|
- Keep unanswered questions unread, including when they are answered from another room, and stop own messages from raising unread counts. The sidebar badge now clears once the conversation is read.
|
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ Restart OpenCode. Ask an agent to create a room named `dev`, or enter `/room cre
|
|
|
22
22
|
On a machine reachable by the other devices, start the server. Replace `your-password` with a shared password:
|
|
23
23
|
|
|
24
24
|
```bash
|
|
25
|
-
bunx @alexsun-top/opencode-chat-room@0.5.
|
|
25
|
+
bunx @alexsun-top/opencode-chat-room@0.5.5 --host 0.0.0.0 --port 4399 --token 'your-password'
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
On each machine running OpenCode, set the server address and the same password, then start OpenCode from that environment:
|
|
@@ -37,6 +37,18 @@ Open `http://SERVER_IP:4399/chat` in a browser and enter the same password in se
|
|
|
37
37
|
|
|
38
38
|
**Security:** Anyone with the shared password can access and manage rooms, including direct chats. Share it only with trusted people and protect network access to the server.
|
|
39
39
|
|
|
40
|
+
### Docker
|
|
41
|
+
|
|
42
|
+
Every release also publishes a container image, so nothing needs to be built:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
docker run --rm -p 4399:4399 -v chat-room-data:/data \
|
|
46
|
+
-e CHAT_ROOM_SERVER_TOKEN='your-password' \
|
|
47
|
+
ghcr.io/agentsyaml/opencode-chat-room:latest
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Pin a release with `ghcr.io/agentsyaml/opencode-chat-room:v0.5.5`. Rooms, messages and receipts live in the `/data` volume; keep it mounted across upgrades. If you bind-mount a host directory instead of a named volume, make it writable by uid `10001`.
|
|
51
|
+
|
|
40
52
|
## 3. Start chatting
|
|
41
53
|
|
|
42
54
|
- Ask an agent to create a room, join a room, or send a message; you can also use the web interface.
|
package/README.zh-CN.md
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
在一台可被其他设备访问的机器上启动服务器,把 `换成自己的密码` 换成共享密码:
|
|
23
23
|
|
|
24
24
|
```bash
|
|
25
|
-
bunx @alexsun-top/opencode-chat-room@0.5.
|
|
25
|
+
bunx @alexsun-top/opencode-chat-room@0.5.5 --host 0.0.0.0 --port 4399 --token '换成自己的密码'
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
在每台运行 OpenCode 的机器上设置服务器地址和相同密码,再从该环境启动 OpenCode:
|
|
@@ -37,6 +37,18 @@ opencode
|
|
|
37
37
|
|
|
38
38
|
**安全提示:**共享密码的持有人可以访问和管理房间,包括私聊;请只分享给可信任的人,并保护服务器网络访问。
|
|
39
39
|
|
|
40
|
+
### Docker
|
|
41
|
+
|
|
42
|
+
每次发版同时发布容器镜像,不需要自己构建:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
docker run --rm -p 4399:4399 -v chat-room-data:/data \
|
|
46
|
+
-e CHAT_ROOM_SERVER_TOKEN='换成自己的密码' \
|
|
47
|
+
ghcr.io/agentsyaml/opencode-chat-room:latest
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
用 `ghcr.io/agentsyaml/opencode-chat-room:v0.5.5` 可以固定到具体版本。房间、消息和回执都保存在 `/data` 卷里,升级时保留该卷即可。如果改用宿主目录做挂载,需要让该目录对 uid `10001` 可写。
|
|
51
|
+
|
|
40
52
|
## 3. 开始聊天
|
|
41
53
|
|
|
42
54
|
- 让 Agent 创建房间、加入房间或发送消息;也可以在网页里操作。
|
|
@@ -1,21 +1,10 @@
|
|
|
1
1
|
# Administrator rooms
|
|
2
2
|
|
|
3
|
-
An administrator room is a normal group room
|
|
3
|
+
An administrator room is a normal group room whose owner designates one registered Agent as its administrator. That Agent can inspect rooms and their history without joining them.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
There is no separate operator credential. The room owner manages the designation from the room's **Options → Edit room** dialog: pick a registered Agent member as the administrator, or choose **None** to revoke. The change applies immediately and stays in effect until the owner revokes it or designates a different Agent.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
## Enroll the designated Agent
|
|
10
|
-
|
|
11
|
-
1. Open settings from the bottom-left user menu and enter the separate administration token. The browser retains it only for that tab.
|
|
12
|
-
2. Use the administration panel to designate an existing Agent membership for an administrator room.
|
|
13
|
-
3. Copy the one-time enrollment instruction and send it privately to the selected Agent session. Do not post it in a room.
|
|
14
|
-
4. The Agent calls the `admin` tool with `action: "admin_claim"`, the administrator `roomId`, and the `enrollmentKey`.
|
|
15
|
-
|
|
16
|
-
The plugin binds the claim to its native session and receiver owner. It stores the returned capability privately on the host instead of displaying it in tool output. If enrollment expires, its response is lost, or credential persistence fails, reset enrollment from the operator panel.
|
|
17
|
-
|
|
18
|
-
Reassigning the designation revokes the previous capability. Joining or rejoining a room never grants administrator privileges. Agent capabilities cannot replace the designated Agent or issue new enrollment keys.
|
|
7
|
+
Only the room owner can edit the room or change its administrator. Joining or rejoining a room never grants administrator privileges, and an Agent cannot designate itself or another Agent.
|
|
19
8
|
|
|
20
9
|
## Inspect rooms and assign work
|
|
21
10
|
|
|
@@ -26,10 +15,12 @@ The `admin` tool uses `roomId` for the administrator room.
|
|
|
26
15
|
| `admin_overview` | None | Inspect rooms and members |
|
|
27
16
|
| `admin_history` | `targetRoomId`, optional `limit` | Inspect bounded target-room history |
|
|
28
17
|
|
|
18
|
+
The server authorizes these calls from the designated Agent's native session and receiver owner identity; a normal room token, a mention, or room membership does not grant administrator privileges. Capabilities claimed by older versions keep working.
|
|
19
|
+
|
|
29
20
|
To assign work, send a message in the target room and mention the Agent. For scheduled work, create a room reminder containing the instruction and mention. The host must be available to execute the Agent; sending a reminder does not itself guarantee completion.
|
|
30
21
|
|
|
31
22
|
## Security and operations
|
|
32
23
|
|
|
33
|
-
Use HTTPS outside loopback. Keep
|
|
24
|
+
Use HTTPS outside loopback. Keep legacy capability credentials out of room messages, URLs, logs, and shared screenshots. The server authenticates the Agent's native identity; caller-supplied session IDs are not credentials. Processes with unrestricted access to the same OS account can read one another's files, so private file modes do not provide sandbox isolation between such Agents.
|
|
34
25
|
|
|
35
|
-
Back up server SQLite state to preserve designations, messages, and room reminders.
|
|
26
|
+
Back up server SQLite state to preserve designations, messages, and room reminders. Revoking a designation removes the Agent's administrator rights immediately; it does not change the room itself. Deleting an administrator room removes its designation along with the room.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alexsun-top/opencode-chat-room",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "A chat-room plugin and central server for OpenCode.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,8 +26,10 @@
|
|
|
26
26
|
"!src/**/*.test.ts",
|
|
27
27
|
"skills/chatroom/SKILL.md",
|
|
28
28
|
"server/chat-server.ts",
|
|
29
|
+
"server/json-body.ts",
|
|
29
30
|
"server/inbox.ts",
|
|
30
31
|
"server/history-route.ts",
|
|
32
|
+
"server/room-payload.ts",
|
|
31
33
|
"server/newrooms.ts",
|
|
32
34
|
"server/member-routes.ts",
|
|
33
35
|
"server/announcement-routes.ts",
|
package/server/admin-auth.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import { matchesHash,
|
|
2
|
-
|
|
3
|
-
const operatorSecret = process.env.CHAT_ROOM_ADMIN_TOKEN ?? "";
|
|
4
|
-
const serverSecret = process.env.CHAT_ROOM_SERVER_TOKEN ?? "";
|
|
5
|
-
export const adminEnabled = Boolean(operatorSecret && serverSecret && !safeEqual(operatorSecret, serverSecret));
|
|
6
|
-
export const isOperator = (request: Request) => adminEnabled && safeEqual(request.headers.get("x-chat-admin-token") ?? "", operatorSecret);
|
|
1
|
+
import { matchesHash, type Binding } from "./admin-state";
|
|
7
2
|
|
|
8
3
|
export function agentHeadersMatch(request: Request, binding: Binding): boolean {
|
|
9
4
|
return request.headers.get("x-chat-agent-session") === binding.session_id &&
|
|
@@ -12,7 +7,7 @@ export function agentHeadersMatch(request: Request, binding: Binding): boolean {
|
|
|
12
7
|
|
|
13
8
|
export function hasAdminCapability(request: Request, binding: Binding): boolean {
|
|
14
9
|
if (!agentHeadersMatch(request, binding)) return false;
|
|
15
|
-
//
|
|
10
|
+
// Owner designation is the grant; the optional claim capability is legacy.
|
|
16
11
|
if (!binding.capability_hash) return true;
|
|
17
12
|
return matchesHash(request.headers.get("x-chat-admin-capability") ?? "", binding.capability_hash);
|
|
18
13
|
}
|
package/server/admin-routes.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { databasePath } from "../src/store";
|
|
2
2
|
import { readHistoryPage } from "../src/sqlite-state";
|
|
3
|
-
import {
|
|
4
|
-
import { binding, digest, ensureAdminSchema, exec, isAgentMember, many, matchesHash, newSecret, one, publicRoom, tx, validCurrent
|
|
5
|
-
import type { Binding } from "./admin-state";
|
|
3
|
+
import { hasAdminCapability } from "./admin-auth";
|
|
4
|
+
import { binding, digest, ensureAdminSchema, exec, isAgentMember, many, matchesHash, newSecret, one, publicRoom, tx, validCurrent } from "./admin-state";
|
|
6
5
|
|
|
7
6
|
const json = (body: unknown, status = 200) => Response.json(body, { status, headers: { "Cache-Control": "no-store" } });
|
|
8
7
|
const object = (value: unknown): value is Record<string, unknown> => !!value && typeof value === "object" && !Array.isArray(value);
|
|
9
8
|
await ensureAdminSchema();
|
|
10
9
|
|
|
10
|
+
// Designation is managed by room owners through PATCH /rooms/:id; these routes
|
|
11
|
+
// only serve the designated agent (overview/history) and the legacy claim flow.
|
|
11
12
|
export async function adminRoutes(request: Request, url: URL): Promise<Response | undefined> {
|
|
12
13
|
if (!url.pathname.startsWith("/admin/") && !url.pathname.startsWith("/supervision/")) return undefined;
|
|
13
|
-
if (!adminEnabled) return json({ error: "admin API is disabled" }, 503);
|
|
14
14
|
try {
|
|
15
15
|
await ensureAdminSchema();
|
|
16
16
|
return await rootRoutes(request, url);
|
|
@@ -22,48 +22,16 @@ export async function adminRoutes(request: Request, url: URL): Promise<Response
|
|
|
22
22
|
|
|
23
23
|
async function rootRoutes(request: Request, url: URL): Promise<Response> {
|
|
24
24
|
const path = url.pathname;
|
|
25
|
-
if (request.method === "GET" && path === "/admin/rooms") return listRooms(request);
|
|
26
|
-
if (request.method === "POST" && path === "/admin/rooms") return createBinding(request);
|
|
27
25
|
const claim = path.match(/^\/admin\/rooms\/([^/]+)\/claim$/);
|
|
28
26
|
if (claim && request.method === "POST") return claimBinding(request, decodeURIComponent(claim[1]!));
|
|
29
27
|
const room = path.match(/^\/admin\/rooms\/([^/]+)(?:\/(overview|history))?$/);
|
|
30
28
|
if (!room) return json({ error: "not found" }, 404);
|
|
31
29
|
const roomID = decodeURIComponent(room[1]!);
|
|
32
|
-
if (request.method === "PUT" && !room[2]) return rotateBinding(request, roomID);
|
|
33
|
-
if (request.method === "DELETE" && !room[2]) return revokeBinding(request, roomID);
|
|
34
30
|
if (request.method === "GET" && room[2] === "overview") return overview(request, roomID);
|
|
35
31
|
if (request.method === "GET" && room[2] === "history") return history(request, url, roomID);
|
|
36
32
|
return json({ error: "method not allowed" }, 405);
|
|
37
33
|
}
|
|
38
34
|
|
|
39
|
-
async function listRooms(request: Request): Promise<Response> {
|
|
40
|
-
if (!isOperator(request)) return json({ error: "operator token required" }, 401);
|
|
41
|
-
return json({ rooms: await tx(db => many<Binding>(db, "SELECT * FROM admin_rooms ORDER BY created_at LIMIT 200").map(publicRoom)) });
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async function createBinding(request: Request): Promise<Response> {
|
|
45
|
-
if (!isOperator(request)) return json({ error: "operator token required" }, 401);
|
|
46
|
-
const body: unknown = await request.json();
|
|
47
|
-
if (!object(body) || !bounded(body.roomId, 128) || !bounded(body.targetRoomId, 128) ||
|
|
48
|
-
!bounded(body.sessionID, 128) || typeof body.receiverOwnerID !== "string" || body.receiverOwnerID.length > 128 ||
|
|
49
|
-
!bounded(body.membershipID, 128)) return json({ error: "invalid admin binding" }, 400);
|
|
50
|
-
const { roomId, targetRoomId, sessionID, receiverOwnerID, membershipID } = body as {
|
|
51
|
-
roomId: string; targetRoomId: string; sessionID: string; receiverOwnerID: string; membershipID: string;
|
|
52
|
-
};
|
|
53
|
-
const result = await tx(db => {
|
|
54
|
-
const admin = one<{ kind: string }>(db, "SELECT kind FROM rooms WHERE id=?", roomId);
|
|
55
|
-
if (!admin) return { status: 404 as const, error: "admin room not found" };
|
|
56
|
-
if (admin.kind !== "group") return { status: 400 as const, error: "admin room must be a group room" };
|
|
57
|
-
if (one(db, "SELECT 1 FROM admin_rooms WHERE room_id=?", roomId)) return { status: 409 as const, error: "admin room already designated; use PUT to rotate" };
|
|
58
|
-
if (!one(db, "SELECT 1 FROM rooms WHERE id=?", targetRoomId)) return { status: 404 as const, error: "target room not found" };
|
|
59
|
-
if (!isAgentMember(db, targetRoomId, sessionID, receiverOwnerID, membershipID)) return { status: 409 as const, error: "target agent binding is not active" };
|
|
60
|
-
const issued = enroll(db, roomId, targetRoomId, sessionID, receiverOwnerID, membershipID, 1);
|
|
61
|
-
const adminBinding = binding(db, roomId);
|
|
62
|
-
return issued && adminBinding ? { status: 201 as const, issued, adminRoom: publicRoom(adminBinding) } : { status: 409 as const, error: "admin room cannot be designated" };
|
|
63
|
-
});
|
|
64
|
-
return "issued" in result ? json({ adminRoom: result.adminRoom, ...result.issued }, result.status) : json({ error: result.error }, result.status);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
35
|
function bounded(value: unknown, max: number): value is string {
|
|
68
36
|
return typeof value === "string" && value.trim().length > 0 && value.length <= max;
|
|
69
37
|
}
|
|
@@ -86,37 +54,12 @@ async function claimBinding(request: Request, roomID: string): Promise<Response>
|
|
|
86
54
|
return result ? json(result) : json({ error: "claim rejected" }, 409);
|
|
87
55
|
}
|
|
88
56
|
|
|
89
|
-
async function rotateBinding(request: Request, roomID: string): Promise<Response> {
|
|
90
|
-
if (!isOperator(request)) return json({ error: "operator token required" }, 401);
|
|
91
|
-
const body: unknown = await request.json();
|
|
92
|
-
if (!object(body) || !bounded(body.targetRoomId, 128) || !bounded(body.sessionID, 128) ||
|
|
93
|
-
typeof body.receiverOwnerID !== "string" || body.receiverOwnerID.length > 128 || !bounded(body.membershipID, 128)) return json({ error: "invalid binding" }, 400);
|
|
94
|
-
const { targetRoomId, sessionID, receiverOwnerID, membershipID } = body as {
|
|
95
|
-
targetRoomId: string; sessionID: string; receiverOwnerID: string; membershipID: string;
|
|
96
|
-
};
|
|
97
|
-
const result = await tx(db => {
|
|
98
|
-
const old = binding(db, roomID);
|
|
99
|
-
if (!old) return null;
|
|
100
|
-
if (!isAgentMember(db, targetRoomId, sessionID, receiverOwnerID, membershipID)) return null;
|
|
101
|
-
const issued = enroll(db, roomID, targetRoomId, sessionID, receiverOwnerID, membershipID, old.generation + 1);
|
|
102
|
-
const current = binding(db, roomID);
|
|
103
|
-
return issued && current ? { issued, adminRoom: publicRoom(current) } : null;
|
|
104
|
-
});
|
|
105
|
-
return result ? json({ adminRoom: result.adminRoom, ...result.issued }) : json({ error: "admin room or active agent binding not found" }, 409);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
async function revokeBinding(request: Request, roomID: string): Promise<Response> {
|
|
109
|
-
if (!isOperator(request)) return json({ error: "operator token required" }, 401);
|
|
110
|
-
const deleted = await tx(db => exec(db, "DELETE FROM admin_rooms WHERE room_id=?", roomID).changes);
|
|
111
|
-
return deleted ? json({ ok: true }) : json({ error: "admin room not found" }, 404);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
57
|
async function overview(request: Request, roomID: string): Promise<Response> {
|
|
115
58
|
const result = await tx(db => {
|
|
116
59
|
const b = binding(db, roomID);
|
|
117
60
|
if (!b) return { status: 404 as const };
|
|
118
|
-
if (!
|
|
119
|
-
if (!
|
|
61
|
+
if (!hasAdminCapability(request, b)) return { status: 401 as const };
|
|
62
|
+
if (!validCurrent(db, b)) return { status: 409 as const };
|
|
120
63
|
const rooms = many<{ id: string; name: string; createdAt: number }>(db, "SELECT id,name,created_at AS createdAt FROM rooms ORDER BY created_at DESC LIMIT 200")
|
|
121
64
|
.map(room => ({ ...room, members: many(db, "SELECT g.session_id AS sessionID,g.name,g.protocol,g.receiver_owner_id AS receiverOwnerID,g.work_state AS workState,g.last_seen_at AS lastSeenAt FROM registry g WHERE g.room_id=? ORDER BY g.name", room.id) }));
|
|
122
65
|
return { rooms };
|
|
@@ -132,14 +75,10 @@ async function history(request: Request, url: URL, roomID: string): Promise<Resp
|
|
|
132
75
|
const allowed = await tx(db => {
|
|
133
76
|
const b = binding(db, roomID);
|
|
134
77
|
if (!b) return 404;
|
|
135
|
-
if (!
|
|
136
|
-
if (!
|
|
78
|
+
if (!hasAdminCapability(request, b)) return 401;
|
|
79
|
+
if (!validCurrent(db, b)) return 409;
|
|
137
80
|
return one(db, "SELECT 1 FROM rooms WHERE id=?", targetRoomID) ? 200 : 404;
|
|
138
81
|
});
|
|
139
82
|
if (allowed !== 200) return json({ error: allowed === 401 ? "unauthorized" : allowed === 404 ? "room not found" : "binding is no longer active" }, allowed);
|
|
140
83
|
return json(await readHistoryPage(databasePath(), targetRoomID, undefined, limit));
|
|
141
84
|
}
|
|
142
|
-
|
|
143
|
-
function authorized(request: Request, b: import("./admin-state").Binding): boolean {
|
|
144
|
-
return isOperator(request) || hasAdminCapability(request, b);
|
|
145
|
-
}
|
package/server/assets/base.css
CHANGED
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
--accent-soft: #e1eee6;
|
|
19
19
|
--danger: #a84437;
|
|
20
20
|
--danger-soft: #f7e8e1;
|
|
21
|
+
--warning: #a9761c;
|
|
22
|
+
--warning-ink: #fffdf6;
|
|
21
23
|
--mention-blue: #266c72;
|
|
22
24
|
--shadow: 0 2px 5px rgb(34 53 47 / .05), 0 18px 44px rgb(34 53 47 / .09);
|
|
23
25
|
}
|
|
@@ -36,6 +38,8 @@
|
|
|
36
38
|
--accent-soft: #263d34;
|
|
37
39
|
--danger: #ef9580;
|
|
38
40
|
--danger-soft: #3a2924;
|
|
41
|
+
--warning: #d9a441;
|
|
42
|
+
--warning-ink: #241a09;
|
|
39
43
|
--mention-blue: #8bc8c2;
|
|
40
44
|
--shadow: 0 2px 6px rgb(0 0 0 / .22), 0 18px 44px rgb(0 0 0 / .32);
|
|
41
45
|
}
|
|
@@ -99,6 +103,7 @@
|
|
|
99
103
|
.locale-control label { font-weight: 600; }
|
|
100
104
|
.locale-select { appearance: auto; min-height: 36px; font: inherit; font-size: 12.5px; line-height: 1.25; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 5px 9px; cursor: pointer; }
|
|
101
105
|
.chat-head-actions .locale-control { margin: 0; }
|
|
106
|
+
.wordmark-row { display: flex; align-items: baseline; gap: 10px; }
|
|
102
107
|
.wordmark {
|
|
103
108
|
margin: 0;
|
|
104
109
|
font-family: var(--font-display);
|
|
@@ -107,6 +112,9 @@
|
|
|
107
112
|
letter-spacing: -.03em;
|
|
108
113
|
color: var(--ink);
|
|
109
114
|
}
|
|
115
|
+
.version-tag { font: 600 10px/1 var(--font-mono); color: var(--ink-3); background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px 7px; white-space: nowrap; }
|
|
116
|
+
.version-tag:empty { display: none; }
|
|
117
|
+
.rail-brand .version-tag { align-self: center; }
|
|
110
118
|
.tagline { margin: 8px 0 26px; font-size: 13.5px; color: var(--ink-2); }
|
|
111
119
|
|
|
112
120
|
.field { display: block; margin-bottom: 14px; }
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { LS } from "./state.js";
|
|
2
2
|
|
|
3
|
+
// Admin badges come from the room payload (adminSessionID); room owners manage
|
|
4
|
+
// the designation through the edit-room dialog instead of an operator token.
|
|
3
5
|
export function initAdmin(app) {
|
|
4
|
-
const $ = app.$, dialog = $("#
|
|
5
|
-
let
|
|
6
|
-
|
|
7
|
-
const json = (body) => JSON.stringify(body);
|
|
8
|
-
const select = (node, values, label, id = (item) => item.id) => {
|
|
9
|
-
node.replaceChildren(new Option(label, ""), ...values.map((item) => new Option(item.name, id(item))));
|
|
10
|
-
};
|
|
11
|
-
app.state.adminRoomIds = new Set();
|
|
6
|
+
const $ = app.$, dialog = $("#editRoomDialog");
|
|
7
|
+
let agents = [], generation = 0, agentsReady = false;
|
|
8
|
+
|
|
12
9
|
const renderRoomOptions = app.renderRoomOptions;
|
|
13
10
|
app.renderRoomOptions = (list, available) => {
|
|
14
11
|
renderRoomOptions(list, available);
|
|
12
|
+
const byId = new Map((available || []).map((room) => [room.id, room]));
|
|
15
13
|
for (const button of list?.querySelectorAll(".room-row[data-room-id]") || []) {
|
|
16
|
-
|
|
14
|
+
const room = app.state.rooms.get(button.dataset.roomId)?.room || byId.get(button.dataset.roomId);
|
|
15
|
+
if (!room?.adminSessionID) continue;
|
|
17
16
|
const badge = document.createElement("span"); badge.className = "room-admin-badge"; badge.textContent = app.t("adminRoomBadge");
|
|
18
17
|
button.querySelector(".r-name")?.after(badge);
|
|
19
18
|
}
|
|
@@ -22,109 +21,58 @@ export function initAdmin(app) {
|
|
|
22
21
|
app.renderHead = () => {
|
|
23
22
|
renderHead();
|
|
24
23
|
const badge = $("#activeAdminBadge");
|
|
25
|
-
if (badge) badge.hidden = !app.state.
|
|
24
|
+
if (badge) badge.hidden = !app.state.room?.adminSessionID;
|
|
26
25
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
function renderAdminRooms() {
|
|
34
|
-
$("#adminRoomSelect").replaceChildren(new Option(app.t("chooseAdminRoom"), ""), ...rooms.map((room) => new Option(`${room.name}${bindings.some((item) => item.roomId === room.id) ? ` · ${app.t("adminRoomBadge")}` : ""}`, room.id)));
|
|
35
|
-
}
|
|
36
|
-
const clearEnrollment = () => { $("#adminEnrollment").replaceChildren(); $("#adminEnrollment").hidden = true; };
|
|
37
|
-
async function verifyToken() {
|
|
38
|
-
const generation = ++tokenGeneration, token = LS.adminToken, error = $("#adminAccessError"), button = $("#btnOpenAdmin");
|
|
39
|
-
error.hidden = true; button.hidden = true;
|
|
40
|
-
if (!token) { setAdminRooms([]); return; }
|
|
41
|
-
try {
|
|
42
|
-
const result = await app.adminApi("/admin/rooms");
|
|
43
|
-
if (generation !== tokenGeneration || token !== LS.adminToken) return;
|
|
44
|
-
setAdminRooms(result.rooms || []); button.hidden = false;
|
|
45
|
-
} catch (failure) {
|
|
46
|
-
if (generation === tokenGeneration && token === LS.adminToken) { setAdminRooms([]); error.textContent = failure.message; error.hidden = false; }
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
async function open() {
|
|
50
|
-
const generation = ++viewGeneration;
|
|
51
|
-
clearEnrollment();
|
|
52
|
-
dialog.showModal(); status(app.t("adminLoading"));
|
|
53
|
-
$("#adminRoomSelect").disabled = $("#adminTargetAgent").disabled = $("#btnDesignateAgent").disabled = true; $("#btnRevokeAdmin").hidden = true;
|
|
54
|
-
try {
|
|
55
|
-
const [adminResult, roomResult] = await Promise.all([app.adminApi("/admin/rooms"), app.api(`/rooms?sessionID=${encodeURIComponent(LS.sessionID)}`)]);
|
|
56
|
-
if (generation !== viewGeneration || !dialog.open) return;
|
|
57
|
-
bindings = adminResult.rooms || []; setAdminRooms(bindings); rooms = roomResult || [];
|
|
58
|
-
renderAdminRooms();
|
|
59
|
-
$("#adminRoomSelect").value = bindings[0]?.roomId || rooms[0]?.id || "";
|
|
60
|
-
status(""); await loadBinding(generation);
|
|
61
|
-
} catch (error) { if (generation === viewGeneration) { setAdminRooms([]); status(error.message, true); } }
|
|
62
|
-
finally { if (generation === viewGeneration) { $("#adminRoomSelect").disabled = $("#adminTargetAgent").disabled = false; } }
|
|
63
|
-
}
|
|
64
|
-
async function registryAgents(roomId) {
|
|
65
|
-
return roomId ? Object.entries(await app.api(`/rooms/${encodeURIComponent(roomId)}/registry`)).map(([sessionID, value]) => ({ sessionID, ...value })).filter((agent) => agent.membershipID && (agent.protocol === "v1" || agent.protocol === "v2" || agent.receiverOwnerID || agent.host)) : [];
|
|
66
|
-
}
|
|
67
|
-
async function loadDesignationAgents() {
|
|
68
|
-
const generation = ++designationGeneration, roomId = $("#adminRoomSelect").value;
|
|
69
|
-
agents = []; $("#adminTargetAgent").disabled = $("#btnDesignateAgent").disabled = true; select($("#adminTargetAgent"), [], app.t("chooseAgent"), (agent) => agent.sessionID);
|
|
26
|
+
|
|
27
|
+
async function loadAgents(gen) {
|
|
28
|
+
const room = app.state.room; if (!room) return;
|
|
29
|
+
const select = $("#editRoomAdmin");
|
|
30
|
+
select.replaceChildren(new Option(app.t("noAdminAgent"), ""));
|
|
31
|
+
agentsReady = false;
|
|
70
32
|
try {
|
|
71
|
-
const
|
|
72
|
-
if (
|
|
73
|
-
agents =
|
|
74
|
-
|
|
33
|
+
const registry = await app.api(`/rooms/${encodeURIComponent(room.id)}/registry`);
|
|
34
|
+
if (gen !== generation || !dialog.open) return;
|
|
35
|
+
agents = Object.entries(registry).map(([sessionID, value]) => ({ sessionID, ...value }))
|
|
36
|
+
.filter((agent) => agent.membershipID && (agent.protocol === "v1" || agent.protocol === "v2" || agent.receiverOwnerID || agent.host));
|
|
37
|
+
for (const agent of agents) select.append(new Option(agent.name, agent.sessionID));
|
|
38
|
+
select.value = agents.some((agent) => agent.sessionID === room.adminSessionID) ? room.adminSessionID : "";
|
|
39
|
+
agentsReady = true;
|
|
40
|
+
} catch (error) { if (gen === generation) $("#editRoomStatus").textContent = error.message; }
|
|
75
41
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
$("#
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
$("#btnDesignateAgent").disabled = !agents.some((agent) => agent.sessionID === $("#adminTargetAgent").value);
|
|
85
|
-
if (!agents.length) status(app.t("noAgents")); else status("");
|
|
42
|
+
|
|
43
|
+
function open() {
|
|
44
|
+
const room = app.state.room; if (!room) return;
|
|
45
|
+
$("#editRoomName").value = room.name;
|
|
46
|
+
$("#editRoomDescription").value = room.description || "";
|
|
47
|
+
$("#editRoomStatus").textContent = "";
|
|
48
|
+
dialog.showModal();
|
|
49
|
+
void loadAgents(++generation);
|
|
86
50
|
}
|
|
87
|
-
|
|
88
|
-
app.
|
|
89
|
-
$("#
|
|
90
|
-
$("#btnRefreshAdmin").addEventListener("click", async () => {
|
|
91
|
-
const id = $("#adminRoomSelect").value;
|
|
92
|
-
const generation = ++viewGeneration;
|
|
93
|
-
try { const [result, roomResult] = await Promise.all([app.adminApi("/admin/rooms"), app.api(`/rooms?sessionID=${encodeURIComponent(LS.sessionID)}`)]); if (generation !== viewGeneration || !dialog.open) return; bindings = result.rooms || []; rooms = roomResult || []; setAdminRooms(bindings); renderAdminRooms(); $("#adminRoomSelect").value = id; await loadBinding(generation); }
|
|
94
|
-
catch (error) { if (generation === viewGeneration) { setAdminRooms([]); status(error.message, true); } }
|
|
95
|
-
});
|
|
96
|
-
$("#btnCloseAdmin").addEventListener("click", () => dialog.close());
|
|
97
|
-
dialog.addEventListener("close", () => { ++viewGeneration; ++designationGeneration; clearEnrollment(); });
|
|
51
|
+
|
|
52
|
+
$("#btnEditRoom").addEventListener("click", () => { app.closePanels(); open(); });
|
|
53
|
+
$("#btnCloseEditRoom").addEventListener("click", () => dialog.close());
|
|
98
54
|
dialog.addEventListener("click", (event) => { if (event.target === dialog) dialog.close(); });
|
|
99
|
-
$("#
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
if (!
|
|
104
|
-
|
|
105
|
-
const
|
|
55
|
+
$("#editRoomForm").addEventListener("submit", async (event) => {
|
|
56
|
+
event.preventDefault();
|
|
57
|
+
const room = app.state.room; if (!room) return;
|
|
58
|
+
const name = $("#editRoomName").value.trim();
|
|
59
|
+
if (!name) { $("#editRoomStatus").textContent = app.t("roomNameRequired"); return; }
|
|
60
|
+
// Until the agent list loads, "None" is a placeholder, not a revocation.
|
|
61
|
+
const body = { sessionID: LS.sessionID, name, description: $("#editRoomDescription").value.trim(), ...(agentsReady ? { adminSessionID: $("#editRoomAdmin").value || null } : {}) };
|
|
62
|
+
const button = event.submitter; if (button) button.disabled = true;
|
|
106
63
|
try {
|
|
107
|
-
const
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
if (
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
$("#btnRevokeAdmin").addEventListener("click", async () => {
|
|
121
|
-
const id = $("#adminRoomSelect").value;
|
|
122
|
-
if (!id || !confirm(app.t("revokeConfirm"))) return;
|
|
123
|
-
const generation = viewGeneration, button = $("#btnRevokeAdmin"); button.disabled = true;
|
|
124
|
-
try { await app.adminApi(`/admin/rooms/${encodeURIComponent(id)}`, { method: "DELETE", body: json({}) }); if (generation !== viewGeneration || id !== $("#adminRoomSelect").value) return; bindings = bindings.filter((item) => item.roomId !== id); setAdminRooms(bindings); renderAdminRooms(); $("#adminRoomSelect").value = id; clearEnrollment(); await loadBinding(generation); }
|
|
125
|
-
catch (error) { if (generation === viewGeneration) status(error.message, true); }
|
|
126
|
-
finally { button.disabled = false; }
|
|
64
|
+
const updated = await app.api(`/rooms/${encodeURIComponent(room.id)}`, { method: "PATCH", body: JSON.stringify(body) });
|
|
65
|
+
const meta = { name: updated.name, description: updated.description, adminSessionID: updated.adminSessionID, openQuestions: updated.openQuestions };
|
|
66
|
+
const entry = app.state.rooms.get(room.id);
|
|
67
|
+
if (entry) { Object.assign(entry.room, meta); app.state.room = entry.room; }
|
|
68
|
+
const listed = app.state.availableRooms?.find((item) => item.id === room.id);
|
|
69
|
+
if (listed) Object.assign(listed, meta);
|
|
70
|
+
app.renderHead();
|
|
71
|
+
app.renderRoomOptions($("#roomList"), app.state.availableRooms || []);
|
|
72
|
+
app.renderRoomOptions($("#roomListChat"), app.state.availableRooms || []);
|
|
73
|
+
app.cacheRoomSoon?.(room.id);
|
|
74
|
+
dialog.close();
|
|
75
|
+
} catch (error) { $("#editRoomStatus").textContent = error.message; }
|
|
76
|
+
finally { if (button) button.disabled = false; }
|
|
127
77
|
});
|
|
128
|
-
|
|
129
|
-
void verifyToken();
|
|
130
|
-
}
|
|
78
|
+
}
|
|
@@ -57,7 +57,18 @@ export function editorSelectionOffsets(editor) {
|
|
|
57
57
|
const selection = getSelection();
|
|
58
58
|
if (!selection?.rangeCount || !editor.contains(selection.anchorNode)) return [editorText(editor).length, editorText(editor).length];
|
|
59
59
|
const selected = selection.getRangeAt(0);
|
|
60
|
-
const offset = (node, position) =>
|
|
60
|
+
const offset = (node, position) => {
|
|
61
|
+
const element = node.nodeType === Node.ELEMENT_NODE ? node : node.parentElement;
|
|
62
|
+
const chip = element?.closest(".editor-mention");
|
|
63
|
+
const raw = lengthBefore(editor, node, position);
|
|
64
|
+
if (chip && editor.contains(chip) && mentionName(chip) !== null) {
|
|
65
|
+
const start = lengthBefore(editor, chip, 0), end = start + `<at>@${mentionName(chip)}</at>`.length;
|
|
66
|
+
// A caret strictly inside a non-editable chip (e.g. left there by an
|
|
67
|
+
// ESC-cancelled IME composition) is not a text position; snap to the end.
|
|
68
|
+
if (raw > start && raw < end) return end;
|
|
69
|
+
}
|
|
70
|
+
return raw;
|
|
71
|
+
};
|
|
61
72
|
return [offset(selected.startContainer, selected.startOffset), offset(selected.endContainer, selected.endOffset)];
|
|
62
73
|
}
|
|
63
74
|
|
|
@@ -239,11 +250,25 @@ export function installEditor(editor) {
|
|
|
239
250
|
editor.replaceTextRange = (start, end, value) => replaceEditorRange(editor, start, end, value);
|
|
240
251
|
editor.addEventListener("input", pruneTrustedChipNames);
|
|
241
252
|
editor.addEventListener("keydown", (event) => deleteMentionAtCaret(editor, event));
|
|
253
|
+
editor.addEventListener("copy", (event) => {
|
|
254
|
+
const [start, end] = editorSelectionOffsets(editor);
|
|
255
|
+
if (start === end) return;
|
|
256
|
+
const text = editorText(editor).slice(start, end);
|
|
257
|
+
if (!text) return;
|
|
258
|
+
// Copy mentions in their token form so a paste rebuilds the same chips.
|
|
259
|
+
event.preventDefault();
|
|
260
|
+
event.clipboardData?.setData("text/plain", text);
|
|
261
|
+
if (/<at>@[^<]+<\/at>/.test(text)) event.clipboardData?.setData("text/html", `<div data-chatroom-mentions>${escapeHTML(text)}</div>`);
|
|
262
|
+
});
|
|
242
263
|
editor.addEventListener("paste", (event) => {
|
|
243
264
|
if (event.defaultPrevented || event.clipboardData?.files.length) return;
|
|
244
265
|
event.preventDefault();
|
|
245
266
|
const [start, end] = editorSelectionOffsets(editor);
|
|
246
|
-
|
|
267
|
+
const text = event.clipboardData?.getData("text/plain") || "";
|
|
268
|
+
// Rebuild chips only for copies this app marked; external text stays literal
|
|
269
|
+
// and keeps the native insert path, which handles newlines correctly.
|
|
270
|
+
const marked = (event.clipboardData?.getData("text/html") || "").includes("data-chatroom-mentions");
|
|
271
|
+
replaceEditorRange(editor, start, end, text, marked && /<at>@[^<]+<\/at>/.test(text));
|
|
247
272
|
editor.dispatchEvent(new InputEvent("input", { bubbles: true, inputType: "insertFromPaste" }));
|
|
248
273
|
});
|
|
249
274
|
editor.addEventListener("drop", (event) => {
|
|
@@ -255,7 +280,7 @@ export function installEditor(editor) {
|
|
|
255
280
|
const range = document.caretRangeFromPoint?.(event.clientX, event.clientY), selection = getSelection();
|
|
256
281
|
if (range && editor.contains(range.startContainer)) { selection.removeAllRanges(); selection.addRange(range); }
|
|
257
282
|
const [start, end] = editorSelectionOffsets(editor);
|
|
258
|
-
replaceEditorRange(editor, start, end, text,
|
|
283
|
+
replaceEditorRange(editor, start, end, text, html.includes("data-chatroom-mentions") && /<at>@[^<]+<\/at>/.test(text));
|
|
259
284
|
editor.dispatchEvent(new InputEvent("input", { bubbles: true, inputType: "insertFromDrop" }));
|
|
260
285
|
});
|
|
261
286
|
}
|