@xmanrui/dsh-im 5.1.0 → 5.2.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xmanrui/dsh-im",
3
- "version": "5.1.0",
3
+ "version": "5.2.0",
4
4
  "icon": "./assets/logo-plugin-message-link-gradient.webp",
5
5
  "description": "把微信、飞书、企微、钉钉、QQ、Telegram、WhatsApp、Slack、Discord、Matrix接入DSH。 Connect Telegram, WhatsApp, Slack, Discord, Matrix, WeChat, Feishu, WeCom, DingTalk, and QQ to DSH.",
6
6
  "keywords": [
@@ -567,7 +567,10 @@ export function apply(ctx) {
567
567
  preferredSectionId: props.preferredSectionId,
568
568
  });
569
569
 
570
- installImPluginPage(ctx, { packageName: manifest.name, renderPanel: buildPanelElement });
570
+ installImPluginPage(ctx, {
571
+ packageName: manifest.name,
572
+ renderPanel: buildPanelElement,
573
+ });
571
574
 
572
575
  ctx.effect(() => {
573
576
  let disposed = false;
@@ -21,6 +21,17 @@ function ImPluginPage({ renderPanel, onBack, t }) {
21
21
  renderPanel()));
22
22
  }
23
23
 
24
+ // Preserve the catalog's linked speech bubbles at the host's regular 1px weight.
25
+ function ImSidebarIcon({ size }) {
26
+ return h('svg', {
27
+ className: 'dim-sidebarIcon', 'aria-hidden': true, focusable: false,
28
+ width: size, height: size, viewBox: '0 0 16 16', fill: 'none',
29
+ stroke: 'currentColor', strokeWidth: 1, strokeLinecap: 'round', strokeLinejoin: 'round',
30
+ },
31
+ h('path', { d: 'M5 9.5H3.8L1.5 10.7l.7-2.2A2.4 2.4 0 0 1 1.5 6.8V4A2.5 2.5 0 0 1 4 1.5h4A2.5 2.5 0 0 1 10.5 4v3A2.5 2.5 0 0 1 8 9.5h-.5' }),
32
+ h('path', { d: 'M12 6.5A2.5 2.5 0 0 1 14.5 9v2.8a2.4 2.4 0 0 1-.7 1.7l.7 1.2-2.3-.7H8A2.5 2.5 0 0 1 5.5 11.5V9A2.5 2.5 0 0 1 8 6.5h.5' }));
33
+ }
34
+
24
35
  // Optional services and slots keep the existing settings entry working on
25
36
  // older DSH versions. Reuse the same panel through public navigation APIs.
26
37
  export function installImPluginPage(ctx, { packageName, renderPanel }) {
@@ -34,6 +45,12 @@ export function installImPluginPage(ctx, { packageName, renderPanel }) {
34
45
  onBack: () => pageCtx.pluginNavigation.openBundle(packageName),
35
46
  }),
36
47
  }, ImPluginPage);
48
+ const stopSidebar = pageCtx.slots.inject('sidebar.panellist', () =>
49
+ pageCtx.slots.register({
50
+ name: 'sidebar.panellist', id: IM_MAIN_PANEL_ID,
51
+ order: 10, label: () => pageCtx.locale.bind(IM_LOCALE_NAMESPACE)('IM机器人'),
52
+ locale: IM_LOCALE_NAMESPACE,
53
+ }, ImSidebarIcon));
37
54
  const stopActions = pageCtx.slots.inject('plugins.detail.actions', () =>
38
55
  pageCtx.slots.register({
39
56
  name: 'plugins.detail.actions', id: 'xmanrui-dsh-im-open',
@@ -45,6 +62,7 @@ export function installImPluginPage(ctx, { packageName, renderPanel }) {
45
62
  }, OpenImAction));
46
63
  return () => {
47
64
  stopActions();
65
+ stopSidebar();
48
66
  unregisterPage();
49
67
  };
50
68
  }));
@@ -1,6 +1,7 @@
1
1
  export const IM_STYLE_ID = 'xmanrui-dsh-im-settings';
2
2
 
3
3
  const CSS = String.raw`
4
+ .dim-sidebarIcon { display: block; flex: none; }
4
5
  .dim-pluginOpen { display: inline-flex; align-items: center; justify-content: center; min-height: 36px; padding: 7px 14px; border: 1px solid var(--dsw-alias-border-l2, #dfe1e5); border-radius: 8px; color: var(--dsw-alias-label-primary, #1f2329); background: var(--dsw-alias-bg-layer-1, #fff); font: inherit; font-size: 13px; line-height: 20px; cursor: pointer; }
5
6
  .dim-pluginOpen:hover { background: var(--dsw-alias-interactive-bg-hover, #f7f8fa); }
6
7
  .dim-pluginOpen:focus-visible, .dim-pluginBack:focus-visible { outline: 2px solid var(--dsw-alias-state-business-primary, #3370ff); outline-offset: 3px; }
@@ -1865,10 +1865,15 @@ export class HarnessClient {
1865
1865
  progressTail = progressTail
1866
1866
  .then(() => onUpdate(update))
1867
1867
  .catch((error) => {
1868
+ // The WeCom SDK rejects with the raw ack frame (no .message), so
1869
+ // surface errcode/errmsg explicitly instead of printing undefined.
1870
+ const detail = error instanceof Error
1871
+ ? error.message
1872
+ : `${error?.errmsg ?? error?.body?.errmsg ?? '(no message)'} (errcode=${error?.errcode ?? error?.body?.errcode ?? 'unknown'})`;
1868
1873
  console.warn(
1869
1874
  '[dsh-im] ignored a progress update failure:',
1870
1875
  this.#logPrefix,
1871
- error.message,
1876
+ detail,
1872
1877
  );
1873
1878
  });
1874
1879
  }
@@ -101,7 +101,14 @@ export class WecomRuntime {
101
101
  await atConnectionStage('harness.check', () => this.#harness.ensureRunning());
102
102
  this.#status.harnessReachable = true;
103
103
 
104
- const silentSdkLogger = { debug() {}, info() {}, warn() {}, error() {} };
104
+ // The SDK's own logger reports reply ack errors (errcode/errmsg) that are
105
+ // invisible otherwise; keep debug/info quiet but surface warn/error.
106
+ const silentSdkLogger = {
107
+ debug() {},
108
+ info() {},
109
+ warn: (...args) => this.#logger.warn?.('[dsh-im:wecom-sdk]', ...args),
110
+ error: (...args) => this.#logger.error?.('[dsh-im:wecom-sdk]', ...args),
111
+ };
105
112
  const client = this.#createClient({
106
113
  botId: this.#config.remoteBotId,
107
114
  secret: this.#secret,
@@ -21,6 +21,7 @@ const ILINK_CLIENT_VERSION = (2 << 16) | (4 << 8) | 6;
21
21
  const DEFAULT_TIMEOUT_MS = 15_000;
22
22
  const DEFAULT_LONG_POLL_TIMEOUT_MS = 35_000;
23
23
  const WEIXIN_CDN_UPLOAD_RETRIES = 3;
24
+ const WEIXIN_TEXT_SEND_RETRY_DELAYS_MS = [400, 1_200];
24
25
  const WEIXIN_CDN_UPLOAD_IDLE_TIMEOUT_MS = 60_000;
25
26
  const WEIXIN_CDN_UPLOAD_CHUNK_BYTES = 64 * 1024;
26
27
  const WEIXIN_MESSAGE_ID_TIMESTAMP_SHIFT = 22n;
@@ -497,6 +498,24 @@ async function requestJson(fetchImpl, {
497
498
  }
498
499
  }
499
500
 
501
+ // A text reply is the only thing the user gets, so a single connection-level failure must not
502
+ // discard it. Only `network-error` is repeated: it means no HTTP response arrived at all, while
503
+ // `timeout`, `http-error` and `send-rejected` may already have been delivered. iLink does not
504
+ // deduplicate by `client_id`, so the caller keeps one id for every attempt of the same chunk and
505
+ // accepts that a request which reached the service just before the socket died can still arrive twice.
506
+ async function requestTextSend(fetchImpl, createRequest, { signal }) {
507
+ for (let attempt = 0; ; attempt += 1) {
508
+ try {
509
+ return await requestJson(fetchImpl, createRequest());
510
+ } catch (error) {
511
+ const retryDelayMs = WEIXIN_TEXT_SEND_RETRY_DELAYS_MS[attempt];
512
+ if (retryDelayMs === undefined || error?.code !== 'network-error' || signal?.aborted) throw error;
513
+ await new Promise((resolve) => { setTimeout(resolve, retryDelayMs); });
514
+ signal?.throwIfAborted?.();
515
+ }
516
+ }
517
+ }
518
+
500
519
  function validateLoginResponse(value) {
501
520
  if (!value || typeof value !== 'object' || !LOGIN_STATUSES.has(value.status)) {
502
521
  throw new WeixinApiError('invalid-login-status', '微信服务返回了无法识别的扫码状态。');
@@ -741,7 +760,7 @@ export function createWeixinApi({ fetchImpl = fetch, uploadFetchImpl = fetchImpl
741
760
  const content = nonEmptyString(text);
742
761
  if (!recipient || !content) throw new TypeError('toUserId and text are required');
743
762
  const clientId = `dsh-weixin-${randomUUID()}`;
744
- const response = await requestJson(fetchImpl, {
763
+ const response = await requestTextSend(fetchImpl, () => ({
745
764
  method: 'POST',
746
765
  baseUrl,
747
766
  endpoint: 'ilink/bot/sendmessage',
@@ -760,7 +779,7 @@ export function createWeixinApi({ fetchImpl = fetch, uploadFetchImpl = fetchImpl
760
779
  },
761
780
  base_info: baseInfo(),
762
781
  },
763
- });
782
+ }), { signal });
764
783
  const sendRejection = rejectedProviderResponse(response);
765
784
  if (sendRejection) {
766
785
  throw new WeixinApiError(