@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
@@ -4,248 +4,281 @@
4
4
  import { roomSettingsMarkdown } from "./info-content.mjs";
5
5
  import { createInfoPalette } from "./info-app.mjs";
6
6
  import { t } from "./i18n.mjs";
7
-
8
7
  const errorText = (error) => (error instanceof Error ? error.message : String(error ?? "unknown error"));
9
-
8
+ function settingsRoom(room, description) {
9
+ return {
10
+ id: room.id,
11
+ name: room.name,
12
+ description,
13
+ ownerId: room.ownerId,
14
+ adminIds: room.adminIds,
15
+ adminSessionID: room.adminSessionID ?? undefined,
16
+ successorId: room.successorId ?? undefined,
17
+ joinPolicy: room.joinPolicy,
18
+ kind: room.kind,
19
+ };
20
+ }
21
+ // The wire type does not declare description, but the server sends it.
22
+ function roomDescription(room) {
23
+ return "description" in room && typeof room.description === "string" ? room.description : undefined;
24
+ }
10
25
  export function attachRoomSettings(Class) {
11
- Object.assign(Class.prototype, {
12
- async openRoomSettings() {
13
- const current = this.state.current;
14
- if (!current || !this.state.joined) {
15
- this.state.palette = null;
16
- this.setStatus(t("info.joinFirst"), "error");
17
- return;
18
- }
19
- this.roomSettings = null;
20
- const palette = {
21
- ...createInfoPalette("room-settings", t("room.title"), `#${current.name}`),
22
- mode: "detail",
23
- detail: { title: t("room.title"), markdown: t("common.loading"), kind: "room-settings" },
24
- hint: t("palette.detailHint"),
25
- };
26
- this.state.palette = palette;
27
- this.touch();
28
- try {
29
- const [room, members] = await Promise.all([
30
- this.api.getRoom(current.id),
31
- this.api.members(current.id).catch(() => []),
32
- ]);
33
- if (this.state.palette !== palette) return;
34
- const owner = room.ownerId === this.participant;
35
- const admin = owner || (room.adminIds ?? []).includes(this.participant);
36
- const canEdit = Boolean(admin) && typeof this.api.updateRoom === "function";
37
- const canDelete = owner && typeof this.api.deleteRoom === "function";
38
- const agent = (members ?? []).find((member) => member.sessionID === room.adminSessionID);
39
- this.roomSettings = { room, canEdit, canDelete };
40
- palette.roomMeta = room;
41
- palette.detail = {
42
- title: t("room.title"),
43
- markdown: roomSettingsMarkdown(room, {
44
- participant: this.participant,
45
- sessionID: this.sessionID,
46
- canEdit,
47
- agentName: agent ? `${agent.name} (agent)` : "",
48
- }),
49
- kind: "room-settings",
50
- };
51
- palette.hint = canEdit ? t("room.editHint") : t("room.readOnlyHint");
52
- if (canDelete) {
53
- palette.hint = canEdit ? t("room.editDeleteHint") : t("room.deleteOnlyHint");
54
- }
55
- palette.error = "";
56
- this.touch();
57
- } catch (error) {
58
- if (this.state.palette !== palette) return;
59
- this.roomSettings = null;
60
- palette.detail = {
61
- title: t("room.title"),
62
- markdown: `${t("room.loadFailed")}\n\n${errorText(error)}`,
63
- kind: "room-settings",
64
- };
65
- palette.error = errorText(error);
66
- palette.hint = t("room.readOnlyHint");
67
- this.touch();
68
- }
69
- },
70
-
71
- roomSettingsGuard() {
72
- const palette = this.state.palette;
73
- const settings = this.roomSettings;
74
- if (
75
- palette?.kind !== "room-settings"
76
- || !settings?.canEdit
77
- || settings.room.id !== this.state.current?.id
78
- ) {
79
- if (palette) {
80
- palette.error = t("room.guardEdit");
81
- this.touch();
82
- }
83
- return null;
84
- }
85
- return settings;
86
- },
87
-
88
- startRoomRename() {
89
- const settings = this.roomSettingsGuard();
90
- const palette = this.state.palette;
91
- if (!settings || !palette) return;
92
- palette.mode = "prompt";
93
- palette.prompt = { label: t("room.namePrompt"), value: settings.room.name, action: "room-name", data: {} };
94
- palette.error = "";
95
- palette.hint = t("palette.enterSaveHint");
96
- this.touch();
97
- },
98
-
99
- startRoomDescription() {
100
- const settings = this.roomSettingsGuard();
101
- const palette = this.state.palette;
102
- if (!settings || !palette) return;
103
- palette.mode = "prompt";
104
- palette.prompt = {
105
- label: t("room.descriptionPrompt"),
106
- value: settings.room.description ?? "",
107
- action: "room-description",
108
- data: {},
109
- };
110
- palette.error = "";
111
- palette.hint = t("room.descriptionHint");
112
- this.touch();
113
- },
114
-
115
- askRoomJoinPolicy() {
116
- const settings = this.roomSettingsGuard();
117
- const palette = this.state.palette;
118
- if (!settings || !palette) return;
119
- const next = settings.room.joinPolicy === "approval" ? "open" : "approval";
120
- palette.mode = "confirm";
121
- palette.previous = { mode: "detail", hint: palette.hint };
122
- palette.confirm = {
123
- text: t("room.policyConfirm", { policy: next }),
124
- action: "room-join-policy",
125
- data: { joinPolicy: next },
126
- };
127
- palette.error = "";
128
- palette.hint = t("room.policyHint");
129
- this.touch();
130
- },
131
-
132
- askDeleteRoom() {
133
- const settings = this.roomSettings;
134
- const palette = this.state.palette;
135
- const current = this.state.current?.id;
136
- if (
137
- !settings?.canDelete
138
- || !palette
139
- || settings.room.id !== current
140
- || palette.kind !== "room-settings"
141
- ) {
142
- if (palette) {
143
- palette.error = t("room.guardDelete");
144
- this.touch();
145
- }
146
- return;
147
- }
148
- palette.mode = "confirm";
149
- palette.previous = { mode: "detail", hint: palette.hint };
150
- palette.confirm = {
151
- text: t("room.deleteConfirm", { name: settings.room.name }),
152
- action: "room-delete",
153
- data: { id: settings.room.id, name: settings.room.name },
154
- };
155
- palette.error = "";
156
- palette.hint = t("palette.deleteHint");
157
- this.touch();
158
- },
159
-
160
- async submitRoomSettingsPrompt(prompt, value) {
161
- const settings = this.roomSettingsGuard();
162
- const palette = this.state.palette;
163
- if (!settings || !palette) return;
164
- if (prompt.action === "room-name") {
165
- const name = String(value ?? "").trim();
166
- if (!name || Array.from(name).length > 64) {
167
- palette.error = t("room.nameInvalid");
168
- this.touch();
169
- return;
170
- }
171
- await this.applyRoomPatch({ name }, t("room.renamed", { name }));
172
- return;
173
- }
174
- if (prompt.action === "room-description") {
175
- const description = String(value ?? "").trim();
176
- if (Array.from(description).length > 2000) {
177
- palette.error = t("room.descriptionInvalid");
178
- this.touch();
179
- return;
180
- }
181
- await this.applyRoomPatch({ description }, t("room.descriptionUpdated"));
182
- }
183
- },
184
-
185
- async applyRoomPatch(patch, status) {
186
- const settings = this.roomSettingsGuard();
187
- const palette = this.state.palette;
188
- if (!settings || !palette) return;
189
- palette.searching = true;
190
- palette.error = "";
191
- this.touch();
192
- try {
193
- const result = await this.api.updateRoom(settings.room.id, this.sessionID, patch);
194
- if (patch.name) {
195
- const name = String(result?.name ?? patch.name);
196
- this.state.current.name = name;
197
- const summary = this.state.rooms.find((item) => item.id === settings.room.id);
198
- if (summary) summary.name = name;
199
- }
200
- this.setStatus(status, "success");
201
- await this.openRoomSettings();
202
- } catch (error) {
203
- if (this.state.palette === palette) {
204
- palette.searching = false;
205
- palette.error = errorText(error);
206
- this.touch();
207
- }
208
- }
209
- },
210
-
211
- async runRoomSettingsConfirm(confirm) {
212
- if (confirm.action === "room-delete") {
213
- const palette = this.state.palette;
214
- const settings = this.roomSettings;
215
- if (
216
- !palette
217
- || !settings?.canDelete
218
- || settings.room.id !== this.state.current?.id
219
- || settings.room.id !== confirm.data.id
220
- ) return;
221
- palette.searching = true;
222
- palette.error = "";
223
- this.touch();
224
- try {
225
- await this.api.deleteRoom(confirm.data.id, this.sessionID);
226
- this.stopPolling();
227
- this.state.rooms = this.state.rooms.filter((room) => room.id !== confirm.data.id);
228
- this.state.current = null;
229
- this.state.joined = false;
230
- this.state.messages = [];
231
- this.state.pending = null;
232
- this.state.selected = Math.min(this.state.selected, Math.max(0, this.state.rooms.length - 1));
233
- this.closePalette();
234
- this.setStatus(t("room.deleted", { name: confirm.data.name }), "success");
235
- } catch (error) {
236
- if (this.state.palette === palette) {
237
- palette.searching = false;
238
- palette.error = errorText(error);
26
+ Object.assign(Class.prototype, {
27
+ async openRoomSettings() {
28
+ const current = this.state.current;
29
+ if (!current || !this.state.joined) {
30
+ this.state.palette = null;
31
+ this.setStatus(t("info.joinFirst"), "error");
32
+ return;
33
+ }
34
+ this.roomSettings = null;
35
+ const palette = {
36
+ ...createInfoPalette("room-settings", t("room.title"), `#${current.name}`),
37
+ mode: "detail",
38
+ detail: { title: t("room.title"), markdown: t("common.loading"), kind: "room-settings" },
39
+ hint: t("palette.detailHint"),
40
+ };
41
+ this.state.palette = palette;
239
42
  this.touch();
240
- }
241
- }
242
- return;
243
- }
244
- if (confirm.action !== "room-join-policy") return;
245
- await this.applyRoomPatch(
246
- { joinPolicy: confirm.data.joinPolicy },
247
- t("room.policySet", { policy: confirm.data.joinPolicy }),
248
- );
249
- },
250
- });
251
- }
43
+ try {
44
+ const [room, members] = await Promise.all([
45
+ this.api.getRoom(current.id),
46
+ this.api.members(current.id).catch(() => []),
47
+ ]);
48
+ if (this.state.palette !== palette)
49
+ return;
50
+ if (!room)
51
+ throw new Error(t("room.loadFailed"));
52
+ const settings = settingsRoom(room, roomDescription(room));
53
+ const owner = settings.ownerId === this.participant;
54
+ const admin = owner || (settings.adminIds ?? []).includes(this.participant);
55
+ const canEdit = Boolean(admin) && typeof this.api.updateRoom === "function";
56
+ const canDelete = owner && typeof this.api.deleteRoom === "function";
57
+ const agent = members.find((member) => member.sessionID === settings.adminSessionID);
58
+ this.roomSettings = { room: settings, canEdit, canDelete };
59
+ palette.roomMeta = room;
60
+ palette.detail = {
61
+ title: t("room.title"),
62
+ markdown: roomSettingsMarkdown(settings, {
63
+ participant: this.participant,
64
+ sessionID: this.sessionID,
65
+ canEdit,
66
+ agentName: agent ? `${agent.name} (agent)` : "",
67
+ }),
68
+ kind: "room-settings",
69
+ };
70
+ palette.hint = canEdit ? t("room.editHint") : t("room.readOnlyHint");
71
+ if (canDelete) {
72
+ palette.hint = canEdit ? t("room.editDeleteHint") : t("room.deleteOnlyHint");
73
+ }
74
+ palette.error = "";
75
+ this.touch();
76
+ }
77
+ catch (error) {
78
+ if (this.state.palette !== palette)
79
+ return;
80
+ this.roomSettings = null;
81
+ palette.detail = {
82
+ title: t("room.title"),
83
+ markdown: `${t("room.loadFailed")}\n\n${errorText(error)}`,
84
+ kind: "room-settings",
85
+ };
86
+ palette.error = errorText(error);
87
+ palette.hint = t("room.readOnlyHint");
88
+ this.touch();
89
+ }
90
+ },
91
+ roomSettingsGuard() {
92
+ const palette = this.state.palette;
93
+ const settings = this.roomSettings;
94
+ if (palette?.kind !== "room-settings"
95
+ || !settings?.canEdit
96
+ || settings.room.id !== this.state.current?.id) {
97
+ if (palette) {
98
+ palette.error = t("room.guardEdit");
99
+ this.touch();
100
+ }
101
+ return null;
102
+ }
103
+ return settings;
104
+ },
105
+ startRoomRename() {
106
+ const settings = this.roomSettingsGuard();
107
+ const palette = this.state.palette;
108
+ if (!settings || !palette)
109
+ return;
110
+ palette.mode = "prompt";
111
+ palette.prompt = { label: t("room.namePrompt"), value: settings.room.name ?? "", action: "room-name", data: {} };
112
+ palette.error = "";
113
+ palette.hint = t("palette.enterSaveHint");
114
+ this.touch();
115
+ },
116
+ startRoomDescription() {
117
+ const settings = this.roomSettingsGuard();
118
+ const palette = this.state.palette;
119
+ if (!settings || !palette)
120
+ return;
121
+ palette.mode = "prompt";
122
+ palette.prompt = {
123
+ label: t("room.descriptionPrompt"),
124
+ value: settings.room.description ?? "",
125
+ action: "room-description",
126
+ data: {},
127
+ };
128
+ palette.error = "";
129
+ palette.hint = t("room.descriptionHint");
130
+ this.touch();
131
+ },
132
+ askRoomJoinPolicy() {
133
+ const settings = this.roomSettingsGuard();
134
+ const palette = this.state.palette;
135
+ if (!settings || !palette)
136
+ return;
137
+ const next = settings.room.joinPolicy === "approval" ? "open" : "approval";
138
+ palette.mode = "confirm";
139
+ palette.previous = { mode: "detail", hint: palette.hint };
140
+ palette.confirm = {
141
+ text: t("room.policyConfirm", { policy: next }),
142
+ action: "room-join-policy",
143
+ data: { joinPolicy: next },
144
+ };
145
+ palette.error = "";
146
+ palette.hint = t("room.policyHint");
147
+ this.touch();
148
+ },
149
+ askDeleteRoom() {
150
+ const settings = this.roomSettings;
151
+ const palette = this.state.palette;
152
+ const current = this.state.current?.id;
153
+ if (!settings?.canDelete
154
+ || !palette
155
+ || settings.room.id !== current
156
+ || palette.kind !== "room-settings") {
157
+ if (palette) {
158
+ palette.error = t("room.guardDelete");
159
+ this.touch();
160
+ }
161
+ return;
162
+ }
163
+ palette.mode = "confirm";
164
+ palette.previous = { mode: "detail", hint: palette.hint };
165
+ palette.confirm = {
166
+ text: t("room.deleteConfirm", { name: settings.room.name }),
167
+ action: "room-delete",
168
+ data: { id: settings.room.id, name: settings.room.name },
169
+ };
170
+ palette.error = "";
171
+ palette.hint = t("palette.deleteHint");
172
+ this.touch();
173
+ },
174
+ async submitRoomSettingsPrompt(prompt, value) {
175
+ const settings = this.roomSettingsGuard();
176
+ const palette = this.state.palette;
177
+ if (!settings || !palette)
178
+ return;
179
+ if (prompt.action === "room-name") {
180
+ const name = String(value ?? "").trim();
181
+ if (!name || Array.from(name).length > 64) {
182
+ palette.error = t("room.nameInvalid");
183
+ this.touch();
184
+ return;
185
+ }
186
+ await this.applyRoomPatch({ name }, t("room.renamed", { name }));
187
+ return;
188
+ }
189
+ if (prompt.action === "room-description") {
190
+ const description = String(value ?? "").trim();
191
+ if (Array.from(description).length > 2000) {
192
+ palette.error = t("room.descriptionInvalid");
193
+ this.touch();
194
+ return;
195
+ }
196
+ await this.applyRoomPatch({ description }, t("room.descriptionUpdated"));
197
+ }
198
+ },
199
+ async applyRoomPatch(patch, status) {
200
+ const settings = this.roomSettingsGuard();
201
+ const palette = this.state.palette;
202
+ if (!settings || !palette)
203
+ return;
204
+ palette.searching = true;
205
+ palette.error = "";
206
+ this.touch();
207
+ try {
208
+ const result = await this.api.updateRoom(settings.room.id, this.sessionID, patch);
209
+ if (patch.name) {
210
+ const name = String(result?.name ?? patch.name);
211
+ if (this.state.current)
212
+ this.state.current.name = name;
213
+ const summary = this.state.rooms.find((item) => item.id === settings.room.id);
214
+ if (summary)
215
+ summary.name = name;
216
+ }
217
+ this.setStatus(status, "success");
218
+ await this.openRoomSettings();
219
+ }
220
+ catch (error) {
221
+ if (this.state.palette === palette) {
222
+ palette.searching = false;
223
+ palette.error = errorText(error);
224
+ this.touch();
225
+ }
226
+ }
227
+ },
228
+ async runRoomSettingsConfirm(confirm) {
229
+ if (confirm.action === "room-delete") {
230
+ const palette = this.state.palette;
231
+ const settings = this.roomSettings;
232
+ if (!palette
233
+ || !settings?.canDelete
234
+ || settings.room.id !== this.state.current?.id
235
+ || settings.room.id !== confirm.data.id)
236
+ return;
237
+ palette.searching = true;
238
+ palette.error = "";
239
+ this.touch();
240
+ const deletedID = settings.room.id;
241
+ try {
242
+ await this.api.deleteRoom(deletedID, this.sessionID);
243
+ const showingDeleted = this.state.current?.id === deletedID;
244
+ const selectedID = this.state.rooms[this.state.selected]?.id;
245
+ this.state.rooms = this.state.rooms.filter((room) => room.id !== deletedID);
246
+ const selected = selectedID ? this.state.rooms.findIndex((room) => room.id === selectedID) : -1;
247
+ this.state.selected = selected >= 0 ? selected : Math.min(this.state.selected, Math.max(0, this.state.rooms.length - 1));
248
+ this.drafts.delete(deletedID);
249
+ this.pendingSends.delete(deletedID);
250
+ this.inflightSends.delete(deletedID);
251
+ this.cache.delete(deletedID);
252
+ this.historyCursor.delete(deletedID);
253
+ this.historyMore.delete(deletedID);
254
+ this.historyPages.delete(deletedID);
255
+ this.historyInflight.delete(deletedID);
256
+ if (showingDeleted) {
257
+ if (this.state.palette)
258
+ this.closePalette();
259
+ this.stopPolling();
260
+ this.state.current = null;
261
+ this.state.joined = false;
262
+ this.state.messages = [];
263
+ this.state.pending = null;
264
+ this.state.draft = "";
265
+ this.state.highlight = null;
266
+ this.state.focus = "rooms";
267
+ }
268
+ this.setStatus(t("room.deleted", { name: confirm.data.name }), "success");
269
+ }
270
+ catch (error) {
271
+ if (this.state.palette === palette) {
272
+ palette.searching = false;
273
+ palette.error = errorText(error);
274
+ this.touch();
275
+ }
276
+ }
277
+ return;
278
+ }
279
+ if (confirm.action !== "room-join-policy")
280
+ return;
281
+ await this.applyRoomPatch({ joinPolicy: confirm.data.joinPolicy }, t("room.policySet", { policy: confirm.data.joinPolicy }));
282
+ },
283
+ });
284
+ }