@alexsun-top/opencode-chat-room 0.8.4 → 0.8.6

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 (206) hide show
  1. package/CHANGELOG.md +17 -3
  2. package/README.md +5 -5
  3. package/README.zh-CN.md +5 -5
  4. package/cli.ts +20 -1
  5. package/dist/cli.js +3785 -1462
  6. package/package.json +19 -11
  7. package/packages/chat-room-channeld/README.md +16 -10
  8. package/packages/chat-room-channeld/src/delivery.ts +0 -4
  9. package/packages/chat-room-channeld/src/host.ts +48 -37
  10. package/packages/chat-room-channeld/src/inbound.ts +3 -6
  11. package/packages/chat-room-channeld/src/pg/database.ts +141 -49
  12. package/packages/chat-room-channeld/src/pg/sql.mjs +157 -142
  13. package/packages/chat-room-channeld/src/pg/sql.mts +175 -0
  14. package/packages/chat-room-channeld/src/pg/worker.mjs +148 -99
  15. package/packages/chat-room-channeld/src/pg/worker.mts +201 -0
  16. package/packages/chat-room-channeld/src/state-rows.ts +132 -0
  17. package/packages/chat-room-channeld/src/state.ts +129 -157
  18. package/plugin.ts +21 -5
  19. package/server/app.ts +9 -0
  20. package/server/assets/base.css +22 -2
  21. package/server/assets/chat/admin.js +17 -1
  22. package/server/assets/chat/announcements.js +79 -34
  23. package/server/assets/chat/attachments.js +3 -3
  24. package/server/assets/chat/clipboard.js +1 -1
  25. package/server/assets/chat/confirm-dialog.js +3 -0
  26. package/server/assets/chat/copy-action.js +1 -1
  27. package/server/assets/chat/create-room-dialog.js +7 -0
  28. package/server/assets/chat/diagram-viewer.js +4 -8
  29. package/server/assets/chat/doc-preview.js +71 -31
  30. package/server/assets/chat/editor.js +49 -10
  31. package/server/assets/chat/events.js +13 -6
  32. package/server/assets/chat/files.js +33 -27
  33. package/server/assets/chat/history-loader.js +31 -15
  34. package/server/assets/chat/integration-editor.js +27 -1
  35. package/server/assets/chat/integrations.js +108 -16
  36. package/server/assets/chat/join-requests.js +40 -2
  37. package/server/assets/chat/locales/de.js +5 -3
  38. package/server/assets/chat/locales/es.js +5 -3
  39. package/server/assets/chat/locales/fr.js +5 -3
  40. package/server/assets/chat/locales/it.js +5 -3
  41. package/server/assets/chat/locales/ja.js +5 -3
  42. package/server/assets/chat/locales/ko.js +5 -3
  43. package/server/assets/chat/markdown-footnotes.js +27 -15
  44. package/server/assets/chat/markdown.js +6 -12
  45. package/server/assets/chat/members.js +34 -22
  46. package/server/assets/chat/mentions.js +8 -5
  47. package/server/assets/chat/message-cache.js +9 -3
  48. package/server/assets/chat/message-polling.js +10 -4
  49. package/server/assets/chat/message-window.js +58 -1
  50. package/server/assets/chat/messages.js +90 -37
  51. package/server/assets/chat/office-preview.js +3 -3
  52. package/server/assets/chat/operator.js +624 -0
  53. package/server/assets/chat/palette.js +7 -10
  54. package/server/assets/chat/panels.js +42 -0
  55. package/server/assets/chat/questions.js +75 -58
  56. package/server/assets/chat/recall.js +14 -5
  57. package/server/assets/chat/receipts.js +63 -7
  58. package/server/assets/chat/refresh-timing.js +6 -0
  59. package/server/assets/chat/reminders.js +47 -13
  60. package/server/assets/chat/replies.js +39 -25
  61. package/server/assets/chat/resource-format.js +6 -3
  62. package/server/assets/chat/room-list.js +202 -3
  63. package/server/assets/chat/room-watcher.js +3 -1
  64. package/server/assets/chat/rooms.js +29 -7
  65. package/server/assets/chat/settings.js +37 -6
  66. package/server/assets/chat/shortcuts.js +3 -1
  67. package/server/assets/chat/side-pane.js +1 -1
  68. package/server/assets/chat/state.js +51 -18
  69. package/server/assets/chat/system-events.js +3 -2
  70. package/server/assets/chat/system-messages.js +15 -15
  71. package/server/assets/chat/tasks.js +37 -14
  72. package/server/assets/chat/window-controls.js +25 -15
  73. package/server/assets/code-highlight.css +0 -13
  74. package/server/assets/conversation.css +45 -5
  75. package/server/assets/doc-preview.css +9 -0
  76. package/server/assets/files.css +4 -0
  77. package/server/assets/monaco/integration-rules.js +1 -1
  78. package/server/assets/office/THIRD-PARTY-NOTICES.txt +23 -1
  79. package/server/assets/office/licenses/docx-preview-HEADER.txt +6 -0
  80. package/server/assets/office/licenses/echarts-LICENSE-d3.txt +27 -0
  81. package/server/assets/office/licenses/echarts-NOTICE.txt +5 -0
  82. package/server/assets/office/licenses/immediate-LICENSE.txt +20 -0
  83. package/server/assets/office/licenses/lie-LICENSE.txt +7 -0
  84. package/server/assets/office/licenses/pako-LICENSE.txt +21 -0
  85. package/server/assets/office/licenses/pako-ZLIB.txt +18 -0
  86. package/server/assets/office/licenses/setimmediate-LICENSE.txt +20 -0
  87. package/server/assets/responsive.css +12 -2
  88. package/server/assets/settings.css +3 -1
  89. package/server/assets/tasks.css +6 -1
  90. package/server/assets/window-controls.css +3 -1
  91. package/server/channels.ts +3 -2
  92. package/server/chat.html +7 -2
  93. package/server/inbox.ts +3 -1
  94. package/server/join-requests.ts +8 -1
  95. package/server/member-routes.ts +16 -2
  96. package/server/newrooms.ts +2 -13
  97. package/server/operator-auth.ts +21 -0
  98. package/server/operator-routes.ts +150 -0
  99. package/server/operator-state.ts +64 -0
  100. package/server/operator.css +139 -0
  101. package/server/room-owner.ts +17 -0
  102. package/server/routes/inbox.ts +15 -5
  103. package/server/routes/pages.ts +12 -2
  104. package/server/routes/room-actions.ts +4 -3
  105. package/server/sw.js +3 -1
  106. package/server/system.html +109 -0
  107. package/server/wake.ts +1 -1
  108. package/skills/chatroom/SKILL.md +9 -0
  109. package/src/README.md +1 -1
  110. package/src/acp/client.ts +254 -0
  111. package/src/acp/protocol.ts +300 -0
  112. package/src/acp/watch.ts +498 -0
  113. package/src/agent/agent-receipts.ts +98 -8
  114. package/src/center/center-client.ts +6 -1
  115. package/src/center/center-inbox.ts +54 -7
  116. package/src/center/center-wake.ts +57 -3
  117. package/src/center/forward-client.ts +48 -0
  118. package/src/center/mentions.ts +16 -3
  119. package/src/center/notification-delay.ts +139 -0
  120. package/src/center/queue.ts +3 -0
  121. package/src/config/file-config.ts +25 -0
  122. package/src/mcp/server.ts +389 -0
  123. package/src/protocol/config.ts +7 -0
  124. package/src/runtime/plugin-notifications.ts +43 -9
  125. package/src/runtime/v2-plugin.ts +14 -3
  126. package/src/runtime/v2-receiver.ts +10 -2
  127. package/src/runtime/watch.ts +5 -1
  128. package/src/state/pg-database.ts +133 -49
  129. package/src/state/pg-sql.mjs +157 -142
  130. package/src/state/pg-sql.mts +175 -0
  131. package/src/state/pg-worker.mjs +148 -99
  132. package/src/state/pg-worker.mts +201 -0
  133. package/src/state/receiver-state.ts +47 -0
  134. package/src/state/sqlite-database.ts +6 -2
  135. package/src/state/sqlite-members.ts +48 -4
  136. package/src/state/sqlite-messages.ts +25 -12
  137. package/src/state/sqlite-schema.ts +4 -1
  138. package/src/state/sqlite-state.ts +1 -1
  139. package/src/state/store.ts +31 -11
  140. package/src/tui/app-types.mjs +1 -0
  141. package/src/tui/app-types.mts +175 -0
  142. package/src/tui/app.mjs +473 -423
  143. package/src/tui/app.mts +543 -0
  144. package/src/tui/config.mjs +166 -158
  145. package/src/tui/config.mts +247 -0
  146. package/src/tui/http.mjs +239 -206
  147. package/src/tui/http.mts +412 -0
  148. package/src/tui/i18n.mjs +17 -20
  149. package/src/tui/i18n.mts +42 -0
  150. package/src/tui/info-app.mjs +431 -427
  151. package/src/tui/info-app.mts +500 -0
  152. package/src/tui/info-content.mjs +205 -199
  153. package/src/tui/info-content.mts +341 -0
  154. package/src/tui/join-app.mjs +75 -64
  155. package/src/tui/join-app.mts +99 -0
  156. package/src/tui/locales/en.mjs +302 -320
  157. package/src/tui/locales/en.mts +349 -0
  158. package/src/tui/locales/zh-CN.mjs +302 -320
  159. package/src/tui/locales/zh-CN.mts +349 -0
  160. package/src/tui/main.mjs +219 -213
  161. package/src/tui/main.mts +255 -0
  162. package/src/tui/markdown.mjs +128 -272
  163. package/src/tui/markdown.mts +152 -0
  164. package/src/tui/mentions.mjs +181 -184
  165. package/src/tui/mentions.mts +251 -0
  166. package/src/tui/message-app.mjs +181 -173
  167. package/src/tui/message-app.mts +213 -0
  168. package/src/tui/message-view.mjs +90 -111
  169. package/src/tui/message-view.mts +151 -0
  170. package/src/tui/messages.mjs +55 -49
  171. package/src/tui/messages.mts +106 -0
  172. package/src/tui/palette-app.mjs +364 -344
  173. package/src/tui/palette-app.mts +388 -0
  174. package/src/tui/palette.mjs +100 -98
  175. package/src/tui/palette.mts +176 -0
  176. package/src/tui/prefs.mjs +56 -63
  177. package/src/tui/prefs.mts +126 -0
  178. package/src/tui/reminder-app.mjs +191 -181
  179. package/src/tui/reminder-app.mts +228 -0
  180. package/src/tui/room-settings-app.mjs +275 -242
  181. package/src/tui/room-settings-app.mts +318 -0
  182. package/src/tui/session.mjs +30 -29
  183. package/src/tui/session.mts +51 -0
  184. package/src/tui/settings-app.mjs +151 -138
  185. package/src/tui/settings-app.mts +179 -0
  186. package/src/tui/ui-content.mjs +426 -421
  187. package/src/tui/ui-content.mts +499 -0
  188. package/src/tui/ui-help.mjs +58 -67
  189. package/src/tui/ui-help.mts +87 -0
  190. package/src/tui/ui-mentions.mjs +34 -36
  191. package/src/tui/ui-mentions.mts +60 -0
  192. package/src/tui/ui-overlay-view.mjs +259 -267
  193. package/src/tui/ui-overlay-view.mts +322 -0
  194. package/src/tui/ui-suggest-view.mjs +54 -57
  195. package/src/tui/ui-suggest-view.mts +78 -0
  196. package/src/tui/ui-suggest.mjs +164 -167
  197. package/src/tui/ui-suggest.mts +248 -0
  198. package/src/tui/ui-theme.mjs +52 -57
  199. package/src/tui/ui-theme.mts +98 -0
  200. package/src/tui/ui-view.mjs +267 -275
  201. package/src/tui/ui-view.mts +308 -0
  202. package/src/tui/ui.mjs +372 -359
  203. package/src/tui/ui.mts +440 -0
  204. package/src/tui/wire.mjs +215 -0
  205. package/src/tui/wire.mts +383 -0
  206. package/src/web/integration-rules-editor.ts +25 -2
@@ -0,0 +1,500 @@
1
+ // CLI parity commands: read-only member/question/file/reminder views plus
2
+ // announcement and question actions. Reuses the palette overlay as a scrollable
3
+ // info/list/detail surface instead of introducing another panel.
4
+ import {
5
+ announcementRows,
6
+ fileRows,
7
+ memberRows,
8
+ questionRows,
9
+ } from "./info-content.mjs";
10
+ import { t } from "./i18n.mjs";
11
+ import { sanitizeText } from "./messages.mjs";
12
+ import type { ChatApp } from "./app.mjs";
13
+ import type {
14
+ CurrentRoom,
15
+ PaletteConfirm,
16
+ PaletteItem,
17
+ PalettePrompt,
18
+ PaletteState,
19
+ } from "./app-types.mjs";
20
+
21
+ const errorText = (error: unknown): string => (error instanceof Error ? error.message : String(error ?? "unknown error"));
22
+ export const MAX_UPLOAD_BYTES = 100 * 1024 * 1024;
23
+ const announcementHint = () => t("info.announcementHint");
24
+
25
+ export function createInfoPalette(kind: string, title: string, subtitle: string): PaletteState {
26
+ return {
27
+ mode: "info",
28
+ kind,
29
+ title,
30
+ subtitle,
31
+ roomId: "",
32
+ items: [],
33
+ selected: 0,
34
+ error: "",
35
+ loading: false,
36
+ hint: "",
37
+ query: "",
38
+ scope: "room",
39
+ results: [],
40
+ searching: false,
41
+ confirm: null,
42
+ detail: null,
43
+ };
44
+ }
45
+
46
+ // Palette methods this module calls but the sibling attach modules still own.
47
+ // Narrow shapes only; each sibling gets its real signature when it migrates.
48
+ interface InfoApp extends ChatApp {
49
+ paletteItems(): PaletteItem[];
50
+ closePalette(): void;
51
+ editSetting(item: PaletteItem): void;
52
+ askJoinDecision(decision: "approve" | "deny"): void;
53
+ runMessageConfirm(confirm: PaletteConfirm): Promise<void>;
54
+ runReminderConfirm(confirm: PaletteConfirm): Promise<void>;
55
+ runRoomSettingsConfirm(confirm: PaletteConfirm): Promise<void>;
56
+ runJoinConfirm(confirm: PaletteConfirm): Promise<void>;
57
+ submitPreferencePrompt(prompt: PalettePrompt, value: string): Promise<void>;
58
+ submitReminderPrompt(prompt: PalettePrompt, value: string): Promise<void>;
59
+ submitRoomSettingsPrompt(prompt: PalettePrompt, value: string): Promise<void>;
60
+ submitMessagePrompt(prompt: PalettePrompt, value: string): Promise<void>;
61
+ }
62
+
63
+ // The methods this module attaches become visible on ChatApp for app.mts and
64
+ // the later attach migrations.
65
+ declare module "./app.mjs" {
66
+ interface ChatApp {
67
+ currentInfoRoom(): CurrentRoom | null;
68
+ paletteRoomId(palette: PaletteState): string | undefined;
69
+ openInfo(kind: string, title: string, hint: string, load: (room: CurrentRoom) => Promise<PaletteItem[]>): Promise<void>;
70
+ openMembers(): Promise<void>;
71
+ openAnnouncements(): Promise<void>;
72
+ openQuestions(): Promise<void>;
73
+ openFiles(): Promise<void>;
74
+ runInfoSelection(): Promise<void>;
75
+ startAnnouncementCreate(): void;
76
+ askDeleteFile(): void;
77
+ runFileDeleteConfirm(confirm: PaletteConfirm): Promise<void>;
78
+ startFileUpload(): void;
79
+ askDeleteAnnouncement(name?: string): void;
80
+ runConfirm(): Promise<void>;
81
+ cancelConfirm(): void;
82
+ backFromDetail(): void;
83
+ downloadFile(item: PaletteItem): Promise<void>;
84
+ submitCommandPrompt(prompt: PalettePrompt, value: string): Promise<void>;
85
+ }
86
+ }
87
+
88
+ export function attachInfo(Class: { prototype: ChatApp }) {
89
+ Object.assign(Class.prototype, {
90
+ currentInfoRoom(this: InfoApp): CurrentRoom | null {
91
+ if (this.state.current && this.state.joined) return this.state.current;
92
+ this.state.palette = null;
93
+ this.setStatus(t("info.joinFirst"), "error");
94
+ return null;
95
+ },
96
+
97
+ // A palette acts on the room it was opened for, even if the rail has since
98
+ // switched rooms; otherwise an announcement prompt could overwrite the new
99
+ // room's same-named announcement.
100
+ paletteRoomId(this: InfoApp, palette: PaletteState): string | undefined {
101
+ const roomId = palette.roomId || this.state.current?.id;
102
+ if (!roomId) {
103
+ palette.error = t("info.joinFirst");
104
+ this.touch();
105
+ }
106
+ return roomId;
107
+ },
108
+
109
+ async openInfo(
110
+ this: InfoApp,
111
+ kind: string,
112
+ title: string,
113
+ hint: string,
114
+ load: (room: CurrentRoom) => Promise<PaletteItem[]>,
115
+ ): Promise<void> {
116
+ const room = this.currentInfoRoom();
117
+ if (!room) return;
118
+ const palette = createInfoPalette(kind, title, `#${room.name}`);
119
+ palette.roomId = room.id;
120
+ palette.hint = hint;
121
+ palette.loading = true;
122
+ this.state.palette = palette;
123
+ this.touch();
124
+ try {
125
+ const items = await load(room);
126
+ if (this.state.palette !== palette) return;
127
+ palette.items = Array.isArray(items) ? items : [];
128
+ palette.loading = false;
129
+ palette.selected = Math.min(palette.selected, Math.max(0, palette.items.length - 1));
130
+ this.touch();
131
+ } catch (error) {
132
+ if (this.state.palette !== palette) return;
133
+ palette.loading = false;
134
+ palette.error = errorText(error);
135
+ this.touch();
136
+ }
137
+ },
138
+
139
+ openMembers(this: InfoApp): Promise<void> {
140
+ return this.openInfo("members", t("info.members"), t("info.readOnlyHint"), async (room) =>
141
+ memberRows(await this.api.members(room.id), this.sessionID));
142
+ },
143
+
144
+ openAnnouncements(this: InfoApp): Promise<void> {
145
+ return this.openInfo("announcements", t("info.announcements"), announcementHint(), async (room) =>
146
+ announcementRows(await this.api.announcements(room.id)));
147
+ },
148
+
149
+ openQuestions(this: InfoApp): Promise<void> {
150
+ return this.openInfo("questions", t("info.questions"), t("info.questionHint"), async (room) =>
151
+ questionRows(await this.api.questions(room.id), this.state.messages));
152
+ },
153
+
154
+ openFiles(this: InfoApp): Promise<void> {
155
+ return this.openInfo("files", t("info.files"), t("info.fileHint"), async (room) => {
156
+ const result = await this.api.resources(room.id, this.sessionID);
157
+ const list = Array.isArray(result) ? result : result?.resources;
158
+ return fileRows(list ?? []);
159
+ });
160
+ },
161
+
162
+ async runInfoSelection(this: InfoApp): Promise<void> {
163
+ const palette = this.state.palette;
164
+ if (!palette || palette.mode !== "info" || palette.loading) return;
165
+ const item = this.paletteItems()[palette.selected];
166
+ if (!item) return;
167
+ if (palette.kind === "settings") {
168
+ this.editSetting(item);
169
+ return;
170
+ }
171
+ if (palette.kind === "announcements") {
172
+ palette.mode = "detail";
173
+ palette.detail = {
174
+ title: String(item.value),
175
+ markdown: String(item.content ?? "").trim() || t("common.emptyAnnouncement"),
176
+ kind: "announcements",
177
+ };
178
+ palette.hint = t("info.announcementBackHint");
179
+ this.touch();
180
+ return;
181
+ }
182
+ if (palette.kind === "questions" && item.open) {
183
+ palette.mode = "prompt";
184
+ palette.prompt = {
185
+ label: t("info.answerLabel", { text: sanitizeText(item.text).slice(0, 40) }),
186
+ value: "",
187
+ action: "question-answer",
188
+ data: { id: String(item.value) },
189
+ };
190
+ palette.hint = t("palette.enterPostHint");
191
+ this.touch();
192
+ return;
193
+ }
194
+ if (palette.kind === "join-requests") {
195
+ this.askJoinDecision("approve");
196
+ return;
197
+ }
198
+ if (palette.kind === "files") await this.downloadFile(item);
199
+ },
200
+
201
+ startAnnouncementCreate(this: InfoApp): void {
202
+ const palette = this.state.palette;
203
+ if (!palette || palette.mode !== "info" || palette.kind !== "announcements") return;
204
+ palette.mode = "prompt";
205
+ palette.prompt = { label: t("info.announcementName"), value: "", action: "announcement-name", data: {} };
206
+ palette.error = "";
207
+ palette.hint = t("palette.enterNextHint");
208
+ this.touch();
209
+ },
210
+
211
+ askDeleteFile(this: InfoApp): void {
212
+ const palette = this.state.palette;
213
+ if (!palette || palette.mode !== "info" || palette.kind !== "files") return;
214
+ const item = this.paletteItems()[palette.selected];
215
+ if (!item?.resource) return;
216
+ palette.mode = "confirm";
217
+ palette.previous = { mode: "info", hint: palette.hint };
218
+ palette.confirm = {
219
+ text: t("info.deleteFile", { name: sanitizeText(item.resource.name) }),
220
+ action: "file-delete",
221
+ data: { id: String(item.resource.id), name: item.resource.name },
222
+ };
223
+ palette.error = "";
224
+ palette.hint = t("palette.deleteHint");
225
+ this.touch();
226
+ },
227
+
228
+ async runFileDeleteConfirm(this: InfoApp, confirm: PaletteConfirm): Promise<void> {
229
+ const palette = this.state.palette;
230
+ if (!palette) return;
231
+ const roomId = this.paletteRoomId(palette);
232
+ if (!roomId) return;
233
+ palette.searching = true;
234
+ palette.error = "";
235
+ this.touch();
236
+ try {
237
+ await this.api.deleteResource(roomId, String(confirm.data.id), this.sessionID);
238
+ this.setStatus(t("info.fileDeleted", { name: confirm.data.name }), "success");
239
+ await this.openFiles();
240
+ } catch (error) {
241
+ if (this.state.palette === palette) {
242
+ palette.mode = "info";
243
+ palette.confirm = null;
244
+ palette.previous = null;
245
+ palette.searching = false;
246
+ palette.hint = t("info.fileHint");
247
+ palette.error = errorText(error);
248
+ this.touch();
249
+ }
250
+ }
251
+ },
252
+
253
+ startFileUpload(this: InfoApp): void {
254
+ const palette = this.state.palette;
255
+ if (!palette || palette.mode !== "info" || palette.kind !== "files") return;
256
+ palette.mode = "prompt";
257
+ palette.prompt = { label: t("info.filePath"), value: "", action: "file-upload", data: {} };
258
+ palette.error = "";
259
+ palette.hint = t("palette.enterUploadHint");
260
+ this.touch();
261
+ },
262
+
263
+ askDeleteAnnouncement(this: InfoApp, name?: string): void {
264
+ const palette = this.state.palette;
265
+ const selected = name ?? palette?.items?.[palette.selected]?.value;
266
+ if (!palette || !selected) return;
267
+ palette.mode = "confirm";
268
+ palette.error = "";
269
+ palette.previous = { mode: "info", hint: palette.hint };
270
+ palette.confirm = {
271
+ text: t("info.deleteAnnouncement", { name: sanitizeText(selected) }),
272
+ action: "announcement-delete",
273
+ data: { name: String(selected) },
274
+ };
275
+ palette.hint = t("palette.deleteHint");
276
+ this.touch();
277
+ },
278
+
279
+ async runConfirm(this: InfoApp): Promise<void> {
280
+ const palette = this.state.palette;
281
+ const confirm = palette?.confirm;
282
+ if (!palette || !confirm) return;
283
+ if (typeof confirm.action === "string" && confirm.action.startsWith("message-")) {
284
+ await this.runMessageConfirm(confirm);
285
+ return;
286
+ }
287
+ if (typeof confirm.action === "string" && confirm.action.startsWith("reminder-")) {
288
+ await this.runReminderConfirm(confirm);
289
+ return;
290
+ }
291
+ if (typeof confirm.action === "string" && confirm.action.startsWith("room-")) {
292
+ await this.runRoomSettingsConfirm(confirm);
293
+ return;
294
+ }
295
+ if (typeof confirm.action === "string" && confirm.action.startsWith("join-")) {
296
+ await this.runJoinConfirm(confirm);
297
+ return;
298
+ }
299
+ if (typeof confirm.action === "string" && confirm.action.startsWith("file-")) {
300
+ await this.runFileDeleteConfirm(confirm);
301
+ return;
302
+ }
303
+ if (confirm.action === "announcement-delete") {
304
+ palette.searching = true;
305
+ this.touch();
306
+ try {
307
+ await this.api.deleteAnnouncement(String(palette.roomId), String(confirm.data.name), this.sessionID);
308
+ this.setStatus(t("info.announcementDeleted", { name: confirm.data.name }), "success");
309
+ await this.openAnnouncements();
310
+ } catch (error) {
311
+ if (this.state.palette === palette) {
312
+ palette.searching = false;
313
+ palette.error = errorText(error);
314
+ this.touch();
315
+ }
316
+ }
317
+ }
318
+ },
319
+
320
+ cancelConfirm(this: InfoApp): void {
321
+ const palette = this.state.palette;
322
+ if (!palette) return;
323
+ const previous = palette.previous;
324
+ palette.previous = null;
325
+ palette.confirm = null;
326
+ palette.error = "";
327
+ if (previous?.mode) {
328
+ palette.mode = previous.mode;
329
+ palette.hint = previous.hint ?? "";
330
+ } else {
331
+ palette.mode = "info";
332
+ palette.hint = announcementHint();
333
+ }
334
+ this.touch();
335
+ },
336
+
337
+ backFromDetail(this: InfoApp): void {
338
+ const palette = this.state.palette;
339
+ if (!palette) return;
340
+ if (palette.previous?.mode === "info") {
341
+ palette.mode = "info";
342
+ palette.detail = null;
343
+ palette.hint = palette.previous.hint ?? t("palette.listHint");
344
+ palette.previous = null;
345
+ this.touch();
346
+ return;
347
+ }
348
+ if (palette.kind !== "announcements") {
349
+ this.closePalette();
350
+ return;
351
+ }
352
+ palette.mode = "info";
353
+ palette.detail = null;
354
+ palette.hint = announcementHint();
355
+ this.touch();
356
+ },
357
+
358
+ async downloadFile(this: InfoApp, item: PaletteItem): Promise<void> {
359
+ const palette = this.state.palette;
360
+ const roomId = palette ? this.paletteRoomId(palette) : this.state.current?.id;
361
+ if (!roomId || !item.resource) return;
362
+ if (palette) palette.searching = true;
363
+ this.touch();
364
+ try {
365
+ const payload = await this.api.resourceContent(roomId, String(item.resource.id));
366
+ const [{ mkdir, writeFile, access }, path] = await Promise.all([
367
+ import("node:fs/promises"),
368
+ import("node:path"),
369
+ ]);
370
+ await mkdir(this.downloadDir, { recursive: true });
371
+ const base = path.basename(String(item.resource.name || "download")).replace(/[\0\r\n]/g, "_");
372
+ const filename = !base || base === "." || base === ".." ? "download" : base;
373
+ let target = path.join(this.downloadDir, filename);
374
+ try {
375
+ await access(target);
376
+ const extension = path.extname(filename);
377
+ target = path.join(this.downloadDir, `${path.basename(filename, extension)}-${Date.now()}${extension}`);
378
+ } catch {
379
+ // Target does not exist yet.
380
+ }
381
+ const content: unknown = payload;
382
+ await writeFile(target, content instanceof Uint8Array ? content : payload.bytes);
383
+ this.closePalette();
384
+ this.setStatus(t("info.fileSaved", { target }), "success");
385
+ } catch (error) {
386
+ if (palette && this.state.palette === palette) {
387
+ palette.searching = false;
388
+ palette.error = errorText(error);
389
+ this.touch();
390
+ }
391
+ }
392
+ },
393
+
394
+ async submitCommandPrompt(this: InfoApp, prompt: PalettePrompt, value: string): Promise<void> {
395
+ const palette = this.state.palette;
396
+ if (!palette || palette.mode !== "prompt") return;
397
+ if (typeof prompt.action === "string" && prompt.action.startsWith("settings-")) {
398
+ await this.submitPreferencePrompt(prompt, value);
399
+ return;
400
+ }
401
+ if (typeof prompt.action === "string" && prompt.action.startsWith("reminder-")) {
402
+ await this.submitReminderPrompt(prompt, value);
403
+ return;
404
+ }
405
+ if (typeof prompt.action === "string" && prompt.action.startsWith("room-")) {
406
+ await this.submitRoomSettingsPrompt(prompt, value);
407
+ return;
408
+ }
409
+ if (typeof prompt.action === "string" && prompt.action.startsWith("message-")) {
410
+ await this.submitMessagePrompt(prompt, value);
411
+ return;
412
+ }
413
+ const roomId = this.paletteRoomId(palette);
414
+ if (!roomId) return;
415
+ if (prompt.action === "announcement-name") {
416
+ const name = String(value ?? "").trim();
417
+ if (!name) {
418
+ palette.error = t("info.announcementNameRequired");
419
+ this.touch();
420
+ return;
421
+ }
422
+ palette.prompt = { label: t("info.announcementContent", { name: sanitizeText(name) }), value: "", action: "announcement-content", data: { name } };
423
+ palette.error = "";
424
+ this.touch();
425
+ return;
426
+ }
427
+ if (prompt.action === "announcement-content") {
428
+ const name = prompt.data?.name;
429
+ if (!name) return;
430
+ palette.searching = true;
431
+ this.touch();
432
+ try {
433
+ await this.api.saveAnnouncement(roomId, name, String(value ?? ""), this.sessionID);
434
+ this.setStatus(t("info.announcementSaved", { name }), "success");
435
+ await this.openAnnouncements();
436
+ } catch (error) {
437
+ if (this.state.palette === palette) {
438
+ palette.searching = false;
439
+ palette.error = errorText(error);
440
+ this.touch();
441
+ }
442
+ }
443
+ return;
444
+ }
445
+ if (prompt.action === "question-answer") {
446
+ const answer = String(value ?? "").trim();
447
+ if (!answer) {
448
+ palette.error = t("info.answerRequired");
449
+ this.touch();
450
+ return;
451
+ }
452
+ palette.searching = true;
453
+ this.touch();
454
+ try {
455
+ await this.api.answerQuestion(roomId, String(prompt.data?.id), this.sessionID, answer);
456
+ this.setStatus(t("info.answerPosted"), "success");
457
+ await this.openQuestions();
458
+ } catch (error) {
459
+ if (this.state.palette === palette) {
460
+ palette.searching = false;
461
+ palette.error = errorText(error);
462
+ this.touch();
463
+ }
464
+ }
465
+ return;
466
+ }
467
+ if (prompt.action === "file-upload") {
468
+ const file = String(value ?? "").trim();
469
+ const path = await import("node:path");
470
+ if (!file || !path.isAbsolute(file)) {
471
+ palette.error = t("info.filePathRequired");
472
+ this.touch();
473
+ return;
474
+ }
475
+ palette.searching = true;
476
+ this.touch();
477
+ try {
478
+ const fs = await import("node:fs/promises");
479
+ const info = await fs.stat(file);
480
+ if (info.size > MAX_UPLOAD_BYTES) {
481
+ palette.searching = false;
482
+ palette.error = t("info.fileTooLarge");
483
+ this.touch();
484
+ return;
485
+ }
486
+ const bytes = new Uint8Array(await fs.readFile(file));
487
+ await this.api.uploadResource(roomId, this.sessionID, path.basename(file), bytes);
488
+ this.setStatus(t("info.fileUploaded", { name: path.basename(file) }), "success");
489
+ await this.openFiles();
490
+ } catch (error) {
491
+ if (this.state.palette === palette) {
492
+ palette.searching = false;
493
+ palette.error = errorText(error);
494
+ this.touch();
495
+ }
496
+ }
497
+ }
498
+ },
499
+ });
500
+ }