@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
@@ -4,248 +4,263 @@
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
+ try {
241
+ await this.api.deleteRoom(settings.room.id, this.sessionID);
242
+ this.stopPolling();
243
+ this.state.rooms = this.state.rooms.filter((room) => room.id !== settings.room.id);
244
+ this.state.current = null;
245
+ this.state.joined = false;
246
+ this.state.messages = [];
247
+ this.state.pending = null;
248
+ this.state.selected = Math.min(this.state.selected, Math.max(0, this.state.rooms.length - 1));
249
+ this.closePalette();
250
+ this.setStatus(t("room.deleted", { name: confirm.data.name }), "success");
251
+ }
252
+ catch (error) {
253
+ if (this.state.palette === palette) {
254
+ palette.searching = false;
255
+ palette.error = errorText(error);
256
+ this.touch();
257
+ }
258
+ }
259
+ return;
260
+ }
261
+ if (confirm.action !== "room-join-policy")
262
+ return;
263
+ await this.applyRoomPatch({ joinPolicy: confirm.data.joinPolicy }, t("room.policySet", { policy: confirm.data.joinPolicy }));
264
+ },
265
+ });
266
+ }