@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,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
+ }