Preserve elapsed time in replay activity parts
This commit is contained in:
@@ -442,7 +442,7 @@ export function toReplayRepository(
|
||||
id,
|
||||
role: message.role,
|
||||
createdAt: new Date(),
|
||||
content: toThreadMessageContent(parts),
|
||||
content: toThreadMessageContent(parts, elapsedMs),
|
||||
...(message.role === "assistant"
|
||||
? {
|
||||
status: { type: "complete", reason: "stop" },
|
||||
@@ -797,9 +797,11 @@ function attachStageNote(input: unknown, stageNote?: string) {
|
||||
return { value: input, __claw_stage_note: note };
|
||||
}
|
||||
|
||||
function toThreadMessageContent(parts: UIMessage["parts"]) {
|
||||
function toThreadMessageContent(parts: UIMessage["parts"], elapsedMs?: number) {
|
||||
return parts.map((part) => {
|
||||
if (part.type === "text" || part.type === "reasoning") return part;
|
||||
const elapsedPayload = elapsedMs === undefined ? {} : { elapsedMs };
|
||||
if (part.type === "text") return part;
|
||||
if (part.type === "reasoning") return { ...part, ...elapsedPayload };
|
||||
if (part.type === "dynamic-tool") {
|
||||
return {
|
||||
type: "tool-call",
|
||||
@@ -807,6 +809,7 @@ function toThreadMessageContent(parts: UIMessage["parts"]) {
|
||||
toolCallId: part.toolCallId,
|
||||
args: part.input ?? {},
|
||||
argsText: JSON.stringify(part.input ?? {}),
|
||||
...elapsedPayload,
|
||||
...(part.state === "output-available" ? { result: part.output } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1316,6 +1316,13 @@ const ActivityChainSummary: FC<{
|
||||
);
|
||||
const storedElapsedMs = useAuiState((s) => {
|
||||
const value = readMetadataValue(s.message.metadata, "elapsedMs");
|
||||
const contentValue = findNumberInActivityParts(
|
||||
s.message.content,
|
||||
"elapsedMs",
|
||||
);
|
||||
if (typeof value !== "number" || !Number.isFinite(value)) {
|
||||
return contentValue;
|
||||
}
|
||||
return typeof value === "number" && Number.isFinite(value)
|
||||
? Math.max(0, Math.round(value))
|
||||
: null;
|
||||
@@ -1376,6 +1383,7 @@ type ActivitySummaryPart = {
|
||||
args?: unknown;
|
||||
toolName?: string;
|
||||
runStartedAtMs?: unknown;
|
||||
elapsedMs?: unknown;
|
||||
};
|
||||
|
||||
function findNumberInActivityParts(
|
||||
|
||||
Reference in New Issue
Block a user