@botharness/im-provider 4.32.0-botharness.16 → 4.32.0-botharness.21
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/PROVENANCE.json +9 -9
- package/lib/client.js +8 -5
- package/lib/index.js +305 -308
- package/package.json +6 -5
- package/plugin-src/host/app-setup.mjs +244 -0
- package/plugin-src/host/build.mjs +3 -2
- package/plugin-src/host/channels/qq/production.mjs +7 -1
- package/plugin-src/host/channels/shared/startup.mjs +3 -0
- package/plugin-src/host/delivery-adapter.mjs +15 -0
- package/plugin-src/host/delivery-service.mjs +103 -3
- package/plugin-src/host/index.mjs +15 -2
- package/plugin-src/host/qq-sdk-observation-patch.mjs +53 -0
- package/src/channels/discord/discord-api.mjs +9 -0
- package/src/channels/discord/discord-controller.mjs +1 -2
- package/src/channels/discord/discord-runtime.mjs +13 -0
- package/src/channels/discord/reachable-conversations.mjs +211 -0
- package/src/channels/feishu/external-cards.mjs +63 -6
- package/src/channels/feishu/external-reactions.mjs +36 -0
- package/src/channels/feishu/feishu-runtime.mjs +95 -2
- package/src/channels/feishu/multi-bot-controller.mjs +78 -4
- package/src/channels/qq/config-store.mjs +1 -0
- package/src/channels/qq/external-addressing.mjs +6 -0
- package/src/channels/qq/external-consumer.mjs +214 -0
- package/src/channels/qq/external-files.mjs +50 -0
- package/src/channels/qq/external-images.mjs +109 -0
- package/src/channels/qq/external-mentions.mjs +32 -0
- package/src/channels/qq/external-post.mjs +51 -0
- package/src/channels/qq/external-voice.mjs +32 -0
- package/src/channels/qq/native-gateway-diagnostics.mjs +86 -0
- package/src/channels/qq/native-reply-observations.mjs +143 -0
- package/src/channels/qq/native-transport-diagnostics.mjs +42 -0
- package/src/channels/qq/qq-controller.mjs +105 -1
- package/src/channels/qq/qq-runtime.mjs +259 -12
- package/src/channels/qq/sdk-frame-observation.mjs +31 -0
- package/src/channels/qq/voice-attachment.mjs +3 -0
- package/src/channels/shared/i18n-en/qq.mjs +4 -0
- package/src/channels/shared/i18n-en/weixin.mjs +1 -0
- package/src/channels/shared/token-bot-controller.mjs +26 -0
- package/src/channels/slack/reachable-conversations.mjs +136 -0
- package/src/channels/slack/slack-api.mjs +9 -1
- package/src/channels/slack/slack-controller.mjs +25 -2
- package/src/channels/slack/slack-runtime.mjs +23 -0
- package/src/channels/weixin/connection-error.en.mjs +1 -0
- package/src/channels/weixin/connection-error.mjs +1 -0
- package/src/channels/weixin/weixin-controller.mjs +23 -2
|
@@ -4,6 +4,7 @@ import { t } from '../shared/i18n.mjs';
|
|
|
4
4
|
import { createSlackHistoryReader } from './history-reader.mjs';
|
|
5
5
|
import { externalAttachments, readExternalFile, replyExternalFile } from './external-files.mjs';
|
|
6
6
|
import { SlackApi } from './slack-api.mjs';
|
|
7
|
+
import { listSlackReachable, postSlackConversation } from './reachable-conversations.mjs';
|
|
7
8
|
import { createSlackBridgeStatus, SlackHarnessBridge } from './slack-bridge.mjs';
|
|
8
9
|
import { normalizeSlackExternalText, slackReplyMentions, verifiedSlackAccount, slackRefusal, slackTimestamp } from './external-consumer.mjs';
|
|
9
10
|
|
|
@@ -486,6 +487,25 @@ export class SlackRuntime {
|
|
|
486
487
|
return this.#bridge.sendConnectionTest(text);
|
|
487
488
|
}
|
|
488
489
|
|
|
490
|
+
#checkedReachable(signal) {
|
|
491
|
+
if (!this.#status.ready || !this.#account || !this.#api || !this.#abortController
|
|
492
|
+
|| this.#config.consumerMode !== 'external-consumer') throw slackRefusal('capability-unavailable');
|
|
493
|
+
const generation = this.#generation;
|
|
494
|
+
const combined = signal ? AbortSignal.any([signal, this.#abortController.signal]) : this.#abortController.signal;
|
|
495
|
+
return {api:this.#api,account:this.#account,signal:combined,assertCurrent:()=>{
|
|
496
|
+
combined.throwIfAborted();
|
|
497
|
+
if(generation!==this.#generation||this.#stopped||!this.#status.ready) throw slackRefusal('capability-unavailable');
|
|
498
|
+
}};
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
listReachableConversations(options = {}) {
|
|
502
|
+
return listSlackReachable(this.#checkedReachable(options.signal), options);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
postConversationChecked(id,text,options = {}) {
|
|
506
|
+
return postSlackConversation(this.#checkedReachable(options.signal), id, text, options);
|
|
507
|
+
}
|
|
508
|
+
|
|
489
509
|
async sendProactiveText(target, text, options = {}) {
|
|
490
510
|
if (this.#config.consumerMode === 'external-consumer') {
|
|
491
511
|
const generation = this.#generation;
|
|
@@ -500,6 +520,9 @@ export class SlackRuntime {
|
|
|
500
520
|
options.signal?.throwIfAborted();
|
|
501
521
|
if (generation !== this.#generation || this.#stopped || !this.#status.ready)
|
|
502
522
|
throw slackRefusal('capability-unavailable');
|
|
523
|
+
if(options.beforeSend!==undefined&&options.beforeSend()!==true)throw slackRefusal('send-permission-denied');
|
|
524
|
+
options.signal?.throwIfAborted();
|
|
525
|
+
if(generation!==this.#generation||this.#stopped||!this.#status.ready)throw slackRefusal('capability-unavailable');
|
|
503
526
|
const sent = await this.#postChecked({ channelId, text, signal: options.signal });
|
|
504
527
|
return { sent: true, ...(options.receipt
|
|
505
528
|
? { receipt: { version: 1, messageId: sent.ts, conversationId: sent.channel } } : {}) };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Shared diagnostic copy for the WeChat Host and settings client.
|
|
2
2
|
export default {
|
|
3
|
+
"该微信账号已在本机配置,请选择已有应用。": "This WeChat account is already configured locally. Choose the existing app.",
|
|
3
4
|
"微信配置格式错误:{file}。请查看诊断详情,修复后重启 DSH。": "The WeChat configuration is invalid: {file}. See the diagnostic details, fix the file, and restart DSH.",
|
|
4
5
|
"配置文件": "Configuration file",
|
|
5
6
|
"配置字段": "Configuration field",
|
|
@@ -63,6 +63,7 @@ const MESSAGES = Object.freeze({
|
|
|
63
63
|
'workspace-not-found': '工作区目录不存在。',
|
|
64
64
|
'workspace-not-directory': '工作区路径不是目录。',
|
|
65
65
|
'workspace-bot-not-found': '找不到要修改的机器人。',
|
|
66
|
+
'account-already-configured': '该微信账号已在本机配置,请选择已有应用。',
|
|
66
67
|
'agent-preset-invalid': 'Agent Preset 无效。',
|
|
67
68
|
'agent-preset-unavailable': 'Agent Preset 不存在或不可用。',
|
|
68
69
|
'model-selection-invalid': '模型无效。',
|
|
@@ -224,8 +224,13 @@ export class WeixinController {
|
|
|
224
224
|
});
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
-
async startProvisioning() {
|
|
227
|
+
async startProvisioning({ consumerMode, signal } = {}) {
|
|
228
|
+
if (consumerMode !== undefined && consumerMode !== 'external-consumer') throw new TypeError('Invalid consumer mode');
|
|
229
|
+
signal?.throwIfAborted();
|
|
228
230
|
if (this.#closed) throw new Error('dsh-weixin controller is closed');
|
|
231
|
+
if (consumerMode === 'external-consumer' && this.#activeAttemptId) {
|
|
232
|
+
throw new Error('Weixin provisioning is already active');
|
|
233
|
+
}
|
|
229
234
|
if (this.#activeAttemptId) await this.cancelProvisioning(this.#activeAttemptId);
|
|
230
235
|
|
|
231
236
|
const record = {
|
|
@@ -240,7 +245,11 @@ export class WeixinController {
|
|
|
240
245
|
error: null,
|
|
241
246
|
botId: null,
|
|
242
247
|
task: null,
|
|
248
|
+
consumerMode,
|
|
243
249
|
};
|
|
250
|
+
const abort = () => { record.controller.abort(); record.verifyResolve?.(); };
|
|
251
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
252
|
+
record.detachSignal = () => signal?.removeEventListener('abort', abort);
|
|
244
253
|
this.#attempts.set(record.id, record);
|
|
245
254
|
this.#activeAttemptId = record.id;
|
|
246
255
|
this.#touch();
|
|
@@ -277,6 +286,7 @@ export class WeixinController {
|
|
|
277
286
|
record.error = error.publicError;
|
|
278
287
|
}
|
|
279
288
|
if (this.#activeAttemptId === record.id) this.#activeAttemptId = null;
|
|
289
|
+
record.detachSignal();
|
|
280
290
|
this.#touch();
|
|
281
291
|
throw error;
|
|
282
292
|
}
|
|
@@ -538,6 +548,11 @@ export class WeixinController {
|
|
|
538
548
|
record.currentBaseUrl = apiBaseFromServer(response.redirect_host, record.currentBaseUrl);
|
|
539
549
|
record.state = 'scanned';
|
|
540
550
|
} else if (response.status === 'binded_redirect') {
|
|
551
|
+
if (record.consumerMode === 'external-consumer') {
|
|
552
|
+
record.state = 'failed';
|
|
553
|
+
record.error = safeAccountError('already-bound', t('该微信账号已绑定,请选择已有应用。'));
|
|
554
|
+
break;
|
|
555
|
+
}
|
|
541
556
|
const existing = this.#configStore.list().find(
|
|
542
557
|
(config) => this.#runtimes.get(config.botId)?.status?.ready === true,
|
|
543
558
|
) ?? this.#configStore.list()[0];
|
|
@@ -590,6 +605,7 @@ export class WeixinController {
|
|
|
590
605
|
}).publicError;
|
|
591
606
|
}
|
|
592
607
|
} finally {
|
|
608
|
+
record.detachSignal();
|
|
593
609
|
record.pendingVerifyCode = null;
|
|
594
610
|
record.verifyResolve?.();
|
|
595
611
|
record.verifyResolve = null;
|
|
@@ -610,7 +626,8 @@ export class WeixinController {
|
|
|
610
626
|
baseUrl,
|
|
611
627
|
createdAt: previousConfig?.createdAt ?? new Date().toISOString(),
|
|
612
628
|
connectedAt: new Date().toISOString(),
|
|
613
|
-
...(
|
|
629
|
+
...(record.consumerMode || previousConfig?.consumerMode
|
|
630
|
+
? { consumerMode: record.consumerMode ?? previousConfig.consumerMode } : {}),
|
|
614
631
|
};
|
|
615
632
|
let previousToken;
|
|
616
633
|
try {
|
|
@@ -620,6 +637,10 @@ export class WeixinController {
|
|
|
620
637
|
}
|
|
621
638
|
|
|
622
639
|
return this.#withBotTransition(identity.botId, async () => {
|
|
640
|
+
this.#assertAttemptActive(record);
|
|
641
|
+
if (record.consumerMode === 'external-consumer' && this.#configStore.getByAccountId(accountId)) {
|
|
642
|
+
throw weixinStageError('account-already-configured');
|
|
643
|
+
}
|
|
623
644
|
try {
|
|
624
645
|
try {
|
|
625
646
|
await this.#writeCredential(identity.tokenRef, token);
|