Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): 群聊主输入框接入 #5972 的共享外观与行为
Chris433cd0518712
diff --git a/apps/desktop/src/renderer/features/bots/BotGroupComposer.tsx b/apps/desktop/src/renderer/features/bots/BotGroupComposer.tsxindex 061776902e..18847088b0 100644--- a/apps/desktop/src/renderer/features/bots/BotGroupComposer.tsx+++ b/apps/desktop/src/renderer/features/bots/BotGroupComposer.tsx@@ -64,6 +64,17 @@ import {import type { AttachedFile } from '@/lib/fileTypes';import { toast } from '@/lib/toast';import { cn } from '@/lib/utils';+import {+ BOT_GROUP_COMPOSER_CARD,+ BOT_GROUP_COMPOSER_COLUMN,+ BOT_GROUP_COMPOSER_DOCK,+ BOT_GROUP_COMPOSER_FOOTER,+ BOT_GROUP_COMPOSER_FOOTER_START,+ BOT_GROUP_COMPOSER_INPUT,+ fitBotGroupComposerInput,+ keepBotGroupComposerInputFocus,+ useRefitBotGroupComposerInputOnResize,+} from './botGroupComposerChrome';import {BOT_GROUP_ATTACHMENTS_MAX,BOT_GROUP_MESSAGE_MAX_CHARS,@@ -282,13 +293,12 @@ export function BotGroupComposer({}, [persistDraft, text]);useEffect(() => () => persistDraft(textRef.current), [persistDraft]);- // Auto-grow; the CSS max height caps it and turns on scrolling.+ // Auto-grow; the CSS max height caps it and turns on scrolling. A width change (window+ // resize, the 话题 panel opening) rewraps the text, so the height is fitted again then.useLayoutEffect(() => {- const element = textareaRef.current;- if (!element) return;- element.style.height = 'auto';- element.style.height = `${element.scrollHeight}px`;+ if (textareaRef.current) fitBotGroupComposerInput(textareaRef.current);}, [text]);+ useRefitBotGroupComposerInputOnResize(textareaRef);/*** 话题 reply: a retry reuses the attempt only for the same text and the same targets@@ -517,8 +527,8 @@ export function BotGroupComposer({const noop = () => undefined;return (- <div className={cn('shrink-0 pb-4 pt-2', thread ? 'px-4' : 'px-5')}>- <div className="relative mx-auto w-full max-w-[760px]">+ <div className={cn(BOT_GROUP_COMPOSER_DOCK, thread && 'px-4')}>+ <div className={BOT_GROUP_COMPOSER_COLUMN}>{error ? <p role="alert" className="mb-2 text-13 text-[var(--error-fg)]">{error}</p> : null}{/* Same floating slot above the card as a task's composer: files that did not attach. */}{attachmentState.rejections.length > 0 ? (@@ -530,7 +540,7 @@ export function BotGroupComposer({</div>) : null}{mention.list}- <div className="relative flex flex-col gap-2 rounded-xl border border-[var(--chat-input-border)] bg-[var(--chat-input-bg)] px-3.5 pb-2.5 pt-3 transition-colors focus-within:border-[var(--chat-input-border-focus)]">+ <div className={BOT_GROUP_COMPOSER_CARD}>{dragOver ? (<divdata-testid="bot-group-drop-hint"@@ -613,10 +623,10 @@ export function BotGroupComposer({setDivision(false);}}}- className="max-h-60 min-h-6 w-full resize-none overflow-y-auto bg-transparent text-15 leading-[1.6] text-[var(--chat-input-text)] outline-none placeholder:text-[var(--chat-input-placeholder)] focus-visible:outline-none"+ className={BOT_GROUP_COMPOSER_INPUT}/>- <div className="flex min-h-7 items-center justify-between gap-3">- <div className="flex min-w-0 items-center gap-2">+ <div className={BOT_GROUP_COMPOSER_FOOTER}>+ <div className={BOT_GROUP_COMPOSER_FOOTER_START}>{thread ? null : (<><inputref={fileInputRef}@@ -697,14 +707,17 @@ export function BotGroupComposer({{hint}</span></div>- <Tip text={actionLabel}>- <SendButton- disabled={showStop ? stopping : !canSend}- isStreaming={showStop}- ariaLabel={actionLabel}- onClick={() => void (showStop ? stop() : send())}- />- </Tip>+ {/* A mouse click must not move the caret out of the input (the button disables itself right after). */}+ <span className="inline-flex rounded-full" onMouseDown={keepBotGroupComposerInputFocus(textareaRef)}>+ <Tip text={actionLabel}>+ <SendButton+ disabled={showStop ? stopping : !canSend}+ isStreaming={showStop}+ ariaLabel={actionLabel}+ onClick={() => void (showStop ? stop() : send())}+ />+ </Tip>+ </span></div></div></div>diff --git a/apps/desktop/src/renderer/features/bots/__tests__/ChatServerControls.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/ChatServerControls.test.tsxindex 3a9fe2dcf9..d94e836c4d 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/ChatServerControls.test.tsx+++ b/apps/desktop/src/renderer/features/bots/__tests__/ChatServerControls.test.tsx@@ -5,6 +5,8 @@ import { Tooltip } from '@/components/ui/tooltip';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { ChatInviteButton, ChatJoinButton, ChatMessageActions } from '../ChatServerControls';import { ChatThreadPanel } from '../ChatThreadPanel';+import { botGroupThreadDraftKey } from '../botGroupAttachments';+import { clearDraft } from '@/lib/composerDraftStore';import type { BotGroupDetail, BotGroupMessageView } from '../../../../shared/botGroupChat';import { shareSelectionStore } from '@/components/chat/shareSelectionStore';import { queryShareableMessageIds, stripInteractiveElements } from '@/lib/shareConversationImage';@@ -32,6 +34,8 @@ const render = (ui: ReactNode) => renderUI(<Tooltip.Provider>{ui}</Tooltip.ProvibeforeEach(() => {vi.clearAllMocks(); mocks.ownerCurrent = true;shareSelectionStore.reset();+ // The thread reply keeps a draft per thread; one test's unsent text must not start the next.+ clearDraft(botGroupThreadDraftKey(group.id, 'root'));vi.stubGlobal('ResizeObserver', class { observe() {} disconnect() {} });mocks.status.mockResolvedValue({ enabled: true, connected: true });mocks.react.mockResolvedValue({ ok: true });@@ -75,23 +79,26 @@ describe('chat interaction controls', () => {expect(input.style.height).toBe('96px');});- it('keeps a sending thread reply focused and locked, then sends it only once', async () => {+ it('keeps the focus in a sending thread reply, shows it in the thread at once, and sends it only once', async () => {let settle: (value: { ok: true; messageId: string }) => void = () => {};mocks.reply.mockReturnValue(new Promise(resolve => { settle = resolve; }));render(<ChatThreadPanel group={group} rootId="root" onClose={vi.fn()} />);const input = screen.getByRole('textbox', { name: k('replyPlaceholder') }) as HTMLTextAreaElement;const sendButton = screen.getByRole('button', { name: k('sendReply') }) as HTMLButtonElement;expect(sendButton.disabled).toBe(true);+ input.focus();fireEvent.change(input, { target: { value: 'In flight' } });fireEvent.keyDown(input, { key: 'Enter' });- await waitFor(() => expect(input.readOnly).toBe(true));+ // Optimistic: the reply moves into the thread while main answers; the input is free again but+ // nothing else goes out until this reply settles.+ await waitFor(() => expect(input.value).toBe(''));expect(document.activeElement).toBe(input);expect(sendButton.disabled).toBe(true);fireEvent.keyDown(input, { key: 'Enter' });fireEvent.click(sendButton);expect(mocks.reply).toHaveBeenCalledOnce();settle({ ok: true, messageId: 'reply' });- await waitFor(() => expect(input.value).toBe(''));+ await waitFor(() => expect(mocks.reply).toHaveBeenCalledOnce());expect(input.readOnly).toBe(false);expect(document.activeElement).toBe(input);});@@ -357,21 +364,22 @@ describe('chat interaction controls', () => {expect(mocks.reply).toHaveBeenCalledOnce();});- it('keeps the list closed while a reply is sending, so the read-only text cannot change', async () => {+ it('closes the list once a reply is sent, so a late pick cannot rewrite what went out', async () => {const input = renderThread();let settle: (value: { ok: true; messageId: string }) => void = () => {};mocks.reply.mockReturnValue(new Promise(resolve => { settle = resolve; }));type(input, '@B');expect(labels()).toContain('Bo');fireEvent.click(screen.getByRole('button', { name: k('sendReply') }));- await waitFor(() => expect(input.readOnly).toBe(true));+ // The reply left the input the moment it was sent; the picker has nothing to complete.+ await waitFor(() => expect(input.value).toBe(''));expect(screen.queryByRole('listbox')).toBeNull();fireEvent.keyDown(input, { key: 'Enter' });fireEvent.keyDown(input, { key: 'Tab' });- expect(input.value).toBe('@B');+ expect(input.value).toBe('');settle({ ok: true, messageId: 'reply' });- await waitFor(() => expect(input.value).toBe(''));- expect(mocks.reply).toHaveBeenCalledOnce();+ await waitFor(() => expect(mocks.reply).toHaveBeenCalledOnce());+ expect(screen.queryByRole('listbox')).toBeNull();});it('treats an e-mail address as text and forgets a pick once its name is edited', async () => {