refactor(agents): reuse embedded block flush helper

This commit is contained in:
Peter Steinberger
2026-02-18 18:54:15 +00:00
parent fa5902f210
commit e1419f3a02
2 changed files with 2 additions and 16 deletions

View File

@@ -67,15 +67,7 @@ export function handleAgentEnd(ctx: EmbeddedPiSubscribeContext) {
});
}
if (ctx.params.onBlockReply) {
if (ctx.blockChunker?.hasBuffered()) {
ctx.blockChunker.drain({ force: true, emit: ctx.emitBlockChunk });
ctx.blockChunker.reset();
} else if (ctx.state.blockBuffer.length > 0) {
ctx.emitBlockChunk(ctx.state.blockBuffer);
ctx.state.blockBuffer = "";
}
}
ctx.flushBlockReplyBuffer();
ctx.state.blockState.thinking = false;
ctx.state.blockState.final = false;

View File

@@ -201,13 +201,7 @@ export function handleMessageUpdate(
}
if (evtType === "text_end" && ctx.state.blockReplyBreak === "text_end") {
if (ctx.blockChunker?.hasBuffered()) {
ctx.blockChunker.drain({ force: true, emit: ctx.emitBlockChunk });
ctx.blockChunker.reset();
} else if (ctx.state.blockBuffer.length > 0) {
ctx.emitBlockChunk(ctx.state.blockBuffer);
ctx.state.blockBuffer = "";
}
ctx.flushBlockReplyBuffer();
}
}