@qwen-code/channel-base 0.26.8 → 0.26.9-nightly.20261107.65e1f1aeaa
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.md +9 -8
- package/dist/AcpBridge.d.ts.map +1 -1
- package/dist/AcpBridge.js +19 -2
- package/dist/AcpBridge.js.map +1 -1
- package/dist/ChannelAgentBridge.d.ts +3 -0
- package/dist/ChannelAgentBridge.d.ts.map +1 -1
- package/dist/ChannelAgentBridge.js +4 -0
- package/dist/ChannelAgentBridge.js.map +1 -1
- package/dist/ChannelBase.d.ts +38 -2
- package/dist/ChannelBase.d.ts.map +1 -1
- package/dist/ChannelBase.js +75 -2
- package/dist/ChannelBase.js.map +1 -1
- package/dist/DaemonChannelBridge.d.ts.map +1 -1
- package/dist/DaemonChannelBridge.js +18 -2
- package/dist/DaemonChannelBridge.js.map +1 -1
- package/dist/GroupGate.d.ts +6 -0
- package/dist/GroupGate.d.ts.map +1 -1
- package/dist/GroupGate.js +16 -0
- package/dist/GroupGate.js.map +1 -1
- package/dist/PollingChannelBase.d.ts.map +1 -1
- package/dist/PollingChannelBase.js +7 -1
- package/dist/PollingChannelBase.js.map +1 -1
- package/dist/bound-session-prompt.d.ts +146 -0
- package/dist/bound-session-prompt.d.ts.map +1 -0
- package/dist/bound-session-prompt.js +200 -0
- package/dist/bound-session-prompt.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/ChannelBase.js
CHANGED
|
@@ -2122,6 +2122,16 @@ export class ChannelBase {
|
|
|
2122
2122
|
getResponseSourceLabel(sessionId) {
|
|
2123
2123
|
return this.activePrompts.get(sessionId)?.sourceLabel;
|
|
2124
2124
|
}
|
|
2125
|
+
/**
|
|
2126
|
+
* True while the session's live turn is an unattended one (loop or webhook
|
|
2127
|
+
* task). Base delivers such a turn once, in full, through pushProactive and
|
|
2128
|
+
* never calls onResponseComplete, so an adapter whose sink flushes streamed
|
|
2129
|
+
* chunks would post the same text twice. Adapters without an inbound anchor
|
|
2130
|
+
* (QQ) gate on this; the base chunk bookkeeping still runs either way.
|
|
2131
|
+
*/
|
|
2132
|
+
isProactivePromptTurn(sessionId) {
|
|
2133
|
+
return this.activePrompts.get(sessionId)?.loopPrompt === true;
|
|
2134
|
+
}
|
|
2125
2135
|
getInboundErrorSourceLabel(envelope) {
|
|
2126
2136
|
return this.inboundErrorSourceLabels.get(envelope);
|
|
2127
2137
|
}
|
|
@@ -3316,6 +3326,25 @@ export class ChannelBase {
|
|
|
3316
3326
|
}
|
|
3317
3327
|
return `Loop ${job.id}: ${job.cron}`;
|
|
3318
3328
|
}
|
|
3329
|
+
/**
|
|
3330
|
+
* Disable every enabled loop in a chat. Adapters call this when the chat can
|
|
3331
|
+
* no longer receive proactive messages (the bot was removed from a group, or
|
|
3332
|
+
* a group's active messages were disabled), so orphaned loops stop burning
|
|
3333
|
+
* unattended turns. Needs the chat-scoped controller lookup; returns how many
|
|
3334
|
+
* jobs were disabled.
|
|
3335
|
+
*/
|
|
3336
|
+
async disableLoopJobsForChat(chatId) {
|
|
3337
|
+
if (!this.loopController?.listForChat)
|
|
3338
|
+
return 0;
|
|
3339
|
+
const jobs = await this.loopController.listForChat(this.name, chatId);
|
|
3340
|
+
let disabled = 0;
|
|
3341
|
+
for (const job of jobs) {
|
|
3342
|
+
if (job.enabled && (await this.loopController.disable(job.id))) {
|
|
3343
|
+
disabled++;
|
|
3344
|
+
}
|
|
3345
|
+
}
|
|
3346
|
+
return disabled;
|
|
3347
|
+
}
|
|
3319
3348
|
async listLoopsFromTool(sessionId) {
|
|
3320
3349
|
if (!this.loopController) {
|
|
3321
3350
|
return { text: 'Channel loops are not configured.', isError: true };
|
|
@@ -4397,7 +4426,9 @@ export class ChannelBase {
|
|
|
4397
4426
|
const deferredGroupPairing = options.deferPairingRequests === true &&
|
|
4398
4427
|
groupResult.reason === 'pairing_trigger_required' &&
|
|
4399
4428
|
(envelope.isMentioned || envelope.isReplyToBot);
|
|
4400
|
-
|
|
4429
|
+
const waivedGroupMention = options.waiveGroupMention === true &&
|
|
4430
|
+
groupResult.reason === 'mention_required';
|
|
4431
|
+
if (!groupResult.allowed && !deferredGroupPairing && !waivedGroupMention) {
|
|
4401
4432
|
if (groupResult.pairing !== undefined) {
|
|
4402
4433
|
this.logPreflightRejected('group_pairing_required', envelope);
|
|
4403
4434
|
return this.onGroupPairingRequired(envelope.chatId, groupResult.pairing, envelope.threadId)
|
|
@@ -4685,6 +4716,14 @@ export class ChannelBase {
|
|
|
4685
4716
|
markPreflighted(envelope) {
|
|
4686
4717
|
this.preflightedEnvelopes.add(envelope);
|
|
4687
4718
|
}
|
|
4719
|
+
/**
|
|
4720
|
+
* Whether a message with this text passes the channel's message routes the
|
|
4721
|
+
* way preflight would route it. Has no side effects.
|
|
4722
|
+
*/
|
|
4723
|
+
admitsMessageRoute(text) {
|
|
4724
|
+
return (this.messageRoutes.size === 0 ||
|
|
4725
|
+
matchMessageRoute(text, this.messageRoutes, this.config.defaultMessageRoute) !== undefined);
|
|
4726
|
+
}
|
|
4688
4727
|
applyMessageRoute(envelope) {
|
|
4689
4728
|
if (this.routedEnvelopes.has(envelope))
|
|
4690
4729
|
return true;
|
|
@@ -5306,14 +5345,21 @@ export class ChannelBase {
|
|
|
5306
5345
|
// bridge only after the latest recovery has restored session routing.
|
|
5307
5346
|
await this.waitForBridgeRecovery();
|
|
5308
5347
|
const promptBridge = this.bridge;
|
|
5348
|
+
let turnNotice = '';
|
|
5349
|
+
const onTurnNotice = (sid, notice) => {
|
|
5350
|
+
if (sid === sessionId)
|
|
5351
|
+
turnNotice = notice;
|
|
5352
|
+
};
|
|
5309
5353
|
promptBridge.on('textChunk', onChunk);
|
|
5354
|
+
promptBridge.on('turnNotice', onTurnNotice);
|
|
5310
5355
|
promptBridge.on('responseBoundary', onResponseBoundary);
|
|
5311
5356
|
let taskResultPartial = false;
|
|
5357
|
+
let answerDelivered = false;
|
|
5312
5358
|
try {
|
|
5313
5359
|
if (!this.canStartInboundTurn()) {
|
|
5314
5360
|
throw new ChannelPromptCancelledError();
|
|
5315
5361
|
}
|
|
5316
|
-
|
|
5362
|
+
let response = await promptBridge.prompt(sessionId, promptToSend, {
|
|
5317
5363
|
...(this.config.outputMode === 'per_task'
|
|
5318
5364
|
? {
|
|
5319
5365
|
outputMode: 'per_task',
|
|
@@ -5336,14 +5382,40 @@ export class ChannelBase {
|
|
|
5336
5382
|
// If cancelled, skip sending the response
|
|
5337
5383
|
if (!promptState.cancelled && response) {
|
|
5338
5384
|
promptState.deliveryStarted = true;
|
|
5385
|
+
if (turnNotice) {
|
|
5386
|
+
response = response.slice(turnNotice.length + 2);
|
|
5387
|
+
}
|
|
5388
|
+
}
|
|
5389
|
+
if (!promptState.cancelled && response) {
|
|
5339
5390
|
const segment = this.ensureOutputSegment(sessionId, promptState);
|
|
5340
5391
|
if (segment && taskResultPartial)
|
|
5341
5392
|
segment.partial = true;
|
|
5342
5393
|
await this.onResponseComplete(envelope.chatId, response, sessionId, segment);
|
|
5394
|
+
answerDelivered = true;
|
|
5343
5395
|
if (segment && promptState.activeSegmentId === segment.segmentId) {
|
|
5344
5396
|
promptState.activeSegmentId = undefined;
|
|
5345
5397
|
}
|
|
5346
5398
|
}
|
|
5399
|
+
if (!promptState.cancelled && turnNotice) {
|
|
5400
|
+
// Keep notices out of stream buffers and let the answer consume
|
|
5401
|
+
// adapter-specific reply metadata (such as DingTalk mentions) first.
|
|
5402
|
+
try {
|
|
5403
|
+
await this.sendResponseMessage(envelope.chatId, turnNotice, sessionId, sourceLabel);
|
|
5404
|
+
}
|
|
5405
|
+
catch (err) {
|
|
5406
|
+
// The prompt result is `turnNotice || body`, so on an empty body
|
|
5407
|
+
// the notice is the turn's only delivery: rethrow instead of
|
|
5408
|
+
// reporting a completed turn the user never received.
|
|
5409
|
+
if (!answerDelivered)
|
|
5410
|
+
throw err;
|
|
5411
|
+
// The answer is already delivered, so the turn's outcome is fixed
|
|
5412
|
+
// (see the deliveryStarted invariant below): log the failed
|
|
5413
|
+
// notice instead of letting it rewrite completed into failed.
|
|
5414
|
+
// The notice was sliced out of the answer above, so this line is
|
|
5415
|
+
// the only remaining record of what the user never received.
|
|
5416
|
+
process.stderr.write(`[${this.name}] turn notice delivery failed for session ${sanitizeLogText(sessionId, 128)}: ${this.lifecycleError(err)} (dropped notice: ${sanitizeLogText(turnNotice, 200)})\n`);
|
|
5417
|
+
}
|
|
5418
|
+
}
|
|
5347
5419
|
// Once delivery started the turn's outcome is fixed — don't let a
|
|
5348
5420
|
// cancel settling during the send rewrite completed into cancelled.
|
|
5349
5421
|
if (!promptState.deliveryStarted) {
|
|
@@ -5397,6 +5469,7 @@ export class ChannelBase {
|
|
|
5397
5469
|
}
|
|
5398
5470
|
finally {
|
|
5399
5471
|
promptBridge.off('textChunk', onChunk);
|
|
5472
|
+
promptBridge.off('turnNotice', onTurnNotice);
|
|
5400
5473
|
promptBridge.off('responseBoundary', onResponseBoundary);
|
|
5401
5474
|
// Identity guard: a turn that wedged past /clear's bounded wait gets
|
|
5402
5475
|
// EVICTED — /clear gives up on active.done, deletes activePrompts, and a
|