@qwen-code/channel-qqbot 0.28.0 → 0.28.1-preview.1

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.
@@ -312,8 +312,9 @@ export declare class QQChannel extends ChannelBase {
312
312
  runCronFlow(fn: () => Promise<void>): Promise<void>;
313
313
  /**
314
314
  * Override setBridge to re-attach the permanent `_cronTextHandler`
315
- * after bridge crash-recovery, and to re-register the moderation tools:
316
- * they live on the bridge instance, so a fresh bridge starts without them.
315
+ * after bridge crash-recovery, and to re-register the moderation tools and
316
+ * the file tool: they live on the bridge instance, so a fresh bridge starts
317
+ * without them.
317
318
  */
318
319
  setBridge(bridge: ChannelAgentBridge): void;
319
320
  connect(): Promise<void>;
@@ -895,14 +896,14 @@ export declare class QQChannel extends ChannelBase {
895
896
  /** Newest tracked message id from `senderId` in `chatId`. */
896
897
  private recentMemberMessage;
897
898
  /**
898
- * The chat a moderation call may touch, resolved from the turn in progress.
899
- * Under a shared `sessionScope` one session serves every group and DM, and
900
- * the router target frozen at session creation is whichever chat happened to
901
- * create it — using it would recall a message in a chat nobody asked about.
902
- * ChannelBase calls `onPromptStart` for every turn with that turn's envelope
903
- * chat, which is the only chat the turn is about.
899
+ * The chat a tool call may touch, resolved from the turn in progress. Under a
900
+ * shared `sessionScope` one session serves every group and DM, and the router
901
+ * target frozen at session creation is whichever chat happened to create it —
902
+ * using it would recall a message, or hand a file, to a chat nobody asked
903
+ * about. ChannelBase calls `onPromptStart` for every turn with that turn's
904
+ * envelope chat, which is the only chat the turn is about.
904
905
  */
905
- private resolveModerationChat;
906
+ private resolveTurnChat;
906
907
  /**
907
908
  * Expose the QQ group-management surface to the agent as client MCP tools.
908
909
  * Opt-in: a no-op unless the channel sets moderationTools: true, and also a
@@ -911,6 +912,23 @@ export declare class QQChannel extends ChannelBase {
911
912
  * owner is what keeps each channel's sessions on their own credentials.
912
913
  */
913
914
  private registerModerationTools;
915
+ /**
916
+ * Expose the outbound media tools to the agent as client MCP tools. Opt-in:
917
+ * a no-op unless the channel sets fileTools: true, because the tools let the
918
+ * model hand a local file to the platform under the bot's own identity.
919
+ */
920
+ private registerFileTools;
921
+ /**
922
+ * Upload local bytes and deliver them as a QQ media message, sharing the text
923
+ * path's route, reply anchor, active-message guard and msg_seq bookkeeping.
924
+ *
925
+ * There is deliberately no text fallback: media that cannot be sent is
926
+ * reported to the model, because replacing it with a text message would read
927
+ * as success while the user never got it. The only retry is the same media
928
+ * message re-sent as an active one (no msg_id/msg_seq) when the anchored
929
+ * attempt is rejected.
930
+ */
931
+ private sendQQMedia;
914
932
  /** Single REST entry point for the moderation tools. */
915
933
  private requestModerationApi;
916
934
  private deleteReplyContext;
@@ -1 +1 @@
1
- {"version":3,"file":"QQChannel.d.ts","sourceRoot":"","sources":["../src/QQChannel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,WAAW,EAWZ,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAEV,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,2BAA2B,EAC3B,QAAQ,EACR,aAAa,EACb,aAAa,EACd,MAAM,yBAAyB,CAAC;AA2EjC,MAAM,MAAM,iBAAiB,GACzB,cAAc,GACd,iBAAiB,GACjB,iBAAiB,GACjB,qBAAqB,CAAC;AAE1B,qBAAa,aAAc,SAAQ,KAAK;IAEpC,QAAQ,CAAC,IAAI,EAAE,iBAAiB;gBAAvB,IAAI,EAAE,iBAAiB,EAChC,OAAO,EAAE,MAAM;CAKlB;AAoKD,8DAA8D;AAC9D,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAEjD;AAuFD,qBAAa,SAAU,SAAQ,WAAW;IACxC,OAAO,CAAC,EAAE,CAA0B;IACpC,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,cAAc,CAAa;IACnC,OAAO,CAAC,iBAAiB,CAA8C;IACvE,OAAO,CAAC,cAAc,CAA+C;I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@ -23,8 +23,9 @@ import { OpCode, Intent } from './types.js';
23
23
  import { QQ_FILE_MAX_BYTES, QQ_IMAGE_MAX_BYTES, QQ_MAX_ATTACHMENTS, QQ_VIDEO_MAX_BYTES, QQ_VOICE_MAX_BYTES, classifyQQAttachment, downloadQQAttachment, } from './media.js';
24
24
  import { getCredsFilePath, loadCredentials, saveCredentials, } from './accounts.js';
25
25
  import { qrCodeLogin } from './login.js';
26
- import { fetchAccessToken, fetchGatewayUrl, getApiBase, requestQQApi, sendQQMessage, } from './api.js';
26
+ import { QQ_FILE_TYPE, QQRichMediaError, fetchAccessToken, fetchGatewayUrl, getApiBase, parseQQErrorCode, requestQQApi, sendQQMessage, uploadQQRichMedia, } from './api.js';
27
27
  import { buildModerationTools, } from './moderation-tools.js';
28
+ import { QQ_MEDIA_TOOL_NAMES, buildFileTools, } from './file-tools.js';
28
29
  /** QQ Bot OPENID format: exactly 32 uppercase hex chars (bot and sender OPENIDs). */
29
30
  const QQ_OPENID_RE = /^[A-F0-9]{32}$/i;
30
31
  /**
@@ -140,6 +141,53 @@ function attachmentFileName(name, kind, mimeType) {
140
141
  const safeStem = truncateToBytes(cleaned, 200) || `qq_${kind}`;
141
142
  return `${safeStem}${canonicalExtension(kind, mimeType, base)}`;
142
143
  }
144
+ /** Upload failures the model can act on, keyed by the platform's own codes. */
145
+ function describeUploadFailure(error, toolName) {
146
+ if (!(error instanceof QQRichMediaError)) {
147
+ return `${toolName}: the upload failed (${sanitizeLogText(error instanceof Error ? error.message : String(error), 120)}).`;
148
+ }
149
+ const detail = sanitizeLogText(error.message, 120);
150
+ switch (error.code) {
151
+ case 850031:
152
+ return `${toolName}: the platform rejected the file as too large (850031).`;
153
+ case 40093002:
154
+ return `${toolName}: the platform refused (40093002) — this chat has hit its daily file-sending limit, so retrying today will not help.`;
155
+ case 850019:
156
+ return `${toolName}: the platform does not support this file format (850019).`;
157
+ case 40093001:
158
+ return `${toolName}: the platform failed to store the file (40093001); it is safe to retry.`;
159
+ default: {
160
+ // Structural failures (missing upload_id, short part coverage, no
161
+ // file_info) are thrown with a synthetic status 200 and no platform
162
+ // code; printing "HTTP 200" would read like a success and bury the
163
+ // actual cause, so the status is only named when it is a real error.
164
+ const labels = [
165
+ ...(error.status >= 400 ? [`HTTP ${error.status}`] : []),
166
+ ...(error.code === undefined ? [] : [`code ${error.code}`]),
167
+ ];
168
+ const prefix = labels.length > 0 ? `${labels.join(', ')}: ` : '';
169
+ return `${toolName}: the upload failed (${prefix}${detail}).`;
170
+ }
171
+ }
172
+ }
173
+ /** Send failures for media that uploaded fine, keyed by platform code. */
174
+ function describeMediaSendFailure(status, body, toolName) {
175
+ // Rate limiting is a deliberate no-retry refusal: the anchored send bails
176
+ // instead of falling back to an active one, so the model has to be told to
177
+ // back off rather than read it as a generic rejection.
178
+ if (status === 429) {
179
+ return `${toolName}: the platform is rate-limiting this chat (429), so the media was not sent; do not retry immediately.`;
180
+ }
181
+ const code = parseQQErrorCode(body);
182
+ switch (code) {
183
+ case 304080:
184
+ return `${toolName}: the uploaded file handle expired (304080) before it could be sent; retrying re-uploads it.`;
185
+ case 40034004:
186
+ return `${toolName}: the platform failed to transfer the uploaded file (40034004); it is safe to retry.`;
187
+ default:
188
+ return `${toolName}: the platform rejected the file message (HTTP ${status}${code === undefined ? '' : `, code ${code}`}: ${sanitizeLogText(body, 120)}).`;
189
+ }
190
+ }
143
191
  export class QQChannel extends ChannelBase {
144
192
  ws = null;
145
193
  accessToken = '';
@@ -492,6 +540,7 @@ export class QQChannel extends ChannelBase {
492
540
  this.attachCronHandler();
493
541
  }
494
542
  this.registerModerationTools();
543
+ this.registerFileTools();
495
544
  // Seal a stashed head on every bridge boundary, including the ones
496
545
  // ChannelBase suppresses while a cancel is pending.
497
546
  this.attachBridgeBoundarySeal();
@@ -749,8 +798,9 @@ export class QQChannel extends ChannelBase {
749
798
  }
750
799
  /**
751
800
  * Override setBridge to re-attach the permanent `_cronTextHandler`
752
- * after bridge crash-recovery, and to re-register the moderation tools:
753
- * they live on the bridge instance, so a fresh bridge starts without them.
801
+ * after bridge crash-recovery, and to re-register the moderation tools and
802
+ * the file tool: they live on the bridge instance, so a fresh bridge starts
803
+ * without them.
754
804
  */
755
805
  setBridge(bridge) {
756
806
  this.detachCronHandler();
@@ -758,6 +808,7 @@ export class QQChannel extends ChannelBase {
758
808
  super.setBridge(bridge);
759
809
  this.attachCronHandler();
760
810
  this.registerModerationTools();
811
+ this.registerFileTools();
761
812
  this.attachBridgeBoundarySeal();
762
813
  }
763
814
  // ── ChannelBase interface ──────────────────────────────────────
@@ -4272,14 +4323,14 @@ export class QQChannel extends ChannelBase {
4272
4323
  return undefined;
4273
4324
  }
4274
4325
  /**
4275
- * The chat a moderation call may touch, resolved from the turn in progress.
4276
- * Under a shared `sessionScope` one session serves every group and DM, and
4277
- * the router target frozen at session creation is whichever chat happened to
4278
- * create it — using it would recall a message in a chat nobody asked about.
4279
- * ChannelBase calls `onPromptStart` for every turn with that turn's envelope
4280
- * chat, which is the only chat the turn is about.
4326
+ * The chat a tool call may touch, resolved from the turn in progress. Under a
4327
+ * shared `sessionScope` one session serves every group and DM, and the router
4328
+ * target frozen at session creation is whichever chat happened to create it —
4329
+ * using it would recall a message, or hand a file, to a chat nobody asked
4330
+ * about. ChannelBase calls `onPromptStart` for every turn with that turn's
4331
+ * envelope chat, which is the only chat the turn is about.
4281
4332
  */
4282
- resolveModerationChat(sessionId) {
4333
+ resolveTurnChat(sessionId) {
4283
4334
  const turn = this.sessionTurnChat.get(sessionId);
4284
4335
  if (turn)
4285
4336
  return turn;
@@ -4309,7 +4360,7 @@ export class QQChannel extends ChannelBase {
4309
4360
  if (!register)
4310
4361
  return;
4311
4362
  for (const tool of buildModerationTools({
4312
- resolveChat: (sessionId) => this.resolveModerationChat(sessionId),
4363
+ resolveChat: (sessionId) => this.resolveTurnChat(sessionId),
4313
4364
  memberRecallDisabled: this.moderationRecallWindowMs === 0,
4314
4365
  currentSenderId: (sessionId) => this.getResponseSenderId(sessionId),
4315
4366
  recentMemberMessage: (chatId, senderId) => this.recentMemberMessage(chatId, senderId),
@@ -4320,6 +4371,190 @@ export class QQChannel extends ChannelBase {
4320
4371
  register({ ...tool, owner: this.name });
4321
4372
  }
4322
4373
  }
4374
+ /**
4375
+ * Expose the outbound media tools to the agent as client MCP tools. Opt-in:
4376
+ * a no-op unless the channel sets fileTools: true, because the tools let the
4377
+ * model hand a local file to the platform under the bot's own identity.
4378
+ */
4379
+ registerFileTools() {
4380
+ if (this.qqConfig.fileTools !== true)
4381
+ return;
4382
+ const register = this.bridge.registerChannelTool?.bind(this.bridge);
4383
+ if (!register)
4384
+ return;
4385
+ for (const tool of buildFileTools({
4386
+ // The turn's chat, not the router target: under a shared `sessionScope`
4387
+ // the routed target is whichever chat created the session, so using it
4388
+ // would upload and deliver the file into a chat the caller never asked
4389
+ // about. Same resolver as the moderation tools, which fails closed for a
4390
+ // 'single' session outside a turn.
4391
+ resolveChat: (sessionId) => {
4392
+ const chat = this.resolveTurnChat(sessionId);
4393
+ return chat === undefined ? undefined : { chatId: chat.chatId };
4394
+ },
4395
+ sessionCwd: (sessionId) => this.router.getSessionCwd(sessionId),
4396
+ sendMedia: (input) => this.sendQQMedia(input),
4397
+ log: (message) => process.stderr.write(`[QQ:${this.name}] ${message}\n`),
4398
+ })) {
4399
+ register({ ...tool, owner: this.name });
4400
+ }
4401
+ }
4402
+ /**
4403
+ * Upload local bytes and deliver them as a QQ media message, sharing the text
4404
+ * path's route, reply anchor, active-message guard and msg_seq bookkeeping.
4405
+ *
4406
+ * There is deliberately no text fallback: media that cannot be sent is
4407
+ * reported to the model, because replacing it with a text message would read
4408
+ * as success while the user never got it. The only retry is the same media
4409
+ * message re-sent as an active one (no msg_id/msg_seq) when the anchored
4410
+ * attempt is rejected.
4411
+ */
4412
+ async sendQQMedia(input) {
4413
+ const { sessionId, chatId, kind, fileName, bytes } = input;
4414
+ const toolName = QQ_MEDIA_TOOL_NAMES[kind];
4415
+ const route = await this.resolveRoute(chatId);
4416
+ if ('block' in route) {
4417
+ return {
4418
+ ok: false,
4419
+ message: `${toolName}: the message route is not usable right now (${route.block}).`,
4420
+ };
4421
+ }
4422
+ // The same per-session anchor the streaming sends use, so the media lands in
4423
+ // this turn's reply chain instead of starting a new one. Read before the
4424
+ // upload only for this cheap refusal: the anchor is re-resolved after it.
4425
+ const initial = this.resolveSessionReplyAnchor(sessionId);
4426
+ if (!initial.msgId && this.groupActiveMsgEnabled.get(chatId) === false) {
4427
+ return {
4428
+ ok: false,
4429
+ message: `${toolName}: active messages are disabled for this chat and this turn has no open reply window, so the media cannot be sent.`,
4430
+ };
4431
+ }
4432
+ const scope = this.chatTypeFor(chatId) === 'group' ? 'groups' : 'users';
4433
+ let fileInfo;
4434
+ try {
4435
+ const uploaded = await uploadQQRichMedia({
4436
+ base: route.base,
4437
+ accessToken: this.accessToken,
4438
+ scope,
4439
+ chatId,
4440
+ fileName,
4441
+ bytes,
4442
+ fileType: QQ_FILE_TYPE[kind],
4443
+ });
4444
+ fileInfo = uploaded.fileInfo;
4445
+ }
4446
+ catch (error) {
4447
+ const message = describeUploadFailure(error, toolName);
4448
+ process.stderr.write(`[QQ:${this.name}] ${toolName} upload failed: ${sanitizeLogText(message, 200)}\n`);
4449
+ return { ok: false, message };
4450
+ }
4451
+ // Re-resolve after the upload: a multi-part upload can outlive
4452
+ // REPLY_MSG_ID_TTL_MS, and the TTL sweep then drops both the session anchor
4453
+ // and its msg_seq counter. Sending the pre-upload msgId would restart the
4454
+ // counter at 1 — a (msg_id, msg_seq) pair the streaming text already used,
4455
+ // which QQ dedupes silently while this path reports success. The fresh
4456
+ // anchor is also what lets the documented "reply window closed, send
4457
+ // actively" fallback happen instead of posting into a dead chain.
4458
+ const { msgId } = this.resolveSessionReplyAnchor(sessionId);
4459
+ if (!msgId && this.groupActiveMsgEnabled.get(chatId) === false) {
4460
+ return {
4461
+ ok: false,
4462
+ message: `${toolName}: the reply window closed during the upload and active messages are disabled for this chat, so the media cannot be sent.`,
4463
+ };
4464
+ }
4465
+ let seq = 0;
4466
+ // The rollback runs at most once: a second one could restore a counter a
4467
+ // concurrent send under the same msgId has since advanced, which would
4468
+ // replay a (msg_id, msg_seq) pair QQ silently dedupes.
4469
+ let rolledBack = false;
4470
+ if (msgId) {
4471
+ seq = (this.msgSeqMap.get(msgId) ?? 0) + 1;
4472
+ this.msgSeqMap.set(msgId, seq);
4473
+ this.beginMsgSeqSend(msgId);
4474
+ }
4475
+ try {
4476
+ const body = {
4477
+ msg_type: 7,
4478
+ media: { file_info: fileInfo },
4479
+ };
4480
+ if (msgId) {
4481
+ body['msg_id'] = msgId;
4482
+ body['msg_seq'] = seq;
4483
+ }
4484
+ const resp = await sendQQMessage(route.base, route.path, this.accessToken, body);
4485
+ const errorBody = await resp.text().catch(() => '');
4486
+ if (resp.ok) {
4487
+ if (msgId)
4488
+ this.saveQQState();
4489
+ return { ok: true };
4490
+ }
4491
+ if (msgId) {
4492
+ // Conditional rollback, as in the text path: a concurrent send under
4493
+ // the same msgId may have advanced the counter past ours, and
4494
+ // restoring would forget the seq that send accepted.
4495
+ if (this.msgSeqMap.get(msgId) === seq) {
4496
+ this.msgSeqMap.set(msgId, seq - 1);
4497
+ }
4498
+ rolledBack = true;
4499
+ this.saveQQState();
4500
+ }
4501
+ process.stderr.write(`[QQ:${this.name}] ${toolName} send failed (HTTP ${resp.status}: ${sanitizeLogText(errorBody, 200)})\n`);
4502
+ // 429 is rate limiting rather than a closed reply window, so retrying
4503
+ // without the anchor would only double the pressure — the same reason
4504
+ // the text path bails instead of falling back. Without an anchor this
4505
+ // send already was the active one, so there is nothing to fall back to.
4506
+ // 304080 means the uploaded handle expired: re-sending the same
4507
+ // file_info would fail again, and the message below already tells the
4508
+ // model to call again, which re-uploads.
4509
+ if (resp.status === 429 ||
4510
+ !msgId ||
4511
+ parseQQErrorCode(errorBody) === 304080) {
4512
+ // The code is read from the whole body: a truncated copy can cut the
4513
+ // JSON and lose the error code the message is chosen from.
4514
+ return {
4515
+ ok: false,
4516
+ message: describeMediaSendFailure(resp.status, errorBody, toolName),
4517
+ };
4518
+ }
4519
+ // The anchored (passive) send was rejected. Mirror the text path's
4520
+ // active retry: the same media body without msg_id/msg_seq is an active
4521
+ // message, which outlives the reply window but needs the chat to accept
4522
+ // active messages.
4523
+ if (this.groupActiveMsgEnabled.get(chatId) === false) {
4524
+ return {
4525
+ ok: false,
4526
+ message: `${toolName}: the anchored send was rejected (HTTP ${resp.status}) and active messages are disabled for this chat, so the media cannot be sent.`,
4527
+ };
4528
+ }
4529
+ const activeResp = await sendQQMessage(route.base, route.path, this.accessToken, { msg_type: 7, media: { file_info: fileInfo } });
4530
+ const activeErrorBody = await activeResp.text().catch(() => '');
4531
+ if (activeResp.ok) {
4532
+ process.stderr.write(`[QQ:${this.name}] ${toolName} active retry succeeded for ${sanitizeLogText(chatId, 64)}\n`);
4533
+ this.saveQQState();
4534
+ return { ok: true };
4535
+ }
4536
+ process.stderr.write(`[QQ:${this.name}] ${toolName} active retry failed (HTTP ${activeResp.status}: ${sanitizeLogText(activeErrorBody, 200)})\n`);
4537
+ return {
4538
+ ok: false,
4539
+ message: describeMediaSendFailure(activeResp.status, activeErrorBody, toolName),
4540
+ };
4541
+ }
4542
+ catch (error) {
4543
+ if (msgId && !rolledBack) {
4544
+ if (this.msgSeqMap.get(msgId) === seq) {
4545
+ this.msgSeqMap.set(msgId, seq - 1);
4546
+ }
4547
+ this.saveQQState();
4548
+ }
4549
+ const message = `${toolName}: the platform call did not complete (${sanitizeLogText(error instanceof Error ? error.message : String(error), 120)}).`;
4550
+ process.stderr.write(`[QQ:${this.name}] ${message}\n`);
4551
+ return { ok: false, message };
4552
+ }
4553
+ finally {
4554
+ if (msgId)
4555
+ this.endMsgSeqSend(msgId);
4556
+ }
4557
+ }
4323
4558
  /** Single REST entry point for the moderation tools. */
4324
4559
  async requestModerationApi(input) {
4325
4560
  if (this.disposed) {