* Reasoning trace from the model. While streaming, shows a shimmer * "Thinking…" header with the latest line as a one-line preview. * When complete, becomes a click-to-expand "Thought" disclosure.
({
text,
complete,
}: {
text: string;
complete: boolean;
})
| 154 | * When complete, becomes a click-to-expand "Thought" disclosure. |
| 155 | */ |
| 156 | function ReasoningBlock({ |
| 157 | text, |
| 158 | complete, |
| 159 | }: { |
| 160 | text: string; |
| 161 | complete: boolean; |
| 162 | }) { |
| 163 | const [open, setOpen] = useState(false); |
| 164 | const trimmed = text.trim(); |
| 165 | // Latest non-empty line for the live preview. |
| 166 | const latestLine = |
| 167 | trimmed |
| 168 | .split('\n') |
| 169 | .map((l) => l.trim()) |
| 170 | .filter(Boolean) |
| 171 | .pop() ?? ''; |
| 172 | |
| 173 | if (!complete) { |
| 174 | return ( |
| 175 | <div className="w-full max-w-full"> |
| 176 | <div className="flex items-center gap-2 text-sm"> |
| 177 | <span className="op-shimmer font-medium">Thinking…</span> |
| 178 | </div> |
| 179 | {latestLine && ( |
| 180 | <div className="mt-1 text-sm text-muted-foreground/80 italic line-clamp-1"> |
| 181 | {latestLine} |
| 182 | </div> |
| 183 | )} |
| 184 | </div> |
| 185 | ); |
| 186 | } |
| 187 | |
| 188 | return ( |
| 189 | <div className="w-full max-w-full mb-2"> |
| 190 | <button |
| 191 | type="button" |
| 192 | onClick={() => setOpen((v) => !v)} |
| 193 | className="flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors" |
| 194 | > |
| 195 | <ChevronRightIcon |
| 196 | className={cn('size-3 transition-transform', open && 'rotate-90')} |
| 197 | /> |
| 198 | <span>Thought</span> |
| 199 | </button> |
| 200 | {open && ( |
| 201 | <div className="mt-2"> |
| 202 | <ChatMarkdown |
| 203 | text={trimmed} |
| 204 | className="text-sm text-muted-foreground leading-normal" |
| 205 | /> |
| 206 | </div> |
| 207 | )} |
| 208 | </div> |
| 209 | ); |
| 210 | } |
| 211 | |
| 212 | function derivePartState( |
| 213 | callState: string | undefined, |