Skip to content

Commit ff6d888

Browse files
prompt enhancement sending bug
1 parent 93dfbc3 commit ff6d888

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

client/src/components/Chat/Input/ChatForm.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,8 @@ const ChatForm = memo(
656656
)}
657657
<div className={`${isRTL ? 'ml-2' : 'mr-2'}`}>
658658
<EnhancePrompt
659-
textAreaRef={textAreaRef}
659+
textAreaRef={textAreaRef}
660+
methods={methods}
660661
disabled={disableInputs || isNotAppendable || !textValue?.trim()}
661662
hasText={!!textValue?.trim()}
662663
/>

client/src/components/Chat/Input/EnhancePrompt.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import React, { useState, useEffect, useRef } from 'react';
22
import { Sparkles } from 'lucide-react';
3+
import { UseFormReturn } from 'react-hook-form';
34
import { cn } from '~/utils';
45
import { useLocalize } from '~/hooks';
56
import { TooltipAnchor } from '~/components/ui/Tooltip';
67
import { dataService } from 'librechat-data-provider';
78

89
interface EnhancePromptProps {
910
textAreaRef: React.RefObject<HTMLTextAreaElement>;
11+
methods: UseFormReturn<{ text: string }>;
1012
disabled?: boolean;
1113
className?: string;
1214
hasText?: boolean;
1315
}
1416

15-
export default function EnhancePrompt({ textAreaRef, disabled = false, className, hasText = false }: EnhancePromptProps) {
17+
export default function EnhancePrompt({ textAreaRef, methods, disabled = false, className, hasText = false }: EnhancePromptProps) {
1618
const localize = useLocalize();
1719
const [isEnhancing, setIsEnhancing] = useState(false);
1820
const [isSparklingIntro, setIsSparklingIntro] = useState(false);
@@ -70,14 +72,19 @@ export default function EnhancePrompt({ textAreaRef, disabled = false, className
7072
setIsEnhancing(true);
7173
try {
7274
const response = await dataService.enhanceMessage(currentText);
73-
if (response.enhancedMessage && textAreaRef.current) {
74-
textAreaRef.current.value = response.enhancedMessage;
75-
// Trigger input event to update form state
76-
const event = new Event('input', { bubbles: true });
77-
textAreaRef.current.dispatchEvent(event);
78-
// Force resize
79-
textAreaRef.current.style.height = 'auto';
80-
textAreaRef.current.style.height = textAreaRef.current.scrollHeight + 'px';
75+
if (response.enhancedMessage) {
76+
// Update form state using React Hook Form's setValue
77+
methods.setValue('text', response.enhancedMessage, {
78+
shouldValidate: true,
79+
shouldDirty: true,
80+
shouldTouch: true
81+
});
82+
83+
// Force textarea resize
84+
if (textAreaRef.current) {
85+
textAreaRef.current.style.height = 'auto';
86+
textAreaRef.current.style.height = textAreaRef.current.scrollHeight + 'px';
87+
}
8188
}
8289
} catch (error) {
8390
console.error('Failed to enhance message:', error);

0 commit comments

Comments
 (0)