Skip to content

🤯 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.

✨ feat(home): add view/continue chat actions to daily brief news items (#20775)

Arvin Xua363d13b072a
diff --git a/locales/en-US/home.json b/locales/en-US/home.json
index 6eb27be552f..8cca7f97fa7 100644
--- a/locales/en-US/home.json
+++ b/locales/en-US/home.json
@@ -128,6 +128,7 @@
"inbox.goals.showAll": "Show all {{count}}",
"inbox.goals.title": "Goals",
"inbox.needsYou.title": "Needs you",
+ "inbox.news.continueChat": "Continue chat",
"inbox.news.emptyDay": "No briefs this day.",
"inbox.news.emptyToday": "Nothing new yet today.",
"inbox.news.markAllRead": "Mark all read",
@@ -138,6 +139,7 @@
"inbox.news.title": "Daily brief",
"inbox.news.titleDay": "Brief · {{date}}",
"inbox.news.titleYesterday": "Yesterday's brief",
+ "inbox.news.viewChat": "View chat",
"inbox.running.title": "{{count}} task running",
"inbox.running.title_plural": "{{count}} tasks running",
"inbox.scope.mine": "Mine",
diff --git a/locales/zh-CN/home.json b/locales/zh-CN/home.json
index a5bd0bc3b3d..3db71a0a707 100644
--- a/locales/zh-CN/home.json
+++ b/locales/zh-CN/home.json
@@ -128,6 +128,7 @@
"inbox.goals.showAll": "查看全部 {{count}} 个",
"inbox.goals.title": "目标",
"inbox.needsYou.title": "需要你处理",
+ "inbox.news.continueChat": "继续对话",
"inbox.news.emptyDay": "这一天没有简报",
"inbox.news.emptyToday": "今天还没有简报",
"inbox.news.markAllRead": "全部已读",
@@ -138,6 +139,7 @@
"inbox.news.title": "今日简报",
"inbox.news.titleDay": "{{date}}简报",
"inbox.news.titleYesterday": "昨日简报",
+ "inbox.news.viewChat": "查看对话",
"inbox.running.title": "{{count}} 个任务正在执行",
"inbox.running.title_plural": "{{count}} 个任务正在执行",
"inbox.scope.mine": "我的",
diff --git a/packages/locales/src/default/home.ts b/packages/locales/src/default/home.ts
index 4e0a819a784..5a3aad746f9 100644
--- a/packages/locales/src/default/home.ts
+++ b/packages/locales/src/default/home.ts
@@ -134,6 +134,7 @@ export default {
'inbox.goals.showAll': 'Show all {{count}}',
'inbox.goals.title': 'Goals',
'inbox.needsYou.title': 'Needs you',
+ 'inbox.news.continueChat': 'Continue chat',
'inbox.news.emptyDay': 'No briefs this day.',
'inbox.news.emptyToday': 'Nothing new yet today.',
'inbox.news.markAllRead': 'Mark all read',
@@ -144,6 +145,7 @@ export default {
'inbox.news.title': 'Daily brief',
'inbox.news.titleDay': 'Brief · {{date}}',
'inbox.news.titleYesterday': "Yesterday's brief",
+ 'inbox.news.viewChat': 'View chat',
'inbox.running.title': '{{count}} task running',
'inbox.running.title_plural': '{{count}} tasks running',
'inbox.scope.mine': 'Mine',
diff --git a/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/FeedbackInput.tsx b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/FeedbackInput.tsx
index 3a8a29b280b..f17046fbdb9 100644
--- a/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/FeedbackInput.tsx
+++ b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/FeedbackInput.tsx
@@ -3,7 +3,7 @@ import { Flexbox } from '@lobehub/ui';
import { Button } from '@lobehub/ui/base-ui';
import { $getRoot } from 'lexical';
import { ChevronDownIcon, MessageCirclePlus } from 'lucide-react';
-import { memo, useCallback, useEffect, useState } from 'react';
+import { memo, useCallback, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { AttachmentUploadButton } from '@/features/AttachmentInput';
@@ -18,6 +18,8 @@ import {
} from '@/features/EditorCanvas/editorAttachments';
import { useEnterToSend } from '@/hooks/useEnterToSend';
+import { useComposerFocus } from './useComposerFocus';
+
interface FeedbackInputProps {
/** Acceptance's in-flow topic rail starts with the composer visible. The
floating Topic drawer keeps its compact, opt-in default. */
@@ -25,10 +27,14 @@ interface FeedbackInputProps {
/** Hide the collapse affordance when the hosting surface intentionally pins
the composer open, as Acceptance's in-flow right rail does. */
disableCollapse?: boolean;
+ /** Expand and focus the composer whenever this changes — the floating drawer
+ opened by "Continue chat" wants the input hot, while read-first surfaces
+ keep the compact, opt-in default. */
+ focusRequest?: number;
}
const FeedbackInput = memo<FeedbackInputProps>(
- ({ defaultExpanded = false, disableCollapse = false }) => {
+ ({ defaultExpanded = false, disableCollapse = false, focusRequest }) => {
const { t } = useTranslation('chat');
const editor = useEditor();
const sendMessage = useConversationStore((s) => s.sendMessage);
@@ -36,7 +42,11 @@ const FeedbackInput = memo<FeedbackInputProps>(
const [submitting, setSubmitting] = useState(false);
const [hasContent, setHasContent] = useState(false);
const [hasAttachments, setHasAttachments] = useState(false);
- const [expanded, setExpanded] = useState(defaultExpanded);
+ const { collapse, expand, expanded, handleEditorInit } = useComposerFocus({
+ defaultExpanded,
+ editor,
+ focusRequest,
+ });
const shouldSendOnEnter = useEnterToSend();
// Task follow-ups send into the shared agent's topic — view-only members
// can watch the run but get no reply composer.
@@ -52,10 +62,6 @@ const FeedbackInput = memo<FeedbackInputProps>(
const { placeholderVariant, showSendWhileGenerating, showStopButton } =
useConversationChatInputUiState({ isInputEmpty: !canSubmit });
- useEffect(() => {
- if (expanded) editor?.focus?.();
- }, [expanded, editor]);
-
const handleContentChange = useCallback(() => {
const lexicalEditor = editor?.getLexicalEditor?.();
if (!lexicalEditor) return;
@@ -113,7 +119,7 @@ const FeedbackInput = memo<FeedbackInputProps>(
return (
<Flexbox gap={8}>
<OpStatusTray seamless />
- <Button block icon={MessageCirclePlus} type={'fill'} onClick={() => setExpanded(true)}>
+ <Button block icon={MessageCirclePlus} type={'fill'} onClick={expand}>
{t('taskDetail.sendFollowUp')}
</Button>
</Flexbox>
@@ -132,12 +138,7 @@ const FeedbackInput = memo<FeedbackInputProps>(
left={
<Flexbox horizontal align={'center'} gap={2}>
{!disableCollapse && (
- <Button
- icon={ChevronDownIcon}
- size={'small'}
- type={'text'}
- onClick={() => setExpanded(false)}
- >
+ <Button icon={ChevronDownIcon} size={'small'} type={'text'} onClick={collapse}>
{t('taskDetail.collapseReply')}
</Button>
)}
@@ -199,6 +200,7 @@ const FeedbackInput = memo<FeedbackInputProps>(
: t('taskDetail.replyPlaceholder')
}
onContentChange={handleContentChange}
+ onInit={handleEditorInit}
onPressEnter={({ event }) => {
if (shouldSendOnEnter(event)) {
handleSubmit();
diff --git a/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index.test.tsx b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index.test.tsx
index 7dc26870756..bfb3e526bf8 100644
--- a/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index.test.tsx
+++ b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index.test.tsx
@@ -37,6 +37,7 @@ const mocks = vi.hoisted(() => ({
},
taskState: {
activeTaskId: 'T-1',
+ activeTopicDrawerFocusRequest: undefined as number | undefined,
activeTopicDrawerTopicId: 'topic-1',
closeTopicDrawer: vi.fn(),
useFetchTaskDetail: vi.fn(),
@@ -121,6 +122,7 @@ vi.mock('@lobehub/ui/base-ui', async (importOriginal) => ({
height,
minHeight,
minWidth,
+ onClose,
open,
placement,
resizable = true,
@@ -133,6 +135,7 @@ vi.mock('@lobehub/ui/base-ui', async (importOriginal) => ({
height?: unknown;
minHeight?: number;
minWidth?: number;
+ onClose?: () => void;
open?: boolean;
placement?: string;
resizable?: boolean;
@@ -156,7 +159,7 @@ vi.mock('@lobehub/ui/base-ui', async (importOriginal) => ({
{title}
</div>
<div data-testid="panel-actions-slot">{actions}</div>
- <button data-testid="panel-close-icon" />
+ <button data-testid="panel-close-icon" onClick={onClose} />
<div data-testid="panel-body-slot" style={styles?.body}>
{children}
</div>
@@ -282,6 +285,7 @@ describe('TopicChatDrawer', () => {
});
mocks.navigate.mockClear();
mocks.taskState.closeTopicDrawer.mockClear();
+ mocks.taskState.activeTopicDrawerFocusRequest = undefined;
mocks.taskState.activeTopicDrawerTopicId = 'topic-1';
mocks.taskState.taskDetailMap['T-1'].activities[0] = {
id: 'topic-1',
@@ -440,6 +444,60 @@ describe('TopicChatDrawer', () => {
expect(mocks.taskState.closeTopicDrawer).not.toHaveBeenCalled();
});
+ it('closes its artifact together with the drawer so the topic reopens on the conversation', () => {
+ mocks.chatState.portalStack = [{ artifact: { id: 'message-1' }, type: 'artifact' }];
+ mocks.chatState.showPortal = true;
+
+ const view = render(<TopicChatDrawer />);
+ expect(view.getByTestId('artifact-portal')).toBeInTheDocument();
+
+ fireEvent.click(view.getByTestId('panel-close-icon'));
+
+ expect(mocks.chatState.closeArtifact).toHaveBeenCalledOnce();
+ expect(mocks.taskState.closeTopicDrawer).toHaveBeenCalledOnce();
+ });
+
+ it('leaves another conversation’s artifact open when the drawer closes', () => {
+ mocks.chatState.portalStack = [{ artifact: { id: 'another-message' }, type: 'artifact' }];
+ mocks.chatState.showPortal = true;
+
+ const view = render(<TopicChatDrawer />);
+ fireEvent.click(view.getByTestId('panel-close-icon'));
+
+ expect(mocks.chatState.closeArtifact).not.toHaveBeenCalled();
+ expect(mocks.taskState.closeTopicDrawer).toHaveBeenCalledOnce();
+ });
+
+ it('switches from its artifact to the conversation on each new focus request', () => {
+ // The store mock is not reactive and the drawer is a prop-less memo, so a
+ // throwaway prop forces each re-render after the mocked state changes.
+ const renderAt = (revision: number) => (
+ <TopicChatDrawer {...({ 'data-revision': revision } as object)} />
+ );
+ mocks.chatState.portalStack = [{ artifact: { id: 'message-1' }, type: 'artifact' }];
+ mocks.chatState.showPortal = true;
+
+ const view = render(renderAt(0));
+ expect(mocks.chatState.closeArtifact).not.toHaveBeenCalled();
+
+ mocks.taskState.activeTopicDrawerFocusRequest = 1;
+ view.rerender(renderAt(1));
+ expect(mocks.chatState.closeArtifact).toHaveBeenCalledOnce();
+ view.rerender(renderAt(2));
+ expect(view.getByTestId('chat-list')).toBeInTheDocument();
+
+ // An artifact opened later from inside the conversation stays open until
+ // another request arrives.
+ mocks.chatState.portalStack = [{ artifact: { id: 'message-1' }, type: 'artifact' }];
+ view.rerender(renderAt(3));
+ expect(view.getByTestId('artifact-portal')).toBeInTheDocument();
+ expect(mocks.chatState.closeArtifact).toHaveBeenCalledOnce();
+
+ mocks.taskState.activeTopicDrawerFocusRequest = 2;
+ view.rerender(renderAt(4));
+ expect(mocks.chatState.closeArtifact).toHaveBeenCalledTimes(2);
+ });
+
it('does not take over an artifact opened by another conversation', () => {
mocks.chatState.portalStack = [{ artifact: { id: 'another-message' }, type: 'artifact' }];
mocks.chatState.showPortal = true;
diff --git a/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index.tsx b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index.tsx
index 2c154ebd5bb..cfe006c5f62 100644
--- a/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index.tsx
+++ b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/index.tsx
@@ -15,7 +15,7 @@ import {
Share2,
Trash,
} from 'lucide-react';
-import { memo, useCallback, useMemo, useState } from 'react';
+import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import ChatList from '@/features/Conversation/ChatList';
@@ -54,6 +54,10 @@ export interface TopicChatDrawerBodyProps {
agentId: string;
defaultInputExpanded?: boolean;
disableInputCollapse?: boolean;
+ /** Expand and focus the reply composer whenever this changes — bumped when the
+ drawer is opened with conversational intent (e.g. the brief's "Continue
+ chat"). */
+ inputFocusRequest?: number;
/**
* The run to resume streaming from. Hosts that embed the body outside the
* drawer pass it themselves; the drawer falls back to its own topic's run.
@@ -63,7 +67,14 @@ export interface TopicChatDrawerBodyProps {
}
export const TopicChatDrawerBody = memo<TopicChatDrawerBodyProps>(
- ({ agentId, defaultInputExpanded, disableInputCollapse, runningOperation, topicId }) => {
+ ({
+ agentId,
+ defaultInputExpanded,
+ disableInputCollapse,
+ inputFocusRequest,
+ runningOperation,
+ topicId,
+ }) => {
const isLogin = useUserStore(authSelectors.isLogin);
const useHydrateAgentConfig = useAgentStore((s) => s.useHydrateAgentConfig);
@@ -115,6 +126,7 @@ export const TopicChatDrawerBody = memo<TopicChatDrawerBodyProps>(
<FeedbackInput
defaultExpanded={defaultInputExpanded}
disableCollapse={disableInputCollapse}
+ focusRequest={inputFocusRequest}
/>
</Flexbox>
</Flexbox>
@@ -134,12 +146,31 @@ const TopicChatDrawer = memo(() => {
const activeTaskId = useTaskStore((s) => s.activeTaskId);
const agentId = useTaskStore(taskDetailSelectors.topicDrawerAgentId);
const drawerTitle = useTaskStore(taskDetailSelectors.topicDrawerTitle);
+ const inputFocusRequest = useTaskStore(taskDetailSelectors.topicDrawerFocusRequest);
const activity = useTaskStore(taskActivitySelectors.activeDrawerTopicActivity);
const closeTopicDrawer = useTaskStore((s) => s.closeTopicDrawer);
const deleteTopic = useTaskStore((s) => s.deleteTopic);
const useFetchTaskDetail = useTaskStore((s) => s.useFetchTaskDetail);
const showArtifactPortal = useTopicDrawerArtifactPortal();
const closeArtifact = useChatStore((s) => s.closeArtifact);
+
+ // The portal state is global: an artifact left open when this drawer closes
+ // would make the next opening of the same topic land on the artifact instead
+ // of the conversation, so the drawer takes its artifact down with it.
+ const handleClose = useCallback(() => {
+ if (showArtifactPortal) closeArtifact();
+ closeTopicDrawer();
+ }, [closeArtifact, closeTopicDrawer, showArtifactPortal]);
+
+ // A request to write ("Continue chat") needs the conversation and its
+ // composer. Each request is handled once, so an artifact the user opens
+ // afterwards from inside the conversation is left alone.
+ const handledFocusRequestRef = useRef(inputFocusRequest);
+ useEffect(() => {
+ if (!inputFocusRequest || inputFocusRequest === handledFocusRequestRef.current) return;
+ handledFocusRequestRef.current = inputFocusRequest;
+ if (showArtifactPortal) closeArtifact();
+ }, [closeArtifact, inputFocusRequest, showArtifactPortal]);
const enableTopicLinkShare = useServerConfigStore(serverConfigSelectors.enableBusinessFeatures);
const { allowed: canShare, reason } = usePermission('edit_own_content');
const { allowed: canEditTask } = usePermission('create_content');
@@ -349,7 +380,7 @@ const TopicChatDrawer = memo(() => {
overflow: 'hidden',
},
}}
- onClose={closeTopicDrawer}
+ onClose={handleClose}
>
{/* `open` already proves both ids. The body deliberately does NOT wait for a
task: a run opened from the home inbox may have no parent task at all,
@@ -361,7 +392,11 @@ const TopicChatDrawer = memo(() => {
<PortalContent onClose={closeArtifact} />
</Flexbox>
) : (
- <TopicChatDrawerBody agentId={agentId!} topicId={topicId!} />
+ <TopicChatDrawerBody
+ agentId={agentId!}
+ inputFocusRequest={inputFocusRequest}
+ topicId={topicId!}
+ />
))}
</Freeze>
</FloatingPanel>
diff --git a/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/useComposerFocus.test.ts b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/useComposerFocus.test.ts
new file mode 100644
index 00000000000..3e87ef48831
--- /dev/null
+++ b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/useComposerFocus.test.ts
@@ -0,0 +1,75 @@
+import { act, renderHook } from '@testing-library/react';
+import { describe, expect, it, vi } from 'vitest';
+
+import { useComposerFocus } from './useComposerFocus';
+
+const createEditor = () => ({ focus: vi.fn() });
+
+describe('useComposerFocus', () => {
+ it('should start expanded without taking focus when the host only pins it open', () => {
+ const editor = createEditor();
+ const { result } = renderHook(() => useComposerFocus({ defaultExpanded: true, editor }));
+
+ act(() => result.current.handleEditorInit(editor));
+
+ expect(result.current.expanded).toBe(true);
+ expect(editor.focus).not.toHaveBeenCalled();
+ });
+
+ it('should start expanded and focus once the editor is ready when opened with a focus request', () => {
+ const editor = createEditor();
+ const { result } = renderHook(() =>
+ useComposerFocus({ defaultExpanded: false, editor, focusRequest: 1 }),
+ );
+ editor.focus.mockClear();
+
+ act(() => result.current.handleEditorInit(editor));
+
+ expect(result.current.expanded).toBe(true);
+ expect(editor.focus).toHaveBeenCalledTimes(1);
+ });
+
+ it('should focus after the user expands the collapsed composer', () => {
+ const editor = createEditor();
+ const { result } = renderHook(() => useComposerFocus({ defaultExpanded: false, editor }));
+ expect(result.current.expanded).toBe(false);
+
+ act(() => result.current.expand());
+ act(() => result.current.handleEditorInit(editor));
+
+ expect(result.current.expanded).toBe(true);
+ expect(editor.focus).toHaveBeenCalledTimes(1);
+ });
+
+ it('should expand and focus a mounted composer when a focus request arrives', () => {
+ const editor = createEditor();
+ const { rerender, result } = renderHook(
+ ({ focusRequest }: { focusRequest?: number }) =>
+ useComposerFocus({ defaultExpanded: false, editor, focusRequest }),
+ { initialProps: {} },
+ );
+ expect(result.current.expanded).toBe(false);
+
+ rerender({ focusRequest: 1 });
+
+ expect(result.current.expanded).toBe(true);
+ expect(editor.focus).toHaveBeenCalled();
+ });
+
+ it('should re-expand and refocus on a repeated request after the user collapsed it', () => {
+ const editor = createEditor();
+ const { rerender, result } = renderHook(
+ ({ focusRequest }: { focusRequest?: number }) =>
+ useComposerFocus({ defaultExpanded: false, editor, focusRequest }),
+ { initialProps: { focusRequest: 1 } },
+ );
+ act(() => result.current.collapse());
+ expect(result.current.expanded).toBe(false);
+ editor.focus.mockClear();
+
+ rerender({ focusRequest: 2 });
+
+ expect(result.current.expanded).toBe(true);
+ expect(editor.focus).toHaveBeenCalledTimes(1);
+ });
+});
diff --git a/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/useComposerFocus.ts b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/useComposerFocus.ts
new file mode 100644
index 00000000000..c0255affa89
--- /dev/null
+++ b/src/features/AgentTasks/AgentTaskDetail/TopicChatDrawer/useComposerFocus.ts
@@ -0,0 +1,53 @@
+import { type IEditor } from '@lobehub/editor';
+import { useCallback, useEffect, useRef, useState } from 'react';
+
+interface UseComposerFocusParams {
+ /** Start expanded without taking focus — a host that pins the composer open. */
+ defaultExpanded: boolean;
+ editor?: Pick<IEditor, 'focus'> | null;
+ /**
+ * Expand and focus whenever this changes to a truthy value — bumped each time
+ * the drawer is opened with conversational intent, so a repeated request on
+ * an already-open drawer still lands.
+ */
+ focusRequest?: number;
+}
+
+/**
+ * Decides when the reply composer expands and when it takes focus. Only an
+ * explicit request to write (the expand click or a focus request) takes focus;
+ * a host that merely pins the composer open must not steal it.
+ */
+export const useComposerFocus = ({
+ defaultExpanded,
+ editor,
+ focusRequest,
+}: UseComposerFocusParams) => {
+ const [expanded, setExpanded] = useState(defaultExpanded || !!focusRequest);
+ const focusOnInitRef = useRef(!!focusRequest);
+
+ // Focus from the editor's own init callback: a mount-time `editor.focus()`
+ // runs before the lexical root attaches and is silently dropped, while
+ // `onInit` fires once the kernel is ready.
+ const handleEditorInit = useCallback((instance: Pick<IEditor, 'focus'>) => {
+ if (focusOnInitRef.current) instance.focus?.();
+ }, []);
+
+ // "Continue chat" on a drawer that is already open for this topic keeps the
+ // body mounted, so the request has to reach the live composer too.
+ useEffect(() => {
+ if (!focusRequest) return;
+ focusOnInitRef.current = true;
+ setExpanded(true);
+ editor?.focus?.();
+ }, [focusRequest, editor]);
+
+ const expand = useCallback(() => {
+ focusOnInitRef.current = true;
+ setExpanded(true);
+ }, []);
+
+ const collapse = useCallback(() => setExpanded(false), []);
+
+ return { collapse, expand, expanded, handleEditorInit };
+};
diff --git a/src/features/Conversation/hooks/useConversationResourceAccess.test.ts b/src/features/Conversation/hooks/useConversationResourceAccess.test.ts
index 6b6a5743bb3..a7cf824ffdf 100644
--- a/src/features/Conversation/hooks/useConversationResourceAccess.test.ts
+++ b/src/features/Conversation/hooks/useConversationResourceAccess.test.ts
@@ -1,7 +1,10 @@
import { renderHook } from '@testing-library/react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
-import { useActiveConversationResourceAccess } from './useConversationResourceAccess';
+import {
+ useActiveConversationResourceAccess,
+ useConversationResourceAccessForTarget,
+} from './useConversationResourceAccess';
const mocks = vi.hoisted(() => ({
agentState: {
@@ -20,7 +23,13 @@ const mocks = vi.hoisted(() => ({
groupState: {
groupMap: {} as Record<string, { id: string; visibility: 'private' | 'public' }>,
},
- useResourceAccess: vi.fn(() => ({ canUseResource: true, isLoading: false })),
+ useResourceAccess: vi.fn(
+ (): { canUseResource: boolean; isAccessResolved?: boolean; isLoading: boolean } => ({
+ canUseResource: true,
+ isAccessResolved: true,
+ isLoading: false,
+ }),
+ ),
}));
vi.mock('@/features/ResourcePermission/useResourceAccess', () => ({
@@ -88,3 +97,67 @@ describe('useActiveConversationResourceAccess', () => {
expect(mocks.useResourceAccess).toHaveBeenCalledWith('agentGroup', 'group-1');
});
});
+
+describe('useConversationResourceAccessForTarget', () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ });
+
+ it('confirms use only once access has resolved to a usable level', () => {
+ mocks.useResourceAccess.mockReturnValue({
+ canUseResource: true,
+ isAccessResolved: true,
+ isLoading: false,
+ });
+
+ const { result } = renderHook(() =>
+ useConversationResourceAccessForTarget({ agentId: 'agent-1' }),
+ );
+
+ expect(result.current.canUseResource).toBe(true);
+ expect(result.current.canUseResourceConfirmed).toBe(true);
+ });
+
+ it('stays permissive but unconfirmed while access is loading', () => {
+ mocks.useResourceAccess.mockReturnValue({
+ canUseResource: true,
+ isAccessResolved: false,
+ isLoading: true,
+ });
+
+ const { result } = renderHook(() =>
+ useConversationResourceAccessForTarget({ agentId: 'agent-1' }),
+ );
+
+ expect(result.current.canUseResource).toBe(true);
+ expect(result.current.canUseResourceConfirmed).toBe(false);
+ });
+
+ it('fails closed when the access lookup errored and never resolved', () => {
+ mocks.useResourceAccess.mockReturnValue({
+ canUseResource: true,
+ isAccessResolved: false,
+ isLoading: false,
+ });
+
+ const { result } = renderHook(() =>
+ useConversationResourceAccessForTarget({ agentId: 'agent-1' }),
+ );
+
+ expect(result.current.canUseResourceConfirmed).toBe(false);
+ });
+
+ it('does not confirm a resolved view-only grant', () => {
+ mocks.useResourceAccess.mockReturnValue({
+ canUseResource: false,
+ isAccessResolved: true,
+ isLoading: false,
+ });
+
+ const { result } = renderHook(() =>
+ useConversationResourceAccessForTarget({ agentId: 'agent-1' }),
+ );
+
+ expect(result.current.canUseResourceConfirmed).toBe(false);
+ });
+});
diff --git a/src/features/Conversation/hooks/useConversationResourceAccess.ts b/src/features/Conversation/hooks/useConversationResourceAccess.ts
index b229a4c1ffe..559a71bcd28 100644
--- a/src/features/Conversation/hooks/useConversationResourceAccess.ts
+++ b/src/features/Conversation/hooks/useConversationResourceAccess.ts
@@ -45,13 +45,20 @@ export const useConversationResourceAccessForTarget = ({
: undefined;
const { allowed: canCreateContent } = usePermission('create_content');
- const { canUseResource, isLoading } = useResourceAccess(
+ const { canUseResource, isAccessResolved, isLoading } = useResourceAccess(
isGroupContext ? 'agentGroup' : 'agent',
gatedResourceId ?? undefined,
);
return {
canUseResource: canCreateContent && canUseResource,
+ /**
+ * `canUseResource` stays permissive while access loads or after it fails,
+ * so a composer never flickers away. An affordance that only promises
+ * writing (and has a read-only sibling) waits for a resolved grant instead,
+ * failing closed on error.
+ */
+ canUseResourceConfirmed: canCreateContent && canUseResource && isAccessResolved,
isAccessLoading: isLoading,
isGroupContext,
};
diff --git a/src/features/HomeInbox/NewsChatActions.tsx b/src/features/HomeInbox/NewsChatActions.tsx
new file mode 100644
index 00000000000..bed88b1e142
--- /dev/null
+++ b/src/features/HomeInbox/NewsChatActions.tsx
@@ -0,0 +1,84 @@
+import { Flexbox } from '@lobehub/ui';
+import { Button } from '@lobehub/ui/base-ui';
+import { cssVar } from 'antd-style';
+import { MessageSquarePlus, Workflow } from 'lucide-react';
+import { memo, useCallback } from 'react';
+import { useTranslation } from 'react-i18next';
+import { shallow } from 'zustand/shallow';
+
+import { useConversationResourceAccessForTarget } from '@/features/Conversation/hooks/useConversationResourceAccess';
+import { useAnalytics } from '@/libs/analytics/client';
+import { useTaskStore } from '@/store/task';
+
+interface NewsChatActionsProps {
+ agentId: string;
+ taskId?: string | null;
+ title: string;
+ topicId: string;
+}
+
+/**
+ * The way back into the conversation behind a run-owned brief. Mounted only
+ * while the brief is expanded, so the agent's access is resolved for the one
+ * row being read rather than for every row in the feed.
+ */
+const NewsChatActions = memo<NewsChatActionsProps>(({ agentId, taskId, title, topicId }) => {
+ const { t } = useTranslation('home');
+ const { analytics } = useAnalytics();
+ const { openTopicDrawer, setActiveTaskId } = useTaskStore(
+ (s) => ({ openTopicDrawer: s.openTopicDrawer, setActiveTaskId: s.setActiveTaskId }),
+ shallow,
+ );
+ // A view-only member can still read the thread, but the drawer gives them no
+ // composer — offering "Continue chat" would promise a reply they cannot send.
+ // It waits for a resolved grant, so it never flashes in while access loads.
+ const { canUseResourceConfirmed } = useConversationResourceAccessForTarget({ agentId });
+
+ const openTopicChat = useCallback(
+ (autoFocus: boolean) => {
+ const action = autoFocus ? 'continue' : 'view';
+ try {
+ analytics?.track({
+ name: 'home_daily_brief_chat_clicked',
+ properties: { action, spm: `homepage.daily_brief.${action}_chat.clicked` },
+ });
+ } catch {
+ // silently ignore tracking errors to avoid affecting business logic
+ }
+ // setActiveTaskId hydrates the drawer's task context when the brief owns a
+ // task and clears any prior drawer state, so openTopicDrawer must come
+ // after it for the topic to survive the reset.
+ setActiveTaskId(taskId ?? undefined);
+ openTopicDrawer(topicId, { agentId, autoFocus, title });
+ },
+ [agentId, analytics, openTopicDrawer, setActiveTaskId, taskId, title, topicId],
+ );
+
+ return (
+ <Flexbox horizontal align={'center'} gap={4} justify={'flex-end'}>
+ <Button
+ icon={Workflow}
+ size={'small'}
+ style={{ color: cssVar.colorTextSecondary }}
+ type={'text'}
+ onClick={() => openTopicChat(false)}
+ >
+ {t('inbox.news.viewChat')}
+ </Button>
+ {canUseResourceConfirmed && (
+ <Button
+ icon={MessageSquarePlus}
+ size={'small'}
+ type={'fill'}
+ onClick={() => openTopicChat(true)}
+ >
+ {t('inbox.news.continueChat')}
+ </Button>
+ )}
+ </Flexbox>
+ );
+});
+
+NewsChatActions.displayName = 'NewsChatActions';
+
+export default NewsChatActions;
diff --git a/src/features/HomeInbox/NewsList.tsx b/src/features/HomeInbox/NewsList.tsx
index 0a05ecbe9c3..8efb42f4402 100644
--- a/src/features/HomeInbox/NewsList.tsx
+++ b/src/features/HomeInbox/NewsList.tsx
@@ -13,6 +13,8 @@ import { homeType } from '@/features/Home/components/homeType';
import Time from '@/features/Home/components/Time';
import { useBriefStore } from '@/store/brief';
+import NewsChatActions from './NewsChatActions';
+
const Markdown = lazy(() => import('@lobehub/ui/es/Markdown/index'));
const AVATAR_SIZE = 20;
@@ -103,6 +105,14 @@ const NewsItem = memo<NewsItemProps>(({ bare, brief, showTime }) => {
});
}, [brief.id, markBriefRead, read]);
+ // Only a run-owned brief (it names both an agent and a topic) has a thread to
+ // go back to: "View chat" reopens the conversation the agent worked in, and
+ // "Continue chat" opens the same thread with the reply composer hot. A brief
+ // without a topic stays a pure information row.
+ const agentId = brief.agentId ?? brief.agent?.id;
+ const topicId = brief.topicId;
+ const hasTopicChat = Boolean(agentId && topicId);
+
return (
<Flexbox className={bare ? undefined : styles.section}>
<Button className={cx(styles.row, bare && styles.bareRow)} type={'text'} onClick={toggle}>
@@ -142,7 +152,7 @@ const NewsItem = memo<NewsItemProps>(({ bare, brief, showTime }) => {
</Flexbox>
</Button>
- {expanded && (brief.summary || brief.artifacts) && (
+ {expanded && (brief.summary || brief.artifacts || hasTopicChat) && (
<Flexbox className={bare ? styles.bareBody : styles.body} gap={8}>
{brief.summary && (
<Suspense fallback={null}>
@@ -152,6 +162,14 @@ const NewsItem = memo<NewsItemProps>(({ bare, brief, showTime }) => {
</Suspense>
)}
<BriefCardArtifacts artifacts={brief.artifacts} />
+ {agentId && topicId && (
+ <NewsChatActions
+ agentId={agentId}
+ taskId={brief.taskId}
+ title={brief.taskName ?? brief.title}
+ topicId={topicId}
+ />
+ )}
</Flexbox>
)}
</Flexbox>
diff --git a/src/store/task/selectors/detailSelectors.ts b/src/store/task/selectors/detailSelectors.ts
index 81215035d60..6ade7f202d6 100644
--- a/src/store/task/selectors/detailSelectors.ts
+++ b/src/store/task/selectors/detailSelectors.ts
@@ -128,6 +128,8 @@ const topicDrawerAgentId = (s: TaskStoreState) =>
const topicDrawerTitle = (s: TaskStoreState) => s.activeTopicDrawerTitle;
+const topicDrawerFocusRequest = (s: TaskStoreState) => s.activeTopicDrawerFocusRequest;
+
export const taskDetailSelectors = {
activeTaskAgentId,
activeTaskAssigneeUserId,
@@ -169,5 +171,6 @@ export const taskDetailSelectors = {
taskDetailById,
taskSaveStatus,
topicDrawerAgentId,
+ topicDrawerFocusRequest,
topicDrawerTitle,
};
diff --git a/src/store/task/slices/detail/action.test.ts b/src/store/task/slices/detail/action.test.ts
index c43234ecab0..c21de5603cc 100644
--- a/src/store/task/slices/detail/action.test.ts
+++ b/src/store/task/slices/detail/action.test.ts
@@ -64,6 +64,10 @@ beforeEach(() => {
vi.resetAllMocks();
useTaskStore.setState({
activeTaskId: undefined,
+ activeTopicDrawerAgentId: undefined,
+ activeTopicDrawerFocusRequest: undefined,
+ activeTopicDrawerTitle: undefined,
+ activeTopicDrawerTopicId: undefined,
isCreatingTask: false,
isDeletingTask: false,
taskDetailMap: {},
@@ -226,6 +230,45 @@ describe('TaskDetailSliceAction', () => {
});
});
+ describe('topic drawer focus request', () => {
+ it('should start a focus request when the drawer opens with conversational intent', () => {
+ useTaskStore.getState().openTopicDrawer('tpc-1', { agentId: 'agt-1', autoFocus: true });
+
+ expect(taskDetailSelectors.topicDrawerFocusRequest(useTaskStore.getState())).toBe(1);
+ });
+
+ it('should not start a focus request for a plain opening', () => {
+ useTaskStore.getState().openTopicDrawer('tpc-1', { agentId: 'agt-1' });
+
+ expect(useTaskStore.getState().activeTopicDrawerFocusRequest).toBeUndefined();
+ });
+
+ it('should bump the request on every repeated autoFocus opening of the same topic', () => {
+ useTaskStore.getState().openTopicDrawer('tpc-1', { agentId: 'agt-1' });
+ useTaskStore.getState().openTopicDrawer('tpc-1', { agentId: 'agt-1', autoFocus: true });
+ useTaskStore.getState().openTopicDrawer('tpc-1', { agentId: 'agt-1', autoFocus: true });
+
+ expect(useTaskStore.getState().activeTopicDrawerFocusRequest).toBe(2);
+ });
+
+ it('should not carry a focus request over to a plainly opened different topic', () => {
+ useTaskStore.getState().openTopicDrawer('tpc-1', { autoFocus: true });
+ useTaskStore.getState().openTopicDrawer('tpc-2');
+
+ expect(useTaskStore.getState().activeTopicDrawerFocusRequest).toBeUndefined();
+ });
+
+ it('should clear the focus request on close and when switching tasks', () => {
+ useTaskStore.getState().openTopicDrawer('tpc-1', { autoFocus: true });
+ useTaskStore.getState().closeTopicDrawer();
+ expect(useTaskStore.getState().activeTopicDrawerFocusRequest).toBeUndefined();
+
+ useTaskStore.getState().openTopicDrawer('tpc-1', { autoFocus: true });
+ useTaskStore.getState().setActiveTaskId('T-2');
+ expect(useTaskStore.getState().activeTopicDrawerFocusRequest).toBeUndefined();
+ });
+ });
+
describe('createTask', () => {
it('should call service and return identifier', async () => {
vi.mocked(taskService.create).mockResolvedValue({
diff --git a/src/store/task/slices/detail/action.ts b/src/store/task/slices/detail/action.ts
index cab9876aee6..2d569ad5733 100644
--- a/src/store/task/slices/detail/action.ts
+++ b/src/store/task/slices/detail/action.ts
@@ -390,6 +390,7 @@ export class TaskDetailSliceActionImpl {
{
activeTaskId: taskId,
activeTopicDrawerAgentId: undefined,
+ activeTopicDrawerFocusRequest: undefined,
activeTopicDrawerTitle: undefined,
activeTopicDrawerTopicId: undefined,
},
@@ -401,13 +402,23 @@ export class TaskDetailSliceActionImpl {
/**
* `topic` carries the agent and title for a run opened outside a task detail
* (the home inbox lists plain topics too) — the drawer falls back to it when
- * no task detail is loaded to read them from.
+ * no task detail is loaded to read them from. `autoFocus` marks openings made
+ * with conversational intent (the brief's "Continue chat"); each one bumps
+ * the focus request so the body expands and focuses its reply composer, even
+ * when the drawer already shows this topic.
*/
- openTopicDrawer = (topicId: string, topic?: { agentId?: string; title?: string }): void => {
- if (this.#get().activeTopicDrawerTopicId === topicId) return;
+ openTopicDrawer = (
+ topicId: string,
+ topic?: { agentId?: string; autoFocus?: boolean; title?: string },
+ ): void => {
+ const current = this.#get();
+ if (current.activeTopicDrawerTopicId === topicId && !topic?.autoFocus) return;
this.#set(
{
activeTopicDrawerAgentId: topic?.agentId,
+ activeTopicDrawerFocusRequest: topic?.autoFocus
+ ? (current.activeTopicDrawerFocusRequest ?? 0) + 1
+ : undefined,
activeTopicDrawerTitle: topic?.title,
activeTopicDrawerTopicId: topicId,
},
@@ -421,6 +432,7 @@ export class TaskDetailSliceActionImpl {
this.#set(
{
activeTopicDrawerAgentId: undefined,
+ activeTopicDrawerFocusRequest: undefined,
activeTopicDrawerTitle: undefined,
activeTopicDrawerTopicId: undefined,
},
diff --git a/src/store/task/slices/detail/initialState.ts b/src/store/task/slices/detail/initialState.ts
index f7484eaa51e..99f9458e56d 100644
--- a/src/store/task/slices/detail/initialState.ts
+++ b/src/store/task/slices/detail/initialState.ts
@@ -11,6 +11,10 @@ export interface TaskDetailSliceState {
* `taskDetailMap` entry to read the agent / title from.
*/
activeTopicDrawerAgentId?: string;
+ /** Bumped on every opening with conversational intent — the body expands and
+ focuses its reply composer each time it changes, so a repeated request
+ on an already-open drawer is still observable. */
+ activeTopicDrawerFocusRequest?: number;
activeTopicDrawerTitle?: string;
activeTopicDrawerTopicId?: string;
isCreatingTask: boolean;