Fix live activity timer

This commit is contained in:
wuyang6
2026-05-14 18:12:11 +08:00
parent 87dd67c76a
commit 119e329dfb
2 changed files with 14 additions and 6 deletions
@@ -2014,6 +2014,7 @@ const ActivityChainSummary: FC<{
});
const initialStartedAtMs =
metadataRunStartedAtMs ?? contentRunStartedAtMs ?? messageCreatedAtMs;
const liveStartedAtRef = useRef<number | null>(initialStartedAtMs);
const [elapsedMs, setElapsedMs] = useState<number | null>(() => {
if (storedElapsedMs !== null) return storedElapsedMs;
if (initialStartedAtMs !== null) {
@@ -2041,11 +2042,14 @@ const ActivityChainSummary: FC<{
setElapsedMs(storedElapsedMs);
return;
}
const startedAt =
metadataRunStartedAtMs ??
contentRunStartedAtMs ??
messageCreatedAtMs ??
(storedElapsedMs === null ? null : Date.now() - storedElapsedMs);
const explicitStartedAt =
metadataRunStartedAtMs ?? contentRunStartedAtMs ?? messageCreatedAtMs;
if (explicitStartedAt !== null) {
liveStartedAtRef.current = explicitStartedAt;
} else if (liveStartedAtRef.current === null && storedElapsedMs !== null) {
liveStartedAtRef.current = Date.now() - storedElapsedMs;
}
const startedAt = liveStartedAtRef.current;
if (startedAt === null) {
setElapsedMs(storedElapsedMs);
return;