refactor: centralize streaming text normalization

This commit is contained in:
Peter Steinberger
2026-01-12 22:17:14 +00:00
parent f4ab057807
commit 29b7b2068a

View File

@@ -547,9 +547,9 @@ export async function runReplyAgent(params: {
const allowPartialStream = !(
followupRun.run.reasoningLevel === "stream" && opts?.onReasoningStream
);
const handlePartialForTyping = async (
const normalizeStreamingText = (
payload: ReplyPayload,
): Promise<string | undefined> => {
): string | undefined => {
if (!allowPartialStream) return undefined;
let text = payload.text;
if (!isHeartbeat && text?.includes("HEARTBEAT_OK")) {
@@ -566,6 +566,13 @@ export async function runReplyAgent(params: {
text = stripped.text;
}
if (isSilentReplyText(text, SILENT_REPLY_TOKEN)) return undefined;
return text;
};
const handlePartialForTyping = async (
payload: ReplyPayload,
): Promise<string | undefined> => {
const text = normalizeStreamingText(payload);
if (!text) return undefined;
await typingSignals.signalTextDelta(text);
return text;
};