Fix live activity streaming and replay summary
This commit is contained in:
@@ -56,6 +56,7 @@ type StreamState = {
|
||||
phase: "waiting" | "queued" | "running" | "done";
|
||||
runId?: string;
|
||||
announcedToolCallKeys: Set<string>;
|
||||
streamedToolCallIds: Set<string>;
|
||||
};
|
||||
|
||||
type ChatRequestBody = {
|
||||
@@ -112,6 +113,7 @@ export async function POST(req: Request) {
|
||||
textStreamed: false,
|
||||
phase: "waiting",
|
||||
announcedToolCallKeys: new Set<string>(),
|
||||
streamedToolCallIds: new Set<string>(),
|
||||
};
|
||||
writer.write({ type: "start" });
|
||||
writer.write({ type: "start-step" });
|
||||
@@ -142,7 +144,7 @@ export async function POST(req: Request) {
|
||||
delta: `\n思考并执行完成,用时 ${formatDuration(elapsedMs)}。`,
|
||||
});
|
||||
writer.write({ type: "reasoning-end", id: "reasoning-1" });
|
||||
writeToolTrace(writer, payload.transcript);
|
||||
writeToolTrace(writer, payload.transcript, streamState);
|
||||
if (!streamState.textStreamed) {
|
||||
writer.write({ type: "text-start", id: "text-1" });
|
||||
writer.write({ type: "text-delta", id: "text-1", delta: text });
|
||||
@@ -183,7 +185,13 @@ export async function POST(req: Request) {
|
||||
},
|
||||
});
|
||||
|
||||
return createUIMessageStreamResponse({ stream });
|
||||
return createUIMessageStreamResponse({
|
||||
stream,
|
||||
headers: {
|
||||
"Cache-Control": "no-cache, no-transform",
|
||||
"X-Accel-Buffering": "no",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function formatDuration(ms: number) {
|
||||
@@ -199,6 +207,7 @@ function formatDuration(ms: number) {
|
||||
function writeToolTrace(
|
||||
writer: UIMessageStreamWriter<UIMessage>,
|
||||
transcript?: ClawTranscriptEntry[],
|
||||
streamState?: StreamState,
|
||||
) {
|
||||
if (!transcript?.length) return;
|
||||
|
||||
@@ -216,6 +225,7 @@ function writeToolTrace(
|
||||
const toolCallId = call.id;
|
||||
const toolName = call.function?.name ?? call.name;
|
||||
if (!toolCallId || !toolName) continue;
|
||||
if (streamState?.streamedToolCallIds.has(toolCallId)) continue;
|
||||
|
||||
writer.write({
|
||||
type: "tool-input-available",
|
||||
@@ -539,6 +549,7 @@ function writeRuntimeEvent(
|
||||
}
|
||||
}
|
||||
if (event.type === "tool_start" && event.tool_call_id && event.tool_name) {
|
||||
streamState?.streamedToolCallIds.add(event.tool_call_id);
|
||||
writer.write({
|
||||
type: "tool-input-available",
|
||||
toolCallId: event.tool_call_id,
|
||||
|
||||
Reference in New Issue
Block a user