Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): 伙伴聊天点「回复」后输入框自动获得焦点
Chrisc3527868d6d3
diff --git a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsxindex 1a4cd4b3cb..973ed2d746 100644--- a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx+++ b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx@@ -803,6 +803,11 @@ interface ChatInputProps {* 嵌入式 rail / split pane 保持 false,避免抢走当前页面快捷键或其它 pane 的焦点。*/focusOnStorageKeyChange?: boolean;+ /**+ * Each new non-null value (after mount) brings the caret back into the editor, e.g. picking+ * 「回复」 on a companion message puts its quote above this composer, ready to type the reply.+ */+ focusRequest?: unknown;/*** Whether this composer should consume hardware send / voice / text commands.* Split panes keep every ChatInput mounted; only the focused owner may act.@@ -1302,6 +1307,7 @@ export function ChatInput({draftKey,disableAutofocus = false,focusOnStorageKeyChange = false,+ focusRequest,ownsHardwareComposerActions = true,extraDirs,writableDirs,@@ -4298,6 +4304,16 @@ export function ChatInput({}}, [editor, storageKey]);+ // A focus request from the owner (see the `focusRequest` prop). The caret goes back to where+ // it was; an editor that already has focus (mid IME composition included) is left alone.+ const focusRequestRef = useRef(focusRequest);+ useEffect(() => {+ if (focusRequestRef.current === focusRequest) return;+ focusRequestRef.current = focusRequest;+ if (focusRequest == null || !editor || editor.isDestroyed || !editor.isEditable || editor.isFocused) return;+ editor.commands.focus();+ }, [editor, focusRequest]);+// ── External draft writes for the CURRENT session (e.g. rewind / fork// pre-fill called saveComposerDraft from outside) ──// The restore-on-sessionId-change effect above only fires when sessionIddiff --git a/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputAnnotationAbort.test.tsx b/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputAnnotationAbort.test.tsxindex 87d9f057b2..bff42b0b8f 100644--- a/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputAnnotationAbort.test.tsx+++ b/apps/desktop/src/renderer/components/new-chat/__tests__/chatInputAnnotationAbort.test.tsx@@ -193,6 +193,28 @@ it('does not replace the empty editor after an external empty-draft notificationexpect(h.editor!.state.selection.from).toBe(1);});+// Companion chat 「回复」 bug: the quote appeared above the composer but focus stayed on the+// message's button. Each new quote (also a second one on the same message) is a new request.+it('focuses the editor for each new focus request, not on mount or a repeated value', async () => {+ supplyRangeGeometry();+ const quote = { clientId: 'm1' };+ const view = renderComposer({ focusRequest: quote });+ await waitFor(() => expect(h.editor).not.toBeNull());+ expect(h.editor!.isFocused).toBe(false);+ const outside = document.body.appendChild(document.createElement('button'));+ view.rerender(<ChatInput {...view.props} focusRequest={quote} />);+ expect(h.editor!.isFocused).toBe(false);+ view.rerender(<ChatInput {...view.props} focusRequest={null} />);+ expect(h.editor!.isFocused).toBe(false);+ view.rerender(<ChatInput {...view.props} focusRequest={{ clientId: 'm1' }} />);+ await waitFor(() => expect(h.editor!.isFocused).toBe(true));+ outside.focus();+ expect(h.editor!.isFocused).toBe(false);+ view.rerender(<ChatInput {...view.props} focusRequest={{ clientId: 'm1' }} />);+ await waitFor(() => expect(h.editor!.isFocused).toBe(true));+ outside.remove();+});+it('does not rehydrate an empty stored document when voice busy state changes', async () => {saveDraft('composer-regression', { text: { type: 'doc', content: [{ type: 'paragraph' }] }, attachments: [] });const view = renderComposer();diff --git a/apps/desktop/src/renderer/features/bots/BotDmThreadViews.tsx b/apps/desktop/src/renderer/features/bots/BotDmThreadViews.tsxindex 3368370f86..10071c123b 100644--- a/apps/desktop/src/renderer/features/bots/BotDmThreadViews.tsx+++ b/apps/desktop/src/renderer/features/bots/BotDmThreadViews.tsx@@ -120,6 +120,7 @@ export function BotDmThreadPanel({ bot, rootSessionId, rootClientId, state, mentmessageStreamHeader={threadRoot}compactcompactToolbar+ focusComposerOnOpenviewVisiblenavigationMode="sidebar-embedded"sidebarTargetSessionId={rootSessionId}diff --git a/apps/desktop/src/renderer/features/bots/BotGroupComposer.tsx b/apps/desktop/src/renderer/features/bots/BotGroupComposer.tsxindex 38155f37f5..4e0e954993 100644--- a/apps/desktop/src/renderer/features/bots/BotGroupComposer.tsx+++ b/apps/desktop/src/renderer/features/bots/BotGroupComposer.tsx@@ -252,7 +252,7 @@ export function BotGroupComposer({attachmentsRef.current = attachmentState.attachments;const quoteRef = useRef(quote?.view ?? null);quoteRef.current = quote?.view ?? null;- const quotedMessageId = quote?.view.messageId ?? null;+ const quoteView = quote?.view ?? null;const focusInputOnMenuCloseRef = useRef(false);const sendingRef = useRef(false);const stoppingRef = useRef(false);@@ -278,10 +278,11 @@ export function BotGroupComposer({const showStop = !thread && running && trimmed.length === 0 && attachmentCount === 0;const divisionBlocked = isBotGroupDivisionBlocked(planState);- // Picking 引用回复 brings the caret here, ready to type the reply.+ // Picking 引用回复 brings the caret here, ready to type the reply; picking the same message+ // again (after clicking elsewhere) does too, since each pick is a new quote.useEffect(() => {- if (quotedMessageId) textareaRef.current?.focus();- }, [quotedMessageId]);+ if (quoteView) textareaRef.current?.focus();+ }, [quoteView]);// Keep the unsent text with the group (or 话题), like a task's composer draft.const discardTokenRef = useRef(captureDraftDiscardToken(draftKey));diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsxindex 35af6dceb5..2e10633506 100644--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx@@ -561,6 +561,8 @@ interface CCAgentSessionViewProps {sidebarTargetSessionId?: string;/** 禁止该常驻视图在挂载时抢占键盘焦点(例如非 owner 的分屏 pane)。 */disableAutofocus?: boolean;+ /** 打开就是为了输入的紧凑视图(伙伴私聊话题面板):照常把焦点放进输入框。 */+ focusComposerOnOpen?: boolean;/** 历史回查只读视图:保留消息流与上下文,但不允许发送或修改 Session。 */readOnly?: boolean;/** Bot 路由提供的其它持久 Bot,交给标准输入框作为结构化委派目标。 */@@ -844,6 +846,7 @@ function CCAgentSessionContent({onSessionNavigate,sidebarTargetSessionId,disableAutofocus = false,+ focusComposerOnOpen = false,readOnly = false,botMentions,botIdentity,@@ -6073,6 +6076,8 @@ function CCAgentSessionContent({<BotChatQuoteComposerPreview sessionId={sessionId} quote={pendingReplyQuote}getMessage={getQuoteMessage} names={botQuoteNames} />) : remoteMakeCards.handlesSession ? <SessionResourceCards state={remoteMakeCards} /> : undefined}+ // Picking 「回复」 brings the caret here, ready to type the reply.+ focusRequest={pendingReplyQuote}onSend={handleSend}onComposerTyping={handleComposerTyping}onBeforeVoiceInputStart={handleBeforeVoiceInputStart}@@ -6167,8 +6172,8 @@ function CCAgentSessionContent({// doc 模式右栏:不抢焦点,避免 TipTap contenteditable 激活// Windows 中文 IME 后,Ctrl+Shift+F 等组合键被 OS 层吞掉。// 详见 ChatInput 的 disableAutofocus prop 注释。- disableAutofocus={isCompactRail || disableAutofocus}- focusOnStorageKeyChange={ownsRoute}+ disableAutofocus={(isCompactRail && !focusComposerOnOpen) || disableAutofocus}+ focusOnStorageKeyChange={ownsRoute || focusComposerOnOpen}// F-COLLAB:「+」菜单里的协同模式项。普通 Lead 的项目/对话会话都渲染,// 项目级与用户级策略范围由 collabEntry 决定;只排除 Worker 子会话// (worker 自己不能再开协同)。