@alexsun-top/opencode-chat-room 0.7.7 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/LICENSE +21 -0
- package/README.md +45 -36
- package/README.zh-CN.md +50 -41
- package/dist/cli.js +2696 -365
- package/package.json +14 -4
- package/packages/chat-room-channeld/README.md +242 -0
- package/packages/chat-room-channeld/dist/feishu-adapter.js +499 -0
- package/packages/chat-room-channeld/dist/mock-adapter.js +295 -0
- package/packages/chat-room-channeld/src/adapter.ts +475 -0
- package/packages/chat-room-channeld/src/cli.ts +124 -0
- package/packages/chat-room-channeld/src/config.ts +207 -0
- package/packages/chat-room-channeld/src/delivery.ts +158 -0
- package/packages/chat-room-channeld/src/feishu-adapter.ts +473 -0
- package/packages/chat-room-channeld/src/framing.ts +128 -0
- package/packages/chat-room-channeld/src/host-helpers.ts +41 -0
- package/packages/chat-room-channeld/src/host.ts +509 -0
- package/packages/chat-room-channeld/src/ingest-gate.ts +108 -0
- package/packages/chat-room-channeld/src/log.ts +26 -0
- package/packages/chat-room-channeld/src/mock-adapter.ts +206 -0
- package/packages/chat-room-channeld/src/protocol.ts +75 -0
- package/packages/chat-room-channeld/src/published.ts +37 -0
- package/packages/chat-room-channeld/src/rules.ts +127 -0
- package/packages/chat-room-channeld/src/state.ts +485 -0
- package/packages/chat-room-channeld/src/stats.ts +167 -0
- package/plugin.ts +22 -5
- package/server/addressing-routes.ts +130 -0
- package/server/assets/NOTICE.txt +2 -2
- package/server/assets/SHIKI-LICENSE +22 -0
- package/server/assets/base.css +9 -1
- package/server/assets/chat/announcements.js +5 -2
- package/server/assets/chat/clipboard.js +30 -0
- package/server/assets/chat/copy-action.js +48 -0
- package/server/assets/chat/diagram-viewer.js +253 -0
- package/server/assets/chat/doc-preview.js +149 -12
- package/server/assets/chat/events.js +25 -4
- package/server/assets/chat/files.js +26 -5
- package/server/assets/chat/forward.js +69 -0
- package/server/assets/chat/history-loader.js +3 -1
- package/server/assets/chat/index.js +11 -1
- package/server/assets/chat/join-requests.js +6 -3
- package/server/assets/chat/locales/de.js +7 -2
- package/server/assets/chat/locales/es.js +7 -2
- package/server/assets/chat/locales/fr.js +7 -2
- package/server/assets/chat/locales/it.js +7 -2
- package/server/assets/chat/locales/ja.js +7 -2
- package/server/assets/chat/locales/ko.js +7 -2
- package/server/assets/chat/markdown-footnotes.js +115 -0
- package/server/assets/chat/markdown.js +65 -113
- package/server/assets/chat/messages.js +6 -3
- package/server/assets/chat/palette.js +33 -16
- package/server/assets/chat/pwa.js +2 -0
- package/server/assets/chat/questions.js +5 -0
- package/server/assets/chat/replies.js +7 -1
- package/server/assets/chat/resource-format.js +74 -0
- package/server/assets/chat/rooms.js +3 -0
- package/server/assets/chat/shiki.js +87 -0
- package/server/assets/chat/side-pane.js +143 -0
- package/server/assets/chat/state.js +63 -9
- package/server/assets/chat/system-messages.js +2 -0
- package/server/assets/chat/task-row.js +2 -1
- package/server/assets/chat/tasks.js +29 -2
- package/server/assets/chat/viewport.js +5 -0
- package/server/assets/code-highlight.css +20 -31
- package/server/assets/conversation.css +27 -2
- package/server/assets/diagram-viewer.css +141 -0
- package/server/assets/doc-preview.css +26 -6
- package/server/assets/responsive.css +87 -13
- package/server/assets/shiki.bundle.js +152 -0
- package/server/assets/tasks.css +1 -4
- package/server/channels.ts +314 -0
- package/server/chat-server.ts +36 -8
- package/server/chat.html +33 -5
- package/server/resource-routes.ts +3 -1
- package/server/sw.js +236 -4
- package/skills/chatroom/SKILL.md +1 -1
- package/src/agent/chatroom-skill.ts +8 -2
- package/src/center/center-client.ts +79 -1
- package/src/config/file-config.ts +34 -0
- package/src/rooms/resources.ts +2 -2
- package/src/runtime/v2-plugin.ts +8 -2
- package/src/runtime/watch.ts +41 -7
- package/src/state/sqlite-state.ts +67 -18
- package/src/state/store.ts +11 -5
- package/src/tui/app.mjs +10 -2
- package/src/tui/http.mjs +16 -2
- package/src/tui/info-app.mjs +24 -15
- package/src/tui/join-app.mjs +3 -3
- package/src/tui/main.mjs +1 -1
- package/src/tui/markdown.mjs +5 -3
- package/src/tui/mentions.mjs +3 -3
- package/src/tui/message-app.mjs +14 -11
- package/src/tui/palette-app.mjs +10 -7
- package/src/tui/reminder-app.mjs +14 -10
- package/src/tui/ui-content.mjs +3 -1
- package/server/assets/HIGHLIGHT-LICENSE +0 -29
- package/server/assets/highlight-10.7.3.min.js +0 -1358
|
@@ -133,10 +133,16 @@ export async function putResource(file: string, resource: StoredResource): Promi
|
|
|
133
133
|
return true;
|
|
134
134
|
});
|
|
135
135
|
}
|
|
136
|
-
export async function listResources(file: string, roomID: string, limit = 500, offset = 0): Promise<{ items: StoredResource[]; total: number }> {
|
|
136
|
+
export async function listResources(file: string, roomID: string, limit = 500, offset = 0, beforeID?: string): Promise<{ items: StoredResource[]; total: number }> {
|
|
137
137
|
const db = await initialize(file);
|
|
138
|
-
const
|
|
139
|
-
.
|
|
138
|
+
const cursor = beforeID
|
|
139
|
+
? db.query("SELECT created_at AS createdAt,id FROM resources WHERE room_id=? AND id=?").get(roomID, beforeID) as { createdAt: number; id: string } | null
|
|
140
|
+
: null;
|
|
141
|
+
const items = cursor
|
|
142
|
+
? db.query("SELECT id,room_id AS roomID,name,mime_type AS mimeType,size,created_at AS createdAt,uploader_session_id AS uploaderSessionID,uploader_name AS uploaderName FROM resources WHERE room_id=? AND (created_at<? OR (created_at=? AND id<?)) ORDER BY created_at DESC, id DESC LIMIT ?")
|
|
143
|
+
.all(roomID, cursor.createdAt, cursor.createdAt, cursor.id, limit) as StoredResource[]
|
|
144
|
+
: db.query("SELECT id,room_id AS roomID,name,mime_type AS mimeType,size,created_at AS createdAt,uploader_session_id AS uploaderSessionID,uploader_name AS uploaderName FROM resources WHERE room_id=? ORDER BY created_at DESC, id DESC LIMIT ? OFFSET ?")
|
|
145
|
+
.all(roomID, limit, offset) as StoredResource[];
|
|
140
146
|
const total = Number((db.query("SELECT COUNT(*) AS count FROM resources WHERE room_id=?").get(roomID) as { count: number } | null)?.count ?? 0);
|
|
141
147
|
return { items, total };
|
|
142
148
|
}
|
|
@@ -221,6 +227,10 @@ async function ensureRoomColumns(db: Database): Promise<void> {
|
|
|
221
227
|
if (!messageColumns.some((column) => column.name === "answered_by")) db.exec("ALTER TABLE messages ADD COLUMN answered_by TEXT");
|
|
222
228
|
if (!messageColumns.some((column) => column.name === "recalled_at")) db.exec("ALTER TABLE messages ADD COLUMN recalled_at INTEGER");
|
|
223
229
|
if (!messageColumns.some((column) => column.name === "recalled_by")) db.exec("ALTER TABLE messages ADD COLUMN recalled_by TEXT");
|
|
230
|
+
if (!messageColumns.some((column) => column.name === "client_msg_id")) db.exec("ALTER TABLE messages ADD COLUMN client_msg_id TEXT");
|
|
231
|
+
// A retry after a lost response must return the first insert, not add a twin.
|
|
232
|
+
db.exec("DROP INDEX IF EXISTS messages_client_id");
|
|
233
|
+
db.exec("CREATE UNIQUE INDEX IF NOT EXISTS messages_client_id ON messages(room_id,sender_session_id,client_msg_id) WHERE client_msg_id IS NOT NULL");
|
|
224
234
|
db.exec("CREATE INDEX IF NOT EXISTS messages_pending_questions ON messages(room_id,is_question,answered_by,seq)");
|
|
225
235
|
db.exec("CREATE INDEX IF NOT EXISTS messages_room_recalled ON messages(room_id,recalled_at)");
|
|
226
236
|
const taskColumns = db.query("PRAGMA table_info(room_tasks)").all() as Array<{ name: string }>;
|
|
@@ -520,6 +530,16 @@ export async function readQuestions(file: string, roomID: string): Promise<Messa
|
|
|
520
530
|
return (db.query("SELECT id,room_id,sender_id,sender_session_id,text,created_at,is_question,answer_to,answered_by FROM messages WHERE room_id=? AND is_question=1 AND answered_by IS NULL AND recalled_at IS NULL ORDER BY seq").all(roomID) as Array<Record<string, string | number | null>>).map(rowMessage);
|
|
521
531
|
}
|
|
522
532
|
|
|
533
|
+
// Open questions as seq references for catch-up; room-wide, excluding recalled.
|
|
534
|
+
// Capped so a room with a large question backlog cannot bloat a catch-up page.
|
|
535
|
+
export const MAX_OPEN_QUESTION_REFS = 200;
|
|
536
|
+
export async function readOpenQuestionRefs(file: string, roomID: string, limit = MAX_OPEN_QUESTION_REFS): Promise<Array<{ id: string; seq: number }>> {
|
|
537
|
+
const db = await openStateDatabase(file);
|
|
538
|
+
const take = Number.isSafeInteger(limit) ? Math.min(MAX_OPEN_QUESTION_REFS, Math.max(1, limit)) : MAX_OPEN_QUESTION_REFS;
|
|
539
|
+
return (db.query("SELECT id,seq FROM messages WHERE room_id=? AND is_question=1 AND answered_by IS NULL AND recalled_at IS NULL ORDER BY seq LIMIT ?").all(roomID, take) as Array<{ id: string; seq: number }>)
|
|
540
|
+
.map((row) => ({ id: String(row.id), seq: Number(row.seq) }));
|
|
541
|
+
}
|
|
542
|
+
|
|
523
543
|
export async function countOpenQuestions(file: string, roomID: string): Promise<number> {
|
|
524
544
|
const db = await openStateDatabase(file);
|
|
525
545
|
const row = db.query("SELECT COUNT(*) AS count FROM messages WHERE room_id=? AND is_question=1 AND answered_by IS NULL AND recalled_at IS NULL").get(roomID) as { count: number };
|
|
@@ -545,37 +565,46 @@ export async function answerQuestion(file: string, roomID: string, questionID: s
|
|
|
545
565
|
});
|
|
546
566
|
}
|
|
547
567
|
|
|
548
|
-
export async function appendRoomMessage(file: string, roomID: string, sessionID: string, text: string, isQuestion: boolean): Promise<{ status: "ok"; message: Message } | { status: "missing" | "member" }> {
|
|
568
|
+
export async function appendRoomMessage(file: string, roomID: string, sessionID: string, text: string, isQuestion: boolean, clientMessageID?: string): Promise<{ status: "ok"; message: Message; duplicate?: true } | { status: "missing" | "member" }> {
|
|
549
569
|
const db = await openStateDatabase(file);
|
|
550
570
|
return immediate(db, () => {
|
|
551
571
|
if (!db.query("SELECT 1 FROM rooms WHERE id=?").get(roomID)) return { status: "missing" };
|
|
552
572
|
const member = db.query("SELECT g.name,r.kind FROM registry g JOIN rooms r ON r.id=g.room_id JOIN participants p ON p.room_id=g.room_id AND p.id=CASE WHEN r.kind='direct' THEN g.session_id ELSE g.name END WHERE g.room_id=? AND g.session_id=?").get(roomID, sessionID) as { name: string; kind: string } | null;
|
|
553
573
|
if (!member) return { status: "member" };
|
|
574
|
+
if (clientMessageID) {
|
|
575
|
+
const existing = db.query("SELECT id,room_id,sender_id,sender_session_id,text,created_at,is_question,answer_to,answered_by FROM messages WHERE room_id=? AND client_msg_id=? AND sender_session_id=?").get(roomID, clientMessageID, sessionID);
|
|
576
|
+
if (existing) return { status: "ok", message: rowMessage(existing as Record<string, string | number | null>), duplicate: true };
|
|
577
|
+
}
|
|
554
578
|
const tail = db.query("SELECT created_at FROM messages WHERE room_id=? ORDER BY seq DESC LIMIT 1").get(roomID) as { created_at: number } | null;
|
|
555
579
|
const message: Message = {
|
|
556
580
|
id: randomUUID(), roomId: roomID, senderId: member.kind === "direct" ? sessionID : member.name,
|
|
557
581
|
senderSessionID: sessionID, text, createdAt: Math.max(Date.now(), (tail?.created_at ?? 0) + 1),
|
|
558
582
|
...(isQuestion ? { isQuestion: true } : {}),
|
|
559
583
|
};
|
|
560
|
-
db.query("INSERT INTO messages(id,room_id,sender_id,sender_session_id,text,created_at,is_question) VALUES(
|
|
561
|
-
.run(message.id, roomID, message.senderId, sessionID, text, message.createdAt, isQuestion ? 1 : 0);
|
|
584
|
+
db.query("INSERT INTO messages(id,room_id,sender_id,sender_session_id,text,created_at,is_question,client_msg_id) VALUES(?,?,?,?,?,?,?,?)")
|
|
585
|
+
.run(message.id, roomID, message.senderId, sessionID, text, message.createdAt, isQuestion ? 1 : 0, clientMessageID ?? null);
|
|
562
586
|
noteMessageInsert(db, roomID);
|
|
563
587
|
return { status: "ok", message };
|
|
564
588
|
});
|
|
565
589
|
}
|
|
566
590
|
|
|
567
|
-
export async function sendReply(file: string, roomID: string, targetID: string, sessionID: string, text: string): Promise<{ status: "ok"; message: Message } | { status: "missing" | "member" | "target" | "question" }> {
|
|
591
|
+
export async function sendReply(file: string, roomID: string, targetID: string, sessionID: string, text: string, clientMessageID?: string): Promise<{ status: "ok"; message: Message; duplicate?: true } | { status: "missing" | "member" | "target" | "recalled" | "question" }> {
|
|
568
592
|
const db = await openStateDatabase(file);
|
|
569
593
|
return immediate(db, () => {
|
|
570
594
|
if (!db.query("SELECT 1 FROM rooms WHERE id=?").get(roomID)) return { status: "missing" };
|
|
571
595
|
const member = db.query("SELECT g.name,r.kind FROM registry g JOIN rooms r ON r.id=g.room_id JOIN participants p ON p.room_id=g.room_id AND p.id=CASE WHEN r.kind='direct' THEN g.session_id ELSE g.name END WHERE g.room_id=? AND g.session_id=?").get(roomID, sessionID) as { name: string; kind: string } | null;
|
|
572
596
|
if (!member) return { status: "member" };
|
|
597
|
+
if (clientMessageID) {
|
|
598
|
+
const existing = db.query("SELECT id,room_id,sender_id,sender_session_id,text,created_at,is_question,answer_to,answered_by FROM messages WHERE room_id=? AND client_msg_id=? AND sender_session_id=?").get(roomID, clientMessageID, sessionID);
|
|
599
|
+
if (existing) return { status: "ok", message: rowMessage(existing as Record<string, string | number | null>), duplicate: true };
|
|
600
|
+
}
|
|
573
601
|
const target = db.query("SELECT is_question,recalled_at FROM messages WHERE room_id=? AND id=?").get(roomID, targetID) as { is_question: number; recalled_at: number | null } | null;
|
|
574
|
-
if (!target
|
|
602
|
+
if (!target) return { status: "target" };
|
|
603
|
+
if (target.recalled_at !== null) return { status: "recalled" };
|
|
575
604
|
if (target.is_question) return { status: "question" };
|
|
576
605
|
const tail = db.query("SELECT created_at FROM messages WHERE room_id=? ORDER BY seq DESC LIMIT 1").get(roomID) as { created_at: number } | null;
|
|
577
606
|
const message: Message = { id: randomUUID(), roomId: roomID, senderId: member.kind === "direct" ? sessionID : member.name, senderSessionID: sessionID, text, createdAt: Math.max(Date.now(), (tail?.created_at ?? 0) + 1), answerToMessageID: targetID };
|
|
578
|
-
db.query("INSERT INTO messages(id,room_id,sender_id,sender_session_id,text,created_at,is_question,answer_to) VALUES(?,?,?,?,?,?,0
|
|
607
|
+
db.query("INSERT INTO messages(id,room_id,sender_id,sender_session_id,text,created_at,is_question,answer_to,client_msg_id) VALUES(?,?,?,?,?,?,0,?,?)").run(message.id, roomID, message.senderId, sessionID, text, message.createdAt, targetID, clientMessageID ?? null);
|
|
579
608
|
noteMessageInsert(db, roomID);
|
|
580
609
|
return { status: "ok", message };
|
|
581
610
|
});
|
|
@@ -731,24 +760,44 @@ export async function readInboxPage(file: string, sessionID: string, roomFilter:
|
|
|
731
760
|
}).deferred();
|
|
732
761
|
}
|
|
733
762
|
|
|
734
|
-
|
|
763
|
+
const HISTORY_COLUMNS = "seq,id,room_id,sender_id,sender_session_id,text,created_at,is_question,answer_to,answered_by,recalled_at,recalled_by";
|
|
764
|
+
|
|
765
|
+
function historyRowMessage(row: Record<string, string | number | null>): HistoryMessage {
|
|
766
|
+
const message = rowMessage(row);
|
|
767
|
+
const recalledAt = row.recalled_at === null || row.recalled_at === undefined ? undefined : Number(row.recalled_at);
|
|
768
|
+
// Recalled rows keep their original text in storage for member reveal; history
|
|
769
|
+
// surfaces only a tombstone.
|
|
770
|
+
return { ...message, ...(recalledAt !== undefined ? { text: "", recalledAt, ...(row.recalled_by ? { recalledBy: String(row.recalled_by) } : {}) } : {}), seq: Number(row.seq) };
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
// afterSeq switches the page to ascending order, exclusive cursor semantics,
|
|
774
|
+
// for catch-up from a persisted seq. beforeSeq is ignored in that branch.
|
|
775
|
+
export async function readHistoryPage(file: string, roomID: string, beforeSeq?: number, limit = 100, excludeSessionID?: string, excludeName = "", afterSeq?: number): Promise<{ messages: HistoryMessage[]; nextBeforeSeq: number | null; hasMore: boolean; recallVersion: number }> {
|
|
735
776
|
const db = await openStateDatabase(file);
|
|
736
777
|
return db.transaction(() => {
|
|
737
778
|
const take = Math.min(200, Math.max(1, limit));
|
|
738
|
-
const
|
|
739
|
-
|
|
740
|
-
|
|
779
|
+
const exclude = `(? IS NULL OR (sender_session_id IS NOT NULL AND sender_session_id!=?) OR (sender_session_id IS NULL AND sender_id!=?))`;
|
|
780
|
+
if (afterSeq !== undefined) {
|
|
781
|
+
const rows = db.query(`SELECT ${HISTORY_COLUMNS} FROM messages WHERE room_id=? AND seq>? AND ${exclude} ORDER BY seq ASC LIMIT ?`)
|
|
782
|
+
.all(roomID, afterSeq, excludeSessionID ?? null, excludeSessionID ?? null, excludeName, take + 1) as Array<Record<string, string | number | null>>;
|
|
783
|
+
const hasMore = rows.length > take;
|
|
784
|
+
return { messages: rows.slice(0, take).map(historyRowMessage), nextBeforeSeq: null, hasMore, recallVersion: recallVersion(db, roomID) };
|
|
785
|
+
}
|
|
786
|
+
const rows = db.query(`SELECT ${HISTORY_COLUMNS} FROM messages WHERE room_id=? ${beforeSeq === undefined ? "" : "AND seq<? "}AND
|
|
787
|
+
${exclude} ORDER BY seq DESC LIMIT ?`).all(...(beforeSeq === undefined ? [roomID] : [roomID, beforeSeq]),
|
|
741
788
|
excludeSessionID ?? null, excludeSessionID ?? null, excludeName, take + 1) as Array<Record<string, string | number | null>>;
|
|
742
789
|
const hasMore = rows.length > take;
|
|
743
|
-
const messages = rows.slice(0, take).reverse().map(
|
|
744
|
-
const message = rowMessage(row);
|
|
745
|
-
const recalledAt = row.recalled_at === null || row.recalled_at === undefined ? undefined : Number(row.recalled_at);
|
|
746
|
-
return { ...message, ...(recalledAt !== undefined ? { text: "", recalledAt, ...(row.recalled_by ? { recalledBy: String(row.recalled_by) } : {}) } : {}), seq: Number(row.seq) };
|
|
747
|
-
});
|
|
790
|
+
const messages = rows.slice(0, take).reverse().map(historyRowMessage);
|
|
748
791
|
return { messages, nextBeforeSeq: hasMore ? messages[0]?.seq ?? null : null, hasMore, recallVersion: recallVersion(db, roomID) };
|
|
749
792
|
}).deferred();
|
|
750
793
|
}
|
|
751
794
|
|
|
795
|
+
export async function readMessage(file: string, roomID: string, messageID: string): Promise<HistoryMessage | undefined> {
|
|
796
|
+
const db = await openStateDatabase(file);
|
|
797
|
+
const row = db.query(`SELECT ${HISTORY_COLUMNS} FROM messages WHERE room_id=? AND id=?`).get(roomID, messageID) as Record<string, string | number | null> | null;
|
|
798
|
+
return row ? historyRowMessage(row) : undefined;
|
|
799
|
+
}
|
|
800
|
+
|
|
752
801
|
export async function readMessageReceipts(file: string, roomID: string, messageIDs?: string[]): Promise<MessageReceipt[] | undefined> {
|
|
753
802
|
const db = await openStateDatabase(file);
|
|
754
803
|
return db.transaction(() => {
|
package/src/state/store.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { Buffer } from "node:buffer";
|
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import os from "node:os";
|
|
7
7
|
import RoomService, { type Message, type Room } from "../rooms/room-service.ts";
|
|
8
|
-
import { acknowledgeQueued as sqliteAcknowledgeQueued, acknowledgeRead as sqliteAcknowledgeRead, answerQuestion as sqliteAnswerQuestion, appendRoomMessage as sqliteAppendRoomMessage, sendReply as sqliteSendReply, readHistoryPage, readInboxPage as sqliteInboxPage, readMessageReceipts, readQuestionExcerpt as sqliteQuestionExcerpt, readQuestions as sqliteReadQuestions, countOpenQuestions as sqliteCountOpenQuestions, readSqliteState, readUnreadPage, recallMessage as sqliteRecallMessage, revealMessageContent as sqliteRevealMessageContent, isMessageRecalled, recalledMessageIDs as sqliteRecalledMessageIDs, writeMessageReceipts, writePresenceState, writeSqliteState, type HistoryMessage, type JoinRequest, listJoinRequests as sqliteListJoinRequests, readJoinRequest as sqliteReadJoinRequest, type RecallMessageResult, type RevealMessageResult } from "./sqlite-state.ts";
|
|
8
|
+
import { acknowledgeQueued as sqliteAcknowledgeQueued, acknowledgeRead as sqliteAcknowledgeRead, answerQuestion as sqliteAnswerQuestion, appendRoomMessage as sqliteAppendRoomMessage, sendReply as sqliteSendReply, readHistoryPage, readMessage as sqliteReadMessage, readOpenQuestionRefs as sqliteReadOpenQuestionRefs, MAX_OPEN_QUESTION_REFS, readInboxPage as sqliteInboxPage, readMessageReceipts, readQuestionExcerpt as sqliteQuestionExcerpt, readQuestions as sqliteReadQuestions, countOpenQuestions as sqliteCountOpenQuestions, readSqliteState, readUnreadPage, recallMessage as sqliteRecallMessage, revealMessageContent as sqliteRevealMessageContent, isMessageRecalled, recalledMessageIDs as sqliteRecalledMessageIDs, writeMessageReceipts, writePresenceState, writeSqliteState, type HistoryMessage, type JoinRequest, listJoinRequests as sqliteListJoinRequests, readJoinRequest as sqliteReadJoinRequest, type RecallMessageResult, type RevealMessageResult } from "./sqlite-state.ts";
|
|
9
9
|
export type { JoinRequest, RecallMessageResult, RevealMessageResult } from "./sqlite-state.ts";
|
|
10
10
|
|
|
11
11
|
export function statePath(): string {
|
|
@@ -33,16 +33,22 @@ export async function readUnreadMessages(roomID: string, afterTs: number, limit
|
|
|
33
33
|
export async function readInboxMessages(sessionID: string, roomID: string | null, excludeSelf: boolean, limit = 100, afterTs?: number) {
|
|
34
34
|
return sqliteInboxPage(databasePath(), sessionID, roomID, excludeSelf, limit, afterTs);
|
|
35
35
|
}
|
|
36
|
-
export async function readHistory(roomID: string, beforeSeq?: number, limit = 100, exclude?: { sessionID: string; name: string }): Promise<{ messages: HistoryMessage[]; nextBeforeSeq: number | null; hasMore: boolean; recallVersion: number }> {
|
|
37
|
-
return readHistoryPage(databasePath(), roomID, beforeSeq, limit, exclude?.sessionID, exclude?.name);
|
|
36
|
+
export async function readHistory(roomID: string, beforeSeq?: number, limit = 100, exclude?: { sessionID: string; name: string }, afterSeq?: number): Promise<{ messages: HistoryMessage[]; nextBeforeSeq: number | null; hasMore: boolean; recallVersion: number }> {
|
|
37
|
+
return readHistoryPage(databasePath(), roomID, beforeSeq, limit, exclude?.sessionID, exclude?.name, afterSeq);
|
|
38
|
+
}
|
|
39
|
+
export async function readMessage(roomID: string, messageID: string): Promise<HistoryMessage | undefined> {
|
|
40
|
+
return sqliteReadMessage(databasePath(), roomID, messageID);
|
|
41
|
+
}
|
|
42
|
+
export async function readOpenQuestionRefs(roomID: string, limit = MAX_OPEN_QUESTION_REFS): Promise<Array<{ id: string; seq: number }>> {
|
|
43
|
+
return sqliteReadOpenQuestionRefs(databasePath(), roomID, limit);
|
|
38
44
|
}
|
|
39
45
|
export async function readQuestions(roomID: string): Promise<Message[]> { return sqliteReadQuestions(databasePath(), roomID); }
|
|
40
46
|
export async function countOpenQuestions(roomID: string): Promise<number> { return sqliteCountOpenQuestions(databasePath(), roomID); }
|
|
41
47
|
export function acknowledgeRead(roomID: string, sessionID: string, ts: number) { return sqliteAcknowledgeRead(databasePath(), roomID, sessionID, ts); }
|
|
42
48
|
export function acknowledgeQueued(roomID: string, sessionID: string, ts: number) { return sqliteAcknowledgeQueued(databasePath(), roomID, sessionID, ts); }
|
|
43
49
|
export async function answerQuestion(roomID: string, questionID: string, sessionID: string, text: string) { return sqliteAnswerQuestion(databasePath(), roomID, questionID, sessionID, text); }
|
|
44
|
-
export async function sendReply(roomID: string, targetID: string, sessionID: string, text: string) { return sqliteSendReply(databasePath(), roomID, targetID, sessionID, text); }
|
|
45
|
-
export function appendRoomMessage(roomID: string, sessionID: string, text: string, isQuestion: boolean) { return sqliteAppendRoomMessage(databasePath(), roomID, sessionID, text, isQuestion); }
|
|
50
|
+
export async function sendReply(roomID: string, targetID: string, sessionID: string, text: string, clientMessageID?: string) { return sqliteSendReply(databasePath(), roomID, targetID, sessionID, text, clientMessageID); }
|
|
51
|
+
export function appendRoomMessage(roomID: string, sessionID: string, text: string, isQuestion: boolean, clientMessageID?: string) { return sqliteAppendRoomMessage(databasePath(), roomID, sessionID, text, isQuestion, clientMessageID); }
|
|
46
52
|
export async function readQuestionExcerpt(roomID: string, questionID: string) { return sqliteQuestionExcerpt(databasePath(), roomID, questionID); }
|
|
47
53
|
export function readJoinRequest(roomID: string, sessionID: string): Promise<JoinRequest | undefined> { return sqliteReadJoinRequest(databasePath(), roomID, sessionID); }
|
|
48
54
|
export function listJoinRequests(roomID: string, agentOnly = false): Promise<JoinRequest[]> { return sqliteListJoinRequests(databasePath(), roomID, agentOnly); }
|
package/src/tui/app.mjs
CHANGED
|
@@ -338,11 +338,18 @@ export class ChatApp {
|
|
|
338
338
|
return;
|
|
339
339
|
}
|
|
340
340
|
const text = canonicalizeMentions(raw, room.participants);
|
|
341
|
+
// Reuse the attempt's id when the same failed text is sent again, so a lost
|
|
342
|
+
// response cannot produce two messages.
|
|
343
|
+
const attempt = this.pendingSend && this.pendingSend.text === raw
|
|
344
|
+
? this.pendingSend
|
|
345
|
+
: { text: raw, clientMessageID: globalThis.crypto.randomUUID() };
|
|
346
|
+
this.pendingSend = attempt;
|
|
341
347
|
this.state.draft = "";
|
|
342
348
|
this.touch();
|
|
343
349
|
try {
|
|
344
|
-
const result = await this.api.send(room.id, this.sessionID, text);
|
|
350
|
+
const result = await this.api.send(room.id, this.sessionID, text, { clientMessageID: attempt.clientMessageID });
|
|
345
351
|
if (!this.isCurrent(room.id)) return;
|
|
352
|
+
this.pendingSend = null;
|
|
346
353
|
if (Array.isArray(result?.messages)) this.merge(result.messages);
|
|
347
354
|
else if (result?.id) this.merge([result]);
|
|
348
355
|
this.state.highlight = null;
|
|
@@ -350,7 +357,8 @@ export class ChatApp {
|
|
|
350
357
|
this.setStatus("sent", "success");
|
|
351
358
|
this.markRead();
|
|
352
359
|
} catch (error) {
|
|
353
|
-
|
|
360
|
+
// Keep text typed while the request was in flight; dropping it loses work.
|
|
361
|
+
this.state.draft = this.state.draft ? `${raw}\n${this.state.draft}` : raw;
|
|
354
362
|
this.setStatus(`send failed: ${errorText(error)}`, "error");
|
|
355
363
|
}
|
|
356
364
|
}
|
package/src/tui/http.mjs
CHANGED
|
@@ -87,10 +87,24 @@ export function createApi({ url, token, requestTimeoutMs = 10000 }) {
|
|
|
87
87
|
async leave(roomId, sessionID) {
|
|
88
88
|
await call(`${room(roomId)}/leave`, { method: "POST", body: { sessionID } });
|
|
89
89
|
},
|
|
90
|
-
async
|
|
90
|
+
async getMessage(roomId, messageId, sessionID) {
|
|
91
|
+
return (await call(`${room(roomId)}/messages/${encodeURIComponent(messageId)}?${query({ sessionID })}`)).data;
|
|
92
|
+
},
|
|
93
|
+
async catchUp(roomId, sessionID, { afterSeq, limit } = {}) {
|
|
94
|
+
const pageSize = limit === undefined ? undefined : Math.min(200, Math.max(1, Math.floor(limit)));
|
|
95
|
+
return (await call(`${room(roomId)}/catch-up?${query({ sessionID, afterSeq, limit: pageSize })}`)).data;
|
|
96
|
+
},
|
|
97
|
+
async send(roomId, sessionID, text, { replyToMessageID, parentMessageId, isQuestion, clientMessageID } = {}) {
|
|
91
98
|
return (await call(`${room(roomId)}/messages`, {
|
|
92
99
|
method: "POST",
|
|
93
|
-
body: {
|
|
100
|
+
body: {
|
|
101
|
+
sessionID,
|
|
102
|
+
text,
|
|
103
|
+
...(replyToMessageID ? { replyToMessageID } : {}),
|
|
104
|
+
...(parentMessageId ? { parentMessageId } : {}),
|
|
105
|
+
...(isQuestion ? { isQuestion: true } : {}),
|
|
106
|
+
...(clientMessageID ? { clientMessageID } : {}),
|
|
107
|
+
},
|
|
94
108
|
})).data;
|
|
95
109
|
},
|
|
96
110
|
async poll(roomId, sessionID, afterTs, { signal, timeoutMs = 20000 } = {}) {
|
package/src/tui/info-app.mjs
CHANGED
|
@@ -45,6 +45,18 @@ export function attachInfo(Class) {
|
|
|
45
45
|
return null;
|
|
46
46
|
},
|
|
47
47
|
|
|
48
|
+
// A palette acts on the room it was opened for, even if the rail has since
|
|
49
|
+
// switched rooms; otherwise an announcement prompt could overwrite the new
|
|
50
|
+
// room's same-named announcement.
|
|
51
|
+
paletteRoomId(palette) {
|
|
52
|
+
const roomId = palette.roomId || this.state.current?.id;
|
|
53
|
+
if (!roomId) {
|
|
54
|
+
palette.error = "open a joined room first";
|
|
55
|
+
this.touch();
|
|
56
|
+
}
|
|
57
|
+
return roomId;
|
|
58
|
+
},
|
|
59
|
+
|
|
48
60
|
async openInfo(kind, title, hint, load) {
|
|
49
61
|
const room = this.currentInfoRoom();
|
|
50
62
|
if (!room) return;
|
|
@@ -172,13 +184,14 @@ export function attachInfo(Class) {
|
|
|
172
184
|
|
|
173
185
|
async runFileDeleteConfirm(confirm) {
|
|
174
186
|
const palette = this.state.palette;
|
|
175
|
-
|
|
176
|
-
|
|
187
|
+
if (!palette) return;
|
|
188
|
+
const roomId = this.paletteRoomId(palette);
|
|
189
|
+
if (!roomId) return;
|
|
177
190
|
palette.searching = true;
|
|
178
191
|
palette.error = "";
|
|
179
192
|
this.touch();
|
|
180
193
|
try {
|
|
181
|
-
await this.api.deleteResource(
|
|
194
|
+
await this.api.deleteResource(roomId, confirm.data.id, this.sessionID);
|
|
182
195
|
this.setStatus(`deleted ${confirm.data.name}`, "success");
|
|
183
196
|
await this.openFiles();
|
|
184
197
|
} catch (error) {
|
|
@@ -292,13 +305,13 @@ export function attachInfo(Class) {
|
|
|
292
305
|
},
|
|
293
306
|
|
|
294
307
|
async downloadFile(item) {
|
|
295
|
-
const room = this.state.current;
|
|
296
|
-
if (!room || !item?.resource) return;
|
|
297
308
|
const palette = this.state.palette;
|
|
309
|
+
const roomId = palette ? this.paletteRoomId(palette) : this.state.current?.id;
|
|
310
|
+
if (!roomId || !item?.resource) return;
|
|
298
311
|
if (palette) palette.searching = true;
|
|
299
312
|
this.touch();
|
|
300
313
|
try {
|
|
301
|
-
const payload = await this.api.resourceContent(
|
|
314
|
+
const payload = await this.api.resourceContent(roomId, item.resource.id);
|
|
302
315
|
const [{ mkdir, writeFile, access }, path] = await Promise.all([
|
|
303
316
|
import("node:fs/promises"),
|
|
304
317
|
import("node:path"),
|
|
@@ -341,12 +354,8 @@ export function attachInfo(Class) {
|
|
|
341
354
|
await this.submitMessagePrompt(prompt, value);
|
|
342
355
|
return;
|
|
343
356
|
}
|
|
344
|
-
const
|
|
345
|
-
if (!
|
|
346
|
-
palette.error = "open a joined room first";
|
|
347
|
-
this.touch();
|
|
348
|
-
return;
|
|
349
|
-
}
|
|
357
|
+
const roomId = this.paletteRoomId(palette);
|
|
358
|
+
if (!roomId) return;
|
|
350
359
|
if (prompt.action === "announcement-name") {
|
|
351
360
|
const name = String(value ?? "").trim();
|
|
352
361
|
if (!name) {
|
|
@@ -365,7 +374,7 @@ export function attachInfo(Class) {
|
|
|
365
374
|
palette.searching = true;
|
|
366
375
|
this.touch();
|
|
367
376
|
try {
|
|
368
|
-
await this.api.saveAnnouncement(
|
|
377
|
+
await this.api.saveAnnouncement(roomId, name, String(value ?? ""), this.sessionID);
|
|
369
378
|
this.setStatus(`saved announcement "${name}"`, "success");
|
|
370
379
|
await this.openAnnouncements();
|
|
371
380
|
} catch (error) {
|
|
@@ -387,7 +396,7 @@ export function attachInfo(Class) {
|
|
|
387
396
|
palette.searching = true;
|
|
388
397
|
this.touch();
|
|
389
398
|
try {
|
|
390
|
-
await this.api.answerQuestion(
|
|
399
|
+
await this.api.answerQuestion(roomId, prompt.data?.id, this.sessionID, answer);
|
|
391
400
|
this.setStatus("answer posted", "success");
|
|
392
401
|
await this.openQuestions();
|
|
393
402
|
} catch (error) {
|
|
@@ -419,7 +428,7 @@ export function attachInfo(Class) {
|
|
|
419
428
|
return;
|
|
420
429
|
}
|
|
421
430
|
const bytes = new Uint8Array(await fs.readFile(file));
|
|
422
|
-
await this.api.uploadResource(
|
|
431
|
+
await this.api.uploadResource(roomId, this.sessionID, path.basename(file), bytes);
|
|
423
432
|
this.setStatus(`uploaded ${path.basename(file)}`, "success");
|
|
424
433
|
await this.openFiles();
|
|
425
434
|
} catch (error) {
|
package/src/tui/join-app.mjs
CHANGED
|
@@ -45,14 +45,14 @@ export function attachJoinRequests(Class) {
|
|
|
45
45
|
|
|
46
46
|
async runJoinConfirm(confirm) {
|
|
47
47
|
const palette = this.state.palette;
|
|
48
|
-
const
|
|
49
|
-
if (!palette || !
|
|
48
|
+
const roomId = palette?.roomId || this.state.current?.id;
|
|
49
|
+
if (!palette || !roomId) return;
|
|
50
50
|
const decision = confirm.action === "join-approve" ? "approve" : "deny";
|
|
51
51
|
palette.searching = true;
|
|
52
52
|
palette.error = "";
|
|
53
53
|
this.touch();
|
|
54
54
|
try {
|
|
55
|
-
await this.api.decideJoin(
|
|
55
|
+
await this.api.decideJoin(roomId, confirm.data.sessionID, this.sessionID, decision);
|
|
56
56
|
this.setStatus(`${decision === "approve" ? "approved" : "denied"} ${confirm.data.name}`, "success");
|
|
57
57
|
await this.openJoinRequests();
|
|
58
58
|
} catch (error) {
|
package/src/tui/main.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import path from "node:path";
|
|
|
5
5
|
import { createApp } from "./app.mjs";
|
|
6
6
|
|
|
7
7
|
const NAME = "opencode-chat-room cli";
|
|
8
|
-
const FALLBACK_VERSION = "0.
|
|
8
|
+
const FALLBACK_VERSION = "0.8.0";
|
|
9
9
|
|
|
10
10
|
export const HELP = `opencode-chat-room cli - terminal client for a chat-room server
|
|
11
11
|
|
package/src/tui/markdown.mjs
CHANGED
|
@@ -84,10 +84,12 @@ export function prepareMarkdown(text) {
|
|
|
84
84
|
return String(text ?? "")
|
|
85
85
|
.split("\n")
|
|
86
86
|
.map((line) => {
|
|
87
|
-
const
|
|
87
|
+
const clean = line.replace(/\r$/, "");
|
|
88
|
+
const marker = clean.match(/^([ \t]*)(`{3,}|~{3,})/);
|
|
89
|
+
const closing = clean.match(/^([ \t]*)(`{3,}|~{3,})[ \t]*$/);
|
|
88
90
|
if (fence) {
|
|
89
|
-
if (
|
|
90
|
-
&&
|
|
91
|
+
if (closing && closing[2][0] === fence.char && closing[2].length >= fence.length
|
|
92
|
+
&& closing[1].length <= fence.indent + 3) fence = null;
|
|
91
93
|
return line;
|
|
92
94
|
}
|
|
93
95
|
if (indented) {
|
package/src/tui/mentions.mjs
CHANGED
|
@@ -73,7 +73,7 @@ function codeSegments(source) {
|
|
|
73
73
|
while (lineStart < source.length) {
|
|
74
74
|
const lineEnd = source.indexOf("\n", lineStart);
|
|
75
75
|
const end = lineEnd < 0 ? source.length : lineEnd;
|
|
76
|
-
const line = source.slice(lineStart, end);
|
|
76
|
+
const line = source.slice(lineStart, end).replace(/\r$/, "");
|
|
77
77
|
const opener = /^([ \t]*)(`{3,}|~{3,})/.exec(line);
|
|
78
78
|
if (opener) {
|
|
79
79
|
if (lineStart > proseStart) splitInlineCode(source, proseStart, lineStart, segments);
|
|
@@ -84,7 +84,7 @@ function codeSegments(source) {
|
|
|
84
84
|
while (scan < source.length) {
|
|
85
85
|
const nextEnd = source.indexOf("\n", scan);
|
|
86
86
|
const stop = nextEnd < 0 ? source.length : nextEnd;
|
|
87
|
-
const close = /^([ \t]*)(`{3,}|~{3,})[ \t]*$/.exec(source.slice(scan, stop));
|
|
87
|
+
const close = /^([ \t]*)(`{3,}|~{3,})[ \t]*$/.exec(source.slice(scan, stop).replace(/\r$/, ""));
|
|
88
88
|
if (close && close[2][0] === fence[0] && close[2].length >= fence.length
|
|
89
89
|
&& close[1].length <= indent + 3) {
|
|
90
90
|
closed = nextEnd < 0 ? source.length : nextEnd + 1;
|
|
@@ -106,7 +106,7 @@ function codeSegments(source) {
|
|
|
106
106
|
while (scan < source.length) {
|
|
107
107
|
const nextEnd = source.indexOf("\n", scan);
|
|
108
108
|
const stop = nextEnd < 0 ? source.length : nextEnd;
|
|
109
|
-
const current = source.slice(scan, stop);
|
|
109
|
+
const current = source.slice(scan, stop).replace(/\r$/, "");
|
|
110
110
|
if (current.trim() && !/^(?: {4,}|\t)/.test(current)) {
|
|
111
111
|
closed = scan;
|
|
112
112
|
break;
|
package/src/tui/message-app.mjs
CHANGED
|
@@ -15,6 +15,8 @@ export function attachMessageActions(Class) {
|
|
|
15
15
|
return null;
|
|
16
16
|
}
|
|
17
17
|
palette.mode = "prompt";
|
|
18
|
+
palette.roomId = this.state.current.id;
|
|
19
|
+
palette.roomParticipants = [...(this.state.current.participants || [])];
|
|
18
20
|
palette.title = title;
|
|
19
21
|
palette.subtitle = `#${this.state.current.name}`;
|
|
20
22
|
palette.error = "";
|
|
@@ -42,15 +44,16 @@ export function attachMessageActions(Class) {
|
|
|
42
44
|
|
|
43
45
|
async submitMessagePrompt(prompt, value) {
|
|
44
46
|
const palette = this.state.palette;
|
|
45
|
-
const
|
|
47
|
+
const roomId = palette?.roomId || this.state.current?.id;
|
|
48
|
+
const participants = palette?.roomParticipants || this.state.current?.participants;
|
|
46
49
|
if (!palette || palette.mode !== "prompt") return;
|
|
47
|
-
if (!
|
|
50
|
+
if (!roomId) {
|
|
48
51
|
palette.error = "open a joined room first";
|
|
49
52
|
this.touch();
|
|
50
53
|
return;
|
|
51
54
|
}
|
|
52
55
|
if (prompt.action === "message-ask") {
|
|
53
|
-
const question = canonicalizeMentions(String(value ?? "").trim(),
|
|
56
|
+
const question = canonicalizeMentions(String(value ?? "").trim(), participants);
|
|
54
57
|
if (!question) {
|
|
55
58
|
palette.error = "question text is required";
|
|
56
59
|
this.touch();
|
|
@@ -60,7 +63,7 @@ export function attachMessageActions(Class) {
|
|
|
60
63
|
palette.error = "";
|
|
61
64
|
this.touch();
|
|
62
65
|
try {
|
|
63
|
-
const result = await this.api.send(
|
|
66
|
+
const result = await this.api.send(roomId, this.sessionID, question, { isQuestion: true });
|
|
64
67
|
if (Array.isArray(result?.messages)) mergeMessages(this.state.messages, result.messages);
|
|
65
68
|
else if (result?.id) mergeMessages(this.state.messages, [result]);
|
|
66
69
|
this.state.connection = "online";
|
|
@@ -109,7 +112,7 @@ export function attachMessageActions(Class) {
|
|
|
109
112
|
return;
|
|
110
113
|
}
|
|
111
114
|
if (prompt.action === "message-reply-text") {
|
|
112
|
-
const text = canonicalizeMentions(String(value ?? "").trim(),
|
|
115
|
+
const text = canonicalizeMentions(String(value ?? "").trim(), participants);
|
|
113
116
|
if (!text) {
|
|
114
117
|
palette.error = "reply text is required";
|
|
115
118
|
this.touch();
|
|
@@ -119,8 +122,8 @@ export function attachMessageActions(Class) {
|
|
|
119
122
|
palette.error = "";
|
|
120
123
|
this.touch();
|
|
121
124
|
try {
|
|
122
|
-
const result = await this.api.send(
|
|
123
|
-
if (!this.isCurrent(
|
|
125
|
+
const result = await this.api.send(roomId, this.sessionID, text, { replyToMessageID: prompt.data.id });
|
|
126
|
+
if (!this.isCurrent(roomId)) return;
|
|
124
127
|
if (Array.isArray(result?.messages)) mergeMessages(this.state.messages, result.messages);
|
|
125
128
|
else if (result?.id) mergeMessages(this.state.messages, [result]);
|
|
126
129
|
this.state.connection = "online";
|
|
@@ -139,22 +142,22 @@ export function attachMessageActions(Class) {
|
|
|
139
142
|
|
|
140
143
|
async runMessageConfirm(confirm) {
|
|
141
144
|
const palette = this.state.palette;
|
|
142
|
-
const
|
|
143
|
-
if (!palette || !
|
|
145
|
+
const roomId = palette?.roomId || this.state.current?.id;
|
|
146
|
+
if (!palette || !roomId) return;
|
|
144
147
|
const id = confirm.data.id;
|
|
145
148
|
palette.searching = true;
|
|
146
149
|
palette.error = "";
|
|
147
150
|
this.touch();
|
|
148
151
|
try {
|
|
149
152
|
if (confirm.action === "message-recall") {
|
|
150
|
-
await this.api.recall(
|
|
153
|
+
await this.api.recall(roomId, id, this.sessionID);
|
|
151
154
|
const target = this.state.messages.find((message) => message.id === id);
|
|
152
155
|
if (target) target.recalledAt = Date.now();
|
|
153
156
|
this.closePalette();
|
|
154
157
|
this.setStatus(`recalled ${id}`, "success");
|
|
155
158
|
return;
|
|
156
159
|
}
|
|
157
|
-
const revealed = await this.api.reveal(
|
|
160
|
+
const revealed = await this.api.reveal(roomId, id, this.sessionID);
|
|
158
161
|
palette.mode = "detail";
|
|
159
162
|
palette.title = "Revealed message";
|
|
160
163
|
palette.confirm = null;
|
package/src/tui/palette-app.mjs
CHANGED
|
@@ -10,8 +10,10 @@ export function attachPalette(Class) {
|
|
|
10
10
|
openPalette({ slash = false } = {}) {
|
|
11
11
|
this.historyPages.clear();
|
|
12
12
|
this.state.help = false;
|
|
13
|
+
// Same rule as the web palette: only "/" means commands; empty input
|
|
14
|
+
// waits for a search query instead of showing a command wall.
|
|
13
15
|
this.state.palette = {
|
|
14
|
-
mode: "commands",
|
|
16
|
+
mode: slash ? "commands" : "search",
|
|
15
17
|
query: slash ? "/" : "",
|
|
16
18
|
scope: "room",
|
|
17
19
|
selected: 0,
|
|
@@ -88,16 +90,17 @@ export function attachPalette(Class) {
|
|
|
88
90
|
this.historyInflight.add(room.id);
|
|
89
91
|
try {
|
|
90
92
|
await this.fetchHistoryPage(room.id);
|
|
93
|
+
// A failed page must not consume the room's search budget.
|
|
94
|
+
this.historyPages.set(room.id, (this.historyPages.get(room.id) ?? 0) + 1);
|
|
91
95
|
} catch (error) {
|
|
92
|
-
if (this.state.palette)
|
|
96
|
+
if (this.state.palette === palette) palette.error = `history: ${error.message ?? error}`;
|
|
93
97
|
} finally {
|
|
94
98
|
this.historyInflight.delete(room.id);
|
|
95
|
-
this.historyPages.set(room.id, (this.historyPages.get(room.id) ?? 0) + 1);
|
|
96
99
|
}
|
|
97
|
-
if (this.state.palette) this.refreshPaletteResults();
|
|
100
|
+
if (this.state.palette === palette) this.refreshPaletteResults();
|
|
98
101
|
}
|
|
99
|
-
if (this.state.palette) {
|
|
100
|
-
|
|
102
|
+
if (this.state.palette === palette) {
|
|
103
|
+
palette.searching = this.historyInflight.size > 0;
|
|
101
104
|
this.refreshPaletteResults();
|
|
102
105
|
}
|
|
103
106
|
},
|
|
@@ -306,7 +309,7 @@ export function attachPalette(Class) {
|
|
|
306
309
|
const query = String(value ?? "");
|
|
307
310
|
palette.error = "";
|
|
308
311
|
if (!query.trim()) {
|
|
309
|
-
palette.mode = "
|
|
312
|
+
palette.mode = "search";
|
|
310
313
|
palette.query = "";
|
|
311
314
|
palette.results = [];
|
|
312
315
|
palette.selected = 0;
|
package/src/tui/reminder-app.mjs
CHANGED
|
@@ -23,6 +23,10 @@ export function attachReminders(Class) {
|
|
|
23
23
|
return palette?.mode === "info" && palette.kind === "reminders" ? palette : null;
|
|
24
24
|
},
|
|
25
25
|
|
|
26
|
+
reminderRoomId(palette) {
|
|
27
|
+
return palette?.roomId || this.state.current?.id;
|
|
28
|
+
},
|
|
29
|
+
|
|
26
30
|
selectedReminder() {
|
|
27
31
|
const palette = this.reminderPalette();
|
|
28
32
|
return palette ? this.paletteItems()[palette.selected] : null;
|
|
@@ -57,13 +61,13 @@ export function attachReminders(Class) {
|
|
|
57
61
|
async toggleReminder() {
|
|
58
62
|
const palette = this.reminderPalette();
|
|
59
63
|
const reminder = this.selectedReminder();
|
|
60
|
-
const
|
|
61
|
-
if (!palette || !reminder || !
|
|
64
|
+
const roomId = this.reminderRoomId(palette);
|
|
65
|
+
if (!palette || !reminder || !roomId) return;
|
|
62
66
|
palette.searching = true;
|
|
63
67
|
palette.error = "";
|
|
64
68
|
this.touch();
|
|
65
69
|
try {
|
|
66
|
-
await this.api.updateReminder(
|
|
70
|
+
await this.api.updateReminder(roomId, reminder.value, this.sessionID, { paused: !reminder.paused });
|
|
67
71
|
this.setStatus(`${reminder.paused ? "resumed" : "paused"} reminder`, "success");
|
|
68
72
|
await this.openReminders();
|
|
69
73
|
} catch (error) {
|
|
@@ -93,9 +97,9 @@ export function attachReminders(Class) {
|
|
|
93
97
|
|
|
94
98
|
async submitReminderPrompt(prompt, value) {
|
|
95
99
|
const palette = this.state.palette;
|
|
96
|
-
const
|
|
100
|
+
const roomId = this.reminderRoomId(palette);
|
|
97
101
|
if (!palette || palette.mode !== "prompt") return;
|
|
98
|
-
if (!
|
|
102
|
+
if (!roomId) {
|
|
99
103
|
palette.error = "open a joined room first";
|
|
100
104
|
this.touch();
|
|
101
105
|
return;
|
|
@@ -131,7 +135,7 @@ export function attachReminders(Class) {
|
|
|
131
135
|
palette.error = "";
|
|
132
136
|
this.touch();
|
|
133
137
|
try {
|
|
134
|
-
await this.api.createReminder(
|
|
138
|
+
await this.api.createReminder(roomId, this.sessionID, prompt.data.text, schedule);
|
|
135
139
|
this.setStatus("reminder created", "success");
|
|
136
140
|
await this.openReminders();
|
|
137
141
|
} catch (error) {
|
|
@@ -154,7 +158,7 @@ export function attachReminders(Class) {
|
|
|
154
158
|
palette.error = "";
|
|
155
159
|
this.touch();
|
|
156
160
|
try {
|
|
157
|
-
await this.api.updateReminder(
|
|
161
|
+
await this.api.updateReminder(roomId, prompt.data.id, this.sessionID, { text });
|
|
158
162
|
this.setStatus("reminder updated", "success");
|
|
159
163
|
await this.openReminders();
|
|
160
164
|
} catch (error) {
|
|
@@ -169,12 +173,12 @@ export function attachReminders(Class) {
|
|
|
169
173
|
|
|
170
174
|
async runReminderConfirm(confirm) {
|
|
171
175
|
const palette = this.state.palette;
|
|
172
|
-
const
|
|
173
|
-
if (!palette || !
|
|
176
|
+
const roomId = this.reminderRoomId(palette);
|
|
177
|
+
if (!palette || !roomId) return;
|
|
174
178
|
palette.searching = true;
|
|
175
179
|
this.touch();
|
|
176
180
|
try {
|
|
177
|
-
await this.api.deleteReminder(
|
|
181
|
+
await this.api.deleteReminder(roomId, confirm.data.id, this.sessionID);
|
|
178
182
|
this.setStatus("reminder deleted", "success");
|
|
179
183
|
await this.openReminders();
|
|
180
184
|
} catch (error) {
|