Fix live activity streaming and replay summary

This commit is contained in:
wuyang6
2026-05-13 20:58:35 +08:00
parent 0eb57f3f42
commit d7c62a4929
4 changed files with 59 additions and 4 deletions
@@ -86,6 +86,7 @@ type ClawRunEvent = {
tool_call_id?: string;
arguments?: unknown;
assistant_content?: string;
delta?: string;
ok?: boolean;
metadata?: {
output_preview?: unknown;
@@ -430,7 +431,12 @@ export function toReplayRepository(
? shouldShowAssistantText
? [...toolParts, { type: "text", text: content }]
: toolParts
: [{ type: "text", text: content }]
: message.role === "assistant" && elapsedMs !== undefined
? [
{ type: "reasoning", text: "思考并执行完成。", elapsedMs },
{ type: "text", text: content },
]
: [{ type: "text", text: content }]
) as UIMessage["parts"];
const replayParts = withReplayElapsedMs(parts, elapsedMs);
const uiMessage: UIMessage = {
@@ -599,6 +605,10 @@ function summarizeRunEvents(runStatus: ClawActiveRunStatus) {
if (event.type === "run_started") {
lines.push("后端已开始执行本轮任务。");
}
if (event.type === "content_delta" && event.delta) {
const note = event.delta.trim();
if (note && !isNoisyLiveDelta(note)) lines.push(note);
}
if (event.type === "tool_start") {
const stageNote =
typeof event.assistant_content === "string"
@@ -614,6 +624,9 @@ function summarizeRunEvents(runStatus: ClawActiveRunStatus) {
event.tool_name ? `工具完成 ${event.tool_name}` : "工具调用完成",
);
}
if (event.type === "tool_delta") {
lines.push(event.tool_name ? `${event.tool_name} 输出中` : "工具输出中");
}
if (event.type === "final_text_start") {
lines.push("正在整理回复");
}
@@ -627,6 +640,10 @@ function summarizeRunEvents(runStatus: ClawActiveRunStatus) {
return lines.slice(-40);
}
function isNoisyLiveDelta(value: string) {
return value === "。" || value === "" || value === "," || value.length <= 1;
}
function buildRunToolParts(events: readonly ClawRunEvent[]) {
const resultById = new Map<string, ClawRunEvent>();
for (const event of events) {