@xmanrui/dsh-im 5.0.3 → 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/README.en.md +18 -8
- package/README.md +18 -8
- package/docs/client-integration.md +10 -2
- package/lib/client.js +687 -496
- package/lib/index.js +318 -294
- package/package.json +1 -1
- package/plugin-src/client/channels/feishu/group-settings.js +10 -9
- package/plugin-src/client/channels/feishu/index.js +3 -3
- package/plugin-src/client/global-settings.js +29 -24
- package/plugin-src/client/group-history-settings.js +72 -0
- package/plugin-src/client/i18n.js +19 -3
- package/plugin-src/client/index.js +4 -1
- package/plugin-src/client/plugin-page.js +18 -0
- package/plugin-src/client/styles.js +13 -4
- package/plugin-src/host/channels/feishu/production.mjs +2 -0
- package/plugin-src/host/channels/feishu/rpc.mjs +5 -4
- package/plugin-src/host/channels/qq/production.mjs +2 -0
- package/plugin-src/host/channels/shared/production.mjs +2 -0
- package/plugin-src/host/channels/slack/production.mjs +2 -0
- package/plugin-src/host/channels/whatsapp/production.mjs +2 -0
- package/plugin-src/host/group-history-rpc.mjs +22 -0
- package/plugin-src/host/group-history-runtime.mjs +21 -0
- package/plugin-src/host/inbound-ttl-rpc.mjs +6 -2
- package/plugin-src/host/index.mjs +4 -1
- package/src/channels/discord/discord-runtime.mjs +8 -0
- package/src/channels/feishu/bridge.mjs +23 -1
- package/src/channels/feishu/feishu-runtime.mjs +5 -0
- package/src/channels/feishu/multi-bot-controller.mjs +17 -3
- package/src/channels/feishu/plugin-controller.mjs +2 -0
- package/src/channels/feishu/repair-manager.mjs +2 -1
- package/src/channels/qq/qq-bridge.mjs +19 -0
- package/src/channels/qq/qq-runtime.mjs +4 -0
- package/src/channels/shared/group-history-access.mjs +133 -0
- package/src/channels/shared/group-history-store.mjs +383 -0
- package/src/channels/shared/group-history.mjs +56 -0
- package/src/channels/shared/harness-client.mjs +9 -1
- package/src/channels/shared/i18n-en/feishu.mjs +2 -2
- package/src/channels/shared/text-harness-bridge.mjs +1 -0
- package/src/channels/slack/manifest.mjs +2 -0
- package/src/channels/slack/slack-runtime.mjs +10 -2
- package/src/channels/telegram/telegram-runtime.mjs +7 -0
- package/src/channels/wecom/wecom-runtime.mjs +8 -1
- package/src/channels/weixin/weixin-api.mjs +21 -2
- package/src/channels/whatsapp/whatsapp-runtime.mjs +20 -0
|
@@ -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
|
|
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(
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { captureGroupHistory, groupHistoryEntry } from '../shared/group-history.mjs';
|
|
1
2
|
import { createConnectionDiagnostics, atConnectionStage } from '../shared/connection-error.mjs';
|
|
2
3
|
import { createHash, randomBytes } from 'node:crypto';
|
|
3
4
|
|
|
@@ -724,6 +725,7 @@ export class WhatsappRuntime {
|
|
|
724
725
|
#harness;
|
|
725
726
|
#state;
|
|
726
727
|
#contextEnhancement;
|
|
728
|
+
#groupHistory;
|
|
727
729
|
#accessPolicy;
|
|
728
730
|
#logger;
|
|
729
731
|
#diagnostics;
|
|
@@ -744,6 +746,7 @@ export class WhatsappRuntime {
|
|
|
744
746
|
harness,
|
|
745
747
|
state,
|
|
746
748
|
contextEnhancement,
|
|
749
|
+
groupHistory,
|
|
747
750
|
accessPolicy,
|
|
748
751
|
logger = console,
|
|
749
752
|
replyTimeoutMs = 600_000,
|
|
@@ -759,6 +762,7 @@ export class WhatsappRuntime {
|
|
|
759
762
|
this.#harness = harness;
|
|
760
763
|
this.#state = state;
|
|
761
764
|
this.#contextEnhancement = contextEnhancement;
|
|
765
|
+
this.#groupHistory = groupHistory;
|
|
762
766
|
this.#accessPolicy = accessPolicy;
|
|
763
767
|
this.#logger = logger; this.#diagnostics = createConnectionDiagnostics({ channel: 'whatsapp', logger });
|
|
764
768
|
this.#replyTimeoutMs = replyTimeoutMs;
|
|
@@ -821,6 +825,22 @@ export class WhatsappRuntime {
|
|
|
821
825
|
}),
|
|
822
826
|
});
|
|
823
827
|
if (!message || outboundIds.has(message.providerMessageId) || !this.#bridge) return;
|
|
828
|
+
let groupName;
|
|
829
|
+
if (this.#groupHistory && message.kind === 'group' && message.addressed) {
|
|
830
|
+
let timeout;
|
|
831
|
+
try {
|
|
832
|
+
groupName = (await Promise.race([
|
|
833
|
+
context?.socket?.groupMetadata?.(message.conversationId),
|
|
834
|
+
new Promise((resolve) => { timeout = setTimeout(resolve, 2500); timeout.unref?.(); }),
|
|
835
|
+
]))?.subject;
|
|
836
|
+
} catch { /* optional metadata must not block normal replies */ }
|
|
837
|
+
finally { clearTimeout(timeout); }
|
|
838
|
+
}
|
|
839
|
+
if (!hasViewOnceWrapper(raw.message)) {
|
|
840
|
+
await captureGroupHistory(this.#groupHistory, message, groupHistoryEntry('whatsapp', raw, message, { groupName }), {
|
|
841
|
+
logger: this.#logger,
|
|
842
|
+
});
|
|
843
|
+
}
|
|
824
844
|
this.#status.lastCheckedAt = Date.now();
|
|
825
845
|
await this.#bridge.accept(message);
|
|
826
846
|
},
|