'use client'; import { useCallback } from 'react'; import { EmbeddedChat } from '@/components/chat/EmbeddedChat'; import { useChatTurns, type AskFn } from '@/hooks/useChatTurns'; import type { TryDocument } from './TryDocumentsPanel'; const STARTERS = [ 'What is this document about?', 'Summarize the key points', 'What are the main conclusions?', 'List any action items or recommendations', ]; interface TryChatPanelProps { documents: TryDocument[]; onError: (msg: string) => void; } export const TryChatPanel = ({ documents, onError }: TryChatPanelProps) => { const ask = useCallback( async (message, _history, signal) => { onError(''); const response = await fetch('/api/demo/document-chat', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ message, documents: documents.map((doc) => ({ name: doc.name, content: doc.content })), }), signal, }); const data = await response.json(); if (!data.success) throw new Error(data.error || 'Something went wrong'); return { content: data.data.response, sources: (data.data.sources as Array<{ document_name: string }> | undefined)?.map( (source) => ({ label: source.document_name }), ), }; }, [documents, onError], ); const chat = useChatTurns(ask, { failedText: 'Failed to get response. Please try again.' }); return (
{/* Chat Header */}

Chat

Ask questions about your documents

Drop your document here

Upload a PDF, text file, or markdown document to start chatting with its content.

Contracts Research papers Reports Legal docs
) : (

Your documents are ready!

Ask any question about your documents.

) } /> ); };