(
baseText: string,
files: File[],
pdfData: Map<File, FileData>,
imageParts?: any[],
)
| 846 | |
| 847 | // Process files and append content to user text (handles PDF, text, and optionally images) |
| 848 | const processFilesAndAppendContent = async ( |
| 849 | baseText: string, |
| 850 | files: File[], |
| 851 | pdfData: Map<File, FileData>, |
| 852 | imageParts?: any[], |
| 853 | ): Promise<string> => { |
| 854 | let userText = baseText |
| 855 | |
| 856 | for (const file of files) { |
| 857 | if (isPdfFile(file)) { |
| 858 | const extracted = pdfData.get(file) |
| 859 | if (extracted?.text) { |
| 860 | userText += `\n\n[PDF: ${file.name}]\n${extracted.text}` |
| 861 | } |
| 862 | } else if (isTextFile(file)) { |
| 863 | const extracted = pdfData.get(file) |
| 864 | if (extracted?.text) { |
| 865 | userText += `\n\n[File: ${file.name}]\n${extracted.text}` |
| 866 | } |
| 867 | } else if (imageParts) { |
| 868 | // Handle as image (only if imageParts array provided) |
| 869 | const reader = new FileReader() |
| 870 | const dataUrl = await new Promise<string>((resolve) => { |
| 871 | reader.onload = () => resolve(reader.result as string) |
| 872 | reader.readAsDataURL(file) |
| 873 | }) |
| 874 | |
| 875 | imageParts.push({ |
| 876 | type: "file", |
| 877 | url: dataUrl, |
| 878 | mediaType: file.type, |
| 879 | }) |
| 880 | } |
| 881 | } |
| 882 | |
| 883 | return userText |
| 884 | } |
| 885 | |
| 886 | const handleRegenerate = async (messageIndex: number) => { |
| 887 | const isProcessing = status === "streaming" || status === "submitted" |
no test coverage detected