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:
parent
7b41d33091
commit
f34ee37ef9
@ -259,10 +259,23 @@ async function deliverReplies(params: {
|
|||||||
chunkMode,
|
chunkMode,
|
||||||
chunkDelay,
|
chunkDelay,
|
||||||
} = params;
|
} = params;
|
||||||
|
let isFirstPayload = true;
|
||||||
for (const payload of replies) {
|
for (const payload of replies) {
|
||||||
const mediaList = payload.mediaUrls ?? (payload.mediaUrl ? [payload.mediaUrl] : []);
|
const mediaList = payload.mediaUrls ?? (payload.mediaUrl ? [payload.mediaUrl] : []);
|
||||||
const text = payload.text ?? "";
|
const text = payload.text ?? "";
|
||||||
if (!text && mediaList.length === 0) continue;
|
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) {
|
if (mediaList.length === 0) {
|
||||||
const chunks = chunkTextWithMode(text, textLimit, chunkMode);
|
const chunks = chunkTextWithMode(text, textLimit, chunkMode);
|
||||||
let isFirst = true;
|
let isFirst = true;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user