@alexsun-top/opencode-chat-room 0.6.6 → 0.6.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/README.md +6 -3
- package/README.zh-CN.md +7 -3
- package/cli.ts +1 -1
- package/docs/administrator-rooms.md +11 -5
- package/index.ts +2 -2
- package/package.json +6 -2
- package/plugin.ts +57 -26
- package/server/admin-routes.ts +15 -7
- package/server/admin-state.ts +2 -2
- package/server/announcement-routes.ts +2 -2
- package/server/assets/attachments.css +25 -0
- package/server/assets/base.css +251 -39
- package/server/assets/chat/admin-badge.js +49 -0
- package/server/assets/chat/admin.js +77 -24
- package/server/assets/chat/announcements.js +27 -11
- package/server/assets/chat/attachment-store.js +106 -0
- package/server/assets/chat/attachments.js +245 -25
- package/server/assets/chat/events.js +56 -12
- package/server/assets/chat/image-zoom.js +141 -0
- package/server/assets/chat/index.js +10 -0
- package/server/assets/chat/install-prompt.js +82 -0
- package/server/assets/chat/join-requests.js +355 -0
- package/server/assets/chat/markdown.js +82 -5
- package/server/assets/chat/members.js +16 -6
- package/server/assets/chat/message-polling.js +158 -0
- package/server/assets/chat/message-window.js +14 -0
- package/server/assets/chat/messages.js +12 -132
- package/server/assets/chat/panels.js +37 -0
- package/server/assets/chat/questions.js +10 -6
- package/server/assets/chat/recall.js +279 -0
- package/server/assets/chat/receipts.js +3 -1
- package/server/assets/chat/reminders.js +67 -9
- package/server/assets/chat/replies.js +1 -1
- package/server/assets/chat/room-list.js +60 -0
- package/server/assets/chat/room-watcher.js +5 -1
- package/server/assets/chat/rooms.js +36 -84
- package/server/assets/chat/shortcuts.js +254 -0
- package/server/assets/chat/state.js +97 -24
- package/server/assets/chat/system-messages.js +28 -7
- package/server/assets/conversation.css +18 -26
- package/server/assets/keyboard-hints.css +51 -0
- package/server/assets/recall.css +29 -0
- package/server/assets/responsive.css +58 -16
- package/server/chat-server.ts +81 -62
- package/server/chat.html +238 -72
- package/server/history-route.ts +1 -1
- package/server/inbox.ts +3 -3
- package/server/join-requests.ts +106 -0
- package/server/member-routes.ts +4 -4
- package/server/message-recall-routes.ts +37 -0
- package/server/newrooms.ts +105 -13
- package/server/resource-routes.ts +19 -5
- package/server/room-join.ts +59 -0
- package/server/room-owner.ts +72 -0
- package/server/room-payload.ts +6 -2
- package/server/room-reminders.ts +3 -3
- package/server/sw.js +2 -0
- package/server/wake.ts +48 -19
- package/skills/chatroom/SKILL.md +35 -1
- package/src/README.md +22 -0
- package/src/{admin-client.ts → agent/admin-client.ts} +39 -9
- package/src/{admin-credentials.ts → agent/admin-credentials.ts} +1 -1
- package/src/{agent-presence.ts → agent/agent-presence.ts} +2 -2
- package/src/{agent-receipts.ts → agent/agent-receipts.ts} +2 -2
- package/src/{announcement-tool.ts → agent/announcement-tool.ts} +2 -2
- package/src/{chatroom-skill.ts → agent/chatroom-skill.ts} +1 -1
- package/src/{center-client.ts → center/center-client.ts} +103 -13
- package/src/{center-inbox.ts → center/center-inbox.ts} +44 -19
- package/src/{center-wake.ts → center/center-wake.ts} +31 -18
- package/src/{mentions.ts → center/mentions.ts} +1 -1
- package/src/center/message-ids.ts +7 -0
- package/src/center/notification-budget.ts +16 -0
- package/src/{queue-transport.ts → center/queue-transport.ts} +3 -3
- package/src/{queue.ts → center/queue.ts} +16 -6
- package/src/{reminder-client.ts → center/reminder-client.ts} +1 -1
- package/src/{session-delivery.ts → center/session-delivery.ts} +1 -1
- package/src/{announcements.ts → rooms/announcements.ts} +2 -2
- package/src/{resource-upload.ts → rooms/resource-upload.ts} +1 -1
- package/src/{resources.ts → rooms/resources.ts} +55 -9
- package/src/{room-service.ts → rooms/room-service.ts} +22 -2
- package/src/{background.ts → runtime/background.ts} +3 -3
- package/src/{plugin-notifications.ts → runtime/plugin-notifications.ts} +45 -19
- package/src/{v1-plugin.ts → runtime/v1-plugin.ts} +4 -4
- package/src/{v2-plugin.ts → runtime/v2-plugin.ts} +10 -10
- package/src/{v2-receiver.ts → runtime/v2-receiver.ts} +7 -7
- package/src/{watch.ts → runtime/watch.ts} +12 -12
- package/src/{member-state.ts → state/member-state.ts} +2 -2
- package/src/state/roles.ts +34 -0
- package/src/{sqlite-state.ts → state/sqlite-state.ts} +226 -37
- package/src/{store.ts → state/store.ts} +23 -4
- package/src/tests/announcement-board.ts +185 -0
- /package/src/{resource-read.ts → rooms/resource-read.ts} +0 -0
- /package/src/{receiver-owner.ts → state/receiver-owner.ts} +0 -0
- /package/src/{receiver-state.ts → state/receiver-state.ts} +0 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { databasePath, listJoinRequests, readJoinRequest, readState } from "../src/state/store.ts";
|
|
2
|
+
import { findJoinRequest, removeJoinRequest, writeSqliteStateWithDatabase } from "../src/state/sqlite-state.ts";
|
|
3
|
+
import { binding, tx, validCurrent } from "./admin-state";
|
|
4
|
+
import { hasAdminCapability } from "./admin-auth";
|
|
5
|
+
import { isRoomAdmin } from "./room-owner";
|
|
6
|
+
import { joinRoomMember } from "./room-join";
|
|
7
|
+
|
|
8
|
+
const json = (body: unknown, status = 200) => Response.json(body, { status, headers: { "Cache-Control": "no-store" } });
|
|
9
|
+
|
|
10
|
+
async function agentReviewer(req: Request, roomID: string, actor: string): Promise<boolean> {
|
|
11
|
+
return tx(db => {
|
|
12
|
+
const b = binding(db, roomID);
|
|
13
|
+
return Boolean(b && b.target_room_id === roomID && b.session_id === actor && validCurrent(db, b) && hasAdminCapability(req, b));
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function humanReviewer(roomID: string, actor: string): Promise<boolean> {
|
|
18
|
+
return readState((svc, registry) => {
|
|
19
|
+
const entry = registry[roomID]?.[actor];
|
|
20
|
+
return Boolean(entry && isRoomAdmin(svc.getRoom(roomID), entry));
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function bounded(value: unknown): value is string {
|
|
25
|
+
return typeof value === "string" && value.length > 0 && value.length <= 128;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Approval-protected joins: requests stay in SQLite until a reviewer consumes
|
|
29
|
+
// them; denial removes the row so the requester can try again.
|
|
30
|
+
export async function joinRequestRoutes(req: Request, url: URL): Promise<Response | undefined> {
|
|
31
|
+
const status = url.pathname.match(/^\/rooms\/([^/]+)\/join-requests\/status$/);
|
|
32
|
+
const list = url.pathname.match(/^\/rooms\/([^/]+)\/join-requests$/);
|
|
33
|
+
const action = url.pathname.match(/^\/rooms\/([^/]+)\/join-requests\/([^/]+)\/(approve|deny)$/);
|
|
34
|
+
if (!status && !list && !action) return undefined;
|
|
35
|
+
|
|
36
|
+
if (status && req.method === "GET") {
|
|
37
|
+
const roomID = decodeURIComponent(status[1]!);
|
|
38
|
+
const sessionID = url.searchParams.get("sessionID") ?? "";
|
|
39
|
+
if (!bounded(sessionID)) return json({ error: "sessionID is required" }, 400);
|
|
40
|
+
const joined = await readState((svc, registry) => {
|
|
41
|
+
svc.getRoom(roomID);
|
|
42
|
+
return Boolean(registry[roomID]?.[sessionID]);
|
|
43
|
+
});
|
|
44
|
+
if (joined) return json({ status: "joined" });
|
|
45
|
+
return json({ status: await readJoinRequest(roomID, sessionID) ? "pending" : "none" });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (list && req.method === "GET") {
|
|
49
|
+
const roomID = decodeURIComponent(list[1]!);
|
|
50
|
+
const actor = url.searchParams.get("sessionID") ?? "";
|
|
51
|
+
if (!bounded(actor)) return json({ error: "sessionID is required" }, 400);
|
|
52
|
+
const human = await humanReviewer(roomID, actor);
|
|
53
|
+
const agent = !human && await agentReviewer(req, roomID, actor);
|
|
54
|
+
if (!human && !agent) return json({ error: "only room administrators can review join requests" }, 403);
|
|
55
|
+
const requests = await listJoinRequests(roomID, agent);
|
|
56
|
+
return json({ requests: requests.map(({ sessionID, participantId, name, isAgent, createdAt }) =>
|
|
57
|
+
({ sessionID, participantId, name, isAgent, createdAt })) });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (action && req.method === "POST") {
|
|
61
|
+
const roomID = decodeURIComponent(action[1]!);
|
|
62
|
+
const requestSessionID = decodeURIComponent(action[2]!);
|
|
63
|
+
const decision = action[3]!;
|
|
64
|
+
const body: unknown = await req.json();
|
|
65
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) return json({ error: "JSON object body is required" }, 400);
|
|
66
|
+
const actor = typeof (body as Record<string, unknown>).sessionID === "string" ? (body as Record<string, string>).sessionID : "";
|
|
67
|
+
if (!bounded(actor)) return json({ error: "sessionID is required" }, 400);
|
|
68
|
+
const result = await writeSqliteStateWithDatabase(databasePath(), (svc, registry, db) => {
|
|
69
|
+
const room = svc.getRoom(roomID);
|
|
70
|
+
const actorEntry = registry[roomID]?.[actor];
|
|
71
|
+
const human = Boolean(actorEntry && isRoomAdmin(room, actorEntry));
|
|
72
|
+
const b = binding(db, roomID);
|
|
73
|
+
const agent = !human && Boolean(b && b.target_room_id === roomID && b.session_id === actor && validCurrent(db, b) && hasAdminCapability(req, b));
|
|
74
|
+
if (!human && !agent) return { status: 403 as const, error: "only room administrators can review join requests" };
|
|
75
|
+
const request = findJoinRequest(db, roomID, requestSessionID);
|
|
76
|
+
if (!request) return { status: 404 as const, error: "join request not found" };
|
|
77
|
+
if (agent && !request.isAgent) return { status: 403 as const, error: "the management agent can only review agent requests" };
|
|
78
|
+
if (decision === "deny") {
|
|
79
|
+
removeJoinRequest(db, roomID, requestSessionID);
|
|
80
|
+
return { ok: true as const };
|
|
81
|
+
}
|
|
82
|
+
if (registry[roomID]?.[request.sessionID]) {
|
|
83
|
+
removeJoinRequest(db, roomID, requestSessionID);
|
|
84
|
+
return { status: 409 as const, error: "requester already joined the room" };
|
|
85
|
+
}
|
|
86
|
+
if (svc.containsParticipant(roomID, request.participantId)) {
|
|
87
|
+
removeJoinRequest(db, roomID, requestSessionID);
|
|
88
|
+
return { status: 409 as const, error: "participant name is already in use in this room" };
|
|
89
|
+
}
|
|
90
|
+
removeJoinRequest(db, roomID, requestSessionID);
|
|
91
|
+
joinRoomMember(svc, registry, roomID, {
|
|
92
|
+
sessionID: request.sessionID,
|
|
93
|
+
participantId: request.participantId,
|
|
94
|
+
name: request.name,
|
|
95
|
+
...(request.protocol ? { protocol: request.protocol } : {}),
|
|
96
|
+
...(request.receiverOwnerID ? { receiverOwnerID: request.receiverOwnerID } : {}),
|
|
97
|
+
...(request.directory ? { directory: request.directory } : {}),
|
|
98
|
+
...(request.host ? { host: request.host } : {}),
|
|
99
|
+
});
|
|
100
|
+
return { ok: true as const };
|
|
101
|
+
});
|
|
102
|
+
return "ok" in result ? json({ ok: true }) : json({ error: result.error }, result.status);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return json({ error: "method not allowed" }, 405);
|
|
106
|
+
}
|
package/server/member-routes.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { memberActivity, type WorkState } from "../src/member-state";
|
|
2
|
-
import { acknowledgeRead, acknowledgeReadWithReceipts, readReceipts, readState, recordMessageReceipts, reportPresence, type ReceiptEvidence, type ReceiptIdentity } from "../src/store";
|
|
3
|
-
import { isReceiverOwnerID } from "../src/receiver-owner";
|
|
4
|
-
import { clearPendingAdmission } from "../src/queue";
|
|
1
|
+
import { memberActivity, type WorkState } from "../src/state/member-state.ts";
|
|
2
|
+
import { acknowledgeRead, acknowledgeReadWithReceipts, readReceipts, readState, recordMessageReceipts, reportPresence, type ReceiptEvidence, type ReceiptIdentity } from "../src/state/store.ts";
|
|
3
|
+
import { isReceiverOwnerID } from "../src/state/receiver-owner.ts";
|
|
4
|
+
import { clearPendingAdmission } from "../src/center/queue.ts";
|
|
5
5
|
import { touchActive } from "./wake";
|
|
6
6
|
import { announcementRoutes } from "./announcement-routes";
|
|
7
7
|
import { jsonObject } from "./json-body";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { recallMessage, revealMessageContent } from "../src/state/store.ts";
|
|
2
|
+
import { jsonObject } from "./json-body";
|
|
3
|
+
|
|
4
|
+
const json = (body: unknown, status = 200) => Response.json(body, { status });
|
|
5
|
+
const MAX_SESSION = 128;
|
|
6
|
+
|
|
7
|
+
export async function messageRecallRoutes(req: Request, url: URL): Promise<Response | undefined> {
|
|
8
|
+
const recall = url.pathname.match(/^\/rooms\/([^/]+)\/messages\/([^/]+)\/recall$/);
|
|
9
|
+
if (recall) {
|
|
10
|
+
if (req.method !== "POST") return json({ error: "method not allowed" }, 405);
|
|
11
|
+
const roomID = decodeURIComponent(recall[1]!);
|
|
12
|
+
const messageID = decodeURIComponent(recall[2]!);
|
|
13
|
+
const body = await jsonObject<Record<string, unknown>>(req);
|
|
14
|
+
if (!body) return json({ error: "JSON object body is required" }, 400);
|
|
15
|
+
const sessionID = typeof body.sessionID === "string" ? body.sessionID.trim() : "";
|
|
16
|
+
if (!sessionID || sessionID.length > MAX_SESSION) return json({ error: "sessionID is required" }, 400);
|
|
17
|
+
const result = await recallMessage(roomID, messageID, sessionID);
|
|
18
|
+
if (result.status === "missing") return json({ error: "message not found" }, 404);
|
|
19
|
+
if (result.status === "member") return json({ error: "session is not a room member" }, 409);
|
|
20
|
+
if (result.status === "forbidden") return json({ error: "not allowed to recall this message" }, 403);
|
|
21
|
+
if (result.status !== "ok") return json({ error: "recall failed" }, 409);
|
|
22
|
+
return json({ ok: true, messageID: result.messageID, recalledAt: result.recalledAt, recalledBy: result.recalledBy });
|
|
23
|
+
}
|
|
24
|
+
const content = url.pathname.match(/^\/rooms\/([^/]+)\/messages\/([^/]+)\/content$/);
|
|
25
|
+
if (!content) return undefined;
|
|
26
|
+
if (req.method !== "GET") return json({ error: "method not allowed" }, 405);
|
|
27
|
+
const roomID = decodeURIComponent(content[1]!);
|
|
28
|
+
const messageID = decodeURIComponent(content[2]!);
|
|
29
|
+
const sessionID = url.searchParams.get("sessionID") ?? "";
|
|
30
|
+
if (!sessionID || sessionID.length > MAX_SESSION) return json({ error: "sessionID is required" }, 400);
|
|
31
|
+
const result = await revealMessageContent(roomID, messageID, sessionID);
|
|
32
|
+
if (result.status === "missing") return json({ error: "message not found" }, 404);
|
|
33
|
+
if (result.status === "member") return json({ error: "session is not a room member" }, 409);
|
|
34
|
+
if (result.status === "hidden") return json({ error: "message is not recalled" }, 409);
|
|
35
|
+
if (result.status !== "ok") return json({ error: "message not found" }, 404);
|
|
36
|
+
return json({ messageID: result.messageID, text: result.text, senderId: result.senderId, createdAt: result.createdAt, recalledAt: result.recalledAt });
|
|
37
|
+
}
|
package/server/newrooms.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import RoomService, { RoomError, type Room } from "../src/room-service";
|
|
2
|
-
import { databasePath, writeState } from "../src/store";
|
|
3
|
-
import { writeSqliteStateWithDatabase } from "../src/sqlite-state";
|
|
4
|
-
import { binding, enroll, exec } from "./admin-state";
|
|
1
|
+
import RoomService, { RoomError, type Room } from "../src/rooms/room-service.ts";
|
|
2
|
+
import { databasePath, writeState } from "../src/state/store.ts";
|
|
3
|
+
import { writeSqliteStateWithDatabase } from "../src/state/sqlite-state.ts";
|
|
4
|
+
import { binding, enroll, exec, tx, validCurrent } from "./admin-state";
|
|
5
|
+
import { hasAdminCapability } from "./admin-auth";
|
|
5
6
|
import { roomPayload } from "./room-payload";
|
|
6
|
-
import { clearPendingAdmission } from "../src/queue";
|
|
7
|
-
import { removeRoomResources } from "../src/resources";
|
|
7
|
+
import { clearPendingAdmission } from "../src/center/queue.ts";
|
|
8
|
+
import { removeRoomResources } from "../src/rooms/resources.ts";
|
|
9
|
+
import { isOwnerEntry, isRoomAdmin, isUser } from "./room-owner";
|
|
8
10
|
|
|
9
11
|
const json = (body: unknown, status = 200) => Response.json(body, { status });
|
|
10
|
-
const mutate = <T>(fn: (service: RoomService, registry: import("../src/store").Registry) => T) => writeState(fn);
|
|
12
|
+
const mutate = <T>(fn: (service: RoomService, registry: import("../src/state/store.ts").Registry) => T) => writeState(fn);
|
|
11
13
|
async function objectBody(req: Request): Promise<Record<string, unknown> | undefined> {
|
|
12
14
|
const value: unknown = await req.json();
|
|
13
15
|
return value && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : undefined;
|
|
@@ -52,15 +54,37 @@ export async function roomManagement(req: Request, url: URL): Promise<Response |
|
|
|
52
54
|
const actor = typeof body.sessionID === "string" ? body.sessionID : "";
|
|
53
55
|
const target = typeof body.targetSessionID === "string" ? body.targetSessionID : "";
|
|
54
56
|
if (!actor || !target || actor === target || actor.length > 128 || target.length > 128) return json({ error: "distinct sessionIDs are required" }, 400);
|
|
57
|
+
const agentBinding = await tx(db => {
|
|
58
|
+
const b = binding(db, roomId);
|
|
59
|
+
return b && b.target_room_id === roomId && b.session_id === actor && validCurrent(db, b) && hasAdminCapability(req, b) ? b : undefined;
|
|
60
|
+
});
|
|
55
61
|
const result = await mutate((svc, registry) => {
|
|
56
62
|
const room = svc.getRoom(roomId), members = registry[roomId];
|
|
57
|
-
|
|
63
|
+
const actorEntry = members?.[actor];
|
|
64
|
+
if (!actorEntry) throw new RoomError("NOT_JOINED", "actor is not a room member");
|
|
58
65
|
if (room.kind === "direct") throw new RoomError("DIRECT_ROOM_FULL", "delete the direct conversation instead");
|
|
66
|
+
const humanAdmin = isRoomAdmin(room, actorEntry);
|
|
67
|
+
const agentAdmin = !humanAdmin && !isUser(actorEntry) && agentBinding?.membership_id === actorEntry.membershipID;
|
|
68
|
+
if (!humanAdmin && !agentAdmin) throw new RoomError("NOT_OWNER", "only human room administrators or the designated agent administrator can remove members");
|
|
59
69
|
const removed = members[target];
|
|
60
70
|
if (!removed) throw new RoomError("ROOM_NOT_FOUND", "target session is not a room member");
|
|
71
|
+
if (agentAdmin && isRoomAdmin(room, removed)) throw new RoomError("NOT_OWNER", "the designated agent administrator cannot remove human administrators");
|
|
72
|
+
if (isOwnerEntry(room, removed) && !Object.entries(members).some(([sid, entry]) => sid !== target && entry.name === room.ownerId)) throw new RoomError("NOT_OWNER", "the room owner cannot be removed");
|
|
61
73
|
delete members[target];
|
|
62
|
-
if (!Object.values(members).some((entry) => entry.name === removed.name))
|
|
74
|
+
if (!Object.values(members).some((entry) => entry.name === removed.name)) {
|
|
75
|
+
svc.leaveRoom(roomId, removed.name);
|
|
76
|
+
const next = (room.adminIds ?? []).filter((name) => name !== removed.name);
|
|
77
|
+
if (next.length) room.adminIds = next; else delete room.adminIds;
|
|
78
|
+
if (removed.membershipID && room.adminMembershipIDs?.length) {
|
|
79
|
+
const ids = room.adminMembershipIDs.filter((id) => id !== removed.membershipID);
|
|
80
|
+
if (ids.length) room.adminMembershipIDs = ids; else delete room.adminMembershipIDs;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
63
83
|
const message = svc.addEvent(roomId, `${removed.name} was removed from the room`);
|
|
84
|
+
if (room.successorId && (room.successorMembershipID ? removed.membershipID === room.successorMembershipID : removed.name === room.successorId)) {
|
|
85
|
+
delete room.successorId;
|
|
86
|
+
delete room.successorMembershipID;
|
|
87
|
+
}
|
|
64
88
|
if (!Object.keys(members).length) delete registry[roomId];
|
|
65
89
|
return { message, target };
|
|
66
90
|
});
|
|
@@ -76,18 +100,37 @@ export async function roomManagement(req: Request, url: URL): Promise<Response |
|
|
|
76
100
|
if (!sessionID || sessionID.length > 128) return json({ error: "sessionID is required" }, 400);
|
|
77
101
|
if (body.name !== undefined && (typeof body.name !== "string" || !body.name.trim() || body.name.trim().length > 64)) return json({ error: "name must be 1-64 characters" }, 400);
|
|
78
102
|
if (body.description !== undefined && (typeof body.description !== "string" || body.description.length > 2000)) return json({ error: "description too long (max 2000)" }, 400);
|
|
103
|
+
if (body.joinPolicy !== undefined && body.joinPolicy !== "open" && body.joinPolicy !== "approval") return json({ error: "joinPolicy must be open or approval" }, 400);
|
|
79
104
|
if (body.adminSessionID !== undefined && body.adminSessionID !== null && (typeof body.adminSessionID !== "string" || body.adminSessionID.length > 128)) return json({ error: "invalid adminSessionID" }, 400);
|
|
105
|
+
if (body.adminIds !== undefined && (!Array.isArray(body.adminIds) || body.adminIds.length > 50 || body.adminIds.some((name) => typeof name !== "string" || !name.trim() || name.trim().length > 64))) return json({ error: "adminIds must be up to 50 member names" }, 400);
|
|
106
|
+
if (body.successorId !== undefined && body.successorId !== null && (typeof body.successorId !== "string" || !body.successorId.trim() || body.successorId.trim().length > 64)) return json({ error: "successorId must be a member name or null" }, 400);
|
|
107
|
+
const successorId = typeof body.successorId === "string" ? body.successorId.trim() : body.successorId === null ? null : undefined;
|
|
108
|
+
const adminIds = Array.isArray(body.adminIds) ? [...new Set(body.adminIds.map((name) => (name as string).trim()))] : undefined;
|
|
80
109
|
const name = typeof body.name === "string" ? body.name.trim() : undefined;
|
|
81
110
|
const description = typeof body.description === "string" ? body.description.trim() : undefined;
|
|
111
|
+
const joinPolicy = body.joinPolicy === "open" || body.joinPolicy === "approval" ? body.joinPolicy : undefined;
|
|
82
112
|
const adminSessionID = typeof body.adminSessionID === "string" ? body.adminSessionID : body.adminSessionID === null ? null : undefined;
|
|
113
|
+
if (body.ownerId !== undefined && (typeof body.ownerId !== "string" || !body.ownerId.trim() || body.ownerId.trim().length > 64)) return json({ error: "ownerId must be 1-64 characters" }, 400);
|
|
114
|
+
const nextOwner = typeof body.ownerId === "string" ? body.ownerId.trim() : undefined;
|
|
83
115
|
const result = await writeSqliteStateWithDatabase(databasePath(), (svc, registry, db) => {
|
|
84
116
|
const room = svc.getRoom(roomId);
|
|
85
117
|
const actor = registry[roomId]?.[sessionID];
|
|
86
118
|
if (!actor) return { status: 409 as const, error: "actor is not a room member" };
|
|
87
|
-
|
|
119
|
+
// The owner keeps the powers that shape the room's control; delegated
|
|
120
|
+
// human admins may edit its presentation and the admin roster.
|
|
121
|
+
const isOwner = actor.name === room.ownerId && (!room.ownerMembershipID || actor.membershipID === room.ownerMembershipID);
|
|
122
|
+
if (!isOwner && !isRoomAdmin(room, actor)) return { status: 403 as const, error: "only the room owner can edit the room" };
|
|
123
|
+
if (!isOwner && (adminSessionID !== undefined || nextOwner !== undefined)) return { status: 403 as const, error: "only the room owner can change agent administrators or hand off the room" };
|
|
88
124
|
const changes: string[] = [];
|
|
89
125
|
if (name !== undefined && name !== room.name) { changes.push(`${actor.name} renamed the room from "${room.name}" to "${name}"`); room.name = name; }
|
|
90
126
|
if (description !== undefined && description !== (room.description ?? "")) { room.description = description || undefined; changes.push(`${actor.name} updated the room description`); }
|
|
127
|
+
if (joinPolicy !== undefined && joinPolicy !== (room.joinPolicy ?? "open")) {
|
|
128
|
+
if (joinPolicy === "approval") room.joinPolicy = "approval"; else delete room.joinPolicy;
|
|
129
|
+
// Opening the room makes waiting requests moot; they would otherwise stay
|
|
130
|
+
// listed forever because anyone can now join directly.
|
|
131
|
+
if (joinPolicy === "open") db.query("DELETE FROM room_join_requests WHERE room_id=?").run(roomId);
|
|
132
|
+
changes.push(`${actor.name} set join approval to ${joinPolicy}`);
|
|
133
|
+
}
|
|
91
134
|
if (adminSessionID !== undefined) {
|
|
92
135
|
if (!adminSessionID) {
|
|
93
136
|
if (binding(db, roomId)) { exec(db, "DELETE FROM admin_rooms WHERE room_id=?", roomId); changes.push(`${actor.name} revoked the administrator designation`); }
|
|
@@ -101,6 +144,53 @@ export async function roomManagement(req: Request, url: URL): Promise<Response |
|
|
|
101
144
|
}
|
|
102
145
|
}
|
|
103
146
|
}
|
|
147
|
+
if (adminIds !== undefined) {
|
|
148
|
+
const entries = Object.values(registry[roomId] ?? {});
|
|
149
|
+
for (const name of adminIds) {
|
|
150
|
+
if (!entries.some((entry) => entry.name === name && isUser(entry))) return { status: 409 as const, error: "administrators must be joined humans" };
|
|
151
|
+
}
|
|
152
|
+
const next = adminIds.filter((name) => name !== room.ownerId);
|
|
153
|
+
const ids = [...new Set(next.flatMap((name) => {
|
|
154
|
+
const entry = entries.find((item) => item.name === name && isUser(item));
|
|
155
|
+
return entry?.membershipID ? [entry.membershipID] : [];
|
|
156
|
+
}))];
|
|
157
|
+
if (JSON.stringify(next) !== JSON.stringify(room.adminIds ?? []) || JSON.stringify(ids) !== JSON.stringify(room.adminMembershipIDs ?? [])) {
|
|
158
|
+
if (next.length) room.adminIds = next; else delete room.adminIds;
|
|
159
|
+
if (ids.length) room.adminMembershipIDs = ids; else delete room.adminMembershipIDs;
|
|
160
|
+
changes.push(`${actor.name} updated the room administrators`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (successorId !== undefined) {
|
|
164
|
+
if (successorId === null) {
|
|
165
|
+
if (room.successorId) { delete room.successorId; delete room.successorMembershipID; changes.push(`${actor.name} cleared the room successor`); }
|
|
166
|
+
} else {
|
|
167
|
+
const target = Object.values(registry[roomId] ?? {}).find((entry) => entry.name === successorId && isUser(entry));
|
|
168
|
+
if (!target) return { status: 409 as const, error: "the successor must be a joined human" };
|
|
169
|
+
if (room.successorId !== target.name || room.successorMembershipID !== target.membershipID) {
|
|
170
|
+
room.successorId = target.name;
|
|
171
|
+
if (target.membershipID) room.successorMembershipID = target.membershipID; else delete room.successorMembershipID;
|
|
172
|
+
changes.push(`${actor.name} named ${target.name} as the room successor`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (nextOwner !== undefined && nextOwner !== room.ownerId) {
|
|
177
|
+
// Only a person can hold a room; an agent must never inherit it by accident.
|
|
178
|
+
const target = Object.values(registry[roomId] ?? {}).find((entry) => entry.name === nextOwner && isUser(entry));
|
|
179
|
+
if (!target) return { status: 409 as const, error: "the new owner must be a person in this room" };
|
|
180
|
+
changes.push(`${actor.name} handed the room to ${nextOwner}`);
|
|
181
|
+
room.ownerId = nextOwner;
|
|
182
|
+
if (target.membershipID) room.ownerMembershipID = target.membershipID; else delete room.ownerMembershipID;
|
|
183
|
+
delete room.successorId;
|
|
184
|
+
delete room.successorMembershipID;
|
|
185
|
+
if (room.adminIds) {
|
|
186
|
+
const remaining = room.adminIds.filter((name) => name !== nextOwner);
|
|
187
|
+
if (remaining.length) room.adminIds = remaining; else delete room.adminIds;
|
|
188
|
+
}
|
|
189
|
+
if (target.membershipID && room.adminMembershipIDs?.length) {
|
|
190
|
+
const remaining = room.adminMembershipIDs.filter((id) => id !== target.membershipID);
|
|
191
|
+
if (remaining.length) room.adminMembershipIDs = remaining; else delete room.adminMembershipIDs;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
104
194
|
if (changes.length) svc.addEvent(roomId, changes.join("; "));
|
|
105
195
|
return { room };
|
|
106
196
|
});
|
|
@@ -114,10 +204,12 @@ export async function roomManagement(req: Request, url: URL): Promise<Response |
|
|
|
114
204
|
if (!body) return json({ error: "JSON object body is required" }, 400);
|
|
115
205
|
const sessionID = typeof body.sessionID === "string" ? body.sessionID : "";
|
|
116
206
|
if (!sessionID || sessionID.length > 128) return json({ error: "sessionID is required" }, 400);
|
|
117
|
-
//
|
|
207
|
+
// Dissolving the room is the owner's call; everyone else only leaves.
|
|
118
208
|
const sessions = await mutate((svc, registry) => {
|
|
119
|
-
svc.getRoom(roomId);
|
|
120
|
-
|
|
209
|
+
const room = svc.getRoom(roomId);
|
|
210
|
+
const actor = registry[roomId]?.[sessionID];
|
|
211
|
+
if (!actor) throw new RoomError("NOT_JOINED", "actor is not a room member");
|
|
212
|
+
if (room.ownerId && !(actor.name === room.ownerId && (!room.ownerMembershipID || actor.membershipID === room.ownerMembershipID))) throw new RoomError("NOT_OWNER", "only the room owner can delete the room");
|
|
121
213
|
const removed = Object.keys(registry[roomId] ?? {});
|
|
122
214
|
svc.deleteRoom(roomId);
|
|
123
215
|
delete registry[roomId];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { stat } from "node:fs/promises";
|
|
2
|
-
import { findResource, maxResourceBytes, resourcePath, uploadResource, type Resource } from "../src/resources";
|
|
3
|
-
import { readState } from "../src/store";
|
|
2
|
+
import { deleteResource, findResource, maxResourceBytes, resourcePath, uploadResource, type Resource } from "../src/rooms/resources.ts";
|
|
3
|
+
import { readState } from "../src/state/store.ts";
|
|
4
|
+
import { isRoomAdmin, isUser } from "./room-owner";
|
|
4
5
|
|
|
5
6
|
const json = (body: unknown, status = 200) => Response.json(body, { status });
|
|
6
7
|
const uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
@@ -17,24 +18,37 @@ export async function resourceRoutes(req: Request, url: URL): Promise<Response |
|
|
|
17
18
|
}
|
|
18
19
|
const upload = url.pathname.match(/^\/rooms\/([^/]+)\/resources$/);
|
|
19
20
|
const item = url.pathname.match(/^\/rooms\/([^/]+)\/resources\/([^/]+)(\/content)?$/);
|
|
20
|
-
if ((!upload || req.method !== "POST") && (!item || req.method !== "GET")) return undefined;
|
|
21
|
+
if ((!upload || req.method !== "POST") && (!item || (req.method !== "GET" && !(req.method === "DELETE" && !item[3])))) return undefined;
|
|
21
22
|
try {
|
|
22
23
|
const roomID = decodeURIComponent((upload ?? item)![1]!);
|
|
23
24
|
if (upload) {
|
|
24
25
|
const sessionID = req.headers.get("x-session-id") ?? "";
|
|
25
|
-
|
|
26
|
+
const entry = await readState((_svc, registry) => registry[roomID]?.[sessionID]);
|
|
27
|
+
if (!entry) return json({ error: "forbidden" }, 403);
|
|
26
28
|
const encoded = req.headers.get("x-file-name");
|
|
27
29
|
if (!encoded) return json({ error: "invalid filename" }, 400);
|
|
28
30
|
let filename: string;
|
|
29
31
|
try { filename = decodeURIComponent(encoded); } catch { return json({ error: "invalid filename" }, 400); }
|
|
30
32
|
if (!filename || filename.length > 255 || /[\\/\r\n\0]/.test(filename) || filename === "." || filename === "..") return json({ error: "invalid filename" }, 400);
|
|
31
|
-
const
|
|
33
|
+
const requestedID = req.headers.get("x-resource-id");
|
|
34
|
+
if (requestedID !== null && !uuid.test(requestedID)) return json({ error: "invalid resource id" }, 400);
|
|
35
|
+
const resource = await uploadResource(roomID, filename, req.body ?? new Blob([]).stream(), maxResourceBytes(), { sessionID, name: entry.name }, requestedID ?? undefined);
|
|
32
36
|
return json({ resource }, 201);
|
|
33
37
|
}
|
|
34
38
|
const id = decodeURIComponent(item![2]!);
|
|
35
39
|
if (!uuid.test(id)) return json({ error: "resource not found" }, 404);
|
|
36
40
|
const resource = await findResource(roomID, id);
|
|
37
41
|
if (!resource) return json({ error: "resource not found" }, 404);
|
|
42
|
+
if (req.method === "DELETE") {
|
|
43
|
+
const sessionID = req.headers.get("x-session-id") ?? "";
|
|
44
|
+
const context = await readState((svc, registry) => ({ room: svc.getRoom(roomID), entry: registry[roomID]?.[sessionID] }));
|
|
45
|
+
if (!context.entry) return json({ error: "forbidden" }, 403);
|
|
46
|
+
// Human admins delete anything; an agent may delete only the file it uploaded.
|
|
47
|
+
const ownAgentUpload = !isUser(context.entry) && resource.uploaderSessionID === sessionID;
|
|
48
|
+
if (!isRoomAdmin(context.room, context.entry) && !ownAgentUpload) return json({ error: "forbidden" }, 403);
|
|
49
|
+
await deleteResource(roomID, id);
|
|
50
|
+
return json({ ok: true });
|
|
51
|
+
}
|
|
38
52
|
if (!item![3]) return json({ resource });
|
|
39
53
|
return await content(req, resource);
|
|
40
54
|
} catch (error) {
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import RoomService, { type Room } from "../src/rooms/room-service.ts";
|
|
3
|
+
import type { Registry, RegistryEntry } from "../src/state/store.ts";
|
|
4
|
+
import { bindOwner, isUser } from "./room-owner";
|
|
5
|
+
|
|
6
|
+
export type JoinMember = {
|
|
7
|
+
sessionID: string;
|
|
8
|
+
participantId: string;
|
|
9
|
+
name: string;
|
|
10
|
+
protocol?: "v2";
|
|
11
|
+
receiverOwnerID?: string;
|
|
12
|
+
directory?: string;
|
|
13
|
+
host?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// Shared by the join endpoint and approved join requests so an approved member
|
|
17
|
+
// gets exactly the same membership, rename retirement, and owner binding.
|
|
18
|
+
export function joinRoomMember(svc: RoomService, registry: Registry, roomId: string, member: JoinMember): Room {
|
|
19
|
+
const currentRoom = svc.getRoom(roomId);
|
|
20
|
+
const participantId = currentRoom.kind === "direct" ? member.sessionID : member.participantId;
|
|
21
|
+
const regRoom = (registry[roomId] = registry[roomId] ?? Object.create(null) as Record<string, RegistryEntry>);
|
|
22
|
+
const prevEntry = regRoom[member.sessionID];
|
|
23
|
+
// Retire the participant this session previously held, unless another
|
|
24
|
+
// session still uses the old name.
|
|
25
|
+
if (currentRoom.kind !== "direct" && prevEntry && prevEntry.name !== member.name) {
|
|
26
|
+
const shared = Object.entries(regRoom).some(([sid, entry]) => sid !== member.sessionID && entry.name === prevEntry.name);
|
|
27
|
+
if (!shared && svc.containsParticipant(roomId, prevEntry.name)) svc.leaveRoom(roomId, prevEntry.name);
|
|
28
|
+
}
|
|
29
|
+
const already = svc.containsParticipant(roomId, participantId);
|
|
30
|
+
// Prune a stale registry entry for the same name from another session, but
|
|
31
|
+
// only when the identity is not already present.
|
|
32
|
+
if (!already && currentRoom.kind !== "direct") {
|
|
33
|
+
for (const [sid, entry] of Object.entries(regRoom)) if (sid !== member.sessionID && entry.name === member.name) delete regRoom[sid];
|
|
34
|
+
}
|
|
35
|
+
svc.joinRoom(roomId, { id: participantId, name: member.name });
|
|
36
|
+
if (!already) svc.addEvent(roomId, `${member.name} joined the room`);
|
|
37
|
+
const latestMessageTs = svc.getMessages(roomId).at(-1)?.createdAt ?? 0;
|
|
38
|
+
regRoom[member.sessionID] = {
|
|
39
|
+
serverUrl: "",
|
|
40
|
+
apiPrefix: "/api",
|
|
41
|
+
...(member.protocol === "v2" ? { protocol: "v2" as const } : {}),
|
|
42
|
+
...(member.protocol === "v2" && member.receiverOwnerID ? { receiverOwnerID: member.receiverOwnerID } : {}),
|
|
43
|
+
name: member.name,
|
|
44
|
+
membershipID: prevEntry?.membershipID ?? randomUUID(),
|
|
45
|
+
directory: member.directory || undefined,
|
|
46
|
+
host: member.host ?? "",
|
|
47
|
+
lastQueuedTs: regRoom[member.sessionID]?.lastQueuedTs,
|
|
48
|
+
lastReadTs: regRoom[member.sessionID]?.lastReadTs ?? Math.max(Date.now(), latestMessageTs),
|
|
49
|
+
};
|
|
50
|
+
// An ownerless room is claimed by the first person who arrives; agents never are.
|
|
51
|
+
const joinedRoom = svc.getRoom(roomId);
|
|
52
|
+
if (!joinedRoom.ownerId && isUser(regRoom[member.sessionID])) {
|
|
53
|
+
joinedRoom.ownerId = member.name;
|
|
54
|
+
joinedRoom.ownerMembershipID = regRoom[member.sessionID]!.membershipID;
|
|
55
|
+
} else {
|
|
56
|
+
bindOwner(joinedRoom, regRoom);
|
|
57
|
+
}
|
|
58
|
+
return svc.getRoom(roomId);
|
|
59
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Participant, Room } from "../src/rooms/room-service.ts";
|
|
2
|
+
import { isUser } from "../src/state/roles.ts";
|
|
3
|
+
|
|
4
|
+
export { isOwnerEntry, isRoomAdmin, isUser } from "../src/state/roles.ts";
|
|
5
|
+
|
|
6
|
+
export type OwnerEntry = { name?: string | null; protocol?: string | null; host?: string | null; receiverOwnerID?: string | null; membershipID?: string | null };
|
|
7
|
+
|
|
8
|
+
function humans(room: Room, registry: Record<string, OwnerEntry>): OwnerEntry[] {
|
|
9
|
+
const joined = new Map([...room.participants.values()].map((member) => [member.name, member]));
|
|
10
|
+
return Object.values(registry)
|
|
11
|
+
.filter(isUser)
|
|
12
|
+
.filter((entry) => joined.has(entry.name!))
|
|
13
|
+
.sort((left, right) => joined.get(left.name!)!.joinedAt - joined.get(right.name!)!.joinedAt) as OwnerEntry[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// A room whose owner entry vanished follows the explicit successor first, then the
|
|
17
|
+
// first person still present; the last person out leaves the room open to claim.
|
|
18
|
+
export function settleOwner(room: Room, registry: Record<string, OwnerEntry>): string {
|
|
19
|
+
const people = humans(room, registry);
|
|
20
|
+
const bound = room.ownerMembershipID ? people.find((entry) => entry.membershipID === room.ownerMembershipID) : undefined;
|
|
21
|
+
if (bound) { room.ownerId = bound.name!; return room.ownerId; }
|
|
22
|
+
if (!room.ownerMembershipID) {
|
|
23
|
+
const named = people.find((entry) => entry.name === room.ownerId);
|
|
24
|
+
if (named) { room.ownerMembershipID = named.membershipID ?? undefined; return room.ownerId; }
|
|
25
|
+
}
|
|
26
|
+
const successor = room.successorId
|
|
27
|
+
? people.find((entry) => room.successorMembershipID ? entry.membershipID === room.successorMembershipID : entry.name === room.successorId)
|
|
28
|
+
: undefined;
|
|
29
|
+
const chosen = successor ?? people[0];
|
|
30
|
+
room.ownerId = chosen?.name ?? "";
|
|
31
|
+
if (chosen?.membershipID) room.ownerMembershipID = chosen.membershipID; else delete room.ownerMembershipID;
|
|
32
|
+
delete room.successorId;
|
|
33
|
+
delete room.successorMembershipID;
|
|
34
|
+
const admins = (room.adminIds ?? []).filter((name) => name !== room.ownerId);
|
|
35
|
+
if (admins.length) room.adminIds = admins;
|
|
36
|
+
else if (room.adminIds) delete room.adminIds;
|
|
37
|
+
if (chosen?.membershipID && room.adminMembershipIDs?.length) {
|
|
38
|
+
const ids = room.adminMembershipIDs.filter((id) => id !== chosen.membershipID);
|
|
39
|
+
if (ids.length) room.adminMembershipIDs = ids; else delete room.adminMembershipIDs;
|
|
40
|
+
}
|
|
41
|
+
return room.ownerId;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Joining must not transfer ownership: bind a legacy room once, follow a renamed
|
|
45
|
+
// owner membership, and only settle when the bound owner is really gone.
|
|
46
|
+
export function bindOwner(room: Room, registry: Record<string, OwnerEntry>): void {
|
|
47
|
+
if (!room.ownerId) return;
|
|
48
|
+
const people = humans(room, registry);
|
|
49
|
+
if (room.ownerMembershipID) {
|
|
50
|
+
const bound = people.find((entry) => entry.membershipID === room.ownerMembershipID);
|
|
51
|
+
if (bound) { room.ownerId = bound.name!; return; }
|
|
52
|
+
settleOwner(room, registry);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const named = people.find((entry) => entry.name === room.ownerId);
|
|
56
|
+
if (named?.membershipID) room.ownerMembershipID = named.membershipID;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Delegated admins follow the people still in the room; the owner is implicit.
|
|
60
|
+
export function settleAdmins(room: Room, registry: Record<string, OwnerEntry>): void {
|
|
61
|
+
if (!room.adminIds?.length) return;
|
|
62
|
+
const people = Object.values(registry).filter(isUser);
|
|
63
|
+
const names = new Set(people.map((entry) => entry.name));
|
|
64
|
+
const next = room.adminIds.filter((name) => names.has(name));
|
|
65
|
+
if (next.length) room.adminIds = next;
|
|
66
|
+
else delete room.adminIds;
|
|
67
|
+
if (room.adminMembershipIDs?.length) {
|
|
68
|
+
const ids = new Set(people.map((entry) => entry.membershipID).filter(Boolean));
|
|
69
|
+
const kept = room.adminMembershipIDs.filter((id) => ids.has(id));
|
|
70
|
+
if (kept.length) room.adminMembershipIDs = kept; else delete room.adminMembershipIDs;
|
|
71
|
+
}
|
|
72
|
+
}
|
package/server/room-payload.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { countOpenQuestions, readHistory } from "../src/store";
|
|
2
|
-
import type { Room } from "../src/room-service";
|
|
1
|
+
import { countOpenQuestions, readHistory } from "../src/state/store.ts";
|
|
2
|
+
import type { Room } from "../src/rooms/room-service.ts";
|
|
3
3
|
import { binding, tx } from "./admin-state";
|
|
4
4
|
|
|
5
5
|
// Initial page of history sent when a room is opened; older pages load on scroll.
|
|
@@ -16,13 +16,17 @@ export async function roomPayload(room: Room, limit = ROOM_WINDOW) {
|
|
|
16
16
|
name: room.name,
|
|
17
17
|
description: room.description ?? "",
|
|
18
18
|
ownerId: room.ownerId,
|
|
19
|
+
adminIds: room.adminIds ?? [],
|
|
20
|
+
successorId: room.successorId ?? null,
|
|
19
21
|
createdAt: room.createdAt,
|
|
22
|
+
joinPolicy: room.joinPolicy ?? "open",
|
|
20
23
|
participants: [...room.participants.values()],
|
|
21
24
|
messages: page.messages,
|
|
22
25
|
kind: room.kind ?? "group",
|
|
23
26
|
...(room.directSessionIDs ? { directSessionIDs: room.directSessionIDs } : {}),
|
|
24
27
|
hasMore: page.hasMore,
|
|
25
28
|
nextBeforeSeq: page.nextBeforeSeq,
|
|
29
|
+
recallVersion: page.recallVersion,
|
|
26
30
|
adminSessionID: admin?.session_id ?? null,
|
|
27
31
|
openQuestions,
|
|
28
32
|
};
|
package/server/room-reminders.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Cron } from "croner";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
|
-
import { databasePath } from "../src/store";
|
|
4
|
-
import { initializeReminderSchema, withStateTransaction } from "../src/sqlite-state";
|
|
5
|
-
import type { Message } from "../src/room-service";
|
|
3
|
+
import { databasePath } from "../src/state/store.ts";
|
|
4
|
+
import { initializeReminderSchema, withStateTransaction } from "../src/state/sqlite-state.ts";
|
|
5
|
+
import type { Message } from "../src/rooms/room-service.ts";
|
|
6
6
|
|
|
7
7
|
type Schedule = { type: "once"; at: string; timezone?: string } | { type: "cron"; expression: string; timezone: string };
|
|
8
8
|
type Row = { id: string; room_id: string; creator_session_id: string; initiator: string; text: string; schedule_type: string; at: string | null; expression: string | null; timezone: string | null; paused: number; next_run_at: number; created_at: number; last_error: string | null };
|
package/server/sw.js
CHANGED