π€― 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
π fix(task): drive the run drawer composer from the run's op status (#20649)
Arvin Xuca6afa91f3d7
diff --git a/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/FeedbackInput.tsx b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/FeedbackInput.tsxindex a52a41a2865..3a8a29b280b 100644--- a/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/FeedbackInput.tsx+++ b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/FeedbackInput.tsx@@ -8,6 +8,7 @@ import { useTranslation } from 'react-i18next';import { AttachmentUploadButton } from '@/features/AttachmentInput';import OpStatusTray from '@/features/Conversation/ChatInput/OpStatusTray';+import { useConversationChatInputUiState } from '@/features/Conversation/ChatInput/useConversationChatInputUiState';import { useConversationResourceAccess } from '@/features/Conversation/hooks/useConversationResourceAccess';import { useConversationStore } from '@/features/Conversation/store';import { EditorCanvas } from '@/features/EditorCanvas';@@ -31,6 +32,7 @@ const FeedbackInput = memo<FeedbackInputProps>(const { t } = useTranslation('chat');const editor = useEditor();const sendMessage = useConversationStore((s) => s.sendMessage);+ const stopGenerating = useConversationStore((s) => s.stopGenerating);const [submitting, setSubmitting] = useState(false);const [hasContent, setHasContent] = useState(false);const [hasAttachments, setHasAttachments] = useState(false);@@ -41,6 +43,14 @@ const FeedbackInput = memo<FeedbackInputProps>(const { canUseResource } = useConversationResourceAccess();const canSubmit = hasContent || hasAttachments;+ // The run this drawer shows is a real op in its own conversation context, so+ // the composer reads the same op-derived send area as the main composer:+ // while the agent is working the control is Stop, and a typed follow-up+ // queues beside it instead of reading as a fresh send. Without it the drawer+ // offered Send during a running run β no way to stop it, and no sign that the+ // follow-up was queued rather than started.+ const { placeholderVariant, showSendWhileGenerating, showStopButton } =+ useConversationChatInputUiState({ isInputEmpty: !canSubmit });useEffect(() => {if (expanded) editor?.focus?.();@@ -135,14 +145,43 @@ const FeedbackInput = memo<FeedbackInputProps>(</Flexbox>}right={- <SendButton- disabled={!canSubmit && !submitting}- loading={submitting}- shape={'round'}- title={t('taskDetail.replyInThread')}- type={'primary'}- onClick={handleSubmit}- />+ showSendWhileGenerating ? (+ // Stop keeps the running state on screen and Send joins it, so a+ // typed follow-up is queued on click β the same pairing the main+ // composer uses. Replacing Stop with Send read as "the run has+ // finished" and made a queued follow-up look like a fresh run.+ <Flexbox horizontal align={'center'} gap={8}>+ <SendButton+ generating+ shape={'round'}+ title={t('stop', { ns: 'common' })}+ onStop={stopGenerating}+ />+ <SendButton+ disabled={!canSubmit}+ shape={'round'}+ title={t('taskDetail.replyInThread')}+ type={'primary'}+ onClick={handleSubmit}+ />+ </Flexbox>+ ) : (+ <SendButton+ disabled={!canSubmit && !submitting}+ generating={showStopButton}+ loading={submitting}+ shape={'round'}+ // `onClick` stays off while generating: the editor's Stop+ // branch fires `onStop` AND `onClick`, so a handler here would+ // send the message the click was meant to cancel.+ type={'primary'}+ title={+ showStopButton ? t('stop', { ns: 'common' }) : t('taskDetail.replyInThread')+ }+ onClick={showStopButton ? undefined : handleSubmit}+ onStop={stopGenerating}+ />+ )}/>}@@ -150,8 +189,15 @@ const FeedbackInput = memo<FeedbackInputProps>(<EditorCanvaseditor={editor}floatingToolbar={false}- placeholder={t('taskDetail.replyPlaceholder')}+ // Same copy switch as the main composer while the run is in flight β+ // what is being typed is a follow-up to the working run, not a fresh+ // reply into an idle thread.style={{ paddingBlock: 0 }}+ placeholder={+ placeholderVariant === 'followUp'+ ? t('followUpPlaceholder')+ : t('taskDetail.replyPlaceholder')+ }onContentChange={handleContentChange}onPressEnter={({ event }) => {if (shouldSendOnEnter(event)) {diff --git a/src/features/Conversation/ChatInput/index.tsx b/src/features/Conversation/ChatInput/index.tsxindex a61034d5b91..1fd103b089e 100644--- a/src/features/Conversation/ChatInput/index.tsx+++ b/src/features/Conversation/ChatInput/index.tsx@@ -45,9 +45,9 @@ import OpStatusTray from './OpStatusTray';import QueueTray from './QueueTray';import { sendVoiceMessage } from './sendVoiceMessage';import { transcribeVoiceMessage } from './transcribeVoiceMessage';+import { useConversationChatInputUiState } from './useConversationChatInputUiState';import {getContextWindowMessages,- getConversationChatInputUiState,getConversationSendButtonProps,toChatInputMessages,toDisplayableSendErrorMessage,@@ -260,7 +260,6 @@ const ChatInput = memo<ChatInputProps>(}, [setChatInputOverlayHeight]);// Loading state from ConversationStore (bridged from ChatStore)- const isInputLoading = useConversationStore(messageStateSelectors.isInputVisiblyLoading);const isInputQueueBlocked = useChatStore((s) =>operationSelectors.isInputLoadingByContext(context)(s),);@@ -312,12 +311,7 @@ const ChatInput = memo<ChatInputProps>(// Computed stateconst isInputEmpty = !inputMessage.trim() && fileList.length === 0 && contextList.length === 0;const { placeholderVariant, showSendMenu, showSendWhileGenerating, showStopButton } =- getConversationChatInputUiState({- disableFollowUpVariant,- disableQueue,- isInputEmpty,- isInputLoading,- });+ useConversationChatInputUiState({ disableFollowUpVariant, disableQueue, isInputEmpty });// 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).diff --git a/src/features/Conversation/ChatInput/useConversationChatInputUiState.test.ts b/src/features/Conversation/ChatInput/useConversationChatInputUiState.test.tsnew file mode 100644index 00000000000..771ea5e4565--- /dev/null+++ b/src/features/Conversation/ChatInput/useConversationChatInputUiState.test.ts@@ -0,0 +1,92 @@+import { act, renderHook } from '@testing-library/react';+import { beforeEach, describe, expect, it, vi } from 'vitest';++import { useConversationChatInputUiState } from './useConversationChatInputUiState';++// A real (reactive) stand-in for the ConversationStore slice the hook reads, so+// the test proves the composer follows the run's op state over time β not just+// that it read it once. A composer that only tracked its own submit flag would+// miss a run started outside it (another tab, a scheduled run, `runTask`).+const storeMock = vi.hoisted(() => ({ current: undefined as any }));++vi.mock('../store', async () => {+ const { create } = await import('zustand');+ const useFakeStore = create<{ operationState: { isInputVisiblyLoading: boolean } }>(() => ({+ operationState: { isInputVisiblyLoading: false },+ }));+ storeMock.current = useFakeStore;++ return {+ messageStateSelectors: {+ isInputVisiblyLoading: (s: { operationState: { isInputVisiblyLoading: boolean } }) =>+ s.operationState.isInputVisiblyLoading,+ },+ useConversationStore: (selector: (s: unknown) => unknown) => useFakeStore(selector as never),+ };+});++const setInputVisiblyLoading = (value: boolean) =>+ act(() => {+ storeMock.current.setState({ operationState: { isInputVisiblyLoading: value } });+ });++describe('useConversationChatInputUiState', () => {+ beforeEach(() => {+ setInputVisiblyLoading(false);+ });++ it('follows a run that flips to loading after the composer is mounted', () => {+ const { result } = renderHook(() => useConversationChatInputUiState({ isInputEmpty: true }));++ expect(result.current.showStopButton).toBe(false);++ setInputVisiblyLoading(true);++ expect(result.current.showStopButton).toBe(true);+ expect(result.current.placeholderVariant).toBe('followUp');+ });++ it('swaps Send for Stop while the run is visibly loading', () => {+ setInputVisiblyLoading(true);++ const { result } = renderHook(() => useConversationChatInputUiState({ isInputEmpty: true }));++ expect(result.current).toEqual({+ placeholderVariant: 'followUp',+ showSendMenu: false,+ showSendWhileGenerating: false,+ showStopButton: true,+ });+ });++ it('keeps Send beside Stop so a typed follow-up can be queued', () => {+ setInputVisiblyLoading(true);++ const { result } = renderHook(() => useConversationChatInputUiState({ isInputEmpty: false }));++ expect(result.current.showStopButton).toBe(true);+ expect(result.current.showSendWhileGenerating).toBe(true);+ });++ it('drops the queued Send when the host refuses to queue', () => {+ setInputVisiblyLoading(true);++ const { result } = renderHook(() =>+ useConversationChatInputUiState({ disableQueue: true, isInputEmpty: false }),+ );++ expect(result.current.showStopButton).toBe(true);+ expect(result.current.showSendWhileGenerating).toBe(false);+ });++ it('offers a plain Send once the run is no longer loading', () => {+ const { result } = renderHook(() => useConversationChatInputUiState({ isInputEmpty: false }));++ expect(result.current).toEqual({+ placeholderVariant: 'default',+ showSendMenu: true,+ showSendWhileGenerating: false,+ showStopButton: false,+ });+ });+});diff --git a/src/features/Conversation/ChatInput/useConversationChatInputUiState.ts b/src/features/Conversation/ChatInput/useConversationChatInputUiState.tsnew file mode 100644index 00000000000..e2cd9a053e3--- /dev/null+++ b/src/features/Conversation/ChatInput/useConversationChatInputUiState.ts@@ -0,0 +1,47 @@+import { messageStateSelectors, useConversationStore } from '../store';+import { type ConversationChatInputUiState, getConversationChatInputUiState } from './utils';++export interface UseConversationChatInputUiStateParams {+ /**+ * When true, the placeholder never flips to the followUp variant β used by+ * 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;+}++/**+ * Resolve a conversation composer's send area from its run's op state.+ *+ * Use when:+ * - A composer renders send / stop affordances inside a conversation. Every host+ * (main chat, task run drawer, acceptance rail) has to react the same way to a+ * run that is in flight: Stop, plus Send beside it for the queued follow-up β+ * never a bare Send that reads as "the run has finished".+ *+ * Expects:+ * - Rendered under the conversation's `ConversationProvider`, whose+ * `operationState` carries the visible-loading flag for that context. A+ * composer that only tracks its own submit flag will miss a run started+ * elsewhere (another tab, a scheduled run, the task's own `runTask`).+ *+ * Returns:+ * - `getConversationChatInputUiState`'s shape, with the op state resolved from+ * the store so hosts cannot disagree about it.+ */+export const useConversationChatInputUiState = ({+ disableFollowUpVariant,+ disableQueue,+ isInputEmpty,+}: UseConversationChatInputUiStateParams): ConversationChatInputUiState => {+ const isInputLoading = useConversationStore(messageStateSelectors.isInputVisiblyLoading);++ return getConversationChatInputUiState({+ disableFollowUpVariant,+ disableQueue,+ isInputEmpty,+ isInputLoading,+ });+};