@alexsun-top/opencode-chat-room 0.4.0 → 0.5.1
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 +29 -0
- package/README.md +38 -5
- package/README.zh-CN.md +34 -4
- package/docs/administrator-rooms.md +51 -0
- package/package.json +11 -1
- package/plugin.ts +28 -17
- package/server/admin-auth.ts +16 -0
- package/server/admin-plan-routes.ts +79 -0
- package/server/admin-routes.ts +154 -0
- package/server/admin-scheduler.ts +42 -0
- package/server/admin-state.ts +61 -0
- package/server/admin-task-routes.ts +182 -0
- package/server/announcement-routes.ts +34 -0
- package/server/assets/MERMAID-LICENSE +21 -0
- package/server/assets/NOTICE.txt +2 -1
- package/server/assets/base.css +60 -43
- package/server/assets/chat/admin.js +196 -0
- package/server/assets/chat/announcements.js +119 -0
- package/server/assets/chat/attachments.js +240 -0
- package/server/assets/chat/events.js +206 -10
- package/server/assets/chat/index.js +6 -0
- package/server/assets/chat/markdown.js +208 -16
- package/server/assets/chat/members.js +5 -2
- package/server/assets/chat/messages.js +85 -23
- package/server/assets/chat/receipts.js +22 -17
- package/server/assets/chat/rooms.js +32 -10
- package/server/assets/chat/state.js +88 -22
- package/server/assets/conversation.css +100 -40
- package/server/assets/mermaid-11.12.2.min.js +2811 -0
- package/server/assets/responsive.css +108 -49
- package/server/chat-server.ts +10 -11
- package/server/chat.html +85 -32
- package/server/member-routes.ts +3 -0
- package/server/newrooms.ts +29 -10
- package/server/resource-routes.ts +68 -0
- package/server/wake.ts +7 -14
- package/skills/chatroom/SKILL.md +104 -0
- package/src/admin-client.ts +130 -0
- package/src/admin-credentials.ts +58 -0
- package/src/agent-receipts.ts +4 -4
- package/src/announcement-tool.ts +25 -0
- package/src/announcements.ts +16 -0
- package/src/center-client.ts +27 -1
- package/src/center-inbox.ts +11 -9
- package/src/chatroom-skill.ts +15 -0
- package/src/plugin-notifications.ts +7 -9
- package/src/resource-upload.ts +50 -0
- package/src/resources.ts +104 -0
- package/src/sqlite-state.ts +81 -12
- package/src/store.ts +1 -10
- package/src/supervision-inbox.ts +62 -0
- package/src/v1-plugin.ts +19 -4
- package/src/v2-plugin.ts +45 -8
|
@@ -5,15 +5,19 @@ export function initRooms(app) {
|
|
|
5
5
|
const $ = app.$;
|
|
6
6
|
|
|
7
7
|
app.showJoin = (refresh = true) => {
|
|
8
|
+
document.documentElement.classList.remove("session-restore");
|
|
8
9
|
if (!$("#inName").value) $("#inName").value = LS.name;
|
|
9
10
|
$("#chatView").hidden = true;
|
|
11
|
+
$("#restoreView").hidden = true;
|
|
10
12
|
$("#joinView").hidden = false;
|
|
11
13
|
app.updateTitle();
|
|
12
14
|
if (refresh) void app.refreshRoomList();
|
|
13
15
|
$("#inRoomId").focus();
|
|
14
16
|
};
|
|
15
17
|
app.showChat = () => {
|
|
18
|
+
document.documentElement.classList.remove("session-restore");
|
|
16
19
|
$("#joinView").hidden = true;
|
|
20
|
+
$("#restoreView").hidden = true;
|
|
17
21
|
$("#chatView").hidden = false;
|
|
18
22
|
};
|
|
19
23
|
app.renderHead = () => {
|
|
@@ -21,7 +25,8 @@ export function initRooms(app) {
|
|
|
21
25
|
$("#roomIdShort").textContent = app.state.room.id.slice(0, 8);
|
|
22
26
|
$("#btnCopyId").title = app.t("copyRoomIdTitle", { id: app.state.room.id });
|
|
23
27
|
$("#btnCopyId").setAttribute("aria-label", app.t("copyRoomId"));
|
|
24
|
-
|
|
28
|
+
$("#railIdentity").textContent = app.state.myName;
|
|
29
|
+
$("#profileAvatar").textContent = Array.from(app.state.myName.trim())[0]?.toLocaleUpperCase() || "?";
|
|
25
30
|
app.updateTitle();
|
|
26
31
|
};
|
|
27
32
|
|
|
@@ -40,6 +45,7 @@ export function initRooms(app) {
|
|
|
40
45
|
const entry = existing || { unreadIds: new Map(), unreadOverflow: false, preview: "", previewAt: 0, position: 0, readTs: 0, receivedTs: room.messages.at(-1)?.createdAt ?? 0 };
|
|
41
46
|
entry.unreadIds ||= new Map();
|
|
42
47
|
entry.unreadOverflow ||= false;
|
|
48
|
+
entry.readTs ||= app.state.lastReadTs.get(room.id) || 0;
|
|
43
49
|
entry.room = room;
|
|
44
50
|
entry.name = name;
|
|
45
51
|
const latest = room.messages.at(-1);
|
|
@@ -60,13 +66,12 @@ export function initRooms(app) {
|
|
|
60
66
|
if (app.state.room?.id === roomId) return;
|
|
61
67
|
if (app.state.room) {
|
|
62
68
|
app.saveDraft(app.state.room.id, $("#msgInput").value);
|
|
63
|
-
app.
|
|
69
|
+
app.captureReadingPosition?.();
|
|
64
70
|
}
|
|
65
71
|
app.stopPolling();
|
|
66
72
|
app.state.room = entry.room;
|
|
67
73
|
app.state.myName = entry.name;
|
|
68
|
-
const
|
|
69
|
-
entry.position = app.state.positions.get(roomId) ?? entry.position;
|
|
74
|
+
const savedPosition = app.state.positions.get(roomId);
|
|
70
75
|
app.state.unread = entry.unreadIds.size + (entry.unreadOverflow ? 100 : 0);
|
|
71
76
|
app.rendered = 0;
|
|
72
77
|
app.firstMessageId = null;
|
|
@@ -76,9 +81,11 @@ export function initRooms(app) {
|
|
|
76
81
|
app.renderHead();
|
|
77
82
|
$("#msgList").textContent = "";
|
|
78
83
|
app.renderMessages(false);
|
|
84
|
+
const restoredPosition = app.restoreReadingPosition?.(roomId);
|
|
85
|
+
app.state.readAnchorGuard = restoredPosition ? { roomId, ...restoredPosition } : null;
|
|
79
86
|
app.startPolling();
|
|
80
87
|
app.renderMembers();
|
|
81
|
-
$("#thread").scrollTop =
|
|
88
|
+
if (!restoredPosition) $("#thread").scrollTop = typeof savedPosition === "number" ? savedPosition : entry.position || $("#thread").scrollHeight;
|
|
82
89
|
$("#msgInput").disabled = false;
|
|
83
90
|
$("#msgInput").value = app.state.drafts.get(roomId) || "";
|
|
84
91
|
app.renderFailedMessages();
|
|
@@ -88,10 +95,11 @@ export function initRooms(app) {
|
|
|
88
95
|
app.hideSendError();
|
|
89
96
|
app.updateBadge();
|
|
90
97
|
app.updateJump();
|
|
91
|
-
app.markActiveRoomRead();
|
|
98
|
+
if (!restoredPosition) app.markActiveRoomRead();
|
|
92
99
|
app.renderRoomOptions($("#roomList"), app.state.availableRooms || []);
|
|
93
100
|
app.renderRoomOptions($("#roomListChat"), app.state.availableRooms || []);
|
|
94
101
|
void app.refreshRoomList();
|
|
102
|
+
document.dispatchEvent(new CustomEvent("chat-room-activated", { detail: roomId }));
|
|
95
103
|
};
|
|
96
104
|
|
|
97
105
|
app.joinRoom = async (roomId, name) => {
|
|
@@ -162,10 +170,11 @@ export function initRooms(app) {
|
|
|
162
170
|
app.removeJoinedRoom = async (roomId, { leaveServer = false, reason = false } = {}) => {
|
|
163
171
|
const active = app.state.room?.id === roomId;
|
|
164
172
|
const entry = app.state.rooms.get(roomId);
|
|
173
|
+
app.disposeRoomAttachments?.(roomId);
|
|
165
174
|
if (active) {
|
|
166
175
|
app.state.navigationGeneration++;
|
|
167
176
|
app.saveDraft(roomId, $("#msgInput").value);
|
|
168
|
-
app.
|
|
177
|
+
app.captureReadingPosition?.();
|
|
169
178
|
app.stopPolling();
|
|
170
179
|
app.closeMention();
|
|
171
180
|
app.state.room = null;
|
|
@@ -231,7 +240,11 @@ export function initRooms(app) {
|
|
|
231
240
|
empty.hidden = rooms.length > 0;
|
|
232
241
|
chatEmpty.hidden = rooms.length > 0;
|
|
233
242
|
} catch (error) {
|
|
234
|
-
if (error.status === 401)
|
|
243
|
+
if (error.status === 401) {
|
|
244
|
+
if (!app.state.room && !app.state.restored) { app.showJoin(false); app.openTokenBox(); app.showJoinError("authRetry"); }
|
|
245
|
+
else app.state.room ? app.openChatSettings() : app.openTokenBox();
|
|
246
|
+
}
|
|
247
|
+
else if (!app.state.restored && !app.state.room) app.showRestoreFailure(app.t("networkRetry"));
|
|
235
248
|
else {
|
|
236
249
|
app.setText(empty, "roomListError");
|
|
237
250
|
app.setText(chatEmpty, "roomListError");
|
|
@@ -258,6 +271,7 @@ export function initRooms(app) {
|
|
|
258
271
|
const candidates = [...new Set([activeId, ...rooms.filter((room) => room.joined).map((room) => room.id), ...app.state.joinedIds, ...directIds].filter(Boolean))];
|
|
259
272
|
const valid = new Set();
|
|
260
273
|
const unresolved = new Set();
|
|
274
|
+
let authFailed = false;
|
|
261
275
|
await bounded(candidates, 3, async (roomId) => {
|
|
262
276
|
try {
|
|
263
277
|
const room = rooms.find((item) => item.id === roomId) || await app.api(`/rooms/${encodeURIComponent(roomId)}`);
|
|
@@ -269,6 +283,7 @@ export function initRooms(app) {
|
|
|
269
283
|
} catch (error) {
|
|
270
284
|
if (error.status !== 404) {
|
|
271
285
|
unresolved.add(roomId);
|
|
286
|
+
if (error.status === 401) authFailed = true;
|
|
272
287
|
if (error.status === 401) app.state.room ? app.openChatSettings() : app.openTokenBox();
|
|
273
288
|
}
|
|
274
289
|
}
|
|
@@ -277,12 +292,16 @@ export function initRooms(app) {
|
|
|
277
292
|
app.state.restorePending = unresolved;
|
|
278
293
|
app.saveJoinedIds();
|
|
279
294
|
app.state.restored = unresolved.size === 0;
|
|
295
|
+
if (authFailed) { app.showJoin(false); app.openTokenBox(); app.showJoinError("authRetry"); return; }
|
|
280
296
|
if (activeId && valid.has(activeId)) app.activateRoom(activeId);
|
|
281
|
-
else if (activeId && unresolved.has(activeId))
|
|
297
|
+
else if (activeId && unresolved.has(activeId)) {
|
|
298
|
+
app.showRestoreFailure(app.t("networkRetry"));
|
|
299
|
+
}
|
|
282
300
|
else {
|
|
283
301
|
LS.roomId = "";
|
|
284
302
|
const fallback = valid.values().next().value;
|
|
285
303
|
if (fallback) app.activateRoom(fallback);
|
|
304
|
+
else if (unresolved.size) app.showRestoreFailure(app.t("networkRetry"));
|
|
286
305
|
else app.showJoin(false);
|
|
287
306
|
}
|
|
288
307
|
app.startRoomWatcher();
|
|
@@ -357,6 +376,7 @@ export function initRooms(app) {
|
|
|
357
376
|
document.querySelectorAll(".panel").forEach((panel) => { panel.hidden = true; });
|
|
358
377
|
$("#btnMembers").setAttribute("aria-expanded", "false");
|
|
359
378
|
$("#btnSettings").setAttribute("aria-expanded", "false");
|
|
379
|
+
$("#btnRoomOptions").setAttribute("aria-expanded", "false");
|
|
360
380
|
};
|
|
361
381
|
app.togglePanel = (selector) => {
|
|
362
382
|
const panel = $(selector), wasHidden = panel.hidden;
|
|
@@ -375,6 +395,7 @@ export function initRooms(app) {
|
|
|
375
395
|
app.openTokenBox = () => { $("#tokenBox").open = true; };
|
|
376
396
|
app.openChatSettings = () => {
|
|
377
397
|
app.closePanels();
|
|
398
|
+
app.lastFocus = $("#btnSettings");
|
|
378
399
|
$("#chatSettings").hidden = false;
|
|
379
400
|
$("#btnSettings").setAttribute("aria-expanded", "true");
|
|
380
401
|
$("#tokenHint").hidden = false;
|
|
@@ -387,12 +408,13 @@ export function initRooms(app) {
|
|
|
387
408
|
try {
|
|
388
409
|
await app.api(`/rooms/${encodeURIComponent(room.id)}`, {
|
|
389
410
|
method: "DELETE", body: JSON.stringify({ sessionID: LS.sessionID }),
|
|
411
|
+
headers: LS.adminToken ? { "X-Chat-Admin-Token": LS.adminToken } : {},
|
|
390
412
|
});
|
|
391
413
|
await app.removeJoinedRoom(room.id);
|
|
392
414
|
app.clearDraft(room.id);
|
|
393
415
|
app.clearPosition(room.id);
|
|
394
416
|
app.saveFailedMessages(room.id, []);
|
|
395
|
-
} catch (error) { app.showSendError("sendFailed", { message: error.message }); }
|
|
417
|
+
} catch (error) { app.showSendError(error.status === 403 && error.message.includes("operator token required") ? "adminRoomDeleteDenied" : "sendFailed", { message: error.message }); }
|
|
396
418
|
};
|
|
397
419
|
|
|
398
420
|
app.copyRoomId = async () => {
|
|
@@ -7,7 +7,8 @@ export const app = {
|
|
|
7
7
|
receiptObservation: null,
|
|
8
8
|
memberApiUnavailable: new Set(), receiptApiUnavailable: new Set(),
|
|
9
9
|
receipts: new Map(), acknowledgedMessages: new Map(), pendingAcknowledgements: new Map(),
|
|
10
|
-
pendingAction: null, watcherTimer: 0, restored: false,
|
|
10
|
+
pendingAction: null, watcherTimer: 0, restored: false, resizeScrollAdjusting: false, layoutScrollAdjusting: false,
|
|
11
|
+
readAnchorGuard: null, userScrollIntentUntil: 0,
|
|
11
12
|
},
|
|
12
13
|
rendered: 0,
|
|
13
14
|
firstMessageId: null,
|
|
@@ -131,6 +132,7 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
131
132
|
get name() { return ensureIdentity().name; },
|
|
132
133
|
set name(value) { ensureIdentity(); browserIdentity.name = String(value ?? "").slice(0, 64); writeSession("chat.name", browserIdentity.name || null); saveIdentity(); },
|
|
133
134
|
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); },
|
|
134
136
|
get locale() { return read("chat.locale") || "en"; }, set locale(value) { write("chat.locale", value || null); },
|
|
135
137
|
get joinedRoomIds() {
|
|
136
138
|
try {
|
|
@@ -145,6 +147,8 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
145
147
|
set drafts(value) { writeSession("chat.drafts", JSON.stringify(value)); },
|
|
146
148
|
get positions() { try { return JSON.parse(readSession("chat.positions") || "{}"); } catch { return {}; } },
|
|
147
149
|
set positions(value) { writeSession("chat.positions", JSON.stringify(value)); },
|
|
150
|
+
get readTs() { try { return JSON.parse(readSession("chat.readTs") || "{}"); } catch { return {}; } },
|
|
151
|
+
set readTs(value) { writeSession("chat.readTs", JSON.stringify(value)); },
|
|
148
152
|
get failedMessages() {
|
|
149
153
|
try {
|
|
150
154
|
const value = JSON.parse(readSession("chat.failedMessages") || "{}");
|
|
@@ -154,10 +158,10 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
154
158
|
set failedMessages(value) { writeSession("chat.failedMessages", JSON.stringify(value)); },
|
|
155
159
|
};
|
|
156
160
|
const saveToken = (value) => { auth.token = String(value ?? "").trim(); return auth.token; };
|
|
157
|
-
const
|
|
161
|
+
const apiResponse = async (url, options = {}) => {
|
|
158
162
|
assertIdentity();
|
|
159
163
|
const headers = { ...options.headers };
|
|
160
|
-
if (options.body) headers["Content-Type"] = "application/json";
|
|
164
|
+
if (typeof options.body === "string" && !headers["Content-Type"]) headers["Content-Type"] = "application/json";
|
|
161
165
|
if (auth.token) headers.Authorization = `Bearer ${auth.token}`;
|
|
162
166
|
let response;
|
|
163
167
|
try { response = await (fetcher ?? globalThis.fetch)(url, { ...options, headers }); }
|
|
@@ -166,16 +170,31 @@ export function createAuth(storage, fetcher, translate = (key) => key, sessionSt
|
|
|
166
170
|
error.network = true;
|
|
167
171
|
throw error;
|
|
168
172
|
}
|
|
169
|
-
const data = await response.json().catch(() => ({}));
|
|
170
173
|
assertIdentity();
|
|
171
174
|
if (!response.ok) {
|
|
175
|
+
const data = await response.clone().json().catch(() => ({}));
|
|
176
|
+
assertIdentity();
|
|
172
177
|
const error = new Error(data.error || translate("requestFailed", { status: response.status }));
|
|
173
178
|
error.status = response.status;
|
|
174
179
|
throw error;
|
|
175
180
|
}
|
|
176
|
-
return
|
|
181
|
+
return response;
|
|
182
|
+
};
|
|
183
|
+
const api = async (url, options) => {
|
|
184
|
+
const response = await apiResponse(url, options), data = await response.json().catch(() => ({}));
|
|
185
|
+
assertIdentity(); return data;
|
|
186
|
+
};
|
|
187
|
+
const apiBlob = async (url, options) => {
|
|
188
|
+
const response = await apiResponse(url, options), blob = await response.blob();
|
|
189
|
+
assertIdentity(); return blob;
|
|
177
190
|
};
|
|
178
|
-
|
|
191
|
+
const adminApi = async (url, options = {}) => {
|
|
192
|
+
if (!url.startsWith("/admin/") || !auth.adminToken) throw new Error("Administration token is required");
|
|
193
|
+
const response = await apiResponse(url, { ...options, headers: { ...options.headers, "X-Chat-Admin-Token": auth.adminToken } });
|
|
194
|
+
const data = await response.json().catch(() => ({}));
|
|
195
|
+
assertIdentity(); return data;
|
|
196
|
+
};
|
|
197
|
+
return { LS: auth, saveToken, api, apiBlob, adminApi };
|
|
179
198
|
}
|
|
180
199
|
|
|
181
200
|
const messages = {
|
|
@@ -183,6 +202,7 @@ const messages = {
|
|
|
183
202
|
brand: "OC Chat", documentTitle: "OC Chat",
|
|
184
203
|
roomTitle: ({ name }) => `${name} · OC Chat`,
|
|
185
204
|
tagline: "A lightweight chat room. Enter a room ID to join, or create a new one.",
|
|
205
|
+
restoringSession: "Restoring your session…", retry: "Retry", roomOptions: "Options",
|
|
186
206
|
languageLabel: "Language", roomIdLabel: "Room ID", roomIdPlaceholder: "Paste or enter a room ID",
|
|
187
207
|
nameLabel: "Your name", namePlaceholder: "What should we call you?", joinRoom: "Join room",
|
|
188
208
|
or: "or", newRoomNameLabel: "New room name", newRoomNamePlaceholder: "e.g. Weekend movie night",
|
|
@@ -192,24 +212,35 @@ const messages = {
|
|
|
192
212
|
existingRooms: "Rooms", noRooms: "No rooms yet. Create one.", copyRoomId: "Copy room ID",
|
|
193
213
|
newRoom: "Create a room",
|
|
194
214
|
copyRoomIdTitle: ({ id }) => `Click to copy the full room ID: ${id}`, copied: "Copied",
|
|
195
|
-
members: "Members", membersCount: ({ count }) => `Members (${count})`, noMembers: "No members yet.",
|
|
215
|
+
members: "Members", membersCount: ({ count }) => `Members (${count})`, noMembers: "No members yet.", profileMenu: "Your profile and settings",
|
|
196
216
|
questions: "Questions", pendingQuestions: "Pending questions", refreshQuestions: "Refresh",
|
|
217
|
+
announcements: "Announcements", announcementName: "Name", announcementContent: "Content",
|
|
218
|
+
diagramLoading: "Rendering diagram…", diagramRenderFailed: "Diagram unavailable; showing its source.", resourceLoading: "Loading file…", resourceFailed: "This file could not be loaded.", resourceDownload: "Download", resourcePreview: "Preview", resourceHide: "Hide preview",
|
|
219
|
+
announcementDelete: "Delete announcement",
|
|
220
|
+
announcementNew: "New announcement", announcementEmpty: "No announcements yet.", announcementLoading: "Loading announcements…",
|
|
221
|
+
announcementLoadFailed: "Could not load announcements. Your draft is still here.", announcementSaved: "Announcement saved.", announcementDeleted: "Announcement deleted.",
|
|
222
|
+
announcementDuplicate: "That name already exists. Select it to edit, or choose another name.", announcementDeleteConfirm: ({ name }) => `Delete “${name}”?`, announcementCount: ({ count }) => `${count} / 5000`, announcementInvalid: "Use a name of 1–64 characters and content up to 5000 characters.",
|
|
197
223
|
questionsLoading: "Loading questions…", questionsEmpty: "No unanswered questions.",
|
|
198
224
|
questionsFailed: "Could not load questions. Try again.", questionLabel: "Question",
|
|
199
225
|
answerQuestion: "Reply", answerPlaceholder: "Write a reply…", sendAnswer: "Send reply",
|
|
200
226
|
answerFailed: "Reply failed. Your draft is still here.", questionAlreadyAnswered: "This question was answered elsewhere.",
|
|
201
227
|
sendAsQuestion: "Send as a question",
|
|
202
|
-
settings: "Settings", tokenRequired: "The server requires an access token (401).",
|
|
228
|
+
settings: "Settings", adminAccess: "Administration", adminToken: "Administration token", openAdministration: "Open administration", administration: "Administration", designations: "Designations", adminRoom: "Admin room", targetRoom: "Agent room", targetAgent: "Registered agent", designate: "Designate and issue enrollment", 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).",
|
|
229
|
+
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.", privateEnrollment: ({ expires }) => `Copy this instruction and paste it privately into the selected agent session. Expires ${expires}. Never post it in a room.`, copyEnrollment: "Copy private instruction", enrollmentCopied: "Private instruction copied.", 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}”?`,
|
|
203
230
|
leave: "Leave", reconnecting: "Connection lost. Retrying…", messageList: "Message list",
|
|
204
231
|
noMessages: "No messages yet. Say something.", latestMessages: "Back to latest messages",
|
|
205
|
-
mentionMembers: "Choose a member to mention", messagePlaceholder: "Message · Enter
|
|
232
|
+
mentionMembers: "Choose a member to mention", messagePlaceholder: "Message · Enter to send",
|
|
233
|
+
attachments: "Attachments", addFiles: "Add files", dropFilesHere: "Drop files here to attach",
|
|
234
|
+
attachmentVolatile: "File attachments are held in this tab and are cleared if you reload.", retryUpload: "Retry", removeFile: "Remove",
|
|
235
|
+
uploadQueued: "Waiting to upload", uploadReady: "Ready to send", uploadPercent: ({ percent }) => `Uploading ${percent}%`,
|
|
236
|
+
uploadFailed: "Upload failed. Retry or remove the file.",
|
|
237
|
+
fileTooLarge: "File exceeds the server's current size limit.",
|
|
206
238
|
send: "Send", roomMeta: ({ members, count }) => `${members} ${members === 1 ? "member" : "members"} · ${count} ${count === 1 ? "message" : "messages"}`,
|
|
207
239
|
joinArrow: "Join →", joinDirectTitle: "Click to join directly", mentionEmpty: "No matching members",
|
|
208
240
|
joined: "Joined", joinAction: "Join room", unreadMessages: ({ count }) => `${count} unread`,
|
|
209
241
|
mentionHint: "↑↓ Select · Enter to confirm · Esc to close", today: "Today", yesterday: "Yesterday",
|
|
210
|
-
earlierMessages: "Earlier messages omitted", you: "You", saved: "Saved",
|
|
242
|
+
earlierMessages: "Earlier messages omitted", messagesBetweenOmitted: "Messages between this reading point and latest are omitted.", you: "You", saved: "Saved",
|
|
211
243
|
savedMemory: "Saved for this tab only", copyFailed: ({ id }) => `Copy failed. Copy manually: ${id}`,
|
|
212
|
-
copyCode: "Copy code", copiedCode: "Copied", copyCodeFailed: "Could not copy code. Select and copy it manually.",
|
|
213
244
|
copyMessage: "Copy", copiedMessage: "Copied", copyMessageFailed: "Could not copy. Select and copy the message manually.",
|
|
214
245
|
identityChanged: "This browser identity changed in another tab. Reload this tab before continuing.",
|
|
215
246
|
networkError: "Network connection failed", requestFailed: ({ status }) => `Request failed (HTTP ${status})`,
|
|
@@ -220,9 +251,11 @@ const messages = {
|
|
|
220
251
|
roomNotFound: "This room is gone, or you no longer have access.",
|
|
221
252
|
sendAuth: "Send failed: an access token is required", sendNetwork: "Send failed. Your message is saved below.",
|
|
222
253
|
sendFailed: ({ message }) => `Send failed: ${message}`,
|
|
254
|
+
adminRoomDeleteDenied: "This room is designated for administration. Enter the Administration token in Settings to delete it.",
|
|
223
255
|
failedMessages: "Messages not sent", retryFailed: "Retry", discardFailed: "Discard",
|
|
224
256
|
roomListError: "Unable to load rooms. You can enter a room ID directly.", guest: "Guest",
|
|
225
257
|
roomsLabel: "Rooms", refreshRooms: "Refresh rooms", identityLabel: ({ name }) => `Chatting as ${name}`,
|
|
258
|
+
roomsMenu: "Open room list", closeRoomList: "Close room list",
|
|
226
259
|
direct: "Direct", messagePrivately: "Message privately", removeMember: "Remove",
|
|
227
260
|
kickConfirm: ({ name, id }) => `Remove ${name} (session ${id}) from this room?`,
|
|
228
261
|
deleteRoom: "Delete room", deleteConfirm: ({ name }) => `Delete “${name}” and all its messages? This cannot be undone.`,
|
|
@@ -232,11 +265,12 @@ const messages = {
|
|
|
232
265
|
activity_working: "Working", activity_idle: "Foreground idle", activity_waiting: "Waiting", activity_unknown: "Status unknown", activity_offline: "Status stale",
|
|
233
266
|
activityHint_working: "The agent reports active work.", activityHint_idle: "Foreground is idle; background work may continue.", activityHint_waiting: "The agent reports that it is waiting.", activityHint_unknown: "No activity report is available.", activityHint_offline: "The last status is stale; this does not prove the agent is offline.",
|
|
234
267
|
receiptCount: ({ count }) => `Read by ${count}`, receiptNone: "No readers yet", receiptNotLoaded: "Read status not loaded", readerPanelTitle: "Message readers", close: "Close", departedMember: "left",
|
|
235
|
-
receiptEvidence_displayed: "Shown on screen", receiptEvidence_tool: "Fetched with room tool", receiptEvidence_context: "
|
|
268
|
+
receiptEvidence_displayed: "Shown on screen", receiptEvidence_tool: "Fetched with room tool", receiptEvidence_context: "In agent context",
|
|
236
269
|
},
|
|
237
270
|
"zh-CN": {
|
|
238
271
|
brand: "OC Chat", documentTitle: "OC Chat", roomTitle: ({ name }) => `${name} · OC Chat`,
|
|
239
272
|
tagline: "一个轻量的聊天房间。输入房间 ID 加入,或直接新建一个。", languageLabel: "语言",
|
|
273
|
+
restoringSession: "正在恢复会话…", retry: "重试", roomOptions: "选项",
|
|
240
274
|
roomIdLabel: "房间 ID", roomIdPlaceholder: "粘贴或输入房间 ID", nameLabel: "你的昵称",
|
|
241
275
|
namePlaceholder: "怎么称呼你", joinRoom: "加入房间", or: "或", newRoomNameLabel: "新房间名称",
|
|
242
276
|
newRoomNamePlaceholder: "例如:周末电影夜", createRoom: "创建新房间", tokenOptional: "访问令牌(可选)",
|
|
@@ -245,22 +279,34 @@ const messages = {
|
|
|
245
279
|
noRooms: "还没有房间,创建一个吧。", copyRoomId: "复制房间 ID",
|
|
246
280
|
newRoom: "创建房间",
|
|
247
281
|
copyRoomIdTitle: ({ id }) => `点击复制完整房间 ID:${id}`, copied: "已复制", members: "成员",
|
|
248
|
-
membersCount: ({ count }) => `成员 ${count}`, noMembers: "暂无成员", settings: "设置",
|
|
282
|
+
membersCount: ({ count }) => `成员 ${count}`, noMembers: "暂无成员", settings: "设置", profileMenu: "个人资料和设置",
|
|
249
283
|
questions: "提问", pendingQuestions: "待回答的问题", refreshQuestions: "刷新",
|
|
284
|
+
announcements: "公告栏", announcementName: "名称", announcementContent: "内容",
|
|
285
|
+
diagramLoading: "正在渲染图表…", diagramRenderFailed: "图表无法显示,以下为源代码。", resourceLoading: "正在加载文件…", resourceFailed: "无法加载此文件。", resourceDownload: "下载", resourcePreview: "预览", resourceHide: "收起预览",
|
|
286
|
+
announcementDelete: "删除公告",
|
|
287
|
+
announcementNew: "新建公告", announcementEmpty: "暂无公告。", announcementLoading: "正在加载公告…",
|
|
288
|
+
announcementLoadFailed: "无法加载公告,草稿仍已保留。", announcementSaved: "公告已保存。", announcementDeleted: "公告已删除。",
|
|
289
|
+
announcementDuplicate: "此名称已存在。请选择该公告进行编辑,或使用其他名称。", announcementDeleteConfirm: ({ name }) => `删除“${name}”?`, announcementCount: ({ count }) => `${count} / 5000`, announcementInvalid: "名称需为 1–64 个字符,内容不能超过 5000 个字符。",
|
|
250
290
|
questionsLoading: "正在加载问题…", questionsEmpty: "没有待回答的问题。",
|
|
251
291
|
questionsFailed: "无法加载问题,请重试。", questionLabel: "问题",
|
|
252
292
|
answerQuestion: "回复", answerPlaceholder: "写下回复…", sendAnswer: "发送回复",
|
|
253
293
|
answerFailed: "回复失败,草稿仍已保留。", questionAlreadyAnswered: "此问题已由其他人回答。",
|
|
254
294
|
sendAsQuestion: "作为问题发送",
|
|
295
|
+
adminAccess: "管理", adminToken: "管理令牌", openAdministration: "打开管理面板", administration: "管理面板", designations: "管理绑定", adminRoom: "管理房间", targetRoom: "Agent 房间", targetAgent: "已注册 Agent", designate: "绑定并生成加入指令", revokeDesignation: "撤销绑定", globalStatus: "全局状态", adminTasks: "任务", taskText: "任务内容", dispatchTask: "派发任务", timers: "定时任务", planName: "定时任务名称", createTimer: "创建定时任务",
|
|
296
|
+
adminLoading: "正在加载管理面板…", refreshAdmin: "刷新", adminRoomBadge: "管理", chooseAdminRoom: "选择普通房间", chooseTargetRoom: "选择 Agent 房间", chooseAgent: "选择已注册 Agent", taskTargetRoom: "任务目标房间", taskTargetAgent: "任务目标 Agent", createAdminRoomFirst: "请先按普通流程创建房间,再选作管理房间。", noAgents: "没有已注册的 Agent", selectAdminAgent: "请选择管理房间和已注册的 Agent。", privateEnrollment: ({ expires }) => `复制此指令并私下粘贴到指定的 Agent 会话中。有效期至 ${expires}。请勿发送到房间。`, copyEnrollment: "复制私密指令", enrollmentCopied: "私密指令已复制。", revokeConfirm: "撤销此管理绑定?普通房间会保留。", updateTask: "更新任务", task_pending: "待处理", task_working: "进行中", task_blocked: "受阻", task_completed: "已完成", task_cancelled: "已取消", nextRun: ({ time, minutes }) => `每 ${minutes} 分钟 · 下次 ${time}`, paused: "已暂停", pauseTimer: "暂停", resumeTimer: "恢复", deleteTimer: "删除", deleteTimerConfirm: ({ name }) => `删除定时任务“${name}”?`,
|
|
255
297
|
tokenRequired: "服务器要求访问令牌(401)。", leave: "离开", reconnecting: "连接中断,正在重试…",
|
|
256
298
|
messageList: "消息列表", noMessages: "还没有消息,说点什么吧。", latestMessages: "回到最新消息",
|
|
257
|
-
mentionMembers: "选择要提及的成员", messagePlaceholder: "输入消息,Enter
|
|
299
|
+
mentionMembers: "选择要提及的成员", messagePlaceholder: "输入消息,Enter 发送",
|
|
300
|
+
attachments: "附件", addFiles: "添加文件", dropFilesHere: "将文件拖到这里添加",
|
|
301
|
+
attachmentVolatile: "附件仅保存在当前标签页,刷新页面后会清除。", retryUpload: "重试", removeFile: "移除",
|
|
302
|
+
uploadQueued: "等待上传", uploadReady: "可以发送", uploadPercent: ({ percent }) => `正在上传 ${percent}%`,
|
|
303
|
+
uploadFailed: "上传失败,请重试或移除文件。",
|
|
304
|
+
fileTooLarge: "文件超过服务器当前大小限制。",
|
|
258
305
|
send: "发送", roomMeta: ({ members, count }) => `${members} 人 · ${count} 条消息`, joinArrow: "加入 →",
|
|
259
306
|
joinDirectTitle: "点击直接加入", mentionEmpty: "没有匹配的成员", mentionHint: "↑↓ 选择 · Enter 确认 · Esc 关闭",
|
|
260
307
|
joined: "已加入", joinAction: "加入房间", unreadMessages: ({ count }) => `${count} 条未读`,
|
|
261
|
-
today: "今天", yesterday: "昨天", earlierMessages: "更早的消息已省略", you: "我", saved: "已保存",
|
|
308
|
+
today: "今天", yesterday: "昨天", earlierMessages: "更早的消息已省略", messagesBetweenOmitted: "此阅读位置与最新消息之间的部分消息已省略。", you: "我", saved: "已保存",
|
|
262
309
|
savedMemory: "仅保存于当前标签页", copyFailed: ({ id }) => `复制失败,请手动复制:${id}`,
|
|
263
|
-
copyCode: "复制代码", copiedCode: "已复制", copyCodeFailed: "复制失败,请手动选择并复制代码。",
|
|
264
310
|
copyMessage: "复制", copiedMessage: "已复制", copyMessageFailed: "复制失败,请手动选择并复制消息。",
|
|
265
311
|
identityChanged: "此浏览器身份已在另一个标签页中更改,请重新加载此标签页后继续。",
|
|
266
312
|
networkError: "网络连接失败", requestFailed: ({ status }) => `请求失败(HTTP ${status})`,
|
|
@@ -269,9 +315,10 @@ const messages = {
|
|
|
269
315
|
roomNameRequired: "请输入房间名称", createFailed: ({ message }) => `创建失败:${message}`,
|
|
270
316
|
roomNotFound: "房间不存在,或你已被移出房间", sendAuth: "发送失败:需要访问令牌",
|
|
271
317
|
sendNetwork: "发送失败,消息已保存在下方", sendFailed: ({ message }) => `发送失败:${message}`,
|
|
318
|
+
adminRoomDeleteDenied: "此房间用于管理。请先在设置中输入管理令牌,再删除房间。",
|
|
272
319
|
failedMessages: "未发送的消息", retryFailed: "重试", discardFailed: "删除",
|
|
273
320
|
roomListError: "无法加载房间列表,可直接输入房间 ID 加入。", guest: "访客", roomsLabel: "房间列表",
|
|
274
|
-
refreshRooms: "刷新房间", identityLabel: ({ name }) => `当前昵称:${name}`, direct: "私聊",
|
|
321
|
+
refreshRooms: "刷新房间", identityLabel: ({ name }) => `当前昵称:${name}`, roomsMenu: "打开房间列表", closeRoomList: "关闭房间列表", direct: "私聊",
|
|
275
322
|
messagePrivately: "私聊", removeMember: "移除", kickConfirm: ({ name, id }) => `确定将 ${name}(会话 ${id})移出此房间?`,
|
|
276
323
|
deleteRoom: "删除房间", deleteConfirm: ({ name }) => `删除“${name}”及全部聊天记录?此操作无法撤销。`,
|
|
277
324
|
allMembers: "所有人", messageCount: ({ count }) => `${count} / 2000`,
|
|
@@ -280,7 +327,7 @@ const messages = {
|
|
|
280
327
|
activity_working: "工作中", activity_idle: "前台空闲", activity_waiting: "等待中", activity_unknown: "状态未知", activity_offline: "状态已过期",
|
|
281
328
|
activityHint_working: "Agent 正在报告工作状态。", activityHint_idle: "前台空闲;后台任务仍可能继续。", activityHint_waiting: "Agent 正在报告等待状态。", activityHint_unknown: "暂无活动状态报告。", activityHint_offline: "最近的状态已过期;这不能证明 Agent 已离线。",
|
|
282
329
|
receiptCount: ({ count }) => `已读 ${count} 人`, receiptNone: "尚无人已读", receiptNotLoaded: "尚未加载已读状态", readerPanelTitle: "消息已读情况", close: "关闭", departedMember: "已离开",
|
|
283
|
-
receiptEvidence_displayed: "已显示在屏幕上", receiptEvidence_tool: "通过房间工具读取", receiptEvidence_context: "
|
|
330
|
+
receiptEvidence_displayed: "已显示在屏幕上", receiptEvidence_tool: "通过房间工具读取", receiptEvidence_context: "进入上下文",
|
|
284
331
|
},
|
|
285
332
|
};
|
|
286
333
|
|
|
@@ -289,14 +336,17 @@ app.t = (key, values = {}) => {
|
|
|
289
336
|
const text = typeof entry === "function" ? entry(values) : entry;
|
|
290
337
|
return String(text).replace(/\{(\w+)\}/g, (_, name) => values[name] ?? "");
|
|
291
338
|
};
|
|
292
|
-
export const { LS, saveToken, api } = createAuth(undefined, undefined, (key, values) => app.t(key, values));
|
|
339
|
+
export const { LS, saveToken, api, apiBlob, adminApi } = createAuth(undefined, undefined, (key, values) => app.t(key, values));
|
|
293
340
|
app.LS = LS;
|
|
294
341
|
app.api = api;
|
|
342
|
+
app.apiBlob = apiBlob;
|
|
343
|
+
app.adminApi = adminApi;
|
|
295
344
|
app.setToken = saveToken;
|
|
296
345
|
app.locale = LS.locale === "zh-CN" ? "zh-CN" : "en";
|
|
297
346
|
app.state.joinedIds = new Set(LS.joinedRoomIds);
|
|
298
347
|
app.state.drafts = new Map(Object.entries(LS.drafts));
|
|
299
|
-
app.state.positions = new Map(Object.entries(LS.positions).map(([id, value]) => [id, Number(value) || 0]));
|
|
348
|
+
app.state.positions = new Map(Object.entries(LS.positions).map(([id, value]) => [id, value && typeof value === "object" ? value : Number(value) || 0]));
|
|
349
|
+
app.state.lastReadTs = new Map(Object.entries(LS.readTs).map(([id, value]) => [id, Number(value) || 0]));
|
|
300
350
|
app.state.roomNames = new Map(Object.entries(LS.roomNames));
|
|
301
351
|
app.state.failedMessages = new Map(Object.entries(LS.failedMessages).map(([id, items]) => [id, Array.isArray(items) ? items.filter((item) => item && typeof item.id === "string" && typeof item.text === "string") : []]));
|
|
302
352
|
app.saveDraft = (roomId, text) => {
|
|
@@ -316,9 +366,15 @@ app.savePosition = (roomId, position) => {
|
|
|
316
366
|
app.state.positions.set(roomId, position);
|
|
317
367
|
LS.positions = Object.fromEntries(app.state.positions);
|
|
318
368
|
};
|
|
369
|
+
app.saveReadTs = (roomId, timestamp) => {
|
|
370
|
+
app.state.lastReadTs.set(roomId, timestamp);
|
|
371
|
+
LS.readTs = Object.fromEntries(app.state.lastReadTs);
|
|
372
|
+
};
|
|
319
373
|
app.clearPosition = (roomId) => {
|
|
320
374
|
app.state.positions.delete(roomId);
|
|
321
375
|
LS.positions = Object.fromEntries(app.state.positions);
|
|
376
|
+
app.state.lastReadTs.delete(roomId);
|
|
377
|
+
LS.readTs = Object.fromEntries(app.state.lastReadTs);
|
|
322
378
|
};
|
|
323
379
|
app.saveJoinedIds = () => { LS.joinedRoomIds = [...app.state.joinedIds]; };
|
|
324
380
|
app.saveRoomNames = () => { LS.roomNames = Object.fromEntries(app.state.roomNames); };
|
|
@@ -340,6 +396,7 @@ app.applyLocale = () => {
|
|
|
340
396
|
});
|
|
341
397
|
}
|
|
342
398
|
document.querySelectorAll(".locale-select").forEach((select) => { select.value = app.locale; });
|
|
399
|
+
app.autoGrow?.(app.$("#msgInput"));
|
|
343
400
|
app.updateDraftCount?.();
|
|
344
401
|
app.updateMentionList?.();
|
|
345
402
|
app.renderFailedMessages?.();
|
|
@@ -373,12 +430,21 @@ app.dayText = (timestamp) => {
|
|
|
373
430
|
return new Intl.DateTimeFormat(app.intlLocale(), { month: "short", day: "numeric" }).format(date);
|
|
374
431
|
};
|
|
375
432
|
app.flash = (button, key) => {
|
|
433
|
+
const output = button.querySelector("[data-flash-output]");
|
|
376
434
|
button._flashKey = key;
|
|
377
|
-
|
|
435
|
+
if (output) {
|
|
436
|
+
output._flashKey = key; output.hidden = false; output.textContent = app.t(key);
|
|
437
|
+
button.classList.add("is-flashing");
|
|
438
|
+
if (button.dataset.i18nAriaLabel) button.setAttribute("aria-label", app.t(key));
|
|
439
|
+
} else button.textContent = app.t(key);
|
|
378
440
|
setTimeout(() => {
|
|
379
441
|
if (button._flashKey !== key) return;
|
|
380
442
|
delete button._flashKey;
|
|
381
|
-
|
|
443
|
+
if (output) {
|
|
444
|
+
delete output._flashKey; output.hidden = true; output.textContent = app.t(output.dataset.i18n, output._i18nValues || {});
|
|
445
|
+
button.classList.remove("is-flashing");
|
|
446
|
+
if (button.dataset.i18nAriaLabel) button.setAttribute("aria-label", app.t(button.dataset.i18nAriaLabel));
|
|
447
|
+
} else button.textContent = app.t(button.dataset.i18n, button._i18nValues || {});
|
|
382
448
|
}, 1200);
|
|
383
449
|
};
|
|
384
450
|
app.updateTitle = () => {
|