@alexsun-top/opencode-chat-room 0.5.2 → 0.5.4
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 +28 -215
- package/README.zh-CN.md +27 -209
- package/docs/administrator-rooms.md +6 -22
- package/package.json +1 -4
- package/plugin.ts +1 -1
- package/server/admin-auth.ts +4 -2
- package/server/admin-routes.ts +2 -11
- package/server/admin-state.ts +15 -4
- package/server/assets/base.css +1 -1
- package/server/assets/chat/admin.js +30 -123
- package/server/assets/chat/announcements.js +17 -1
- package/server/assets/chat/attachments.js +4 -1
- package/server/assets/chat/editor.js +65 -15
- package/server/assets/chat/events.js +12 -7
- package/server/assets/chat/markdown.js +31 -11
- package/server/assets/chat/mentions.js +3 -1
- package/server/assets/chat/messages.js +55 -20
- package/server/assets/chat/questions.js +15 -4
- package/server/assets/chat/reminders.js +4 -3
- package/server/assets/chat/replies.js +2 -1
- package/server/assets/chat/room-watcher.js +45 -0
- package/server/assets/chat/rooms.js +62 -69
- package/server/assets/chat/state.js +8 -6
- package/server/assets/conversation.css +8 -5
- package/server/assets/responsive.css +5 -12
- package/server/chat-server.ts +26 -37
- package/server/chat.html +3 -10
- package/server/member-routes.ts +9 -11
- package/server/room-reminders.ts +15 -5
- package/server/wake.ts +11 -2
- package/skills/chatroom/SKILL.md +3 -7
- package/src/admin-client.ts +8 -45
- package/src/admin-credentials.ts +0 -19
- package/src/center-inbox.ts +0 -2
- package/src/mentions.ts +2 -1
- package/src/plugin-notifications.ts +4 -3
- package/src/resource-upload.ts +1 -1
- package/src/resources.ts +4 -1
- package/src/sqlite-state.ts +40 -0
- package/src/store.ts +4 -1
- package/src/v2-plugin.ts +1 -1
- package/server/admin-plan-routes.ts +0 -79
- package/server/admin-scheduler.ts +0 -42
- package/server/admin-task-routes.ts +0 -182
- package/src/supervision-inbox.ts +0 -62
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { LS } from "./state.js";
|
|
2
2
|
import { isOwnMessage } from "./messages.js";
|
|
3
3
|
import { formatRoomPreview, setRoomPreview } from "./system-messages.js";
|
|
4
|
+
import { watchRoom } from "./room-watcher.js";
|
|
4
5
|
|
|
5
6
|
export function initRooms(app) {
|
|
6
7
|
const $ = app.$;
|
|
8
|
+
let roomListGeneration = 0;
|
|
9
|
+
let autoRefresh;
|
|
10
|
+
const invalidateRoomList = () => { autoRefresh = undefined; return ++roomListGeneration; };
|
|
7
11
|
|
|
8
|
-
app.showJoin = (refresh = true) => {
|
|
12
|
+
app.showJoin = (refresh = true, preserveRoomListGeneration = false) => {
|
|
13
|
+
if (!preserveRoomListGeneration) invalidateRoomList();
|
|
9
14
|
document.documentElement.classList.remove("session-restore");
|
|
10
15
|
if (!$("#inName").value) $("#inName").value = LS.name;
|
|
11
16
|
$("#chatView").hidden = true;
|
|
@@ -46,10 +51,16 @@ export function initRooms(app) {
|
|
|
46
51
|
const entry = existing || { unreadIds: new Map(), unreadOverflow: false, preview: "", previewAt: 0, position: 0, readTs: 0, receivedTs: room.messages.at(-1)?.createdAt ?? 0 };
|
|
47
52
|
entry.unreadIds ||= new Map();
|
|
48
53
|
entry.unreadOverflow ||= false;
|
|
49
|
-
|
|
54
|
+
const latest = room.messages.at(-1), savedReadTs = app.state.lastReadTs.get(room.id);
|
|
55
|
+
entry.readTs ||= savedReadTs || 0;
|
|
50
56
|
entry.room = room;
|
|
51
57
|
entry.name = name;
|
|
52
|
-
|
|
58
|
+
// Only rebuild unread history when this browser already has a read watermark;
|
|
59
|
+
// a never-opened room is not a burst of unread messages.
|
|
60
|
+
if (!existing && savedReadTs !== undefined) for (const message of room.messages) {
|
|
61
|
+
const unread = message.createdAt > entry.readTs || (message.isQuestion && !message.answeredByMessageID);
|
|
62
|
+
if (unread && !isOwnMessage(message, app, room, name)) entry.unreadIds.set(message.id, message);
|
|
63
|
+
}
|
|
53
64
|
entry.receivedTs ??= latest?.createdAt ?? 0;
|
|
54
65
|
if (latest && (!existing || latest.createdAt >= entry.previewAt)) setRoomPreview(entry, latest);
|
|
55
66
|
app.state.rooms.set(room.id, entry);
|
|
@@ -60,11 +71,12 @@ export function initRooms(app) {
|
|
|
60
71
|
app.startRoomWatcher();
|
|
61
72
|
};
|
|
62
73
|
|
|
63
|
-
app.activateRoom = (roomId) => {
|
|
74
|
+
app.activateRoom = (roomId, preserveRoomListGeneration = false) => {
|
|
64
75
|
app.state.navigationGeneration++;
|
|
65
76
|
const entry = app.state.rooms.get(roomId);
|
|
66
77
|
if (!entry) return;
|
|
67
78
|
if (app.state.room?.id === roomId) return;
|
|
79
|
+
if (!preserveRoomListGeneration) invalidateRoomList();
|
|
68
80
|
if (app.state.room) {
|
|
69
81
|
app.saveDraft(app.state.room.id, $("#msgInput").draftValue);
|
|
70
82
|
app.captureReadingPosition?.();
|
|
@@ -106,7 +118,7 @@ export function initRooms(app) {
|
|
|
106
118
|
|
|
107
119
|
app.joinRoom = async (roomId, name) => {
|
|
108
120
|
if (app.state.rooms.has(roomId)) return app.activateRoom(roomId);
|
|
109
|
-
const intent = ++app.state.navigationGeneration;
|
|
121
|
+
const intent = ++app.state.navigationGeneration; invalidateRoomList();
|
|
110
122
|
app.state.pendingAction = null;
|
|
111
123
|
app.setJoinBusy(true);
|
|
112
124
|
app.hideJoinError();
|
|
@@ -115,6 +127,7 @@ export function initRooms(app) {
|
|
|
115
127
|
method: "POST",
|
|
116
128
|
body: JSON.stringify({ sessionID: LS.sessionID, participantId: name, participantName: name }),
|
|
117
129
|
});
|
|
130
|
+
invalidateRoomList();
|
|
118
131
|
LS.name = name;
|
|
119
132
|
app.enterRoom(room, name, intent);
|
|
120
133
|
} catch (error) {
|
|
@@ -122,7 +135,7 @@ export function initRooms(app) {
|
|
|
122
135
|
app.state.pendingAction = { type: "join", roomId, name };
|
|
123
136
|
if (app.state.room) { app.openChatSettings(); app.showSendError("sendAuth"); }
|
|
124
137
|
else { app.openTokenBox(); app.showJoinError("authRetry"); }
|
|
125
|
-
} else app.showJoinError(error.network ? "networkRetry" : "joinFailed", { message: error.message });
|
|
138
|
+
} else { app.showJoinError(error.network ? "networkRetry" : "joinFailed", { message: error.message }); void app.refreshRoomList(); }
|
|
126
139
|
} finally { app.setJoinBusy(false); }
|
|
127
140
|
};
|
|
128
141
|
|
|
@@ -131,7 +144,7 @@ export function initRooms(app) {
|
|
|
131
144
|
const name = pending?.name || (fromChat ? app.state.myName : $("#inName").value.trim()) || LS.name || app.t("guest");
|
|
132
145
|
const roomName = pending?.roomName || $(fromChat ? "#inRoomNameChat" : "#inRoomName").value.trim();
|
|
133
146
|
if (!roomName) return fromChat ? app.showSendError("roomNameRequired") : app.showJoinError("roomNameRequired");
|
|
134
|
-
const intent = ++app.state.navigationGeneration;
|
|
147
|
+
const intent = ++app.state.navigationGeneration; invalidateRoomList();
|
|
135
148
|
app.setJoinBusy(true);
|
|
136
149
|
app.hideJoinError();
|
|
137
150
|
app.state.pendingAction = null;
|
|
@@ -141,6 +154,7 @@ export function initRooms(app) {
|
|
|
141
154
|
method: "POST",
|
|
142
155
|
body: JSON.stringify({ name: roomName, ownerId: name, sessionID: LS.sessionID }),
|
|
143
156
|
});
|
|
157
|
+
invalidateRoomList();
|
|
144
158
|
LS.name = name;
|
|
145
159
|
if (fromChat) {
|
|
146
160
|
$("#inRoomNameChat").value = "";
|
|
@@ -152,8 +166,8 @@ export function initRooms(app) {
|
|
|
152
166
|
app.state.pendingAction = { type: "create", name, roomName, fromChat };
|
|
153
167
|
if (fromChat) { app.openChatSettings(); app.showSendError("sendAuth"); }
|
|
154
168
|
else { app.openTokenBox(); app.showJoinError("authRetry"); }
|
|
155
|
-
} else if (fromChat) app.showSendError("sendFailed", { message: error.message });
|
|
156
|
-
else app.showJoinError("createFailed", { message: error.message });
|
|
169
|
+
} else if (fromChat) { app.showSendError("sendFailed", { message: error.message }); void app.refreshRoomList(); }
|
|
170
|
+
else { app.showJoinError("createFailed", { message: error.message }); void app.refreshRoomList(); }
|
|
157
171
|
} finally {
|
|
158
172
|
app.setJoinBusy(false);
|
|
159
173
|
$("#btnCreateChatRoom").disabled = false;
|
|
@@ -169,13 +183,14 @@ export function initRooms(app) {
|
|
|
169
183
|
const roomId = app.state.room?.id;
|
|
170
184
|
if (roomId) void app.removeJoinedRoom(roomId, { leaveServer: !silent });
|
|
171
185
|
};
|
|
172
|
-
app.removeJoinedRoom = async (roomId, { leaveServer = false, reason = false } = {}) => {
|
|
186
|
+
app.removeJoinedRoom = async (roomId, { leaveServer = false, reason = false, reconcile = false } = {}) => {
|
|
187
|
+
if (!reconcile) invalidateRoomList();
|
|
173
188
|
const active = app.state.room?.id === roomId;
|
|
174
189
|
const entry = app.state.rooms.get(roomId);
|
|
175
190
|
app.disposeRoomAttachments?.(roomId);
|
|
176
191
|
if (active) {
|
|
177
192
|
app.state.navigationGeneration++;
|
|
178
|
-
app.saveDraft(roomId, $("#msgInput").
|
|
193
|
+
app.saveDraft(roomId, $("#msgInput").draftValue);
|
|
179
194
|
app.captureReadingPosition?.();
|
|
180
195
|
app.stopPolling();
|
|
181
196
|
app.closeMention();
|
|
@@ -202,10 +217,10 @@ export function initRooms(app) {
|
|
|
202
217
|
}
|
|
203
218
|
if (active) {
|
|
204
219
|
const next = app.state.rooms.keys().next().value;
|
|
205
|
-
if (next) app.activateRoom(next);
|
|
220
|
+
if (next) app.activateRoom(next, true);
|
|
206
221
|
else {
|
|
207
222
|
LS.roomId = "";
|
|
208
|
-
app.showJoin();
|
|
223
|
+
app.showJoin(false, true);
|
|
209
224
|
if (reason) app.showJoinError("roomNotFound");
|
|
210
225
|
}
|
|
211
226
|
}
|
|
@@ -220,29 +235,39 @@ export function initRooms(app) {
|
|
|
220
235
|
app.state.watcherTimer = setTimeout(async () => {
|
|
221
236
|
const inactive = [...app.state.rooms.keys()].filter((id) => id !== app.state.room?.id);
|
|
222
237
|
await bounded(inactive, 3, (roomId) => watchRoom(roomId, app));
|
|
223
|
-
if (app.state.restorePending?.size || app.state.restoreRetry) void app.refreshRoomList();
|
|
238
|
+
if (app.state.restorePending?.size || app.state.restoreRetry) void app.refreshRoomList(true);
|
|
224
239
|
app.renderRoomOptions($("#roomList"), app.state.availableRooms || []);
|
|
225
240
|
app.renderRoomOptions($("#roomListChat"), app.state.availableRooms || []);
|
|
226
241
|
app.startRoomWatcher();
|
|
227
242
|
}, 5000);
|
|
228
243
|
};
|
|
229
244
|
|
|
230
|
-
app.refreshRoomList =
|
|
245
|
+
app.refreshRoomList = (automatic = false) => {
|
|
246
|
+
if (automatic && autoRefresh?.generation === roomListGeneration) return autoRefresh.promise;
|
|
247
|
+
const generation = invalidateRoomList(), promise = loadRoomList(generation);
|
|
248
|
+
if (automatic) { autoRefresh = { generation, promise }; const clear = () => { if (autoRefresh?.promise === promise) autoRefresh = undefined; }; void promise.then(clear, clear); }
|
|
249
|
+
return promise;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
async function loadRoomList(generation) {
|
|
231
253
|
const empty = $("#roomListEmpty"), chatEmpty = $("#roomListChatEmpty");
|
|
232
254
|
try {
|
|
233
255
|
const rooms = await app.api(`/rooms?sessionID=${encodeURIComponent(LS.sessionID)}`);
|
|
256
|
+
if (generation !== roomListGeneration) return;
|
|
234
257
|
app.state.restoreRetry = false;
|
|
235
258
|
app.state.availableRooms = rooms;
|
|
236
|
-
if (!app.state.restored || app.state.restorePending?.size) await app.restoreJoinedRooms(rooms);
|
|
259
|
+
if (!app.state.restored || app.state.restorePending?.size) await app.restoreJoinedRooms(rooms, generation);
|
|
237
260
|
else {
|
|
238
261
|
syncCachedRooms(rooms, app);
|
|
239
|
-
await app.discoverDirectRooms(rooms);
|
|
262
|
+
await app.discoverDirectRooms(rooms, generation);
|
|
240
263
|
}
|
|
264
|
+
if (generation !== roomListGeneration) return;
|
|
241
265
|
app.renderRoomOptions($("#roomList"), rooms);
|
|
242
266
|
app.renderRoomOptions($("#roomListChat"), rooms);
|
|
243
267
|
empty.hidden = rooms.length > 0;
|
|
244
268
|
chatEmpty.hidden = rooms.length > 0;
|
|
245
269
|
} catch (error) {
|
|
270
|
+
if (generation !== roomListGeneration) return;
|
|
246
271
|
if (error.status === 401) {
|
|
247
272
|
if (!app.state.room && !app.state.restored) { app.showJoin(false); app.openTokenBox(); app.showJoinError("authRetry"); }
|
|
248
273
|
else app.state.room ? app.openChatSettings() : app.openTokenBox();
|
|
@@ -260,13 +285,11 @@ export function initRooms(app) {
|
|
|
260
285
|
app.startRoomWatcher();
|
|
261
286
|
}
|
|
262
287
|
}
|
|
263
|
-
}
|
|
288
|
+
}
|
|
264
289
|
|
|
265
|
-
app.restoreJoinedRooms = async (rooms) => {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
290
|
+
app.restoreJoinedRooms = async (rooms, generation = roomListGeneration) => {
|
|
291
|
+
while (app.state.restoring) { await new Promise((resolve) => setTimeout(resolve, 10)); if (generation !== roomListGeneration) return; }
|
|
292
|
+
if (generation !== roomListGeneration) return;
|
|
270
293
|
app.state.restoring = true;
|
|
271
294
|
try {
|
|
272
295
|
const activeId = LS.roomId;
|
|
@@ -276,14 +299,18 @@ export function initRooms(app) {
|
|
|
276
299
|
const unresolved = new Set();
|
|
277
300
|
let authFailed = false;
|
|
278
301
|
await bounded(candidates, 3, async (roomId) => {
|
|
302
|
+
if (generation !== roomListGeneration) return;
|
|
279
303
|
try {
|
|
280
304
|
const room = rooms.find((item) => item.id === roomId) || await app.api(`/rooms/${encodeURIComponent(roomId)}`);
|
|
305
|
+
if (generation !== roomListGeneration) return;
|
|
281
306
|
const members = await app.api(`/rooms/${encodeURIComponent(roomId)}/members`);
|
|
307
|
+
if (generation !== roomListGeneration) return;
|
|
282
308
|
const me = members.find((member) => member.sessionID === LS.sessionID);
|
|
283
309
|
if (!me) return;
|
|
284
310
|
valid.add(roomId);
|
|
285
311
|
app.ensureJoinedRoom(room, me.name);
|
|
286
312
|
} catch (error) {
|
|
313
|
+
if (generation !== roomListGeneration) return;
|
|
287
314
|
if (error.status !== 404) {
|
|
288
315
|
unresolved.add(roomId);
|
|
289
316
|
if (error.status === 401) authFailed = true;
|
|
@@ -291,34 +318,38 @@ export function initRooms(app) {
|
|
|
291
318
|
}
|
|
292
319
|
}
|
|
293
320
|
});
|
|
321
|
+
if (generation !== roomListGeneration) return;
|
|
294
322
|
app.state.joinedIds = new Set([...valid, ...unresolved]);
|
|
295
323
|
app.state.restorePending = unresolved;
|
|
296
324
|
app.saveJoinedIds();
|
|
297
325
|
app.state.restored = unresolved.size === 0;
|
|
298
|
-
if (authFailed) { app.showJoin(false); app.openTokenBox(); app.showJoinError("authRetry"); return; }
|
|
299
|
-
if (activeId && valid.has(activeId)) app.activateRoom(activeId);
|
|
326
|
+
if (authFailed) { app.showJoin(false, true); app.openTokenBox(); app.showJoinError("authRetry"); return; }
|
|
327
|
+
if (activeId && valid.has(activeId)) app.activateRoom(activeId, true);
|
|
300
328
|
else if (activeId && unresolved.has(activeId)) {
|
|
301
329
|
app.showRestoreFailure(app.t("networkRetry"));
|
|
302
330
|
}
|
|
303
331
|
else {
|
|
304
332
|
LS.roomId = "";
|
|
305
333
|
const fallback = valid.values().next().value;
|
|
306
|
-
if (fallback) app.activateRoom(fallback);
|
|
334
|
+
if (fallback) app.activateRoom(fallback, true);
|
|
307
335
|
else if (unresolved.size) app.showRestoreFailure(app.t("networkRetry"));
|
|
308
|
-
else app.showJoin(false);
|
|
336
|
+
else app.showJoin(false, true);
|
|
309
337
|
}
|
|
310
338
|
app.startRoomWatcher();
|
|
311
339
|
} finally { app.state.restoring = false; }
|
|
312
340
|
};
|
|
313
341
|
|
|
314
|
-
app.discoverDirectRooms = async (rooms) => {
|
|
342
|
+
app.discoverDirectRooms = async (rooms, generation = roomListGeneration) => {
|
|
315
343
|
const candidates = rooms.filter((room) => room.kind === "direct" && !app.state.rooms.has(room.id));
|
|
316
344
|
await bounded(candidates, 3, async (room) => {
|
|
345
|
+
if (generation !== roomListGeneration) return;
|
|
317
346
|
try {
|
|
318
347
|
const members = await app.api(`/rooms/${encodeURIComponent(room.id)}/members`);
|
|
348
|
+
if (generation !== roomListGeneration) return;
|
|
319
349
|
const me = members.find((member) => member.sessionID === LS.sessionID);
|
|
320
350
|
if (me) app.ensureJoinedRoom(room, me.name);
|
|
321
351
|
} catch (error) {
|
|
352
|
+
if (generation !== roomListGeneration) return;
|
|
322
353
|
if (error.status !== 404) {
|
|
323
354
|
app.state.restorePending ||= new Set();
|
|
324
355
|
app.state.restorePending.add(room.id);
|
|
@@ -329,6 +360,7 @@ export function initRooms(app) {
|
|
|
329
360
|
}
|
|
330
361
|
}
|
|
331
362
|
});
|
|
363
|
+
if (generation !== roomListGeneration) return;
|
|
332
364
|
if (app.state.restorePending?.size) app.startRoomWatcher();
|
|
333
365
|
};
|
|
334
366
|
|
|
@@ -361,7 +393,7 @@ export function initRooms(app) {
|
|
|
361
393
|
status.className = "r-status";
|
|
362
394
|
app.setText(status, entry ? "joined" : "joinAction");
|
|
363
395
|
button.append(name, kind, meta, preview, status);
|
|
364
|
-
const unread = entry?.
|
|
396
|
+
const unread = entry && app.state.room?.id !== room.id ? (entry.unreadOverflow ? 100 : entry.unreadIds.size) : 0;
|
|
365
397
|
if (unread) {
|
|
366
398
|
const badge = document.createElement("span");
|
|
367
399
|
badge.className = "r-badge";
|
|
@@ -450,7 +482,7 @@ function syncCachedRooms(rooms, app) {
|
|
|
450
482
|
const remote = new Map(rooms.map((room) => [room.id, room]));
|
|
451
483
|
for (const [roomId, entry] of app.state.rooms) {
|
|
452
484
|
const fresh = remote.get(roomId);
|
|
453
|
-
if (!fresh || fresh.joined === false) { void app.removeJoinedRoom(roomId, { reason: app.state.room?.id === roomId }); continue; }
|
|
485
|
+
if (!fresh || fresh.joined === false) { void app.removeJoinedRoom(roomId, { reason: app.state.room?.id === roomId, reconcile: true }); continue; }
|
|
454
486
|
if (app.state.room?.id === roomId) continue;
|
|
455
487
|
const messages = new Map([...entry.room.messages, ...fresh.messages].map((message) => [message.id, message]));
|
|
456
488
|
entry.room = { ...fresh, messages: [...messages.values()].sort((a, b) => a.createdAt - b.createdAt).slice(-500) };
|
|
@@ -458,42 +490,3 @@ function syncCachedRooms(rooms, app) {
|
|
|
458
490
|
if (latest) setRoomPreview(entry, latest);
|
|
459
491
|
}
|
|
460
492
|
}
|
|
461
|
-
|
|
462
|
-
async function watchRoom(roomId, app) {
|
|
463
|
-
const entry = app.state.rooms.get(roomId);
|
|
464
|
-
if (!entry || app.state.room?.id === roomId) return;
|
|
465
|
-
try {
|
|
466
|
-
const query = new URLSearchParams({ sessionID: app.LS.sessionID, roomId, excludeSelf: "0", timeout: "0" });
|
|
467
|
-
query.set("afterTs", String(entry.receivedTs || 0));
|
|
468
|
-
const result = await app.api(`/inbox?${query}`);
|
|
469
|
-
if (app.state.rooms.get(roomId) !== entry) return;
|
|
470
|
-
if (result.member === false) { await app.removeJoinedRoom(roomId, { reason: false }); return; }
|
|
471
|
-
if (result.member !== true || !Array.isArray(result.items)) return;
|
|
472
|
-
if (app.state.room?.id === roomId) return;
|
|
473
|
-
const previousReceivedTs = entry.receivedTs || 0;
|
|
474
|
-
const sawSystem = (result.items || []).some((message) => message.senderId === "system");
|
|
475
|
-
for (const message of result.items || []) {
|
|
476
|
-
if (!isOwnMessage(message, app, entry.room, entry.name) && !entry.unreadIds.has(message.id)) entry.unreadIds.set(message.id, message);
|
|
477
|
-
if (!entry.room.messages.some((item) => item.id === message.id)) entry.room.messages.push({ ...message, roomId });
|
|
478
|
-
if (message.createdAt >= entry.previewAt) {
|
|
479
|
-
setRoomPreview(entry, message);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
entry.receivedTs = (result.items || []).reduce((latest, message) => Number.isSafeInteger(message.createdAt) ? Math.max(latest, message.createdAt) : latest, previousReceivedTs);
|
|
483
|
-
if (sawSystem || result.hasMore) {
|
|
484
|
-
const latest = await app.api(`/rooms/${encodeURIComponent(roomId)}`);
|
|
485
|
-
if (app.state.rooms.get(roomId) !== entry || app.state.room?.id === roomId) return;
|
|
486
|
-
entry.room.participants = latest.participants;
|
|
487
|
-
const messages = new Map([...entry.room.messages, ...latest.messages].map((message) => [message.id, message]));
|
|
488
|
-
entry.room.messages = [...messages.values()].sort((a, b) => a.createdAt - b.createdAt).slice(-500);
|
|
489
|
-
const newest = latest.messages.at(-1);
|
|
490
|
-
if (newest && newest.createdAt >= entry.previewAt) setRoomPreview(entry, newest);
|
|
491
|
-
}
|
|
492
|
-
entry.unreadOverflow = Boolean(result.hasMore);
|
|
493
|
-
if (entry.room.messages.length > 500) entry.room.messages.splice(0, entry.room.messages.length - 500);
|
|
494
|
-
if (result.hasMore && entry.receivedTs > previousReceivedTs) await watchRoom(roomId, app);
|
|
495
|
-
} catch (error) {
|
|
496
|
-
if (error.status === 401) app.openChatSettings();
|
|
497
|
-
else if (error.status === 404) await app.removeJoinedRoom(roomId, { reason: false });
|
|
498
|
-
}
|
|
499
|
-
}
|
|
@@ -219,7 +219,7 @@ const messages = {
|
|
|
219
219
|
announcements: "Announcements", announcementName: "Name", announcementContent: "Content",
|
|
220
220
|
reminders: "Reminders", reminderSchedule: "Schedule", reminderOnce: "One time", reminderDate: "Date and time",
|
|
221
221
|
reminderCron: "5-field CRON expression", reminderTimezone: "Timezone override (optional)", reminderTimezoneHint: "Leave blank to use the server timezone. An IANA timezone applies to both schedule types. The server rejects one-time times skipped or repeated by daylight-saving changes.",
|
|
222
|
-
reminderText: "Reminder text", reminderTemplateHint: "Use {time}, {initiator}, and {room} in your message.", reminderCreate: "Create reminder",
|
|
222
|
+
reminderText: "Reminder text", reminderTemplateHint: "Use {{time}}, {{initiator}}, and {{room}} in your message.", reminderCreate: "Create reminder",
|
|
223
223
|
reminderLoading: "Loading reminders…", reminderEmpty: "No reminders yet.", reminderPaused: "Paused", reminderNext: ({ time }) => `Next: ${time}`,
|
|
224
224
|
reminderPause: "Pause", reminderResume: "Resume", reminderDelete: "Delete", reminderDeleteConfirm: "Delete this reminder?",
|
|
225
225
|
reminderCreated: "Reminder created.", reminderUpdated: "Reminder updated.", reminderDeleted: "Reminder deleted.",
|
|
@@ -234,8 +234,9 @@ const messages = {
|
|
|
234
234
|
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
235
|
answerFailed: "Reply failed. Your draft is still here.", answerTooLong: "Reply must be 2,000 characters or fewer.", questionAlreadyAnswered: "This question was answered elsewhere.",
|
|
236
236
|
sendAsQuestion: "Send as a question",
|
|
237
|
-
|
|
238
|
-
|
|
237
|
+
adminBindingGuide: "Choose a room and an Agent in it. Send the invitation privately to finish setup.", adminRoomLabel: "Administrator room", adminDesignateAgent: "Invite Agent",
|
|
238
|
+
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
|
+
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}”?`,
|
|
239
240
|
leave: "Leave", reconnecting: "Connection lost. Retrying…", messageList: "Message list",
|
|
240
241
|
noMessages: "No messages yet. Say something.", latestMessages: "Back to latest messages",
|
|
241
242
|
mentionMembers: "Choose a member to mention", messagePlaceholder: "Message · Enter to send",
|
|
@@ -294,7 +295,7 @@ const messages = {
|
|
|
294
295
|
announcements: "公告栏", announcementName: "名称", announcementContent: "内容",
|
|
295
296
|
reminders: "提醒", reminderSchedule: "计划", reminderOnce: "单次", reminderDate: "日期和时间",
|
|
296
297
|
reminderCron: "5 字段 CRON 表达式", reminderTimezone: "时区覆盖(可选)", reminderTimezoneHint: "留空则使用服务器时区。填写 IANA 时区会应用于两种计划。服务器会拒绝夏令时调整中不存在或重复的单次时间。",
|
|
297
|
-
reminderText: "提醒内容", reminderTemplateHint: "可使用 {time}、{initiator} 和 {room}。", reminderCreate: "创建提醒",
|
|
298
|
+
reminderText: "提醒内容", reminderTemplateHint: "可使用 {{time}}、{{initiator}} 和 {{room}}。", reminderCreate: "创建提醒",
|
|
298
299
|
reminderLoading: "正在加载提醒…", reminderEmpty: "暂无提醒。", reminderPaused: "已暂停", reminderNext: ({ time }) => `下次:${time}`,
|
|
299
300
|
reminderPause: "暂停", reminderResume: "恢复", reminderDelete: "删除", reminderDeleteConfirm: "确定删除此提醒?",
|
|
300
301
|
reminderCreated: "提醒已创建。", reminderUpdated: "提醒已更新。", reminderDeleted: "提醒已删除。",
|
|
@@ -309,8 +310,9 @@ const messages = {
|
|
|
309
310
|
answerQuestion: "回复", answerPlaceholder: "写下回复…", sendAnswer: "发送回复", selectQuestion: "回复此问题", copyQuestion: "复制问题", questionCopied: "问题已复制。", questionCopyFailed: "无法复制问题。",
|
|
310
311
|
answerFailed: "回复失败,草稿仍已保留。", answerTooLong: "回复不能超过 2,000 个字符。", questionAlreadyAnswered: "此问题已由其他人回答。",
|
|
311
312
|
sendAsQuestion: "作为问题发送",
|
|
312
|
-
|
|
313
|
-
|
|
313
|
+
adminBindingGuide: "选择管理员房间和其中的 Agent,再将邀请私下发送给该 Agent 完成设置。", adminRoomLabel: "管理员房间", adminDesignateAgent: "邀请 Agent",
|
|
314
|
+
adminAccess: "管理", adminToken: "管理令牌", openAdministration: "打开管理面板", administration: "管理面板", designations: "管理绑定", adminRoom: "管理员房间", targetRoom: "Agent 所属房间", adminScopeNote: "请选择管理员房间内的 Agent。管理员可以管理所有房间。", adminRoomBadge: "管理", targetAgent: "已注册 Agent", designate: "指定管理员", revokeDesignation: "撤销绑定", globalStatus: "全局状态", adminTasks: "任务", taskText: "任务内容", dispatchTask: "派发任务", timers: "定时任务", planName: "定时任务名称", createTimer: "创建定时任务",
|
|
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}”?`,
|
|
314
316
|
tokenRequired: "服务器要求访问令牌(401)。", leave: "离开", reconnecting: "连接中断,正在重试…",
|
|
315
317
|
messageList: "消息列表", noMessages: "还没有消息,说点什么吧。", latestMessages: "回到最新消息",
|
|
316
318
|
mentionMembers: "选择要提及的成员", messagePlaceholder: "输入消息,Enter 发送",
|
|
@@ -248,13 +248,16 @@
|
|
|
248
248
|
.message-copy:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
|
|
249
249
|
.message-copy-feedback { position: absolute; z-index: 25; left: 0; bottom: calc(100% + 5px); width: max-content; max-width: min(260px, calc(100vw - 32px)); padding: 6px 9px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: var(--surface); box-shadow: var(--shadow); font-size: 11px; font-weight: 500; line-height: 1.4; text-align: left; white-space: normal; overflow-wrap: anywhere; }
|
|
250
250
|
.message-actions { display: flex; align-items: center; gap: 2px; }
|
|
251
|
-
.message-reply {
|
|
251
|
+
.message-reply { display: grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 1px solid transparent; border-radius: 8px; color: var(--ink-3); background: transparent; cursor: pointer; }
|
|
252
|
+
.message-reply-icon { display: block; width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.7; }
|
|
252
253
|
.message-reply:hover, .message-reply:focus-visible { border-color: var(--line); color: var(--accent); background: var(--accent-soft); }
|
|
253
|
-
.reply-preview { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: min(940px, 100%); margin: 0 auto; padding: 8px 12px; border-left: 3px solid var(--accent); border-radius: 6px; background: var(--accent-soft); }
|
|
254
|
+
.reply-preview { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: min(940px, 100%); min-width: 0; margin: 0 auto; padding: 8px 12px; border-left: 3px solid var(--accent); border-radius: 6px; background: var(--accent-soft); }
|
|
255
|
+
.reply-preview > div { min-width: 0; flex: 1; }
|
|
254
256
|
.reply-preview strong { font-size: 12px; color: var(--accent); }
|
|
255
|
-
.reply-preview p { overflow: hidden; margin: 2px 0 0; color: var(--ink-2); font-size: 12px;
|
|
256
|
-
.reply-cancel { flex: none;
|
|
257
|
-
.reply-cancel:hover { color: var(--danger); background: var(--surface); }
|
|
257
|
+
.reply-preview p { display: -webkit-box; overflow: hidden; margin: 2px 0 0; color: var(--ink-2); font-size: 12px; line-height: 1.4; overflow-wrap: anywhere; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
|
|
258
|
+
.reply-cancel { flex: none; min-height: 32px; padding: 0 9px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink-2); background: var(--surface); font: inherit; font-size: 11px; font-weight: 600; white-space: nowrap; cursor: pointer; }
|
|
259
|
+
.reply-cancel:hover, .reply-cancel:focus-visible { border-color: var(--danger); color: var(--danger); background: var(--surface); }
|
|
260
|
+
.reply-cancel:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
258
261
|
.reply-quote { display: block; max-width: min(82%, 500px); overflow: hidden; margin: 0 0 5px; padding: 5px 10px; border: 0; border-left: 2px solid var(--accent); border-radius: 0 6px 6px 0; color: var(--ink-2); background: var(--surface-2); font: inherit; font-size: 12px; text-align: left; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
|
|
259
262
|
.reply-quote:hover:not(:disabled) { color: var(--accent); background: var(--accent-soft); }
|
|
260
263
|
.reply-quote:disabled { cursor: default; opacity: .7; }
|
|
@@ -77,25 +77,18 @@
|
|
|
77
77
|
.admin-badge { padding: 3px 8px; }
|
|
78
78
|
.room-admin-badge { padding: 1px 6px; vertical-align: middle; }
|
|
79
79
|
.admin-scope-note { margin: 0 0 14px; padding: 10px 11px; border-left: 2px solid var(--accent); border-radius: 0 8px 8px 0; background: color-mix(in srgb, var(--accent-soft) 58%, transparent); line-height: 1.5; }
|
|
80
|
-
.admin-dialog { width: min(
|
|
80
|
+
.admin-dialog { width: min(560px, calc(100vw - 32px)); max-width: none; max-height: 90dvh; overflow: auto; padding: 24px; color: var(--ink); background: linear-gradient(145deg, var(--surface), color-mix(in srgb, var(--accent-soft) 16%, var(--surface))); border: 1px solid color-mix(in srgb, var(--accent) 18%, var(--line)); border-radius: 20px; box-shadow: 0 24px 80px rgb(10 25 20 / .2); }
|
|
81
81
|
.admin-dialog::backdrop { background: rgb(9 22 18 / .52); backdrop-filter: blur(4px); }
|
|
82
82
|
.admin-dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
|
|
83
83
|
.admin-dialog-actions { display: flex; align-items: center; gap: 10px; }
|
|
84
84
|
.admin-dialog #btnCloseAdmin { width: 36px; height: 36px; margin: 0; }
|
|
85
85
|
.admin-dialog-head h2 { margin: 0; font-family: var(--font-display); font-size: 25px; font-weight: 600; letter-spacing: -.02em; }
|
|
86
86
|
.admin-dialog h3 { margin: 20px 0 9px; font-size: 14px; font-weight: 700; letter-spacing: .01em; }
|
|
87
|
-
.admin-
|
|
88
|
-
.admin-
|
|
89
|
-
.admin-columns > section > h3:first-child { margin-top: 0; }
|
|
90
|
-
.admin-columns .field { margin-bottom: 10px; }
|
|
87
|
+
.admin-guide { padding: 16px; border: 1px solid color-mix(in srgb, var(--line) 82%, transparent); border-radius: 14px; background: color-mix(in srgb, var(--surface) 84%, var(--accent-soft)); }
|
|
88
|
+
.admin-guide .field { margin-bottom: 12px; }
|
|
91
89
|
.admin-dialog .admin-select { display: block; box-sizing: border-box; width: 100%; min-width: 0; min-height: 40px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: var(--surface); font: inherit; }
|
|
92
|
-
.admin-
|
|
93
|
-
|
|
94
|
-
.admin-list li { display: grid; gap: 7px; }
|
|
95
|
-
.admin-plan-form { display: grid; gap: 8px; }
|
|
96
|
-
.admin-enrollment { display: grid; gap: 8px; margin-top: 12px; padding: 12px; border-radius: 10px; background: var(--accent-soft); overflow-wrap: anywhere; }
|
|
97
|
-
.admin-enrollment code { user-select: all; }
|
|
98
|
-
@media (max-width: 620px) { .admin-dialog { padding: 15px; } .admin-columns { grid-template-columns: minmax(0, 1fr); gap: 0; } }
|
|
90
|
+
.admin-enrollment { display: grid; gap: 8px; margin-top: 12px; padding: 12px; border-radius: 10px; background: var(--accent-soft); }
|
|
91
|
+
@media (max-width: 620px) { .admin-dialog { padding: 15px; } }
|
|
99
92
|
.rail-avatar { display: grid; place-items: center; width: 25px; height: 25px; border-radius: 50%; color: var(--accent); background: var(--accent-soft); }
|
|
100
93
|
.online-dot { width: 7px; height: 7px; border-radius: 50%; background: #609773; box-shadow: 0 0 0 3px color-mix(in srgb, #609773 16%, transparent); }
|
|
101
94
|
#chatView > .chat-head { grid-column: 2; grid-row: 1; min-width: 0; }
|
package/server/chat-server.ts
CHANGED
|
@@ -8,7 +8,7 @@ import RoomService, {
|
|
|
8
8
|
type Message,
|
|
9
9
|
type Room,
|
|
10
10
|
} from "../src/room-service";
|
|
11
|
-
import { answerQuestion, sendReply, readQuestions, readState, writeState, type Registry, type RegistryEntry } from "../src/store";
|
|
11
|
+
import { acknowledgeQueued, answerQuestion, appendRoomMessage, sendReply, readQuestions, readState, writeState, type Registry, type RegistryEntry } from "../src/store";
|
|
12
12
|
import {
|
|
13
13
|
admissionMatches,
|
|
14
14
|
clearPendingAdmission,
|
|
@@ -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 { jsonObject } from "./json-body";
|
|
20
21
|
import { roomManagement } from "./newrooms";
|
|
21
22
|
import { memberRoutes } from "./member-routes";
|
|
22
23
|
import { resourceRoutes } from "./resource-routes";
|
|
@@ -161,7 +162,8 @@ async function handle(req: Request): Promise<Response> {
|
|
|
161
162
|
const management = await roomManagement(req, url);
|
|
162
163
|
if (management) return management;
|
|
163
164
|
if (req.method === "POST" && p === "/rooms") {
|
|
164
|
-
const body =
|
|
165
|
+
const body = await jsonObject<Record<string, string>>(req);
|
|
166
|
+
if (!body) return json({ error: "JSON object body is required" }, 400);
|
|
165
167
|
if (body.protocol !== undefined && body.protocol !== "v2" || body.receiverOwnerID !== undefined && !isReceiverOwnerID(body.receiverOwnerID)) {
|
|
166
168
|
return json({ error: "invalid receiver ownership" }, 400);
|
|
167
169
|
}
|
|
@@ -226,13 +228,14 @@ async function handle(req: Request): Promise<Response> {
|
|
|
226
228
|
while (result.items.length === 0 && Date.now() < deadline) {
|
|
227
229
|
// ponytail: 2s between disk scans (orc-1 #7) — 1s × 25 iterations
|
|
228
230
|
// doubles the file reads on shared-mount deployments
|
|
229
|
-
await sleep(2000);
|
|
231
|
+
await sleep(Math.max(1, Math.min(2000, deadline - Date.now())));
|
|
230
232
|
result = await readInbox(sessionID, roomFilter, excludeSelf, afterTs);
|
|
231
233
|
}
|
|
232
234
|
return json(result);
|
|
233
235
|
}
|
|
234
236
|
if (req.method === "POST" && p === "/queued") {
|
|
235
|
-
const body =
|
|
237
|
+
const body = await jsonObject<Record<string, unknown>>(req);
|
|
238
|
+
if (!body) return json({ error: "JSON object body is required" }, 400);
|
|
236
239
|
const ts = Number(body.ts);
|
|
237
240
|
const roomId = String(body.roomId ?? "");
|
|
238
241
|
const sessionID = String(body.sessionID ?? "");
|
|
@@ -245,32 +248,28 @@ async function handle(req: Request): Promise<Response> {
|
|
|
245
248
|
) {
|
|
246
249
|
return json({ error: "roomId/sessionID/finite ts are required" }, 400);
|
|
247
250
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
return false;
|
|
252
|
-
}
|
|
253
|
-
entry.lastQueuedTs = Math.max(entry.lastQueuedTs ?? 0, ts);
|
|
254
|
-
return true;
|
|
255
|
-
});
|
|
256
|
-
if (!updated) {
|
|
251
|
+
// Clamp to the room tail so a forged future ts cannot silence delivery.
|
|
252
|
+
const updated = await acknowledgeQueued(roomId, sessionID, ts);
|
|
253
|
+
if (updated === null) {
|
|
257
254
|
return json({ error: "registry entry not found" }, 404);
|
|
258
255
|
}
|
|
259
|
-
clearPendingAdmission(sessionID, roomId,
|
|
256
|
+
clearPendingAdmission(sessionID, roomId, updated);
|
|
260
257
|
touchActive(sessionID);
|
|
261
258
|
return json({ ok: true });
|
|
262
259
|
}
|
|
263
260
|
if (req.method === "POST" && p === "/active") {
|
|
264
261
|
// ponytail: 活跃上报——插件对"进程内自推成功"的 session 调用(真实
|
|
265
262
|
// 活跃);服务器据此避免 serve 双唤起
|
|
266
|
-
const body =
|
|
263
|
+
const body = await jsonObject<Record<string, unknown>>(req);
|
|
264
|
+
if (!body) return json({ error: "JSON object body is required" }, 400);
|
|
267
265
|
touchActive(String(body.sessionID ?? ""));
|
|
268
266
|
return json({ ok: true });
|
|
269
267
|
}
|
|
270
268
|
if (req.method === "POST" && p === "/wake-claim") {
|
|
271
269
|
// ponytail: atomic cross-process wake dedupe (see claimWake) — the
|
|
272
270
|
// server only arbitrates, it never spawns anything itself
|
|
273
|
-
const body =
|
|
271
|
+
const body = await jsonObject<Record<string, unknown>>(req);
|
|
272
|
+
if (!body) return json({ error: "JSON object body is required" }, 400);
|
|
274
273
|
const sessionID = String(body.sessionID ?? "");
|
|
275
274
|
const ok = claimWake(sessionID);
|
|
276
275
|
return json({ ok });
|
|
@@ -278,7 +277,8 @@ async function handle(req: Request): Promise<Response> {
|
|
|
278
277
|
const m = p.match(/^\/rooms\/([^/]+)\/(join|leave|messages)$/);
|
|
279
278
|
if (m) {
|
|
280
279
|
const roomId = decodeURIComponent(m[1]!);
|
|
281
|
-
const body =
|
|
280
|
+
const body = await jsonObject<Record<string, string>>(req);
|
|
281
|
+
if (!body) return json({ error: "JSON object body is required" }, 400);
|
|
282
282
|
const sessionID = typeof body.sessionID === "string" ? body.sessionID : "";
|
|
283
283
|
if (req.method === "POST" && m[2] === "join") {
|
|
284
284
|
if (body.protocol !== undefined && body.protocol !== "v2" || body.receiverOwnerID !== undefined && !isReceiverOwnerID(body.receiverOwnerID)) {
|
|
@@ -380,7 +380,7 @@ async function handle(req: Request): Promise<Response> {
|
|
|
380
380
|
const isQuestion = (body as Record<string, unknown>).isQuestion;
|
|
381
381
|
if (isQuestion !== undefined && typeof isQuestion !== "boolean") return json({ error: "isQuestion must be a boolean" }, 400);
|
|
382
382
|
// ponytail: F3 — mirror the plugin's zod limit at the HTTP boundary
|
|
383
|
-
const text =
|
|
383
|
+
const text = typeof body.text === "string" ? body.text.trim() : "";
|
|
384
384
|
if (!text) {
|
|
385
385
|
return json({ error: "text is required" }, 400);
|
|
386
386
|
}
|
|
@@ -402,26 +402,15 @@ async function handle(req: Request): Promise<Response> {
|
|
|
402
402
|
void wakeMentionedSessions(serveWakeUrl, roomId, room.name, text, sessionID, result.message);
|
|
403
403
|
return json(serializeRoom(room), 201);
|
|
404
404
|
}
|
|
405
|
-
const
|
|
406
|
-
|
|
407
|
-
if (
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
return svc.getRoom(roomId);
|
|
411
|
-
});
|
|
405
|
+
const result = await appendRoomMessage(roomId, sessionID, text, isQuestion === true);
|
|
406
|
+
if (result.status !== "ok") {
|
|
407
|
+
if (result.status === "missing") return json({ error: "room not found" }, 404);
|
|
408
|
+
return json({ error: "session is not a room member" }, 409);
|
|
409
|
+
}
|
|
412
410
|
touchActive(sessionID); // 发送者活跃
|
|
411
|
+
const room = await read((svc) => svc.getRoom(roomId));
|
|
413
412
|
// ponytail: 即时唤起——仅 @ 点名成员时(核心需求)
|
|
414
|
-
|
|
415
|
-
if (sent) {
|
|
416
|
-
void wakeMentionedSessions(
|
|
417
|
-
serveWakeUrl,
|
|
418
|
-
roomId,
|
|
419
|
-
room.name,
|
|
420
|
-
text,
|
|
421
|
-
sessionID,
|
|
422
|
-
sent,
|
|
423
|
-
);
|
|
424
|
-
}
|
|
413
|
+
void wakeMentionedSessions(serveWakeUrl, roomId, room.name, text, sessionID, result.message);
|
|
425
414
|
return json(serializeRoom(room), 201);
|
|
426
415
|
}
|
|
427
416
|
}
|
|
@@ -509,7 +498,7 @@ export default {
|
|
|
509
498
|
console.log(
|
|
510
499
|
`chat-room center listening on http://${displayHostname}:${port}${token ? " (token auth on)" : ""}`,
|
|
511
500
|
);
|
|
512
|
-
startRoomReminderScheduler();
|
|
501
|
+
startRoomReminderScheduler((roomId, roomName, text, message) => wakeMentionedSessions(serveWakeUrl, roomId, roomName, text, "", message));
|
|
513
502
|
if (!token) {
|
|
514
503
|
console.warn(
|
|
515
504
|
"chat-room center has NO token auth — set CHAT_ROOM_SERVER_TOKEN if this port is reachable from other hosts",
|