File size: 1,418 Bytes
f672a5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { useRef, useState } from "react";
import { Brain, ChevronDown } from "lucide-react";

interface ReasoningBlockProps {
  reasoning: string;
  isThinking: boolean;
  thinkingSeconds: number;
}

export function ReasoningBlock({
  reasoning,
  isThinking,
  thinkingSeconds,
}: ReasoningBlockProps) {
  const [open, setOpen] = useState(true);
  const prevIsThinkingRef = useRef(isThinking);

  // Synchronously collapse when thinking ends (no effect delay).
  if (prevIsThinkingRef.current !== isThinking) {
    prevIsThinkingRef.current = isThinking;
    if (open !== isThinking) {
      setOpen(isThinking);
    }
  }

  return (
    <div className="mb-3">
      <button
        onClick={() => setOpen((value) => !value)}
        className="flex items-center gap-2 text-xs text-[#c9a84c] hover:text-[#f0f0f0] transition-colors cursor-pointer"
      >
        <Brain className="h-3.5 w-3.5" />
        {isThinking ? (
          <span className="font-medium">Thinking…</span>
        ) : (
          <span>Thought for {thinkingSeconds}s</span>
        )}
        <ChevronDown
          className={`h-3 w-3 transition-transform duration-200 ${open ? "" : "-rotate-90"}`}
        />
      </button>
      {open && (
        <div className="mt-2 rounded-lg border border-[#c9a84c33] bg-[#1a1a1a] px-3 py-2 text-xs text-[#888888] whitespace-pre-wrap">
          {reasoning}
        </div>
      )}
    </div>
  );
}