@alexsun-top/opencode-chat-room 0.8.3 → 0.8.4

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 (56) hide show
  1. package/CHANGELOG.md +3 -1
  2. package/README.md +4 -4
  3. package/README.zh-CN.md +4 -4
  4. package/package.json +6 -3
  5. package/server/assets/chat/admin-badge.js +1 -1
  6. package/server/assets/chat/admin.js +12 -9
  7. package/server/assets/chat/announcements.js +9 -2
  8. package/server/assets/chat/attachment-store.js +15 -6
  9. package/server/assets/chat/attachments.js +46 -31
  10. package/server/assets/chat/chat-background.js +8 -14
  11. package/server/assets/chat/clipboard.js +2 -1
  12. package/server/assets/chat/confirm-dialog.js +3 -3
  13. package/server/assets/chat/copy-action.js +0 -1
  14. package/server/assets/chat/diagram-viewer.js +7 -9
  15. package/server/assets/chat/doc-preview.js +18 -11
  16. package/server/assets/chat/editor.js +80 -58
  17. package/server/assets/chat/events.js +43 -30
  18. package/server/assets/chat/files.js +41 -13
  19. package/server/assets/chat/history-loader.js +5 -3
  20. package/server/assets/chat/image-zoom.js +21 -17
  21. package/server/assets/chat/install-prompt.js +10 -9
  22. package/server/assets/chat/integration-account-schema.js +5 -3
  23. package/server/assets/chat/integration-editor.js +0 -2
  24. package/server/assets/chat/integration-values.js +17 -11
  25. package/server/assets/chat/integrations.js +137 -80
  26. package/server/assets/chat/join-requests.js +19 -12
  27. package/server/assets/chat/markdown-footnotes.js +0 -1
  28. package/server/assets/chat/markdown.js +43 -34
  29. package/server/assets/chat/members.js +45 -22
  30. package/server/assets/chat/mentions.js +31 -7
  31. package/server/assets/chat/message-cache.js +1 -1
  32. package/server/assets/chat/message-polling.js +38 -19
  33. package/server/assets/chat/message-window.js +9 -5
  34. package/server/assets/chat/messages.js +53 -43
  35. package/server/assets/chat/palette.js +40 -26
  36. package/server/assets/chat/panels.js +0 -1
  37. package/server/assets/chat/pwa.js +5 -4
  38. package/server/assets/chat/questions.js +22 -20
  39. package/server/assets/chat/recall.js +39 -21
  40. package/server/assets/chat/receipts.js +9 -7
  41. package/server/assets/chat/reminders.js +22 -8
  42. package/server/assets/chat/replies.js +28 -12
  43. package/server/assets/chat/room-list.js +2 -2
  44. package/server/assets/chat/room-watcher.js +8 -4
  45. package/server/assets/chat/rooms.js +44 -36
  46. package/server/assets/chat/search.js +8 -6
  47. package/server/assets/chat/settings.js +12 -11
  48. package/server/assets/chat/shiki.js +1 -1
  49. package/server/assets/chat/shortcuts.js +0 -2
  50. package/server/assets/chat/side-pane.js +3 -2
  51. package/server/assets/chat/state.js +35 -26
  52. package/server/assets/chat/system-events.js +4 -4
  53. package/server/assets/chat/task-form.js +5 -5
  54. package/server/assets/chat/task-row.js +1 -1
  55. package/server/assets/chat/tasks.js +37 -25
  56. package/server/chat.html +1 -0
@@ -1,4 +1,3 @@
1
- // Settings > Integrations: runtime switch, accounts, plugin uploads, and rules.
2
1
  import { initIntegrationEditor } from "./integration-editor.js";
3
2
  import { iconNode } from "./icons.js";
4
3
  import { readAccountSchema, renderAccountSchema } from "./integration-account-schema.js";
@@ -9,6 +8,45 @@ const IDENTIFIER = /^[A-Za-z0-9._-]{1,128}$/;
9
8
  const PLUGIN_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*\.(?:js|mjs|cjs|ts)$/;
10
9
  const ENV_KEY = /^[A-Za-z_][A-Za-z0-9_]*$/;
11
10
  const isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
11
+ function readPlugin(value) {
12
+ const account = isRecord(value.account) ? value.account : null;
13
+ return {
14
+ ...value,
15
+ pluginId: String(value.pluginId ?? ""),
16
+ name: String(value.name ?? ""),
17
+ platform: String(value.platform ?? ""),
18
+ account: account ? { env: account.env, schema: account.schema } : undefined,
19
+ };
20
+ }
21
+ function normalizeAccountRow(account) {
22
+ return {
23
+ id: account.id,
24
+ platform: account.platform,
25
+ pluginId: account.pluginId,
26
+ envKeys: account.envKeys ?? [],
27
+ storedKeys: account.storedKeys ?? [],
28
+ envSet: account.envSet ?? {},
29
+ envDelete: account.envDelete ?? [],
30
+ envClear: account.envClear ?? false,
31
+ state: account.state ?? "unknown",
32
+ lastError: account.lastError ?? "",
33
+ };
34
+ }
35
+ function pluginsOf(data) {
36
+ return knownPlugins(data).map((plugin) => readPlugin(isRecord(plugin) ? plugin : {}));
37
+ }
38
+ function envFieldsOf(plugin) {
39
+ const account = plugin && isRecord(plugin.account) ? plugin.account : {};
40
+ const env = Array.isArray(account.env) ? account.env : [];
41
+ return env.filter(isRecord).map((field) => ({
42
+ key: String(field.key ?? ""),
43
+ label: typeof field.label === "string" ? field.label : undefined,
44
+ description: typeof field.description === "string" ? field.description : undefined,
45
+ }));
46
+ }
47
+ function errorText(error) {
48
+ return error instanceof Error ? error.message : String(error);
49
+ }
12
50
  export function initIntegrations(app) {
13
51
  const $ = app.$;
14
52
  const panel = $("#settingsPanelIntegrations");
@@ -30,12 +68,20 @@ export function initIntegrations(app) {
30
68
  const accountClear = $("#btnClearAccountEnv"), accountAddEnv = $("#btnAddAccountEnv");
31
69
  const pluginDialog = $("#integrationPluginDialog"), pluginForm = $("#integrationPluginForm");
32
70
  const pluginError = $("#integrationPluginError"), pluginFile = $("#integrationPluginFile");
71
+ if (!enabledInput || !statusText || !integrationBody || !disabledHint || !panelError || !accountsList
72
+ || !accountsEmpty || !pluginsList || !pluginsEmpty || !rulesError || !saveButton
73
+ || !accountDialog || !accountForm || !accountError || !accountId || !accountPlugin || !accountSchema
74
+ || !accountSchemaField || !accountAdvanced || !accountEnv || !accountEnvNote || !accountClear || !accountAddEnv
75
+ || !pluginDialog || !pluginForm || !pluginError || !pluginFile)
76
+ return;
77
+ const api = (url, options) => app.api(url, options);
33
78
  let data = { enabled: false, source: "managed", editable: true, accounts: [], rules: [], inbound: [], plugins: [] };
34
79
  let initialInbound = "[]";
35
- let loaded = false, loading = false, saving = false, accountDraft = null, clearEnv = false;
80
+ let loaded = false, loading = false, saving = false, clearEnv = false;
81
+ let accountDraft = null;
36
82
  let pluginUploadSource = "", pluginUploadName = "";
37
83
  const text = (key, values) => app.t(key, values);
38
- const clean = (error) => cleanError(error, text("integrationsLoadFailed"));
84
+ const clean = (error) => String(cleanError(error, text("integrationsLoadFailed")));
39
85
  const showPanelError = (error) => { panelError.textContent = clean(error); panelError.hidden = false; };
40
86
  const hidePanelError = () => { panelError.hidden = true; };
41
87
  const showStatus = (value) => { statusText.textContent = value; };
@@ -67,7 +113,7 @@ export function initIntegrations(app) {
67
113
  getValue: () => data.inbound,
68
114
  getAccounts: () => data.accounts,
69
115
  });
70
- function applyEditableState() {
116
+ const applyEditableState = () => {
71
117
  const editable = data.editable !== false;
72
118
  if (externalNotice)
73
119
  externalNotice.hidden = editable;
@@ -78,30 +124,30 @@ export function initIntegrations(app) {
78
124
  uploadPluginButton.disabled = !editable;
79
125
  rulesSection.setEditable(editable);
80
126
  inboundSection.setEditable(editable);
81
- }
82
- function applyEnabledState() {
127
+ };
128
+ const applyEnabledState = () => {
83
129
  const enabled = enabledInput.checked;
84
130
  integrationBody.hidden = !enabled;
85
131
  disabledHint.hidden = enabled;
86
- }
87
- const pluginNameOf = (pluginId) => knownPlugins(data).find((plugin) => plugin.pluginId === pluginId)?.name || pluginId;
132
+ };
133
+ const pluginNameOf = (pluginId) => String(pluginsOf(data).find((plugin) => plugin.pluginId === pluginId)?.name || pluginId);
88
134
  function adopt(snapshot) {
89
135
  const raw = isRecord(snapshot) ? snapshot : {};
90
136
  data = {
91
137
  enabled: raw.enabled === true,
92
138
  source: typeof raw.source === "string" ? raw.source : "managed",
93
139
  editable: raw.editable !== false,
94
- accounts: Array.isArray(raw.accounts) ? raw.accounts.filter(isRecord).map(normalizeAccount) : [],
140
+ accounts: Array.isArray(raw.accounts) ? raw.accounts.filter(isRecord).map((account) => normalizeAccountRow(normalizeAccount(account))) : [],
95
141
  rules: Array.isArray(raw.rules) ? raw.rules : [],
96
142
  inbound: Array.isArray(raw.inbound) ? raw.inbound : data.inbound,
97
143
  plugins: Array.isArray(raw.plugins)
98
- ? raw.plugins.filter((plugin) => isRecord(plugin) && typeof plugin.pluginId === "string" && typeof plugin.name === "string" && typeof plugin.platform === "string")
144
+ ? raw.plugins.filter(isRecord).filter((plugin) => typeof plugin.pluginId === "string" && typeof plugin.name === "string" && typeof plugin.platform === "string").map(readPlugin)
99
145
  : data.plugins,
100
146
  };
101
147
  initialInbound = JSON.stringify(data.inbound);
102
148
  loaded = true;
103
149
  }
104
- function renderAccounts() {
150
+ const renderAccounts = () => {
105
151
  accountsList.textContent = "";
106
152
  for (const account of data.accounts) {
107
153
  const row = document.createElement("li");
@@ -163,9 +209,9 @@ export function initIntegrations(app) {
163
209
  accountsEmpty.hidden = data.accounts.length > 0;
164
210
  rulesSection.setAccounts(data.accounts);
165
211
  inboundSection.setAccounts(data.accounts);
166
- }
167
- function renderPlugins() {
168
- const plugins = knownPlugins(data);
212
+ };
213
+ const renderPlugins = () => {
214
+ const plugins = pluginsOf(data);
169
215
  pluginsList.textContent = "";
170
216
  for (const plugin of plugins) {
171
217
  const row = document.createElement("li");
@@ -187,7 +233,7 @@ export function initIntegrations(app) {
187
233
  pluginsList.append(row);
188
234
  }
189
235
  pluginsEmpty.hidden = plugins.length > 0;
190
- }
236
+ };
191
237
  async function downloadPlugin(plugin, button) {
192
238
  if (button.disabled)
193
239
  return;
@@ -217,14 +263,14 @@ export function initIntegrations(app) {
217
263
  inboundSection.setAccounts(data.accounts);
218
264
  hideRulesError();
219
265
  }
220
- function renderAll() {
266
+ const renderAll = () => {
221
267
  enabledInput.checked = data.enabled;
222
268
  renderAccounts();
223
269
  renderPlugins();
224
270
  renderRules();
225
271
  applyEnabledState();
226
272
  applyEditableState();
227
- }
273
+ };
228
274
  async function load(force = false) {
229
275
  if (loading || loaded && !force)
230
276
  return;
@@ -234,7 +280,7 @@ export function initIntegrations(app) {
234
280
  hidePanelError();
235
281
  showStatus(text("integrationsLoading"));
236
282
  try {
237
- adopt(await app.api("/channeld/integration", { cache: "no-store" }));
283
+ adopt(await api("/channeld/integration", { cache: "no-store" }));
238
284
  renderAll();
239
285
  showStatus("");
240
286
  }
@@ -247,24 +293,24 @@ export function initIntegrations(app) {
247
293
  }
248
294
  }
249
295
  app.loadIntegrations = () => { void load(true); };
250
- function setSaving(busy) {
296
+ const setSaving = (busy) => {
251
297
  saving = busy;
252
298
  saveButton.disabled = busy || data.editable === false;
253
299
  enabledInput.disabled = busy;
254
- }
300
+ };
255
301
  let envMenuSerial = 0;
256
- function envFields() {
257
- const plugin = knownPlugins(data).find((item) => item.pluginId === accountPlugin.value);
258
- return (plugin?.account?.env ?? []).filter((field) => ENV_KEY.test(field.key));
259
- }
260
- function closeEnvMenus(except) {
302
+ const envFields = () => {
303
+ const plugin = pluginsOf(data).find((item) => item.pluginId === accountPlugin.value);
304
+ return envFieldsOf(plugin).filter((field) => ENV_KEY.test(field.key));
305
+ };
306
+ const closeEnvMenus = (except) => {
261
307
  for (const menu of accountEnv.querySelectorAll(".integration-env-menu")) {
262
308
  if (menu === except)
263
309
  continue;
264
310
  menu.hidden = true;
265
311
  menu.parentElement?.querySelector(".integration-env-key")?.setAttribute("aria-expanded", "false");
266
312
  }
267
- }
313
+ };
268
314
  function addEnvRow(container, entry = {}, existing = false, onRemove = null) {
269
315
  const row = document.createElement("div");
270
316
  row.className = `integration-env-row${existing ? " is-stored" : ""}`;
@@ -300,7 +346,7 @@ export function initIntegrations(app) {
300
346
  key.setAttribute("aria-expanded", "false");
301
347
  };
302
348
  const choose = (option) => {
303
- key.value = option.dataset.key;
349
+ key.value = option.dataset.key ?? "";
304
350
  hide();
305
351
  value.focus();
306
352
  };
@@ -401,8 +447,12 @@ export function initIntegrations(app) {
401
447
  function readEnv(container) {
402
448
  const values = {};
403
449
  for (const row of container.querySelectorAll(".integration-env-row")) {
404
- const key = row.querySelector(".integration-env-key").value.trim();
405
- const value = row.querySelector(".integration-env-value").value;
450
+ const keyNode = row.querySelector(".integration-env-key");
451
+ const valueNode = row.querySelector(".integration-env-value");
452
+ if (!keyNode || !valueNode)
453
+ continue;
454
+ const key = keyNode.value.trim();
455
+ const value = valueNode.value;
406
456
  if (!key && !value)
407
457
  continue;
408
458
  if (!ENV_KEY.test(key) || Object.hasOwn(values, key))
@@ -412,9 +462,9 @@ export function initIntegrations(app) {
412
462
  }
413
463
  return values;
414
464
  }
415
- function fillPlugins(selected) {
465
+ const fillPlugins = (selected) => {
416
466
  accountPlugin.textContent = "";
417
- const plugins = knownPlugins(data);
467
+ const plugins = pluginsOf(data);
418
468
  if (!plugins.length) {
419
469
  const option = document.createElement("option");
420
470
  option.value = "";
@@ -428,14 +478,14 @@ export function initIntegrations(app) {
428
478
  accountPlugin.append(option);
429
479
  }
430
480
  accountPlugin.value = plugins.some((plugin) => plugin.pluginId === selected) ? selected : plugins[0]?.pluginId || "";
431
- }
481
+ };
432
482
  /** Stable once saved; a blank ID is only a convenience for new accounts. */
433
483
  function newAccountId(plugin) {
434
484
  const prefix = String(plugin?.platform || "account").replace(/[^A-Za-z0-9._-]/g, "") || "account";
435
485
  const bytes = crypto.getRandomValues(new Uint8Array(4));
436
486
  return `${prefix}-${[...bytes].map((byte) => byte.toString(16).padStart(2, "0")).join("")}`;
437
487
  }
438
- function setClearEnv(next) {
488
+ const setClearEnv = (next) => {
439
489
  clearEnv = next;
440
490
  accountClear.textContent = text(next ? "integrationsKeepEnv" : "integrationsClearEnv");
441
491
  accountEnvNote.hidden = !next;
@@ -445,7 +495,7 @@ export function initIntegrations(app) {
445
495
  control.disabled = next;
446
496
  for (const control of accountSchema.querySelectorAll("input, select, button"))
447
497
  control.disabled = next;
448
- }
498
+ };
449
499
  function removeStoredKey(key) {
450
500
  if (!key || !accountDraft)
451
501
  return;
@@ -456,19 +506,19 @@ export function initIntegrations(app) {
456
506
  if (accountDraft.envSet)
457
507
  delete accountDraft.envSet[key];
458
508
  }
459
- function syncAccountSchema() {
460
- const plugin = knownPlugins(data).find((item) => item.pluginId === accountPlugin.value);
509
+ const syncAccountSchema = () => {
510
+ const plugin = pluginsOf(data).find((item) => item.pluginId === accountPlugin.value);
461
511
  closeEnvMenus();
462
512
  renderAccountSchema(accountSchema, plugin, accountDraft?.id ? accountDraft : null, text);
463
513
  accountSchemaField.hidden = accountSchema.hidden;
464
514
  // Without a declared schema the raw env rows are the only way to configure
465
515
  // the account, so keep them open; schema-backed plugins can collapse them.
466
516
  accountAdvanced.open = accountSchema.hidden;
467
- }
468
- function openAccount(account = null, presetPlugin = "") {
517
+ };
518
+ const openAccount = (account = null, presetPlugin = "") => {
469
519
  if (data.editable === false)
470
520
  return;
471
- if (!knownPlugins(data).length) {
521
+ if (!pluginsOf(data).length) {
472
522
  showPanelError(text("integrationsPluginFirst"));
473
523
  return;
474
524
  }
@@ -492,25 +542,26 @@ export function initIntegrations(app) {
492
542
  setClearEnv(Boolean(account?.envClear));
493
543
  accountDialog.showModal();
494
544
  accountPlugin.focus();
495
- }
496
- function closeAccount() {
545
+ };
546
+ const closeAccount = () => {
497
547
  if (accountDialog.open)
498
548
  accountDialog.close();
499
549
  accountDraft = null;
500
- }
550
+ };
501
551
  accountForm.addEventListener("submit", (event) => {
502
552
  event.preventDefault();
503
- if (!accountDraft)
553
+ const draft = accountDraft;
554
+ if (!draft)
504
555
  return;
505
556
  hideAccountError();
506
557
  const pluginId = accountPlugin.value;
507
- const plugin = knownPlugins(data).find((item) => item.pluginId === pluginId);
558
+ const plugin = pluginsOf(data).find((item) => item.pluginId === pluginId);
508
559
  if (!plugin)
509
560
  return showAccountError(text("integrationsAccountInvalid"));
510
- const id = accountDraft.id || accountId.value.trim() || newAccountId(plugin);
561
+ const id = draft.id || accountId.value.trim() || newAccountId(plugin);
511
562
  if (!IDENTIFIER.test(id))
512
563
  return showAccountError(text("integrationsAccountInvalid"));
513
- if (data.accounts.some((item) => item.id === id && item.id !== accountDraft.id)) {
564
+ if (data.accounts.some((item) => item.id === id && item.id !== draft.id)) {
514
565
  return showAccountError(text("integrationsDuplicateAccount"));
515
566
  }
516
567
  let values;
@@ -528,37 +579,38 @@ export function initIntegrations(app) {
528
579
  return showAccountError(error);
529
580
  }
530
581
  // A schema field and a free-form env row can name the same key: the schema wins.
531
- for (const key of schema.keys)
582
+ const schemaKeys = [...schema.keys].filter((key) => typeof key === "string");
583
+ for (const key of schemaKeys)
532
584
  delete values[key];
533
585
  const schemaValues = clearEnv ? {} : schema.values;
534
- const envSet = clearEnv ? {} : { ...(accountDraft.envSet || {}), ...values, ...schemaValues };
535
- const deleted = new Set(clearEnv ? [] : accountDraft.envDelete || []);
586
+ const envSet = clearEnv ? {} : { ...(draft.envSet || {}), ...values, ...schemaValues };
587
+ const deleted = new Set(clearEnv ? [] : draft.envDelete || []);
536
588
  for (const key of Object.keys(values))
537
589
  deleted.delete(key);
538
590
  for (const key of Object.keys(schemaValues))
539
591
  deleted.delete(key);
540
- const remaining = (accountDraft.envKeys || []).filter((key) => !deleted.has(key));
592
+ const remaining = (draft.envKeys || []).filter((key) => !deleted.has(key));
541
593
  const next = {
542
594
  id,
543
595
  platform: plugin.platform,
544
596
  pluginId: plugin.pluginId,
545
- state: accountDraft.state,
546
- lastError: accountDraft.lastError,
597
+ state: draft.state,
598
+ lastError: draft.lastError,
547
599
  envKeys: clearEnv ? [] : [...new Set([...remaining, ...Object.keys(envSet)])],
548
- storedKeys: accountDraft.storedKeys || [],
600
+ storedKeys: draft.storedKeys || [],
549
601
  envSet,
550
602
  envDelete: clearEnv ? [] : [...deleted].filter((key) => !Object.hasOwn(envSet, key)),
551
603
  envClear: clearEnv,
552
604
  };
553
- data.accounts = accountDraft.id
554
- ? data.accounts.map((item) => item.id === accountDraft.id ? next : item)
605
+ data.accounts = draft.id
606
+ ? data.accounts.map((item) => item.id === draft.id ? next : item)
555
607
  : [...data.accounts, next];
556
608
  renderAccounts();
557
609
  renderPlugins();
558
610
  closeAccount();
559
611
  showStatus(text("integrationsAccountSaved"));
560
612
  });
561
- async function save() {
613
+ const save = async () => {
562
614
  if (saving || data.editable === false)
563
615
  return;
564
616
  if (data.enabled && !enabledInput.checked && !(await app.confirmAction(text("integrationsDisableConfirm")))) {
@@ -575,11 +627,12 @@ export function initIntegrations(app) {
575
627
  if (rulesState.editor) {
576
628
  if (rulesState.errors.length)
577
629
  return;
630
+ const editorValue = Reflect.get(rulesState, "value");
578
631
  try {
579
- rules = checkRules(rulesState.value, data.accounts, text);
632
+ rules = checkRules(editorValue, data.accounts, text);
580
633
  }
581
634
  catch (error) {
582
- return rulesSection.showMessage(error.message);
635
+ return rulesSection.showMessage(errorText(error));
583
636
  }
584
637
  }
585
638
  else {
@@ -587,7 +640,7 @@ export function initIntegrations(app) {
587
640
  rules = parseRules(rulesState.text, data.accounts, text);
588
641
  }
589
642
  catch (error) {
590
- return showRulesError(error.message);
643
+ return showRulesError(errorText(error));
591
644
  }
592
645
  }
593
646
  const inboundState = inboundSection.current();
@@ -595,11 +648,12 @@ export function initIntegrations(app) {
595
648
  if (inboundState.editor) {
596
649
  if (inboundState.errors.length)
597
650
  return;
651
+ const editorValue = Reflect.get(inboundState, "value");
598
652
  try {
599
- inbound = checkInbound(inboundState.value, data.accounts);
653
+ inbound = checkInbound(editorValue, data.accounts);
600
654
  }
601
655
  catch (error) {
602
- return inboundSection.showMessage(error.message);
656
+ return inboundSection.showMessage(errorText(error));
603
657
  }
604
658
  }
605
659
  else {
@@ -607,13 +661,13 @@ export function initIntegrations(app) {
607
661
  inbound = parseInbound(inboundState.text, data.accounts, text);
608
662
  }
609
663
  catch (error) {
610
- return inboundSection.showMessage(error.message);
664
+ return inboundSection.showMessage(errorText(error));
611
665
  }
612
666
  }
613
667
  const inboundChanged = JSON.stringify(inbound) !== initialInbound;
614
668
  setSaving(true);
615
669
  try {
616
- adopt(await app.api("/channeld/integration", {
670
+ adopt(await api("/channeld/integration", {
617
671
  method: "PUT",
618
672
  body: JSON.stringify({
619
673
  enabled: enabledInput.checked,
@@ -633,8 +687,8 @@ export function initIntegrations(app) {
633
687
  finally {
634
688
  setSaving(false);
635
689
  }
636
- }
637
- function openUpload() {
690
+ };
691
+ const openUpload = () => {
638
692
  if (data.editable === false)
639
693
  return;
640
694
  pluginForm.reset();
@@ -643,7 +697,7 @@ export function initIntegrations(app) {
643
697
  hidePluginError();
644
698
  pluginDialog.showModal();
645
699
  pluginFile.focus();
646
- }
700
+ };
647
701
  pluginFile.addEventListener("change", async () => {
648
702
  const file = pluginFile.files?.[0];
649
703
  pluginUploadSource = "";
@@ -672,18 +726,21 @@ export function initIntegrations(app) {
672
726
  if (new TextEncoder().encode(source).length > MAX_SOURCE)
673
727
  return showPluginError(text("integrationsSourceTooLarge"));
674
728
  const submit = $("#btnSaveIntegrationPlugin");
729
+ if (!submit)
730
+ return;
675
731
  submit.disabled = true;
676
732
  try {
677
- const result = await app.api("/channeld/plugins", {
733
+ const result = await api("/channeld/plugins", {
678
734
  method: "POST",
679
735
  body: JSON.stringify({ name, source }),
680
736
  });
737
+ if (!isRecord(result))
738
+ return;
681
739
  const plugin = {
682
- pluginId: result.pluginId,
683
- name: result.name,
684
- platform: result.platform,
685
- ...(result.displayName ? { displayName: result.displayName } : {}),
686
- ...(result.account ? { account: result.account } : {}),
740
+ ...result,
741
+ pluginId: String(result.pluginId ?? ""),
742
+ name: String(result.name ?? ""),
743
+ platform: String(result.platform ?? ""),
687
744
  };
688
745
  data.plugins = [...data.plugins.filter((item) => item.pluginId !== plugin.pluginId), plugin];
689
746
  renderPlugins();
@@ -698,18 +755,18 @@ export function initIntegrations(app) {
698
755
  submit.disabled = false;
699
756
  }
700
757
  });
701
- $("#btnAddAccountEnv").addEventListener("click", () => addEnvRow(accountEnv).querySelector(".integration-env-key").focus());
758
+ accountAddEnv.addEventListener("click", () => addEnvRow(accountEnv).querySelector(".integration-env-key")?.focus());
702
759
  accountPlugin.addEventListener("change", syncAccountSchema);
703
760
  accountClear.addEventListener("click", () => setClearEnv(!clearEnv));
704
761
  enabledInput.addEventListener("change", applyEnabledState);
705
- addAccountButton.addEventListener("click", () => openAccount(null));
706
- uploadPluginButton.addEventListener("click", openUpload);
707
- $("#btnRefreshIntegrations").addEventListener("click", () => void load(true));
762
+ addAccountButton?.addEventListener("click", () => openAccount(null));
763
+ uploadPluginButton?.addEventListener("click", openUpload);
764
+ $("#btnRefreshIntegrations")?.addEventListener("click", () => void load(true));
708
765
  saveButton.addEventListener("click", () => void save());
709
- $("#btnCloseIntegrationAccount").addEventListener("click", closeAccount);
710
- $("#btnCancelIntegrationAccount").addEventListener("click", closeAccount);
766
+ $("#btnCloseIntegrationAccount")?.addEventListener("click", closeAccount);
767
+ $("#btnCancelIntegrationAccount")?.addEventListener("click", closeAccount);
711
768
  accountDialog.addEventListener("cancel", (event) => { event.preventDefault(); closeAccount(); });
712
- $("#btnCloseIntegrationPlugin").addEventListener("click", () => pluginDialog.close());
713
- $("#btnCancelIntegrationPlugin").addEventListener("click", () => pluginDialog.close());
769
+ $("#btnCloseIntegrationPlugin")?.addEventListener("click", () => pluginDialog.close());
770
+ $("#btnCancelIntegrationPlugin")?.addEventListener("click", () => pluginDialog.close());
714
771
  pluginDialog.addEventListener("cancel", (event) => { event.preventDefault(); pluginDialog.close(); });
715
772
  }
@@ -1,8 +1,17 @@
1
1
  import { LS } from "./state.js";
2
2
  import { isRoomAdmin } from "./admin-badge.js";
3
+ const isJoinRequest = (value) => typeof value === "object" && value !== null
4
+ && "sessionID" in value && typeof value.sessionID === "string" && value.sessionID.length > 0
5
+ && "name" in value && typeof value.name === "string";
6
+ const statusOf = (error) => error instanceof Error && "status" in error && typeof error.status === "number" ? error.status : 0;
3
7
  // Pending join state is browser-local; the server remains authoritative.
4
8
  export function initJoinRequests(app) {
5
- const $ = app.$;
9
+ const $ = (selector) => {
10
+ const element = app.$(selector);
11
+ if (!element)
12
+ throw new Error(`Missing element: ${selector}`);
13
+ return element;
14
+ };
6
15
  const pendingIds = (app.state.pendingJoinIds ??= new Set());
7
16
  let pending = { roomId: "", name: "", status: "", timer: 0, generation: 0, checking: false, cancelling: false };
8
17
  let requests = [], requestsRoomId = "", requestsGeneration = 0, requestsLoading = false, loadingRoomId = "", deniedRoomId = "";
@@ -105,7 +114,7 @@ export function initJoinRequests(app) {
105
114
  catch (error) {
106
115
  if (generation !== pending.generation)
107
116
  return;
108
- if (error.status === 404) {
117
+ if (statusOf(error) === 404) {
109
118
  pendingIds.delete(roomId);
110
119
  pending.status = "gone";
111
120
  app.setText(title, "joinPendingGoneTitle");
@@ -192,15 +201,13 @@ export function initJoinRequests(app) {
192
201
  if (generation !== requestsGeneration || app.state.room?.id !== roomId)
193
202
  return;
194
203
  requestsRoomId = roomId;
195
- requests = Array.isArray(data.requests)
196
- ? data.requests.filter((request) => request && typeof request.sessionID === "string" && request.sessionID && typeof request.name === "string")
197
- : [];
204
+ requests = Array.isArray(data.requests) ? data.requests.filter(isJoinRequest) : [];
198
205
  renderRequests();
199
206
  }
200
207
  catch (error) {
201
208
  if (generation !== requestsGeneration || app.state.room?.id !== roomId)
202
209
  return;
203
- if (error.status === 403) {
210
+ if (statusOf(error) === 403) {
204
211
  deniedRoomId = roomId;
205
212
  requests = [];
206
213
  renderRequests();
@@ -219,7 +226,7 @@ export function initJoinRequests(app) {
219
226
  const room = app.state.room;
220
227
  const visible = Boolean(room && room.kind !== "direct" && room.joinPolicy === "approval" && isRoomAdmin(app) && deniedRoomId !== room.id);
221
228
  section.hidden = !visible;
222
- if (!visible) {
229
+ if (!room || !visible) {
223
230
  list.textContent = "";
224
231
  requestSignature = "";
225
232
  updateBadge(0);
@@ -309,14 +316,14 @@ export function initJoinRequests(app) {
309
316
  void app.refreshRoomMeta?.();
310
317
  }
311
318
  catch (error) {
312
- if (error.status === 404) {
319
+ if (statusOf(error) === 404) {
313
320
  requests = requests.filter((entry) => entry.sessionID !== request.sessionID);
314
321
  requestSignature = "";
315
322
  app.setText($("#joinRequestsStatus"), "joinRequestAlreadyHandled");
316
323
  renderRequests();
317
324
  focusAfterRequest(index);
318
325
  }
319
- else if (error.status === 403) {
326
+ else if (statusOf(error) === 403) {
320
327
  deniedRoomId = room.id;
321
328
  requests = [];
322
329
  renderRequests();
@@ -325,8 +332,8 @@ export function initJoinRequests(app) {
325
332
  item.removeAttribute("aria-busy");
326
333
  approve.disabled = false;
327
334
  deny.disabled = false;
328
- app.setText($("#joinRequestsStatus"), "joinRequestActionFailed", { message: error.message });
329
- if (error.status === 409)
335
+ app.setText($("#joinRequestsStatus"), "joinRequestActionFailed", { message: error instanceof Error ? error.message : String(error) });
336
+ if (statusOf(error) === 409)
330
337
  void refreshRequests();
331
338
  }
332
339
  }
@@ -365,7 +372,7 @@ export function initJoinRequests(app) {
365
372
  catch (error) {
366
373
  if (generation !== pending.generation)
367
374
  return;
368
- if (error.status === 404) {
375
+ if (statusOf(error) === 404) {
369
376
  pendingIds.delete(roomId);
370
377
  closePending();
371
378
  ($("#joinView").hidden ? $("#msgInput") : $("#inRoomId"))?.focus({ preventScroll: true });
@@ -1,4 +1,3 @@
1
- // Code masking keeps footnote syntax literal inside fences and inline spans.
2
1
  function maskCode(value, nonce) {
3
2
  const blocks = [];
4
3
  const token = () => `CHATCODETOKEN${nonce}${blocks.length}END`;