@alexsun-top/opencode-chat-room 0.6.6 → 0.6.8
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 +28 -0
- package/README.md +6 -3
- package/README.zh-CN.md +7 -3
- package/cli.ts +1 -1
- package/docs/administrator-rooms.md +11 -5
- package/index.ts +2 -2
- package/package.json +6 -2
- package/plugin.ts +57 -26
- package/server/admin-routes.ts +15 -7
- package/server/admin-state.ts +2 -2
- package/server/announcement-routes.ts +2 -2
- package/server/assets/attachments.css +25 -0
- package/server/assets/base.css +251 -39
- package/server/assets/chat/admin-badge.js +49 -0
- package/server/assets/chat/admin.js +77 -24
- package/server/assets/chat/announcements.js +27 -11
- package/server/assets/chat/attachment-store.js +106 -0
- package/server/assets/chat/attachments.js +245 -25
- package/server/assets/chat/events.js +56 -12
- package/server/assets/chat/image-zoom.js +141 -0
- package/server/assets/chat/index.js +10 -0
- package/server/assets/chat/install-prompt.js +82 -0
- package/server/assets/chat/join-requests.js +355 -0
- package/server/assets/chat/markdown.js +82 -5
- package/server/assets/chat/members.js +16 -6
- package/server/assets/chat/message-polling.js +158 -0
- package/server/assets/chat/message-window.js +14 -0
- package/server/assets/chat/messages.js +12 -132
- package/server/assets/chat/panels.js +37 -0
- package/server/assets/chat/questions.js +10 -6
- package/server/assets/chat/recall.js +279 -0
- package/server/assets/chat/receipts.js +3 -1
- package/server/assets/chat/reminders.js +67 -9
- package/server/assets/chat/replies.js +1 -1
- package/server/assets/chat/room-list.js +60 -0
- package/server/assets/chat/room-watcher.js +5 -1
- package/server/assets/chat/rooms.js +36 -84
- package/server/assets/chat/shortcuts.js +254 -0
- package/server/assets/chat/state.js +97 -24
- package/server/assets/chat/system-messages.js +28 -7
- package/server/assets/conversation.css +18 -26
- package/server/assets/keyboard-hints.css +51 -0
- package/server/assets/recall.css +29 -0
- package/server/assets/responsive.css +58 -16
- package/server/chat-server.ts +81 -62
- package/server/chat.html +238 -72
- package/server/history-route.ts +1 -1
- package/server/inbox.ts +3 -3
- package/server/join-requests.ts +106 -0
- package/server/member-routes.ts +4 -4
- package/server/message-recall-routes.ts +37 -0
- package/server/newrooms.ts +105 -13
- package/server/resource-routes.ts +19 -5
- package/server/room-join.ts +59 -0
- package/server/room-owner.ts +72 -0
- package/server/room-payload.ts +6 -2
- package/server/room-reminders.ts +3 -3
- package/server/sw.js +2 -0
- package/server/wake.ts +48 -19
- package/skills/chatroom/SKILL.md +35 -1
- package/src/README.md +22 -0
- package/src/{admin-client.ts → agent/admin-client.ts} +39 -9
- package/src/{admin-credentials.ts → agent/admin-credentials.ts} +1 -1
- package/src/{agent-presence.ts → agent/agent-presence.ts} +2 -2
- package/src/{agent-receipts.ts → agent/agent-receipts.ts} +2 -2
- package/src/{announcement-tool.ts → agent/announcement-tool.ts} +2 -2
- package/src/{chatroom-skill.ts → agent/chatroom-skill.ts} +1 -1
- package/src/{center-client.ts → center/center-client.ts} +103 -13
- package/src/{center-inbox.ts → center/center-inbox.ts} +44 -19
- package/src/{center-wake.ts → center/center-wake.ts} +31 -18
- package/src/{mentions.ts → center/mentions.ts} +1 -1
- package/src/center/message-ids.ts +7 -0
- package/src/center/notification-budget.ts +16 -0
- package/src/{queue-transport.ts → center/queue-transport.ts} +3 -3
- package/src/{queue.ts → center/queue.ts} +16 -6
- package/src/{reminder-client.ts → center/reminder-client.ts} +1 -1
- package/src/{session-delivery.ts → center/session-delivery.ts} +1 -1
- package/src/{announcements.ts → rooms/announcements.ts} +2 -2
- package/src/{resource-upload.ts → rooms/resource-upload.ts} +1 -1
- package/src/{resources.ts → rooms/resources.ts} +55 -9
- package/src/{room-service.ts → rooms/room-service.ts} +22 -2
- package/src/{background.ts → runtime/background.ts} +3 -3
- package/src/{plugin-notifications.ts → runtime/plugin-notifications.ts} +45 -19
- package/src/{v1-plugin.ts → runtime/v1-plugin.ts} +4 -4
- package/src/{v2-plugin.ts → runtime/v2-plugin.ts} +10 -10
- package/src/{v2-receiver.ts → runtime/v2-receiver.ts} +7 -7
- package/src/{watch.ts → runtime/watch.ts} +12 -12
- package/src/{member-state.ts → state/member-state.ts} +2 -2
- package/src/state/roles.ts +34 -0
- package/src/{sqlite-state.ts → state/sqlite-state.ts} +226 -37
- package/src/{store.ts → state/store.ts} +23 -4
- package/src/tests/announcement-board.ts +185 -0
- /package/src/{resource-read.ts → rooms/resource-read.ts} +0 -0
- /package/src/{receiver-owner.ts → state/receiver-owner.ts} +0 -0
- /package/src/{receiver-state.ts → state/receiver-state.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.8 — 2026-11-18
|
|
4
|
+
|
|
5
|
+
- Create protected group rooms that require approval to join. Human owners and administrators approve people and Agents; the designated management Agent can approve Agent requests only. Pending applicants are not members and cannot send, poll, or receive room delivery until approved.
|
|
6
|
+
- Recall messages by ID: authors can recall their own messages, human administrators can recall any message in a room they administer, and members can reveal the retained original.
|
|
7
|
+
- Accept messages up to 5,000 characters and convert oversized pasted text to a file attachment in web chat.
|
|
8
|
+
- Expand announcement and reminder editors and support editing existing reminders.
|
|
9
|
+
- Keep the mobile chat header compact and show an install recommendation on supported mobile browsers, with manual home-screen instructions on iOS.
|
|
10
|
+
- Improve join-page hierarchy, select spacing and language identification; keep the user menu compact when the composer grows.
|
|
11
|
+
- Identify human owners and administrators in the member list. Move resource deletion into the download button's actions menu.
|
|
12
|
+
- Zoom images with the mouse wheel, controls or keyboard, and pan enlarged images with a pointer or keyboard.
|
|
13
|
+
- Show keyboard hints on interactive controls as they enter the viewport. Badges omit the `Alt` modifier, a shortcut sheet lists the full combinations, and the hint preference persists.
|
|
14
|
+
- Scroll the conversation with PageUp and PageDown while the composer is focused, without moving the caret or losing the draft.
|
|
15
|
+
- Avoid a reading-position error when resizing without an active room. Start bounded clipboard reads promptly and distinguish unreadable files from upload network errors.
|
|
16
|
+
- Prepare independently versioned dsh and Codex packages for release alongside the main package when their versions advance.
|
|
17
|
+
|
|
18
|
+
## 0.6.7 — 2026-11-17
|
|
19
|
+
|
|
20
|
+
- Open an image full screen by clicking it, in a message or in the attachment tray. Escape, a click outside, or the close button returns to the same place with focus back on the image, and nothing is downloaded twice.
|
|
21
|
+
- Allow human room administrators to delegate administration, choose a successor and manage members; agents cannot become human administrators. The owner can transfer or dissolve the room. A designated management agent can remove members of its own room, except human administrators.
|
|
22
|
+
- Simplify the join page to two entries, join and create, over a nickname, with the key asked for once in a dialog when it is missing or rejected. A wide screen gets a two-column layout instead of a narrow card.
|
|
23
|
+
- Align the rail footer divider with the composer's divider at any composer height, including a five-line draft.
|
|
24
|
+
- Show upload failure details and use a bounded fallback for pasted files. The original intermittent paste failure has not been reproduced.
|
|
25
|
+
- Switch rooms with Alt+ArrowUp and Alt+ArrowDown: the selection cycles through the rooms this browser has joined, in the order the rail lists them, and stays put while a dialog is open.
|
|
26
|
+
- Put the room-list button on the left of the phone header, where a menu is expected, and keep the drawer opening from the left.
|
|
27
|
+
- Separate reminder and announcement lists from their editors, and identify management agents beside their messages and member entries.
|
|
28
|
+
- Let administrators delete room resources and agents delete their own uploads. Limit management-agent overview and history to their designated room.
|
|
29
|
+
- Organize source files by responsibility. Add experimental dsh and Codex plugin source; these packages are versioned separately and are not published with this release.
|
|
30
|
+
|
|
3
31
|
## 0.6.6 — 2026-11-16
|
|
4
32
|
|
|
5
33
|
- 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.
|
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ When upgrading an existing install, quit OpenCode first or use `opencode plugin
|
|
|
24
24
|
On a machine reachable by the other devices, start the server. Replace `your-password` with a shared password:
|
|
25
25
|
|
|
26
26
|
```bash
|
|
27
|
-
bunx @alexsun-top/opencode-chat-room@0.
|
|
27
|
+
bunx @alexsun-top/opencode-chat-room@0.6.8 --host 0.0.0.0 --port 4399 --token 'your-password'
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
On each machine running OpenCode, set the server address and the same password, then start OpenCode from that environment:
|
|
@@ -37,7 +37,7 @@ opencode
|
|
|
37
37
|
|
|
38
38
|
Open `http://SERVER_IP:4399/chat` in a browser and enter the same password in settings. Create or join a room there, and ask each agent to join it too.
|
|
39
39
|
|
|
40
|
-
**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.
|
|
40
|
+
**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. Join approval controls the normal join flow; it is not per-user authentication, so it does not stop a password holder from misrepresenting itself.
|
|
41
41
|
|
|
42
42
|
### Docker
|
|
43
43
|
|
|
@@ -49,15 +49,18 @@ docker run --rm -p 4399:4399 -v chat-room-data:/data \
|
|
|
49
49
|
ghcr.io/agentsyaml/opencode-chat-room:latest
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
Pin a release with `ghcr.io/agentsyaml/opencode-chat-room:v0.
|
|
52
|
+
Pin a release with `ghcr.io/agentsyaml/opencode-chat-room:v0.6.8`. 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`.
|
|
53
53
|
|
|
54
54
|
## 3. Start chatting
|
|
55
55
|
|
|
56
56
|
- Ask an agent to create a room, join a room, or send a message; you can also use the web interface.
|
|
57
|
+
- When creating or editing a room, turn on **Require approval to join**. You and other human administrators approve people and Agents from the member panel; a designated management agent can also approve Agent requests. A pending applicant is not a member yet.
|
|
57
58
|
- Use Reply to respond to a message. Mark a message as a question when you need an answer.
|
|
58
59
|
- Use the room's reminder button for one-time or recurring reminders. Times default to the server's time zone.
|
|
59
60
|
- Reminder text supports `{{time}}`, `{{initiator}}`, and `{{room}}`.
|
|
61
|
+
- Press `?` for the keyboard shortcut sheet. Interactive controls also show compact hints, and PageUp/PageDown scrolls the conversation while you type.
|
|
60
62
|
- Attach files, drag them in, or paste images. The default limit is 500 MiB per file.
|
|
63
|
+
- Agents can recall a message by ID; the original stays available to current members.
|
|
61
64
|
- Agents can use the `room` tool's `read_resource` action to save an attachment to a temporary file before opening it.
|
|
62
65
|
|
|
63
66
|
### Install as an app
|
package/README.zh-CN.md
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
在一台可被其他设备访问的机器上启动服务器,把 `换成自己的密码` 换成共享密码:
|
|
25
25
|
|
|
26
26
|
```bash
|
|
27
|
-
bunx @alexsun-top/opencode-chat-room@0.
|
|
27
|
+
bunx @alexsun-top/opencode-chat-room@0.6.8 --host 0.0.0.0 --port 4399 --token '换成自己的密码'
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
在每台运行 OpenCode 的机器上设置服务器地址和相同密码,再从该环境启动 OpenCode:
|
|
@@ -37,7 +37,7 @@ opencode
|
|
|
37
37
|
|
|
38
38
|
在浏览器打开 `http://服务器IP:4399/chat`,在页面设置中填入相同密码,即可创建或加入房间。每个 Agent 也需要加入同一个房间。
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
**安全提示:**共享密码的持有人可以访问和管理房间,包括私聊;请只分享给可信任的人,并保护服务器网络访问。加入审核只约束正常加入流程,不是按用户认证,无法阻止密码持有人伪装身份。
|
|
41
41
|
|
|
42
42
|
### Docker
|
|
43
43
|
|
|
@@ -49,14 +49,18 @@ docker run --rm -p 4399:4399 -v chat-room-data:/data \
|
|
|
49
49
|
ghcr.io/agentsyaml/opencode-chat-room:latest
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
用 `ghcr.io/agentsyaml/opencode-chat-room:v0.
|
|
52
|
+
用 `ghcr.io/agentsyaml/opencode-chat-room:v0.6.8` 可以固定到具体版本。房间、消息和回执都保存在 `/data` 卷里,升级时保留该卷即可。如果改用宿主目录做挂载,需要让该目录对 uid `10001` 可写。
|
|
53
53
|
|
|
54
54
|
## 3. 开始聊天
|
|
55
55
|
|
|
56
56
|
- 让 Agent 创建房间、加入房间或发送消息;也可以在网页里操作。
|
|
57
|
+
- 创建或编辑房间时可开启「需审核加入」。你和其他人类管理员在成员面板审核人和 Agent;被指定的管理 Agent 也可以审核 Agent 的申请。待审核的申请人还不算成员。
|
|
57
58
|
- 回复消息时点击回复;需要对方回答的问题可标记为「问题」。
|
|
58
59
|
- 点击房间里的提醒按钮,可创建一次性或周期提醒。默认使用服务器时区。
|
|
60
|
+
- 提醒正文支持 `{{time}}`、`{{initiator}}`、`{{room}}` 模板变量。
|
|
61
|
+
- 按 `?` 打开快捷键面板;可交互控件也会显示简短提示,输入时用 PageUp/PageDown 滚动会话。
|
|
59
62
|
- 点击附件按钮、拖入文件或粘贴图片即可分享;默认单文件上限为 500 MiB。
|
|
63
|
+
- Agent 可按消息 ID 撤回;当前成员仍可查看原文。
|
|
60
64
|
- Agent 收到附件后可通过 `room` 的 `read_resource` 操作保存到临时文件,再打开查看。
|
|
61
65
|
|
|
62
66
|
### 安装为应用
|
package/cli.ts
CHANGED
|
@@ -47,7 +47,7 @@ if (args[0] === "watch") {
|
|
|
47
47
|
if (args.length !== 2 || !["run", "start", "status", "stop"].includes(action ?? "")) {
|
|
48
48
|
fail("Expected watch run, start, status, or stop");
|
|
49
49
|
}
|
|
50
|
-
const watcher = await import("./src/watch");
|
|
50
|
+
const watcher = await import("./src/runtime/watch.ts");
|
|
51
51
|
try {
|
|
52
52
|
if (action === "run") await watcher.runWatcher();
|
|
53
53
|
else if (action === "start") console.log(await watcher.startWatcher());
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# Administrator rooms
|
|
2
2
|
|
|
3
|
-
An administrator room is a normal group room whose owner designates one registered Agent as its administrator. That Agent can inspect
|
|
3
|
+
An administrator room is a normal group room whose owner designates one registered Agent as its administrator. That Agent can inspect its own room and its history, and can review Agent join requests when the room requires approval.
|
|
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
|
-
|
|
7
|
+
The owner and delegated human administrators can edit the room's name, description, join policy, human administrator list, and successor. Only the owner can change the designated management Agent or hand the room to another person. Joining or rejoining a room never grants administrator privileges, and an Agent cannot designate itself or another Agent.
|
|
8
8
|
|
|
9
9
|
## Inspect rooms and assign work
|
|
10
10
|
|
|
@@ -12,8 +12,14 @@ The `admin` tool uses `roomId` for the administrator room.
|
|
|
12
12
|
|
|
13
13
|
| Action | Additional arguments | Purpose |
|
|
14
14
|
| --- | --- | --- |
|
|
15
|
-
| `admin_overview` | None | Inspect
|
|
16
|
-
| `admin_history` | `targetRoomId`, optional `limit` | Inspect bounded
|
|
15
|
+
| `admin_overview` | None | Inspect the designated room and its members |
|
|
16
|
+
| `admin_history` | Optional `targetRoomId`, optional `limit` | Inspect bounded history in the designated room |
|
|
17
|
+
| `admin_remove_member` | `targetSessionID` | Remove a member of the designated room, except a human administrator |
|
|
18
|
+
| `admin_join_requests` | None | List pending Agent join requests in the designated room |
|
|
19
|
+
| `admin_approve_join` | `targetSessionID` | Approve an Agent join request |
|
|
20
|
+
| `admin_deny_join` | `targetSessionID` | Deny an Agent join request, letting it apply again |
|
|
21
|
+
|
|
22
|
+
The designated Agent can review only requests from Agents. A human join request must be approved or denied by a human room administrator, and the server rejects an attempt by the management Agent to decide one.
|
|
17
23
|
|
|
18
24
|
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
25
|
|
|
@@ -23,4 +29,4 @@ To assign work, send a message in the target room and mention the Agent. For sch
|
|
|
23
29
|
|
|
24
30
|
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.
|
|
25
31
|
|
|
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.
|
|
32
|
+
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/index.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// file persistence stay internal
|
|
3
3
|
export { default } from "./plugin";
|
|
4
4
|
export { id, server, setup } from "./plugin";
|
|
5
|
-
export { default as RoomService, RoomError } from "./src/room-service";
|
|
5
|
+
export { default as RoomService, RoomError } from "./src/rooms/room-service.ts";
|
|
6
6
|
export type {
|
|
7
7
|
Message,
|
|
8
8
|
Participant,
|
|
9
9
|
Room,
|
|
10
10
|
RoomErrorCode,
|
|
11
|
-
} from "./src/room-service";
|
|
11
|
+
} from "./src/rooms/room-service.ts";
|
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.8",
|
|
4
4
|
"description": "A chat-room plugin and central server for OpenCode.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,8 +29,12 @@
|
|
|
29
29
|
"server/json-body.ts",
|
|
30
30
|
"server/inbox.ts",
|
|
31
31
|
"server/history-route.ts",
|
|
32
|
+
"server/message-recall-routes.ts",
|
|
32
33
|
"server/room-payload.ts",
|
|
34
|
+
"server/room-owner.ts",
|
|
33
35
|
"server/newrooms.ts",
|
|
36
|
+
"server/join-requests.ts",
|
|
37
|
+
"server/room-join.ts",
|
|
34
38
|
"server/member-routes.ts",
|
|
35
39
|
"server/announcement-routes.ts",
|
|
36
40
|
"server/resource-routes.ts",
|
|
@@ -54,7 +58,7 @@
|
|
|
54
58
|
},
|
|
55
59
|
"scripts": {
|
|
56
60
|
"server": "bun run server/chat-server.ts",
|
|
57
|
-
"test": "for file in src/*.test.ts server/*.test.ts; do bun test \"$file\" || exit; done",
|
|
61
|
+
"test": "for file in src/tests/*.test.ts server/*.test.ts; do bun test \"$file\" || exit; done",
|
|
58
62
|
"typecheck": "tsc --noEmit"
|
|
59
63
|
},
|
|
60
64
|
"devDependencies": {
|
package/plugin.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { tool } from "@opencode-ai/plugin";
|
|
|
2
2
|
import type { ToolContext as V1ToolContext } from "@opencode-ai/plugin";
|
|
3
3
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
-
import RoomService, { RoomError, type Message } from "./src/room-service";
|
|
5
|
+
import RoomService, { RoomError, type Message } from "./src/rooms/room-service.ts";
|
|
6
6
|
import {
|
|
7
7
|
formatRoom,
|
|
8
8
|
acknowledgeReadWithReceipts,
|
|
@@ -12,27 +12,28 @@ import {
|
|
|
12
12
|
writeState,
|
|
13
13
|
readState,
|
|
14
14
|
readUnreadMessages,
|
|
15
|
+
recallMessage,
|
|
15
16
|
senderName,
|
|
16
17
|
timeOf,
|
|
17
18
|
type Registry,
|
|
18
19
|
type RegistryEntry,
|
|
19
|
-
} from "./src/store";
|
|
20
|
-
import { flushReceiptCandidates, receiptDestination } from "./src/agent-receipts";
|
|
21
|
-
import { centerAction } from "./src/center-client";
|
|
22
|
-
import { createQueueTransport, type QueueTransport } from "./src/queue-transport";
|
|
23
|
-
import { checkCenterInbox } from "./src/center-inbox";
|
|
24
|
-
import { assertDeliveryLease } from "./src/session-delivery";
|
|
25
|
-
import { wakeSessions } from "./src/center-wake";
|
|
26
|
-
import { clearPendingAdmission } from "./src/queue";
|
|
27
|
-
import { createNotifier } from "./src/plugin-notifications";
|
|
28
|
-
import { explicitlyAddresses } from "./src/mentions";
|
|
29
|
-
import { createV2Setup, type V2Runtime } from "./src/v2-plugin";
|
|
30
|
-
import { createV1Server } from "./src/v1-plugin";
|
|
31
|
-
import { runAnnouncementTool } from "./src/announcement-tool";
|
|
32
|
-
import { uploadAgentResource } from "./src/resource-upload";
|
|
33
|
-
import { readAgentResource, resourceReadFailure } from "./src/resource-read";
|
|
34
|
-
import { adminTool, adminToolDescription, adminToolSchema } from "./src/admin-client";
|
|
35
|
-
import { runReminderTool } from "./src/reminder-client";
|
|
20
|
+
} from "./src/state/store.ts";
|
|
21
|
+
import { flushReceiptCandidates, receiptDestination } from "./src/agent/agent-receipts.ts";
|
|
22
|
+
import { centerAction, deleteAgentResource } from "./src/center/center-client.ts";
|
|
23
|
+
import { createQueueTransport, type QueueTransport } from "./src/center/queue-transport.ts";
|
|
24
|
+
import { checkCenterInbox } from "./src/center/center-inbox.ts";
|
|
25
|
+
import { assertDeliveryLease } from "./src/center/session-delivery.ts";
|
|
26
|
+
import { wakeSessions } from "./src/center/center-wake.ts";
|
|
27
|
+
import { clearPendingAdmission } from "./src/center/queue.ts";
|
|
28
|
+
import { createNotifier } from "./src/runtime/plugin-notifications.ts";
|
|
29
|
+
import { explicitlyAddresses } from "./src/center/mentions.ts";
|
|
30
|
+
import { createV2Setup, type V2Runtime } from "./src/runtime/v2-plugin.ts";
|
|
31
|
+
import { createV1Server } from "./src/runtime/v1-plugin.ts";
|
|
32
|
+
import { runAnnouncementTool } from "./src/agent/announcement-tool.ts";
|
|
33
|
+
import { uploadAgentResource } from "./src/rooms/resource-upload.ts";
|
|
34
|
+
import { readAgentResource, resourceReadFailure } from "./src/rooms/resource-read.ts";
|
|
35
|
+
import { adminTool, adminToolDescription, adminToolSchema } from "./src/agent/admin-client.ts";
|
|
36
|
+
import { runReminderTool } from "./src/center/reminder-client.ts";
|
|
36
37
|
// ponytail: CHAT_ROOM_SERVER_URL switches to central mode (all state on a
|
|
37
38
|
// central server); unset = standalone local-file mode
|
|
38
39
|
const centerUrl = process.env.CHAT_ROOM_SERVER_URL ?? "";
|
|
@@ -243,21 +244,23 @@ export async function pollKnownSessions(
|
|
|
243
244
|
await flushReceiptCandidates({ destination: receiptDestination(""), receiverOwnerID: transport.receiverOwnerID }).catch(() => {});
|
|
244
245
|
}
|
|
245
246
|
|
|
246
|
-
const READ_ONLY_ACTIONS = new Set(["list", "members", "poll", "announcement_list", "announcement_read"]);
|
|
247
|
+
const READ_ONLY_ACTIONS = new Set(["list", "members", "poll", "join_status", "announcement_list", "announcement_read"]);
|
|
247
248
|
|
|
248
249
|
export const roomArgs = z.object({
|
|
249
|
-
action: z.enum(["create", "join", "leave", "list", "send", "poll", "members", "upload_resource", "read_resource", "announcement_list", "announcement_read", "announcement_write", "announcement_delete", "reminder_list", "reminder_create", "reminder_update", "reminder_delete"]),
|
|
250
|
+
action: z.enum(["create", "join", "join_status", "leave", "list", "send", "poll", "recall", "members", "upload_resource", "read_resource", "delete_resource", "announcement_list", "announcement_read", "announcement_write", "announcement_delete", "reminder_list", "reminder_create", "reminder_update", "reminder_delete"]),
|
|
250
251
|
name: z.string().max(64).optional().describe("For join: your own participant display name, NOT the room name (required). For create: the new room name."),
|
|
251
252
|
roomId: z.string().optional(),
|
|
253
|
+
messageId: z.string().optional().describe("For recall: the full message ID to withdraw; agents recall their own messages, admins any message."),
|
|
252
254
|
resourceId: z.string().optional(),
|
|
253
255
|
filePath: z.string().optional().describe("Local regular file to upload; central mode only; requires host read permission."),
|
|
254
|
-
text: z.string().max(
|
|
256
|
+
text: z.string().max(5000).optional(),
|
|
255
257
|
isQuestion: z.boolean().optional(),
|
|
256
258
|
announcementName: z.string().optional().describe("Name of a room announcement; distinct from participant or room name."),
|
|
257
259
|
content: z.string().optional().describe("Announcement content, at most 5000 Unicode characters."),
|
|
258
260
|
reminderId: z.string().optional(),
|
|
259
261
|
schedule: z.discriminatedUnion("type", [z.object({ type: z.literal("once"), at: z.string(), timezone: z.string().refine((value) => { try { new Intl.DateTimeFormat("en", { timeZone: value }); return true; } catch { return false; } }, "timezone must be an IANA timezone").optional() }), z.object({ type: z.literal("cron"), expression: z.string().regex(/^\S+\s+\S+\s+\S+\s+\S+\s+\S+$/), timezone: z.string().refine((value) => { try { new Intl.DateTimeFormat("en", { timeZone: value }); return true; } catch { return false; } }, "timezone must be an IANA timezone").optional() })]).optional(),
|
|
260
262
|
paused: z.boolean().optional(),
|
|
263
|
+
joinPolicy: z.enum(["open", "approval"]).optional().describe("For create: \"approval\" holds new identities as pending until a human administrator approves them; central mode only."),
|
|
261
264
|
}).superRefine((args, ctx) => {
|
|
262
265
|
if (args.action === "join" && !args.name?.trim()) {
|
|
263
266
|
ctx.addIssue({ code: "custom", path: ["name"], message: "name is required to join a room" });
|
|
@@ -275,6 +278,7 @@ const roomExecute = async (
|
|
|
275
278
|
return await runReminderTool(runtime.center, args, context.sessionID);
|
|
276
279
|
}
|
|
277
280
|
if (args.action === "upload_resource") return uploadAgentResource(runtime.center, args.roomId ?? "", args.filePath ?? "", context.sessionID, context);
|
|
281
|
+
if (args.action === "delete_resource") return deleteAgentResource(runtime.center, args.roomId ?? "", args.resourceId ?? "", context.sessionID);
|
|
278
282
|
if (args.action === "read_resource") {
|
|
279
283
|
try {
|
|
280
284
|
if (!context.ask) return "error: host webfetch permission is unavailable";
|
|
@@ -297,6 +301,21 @@ const roomExecute = async (
|
|
|
297
301
|
...(runtime.protocol === "v2" ? { protocol: "v2" as const, receiverOwnerID } : {}),
|
|
298
302
|
}, context.sessionID);
|
|
299
303
|
}
|
|
304
|
+
if (args.action === "recall") {
|
|
305
|
+
if (!args.roomId) return "error: roomId is required";
|
|
306
|
+
if (!args.messageId) return "error: messageId is required";
|
|
307
|
+
try {
|
|
308
|
+
const recalled = await recallMessage(args.roomId, args.messageId, context.sessionID);
|
|
309
|
+
switch (recalled.status) {
|
|
310
|
+
case "ok": return `recalled message ${recalled.messageID}`;
|
|
311
|
+
case "missing": return `error: message not found: ${args.messageId}`;
|
|
312
|
+
case "member": return "error: not joined";
|
|
313
|
+
case "forbidden": return "error: only the sender or a room admin can recall this message";
|
|
314
|
+
}
|
|
315
|
+
} catch (err) {
|
|
316
|
+
return `error: ${err instanceof Error ? err.message : String(err)}`;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
300
319
|
const announcementResult = await runAnnouncementTool(args, context.sessionID);
|
|
301
320
|
if (announcementResult !== undefined) return announcementResult;
|
|
302
321
|
// ponytail: act as the identity this session registered with on join
|
|
@@ -334,6 +353,9 @@ const roomExecute = async (
|
|
|
334
353
|
if (!args.name?.trim()) {
|
|
335
354
|
return "error: name is required";
|
|
336
355
|
}
|
|
356
|
+
if (args.joinPolicy === "approval") {
|
|
357
|
+
return "error: joinPolicy \"approval\" requires central mode (set CHAT_ROOM_SERVER_URL); local rooms are always open";
|
|
358
|
+
}
|
|
337
359
|
const created = svc.createRoom(args.name.trim(), identity());
|
|
338
360
|
registerSelfInState(svc, registry, runtime, created.id, context.sessionID, undefined, receiverOwnerID);
|
|
339
361
|
return formatRoom(svc, created);
|
|
@@ -404,6 +426,14 @@ const roomExecute = async (
|
|
|
404
426
|
? members.map((m) => m.name).join("\n")
|
|
405
427
|
: "no members";
|
|
406
428
|
}
|
|
429
|
+
case "join_status": {
|
|
430
|
+
if (!args.roomId) {
|
|
431
|
+
return "error: roomId is required";
|
|
432
|
+
}
|
|
433
|
+
return registry[args.roomId]?.[context.sessionID]
|
|
434
|
+
? `joined room ${args.roomId}`
|
|
435
|
+
: `none: not registered in room ${args.roomId}; run join with your name (local rooms are always open)`;
|
|
436
|
+
}
|
|
407
437
|
case "send": {
|
|
408
438
|
if (!args.roomId) {
|
|
409
439
|
return "error: roomId is required";
|
|
@@ -420,7 +450,7 @@ const roomExecute = async (
|
|
|
420
450
|
);
|
|
421
451
|
const room = svc.getRoom(args.roomId);
|
|
422
452
|
notifications.push({ roomId: args.roomId, roomName: room.name, messages: [...room.messages] });
|
|
423
|
-
return `sent: ${args.text}\n${formatRoom(svc, room)}`;
|
|
453
|
+
return `sent: ${args.text}\nmessage id: ${msg.id}\n${formatRoom(svc, room)}`;
|
|
424
454
|
}
|
|
425
455
|
case "poll": {
|
|
426
456
|
if (!args.roomId) {
|
|
@@ -437,7 +467,7 @@ const roomExecute = async (
|
|
|
437
467
|
}
|
|
438
468
|
// ponytail: only messages newer than this session's last read (or
|
|
439
469
|
// last successful push) — queue-notified messages don't repeat
|
|
440
|
-
const messages = pollPage?.items ?? [];
|
|
470
|
+
const messages = (pollPage?.items ?? []).filter((message) => !message.recalledAt);
|
|
441
471
|
if (messages.length === 0) {
|
|
442
472
|
return "no new messages";
|
|
443
473
|
}
|
|
@@ -448,7 +478,7 @@ const roomExecute = async (
|
|
|
448
478
|
return messages
|
|
449
479
|
.map(
|
|
450
480
|
(m) =>
|
|
451
|
-
`[${timeOf(m.createdAt)}] ${senderName(svc, m)}: ${m.text}`,
|
|
481
|
+
`[${timeOf(m.createdAt)}] ${senderName(svc, m)}: ${m.text} (id: ${m.id})`,
|
|
452
482
|
)
|
|
453
483
|
.join("\n") + (pollPage?.hasMore ? "\nMore unread messages remain; poll again." : "");
|
|
454
484
|
}
|
|
@@ -461,7 +491,8 @@ const roomExecute = async (
|
|
|
461
491
|
context.sessionID, notification.messages).catch(() => {});
|
|
462
492
|
}
|
|
463
493
|
if (args.action === "poll" && pollMaxTs !== undefined && pollMaxTs > 0) {
|
|
464
|
-
await acknowledgeStandalonePoll(args.roomId!, context.sessionID, pollMaxTs,
|
|
494
|
+
await acknowledgeStandalonePoll(args.roomId!, context.sessionID, pollMaxTs,
|
|
495
|
+
(pollPage?.items ?? []).filter((message) => !message.recalledAt), pollIdentity);
|
|
465
496
|
}
|
|
466
497
|
return result;
|
|
467
498
|
} catch (err) {
|
|
@@ -469,7 +500,7 @@ const roomExecute = async (
|
|
|
469
500
|
}
|
|
470
501
|
};
|
|
471
502
|
const room = tool({
|
|
472
|
-
description: "Chat room operations: create, join, leave and list rooms; send and
|
|
503
|
+
description: "Chat room operations: create, join, leave and list rooms; send, poll and recall messages; list members and announcements; manage reminders. Sent and polled messages carry full message IDs; recall takes roomId plus messageId and withdraws the message for everyone (agents their own, room admins any). Reminder schedules use the server timezone unless an IANA timezone is provided; once schedules require an ISO datetime. Upload files and media; upload_resource returns a [[resource:UUID]] marker, and the attachment renders only when that exact marker is included in a send message. read_resource saves files to a private temporary path and leaves them there until removed or system cleanup. delete_resource removes an uploaded file; servers allow human room administrators any resource and agents only their own uploads. Room joinPolicy \"approval\" makes join a pending request: you are not a member while pending, never claim otherwise, and use join_status to check whether a human administrator approved it.",
|
|
473
504
|
args: roomArgs.shape,
|
|
474
505
|
execute: roomExecute,
|
|
475
506
|
});
|
package/server/admin-routes.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { databasePath } from "../src/store";
|
|
2
|
-
import { readHistoryPage } from "../src/sqlite-state";
|
|
1
|
+
import { databasePath } from "../src/state/store.ts";
|
|
2
|
+
import { readHistoryPage } from "../src/state/sqlite-state.ts";
|
|
3
3
|
import { hasAdminCapability } from "./admin-auth";
|
|
4
|
-
import { binding, digest, ensureAdminSchema, exec, isAgentMember, many, matchesHash, newSecret,
|
|
4
|
+
import { binding, digest, ensureAdminSchema, exec, isAgentMember, many, matchesHash, newSecret, publicRoom, tx, validCurrent } from "./admin-state";
|
|
5
5
|
|
|
6
6
|
const json = (body: unknown, status = 200) => Response.json(body, { status, headers: { "Cache-Control": "no-store" } });
|
|
7
7
|
const object = (value: unknown): value is Record<string, unknown> => !!value && typeof value === "object" && !Array.isArray(value);
|
|
@@ -59,8 +59,12 @@ async function overview(request: Request, roomID: string): Promise<Response> {
|
|
|
59
59
|
const b = binding(db, roomID);
|
|
60
60
|
if (!b) return { status: 404 as const };
|
|
61
61
|
if (!hasAdminCapability(request, b)) return { status: 401 as const };
|
|
62
|
+
// A binding may only administer the room it points at; legacy rows targeting
|
|
63
|
+
// another room are stale and must not borrow that room's membership.
|
|
64
|
+
if (b.target_room_id !== roomID) return { status: 409 as const };
|
|
62
65
|
if (!validCurrent(db, b)) return { status: 409 as const };
|
|
63
|
-
|
|
66
|
+
// The designation grants insight into its own room only.
|
|
67
|
+
const rooms = many<{ id: string; name: string; createdAt: number }>(db, "SELECT id,name,created_at AS createdAt FROM rooms WHERE id=?", roomID)
|
|
64
68
|
.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) }));
|
|
65
69
|
return { rooms };
|
|
66
70
|
});
|
|
@@ -69,16 +73,20 @@ async function overview(request: Request, roomID: string): Promise<Response> {
|
|
|
69
73
|
|
|
70
74
|
async function history(request: Request, url: URL, roomID: string): Promise<Response> {
|
|
71
75
|
const targetRoomID = url.searchParams.get("targetRoomId") ?? "";
|
|
76
|
+
if (!bounded(targetRoomID, 128)) return json({ error: "invalid history request" }, 400);
|
|
72
77
|
const rawLimit = url.searchParams.get("limit");
|
|
73
78
|
const limit = rawLimit === null ? 20 : Number(rawLimit);
|
|
74
|
-
if (!
|
|
79
|
+
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 50) return json({ error: "invalid history request" }, 400);
|
|
75
80
|
const allowed = await tx(db => {
|
|
76
81
|
const b = binding(db, roomID);
|
|
77
82
|
if (!b) return 404;
|
|
78
83
|
if (!hasAdminCapability(request, b)) return 401;
|
|
84
|
+
if (b.target_room_id !== roomID) return 409;
|
|
79
85
|
if (!validCurrent(db, b)) return 409;
|
|
80
|
-
return
|
|
86
|
+
return 200;
|
|
81
87
|
});
|
|
82
88
|
if (allowed !== 200) return json({ error: allowed === 401 ? "unauthorized" : allowed === 404 ? "room not found" : "binding is no longer active" }, allowed);
|
|
83
|
-
|
|
89
|
+
// The path room is the only scope; another target is never readable.
|
|
90
|
+
if (targetRoomID !== roomID) return json({ error: "room is outside this administrator's scope" }, 403);
|
|
91
|
+
return json(await readHistoryPage(databasePath(), roomID, undefined, limit));
|
|
84
92
|
}
|
package/server/admin-state.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
|
|
2
2
|
import type { Database, SQLQueryBindings } from "bun:sqlite";
|
|
3
|
-
import { databasePath } from "../src/store";
|
|
4
|
-
import { initializeAdminSchema, withStateTransaction } from "../src/sqlite-state";
|
|
3
|
+
import { databasePath } from "../src/state/store.ts";
|
|
4
|
+
import { initializeAdminSchema, withStateTransaction } from "../src/state/sqlite-state.ts";
|
|
5
5
|
|
|
6
6
|
const hash = (value: string) => createHash("sha256").update(value).digest("hex");
|
|
7
7
|
const secret = () => randomBytes(32).toString("base64url");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { deleteAnnouncement, getAnnouncement, listAnnouncements, putAnnouncement, validateAnnouncement } from "../src/announcements";
|
|
2
|
-
import { readState } from "../src/store";
|
|
1
|
+
import { deleteAnnouncement, getAnnouncement, listAnnouncements, putAnnouncement, validateAnnouncement } from "../src/rooms/announcements.ts";
|
|
2
|
+
import { readState } from "../src/state/store.ts";
|
|
3
3
|
|
|
4
4
|
const json = (body: unknown, status = 200) => Response.json(body, { status });
|
|
5
5
|
const object = (value: unknown): value is Record<string, unknown> => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/* Composer attachment tray: kept apart from the conversation layout. */
|
|
2
|
+
.attachment-button { flex: none; display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 1px solid var(--line); border-radius: 12px; color: var(--ink-2); background: var(--surface); font: inherit; font-size: 24px; cursor: pointer; }
|
|
3
|
+
.attachment-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
|
|
4
|
+
.attachment-button:hover { color: var(--accent); border-color: var(--accent); }
|
|
5
|
+
.attachment-button:disabled { opacity: .5; cursor: default; }
|
|
6
|
+
.attachment-tray { width: min(940px, 100%); margin: 0 auto; }
|
|
7
|
+
.attachment-volatile { margin: 0 0 3px; color: var(--ink-3); font-size: 10.5px; }
|
|
8
|
+
.attachment-status { display: inline-flex; width: fit-content; margin: 5px 0 0; padding: 3px 8px; border-radius: 999px; color: var(--accent); background: var(--accent-soft); font-size: 10.5px; }
|
|
9
|
+
.attachment-status.danger-text { color: var(--danger); background: var(--danger-soft); }
|
|
10
|
+
.attachment-status:empty { display: none; }
|
|
11
|
+
.attachment-list { display: grid; gap: 6px; max-height: 132px; overflow: auto; margin: 0; padding: 0; list-style: none; }
|
|
12
|
+
.attachment-item { display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; align-items: center; gap: 9px; min-width: 0; padding: 7px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); box-shadow: 0 1px 2px rgb(20 40 32 / .035); }
|
|
13
|
+
.attachment-preview { display: grid; place-items: center; width: 38px; height: 38px; overflow: hidden; border: 1px solid color-mix(in srgb, var(--ink) 5%, transparent); border-radius: 8px; background: var(--surface-2); color: var(--ink-3); font-size: 11px; font-weight: 700; }
|
|
14
|
+
.attachment-preview img { width: 100%; height: 100%; object-fit: cover; }
|
|
15
|
+
.attachment-file { min-width: 0; }
|
|
16
|
+
.attachment-name { overflow: hidden; margin: 0; color: var(--ink); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
|
|
17
|
+
.attachment-detail { margin: 0; color: var(--ink-3); font-size: 10px; }
|
|
18
|
+
.attachment-item progress { display: block; width: 100%; height: 5px; accent-color: var(--accent); }
|
|
19
|
+
.attachment-actions { display: flex; gap: 4px; }
|
|
20
|
+
.attachment-actions button { min-width: 44px; min-height: 44px; padding: 5px 9px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink-2); background: var(--surface); font: inherit; font-size: 11px; cursor: pointer; }
|
|
21
|
+
.attachment-actions button:hover { border-color: var(--accent); color: var(--accent); }
|
|
22
|
+
.attachment-over-limit { color: var(--danger); }
|
|
23
|
+
#draftCount.over-limit { color: var(--danger); font-weight: 700; }
|
|
24
|
+
.attachment-drop-overlay { position: fixed; inset: 12px; z-index: 100; place-items: center; border: 2px dashed var(--accent); border-radius: 18px; color: var(--accent); background: color-mix(in srgb, var(--accent-soft) 88%, transparent); font-size: clamp(18px, 4vw, 28px); font-weight: 700; pointer-events: none; }
|
|
25
|
+
#chatView.drag-over .attachment-drop-overlay { display: grid; }
|