()
| 42 | } |
| 43 | |
| 44 | function TestPanel() { |
| 45 | const searchParams = useSearch({ from: '/stream-debugger' }) |
| 46 | const [recording, setRecording] = useState<ChunkRecording | null>(null) |
| 47 | const [currentChunkIndex, setCurrentChunkIndex] = useState(-1) |
| 48 | const [uiMessage, setUIMessage] = useState<UIMessage | null>(null) |
| 49 | const [result, setResult] = useState<ProcessorResult | null>(null) |
| 50 | const [isDragging, setIsDragging] = useState(false) |
| 51 | const [selectedSample, setSelectedSample] = useState<string>('') |
| 52 | const [copied, setCopied] = useState(false) |
| 53 | const [recordedTraces, setRecordedTraces] = useState<Array<RecordedTrace>>([]) |
| 54 | const fileInputRef = useRef<HTMLInputElement>(null) |
| 55 | |
| 56 | // Processor ref for step-through mode |
| 57 | const processorRef = useRef<StreamProcessor | null>(null) |
| 58 | |
| 59 | const sampleOptions = useMemo(() => Object.keys(sampleTraces), []) |
| 60 | |
| 61 | // Function to fetch recorded traces |
| 62 | const fetchRecordedTraces = useCallback(() => { |
| 63 | fetch('/api/list-traces') |
| 64 | .then((res) => res.json()) |
| 65 | .then((data) => { |
| 66 | if (data.traces) { |
| 67 | setRecordedTraces(data.traces) |
| 68 | } |
| 69 | }) |
| 70 | .catch((error) => { |
| 71 | console.error('[TestPanel] Failed to load trace list:', error) |
| 72 | }) |
| 73 | }, []) |
| 74 | |
| 75 | // Fetch recorded traces on mount |
| 76 | useEffect(() => { |
| 77 | fetchRecordedTraces() |
| 78 | }, [fetchRecordedTraces]) |
| 79 | |
| 80 | const resetState = useCallback(() => { |
| 81 | setCurrentChunkIndex(-1) |
| 82 | setUIMessage(null) |
| 83 | setResult(null) |
| 84 | processorRef.current = null |
| 85 | }, []) |
| 86 | |
| 87 | const createProcessor = useCallback(() => { |
| 88 | const processor = new StreamProcessor({ |
| 89 | events: { |
| 90 | onMessagesChange: (messages: Array<UIMessage>) => { |
| 91 | // Get the assistant message (should be the last one) |
| 92 | const assistantMessage = messages.find((m) => m.role === 'assistant') |
| 93 | if (assistantMessage) { |
| 94 | setUIMessage(assistantMessage) |
| 95 | } |
| 96 | }, |
| 97 | onStreamEnd: (message: UIMessage) => { |
| 98 | // Get text content from parts |
| 99 | const textParts = message.parts.filter((p) => p.type === 'text') |
| 100 | const content = textParts.map((p) => (p as any).content).join('') |
| 101 |
nothing calls this directly
no test coverage detected