@alexsun-top/opencode-chat-room 0.7.6 → 0.7.7
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 +13 -0
- package/README.md +5 -5
- package/README.zh-CN.md +5 -5
- package/dist/cli.js +735 -164
- package/package.json +2 -1
- package/plugin.ts +15 -3
- package/server/assets/base.css +0 -2
- package/server/assets/chat/doc-preview.js +11 -2
- package/server/assets/chat/editor.js +10 -7
- package/server/assets/chat/events.js +1 -1
- package/server/assets/chat/index.js +2 -0
- package/server/assets/chat/locales/de.js +18 -0
- package/server/assets/chat/locales/es.js +18 -0
- package/server/assets/chat/locales/fr.js +18 -0
- package/server/assets/chat/locales/it.js +18 -0
- package/server/assets/chat/locales/ja.js +18 -0
- package/server/assets/chat/locales/ko.js +18 -0
- package/server/assets/chat/markdown.js +27 -1
- package/server/assets/chat/messages.js +1 -0
- package/server/assets/chat/palette.js +9 -4
- package/server/assets/chat/questions.js +1 -0
- package/server/assets/chat/rooms.js +6 -1
- package/server/assets/chat/shortcuts.js +14 -3
- package/server/assets/chat/state.js +36 -0
- 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 +169 -0
- package/server/assets/chat/tasks.js +494 -0
- package/server/assets/responsive.css +26 -1
- package/server/assets/tasks.css +422 -0
- package/server/chat.html +97 -19
- package/server/member-routes.ts +3 -0
- package/server/sw.js +12 -2
- package/server/task-routes.ts +53 -0
- package/skills/chatroom/SKILL.md +3 -1
- package/src/README.md +3 -3
- package/src/agent/task-tool.ts +155 -0
- package/src/center/center-client.ts +44 -0
- package/src/rooms/tasks.ts +246 -0
- package/src/runtime/v2-plugin.ts +11 -2
- package/src/state/sqlite-state.ts +67 -0
- package/src/tui/app.mjs +5 -3
- package/src/tui/main.mjs +4 -4
- package/src/tui/markdown.mjs +29 -5
- package/src/tui/mentions.mjs +218 -0
- package/src/tui/message-app.mjs +3 -2
- package/src/tui/palette-app.mjs +9 -2
- package/src/tui/ui-content.mjs +9 -2
- 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;");
|
|
@@ -870,6 +872,41 @@ async function removeResource(file, roomID, id) {
|
|
|
870
872
|
const db = await openStateDatabase(file);
|
|
871
873
|
return immediate2(db, () => db.query("DELETE FROM resources WHERE room_id=? AND id=?").run(roomID, id).changes > 0);
|
|
872
874
|
}
|
|
875
|
+
function listRoomTasks(db, roomID) {
|
|
876
|
+
return db.query(`SELECT ${ROOM_TASK_COLUMNS} FROM room_tasks WHERE room_id=? ORDER BY created_at,id`).all(roomID).map(roomTask);
|
|
877
|
+
}
|
|
878
|
+
function readRoomTask(db, roomID, id) {
|
|
879
|
+
const row = db.query(`SELECT ${ROOM_TASK_COLUMNS} FROM room_tasks WHERE room_id=? AND id=?`).get(roomID, id);
|
|
880
|
+
return row ? roomTask(row) : undefined;
|
|
881
|
+
}
|
|
882
|
+
function insertRoomTask(db, task) {
|
|
883
|
+
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));
|
|
884
|
+
}
|
|
885
|
+
function patchRoomTask(db, roomID, id, patch, updatedAt) {
|
|
886
|
+
const sets = [], values = [];
|
|
887
|
+
for (const [column, value] of [["title", patch.title], ["description", patch.description], ["assignee", patch.assignee], ["status", patch.status], ["due_date", patch.dueDate], ["conclusion", patch.conclusion]]) {
|
|
888
|
+
if (value !== undefined) {
|
|
889
|
+
sets.push(`${column}=?`);
|
|
890
|
+
values.push(value);
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
if (patch.participants !== undefined) {
|
|
894
|
+
sets.push("participants=?");
|
|
895
|
+
values.push(JSON.stringify(patch.participants));
|
|
896
|
+
}
|
|
897
|
+
if (patch.steps !== undefined) {
|
|
898
|
+
sets.push("steps=?");
|
|
899
|
+
values.push(JSON.stringify(patch.steps));
|
|
900
|
+
}
|
|
901
|
+
db.query(`UPDATE room_tasks SET ${sets.map((set) => `${set},`).join("")}updated_at=? WHERE room_id=? AND id=?`).run(...values, updatedAt, roomID, id);
|
|
902
|
+
return readRoomTask(db, roomID, id);
|
|
903
|
+
}
|
|
904
|
+
function deleteRoomTask(db, roomID, id) {
|
|
905
|
+
return db.query("DELETE FROM room_tasks WHERE room_id=? AND id=?").run(roomID, id).changes > 0;
|
|
906
|
+
}
|
|
907
|
+
function deleteCompletedRoomTasks(db, roomID, creatorSessionID) {
|
|
908
|
+
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;
|
|
909
|
+
}
|
|
873
910
|
async function ensureRoomColumns(db) {
|
|
874
911
|
await immediate2(db, () => {
|
|
875
912
|
const messageColumns = db.query("PRAGMA table_info(messages)").all();
|
|
@@ -885,6 +922,15 @@ async function ensureRoomColumns(db) {
|
|
|
885
922
|
db.exec("ALTER TABLE messages ADD COLUMN recalled_by TEXT");
|
|
886
923
|
db.exec("CREATE INDEX IF NOT EXISTS messages_pending_questions ON messages(room_id,is_question,answered_by,seq)");
|
|
887
924
|
db.exec("CREATE INDEX IF NOT EXISTS messages_room_recalled ON messages(room_id,recalled_at)");
|
|
925
|
+
const taskColumns = db.query("PRAGMA table_info(room_tasks)").all();
|
|
926
|
+
if (!taskColumns.some((column) => column.name === "due_date"))
|
|
927
|
+
db.exec("ALTER TABLE room_tasks ADD COLUMN due_date TEXT NOT NULL DEFAULT ''");
|
|
928
|
+
if (!taskColumns.some((column) => column.name === "participants"))
|
|
929
|
+
db.exec("ALTER TABLE room_tasks ADD COLUMN participants TEXT NOT NULL DEFAULT '[]'");
|
|
930
|
+
if (!taskColumns.some((column) => column.name === "conclusion"))
|
|
931
|
+
db.exec("ALTER TABLE room_tasks ADD COLUMN conclusion TEXT NOT NULL DEFAULT ''");
|
|
932
|
+
if (!taskColumns.some((column) => column.name === "steps"))
|
|
933
|
+
db.exec("ALTER TABLE room_tasks ADD COLUMN steps TEXT NOT NULL DEFAULT '[]'");
|
|
888
934
|
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
935
|
db.exec(`CREATE TABLE IF NOT EXISTS room_join_requests(
|
|
890
936
|
room_id TEXT NOT NULL REFERENCES rooms(id) ON DELETE CASCADE,
|
|
@@ -1540,11 +1586,24 @@ function rowMessage(row) {
|
|
|
1540
1586
|
...row.answered_by ? { answeredByMessageID: String(row.answered_by) } : {}
|
|
1541
1587
|
};
|
|
1542
1588
|
}
|
|
1543
|
-
var databases2,
|
|
1589
|
+
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) => {
|
|
1590
|
+
try {
|
|
1591
|
+
const parsed = JSON.parse(value);
|
|
1592
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
1593
|
+
} catch {
|
|
1594
|
+
return [];
|
|
1595
|
+
}
|
|
1596
|
+
}, roomTask = (row) => ({
|
|
1597
|
+
...row,
|
|
1598
|
+
status: row.status,
|
|
1599
|
+
participants: jsonArray(row.participants),
|
|
1600
|
+
steps: jsonArray(row.steps)
|
|
1601
|
+
}), 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
1602
|
var init_sqlite_state = __esm(() => {
|
|
1545
1603
|
init_room_service();
|
|
1546
1604
|
init_sqlite();
|
|
1547
1605
|
databases2 = new Map;
|
|
1606
|
+
ROOM_TASK_STATUSES = ["todo", "doing", "done"];
|
|
1548
1607
|
retentionCounters = new Map;
|
|
1549
1608
|
});
|
|
1550
1609
|
|
|
@@ -1834,6 +1893,388 @@ var init_queue = __esm(() => {
|
|
|
1834
1893
|
PENDING_TTL_MS = 5 * 60000;
|
|
1835
1894
|
});
|
|
1836
1895
|
|
|
1896
|
+
// src/rooms/tasks.ts
|
|
1897
|
+
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
1898
|
+
function context(db, roomID, sessionID) {
|
|
1899
|
+
const room = db.query("SELECT kind,owner_id,owner_membership_id,admin_names,admin_membership_ids FROM rooms WHERE id=?").get(roomID);
|
|
1900
|
+
if (!room)
|
|
1901
|
+
return { status: 404, error: "room not found" };
|
|
1902
|
+
if (room.kind === "direct")
|
|
1903
|
+
return { status: 409, error: "tasks are not available in direct rooms" };
|
|
1904
|
+
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);
|
|
1905
|
+
if (!member)
|
|
1906
|
+
return { status: 403, error: "not a room member" };
|
|
1907
|
+
const roleRoom = {
|
|
1908
|
+
ownerId: room.owner_id,
|
|
1909
|
+
...room.owner_membership_id ? { ownerMembershipID: room.owner_membership_id } : {},
|
|
1910
|
+
...room.admin_names ? { adminIds: JSON.parse(room.admin_names) } : {},
|
|
1911
|
+
...room.admin_membership_ids ? { adminMembershipIDs: JSON.parse(room.admin_membership_ids) } : {}
|
|
1912
|
+
};
|
|
1913
|
+
const entry = {
|
|
1914
|
+
name: member.name,
|
|
1915
|
+
...member.protocol ? { protocol: member.protocol } : {},
|
|
1916
|
+
...member.host ? { host: member.host } : {},
|
|
1917
|
+
...member.receiver_owner_id ? { receiverOwnerID: member.receiver_owner_id } : {},
|
|
1918
|
+
...member.membership_id ? { membershipID: member.membership_id } : {}
|
|
1919
|
+
};
|
|
1920
|
+
const participants = new Set(db.query("SELECT name FROM participants WHERE room_id=?").all(roomID).map((row) => row.name));
|
|
1921
|
+
return { room: roleRoom, entry, name: member.name, participants };
|
|
1922
|
+
}
|
|
1923
|
+
function readTitle(value) {
|
|
1924
|
+
if (typeof value !== "string")
|
|
1925
|
+
return;
|
|
1926
|
+
const title = value.trim();
|
|
1927
|
+
return title && Array.from(title).length <= MAX_TITLE ? title : undefined;
|
|
1928
|
+
}
|
|
1929
|
+
function readDescription(value) {
|
|
1930
|
+
return typeof value === "string" && Array.from(value).length <= MAX_DESCRIPTION ? value : undefined;
|
|
1931
|
+
}
|
|
1932
|
+
function readDueDate(value) {
|
|
1933
|
+
if (typeof value !== "string")
|
|
1934
|
+
return;
|
|
1935
|
+
if (value === "")
|
|
1936
|
+
return "";
|
|
1937
|
+
if (value.length !== 10)
|
|
1938
|
+
return;
|
|
1939
|
+
const date = new Date(`${value}T00:00:00Z`);
|
|
1940
|
+
return !Number.isNaN(date.getTime()) && date.toISOString().slice(0, 10) === value ? value : undefined;
|
|
1941
|
+
}
|
|
1942
|
+
function readParticipants(value, participants) {
|
|
1943
|
+
if (!Array.isArray(value) || value.length > MAX_PARTICIPANTS)
|
|
1944
|
+
return;
|
|
1945
|
+
const names = [];
|
|
1946
|
+
for (const name of value) {
|
|
1947
|
+
if (typeof name !== "string" || !participants.has(name) || names.includes(name))
|
|
1948
|
+
return;
|
|
1949
|
+
names.push(name);
|
|
1950
|
+
}
|
|
1951
|
+
return names;
|
|
1952
|
+
}
|
|
1953
|
+
function readConclusion(value) {
|
|
1954
|
+
return typeof value === "string" && Array.from(value).length <= MAX_CONCLUSION ? value : undefined;
|
|
1955
|
+
}
|
|
1956
|
+
function readStepText(value) {
|
|
1957
|
+
return typeof value === "string" && value.trim().length > 0 && Array.from(value).length <= MAX_STEP_TEXT ? value : undefined;
|
|
1958
|
+
}
|
|
1959
|
+
function readSteps(value) {
|
|
1960
|
+
if (!Array.isArray(value) || value.length > MAX_STEPS)
|
|
1961
|
+
return;
|
|
1962
|
+
const steps = [];
|
|
1963
|
+
for (const item of value) {
|
|
1964
|
+
if (typeof item === "string") {
|
|
1965
|
+
const text = readStepText(item);
|
|
1966
|
+
if (text === undefined)
|
|
1967
|
+
return;
|
|
1968
|
+
steps.push({ text, done: false });
|
|
1969
|
+
continue;
|
|
1970
|
+
}
|
|
1971
|
+
if (typeof item !== "object" || item === null || Array.isArray(item))
|
|
1972
|
+
return;
|
|
1973
|
+
const text = readStepText(item.text);
|
|
1974
|
+
const done = item.done;
|
|
1975
|
+
if (text === undefined || typeof done !== "boolean")
|
|
1976
|
+
return;
|
|
1977
|
+
steps.push({ text, done });
|
|
1978
|
+
}
|
|
1979
|
+
return steps;
|
|
1980
|
+
}
|
|
1981
|
+
function listTasks(roomID, sessionID) {
|
|
1982
|
+
return withStateTransaction(databasePath(), (db) => {
|
|
1983
|
+
const ctx = context(db, roomID, sessionID);
|
|
1984
|
+
if (isFailure(ctx))
|
|
1985
|
+
return ctx;
|
|
1986
|
+
return { tasks: listRoomTasks(db, roomID) };
|
|
1987
|
+
});
|
|
1988
|
+
}
|
|
1989
|
+
function createTask(roomID, sessionID, input) {
|
|
1990
|
+
return withStateTransaction(databasePath(), (db) => {
|
|
1991
|
+
const ctx = context(db, roomID, sessionID);
|
|
1992
|
+
if (isFailure(ctx))
|
|
1993
|
+
return ctx;
|
|
1994
|
+
const title = readTitle(input.title);
|
|
1995
|
+
if (!title)
|
|
1996
|
+
return invalid(`title must contain 1 to ${MAX_TITLE} characters`);
|
|
1997
|
+
const description = input.description === undefined ? "" : readDescription(input.description);
|
|
1998
|
+
if (description === undefined)
|
|
1999
|
+
return invalid(`description must be a string of at most ${MAX_DESCRIPTION} characters`);
|
|
2000
|
+
const assignee = input.assignee === undefined ? "" : input.assignee;
|
|
2001
|
+
if (typeof assignee !== "string" || assignee !== "" && !ctx.participants.has(assignee))
|
|
2002
|
+
return invalid("assignee must be a current participant name");
|
|
2003
|
+
const dueDate = input.dueDate === undefined ? "" : readDueDate(input.dueDate);
|
|
2004
|
+
if (dueDate === undefined)
|
|
2005
|
+
return invalid("dueDate must be empty or a valid YYYY-MM-DD calendar date");
|
|
2006
|
+
const participants = input.participants === undefined ? [] : readParticipants(input.participants, ctx.participants);
|
|
2007
|
+
if (participants === undefined)
|
|
2008
|
+
return invalid(`participants must be at most ${MAX_PARTICIPANTS} unique current participant names`);
|
|
2009
|
+
const conclusion = input.conclusion === undefined ? "" : readConclusion(input.conclusion);
|
|
2010
|
+
if (conclusion === undefined)
|
|
2011
|
+
return invalid(`conclusion must be a string of at most ${MAX_CONCLUSION} characters`);
|
|
2012
|
+
const steps = input.steps === undefined ? [] : readSteps(input.steps);
|
|
2013
|
+
if (steps === undefined)
|
|
2014
|
+
return invalid(`steps must be at most ${MAX_STEPS} items, each text 1 to ${MAX_STEP_TEXT} characters with a boolean done`);
|
|
2015
|
+
const now = Date.now();
|
|
2016
|
+
const task = {
|
|
2017
|
+
id: randomUUID5(),
|
|
2018
|
+
roomId: roomID,
|
|
2019
|
+
title,
|
|
2020
|
+
description,
|
|
2021
|
+
assignee,
|
|
2022
|
+
status: "todo",
|
|
2023
|
+
creatorName: ctx.name,
|
|
2024
|
+
creatorSessionID: sessionID,
|
|
2025
|
+
createdAt: now,
|
|
2026
|
+
updatedAt: now,
|
|
2027
|
+
dueDate,
|
|
2028
|
+
participants,
|
|
2029
|
+
conclusion,
|
|
2030
|
+
steps
|
|
2031
|
+
};
|
|
2032
|
+
insertRoomTask(db, task);
|
|
2033
|
+
return { task };
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
function updateTask(roomID, taskID, sessionID, input) {
|
|
2037
|
+
return withStateTransaction(databasePath(), (db) => {
|
|
2038
|
+
const ctx = context(db, roomID, sessionID);
|
|
2039
|
+
if (isFailure(ctx))
|
|
2040
|
+
return ctx;
|
|
2041
|
+
const task = readRoomTask(db, roomID, taskID);
|
|
2042
|
+
if (!task)
|
|
2043
|
+
return { status: 404, error: "task not found" };
|
|
2044
|
+
const patch = {};
|
|
2045
|
+
if (input.title !== undefined) {
|
|
2046
|
+
const title = readTitle(input.title);
|
|
2047
|
+
if (!title)
|
|
2048
|
+
return invalid(`title must contain 1 to ${MAX_TITLE} characters`);
|
|
2049
|
+
patch.title = title;
|
|
2050
|
+
}
|
|
2051
|
+
if (input.description !== undefined) {
|
|
2052
|
+
const description = readDescription(input.description);
|
|
2053
|
+
if (description === undefined)
|
|
2054
|
+
return invalid(`description must be a string of at most ${MAX_DESCRIPTION} characters`);
|
|
2055
|
+
patch.description = description;
|
|
2056
|
+
}
|
|
2057
|
+
if (input.assignee !== undefined) {
|
|
2058
|
+
const assignee = input.assignee;
|
|
2059
|
+
if (typeof assignee !== "string")
|
|
2060
|
+
return invalid("assignee must be a current participant name");
|
|
2061
|
+
if (assignee !== "" && !ctx.participants.has(assignee) && assignee !== task.assignee)
|
|
2062
|
+
return invalid("assignee must be a current participant name");
|
|
2063
|
+
patch.assignee = assignee;
|
|
2064
|
+
}
|
|
2065
|
+
if (input.status !== undefined) {
|
|
2066
|
+
if (typeof input.status !== "string" || !ROOM_TASK_STATUSES.includes(input.status))
|
|
2067
|
+
return invalid("status must be todo, doing, or done");
|
|
2068
|
+
patch.status = input.status;
|
|
2069
|
+
}
|
|
2070
|
+
if (input.dueDate !== undefined) {
|
|
2071
|
+
const dueDate = readDueDate(input.dueDate);
|
|
2072
|
+
if (dueDate === undefined)
|
|
2073
|
+
return invalid("dueDate must be empty or a valid YYYY-MM-DD calendar date");
|
|
2074
|
+
patch.dueDate = dueDate;
|
|
2075
|
+
}
|
|
2076
|
+
if (input.participants !== undefined) {
|
|
2077
|
+
const allowed = new Set([...ctx.participants, ...task.participants]);
|
|
2078
|
+
const participants = readParticipants(input.participants, allowed);
|
|
2079
|
+
if (participants === undefined)
|
|
2080
|
+
return invalid(`participants must be at most ${MAX_PARTICIPANTS} unique participant names`);
|
|
2081
|
+
patch.participants = participants;
|
|
2082
|
+
}
|
|
2083
|
+
if (input.conclusion !== undefined) {
|
|
2084
|
+
const conclusion = readConclusion(input.conclusion);
|
|
2085
|
+
if (conclusion === undefined)
|
|
2086
|
+
return invalid(`conclusion must be a string of at most ${MAX_CONCLUSION} characters`);
|
|
2087
|
+
patch.conclusion = conclusion;
|
|
2088
|
+
}
|
|
2089
|
+
if (input.steps !== undefined) {
|
|
2090
|
+
const steps = readSteps(input.steps);
|
|
2091
|
+
if (steps === undefined)
|
|
2092
|
+
return invalid(`steps must be at most ${MAX_STEPS} items, each text 1 to ${MAX_STEP_TEXT} characters with a boolean done`);
|
|
2093
|
+
patch.steps = steps;
|
|
2094
|
+
}
|
|
2095
|
+
if (!Object.keys(patch).length)
|
|
2096
|
+
return invalid("at least one task field is required");
|
|
2097
|
+
const admin = isRoomAdmin(ctx.room, ctx.entry);
|
|
2098
|
+
const creator = task.creatorSessionID === sessionID;
|
|
2099
|
+
const assignee = task.assignee !== "" && task.assignee === ctx.name;
|
|
2100
|
+
const contentChanged = patch.title !== undefined || patch.description !== undefined || patch.assignee !== undefined || patch.dueDate !== undefined || patch.participants !== undefined || patch.conclusion !== undefined;
|
|
2101
|
+
const stepsChanged = patch.steps !== undefined && (patch.steps.length !== task.steps.length || patch.steps.some((step, index) => step.text !== task.steps[index].text));
|
|
2102
|
+
if (!admin && !creator && (!assignee || contentChanged || stepsChanged)) {
|
|
2103
|
+
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" };
|
|
2104
|
+
}
|
|
2105
|
+
const updated = patchRoomTask(db, roomID, taskID, patch, Date.now());
|
|
2106
|
+
return updated ? { task: updated } : { status: 404, error: "task not found" };
|
|
2107
|
+
});
|
|
2108
|
+
}
|
|
2109
|
+
function deleteTask(roomID, taskID, sessionID) {
|
|
2110
|
+
return withStateTransaction(databasePath(), (db) => {
|
|
2111
|
+
const ctx = context(db, roomID, sessionID);
|
|
2112
|
+
if (isFailure(ctx))
|
|
2113
|
+
return ctx;
|
|
2114
|
+
const task = readRoomTask(db, roomID, taskID);
|
|
2115
|
+
if (!task)
|
|
2116
|
+
return { status: 404, error: "task not found" };
|
|
2117
|
+
if (task.creatorSessionID !== sessionID && !isRoomAdmin(ctx.room, ctx.entry)) {
|
|
2118
|
+
return { status: 403, error: "not allowed to delete this task" };
|
|
2119
|
+
}
|
|
2120
|
+
deleteRoomTask(db, roomID, taskID);
|
|
2121
|
+
return { ok: true };
|
|
2122
|
+
});
|
|
2123
|
+
}
|
|
2124
|
+
function clearCompletedTasks(roomID, sessionID) {
|
|
2125
|
+
return withStateTransaction(databasePath(), (db) => {
|
|
2126
|
+
const ctx = context(db, roomID, sessionID);
|
|
2127
|
+
if (isFailure(ctx))
|
|
2128
|
+
return ctx;
|
|
2129
|
+
const admin = isRoomAdmin(ctx.room, ctx.entry);
|
|
2130
|
+
return { ok: true, count: deleteCompletedRoomTasks(db, roomID, admin ? undefined : sessionID) };
|
|
2131
|
+
});
|
|
2132
|
+
}
|
|
2133
|
+
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);
|
|
2134
|
+
var init_tasks = __esm(() => {
|
|
2135
|
+
init_sqlite_state();
|
|
2136
|
+
init_store();
|
|
2137
|
+
init_sqlite_state();
|
|
2138
|
+
});
|
|
2139
|
+
|
|
2140
|
+
// src/agent/task-tool.ts
|
|
2141
|
+
function visible(value, max) {
|
|
2142
|
+
return typeof value === "string" && value.trim().length > 0 && Array.from(value.trim()).length <= max;
|
|
2143
|
+
}
|
|
2144
|
+
function calendarDate(value) {
|
|
2145
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
|
|
2146
|
+
if (!match)
|
|
2147
|
+
return false;
|
|
2148
|
+
const [year, month, day] = [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
2149
|
+
const date = new Date(Date.UTC(year, month - 1, day));
|
|
2150
|
+
return date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day;
|
|
2151
|
+
}
|
|
2152
|
+
function readSteps2(value) {
|
|
2153
|
+
if (!Array.isArray(value) || value.length > MAX_STEPS2)
|
|
2154
|
+
return;
|
|
2155
|
+
const steps = [];
|
|
2156
|
+
for (const item of value) {
|
|
2157
|
+
if (typeof item === "string") {
|
|
2158
|
+
if (!visible(item, 300))
|
|
2159
|
+
return;
|
|
2160
|
+
steps.push(item.trim());
|
|
2161
|
+
continue;
|
|
2162
|
+
}
|
|
2163
|
+
if (!item || typeof item !== "object" || Array.isArray(item))
|
|
2164
|
+
return;
|
|
2165
|
+
const step = item;
|
|
2166
|
+
if (!visible(step.text, 300) || step.done !== undefined && typeof step.done !== "boolean")
|
|
2167
|
+
return;
|
|
2168
|
+
steps.push({ text: step.text.trim(), done: step.done === true });
|
|
2169
|
+
}
|
|
2170
|
+
return steps;
|
|
2171
|
+
}
|
|
2172
|
+
function displaySteps(steps) {
|
|
2173
|
+
return (steps ?? []).flatMap((step) => {
|
|
2174
|
+
if (typeof step === "string")
|
|
2175
|
+
return step ? [{ text: step, done: false }] : [];
|
|
2176
|
+
return typeof step?.text === "string" && step.text ? [{ text: step.text, done: step.done === true }] : [];
|
|
2177
|
+
});
|
|
2178
|
+
}
|
|
2179
|
+
function validateTaskFields(fields, creating) {
|
|
2180
|
+
if (creating && (typeof fields.title !== "string" || !fields.title.trim()))
|
|
2181
|
+
return "title is required to create a task; pass a short task title";
|
|
2182
|
+
if (fields.title !== undefined && !visible(fields.title, 200))
|
|
2183
|
+
return "title must contain 1 to 200 characters";
|
|
2184
|
+
if (fields.description !== undefined && (typeof fields.description !== "string" || Array.from(fields.description).length > 5000))
|
|
2185
|
+
return "description must be a string of at most 5000 characters";
|
|
2186
|
+
if (fields.assignee !== undefined && (typeof fields.assignee !== "string" || Array.from(fields.assignee.trim()).length > 64))
|
|
2187
|
+
return "assignee must be a participant name of at most 64 characters";
|
|
2188
|
+
if (fields.status !== undefined && !["todo", "doing", "done"].includes(fields.status))
|
|
2189
|
+
return "status must be todo, doing, or done";
|
|
2190
|
+
if (fields.dueDate !== undefined) {
|
|
2191
|
+
if (typeof fields.dueDate !== "string")
|
|
2192
|
+
return "dueDate must be YYYY-MM-DD or empty to clear it";
|
|
2193
|
+
if (fields.dueDate.trim() !== "" && !calendarDate(fields.dueDate.trim()))
|
|
2194
|
+
return "dueDate must be a real calendar date in YYYY-MM-DD form, for example 2026-12-31, or empty to clear it";
|
|
2195
|
+
}
|
|
2196
|
+
if (fields.participants !== undefined && (!Array.isArray(fields.participants) || fields.participants.length > 50 || !fields.participants.every((name) => visible(name, 64))))
|
|
2197
|
+
return "participants must be an array of at most 50 room participant names, each 1 to 64 characters";
|
|
2198
|
+
if (fields.conclusion !== undefined && (typeof fields.conclusion !== "string" || Array.from(fields.conclusion).length > 5000))
|
|
2199
|
+
return "conclusion must be a string of at most 5000 characters";
|
|
2200
|
+
if (fields.steps !== undefined && readSteps2(fields.steps) === undefined)
|
|
2201
|
+
return "steps must be an array of at most 30 steps; each step is text of 1 to 300 characters or {text, done}";
|
|
2202
|
+
return;
|
|
2203
|
+
}
|
|
2204
|
+
function taskFields(args) {
|
|
2205
|
+
return {
|
|
2206
|
+
...args.title !== undefined ? { title: args.title.trim() } : {},
|
|
2207
|
+
...args.description !== undefined ? { description: args.description } : {},
|
|
2208
|
+
...args.assignee !== undefined ? { assignee: args.assignee.trim() } : {},
|
|
2209
|
+
...args.status !== undefined ? { status: args.status } : {},
|
|
2210
|
+
...args.dueDate !== undefined ? { dueDate: args.dueDate.trim() } : {},
|
|
2211
|
+
...args.participants !== undefined ? { participants: args.participants.map((name) => name.trim()) } : {},
|
|
2212
|
+
...args.conclusion !== undefined ? { conclusion: args.conclusion } : {},
|
|
2213
|
+
...args.steps !== undefined ? { steps: readSteps2(args.steps) } : {}
|
|
2214
|
+
};
|
|
2215
|
+
}
|
|
2216
|
+
function formatTasks(tasks) {
|
|
2217
|
+
if (!tasks.length)
|
|
2218
|
+
return "no tasks";
|
|
2219
|
+
return tasks.map((task) => {
|
|
2220
|
+
const steps = displaySteps(task.steps);
|
|
2221
|
+
const done = steps.filter((step) => step.done).length;
|
|
2222
|
+
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 ? `
|
|
2223
|
+
${task.description}` : ""}` + `${steps.length ? `
|
|
2224
|
+
steps: ${done}/${steps.length}${steps.map((step) => `
|
|
2225
|
+
- [${step.done ? "x" : " "}] ${step.text}`).join("")}` : ""}` + `${task.conclusion ? `
|
|
2226
|
+
conclusion: ${task.conclusion}` : ""}`;
|
|
2227
|
+
}).join(`
|
|
2228
|
+
`);
|
|
2229
|
+
}
|
|
2230
|
+
function failure(error, status, action) {
|
|
2231
|
+
if (status === 404) {
|
|
2232
|
+
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`;
|
|
2233
|
+
}
|
|
2234
|
+
if (status === 403 && (action === "task_list" || action === "task_create"))
|
|
2235
|
+
return NOT_JOINED;
|
|
2236
|
+
if (status === 403)
|
|
2237
|
+
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`;
|
|
2238
|
+
return `error: ${error}`;
|
|
2239
|
+
}
|
|
2240
|
+
async function runTaskTool(args, sessionID) {
|
|
2241
|
+
if (!args.action.startsWith("task_"))
|
|
2242
|
+
return;
|
|
2243
|
+
if (!args.roomId)
|
|
2244
|
+
return "error: roomId is required; use a room UUID from the room list, not the room name";
|
|
2245
|
+
if (args.action === "task_list") {
|
|
2246
|
+
const result = await listTasks(args.roomId, sessionID);
|
|
2247
|
+
return "error" in result ? failure(result.error, result.status, args.action) : formatTasks(result.tasks);
|
|
2248
|
+
}
|
|
2249
|
+
if (args.action === "task_create") {
|
|
2250
|
+
const error = validateTaskFields(args, true);
|
|
2251
|
+
if (error)
|
|
2252
|
+
return `error: ${error}`;
|
|
2253
|
+
const result = await createTask(args.roomId, sessionID, taskFields(args));
|
|
2254
|
+
return "error" in result ? failure(result.error, result.status, args.action) : `task created: ${result.task.title} (id: ${result.task.id}, status: ${result.task.status})`;
|
|
2255
|
+
}
|
|
2256
|
+
if (!args.taskId)
|
|
2257
|
+
return "error: taskId is required; run task_list to get a task ID";
|
|
2258
|
+
if (args.action === "task_delete") {
|
|
2259
|
+
const result = await deleteTask(args.roomId, args.taskId, sessionID);
|
|
2260
|
+
return "error" in result ? failure(result.error, result.status, args.action) : `task deleted: ${args.taskId}`;
|
|
2261
|
+
}
|
|
2262
|
+
if (args.action !== "task_update")
|
|
2263
|
+
return "error: unsupported task action";
|
|
2264
|
+
const error = validateTaskFields(args, false);
|
|
2265
|
+
if (error)
|
|
2266
|
+
return `error: ${error}`;
|
|
2267
|
+
if (!EDIT_KEYS.some((field) => args[field] !== undefined))
|
|
2268
|
+
return `error: at least one of ${EDIT_KEYS.join(", ")} is required to update a task`;
|
|
2269
|
+
const result = await updateTask(args.roomId, args.taskId, sessionID, taskFields(args));
|
|
2270
|
+
return "error" in result ? failure(result.error, result.status, args.action) : `task updated: ${result.task.title} (id: ${result.task.id}, status: ${result.task.status})`;
|
|
2271
|
+
}
|
|
2272
|
+
var EDIT_KEYS, MAX_STEPS2 = 30, NOT_JOINED = "error: not joined; call join for this room first, and wait for approval if required";
|
|
2273
|
+
var init_task_tool = __esm(() => {
|
|
2274
|
+
init_tasks();
|
|
2275
|
+
EDIT_KEYS = ["title", "description", "assignee", "status", "dueDate", "participants", "conclusion", "steps"];
|
|
2276
|
+
});
|
|
2277
|
+
|
|
1837
2278
|
// src/center/queue-transport.ts
|
|
1838
2279
|
function backgroundResult(value) {
|
|
1839
2280
|
return typeof value === "boolean" ? value ? { status: "done" } : { status: "failed", reason: "unclassified-failure" } : value;
|
|
@@ -2166,6 +2607,49 @@ ${result.announcement.content}`;
|
|
|
2166
2607
|
await request(opts, path, "DELETE", { sessionID });
|
|
2167
2608
|
return `announcement deleted: ${args.announcementName}`;
|
|
2168
2609
|
}
|
|
2610
|
+
case "task_list": {
|
|
2611
|
+
if (!args.roomId)
|
|
2612
|
+
return "error: roomId is required; use a room UUID from the room list, not the room name";
|
|
2613
|
+
const result = await request(opts, `/rooms/${encodeURIComponent(args.roomId)}/tasks?sessionID=${encodeURIComponent(sessionID)}`, "GET");
|
|
2614
|
+
return formatTasks(Array.isArray(result.tasks) ? result.tasks : []);
|
|
2615
|
+
}
|
|
2616
|
+
case "task_create": {
|
|
2617
|
+
if (!args.roomId)
|
|
2618
|
+
return "error: roomId is required; use a room UUID from the room list, not the room name";
|
|
2619
|
+
const error = validateTaskFields(args, true);
|
|
2620
|
+
if (error)
|
|
2621
|
+
return `error: ${error}`;
|
|
2622
|
+
const result = await request(opts, `/rooms/${encodeURIComponent(args.roomId)}/tasks`, "POST", {
|
|
2623
|
+
sessionID,
|
|
2624
|
+
...taskFields(args)
|
|
2625
|
+
});
|
|
2626
|
+
return `task created: ${result.task.title} (id: ${result.task.id}, status: ${result.task.status})`;
|
|
2627
|
+
}
|
|
2628
|
+
case "task_update": {
|
|
2629
|
+
if (!args.roomId)
|
|
2630
|
+
return "error: roomId is required; use a room UUID from the room list, not the room name";
|
|
2631
|
+
if (!args.taskId)
|
|
2632
|
+
return "error: taskId is required; run task_list to get a task ID";
|
|
2633
|
+
const error = validateTaskFields(args, false);
|
|
2634
|
+
if (error)
|
|
2635
|
+
return `error: ${error}`;
|
|
2636
|
+
const fields = taskFields(args);
|
|
2637
|
+
if (!Object.keys(fields).length)
|
|
2638
|
+
return "error: at least one of title, description, assignee, status, dueDate, participants, conclusion, or steps is required to update a task";
|
|
2639
|
+
const result = await request(opts, `/rooms/${encodeURIComponent(args.roomId)}/tasks/${encodeURIComponent(args.taskId)}`, "PATCH", {
|
|
2640
|
+
sessionID,
|
|
2641
|
+
...fields
|
|
2642
|
+
});
|
|
2643
|
+
return `task updated: ${result.task.title} (id: ${result.task.id}, status: ${result.task.status})`;
|
|
2644
|
+
}
|
|
2645
|
+
case "task_delete": {
|
|
2646
|
+
if (!args.roomId)
|
|
2647
|
+
return "error: roomId is required; use a room UUID from the room list, not the room name";
|
|
2648
|
+
if (!args.taskId)
|
|
2649
|
+
return "error: taskId is required; run task_list to get a task ID";
|
|
2650
|
+
await request(opts, `/rooms/${encodeURIComponent(args.roomId)}/tasks/${encodeURIComponent(args.taskId)}`, "DELETE", { sessionID });
|
|
2651
|
+
return `task deleted: ${args.taskId}`;
|
|
2652
|
+
}
|
|
2169
2653
|
case "send": {
|
|
2170
2654
|
if (!args.roomId) {
|
|
2171
2655
|
return "error: roomId is required; use a room UUID from the room list, not the room name";
|
|
@@ -2239,6 +2723,7 @@ var init_center_client = __esm(() => {
|
|
|
2239
2723
|
init_store();
|
|
2240
2724
|
init_queue();
|
|
2241
2725
|
init_session_delivery();
|
|
2726
|
+
init_task_tool();
|
|
2242
2727
|
init_queue();
|
|
2243
2728
|
init_queue_transport();
|
|
2244
2729
|
});
|
|
@@ -2499,7 +2984,7 @@ var init_file_config = __esm(() => {
|
|
|
2499
2984
|
});
|
|
2500
2985
|
|
|
2501
2986
|
// src/agent/agent-presence.ts
|
|
2502
|
-
import { randomUUID as
|
|
2987
|
+
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
2503
2988
|
function locallyOwnedSessions(registry, ownerID) {
|
|
2504
2989
|
return new Set(Object.values(registry).flatMap((entries) => Object.entries(entries).filter(([, entry]) => entry.protocol === "v2" && entry.receiverOwnerID === ownerID).map(([id]) => id)));
|
|
2505
2990
|
}
|
|
@@ -2509,7 +2994,7 @@ async function reportAgentPresence(input) {
|
|
|
2509
2994
|
return;
|
|
2510
2995
|
const target = input.center.center ? new URL(input.center.center).origin : "standalone";
|
|
2511
2996
|
const key = `presence:${input.ownerID}:${target}`;
|
|
2512
|
-
const holder =
|
|
2997
|
+
const holder = randomUUID6();
|
|
2513
2998
|
const now = Date.now();
|
|
2514
2999
|
try {
|
|
2515
3000
|
if (!acquireDeliveryLease(key, holder, now, now + LEASE_MS2))
|
|
@@ -2560,7 +3045,7 @@ var init_agent_presence = __esm(() => {
|
|
|
2560
3045
|
});
|
|
2561
3046
|
|
|
2562
3047
|
// src/agent/agent-receipts.ts
|
|
2563
|
-
import { createHash as createHash3, randomUUID as
|
|
3048
|
+
import { createHash as createHash3, randomUUID as randomUUID7 } from "node:crypto";
|
|
2564
3049
|
import path6 from "node:path";
|
|
2565
3050
|
function hasCappedMetadata(item) {
|
|
2566
3051
|
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 +3150,7 @@ function flushReceiptCandidates(input) {
|
|
|
2665
3150
|
}
|
|
2666
3151
|
async function flushOneReceiptCandidate(input, cursorKey) {
|
|
2667
3152
|
const leaseKey = `receipt-flush:${hash(cursorKey)}`;
|
|
2668
|
-
const holder =
|
|
3153
|
+
const holder = randomUUID7(), now = Date.now();
|
|
2669
3154
|
if (!acquireDeliveryLease(leaseKey, holder, now, now + RECEIPT_FLUSH_LEASE_MS))
|
|
2670
3155
|
return;
|
|
2671
3156
|
try {
|
|
@@ -3502,7 +3987,7 @@ var init_chatroom_skill = __esm(() => {
|
|
|
3502
3987
|
});
|
|
3503
3988
|
|
|
3504
3989
|
// src/agent/admin-credentials.ts
|
|
3505
|
-
import { createHash as createHash5, randomUUID as
|
|
3990
|
+
import { createHash as createHash5, randomUUID as randomUUID8 } from "node:crypto";
|
|
3506
3991
|
import { mkdir, readFile, rename, chmod, writeFile, rm } from "node:fs/promises";
|
|
3507
3992
|
import path9 from "node:path";
|
|
3508
3993
|
function credentialPath(identity) {
|
|
@@ -3512,7 +3997,7 @@ async function persist(file, content) {
|
|
|
3512
3997
|
const directory = path9.dirname(file);
|
|
3513
3998
|
await mkdir(directory, { recursive: true, mode: 448 });
|
|
3514
3999
|
await chmod(directory, 448);
|
|
3515
|
-
const temporary = `${file}.${
|
|
4000
|
+
const temporary = `${file}.${randomUUID8()}.tmp`;
|
|
3516
4001
|
try {
|
|
3517
4002
|
await writeFile(temporary, JSON.stringify(content), { mode: 384, flag: "wx" });
|
|
3518
4003
|
await chmod(temporary, 384);
|
|
@@ -3752,7 +4237,7 @@ function createV2Setup(deps) {
|
|
|
3752
4237
|
});
|
|
3753
4238
|
toolRegistration = await context.tool.transform((editor) => editor.add({
|
|
3754
4239
|
name: "room",
|
|
3755
|
-
description: "Chat room operations: create, join, join_status, leave and list rooms; send and poll messages; list members and
|
|
4240
|
+
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
4241
|
options: { codemode: false },
|
|
3757
4242
|
input: roomSchema(),
|
|
3758
4243
|
execute: async (args, toolContext) => {
|
|
@@ -3851,7 +4336,7 @@ The user invoked /room. Use the room tool to perform this command.`,
|
|
|
3851
4336
|
}
|
|
3852
4337
|
function roomSchema() {
|
|
3853
4338
|
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"]),
|
|
4339
|
+
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
4340
|
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
4341
|
roomId: z2.string().optional(),
|
|
3857
4342
|
resourceId: z2.string().optional(),
|
|
@@ -3860,6 +4345,15 @@ function roomSchema() {
|
|
|
3860
4345
|
isQuestion: z2.boolean().optional(),
|
|
3861
4346
|
announcementName: z2.string().optional().describe("Name of a room announcement; distinct from participant or room name."),
|
|
3862
4347
|
content: z2.string().optional().describe("Announcement content, at most 5000 Unicode characters."),
|
|
4348
|
+
taskId: z2.string().optional().describe("Task UUID from task_list; required for task_update and task_delete."),
|
|
4349
|
+
title: z2.string().optional().describe("Task title, 1 to 200 characters; required for task_create."),
|
|
4350
|
+
description: z2.string().optional().describe("Task description, at most 5000 characters."),
|
|
4351
|
+
assignee: z2.string().optional().describe("Participant display name responsible for the task; empty leaves it unassigned."),
|
|
4352
|
+
status: z2.enum(["todo", "doing", "done"]).optional().describe("Task status; the assignee may change only this field."),
|
|
4353
|
+
dueDate: z2.string().optional().describe("Task due date as YYYY-MM-DD; empty clears it."),
|
|
4354
|
+
participants: z2.array(z2.string()).optional().describe("Task participants as room participant display names; empty clears them."),
|
|
4355
|
+
conclusion: z2.string().optional().describe("Task conclusion, at most 5000 characters; empty clears it."),
|
|
4356
|
+
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
4357
|
reminderId: z2.string().optional(),
|
|
3864
4358
|
schedule: z2.discriminatedUnion("type", [z2.object({ type: z2.literal("once"), at: z2.string(), timezone: z2.string().refine((value) => {
|
|
3865
4359
|
try {
|
|
@@ -4102,7 +4596,7 @@ var init_resource_upload = () => {};
|
|
|
4102
4596
|
|
|
4103
4597
|
// src/rooms/resource-read.ts
|
|
4104
4598
|
import { promises as fs3 } from "node:fs";
|
|
4105
|
-
import { randomUUID as
|
|
4599
|
+
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
4106
4600
|
import os7 from "node:os";
|
|
4107
4601
|
import path11 from "node:path";
|
|
4108
4602
|
function resourceReadFailure(error) {
|
|
@@ -4164,7 +4658,7 @@ async function saveResource(permission, headers, endpoint, resource, allowed, si
|
|
|
4164
4658
|
await ask(permission, "external_directory", [tmp], { filepath: tmp });
|
|
4165
4659
|
const directory = await fs3.mkdtemp(path11.join(tmp, "opencode-chat-room-"));
|
|
4166
4660
|
const extension = path11.extname(resource.name).toLowerCase();
|
|
4167
|
-
const filename = `${
|
|
4661
|
+
const filename = `${randomUUID9()}${/^\.[a-z0-9]{1,10}$/.test(extension) ? extension : ".bin"}`;
|
|
4168
4662
|
const filepath = path11.join(directory, filename);
|
|
4169
4663
|
try {
|
|
4170
4664
|
await fs3.chmod(directory, 448);
|
|
@@ -4567,6 +5061,9 @@ var connection, centerUrl, centerToken, serveWakeUrl, runtimeContext, defaultRun
|
|
|
4567
5061
|
const announcementResult = await runAnnouncementTool(args, context.sessionID);
|
|
4568
5062
|
if (announcementResult !== undefined)
|
|
4569
5063
|
return announcementResult;
|
|
5064
|
+
const taskResult = await runTaskTool(args, context.sessionID);
|
|
5065
|
+
if (taskResult !== undefined)
|
|
5066
|
+
return taskResult;
|
|
4570
5067
|
let selfName = identity();
|
|
4571
5068
|
let joinPrevName;
|
|
4572
5069
|
let joinPrevShared = false;
|
|
@@ -4729,6 +5226,7 @@ var init_plugin = __esm(() => {
|
|
|
4729
5226
|
init_v2_plugin();
|
|
4730
5227
|
init_v1_plugin();
|
|
4731
5228
|
init_announcement_tool();
|
|
5229
|
+
init_task_tool();
|
|
4732
5230
|
init_resource_upload();
|
|
4733
5231
|
init_resource_read();
|
|
4734
5232
|
init_admin_client();
|
|
@@ -4752,9 +5250,9 @@ var init_plugin = __esm(() => {
|
|
|
4752
5250
|
});
|
|
4753
5251
|
({ notifyRoom, notifyTarget } = notifier);
|
|
4754
5252
|
restoreScans2 = new Map;
|
|
4755
|
-
READ_ONLY_ACTIONS = new Set(["list", "members", "poll", "join_status", "announcement_list", "announcement_read"]);
|
|
5253
|
+
READ_ONLY_ACTIONS = new Set(["list", "members", "poll", "join_status", "announcement_list", "announcement_read", "task_list"]);
|
|
4756
5254
|
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"]),
|
|
5255
|
+
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
5256
|
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
5257
|
roomId: z3.string().optional().describe("Room UUID, not the room name. Required for resource actions and every room-scoped action."),
|
|
4760
5258
|
messageId: z3.string().optional().describe("For recall: the full message ID returned by send or poll; required for recall."),
|
|
@@ -4764,6 +5262,15 @@ var init_plugin = __esm(() => {
|
|
|
4764
5262
|
isQuestion: z3.boolean().optional().describe("For send: mark the message as a question awaiting an answer."),
|
|
4765
5263
|
announcementName: z3.string().optional().describe("Exact announcement name from announcement_list; distinct from participant or room name."),
|
|
4766
5264
|
content: z3.string().optional().describe("Announcement content, at most 5000 Unicode characters; required for announcement_write."),
|
|
5265
|
+
taskId: z3.string().optional().describe("Task UUID from task_list; required for task_update and task_delete."),
|
|
5266
|
+
title: z3.string().optional().describe("Task title, 1 to 200 characters; required for task_create."),
|
|
5267
|
+
description: z3.string().optional().describe("Task description, at most 5000 characters."),
|
|
5268
|
+
assignee: z3.string().optional().describe("Participant display name responsible for the task; empty leaves it unassigned."),
|
|
5269
|
+
status: z3.enum(["todo", "doing", "done"]).optional().describe("Task status; the assignee may change only this field."),
|
|
5270
|
+
dueDate: z3.string().optional().describe("Task due date as YYYY-MM-DD; empty clears it."),
|
|
5271
|
+
participants: z3.array(z3.string()).optional().describe("Task participants as room participant display names; empty clears them."),
|
|
5272
|
+
conclusion: z3.string().optional().describe("Task conclusion, at most 5000 characters; empty clears it."),
|
|
5273
|
+
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
5274
|
reminderId: z3.string().optional().describe("Reminder UUID from reminder_list; required for reminder_update and reminder_delete."),
|
|
4768
5275
|
schedule: z3.discriminatedUnion("type", [z3.object({ type: z3.literal("once"), at: z3.string(), timezone: z3.string().refine((value) => {
|
|
4769
5276
|
try {
|
|
@@ -4788,7 +5295,7 @@ var init_plugin = __esm(() => {
|
|
|
4788
5295
|
}
|
|
4789
5296
|
});
|
|
4790
5297
|
room = tool({
|
|
4791
|
-
description: 'Chat room operations: create, join, leave and list rooms; send, poll and recall messages; list members and
|
|
5298
|
+
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
5299
|
args: roomArgs.shape,
|
|
4793
5300
|
execute: roomExecute
|
|
4794
5301
|
});
|
|
@@ -5661,7 +6168,7 @@ var init_message_recall_routes = __esm(() => {
|
|
|
5661
6168
|
|
|
5662
6169
|
// server/admin-state.ts
|
|
5663
6170
|
import { Buffer as Buffer4 } from "node:buffer";
|
|
5664
|
-
import { createHash as createHash7, randomBytes as randomBytes2, randomUUID as
|
|
6171
|
+
import { createHash as createHash7, randomBytes as randomBytes2, randomUUID as randomUUID10, timingSafeEqual as timingSafeEqual2 } from "node:crypto";
|
|
5665
6172
|
function matchesHash(value, stored) {
|
|
5666
6173
|
const left = Buffer4.from(hash2(value), "hex"), right = Buffer4.from(stored, "hex");
|
|
5667
6174
|
return right.length === 32 && timingSafeEqual2(left, right);
|
|
@@ -5851,7 +6358,7 @@ var init_admin_auth = __esm(() => {
|
|
|
5851
6358
|
});
|
|
5852
6359
|
|
|
5853
6360
|
// src/rooms/resources.ts
|
|
5854
|
-
import { randomUUID as
|
|
6361
|
+
import { randomUUID as randomUUID11 } from "node:crypto";
|
|
5855
6362
|
import { promises as fs4 } from "node:fs";
|
|
5856
6363
|
import path13 from "node:path";
|
|
5857
6364
|
function maxResourceBytes() {
|
|
@@ -5925,8 +6432,8 @@ async function uploadResource(roomID, filename, body, limitBytes, uploader, requ
|
|
|
5925
6432
|
}
|
|
5926
6433
|
const dir = roomDirectory(roomID);
|
|
5927
6434
|
await fs4.mkdir(dir, { recursive: true, mode: 448 });
|
|
5928
|
-
const id = requestedID ??
|
|
5929
|
-
const temp = path13.join(dir, `${id}.${
|
|
6435
|
+
const id = requestedID ?? randomUUID11();
|
|
6436
|
+
const temp = path13.join(dir, `${id}.${randomUUID11()}.tmp`);
|
|
5930
6437
|
const dest = resourcePath({ id, roomID });
|
|
5931
6438
|
let handle;
|
|
5932
6439
|
let linked = false;
|
|
@@ -6399,25 +6906,88 @@ var init_announcement_routes = __esm(() => {
|
|
|
6399
6906
|
init_store();
|
|
6400
6907
|
});
|
|
6401
6908
|
|
|
6909
|
+
// server/task-routes.ts
|
|
6910
|
+
function sessionID(value) {
|
|
6911
|
+
return typeof value === "string" && value.length > 0 && value.length <= MAX_SESSION2 ? value : undefined;
|
|
6912
|
+
}
|
|
6913
|
+
async function taskRoutes(req, url) {
|
|
6914
|
+
const collection = url.pathname.match(/^\/rooms\/([^/]+)\/tasks$/);
|
|
6915
|
+
const item = url.pathname.match(/^\/rooms\/([^/]+)\/tasks\/([^/]+)$/);
|
|
6916
|
+
if (!collection && !item)
|
|
6917
|
+
return;
|
|
6918
|
+
let roomID, taskID;
|
|
6919
|
+
try {
|
|
6920
|
+
roomID = decodeURIComponent((collection ?? item)[1]);
|
|
6921
|
+
taskID = item ? decodeURIComponent(item[2]) : undefined;
|
|
6922
|
+
} catch {
|
|
6923
|
+
return json4({ error: "invalid path" }, 400);
|
|
6924
|
+
}
|
|
6925
|
+
if (collection) {
|
|
6926
|
+
if (req.method === "GET") {
|
|
6927
|
+
const session = sessionID(url.searchParams.get("sessionID"));
|
|
6928
|
+
if (!session)
|
|
6929
|
+
return json4({ error: "sessionID is required" }, 400);
|
|
6930
|
+
const result = await listTasks(roomID, session);
|
|
6931
|
+
return "error" in result ? json4({ error: result.error }, result.status) : json4({ tasks: result.tasks });
|
|
6932
|
+
}
|
|
6933
|
+
if (req.method !== "POST" && req.method !== "DELETE")
|
|
6934
|
+
return json4({ error: "method not allowed" }, 405);
|
|
6935
|
+
const body = await jsonObject(req);
|
|
6936
|
+
if (!body)
|
|
6937
|
+
return json4({ error: "JSON object body is required" }, 400);
|
|
6938
|
+
const session = sessionID(body.sessionID);
|
|
6939
|
+
if (!session)
|
|
6940
|
+
return json4({ error: "sessionID is required" }, 400);
|
|
6941
|
+
if (req.method === "DELETE") {
|
|
6942
|
+
const result = await clearCompletedTasks(roomID, session);
|
|
6943
|
+
return "error" in result ? json4({ error: result.error }, result.status) : json4({ ok: true, count: result.count });
|
|
6944
|
+
}
|
|
6945
|
+
const fields = { title: body.title, description: body.description, assignee: body.assignee, dueDate: body.dueDate, participants: body.participants, conclusion: body.conclusion, steps: body.steps };
|
|
6946
|
+
const result = await createTask(roomID, session, fields);
|
|
6947
|
+
return "error" in result ? json4({ error: result.error }, result.status) : json4({ task: result.task }, 201);
|
|
6948
|
+
}
|
|
6949
|
+
if (req.method !== "PATCH" && req.method !== "DELETE")
|
|
6950
|
+
return json4({ error: "method not allowed" }, 405);
|
|
6951
|
+
const body = await jsonObject(req);
|
|
6952
|
+
if (!body)
|
|
6953
|
+
return json4({ error: "JSON object body is required" }, 400);
|
|
6954
|
+
const session = sessionID(body.sessionID);
|
|
6955
|
+
if (!session)
|
|
6956
|
+
return json4({ error: "sessionID is required" }, 400);
|
|
6957
|
+
if (req.method === "DELETE") {
|
|
6958
|
+
const result = await deleteTask(roomID, taskID, session);
|
|
6959
|
+
return "error" in result ? json4({ error: result.error }, result.status) : json4({ ok: true });
|
|
6960
|
+
}
|
|
6961
|
+
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 });
|
|
6962
|
+
return "error" in result ? json4({ error: result.error }, result.status) : json4({ task: result.task });
|
|
6963
|
+
}
|
|
6964
|
+
var json4 = (body, status = 200) => Response.json(body, { status }), MAX_SESSION2 = 128;
|
|
6965
|
+
var init_task_routes = __esm(() => {
|
|
6966
|
+
init_tasks();
|
|
6967
|
+
});
|
|
6968
|
+
|
|
6402
6969
|
// server/member-routes.ts
|
|
6403
6970
|
function object2(value) {
|
|
6404
6971
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6405
6972
|
}
|
|
6406
6973
|
async function memberRoutes(req, url) {
|
|
6974
|
+
const tasks = await taskRoutes(req, url);
|
|
6975
|
+
if (tasks)
|
|
6976
|
+
return tasks;
|
|
6407
6977
|
const announcements = await announcementRoutes(req, url);
|
|
6408
6978
|
if (announcements)
|
|
6409
6979
|
return announcements;
|
|
6410
6980
|
if (req.method === "POST" && url.pathname === "/read") {
|
|
6411
6981
|
const body = await jsonObject(req);
|
|
6412
6982
|
if (!body)
|
|
6413
|
-
return
|
|
6983
|
+
return json5({ error: "JSON object body is required" }, 400);
|
|
6414
6984
|
const ts = body.ts;
|
|
6415
6985
|
const roomId = String(body.roomId ?? "");
|
|
6416
6986
|
const sessionID = String(body.sessionID ?? "");
|
|
6417
6987
|
const messageIDs = body.messageIDs;
|
|
6418
6988
|
const hasReceipts = messageIDs !== undefined;
|
|
6419
6989
|
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
|
|
6990
|
+
return json5({ error: "invalid read acknowledgement" }, 400);
|
|
6421
6991
|
}
|
|
6422
6992
|
if (hasReceipts) {
|
|
6423
6993
|
const result = await acknowledgeReadWithReceipts(roomId, sessionID, ts, messageIDs, body.evidence, {
|
|
@@ -6425,45 +6995,45 @@ async function memberRoutes(req, url) {
|
|
|
6425
6995
|
...typeof body.receiverOwnerID === "string" ? { receiverOwnerID: body.receiverOwnerID } : {}
|
|
6426
6996
|
});
|
|
6427
6997
|
if (result.status === "membership")
|
|
6428
|
-
return
|
|
6998
|
+
return json5({ error: "membership generation mismatch" }, 409);
|
|
6429
6999
|
if (result.status === "messageIDs")
|
|
6430
|
-
return
|
|
7000
|
+
return json5({ error: "message IDs do not belong to this room" }, 400);
|
|
6431
7001
|
if (result.status !== "ok")
|
|
6432
|
-
return
|
|
7002
|
+
return json5({ error: "read acknowledgement rejected" }, 400);
|
|
6433
7003
|
clearPendingAdmission(sessionID, roomId, result.readThroughTs ?? 0);
|
|
6434
7004
|
touchActive(sessionID);
|
|
6435
|
-
return
|
|
7005
|
+
return json5({ ok: true, acceptedIDs: result.acceptedIDs });
|
|
6436
7006
|
}
|
|
6437
7007
|
const actualTs = await acknowledgeRead2(roomId, sessionID, ts);
|
|
6438
7008
|
if (actualTs === null)
|
|
6439
|
-
return
|
|
7009
|
+
return json5({ error: "registry entry not found" }, 404);
|
|
6440
7010
|
clearPendingAdmission(sessionID, roomId, actualTs);
|
|
6441
7011
|
touchActive(sessionID);
|
|
6442
|
-
return
|
|
7012
|
+
return json5({ ok: true });
|
|
6443
7013
|
}
|
|
6444
7014
|
const receiptRoute = url.pathname.match(/^\/rooms\/([^/]+)\/receipts$/);
|
|
6445
7015
|
if (req.method === "POST" && receiptRoute) {
|
|
6446
7016
|
const body = await req.json();
|
|
6447
7017
|
if (!object2(body))
|
|
6448
|
-
return
|
|
7018
|
+
return json5({ error: "JSON object body is required" }, 400);
|
|
6449
7019
|
const { sessionID, membershipID, evidence } = body;
|
|
6450
7020
|
const ids = body.messageIDs;
|
|
6451
7021
|
const ownerID = body.receiverOwnerID;
|
|
6452
7022
|
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
|
|
7023
|
+
return json5({ error: "invalid message receipt" }, 400);
|
|
6454
7024
|
const identity = { membershipID, ...typeof ownerID === "string" ? { receiverOwnerID: ownerID } : {} };
|
|
6455
7025
|
const result = await recordMessageReceipts(decodeURIComponent(receiptRoute[1]), sessionID, ids, evidence, identity);
|
|
6456
7026
|
if (result.status === "membership")
|
|
6457
|
-
return
|
|
7027
|
+
return json5({ error: "membership generation mismatch" }, 409);
|
|
6458
7028
|
if (result.status === "messageIDs")
|
|
6459
|
-
return
|
|
6460
|
-
return
|
|
7029
|
+
return json5({ error: "message IDs do not belong to this room" }, 400);
|
|
7030
|
+
return json5({ acceptedIDs: result.acceptedIDs });
|
|
6461
7031
|
}
|
|
6462
7032
|
const match = url.pathname.match(/^\/rooms\/([^/]+)\/(members|receipts)$/);
|
|
6463
7033
|
if (req.method === "GET" && match) {
|
|
6464
7034
|
const roomID = decodeURIComponent(match[1]);
|
|
6465
7035
|
if (match[2] === "members")
|
|
6466
|
-
return
|
|
7036
|
+
return json5(await readState2((svc, registry) => {
|
|
6467
7037
|
svc.getRoom(roomID);
|
|
6468
7038
|
return Object.entries(registry[roomID] ?? {}).map(([sessionID, entry]) => ({
|
|
6469
7039
|
sessionID,
|
|
@@ -6482,25 +7052,25 @@ async function memberRoutes(req, url) {
|
|
|
6482
7052
|
const filter = url.searchParams.get("messageIDs");
|
|
6483
7053
|
const ids = filter === null ? undefined : filter.split(",");
|
|
6484
7054
|
if (ids && (!ids.length || ids.length > 500 || ids.some((id) => !id || id.length > 128)))
|
|
6485
|
-
return
|
|
7055
|
+
return json5({ error: "invalid message IDs" }, 400);
|
|
6486
7056
|
const receipts = await readReceipts(roomID, ids);
|
|
6487
7057
|
if (!receipts)
|
|
6488
|
-
return
|
|
6489
|
-
return
|
|
7058
|
+
return json5({ error: "message IDs do not belong to this room" }, 400);
|
|
7059
|
+
return json5({ receipts: receipts.map((item) => ({ messageID: item.messageID, readers: item.readers.map((reader) => ({ ...reader, currentMember: Boolean(registry[reader.sessionID]) })) })), semantics: "per-message" });
|
|
6490
7060
|
}
|
|
6491
7061
|
if (req.method !== "POST" || url.pathname !== "/presence")
|
|
6492
7062
|
return;
|
|
6493
7063
|
const body = await req.json();
|
|
6494
7064
|
if (!object2(body) || !Array.isArray(body.sessions) || body.sessions.length > 200)
|
|
6495
|
-
return
|
|
7065
|
+
return json5({ error: "sessions must be an array of at most 200 reports" }, 400);
|
|
6496
7066
|
const ownerID = body.ownerID;
|
|
6497
7067
|
const sequence = body.sequence;
|
|
6498
7068
|
if (ownerID !== undefined && !isReceiverOwnerID(ownerID) || ownerID === undefined && sequence !== undefined || ownerID !== undefined && (typeof sequence !== "number" || !Number.isSafeInteger(sequence) || sequence <= 0))
|
|
6499
|
-
return
|
|
7069
|
+
return json5({ error: "invalid owner sequence" }, 400);
|
|
6500
7070
|
const reports = new Map;
|
|
6501
7071
|
for (const item of body.sessions) {
|
|
6502
7072
|
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
|
|
7073
|
+
return json5({ error: "invalid presence report" }, 400);
|
|
6504
7074
|
reports.set(item.sessionID, {
|
|
6505
7075
|
sessionID: item.sessionID,
|
|
6506
7076
|
state: item.state,
|
|
@@ -6508,15 +7078,16 @@ async function memberRoutes(req, url) {
|
|
|
6508
7078
|
});
|
|
6509
7079
|
}
|
|
6510
7080
|
const result = await reportPresence([...reports.values()], ownerID, sequence);
|
|
6511
|
-
return
|
|
7081
|
+
return json5({ updatedSessionIDs: result.stale ? [] : result.updatedSessionIDs });
|
|
6512
7082
|
}
|
|
6513
|
-
var
|
|
7083
|
+
var json5 = (body, status = 200) => Response.json(body, { status }), states;
|
|
6514
7084
|
var init_member_routes = __esm(() => {
|
|
6515
7085
|
init_store();
|
|
6516
7086
|
init_receiver_owner();
|
|
6517
7087
|
init_queue();
|
|
6518
7088
|
init_wake();
|
|
6519
7089
|
init_announcement_routes();
|
|
7090
|
+
init_task_routes();
|
|
6520
7091
|
states = new Set(["working", "idle", "waiting", "unknown"]);
|
|
6521
7092
|
});
|
|
6522
7093
|
|
|
@@ -6546,63 +7117,63 @@ async function resourceRoutes(req, url) {
|
|
|
6546
7117
|
const sessionID = req.headers.get("x-session-id") ?? "";
|
|
6547
7118
|
const entry = await readState2((_svc, registry) => registry[roomID]?.[sessionID]);
|
|
6548
7119
|
if (!entry)
|
|
6549
|
-
return
|
|
7120
|
+
return json6({ error: "forbidden" }, 403);
|
|
6550
7121
|
const rawLimit = Number(url.searchParams.get("limit") ?? 500);
|
|
6551
7122
|
const rawOffset = Number(url.searchParams.get("offset") ?? 0);
|
|
6552
7123
|
const limit = Number.isSafeInteger(rawLimit) ? Math.min(1000, Math.max(1, rawLimit)) : 500;
|
|
6553
7124
|
const offset = Number.isSafeInteger(rawOffset) ? Math.max(0, rawOffset) : 0;
|
|
6554
7125
|
const page = await listRoomResources(roomID, limit, offset);
|
|
6555
|
-
return
|
|
7126
|
+
return json6({ resources: page.items, total: page.total, limit, offset }, 200);
|
|
6556
7127
|
}
|
|
6557
7128
|
if (upload) {
|
|
6558
7129
|
const sessionID = req.headers.get("x-session-id") ?? "";
|
|
6559
7130
|
const entry = await readState2((_svc, registry) => registry[roomID]?.[sessionID]);
|
|
6560
7131
|
if (!entry)
|
|
6561
|
-
return
|
|
7132
|
+
return json6({ error: "forbidden" }, 403);
|
|
6562
7133
|
const encoded = req.headers.get("x-file-name");
|
|
6563
7134
|
if (!encoded)
|
|
6564
|
-
return
|
|
7135
|
+
return json6({ error: "invalid filename" }, 400);
|
|
6565
7136
|
let filename;
|
|
6566
7137
|
try {
|
|
6567
7138
|
filename = decodeURIComponent(encoded);
|
|
6568
7139
|
} catch {
|
|
6569
|
-
return
|
|
7140
|
+
return json6({ error: "invalid filename" }, 400);
|
|
6570
7141
|
}
|
|
6571
7142
|
if (!filename || filename.length > 255 || /[\\/\r\n\0]/.test(filename) || filename === "." || filename === "..")
|
|
6572
|
-
return
|
|
7143
|
+
return json6({ error: "invalid filename" }, 400);
|
|
6573
7144
|
const requestedID = req.headers.get("x-resource-id");
|
|
6574
7145
|
if (requestedID !== null && !uuid3.test(requestedID))
|
|
6575
|
-
return
|
|
7146
|
+
return json6({ error: "invalid resource id" }, 400);
|
|
6576
7147
|
const resource = await uploadResource(roomID, filename, req.body ?? new Blob([]).stream(), maxResourceBytes(), { sessionID, name: entry.name }, requestedID ?? undefined);
|
|
6577
|
-
return
|
|
7148
|
+
return json6({ resource }, 201);
|
|
6578
7149
|
}
|
|
6579
7150
|
const id = decodeURIComponent(item[2]);
|
|
6580
7151
|
if (!uuid3.test(id))
|
|
6581
|
-
return
|
|
7152
|
+
return json6({ error: "resource not found" }, 404);
|
|
6582
7153
|
const resource = await findResource(roomID, id);
|
|
6583
7154
|
if (!resource)
|
|
6584
|
-
return
|
|
7155
|
+
return json6({ error: "resource not found" }, 404);
|
|
6585
7156
|
if (req.method === "DELETE") {
|
|
6586
7157
|
const sessionID = req.headers.get("x-session-id") ?? "";
|
|
6587
7158
|
const context = await readState2((svc, registry) => ({ room: svc.getRoom(roomID), entry: registry[roomID]?.[sessionID] }));
|
|
6588
7159
|
if (!context.entry)
|
|
6589
|
-
return
|
|
7160
|
+
return json6({ error: "forbidden" }, 403);
|
|
6590
7161
|
const ownAgentUpload = !isUser(context.entry) && resource.uploaderSessionID === sessionID;
|
|
6591
7162
|
if (!isRoomAdmin(context.room, context.entry) && !ownAgentUpload)
|
|
6592
|
-
return
|
|
7163
|
+
return json6({ error: "forbidden" }, 403);
|
|
6593
7164
|
await deleteResource(roomID, id);
|
|
6594
|
-
return
|
|
7165
|
+
return json6({ ok: true });
|
|
6595
7166
|
}
|
|
6596
7167
|
if (!item[3])
|
|
6597
|
-
return
|
|
7168
|
+
return json6({ resource });
|
|
6598
7169
|
return await content2(req, resource);
|
|
6599
7170
|
} catch (error) {
|
|
6600
7171
|
if (error instanceof URIError)
|
|
6601
|
-
return
|
|
7172
|
+
return json6({ error: "invalid resource request" }, 400);
|
|
6602
7173
|
const status = typeof error === "object" && error !== null && "status" in error ? Number(error.status) : 500;
|
|
6603
7174
|
if (status >= 400 && status < 500)
|
|
6604
|
-
return
|
|
6605
|
-
return
|
|
7175
|
+
return json6({ error: status === 413 ? "file exceeds maximum size" : status === 404 ? "resource not found" : status === 403 ? "forbidden" : "invalid resource request" }, status);
|
|
7176
|
+
return json6({ error: "internal server error" }, 500);
|
|
6606
7177
|
}
|
|
6607
7178
|
}
|
|
6608
7179
|
async function content2(req, resource) {
|
|
@@ -6644,7 +7215,7 @@ async function content2(req, resource) {
|
|
|
6644
7215
|
headers.set("Content-Range", `bytes ${start}-${end}/${info.size}`);
|
|
6645
7216
|
return new Response(Readable3.toWeb(createReadStream2(path, { start, end })), { status, headers });
|
|
6646
7217
|
}
|
|
6647
|
-
var
|
|
7218
|
+
var json6 = (body, status = 200) => Response.json(body, { status }), uuid3, safeHeaders;
|
|
6648
7219
|
var init_resource_routes = __esm(() => {
|
|
6649
7220
|
init_resources();
|
|
6650
7221
|
init_store();
|
|
@@ -6662,8 +7233,8 @@ async function adminRoutes(request, url) {
|
|
|
6662
7233
|
return await rootRoutes(request, url);
|
|
6663
7234
|
} catch (error) {
|
|
6664
7235
|
if (error instanceof SyntaxError || error instanceof URIError)
|
|
6665
|
-
return
|
|
6666
|
-
return
|
|
7236
|
+
return json7({ error: "invalid request" }, 400);
|
|
7237
|
+
return json7({ error: "admin request failed" }, 500);
|
|
6667
7238
|
}
|
|
6668
7239
|
}
|
|
6669
7240
|
async function rootRoutes(request, url) {
|
|
@@ -6673,13 +7244,13 @@ async function rootRoutes(request, url) {
|
|
|
6673
7244
|
return claimBinding(request, decodeURIComponent(claim[1]));
|
|
6674
7245
|
const room = path.match(/^\/admin\/rooms\/([^/]+)(?:\/(overview|history))?$/);
|
|
6675
7246
|
if (!room)
|
|
6676
|
-
return
|
|
7247
|
+
return json7({ error: "not found" }, 404);
|
|
6677
7248
|
const roomID = decodeURIComponent(room[1]);
|
|
6678
7249
|
if (request.method === "GET" && room[2] === "overview")
|
|
6679
7250
|
return overview(request, roomID);
|
|
6680
7251
|
if (request.method === "GET" && room[2] === "history")
|
|
6681
7252
|
return history(request, url, roomID);
|
|
6682
|
-
return
|
|
7253
|
+
return json7({ error: "method not allowed" }, 405);
|
|
6683
7254
|
}
|
|
6684
7255
|
function bounded(value, max) {
|
|
6685
7256
|
return typeof value === "string" && value.trim().length > 0 && value.length <= max;
|
|
@@ -6687,7 +7258,7 @@ function bounded(value, max) {
|
|
|
6687
7258
|
async function claimBinding(request, roomID) {
|
|
6688
7259
|
const body = await request.json();
|
|
6689
7260
|
if (!object3(body) || !bounded(body.sessionID, 128) || typeof body.receiverOwnerID !== "string" || body.receiverOwnerID.length > 128 || !bounded(body.enrollmentKey, 256))
|
|
6690
|
-
return
|
|
7261
|
+
return json7({ error: "invalid claim" }, 400);
|
|
6691
7262
|
const { sessionID, receiverOwnerID, enrollmentKey } = body;
|
|
6692
7263
|
const result = await tx((db) => {
|
|
6693
7264
|
const b = binding(db, roomID);
|
|
@@ -6697,7 +7268,7 @@ async function claimBinding(request, roomID) {
|
|
|
6697
7268
|
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
7269
|
return saved.changes === 1 ? { capability, adminRoom: publicRoom({ ...b, capability_hash: digest(capability) }) } : null;
|
|
6699
7270
|
});
|
|
6700
|
-
return result ?
|
|
7271
|
+
return result ? json7(result) : json7({ error: "claim rejected" }, 409);
|
|
6701
7272
|
}
|
|
6702
7273
|
async function overview(request, roomID) {
|
|
6703
7274
|
const result = await tx((db) => {
|
|
@@ -6713,16 +7284,16 @@ async function overview(request, roomID) {
|
|
|
6713
7284
|
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
7285
|
return { rooms };
|
|
6715
7286
|
});
|
|
6716
|
-
return "status" in result ?
|
|
7287
|
+
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
7288
|
}
|
|
6718
7289
|
async function history(request, url, roomID) {
|
|
6719
7290
|
const targetRoomID = url.searchParams.get("targetRoomId") ?? "";
|
|
6720
7291
|
if (!bounded(targetRoomID, 128))
|
|
6721
|
-
return
|
|
7292
|
+
return json7({ error: "invalid history request" }, 400);
|
|
6722
7293
|
const rawLimit = url.searchParams.get("limit");
|
|
6723
7294
|
const limit = rawLimit === null ? 20 : Number(rawLimit);
|
|
6724
7295
|
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 50)
|
|
6725
|
-
return
|
|
7296
|
+
return json7({ error: "invalid history request" }, 400);
|
|
6726
7297
|
const allowed = await tx((db) => {
|
|
6727
7298
|
const b = binding(db, roomID);
|
|
6728
7299
|
if (!b)
|
|
@@ -6736,12 +7307,12 @@ async function history(request, url, roomID) {
|
|
|
6736
7307
|
return 200;
|
|
6737
7308
|
});
|
|
6738
7309
|
if (allowed !== 200)
|
|
6739
|
-
return
|
|
7310
|
+
return json7({ error: allowed === 401 ? "unauthorized" : allowed === 404 ? "room not found" : "binding is no longer active" }, allowed);
|
|
6740
7311
|
if (targetRoomID !== roomID)
|
|
6741
|
-
return
|
|
6742
|
-
return
|
|
7312
|
+
return json7({ error: "room is outside this administrator's scope" }, 403);
|
|
7313
|
+
return json7(await readHistoryPage(databasePath(), roomID, undefined, limit));
|
|
6743
7314
|
}
|
|
6744
|
-
var
|
|
7315
|
+
var json7 = (body, status = 200) => Response.json(body, { status, headers: { "Cache-Control": "no-store" } }), object3 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
6745
7316
|
var init_admin_routes = __esm(async () => {
|
|
6746
7317
|
init_store();
|
|
6747
7318
|
init_sqlite_state();
|
|
@@ -6751,7 +7322,7 @@ var init_admin_routes = __esm(async () => {
|
|
|
6751
7322
|
});
|
|
6752
7323
|
|
|
6753
7324
|
// server/room-join.ts
|
|
6754
|
-
import { randomUUID as
|
|
7325
|
+
import { randomUUID as randomUUID12 } from "node:crypto";
|
|
6755
7326
|
function joinRoomMember(svc, registry, roomId, member) {
|
|
6756
7327
|
const currentRoom = svc.getRoom(roomId);
|
|
6757
7328
|
const participantId = currentRoom.kind === "direct" ? member.sessionID : member.participantId;
|
|
@@ -6777,7 +7348,7 @@ function joinRoomMember(svc, registry, roomId, member) {
|
|
|
6777
7348
|
...member.protocol === "v2" ? { protocol: "v2" } : {},
|
|
6778
7349
|
...member.protocol === "v2" && member.receiverOwnerID ? { receiverOwnerID: member.receiverOwnerID } : {},
|
|
6779
7350
|
name: member.name,
|
|
6780
|
-
membershipID: prevEntry?.membershipID ??
|
|
7351
|
+
membershipID: prevEntry?.membershipID ?? randomUUID12(),
|
|
6781
7352
|
directory: member.directory || undefined,
|
|
6782
7353
|
host: member.host ?? "",
|
|
6783
7354
|
lastQueuedTs: regRoom[member.sessionID]?.lastQueuedTs,
|
|
@@ -6822,37 +7393,37 @@ async function joinRequestRoutes(req, url) {
|
|
|
6822
7393
|
const roomID = decodeURIComponent(status[1]);
|
|
6823
7394
|
const sessionID = url.searchParams.get("sessionID") ?? "";
|
|
6824
7395
|
if (!bounded2(sessionID))
|
|
6825
|
-
return
|
|
7396
|
+
return json8({ error: "sessionID is required" }, 400);
|
|
6826
7397
|
const joined = await readState2((svc, registry) => {
|
|
6827
7398
|
svc.getRoom(roomID);
|
|
6828
7399
|
return Boolean(registry[roomID]?.[sessionID]);
|
|
6829
7400
|
});
|
|
6830
7401
|
if (joined)
|
|
6831
|
-
return
|
|
6832
|
-
return
|
|
7402
|
+
return json8({ status: "joined" });
|
|
7403
|
+
return json8({ status: await readJoinRequest2(roomID, sessionID) ? "pending" : "none" });
|
|
6833
7404
|
}
|
|
6834
7405
|
if (list && req.method === "DELETE") {
|
|
6835
7406
|
const roomID = decodeURIComponent(list[1]);
|
|
6836
7407
|
const sessionID = url.searchParams.get("sessionID") ?? "";
|
|
6837
7408
|
if (!bounded2(sessionID))
|
|
6838
|
-
return
|
|
7409
|
+
return json8({ error: "sessionID is required" }, 400);
|
|
6839
7410
|
const removed = await writeSqliteStateWithDatabase(databasePath(), (svc, _registry, db) => {
|
|
6840
7411
|
svc.getRoom(roomID);
|
|
6841
7412
|
return removeJoinRequest(db, roomID, sessionID);
|
|
6842
7413
|
});
|
|
6843
|
-
return removed ?
|
|
7414
|
+
return removed ? json8({ ok: true }) : json8({ error: "join request not found" }, 404);
|
|
6844
7415
|
}
|
|
6845
7416
|
if (list && req.method === "GET") {
|
|
6846
7417
|
const roomID = decodeURIComponent(list[1]);
|
|
6847
7418
|
const actor = url.searchParams.get("sessionID") ?? "";
|
|
6848
7419
|
if (!bounded2(actor))
|
|
6849
|
-
return
|
|
7420
|
+
return json8({ error: "sessionID is required" }, 400);
|
|
6850
7421
|
const human = await humanReviewer(roomID, actor);
|
|
6851
7422
|
const agent = !human && await agentReviewer(req, roomID, actor);
|
|
6852
7423
|
if (!human && !agent)
|
|
6853
|
-
return
|
|
7424
|
+
return json8({ error: "only room administrators can review join requests" }, 403);
|
|
6854
7425
|
const requests = await listJoinRequests2(roomID, agent);
|
|
6855
|
-
return
|
|
7426
|
+
return json8({ requests: requests.map(({ sessionID, participantId, name, isAgent, createdAt }) => ({ sessionID, participantId, name, isAgent, createdAt })) });
|
|
6856
7427
|
}
|
|
6857
7428
|
if (action && req.method === "POST") {
|
|
6858
7429
|
const roomID = decodeURIComponent(action[1]);
|
|
@@ -6860,10 +7431,10 @@ async function joinRequestRoutes(req, url) {
|
|
|
6860
7431
|
const decision = action[3];
|
|
6861
7432
|
const body = await req.json();
|
|
6862
7433
|
if (!body || typeof body !== "object" || Array.isArray(body))
|
|
6863
|
-
return
|
|
7434
|
+
return json8({ error: "JSON object body is required" }, 400);
|
|
6864
7435
|
const actor = typeof body.sessionID === "string" ? body.sessionID : "";
|
|
6865
7436
|
if (!bounded2(actor))
|
|
6866
|
-
return
|
|
7437
|
+
return json8({ error: "sessionID is required" }, 400);
|
|
6867
7438
|
const result = await writeSqliteStateWithDatabase(databasePath(), (svc, registry, db) => {
|
|
6868
7439
|
const room = svc.getRoom(roomID);
|
|
6869
7440
|
const actorEntry = registry[roomID]?.[actor];
|
|
@@ -6902,11 +7473,11 @@ async function joinRequestRoutes(req, url) {
|
|
|
6902
7473
|
});
|
|
6903
7474
|
return { ok: true };
|
|
6904
7475
|
});
|
|
6905
|
-
return "ok" in result ?
|
|
7476
|
+
return "ok" in result ? json8({ ok: true }) : json8({ error: result.error }, result.status);
|
|
6906
7477
|
}
|
|
6907
|
-
return
|
|
7478
|
+
return json8({ error: "method not allowed" }, 405);
|
|
6908
7479
|
}
|
|
6909
|
-
var
|
|
7480
|
+
var json8 = (body, status = 200) => Response.json(body, { status, headers: { "Cache-Control": "no-store" } });
|
|
6910
7481
|
var init_join_requests = __esm(() => {
|
|
6911
7482
|
init_store();
|
|
6912
7483
|
init_sqlite_state();
|
|
@@ -6918,7 +7489,7 @@ var init_join_requests = __esm(() => {
|
|
|
6918
7489
|
|
|
6919
7490
|
// server/room-reminders.ts
|
|
6920
7491
|
import { Cron } from "croner";
|
|
6921
|
-
import { randomUUID as
|
|
7492
|
+
import { randomUUID as randomUUID13 } from "node:crypto";
|
|
6922
7493
|
function zone() {
|
|
6923
7494
|
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
6924
7495
|
}
|
|
@@ -7055,16 +7626,16 @@ async function roomReminderRoutes(req, url) {
|
|
|
7055
7626
|
return null;
|
|
7056
7627
|
return db.query("SELECT * FROM room_reminders WHERE room_id=? ORDER BY created_at,id").all(room);
|
|
7057
7628
|
});
|
|
7058
|
-
return items ?
|
|
7629
|
+
return items ? json9({ reminders: items.map(output) }) : json9({ error: "room not found or session is not a current member" }, 404);
|
|
7059
7630
|
}
|
|
7060
7631
|
if (req.method !== "POST" && req.method !== "PATCH" && req.method !== "DELETE")
|
|
7061
|
-
return
|
|
7632
|
+
return json9({ error: "method not allowed" }, 405);
|
|
7062
7633
|
const body = await req.json();
|
|
7063
7634
|
if (!body || typeof body !== "object" || Array.isArray(body))
|
|
7064
|
-
return
|
|
7635
|
+
return json9({ error: "JSON object body is required" }, 400);
|
|
7065
7636
|
const input = body, session = input.sessionID;
|
|
7066
7637
|
if (typeof session !== "string" || !session || session.length > 128)
|
|
7067
|
-
return
|
|
7638
|
+
return json9({ error: "sessionID is required" }, 400);
|
|
7068
7639
|
const result = await withStateTransaction(dbFile(), (db) => {
|
|
7069
7640
|
const who = member(db, room, session);
|
|
7070
7641
|
if (!who)
|
|
@@ -7074,7 +7645,7 @@ async function roomReminderRoutes(req, url) {
|
|
|
7074
7645
|
if (typeof text !== "string" || !text.trim() || text.length > 2000 || input.schedule === undefined)
|
|
7075
7646
|
return { error: "text (max 2000) and valid schedule are required", status: 400 };
|
|
7076
7647
|
try {
|
|
7077
|
-
const schedule = normalizeSchedule(input.schedule), at = next(schedule, Date.now()), created = Date.now(), rid =
|
|
7648
|
+
const schedule = normalizeSchedule(input.schedule), at = next(schedule, Date.now()), created = Date.now(), rid = randomUUID13();
|
|
7078
7649
|
const roomName = db.query("SELECT name FROM rooms WHERE id=?").get(room)?.name;
|
|
7079
7650
|
if (roomName === undefined)
|
|
7080
7651
|
return { error: "room not found", status: 404 };
|
|
@@ -7116,7 +7687,7 @@ async function roomReminderRoutes(req, url) {
|
|
|
7116
7687
|
}
|
|
7117
7688
|
});
|
|
7118
7689
|
const { status, ...bodyOut } = result;
|
|
7119
|
-
return
|
|
7690
|
+
return json9(bodyOut, status);
|
|
7120
7691
|
}
|
|
7121
7692
|
async function tickRoomReminders(now = Date.now(), wake) {
|
|
7122
7693
|
await initializeReminderSchema(dbFile());
|
|
@@ -7138,7 +7709,7 @@ async function tickRoomReminders(now = Date.now(), wake) {
|
|
|
7138
7709
|
})();
|
|
7139
7710
|
const tail = db.query("SELECT created_at FROM messages WHERE room_id=? ORDER BY seq DESC LIMIT 1").get(r.room_id);
|
|
7140
7711
|
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:${
|
|
7712
|
+
const message = { id: `reminder:${randomUUID13()}`, roomId: r.room_id, senderId: "system", text, createdAt: sentAt };
|
|
7142
7713
|
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
7714
|
delivered = { roomName: room.name, message };
|
|
7144
7715
|
if (upcoming === undefined)
|
|
@@ -7172,7 +7743,7 @@ function startRoomReminderScheduler(wake) {
|
|
|
7172
7743
|
}, 1000);
|
|
7173
7744
|
timer2.unref?.();
|
|
7174
7745
|
}
|
|
7175
|
-
var
|
|
7746
|
+
var json9 = (body, status = 200) => Response.json(body, { status }), dbFile = () => databasePath(), timer2;
|
|
7176
7747
|
var init_room_reminders = __esm(() => {
|
|
7177
7748
|
init_store();
|
|
7178
7749
|
init_sqlite_state();
|
|
@@ -7182,7 +7753,7 @@ var init_room_reminders = __esm(() => {
|
|
|
7182
7753
|
import { existsSync as existsSync2, promises as fs5 } from "node:fs";
|
|
7183
7754
|
import path14 from "node:path";
|
|
7184
7755
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
7185
|
-
import { randomUUID as
|
|
7756
|
+
import { randomUUID as randomUUID14 } from "node:crypto";
|
|
7186
7757
|
function parsePort(value) {
|
|
7187
7758
|
const port = Number(value);
|
|
7188
7759
|
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
@@ -7205,7 +7776,7 @@ async function handle(req) {
|
|
|
7205
7776
|
if (req.method === "GET" && p === "/chat") {
|
|
7206
7777
|
const html = await fs5.readFile(path14.join(here, "chat.html"), "utf8").catch(() => null);
|
|
7207
7778
|
if (html === null) {
|
|
7208
|
-
return
|
|
7779
|
+
return json10({ error: "chat page not found" }, 404);
|
|
7209
7780
|
}
|
|
7210
7781
|
const version = await chatVersionTag();
|
|
7211
7782
|
return new Response(html.replaceAll("{{version}}", version), {
|
|
@@ -7218,7 +7789,7 @@ async function handle(req) {
|
|
|
7218
7789
|
if (req.method === "GET" && p === "/manifest.webmanifest") {
|
|
7219
7790
|
const body = await fs5.readFile(path14.join(here, "manifest.webmanifest"), "utf8").catch(() => null);
|
|
7220
7791
|
if (body === null)
|
|
7221
|
-
return
|
|
7792
|
+
return json10({ error: "manifest not found" }, 404);
|
|
7222
7793
|
return new Response(body, {
|
|
7223
7794
|
headers: { "Content-Type": "application/manifest+json; charset=utf-8", "Cache-Control": "no-store" }
|
|
7224
7795
|
});
|
|
@@ -7226,7 +7797,7 @@ async function handle(req) {
|
|
|
7226
7797
|
if (req.method === "GET" && p === "/sw.js") {
|
|
7227
7798
|
const body = await fs5.readFile(path14.join(here, "sw.js"), "utf8").catch(() => null);
|
|
7228
7799
|
if (body === null)
|
|
7229
|
-
return
|
|
7800
|
+
return json10({ error: "service worker not found" }, 404);
|
|
7230
7801
|
const version = await chatVersionTag() || "dev";
|
|
7231
7802
|
return new Response(body.replaceAll("{{version}}", version), {
|
|
7232
7803
|
headers: {
|
|
@@ -7241,23 +7812,23 @@ async function handle(req) {
|
|
|
7241
7812
|
try {
|
|
7242
7813
|
relative = decodeURIComponent(p.slice("/assets/".length));
|
|
7243
7814
|
} catch {
|
|
7244
|
-
return
|
|
7815
|
+
return json10({ error: "invalid asset path" }, 400);
|
|
7245
7816
|
}
|
|
7246
7817
|
const root = path14.resolve(here, "assets");
|
|
7247
7818
|
const file = path14.resolve(root, relative);
|
|
7248
7819
|
if (!relative || !file.startsWith(`${root}${path14.sep}`) || !/\.(?:css|js|mjs|svg|png|jpg|woff2?)$/i.test(file))
|
|
7249
|
-
return
|
|
7820
|
+
return json10({ error: "not found" }, 404);
|
|
7250
7821
|
const data = await fs5.readFile(file).catch(() => null);
|
|
7251
7822
|
if (!data)
|
|
7252
|
-
return
|
|
7823
|
+
return json10({ error: "not found" }, 404);
|
|
7253
7824
|
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
7825
|
return new Response(data, { headers: { "Content-Type": type, "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff" } });
|
|
7255
7826
|
}
|
|
7256
7827
|
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
|
|
7828
|
+
return json10({ error: "content-type must be application/json" }, 415);
|
|
7258
7829
|
}
|
|
7259
7830
|
if (token && req.headers.get("authorization") !== `Bearer ${token}`) {
|
|
7260
|
-
return
|
|
7831
|
+
return json10({ error: "unauthorized" }, 401);
|
|
7261
7832
|
}
|
|
7262
7833
|
try {
|
|
7263
7834
|
const reminders = await roomReminderRoutes(req, url);
|
|
@@ -7281,16 +7852,16 @@ async function handle(req) {
|
|
|
7281
7852
|
name: r.name,
|
|
7282
7853
|
latestMsgTs: r.messages.at(-1)?.createdAt ?? 0
|
|
7283
7854
|
})));
|
|
7284
|
-
return
|
|
7855
|
+
return json10(rooms);
|
|
7285
7856
|
}
|
|
7286
7857
|
if (req.method === "GET" && p === "/receiver/memberships") {
|
|
7287
7858
|
const ownerID = url.searchParams.get("ownerID");
|
|
7288
7859
|
if (!isReceiverOwnerID(ownerID))
|
|
7289
|
-
return
|
|
7860
|
+
return json10({ error: "invalid ownerID" }, 400);
|
|
7290
7861
|
const sessionIDs = await readState2((_svc, registry) => {
|
|
7291
7862
|
return [...new Set(Object.values(registry).flatMap((entries) => Object.entries(entries).filter(([, entry]) => entry.protocol === "v2" && entry.receiverOwnerID === ownerID).map(([id]) => id)))];
|
|
7292
7863
|
});
|
|
7293
|
-
return
|
|
7864
|
+
return json10({ sessionIDs });
|
|
7294
7865
|
}
|
|
7295
7866
|
if (req.method === "GET" && p === "/rooms") {
|
|
7296
7867
|
const caller = url.searchParams.get("sessionID");
|
|
@@ -7299,7 +7870,7 @@ async function handle(req) {
|
|
|
7299
7870
|
for (const { room, entry } of rows) {
|
|
7300
7871
|
rooms.push({ ...await roomPayload(room), joined: Boolean(entry), ...entry?.lastReadTs ? { lastReadTs: entry.lastReadTs } : {} });
|
|
7301
7872
|
}
|
|
7302
|
-
return
|
|
7873
|
+
return json10(rooms);
|
|
7303
7874
|
}
|
|
7304
7875
|
const members = await memberRoutes(req, url);
|
|
7305
7876
|
if (members)
|
|
@@ -7313,23 +7884,23 @@ async function handle(req) {
|
|
|
7313
7884
|
if (req.method === "POST" && p === "/rooms") {
|
|
7314
7885
|
const body = await jsonObject(req);
|
|
7315
7886
|
if (!body)
|
|
7316
|
-
return
|
|
7887
|
+
return json10({ error: "JSON object body is required" }, 400);
|
|
7317
7888
|
if (body.protocol !== undefined && body.protocol !== "v2" || body.receiverOwnerID !== undefined && !isReceiverOwnerID(body.receiverOwnerID)) {
|
|
7318
|
-
return
|
|
7889
|
+
return json10({ error: "invalid receiver ownership" }, 400);
|
|
7319
7890
|
}
|
|
7320
7891
|
const name = body.name?.trim();
|
|
7321
7892
|
if (!name) {
|
|
7322
|
-
return
|
|
7893
|
+
return json10({ error: "name is required" }, 400);
|
|
7323
7894
|
}
|
|
7324
7895
|
if (name.length > 64) {
|
|
7325
|
-
return
|
|
7896
|
+
return json10({ error: "name too long (max 64)" }, 400);
|
|
7326
7897
|
}
|
|
7327
7898
|
const owner = (body.ownerId ?? "").trim() || "访客";
|
|
7328
7899
|
if (owner.length > 64) {
|
|
7329
|
-
return
|
|
7900
|
+
return json10({ error: "ownerId too long (max 64)" }, 400);
|
|
7330
7901
|
}
|
|
7331
7902
|
if (body.joinPolicy !== undefined && body.joinPolicy !== "open" && body.joinPolicy !== "approval") {
|
|
7332
|
-
return
|
|
7903
|
+
return json10({ error: "joinPolicy must be open or approval" }, 400);
|
|
7333
7904
|
}
|
|
7334
7905
|
const joinPolicy = body.joinPolicy === "approval" ? "approval" : body.joinPolicy === "open" ? "open" : undefined;
|
|
7335
7906
|
const room = await mutate2((svc, reg) => {
|
|
@@ -7339,7 +7910,7 @@ async function handle(req) {
|
|
|
7339
7910
|
regRoom[body.sessionID] = {
|
|
7340
7911
|
serverUrl: "",
|
|
7341
7912
|
apiPrefix: "/api",
|
|
7342
|
-
membershipID:
|
|
7913
|
+
membershipID: randomUUID14(),
|
|
7343
7914
|
...body.protocol === "v2" ? { protocol: "v2" } : {},
|
|
7344
7915
|
...body.protocol === "v2" && isReceiverOwnerID(body.receiverOwnerID) ? { receiverOwnerID: body.receiverOwnerID } : {},
|
|
7345
7916
|
name: owner,
|
|
@@ -7352,7 +7923,7 @@ async function handle(req) {
|
|
|
7352
7923
|
}
|
|
7353
7924
|
return created;
|
|
7354
7925
|
});
|
|
7355
|
-
return
|
|
7926
|
+
return json10(await roomPayload(room), 201);
|
|
7356
7927
|
}
|
|
7357
7928
|
if (req.method === "GET" && p === "/inbox") {
|
|
7358
7929
|
const sessionID = url.searchParams.get("sessionID") ?? "";
|
|
@@ -7361,11 +7932,11 @@ async function handle(req) {
|
|
|
7361
7932
|
const afterTs = afterValue === null ? undefined : Number(afterValue);
|
|
7362
7933
|
const recallVersionValue = url.searchParams.get("recallVersion");
|
|
7363
7934
|
if (url.searchParams.has("recallVersion") && (recallVersionValue === "" || !/^\d+$/.test(recallVersionValue ?? "") || !Number.isSafeInteger(Number(recallVersionValue)))) {
|
|
7364
|
-
return
|
|
7935
|
+
return json10({ error: "recallVersion must be a non-negative safe integer" }, 400);
|
|
7365
7936
|
}
|
|
7366
7937
|
const clientRecallVersion = recallVersionValue === null ? undefined : Number(recallVersionValue);
|
|
7367
7938
|
if (url.searchParams.has("afterTs") && (afterValue === "" || !/^\d+$/.test(afterValue ?? "") || !Number.isSafeInteger(afterTs) || afterTs < 0 || !roomFilter || url.searchParams.get("excludeSelf") !== "0")) {
|
|
7368
|
-
return
|
|
7939
|
+
return json10({ error: "afterTs requires a roomId and excludeSelf=0, with a non-negative safe integer value" }, 400);
|
|
7369
7940
|
}
|
|
7370
7941
|
const excludeSelf = url.searchParams.get("excludeSelf") === "1";
|
|
7371
7942
|
const timeout = Math.min(Math.max(Number(url.searchParams.get("timeout") ?? 0) || 0, 0), 30000);
|
|
@@ -7376,59 +7947,59 @@ async function handle(req) {
|
|
|
7376
7947
|
await sleep(Math.max(1, Math.min(500, deadline - Date.now())));
|
|
7377
7948
|
result = await readInbox(sessionID, roomFilter, excludeSelf, afterTs);
|
|
7378
7949
|
}
|
|
7379
|
-
return
|
|
7950
|
+
return json10(result);
|
|
7380
7951
|
}
|
|
7381
7952
|
if (req.method === "POST" && p === "/queued") {
|
|
7382
7953
|
const body = await jsonObject(req);
|
|
7383
7954
|
if (!body)
|
|
7384
|
-
return
|
|
7955
|
+
return json10({ error: "JSON object body is required" }, 400);
|
|
7385
7956
|
const ts = Number(body.ts);
|
|
7386
7957
|
const roomId = String(body.roomId ?? "");
|
|
7387
7958
|
const sessionID = String(body.sessionID ?? "");
|
|
7388
7959
|
if (body.ts === undefined || body.ts === null || !roomId || !sessionID || !Number.isFinite(ts)) {
|
|
7389
|
-
return
|
|
7960
|
+
return json10({ error: "roomId/sessionID/finite ts are required" }, 400);
|
|
7390
7961
|
}
|
|
7391
7962
|
const updated = await acknowledgeQueued2(roomId, sessionID, ts);
|
|
7392
7963
|
if (updated === null) {
|
|
7393
|
-
return
|
|
7964
|
+
return json10({ error: "registry entry not found" }, 404);
|
|
7394
7965
|
}
|
|
7395
7966
|
clearPendingAdmission(sessionID, roomId, updated);
|
|
7396
7967
|
touchActive(sessionID);
|
|
7397
|
-
return
|
|
7968
|
+
return json10({ ok: true });
|
|
7398
7969
|
}
|
|
7399
7970
|
if (req.method === "POST" && p === "/active") {
|
|
7400
7971
|
const body = await jsonObject(req);
|
|
7401
7972
|
if (!body)
|
|
7402
|
-
return
|
|
7973
|
+
return json10({ error: "JSON object body is required" }, 400);
|
|
7403
7974
|
touchActive(String(body.sessionID ?? ""));
|
|
7404
|
-
return
|
|
7975
|
+
return json10({ ok: true });
|
|
7405
7976
|
}
|
|
7406
7977
|
if (req.method === "POST" && p === "/wake-claim") {
|
|
7407
7978
|
const body = await jsonObject(req);
|
|
7408
7979
|
if (!body)
|
|
7409
|
-
return
|
|
7980
|
+
return json10({ error: "JSON object body is required" }, 400);
|
|
7410
7981
|
const sessionID = String(body.sessionID ?? "");
|
|
7411
7982
|
const ok = claimWake(sessionID);
|
|
7412
|
-
return
|
|
7983
|
+
return json10({ ok });
|
|
7413
7984
|
}
|
|
7414
7985
|
const m = p.match(/^\/rooms\/([^/]+)\/(join|leave|messages)$/);
|
|
7415
7986
|
if (m) {
|
|
7416
7987
|
const roomId = decodeURIComponent(m[1]);
|
|
7417
7988
|
const body = await jsonObject(req);
|
|
7418
7989
|
if (!body)
|
|
7419
|
-
return
|
|
7990
|
+
return json10({ error: "JSON object body is required" }, 400);
|
|
7420
7991
|
const sessionID = typeof body.sessionID === "string" ? body.sessionID : "";
|
|
7421
7992
|
if (req.method === "POST" && m[2] === "join") {
|
|
7422
7993
|
if (body.protocol !== undefined && body.protocol !== "v2" || body.receiverOwnerID !== undefined && !isReceiverOwnerID(body.receiverOwnerID)) {
|
|
7423
|
-
return
|
|
7994
|
+
return json10({ error: "invalid receiver ownership" }, 400);
|
|
7424
7995
|
}
|
|
7425
7996
|
const id = typeof body.participantId === "string" ? body.participantId.trim() : "";
|
|
7426
7997
|
const name = typeof body.participantName === "string" ? body.participantName.trim() : "";
|
|
7427
7998
|
if (!id || !name || !sessionID) {
|
|
7428
|
-
return
|
|
7999
|
+
return json10({ error: "participantId/participantName/sessionID are required" }, 400);
|
|
7429
8000
|
}
|
|
7430
8001
|
if (id.length > 64 || name.length > 64) {
|
|
7431
|
-
return
|
|
8002
|
+
return json10({ error: "name too long (max 64)" }, 400);
|
|
7432
8003
|
}
|
|
7433
8004
|
const result = await writeSqliteStateWithDatabase(databasePath(), (svc, reg, db) => {
|
|
7434
8005
|
const currentRoom = svc.getRoom(roomId);
|
|
@@ -7463,14 +8034,14 @@ async function handle(req) {
|
|
|
7463
8034
|
}) };
|
|
7464
8035
|
});
|
|
7465
8036
|
if ("status" in result)
|
|
7466
|
-
return
|
|
8037
|
+
return json10({ error: result.error }, result.status);
|
|
7467
8038
|
if ("pending" in result)
|
|
7468
|
-
return
|
|
8039
|
+
return json10({
|
|
7469
8040
|
status: "pending",
|
|
7470
8041
|
message: "Join request submitted. You are not a member yet; a human administrator must approve it before you can send or poll."
|
|
7471
8042
|
}, 202);
|
|
7472
8043
|
touchActive(sessionID);
|
|
7473
|
-
return
|
|
8044
|
+
return json10(await roomPayload(result.room), 201);
|
|
7474
8045
|
}
|
|
7475
8046
|
if (req.method === "POST" && m[2] === "leave") {
|
|
7476
8047
|
await mutate2((svc, reg) => {
|
|
@@ -7503,48 +8074,48 @@ async function handle(req) {
|
|
|
7503
8074
|
settleAdmins(svc.getRoom(roomId), reg[roomId] ?? {});
|
|
7504
8075
|
settleOwner(svc.getRoom(roomId), reg[roomId] ?? {});
|
|
7505
8076
|
});
|
|
7506
|
-
return
|
|
8077
|
+
return json10({ ok: true });
|
|
7507
8078
|
}
|
|
7508
8079
|
if (req.method === "POST" && m[2] === "messages") {
|
|
7509
8080
|
const isQuestion = body.isQuestion;
|
|
7510
8081
|
if (isQuestion !== undefined && typeof isQuestion !== "boolean")
|
|
7511
|
-
return
|
|
8082
|
+
return json10({ error: "isQuestion must be a boolean" }, 400);
|
|
7512
8083
|
const text = typeof body.text === "string" ? body.text.trim() : "";
|
|
7513
8084
|
if (!text) {
|
|
7514
|
-
return
|
|
8085
|
+
return json10({ error: "text is required" }, 400);
|
|
7515
8086
|
}
|
|
7516
8087
|
if (text.length > 5000) {
|
|
7517
|
-
return
|
|
8088
|
+
return json10({ error: "text too long (max 5000)" }, 400);
|
|
7518
8089
|
}
|
|
7519
8090
|
const replyTo = body.replyToMessageID;
|
|
7520
8091
|
if (replyTo !== undefined && (typeof replyTo !== "string" || !replyTo))
|
|
7521
|
-
return
|
|
8092
|
+
return json10({ error: "replyToMessageID must be a non-empty message ID" }, 400);
|
|
7522
8093
|
if (replyTo !== undefined) {
|
|
7523
8094
|
const result = await sendReply2(roomId, replyTo, sessionID, text);
|
|
7524
8095
|
if (result.status !== "ok") {
|
|
7525
8096
|
if (result.status === "missing")
|
|
7526
|
-
return
|
|
8097
|
+
return json10({ error: "room not found" }, 404);
|
|
7527
8098
|
if (result.status === "target")
|
|
7528
|
-
return
|
|
8099
|
+
return json10({ error: "reply target not found in room" }, 404);
|
|
7529
8100
|
if (result.status === "question")
|
|
7530
|
-
return
|
|
7531
|
-
return
|
|
8101
|
+
return json10({ error: "use the question answers endpoint to reply to a question" }, 409);
|
|
8102
|
+
return json10({ error: "session is not a room member" }, 409);
|
|
7532
8103
|
}
|
|
7533
8104
|
touchActive(sessionID);
|
|
7534
8105
|
const room = await read((svc) => svc.getRoom(roomId));
|
|
7535
8106
|
wakeMentionedSessions(serveWakeUrl2, roomId, room.name, text, sessionID, result.message);
|
|
7536
|
-
return
|
|
8107
|
+
return json10(await roomPayload(room), 201);
|
|
7537
8108
|
}
|
|
7538
8109
|
const result = await appendRoomMessage2(roomId, sessionID, text, isQuestion === true);
|
|
7539
8110
|
if (result.status !== "ok") {
|
|
7540
8111
|
if (result.status === "missing")
|
|
7541
|
-
return
|
|
7542
|
-
return
|
|
8112
|
+
return json10({ error: "room not found" }, 404);
|
|
8113
|
+
return json10({ error: "session is not a room member" }, 409);
|
|
7543
8114
|
}
|
|
7544
8115
|
touchActive(sessionID);
|
|
7545
8116
|
const room = await read((svc) => svc.getRoom(roomId));
|
|
7546
8117
|
wakeMentionedSessions(serveWakeUrl2, roomId, room.name, text, sessionID, result.message);
|
|
7547
|
-
return
|
|
8118
|
+
return json10(await roomPayload(room), 201);
|
|
7548
8119
|
}
|
|
7549
8120
|
}
|
|
7550
8121
|
const questions = p.match(/^\/rooms\/([^/]+)\/questions$/);
|
|
@@ -7552,8 +8123,8 @@ async function handle(req) {
|
|
|
7552
8123
|
const roomId = decodeURIComponent(questions[1]);
|
|
7553
8124
|
const exists = await read((svc) => svc.listRooms().some((room) => room.id === roomId));
|
|
7554
8125
|
if (!exists)
|
|
7555
|
-
return
|
|
7556
|
-
return
|
|
8126
|
+
return json10({ error: "room not found" }, 404);
|
|
8127
|
+
return json10({ questions: await readQuestions2(roomId) });
|
|
7557
8128
|
}
|
|
7558
8129
|
const answer = p.match(/^\/rooms\/([^/]+)\/questions\/([^/]+)\/answers$/);
|
|
7559
8130
|
if (req.method === "POST" && answer) {
|
|
@@ -7561,30 +8132,30 @@ async function handle(req) {
|
|
|
7561
8132
|
const questionID = decodeURIComponent(answer[2]);
|
|
7562
8133
|
const body = await req.json();
|
|
7563
8134
|
if (!body || typeof body !== "object" || Array.isArray(body))
|
|
7564
|
-
return
|
|
8135
|
+
return json10({ error: "sessionID and non-empty text (max 5000) are required" }, 400);
|
|
7565
8136
|
const input = body;
|
|
7566
8137
|
if (typeof input.sessionID !== "string" || !input.sessionID || typeof input.text !== "string" || !input.text.trim() || input.text.trim().length > 5000)
|
|
7567
|
-
return
|
|
8138
|
+
return json10({ error: "sessionID and non-empty text (max 5000) are required" }, 400);
|
|
7568
8139
|
const result = await answerQuestion2(roomId, questionID, input.sessionID, input.text.trim());
|
|
7569
8140
|
if (result.status === "missing")
|
|
7570
|
-
return
|
|
8141
|
+
return json10({ error: "room not found" }, 404);
|
|
7571
8142
|
if (result.status === "question")
|
|
7572
|
-
return
|
|
8143
|
+
return json10({ error: "question not found" }, 404);
|
|
7573
8144
|
if (result.status === "member")
|
|
7574
|
-
return
|
|
8145
|
+
return json10({ error: "session is not a room member" }, 409);
|
|
7575
8146
|
if (result.status === "answered")
|
|
7576
|
-
return
|
|
8147
|
+
return json10({ error: "question already answered" }, 409);
|
|
7577
8148
|
if (result.status !== "ok")
|
|
7578
|
-
return
|
|
8149
|
+
return json10({ error: "question not found" }, 404);
|
|
7579
8150
|
touchActive(input.sessionID);
|
|
7580
8151
|
const room = await read((svc) => svc.getRoom(roomId));
|
|
7581
8152
|
wakeMentionedSessions(serveWakeUrl2, roomId, room.name, result.answer.text, input.sessionID, result.answer);
|
|
7582
|
-
return
|
|
8153
|
+
return json10({ questionID, answer: result.answer }, 201);
|
|
7583
8154
|
}
|
|
7584
8155
|
const g = p.match(/^\/rooms\/([^/]+)$/);
|
|
7585
8156
|
if (g && req.method === "GET") {
|
|
7586
8157
|
const room = await read((svc) => svc.getRoom(decodeURIComponent(g[1])));
|
|
7587
|
-
return
|
|
8158
|
+
return json10(await roomPayload(room));
|
|
7588
8159
|
}
|
|
7589
8160
|
const r = p.match(/^\/rooms\/([^/]+)\/registry$/);
|
|
7590
8161
|
if (r && req.method === "GET") {
|
|
@@ -7606,22 +8177,22 @@ async function handle(req) {
|
|
|
7606
8177
|
}
|
|
7607
8178
|
]));
|
|
7608
8179
|
});
|
|
7609
|
-
return
|
|
8180
|
+
return json10(reg);
|
|
7610
8181
|
}
|
|
7611
|
-
return
|
|
8182
|
+
return json10({ error: "not found" }, 404);
|
|
7612
8183
|
} catch (err) {
|
|
7613
8184
|
if (err instanceof SyntaxError)
|
|
7614
|
-
return
|
|
8185
|
+
return json10({ error: "invalid JSON body" }, 400);
|
|
7615
8186
|
if (err instanceof RoomError) {
|
|
7616
|
-
return
|
|
8187
|
+
return json10({ error: err.message }, err.code === "ROOM_NOT_FOUND" ? 404 : err.code === "NOT_OWNER" ? 403 : 409);
|
|
7617
8188
|
}
|
|
7618
|
-
return
|
|
8189
|
+
return json10({ error: err instanceof Error ? err.message : String(err) }, 500);
|
|
7619
8190
|
}
|
|
7620
8191
|
}
|
|
7621
8192
|
var moduleDir, here, versionTag, chatVersionTag = () => versionTag ??= fs5.readFile(path14.join(here, "../package.json"), "utf8").then((text) => {
|
|
7622
8193
|
const pkg = JSON.parse(text);
|
|
7623
8194
|
return typeof pkg?.version === "string" && pkg.version ? `v${pkg.version}` : "";
|
|
7624
|
-
}).catch(() => ""), settings, hostname, displayHostname, port, token, serveWakeUrl2,
|
|
8195
|
+
}).catch(() => ""), settings, hostname, displayHostname, port, token, serveWakeUrl2, json10 = (body, status = 200) => new Response(JSON.stringify(body), {
|
|
7625
8196
|
status,
|
|
7626
8197
|
headers: { "Content-Type": "application/json" }
|
|
7627
8198
|
}), sleep = (ms) => new Promise((r) => setTimeout(r, ms)), config, chat_server_default;
|