Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

feat(bots): 支持群聊话题面板拖拽调宽

xuzini-xzn44754221c5bc
diff --git a/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx b/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx
index 8a9253ed2a..0e5a2c4ff6 100644
--- a/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx
+++ b/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx
@@ -1,4 +1,6 @@
import { RemoveChatFromListButton } from './RemoveChatFromListButton';
+import { useThreadPanelResize } from './useThreadPanelResize';
+import { cn } from '@/lib/utils';
/**
* 群聊页:顶栏(成员头像、群名、成员与负责人、此刻谁在做什么、群设置入口)+ 多作者时间线 +
* 进行中条 + 输入框。
@@ -559,17 +561,22 @@ function BotGroupChatContent({ groupId }: { groupId: string }) {
const threadLayoutRef = useRef<HTMLDivElement>(null);
const threadHeaderRef = useRef<HTMLDivElement>(null);
const threadCloseAnimationRef = useRef<Animation | null>(null);
+ const threadOpenAnimationRef = useRef<Animation | null>(null);
+ const cancelThreadOpening = useCallback(() => threadOpenAnimationRef.current?.cancel(), []);
+ const threadResize = useThreadPanelResize(threadLayoutRef, threadRootId, cancelThreadOpening);
const threadWasOpenRef = useRef(false);
useLayoutEffect(() => {
const opening = !!threadRootId && !threadWasOpenRef.current;
threadWasOpenRef.current = !!threadRootId;
if (!opening) return;
const panel = threadLayoutRef.current?.querySelector('aside');
- const animation = panel && animateThreadPanelWidth(panel, '0px', '50%');
+ const animation = panel && animateThreadPanelWidth(panel, '0px',
+ threadResize.width === undefined ? '50%' : `${threadResize.width}px`);
if (!animation) return;
+ threadOpenAnimationRef.current = animation;
void animation.finished.then(() => animation.cancel(), () => {});
return () => animation.cancel();
- }, [threadRootId]);
+ }, [threadRootId, threadResize.width]);
const closeThread = useCallback(() => {
if (threadCloseAnimationRef.current) return;
const panel = threadLayoutRef.current?.querySelector('aside');
@@ -1053,7 +1060,7 @@ function BotGroupChatContent({ groupId }: { groupId: string }) {
const enterAfter = enterAfterRef.current;
return (
- <div ref={threadLayoutRef} className="flex h-full min-w-0 overflow-hidden">
+ <div ref={threadLayoutRef} className={cn('flex h-full min-w-0 overflow-hidden', threadResize.isDragging && 'select-none [&_*]:cursor-col-resize')}>
<main
className="relative flex h-full min-w-0 flex-1 flex-col overflow-hidden bg-[var(--surface)]"
onDragEnter={(event) => {
@@ -1248,7 +1255,7 @@ function BotGroupChatContent({ groupId }: { groupId: string }) {
) : null}
</main>
{group.serverBacked && threadRootId && <ChatThreadPanel key={`${group.id}:${threadRootId}`} group={group} rootId={threadRootId} quoteSources={quoteSources}
- focus={threadFocus} sharedReplies={sharedReplies} onRevealShare={revealMainMessage} onClose={closeThread} />}
+ focus={threadFocus} sharedReplies={sharedReplies} onRevealShare={revealMainMessage} onClose={closeThread} resize={threadResize} />}
</div>
);
}
diff --git a/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsx b/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsx
index 58f0fcdbef..464a76ae68 100644
--- a/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsx
+++ b/apps/desktop/src/renderer/features/bots/ChatThreadPanel.tsx
@@ -36,6 +36,7 @@ import {
type BotGroupTimelineMessage,
} from './BotGroupTimelineModel';
import { chatErrorKey, messageReactionRevision } from './ChatServerControls';
+import type { ThreadPanelResize } from './useThreadPanelResize';
const key = (name: string) => `bots.groupChat.server.${name}`;
const api = () => window.electronAPI.maker.chatServer;
const STICK_TO_BOTTOM_PX = 48;
@@ -148,7 +149,7 @@ export function animateThreadPanelWidth(panel: HTMLElement, from: string, to: st
* `quoteSources` are the main timeline's verified messages (older pages included), so a
* 话题 root's quote reads the same as it does in the timeline; without them, the latest page.
*/
-export function ChatThreadPanel({ group, rootId, quoteSources = group.messages, focus, sharedReplies, onRevealShare, onClose }: {
+export function ChatThreadPanel({ group, rootId, quoteSources = group.messages, focus, sharedReplies, onRevealShare, onClose, resize }: {
group: BotGroupDetail; rootId: string; quoteSources?: readonly BotGroupMessageView[];
/** A reply to bring into view; a new nonce repeats the jump. */
focus?: { messageId: string; nonce: number } | null;
@@ -156,6 +157,7 @@ export function ChatThreadPanel({ group, rootId, quoteSources = group.messages,
/** Scroll the main chat to a share; false when it is not loaded there. */
onRevealShare?: (messageId: string) => boolean;
onClose: () => void;
+ resize?: ThreadPanelResize;
}) {
const { t, i18n } = useTranslation();
const locale = i18n.language;
@@ -484,7 +486,8 @@ export function ChatThreadPanel({ group, rootId, quoteSources = group.messages,
const firstNewId = firstNewIndex > 0 ? replyRows[firstNewIndex]!.id : null;
return <aside ref={panelRef} aria-labelledby={titleId}
- className="flex h-full min-w-0 w-1/2 max-w-[min(50%,28rem)] shrink-0 flex-col overflow-hidden border-l border-[var(--border-default)] bg-[var(--surface)]">
+ style={resize?.width === undefined ? undefined : { width: resize.width, maxWidth: 'none' }}
+ className="relative flex h-full min-w-0 w-1/2 max-w-[min(50%,28rem)] shrink-0 flex-col overflow-hidden border-l border-[var(--border-default)] bg-[var(--surface)]">
<header className="flex h-14 shrink-0 items-center justify-between border-b border-[var(--border-default)] px-5">
<h2 id={titleId} className="text-15 font-medium text-[var(--text-primary)]">{t(key('topic'))}</h2>
<div className="flex items-center gap-1">
@@ -568,5 +571,9 @@ export function ChatThreadPanel({ group, rootId, quoteSources = group.messages,
/>
</div>
</>}
+ {/* Keep the existing Shift+Tab route from Close back into the group. */}
+ {resize && <div role="separator" aria-orientation="vertical" aria-label={t('diffPanel.shell.resizeHandleAria')}
+ tabIndex={0} {...resize.handleProps}
+ className="absolute inset-y-0 left-0 z-10 w-2 touch-none cursor-col-resize hover:border-l hover:border-[var(--text-tertiary)] focus-visible:border-l focus-visible:border-[var(--focus-ring)] focus-visible:outline-none" />}
</aside>;
}
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
index 85206a5825..891b9ccbdb 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
@@ -500,6 +500,134 @@ describe('BotGroupChatView', () => {
} finally { cleanup(); motion.restore(); }
});
+ describe('thread width resizing', () => {
+ let available = 1200;
+ const observed = new Map<Element, ResizeObserverCallback>();
+ let restoreGeometry: () => void;
+
+ beforeEach(() => {
+ available = 1200;
+ observed.clear();
+ vi.stubGlobal('ResizeObserver', class {
+ constructor(private callback: ResizeObserverCallback) {}
+ observe(element: Element) { observed.set(element, this.callback); }
+ disconnect() {}
+ });
+ vi.stubGlobal('PointerEvent', class extends MouseEvent {
+ pointerId: number;
+ isPrimary: boolean;
+ constructor(type: string, init: PointerEventInit = {}) {
+ super(type, init);
+ this.pointerId = init.pointerId ?? 1;
+ this.isPrimary = init.isPrimary ?? true;
+ }
+ });
+ const original = HTMLElement.prototype.getBoundingClientRect;
+ const geometry = vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function (this: HTMLElement) {
+ if (this.tagName === 'ASIDE') return new DOMRect(0, 0, Number.parseFloat(this.style.width) || 448, 800);
+ if (this.querySelector(':scope > main')) return new DOMRect(0, 0, available, 800);
+ return original.call(this);
+ });
+ restoreGeometry = () => geometry.mockRestore();
+ mocks.getBotGroup.mockResolvedValue({ ok: true, group: detail({ serverBacked: true }) });
+ });
+ afterEach(() => { restoreGeometry(); });
+
+ async function openResizableThread() {
+ renderView();
+ const triggers = await screen.findAllByRole('button', { name: 'bots.groupChat.server.startTopic' });
+ fireEvent.click(triggers[0]!);
+ await screen.findByText('Reply to u1');
+ const panel = screen.getByRole('complementary');
+ const handle = within(panel).getByRole('separator', { name: 'diffPanel.shell.resizeHandleAria' });
+ Object.assign(handle, { setPointerCapture: vi.fn(), hasPointerCapture: () => true, releasePointerCapture: vi.fn() });
+ return { panel, handle, triggers };
+ }
+
+ it('only changes the width, keeping both inputs, message rows and scrolling in place', async () => {
+ const { panel, handle } = await openResizableThread();
+ const main = screen.getByRole('main');
+ const groupInput = within(main).getByRole('textbox');
+ const replyInput = within(panel).getByRole('textbox');
+ const message = screen.getByText('周六 8:10 有票').closest('article');
+ const timeline = screen.getByTestId('bot-group-timeline');
+ timeline.scrollTop = 25;
+ fireEvent.change(groupInput, { target: { value: 'Group draft' } });
+ fireEvent.change(replyInput, { target: { value: 'Reply draft' } });
+ expect(panel.style.width).toBe('');
+ expect(panel.style.maxWidth).toBe('');
+ fireEvent.pointerDown(handle, { button: 0, pointerId: 1, clientX: 752 });
+ fireEvent.pointerMove(handle, { pointerId: 2, clientX: 100 });
+ expect(panel.style.width).toBe('');
+ fireEvent.pointerMove(handle, { pointerId: 1, clientX: 552 });
+ expect(panel.style.width).toBe('648px');
+ expect(panel.style.maxWidth).toBe('none');
+ expect(handle.getAttribute('aria-valuenow')).toBe('648');
+ fireEvent.pointerUp(handle, { pointerId: 1 });
+ fireEvent.pointerMove(handle, { pointerId: 1, clientX: 100 });
+ expect(panel.style.width).toBe('648px');
+ expect(within(main).getByRole('textbox')).toBe(groupInput);
+ expect(within(panel).getByRole('textbox')).toBe(replyInput);
+ expect((groupInput as HTMLTextAreaElement).value).toBe('Group draft');
+ expect((replyInput as HTMLTextAreaElement).value).toBe('Reply draft');
+ expect(screen.getByText('周六 8:10 有票').closest('article')).toBe(message);
+ expect(screen.getByTestId('bot-group-timeline')).toBe(timeline);
+ expect(timeline.scrollTop).toBe(25);
+ // Dragging must not acquire a CSS transition that would lag behind the pointer.
+ expect(panel.className).not.toMatch(/transition/);
+ });
+
+ it('bounds both columns, adapts to container resizing, and ends cancelled pointer gestures', async () => {
+ const { panel, handle } = await openResizableThread();
+ fireEvent.pointerDown(handle, { button: 2, clientX: 752 });
+ fireEvent.pointerMove(handle, { clientX: 100 });
+ expect(panel.style.width).toBe('');
+ fireEvent.pointerDown(handle, { button: 0, pointerId: 1, clientX: 752 });
+ fireEvent.pointerMove(handle, { pointerId: 1, clientX: -1000 });
+ expect(panel.style.width).toBe('800px');
+ fireEvent.pointerCancel(handle, { pointerId: 1 });
+ fireEvent.pointerMove(handle, { pointerId: 1, clientX: 2000 });
+ expect(panel.style.width).toBe('800px');
+ const layout = panel.parentElement!;
+ available = 600;
+ act(() => observed.get(layout)!([], {} as ResizeObserver));
+ expect(panel.style.width).toBe('360px');
+ available = 1200;
+ act(() => observed.get(layout)!([], {} as ResizeObserver));
+ expect(panel.style.width).toBe('800px');
+ fireEvent.pointerDown(handle, { button: 0, pointerId: 3, clientX: 400 });
+ fireEvent.pointerMove(handle, { pointerId: 3, clientX: 2000 });
+ expect(panel.style.width).toBe('280px');
+ fireEvent.lostPointerCapture(handle, { pointerId: 3 });
+ fireEvent.pointerMove(handle, { pointerId: 3, clientX: 0 });
+ expect(panel.style.width).toBe('280px');
+ });
+
+ it('keeps the chosen width when switching topics and reopening, with the existing open/close motion', async () => {
+ const motion = mockThreadMotion('200ms');
+ try {
+ const { panel, handle, triggers } = await openResizableThread();
+ fireEvent.keyDown(handle, { key: 'ArrowLeft' });
+ expect(motion.animations[0]!.cancel).toHaveBeenCalled();
+ expect(panel.style.width).toBe('464px');
+ fireEvent.keyDown(handle, { key: 'ArrowRight' });
+ expect(panel.style.width).toBe('448px');
+ fireEvent.keyDown(handle, { key: 'ArrowLeft' });
+ fireEvent.click(triggers[1]!);
+ await screen.findByText('Reply to b1');
+ const switched = screen.getByRole('complementary');
+ expect(switched.style.width).toBe('464px');
+ fireEvent.click(within(switched).getByRole('button', { name: 'bots.close' }));
+ await act(async () => motion.animations[1]!.finish());
+ expect(screen.queryByRole('complementary')).toBeNull();
+ fireEvent.click(triggers[0]!);
+ const reopened = screen.getByRole('complementary');
+ expect(reopened.style.width).toBe('464px');
+ expect(motion.animate).toHaveBeenLastCalledWith([{ width: '0px' }, { width: '464px' }], expect.anything());
+ } finally { cleanup(); motion.restore(); }
+ });
+ });
+
it('expands a sibling thread panel, keeps the group usable, switches threads and restores the layout on close', async () => {
vi.stubGlobal('ResizeObserver', class { observe() {} disconnect() {} });
mocks.getBotGroup.mockResolvedValue({ ok: true, group: detail({ serverBacked: true }) });
diff --git a/apps/desktop/src/renderer/features/bots/useThreadPanelResize.ts b/apps/desktop/src/renderer/features/bots/useThreadPanelResize.ts
new file mode 100644
index 0000000000..179ed46e47
--- /dev/null
+++ b/apps/desktop/src/renderer/features/bots/useThreadPanelResize.ts
@@ -0,0 +1,86 @@
+import { useLayoutEffect, useRef, useState, type KeyboardEvent, type PointerEvent, type RefObject } from 'react';
+
+/** View-only sizing: keep the current CSS default until the reader actually resizes. */
+export function useThreadPanelResize(
+ layoutRef: RefObject<HTMLDivElement | null>,
+ rootId: string | null,
+ cancelOpening: () => void,
+) {
+ const [preferredWidth, setPreferredWidth] = useState<number | null>(null);
+ const [availableWidth, setAvailableWidth] = useState(0);
+ const [isDragging, setIsDragging] = useState(false);
+ const drag = useRef<{ pointerId: number; startX: number; width: number } | null>(null);
+
+ useLayoutEffect(() => {
+ drag.current = null;
+ setIsDragging(false);
+ const layout = layoutRef.current;
+ if (!rootId || !layout) return;
+ const measure = () => setAvailableWidth(layout.getBoundingClientRect().width);
+ measure();
+ const observer = new ResizeObserver(measure);
+ observer.observe(layout);
+ return () => observer.disconnect();
+ }, [layoutRef, rootId]);
+
+ // At narrow widths retain two columns, rather than introducing another layout.
+ const minWidth = Math.min(280, availableWidth * 0.4);
+ const maxWidth = availableWidth - Math.min(400, availableWidth * 0.4);
+ const clamp = (width: number) => Math.min(maxWidth, Math.max(minWidth, width));
+ const width = preferredWidth === null ? undefined : clamp(preferredWidth);
+
+ const onPointerDown = (event: PointerEvent<HTMLDivElement>) => {
+ if (event.button !== 0 || !event.isPrimary || availableWidth <= 0) return;
+ const panel = event.currentTarget.parentElement;
+ if (!panel || panel.inert) return;
+ event.preventDefault();
+ cancelOpening();
+ drag.current = {
+ pointerId: event.pointerId,
+ startX: event.clientX,
+ width: panel.getBoundingClientRect().width,
+ };
+ event.currentTarget.setPointerCapture(event.pointerId);
+ setIsDragging(true);
+ };
+ const onPointerMove = (event: PointerEvent<HTMLDivElement>) => {
+ const current = drag.current;
+ if (!current || current.pointerId !== event.pointerId || event.currentTarget.parentElement?.inert) return;
+ setPreferredWidth(clamp(current.width + current.startX - event.clientX));
+ };
+ const stopDragging = (event: PointerEvent<HTMLDivElement>) => {
+ if (drag.current?.pointerId !== event.pointerId) return;
+ drag.current = null;
+ setIsDragging(false);
+ if (event.currentTarget.hasPointerCapture(event.pointerId)) {
+ event.currentTarget.releasePointerCapture(event.pointerId);
+ }
+ };
+ const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
+ if (event.key !== 'ArrowLeft' && event.key !== 'ArrowRight') return;
+ const panel = event.currentTarget.parentElement;
+ if (!panel || panel.inert || availableWidth <= 0) return;
+ event.preventDefault();
+ cancelOpening();
+ const step = event.key === 'ArrowLeft' ? 16 : -16;
+ setPreferredWidth(clamp(panel.getBoundingClientRect().width + step));
+ };
+
+ return {
+ width,
+ isDragging,
+ handleProps: {
+ 'aria-valuemin': Math.round(minWidth),
+ 'aria-valuemax': Math.round(maxWidth),
+ 'aria-valuenow': Math.round(width ?? Math.min(availableWidth / 2, 448)),
+ onPointerDown,
+ onPointerMove,
+ onPointerUp: stopDragging,
+ onPointerCancel: stopDragging,
+ onLostPointerCapture: stopDragging,
+ onKeyDown,
+ },
+ };
+}
+
+export type ThreadPanelResize = ReturnType<typeof useThreadPanelResize>;
diff --git a/docs/product-rules/bot-group-chat.md b/docs/product-rules/bot-group-chat.md
index b8a7788476..89af10f32b 100644
--- a/docs/product-rules/bot-group-chat.md
+++ b/docs/product-rules/bot-group-chat.md
@@ -638,6 +638,10 @@ Desktop 群聊只对 `TOKEN_EXPIRED`、`INVALID_TOKEN`、`AUTH_REQUIRED` 的 401
Desktop 主聊天在根消息下方提示话题里的最新回复,并能把话题回复贴回主聊天。
+Desktop 群聊与话题之间的分隔线支持左右拖拽和方向键调宽;未调整时保留原有默认宽度。
+调宽仅改变两栏宽度,在本群页面内切换或关闭重开话题时保留;窄窗按可用空间限制宽度,
+不切换布局,不改变消息、输入框、滚动条、tab 与既有话题入口。
+
- **最近回复预览**:有回复的根消息下方显示一行与气泡对齐的话题入口:最近回复者头像(去重,最多 3 个)、回复数和最后回复时间(2026-10-20 起,
取代原先可见的最新 2 条回复卡片)。整行是打开话题的按钮,键盘可达;最新 2 条回复的作者和单行摘要作为该按钮的无障碍描述读出,不再可见展示。
头像从已读取窗口按服务端作者身份去重后取最近 3 位,与两条摘要分别投影;同一人连续回复不会挤掉窗口内其他回复者,不为凑满头像额外翻历史。