refactor: centralize reply dispatch

This commit is contained in:
Peter Steinberger
2026-01-06 04:55:00 +01:00
parent 319dd14e8e
commit 13eb9c9ee9
10 changed files with 90 additions and 131 deletions

View File

@@ -1,12 +1,12 @@
import { chunkText, resolveTextChunkLimit } from "../auto-reply/chunk.js";
import { hasControlCommand } from "../auto-reply/command-detection.js";
import { formatAgentEnvelope } from "../auto-reply/envelope.js";
import { dispatchReplyFromConfig } from "../auto-reply/reply/dispatch-from-config.js";
import {
buildMentionRegexes,
matchesMentionPatterns,
} from "../auto-reply/reply/mentions.js";
import { createReplyDispatcher } from "../auto-reply/reply/reply-dispatcher.js";
import { getReplyFromConfig } from "../auto-reply/reply.js";
import type { ReplyPayload } from "../auto-reply/types.js";
import { loadConfig } from "../config/config.js";
import {
@@ -285,28 +285,11 @@ export async function monitorIMessageProvider(
},
});
const replyResult = await getReplyFromConfig(
ctxPayload,
{
onToolResult: (payload) => {
dispatcher.sendToolResult(payload);
},
onBlockReply: (payload) => {
dispatcher.sendBlockReply(payload);
},
},
const { queuedFinal } = await dispatchReplyFromConfig({
ctx: ctxPayload,
cfg,
);
const replies = replyResult
? Array.isArray(replyResult)
? replyResult
: [replyResult]
: [];
let queuedFinal = false;
for (const reply of replies) {
queuedFinal = dispatcher.sendFinalReply(reply) || queuedFinal;
}
await dispatcher.waitForIdle();
dispatcher,
});
if (!queuedFinal) return;
};