🤯 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): show queued follow-ups in the task run drawer (#21822)
Rdmclin23987f33cc7c0
diff --git a/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/FeedbackInput.tsx b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/FeedbackInput.tsxindex 56f5edf7b93..93d35059838 100644--- a/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/FeedbackInput.tsx+++ b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/FeedbackInput.tsx@@ -7,6 +7,7 @@ import { useTranslation } from 'react-i18next';import { AttachmentUploadButton } from '@/features/AttachmentInput';import OpStatusTray from '@/features/Conversation/ChatInput/OpStatusTray';+import QueueTray from '@/features/Conversation/ChatInput/QueueTray';import { useConversationChatInputUiState } from '@/features/Conversation/ChatInput/useConversationChatInputUiState';import { useConversationResourceAccess } from '@/features/Conversation/hooks/useConversationResourceAccess';import { useConversationStore } from '@/features/Conversation/store';@@ -18,6 +19,7 @@ import {import { useEnterToSend } from '@/hooks/useEnterToSend';import { useComposerFocus } from './useComposerFocus';+import { useFollowUpQueue } from './useFollowUpQueue';interface FeedbackInputProps {/** Acceptance's in-flow topic rail starts with the composer visible. The@@ -41,7 +43,7 @@ const FeedbackInput = memo<FeedbackInputProps>(const [submitting, setSubmitting] = useState(false);const [hasContent, setHasContent] = useState(false);const [hasAttachments, setHasAttachments] = useState(false);- const { collapse, expand, expanded, handleEditorInit } = useComposerFocus({+ const { collapse, expand, expanded, handleEditorInit, reveal } = useComposerFocus({defaultExpanded,editor,focusRequest,@@ -51,6 +53,15 @@ const FeedbackInput = memo<FeedbackInputProps>(// can watch the run but get no reply composer.const { canUseResource } = useConversationResourceAccess();+ // Follow-ups queued behind the running run are listed above the composer,+ // like the main chat input, so they can be edited, sent now or deleted.+ const { composerExpanded, hasQueuedMessages } = useFollowUpQueue({+ editor,+ enabled: canUseResource,+ expanded,+ reveal,+ });+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:@@ -114,7 +125,7 @@ const FeedbackInput = memo<FeedbackInputProps>(// Surface the live running-op status flush above the reply affordance (seamless// inline row that renders nothing when idle), so the user can watch the agent// work without expanding the composer.- if (!expanded) {+ if (!composerExpanded) {return (<Flexbox gap={8}><OpStatusTray seamless />@@ -126,8 +137,17 @@ const FeedbackInput = memo<FeedbackInputProps>(}return (- <Flexbox gap={8}>- <OpStatusTray seamless />+ <Flexbox gap={hasQueuedMessages ? 0 : 8}>+ {hasQueuedMessages ? (+ // Same stack as the main composer: the queue and the run status ride+ // flush on the input as attached cards, inset from its edges.+ <Flexbox paddingInline={12}>+ <QueueTray />+ <OpStatusTray topAttached />+ </Flexbox>+ ) : (+ <OpStatusTray seamless />+ )}<ChatInputmaxHeight={240}minHeight={64}@@ -136,7 +156,7 @@ const FeedbackInput = memo<FeedbackInputProps>(style={{ paddingInline: 8 }}left={<Flexbox horizontal align={'center'} gap={2}>- {!disableCollapse && (+ {!disableCollapse && !hasQueuedMessages && (<Button icon={ChevronDownIcon} size={'small'} type={'text'} onClick={collapse}>{t('taskDetail.collapseReply')}</Button>diff --git a/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/useComposerFocus.ts b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/useComposerFocus.tsindex c0255affa89..61c29c6c4a2 100644--- a/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/useComposerFocus.ts+++ b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/useComposerFocus.ts@@ -49,5 +49,9 @@ export const useComposerFocus = ({const collapse = useCallback(() => setExpanded(false), []);- return { collapse, expand, expanded, handleEditorInit };+ // Open the composer for content that arrives on its own (a queued follow-up)+ // without taking focus: nothing the user did asked to write.+ const reveal = useCallback(() => setExpanded(true), []);++ return { collapse, expand, expanded, handleEditorInit, reveal };};diff --git a/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/useFollowUpQueue.test.ts b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/useFollowUpQueue.test.tsnew file mode 100644index 00000000000..90905c210f2--- /dev/null+++ b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/useFollowUpQueue.test.ts@@ -0,0 +1,109 @@+/**+ * @vitest-environment happy-dom+ */+import type { IEditor } from '@lobehub/editor';+import { renderHook } from '@testing-library/react';+import { beforeEach, describe, expect, it, vi } from 'vitest';++import { useComposerFocus } from './useComposerFocus';+import { useFollowUpQueue } from './useFollowUpQueue';++const mocks = vi.hoisted(() => {+ const context = { agentId: 'agt_assignee', isolatedTopic: true, scope: 'main', topicId: 'tpc_1' };+ return {+ context,+ conversationState: { context, editor: undefined as unknown },+ queuedCount: 0,+ restoreServerQueue: vi.fn(),+ };+});++vi.mock('@/features/Conversation/ChatInput/useRestoreServerQueue', () => ({+ useRestoreServerQueue: mocks.restoreServerQueue,+}));+vi.mock('@/features/Conversation/store', () => ({+ useConversationStore: (selector: (state: typeof mocks.conversationState) => unknown) =>+ selector(mocks.conversationState),+ useConversationStoreApi: () => ({+ setState: (patch: Partial<typeof mocks.conversationState>) =>+ Object.assign(mocks.conversationState, patch),+ }),+}));+vi.mock('@/store/chat', () => ({+ useChatStore: (selector: (state: object) => unknown) => selector({}),+}));+vi.mock('@/store/chat/selectors', () => ({+ operationSelectors: { queuedMessageCount: () => () => mocks.queuedCount },+}));++const editor = { focus: vi.fn() } as unknown as IEditor;+const reveal = vi.fn();++describe('useFollowUpQueue', () => {+ beforeEach(() => {+ mocks.queuedCount = 0;+ mocks.conversationState.editor = undefined;+ mocks.restoreServerQueue.mockClear();+ });++ it('shows the queue and keeps the composer open while a follow-up waits', () => {+ mocks.queuedCount = 1;++ const { result } = renderHook(() =>+ useFollowUpQueue({ editor, enabled: true, expanded: false, reveal }),+ );++ expect(result.current).toEqual({ composerExpanded: true, hasQueuedMessages: true });+ });++ it('hands the drawer editor to the conversation so Edit can refill it', () => {+ renderHook(() => useFollowUpQueue({ editor, enabled: true, expanded: true, reveal }));++ expect(mocks.conversationState.editor).toBe(editor);+ });++ it('restores the follow-ups still queued on the server for this conversation', () => {+ renderHook(() => useFollowUpQueue({ editor, enabled: true, expanded: false, reveal }));++ expect(mocks.restoreServerQueue).toHaveBeenCalledWith(mocks.context, true);+ });++ it('leaves the composer as the user set it when nothing is queued', () => {+ const { result } = renderHook(() =>+ useFollowUpQueue({ editor, enabled: true, expanded: false, reveal }),+ );++ expect(result.current).toEqual({ composerExpanded: false, hasQueuedMessages: false });+ });++ it('keeps the composer open after Edit takes the last queued follow-up out', () => {+ mocks.queuedCount = 1;+ const { result, rerender } = renderHook(() => {+ const focus = useComposerFocus({ defaultExpanded: false, editor });+ return useFollowUpQueue({+ editor,+ enabled: true,+ expanded: focus.expanded,+ reveal: focus.reveal,+ });+ });++ // Edit withdraws the only queued message into the editor.+ mocks.queuedCount = 0;+ rerender();++ expect(result.current).toEqual({ composerExpanded: true, hasQueuedMessages: false });+ expect(editor.focus).not.toHaveBeenCalled();+ });++ it('shows no queue to a viewer who cannot reply', () => {+ mocks.queuedCount = 1;++ const { result } = renderHook(() =>+ useFollowUpQueue({ editor, enabled: false, expanded: false, reveal }),+ );++ expect(result.current).toEqual({ composerExpanded: false, hasQueuedMessages: false });+ expect(mocks.restoreServerQueue).toHaveBeenCalledWith(mocks.context, false);+ });+});diff --git a/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/useFollowUpQueue.ts b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/useFollowUpQueue.tsnew file mode 100644index 00000000000..4510205c5ee--- /dev/null+++ b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/useFollowUpQueue.ts@@ -0,0 +1,54 @@+import { type IEditor } from '@lobehub/editor';+import { useEffect } from 'react';++import { useRestoreServerQueue } from '@/features/Conversation/ChatInput/useRestoreServerQueue';+import { useConversationStore, useConversationStoreApi } from '@/features/Conversation/store';+import { useChatStore } from '@/store/chat';+import { operationSelectors } from '@/store/chat/selectors';++interface UseFollowUpQueueParams {+ /** The drawer's own composer editor, which the queue's Edit refills. */+ editor?: IEditor | null;+ /** Whether the viewer may reply; a view-only member never queues follow-ups. */+ enabled: boolean;+ /** Whether the user has the composer open. */+ expanded: boolean;+ /** Opens the composer without focusing it. */+ reveal: () => void;+}++/**+ * Wires the drawer composer to the follow-up queue the main chat input shows.+ *+ * A follow-up typed while the run works is queued, not sent; without this the+ * drawer showed nothing until the run took it in as a steered message, so it+ * could not be read, edited or withdrawn.+ *+ * Returns:+ * - `hasQueuedMessages`: whether the queue tray has rows to show.+ * - `composerExpanded`: whether the composer must be open. A queued follow-up+ * opens it for good, not only while queued: Edit withdraws the last message+ * into the editor, which empties the queue, and a composer that collapsed then+ * would lose the text.+ */+export const useFollowUpQueue = ({ editor, enabled, expanded, reveal }: UseFollowUpQueueParams) => {+ const context = useConversationStore((s) => s.context);+ const storeApi = useConversationStoreApi();++ useRestoreServerQueue(context, enabled);+ const hasQueuedMessages = useChatStore(+ (s) => enabled && operationSelectors.queuedMessageCount(context)(s) > 0,+ );++ // Set the editor on this conversation only: the store's `setEditor` also+ // claims the global main-input editor, which belongs to the chat behind the drawer.+ useEffect(() => {+ if (editor) storeApi.setState({ editor });+ }, [editor, storeApi]);++ useEffect(() => {+ if (hasQueuedMessages) reveal();+ }, [hasQueuedMessages, reveal]);++ return { composerExpanded: expanded || hasQueuedMessages, hasQueuedMessages };+};diff --git a/src/features/Conversation/ChatInput/utils.test.ts b/src/features/Conversation/ChatInput/utils.test.tsindex b4cf037c0c6..9e5ce414571 100644--- a/src/features/Conversation/ChatInput/utils.test.ts+++ b/src/features/Conversation/ChatInput/utils.test.ts@@ -380,6 +380,24 @@ describe('sendQueuedMessageNow', () => {);});+ it('sends on the runtime the item was queued for', async () => {+ // A task-run drawer queues follow-ups with `forceRuntime: 'gateway'`; Send+ // now must not fall back to the user's global runtime preference.+ const { chat } = chatWith(true);++ await sendQueuedMessageNow({+ chat,+ context,+ contextKey: messageMapKey(context),+ msg: { ...msg, forceRuntime: 'gateway' },+ withdraw: async () => true,+ });++ expect(chat.sendMessage).toHaveBeenCalledWith(+ expect.objectContaining({ forceRuntime: 'gateway', message: 'now' }),+ );+ });+it('stops nothing and sends nothing when the run already took it', async () => {const { chat } = chatWith(true);diff --git a/src/features/Conversation/ChatInput/utils.ts b/src/features/Conversation/ChatInput/utils.tsindex 8cdf8df86ad..9c1a9c371ca 100644--- a/src/features/Conversation/ChatInput/utils.ts+++ b/src/features/Conversation/ChatInput/utils.ts@@ -246,6 +246,9 @@ export const sendQueuedMessageNow = async ({context,editorData: msg.editorData,files,+ // Keep the runtime the item was queued for (a task-run drawer forces the+ // gateway), as the queue drain does.+ ...(msg.forceRuntime ? { forceRuntime: msg.forceRuntime } : {}),message: msg.content,metadata: { ...msg.metadata, steer: true },});