fix(webui): update usage and tool progress during active turns (#6553)
* fix(webui): stream model status and usage during active turns * fix(webui): keep live rounds and active-run status consistent * fix(webui): reuse existing run indicators without extra status text * fix(webui): preserve live activity and batch durable delivery Cancel and drain sibling tools when progress notifications fail, retain balanced checkpoints, and keep model telemetry separate from answer provenance. Group-commit already queued activity at the channel delivery boundary while preserving FIFO, generation ownership, per-envelope admission, and commit-before-fanout semantics. Isolate invalid members without dropping valid neighboring events. Retain tool detail lazy grouping and cover scheduling, cancellation, persistence, encoding failures, and projection regressions. * test(webui): separate standard-library imports in batch regression * test: tighten live execution checks and clarify contracts * refactor: remove redundant live execution comments * refactor: settle tool results through one output path
This commit is contained in:
1 parent
006a535537
commit
8ff04aad2b
52 files changed
+2065
-211
No files matched your search
@@ -36,6 +36,7 @@ import type {
|
||||
RetryStatus,
|
||||
UIMediaAttachment,
|
||||
UIMessage,
|
||||
UIModelRequestSnapshot,
|
||||
WorkspaceScopePayload,
|
||||
} from "@/lib/types";
|
||||
|
||||
@@ -147,6 +148,7 @@ export function useNanobotStream(
|
||||
historyActiveTurnId: string | null = null,
|
||||
): {
|
||||
messages: UIMessage[];
|
||||
modelRequests: ReadonlyMap<string, UIModelRequestSnapshot>;
|
||||
/** Conversation owning these messages, including while a selection is handing over. */
|
||||
messagesKey: string | null;
|
||||
/** Whether ``messages`` belongs to the current ``chatId`` after a session switch. */
|
||||
@@ -197,6 +199,7 @@ export function useNanobotStream(
|
||||
historyRunGenerationRef.current = { chatId, generation: chatId ? client.getRunGeneration(chatId) : 0 };
|
||||
}
|
||||
const [messages, setRenderedMessages] = useState<UIMessage[]>(initialTranscript.messages);
|
||||
const [modelRequests, setModelRequests] = useState(initialTranscript.modelRequests);
|
||||
const messagesRef = useRef(messages);
|
||||
// Keep received state ahead of React's batched render: navigation can unmount
|
||||
// this hook after a stream flush but before the queued render commits.
|
||||
@@ -205,6 +208,7 @@ export function useNanobotStream(
|
||||
messagesRef.current = next;
|
||||
transcriptRef.current.projection = { ...transcriptRef.current.projection, messages: next };
|
||||
setRenderedMessages(next);
|
||||
setModelRequests(transcriptRef.current.modelRequests);
|
||||
setHistoryState(transcriptRef.current.paging);
|
||||
}, []);
|
||||
const [messageScope, setMessageScope] = useState({ chatId, historyKey, client });
|
||||
@@ -717,6 +721,11 @@ export function useNanobotStream(
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (ev.event === "model_request") {
|
||||
flushPendingStreamEvents();
|
||||
applyProjectionEvent(ev);
|
||||
return;
|
||||
}
|
||||
const sideChannelEvent = isSideChannelEvent(ev);
|
||||
if (ev.event === "context_compaction") {
|
||||
flushPendingStreamEvents();
|
||||
@@ -1042,8 +1051,11 @@ export function useNanobotStream(
|
||||
flushPendingStreamEvents();
|
||||
setRetryStatus(null);
|
||||
setMessages((prev) => {
|
||||
const settled = prev.map((m) => (m.isStreaming ? { ...m, isStreaming: false } : m));
|
||||
transcriptRef.current.projection = resetThreadProjectionCursor(transcriptRef.current.projection, settled);
|
||||
const settled = prev.map((m) => ({ ...m, isStreaming: false }));
|
||||
const projection = resetThreadProjectionCursor(transcriptRef.current.projection, settled);
|
||||
const modelRequests = new Map(projection.modelRequests);
|
||||
for (const [turn, snapshot] of modelRequests) modelRequests.set(turn, { ...snapshot, ended: true });
|
||||
transcriptRef.current.projection = { ...projection, modelRequests };
|
||||
return settled;
|
||||
});
|
||||
client.finishRunLocally(chatId);
|
||||
@@ -1075,6 +1087,7 @@ export function useNanobotStream(
|
||||
|
||||
return {
|
||||
messages,
|
||||
modelRequests,
|
||||
messagesKey: messageScope.historyKey ?? messageScope.chatId,
|
||||
messagesReady: messageScope.chatId === chatId && messageScope.historyKey === historyKey && messageScope.client === client,
|
||||
isStreaming,
|
||||
|
||||
Reference in new issue
Block a user