fix: include file attachments in queued messages (#5961)
Signed-off-by: Abhijay007 <Abhijay007j@gmail.com>
This commit is contained in:
@@ -816,8 +816,22 @@ export default function ChatInput({
|
|||||||
|
|
||||||
// Helper function to handle interruption and queue logic when loading
|
// Helper function to handle interruption and queue logic when loading
|
||||||
const handleInterruptionAndQueue = () => {
|
const handleInterruptionAndQueue = () => {
|
||||||
if (!isLoading || !displayValue.trim()) {
|
if (!isLoading || !hasSubmittableContent) {
|
||||||
return false; // Return false if no action was taken
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const validPastedImageFilesPaths = pastedImages
|
||||||
|
.filter((img) => img.filePath && !img.error && !img.isLoading)
|
||||||
|
.map((img) => img.filePath as string);
|
||||||
|
const droppedFilePaths = allDroppedFiles
|
||||||
|
.filter((file) => !file.error && !file.isLoading)
|
||||||
|
.map((file) => file.path);
|
||||||
|
|
||||||
|
let contentToQueue = displayValue.trim();
|
||||||
|
const allFilePaths = [...validPastedImageFilesPaths, ...droppedFilePaths];
|
||||||
|
if (allFilePaths.length > 0) {
|
||||||
|
const pathsString = allFilePaths.join(' ');
|
||||||
|
contentToQueue = contentToQueue ? `${contentToQueue} ${pathsString}` : pathsString;
|
||||||
}
|
}
|
||||||
|
|
||||||
const interruptionMatch = detectInterruption(displayValue.trim());
|
const interruptionMatch = detectInterruption(displayValue.trim());
|
||||||
@@ -831,7 +845,7 @@ export default function ChatInput({
|
|||||||
// rather than trying to send it immediately while the system is still loading
|
// rather than trying to send it immediately while the system is still loading
|
||||||
const interruptionMessage = {
|
const interruptionMessage = {
|
||||||
id: Date.now().toString() + Math.random().toString(36).substr(2, 9),
|
id: Date.now().toString() + Math.random().toString(36).substr(2, 9),
|
||||||
content: displayValue.trim(),
|
content: contentToQueue,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -840,12 +854,19 @@ export default function ChatInput({
|
|||||||
|
|
||||||
setDisplayValue('');
|
setDisplayValue('');
|
||||||
setValue('');
|
setValue('');
|
||||||
return true; // Return true if interruption was handled
|
setPastedImages([]);
|
||||||
|
if (onFilesProcessed && droppedFiles.length > 0) {
|
||||||
|
onFilesProcessed();
|
||||||
|
}
|
||||||
|
if (localDroppedFiles.length > 0) {
|
||||||
|
setLocalDroppedFiles([]);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const newMessage = {
|
const newMessage = {
|
||||||
id: Date.now().toString() + Math.random().toString(36).substr(2, 9),
|
id: Date.now().toString() + Math.random().toString(36).substr(2, 9),
|
||||||
content: displayValue.trim(),
|
content: contentToQueue,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
};
|
};
|
||||||
setQueuedMessages((prev) => {
|
setQueuedMessages((prev) => {
|
||||||
@@ -859,7 +880,14 @@ export default function ChatInput({
|
|||||||
});
|
});
|
||||||
setDisplayValue('');
|
setDisplayValue('');
|
||||||
setValue('');
|
setValue('');
|
||||||
return true; // Return true if message was queued
|
setPastedImages([]);
|
||||||
|
if (onFilesProcessed && droppedFiles.length > 0) {
|
||||||
|
onFilesProcessed();
|
||||||
|
}
|
||||||
|
if (localDroppedFiles.length > 0) {
|
||||||
|
setLocalDroppedFiles([]);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const canSubmit =
|
const canSubmit =
|
||||||
@@ -1004,6 +1032,10 @@ export default function ChatInput({
|
|||||||
|
|
||||||
const onFormSubmit = (e: React.FormEvent) => {
|
const onFormSubmit = (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
if (isLoading && hasSubmittableContent) {
|
||||||
|
handleInterruptionAndQueue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
const canSubmit =
|
const canSubmit =
|
||||||
!isLoading &&
|
!isLoading &&
|
||||||
(displayValue.trim() ||
|
(displayValue.trim() ||
|
||||||
@@ -1272,7 +1304,7 @@ export default function ChatInput({
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Send/Stop button */}
|
{/* Send/Stop button */}
|
||||||
{isLoading ? (
|
{isLoading && !hasSubmittableContent ? (
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={onStop}
|
onClick={onStop}
|
||||||
|
|||||||
Reference in New Issue
Block a user