@alexsun-top/opencode-chat-room 0.8.3 → 0.8.5

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.
Files changed (156) hide show
  1. package/CHANGELOG.md +7 -1
  2. package/README.md +5 -5
  3. package/README.zh-CN.md +5 -5
  4. package/cli.ts +1 -1
  5. package/dist/cli.js +35 -16
  6. package/package.json +15 -9
  7. package/packages/chat-room-channeld/README.md +3 -2
  8. package/packages/chat-room-channeld/src/inbound.ts +3 -6
  9. package/packages/chat-room-channeld/src/pg/sql.mjs +157 -142
  10. package/packages/chat-room-channeld/src/pg/sql.mts +175 -0
  11. package/packages/chat-room-channeld/src/pg/worker.mjs +107 -99
  12. package/packages/chat-room-channeld/src/pg/worker.mts +166 -0
  13. package/plugin.ts +1 -1
  14. package/server/assets/chat/admin-badge.js +1 -1
  15. package/server/assets/chat/admin.js +16 -10
  16. package/server/assets/chat/announcements.js +12 -2
  17. package/server/assets/chat/attachment-store.js +15 -6
  18. package/server/assets/chat/attachments.js +48 -33
  19. package/server/assets/chat/chat-background.js +8 -14
  20. package/server/assets/chat/clipboard.js +2 -1
  21. package/server/assets/chat/confirm-dialog.js +3 -3
  22. package/server/assets/chat/copy-action.js +1 -2
  23. package/server/assets/chat/diagram-viewer.js +7 -9
  24. package/server/assets/chat/doc-preview.js +19 -12
  25. package/server/assets/chat/editor.js +87 -61
  26. package/server/assets/chat/events.js +49 -34
  27. package/server/assets/chat/files.js +45 -13
  28. package/server/assets/chat/history-loader.js +5 -3
  29. package/server/assets/chat/image-zoom.js +21 -17
  30. package/server/assets/chat/install-prompt.js +10 -9
  31. package/server/assets/chat/integration-account-schema.js +5 -3
  32. package/server/assets/chat/integration-editor.js +2 -2
  33. package/server/assets/chat/integration-values.js +17 -11
  34. package/server/assets/chat/integrations.js +138 -81
  35. package/server/assets/chat/join-requests.js +20 -13
  36. package/server/assets/chat/markdown-footnotes.js +8 -8
  37. package/server/assets/chat/markdown.js +48 -38
  38. package/server/assets/chat/members.js +48 -25
  39. package/server/assets/chat/mentions.js +39 -12
  40. package/server/assets/chat/message-cache.js +2 -2
  41. package/server/assets/chat/message-polling.js +40 -21
  42. package/server/assets/chat/message-window.js +10 -6
  43. package/server/assets/chat/messages.js +70 -46
  44. package/server/assets/chat/office-preview.js +3 -3
  45. package/server/assets/chat/palette.js +45 -29
  46. package/server/assets/chat/panels.js +19 -1
  47. package/server/assets/chat/pwa.js +5 -4
  48. package/server/assets/chat/questions.js +25 -22
  49. package/server/assets/chat/recall.js +39 -21
  50. package/server/assets/chat/receipts.js +9 -7
  51. package/server/assets/chat/reminders.js +25 -8
  52. package/server/assets/chat/replies.js +34 -15
  53. package/server/assets/chat/resource-format.js +2 -2
  54. package/server/assets/chat/room-list.js +2 -2
  55. package/server/assets/chat/room-watcher.js +8 -4
  56. package/server/assets/chat/rooms.js +51 -40
  57. package/server/assets/chat/search.js +8 -6
  58. package/server/assets/chat/settings.js +16 -14
  59. package/server/assets/chat/shiki.js +1 -1
  60. package/server/assets/chat/shortcuts.js +3 -3
  61. package/server/assets/chat/side-pane.js +4 -3
  62. package/server/assets/chat/state.js +65 -37
  63. package/server/assets/chat/system-events.js +6 -5
  64. package/server/assets/chat/system-messages.js +15 -15
  65. package/server/assets/chat/task-form.js +5 -5
  66. package/server/assets/chat/task-row.js +1 -1
  67. package/server/assets/chat/tasks.js +41 -28
  68. package/server/assets/chat/window-controls.js +3 -2
  69. package/server/assets/conversation.css +14 -2
  70. package/server/assets/doc-preview.css +6 -0
  71. package/server/assets/office/THIRD-PARTY-NOTICES.txt +23 -1
  72. package/server/assets/office/licenses/docx-preview-HEADER.txt +6 -0
  73. package/server/assets/office/licenses/echarts-LICENSE-d3.txt +27 -0
  74. package/server/assets/office/licenses/echarts-NOTICE.txt +5 -0
  75. package/server/assets/office/licenses/immediate-LICENSE.txt +20 -0
  76. package/server/assets/office/licenses/lie-LICENSE.txt +7 -0
  77. package/server/assets/office/licenses/pako-LICENSE.txt +21 -0
  78. package/server/assets/office/licenses/pako-ZLIB.txt +18 -0
  79. package/server/assets/office/licenses/setimmediate-LICENSE.txt +20 -0
  80. package/server/chat.html +1 -0
  81. package/server/sw.js +3 -1
  82. package/skills/chatroom/SKILL.md +9 -0
  83. package/src/README.md +1 -1
  84. package/src/agent/agent-receipts.ts +12 -4
  85. package/src/center/center-client.ts +1 -1
  86. package/src/state/pg-sql.mjs +157 -142
  87. package/src/state/pg-sql.mts +175 -0
  88. package/src/state/pg-worker.mjs +107 -99
  89. package/src/state/pg-worker.mts +166 -0
  90. package/src/state/store.ts +21 -7
  91. package/src/tui/app-types.mjs +1 -0
  92. package/src/tui/app-types.mts +175 -0
  93. package/src/tui/app.mjs +426 -423
  94. package/src/tui/app.mts +500 -0
  95. package/src/tui/config.mjs +166 -158
  96. package/src/tui/config.mts +247 -0
  97. package/src/tui/http.mjs +239 -206
  98. package/src/tui/http.mts +412 -0
  99. package/src/tui/i18n.mjs +17 -20
  100. package/src/tui/i18n.mts +42 -0
  101. package/src/tui/info-app.mjs +431 -427
  102. package/src/tui/info-app.mts +500 -0
  103. package/src/tui/info-content.mjs +205 -199
  104. package/src/tui/info-content.mts +341 -0
  105. package/src/tui/join-app.mjs +75 -64
  106. package/src/tui/join-app.mts +99 -0
  107. package/src/tui/locales/en.mjs +302 -320
  108. package/src/tui/locales/en.mts +349 -0
  109. package/src/tui/locales/zh-CN.mjs +302 -320
  110. package/src/tui/locales/zh-CN.mts +349 -0
  111. package/src/tui/main.mjs +219 -213
  112. package/src/tui/main.mts +255 -0
  113. package/src/tui/markdown.mjs +128 -272
  114. package/src/tui/markdown.mts +152 -0
  115. package/src/tui/mentions.mjs +181 -184
  116. package/src/tui/mentions.mts +251 -0
  117. package/src/tui/message-app.mjs +181 -173
  118. package/src/tui/message-app.mts +213 -0
  119. package/src/tui/message-view.mjs +90 -111
  120. package/src/tui/message-view.mts +151 -0
  121. package/src/tui/messages.mjs +55 -49
  122. package/src/tui/messages.mts +106 -0
  123. package/src/tui/palette-app.mjs +364 -344
  124. package/src/tui/palette-app.mts +388 -0
  125. package/src/tui/palette.mjs +100 -98
  126. package/src/tui/palette.mts +176 -0
  127. package/src/tui/prefs.mjs +56 -63
  128. package/src/tui/prefs.mts +126 -0
  129. package/src/tui/reminder-app.mjs +191 -181
  130. package/src/tui/reminder-app.mts +228 -0
  131. package/src/tui/room-settings-app.mjs +257 -242
  132. package/src/tui/room-settings-app.mts +301 -0
  133. package/src/tui/session.mjs +30 -29
  134. package/src/tui/session.mts +51 -0
  135. package/src/tui/settings-app.mjs +151 -138
  136. package/src/tui/settings-app.mts +179 -0
  137. package/src/tui/ui-content.mjs +426 -421
  138. package/src/tui/ui-content.mts +499 -0
  139. package/src/tui/ui-help.mjs +58 -67
  140. package/src/tui/ui-help.mts +87 -0
  141. package/src/tui/ui-mentions.mjs +34 -36
  142. package/src/tui/ui-mentions.mts +60 -0
  143. package/src/tui/ui-overlay-view.mjs +259 -267
  144. package/src/tui/ui-overlay-view.mts +322 -0
  145. package/src/tui/ui-suggest-view.mjs +54 -57
  146. package/src/tui/ui-suggest-view.mts +78 -0
  147. package/src/tui/ui-suggest.mjs +164 -167
  148. package/src/tui/ui-suggest.mts +248 -0
  149. package/src/tui/ui-theme.mjs +52 -57
  150. package/src/tui/ui-theme.mts +98 -0
  151. package/src/tui/ui-view.mjs +267 -275
  152. package/src/tui/ui-view.mts +308 -0
  153. package/src/tui/ui.mjs +372 -359
  154. package/src/tui/ui.mts +440 -0
  155. package/src/tui/wire.mjs +215 -0
  156. package/src/tui/wire.mts +383 -0
@@ -0,0 +1,251 @@
1
+ // Mention helpers shared by the composer suggestions and outgoing messages.
2
+ // Display names stay visible while typing; the wire format is applied on send.
3
+ import { t } from "./i18n.mjs";
4
+
5
+ export interface Participant {
6
+ id?: string;
7
+ name?: string;
8
+ }
9
+
10
+ export interface MentionItem {
11
+ name: string;
12
+ insert: string;
13
+ label: string;
14
+ }
15
+
16
+ export interface MentionTrigger {
17
+ start: number;
18
+ query: string;
19
+ cursor: number;
20
+ }
21
+
22
+ export interface MentionRange {
23
+ start: number;
24
+ end: number;
25
+ }
26
+
27
+ interface Segment {
28
+ text: string;
29
+ code: boolean;
30
+ start: number;
31
+ end: number;
32
+ }
33
+
34
+ const escapeRegExp = (value: string) => String(value).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
35
+
36
+ export function mentionNames(participants: readonly Participant[] = []): string[] {
37
+ const names: string[] = [];
38
+ const seen = new Set(["all"]);
39
+ const list = Array.isArray(participants) ? participants : [];
40
+ for (const participant of list) {
41
+ const name = String(participant?.name ?? participant?.id ?? "").trim();
42
+ if (!name || seen.has(name.toLowerCase())) continue;
43
+ seen.add(name.toLowerCase());
44
+ names.push(name);
45
+ }
46
+ return names;
47
+ }
48
+
49
+ export function mentionItems(participants: readonly Participant[], query = ""): MentionItem[] {
50
+ const needle = String(query ?? "").toLowerCase();
51
+ const items: MentionItem[] = mentionNames(participants).map((name) => ({
52
+ name,
53
+ insert: `@${name}`,
54
+ label: name,
55
+ }));
56
+ items.push({ name: "all", insert: "@all", label: t("mentions.everyone") });
57
+ return items.filter((item) => {
58
+ const haystack = `${item.label} ${item.name}`.toLowerCase();
59
+ return !needle || haystack.includes(needle);
60
+ });
61
+ }
62
+
63
+ /** Locate the @token at the end of the draft, outside email-like tokens. */
64
+ export function mentionTrigger(text: string): MentionTrigger | null {
65
+ const source = String(text ?? "");
66
+ const match = source.match(/(^|[^\p{L}\p{N}_@])@([^\n@]{0,64})$/u);
67
+ if (!match) return null;
68
+ const query = match[2] ?? "";
69
+ return { start: source.length - query.length - 1, query, cursor: source.length };
70
+ }
71
+
72
+ export function insertMention(draft: string, trigger: MentionTrigger | null, insert: string): string {
73
+ const source = String(draft ?? "");
74
+ const at = trigger ?? mentionTrigger(source);
75
+ if (!at) return source;
76
+ const before = source.slice(0, at.start);
77
+ const after = source.slice(at.cursor ?? source.length);
78
+ return `${before}${insert} ${after}`;
79
+ }
80
+
81
+ /** Find a closing backtick run of exactly `length`, never a longer run. */
82
+ function closingBackticks(source: string, from: number, end: number, length: number): number {
83
+ let i = from;
84
+ while (i < end) {
85
+ if (source.charAt(i) !== "`") {
86
+ i += 1;
87
+ continue;
88
+ }
89
+ let run = 0;
90
+ while (i + run < end && source.charAt(i + run) === "`") run += 1;
91
+ if (run === length) return i;
92
+ i += run;
93
+ }
94
+ return -1;
95
+ }
96
+
97
+ /** Split Markdown prose from fenced/indented code and inline code spans. */
98
+ function codeSegments(source: string): Segment[] {
99
+ const segments: Segment[] = [];
100
+ let proseStart = 0;
101
+ let lineStart = 0;
102
+ const push = (start: number, end: number, code: boolean) => {
103
+ if (end > start) segments.push({ text: source.slice(start, end), code, start, end });
104
+ };
105
+ while (lineStart < source.length) {
106
+ const lineEnd = source.indexOf("\n", lineStart);
107
+ const end = lineEnd < 0 ? source.length : lineEnd;
108
+ const line = source.slice(lineStart, end).replace(/\r$/, "");
109
+ const opener = /^([ \t]*)(`{3,}|~{3,})/.exec(line);
110
+ if (opener) {
111
+ if (lineStart > proseStart) splitInlineCode(source, proseStart, lineStart, segments);
112
+ const fence = opener[2] ?? "";
113
+ const indent = (opener[1] ?? "").length;
114
+ let scan = lineEnd < 0 ? source.length : lineEnd + 1;
115
+ let closed = source.length;
116
+ while (scan < source.length) {
117
+ const nextEnd = source.indexOf("\n", scan);
118
+ const stop = nextEnd < 0 ? source.length : nextEnd;
119
+ const close = /^([ \t]*)(`{3,}|~{3,})[ \t]*$/.exec(source.slice(scan, stop).replace(/\r$/, ""));
120
+ const closeFence = close?.[2] ?? "";
121
+ if (close && closeFence.charAt(0) === fence.charAt(0) && closeFence.length >= fence.length
122
+ && (close[1] ?? "").length <= indent + 3) {
123
+ closed = nextEnd < 0 ? source.length : nextEnd + 1;
124
+ break;
125
+ }
126
+ scan = nextEnd < 0 ? source.length : nextEnd + 1;
127
+ }
128
+ push(lineStart, closed, true);
129
+ proseStart = closed;
130
+ lineStart = closed;
131
+ continue;
132
+ }
133
+ // CommonMark indented code is also literal. Treat four spaces/tab as code
134
+ // rather than risking a mention rewrite inside it.
135
+ if (/^(?: {4,}|\t)/.test(line)) {
136
+ if (lineStart > proseStart) splitInlineCode(source, proseStart, lineStart, segments);
137
+ let scan = lineStart;
138
+ let closed = source.length;
139
+ while (scan < source.length) {
140
+ const nextEnd = source.indexOf("\n", scan);
141
+ const stop = nextEnd < 0 ? source.length : nextEnd;
142
+ const current = source.slice(scan, stop).replace(/\r$/, "");
143
+ if (current.trim() && !/^(?: {4,}|\t)/.test(current)) {
144
+ closed = scan;
145
+ break;
146
+ }
147
+ scan = nextEnd < 0 ? source.length : nextEnd + 1;
148
+ }
149
+ push(lineStart, closed, true);
150
+ proseStart = closed;
151
+ lineStart = closed;
152
+ continue;
153
+ }
154
+ lineStart = lineEnd < 0 ? source.length : lineEnd + 1;
155
+ }
156
+ splitInlineCode(source, proseStart, source.length, segments);
157
+ return segments;
158
+ }
159
+
160
+ function splitInlineCode(source: string, start: number, end: number, segments: Segment[]): void {
161
+ let prose = start;
162
+ let i = start;
163
+ while (i < end) {
164
+ if (source.charAt(i) !== "`") {
165
+ i += 1;
166
+ continue;
167
+ }
168
+ let run = 1;
169
+ while (i + run < end && source.charAt(i + run) === "`") run += 1;
170
+ const close = closingBackticks(source, i + run, end, run);
171
+ if (close < 0) {
172
+ i += run;
173
+ continue;
174
+ }
175
+ if (i > prose) segments.push({ text: source.slice(prose, i), code: false, start: prose, end: i });
176
+ segments.push({ text: source.slice(i, close + run), code: true, start: i, end: close + run });
177
+ prose = close + run;
178
+ i = prose;
179
+ }
180
+ if (end > prose) segments.push({ text: source.slice(prose, end), code: false, start: prose, end });
181
+ }
182
+
183
+ function convertPlain(segment: string, names: readonly string[]): string {
184
+ if (!segment) return segment;
185
+ const candidates = ["all", ...names].sort((a, b) => b.length - a.length);
186
+ const pattern = new RegExp(
187
+ `(?<![\\p{L}\\p{N}_.@])@(${candidates.map(escapeRegExp).join("|")})(?![\\p{L}\\p{N}_])`,
188
+ "gu",
189
+ );
190
+ return segment.replace(pattern, (_match: string, name: string) => `<at>@${name}</at>`);
191
+ }
192
+
193
+ function convertProse(source: string, names: readonly string[]): string {
194
+ const tag = /<at>[\s\S]*?<\/at>/giu;
195
+ let output = "";
196
+ let last = 0;
197
+ for (const match of source.matchAll(tag)) {
198
+ output += convertPlain(source.slice(last, match.index), names);
199
+ output += match[0];
200
+ last = match.index + match[0].length;
201
+ }
202
+ return output + convertPlain(source.slice(last), names);
203
+ }
204
+
205
+ /** Convert known @names and @all to <at> tags, preserving code and existing tags. */
206
+ export function canonicalizeMentions(text: string, participants: readonly Participant[] = []): string {
207
+ const source = String(text ?? "");
208
+ const names = mentionNames(participants);
209
+ return codeSegments(source)
210
+ .map((segment) => (segment.code ? segment.text : convertProse(segment.text, names)))
211
+ .join("");
212
+ }
213
+
214
+ /** Character ranges for visible mention chips, excluding email-like tokens. */
215
+ export function mentionRanges(text: string, participants: readonly Participant[] = []): MentionRange[] {
216
+ const source = String(text ?? "");
217
+ const ranges: MentionRange[] = [];
218
+ const candidates = ["all", ...mentionNames(participants)].sort((a, b) => b.length - a.length);
219
+ const pattern = new RegExp(
220
+ `(?<![\\p{L}\\p{N}_.@])@(${candidates.map(escapeRegExp).join("|")})(?![\\p{L}\\p{N}_])`,
221
+ "gu",
222
+ );
223
+ for (const segment of codeSegments(source)) {
224
+ if (segment.code) continue;
225
+ const tag = /<at>([\s\S]*?)<\/at>/giu;
226
+ let last = 0;
227
+ const plain: [number, number][] = [];
228
+ for (const match of segment.text.matchAll(tag)) {
229
+ const inner = match[1] ?? "";
230
+ const trimmed = inner.trim();
231
+ const at = trimmed.indexOf("@");
232
+ if (at >= 0) {
233
+ const innerStart = segment.start + match.index + 4 + (inner.length - inner.trimStart().length);
234
+ ranges.push({ start: innerStart + at, end: innerStart + trimmed.length });
235
+ }
236
+ plain.push([last, match.index]);
237
+ last = match.index + match[0].length;
238
+ }
239
+ plain.push([last, segment.text.length]);
240
+ for (const [start, end] of plain) {
241
+ const piece = segment.text.slice(start, end);
242
+ for (const match of piece.matchAll(pattern)) {
243
+ ranges.push({
244
+ start: segment.start + start + match.index,
245
+ end: segment.start + start + match.index + match[0].length,
246
+ });
247
+ }
248
+ }
249
+ }
250
+ return ranges.sort((a, b) => a.start - b.start);
251
+ }
@@ -3,180 +3,188 @@
3
3
  import { mergeMessages } from "./messages.mjs";
4
4
  import { canonicalizeMentions } from "./mentions.mjs";
5
5
  import { t } from "./i18n.mjs";
6
-
7
6
  const errorText = (error) => (error instanceof Error ? error.message : String(error ?? "unknown error"));
8
-
9
7
  export function attachMessageActions(Class) {
10
- Object.assign(Class.prototype, {
11
- messageActionPalette(title, label, action, data = {}) {
12
- const palette = this.state.palette;
13
- if (!palette || !this.state.current || !this.state.joined) {
14
- this.state.palette = null;
15
- this.setStatus(t("info.joinFirst"), "error");
16
- return null;
17
- }
18
- palette.mode = "prompt";
19
- palette.roomId = this.state.current.id;
20
- palette.roomParticipants = [...(this.state.current.participants || [])];
21
- palette.title = title;
22
- palette.subtitle = `#${this.state.current.name}`;
23
- palette.error = "";
24
- palette.prompt = { label, value: "", action, data };
25
- palette.hint = t("palette.enterNextHint");
26
- this.touch();
27
- return palette;
28
- },
29
-
30
- startMessageRecall() {
31
- return this.messageActionPalette(t("message.recallTitle"), t("message.recallPrompt"), "message-recall-id");
32
- },
33
-
34
- startMessageReveal() {
35
- return this.messageActionPalette(t("message.revealTitle"), t("message.revealPrompt"), "message-reveal-id");
36
- },
37
-
38
- startMessageReply() {
39
- return this.messageActionPalette(t("message.replyTitle"), t("message.replyPrompt"), "message-reply-id");
40
- },
41
-
42
- startAskQuestion() {
43
- return this.messageActionPalette(t("message.askTitle"), t("message.askPrompt"), "message-ask");
44
- },
45
-
46
- async submitMessagePrompt(prompt, value) {
47
- const palette = this.state.palette;
48
- const roomId = palette?.roomId || this.state.current?.id;
49
- const participants = palette?.roomParticipants || this.state.current?.participants;
50
- if (!palette || palette.mode !== "prompt") return;
51
- if (!roomId) {
52
- palette.error = t("info.joinFirst");
53
- this.touch();
54
- return;
55
- }
56
- if (prompt.action === "message-ask") {
57
- const question = canonicalizeMentions(String(value ?? "").trim(), participants);
58
- if (!question) {
59
- palette.error = t("message.questionRequired");
60
- this.touch();
61
- return;
62
- }
63
- palette.searching = true;
64
- palette.error = "";
65
- this.touch();
66
- try {
67
- const result = await this.api.send(roomId, this.sessionID, question, { isQuestion: true });
68
- if (Array.isArray(result?.messages)) mergeMessages(this.state.messages, result.messages);
69
- else if (result?.id) mergeMessages(this.state.messages, [result]);
70
- this.state.connection = "online";
71
- this.closePalette();
72
- this.setStatus(t("message.questionSent"), "success");
73
- this.markRead();
74
- } catch (error) {
75
- if (this.state.palette === palette) {
76
- palette.searching = false;
77
- palette.error = errorText(error);
8
+ Object.assign(Class.prototype, {
9
+ messageActionPalette(title, label, action, data = {}) {
10
+ const palette = this.state.palette;
11
+ const current = this.state.current;
12
+ if (!palette || !current || !this.state.joined) {
13
+ this.state.palette = null;
14
+ this.setStatus(t("info.joinFirst"), "error");
15
+ return null;
16
+ }
17
+ palette.mode = "prompt";
18
+ palette.roomId = current.id;
19
+ palette.roomParticipants = [...(current.participants || [])];
20
+ palette.title = title;
21
+ palette.subtitle = `#${current.name}`;
22
+ palette.error = "";
23
+ palette.prompt = { label, value: "", action, data };
24
+ palette.hint = t("palette.enterNextHint");
78
25
  this.touch();
79
- }
80
- }
81
- return;
82
- }
83
- const id = String(value ?? "").trim();
84
- if (!id) {
85
- palette.error = t("message.idRequired");
86
- this.touch();
87
- return;
88
- }
89
- if (prompt.action === "message-recall-id" || prompt.action === "message-reveal-id") {
90
- const recall = prompt.action === "message-recall-id";
91
- palette.mode = "confirm";
92
- palette.previous = { mode: "prompt", hint: palette.hint };
93
- palette.confirm = {
94
- text: recall ? t("message.recallConfirm", { id }) : t("message.revealConfirm", { id }),
95
- action: recall ? "message-recall" : "message-reveal",
96
- data: { id },
97
- };
98
- palette.hint = t("palette.confirmHint");
99
- palette.error = "";
100
- this.touch();
101
- return;
102
- }
103
- if (prompt.action === "message-reply-id") {
104
- palette.prompt = {
105
- label: t("message.replyLabel", { id }),
106
- value: "",
107
- action: "message-reply-text",
108
- data: { id },
109
- };
110
- palette.hint = t("message.replyHint");
111
- palette.error = "";
112
- this.touch();
113
- return;
114
- }
115
- if (prompt.action === "message-reply-text") {
116
- const text = canonicalizeMentions(String(value ?? "").trim(), participants);
117
- if (!text) {
118
- palette.error = t("message.replyRequired");
119
- this.touch();
120
- return;
121
- }
122
- palette.searching = true;
123
- palette.error = "";
124
- this.touch();
125
- try {
126
- const result = await this.api.send(roomId, this.sessionID, text, { replyToMessageID: prompt.data.id });
127
- if (!this.isCurrent(roomId)) return;
128
- if (Array.isArray(result?.messages)) mergeMessages(this.state.messages, result.messages);
129
- else if (result?.id) mergeMessages(this.state.messages, [result]);
130
- this.state.connection = "online";
131
- this.closePalette();
132
- this.setStatus(t("message.replySent"), "success");
133
- this.markRead();
134
- } catch (error) {
135
- if (this.state.palette === palette) {
136
- palette.searching = false;
137
- palette.error = errorText(error);
26
+ return palette;
27
+ },
28
+ startMessageRecall() {
29
+ return this.messageActionPalette(t("message.recallTitle"), t("message.recallPrompt"), "message-recall-id");
30
+ },
31
+ startMessageReveal() {
32
+ return this.messageActionPalette(t("message.revealTitle"), t("message.revealPrompt"), "message-reveal-id");
33
+ },
34
+ startMessageReply() {
35
+ return this.messageActionPalette(t("message.replyTitle"), t("message.replyPrompt"), "message-reply-id");
36
+ },
37
+ startAskQuestion() {
38
+ return this.messageActionPalette(t("message.askTitle"), t("message.askPrompt"), "message-ask");
39
+ },
40
+ async submitMessagePrompt(prompt, value) {
41
+ const palette = this.state.palette;
42
+ const roomId = palette?.roomId || this.state.current?.id;
43
+ const participants = palette?.roomParticipants || this.state.current?.participants;
44
+ if (!palette || palette.mode !== "prompt")
45
+ return;
46
+ if (!roomId) {
47
+ palette.error = t("info.joinFirst");
48
+ this.touch();
49
+ return;
50
+ }
51
+ if (prompt.action === "message-ask") {
52
+ const question = canonicalizeMentions(String(value ?? "").trim(), participants);
53
+ if (!question) {
54
+ palette.error = t("message.questionRequired");
55
+ this.touch();
56
+ return;
57
+ }
58
+ palette.searching = true;
59
+ palette.error = "";
60
+ this.touch();
61
+ try {
62
+ const result = await this.api.send(roomId, this.sessionID, question, { isQuestion: true });
63
+ const messages = result?.messages;
64
+ if (Array.isArray(messages))
65
+ mergeMessages(this.state.messages, messages);
66
+ else if (result?.id)
67
+ mergeMessages(this.state.messages, [result]);
68
+ this.state.connection = "online";
69
+ this.closePalette();
70
+ this.setStatus(t("message.questionSent"), "success");
71
+ this.markRead();
72
+ }
73
+ catch (error) {
74
+ if (this.state.palette === palette) {
75
+ palette.searching = false;
76
+ palette.error = errorText(error);
77
+ this.touch();
78
+ }
79
+ }
80
+ return;
81
+ }
82
+ const id = String(value ?? "").trim();
83
+ if (!id) {
84
+ palette.error = t("message.idRequired");
85
+ this.touch();
86
+ return;
87
+ }
88
+ if (prompt.action === "message-recall-id" || prompt.action === "message-reveal-id") {
89
+ const recall = prompt.action === "message-recall-id";
90
+ palette.mode = "confirm";
91
+ palette.previous = { mode: "prompt", hint: palette.hint };
92
+ palette.confirm = {
93
+ text: recall ? t("message.recallConfirm", { id }) : t("message.revealConfirm", { id }),
94
+ action: recall ? "message-recall" : "message-reveal",
95
+ data: { id },
96
+ };
97
+ palette.hint = t("palette.confirmHint");
98
+ palette.error = "";
99
+ this.touch();
100
+ return;
101
+ }
102
+ if (prompt.action === "message-reply-id") {
103
+ palette.prompt = {
104
+ label: t("message.replyLabel", { id }),
105
+ value: "",
106
+ action: "message-reply-text",
107
+ data: { id },
108
+ };
109
+ palette.hint = t("message.replyHint");
110
+ palette.error = "";
111
+ this.touch();
112
+ return;
113
+ }
114
+ if (prompt.action === "message-reply-text") {
115
+ const text = canonicalizeMentions(String(value ?? "").trim(), participants);
116
+ if (!text) {
117
+ palette.error = t("message.replyRequired");
118
+ this.touch();
119
+ return;
120
+ }
121
+ palette.searching = true;
122
+ palette.error = "";
123
+ this.touch();
124
+ try {
125
+ const result = await this.api.send(roomId, this.sessionID, text, { replyToMessageID: prompt.data.id });
126
+ if (!this.isCurrent(roomId))
127
+ return;
128
+ const messages = result?.messages;
129
+ if (Array.isArray(messages))
130
+ mergeMessages(this.state.messages, messages);
131
+ else if (result?.id)
132
+ mergeMessages(this.state.messages, [result]);
133
+ this.state.connection = "online";
134
+ this.closePalette();
135
+ this.setStatus(t("message.replySent"), "success");
136
+ this.markRead();
137
+ }
138
+ catch (error) {
139
+ if (this.state.palette === palette) {
140
+ palette.searching = false;
141
+ palette.error = errorText(error);
142
+ this.touch();
143
+ }
144
+ }
145
+ }
146
+ },
147
+ async runMessageConfirm(confirm) {
148
+ const palette = this.state.palette;
149
+ const roomId = palette?.roomId || this.state.current?.id;
150
+ if (!palette || !roomId)
151
+ return;
152
+ const id = confirm.data.id;
153
+ if (!id)
154
+ return;
155
+ palette.searching = true;
156
+ palette.error = "";
138
157
  this.touch();
139
- }
140
- }
141
- }
142
- },
143
-
144
- async runMessageConfirm(confirm) {
145
- const palette = this.state.palette;
146
- const roomId = palette?.roomId || this.state.current?.id;
147
- if (!palette || !roomId) return;
148
- const id = confirm.data.id;
149
- palette.searching = true;
150
- palette.error = "";
151
- this.touch();
152
- try {
153
- if (confirm.action === "message-recall") {
154
- await this.api.recall(roomId, id, this.sessionID);
155
- const target = this.state.messages.find((message) => message.id === id);
156
- if (target) target.recalledAt = Date.now();
157
- this.closePalette();
158
- this.setStatus(t("message.recalledStatus", { id }), "success");
159
- return;
160
- }
161
- const revealed = await this.api.reveal(roomId, id, this.sessionID);
162
- palette.mode = "detail";
163
- palette.title = t("message.revealed");
164
- palette.confirm = null;
165
- palette.detail = {
166
- title: t("message.revealed"),
167
- markdown: String(revealed?.text ?? t("message.empty")),
168
- kind: "revealed-message",
169
- };
170
- palette.hint = t("palette.closeHint");
171
- palette.searching = false;
172
- this.touch();
173
- } catch (error) {
174
- if (this.state.palette === palette) {
175
- palette.searching = false;
176
- palette.error = errorText(error);
177
- this.touch();
178
- }
179
- }
180
- },
181
- });
182
- }
158
+ try {
159
+ if (confirm.action === "message-recall") {
160
+ await this.api.recall(roomId, id, this.sessionID);
161
+ const target = this.state.messages.find((message) => message.id === id);
162
+ if (target)
163
+ target.recalledAt = Date.now();
164
+ this.closePalette();
165
+ this.setStatus(t("message.recalledStatus", { id }), "success");
166
+ return;
167
+ }
168
+ const revealed = await this.api.reveal(roomId, id, this.sessionID);
169
+ palette.mode = "detail";
170
+ palette.title = t("message.revealed");
171
+ palette.confirm = null;
172
+ palette.detail = {
173
+ title: t("message.revealed"),
174
+ markdown: String(revealed?.text ?? t("message.empty")),
175
+ kind: "revealed-message",
176
+ };
177
+ palette.hint = t("palette.closeHint");
178
+ palette.searching = false;
179
+ this.touch();
180
+ }
181
+ catch (error) {
182
+ if (this.state.palette === palette) {
183
+ palette.searching = false;
184
+ palette.error = errorText(error);
185
+ this.touch();
186
+ }
187
+ }
188
+ },
189
+ });
190
+ }