@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
@@ -1,9 +1,9 @@
1
- // Room files: a file-browser dialog over the room's uploaded resources.
2
1
  import { LS } from "./state.js";
3
2
  import { isRoomAdmin } from "./admin-badge.js";
4
3
  import { icon } from "./icons.js";
5
4
  import { docPreviewFormat, isDocPreviewResource, OFFICE_KINDS, TEXT_PREVIEW_LIMIT } from "./resource-format.js";
6
5
  import { createCopyButton, copyResourceText } from "./copy-action.js";
6
+ import { closeOnBackdrop } from "./panels.js";
7
7
  const PAGE_SIZE = 500;
8
8
  const UNKNOWN_UPLOADER = "__unknown_uploader__";
9
9
  const ICONS = {
@@ -15,6 +15,23 @@ const ICONS = {
15
15
  download: "arrow_download",
16
16
  trash: "delete",
17
17
  };
18
+ function isRecord(value) {
19
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
20
+ }
21
+ function readResource(value) {
22
+ if (!isRecord(value) || typeof value.id !== "string")
23
+ return null;
24
+ return {
25
+ id: value.id,
26
+ name: typeof value.name === "string" ? value.name : "",
27
+ roomID: typeof value.roomID === "string" ? value.roomID : "",
28
+ mimeType: typeof value.mimeType === "string" ? value.mimeType : undefined,
29
+ size: typeof value.size === "number" ? value.size : undefined,
30
+ createdAt: typeof value.createdAt === "number" ? value.createdAt : undefined,
31
+ uploaderName: typeof value.uploaderName === "string" ? value.uploaderName : undefined,
32
+ uploaderSessionID: typeof value.uploaderSessionID === "string" ? value.uploaderSessionID : undefined,
33
+ };
34
+ }
18
35
  export function initFiles(app) {
19
36
  const dialog = app.$("#filesDialog");
20
37
  if (!dialog)
@@ -23,7 +40,10 @@ export function initFiles(app) {
23
40
  const list = $("#fileList"), select = $("#filesUploader"), summary = $("#filesSummary");
24
41
  const empty = $("#filesEmpty"), error = $("#filesError"), more = $("#btnFilesMore");
25
42
  const roomName = $("#filesRoomName"), heading = $("#filesHeading"), trigger = $("#btnFiles"), chatView = $("#chatView");
26
- let items = [], total = 0, loading = false, generation = 0, opener = null, preview = null, previewToken = 0;
43
+ if (!list || !select || !summary || !empty || !error || !more || !roomName || !heading || !chatView)
44
+ return;
45
+ let items = [], total = 0, loading = false, generation = 0, opener = null;
46
+ let preview = null, previewToken = 0;
27
47
  let pendingReopen = false, restoreFocus = true;
28
48
  const mediaKind = (mime) => /^image\//.test(mime || "") ? "image"
29
49
  : /^audio\//.test(mime || "") ? "audio"
@@ -42,7 +62,8 @@ export function initFiles(app) {
42
62
  return `${size.toLocaleString(app.intlLocale(), { maximumFractionDigits: size >= 10 ? 0 : 1 })} ${units[unit]}`;
43
63
  };
44
64
  const selfIsHuman = () => {
45
- const self = app.state.memberSessions.get(app.state.room?.id)?.find((member) => member.sessionID === LS.sessionID);
65
+ const roomId = app.state.room?.id;
66
+ const self = roomId ? app.state.memberSessions.get(roomId)?.find((member) => member.sessionID === LS.sessionID) : undefined;
46
67
  return !self || self.type === "human";
47
68
  };
48
69
  const canDelete = (resource) => {
@@ -78,6 +99,8 @@ export function initFiles(app) {
78
99
  if (!kind)
79
100
  return;
80
101
  const box = row.querySelector(".file-preview");
102
+ if (!box)
103
+ return;
81
104
  box.hidden = false;
82
105
  box.classList.remove("is-error");
83
106
  box.textContent = app.t("resourceLoading");
@@ -91,10 +114,11 @@ export function initFiles(app) {
91
114
  const url = URL.createObjectURL(blob);
92
115
  const media = kind === "image" ? new Image() : document.createElement(kind);
93
116
  media.className = `file-preview-media file-preview-${kind}`;
94
- media.src = url;
95
- if (kind === "image")
117
+ if (media instanceof HTMLImageElement || media instanceof HTMLMediaElement)
118
+ media.src = url;
119
+ if (media instanceof HTMLImageElement)
96
120
  media.alt = resource.name;
97
- else {
121
+ else if (media instanceof HTMLMediaElement) {
98
122
  media.controls = true;
99
123
  media.setAttribute("aria-label", resource.name);
100
124
  }
@@ -298,20 +322,23 @@ export function initFiles(app) {
298
322
  summary.textContent = app.t("filesLoading");
299
323
  try {
300
324
  const offset = reset ? 0 : items.length;
301
- const before = !reset && items.length ? `&before=${encodeURIComponent(items.at(-1).id)}` : "";
325
+ const lastItem = items.at(-1);
326
+ const before = !reset && lastItem ? `&before=${encodeURIComponent(lastItem.id)}` : "";
302
327
  const page = await app.api(`/rooms/${encodeURIComponent(room.id)}/resources?limit=${PAGE_SIZE}&offset=${offset}${before}`, {
303
328
  headers: { "x-session-id": LS.sessionID },
304
329
  });
305
330
  if (request !== generation || app.state.room?.id !== room.id)
306
331
  return;
332
+ const payload = isRecord(page) ? page : {};
307
333
  const seen = new Set(items.map((item) => item.id));
308
- for (const resource of Array.isArray(page.resources) ? page.resources : []) {
309
- if (!resource || typeof resource.id !== "string" || seen.has(resource.id))
334
+ for (const value of Array.isArray(payload.resources) ? payload.resources : []) {
335
+ const resource = readResource(value);
336
+ if (!resource || seen.has(resource.id))
310
337
  continue;
311
338
  seen.add(resource.id);
312
339
  items.push(resource);
313
340
  }
314
- total = Number(page.total) || items.length;
341
+ total = Number(payload.total) || items.length;
315
342
  render();
316
343
  }
317
344
  catch {
@@ -397,7 +424,9 @@ export function initFiles(app) {
397
424
  dialog.close();
398
425
  };
399
426
  trigger?.addEventListener("click", () => { app.closePanels(); open(); });
400
- $("#btnCloseFiles")?.addEventListener("click", close);
427
+ $("#btnCloseFiles")?.addEventListener("click", () => close());
428
+ // The file browser is a list, so a backdrop click dismisses it; pane mode has no backdrop.
429
+ closeOnBackdrop(dialog, () => close());
401
430
  document.addEventListener("keydown", (event) => {
402
431
  if (event.key !== "Escape" || event.altKey || !dialog.open || !dialog.classList.contains("is-pane"))
403
432
  return;
@@ -442,11 +471,14 @@ export function initFiles(app) {
442
471
  target.focus({ preventScroll: true });
443
472
  });
444
473
  list.addEventListener("click", (event) => {
445
- const button = event.target.closest?.("[data-file-action]");
474
+ const target = event.target instanceof Element ? event.target : null;
475
+ const button = target?.closest("[data-file-action]");
446
476
  if (!button || !list.contains(button))
447
477
  return;
448
478
  const row = button.closest(".file-row");
449
- const resource = items.find((item) => item.id === row?.dataset.resourceId);
479
+ if (!row)
480
+ return;
481
+ const resource = items.find((item) => item.id === row.dataset.resourceId);
450
482
  if (!resource)
451
483
  return;
452
484
  const action = button.dataset.fileAction;
@@ -17,7 +17,8 @@ export function initHistoryLoader(app) {
17
17
  const prependOlder = (older, thread, list) => {
18
18
  // The loading spinner can be the first child; only a day separator at the
19
19
  // boundary is a duplicate to drop.
20
- const tailSep = list.firstElementChild?.classList.contains("day-sep") ? list.firstElementChild : null;
20
+ const first = list.firstElementChild;
21
+ const tailSep = first instanceof HTMLElement && first.classList.contains("day-sep") ? first : null;
21
22
  const fragment = document.createDocumentFragment();
22
23
  let day = null;
23
24
  for (const message of older) {
@@ -36,7 +37,8 @@ export function initHistoryLoader(app) {
36
37
  }
37
38
  const beforeHeight = thread.scrollHeight, beforeTop = thread.scrollTop;
38
39
  list.prepend(fragment);
39
- if (tailSep?.classList.contains("day-sep") && new Date(older.at(-1).createdAt).toDateString() === tailSep.dataset.day)
40
+ const last = older.at(-1), tailDay = last && new Date(last.createdAt).toDateString();
41
+ if (tailSep?.classList.contains("day-sep") && tailDay === tailSep.dataset.day)
40
42
  tailSep.remove();
41
43
  app.cancelThreadScrollAnimation?.();
42
44
  thread.scrollTop = beforeTop + (thread.scrollHeight - beforeHeight);
@@ -45,7 +47,7 @@ export function initHistoryLoader(app) {
45
47
  app.loadOlderHistory = async () => {
46
48
  const room = app.state.room, entry = room && app.state.rooms.get(room.id);
47
49
  const thread = $("#thread"), list = $("#msgList");
48
- if (!room || !entry || loading)
50
+ if (!room || !entry || !thread || !list || loading)
49
51
  return;
50
52
  loading = true;
51
53
  const generation = app.state.pollGeneration;
@@ -1,21 +1,25 @@
1
- // An image in a message opens full-screen in a native dialog. Nothing in the
2
- // message list moves: the overlay is a top-layer dialog, not a row change.
3
1
  export function initImageZoom(app) {
4
2
  const dialog = app.$("#imageDialog"), preview = app.$("#imageDialogImage");
5
3
  const zoomLevel = app.$("#zoomLevel"), zoomOut = app.$("#btnZoomOut"), zoomIn = app.$("#btnZoomIn"), zoomReset = app.$("#btnZoomReset");
4
+ if (!dialog || !preview)
5
+ return;
6
6
  const MAX = 4, STEP = 1.25;
7
- let trigger = null, scale = 1, fitScale = 1, pendingFit = false, panX = 0, panY = 0, drag = null;
7
+ let trigger = null, scale = 1, fitScale = 1, pendingFit = false, panX = 0, panY = 0;
8
+ let drag = null;
8
9
  const clamp = (value, min, max) => Math.min(max, Math.max(min, value));
9
- const imageOf = (node) => node?.closest?.("#msgList img, #attachmentList img");
10
- function fitLimit() {
10
+ const imageOf = (node) => {
11
+ const image = node instanceof Element ? node.closest("#msgList img, #attachmentList img") : null;
12
+ return image instanceof HTMLImageElement ? image : null;
13
+ };
14
+ const fitLimit = () => {
11
15
  const style = getComputedStyle(dialog);
12
16
  const width = dialog.clientWidth - parseFloat(style.paddingLeft) - parseFloat(style.paddingRight);
13
17
  const height = dialog.clientHeight - parseFloat(style.paddingTop) - parseFloat(style.paddingBottom);
14
18
  if (!preview.naturalWidth || !preview.naturalHeight)
15
19
  return 1;
16
20
  return Math.min(1, width / preview.naturalWidth, height / preview.naturalHeight);
17
- }
18
- function limits() {
21
+ };
22
+ const limits = () => {
19
23
  const style = getComputedStyle(dialog);
20
24
  const box = dialog.getBoundingClientRect();
21
25
  const left = box.left + parseFloat(style.paddingLeft), right = box.right - parseFloat(style.paddingRight);
@@ -34,8 +38,8 @@ export function initImageZoom(app) {
34
38
  const minY = fitsY ? 0 : bottom - baseTop - scaledHeight;
35
39
  const maxY = fitsY ? 0 : top - baseTop;
36
40
  return { minX, maxX, minY, maxY, x: maxX - minX, y: maxY - minY };
37
- }
38
- function apply() {
41
+ };
42
+ const apply = () => {
39
43
  const limit = limits();
40
44
  panX = clamp(panX, limit.minX, limit.maxX);
41
45
  panY = clamp(panY, limit.minY, limit.maxY);
@@ -47,8 +51,8 @@ export function initImageZoom(app) {
47
51
  zoomOut.disabled = scale <= fitScale + .001;
48
52
  if (zoomIn)
49
53
  zoomIn.disabled = scale >= MAX - .001;
50
- }
51
- function zoomTo(next, x = innerWidth / 2, y = innerHeight / 2) {
54
+ };
55
+ const zoomTo = (next, x = innerWidth / 2, y = innerHeight / 2) => {
52
56
  const target = clamp(next, fitScale, MAX);
53
57
  if (Math.abs(target - scale) < .001)
54
58
  return apply();
@@ -64,17 +68,17 @@ export function initImageZoom(app) {
64
68
  }
65
69
  preview.style.animation = "none";
66
70
  apply();
67
- }
71
+ };
68
72
  const zoomBy = (factor) => zoomTo(scale * factor);
69
- function resetZoom() {
73
+ const resetZoom = () => {
70
74
  fitScale = fitLimit();
71
75
  scale = fitScale;
72
76
  pendingFit = false;
73
77
  panX = 0;
74
78
  panY = 0;
75
79
  apply();
76
- }
77
- function open(image) {
80
+ };
81
+ const open = (image) => {
78
82
  if (!image || !dialog)
79
83
  return;
80
84
  trigger = image;
@@ -92,7 +96,7 @@ export function initImageZoom(app) {
92
96
  apply();
93
97
  else
94
98
  resetZoom();
95
- }
99
+ };
96
100
  const close = () => { if (dialog.open)
97
101
  dialog.close(); };
98
102
  // A click that focuses the image makes the browser scroll it into view; the
@@ -135,7 +139,7 @@ export function initImageZoom(app) {
135
139
  if (!dialog.open)
136
140
  return;
137
141
  event.preventDefault();
138
- if (event.target.closest?.(".image-dialog-tools, .image-dialog-close"))
142
+ if (event.target instanceof Element && event.target.closest(".image-dialog-tools, .image-dialog-close"))
139
143
  return;
140
144
  const delta = event.deltaMode === 1 ? event.deltaY * 16 : event.deltaY;
141
145
  zoomTo(scale * Math.exp(-delta * .0015), event.clientX, event.clientY);
@@ -1,10 +1,10 @@
1
- // A one-time install recommendation for phones. The browser prompt itself is deferred
2
- // until the Install button gesture; desktop, standalone, installed, and recent dissent
3
- // all stay silent. Local storage is optional: blocked storage falls back to this tab.
4
1
  const DISMISS_MS = 30 * 24 * 60 * 60 * 1000;
5
2
  const DISMISS_KEY = "chat.installDismissedAt";
6
3
  const INSTALLED_KEY = "chat.installedApp";
7
4
  const memory = new Map();
5
+ function installPromptEvent(event) {
6
+ return "prompt" in event && typeof event.prompt === "function";
7
+ }
8
8
  function read(key) {
9
9
  try {
10
10
  return localStorage.getItem(key);
@@ -33,7 +33,8 @@ function isIos() {
33
33
  return /iPad|iPhone|iPod/.test(navigator.userAgent) || (navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1);
34
34
  }
35
35
  function isStandalone() {
36
- return matchMedia("(display-mode: standalone)").matches || navigator.standalone === true;
36
+ return matchMedia("(display-mode: standalone)").matches
37
+ || navigator.standalone === true;
37
38
  }
38
39
  export function initInstallPrompt(app) {
39
40
  const card = app.$("#installPrompt"), installButton = app.$("#btnInstallApp"), guideButton = app.$("#btnInstallGuide"), guide = app.$("#installGuide"), dismissButton = app.$("#btnDismissInstall");
@@ -43,7 +44,7 @@ export function initInstallPrompt(app) {
43
44
  const eligible = () => matchMedia("(max-width: 760px)").matches && window.isSecureContext;
44
45
  const suppressed = () => read(INSTALLED_KEY) === "1" || Number(read(DISMISS_KEY) || 0) > Date.now() - DISMISS_MS;
45
46
  let deferred = null;
46
- function hide() {
47
+ const hide = () => {
47
48
  const fromCard = card.contains(document.activeElement), fromRail = rail.contains(document.activeElement);
48
49
  card.hidden = true;
49
50
  rail.hidden = true;
@@ -51,10 +52,10 @@ export function initInstallPrompt(app) {
51
52
  app.$("#inName")?.focus({ preventScroll: true });
52
53
  else if (fromRail)
53
54
  app.$("#btnSettings")?.focus({ preventScroll: true });
54
- }
55
+ };
55
56
  // The join card explains itself; the room drawer carries the same offer for people
56
57
  // who restore straight into a room and never see the join page.
57
- function render(mode) {
58
+ const render = (mode) => {
58
59
  const visible = Boolean(mode) && eligible() && !isStandalone() && !suppressed();
59
60
  card.hidden = rail.hidden = !visible;
60
61
  if (!visible)
@@ -67,9 +68,9 @@ export function initInstallPrompt(app) {
67
68
  guide.hidden = true;
68
69
  guideButton.setAttribute("aria-expanded", "false");
69
70
  }
70
- }
71
+ };
71
72
  window.addEventListener("beforeinstallprompt", (event) => {
72
- if (!eligible() || isStandalone() || suppressed())
73
+ if (!installPromptEvent(event) || !eligible() || isStandalone() || suppressed())
73
74
  return;
74
75
  event.preventDefault();
75
76
  deferred = event;
@@ -1,4 +1,3 @@
1
- // Account form generated from the JSON Schema a plugin declares in initialize.
2
1
  const CONTROL = { string: "text", secret: "password", number: "number" };
3
2
  function textFor(field, fallback) {
4
3
  return typeof field.label === "string" && field.label.trim() ? field.label : fallback;
@@ -43,7 +42,7 @@ function addField(container, field, existing, stored, text) {
43
42
  else {
44
43
  control = document.createElement("input");
45
44
  control.className = "input";
46
- control.type = CONTROL[field.type] || "text";
45
+ control.type = (field.type && CONTROL[field.type]) || "text";
47
46
  control.autocomplete = field.type === "secret" ? "new-password" : "off";
48
47
  if (existing)
49
48
  control.placeholder = stored ? text("integrationsLeaveBlank") : text("integrationsNotSet");
@@ -65,7 +64,8 @@ function addField(container, field, existing, stored, text) {
65
64
  }
66
65
  export function renderAccountSchema(container, plugin, account, text) {
67
66
  container.textContent = "";
68
- const fields = Array.isArray(plugin?.account?.schema) ? plugin.account.schema : [];
67
+ const schema = plugin?.account?.schema;
68
+ const fields = Array.isArray(schema) ? schema : [];
69
69
  container.hidden = fields.length === 0;
70
70
  if (!fields.length)
71
71
  return;
@@ -84,6 +84,8 @@ export function readAccountSchema(container, text) {
84
84
  const missing = [];
85
85
  for (const control of container.querySelectorAll("[data-account-key]")) {
86
86
  const key = control.dataset.accountKey;
87
+ if (key === undefined)
88
+ continue;
87
89
  keys.add(key);
88
90
  const value = String(control.value ?? "").trim();
89
91
  if (value !== "") {
@@ -1,5 +1,3 @@
1
- // Lazy Monaco wrapper for one integration rules section. The textarea stays in the
2
- // page as the no-JS and failed-download fallback, so this module never imports Monaco.
3
1
  const BUNDLE_URL = "/assets/monaco/integration-rules.js";
4
2
  const STYLES_URL = "/assets/monaco/integration-rules.css";
5
3
  let bundlePromise = null;
@@ -63,6 +61,8 @@ export function initIntegrationEditor(app, options) {
63
61
  return;
64
62
  }
65
63
  const first = result.errors[0];
64
+ if (!first)
65
+ return;
66
66
  error.textContent = app.t("integrationsRulesErrors", {
67
67
  count: result.errors.length,
68
68
  first: `Line ${first.line}: ${first.message}`,
@@ -1,7 +1,7 @@
1
- // Parsing and account-reference checks for integration rules and inbound routes.
2
1
  const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
3
2
  export function cleanError(error, fallback) {
4
- const value = String(error?.message || error || "").trim()
3
+ const detail = error instanceof Error ? error.message || error : error;
4
+ const value = String(detail || "").trim()
5
5
  .replace(/channeld/gi, "integrations")
6
6
  .replace(/\bBearer\s+\S+/gi, "Bearer [redacted]")
7
7
  .replace(/\b(secret|token|password|authorization|api[_-]?key)\b\s*[:=]\s*\S+/gi, "$1=[redacted]");
@@ -62,7 +62,8 @@ export function parseRules(value, accounts, text) {
62
62
  rules = JSON.parse(value || "[]");
63
63
  }
64
64
  catch (error) {
65
- throw new Error(text("integrationsInvalidJson", { line: jsonLine(value, String(error.message)) }));
65
+ const message = error instanceof Error ? error.message : String(error);
66
+ throw new Error(text("integrationsInvalidJson", { line: jsonLine(value, message) }));
66
67
  }
67
68
  return checkRules(rules, accounts, text);
68
69
  }
@@ -85,12 +86,14 @@ export function checkRules(rules, accounts, text) {
85
86
  if (!isRecord(target))
86
87
  throw new Error(text("integrationsInvalidRules"));
87
88
  for (const field of ["platform", "account", "room"]) {
88
- if (typeof target[field] !== "string" || !target[field].trim()) {
89
+ const value = target[field];
90
+ if (typeof value !== "string" || !value.trim()) {
89
91
  throw new Error(text("integrationsTargetRequired", { index: ruleNumber, target: targetIndex + 1, field }));
90
92
  }
91
93
  }
92
- if (!known.has(target.account)) {
93
- throw new Error(text("integrationsTargetMissing", { index: ruleNumber, target: targetIndex + 1, account: target.account }));
94
+ const targetAccount = typeof target.account === "string" ? target.account : "";
95
+ if (!known.has(targetAccount)) {
96
+ throw new Error(text("integrationsTargetMissing", { index: ruleNumber, target: targetIndex + 1, account: targetAccount }));
94
97
  }
95
98
  });
96
99
  });
@@ -102,7 +105,8 @@ export function parseInbound(value, accounts, text) {
102
105
  inbound = JSON.parse(value || "[]");
103
106
  }
104
107
  catch (error) {
105
- throw new Error(text("integrationsInvalidJson", { line: jsonLine(value, String(error.message)) }));
108
+ const message = error instanceof Error ? error.message : String(error);
109
+ throw new Error(text("integrationsInvalidJson", { line: jsonLine(value, message) }));
106
110
  }
107
111
  return checkInbound(inbound, accounts);
108
112
  }
@@ -116,16 +120,18 @@ export function checkInbound(inbound, accounts) {
116
120
  throw new Error(`${label}: from is required.`);
117
121
  const from = route.from;
118
122
  for (const field of ["platform", "account", "room"]) {
119
- if (typeof from[field] !== "string" || !from[field].trim())
123
+ const value = from[field];
124
+ if (typeof value !== "string" || !value.trim())
120
125
  throw new Error(`${label}: from.${field} is required.`);
121
126
  }
122
127
  if (from.event !== undefined && typeof from.event !== "string")
123
128
  throw new Error(`${label}: from.event must be a string.`);
124
- const account = known.get(from.account);
129
+ const fromAccount = typeof from.account === "string" ? from.account : "";
130
+ const account = known.get(fromAccount);
125
131
  if (!account)
126
- throw new Error(`${label}: account “${from.account}” does not exist.`);
132
+ throw new Error(`${label}: account “${fromAccount}” does not exist.`);
127
133
  if (account.platform !== from.platform)
128
- throw new Error(`${label}: account “${from.account}” belongs to “${account.platform}”.`);
134
+ throw new Error(`${label}: account “${fromAccount}” belongs to “${account.platform}”.`);
129
135
  if (!isRecord(route.to) || typeof route.to.room !== "string" || !route.to.room.trim())
130
136
  throw new Error(`${label}: to.room is required.`);
131
137
  });