@botharness/im-provider 4.32.0-botharness.20 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botharness/im-provider",
3
- "version": "4.32.0-botharness.20",
3
+ "version": "4.32.0-botharness.21",
4
4
  "icon": "./assets/logo-plugin-message-link-gradient.webp",
5
5
  "description": "BotHarness-qualified IM Provider, maintained from dsh-im",
6
6
  "keywords": [
@@ -178,6 +178,6 @@
178
178
  "peerDependencies": {},
179
179
  "botharness": {
180
180
  "managedByProduct": true,
181
- "upstreamSource": "0e5b447f45e4a44d4089eac16cc1fa5673dbd66d"
181
+ "upstreamSource": "beaed4a6dabb583654d28fb09298716267039b4a"
182
182
  }
183
183
  }
@@ -113,7 +113,7 @@ export async function createProductionController(ctx, config = {}, internals = {
113
113
  credentials: ctx.credentials,
114
114
  configStore: observedConfigStore,
115
115
  logger,
116
- createRuntime: async ({ botId, config: botConfig, appSecret, externalConsumer, sourceImages, sourceFiles, sourceVoiceTranscripts, sourceVoiceAudio }) => {
116
+ createRuntime: async ({ botId, config: botConfig, appSecret, externalConsumer, sourceImages, sourceFiles, sourceVoiceTranscripts, sourceVoiceAudio, ordinaryText }) => {
117
117
  const state = await stateFor(botId);
118
118
  await workspaces.ensure(botId, {
119
119
  defaultAgentPreset: config.agentPreset,
@@ -130,6 +130,7 @@ export async function createProductionController(ctx, config = {}, internals = {
130
130
  sourceFiles,
131
131
  sourceVoiceTranscripts,
132
132
  sourceVoiceAudio,
133
+ ordinaryText,
133
134
  harness: workspaceScope.harness,
134
135
  state: workspaceScope.state,
135
136
  contextEnhancement: { botId, getSettings: () => workspaces.contextEnhancementFor(botId) },
@@ -41,8 +41,11 @@ export function verifiedQqAccount(appId, user) {
41
41
  }
42
42
 
43
43
  /** QQ group and member OpenIDs belong to this authenticated application. */
44
- export function normalizeQqExternalText(message, { botId, account }) {
45
- if (!isQqAddressedGroupMessage(message)
44
+ export function normalizeQqExternalText(message, { botId, account, ordinaryText = false }) {
45
+ const addressed = isQqAddressedGroupMessage(message);
46
+ const ordinary = ordinaryText === true && message?.kind === 'group'
47
+ && message.rawEventType === 'GROUP_MESSAGE_CREATE';
48
+ if (!(addressed || ordinary)
46
49
  || message.senderIsBot || message.senderId === account.userId
47
50
  || message.attachments?.length || message.msgElements?.length
48
51
  || (message.msgType !== undefined && message.msgType !== 0)) return null;
@@ -61,7 +64,7 @@ export function normalizeQqExternalText(message, { botId, account }) {
61
64
  ...(typeof message.senderName === 'string' && message.senderName.trim()
62
65
  ? { name: message.senderName.slice(0, 512) } : {}) },
63
66
  conversation: { kind: 'group', id: message.groupOpenid },
64
- mentions: qqExternalMentions(message, account), mentionedAccount: true, at: at.toISOString(), text: message.content,
67
+ mentions: qqExternalMentions(message, account), mentionedAccount: addressed, at: at.toISOString(), text: message.content,
65
68
  reply: { messageId: message.messageId, conversationId: message.groupOpenid, actorId: message.senderId },
66
69
  replay: { kind: 'provider-redelivery', resumeCursor: false, gapPossible: true },
67
70
  });
@@ -78,8 +81,9 @@ export class QqExternalConsumer {
78
81
  #sourceFiles;
79
82
  #sourceVoiceTranscripts;
80
83
  #sourceVoiceAudio;
84
+ #ordinaryText;
81
85
  #sources = new Map();
82
- constructor({ bot, account, botId, accept, sourceImages = () => false, sourceFiles = () => false, sourceVoiceTranscripts = () => false, sourceVoiceAudio = () => false, reportNativeObservation = () => {}, reportNativeFrame, nativeUser }) {
86
+ constructor({ bot, account, botId, accept, sourceImages = () => false, sourceFiles = () => false, sourceVoiceTranscripts = () => false, sourceVoiceAudio = () => false, ordinaryText = () => false, reportNativeObservation = () => {}, reportNativeFrame, nativeUser }) {
83
87
  this.#bot = bot; this.#account = account; this.#botId = botId; this.#accept = accept;
84
88
  this.#observations = new QqNativeReplyObservations({ account, report: reportNativeObservation,
85
89
  reportFrame: reportNativeFrame, nativeUser });
@@ -87,22 +91,24 @@ export class QqExternalConsumer {
87
91
  this.#sourceFiles = sourceFiles;
88
92
  this.#sourceVoiceTranscripts = sourceVoiceTranscripts;
89
93
  this.#sourceVoiceAudio = sourceVoiceAudio;
94
+ this.#ordinaryText = ordinaryText;
90
95
  }
91
96
  recordNativeReceipt(receipt, signal) {
92
97
  this.#observations.sent(receipt.conversationId, receipt.messageId, signal);
93
98
  }
94
99
  async accept(message, signal) {
95
100
  this.#observations.receive(message, signal);
96
- const voice = this.#sourceVoiceTranscripts() === true || this.#sourceVoiceAudio() === true
101
+ const addressed = isQqAddressedGroupMessage(message);
102
+ const voice = addressed && (this.#sourceVoiceTranscripts() === true || this.#sourceVoiceAudio() === true)
97
103
  ? qqVoiceMessage(message, { sourceVoiceTranscripts: this.#sourceVoiceTranscripts() === true }) : undefined;
98
- const quoted = !voice && this.#sourceFiles() === true ? qqQuotedFileMessage(message) : undefined;
104
+ const quoted = addressed && !voice && this.#sourceFiles() === true ? qqQuotedFileMessage(message) : undefined;
99
105
  message = quoted?.message ?? message;
100
106
  message = voice?.message ?? message;
101
- const mediaEnabled = (this.#sourceImages() === true || this.#sourceFiles() === true) && message?.attachments?.length;
107
+ const mediaEnabled = addressed && (this.#sourceImages() === true || this.#sourceFiles() === true) && message?.attachments?.length;
102
108
  const base = normalizeQqExternalText(mediaEnabled ? { ...message, attachments: undefined,
103
109
  content: typeof message.content === 'string' && !message.content.trim()
104
110
  ? message.attachments.every(file => file?.content_type === 'file') ? '[File]' : '[Image]' : message.content } : message,
105
- { botId: this.#botId, account: this.#account });
111
+ { botId: this.#botId, account: this.#account, ordinaryText: this.#ordinaryText() === true });
106
112
  const media = base && voice && this.#sourceVoiceAudio() === true
107
113
  ? qqSourceAttachments(voice.nativeMessage, base, { sourceImages: false, sourceVoiceAudio: true, referenceKey: voice.referenceKey })
108
114
  : base && mediaEnabled ? qqSourceAttachments(message, base,
@@ -131,6 +137,7 @@ export class QqExternalConsumer {
131
137
  }
132
138
  qualify(route, signal) {
133
139
  const source = this.#source(route, signal);
140
+ if (!source.event.mentionedAccount) throw qqRefusal('capability-unavailable');
134
141
  if (Date.now() - Date.parse(source.event.at) >= 5 * 60_000) throw qqRefusal('reply-window-expired');
135
142
  if (source.attempts >= 5) throw qqRefusal('reply-limit-exceeded');
136
143
  return structuredClone(source.event.reply);
@@ -321,18 +321,18 @@ export class QqController {
321
321
  return this.#withBotTransition(botId, async () => ({
322
322
  version: 1, botId, channel: 'qq', account: await this.#deliveryAccount(botId), connected: true,
323
323
  capabilities: ['proactive-text-checked', 'proactive-receipt-checked', 'proactive-fence-checked',
324
- 'exclusive-text-consumer', 'reply-text-checked', 'reply-context-checked',
324
+ 'exclusive-text-consumer', 'ordinary-text-consumer', 'reply-text-checked', 'reply-context-checked',
325
325
  'reply-receipt-checked', 'reply-fence-checked', 'source-file-checked', 'source-image-checked',
326
326
  'reply-file-checked', 'reply-image-fence-checked', 'reply-file-receipt-checked',
327
327
  'source-generic-file-checked', 'reply-file-fence-checked', 'source-voice-transcript-checked', 'source-voice-audio-checked'],
328
328
  }));
329
329
  }
330
330
 
331
- async consumeInbound(botId, { expectedFingerprint, onEvent, signal, sourceImages = false, sourceFiles = false, sourceVoiceTranscripts = false, sourceVoiceAudio = false } = {}) {
331
+ async consumeInbound(botId, { expectedFingerprint, onEvent, signal, sourceImages = false, sourceFiles = false, sourceVoiceTranscripts = false, sourceVoiceAudio = false, ordinaryText = false } = {}) {
332
332
  return this.#withBotTransition(botId, async () => {
333
333
  const account = await this.#deliveryAccount(botId, signal);
334
334
  if (account.fingerprint !== expectedFingerprint) throw qqRefusal('account-changed');
335
- const dispose = this.#inboundConsumers.register(botId, { fingerprint: expectedFingerprint, onEvent, signal, sourceImages, sourceFiles, sourceVoiceTranscripts, sourceVoiceAudio });
335
+ const dispose = this.#inboundConsumers.register(botId, { fingerprint: expectedFingerprint, onEvent, signal, sourceImages, sourceFiles, sourceVoiceTranscripts, sourceVoiceAudio, ordinaryText });
336
336
  try {
337
337
  const saved = await this.#configStore.save({ ...this.#configStore.get(botId), consumerMode: 'external-consumer' });
338
338
  const secret = await this.#resolveSecret(saved.secretRef);
@@ -568,6 +568,7 @@ export class QqController {
568
568
  sourceFiles: () => this.#inboundConsumers.acceptsFiles(config.botId),
569
569
  sourceVoiceTranscripts: () => this.#inboundConsumers.acceptsVoiceTranscripts(config.botId),
570
570
  sourceVoiceAudio: () => this.#inboundConsumers.acceptsVoiceAudio(config.botId),
571
+ ordinaryText: () => this.#inboundConsumers.acceptsOrdinary(config.botId),
571
572
  } : {}),
572
573
  }));
573
574
  if (!runtime || typeof runtime.start !== 'function' || typeof runtime.stop !== 'function') {
@@ -57,6 +57,7 @@ export class QqRuntime {
57
57
  #sourceFiles;
58
58
  #sourceVoiceTranscripts;
59
59
  #sourceVoiceAudio;
60
+ #ordinaryText;
60
61
  #externalBridge = null;
61
62
 
62
63
  constructor({
@@ -74,7 +75,7 @@ export class QqRuntime {
74
75
  externalConsumer,
75
76
  sourceImages = () => false,
76
77
  sourceFiles = () => false,
77
- sourceVoiceTranscripts = () => false, sourceVoiceAudio = () => false,
78
+ sourceVoiceTranscripts = () => false, sourceVoiceAudio = () => false, ordinaryText = () => false,
78
79
  }) {
79
80
  if (!config || !appSecret || !harness || !state) {
80
81
  throw new TypeError('QqRuntime requires config, app secret, Harness, and state');
@@ -95,6 +96,7 @@ export class QqRuntime {
95
96
  this.#sourceFiles = sourceFiles;
96
97
  this.#sourceVoiceTranscripts = sourceVoiceTranscripts;
97
98
  this.#sourceVoiceAudio = sourceVoiceAudio;
99
+ this.#ordinaryText = ordinaryText;
98
100
  }
99
101
 
100
102
  get status() {
@@ -337,6 +339,7 @@ export class QqRuntime {
337
339
  sourceFiles: this.#sourceFiles,
338
340
  sourceVoiceTranscripts: this.#sourceVoiceTranscripts,
339
341
  sourceVoiceAudio: this.#sourceVoiceAudio,
342
+ ordinaryText: this.#ordinaryText,
340
343
  reportNativeObservation: record => this.#logger.info?.('[dsh-im:qq] native reply observation', record),
341
344
  reportNativeFrame: record => this.#logger.info?.('[dsh-im:qq] native reply frame', record),
342
345
  });