@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
@@ -3,350 +3,370 @@
3
3
  import { buildCommands, filterCommands, nextScope, scopeSources, searchMessages } from "./palette.mjs";
4
4
  import { mergeMessages, oldestSeq } from "./messages.mjs";
5
5
  import { t } from "./i18n.mjs";
6
-
7
6
  const SEARCH_PAGES = 2;
8
-
7
+ const errorText = (error) => (error instanceof Error ? error.message : String(error ?? "unknown error"));
9
8
  export function attachPalette(Class) {
10
- Object.assign(Class.prototype, {
11
- openPalette({ slash = false } = {}) {
12
- this.historyPages.clear();
13
- this.state.help = false;
14
- // Same rule as the web palette: only "/" means commands; empty input
15
- // waits for a search query instead of showing a command wall.
16
- this.state.palette = {
17
- mode: slash ? "commands" : "search",
18
- query: slash ? "/" : "",
19
- scope: "room",
20
- selected: 0,
21
- results: [],
22
- prompt: null,
23
- searching: false,
24
- error: "",
25
- commands: buildCommands({
26
- rooms: this.state.rooms,
27
- current: this.state.current,
28
- joined: this.state.joined,
29
- help: this.state.help,
30
- }),
31
- };
32
- this.touch();
33
- },
34
-
35
- closePalette() {
36
- this.state.palette = null;
37
- this.state.focus = "composer";
38
- this.touch();
39
- },
40
-
41
- paletteCommands() {
42
- const palette = this.state.palette;
43
- const query = palette?.mode === "commands" ? String(palette.query ?? "").replace(/^\s*\//, "") : "";
44
- const commands = palette?.commands ?? buildCommands({
45
- rooms: this.state.rooms,
46
- current: this.state.current,
47
- joined: this.state.joined,
48
- help: this.state.help,
49
- });
50
- return filterCommands(commands, query);
51
- },
52
-
53
- paletteItems() {
54
- const palette = this.state.palette;
55
- if (!palette) return [];
56
- if (palette.mode === "search") return palette.results;
57
- if (palette.mode === "commands") return this.paletteCommands();
58
- if (palette.mode === "info") return palette.items ?? [];
59
- return [];
60
- },
61
-
62
- paletteScopeRooms(scope) {
63
- if (scope === "all") return this.state.rooms.filter((room) => room.joined);
64
- return this.state.current && this.state.joined ? [this.state.current] : [];
65
- },
66
-
67
- refreshPaletteResults() {
68
- const palette = this.state.palette;
69
- if (!palette || palette.mode !== "search") return;
70
- palette.results = searchMessages(palette.query, scopeSources({
71
- rooms: this.state.rooms,
72
- current: this.state.current,
73
- scope: palette.scope,
74
- cache: this.cache,
75
- }));
76
- palette.selected = Math.min(palette.selected, Math.max(0, palette.results.length - 1));
77
- this.touch();
78
- },
79
-
80
- async ensureSearchHistory() {
81
- const palette = this.state.palette;
82
- if (!palette || palette.mode !== "search" || typeof this.api.history !== "function") return;
83
- const jobs = this.paletteScopeRooms(palette.scope).filter((room) =>
84
- (this.historyPages.get(room.id) ?? 0) < SEARCH_PAGES
85
- && this.historyMore.get(room.id) !== false
86
- && !this.historyInflight.has(room.id));
87
- if (!jobs.length) return;
88
- palette.searching = true;
89
- this.touch();
90
- for (const room of jobs) {
91
- this.historyInflight.add(room.id);
92
- try {
93
- await this.fetchHistoryPage(room.id);
94
- // A failed page must not consume the room's search budget.
95
- this.historyPages.set(room.id, (this.historyPages.get(room.id) ?? 0) + 1);
96
- } catch (error) {
97
- if (this.state.palette === palette) palette.error = t("palette.historyError", { error: error.message ?? error });
98
- } finally {
99
- this.historyInflight.delete(room.id);
100
- }
101
- if (this.state.palette === palette) this.refreshPaletteResults();
102
- }
103
- if (this.state.palette === palette) {
104
- palette.searching = this.historyInflight.size > 0;
105
- this.refreshPaletteResults();
106
- }
107
- },
108
-
109
- async fetchHistoryPage(roomID) {
110
- const beforeSeq = this.historyCursor.get(roomID);
111
- const result = await this.api.history(roomID, this.sessionID, beforeSeq);
112
- const messages = Array.isArray(result) ? result : result?.messages ?? result?.items ?? [];
113
- mergeMessages(this.historyList(roomID), messages);
114
- this.historyMore.set(roomID, result?.hasMore === true);
115
- const next = result?.nextBeforeSeq ?? result?.beforeSeq ?? oldestSeq(this.historyList(roomID));
116
- if (typeof next === "number" && Number.isFinite(next)) this.historyCursor.set(roomID, next);
117
- },
118
-
119
- movePalette(delta) {
120
- const items = this.paletteItems();
121
- if (!items.length) return;
122
- const palette = this.state.palette;
123
- palette.selected = Math.min(items.length - 1, Math.max(0, palette.selected + delta));
124
- this.touch();
125
- },
126
-
127
- async runPaletteSelection() {
128
- const palette = this.state.palette;
129
- if (!palette) return;
130
- if (palette.mode === "prompt") {
131
- await this.submitPalettePrompt();
132
- return;
133
- }
134
- if (palette.mode === "info") {
135
- await this.runInfoSelection();
136
- return;
137
- }
138
- if (palette.mode === "confirm") {
139
- await this.runConfirm();
140
- return;
141
- }
142
- if (palette.mode === "detail") return;
143
- if (palette.mode === "commands") {
144
- const command = this.paletteCommands()[palette.selected];
145
- if (command) await this.runPaletteCommand(command);
146
- return;
147
- }
148
- const result = palette.results[palette.selected];
149
- if (result) await this.activateResult(result);
150
- },
151
-
152
- async submitPalettePrompt() {
153
- const palette = this.state.palette;
154
- const value = palette?.prompt?.value ?? "";
155
- if (!palette?.prompt) return;
156
- if (palette.prompt.action && palette.prompt.action !== "new-room") {
157
- await this.submitCommandPrompt(palette.prompt, value);
158
- return;
159
- }
160
- await this.createRoomFromPrompt();
161
- },
162
-
163
- async runPaletteCommand(command) {
164
- const palette = this.state.palette;
165
- switch (command.id) {
166
- case "refresh":
167
- this.closePalette();
168
- await this.refreshRooms();
169
- return;
170
- case "new-room":
171
- palette.mode = "prompt";
172
- palette.prompt = { label: t("palette.newRoomPrompt"), value: "", action: "new-room", data: {} };
173
- palette.selected = 0;
174
- palette.error = "";
175
- this.touch();
176
- return;
177
- case "toggle-help":
178
- this.state.help = !this.state.help;
179
- this.state.palette = null;
180
- this.state.focus = "rooms";
181
- this.touch();
182
- return;
183
- case "leave-room":
184
- this.closePalette();
185
- await this.leaveCurrent();
186
- return;
187
- case "search-room":
188
- case "search-all":
189
- palette.mode = "search";
190
- palette.scope = command.id === "search-all" ? "all" : "room";
191
- palette.query = "";
192
- palette.results = [];
193
- palette.selected = 0;
194
- palette.error = "";
195
- this.touch();
196
- void this.ensureSearchHistory();
197
- return;
198
- case "members":
199
- await this.openMembers();
200
- return;
201
- case "join-requests":
202
- await this.openJoinRequests();
203
- return;
204
- case "announcements":
205
- await this.openAnnouncements();
206
- return;
207
- case "questions":
208
- await this.openQuestions();
209
- return;
210
- case "files":
211
- await this.openFiles();
212
- return;
213
- case "reminders":
214
- await this.openReminders();
215
- return;
216
- case "settings":
217
- this.openSettingsEditor();
218
- return;
219
- case "room-settings":
220
- await this.openRoomSettings();
221
- return;
222
- case "delete-room":
223
- await this.openRoomSettings();
224
- this.askDeleteRoom();
225
- return;
226
- case "recall-message":
227
- this.startMessageRecall();
228
- return;
229
- case "reveal-message":
230
- this.startMessageReveal();
231
- return;
232
- case "reply-message":
233
- this.startMessageReply();
234
- return;
235
- case "ask-question":
236
- this.startAskQuestion();
237
- return;
238
- case "quit":
239
- this.closePalette();
240
- this.quit();
241
- return;
242
- default:
243
- if (command.roomId) {
244
- const index = this.state.rooms.findIndex((room) => room.id === command.roomId);
9
+ Object.assign(Class.prototype, {
10
+ openPalette({ slash = false } = {}) {
11
+ this.historyPages.clear();
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.
15
+ this.state.palette = {
16
+ mode: slash ? "commands" : "search",
17
+ query: slash ? "/" : "",
18
+ scope: "room",
19
+ selected: 0,
20
+ results: [],
21
+ items: [],
22
+ confirm: null,
23
+ detail: null,
24
+ searching: false,
25
+ error: "",
26
+ commands: buildCommands({
27
+ rooms: this.state.rooms,
28
+ current: this.state.current,
29
+ joined: this.state.joined,
30
+ help: this.state.help,
31
+ }),
32
+ };
33
+ this.touch();
34
+ },
35
+ closePalette() {
36
+ this.state.palette = null;
37
+ this.state.focus = "composer";
38
+ this.touch();
39
+ },
40
+ paletteCommands() {
41
+ const palette = this.state.palette;
42
+ const query = palette?.mode === "commands" ? String(palette.query ?? "").replace(/^\s*\//, "") : "";
43
+ const commands = palette?.commands ?? buildCommands({
44
+ rooms: this.state.rooms,
45
+ current: this.state.current,
46
+ joined: this.state.joined,
47
+ help: this.state.help,
48
+ });
49
+ return filterCommands(commands, query);
50
+ },
51
+ paletteItems() {
52
+ const palette = this.state.palette;
53
+ if (!palette)
54
+ return [];
55
+ if (palette.mode === "search")
56
+ return palette.results;
57
+ if (palette.mode === "commands")
58
+ return this.paletteCommands();
59
+ if (palette.mode === "info")
60
+ return palette.items ?? [];
61
+ return [];
62
+ },
63
+ paletteScopeRooms(scope) {
64
+ if (scope === "all")
65
+ return this.state.rooms.filter((room) => room.joined);
66
+ return this.state.current && this.state.joined ? [this.state.current] : [];
67
+ },
68
+ refreshPaletteResults() {
69
+ const palette = this.state.palette;
70
+ if (!palette || palette.mode !== "search")
71
+ return;
72
+ palette.results = searchMessages(String(palette.query ?? ""), scopeSources({
73
+ rooms: this.state.rooms,
74
+ current: this.state.current,
75
+ scope: palette.scope,
76
+ cache: this.cache,
77
+ }));
78
+ palette.selected = Math.min(palette.selected, Math.max(0, palette.results.length - 1));
79
+ this.touch();
80
+ },
81
+ async ensureSearchHistory() {
82
+ const palette = this.state.palette;
83
+ if (!palette || palette.mode !== "search" || typeof this.api.history !== "function")
84
+ return;
85
+ const jobs = this.paletteScopeRooms(palette.scope ?? "room").filter((room) => (this.historyPages.get(room.id) ?? 0) < SEARCH_PAGES
86
+ && this.historyMore.get(room.id) !== false
87
+ && !this.historyInflight.has(room.id));
88
+ if (!jobs.length)
89
+ return;
90
+ palette.searching = true;
91
+ this.touch();
92
+ for (const room of jobs) {
93
+ this.historyInflight.add(room.id);
94
+ try {
95
+ await this.fetchHistoryPage(room.id);
96
+ // A failed page must not consume the room's search budget.
97
+ this.historyPages.set(room.id, (this.historyPages.get(room.id) ?? 0) + 1);
98
+ }
99
+ catch (error) {
100
+ if (this.state.palette === palette)
101
+ palette.error = t("palette.historyError", { error: errorText(error) });
102
+ }
103
+ finally {
104
+ this.historyInflight.delete(room.id);
105
+ }
106
+ if (this.state.palette === palette)
107
+ this.refreshPaletteResults();
108
+ }
109
+ if (this.state.palette === palette) {
110
+ palette.searching = this.historyInflight.size > 0;
111
+ this.refreshPaletteResults();
112
+ }
113
+ },
114
+ async fetchHistoryPage(roomID) {
115
+ const beforeSeq = this.historyCursor.get(roomID);
116
+ const result = await this.api.history(roomID, this.sessionID, beforeSeq);
117
+ const messages = result?.messages ?? [];
118
+ mergeMessages(this.historyList(roomID), messages);
119
+ this.historyMore.set(roomID, result?.hasMore === true);
120
+ const next = result?.nextBeforeSeq ?? oldestSeq(this.historyList(roomID));
121
+ if (typeof next === "number" && Number.isFinite(next))
122
+ this.historyCursor.set(roomID, next);
123
+ },
124
+ movePalette(delta) {
125
+ const items = this.paletteItems();
126
+ if (!items.length)
127
+ return;
128
+ const palette = this.state.palette;
129
+ if (!palette)
130
+ return;
131
+ palette.selected = Math.min(items.length - 1, Math.max(0, palette.selected + delta));
132
+ this.touch();
133
+ },
134
+ async runPaletteSelection() {
135
+ const palette = this.state.palette;
136
+ if (!palette)
137
+ return;
138
+ if (palette.mode === "prompt") {
139
+ await this.submitPalettePrompt();
140
+ return;
141
+ }
142
+ if (palette.mode === "info") {
143
+ await this.runInfoSelection();
144
+ return;
145
+ }
146
+ if (palette.mode === "confirm") {
147
+ await this.runConfirm();
148
+ return;
149
+ }
150
+ if (palette.mode === "detail")
151
+ return;
152
+ if (palette.mode === "commands") {
153
+ const command = this.paletteCommands()[palette.selected];
154
+ if (command)
155
+ await this.runPaletteCommand(command);
156
+ return;
157
+ }
158
+ const result = palette.results[palette.selected];
159
+ if (result)
160
+ await this.activateResult(result);
161
+ },
162
+ async submitPalettePrompt() {
163
+ const palette = this.state.palette;
164
+ const prompt = palette?.prompt;
165
+ if (!palette || !prompt)
166
+ return;
167
+ const value = prompt.value ?? "";
168
+ if (prompt.action && prompt.action !== "new-room") {
169
+ await this.submitCommandPrompt(prompt, value);
170
+ return;
171
+ }
172
+ await this.createRoomFromPrompt();
173
+ },
174
+ async runPaletteCommand(command) {
175
+ const palette = this.state.palette;
176
+ if (!palette)
177
+ return;
178
+ switch (command.id) {
179
+ case "refresh":
180
+ this.closePalette();
181
+ await this.refreshRooms();
182
+ return;
183
+ case "new-room":
184
+ palette.mode = "prompt";
185
+ palette.prompt = { label: t("palette.newRoomPrompt"), value: "", action: "new-room", data: {} };
186
+ palette.selected = 0;
187
+ palette.error = "";
188
+ this.touch();
189
+ return;
190
+ case "toggle-help":
191
+ this.state.help = !this.state.help;
192
+ this.state.palette = null;
193
+ this.state.focus = "rooms";
194
+ this.touch();
195
+ return;
196
+ case "leave-room":
197
+ this.closePalette();
198
+ await this.leaveCurrent();
199
+ return;
200
+ case "search-room":
201
+ case "search-all":
202
+ palette.mode = "search";
203
+ palette.scope = command.id === "search-all" ? "all" : "room";
204
+ palette.query = "";
205
+ palette.results = [];
206
+ palette.selected = 0;
207
+ palette.error = "";
208
+ this.touch();
209
+ void this.ensureSearchHistory();
210
+ return;
211
+ case "members":
212
+ await this.openMembers();
213
+ return;
214
+ case "join-requests":
215
+ await this.openJoinRequests();
216
+ return;
217
+ case "announcements":
218
+ await this.openAnnouncements();
219
+ return;
220
+ case "questions":
221
+ await this.openQuestions();
222
+ return;
223
+ case "files":
224
+ await this.openFiles();
225
+ return;
226
+ case "reminders":
227
+ await this.openReminders();
228
+ return;
229
+ case "settings":
230
+ this.openSettingsEditor();
231
+ return;
232
+ case "room-settings":
233
+ await this.openRoomSettings();
234
+ return;
235
+ case "delete-room":
236
+ await this.openRoomSettings();
237
+ this.askDeleteRoom();
238
+ return;
239
+ case "recall-message":
240
+ this.startMessageRecall();
241
+ return;
242
+ case "reveal-message":
243
+ this.startMessageReveal();
244
+ return;
245
+ case "reply-message":
246
+ this.startMessageReply();
247
+ return;
248
+ case "ask-question":
249
+ this.startAskQuestion();
250
+ return;
251
+ case "quit":
252
+ this.closePalette();
253
+ this.quit();
254
+ return;
255
+ default:
256
+ if (command.roomId) {
257
+ const index = this.state.rooms.findIndex((room) => room.id === command.roomId);
258
+ this.closePalette();
259
+ if (index >= 0)
260
+ await this.openRoom(index);
261
+ }
262
+ }
263
+ },
264
+ async activateResult(result) {
265
+ const index = this.state.rooms.findIndex((room) => room.id === result.roomId);
245
266
  this.closePalette();
246
- if (index >= 0) await this.openRoom(index);
247
- }
248
- }
249
- },
250
-
251
- async activateResult(result) {
252
- const index = this.state.rooms.findIndex((room) => room.id === result.roomId);
253
- this.closePalette();
254
- if (index >= 0 && this.state.current?.id !== result.roomId) await this.openRoom(index);
255
- this.state.highlight = result.message.id;
256
- this.state.focus = "composer";
257
- this.touch();
258
- },
259
-
260
- async createRoomFromPrompt() {
261
- const palette = this.state.palette;
262
- const name = String(palette?.prompt?.value ?? "").trim();
263
- if (!name) {
264
- palette.error = t("palette.enterRoomName");
265
- this.touch();
266
- return;
267
- }
268
- palette.searching = true;
269
- palette.error = "";
270
- this.touch();
271
- try {
272
- const created = await this.api.createRoom(name, this.sessionID, this.participant);
273
- const roomID = created?.room?.id ?? created?.id;
274
- await this.refreshRooms(true);
275
- const index = this.state.rooms.findIndex((room) => room.id === roomID);
276
- this.closePalette();
277
- if (index >= 0) await this.openRoom(index);
278
- else this.setStatus(t("palette.created", { name }), "success");
279
- } catch (error) {
280
- if (this.state.palette) {
281
- this.state.palette.searching = false;
282
- this.state.palette.error = error.message ?? String(error);
283
- this.touch();
284
- }
285
- }
286
- },
287
-
288
- async leaveCurrent() {
289
- const room = this.state.current;
290
- if (!room || !this.state.joined) {
291
- this.setStatus(t("palette.notJoined"), "error");
292
- return;
293
- }
294
- try {
295
- await this.api.leave(room.id, this.sessionID);
296
- this.stopPolling();
297
- this.state.joined = false;
298
- const summary = this.state.rooms.find((item) => item.id === room.id);
299
- if (summary) summary.joined = false;
300
- await this.refreshRooms(true);
301
- this.setStatus(t("palette.left", { name: room.name }), "success");
302
- } catch (error) {
303
- this.setStatus(t("palette.leaveFailed", { error: error.message ?? error }), "error");
304
- }
305
- },
306
-
307
- setPaletteQuery(value) {
308
- const palette = this.state.palette;
309
- if (!palette || (palette.mode !== "commands" && palette.mode !== "search")) return;
310
- const query = String(value ?? "");
311
- palette.error = "";
312
- if (!query.trim()) {
313
- palette.mode = "search";
314
- palette.query = "";
315
- palette.results = [];
316
- palette.selected = 0;
317
- palette.searching = false;
318
- this.touch();
319
- return;
320
- }
321
- if (query.trimStart().startsWith("/")) {
322
- palette.mode = "commands";
323
- palette.query = query;
324
- palette.results = [];
325
- palette.searching = false;
326
- palette.selected = 0;
327
- this.touch();
328
- return;
329
- }
330
- palette.mode = "search";
331
- palette.query = query;
332
- palette.selected = 0;
333
- this.refreshPaletteResults();
334
- void this.ensureSearchHistory();
335
- },
336
-
337
- setPalettePrompt(value) {
338
- const palette = this.state.palette;
339
- if (palette?.prompt) palette.prompt.value = String(value ?? "");
340
- },
341
-
342
- togglePaletteScope() {
343
- const palette = this.state.palette;
344
- if (!palette || palette.mode !== "search") return;
345
- palette.scope = nextScope(palette.scope);
346
- palette.selected = 0;
347
- palette.error = "";
348
- this.refreshPaletteResults();
349
- void this.ensureSearchHistory();
350
- },
351
- });
352
- }
267
+ if (index >= 0 && this.state.current?.id !== result.roomId)
268
+ await this.openRoom(index);
269
+ this.state.highlight = result.message.id;
270
+ this.state.focus = "composer";
271
+ this.touch();
272
+ },
273
+ async createRoomFromPrompt() {
274
+ const palette = this.state.palette;
275
+ if (!palette)
276
+ return;
277
+ const name = String(palette.prompt?.value ?? "").trim();
278
+ if (!name) {
279
+ palette.error = t("palette.enterRoomName");
280
+ this.touch();
281
+ return;
282
+ }
283
+ palette.searching = true;
284
+ palette.error = "";
285
+ this.touch();
286
+ try {
287
+ const created = await this.api.createRoom(name, this.sessionID, this.participant);
288
+ const roomID = created?.id;
289
+ await this.refreshRooms(true);
290
+ const index = this.state.rooms.findIndex((room) => room.id === roomID);
291
+ this.closePalette();
292
+ if (index >= 0)
293
+ await this.openRoom(index);
294
+ else
295
+ this.setStatus(t("palette.created", { name }), "success");
296
+ }
297
+ catch (error) {
298
+ const current = this.state.palette;
299
+ if (current) {
300
+ current.searching = false;
301
+ current.error = errorText(error);
302
+ this.touch();
303
+ }
304
+ }
305
+ },
306
+ async leaveCurrent() {
307
+ const room = this.state.current;
308
+ if (!room || !this.state.joined) {
309
+ this.setStatus(t("palette.notJoined"), "error");
310
+ return;
311
+ }
312
+ try {
313
+ await this.api.leave(room.id, this.sessionID);
314
+ this.stopPolling();
315
+ this.state.joined = false;
316
+ const summary = this.state.rooms.find((item) => item.id === room.id);
317
+ if (summary)
318
+ summary.joined = false;
319
+ await this.refreshRooms(true);
320
+ this.setStatus(t("palette.left", { name: room.name }), "success");
321
+ }
322
+ catch (error) {
323
+ this.setStatus(t("palette.leaveFailed", { error: errorText(error) }), "error");
324
+ }
325
+ },
326
+ setPaletteQuery(value) {
327
+ const palette = this.state.palette;
328
+ if (!palette || (palette.mode !== "commands" && palette.mode !== "search"))
329
+ return;
330
+ const query = String(value ?? "");
331
+ palette.error = "";
332
+ if (!query.trim()) {
333
+ palette.mode = "search";
334
+ palette.query = "";
335
+ palette.results = [];
336
+ palette.selected = 0;
337
+ palette.searching = false;
338
+ this.touch();
339
+ return;
340
+ }
341
+ if (query.trimStart().startsWith("/")) {
342
+ palette.mode = "commands";
343
+ palette.query = query;
344
+ palette.results = [];
345
+ palette.searching = false;
346
+ palette.selected = 0;
347
+ this.touch();
348
+ return;
349
+ }
350
+ palette.mode = "search";
351
+ palette.query = query;
352
+ palette.selected = 0;
353
+ this.refreshPaletteResults();
354
+ void this.ensureSearchHistory();
355
+ },
356
+ setPalettePrompt(value) {
357
+ const palette = this.state.palette;
358
+ if (palette?.prompt)
359
+ palette.prompt.value = String(value ?? "");
360
+ },
361
+ togglePaletteScope() {
362
+ const palette = this.state.palette;
363
+ if (!palette || palette.mode !== "search")
364
+ return;
365
+ palette.scope = nextScope(palette.scope ?? "room");
366
+ palette.selected = 0;
367
+ palette.error = "";
368
+ this.refreshPaletteResults();
369
+ void this.ensureSearchHistory();
370
+ },
371
+ });
372
+ }