@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
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isUnreadMessage } from "./messages.js";
|
|
2
|
+
import { LOADED_MESSAGE_LIMIT } from "./state.js";
|
|
2
3
|
import { setRoomPreview } from "./system-messages.js";
|
|
3
4
|
|
|
4
5
|
export async function watchRoom(roomId, app) {
|
|
@@ -13,30 +14,33 @@ export async function watchRoom(roomId, app) {
|
|
|
13
14
|
if (result.member !== true || !Array.isArray(result.items) || app.state.room?.id === roomId) return;
|
|
14
15
|
const previousReceivedTs = entry.receivedTs || 0;
|
|
15
16
|
const sawSystem = result.items.some((message) => message.senderId === "system");
|
|
17
|
+
const sawQuestion = result.items.some((message) => message.isQuestion || message.answerToMessageID);
|
|
16
18
|
const before = new Set(entry.room.messages.map((message) => message.id));
|
|
17
19
|
for (const message of result.items) {
|
|
18
|
-
if (message.createdAt > entry.readTs &&
|
|
20
|
+
if (message.createdAt > entry.readTs && isUnreadMessage(message, app, entry.room, entry.name) && !entry.unreadIds.has(message.id)) entry.unreadIds.set(message.id, message);
|
|
19
21
|
if (message.answerToMessageID && entry.unreadIds.get(message.answerToMessageID)?.isQuestion) entry.unreadIds.delete(message.answerToMessageID);
|
|
20
22
|
if (!before.has(message.id)) entry.room.messages.push({ ...message, roomId });
|
|
21
23
|
if (message.createdAt >= entry.previewAt) setRoomPreview(entry, message);
|
|
22
24
|
}
|
|
23
25
|
entry.receivedTs = result.items.reduce((latest, message) => Number.isSafeInteger(message.createdAt) ? Math.max(latest, message.createdAt) : latest, previousReceivedTs);
|
|
24
26
|
entry.unreadOverflow = Boolean(result.hasMore);
|
|
25
|
-
if (sawSystem || result.hasMore) {
|
|
27
|
+
if (sawSystem || sawQuestion || result.hasMore) {
|
|
26
28
|
const latest = await app.api(`/rooms/${encodeURIComponent(roomId)}`);
|
|
27
29
|
if (app.state.rooms.get(roomId) !== entry || app.state.room?.id === roomId) return;
|
|
28
30
|
entry.room.participants = latest.participants;
|
|
29
|
-
entry.room.
|
|
31
|
+
entry.room.openQuestions = latest.openQuestions;
|
|
32
|
+
entry.room.messages = [...new Map([...entry.room.messages, ...latest.messages].map((message) => [message.id, message])).values()].sort((a, b) => a.createdAt - b.createdAt).slice(-LOADED_MESSAGE_LIMIT);
|
|
30
33
|
const newest = latest.messages.at(-1);
|
|
31
34
|
if (newest && newest.createdAt >= entry.previewAt) setRoomPreview(entry, newest);
|
|
32
35
|
// A full refresh pages past the inbox window; count what arrived since the last look.
|
|
33
36
|
for (const message of latest.messages) {
|
|
34
37
|
if (message.answeredByMessageID) entry.unreadIds.delete(message.id);
|
|
35
|
-
if (message.createdAt > previousReceivedTs && message.createdAt > entry.readTs &&
|
|
38
|
+
if (message.createdAt > previousReceivedTs && message.createdAt > entry.readTs && isUnreadMessage(message, app, entry.room, entry.name) && !entry.unreadIds.has(message.id)) entry.unreadIds.set(message.id, message);
|
|
36
39
|
}
|
|
37
40
|
if (newest && Number.isSafeInteger(newest.createdAt)) entry.receivedTs = Math.max(entry.receivedTs, newest.createdAt);
|
|
38
41
|
}
|
|
39
|
-
if (entry.room.messages.length >
|
|
42
|
+
if (entry.room.messages.length > LOADED_MESSAGE_LIMIT) entry.room.messages.splice(0, entry.room.messages.length - LOADED_MESSAGE_LIMIT);
|
|
43
|
+
app.cacheRoomSoon?.(roomId);
|
|
40
44
|
if (result.hasMore && entry.receivedTs > previousReceivedTs) await watchRoom(roomId, app);
|
|
41
45
|
} catch (error) {
|
|
42
46
|
if (error.status === 401) app.openChatSettings();
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { LS } from "./state.js";
|
|
2
|
-
import {
|
|
1
|
+
import { LS, LOADED_MESSAGE_LIMIT } from "./state.js";
|
|
2
|
+
import { isUnreadMessage } from "./messages.js";
|
|
3
3
|
import { formatRoomPreview, setRoomPreview } from "./system-messages.js";
|
|
4
4
|
import { watchRoom } from "./room-watcher.js";
|
|
5
|
+
import { cacheRoomSoon, deleteCachedRoom, loadCachedRooms } from "./message-cache.js";
|
|
5
6
|
|
|
6
7
|
export function initRooms(app) {
|
|
7
8
|
const $ = app.$;
|
|
@@ -9,6 +10,19 @@ export function initRooms(app) {
|
|
|
9
10
|
let autoRefresh;
|
|
10
11
|
const invalidateRoomList = () => { autoRefresh = undefined; return ++roomListGeneration; };
|
|
11
12
|
|
|
13
|
+
app.cacheRoomSoon = (roomId) => cacheRoomSoon(app, roomId);
|
|
14
|
+
// Render joined rooms from the local snapshot before the network round trip;
|
|
15
|
+
// the normal restore then validates membership and merges the server delta.
|
|
16
|
+
app.seedFromCache = async () => {
|
|
17
|
+
for (const record of await loadCachedRooms()) {
|
|
18
|
+
const room = record?.room;
|
|
19
|
+
if (!room?.id || app.state.rooms.has(room.id)) continue;
|
|
20
|
+
if (!app.state.joinedIds.has(room.id) && room.id !== LS.roomId) continue;
|
|
21
|
+
app.ensureJoinedRoom(room, record.name || app.state.roomNames.get(room.id) || LS.name || app.t("guest"));
|
|
22
|
+
}
|
|
23
|
+
if (!app.state.room && LS.roomId && app.state.rooms.has(LS.roomId)) app.activateRoom(LS.roomId);
|
|
24
|
+
};
|
|
25
|
+
|
|
12
26
|
app.showJoin = (refresh = true, preserveRoomListGeneration = false) => {
|
|
13
27
|
if (!preserveRoomListGeneration) invalidateRoomList();
|
|
14
28
|
document.documentElement.classList.remove("session-restore");
|
|
@@ -33,6 +47,10 @@ export function initRooms(app) {
|
|
|
33
47
|
$("#btnCopyId").setAttribute("aria-label", app.t("copyRoomId"));
|
|
34
48
|
$("#railIdentity").textContent = app.state.myName;
|
|
35
49
|
$("#profileAvatar").textContent = Array.from(app.state.myName.trim())[0]?.toLocaleUpperCase() || "?";
|
|
50
|
+
const description = app.state.room.description || "";
|
|
51
|
+
$("#roomDescription").textContent = description;
|
|
52
|
+
$("#roomDescription").hidden = !description;
|
|
53
|
+
$("#btnEditRoom").hidden = app.state.myName !== app.state.room.ownerId;
|
|
36
54
|
app.updateTitle();
|
|
37
55
|
};
|
|
38
56
|
|
|
@@ -51,15 +69,27 @@ export function initRooms(app) {
|
|
|
51
69
|
const entry = existing || { unreadIds: new Map(), unreadOverflow: false, preview: "", previewAt: 0, position: 0, readTs: 0, receivedTs: room.messages.at(-1)?.createdAt ?? 0 };
|
|
52
70
|
entry.unreadIds ||= new Map();
|
|
53
71
|
entry.unreadOverflow ||= false;
|
|
54
|
-
const latest = room.messages.at(-1), savedReadTs = app.state.lastReadTs.get(room.id);
|
|
72
|
+
const latest = room.messages.at(-1), savedReadTs = app.state.lastReadTs.get(room.id) ?? (typeof room.lastReadTs === "number" ? room.lastReadTs : undefined);
|
|
73
|
+
if (savedReadTs !== undefined && !app.state.lastReadTs.has(room.id)) app.saveReadTs(room.id, savedReadTs);
|
|
55
74
|
entry.readTs ||= savedReadTs || 0;
|
|
75
|
+
// A server page only carries the newest window; keep older history already
|
|
76
|
+
// loaded or restored from the local cache instead of dropping it.
|
|
77
|
+
if (existing) {
|
|
78
|
+
const merged = new Map([...existing.room.messages, ...room.messages].map((message) => [message.id, message]));
|
|
79
|
+
room = { ...room, messages: [...merged.values()].sort((left, right) => left.createdAt - right.createdAt).slice(-LOADED_MESSAGE_LIMIT) };
|
|
80
|
+
}
|
|
81
|
+
entry.historyComplete = Boolean(existing?.historyComplete) || room.hasMore === false;
|
|
82
|
+
entry.historyBeforeSeq = entry.historyComplete ? null : existing?.historyBeforeSeq ?? (typeof room.messages[0]?.seq === "number" ? room.messages[0].seq : null);
|
|
56
83
|
entry.room = room;
|
|
57
84
|
entry.name = name;
|
|
58
85
|
// Only rebuild unread history when this browser already has a read watermark;
|
|
59
86
|
// a never-opened room is not a burst of unread messages.
|
|
60
|
-
if (!existing && savedReadTs !== undefined)
|
|
61
|
-
const
|
|
62
|
-
|
|
87
|
+
if (!existing && savedReadTs !== undefined) {
|
|
88
|
+
for (const message of room.messages) {
|
|
89
|
+
const unread = message.createdAt > entry.readTs;
|
|
90
|
+
if (unread && isUnreadMessage(message, app, room, name)) entry.unreadIds.set(message.id, message);
|
|
91
|
+
}
|
|
92
|
+
entry.unreadOverflow ||= Boolean(room.hasMore && entry.readTs < (room.messages[0]?.createdAt ?? Infinity));
|
|
63
93
|
}
|
|
64
94
|
entry.receivedTs ??= latest?.createdAt ?? 0;
|
|
65
95
|
if (latest && (!existing || latest.createdAt >= entry.previewAt)) setRoomPreview(entry, latest);
|
|
@@ -69,6 +99,7 @@ export function initRooms(app) {
|
|
|
69
99
|
app.saveJoinedIds();
|
|
70
100
|
app.saveRoomNames();
|
|
71
101
|
app.startRoomWatcher();
|
|
102
|
+
cacheRoomSoon(app, room.id);
|
|
72
103
|
};
|
|
73
104
|
|
|
74
105
|
app.activateRoom = (roomId, preserveRoomListGeneration = false) => {
|
|
@@ -95,7 +126,8 @@ export function initRooms(app) {
|
|
|
95
126
|
$("#msgList").textContent = "";
|
|
96
127
|
app.renderMessages(false);
|
|
97
128
|
const restoredPosition = app.restoreReadingPosition?.(roomId);
|
|
98
|
-
|
|
129
|
+
// A restore above the bottom needs a scroll before it counts as read.
|
|
130
|
+
app.state.readAnchorGuard = restoredPosition && !restoredPosition.atBottom ? { roomId, ...restoredPosition } : null;
|
|
99
131
|
app.startPolling();
|
|
100
132
|
app.renderMembers();
|
|
101
133
|
if (!restoredPosition) $("#thread").scrollTop = typeof savedPosition === "number" ? savedPosition : entry.position || $("#thread").scrollHeight;
|
|
@@ -109,7 +141,7 @@ export function initRooms(app) {
|
|
|
109
141
|
app.hideSendError();
|
|
110
142
|
app.updateBadge();
|
|
111
143
|
app.updateJump();
|
|
112
|
-
if (!restoredPosition) app.markActiveRoomRead();
|
|
144
|
+
if (!restoredPosition || restoredPosition.atBottom) app.markActiveRoomRead();
|
|
113
145
|
app.renderRoomOptions($("#roomList"), app.state.availableRooms || []);
|
|
114
146
|
app.renderRoomOptions($("#roomListChat"), app.state.availableRooms || []);
|
|
115
147
|
void app.refreshRoomList();
|
|
@@ -205,6 +237,7 @@ export function initRooms(app) {
|
|
|
205
237
|
$("#btnSend").disabled = true;
|
|
206
238
|
}
|
|
207
239
|
app.state.rooms.delete(roomId);
|
|
240
|
+
void deleteCachedRoom(roomId);
|
|
208
241
|
app.state.memberSessions.delete(roomId);
|
|
209
242
|
app.state.joinedIds.delete(roomId);
|
|
210
243
|
app.state.roomNames.delete(roomId);
|
|
@@ -394,17 +427,23 @@ export function initRooms(app) {
|
|
|
394
427
|
app.setText(status, entry ? "joined" : "joinAction");
|
|
395
428
|
button.append(name, kind, meta, preview, status);
|
|
396
429
|
const unread = entry && app.state.room?.id !== room.id ? (entry.unreadOverflow ? 100 : entry.unreadIds.size) : 0;
|
|
397
|
-
|
|
430
|
+
const openQuestions = Number(shownRoom.openQuestions) || 0;
|
|
431
|
+
// Same badge slot as unread: a pending question shows "?" instead of a count.
|
|
432
|
+
if (unread || openQuestions) {
|
|
398
433
|
const badge = document.createElement("span");
|
|
399
|
-
badge.className = "r-badge";
|
|
400
|
-
badge.textContent = unread > 99 ? "99+" : String(unread);
|
|
401
|
-
|
|
434
|
+
badge.className = openQuestions ? "r-badge r-badge-question" : "r-badge";
|
|
435
|
+
badge.textContent = openQuestions ? "?" : (unread > 99 ? "99+" : String(unread));
|
|
436
|
+
const label = openQuestions ? app.t("openQuestions", { count: openQuestions }) : app.t("unreadMessages", { count: unread });
|
|
437
|
+
badge.title = label;
|
|
438
|
+
badge.setAttribute("aria-label", label);
|
|
402
439
|
button.append(badge);
|
|
403
440
|
}
|
|
404
441
|
button.addEventListener("click", () => app.joinRoom(room.id, app.state.myName || $("#inName").value.trim() || app.t("guest")));
|
|
405
442
|
row.append(button);
|
|
406
443
|
list.append(row);
|
|
407
444
|
}
|
|
445
|
+
// Other rooms' unread changes only reach the title through this rerender.
|
|
446
|
+
app.updateTitle();
|
|
408
447
|
};
|
|
409
448
|
|
|
410
449
|
app.closePanels = () => {
|
|
@@ -443,19 +482,23 @@ export function initRooms(app) {
|
|
|
443
482
|
try {
|
|
444
483
|
await app.api(`/rooms/${encodeURIComponent(room.id)}`, {
|
|
445
484
|
method: "DELETE", body: JSON.stringify({ sessionID: LS.sessionID }),
|
|
446
|
-
headers: LS.adminToken ? { "X-Chat-Admin-Token": LS.adminToken } : {},
|
|
447
485
|
});
|
|
448
486
|
await app.removeJoinedRoom(room.id);
|
|
449
487
|
app.clearDraft(room.id);
|
|
450
488
|
app.clearPosition(room.id);
|
|
451
489
|
app.saveFailedMessages(room.id, []);
|
|
452
|
-
} catch (error) { app.showSendError(
|
|
490
|
+
} catch (error) { app.showSendError("sendFailed", { message: error.message }); }
|
|
453
491
|
};
|
|
454
492
|
|
|
455
493
|
app.copyRoomId = async () => {
|
|
494
|
+
const button = $("#btnCopyId");
|
|
456
495
|
try {
|
|
457
496
|
await navigator.clipboard.writeText(app.state.room.id);
|
|
458
|
-
|
|
497
|
+
// Swap a class so the ID span survives; flash() would overwrite the whole
|
|
498
|
+
// button and then restore it to "undefined" (the button has no data-i18n).
|
|
499
|
+
clearTimeout(button._copiedTimer);
|
|
500
|
+
button.classList.add("copied");
|
|
501
|
+
button._copiedTimer = setTimeout(() => button.classList.remove("copied"), 1200);
|
|
459
502
|
} catch { app.showSendError("copyFailed", { id: app.state.room.id }); }
|
|
460
503
|
};
|
|
461
504
|
|
|
@@ -485,7 +528,7 @@ function syncCachedRooms(rooms, app) {
|
|
|
485
528
|
if (!fresh || fresh.joined === false) { void app.removeJoinedRoom(roomId, { reason: app.state.room?.id === roomId, reconcile: true }); continue; }
|
|
486
529
|
if (app.state.room?.id === roomId) continue;
|
|
487
530
|
const messages = new Map([...entry.room.messages, ...fresh.messages].map((message) => [message.id, message]));
|
|
488
|
-
entry.room = { ...fresh, messages: [...messages.values()].sort((a, b) => a.createdAt - b.createdAt).slice(-
|
|
531
|
+
entry.room = { ...fresh, messages: [...messages.values()].sort((a, b) => a.createdAt - b.createdAt).slice(-LOADED_MESSAGE_LIMIT) };
|
|
489
532
|
const latest = entry.room.messages.at(-1);
|
|
490
533
|
if (latest) setRoomPreview(entry, latest);
|
|
491
534
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// Upper bound on messages kept in memory per open room; older pages load on scroll.
|
|
2
|
+
export const LOADED_MESSAGE_LIMIT = 5000;
|
|
3
|
+
|
|
1
4
|
export const app = {
|
|
2
5
|
$: (selector) => document.querySelector(selector),
|
|
3
6
|
state: {
|
|
@@ -132,7 +135,6 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
132
135
|
get name() { return ensureIdentity().name; },
|
|
133
136
|
set name(value) { ensureIdentity(); browserIdentity.name = String(value ?? "").slice(0, 64); writeSession("chat.name", browserIdentity.name || null); saveIdentity(); },
|
|
134
137
|
get token() { return read("chat.token") || ""; }, set token(value) { write("chat.token", value || null); },
|
|
135
|
-
get adminToken() { return readSession("chat.adminToken") || ""; }, set adminToken(value) { writeSession("chat.adminToken", value || null); },
|
|
136
138
|
get locale() { return read("chat.locale") || "en"; }, set locale(value) { write("chat.locale", value || null); },
|
|
137
139
|
get joinedRoomIds() {
|
|
138
140
|
try {
|
|
@@ -190,13 +192,7 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
190
192
|
const response = await apiResponse(url, options), blob = await response.blob();
|
|
191
193
|
assertIdentity(); return blob;
|
|
192
194
|
};
|
|
193
|
-
|
|
194
|
-
if (!url.startsWith("/admin/") || !auth.adminToken) throw new Error("Administration token is required");
|
|
195
|
-
const response = await apiResponse(url, { ...options, headers: { ...options.headers, "X-Chat-Admin-Token": auth.adminToken } });
|
|
196
|
-
const data = await response.json().catch(() => ({}));
|
|
197
|
-
assertIdentity(); return data;
|
|
198
|
-
};
|
|
199
|
-
return { LS: auth, saveToken, api, apiBlob, adminApi };
|
|
195
|
+
return { LS: auth, saveToken, api, apiBlob };
|
|
200
196
|
}
|
|
201
197
|
|
|
202
198
|
const messages = {
|
|
@@ -211,7 +207,10 @@ const messages = {
|
|
|
211
207
|
createRoom: "Create room", tokenOptional: "Access token (optional)", bearerToken: "Bearer token",
|
|
212
208
|
tokenPlaceholder: "Enter if the server requires it", save: "Save",
|
|
213
209
|
tokenHint: "If the server requires an access token (401), all requests will include it.",
|
|
214
|
-
existingRooms: "Rooms", noRooms: "No rooms yet. Create one.", copyRoomId: "Copy room ID",
|
|
210
|
+
existingRooms: "Rooms", noRooms: "No rooms yet. Create one.", copyRoomId: "Copy room ID", loadingHistory: "Loading earlier messages",
|
|
211
|
+
editRoom: "Edit room", roomNameLabel: "Room name", roomDescriptionLabel: "Description", adminAgentLabel: "Administrator agent",
|
|
212
|
+
adminAgentHint: "The designated agent can inspect all rooms and their history with the admin tool. Leave empty for none.",
|
|
213
|
+
noAdminAgent: "None", roomNameRequired: "Room name is required", openQuestions: ({ count }) => `${count} unanswered question${count === 1 ? "" : "s"}`,
|
|
215
214
|
newRoom: "Create a room",
|
|
216
215
|
copyRoomIdTitle: ({ id }) => `Click to copy the full room ID: ${id}`, copied: "Copied",
|
|
217
216
|
members: "Members", membersCount: ({ count }) => `Members (${count})`, noMembers: "No members yet.", profileMenu: "Your profile and settings",
|
|
@@ -233,7 +232,6 @@ const messages = {
|
|
|
233
232
|
questionsFailed: "Could not load questions. Try again.", questionsUnsupported: "Unanswered questions are unavailable on this server.", questionLabel: "Question",
|
|
234
233
|
answerQuestion: "Reply", answerPlaceholder: "Write a reply…", sendAnswer: "Send reply", selectQuestion: "Reply to question", copyQuestion: "Copy question", questionCopied: "Question copied.", questionCopyFailed: "Could not copy question.",
|
|
235
234
|
answerFailed: "Reply failed. Your draft is still here.", answerTooLong: "Reply must be 2,000 characters or fewer.", questionAlreadyAnswered: "This question was answered elsewhere.",
|
|
236
|
-
sendAsQuestion: "Send as a question",
|
|
237
235
|
adminBindingGuide: "Choose a room and an Agent in it. Send the invitation privately to finish setup.", adminRoomLabel: "Administrator room", adminDesignateAgent: "Invite Agent",
|
|
238
236
|
settings: "Settings", adminAccess: "Administration", adminToken: "Administration token", openAdministration: "Open administration", administration: "Administration", designations: "Designations", adminRoom: "Administrator room", targetRoom: "Agent membership room", adminScopeNote: "Choose an Agent in the administrator room. Administrators can manage all rooms.", targetAgent: "Registered agent", designate: "Designate administrator", revokeDesignation: "Revoke designation", globalStatus: "Global status", adminTasks: "Tasks", taskText: "Task", dispatchTask: "Dispatch task", timers: "Timers", planName: "Timer name", createTimer: "Create timer", tokenRequired: "The server requires an access token (401).",
|
|
239
237
|
adminLoading: "Loading administration…", refreshAdmin: "Refresh", adminRoomBadge: "admin", chooseAdminRoom: "Choose a normal room", chooseTargetRoom: "Choose an agent room", chooseAgent: "Choose a registered agent", taskTargetRoom: "Target room", taskTargetAgent: "Target agent", createAdminRoomFirst: "Create a normal room first, then select it as the admin room.", noAgents: "No registered agents", selectAdminAgent: "Choose an admin room and registered agent.", adminDesignated: "Administrator designation is active immediately and stays until you revoke it.", revokeConfirm: "Revoke this admin designation? The normal room will remain.", updateTask: "Update task", task_pending: "Pending", task_working: "Working", task_blocked: "Blocked", task_completed: "Completed", task_cancelled: "Cancelled", nextRun: ({ time, minutes }) => `Every ${minutes} min · next ${time}`, paused: "Paused", pauseTimer: "Pause", resumeTimer: "Resume", deleteTimer: "Delete", deleteTimerConfirm: ({ name }) => `Delete timer “${name}”?`,
|
|
@@ -287,7 +285,10 @@ const messages = {
|
|
|
287
285
|
newRoomNamePlaceholder: "例如:周末电影夜", createRoom: "创建新房间", tokenOptional: "访问令牌(可选)",
|
|
288
286
|
bearerToken: "Bearer Token", tokenPlaceholder: "服务器要求时填写", save: "保存",
|
|
289
287
|
tokenHint: "若服务器设置了访问令牌(401),所有请求都会带上它。", existingRooms: "房间",
|
|
290
|
-
noRooms: "还没有房间,创建一个吧。", copyRoomId: "复制房间 ID",
|
|
288
|
+
noRooms: "还没有房间,创建一个吧。", copyRoomId: "复制房间 ID", loadingHistory: "正在加载更早的消息",
|
|
289
|
+
editRoom: "编辑房间", roomNameLabel: "房间名称", roomDescriptionLabel: "描述", adminAgentLabel: "管理员 Agent",
|
|
290
|
+
adminAgentHint: "被指定的 Agent 可用 admin 工具查看所有房间及其历史。留空表示不指定。",
|
|
291
|
+
noAdminAgent: "不指定", roomNameRequired: "房间名称不能为空", openQuestions: ({ count }) => `${count} 个待回答的问题`,
|
|
291
292
|
newRoom: "创建房间",
|
|
292
293
|
copyRoomIdTitle: ({ id }) => `点击复制完整房间 ID:${id}`, copied: "已复制", members: "成员",
|
|
293
294
|
membersCount: ({ count }) => `成员 ${count}`, noMembers: "暂无成员", settings: "设置", profileMenu: "个人资料和设置",
|
|
@@ -309,7 +310,6 @@ const messages = {
|
|
|
309
310
|
questionsFailed: "无法加载问题,请重试。", questionsUnsupported: "此服务器不支持查看待回答问题。", questionLabel: "问题",
|
|
310
311
|
answerQuestion: "回复", answerPlaceholder: "写下回复…", sendAnswer: "发送回复", selectQuestion: "回复此问题", copyQuestion: "复制问题", questionCopied: "问题已复制。", questionCopyFailed: "无法复制问题。",
|
|
311
312
|
answerFailed: "回复失败,草稿仍已保留。", answerTooLong: "回复不能超过 2,000 个字符。", questionAlreadyAnswered: "此问题已由其他人回答。",
|
|
312
|
-
sendAsQuestion: "作为问题发送",
|
|
313
313
|
adminBindingGuide: "选择管理员房间和其中的 Agent,再将邀请私下发送给该 Agent 完成设置。", adminRoomLabel: "管理员房间", adminDesignateAgent: "邀请 Agent",
|
|
314
314
|
adminAccess: "管理", adminToken: "管理令牌", openAdministration: "打开管理面板", administration: "管理面板", designations: "管理绑定", adminRoom: "管理员房间", targetRoom: "Agent 所属房间", adminScopeNote: "请选择管理员房间内的 Agent。管理员可以管理所有房间。", adminRoomBadge: "管理", targetAgent: "已注册 Agent", designate: "指定管理员", revokeDesignation: "撤销绑定", globalStatus: "全局状态", adminTasks: "任务", taskText: "任务内容", dispatchTask: "派发任务", timers: "定时任务", planName: "定时任务名称", createTimer: "创建定时任务",
|
|
315
315
|
adminLoading: "正在加载管理面板…", refreshAdmin: "刷新", adminRoomBadge: "管理", chooseAdminRoom: "选择普通房间", chooseTargetRoom: "选择 Agent 房间", chooseAgent: "选择已注册 Agent", taskTargetRoom: "任务目标房间", taskTargetAgent: "任务目标 Agent", createAdminRoomFirst: "请先按普通流程创建房间,再选作管理房间。", noAgents: "没有已注册的 Agent", selectAdminAgent: "请选择管理房间和已注册的 Agent。", adminDesignated: "管理员已立即生效,长期有效,直到撤销。", revokeConfirm: "撤销此管理绑定?普通房间会保留。", updateTask: "更新任务", task_pending: "待处理", task_working: "进行中", task_blocked: "受阻", task_completed: "已完成", task_cancelled: "已取消", nextRun: ({ time, minutes }) => `每 ${minutes} 分钟 · 下次 ${time}`, paused: "已暂停", pauseTimer: "暂停", resumeTimer: "恢复", deleteTimer: "删除", deleteTimerConfirm: ({ name }) => `删除定时任务“${name}”?`,
|
|
@@ -356,11 +356,10 @@ app.t = (key, values = {}) => {
|
|
|
356
356
|
const text = typeof entry === "function" ? entry(values) : entry;
|
|
357
357
|
return String(text).replace(/\{(\w+)\}/g, (_, name) => values[name] ?? "");
|
|
358
358
|
};
|
|
359
|
-
export const { LS, saveToken, api, apiBlob
|
|
359
|
+
export const { LS, saveToken, api, apiBlob } = createAuth(undefined, undefined, (key, values) => app.t(key, values));
|
|
360
360
|
app.LS = LS;
|
|
361
361
|
app.api = api;
|
|
362
362
|
app.apiBlob = apiBlob;
|
|
363
|
-
app.adminApi = adminApi;
|
|
364
363
|
app.setToken = saveToken;
|
|
365
364
|
app.locale = LS.locale === "zh-CN" ? "zh-CN" : "en";
|
|
366
365
|
app.state.joinedIds = new Set(LS.joinedRoomIds);
|
|
@@ -469,7 +468,10 @@ app.flash = (button, key) => {
|
|
|
469
468
|
};
|
|
470
469
|
app.updateTitle = () => {
|
|
471
470
|
const title = app.state.room ? app.t("roomTitle", { name: app.state.room.name }) : app.t("documentTitle");
|
|
472
|
-
|
|
471
|
+
const active = app.state.room?.id;
|
|
472
|
+
let total = 0;
|
|
473
|
+
for (const [id, entry] of app.state.rooms) total += id === active ? app.state.unread : entry.unreadIds.size + (entry.unreadOverflow ? 100 : 0);
|
|
474
|
+
document.title = total ? `(${total}) ${title}` : title;
|
|
473
475
|
};
|
|
474
476
|
app.setOnline = (online) => { app.$("#connBar").hidden = online; };
|
|
475
477
|
app.showSendError = (key, values = {}) => {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export function formatSystemMessage(message, app) {
|
|
2
|
-
|
|
2
|
+
// `<at>@name</at>` is an editor token; system rows and previews show the plain mention.
|
|
3
|
+
const text = String(message?.text ?? "").replace(/<at>([\s\S]*?)<\/at>/g, "$1");
|
|
3
4
|
if (message?.senderId !== "system") return text;
|
|
4
5
|
const joined = /^(.*?)\s+joined the room$/.exec(text);
|
|
5
6
|
if (joined) return app.t("systemJoined", { name: joined[1] });
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
.rooms-drawer-trigger { display: none; }
|
|
15
15
|
.room-drawer-backdrop { position: fixed; inset: 0; z-index: 49; border: 0; background: rgb(9 16 22 / .38); }
|
|
16
16
|
.room-meta { margin: 4px 0 0; font-size: 11px; color: var(--ink-3); }
|
|
17
|
+
.room-description { margin: 4px 0 0; font-size: 12.5px; line-height: 1.5; color: var(--ink-2); white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
17
18
|
.mono { font-family: var(--font-mono); }
|
|
18
19
|
.copy-id {
|
|
19
20
|
appearance: none;
|
|
@@ -222,6 +223,12 @@
|
|
|
222
223
|
}
|
|
223
224
|
.msg-text::selection, .msg-text *::selection { color: var(--accent-ink); background: var(--accent); }
|
|
224
225
|
.msg.own .msg-text { background: linear-gradient(145deg, color-mix(in srgb, var(--accent-soft) 86%, var(--surface)), var(--accent-soft)); border-color: color-mix(in srgb, var(--accent) 12%, transparent); border-bottom-left-radius: 16px; border-bottom-right-radius: 5px; }
|
|
226
|
+
.msg.jump-flash .msg-text { animation: jump-flash .4s ease-in-out 2; }
|
|
227
|
+
@keyframes jump-flash {
|
|
228
|
+
0%, 100% { box-shadow: 0 1px 2px rgb(20 40 32 / .035); }
|
|
229
|
+
50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 55%, transparent); }
|
|
230
|
+
}
|
|
231
|
+
@media (prefers-reduced-motion: reduce) { .msg.jump-flash .msg-text { animation-duration: .8s; animation-iteration-count: 1; } }
|
|
225
232
|
.msg-content { position: relative; display: flex; align-items: flex-end; gap: 6px; width: 100%; max-width: 100%; }
|
|
226
233
|
.msg.own .msg-content { flex-direction: row-reverse; }
|
|
227
234
|
.message-copy {
|
|
@@ -418,6 +425,11 @@
|
|
|
418
425
|
}
|
|
419
426
|
.day-sep::before, .day-sep::after { content: ""; flex: 1; height: 1px; background: var(--line); }
|
|
420
427
|
|
|
428
|
+
.history-loading { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 0 4px; font-size: 12px; color: var(--ink-3); }
|
|
429
|
+
.history-spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: history-spin .8s linear infinite; }
|
|
430
|
+
@keyframes history-spin { to { transform: rotate(360deg); } }
|
|
431
|
+
@media (prefers-reduced-motion: reduce) { .history-spinner { animation-duration: 1.6s; } }
|
|
432
|
+
|
|
421
433
|
.gap { padding: 6px 0 2px; text-align: center; font-size: 12px; color: var(--ink-3); }
|
|
422
434
|
|
|
423
435
|
.chat-empty { padding: 64px 0 44px; text-align: center; font-family: var(--font-display); font-size: 16px; color: var(--ink-3); }
|
|
@@ -442,9 +454,7 @@
|
|
|
442
454
|
background: linear-gradient(180deg, var(--surface), color-mix(in srgb, var(--accent-soft) 18%, var(--surface)));
|
|
443
455
|
}
|
|
444
456
|
.composer-row { display: flex; gap: 9px; align-items: flex-end; }
|
|
445
|
-
.composer-meta { display: flex; align-items: center; justify-content:
|
|
446
|
-
.question-toggle { min-width: 0; margin: 0; color: var(--ink-2); font-size: 12px; }
|
|
447
|
-
.question-toggle input { accent-color: var(--accent); vertical-align: -1px; }
|
|
457
|
+
.composer-meta { display: flex; align-items: center; justify-content: flex-end; gap: 8px; width: min(940px, 100%); min-width: 0; margin: -1px auto 0; }
|
|
448
458
|
.composer .input { flex: 1; }
|
|
449
459
|
.composer .input:disabled { opacity: .5; }
|
|
450
460
|
#msgInput {
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
.r-status { color: var(--accent); font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
|
|
53
53
|
.r-preview { overflow: hidden; color: var(--ink-3); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
|
|
54
54
|
.r-badge { position: absolute; top: 8px; right: 9px; display: grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: 10px; font-weight: 700; }
|
|
55
|
+
.r-badge-question { background: var(--warning); color: var(--warning-ink); font-size: 12px; }
|
|
55
56
|
.rail-foot { display: flex; align-items: center; gap: 8px; margin-top: auto; padding: 12px 4px 0; border-top: 1px solid color-mix(in srgb, var(--line) 80%, transparent); font-size: 12px; color: var(--ink-3); }
|
|
56
57
|
.rail-foot .anchor { width: 100%; }
|
|
57
58
|
.user-menu-trigger { display: flex; align-items: center; gap: 10px; width: 100%; min-width: 0; padding: 7px; border: 1px solid transparent; border-radius: 12px; color: var(--ink); background: transparent; font: inherit; text-align: left; cursor: pointer; transition: border-color .16s, background .16s, box-shadow .16s; }
|
package/server/chat-server.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { readInbox } from "./inbox";
|
|
|
17
17
|
import { isReceiverOwnerID } from "../src/receiver-owner";
|
|
18
18
|
import { claimWake, touchActive, wakeMentionedSessions } from "./wake";
|
|
19
19
|
import { historyRoute } from "./history-route";
|
|
20
|
+
import { roomPayload } from "./room-payload";
|
|
20
21
|
import { jsonObject } from "./json-body";
|
|
21
22
|
import { roomManagement } from "./newrooms";
|
|
22
23
|
import { memberRoutes } from "./member-routes";
|
|
@@ -25,6 +26,13 @@ import { maxResourceBytes } from "../src/resources";
|
|
|
25
26
|
import { adminRoutes } from "./admin-routes";
|
|
26
27
|
import { roomReminderRoutes, startRoomReminderScheduler } from "./room-reminders";
|
|
27
28
|
|
|
29
|
+
// The chat page shows this next to the app title; a missing package must not
|
|
30
|
+
// leave a placeholder behind.
|
|
31
|
+
let versionTag: Promise<string> | undefined;
|
|
32
|
+
const chatVersionTag = () => (versionTag ??= Bun.file(path.join(import.meta.dir, "../package.json")).json()
|
|
33
|
+
.then((pkg) => typeof pkg?.version === "string" && pkg.version ? `v${pkg.version}` : "")
|
|
34
|
+
.catch(() => ""));
|
|
35
|
+
|
|
28
36
|
function parsePort(value: string): number {
|
|
29
37
|
const port = Number(value);
|
|
30
38
|
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
@@ -54,17 +62,6 @@ const json = (body: unknown, status = 200) =>
|
|
|
54
62
|
headers: { "Content-Type": "application/json" },
|
|
55
63
|
});
|
|
56
64
|
|
|
57
|
-
const serializeRoom = (r: Room) => ({
|
|
58
|
-
id: r.id,
|
|
59
|
-
name: r.name,
|
|
60
|
-
ownerId: r.ownerId,
|
|
61
|
-
createdAt: r.createdAt,
|
|
62
|
-
participants: [...r.participants.values()],
|
|
63
|
-
messages: r.messages,
|
|
64
|
-
kind: r.kind ?? "group",
|
|
65
|
-
...(r.directSessionIDs ? { directSessionIDs: r.directSessionIDs } : {}),
|
|
66
|
-
});
|
|
67
|
-
|
|
68
65
|
function mutate<T>(fn: (svc: RoomService, registry: Registry) => T): Promise<T> {
|
|
69
66
|
return writeState(fn);
|
|
70
67
|
}
|
|
@@ -89,7 +86,8 @@ async function handle(req: Request): Promise<Response> {
|
|
|
89
86
|
if (html === null) {
|
|
90
87
|
return json({ error: "chat page not found" }, 404);
|
|
91
88
|
}
|
|
92
|
-
|
|
89
|
+
const version = await chatVersionTag();
|
|
90
|
+
return new Response(html.replaceAll("{{version}}", version), {
|
|
93
91
|
headers: {
|
|
94
92
|
"Content-Type": "text/html; charset=utf-8",
|
|
95
93
|
"Cache-Control": "no-store",
|
|
@@ -152,9 +150,14 @@ async function handle(req: Request): Promise<Response> {
|
|
|
152
150
|
}
|
|
153
151
|
if (req.method === "GET" && p === "/rooms") {
|
|
154
152
|
const caller = url.searchParams.get("sessionID");
|
|
155
|
-
const
|
|
153
|
+
const rows = await readState((svc, registry) => svc.listRooms()
|
|
156
154
|
.filter((room) => room.kind !== "direct" ? true : !!caller && room.directSessionIDs?.includes(caller))
|
|
157
|
-
.map((room) => ({
|
|
155
|
+
.map((room) => ({ room, entry: caller ? registry[room.id]?.[caller] : undefined })));
|
|
156
|
+
const rooms = [];
|
|
157
|
+
for (const { room, entry } of rows) {
|
|
158
|
+
// The browser keeps its watermark per tab; a new tab starts from this one.
|
|
159
|
+
rooms.push({ ...await roomPayload(room), joined: Boolean(entry), ...(entry?.lastReadTs ? { lastReadTs: entry.lastReadTs } : {}) });
|
|
160
|
+
}
|
|
158
161
|
return json(rooms);
|
|
159
162
|
}
|
|
160
163
|
const members = await memberRoutes(req, url);
|
|
@@ -202,7 +205,7 @@ async function handle(req: Request): Promise<Response> {
|
|
|
202
205
|
}
|
|
203
206
|
return created;
|
|
204
207
|
});
|
|
205
|
-
return json(
|
|
208
|
+
return json(await roomPayload(room), 201);
|
|
206
209
|
}
|
|
207
210
|
if (req.method === "GET" && p === "/inbox") {
|
|
208
211
|
const sessionID = url.searchParams.get("sessionID") ?? "";
|
|
@@ -352,7 +355,7 @@ async function handle(req: Request): Promise<Response> {
|
|
|
352
355
|
return svc.getRoom(roomId);
|
|
353
356
|
});
|
|
354
357
|
touchActive(sessionID); // join = active
|
|
355
|
-
return json(
|
|
358
|
+
return json(await roomPayload(room), 201);
|
|
356
359
|
}
|
|
357
360
|
if (req.method === "POST" && m[2] === "leave") {
|
|
358
361
|
await mutate((svc, reg) => {
|
|
@@ -400,7 +403,7 @@ async function handle(req: Request): Promise<Response> {
|
|
|
400
403
|
touchActive(sessionID);
|
|
401
404
|
const room = await read((svc) => svc.getRoom(roomId));
|
|
402
405
|
void wakeMentionedSessions(serveWakeUrl, roomId, room.name, text, sessionID, result.message);
|
|
403
|
-
return json(
|
|
406
|
+
return json(await roomPayload(room), 201);
|
|
404
407
|
}
|
|
405
408
|
const result = await appendRoomMessage(roomId, sessionID, text, isQuestion === true);
|
|
406
409
|
if (result.status !== "ok") {
|
|
@@ -411,7 +414,7 @@ async function handle(req: Request): Promise<Response> {
|
|
|
411
414
|
const room = await read((svc) => svc.getRoom(roomId));
|
|
412
415
|
// ponytail: 即时唤起——仅 @ 点名成员时(核心需求)
|
|
413
416
|
void wakeMentionedSessions(serveWakeUrl, roomId, room.name, text, sessionID, result.message);
|
|
414
|
-
return json(
|
|
417
|
+
return json(await roomPayload(room), 201);
|
|
415
418
|
}
|
|
416
419
|
}
|
|
417
420
|
const questions = p.match(/^\/rooms\/([^/]+)\/questions$/);
|
|
@@ -445,7 +448,7 @@ async function handle(req: Request): Promise<Response> {
|
|
|
445
448
|
const room = await read((svc) =>
|
|
446
449
|
svc.getRoom(decodeURIComponent(g[1]!)),
|
|
447
450
|
);
|
|
448
|
-
return json(
|
|
451
|
+
return json(await roomPayload(room));
|
|
449
452
|
}
|
|
450
453
|
const r = p.match(/^\/rooms\/([^/]+)\/registry$/);
|
|
451
454
|
if (r && req.method === "GET") {
|
package/server/chat.html
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
<option value="zh-CN">中文</option>
|
|
30
30
|
</select>
|
|
31
31
|
</div>
|
|
32
|
-
<p class="wordmark" data-i18n="brand">OC Chat</p>
|
|
32
|
+
<div class="wordmark-row"><p class="wordmark" data-i18n="brand">OC Chat</p><span class="version-tag">{{version}}</span></div>
|
|
33
33
|
<p class="tagline" data-i18n="tagline">A lightweight chat room. Enter a room ID to join, or create a new one.</p>
|
|
34
34
|
|
|
35
35
|
<form id="joinForm" novalidate>
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
<!-- Shared room workspace. -->
|
|
80
80
|
<section id="chatView" class="view" hidden>
|
|
81
81
|
<aside id="roomRail" class="room-rail" aria-label="Rooms" data-i18n-aria-label="roomsLabel">
|
|
82
|
-
<div class="rail-brand"><span class="brand-mark">OC</span><span data-i18n="brand">OC Chat</span></div>
|
|
82
|
+
<div class="rail-brand"><span class="brand-mark">OC</span><span data-i18n="brand">OC Chat</span><span class="version-tag">{{version}}</span></div>
|
|
83
83
|
<div class="rail-label"><span data-i18n="existingRooms">Rooms</span><span class="rail-tools"><button id="btnNewRoom" class="icon-btn" type="button" aria-label="Create a room" data-i18n-aria-label="newRoom"><svg aria-hidden="true" viewBox="0 0 24 24"><path d="M12 5v14M5 12h14"/></svg></button><button id="btnRefreshRooms" class="icon-btn" type="button" aria-label="Refresh rooms" data-i18n-aria-label="refreshRooms"><svg aria-hidden="true" viewBox="0 0 24 24"><path d="M20 7v5h-5M4 17v-5h5"/><path d="M5.6 9a7 7 0 0 1 11.8-2L20 12M4 12l2.6 5a7 7 0 0 0 11.8-2"/></svg></button></span></div>
|
|
84
84
|
<form id="railRoomForm" class="rail-composer" hidden>
|
|
85
85
|
<label class="field"><span class="field-label" data-i18n="newRoomNameLabel">New room name</span><input id="inRoomNameChat" class="input" maxlength="40" data-i18n-placeholder="newRoomNamePlaceholder" placeholder="e.g. Weekend movie night"></label>
|
|
@@ -99,25 +99,20 @@
|
|
|
99
99
|
<button class="btn ghost small" type="button" data-token-save="inTokenChat" data-i18n="save">Save</button>
|
|
100
100
|
<p id="tokenHint" class="hint" data-i18n="tokenRequired" hidden>The server requires an access token (401).</p>
|
|
101
101
|
<p class="hint" data-i18n="privacyNote">Anyone with the shared token can read direct messages and manage rooms; the server can read them too.</p>
|
|
102
|
-
<details class="admin-access" aria-labelledby="adminAccessHeading">
|
|
103
|
-
<summary id="adminAccessHeading" data-i18n="adminAccess">Administration</summary>
|
|
104
|
-
<label class="field"><span class="field-label" data-i18n="adminToken">Administration token</span><input id="inAdminToken" class="input" type="password" autocomplete="off" spellcheck="false"></label>
|
|
105
|
-
<button id="btnSaveAdminToken" class="btn ghost small" type="button" data-i18n="save">Save</button>
|
|
106
|
-
<p id="adminAccessError" class="hint danger-text" role="alert" hidden></p>
|
|
107
|
-
<button id="btnOpenAdmin" class="btn ghost small" type="button" data-i18n="openAdministration" hidden>Open administration</button>
|
|
108
|
-
</details>
|
|
109
102
|
</div>
|
|
110
103
|
</div>
|
|
111
104
|
</div>
|
|
112
105
|
</aside>
|
|
113
|
-
<dialog id="
|
|
114
|
-
<header class="admin-dialog-head"><h2 id="
|
|
115
|
-
<p id="
|
|
116
|
-
<
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
106
|
+
<dialog id="editRoomDialog" class="admin-dialog" aria-labelledby="editRoomHeading">
|
|
107
|
+
<header class="admin-dialog-head"><h2 id="editRoomHeading" data-i18n="editRoom">Edit room</h2><div class="admin-dialog-actions"><button id="btnCloseEditRoom" class="reader-close" type="button" aria-label="Close" data-i18n-aria-label="close">×</button></div></header>
|
|
108
|
+
<p id="editRoomStatus" class="hint" role="status" aria-live="polite"></p>
|
|
109
|
+
<form id="editRoomForm" class="admin-guide">
|
|
110
|
+
<label class="field"><span class="field-label" data-i18n="roomNameLabel">Room name</span><input id="editRoomName" class="input" maxlength="64" autocomplete="off" required></label>
|
|
111
|
+
<label class="field"><span class="field-label" data-i18n="roomDescriptionLabel">Description</span><textarea id="editRoomDescription" class="input" rows="3" maxlength="2000"></textarea></label>
|
|
112
|
+
<label class="field"><span class="field-label" data-i18n="adminAgentLabel">Administrator agent</span><select id="editRoomAdmin" class="admin-select"></select></label>
|
|
113
|
+
<p class="hint" data-i18n="adminAgentHint">The designated agent can inspect all rooms and their history with the admin tool. Leave empty for none.</p>
|
|
114
|
+
<button class="btn primary small" type="submit" data-i18n="save">Save</button>
|
|
115
|
+
</form>
|
|
121
116
|
</dialog>
|
|
122
117
|
<button id="roomDrawerBackdrop" class="room-drawer-backdrop" type="button" aria-label="Close room list" data-i18n-aria-label="closeRoomList" hidden></button>
|
|
123
118
|
<header class="chat-head">
|
|
@@ -128,6 +123,7 @@
|
|
|
128
123
|
<span class="mono" id="roomIdShort"></span><span class="copy-ok" data-i18n="copied">Copied</span>
|
|
129
124
|
</button>
|
|
130
125
|
</p>
|
|
126
|
+
<p id="roomDescription" class="room-description" hidden></p>
|
|
131
127
|
</div>
|
|
132
128
|
<div class="chat-head-actions">
|
|
133
129
|
<div class="anchor questions-anchor">
|
|
@@ -184,6 +180,7 @@
|
|
|
184
180
|
<div class="anchor room-options-anchor">
|
|
185
181
|
<button class="chip" type="button" id="btnRoomOptions" aria-haspopup="true" aria-expanded="false" aria-controls="roomOptions"><svg class="action-icon" aria-hidden="true" viewBox="0 0 24 24"><circle cx="5" cy="12" r="1"/><circle cx="12" cy="12" r="1"/><circle cx="19" cy="12" r="1"/></svg><span class="action-label" data-i18n="roomOptions">Options</span></button>
|
|
186
182
|
<div class="panel room-options-panel" id="roomOptions" hidden>
|
|
183
|
+
<button class="menu-action" type="button" id="btnEditRoom" data-i18n="editRoom" hidden>Edit room</button>
|
|
187
184
|
<button class="menu-action" type="button" id="btnLeave" data-i18n="leave">Leave room</button>
|
|
188
185
|
<button class="menu-action danger-text" type="button" id="btnDeleteRoom" data-i18n="deleteRoom">Delete room</button>
|
|
189
186
|
</div>
|
|
@@ -230,7 +227,6 @@
|
|
|
230
227
|
<button class="btn primary" type="button" id="btnSend" data-i18n="send" disabled>Send</button>
|
|
231
228
|
</div>
|
|
232
229
|
<div class="composer-meta">
|
|
233
|
-
<label class="question-toggle"><input id="questionToggle" type="checkbox"><span data-i18n="sendAsQuestion">Send as a question</span></label>
|
|
234
230
|
<p id="draftCount" class="draft-count">0 / 2000</p>
|
|
235
231
|
</div>
|
|
236
232
|
</footer>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export async function jsonObject<T>(req: Request): Promise<T | undefined> {
|
|
2
|
+
try {
|
|
3
|
+
const value: unknown = await req.json();
|
|
4
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value as T : undefined;
|
|
5
|
+
} catch {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
}
|