fix: channelId extraction, sender identification, and per-channel turn order #9

Merged
hzhang merged 18 commits from fix/turn-gate-and-handoff into main 2026-03-01 11:12:18 +00:00
Showing only changes of commit 9e754d32cf - Show all commits

View File

@@ -805,7 +805,8 @@ export default {
// Handle NO_REPLY detection before message write // Handle NO_REPLY detection before message write
// This is where we detect if agent output is NO_REPLY and handle turn advancement // This is where we detect if agent output is NO_REPLY and handle turn advancement
api.on("before_message_write", async (event, ctx) => { // NOTE: This hook is synchronous, do not use async/await
api.on("before_message_write", (event, ctx) => {
try { try {
const key = ctx.sessionKey; const key = ctx.sessionKey;
const channelId = ctx.channelId as string | undefined; const channelId = ctx.channelId as string | undefined;
@@ -859,12 +860,14 @@ export default {
return; return;
} }
// Trigger moderator handoff message // Trigger moderator handoff message (fire-and-forget, don't await)
if (live.moderatorBotToken) { if (live.moderatorBotToken) {
const nextUserId = resolveDiscordUserId(api, nextSpeaker); const nextUserId = resolveDiscordUserId(api, nextSpeaker);
if (nextUserId) { if (nextUserId) {
const handoffMsg = `轮到(<@${nextUserId}>如果没有想说的请直接回复NO_REPLY`; const handoffMsg = `轮到(<@${nextUserId}>如果没有想说的请直接回复NO_REPLY`;
sendModeratorMessage(live.moderatorBotToken, channelId, handoffMsg, api.logger); void sendModeratorMessage(live.moderatorBotToken, channelId, handoffMsg, api.logger).catch((err) => {
api.logger.warn(`whispergate: before_message_write handoff failed: ${String(err)}`);
});
} else { } else {
api.logger.warn(`whispergate: cannot resolve Discord userId for next speaker accountId=${nextSpeaker}`); api.logger.warn(`whispergate: cannot resolve Discord userId for next speaker accountId=${nextSpeaker}`);
} }