Stream assistant content to chat output

This commit is contained in:
wuyang6
2026-05-14 20:06:55 +08:00
parent 2eeabdeccf
commit 2895425869
3 changed files with 6 additions and 53 deletions
@@ -647,18 +647,7 @@ function buildActiveRunParts(runStatus: ClawActiveRunStatus) {
function summarizeRunEvents(runStatus: ClawActiveRunStatus) {
const lines: string[] = [];
let contentBuffer = "";
const flushContentBuffer = () => {
const preview = compactLiveContentDelta(contentBuffer);
contentBuffer = "";
if (preview) lines.push(`输出:${preview}`);
};
for (const event of runStatus.events ?? []) {
if (event.type === "content_delta") {
contentBuffer += event.delta ?? "";
continue;
}
flushContentBuffer();
if (event.type === "run_queued") {
lines.push("当前会话已有任务在执行,本轮正在排队。");
}
@@ -690,25 +679,12 @@ function summarizeRunEvents(runStatus: ClawActiveRunStatus) {
lines.push("等待用户 review");
}
}
flushContentBuffer();
if (runStatus.current_stage && lines.at(-1) !== runStatus.current_stage) {
lines.push(runStatus.current_stage);
}
return lines.slice(-40);
}
function isNoisyLiveDelta(value: string) {
return value === "。" || value === "" || value === "," || value.length <= 1;
}
function compactLiveContentDelta(value: string) {
const normalized = value.replace(/\s+/g, " ").trim();
if (!normalized || isNoisyLiveDelta(normalized)) return "";
return normalized.length <= 36
? normalized
: `${normalized.slice(Math.max(0, normalized.length - 35))}`;
}
function buildRunToolParts(events: readonly ClawRunEvent[]) {
const resultById = new Map<string, ClawRunEvent>();
for (const event of events) {