@alexsun-top/opencode-chat-room 0.7.6 → 0.7.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 +32 -0
- package/README.md +5 -5
- package/README.zh-CN.md +5 -5
- package/dist/cli.js +815 -192
- package/package.json +3 -2
- package/plugin.ts +15 -3
- package/server/assets/base.css +0 -2
- package/server/assets/chat/announcements.js +5 -2
- package/server/assets/chat/clipboard.js +30 -0
- package/server/assets/chat/copy-action.js +48 -0
- package/server/assets/chat/diagram-viewer.js +253 -0
- package/server/assets/chat/doc-preview.js +160 -13
- package/server/assets/chat/editor.js +10 -7
- package/server/assets/chat/events.js +26 -5
- package/server/assets/chat/files.js +26 -5
- package/server/assets/chat/history-loader.js +3 -1
- package/server/assets/chat/index.js +11 -1
- package/server/assets/chat/join-requests.js +6 -3
- package/server/assets/chat/locales/de.js +20 -2
- package/server/assets/chat/locales/es.js +20 -2
- package/server/assets/chat/locales/fr.js +20 -2
- package/server/assets/chat/locales/it.js +20 -2
- package/server/assets/chat/locales/ja.js +20 -2
- package/server/assets/chat/locales/ko.js +20 -2
- package/server/assets/chat/markdown.js +75 -86
- package/server/assets/chat/messages.js +7 -3
- package/server/assets/chat/palette.js +40 -18
- package/server/assets/chat/pwa.js +2 -0
- package/server/assets/chat/questions.js +6 -0
- package/server/assets/chat/resource-format.js +74 -0
- package/server/assets/chat/rooms.js +9 -1
- package/server/assets/chat/shortcuts.js +14 -3
- package/server/assets/chat/side-pane.js +136 -0
- package/server/assets/chat/state.js +85 -8
- package/server/assets/chat/system-messages.js +3 -1
- package/server/assets/chat/task-form.js +197 -0
- package/server/assets/chat/task-row.js +170 -0
- package/server/assets/chat/tasks.js +521 -0
- package/server/assets/chat/viewport.js +5 -0
- package/server/assets/conversation.css +25 -1
- package/server/assets/diagram-viewer.css +141 -0
- package/server/assets/doc-preview.css +24 -5
- package/server/assets/responsive.css +108 -14
- package/server/assets/tasks.css +419 -0
- package/server/chat-server.ts +9 -4
- package/server/chat.html +120 -21
- package/server/member-routes.ts +3 -0
- package/server/resource-routes.ts +3 -1
- package/server/sw.js +247 -4
- package/server/task-routes.ts +53 -0
- package/skills/chatroom/SKILL.md +3 -1
- package/src/README.md +3 -3
- package/src/agent/chatroom-skill.ts +8 -2
- package/src/agent/task-tool.ts +155 -0
- package/src/center/center-client.ts +44 -0
- package/src/rooms/resources.ts +2 -2
- package/src/rooms/tasks.ts +246 -0
- package/src/runtime/v2-plugin.ts +11 -2
- package/src/runtime/watch.ts +38 -5
- package/src/state/sqlite-state.ts +93 -8
- package/src/state/store.ts +2 -2
- package/src/tui/app.mjs +14 -4
- package/src/tui/http.mjs +2 -2
- package/src/tui/info-app.mjs +24 -15
- package/src/tui/join-app.mjs +3 -3
- package/src/tui/main.mjs +4 -4
- package/src/tui/markdown.mjs +31 -5
- package/src/tui/mentions.mjs +218 -0
- package/src/tui/message-app.mjs +15 -11
- package/src/tui/palette-app.mjs +19 -9
- package/src/tui/reminder-app.mjs +14 -10
- package/src/tui/ui-content.mjs +12 -3
- package/src/tui/ui-mentions.mjs +44 -0
- package/src/tui/ui-suggest-view.mjs +63 -0
- package/src/tui/ui-suggest.mjs +197 -0
- package/src/tui/ui-theme.mjs +2 -1
- package/src/tui/ui-view.mjs +2 -0
- package/src/tui/ui.mjs +17 -9
package/dist/cli.js
CHANGED
|
@@ -805,6 +805,8 @@ async function initialize2(file) {
|
|
|
805
805
|
CREATE TABLE IF NOT EXISTS registry(room_id TEXT NOT NULL REFERENCES rooms(id) ON DELETE CASCADE,session_id TEXT NOT NULL,server_url TEXT NOT NULL,api_prefix TEXT NOT NULL,protocol TEXT,name TEXT NOT NULL,last_read_ts INTEGER,last_queued_ts INTEGER,directory TEXT,host TEXT,receiver_owner_id TEXT,membership_id TEXT,work_state TEXT,last_seen_at INTEGER,PRIMARY KEY(room_id,session_id));`);
|
|
806
806
|
db.exec("CREATE TABLE IF NOT EXISTS announcements(room_id TEXT NOT NULL REFERENCES rooms(id) ON DELETE CASCADE,name TEXT NOT NULL,content TEXT NOT NULL,updated_at INTEGER NOT NULL,PRIMARY KEY(room_id,name))");
|
|
807
807
|
db.exec("CREATE TABLE IF NOT EXISTS resources(id TEXT PRIMARY KEY,room_id TEXT NOT NULL REFERENCES rooms(id) ON DELETE CASCADE,name TEXT NOT NULL,mime_type TEXT NOT NULL,size INTEGER NOT NULL,created_at INTEGER NOT NULL,uploader_session_id TEXT,uploader_name TEXT)");
|
|
808
|
+
db.exec("CREATE TABLE IF NOT EXISTS room_tasks(id TEXT PRIMARY KEY,room_id TEXT NOT NULL REFERENCES rooms(id) ON DELETE CASCADE,title TEXT NOT NULL,description TEXT NOT NULL DEFAULT '',assignee TEXT NOT NULL DEFAULT '',status TEXT NOT NULL CHECK(status IN ('todo','doing','done')),creator_name TEXT NOT NULL,creator_session_id TEXT NOT NULL,created_at INTEGER NOT NULL,updated_at INTEGER NOT NULL,due_date TEXT NOT NULL DEFAULT '',participants TEXT NOT NULL DEFAULT '[]',conclusion TEXT NOT NULL DEFAULT '',steps TEXT NOT NULL DEFAULT '[]')");
|
|
809
|
+
db.exec("CREATE INDEX IF NOT EXISTS room_tasks_room_status_created ON room_tasks(room_id,status,created_at,id)");
|
|
808
810
|
await ensureRoomColumns(db);
|
|
809
811
|
await migrate(db, file);
|
|
810
812
|
db.exec("PRAGMA busy_timeout=50;");
|
|
@@ -852,9 +854,10 @@ async function putResource(file, resource) {
|
|
|
852
854
|
return true;
|
|
853
855
|
});
|
|
854
856
|
}
|
|
855
|
-
async function listResources(file, roomID, limit = 500, offset = 0) {
|
|
857
|
+
async function listResources(file, roomID, limit = 500, offset = 0, beforeID) {
|
|
856
858
|
const db = await initialize2(file);
|
|
857
|
-
const
|
|
859
|
+
const cursor = beforeID ? db.query("SELECT created_at AS createdAt,id FROM resources WHERE room_id=? AND id=?").get(roomID, beforeID) : null;
|
|
860
|
+
const items = cursor ? db.query("SELECT id,room_id AS roomID,name,mime_type AS mimeType,size,created_at AS createdAt,uploader_session_id AS uploaderSessionID,uploader_name AS uploaderName FROM resources WHERE room_id=? AND (created_at<? OR (created_at=? AND id<?)) ORDER BY created_at DESC, id DESC LIMIT ?").all(roomID, cursor.createdAt, cursor.createdAt, cursor.id, limit) : db.query("SELECT id,room_id AS roomID,name,mime_type AS mimeType,size,created_at AS createdAt,uploader_session_id AS uploaderSessionID,uploader_name AS uploaderName FROM resources WHERE room_id=? ORDER BY created_at DESC, id DESC LIMIT ? OFFSET ?").all(roomID, limit, offset);
|
|
858
861
|
const total = Number(db.query("SELECT COUNT(*) AS count FROM resources WHERE room_id=?").get(roomID)?.count ?? 0);
|
|
859
862
|
return { items, total };
|
|
860
863
|
}
|
|
@@ -870,6 +873,41 @@ async function removeResource(file, roomID, id) {
|
|
|
870
873
|
const db = await openStateDatabase(file);
|
|
871
874
|
return immediate2(db, () => db.query("DELETE FROM resources WHERE room_id=? AND id=?").run(roomID, id).changes > 0);
|
|
872
875
|
}
|
|
876
|
+
function listRoomTasks(db, roomID) {
|
|
877
|
+
return db.query(`SELECT ${ROOM_TASK_COLUMNS} FROM room_tasks WHERE room_id=? ORDER BY created_at,id`).all(roomID).map(roomTask);
|
|
878
|
+
}
|
|
879
|
+
function readRoomTask(db, roomID, id) {
|
|
880
|
+
const row = db.query(`SELECT ${ROOM_TASK_COLUMNS} FROM room_tasks WHERE room_id=? AND id=?`).get(roomID, id);
|
|
881
|
+
return row ? roomTask(row) : undefined;
|
|
882
|
+
}
|
|
883
|
+
function insertRoomTask(db, task) {
|
|
884
|
+
db.query("INSERT INTO room_tasks(id,room_id,title,description,assignee,status,creator_name,creator_session_id,created_at,updated_at,due_date,participants,conclusion,steps) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)").run(task.id, task.roomId, task.title, task.description, task.assignee, task.status, task.creatorName, task.creatorSessionID, task.createdAt, task.updatedAt, task.dueDate, JSON.stringify(task.participants), task.conclusion, JSON.stringify(task.steps));
|
|
885
|
+
}
|
|
886
|
+
function patchRoomTask(db, roomID, id, patch, updatedAt) {
|
|
887
|
+
const sets = [], values = [];
|
|
888
|
+
for (const [column, value] of [["title", patch.title], ["description", patch.description], ["assignee", patch.assignee], ["status", patch.status], ["due_date", patch.dueDate], ["conclusion", patch.conclusion]]) {
|
|
889
|
+
if (value !== undefined) {
|
|
890
|
+
sets.push(`${column}=?`);
|
|
891
|
+
values.push(value);
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
if (patch.participants !== undefined) {
|
|
895
|
+
sets.push("participants=?");
|
|
896
|
+
values.push(JSON.stringify(patch.participants));
|
|
897
|
+
}
|
|
898
|
+
if (patch.steps !== undefined) {
|
|
899
|
+
sets.push("steps=?");
|
|
900
|
+
values.push(JSON.stringify(patch.steps));
|
|
901
|
+
}
|
|
902
|
+
db.query(`UPDATE room_tasks SET ${sets.map((set) => `${set},`).join("")}updated_at=? WHERE room_id=? AND id=?`).run(...values, updatedAt, roomID, id);
|
|
903
|
+
return readRoomTask(db, roomID, id);
|
|
904
|
+
}
|
|
905
|
+
function deleteRoomTask(db, roomID, id) {
|
|
906
|
+
return db.query("DELETE FROM room_tasks WHERE room_id=? AND id=?").run(roomID, id).changes > 0;
|
|
907
|
+
}
|
|
908
|
+
function deleteCompletedRoomTasks(db, roomID, creatorSessionID) {
|
|
909
|
+
return creatorSessionID === undefined ? db.query("DELETE FROM room_tasks WHERE room_id=? AND status='done'").run(roomID).changes : db.query("DELETE FROM room_tasks WHERE room_id=? AND status='done' AND creator_session_id=?").run(roomID, creatorSessionID).changes;
|
|
910
|
+
}
|
|
873
911
|
async function ensureRoomColumns(db) {
|
|
874
912
|
await immediate2(db, () => {
|
|
875
913
|
const messageColumns = db.query("PRAGMA table_info(messages)").all();
|
|
@@ -883,8 +921,21 @@ async function ensureRoomColumns(db) {
|
|
|
883
921
|
db.exec("ALTER TABLE messages ADD COLUMN recalled_at INTEGER");
|
|
884
922
|
if (!messageColumns.some((column) => column.name === "recalled_by"))
|
|
885
923
|
db.exec("ALTER TABLE messages ADD COLUMN recalled_by TEXT");
|
|
924
|
+
if (!messageColumns.some((column) => column.name === "client_msg_id"))
|
|
925
|
+
db.exec("ALTER TABLE messages ADD COLUMN client_msg_id TEXT");
|
|
926
|
+
db.exec("DROP INDEX IF EXISTS messages_client_id");
|
|
927
|
+
db.exec("CREATE UNIQUE INDEX IF NOT EXISTS messages_client_id ON messages(room_id,sender_session_id,client_msg_id) WHERE client_msg_id IS NOT NULL");
|
|
886
928
|
db.exec("CREATE INDEX IF NOT EXISTS messages_pending_questions ON messages(room_id,is_question,answered_by,seq)");
|
|
887
929
|
db.exec("CREATE INDEX IF NOT EXISTS messages_room_recalled ON messages(room_id,recalled_at)");
|
|
930
|
+
const taskColumns = db.query("PRAGMA table_info(room_tasks)").all();
|
|
931
|
+
if (!taskColumns.some((column) => column.name === "due_date"))
|
|
932
|
+
db.exec("ALTER TABLE room_tasks ADD COLUMN due_date TEXT NOT NULL DEFAULT ''");
|
|
933
|
+
if (!taskColumns.some((column) => column.name === "participants"))
|
|
934
|
+
db.exec("ALTER TABLE room_tasks ADD COLUMN participants TEXT NOT NULL DEFAULT '[]'");
|
|
935
|
+
if (!taskColumns.some((column) => column.name === "conclusion"))
|
|
936
|
+
db.exec("ALTER TABLE room_tasks ADD COLUMN conclusion TEXT NOT NULL DEFAULT ''");
|
|
937
|
+
if (!taskColumns.some((column) => column.name === "steps"))
|
|
938
|
+
db.exec("ALTER TABLE room_tasks ADD COLUMN steps TEXT NOT NULL DEFAULT '[]'");
|
|
888
939
|
db.exec("CREATE TABLE IF NOT EXISTS room_recall_versions(room_id TEXT PRIMARY KEY REFERENCES rooms(id) ON DELETE CASCADE,version INTEGER NOT NULL)");
|
|
889
940
|
db.exec(`CREATE TABLE IF NOT EXISTS room_join_requests(
|
|
890
941
|
room_id TEXT NOT NULL REFERENCES rooms(id) ON DELETE CASCADE,
|
|
@@ -1232,7 +1283,7 @@ async function answerQuestion(file, roomID, questionID, sessionID, text) {
|
|
|
1232
1283
|
return { status: "ok", answer };
|
|
1233
1284
|
});
|
|
1234
1285
|
}
|
|
1235
|
-
async function appendRoomMessage(file, roomID, sessionID, text, isQuestion) {
|
|
1286
|
+
async function appendRoomMessage(file, roomID, sessionID, text, isQuestion, clientMessageID) {
|
|
1236
1287
|
const db = await openStateDatabase(file);
|
|
1237
1288
|
return immediate2(db, () => {
|
|
1238
1289
|
if (!db.query("SELECT 1 FROM rooms WHERE id=?").get(roomID))
|
|
@@ -1240,6 +1291,11 @@ async function appendRoomMessage(file, roomID, sessionID, text, isQuestion) {
|
|
|
1240
1291
|
const member = db.query("SELECT g.name,r.kind FROM registry g JOIN rooms r ON r.id=g.room_id JOIN participants p ON p.room_id=g.room_id AND p.id=CASE WHEN r.kind='direct' THEN g.session_id ELSE g.name END WHERE g.room_id=? AND g.session_id=?").get(roomID, sessionID);
|
|
1241
1292
|
if (!member)
|
|
1242
1293
|
return { status: "member" };
|
|
1294
|
+
if (clientMessageID) {
|
|
1295
|
+
const existing = db.query("SELECT id,room_id,sender_id,sender_session_id,text,created_at,is_question,answer_to,answered_by FROM messages WHERE room_id=? AND client_msg_id=? AND sender_session_id=?").get(roomID, clientMessageID, sessionID);
|
|
1296
|
+
if (existing)
|
|
1297
|
+
return { status: "ok", message: rowMessage(existing), duplicate: true };
|
|
1298
|
+
}
|
|
1243
1299
|
const tail = db.query("SELECT created_at FROM messages WHERE room_id=? ORDER BY seq DESC LIMIT 1").get(roomID);
|
|
1244
1300
|
const message = {
|
|
1245
1301
|
id: randomUUID4(),
|
|
@@ -1250,12 +1306,12 @@ async function appendRoomMessage(file, roomID, sessionID, text, isQuestion) {
|
|
|
1250
1306
|
createdAt: Math.max(Date.now(), (tail?.created_at ?? 0) + 1),
|
|
1251
1307
|
...isQuestion ? { isQuestion: true } : {}
|
|
1252
1308
|
};
|
|
1253
|
-
db.query("INSERT INTO messages(id,room_id,sender_id,sender_session_id,text,created_at,is_question) VALUES(
|
|
1309
|
+
db.query("INSERT INTO messages(id,room_id,sender_id,sender_session_id,text,created_at,is_question,client_msg_id) VALUES(?,?,?,?,?,?,?,?)").run(message.id, roomID, message.senderId, sessionID, text, message.createdAt, isQuestion ? 1 : 0, clientMessageID ?? null);
|
|
1254
1310
|
noteMessageInsert(db, roomID);
|
|
1255
1311
|
return { status: "ok", message };
|
|
1256
1312
|
});
|
|
1257
1313
|
}
|
|
1258
|
-
async function sendReply(file, roomID, targetID, sessionID, text) {
|
|
1314
|
+
async function sendReply(file, roomID, targetID, sessionID, text, clientMessageID) {
|
|
1259
1315
|
const db = await openStateDatabase(file);
|
|
1260
1316
|
return immediate2(db, () => {
|
|
1261
1317
|
if (!db.query("SELECT 1 FROM rooms WHERE id=?").get(roomID))
|
|
@@ -1263,6 +1319,11 @@ async function sendReply(file, roomID, targetID, sessionID, text) {
|
|
|
1263
1319
|
const member = db.query("SELECT g.name,r.kind FROM registry g JOIN rooms r ON r.id=g.room_id JOIN participants p ON p.room_id=g.room_id AND p.id=CASE WHEN r.kind='direct' THEN g.session_id ELSE g.name END WHERE g.room_id=? AND g.session_id=?").get(roomID, sessionID);
|
|
1264
1320
|
if (!member)
|
|
1265
1321
|
return { status: "member" };
|
|
1322
|
+
if (clientMessageID) {
|
|
1323
|
+
const existing = db.query("SELECT id,room_id,sender_id,sender_session_id,text,created_at,is_question,answer_to,answered_by FROM messages WHERE room_id=? AND client_msg_id=? AND sender_session_id=?").get(roomID, clientMessageID, sessionID);
|
|
1324
|
+
if (existing)
|
|
1325
|
+
return { status: "ok", message: rowMessage(existing), duplicate: true };
|
|
1326
|
+
}
|
|
1266
1327
|
const target = db.query("SELECT is_question,recalled_at FROM messages WHERE room_id=? AND id=?").get(roomID, targetID);
|
|
1267
1328
|
if (!target || target.recalled_at !== null)
|
|
1268
1329
|
return { status: "target" };
|
|
@@ -1270,7 +1331,7 @@ async function sendReply(file, roomID, targetID, sessionID, text) {
|
|
|
1270
1331
|
return { status: "question" };
|
|
1271
1332
|
const tail = db.query("SELECT created_at FROM messages WHERE room_id=? ORDER BY seq DESC LIMIT 1").get(roomID);
|
|
1272
1333
|
const message = { id: randomUUID4(), roomId: roomID, senderId: member.kind === "direct" ? sessionID : member.name, senderSessionID: sessionID, text, createdAt: Math.max(Date.now(), (tail?.created_at ?? 0) + 1), answerToMessageID: targetID };
|
|
1273
|
-
db.query("INSERT INTO messages(id,room_id,sender_id,sender_session_id,text,created_at,is_question,answer_to) VALUES(?,?,?,?,?,?,0
|
|
1334
|
+
db.query("INSERT INTO messages(id,room_id,sender_id,sender_session_id,text,created_at,is_question,answer_to,client_msg_id) VALUES(?,?,?,?,?,?,0,?,?)").run(message.id, roomID, message.senderId, sessionID, text, message.createdAt, targetID, clientMessageID ?? null);
|
|
1274
1335
|
noteMessageInsert(db, roomID);
|
|
1275
1336
|
return { status: "ok", message };
|
|
1276
1337
|
});
|
|
@@ -1540,11 +1601,24 @@ function rowMessage(row) {
|
|
|
1540
1601
|
...row.answered_by ? { answeredByMessageID: String(row.answered_by) } : {}
|
|
1541
1602
|
};
|
|
1542
1603
|
}
|
|
1543
|
-
var databases2,
|
|
1604
|
+
var databases2, ROOM_TASK_STATUSES, ROOM_TASK_COLUMNS = "id,room_id AS roomId,title,description,assignee,status,creator_name AS creatorName,creator_session_id AS creatorSessionID,created_at AS createdAt,updated_at AS updatedAt,due_date AS dueDate,participants,conclusion,steps", jsonArray = (value) => {
|
|
1605
|
+
try {
|
|
1606
|
+
const parsed = JSON.parse(value);
|
|
1607
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
1608
|
+
} catch {
|
|
1609
|
+
return [];
|
|
1610
|
+
}
|
|
1611
|
+
}, roomTask = (row) => ({
|
|
1612
|
+
...row,
|
|
1613
|
+
status: row.status,
|
|
1614
|
+
participants: jsonArray(row.participants),
|
|
1615
|
+
steps: jsonArray(row.steps)
|
|
1616
|
+
}), pause2 = (ms) => new Promise((resolve) => setTimeout(resolve, ms)), adminBindings = (room) => room.adminMembershipIDs?.length ? JSON.stringify([...new Set(room.adminMembershipIDs)]) : null, roomBindings = (room) => [room.ownerMembershipID ?? null, room.successorId ?? null, room.successorMembershipID ?? null], JOIN_REQUEST_COLUMNS = "session_id AS sessionID,participant_id AS participantId,name,protocol,receiver_owner_id AS receiverOwnerID,directory,host,is_agent AS isAgent,created_at AS createdAt", MAX_RETAINED_MESSAGES = 1e6, retentionCounters;
|
|
1544
1617
|
var init_sqlite_state = __esm(() => {
|
|
1545
1618
|
init_room_service();
|
|
1546
1619
|
init_sqlite();
|
|
1547
1620
|
databases2 = new Map;
|
|
1621
|
+
ROOM_TASK_STATUSES = ["todo", "doing", "done"];
|
|
1548
1622
|
retentionCounters = new Map;
|
|
1549
1623
|
});
|
|
1550
1624
|
|
|
@@ -1595,11 +1669,11 @@ function acknowledgeQueued2(roomID, sessionID, ts) {
|
|
|
1595
1669
|
async function answerQuestion2(roomID, questionID, sessionID, text) {
|
|
1596
1670
|
return answerQuestion(databasePath(), roomID, questionID, sessionID, text);
|
|
1597
1671
|
}
|
|
1598
|
-
async function sendReply2(roomID, targetID, sessionID, text) {
|
|
1599
|
-
return sendReply(databasePath(), roomID, targetID, sessionID, text);
|
|
1672
|
+
async function sendReply2(roomID, targetID, sessionID, text, clientMessageID) {
|
|
1673
|
+
return sendReply(databasePath(), roomID, targetID, sessionID, text, clientMessageID);
|
|
1600
1674
|
}
|
|
1601
|
-
function appendRoomMessage2(roomID, sessionID, text, isQuestion) {
|
|
1602
|
-
return appendRoomMessage(databasePath(), roomID, sessionID, text, isQuestion);
|
|
1675
|
+
function appendRoomMessage2(roomID, sessionID, text, isQuestion, clientMessageID) {
|
|
1676
|
+
return appendRoomMessage(databasePath(), roomID, sessionID, text, isQuestion, clientMessageID);
|
|
1603
1677
|
}
|
|
1604
1678
|
async function readQuestionExcerpt2(roomID, questionID) {
|
|
1605
1679
|
return readQuestionExcerpt(databasePath(), roomID, questionID);
|
|
@@ -1834,6 +1908,388 @@ var init_queue = __esm(() => {
|
|
|
1834
1908
|
PENDING_TTL_MS = 5 * 60000;
|
|
1835
1909
|
});
|
|
1836
1910
|
|
|
1911
|
+
// src/rooms/tasks.ts
|
|
1912
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
1913
|
+
function context(db, roomID, sessionID) {
|
|
1914
|
+
const room = db.query("SELECT kind,owner_id,owner_membership_id,admin_names,admin_membership_ids FROM rooms WHERE id=?").get(roomID);
|
|
1915
|
+
if (!room)
|
|
1916
|
+
return { status: 404, error: "room not found" };
|
|
1917
|
+
if (room.kind === "direct")
|
|
1918
|
+
return { status: 409, error: "tasks are not available in direct rooms" };
|
|
1919
|
+
const member = db.query("SELECT g.name,g.protocol,g.host,g.receiver_owner_id,g.membership_id FROM registry g JOIN participants p ON p.room_id=g.room_id AND p.id=g.name WHERE g.room_id=? AND g.session_id=?").get(roomID, sessionID);
|
|
1920
|
+
if (!member)
|
|
1921
|
+
return { status: 403, error: "not a room member" };
|
|
1922
|
+
const roleRoom = {
|
|
1923
|
+
ownerId: room.owner_id,
|
|
1924
|
+
...room.owner_membership_id ? { ownerMembershipID: room.owner_membership_id } : {},
|
|
1925
|
+
...room.admin_names ? { adminIds: JSON.parse(room.admin_names) } : {},
|
|
1926
|
+
...room.admin_membership_ids ? { adminMembershipIDs: JSON.parse(room.admin_membership_ids) } : {}
|
|
1927
|
+
};
|
|
1928
|
+
const entry = {
|
|
1929
|
+
name: member.name,
|
|
1930
|
+
...member.protocol ? { protocol: member.protocol } : {},
|
|
1931
|
+
...member.host ? { host: member.host } : {},
|
|
1932
|
+
...member.receiver_owner_id ? { receiverOwnerID: member.receiver_owner_id } : {},
|
|
1933
|
+
...member.membership_id ? { membershipID: member.membership_id } : {}
|
|
1934
|
+
};
|
|
1935
|
+
const participants = new Set(db.query("SELECT name FROM participants WHERE room_id=?").all(roomID).map((row) => row.name));
|
|
1936
|
+
return { room: roleRoom, entry, name: member.name, participants };
|
|
1937
|
+
}
|
|
1938
|
+
function readTitle(value) {
|
|
1939
|
+
if (typeof value !== "string")
|
|
1940
|
+
return;
|
|
1941
|
+
const title = value.trim();
|
|
1942
|
+
return title && Array.from(title).length <= MAX_TITLE ? title : undefined;
|
|
1943
|
+
}
|
|
1944
|
+
function readDescription(value) {
|
|
1945
|
+
return typeof value === "string" && Array.from(value).length <= MAX_DESCRIPTION ? value : undefined;
|
|
1946
|
+
}
|
|
1947
|
+
function readDueDate(value) {
|
|
1948
|
+
if (typeof value !== "string")
|
|
1949
|
+
return;
|
|
1950
|
+
if (value === "")
|
|
1951
|
+
return "";
|
|
1952
|
+
if (value.length !== 10)
|
|
1953
|
+
return;
|
|
1954
|
+
const date = new Date(`${value}T00:00:00Z`);
|
|
1955
|
+
return !Number.isNaN(date.getTime()) && date.toISOString().slice(0, 10) === value ? value : undefined;
|
|
1956
|
+
}
|
|
1957
|
+
function readParticipants(value, participants) {
|
|
1958
|
+
if (!Array.isArray(value) || value.length > MAX_PARTICIPANTS)
|
|
1959
|
+
return;
|
|
1960
|
+
const names = [];
|
|
1961
|
+
for (const name of value) {
|
|
1962
|
+
if (typeof name !== "string" || !participants.has(name) || names.includes(name))
|
|
1963
|
+
return;
|
|
1964
|
+
names.push(name);
|
|
1965
|
+
}
|
|
1966
|
+
return names;
|
|
1967
|
+
}
|
|
1968
|
+
function readConclusion(value) {
|
|
1969
|
+
return typeof value === "string" && Array.from(value).length <= MAX_CONCLUSION ? value : undefined;
|
|
1970
|
+
}
|
|
1971
|
+
function readStepText(value) {
|
|
1972
|
+
return typeof value === "string" && value.trim().length > 0 && Array.from(value).length <= MAX_STEP_TEXT ? value : undefined;
|
|
1973
|
+
}
|
|
1974
|
+
function readSteps(value) {
|
|
1975
|
+
if (!Array.isArray(value) || value.length > MAX_STEPS)
|
|
1976
|
+
return;
|
|
1977
|
+
const steps = [];
|
|
1978
|
+
for (const item of value) {
|
|
1979
|
+
if (typeof item === "string") {
|
|
1980
|
+
const text = readStepText(item);
|
|
1981
|
+
if (text === undefined)
|
|
1982
|
+
return;
|
|
1983
|
+
steps.push({ text, done: false });
|
|
1984
|
+
continue;
|
|
1985
|
+
}
|
|
1986
|
+
if (typeof item !== "object" || item === null || Array.isArray(item))
|
|
1987
|
+
return;
|
|
1988
|
+
const text = readStepText(item.text);
|
|
1989
|
+
const done = item.done;
|
|
1990
|
+
if (text === undefined || typeof done !== "boolean")
|
|
1991
|
+
return;
|
|
1992
|
+
steps.push({ text, done });
|
|
1993
|
+
}
|
|
1994
|
+
return steps;
|
|
1995
|
+
}
|
|
1996
|
+
function listTasks(roomID, sessionID) {
|
|
1997
|
+
return withStateTransaction(databasePath(), (db) => {
|
|
1998
|
+
const ctx = context(db, roomID, sessionID);
|
|
1999
|
+
if (isFailure(ctx))
|
|
2000
|
+
return ctx;
|
|
2001
|
+
return { tasks: listRoomTasks(db, roomID) };
|
|
2002
|
+
});
|
|
2003
|
+
}
|
|
2004
|
+
function createTask(roomID, sessionID, input) {
|
|
2005
|
+
return withStateTransaction(databasePath(), (db) => {
|
|
2006
|
+
const ctx = context(db, roomID, sessionID);
|
|
2007
|
+
if (isFailure(ctx))
|
|
2008
|
+
return ctx;
|
|
2009
|
+
const title = readTitle(input.title);
|
|
2010
|
+
if (!title)
|
|
2011
|
+
return invalid(`title must contain 1 to ${MAX_TITLE} characters`);
|
|
2012
|
+
const description = input.description === undefined ? "" : readDescription(input.description);
|
|
2013
|
+
if (description === undefined)
|
|
2014
|
+
return invalid(`description must be a string of at most ${MAX_DESCRIPTION} characters`);
|
|
2015
|
+
const assignee = input.assignee === undefined ? "" : input.assignee;
|
|
2016
|
+
if (typeof assignee !== "string" || assignee !== "" && !ctx.participants.has(assignee))
|
|
2017
|
+
return invalid("assignee must be a current participant name");
|
|
2018
|
+
const dueDate = input.dueDate === undefined ? "" : readDueDate(input.dueDate);
|
|
2019
|
+
if (dueDate === undefined)
|
|
2020
|
+
return invalid("dueDate must be empty or a valid YYYY-MM-DD calendar date");
|
|
2021
|
+
const participants = input.participants === undefined ? [] : readParticipants(input.participants, ctx.participants);
|
|
2022
|
+
if (participants === undefined)
|
|
2023
|
+
return invalid(`participants must be at most ${MAX_PARTICIPANTS} unique current participant names`);
|
|
2024
|
+
const conclusion = input.conclusion === undefined ? "" : readConclusion(input.conclusion);
|
|
2025
|
+
if (conclusion === undefined)
|
|
2026
|
+
return invalid(`conclusion must be a string of at most ${MAX_CONCLUSION} characters`);
|
|
2027
|
+
const steps = input.steps === undefined ? [] : readSteps(input.steps);
|
|
2028
|
+
if (steps === undefined)
|
|
2029
|
+
return invalid(`steps must be at most ${MAX_STEPS} items, each text 1 to ${MAX_STEP_TEXT} characters with a boolean done`);
|
|
2030
|
+
const now = Date.now();
|
|
2031
|
+
const task = {
|
|
2032
|
+
id: randomUUID5(),
|
|
2033
|
+
roomId: roomID,
|
|
2034
|
+
title,
|
|
2035
|
+
description,
|
|
2036
|
+
assignee,
|
|
2037
|
+
status: "todo",
|
|
2038
|
+
creatorName: ctx.name,
|
|
2039
|
+
creatorSessionID: sessionID,
|
|
2040
|
+
createdAt: now,
|
|
2041
|
+
updatedAt: now,
|
|
2042
|
+
dueDate,
|
|
2043
|
+
participants,
|
|
2044
|
+
conclusion,
|
|
2045
|
+
steps
|
|
2046
|
+
};
|
|
2047
|
+
insertRoomTask(db, task);
|
|
2048
|
+
return { task };
|
|
2049
|
+
});
|
|
2050
|
+
}
|
|
2051
|
+
function updateTask(roomID, taskID, sessionID, input) {
|
|
2052
|
+
return withStateTransaction(databasePath(), (db) => {
|
|
2053
|
+
const ctx = context(db, roomID, sessionID);
|
|
2054
|
+
if (isFailure(ctx))
|
|
2055
|
+
return ctx;
|
|
2056
|
+
const task = readRoomTask(db, roomID, taskID);
|
|
2057
|
+
if (!task)
|
|
2058
|
+
return { status: 404, error: "task not found" };
|
|
2059
|
+
const patch = {};
|
|
2060
|
+
if (input.title !== undefined) {
|
|
2061
|
+
const title = readTitle(input.title);
|
|
2062
|
+
if (!title)
|
|
2063
|
+
return invalid(`title must contain 1 to ${MAX_TITLE} characters`);
|
|
2064
|
+
patch.title = title;
|
|
2065
|
+
}
|
|
2066
|
+
if (input.description !== undefined) {
|
|
2067
|
+
const description = readDescription(input.description);
|
|
2068
|
+
if (description === undefined)
|
|
2069
|
+
return invalid(`description must be a string of at most ${MAX_DESCRIPTION} characters`);
|
|
2070
|
+
patch.description = description;
|
|
2071
|
+
}
|
|
2072
|
+
if (input.assignee !== undefined) {
|
|
2073
|
+
const assignee = input.assignee;
|
|
2074
|
+
if (typeof assignee !== "string")
|
|
2075
|
+
return invalid("assignee must be a current participant name");
|
|
2076
|
+
if (assignee !== "" && !ctx.participants.has(assignee) && assignee !== task.assignee)
|
|
2077
|
+
return invalid("assignee must be a current participant name");
|
|
2078
|
+
patch.assignee = assignee;
|
|
2079
|
+
}
|
|
2080
|
+
if (input.status !== undefined) {
|
|
2081
|
+
if (typeof input.status !== "string" || !ROOM_TASK_STATUSES.includes(input.status))
|
|
2082
|
+
return invalid("status must be todo, doing, or done");
|
|
2083
|
+
patch.status = input.status;
|
|
2084
|
+
}
|
|
2085
|
+
if (input.dueDate !== undefined) {
|
|
2086
|
+
const dueDate = readDueDate(input.dueDate);
|
|
2087
|
+
if (dueDate === undefined)
|
|
2088
|
+
return invalid("dueDate must be empty or a valid YYYY-MM-DD calendar date");
|
|
2089
|
+
patch.dueDate = dueDate;
|
|
2090
|
+
}
|
|
2091
|
+
if (input.participants !== undefined) {
|
|
2092
|
+
const allowed = new Set([...ctx.participants, ...task.participants]);
|
|
2093
|
+
const participants = readParticipants(input.participants, allowed);
|
|
2094
|
+
if (participants === undefined)
|
|
2095
|
+
return invalid(`participants must be at most ${MAX_PARTICIPANTS} unique participant names`);
|
|
2096
|
+
patch.participants = participants;
|
|
2097
|
+
}
|
|
2098
|
+
if (input.conclusion !== undefined) {
|
|
2099
|
+
const conclusion = readConclusion(input.conclusion);
|
|
2100
|
+
if (conclusion === undefined)
|
|
2101
|
+
return invalid(`conclusion must be a string of at most ${MAX_CONCLUSION} characters`);
|
|
2102
|
+
patch.conclusion = conclusion;
|
|
2103
|
+
}
|
|
2104
|
+
if (input.steps !== undefined) {
|
|
2105
|
+
const steps = readSteps(input.steps);
|
|
2106
|
+
if (steps === undefined)
|
|
2107
|
+
return invalid(`steps must be at most ${MAX_STEPS} items, each text 1 to ${MAX_STEP_TEXT} characters with a boolean done`);
|
|
2108
|
+
patch.steps = steps;
|
|
2109
|
+
}
|
|
2110
|
+
if (!Object.keys(patch).length)
|
|
2111
|
+
return invalid("at least one task field is required");
|
|
2112
|
+
const admin = isRoomAdmin(ctx.room, ctx.entry);
|
|
2113
|
+
const creator = task.creatorSessionID === sessionID;
|
|
2114
|
+
const assignee = task.assignee !== "" && task.assignee === ctx.name;
|
|
2115
|
+
const contentChanged = patch.title !== undefined || patch.description !== undefined || patch.assignee !== undefined || patch.dueDate !== undefined || patch.participants !== undefined || patch.conclusion !== undefined;
|
|
2116
|
+
const stepsChanged = patch.steps !== undefined && (patch.steps.length !== task.steps.length || patch.steps.some((step, index) => step.text !== task.steps[index].text));
|
|
2117
|
+
if (!admin && !creator && (!assignee || contentChanged || stepsChanged)) {
|
|
2118
|
+
return { status: 403, error: "only the creator or a room admin may edit task fields; the assignee may change status or toggle step done values" };
|
|
2119
|
+
}
|
|
2120
|
+
const updated = patchRoomTask(db, roomID, taskID, patch, Date.now());
|
|
2121
|
+
return updated ? { task: updated } : { status: 404, error: "task not found" };
|
|
2122
|
+
});
|
|
2123
|
+
}
|
|
2124
|
+
function deleteTask(roomID, taskID, sessionID) {
|
|
2125
|
+
return withStateTransaction(databasePath(), (db) => {
|
|
2126
|
+
const ctx = context(db, roomID, sessionID);
|
|
2127
|
+
if (isFailure(ctx))
|
|
2128
|
+
return ctx;
|
|
2129
|
+
const task = readRoomTask(db, roomID, taskID);
|
|
2130
|
+
if (!task)
|
|
2131
|
+
return { status: 404, error: "task not found" };
|
|
2132
|
+
if (task.creatorSessionID !== sessionID && !isRoomAdmin(ctx.room, ctx.entry)) {
|
|
2133
|
+
return { status: 403, error: "not allowed to delete this task" };
|
|
2134
|
+
}
|
|
2135
|
+
deleteRoomTask(db, roomID, taskID);
|
|
2136
|
+
return { ok: true };
|
|
2137
|
+
});
|
|
2138
|
+
}
|
|
2139
|
+
function clearCompletedTasks(roomID, sessionID) {
|
|
2140
|
+
return withStateTransaction(databasePath(), (db) => {
|
|
2141
|
+
const ctx = context(db, roomID, sessionID);
|
|
2142
|
+
if (isFailure(ctx))
|
|
2143
|
+
return ctx;
|
|
2144
|
+
const admin = isRoomAdmin(ctx.room, ctx.entry);
|
|
2145
|
+
return { ok: true, count: deleteCompletedRoomTasks(db, roomID, admin ? undefined : sessionID) };
|
|
2146
|
+
});
|
|
2147
|
+
}
|
|
2148
|
+
var MAX_TITLE = 200, MAX_DESCRIPTION = 5000, MAX_CONCLUSION = 5000, MAX_PARTICIPANTS = 50, MAX_STEPS = 30, MAX_STEP_TEXT = 300, invalid = (error) => ({ status: 400, error }), isFailure = (value) => ("status" in value);
|
|
2149
|
+
var init_tasks = __esm(() => {
|
|
2150
|
+
init_sqlite_state();
|
|
2151
|
+
init_store();
|
|
2152
|
+
init_sqlite_state();
|
|
2153
|
+
});
|
|
2154
|
+
|
|
2155
|
+
// src/agent/task-tool.ts
|
|
2156
|
+
function visible(value, max) {
|
|
2157
|
+
return typeof value === "string" && value.trim().length > 0 && Array.from(value.trim()).length <= max;
|
|
2158
|
+
}
|
|
2159
|
+
function calendarDate(value) {
|
|
2160
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
|
|
2161
|
+
if (!match)
|
|
2162
|
+
return false;
|
|
2163
|
+
const [year, month, day] = [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
2164
|
+
const date = new Date(Date.UTC(year, month - 1, day));
|
|
2165
|
+
return date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day;
|
|
2166
|
+
}
|
|
2167
|
+
function readSteps2(value) {
|
|
2168
|
+
if (!Array.isArray(value) || value.length > MAX_STEPS2)
|
|
2169
|
+
return;
|
|
2170
|
+
const steps = [];
|
|
2171
|
+
for (const item of value) {
|
|
2172
|
+
if (typeof item === "string") {
|
|
2173
|
+
if (!visible(item, 300))
|
|
2174
|
+
return;
|
|
2175
|
+
steps.push(item.trim());
|
|
2176
|
+
continue;
|
|
2177
|
+
}
|
|
2178
|
+
if (!item || typeof item !== "object" || Array.isArray(item))
|
|
2179
|
+
return;
|
|
2180
|
+
const step = item;
|
|
2181
|
+
if (!visible(step.text, 300) || step.done !== undefined && typeof step.done !== "boolean")
|
|
2182
|
+
return;
|
|
2183
|
+
steps.push({ text: step.text.trim(), done: step.done === true });
|
|
2184
|
+
}
|
|
2185
|
+
return steps;
|
|
2186
|
+
}
|
|
2187
|
+
function displaySteps(steps) {
|
|
2188
|
+
return (steps ?? []).flatMap((step) => {
|
|
2189
|
+
if (typeof step === "string")
|
|
2190
|
+
return step ? [{ text: step, done: false }] : [];
|
|
2191
|
+
return typeof step?.text === "string" && step.text ? [{ text: step.text, done: step.done === true }] : [];
|
|
2192
|
+
});
|
|
2193
|
+
}
|
|
2194
|
+
function validateTaskFields(fields, creating) {
|
|
2195
|
+
if (creating && (typeof fields.title !== "string" || !fields.title.trim()))
|
|
2196
|
+
return "title is required to create a task; pass a short task title";
|
|
2197
|
+
if (fields.title !== undefined && !visible(fields.title, 200))
|
|
2198
|
+
return "title must contain 1 to 200 characters";
|
|
2199
|
+
if (fields.description !== undefined && (typeof fields.description !== "string" || Array.from(fields.description).length > 5000))
|
|
2200
|
+
return "description must be a string of at most 5000 characters";
|
|
2201
|
+
if (fields.assignee !== undefined && (typeof fields.assignee !== "string" || Array.from(fields.assignee.trim()).length > 64))
|
|
2202
|
+
return "assignee must be a participant name of at most 64 characters";
|
|
2203
|
+
if (fields.status !== undefined && !["todo", "doing", "done"].includes(fields.status))
|
|
2204
|
+
return "status must be todo, doing, or done";
|
|
2205
|
+
if (fields.dueDate !== undefined) {
|
|
2206
|
+
if (typeof fields.dueDate !== "string")
|
|
2207
|
+
return "dueDate must be YYYY-MM-DD or empty to clear it";
|
|
2208
|
+
if (fields.dueDate.trim() !== "" && !calendarDate(fields.dueDate.trim()))
|
|
2209
|
+
return "dueDate must be a real calendar date in YYYY-MM-DD form, for example 2026-12-31, or empty to clear it";
|
|
2210
|
+
}
|
|
2211
|
+
if (fields.participants !== undefined && (!Array.isArray(fields.participants) || fields.participants.length > 50 || !fields.participants.every((name) => visible(name, 64))))
|
|
2212
|
+
return "participants must be an array of at most 50 room participant names, each 1 to 64 characters";
|
|
2213
|
+
if (fields.conclusion !== undefined && (typeof fields.conclusion !== "string" || Array.from(fields.conclusion).length > 5000))
|
|
2214
|
+
return "conclusion must be a string of at most 5000 characters";
|
|
2215
|
+
if (fields.steps !== undefined && readSteps2(fields.steps) === undefined)
|
|
2216
|
+
return "steps must be an array of at most 30 steps; each step is text of 1 to 300 characters or {text, done}";
|
|
2217
|
+
return;
|
|
2218
|
+
}
|
|
2219
|
+
function taskFields(args) {
|
|
2220
|
+
return {
|
|
2221
|
+
...args.title !== undefined ? { title: args.title.trim() } : {},
|
|
2222
|
+
...args.description !== undefined ? { description: args.description } : {},
|
|
2223
|
+
...args.assignee !== undefined ? { assignee: args.assignee.trim() } : {},
|
|
2224
|
+
...args.status !== undefined ? { status: args.status } : {},
|
|
2225
|
+
...args.dueDate !== undefined ? { dueDate: args.dueDate.trim() } : {},
|
|
2226
|
+
...args.participants !== undefined ? { participants: args.participants.map((name) => name.trim()) } : {},
|
|
2227
|
+
...args.conclusion !== undefined ? { conclusion: args.conclusion } : {},
|
|
2228
|
+
...args.steps !== undefined ? { steps: readSteps2(args.steps) } : {}
|
|
2229
|
+
};
|
|
2230
|
+
}
|
|
2231
|
+
function formatTasks(tasks) {
|
|
2232
|
+
if (!tasks.length)
|
|
2233
|
+
return "no tasks";
|
|
2234
|
+
return tasks.map((task) => {
|
|
2235
|
+
const steps = displaySteps(task.steps);
|
|
2236
|
+
const done = steps.filter((step) => step.done).length;
|
|
2237
|
+
return `${task.id} [${task.status}] ${task.title} (creator: ${task.creatorName})` + `${task.assignee ? ` (assignee: ${task.assignee})` : ""}` + `${task.dueDate ? ` (due: ${task.dueDate})` : ""}` + `${task.participants?.length ? ` (participants: ${task.participants.join(", ")})` : ""}` + `${task.description ? `
|
|
2238
|
+
${task.description}` : ""}` + `${steps.length ? `
|
|
2239
|
+
steps: ${done}/${steps.length}${steps.map((step) => `
|
|
2240
|
+
- [${step.done ? "x" : " "}] ${step.text}`).join("")}` : ""}` + `${task.conclusion ? `
|
|
2241
|
+
conclusion: ${task.conclusion}` : ""}`;
|
|
2242
|
+
}).join(`
|
|
2243
|
+
`);
|
|
2244
|
+
}
|
|
2245
|
+
function failure(error, status, action) {
|
|
2246
|
+
if (status === 404) {
|
|
2247
|
+
return error === "room not found" ? "error: room not found; run room action list to see valid room UUIDs" : `error: ${error}; run task_list to get a task ID`;
|
|
2248
|
+
}
|
|
2249
|
+
if (status === 403 && (action === "task_list" || action === "task_create"))
|
|
2250
|
+
return NOT_JOINED;
|
|
2251
|
+
if (status === 403)
|
|
2252
|
+
return `error: ${error}; only the task creator or a room administrator can edit or delete a task, and the assignee may change status or toggle existing steps`;
|
|
2253
|
+
return `error: ${error}`;
|
|
2254
|
+
}
|
|
2255
|
+
async function runTaskTool(args, sessionID) {
|
|
2256
|
+
if (!args.action.startsWith("task_"))
|
|
2257
|
+
return;
|
|
2258
|
+
if (!args.roomId)
|
|
2259
|
+
return "error: roomId is required; use a room UUID from the room list, not the room name";
|
|
2260
|
+
if (args.action === "task_list") {
|
|
2261
|
+
const result = await listTasks(args.roomId, sessionID);
|
|
2262
|
+
return "error" in result ? failure(result.error, result.status, args.action) : formatTasks(result.tasks);
|
|
2263
|
+
}
|
|
2264
|
+
if (args.action === "task_create") {
|
|
2265
|
+
const error = validateTaskFields(args, true);
|
|
2266
|
+
if (error)
|
|
2267
|
+
return `error: ${error}`;
|
|
2268
|
+
const result = await createTask(args.roomId, sessionID, taskFields(args));
|
|
2269
|
+
return "error" in result ? failure(result.error, result.status, args.action) : `task created: ${result.task.title} (id: ${result.task.id}, status: ${result.task.status})`;
|
|
2270
|
+
}
|
|
2271
|
+
if (!args.taskId)
|
|
2272
|
+
return "error: taskId is required; run task_list to get a task ID";
|
|
2273
|
+
if (args.action === "task_delete") {
|
|
2274
|
+
const result = await deleteTask(args.roomId, args.taskId, sessionID);
|
|
2275
|
+
return "error" in result ? failure(result.error, result.status, args.action) : `task deleted: ${args.taskId}`;
|
|
2276
|
+
}
|
|
2277
|
+
if (args.action !== "task_update")
|
|
2278
|
+
return "error: unsupported task action";
|
|
2279
|
+
const error = validateTaskFields(args, false);
|
|
2280
|
+
if (error)
|
|
2281
|
+
return `error: ${error}`;
|
|
2282
|
+
if (!EDIT_KEYS.some((field) => args[field] !== undefined))
|
|
2283
|
+
return `error: at least one of ${EDIT_KEYS.join(", ")} is required to update a task`;
|
|
2284
|
+
const result = await updateTask(args.roomId, args.taskId, sessionID, taskFields(args));
|
|
2285
|
+
return "error" in result ? failure(result.error, result.status, args.action) : `task updated: ${result.task.title} (id: ${result.task.id}, status: ${result.task.status})`;
|
|
2286
|
+
}
|
|
2287
|
+
var EDIT_KEYS, MAX_STEPS2 = 30, NOT_JOINED = "error: not joined; call join for this room first, and wait for approval if required";
|
|
2288
|
+
var init_task_tool = __esm(() => {
|
|
2289
|
+
init_tasks();
|
|
2290
|
+
EDIT_KEYS = ["title", "description", "assignee", "status", "dueDate", "participants", "conclusion", "steps"];
|
|
2291
|
+
});
|
|
2292
|
+
|
|
1837
2293
|
// src/center/queue-transport.ts
|
|
1838
2294
|
function backgroundResult(value) {
|
|
1839
2295
|
return typeof value === "boolean" ? value ? { status: "done" } : { status: "failed", reason: "unclassified-failure" } : value;
|
|
@@ -2166,6 +2622,49 @@ ${result.announcement.content}`;
|
|
|
2166
2622
|
await request(opts, path, "DELETE", { sessionID });
|
|
2167
2623
|
return `announcement deleted: ${args.announcementName}`;
|
|
2168
2624
|
}
|
|
2625
|
+
case "task_list": {
|
|
2626
|
+
if (!args.roomId)
|
|
2627
|
+
return "error: roomId is required; use a room UUID from the room list, not the room name";
|
|
2628
|
+
const result = await request(opts, `/rooms/${encodeURIComponent(args.roomId)}/tasks?sessionID=${encodeURIComponent(sessionID)}`, "GET");
|
|
2629
|
+
return formatTasks(Array.isArray(result.tasks) ? result.tasks : []);
|
|
2630
|
+
}
|
|
2631
|
+
case "task_create": {
|
|
2632
|
+
if (!args.roomId)
|
|
2633
|
+
return "error: roomId is required; use a room UUID from the room list, not the room name";
|
|
2634
|
+
const error = validateTaskFields(args, true);
|
|
2635
|
+
if (error)
|
|
2636
|
+
return `error: ${error}`;
|
|
2637
|
+
const result = await request(opts, `/rooms/${encodeURIComponent(args.roomId)}/tasks`, "POST", {
|
|
2638
|
+
sessionID,
|
|
2639
|
+
...taskFields(args)
|
|
2640
|
+
});
|
|
2641
|
+
return `task created: ${result.task.title} (id: ${result.task.id}, status: ${result.task.status})`;
|
|
2642
|
+
}
|
|
2643
|
+
case "task_update": {
|
|
2644
|
+
if (!args.roomId)
|
|
2645
|
+
return "error: roomId is required; use a room UUID from the room list, not the room name";
|
|
2646
|
+
if (!args.taskId)
|
|
2647
|
+
return "error: taskId is required; run task_list to get a task ID";
|
|
2648
|
+
const error = validateTaskFields(args, false);
|
|
2649
|
+
if (error)
|
|
2650
|
+
return `error: ${error}`;
|
|
2651
|
+
const fields = taskFields(args);
|
|
2652
|
+
if (!Object.keys(fields).length)
|
|
2653
|
+
return "error: at least one of title, description, assignee, status, dueDate, participants, conclusion, or steps is required to update a task";
|
|
2654
|
+
const result = await request(opts, `/rooms/${encodeURIComponent(args.roomId)}/tasks/${encodeURIComponent(args.taskId)}`, "PATCH", {
|
|
2655
|
+
sessionID,
|
|
2656
|
+
...fields
|
|
2657
|
+
});
|
|
2658
|
+
return `task updated: ${result.task.title} (id: ${result.task.id}, status: ${result.task.status})`;
|
|
2659
|
+
}
|
|
2660
|
+
case "task_delete": {
|
|
2661
|
+
if (!args.roomId)
|
|
2662
|
+
return "error: roomId is required; use a room UUID from the room list, not the room name";
|
|
2663
|
+
if (!args.taskId)
|
|
2664
|
+
return "error: taskId is required; run task_list to get a task ID";
|
|
2665
|
+
await request(opts, `/rooms/${encodeURIComponent(args.roomId)}/tasks/${encodeURIComponent(args.taskId)}`, "DELETE", { sessionID });
|
|
2666
|
+
return `task deleted: ${args.taskId}`;
|
|
2667
|
+
}
|
|
2169
2668
|
case "send": {
|
|
2170
2669
|
if (!args.roomId) {
|
|
2171
2670
|
return "error: roomId is required; use a room UUID from the room list, not the room name";
|
|
@@ -2239,6 +2738,7 @@ var init_center_client = __esm(() => {
|
|
|
2239
2738
|
init_store();
|
|
2240
2739
|
init_queue();
|
|
2241
2740
|
init_session_delivery();
|
|
2741
|
+
init_task_tool();
|
|
2242
2742
|
init_queue();
|
|
2243
2743
|
init_queue_transport();
|
|
2244
2744
|
});
|
|
@@ -2499,7 +2999,7 @@ var init_file_config = __esm(() => {
|
|
|
2499
2999
|
});
|
|
2500
3000
|
|
|
2501
3001
|
// src/agent/agent-presence.ts
|
|
2502
|
-
import { randomUUID as
|
|
3002
|
+
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
2503
3003
|
function locallyOwnedSessions(registry, ownerID) {
|
|
2504
3004
|
return new Set(Object.values(registry).flatMap((entries) => Object.entries(entries).filter(([, entry]) => entry.protocol === "v2" && entry.receiverOwnerID === ownerID).map(([id]) => id)));
|
|
2505
3005
|
}
|
|
@@ -2509,7 +3009,7 @@ async function reportAgentPresence(input) {
|
|
|
2509
3009
|
return;
|
|
2510
3010
|
const target = input.center.center ? new URL(input.center.center).origin : "standalone";
|
|
2511
3011
|
const key = `presence:${input.ownerID}:${target}`;
|
|
2512
|
-
const holder =
|
|
3012
|
+
const holder = randomUUID6();
|
|
2513
3013
|
const now = Date.now();
|
|
2514
3014
|
try {
|
|
2515
3015
|
if (!acquireDeliveryLease(key, holder, now, now + LEASE_MS2))
|
|
@@ -2560,7 +3060,7 @@ var init_agent_presence = __esm(() => {
|
|
|
2560
3060
|
});
|
|
2561
3061
|
|
|
2562
3062
|
// src/agent/agent-receipts.ts
|
|
2563
|
-
import { createHash as createHash3, randomUUID as
|
|
3063
|
+
import { createHash as createHash3, randomUUID as randomUUID7 } from "node:crypto";
|
|
2564
3064
|
import path6 from "node:path";
|
|
2565
3065
|
function hasCappedMetadata(item) {
|
|
2566
3066
|
return typeof item.senderId === "string" && typeof item.createdAt === "number" && Number.isSafeInteger(item.createdAt) && !/[\r\n]/.test(item.senderId) && !/[\r\n]/.test(item.text);
|
|
@@ -2665,7 +3165,7 @@ function flushReceiptCandidates(input) {
|
|
|
2665
3165
|
}
|
|
2666
3166
|
async function flushOneReceiptCandidate(input, cursorKey) {
|
|
2667
3167
|
const leaseKey = `receipt-flush:${hash(cursorKey)}`;
|
|
2668
|
-
const holder =
|
|
3168
|
+
const holder = randomUUID7(), now = Date.now();
|
|
2669
3169
|
if (!acquireDeliveryLease(leaseKey, holder, now, now + RECEIPT_FLUSH_LEASE_MS))
|
|
2670
3170
|
return;
|
|
2671
3171
|
try {
|
|
@@ -3484,11 +3984,15 @@ var init_plugin_notifications = __esm(() => {
|
|
|
3484
3984
|
});
|
|
3485
3985
|
|
|
3486
3986
|
// src/agent/chatroom-skill.ts
|
|
3487
|
-
import { readFileSync as readFileSync3 } from "node:fs";
|
|
3987
|
+
import { existsSync as existsSync2, readFileSync as readFileSync3 } from "node:fs";
|
|
3488
3988
|
import { fileURLToPath } from "node:url";
|
|
3489
|
-
var path8, source, metadata, content, description, chatroomSkill;
|
|
3989
|
+
var candidates, path8, source, metadata, content, description, chatroomSkill;
|
|
3490
3990
|
var init_chatroom_skill = __esm(() => {
|
|
3491
|
-
|
|
3991
|
+
candidates = [
|
|
3992
|
+
new URL("../../skills/chatroom/SKILL.md", import.meta.url),
|
|
3993
|
+
new URL("../skills/chatroom/SKILL.md", import.meta.url)
|
|
3994
|
+
].map((url) => fileURLToPath(url));
|
|
3995
|
+
path8 = candidates.find((candidate) => existsSync2(candidate)) ?? candidates[0];
|
|
3492
3996
|
source = readFileSync3(path8, "utf8");
|
|
3493
3997
|
[, metadata = "", content = source] = source.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/) ?? [];
|
|
3494
3998
|
description = metadata.match(/^description:\s*(.+)$/m)?.[1]?.trim();
|
|
@@ -3502,7 +4006,7 @@ var init_chatroom_skill = __esm(() => {
|
|
|
3502
4006
|
});
|
|
3503
4007
|
|
|
3504
4008
|
// src/agent/admin-credentials.ts
|
|
3505
|
-
import { createHash as createHash5, randomUUID as
|
|
4009
|
+
import { createHash as createHash5, randomUUID as randomUUID8 } from "node:crypto";
|
|
3506
4010
|
import { mkdir, readFile, rename, chmod, writeFile, rm } from "node:fs/promises";
|
|
3507
4011
|
import path9 from "node:path";
|
|
3508
4012
|
function credentialPath(identity) {
|
|
@@ -3512,7 +4016,7 @@ async function persist(file, content) {
|
|
|
3512
4016
|
const directory = path9.dirname(file);
|
|
3513
4017
|
await mkdir(directory, { recursive: true, mode: 448 });
|
|
3514
4018
|
await chmod(directory, 448);
|
|
3515
|
-
const temporary = `${file}.${
|
|
4019
|
+
const temporary = `${file}.${randomUUID8()}.tmp`;
|
|
3516
4020
|
try {
|
|
3517
4021
|
await writeFile(temporary, JSON.stringify(content), { mode: 384, flag: "wx" });
|
|
3518
4022
|
await chmod(temporary, 384);
|
|
@@ -3752,7 +4256,7 @@ function createV2Setup(deps) {
|
|
|
3752
4256
|
});
|
|
3753
4257
|
toolRegistration = await context.tool.transform((editor) => editor.add({
|
|
3754
4258
|
name: "room",
|
|
3755
|
-
description: "Chat room operations: create, join, join_status, leave and list rooms; send and poll messages; list members and
|
|
4259
|
+
description: "Chat room operations: create, join, join_status, leave and list rooms; send and poll messages; list members, announcements and tasks; create, update and delete room tasks; manage reminders. In an approval room join returns pending: you are not a member yet; call join_status to check whether an administrator approved you. Reminder schedules use the server timezone unless an IANA timezone is provided; once schedules require an ISO datetime. Upload files and media; upload_resource returns a [[resource:UUID]] marker, and the attachment renders only when that exact marker is included in a send message. read_resource saves files to a private temporary path and leaves them there until removed or system cleanup. delete_resource removes an uploaded file; servers allow human room administrators any resource and agents only their own uploads.",
|
|
3756
4260
|
options: { codemode: false },
|
|
3757
4261
|
input: roomSchema(),
|
|
3758
4262
|
execute: async (args, toolContext) => {
|
|
@@ -3851,7 +4355,7 @@ The user invoked /room. Use the room tool to perform this command.`,
|
|
|
3851
4355
|
}
|
|
3852
4356
|
function roomSchema() {
|
|
3853
4357
|
return z2.object({
|
|
3854
|
-
action: z2.enum(["create", "join", "join_status", "leave", "list", "send", "poll", "members", "upload_resource", "read_resource", "delete_resource", "announcement_list", "announcement_read", "announcement_write", "announcement_delete", "reminder_list", "reminder_create", "reminder_update", "reminder_delete"]),
|
|
4358
|
+
action: z2.enum(["create", "join", "join_status", "leave", "list", "send", "poll", "members", "upload_resource", "read_resource", "delete_resource", "announcement_list", "announcement_read", "announcement_write", "announcement_delete", "reminder_list", "reminder_create", "reminder_update", "reminder_delete", "task_list", "task_create", "task_update", "task_delete"]),
|
|
3855
4359
|
name: z2.string().max(64).optional().describe("For join: your own participant display name, NOT the room name (required). For create: the new room name."),
|
|
3856
4360
|
roomId: z2.string().optional(),
|
|
3857
4361
|
resourceId: z2.string().optional(),
|
|
@@ -3860,6 +4364,15 @@ function roomSchema() {
|
|
|
3860
4364
|
isQuestion: z2.boolean().optional(),
|
|
3861
4365
|
announcementName: z2.string().optional().describe("Name of a room announcement; distinct from participant or room name."),
|
|
3862
4366
|
content: z2.string().optional().describe("Announcement content, at most 5000 Unicode characters."),
|
|
4367
|
+
taskId: z2.string().optional().describe("Task UUID from task_list; required for task_update and task_delete."),
|
|
4368
|
+
title: z2.string().optional().describe("Task title, 1 to 200 characters; required for task_create."),
|
|
4369
|
+
description: z2.string().optional().describe("Task description, at most 5000 characters."),
|
|
4370
|
+
assignee: z2.string().optional().describe("Participant display name responsible for the task; empty leaves it unassigned."),
|
|
4371
|
+
status: z2.enum(["todo", "doing", "done"]).optional().describe("Task status; the assignee may change only this field."),
|
|
4372
|
+
dueDate: z2.string().optional().describe("Task due date as YYYY-MM-DD; empty clears it."),
|
|
4373
|
+
participants: z2.array(z2.string()).optional().describe("Task participants as room participant display names; empty clears them."),
|
|
4374
|
+
conclusion: z2.string().optional().describe("Task conclusion, at most 5000 characters; empty clears it."),
|
|
4375
|
+
steps: z2.array(z2.union([z2.string(), z2.object({ text: z2.string(), done: z2.boolean().optional() })])).optional().describe("Task checklist, at most 30 steps; each is text of 1 to 300 characters or {text, done}; empty clears them."),
|
|
3863
4376
|
reminderId: z2.string().optional(),
|
|
3864
4377
|
schedule: z2.discriminatedUnion("type", [z2.object({ type: z2.literal("once"), at: z2.string(), timezone: z2.string().refine((value) => {
|
|
3865
4378
|
try {
|
|
@@ -4102,7 +4615,7 @@ var init_resource_upload = () => {};
|
|
|
4102
4615
|
|
|
4103
4616
|
// src/rooms/resource-read.ts
|
|
4104
4617
|
import { promises as fs3 } from "node:fs";
|
|
4105
|
-
import { randomUUID as
|
|
4618
|
+
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
4106
4619
|
import os7 from "node:os";
|
|
4107
4620
|
import path11 from "node:path";
|
|
4108
4621
|
function resourceReadFailure(error) {
|
|
@@ -4164,7 +4677,7 @@ async function saveResource(permission, headers, endpoint, resource, allowed, si
|
|
|
4164
4677
|
await ask(permission, "external_directory", [tmp], { filepath: tmp });
|
|
4165
4678
|
const directory = await fs3.mkdtemp(path11.join(tmp, "opencode-chat-room-"));
|
|
4166
4679
|
const extension = path11.extname(resource.name).toLowerCase();
|
|
4167
|
-
const filename = `${
|
|
4680
|
+
const filename = `${randomUUID9()}${/^\.[a-z0-9]{1,10}$/.test(extension) ? extension : ".bin"}`;
|
|
4168
4681
|
const filepath = path11.join(directory, filename);
|
|
4169
4682
|
try {
|
|
4170
4683
|
await fs3.chmod(directory, 448);
|
|
@@ -4567,6 +5080,9 @@ var connection, centerUrl, centerToken, serveWakeUrl, runtimeContext, defaultRun
|
|
|
4567
5080
|
const announcementResult = await runAnnouncementTool(args, context.sessionID);
|
|
4568
5081
|
if (announcementResult !== undefined)
|
|
4569
5082
|
return announcementResult;
|
|
5083
|
+
const taskResult = await runTaskTool(args, context.sessionID);
|
|
5084
|
+
if (taskResult !== undefined)
|
|
5085
|
+
return taskResult;
|
|
4570
5086
|
let selfName = identity();
|
|
4571
5087
|
let joinPrevName;
|
|
4572
5088
|
let joinPrevShared = false;
|
|
@@ -4729,6 +5245,7 @@ var init_plugin = __esm(() => {
|
|
|
4729
5245
|
init_v2_plugin();
|
|
4730
5246
|
init_v1_plugin();
|
|
4731
5247
|
init_announcement_tool();
|
|
5248
|
+
init_task_tool();
|
|
4732
5249
|
init_resource_upload();
|
|
4733
5250
|
init_resource_read();
|
|
4734
5251
|
init_admin_client();
|
|
@@ -4752,9 +5269,9 @@ var init_plugin = __esm(() => {
|
|
|
4752
5269
|
});
|
|
4753
5270
|
({ notifyRoom, notifyTarget } = notifier);
|
|
4754
5271
|
restoreScans2 = new Map;
|
|
4755
|
-
READ_ONLY_ACTIONS = new Set(["list", "members", "poll", "join_status", "announcement_list", "announcement_read"]);
|
|
5272
|
+
READ_ONLY_ACTIONS = new Set(["list", "members", "poll", "join_status", "announcement_list", "announcement_read", "task_list"]);
|
|
4756
5273
|
roomArgs = z3.object({
|
|
4757
|
-
action: z3.enum(["create", "join", "join_status", "leave", "list", "send", "poll", "recall", "members", "upload_resource", "read_resource", "delete_resource", "announcement_list", "announcement_read", "announcement_write", "announcement_delete", "reminder_list", "reminder_create", "reminder_update", "reminder_delete"]),
|
|
5274
|
+
action: z3.enum(["create", "join", "join_status", "leave", "list", "send", "poll", "recall", "members", "upload_resource", "read_resource", "delete_resource", "announcement_list", "announcement_read", "announcement_write", "announcement_delete", "reminder_list", "reminder_create", "reminder_update", "reminder_delete", "task_list", "task_create", "task_update", "task_delete"]),
|
|
4758
5275
|
name: z3.string().max(64).optional().describe("For join: your own participant display name, NOT the room name (required). For create: the new room name."),
|
|
4759
5276
|
roomId: z3.string().optional().describe("Room UUID, not the room name. Required for resource actions and every room-scoped action."),
|
|
4760
5277
|
messageId: z3.string().optional().describe("For recall: the full message ID returned by send or poll; required for recall."),
|
|
@@ -4764,6 +5281,15 @@ var init_plugin = __esm(() => {
|
|
|
4764
5281
|
isQuestion: z3.boolean().optional().describe("For send: mark the message as a question awaiting an answer."),
|
|
4765
5282
|
announcementName: z3.string().optional().describe("Exact announcement name from announcement_list; distinct from participant or room name."),
|
|
4766
5283
|
content: z3.string().optional().describe("Announcement content, at most 5000 Unicode characters; required for announcement_write."),
|
|
5284
|
+
taskId: z3.string().optional().describe("Task UUID from task_list; required for task_update and task_delete."),
|
|
5285
|
+
title: z3.string().optional().describe("Task title, 1 to 200 characters; required for task_create."),
|
|
5286
|
+
description: z3.string().optional().describe("Task description, at most 5000 characters."),
|
|
5287
|
+
assignee: z3.string().optional().describe("Participant display name responsible for the task; empty leaves it unassigned."),
|
|
5288
|
+
status: z3.enum(["todo", "doing", "done"]).optional().describe("Task status; the assignee may change only this field."),
|
|
5289
|
+
dueDate: z3.string().optional().describe("Task due date as YYYY-MM-DD; empty clears it."),
|
|
5290
|
+
participants: z3.array(z3.string()).optional().describe("Task participants as room participant display names; empty clears them."),
|
|
5291
|
+
conclusion: z3.string().optional().describe("Task conclusion, at most 5000 characters; empty clears it."),
|
|
5292
|
+
steps: z3.array(z3.union([z3.string(), z3.object({ text: z3.string(), done: z3.boolean().optional() })])).optional().describe("Task checklist, at most 30 steps; each is text of 1 to 300 characters or {text, done}; empty clears them."),
|
|
4767
5293
|
reminderId: z3.string().optional().describe("Reminder UUID from reminder_list; required for reminder_update and reminder_delete."),
|
|
4768
5294
|
schedule: z3.discriminatedUnion("type", [z3.object({ type: z3.literal("once"), at: z3.string(), timezone: z3.string().refine((value) => {
|
|
4769
5295
|
try {
|
|
@@ -4788,7 +5314,7 @@ var init_plugin = __esm(() => {
|
|
|
4788
5314
|
}
|
|
4789
5315
|
});
|
|
4790
5316
|
room = tool({
|
|
4791
|
-
description: 'Chat room operations: create, join, leave and list rooms; send, poll and recall messages; list members and
|
|
5317
|
+
description: 'Chat room operations: create, join, leave and list rooms; send, poll and recall messages; list members, announcements and tasks; create, update and delete room tasks; manage reminders. Sent and polled messages carry full message IDs; recall takes roomId plus messageId and withdraws the message for everyone (agents their own, room admins any). Reminder schedules use the server timezone unless an IANA timezone is provided; once schedules require an ISO datetime. Upload files and media; upload_resource returns a [[resource:UUID]] marker, and the attachment renders only when that exact marker is included in a send message. Resource actions need both roomId (the room UUID) and resourceId (the UUID in the marker); the marker alone does not identify the room. read_resource saves files to a private temporary path and leaves them there until removed or system cleanup. delete_resource removes an uploaded file; servers allow human room administrators any resource and agents only their own uploads. Room joinPolicy "approval" makes join a pending request: you are not a member while pending, never claim otherwise, and use join_status to check whether a human administrator approved it.',
|
|
4792
5318
|
args: roomArgs.shape,
|
|
4793
5319
|
execute: roomExecute
|
|
4794
5320
|
});
|
|
@@ -4989,7 +5515,7 @@ var init_http_server = __esm(() => {
|
|
|
4989
5515
|
// src/runtime/watch.ts
|
|
4990
5516
|
import { Buffer as Buffer3 } from "node:buffer";
|
|
4991
5517
|
import { createHash as createHash6, randomBytes, timingSafeEqual } from "node:crypto";
|
|
4992
|
-
import { realpathSync } from "node:fs";
|
|
5518
|
+
import { existsSync as existsSync3, realpathSync } from "node:fs";
|
|
4993
5519
|
import { appendFile, chmod as chmod2, link, mkdir as mkdir2, readFile as readFile2, rename as rename2, unlink, writeFile as writeFile2 } from "node:fs/promises";
|
|
4994
5520
|
import { spawn } from "node:child_process";
|
|
4995
5521
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
@@ -5208,6 +5734,23 @@ function sameController(value, record, status) {
|
|
|
5208
5734
|
const body = value;
|
|
5209
5735
|
return body.status === status && body.pid === record.pid && body.instanceID === record.instanceID && body.nonce === record.nonce;
|
|
5210
5736
|
}
|
|
5737
|
+
function cliEntryPath() {
|
|
5738
|
+
const argv = process.argv[1];
|
|
5739
|
+
if (argv) {
|
|
5740
|
+
let resolved = path12.resolve(argv);
|
|
5741
|
+
try {
|
|
5742
|
+
resolved = realpathSync(resolved);
|
|
5743
|
+
} catch {}
|
|
5744
|
+
if (/^cli\.(?:ts|js)$/.test(path12.basename(resolved)))
|
|
5745
|
+
return resolved;
|
|
5746
|
+
}
|
|
5747
|
+
const candidates = [
|
|
5748
|
+
fileURLToPath3(new URL("../../dist/cli.js", import.meta.url)),
|
|
5749
|
+
fileURLToPath3(new URL("../../cli.ts", import.meta.url)),
|
|
5750
|
+
fileURLToPath3(new URL("../cli.js", import.meta.url))
|
|
5751
|
+
];
|
|
5752
|
+
return candidates.find((candidate) => existsSync3(candidate)) ?? candidates[0];
|
|
5753
|
+
}
|
|
5211
5754
|
async function watchStatus() {
|
|
5212
5755
|
const record = await readRecord();
|
|
5213
5756
|
if (!record) {
|
|
@@ -5244,9 +5787,9 @@ async function startWatcher(beforePublish) {
|
|
|
5244
5787
|
}
|
|
5245
5788
|
throw new Error("watcher state exists or is starting; no process was signaled");
|
|
5246
5789
|
}
|
|
5247
|
-
const cli =
|
|
5790
|
+
const cli = cliEntryPath();
|
|
5248
5791
|
let childError;
|
|
5249
|
-
const child = spawn(process.execPath, [
|
|
5792
|
+
const child = spawn(process.execPath, [cli, "watch", "run"], {
|
|
5250
5793
|
detached: true,
|
|
5251
5794
|
stdio: "ignore",
|
|
5252
5795
|
env: { ...process.env, CHAT_ROOM_WATCH_CONTROL_TOKEN: own.token, CHAT_ROOM_WATCH_START_NONCE: own.nonce, CHAT_ROOM_WATCH_INSTANCE_ID: own.instanceID }
|
|
@@ -5273,7 +5816,16 @@ async function startWatcher(beforePublish) {
|
|
|
5273
5816
|
}
|
|
5274
5817
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
5275
5818
|
}
|
|
5276
|
-
|
|
5819
|
+
child.kill("SIGTERM");
|
|
5820
|
+
if (child.exitCode === null) {
|
|
5821
|
+
await Promise.race([
|
|
5822
|
+
new Promise((resolve) => child.once("exit", resolve)),
|
|
5823
|
+
new Promise((resolve) => setTimeout(resolve, 1000))
|
|
5824
|
+
]);
|
|
5825
|
+
}
|
|
5826
|
+
await removeRecord(own.token, own.nonce);
|
|
5827
|
+
releaseWatcherClaim(profile(), own.instanceID);
|
|
5828
|
+
throw new Error("watcher did not become ready; its process was stopped");
|
|
5277
5829
|
}
|
|
5278
5830
|
async function stopWatcher() {
|
|
5279
5831
|
const record = await readRecord();
|
|
@@ -5661,7 +6213,7 @@ var init_message_recall_routes = __esm(() => {
|
|
|
5661
6213
|
|
|
5662
6214
|
// server/admin-state.ts
|
|
5663
6215
|
import { Buffer as Buffer4 } from "node:buffer";
|
|
5664
|
-
import { createHash as createHash7, randomBytes as randomBytes2, randomUUID as
|
|
6216
|
+
import { createHash as createHash7, randomBytes as randomBytes2, randomUUID as randomUUID10, timingSafeEqual as timingSafeEqual2 } from "node:crypto";
|
|
5665
6217
|
function matchesHash(value, stored) {
|
|
5666
6218
|
const left = Buffer4.from(hash2(value), "hex"), right = Buffer4.from(stored, "hex");
|
|
5667
6219
|
return right.length === 32 && timingSafeEqual2(left, right);
|
|
@@ -5851,7 +6403,7 @@ var init_admin_auth = __esm(() => {
|
|
|
5851
6403
|
});
|
|
5852
6404
|
|
|
5853
6405
|
// src/rooms/resources.ts
|
|
5854
|
-
import { randomUUID as
|
|
6406
|
+
import { randomUUID as randomUUID11 } from "node:crypto";
|
|
5855
6407
|
import { promises as fs4 } from "node:fs";
|
|
5856
6408
|
import path13 from "node:path";
|
|
5857
6409
|
function maxResourceBytes() {
|
|
@@ -5925,8 +6477,8 @@ async function uploadResource(roomID, filename, body, limitBytes, uploader, requ
|
|
|
5925
6477
|
}
|
|
5926
6478
|
const dir = roomDirectory(roomID);
|
|
5927
6479
|
await fs4.mkdir(dir, { recursive: true, mode: 448 });
|
|
5928
|
-
const id = requestedID ??
|
|
5929
|
-
const temp = path13.join(dir, `${id}.${
|
|
6480
|
+
const id = requestedID ?? randomUUID11();
|
|
6481
|
+
const temp = path13.join(dir, `${id}.${randomUUID11()}.tmp`);
|
|
5930
6482
|
const dest = resourcePath({ id, roomID });
|
|
5931
6483
|
let handle;
|
|
5932
6484
|
let linked = false;
|
|
@@ -6002,10 +6554,10 @@ function resourcePath(resource) {
|
|
|
6002
6554
|
throw new ResourceError(404, "resource not found");
|
|
6003
6555
|
return path13.join(roomDirectory(resource.roomID), resource.id);
|
|
6004
6556
|
}
|
|
6005
|
-
async function listRoomResources(roomID, limit = 500, offset = 0) {
|
|
6557
|
+
async function listRoomResources(roomID, limit = 500, offset = 0, beforeID) {
|
|
6006
6558
|
if (!uuid2.test(roomID))
|
|
6007
6559
|
throw new ResourceError(404, "room not found");
|
|
6008
|
-
return listResources(databasePath(), roomID, limit, offset);
|
|
6560
|
+
return listResources(databasePath(), roomID, limit, offset, beforeID);
|
|
6009
6561
|
}
|
|
6010
6562
|
async function findResource(roomID, id) {
|
|
6011
6563
|
if (!uuid2.test(id))
|
|
@@ -6399,25 +6951,88 @@ var init_announcement_routes = __esm(() => {
|
|
|
6399
6951
|
init_store();
|
|
6400
6952
|
});
|
|
6401
6953
|
|
|
6954
|
+
// server/task-routes.ts
|
|
6955
|
+
function sessionID(value) {
|
|
6956
|
+
return typeof value === "string" && value.length > 0 && value.length <= MAX_SESSION2 ? value : undefined;
|
|
6957
|
+
}
|
|
6958
|
+
async function taskRoutes(req, url) {
|
|
6959
|
+
const collection = url.pathname.match(/^\/rooms\/([^/]+)\/tasks$/);
|
|
6960
|
+
const item = url.pathname.match(/^\/rooms\/([^/]+)\/tasks\/([^/]+)$/);
|
|
6961
|
+
if (!collection && !item)
|
|
6962
|
+
return;
|
|
6963
|
+
let roomID, taskID;
|
|
6964
|
+
try {
|
|
6965
|
+
roomID = decodeURIComponent((collection ?? item)[1]);
|
|
6966
|
+
taskID = item ? decodeURIComponent(item[2]) : undefined;
|
|
6967
|
+
} catch {
|
|
6968
|
+
return json4({ error: "invalid path" }, 400);
|
|
6969
|
+
}
|
|
6970
|
+
if (collection) {
|
|
6971
|
+
if (req.method === "GET") {
|
|
6972
|
+
const session = sessionID(url.searchParams.get("sessionID"));
|
|
6973
|
+
if (!session)
|
|
6974
|
+
return json4({ error: "sessionID is required" }, 400);
|
|
6975
|
+
const result = await listTasks(roomID, session);
|
|
6976
|
+
return "error" in result ? json4({ error: result.error }, result.status) : json4({ tasks: result.tasks });
|
|
6977
|
+
}
|
|
6978
|
+
if (req.method !== "POST" && req.method !== "DELETE")
|
|
6979
|
+
return json4({ error: "method not allowed" }, 405);
|
|
6980
|
+
const body = await jsonObject(req);
|
|
6981
|
+
if (!body)
|
|
6982
|
+
return json4({ error: "JSON object body is required" }, 400);
|
|
6983
|
+
const session = sessionID(body.sessionID);
|
|
6984
|
+
if (!session)
|
|
6985
|
+
return json4({ error: "sessionID is required" }, 400);
|
|
6986
|
+
if (req.method === "DELETE") {
|
|
6987
|
+
const result = await clearCompletedTasks(roomID, session);
|
|
6988
|
+
return "error" in result ? json4({ error: result.error }, result.status) : json4({ ok: true, count: result.count });
|
|
6989
|
+
}
|
|
6990
|
+
const fields = { title: body.title, description: body.description, assignee: body.assignee, dueDate: body.dueDate, participants: body.participants, conclusion: body.conclusion, steps: body.steps };
|
|
6991
|
+
const result = await createTask(roomID, session, fields);
|
|
6992
|
+
return "error" in result ? json4({ error: result.error }, result.status) : json4({ task: result.task }, 201);
|
|
6993
|
+
}
|
|
6994
|
+
if (req.method !== "PATCH" && req.method !== "DELETE")
|
|
6995
|
+
return json4({ error: "method not allowed" }, 405);
|
|
6996
|
+
const body = await jsonObject(req);
|
|
6997
|
+
if (!body)
|
|
6998
|
+
return json4({ error: "JSON object body is required" }, 400);
|
|
6999
|
+
const session = sessionID(body.sessionID);
|
|
7000
|
+
if (!session)
|
|
7001
|
+
return json4({ error: "sessionID is required" }, 400);
|
|
7002
|
+
if (req.method === "DELETE") {
|
|
7003
|
+
const result = await deleteTask(roomID, taskID, session);
|
|
7004
|
+
return "error" in result ? json4({ error: result.error }, result.status) : json4({ ok: true });
|
|
7005
|
+
}
|
|
7006
|
+
const result = await updateTask(roomID, taskID, session, { title: body.title, description: body.description, assignee: body.assignee, status: body.status, dueDate: body.dueDate, participants: body.participants, conclusion: body.conclusion, steps: body.steps });
|
|
7007
|
+
return "error" in result ? json4({ error: result.error }, result.status) : json4({ task: result.task });
|
|
7008
|
+
}
|
|
7009
|
+
var json4 = (body, status = 200) => Response.json(body, { status }), MAX_SESSION2 = 128;
|
|
7010
|
+
var init_task_routes = __esm(() => {
|
|
7011
|
+
init_tasks();
|
|
7012
|
+
});
|
|
7013
|
+
|
|
6402
7014
|
// server/member-routes.ts
|
|
6403
7015
|
function object2(value) {
|
|
6404
7016
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6405
7017
|
}
|
|
6406
7018
|
async function memberRoutes(req, url) {
|
|
7019
|
+
const tasks = await taskRoutes(req, url);
|
|
7020
|
+
if (tasks)
|
|
7021
|
+
return tasks;
|
|
6407
7022
|
const announcements = await announcementRoutes(req, url);
|
|
6408
7023
|
if (announcements)
|
|
6409
7024
|
return announcements;
|
|
6410
7025
|
if (req.method === "POST" && url.pathname === "/read") {
|
|
6411
7026
|
const body = await jsonObject(req);
|
|
6412
7027
|
if (!body)
|
|
6413
|
-
return
|
|
7028
|
+
return json5({ error: "JSON object body is required" }, 400);
|
|
6414
7029
|
const ts = body.ts;
|
|
6415
7030
|
const roomId = String(body.roomId ?? "");
|
|
6416
7031
|
const sessionID = String(body.sessionID ?? "");
|
|
6417
7032
|
const messageIDs = body.messageIDs;
|
|
6418
7033
|
const hasReceipts = messageIDs !== undefined;
|
|
6419
7034
|
if (body.ts === undefined || body.ts === null || !roomId || !sessionID || typeof ts !== "number" || !Number.isSafeInteger(ts) || ts <= 0 || hasReceipts && (!Array.isArray(messageIDs) || !messageIDs.length || messageIDs.length > 500 || messageIDs.some((id) => typeof id !== "string" || !id || id.length > 128) || typeof body.membershipID !== "string" || !body.membershipID || body.membershipID.length > 128 || typeof body.evidence !== "string" || !["displayed", "tool", "context"].includes(body.evidence) || body.receiverOwnerID !== undefined && !isReceiverOwnerID(body.receiverOwnerID))) {
|
|
6420
|
-
return
|
|
7035
|
+
return json5({ error: "invalid read acknowledgement" }, 400);
|
|
6421
7036
|
}
|
|
6422
7037
|
if (hasReceipts) {
|
|
6423
7038
|
const result = await acknowledgeReadWithReceipts(roomId, sessionID, ts, messageIDs, body.evidence, {
|
|
@@ -6425,45 +7040,45 @@ async function memberRoutes(req, url) {
|
|
|
6425
7040
|
...typeof body.receiverOwnerID === "string" ? { receiverOwnerID: body.receiverOwnerID } : {}
|
|
6426
7041
|
});
|
|
6427
7042
|
if (result.status === "membership")
|
|
6428
|
-
return
|
|
7043
|
+
return json5({ error: "membership generation mismatch" }, 409);
|
|
6429
7044
|
if (result.status === "messageIDs")
|
|
6430
|
-
return
|
|
7045
|
+
return json5({ error: "message IDs do not belong to this room" }, 400);
|
|
6431
7046
|
if (result.status !== "ok")
|
|
6432
|
-
return
|
|
7047
|
+
return json5({ error: "read acknowledgement rejected" }, 400);
|
|
6433
7048
|
clearPendingAdmission(sessionID, roomId, result.readThroughTs ?? 0);
|
|
6434
7049
|
touchActive(sessionID);
|
|
6435
|
-
return
|
|
7050
|
+
return json5({ ok: true, acceptedIDs: result.acceptedIDs });
|
|
6436
7051
|
}
|
|
6437
7052
|
const actualTs = await acknowledgeRead2(roomId, sessionID, ts);
|
|
6438
7053
|
if (actualTs === null)
|
|
6439
|
-
return
|
|
7054
|
+
return json5({ error: "registry entry not found" }, 404);
|
|
6440
7055
|
clearPendingAdmission(sessionID, roomId, actualTs);
|
|
6441
7056
|
touchActive(sessionID);
|
|
6442
|
-
return
|
|
7057
|
+
return json5({ ok: true });
|
|
6443
7058
|
}
|
|
6444
7059
|
const receiptRoute = url.pathname.match(/^\/rooms\/([^/]+)\/receipts$/);
|
|
6445
7060
|
if (req.method === "POST" && receiptRoute) {
|
|
6446
7061
|
const body = await req.json();
|
|
6447
7062
|
if (!object2(body))
|
|
6448
|
-
return
|
|
7063
|
+
return json5({ error: "JSON object body is required" }, 400);
|
|
6449
7064
|
const { sessionID, membershipID, evidence } = body;
|
|
6450
7065
|
const ids = body.messageIDs;
|
|
6451
7066
|
const ownerID = body.receiverOwnerID;
|
|
6452
7067
|
if (typeof sessionID !== "string" || !sessionID || sessionID.length > 128 || typeof membershipID !== "string" || !membershipID || membershipID.length > 128 || !Array.isArray(ids) || !ids.length || ids.length > 500 || ids.some((id) => typeof id !== "string" || !id || id.length > 128) || typeof evidence !== "string" || !["displayed", "tool", "context"].includes(evidence) || ownerID !== undefined && !isReceiverOwnerID(ownerID))
|
|
6453
|
-
return
|
|
7068
|
+
return json5({ error: "invalid message receipt" }, 400);
|
|
6454
7069
|
const identity = { membershipID, ...typeof ownerID === "string" ? { receiverOwnerID: ownerID } : {} };
|
|
6455
7070
|
const result = await recordMessageReceipts(decodeURIComponent(receiptRoute[1]), sessionID, ids, evidence, identity);
|
|
6456
7071
|
if (result.status === "membership")
|
|
6457
|
-
return
|
|
7072
|
+
return json5({ error: "membership generation mismatch" }, 409);
|
|
6458
7073
|
if (result.status === "messageIDs")
|
|
6459
|
-
return
|
|
6460
|
-
return
|
|
7074
|
+
return json5({ error: "message IDs do not belong to this room" }, 400);
|
|
7075
|
+
return json5({ acceptedIDs: result.acceptedIDs });
|
|
6461
7076
|
}
|
|
6462
7077
|
const match = url.pathname.match(/^\/rooms\/([^/]+)\/(members|receipts)$/);
|
|
6463
7078
|
if (req.method === "GET" && match) {
|
|
6464
7079
|
const roomID = decodeURIComponent(match[1]);
|
|
6465
7080
|
if (match[2] === "members")
|
|
6466
|
-
return
|
|
7081
|
+
return json5(await readState2((svc, registry) => {
|
|
6467
7082
|
svc.getRoom(roomID);
|
|
6468
7083
|
return Object.entries(registry[roomID] ?? {}).map(([sessionID, entry]) => ({
|
|
6469
7084
|
sessionID,
|
|
@@ -6482,25 +7097,25 @@ async function memberRoutes(req, url) {
|
|
|
6482
7097
|
const filter = url.searchParams.get("messageIDs");
|
|
6483
7098
|
const ids = filter === null ? undefined : filter.split(",");
|
|
6484
7099
|
if (ids && (!ids.length || ids.length > 500 || ids.some((id) => !id || id.length > 128)))
|
|
6485
|
-
return
|
|
7100
|
+
return json5({ error: "invalid message IDs" }, 400);
|
|
6486
7101
|
const receipts = await readReceipts(roomID, ids);
|
|
6487
7102
|
if (!receipts)
|
|
6488
|
-
return
|
|
6489
|
-
return
|
|
7103
|
+
return json5({ error: "message IDs do not belong to this room" }, 400);
|
|
7104
|
+
return json5({ receipts: receipts.map((item) => ({ messageID: item.messageID, readers: item.readers.map((reader) => ({ ...reader, currentMember: Boolean(registry[reader.sessionID]) })) })), semantics: "per-message" });
|
|
6490
7105
|
}
|
|
6491
7106
|
if (req.method !== "POST" || url.pathname !== "/presence")
|
|
6492
7107
|
return;
|
|
6493
7108
|
const body = await req.json();
|
|
6494
7109
|
if (!object2(body) || !Array.isArray(body.sessions) || body.sessions.length > 200)
|
|
6495
|
-
return
|
|
7110
|
+
return json5({ error: "sessions must be an array of at most 200 reports" }, 400);
|
|
6496
7111
|
const ownerID = body.ownerID;
|
|
6497
7112
|
const sequence = body.sequence;
|
|
6498
7113
|
if (ownerID !== undefined && !isReceiverOwnerID(ownerID) || ownerID === undefined && sequence !== undefined || ownerID !== undefined && (typeof sequence !== "number" || !Number.isSafeInteger(sequence) || sequence <= 0))
|
|
6499
|
-
return
|
|
7114
|
+
return json5({ error: "invalid owner sequence" }, 400);
|
|
6500
7115
|
const reports = new Map;
|
|
6501
7116
|
for (const item of body.sessions) {
|
|
6502
7117
|
if (!object2(item) || typeof item.sessionID !== "string" || !item.sessionID || item.sessionID.length > 128 || typeof item.state !== "string" || !states.has(item.state) || item.receiverOwnerID !== undefined && (!isReceiverOwnerID(item.receiverOwnerID) || item.receiverOwnerID !== ownerID) || ownerID === undefined && item.receiverOwnerID !== undefined)
|
|
6503
|
-
return
|
|
7118
|
+
return json5({ error: "invalid presence report" }, 400);
|
|
6504
7119
|
reports.set(item.sessionID, {
|
|
6505
7120
|
sessionID: item.sessionID,
|
|
6506
7121
|
state: item.state,
|
|
@@ -6508,15 +7123,16 @@ async function memberRoutes(req, url) {
|
|
|
6508
7123
|
});
|
|
6509
7124
|
}
|
|
6510
7125
|
const result = await reportPresence([...reports.values()], ownerID, sequence);
|
|
6511
|
-
return
|
|
7126
|
+
return json5({ updatedSessionIDs: result.stale ? [] : result.updatedSessionIDs });
|
|
6512
7127
|
}
|
|
6513
|
-
var
|
|
7128
|
+
var json5 = (body, status = 200) => Response.json(body, { status }), states;
|
|
6514
7129
|
var init_member_routes = __esm(() => {
|
|
6515
7130
|
init_store();
|
|
6516
7131
|
init_receiver_owner();
|
|
6517
7132
|
init_queue();
|
|
6518
7133
|
init_wake();
|
|
6519
7134
|
init_announcement_routes();
|
|
7135
|
+
init_task_routes();
|
|
6520
7136
|
states = new Set(["working", "idle", "waiting", "unknown"]);
|
|
6521
7137
|
});
|
|
6522
7138
|
|
|
@@ -6546,63 +7162,64 @@ async function resourceRoutes(req, url) {
|
|
|
6546
7162
|
const sessionID = req.headers.get("x-session-id") ?? "";
|
|
6547
7163
|
const entry = await readState2((_svc, registry) => registry[roomID]?.[sessionID]);
|
|
6548
7164
|
if (!entry)
|
|
6549
|
-
return
|
|
7165
|
+
return json6({ error: "forbidden" }, 403);
|
|
6550
7166
|
const rawLimit = Number(url.searchParams.get("limit") ?? 500);
|
|
6551
7167
|
const rawOffset = Number(url.searchParams.get("offset") ?? 0);
|
|
6552
7168
|
const limit = Number.isSafeInteger(rawLimit) ? Math.min(1000, Math.max(1, rawLimit)) : 500;
|
|
6553
7169
|
const offset = Number.isSafeInteger(rawOffset) ? Math.max(0, rawOffset) : 0;
|
|
6554
|
-
const
|
|
6555
|
-
|
|
7170
|
+
const before = url.searchParams.get("before");
|
|
7171
|
+
const page = await listRoomResources(roomID, limit, offset, before && uuid3.test(before) ? before : undefined);
|
|
7172
|
+
return json6({ resources: page.items, total: page.total, limit, offset }, 200);
|
|
6556
7173
|
}
|
|
6557
7174
|
if (upload) {
|
|
6558
7175
|
const sessionID = req.headers.get("x-session-id") ?? "";
|
|
6559
7176
|
const entry = await readState2((_svc, registry) => registry[roomID]?.[sessionID]);
|
|
6560
7177
|
if (!entry)
|
|
6561
|
-
return
|
|
7178
|
+
return json6({ error: "forbidden" }, 403);
|
|
6562
7179
|
const encoded = req.headers.get("x-file-name");
|
|
6563
7180
|
if (!encoded)
|
|
6564
|
-
return
|
|
7181
|
+
return json6({ error: "invalid filename" }, 400);
|
|
6565
7182
|
let filename;
|
|
6566
7183
|
try {
|
|
6567
7184
|
filename = decodeURIComponent(encoded);
|
|
6568
7185
|
} catch {
|
|
6569
|
-
return
|
|
7186
|
+
return json6({ error: "invalid filename" }, 400);
|
|
6570
7187
|
}
|
|
6571
7188
|
if (!filename || filename.length > 255 || /[\\/\r\n\0]/.test(filename) || filename === "." || filename === "..")
|
|
6572
|
-
return
|
|
7189
|
+
return json6({ error: "invalid filename" }, 400);
|
|
6573
7190
|
const requestedID = req.headers.get("x-resource-id");
|
|
6574
7191
|
if (requestedID !== null && !uuid3.test(requestedID))
|
|
6575
|
-
return
|
|
7192
|
+
return json6({ error: "invalid resource id" }, 400);
|
|
6576
7193
|
const resource = await uploadResource(roomID, filename, req.body ?? new Blob([]).stream(), maxResourceBytes(), { sessionID, name: entry.name }, requestedID ?? undefined);
|
|
6577
|
-
return
|
|
7194
|
+
return json6({ resource }, 201);
|
|
6578
7195
|
}
|
|
6579
7196
|
const id = decodeURIComponent(item[2]);
|
|
6580
7197
|
if (!uuid3.test(id))
|
|
6581
|
-
return
|
|
7198
|
+
return json6({ error: "resource not found" }, 404);
|
|
6582
7199
|
const resource = await findResource(roomID, id);
|
|
6583
7200
|
if (!resource)
|
|
6584
|
-
return
|
|
7201
|
+
return json6({ error: "resource not found" }, 404);
|
|
6585
7202
|
if (req.method === "DELETE") {
|
|
6586
7203
|
const sessionID = req.headers.get("x-session-id") ?? "";
|
|
6587
7204
|
const context = await readState2((svc, registry) => ({ room: svc.getRoom(roomID), entry: registry[roomID]?.[sessionID] }));
|
|
6588
7205
|
if (!context.entry)
|
|
6589
|
-
return
|
|
7206
|
+
return json6({ error: "forbidden" }, 403);
|
|
6590
7207
|
const ownAgentUpload = !isUser(context.entry) && resource.uploaderSessionID === sessionID;
|
|
6591
7208
|
if (!isRoomAdmin(context.room, context.entry) && !ownAgentUpload)
|
|
6592
|
-
return
|
|
7209
|
+
return json6({ error: "forbidden" }, 403);
|
|
6593
7210
|
await deleteResource(roomID, id);
|
|
6594
|
-
return
|
|
7211
|
+
return json6({ ok: true });
|
|
6595
7212
|
}
|
|
6596
7213
|
if (!item[3])
|
|
6597
|
-
return
|
|
7214
|
+
return json6({ resource });
|
|
6598
7215
|
return await content2(req, resource);
|
|
6599
7216
|
} catch (error) {
|
|
6600
7217
|
if (error instanceof URIError)
|
|
6601
|
-
return
|
|
7218
|
+
return json6({ error: "invalid resource request" }, 400);
|
|
6602
7219
|
const status = typeof error === "object" && error !== null && "status" in error ? Number(error.status) : 500;
|
|
6603
7220
|
if (status >= 400 && status < 500)
|
|
6604
|
-
return
|
|
6605
|
-
return
|
|
7221
|
+
return json6({ error: status === 413 ? "file exceeds maximum size" : status === 404 ? "resource not found" : status === 403 ? "forbidden" : "invalid resource request" }, status);
|
|
7222
|
+
return json6({ error: "internal server error" }, 500);
|
|
6606
7223
|
}
|
|
6607
7224
|
}
|
|
6608
7225
|
async function content2(req, resource) {
|
|
@@ -6644,7 +7261,7 @@ async function content2(req, resource) {
|
|
|
6644
7261
|
headers.set("Content-Range", `bytes ${start}-${end}/${info.size}`);
|
|
6645
7262
|
return new Response(Readable3.toWeb(createReadStream2(path, { start, end })), { status, headers });
|
|
6646
7263
|
}
|
|
6647
|
-
var
|
|
7264
|
+
var json6 = (body, status = 200) => Response.json(body, { status }), uuid3, safeHeaders;
|
|
6648
7265
|
var init_resource_routes = __esm(() => {
|
|
6649
7266
|
init_resources();
|
|
6650
7267
|
init_store();
|
|
@@ -6662,8 +7279,8 @@ async function adminRoutes(request, url) {
|
|
|
6662
7279
|
return await rootRoutes(request, url);
|
|
6663
7280
|
} catch (error) {
|
|
6664
7281
|
if (error instanceof SyntaxError || error instanceof URIError)
|
|
6665
|
-
return
|
|
6666
|
-
return
|
|
7282
|
+
return json7({ error: "invalid request" }, 400);
|
|
7283
|
+
return json7({ error: "admin request failed" }, 500);
|
|
6667
7284
|
}
|
|
6668
7285
|
}
|
|
6669
7286
|
async function rootRoutes(request, url) {
|
|
@@ -6673,13 +7290,13 @@ async function rootRoutes(request, url) {
|
|
|
6673
7290
|
return claimBinding(request, decodeURIComponent(claim[1]));
|
|
6674
7291
|
const room = path.match(/^\/admin\/rooms\/([^/]+)(?:\/(overview|history))?$/);
|
|
6675
7292
|
if (!room)
|
|
6676
|
-
return
|
|
7293
|
+
return json7({ error: "not found" }, 404);
|
|
6677
7294
|
const roomID = decodeURIComponent(room[1]);
|
|
6678
7295
|
if (request.method === "GET" && room[2] === "overview")
|
|
6679
7296
|
return overview(request, roomID);
|
|
6680
7297
|
if (request.method === "GET" && room[2] === "history")
|
|
6681
7298
|
return history(request, url, roomID);
|
|
6682
|
-
return
|
|
7299
|
+
return json7({ error: "method not allowed" }, 405);
|
|
6683
7300
|
}
|
|
6684
7301
|
function bounded(value, max) {
|
|
6685
7302
|
return typeof value === "string" && value.trim().length > 0 && value.length <= max;
|
|
@@ -6687,7 +7304,7 @@ function bounded(value, max) {
|
|
|
6687
7304
|
async function claimBinding(request, roomID) {
|
|
6688
7305
|
const body = await request.json();
|
|
6689
7306
|
if (!object3(body) || !bounded(body.sessionID, 128) || typeof body.receiverOwnerID !== "string" || body.receiverOwnerID.length > 128 || !bounded(body.enrollmentKey, 256))
|
|
6690
|
-
return
|
|
7307
|
+
return json7({ error: "invalid claim" }, 400);
|
|
6691
7308
|
const { sessionID, receiverOwnerID, enrollmentKey } = body;
|
|
6692
7309
|
const result = await tx((db) => {
|
|
6693
7310
|
const b = binding(db, roomID);
|
|
@@ -6697,7 +7314,7 @@ async function claimBinding(request, roomID) {
|
|
|
6697
7314
|
const saved = run(db, "UPDATE admin_rooms SET capability_hash=?,enrollment_hash='',enrollment_expires=0 WHERE room_id=? AND generation=? AND enrollment_hash=? AND enrollment_expires>?", digest(capability), roomID, b.generation, b.enrollment_hash, Date.now());
|
|
6698
7315
|
return saved.changes === 1 ? { capability, adminRoom: publicRoom({ ...b, capability_hash: digest(capability) }) } : null;
|
|
6699
7316
|
});
|
|
6700
|
-
return result ?
|
|
7317
|
+
return result ? json7(result) : json7({ error: "claim rejected" }, 409);
|
|
6701
7318
|
}
|
|
6702
7319
|
async function overview(request, roomID) {
|
|
6703
7320
|
const result = await tx((db) => {
|
|
@@ -6713,16 +7330,16 @@ async function overview(request, roomID) {
|
|
|
6713
7330
|
const rooms = many(db, "SELECT id,name,created_at AS createdAt FROM rooms WHERE id=?", roomID).map((room) => ({ ...room, members: many(db, "SELECT g.session_id AS sessionID,g.name,g.protocol,g.receiver_owner_id AS receiverOwnerID,g.work_state AS workState,g.last_seen_at AS lastSeenAt FROM registry g WHERE g.room_id=? ORDER BY g.name", room.id) }));
|
|
6714
7331
|
return { rooms };
|
|
6715
7332
|
});
|
|
6716
|
-
return "status" in result ?
|
|
7333
|
+
return "status" in result ? json7({ error: result.status === 404 ? "admin room not found" : result.status === 401 ? "unauthorized" : "binding is no longer active" }, result.status) : json7(result);
|
|
6717
7334
|
}
|
|
6718
7335
|
async function history(request, url, roomID) {
|
|
6719
7336
|
const targetRoomID = url.searchParams.get("targetRoomId") ?? "";
|
|
6720
7337
|
if (!bounded(targetRoomID, 128))
|
|
6721
|
-
return
|
|
7338
|
+
return json7({ error: "invalid history request" }, 400);
|
|
6722
7339
|
const rawLimit = url.searchParams.get("limit");
|
|
6723
7340
|
const limit = rawLimit === null ? 20 : Number(rawLimit);
|
|
6724
7341
|
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 50)
|
|
6725
|
-
return
|
|
7342
|
+
return json7({ error: "invalid history request" }, 400);
|
|
6726
7343
|
const allowed = await tx((db) => {
|
|
6727
7344
|
const b = binding(db, roomID);
|
|
6728
7345
|
if (!b)
|
|
@@ -6736,12 +7353,12 @@ async function history(request, url, roomID) {
|
|
|
6736
7353
|
return 200;
|
|
6737
7354
|
});
|
|
6738
7355
|
if (allowed !== 200)
|
|
6739
|
-
return
|
|
7356
|
+
return json7({ error: allowed === 401 ? "unauthorized" : allowed === 404 ? "room not found" : "binding is no longer active" }, allowed);
|
|
6740
7357
|
if (targetRoomID !== roomID)
|
|
6741
|
-
return
|
|
6742
|
-
return
|
|
7358
|
+
return json7({ error: "room is outside this administrator's scope" }, 403);
|
|
7359
|
+
return json7(await readHistoryPage(databasePath(), roomID, undefined, limit));
|
|
6743
7360
|
}
|
|
6744
|
-
var
|
|
7361
|
+
var json7 = (body, status = 200) => Response.json(body, { status, headers: { "Cache-Control": "no-store" } }), object3 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
6745
7362
|
var init_admin_routes = __esm(async () => {
|
|
6746
7363
|
init_store();
|
|
6747
7364
|
init_sqlite_state();
|
|
@@ -6751,7 +7368,7 @@ var init_admin_routes = __esm(async () => {
|
|
|
6751
7368
|
});
|
|
6752
7369
|
|
|
6753
7370
|
// server/room-join.ts
|
|
6754
|
-
import { randomUUID as
|
|
7371
|
+
import { randomUUID as randomUUID12 } from "node:crypto";
|
|
6755
7372
|
function joinRoomMember(svc, registry, roomId, member) {
|
|
6756
7373
|
const currentRoom = svc.getRoom(roomId);
|
|
6757
7374
|
const participantId = currentRoom.kind === "direct" ? member.sessionID : member.participantId;
|
|
@@ -6777,7 +7394,7 @@ function joinRoomMember(svc, registry, roomId, member) {
|
|
|
6777
7394
|
...member.protocol === "v2" ? { protocol: "v2" } : {},
|
|
6778
7395
|
...member.protocol === "v2" && member.receiverOwnerID ? { receiverOwnerID: member.receiverOwnerID } : {},
|
|
6779
7396
|
name: member.name,
|
|
6780
|
-
membershipID: prevEntry?.membershipID ??
|
|
7397
|
+
membershipID: prevEntry?.membershipID ?? randomUUID12(),
|
|
6781
7398
|
directory: member.directory || undefined,
|
|
6782
7399
|
host: member.host ?? "",
|
|
6783
7400
|
lastQueuedTs: regRoom[member.sessionID]?.lastQueuedTs,
|
|
@@ -6822,37 +7439,37 @@ async function joinRequestRoutes(req, url) {
|
|
|
6822
7439
|
const roomID = decodeURIComponent(status[1]);
|
|
6823
7440
|
const sessionID = url.searchParams.get("sessionID") ?? "";
|
|
6824
7441
|
if (!bounded2(sessionID))
|
|
6825
|
-
return
|
|
7442
|
+
return json8({ error: "sessionID is required" }, 400);
|
|
6826
7443
|
const joined = await readState2((svc, registry) => {
|
|
6827
7444
|
svc.getRoom(roomID);
|
|
6828
7445
|
return Boolean(registry[roomID]?.[sessionID]);
|
|
6829
7446
|
});
|
|
6830
7447
|
if (joined)
|
|
6831
|
-
return
|
|
6832
|
-
return
|
|
7448
|
+
return json8({ status: "joined" });
|
|
7449
|
+
return json8({ status: await readJoinRequest2(roomID, sessionID) ? "pending" : "none" });
|
|
6833
7450
|
}
|
|
6834
7451
|
if (list && req.method === "DELETE") {
|
|
6835
7452
|
const roomID = decodeURIComponent(list[1]);
|
|
6836
7453
|
const sessionID = url.searchParams.get("sessionID") ?? "";
|
|
6837
7454
|
if (!bounded2(sessionID))
|
|
6838
|
-
return
|
|
7455
|
+
return json8({ error: "sessionID is required" }, 400);
|
|
6839
7456
|
const removed = await writeSqliteStateWithDatabase(databasePath(), (svc, _registry, db) => {
|
|
6840
7457
|
svc.getRoom(roomID);
|
|
6841
7458
|
return removeJoinRequest(db, roomID, sessionID);
|
|
6842
7459
|
});
|
|
6843
|
-
return removed ?
|
|
7460
|
+
return removed ? json8({ ok: true }) : json8({ error: "join request not found" }, 404);
|
|
6844
7461
|
}
|
|
6845
7462
|
if (list && req.method === "GET") {
|
|
6846
7463
|
const roomID = decodeURIComponent(list[1]);
|
|
6847
7464
|
const actor = url.searchParams.get("sessionID") ?? "";
|
|
6848
7465
|
if (!bounded2(actor))
|
|
6849
|
-
return
|
|
7466
|
+
return json8({ error: "sessionID is required" }, 400);
|
|
6850
7467
|
const human = await humanReviewer(roomID, actor);
|
|
6851
7468
|
const agent = !human && await agentReviewer(req, roomID, actor);
|
|
6852
7469
|
if (!human && !agent)
|
|
6853
|
-
return
|
|
7470
|
+
return json8({ error: "only room administrators can review join requests" }, 403);
|
|
6854
7471
|
const requests = await listJoinRequests2(roomID, agent);
|
|
6855
|
-
return
|
|
7472
|
+
return json8({ requests: requests.map(({ sessionID, participantId, name, isAgent, createdAt }) => ({ sessionID, participantId, name, isAgent, createdAt })) });
|
|
6856
7473
|
}
|
|
6857
7474
|
if (action && req.method === "POST") {
|
|
6858
7475
|
const roomID = decodeURIComponent(action[1]);
|
|
@@ -6860,10 +7477,10 @@ async function joinRequestRoutes(req, url) {
|
|
|
6860
7477
|
const decision = action[3];
|
|
6861
7478
|
const body = await req.json();
|
|
6862
7479
|
if (!body || typeof body !== "object" || Array.isArray(body))
|
|
6863
|
-
return
|
|
7480
|
+
return json8({ error: "JSON object body is required" }, 400);
|
|
6864
7481
|
const actor = typeof body.sessionID === "string" ? body.sessionID : "";
|
|
6865
7482
|
if (!bounded2(actor))
|
|
6866
|
-
return
|
|
7483
|
+
return json8({ error: "sessionID is required" }, 400);
|
|
6867
7484
|
const result = await writeSqliteStateWithDatabase(databasePath(), (svc, registry, db) => {
|
|
6868
7485
|
const room = svc.getRoom(roomID);
|
|
6869
7486
|
const actorEntry = registry[roomID]?.[actor];
|
|
@@ -6902,11 +7519,11 @@ async function joinRequestRoutes(req, url) {
|
|
|
6902
7519
|
});
|
|
6903
7520
|
return { ok: true };
|
|
6904
7521
|
});
|
|
6905
|
-
return "ok" in result ?
|
|
7522
|
+
return "ok" in result ? json8({ ok: true }) : json8({ error: result.error }, result.status);
|
|
6906
7523
|
}
|
|
6907
|
-
return
|
|
7524
|
+
return json8({ error: "method not allowed" }, 405);
|
|
6908
7525
|
}
|
|
6909
|
-
var
|
|
7526
|
+
var json8 = (body, status = 200) => Response.json(body, { status, headers: { "Cache-Control": "no-store" } });
|
|
6910
7527
|
var init_join_requests = __esm(() => {
|
|
6911
7528
|
init_store();
|
|
6912
7529
|
init_sqlite_state();
|
|
@@ -6918,7 +7535,7 @@ var init_join_requests = __esm(() => {
|
|
|
6918
7535
|
|
|
6919
7536
|
// server/room-reminders.ts
|
|
6920
7537
|
import { Cron } from "croner";
|
|
6921
|
-
import { randomUUID as
|
|
7538
|
+
import { randomUUID as randomUUID13 } from "node:crypto";
|
|
6922
7539
|
function zone() {
|
|
6923
7540
|
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
6924
7541
|
}
|
|
@@ -7055,16 +7672,16 @@ async function roomReminderRoutes(req, url) {
|
|
|
7055
7672
|
return null;
|
|
7056
7673
|
return db.query("SELECT * FROM room_reminders WHERE room_id=? ORDER BY created_at,id").all(room);
|
|
7057
7674
|
});
|
|
7058
|
-
return items ?
|
|
7675
|
+
return items ? json9({ reminders: items.map(output) }) : json9({ error: "room not found or session is not a current member" }, 404);
|
|
7059
7676
|
}
|
|
7060
7677
|
if (req.method !== "POST" && req.method !== "PATCH" && req.method !== "DELETE")
|
|
7061
|
-
return
|
|
7678
|
+
return json9({ error: "method not allowed" }, 405);
|
|
7062
7679
|
const body = await req.json();
|
|
7063
7680
|
if (!body || typeof body !== "object" || Array.isArray(body))
|
|
7064
|
-
return
|
|
7681
|
+
return json9({ error: "JSON object body is required" }, 400);
|
|
7065
7682
|
const input = body, session = input.sessionID;
|
|
7066
7683
|
if (typeof session !== "string" || !session || session.length > 128)
|
|
7067
|
-
return
|
|
7684
|
+
return json9({ error: "sessionID is required" }, 400);
|
|
7068
7685
|
const result = await withStateTransaction(dbFile(), (db) => {
|
|
7069
7686
|
const who = member(db, room, session);
|
|
7070
7687
|
if (!who)
|
|
@@ -7074,7 +7691,7 @@ async function roomReminderRoutes(req, url) {
|
|
|
7074
7691
|
if (typeof text !== "string" || !text.trim() || text.length > 2000 || input.schedule === undefined)
|
|
7075
7692
|
return { error: "text (max 2000) and valid schedule are required", status: 400 };
|
|
7076
7693
|
try {
|
|
7077
|
-
const schedule = normalizeSchedule(input.schedule), at = next(schedule, Date.now()), created = Date.now(), rid =
|
|
7694
|
+
const schedule = normalizeSchedule(input.schedule), at = next(schedule, Date.now()), created = Date.now(), rid = randomUUID13();
|
|
7078
7695
|
const roomName = db.query("SELECT name FROM rooms WHERE id=?").get(room)?.name;
|
|
7079
7696
|
if (roomName === undefined)
|
|
7080
7697
|
return { error: "room not found", status: 404 };
|
|
@@ -7116,7 +7733,7 @@ async function roomReminderRoutes(req, url) {
|
|
|
7116
7733
|
}
|
|
7117
7734
|
});
|
|
7118
7735
|
const { status, ...bodyOut } = result;
|
|
7119
|
-
return
|
|
7736
|
+
return json9(bodyOut, status);
|
|
7120
7737
|
}
|
|
7121
7738
|
async function tickRoomReminders(now = Date.now(), wake) {
|
|
7122
7739
|
await initializeReminderSchema(dbFile());
|
|
@@ -7138,7 +7755,7 @@ async function tickRoomReminders(now = Date.now(), wake) {
|
|
|
7138
7755
|
})();
|
|
7139
7756
|
const tail = db.query("SELECT created_at FROM messages WHERE room_id=? ORDER BY seq DESC LIMIT 1").get(r.room_id);
|
|
7140
7757
|
const sentAt = Math.max(now, (tail?.created_at ?? 0) + 1), text = template(r.text, sentAt, r.initiator, room.name, r.timezone ?? undefined);
|
|
7141
|
-
const message = { id: `reminder:${
|
|
7758
|
+
const message = { id: `reminder:${randomUUID13()}`, roomId: r.room_id, senderId: "system", text, createdAt: sentAt };
|
|
7142
7759
|
db.query("INSERT INTO messages(id,room_id,sender_id,sender_session_id,text,created_at,is_question) VALUES(?,?, 'system',NULL,?,?,0)").run(message.id, r.room_id, text, sentAt);
|
|
7143
7760
|
delivered = { roomName: room.name, message };
|
|
7144
7761
|
if (upcoming === undefined)
|
|
@@ -7172,17 +7789,17 @@ function startRoomReminderScheduler(wake) {
|
|
|
7172
7789
|
}, 1000);
|
|
7173
7790
|
timer2.unref?.();
|
|
7174
7791
|
}
|
|
7175
|
-
var
|
|
7792
|
+
var json9 = (body, status = 200) => Response.json(body, { status }), dbFile = () => databasePath(), timer2;
|
|
7176
7793
|
var init_room_reminders = __esm(() => {
|
|
7177
7794
|
init_store();
|
|
7178
7795
|
init_sqlite_state();
|
|
7179
7796
|
});
|
|
7180
7797
|
|
|
7181
7798
|
// server/chat-server.ts
|
|
7182
|
-
import { existsSync as
|
|
7799
|
+
import { existsSync as existsSync4, promises as fs5 } from "node:fs";
|
|
7183
7800
|
import path14 from "node:path";
|
|
7184
7801
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
7185
|
-
import { randomUUID as
|
|
7802
|
+
import { randomUUID as randomUUID14 } from "node:crypto";
|
|
7186
7803
|
function parsePort(value) {
|
|
7187
7804
|
const port = Number(value);
|
|
7188
7805
|
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
@@ -7205,7 +7822,7 @@ async function handle(req) {
|
|
|
7205
7822
|
if (req.method === "GET" && p === "/chat") {
|
|
7206
7823
|
const html = await fs5.readFile(path14.join(here, "chat.html"), "utf8").catch(() => null);
|
|
7207
7824
|
if (html === null) {
|
|
7208
|
-
return
|
|
7825
|
+
return json10({ error: "chat page not found" }, 404);
|
|
7209
7826
|
}
|
|
7210
7827
|
const version = await chatVersionTag();
|
|
7211
7828
|
return new Response(html.replaceAll("{{version}}", version), {
|
|
@@ -7218,7 +7835,7 @@ async function handle(req) {
|
|
|
7218
7835
|
if (req.method === "GET" && p === "/manifest.webmanifest") {
|
|
7219
7836
|
const body = await fs5.readFile(path14.join(here, "manifest.webmanifest"), "utf8").catch(() => null);
|
|
7220
7837
|
if (body === null)
|
|
7221
|
-
return
|
|
7838
|
+
return json10({ error: "manifest not found" }, 404);
|
|
7222
7839
|
return new Response(body, {
|
|
7223
7840
|
headers: { "Content-Type": "application/manifest+json; charset=utf-8", "Cache-Control": "no-store" }
|
|
7224
7841
|
});
|
|
@@ -7226,7 +7843,7 @@ async function handle(req) {
|
|
|
7226
7843
|
if (req.method === "GET" && p === "/sw.js") {
|
|
7227
7844
|
const body = await fs5.readFile(path14.join(here, "sw.js"), "utf8").catch(() => null);
|
|
7228
7845
|
if (body === null)
|
|
7229
|
-
return
|
|
7846
|
+
return json10({ error: "service worker not found" }, 404);
|
|
7230
7847
|
const version = await chatVersionTag() || "dev";
|
|
7231
7848
|
return new Response(body.replaceAll("{{version}}", version), {
|
|
7232
7849
|
headers: {
|
|
@@ -7241,23 +7858,23 @@ async function handle(req) {
|
|
|
7241
7858
|
try {
|
|
7242
7859
|
relative = decodeURIComponent(p.slice("/assets/".length));
|
|
7243
7860
|
} catch {
|
|
7244
|
-
return
|
|
7861
|
+
return json10({ error: "invalid asset path" }, 400);
|
|
7245
7862
|
}
|
|
7246
7863
|
const root = path14.resolve(here, "assets");
|
|
7247
7864
|
const file = path14.resolve(root, relative);
|
|
7248
7865
|
if (!relative || !file.startsWith(`${root}${path14.sep}`) || !/\.(?:css|js|mjs|svg|png|jpg|woff2?)$/i.test(file))
|
|
7249
|
-
return
|
|
7866
|
+
return json10({ error: "not found" }, 404);
|
|
7250
7867
|
const data = await fs5.readFile(file).catch(() => null);
|
|
7251
7868
|
if (!data)
|
|
7252
|
-
return
|
|
7869
|
+
return json10({ error: "not found" }, 404);
|
|
7253
7870
|
const type = file.endsWith(".css") ? "text/css" : file.endsWith(".svg") ? "image/svg+xml" : /\.(?:js|mjs)$/.test(file) ? "text/javascript" : file.endsWith(".png") ? "image/png" : file.endsWith(".jpg") ? "image/jpeg" : "font/woff2";
|
|
7254
7871
|
return new Response(data, { headers: { "Content-Type": type, "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff" } });
|
|
7255
7872
|
}
|
|
7256
7873
|
if (["POST", "PUT", "PATCH", "DELETE"].includes(req.method) && !req.headers.get("content-type")?.includes("application/json") && !(/^\/rooms\/[^/]+\/resources$/.test(p) && req.method === "POST")) {
|
|
7257
|
-
return
|
|
7874
|
+
return json10({ error: "content-type must be application/json" }, 415);
|
|
7258
7875
|
}
|
|
7259
7876
|
if (token && req.headers.get("authorization") !== `Bearer ${token}`) {
|
|
7260
|
-
return
|
|
7877
|
+
return json10({ error: "unauthorized" }, 401);
|
|
7261
7878
|
}
|
|
7262
7879
|
try {
|
|
7263
7880
|
const reminders = await roomReminderRoutes(req, url);
|
|
@@ -7281,16 +7898,16 @@ async function handle(req) {
|
|
|
7281
7898
|
name: r.name,
|
|
7282
7899
|
latestMsgTs: r.messages.at(-1)?.createdAt ?? 0
|
|
7283
7900
|
})));
|
|
7284
|
-
return
|
|
7901
|
+
return json10(rooms);
|
|
7285
7902
|
}
|
|
7286
7903
|
if (req.method === "GET" && p === "/receiver/memberships") {
|
|
7287
7904
|
const ownerID = url.searchParams.get("ownerID");
|
|
7288
7905
|
if (!isReceiverOwnerID(ownerID))
|
|
7289
|
-
return
|
|
7906
|
+
return json10({ error: "invalid ownerID" }, 400);
|
|
7290
7907
|
const sessionIDs = await readState2((_svc, registry) => {
|
|
7291
7908
|
return [...new Set(Object.values(registry).flatMap((entries) => Object.entries(entries).filter(([, entry]) => entry.protocol === "v2" && entry.receiverOwnerID === ownerID).map(([id]) => id)))];
|
|
7292
7909
|
});
|
|
7293
|
-
return
|
|
7910
|
+
return json10({ sessionIDs });
|
|
7294
7911
|
}
|
|
7295
7912
|
if (req.method === "GET" && p === "/rooms") {
|
|
7296
7913
|
const caller = url.searchParams.get("sessionID");
|
|
@@ -7299,7 +7916,7 @@ async function handle(req) {
|
|
|
7299
7916
|
for (const { room, entry } of rows) {
|
|
7300
7917
|
rooms.push({ ...await roomPayload(room), joined: Boolean(entry), ...entry?.lastReadTs ? { lastReadTs: entry.lastReadTs } : {} });
|
|
7301
7918
|
}
|
|
7302
|
-
return
|
|
7919
|
+
return json10(rooms);
|
|
7303
7920
|
}
|
|
7304
7921
|
const members = await memberRoutes(req, url);
|
|
7305
7922
|
if (members)
|
|
@@ -7313,23 +7930,23 @@ async function handle(req) {
|
|
|
7313
7930
|
if (req.method === "POST" && p === "/rooms") {
|
|
7314
7931
|
const body = await jsonObject(req);
|
|
7315
7932
|
if (!body)
|
|
7316
|
-
return
|
|
7933
|
+
return json10({ error: "JSON object body is required" }, 400);
|
|
7317
7934
|
if (body.protocol !== undefined && body.protocol !== "v2" || body.receiverOwnerID !== undefined && !isReceiverOwnerID(body.receiverOwnerID)) {
|
|
7318
|
-
return
|
|
7935
|
+
return json10({ error: "invalid receiver ownership" }, 400);
|
|
7319
7936
|
}
|
|
7320
7937
|
const name = body.name?.trim();
|
|
7321
7938
|
if (!name) {
|
|
7322
|
-
return
|
|
7939
|
+
return json10({ error: "name is required" }, 400);
|
|
7323
7940
|
}
|
|
7324
7941
|
if (name.length > 64) {
|
|
7325
|
-
return
|
|
7942
|
+
return json10({ error: "name too long (max 64)" }, 400);
|
|
7326
7943
|
}
|
|
7327
7944
|
const owner = (body.ownerId ?? "").trim() || "访客";
|
|
7328
7945
|
if (owner.length > 64) {
|
|
7329
|
-
return
|
|
7946
|
+
return json10({ error: "ownerId too long (max 64)" }, 400);
|
|
7330
7947
|
}
|
|
7331
7948
|
if (body.joinPolicy !== undefined && body.joinPolicy !== "open" && body.joinPolicy !== "approval") {
|
|
7332
|
-
return
|
|
7949
|
+
return json10({ error: "joinPolicy must be open or approval" }, 400);
|
|
7333
7950
|
}
|
|
7334
7951
|
const joinPolicy = body.joinPolicy === "approval" ? "approval" : body.joinPolicy === "open" ? "open" : undefined;
|
|
7335
7952
|
const room = await mutate2((svc, reg) => {
|
|
@@ -7339,7 +7956,7 @@ async function handle(req) {
|
|
|
7339
7956
|
regRoom[body.sessionID] = {
|
|
7340
7957
|
serverUrl: "",
|
|
7341
7958
|
apiPrefix: "/api",
|
|
7342
|
-
membershipID:
|
|
7959
|
+
membershipID: randomUUID14(),
|
|
7343
7960
|
...body.protocol === "v2" ? { protocol: "v2" } : {},
|
|
7344
7961
|
...body.protocol === "v2" && isReceiverOwnerID(body.receiverOwnerID) ? { receiverOwnerID: body.receiverOwnerID } : {},
|
|
7345
7962
|
name: owner,
|
|
@@ -7352,7 +7969,7 @@ async function handle(req) {
|
|
|
7352
7969
|
}
|
|
7353
7970
|
return created;
|
|
7354
7971
|
});
|
|
7355
|
-
return
|
|
7972
|
+
return json10(await roomPayload(room), 201);
|
|
7356
7973
|
}
|
|
7357
7974
|
if (req.method === "GET" && p === "/inbox") {
|
|
7358
7975
|
const sessionID = url.searchParams.get("sessionID") ?? "";
|
|
@@ -7361,11 +7978,11 @@ async function handle(req) {
|
|
|
7361
7978
|
const afterTs = afterValue === null ? undefined : Number(afterValue);
|
|
7362
7979
|
const recallVersionValue = url.searchParams.get("recallVersion");
|
|
7363
7980
|
if (url.searchParams.has("recallVersion") && (recallVersionValue === "" || !/^\d+$/.test(recallVersionValue ?? "") || !Number.isSafeInteger(Number(recallVersionValue)))) {
|
|
7364
|
-
return
|
|
7981
|
+
return json10({ error: "recallVersion must be a non-negative safe integer" }, 400);
|
|
7365
7982
|
}
|
|
7366
7983
|
const clientRecallVersion = recallVersionValue === null ? undefined : Number(recallVersionValue);
|
|
7367
7984
|
if (url.searchParams.has("afterTs") && (afterValue === "" || !/^\d+$/.test(afterValue ?? "") || !Number.isSafeInteger(afterTs) || afterTs < 0 || !roomFilter || url.searchParams.get("excludeSelf") !== "0")) {
|
|
7368
|
-
return
|
|
7985
|
+
return json10({ error: "afterTs requires a roomId and excludeSelf=0, with a non-negative safe integer value" }, 400);
|
|
7369
7986
|
}
|
|
7370
7987
|
const excludeSelf = url.searchParams.get("excludeSelf") === "1";
|
|
7371
7988
|
const timeout = Math.min(Math.max(Number(url.searchParams.get("timeout") ?? 0) || 0, 0), 30000);
|
|
@@ -7376,59 +7993,59 @@ async function handle(req) {
|
|
|
7376
7993
|
await sleep(Math.max(1, Math.min(500, deadline - Date.now())));
|
|
7377
7994
|
result = await readInbox(sessionID, roomFilter, excludeSelf, afterTs);
|
|
7378
7995
|
}
|
|
7379
|
-
return
|
|
7996
|
+
return json10(result);
|
|
7380
7997
|
}
|
|
7381
7998
|
if (req.method === "POST" && p === "/queued") {
|
|
7382
7999
|
const body = await jsonObject(req);
|
|
7383
8000
|
if (!body)
|
|
7384
|
-
return
|
|
8001
|
+
return json10({ error: "JSON object body is required" }, 400);
|
|
7385
8002
|
const ts = Number(body.ts);
|
|
7386
8003
|
const roomId = String(body.roomId ?? "");
|
|
7387
8004
|
const sessionID = String(body.sessionID ?? "");
|
|
7388
8005
|
if (body.ts === undefined || body.ts === null || !roomId || !sessionID || !Number.isFinite(ts)) {
|
|
7389
|
-
return
|
|
8006
|
+
return json10({ error: "roomId/sessionID/finite ts are required" }, 400);
|
|
7390
8007
|
}
|
|
7391
8008
|
const updated = await acknowledgeQueued2(roomId, sessionID, ts);
|
|
7392
8009
|
if (updated === null) {
|
|
7393
|
-
return
|
|
8010
|
+
return json10({ error: "registry entry not found" }, 404);
|
|
7394
8011
|
}
|
|
7395
8012
|
clearPendingAdmission(sessionID, roomId, updated);
|
|
7396
8013
|
touchActive(sessionID);
|
|
7397
|
-
return
|
|
8014
|
+
return json10({ ok: true });
|
|
7398
8015
|
}
|
|
7399
8016
|
if (req.method === "POST" && p === "/active") {
|
|
7400
8017
|
const body = await jsonObject(req);
|
|
7401
8018
|
if (!body)
|
|
7402
|
-
return
|
|
8019
|
+
return json10({ error: "JSON object body is required" }, 400);
|
|
7403
8020
|
touchActive(String(body.sessionID ?? ""));
|
|
7404
|
-
return
|
|
8021
|
+
return json10({ ok: true });
|
|
7405
8022
|
}
|
|
7406
8023
|
if (req.method === "POST" && p === "/wake-claim") {
|
|
7407
8024
|
const body = await jsonObject(req);
|
|
7408
8025
|
if (!body)
|
|
7409
|
-
return
|
|
8026
|
+
return json10({ error: "JSON object body is required" }, 400);
|
|
7410
8027
|
const sessionID = String(body.sessionID ?? "");
|
|
7411
8028
|
const ok = claimWake(sessionID);
|
|
7412
|
-
return
|
|
8029
|
+
return json10({ ok });
|
|
7413
8030
|
}
|
|
7414
8031
|
const m = p.match(/^\/rooms\/([^/]+)\/(join|leave|messages)$/);
|
|
7415
8032
|
if (m) {
|
|
7416
8033
|
const roomId = decodeURIComponent(m[1]);
|
|
7417
8034
|
const body = await jsonObject(req);
|
|
7418
8035
|
if (!body)
|
|
7419
|
-
return
|
|
8036
|
+
return json10({ error: "JSON object body is required" }, 400);
|
|
7420
8037
|
const sessionID = typeof body.sessionID === "string" ? body.sessionID : "";
|
|
7421
8038
|
if (req.method === "POST" && m[2] === "join") {
|
|
7422
8039
|
if (body.protocol !== undefined && body.protocol !== "v2" || body.receiverOwnerID !== undefined && !isReceiverOwnerID(body.receiverOwnerID)) {
|
|
7423
|
-
return
|
|
8040
|
+
return json10({ error: "invalid receiver ownership" }, 400);
|
|
7424
8041
|
}
|
|
7425
8042
|
const id = typeof body.participantId === "string" ? body.participantId.trim() : "";
|
|
7426
8043
|
const name = typeof body.participantName === "string" ? body.participantName.trim() : "";
|
|
7427
8044
|
if (!id || !name || !sessionID) {
|
|
7428
|
-
return
|
|
8045
|
+
return json10({ error: "participantId/participantName/sessionID are required" }, 400);
|
|
7429
8046
|
}
|
|
7430
8047
|
if (id.length > 64 || name.length > 64) {
|
|
7431
|
-
return
|
|
8048
|
+
return json10({ error: "name too long (max 64)" }, 400);
|
|
7432
8049
|
}
|
|
7433
8050
|
const result = await writeSqliteStateWithDatabase(databasePath(), (svc, reg, db) => {
|
|
7434
8051
|
const currentRoom = svc.getRoom(roomId);
|
|
@@ -7463,14 +8080,14 @@ async function handle(req) {
|
|
|
7463
8080
|
}) };
|
|
7464
8081
|
});
|
|
7465
8082
|
if ("status" in result)
|
|
7466
|
-
return
|
|
8083
|
+
return json10({ error: result.error }, result.status);
|
|
7467
8084
|
if ("pending" in result)
|
|
7468
|
-
return
|
|
8085
|
+
return json10({
|
|
7469
8086
|
status: "pending",
|
|
7470
8087
|
message: "Join request submitted. You are not a member yet; a human administrator must approve it before you can send or poll."
|
|
7471
8088
|
}, 202);
|
|
7472
8089
|
touchActive(sessionID);
|
|
7473
|
-
return
|
|
8090
|
+
return json10(await roomPayload(result.room), 201);
|
|
7474
8091
|
}
|
|
7475
8092
|
if (req.method === "POST" && m[2] === "leave") {
|
|
7476
8093
|
await mutate2((svc, reg) => {
|
|
@@ -7503,48 +8120,54 @@ async function handle(req) {
|
|
|
7503
8120
|
settleAdmins(svc.getRoom(roomId), reg[roomId] ?? {});
|
|
7504
8121
|
settleOwner(svc.getRoom(roomId), reg[roomId] ?? {});
|
|
7505
8122
|
});
|
|
7506
|
-
return
|
|
8123
|
+
return json10({ ok: true });
|
|
7507
8124
|
}
|
|
7508
8125
|
if (req.method === "POST" && m[2] === "messages") {
|
|
7509
8126
|
const isQuestion = body.isQuestion;
|
|
7510
8127
|
if (isQuestion !== undefined && typeof isQuestion !== "boolean")
|
|
7511
|
-
return
|
|
8128
|
+
return json10({ error: "isQuestion must be a boolean" }, 400);
|
|
7512
8129
|
const text = typeof body.text === "string" ? body.text.trim() : "";
|
|
7513
8130
|
if (!text) {
|
|
7514
|
-
return
|
|
8131
|
+
return json10({ error: "text is required" }, 400);
|
|
7515
8132
|
}
|
|
7516
8133
|
if (text.length > 5000) {
|
|
7517
|
-
return
|
|
8134
|
+
return json10({ error: "text too long (max 5000)" }, 400);
|
|
7518
8135
|
}
|
|
7519
8136
|
const replyTo = body.replyToMessageID;
|
|
7520
8137
|
if (replyTo !== undefined && (typeof replyTo !== "string" || !replyTo))
|
|
7521
|
-
return
|
|
8138
|
+
return json10({ error: "replyToMessageID must be a non-empty message ID" }, 400);
|
|
8139
|
+
const clientMessageID = body.clientMessageID;
|
|
8140
|
+
if (clientMessageID !== undefined && (typeof clientMessageID !== "string" || !clientMessageID || clientMessageID.length > 100)) {
|
|
8141
|
+
return json10({ error: "clientMessageID must be a non-empty string (max 100)" }, 400);
|
|
8142
|
+
}
|
|
7522
8143
|
if (replyTo !== undefined) {
|
|
7523
|
-
const result = await sendReply2(roomId, replyTo, sessionID, text);
|
|
8144
|
+
const result = await sendReply2(roomId, replyTo, sessionID, text, clientMessageID);
|
|
7524
8145
|
if (result.status !== "ok") {
|
|
7525
8146
|
if (result.status === "missing")
|
|
7526
|
-
return
|
|
8147
|
+
return json10({ error: "room not found" }, 404);
|
|
7527
8148
|
if (result.status === "target")
|
|
7528
|
-
return
|
|
8149
|
+
return json10({ error: "reply target not found in room" }, 404);
|
|
7529
8150
|
if (result.status === "question")
|
|
7530
|
-
return
|
|
7531
|
-
return
|
|
8151
|
+
return json10({ error: "use the question answers endpoint to reply to a question" }, 409);
|
|
8152
|
+
return json10({ error: "session is not a room member" }, 409);
|
|
7532
8153
|
}
|
|
7533
8154
|
touchActive(sessionID);
|
|
7534
8155
|
const room = await read((svc) => svc.getRoom(roomId));
|
|
7535
|
-
|
|
7536
|
-
|
|
8156
|
+
if (!result.duplicate)
|
|
8157
|
+
wakeMentionedSessions(serveWakeUrl2, roomId, room.name, text, sessionID, result.message);
|
|
8158
|
+
return json10(await roomPayload(room), 201);
|
|
7537
8159
|
}
|
|
7538
|
-
const result = await appendRoomMessage2(roomId, sessionID, text, isQuestion === true);
|
|
8160
|
+
const result = await appendRoomMessage2(roomId, sessionID, text, isQuestion === true, clientMessageID);
|
|
7539
8161
|
if (result.status !== "ok") {
|
|
7540
8162
|
if (result.status === "missing")
|
|
7541
|
-
return
|
|
7542
|
-
return
|
|
8163
|
+
return json10({ error: "room not found" }, 404);
|
|
8164
|
+
return json10({ error: "session is not a room member" }, 409);
|
|
7543
8165
|
}
|
|
7544
8166
|
touchActive(sessionID);
|
|
7545
8167
|
const room = await read((svc) => svc.getRoom(roomId));
|
|
7546
|
-
|
|
7547
|
-
|
|
8168
|
+
if (!result.duplicate)
|
|
8169
|
+
wakeMentionedSessions(serveWakeUrl2, roomId, room.name, text, sessionID, result.message);
|
|
8170
|
+
return json10(await roomPayload(room), 201);
|
|
7548
8171
|
}
|
|
7549
8172
|
}
|
|
7550
8173
|
const questions = p.match(/^\/rooms\/([^/]+)\/questions$/);
|
|
@@ -7552,8 +8175,8 @@ async function handle(req) {
|
|
|
7552
8175
|
const roomId = decodeURIComponent(questions[1]);
|
|
7553
8176
|
const exists = await read((svc) => svc.listRooms().some((room) => room.id === roomId));
|
|
7554
8177
|
if (!exists)
|
|
7555
|
-
return
|
|
7556
|
-
return
|
|
8178
|
+
return json10({ error: "room not found" }, 404);
|
|
8179
|
+
return json10({ questions: await readQuestions2(roomId) });
|
|
7557
8180
|
}
|
|
7558
8181
|
const answer = p.match(/^\/rooms\/([^/]+)\/questions\/([^/]+)\/answers$/);
|
|
7559
8182
|
if (req.method === "POST" && answer) {
|
|
@@ -7561,30 +8184,30 @@ async function handle(req) {
|
|
|
7561
8184
|
const questionID = decodeURIComponent(answer[2]);
|
|
7562
8185
|
const body = await req.json();
|
|
7563
8186
|
if (!body || typeof body !== "object" || Array.isArray(body))
|
|
7564
|
-
return
|
|
8187
|
+
return json10({ error: "sessionID and non-empty text (max 5000) are required" }, 400);
|
|
7565
8188
|
const input = body;
|
|
7566
8189
|
if (typeof input.sessionID !== "string" || !input.sessionID || typeof input.text !== "string" || !input.text.trim() || input.text.trim().length > 5000)
|
|
7567
|
-
return
|
|
8190
|
+
return json10({ error: "sessionID and non-empty text (max 5000) are required" }, 400);
|
|
7568
8191
|
const result = await answerQuestion2(roomId, questionID, input.sessionID, input.text.trim());
|
|
7569
8192
|
if (result.status === "missing")
|
|
7570
|
-
return
|
|
8193
|
+
return json10({ error: "room not found" }, 404);
|
|
7571
8194
|
if (result.status === "question")
|
|
7572
|
-
return
|
|
8195
|
+
return json10({ error: "question not found" }, 404);
|
|
7573
8196
|
if (result.status === "member")
|
|
7574
|
-
return
|
|
8197
|
+
return json10({ error: "session is not a room member" }, 409);
|
|
7575
8198
|
if (result.status === "answered")
|
|
7576
|
-
return
|
|
8199
|
+
return json10({ error: "question already answered" }, 409);
|
|
7577
8200
|
if (result.status !== "ok")
|
|
7578
|
-
return
|
|
8201
|
+
return json10({ error: "question not found" }, 404);
|
|
7579
8202
|
touchActive(input.sessionID);
|
|
7580
8203
|
const room = await read((svc) => svc.getRoom(roomId));
|
|
7581
8204
|
wakeMentionedSessions(serveWakeUrl2, roomId, room.name, result.answer.text, input.sessionID, result.answer);
|
|
7582
|
-
return
|
|
8205
|
+
return json10({ questionID, answer: result.answer }, 201);
|
|
7583
8206
|
}
|
|
7584
8207
|
const g = p.match(/^\/rooms\/([^/]+)$/);
|
|
7585
8208
|
if (g && req.method === "GET") {
|
|
7586
8209
|
const room = await read((svc) => svc.getRoom(decodeURIComponent(g[1])));
|
|
7587
|
-
return
|
|
8210
|
+
return json10(await roomPayload(room));
|
|
7588
8211
|
}
|
|
7589
8212
|
const r = p.match(/^\/rooms\/([^/]+)\/registry$/);
|
|
7590
8213
|
if (r && req.method === "GET") {
|
|
@@ -7606,22 +8229,22 @@ async function handle(req) {
|
|
|
7606
8229
|
}
|
|
7607
8230
|
]));
|
|
7608
8231
|
});
|
|
7609
|
-
return
|
|
8232
|
+
return json10(reg);
|
|
7610
8233
|
}
|
|
7611
|
-
return
|
|
8234
|
+
return json10({ error: "not found" }, 404);
|
|
7612
8235
|
} catch (err) {
|
|
7613
8236
|
if (err instanceof SyntaxError)
|
|
7614
|
-
return
|
|
8237
|
+
return json10({ error: "invalid JSON body" }, 400);
|
|
7615
8238
|
if (err instanceof RoomError) {
|
|
7616
|
-
return
|
|
8239
|
+
return json10({ error: err.message }, err.code === "ROOM_NOT_FOUND" ? 404 : err.code === "NOT_OWNER" ? 403 : 409);
|
|
7617
8240
|
}
|
|
7618
|
-
return
|
|
8241
|
+
return json10({ error: err instanceof Error ? err.message : String(err) }, 500);
|
|
7619
8242
|
}
|
|
7620
8243
|
}
|
|
7621
8244
|
var moduleDir, here, versionTag, chatVersionTag = () => versionTag ??= fs5.readFile(path14.join(here, "../package.json"), "utf8").then((text) => {
|
|
7622
8245
|
const pkg = JSON.parse(text);
|
|
7623
8246
|
return typeof pkg?.version === "string" && pkg.version ? `v${pkg.version}` : "";
|
|
7624
|
-
}).catch(() => ""), settings, hostname, displayHostname, port, token, serveWakeUrl2,
|
|
8247
|
+
}).catch(() => ""), settings, hostname, displayHostname, port, token, serveWakeUrl2, json10 = (body, status = 200) => new Response(JSON.stringify(body), {
|
|
7625
8248
|
status,
|
|
7626
8249
|
headers: { "Content-Type": "application/json" }
|
|
7627
8250
|
}), sleep = (ms) => new Promise((r) => setTimeout(r, ms)), config, chat_server_default;
|
|
@@ -7648,7 +8271,7 @@ var init_chat_server = __esm(async () => {
|
|
|
7648
8271
|
init_http_server();
|
|
7649
8272
|
await init_admin_routes();
|
|
7650
8273
|
moduleDir = path14.dirname(fileURLToPath4(import.meta.url));
|
|
7651
|
-
here =
|
|
8274
|
+
here = existsSync4(path14.join(moduleDir, "chat.html")) ? moduleDir : path14.resolve(moduleDir, "../server");
|
|
7652
8275
|
settings = resolveServerSettings(loadRoomConfig());
|
|
7653
8276
|
hostname = settings.host;
|
|
7654
8277
|
displayHostname = hostname.includes(":") ? `[${hostname}]` : hostname;
|
|
@@ -7679,7 +8302,7 @@ var init_chat_server = __esm(async () => {
|
|
|
7679
8302
|
|
|
7680
8303
|
// cli.ts
|
|
7681
8304
|
import { spawnSync } from "node:child_process";
|
|
7682
|
-
import { existsSync as
|
|
8305
|
+
import { existsSync as existsSync5 } from "node:fs";
|
|
7683
8306
|
import { readFile as readFile3 } from "node:fs/promises";
|
|
7684
8307
|
import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
7685
8308
|
var usage = `Usage: opencode-chat-room [options]
|
|
@@ -7736,7 +8359,7 @@ if (args[0] === "cli") {
|
|
|
7736
8359
|
relaunchTuiWithBun();
|
|
7737
8360
|
const packaged = new URL("../src/tui/main.mjs", import.meta.url);
|
|
7738
8361
|
const source = new URL("./src/tui/main.mjs", import.meta.url);
|
|
7739
|
-
const entry =
|
|
8362
|
+
const entry = existsSync5(fileURLToPath5(packaged)) ? packaged : source;
|
|
7740
8363
|
const { main } = await import(entry.href);
|
|
7741
8364
|
process.exit(await main(args.slice(1)));
|
|
7742
8365
|
}
|