Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(chat-input): show send button beside stop while generating (#19912)

AmAzing-38e997728705
diff --git a/src/features/ChatInput/SendArea/SendButton.tsx b/src/features/ChatInput/SendArea/SendButton.tsx
index 857c964bb9e..f9f6c24ecd5 100644
--- a/src/features/ChatInput/SendArea/SendButton.tsx
+++ b/src/features/ChatInput/SendArea/SendButton.tsx
@@ -1,5 +1,5 @@
import { SendButton as Send } from '@lobehub/editor/react';
-import { Tooltip } from '@lobehub/ui';
+import { Flexbox, Tooltip } from '@lobehub/ui';
import isEqual from 'fast-deep-equal';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
@@ -14,7 +14,10 @@ const SendButton = memo(() => {
const sendMenu = useChatInputStore((s) => s.sendMenu);
const shape = useChatInputStore((s) => s.sendButtonProps?.shape);
const size = useChatInputStore((s) => s.sendButtonProps?.size);
- const { generating, disabled } = useChatInputStore(selectors.sendButtonProps, isEqual);
+ const { generating, disabled, showSendWhileGenerating } = useChatInputStore(
+ selectors.sendButtonProps,
+ isEqual,
+ );
const [send, handleStop] = useChatInputStore((s) => [s.handleSendButton, s.handleStop]);
// Workspace viewer doesn't have `message:create` β†’ backend would 403.
@@ -28,19 +31,32 @@ const SendButton = memo(() => {
const viewOnly = !canUseResource;
const canSend = canCreate && !viewOnly;
- const button = (
- <Send
- disabled={disabled || !canSend}
- generating={generating}
- menu={canSend ? (sendMenu as any) : undefined}
- placement={'topRight'}
- shape={shape}
- size={size}
- trigger={['hover']}
- onClick={generating || !canSend ? undefined : () => send()}
- onStop={() => handleStop()}
- />
- );
+ // Stop keeps its spinner so the running state stays visible; Send sits beside
+ // it for the follow-up the user typed (Enter sends too).
+ const button =
+ generating && showSendWhileGenerating ? (
+ <Flexbox horizontal align={'center'} gap={8}>
+ <Send generating shape={shape} size={size} onStop={() => handleStop()} />
+ <Send
+ disabled={disabled || !canSend}
+ shape={shape}
+ size={size}
+ onClick={canSend ? () => send() : undefined}
+ />
+ </Flexbox>
+ ) : (
+ <Send
+ disabled={disabled || !canSend}
+ generating={generating}
+ menu={canSend ? (sendMenu as any) : undefined}
+ placement={'topRight'}
+ shape={shape}
+ size={size}
+ trigger={['hover']}
+ onClick={generating || !canSend ? undefined : () => send()}
+ onStop={() => handleStop()}
+ />
+ );
if (!canCreate) return <Tooltip title={reason}>{button}</Tooltip>;
if (viewOnly) return <Tooltip title={t('permission.viewOnlySendTip')}>{button}</Tooltip>;
diff --git a/src/features/ChatInput/StoreUpdater.test.tsx b/src/features/ChatInput/StoreUpdater.test.tsx
index 6a4f532470f..acbcb9f43bc 100644
--- a/src/features/ChatInput/StoreUpdater.test.tsx
+++ b/src/features/ChatInput/StoreUpdater.test.tsx
@@ -3,8 +3,10 @@ import { act, fireEvent, render, screen, waitFor } from '@testing-library/react'
import { type PropsWithChildren, useEffect } from 'react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
+import { getConversationSendButtonProps } from '@/features/Conversation/ChatInput/utils';
import { useSingleton } from '@/hooks/useSingleton';
+import SendButton from './SendArea/SendButton';
import { createStore, Provider, useChatInputStore } from './store';
import StoreUpdater from './StoreUpdater';
import VoiceMessage from './VoiceMessage';
@@ -86,6 +88,43 @@ beforeEach(() => {
});
describe('ChatInput StoreUpdater', () => {
+ it('keeps follow-up Send disabled during uploads and restores it without disabling Stop', () => {
+ const onStop = vi.fn();
+ const send = vi.fn();
+ const store = createStore();
+ store.setState({ handleSendButton: send, handleStop: onStop });
+ const composer = (isUploading: boolean) => (
+ <Provider createStore={() => store}>
+ <StoreUpdater
+ leftActions={[]}
+ rightActions={[]}
+ sendButtonProps={getConversationSendButtonProps(
+ { disabled: isUploading, generating: true, onStop, showSendWhileGenerating: true },
+ { disabled: false, shape: 'round' },
+ isUploading,
+ )}
+ />
+ <SendButton />
+ </Provider>
+ );
+ const { rerender } = render(composer(true));
+ const [stopButton, sendButton] = screen.getAllByRole('button');
+
+ expect(stopButton).not.toBeDisabled();
+ expect(sendButton).toBeDisabled();
+ fireEvent.click(sendButton);
+ expect(send).not.toHaveBeenCalled();
+ fireEvent.click(stopButton);
+ expect(onStop).toHaveBeenCalledOnce();
+
+ rerender(composer(false));
+ const [restoredStop, restoredSend] = screen.getAllByRole('button');
+ expect(restoredStop).not.toBeDisabled();
+ expect(restoredSend).not.toBeDisabled();
+ fireEvent.click(restoredSend);
+ expect(send).toHaveBeenCalledOnce();
+ });
+
it('clears sendMenu when the prop becomes undefined', () => {
const initialSendMenu = { items: [{ key: 'test', label: 'Test' }] } satisfies MenuProps;
const onSendMenuChange = vi.fn();
diff --git a/src/features/ChatInput/store/initialState.ts b/src/features/ChatInput/store/initialState.ts
index 43b800624b5..8e8e1da8a66 100644
--- a/src/features/ChatInput/store/initialState.ts
+++ b/src/features/ChatInput/store/initialState.ts
@@ -19,6 +19,12 @@ export interface SendButtonProps {
generating: boolean;
onStop: (params: { editor: IEditor }) => void;
shape?: 'round' | 'default';
+ /**
+ * While `generating`, render a Send button beside Stop so a follow-up can be
+ * sent without hiding the running indicator. Only hosts whose `onSend`
+ * accepts sends during generation (e.g. by queueing) should enable this.
+ */
+ showSendWhileGenerating?: boolean;
size?: number;
}
diff --git a/src/features/Conversation/ChatInput/index.tsx b/src/features/Conversation/ChatInput/index.tsx
index de7b3ab2552..36e30f61493 100644
--- a/src/features/Conversation/ChatInput/index.tsx
+++ b/src/features/Conversation/ChatInput/index.tsx
@@ -47,6 +47,7 @@ import { sendVoiceMessage } from './sendVoiceMessage';
import {
getContextWindowMessages,
getConversationChatInputUiState,
+ getConversationSendButtonProps,
toChatInputMessages,
} from './utils';
import GoalArmedChip from './VerifyTray/GoalArmedChip';
@@ -307,11 +308,13 @@ const ChatInput = memo<ChatInputProps>(
// Computed state
const isInputEmpty = !inputMessage.trim() && fileList.length === 0 && contextList.length === 0;
- const { placeholderVariant, showSendMenu, showStopButton } = getConversationChatInputUiState({
- disableFollowUpVariant,
- isInputEmpty,
- isInputLoading,
- });
+ const { placeholderVariant, showSendMenu, showSendWhileGenerating, showStopButton } =
+ getConversationChatInputUiState({
+ disableFollowUpVariant,
+ disableQueue,
+ isInputEmpty,
+ isInputLoading,
+ });
// Input stays enabled during agent execution β€” messages are queued.
// When disableQueue is set (e.g. onboarding), block sending while loading.
// disableSend hard-blocks regardless of content (host surface is read-only).
@@ -326,10 +329,10 @@ const ChatInput = memo<ChatInputProps>(
const customDisabled = customSendButtonProps?.disabled;
const resolveSendBlocked = useCallback(() => {
if (disableSend) return true;
- if (customDisabled !== undefined) return customDisabled;
const fileStore = useFileStore.getState();
if (fileChatSelectors.isUploadingFiles(fileStore)) return true;
+ if (customDisabled !== undefined) return customDisabled;
const { context: liveContext, editor } = storeApi.getState();
if (
@@ -417,10 +420,11 @@ const ChatInput = memo<ChatInputProps>(
);
const sendButtonProps: SendButtonProps = {
- disabled,
- generating: showStopButton,
- onStop: stopGenerating,
- ...customSendButtonProps,
+ ...getConversationSendButtonProps(
+ { disabled, generating: showStopButton, onStop: stopGenerating, showSendWhileGenerating },
+ customSendButtonProps,
+ isUploadingFiles,
+ ),
...(shouldUsePlainSendButton
? { shape: customSendButtonProps?.shape ?? 'round' }
: undefined),
diff --git a/src/features/Conversation/ChatInput/utils.test.ts b/src/features/Conversation/ChatInput/utils.test.ts
index a47e62165d4..4f45a8c3f42 100644
--- a/src/features/Conversation/ChatInput/utils.test.ts
+++ b/src/features/Conversation/ChatInput/utils.test.ts
@@ -5,6 +5,7 @@ import {
createQueueSendNowGate,
getContextWindowMessages,
getConversationChatInputUiState,
+ getConversationSendButtonProps,
toChatInputMessages,
} from './utils';
@@ -122,8 +123,48 @@ describe('getContextWindowMessages', () => {
});
});
+describe('getConversationSendButtonProps', () => {
+ it.each([false, true])(
+ 'keeps uploads disabled with generating=%s despite a host override',
+ (generating) => {
+ const defaults = {
+ disabled: true,
+ generating,
+ onStop: vi.fn(),
+ showSendWhileGenerating: generating,
+ };
+ const overrides = { disabled: false, shape: 'round' as const };
+
+ expect(getConversationSendButtonProps(defaults, overrides, true)).toEqual({
+ ...defaults,
+ disabled: true,
+ shape: 'round',
+ });
+ expect(getConversationSendButtonProps(defaults, overrides, false).disabled).toBe(false);
+ },
+ );
+
+ it.each([
+ { customDisabled: undefined, disabled: true, expected: true },
+ { customDisabled: undefined, disabled: false, expected: false },
+ { customDisabled: true, disabled: false, expected: true },
+ { customDisabled: false, disabled: true, expected: false },
+ ])(
+ 'preserves non-upload disabled overrides: $customDisabled / $disabled',
+ ({ customDisabled, disabled, expected }) => {
+ expect(
+ getConversationSendButtonProps(
+ { disabled, generating: false, onStop: vi.fn() },
+ customDisabled === undefined ? undefined : { disabled: customDisabled },
+ false,
+ ).disabled,
+ ).toBe(expected);
+ },
+ );
+});
+
describe('getConversationChatInputUiState', () => {
- it('shows follow-up placeholder and stop button while loading with an empty composer', () => {
+ it('shows follow-up placeholder and only the stop button while loading with an empty composer', () => {
expect(
getConversationChatInputUiState({
isInputEmpty: true,
@@ -132,15 +173,16 @@ describe('getConversationChatInputUiState', () => {
).toEqual({
placeholderVariant: 'followUp',
showSendMenu: false,
+ showSendWhileGenerating: false,
showStopButton: true,
});
});
- it('keeps the stop button visible while the user types a follow-up during loading', () => {
- // Regression: flipping to Send the moment the composer had any text read
- // as "agent finished" and made queued sends look like fresh sends. Stop
- // must stay up for the whole loading window β€” Enter still enqueues, and
- // the QueueTray exposes Send-now per item.
+ it('shows Send beside Stop while the user types a follow-up during loading', () => {
+ // Regression: flipping Stop to Send the moment the composer had any text
+ // read as "agent finished". Stop must stay up for the whole loading window;
+ // Send appears next to it so the follow-up can be queued by click as well
+ // as by Enter.
expect(
getConversationChatInputUiState({
isInputEmpty: false,
@@ -149,6 +191,20 @@ describe('getConversationChatInputUiState', () => {
).toEqual({
placeholderVariant: 'default',
showSendMenu: false,
+ showSendWhileGenerating: true,
+ showStopButton: true,
+ });
+ });
+
+ it('keeps only Stop while loading when the host disables queueing', () => {
+ expect(
+ getConversationChatInputUiState({
+ disableQueue: true,
+ isInputEmpty: false,
+ isInputLoading: true,
+ }),
+ ).toMatchObject({
+ showSendWhileGenerating: false,
showStopButton: true,
});
});
@@ -156,12 +212,13 @@ describe('getConversationChatInputUiState', () => {
it('keeps the default composer state when not loading', () => {
expect(
getConversationChatInputUiState({
- isInputEmpty: true,
+ isInputEmpty: false,
isInputLoading: false,
}),
).toEqual({
placeholderVariant: 'default',
showSendMenu: true,
+ showSendWhileGenerating: false,
showStopButton: false,
});
});
@@ -176,6 +233,7 @@ describe('getConversationChatInputUiState', () => {
).toEqual({
placeholderVariant: 'default',
showSendMenu: false,
+ showSendWhileGenerating: false,
showStopButton: true,
});
});
diff --git a/src/features/Conversation/ChatInput/utils.ts b/src/features/Conversation/ChatInput/utils.ts
index 3c0faf84265..2de00a83618 100644
--- a/src/features/Conversation/ChatInput/utils.ts
+++ b/src/features/Conversation/ChatInput/utils.ts
@@ -1,6 +1,7 @@
import type { OpenAIChatMessage, UIChatMessage } from '@lobechat/types';
import type { PlaceholderVariant } from '@/features/ChatInput/InputEditor/Placeholder';
+import type { SendButtonProps } from '@/features/ChatInput/store/initialState';
import { chatHelpers } from '@/store/chat/helpers';
type SupportedChatInputRole = Extract<OpenAIChatMessage['role'], 'assistant' | 'tool' | 'user'>;
@@ -71,9 +72,22 @@ export const getContextWindowMessages = (
},
) => toChatInputMessages(chatHelpers.getSlicedMessages(messages, options));
+export const getConversationSendButtonProps = (
+ defaults: SendButtonProps,
+ overrides: Partial<SendButtonProps> | undefined,
+ isUploadingFiles: boolean,
+): SendButtonProps => ({
+ ...defaults,
+ ...overrides,
+ // Uploads are a hard gate even when a host explicitly enables sending.
+ disabled: isUploadingFiles || (overrides?.disabled ?? defaults.disabled),
+});
+
export interface ConversationChatInputUiState {
placeholderVariant: PlaceholderVariant;
showSendMenu: boolean;
+ /** Show Send beside Stop so a typed follow-up can be queued by click. */
+ showSendWhileGenerating: boolean;
showStopButton: boolean;
}
@@ -83,24 +97,27 @@ export interface GetConversationChatInputUiStateParams {
* surfaces (e.g. onboarding) that have no follow-up / pending-message design.
*/
disableFollowUpVariant?: boolean;
+ /** Sending is blocked while loading, so no Send button appears beside Stop. */
+ disableQueue?: boolean;
isInputEmpty: boolean;
isInputLoading: boolean;
}
export const getConversationChatInputUiState = ({
disableFollowUpVariant,
+ disableQueue,
isInputEmpty,
isInputLoading,
}: GetConversationChatInputUiStateParams): ConversationChatInputUiState => {
// Keep the Stop button up for the entire loading window β€” including when the
- // user starts typing a follow-up. Previously this flipped to Send the moment
- // the composer had any text, which read as "agent finished" and made queued
- // sends look like fresh sends. Pressing Enter still enqueues; the QueueTray
- // exposes per-item Send-now and Edit/Delete for explicit control.
+ // user starts typing a follow-up. Replacing Stop with Send read as "agent
+ // finished" and made queued sends look like fresh sends. Once the composer
+ // has content, Send appears beside Stop instead; Enter and Send both enqueue.
const followUp = !disableFollowUpVariant && isInputLoading && isInputEmpty;
return {
placeholderVariant: followUp ? 'followUp' : 'default',
showSendMenu: !isInputLoading,
+ showSendWhileGenerating: isInputLoading && !isInputEmpty && !disableQueue,
showStopButton: isInputLoading,
};
};