@michengai/dsh-im-connect 1.0.47 → 1.0.49

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.
package/lib/client.js CHANGED
@@ -474,8 +474,13 @@ function resolveApiUrl(path) {
474
474
  function parseChannelSettingsRequest(value) {
475
475
  if (!value || typeof value !== "object") return undefined;
476
476
  const channelId = typeof value.channelId === "string" ? value.channelId.trim() : "";
477
- if (!channelId) return undefined;
478
- return { channelId, name: typeof value.name === "string" ? value.name : "" };
477
+ const accountId = typeof value.accountId === "string" ? value.accountId.trim() : "";
478
+ if (!channelId && !accountId) return undefined;
479
+ return {
480
+ channelId,
481
+ accountId: accountId || undefined,
482
+ name: typeof value.name === "string" ? value.name : "",
483
+ };
479
484
  }
480
485
  function writeChannelSettingsRequest(storage, request) {
481
486
  try { storage && storage.setItem(CHANNEL_SETTINGS_STORAGE_KEY, JSON.stringify(request)); } catch { /* ignore */ }
@@ -498,10 +503,20 @@ function resolveApiUrl(path) {
498
503
  function resolveChannelSettingsTarget(request, channels) {
499
504
  const parsed = parseChannelSettingsRequest(request);
500
505
  if (!parsed || !Array.isArray(channels)) return undefined;
501
- const channel = channels.find((item) => item && item.id === parsed.channelId);
506
+ if (parsed.accountId) {
507
+ for (const channel of channels) {
508
+ const account = (channel.accounts || []).find((a) => a && a.id === parsed.accountId);
509
+ if (account) return { channelId: channel.id, accountId: account.id };
510
+ }
511
+ }
512
+ const channel = channels.find((item) => item && (item.id === parsed.channelId || (item.accounts || []).some((a) => a && a.id === parsed.channelId)));
502
513
  if (!channel) return undefined;
503
514
  const accounts = channel.accounts || [];
504
- return { channelId: channel.id, accountId: accounts.length === 1 ? accounts[0].id : undefined };
515
+ const matchedAccount = accounts.find((a) => a && (a.id === parsed.accountId || a.id === parsed.channelId));
516
+ return {
517
+ channelId: channel.id,
518
+ accountId: matchedAccount ? matchedAccount.id : (accounts.length === 1 ? accounts[0].id : undefined),
519
+ };
505
520
  }
506
521
  function pickSettingsSectionButton(buttons, labels) {
507
522
  const normalize = (value) => String(value || "").replace(/\s+/g, "").trim().toLowerCase();
@@ -655,6 +670,9 @@ function resolveApiUrl(path) {
655
670
  "account.proxyNote": "仅影响当前账号;保存后自动重连生效。",
656
671
  "account.proxySaved": "代理地址已保存;留空保存可保留当前地址。",
657
672
  "account.proxyUrl": "代理地址",
673
+ "account.wecomWsUrl": "WebSocket URL",
674
+ "account.wecomWsUrlNote": "私有化部署时填写自定义长连接地址,留空使用官方默认地址;保存后自动重连生效。",
675
+ "account.wecomWsUrlPlaceholder": "默认 wss://openws.work.weixin.qq.com",
658
676
  "account.receive": "接收消息",
659
677
  "account.receiveDescription": "关闭后保留账号配置,但不接收新消息",
660
678
  "account.remark": "名称备注",
@@ -825,6 +843,8 @@ function resolveApiUrl(path) {
825
843
  "field.telegram.token": "Bot Token",
826
844
  "field.wecom.botId": "Bot ID",
827
845
  "field.wecom.secret": "Secret",
846
+ "field.wecom.wsUrl": "WebSocket URL",
847
+ "field.wecom.wsUrl.placeholder": "默认 wss://openws.work.weixin.qq.com",
828
848
  "hover.copied": "已复制",
829
849
  "loading": "加载中…",
830
850
  "pending.notice": "有访问请求。批准后该用户才能驱动本机助手。",
@@ -961,6 +981,9 @@ function resolveApiUrl(path) {
961
981
  "account.proxyNote": "Affects only this account. The channel reconnects automatically after saving.",
962
982
  "account.proxySaved": "A proxy address is saved. Leave the field blank to keep it.",
963
983
  "account.proxyUrl": "Proxy address",
984
+ "account.wecomWsUrl": "WebSocket URL",
985
+ "account.wecomWsUrlNote": "Enter a custom WebSocket URL for on-premise deployments, or leave blank for the official default; reconnects automatically after saving.",
986
+ "account.wecomWsUrlPlaceholder": "Default: wss://openws.work.weixin.qq.com",
964
987
  "account.receive": "Receive messages",
965
988
  "account.receiveDescription": "Turn this off to keep the account settings without receiving new messages",
966
989
  "account.remark": "Name remark",
@@ -1131,6 +1154,8 @@ function resolveApiUrl(path) {
1131
1154
  "field.telegram.token": "Bot Token",
1132
1155
  "field.wecom.botId": "Bot ID",
1133
1156
  "field.wecom.secret": "Secret",
1157
+ "field.wecom.wsUrl": "WebSocket URL",
1158
+ "field.wecom.wsUrl.placeholder": "Default: wss://openws.work.weixin.qq.com",
1134
1159
  "hover.copied": "Copied",
1135
1160
  "loading": "Loading…",
1136
1161
  "pending.notice": "There are access requests. Approve a user before they can control the local assistant.",
@@ -1267,6 +1292,9 @@ function resolveApiUrl(path) {
1267
1292
  "account.proxyNote": "現在のアカウントにのみ影響します。保存後に自動再接続して反映されます。",
1268
1293
  "account.proxySaved": "プロキシアドレスは保存されています。空のまま保存すると現在のアドレスが維持されます。",
1269
1294
  "account.proxyUrl": "プロキシアドレス",
1295
+ "account.wecomWsUrl": "WebSocket URL",
1296
+ "account.wecomWsUrlNote": "オンプレミス展開の場合はカスタム WebSocket URL を入力し、公式デフォルトを使用する場合は空欄にします。保存後に自動再接続されます。",
1297
+ "account.wecomWsUrlPlaceholder": "デフォルト wss://openws.work.weixin.qq.com",
1270
1298
  "account.receive": "メッセージを受信",
1271
1299
  "account.receiveDescription": "無効にするとアカウント設定を維持したまま新規メッセージを受信しません",
1272
1300
  "account.remark": "名称備考",
@@ -1437,6 +1465,8 @@ function resolveApiUrl(path) {
1437
1465
  "field.telegram.token": "Bot Token",
1438
1466
  "field.wecom.botId": "Bot ID",
1439
1467
  "field.wecom.secret": "Secret",
1468
+ "field.wecom.wsUrl": "WebSocket URL",
1469
+ "field.wecom.wsUrl.placeholder": "デフォルト wss://openws.work.weixin.qq.com",
1440
1470
  "hover.copied": "コピー完了",
1441
1471
  "loading": "読み込み中…",
1442
1472
  "pending.notice": "アクセスリクエストがあります。承認されたユーザーのみがローカルアシスタントを操作できます。",
@@ -1573,6 +1603,9 @@ function resolveApiUrl(path) {
1573
1603
  "account.proxyNote": "Afecta solo a esta cuenta. El canal se reconecta automáticamente al guardar.",
1574
1604
  "account.proxySaved": "Se ha guardado una dirección de proxy. Deje el campo en blanco para conservarla.",
1575
1605
  "account.proxyUrl": "Dirección del proxy",
1606
+ "account.wecomWsUrl": "WebSocket URL",
1607
+ "account.wecomWsUrlNote": "Ingrese una URL de WebSocket personalizada para implementaciones locales o déjela en blanco para el valor predeterminado oficial; se reconecta automáticamente al guardar.",
1608
+ "account.wecomWsUrlPlaceholder": "Predeterminado: wss://openws.work.weixin.qq.com",
1576
1609
  "account.receive": "Recibir mensajes",
1577
1610
  "account.receiveDescription": "Desactive esto para conservar la configuración de la cuenta sin recibir nuevos mensajes",
1578
1611
  "account.remark": "Observación del nombre",
@@ -1743,6 +1776,8 @@ function resolveApiUrl(path) {
1743
1776
  "field.telegram.token": "Bot Token",
1744
1777
  "field.wecom.botId": "Bot ID",
1745
1778
  "field.wecom.secret": "Secret",
1779
+ "field.wecom.wsUrl": "WebSocket URL",
1780
+ "field.wecom.wsUrl.placeholder": "Predeterminado: wss://openws.work.weixin.qq.com",
1746
1781
  "hover.copied": "Copiado",
1747
1782
  "loading": "Cargando…",
1748
1783
  "pending.notice": "Hay solicitudes de acceso. Apruebe a un usuario para que pueda controlar el asistente local.",
@@ -1879,6 +1914,9 @@ function resolveApiUrl(path) {
1879
1914
  "account.proxyNote": "Ne concerne que ce compte. Le canal se reconnecte automatiquement après enregistrement.",
1880
1915
  "account.proxySaved": "Une adresse de proxy est enregistrée. Laissez vide pour la conserver.",
1881
1916
  "account.proxyUrl": "Adresse du proxy",
1917
+ "account.wecomWsUrl": "WebSocket URL",
1918
+ "account.wecomWsUrlNote": "Saisissez une URL WebSocket personnalisée pour les déploiements sur site, ou laissez vide pour la valeur par défaut officielle ; se reconnecte automatiquement après enregistrement.",
1919
+ "account.wecomWsUrlPlaceholder": "Par défaut : wss://openws.work.weixin.qq.com",
1882
1920
  "account.receive": "Recevoir des messages",
1883
1921
  "account.receiveDescription": "Désactivez cette option pour conserver les paramètres sans recevoir de nouveaux messages",
1884
1922
  "account.remark": "Remarque sur le nom",
@@ -2049,6 +2087,8 @@ function resolveApiUrl(path) {
2049
2087
  "field.telegram.token": "Bot Token",
2050
2088
  "field.wecom.botId": "Bot ID",
2051
2089
  "field.wecom.secret": "Secret",
2090
+ "field.wecom.wsUrl": "WebSocket URL",
2091
+ "field.wecom.wsUrl.placeholder": "Par défaut : wss://openws.work.weixin.qq.com",
2052
2092
  "hover.copied": "Copié",
2053
2093
  "loading": "Chargement…",
2054
2094
  "pending.notice": "Demandes d'accès en attente. Approuvez un utilisateur pour lui permettre de piloter l'assistant local.",
@@ -2185,6 +2225,9 @@ function resolveApiUrl(path) {
2185
2225
  "account.proxyNote": "Betrifft nur dieses Konto. Der Kanal verbindet sich nach dem Speichern automatisch neu.",
2186
2226
  "account.proxySaved": "Eine Proxy-Adresse ist gespeichert. Feld leer lassen, um sie beizubehalten.",
2187
2227
  "account.proxyUrl": "Proxy-Adresse",
2228
+ "account.wecomWsUrl": "WebSocket URL",
2229
+ "account.wecomWsUrlNote": "Geben Sie eine benutzerdefinierte WebSocket-URL für On-Premise-Bereitstellungen ein oder lassen Sie das Feld leer für den offiziellen Standard; verbindet sich nach dem Speichern automatisch neu.",
2230
+ "account.wecomWsUrlPlaceholder": "Standard: wss://openws.work.weixin.qq.com",
2188
2231
  "account.receive": "Nachrichten empfangen",
2189
2232
  "account.receiveDescription": "Ausschalten, um Kontoeinstellungen zu behalten, ohne neue Nachrichten zu empfangen",
2190
2233
  "account.remark": "Namensnotiz",
@@ -2355,6 +2398,8 @@ function resolveApiUrl(path) {
2355
2398
  "field.telegram.token": "Bot Token",
2356
2399
  "field.wecom.botId": "Bot ID",
2357
2400
  "field.wecom.secret": "Secret",
2401
+ "field.wecom.wsUrl": "WebSocket URL",
2402
+ "field.wecom.wsUrl.placeholder": "Standard: wss://openws.work.weixin.qq.com",
2358
2403
  "hover.copied": "Kopiert",
2359
2404
  "loading": "Wird geladen…",
2360
2405
  "pending.notice": "Es liegen Zugriffsanfragen vor. Genehmigen Sie Benutzer, damit sie den lokalen Assistenten steuern können.",
@@ -2491,6 +2536,9 @@ function resolveApiUrl(path) {
2491
2536
  "account.proxyNote": "Влияет только на этот аккаунт. Канал автоматически переподключается после сохранения.",
2492
2537
  "account.proxySaved": "Адрес прокси сохранен. Оставьте поле пустым, чтобы сохранить его.",
2493
2538
  "account.proxyUrl": "Адрес прокси",
2539
+ "account.wecomWsUrl": "WebSocket URL",
2540
+ "account.wecomWsUrlNote": "Укажите пользовательский URL WebSocket для локального развертывания или оставьте пустым для официального адреса по умолчанию; переподключается автоматически после сохранения.",
2541
+ "account.wecomWsUrlPlaceholder": "По умолчанию: wss://openws.work.weixin.qq.com",
2494
2542
  "account.receive": "Прием сообщений",
2495
2543
  "account.receiveDescription": "Отключите, чтобы сохранить настройки аккаунта без приема новых сообщений",
2496
2544
  "account.remark": "Примечание к имени",
@@ -2661,6 +2709,8 @@ function resolveApiUrl(path) {
2661
2709
  "field.telegram.token": "Bot Token",
2662
2710
  "field.wecom.botId": "Bot ID",
2663
2711
  "field.wecom.secret": "Secret",
2712
+ "field.wecom.wsUrl": "WebSocket URL",
2713
+ "field.wecom.wsUrl.placeholder": "По умолчанию: wss://openws.work.weixin.qq.com",
2664
2714
  "hover.copied": "Скопировано",
2665
2715
  "loading": "Загрузка…",
2666
2716
  "pending.notice": "Есть запросы на доступ. Одобрите пользователя, чтобы он мог взаимодействовать с локальным ассистентом.",
@@ -2797,6 +2847,9 @@ function resolveApiUrl(path) {
2797
2847
  "account.proxyNote": "Afeta apenas esta conta. O canal reconecta automaticamente após salvar.",
2798
2848
  "account.proxySaved": "Um endereço de proxy foi salvo. Deixe em branco para mantê-lo.",
2799
2849
  "account.proxyUrl": "Endereço do proxy",
2850
+ "account.wecomWsUrl": "WebSocket URL",
2851
+ "account.wecomWsUrlNote": "Insira uma URL WebSocket personalizada para implantações locais ou deixe em branco para o padrão oficial; reconecta automaticamente após salvar.",
2852
+ "account.wecomWsUrlPlaceholder": "Padrão: wss://openws.work.weixin.qq.com",
2800
2853
  "account.receive": "Receber mensagens",
2801
2854
  "account.receiveDescription": "Desative para manter as configurações da conta sem receber novas mensagens",
2802
2855
  "account.remark": "Observação do nome",
@@ -2967,6 +3020,8 @@ function resolveApiUrl(path) {
2967
3020
  "field.telegram.token": "Bot Token",
2968
3021
  "field.wecom.botId": "Bot ID",
2969
3022
  "field.wecom.secret": "Secret",
3023
+ "field.wecom.wsUrl": "WebSocket URL",
3024
+ "field.wecom.wsUrl.placeholder": "Padrão: wss://openws.work.weixin.qq.com",
2970
3025
  "hover.copied": "Copiado",
2971
3026
  "loading": "Carregando…",
2972
3027
  "pending.notice": "Existem solicitações de acesso. Aprove um usuário para permitir que ele controle o assistente local.",
@@ -3303,15 +3358,33 @@ body:not([data-ds-dark-theme]) .ima-section-card{background:var(--dsw-alias-bg-l
3303
3358
  let requestHostSessionRefresh = () => {};
3304
3359
  let channelSessionIds = new Set();
3305
3360
  let channelSessionChannels = new Map();
3361
+ let channelSessionAccounts = new Map();
3362
+ let channelAccountMeta = new Map();
3306
3363
  let channelMembershipRevision = 0;
3307
3364
  const channelMembershipListeners = new Set();
3365
+ function parsePlatformFromChannelId(id) {
3366
+ const val = String(id || "");
3367
+ const split = val.indexOf("_");
3368
+ return split > 0 ? val.slice(0, split) : val;
3369
+ }
3308
3370
  function updateChannelMembership(groups) {
3309
3371
  const next = new Set();
3310
3372
  const channels = new Map();
3311
- for (const group of groups) {
3373
+ const accounts = new Map();
3374
+ const meta = new Map();
3375
+ for (const group of groups || []) {
3376
+ const platform = group.platform || parsePlatformFromChannelId(group.id);
3377
+ const accountId = group.accountId || group.id;
3378
+ meta.set(accountId, {
3379
+ id: accountId,
3380
+ accountId,
3381
+ platform,
3382
+ label: group.label || "",
3383
+ });
3312
3384
  for (const session of group.sessions || []) {
3313
3385
  next.add(session.sessionId);
3314
- channels.set(String(session.sessionId), group.id);
3386
+ channels.set(String(session.sessionId), platform);
3387
+ accounts.set(String(session.sessionId), accountId);
3315
3388
  }
3316
3389
  }
3317
3390
  let changed = next.size !== channelSessionIds.size || [...next].some(id => !channelSessionIds.has(id));
@@ -3320,15 +3393,35 @@ body:not([data-ds-dark-theme]) .ima-section-card{background:var(--dsw-alias-bg-l
3320
3393
  if (channelSessionChannels.get(id) !== channel) { changed = true; break; }
3321
3394
  }
3322
3395
  }
3396
+ if (!changed) {
3397
+ for (const [id, account] of accounts) {
3398
+ if (channelSessionAccounts.get(id) !== account) { changed = true; break; }
3399
+ }
3400
+ }
3401
+ if (!changed) {
3402
+ if (meta.size !== channelAccountMeta.size) {
3403
+ changed = true;
3404
+ } else {
3405
+ for (const [id, item] of meta) {
3406
+ const prev = channelAccountMeta.get(id);
3407
+ if (!prev || prev.label !== item.label || prev.platform !== item.platform) {
3408
+ changed = true;
3409
+ break;
3410
+ }
3411
+ }
3412
+ }
3413
+ }
3323
3414
  if (changed) {
3324
3415
  channelSessionIds = next;
3325
3416
  channelSessionChannels = channels;
3417
+ channelSessionAccounts = accounts;
3418
+ channelAccountMeta = meta;
3326
3419
  channelMembershipRevision += 1;
3327
3420
  for (const listener of channelMembershipListeners) listener();
3328
3421
  }
3329
3422
  try { requestHostSessionRefresh(changed); } catch { /* 下次频道轮询继续重试 */ }
3330
3423
  }
3331
- /** IM 会话 ID 包含账号实例;接口映射兼容沿用普通 ID 的已接入会话。 */
3424
+ /** IM 会话 ID 所属渠道平台(如 weixin/feishu),供会话行图标展示。 */
3332
3425
  function channelIdOfSession(sessionId) {
3333
3426
  const value = String(sessionId || "");
3334
3427
  const mapped = channelSessionChannels.get(value);
@@ -3341,6 +3434,17 @@ body:not([data-ds-dark-theme]) .ima-section-card{background:var(--dsw-alias-bg-l
3341
3434
  const platform = instance.split("_", 1)[0];
3342
3435
  return platform || undefined;
3343
3436
  }
3437
+ /** IM 会话 ID 所属具体账号实例(如 feishu_1)。 */
3438
+ function accountIdOfSession(sessionId) {
3439
+ const value = String(sessionId || "");
3440
+ const mapped = channelSessionAccounts.get(value);
3441
+ if (mapped) return mapped;
3442
+ if (!value.startsWith("im:")) return channelSessionChannels.get(value);
3443
+ const rest = value.slice(3);
3444
+ const split = rest.indexOf(":");
3445
+ const instance = split > 0 ? rest.slice(0, split) : rest;
3446
+ return instance || undefined;
3447
+ }
3344
3448
  // 新旧两代 IM 前缀都要认,否则存量会话升级后会掉出渠道页签。
3345
3449
  const isChannelSession = (id) => {
3346
3450
  const value = String(id);
@@ -3607,6 +3711,12 @@ body:not([data-ds-dark-theme]) .ima-section-card{background:var(--dsw-alias-bg-l
3607
3711
  const translated = t(key);
3608
3712
  return translated === key ? field.label : translated;
3609
3713
  }
3714
+ function fieldPlaceholder(ch, field, t) {
3715
+ const key = "field." + ch.id + "." + field.key + ".placeholder";
3716
+ const translated = t(key);
3717
+ if (translated !== key) return translated;
3718
+ return field.placeholder || fieldLabel(ch, field, t);
3719
+ }
3610
3720
  function hintOf(ch, t) {
3611
3721
  const key = "qr." + ch.id;
3612
3722
  const translated = t(key);
@@ -4061,7 +4171,7 @@ body:not([data-ds-dark-theme]) .ima-section-card{background:var(--dsw-alias-bg-l
4061
4171
  h(Input, {
4062
4172
  type: f.secret ? "password" : "text",
4063
4173
  value: draft[f.key] || "",
4064
- placeholder: fieldLabel(ch, f, t),
4174
+ placeholder: fieldPlaceholder(ch, f, t),
4065
4175
  onChange: (e) => setDraft({ ...draft, [f.key]: e.target.value }),
4066
4176
  }),
4067
4177
  )),
@@ -4142,6 +4252,11 @@ body:not([data-ds-dark-theme]) .ima-section-card{background:var(--dsw-alias-bg-l
4142
4252
  result.threadSessions = patch.threadSessions;
4143
4253
  }
4144
4254
  }
4255
+ if (platform === "wecom") {
4256
+ if (Object.prototype.hasOwnProperty.call(patch, "wsUrl")) {
4257
+ result.wsUrl = patch.wsUrl;
4258
+ }
4259
+ }
4145
4260
  return result;
4146
4261
  }
4147
4262
 
@@ -4641,6 +4756,7 @@ body:not([data-ds-dark-theme]) .ima-section-card{background:var(--dsw-alias-bg-l
4641
4756
  const [draft, setDraft] = useState(account);
4642
4757
  const [proxyModeDraft, setProxyModeDraft] = useState(account.proxyMode || "inherit");
4643
4758
  const [proxyUrlDraft, setProxyUrlDraft] = useState(account.proxyUrl || "");
4759
+ const [wsUrlDraft, setWsUrlDraft] = useState(account.wsUrl || "");
4644
4760
  const [mentionPolicyDraft, setMentionPolicyDraft] = useState(
4645
4761
  account.mentionPolicy === "always" ? "always" : (account.freeChatGroups ? "custom" : "addressed")
4646
4762
  );
@@ -4697,6 +4813,9 @@ body:not([data-ds-dark-theme]) .ima-section-card{background:var(--dsw-alias-bg-l
4697
4813
  useEffect(() => {
4698
4814
  setProxyUrlDraft(account.proxyUrl || "");
4699
4815
  }, [account.id, account.proxyUrl]);
4816
+ useEffect(() => {
4817
+ setWsUrlDraft(account.wsUrl || "");
4818
+ }, [account.id, account.wsUrl]);
4700
4819
  const save = (patch) => {
4701
4820
  const seq = ++saveSeq.current;
4702
4821
  const next = { ...draft, ...patch };
@@ -4745,6 +4864,11 @@ body:not([data-ds-dark-theme]) .ima-section-card{background:var(--dsw-alias-bg-l
4745
4864
  res.threadSessions = patch.threadSessions;
4746
4865
  }
4747
4866
  }
4867
+ if (platform === "wecom") {
4868
+ if (Object.prototype.hasOwnProperty.call(patch, "wsUrl")) {
4869
+ res.wsUrl = patch.wsUrl;
4870
+ }
4871
+ }
4748
4872
  return res;
4749
4873
  };
4750
4874
  filterPayload(account.platform, patch, payload);
@@ -4888,6 +5012,32 @@ body:not([data-ds-dark-theme]) .ima-section-card{background:var(--dsw-alias-bg-l
4888
5012
  })(),
4889
5013
  h("div", { className: "ima-picker-note" }, t("account.telegramGroupPolicyNote")),
4890
5014
  ),
5015
+ account.platform === "wecom" && h("div", { className: "ima-wecom-settings" },
5016
+ h("label", { className: "ima-picker-field wide" },
5017
+ h("span", { className: "ima-picker-label" }, t("account.wecomWsUrl")),
5018
+ h(Input, {
5019
+ type: "text",
5020
+ value: wsUrlDraft,
5021
+ placeholder: t("account.wecomWsUrlPlaceholder"),
5022
+ "aria-label": t("account.wecomWsUrl"),
5023
+ onChange: (event) => setWsUrlDraft(event.target.value),
5024
+ onBlur: (event) => {
5025
+ const value = event.target.value.trim();
5026
+ if (value === (account.wsUrl || "")) return;
5027
+ save({ wsUrl: value }).then((ok) => {
5028
+ if (ok && !value) setWsUrlDraft("");
5029
+ });
5030
+ },
5031
+ onKeyDown: (event) => {
5032
+ if (event.key === "Enter") {
5033
+ event.preventDefault();
5034
+ event.currentTarget.blur();
5035
+ }
5036
+ },
5037
+ }),
5038
+ ),
5039
+ h("div", { className: "ima-picker-note" }, t("account.wecomWsUrlNote")),
5040
+ ),
4891
5041
  h(CommandPermissionSettings, { value: draft.commandPermissions, onSave: commandPermissions => save({ commandPermissions }), t }),
4892
5042
  note && h("div", { className: note === "status.saved" ? "ima-save-note ok" : "ima-save-note" }, t(note)),
4893
5043
  h("div", { className: "ima-inspector-actions" },
@@ -5229,7 +5379,6 @@ body:not([data-ds-dark-theme]) .ima-section-card{background:var(--dsw-alias-bg-l
5229
5379
  // ---------------------------------------------------------------------
5230
5380
 
5231
5381
  const CHANNEL_WORKSPACE_PREFIX = "dsh-im-channel:";
5232
- const CHANNEL_GROUP_IDS = ["weixin", "wecom", "qq", "feishu", "lark", "dingtalk", "telegram", "discord", "slack"];
5233
5382
  const EMPTY_SESSION_STATE = { ids: [], byId: {}, current: null };
5234
5383
  const EMPTY_WORKSPACE_STATE = { items: [], archivedSessionIds: [], pinnedSessionIds: [], state: "idle", phase: "ready", error: null };
5235
5384
  const CHANNEL_GROUP_OPTION_ATTR = "data-ima-channel-group-option";
@@ -5357,16 +5506,34 @@ body:not([data-ds-dark-theme]) .ima-section-card{background:var(--dsw-alias-bg-l
5357
5506
  }
5358
5507
 
5359
5508
  function channelGroupsFromSessionState(state, t) {
5360
- const groups = new Map(CHANNEL_GROUP_IDS.map((id) => [id, {
5361
- id,
5362
- label: channelLabel({ id }, t),
5363
- sessions: [],
5364
- }]));
5509
+ const groups = new Map();
5510
+ const metaMap = channelAccountMeta;
5511
+ for (const [accountId, meta] of metaMap) {
5512
+ groups.set(accountId, {
5513
+ id: accountId,
5514
+ platform: meta.platform,
5515
+ label: meta.label || channelLabel({ id: meta.platform }, t),
5516
+ sessions: [],
5517
+ });
5518
+ }
5365
5519
  const src = state || EMPTY_SESSION_STATE;
5366
5520
  for (const id of src.ids || []) {
5367
- const group = groups.get(channelIdOfSession(id));
5521
+ const platform = channelIdOfSession(id);
5522
+ if (!platform) continue;
5523
+ const accountId = accountIdOfSession(id) || platform;
5524
+ let group = groups.get(accountId);
5525
+ if (!group) {
5526
+ const meta = metaMap.get(accountId);
5527
+ group = {
5528
+ id: accountId,
5529
+ platform,
5530
+ label: (meta && meta.label) || channelLabel({ id: platform }, t),
5531
+ sessions: [],
5532
+ };
5533
+ groups.set(accountId, group);
5534
+ }
5368
5535
  const session = src.byId && src.byId[id];
5369
- if (group && session) group.sessions.push({ sessionId: id, updatedAt: session.updatedAt });
5536
+ if (session) group.sessions.push({ sessionId: id, updatedAt: session.updatedAt });
5370
5537
  }
5371
5538
  return [...groups.values()].filter((group) => group.sessions.length > 0);
5372
5539
  }
@@ -5388,7 +5555,7 @@ body:not([data-ds-dark-theme]) .ima-section-card{background:var(--dsw-alias-bg-l
5388
5555
  const src = state || EMPTY_WORKSPACE_STATE;
5389
5556
  const key = groups.map((group) => [
5390
5557
  group.id,
5391
- channelLabel(group, t),
5558
+ group.label || channelLabel(group, t),
5392
5559
  channelGroupCreatedAt(group),
5393
5560
  (group.sessions || []).map((session) => session.sessionId).join(","),
5394
5561
  ].join("\0")).join("\0\0");
@@ -5399,7 +5566,7 @@ body:not([data-ds-dark-theme]) .ima-section-card{background:var(--dsw-alias-bg-l
5399
5566
  return {
5400
5567
  workspaceId,
5401
5568
  id: workspaceId,
5402
- title: channelLabel(group, t),
5569
+ title: group.label || channelLabel(group, t),
5403
5570
  path: "",
5404
5571
  sessionIds: (group.sessions || []).map((session) => session.sessionId),
5405
5572
  createdAt: channelGroupCreatedAt(group),
@@ -5426,8 +5593,6 @@ body:not([data-ds-dark-theme]) .ima-section-card{background:var(--dsw-alias-bg-l
5426
5593
  return result;
5427
5594
  }
5428
5595
 
5429
- let channelIconCssValue;
5430
-
5431
5596
  /** 把 React 元素渲染成可直接注入官方 DOM 的 HTML。 */
5432
5597
  function channelMarkup(element) {
5433
5598
  if (typeof document === "undefined") return "";
@@ -5454,7 +5619,7 @@ body:not([data-ds-dark-theme]) .ima-section-card{background:var(--dsw-alias-bg-l
5454
5619
  }
5455
5620
 
5456
5621
  const channelLogoUrlCache = new Map();
5457
- /** 频道品牌标 data URL,供分组头和会话行复用。 */
5622
+ /** 频道品牌标 data URL,供工作区图标和会话行复用。 */
5458
5623
  function channelLogoUrl(id) {
5459
5624
  if (channelLogoUrlCache.has(id)) return channelLogoUrlCache.get(id);
5460
5625
  const markup = channelMarkup(h(BrandMark, { id, compact: true }));
@@ -5463,26 +5628,6 @@ body:not([data-ds-dark-theme]) .ima-section-card{background:var(--dsw-alias-bg-l
5463
5628
  return url;
5464
5629
  }
5465
5630
 
5466
- /** 频道分组头图标:用品牌标覆盖官方文件夹图标,并保持悬停时可见。 */
5467
- function channelIconCss() {
5468
- if (channelIconCssValue !== undefined) return channelIconCssValue;
5469
- if (typeof document === "undefined") {
5470
- channelIconCssValue = "";
5471
- return channelIconCssValue;
5472
- }
5473
- channelIconCssValue = CHANNEL_GROUP_IDS.map((id) => {
5474
- const logo = channelLogoUrl(id);
5475
- if (!logo) return "";
5476
- const row = `[data-row-key="workspace:${channelWorkspaceId(id)}"]`;
5477
- return `.ima-channel-official ${row}>span:first-child>svg{display:none!important}`
5478
- + `.ima-channel-official ${row}>span:first-child{display:inline-flex!important;background:${logo} center/contain no-repeat!important}`
5479
- // 宿主在悬停时用 chevron 换掉文件夹;频道分组保持品牌图标可见。
5480
- + `.ima-channel-official ${row}:hover>span:first-child{display:inline-flex!important}`
5481
- + `.ima-channel-official ${row}:hover>span:nth-child(2){display:none!important}`;
5482
- }).join("");
5483
- return channelIconCssValue;
5484
- }
5485
-
5486
5631
  let channelWorkspaceIconCache = { key: "", css: "" };
5487
5632
  /**
5488
5633
  * 按工作区/工作区树分组时,如果某个工作区的频道会话都来自同一个频道,
@@ -5519,6 +5664,55 @@ body:not([data-ds-dark-theme]) .ima-section-card{background:var(--dsw-alias-bg-l
5519
5664
  return css;
5520
5665
  }
5521
5666
 
5667
+ /**
5668
+ * 替换菜单项内的图标与文案,兼容各种带有嵌套包装、CSS Module 类名或纯结构节点的宿主 DOM。
5669
+ */
5670
+ function replaceMenuItemContent(button, templateText, label, icon) {
5671
+ const ownerDoc = button.ownerDocument || (typeof document !== "undefined" ? document : null);
5672
+ let iconContainer = button.querySelector('[class*="itemIcon"], [class*="Icon"]');
5673
+ if (!iconContainer && button.firstElementChild) {
5674
+ const first = button.firstElementChild;
5675
+ const isSvg = first.tagName && first.tagName.toLowerCase() === "svg";
5676
+ const isImg = first.tagName && first.tagName.toLowerCase() === "img";
5677
+ if (isSvg || isImg || button.children.length > 1) {
5678
+ iconContainer = first;
5679
+ }
5680
+ }
5681
+ const isInsideIcon = (el) => iconContainer && typeof iconContainer.contains === "function" && iconContainer.contains(el);
5682
+ const labelContainer = button.querySelector('[class*="itemLabel"], [class*="Label"]')
5683
+ || [...button.querySelectorAll("span, div")].find((el) => el !== iconContainer && !isInsideIcon(el) && (el.textContent || "").trim() === templateText)
5684
+ || (button.children.length > 1 ? button.children[1] : null)
5685
+ || (button.lastElementChild !== iconContainer ? button.lastElementChild : null);
5686
+
5687
+ if (icon !== undefined) {
5688
+ if (!iconContainer && ownerDoc && typeof ownerDoc.createElement === "function") {
5689
+ iconContainer = ownerDoc.createElement("span");
5690
+ if (typeof iconContainer.setAttribute === "function") {
5691
+ iconContainer.setAttribute("class", "ima-menu-item-icon");
5692
+ iconContainer.setAttribute("aria-hidden", "true");
5693
+ }
5694
+ button.insertBefore(iconContainer, button.firstChild);
5695
+ }
5696
+ if (iconContainer) {
5697
+ iconContainer.innerHTML = icon;
5698
+ }
5699
+ }
5700
+ if (labelContainer && labelContainer !== iconContainer) {
5701
+ labelContainer.textContent = label;
5702
+ } else {
5703
+ const remaining = [...button.children].filter((el) => el !== iconContainer);
5704
+ if (remaining.length >= 1) {
5705
+ remaining[0].textContent = label;
5706
+ } else if (ownerDoc && typeof ownerDoc.createElement === "function") {
5707
+ const textNode = ownerDoc.createElement("span");
5708
+ textNode.textContent = label;
5709
+ button.appendChild(textNode);
5710
+ } else {
5711
+ button.textContent = label;
5712
+ }
5713
+ }
5714
+ }
5715
+
5522
5716
  /**
5523
5717
  * 官方视图选项菜单没有扩展位,注入第四个分组项「按频道」。
5524
5718
  * 只在频道页签挂载期间生效。
@@ -5545,11 +5739,11 @@ body:not([data-ds-dark-theme]) .ima-section-card{background:var(--dsw-alias-bg-l
5545
5739
  button.removeAttribute("disabled");
5546
5740
  button.disabled = false;
5547
5741
  button.classList.remove("danger");
5548
- for (const svg of button.querySelectorAll(":scope > svg")) svg.remove();
5549
- const spans = button.querySelectorAll("span");
5550
- if (spans[0] !== undefined) spans[0].innerHTML = channelMarkup(h(IconQueueOutline, { size: 16 }));
5551
- if (spans[1] !== undefined) spans[1].textContent = options.label;
5552
- else button.textContent = options.label;
5742
+ for (const child of [...button.children]) {
5743
+ if (child.tagName && child.tagName.toLowerCase() === "svg") child.remove();
5744
+ }
5745
+ for (const check of button.querySelectorAll('[class*="check"], svg[class*="check"]')) check.remove();
5746
+ replaceMenuItemContent(button, (first.textContent || "").trim(), options.label, channelMarkup(h(IconQueueOutline, { size: 16 })));
5553
5747
  if (options.checked) {
5554
5748
  const check = document.createElement("span");
5555
5749
  check.innerHTML = channelMarkup(h(IconCheckOutline, { size: 16 }));
@@ -5606,23 +5800,53 @@ body:not([data-ds-dark-theme]) .ima-section-card{background:var(--dsw-alias-bg-l
5606
5800
  }
5607
5801
  if (target.closest('[role="menu"]') === null) channelId = undefined;
5608
5802
  };
5609
- const hiddenItems = new Map();
5803
+ const hiddenElements = new Map();
5804
+ const hideElement = (el) => {
5805
+ if (!el || typeof el.getAttribute !== "function") return;
5806
+ if (!hiddenElements.has(el)) {
5807
+ hiddenElements.set(el, {
5808
+ display: el.style.display || "",
5809
+ ariaHidden: el.getAttribute("aria-hidden"),
5810
+ });
5811
+ }
5812
+ el.style.display = "none";
5813
+ el.setAttribute("aria-hidden", "true");
5814
+ };
5815
+ const purgeDetached = () => {
5816
+ for (const el of hiddenElements.keys()) {
5817
+ if (typeof document.contains === "function" && !document.contains(el)) {
5818
+ hiddenElements.delete(el);
5819
+ }
5820
+ }
5821
+ };
5610
5822
  const hideOthers = (menu, ours) => {
5823
+ purgeDetached();
5611
5824
  for (const item of menu.querySelectorAll('button[role="menuitem"]')) {
5612
5825
  if (ours.has(item)) continue;
5613
- if (!hiddenItems.has(item)) {
5614
- hiddenItems.set(item, {
5615
- display: item.style.display,
5616
- ariaHidden: item.getAttribute("aria-hidden"),
5617
- });
5826
+ hideElement(item);
5827
+ const wrapper = item.parentElement;
5828
+ if (wrapper && wrapper !== menu && wrapper.parentElement === menu) {
5829
+ let containsOurs = false;
5830
+ for (const o of ours) {
5831
+ if (typeof wrapper.contains === "function" && wrapper.contains(o)) {
5832
+ containsOurs = true;
5833
+ break;
5834
+ }
5835
+ }
5836
+ if (!containsOurs) hideElement(wrapper);
5618
5837
  }
5619
- item.style.display = "none";
5620
- item.setAttribute("aria-hidden", "true");
5838
+ }
5839
+ for (const sep of menu.querySelectorAll('[role="separator"], hr, [class*="separator"], [class*="divider"]')) {
5840
+ hideElement(sep);
5621
5841
  }
5622
5842
  };
5623
5843
  const inject = (menu) => {
5624
5844
  if (channelId === undefined || performance.now() - rememberedAt > 2000) return;
5625
- if (menu.querySelector(`[${CHANNEL_GROUP_MENU_ATTR}="true"]`) !== null) return;
5845
+ const existing = menu.querySelector(`button[${CHANNEL_GROUP_MENU_ATTR}="true"]`);
5846
+ if (existing !== null) {
5847
+ hideOthers(menu, new Set([existing]));
5848
+ return;
5849
+ }
5626
5850
  const items = [...menu.querySelectorAll('button[role="menuitem"]')];
5627
5851
  if (items.length === 0) return;
5628
5852
  const menuText = items.map((item) => item.textContent || "").join(" ");
@@ -5642,15 +5866,15 @@ body:not([data-ds-dark-theme]) .ima-section-card{background:var(--dsw-alias-bg-l
5642
5866
  button.removeAttribute(CHANNEL_GROUP_MENU_ATTR);
5643
5867
  button.removeAttribute("aria-disabled");
5644
5868
  button.removeAttribute("disabled");
5869
+ button.removeAttribute("aria-keyshortcuts");
5870
+ button.removeAttribute("aria-describedby");
5645
5871
  button.disabled = false;
5646
5872
  button.style.opacity = "";
5647
5873
  button.style.cursor = "";
5648
5874
  button.classList.remove("danger");
5649
5875
  button.setAttribute(CHANNEL_GROUP_MENU_ATTR, "true");
5650
- const spans = button.querySelectorAll("span");
5651
- if (spans[0] !== undefined) spans[0].innerHTML = icon;
5652
- if (spans[1] !== undefined) spans[1].textContent = label;
5653
- else button.textContent = label;
5876
+ for (const extra of button.querySelectorAll('[class*="check"], [class*="shortcut"]')) extra.remove();
5877
+ replaceMenuItemContent(button, (template.textContent || "").trim(), label, icon);
5654
5878
  let fired = false;
5655
5879
  const activate = (event) => {
5656
5880
  if (fired) return;
@@ -5691,12 +5915,12 @@ body:not([data-ds-dark-theme]) .ima-section-card{background:var(--dsw-alias-bg-l
5691
5915
  observer.disconnect();
5692
5916
  document.removeEventListener("pointerdown", remember, true);
5693
5917
  document.removeEventListener("click", remember, true);
5694
- for (const [item, previous] of hiddenItems) {
5695
- item.style.display = previous.display;
5696
- if (previous.ariaHidden === null) item.removeAttribute("aria-hidden");
5697
- else item.setAttribute("aria-hidden", previous.ariaHidden);
5918
+ for (const [el, previous] of hiddenElements) {
5919
+ el.style.display = previous.display;
5920
+ if (previous.ariaHidden === null) el.removeAttribute("aria-hidden");
5921
+ else el.setAttribute("aria-hidden", previous.ariaHidden);
5698
5922
  }
5699
- hiddenItems.clear();
5923
+ hiddenElements.clear();
5700
5924
  for (const item of document.querySelectorAll(`[${CHANNEL_GROUP_MENU_ATTR}="true"]`)) item.parentElement?.remove();
5701
5925
  };
5702
5926
  }
@@ -5751,7 +5975,6 @@ body:not([data-ds-dark-theme]) .ima-section-card{background:var(--dsw-alias-bg-l
5751
5975
  const groups = useMemo(() => channelGroupsFromSessionState(sessionSource, t), [membershipRevision, sessionSource, t]);
5752
5976
  const groupsRef = useRef(groups);
5753
5977
  groupsRef.current = groups;
5754
- const [channelIcons, setChannelIcons] = useState("");
5755
5978
  const [workspaceIcons, setWorkspaceIcons] = useState("");
5756
5979
  const open = props.openSession || hostProps.open || hostProps.openSession;
5757
5980
  const openChannelSettings = props.openChannelSettings || hostProps.openChannelSettings;
@@ -5759,10 +5982,6 @@ body:not([data-ds-dark-theme]) .ima-section-card{background:var(--dsw-alias-bg-l
5759
5982
 
5760
5983
  useEffect(() => { ensureStyle(); }, []);
5761
5984
 
5762
- useEffect(() => {
5763
- if (groupBy === "channel" && channelIcons === "") setChannelIcons(channelIconCss());
5764
- }, [channelIcons, groupBy]);
5765
-
5766
5985
  const memberKey = groups.map((group) => group.id + ":" + (group.sessions || []).map((session) => session.sessionId).join(",")).join("|");
5767
5986
  const memberIds = useMemo(() => {
5768
5987
  const ids = new Set();
@@ -5830,7 +6049,11 @@ body:not([data-ds-dark-theme]) .ima-section-card{background:var(--dsw-alias-bg-l
5830
6049
  resolve: (channelId) => groupsRef.current.find((group) => group.id === channelId),
5831
6050
  onSettings: (group) => {
5832
6051
  if (typeof openChannelSettings === "function") {
5833
- openChannelSettings({ channelId: group.id, name: channelLabel(group, t) });
6052
+ openChannelSettings({
6053
+ channelId: group.platform || group.id,
6054
+ accountId: group.accountId || group.id,
6055
+ name: group.label || channelLabel(group, t),
6056
+ });
5834
6057
  return;
5835
6058
  }
5836
6059
  openImSettings();
@@ -5898,7 +6121,6 @@ body:not([data-ds-dark-theme]) .ima-section-card{background:var(--dsw-alias-bg-l
5898
6121
 
5899
6122
  return h(React.Fragment, null,
5900
6123
  h("div", { className: "ima-channel-official", "data-mode": groupBy },
5901
- groupBy === "channel" && channelIcons !== "" && h("style", null, channelIcons),
5902
6124
  groupBy !== "channel" && workspaceIcons !== "" && h("style", null, workspaceIcons),
5903
6125
  // 宿主列表失败时 phase 仍停在 pending,没有横幅就是整页空白。
5904
6126
  groupsError && h("div", { className: "ima-channel-error", role: "alert" }, t("error.load")),