feat(chat): render the live turn's thinking in the dashboard (#1907)
Reasoning frames accumulate into streamingTurn.reasoning and the live row shows them in a collapsible Thinking trace built from the components/ui trace pattern, with a spinning icon and shimmering title while no reasoning has arrived yet. A turn that produces no reasoning renders no trace, and reasoning never leaks into the reply text.
This commit is contained in:
5 files changed
+197
-4
No files matched your search
@@ -7,6 +7,7 @@ import { CodeBlockCopyButton } from "@/components/ui/code-block";
|
||||
import { Message, MessageContent, MessageFooter } from "@/components/ui/message";
|
||||
import ChatAttachment from "./ChatAttachment.vue";
|
||||
import ChatMarkdown from "./ChatMarkdown.vue";
|
||||
import ChatThinking from "./ChatThinking.vue";
|
||||
import ChatToolCall from "./ChatToolCall.vue";
|
||||
import ChatToolGroup from "./ChatToolGroup.vue";
|
||||
import type { ChatMedia, ChatToolCall as ToolCall } from "./state";
|
||||
@@ -27,8 +28,12 @@ const props = withDefaults(
|
||||
assistant?: boolean;
|
||||
/** The turn is still arriving: a tool call with no outcome is running. */
|
||||
streaming?: boolean;
|
||||
/** The live turn's thinking so far, rendered as a collapsible trace. */
|
||||
reasoning?: string;
|
||||
/** The live turn is still arriving and has not reasoned yet. */
|
||||
thinkingPending?: boolean;
|
||||
}>(),
|
||||
{ tools: () => [], media: () => [], assistant: false, streaming: false },
|
||||
{ tools: () => [], media: () => [], assistant: false, streaming: false, reasoning: "", thinkingPending: false },
|
||||
);
|
||||
|
||||
// The reply in the order it happened: text up to each call's offset, then the
|
||||
@@ -73,6 +78,11 @@ const segments = computed(() => {
|
||||
/>
|
||||
</div>
|
||||
<template v-if="assistant">
|
||||
<ChatThinking
|
||||
v-if="reasoning || thinkingPending"
|
||||
:text="reasoning"
|
||||
:pending="thinkingPending"
|
||||
/>
|
||||
<template v-for="(segment, i) in segments" :key="i">
|
||||
<ChatMarkdown v-if="'text' in segment" :text="segment.text" />
|
||||
<Trace v-else class="my-2">
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<script setup lang="ts">
|
||||
import { BrainIcon } from "@lucide/vue";
|
||||
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import {
|
||||
Trace,
|
||||
TraceCollapsible,
|
||||
TraceCollapsibleContent,
|
||||
TraceCollapsibleTrigger,
|
||||
TraceIcon,
|
||||
TraceLine,
|
||||
TraceTitle,
|
||||
} from "@/components/ui/trace";
|
||||
|
||||
/**
|
||||
* The live turn's thinking: the model's reasoning as it streams, in the same
|
||||
* collapsible trace a tool call uses. While the turn has not produced any
|
||||
* reasoning yet, the icon spins and the title shimmers; once text arrives it
|
||||
* streams into the open trace. A turn that never reasons renders nothing,
|
||||
* which the caller decides by not mounting this at all.
|
||||
*/
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
text?: string;
|
||||
/** The turn is still arriving and has not reasoned yet. */
|
||||
pending?: boolean;
|
||||
}>(),
|
||||
{ text: "", pending: false },
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Trace class="my-2">
|
||||
<TraceCollapsible default-open>
|
||||
<TraceCollapsibleTrigger>
|
||||
<TraceLine :status="pending && !text ? 'running' : undefined">
|
||||
<TraceIcon>
|
||||
<Spinner v-if="pending && !text" />
|
||||
<BrainIcon v-else />
|
||||
</TraceIcon>
|
||||
<TraceTitle>Thinking</TraceTitle>
|
||||
</TraceLine>
|
||||
</TraceCollapsibleTrigger>
|
||||
<TraceCollapsibleContent v-if="text" class="whitespace-pre-wrap [overflow-wrap:anywhere]">{{ text }}</TraceCollapsibleContent>
|
||||
</TraceCollapsible>
|
||||
</Trace>
|
||||
</template>
|
||||
@@ -63,9 +63,21 @@ const bubbles = computed(() => messages.value.map(parts));
|
||||
// the scroller sees one row grow and settle, not one leave and another arrive.
|
||||
const rows = computed(() => {
|
||||
const turn = streamingTurn.value;
|
||||
if (!turn) return bubbles.value.map((bubble) => ({ ...bubble, live: false }));
|
||||
if (!turn) {
|
||||
return bubbles.value.map((bubble) => ({
|
||||
...bubble,
|
||||
live: false,
|
||||
reasoning: "",
|
||||
thinkingPending: false,
|
||||
}));
|
||||
}
|
||||
return [
|
||||
...bubbles.value.map((bubble) => ({ ...bubble, live: false })),
|
||||
...bubbles.value.map((bubble) => ({
|
||||
...bubble,
|
||||
live: false,
|
||||
reasoning: "",
|
||||
thinkingPending: false,
|
||||
})),
|
||||
{
|
||||
id: `m${bubbles.value.length}`,
|
||||
text: turn.text || "…",
|
||||
@@ -75,6 +87,11 @@ const rows = computed(() => {
|
||||
update: undefined,
|
||||
choose: undefined,
|
||||
live: true,
|
||||
reasoning: turn.reasoning ?? "",
|
||||
// Nothing said and nothing reasoned yet: the turn may still be thinking,
|
||||
// so the row shows the pending thinking trace. Once the answer's text
|
||||
// arrives without any reasoning, the trace is not rendered at all.
|
||||
thinkingPending: !turn.text && !(turn.reasoning ?? ""),
|
||||
},
|
||||
];
|
||||
});
|
||||
@@ -120,6 +137,8 @@ useLiveResource("chat", () => void reloadTranscript());
|
||||
:media="row.media"
|
||||
:assistant="row.assistant"
|
||||
:streaming="row.live"
|
||||
:reasoning="row.reasoning"
|
||||
:thinking-pending="row.thinkingPending"
|
||||
>
|
||||
<template v-if="row.live && streamingTurn">
|
||||
<Button
|
||||
|
||||
+15
-1
@@ -124,6 +124,8 @@ export interface StreamingTurn {
|
||||
isError: boolean;
|
||||
turn?: ChatTurn;
|
||||
isRetry: boolean;
|
||||
/** The model's thinking so far, streamed on `reasoning` frames. */
|
||||
reasoning?: string;
|
||||
/** A question the turn waits on until the operator answers it. */
|
||||
ask?: ChatAsk;
|
||||
}
|
||||
@@ -731,10 +733,11 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
|
||||
}
|
||||
|
||||
let activeTools: ChatToolCall[] = [];
|
||||
streamingTurn.value = { text: "", tools: [], isError: false, turn, isRetry };
|
||||
streamingTurn.value = { text: "", tools: [], isError: false, turn, isRetry, reasoning: "" };
|
||||
askError.value = "";
|
||||
|
||||
let streamedText = "";
|
||||
let streamedReasoning = "";
|
||||
let finished = false;
|
||||
let timedOut = false;
|
||||
let detached = false;
|
||||
@@ -806,6 +809,15 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
|
||||
? { ...streamingTurn.value, text: streamedText }
|
||||
: null;
|
||||
}
|
||||
// The model's thinking streams ahead of the answer on its own frame
|
||||
// kind; it accumulates like the text, but renders as the live turn's
|
||||
// thinking trace rather than as reply text.
|
||||
if (event.type === "reasoning") {
|
||||
streamedReasoning += event.text;
|
||||
streamingTurn.value = streamingTurn.value
|
||||
? { ...streamingTurn.value, reasoning: streamedReasoning }
|
||||
: null;
|
||||
}
|
||||
// A navigate result is appended to the same list as the tool calls: it
|
||||
// is one more thing the turn did, and it renders as a chip rather than
|
||||
// a tool line.
|
||||
@@ -873,6 +885,7 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
|
||||
isError: false,
|
||||
turn,
|
||||
isRetry,
|
||||
reasoning: streamedReasoning,
|
||||
};
|
||||
statusText.value = "Stopped";
|
||||
} else {
|
||||
@@ -886,6 +899,7 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise<void> {
|
||||
isError: true,
|
||||
turn: turn ? retryChatTurn(turn) : undefined,
|
||||
isRetry,
|
||||
reasoning: streamedReasoning,
|
||||
};
|
||||
statusText.value = "Error. Retry available.";
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user