@alexsun-top/opencode-chat-room 0.8.4 → 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 (136) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/README.md +4 -4
  3. package/README.zh-CN.md +4 -4
  4. package/cli.ts +1 -1
  5. package/dist/cli.js +35 -16
  6. package/package.json +14 -11
  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.js +4 -1
  15. package/server/assets/chat/announcements.js +3 -0
  16. package/server/assets/chat/attachments.js +3 -3
  17. package/server/assets/chat/clipboard.js +1 -1
  18. package/server/assets/chat/copy-action.js +1 -1
  19. package/server/assets/chat/doc-preview.js +1 -1
  20. package/server/assets/chat/editor.js +11 -7
  21. package/server/assets/chat/events.js +7 -5
  22. package/server/assets/chat/files.js +5 -1
  23. package/server/assets/chat/integration-editor.js +2 -0
  24. package/server/assets/chat/integrations.js +1 -1
  25. package/server/assets/chat/join-requests.js +1 -1
  26. package/server/assets/chat/markdown-footnotes.js +8 -7
  27. package/server/assets/chat/markdown.js +6 -5
  28. package/server/assets/chat/members.js +3 -3
  29. package/server/assets/chat/mentions.js +8 -5
  30. package/server/assets/chat/message-cache.js +1 -1
  31. package/server/assets/chat/message-polling.js +2 -2
  32. package/server/assets/chat/message-window.js +1 -1
  33. package/server/assets/chat/messages.js +17 -3
  34. package/server/assets/chat/office-preview.js +3 -3
  35. package/server/assets/chat/palette.js +5 -3
  36. package/server/assets/chat/panels.js +19 -0
  37. package/server/assets/chat/questions.js +3 -2
  38. package/server/assets/chat/reminders.js +3 -0
  39. package/server/assets/chat/replies.js +6 -3
  40. package/server/assets/chat/resource-format.js +2 -2
  41. package/server/assets/chat/rooms.js +7 -4
  42. package/server/assets/chat/settings.js +4 -3
  43. package/server/assets/chat/shortcuts.js +3 -1
  44. package/server/assets/chat/side-pane.js +1 -1
  45. package/server/assets/chat/state.js +30 -11
  46. package/server/assets/chat/system-events.js +3 -2
  47. package/server/assets/chat/system-messages.js +15 -15
  48. package/server/assets/chat/tasks.js +4 -3
  49. package/server/assets/chat/window-controls.js +3 -2
  50. package/server/assets/conversation.css +14 -2
  51. package/server/assets/doc-preview.css +6 -0
  52. package/server/assets/office/THIRD-PARTY-NOTICES.txt +23 -1
  53. package/server/assets/office/licenses/docx-preview-HEADER.txt +6 -0
  54. package/server/assets/office/licenses/echarts-LICENSE-d3.txt +27 -0
  55. package/server/assets/office/licenses/echarts-NOTICE.txt +5 -0
  56. package/server/assets/office/licenses/immediate-LICENSE.txt +20 -0
  57. package/server/assets/office/licenses/lie-LICENSE.txt +7 -0
  58. package/server/assets/office/licenses/pako-LICENSE.txt +21 -0
  59. package/server/assets/office/licenses/pako-ZLIB.txt +18 -0
  60. package/server/assets/office/licenses/setimmediate-LICENSE.txt +20 -0
  61. package/server/sw.js +3 -1
  62. package/skills/chatroom/SKILL.md +9 -0
  63. package/src/README.md +1 -1
  64. package/src/agent/agent-receipts.ts +12 -4
  65. package/src/center/center-client.ts +1 -1
  66. package/src/state/pg-sql.mjs +157 -142
  67. package/src/state/pg-sql.mts +175 -0
  68. package/src/state/pg-worker.mjs +107 -99
  69. package/src/state/pg-worker.mts +166 -0
  70. package/src/state/store.ts +21 -7
  71. package/src/tui/app-types.mjs +1 -0
  72. package/src/tui/app-types.mts +175 -0
  73. package/src/tui/app.mjs +426 -423
  74. package/src/tui/app.mts +500 -0
  75. package/src/tui/config.mjs +166 -158
  76. package/src/tui/config.mts +247 -0
  77. package/src/tui/http.mjs +239 -206
  78. package/src/tui/http.mts +412 -0
  79. package/src/tui/i18n.mjs +17 -20
  80. package/src/tui/i18n.mts +42 -0
  81. package/src/tui/info-app.mjs +431 -427
  82. package/src/tui/info-app.mts +500 -0
  83. package/src/tui/info-content.mjs +205 -199
  84. package/src/tui/info-content.mts +341 -0
  85. package/src/tui/join-app.mjs +75 -64
  86. package/src/tui/join-app.mts +99 -0
  87. package/src/tui/locales/en.mjs +302 -320
  88. package/src/tui/locales/en.mts +349 -0
  89. package/src/tui/locales/zh-CN.mjs +302 -320
  90. package/src/tui/locales/zh-CN.mts +349 -0
  91. package/src/tui/main.mjs +219 -213
  92. package/src/tui/main.mts +255 -0
  93. package/src/tui/markdown.mjs +128 -272
  94. package/src/tui/markdown.mts +152 -0
  95. package/src/tui/mentions.mjs +181 -184
  96. package/src/tui/mentions.mts +251 -0
  97. package/src/tui/message-app.mjs +181 -173
  98. package/src/tui/message-app.mts +213 -0
  99. package/src/tui/message-view.mjs +90 -111
  100. package/src/tui/message-view.mts +151 -0
  101. package/src/tui/messages.mjs +55 -49
  102. package/src/tui/messages.mts +106 -0
  103. package/src/tui/palette-app.mjs +364 -344
  104. package/src/tui/palette-app.mts +388 -0
  105. package/src/tui/palette.mjs +100 -98
  106. package/src/tui/palette.mts +176 -0
  107. package/src/tui/prefs.mjs +56 -63
  108. package/src/tui/prefs.mts +126 -0
  109. package/src/tui/reminder-app.mjs +191 -181
  110. package/src/tui/reminder-app.mts +228 -0
  111. package/src/tui/room-settings-app.mjs +257 -242
  112. package/src/tui/room-settings-app.mts +301 -0
  113. package/src/tui/session.mjs +30 -29
  114. package/src/tui/session.mts +51 -0
  115. package/src/tui/settings-app.mjs +151 -138
  116. package/src/tui/settings-app.mts +179 -0
  117. package/src/tui/ui-content.mjs +426 -421
  118. package/src/tui/ui-content.mts +499 -0
  119. package/src/tui/ui-help.mjs +58 -67
  120. package/src/tui/ui-help.mts +87 -0
  121. package/src/tui/ui-mentions.mjs +34 -36
  122. package/src/tui/ui-mentions.mts +60 -0
  123. package/src/tui/ui-overlay-view.mjs +259 -267
  124. package/src/tui/ui-overlay-view.mts +322 -0
  125. package/src/tui/ui-suggest-view.mjs +54 -57
  126. package/src/tui/ui-suggest-view.mts +78 -0
  127. package/src/tui/ui-suggest.mjs +164 -167
  128. package/src/tui/ui-suggest.mts +248 -0
  129. package/src/tui/ui-theme.mjs +52 -57
  130. package/src/tui/ui-theme.mts +98 -0
  131. package/src/tui/ui-view.mjs +267 -275
  132. package/src/tui/ui-view.mts +308 -0
  133. package/src/tui/ui.mjs +372 -359
  134. package/src/tui/ui.mts +440 -0
  135. package/src/tui/wire.mjs +215 -0
  136. package/src/tui/wire.mts +383 -0
@@ -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
+ }