fix(signal): add chunkDelay between separate reply payloads

Previously chunkDelay only applied between chunks of a single text
message (split by newline). When the agent sent multiple separate
reply payloads in one turn, they all fired immediately with no delay.

This adds the same delay logic to the outer reply loop, so consecutive
reply payloads also get typing indicators and natural pauses.
This commit is contained in:
Claire 2026-01-30 10:13:16 +00:00
parent 7b41d33091
commit f34ee37ef9

View File

@ -259,10 +259,23 @@ async function deliverReplies(params: {
chunkMode,
chunkDelay,
} = params;
let isFirstPayload = true;
for (const payload of replies) {
const mediaList = payload.mediaUrls ?? (payload.mediaUrl ? [payload.mediaUrl] : []);
const text = payload.text ?? "";
if (!text && mediaList.length === 0) continue;
if (!isFirstPayload && chunkDelay) {
const delayMs = computeChunkDelay(chunkDelay, (text || "").length);
if (delayMs > 0) {
try {
await sendTypingSignal(target, { baseUrl, account, accountId });
} catch {
/* typing failure is non-fatal */
}
await sleep(delayMs);
}
}
isFirstPayload = false;
if (mediaList.length === 0) {
const chunks = chunkTextWithMode(text, textLimit, chunkMode);
let isFirst = true;