fix: avoid completed cron tail pending state

This commit is contained in:
chengyongru
2026-06-12 00:54:32 +08:00
parent e46a99ced9
commit 1ad9d77bc7
8 changed files with 223 additions and 13 deletions
+4 -9
View File
@@ -8,6 +8,7 @@ import {
normalizeToolProgressEvents,
toolTraceLinesFromEvents,
} from "@/lib/tool-traces";
import { hasPendingAgentActivity } from "@/lib/activity-timeline";
import type { StreamError } from "@/lib/nanobot-client";
import type {
InboundEvent,
@@ -450,12 +451,8 @@ export function useNanobotStream(
} {
const { client } = useClient();
const [messages, setMessages] = useState<UIMessage[]>(initialMessages);
/** If the last loaded message is a trace row (e.g. "Using 2 tools"),
* the model was still processing when the page loaded — keep the
* loading spinner alive so the user sees the model is active. */
const initialStreaming = initialMessages.length > 0
? initialMessages[initialMessages.length - 1].kind === "trace"
: false;
/** If history ends in unfinished agent activity, keep the loading spinner alive. */
const initialStreaming = hasPendingAgentActivity(initialMessages);
const [isStreaming, setIsStreaming] = useState(initialStreaming || hasPendingToolCalls);
/** Unix epoch seconds when the current user turn started; cleared on ``idle``. */
const [runStartedAt, setRunStartedAt] = useState<number | null>(null);
@@ -694,9 +691,7 @@ export function useNanobotStream(
useEffect(() => {
setMessages(initialMessages);
setIsStreaming(
(initialMessages.length > 0
? initialMessages[initialMessages.length - 1].kind === "trace"
: false) || hasPendingToolCalls,
hasPendingAgentActivity(initialMessages) || hasPendingToolCalls,
);
setStreamError(null);
setRunStartedAt(chatId ? client.getRunStartedAt(chatId) : null);