Show live content deltas in activity
This commit is contained in:
@@ -984,7 +984,18 @@ function summarizeLiveRunEvents(
|
|||||||
events: readonly LiveRunEvent[],
|
events: readonly LiveRunEvent[],
|
||||||
) {
|
) {
|
||||||
const lines: string[] = [];
|
const lines: string[] = [];
|
||||||
|
let contentBuffer = "";
|
||||||
|
const flushContentBuffer = () => {
|
||||||
|
const preview = compactLiveContentDelta(contentBuffer);
|
||||||
|
contentBuffer = "";
|
||||||
|
if (preview) lines.push(`输出:${preview}`);
|
||||||
|
};
|
||||||
for (const event of events) {
|
for (const event of events) {
|
||||||
|
if (event.type === "content_delta") {
|
||||||
|
contentBuffer += event.delta ?? "";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
flushContentBuffer();
|
||||||
if (event.type === "run_queued") {
|
if (event.type === "run_queued") {
|
||||||
lines.push("当前会话已有任务在执行,本轮正在排队。");
|
lines.push("当前会话已有任务在执行,本轮正在排队。");
|
||||||
}
|
}
|
||||||
@@ -1013,6 +1024,7 @@ function summarizeLiveRunEvents(
|
|||||||
lines.push("正在整理回复");
|
lines.push("正在整理回复");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
flushContentBuffer();
|
||||||
if (runStatus.current_stage && lines.at(-1) !== runStatus.current_stage) {
|
if (runStatus.current_stage && lines.at(-1) !== runStatus.current_stage) {
|
||||||
lines.push(runStatus.current_stage);
|
lines.push(runStatus.current_stage);
|
||||||
}
|
}
|
||||||
@@ -1030,6 +1042,14 @@ function isNoisyLiveDelta(value: string) {
|
|||||||
return value === "。" || value === "," || value === "," || value.length <= 1;
|
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 collectActivityItems(messages: readonly MessageState[]) {
|
function collectActivityItems(messages: readonly MessageState[]) {
|
||||||
const items: ActivityItem[] = [];
|
const items: ActivityItem[] = [];
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ import {
|
|||||||
readActiveSessionId,
|
readActiveSessionId,
|
||||||
writeActiveSessionId,
|
writeActiveSessionId,
|
||||||
} from "@/lib/claw-active-session";
|
} from "@/lib/claw-active-session";
|
||||||
import { pushHomeUrl, pushSessionUrl } from "@/lib/claw-session-url";
|
|
||||||
import { useClawSessionReplay } from "@/lib/claw-session-replay";
|
import { useClawSessionReplay } from "@/lib/claw-session-replay";
|
||||||
|
import { pushHomeUrl, pushSessionUrl } from "@/lib/claw-session-url";
|
||||||
|
|
||||||
type ClawSession = {
|
type ClawSession = {
|
||||||
session_id: string;
|
session_id: string;
|
||||||
@@ -647,7 +647,18 @@ function buildActiveRunParts(runStatus: ClawActiveRunStatus) {
|
|||||||
|
|
||||||
function summarizeRunEvents(runStatus: ClawActiveRunStatus) {
|
function summarizeRunEvents(runStatus: ClawActiveRunStatus) {
|
||||||
const lines: string[] = [];
|
const lines: string[] = [];
|
||||||
|
let contentBuffer = "";
|
||||||
|
const flushContentBuffer = () => {
|
||||||
|
const preview = compactLiveContentDelta(contentBuffer);
|
||||||
|
contentBuffer = "";
|
||||||
|
if (preview) lines.push(`输出:${preview}`);
|
||||||
|
};
|
||||||
for (const event of runStatus.events ?? []) {
|
for (const event of runStatus.events ?? []) {
|
||||||
|
if (event.type === "content_delta") {
|
||||||
|
contentBuffer += event.delta ?? "";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
flushContentBuffer();
|
||||||
if (event.type === "run_queued") {
|
if (event.type === "run_queued") {
|
||||||
lines.push("当前会话已有任务在执行,本轮正在排队。");
|
lines.push("当前会话已有任务在执行,本轮正在排队。");
|
||||||
}
|
}
|
||||||
@@ -679,6 +690,7 @@ function summarizeRunEvents(runStatus: ClawActiveRunStatus) {
|
|||||||
lines.push("等待用户 review");
|
lines.push("等待用户 review");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
flushContentBuffer();
|
||||||
if (runStatus.current_stage && lines.at(-1) !== runStatus.current_stage) {
|
if (runStatus.current_stage && lines.at(-1) !== runStatus.current_stage) {
|
||||||
lines.push(runStatus.current_stage);
|
lines.push(runStatus.current_stage);
|
||||||
}
|
}
|
||||||
@@ -689,6 +701,14 @@ function isNoisyLiveDelta(value: string) {
|
|||||||
return value === "。" || value === "," || value === "," || value.length <= 1;
|
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[]) {
|
function buildRunToolParts(events: readonly ClawRunEvent[]) {
|
||||||
const resultById = new Map<string, ClawRunEvent>();
|
const resultById = new Map<string, ClawRunEvent>();
|
||||||
for (const event of events) {
|
for (const event of events) {
|
||||||
|
|||||||
Reference in New Issue
Block a user