@gonzih/cc-discord 0.2.10 → 0.2.11
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/dist/bot.d.ts +4 -0
- package/dist/bot.js +31 -6
- package/package.json +1 -1
package/dist/bot.d.ts
CHANGED
|
@@ -54,6 +54,10 @@ export declare class CcDiscordBot {
|
|
|
54
54
|
loadChannelMappings(): Promise<void>;
|
|
55
55
|
/** Typing intervals for meta-agent routed channels — keyed by channelId. */
|
|
56
56
|
private metaAgentTypingTimers;
|
|
57
|
+
/** Per-channel debounce state for guild channel → meta-agent routing. */
|
|
58
|
+
private messageBuffer;
|
|
59
|
+
/** Debounce window in ms — multiple messages within this window are coalesced into one prompt. */
|
|
60
|
+
private static readonly MESSAGE_DEBOUNCE_MS;
|
|
57
61
|
/** Start (or reset) the typing indicator for a meta-agent–routed channel. */
|
|
58
62
|
private startMetaAgentTyping;
|
|
59
63
|
/** Stop the typing indicator for a meta-agent–routed channel. Called by the notifier on flush. */
|
package/dist/bot.js
CHANGED
|
@@ -227,6 +227,10 @@ export class CcDiscordBot {
|
|
|
227
227
|
}
|
|
228
228
|
/** Typing intervals for meta-agent routed channels — keyed by channelId. */
|
|
229
229
|
metaAgentTypingTimers = new Map();
|
|
230
|
+
/** Per-channel debounce state for guild channel → meta-agent routing. */
|
|
231
|
+
messageBuffer = new Map();
|
|
232
|
+
/** Debounce window in ms — multiple messages within this window are coalesced into one prompt. */
|
|
233
|
+
static MESSAGE_DEBOUNCE_MS = 2500;
|
|
230
234
|
/** Start (or reset) the typing indicator for a meta-agent–routed channel. */
|
|
231
235
|
startMetaAgentTyping(channelId, channel) {
|
|
232
236
|
this.stopMetaAgentTyping(channelId);
|
|
@@ -466,20 +470,41 @@ export class CcDiscordBot {
|
|
|
466
470
|
this.writeChatMessage("user", "discord", text, effectiveChannelId, mappedNs.namespace);
|
|
467
471
|
this.opts.registerRoutedChannelId?.(mappedNs.namespace, effectiveChannelId);
|
|
468
472
|
this.persistChannelMapping(effectiveChannelId, mappedNs.namespace, mappedNs.repoUrl);
|
|
469
|
-
|
|
470
|
-
// Detect goal messages → create a thread for loop tracking
|
|
473
|
+
// Detect goal messages → create a thread for loop tracking (before debounce so thread is created promptly)
|
|
471
474
|
if (this.loopManager && msg.guild && !msg.channel.isThread()) {
|
|
472
475
|
if (isGoalMessage(text)) {
|
|
473
476
|
await this.createLoopThread(msg, effectiveChannelId, mappedNs.namespace, text);
|
|
474
477
|
}
|
|
475
478
|
}
|
|
476
479
|
const username = msg.member?.displayName ?? msg.author.username;
|
|
477
|
-
|
|
478
|
-
|
|
480
|
+
const stamped = stampPrompt(text, username, msg.createdAt);
|
|
481
|
+
// Capture for use inside async callback (this.redis is guaranteed non-null by the outer guard)
|
|
482
|
+
const redis = this.redis;
|
|
483
|
+
const nsName = mappedNs.namespace;
|
|
484
|
+
const sendChannel = msg.channel;
|
|
485
|
+
// Debounce: buffer messages arriving within MESSAGE_DEBOUNCE_MS and route once
|
|
486
|
+
const existing = this.messageBuffer.get(effectiveChannelId);
|
|
487
|
+
if (existing) {
|
|
488
|
+
// Another message already queued — append and reset timer
|
|
489
|
+
clearTimeout(existing.timer);
|
|
490
|
+
existing.messages.push(stamped);
|
|
479
491
|
}
|
|
480
|
-
|
|
481
|
-
|
|
492
|
+
else {
|
|
493
|
+
// First message in the window — start typing indicator immediately so user sees feedback
|
|
494
|
+
this.startMetaAgentTyping(effectiveChannelId, msg.channel);
|
|
495
|
+
this.messageBuffer.set(effectiveChannelId, { timer: undefined, messages: [stamped] });
|
|
482
496
|
}
|
|
497
|
+
const buf = this.messageBuffer.get(effectiveChannelId);
|
|
498
|
+
buf.timer = setTimeout(async () => {
|
|
499
|
+
this.messageBuffer.delete(effectiveChannelId);
|
|
500
|
+
const combined = buf.messages.join('\n\n');
|
|
501
|
+
try {
|
|
502
|
+
await routeToMetaAgent(nsName, combined, redis);
|
|
503
|
+
}
|
|
504
|
+
catch (err) {
|
|
505
|
+
await sendChannel.send(`Failed to route to ${nsName}: ${err.message}`).catch(() => { });
|
|
506
|
+
}
|
|
507
|
+
}, CcDiscordBot.MESSAGE_DEBOUNCE_MS);
|
|
483
508
|
return;
|
|
484
509
|
}
|
|
485
510
|
// Unknown guild channel — reject rather than silently start a local session with wrong context
|