fix: disappearing user text when stopped (#1839)
This commit is contained in:
@@ -255,6 +255,12 @@ export default function ChatView({
|
|||||||
// isUserMessage also checks if the message is a toolConfirmationRequest
|
// isUserMessage also checks if the message is a toolConfirmationRequest
|
||||||
// check if the last message is a real user's message
|
// check if the last message is a real user's message
|
||||||
if (lastMessage && isUserMessage(lastMessage) && !isToolResponse) {
|
if (lastMessage && isUserMessage(lastMessage) && !isToolResponse) {
|
||||||
|
// Get the text content from the last message before removing it
|
||||||
|
const textContent = lastMessage.content.find((c) => c.type === 'text')?.text || '';
|
||||||
|
|
||||||
|
// Set the text back to the input field
|
||||||
|
_setInput(textContent);
|
||||||
|
|
||||||
// Remove the last user message if it's the most recent one
|
// Remove the last user message if it's the most recent one
|
||||||
if (messages.length > 1) {
|
if (messages.length > 1) {
|
||||||
setMessages(messages.slice(0, -1));
|
setMessages(messages.slice(0, -1));
|
||||||
@@ -433,6 +439,8 @@ export default function ChatView({
|
|||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
onStop={onStopGoose}
|
onStop={onStopGoose}
|
||||||
commandHistory={commandHistory}
|
commandHistory={commandHistory}
|
||||||
|
value={_input}
|
||||||
|
onValueChange={_setInput}
|
||||||
/>
|
/>
|
||||||
<BottomMenu hasMessages={hasMessages} setView={setView} />
|
<BottomMenu hasMessages={hasMessages} setView={setView} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ interface InputProps {
|
|||||||
isLoading?: boolean;
|
isLoading?: boolean;
|
||||||
onStop?: () => void;
|
onStop?: () => void;
|
||||||
commandHistory?: string[];
|
commandHistory?: string[];
|
||||||
|
value?: string;
|
||||||
|
onValueChange?: (value: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Input({
|
export default function Input({
|
||||||
@@ -15,8 +17,19 @@ export default function Input({
|
|||||||
isLoading = false,
|
isLoading = false,
|
||||||
onStop,
|
onStop,
|
||||||
commandHistory = [],
|
commandHistory = [],
|
||||||
|
value: controlledValue,
|
||||||
|
onValueChange,
|
||||||
}: InputProps) {
|
}: InputProps) {
|
||||||
const [value, setValue] = useState('');
|
const [internalValue, setInternalValue] = useState('');
|
||||||
|
// Use controlled value if provided, otherwise use internal state
|
||||||
|
const value = controlledValue !== undefined ? controlledValue : internalValue;
|
||||||
|
const setValue = (newValue: string) => {
|
||||||
|
if (controlledValue !== undefined && onValueChange) {
|
||||||
|
onValueChange(newValue);
|
||||||
|
} else {
|
||||||
|
setInternalValue(newValue);
|
||||||
|
}
|
||||||
|
};
|
||||||
// State to track if the IME is composing (i.e., in the middle of Japanese IME input)
|
// State to track if the IME is composing (i.e., in the middle of Japanese IME input)
|
||||||
const [isComposing, setIsComposing] = useState(false);
|
const [isComposing, setIsComposing] = useState(false);
|
||||||
const [historyIndex, setHistoryIndex] = useState(-1);
|
const [historyIndex, setHistoryIndex] = useState(-1);
|
||||||
|
|||||||
Reference in New Issue
Block a user